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., 675 Mass Ave, Cambridge, MA 02139, USA.
00018 */
00019 
00020 // $Id: holidays.cpp,v 1.5.4.1 2003/07/16 19:12:41 mueller 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   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   //static int lastYear = 0;
00089   int lastYear = 0;
00090 
00091   if (mHolidayFile.isEmpty()) return QString::null;
00092 
00093   //if ((lastYear == 0) || (qd.year() != lastYear)) {
00094   if ((yearLast == 0) || (qd.year() != yearLast)) {
00095       yearLast = qd.year();
00096       lastYear = qd.year() - 1900; // silly parse_year takes 2 digit year...
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 }
KDE Logo
This file is part of the documentation for kdelibs Version 3.1.5.
Documentation copyright © 1996-2002 the KDE developers.
Generated on Sun Feb 15 11:41:08 2004 by doxygen 1.3.5 written by Dimitri van Heesch, © 1997-2001