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 kapp->config()->setGroup("Calendar/Holiday Plugin");
00059 QString holiday = kapp->config()->readEntry("Holidays");
00060
00061 mHolidayFile = locate("appdata","holiday_" + holiday);
00062
00063 yearLast = 0;
00064 }
00065
00066 Holidays::~Holidays()
00067 {
00068 }
00069
00070 QString Holidays::shortText(const QDate &date)
00071 {
00072 return getHoliday(date);
00073 }
00074
00075 QString Holidays::info()
00076 {
00077 return i18n("This plugin provides holidays.");
00078 }
00079
00080 void Holidays::configure(QWidget *parent)
00081 {
00082 ConfigDialog *dlg = new ConfigDialog(parent);
00083 dlg->exec();
00084 }
00085
00086 QString Holidays::getHoliday(const QDate &qd)
00087 {
00088
00089 int lastYear = 0;
00090
00091 if (mHolidayFile.isEmpty()) return QString::null;
00092
00093
00094 if ((yearLast == 0) || (qd.year() != yearLast)) {
00095 yearLast = qd.year();
00096 lastYear = qd.year() - 1900;
00097 parse_holidays(QFile::encodeName(mHolidayFile), lastYear, 1);
00098 }
00099
00100 if (holiday[qd.dayOfYear()-1].string) {
00101 QString holidayname = QString::fromLocal8Bit(holiday[qd.dayOfYear()-1].string);
00102 return holidayname;
00103 } else {
00104 return QString::null;
00105 }
00106 }
This file is part of the documentation for kdelibs Version 3.1.4.