summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--core/pim/datebook/datebook.cpp189
1 files changed, 97 insertions, 92 deletions
diff --git a/core/pim/datebook/datebook.cpp b/core/pim/datebook/datebook.cpp
index 1bc82a5..829f8f8 100644
--- a/core/pim/datebook/datebook.cpp
+++ b/core/pim/datebook/datebook.cpp
@@ -200,125 +200,129 @@ DateBook::DateBook( QWidget *parent, const char *, WFlags f )
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
281 presetTime = frmSettings.presetTime(); 281 aPreset = frmSettings.alarmPreset();
282 startTime = frmSettings.startTime(); 282 presetTime = frmSettings.presetTime();
283 bJumpToCurTime = frmSettings.jumpToCurTime(); 283 startTime = frmSettings.startTime();
284 rowStyle = frmSettings.rowStyle(); 284 bJumpToCurTime = frmSettings.jumpToCurTime();
285 if ( dayView ) 285 rowStyle = frmSettings.rowStyle();
286 dayView->setStartViewTime( startTime ); 286
287 dayView->setJumpToCurTime( bJumpToCurTime ); 287 if ( dayView ) {
288 dayView->setRowStyle( rowStyle ); 288 dayView->setStartViewTime( startTime );
289 if ( weekView ) 289 dayView->setJumpToCurTime( bJumpToCurTime );
290 weekView->setStartViewTime( startTime ); 290 dayView->setRowStyle( rowStyle );
291 saveSettings(); 291 }
292 292 if ( weekView ) {
293 // make the change obvious 293 weekView->setStartViewTime( startTime );
294 if ( views->visibleWidget() ) { 294 }
295 if ( views->visibleWidget() == dayView ) 295 saveSettings();
296 dayView->redraw(); 296
297 else if ( views->visibleWidget() == weekView ) 297 // make the change obvious
298 weekView->redraw(); 298 if ( views->visibleWidget() ) {
299 if ( views->visibleWidget() == dayView )
300 dayView->redraw();
301 else if ( views->visibleWidget() == weekView )
302 weekView->redraw();
303 }
299 } 304 }
300 }
301} 305}
302 306
303void DateBook::fileNew() 307void DateBook::fileNew()
304{ 308{
305 slotNewEventFromKey(""); 309 slotNewEventFromKey("");
306} 310}
307 311
308QString DateBook::checkEvent(const Event &e) 312QString DateBook::checkEvent(const Event &e)
309{ 313{
310 /* check if overlaps with itself */ 314 /* check if overlaps with itself */
311 bool checkFailed = FALSE; 315 bool checkFailed = FALSE;
312 316
313 /* check the next 12 repeats. should catch most problems */ 317 /* check the next 12 repeats. should catch most problems */
314 QDate current_date = e.start().date(); 318 QDate current_date = e.start().date();
315 Event previous = e; 319 Event previous = e;
316 for(int i = 0; i < 12; i++) 320 for(int i = 0; i < 12; i++)
317 { 321 {
318 QDateTime next; 322 QDateTime next;
319 if (!nextOccurance(previous, current_date.addDays(1), next)) { 323 if (!nextOccurance(previous, current_date.addDays(1), next)) {
320 break; // no more repeats 324 break; // no more repeats
321 } 325 }
322 if(next < previous.end()) { 326 if(next < previous.end()) {
323 checkFailed = TRUE; 327 checkFailed = TRUE;
324 break; 328 break;
@@ -330,73 +334,73 @@ QString DateBook::checkEvent(const Event &e)
330 return tr("Event duration is potentially longer\n" 334 return tr("Event duration is potentially longer\n"
331 "than interval between repeats."); 335 "than interval between repeats.");
332 336
333 return QString::null; 337 return QString::null;
334} 338}
335 339
336QDate DateBook::currentDate() 340QDate DateBook::currentDate()
337{ 341{
338 QDate d = QDate::currentDate(); 342 QDate d = QDate::currentDate();
339 343
340 if ( dayView && views->visibleWidget() == dayView ) { 344 if ( dayView && views->visibleWidget() == dayView ) {
341 d = dayView->date(); 345 d = dayView->date();
342 } else if ( weekView && views->visibleWidget() == weekView ) { 346 } else if ( weekView && views->visibleWidget() == weekView ) {
343 d = weekView->date(); 347 d = weekView->date();
344 } else if ( weekLstView && views->visibleWidget() == weekLstView ) { 348 } else if ( weekLstView && views->visibleWidget() == weekLstView ) {
345 d = weekLstView->date(); 349 d = weekLstView->date();
346 } else if ( monthView && views->visibleWidget() == monthView ) { 350 } else if ( monthView && views->visibleWidget() == monthView ) {
347 d = monthView->selectedDate(); 351 d = monthView->selectedDate();
348 } 352 }
349 353
350 return d; 354 return d;
351} 355}
352 356
353void DateBook::view(int v, const QDate &d) { 357void DateBook::view(int v, const QDate &d) {
354 if (v==DAY) { 358 if (v==DAY) {
355 initDay(); 359 initDay();
356 dayAction->setOn( TRUE ); 360 dayAction->setOn( TRUE );
357 dayView->setDate( d ); 361 dayView->setDate( d );
358 views->raiseWidget( dayView ); 362 views->raiseWidget( dayView );
359 dayView->redraw(); 363 dayView->redraw();
360 } else if (v==WEEK) { 364 } else if (v==WEEK) {
361 initWeek(); 365 initWeek();
362 weekAction->setOn( TRUE ); 366 weekAction->setOn( TRUE );
363 weekView->setDate( d ); 367 weekView->setDate( d );
364 views->raiseWidget( weekView ); 368 views->raiseWidget( weekView );
365 weekView->redraw(); 369 weekView->redraw();
366 } else if (v==WEEKLST) { 370 } else if (v==WEEKLST) {
367 initWeekLst(); 371 initWeekLst();
368 weekLstAction->setOn( TRUE ); 372 weekLstAction->setOn( TRUE );
369 weekLstView->setDate(d); 373 weekLstView->setDate(d);
370 views->raiseWidget( weekLstView ); 374 views->raiseWidget( weekLstView );
371 weekLstView->redraw(); 375 weekLstView->redraw();
372 } else if (v==MONTH) { 376 } else if (v==MONTH) {
373 initMonth(); 377 initMonth();
374 monthAction->setOn( TRUE ); 378 monthAction->setOn( TRUE );
375 monthView->setDate( d.year(), d.month(), d.day() ); 379 monthView->setDate( d.year(), d.month(), d.day() );
376 views->raiseWidget( monthView ); 380 views->raiseWidget( monthView );
377 monthView->redraw(); 381 monthView->redraw();
378 } 382 }
379} 383}
380 384
381void DateBook::viewDefault(const QDate &d) { 385void DateBook::viewDefault(const QDate &d) {
382 Config config("DateBook"); 386 Config config("DateBook");
383 config.setGroup("Main"); 387 config.setGroup("Main");
384 int current=config.readNumEntry("defaultview", DAY); 388 int current=config.readNumEntry("defaultview", DAY);
385 389
386 view(current,d); 390 view(current,d);
387} 391}
388 392
389void DateBook::viewDay() { 393void DateBook::viewDay() {
390 view(DAY,currentDate()); 394 view(DAY,currentDate());
391} 395}
392 396
393void DateBook::viewWeek() { 397void DateBook::viewWeek() {
394 view(WEEK,currentDate()); 398 view(WEEK,currentDate());
395} 399}
396 400
397void DateBook::viewWeekLst() { 401void DateBook::viewWeekLst() {
398 view(WEEKLST,currentDate()); 402 view(WEEKLST,currentDate());
399} 403}
400 404
401void DateBook::viewMonth() { 405void DateBook::viewMonth() {
402 view(MONTH,currentDate()); 406 view(MONTH,currentDate());
@@ -493,99 +497,100 @@ void DateBook::removeEvent( const Event &e )
493 497
494 if ( !QPEMessageBox::confirmDelete( this, tr( "Calendar" ),strName ) ) 498 if ( !QPEMessageBox::confirmDelete( this, tr( "Calendar" ),strName ) )
495 return; 499 return;
496 500
497 db->removeEvent( e ); 501 db->removeEvent( e );
498 if ( views->visibleWidget() == dayView && dayView ) 502 if ( views->visibleWidget() == dayView && dayView )
499 dayView->redraw(); 503 dayView->redraw();
500} 504}
501 505
502void DateBook::addEvent( const Event &e ) 506void DateBook::addEvent( const Event &e )
503{ 507{
504 QDate d = e.start().date(); 508 QDate d = e.start().date();
505 initDay(); 509 initDay();
506 dayView->setDate( d ); 510 dayView->setDate( d );
507} 511}
508 512
509void DateBook::showDay( int year, int month, int day ) 513void DateBook::showDay( int year, int month, int day )
510{ 514{
511 QDate d(year, month, day); 515 QDate d(year, month, day);
512 view(DAY,d); 516 view(DAY,d);
513} 517}
514 518
515void DateBook::initDay() 519void DateBook::initDay()
516{ 520{
517 if ( !dayView ) { 521 if ( !dayView ) {
518 dayView = new DateBookDay( ampm, onMonday, db, views, "day view" ); 522 dayView = new DateBookDay( ampm, onMonday, db, views, "day view" );
519 views->addWidget( dayView, DAY ); 523 views->addWidget( dayView, DAY );
520 dayView->setStartViewTime( startTime ); 524 dayView->setStartViewTime( startTime );
521 dayView->setJumpToCurTime( bJumpToCurTime ); 525 dayView->setJumpToCurTime( bJumpToCurTime );
522 dayView->setRowStyle( rowStyle ); 526 dayView->setRowStyle( rowStyle );
523 connect( this, SIGNAL( newEvent() ), 527 connect( this, SIGNAL( newEvent() ),
524 dayView, SLOT( redraw() ) ); 528 dayView, SLOT( redraw() ) );
525 connect( dayView, SIGNAL( newEvent() ), 529 connect( dayView, SIGNAL( newEvent() ),
526 this, SLOT( fileNew() ) ); 530 this, SLOT( fileNew() ) );
527 connect( dayView, SIGNAL( removeEvent( const Event & ) ), 531 connect( dayView, SIGNAL( removeEvent( const Event & ) ),
528 this, SLOT( removeEvent( const Event & ) ) ); 532 this, SLOT( removeEvent( const Event & ) ) );
529 connect( dayView, SIGNAL( editEvent( const Event & ) ), 533 connect( dayView, SIGNAL( editEvent( const Event & ) ),
530 this, SLOT( editEvent( const Event & ) ) ); 534 this, SLOT( editEvent( const Event & ) ) );
531 connect( dayView, SIGNAL( duplicateEvent( const Event & ) ), 535 connect( dayView, SIGNAL( duplicateEvent( const Event & ) ),
532 this, SLOT( duplicateEvent( const Event & ) ) ); 536 this, SLOT( duplicateEvent( const Event & ) ) );
533 connect( dayView, SIGNAL( beamEvent( const Event & ) ), 537 connect( dayView, SIGNAL( beamEvent( const Event & ) ),
534 this, SLOT( beamEvent( const Event & ) ) ); 538 this, SLOT( beamEvent( const Event & ) ) );
535 connect( dayView, SIGNAL(sigNewEvent(const QString &)), 539 connect( dayView, SIGNAL(sigNewEvent(const QString &)),
536 this, SLOT(slotNewEventFromKey(const QString &)) ); 540 this, SLOT(slotNewEventFromKey(const QString &)) );
537 } 541 }
538} 542}
539 543
540void DateBook::initWeek() 544void DateBook::initWeek()
541{ 545{
542 if ( !weekView ) { 546 if ( !weekView ) {
543 weekView = new DateBookWeek( ampm, onMonday, db, views, "week view" ); 547 weekView = new DateBookWeek( ampm, onMonday, db, views, "week view" );
544 weekView->setStartViewTime( startTime ); 548 weekView->setStartViewTime( startTime );
545 views->addWidget( weekView, WEEK ); 549 views->addWidget( weekView, WEEK );
546 connect( weekView, SIGNAL( showDate( int, int, int ) ), 550 connect( weekView, SIGNAL( showDate( int, int, int ) ),
547 this, SLOT( showDay( int, int, int ) ) ); 551 this, SLOT( showDay( int, int, int ) ) );
548 connect( this, SIGNAL( newEvent() ), 552 connect( this, SIGNAL( newEvent() ),
549 weekView, SLOT( redraw() ) ); 553 weekView, SLOT( redraw() ) );
550 } 554 }
551 //But also get it right: the year that we display can be different
552 //from the year of the current date. So, first find the year
553 //number of the current week.
554
555 int yearNumber, totWeeks;
556 calcWeek( currentDate(), totWeeks, yearNumber, onMonday );
557 555
558 QDate d = QDate( yearNumber, 12, 31 ); 556 //But also get it right: the year that we display can be different
559 calcWeek( d, totWeeks, yearNumber, onMonday ); 557 //from the year of the current date. So, first find the year
558 //number of the current week.
559 int yearNumber, totWeeks;
560 calcWeek( currentDate(), totWeeks, yearNumber, onMonday );
560 561
561 while ( totWeeks == 1 ) { 562 QDate d = QDate( yearNumber, 12, 31 );
562 d = d.addDays( -1 );
563 calcWeek( d, totWeeks, yearNumber, onMonday ); 563 calcWeek( d, totWeeks, yearNumber, onMonday );
564 } 564
565 if ( totWeeks != weekView->totalWeeks() ) 565 while ( totWeeks == 1 ) {
566 weekView->setTotalWeeks( totWeeks ); 566 d = d.addDays( -1 );
567 calcWeek( d, totWeeks, yearNumber, onMonday );
568 }
569 if ( totWeeks != weekView->totalWeeks() )
570 weekView->setTotalWeeks( totWeeks );
567} 571}
572
568void DateBook::initWeekLst() { 573void DateBook::initWeekLst() {
569 if ( !weekLstView ) { 574 if ( !weekLstView ) {
570 weekLstView = new DateBookWeekLst( ampm, onMonday, db, 575 weekLstView = new DateBookWeekLst( ampm, onMonday, db,
571 views, "weeklst view" ); 576 views, "weeklst view" );
572 views->addWidget( weekLstView, WEEKLST ); 577 views->addWidget( weekLstView, WEEKLST );
573 578
574 //weekLstView->setStartViewTime( startTime ); 579 //weekLstView->setStartViewTime( startTime );
575 connect( weekLstView, SIGNAL( showDate( int, int, int ) ), 580 connect( weekLstView, SIGNAL( showDate( int, int, int ) ),
576 this, SLOT( showDay( int, int, int ) ) ); 581 this, SLOT( showDay( int, int, int ) ) );
577 connect( weekLstView, SIGNAL( addEvent( const QDateTime &, 582 connect( weekLstView, SIGNAL( addEvent( const QDateTime &,
578 const QDateTime &, 583 const QDateTime &,
579 const QString & , const QString &) ), 584 const QString & , const QString &) ),
580 this, SLOT( slotNewEntry( const QDateTime &, 585 this, SLOT( slotNewEntry( const QDateTime &,
581 const QDateTime &, 586 const QDateTime &,
582 const QString & , const QString &) ) ); 587 const QString & , const QString &) ) );
583 connect( this, SIGNAL( newEvent() ), 588 connect( this, SIGNAL( newEvent() ),
584 weekLstView, SLOT( redraw() ) ); 589 weekLstView, SLOT( redraw() ) );
585 connect( weekLstView, SIGNAL( editEvent( const Event & ) ), 590 connect( weekLstView, SIGNAL( editEvent( const Event & ) ),
586 this, SLOT( editEvent( const Event & ) ) ); 591 this, SLOT( editEvent( const Event & ) ) );
587 } 592 }
588} 593}
589 594
590 595
591void DateBook::initMonth() 596void DateBook::initMonth()