summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--core/pim/datebook/datebook.cpp4
1 files changed, 2 insertions, 2 deletions
diff --git a/core/pim/datebook/datebook.cpp b/core/pim/datebook/datebook.cpp
index 47be523..3e18374 100644
--- a/core/pim/datebook/datebook.cpp
+++ b/core/pim/datebook/datebook.cpp
@@ -88,1013 +88,1013 @@ DateBook::DateBook( QWidget *parent, const char *, WFlags f )
88 alarmCounter(0) 88 alarmCounter(0)
89{ 89{
90 bool needEvilHack= false; // if we need an Evil Hack 90 bool needEvilHack= false; // if we need an Evil Hack
91 QTime t; 91 QTime t;
92 t.start(); 92 t.start();
93 db = new DateBookDBHack; 93 db = new DateBookDBHack;
94 qDebug("loading db t=%d", t.elapsed() ); 94 qDebug("loading db t=%d", t.elapsed() );
95 loadSettings(); 95 loadSettings();
96 setCaption( tr("Calendar") ); 96 setCaption( tr("Calendar") );
97 setIcon( Resource::loadPixmap( "datebook_icon" ) ); 97 setIcon( Resource::loadPixmap( "datebook_icon" ) );
98 98
99 setToolBarsMovable( FALSE ); 99 setToolBarsMovable( FALSE );
100 100
101 views = new QWidgetStack( this ); 101 views = new QWidgetStack( this );
102 setCentralWidget( views ); 102 setCentralWidget( views );
103 103
104 dayView = 0; 104 dayView = 0;
105 weekView = 0; 105 weekView = 0;
106 weekLstView = 0; 106 weekLstView = 0;
107 monthView = 0; 107 monthView = 0;
108 108
109 QPEToolBar *bar = new QPEToolBar( this ); 109 QPEToolBar *bar = new QPEToolBar( this );
110 bar->setHorizontalStretchable( TRUE ); 110 bar->setHorizontalStretchable( TRUE );
111 111
112 QPEMenuBar *mb = new QPEMenuBar( bar ); 112 QPEMenuBar *mb = new QPEMenuBar( bar );
113 mb->setMargin( 0 ); 113 mb->setMargin( 0 );
114 114
115 QPEToolBar *sub_bar = new QPEToolBar(this); 115 QPEToolBar *sub_bar = new QPEToolBar(this);
116 116
117 QPopupMenu *view = new QPopupMenu( this ); 117 QPopupMenu *view = new QPopupMenu( this );
118 QPopupMenu *settings = new QPopupMenu( this ); 118 QPopupMenu *settings = new QPopupMenu( this );
119 119
120 mb->insertItem( tr( "View" ), view ); 120 mb->insertItem( tr( "View" ), view );
121 mb->insertItem( tr( "Settings" ), settings ); 121 mb->insertItem( tr( "Settings" ), settings );
122 122
123 QActionGroup *g = new QActionGroup( this ); 123 QActionGroup *g = new QActionGroup( this );
124 g->setExclusive( TRUE ); 124 g->setExclusive( TRUE );
125 125
126 QAction *a = new QAction( tr( "New" ), Resource::loadPixmap( "new" ), 126 QAction *a = new QAction( tr( "New" ), Resource::loadPixmap( "new" ),
127 QString::null, 0, this, 0 ); 127 QString::null, 0, this, 0 );
128 connect( a, SIGNAL( activated() ), this, SLOT( fileNew() ) ); 128 connect( a, SIGNAL( activated() ), this, SLOT( fileNew() ) );
129 a->addTo( sub_bar ); 129 a->addTo( sub_bar );
130 130
131 a = new QAction( tr( "Today" ), Resource::loadPixmap( "datebook/to_day" ), QString::null, 0, g, 0 ); 131 a = new QAction( tr( "Today" ), Resource::loadPixmap( "datebook/to_day" ), QString::null, 0, g, 0 );
132 connect( a, SIGNAL( activated() ), this, SLOT( slotToday() ) ); 132 connect( a, SIGNAL( activated() ), this, SLOT( slotToday() ) );
133 a->addTo( sub_bar ); 133 a->addTo( sub_bar );
134 a->addTo( view ); 134 a->addTo( view );
135 135
136 a = new QAction( tr( "Day" ), Resource::loadPixmap( "day" ), QString::null, 0, g, 0 ); 136 a = new QAction( tr( "Day" ), Resource::loadPixmap( "day" ), QString::null, 0, g, 0 );
137 connect( a, SIGNAL( activated() ), this, SLOT( viewDay() ) ); 137 connect( a, SIGNAL( activated() ), this, SLOT( viewDay() ) );
138 a->addTo( sub_bar ); 138 a->addTo( sub_bar );
139 a->addTo( view ); 139 a->addTo( view );
140 a->setToggleAction( TRUE ); 140 a->setToggleAction( TRUE );
141 a->setOn( TRUE ); 141 a->setOn( TRUE );
142 dayAction = a; 142 dayAction = a;
143 143
144 a = new QAction( tr( "Week" ), Resource::loadPixmap( "week" ), QString::null, 0, g, 0 ); 144 a = new QAction( tr( "Week" ), Resource::loadPixmap( "week" ), QString::null, 0, g, 0 );
145 connect( a, SIGNAL( activated() ), this, SLOT( viewWeek() ) ); 145 connect( a, SIGNAL( activated() ), this, SLOT( viewWeek() ) );
146 a->addTo( sub_bar ); 146 a->addTo( sub_bar );
147 a->addTo( view ); 147 a->addTo( view );
148 a->setToggleAction( TRUE ); 148 a->setToggleAction( TRUE );
149 weekAction = a; 149 weekAction = a;
150 150
151 a = new QAction( tr( "WeekLst" ), Resource::loadPixmap( "datebook/weeklst" ), QString::null, 0, g, 0 ); 151 a = new QAction( tr( "WeekLst" ), Resource::loadPixmap( "datebook/weeklst" ), QString::null, 0, g, 0 );
152 connect( a, SIGNAL( activated() ), this, SLOT( viewWeekLst() ) ); 152 connect( a, SIGNAL( activated() ), this, SLOT( viewWeekLst() ) );
153 a->addTo( sub_bar ); 153 a->addTo( sub_bar );
154 a->addTo( view ); 154 a->addTo( view );
155 a->setToggleAction( TRUE ); 155 a->setToggleAction( TRUE );
156 weekLstAction = a; 156 weekLstAction = a;
157 157
158 a = new QAction( tr( "Month" ), Resource::loadPixmap( "month" ), QString::null, 0, g, 0 ); 158 a = new QAction( tr( "Month" ), Resource::loadPixmap( "month" ), QString::null, 0, g, 0 );
159 connect( a, SIGNAL( activated() ), this, SLOT( viewMonth() ) ); 159 connect( a, SIGNAL( activated() ), this, SLOT( viewMonth() ) );
160 a->addTo( sub_bar ); 160 a->addTo( sub_bar );
161 a->addTo( view ); 161 a->addTo( view );
162 a->setToggleAction( TRUE ); 162 a->setToggleAction( TRUE );
163 monthAction = a; 163 monthAction = a;
164 164
165 a = new QAction( tr( "Find" ), Resource::loadPixmap( "mag" ), QString::null, 0, g, 0 ); 165 a = new QAction( tr( "Find" ), Resource::loadPixmap( "mag" ), QString::null, 0, g, 0 );
166 connect( a, SIGNAL(activated()), this, SLOT(slotFind()) ); 166 connect( a, SIGNAL(activated()), this, SLOT(slotFind()) );
167 a->addTo( sub_bar ); 167 a->addTo( sub_bar );
168 168
169 a = new QAction( tr( "Alarm and Start Time..." ), QString::null, 0, 0 ); 169 a = new QAction( tr( "Alarm and Start Time..." ), QString::null, 0, 0 );
170 connect( a, SIGNAL( activated() ), this, SLOT( slotSettings() ) ); 170 connect( a, SIGNAL( activated() ), this, SLOT( slotSettings() ) );
171 a->addTo( settings ); 171 a->addTo( settings );
172 172
173 QPopupMenu *default_view = new QPopupMenu(this); 173 QPopupMenu *default_view = new QPopupMenu(this);
174 settings->insertItem( tr( "Default View" ),default_view ); 174 settings->insertItem( tr( "Default View" ),default_view );
175 default_view->setCheckable(TRUE); 175 default_view->setCheckable(TRUE);
176 176
177 Config config("DateBook"); 177 Config config("DateBook");
178 config.setGroup("Main"); 178 config.setGroup("Main");
179 int current=config.readNumEntry("defaultview", DAY); 179 int current=config.readNumEntry("defaultview", DAY);
180 180
181 QActionGroup *ag = new QActionGroup(this); 181 QActionGroup *ag = new QActionGroup(this);
182 a = new QAction( tr( "Day" ), QString::null, 0, 0, 0, true ); 182 a = new QAction( tr( "Day" ), QString::null, 0, 0, 0, true );
183 if (current==DAY) a->setOn(true), viewDay(); 183 if (current==DAY) a->setOn(true), viewDay();
184 ag->insert(a); 184 ag->insert(a);
185 a = new QAction( tr( "Week" ), QString::null, 0, 0, 0, true ); 185 a = new QAction( tr( "Week" ), QString::null, 0, 0, 0, true );
186 if (current==WEEK) a->setOn(true), /*viewWeek(),*/ needEvilHack = true; 186 if (current==WEEK) a->setOn(true), /*viewWeek(),*/ needEvilHack = true;
187 ag->insert(a); 187 ag->insert(a);
188 a = new QAction( tr( "WeekLst" ), QString::null, 0, 0, 0, true ); 188 a = new QAction( tr( "WeekLst" ), QString::null, 0, 0, 0, true );
189 if (current==WEEKLST) a->setOn(true), viewWeekLst(); 189 if (current==WEEKLST) a->setOn(true), viewWeekLst();
190 ag->insert(a); 190 ag->insert(a);
191 a = new QAction( tr( "Month" ), QString::null, 0, 0, 0, true ); 191 a = new QAction( tr( "Month" ), QString::null, 0, 0, 0, true );
192 if (current==MONTH) a->setOn(true), viewMonth(); 192 if (current==MONTH) a->setOn(true), viewMonth();
193 ag->insert(a); 193 ag->insert(a);
194 194
195 ag->addTo(default_view); 195 ag->addTo(default_view);
196 connect(ag, SIGNAL( selected ( QAction * ) ), 196 connect(ag, SIGNAL( selected ( QAction * ) ),
197 this, SLOT( newDefaultView(QAction *) ) 197 this, SLOT( newDefaultView(QAction *) )
198 ); 198 );
199 199
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 aPreset = frmSettings.alarmPreset();
281 presetTime = frmSettings.presetTime(); 281 presetTime = frmSettings.presetTime();
282 startTime = frmSettings.startTime(); 282 startTime = frmSettings.startTime();
283 bJumpToCurTime = frmSettings.jumpToCurTime(); 283 bJumpToCurTime = frmSettings.jumpToCurTime();
284 rowStyle = frmSettings.rowStyle(); 284 rowStyle = frmSettings.rowStyle();
285 if ( dayView ) 285 if ( dayView )
286 dayView->setStartViewTime( startTime ); 286 dayView->setStartViewTime( startTime );
287 dayView->setJumpToCurTime( bJumpToCurTime ); 287 dayView->setJumpToCurTime( bJumpToCurTime );
288 dayView->setRowStyle( rowStyle ); 288 dayView->setRowStyle( rowStyle );
289 if ( weekView ) 289 if ( weekView )
290 weekView->setStartViewTime( startTime ); 290 weekView->setStartViewTime( startTime );
291 saveSettings(); 291 saveSettings();
292 292
293 // make the change obvious 293 // make the change obvious
294 if ( views->visibleWidget() ) { 294 if ( views->visibleWidget() ) {
295 if ( views->visibleWidget() == dayView ) 295 if ( views->visibleWidget() == dayView )
296 dayView->redraw(); 296 dayView->redraw();
297 else if ( views->visibleWidget() == weekView ) 297 else if ( views->visibleWidget() == weekView )
298 weekView->redraw(); 298 weekView->redraw();
299 } 299 }
300 } 300 }
301} 301}
302 302
303void DateBook::fileNew() 303void DateBook::fileNew()
304{ 304{
305 slotNewEventFromKey(""); 305 slotNewEventFromKey("");
306} 306}
307 307
308QString DateBook::checkEvent(const Event &e) 308QString DateBook::checkEvent(const Event &e)
309{ 309{
310 /* check if overlaps with itself */ 310 /* check if overlaps with itself */
311 bool checkFailed = FALSE; 311 bool checkFailed = FALSE;
312 312
313 /* check the next 12 repeats. should catch most problems */ 313 /* check the next 12 repeats. should catch most problems */
314 QDate current_date = e.start().date(); 314 QDate current_date = e.start().date();
315 Event previous = e; 315 Event previous = e;
316 for(int i = 0; i < 12; i++) 316 for(int i = 0; i < 12; i++)
317 { 317 {
318 QDateTime next; 318 QDateTime next;
319 if (!nextOccurance(previous, current_date.addDays(1), next)) { 319 if (!nextOccurance(previous, current_date.addDays(1), next)) {
320 break; // no more repeats 320 break; // no more repeats
321 } 321 }
322 if(next < previous.end()) { 322 if(next < previous.end()) {
323 checkFailed = TRUE; 323 checkFailed = TRUE;
324 break; 324 break;
325 } 325 }
326 current_date = next.date(); 326 current_date = next.date();
327 } 327 }
328 328
329 if(checkFailed) 329 if(checkFailed)
330 return tr("Event duration is potentially longer\n" 330 return tr("Event duration is potentially longer\n"
331 "than interval between repeats."); 331 "than interval between repeats.");
332 332
333 return QString::null; 333 return QString::null;
334} 334}
335 335
336QDate DateBook::currentDate() 336QDate DateBook::currentDate()
337{ 337{
338 QDate d = QDate::currentDate(); 338 QDate d = QDate::currentDate();
339 339
340 if ( dayView && views->visibleWidget() == dayView ) { 340 if ( dayView && views->visibleWidget() == dayView ) {
341 d = dayView->date(); 341 d = dayView->date();
342 } else if ( weekView && views->visibleWidget() == weekView ) { 342 } else if ( weekView && views->visibleWidget() == weekView ) {
343 d = weekView->date(); 343 d = weekView->date();
344 } else if ( weekLstView && views->visibleWidget() == weekLstView ) { 344 } else if ( weekLstView && views->visibleWidget() == weekLstView ) {
345 d = weekLstView->date(); 345 d = weekLstView->date();
346 } else if ( monthView && views->visibleWidget() == monthView ) { 346 } else if ( monthView && views->visibleWidget() == monthView ) {
347 d = monthView->selectedDate(); 347 d = monthView->selectedDate();
348 } 348 }
349 349
350 return d; 350 return d;
351} 351}
352 352
353void DateBook::view(int v, const QDate &d) { 353void DateBook::view(int v, const QDate &d) {
354 if (v==DAY) { 354 if (v==DAY) {
355 initDay(); 355 initDay();
356 dayAction->setOn( TRUE ); 356 dayAction->setOn( TRUE );
357 dayView->setDate( d ); 357 dayView->setDate( d );
358 views->raiseWidget( dayView ); 358 views->raiseWidget( dayView );
359 dayView->redraw(); 359 dayView->redraw();
360 } else if (v==WEEK) { 360 } else if (v==WEEK) {
361 initWeek(); 361 initWeek();
362 weekAction->setOn( TRUE ); 362 weekAction->setOn( TRUE );
363 weekView->setDate( d ); 363 weekView->setDate( d );
364 views->raiseWidget( weekView ); 364 views->raiseWidget( weekView );
365 weekView->redraw(); 365 weekView->redraw();
366 } else if (v==WEEKLST) { 366 } else if (v==WEEKLST) {
367 initWeekLst(); 367 initWeekLst();
368 weekLstAction->setOn( TRUE ); 368 weekLstAction->setOn( TRUE );
369 weekLstView->setDate(d); 369 weekLstView->setDate(d);
370 views->raiseWidget( weekLstView ); 370 views->raiseWidget( weekLstView );
371 weekLstView->redraw(); 371 weekLstView->redraw();
372 } else if (v==MONTH) { 372 } else if (v==MONTH) {
373 initMonth(); 373 initMonth();
374 monthAction->setOn( TRUE ); 374 monthAction->setOn( TRUE );
375 monthView->setDate( d.year(), d.month(), d.day() ); 375 monthView->setDate( d.year(), d.month(), d.day() );
376 views->raiseWidget( monthView ); 376 views->raiseWidget( monthView );
377 monthView->redraw(); 377 monthView->redraw();
378 } 378 }
379} 379}
380 380
381void DateBook::viewDefault(const QDate &d) { 381void DateBook::viewDefault(const QDate &d) {
382 Config config("DateBook"); 382 Config config("DateBook");
383 config.setGroup("Main"); 383 config.setGroup("Main");
384 int current=config.readNumEntry("defaultview", DAY); 384 int current=config.readNumEntry("defaultview", DAY);
385 385
386 view(current,d); 386 view(current,d);
387} 387}
388 388
389void DateBook::viewDay() { 389void DateBook::viewDay() {
390 view(DAY,currentDate()); 390 view(DAY,currentDate());
391} 391}
392 392
393void DateBook::viewWeek() { 393void DateBook::viewWeek() {
394 view(WEEK,currentDate()); 394 view(WEEK,currentDate());
395} 395}
396 396
397void DateBook::viewWeekLst() { 397void DateBook::viewWeekLst() {
398 view(WEEKLST,currentDate()); 398 view(WEEKLST,currentDate());
399} 399}
400 400
401void DateBook::viewMonth() { 401void DateBook::viewMonth() {
402 view(MONTH,currentDate()); 402 view(MONTH,currentDate());
403} 403}
404 404
405void DateBook::duplicateEvent( const Event &e ) 405void DateBook::duplicateEvent( const Event &e )
406{ 406{
407 qWarning("Hmmm..."); 407 qWarning("Hmmm...");
408 // Alot of code duplication, as this is almost like editEvent(); 408 // Alot of code duplication, as this is almost like editEvent();
409 if (syncing) { 409 if (syncing) {
410 QMessageBox::warning( this, tr("Calendar"), 410 QMessageBox::warning( this, tr("Calendar"),
411 tr( "Can not edit data, currently syncing") ); 411 tr( "Can not edit data, currently syncing") );
412 return; 412 return;
413 } 413 }
414 414
415 Event dupevent; 415 Event dupevent;
416 dupevent.setStart(e.start()); 416 dupevent.setStart(e.start());
417 dupevent.setEnd(e.end()); 417 dupevent.setEnd(e.end());
418 dupevent.setDescription(e.description()); 418 dupevent.setDescription(e.description());
419 dupevent.setLocation(e.location()); 419 dupevent.setLocation(e.location());
420 // dupevent.setCategory(e.category());// how is this done?? 420 // dupevent.setCategory(e.category());// how is this done??
421 dupevent.setNotes(e.notes()); 421 dupevent.setNotes(e.notes());
422 dupevent.setAllDay(e.isAllDay()); 422 dupevent.setAllDay(e.isAllDay());
423 dupevent.setTimeZone(e.timeZone()); 423 dupevent.setTimeZone(e.timeZone());
424 if(e.hasAlarm()) dupevent.setAlarm(e.alarmDelay(),e.alarmSound()); 424 if(e.hasAlarm()) dupevent.setAlarm(e.alarmDelay(),e.alarmSound());
425 if(e.hasRepeat()) dupevent.setRepeat(e.repeatPattern()); 425 if(e.hasRepeat()) dupevent.setRepeat(e.repeatPattern());
426 426
427 // workaround added for text input. 427 // workaround added for text input.
428 QDialog editDlg( this, 0, TRUE ); 428 QDialog editDlg( this, 0, TRUE );
429 DateEntry *entry; 429 DateEntry *entry;
430 editDlg.setCaption( tr("Duplicate Event") ); 430 editDlg.setCaption( tr("Duplicate Event") );
431 QVBoxLayout *vb = new QVBoxLayout( &editDlg ); 431 QVBoxLayout *vb = new QVBoxLayout( &editDlg );
432 QScrollView *sv = new QScrollView( &editDlg, "scrollview" ); 432 QScrollView *sv = new QScrollView( &editDlg, "scrollview" );
433 sv->setResizePolicy( QScrollView::AutoOneFit ); 433 sv->setResizePolicy( QScrollView::AutoOneFit );
434 // KLUDGE!!! 434 // KLUDGE!!!
435 sv->setHScrollBarMode( QScrollView::AlwaysOff ); 435 sv->setHScrollBarMode( QScrollView::AlwaysOff );
436 vb->addWidget( sv ); 436 vb->addWidget( sv );
437 entry = new DateEntry( onMonday, dupevent, ampm, &editDlg, "editor" ); 437 entry = new DateEntry( onMonday, dupevent, ampm, &editDlg, "editor" );
438 entry->timezone->setEnabled( FALSE ); 438 entry->timezone->setEnabled( FALSE );
439 sv->addChild( entry ); 439 sv->addChild( entry );
440 440
441#if defined(Q_WS_QWS) || defined(_WS_QWS_) 441#if defined(Q_WS_QWS) || defined(_WS_QWS_)
442 editDlg.showMaximized(); 442 editDlg.showMaximized();
443#endif 443#endif
444 while (editDlg.exec() ) { 444 while (editDlg.exec() ) {
445 Event newEv = entry->event(); 445 Event newEv = entry->event();
446 if(newEv.description().isEmpty() && newEv.notes().isEmpty() ) 446 if(newEv.description().isEmpty() && newEv.notes().isEmpty() )
447 break; 447 break;
448 newEv.setUid(e.uid()); // FIXME: Hack not to clear uid 448 newEv.setUid(e.uid()); // FIXME: Hack not to clear uid
449 QString error = checkEvent(newEv); 449 QString error = checkEvent(newEv);
450 if (!error.isNull()) { 450 if (!error.isNull()) {
451 if (QMessageBox::warning(this, "error box", 451 if (QMessageBox::warning(this, "error box",
452 error, "Fix it", "Continue", 452 error, "Fix it", "Continue",
453 0, 0, 1) == 0) 453 0, 0, 1) == 0)
454 continue; 454 continue;
455 } 455 }
456 db->addEvent(newEv); 456 db->addEvent(newEv);
457 emit newEvent(); 457 emit newEvent();
458 break; 458 break;
459 } 459 }
460} 460}
461 461
462void DateBook::editEvent( const Event &e ) 462void DateBook::editEvent( const Event &e )
463{ 463{
464 if (syncing) { 464 if (syncing) {
465 QMessageBox::warning( this, tr("Calendar"), 465 QMessageBox::warning( this, tr("Calendar"),
466 tr( "Can not edit data, currently syncing") ); 466 tr( "Can not edit data, currently syncing") );
467 return; 467 return;
468 } 468 }
469 469
470 // workaround added for text input. 470 // workaround added for text input.
471 QDialog editDlg( this, 0, TRUE ); 471 QDialog editDlg( this, 0, TRUE );
472 DateEntry *entry; 472 DateEntry *entry;
473 editDlg.setCaption( tr("Edit Event") ); 473 editDlg.setCaption( tr("Edit Event") );
474 QVBoxLayout *vb = new QVBoxLayout( &editDlg ); 474 QVBoxLayout *vb = new QVBoxLayout( &editDlg );
475 QScrollView *sv = new QScrollView( &editDlg, "scrollview" ); 475 QScrollView *sv = new QScrollView( &editDlg, "scrollview" );
476 sv->setResizePolicy( QScrollView::AutoOneFit ); 476 sv->setResizePolicy( QScrollView::AutoOneFit );
477 // KLUDGE!!! 477 // KLUDGE!!!
478 sv->setHScrollBarMode( QScrollView::AlwaysOff ); 478 sv->setHScrollBarMode( QScrollView::AlwaysOff );
479 vb->addWidget( sv ); 479 vb->addWidget( sv );
480 entry = new DateEntry( onMonday, e, ampm, &editDlg, "editor" ); 480 entry = new DateEntry( onMonday, e, ampm, &editDlg, "editor" );
481 entry->timezone->setEnabled( FALSE ); 481 entry->timezone->setEnabled( FALSE );
482 sv->addChild( entry ); 482 sv->addChild( entry );
483 483
484#if defined(Q_WS_QWS) || defined(_WS_QWS_) 484#if defined(Q_WS_QWS) || defined(_WS_QWS_)
485 editDlg.showMaximized(); 485 editDlg.showMaximized();
486#endif 486#endif
487 while (editDlg.exec() ) { 487 while (editDlg.exec() ) {
488 Event newEv = entry->event(); 488 Event newEv = entry->event();
489 if(newEv.description().isEmpty() && newEv.notes().isEmpty() ) 489 if(newEv.description().isEmpty() && newEv.notes().isEmpty() )
490 break; 490 break;
491 newEv.setUid(e.uid()); // FIXME: Hack not to clear uid 491 newEv.setUid(e.uid()); // FIXME: Hack not to clear uid
492 QString error = checkEvent(newEv); 492 QString error = checkEvent(newEv);
493 if (!error.isNull()) { 493 if (!error.isNull()) {
494 if (QMessageBox::warning(this, "error box", 494 if (QMessageBox::warning(this, "error box",
495 error, "Fix it", "Continue", 495 error, "Fix it", "Continue",
496 0, 0, 1) == 0) 496 0, 0, 1) == 0)
497 continue; 497 continue;
498 } 498 }
499 db->editEvent(e, newEv); 499 db->editEvent(e, newEv);
500 emit newEvent(); 500 emit newEvent();
501 break; 501 break;
502 } 502 }
503} 503}
504 504
505void DateBook::removeEvent( const Event &e ) 505void DateBook::removeEvent( const Event &e )
506{ 506{
507 if (syncing) { 507 if (syncing) {
508 QMessageBox::warning( this, tr("Calendar"), 508 QMessageBox::warning( this, tr("Calendar"),
509 tr( "Can not edit data, currently syncing") ); 509 tr( "Can not edit data, currently syncing") );
510 return; 510 return;
511 } 511 }
512 512
513 QString strName = e.description(); 513 QString strName = e.description();
514 514
515 if ( !QPEMessageBox::confirmDelete( this, tr( "Calendar" ),strName ) ) 515 if ( !QPEMessageBox::confirmDelete( this, tr( "Calendar" ),strName ) )
516 return; 516 return;
517 517
518 db->removeEvent( e ); 518 db->removeEvent( e );
519 if ( views->visibleWidget() == dayView && dayView ) 519 if ( views->visibleWidget() == dayView && dayView )
520 dayView->redraw(); 520 dayView->redraw();
521} 521}
522 522
523void DateBook::addEvent( const Event &e ) 523void DateBook::addEvent( const Event &e )
524{ 524{
525 QDate d = e.start().date(); 525 QDate d = e.start().date();
526 initDay(); 526 initDay();
527 dayView->setDate( d ); 527 dayView->setDate( d );
528} 528}
529 529
530void DateBook::showDay( int year, int month, int day ) 530void DateBook::showDay( int year, int month, int day )
531{ 531{
532 QDate d(year, month, day); 532 QDate d(year, month, day);
533 view(DAY,d); 533 view(DAY,d);
534} 534}
535 535
536void DateBook::initDay() 536void DateBook::initDay()
537{ 537{
538 if ( !dayView ) { 538 if ( !dayView ) {
539 dayView = new DateBookDay( ampm, onMonday, db, views, "day view" ); 539 dayView = new DateBookDay( ampm, onMonday, db, views, "day view" );
540 views->addWidget( dayView, DAY ); 540 views->addWidget( dayView, DAY );
541 dayView->setStartViewTime( startTime ); 541 dayView->setStartViewTime( startTime );
542 dayView->setJumpToCurTime( bJumpToCurTime ); 542 dayView->setJumpToCurTime( bJumpToCurTime );
543 dayView->setRowStyle( rowStyle ); 543 dayView->setRowStyle( rowStyle );
544 connect( this, SIGNAL( newEvent() ), 544 connect( this, SIGNAL( newEvent() ),
545 dayView, SLOT( redraw() ) ); 545 dayView, SLOT( redraw() ) );
546 connect( dayView, SIGNAL( newEvent() ), 546 connect( dayView, SIGNAL( newEvent() ),
547 this, SLOT( fileNew() ) ); 547 this, SLOT( fileNew() ) );
548 connect( dayView, SIGNAL( removeEvent( const Event & ) ), 548 connect( dayView, SIGNAL( removeEvent( const Event & ) ),
549 this, SLOT( removeEvent( const Event & ) ) ); 549 this, SLOT( removeEvent( const Event & ) ) );
550 connect( dayView, SIGNAL( editEvent( const Event & ) ), 550 connect( dayView, SIGNAL( editEvent( const Event & ) ),
551 this, SLOT( editEvent( const Event & ) ) ); 551 this, SLOT( editEvent( const Event & ) ) );
552 connect( dayView, SIGNAL( duplicateEvent( const Event & ) ), 552 connect( dayView, SIGNAL( duplicateEvent( const Event & ) ),
553 this, SLOT( duplicateEvent( const Event & ) ) ); 553 this, SLOT( duplicateEvent( const Event & ) ) );
554 connect( dayView, SIGNAL( beamEvent( const Event & ) ), 554 connect( dayView, SIGNAL( beamEvent( const Event & ) ),
555 this, SLOT( beamEvent( const Event & ) ) ); 555 this, SLOT( beamEvent( const Event & ) ) );
556 connect( dayView, SIGNAL(sigNewEvent(const QString &)), 556 connect( dayView, SIGNAL(sigNewEvent(const QString &)),
557 this, SLOT(slotNewEventFromKey(const QString &)) ); 557 this, SLOT(slotNewEventFromKey(const QString &)) );
558 } 558 }
559} 559}
560 560
561void DateBook::initWeek() 561void DateBook::initWeek()
562{ 562{
563 if ( !weekView ) { 563 if ( !weekView ) {
564 weekView = new DateBookWeek( ampm, onMonday, db, views, "week view" ); 564 weekView = new DateBookWeek( ampm, onMonday, db, views, "week view" );
565 weekView->setStartViewTime( startTime ); 565 weekView->setStartViewTime( startTime );
566 views->addWidget( weekView, WEEK ); 566 views->addWidget( weekView, WEEK );
567 connect( weekView, SIGNAL( showDate( int, int, int ) ), 567 connect( weekView, SIGNAL( showDate( int, int, int ) ),
568 this, SLOT( showDay( int, int, int ) ) ); 568 this, SLOT( showDay( int, int, int ) ) );
569 connect( this, SIGNAL( newEvent() ), 569 connect( this, SIGNAL( newEvent() ),
570 weekView, SLOT( redraw() ) ); 570 weekView, SLOT( redraw() ) );
571 } 571 }
572 //But also get it right: the year that we display can be different 572 //But also get it right: the year that we display can be different
573 //from the year of the current date. So, first find the year 573 //from the year of the current date. So, first find the year
574 //number of the current week. 574 //number of the current week.
575 575
576 int yearNumber, totWeeks; 576 int yearNumber, totWeeks;
577 calcWeek( currentDate(), totWeeks, yearNumber, onMonday ); 577 calcWeek( currentDate(), totWeeks, yearNumber, onMonday );
578 578
579 QDate d = QDate( yearNumber, 12, 31 ); 579 QDate d = QDate( yearNumber, 12, 31 );
580 calcWeek( d, totWeeks, yearNumber, onMonday ); 580 calcWeek( d, totWeeks, yearNumber, onMonday );
581 581
582 while ( totWeeks == 1 ) { 582 while ( totWeeks == 1 ) {
583 d = d.addDays( -1 ); 583 d = d.addDays( -1 );
584 calcWeek( d, totWeeks, yearNumber, onMonday ); 584 calcWeek( d, totWeeks, yearNumber, onMonday );
585 } 585 }
586 if ( totWeeks != weekView->totalWeeks() ) 586 if ( totWeeks != weekView->totalWeeks() )
587 weekView->setTotalWeeks( totWeeks ); 587 weekView->setTotalWeeks( totWeeks );
588} 588}
589void DateBook::initWeekLst() { 589void DateBook::initWeekLst() {
590 if ( !weekLstView ) { 590 if ( !weekLstView ) {
591 weekLstView = new DateBookWeekLst( ampm, onMonday, db, 591 weekLstView = new DateBookWeekLst( ampm, onMonday, db,
592 views, "weeklst view" ); 592 views, "weeklst view" );
593 views->addWidget( weekLstView, WEEKLST ); 593 views->addWidget( weekLstView, WEEKLST );
594 594
595 //weekLstView->setStartViewTime( startTime ); 595 //weekLstView->setStartViewTime( startTime );
596 connect( weekLstView, SIGNAL( showDate( int, int, int ) ), 596 connect( weekLstView, SIGNAL( showDate( int, int, int ) ),
597 this, SLOT( showDay( int, int, int ) ) ); 597 this, SLOT( showDay( int, int, int ) ) );
598 connect( weekLstView, SIGNAL( addEvent( const QDateTime &, 598 connect( weekLstView, SIGNAL( addEvent( const QDateTime &,
599 const QDateTime &, 599 const QDateTime &,
600 const QString & ) ), 600 const QString & , const QString &) ),
601 this, SLOT( slotNewEntry( const QDateTime &, 601 this, SLOT( slotNewEntry( const QDateTime &,
602 const QDateTime &, 602 const QDateTime &,
603 const QString & ) ) ); 603 const QString & , const QString &) ) );
604 connect( this, SIGNAL( newEvent() ), 604 connect( this, SIGNAL( newEvent() ),
605 weekLstView, SLOT( redraw() ) ); 605 weekLstView, SLOT( redraw() ) );
606 connect( weekLstView, SIGNAL( editEvent( const Event & ) ), 606 connect( weekLstView, SIGNAL( editEvent( const Event & ) ),
607 this, SLOT( editEvent( const Event & ) ) ); 607 this, SLOT( editEvent( const Event & ) ) );
608 } 608 }
609} 609}
610 610
611 611
612void DateBook::initMonth() 612void DateBook::initMonth()
613{ 613{
614 if ( !monthView ) { 614 if ( !monthView ) {
615 monthView = new DateBookMonth( views, "month view", FALSE, db ); 615 monthView = new DateBookMonth( views, "month view", FALSE, db );
616 views->addWidget( monthView, MONTH ); 616 views->addWidget( monthView, MONTH );
617 connect( monthView, SIGNAL( dateClicked( int, int, int ) ), 617 connect( monthView, SIGNAL( dateClicked( int, int, int ) ),
618 this, SLOT( showDay( int, int, int ) ) ); 618 this, SLOT( showDay( int, int, int ) ) );
619 connect( this, SIGNAL( newEvent() ), 619 connect( this, SIGNAL( newEvent() ),
620 monthView, SLOT( redraw() ) ); 620 monthView, SLOT( redraw() ) );
621 qApp->processEvents(); 621 qApp->processEvents();
622 } 622 }
623} 623}
624 624
625void DateBook::loadSettings() 625void DateBook::loadSettings()
626{ 626{
627 { 627 {
628 Config config( "qpe" ); 628 Config config( "qpe" );
629 config.setGroup("Time"); 629 config.setGroup("Time");
630 ampm = config.readBoolEntry( "AMPM", TRUE ); 630 ampm = config.readBoolEntry( "AMPM", TRUE );
631 onMonday = config.readBoolEntry( "MONDAY" ); 631 onMonday = config.readBoolEntry( "MONDAY" );
632 } 632 }
633 633
634 { 634 {
635 Config config("DateBook"); 635 Config config("DateBook");
636 config.setGroup("Main"); 636 config.setGroup("Main");
637 startTime = config.readNumEntry("startviewtime", 8); 637 startTime = config.readNumEntry("startviewtime", 8);
638 aPreset = config.readBoolEntry("alarmpreset"); 638 aPreset = config.readBoolEntry("alarmpreset");
639 presetTime = config.readNumEntry("presettime"); 639 presetTime = config.readNumEntry("presettime");
640 bJumpToCurTime = config.readBoolEntry("jumptocurtime"); 640 bJumpToCurTime = config.readBoolEntry("jumptocurtime");
641 rowStyle = config.readNumEntry("rowstyle"); 641 rowStyle = config.readNumEntry("rowstyle");
642 } 642 }
643} 643}
644 644
645void DateBook::saveSettings() 645void DateBook::saveSettings()
646{ 646{
647 Config config( "qpe" ); 647 Config config( "qpe" );
648 Config configDB( "DateBook" ); 648 Config configDB( "DateBook" );
649 configDB.setGroup( "Main" ); 649 configDB.setGroup( "Main" );
650 configDB.writeEntry("startviewtime",startTime); 650 configDB.writeEntry("startviewtime",startTime);
651 configDB.writeEntry("alarmpreset",aPreset); 651 configDB.writeEntry("alarmpreset",aPreset);
652 configDB.writeEntry("presettime",presetTime); 652 configDB.writeEntry("presettime",presetTime);
653 configDB.writeEntry("jumptocurtime", bJumpToCurTime); 653 configDB.writeEntry("jumptocurtime", bJumpToCurTime);
654 configDB.writeEntry("rowstyle", rowStyle); 654 configDB.writeEntry("rowstyle", rowStyle);
655} 655}
656 656
657void DateBook::newDefaultView(QAction *a) { 657void DateBook::newDefaultView(QAction *a) {
658 int val=DAY; 658 int val=DAY;
659 if (a->text() == "Day") val=DAY; 659 if (a->text() == "Day") val=DAY;
660 if (a->text() == "Week") val=WEEK; 660 if (a->text() == "Week") val=WEEK;
661 if (a->text() == "WeekLst") val=WEEKLST; 661 if (a->text() == "WeekLst") val=WEEKLST;
662 if (a->text() == "Month") val=MONTH; 662 if (a->text() == "Month") val=MONTH;
663 663
664 Config configDB( "DateBook" ); 664 Config configDB( "DateBook" );
665 configDB.setGroup( "Main" ); 665 configDB.setGroup( "Main" );
666 configDB.writeEntry("defaultview",val); 666 configDB.writeEntry("defaultview",val);
667} 667}
668 668
669void DateBook::appMessage(const QCString& msg, const QByteArray& data) 669void DateBook::appMessage(const QCString& msg, const QByteArray& data)
670{ 670{
671 bool needShow = FALSE; 671 bool needShow = FALSE;
672 if ( msg == "alarm(QDateTime,int)" ) { 672 if ( msg == "alarm(QDateTime,int)" ) {
673 QDataStream ds(data,IO_ReadOnly); 673 QDataStream ds(data,IO_ReadOnly);
674 QDateTime when; int warn; 674 QDateTime when; int warn;
675 ds >> when >> warn; 675 ds >> when >> warn;
676 676
677 // check to make it's okay to continue, 677 // check to make it's okay to continue,
678 // this is the case that the time was set ahead, and 678 // this is the case that the time was set ahead, and
679 // we are forced given a stale alarm... 679 // we are forced given a stale alarm...
680 QDateTime current = QDateTime::currentDateTime(); 680 QDateTime current = QDateTime::currentDateTime();
681 if ( current.time().hour() != when.time().hour() 681 if ( current.time().hour() != when.time().hour()
682 && current.time().minute() != when.time().minute() ) 682 && current.time().minute() != when.time().minute() )
683 return; 683 return;
684 684
685 QValueList<EffectiveEvent> list = db->getEffectiveEvents(when.addSecs(warn*60)); 685 QValueList<EffectiveEvent> list = db->getEffectiveEvents(when.addSecs(warn*60));
686 if ( list.count() > 0 ) { 686 if ( list.count() > 0 ) {
687 QString msg; 687 QString msg;
688 bool bSound = FALSE; 688 bool bSound = FALSE;
689 int stopTimer = 0; 689 int stopTimer = 0;
690 bool found = FALSE; 690 bool found = FALSE;
691 for ( QValueList<EffectiveEvent>::ConstIterator it=list.begin(); 691 for ( QValueList<EffectiveEvent>::ConstIterator it=list.begin();
692 it!=list.end(); ++it ) { 692 it!=list.end(); ++it ) {
693 if ( (*it).event().hasAlarm() ) { 693 if ( (*it).event().hasAlarm() ) {
694 found = TRUE; 694 found = TRUE;
695 msg += "<CENTER><B>" + (*it).description() + "</B>" 695 msg += "<CENTER><B>" + (*it).description() + "</B>"
696 + "<BR>" + (*it).location() + "<BR>" 696 + "<BR>" + (*it).location() + "<BR>"
697 + TimeString::dateString((*it).event().start(),ampm) 697 + TimeString::dateString((*it).event().start(),ampm)
698 + (warn 698 + (warn
699 ? tr(" (in " + QString::number(warn) 699 ? tr(" (in " + QString::number(warn)
700 + tr(" minutes)")) 700 + tr(" minutes)"))
701 : QString("")) 701 : QString(""))
702 + "<BR>" 702 + "<BR>"
703 + (*it).notes() + "</CENTER>"; 703 + (*it).notes() + "</CENTER>";
704 if ( (*it).event().alarmSound() != Event::Silent ) { 704 if ( (*it).event().alarmSound() != Event::Silent ) {
705 bSound = TRUE; 705 bSound = TRUE;
706 } 706 }
707 } 707 }
708 } 708 }
709 if ( found ) { 709 if ( found ) {
710 if ( bSound ) { 710 if ( bSound ) {
711 Sound::soundAlarm(); 711 Sound::soundAlarm();
712 alarmCounter = 0; 712 alarmCounter = 0;
713 stopTimer = startTimer( 5000 ); 713 stopTimer = startTimer( 5000 );
714 } 714 }
715 715
716 QDialog dlg( this, 0, TRUE ); 716 QDialog dlg( this, 0, TRUE );
717 QVBoxLayout *vb = new QVBoxLayout( &dlg ); 717 QVBoxLayout *vb = new QVBoxLayout( &dlg );
718 QScrollView *view = new QScrollView( &dlg, "scrollView"); 718 QScrollView *view = new QScrollView( &dlg, "scrollView");
719 view->setResizePolicy( QScrollView::AutoOneFit ); 719 view->setResizePolicy( QScrollView::AutoOneFit );
720 vb->addWidget( view ); 720 vb->addWidget( view );
721 QLabel *lblMsg = new QLabel( msg, &dlg ); 721 QLabel *lblMsg = new QLabel( msg, &dlg );
722 view->addChild( lblMsg ); 722 view->addChild( lblMsg );
723 QPushButton *cmdOk = new QPushButton( tr("OK"), &dlg ); 723 QPushButton *cmdOk = new QPushButton( tr("OK"), &dlg );
724 connect( cmdOk, SIGNAL(clicked()), &dlg, SLOT(accept()) ); 724 connect( cmdOk, SIGNAL(clicked()), &dlg, SLOT(accept()) );
725 vb->addWidget( cmdOk ); 725 vb->addWidget( cmdOk );
726 726
727#if defined(Q_WS_QWS) || defined(_WS_QWS_) 727#if defined(Q_WS_QWS) || defined(_WS_QWS_)
728 dlg.showMaximized(); 728 dlg.showMaximized();
729#endif 729#endif
730 needShow = dlg.exec(); 730 needShow = dlg.exec();
731 731
732 if ( bSound ) 732 if ( bSound )
733 killTimer( stopTimer ); 733 killTimer( stopTimer );
734 } 734 }
735 } 735 }
736 } else if ( msg == "nextView()" ) { 736 } else if ( msg == "nextView()" ) {
737 if ( !qApp-> activeWindow ( )) { 737 if ( !qApp-> activeWindow ( )) {
738 needShow = TRUE; 738 needShow = TRUE;
739 } 739 }
740 else { 740 else {
741 QWidget* cur = views->visibleWidget(); 741 QWidget* cur = views->visibleWidget();
742 if ( cur ) { 742 if ( cur ) {
743 if ( cur == dayView ) 743 if ( cur == dayView )
744 viewWeek(); 744 viewWeek();
745 else if ( cur == weekView ) 745 else if ( cur == weekView )
746 viewWeekLst(); 746 viewWeekLst();
747 else if ( cur == weekLstView ) 747 else if ( cur == weekLstView )
748 viewMonth(); 748 viewMonth();
749 else if ( cur == monthView ) 749 else if ( cur == monthView )
750 viewDay(); 750 viewDay();
751 needShow = TRUE; 751 needShow = TRUE;
752 } 752 }
753 } 753 }
754 } 754 }
755 if ( needShow ) { 755 if ( needShow ) {
756#if defined(Q_WS_QWS) || defined(_WS_QWS_) 756#if defined(Q_WS_QWS) || defined(_WS_QWS_)
757 showMaximized(); 757 showMaximized();
758#else 758#else
759 show(); 759 show();
760#endif 760#endif
761 raise(); 761 raise();
762 QPEApplication::setKeepRunning(); 762 QPEApplication::setKeepRunning();
763 setActiveWindow(); 763 setActiveWindow();
764 } 764 }
765} 765}
766 766
767void DateBook::reload() 767void DateBook::reload()
768{ 768{
769 db->reload(); 769 db->reload();
770 if ( dayAction->isOn() ) 770 if ( dayAction->isOn() )
771 viewDay(); 771 viewDay();
772 else if ( weekAction->isOn() ) 772 else if ( weekAction->isOn() )
773 viewWeek(); 773 viewWeek();
774 else if ( monthAction->isOn() ) 774 else if ( monthAction->isOn() )
775 viewMonth(); 775 viewMonth();
776 syncing = FALSE; 776 syncing = FALSE;
777} 777}
778 778
779void DateBook::flush() 779void DateBook::flush()
780{ 780{
781 syncing = TRUE; 781 syncing = TRUE;
782 db->save(); 782 db->save();
783} 783}
784 784
785void DateBook::timerEvent( QTimerEvent *e ) 785void DateBook::timerEvent( QTimerEvent *e )
786{ 786{
787 if ( alarmCounter < 10 ) { 787 if ( alarmCounter < 10 ) {
788 alarmCounter++; 788 alarmCounter++;
789 Sound::soundAlarm(); 789 Sound::soundAlarm();
790 } 790 }
791 else 791 else
792 killTimer( e->timerId() ); 792 killTimer( e->timerId() );
793} 793}
794 794
795void DateBook::changeClock( bool newClock ) 795void DateBook::changeClock( bool newClock )
796{ 796{
797 ampm = newClock; 797 ampm = newClock;
798 // repaint the affected objects... 798 // repaint the affected objects...
799 if (dayView) dayView->redraw(); 799 if (dayView) dayView->redraw();
800 if (weekView) weekView->redraw(); 800 if (weekView) weekView->redraw();
801 if (weekLstView) weekLstView->redraw(); 801 if (weekLstView) weekLstView->redraw();
802} 802}
803 803
804void DateBook::changeWeek( bool m ) 804void DateBook::changeWeek( bool m )
805{ 805{
806 /* no need to redraw, each widget catches. Do need to 806 /* no need to redraw, each widget catches. Do need to
807 store though for widgets we haven't made yet */ 807 store though for widgets we haven't made yet */
808 onMonday = m; 808 onMonday = m;
809} 809}
810 810
811void DateBook::slotToday() 811void DateBook::slotToday()
812{ 812{
813 // we need to view today using default view 813 // we need to view today using default view
814 viewDefault(QDate::currentDate()); 814 viewDefault(QDate::currentDate());
815} 815}
816 816
817void DateBook::closeEvent( QCloseEvent *e ) 817void DateBook::closeEvent( QCloseEvent *e )
818{ 818{
819 if(syncing) { 819 if(syncing) {
820 /* no need to save, did that at flush */ 820 /* no need to save, did that at flush */
821 e->accept(); 821 e->accept();
822 return; 822 return;
823 } 823 }
824 824
825 // save settings will generate it's own error messages, no 825 // save settings will generate it's own error messages, no
826 // need to do checking ourselves. 826 // need to do checking ourselves.
827 saveSettings(); 827 saveSettings();
828 if ( db->save() ) 828 if ( db->save() )
829 e->accept(); 829 e->accept();
830 else { 830 else {
831 if ( QMessageBox::critical( this, tr( "Out of space" ), 831 if ( QMessageBox::critical( this, tr( "Out of space" ),
832 tr("Calendar was unable to save\n" 832 tr("Calendar was unable to save\n"
833 "your changes.\n" 833 "your changes.\n"
834 "Free up some space and try again.\n" 834 "Free up some space and try again.\n"
835 "\nQuit anyway?"), 835 "\nQuit anyway?"),
836 QMessageBox::Yes|QMessageBox::Escape, 836 QMessageBox::Yes|QMessageBox::Escape,
837 QMessageBox::No|QMessageBox::Default ) 837 QMessageBox::No|QMessageBox::Default )
838 != QMessageBox::No ) 838 != QMessageBox::No )
839 e->accept(); 839 e->accept();
840 else 840 else
841 e->ignore(); 841 e->ignore();
842 } 842 }
843} 843}
844 844
845// Entering directly from the "keyboard" 845// Entering directly from the "keyboard"
846void DateBook::slotNewEventFromKey( const QString &str ) 846void DateBook::slotNewEventFromKey( const QString &str )
847{ 847{
848 if (syncing) { 848 if (syncing) {
849 QMessageBox::warning( this, tr("Calendar"), 849 QMessageBox::warning( this, tr("Calendar"),
850 tr( "Can not edit data, currently syncing") ); 850 tr( "Can not edit data, currently syncing") );
851 return; 851 return;
852 } 852 }
853 853
854 // We get to here from a key pressed in the Day View 854 // We get to here from a key pressed in the Day View
855 // So we can assume some things. We want the string 855 // So we can assume some things. We want the string
856 // passed in to be part of the description. 856 // passed in to be part of the description.
857 QDateTime start, end; 857 QDateTime start, end;
858 if ( views->visibleWidget() == dayView ) { 858 if ( views->visibleWidget() == dayView ) {
859 dayView->selectedDates( start, end ); 859 dayView->selectedDates( start, end );
860 } else if ( views->visibleWidget() == monthView ) { 860 } else if ( views->visibleWidget() == monthView ) {
861 QDate d = monthView->selectedDate(); 861 QDate d = monthView->selectedDate();
862 start = end = d; 862 start = end = d;
863 start.setTime( QTime( 10, 0 ) ); 863 start.setTime( QTime( 10, 0 ) );
864 end.setTime( QTime( 12, 0 ) ); 864 end.setTime( QTime( 12, 0 ) );
865 } else if ( views->visibleWidget() == weekView ) { 865 } else if ( views->visibleWidget() == weekView ) {
866 QDate d = weekView->date(); 866 QDate d = weekView->date();
867 start = end = d; 867 start = end = d;
868 start.setTime( QTime( 10, 0 ) ); 868 start.setTime( QTime( 10, 0 ) );
869 end.setTime( QTime( 12, 0 ) ); 869 end.setTime( QTime( 12, 0 ) );
870 } else if ( views->visibleWidget() == weekLstView ) { 870 } else if ( views->visibleWidget() == weekLstView ) {
871 QDate d = weekLstView->date(); 871 QDate d = weekLstView->date();
872 start = end = d; 872 start = end = d;
873 start.setTime( QTime( 10, 0 ) ); 873 start.setTime( QTime( 10, 0 ) );
874 end.setTime( QTime( 12, 0 ) ); 874 end.setTime( QTime( 12, 0 ) );
875 } 875 }
876 slotNewEntry(start, end, str); 876 slotNewEntry(start, end, str);
877} 877}
878void DateBook::slotNewEntry(const QDateTime &start, const QDateTime &end, const QString &str, const QString &location) { 878void DateBook::slotNewEntry(const QDateTime &start, const QDateTime &end, const QString &str, const QString &location) {
879 // argh! This really needs to be encapsulated in a class 879 // argh! This really needs to be encapsulated in a class
880 // or function. 880 // or function.
881 QDialog newDlg( this, 0, TRUE ); 881 QDialog newDlg( this, 0, TRUE );
882 newDlg.setCaption( DateEntryBase::tr("New Event") ); 882 newDlg.setCaption( DateEntryBase::tr("New Event") );
883 DateEntry *e; 883 DateEntry *e;
884 QVBoxLayout *vb = new QVBoxLayout( &newDlg ); 884 QVBoxLayout *vb = new QVBoxLayout( &newDlg );
885 QScrollView *sv = new QScrollView( &newDlg ); 885 QScrollView *sv = new QScrollView( &newDlg );
886 sv->setResizePolicy( QScrollView::AutoOneFit ); 886 sv->setResizePolicy( QScrollView::AutoOneFit );
887 sv->setFrameStyle( QFrame::NoFrame ); 887 sv->setFrameStyle( QFrame::NoFrame );
888 sv->setHScrollBarMode( QScrollView::AlwaysOff ); 888 sv->setHScrollBarMode( QScrollView::AlwaysOff );
889 vb->addWidget( sv ); 889 vb->addWidget( sv );
890 890
891 Event ev; 891 Event ev;
892 ev.setDescription( str ); 892 ev.setDescription( str );
893 // When the new gui comes in, change this... 893 // When the new gui comes in, change this...
894 if(location==0) { 894 if(location==0) {
895 ev.setLocation( tr("(Unknown)") ); 895 ev.setLocation( tr("(Unknown)") );
896 } else { 896 } else {
897 ev.setLocation(location); 897 ev.setLocation(location);
898 } 898 }
899 ev.setStart( start ); 899 ev.setStart( start );
900 ev.setEnd( end ); 900 ev.setEnd( end );
901 901
902 e = new DateEntry( onMonday, ev, ampm, &newDlg ); 902 e = new DateEntry( onMonday, ev, ampm, &newDlg );
903 e->setAlarmEnabled( aPreset, presetTime, Event::Loud ); 903 e->setAlarmEnabled( aPreset, presetTime, Event::Loud );
904 sv->addChild( e ); 904 sv->addChild( e );
905#if defined(Q_WS_QWS) || defined(_WS_QWS_) 905#if defined(Q_WS_QWS) || defined(_WS_QWS_)
906 newDlg.showMaximized(); 906 newDlg.showMaximized();
907#endif 907#endif
908 while (newDlg.exec()) { 908 while (newDlg.exec()) {
909 ev = e->event(); 909 ev = e->event();
910 ev.assignUid(); 910 ev.assignUid();
911 QString error = checkEvent( ev ); 911 QString error = checkEvent( ev );
912 if ( !error.isNull() ) { 912 if ( !error.isNull() ) {
913 if ( QMessageBox::warning( this, tr("Error!"), 913 if ( QMessageBox::warning( this, tr("Error!"),
914 error, tr("Fix it"), tr("Continue"), 0, 0, 1 ) == 0 ) 914 error, tr("Fix it"), tr("Continue"), 0, 0, 1 ) == 0 )
915 continue; 915 continue;
916 } 916 }
917 db->addEvent( ev ); 917 db->addEvent( ev );
918 emit newEvent(); 918 emit newEvent();
919 break; 919 break;
920 } 920 }
921} 921}
922 922
923void DateBook::setDocument( const QString &filename ) 923void DateBook::setDocument( const QString &filename )
924{ 924{
925 if ( filename.find(".vcs") != int(filename.length()) - 4 ) return; 925 if ( filename.find(".vcs") != int(filename.length()) - 4 ) return;
926 926
927 QValueList<Event> tl = Event::readVCalendar( filename ); 927 QValueList<Event> tl = Event::readVCalendar( filename );
928 for( QValueList<Event>::Iterator it = tl.begin(); it != tl.end(); ++it ) { 928 for( QValueList<Event>::Iterator it = tl.begin(); it != tl.end(); ++it ) {
929 db->addEvent( *it ); 929 db->addEvent( *it );
930 } 930 }
931} 931}
932 932
933static const char * beamfile = "/tmp/obex/event.vcs"; 933static const char * beamfile = "/tmp/obex/event.vcs";
934 934
935void DateBook::beamEvent( const Event &e ) 935void DateBook::beamEvent( const Event &e )
936{ 936{
937 qDebug("trying to beamn"); 937 qDebug("trying to beamn");
938 unlink( beamfile ); // delete if exists 938 unlink( beamfile ); // delete if exists
939 mkdir("/tmp/obex/", 0755); 939 mkdir("/tmp/obex/", 0755);
940 Event::writeVCalendar( beamfile, e ); 940 Event::writeVCalendar( beamfile, e );
941 Ir *ir = new Ir( this ); 941 Ir *ir = new Ir( this );
942 connect( ir, SIGNAL( done( Ir * ) ), this, SLOT( beamDone( Ir * ) ) ); 942 connect( ir, SIGNAL( done( Ir * ) ), this, SLOT( beamDone( Ir * ) ) );
943 QString description = e.description(); 943 QString description = e.description();
944 ir->send( beamfile, description, "text/x-vCalendar" ); 944 ir->send( beamfile, description, "text/x-vCalendar" );
945} 945}
946 946
947void DateBook::beamDone( Ir *ir ) 947void DateBook::beamDone( Ir *ir )
948{ 948{
949 delete ir; 949 delete ir;
950 unlink( beamfile ); 950 unlink( beamfile );
951} 951}
952 952
953void DateBook::slotFind() 953void DateBook::slotFind()
954{ 954{
955 // move it to the day view... 955 // move it to the day view...
956 viewDay(); 956 viewDay();
957 FindDialog frmFind( "Calendar", this ); 957 FindDialog frmFind( "Calendar", this );
958 frmFind.setUseDate( true ); 958 frmFind.setUseDate( true );
959 frmFind.setDate( currentDate() ); 959 frmFind.setDate( currentDate() );
960 QObject::connect( &frmFind, 960 QObject::connect( &frmFind,
961 SIGNAL(signalFindClicked(const QString&, const QDate&, 961 SIGNAL(signalFindClicked(const QString&, const QDate&,
962 bool, bool, int)), 962 bool, bool, int)),
963 this, 963 this,
964 SLOT(slotDoFind(const QString&, const QDate&, 964 SLOT(slotDoFind(const QString&, const QDate&,
965 bool, bool, int)) ); 965 bool, bool, int)) );
966 QObject::connect( this, 966 QObject::connect( this,
967 SIGNAL(signalNotFound()), 967 SIGNAL(signalNotFound()),
968 &frmFind, 968 &frmFind,
969 SLOT(slotNotFound()) ); 969 SLOT(slotNotFound()) );
970 QObject::connect( this, 970 QObject::connect( this,
971 SIGNAL(signalWrapAround()), 971 SIGNAL(signalWrapAround()),
972 &frmFind, 972 &frmFind,
973 SLOT(slotWrapAround()) ); 973 SLOT(slotWrapAround()) );
974 frmFind.move(0,0); 974 frmFind.move(0,0);
975 frmFind.exec(); 975 frmFind.exec();
976 inSearch = false; 976 inSearch = false;
977} 977}
978 978
979bool catComp( QArray<int> cats, int category ) 979bool catComp( QArray<int> cats, int category )
980{ 980{
981 bool returnMe; 981 bool returnMe;
982 int i, 982 int i,
983 count; 983 count;
984 984
985 count = int(cats.count()); 985 count = int(cats.count());
986 returnMe = false; 986 returnMe = false;
987 if ( (category == -1 && count == 0) || category == -2 ) 987 if ( (category == -1 && count == 0) || category == -2 )
988 returnMe = true; 988 returnMe = true;
989 else { 989 else {
990 for ( i = 0; i < count; i++ ) { 990 for ( i = 0; i < count; i++ ) {
991 if ( category == cats[i] ) { 991 if ( category == cats[i] ) {
992 returnMe = true; 992 returnMe = true;
993 break; 993 break;
994 } 994 }
995 } 995 }
996 } 996 }
997 return returnMe; 997 return returnMe;
998} 998}
999 999
1000 1000
1001void DateBook::slotDoFind( const QString& txt, const QDate &dt, 1001void DateBook::slotDoFind( const QString& txt, const QDate &dt,
1002 bool caseSensitive, bool /*backwards*/, 1002 bool caseSensitive, bool /*backwards*/,
1003 int category ) 1003 int category )
1004{ 1004{
1005 QDateTime dtEnd( QDate(3001, 1, 1), QTime(0, 0, 0) ), 1005 QDateTime dtEnd( QDate(3001, 1, 1), QTime(0, 0, 0) ),
1006 next; 1006 next;
1007 1007
1008 QRegExp r( txt ); 1008 QRegExp r( txt );
1009 r.setCaseSensitive( caseSensitive ); 1009 r.setCaseSensitive( caseSensitive );
1010 1010
1011 1011
1012 static Event rev, 1012 static Event rev,
1013 nonrev; 1013 nonrev;
1014 if ( !inSearch ) { 1014 if ( !inSearch ) {
1015 rev.setStart( QDateTime(QDate(1960, 1, 1), QTime(0, 0, 0)) ); 1015 rev.setStart( QDateTime(QDate(1960, 1, 1), QTime(0, 0, 0)) );
1016 nonrev.setStart( rev.start() ); 1016 nonrev.setStart( rev.start() );
1017 inSearch = true; 1017 inSearch = true;
1018 } 1018 }
1019 static QDate searchDate = dt; 1019 static QDate searchDate = dt;
1020 static bool wrapAround = true; 1020 static bool wrapAround = true;
1021 bool candidtate; 1021 bool candidtate;
1022 candidtate = false; 1022 candidtate = false;
1023 1023
1024 QValueList<Event> repeats = db->getRawRepeats(); 1024 QValueList<Event> repeats = db->getRawRepeats();
1025 1025
1026 // find the candidate for the first repeat that matches... 1026 // find the candidate for the first repeat that matches...
1027 QValueListConstIterator<Event> it; 1027 QValueListConstIterator<Event> it;
1028 QDate start = dt; 1028 QDate start = dt;
1029 for ( it = repeats.begin(); it != repeats.end(); ++it ) { 1029 for ( it = repeats.begin(); it != repeats.end(); ++it ) {
1030 if ( catComp( (*it).categories(), category ) ) { 1030 if ( catComp( (*it).categories(), category ) ) {
1031 while ( nextOccurance( *it, start, next ) ) { 1031 while ( nextOccurance( *it, start, next ) ) {
1032 if ( next < dtEnd ) { 1032 if ( next < dtEnd ) {
1033 if ( (*it).match( r ) && !(next <= rev.start()) ) { 1033 if ( (*it).match( r ) && !(next <= rev.start()) ) {
1034 rev = *it; 1034 rev = *it;
1035 dtEnd = next; 1035 dtEnd = next;
1036 rev.setStart( next ); 1036 rev.setStart( next );
1037 candidtate = true; 1037 candidtate = true;
1038 wrapAround = true; 1038 wrapAround = true;
1039 start = dt; 1039 start = dt;
1040 break; 1040 break;
1041 } else 1041 } else
1042 start = next.date().addDays( 1 ); 1042 start = next.date().addDays( 1 );
1043 } 1043 }
1044 } 1044 }
1045 } 1045 }
1046 } 1046 }
1047 1047
1048 // now the for first non repeat... 1048 // now the for first non repeat...
1049 QValueList<Event> nonRepeats = db->getNonRepeatingEvents( dt, dtEnd.date() ); 1049 QValueList<Event> nonRepeats = db->getNonRepeatingEvents( dt, dtEnd.date() );
1050 qHeapSort( nonRepeats.begin(), nonRepeats.end() ); 1050 qHeapSort( nonRepeats.begin(), nonRepeats.end() );
1051 for ( it = nonRepeats.begin(); it != nonRepeats.end(); ++it ) { 1051 for ( it = nonRepeats.begin(); it != nonRepeats.end(); ++it ) {
1052 if ( catComp( (*it).categories(), category ) ) { 1052 if ( catComp( (*it).categories(), category ) ) {
1053 if ( (*it).start() < dtEnd ) { 1053 if ( (*it).start() < dtEnd ) {
1054 if ( (*it).match( r ) && !(*it <= nonrev) ) { 1054 if ( (*it).match( r ) && !(*it <= nonrev) ) {
1055 nonrev = *it; 1055 nonrev = *it;
1056 dtEnd = nonrev.start(); 1056 dtEnd = nonrev.start();
1057 candidtate = true; 1057 candidtate = true;
1058 wrapAround = true; 1058 wrapAround = true;
1059 break; 1059 break;
1060 } 1060 }
1061 } 1061 }
1062 } 1062 }
1063 } 1063 }
1064 if ( candidtate ) { 1064 if ( candidtate ) {
1065 dayView->setStartViewTime( dtEnd.time().hour() ); 1065 dayView->setStartViewTime( dtEnd.time().hour() );
1066 dayView->setDate( dtEnd.date().year(), dtEnd.date().month(), 1066 dayView->setDate( dtEnd.date().year(), dtEnd.date().month(),
1067 dtEnd.date().day() ); 1067 dtEnd.date().day() );
1068 } else { 1068 } else {
1069 if ( wrapAround ) { 1069 if ( wrapAround ) {
1070 emit signalWrapAround(); 1070 emit signalWrapAround();
1071 rev.setStart( QDateTime(QDate(1960, 1, 1), QTime(0, 0, 0)) ); 1071 rev.setStart( QDateTime(QDate(1960, 1, 1), QTime(0, 0, 0)) );
1072 nonrev.setStart( rev.start() ); 1072 nonrev.setStart( rev.start() );
1073 } else 1073 } else
1074 emit signalNotFound(); 1074 emit signalNotFound();
1075 wrapAround = !wrapAround; 1075 wrapAround = !wrapAround;
1076 } 1076 }
1077} 1077}
1078 1078
1079Event DateBookDBHack::eventByUID(int uid) { 1079Event DateBookDBHack::eventByUID(int uid) {
1080 1080
1081 // FIXME: Dirty Hacks to get hold of the private event lists 1081 // FIXME: Dirty Hacks to get hold of the private event lists
1082 QDate start; 1082 QDate start;
1083 QDate end=start.addDays(-1); 1083 QDate end=start.addDays(-1);
1084 QValueList<Event> myEventList=getNonRepeatingEvents(start,end); 1084 QValueList<Event> myEventList=getNonRepeatingEvents(start,end);
1085 QValueList<Event> myRepeatEvents=getRawRepeats(); 1085 QValueList<Event> myRepeatEvents=getRawRepeats();
1086 1086
1087 QValueList<Event>::ConstIterator it; 1087 QValueList<Event>::ConstIterator it;
1088 1088
1089 for (it = myEventList.begin(); it != myEventList.end(); it++) { 1089 for (it = myEventList.begin(); it != myEventList.end(); it++) {
1090 if ((*it).uid() == uid) return *it; 1090 if ((*it).uid() == uid) return *it;
1091 } 1091 }
1092 for (it = myRepeatEvents.begin(); it != myRepeatEvents.end(); it++) { 1092 for (it = myRepeatEvents.begin(); it != myRepeatEvents.end(); it++) {
1093 if ((*it).uid() == uid) return *it; 1093 if ((*it).uid() == uid) return *it;
1094 } 1094 }
1095 1095
1096 qDebug("Event not found: uid=%d\n", uid); 1096 qDebug("Event not found: uid=%d\n", uid);
1097 Event ev; 1097 Event ev;
1098 return ev; // return at least 1098 return ev; // return at least
1099} 1099}
1100 1100