hebrew.cpp
1 /*
2  This file is part of KOrganizer.
3  Copyright (c) 2003 Jonathan Singer <jsinger@leeta.net>
4 
5  This program is free software; you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation; either version 2 of the License, or
8  (at your option) any later version.
9 
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License
16  along with this program; if not, write to the Free Software
17  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 */
19 
20 #include <tdeglobal.h>
21 #include <tdeconfig.h>
22 #include <kstandarddirs.h>
23 #include <ksimpleconfig.h>
24 #include <kcalendarsystem.h>
25 #include <kcalendarsystemfactory.h>
26 #include "hebrew.h"
27 #include "configdialog.h"
28 #include "parsha.h"
29 #include "converter.h"
30 #include "holiday.h"
31 
32 bool Hebrew::IsraelP;
33 
34 class HebrewFactory:public CalendarDecorationFactory
35 {
36 public:
37  CalendarDecoration * create()
38  {
39  return new Hebrew;
40  }
41 };
42 
43 K_EXPORT_COMPONENT_FACTORY( libkorg_hebrew, HebrewFactory )
44 
45 
46 TQString Hebrew::shortText(const TQDate & date)
47 {
48 
49  TDEConfig config("korganizerrc", true, false); // Open read-only, no kdeglobals
50 
51  config.setGroup("Calendar/Hebrew Calendar Plugin");
52  IsraelP =
53  config.readBoolEntry("Israel",
54  (TDEGlobal::locale()->country() == ".il"));
55  Holiday::ParshaP = config.readBoolEntry("Parsha", true);
56  Holiday::CholP = config.readBoolEntry("Chol_HaMoed", true);
57  Holiday::OmerP = config.readBoolEntry("Omer", true);
58  TQString label_text;
59 
60  int day = date.day();
61  int month = date.month();
62  int year = date.year();
63 
64  // core calculations!!
65  struct DateResult result;
66 
67  Converter::SecularToHebrewConversion(year, month, day, /*0, */
68  &result);
69  int hebrew_day = result.day;
70  int hebrew_month = result.month;
71  int hebrew_year = result.year;
72  int hebrew_day_of_week = result.day_of_week;
73  bool hebrew_leap_year_p = result.hebrew_leap_year_p;
74  int hebrew_kvia = result.kvia;
75  int hebrew_day_number = result.hebrew_day_number;
76 
77  TQStringList holidays =
78  Holiday::FindHoliday(hebrew_month, hebrew_day,
79  hebrew_day_of_week + 1, hebrew_kvia,
80  hebrew_leap_year_p, IsraelP,
81  hebrew_day_number, hebrew_year);
82 
83  KCalendarSystem *cal = KCalendarSystemFactory::create("hebrew");
84  label_text = TQString("%1 %2").arg(cal->dayString(date, false))
85  .arg(cal->monthName(date));
86 
87  if (holidays.count())
88  {
89  int count = holidays.count();
90 
91  for (int h = 0; h <= count; ++h)
92  {
93  label_text += "\n" + holidays[h];
94  }
95  }
96 
97  return label_text;
98 }
99 
100 TQString Hebrew::info()
101 {
102  return
103  i18n("This plugin provides the date in the Jewish calendar.");
104 }
105 
106 void Hebrew::configure(TQWidget * parent)
107 {
108  ConfigDialog *dlg = new ConfigDialog(parent); //parent?
109 
110  dlg->exec();
111  delete dlg;
112 }
This class provides the interface for a date dependent decoration.