korganizer Library API Documentation

hebrew.cpp

00001 /*
00002     This file is part of KOrganizer.
00003     Copyright (c) 2003 Jonathan Singer <jsinger@leeta.net>
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 #include <kglobal.h>
00021 #include <kconfig.h>
00022 #include <kstandarddirs.h>
00023 #include <ksimpleconfig.h>
00024 #include <kcalendarsystem.h>
00025 #include <kcalendarsystemfactory.h>
00026 #include "hebrew.h"
00027 #include "configdialog.h"
00028 #include "parsha.h"
00029 #include "converter.h"
00030 #include "holiday.h"
00031 
00032 bool Hebrew::IsraelP;
00033 
00034 class HebrewFactory:public CalendarDecorationFactory
00035 {
00036 public:
00037   CalendarDecoration * create()
00038   {
00039     return new Hebrew;
00040   }
00041 };
00042 
00043 extern "C"
00044 {
00045   void *init_libkorg_hebrew()
00046   {
00047     return (new HebrewFactory);
00048   }
00049 }
00050 
00051 QString Hebrew::shortText(const QDate & date)
00052 {
00053 
00054   KConfig config(locateLocal("config", "korganizerrc"));
00055 
00056   config.setGroup("Calendar/Hebrew Calendar Plugin");
00057   IsraelP =
00058     config.readBoolEntry("Israel",
00059                          (KGlobal::locale()->country() == ".il"));
00060   Holiday::ParshaP = config.readBoolEntry("Parsha", true);
00061   Holiday::CholP = config.readBoolEntry("Chol_HaMoed", true);
00062   Holiday::OmerP = config.readBoolEntry("Omer", true);
00063   QString *label_text = new QString();
00064 
00065   int day = date.day();
00066   int month = date.month();
00067   int year = date.year();
00068 
00069   // core calculations!!
00070   struct DateResult result;
00071 
00072   Converter::SecularToHebrewConversion(year, month, day, /*0, */
00073                                        &result);
00074   int hebrew_day = result.day;
00075   int hebrew_month = result.month;
00076   int hebrew_year = result.year;
00077   int hebrew_day_of_week = result.day_of_week;
00078   bool hebrew_leap_year_p = result.hebrew_leap_year_p;
00079   int hebrew_kvia = result.kvia;
00080   int hebrew_day_number = result.hebrew_day_number;
00081 
00082   QStringList holidays =
00083     Holiday::FindHoliday(hebrew_month, hebrew_day,
00084                          hebrew_day_of_week + 1, hebrew_kvia,
00085                          hebrew_leap_year_p, IsraelP,
00086                          hebrew_day_number, hebrew_year);
00087 
00088   KCalendarSystem *cal = KCalendarSystemFactory::create("hebrew");
00089   *label_text = QString("%1 %2").arg(cal->dayString(date, false))
00090                                 .arg(cal->monthName(date));
00091 
00092   if (holidays.count())
00093       {
00094         int count = holidays.count();
00095 
00096         for (int h = 0; h <= count; h++)
00097             {
00098               *label_text += "\n" + holidays[h];
00099             }
00100       }
00101 
00102   return *label_text;
00103 }
00104 
00105 QString Hebrew::info()
00106 {
00107   return
00108     i18n("This plugin provides the date in the Jewish calendar.");
00109 }
00110 
00111 void Hebrew::configure(QWidget * parent)
00112 {
00113   ConfigDialog *dlg = new ConfigDialog(parent);        //parent?
00114 
00115   dlg->exec();
00116 }
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 Sat May 1 11:38:27 2004 by doxygen 1.2.15 written by Dimitri van Heesch, © 1997-2003