summaryrefslogtreecommitdiff
authorzecke <zecke>2004-02-18 22:11:25 (UTC)
committer zecke <zecke>2004-02-18 22:11:25 (UTC)
commit71b6aa6d19ed2e4690cd98ecdb7dbfe40f857653 (patch) (unidiff)
tree2d300c075b052fa1ad7e4814f52256e51fd7d8ba
parent859ad22772e90dfbd4a8c0760ddc52d451f50011 (diff)
downloadopie-71b6aa6d19ed2e4690cd98ecdb7dbfe40f857653.zip
opie-71b6aa6d19ed2e4690cd98ecdb7dbfe40f857653.tar.gz
opie-71b6aa6d19ed2e4690cd98ecdb7dbfe40f857653.tar.bz2
be more clever when it comes to searching events
Fix bug 1193
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--core/pim/datebook/datebook.cpp35
1 files changed, 14 insertions, 21 deletions
diff --git a/core/pim/datebook/datebook.cpp b/core/pim/datebook/datebook.cpp
index 706cc08..832b2f8 100644
--- a/core/pim/datebook/datebook.cpp
+++ b/core/pim/datebook/datebook.cpp
@@ -165,49 +165,48 @@ DateBook::DateBook( QWidget *parent, const char *, WFlags f )
165 165
166 a = new QAction( tr( "Edit..." ), Resource::loadPixmap("SettingsIcon"), QString::null, 0, this, 0 ); 166 a = new QAction( tr( "Edit..." ), Resource::loadPixmap("SettingsIcon"), QString::null, 0, this, 0 );
167 connect( a, SIGNAL( activated() ), this, SLOT( slotSettings() ) ); 167 connect( a, SIGNAL( activated() ), this, SLOT( slotSettings() ) );
168 a->addTo( sub_bar ); 168 a->addTo( sub_bar );
169 169
170 if(defaultView==DAY) viewDay(); 170 if(defaultView==DAY) viewDay();
171 if(defaultView==WEEK) needEvilHack=true;// viewWeek(); 171 if(defaultView==WEEK) needEvilHack=true;// viewWeek();
172 if(defaultView==WEEKLST) viewWeekLst(); 172 if(defaultView==WEEKLST) viewWeekLst();
173 if(defaultView==MONTH) viewMonth(); 173 if(defaultView==MONTH) viewMonth();
174 174
175 connect( qApp, SIGNAL(clockChanged(bool)), this, SLOT(changeClock(bool)) ); 175 connect( qApp, SIGNAL(clockChanged(bool)), this, SLOT(changeClock(bool)) );
176 connect( qApp, SIGNAL(weekChanged(bool)), this, SLOT(changeWeek(bool)) ); 176 connect( qApp, SIGNAL(weekChanged(bool)), this, SLOT(changeWeek(bool)) );
177 177
178#if defined(Q_WS_QWS) && !defined(QT_NO_COP) 178#if defined(Q_WS_QWS) && !defined(QT_NO_COP)
179 connect( qApp, SIGNAL(appMessage(const QCString&, const QByteArray&)), this, SLOT(appMessage(const QCString&, const QByteArray&)) ); 179 connect( qApp, SIGNAL(appMessage(const QCString&, const QByteArray&)), this, SLOT(appMessage(const QCString&, const QByteArray&)) );
180#endif 180#endif
181 181
182 // listen on QPE/System 182 // listen on QPE/System
183#if defined(Q_WS_QWS) 183#if defined(Q_WS_QWS)
184#if !defined(QT_NO_COP) 184#if !defined(QT_NO_COP)
185 QCopChannel *channel = new QCopChannel( "QPE/System", this ); 185 QCopChannel *channel = new QCopChannel( "QPE/System", this );
186 connect( channel, SIGNAL(received(const QCString&, const QByteArray&)), this, SLOT(receive(const QCString&, const QByteArray&)) ); 186 connect( channel, SIGNAL(received(const QCString&, const QByteArray&)), this, SLOT(receive(const QCString&, const QByteArray&)) );
187 channel = new QCopChannel( "QPE/Datebook", this ); 187 channel = new QCopChannel( "QPE/Datebook", this );
188 connect( channel, SIGNAL(received(const QCString&, const QByteArray&)), this, SLOT(receive(const QCString&, const QByteArray&)) ); 188 connect( channel, SIGNAL(received(const QCString&, const QByteArray&)), this, SLOT(receive(const QCString&, const QByteArray&)) );
189 qDebug("olle\n");
190#endif 189#endif
191#endif 190#endif
192 191
193 qDebug("done t=%d", t.elapsed() ); 192 qDebug("done t=%d", t.elapsed() );
194 193
195 connect( qApp, SIGNAL( flush() ), this, SLOT( flush() ) ); 194 connect( qApp, SIGNAL( flush() ), this, SLOT( flush() ) );
196 connect( qApp, SIGNAL( reload()), this, SLOT( reload() ) ); 195 connect( qApp, SIGNAL( reload()), this, SLOT( reload() ) );
197 /* 196 /*
198 * Here is a problem description: 197 * Here is a problem description:
199 * When Weekview is the default view 198 * When Weekview is the default view
200 * a DateBookWeekView get's created 199 * a DateBookWeekView get's created
201 * redraw() get's called. So what? 200 * redraw() get's called. So what?
202 * Remember that we're still in the c'tor 201 * Remember that we're still in the c'tor
203 * and no final layout has happened? Ok 202 * and no final layout has happened? Ok
204 * now all Events get arranged. Their x 203 * now all Events get arranged. Their x
205 * position get's determined by a QHeader 204 * position get's determined by a QHeader
206 * position. But the QHeader isn't layouted or 205 * position. But the QHeader isn't layouted or
207 * at the right position. redraw() is a slot 206 * at the right position. redraw() is a slot
208 * so we'll call it then via a singleShot 207 * so we'll call it then via a singleShot
209 * from view() 208 * from view()
210 */ 209 */
211 if( needEvilHack ){ 210 if( needEvilHack ){
212 QTimer::singleShot( 500, this, SLOT(viewWeek()) ); 211 QTimer::singleShot( 500, this, SLOT(viewWeek()) );
213 } 212 }
@@ -388,49 +387,48 @@ void DateBook::viewWeek() {
388 view(WEEK,currentDate()); 387 view(WEEK,currentDate());
389} 388}
390 389
391void DateBook::viewWeekLst() { 390void DateBook::viewWeekLst() {
392 view(WEEKLST,currentDate()); 391 view(WEEKLST,currentDate());
393} 392}
394 393
395void DateBook::viewMonth() { 394void DateBook::viewMonth() {
396 view(MONTH,currentDate()); 395 view(MONTH,currentDate());
397} 396}
398 397
399void DateBook::insertEvent( const Event &e ) 398void DateBook::insertEvent( const Event &e )
400{ 399{
401 Event dupEvent=e; 400 Event dupEvent=e;
402 if(!dupEvent.isValidUid() ) // tkcRom seems to be different 401 if(!dupEvent.isValidUid() ) // tkcRom seems to be different
403 dupEvent.assignUid(); 402 dupEvent.assignUid();
404 dupEvent.setLocation(defaultLocation); 403 dupEvent.setLocation(defaultLocation);
405 dupEvent.setCategories(defaultCategories); 404 dupEvent.setCategories(defaultCategories);
406 db->addEvent(dupEvent); 405 db->addEvent(dupEvent);
407 emit newEvent(); 406 emit newEvent();
408} 407}
409 408
410void DateBook::duplicateEvent( const Event &e ) 409void DateBook::duplicateEvent( const Event &e )
411{ 410{
412 qWarning("Hmmm...");
413 // Alot of code duplication, as this is almost like editEvent(); 411 // Alot of code duplication, as this is almost like editEvent();
414 if (syncing) { 412 if (syncing) {
415 QMessageBox::warning( this, tr("Calendar"), tr( "Can not edit data, currently syncing") ); 413 QMessageBox::warning( this, tr("Calendar"), tr( "Can not edit data, currently syncing") );
416 return; 414 return;
417 } 415 }
418 416
419 Event dupevent(e);// Make a duplicate. 417 Event dupevent(e);// Make a duplicate.
420 418
421 // workaround added for text input. 419 // workaround added for text input.
422 QDialog editDlg( this, 0, TRUE ); 420 QDialog editDlg( this, 0, TRUE );
423 DateEntry *entry; 421 DateEntry *entry;
424 editDlg.setCaption( tr("Duplicate Event") ); 422 editDlg.setCaption( tr("Duplicate Event") );
425 QVBoxLayout *vb = new QVBoxLayout( &editDlg ); 423 QVBoxLayout *vb = new QVBoxLayout( &editDlg );
426 QScrollView *sv = new QScrollView( &editDlg, "scrollview" ); 424 QScrollView *sv = new QScrollView( &editDlg, "scrollview" );
427 sv->setResizePolicy( QScrollView::AutoOneFit ); 425 sv->setResizePolicy( QScrollView::AutoOneFit );
428 // KLUDGE!!! 426 // KLUDGE!!!
429 sv->setHScrollBarMode( QScrollView::AlwaysOff ); 427 sv->setHScrollBarMode( QScrollView::AlwaysOff );
430 vb->addWidget( sv ); 428 vb->addWidget( sv );
431 entry = new DateEntry( onMonday, dupevent, ampm, &editDlg, "editor" ); 429 entry = new DateEntry( onMonday, dupevent, ampm, &editDlg, "editor" );
432 entry->timezone->setEnabled( FALSE ); 430 entry->timezone->setEnabled( FALSE );
433 sv->addChild( entry ); 431 sv->addChild( entry );
434 432
435 while ( QPEApplication::execDialog( &editDlg ) ) { 433 while ( QPEApplication::execDialog( &editDlg ) ) {
436 Event newEv = entry->event(); 434 Event newEv = entry->event();
@@ -487,48 +485,49 @@ void DateBook::editEvent( const Event &e )
487 if (!error.isNull()) { 485 if (!error.isNull()) {
488 if (QMessageBox::warning(this, tr("error box"), error, tr("Fix it"), tr("Continue"), 0, 0, 1) == 0) continue; 486 if (QMessageBox::warning(this, tr("error box"), error, tr("Fix it"), tr("Continue"), 0, 0, 1) == 0) continue;
489 } 487 }
490 db->editEvent(e, newEv); 488 db->editEvent(e, newEv);
491 emit newEvent(); 489 emit newEvent();
492 break; 490 break;
493 } 491 }
494} 492}
495 493
496void DateBook::removeEvent( const Event &e ) 494void DateBook::removeEvent( const Event &e )
497{ 495{
498 if (syncing) { 496 if (syncing) {
499 QMessageBox::warning( this, tr("Calendar"), tr( "Can not edit data, currently syncing") ); 497 QMessageBox::warning( this, tr("Calendar"), tr( "Can not edit data, currently syncing") );
500 return; 498 return;
501 } 499 }
502 500
503 QString strName = e.description(); 501 QString strName = e.description();
504 502
505 if ( !QPEMessageBox::confirmDelete( this, tr( "Calendar" ),strName ) ) 503 if ( !QPEMessageBox::confirmDelete( this, tr( "Calendar" ),strName ) )
506 return; 504 return;
507 505
508 db->removeEvent( e ); 506 db->removeEvent( e );
509 if ( views->visibleWidget() == dayView && dayView ) 507 if ( views->visibleWidget() == dayView && dayView )
510 dayView->redraw(); 508 dayView->redraw();
509
511} 510}
512 511
513void DateBook::addEvent( const Event &e ) 512void DateBook::addEvent( const Event &e )
514{ 513{
515 QDate d = e.start().date(); 514 QDate d = e.start().date();
516 initDay(); 515 initDay();
517 dayView->setDate( d ); 516 dayView->setDate( d );
518} 517}
519 518
520void DateBook::showDay( int year, int month, int day ) 519void DateBook::showDay( int year, int month, int day )
521{ 520{
522 QDate d(year, month, day); 521 QDate d(year, month, day);
523 view(DAY,d); 522 view(DAY,d);
524} 523}
525 524
526void DateBook::initDay() 525void DateBook::initDay()
527{ 526{
528 if ( !dayView ) { 527 if ( !dayView ) {
529 dayView = new DateBookDay( ampm, onMonday, db, views, "day view" ); 528 dayView = new DateBookDay( ampm, onMonday, db, views, "day view" );
530 views->addWidget( dayView, DAY ); 529 views->addWidget( dayView, DAY );
531 dayView->setJumpToCurTime( bJumpToCurTime ); 530 dayView->setJumpToCurTime( bJumpToCurTime );
532 dayView->setStartViewTime( startTime ); 531 dayView->setStartViewTime( startTime );
533 dayView->setRowStyle( rowStyle ); 532 dayView->setRowStyle( rowStyle );
534 connect( this, SIGNAL( newEvent() ), dayView, SLOT( redraw() ) ); 533 connect( this, SIGNAL( newEvent() ), dayView, SLOT( redraw() ) );
@@ -970,82 +969,78 @@ bool catComp( QArray<int> cats, int category )
970 returnMe = true; 969 returnMe = true;
971 else { 970 else {
972 for ( i = 0; i < count; i++ ) { 971 for ( i = 0; i < count; i++ ) {
973 if ( category == cats[i] ) { 972 if ( category == cats[i] ) {
974 returnMe = true; 973 returnMe = true;
975 break; 974 break;
976 } 975 }
977 } 976 }
978 } 977 }
979 return returnMe; 978 return returnMe;
980} 979}
981 980
982 981
983void DateBook::slotDoFind( const QString& txt, const QDate &dt, 982void DateBook::slotDoFind( const QString& txt, const QDate &dt,
984 bool caseSensitive, bool /*backwards*/, 983 bool caseSensitive, bool /*backwards*/,
985 int category ) 984 int category )
986{ 985{
987 QDateTime dtEnd( QDate(3001, 1, 1), QTime(0, 0, 0) ), 986 QDateTime dtEnd( QDate(3001, 1, 1), QTime(0, 0, 0) ),
988 next; 987 next;
989 988
990 QRegExp r( txt ); 989 QRegExp r( txt );
991 r.setCaseSensitive( caseSensitive ); 990 r.setCaseSensitive( caseSensitive );
992 991
993 992
994 static Event rev, 993 static Event rev, nonrev;
995 nonrev;
996 if ( !inSearch ) { 994 if ( !inSearch ) {
997 rev.setStart( QDateTime(QDate(1960, 1, 1), QTime(0, 0, 0)) ); 995 rev.setStart( QDateTime(QDate(1960, 1, 1), QTime(0, 0, 0)) );
998 nonrev.setStart( rev.start() ); 996 nonrev.setStart( rev.start() );
999 inSearch = true; 997 inSearch = true;
1000 } 998 }
1001 static QDate searchDate = dt; 999 static QDate searchDate = dt;
1002 static bool wrapAround = true; 1000 static bool wrapAround = true;
1003 bool candidtate; 1001 bool candidtate;
1004 candidtate = false; 1002 candidtate = false;
1005 1003
1006 QValueList<Event> repeats = db->getRawRepeats(); 1004 QValueList<Event> repeats = db->getRawRepeats();
1007 1005
1008 // find the candidate for the first repeat that matches... 1006 // find the candidate for the first repeat that matches...
1009 QValueListConstIterator<Event> it; 1007 QValueListConstIterator<Event> it;
1010 QDate start = dt; 1008 QDate start = dt;
1011 for ( it = repeats.begin(); it != repeats.end(); ++it ) { 1009 for ( it = repeats.begin(); it != repeats.end(); ++it ) {
1012 if ( catComp( (*it).categories(), category ) ) { 1010 if ( catComp( (*it).categories(), category ) ) {
1013 while ( nextOccurance( *it, start, next ) ) { 1011 if ( (*it).match( r ) ) {
1014 if ( next < dtEnd ) { 1012 if ( nextOccurance( *it, start, next ) ) {
1015 if ( (*it).match( r ) && !(next <= rev.start()) ) { 1013 if ( next < dtEnd && !(next <= rev.start() ) ) {
1016 rev = *it; 1014 rev = *it;
1017 dtEnd = next; 1015 dtEnd = next;
1018 rev.setStart( next ); 1016 rev.setStart( next );
1019 candidtate = true; 1017 candidtate = true;
1020 wrapAround = true; 1018 wrapAround = true;
1021 start = dt; 1019 }
1022 break; 1020 }
1023 } else 1021 }
1024 start = next.date().addDays( 1 ); 1022 }
1025 }
1026 }
1027 }
1028 } 1023 }
1029 1024
1030 // now the for first non repeat... 1025 // now the for first non repeat...
1031 QValueList<Event> nonRepeats = db->getNonRepeatingEvents( dt, dtEnd.date() ); 1026 QValueList<Event> nonRepeats = db->getNonRepeatingEvents( dt, dtEnd.date() );
1032 qHeapSort( nonRepeats.begin(), nonRepeats.end() ); 1027 qHeapSort( nonRepeats.begin(), nonRepeats.end() );
1033 for ( it = nonRepeats.begin(); it != nonRepeats.end(); ++it ) { 1028 for ( it = nonRepeats.begin(); it != nonRepeats.end(); ++it ) {
1034 if ( catComp( (*it).categories(), category ) ) { 1029 if ( catComp( (*it).categories(), category ) ) {
1035 if ( (*it).start() < dtEnd ) { 1030 if ( (*it).start() < dtEnd ) {
1036 if ( (*it).match( r ) && !(*it <= nonrev) ) { 1031 if ( (*it).match( r ) && !(*it <= nonrev) ) {
1037 nonrev = *it; 1032 nonrev = *it;
1038 dtEnd = nonrev.start(); 1033 dtEnd = nonrev.start();
1039 candidtate = true; 1034 candidtate = true;
1040 wrapAround = true; 1035 wrapAround = true;
1041 break; 1036 break;
1042 } 1037 }
1043 } 1038 }
1044 } 1039 }
1045 } 1040 }
1046 if ( candidtate ) { 1041 if ( candidtate ) {
1047 dayView->setStartViewTime( dtEnd.time().hour() ); 1042 dayView->setStartViewTime( dtEnd.time().hour() );
1048 dayView->setDate( dtEnd.date().year(), dtEnd.date().month(), 1043 dayView->setDate( dtEnd.date().year(), dtEnd.date().month(),
1049 dtEnd.date().day() ); 1044 dtEnd.date().day() );
1050 } else { 1045 } else {
1051 if ( wrapAround ) { 1046 if ( wrapAround ) {
@@ -1054,29 +1049,27 @@ void DateBook::slotDoFind( const QString& txt, const QDate &dt,
1054 nonrev.setStart( rev.start() ); 1049 nonrev.setStart( rev.start() );
1055 } else 1050 } else
1056 emit signalNotFound(); 1051 emit signalNotFound();
1057 wrapAround = !wrapAround; 1052 wrapAround = !wrapAround;
1058 } 1053 }
1059} 1054}
1060 1055
1061Event DateBookDBHack::eventByUID(int uid) { 1056Event DateBookDBHack::eventByUID(int uid) {
1062 1057
1063 // FIXME: Dirty Hacks to get hold of the private event lists 1058 // FIXME: Dirty Hacks to get hold of the private event lists
1064 QDate start; 1059 QDate start;
1065 QDate end=start.addDays(-1); 1060 QDate end=start.addDays(-1);
1066 QValueList<Event> myEventList=getNonRepeatingEvents(start,end); 1061 QValueList<Event> myEventList=getNonRepeatingEvents(start,end);
1067 QValueList<Event> myRepeatEvents=getRawRepeats(); 1062 QValueList<Event> myRepeatEvents=getRawRepeats();
1068 1063
1069 QValueList<Event>::ConstIterator it; 1064 QValueList<Event>::ConstIterator it;
1070 1065
1071 for (it = myEventList.begin(); it != myEventList.end(); it++) { 1066 for (it = myEventList.begin(); it != myEventList.end(); it++) {
1072 if ((*it).uid() == uid) return *it; 1067 if ((*it).uid() == uid) return *it;
1073 } 1068 }
1074 for (it = myRepeatEvents.begin(); it != myRepeatEvents.end(); it++) { 1069 for (it = myRepeatEvents.begin(); it != myRepeatEvents.end(); it++) {
1075 if ((*it).uid() == uid) return *it; 1070 if ((*it).uid() == uid) return *it;
1076 } 1071 }
1077 1072
1078 qDebug("Event not found: uid=%d\n", uid);
1079 Event ev; 1073 Event ev;
1080 return ev; // return at least 1074 return ev; // return at least
1081} 1075}
1082