summaryrefslogtreecommitdiff
authorharlekin <harlekin>2002-02-15 20:02:50 (UTC)
committer harlekin <harlekin>2002-02-15 20:02:50 (UTC)
commit50bc570309b0da3ecd4a9d0a0448b58a9a8ed2ab (patch) (unidiff)
treefefefb94f5d4c0eae01ef441900a0c7c9dd3e22b
parent8ccfea56d43fde77717cfd354b62ccb3f67585d1 (diff)
downloadopie-50bc570309b0da3ecd4a9d0a0448b58a9a8ed2ab.zip
opie-50bc570309b0da3ecd4a9d0a0448b58a9a8ed2ab.tar.gz
opie-50bc570309b0da3ecd4a9d0a0448b58a9a8ed2ab.tar.bz2
added a icon for the today view to the menubar and change it in the view menu to first place
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--core/pim/datebook/datebook.cpp13
1 files changed, 8 insertions, 5 deletions
diff --git a/core/pim/datebook/datebook.cpp b/core/pim/datebook/datebook.cpp
index 6ec6cc2..e8d808f 100644
--- a/core/pim/datebook/datebook.cpp
+++ b/core/pim/datebook/datebook.cpp
@@ -1,854 +1,857 @@
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** $Id$ 19** $Id$
20** 20**
21**********************************************************************/ 21**********************************************************************/
22 22
23#define QTOPIA_INTERNAL_FD
24
23#include "datebook.h" 25#include "datebook.h"
24#include "datebookday.h" 26#include "datebookday.h"
25#include "datebooksettings.h" 27#include "datebooksettings.h"
26#include "datebookweek.h" 28#include "datebookweek.h"
27#include "dateentryimpl.h" 29#include "dateentryimpl.h"
28 30
29#include <qpe/datebookmonth.h> 31#include <qpe/datebookmonth.h>
30#include <qpe/qpeapplication.h> 32#include <qpe/qpeapplication.h>
31#include <qpe/config.h> 33#include <qpe/config.h>
32#include <qpe/qpedebug.h> 34#include <qpe/qpedebug.h>
33#include <qpe/event.h> 35#include <qpe/event.h>
34#include <qpe/finddialog.h> 36#include <qpe/finddialog.h>
35#include <qpe/ir.h> 37#include <qpe/ir.h>
36#include <qpe/qpemenubar.h> 38#include <qpe/qpemenubar.h>
37#include <qpe/qpemessagebox.h> 39#include <qpe/qpemessagebox.h>
38#include <qpe/resource.h> 40#include <qpe/resource.h>
39#include <qpe/sound.h> 41#include <qpe/sound.h>
40#include <qpe/timestring.h> 42#include <qpe/timestring.h>
41#include <qpe/qpetoolbar.h> 43#include <qpe/qpetoolbar.h>
42#include <qpe/tzselect.h> 44#include <qpe/tzselect.h>
43#include <qpe/xmlreader.h> 45#include <qpe/xmlreader.h>
44 46
45#include <qaction.h> 47#include <qaction.h>
46#include <qcopchannel_qws.h> 48#include <qcopchannel_qws.h>
47#include <qdatetime.h> 49#include <qdatetime.h>
48#include <qdialog.h> 50#include <qdialog.h>
49#include <qfile.h> 51#include <qfile.h>
50#include <qlabel.h> 52#include <qlabel.h>
51#include <qlayout.h> 53#include <qlayout.h>
52#include <qmessagebox.h> 54#include <qmessagebox.h>
53#include <qpopupmenu.h> 55#include <qpopupmenu.h>
54#include <qpushbutton.h> 56#include <qpushbutton.h>
55#include <qtextcodec.h> 57#include <qtextcodec.h>
56#include <qtextstream.h> 58#include <qtextstream.h>
57#include <qtl.h> 59#include <qtl.h>
58#include <qwidgetstack.h> 60#include <qwidgetstack.h>
59#include <qwindowsystem_qws.h> 61#include <qwindowsystem_qws.h>
60 62
61#include <sys/stat.h> 63#include <sys/stat.h>
62#include <sys/types.h> 64#include <sys/types.h>
63#include <fcntl.h> 65#include <fcntl.h>
64#include <unistd.h> 66#include <unistd.h>
65 67
66#include <stdlib.h> 68#include <stdlib.h>
67 69
68#define DAY 1 70#define DAY 1
69#define WEEK 2 71#define WEEK 2
70#define MONTH 3 72#define MONTH 3
71 73
72 74
73DateBook::DateBook( QWidget *parent, const char *, WFlags f ) 75DateBook::DateBook( QWidget *parent, const char *, WFlags f )
74 : QMainWindow( parent, "datebook", f ), 76 : QMainWindow( parent, "datebook", f ),
75 aPreset( FALSE ), 77 aPreset( FALSE ),
76 presetTime( -1 ), 78 presetTime( -1 ),
77 startTime( 8 ), // an acceptable default 79 startTime( 8 ), // an acceptable default
78 syncing(FALSE), 80 syncing(FALSE),
79 inSearch(FALSE) 81 inSearch(FALSE)
80{ 82{
81 QTime t; 83 QTime t;
82 t.start(); 84 t.start();
83 db = new DateBookDB; 85 db = new DateBookDB;
84 qDebug("loading db t=%d", t.elapsed() ); 86 qDebug("loading db t=%d", t.elapsed() );
85 loadSettings(); 87 loadSettings();
86 setCaption( tr("Calendar") ); 88 setCaption( tr("Calendar") );
87 setIcon( Resource::loadPixmap( "datebook_icon" ) ); 89 setIcon( Resource::loadPixmap( "datebook_icon" ) );
88 90
89 setToolBarsMovable( FALSE ); 91 setToolBarsMovable( FALSE );
90 92
91 QPEToolBar *bar = new QPEToolBar( this ); 93 QPEToolBar *bar = new QPEToolBar( this );
92 bar->setHorizontalStretchable( TRUE ); 94 bar->setHorizontalStretchable( TRUE );
93 95
94 QPEMenuBar *mb = new QPEMenuBar( bar ); 96 QPEMenuBar *mb = new QPEMenuBar( bar );
95 mb->setMargin( 0 ); 97 mb->setMargin( 0 );
96 98
97 QPEToolBar *sub_bar = new QPEToolBar(this); 99 QPEToolBar *sub_bar = new QPEToolBar(this);
98 100
99 QPopupMenu *view = new QPopupMenu( this ); 101 QPopupMenu *view = new QPopupMenu( this );
100 QPopupMenu *settings = new QPopupMenu( this ); 102 QPopupMenu *settings = new QPopupMenu( this );
101 103
102 mb->insertItem( tr( "View" ), view ); 104 mb->insertItem( tr( "View" ), view );
103 mb->insertItem( tr( "Settings" ), settings ); 105 mb->insertItem( tr( "Settings" ), settings );
104 106
105 QActionGroup *g = new QActionGroup( this ); 107 QActionGroup *g = new QActionGroup( this );
106 g->setExclusive( TRUE ); 108 g->setExclusive( TRUE );
107 109
108 QAction *a = new QAction( tr( "New" ), Resource::loadPixmap( "new" ), 110 QAction *a = new QAction( tr( "New" ), Resource::loadPixmap( "new" ),
109 QString::null, 0, this, 0 ); 111 QString::null, 0, this, 0 );
110 connect( a, SIGNAL( activated() ), this, SLOT( fileNew() ) ); 112 connect( a, SIGNAL( activated() ), this, SLOT( fileNew() ) );
111 a->addTo( sub_bar ); 113 a->addTo( sub_bar );
112 114
115 a = new QAction( tr( "Today" ), Resource::loadPixmap( "to_day" ), QString::null, 0, g, 0 );
116 connect( a, SIGNAL( activated() ), this, SLOT( slotToday() ) );
117 a->addTo( sub_bar );
118 a->addTo( view );
119
113 a = new QAction( tr( "Day" ), Resource::loadPixmap( "day" ), QString::null, 0, g, 0 ); 120 a = new QAction( tr( "Day" ), Resource::loadPixmap( "day" ), QString::null, 0, g, 0 );
114 connect( a, SIGNAL( activated() ), this, SLOT( viewDay() ) ); 121 connect( a, SIGNAL( activated() ), this, SLOT( viewDay() ) );
115 a->addTo( sub_bar ); 122 a->addTo( sub_bar );
116 a->addTo( view ); 123 a->addTo( view );
117 a->setToggleAction( TRUE ); 124 a->setToggleAction( TRUE );
118 a->setOn( TRUE ); 125 a->setOn( TRUE );
119 dayAction = a; 126 dayAction = a;
120 a = new QAction( tr( "Week" ), Resource::loadPixmap( "week" ), QString::null, 0, g, 0 ); 127 a = new QAction( tr( "Week" ), Resource::loadPixmap( "week" ), QString::null, 0, g, 0 );
121 connect( a, SIGNAL( activated() ), this, SLOT( viewWeek() ) ); 128 connect( a, SIGNAL( activated() ), this, SLOT( viewWeek() ) );
122 a->addTo( sub_bar ); 129 a->addTo( sub_bar );
123 a->addTo( view ); 130 a->addTo( view );
124 a->setToggleAction( TRUE ); 131 a->setToggleAction( TRUE );
125 weekAction = a; 132 weekAction = a;
126 a = new QAction( tr( "Month" ), Resource::loadPixmap( "month" ), QString::null, 0, g, 0 ); 133 a = new QAction( tr( "Month" ), Resource::loadPixmap( "month" ), QString::null, 0, g, 0 );
127 connect( a, SIGNAL( activated() ), this, SLOT( viewMonth() ) ); 134 connect( a, SIGNAL( activated() ), this, SLOT( viewMonth() ) );
128 a->addTo( sub_bar ); 135 a->addTo( sub_bar );
129 a->addTo( view ); 136 a->addTo( view );
130 a->setToggleAction( TRUE ); 137 a->setToggleAction( TRUE );
131 monthAction = a; 138 monthAction = a;
132 139
133 a = new QAction( tr( "Find" ), Resource::loadPixmap( "mag" ), QString::null, 0, g, 0 ); 140 a = new QAction( tr( "Find" ), Resource::loadPixmap( "mag" ), QString::null, 0, g, 0 );
134 connect( a, SIGNAL(activated()), this, SLOT(slotFind()) ); 141 connect( a, SIGNAL(activated()), this, SLOT(slotFind()) );
135 a->addTo( sub_bar ); 142 a->addTo( sub_bar );
136 143
137 a = new QAction( tr( "Today" ), QString::null, 0, 0 );
138 connect( a, SIGNAL( activated() ), this, SLOT( slotToday() ) );
139 a->addTo( view );
140
141 a = new QAction( tr( "Alarm and Start Time..." ), QString::null, 0, 0 ); 144 a = new QAction( tr( "Alarm and Start Time..." ), QString::null, 0, 0 );
142 connect( a, SIGNAL( activated() ), this, SLOT( slotSettings() ) ); 145 connect( a, SIGNAL( activated() ), this, SLOT( slotSettings() ) );
143 a->addTo( settings ); 146 a->addTo( settings );
144 147
145 views = new QWidgetStack( this ); 148 views = new QWidgetStack( this );
146 setCentralWidget( views ); 149 setCentralWidget( views );
147 150
148 dayView = 0; 151 dayView = 0;
149 weekView = 0; 152 weekView = 0;
150 monthView = 0; 153 monthView = 0;
151 154
152 viewDay(); 155 viewDay();
153 connect( qApp, SIGNAL(clockChanged(bool)), 156 connect( qApp, SIGNAL(clockChanged(bool)),
154 this, SLOT(changeClock(bool)) ); 157 this, SLOT(changeClock(bool)) );
155 connect( qApp, SIGNAL(weekChanged(bool)), 158 connect( qApp, SIGNAL(weekChanged(bool)),
156 this, SLOT(changeWeek(bool)) ); 159 this, SLOT(changeWeek(bool)) );
157 160
158#if defined(Q_WS_QWS) && !defined(QT_NO_COP) 161#if defined(Q_WS_QWS) && !defined(QT_NO_COP)
159 connect( qApp, SIGNAL(appMessage(const QCString&, const QByteArray&)), 162 connect( qApp, SIGNAL(appMessage(const QCString&, const QByteArray&)),
160 this, SLOT(appMessage(const QCString&, const QByteArray&)) ); 163 this, SLOT(appMessage(const QCString&, const QByteArray&)) );
161#endif 164#endif
162 165
163 // listen on QPE/System 166 // listen on QPE/System
164#if defined(Q_WS_QWS) 167#if defined(Q_WS_QWS)
165#if !defined(QT_NO_COP) 168#if !defined(QT_NO_COP)
166 QCopChannel *channel = new QCopChannel( "QPE/System", this ); 169 QCopChannel *channel = new QCopChannel( "QPE/System", this );
167 connect( channel, SIGNAL(received(const QCString&, const QByteArray&)), 170 connect( channel, SIGNAL(received(const QCString&, const QByteArray&)),
168 this, SLOT(receive(const QCString&, const QByteArray&)) ); 171 this, SLOT(receive(const QCString&, const QByteArray&)) );
169#endif 172#endif
170#endif 173#endif
171 174
172 qDebug("done t=%d", t.elapsed() ); 175 qDebug("done t=%d", t.elapsed() );
173 176
174} 177}
175 178
176void DateBook::receive( const QCString &msg, const QByteArray &data ) 179void DateBook::receive( const QCString &msg, const QByteArray &data )
177{ 180{
178 QDataStream stream( data, IO_ReadOnly ); 181 QDataStream stream( data, IO_ReadOnly );
179 if ( msg == "timeChange(QString)" ) { 182 if ( msg == "timeChange(QString)" ) {
180 // update active view! 183 // update active view!
181 if ( dayAction->isOn() ) 184 if ( dayAction->isOn() )
182 viewDay(); 185 viewDay();
183 else if ( weekAction->isOn() ) 186 else if ( weekAction->isOn() )
184 viewWeek(); 187 viewWeek();
185 else if ( monthAction->isOn() ) 188 else if ( monthAction->isOn() )
186 viewMonth(); 189 viewMonth();
187 } 190 }
188} 191}
189 192
190DateBook::~DateBook() 193DateBook::~DateBook()
191{ 194{
192} 195}
193 196
194void DateBook::slotSettings() 197void DateBook::slotSettings()
195{ 198{
196 DateBookSettings frmSettings( ampm, this ); 199 DateBookSettings frmSettings( ampm, this );
197 frmSettings.setStartTime( startTime ); 200 frmSettings.setStartTime( startTime );
198 frmSettings.setAlarmPreset( aPreset, presetTime ); 201 frmSettings.setAlarmPreset( aPreset, presetTime );
199#if defined (Q_WS_QWS) || defined(_WS_QWS_) 202#if defined (Q_WS_QWS) || defined(_WS_QWS_)
200 frmSettings.showMaximized(); 203 frmSettings.showMaximized();
201#endif 204#endif
202 205
203 if ( frmSettings.exec() ) { 206 if ( frmSettings.exec() ) {
204 aPreset = frmSettings.alarmPreset(); 207 aPreset = frmSettings.alarmPreset();
205 presetTime = frmSettings.presetTime(); 208 presetTime = frmSettings.presetTime();
206 startTime = frmSettings.startTime(); 209 startTime = frmSettings.startTime();
207 if ( dayView ) 210 if ( dayView )
208 dayView->setStartViewTime( startTime ); 211 dayView->setStartViewTime( startTime );
209 if ( weekView ) 212 if ( weekView )
210 weekView->setStartViewTime( startTime ); 213 weekView->setStartViewTime( startTime );
211 saveSettings(); 214 saveSettings();
212 215
213 // make the change obvious 216 // make the change obvious
214 if ( views->visibleWidget() ) { 217 if ( views->visibleWidget() ) {
215 if ( views->visibleWidget() == dayView ) 218 if ( views->visibleWidget() == dayView )
216 dayView->redraw(); 219 dayView->redraw();
217 else if ( views->visibleWidget() == weekView ) 220 else if ( views->visibleWidget() == weekView )
218 weekView->redraw(); 221 weekView->redraw();
219 } 222 }
220 } 223 }
221} 224}
222 225
223void DateBook::fileNew() 226void DateBook::fileNew()
224{ 227{
225 slotNewEventFromKey(""); 228 slotNewEventFromKey("");
226} 229}
227 230
228QString DateBook::checkEvent(const Event &e) 231QString DateBook::checkEvent(const Event &e)
229{ 232{
230 /* check if overlaps with itself */ 233 /* check if overlaps with itself */
231 bool checkFailed = FALSE; 234 bool checkFailed = FALSE;
232 235
233 /* check the next 12 repeats. should catch most problems */ 236 /* check the next 12 repeats. should catch most problems */
234 QDate current_date = e.start().date(); 237 QDate current_date = e.start().date();
235 Event previous = e; 238 Event previous = e;
236 for(int i = 0; i < 12; i++) 239 for(int i = 0; i < 12; i++)
237 { 240 {
238 QDateTime next; 241 QDateTime next;
239 if (!nextOccurance(previous, current_date.addDays(1), next)) { 242 if (!nextOccurance(previous, current_date.addDays(1), next)) {
240 break; // no more repeats 243 break; // no more repeats
241 } 244 }
242 if(next < previous.end()) { 245 if(next < previous.end()) {
243 checkFailed = TRUE; 246 checkFailed = TRUE;
244 break; 247 break;
245 } 248 }
246 current_date = next.date(); 249 current_date = next.date();
247 } 250 }
248 251
249 if(checkFailed) 252 if(checkFailed)
250 return tr("Event duration is potentially longer\n" 253 return tr("Event duration is potentially longer\n"
251 "than interval between repeats."); 254 "than interval between repeats.");
252 255
253 return QString::null; 256 return QString::null;
254} 257}
255 258
256QDate DateBook::currentDate() 259QDate DateBook::currentDate()
257{ 260{
258 QDate d = QDate::currentDate(); 261 QDate d = QDate::currentDate();
259 262
260 if ( dayView && views->visibleWidget() == dayView ) { 263 if ( dayView && views->visibleWidget() == dayView ) {
261 d = dayView->date(); 264 d = dayView->date();
262 } else if ( weekView && views->visibleWidget() == weekView ) { 265 } else if ( weekView && views->visibleWidget() == weekView ) {
263 d = weekView->date(); 266 d = weekView->date();
264 } else if ( monthView && views->visibleWidget() == monthView ) { 267 } else if ( monthView && views->visibleWidget() == monthView ) {
265 d = monthView->selectedDate(); 268 d = monthView->selectedDate();
266 } 269 }
267 270
268 return d; 271 return d;
269} 272}
270 273
271void DateBook::viewDay() 274void DateBook::viewDay()
272{ 275{
273 initDay(); 276 initDay();
274 dayAction->setOn( TRUE ); 277 dayAction->setOn( TRUE );
275 QDate d = currentDate(); 278 QDate d = currentDate();
276 dayView->setDate( d ); 279 dayView->setDate( d );
277 views->raiseWidget( dayView ); 280 views->raiseWidget( dayView );
278 dayView->redraw(); 281 dayView->redraw();
279} 282}
280 283
281void DateBook::viewWeek() 284void DateBook::viewWeek()
282{ 285{
283 initWeek(); 286 initWeek();
284 weekAction->setOn( TRUE ); 287 weekAction->setOn( TRUE );
285 QDate d = currentDate(); 288 QDate d = currentDate();
286 weekView->setDate( d ); 289 weekView->setDate( d );
287 views->raiseWidget( weekView ); 290 views->raiseWidget( weekView );
288 weekView->redraw(); 291 weekView->redraw();
289} 292}
290 293
291void DateBook::viewMonth() 294void DateBook::viewMonth()
292{ 295{
293 initMonth(); 296 initMonth();
294 monthAction->setOn( TRUE ); 297 monthAction->setOn( TRUE );
295 QDate d = currentDate(); 298 QDate d = currentDate();
296 monthView->setDate( d.year(), d.month(), d.day() ); 299 monthView->setDate( d.year(), d.month(), d.day() );
297 views->raiseWidget( monthView ); 300 views->raiseWidget( monthView );
298 monthView->redraw(); 301 monthView->redraw();
299} 302}
300 303
301void DateBook::editEvent( const Event &e ) 304void DateBook::editEvent( const Event &e )
302{ 305{
303 if (syncing) { 306 if (syncing) {
304 QMessageBox::warning( this, tr("Calendar"), 307 QMessageBox::warning( this, tr("Calendar"),
305 tr( "Can not edit data, currently syncing") ); 308 tr( "Can not edit data, currently syncing") );
306 return; 309 return;
307 } 310 }
308 311
309 // workaround added for text input. 312 // workaround added for text input.
310 QDialog editDlg( this, 0, TRUE ); 313 QDialog editDlg( this, 0, TRUE );
311 DateEntry *entry; 314 DateEntry *entry;
312 editDlg.setCaption( tr("Edit Event") ); 315 editDlg.setCaption( tr("Edit Event") );
313 QVBoxLayout *vb = new QVBoxLayout( &editDlg ); 316 QVBoxLayout *vb = new QVBoxLayout( &editDlg );
314 QScrollView *sv = new QScrollView( &editDlg, "scrollview" ); 317 QScrollView *sv = new QScrollView( &editDlg, "scrollview" );
315 sv->setResizePolicy( QScrollView::AutoOneFit ); 318 sv->setResizePolicy( QScrollView::AutoOneFit );
316 // KLUDGE!!! 319 // KLUDGE!!!
317 sv->setHScrollBarMode( QScrollView::AlwaysOff ); 320 sv->setHScrollBarMode( QScrollView::AlwaysOff );
318 vb->addWidget( sv ); 321 vb->addWidget( sv );
319 entry = new DateEntry( onMonday, e, ampm, &editDlg, "editor" ); 322 entry = new DateEntry( onMonday, e, ampm, &editDlg, "editor" );
320 entry->timezone->setEnabled( FALSE ); 323 entry->timezone->setEnabled( FALSE );
321 sv->addChild( entry ); 324 sv->addChild( entry );
322 325
323#if defined(Q_WS_QWS) || defined(_WS_QWS_) 326#if defined(Q_WS_QWS) || defined(_WS_QWS_)
324 editDlg.showMaximized(); 327 editDlg.showMaximized();
325#endif 328#endif
326 while (editDlg.exec() ) { 329 while (editDlg.exec() ) {
327 Event newEv = entry->event(); 330 Event newEv = entry->event();
328 QString error = checkEvent(newEv); 331 QString error = checkEvent(newEv);
329 if (!error.isNull()) { 332 if (!error.isNull()) {
330 if (QMessageBox::warning(this, "error box", 333 if (QMessageBox::warning(this, "error box",
331 error, "Fix it", "Continue", 0, 0, 1) == 0) 334 error, "Fix it", "Continue", 0, 0, 1) == 0)
332 continue; 335 continue;
333 } 336 }
334 db->editEvent(e, newEv); 337 db->editEvent(e, newEv);
335 emit newEvent(); 338 emit newEvent();
336 break; 339 break;
337 } 340 }
338} 341}
339 342
340void DateBook::removeEvent( const Event &e ) 343void DateBook::removeEvent( const Event &e )
341{ 344{
342 if (syncing) { 345 if (syncing) {
343 QMessageBox::warning( this, tr("Calendar"), 346 QMessageBox::warning( this, tr("Calendar"),
344 tr( "Can not edit data, currently syncing") ); 347 tr( "Can not edit data, currently syncing") );
345 return; 348 return;
346 } 349 }
347 350
348 QString strName = e.description(); 351 QString strName = e.description();
349 352
350 if ( !QPEMessageBox::confirmDelete( this, tr( "Calendar" ),strName ) ) 353 if ( !QPEMessageBox::confirmDelete( this, tr( "Calendar" ),strName ) )
351 return; 354 return;
352 355
353 db->removeEvent( e ); 356 db->removeEvent( e );
354 if ( views->visibleWidget() == dayView && dayView ) 357 if ( views->visibleWidget() == dayView && dayView )
355 dayView->redraw(); 358 dayView->redraw();
356} 359}
357 360
358void DateBook::addEvent( const Event &e ) 361void DateBook::addEvent( const Event &e )
359{ 362{
360 QDate d = e.start().date(); 363 QDate d = e.start().date();
361 initDay(); 364 initDay();
362 dayView->setDate( d ); 365 dayView->setDate( d );
363} 366}
364 367
365void DateBook::showDay( int year, int month, int day ) 368void DateBook::showDay( int year, int month, int day )
366{ 369{
367 initDay(); 370 initDay();
368 dayView->setDate( year, month, day ); 371 dayView->setDate( year, month, day );
369 views->raiseWidget( dayView ); 372 views->raiseWidget( dayView );
370 dayAction->setOn( TRUE ); 373 dayAction->setOn( TRUE );
371} 374}
372 375
373void DateBook::initDay() 376void DateBook::initDay()
374{ 377{
375 if ( !dayView ) { 378 if ( !dayView ) {
376 dayView = new DateBookDay( ampm, onMonday, db, views, "day view" ); 379 dayView = new DateBookDay( ampm, onMonday, db, views, "day view" );
377 views->addWidget( dayView, DAY ); 380 views->addWidget( dayView, DAY );
378 dayView->setStartViewTime( startTime ); 381 dayView->setStartViewTime( startTime );
379 connect( this, SIGNAL( newEvent() ), 382 connect( this, SIGNAL( newEvent() ),
380 dayView, SLOT( redraw() ) ); 383 dayView, SLOT( redraw() ) );
381 connect( dayView, SIGNAL( newEvent() ), 384 connect( dayView, SIGNAL( newEvent() ),
382 this, SLOT( fileNew() ) ); 385 this, SLOT( fileNew() ) );
383 connect( dayView, SIGNAL( removeEvent( const Event & ) ), 386 connect( dayView, SIGNAL( removeEvent( const Event & ) ),
384 this, SLOT( removeEvent( const Event & ) ) ); 387 this, SLOT( removeEvent( const Event & ) ) );
385 connect( dayView, SIGNAL( editEvent( const Event & ) ), 388 connect( dayView, SIGNAL( editEvent( const Event & ) ),
386 this, SLOT( editEvent( const Event & ) ) ); 389 this, SLOT( editEvent( const Event & ) ) );
387 connect( dayView, SIGNAL( beamEvent( const Event & ) ), 390 connect( dayView, SIGNAL( beamEvent( const Event & ) ),
388 this, SLOT( beamEvent( const Event & ) ) ); 391 this, SLOT( beamEvent( const Event & ) ) );
389 connect( dayView, SIGNAL(sigNewEvent(const QString &)), 392 connect( dayView, SIGNAL(sigNewEvent(const QString &)),
390 this, SLOT(slotNewEventFromKey(const QString &)) ); 393 this, SLOT(slotNewEventFromKey(const QString &)) );
391 } 394 }
392} 395}
393 396
394void DateBook::initWeek() 397void DateBook::initWeek()
395{ 398{
396 if ( !weekView ) { 399 if ( !weekView ) {
397 weekView = new DateBookWeek( ampm, onMonday, db, views, "week view" ); 400 weekView = new DateBookWeek( ampm, onMonday, db, views, "week view" );
398 weekView->setStartViewTime( startTime ); 401 weekView->setStartViewTime( startTime );
399 views->addWidget( weekView, WEEK ); 402 views->addWidget( weekView, WEEK );
400 connect( weekView, SIGNAL( showDate( int, int, int ) ), 403 connect( weekView, SIGNAL( showDate( int, int, int ) ),
401 this, SLOT( showDay( int, int, int ) ) ); 404 this, SLOT( showDay( int, int, int ) ) );
402 connect( this, SIGNAL( newEvent() ), 405 connect( this, SIGNAL( newEvent() ),
403 weekView, SLOT( redraw() ) ); 406 weekView, SLOT( redraw() ) );
404 } 407 }
405 //But also get it right: the year that we display can be different 408 //But also get it right: the year that we display can be different
406 //from the year of the current date. So, first find the year 409 //from the year of the current date. So, first find the year
407 //number of the current week. 410 //number of the current week.
408 411
409 int yearNumber, totWeeks; 412 int yearNumber, totWeeks;
410 calcWeek( currentDate(), totWeeks, yearNumber, onMonday ); 413 calcWeek( currentDate(), totWeeks, yearNumber, onMonday );
411 414
412 QDate d = QDate( yearNumber, 12, 31 ); 415 QDate d = QDate( yearNumber, 12, 31 );
413 calcWeek( d, totWeeks, yearNumber, onMonday ); 416 calcWeek( d, totWeeks, yearNumber, onMonday );
414 417
415 while ( totWeeks == 1 ) { 418 while ( totWeeks == 1 ) {
416 d = d.addDays( -1 ); 419 d = d.addDays( -1 );
417 calcWeek( d, totWeeks, yearNumber, onMonday ); 420 calcWeek( d, totWeeks, yearNumber, onMonday );
418 } 421 }
419 if ( totWeeks != weekView->totalWeeks() ) 422 if ( totWeeks != weekView->totalWeeks() )
420 weekView->setTotalWeeks( totWeeks ); 423 weekView->setTotalWeeks( totWeeks );
421} 424}
422 425
423void DateBook::initMonth() 426void DateBook::initMonth()
424{ 427{
425 if ( !monthView ) { 428 if ( !monthView ) {
426 monthView = new DateBookMonth( views, "month view", FALSE, db ); 429 monthView = new DateBookMonth( views, "month view", FALSE, db );
427 views->addWidget( monthView, MONTH ); 430 views->addWidget( monthView, MONTH );
428 connect( monthView, SIGNAL( dateClicked( int, int, int ) ), 431 connect( monthView, SIGNAL( dateClicked( int, int, int ) ),
429 this, SLOT( showDay( int, int, int ) ) ); 432 this, SLOT( showDay( int, int, int ) ) );
430 connect( this, SIGNAL( newEvent() ), 433 connect( this, SIGNAL( newEvent() ),
431 monthView, SLOT( redraw() ) ); 434 monthView, SLOT( redraw() ) );
432 qApp->processEvents(); 435 qApp->processEvents();
433 } 436 }
434} 437}
435 438
436void DateBook::loadSettings() 439void DateBook::loadSettings()
437{ 440{
438 { 441 {
439 Config config( "qpe" ); 442 Config config( "qpe" );
440 config.setGroup("Time"); 443 config.setGroup("Time");
441 ampm = config.readBoolEntry( "AMPM", TRUE ); 444 ampm = config.readBoolEntry( "AMPM", TRUE );
442 onMonday = config.readBoolEntry( "MONDAY" ); 445 onMonday = config.readBoolEntry( "MONDAY" );
443 } 446 }
444 447
445 { 448 {
446 Config config("DateBook"); 449 Config config("DateBook");
447 config.setGroup("Main"); 450 config.setGroup("Main");
448 startTime = config.readNumEntry("startviewtime", 8); 451 startTime = config.readNumEntry("startviewtime", 8);
449 aPreset = config.readBoolEntry("alarmpreset"); 452 aPreset = config.readBoolEntry("alarmpreset");
450 presetTime = config.readNumEntry("presettime"); 453 presetTime = config.readNumEntry("presettime");
451 } 454 }
452} 455}
453 456
454void DateBook::saveSettings() 457void DateBook::saveSettings()
455{ 458{
456 Config config( "qpe" ); 459 Config config( "qpe" );
457 Config configDB( "DateBook" ); 460 Config configDB( "DateBook" );
458 configDB.setGroup( "Main" ); 461 configDB.setGroup( "Main" );
459 configDB.writeEntry("startviewtime",startTime); 462 configDB.writeEntry("startviewtime",startTime);
460 configDB.writeEntry("alarmpreset",aPreset); 463 configDB.writeEntry("alarmpreset",aPreset);
461 configDB.writeEntry("presettime",presetTime); 464 configDB.writeEntry("presettime",presetTime);
462} 465}
463 466
464void DateBook::appMessage(const QCString& msg, const QByteArray& data) 467void DateBook::appMessage(const QCString& msg, const QByteArray& data)
465{ 468{
466 bool needShow = FALSE; 469 bool needShow = FALSE;
467 if ( msg == "alarm(QDateTime,int)" ) { 470 if ( msg == "alarm(QDateTime,int)" ) {
468 QDataStream ds(data,IO_ReadOnly); 471 QDataStream ds(data,IO_ReadOnly);
469 QDateTime when; int warn; 472 QDateTime when; int warn;
470 ds >> when >> warn; 473 ds >> when >> warn;
471 474
472 // check to make it's okay to continue, 475 // check to make it's okay to continue,
473 // this is the case that the time was set ahead, and 476 // this is the case that the time was set ahead, and
474 // we are forced given a stale alarm... 477 // we are forced given a stale alarm...
475 QDateTime current = QDateTime::currentDateTime(); 478 QDateTime current = QDateTime::currentDateTime();
476 if ( current.time().hour() != when.time().hour() 479 if ( current.time().hour() != when.time().hour()
477 && current.time().minute() != when.time().minute() ) 480 && current.time().minute() != when.time().minute() )
478 return; 481 return;
479 482
480 QValueList<EffectiveEvent> list = db->getEffectiveEvents(when.addSecs(warn*60)); 483 QValueList<EffectiveEvent> list = db->getEffectiveEvents(when.addSecs(warn*60));
481 if ( list.count() > 0 ) { 484 if ( list.count() > 0 ) {
482 QString msg; 485 QString msg;
483 bool bSound = FALSE; 486 bool bSound = FALSE;
484 int stopTimer = 0; 487 int stopTimer = 0;
485 bool found = FALSE; 488 bool found = FALSE;
486 for ( QValueList<EffectiveEvent>::ConstIterator it=list.begin(); 489 for ( QValueList<EffectiveEvent>::ConstIterator it=list.begin();
487 it!=list.end(); ++it ) { 490 it!=list.end(); ++it ) {
488 if ( (*it).event().hasAlarm() ) { 491 if ( (*it).event().hasAlarm() ) {
489 found = TRUE; 492 found = TRUE;
490 msg += "<CENTER><B>" + (*it).description() + "</B>" 493 msg += "<CENTER><B>" + (*it).description() + "</B>"
491 + "<BR>" + (*it).location() + "<BR>" 494 + "<BR>" + (*it).location() + "<BR>"
492 + TimeString::dateString((*it).event().start(),ampm) 495 + TimeString::dateString((*it).event().start(),ampm)
493 + (warn 496 + (warn
494 ? tr(" (in " + QString::number(warn) 497 ? tr(" (in " + QString::number(warn)
495 + tr(" minutes)")) 498 + tr(" minutes)"))
496 : QString("")) 499 : QString(""))
497 + "<BR>" 500 + "<BR>"
498 + (*it).notes() + "</CENTER>"; 501 + (*it).notes() + "</CENTER>";
499 if ( (*it).event().alarmSound() != Event::Silent ) { 502 if ( (*it).event().alarmSound() != Event::Silent ) {
500 bSound = TRUE; 503 bSound = TRUE;
501 } 504 }
502 } 505 }
503 } 506 }
504 if ( found ) { 507 if ( found ) {
505 if ( bSound ) { 508 if ( bSound ) {
506 Sound::soundAlarm(); 509 Sound::soundAlarm();
507 stopTimer = startTimer( 5000 ); 510 stopTimer = startTimer( 5000 );
508 } 511 }
509 512
510 QDialog dlg( this, 0, TRUE ); 513 QDialog dlg( this, 0, TRUE );
511 QVBoxLayout *vb = new QVBoxLayout( &dlg ); 514 QVBoxLayout *vb = new QVBoxLayout( &dlg );
512 QScrollView *view = new QScrollView( &dlg, "scrollView"); 515 QScrollView *view = new QScrollView( &dlg, "scrollView");
513 view->setResizePolicy( QScrollView::AutoOneFit ); 516 view->setResizePolicy( QScrollView::AutoOneFit );
514 vb->addWidget( view ); 517 vb->addWidget( view );
515 QLabel *lblMsg = new QLabel( msg, &dlg ); 518 QLabel *lblMsg = new QLabel( msg, &dlg );
516 view->addChild( lblMsg ); 519 view->addChild( lblMsg );
517 QPushButton *cmdOk = new QPushButton( tr("OK"), &dlg ); 520 QPushButton *cmdOk = new QPushButton( tr("OK"), &dlg );
518 connect( cmdOk, SIGNAL(clicked()), &dlg, SLOT(accept()) ); 521 connect( cmdOk, SIGNAL(clicked()), &dlg, SLOT(accept()) );
519 vb->addWidget( cmdOk ); 522 vb->addWidget( cmdOk );
520 523
521#if defined(Q_WS_QWS) || defined(_WS_QWS_) 524#if defined(Q_WS_QWS) || defined(_WS_QWS_)
522 dlg.showMaximized(); 525 dlg.showMaximized();
523#endif 526#endif
524 needShow = dlg.exec(); 527 needShow = dlg.exec();
525 528
526 if ( bSound ) 529 if ( bSound )
527 killTimer( stopTimer ); 530 killTimer( stopTimer );
528 } 531 }
529 } 532 }
530 } else if ( msg == "nextView()" ) { 533 } else if ( msg == "nextView()" ) {
531 QWidget* cur = views->visibleWidget(); 534 QWidget* cur = views->visibleWidget();
532 if ( cur ) { 535 if ( cur ) {
533 if ( cur == dayView ) 536 if ( cur == dayView )
534 viewWeek(); 537 viewWeek();
535 else if ( cur == weekView ) 538 else if ( cur == weekView )
536 viewMonth(); 539 viewMonth();
537 else if ( cur == monthView ) 540 else if ( cur == monthView )
538 viewDay(); 541 viewDay();
539 needShow = TRUE; 542 needShow = TRUE;
540 } 543 }
541 } 544 }
542 if ( needShow ) { 545 if ( needShow ) {
543#if defined(Q_WS_QWS) || defined(_WS_QWS_) 546#if defined(Q_WS_QWS) || defined(_WS_QWS_)
544 showMaximized(); 547 showMaximized();
545#else 548#else
546 show(); 549 show();
547#endif 550#endif
548 raise(); 551 raise();
549 QPEApplication::setKeepRunning(); 552 QPEApplication::setKeepRunning();
550 setActiveWindow(); 553 setActiveWindow();
551 } 554 }
552} 555}
553 556
554void DateBook::reload() 557void DateBook::reload()
555{ 558{
556 db->reload(); 559 db->reload();
557 if ( dayAction->isOn() ) 560 if ( dayAction->isOn() )
558 viewDay(); 561 viewDay();
559 else if ( weekAction->isOn() ) 562 else if ( weekAction->isOn() )
560 viewWeek(); 563 viewWeek();
561 else if ( monthAction->isOn() ) 564 else if ( monthAction->isOn() )
562 viewMonth(); 565 viewMonth();
563 syncing = FALSE; 566 syncing = FALSE;
564} 567}
565 568
566void DateBook::flush() 569void DateBook::flush()
567{ 570{
568 syncing = TRUE; 571 syncing = TRUE;
569 db->save(); 572 db->save();
570} 573}
571 574
572void DateBook::timerEvent( QTimerEvent *e ) 575void DateBook::timerEvent( QTimerEvent *e )
573{ 576{
574 static int stop = 0; 577 static int stop = 0;
575 if ( stop < 10 ) { 578 if ( stop < 10 ) {
576 Sound::soundAlarm(); 579 Sound::soundAlarm();
577 stop++; 580 stop++;
578 } else { 581 } else {
579 stop = 0; 582 stop = 0;
580 killTimer( e->timerId() ); 583 killTimer( e->timerId() );
581 } 584 }
582} 585}
583 586
584void DateBook::changeClock( bool newClock ) 587void DateBook::changeClock( bool newClock )
585{ 588{
586 ampm = newClock; 589 ampm = newClock;
587 // repaint the affected objects... 590 // repaint the affected objects...
588 if (dayView) dayView->redraw(); 591 if (dayView) dayView->redraw();
589 if (weekView) weekView->redraw(); 592 if (weekView) weekView->redraw();
590} 593}
591 594
592void DateBook::changeWeek( bool m ) 595void DateBook::changeWeek( bool m )
593{ 596{
594 /* no need to redraw, each widget catches. Do need to 597 /* no need to redraw, each widget catches. Do need to
595 store though for widgets we haven't made yet */ 598 store though for widgets we haven't made yet */
596 onMonday = m; 599 onMonday = m;
597} 600}
598 601
599void DateBook::slotToday() 602void DateBook::slotToday()
600{ 603{
601 // we need to view today 604 // we need to view today
602 QDate dt = QDate::currentDate(); 605 QDate dt = QDate::currentDate();
603 showDay( dt.year(), dt.month(), dt.day() ); 606 showDay( dt.year(), dt.month(), dt.day() );
604} 607}
605 608
606void DateBook::closeEvent( QCloseEvent *e ) 609void DateBook::closeEvent( QCloseEvent *e )
607{ 610{
608 if(syncing) { 611 if(syncing) {
609 /* no need to save, did that at flush */ 612 /* no need to save, did that at flush */
610 e->accept(); 613 e->accept();
611 return; 614 return;
612 } 615 }
613 616
614 // save settings will generate it's own error messages, no 617 // save settings will generate it's own error messages, no
615 // need to do checking ourselves. 618 // need to do checking ourselves.
616 saveSettings(); 619 saveSettings();
617 if ( db->save() ) 620 if ( db->save() )
618 e->accept(); 621 e->accept();
619 else { 622 else {
620 if ( QMessageBox::critical( this, tr( "Out of space" ), 623 if ( QMessageBox::critical( this, tr( "Out of space" ),
621 tr("Calendar was unable to save\n" 624 tr("Calendar was unable to save\n"
622 "your changes.\n" 625 "your changes.\n"
623 "Free up some space and try again.\n" 626 "Free up some space and try again.\n"
624 "\nQuit anyway?"), 627 "\nQuit anyway?"),
625 QMessageBox::Yes|QMessageBox::Escape, 628 QMessageBox::Yes|QMessageBox::Escape,
626 QMessageBox::No|QMessageBox::Default ) 629 QMessageBox::No|QMessageBox::Default )
627 != QMessageBox::No ) 630 != QMessageBox::No )
628 e->accept(); 631 e->accept();
629 else 632 else
630 e->ignore(); 633 e->ignore();
631 } 634 }
632} 635}
633 636
634// Entering directly from the "keyboard" 637// Entering directly from the "keyboard"
635void DateBook::slotNewEventFromKey( const QString &str ) 638void DateBook::slotNewEventFromKey( const QString &str )
636{ 639{
637 if (syncing) { 640 if (syncing) {
638 QMessageBox::warning( this, tr("Calendar"), 641 QMessageBox::warning( this, tr("Calendar"),
639 tr( "Can not edit data, currently syncing") ); 642 tr( "Can not edit data, currently syncing") );
640 return; 643 return;
641 } 644 }
642 645
643 // We get to here from a key pressed in the Day View 646 // We get to here from a key pressed in the Day View
644 // So we can assume some things. We want the string 647 // So we can assume some things. We want the string
645 // passed in to be part of the description. 648 // passed in to be part of the description.
646 QDateTime start, end; 649 QDateTime start, end;
647 if ( views->visibleWidget() == dayView ) { 650 if ( views->visibleWidget() == dayView ) {
648 dayView->selectedDates( start, end ); 651 dayView->selectedDates( start, end );
649 } else if ( views->visibleWidget() == monthView ) { 652 } else if ( views->visibleWidget() == monthView ) {
650 QDate d = monthView->selectedDate(); 653 QDate d = monthView->selectedDate();
651 start = end = d; 654 start = end = d;
652 start.setTime( QTime( 10, 0 ) ); 655 start.setTime( QTime( 10, 0 ) );
653 end.setTime( QTime( 12, 0 ) ); 656 end.setTime( QTime( 12, 0 ) );
654 } else if ( views->visibleWidget() == weekView ) { 657 } else if ( views->visibleWidget() == weekView ) {
655 QDate d = weekView->date(); 658 QDate d = weekView->date();
656 start = end = d; 659 start = end = d;
657 start.setTime( QTime( 10, 0 ) ); 660 start.setTime( QTime( 10, 0 ) );
658 end.setTime( QTime( 12, 0 ) ); 661 end.setTime( QTime( 12, 0 ) );
659 } 662 }
660 663
661 // argh! This really needs to be encapsulated in a class 664 // argh! This really needs to be encapsulated in a class
662 // or function. 665 // or function.
663 QDialog newDlg( this, 0, TRUE ); 666 QDialog newDlg( this, 0, TRUE );
664 newDlg.setCaption( DateEntryBase::tr("New Event") ); 667 newDlg.setCaption( DateEntryBase::tr("New Event") );
665 DateEntry *e; 668 DateEntry *e;
666 QVBoxLayout *vb = new QVBoxLayout( &newDlg ); 669 QVBoxLayout *vb = new QVBoxLayout( &newDlg );
667 QScrollView *sv = new QScrollView( &newDlg ); 670 QScrollView *sv = new QScrollView( &newDlg );
668 sv->setResizePolicy( QScrollView::AutoOneFit ); 671 sv->setResizePolicy( QScrollView::AutoOneFit );
669 sv->setFrameStyle( QFrame::NoFrame ); 672 sv->setFrameStyle( QFrame::NoFrame );
670 sv->setHScrollBarMode( QScrollView::AlwaysOff ); 673 sv->setHScrollBarMode( QScrollView::AlwaysOff );
671 vb->addWidget( sv ); 674 vb->addWidget( sv );
672 675
673 Event ev; 676 Event ev;
674 ev.setDescription( str ); 677 ev.setDescription( str );
675 // When the new gui comes in, change this... 678 // When the new gui comes in, change this...
676 ev.setLocation( tr("(Unknown)") ); 679 ev.setLocation( tr("(Unknown)") );
677 ev.setStart( start ); 680 ev.setStart( start );
678 ev.setEnd( end ); 681 ev.setEnd( end );
679 682
680 e = new DateEntry( onMonday, ev, ampm, &newDlg ); 683 e = new DateEntry( onMonday, ev, ampm, &newDlg );
681 e->setAlarmEnabled( aPreset, presetTime, Event::Loud ); 684 e->setAlarmEnabled( aPreset, presetTime, Event::Loud );
682 sv->addChild( e ); 685 sv->addChild( e );
683#if defined(Q_WS_QWS) || defined(_WS_QWS_) 686#if defined(Q_WS_QWS) || defined(_WS_QWS_)
684 newDlg.showMaximized(); 687 newDlg.showMaximized();
685#endif 688#endif
686 while (newDlg.exec()) { 689 while (newDlg.exec()) {
687 ev = e->event(); 690 ev = e->event();
688 ev.assignUid(); 691 ev.assignUid();
689 QString error = checkEvent( ev ); 692 QString error = checkEvent( ev );
690 if ( !error.isNull() ) { 693 if ( !error.isNull() ) {
691 if ( QMessageBox::warning( this, tr("Error!"), 694 if ( QMessageBox::warning( this, tr("Error!"),
692 error, tr("Fix it"), tr("Continue"), 0, 0, 1 ) == 0 ) 695 error, tr("Fix it"), tr("Continue"), 0, 0, 1 ) == 0 )
693 continue; 696 continue;
694 } 697 }
695 db->addEvent( ev ); 698 db->addEvent( ev );
696 emit newEvent(); 699 emit newEvent();
697 break; 700 break;
698 } 701 }
699} 702}
700 703
701void DateBook::setDocument( const QString &filename ) 704void DateBook::setDocument( const QString &filename )
702{ 705{
703 if ( filename.find(".vcs") != int(filename.length()) - 4 ) return; 706 if ( filename.find(".vcs") != int(filename.length()) - 4 ) return;
704 707
705 QValueList<Event> tl = Event::readVCalendar( filename ); 708 QValueList<Event> tl = Event::readVCalendar( filename );
706 for( QValueList<Event>::Iterator it = tl.begin(); it != tl.end(); ++it ) { 709 for( QValueList<Event>::Iterator it = tl.begin(); it != tl.end(); ++it ) {
707 db->addEvent( *it ); 710 db->addEvent( *it );
708 } 711 }
709} 712}
710 713
711static const char * beamfile = "/tmp/obex/event.vcs"; 714static const char * beamfile = "/tmp/obex/event.vcs";
712 715
713void DateBook::beamEvent( const Event &e ) 716void DateBook::beamEvent( const Event &e )
714{ 717{
715 qDebug("trying to beamn"); 718 qDebug("trying to beamn");
716 unlink( beamfile ); // delete if exists 719 unlink( beamfile ); // delete if exists
717 mkdir("/tmp/obex/", 0755); 720 mkdir("/tmp/obex/", 0755);
718 Event::writeVCalendar( beamfile, e ); 721 Event::writeVCalendar( beamfile, e );
719 Ir *ir = new Ir( this ); 722 Ir *ir = new Ir( this );
720 connect( ir, SIGNAL( done( Ir * ) ), this, SLOT( beamDone( Ir * ) ) ); 723 connect( ir, SIGNAL( done( Ir * ) ), this, SLOT( beamDone( Ir * ) ) );
721 QString description = e.description(); 724 QString description = e.description();
722 ir->send( beamfile, description, "text/x-vCalendar" ); 725 ir->send( beamfile, description, "text/x-vCalendar" );
723} 726}
724 727
725void DateBook::beamDone( Ir *ir ) 728void DateBook::beamDone( Ir *ir )
726{ 729{
727 delete ir; 730 delete ir;
728 unlink( beamfile ); 731 unlink( beamfile );
729} 732}
730 733
731void DateBook::slotFind() 734void DateBook::slotFind()
732{ 735{
733 // move it to the day view... 736 // move it to the day view...
734 viewDay(); 737 viewDay();
735 FindDialog frmFind( "Calendar", this ); 738 FindDialog frmFind( "Calendar", this );
736 frmFind.setUseDate( true ); 739 frmFind.setUseDate( true );
737 frmFind.setDate( currentDate() ); 740 frmFind.setDate( currentDate() );
738 QObject::connect( &frmFind, 741 QObject::connect( &frmFind,
739 SIGNAL(signalFindClicked(const QString&, const QDate&, 742 SIGNAL(signalFindClicked(const QString&, const QDate&,
740 bool, bool, int)), 743 bool, bool, int)),
741 this, 744 this,
742 SLOT(slotDoFind(const QString&, const QDate&, 745 SLOT(slotDoFind(const QString&, const QDate&,
743 bool, bool, int)) ); 746 bool, bool, int)) );
744 QObject::connect( this, 747 QObject::connect( this,
745 SIGNAL(signalNotFound()), 748 SIGNAL(signalNotFound()),
746 &frmFind, 749 &frmFind,
747 SLOT(slotNotFound()) ); 750 SLOT(slotNotFound()) );
748 QObject::connect( this, 751 QObject::connect( this,
749 SIGNAL(signalWrapAround()), 752 SIGNAL(signalWrapAround()),
750 &frmFind, 753 &frmFind,
751 SLOT(slotWrapAround()) ); 754 SLOT(slotWrapAround()) );
752 frmFind.exec(); 755 frmFind.exec();
753 inSearch = false; 756 inSearch = false;
754} 757}
755 758
756bool catComp( QArray<int> cats, int category ) 759bool catComp( QArray<int> cats, int category )
757{ 760{
758 bool returnMe; 761 bool returnMe;
759 int i, 762 int i,
760 count; 763 count;
761 764
762 count = int(cats.count()); 765 count = int(cats.count());
763 returnMe = false; 766 returnMe = false;
764 if ( (category == -1 && count == 0) || category == -2 ) 767 if ( (category == -1 && count == 0) || category == -2 )
765 returnMe = true; 768 returnMe = true;
766 else { 769 else {
767 for ( i = 0; i < count; i++ ) { 770 for ( i = 0; i < count; i++ ) {
768 if ( category == cats[i] ) { 771 if ( category == cats[i] ) {
769 returnMe = true; 772 returnMe = true;
770 break; 773 break;
771 } 774 }
772 } 775 }
773 } 776 }
774 return returnMe; 777 return returnMe;
775} 778}
776 779
777 780
778void DateBook::slotDoFind( const QString& txt, const QDate &dt, 781void DateBook::slotDoFind( const QString& txt, const QDate &dt,
779 bool caseSensitive, bool /*backwards*/, 782 bool caseSensitive, bool /*backwards*/,
780 int category ) 783 int category )
781{ 784{
782 QDateTime dtEnd( QDate(3001, 1, 1), QTime(0, 0, 0) ), 785 QDateTime dtEnd( QDate(3001, 1, 1), QTime(0, 0, 0) ),
783 next; 786 next;
784 787
785 QRegExp r( txt ); 788 QRegExp r( txt );
786 r.setCaseSensitive( caseSensitive ); 789 r.setCaseSensitive( caseSensitive );
787 790
788 791
789 static Event rev, 792 static Event rev,
790 nonrev; 793 nonrev;
791 if ( !inSearch ) { 794 if ( !inSearch ) {
792 rev.setStart( QDateTime(QDate(1960, 1, 1), QTime(0, 0, 0)) ); 795 rev.setStart( QDateTime(QDate(1960, 1, 1), QTime(0, 0, 0)) );
793 nonrev.setStart( rev.start() ); 796 nonrev.setStart( rev.start() );
794 inSearch = true; 797 inSearch = true;
795 } 798 }
796 static QDate searchDate = dt; 799 static QDate searchDate = dt;
797 static bool wrapAround = true; 800 static bool wrapAround = true;
798 bool candidtate; 801 bool candidtate;
799 candidtate = false; 802 candidtate = false;
800 803
801 QValueList<Event> repeats = db->getRawRepeats(); 804 QValueList<Event> repeats = db->getRawRepeats();
802 805
803 // find the candidate for the first repeat that matches... 806 // find the candidate for the first repeat that matches...
804 QValueListConstIterator<Event> it; 807 QValueListConstIterator<Event> it;
805 QDate start = dt; 808 QDate start = dt;
806 for ( it = repeats.begin(); it != repeats.end(); ++it ) { 809 for ( it = repeats.begin(); it != repeats.end(); ++it ) {
807 if ( catComp( (*it).categories(), category ) ) { 810 if ( catComp( (*it).categories(), category ) ) {
808 while ( nextOccurance( *it, start, next ) ) { 811 while ( nextOccurance( *it, start, next ) ) {
809 if ( next < dtEnd ) { 812 if ( next < dtEnd ) {
810 if ( (*it).match( r ) && !(next <= rev.start()) ) { 813 if ( (*it).match( r ) && !(next <= rev.start()) ) {
811 rev = *it; 814 rev = *it;
812 dtEnd = next; 815 dtEnd = next;
813 rev.setStart( next ); 816 rev.setStart( next );
814 candidtate = true; 817 candidtate = true;
815 wrapAround = true; 818 wrapAround = true;
816 start = dt; 819 start = dt;
817 break; 820 break;
818 } else 821 } else
819 start = next.date().addDays( 1 ); 822 start = next.date().addDays( 1 );
820 } 823 }
821 } 824 }
822 } 825 }
823 } 826 }
824 827
825 // now the for first non repeat... 828 // now the for first non repeat...
826 QValueList<Event> nonRepeats = db->getNonRepeatingEvents( dt, dtEnd.date() ); 829 QValueList<Event> nonRepeats = db->getNonRepeatingEvents( dt, dtEnd.date() );
827 qHeapSort( nonRepeats.begin(), nonRepeats.end() ); 830 qHeapSort( nonRepeats.begin(), nonRepeats.end() );
828 for ( it = nonRepeats.begin(); it != nonRepeats.end(); ++it ) { 831 for ( it = nonRepeats.begin(); it != nonRepeats.end(); ++it ) {
829 if ( catComp( (*it).categories(), category ) ) { 832 if ( catComp( (*it).categories(), category ) ) {
830 if ( (*it).start() < dtEnd ) { 833 if ( (*it).start() < dtEnd ) {
831 if ( (*it).match( r ) && !(*it <= nonrev) ) { 834 if ( (*it).match( r ) && !(*it <= nonrev) ) {
832 nonrev = *it; 835 nonrev = *it;
833 dtEnd = nonrev.start(); 836 dtEnd = nonrev.start();
834 candidtate = true; 837 candidtate = true;
835 wrapAround = true; 838 wrapAround = true;
836 break; 839 break;
837 } 840 }
838 } 841 }
839 } 842 }
840 } 843 }
841 if ( candidtate ) { 844 if ( candidtate ) {
842 dayView->setStartViewTime( dtEnd.time().hour() ); 845 dayView->setStartViewTime( dtEnd.time().hour() );
843 dayView->setDate( dtEnd.date().year(), dtEnd.date().month(), 846 dayView->setDate( dtEnd.date().year(), dtEnd.date().month(),
844 dtEnd.date().day() ); 847 dtEnd.date().day() );
845 } else { 848 } else {
846 if ( wrapAround ) { 849 if ( wrapAround ) {
847 emit signalWrapAround(); 850 emit signalWrapAround();
848 rev.setStart( QDateTime(QDate(1960, 1, 1), QTime(0, 0, 0)) ); 851 rev.setStart( QDateTime(QDate(1960, 1, 1), QTime(0, 0, 0)) );
849 nonrev.setStart( rev.start() ); 852 nonrev.setStart( rev.start() );
850 } else 853 } else
851 emit signalNotFound(); 854 emit signalNotFound();
852 wrapAround = !wrapAround; 855 wrapAround = !wrapAround;
853 } 856 }
854} 857}