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 #include <kconfig.h>
00026 #include <kstandarddirs.h>
00027
00028 #include "configdialog.h"
00029
00030 #include "holidays.h"
00031
00032 class HolidaysFactory : public CalendarDecorationFactory {
00033 public:
00034 CalendarDecoration *create() { return new Holidays; }
00035 };
00036
00037 extern "C" {
00038 void *init_libkorg_holidays()
00039 {
00040 return (new HolidaysFactory);
00041 }
00042 }
00043
00044
00045 extern "C" {
00046 char *parse_holidays(const char *, int year, short force);
00048 struct holiday {
00049 char *string;
00050 unsigned short dup;
00051 };
00052 extern struct holiday holiday[366];
00053 }
00054
00055
00056 Holidays::Holidays()
00057 {
00058 KConfig config( locateLocal( "config", "korganizerrc" ));
00059 config.setGroup("Calendar/Holiday Plugin");
00060 QString holiday = config.readEntry("Holidays");
00061
00062 mHolidayFile = locate("data","korganizer/holiday_" + holiday);
00063
00064 yearLast = 0;
00065 }
00066
00067 Holidays::~Holidays()
00068 {
00069 }
00070
00071 QString Holidays::shortText(const QDate &date)
00072 {
00073 return getHoliday(date);
00074 }
00075
00076 QString Holidays::info()
00077 {
00078 return i18n("This plugin provides holidays.");
00079 }
00080
00081 void Holidays::configure(QWidget *parent)
00082 {
00083 ConfigDialog *dlg = new ConfigDialog(parent);
00084 dlg->exec();
00085 delete dlg;
00086 }
00087
00088 QString Holidays::getHoliday(const QDate &qd)
00089 {
00090
00091 int lastYear = 0;
00092
00093 if (mHolidayFile.isEmpty()) return QString::null;
00094
00095
00096 if ((yearLast == 0) || (qd.year() != yearLast)) {
00097 yearLast = qd.year();
00098 lastYear = qd.year() - 1900;
00099 parse_holidays(QFile::encodeName(mHolidayFile), lastYear, 1);
00100 }
00101
00102 if (holiday[qd.dayOfYear()-1].string) {
00103 QString holidayname = QString::fromLocal8Bit(holiday[qd.dayOfYear()-1].string);
00104 return holidayname;
00105 } else {
00106 return QString::null;
00107 }
00108 }
This file is part of the documentation for korganizer Library Version 3.2.2.