summaryrefslogtreecommitdiff
path: root/core/pim/datebook/datebook.cpp
Unidiff
Diffstat (limited to 'core/pim/datebook/datebook.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--core/pim/datebook/datebook.cpp1258
1 files changed, 667 insertions, 591 deletions
diff --git a/core/pim/datebook/datebook.cpp b/core/pim/datebook/datebook.cpp
index a18a5b4..f6aab0c 100644
--- a/core/pim/datebook/datebook.cpp
+++ b/core/pim/datebook/datebook.cpp
@@ -31,4 +31,6 @@
31 31
32#include <opie2/odebug.h> 32#include <opie2/odebug.h>
33#include <opie2/oholidaypluginif.h>
34#include <opie2/oholidayplugin.h>
33 35
34#include <qpe/datebookmonth.h> 36#include <qpe/datebookmonth.h>
@@ -50,4 +52,6 @@
50#include <qtoolbar.h> 52#include <qtoolbar.h>
51#include <qwidgetstack.h> 53#include <qwidgetstack.h>
54#include <qdir.h>
55#include <qtopia/qlibrary.h>
52 56
53#include <sys/stat.h> 57#include <sys/stat.h>
@@ -69,22 +73,24 @@ DateBook::DateBook( QWidget *parent, const char *, WFlags f )
69 alarmCounter(0) 73 alarmCounter(0)
70{ 74{
71 bool needEvilHack= false; // if we need an Evil Hack 75 bool needEvilHack= false; // if we need an Evil Hack
72 QTime t; 76 QTime t;
73 t.start(); 77 t.start();
74 db = new DateBookDBHack; 78 db = new DateBookDBHack;
75 odebug << "loading db t=" << t.elapsed() << oendl; 79 odebug << "loading db t=" << t.elapsed() << oendl;
76 loadSettings(); 80 db_holiday = new DateBookHoliday();
77 setCaption( tr("Calendar") );
78 setIcon( Resource::loadPixmap( "datebook_icon" ) );
79 81
80 setToolBarsMovable( FALSE ); 82 loadSettings();
83 setCaption( tr("Calendar") );
84 setIcon( Resource::loadPixmap( "datebook_icon" ) );
81 85
82 views = new QWidgetStack( this ); 86 setToolBarsMovable( FALSE );
83 setCentralWidget( views );
84 87
85 dayView = 0; 88 views = new QWidgetStack( this );
86 weekView = 0; 89 setCentralWidget( views );
87 weekLstView = 0; 90
88 monthView = 0; 91 dayView = 0;
92 weekView = 0;
93 weekLstView = 0;
94 monthView = 0;
89 95
90// QToolBar *bar = new QToolBar( this ); 96// QToolBar *bar = new QToolBar( this );
@@ -97,72 +103,72 @@ DateBook::DateBook( QWidget *parent, const char *, WFlags f )
97// mb->insertItem( tr( "View" ), view ); 103// mb->insertItem( tr( "View" ), view );
98 104
99 QToolBar *sub_bar = new QToolBar(this); 105 QToolBar *sub_bar = new QToolBar(this);
100 sub_bar->setHorizontalStretchable(TRUE); 106 sub_bar->setHorizontalStretchable(TRUE);
101 107
102 QActionGroup *g = new QActionGroup( this ); 108 QActionGroup *g = new QActionGroup( this );
103 g->setExclusive( TRUE ); 109 g->setExclusive( TRUE );
104 110
105 QAction *a = new QAction( tr( "New" ), Resource::loadPixmap( "new" ), QString::null, 0, this, 0 ); 111 QAction *a = new QAction( tr( "New" ), Resource::loadPixmap( "new" ), QString::null, 0, this, 0 );
106 connect( a, SIGNAL( activated() ), this, SLOT( fileNew() ) ); 112 connect( a, SIGNAL( activated() ), this, SLOT( fileNew() ) );
107 a->addTo( sub_bar ); 113 a->addTo( sub_bar );
108 114
109 sub_bar->addSeparator(); 115 sub_bar->addSeparator();
110 116
111 a = new QAction( tr( "Today" ), Resource::loadPixmap( "datebook/to_day" ), QString::null, 0, g, 0 ); 117 a = new QAction( tr( "Today" ), Resource::loadPixmap( "datebook/to_day" ), QString::null, 0, g, 0 );
112 connect( a, SIGNAL( activated() ), this, SLOT( slotToday() ) ); 118 connect( a, SIGNAL( activated() ), this, SLOT( slotToday() ) );
113 a->addTo( sub_bar ); 119 a->addTo( sub_bar );
114 //a->addTo( view ); 120// a->addTo( view );
115 121
116 sub_bar->addSeparator(); 122 sub_bar->addSeparator();
117 123
118 a = new QAction( tr( "Day" ), Resource::loadPixmap( "day" ), QString::null, 0, g, 0 ); 124 a = new QAction( tr( "Day" ), Resource::loadPixmap( "day" ), QString::null, 0, g, 0 );
119 connect( a, SIGNAL( activated() ), this, SLOT( viewDay() ) ); 125 connect( a, SIGNAL( activated() ), this, SLOT( viewDay() ) );
120 a->addTo( sub_bar ); 126 a->addTo( sub_bar );
121// a->addTo( view ); 127// a->addTo( view );
122 a->setToggleAction( TRUE ); 128 a->setToggleAction( TRUE );
123 a->setOn( TRUE ); 129 a->setOn( TRUE );
124 dayAction = a; 130 dayAction = a;
125 131
126 a = new QAction( tr( "Week" ), Resource::loadPixmap( "week" ), QString::null, 0, g, 0 ); 132 a = new QAction( tr( "Week" ), Resource::loadPixmap( "week" ), QString::null, 0, g, 0 );
127 connect( a, SIGNAL( activated() ), this, SLOT( viewWeek() ) ); 133 connect( a, SIGNAL( activated() ), this, SLOT( viewWeek() ) );
128 a->addTo( sub_bar ); 134 a->addTo( sub_bar );
129// a->addTo( view ); 135// a->addTo( view );
130 a->setToggleAction( TRUE ); 136 a->setToggleAction( TRUE );
131 weekAction = a; 137 weekAction = a;
132 138
133 a = new QAction( tr( "WeekLst" ), Resource::loadPixmap( "datebook/weeklst" ), QString::null, 0, g, 0 ); 139 a = new QAction( tr( "WeekLst" ), Resource::loadPixmap( "datebook/weeklst" ), QString::null, 0, g, 0 );
134 connect( a, SIGNAL( activated() ), this, SLOT( viewWeekLst() ) ); 140 connect( a, SIGNAL( activated() ), this, SLOT( viewWeekLst() ) );
135 a->addTo( sub_bar ); 141 a->addTo( sub_bar );
136// a->addTo( view ); 142// a->addTo( view );
137 a->setToggleAction( TRUE ); 143 a->setToggleAction( TRUE );
138 weekLstAction = a; 144 weekLstAction = a;
139 145
140 a = new QAction( tr( "Month" ), Resource::loadPixmap( "month" ), QString::null, 0, g, 0 ); 146 a = new QAction( tr( "Month" ), Resource::loadPixmap( "month" ), QString::null, 0, g, 0 );
141 connect( a, SIGNAL( activated() ), this, SLOT( viewMonth() ) ); 147 connect( a, SIGNAL( activated() ), this, SLOT( viewMonth() ) );
142 a->addTo( sub_bar ); 148 a->addTo( sub_bar );
143// a->addTo( view ); 149// a->addTo( view );
144 a->setToggleAction( TRUE ); 150 a->setToggleAction( TRUE );
145 monthAction = a; 151 monthAction = a;
146 152
147 sub_bar->addSeparator(); 153 sub_bar->addSeparator();
148 154
149 a = new QAction( tr( "Find" ), Resource::loadPixmap( "mag" ), QString::null, 0, this, 0 ); 155 a = new QAction( tr( "Find" ), Resource::loadPixmap( "mag" ), QString::null, 0, this, 0 );
150 connect( a, SIGNAL(activated()), this, SLOT(slotFind()) ); 156 connect( a, SIGNAL(activated()), this, SLOT(slotFind()) );
151 a->addTo( sub_bar ); 157 a->addTo( sub_bar );
152 158
153 a = new QAction( tr( "Edit..." ), Resource::loadPixmap("SettingsIcon"), QString::null, 0, this, 0 ); 159 a = new QAction( tr( "Edit..." ), Resource::loadPixmap("SettingsIcon"), QString::null, 0, this, 0 );
154 connect( a, SIGNAL( activated() ), this, SLOT( slotSettings() ) ); 160 connect( a, SIGNAL( activated() ), this, SLOT( slotSettings() ) );
155 a->addTo( sub_bar ); 161 a->addTo( sub_bar );
156 162
157 if(defaultView==DAY) viewDay(); 163 if(defaultView==DAY) viewDay();
158 if(defaultView==WEEK) needEvilHack=true;// viewWeek(); 164 if(defaultView==WEEK) needEvilHack=true; // viewWeek();
159 if(defaultView==WEEKLST) viewWeekLst(); 165 if(defaultView==WEEKLST) viewWeekLst();
160 if(defaultView==MONTH) viewMonth(); 166 if(defaultView==MONTH) viewMonth();
161 167
162 connect( qApp, SIGNAL(clockChanged(bool)), this, SLOT(changeClock(bool)) ); 168 connect( qApp, SIGNAL(clockChanged(bool)), this, SLOT(changeClock(bool)) );
163 connect( qApp, SIGNAL(weekChanged(bool)), this, SLOT(changeWeek(bool)) ); 169 connect( qApp, SIGNAL(weekChanged(bool)), this, SLOT(changeWeek(bool)) );
164 170
165#if defined(Q_WS_QWS) && !defined(QT_NO_COP) 171#if defined(Q_WS_QWS) && !defined(QT_NO_COP)
166 connect( qApp, SIGNAL(appMessage(const QCString&,const QByteArray&)), this, SLOT(appMessage(const QCString&,const QByteArray&)) ); 172 connect( qApp, SIGNAL(appMessage(const QCString&,const QByteArray&)), this, SLOT(appMessage(const QCString&,const QByteArray&)) );
167#endif 173#endif
168 174
@@ -170,12 +176,12 @@ DateBook::DateBook( QWidget *parent, const char *, WFlags f )
170#if defined(Q_WS_QWS) 176#if defined(Q_WS_QWS)
171#if !defined(QT_NO_COP) 177#if !defined(QT_NO_COP)
172 QCopChannel *channel = new QCopChannel( "QPE/System", this ); 178 QCopChannel *channel = new QCopChannel( "QPE/System", this );
173 connect( channel, SIGNAL(received(const QCString&,const QByteArray&)), this, SLOT(receive(const QCString&,const QByteArray&)) ); 179 connect( channel, SIGNAL(received(const QCString&,const QByteArray&)), this, SLOT(receive(const QCString&,const QByteArray&)) );
174 channel = new QCopChannel( "QPE/Datebook", this ); 180 channel = new QCopChannel( "QPE/Datebook", this );
175 connect( channel, SIGNAL(received(const QCString&,const QByteArray&)), this, SLOT(receive(const QCString&,const QByteArray&)) ); 181 connect( channel, SIGNAL(received(const QCString&,const QByteArray&)), this, SLOT(receive(const QCString&,const QByteArray&)) );
176#endif 182#endif
177#endif 183#endif
178 184
179 odebug << "done t=" << t.elapsed() << oendl; 185 odebug << "done t=" << t.elapsed() << oendl;
180 186
181 connect( qApp, SIGNAL( flush() ), this, SLOT( flush() ) ); 187 connect( qApp, SIGNAL( flush() ), this, SLOT( flush() ) );
@@ -195,7 +201,7 @@ DateBook::DateBook( QWidget *parent, const char *, WFlags f )
195 * from view() 201 * from view()
196 */ 202 */
197 if( needEvilHack ){ 203 if( needEvilHack ){
198 QTimer::singleShot( 500, this, SLOT(viewWeek()) ); 204 QTimer::singleShot( 500, this, SLOT(viewWeek()) );
199 } 205 }
200} 206}
201 207
@@ -204,17 +210,17 @@ void DateBook::receive( const QCString &msg, const QByteArray &data )
204 QDataStream stream( data, IO_ReadOnly ); 210 QDataStream stream( data, IO_ReadOnly );
205 if ( msg == "timeChange(QString)" ) { 211 if ( msg == "timeChange(QString)" ) {
206 // update active view! 212 // update active view!
207 if ( dayAction->isOn() ) 213 if ( dayAction->isOn() )
208 viewDay(); 214 viewDay();
209 else if ( weekAction->isOn() ) 215 else if ( weekAction->isOn() )
210 viewWeek(); 216 viewWeek();
211 else if ( monthAction->isOn() ) 217 else if ( monthAction->isOn() )
212 viewMonth(); 218 viewMonth();
213 } 219 }
214 else if (msg == "editEvent(int)") { 220 else if (msg == "editEvent(int)") {
215 int uid; 221 int uid;
216 stream >> uid; 222 stream >> uid;
217 Event e=db->eventByUID(uid); 223 Event e=db->eventByUID(uid);
218 editEvent(e); 224 editEvent(e);
219 }else if (msg == "viewDefault(QDate)"){ 225 }else if (msg == "viewDefault(QDate)"){
220 QDate day; 226 QDate day;
@@ -226,61 +232,62 @@ void DateBook::receive( const QCString &msg, const QByteArray &data )
226DateBook::~DateBook() 232DateBook::~DateBook()
227{ 233{
234 delete db_holiday;
228} 235}
229 236
230void DateBook::slotSettings() 237void DateBook::slotSettings()
231{ 238{
232 DateBookSettings frmSettings( ampm, this ); 239 DateBookSettings frmSettings( ampm, this );
233 frmSettings.setStartTime( startTime ); 240 frmSettings.setStartTime( startTime );
234 frmSettings.setAlarmPreset( aPreset, presetTime ); 241 frmSettings.setAlarmPreset( aPreset, presetTime );
235 frmSettings.setJumpToCurTime( bJumpToCurTime ); 242 frmSettings.setJumpToCurTime( bJumpToCurTime );
236 frmSettings.setRowStyle( rowStyle ); 243 frmSettings.setRowStyle( rowStyle );
237 frmSettings.comboDefaultView->setCurrentItem(defaultView-1); 244 frmSettings.comboDefaultView->setCurrentItem(defaultView-1);
238 frmSettings.comboWeekListView->setCurrentItem(weeklistviewconfig); 245 frmSettings.comboWeekListView->setCurrentItem(weeklistviewconfig);
239 246
240 bool found=false; 247 bool found=false;
241 for (int i=0; i<(frmSettings.comboLocation->count()); i++) { 248 for (int i=0; i<(frmSettings.comboLocation->count()); i++) {
242 if ( frmSettings.comboLocation->text(i) == defaultLocation ) { 249 if ( frmSettings.comboLocation->text(i) == defaultLocation ) {
243 frmSettings.comboLocation->setCurrentItem(i); 250 frmSettings.comboLocation->setCurrentItem(i);
244 found=true; 251 found=true;
245 break; 252 break;
246 } 253 }
247 } 254 }
248 if(!found) { 255 if(!found) {
249 frmSettings.comboLocation->insertItem(defaultLocation); 256 frmSettings.comboLocation->insertItem(defaultLocation);
250 frmSettings.comboLocation->setCurrentItem(frmSettings.comboLocation->count()-1); 257 frmSettings.comboLocation->setCurrentItem(frmSettings.comboLocation->count()-1);
251 } 258 }
252 frmSettings.comboCategory->setCategories(defaultCategories,"Calendar", tr("Calendar")); 259 frmSettings.comboCategory->setCategories(defaultCategories,"Calendar", tr("Calendar"));
253 260
254 if ( QPEApplication::execDialog( &frmSettings ) ) { 261 if ( QPEApplication::execDialog( &frmSettings ) ) {
255 aPreset = frmSettings.alarmPreset(); 262 aPreset = frmSettings.alarmPreset();
256 presetTime = frmSettings.presetTime(); 263 presetTime = frmSettings.presetTime();
257 startTime = frmSettings.startTime(); 264 startTime = frmSettings.startTime();
258 bJumpToCurTime = frmSettings.jumpToCurTime(); 265 bJumpToCurTime = frmSettings.jumpToCurTime();
259 rowStyle = frmSettings.rowStyle(); 266 rowStyle = frmSettings.rowStyle();
260 defaultView=frmSettings.comboDefaultView->currentItem()+1; 267 defaultView=frmSettings.comboDefaultView->currentItem()+1;
261 weeklistviewconfig=frmSettings.comboWeekListView->currentItem(); 268 weeklistviewconfig=frmSettings.comboWeekListView->currentItem();
262 defaultLocation=frmSettings.comboLocation->currentText(); 269 defaultLocation=frmSettings.comboLocation->currentText();
263 defaultCategories=frmSettings.comboCategory->currentCategories(); 270 defaultCategories=frmSettings.comboCategory->currentCategories();
264 271
265 if ( dayView ) { 272 if ( dayView ) {
266 dayView->setStartViewTime( startTime ); 273 dayView->setStartViewTime( startTime );
267 dayView->setJumpToCurTime( bJumpToCurTime ); 274 dayView->setJumpToCurTime( bJumpToCurTime );
268 dayView->setRowStyle( rowStyle ); 275 dayView->setRowStyle( rowStyle );
269 } 276 }
270 if ( weekView ) { 277 if ( weekView ) {
271 weekView->setStartViewTime( startTime ); 278 weekView->setStartViewTime( startTime );
272 } 279 }
273 saveSettings(); 280 saveSettings();
274 281
275 // make the change obvious 282 // make the change obvious
276 if ( views->visibleWidget() ) { 283 if ( views->visibleWidget() ) {
277 if ( views->visibleWidget() == dayView ) 284 if ( views->visibleWidget() == dayView )
278 dayView->redraw(); 285 dayView->redraw();
279 else if ( views->visibleWidget() == weekView ) 286 else if ( views->visibleWidget() == weekView )
280 weekView->redraw(); 287 weekView->redraw();
281 else if ( views->visibleWidget() == weekLstView ) 288 else if ( views->visibleWidget() == weekLstView )
282 weekLstView->redraw(); 289 weekLstView->redraw();
283 } 290 }
284 } 291 }
285} 292}
286 293
@@ -300,18 +307,18 @@ QString DateBook::checkEvent(const Event &e)
300 for(int i = 0; i < 12; i++) 307 for(int i = 0; i < 12; i++)
301 { 308 {
302 QDateTime next; 309 QDateTime next;
303 if (!nextOccurance(previous, current_date.addDays(1), next)) { 310 if (!nextOccurance(previous, current_date.addDays(1), next)) {
304 break; // no more repeats 311 break; // no more repeats
305 } 312 }
306 if(next < previous.end()) { 313 if(next < previous.end()) {
307 checkFailed = TRUE; 314 checkFailed = TRUE;
308 break; 315 break;
309 } 316 }
310 current_date = next.date(); 317 current_date = next.date();
311 } 318 }
312 319
313 if(checkFailed) 320 if(checkFailed)
314 return tr("Event duration is potentially longer\n" 321 return tr("Event duration is potentially longer\n"
315 "than interval between repeats."); 322 "than interval between repeats.");
316 323
317 return QString::null; 324 return QString::null;
@@ -323,5 +330,5 @@ QDate DateBook::currentDate()
323 330
324 if ( dayView && views->visibleWidget() == dayView ) { 331 if ( dayView && views->visibleWidget() == dayView ) {
325 d = dayView->date(); 332 d = dayView->date();
326 } else if ( weekView && views->visibleWidget() == weekView ) { 333 } else if ( weekView && views->visibleWidget() == weekView ) {
327 d = weekView->date(); 334 d = weekView->date();
@@ -329,5 +336,5 @@ QDate DateBook::currentDate()
329 d = weekLstView->date(); 336 d = weekLstView->date();
330 } else if ( monthView && views->visibleWidget() == monthView ) { 337 } else if ( monthView && views->visibleWidget() == monthView ) {
331 d = monthView->selectedDate(); 338 d = monthView->selectedDate();
332 } 339 }
333 340
@@ -336,60 +343,60 @@ QDate DateBook::currentDate()
336 343
337void DateBook::view(int v, const QDate &d) { 344void DateBook::view(int v, const QDate &d) {
338 if (v==DAY) { 345 if (v==DAY) {
339 initDay(); 346 initDay();
340 dayAction->setOn( TRUE ); 347 dayAction->setOn( TRUE );
341 dayView->setDate( d ); 348 dayView->setDate( d );
342 views->raiseWidget( dayView ); 349 views->raiseWidget( dayView );
343 dayView->redraw(); 350 dayView->redraw();
344 } else if (v==WEEK) { 351 } else if (v==WEEK) {
345 initWeek(); 352 initWeek();
346 weekAction->setOn( TRUE ); 353 weekAction->setOn( TRUE );
347 weekView->setDate( d ); 354 weekView->setDate( d );
348 views->raiseWidget( weekView ); 355 views->raiseWidget( weekView );
349 weekView->redraw(); 356 weekView->redraw();
350 } else if (v==WEEKLST) { 357 } else if (v==WEEKLST) {
351 initWeekLst(); 358 initWeekLst();
352 weekLstAction->setOn( TRUE ); 359 weekLstAction->setOn( TRUE );
353 weekLstView->setDate(d); 360 weekLstView->setDate(d);
354 views->raiseWidget( weekLstView ); 361 views->raiseWidget( weekLstView );
355 weekLstView->redraw(); 362 weekLstView->redraw();
356 } else if (v==MONTH) { 363 } else if (v==MONTH) {
357 initMonth(); 364 initMonth();
358 monthAction->setOn( TRUE ); 365 monthAction->setOn( TRUE );
359 monthView->setDate( d.year(), d.month(), d.day() ); 366 monthView->setDate( d.year(), d.month(), d.day() );
360 views->raiseWidget( monthView ); 367 views->raiseWidget( monthView );
361 monthView->redraw(); 368 monthView->redraw();
362 } 369 }
363} 370}
364 371
365void DateBook::viewDefault(const QDate &d) { 372void DateBook::viewDefault(const QDate &d) {
366 view(defaultView,d); 373 view(defaultView,d);
367} 374}
368 375
369void DateBook::viewDay() { 376void DateBook::viewDay() {
370 view(DAY,currentDate()); 377 view(DAY,currentDate());
371} 378}
372 379
373void DateBook::viewWeek() { 380void DateBook::viewWeek() {
374 view(WEEK,currentDate()); 381 view(WEEK,currentDate());
375} 382}
376 383
377void DateBook::viewWeekLst() { 384void DateBook::viewWeekLst() {
378 view(WEEKLST,currentDate()); 385 view(WEEKLST,currentDate());
379} 386}
380 387
381void DateBook::viewMonth() { 388void DateBook::viewMonth() {
382 view(MONTH,currentDate()); 389 view(MONTH,currentDate());
383} 390}
384 391
385void DateBook::insertEvent( const Event &e ) 392void DateBook::insertEvent( const Event &e )
386{ 393{
387 Event dupEvent=e; 394 Event dupEvent=e;
388 if(!dupEvent.isValidUid() ) // tkcRom seems to be different 395 if(!dupEvent.isValidUid() ) // tkcRom seems to be different
389 dupEvent.assignUid(); 396 dupEvent.assignUid();
390 dupEvent.setLocation(defaultLocation); 397 dupEvent.setLocation(defaultLocation);
391 dupEvent.setCategories(defaultCategories); 398 dupEvent.setCategories(defaultCategories);
392 db->addEvent(dupEvent); 399 db->addEvent(dupEvent);
393 emit newEvent(); 400 emit newEvent();
394} 401}
395 402
@@ -397,32 +404,32 @@ void DateBook::duplicateEvent( const Event &e )
397{ 404{
398 // Alot of code duplication, as this is almost like editEvent(); 405 // Alot of code duplication, as this is almost like editEvent();
399 if (syncing) { 406 if (syncing) {
400 QMessageBox::warning( this, tr("Calendar"), tr( "Can not edit data, currently syncing") ); 407 QMessageBox::warning( this, tr("Calendar"), tr( "Can not edit data, currently syncing") );
401 return; 408 return;
402 } 409 }
403 410
404 Event dupevent(e);// Make a duplicate. 411 Event dupevent(e); // Make a duplicate.
405 412
406 // workaround added for text input. 413 // workaround added for text input.
407 QDialog editDlg( this, 0, TRUE ); 414 QDialog editDlg( this, 0, TRUE );
408 DateEntry *entry; 415 DateEntry *entry;
409 editDlg.setCaption( tr("Duplicate Event") ); 416 editDlg.setCaption( tr("Duplicate Event") );
410 QVBoxLayout *vb = new QVBoxLayout( &editDlg ); 417 QVBoxLayout *vb = new QVBoxLayout( &editDlg );
411 QScrollView *sv = new QScrollView( &editDlg, "scrollview" ); 418 QScrollView *sv = new QScrollView( &editDlg, "scrollview" );
412 sv->setResizePolicy( QScrollView::AutoOneFit ); 419 sv->setResizePolicy( QScrollView::AutoOneFit );
413 // KLUDGE!!! 420 // KLUDGE!!!
414 sv->setHScrollBarMode( QScrollView::AlwaysOff ); 421 sv->setHScrollBarMode( QScrollView::AlwaysOff );
415 vb->addWidget( sv ); 422 vb->addWidget( sv );
416 entry = new DateEntry( onMonday, dupevent, ampm, &editDlg, "editor" ); 423 entry = new DateEntry( onMonday, dupevent, ampm, &editDlg, "editor" );
417 entry->timezone->setEnabled( FALSE ); 424 entry->timezone->setEnabled( FALSE );
418 sv->addChild( entry ); 425 sv->addChild( entry );
419 426
420 while ( QPEApplication::execDialog( &editDlg ) ) { 427 while ( QPEApplication::execDialog( &editDlg ) ) {
421 Event newEv = entry->event(); 428 Event newEv = entry->event();
422 QString error = checkEvent(newEv); 429 QString error = checkEvent(newEv);
423 if (!error.isNull()) { 430 if (!error.isNull()) {
424 if (QMessageBox::warning(this, tr("error box"), error, tr("Fix it"), tr("Continue"), 0, 0, 1) == 0) 431 if (QMessageBox::warning(this, tr("error box"), error, tr("Fix it"), tr("Continue"), 0, 0, 1) == 0)
425 continue; 432 continue;
426 } 433 }
427 /* 434 /*
428 * The problem: 435 * The problem:
@@ -434,60 +441,60 @@ void DateBook::duplicateEvent( const Event &e )
434 rp.createTime = ::time( NULL ); 441 rp.createTime = ::time( NULL );
435 newEv.setRepeat( TRUE, rp ); // has repeat and repeatPattern... 442 newEv.setRepeat( TRUE, rp ); // has repeat and repeatPattern...
436 if( newEv.uid() == e.uid() || !newEv.isValidUid() ) 443 if( newEv.uid() == e.uid() || !newEv.isValidUid() )
437 newEv.assignUid(); 444 newEv.assignUid();
438 445
439 db->addEvent(newEv); 446 db->addEvent(newEv);
440 emit newEvent(); 447 emit newEvent();
441 break; 448 break;
442 } 449 }
443} 450}
444 451
445void DateBook::editEvent( const Event &e ) 452void DateBook::editEvent( const Event &e )
446{ 453{
447 if (syncing) { 454 if (syncing) {
448 QMessageBox::warning( this, tr("Calendar"), tr( "Can not edit data, currently syncing") ); 455 QMessageBox::warning( this, tr("Calendar"), tr( "Can not edit data, currently syncing") );
449 return; 456 return;
450 } 457 }
451 458
452 // workaround added for text input. 459 // workaround added for text input.
453 QDialog editDlg( this, 0, TRUE ); 460 QDialog editDlg( this, 0, TRUE );
454 DateEntry *entry; 461 DateEntry *entry;
455 editDlg.setCaption( tr("Edit Event") ); 462 editDlg.setCaption( tr("Edit Event") );
456 QVBoxLayout *vb = new QVBoxLayout( &editDlg ); 463 QVBoxLayout *vb = new QVBoxLayout( &editDlg );
457 QScrollView *sv = new QScrollView( &editDlg, "scrollview" ); 464 QScrollView *sv = new QScrollView( &editDlg, "scrollview" );
458 sv->setResizePolicy( QScrollView::AutoOneFit ); 465 sv->setResizePolicy( QScrollView::AutoOneFit );
459 // KLUDGE!!! 466 // KLUDGE!!!
460 sv->setHScrollBarMode( QScrollView::AlwaysOff ); 467 sv->setHScrollBarMode( QScrollView::AlwaysOff );
461 vb->addWidget( sv ); 468 vb->addWidget( sv );
462 entry = new DateEntry( onMonday, e, ampm, &editDlg, "editor" ); 469 entry = new DateEntry( onMonday, e, ampm, &editDlg, "editor" );
463 entry->timezone->setEnabled( FALSE ); 470 entry->timezone->setEnabled( FALSE );
464 sv->addChild( entry ); 471 sv->addChild( entry );
465 472
466 while ( QPEApplication::execDialog( &editDlg ) ) { 473 while ( QPEApplication::execDialog( &editDlg ) ) {
467 Event newEv = entry->event(); 474 Event newEv = entry->event();
468 if(newEv.description().isEmpty() && newEv.notes().isEmpty() ) 475 if(newEv.description().isEmpty() && newEv.notes().isEmpty() )
469 break; 476 break;
470 newEv.setUid(e.uid()); // FIXME: Hack not to clear uid 477 newEv.setUid(e.uid()); // FIXME: Hack not to clear uid
471 QString error = checkEvent(newEv); 478 QString error = checkEvent(newEv);
472 if (!error.isNull()) { 479 if (!error.isNull()) {
473 if (QMessageBox::warning(this, tr("error box"), error, tr("Fix it"), tr("Continue"), 0, 0, 1) == 0) continue; 480 if (QMessageBox::warning(this, tr("error box"), error, tr("Fix it"), tr("Continue"), 0, 0, 1) == 0) continue;
474 } 481 }
475 db->editEvent(e, newEv); 482 db->editEvent(e, newEv);
476 emit newEvent(); 483 emit newEvent();
477 break; 484 break;
478 } 485 }
479} 486}
480 487
481void DateBook::removeEvent( const Event &e ) 488void DateBook::removeEvent( const Event &e )
482{ 489{
483 if (syncing) { 490 if (syncing) {
484 QMessageBox::warning( this, tr("Calendar"), tr( "Can not edit data, currently syncing") ); 491 QMessageBox::warning( this, tr("Calendar"), tr( "Can not edit data, currently syncing") );
485 return; 492 return;
486 } 493 }
487 494
488 QString strName = e.description(); 495 QString strName = e.description();
489 496
490 if ( !QPEMessageBox::confirmDelete( this, tr( "Calendar" ),strName ) ) 497 if ( !QPEMessageBox::confirmDelete( this, tr( "Calendar" ),strName ) )
491 return; 498 return;
492 499
493 db->removeEvent( e ); 500 db->removeEvent( e );
@@ -512,60 +519,60 @@ void DateBook::showDay( int year, int month, int day )
512void DateBook::initDay() 519void DateBook::initDay()
513{ 520{
514 if ( !dayView ) { 521 if ( !dayView ) {
515 dayView = new DateBookDay( ampm, onMonday, db, views, "day view" ); 522 dayView = new DateBookDay( ampm, onMonday, db, db_holiday, views, "day view" );
516 views->addWidget( dayView, DAY ); 523 views->addWidget( dayView, DAY );
517 dayView->setJumpToCurTime( bJumpToCurTime ); 524 dayView->setJumpToCurTime( bJumpToCurTime );
518 dayView->setStartViewTime( startTime ); 525 dayView->setStartViewTime( startTime );
519 dayView->setRowStyle( rowStyle ); 526 dayView->setRowStyle( rowStyle );
520 connect( this, SIGNAL( newEvent() ), dayView, SLOT( redraw() ) ); 527 connect( this, SIGNAL( newEvent() ), dayView, SLOT( redraw() ) );
521 connect( dayView, SIGNAL( newEvent() ), this, SLOT( fileNew() ) ); 528 connect( dayView, SIGNAL( newEvent() ), this, SLOT( fileNew() ) );
522 connect( dayView, SIGNAL( removeEvent(const Event&) ), this, SLOT( removeEvent(const Event&) ) ); 529 connect( dayView, SIGNAL( removeEvent(const Event&) ), this, SLOT( removeEvent(const Event&) ) );
523 connect( dayView, SIGNAL( editEvent(const Event&) ), this, SLOT( editEvent(const Event&) ) ); 530 connect( dayView, SIGNAL( editEvent(const Event&) ), this, SLOT( editEvent(const Event&) ) );
524 connect( dayView, SIGNAL( duplicateEvent(const Event&) ), this, SLOT( duplicateEvent(const Event&) ) ); 531 connect( dayView, SIGNAL( duplicateEvent(const Event&) ), this, SLOT( duplicateEvent(const Event&) ) );
525 connect( dayView, SIGNAL( beamEvent(const Event&) ), this, SLOT( beamEvent(const Event&) ) ); 532 connect( dayView, SIGNAL( beamEvent(const Event&) ), this, SLOT( beamEvent(const Event&) ) );
526 connect( dayView, SIGNAL(sigNewEvent(const QString&)), this, SLOT(slotNewEventFromKey(const QString&)) ); 533 connect( dayView, SIGNAL(sigNewEvent(const QString&)), this, SLOT(slotNewEventFromKey(const QString&)) );
527 } 534 }
528} 535}
529 536
530void DateBook::initWeek() 537void DateBook::initWeek()
531{ 538{
532 if ( !weekView ) { 539 if ( !weekView ) {
533 weekView = new DateBookWeek( ampm, onMonday, db, views, "week view" ); 540 weekView = new DateBookWeek( ampm, onMonday, db, views, "week view" );
534 weekView->setStartViewTime( startTime ); 541 weekView->setStartViewTime( startTime );
535 views->addWidget( weekView, WEEK ); 542 views->addWidget( weekView, WEEK );
536 connect( weekView, SIGNAL( showDate(int,int,int) ), this, SLOT( showDay(int,int,int) ) ); 543 connect( weekView, SIGNAL( showDate(int,int,int) ), this, SLOT( showDay(int,int,int) ) );
537 connect( this, SIGNAL( newEvent() ), weekView, SLOT( redraw() ) ); 544 connect( this, SIGNAL( newEvent() ), weekView, SLOT( redraw() ) );
538 } 545 }
539 546
540 //But also get it right: the year that we display can be different 547 //But also get it right: the year that we display can be different
541 //from the year of the current date. So, first find the year 548 //from the year of the current date. So, first find the year
542 //number of the current week. 549 //number of the current week.
543 int yearNumber, totWeeks; 550 int yearNumber, totWeeks;
544 calcWeek( currentDate(), totWeeks, yearNumber, onMonday ); 551 calcWeek( currentDate(), totWeeks, yearNumber, onMonday );
545 552
546 QDate d = QDate( yearNumber, 12, 31 ); 553 QDate d = QDate( yearNumber, 12, 31 );
547 calcWeek( d, totWeeks, yearNumber, onMonday ); 554 calcWeek( d, totWeeks, yearNumber, onMonday );
548 555
549 while ( totWeeks == 1 ) { 556 while ( totWeeks == 1 ) {
550 d = d.addDays( -1 ); 557 d = d.addDays( -1 );
551 calcWeek( d, totWeeks, yearNumber, onMonday ); 558 calcWeek( d, totWeeks, yearNumber, onMonday );
552 } 559 }
553} 560}
554 561
555void DateBook::initWeekLst() { 562void DateBook::initWeekLst() {
556 if ( !weekLstView ) { 563 if ( !weekLstView ) {
557 weekLstView = new DateBookWeekLst( ampm, onMonday, db, views, "weeklst view" ); 564 weekLstView = new DateBookWeekLst( ampm, onMonday, db, views, "weeklst view" );
558 views->addWidget( weekLstView, WEEKLST ); 565 views->addWidget( weekLstView, WEEKLST );
559 566
560 //weekLstView->setStartViewTime( startTime ); 567 //weekLstView->setStartViewTime( startTime );
561 connect( weekLstView, SIGNAL( showDate(int,int,int) ), this, SLOT( showDay(int,int,int) ) ); 568 connect( weekLstView, SIGNAL( showDate(int,int,int) ), this, SLOT( showDay(int,int,int) ) );
562 connect( weekLstView, SIGNAL( addEvent(const QDateTime&,const QDateTime&,const QString&, const QString&) ), 569 connect( weekLstView, SIGNAL( addEvent(const QDateTime&,const QDateTime&,const QString&, const QString&) ),
563 this, SLOT( slotNewEntry(const QDateTime&,const QDateTime&,const QString&, const QString&) ) ); 570 this, SLOT( slotNewEntry(const QDateTime&,const QDateTime&,const QString&, const QString&) ) );
564 connect( this, SIGNAL( newEvent() ), weekLstView, SLOT( redraw() ) ); 571 connect( this, SIGNAL( newEvent() ), weekLstView, SLOT( redraw() ) );
565 connect( weekLstView, SIGNAL( editEvent(const Event&) ), this, SLOT( editEvent(const Event&) ) ); 572 connect( weekLstView, SIGNAL( editEvent(const Event&) ), this, SLOT( editEvent(const Event&) ) );
566 connect( weekLstView, SIGNAL( duplicateEvent( const Event & ) ), this, SLOT( duplicateEvent( const Event & ) ) ); 573 connect( weekLstView, SIGNAL( duplicateEvent( const Event & ) ), this, SLOT( duplicateEvent( const Event & ) ) );
567 connect( weekLstView, SIGNAL( beamEvent(const Event&) ), this, SLOT( beamEvent(const Event&) ) ); 574 connect( weekLstView, SIGNAL( beamEvent(const Event&) ), this, SLOT( beamEvent(const Event&) ) );
568 connect( weekLstView, SIGNAL( removeEvent( const Event & ) ), this, SLOT( removeEvent( const Event & ) ) ); 575 connect( weekLstView, SIGNAL( removeEvent( const Event & ) ), this, SLOT( removeEvent( const Event & ) ) );
569 } 576 }
570} 577}
571 578
@@ -573,148 +580,148 @@ void DateBook::initWeekLst() {
573void DateBook::initMonth() 580void DateBook::initMonth()
574{ 581{
575 if ( !monthView ) { 582 if ( !monthView ) {
576 monthView = new DateBookMonth( views, "month view", FALSE, db ); 583 monthView = new DateBookMonth( views, "month view", FALSE, db );
577 views->addWidget( monthView, MONTH ); 584 views->addWidget( monthView, MONTH );
578 connect( monthView, SIGNAL( dateClicked(int,int,int) ), this, SLOT( showDay(int,int,int) ) ); 585 connect( monthView, SIGNAL( dateClicked(int,int,int) ), this, SLOT( showDay(int,int,int) ) );
579 connect( this, SIGNAL( newEvent() ), monthView, SLOT( redraw() ) ); 586 connect( this, SIGNAL( newEvent() ), monthView, SLOT( redraw() ) );
580 qApp->processEvents(); 587 qApp->processEvents();
581 } 588 }
582} 589}
583 590
584void DateBook::loadSettings() 591void DateBook::loadSettings()
585{ 592{
586 Config qpeconfig( "qpe" ); 593 Config qpeconfig( "qpe" );
587 qpeconfig.setGroup("Time"); 594 qpeconfig.setGroup("Time");
588 ampm = qpeconfig.readBoolEntry( "AMPM", TRUE ); 595 ampm = qpeconfig.readBoolEntry( "AMPM", TRUE );
589 onMonday = qpeconfig.readBoolEntry( "MONDAY" ); 596 onMonday = qpeconfig.readBoolEntry( "MONDAY" );
590 597
591 Config config("DateBook"); 598 Config config("DateBook");
592 config.setGroup("Main"); 599 config.setGroup("Main");
593 startTime = config.readNumEntry("startviewtime", 8); 600 startTime = config.readNumEntry("startviewtime", 8);
594 aPreset = config.readBoolEntry("alarmpreset"); 601 aPreset = config.readBoolEntry("alarmpreset");
595 presetTime = config.readNumEntry("presettime"); 602 presetTime = config.readNumEntry("presettime");
596 bJumpToCurTime = config.readBoolEntry("jumptocurtime"); 603 bJumpToCurTime = config.readBoolEntry("jumptocurtime");
597 rowStyle = config.readNumEntry("rowstyle"); 604 rowStyle = config.readNumEntry("rowstyle");
598 defaultView = config.readNumEntry("defaultview",DAY); 605 defaultView = config.readNumEntry("defaultview",DAY);
599 weeklistviewconfig = config.readNumEntry("weeklistviewconfig",NORMAL); 606 weeklistviewconfig = config.readNumEntry("weeklistviewconfig",NORMAL);
600 607
601 defaultLocation=config.readEntry("defaultLocation"); 608 defaultLocation=config.readEntry("defaultLocation");
602 QString tmpString=config.readEntry("defaultCategories"); 609 QString tmpString=config.readEntry("defaultCategories");
603 QStringList tmpStringList=QStringList::split(",",tmpString); 610 QStringList tmpStringList=QStringList::split(",",tmpString);
604 defaultCategories.truncate(0); 611 defaultCategories.truncate(0);
605 612
606 for( QStringList::Iterator i=tmpStringList.begin(); i!=tmpStringList.end(); i++) { 613 for( QStringList::Iterator i=tmpStringList.begin(); i!=tmpStringList.end(); i++) {
607 defaultCategories.resize(defaultCategories.count()+1); 614 defaultCategories.resize(defaultCategories.count()+1);
608 defaultCategories[defaultCategories.count()-1]=(*i).toInt(); 615 defaultCategories[defaultCategories.count()-1]=(*i).toInt();
609 } 616 }
610} 617}
611 618
612void DateBook::saveSettings() 619void DateBook::saveSettings()
613{ 620{
614 Config config( "qpe" ); 621 Config config( "qpe" );
615 Config configDB( "DateBook" ); 622 Config configDB( "DateBook" );
616 configDB.setGroup( "Main" ); 623 configDB.setGroup( "Main" );
617 configDB.writeEntry("startviewtime",startTime); 624 configDB.writeEntry("startviewtime",startTime);
618 configDB.writeEntry("alarmpreset",aPreset); 625 configDB.writeEntry("alarmpreset",aPreset);
619 configDB.writeEntry("presettime",presetTime); 626 configDB.writeEntry("presettime",presetTime);
620 configDB.writeEntry("jumptocurtime", bJumpToCurTime); 627 configDB.writeEntry("jumptocurtime", bJumpToCurTime);
621 configDB.writeEntry("rowstyle", rowStyle); 628 configDB.writeEntry("rowstyle", rowStyle);
622 configDB.writeEntry("defaultview",defaultView); 629 configDB.writeEntry("defaultview",defaultView);
623 configDB.writeEntry("weeklistviewconfig",weeklistviewconfig); 630 configDB.writeEntry("weeklistviewconfig",weeklistviewconfig);
624 631
625 configDB.writeEntry("defaultLocation",defaultLocation); 632 configDB.writeEntry("defaultLocation",defaultLocation);
626 QStringList tmpStringList; 633 QStringList tmpStringList;
627 for( uint i=0; i<defaultCategories.count(); i++) { 634 for( uint i=0; i<defaultCategories.count(); i++) {
628 tmpStringList << QString::number(defaultCategories[i]); 635 tmpStringList << QString::number(defaultCategories[i]);
629 } 636 }
630 configDB.writeEntry("defaultCategories",tmpStringList.join(",")); 637 configDB.writeEntry("defaultCategories",tmpStringList.join(","));
631} 638}
632 639
633void DateBook::appMessage(const QCString& msg, const QByteArray& data) 640void DateBook::appMessage(const QCString& msg, const QByteArray& data)
634{ 641{
635 bool needShow = FALSE; 642 bool needShow = FALSE;
636 if ( msg == "alarm(QDateTime,int)" ) { 643 if ( msg == "alarm(QDateTime,int)" ) {
637 QDataStream ds(data,IO_ReadOnly); 644 QDataStream ds(data,IO_ReadOnly);
638 QDateTime when; int warn; 645 QDateTime when; int warn;
639 ds >> when >> warn; 646 ds >> when >> warn;
640 647
641 // check to make it's okay to continue, 648 // check to make it's okay to continue,
642 // this is the case that the time was set ahead, and 649 // this is the case that the time was set ahead, and
643 // we are forced given a stale alarm... 650 // we are forced given a stale alarm...
644 QDateTime current = QDateTime::currentDateTime(); 651 QDateTime current = QDateTime::currentDateTime();
645 if ( current.time().hour() != when.time().hour() && current.time().minute() != when.time().minute() ) 652 if ( current.time().hour() != when.time().hour() && current.time().minute() != when.time().minute() )
646 return; 653 return;
647 654
648 QValueList<EffectiveEvent> list = db->getEffectiveEvents(when.addSecs(warn*60)); 655 QValueList<EffectiveEvent> list = db->getEffectiveEvents(when.addSecs(warn*60));
649 if ( list.count() > 0 ) { 656 if ( list.count() > 0 ) {
650 QString msg; 657 QString msg;
651 bool bSound = FALSE; 658 bool bSound = FALSE;
652 int stopTimer = 0; 659 int stopTimer = 0;
653 bool found = FALSE; 660 bool found = FALSE;
654 for ( QValueList<EffectiveEvent>::ConstIterator it=list.begin(); it!=list.end(); ++it ) { 661 for ( QValueList<EffectiveEvent>::ConstIterator it=list.begin(); it!=list.end(); ++it ) {
655 if ( (*it).event().hasAlarm() ) { 662 if ( (*it).event().hasAlarm() ) {
656 found = TRUE; 663 found = TRUE;
657 msg += "<CENTER><B>" + (*it).description() + "</B>" 664 msg += "<CENTER><B>" + (*it).description() + "</B>"
658 + "<BR>" + (*it).location() + "<BR>" 665 + "<BR>" + (*it).location() + "<BR>"
659 + TimeString::dateString((*it).event().start(),ampm) 666 + TimeString::dateString((*it).event().start(),ampm)
660 + (warn 667 + (warn
661 ? tr(" (in " + QString::number(warn) 668 ? tr(" (in " + QString::number(warn)
662 + tr(" minutes)")) 669 + tr(" minutes)"))
663 : QString("")) 670 : QString(""))
664 + "<BR>" 671 + "<BR>"
665 + (*it).notes() + "</CENTER>"; 672 + (*it).notes() + "</CENTER>";
666 if ( (*it).event().alarmSound() != Event::Silent ) { 673 if ( (*it).event().alarmSound() != Event::Silent ) {
667 bSound = TRUE; 674 bSound = TRUE;
668 } 675 }
669 } 676 }
670 } 677 }
671 if ( found ) { 678 if ( found ) {
672 if ( bSound ) { 679 if ( bSound ) {
673 Sound::soundAlarm(); 680 Sound::soundAlarm();
674 alarmCounter = 0; 681 alarmCounter = 0;
675 stopTimer = startTimer( 5000 ); 682 stopTimer = startTimer( 5000 );
676 } 683 }
677 QDialog dlg( this, 0, TRUE ); 684 QDialog dlg( this, 0, TRUE );
678 QVBoxLayout *vb = new QVBoxLayout( &dlg ); 685 QVBoxLayout *vb = new QVBoxLayout( &dlg );
679 QScrollView *view = new QScrollView( &dlg, "scrollView"); 686 QScrollView *view = new QScrollView( &dlg, "scrollView");
680 view->setResizePolicy( QScrollView::AutoOneFit ); 687 view->setResizePolicy( QScrollView::AutoOneFit );
681 vb->addWidget( view ); 688 vb->addWidget( view );
682 QLabel *lblMsg = new QLabel( msg, &dlg ); 689 QLabel *lblMsg = new QLabel( msg, &dlg );
683 view->addChild( lblMsg ); 690 view->addChild( lblMsg );
684 QPushButton *cmdOk = new QPushButton( tr("OK"), &dlg ); 691 QPushButton *cmdOk = new QPushButton( tr("OK"), &dlg );
685 connect( cmdOk, SIGNAL(clicked()), &dlg, SLOT(accept()) ); 692 connect( cmdOk, SIGNAL(clicked()), &dlg, SLOT(accept()) );
686 vb->addWidget( cmdOk ); 693 vb->addWidget( cmdOk );
687 694
688 needShow = QPEApplication::execDialog( &dlg ); 695 needShow = QPEApplication::execDialog( &dlg );
689 696
690 if ( bSound ) 697 if ( bSound )
691 killTimer( stopTimer ); 698 killTimer( stopTimer );
692 } 699 }
693 } 700 }
694 } else if ( msg == "nextView()" ) { 701 } else if ( msg == "nextView()" ) {
695 needShow = true; 702 needShow = true;
696 if ( !qApp-> activeWindow ( )) { 703 if ( !qApp-> activeWindow ( )) {
697 needShow = TRUE; 704 needShow = TRUE;
698 } else { 705 } else {
699 QWidget* cur = views->visibleWidget(); 706 QWidget* cur = views->visibleWidget();
700 if ( cur ) { 707 if ( cur ) {
701 if ( cur == dayView ) 708 if ( cur == dayView )
702 viewWeek(); 709 viewWeek();
703 else if ( cur == weekView ) 710 else if ( cur == weekView )
704 viewWeekLst(); 711 viewWeekLst();
705 else if ( cur == weekLstView ) 712 else if ( cur == weekLstView )
706 viewMonth(); 713 viewMonth();
707 else if ( cur == monthView ) 714 else if ( cur == monthView )
708 viewDay(); 715 viewDay();
709 needShow = TRUE; 716 needShow = TRUE;
710 } 717 }
711 } 718 }
712 } else if (msg == "editEvent(int)") { 719 } else if (msg == "editEvent(int)") {
713 /* simple copy from receive */ 720 /* simple copy from receive */
714 QDataStream stream(data,IO_ReadOnly); 721 QDataStream stream(data,IO_ReadOnly);
715 int uid; 722 int uid;
716 stream >> uid; 723 stream >> uid;
717 Event e=db->eventByUID(uid); 724 Event e=db->eventByUID(uid);
718 editEvent(e); 725 editEvent(e);
719 } else if (msg == "viewDefault(QDate)"){ 726 } else if (msg == "viewDefault(QDate)"){
720 /* simple copy from receive */ 727 /* simple copy from receive */
@@ -728,86 +735,86 @@ void DateBook::appMessage(const QCString& msg, const QByteArray& data)
728 if ( needShow ) { 735 if ( needShow ) {
729#if defined(Q_WS_QWS) || defined(_WS_QWS_) 736#if defined(Q_WS_QWS) || defined(_WS_QWS_)
730 // showMaximized(); 737// showMaximized();
731#else 738#else
732 // show(); 739// show();
733#endif 740#endif
734 // raise(); 741// raise();
735 QPEApplication::setKeepRunning(); 742 QPEApplication::setKeepRunning();
736 // setActiveWindow(); 743// setActiveWindow();
737 } 744 }
738} 745}
739 746
740void DateBook::reload() 747void DateBook::reload()
741{ 748{
742 db->reload(); 749 db->reload();
743 if ( dayAction->isOn() ) viewDay(); 750 if ( dayAction->isOn() ) viewDay();
744 else if ( weekAction->isOn() ) viewWeek(); 751 else if ( weekAction->isOn() ) viewWeek();
745 else if ( monthAction->isOn() ) viewMonth(); 752 else if ( monthAction->isOn() ) viewMonth();
746 syncing = FALSE; 753 syncing = FALSE;
747} 754}
748 755
749void DateBook::flush() 756void DateBook::flush()
750{ 757{
751 syncing = TRUE; 758 syncing = TRUE;
752 db->save(); 759 db->save();
753} 760}
754 761
755void DateBook::timerEvent( QTimerEvent *e ) 762void DateBook::timerEvent( QTimerEvent *e )
756{ 763{
757 if ( alarmCounter < 10 ) { 764 if ( alarmCounter < 10 ) {
758 alarmCounter++; 765 alarmCounter++;
759 Sound::soundAlarm(); 766 Sound::soundAlarm();
760 } else { 767 } else {
761 killTimer( e->timerId() ); 768 killTimer( e->timerId() );
762 } 769 }
763} 770}
764 771
765void DateBook::changeClock( bool newClock ) 772void DateBook::changeClock( bool newClock )
766{ 773{
767 ampm = newClock; 774 ampm = newClock;
768 // repaint the affected objects... 775 // repaint the affected objects...
769 if (dayView) dayView->redraw(); 776 if (dayView) dayView->redraw();
770 if (weekView) weekView->redraw(); 777 if (weekView) weekView->redraw();
771 if (weekLstView) weekLstView->redraw(); 778 if (weekLstView) weekLstView->redraw();
772} 779}
773 780
774void DateBook::changeWeek( bool m ) 781void DateBook::changeWeek( bool m )
775{ 782{
776 /* no need to redraw, each widget catches. Do need to 783 /* no need to redraw, each widget catches. Do need to
777 store though for widgets we haven't made yet */ 784 store though for widgets we haven't made yet */
778 onMonday = m; 785 onMonday = m;
779} 786}
780 787
781void DateBook::slotToday() 788void DateBook::slotToday()
782{ 789{
783 // we need to view today using default view 790 // we need to view today using default view
784 view(defaultView,QDate::currentDate()); 791 view(defaultView,QDate::currentDate());
785} 792}
786 793
787void DateBook::closeEvent( QCloseEvent *e ) 794void DateBook::closeEvent( QCloseEvent *e )
788{ 795{
789 if(syncing) { 796 if(syncing) {
790 /* no need to save, did that at flush */ 797 /* no need to save, did that at flush */
791 e->accept(); 798 e->accept();
792 return; 799 return;
793 } 800 }
794 801
795 // save settings will generate it's own error messages, no 802 // save settings will generate it's own error messages, no
796 // need to do checking ourselves. 803 // need to do checking ourselves.
797 saveSettings(); 804 saveSettings();
798 if ( db->save() ) { 805 if ( db->save() ) {
799 e->accept(); 806 e->accept();
800 } else { 807 } else {
801 if ( QMessageBox::critical( this, tr( "Out of space" ), 808 if ( QMessageBox::critical( this, tr( "Out of space" ),
802 tr("Calendar was unable to save\n" 809 tr("Calendar was unable to save\n"
803 "your changes.\n" 810 "your changes.\n"
804 "Free up some space and try again.\n" 811 "Free up some space and try again.\n"
805 "\nQuit anyway?"), 812 "\nQuit anyway?"),
806 QMessageBox::Yes|QMessageBox::Escape, 813 QMessageBox::Yes|QMessageBox::Escape,
807 QMessageBox::No|QMessageBox::Default ) 814 QMessageBox::No|QMessageBox::Default )
808 != QMessageBox::No ) 815 != QMessageBox::No )
809 e->accept(); 816 e->accept();
810 else 817 else
811 e->ignore(); 818 e->ignore();
812 } 819 }
813} 820}
@@ -817,7 +824,7 @@ void DateBook::slotNewEventFromKey( const QString &str )
817{ 824{
818 if (syncing) { 825 if (syncing) {
819 QMessageBox::warning( this, tr("Calendar"), 826 QMessageBox::warning( this, tr("Calendar"),
820 tr( "Can not edit data, currently syncing") ); 827 tr( "Can not edit data, currently syncing") );
821 return; 828 return;
822 } 829 }
823 830
@@ -827,67 +834,67 @@ void DateBook::slotNewEventFromKey( const QString &str )
827 QDateTime start, end; 834 QDateTime start, end;
828 if ( views->visibleWidget() == dayView ) { 835 if ( views->visibleWidget() == dayView ) {
829 dayView->selectedDates( start, end ); 836 dayView->selectedDates( start, end );
830 } else if ( views->visibleWidget() == monthView ) { 837 } else if ( views->visibleWidget() == monthView ) {
831 QDate d = monthView->selectedDate(); 838 QDate d = monthView->selectedDate();
832 start = end = d; 839 start = end = d;
833 start.setTime( QTime( 10, 0 ) ); 840 start.setTime( QTime( 10, 0 ) );
834 end.setTime( QTime( 12, 0 ) ); 841 end.setTime( QTime( 12, 0 ) );
835 } else if ( views->visibleWidget() == weekView ) { 842 } else if ( views->visibleWidget() == weekView ) {
836 QDate d = weekView->date(); 843 QDate d = weekView->date();
837 start = end = d; 844 start = end = d;
838 start.setTime( QTime( 10, 0 ) ); 845 start.setTime( QTime( 10, 0 ) );
839 end.setTime( QTime( 12, 0 ) ); 846 end.setTime( QTime( 12, 0 ) );
840 } else if ( views->visibleWidget() == weekLstView ) { 847 } else if ( views->visibleWidget() == weekLstView ) {
841 QDate d = weekLstView->date(); 848 QDate d = weekLstView->date();
842 start = end = d; 849 start = end = d;
843 start.setTime( QTime( 10, 0 ) ); 850 start.setTime( QTime( 10, 0 ) );
844 end.setTime( QTime( 12, 0 ) ); 851 end.setTime( QTime( 12, 0 ) );
845 } 852 }
846 slotNewEntry(start, end, str); 853 slotNewEntry(start, end, str);
847} 854}
848void DateBook::slotNewEntry(const QDateTime &start, const QDateTime &end, const QString &str, const QString &location) { 855void DateBook::slotNewEntry(const QDateTime &start, const QDateTime &end, const QString &str, const QString &location) {
849 // argh! This really needs to be encapsulated in a class 856 // argh! This really needs to be encapsulated in a class
850 // or function. 857 // or function.
851 QDialog newDlg( this, 0, TRUE ); 858 QDialog newDlg( this, 0, TRUE );
852 newDlg.setCaption( DateEntryBase::tr("New Event") ); 859 newDlg.setCaption( DateEntryBase::tr("New Event") );
853 DateEntry *e; 860 DateEntry *e;
854 QVBoxLayout *vb = new QVBoxLayout( &newDlg ); 861 QVBoxLayout *vb = new QVBoxLayout( &newDlg );
855 QScrollView *sv = new QScrollView( &newDlg ); 862 QScrollView *sv = new QScrollView( &newDlg );
856 sv->setResizePolicy( QScrollView::AutoOneFit ); 863 sv->setResizePolicy( QScrollView::AutoOneFit );
857 sv->setFrameStyle( QFrame::NoFrame ); 864 sv->setFrameStyle( QFrame::NoFrame );
858 sv->setHScrollBarMode( QScrollView::AlwaysOff ); 865 sv->setHScrollBarMode( QScrollView::AlwaysOff );
859 vb->addWidget( sv ); 866 vb->addWidget( sv );
860 867
861 Event ev; 868 Event ev;
862 ev.setDescription( str ); 869 ev.setDescription( str );
863 // When the new gui comes in, change this... 870 // When the new gui comes in, change this...
864 if(location==0) { 871 if(location==0) {
865 if(defaultLocation.isEmpty()) { 872 if(defaultLocation.isEmpty()) {
866 ev.setLocation(tr("(Unknown)")); 873 ev.setLocation(tr("(Unknown)"));
867 } else { 874 } else {
868 ev.setLocation( defaultLocation ); 875 ev.setLocation( defaultLocation );
869 } 876 }
870 } else { 877 } else {
871 ev.setLocation(location); 878 ev.setLocation(location);
872 } 879 }
873 ev.setCategories(defaultCategories); 880 ev.setCategories(defaultCategories);
874 ev.setStart( start ); 881 ev.setStart( start );
875 ev.setEnd( end ); 882 ev.setEnd( end );
876 883
877 e = new DateEntry( onMonday, ev, ampm, &newDlg ); 884 e = new DateEntry( onMonday, ev, ampm, &newDlg );
878 e->setAlarmEnabled( aPreset, presetTime, Event::Loud ); 885 e->setAlarmEnabled( aPreset, presetTime, Event::Loud );
879 sv->addChild( e ); 886 sv->addChild( e );
880 while ( QPEApplication::execDialog( &newDlg ) ) { 887 while ( QPEApplication::execDialog( &newDlg ) ) {
881 ev = e->event(); 888 ev = e->event();
882 ev.assignUid(); 889 ev.assignUid();
883 QString error = checkEvent( ev ); 890 QString error = checkEvent( ev );
884 if ( !error.isNull() ) { 891 if ( !error.isNull() ) {
885 if ( QMessageBox::warning( this, tr("Error!"), error, tr("Fix it"), tr("Continue"), 0, 0, 1 ) == 0 ) 892 if ( QMessageBox::warning( this, tr("Error!"), error, tr("Fix it"), tr("Continue"), 0, 0, 1 ) == 0 )
886 continue; 893 continue;
887 } 894 }
888 db->addEvent( ev ); 895 db->addEvent( ev );
889 emit newEvent(); 896 emit newEvent();
890 break; 897 break;
891 } 898 }
892} 899}
893 900
@@ -898,5 +905,5 @@ void DateBook::setDocument( const QString &filename )
898 QValueList<Event> tl = Event::readVCalendar( filename ); 905 QValueList<Event> tl = Event::readVCalendar( filename );
899 for( QValueList<Event>::Iterator it = tl.begin(); it != tl.end(); ++it ) { 906 for( QValueList<Event>::Iterator it = tl.begin(); it != tl.end(); ++it ) {
900 db->addEvent( *it ); 907 db->addEvent( *it );
901 } 908 }
902} 909}
@@ -906,5 +913,5 @@ static const char * beamfile = "/tmp/obex/event.vcs";
906void DateBook::beamEvent( const Event &e ) 913void DateBook::beamEvent( const Event &e )
907{ 914{
908 odebug << "trying to beam" << oendl; 915 odebug << "trying to beam" << oendl;
909 unlink( beamfile ); // delete if exists 916 unlink( beamfile ); // delete if exists
910 mkdir("/tmp/obex/", 0755); 917 mkdir("/tmp/obex/", 0755);
@@ -931,15 +938,15 @@ void DateBook::slotFind()
931 QObject::connect( &frmFind, 938 QObject::connect( &frmFind,
932 SIGNAL(signalFindClicked(const QString&,const QDate&,bool,bool,int)), 939 SIGNAL(signalFindClicked(const QString&,const QDate&,bool,bool,int)),
933 this, 940 this,
934 SLOT(slotDoFind(const QString&,const QDate&,bool,bool,int)) ); 941 SLOT(slotDoFind(const QString&,const QDate&,bool,bool,int)) );
935 QObject::connect( this, 942 QObject::connect( this,
936 SIGNAL(signalNotFound()), 943 SIGNAL(signalNotFound()),
937 &frmFind, 944 &frmFind,
938 SLOT(slotNotFound()) ); 945 SLOT(slotNotFound()) );
939 QObject::connect( this, 946 QObject::connect( this,
940 SIGNAL(signalWrapAround()), 947 SIGNAL(signalWrapAround()),
941 &frmFind, 948 &frmFind,
942 SLOT(slotWrapAround()) ); 949 SLOT(slotWrapAround()) );
943 frmFind.move(0,0); 950 frmFind.move(0,0);
944 frmFind.exec(); 951 frmFind.exec();
945 inSearch = false; 952 inSearch = false;
@@ -950,17 +957,17 @@ bool catComp( QArray<int> cats, int category )
950 bool returnMe; 957 bool returnMe;
951 int i, 958 int i,
952 count; 959 count;
953 960
954 count = int(cats.count()); 961 count = int(cats.count());
955 returnMe = false; 962 returnMe = false;
956 if ( (category == -1 && count == 0) || category == -2 ) 963 if ( (category == -1 && count == 0) || category == -2 )
957 returnMe = true; 964 returnMe = true;
958 else { 965 else {
959 for ( i = 0; i < count; i++ ) { 966 for ( i = 0; i < count; i++ ) {
960 if ( category == cats[i] ) { 967 if ( category == cats[i] ) {
961 returnMe = true; 968 returnMe = true;
962 break; 969 break;
963 } 970 }
964 } 971 }
965 } 972 }
966 return returnMe; 973 return returnMe;
@@ -969,9 +976,9 @@ bool catComp( QArray<int> cats, int category )
969 976
970void DateBook::slotDoFind( const QString& txt, const QDate &dt, 977void DateBook::slotDoFind( const QString& txt, const QDate &dt,
971 bool caseSensitive, bool /*backwards*/, 978 bool caseSensitive, bool /*backwards*/,
972 int category ) 979 int category )
973{ 980{
974 QDateTime dtEnd( QDate(3001, 1, 1), QTime(0, 0, 0) ), 981 QDateTime dtEnd( QDate(3001, 1, 1), QTime(0, 0, 0) ),
975 next; 982 next;
976 983
977 QRegExp r( txt ); 984 QRegExp r( txt );
@@ -981,7 +988,7 @@ void DateBook::slotDoFind( const QString& txt, const QDate &dt,
981 static Event rev, nonrev; 988 static Event rev, nonrev;
982 if ( !inSearch ) { 989 if ( !inSearch ) {
983 rev.setStart( QDateTime(QDate(1960, 1, 1), QTime(0, 0, 0)) ); 990 rev.setStart( QDateTime(QDate(1960, 1, 1), QTime(0, 0, 0)) );
984 nonrev.setStart( rev.start() ); 991 nonrev.setStart( rev.start() );
985 inSearch = true; 992 inSearch = true;
986 } 993 }
987 static QDate searchDate = dt; 994 static QDate searchDate = dt;
@@ -1005,5 +1012,5 @@ void DateBook::slotDoFind( const QString& txt, const QDate &dt,
1005 QDate start = dt; 1012 QDate start = dt;
1006 for ( it = repeats.begin(); it != repeats.end(); ++it ) { 1013 for ( it = repeats.begin(); it != repeats.end(); ++it ) {
1007 if ( catComp( (*it).categories(), category ) ) { 1014 if ( catComp( (*it).categories(), category ) ) {
1008 if ( (*it).match( r ) ) { 1015 if ( (*it).match( r ) ) {
1009 if ( nextOccurance( *it, start, next ) ) { 1016 if ( nextOccurance( *it, start, next ) ) {
@@ -1027,28 +1034,28 @@ void DateBook::slotDoFind( const QString& txt, const QDate &dt,
1027 qHeapSort( nonRepeats.begin(), nonRepeats.end() ); 1034 qHeapSort( nonRepeats.begin(), nonRepeats.end() );
1028 for ( it = nonRepeats.begin(); it != nonRepeats.end(); ++it ) { 1035 for ( it = nonRepeats.begin(); it != nonRepeats.end(); ++it ) {
1029 if ( catComp( (*it).categories(), category ) ) { 1036 if ( catComp( (*it).categories(), category ) ) {
1030 if ( (*it).start() < dtEnd ) { 1037 if ( (*it).start() < dtEnd ) {
1031 if ( (*it).match( r ) && !(*it <= nonrev) ) { 1038 if ( (*it).match( r ) && !(*it <= nonrev) ) {
1032 nonrev = *it; 1039 nonrev = *it;
1033 dtEnd = nonrev.start(); 1040 dtEnd = nonrev.start();
1034 candidtate = true; 1041 candidtate = true;
1035 wrapAround = true; 1042 wrapAround = true;
1036 break; 1043 break;
1037 } 1044 }
1038 } 1045 }
1039 } 1046 }
1040 } 1047 }
1041 if ( candidtate ) { 1048 if ( candidtate ) {
1042 dayView->setStartViewTime( dtEnd.time().hour() ); 1049 dayView->setStartViewTime( dtEnd.time().hour() );
1043 dayView->setDate( dtEnd.date().year(), dtEnd.date().month(), 1050 dayView->setDate( dtEnd.date().year(), dtEnd.date().month(),
1044 dtEnd.date().day() ); 1051 dtEnd.date().day() );
1045 } else { 1052 } else {
1046 if ( wrapAround ) { 1053 if ( wrapAround ) {
1047 emit signalWrapAround(); 1054 emit signalWrapAround();
1048 rev.setStart( QDateTime(QDate(1960, 1, 1), QTime(0, 0, 0)) ); 1055 rev.setStart( QDateTime(QDate(1960, 1, 1), QTime(0, 0, 0)) );
1049 nonrev.setStart( rev.start() ); 1056 nonrev.setStart( rev.start() );
1050 } else 1057 } else
1051 emit signalNotFound(); 1058 emit signalNotFound();
1052 wrapAround = !wrapAround; 1059 wrapAround = !wrapAround;
1053 } 1060 }
1054} 1061}
@@ -1065,8 +1072,8 @@ Event DateBookDBHack::eventByUID(int uid) {
1065 1072
1066 for (it = myEventList.begin(); it != myEventList.end(); it++) { 1073 for (it = myEventList.begin(); it != myEventList.end(); it++) {
1067 if ((*it).uid() == uid) return *it; 1074 if ((*it).uid() == uid) return *it;
1068 } 1075 }
1069 for (it = myRepeatEvents.begin(); it != myRepeatEvents.end(); it++) { 1076 for (it = myRepeatEvents.begin(); it != myRepeatEvents.end(); it++) {
1070 if ((*it).uid() == uid) return *it; 1077 if ((*it).uid() == uid) return *it;
1071 } 1078 }
1072 1079
@@ -1074,2 +1081,71 @@ Event DateBookDBHack::eventByUID(int uid) {
1074 return ev; // return at least 1081 return ev; // return at least
1075} 1082}
1083
1084DateBookHoliday::DateBookHoliday()
1085{
1086 _pluginlist.clear();
1087 init();
1088}
1089
1090DateBookHoliday::~DateBookHoliday()
1091{
1092 deinit();
1093}
1094
1095void DateBookHoliday::deinit()
1096{
1097 QValueList<HPlugin*>::Iterator it;
1098 for (it=_pluginlist.begin();it!=_pluginlist.end();++it) {
1099 HPlugin*_pl = *it;
1100 // destructs itself?
1101 _pl->_if->release();
1102 _pl->_lib->unload();
1103 delete _pl->_lib;
1104 delete _pl;
1105 }
1106 _pluginlist.clear();
1107}
1108
1109void DateBookHoliday::init()
1110{
1111 deinit();
1112 QString path = QPEApplication::qpeDir() + "plugins/datebook/holiday";
1113 QDir dir( path, "lib*.so" );
1114 QStringList list = dir.entryList();
1115 QStringList::Iterator it;
1116 for (it=list.begin();it!=list.end();++it) {
1117 Opie::Datebook::HolidayPluginIf*hif = 0;
1118 QLibrary*lib=new QLibrary(path+"/"+*it);
1119 if ((lib->queryInterface(IID_HOLIDAY_PLUGIN,(QUnknownInterface**)&hif) == QS_OK) && hif) {
1120 Opie::Datebook::HolidayPlugin*pl = hif->plugin();
1121 if (pl) {
1122 HPlugin*_pl=new HPlugin;
1123 _pl->_plugin = pl;
1124 odebug << "Found holiday " << pl->description()<<oendl;
1125 _pl->_lib = lib;
1126 _pl->_if = hif;
1127 _pluginlist.append(_pl);
1128 } else {
1129 }
1130 } else {
1131 delete lib;
1132 }
1133 }
1134}
1135
1136QStringList DateBookHoliday::holidaylist(const QDate&aDate)
1137{
1138 QStringList ret;
1139 QValueList<HPlugin*>::Iterator it;
1140 for (it=_pluginlist.begin();it!=_pluginlist.end();++it) {
1141 HPlugin*_pl = *it;
1142 ret+=_pl->_plugin->entries(aDate);
1143 }
1144 return ret;
1145}
1146
1147QStringList DateBookHoliday::holidaylist(unsigned year, unsigned month, unsigned day)
1148{
1149 return holidaylist(QDate(year,month,day));
1150}
1151