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 351613 2004-10-03 18:33:19Z kainhofe $
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 "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;        /* name of holiday, 0=not a holiday */
00052     unsigned short  dup;            /* reference count */
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   //static int lastYear = 0;
00092   int lastYear = 0;
00093 
00094   if (mHolidayFile.isEmpty() || qd.isNull()) return QString::null;
00095 
00096   //if ((lastYear == 0) || (qd.year() != lastYear)) {
00097   if ((yearLast == 0) || (qd.year() != yearLast)) {
00098       yearLast = qd.year();
00099       lastYear = qd.year() - 1900; // silly parse_year takes 2 digit year...
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 }
KDE Logo
This file is part of the documentation for korganizer Library Version 3.3.2.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Wed Jul 25 11:20:58 2007 by doxygen 1.4.2 written by Dimitri van Heesch, © 1997-2003