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
@@ -904,172 +904,184 @@ void DateBook::slotNewEntry(const QDateTime &start, const QDateTime &end, const
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}