summaryrefslogtreecommitdiff
authorhakan <hakan>2002-03-31 12:56:14 (UTC)
committer hakan <hakan>2002-03-31 12:56:14 (UTC)
commit7208583b0b7ff339e6019b188332d8bcb8f30973 (patch) (unidiff)
tree4d0b064f1aa0a8553703af4f6e481393cf0ee13c
parenta386e428cbd6b468d4dbff5bf2df4fdba6df9b6e (diff)
downloadopie-7208583b0b7ff339e6019b188332d8bcb8f30973.zip
opie-7208583b0b7ff339e6019b188332d8bcb8f30973.tar.gz
opie-7208583b0b7ff339e6019b188332d8bcb8f30973.tar.bz2
Moved getEvent(uid) into some hack DateBookDBHack::eventByUID(uid) in the datbeook that might work as long as the QDate implementation are not chnaged.
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--core/pim/datebook/datebook.cpp25
-rw-r--r--core/pim/datebook/datebook.h7
-rw-r--r--library/datebookdb.cpp14
-rw-r--r--library/datebookdb.h1
4 files changed, 29 insertions, 18 deletions
diff --git a/core/pim/datebook/datebook.cpp b/core/pim/datebook/datebook.cpp
index 97c305c..c23129a 100644
--- a/core/pim/datebook/datebook.cpp
+++ b/core/pim/datebook/datebook.cpp
@@ -23,129 +23,129 @@
23#define QTOPIA_INTERNAL_FD 23#define QTOPIA_INTERNAL_FD
24 24
25#include "datebook.h" 25#include "datebook.h"
26#include "datebookday.h" 26#include "datebookday.h"
27#include "datebooksettings.h" 27#include "datebooksettings.h"
28#include "datebookweek.h" 28#include "datebookweek.h"
29#include "datebookweeklst.h" 29#include "datebookweeklst.h"
30#include "dateentryimpl.h" 30#include "dateentryimpl.h"
31 31
32#include <qpe/datebookmonth.h> 32#include <qpe/datebookmonth.h>
33#include <qpe/qpeapplication.h> 33#include <qpe/qpeapplication.h>
34#include <qpe/config.h> 34#include <qpe/config.h>
35#include <qpe/qpedebug.h> 35#include <qpe/qpedebug.h>
36#include <qpe/event.h> 36#include <qpe/event.h>
37#include <qpe/finddialog.h> 37#include <qpe/finddialog.h>
38#include <qpe/ir.h> 38#include <qpe/ir.h>
39#include <qpe/qpemenubar.h> 39#include <qpe/qpemenubar.h>
40#include <qpe/qpemessagebox.h> 40#include <qpe/qpemessagebox.h>
41#include <qpe/resource.h> 41#include <qpe/resource.h>
42#include <qpe/sound.h> 42#include <qpe/sound.h>
43#include <qpe/timestring.h> 43#include <qpe/timestring.h>
44#include <qpe/qpetoolbar.h> 44#include <qpe/qpetoolbar.h>
45#include <qpe/tzselect.h> 45#include <qpe/tzselect.h>
46#include <qpe/xmlreader.h> 46#include <qpe/xmlreader.h>
47 47
48#include <qaction.h> 48#include <qaction.h>
49#include <qcopchannel_qws.h> 49#include <qcopchannel_qws.h>
50#include <qdatetime.h> 50#include <qdatetime.h>
51#include <qdialog.h> 51#include <qdialog.h>
52#include <qfile.h> 52#include <qfile.h>
53#include <qlabel.h> 53#include <qlabel.h>
54#include <qlayout.h> 54#include <qlayout.h>
55#include <qmessagebox.h> 55#include <qmessagebox.h>
56#include <qpopupmenu.h> 56#include <qpopupmenu.h>
57#include <qpushbutton.h> 57#include <qpushbutton.h>
58#include <qtextcodec.h> 58#include <qtextcodec.h>
59#include <qtextstream.h> 59#include <qtextstream.h>
60#include <qtl.h> 60#include <qtl.h>
61#include <qwidgetstack.h> 61#include <qwidgetstack.h>
62#include <qwindowsystem_qws.h> 62#include <qwindowsystem_qws.h>
63 63
64#include <sys/stat.h> 64#include <sys/stat.h>
65#include <sys/types.h> 65#include <sys/types.h>
66#include <fcntl.h> 66#include <fcntl.h>
67#include <unistd.h> 67#include <unistd.h>
68 68
69#include <stdlib.h> 69#include <stdlib.h>
70 70
71#define DAY 1 71#define DAY 1
72#define WEEK 2 72#define WEEK 2
73#define WEEKLST 4 73#define WEEKLST 4
74#define MONTH 3 74#define MONTH 3
75 75
76 76
77DateBook::DateBook( QWidget *parent, const char *, WFlags f ) 77DateBook::DateBook( QWidget *parent, const char *, WFlags f )
78 : QMainWindow( parent, "datebook", f ), 78 : QMainWindow( parent, "datebook", f ),
79 aPreset( FALSE ), 79 aPreset( FALSE ),
80 presetTime( -1 ), 80 presetTime( -1 ),
81 startTime( 8 ), // an acceptable default 81 startTime( 8 ), // an acceptable default
82 syncing(FALSE), 82 syncing(FALSE),
83 inSearch(FALSE) 83 inSearch(FALSE)
84{ 84{
85 QTime t; 85 QTime t;
86 t.start(); 86 t.start();
87 db = new DateBookDB; 87 db = new DateBookDBHack;
88 qDebug("loading db t=%d", t.elapsed() ); 88 qDebug("loading db t=%d", t.elapsed() );
89 loadSettings(); 89 loadSettings();
90 setCaption( tr("Calendar") ); 90 setCaption( tr("Calendar") );
91 setIcon( Resource::loadPixmap( "datebook_icon" ) ); 91 setIcon( Resource::loadPixmap( "datebook_icon" ) );
92 92
93 setToolBarsMovable( FALSE ); 93 setToolBarsMovable( FALSE );
94 94
95 views = new QWidgetStack( this ); 95 views = new QWidgetStack( this );
96 setCentralWidget( views ); 96 setCentralWidget( views );
97 97
98 dayView = 0; 98 dayView = 0;
99 weekView = 0; 99 weekView = 0;
100 weekLstView = 0; 100 weekLstView = 0;
101 monthView = 0; 101 monthView = 0;
102 102
103 QPEToolBar *bar = new QPEToolBar( this ); 103 QPEToolBar *bar = new QPEToolBar( this );
104 bar->setHorizontalStretchable( TRUE ); 104 bar->setHorizontalStretchable( TRUE );
105 105
106 QPEMenuBar *mb = new QPEMenuBar( bar ); 106 QPEMenuBar *mb = new QPEMenuBar( bar );
107 mb->setMargin( 0 ); 107 mb->setMargin( 0 );
108 108
109 QPEToolBar *sub_bar = new QPEToolBar(this); 109 QPEToolBar *sub_bar = new QPEToolBar(this);
110 110
111 QPopupMenu *view = new QPopupMenu( this ); 111 QPopupMenu *view = new QPopupMenu( this );
112 QPopupMenu *settings = new QPopupMenu( this ); 112 QPopupMenu *settings = new QPopupMenu( this );
113 113
114 mb->insertItem( tr( "View" ), view ); 114 mb->insertItem( tr( "View" ), view );
115 mb->insertItem( tr( "Settings" ), settings ); 115 mb->insertItem( tr( "Settings" ), settings );
116 116
117 QActionGroup *g = new QActionGroup( this ); 117 QActionGroup *g = new QActionGroup( this );
118 g->setExclusive( TRUE ); 118 g->setExclusive( TRUE );
119 119
120 QAction *a = new QAction( tr( "New" ), Resource::loadPixmap( "new" ), 120 QAction *a = new QAction( tr( "New" ), Resource::loadPixmap( "new" ),
121 QString::null, 0, this, 0 ); 121 QString::null, 0, this, 0 );
122 connect( a, SIGNAL( activated() ), this, SLOT( fileNew() ) ); 122 connect( a, SIGNAL( activated() ), this, SLOT( fileNew() ) );
123 a->addTo( sub_bar ); 123 a->addTo( sub_bar );
124 124
125 a = new QAction( tr( "Today" ), Resource::loadPixmap( "to_day" ), QString::null, 0, g, 0 ); 125 a = new QAction( tr( "Today" ), Resource::loadPixmap( "to_day" ), QString::null, 0, g, 0 );
126 connect( a, SIGNAL( activated() ), this, SLOT( slotToday() ) ); 126 connect( a, SIGNAL( activated() ), this, SLOT( slotToday() ) );
127 a->addTo( sub_bar ); 127 a->addTo( sub_bar );
128 a->addTo( view ); 128 a->addTo( view );
129 129
130 a = new QAction( tr( "Day" ), Resource::loadPixmap( "day" ), QString::null, 0, g, 0 ); 130 a = new QAction( tr( "Day" ), Resource::loadPixmap( "day" ), QString::null, 0, g, 0 );
131 connect( a, SIGNAL( activated() ), this, SLOT( viewDay() ) ); 131 connect( a, SIGNAL( activated() ), this, SLOT( viewDay() ) );
132 a->addTo( sub_bar ); 132 a->addTo( sub_bar );
133 a->addTo( view ); 133 a->addTo( view );
134 a->setToggleAction( TRUE ); 134 a->setToggleAction( TRUE );
135 a->setOn( TRUE ); 135 a->setOn( TRUE );
136 dayAction = a; 136 dayAction = a;
137 137
138 a = new QAction( tr( "Week" ), Resource::loadPixmap( "week" ), QString::null, 0, g, 0 ); 138 a = new QAction( tr( "Week" ), Resource::loadPixmap( "week" ), QString::null, 0, g, 0 );
139 connect( a, SIGNAL( activated() ), this, SLOT( viewWeek() ) ); 139 connect( a, SIGNAL( activated() ), this, SLOT( viewWeek() ) );
140 a->addTo( sub_bar ); 140 a->addTo( sub_bar );
141 a->addTo( view ); 141 a->addTo( view );
142 a->setToggleAction( TRUE ); 142 a->setToggleAction( TRUE );
143 weekAction = a; 143 weekAction = a;
144 144
145 a = new QAction( tr( "WeekLst" ), Resource::loadPixmap( "weeklst" ), QString::null, 0, g, 0 ); 145 a = new QAction( tr( "WeekLst" ), Resource::loadPixmap( "weeklst" ), QString::null, 0, g, 0 );
146 connect( a, SIGNAL( activated() ), this, SLOT( viewWeekLst() ) ); 146 connect( a, SIGNAL( activated() ), this, SLOT( viewWeekLst() ) );
147 a->addTo( sub_bar ); 147 a->addTo( sub_bar );
148 a->addTo( view ); 148 a->addTo( view );
149 a->setToggleAction( TRUE ); 149 a->setToggleAction( TRUE );
150 weekLstAction = a; 150 weekLstAction = a;
151 151
@@ -172,129 +172,129 @@ DateBook::DateBook( QWidget *parent, const char *, WFlags f )
172 config.setGroup("Main"); 172 config.setGroup("Main");
173 int current=config.readNumEntry("defaultview", DAY); 173 int current=config.readNumEntry("defaultview", DAY);
174 174
175 QActionGroup *ag = new QActionGroup(this); 175 QActionGroup *ag = new QActionGroup(this);
176 a = new QAction( tr( "Day" ), QString::null, 0, 0, 0, true ); 176 a = new QAction( tr( "Day" ), QString::null, 0, 0, 0, true );
177 if (current==DAY) a->setOn(true), viewDay(); 177 if (current==DAY) a->setOn(true), viewDay();
178 ag->insert(a); 178 ag->insert(a);
179 a = new QAction( tr( "Week" ), QString::null, 0, 0, 0, true ); 179 a = new QAction( tr( "Week" ), QString::null, 0, 0, 0, true );
180 if (current==WEEK) a->setOn(true), viewWeek(); 180 if (current==WEEK) a->setOn(true), viewWeek();
181 ag->insert(a); 181 ag->insert(a);
182 a = new QAction( tr( "WeekLst" ), QString::null, 0, 0, 0, true ); 182 a = new QAction( tr( "WeekLst" ), QString::null, 0, 0, 0, true );
183 if (current==WEEKLST) a->setOn(true), viewWeekLst(); 183 if (current==WEEKLST) a->setOn(true), viewWeekLst();
184 ag->insert(a); 184 ag->insert(a);
185 a = new QAction( tr( "Month" ), QString::null, 0, 0, 0, true ); 185 a = new QAction( tr( "Month" ), QString::null, 0, 0, 0, true );
186 if (current==MONTH) a->setOn(true), viewMonth(); 186 if (current==MONTH) a->setOn(true), viewMonth();
187 ag->insert(a); 187 ag->insert(a);
188 188
189 ag->addTo(default_view); 189 ag->addTo(default_view);
190 connect(ag, SIGNAL( selected ( QAction * ) ), 190 connect(ag, SIGNAL( selected ( QAction * ) ),
191 this, SLOT( newDefaultView(QAction *) ) 191 this, SLOT( newDefaultView(QAction *) )
192 ); 192 );
193 193
194 connect( qApp, SIGNAL(clockChanged(bool)), 194 connect( qApp, SIGNAL(clockChanged(bool)),
195 this, SLOT(changeClock(bool)) ); 195 this, SLOT(changeClock(bool)) );
196 connect( qApp, SIGNAL(weekChanged(bool)), 196 connect( qApp, SIGNAL(weekChanged(bool)),
197 this, SLOT(changeWeek(bool)) ); 197 this, SLOT(changeWeek(bool)) );
198 198
199#if defined(Q_WS_QWS) && !defined(QT_NO_COP) 199#if defined(Q_WS_QWS) && !defined(QT_NO_COP)
200 connect( qApp, SIGNAL(appMessage(const QCString&, const QByteArray&)), 200 connect( qApp, SIGNAL(appMessage(const QCString&, const QByteArray&)),
201 this, SLOT(appMessage(const QCString&, const QByteArray&)) ); 201 this, SLOT(appMessage(const QCString&, const QByteArray&)) );
202#endif 202#endif
203 203
204 // listen on QPE/System 204 // listen on QPE/System
205#if defined(Q_WS_QWS) 205#if defined(Q_WS_QWS)
206#if !defined(QT_NO_COP) 206#if !defined(QT_NO_COP)
207 QCopChannel *channel = new QCopChannel( "QPE/System", this ); 207 QCopChannel *channel = new QCopChannel( "QPE/System", this );
208 connect( channel, SIGNAL(received(const QCString&, const QByteArray&)), 208 connect( channel, SIGNAL(received(const QCString&, const QByteArray&)),
209 this, SLOT(receive(const QCString&, const QByteArray&)) ); 209 this, SLOT(receive(const QCString&, const QByteArray&)) );
210 channel = new QCopChannel( "QPE/Datebook", this ); 210 channel = new QCopChannel( "QPE/Datebook", this );
211 connect( channel, SIGNAL(received(const QCString&, const QByteArray&)), 211 connect( channel, SIGNAL(received(const QCString&, const QByteArray&)),
212 this, SLOT(receive(const QCString&, const QByteArray&)) ); 212 this, SLOT(receive(const QCString&, const QByteArray&)) );
213 qDebug("olle\n"); 213 qDebug("olle\n");
214#endif 214#endif
215#endif 215#endif
216 216
217 qDebug("done t=%d", t.elapsed() ); 217 qDebug("done t=%d", t.elapsed() );
218 218
219} 219}
220 220
221void DateBook::receive( const QCString &msg, const QByteArray &data ) 221void DateBook::receive( const QCString &msg, const QByteArray &data )
222{ 222{
223 QDataStream stream( data, IO_ReadOnly ); 223 QDataStream stream( data, IO_ReadOnly );
224 if ( msg == "timeChange(QString)" ) { 224 if ( msg == "timeChange(QString)" ) {
225 // update active view! 225 // update active view!
226 if ( dayAction->isOn() ) 226 if ( dayAction->isOn() )
227 viewDay(); 227 viewDay();
228 else if ( weekAction->isOn() ) 228 else if ( weekAction->isOn() )
229 viewWeek(); 229 viewWeek();
230 else if ( monthAction->isOn() ) 230 else if ( monthAction->isOn() )
231 viewMonth(); 231 viewMonth();
232 } 232 }
233 else if (msg == "editEvent(int)") { 233 else if (msg == "editEvent(int)") {
234 int uid; 234 int uid;
235 stream >> uid; 235 stream >> uid;
236 Event e=db->getEvent(uid); 236 Event e=db->eventByUID(uid);
237 editEvent(e); 237 editEvent(e);
238 } 238 }
239} 239}
240 240
241DateBook::~DateBook() 241DateBook::~DateBook()
242{ 242{
243} 243}
244 244
245void DateBook::slotSettings() 245void DateBook::slotSettings()
246{ 246{
247 DateBookSettings frmSettings( ampm, this ); 247 DateBookSettings frmSettings( ampm, this );
248 frmSettings.setStartTime( startTime ); 248 frmSettings.setStartTime( startTime );
249 frmSettings.setAlarmPreset( aPreset, presetTime ); 249 frmSettings.setAlarmPreset( aPreset, presetTime );
250#if defined (Q_WS_QWS) || defined(_WS_QWS_) 250#if defined (Q_WS_QWS) || defined(_WS_QWS_)
251 frmSettings.showMaximized(); 251 frmSettings.showMaximized();
252#endif 252#endif
253 253
254 if ( frmSettings.exec() ) { 254 if ( frmSettings.exec() ) {
255 aPreset = frmSettings.alarmPreset(); 255 aPreset = frmSettings.alarmPreset();
256 presetTime = frmSettings.presetTime(); 256 presetTime = frmSettings.presetTime();
257 startTime = frmSettings.startTime(); 257 startTime = frmSettings.startTime();
258 if ( dayView ) 258 if ( dayView )
259 dayView->setStartViewTime( startTime ); 259 dayView->setStartViewTime( startTime );
260 if ( weekView ) 260 if ( weekView )
261 weekView->setStartViewTime( startTime ); 261 weekView->setStartViewTime( startTime );
262 saveSettings(); 262 saveSettings();
263 263
264 // make the change obvious 264 // make the change obvious
265 if ( views->visibleWidget() ) { 265 if ( views->visibleWidget() ) {
266 if ( views->visibleWidget() == dayView ) 266 if ( views->visibleWidget() == dayView )
267 dayView->redraw(); 267 dayView->redraw();
268 else if ( views->visibleWidget() == weekView ) 268 else if ( views->visibleWidget() == weekView )
269 weekView->redraw(); 269 weekView->redraw();
270 } 270 }
271 } 271 }
272} 272}
273 273
274void DateBook::fileNew() 274void DateBook::fileNew()
275{ 275{
276 slotNewEventFromKey(""); 276 slotNewEventFromKey("");
277} 277}
278 278
279QString DateBook::checkEvent(const Event &e) 279QString DateBook::checkEvent(const Event &e)
280{ 280{
281 /* check if overlaps with itself */ 281 /* check if overlaps with itself */
282 bool checkFailed = FALSE; 282 bool checkFailed = FALSE;
283 283
284 /* check the next 12 repeats. should catch most problems */ 284 /* check the next 12 repeats. should catch most problems */
285 QDate current_date = e.start().date(); 285 QDate current_date = e.start().date();
286 Event previous = e; 286 Event previous = e;
287 for(int i = 0; i < 12; i++) 287 for(int i = 0; i < 12; i++)
288 { 288 {
289 QDateTime next; 289 QDateTime next;
290 if (!nextOccurance(previous, current_date.addDays(1), next)) { 290 if (!nextOccurance(previous, current_date.addDays(1), next)) {
291 break; // no more repeats 291 break; // no more repeats
292 } 292 }
293 if(next < previous.end()) { 293 if(next < previous.end()) {
294 checkFailed = TRUE; 294 checkFailed = TRUE;
295 break; 295 break;
296 } 296 }
297 current_date = next.date(); 297 current_date = next.date();
298 } 298 }
299 299
300 if(checkFailed) 300 if(checkFailed)
@@ -904,64 +904,85 @@ void DateBook::slotDoFind( const QString& txt, const QDate &dt,
904 if ( !inSearch ) { 904 if ( !inSearch ) {
905 rev.setStart( QDateTime(QDate(1960, 1, 1), QTime(0, 0, 0)) ); 905 rev.setStart( QDateTime(QDate(1960, 1, 1), QTime(0, 0, 0)) );
906 nonrev.setStart( rev.start() ); 906 nonrev.setStart( rev.start() );
907 inSearch = true; 907 inSearch = true;
908 } 908 }
909 static QDate searchDate = dt; 909 static QDate searchDate = dt;
910 static bool wrapAround = true; 910 static bool wrapAround = true;
911 bool candidtate; 911 bool candidtate;
912 candidtate = false; 912 candidtate = false;
913 913
914 QValueList<Event> repeats = db->getRawRepeats(); 914 QValueList<Event> repeats = db->getRawRepeats();
915 915
916 // find the candidate for the first repeat that matches... 916 // find the candidate for the first repeat that matches...
917 QValueListConstIterator<Event> it; 917 QValueListConstIterator<Event> it;
918 QDate start = dt; 918 QDate start = dt;
919 for ( it = repeats.begin(); it != repeats.end(); ++it ) { 919 for ( it = repeats.begin(); it != repeats.end(); ++it ) {
920 if ( catComp( (*it).categories(), category ) ) { 920 if ( catComp( (*it).categories(), category ) ) {
921 while ( nextOccurance( *it, start, next ) ) { 921 while ( nextOccurance( *it, start, next ) ) {
922 if ( next < dtEnd ) { 922 if ( next < dtEnd ) {
923 if ( (*it).match( r ) && !(next <= rev.start()) ) { 923 if ( (*it).match( r ) && !(next <= rev.start()) ) {
924 rev = *it; 924 rev = *it;
925 dtEnd = next; 925 dtEnd = next;
926 rev.setStart( next ); 926 rev.setStart( next );
927 candidtate = true; 927 candidtate = true;
928 wrapAround = true; 928 wrapAround = true;
929 start = dt; 929 start = dt;
930 break; 930 break;
931 } else 931 } else
932 start = next.date().addDays( 1 ); 932 start = next.date().addDays( 1 );
933 } 933 }
934 } 934 }
935 } 935 }
936 } 936 }
937 937
938 // now the for first non repeat... 938 // now the for first non repeat...
939 QValueList<Event> nonRepeats = db->getNonRepeatingEvents( dt, dtEnd.date() ); 939 QValueList<Event> nonRepeats = db->getNonRepeatingEvents( dt, dtEnd.date() );
940 qHeapSort( nonRepeats.begin(), nonRepeats.end() ); 940 qHeapSort( nonRepeats.begin(), nonRepeats.end() );
941 for ( it = nonRepeats.begin(); it != nonRepeats.end(); ++it ) { 941 for ( it = nonRepeats.begin(); it != nonRepeats.end(); ++it ) {
942 if ( catComp( (*it).categories(), category ) ) { 942 if ( catComp( (*it).categories(), category ) ) {
943 if ( (*it).start() < dtEnd ) { 943 if ( (*it).start() < dtEnd ) {
944 if ( (*it).match( r ) && !(*it <= nonrev) ) { 944 if ( (*it).match( r ) && !(*it <= nonrev) ) {
945 nonrev = *it; 945 nonrev = *it;
946 dtEnd = nonrev.start(); 946 dtEnd = nonrev.start();
947 candidtate = true; 947 candidtate = true;
948 wrapAround = true; 948 wrapAround = true;
949 break; 949 break;
950 } 950 }
951 } 951 }
952 } 952 }
953 } 953 }
954 if ( candidtate ) { 954 if ( candidtate ) {
955 dayView->setStartViewTime( dtEnd.time().hour() ); 955 dayView->setStartViewTime( dtEnd.time().hour() );
956 dayView->setDate( dtEnd.date().year(), dtEnd.date().month(), 956 dayView->setDate( dtEnd.date().year(), dtEnd.date().month(),
957 dtEnd.date().day() ); 957 dtEnd.date().day() );
958 } else { 958 } else {
959 if ( wrapAround ) { 959 if ( wrapAround ) {
960 emit signalWrapAround(); 960 emit signalWrapAround();
961 rev.setStart( QDateTime(QDate(1960, 1, 1), QTime(0, 0, 0)) ); 961 rev.setStart( QDateTime(QDate(1960, 1, 1), QTime(0, 0, 0)) );
962 nonrev.setStart( rev.start() ); 962 nonrev.setStart( rev.start() );
963 } else 963 } else
964 emit signalNotFound(); 964 emit signalNotFound();
965 wrapAround = !wrapAround; 965 wrapAround = !wrapAround;
966 } 966 }
967} 967}
968
969Event DateBookDBHack::eventByUID(int uid) {
970
971 // FIXME: Dirty Hacks to get hold of the private event lists
972 QDate start;
973 QDate end=start.addDays(-1);
974 QValueList<Event> myEventList=getNonRepeatingEvents(start,end);
975 QValueList<Event> myRepeatEvents=getRawRepeats();
976
977 QValueList<Event>::ConstIterator it;
978
979 for (it = myEventList.begin(); it != myEventList.end(); it++) {
980 if ((*it).uid() == uid) return *it;
981 }
982 for (it = myRepeatEvents.begin(); it != myRepeatEvents.end(); it++) {
983 if ((*it).uid() == uid) return *it;
984 }
985
986 qDebug("Event not found: uid=%d\n", uid);
987}
988
diff --git a/core/pim/datebook/datebook.h b/core/pim/datebook/datebook.h
index 2ffcdbe..d1fe90d 100644
--- a/core/pim/datebook/datebook.h
+++ b/core/pim/datebook/datebook.h
@@ -1,121 +1,126 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved. 2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3** 3**
4** This file is part of Qtopia Environment. 4** This file is part of Qtopia Environment.
5** 5**
6** This file may be distributed and/or modified under the terms of the 6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software 7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the 8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file. 9** packaging of this file.
10** 10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13** 13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information. 14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15** 15**
16** Contact info@trolltech.com if any conditions of this licensing are 16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you. 17** not clear to you.
18** 18**
19**********************************************************************/ 19**********************************************************************/
20#ifndef DATEBOOK_H 20#ifndef DATEBOOK_H
21#define DATEBOOK_H 21#define DATEBOOK_H
22 22
23#include <qpe/datebookdb.h> 23#include <qpe/datebookdb.h>
24 24
25#include <qmainwindow.h> 25#include <qmainwindow.h>
26 26
27class QAction; 27class QAction;
28class QWidgetStack; 28class QWidgetStack;
29class DateBookDay; 29class DateBookDay;
30class DateBookWeek; 30class DateBookWeek;
31class DateBookWeekLst; 31class DateBookWeekLst;
32class DateBookMonth; 32class DateBookMonth;
33class Event; 33class Event;
34class QDate; 34class QDate;
35class Ir; 35class Ir;
36 36
37class DateBookDBHack : public DateBookDB {
38 public:
39 Event eventByUID(int id);
40};
41
37class DateBook : public QMainWindow 42class DateBook : public QMainWindow
38{ 43{
39 Q_OBJECT 44 Q_OBJECT
40 45
41public: 46public:
42 DateBook( QWidget *parent = 0, const char *name = 0, WFlags f = 0 ); 47 DateBook( QWidget *parent = 0, const char *name = 0, WFlags f = 0 );
43 ~DateBook(); 48 ~DateBook();
44 49
45signals: 50signals:
46 void newEvent(); 51 void newEvent();
47 void signalNotFound(); 52 void signalNotFound();
48 void signalWrapAround(); 53 void signalWrapAround();
49 54
50protected: 55protected:
51 QDate currentDate(); 56 QDate currentDate();
52 void timerEvent( QTimerEvent *e ); 57 void timerEvent( QTimerEvent *e );
53 void closeEvent( QCloseEvent *e ); 58 void closeEvent( QCloseEvent *e );
54 59
55 void view(int v, const QDate &d); 60 void view(int v, const QDate &d);
56 61
57public slots: 62public slots:
58 void flush(); 63 void flush();
59 void reload(); 64 void reload();
60 65
61private slots: 66private slots:
62 void fileNew(); 67 void fileNew();
63 void slotNewEntry(const QDateTime &start, const QDateTime &end, const QString &str); 68 void slotNewEntry(const QDateTime &start, const QDateTime &end, const QString &str);
64 void slotSettings(); 69 void slotSettings();
65 void newDefaultView(QAction *a); 70 void newDefaultView(QAction *a);
66 void slotToday();// view today 71 void slotToday();// view today
67 void changeClock( bool newClock ); 72 void changeClock( bool newClock );
68 void changeWeek( bool newDay ); 73 void changeWeek( bool newDay );
69 void appMessage(const QCString& msg, const QByteArray& data); 74 void appMessage(const QCString& msg, const QByteArray& data);
70 // handle key events in the day view... 75 // handle key events in the day view...
71 void slotNewEventFromKey( const QString &str ); 76 void slotNewEventFromKey( const QString &str );
72 void slotFind(); 77 void slotFind();
73 void slotDoFind( const QString &, const QDate &, bool, bool, int ); 78 void slotDoFind( const QString &, const QDate &, bool, bool, int );
74 79
75 void viewDefault(const QDate &d); 80 void viewDefault(const QDate &d);
76 81
77 void viewDay(); 82 void viewDay();
78 void viewWeek(); 83 void viewWeek();
79 void viewWeekLst(); 84 void viewWeekLst();
80 void viewMonth(); 85 void viewMonth();
81 86
82 void showDay( int y, int m, int d ); 87 void showDay( int y, int m, int d );
83 88
84 void editEvent( const Event &e ); 89 void editEvent( const Event &e );
85 void removeEvent( const Event &e ); 90 void removeEvent( const Event &e );
86 91
87 void receive( const QCString &msg, const QByteArray &data ); 92 void receive( const QCString &msg, const QByteArray &data );
88 void setDocument( const QString & ); 93 void setDocument( const QString & );
89 void beamEvent( const Event &e ); 94 void beamEvent( const Event &e );
90 void beamDone( Ir *ir ); 95 void beamDone( Ir *ir );
91 96
92private: 97private:
93 void addEvent( const Event &e ); 98 void addEvent( const Event &e );
94 void initDay(); 99 void initDay();
95 void initWeek(); 100 void initWeek();
96 void initWeekLst(); 101 void initWeekLst();
97 void initMonth(); 102 void initMonth();
98 void loadSettings(); 103 void loadSettings();
99 void saveSettings(); 104 void saveSettings();
100 105
101private: 106private:
102 DateBookDB *db; 107 DateBookDBHack *db;
103 QWidgetStack *views; 108 QWidgetStack *views;
104 DateBookDay *dayView; 109 DateBookDay *dayView;
105 DateBookWeek *weekView; 110 DateBookWeek *weekView;
106 DateBookMonth *monthView; 111 DateBookMonth *monthView;
107 DateBookWeekLst *weekLstView; 112 DateBookWeekLst *weekLstView;
108 QAction *dayAction, *weekAction, *weekLstAction, *monthAction; 113 QAction *dayAction, *weekAction, *weekLstAction, *monthAction;
109 bool aPreset; // have everything set to alarm? 114 bool aPreset; // have everything set to alarm?
110 int presetTime; // the standard time for the alarm 115 int presetTime; // the standard time for the alarm
111 int startTime; 116 int startTime;
112 bool ampm; 117 bool ampm;
113 bool onMonday; 118 bool onMonday;
114 119
115 bool syncing; 120 bool syncing;
116 bool inSearch; 121 bool inSearch;
117 122
118 QString checkEvent(const Event &); 123 QString checkEvent(const Event &);
119}; 124};
120 125
121#endif 126#endif
diff --git a/library/datebookdb.cpp b/library/datebookdb.cpp
index da5a797..2ac9a0c 100644
--- a/library/datebookdb.cpp
+++ b/library/datebookdb.cpp
@@ -526,142 +526,128 @@ QValueList<EffectiveEvent> DateBookDB::getEffectiveEvents( const QDate &from,
526 if(repeat.date() > to) 526 if(repeat.date() > to)
527 break; 527 break;
528 effEv.setDate( repeat.date() ); 528 effEv.setDate( repeat.date() );
529 if ((*it).type() == Event::AllDay) { 529 if ((*it).type() == Event::AllDay) {
530 effEv.setStart( QTime(0,0,0) ); 530 effEv.setStart( QTime(0,0,0) );
531 effEv.setEnd( QTime(23,59,59) ); 531 effEv.setEnd( QTime(23,59,59) );
532 } else { 532 } else {
533 /* we only occur by days, not hours/minutes/seconds. Hence 533 /* we only occur by days, not hours/minutes/seconds. Hence
534 the actual end and start times will be the same for 534 the actual end and start times will be the same for
535 every repeated event. For multi day events this is 535 every repeated event. For multi day events this is
536 fixed up later if on wronge day span */ 536 fixed up later if on wronge day span */
537 effEv.setStart( (*it).start().time() ); 537 effEv.setStart( (*it).start().time() );
538 effEv.setEnd( (*it).end().time() ); 538 effEv.setEnd( (*it).end().time() );
539 } 539 }
540 if ( duration != 0 ) { 540 if ( duration != 0 ) {
541 // multi-day repeating events 541 // multi-day repeating events
542 QDate sub_it = QMAX( repeat.date(), from ); 542 QDate sub_it = QMAX( repeat.date(), from );
543 QDate startDate = repeat.date(); 543 QDate startDate = repeat.date();
544 QDate endDate = startDate.addDays( duration ); 544 QDate endDate = startDate.addDays( duration );
545 545
546 while ( sub_it <= endDate && sub_it <= to ) { 546 while ( sub_it <= endDate && sub_it <= to ) {
547 EffectiveEvent tmpEffEv = effEv; 547 EffectiveEvent tmpEffEv = effEv;
548 Event tmpEv = *it; 548 Event tmpEv = *it;
549 tmpEffEv.setEvent( tmpEv ); 549 tmpEffEv.setEvent( tmpEv );
550 550
551 if ( sub_it != startDate ) 551 if ( sub_it != startDate )
552 tmpEffEv.setStart( QTime(0,0,0) ); 552 tmpEffEv.setStart( QTime(0,0,0) );
553 if ( sub_it != endDate ) 553 if ( sub_it != endDate )
554 tmpEffEv.setEnd( QTime(23,59,59) ); 554 tmpEffEv.setEnd( QTime(23,59,59) );
555 tmpEffEv.setDate( sub_it ); 555 tmpEffEv.setDate( sub_it );
556 tmpEffEv.setEffectiveDates( startDate, endDate ); 556 tmpEffEv.setEffectiveDates( startDate, endDate );
557 tmpList.append( tmpEffEv ); 557 tmpList.append( tmpEffEv );
558 sub_it = sub_it.addDays( 1 ); 558 sub_it = sub_it.addDays( 1 );
559 } 559 }
560 itDate = endDate; 560 itDate = endDate;
561 } else { 561 } else {
562 Event tmpEv = *it; 562 Event tmpEv = *it;
563 effEv.setEvent( tmpEv ); 563 effEv.setEvent( tmpEv );
564 tmpList.append( effEv ); 564 tmpList.append( effEv );
565 itDate = repeat.date().addDays( 1 ); 565 itDate = repeat.date().addDays( 1 );
566 } 566 }
567 } 567 }
568 } 568 }
569 569
570 qHeapSort( tmpList ); 570 qHeapSort( tmpList );
571 return tmpList; 571 return tmpList;
572} 572}
573 573
574QValueList<EffectiveEvent> DateBookDB::getEffectiveEvents( const QDateTime &dt) 574QValueList<EffectiveEvent> DateBookDB::getEffectiveEvents( const QDateTime &dt)
575{ 575{
576 QValueList<EffectiveEvent> day = getEffectiveEvents(dt.date(), dt.date()); 576 QValueList<EffectiveEvent> day = getEffectiveEvents(dt.date(), dt.date());
577 QValueListConstIterator<EffectiveEvent> it; 577 QValueListConstIterator<EffectiveEvent> it;
578 QValueList<EffectiveEvent> tmpList; 578 QValueList<EffectiveEvent> tmpList;
579 QDateTime dtTmp; 579 QDateTime dtTmp;
580 580
581 for (it = day.begin(); it != day.end(); ++it ) { 581 for (it = day.begin(); it != day.end(); ++it ) {
582 dtTmp = QDateTime( (*it).date(), (*it).start() ); 582 dtTmp = QDateTime( (*it).date(), (*it).start() );
583 // at the moment we don't have second granularity, be nice about that.. 583 // at the moment we don't have second granularity, be nice about that..
584 if ( QABS(dt.secsTo(dtTmp)) < 60 ) 584 if ( QABS(dt.secsTo(dtTmp)) < 60 )
585 tmpList.append( *it ); 585 tmpList.append( *it );
586 } 586 }
587 return tmpList; 587 return tmpList;
588} 588}
589 589
590Event DateBookDB::getEvent( int uid ) {
591 QValueList<Event>::ConstIterator it;
592
593 for (it = eventList.begin(); it != eventList.end(); it++) {
594 if ((*it).uid() == uid) return *it;
595 }
596 for (it = repeatEvents.begin(); it != repeatEvents.end(); it++) {
597 if ((*it).uid() == uid) return *it;
598 }
599
600 qDebug("Event not found: uid=%d\n", uid);
601}
602
603
604void DateBookDB::addEvent( const Event &ev, bool doalarm ) 590void DateBookDB::addEvent( const Event &ev, bool doalarm )
605{ 591{
606 // write to the journal... 592 // write to the journal...
607 saveJournalEntry( ev, ACTION_ADD, -1, false ); 593 saveJournalEntry( ev, ACTION_ADD, -1, false );
608 addJFEvent( ev, doalarm ); 594 addJFEvent( ev, doalarm );
609 d->clean = false; 595 d->clean = false;
610} 596}
611 597
612void DateBookDB::addJFEvent( const Event &ev, bool doalarm ) 598void DateBookDB::addJFEvent( const Event &ev, bool doalarm )
613{ 599{
614 if ( doalarm && ev.hasAlarm() ) 600 if ( doalarm && ev.hasAlarm() )
615 addEventAlarm( ev ); 601 addEventAlarm( ev );
616 if ( ev.hasRepeat() ) 602 if ( ev.hasRepeat() )
617 repeatEvents.append( ev ); 603 repeatEvents.append( ev );
618 else 604 else
619 eventList.append( ev ); 605 eventList.append( ev );
620} 606}
621 607
622void DateBookDB::editEvent( const Event &old, Event &editedEv ) 608void DateBookDB::editEvent( const Event &old, Event &editedEv )
623{ 609{
624 int oldIndex=0; 610 int oldIndex=0;
625 bool oldHadRepeat = old.hasRepeat(); 611 bool oldHadRepeat = old.hasRepeat();
626 Event orig; 612 Event orig;
627 613
628 // write to the journal... 614 // write to the journal...
629 if ( oldHadRepeat ) { 615 if ( oldHadRepeat ) {
630 if ( origRepeat( old, orig ) ) // should work always... 616 if ( origRepeat( old, orig ) ) // should work always...
631 oldIndex = repeatEvents.findIndex( orig ); 617 oldIndex = repeatEvents.findIndex( orig );
632 } else 618 } else
633 oldIndex = eventList.findIndex( old ); 619 oldIndex = eventList.findIndex( old );
634 saveJournalEntry( editedEv, ACTION_REPLACE, oldIndex, oldHadRepeat ); 620 saveJournalEntry( editedEv, ACTION_REPLACE, oldIndex, oldHadRepeat );
635 621
636 // Delete old event 622 // Delete old event
637 if ( old.hasAlarm() ) 623 if ( old.hasAlarm() )
638 delEventAlarm( old ); 624 delEventAlarm( old );
639 if ( oldHadRepeat ) { 625 if ( oldHadRepeat ) {
640 if ( editedEv.hasRepeat() ) { // This mean that origRepeat was run above and 626 if ( editedEv.hasRepeat() ) { // This mean that origRepeat was run above and
641 // orig is initialized 627 // orig is initialized
642 // assumption, when someone edits a repeating event, they 628 // assumption, when someone edits a repeating event, they
643 // want to change them all, maybe not perfect, but it works 629 // want to change them all, maybe not perfect, but it works
644 // for the moment... 630 // for the moment...
645 repeatEvents.remove( orig ); 631 repeatEvents.remove( orig );
646 } else 632 } else
647 removeRepeat( old ); 633 removeRepeat( old );
648 } else { 634 } else {
649 QValueList<Event>::Iterator it = eventList.find( old ); 635 QValueList<Event>::Iterator it = eventList.find( old );
650 if ( it != eventList.end() ) 636 if ( it != eventList.end() )
651 eventList.remove( it ); 637 eventList.remove( it );
652 } 638 }
653 639
654 // Add new event 640 // Add new event
655 if ( editedEv.hasAlarm() ) 641 if ( editedEv.hasAlarm() )
656 addEventAlarm( editedEv ); 642 addEventAlarm( editedEv );
657 if ( editedEv.hasRepeat() ) 643 if ( editedEv.hasRepeat() )
658 repeatEvents.append( editedEv ); 644 repeatEvents.append( editedEv );
659 else 645 else
660 eventList.append( editedEv ); 646 eventList.append( editedEv );
661 647
662 d->clean = false; 648 d->clean = false;
663} 649}
664 650
665void DateBookDB::removeEvent( const Event &ev ) 651void DateBookDB::removeEvent( const Event &ev )
666{ 652{
667 // write to the journal... 653 // write to the journal...
diff --git a/library/datebookdb.h b/library/datebookdb.h
index e4c251c..0add028 100644
--- a/library/datebookdb.h
+++ b/library/datebookdb.h
@@ -1,88 +1,87 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved. 2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3** 3**
4** This file is part of Qtopia Environment. 4** This file is part of Qtopia Environment.
5** 5**
6** This file may be distributed and/or modified under the terms of the 6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software 7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the 8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file. 9** packaging of this file.
10** 10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13** 13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information. 14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15** 15**
16** Contact info@trolltech.com if any conditions of this licensing are 16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you. 17** not clear to you.
18** 18**
19**********************************************************************/ 19**********************************************************************/
20 20
21#ifndef DATEBOOKDB_H 21#ifndef DATEBOOKDB_H
22#define DATEBOOKDB_H 22#define DATEBOOKDB_H
23 23
24#include <qdatetime.h> 24#include <qdatetime.h>
25#include <qfile.h> 25#include <qfile.h>
26#include <qvaluelist.h> 26#include <qvaluelist.h>
27#include <qpe/event.h> 27#include <qpe/event.h>
28 28
29// journal actions... 29// journal actions...
30enum journal_action { ACTION_ADD, ACTION_REMOVE, ACTION_REPLACE }; 30enum journal_action { ACTION_ADD, ACTION_REMOVE, ACTION_REPLACE };
31 31
32class DateBookDBPrivate; 32class DateBookDBPrivate;
33class DateBookDB 33class DateBookDB
34{ 34{
35public: 35public:
36 DateBookDB(); 36 DateBookDB();
37 ~DateBookDB(); 37 ~DateBookDB();
38 38
39 // very depreciated now!!! 39 // very depreciated now!!!
40 QValueList<Event> getEvents( const QDate &from, const QDate &to ); 40 QValueList<Event> getEvents( const QDate &from, const QDate &to );
41 QValueList<Event> getEvents( const QDateTime &start ); 41 QValueList<Event> getEvents( const QDateTime &start );
42 42
43 // USE THESE!!! 43 // USE THESE!!!
44 QValueList<EffectiveEvent> getEffectiveEvents( const QDate &from, 44 QValueList<EffectiveEvent> getEffectiveEvents( const QDate &from,
45 const QDate &to ); 45 const QDate &to );
46 QValueList<EffectiveEvent> getEffectiveEvents( const QDateTime &start ); 46 QValueList<EffectiveEvent> getEffectiveEvents( const QDateTime &start );
47 Event getEvent( int uid );
48 47
49 QValueList<Event> getRawRepeats() const; 48 QValueList<Event> getRawRepeats() const;
50 QValueList<Event> getNonRepeatingEvents( const QDate &from, 49 QValueList<Event> getNonRepeatingEvents( const QDate &from,
51 const QDate &to ) const; 50 const QDate &to ) const;
52 51
53 // Use these when dealing with adding removing events... 52 // Use these when dealing with adding removing events...
54 void addEvent( const Event &ev, bool doalarm=TRUE ); 53 void addEvent( const Event &ev, bool doalarm=TRUE );
55 void removeEvent( const Event &ev ); 54 void removeEvent( const Event &ev );
56 void editEvent( const Event &old, Event &ev ); 55 void editEvent( const Event &old, Event &ev );
57 // add/remove event without journaling ( these ended up in public by accident, never 56 // add/remove event without journaling ( these ended up in public by accident, never
58 // use them unless you know what you are doing...), 57 // use them unless you know what you are doing...),
59 // please put them in private if we ever can change the class... 58 // please put them in private if we ever can change the class...
60 void addJFEvent( const Event &ev, bool doalarm=TRUE ); 59 void addJFEvent( const Event &ev, bool doalarm=TRUE );
61 void removeJFEvent( const Event &ev ); 60 void removeJFEvent( const Event &ev );
62 61
63 bool save(); 62 bool save();
64 void reload(); 63 void reload();
65private: 64private:
66 //find the real repeat... 65 //find the real repeat...
67 bool origRepeat( const Event &ev, Event &orig ) const; 66 bool origRepeat( const Event &ev, Event &orig ) const;
68 bool removeRepeat( const Event &ev ); 67 bool removeRepeat( const Event &ev );
69 void init(); 68 void init();
70 void loadFile( const QString &strFile ); 69 void loadFile( const QString &strFile );
71 // depreciated... 70 // depreciated...
72 void saveJournalEntry( const Event &ev, journal_action action ); 71 void saveJournalEntry( const Event &ev, journal_action action );
73 // new version, uncomment the "= -1" when we remove the above 72 // new version, uncomment the "= -1" when we remove the above
74 // function.. 73 // function..
75 bool saveJournalEntry( const Event &ev, journal_action action, 74 bool saveJournalEntry( const Event &ev, journal_action action,
76 int key/* = -1*/, bool origHadRepeat = false ); 75 int key/* = -1*/, bool origHadRepeat = false );
77 76
78 QValueList<Event> eventList; // non-repeating events... 77 QValueList<Event> eventList; // non-repeating events...
79 QValueList<Event> repeatEvents; // the repeating events... 78 QValueList<Event> repeatEvents; // the repeating events...
80 DateBookDBPrivate *d; 79 DateBookDBPrivate *d;
81 QFile journalFile; 80 QFile journalFile;
82 81
83 intrecordIdMax; // ADDITION 82 intrecordIdMax; // ADDITION
84}; 83};
85 84
86/* helper functions, also useful to other apps. */ 85/* helper functions, also useful to other apps. */
87bool nextOccurance( const Event &e, const QDate &from, QDateTime &next); 86bool nextOccurance( const Event &e, const QDate &from, QDateTime &next);
88#endif 87#endif