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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 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 K_EXPORT_COMPONENT_FACTORY( libkorg_hebrew, HebrewFactory ) 00044 00045 00046 TQString Hebrew::shortText(const TQDate & date) 00047 { 00048 00049 KConfig config("korganizerrc", true, false); // Open read-only, no kdeglobals 00050 00051 config.setGroup("Calendar/Hebrew Calendar Plugin"); 00052 IsraelP = 00053 config.readBoolEntry("Israel", 00054 (KGlobal::locale()->country() == ".il")); 00055 Holiday::ParshaP = config.readBoolEntry("Parsha", true); 00056 Holiday::CholP = config.readBoolEntry("Chol_HaMoed", true); 00057 Holiday::OmerP = config.readBoolEntry("Omer", true); 00058 TQString label_text; 00059 00060 int day = date.day(); 00061 int month = date.month(); 00062 int year = date.year(); 00063 00064 // core calculations!! 00065 struct DateResult result; 00066 00067 Converter::SecularToHebrewConversion(year, month, day, /*0, */ 00068 &result); 00069 int hebrew_day = result.day; 00070 int hebrew_month = result.month; 00071 int hebrew_year = result.year; 00072 int hebrew_day_of_week = result.day_of_week; 00073 bool hebrew_leap_year_p = result.hebrew_leap_year_p; 00074 int hebrew_kvia = result.kvia; 00075 int hebrew_day_number = result.hebrew_day_number; 00076 00077 TQStringList holidays = 00078 Holiday::FindHoliday(hebrew_month, hebrew_day, 00079 hebrew_day_of_week + 1, hebrew_kvia, 00080 hebrew_leap_year_p, IsraelP, 00081 hebrew_day_number, hebrew_year); 00082 00083 KCalendarSystem *cal = KCalendarSystemFactory::create("hebrew"); 00084 label_text = TQString("%1 %2").arg(cal->dayString(date, false)) 00085 .arg(cal->monthName(date)); 00086 00087 if (holidays.count()) 00088 { 00089 int count = holidays.count(); 00090 00091 for (int h = 0; h <= count; ++h) 00092 { 00093 label_text += "\n" + holidays[h]; 00094 } 00095 } 00096 00097 return label_text; 00098 } 00099 00100 TQString Hebrew::info() 00101 { 00102 return 00103 i18n("This plugin provides the date in the Jewish calendar."); 00104 } 00105 00106 void Hebrew::configure(TQWidget * parent) 00107 { 00108 ConfigDialog *dlg = new ConfigDialog(parent); //parent? 00109 00110 dlg->exec(); 00111 delete dlg; 00112 }