holidays.cpp
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include <qfile.h>
00023
00024 #include <kapplication.h>
00025
00026 #include <kstandarddirs.h>
00027
00028 #include "configdialog.h"
00029
00030 #include "holidaySettings.h"
00031 #include "holidays.h"
00032
00033
00034 class HolidaysFactory : public CalendarDecorationFactory {
00035 public:
00036 CalendarDecoration *create() { return new Holidays; }
00037 };
00038
00039 extern "C" {
00040 void *init_libkorg_holidays()
00041 {
00042 return (new HolidaysFactory);
00043 }
00044 }
00045
00046
00047 extern "C" {
00048 char *parse_holidays(const char *, int year, short force);
00050 struct holiday {
00051 char *string;
00052 unsigned short dup;
00053 };
00054 extern struct holiday holiday[366];
00055 }
00056
00057
00058 Holidays::Holidays()
00059 {
00060 HolidaySettings::self()->readConfig();
00061 QString holiday( HolidaySettings::holidays() );
00062
00063 mHolidayFile = locate("data","korganizer/holiday_" + holiday);
00064
00065 yearLast = 0;
00066 }
00067
00068 Holidays::~Holidays()
00069 {
00070 }
00071
00072 QString Holidays::shortText(const QDate &date)
00073 {
00074 return getHoliday(date);
00075 }
00076
00077 QString Holidays::info()
00078 {
00079 return i18n("This plugin provides holidays.");
00080 }
00081
00082 void Holidays::configure(QWidget *parent)
00083 {
00084 ConfigDialog *dlg = new ConfigDialog(parent);
00085 dlg->exec();
00086 delete dlg;
00087 }
00088
00089 QString Holidays::getHoliday(const QDate &qd)
00090 {
00091
00092 int lastYear = 0;
00093
00094 if (mHolidayFile.isEmpty() || qd.isNull()) return QString::null;
00095
00096
00097 if ((yearLast == 0) || (qd.year() != yearLast)) {
00098 yearLast = qd.year();
00099 lastYear = qd.year() - 1900;
00100 parse_holidays(QFile::encodeName(mHolidayFile), lastYear, 1);
00101 }
00102
00103 if (holiday[qd.dayOfYear()-1].string) {
00104 QString holidayname = QString::fromUtf8(holiday[qd.dayOfYear()-1].string);
00105 return holidayname;
00106 } else {
00107 return QString::null;
00108 }
00109 }
This file is part of the documentation for korganizer Library Version 3.3.2.