korganizer Library API Documentation

holidays.cpp

00001 /* 00002 This file is part of KOrganizer. 00003 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> 00004 00005 This program is free software; you can redistribute it and/or modify 00006 it under the terms of the GNU General Public License as published by 00007 the Free Software Foundation; either version 2 of the License, or 00008 (at your option) any later version. 00009 00010 This program is distributed in the hope that it will be useful, 00011 but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 GNU General Public License for more details. 00014 00015 You should have received a copy of the GNU General Public License 00016 along with this program; if not, write to the Free Software 00017 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 00018 */ 00019 00020 // $Id: holidays.cpp,v 1.10 2003/12/11 18:40:02 mlaurent Exp $ 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; /* name of holiday, 0=not a holiday */ 00050 unsigned short dup; /* reference count */ 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 //static int lastYear = 0; 00091 int lastYear = 0; 00092 00093 if (mHolidayFile.isEmpty()) return QString::null; 00094 00095 //if ((lastYear == 0) || (qd.year() != lastYear)) { 00096 if ((yearLast == 0) || (qd.year() != yearLast)) { 00097 yearLast = qd.year(); 00098 lastYear = qd.year() - 1900; // silly parse_year takes 2 digit year... 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 }
KDE Logo
This file is part of the documentation for korganizer Library Version 3.2.2.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Wed Jul 28 23:58:12 2004 by doxygen 1.3.7 written by Dimitri van Heesch, © 1997-2003