summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--core/pim/datebook/datebook.cpp1
1 files changed, 1 insertions, 0 deletions
diff --git a/core/pim/datebook/datebook.cpp b/core/pim/datebook/datebook.cpp
index c23129a..8614b3f 100644
--- a/core/pim/datebook/datebook.cpp
+++ b/core/pim/datebook/datebook.cpp
@@ -1,569 +1,570 @@
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 23#define QTOPIA_INTERNAL_FD
24 24
25#include "datebook.h" 25#include "datebook.h"
26#include "datebookday.h" 26#include "datebookday.h"
27#include "datebooksettings.h" 27#include "datebooksettings.h"
28#include "datebookweek.h" 28#include "datebookweek.h"
29#include "datebookweeklst.h" 29#include "datebookweeklst.h"
30#include "dateentryimpl.h" 30#include "dateentryimpl.h"
31 31
32#include <qpe/datebookmonth.h> 32#include <qpe/datebookmonth.h>
33#include <qpe/qpeapplication.h> 33#include <qpe/qpeapplication.h>
34#include <qpe/config.h> 34#include <qpe/config.h>
35#include <qpe/qpedebug.h> 35#include <qpe/qpedebug.h>
36#include <qpe/event.h> 36#include <qpe/event.h>
37#include <qpe/finddialog.h> 37#include <qpe/finddialog.h>
38#include <qpe/ir.h> 38#include <qpe/ir.h>
39#include <qpe/qpemenubar.h> 39#include <qpe/qpemenubar.h>
40#include <qpe/qpemessagebox.h> 40#include <qpe/qpemessagebox.h>
41#include <qpe/resource.h> 41#include <qpe/resource.h>
42#include <qpe/sound.h> 42#include <qpe/sound.h>
43#include <qpe/timestring.h> 43#include <qpe/timestring.h>
44#include <qpe/qpetoolbar.h> 44#include <qpe/qpetoolbar.h>
45#include <qpe/tzselect.h> 45#include <qpe/tzselect.h>
46#include <qpe/xmlreader.h> 46#include <qpe/xmlreader.h>
47 47
48#include <qaction.h> 48#include <qaction.h>
49#include <qcopchannel_qws.h> 49#include <qcopchannel_qws.h>
50#include <qdatetime.h> 50#include <qdatetime.h>
51#include <qdialog.h> 51#include <qdialog.h>
52#include <qfile.h> 52#include <qfile.h>
53#include <qlabel.h> 53#include <qlabel.h>
54#include <qlayout.h> 54#include <qlayout.h>
55#include <qmessagebox.h> 55#include <qmessagebox.h>
56#include <qpopupmenu.h> 56#include <qpopupmenu.h>
57#include <qpushbutton.h> 57#include <qpushbutton.h>
58#include <qregexp.h>
58#include <qtextcodec.h> 59#include <qtextcodec.h>
59#include <qtextstream.h> 60#include <qtextstream.h>
60#include <qtl.h> 61#include <qtl.h>
61#include <qwidgetstack.h> 62#include <qwidgetstack.h>
62#include <qwindowsystem_qws.h> 63#include <qwindowsystem_qws.h>
63 64
64#include <sys/stat.h> 65#include <sys/stat.h>
65#include <sys/types.h> 66#include <sys/types.h>
66#include <fcntl.h> 67#include <fcntl.h>
67#include <unistd.h> 68#include <unistd.h>
68 69
69#include <stdlib.h> 70#include <stdlib.h>
70 71
71#define DAY 1 72#define DAY 1
72#define WEEK 2 73#define WEEK 2
73#define WEEKLST 4 74#define WEEKLST 4
74#define MONTH 3 75#define MONTH 3
75 76
76 77
77DateBook::DateBook( QWidget *parent, const char *, WFlags f ) 78DateBook::DateBook( QWidget *parent, const char *, WFlags f )
78 : QMainWindow( parent, "datebook", f ), 79 : QMainWindow( parent, "datebook", f ),
79 aPreset( FALSE ), 80 aPreset( FALSE ),
80 presetTime( -1 ), 81 presetTime( -1 ),
81 startTime( 8 ), // an acceptable default 82 startTime( 8 ), // an acceptable default
82 syncing(FALSE), 83 syncing(FALSE),
83 inSearch(FALSE) 84 inSearch(FALSE)
84{ 85{
85 QTime t; 86 QTime t;
86 t.start(); 87 t.start();
87 db = new DateBookDBHack; 88 db = new DateBookDBHack;
88 qDebug("loading db t=%d", t.elapsed() ); 89 qDebug("loading db t=%d", t.elapsed() );
89 loadSettings(); 90 loadSettings();
90 setCaption( tr("Calendar") ); 91 setCaption( tr("Calendar") );
91 setIcon( Resource::loadPixmap( "datebook_icon" ) ); 92 setIcon( Resource::loadPixmap( "datebook_icon" ) );
92 93
93 setToolBarsMovable( FALSE ); 94 setToolBarsMovable( FALSE );
94 95
95 views = new QWidgetStack( this ); 96 views = new QWidgetStack( this );
96 setCentralWidget( views ); 97 setCentralWidget( views );
97 98
98 dayView = 0; 99 dayView = 0;
99 weekView = 0; 100 weekView = 0;
100 weekLstView = 0; 101 weekLstView = 0;
101 monthView = 0; 102 monthView = 0;
102 103
103 QPEToolBar *bar = new QPEToolBar( this ); 104 QPEToolBar *bar = new QPEToolBar( this );
104 bar->setHorizontalStretchable( TRUE ); 105 bar->setHorizontalStretchable( TRUE );
105 106
106 QPEMenuBar *mb = new QPEMenuBar( bar ); 107 QPEMenuBar *mb = new QPEMenuBar( bar );
107 mb->setMargin( 0 ); 108 mb->setMargin( 0 );
108 109
109 QPEToolBar *sub_bar = new QPEToolBar(this); 110 QPEToolBar *sub_bar = new QPEToolBar(this);
110 111
111 QPopupMenu *view = new QPopupMenu( this ); 112 QPopupMenu *view = new QPopupMenu( this );
112 QPopupMenu *settings = new QPopupMenu( this ); 113 QPopupMenu *settings = new QPopupMenu( this );
113 114
114 mb->insertItem( tr( "View" ), view ); 115 mb->insertItem( tr( "View" ), view );
115 mb->insertItem( tr( "Settings" ), settings ); 116 mb->insertItem( tr( "Settings" ), settings );
116 117
117 QActionGroup *g = new QActionGroup( this ); 118 QActionGroup *g = new QActionGroup( this );
118 g->setExclusive( TRUE ); 119 g->setExclusive( TRUE );
119 120
120 QAction *a = new QAction( tr( "New" ), Resource::loadPixmap( "new" ), 121 QAction *a = new QAction( tr( "New" ), Resource::loadPixmap( "new" ),
121 QString::null, 0, this, 0 ); 122 QString::null, 0, this, 0 );
122 connect( a, SIGNAL( activated() ), this, SLOT( fileNew() ) ); 123 connect( a, SIGNAL( activated() ), this, SLOT( fileNew() ) );
123 a->addTo( sub_bar ); 124 a->addTo( sub_bar );
124 125
125 a = new QAction( tr( "Today" ), Resource::loadPixmap( "to_day" ), QString::null, 0, g, 0 ); 126 a = new QAction( tr( "Today" ), Resource::loadPixmap( "to_day" ), QString::null, 0, g, 0 );
126 connect( a, SIGNAL( activated() ), this, SLOT( slotToday() ) ); 127 connect( a, SIGNAL( activated() ), this, SLOT( slotToday() ) );
127 a->addTo( sub_bar ); 128 a->addTo( sub_bar );
128 a->addTo( view ); 129 a->addTo( view );
129 130
130 a = new QAction( tr( "Day" ), Resource::loadPixmap( "day" ), QString::null, 0, g, 0 ); 131 a = new QAction( tr( "Day" ), Resource::loadPixmap( "day" ), QString::null, 0, g, 0 );
131 connect( a, SIGNAL( activated() ), this, SLOT( viewDay() ) ); 132 connect( a, SIGNAL( activated() ), this, SLOT( viewDay() ) );
132 a->addTo( sub_bar ); 133 a->addTo( sub_bar );
133 a->addTo( view ); 134 a->addTo( view );
134 a->setToggleAction( TRUE ); 135 a->setToggleAction( TRUE );
135 a->setOn( TRUE ); 136 a->setOn( TRUE );
136 dayAction = a; 137 dayAction = a;
137 138
138 a = new QAction( tr( "Week" ), Resource::loadPixmap( "week" ), QString::null, 0, g, 0 ); 139 a = new QAction( tr( "Week" ), Resource::loadPixmap( "week" ), QString::null, 0, g, 0 );
139 connect( a, SIGNAL( activated() ), this, SLOT( viewWeek() ) ); 140 connect( a, SIGNAL( activated() ), this, SLOT( viewWeek() ) );
140 a->addTo( sub_bar ); 141 a->addTo( sub_bar );
141 a->addTo( view ); 142 a->addTo( view );
142 a->setToggleAction( TRUE ); 143 a->setToggleAction( TRUE );
143 weekAction = a; 144 weekAction = a;
144 145
145 a = new QAction( tr( "WeekLst" ), Resource::loadPixmap( "weeklst" ), QString::null, 0, g, 0 ); 146 a = new QAction( tr( "WeekLst" ), Resource::loadPixmap( "weeklst" ), QString::null, 0, g, 0 );
146 connect( a, SIGNAL( activated() ), this, SLOT( viewWeekLst() ) ); 147 connect( a, SIGNAL( activated() ), this, SLOT( viewWeekLst() ) );
147 a->addTo( sub_bar ); 148 a->addTo( sub_bar );
148 a->addTo( view ); 149 a->addTo( view );
149 a->setToggleAction( TRUE ); 150 a->setToggleAction( TRUE );
150 weekLstAction = a; 151 weekLstAction = a;
151 152
152 a = new QAction( tr( "Month" ), Resource::loadPixmap( "month" ), QString::null, 0, g, 0 ); 153 a = new QAction( tr( "Month" ), Resource::loadPixmap( "month" ), QString::null, 0, g, 0 );
153 connect( a, SIGNAL( activated() ), this, SLOT( viewMonth() ) ); 154 connect( a, SIGNAL( activated() ), this, SLOT( viewMonth() ) );
154 a->addTo( sub_bar ); 155 a->addTo( sub_bar );
155 a->addTo( view ); 156 a->addTo( view );
156 a->setToggleAction( TRUE ); 157 a->setToggleAction( TRUE );
157 monthAction = a; 158 monthAction = a;
158 159
159 a = new QAction( tr( "Find" ), Resource::loadPixmap( "mag" ), QString::null, 0, g, 0 ); 160 a = new QAction( tr( "Find" ), Resource::loadPixmap( "mag" ), QString::null, 0, g, 0 );
160 connect( a, SIGNAL(activated()), this, SLOT(slotFind()) ); 161 connect( a, SIGNAL(activated()), this, SLOT(slotFind()) );
161 a->addTo( sub_bar ); 162 a->addTo( sub_bar );
162 163
163 a = new QAction( tr( "Alarm and Start Time..." ), QString::null, 0, 0 ); 164 a = new QAction( tr( "Alarm and Start Time..." ), QString::null, 0, 0 );
164 connect( a, SIGNAL( activated() ), this, SLOT( slotSettings() ) ); 165 connect( a, SIGNAL( activated() ), this, SLOT( slotSettings() ) );
165 a->addTo( settings ); 166 a->addTo( settings );
166 167
167 QPopupMenu *default_view = new QPopupMenu(this); 168 QPopupMenu *default_view = new QPopupMenu(this);
168 settings->insertItem( tr( "Default View" ),default_view ); 169 settings->insertItem( tr( "Default View" ),default_view );
169 default_view->setCheckable(TRUE); 170 default_view->setCheckable(TRUE);
170 171
171 Config config("DateBook"); 172 Config config("DateBook");
172 config.setGroup("Main"); 173 config.setGroup("Main");
173 int current=config.readNumEntry("defaultview", DAY); 174 int current=config.readNumEntry("defaultview", DAY);
174 175
175 QActionGroup *ag = new QActionGroup(this); 176 QActionGroup *ag = new QActionGroup(this);
176 a = new QAction( tr( "Day" ), QString::null, 0, 0, 0, true ); 177 a = new QAction( tr( "Day" ), QString::null, 0, 0, 0, true );
177 if (current==DAY) a->setOn(true), viewDay(); 178 if (current==DAY) a->setOn(true), viewDay();
178 ag->insert(a); 179 ag->insert(a);
179 a = new QAction( tr( "Week" ), QString::null, 0, 0, 0, true ); 180 a = new QAction( tr( "Week" ), QString::null, 0, 0, 0, true );
180 if (current==WEEK) a->setOn(true), viewWeek(); 181 if (current==WEEK) a->setOn(true), viewWeek();
181 ag->insert(a); 182 ag->insert(a);
182 a = new QAction( tr( "WeekLst" ), QString::null, 0, 0, 0, true ); 183 a = new QAction( tr( "WeekLst" ), QString::null, 0, 0, 0, true );
183 if (current==WEEKLST) a->setOn(true), viewWeekLst(); 184 if (current==WEEKLST) a->setOn(true), viewWeekLst();
184 ag->insert(a); 185 ag->insert(a);
185 a = new QAction( tr( "Month" ), QString::null, 0, 0, 0, true ); 186 a = new QAction( tr( "Month" ), QString::null, 0, 0, 0, true );
186 if (current==MONTH) a->setOn(true), viewMonth(); 187 if (current==MONTH) a->setOn(true), viewMonth();
187 ag->insert(a); 188 ag->insert(a);
188 189
189 ag->addTo(default_view); 190 ag->addTo(default_view);
190 connect(ag, SIGNAL( selected ( QAction * ) ), 191 connect(ag, SIGNAL( selected ( QAction * ) ),
191 this, SLOT( newDefaultView(QAction *) ) 192 this, SLOT( newDefaultView(QAction *) )
192 ); 193 );
193 194
194 connect( qApp, SIGNAL(clockChanged(bool)), 195 connect( qApp, SIGNAL(clockChanged(bool)),
195 this, SLOT(changeClock(bool)) ); 196 this, SLOT(changeClock(bool)) );
196 connect( qApp, SIGNAL(weekChanged(bool)), 197 connect( qApp, SIGNAL(weekChanged(bool)),
197 this, SLOT(changeWeek(bool)) ); 198 this, SLOT(changeWeek(bool)) );
198 199
199#if defined(Q_WS_QWS) && !defined(QT_NO_COP) 200#if defined(Q_WS_QWS) && !defined(QT_NO_COP)
200 connect( qApp, SIGNAL(appMessage(const QCString&, const QByteArray&)), 201 connect( qApp, SIGNAL(appMessage(const QCString&, const QByteArray&)),
201 this, SLOT(appMessage(const QCString&, const QByteArray&)) ); 202 this, SLOT(appMessage(const QCString&, const QByteArray&)) );
202#endif 203#endif
203 204
204 // listen on QPE/System 205 // listen on QPE/System
205#if defined(Q_WS_QWS) 206#if defined(Q_WS_QWS)
206#if !defined(QT_NO_COP) 207#if !defined(QT_NO_COP)
207 QCopChannel *channel = new QCopChannel( "QPE/System", this ); 208 QCopChannel *channel = new QCopChannel( "QPE/System", this );
208 connect( channel, SIGNAL(received(const QCString&, const QByteArray&)), 209 connect( channel, SIGNAL(received(const QCString&, const QByteArray&)),
209 this, SLOT(receive(const QCString&, const QByteArray&)) ); 210 this, SLOT(receive(const QCString&, const QByteArray&)) );
210 channel = new QCopChannel( "QPE/Datebook", this ); 211 channel = new QCopChannel( "QPE/Datebook", this );
211 connect( channel, SIGNAL(received(const QCString&, const QByteArray&)), 212 connect( channel, SIGNAL(received(const QCString&, const QByteArray&)),
212 this, SLOT(receive(const QCString&, const QByteArray&)) ); 213 this, SLOT(receive(const QCString&, const QByteArray&)) );
213 qDebug("olle\n"); 214 qDebug("olle\n");
214#endif 215#endif
215#endif 216#endif
216 217
217 qDebug("done t=%d", t.elapsed() ); 218 qDebug("done t=%d", t.elapsed() );
218 219
219} 220}
220 221
221void DateBook::receive( const QCString &msg, const QByteArray &data ) 222void DateBook::receive( const QCString &msg, const QByteArray &data )
222{ 223{
223 QDataStream stream( data, IO_ReadOnly ); 224 QDataStream stream( data, IO_ReadOnly );
224 if ( msg == "timeChange(QString)" ) { 225 if ( msg == "timeChange(QString)" ) {
225 // update active view! 226 // update active view!
226 if ( dayAction->isOn() ) 227 if ( dayAction->isOn() )
227 viewDay(); 228 viewDay();
228 else if ( weekAction->isOn() ) 229 else if ( weekAction->isOn() )
229 viewWeek(); 230 viewWeek();
230 else if ( monthAction->isOn() ) 231 else if ( monthAction->isOn() )
231 viewMonth(); 232 viewMonth();
232 } 233 }
233 else if (msg == "editEvent(int)") { 234 else if (msg == "editEvent(int)") {
234 int uid; 235 int uid;
235 stream >> uid; 236 stream >> uid;
236 Event e=db->eventByUID(uid); 237 Event e=db->eventByUID(uid);
237 editEvent(e); 238 editEvent(e);
238 } 239 }
239} 240}
240 241
241DateBook::~DateBook() 242DateBook::~DateBook()
242{ 243{
243} 244}
244 245
245void DateBook::slotSettings() 246void DateBook::slotSettings()
246{ 247{
247 DateBookSettings frmSettings( ampm, this ); 248 DateBookSettings frmSettings( ampm, this );
248 frmSettings.setStartTime( startTime ); 249 frmSettings.setStartTime( startTime );
249 frmSettings.setAlarmPreset( aPreset, presetTime ); 250 frmSettings.setAlarmPreset( aPreset, presetTime );
250#if defined (Q_WS_QWS) || defined(_WS_QWS_) 251#if defined (Q_WS_QWS) || defined(_WS_QWS_)
251 frmSettings.showMaximized(); 252 frmSettings.showMaximized();
252#endif 253#endif
253 254
254 if ( frmSettings.exec() ) { 255 if ( frmSettings.exec() ) {
255 aPreset = frmSettings.alarmPreset(); 256 aPreset = frmSettings.alarmPreset();
256 presetTime = frmSettings.presetTime(); 257 presetTime = frmSettings.presetTime();
257 startTime = frmSettings.startTime(); 258 startTime = frmSettings.startTime();
258 if ( dayView ) 259 if ( dayView )
259 dayView->setStartViewTime( startTime ); 260 dayView->setStartViewTime( startTime );
260 if ( weekView ) 261 if ( weekView )
261 weekView->setStartViewTime( startTime ); 262 weekView->setStartViewTime( startTime );
262 saveSettings(); 263 saveSettings();
263 264
264 // make the change obvious 265 // make the change obvious
265 if ( views->visibleWidget() ) { 266 if ( views->visibleWidget() ) {
266 if ( views->visibleWidget() == dayView ) 267 if ( views->visibleWidget() == dayView )
267 dayView->redraw(); 268 dayView->redraw();
268 else if ( views->visibleWidget() == weekView ) 269 else if ( views->visibleWidget() == weekView )
269 weekView->redraw(); 270 weekView->redraw();
270 } 271 }
271 } 272 }
272} 273}
273 274
274void DateBook::fileNew() 275void DateBook::fileNew()
275{ 276{
276 slotNewEventFromKey(""); 277 slotNewEventFromKey("");
277} 278}
278 279
279QString DateBook::checkEvent(const Event &e) 280QString DateBook::checkEvent(const Event &e)
280{ 281{
281 /* check if overlaps with itself */ 282 /* check if overlaps with itself */
282 bool checkFailed = FALSE; 283 bool checkFailed = FALSE;
283 284
284 /* check the next 12 repeats. should catch most problems */ 285 /* check the next 12 repeats. should catch most problems */
285 QDate current_date = e.start().date(); 286 QDate current_date = e.start().date();
286 Event previous = e; 287 Event previous = e;
287 for(int i = 0; i < 12; i++) 288 for(int i = 0; i < 12; i++)
288 { 289 {
289 QDateTime next; 290 QDateTime next;
290 if (!nextOccurance(previous, current_date.addDays(1), next)) { 291 if (!nextOccurance(previous, current_date.addDays(1), next)) {
291 break; // no more repeats 292 break; // no more repeats
292 } 293 }
293 if(next < previous.end()) { 294 if(next < previous.end()) {
294 checkFailed = TRUE; 295 checkFailed = TRUE;
295 break; 296 break;
296 } 297 }
297 current_date = next.date(); 298 current_date = next.date();
298 } 299 }
299 300
300 if(checkFailed) 301 if(checkFailed)
301 return tr("Event duration is potentially longer\n" 302 return tr("Event duration is potentially longer\n"
302 "than interval between repeats."); 303 "than interval between repeats.");
303 304
304 return QString::null; 305 return QString::null;
305} 306}
306 307
307QDate DateBook::currentDate() 308QDate DateBook::currentDate()
308{ 309{
309 QDate d = QDate::currentDate(); 310 QDate d = QDate::currentDate();
310 311
311 if ( dayView && views->visibleWidget() == dayView ) { 312 if ( dayView && views->visibleWidget() == dayView ) {
312 d = dayView->date(); 313 d = dayView->date();
313 } else if ( weekView && views->visibleWidget() == weekView ) { 314 } else if ( weekView && views->visibleWidget() == weekView ) {
314 d = weekView->date(); 315 d = weekView->date();
315 } else if ( weekLstView && views->visibleWidget() == weekLstView ) { 316 } else if ( weekLstView && views->visibleWidget() == weekLstView ) {
316 d = weekLstView->date(); 317 d = weekLstView->date();
317 } else if ( monthView && views->visibleWidget() == monthView ) { 318 } else if ( monthView && views->visibleWidget() == monthView ) {
318 d = monthView->selectedDate(); 319 d = monthView->selectedDate();
319 } 320 }
320 321
321 return d; 322 return d;
322} 323}
323 324
324void DateBook::view(int v, const QDate &d) { 325void DateBook::view(int v, const QDate &d) {
325 if (v==DAY) { 326 if (v==DAY) {
326 initDay(); 327 initDay();
327 dayAction->setOn( TRUE ); 328 dayAction->setOn( TRUE );
328 dayView->setDate( d ); 329 dayView->setDate( d );
329 views->raiseWidget( dayView ); 330 views->raiseWidget( dayView );
330 dayView->redraw(); 331 dayView->redraw();
331 } else if (v==WEEK) { 332 } else if (v==WEEK) {
332 initWeek(); 333 initWeek();
333 weekAction->setOn( TRUE ); 334 weekAction->setOn( TRUE );
334 weekView->setDate( d ); 335 weekView->setDate( d );
335 views->raiseWidget( weekView ); 336 views->raiseWidget( weekView );
336 weekView->redraw(); 337 weekView->redraw();
337 } else if (v==WEEKLST) { 338 } else if (v==WEEKLST) {
338 initWeekLst(); 339 initWeekLst();
339 weekLstAction->setOn( TRUE ); 340 weekLstAction->setOn( TRUE );
340 weekLstView->setDate(d); 341 weekLstView->setDate(d);
341 views->raiseWidget( weekLstView ); 342 views->raiseWidget( weekLstView );
342 weekLstView->redraw(); 343 weekLstView->redraw();
343 } else if (v==MONTH) { 344 } else if (v==MONTH) {
344 initMonth(); 345 initMonth();
345 monthAction->setOn( TRUE ); 346 monthAction->setOn( TRUE );
346 monthView->setDate( d.year(), d.month(), d.day() ); 347 monthView->setDate( d.year(), d.month(), d.day() );
347 views->raiseWidget( monthView ); 348 views->raiseWidget( monthView );
348 monthView->redraw(); 349 monthView->redraw();
349 } 350 }
350} 351}
351 352
352void DateBook::viewDefault(const QDate &d) { 353void DateBook::viewDefault(const QDate &d) {
353 Config config("DateBook"); 354 Config config("DateBook");
354 config.setGroup("Main"); 355 config.setGroup("Main");
355 int current=config.readNumEntry("defaultview", DAY); 356 int current=config.readNumEntry("defaultview", DAY);
356 357
357 view(current,d); 358 view(current,d);
358} 359}
359 360
360void DateBook::viewDay() { 361void DateBook::viewDay() {
361 view(DAY,currentDate()); 362 view(DAY,currentDate());
362} 363}
363 364
364void DateBook::viewWeek() { 365void DateBook::viewWeek() {
365 view(WEEK,currentDate()); 366 view(WEEK,currentDate());
366} 367}
367 368
368void DateBook::viewWeekLst() { 369void DateBook::viewWeekLst() {
369 view(WEEKLST,currentDate()); 370 view(WEEKLST,currentDate());
370} 371}
371 372
372void DateBook::viewMonth() { 373void DateBook::viewMonth() {
373 view(MONTH,currentDate()); 374 view(MONTH,currentDate());
374} 375}
375 376
376void DateBook::editEvent( const Event &e ) 377void DateBook::editEvent( const Event &e )
377{ 378{
378 if (syncing) { 379 if (syncing) {
379 QMessageBox::warning( this, tr("Calendar"), 380 QMessageBox::warning( this, tr("Calendar"),
380 tr( "Can not edit data, currently syncing") ); 381 tr( "Can not edit data, currently syncing") );
381 return; 382 return;
382 } 383 }
383 384
384 // workaround added for text input. 385 // workaround added for text input.
385 QDialog editDlg( this, 0, TRUE ); 386 QDialog editDlg( this, 0, TRUE );
386 DateEntry *entry; 387 DateEntry *entry;
387 editDlg.setCaption( tr("Edit Event") ); 388 editDlg.setCaption( tr("Edit Event") );
388 QVBoxLayout *vb = new QVBoxLayout( &editDlg ); 389 QVBoxLayout *vb = new QVBoxLayout( &editDlg );
389 QScrollView *sv = new QScrollView( &editDlg, "scrollview" ); 390 QScrollView *sv = new QScrollView( &editDlg, "scrollview" );
390 sv->setResizePolicy( QScrollView::AutoOneFit ); 391 sv->setResizePolicy( QScrollView::AutoOneFit );
391 // KLUDGE!!! 392 // KLUDGE!!!
392 sv->setHScrollBarMode( QScrollView::AlwaysOff ); 393 sv->setHScrollBarMode( QScrollView::AlwaysOff );
393 vb->addWidget( sv ); 394 vb->addWidget( sv );
394 entry = new DateEntry( onMonday, e, ampm, &editDlg, "editor" ); 395 entry = new DateEntry( onMonday, e, ampm, &editDlg, "editor" );
395 entry->timezone->setEnabled( FALSE ); 396 entry->timezone->setEnabled( FALSE );
396 sv->addChild( entry ); 397 sv->addChild( entry );
397 398
398#if defined(Q_WS_QWS) || defined(_WS_QWS_) 399#if defined(Q_WS_QWS) || defined(_WS_QWS_)
399 editDlg.showMaximized(); 400 editDlg.showMaximized();
400#endif 401#endif
401 while (editDlg.exec() ) { 402 while (editDlg.exec() ) {
402 Event newEv = entry->event(); 403 Event newEv = entry->event();
403 newEv.setUid(e.uid()); // FIXME: Hack not to clear uid 404 newEv.setUid(e.uid()); // FIXME: Hack not to clear uid
404 QString error = checkEvent(newEv); 405 QString error = checkEvent(newEv);
405 if (!error.isNull()) { 406 if (!error.isNull()) {
406 if (QMessageBox::warning(this, "error box", 407 if (QMessageBox::warning(this, "error box",
407 error, "Fix it", "Continue", 408 error, "Fix it", "Continue",
408 0, 0, 1) == 0) 409 0, 0, 1) == 0)
409 continue; 410 continue;
410 } 411 }
411 db->editEvent(e, newEv); 412 db->editEvent(e, newEv);
412 emit newEvent(); 413 emit newEvent();
413 break; 414 break;
414 } 415 }
415} 416}
416 417
417void DateBook::removeEvent( const Event &e ) 418void DateBook::removeEvent( const Event &e )
418{ 419{
419 if (syncing) { 420 if (syncing) {
420 QMessageBox::warning( this, tr("Calendar"), 421 QMessageBox::warning( this, tr("Calendar"),
421 tr( "Can not edit data, currently syncing") ); 422 tr( "Can not edit data, currently syncing") );
422 return; 423 return;
423 } 424 }
424 425
425 QString strName = e.description(); 426 QString strName = e.description();
426 427
427 if ( !QPEMessageBox::confirmDelete( this, tr( "Calendar" ),strName ) ) 428 if ( !QPEMessageBox::confirmDelete( this, tr( "Calendar" ),strName ) )
428 return; 429 return;
429 430
430 db->removeEvent( e ); 431 db->removeEvent( e );
431 if ( views->visibleWidget() == dayView && dayView ) 432 if ( views->visibleWidget() == dayView && dayView )
432 dayView->redraw(); 433 dayView->redraw();
433} 434}
434 435
435void DateBook::addEvent( const Event &e ) 436void DateBook::addEvent( const Event &e )
436{ 437{
437 QDate d = e.start().date(); 438 QDate d = e.start().date();
438 initDay(); 439 initDay();
439 dayView->setDate( d ); 440 dayView->setDate( d );
440} 441}
441 442
442void DateBook::showDay( int year, int month, int day ) 443void DateBook::showDay( int year, int month, int day )
443{ 444{
444 QDate d(year, month, day); 445 QDate d(year, month, day);
445 view(DAY,d); 446 view(DAY,d);
446} 447}
447 448
448void DateBook::initDay() 449void DateBook::initDay()
449{ 450{
450 if ( !dayView ) { 451 if ( !dayView ) {
451 dayView = new DateBookDay( ampm, onMonday, db, views, "day view" ); 452 dayView = new DateBookDay( ampm, onMonday, db, views, "day view" );
452 views->addWidget( dayView, DAY ); 453 views->addWidget( dayView, DAY );
453 dayView->setStartViewTime( startTime ); 454 dayView->setStartViewTime( startTime );
454 connect( this, SIGNAL( newEvent() ), 455 connect( this, SIGNAL( newEvent() ),
455 dayView, SLOT( redraw() ) ); 456 dayView, SLOT( redraw() ) );
456 connect( dayView, SIGNAL( newEvent() ), 457 connect( dayView, SIGNAL( newEvent() ),
457 this, SLOT( fileNew() ) ); 458 this, SLOT( fileNew() ) );
458 connect( dayView, SIGNAL( removeEvent( const Event & ) ), 459 connect( dayView, SIGNAL( removeEvent( const Event & ) ),
459 this, SLOT( removeEvent( const Event & ) ) ); 460 this, SLOT( removeEvent( const Event & ) ) );
460 connect( dayView, SIGNAL( editEvent( const Event & ) ), 461 connect( dayView, SIGNAL( editEvent( const Event & ) ),
461 this, SLOT( editEvent( const Event & ) ) ); 462 this, SLOT( editEvent( const Event & ) ) );
462 connect( dayView, SIGNAL( beamEvent( const Event & ) ), 463 connect( dayView, SIGNAL( beamEvent( const Event & ) ),
463 this, SLOT( beamEvent( const Event & ) ) ); 464 this, SLOT( beamEvent( const Event & ) ) );
464 connect( dayView, SIGNAL(sigNewEvent(const QString &)), 465 connect( dayView, SIGNAL(sigNewEvent(const QString &)),
465 this, SLOT(slotNewEventFromKey(const QString &)) ); 466 this, SLOT(slotNewEventFromKey(const QString &)) );
466 } 467 }
467} 468}
468 469
469void DateBook::initWeek() 470void DateBook::initWeek()
470{ 471{
471 if ( !weekView ) { 472 if ( !weekView ) {
472 weekView = new DateBookWeek( ampm, onMonday, db, views, "week view" ); 473 weekView = new DateBookWeek( ampm, onMonday, db, views, "week view" );
473 weekView->setStartViewTime( startTime ); 474 weekView->setStartViewTime( startTime );
474 views->addWidget( weekView, WEEK ); 475 views->addWidget( weekView, WEEK );
475 connect( weekView, SIGNAL( showDate( int, int, int ) ), 476 connect( weekView, SIGNAL( showDate( int, int, int ) ),
476 this, SLOT( showDay( int, int, int ) ) ); 477 this, SLOT( showDay( int, int, int ) ) );
477 connect( this, SIGNAL( newEvent() ), 478 connect( this, SIGNAL( newEvent() ),
478 weekView, SLOT( redraw() ) ); 479 weekView, SLOT( redraw() ) );
479 } 480 }
480 //But also get it right: the year that we display can be different 481 //But also get it right: the year that we display can be different
481 //from the year of the current date. So, first find the year 482 //from the year of the current date. So, first find the year
482 //number of the current week. 483 //number of the current week.
483 484
484 int yearNumber, totWeeks; 485 int yearNumber, totWeeks;
485 calcWeek( currentDate(), totWeeks, yearNumber, onMonday ); 486 calcWeek( currentDate(), totWeeks, yearNumber, onMonday );
486 487
487 QDate d = QDate( yearNumber, 12, 31 ); 488 QDate d = QDate( yearNumber, 12, 31 );
488 calcWeek( d, totWeeks, yearNumber, onMonday ); 489 calcWeek( d, totWeeks, yearNumber, onMonday );
489 490
490 while ( totWeeks == 1 ) { 491 while ( totWeeks == 1 ) {
491 d = d.addDays( -1 ); 492 d = d.addDays( -1 );
492 calcWeek( d, totWeeks, yearNumber, onMonday ); 493 calcWeek( d, totWeeks, yearNumber, onMonday );
493 } 494 }
494 if ( totWeeks != weekView->totalWeeks() ) 495 if ( totWeeks != weekView->totalWeeks() )
495 weekView->setTotalWeeks( totWeeks ); 496 weekView->setTotalWeeks( totWeeks );
496} 497}
497void DateBook::initWeekLst() { 498void DateBook::initWeekLst() {
498 if ( !weekLstView ) { 499 if ( !weekLstView ) {
499 weekLstView = new DateBookWeekLst( ampm, onMonday, db, 500 weekLstView = new DateBookWeekLst( ampm, onMonday, db,
500 views, "weeklst view" ); 501 views, "weeklst view" );
501 views->addWidget( weekLstView, WEEKLST ); 502 views->addWidget( weekLstView, WEEKLST );
502 503
503 //weekLstView->setStartViewTime( startTime ); 504 //weekLstView->setStartViewTime( startTime );
504 connect( weekLstView, SIGNAL( showDate( int, int, int ) ), 505 connect( weekLstView, SIGNAL( showDate( int, int, int ) ),
505 this, SLOT( showDay( int, int, int ) ) ); 506 this, SLOT( showDay( int, int, int ) ) );
506 connect( weekLstView, SIGNAL( addEvent( const QDateTime &, 507 connect( weekLstView, SIGNAL( addEvent( const QDateTime &,
507 const QDateTime &, 508 const QDateTime &,
508 const QString & ) ), 509 const QString & ) ),
509 this, SLOT( slotNewEntry( const QDateTime &, 510 this, SLOT( slotNewEntry( const QDateTime &,
510 const QDateTime &, 511 const QDateTime &,
511 const QString & ) ) ); 512 const QString & ) ) );
512 connect( this, SIGNAL( newEvent() ), 513 connect( this, SIGNAL( newEvent() ),
513 weekLstView, SLOT( redraw() ) ); 514 weekLstView, SLOT( redraw() ) );
514 connect( weekLstView, SIGNAL( editEvent( const Event & ) ), 515 connect( weekLstView, SIGNAL( editEvent( const Event & ) ),
515 this, SLOT( editEvent( const Event & ) ) ); 516 this, SLOT( editEvent( const Event & ) ) );
516 } 517 }
517} 518}
518 519
519 520
520void DateBook::initMonth() 521void DateBook::initMonth()
521{ 522{
522 if ( !monthView ) { 523 if ( !monthView ) {
523 monthView = new DateBookMonth( views, "month view", FALSE, db ); 524 monthView = new DateBookMonth( views, "month view", FALSE, db );
524 views->addWidget( monthView, MONTH ); 525 views->addWidget( monthView, MONTH );
525 connect( monthView, SIGNAL( dateClicked( int, int, int ) ), 526 connect( monthView, SIGNAL( dateClicked( int, int, int ) ),
526 this, SLOT( showDay( int, int, int ) ) ); 527 this, SLOT( showDay( int, int, int ) ) );
527 connect( this, SIGNAL( newEvent() ), 528 connect( this, SIGNAL( newEvent() ),
528 monthView, SLOT( redraw() ) ); 529 monthView, SLOT( redraw() ) );
529 qApp->processEvents(); 530 qApp->processEvents();
530 } 531 }
531} 532}
532 533
533void DateBook::loadSettings() 534void DateBook::loadSettings()
534{ 535{
535 { 536 {
536 Config config( "qpe" ); 537 Config config( "qpe" );
537 config.setGroup("Time"); 538 config.setGroup("Time");
538 ampm = config.readBoolEntry( "AMPM", TRUE ); 539 ampm = config.readBoolEntry( "AMPM", TRUE );
539 onMonday = config.readBoolEntry( "MONDAY" ); 540 onMonday = config.readBoolEntry( "MONDAY" );
540 } 541 }
541 542
542 { 543 {
543 Config config("DateBook"); 544 Config config("DateBook");
544 config.setGroup("Main"); 545 config.setGroup("Main");
545 startTime = config.readNumEntry("startviewtime", 8); 546 startTime = config.readNumEntry("startviewtime", 8);
546 aPreset = config.readBoolEntry("alarmpreset"); 547 aPreset = config.readBoolEntry("alarmpreset");
547 presetTime = config.readNumEntry("presettime"); 548 presetTime = config.readNumEntry("presettime");
548 } 549 }
549} 550}
550 551
551void DateBook::saveSettings() 552void DateBook::saveSettings()
552{ 553{
553 Config config( "qpe" ); 554 Config config( "qpe" );
554 Config configDB( "DateBook" ); 555 Config configDB( "DateBook" );
555 configDB.setGroup( "Main" ); 556 configDB.setGroup( "Main" );
556 configDB.writeEntry("startviewtime",startTime); 557 configDB.writeEntry("startviewtime",startTime);
557 configDB.writeEntry("alarmpreset",aPreset); 558 configDB.writeEntry("alarmpreset",aPreset);
558 configDB.writeEntry("presettime",presetTime); 559 configDB.writeEntry("presettime",presetTime);
559} 560}
560 561
561void DateBook::newDefaultView(QAction *a) { 562void DateBook::newDefaultView(QAction *a) {
562 int val=DAY; 563 int val=DAY;
563 if (a->text() == "Day") val=DAY; 564 if (a->text() == "Day") val=DAY;
564 if (a->text() == "Week") val=WEEK; 565 if (a->text() == "Week") val=WEEK;
565 if (a->text() == "WeekLst") val=WEEKLST; 566 if (a->text() == "WeekLst") val=WEEKLST;
566 if (a->text() == "Month") val=MONTH; 567 if (a->text() == "Month") val=MONTH;
567 568
568 Config configDB( "DateBook" ); 569 Config configDB( "DateBook" );
569 configDB.setGroup( "Main" ); 570 configDB.setGroup( "Main" );