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