summaryrefslogtreecommitdiff
authorzecke <zecke>2004-02-18 23:19:17 (UTC)
committer zecke <zecke>2004-02-18 23:19:17 (UTC)
commit28b63b3270b8162fcea4449b53b75fa325d740ad (patch) (unidiff)
treeeed2c5064cd05c080ac6e9da38996857cd9008b7
parentf8caabcef314cad5007fec940af48d8cd4612c49 (diff)
downloadopie-28b63b3270b8162fcea4449b53b75fa325d740ad.zip
opie-28b63b3270b8162fcea4449b53b75fa325d740ad.tar.gz
opie-28b63b3270b8162fcea4449b53b75fa325d740ad.tar.bz2
Add Documentation on how we search and why we do stuff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--core/pim/datebook/datebook.cpp12
1 files changed, 12 insertions, 0 deletions
diff --git a/core/pim/datebook/datebook.cpp b/core/pim/datebook/datebook.cpp
index 832b2f8..24affd0 100644
--- a/core/pim/datebook/datebook.cpp
+++ b/core/pim/datebook/datebook.cpp
@@ -808,268 +808,280 @@ void DateBook::closeEvent( QCloseEvent *e )
808 if ( db->save() ) { 808 if ( db->save() ) {
809 e->accept(); 809 e->accept();
810 } else { 810 } else {
811 if ( QMessageBox::critical( this, tr( "Out of space" ), 811 if ( QMessageBox::critical( this, tr( "Out of space" ),
812 tr("Calendar was unable to save\n" 812 tr("Calendar was unable to save\n"
813 "your changes.\n" 813 "your changes.\n"
814 "Free up some space and try again.\n" 814 "Free up some space and try again.\n"
815 "\nQuit anyway?"), 815 "\nQuit anyway?"),
816 QMessageBox::Yes|QMessageBox::Escape, 816 QMessageBox::Yes|QMessageBox::Escape,
817 QMessageBox::No|QMessageBox::Default ) 817 QMessageBox::No|QMessageBox::Default )
818 != QMessageBox::No ) 818 != QMessageBox::No )
819 e->accept(); 819 e->accept();
820 else 820 else
821 e->ignore(); 821 e->ignore();
822 } 822 }
823} 823}
824 824
825// Entering directly from the "keyboard" 825// Entering directly from the "keyboard"
826void DateBook::slotNewEventFromKey( const QString &str ) 826void DateBook::slotNewEventFromKey( const QString &str )
827{ 827{
828 if (syncing) { 828 if (syncing) {
829 QMessageBox::warning( this, tr("Calendar"), 829 QMessageBox::warning( this, tr("Calendar"),
830 tr( "Can not edit data, currently syncing") ); 830 tr( "Can not edit data, currently syncing") );
831 return; 831 return;
832 } 832 }
833 833
834 // We get to here from a key pressed in the Day View 834 // We get to here from a key pressed in the Day View
835 // So we can assume some things. We want the string 835 // So we can assume some things. We want the string
836 // passed in to be part of the description. 836 // passed in to be part of the description.
837 QDateTime start, end; 837 QDateTime start, end;
838 if ( views->visibleWidget() == dayView ) { 838 if ( views->visibleWidget() == dayView ) {
839 dayView->selectedDates( start, end ); 839 dayView->selectedDates( start, end );
840 } else if ( views->visibleWidget() == monthView ) { 840 } else if ( views->visibleWidget() == monthView ) {
841 QDate d = monthView->selectedDate(); 841 QDate d = monthView->selectedDate();
842 start = end = d; 842 start = end = d;
843 start.setTime( QTime( 10, 0 ) ); 843 start.setTime( QTime( 10, 0 ) );
844 end.setTime( QTime( 12, 0 ) ); 844 end.setTime( QTime( 12, 0 ) );
845 } else if ( views->visibleWidget() == weekView ) { 845 } else if ( views->visibleWidget() == weekView ) {
846 QDate d = weekView->date(); 846 QDate d = weekView->date();
847 start = end = d; 847 start = end = d;
848 start.setTime( QTime( 10, 0 ) ); 848 start.setTime( QTime( 10, 0 ) );
849 end.setTime( QTime( 12, 0 ) ); 849 end.setTime( QTime( 12, 0 ) );
850 } else if ( views->visibleWidget() == weekLstView ) { 850 } else if ( views->visibleWidget() == weekLstView ) {
851 QDate d = weekLstView->date(); 851 QDate d = weekLstView->date();
852 start = end = d; 852 start = end = d;
853 start.setTime( QTime( 10, 0 ) ); 853 start.setTime( QTime( 10, 0 ) );
854 end.setTime( QTime( 12, 0 ) ); 854 end.setTime( QTime( 12, 0 ) );
855 } 855 }
856 slotNewEntry(start, end, str); 856 slotNewEntry(start, end, str);
857} 857}
858void DateBook::slotNewEntry(const QDateTime &start, const QDateTime &end, const QString &str, const QString &location) { 858void DateBook::slotNewEntry(const QDateTime &start, const QDateTime &end, const QString &str, const QString &location) {
859 // argh! This really needs to be encapsulated in a class 859 // argh! This really needs to be encapsulated in a class
860 // or function. 860 // or function.
861 QDialog newDlg( this, 0, TRUE ); 861 QDialog newDlg( this, 0, TRUE );
862 newDlg.setCaption( DateEntryBase::tr("New Event") ); 862 newDlg.setCaption( DateEntryBase::tr("New Event") );
863 DateEntry *e; 863 DateEntry *e;
864 QVBoxLayout *vb = new QVBoxLayout( &newDlg ); 864 QVBoxLayout *vb = new QVBoxLayout( &newDlg );
865 QScrollView *sv = new QScrollView( &newDlg ); 865 QScrollView *sv = new QScrollView( &newDlg );
866 sv->setResizePolicy( QScrollView::AutoOneFit ); 866 sv->setResizePolicy( QScrollView::AutoOneFit );
867 sv->setFrameStyle( QFrame::NoFrame ); 867 sv->setFrameStyle( QFrame::NoFrame );
868 sv->setHScrollBarMode( QScrollView::AlwaysOff ); 868 sv->setHScrollBarMode( QScrollView::AlwaysOff );
869 vb->addWidget( sv ); 869 vb->addWidget( sv );
870 870
871 Event ev; 871 Event ev;
872 ev.setDescription( str ); 872 ev.setDescription( str );
873 // When the new gui comes in, change this... 873 // When the new gui comes in, change this...
874 if(location==0) { 874 if(location==0) {
875 if(defaultLocation.isEmpty()) { 875 if(defaultLocation.isEmpty()) {
876 ev.setLocation(tr("(Unknown)")); 876 ev.setLocation(tr("(Unknown)"));
877 } else { 877 } else {
878 ev.setLocation( defaultLocation ); 878 ev.setLocation( defaultLocation );
879 } 879 }
880 } else { 880 } else {
881 ev.setLocation(location); 881 ev.setLocation(location);
882 } 882 }
883 ev.setCategories(defaultCategories); 883 ev.setCategories(defaultCategories);
884 ev.setStart( start ); 884 ev.setStart( start );
885 ev.setEnd( end ); 885 ev.setEnd( end );
886 886
887 e = new DateEntry( onMonday, ev, ampm, &newDlg ); 887 e = new DateEntry( onMonday, ev, ampm, &newDlg );
888 e->setAlarmEnabled( aPreset, presetTime, Event::Loud ); 888 e->setAlarmEnabled( aPreset, presetTime, Event::Loud );
889 sv->addChild( e ); 889 sv->addChild( e );
890 while ( QPEApplication::execDialog( &newDlg ) ) { 890 while ( QPEApplication::execDialog( &newDlg ) ) {
891 ev = e->event(); 891 ev = e->event();
892 ev.assignUid(); 892 ev.assignUid();
893 QString error = checkEvent( ev ); 893 QString error = checkEvent( ev );
894 if ( !error.isNull() ) { 894 if ( !error.isNull() ) {
895 if ( QMessageBox::warning( this, tr("Error!"), error, tr("Fix it"), tr("Continue"), 0, 0, 1 ) == 0 ) 895 if ( QMessageBox::warning( this, tr("Error!"), error, tr("Fix it"), tr("Continue"), 0, 0, 1 ) == 0 )
896 continue; 896 continue;
897 } 897 }
898 db->addEvent( ev ); 898 db->addEvent( ev );
899 emit newEvent(); 899 emit newEvent();
900 break; 900 break;
901 } 901 }
902} 902}
903 903
904void DateBook::setDocument( const QString &filename ) 904void DateBook::setDocument( const QString &filename )
905{ 905{
906 if ( filename.find(".vcs") != int(filename.length()) - 4 ) return; 906 if ( filename.find(".vcs") != int(filename.length()) - 4 ) return;
907 907
908 QValueList<Event> tl = Event::readVCalendar( filename ); 908 QValueList<Event> tl = Event::readVCalendar( filename );
909 for( QValueList<Event>::Iterator it = tl.begin(); it != tl.end(); ++it ) { 909 for( QValueList<Event>::Iterator it = tl.begin(); it != tl.end(); ++it ) {
910 db->addEvent( *it ); 910 db->addEvent( *it );
911 } 911 }
912} 912}
913 913
914static const char * beamfile = "/tmp/obex/event.vcs"; 914static const char * beamfile = "/tmp/obex/event.vcs";
915 915
916void DateBook::beamEvent( const Event &e ) 916void DateBook::beamEvent( const Event &e )
917{ 917{
918 qDebug("trying to beamn"); 918 qDebug("trying to beamn");
919 unlink( beamfile ); // delete if exists 919 unlink( beamfile ); // delete if exists
920 mkdir("/tmp/obex/", 0755); 920 mkdir("/tmp/obex/", 0755);
921 Event::writeVCalendar( beamfile, e ); 921 Event::writeVCalendar( beamfile, e );
922 Ir *ir = new Ir( this ); 922 Ir *ir = new Ir( this );
923 connect( ir, SIGNAL( done( Ir * ) ), this, SLOT( beamDone( Ir * ) ) ); 923 connect( ir, SIGNAL( done( Ir * ) ), this, SLOT( beamDone( Ir * ) ) );
924 QString description = e.description(); 924 QString description = e.description();
925 ir->send( beamfile, description, "text/x-vCalendar" ); 925 ir->send( beamfile, description, "text/x-vCalendar" );
926} 926}
927 927
928void DateBook::beamDone( Ir *ir ) 928void DateBook::beamDone( Ir *ir )
929{ 929{
930 delete ir; 930 delete ir;
931 unlink( beamfile ); 931 unlink( beamfile );
932} 932}
933 933
934void DateBook::slotFind() 934void DateBook::slotFind()
935{ 935{
936 // move it to the day view... 936 // move it to the day view...
937 viewDay(); 937 viewDay();
938 FindDialog frmFind( "Calendar", this ); // no tr needed 938 FindDialog frmFind( "Calendar", this ); // no tr needed
939 frmFind.setUseDate( true ); 939 frmFind.setUseDate( true );
940 frmFind.setDate( currentDate() ); 940 frmFind.setDate( currentDate() );
941 QObject::connect( &frmFind, 941 QObject::connect( &frmFind,
942 SIGNAL(signalFindClicked(const QString&, const QDate&, 942 SIGNAL(signalFindClicked(const QString&, const QDate&,
943 bool, bool, int)), 943 bool, bool, int)),
944 this, 944 this,
945 SLOT(slotDoFind(const QString&, const QDate&, 945 SLOT(slotDoFind(const QString&, const QDate&,
946 bool, bool, int)) ); 946 bool, bool, int)) );
947 QObject::connect( this, 947 QObject::connect( this,
948 SIGNAL(signalNotFound()), 948 SIGNAL(signalNotFound()),
949 &frmFind, 949 &frmFind,
950 SLOT(slotNotFound()) ); 950 SLOT(slotNotFound()) );
951 QObject::connect( this, 951 QObject::connect( this,
952 SIGNAL(signalWrapAround()), 952 SIGNAL(signalWrapAround()),
953 &frmFind, 953 &frmFind,
954 SLOT(slotWrapAround()) ); 954 SLOT(slotWrapAround()) );
955 frmFind.move(0,0); 955 frmFind.move(0,0);
956 frmFind.exec(); 956 frmFind.exec();
957 inSearch = false; 957 inSearch = false;
958} 958}
959 959
960bool catComp( QArray<int> cats, int category ) 960bool catComp( QArray<int> cats, int category )
961{ 961{
962 bool returnMe; 962 bool returnMe;
963 int i, 963 int i,
964 count; 964 count;
965 965
966 count = int(cats.count()); 966 count = int(cats.count());
967 returnMe = false; 967 returnMe = false;
968 if ( (category == -1 && count == 0) || category == -2 ) 968 if ( (category == -1 && count == 0) || category == -2 )
969 returnMe = true; 969 returnMe = true;
970 else { 970 else {
971 for ( i = 0; i < count; i++ ) { 971 for ( i = 0; i < count; i++ ) {
972 if ( category == cats[i] ) { 972 if ( category == cats[i] ) {
973 returnMe = true; 973 returnMe = true;
974 break; 974 break;
975 } 975 }
976 } 976 }
977 } 977 }
978 return returnMe; 978 return returnMe;
979} 979}
980 980
981 981
982void DateBook::slotDoFind( const QString& txt, const QDate &dt, 982void DateBook::slotDoFind( const QString& txt, const QDate &dt,
983 bool caseSensitive, bool /*backwards*/, 983 bool caseSensitive, bool /*backwards*/,
984 int category ) 984 int category )
985{ 985{
986 QDateTime dtEnd( QDate(3001, 1, 1), QTime(0, 0, 0) ), 986 QDateTime dtEnd( QDate(3001, 1, 1), QTime(0, 0, 0) ),
987 next; 987 next;
988 988
989 QRegExp r( txt ); 989 QRegExp r( txt );
990 r.setCaseSensitive( caseSensitive ); 990 r.setCaseSensitive( caseSensitive );
991 991
992 992
993 static Event rev, nonrev; 993 static Event rev, nonrev;
994 if ( !inSearch ) { 994 if ( !inSearch ) {
995 rev.setStart( QDateTime(QDate(1960, 1, 1), QTime(0, 0, 0)) ); 995 rev.setStart( QDateTime(QDate(1960, 1, 1), QTime(0, 0, 0)) );
996 nonrev.setStart( rev.start() ); 996 nonrev.setStart( rev.start() );
997 inSearch = true; 997 inSearch = true;
998 } 998 }
999 static QDate searchDate = dt; 999 static QDate searchDate = dt;
1000 // if true at the end we will start at the begin again and afterwards
1001 // we will emit string not found
1000 static bool wrapAround = true; 1002 static bool wrapAround = true;
1001 bool candidtate; 1003 bool candidtate;
1002 candidtate = false; 1004 candidtate = false;
1003 1005
1004 QValueList<Event> repeats = db->getRawRepeats(); 1006 QValueList<Event> repeats = db->getRawRepeats();
1005 1007
1006 // find the candidate for the first repeat that matches... 1008 // find the candidate for the first repeat that matches...
1009 // first check if there can ever be a match and then compute
1010 // the next occurence from start. See if this event is closer
1011 // to the beginning (start. next < dtEnd) and not smaller then the last
1012 // result. If we find a canditate we set the dtEnd to the time
1013 // of the ocurrence and rev to this occurence.
1014 // set wrap around to true because there might be more events coming
1015 // and we're not at the end.
1007 QValueListConstIterator<Event> it; 1016 QValueListConstIterator<Event> it;
1008 QDate start = dt; 1017 QDate start = dt;
1009 for ( it = repeats.begin(); it != repeats.end(); ++it ) { 1018 for ( it = repeats.begin(); it != repeats.end(); ++it ) {
1010 if ( catComp( (*it).categories(), category ) ) { 1019 if ( catComp( (*it).categories(), category ) ) {
1011 if ( (*it).match( r ) ) { 1020 if ( (*it).match( r ) ) {
1012 if ( nextOccurance( *it, start, next ) ) { 1021 if ( nextOccurance( *it, start, next ) ) {
1013 if ( next < dtEnd && !(next <= rev.start() ) ) { 1022 if ( next < dtEnd && !(next <= rev.start() ) ) {
1014 rev = *it; 1023 rev = *it;
1015 dtEnd = next; 1024 dtEnd = next;
1016 rev.setStart( next ); 1025 rev.setStart( next );
1017 candidtate = true; 1026 candidtate = true;
1018 wrapAround = true; 1027 wrapAround = true;
1019 } 1028 }
1020 } 1029 }
1021 } 1030 }
1022 } 1031 }
1023 } 1032 }
1024 1033
1025 // now the for first non repeat... 1034 // now the for first non repeat...
1035 // dtEnd is set by the previous iteration of repeatingEvents
1036 // check if we find a closer item. Also set dtEnd to find even
1037 // more close occurrence
1026 QValueList<Event> nonRepeats = db->getNonRepeatingEvents( dt, dtEnd.date() ); 1038 QValueList<Event> nonRepeats = db->getNonRepeatingEvents( dt, dtEnd.date() );
1027 qHeapSort( nonRepeats.begin(), nonRepeats.end() ); 1039 qHeapSort( nonRepeats.begin(), nonRepeats.end() );
1028 for ( it = nonRepeats.begin(); it != nonRepeats.end(); ++it ) { 1040 for ( it = nonRepeats.begin(); it != nonRepeats.end(); ++it ) {
1029 if ( catComp( (*it).categories(), category ) ) { 1041 if ( catComp( (*it).categories(), category ) ) {
1030 if ( (*it).start() < dtEnd ) { 1042 if ( (*it).start() < dtEnd ) {
1031 if ( (*it).match( r ) && !(*it <= nonrev) ) { 1043 if ( (*it).match( r ) && !(*it <= nonrev) ) {
1032 nonrev = *it; 1044 nonrev = *it;
1033 dtEnd = nonrev.start(); 1045 dtEnd = nonrev.start();
1034 candidtate = true; 1046 candidtate = true;
1035 wrapAround = true; 1047 wrapAround = true;
1036 break; 1048 break;
1037 } 1049 }
1038 } 1050 }
1039 } 1051 }
1040 } 1052 }
1041 if ( candidtate ) { 1053 if ( candidtate ) {
1042 dayView->setStartViewTime( dtEnd.time().hour() ); 1054 dayView->setStartViewTime( dtEnd.time().hour() );
1043 dayView->setDate( dtEnd.date().year(), dtEnd.date().month(), 1055 dayView->setDate( dtEnd.date().year(), dtEnd.date().month(),
1044 dtEnd.date().day() ); 1056 dtEnd.date().day() );
1045 } else { 1057 } else {
1046 if ( wrapAround ) { 1058 if ( wrapAround ) {
1047 emit signalWrapAround(); 1059 emit signalWrapAround();
1048 rev.setStart( QDateTime(QDate(1960, 1, 1), QTime(0, 0, 0)) ); 1060 rev.setStart( QDateTime(QDate(1960, 1, 1), QTime(0, 0, 0)) );
1049 nonrev.setStart( rev.start() ); 1061 nonrev.setStart( rev.start() );
1050 } else 1062 } else
1051 emit signalNotFound(); 1063 emit signalNotFound();
1052 wrapAround = !wrapAround; 1064 wrapAround = !wrapAround;
1053 } 1065 }
1054} 1066}
1055 1067
1056Event DateBookDBHack::eventByUID(int uid) { 1068Event DateBookDBHack::eventByUID(int uid) {
1057 1069
1058 // FIXME: Dirty Hacks to get hold of the private event lists 1070 // FIXME: Dirty Hacks to get hold of the private event lists
1059 QDate start; 1071 QDate start;
1060 QDate end=start.addDays(-1); 1072 QDate end=start.addDays(-1);
1061 QValueList<Event> myEventList=getNonRepeatingEvents(start,end); 1073 QValueList<Event> myEventList=getNonRepeatingEvents(start,end);
1062 QValueList<Event> myRepeatEvents=getRawRepeats(); 1074 QValueList<Event> myRepeatEvents=getRawRepeats();
1063 1075
1064 QValueList<Event>::ConstIterator it; 1076 QValueList<Event>::ConstIterator it;
1065 1077
1066 for (it = myEventList.begin(); it != myEventList.end(); it++) { 1078 for (it = myEventList.begin(); it != myEventList.end(); it++) {
1067 if ((*it).uid() == uid) return *it; 1079 if ((*it).uid() == uid) return *it;
1068 } 1080 }
1069 for (it = myRepeatEvents.begin(); it != myRepeatEvents.end(); it++) { 1081 for (it = myRepeatEvents.begin(); it != myRepeatEvents.end(); it++) {
1070 if ((*it).uid() == uid) return *it; 1082 if ((*it).uid() == uid) return *it;
1071 } 1083 }
1072 1084
1073 Event ev; 1085 Event ev;
1074 return ev; // return at least 1086 return ev; // return at least
1075} 1087}