summaryrefslogtreecommitdiff
authorumopapisdn <umopapisdn>2003-04-12 00:22:57 (UTC)
committer umopapisdn <umopapisdn>2003-04-12 00:22:57 (UTC)
commit59e2de381eebb33238ee1b257736a9ae0afdbb7e (patch) (unidiff)
treeb86025f2f75318aba65534048105cec36d4b7766
parentd37f3eac6b876285eb7a03ab01194ea261458ea5 (diff)
downloadopie-59e2de381eebb33238ee1b257736a9ae0afdbb7e.zip
opie-59e2de381eebb33238ee1b257736a9ae0afdbb7e.tar.gz
opie-59e2de381eebb33238ee1b257736a9ae0afdbb7e.tar.bz2
Bugfix: (bug #0000833) Duplicating an event should also duplicate the category.
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--core/pim/datebook/datebook.cpp137
1 files changed, 58 insertions, 79 deletions
diff --git a/core/pim/datebook/datebook.cpp b/core/pim/datebook/datebook.cpp
index 3e18374..1bc82a5 100644
--- a/core/pim/datebook/datebook.cpp
+++ b/core/pim/datebook/datebook.cpp
@@ -154,614 +154,593 @@ DateBook::DateBook( QWidget *parent, const char *, WFlags f )
154 a->addTo( view ); 154 a->addTo( view );
155 a->setToggleAction( TRUE ); 155 a->setToggleAction( TRUE );
156 weekLstAction = a; 156 weekLstAction = a;
157 157
158 a = new QAction( tr( "Month" ), Resource::loadPixmap( "month" ), QString::null, 0, g, 0 ); 158 a = new QAction( tr( "Month" ), Resource::loadPixmap( "month" ), QString::null, 0, g, 0 );
159 connect( a, SIGNAL( activated() ), this, SLOT( viewMonth() ) ); 159 connect( a, SIGNAL( activated() ), this, SLOT( viewMonth() ) );
160 a->addTo( sub_bar ); 160 a->addTo( sub_bar );
161 a->addTo( view ); 161 a->addTo( view );
162 a->setToggleAction( TRUE ); 162 a->setToggleAction( TRUE );
163 monthAction = a; 163 monthAction = a;
164 164
165 a = new QAction( tr( "Find" ), Resource::loadPixmap( "mag" ), QString::null, 0, g, 0 ); 165 a = new QAction( tr( "Find" ), Resource::loadPixmap( "mag" ), QString::null, 0, g, 0 );
166 connect( a, SIGNAL(activated()), this, SLOT(slotFind()) ); 166 connect( a, SIGNAL(activated()), this, SLOT(slotFind()) );
167 a->addTo( sub_bar ); 167 a->addTo( sub_bar );
168 168
169 a = new QAction( tr( "Alarm and Start Time..." ), QString::null, 0, 0 ); 169 a = new QAction( tr( "Alarm and Start Time..." ), QString::null, 0, 0 );
170 connect( a, SIGNAL( activated() ), this, SLOT( slotSettings() ) ); 170 connect( a, SIGNAL( activated() ), this, SLOT( slotSettings() ) );
171 a->addTo( settings ); 171 a->addTo( settings );
172 172
173 QPopupMenu *default_view = new QPopupMenu(this); 173 QPopupMenu *default_view = new QPopupMenu(this);
174 settings->insertItem( tr( "Default View" ),default_view ); 174 settings->insertItem( tr( "Default View" ),default_view );
175 default_view->setCheckable(TRUE); 175 default_view->setCheckable(TRUE);
176 176
177 Config config("DateBook"); 177 Config config("DateBook");
178 config.setGroup("Main"); 178 config.setGroup("Main");
179 int current=config.readNumEntry("defaultview", DAY); 179 int current=config.readNumEntry("defaultview", DAY);
180 180
181 QActionGroup *ag = new QActionGroup(this); 181 QActionGroup *ag = new QActionGroup(this);
182 a = new QAction( tr( "Day" ), QString::null, 0, 0, 0, true ); 182 a = new QAction( tr( "Day" ), QString::null, 0, 0, 0, true );
183 if (current==DAY) a->setOn(true), viewDay(); 183 if (current==DAY) a->setOn(true), viewDay();
184 ag->insert(a); 184 ag->insert(a);
185 a = new QAction( tr( "Week" ), QString::null, 0, 0, 0, true ); 185 a = new QAction( tr( "Week" ), QString::null, 0, 0, 0, true );
186 if (current==WEEK) a->setOn(true), /*viewWeek(),*/ needEvilHack = true; 186 if (current==WEEK) a->setOn(true), /*viewWeek(),*/ needEvilHack = true;
187 ag->insert(a); 187 ag->insert(a);
188 a = new QAction( tr( "WeekLst" ), QString::null, 0, 0, 0, true ); 188 a = new QAction( tr( "WeekLst" ), QString::null, 0, 0, 0, true );
189 if (current==WEEKLST) a->setOn(true), viewWeekLst(); 189 if (current==WEEKLST) a->setOn(true), viewWeekLst();
190 ag->insert(a); 190 ag->insert(a);
191 a = new QAction( tr( "Month" ), QString::null, 0, 0, 0, true ); 191 a = new QAction( tr( "Month" ), QString::null, 0, 0, 0, true );
192 if (current==MONTH) a->setOn(true), viewMonth(); 192 if (current==MONTH) a->setOn(true), viewMonth();
193 ag->insert(a); 193 ag->insert(a);
194 194
195 ag->addTo(default_view); 195 ag->addTo(default_view);
196 connect(ag, SIGNAL( selected ( QAction * ) ), 196 connect(ag, SIGNAL( selected ( QAction * ) ),
197 this, SLOT( newDefaultView(QAction *) ) 197 this, SLOT( newDefaultView(QAction *) )
198 ); 198 );
199 199
200 connect( qApp, SIGNAL(clockChanged(bool)), 200 connect( qApp, SIGNAL(clockChanged(bool)),
201 this, SLOT(changeClock(bool)) ); 201 this, SLOT(changeClock(bool)) );
202 connect( qApp, SIGNAL(weekChanged(bool)), 202 connect( qApp, SIGNAL(weekChanged(bool)),
203 this, SLOT(changeWeek(bool)) ); 203 this, SLOT(changeWeek(bool)) );
204 204
205#if defined(Q_WS_QWS) && !defined(QT_NO_COP) 205#if defined(Q_WS_QWS) && !defined(QT_NO_COP)
206 connect( qApp, SIGNAL(appMessage(const QCString&, const QByteArray&)), 206 connect( qApp, SIGNAL(appMessage(const QCString&, const QByteArray&)),
207 this, SLOT(appMessage(const QCString&, const QByteArray&)) ); 207 this, SLOT(appMessage(const QCString&, const QByteArray&)) );
208#endif 208#endif
209 209
210 // listen on QPE/System 210 // listen on QPE/System
211#if defined(Q_WS_QWS) 211#if defined(Q_WS_QWS)
212#if !defined(QT_NO_COP) 212#if !defined(QT_NO_COP)
213 QCopChannel *channel = new QCopChannel( "QPE/System", this ); 213 QCopChannel *channel = new QCopChannel( "QPE/System", this );
214 connect( channel, SIGNAL(received(const QCString&, const QByteArray&)), 214 connect( channel, SIGNAL(received(const QCString&, const QByteArray&)),
215 this, SLOT(receive(const QCString&, const QByteArray&)) ); 215 this, SLOT(receive(const QCString&, const QByteArray&)) );
216 channel = new QCopChannel( "QPE/Datebook", this ); 216 channel = new QCopChannel( "QPE/Datebook", this );
217 connect( channel, SIGNAL(received(const QCString&, const QByteArray&)), 217 connect( channel, SIGNAL(received(const QCString&, const QByteArray&)),
218 this, SLOT(receive(const QCString&, const QByteArray&)) ); 218 this, SLOT(receive(const QCString&, const QByteArray&)) );
219 qDebug("olle\n"); 219 qDebug("olle\n");
220#endif 220#endif
221#endif 221#endif
222 222
223 qDebug("done t=%d", t.elapsed() ); 223 qDebug("done t=%d", t.elapsed() );
224 224
225 /* 225 /*
226 * Here is a problem description: 226 * Here is a problem description:
227 * When Weekview is the default view 227 * When Weekview is the default view
228 * a DateBookWeekView get's created 228 * a DateBookWeekView get's created
229 * redraw() get's called. So what? 229 * redraw() get's called. So what?
230 * Remember that we're still in the c'tor 230 * Remember that we're still in the c'tor
231 * and no final layout has happened? Ok 231 * and no final layout has happened? Ok
232 * now all Events get arranged. Their x 232 * now all Events get arranged. Their x
233 * position get's determined by a QHeader 233 * position get's determined by a QHeader
234 * position. But the QHeader isn't layouted or 234 * position. But the QHeader isn't layouted or
235 * at the right position. redraw() is a slot 235 * at the right position. redraw() is a slot
236 * so we'll call it then via a singleShot 236 * so we'll call it then via a singleShot
237 * from view() 237 * from view()
238 */ 238 */
239 if( needEvilHack ){ 239 if( needEvilHack ){
240 QTimer::singleShot( 500, this, SLOT(viewWeek()) ); 240 QTimer::singleShot( 500, this, SLOT(viewWeek()) );
241 } 241 }
242} 242}
243 243
244void DateBook::receive( const QCString &msg, const QByteArray &data ) 244void DateBook::receive( const QCString &msg, const QByteArray &data )
245{ 245{
246 QDataStream stream( data, IO_ReadOnly ); 246 QDataStream stream( data, IO_ReadOnly );
247 if ( msg == "timeChange(QString)" ) { 247 if ( msg == "timeChange(QString)" ) {
248 // update active view! 248 // update active view!
249 if ( dayAction->isOn() ) 249 if ( dayAction->isOn() )
250 viewDay(); 250 viewDay();
251 else if ( weekAction->isOn() ) 251 else if ( weekAction->isOn() )
252 viewWeek(); 252 viewWeek();
253 else if ( monthAction->isOn() ) 253 else if ( monthAction->isOn() )
254 viewMonth(); 254 viewMonth();
255 } 255 }
256 else if (msg == "editEvent(int)") { 256 else if (msg == "editEvent(int)") {
257 int uid; 257 int uid;
258 stream >> uid; 258 stream >> uid;
259 Event e=db->eventByUID(uid); 259 Event e=db->eventByUID(uid);
260 editEvent(e); 260 editEvent(e);
261 } 261 }
262} 262}
263 263
264DateBook::~DateBook() 264DateBook::~DateBook()
265{ 265{
266} 266}
267 267
268void DateBook::slotSettings() 268void DateBook::slotSettings()
269{ 269{
270 DateBookSettings frmSettings( ampm, this ); 270 DateBookSettings frmSettings( ampm, this );
271 frmSettings.setStartTime( startTime ); 271 frmSettings.setStartTime( startTime );
272 frmSettings.setAlarmPreset( aPreset, presetTime ); 272 frmSettings.setAlarmPreset( aPreset, presetTime );
273 frmSettings.setJumpToCurTime( bJumpToCurTime ); 273 frmSettings.setJumpToCurTime( bJumpToCurTime );
274 frmSettings.setRowStyle( rowStyle ); 274 frmSettings.setRowStyle( rowStyle );
275#if defined (Q_WS_QWS) || defined(_WS_QWS_) 275#if defined (Q_WS_QWS) || defined(_WS_QWS_)
276 frmSettings.showMaximized(); 276 frmSettings.showMaximized();
277#endif 277#endif
278 278
279 if ( frmSettings.exec() ) { 279 if ( frmSettings.exec() ) {
280 aPreset = frmSettings.alarmPreset(); 280 aPreset = frmSettings.alarmPreset();
281 presetTime = frmSettings.presetTime(); 281 presetTime = frmSettings.presetTime();
282 startTime = frmSettings.startTime(); 282 startTime = frmSettings.startTime();
283 bJumpToCurTime = frmSettings.jumpToCurTime(); 283 bJumpToCurTime = frmSettings.jumpToCurTime();
284 rowStyle = frmSettings.rowStyle(); 284 rowStyle = frmSettings.rowStyle();
285 if ( dayView ) 285 if ( dayView )
286 dayView->setStartViewTime( startTime ); 286 dayView->setStartViewTime( startTime );
287 dayView->setJumpToCurTime( bJumpToCurTime ); 287 dayView->setJumpToCurTime( bJumpToCurTime );
288 dayView->setRowStyle( rowStyle ); 288 dayView->setRowStyle( rowStyle );
289 if ( weekView ) 289 if ( weekView )
290 weekView->setStartViewTime( startTime ); 290 weekView->setStartViewTime( startTime );
291 saveSettings(); 291 saveSettings();
292 292
293 // make the change obvious 293 // make the change obvious
294 if ( views->visibleWidget() ) { 294 if ( views->visibleWidget() ) {
295 if ( views->visibleWidget() == dayView ) 295 if ( views->visibleWidget() == dayView )
296 dayView->redraw(); 296 dayView->redraw();
297 else if ( views->visibleWidget() == weekView ) 297 else if ( views->visibleWidget() == weekView )
298 weekView->redraw(); 298 weekView->redraw();
299 } 299 }
300 } 300 }
301} 301}
302 302
303void DateBook::fileNew() 303void DateBook::fileNew()
304{ 304{
305 slotNewEventFromKey(""); 305 slotNewEventFromKey("");
306} 306}
307 307
308QString DateBook::checkEvent(const Event &e) 308QString DateBook::checkEvent(const Event &e)
309{ 309{
310 /* check if overlaps with itself */ 310 /* check if overlaps with itself */
311 bool checkFailed = FALSE; 311 bool checkFailed = FALSE;
312 312
313 /* check the next 12 repeats. should catch most problems */ 313 /* check the next 12 repeats. should catch most problems */
314 QDate current_date = e.start().date(); 314 QDate current_date = e.start().date();
315 Event previous = e; 315 Event previous = e;
316 for(int i = 0; i < 12; i++) 316 for(int i = 0; i < 12; i++)
317 { 317 {
318 QDateTime next; 318 QDateTime next;
319 if (!nextOccurance(previous, current_date.addDays(1), next)) { 319 if (!nextOccurance(previous, current_date.addDays(1), next)) {
320 break; // no more repeats 320 break; // no more repeats
321 } 321 }
322 if(next < previous.end()) { 322 if(next < previous.end()) {
323 checkFailed = TRUE; 323 checkFailed = TRUE;
324 break; 324 break;
325 } 325 }
326 current_date = next.date(); 326 current_date = next.date();
327 } 327 }
328 328
329 if(checkFailed) 329 if(checkFailed)
330 return tr("Event duration is potentially longer\n" 330 return tr("Event duration is potentially longer\n"
331 "than interval between repeats."); 331 "than interval between repeats.");
332 332
333 return QString::null; 333 return QString::null;
334} 334}
335 335
336QDate DateBook::currentDate() 336QDate DateBook::currentDate()
337{ 337{
338 QDate d = QDate::currentDate(); 338 QDate d = QDate::currentDate();
339 339
340 if ( dayView && views->visibleWidget() == dayView ) { 340 if ( dayView && views->visibleWidget() == dayView ) {
341 d = dayView->date(); 341 d = dayView->date();
342 } else if ( weekView && views->visibleWidget() == weekView ) { 342 } else if ( weekView && views->visibleWidget() == weekView ) {
343 d = weekView->date(); 343 d = weekView->date();
344 } else if ( weekLstView && views->visibleWidget() == weekLstView ) { 344 } else if ( weekLstView && views->visibleWidget() == weekLstView ) {
345 d = weekLstView->date(); 345 d = weekLstView->date();
346 } else if ( monthView && views->visibleWidget() == monthView ) { 346 } else if ( monthView && views->visibleWidget() == monthView ) {
347 d = monthView->selectedDate(); 347 d = monthView->selectedDate();
348 } 348 }
349 349
350 return d; 350 return d;
351} 351}
352 352
353void DateBook::view(int v, const QDate &d) { 353void DateBook::view(int v, const QDate &d) {
354 if (v==DAY) { 354 if (v==DAY) {
355 initDay(); 355 initDay();
356 dayAction->setOn( TRUE ); 356 dayAction->setOn( TRUE );
357 dayView->setDate( d ); 357 dayView->setDate( d );
358 views->raiseWidget( dayView ); 358 views->raiseWidget( dayView );
359 dayView->redraw(); 359 dayView->redraw();
360 } else if (v==WEEK) { 360 } else if (v==WEEK) {
361 initWeek(); 361 initWeek();
362 weekAction->setOn( TRUE ); 362 weekAction->setOn( TRUE );
363 weekView->setDate( d ); 363 weekView->setDate( d );
364 views->raiseWidget( weekView ); 364 views->raiseWidget( weekView );
365 weekView->redraw(); 365 weekView->redraw();
366 } else if (v==WEEKLST) { 366 } else if (v==WEEKLST) {
367 initWeekLst(); 367 initWeekLst();
368 weekLstAction->setOn( TRUE ); 368 weekLstAction->setOn( TRUE );
369 weekLstView->setDate(d); 369 weekLstView->setDate(d);
370 views->raiseWidget( weekLstView ); 370 views->raiseWidget( weekLstView );
371 weekLstView->redraw(); 371 weekLstView->redraw();
372 } else if (v==MONTH) { 372 } else if (v==MONTH) {
373 initMonth(); 373 initMonth();
374 monthAction->setOn( TRUE ); 374 monthAction->setOn( TRUE );
375 monthView->setDate( d.year(), d.month(), d.day() ); 375 monthView->setDate( d.year(), d.month(), d.day() );
376 views->raiseWidget( monthView ); 376 views->raiseWidget( monthView );
377 monthView->redraw(); 377 monthView->redraw();
378 } 378 }
379} 379}
380 380
381void DateBook::viewDefault(const QDate &d) { 381void DateBook::viewDefault(const QDate &d) {
382 Config config("DateBook"); 382 Config config("DateBook");
383 config.setGroup("Main"); 383 config.setGroup("Main");
384 int current=config.readNumEntry("defaultview", DAY); 384 int current=config.readNumEntry("defaultview", DAY);
385 385
386 view(current,d); 386 view(current,d);
387} 387}
388 388
389void DateBook::viewDay() { 389void DateBook::viewDay() {
390 view(DAY,currentDate()); 390 view(DAY,currentDate());
391} 391}
392 392
393void DateBook::viewWeek() { 393void DateBook::viewWeek() {
394 view(WEEK,currentDate()); 394 view(WEEK,currentDate());
395} 395}
396 396
397void DateBook::viewWeekLst() { 397void DateBook::viewWeekLst() {
398 view(WEEKLST,currentDate()); 398 view(WEEKLST,currentDate());
399} 399}
400 400
401void DateBook::viewMonth() { 401void DateBook::viewMonth() {
402 view(MONTH,currentDate()); 402 view(MONTH,currentDate());
403} 403}
404 404
405void DateBook::duplicateEvent( const Event &e ) 405void DateBook::duplicateEvent( const Event &e )
406{ 406{
407 qWarning("Hmmm..."); 407 qWarning("Hmmm...");
408 // Alot of code duplication, as this is almost like editEvent(); 408 // Alot of code duplication, as this is almost like editEvent();
409 if (syncing) { 409 if (syncing) {
410 QMessageBox::warning( this, tr("Calendar"), 410 QMessageBox::warning( this, tr("Calendar"), tr( "Can not edit data, currently syncing") );
411 tr( "Can not edit data, currently syncing") ); 411 return;
412 return;
413 } 412 }
414 413
415 Event dupevent; 414 Event dupevent(e);// Make a duplicate.
416 dupevent.setStart(e.start()); 415
417 dupevent.setEnd(e.end());
418 dupevent.setDescription(e.description());
419 dupevent.setLocation(e.location());
420 // dupevent.setCategory(e.category());// how is this done??
421 dupevent.setNotes(e.notes());
422 dupevent.setAllDay(e.isAllDay());
423 dupevent.setTimeZone(e.timeZone());
424 if(e.hasAlarm()) dupevent.setAlarm(e.alarmDelay(),e.alarmSound());
425 if(e.hasRepeat()) dupevent.setRepeat(e.repeatPattern());
426
427 // workaround added for text input. 416 // workaround added for text input.
428 QDialog editDlg( this, 0, TRUE ); 417 QDialog editDlg( this, 0, TRUE );
429 DateEntry *entry; 418 DateEntry *entry;
430 editDlg.setCaption( tr("Duplicate Event") ); 419 editDlg.setCaption( tr("Duplicate Event") );
431 QVBoxLayout *vb = new QVBoxLayout( &editDlg ); 420 QVBoxLayout *vb = new QVBoxLayout( &editDlg );
432 QScrollView *sv = new QScrollView( &editDlg, "scrollview" ); 421 QScrollView *sv = new QScrollView( &editDlg, "scrollview" );
433 sv->setResizePolicy( QScrollView::AutoOneFit ); 422 sv->setResizePolicy( QScrollView::AutoOneFit );
434 // KLUDGE!!! 423 // KLUDGE!!!
435 sv->setHScrollBarMode( QScrollView::AlwaysOff ); 424 sv->setHScrollBarMode( QScrollView::AlwaysOff );
436 vb->addWidget( sv ); 425 vb->addWidget( sv );
437 entry = new DateEntry( onMonday, dupevent, ampm, &editDlg, "editor" ); 426 entry = new DateEntry( onMonday, dupevent, ampm, &editDlg, "editor" );
438 entry->timezone->setEnabled( FALSE ); 427 entry->timezone->setEnabled( FALSE );
439 sv->addChild( entry ); 428 sv->addChild( entry );
440 429
441#if defined(Q_WS_QWS) || defined(_WS_QWS_) 430#if defined(Q_WS_QWS) || defined(_WS_QWS_)
442 editDlg.showMaximized(); 431 editDlg.showMaximized();
443#endif 432#endif
444 while (editDlg.exec() ) { 433 while (editDlg.exec() ) {
445 Event newEv = entry->event(); 434 Event newEv = entry->event();
446 if(newEv.description().isEmpty() && newEv.notes().isEmpty() ) 435 QString error = checkEvent(newEv);
447 break; 436 if (!error.isNull()) {
448 newEv.setUid(e.uid()); // FIXME: Hack not to clear uid 437 if (QMessageBox::warning(this, "error box", error, "Fix it", "Continue", 0, 0, 1) == 0)
449 QString error = checkEvent(newEv); 438 continue;
450 if (!error.isNull()) { 439 }
451 if (QMessageBox::warning(this, "error box", 440 db->addEvent(newEv);
452 error, "Fix it", "Continue", 441 emit newEvent();
453 0, 0, 1) == 0) 442 break;
454 continue;
455 } 443 }
456 db->addEvent(newEv);
457 emit newEvent();
458 break;
459 }
460} 444}
461 445
462void DateBook::editEvent( const Event &e ) 446void DateBook::editEvent( const Event &e )
463{ 447{
464 if (syncing) { 448 if (syncing) {
465 QMessageBox::warning( this, tr("Calendar"), 449 QMessageBox::warning( this, tr("Calendar"), tr( "Can not edit data, currently syncing") );
466 tr( "Can not edit data, currently syncing") ); 450 return;
467 return; 451 }
468 }
469 452
470 // workaround added for text input. 453 // workaround added for text input.
471 QDialog editDlg( this, 0, TRUE ); 454 QDialog editDlg( this, 0, TRUE );
472 DateEntry *entry; 455 DateEntry *entry;
473 editDlg.setCaption( tr("Edit Event") ); 456 editDlg.setCaption( tr("Edit Event") );
474 QVBoxLayout *vb = new QVBoxLayout( &editDlg ); 457 QVBoxLayout *vb = new QVBoxLayout( &editDlg );
475 QScrollView *sv = new QScrollView( &editDlg, "scrollview" ); 458 QScrollView *sv = new QScrollView( &editDlg, "scrollview" );
476 sv->setResizePolicy( QScrollView::AutoOneFit ); 459 sv->setResizePolicy( QScrollView::AutoOneFit );
477 // KLUDGE!!! 460 // KLUDGE!!!
478 sv->setHScrollBarMode( QScrollView::AlwaysOff ); 461 sv->setHScrollBarMode( QScrollView::AlwaysOff );
479 vb->addWidget( sv ); 462 vb->addWidget( sv );
480 entry = new DateEntry( onMonday, e, ampm, &editDlg, "editor" ); 463 entry = new DateEntry( onMonday, e, ampm, &editDlg, "editor" );
481 entry->timezone->setEnabled( FALSE ); 464 entry->timezone->setEnabled( FALSE );
482 sv->addChild( entry ); 465 sv->addChild( entry );
483 466
484#if defined(Q_WS_QWS) || defined(_WS_QWS_) 467#if defined(Q_WS_QWS) || defined(_WS_QWS_)
485 editDlg.showMaximized(); 468 editDlg.showMaximized();
486#endif 469#endif
487 while (editDlg.exec() ) { 470 while (editDlg.exec() ) {
488 Event newEv = entry->event(); 471 Event newEv = entry->event();
489 if(newEv.description().isEmpty() && newEv.notes().isEmpty() ) 472 if(newEv.description().isEmpty() && newEv.notes().isEmpty() )
490 break; 473 break;
491 newEv.setUid(e.uid()); // FIXME: Hack not to clear uid 474 newEv.setUid(e.uid()); // FIXME: Hack not to clear uid
492 QString error = checkEvent(newEv); 475 QString error = checkEvent(newEv);
493 if (!error.isNull()) { 476 if (!error.isNull()) {
494 if (QMessageBox::warning(this, "error box", 477 if (QMessageBox::warning(this, "error box", error, "Fix it", "Continue", 0, 0, 1) == 0) continue;
495 error, "Fix it", "Continue",
496 0, 0, 1) == 0)
497 continue;
498 } 478 }
499 db->editEvent(e, newEv); 479 db->editEvent(e, newEv);
500 emit newEvent(); 480 emit newEvent();
501 break; 481 break;
502 } 482 }
503} 483}
504 484
505void DateBook::removeEvent( const Event &e ) 485void DateBook::removeEvent( const Event &e )
506{ 486{
507 if (syncing) { 487 if (syncing) {
508 QMessageBox::warning( this, tr("Calendar"), 488 QMessageBox::warning( this, tr("Calendar"), tr( "Can not edit data, currently syncing") );
509 tr( "Can not edit data, currently syncing") ); 489 return;
510 return; 490 }
511 }
512 491
513 QString strName = e.description(); 492 QString strName = e.description();
514 493
515 if ( !QPEMessageBox::confirmDelete( this, tr( "Calendar" ),strName ) ) 494 if ( !QPEMessageBox::confirmDelete( this, tr( "Calendar" ),strName ) )
516 return; 495 return;
517 496
518 db->removeEvent( e ); 497 db->removeEvent( e );
519 if ( views->visibleWidget() == dayView && dayView ) 498 if ( views->visibleWidget() == dayView && dayView )
520 dayView->redraw(); 499 dayView->redraw();
521} 500}
522 501
523void DateBook::addEvent( const Event &e ) 502void DateBook::addEvent( const Event &e )
524{ 503{
525 QDate d = e.start().date(); 504 QDate d = e.start().date();
526 initDay(); 505 initDay();
527 dayView->setDate( d ); 506 dayView->setDate( d );
528} 507}
529 508
530void DateBook::showDay( int year, int month, int day ) 509void DateBook::showDay( int year, int month, int day )
531{ 510{
532 QDate d(year, month, day); 511 QDate d(year, month, day);
533 view(DAY,d); 512 view(DAY,d);
534} 513}
535 514
536void DateBook::initDay() 515void DateBook::initDay()
537{ 516{
538 if ( !dayView ) { 517 if ( !dayView ) {
539 dayView = new DateBookDay( ampm, onMonday, db, views, "day view" ); 518 dayView = new DateBookDay( ampm, onMonday, db, views, "day view" );
540 views->addWidget( dayView, DAY ); 519 views->addWidget( dayView, DAY );
541 dayView->setStartViewTime( startTime ); 520 dayView->setStartViewTime( startTime );
542 dayView->setJumpToCurTime( bJumpToCurTime ); 521 dayView->setJumpToCurTime( bJumpToCurTime );
543 dayView->setRowStyle( rowStyle ); 522 dayView->setRowStyle( rowStyle );
544 connect( this, SIGNAL( newEvent() ), 523 connect( this, SIGNAL( newEvent() ),
545 dayView, SLOT( redraw() ) ); 524 dayView, SLOT( redraw() ) );
546 connect( dayView, SIGNAL( newEvent() ), 525 connect( dayView, SIGNAL( newEvent() ),
547 this, SLOT( fileNew() ) ); 526 this, SLOT( fileNew() ) );
548 connect( dayView, SIGNAL( removeEvent( const Event & ) ), 527 connect( dayView, SIGNAL( removeEvent( const Event & ) ),
549 this, SLOT( removeEvent( const Event & ) ) ); 528 this, SLOT( removeEvent( const Event & ) ) );
550 connect( dayView, SIGNAL( editEvent( const Event & ) ), 529 connect( dayView, SIGNAL( editEvent( const Event & ) ),
551 this, SLOT( editEvent( const Event & ) ) ); 530 this, SLOT( editEvent( const Event & ) ) );
552 connect( dayView, SIGNAL( duplicateEvent( const Event & ) ), 531 connect( dayView, SIGNAL( duplicateEvent( const Event & ) ),
553 this, SLOT( duplicateEvent( const Event & ) ) ); 532 this, SLOT( duplicateEvent( const Event & ) ) );
554 connect( dayView, SIGNAL( beamEvent( const Event & ) ), 533 connect( dayView, SIGNAL( beamEvent( const Event & ) ),
555 this, SLOT( beamEvent( const Event & ) ) ); 534 this, SLOT( beamEvent( const Event & ) ) );
556 connect( dayView, SIGNAL(sigNewEvent(const QString &)), 535 connect( dayView, SIGNAL(sigNewEvent(const QString &)),
557 this, SLOT(slotNewEventFromKey(const QString &)) ); 536 this, SLOT(slotNewEventFromKey(const QString &)) );
558 } 537 }
559} 538}
560 539
561void DateBook::initWeek() 540void DateBook::initWeek()
562{ 541{
563 if ( !weekView ) { 542 if ( !weekView ) {
564 weekView = new DateBookWeek( ampm, onMonday, db, views, "week view" ); 543 weekView = new DateBookWeek( ampm, onMonday, db, views, "week view" );
565 weekView->setStartViewTime( startTime ); 544 weekView->setStartViewTime( startTime );
566 views->addWidget( weekView, WEEK ); 545 views->addWidget( weekView, WEEK );
567 connect( weekView, SIGNAL( showDate( int, int, int ) ), 546 connect( weekView, SIGNAL( showDate( int, int, int ) ),
568 this, SLOT( showDay( int, int, int ) ) ); 547 this, SLOT( showDay( int, int, int ) ) );
569 connect( this, SIGNAL( newEvent() ), 548 connect( this, SIGNAL( newEvent() ),
570 weekView, SLOT( redraw() ) ); 549 weekView, SLOT( redraw() ) );
571 } 550 }
572 //But also get it right: the year that we display can be different 551 //But also get it right: the year that we display can be different
573 //from the year of the current date. So, first find the year 552 //from the year of the current date. So, first find the year
574 //number of the current week. 553 //number of the current week.
575 554
576 int yearNumber, totWeeks; 555 int yearNumber, totWeeks;
577 calcWeek( currentDate(), totWeeks, yearNumber, onMonday ); 556 calcWeek( currentDate(), totWeeks, yearNumber, onMonday );
578 557
579 QDate d = QDate( yearNumber, 12, 31 ); 558 QDate d = QDate( yearNumber, 12, 31 );
580 calcWeek( d, totWeeks, yearNumber, onMonday ); 559 calcWeek( d, totWeeks, yearNumber, onMonday );
581 560
582 while ( totWeeks == 1 ) { 561 while ( totWeeks == 1 ) {
583 d = d.addDays( -1 ); 562 d = d.addDays( -1 );
584 calcWeek( d, totWeeks, yearNumber, onMonday ); 563 calcWeek( d, totWeeks, yearNumber, onMonday );
585 } 564 }
586 if ( totWeeks != weekView->totalWeeks() ) 565 if ( totWeeks != weekView->totalWeeks() )
587 weekView->setTotalWeeks( totWeeks ); 566 weekView->setTotalWeeks( totWeeks );
588} 567}
589void DateBook::initWeekLst() { 568void DateBook::initWeekLst() {
590 if ( !weekLstView ) { 569 if ( !weekLstView ) {
591 weekLstView = new DateBookWeekLst( ampm, onMonday, db, 570 weekLstView = new DateBookWeekLst( ampm, onMonday, db,
592 views, "weeklst view" ); 571 views, "weeklst view" );
593 views->addWidget( weekLstView, WEEKLST ); 572 views->addWidget( weekLstView, WEEKLST );
594 573
595 //weekLstView->setStartViewTime( startTime ); 574 //weekLstView->setStartViewTime( startTime );
596 connect( weekLstView, SIGNAL( showDate( int, int, int ) ), 575 connect( weekLstView, SIGNAL( showDate( int, int, int ) ),
597 this, SLOT( showDay( int, int, int ) ) ); 576 this, SLOT( showDay( int, int, int ) ) );
598 connect( weekLstView, SIGNAL( addEvent( const QDateTime &, 577 connect( weekLstView, SIGNAL( addEvent( const QDateTime &,
599 const QDateTime &, 578 const QDateTime &,
600 const QString & , const QString &) ), 579 const QString & , const QString &) ),
601 this, SLOT( slotNewEntry( const QDateTime &, 580 this, SLOT( slotNewEntry( const QDateTime &,
602 const QDateTime &, 581 const QDateTime &,
603 const QString & , const QString &) ) ); 582 const QString & , const QString &) ) );
604 connect( this, SIGNAL( newEvent() ), 583 connect( this, SIGNAL( newEvent() ),
605 weekLstView, SLOT( redraw() ) ); 584 weekLstView, SLOT( redraw() ) );
606 connect( weekLstView, SIGNAL( editEvent( const Event & ) ), 585 connect( weekLstView, SIGNAL( editEvent( const Event & ) ),
607 this, SLOT( editEvent( const Event & ) ) ); 586 this, SLOT( editEvent( const Event & ) ) );
608 } 587 }
609} 588}
610 589
611 590
612void DateBook::initMonth() 591void DateBook::initMonth()
613{ 592{
614 if ( !monthView ) { 593 if ( !monthView ) {
615 monthView = new DateBookMonth( views, "month view", FALSE, db ); 594 monthView = new DateBookMonth( views, "month view", FALSE, db );
616 views->addWidget( monthView, MONTH ); 595 views->addWidget( monthView, MONTH );
617 connect( monthView, SIGNAL( dateClicked( int, int, int ) ), 596 connect( monthView, SIGNAL( dateClicked( int, int, int ) ),
618 this, SLOT( showDay( int, int, int ) ) ); 597 this, SLOT( showDay( int, int, int ) ) );
619 connect( this, SIGNAL( newEvent() ), 598 connect( this, SIGNAL( newEvent() ),
620 monthView, SLOT( redraw() ) ); 599 monthView, SLOT( redraw() ) );
621 qApp->processEvents(); 600 qApp->processEvents();
622 } 601 }
623} 602}
624 603
625void DateBook::loadSettings() 604void DateBook::loadSettings()
626{ 605{
627 { 606 {
628 Config config( "qpe" ); 607 Config config( "qpe" );
629 config.setGroup("Time"); 608 config.setGroup("Time");
630 ampm = config.readBoolEntry( "AMPM", TRUE ); 609 ampm = config.readBoolEntry( "AMPM", TRUE );
631 onMonday = config.readBoolEntry( "MONDAY" ); 610 onMonday = config.readBoolEntry( "MONDAY" );
632 } 611 }
633 612
634 { 613 {
635 Config config("DateBook"); 614 Config config("DateBook");
636 config.setGroup("Main"); 615 config.setGroup("Main");
637 startTime = config.readNumEntry("startviewtime", 8); 616 startTime = config.readNumEntry("startviewtime", 8);
638 aPreset = config.readBoolEntry("alarmpreset"); 617 aPreset = config.readBoolEntry("alarmpreset");
639 presetTime = config.readNumEntry("presettime"); 618 presetTime = config.readNumEntry("presettime");
640 bJumpToCurTime = config.readBoolEntry("jumptocurtime"); 619 bJumpToCurTime = config.readBoolEntry("jumptocurtime");
641 rowStyle = config.readNumEntry("rowstyle"); 620 rowStyle = config.readNumEntry("rowstyle");
642 } 621 }
643} 622}
644 623
645void DateBook::saveSettings() 624void DateBook::saveSettings()
646{ 625{
647 Config config( "qpe" ); 626 Config config( "qpe" );
648 Config configDB( "DateBook" ); 627 Config configDB( "DateBook" );
649 configDB.setGroup( "Main" ); 628 configDB.setGroup( "Main" );
650 configDB.writeEntry("startviewtime",startTime); 629 configDB.writeEntry("startviewtime",startTime);
651 configDB.writeEntry("alarmpreset",aPreset); 630 configDB.writeEntry("alarmpreset",aPreset);
652 configDB.writeEntry("presettime",presetTime); 631 configDB.writeEntry("presettime",presetTime);
653 configDB.writeEntry("jumptocurtime", bJumpToCurTime); 632 configDB.writeEntry("jumptocurtime", bJumpToCurTime);
654 configDB.writeEntry("rowstyle", rowStyle); 633 configDB.writeEntry("rowstyle", rowStyle);
655} 634}
656 635
657void DateBook::newDefaultView(QAction *a) { 636void DateBook::newDefaultView(QAction *a) {
658 int val=DAY; 637 int val=DAY;
659 if (a->text() == "Day") val=DAY; 638 if (a->text() == "Day") val=DAY;
660 if (a->text() == "Week") val=WEEK; 639 if (a->text() == "Week") val=WEEK;
661 if (a->text() == "WeekLst") val=WEEKLST; 640 if (a->text() == "WeekLst") val=WEEKLST;
662 if (a->text() == "Month") val=MONTH; 641 if (a->text() == "Month") val=MONTH;
663 642
664 Config configDB( "DateBook" ); 643 Config configDB( "DateBook" );
665 configDB.setGroup( "Main" ); 644 configDB.setGroup( "Main" );
666 configDB.writeEntry("defaultview",val); 645 configDB.writeEntry("defaultview",val);
667} 646}
668 647
669void DateBook::appMessage(const QCString& msg, const QByteArray& data) 648void DateBook::appMessage(const QCString& msg, const QByteArray& data)
670{ 649{
671 bool needShow = FALSE; 650 bool needShow = FALSE;
672 if ( msg == "alarm(QDateTime,int)" ) { 651 if ( msg == "alarm(QDateTime,int)" ) {
673 QDataStream ds(data,IO_ReadOnly); 652 QDataStream ds(data,IO_ReadOnly);
674 QDateTime when; int warn; 653 QDateTime when; int warn;
675 ds >> when >> warn; 654 ds >> when >> warn;
676 655
677 // check to make it's okay to continue, 656 // check to make it's okay to continue,
678 // this is the case that the time was set ahead, and 657 // this is the case that the time was set ahead, and
679 // we are forced given a stale alarm... 658 // we are forced given a stale alarm...
680 QDateTime current = QDateTime::currentDateTime(); 659 QDateTime current = QDateTime::currentDateTime();
681 if ( current.time().hour() != when.time().hour() 660 if ( current.time().hour() != when.time().hour()
682 && current.time().minute() != when.time().minute() ) 661 && current.time().minute() != when.time().minute() )
683 return; 662 return;
684 663
685 QValueList<EffectiveEvent> list = db->getEffectiveEvents(when.addSecs(warn*60)); 664 QValueList<EffectiveEvent> list = db->getEffectiveEvents(when.addSecs(warn*60));
686 if ( list.count() > 0 ) { 665 if ( list.count() > 0 ) {
687 QString msg; 666 QString msg;
688 bool bSound = FALSE; 667 bool bSound = FALSE;
689 int stopTimer = 0; 668 int stopTimer = 0;
690 bool found = FALSE; 669 bool found = FALSE;
691 for ( QValueList<EffectiveEvent>::ConstIterator it=list.begin(); 670 for ( QValueList<EffectiveEvent>::ConstIterator it=list.begin();
692 it!=list.end(); ++it ) { 671 it!=list.end(); ++it ) {
693 if ( (*it).event().hasAlarm() ) { 672 if ( (*it).event().hasAlarm() ) {
694 found = TRUE; 673 found = TRUE;
695 msg += "<CENTER><B>" + (*it).description() + "</B>" 674 msg += "<CENTER><B>" + (*it).description() + "</B>"
696 + "<BR>" + (*it).location() + "<BR>" 675 + "<BR>" + (*it).location() + "<BR>"
697 + TimeString::dateString((*it).event().start(),ampm) 676 + TimeString::dateString((*it).event().start(),ampm)
698 + (warn 677 + (warn
699 ? tr(" (in " + QString::number(warn) 678 ? tr(" (in " + QString::number(warn)
700 + tr(" minutes)")) 679 + tr(" minutes)"))
701 : QString("")) 680 : QString(""))
702 + "<BR>" 681 + "<BR>"
703 + (*it).notes() + "</CENTER>"; 682 + (*it).notes() + "</CENTER>";
704 if ( (*it).event().alarmSound() != Event::Silent ) { 683 if ( (*it).event().alarmSound() != Event::Silent ) {
705 bSound = TRUE; 684 bSound = TRUE;
706 } 685 }
707 } 686 }
708 } 687 }
709 if ( found ) { 688 if ( found ) {
710 if ( bSound ) { 689 if ( bSound ) {
711 Sound::soundAlarm(); 690 Sound::soundAlarm();
712 alarmCounter = 0; 691 alarmCounter = 0;
713 stopTimer = startTimer( 5000 ); 692 stopTimer = startTimer( 5000 );
714 } 693 }
715 694
716 QDialog dlg( this, 0, TRUE ); 695 QDialog dlg( this, 0, TRUE );
717 QVBoxLayout *vb = new QVBoxLayout( &dlg ); 696 QVBoxLayout *vb = new QVBoxLayout( &dlg );
718 QScrollView *view = new QScrollView( &dlg, "scrollView"); 697 QScrollView *view = new QScrollView( &dlg, "scrollView");
719 view->setResizePolicy( QScrollView::AutoOneFit ); 698 view->setResizePolicy( QScrollView::AutoOneFit );
720 vb->addWidget( view ); 699 vb->addWidget( view );
721 QLabel *lblMsg = new QLabel( msg, &dlg ); 700 QLabel *lblMsg = new QLabel( msg, &dlg );
722 view->addChild( lblMsg ); 701 view->addChild( lblMsg );
723 QPushButton *cmdOk = new QPushButton( tr("OK"), &dlg ); 702 QPushButton *cmdOk = new QPushButton( tr("OK"), &dlg );
724 connect( cmdOk, SIGNAL(clicked()), &dlg, SLOT(accept()) ); 703 connect( cmdOk, SIGNAL(clicked()), &dlg, SLOT(accept()) );
725 vb->addWidget( cmdOk ); 704 vb->addWidget( cmdOk );
726 705
727#if defined(Q_WS_QWS) || defined(_WS_QWS_) 706#if defined(Q_WS_QWS) || defined(_WS_QWS_)
728 dlg.showMaximized(); 707 dlg.showMaximized();
729#endif 708#endif
730 needShow = dlg.exec(); 709 needShow = dlg.exec();
731 710
732 if ( bSound ) 711 if ( bSound )
733 killTimer( stopTimer ); 712 killTimer( stopTimer );
734 } 713 }
735 } 714 }
736 } else if ( msg == "nextView()" ) { 715 } else if ( msg == "nextView()" ) {
737 if ( !qApp-> activeWindow ( )) { 716 if ( !qApp-> activeWindow ( )) {
738 needShow = TRUE; 717 needShow = TRUE;
739 } 718 }
740 else { 719 else {
741 QWidget* cur = views->visibleWidget(); 720 QWidget* cur = views->visibleWidget();
742 if ( cur ) { 721 if ( cur ) {
743 if ( cur == dayView ) 722 if ( cur == dayView )
744 viewWeek(); 723 viewWeek();
745 else if ( cur == weekView ) 724 else if ( cur == weekView )
746 viewWeekLst(); 725 viewWeekLst();
747 else if ( cur == weekLstView ) 726 else if ( cur == weekLstView )
748 viewMonth(); 727 viewMonth();
749 else if ( cur == monthView ) 728 else if ( cur == monthView )
750 viewDay(); 729 viewDay();
751 needShow = TRUE; 730 needShow = TRUE;
752 } 731 }
753 } 732 }
754 } 733 }
755 if ( needShow ) { 734 if ( needShow ) {
756#if defined(Q_WS_QWS) || defined(_WS_QWS_) 735#if defined(Q_WS_QWS) || defined(_WS_QWS_)
757 showMaximized(); 736 showMaximized();
758#else 737#else
759 show(); 738 show();
760#endif 739#endif
761 raise(); 740 raise();
762 QPEApplication::setKeepRunning(); 741 QPEApplication::setKeepRunning();
763 setActiveWindow(); 742 setActiveWindow();
764 } 743 }
765} 744}
766 745
767void DateBook::reload() 746void DateBook::reload()