summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--core/pim/datebook/datebook.cpp1
-rw-r--r--core/pim/datebook/datebooksettings.cpp28
-rw-r--r--core/pim/datebook/datebooksettings.h6
-rw-r--r--core/pim/datebook/holiday/national/national-holidays.pro4
-rw-r--r--core/pim/datebook/holiday/national/nationalcfg.cpp11
-rw-r--r--core/pim/datebook/holiday/national/nationalcfgwidget.cpp99
-rw-r--r--core/pim/datebook/holiday/national/nationalcfgwidget.h39
-rw-r--r--core/pim/datebook/holiday/national/nationalholiday.cpp13
-rw-r--r--core/pim/datebook/holiday/national/nationalholiday.h2
-rw-r--r--libopie2/opiepim/ui/oholidayplugin.h6
-rw-r--r--libopie2/opiepim/ui/oholidayplugincfgwidget.cpp14
-rw-r--r--libopie2/opiepim/ui/oholidayplugincfgwidget.h30
-rw-r--r--libopie2/opiepim/ui/oholidaypluginif.h8
-rw-r--r--libopie2/opiepim/ui/ui.pro8
14 files changed, 247 insertions, 22 deletions
diff --git a/core/pim/datebook/datebook.cpp b/core/pim/datebook/datebook.cpp
index 8ae4f84..70dd7b5 100644
--- a/core/pim/datebook/datebook.cpp
+++ b/core/pim/datebook/datebook.cpp
@@ -1,1033 +1,1034 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved. 2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3** 3**
4** This file is part of Qtopia Environment. 4** This file is part of Qtopia Environment.
5** 5**
6** This file may be distributed and/or modified under the terms of the 6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software 7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the 8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file. 9** packaging of this file.
10** 10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13** 13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information. 14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15** 15**
16** Contact info@trolltech.com if any conditions of this licensing are 16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you. 17** not clear to you.
18** 18**
19** $Id$ 19** $Id$
20** 20**
21**********************************************************************/ 21**********************************************************************/
22 22
23#define QTOPIA_INTERNAL_FD 23#define QTOPIA_INTERNAL_FD
24 24
25#include "datebook.h" 25#include "datebook.h"
26#include "datebookday.h" 26#include "datebookday.h"
27#include "datebooksettings.h" 27#include "datebooksettings.h"
28#include "datebookweek.h" 28#include "datebookweek.h"
29#include "datebookweeklst.h" 29#include "datebookweeklst.h"
30#include "dateentryimpl.h" 30#include "dateentryimpl.h"
31 31
32#include <opie2/odebug.h> 32#include <opie2/odebug.h>
33#include <opie2/oholidaypluginif.h> 33#include <opie2/oholidaypluginif.h>
34#include <opie2/oholidayplugin.h> 34#include <opie2/oholidayplugin.h>
35#include <opie2/opluginloader.h> 35#include <opie2/opluginloader.h>
36#include <opie2/todayplugininterface.h> 36#include <opie2/todayplugininterface.h>
37 37
38#include <qpe/datebookmonth.h> 38#include <qpe/datebookmonth.h>
39#include <qpe/qpeapplication.h> 39#include <qpe/qpeapplication.h>
40#include <qpe/config.h> 40#include <qpe/config.h>
41#include <qpe/finddialog.h> 41#include <qpe/finddialog.h>
42#include <qpe/ir.h> 42#include <qpe/ir.h>
43#include <qpe/qpemessagebox.h> 43#include <qpe/qpemessagebox.h>
44#include <qpe/resource.h> 44#include <qpe/resource.h>
45#include <qpe/sound.h> 45#include <qpe/sound.h>
46#include <qpe/tzselect.h> 46#include <qpe/tzselect.h>
47 47
48#include <qaction.h> 48#include <qaction.h>
49#include <qcopchannel_qws.h> 49#include <qcopchannel_qws.h>
50#include <qlayout.h> 50#include <qlayout.h>
51#include <qmessagebox.h> 51#include <qmessagebox.h>
52#include <qtimer.h> 52#include <qtimer.h>
53#include <qtl.h> 53#include <qtl.h>
54#include <qtoolbar.h> 54#include <qtoolbar.h>
55#include <qwidgetstack.h> 55#include <qwidgetstack.h>
56#include <qdir.h> 56#include <qdir.h>
57#include <qtopia/qlibrary.h> 57#include <qtopia/qlibrary.h>
58 58
59#include <sys/stat.h> 59#include <sys/stat.h>
60#include <sys/types.h> 60#include <sys/types.h>
61#include <fcntl.h> 61#include <fcntl.h>
62#include <unistd.h> 62#include <unistd.h>
63 63
64#include <stdlib.h> 64#include <stdlib.h>
65 65
66DateBook::DateBook( QWidget *parent, const char *, WFlags f ) 66DateBook::DateBook( QWidget *parent, const char *, WFlags f )
67 : QMainWindow( parent, "datebook", f ), 67 : QMainWindow( parent, "datebook", f ),
68 aPreset( FALSE ), 68 aPreset( FALSE ),
69 presetTime( -1 ), 69 presetTime( -1 ),
70 startTime( 8 ), // an acceptable default 70 startTime( 8 ), // an acceptable default
71 rowStyle( 0 ), 71 rowStyle( 0 ),
72 bJumpToCurTime(FALSE), 72 bJumpToCurTime(FALSE),
73 syncing(FALSE), 73 syncing(FALSE),
74 inSearch(FALSE), 74 inSearch(FALSE),
75 alarmCounter(0) 75 alarmCounter(0)
76{ 76{
77 bool needEvilHack= false; // if we need an Evil Hack 77 bool needEvilHack= false; // if we need an Evil Hack
78 QTime t; 78 QTime t;
79 t.start(); 79 t.start();
80 db = new DateBookDBHoliday; 80 db = new DateBookDBHoliday;
81 odebug << "loading db t=" << t.elapsed() << oendl; 81 odebug << "loading db t=" << t.elapsed() << oendl;
82 db_holiday = new DateBookHoliday(); 82 db_holiday = new DateBookHoliday();
83 db->db_holiday=db_holiday; 83 db->db_holiday=db_holiday;
84 84
85 loadSettings(); 85 loadSettings();
86 setCaption( tr("Calendar") ); 86 setCaption( tr("Calendar") );
87 setIcon( Resource::loadPixmap( "datebook_icon" ) ); 87 setIcon( Resource::loadPixmap( "datebook_icon" ) );
88 88
89 setToolBarsMovable( FALSE ); 89 setToolBarsMovable( FALSE );
90 90
91 views = new QWidgetStack( this ); 91 views = new QWidgetStack( this );
92 setCentralWidget( views ); 92 setCentralWidget( views );
93 93
94 dayView = 0; 94 dayView = 0;
95 weekView = 0; 95 weekView = 0;
96 weekLstView = 0; 96 weekLstView = 0;
97 monthView = 0; 97 monthView = 0;
98 98
99// QToolBar *bar = new QToolBar( this ); 99// QToolBar *bar = new QToolBar( this );
100// bar->setHorizontalStretchable( TRUE ); 100// bar->setHorizontalStretchable( TRUE );
101 101
102// QMenuBar *mb = new QMenuBar( bar ); 102// QMenuBar *mb = new QMenuBar( bar );
103// mb->setMargin( 0 ); 103// mb->setMargin( 0 );
104 104
105// QPopupMenu *view = new QPopupMenu( this ); 105// QPopupMenu *view = new QPopupMenu( this );
106// mb->insertItem( tr( "View" ), view ); 106// mb->insertItem( tr( "View" ), view );
107 107
108 QToolBar *sub_bar = new QToolBar(this); 108 QToolBar *sub_bar = new QToolBar(this);
109 sub_bar->setHorizontalStretchable(TRUE); 109 sub_bar->setHorizontalStretchable(TRUE);
110 110
111 QActionGroup *g = new QActionGroup( this ); 111 QActionGroup *g = new QActionGroup( this );
112 g->setExclusive( TRUE ); 112 g->setExclusive( TRUE );
113 113
114 QAction *a = new QAction( tr( "New" ), Resource::loadPixmap( "new" ), QString::null, 0, this, 0 ); 114 QAction *a = new QAction( tr( "New" ), Resource::loadPixmap( "new" ), QString::null, 0, this, 0 );
115 connect( a, SIGNAL( activated() ), this, SLOT( fileNew() ) ); 115 connect( a, SIGNAL( activated() ), this, SLOT( fileNew() ) );
116 a->addTo( sub_bar ); 116 a->addTo( sub_bar );
117 117
118 sub_bar->addSeparator(); 118 sub_bar->addSeparator();
119 119
120 a = new QAction( tr( "Today" ), Resource::loadPixmap( "datebook/to_day" ), QString::null, 0, g, 0 ); 120 a = new QAction( tr( "Today" ), Resource::loadPixmap( "datebook/to_day" ), QString::null, 0, g, 0 );
121 connect( a, SIGNAL( activated() ), this, SLOT( slotToday() ) ); 121 connect( a, SIGNAL( activated() ), this, SLOT( slotToday() ) );
122 a->addTo( sub_bar ); 122 a->addTo( sub_bar );
123// a->addTo( view ); 123// a->addTo( view );
124 124
125 sub_bar->addSeparator(); 125 sub_bar->addSeparator();
126 126
127 a = new QAction( tr( "Day" ), Resource::loadPixmap( "day" ), QString::null, 0, g, 0 ); 127 a = new QAction( tr( "Day" ), Resource::loadPixmap( "day" ), QString::null, 0, g, 0 );
128 connect( a, SIGNAL( activated() ), this, SLOT( viewDay() ) ); 128 connect( a, SIGNAL( activated() ), this, SLOT( viewDay() ) );
129 a->addTo( sub_bar ); 129 a->addTo( sub_bar );
130// a->addTo( view ); 130// a->addTo( view );
131 a->setToggleAction( TRUE ); 131 a->setToggleAction( TRUE );
132 a->setOn( TRUE ); 132 a->setOn( TRUE );
133 dayAction = a; 133 dayAction = a;
134 134
135 a = new QAction( tr( "Week" ), Resource::loadPixmap( "week" ), QString::null, 0, g, 0 ); 135 a = new QAction( tr( "Week" ), Resource::loadPixmap( "week" ), QString::null, 0, g, 0 );
136 connect( a, SIGNAL( activated() ), this, SLOT( viewWeek() ) ); 136 connect( a, SIGNAL( activated() ), this, SLOT( viewWeek() ) );
137 a->addTo( sub_bar ); 137 a->addTo( sub_bar );
138// a->addTo( view ); 138// a->addTo( view );
139 a->setToggleAction( TRUE ); 139 a->setToggleAction( TRUE );
140 weekAction = a; 140 weekAction = a;
141 141
142 a = new QAction( tr( "WeekLst" ), Resource::loadPixmap( "datebook/weeklst" ), QString::null, 0, g, 0 ); 142 a = new QAction( tr( "WeekLst" ), Resource::loadPixmap( "datebook/weeklst" ), QString::null, 0, g, 0 );
143 connect( a, SIGNAL( activated() ), this, SLOT( viewWeekLst() ) ); 143 connect( a, SIGNAL( activated() ), this, SLOT( viewWeekLst() ) );
144 a->addTo( sub_bar ); 144 a->addTo( sub_bar );
145// a->addTo( view ); 145// a->addTo( view );
146 a->setToggleAction( TRUE ); 146 a->setToggleAction( TRUE );
147 weekLstAction = a; 147 weekLstAction = a;
148 148
149 a = new QAction( tr( "Month" ), Resource::loadPixmap( "month" ), QString::null, 0, g, 0 ); 149 a = new QAction( tr( "Month" ), Resource::loadPixmap( "month" ), QString::null, 0, g, 0 );
150 connect( a, SIGNAL( activated() ), this, SLOT( viewMonth() ) ); 150 connect( a, SIGNAL( activated() ), this, SLOT( viewMonth() ) );
151 a->addTo( sub_bar ); 151 a->addTo( sub_bar );
152// a->addTo( view ); 152// a->addTo( view );
153 a->setToggleAction( TRUE ); 153 a->setToggleAction( TRUE );
154 monthAction = a; 154 monthAction = a;
155 155
156 sub_bar->addSeparator(); 156 sub_bar->addSeparator();
157 157
158 a = new QAction( tr( "Find" ), Resource::loadPixmap( "mag" ), QString::null, 0, this, 0 ); 158 a = new QAction( tr( "Find" ), Resource::loadPixmap( "mag" ), QString::null, 0, this, 0 );
159 connect( a, SIGNAL(activated()), this, SLOT(slotFind()) ); 159 connect( a, SIGNAL(activated()), this, SLOT(slotFind()) );
160 a->addTo( sub_bar ); 160 a->addTo( sub_bar );
161 161
162 a = new QAction( tr( "Edit..." ), Resource::loadPixmap("SettingsIcon"), QString::null, 0, this, 0 ); 162 a = new QAction( tr( "Edit..." ), Resource::loadPixmap("SettingsIcon"), QString::null, 0, this, 0 );
163 connect( a, SIGNAL( activated() ), this, SLOT( slotSettings() ) ); 163 connect( a, SIGNAL( activated() ), this, SLOT( slotSettings() ) );
164 a->addTo( sub_bar ); 164 a->addTo( sub_bar );
165 165
166 if(defaultView==DAY) viewDay(); 166 if(defaultView==DAY) viewDay();
167 if(defaultView==WEEK) needEvilHack=true; // viewWeek(); 167 if(defaultView==WEEK) needEvilHack=true; // viewWeek();
168 if(defaultView==WEEKLST) viewWeekLst(); 168 if(defaultView==WEEKLST) viewWeekLst();
169 if(defaultView==MONTH) viewMonth(); 169 if(defaultView==MONTH) viewMonth();
170 170
171 connect( qApp, SIGNAL(clockChanged(bool)), this, SLOT(changeClock(bool)) ); 171 connect( qApp, SIGNAL(clockChanged(bool)), this, SLOT(changeClock(bool)) );
172 connect( qApp, SIGNAL(weekChanged(bool)), this, SLOT(changeWeek(bool)) ); 172 connect( qApp, SIGNAL(weekChanged(bool)), this, SLOT(changeWeek(bool)) );
173 173
174#if defined(Q_WS_QWS) && !defined(QT_NO_COP) 174#if defined(Q_WS_QWS) && !defined(QT_NO_COP)
175 connect( qApp, SIGNAL(appMessage(const QCString&,const QByteArray&)), this, SLOT(appMessage(const QCString&,const QByteArray&)) ); 175 connect( qApp, SIGNAL(appMessage(const QCString&,const QByteArray&)), this, SLOT(appMessage(const QCString&,const QByteArray&)) );
176#endif 176#endif
177 177
178 // listen on QPE/System 178 // listen on QPE/System
179#if defined(Q_WS_QWS) 179#if defined(Q_WS_QWS)
180#if !defined(QT_NO_COP) 180#if !defined(QT_NO_COP)
181 QCopChannel *channel = new QCopChannel( "QPE/System", this ); 181 QCopChannel *channel = new QCopChannel( "QPE/System", this );
182 connect( channel, SIGNAL(received(const QCString&,const QByteArray&)), this, SLOT(receive(const QCString&,const QByteArray&)) ); 182 connect( channel, SIGNAL(received(const QCString&,const QByteArray&)), this, SLOT(receive(const QCString&,const QByteArray&)) );
183 channel = new QCopChannel( "QPE/Datebook", this ); 183 channel = new QCopChannel( "QPE/Datebook", this );
184 connect( channel, SIGNAL(received(const QCString&,const QByteArray&)), this, SLOT(receive(const QCString&,const QByteArray&)) ); 184 connect( channel, SIGNAL(received(const QCString&,const QByteArray&)), this, SLOT(receive(const QCString&,const QByteArray&)) );
185#endif 185#endif
186#endif 186#endif
187 187
188 odebug << "done t=" << t.elapsed() << oendl; 188 odebug << "done t=" << t.elapsed() << oendl;
189 189
190 connect( qApp, SIGNAL( flush() ), this, SLOT( flush() ) ); 190 connect( qApp, SIGNAL( flush() ), this, SLOT( flush() ) );
191 connect( qApp, SIGNAL( reload()), this, SLOT( reload() ) ); 191 connect( qApp, SIGNAL( reload()), this, SLOT( reload() ) );
192 /* 192 /*
193 * Here is a problem description: 193 * Here is a problem description:
194 * When Weekview is the default view 194 * When Weekview is the default view
195 * a DateBookWeekView get's created 195 * a DateBookWeekView get's created
196 * redraw() get's called. So what? 196 * redraw() get's called. So what?
197 * Remember that we're still in the c'tor 197 * Remember that we're still in the c'tor
198 * and no final layout has happened? Ok 198 * and no final layout has happened? Ok
199 * now all Events get arranged. Their x 199 * now all Events get arranged. Their x
200 * position get's determined by a QHeader 200 * position get's determined by a QHeader
201 * position. But the QHeader isn't layouted or 201 * position. But the QHeader isn't layouted or
202 * at the right position. redraw() is a slot 202 * at the right position. redraw() is a slot
203 * so we'll call it then via a singleShot 203 * so we'll call it then via a singleShot
204 * from view() 204 * from view()
205 */ 205 */
206 if( needEvilHack ){ 206 if( needEvilHack ){
207 QTimer::singleShot( 500, this, SLOT(viewWeek()) ); 207 QTimer::singleShot( 500, this, SLOT(viewWeek()) );
208 } 208 }
209} 209}
210 210
211void DateBook::receive( const QCString &msg, const QByteArray &data ) 211void DateBook::receive( const QCString &msg, const QByteArray &data )
212{ 212{
213 QDataStream stream( data, IO_ReadOnly ); 213 QDataStream stream( data, IO_ReadOnly );
214 if ( msg == "timeChange(QString)" ) { 214 if ( msg == "timeChange(QString)" ) {
215 // update active view! 215 // update active view!
216 if ( dayAction->isOn() ) 216 if ( dayAction->isOn() )
217 viewDay(); 217 viewDay();
218 else if ( weekAction->isOn() ) 218 else if ( weekAction->isOn() )
219 viewWeek(); 219 viewWeek();
220 else if ( monthAction->isOn() ) 220 else if ( monthAction->isOn() )
221 viewMonth(); 221 viewMonth();
222 } 222 }
223 else if (msg == "editEvent(int)") { 223 else if (msg == "editEvent(int)") {
224 int uid; 224 int uid;
225 stream >> uid; 225 stream >> uid;
226 Event e=db->eventByUID(uid); 226 Event e=db->eventByUID(uid);
227 editEvent(e); 227 editEvent(e);
228 }else if (msg == "viewDefault(QDate)"){ 228 }else if (msg == "viewDefault(QDate)"){
229 QDate day; 229 QDate day;
230 stream >> day; 230 stream >> day;
231 viewDefault(day); 231 viewDefault(day);
232 } 232 }
233} 233}
234 234
235DateBook::~DateBook() 235DateBook::~DateBook()
236{ 236{
237 delete db_holiday; 237 delete db_holiday;
238} 238}
239 239
240void DateBook::slotSettings() 240void DateBook::slotSettings()
241{ 241{
242 DateBookSettings frmSettings( ampm, this ); 242 DateBookSettings frmSettings( ampm, this );
243 frmSettings.setStartTime( startTime ); 243 frmSettings.setStartTime( startTime );
244 frmSettings.setAlarmPreset( aPreset, presetTime ); 244 frmSettings.setAlarmPreset( aPreset, presetTime );
245 frmSettings.setJumpToCurTime( bJumpToCurTime ); 245 frmSettings.setJumpToCurTime( bJumpToCurTime );
246 frmSettings.setRowStyle( rowStyle ); 246 frmSettings.setRowStyle( rowStyle );
247 frmSettings.comboDefaultView->setCurrentItem(defaultView-1); 247 frmSettings.comboDefaultView->setCurrentItem(defaultView-1);
248 frmSettings.comboWeekListView->setCurrentItem(weeklistviewconfig); 248 frmSettings.comboWeekListView->setCurrentItem(weeklistviewconfig);
249 frmSettings.setPluginList(db_holiday->pluginManager(),db_holiday->pluginLoader()); 249 frmSettings.setPluginList(db_holiday->pluginManager(),db_holiday->pluginLoader());
250 250
251 bool found=false; 251 bool found=false;
252 for (int i=0; i<(frmSettings.comboLocation->count()); i++) { 252 for (int i=0; i<(frmSettings.comboLocation->count()); i++) {
253 if ( frmSettings.comboLocation->text(i) == defaultLocation ) { 253 if ( frmSettings.comboLocation->text(i) == defaultLocation ) {
254 frmSettings.comboLocation->setCurrentItem(i); 254 frmSettings.comboLocation->setCurrentItem(i);
255 found=true; 255 found=true;
256 break; 256 break;
257 } 257 }
258 } 258 }
259 if(!found) { 259 if(!found) {
260 frmSettings.comboLocation->insertItem(defaultLocation); 260 frmSettings.comboLocation->insertItem(defaultLocation);
261 frmSettings.comboLocation->setCurrentItem(frmSettings.comboLocation->count()-1); 261 frmSettings.comboLocation->setCurrentItem(frmSettings.comboLocation->count()-1);
262 } 262 }
263 frmSettings.comboCategory->setCategories(defaultCategories,"Calendar", tr("Calendar")); 263 frmSettings.comboCategory->setCategories(defaultCategories,"Calendar", tr("Calendar"));
264 264
265 if ( QPEApplication::execDialog( &frmSettings ) ) { 265 if ( QPEApplication::execDialog( &frmSettings ) ) {
266 frmSettings.savePlugins();
266 db_holiday->pluginManager()->save(); 267 db_holiday->pluginManager()->save();
267 db_holiday->reloadPlugins(); 268 db_holiday->reloadPlugins();
268 269
269 aPreset = frmSettings.alarmPreset(); 270 aPreset = frmSettings.alarmPreset();
270 presetTime = frmSettings.presetTime(); 271 presetTime = frmSettings.presetTime();
271 startTime = frmSettings.startTime(); 272 startTime = frmSettings.startTime();
272 bJumpToCurTime = frmSettings.jumpToCurTime(); 273 bJumpToCurTime = frmSettings.jumpToCurTime();
273 rowStyle = frmSettings.rowStyle(); 274 rowStyle = frmSettings.rowStyle();
274 defaultView=frmSettings.comboDefaultView->currentItem()+1; 275 defaultView=frmSettings.comboDefaultView->currentItem()+1;
275 weeklistviewconfig=frmSettings.comboWeekListView->currentItem(); 276 weeklistviewconfig=frmSettings.comboWeekListView->currentItem();
276 defaultLocation=frmSettings.comboLocation->currentText(); 277 defaultLocation=frmSettings.comboLocation->currentText();
277 defaultCategories=frmSettings.comboCategory->currentCategories(); 278 defaultCategories=frmSettings.comboCategory->currentCategories();
278 279
279 if ( dayView ) { 280 if ( dayView ) {
280 dayView->setStartViewTime( startTime ); 281 dayView->setStartViewTime( startTime );
281 dayView->setJumpToCurTime( bJumpToCurTime ); 282 dayView->setJumpToCurTime( bJumpToCurTime );
282 dayView->setRowStyle( rowStyle ); 283 dayView->setRowStyle( rowStyle );
283 } 284 }
284 if ( weekView ) { 285 if ( weekView ) {
285 weekView->setStartViewTime( startTime ); 286 weekView->setStartViewTime( startTime );
286 } 287 }
287 saveSettings(); 288 saveSettings();
288 289
289 // make the change obvious 290 // make the change obvious
290 if ( views->visibleWidget() ) { 291 if ( views->visibleWidget() ) {
291 if ( views->visibleWidget() == dayView ) 292 if ( views->visibleWidget() == dayView )
292 dayView->redraw(); 293 dayView->redraw();
293 else if ( views->visibleWidget() == weekView ) 294 else if ( views->visibleWidget() == weekView )
294 weekView->redraw(); 295 weekView->redraw();
295 else if ( views->visibleWidget() == weekLstView ) 296 else if ( views->visibleWidget() == weekLstView )
296 weekLstView->redraw(); 297 weekLstView->redraw();
297 } 298 }
298 } 299 }
299} 300}
300 301
301void DateBook::fileNew() 302void DateBook::fileNew()
302{ 303{
303 slotNewEventFromKey(""); 304 slotNewEventFromKey("");
304} 305}
305 306
306QString DateBook::checkEvent(const Event &e) 307QString DateBook::checkEvent(const Event &e)
307{ 308{
308 /* check if overlaps with itself */ 309 /* check if overlaps with itself */
309 bool checkFailed = FALSE; 310 bool checkFailed = FALSE;
310 311
311 /* check the next 12 repeats. should catch most problems */ 312 /* check the next 12 repeats. should catch most problems */
312 QDate current_date = e.start().date(); 313 QDate current_date = e.start().date();
313 Event previous = e; 314 Event previous = e;
314 for(int i = 0; i < 12; i++) 315 for(int i = 0; i < 12; i++)
315 { 316 {
316 QDateTime next; 317 QDateTime next;
317 if (!nextOccurance(previous, current_date.addDays(1), next)) { 318 if (!nextOccurance(previous, current_date.addDays(1), next)) {
318 break; // no more repeats 319 break; // no more repeats
319 } 320 }
320 if(next < previous.end()) { 321 if(next < previous.end()) {
321 checkFailed = TRUE; 322 checkFailed = TRUE;
322 break; 323 break;
323 } 324 }
324 current_date = next.date(); 325 current_date = next.date();
325 } 326 }
326 327
327 if(checkFailed) 328 if(checkFailed)
328 return tr("Event duration is potentially longer\n" 329 return tr("Event duration is potentially longer\n"
329 "than interval between repeats."); 330 "than interval between repeats.");
330 331
331 return QString::null; 332 return QString::null;
332} 333}
333 334
334QDate DateBook::currentDate() 335QDate DateBook::currentDate()
335{ 336{
336 QDate d = QDate::currentDate(); 337 QDate d = QDate::currentDate();
337 338
338 if ( dayView && views->visibleWidget() == dayView ) { 339 if ( dayView && views->visibleWidget() == dayView ) {
339 d = dayView->date(); 340 d = dayView->date();
340 } else if ( weekView && views->visibleWidget() == weekView ) { 341 } else if ( weekView && views->visibleWidget() == weekView ) {
341 d = weekView->date(); 342 d = weekView->date();
342 } else if ( weekLstView && views->visibleWidget() == weekLstView ) { 343 } else if ( weekLstView && views->visibleWidget() == weekLstView ) {
343 d = weekLstView->date(); 344 d = weekLstView->date();
344 } else if ( monthView && views->visibleWidget() == monthView ) { 345 } else if ( monthView && views->visibleWidget() == monthView ) {
345 d = monthView->selectedDate(); 346 d = monthView->selectedDate();
346 } 347 }
347 348
348 return d; 349 return d;
349} 350}
350 351
351void DateBook::view(int v, const QDate &d) { 352void DateBook::view(int v, const QDate &d) {
352 if (v==DAY) { 353 if (v==DAY) {
353 initDay(); 354 initDay();
354 dayAction->setOn( TRUE ); 355 dayAction->setOn( TRUE );
355 dayView->setDate( d ); 356 dayView->setDate( d );
356 views->raiseWidget( dayView ); 357 views->raiseWidget( dayView );
357 dayView->redraw(); 358 dayView->redraw();
358 } else if (v==WEEK) { 359 } else if (v==WEEK) {
359 initWeek(); 360 initWeek();
360 weekAction->setOn( TRUE ); 361 weekAction->setOn( TRUE );
361 weekView->setDate( d ); 362 weekView->setDate( d );
362 views->raiseWidget( weekView ); 363 views->raiseWidget( weekView );
363 weekView->redraw(); 364 weekView->redraw();
364 } else if (v==WEEKLST) { 365 } else if (v==WEEKLST) {
365 initWeekLst(); 366 initWeekLst();
366 weekLstAction->setOn( TRUE ); 367 weekLstAction->setOn( TRUE );
367 weekLstView->setDate(d); 368 weekLstView->setDate(d);
368 views->raiseWidget( weekLstView ); 369 views->raiseWidget( weekLstView );
369 weekLstView->redraw(); 370 weekLstView->redraw();
370 } else if (v==MONTH) { 371 } else if (v==MONTH) {
371 initMonth(); 372 initMonth();
372 monthAction->setOn( TRUE ); 373 monthAction->setOn( TRUE );
373 monthView->setDate( d.year(), d.month(), d.day() ); 374 monthView->setDate( d.year(), d.month(), d.day() );
374 views->raiseWidget( monthView ); 375 views->raiseWidget( monthView );
375 monthView->redraw(); 376 monthView->redraw();
376 } 377 }
377} 378}
378 379
379void DateBook::viewDefault(const QDate &d) { 380void DateBook::viewDefault(const QDate &d) {
380 view(defaultView,d); 381 view(defaultView,d);
381} 382}
382 383
383void DateBook::viewDay() { 384void DateBook::viewDay() {
384 view(DAY,currentDate()); 385 view(DAY,currentDate());
385} 386}
386 387
387void DateBook::viewWeek() { 388void DateBook::viewWeek() {
388 view(WEEK,currentDate()); 389 view(WEEK,currentDate());
389} 390}
390 391
391void DateBook::viewWeekLst() { 392void DateBook::viewWeekLst() {
392 view(WEEKLST,currentDate()); 393 view(WEEKLST,currentDate());
393} 394}
394 395
395void DateBook::viewMonth() { 396void DateBook::viewMonth() {
396 view(MONTH,currentDate()); 397 view(MONTH,currentDate());
397} 398}
398 399
399void DateBook::insertEvent( const Event &e ) 400void DateBook::insertEvent( const Event &e )
400{ 401{
401 Event dupEvent=e; 402 Event dupEvent=e;
402 if(!dupEvent.isValidUid() ) // tkcRom seems to be different 403 if(!dupEvent.isValidUid() ) // tkcRom seems to be different
403 dupEvent.assignUid(); 404 dupEvent.assignUid();
404 dupEvent.setLocation(defaultLocation); 405 dupEvent.setLocation(defaultLocation);
405 dupEvent.setCategories(defaultCategories); 406 dupEvent.setCategories(defaultCategories);
406 db->addEvent(dupEvent); 407 db->addEvent(dupEvent);
407 emit newEvent(); 408 emit newEvent();
408} 409}
409 410
410void DateBook::duplicateEvent( const Event &e ) 411void DateBook::duplicateEvent( const Event &e )
411{ 412{
412 // Alot of code duplication, as this is almost like editEvent(); 413 // Alot of code duplication, as this is almost like editEvent();
413 if (syncing) { 414 if (syncing) {
414 QMessageBox::warning( this, tr("Calendar"), tr( "Can not edit data, currently syncing") ); 415 QMessageBox::warning( this, tr("Calendar"), tr( "Can not edit data, currently syncing") );
415 return; 416 return;
416 } 417 }
417 418
418 Event dupevent(e); // Make a duplicate. 419 Event dupevent(e); // Make a duplicate.
419 420
420 // workaround added for text input. 421 // workaround added for text input.
421 QDialog editDlg( this, 0, TRUE ); 422 QDialog editDlg( this, 0, TRUE );
422 DateEntry *entry; 423 DateEntry *entry;
423 editDlg.setCaption( tr("Duplicate Event") ); 424 editDlg.setCaption( tr("Duplicate Event") );
424 QVBoxLayout *vb = new QVBoxLayout( &editDlg ); 425 QVBoxLayout *vb = new QVBoxLayout( &editDlg );
425 QScrollView *sv = new QScrollView( &editDlg, "scrollview" ); 426 QScrollView *sv = new QScrollView( &editDlg, "scrollview" );
426 sv->setResizePolicy( QScrollView::AutoOneFit ); 427 sv->setResizePolicy( QScrollView::AutoOneFit );
427 // KLUDGE!!! 428 // KLUDGE!!!
428 sv->setHScrollBarMode( QScrollView::AlwaysOff ); 429 sv->setHScrollBarMode( QScrollView::AlwaysOff );
429 vb->addWidget( sv ); 430 vb->addWidget( sv );
430 entry = new DateEntry( onMonday, dupevent, ampm, &editDlg, "editor" ); 431 entry = new DateEntry( onMonday, dupevent, ampm, &editDlg, "editor" );
431 entry->timezone->setEnabled( FALSE ); 432 entry->timezone->setEnabled( FALSE );
432 sv->addChild( entry ); 433 sv->addChild( entry );
433 434
434 while ( QPEApplication::execDialog( &editDlg ) ) { 435 while ( QPEApplication::execDialog( &editDlg ) ) {
435 Event newEv = entry->event(); 436 Event newEv = entry->event();
436 QString error = checkEvent(newEv); 437 QString error = checkEvent(newEv);
437 if (!error.isNull()) { 438 if (!error.isNull()) {
438 if (QMessageBox::warning(this, tr("error box"), error, tr("Fix it"), tr("Continue"), 0, 0, 1) == 0) 439 if (QMessageBox::warning(this, tr("error box"), error, tr("Fix it"), tr("Continue"), 0, 0, 1) == 0)
439 continue; 440 continue;
440 } 441 }
441 /* 442 /*
442 * The problem: 443 * The problem:
443 * DateBookDB does remove repeating events not by uid but by the time 444 * DateBookDB does remove repeating events not by uid but by the time
444 * the recurrence was created 445 * the recurrence was created
445 * so we need to update that time as well 446 * so we need to update that time as well
446 */ 447 */
447 Event::RepeatPattern rp = newEv.repeatPattern(); 448 Event::RepeatPattern rp = newEv.repeatPattern();
448 rp.createTime = ::time( NULL ); 449 rp.createTime = ::time( NULL );
449 newEv.setRepeat( TRUE, rp ); // has repeat and repeatPattern... 450 newEv.setRepeat( TRUE, rp ); // has repeat and repeatPattern...
450 if( newEv.uid() == e.uid() || !newEv.isValidUid() ) 451 if( newEv.uid() == e.uid() || !newEv.isValidUid() )
451 newEv.assignUid(); 452 newEv.assignUid();
452 453
453 db->addEvent(newEv); 454 db->addEvent(newEv);
454 emit newEvent(); 455 emit newEvent();
455 break; 456 break;
456 } 457 }
457} 458}
458 459
459void DateBook::editEvent( const Event &e ) 460void DateBook::editEvent( const Event &e )
460{ 461{
461 if (syncing) { 462 if (syncing) {
462 QMessageBox::warning( this, tr("Calendar"), tr( "Can not edit data, currently syncing") ); 463 QMessageBox::warning( this, tr("Calendar"), tr( "Can not edit data, currently syncing") );
463 return; 464 return;
464 } 465 }
465 466
466 // workaround added for text input. 467 // workaround added for text input.
467 QDialog editDlg( this, 0, TRUE ); 468 QDialog editDlg( this, 0, TRUE );
468 DateEntry *entry; 469 DateEntry *entry;
469 editDlg.setCaption( tr("Edit Event") ); 470 editDlg.setCaption( tr("Edit Event") );
470 QVBoxLayout *vb = new QVBoxLayout( &editDlg ); 471 QVBoxLayout *vb = new QVBoxLayout( &editDlg );
471 QScrollView *sv = new QScrollView( &editDlg, "scrollview" ); 472 QScrollView *sv = new QScrollView( &editDlg, "scrollview" );
472 sv->setResizePolicy( QScrollView::AutoOneFit ); 473 sv->setResizePolicy( QScrollView::AutoOneFit );
473 // KLUDGE!!! 474 // KLUDGE!!!
474 sv->setHScrollBarMode( QScrollView::AlwaysOff ); 475 sv->setHScrollBarMode( QScrollView::AlwaysOff );
475 vb->addWidget( sv ); 476 vb->addWidget( sv );
476 entry = new DateEntry( onMonday, e, ampm, &editDlg, "editor" ); 477 entry = new DateEntry( onMonday, e, ampm, &editDlg, "editor" );
477 entry->timezone->setEnabled( FALSE ); 478 entry->timezone->setEnabled( FALSE );
478 sv->addChild( entry ); 479 sv->addChild( entry );
479 480
480 while ( QPEApplication::execDialog( &editDlg ) ) { 481 while ( QPEApplication::execDialog( &editDlg ) ) {
481 Event newEv = entry->event(); 482 Event newEv = entry->event();
482 if(newEv.description().isEmpty() && newEv.notes().isEmpty() ) 483 if(newEv.description().isEmpty() && newEv.notes().isEmpty() )
483 break; 484 break;
484 newEv.setUid(e.uid()); // FIXME: Hack not to clear uid 485 newEv.setUid(e.uid()); // FIXME: Hack not to clear uid
485 QString error = checkEvent(newEv); 486 QString error = checkEvent(newEv);
486 if (!error.isNull()) { 487 if (!error.isNull()) {
487 if (QMessageBox::warning(this, tr("error box"), error, tr("Fix it"), tr("Continue"), 0, 0, 1) == 0) continue; 488 if (QMessageBox::warning(this, tr("error box"), error, tr("Fix it"), tr("Continue"), 0, 0, 1) == 0) continue;
488 } 489 }
489 db->editEvent(e, newEv); 490 db->editEvent(e, newEv);
490 emit newEvent(); 491 emit newEvent();
491 break; 492 break;
492 } 493 }
493} 494}
494 495
495void DateBook::removeEvent( const Event &e ) 496void DateBook::removeEvent( const Event &e )
496{ 497{
497 if (syncing) { 498 if (syncing) {
498 QMessageBox::warning( this, tr("Calendar"), tr( "Can not edit data, currently syncing") ); 499 QMessageBox::warning( this, tr("Calendar"), tr( "Can not edit data, currently syncing") );
499 return; 500 return;
500 } 501 }
501 502
502 QString strName = e.description(); 503 QString strName = e.description();
503 504
504 if ( !QPEMessageBox::confirmDelete( this, tr( "Calendar" ),strName ) ) 505 if ( !QPEMessageBox::confirmDelete( this, tr( "Calendar" ),strName ) )
505 return; 506 return;
506 507
507 db->removeEvent( e ); 508 db->removeEvent( e );
508 if ( views->visibleWidget() == dayView && dayView ) 509 if ( views->visibleWidget() == dayView && dayView )
509 dayView->redraw(); 510 dayView->redraw();
510 511
511} 512}
512 513
513void DateBook::addEvent( const Event &e ) 514void DateBook::addEvent( const Event &e )
514{ 515{
515 QDate d = e.start().date(); 516 QDate d = e.start().date();
516 initDay(); 517 initDay();
517 dayView->setDate( d ); 518 dayView->setDate( d );
518} 519}
519 520
520void DateBook::showDay( int year, int month, int day ) 521void DateBook::showDay( int year, int month, int day )
521{ 522{
522 QDate d(year, month, day); 523 QDate d(year, month, day);
523 view(DAY,d); 524 view(DAY,d);
524} 525}
525 526
526void DateBook::initDay() 527void DateBook::initDay()
527{ 528{
528 if ( !dayView ) { 529 if ( !dayView ) {
529 dayView = new DateBookDay( ampm, onMonday, db, db_holiday, views, "day view" ); 530 dayView = new DateBookDay( ampm, onMonday, db, db_holiday, views, "day view" );
530 views->addWidget( dayView, DAY ); 531 views->addWidget( dayView, DAY );
531 dayView->setJumpToCurTime( bJumpToCurTime ); 532 dayView->setJumpToCurTime( bJumpToCurTime );
532 dayView->setStartViewTime( startTime ); 533 dayView->setStartViewTime( startTime );
533 dayView->setRowStyle( rowStyle ); 534 dayView->setRowStyle( rowStyle );
534 connect( this, SIGNAL( newEvent() ), dayView, SLOT( redraw() ) ); 535 connect( this, SIGNAL( newEvent() ), dayView, SLOT( redraw() ) );
535 connect( dayView, SIGNAL( newEvent() ), this, SLOT( fileNew() ) ); 536 connect( dayView, SIGNAL( newEvent() ), this, SLOT( fileNew() ) );
536 connect( dayView, SIGNAL( removeEvent(const Event&) ), this, SLOT( removeEvent(const Event&) ) ); 537 connect( dayView, SIGNAL( removeEvent(const Event&) ), this, SLOT( removeEvent(const Event&) ) );
537 connect( dayView, SIGNAL( editEvent(const Event&) ), this, SLOT( editEvent(const Event&) ) ); 538 connect( dayView, SIGNAL( editEvent(const Event&) ), this, SLOT( editEvent(const Event&) ) );
538 connect( dayView, SIGNAL( duplicateEvent(const Event&) ), this, SLOT( duplicateEvent(const Event&) ) ); 539 connect( dayView, SIGNAL( duplicateEvent(const Event&) ), this, SLOT( duplicateEvent(const Event&) ) );
539 connect( dayView, SIGNAL( beamEvent(const Event&) ), this, SLOT( beamEvent(const Event&) ) ); 540 connect( dayView, SIGNAL( beamEvent(const Event&) ), this, SLOT( beamEvent(const Event&) ) );
540 connect( dayView, SIGNAL(sigNewEvent(const QString&)), this, SLOT(slotNewEventFromKey(const QString&)) ); 541 connect( dayView, SIGNAL(sigNewEvent(const QString&)), this, SLOT(slotNewEventFromKey(const QString&)) );
541 } 542 }
542} 543}
543 544
544void DateBook::initWeek() 545void DateBook::initWeek()
545{ 546{
546 if ( !weekView ) { 547 if ( !weekView ) {
547 weekView = new DateBookWeek( ampm, onMonday, db, views, "week view" ); 548 weekView = new DateBookWeek( ampm, onMonday, db, views, "week view" );
548 weekView->setStartViewTime( startTime ); 549 weekView->setStartViewTime( startTime );
549 views->addWidget( weekView, WEEK ); 550 views->addWidget( weekView, WEEK );
550 connect( weekView, SIGNAL( showDate(int,int,int) ), this, SLOT( showDay(int,int,int) ) ); 551 connect( weekView, SIGNAL( showDate(int,int,int) ), this, SLOT( showDay(int,int,int) ) );
551 connect( this, SIGNAL( newEvent() ), weekView, SLOT( redraw() ) ); 552 connect( this, SIGNAL( newEvent() ), weekView, SLOT( redraw() ) );
552 } 553 }
553 554
554 //But also get it right: the year that we display can be different 555 //But also get it right: the year that we display can be different
555 //from the year of the current date. So, first find the year 556 //from the year of the current date. So, first find the year
556 //number of the current week. 557 //number of the current week.
557 int yearNumber, totWeeks; 558 int yearNumber, totWeeks;
558 calcWeek( currentDate(), totWeeks, yearNumber, onMonday ); 559 calcWeek( currentDate(), totWeeks, yearNumber, onMonday );
559 560
560 QDate d = QDate( yearNumber, 12, 31 ); 561 QDate d = QDate( yearNumber, 12, 31 );
561 calcWeek( d, totWeeks, yearNumber, onMonday ); 562 calcWeek( d, totWeeks, yearNumber, onMonday );
562 563
563 while ( totWeeks == 1 ) { 564 while ( totWeeks == 1 ) {
564 d = d.addDays( -1 ); 565 d = d.addDays( -1 );
565 calcWeek( d, totWeeks, yearNumber, onMonday ); 566 calcWeek( d, totWeeks, yearNumber, onMonday );
566 } 567 }
567} 568}
568 569
569void DateBook::initWeekLst() { 570void DateBook::initWeekLst() {
570 if ( !weekLstView ) { 571 if ( !weekLstView ) {
571 weekLstView = new DateBookWeekLst( ampm, onMonday, db, views, "weeklst view" ); 572 weekLstView = new DateBookWeekLst( ampm, onMonday, db, views, "weeklst view" );
572 views->addWidget( weekLstView, WEEKLST ); 573 views->addWidget( weekLstView, WEEKLST );
573 574
574 //weekLstView->setStartViewTime( startTime ); 575 //weekLstView->setStartViewTime( startTime );
575 connect( weekLstView, SIGNAL( showDate(int,int,int) ), this, SLOT( showDay(int,int,int) ) ); 576 connect( weekLstView, SIGNAL( showDate(int,int,int) ), this, SLOT( showDay(int,int,int) ) );
576 connect( weekLstView, SIGNAL( addEvent(const QDateTime&,const QDateTime&,const QString&, const QString&) ), 577 connect( weekLstView, SIGNAL( addEvent(const QDateTime&,const QDateTime&,const QString&, const QString&) ),
577 this, SLOT( slotNewEntry(const QDateTime&,const QDateTime&,const QString&, const QString&) ) ); 578 this, SLOT( slotNewEntry(const QDateTime&,const QDateTime&,const QString&, const QString&) ) );
578 connect( this, SIGNAL( newEvent() ), weekLstView, SLOT( redraw() ) ); 579 connect( this, SIGNAL( newEvent() ), weekLstView, SLOT( redraw() ) );
579 connect( weekLstView, SIGNAL( editEvent(const Event&) ), this, SLOT( editEvent(const Event&) ) ); 580 connect( weekLstView, SIGNAL( editEvent(const Event&) ), this, SLOT( editEvent(const Event&) ) );
580 connect( weekLstView, SIGNAL( duplicateEvent( const Event & ) ), this, SLOT( duplicateEvent( const Event & ) ) ); 581 connect( weekLstView, SIGNAL( duplicateEvent( const Event & ) ), this, SLOT( duplicateEvent( const Event & ) ) );
581 connect( weekLstView, SIGNAL( beamEvent(const Event&) ), this, SLOT( beamEvent(const Event&) ) ); 582 connect( weekLstView, SIGNAL( beamEvent(const Event&) ), this, SLOT( beamEvent(const Event&) ) );
582 connect( weekLstView, SIGNAL( removeEvent( const Event & ) ), this, SLOT( removeEvent( const Event & ) ) ); 583 connect( weekLstView, SIGNAL( removeEvent( const Event & ) ), this, SLOT( removeEvent( const Event & ) ) );
583 } 584 }
584} 585}
585 586
586 587
587void DateBook::initMonth() 588void DateBook::initMonth()
588{ 589{
589 if ( !monthView ) { 590 if ( !monthView ) {
590 monthView = new DateBookMonth( views, "month view", FALSE, db ); 591 monthView = new DateBookMonth( views, "month view", FALSE, db );
591 views->addWidget( monthView, MONTH ); 592 views->addWidget( monthView, MONTH );
592 connect( monthView, SIGNAL( dateClicked(int,int,int) ), this, SLOT( showDay(int,int,int) ) ); 593 connect( monthView, SIGNAL( dateClicked(int,int,int) ), this, SLOT( showDay(int,int,int) ) );
593 connect( this, SIGNAL( newEvent() ), monthView, SLOT( redraw() ) ); 594 connect( this, SIGNAL( newEvent() ), monthView, SLOT( redraw() ) );
594 qApp->processEvents(); 595 qApp->processEvents();
595 } 596 }
596} 597}
597 598
598void DateBook::loadSettings() 599void DateBook::loadSettings()
599{ 600{
600 Config qpeconfig( "qpe" ); 601 Config qpeconfig( "qpe" );
601 qpeconfig.setGroup("Time"); 602 qpeconfig.setGroup("Time");
602 ampm = qpeconfig.readBoolEntry( "AMPM", TRUE ); 603 ampm = qpeconfig.readBoolEntry( "AMPM", TRUE );
603 onMonday = qpeconfig.readBoolEntry( "MONDAY" ); 604 onMonday = qpeconfig.readBoolEntry( "MONDAY" );
604 605
605 Config config("DateBook"); 606 Config config("DateBook");
606 config.setGroup("Main"); 607 config.setGroup("Main");
607 startTime = config.readNumEntry("startviewtime", 8); 608 startTime = config.readNumEntry("startviewtime", 8);
608 aPreset = config.readBoolEntry("alarmpreset"); 609 aPreset = config.readBoolEntry("alarmpreset");
609 presetTime = config.readNumEntry("presettime"); 610 presetTime = config.readNumEntry("presettime");
610 bJumpToCurTime = config.readBoolEntry("jumptocurtime"); 611 bJumpToCurTime = config.readBoolEntry("jumptocurtime");
611 rowStyle = config.readNumEntry("rowstyle"); 612 rowStyle = config.readNumEntry("rowstyle");
612 defaultView = config.readNumEntry("defaultview",DAY); 613 defaultView = config.readNumEntry("defaultview",DAY);
613 weeklistviewconfig = config.readNumEntry("weeklistviewconfig",NORMAL); 614 weeklistviewconfig = config.readNumEntry("weeklistviewconfig",NORMAL);
614 615
615 defaultLocation=config.readEntry("defaultLocation"); 616 defaultLocation=config.readEntry("defaultLocation");
616 QString tmpString=config.readEntry("defaultCategories"); 617 QString tmpString=config.readEntry("defaultCategories");
617 QStringList tmpStringList=QStringList::split(",",tmpString); 618 QStringList tmpStringList=QStringList::split(",",tmpString);
618 defaultCategories.truncate(0); 619 defaultCategories.truncate(0);
619 620
620 for( QStringList::Iterator i=tmpStringList.begin(); i!=tmpStringList.end(); i++) { 621 for( QStringList::Iterator i=tmpStringList.begin(); i!=tmpStringList.end(); i++) {
621 defaultCategories.resize(defaultCategories.count()+1); 622 defaultCategories.resize(defaultCategories.count()+1);
622 defaultCategories[defaultCategories.count()-1]=(*i).toInt(); 623 defaultCategories[defaultCategories.count()-1]=(*i).toInt();
623 } 624 }
624} 625}
625 626
626void DateBook::saveSettings() 627void DateBook::saveSettings()
627{ 628{
628 Config config( "qpe" ); 629 Config config( "qpe" );
629 Config configDB( "DateBook" ); 630 Config configDB( "DateBook" );
630 configDB.setGroup( "Main" ); 631 configDB.setGroup( "Main" );
631 configDB.writeEntry("startviewtime",startTime); 632 configDB.writeEntry("startviewtime",startTime);
632 configDB.writeEntry("alarmpreset",aPreset); 633 configDB.writeEntry("alarmpreset",aPreset);
633 configDB.writeEntry("presettime",presetTime); 634 configDB.writeEntry("presettime",presetTime);
634 configDB.writeEntry("jumptocurtime", bJumpToCurTime); 635 configDB.writeEntry("jumptocurtime", bJumpToCurTime);
635 configDB.writeEntry("rowstyle", rowStyle); 636 configDB.writeEntry("rowstyle", rowStyle);
636 configDB.writeEntry("defaultview",defaultView); 637 configDB.writeEntry("defaultview",defaultView);
637 configDB.writeEntry("weeklistviewconfig",weeklistviewconfig); 638 configDB.writeEntry("weeklistviewconfig",weeklistviewconfig);
638 639
639 configDB.writeEntry("defaultLocation",defaultLocation); 640 configDB.writeEntry("defaultLocation",defaultLocation);
640 QStringList tmpStringList; 641 QStringList tmpStringList;
641 for( uint i=0; i<defaultCategories.count(); i++) { 642 for( uint i=0; i<defaultCategories.count(); i++) {
642 tmpStringList << QString::number(defaultCategories[i]); 643 tmpStringList << QString::number(defaultCategories[i]);
643 } 644 }
644 configDB.writeEntry("defaultCategories",tmpStringList.join(",")); 645 configDB.writeEntry("defaultCategories",tmpStringList.join(","));
645} 646}
646 647
647void DateBook::appMessage(const QCString& msg, const QByteArray& data) 648void DateBook::appMessage(const QCString& msg, const QByteArray& data)
648{ 649{
649 bool needShow = FALSE; 650 bool needShow = FALSE;
650 if ( msg == "alarm(QDateTime,int)" ) { 651 if ( msg == "alarm(QDateTime,int)" ) {
651 QDataStream ds(data,IO_ReadOnly); 652 QDataStream ds(data,IO_ReadOnly);
652 QDateTime when; int warn; 653 QDateTime when; int warn;
653 ds >> when >> warn; 654 ds >> when >> warn;
654 655
655 // check to make it's okay to continue, 656 // check to make it's okay to continue,
656 // this is the case that the time was set ahead, and 657 // this is the case that the time was set ahead, and
657 // we are forced given a stale alarm... 658 // we are forced given a stale alarm...
658 QDateTime current = QDateTime::currentDateTime(); 659 QDateTime current = QDateTime::currentDateTime();
659 if ( current.time().hour() != when.time().hour() && current.time().minute() != when.time().minute() ) 660 if ( current.time().hour() != when.time().hour() && current.time().minute() != when.time().minute() )
660 return; 661 return;
661 662
662 QValueList<EffectiveEvent> list = db->getEffectiveEvents(when.addSecs(warn*60)); 663 QValueList<EffectiveEvent> list = db->getEffectiveEvents(when.addSecs(warn*60));
663 if ( list.count() > 0 ) { 664 if ( list.count() > 0 ) {
664 QString msg; 665 QString msg;
665 bool bSound = FALSE; 666 bool bSound = FALSE;
666 int stopTimer = 0; 667 int stopTimer = 0;
667 bool found = FALSE; 668 bool found = FALSE;
668 for ( QValueList<EffectiveEvent>::ConstIterator it=list.begin(); it!=list.end(); ++it ) { 669 for ( QValueList<EffectiveEvent>::ConstIterator it=list.begin(); it!=list.end(); ++it ) {
669 if ( (*it).event().hasAlarm() ) { 670 if ( (*it).event().hasAlarm() ) {
670 found = TRUE; 671 found = TRUE;
671 msg += "<CENTER><B>" + (*it).description() + "</B>" 672 msg += "<CENTER><B>" + (*it).description() + "</B>"
672 + "<BR>" + (*it).location() + "<BR>" 673 + "<BR>" + (*it).location() + "<BR>"
673 + TimeString::dateString((*it).event().start(),ampm) 674 + TimeString::dateString((*it).event().start(),ampm)
674 + (warn 675 + (warn
675 ? tr(" (in " + QString::number(warn) 676 ? tr(" (in " + QString::number(warn)
676 + tr(" minutes)")) 677 + tr(" minutes)"))
677 : QString("")) 678 : QString(""))
678 + "<BR>" 679 + "<BR>"
679 + (*it).notes() + "</CENTER>"; 680 + (*it).notes() + "</CENTER>";
680 if ( (*it).event().alarmSound() != Event::Silent ) { 681 if ( (*it).event().alarmSound() != Event::Silent ) {
681 bSound = TRUE; 682 bSound = TRUE;
682 } 683 }
683 } 684 }
684 } 685 }
685 if ( found ) { 686 if ( found ) {
686 if ( bSound ) { 687 if ( bSound ) {
687 Sound::soundAlarm(); 688 Sound::soundAlarm();
688 alarmCounter = 0; 689 alarmCounter = 0;
689 stopTimer = startTimer( 5000 ); 690 stopTimer = startTimer( 5000 );
690 } 691 }
691 QDialog dlg( this, 0, TRUE ); 692 QDialog dlg( this, 0, TRUE );
692 QVBoxLayout *vb = new QVBoxLayout( &dlg ); 693 QVBoxLayout *vb = new QVBoxLayout( &dlg );
693 QScrollView *view = new QScrollView( &dlg, "scrollView"); 694 QScrollView *view = new QScrollView( &dlg, "scrollView");
694 view->setResizePolicy( QScrollView::AutoOneFit ); 695 view->setResizePolicy( QScrollView::AutoOneFit );
695 vb->addWidget( view ); 696 vb->addWidget( view );
696 QLabel *lblMsg = new QLabel( msg, &dlg ); 697 QLabel *lblMsg = new QLabel( msg, &dlg );
697 view->addChild( lblMsg ); 698 view->addChild( lblMsg );
698 QPushButton *cmdOk = new QPushButton( tr("OK"), &dlg ); 699 QPushButton *cmdOk = new QPushButton( tr("OK"), &dlg );
699 connect( cmdOk, SIGNAL(clicked()), &dlg, SLOT(accept()) ); 700 connect( cmdOk, SIGNAL(clicked()), &dlg, SLOT(accept()) );
700 vb->addWidget( cmdOk ); 701 vb->addWidget( cmdOk );
701 702
702 needShow = QPEApplication::execDialog( &dlg ); 703 needShow = QPEApplication::execDialog( &dlg );
703 704
704 if ( bSound ) 705 if ( bSound )
705 killTimer( stopTimer ); 706 killTimer( stopTimer );
706 } 707 }
707 } 708 }
708 } else if ( msg == "nextView()" ) { 709 } else if ( msg == "nextView()" ) {
709 needShow = true; 710 needShow = true;
710 if ( !qApp-> activeWindow ( )) { 711 if ( !qApp-> activeWindow ( )) {
711 needShow = TRUE; 712 needShow = TRUE;
712 } else { 713 } else {
713 QWidget* cur = views->visibleWidget(); 714 QWidget* cur = views->visibleWidget();
714 if ( cur ) { 715 if ( cur ) {
715 if ( cur == dayView ) 716 if ( cur == dayView )
716 viewWeek(); 717 viewWeek();
717 else if ( cur == weekView ) 718 else if ( cur == weekView )
718 viewWeekLst(); 719 viewWeekLst();
719 else if ( cur == weekLstView ) 720 else if ( cur == weekLstView )
720 viewMonth(); 721 viewMonth();
721 else if ( cur == monthView ) 722 else if ( cur == monthView )
722 viewDay(); 723 viewDay();
723 needShow = TRUE; 724 needShow = TRUE;
724 } 725 }
725 } 726 }
726 } else if (msg == "editEvent(int)") { 727 } else if (msg == "editEvent(int)") {
727 /* simple copy from receive */ 728 /* simple copy from receive */
728 QDataStream stream(data,IO_ReadOnly); 729 QDataStream stream(data,IO_ReadOnly);
729 int uid; 730 int uid;
730 stream >> uid; 731 stream >> uid;
731 Event e=db->eventByUID(uid); 732 Event e=db->eventByUID(uid);
732 editEvent(e); 733 editEvent(e);
733 } else if (msg == "viewDefault(QDate)"){ 734 } else if (msg == "viewDefault(QDate)"){
734 /* simple copy from receive */ 735 /* simple copy from receive */
735 QDataStream stream(data,IO_ReadOnly); 736 QDataStream stream(data,IO_ReadOnly);
736 QDate day; 737 QDate day;
737 stream >> day; 738 stream >> day;
738 viewDefault(day); 739 viewDefault(day);
739 needShow = true; 740 needShow = true;
740 } 741 }
741 742
742 if ( needShow ) { 743 if ( needShow ) {
743#if defined(Q_WS_QWS) || defined(_WS_QWS_) 744#if defined(Q_WS_QWS) || defined(_WS_QWS_)
744// showMaximized(); 745// showMaximized();
745#else 746#else
746// show(); 747// show();
747#endif 748#endif
748// raise(); 749// raise();
749 QPEApplication::setKeepRunning(); 750 QPEApplication::setKeepRunning();
750// setActiveWindow(); 751// setActiveWindow();
751 } 752 }
752} 753}
753 754
754void DateBook::reload() 755void DateBook::reload()
755{ 756{
756 db->reload(); 757 db->reload();
757 if ( dayAction->isOn() ) viewDay(); 758 if ( dayAction->isOn() ) viewDay();
758 else if ( weekAction->isOn() ) viewWeek(); 759 else if ( weekAction->isOn() ) viewWeek();
759 else if ( monthAction->isOn() ) viewMonth(); 760 else if ( monthAction->isOn() ) viewMonth();
760 syncing = FALSE; 761 syncing = FALSE;
761} 762}
762 763
763void DateBook::flush() 764void DateBook::flush()
764{ 765{
765 syncing = TRUE; 766 syncing = TRUE;
766 db->save(); 767 db->save();
767} 768}
768 769
769void DateBook::timerEvent( QTimerEvent *e ) 770void DateBook::timerEvent( QTimerEvent *e )
770{ 771{
771 if ( alarmCounter < 10 ) { 772 if ( alarmCounter < 10 ) {
772 alarmCounter++; 773 alarmCounter++;
773 Sound::soundAlarm(); 774 Sound::soundAlarm();
774 } else { 775 } else {
775 killTimer( e->timerId() ); 776 killTimer( e->timerId() );
776 } 777 }
777} 778}
778 779
779void DateBook::changeClock( bool newClock ) 780void DateBook::changeClock( bool newClock )
780{ 781{
781 ampm = newClock; 782 ampm = newClock;
782 // repaint the affected objects... 783 // repaint the affected objects...
783 if (dayView) dayView->redraw(); 784 if (dayView) dayView->redraw();
784 if (weekView) weekView->redraw(); 785 if (weekView) weekView->redraw();
785 if (weekLstView) weekLstView->redraw(); 786 if (weekLstView) weekLstView->redraw();
786} 787}
787 788
788void DateBook::changeWeek( bool m ) 789void DateBook::changeWeek( bool m )
789{ 790{
790 /* no need to redraw, each widget catches. Do need to 791 /* no need to redraw, each widget catches. Do need to
791 store though for widgets we haven't made yet */ 792 store though for widgets we haven't made yet */
792 onMonday = m; 793 onMonday = m;
793} 794}
794 795
795void DateBook::slotToday() 796void DateBook::slotToday()
796{ 797{
797 // we need to view today using default view 798 // we need to view today using default view
798 view(defaultView,QDate::currentDate()); 799 view(defaultView,QDate::currentDate());
799} 800}
800 801
801void DateBook::closeEvent( QCloseEvent *e ) 802void DateBook::closeEvent( QCloseEvent *e )
802{ 803{
803 if(syncing) { 804 if(syncing) {
804 /* no need to save, did that at flush */ 805 /* no need to save, did that at flush */
805 e->accept(); 806 e->accept();
806 return; 807 return;
807 } 808 }
808 809
809 // save settings will generate it's own error messages, no 810 // save settings will generate it's own error messages, no
810 // need to do checking ourselves. 811 // need to do checking ourselves.
811 saveSettings(); 812 saveSettings();
812 if ( db->save() ) { 813 if ( db->save() ) {
813 e->accept(); 814 e->accept();
814 } else { 815 } else {
815 if ( QMessageBox::critical( this, tr( "Out of space" ), 816 if ( QMessageBox::critical( this, tr( "Out of space" ),
816 tr("Calendar was unable to save\n" 817 tr("Calendar was unable to save\n"
817 "your changes.\n" 818 "your changes.\n"
818 "Free up some space and try again.\n" 819 "Free up some space and try again.\n"
819 "\nQuit anyway?"), 820 "\nQuit anyway?"),
820 QMessageBox::Yes|QMessageBox::Escape, 821 QMessageBox::Yes|QMessageBox::Escape,
821 QMessageBox::No|QMessageBox::Default ) 822 QMessageBox::No|QMessageBox::Default )
822 != QMessageBox::No ) 823 != QMessageBox::No )
823 e->accept(); 824 e->accept();
824 else 825 else
825 e->ignore(); 826 e->ignore();
826 } 827 }
827} 828}
828 829
829// Entering directly from the "keyboard" 830// Entering directly from the "keyboard"
830void DateBook::slotNewEventFromKey( const QString &str ) 831void DateBook::slotNewEventFromKey( const QString &str )
831{ 832{
832 if (syncing) { 833 if (syncing) {
833 QMessageBox::warning( this, tr("Calendar"), 834 QMessageBox::warning( this, tr("Calendar"),
834 tr( "Can not edit data, currently syncing") ); 835 tr( "Can not edit data, currently syncing") );
835 return; 836 return;
836 } 837 }
837 838
838 // We get to here from a key pressed in the Day View 839 // We get to here from a key pressed in the Day View
839 // So we can assume some things. We want the string 840 // So we can assume some things. We want the string
840 // passed in to be part of the description. 841 // passed in to be part of the description.
841 QDateTime start, end; 842 QDateTime start, end;
842 if ( views->visibleWidget() == dayView ) { 843 if ( views->visibleWidget() == dayView ) {
843 dayView->selectedDates( start, end ); 844 dayView->selectedDates( start, end );
844 } else if ( views->visibleWidget() == monthView ) { 845 } else if ( views->visibleWidget() == monthView ) {
845 QDate d = monthView->selectedDate(); 846 QDate d = monthView->selectedDate();
846 start = end = d; 847 start = end = d;
847 start.setTime( QTime( 10, 0 ) ); 848 start.setTime( QTime( 10, 0 ) );
848 end.setTime( QTime( 12, 0 ) ); 849 end.setTime( QTime( 12, 0 ) );
849 } else if ( views->visibleWidget() == weekView ) { 850 } else if ( views->visibleWidget() == weekView ) {
850 QDate d = weekView->date(); 851 QDate d = weekView->date();
851 start = end = d; 852 start = end = d;
852 start.setTime( QTime( 10, 0 ) ); 853 start.setTime( QTime( 10, 0 ) );
853 end.setTime( QTime( 12, 0 ) ); 854 end.setTime( QTime( 12, 0 ) );
854 } else if ( views->visibleWidget() == weekLstView ) { 855 } else if ( views->visibleWidget() == weekLstView ) {
855 QDate d = weekLstView->date(); 856 QDate d = weekLstView->date();
856 start = end = d; 857 start = end = d;
857 start.setTime( QTime( 10, 0 ) ); 858 start.setTime( QTime( 10, 0 ) );
858 end.setTime( QTime( 12, 0 ) ); 859 end.setTime( QTime( 12, 0 ) );
859 } 860 }
860 slotNewEntry(start, end, str); 861 slotNewEntry(start, end, str);
861} 862}
862void DateBook::slotNewEntry(const QDateTime &start, const QDateTime &end, const QString &str, const QString &location) { 863void DateBook::slotNewEntry(const QDateTime &start, const QDateTime &end, const QString &str, const QString &location) {
863 // argh! This really needs to be encapsulated in a class 864 // argh! This really needs to be encapsulated in a class
864 // or function. 865 // or function.
865 QDialog newDlg( this, 0, TRUE ); 866 QDialog newDlg( this, 0, TRUE );
866 newDlg.setCaption( DateEntryBase::tr("New Event") ); 867 newDlg.setCaption( DateEntryBase::tr("New Event") );
867 DateEntry *e; 868 DateEntry *e;
868 QVBoxLayout *vb = new QVBoxLayout( &newDlg ); 869 QVBoxLayout *vb = new QVBoxLayout( &newDlg );
869 QScrollView *sv = new QScrollView( &newDlg ); 870 QScrollView *sv = new QScrollView( &newDlg );
870 sv->setResizePolicy( QScrollView::AutoOneFit ); 871 sv->setResizePolicy( QScrollView::AutoOneFit );
871 sv->setFrameStyle( QFrame::NoFrame ); 872 sv->setFrameStyle( QFrame::NoFrame );
872 sv->setHScrollBarMode( QScrollView::AlwaysOff ); 873 sv->setHScrollBarMode( QScrollView::AlwaysOff );
873 vb->addWidget( sv ); 874 vb->addWidget( sv );
874 875
875 Event ev; 876 Event ev;
876 ev.setDescription( str ); 877 ev.setDescription( str );
877 // When the new gui comes in, change this... 878 // When the new gui comes in, change this...
878 if(location==0) { 879 if(location==0) {
879 if(defaultLocation.isEmpty()) { 880 if(defaultLocation.isEmpty()) {
880 ev.setLocation(tr("(Unknown)")); 881 ev.setLocation(tr("(Unknown)"));
881 } else { 882 } else {
882 ev.setLocation( defaultLocation ); 883 ev.setLocation( defaultLocation );
883 } 884 }
884 } else { 885 } else {
885 ev.setLocation(location); 886 ev.setLocation(location);
886 } 887 }
887 ev.setCategories(defaultCategories); 888 ev.setCategories(defaultCategories);
888 ev.setStart( start ); 889 ev.setStart( start );
889 ev.setEnd( end ); 890 ev.setEnd( end );
890 891
891 e = new DateEntry( onMonday, ev, ampm, &newDlg ); 892 e = new DateEntry( onMonday, ev, ampm, &newDlg );
892 e->setAlarmEnabled( aPreset, presetTime, Event::Loud ); 893 e->setAlarmEnabled( aPreset, presetTime, Event::Loud );
893 sv->addChild( e ); 894 sv->addChild( e );
894 while ( QPEApplication::execDialog( &newDlg ) ) { 895 while ( QPEApplication::execDialog( &newDlg ) ) {
895 ev = e->event(); 896 ev = e->event();
896 ev.assignUid(); 897 ev.assignUid();
897 QString error = checkEvent( ev ); 898 QString error = checkEvent( ev );
898 if ( !error.isNull() ) { 899 if ( !error.isNull() ) {
899 if ( QMessageBox::warning( this, tr("Error!"), error, tr("Fix it"), tr("Continue"), 0, 0, 1 ) == 0 ) 900 if ( QMessageBox::warning( this, tr("Error!"), error, tr("Fix it"), tr("Continue"), 0, 0, 1 ) == 0 )
900 continue; 901 continue;
901 } 902 }
902 db->addEvent( ev ); 903 db->addEvent( ev );
903 emit newEvent(); 904 emit newEvent();
904 break; 905 break;
905 } 906 }
906} 907}
907 908
908void DateBook::setDocument( const QString &filename ) 909void DateBook::setDocument( const QString &filename )
909{ 910{
910 if ( filename.find(".vcs") != int(filename.length()) - 4 ) return; 911 if ( filename.find(".vcs") != int(filename.length()) - 4 ) return;
911 912
912 QValueList<Event> tl = Event::readVCalendar( filename ); 913 QValueList<Event> tl = Event::readVCalendar( filename );
913 for( QValueList<Event>::Iterator it = tl.begin(); it != tl.end(); ++it ) { 914 for( QValueList<Event>::Iterator it = tl.begin(); it != tl.end(); ++it ) {
914 db->addEvent( *it ); 915 db->addEvent( *it );
915 } 916 }
916} 917}
917 918
918static const char * beamfile = "/tmp/obex/event.vcs"; 919static const char * beamfile = "/tmp/obex/event.vcs";
919 920
920void DateBook::beamEvent( const Event &e ) 921void DateBook::beamEvent( const Event &e )
921{ 922{
922 odebug << "trying to beam" << oendl; 923 odebug << "trying to beam" << oendl;
923 unlink( beamfile ); // delete if exists 924 unlink( beamfile ); // delete if exists
924 mkdir("/tmp/obex/", 0755); 925 mkdir("/tmp/obex/", 0755);
925 Event::writeVCalendar( beamfile, e ); 926 Event::writeVCalendar( beamfile, e );
926 Ir *ir = new Ir( this ); 927 Ir *ir = new Ir( this );
927 connect( ir, SIGNAL( done(Ir*) ), this, SLOT( beamDone(Ir*) ) ); 928 connect( ir, SIGNAL( done(Ir*) ), this, SLOT( beamDone(Ir*) ) );
928 QString description = e.description(); 929 QString description = e.description();
929 ir->send( beamfile, description, "text/x-vCalendar" ); 930 ir->send( beamfile, description, "text/x-vCalendar" );
930} 931}
931 932
932void DateBook::beamDone( Ir *ir ) 933void DateBook::beamDone( Ir *ir )
933{ 934{
934 delete ir; 935 delete ir;
935 unlink( beamfile ); 936 unlink( beamfile );
936} 937}
937 938
938void DateBook::slotFind() 939void DateBook::slotFind()
939{ 940{
940 // move it to the day view... 941 // move it to the day view...
941 viewDay(); 942 viewDay();
942 FindDialog frmFind( "Calendar", this ); // no tr needed 943 FindDialog frmFind( "Calendar", this ); // no tr needed
943 frmFind.setUseDate( true ); 944 frmFind.setUseDate( true );
944 frmFind.setDate( currentDate() ); 945 frmFind.setDate( currentDate() );
945 QObject::connect( &frmFind, 946 QObject::connect( &frmFind,
946 SIGNAL(signalFindClicked(const QString&,const QDate&,bool,bool,int)), 947 SIGNAL(signalFindClicked(const QString&,const QDate&,bool,bool,int)),
947 this, 948 this,
948 SLOT(slotDoFind(const QString&,const QDate&,bool,bool,int)) ); 949 SLOT(slotDoFind(const QString&,const QDate&,bool,bool,int)) );
949 QObject::connect( this, 950 QObject::connect( this,
950 SIGNAL(signalNotFound()), 951 SIGNAL(signalNotFound()),
951 &frmFind, 952 &frmFind,
952 SLOT(slotNotFound()) ); 953 SLOT(slotNotFound()) );
953 QObject::connect( this, 954 QObject::connect( this,
954 SIGNAL(signalWrapAround()), 955 SIGNAL(signalWrapAround()),
955 &frmFind, 956 &frmFind,
956 SLOT(slotWrapAround()) ); 957 SLOT(slotWrapAround()) );
957 frmFind.move(0,0); 958 frmFind.move(0,0);
958 frmFind.exec(); 959 frmFind.exec();
959 inSearch = false; 960 inSearch = false;
960} 961}
961 962
962bool catComp( QArray<int> cats, int category ) 963bool catComp( QArray<int> cats, int category )
963{ 964{
964 bool returnMe; 965 bool returnMe;
965 int i, 966 int i,
966 count; 967 count;
967 968
968 count = int(cats.count()); 969 count = int(cats.count());
969 returnMe = false; 970 returnMe = false;
970 if ( (category == -1 && count == 0) || category == -2 ) 971 if ( (category == -1 && count == 0) || category == -2 )
971 returnMe = true; 972 returnMe = true;
972 else { 973 else {
973 for ( i = 0; i < count; i++ ) { 974 for ( i = 0; i < count; i++ ) {
974 if ( category == cats[i] ) { 975 if ( category == cats[i] ) {
975 returnMe = true; 976 returnMe = true;
976 break; 977 break;
977 } 978 }
978 } 979 }
979 } 980 }
980 return returnMe; 981 return returnMe;
981} 982}
982 983
983 984
984void DateBook::slotDoFind( const QString& txt, const QDate &dt, 985void DateBook::slotDoFind( const QString& txt, const QDate &dt,
985 bool caseSensitive, bool /*backwards*/, 986 bool caseSensitive, bool /*backwards*/,
986 int category ) 987 int category )
987{ 988{
988 QDateTime dtEnd( QDate(3001, 1, 1), QTime(0, 0, 0) ), 989 QDateTime dtEnd( QDate(3001, 1, 1), QTime(0, 0, 0) ),
989 next; 990 next;
990 991
991 QRegExp r( txt ); 992 QRegExp r( txt );
992 r.setCaseSensitive( caseSensitive ); 993 r.setCaseSensitive( caseSensitive );
993 994
994 995
995 static Event rev, nonrev; 996 static Event rev, nonrev;
996 if ( !inSearch ) { 997 if ( !inSearch ) {
997 rev.setStart( QDateTime(QDate(1960, 1, 1), QTime(0, 0, 0)) ); 998 rev.setStart( QDateTime(QDate(1960, 1, 1), QTime(0, 0, 0)) );
998 nonrev.setStart( rev.start() ); 999 nonrev.setStart( rev.start() );
999 inSearch = true; 1000 inSearch = true;
1000 } 1001 }
1001 static QDate searchDate = dt; 1002 static QDate searchDate = dt;
1002 // if true at the end we will start at the begin again and afterwards 1003 // if true at the end we will start at the begin again and afterwards
1003 // we will emit string not found 1004 // we will emit string not found
1004 static bool wrapAround = true; 1005 static bool wrapAround = true;
1005 bool candidtate; 1006 bool candidtate;
1006 candidtate = false; 1007 candidtate = false;
1007 1008
1008 QValueList<Event> repeats = db->getRawRepeats(); 1009 QValueList<Event> repeats = db->getRawRepeats();
1009 1010
1010 // find the candidate for the first repeat that matches... 1011 // find the candidate for the first repeat that matches...
1011 // first check if there can ever be a match and then compute 1012 // first check if there can ever be a match and then compute
1012 // the next occurence from start. See if this event is closer 1013 // the next occurence from start. See if this event is closer
1013 // to the beginning (start. next < dtEnd) and not smaller then the last 1014 // to the beginning (start. next < dtEnd) and not smaller then the last
1014 // result. If we find a canditate we set the dtEnd to the time 1015 // result. If we find a canditate we set the dtEnd to the time
1015 // of the ocurrence and rev to this occurence. 1016 // of the ocurrence and rev to this occurence.
1016 // set wrap around to true because there might be more events coming 1017 // set wrap around to true because there might be more events coming
1017 // and we're not at the end. 1018 // and we're not at the end.
1018 QValueListConstIterator<Event> it; 1019 QValueListConstIterator<Event> it;
1019 QDate start = dt; 1020 QDate start = dt;
1020 for ( it = repeats.begin(); it != repeats.end(); ++it ) { 1021 for ( it = repeats.begin(); it != repeats.end(); ++it ) {
1021 if ( catComp( (*it).categories(), category ) ) { 1022 if ( catComp( (*it).categories(), category ) ) {
1022 if ( (*it).match( r ) ) { 1023 if ( (*it).match( r ) ) {
1023 if ( nextOccurance( *it, start, next ) ) { 1024 if ( nextOccurance( *it, start, next ) ) {
1024 if ( next < dtEnd && !(next <= rev.start() ) ) { 1025 if ( next < dtEnd && !(next <= rev.start() ) ) {
1025 rev = *it; 1026 rev = *it;
1026 dtEnd = next; 1027 dtEnd = next;
1027 rev.setStart( next ); 1028 rev.setStart( next );
1028 candidtate = true; 1029 candidtate = true;
1029 wrapAround = true; 1030 wrapAround = true;
1030 } 1031 }
1031 } 1032 }
1032 } 1033 }
1033 } 1034 }
diff --git a/core/pim/datebook/datebooksettings.cpp b/core/pim/datebook/datebooksettings.cpp
index 861e266..561dc38 100644
--- a/core/pim/datebook/datebooksettings.cpp
+++ b/core/pim/datebook/datebooksettings.cpp
@@ -1,191 +1,219 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved. 2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3** 3**
4** This file is part of Qtopia Environment. 4** This file is part of Qtopia Environment.
5** 5**
6** This file may be distributed and/or modified under the terms of the 6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software 7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the 8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file. 9** packaging of this file.
10** 10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13** 13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information. 14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15** 15**
16** Contact info@trolltech.com if any conditions of this licensing are 16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you. 17** not clear to you.
18** 18**
19**********************************************************************/ 19**********************************************************************/
20 20
21#include "datebooksettings.h" 21#include "datebooksettings.h"
22 22
23#include <opie2/opluginloader.h> 23#include <opie2/opluginloader.h>
24#include <opie2/odebug.h> 24#include <opie2/odebug.h>
25#include <opie2/oholidaypluginif.h>
26#include <opie2/oholidayplugin.h>
27#include <opie2/oholidayplugincfgwidget.h>
25 28
26#include <qpe/qpeapplication.h> 29#include <qpe/qpeapplication.h>
27 30
28#include <qspinbox.h> 31#include <qspinbox.h>
29#include <qcheckbox.h> 32#include <qcheckbox.h>
30#include <qlistview.h> 33#include <qlistview.h>
31#include <qheader.h> 34#include <qheader.h>
35#include <qtabwidget.h>
36#include <qlayout.h>
32 37
33DateBookSettings::DateBookSettings( bool whichClock, QWidget *parent, 38DateBookSettings::DateBookSettings( bool whichClock, QWidget *parent,
34 const char *name, bool modal, WFlags fl ) 39 const char *name, bool modal, WFlags fl )
35 : DateBookSettingsBase( parent, name, modal, fl ), 40 : DateBookSettingsBase( parent, name, modal, fl ),
36 ampm( whichClock ) 41 ampm( whichClock )
37{ 42{
38 init(); 43 init();
39 QObject::connect( qApp, SIGNAL( clockChanged(bool) ), this, SLOT( slotChangeClock(bool) ) ); 44 QObject::connect( qApp, SIGNAL( clockChanged(bool) ), this, SLOT( slotChangeClock(bool) ) );
40 QArray<int> categories; 45 QArray<int> categories;
41 comboCategory->setCategories( categories, "Calendar", tr("Calendar") ); 46 comboCategory->setCategories( categories, "Calendar", tr("Calendar") );
42 m_loader = 0; 47 m_loader = 0;
43 m_manager = 0; 48 m_manager = 0;
44 m_PluginListView->header()->hide(); 49 m_PluginListView->header()->hide();
45 m_PluginListView->setSorting(-1); 50 m_PluginListView->setSorting(-1);
46} 51}
47 52
48DateBookSettings::~DateBookSettings() 53DateBookSettings::~DateBookSettings()
49{ 54{
50} 55}
51 56
52void DateBookSettings::setStartTime( int newStartViewTime ) 57void DateBookSettings::setStartTime( int newStartViewTime )
53{ 58{
54 if ( ampm ) { 59 if ( ampm ) {
55 if ( newStartViewTime >= 12 ) { 60 if ( newStartViewTime >= 12 ) {
56 newStartViewTime %= 12; 61 newStartViewTime %= 12;
57 if ( newStartViewTime == 0 ) 62 if ( newStartViewTime == 0 )
58 newStartViewTime = 12; 63 newStartViewTime = 12;
59 spinStart->setSuffix( tr(":00 PM") ); 64 spinStart->setSuffix( tr(":00 PM") );
60 } 65 }
61 else if ( newStartViewTime == 0 ) { 66 else if ( newStartViewTime == 0 ) {
62 newStartViewTime = 12; 67 newStartViewTime = 12;
63 spinStart->setSuffix( tr(":00 AM") ); 68 spinStart->setSuffix( tr(":00 AM") );
64 } 69 }
65 oldtime = newStartViewTime; 70 oldtime = newStartViewTime;
66 } 71 }
67 spinStart->setValue( newStartViewTime ); 72 spinStart->setValue( newStartViewTime );
68} 73}
69 74
70int DateBookSettings::startTime() const 75int DateBookSettings::startTime() const
71{ 76{
72 int returnMe = spinStart->value(); 77 int returnMe = spinStart->value();
73 if ( ampm ) { 78 if ( ampm ) {
74 if ( returnMe != 12 && spinStart->suffix().contains(tr("PM"), FALSE) ) 79 if ( returnMe != 12 && spinStart->suffix().contains(tr("PM"), FALSE) )
75 returnMe += 12; 80 returnMe += 12;
76 else if (returnMe == 12 && spinStart->suffix().contains(tr("AM"), TRUE)) 81 else if (returnMe == 12 && spinStart->suffix().contains(tr("AM"), TRUE))
77 returnMe = 0; 82 returnMe = 0;
78 } 83 }
79 return returnMe; 84 return returnMe;
80} 85}
81 86
82void DateBookSettings::setPluginList(Opie::Core::OPluginManager*aManager,Opie::Core::OPluginLoader*aLoader) 87void DateBookSettings::setPluginList(Opie::Core::OPluginManager*aManager,Opie::Core::OPluginLoader*aLoader)
83{ 88{
84 m_manager = aManager; 89 m_manager = aManager;
85 m_loader = aLoader; 90 m_loader = aLoader;
86 if (!aManager||!aLoader) return; 91 if (!aManager||!aLoader) return;
87 Opie::Core::OPluginItem::List inLst = m_loader->allAvailable(true); 92 Opie::Core::OPluginItem::List inLst = m_loader->allAvailable(true);
88 QCheckListItem *pitem = 0; 93 QCheckListItem *pitem = 0;
89 94
90 for ( Opie::Core::OPluginItem::List::Iterator it = inLst.begin(); it != inLst.end(); ++it ) { 95 for ( Opie::Core::OPluginItem::List::Iterator it = inLst.begin(); it != inLst.end(); ++it ) {
91 pitem = new QCheckListItem(m_PluginListView,(*it).name(),QCheckListItem::CheckBox); 96 pitem = new QCheckListItem(m_PluginListView,(*it).name(),QCheckListItem::CheckBox);
92 pitem->setOn( (*it).isEnabled() ); 97 pitem->setOn( (*it).isEnabled() );
98
99 Opie::Datebook::HolidayPluginIf*hif = m_loader->load<Opie::Datebook::HolidayPluginIf>(*it,IID_HOLIDAY_PLUGIN);
100 if (!hif) continue;
101 Opie::Datebook::HolidayPlugin*pl = hif->plugin();
102 if (!pl) continue;
103 Opie::Datebook::HolidayPluginConfigWidget*cfg = pl->configWidget();
104 if (!cfg) continue;
105 QWidget * dtab = new QWidget(TabWidget,pl->description());
106 QVBoxLayout*dlayout = new QVBoxLayout(dtab);
107 dlayout->setMargin(2);
108 dlayout->setSpacing(2);
109 cfg->reparent(dtab,0,QPoint(0,0));
110 dlayout->addWidget(cfg);
111 TabWidget->insertTab(dtab,pl->description());
112
113 m_cfgWidgets.append(cfg);
114 }
115}
116void DateBookSettings::savePlugins()
117{
118 QValueList<Opie::Datebook::HolidayPluginConfigWidget*>::Iterator it;
119 for (it=m_cfgWidgets.begin();it!=m_cfgWidgets.end();++it) {
120 (*it)->saveConfig();
93 } 121 }
94} 122}
95 123
96void DateBookSettings::pluginItemClicked(QListViewItem *aItem) 124void DateBookSettings::pluginItemClicked(QListViewItem *aItem)
97{ 125{
98 if (!aItem||!m_manager||!m_loader) return; 126 if (!aItem||!m_manager||!m_loader) return;
99 QCheckListItem*pitem = ((QCheckListItem*)aItem); 127 QCheckListItem*pitem = ((QCheckListItem*)aItem);
100 128
101 Opie::Core::OPluginItem::List lst = m_loader->allAvailable( true ); 129 Opie::Core::OPluginItem::List lst = m_loader->allAvailable( true );
102 for ( Opie::Core::OPluginItem::List::Iterator it = lst.begin(); it != lst.end(); ++it ) { 130 for ( Opie::Core::OPluginItem::List::Iterator it = lst.begin(); it != lst.end(); ++it ) {
103 if ( QString::compare( (*it).name() , pitem->text(0) ) == 0 ) { 131 if ( QString::compare( (*it).name() , pitem->text(0) ) == 0 ) {
104 m_manager->setEnabled((*it),pitem->isOn()); 132 m_manager->setEnabled((*it),pitem->isOn());
105 break; 133 break;
106 } 134 }
107 } 135 }
108} 136}
109 137
110void DateBookSettings::setAlarmPreset( bool bAlarm, int presetTime ) 138void DateBookSettings::setAlarmPreset( bool bAlarm, int presetTime )
111{ 139{
112 chkAlarmPreset->setChecked( bAlarm ); 140 chkAlarmPreset->setChecked( bAlarm );
113 if ( presetTime >=5 ) 141 if ( presetTime >=5 )
114 spinPreset->setValue( presetTime ); 142 spinPreset->setValue( presetTime );
115} 143}
116 144
117bool DateBookSettings::alarmPreset() const 145bool DateBookSettings::alarmPreset() const
118{ 146{
119 return chkAlarmPreset->isChecked(); 147 return chkAlarmPreset->isChecked();
120} 148}
121 149
122int DateBookSettings::presetTime() const 150int DateBookSettings::presetTime() const
123{ 151{
124 return spinPreset->value(); 152 return spinPreset->value();
125} 153}
126 154
127 155
128void DateBookSettings::slot12Hour( int i ) 156void DateBookSettings::slot12Hour( int i )
129{ 157{
130 if ( ampm ) { 158 if ( ampm ) {
131 if ( spinStart->suffix().contains( tr("AM"), FALSE ) ) { 159 if ( spinStart->suffix().contains( tr("AM"), FALSE ) ) {
132 if ( oldtime == 12 && i == 11 || oldtime == 11 && i == 12 ) 160 if ( oldtime == 12 && i == 11 || oldtime == 11 && i == 12 )
133 spinStart->setSuffix( tr(":00 PM") ); 161 spinStart->setSuffix( tr(":00 PM") );
134 } else { 162 } else {
135 if ( oldtime == 12 && i == 11 || oldtime == 11 && i == 12 ) 163 if ( oldtime == 12 && i == 11 || oldtime == 11 && i == 12 )
136 spinStart->setSuffix( tr(":00 AM") ); 164 spinStart->setSuffix( tr(":00 AM") );
137 } 165 }
138 oldtime = i; 166 oldtime = i;
139 } 167 }
140} 168}
141 169
142void DateBookSettings::init() 170void DateBookSettings::init()
143{ 171{
144 if ( ampm ) { 172 if ( ampm ) {
145 spinStart->setMinValue( 1 ); 173 spinStart->setMinValue( 1 );
146 spinStart->setMaxValue( 12 ); 174 spinStart->setMaxValue( 12 );
147 spinStart->setValue( 12 ); 175 spinStart->setValue( 12 );
148 spinStart->setSuffix( tr(":00 AM") ); 176 spinStart->setSuffix( tr(":00 AM") );
149 oldtime = 12; 177 oldtime = 12;
150 } else { 178 } else {
151 spinStart->setMinValue( 0 ); 179 spinStart->setMinValue( 0 );
152 spinStart->setMaxValue( 23 ); 180 spinStart->setMaxValue( 23 );
153 spinStart->setSuffix( tr(":00") ); 181 spinStart->setSuffix( tr(":00") );
154 } 182 }
155} 183}
156 184
157void DateBookSettings::slotChangeClock( bool whichClock ) 185void DateBookSettings::slotChangeClock( bool whichClock )
158{ 186{
159 int saveMe; 187 int saveMe;
160 saveMe = spinStart->value(); 188 saveMe = spinStart->value();
161 if ( ampm && spinStart->suffix().contains( tr("AM"), FALSE ) ) { 189 if ( ampm && spinStart->suffix().contains( tr("AM"), FALSE ) ) {
162 if ( saveMe == 12 ) 190 if ( saveMe == 12 )
163 saveMe = 0; 191 saveMe = 0;
164 } else if ( ampm && spinStart->suffix().contains( tr("PM"), FALSE ) ) { 192 } else if ( ampm && spinStart->suffix().contains( tr("PM"), FALSE ) ) {
165 if ( saveMe != 12 ) 193 if ( saveMe != 12 )
166 saveMe += 12; 194 saveMe += 12;
167 } 195 }
168 ampm = whichClock; 196 ampm = whichClock;
169 init(); 197 init();
170 setStartTime( saveMe ); 198 setStartTime( saveMe );
171} 199}
172 200
173void DateBookSettings::setJumpToCurTime( bool bJump ) 201void DateBookSettings::setJumpToCurTime( bool bJump )
174{ 202{
175 chkJumpToCurTime->setChecked( bJump ); 203 chkJumpToCurTime->setChecked( bJump );
176} 204}
177 205
178bool DateBookSettings::jumpToCurTime() const 206bool DateBookSettings::jumpToCurTime() const
179{ 207{
180 return chkJumpToCurTime->isChecked(); 208 return chkJumpToCurTime->isChecked();
181} 209}
182 210
183void DateBookSettings::setRowStyle( int style ) 211void DateBookSettings::setRowStyle( int style )
184{ 212{
185 comboRowStyle->setCurrentItem( style ); 213 comboRowStyle->setCurrentItem( style );
186} 214}
187 215
188int DateBookSettings::rowStyle() const 216int DateBookSettings::rowStyle() const
189{ 217{
190 return comboRowStyle->currentItem(); 218 return comboRowStyle->currentItem();
191} 219}
diff --git a/core/pim/datebook/datebooksettings.h b/core/pim/datebook/datebooksettings.h
index df7d32c..912088f 100644
--- a/core/pim/datebook/datebooksettings.h
+++ b/core/pim/datebook/datebooksettings.h
@@ -1,71 +1,77 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved. 2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3** 3**
4** This file is part of Qtopia Environment. 4** This file is part of Qtopia Environment.
5** 5**
6** This file may be distributed and/or modified under the terms of the 6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software 7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the 8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file. 9** packaging of this file.
10** 10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13** 13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information. 14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15** 15**
16** Contact info@trolltech.com if any conditions of this licensing are 16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you. 17** not clear to you.
18** 18**
19**********************************************************************/ 19**********************************************************************/
20 20
21#ifndef DATEBOOKSETTINGS_H 21#ifndef DATEBOOKSETTINGS_H
22#define DATEBOOKSETTINGS_H 22#define DATEBOOKSETTINGS_H
23#include "datebooksettingsbase.h" 23#include "datebooksettingsbase.h"
24#include <qpe/categoryselect.h> 24#include <qpe/categoryselect.h>
25#include <qvaluelist.h>
25 26
26namespace Opie { 27namespace Opie {
27namespace Core { 28namespace Core {
28 class OPluginManager; 29 class OPluginManager;
29 class OGenericPluginLoader; 30 class OGenericPluginLoader;
30 class OPluginLoader; 31 class OPluginLoader;
31} 32}
32namespace Ui { 33namespace Ui {
33 class OPluginConfigWidget; 34 class OPluginConfigWidget;
34} 35}
36namespace Datebook {
37 class HolidayPluginConfigWidget;
38}
35} 39}
36 40
37class DateBookSettings : public DateBookSettingsBase 41class DateBookSettings : public DateBookSettingsBase
38{ 42{
39 Q_OBJECT 43 Q_OBJECT
40public: 44public:
41 DateBookSettings( bool whichClock, QWidget *parent = 0, 45 DateBookSettings( bool whichClock, QWidget *parent = 0,
42 const char *name = 0, bool modal = TRUE, WFlags = 0 ); 46 const char *name = 0, bool modal = TRUE, WFlags = 0 );
43 ~DateBookSettings(); 47 ~DateBookSettings();
44 void setStartTime( int newStartViewTime ); 48 void setStartTime( int newStartViewTime );
45 int startTime() const; 49 int startTime() const;
46 void setAlarmPreset( bool bAlarm, int presetTime ); 50 void setAlarmPreset( bool bAlarm, int presetTime );
47 bool alarmPreset() const; 51 bool alarmPreset() const;
48 int presetTime() const; 52 int presetTime() const;
49 void setAlarmType( int alarmType ); 53 void setAlarmType( int alarmType );
50 int alarmType() const; 54 int alarmType() const;
51 55
52 void setJumpToCurTime( bool bJump ); 56 void setJumpToCurTime( bool bJump );
53 bool jumpToCurTime() const; 57 bool jumpToCurTime() const;
54 void setRowStyle( int style ); 58 void setRowStyle( int style );
55 int rowStyle() const; 59 int rowStyle() const;
56 60
57 void setPluginList(Opie::Core::OPluginManager*,Opie::Core::OPluginLoader*); 61 void setPluginList(Opie::Core::OPluginManager*,Opie::Core::OPluginLoader*);
62 void savePlugins();
58private slots: 63private slots:
59 void slot12Hour( int ); 64 void slot12Hour( int );
60 void slotChangeClock( bool ); 65 void slotChangeClock( bool );
61protected slots: 66protected slots:
62 virtual void pluginItemClicked(QListViewItem *); 67 virtual void pluginItemClicked(QListViewItem *);
63 68
64protected: 69protected:
65 void init(); 70 void init();
66 bool ampm; 71 bool ampm;
67 int oldtime; 72 int oldtime;
68 Opie::Core::OPluginManager*m_manager; 73 Opie::Core::OPluginManager*m_manager;
69 Opie::Core::OPluginLoader*m_loader; 74 Opie::Core::OPluginLoader*m_loader;
75 QValueList<Opie::Datebook::HolidayPluginConfigWidget*> m_cfgWidgets;
70}; 76};
71#endif 77#endif
diff --git a/core/pim/datebook/holiday/national/national-holidays.pro b/core/pim/datebook/holiday/national/national-holidays.pro
index 8b2b33e..3da9c3b 100644
--- a/core/pim/datebook/holiday/national/national-holidays.pro
+++ b/core/pim/datebook/holiday/national/national-holidays.pro
@@ -1,20 +1,20 @@
1TEMPLATE = lib 1TEMPLATE = lib
2CONFIG -= moc 2CONFIG -= moc
3CONFIG += qt plugin 3CONFIG += qt plugin
4 4
5# Input 5# Input
6HEADERS = nationalholiday.h nationalcfg.h 6HEADERS = nationalholiday.h nationalcfg.h nationalcfgwidget.h
7SOURCES = nationalholiday.cpp nationalcfg.cpp 7SOURCES = nationalholiday.cpp nationalcfg.cpp nationalcfgwidget.cpp
8INTERFACES= 8INTERFACES=
9 9
10INCLUDEPATH += $(OPIEDIR)/include \ 10INCLUDEPATH += $(OPIEDIR)/include \
11 ../ ../library 11 ../ ../library
12DEPENDPATH += $(OPIEDIR)/include \ 12DEPENDPATH += $(OPIEDIR)/include \
13 ../ ../library 13 ../ ../library
14 14
15LIBS+= -lqpe -lopiecore2 -lopieui2 15LIBS+= -lqpe -lopiecore2 -lopieui2
16 16
17DESTDIR = $(OPIEDIR)/plugins/holidays 17DESTDIR = $(OPIEDIR)/plugins/holidays
18TARGET = nationaldayplugin 18TARGET = nationaldayplugin
19 19
20include( $(OPIEDIR)/include.pro ) 20include( $(OPIEDIR)/include.pro )
diff --git a/core/pim/datebook/holiday/national/nationalcfg.cpp b/core/pim/datebook/holiday/national/nationalcfg.cpp
index a293251..52c453f 100644
--- a/core/pim/datebook/holiday/national/nationalcfg.cpp
+++ b/core/pim/datebook/holiday/national/nationalcfg.cpp
@@ -1,149 +1,142 @@
1#include "nationalcfg.h" 1#include "nationalcfg.h"
2 2
3#include <opie2/odebug.h> 3#include <opie2/odebug.h>
4 4
5#include <qfile.h> 5#include <qfile.h>
6 6
7static QString _key_desc="description"; 7static QString _key_desc="description";
8static QString _key_doc="nationaldays"; 8static QString _key_doc="nationaldays";
9static QString _key_list="entries"; 9static QString _key_list="entries";
10static QString _key_entry="entry"; 10static QString _key_entry="entry";
11static QString _content_name="name"; 11static QString _content_name="name";
12static QString _content_date="date"; 12static QString _content_date="date";
13 13
14NHcfg::NHcfg() 14NHcfg::NHcfg()
15 :QXmlDefaultHandler(),err(""),_path("") 15 :QXmlDefaultHandler(),err(""),_path("")
16{ 16{
17} 17}
18 18
19NHcfg::~NHcfg() 19NHcfg::~NHcfg()
20{ 20{
21} 21}
22 22
23bool NHcfg::load(const QString&aPath) 23bool NHcfg::load(const QString&aPath)
24{ 24{
25 _path=aPath; 25 _path=aPath;
26 stage = 0; 26 stage = 0;
27 _content.clear(); 27 _content.clear();
28 odebug << "Start loading file "<<_path<<oendl;
29 QFile *f=new QFile(_path); 28 QFile *f=new QFile(_path);
30 if (!f) { 29 if (!f) {
31 oerr << "Could not open file" << oendl; 30 oerr << "Could not open file" << oendl;
32 return false; 31 return false;
33 } 32 }
34 odebug << "Source" << oendl;
35 QXmlInputSource is(*f); 33 QXmlInputSource is(*f);
36 odebug << "Reader" << oendl;
37 QXmlSimpleReader reader; 34 QXmlSimpleReader reader;
38 odebug << "Handler" << oendl;
39 reader.setContentHandler(this); 35 reader.setContentHandler(this);
40 odebug << "Error handler" << oendl;
41 reader.setErrorHandler(this); 36 reader.setErrorHandler(this);
42 37
43 err = ""; 38 err = "";
44 odebug << "parse it" << oendl;
45 bool ret = reader.parse(is); 39 bool ret = reader.parse(is);
46 odebug << "Errors: " << err << oendl; 40 if (err.length()>0)
41 odebug << "Errors: " << err << oendl;
47 return ret; 42 return ret;
48} 43}
49 44
50const tholidaylist&NHcfg::days()const 45const tholidaylist&NHcfg::days()const
51{ 46{
52 return _content; 47 return _content;
53} 48}
54 49
55bool NHcfg::warning(const QXmlParseException& e) 50bool NHcfg::warning(const QXmlParseException& e)
56{ 51{
57 QString tmp; 52 QString tmp;
58 53
59 tmp.sprintf("%d: warning: %s\n", e.lineNumber(), 54 tmp.sprintf("%d: warning: %s\n", e.lineNumber(),
60 (const char*) e.message().utf8()); 55 (const char*) e.message().utf8());
61 56
62 err += tmp; 57 err += tmp;
63 58
64 return true; 59 return true;
65} 60}
66 61
67bool NHcfg::error(const QXmlParseException& e) 62bool NHcfg::error(const QXmlParseException& e)
68{ 63{
69 QString tmp; 64 QString tmp;
70 65
71 tmp.sprintf("%d: error: %s\n", e.lineNumber(), 66 tmp.sprintf("%d: error: %s\n", e.lineNumber(),
72 (const char*) e.message().utf8()); 67 (const char*) e.message().utf8());
73 68
74 err += tmp; 69 err += tmp;
75 70
76 return true; 71 return true;
77} 72}
78 73
79bool NHcfg::fatalError(const QXmlParseException& e) 74bool NHcfg::fatalError(const QXmlParseException& e)
80{ 75{
81 QString tmp; 76 QString tmp;
82 77
83 tmp.sprintf("%d: fatal error: %s\n", e.lineNumber(), 78 tmp.sprintf("%d: fatal error: %s\n", e.lineNumber(),
84 (const char*) e.message().utf8()); 79 (const char*) e.message().utf8());
85 80
86 err += tmp; 81 err += tmp;
87 82
88 return false; 83 return false;
89} 84}
90 85
91bool NHcfg::startElement(const QString&, const QString&,const QString& name, const QXmlAttributes& attr) 86bool NHcfg::startElement(const QString&, const QString&,const QString& name, const QXmlAttributes& attr)
92{ 87{
93 bool ret = false; 88 bool ret = false;
94 odebug << "startElement: " << name << oendl;
95 if (name==_key_doc) { 89 if (name==_key_doc) {
96 stage = 1; 90 stage = 1;
97 return true; 91 return true;
98 } 92 }
99 if (stage == 0) { 93 if (stage == 0) {
100 err = "This is not a national holiday config file"; 94 err = "This is not a national holiday config file";
101 return false; 95 return false;
102 } 96 }
103 if (name==_key_desc) { 97 if (name==_key_desc) {
104 stage = 2; 98 stage = 2;
105 ret = setName(attr); 99 ret = setName(attr);
106 return ret; 100 return ret;
107 } 101 }
108 if (stage<2) {return false;} 102 if (stage<2) {return false;}
109 if (name==_key_list) {stage=3;return true;} 103 if (name==_key_list) {stage=3;return true;}
110 if (stage<3) {return false;} 104 if (stage<3) {return false;}
111 return parsevalue(name,attr); 105 return parsevalue(name,attr);
112} 106}
113 107
114bool NHcfg::parsevalue(const QString&name,const QXmlAttributes&attr) 108bool NHcfg::parsevalue(const QString&name,const QXmlAttributes&attr)
115{ 109{
116 int nindex = attr.index(_content_name); 110 int nindex = attr.index(_content_name);
117 int dindex = attr.index(_content_date); 111 int dindex = attr.index(_content_date);
118 if (name != _key_entry) {err = "Not a valid entry"; return false;} 112 if (name != _key_entry) {err = "Not a valid entry"; return false;}
119 if (dindex == -1 || nindex == -1) {err = QString("Listentry %i is invalid").arg(1);return false;} 113 if (dindex == -1 || nindex == -1) {err = QString("Listentry %i is invalid").arg(1);return false;}
120 QString txt = attr.value(nindex); 114 QString txt = attr.value(nindex);
121 QString dstring = attr.value(dindex); 115 QString dstring = attr.value(dindex);
122 QStringList e = QStringList::split("-",dstring); 116 QStringList e = QStringList::split("-",dstring);
123 if (e.count()!=2){err=QString("Datestring %1 is invalid").arg(dstring);return false;} 117 if (e.count()!=2){err=QString("Datestring %1 is invalid").arg(dstring);return false;}
124 QDate d(0,e[0].toInt(),e[1].toInt()); 118 QDate d(0,e[0].toInt(),e[1].toInt());
125 odebug << "Found entry \"" << txt<<"\" on "<<d<<oendl; 119 odebug << "Found entry \"" << txt<<"\" on "<<d<<oendl;
126 _content[d].append(txt); 120 _content[d].append(txt);
127 return true; 121 return true;
128} 122}
129 123
130bool NHcfg::endElement(const QString&, const QString&,const QString& name) 124bool NHcfg::endElement(const QString&, const QString&,const QString& name)
131{ 125{
132 return true; 126 return true;
133} 127}
134 128
135const QString&NHcfg::errorString()const 129const QString&NHcfg::errorString()const
136{ 130{
137 return err; 131 return err;
138} 132}
139 133
140bool NHcfg::setName(const QXmlAttributes&attr) 134bool NHcfg::setName(const QXmlAttributes&attr)
141{ 135{
142 int nindx = attr.index("value"); 136 int nindx = attr.index("value");
143 if (nindx==-1) { 137 if (nindx==-1) {
144 return false; 138 return false;
145 } 139 }
146 _contentname = attr.value(nindx); 140 _contentname = attr.value(nindx);
147 odebug << "Contentname = " << _contentname<<oendl;
148 return true; 141 return true;
149} 142}
diff --git a/core/pim/datebook/holiday/national/nationalcfgwidget.cpp b/core/pim/datebook/holiday/national/nationalcfgwidget.cpp
new file mode 100644
index 0000000..6e3dd7d
--- a/dev/null
+++ b/core/pim/datebook/holiday/national/nationalcfgwidget.cpp
@@ -0,0 +1,99 @@
1#include "nationalcfgwidget.h"
2
3#include <opie2/odebug.h>
4
5#include <qpe/config.h>
6#include <qpe/qpeapplication.h>
7
8#include <qheader.h>
9#include <qlabel.h>
10#include <qlistview.h>
11#include <qpushbutton.h>
12#include <qlayout.h>
13#include <qvariant.h>
14#include <qtooltip.h>
15#include <qwhatsthis.h>
16#include <qheader.h>
17#include <qdir.h>
18
19/*
20 * Constructs a NationalHolidayConfig which is a child of 'parent', with the
21 * name 'name' and widget flags set to 'f'
22 */
23NationalHolidayConfigWidget::NationalHolidayConfigWidget( QWidget* parent, const char* name, WFlags fl )
24 : Opie::Datebook::HolidayPluginConfigWidget( parent, name, fl )
25{
26 if ( !name )
27 setName( "NationalHolidayConfig" );
28 resize( 206, 210 );
29 setCaption( tr( "Select national config" ) );
30 NationalHolidayConfigLayout = new QVBoxLayout( this );
31 NationalHolidayConfigLayout->setSpacing( 2 );
32 NationalHolidayConfigLayout->setMargin( 2 );
33
34 m_headLabel = new QLabel( this, "m_headLabel" );
35 m_headLabel->setText( tr( "Select one or more configs to load" ) );
36 m_headLabel->setAlignment( int( QLabel::AlignCenter ) );
37 NationalHolidayConfigLayout->addWidget( m_headLabel );
38
39 m_Configlist = new QListView( this, "m_Configlist" );
40 m_Configlist->addColumn( tr( "configfiles" ) );
41 QWhatsThis::add( m_Configlist, tr( "List of found xml-files which may load." ) );
42 NationalHolidayConfigLayout->addWidget( m_Configlist );
43
44 // signals and slots connections
45 connect( m_Configlist, SIGNAL( clicked(QListViewItem*) ), this, SLOT( listItemClicked(QListViewItem*) ) );
46 init();
47}
48
49void NationalHolidayConfigWidget::init()
50{
51 m_Configlist->header()->hide();
52 m_Configlist->setSorting(-1);
53
54 QString path = QPEApplication::qpeDir() + "etc/nationaldays";
55 QDir dir( path, "*.xml" );
56 QStringList list = dir.entryList();
57 QStringList::Iterator it;
58 Config cfg("nationaldays");
59 cfg.setGroup("entries");
60 files = cfg.readListEntry("files");
61 QCheckListItem *pitem = 0;
62
63 for (it=list.begin();it!=list.end();++it) {
64 pitem = new QCheckListItem(m_Configlist,(*it),QCheckListItem::CheckBox);
65 if (files.find((*it)) != files.end()) {
66 pitem->setOn(true);
67 } else {
68 pitem->setOn(false);
69 }
70 }
71}
72
73/*
74 * Destroys the object and frees any allocated resources
75 */
76NationalHolidayConfigWidget::~NationalHolidayConfigWidget()
77{
78 // no need to delete child widgets, Qt does it all for us
79}
80
81void NationalHolidayConfigWidget::listItemClicked(QListViewItem*item)
82{
83 if (!item) return;
84 QCheckListItem*pitem = ((QCheckListItem*)item);
85 QStringList::Iterator it = files.find(pitem->text(0));
86 if (pitem->isOn()&&it==files.end()) {
87 files.append(pitem->text(0));
88 } else if (!pitem->isOn() && it!=files.end()) {
89 files.remove(it);
90 }
91}
92
93void NationalHolidayConfigWidget::saveConfig()
94{
95 Config cfg("nationaldays");
96 cfg.setGroup("entries");
97 cfg.writeEntry("files",files);
98}
99
diff --git a/core/pim/datebook/holiday/national/nationalcfgwidget.h b/core/pim/datebook/holiday/national/nationalcfgwidget.h
new file mode 100644
index 0000000..9f16aa4
--- a/dev/null
+++ b/core/pim/datebook/holiday/national/nationalcfgwidget.h
@@ -0,0 +1,39 @@
1#ifndef NATIONALHOLIDAYCONFIGWIDGET_H
2#define NATIONALHOLIDAYCONFIGWIDGET_H
3
4#include <opie2/oholidayplugincfgwidget.h>
5
6#include <qvariant.h>
7#include <qwidget.h>
8#include <qstringlist.h>
9
10class QVBoxLayout;
11class QHBoxLayout;
12class QGridLayout;
13class QLabel;
14class QListView;
15class QListViewItem;
16
17class NationalHolidayConfigWidget : public Opie::Datebook::HolidayPluginConfigWidget
18{
19 Q_OBJECT
20
21public:
22 NationalHolidayConfigWidget( QWidget* parent = 0, const char* name = 0, WFlags fl = 0 );
23 virtual ~NationalHolidayConfigWidget();
24
25 virtual void saveConfig();
26
27protected slots:
28 virtual void listItemClicked(QListViewItem*);
29
30protected:
31 void init();
32
33 QVBoxLayout* NationalHolidayConfigLayout;
34 QLabel* m_headLabel;
35 QListView* m_Configlist;
36 QStringList files;
37};
38
39#endif // NATIONALHOLIDAYCONFIG_H
diff --git a/core/pim/datebook/holiday/national/nationalholiday.cpp b/core/pim/datebook/holiday/national/nationalholiday.cpp
index 26cd913..52f3489 100644
--- a/core/pim/datebook/holiday/national/nationalholiday.cpp
+++ b/core/pim/datebook/holiday/national/nationalholiday.cpp
@@ -1,123 +1,130 @@
1#include "nationalholiday.h" 1#include "nationalholiday.h"
2#include "nationalcfg.h" 2#include "nationalcfg.h"
3#include "nationalcfgwidget.h"
3 4
4#include <opie2/odebug.h> 5#include <opie2/odebug.h>
5 6
6#include <qobject.h> 7#include <qobject.h>
7#include <qpe/event.h> 8#include <qpe/event.h>
8#include <qpe/config.h> 9#include <qpe/config.h>
9#include <qpe/qpeapplication.h> 10#include <qpe/qpeapplication.h>
10 11
11NationalHoliday::NationalHoliday() 12NationalHoliday::NationalHoliday()
12 :Opie::Datebook::HolidayPlugin() 13 :Opie::Datebook::HolidayPlugin()
13{ 14{
14 _lastyear=0; 15 _lastyear=0;
15 init_done = false; 16 init_done = false;
16 init(); 17 init();
17} 18}
18 19
19QString NationalHoliday::description() 20QString NationalHoliday::description()
20{ 21{
21 return QObject::tr("National holidays","holidays"); 22 return QObject::tr("National holidays","holidays");
22} 23}
23 24
24void NationalHoliday::init() 25void NationalHoliday::init()
25{ 26{
26 Config cfg("nationaldays"); 27 Config cfg("nationaldays");
27 cfg.setGroup("entries"); 28 cfg.setGroup("entries");
28 files = cfg.readListEntry("files"); 29 files = cfg.readListEntry("files");
29 odebug << "Read " << files << oendl;
30} 30}
31 31
32void NationalHoliday::load_days() 32void NationalHoliday::load_days()
33{ 33{
34 if (init_done) return; 34 if (init_done) return;
35 Config cfg("nationaldays");
36 cfg.setGroup("entries");
35 QStringList::ConstIterator it; 37 QStringList::ConstIterator it;
36 NHcfg readit; 38 NHcfg readit;
37 for (it=files.begin();it!=files.end();++it) { 39 for (it=files.begin();it!=files.end();++it) {
38 odebug << QPEApplication::qpeDir()+"/etc/nationaldays/"+(*it) << oendl; 40 if (!readit.load(QPEApplication::qpeDir()+"/etc/nationaldays/"+(*it))) {
39 if (!readit.load(QPEApplication::qpeDir()+"/etc/nationaldays/"+(*it)))
40 continue; 41 continue;
42 }
41 tholidaylist::ConstIterator it; 43 tholidaylist::ConstIterator it;
42 for (it=readit.days().begin();it!=readit.days().end();++it) { 44 for (it=readit.days().begin();it!=readit.days().end();++it) {
43 _days[it.key()]+=(it.data()); 45 _days[it.key()]+=(it.data());
44 } 46 }
45 47
46 } 48 }
47 init_done = true; 49 init_done = true;
48} 50}
49 51
50QStringList NationalHoliday::entries(const QDate&aDate) 52QStringList NationalHoliday::entries(const QDate&aDate)
51{ 53{
52 load_days(); 54 load_days();
53 QStringList ret; 55 QStringList ret;
54 QDate d(0,aDate.month(),aDate.day()); 56 QDate d(0,aDate.month(),aDate.day());
55 57
56 tholidaylist::Iterator it = _days.find(d); 58 tholidaylist::Iterator it = _days.find(d);
57 if (it!=_days.end()) { 59 if (it!=_days.end()) {
58 ret+=*it; 60 ret+=*it;
59 } 61 }
60 62
61 return ret; 63 return ret;
62} 64}
63 65
64QStringList NationalHoliday::entries(unsigned year, unsigned month, unsigned day) 66QStringList NationalHoliday::entries(unsigned year, unsigned month, unsigned day)
65{ 67{
66 return entries(QDate(0,month,day)); 68 return entries(QDate(0,month,day));
67} 69}
68 70
69QMap<QDate,QStringList> NationalHoliday::entries(const QDate&start,const QDate&end) 71QMap<QDate,QStringList> NationalHoliday::entries(const QDate&start,const QDate&end)
70{ 72{
71 load_days(); 73 load_days();
72 QMap<QDate,QStringList> ret; 74 QMap<QDate,QStringList> ret;
73 if (start==end) { 75 if (start==end) {
74 ret[start]=entries(start); 76 ret[start]=entries(start);
75 return ret; 77 return ret;
76 } 78 }
77 QDate d; 79 QDate d;
78 int daysto; 80 int daysto;
79 if (end < start) { 81 if (end < start) {
80 d = end; 82 d = end;
81 daysto = end.daysTo(start); 83 daysto = end.daysTo(start);
82 } else { 84 } else {
83 d = start; 85 d = start;
84 daysto = start.daysTo(end); 86 daysto = start.daysTo(end);
85 } 87 }
86 QStringList temp; 88 QStringList temp;
87 for (int i=0;i<=daysto;++i) { 89 for (int i=0;i<=daysto;++i) {
88 temp = entries(d.addDays(i)); 90 temp = entries(d.addDays(i));
89 if (temp.count()==0) continue; 91 if (temp.count()==0) continue;
90 ret[d.addDays(i)]+=temp; 92 ret[d.addDays(i)]+=temp;
91 temp.clear(); 93 temp.clear();
92 } 94 }
93 return ret; 95 return ret;
94} 96}
95 97
96QValueList<EffectiveEvent> NationalHoliday::events(const QDate&start,const QDate&end) 98QValueList<EffectiveEvent> NationalHoliday::events(const QDate&start,const QDate&end)
97{ 99{
98 QValueList<EffectiveEvent> ret; 100 QValueList<EffectiveEvent> ret;
99 QDate d = (start<end?start:end); 101 QDate d = (start<end?start:end);
100 int daysto = start.daysTo(end); 102 int daysto = start.daysTo(end);
101 if (daysto < 0) { 103 if (daysto < 0) {
102 daysto = end.daysTo(start); 104 daysto = end.daysTo(start);
103 } 105 }
104 106
105 QStringList temp; 107 QStringList temp;
106 for (int i =0; i<=daysto;++i) { 108 for (int i =0; i<=daysto;++i) {
107 temp = entries(d.addDays(i)); 109 temp = entries(d.addDays(i));
108 if (temp.count()==0) { 110 if (temp.count()==0) {
109 continue; 111 continue;
110 } 112 }
111 for (unsigned j=0;j<temp.count();++j) { 113 for (unsigned j=0;j<temp.count();++j) {
112 Event ev; 114 Event ev;
113 ev.setDescription(temp[j]); 115 ev.setDescription(temp[j]);
114 ev.setStart(d.addDays(i)); 116 ev.setStart(d.addDays(i));
115 ev.setAllDay(true); 117 ev.setAllDay(true);
116 ret.append(EffectiveEvent(ev,d.addDays(i))); 118 ret.append(EffectiveEvent(ev,d.addDays(i)));
117 } 119 }
118 } 120 }
119 121
120 return ret; 122 return ret;
121} 123}
122 124
125Opie::Datebook::HolidayPluginConfigWidget*NationalHoliday::configWidget(QWidget *parent, const char *name, QWidget::WFlags fl)
126{
127 return new NationalHolidayConfigWidget(parent,name,fl);
128}
129
123EXPORT_HOLIDAY_PLUGIN(NationalHoliday); 130EXPORT_HOLIDAY_PLUGIN(NationalHoliday);
diff --git a/core/pim/datebook/holiday/national/nationalholiday.h b/core/pim/datebook/holiday/national/nationalholiday.h
index 6581263..afce3f4 100644
--- a/core/pim/datebook/holiday/national/nationalholiday.h
+++ b/core/pim/datebook/holiday/national/nationalholiday.h
@@ -1,34 +1,36 @@
1#ifndef __NATIONAL_HOLIDAY_H 1#ifndef __NATIONAL_HOLIDAY_H
2#define __NATIONAL_HOLIDAY_H 2#define __NATIONAL_HOLIDAY_H
3 3
4#include "nationalcfg.h" 4#include "nationalcfg.h"
5 5
6#include <opie2/oholidayplugin.h> 6#include <opie2/oholidayplugin.h>
7#include <opie2/oholidaypluginif.h> 7#include <opie2/oholidaypluginif.h>
8#include <opie2/oholidayplugincfgwidget.h>
8 9
9#include <qmap.h> 10#include <qmap.h>
10#include <qstringlist.h> 11#include <qstringlist.h>
11 12
12class NationalHoliday:public Opie::Datebook::HolidayPlugin 13class NationalHoliday:public Opie::Datebook::HolidayPlugin
13{ 14{
14 15
15public: 16public:
16 NationalHoliday(); 17 NationalHoliday();
17 virtual ~NationalHoliday(){} 18 virtual ~NationalHoliday(){}
18 19
19 virtual QString description(); 20 virtual QString description();
20 virtual QStringList entries(const QDate&); 21 virtual QStringList entries(const QDate&);
21 virtual QStringList entries(unsigned year, unsigned month, unsigned day); 22 virtual QStringList entries(unsigned year, unsigned month, unsigned day);
22 virtual QMap<QDate,QStringList> entries(const QDate&,const QDate&); 23 virtual QMap<QDate,QStringList> entries(const QDate&,const QDate&);
23 virtual QValueList<EffectiveEvent> events(const QDate&,const QDate&); 24 virtual QValueList<EffectiveEvent> events(const QDate&,const QDate&);
25 virtual Opie::Datebook::HolidayPluginConfigWidget*configWidget(QWidget *parent=0, const char *name = 0, QWidget::WFlags fl = 0);
24 26
25protected: 27protected:
26 void init(); 28 void init();
27 unsigned int _lastyear; 29 unsigned int _lastyear;
28 tholidaylist _days; 30 tholidaylist _days;
29 QStringList files; 31 QStringList files;
30 bool init_done:1; 32 bool init_done:1;
31 void load_days(); 33 void load_days();
32}; 34};
33 35
34#endif 36#endif
diff --git a/libopie2/opiepim/ui/oholidayplugin.h b/libopie2/opiepim/ui/oholidayplugin.h
index 52db0eb..192a020 100644
--- a/libopie2/opiepim/ui/oholidayplugin.h
+++ b/libopie2/opiepim/ui/oholidayplugin.h
@@ -1,29 +1,33 @@
1#ifndef _HOLIDAY_PLUGIN_H 1#ifndef _HOLIDAY_PLUGIN_H
2#define _HOLIDAY_PLUGIN_H 2#define _HOLIDAY_PLUGIN_H
3 3
4#include <qstring.h> 4#include <qstring.h>
5#include <qstringlist.h> 5#include <qstringlist.h>
6#include <qdatetime.h> 6#include <qdatetime.h>
7#include <qmap.h> 7#include <qmap.h>
8#include <qwidget.h>
8 9
9class EffectiveEvent; 10class EffectiveEvent;
10 11
11namespace Opie { 12namespace Opie {
12namespace Datebook { 13namespace Datebook {
13 14
15class HolidayPluginConfigWidget;
16
14class HolidayPlugin 17class HolidayPlugin
15{ 18{
16public: 19public:
17 HolidayPlugin(){}; 20 HolidayPlugin(){};
18 virtual ~HolidayPlugin(){}; 21 virtual ~HolidayPlugin(){};
19 virtual QString description()=0; 22 virtual QString description()=0;
20 virtual QStringList entries(const QDate&)=0; 23 virtual QStringList entries(const QDate&)=0;
21 virtual QStringList entries(unsigned year, unsigned month, unsigned day)=0; 24 virtual QStringList entries(unsigned year, unsigned month, unsigned day)=0;
22 virtual QMap<QDate,QStringList> entries(const QDate&,const QDate&)=0; 25 virtual QMap<QDate,QStringList> entries(const QDate&,const QDate&)=0;
23 virtual QValueList<EffectiveEvent> events(const QDate&,const QDate&)=0; 26 virtual QValueList<EffectiveEvent> events(const QDate&,const QDate&)=0;
24};
25 27
28 virtual HolidayPluginConfigWidget*configWidget(QWidget *parent=0, const char *name = 0, QWidget::WFlags fl = 0 ){return 0;}
29};
26} 30}
27} 31}
28#endif 32#endif
29 33
diff --git a/libopie2/opiepim/ui/oholidayplugincfgwidget.cpp b/libopie2/opiepim/ui/oholidayplugincfgwidget.cpp
new file mode 100644
index 0000000..43380bb
--- a/dev/null
+++ b/libopie2/opiepim/ui/oholidayplugincfgwidget.cpp
@@ -0,0 +1,14 @@
1#include "oholidayplugincfgwidget.h"
2
3namespace Opie {
4namespace Datebook {
5HolidayPluginConfigWidget::HolidayPluginConfigWidget( QWidget* parent, const char* name, WFlags fl )
6 : QWidget( parent, name, fl )
7{}
8
9HolidayPluginConfigWidget::~HolidayPluginConfigWidget()
10{}
11
12}
13}
14
diff --git a/libopie2/opiepim/ui/oholidayplugincfgwidget.h b/libopie2/opiepim/ui/oholidayplugincfgwidget.h
new file mode 100644
index 0000000..17af467
--- a/dev/null
+++ b/libopie2/opiepim/ui/oholidayplugincfgwidget.h
@@ -0,0 +1,30 @@
1#ifndef _HOLIDAY_PLUGIN_CFG_WIDGET
2#define _HOLIDAY_PLUGIN_CFG_WIDGET
3#include <qwidget.h>
4
5namespace Opie {
6namespace Datebook {
7class HolidayPluginConfigWidget:public QWidget
8{
9 Q_OBJECT
10public:
11 /**
12 * This will construct the widget. The widget gets deleted once the parent
13 * gets deleted as in any Qt application
14 *
15 * A Parent is required!
16 *
17 * @param parent The parent of the widget
18 * @param name The name of the object
19 */
20 HolidayPluginConfigWidget(QWidget *parent, const char *name = 0, WFlags fl = 0 );
21 virtual ~HolidayPluginConfigWidget();
22
23 virtual void saveConfig()=0;
24};
25
26}
27}
28
29#endif
30
diff --git a/libopie2/opiepim/ui/oholidaypluginif.h b/libopie2/opiepim/ui/oholidaypluginif.h
index 825d3ad..618d371 100644
--- a/libopie2/opiepim/ui/oholidaypluginif.h
+++ b/libopie2/opiepim/ui/oholidaypluginif.h
@@ -1,62 +1,60 @@
1#ifndef _O_HOLIDAY_PLUGIN_IF_H 1#ifndef _O_HOLIDAY_PLUGIN_IF_H
2#define _O_HOLIDAY_PLUGIN_IF_H 2#define _O_HOLIDAY_PLUGIN_IF_H
3#include <opie2/odebug.h> 3#include <opie2/odebug.h>
4#include <qpe/qcom.h> 4#include <qpe/qcom.h>
5 5
6#ifndef QT_NO_COMPONENT 6#ifndef QT_NO_COMPONENT
7//017f90d4-34fc-4dc5-aed7-498c6da6571e 7//c0a5f73f-975e-4492-9285-af555284c4ab
8#define IID_HOLIDAY_PLUGIN QUuid(0x017f90d4,0x34fc,0x4dc5,0xae,0xd7,0x49,0x8c,0x6d,0xa6,0x57,0x1e) 8#define IID_HOLIDAY_PLUGIN QUuid(0xc0a5f73f,0x975e,0x4492,0x92,0x85,0xaf,0x55,0x52,0x84,0xc4,0xab)
9#endif 9#endif
10 10
11namespace Opie { 11namespace Opie {
12namespace Datebook { 12namespace Datebook {
13 13
14class HolidayPlugin; 14class HolidayPlugin;
15 15
16class HolidayPluginIf:public QUnknownInterface 16class HolidayPluginIf:public QUnknownInterface
17{ 17{
18public: 18public:
19 HolidayPluginIf():QUnknownInterface(){} 19 HolidayPluginIf():QUnknownInterface(){}
20 virtual ~HolidayPluginIf(){} 20 virtual ~HolidayPluginIf(){}
21 21
22 virtual HolidayPlugin*plugin()=0; 22 virtual HolidayPlugin*plugin()=0;
23}; 23};
24 24
25template<class T> class HolidayPluginWrapper:public HolidayPluginIf 25template<class T> class HolidayPluginWrapper:public HolidayPluginIf
26{ 26{
27public: 27public:
28 HolidayPluginWrapper():HolidayPluginIf(),_plugin(0){} 28 HolidayPluginWrapper():HolidayPluginIf(),_plugin(0){}
29 virtual ~HolidayPluginWrapper(){if (_plugin) delete _plugin;} 29 virtual ~HolidayPluginWrapper(){if (_plugin) delete _plugin;}
30 30
31 QRESULT queryInterface( const QUuid& uuid, QUnknownInterface** iface ) { 31 QRESULT queryInterface( const QUuid& uuid, QUnknownInterface** iface ) {
32 odebug << "HolidayPluginWrapper::queryInterface()" << oendl;
33 *iface = 0; 32 *iface = 0;
34 if (uuid == IID_HOLIDAY_PLUGIN || uuid == IID_QUnknown) { 33 if (uuid == IID_HOLIDAY_PLUGIN || uuid == IID_QUnknown) {
35 *iface = this; 34 *iface = this;
36 } else { 35 } else {
37 return QS_FALSE; 36 return QS_FALSE;
38 } 37 }
39 if (*iface) (*iface)->addRef(); 38 if (*iface) (*iface)->addRef();
40 return QS_OK; 39 return QS_OK;
41 } 40 }
42 41
43 // from qcom 42 // from qcom
44 Q_REFCOUNT 43 Q_REFCOUNT
45 44
46 virtual T*plugin() { 45 virtual T*plugin() {
47 if (!_plugin) {_plugin = new T();} 46 if (!_plugin) {_plugin = new T();}
48 return _plugin; 47 return _plugin;
49 } 48 }
50protected: 49protected:
51 T*_plugin; 50 T*_plugin;
52}; 51};
53 52
54#define EXPORT_HOLIDAY_PLUGIN( Plugin ) \ 53#define EXPORT_HOLIDAY_PLUGIN( Plugin ) \
55 Q_EXPORT_INTERFACE() { \ 54 Q_EXPORT_INTERFACE() { \
56 Q_CREATE_INSTANCE( Opie::Datebook::HolidayPluginWrapper<Plugin> ) \ 55 Q_CREATE_INSTANCE( Opie::Datebook::HolidayPluginWrapper<Plugin> ) \
57 } 56 }
58
59} 57}
60} 58}
61#endif 59#endif
62 60
diff --git a/libopie2/opiepim/ui/ui.pro b/libopie2/opiepim/ui/ui.pro
index 53c7ae2..97c8d81 100644
--- a/libopie2/opiepim/ui/ui.pro
+++ b/libopie2/opiepim/ui/ui.pro
@@ -1,10 +1,14 @@
1HEADERS += ui/opimmainwindow.h \ 1HEADERS += ui/opimmainwindow.h \
2 ui/opimrecurrencewidget.h \ 2 ui/opimrecurrencewidget.h \
3 ui/todayconfigwidget.h \ 3 ui/todayconfigwidget.h \
4 ui/todayplugininterface.h 4 ui/todayplugininterface.h \
5 ui/oholidayplugin.h \
6 ui/oholidayplugincfgwidget.h \
7 ui/oholidaypluginif.h
5 8
6SOURCES += ui/opimmainwindow.cpp \ 9SOURCES += ui/opimmainwindow.cpp \
7 ui/opimrecurrencewidget.cpp \ 10 ui/opimrecurrencewidget.cpp \
8 ui/todayconfigwidget.cpp 11 ui/todayconfigwidget.cpp \
12 ui/oholidayplugincfgwidget.cpp
9 13
10INTERFACES += ui/opimrecurrencebase.ui 14INTERFACES += ui/opimrecurrencebase.ui