summaryrefslogtreecommitdiff
authorzecke <zecke>2002-06-27 12:42:37 (UTC)
committer zecke <zecke>2002-06-27 12:42:37 (UTC)
commit475c11d442a03d8e53b220923626c4bb7350831f (patch) (unidiff)
tree10e7fdfc22b337dfd8f6947f09e7bd163e609f0f
parente69c1daabcd8149f2ad61b2cbbf205128072b415 (diff)
downloadopie-475c11d442a03d8e53b220923626c4bb7350831f.zip
opie-475c11d442a03d8e53b220923626c4bb7350831f.tar.gz
opie-475c11d442a03d8e53b220923626c4bb7350831f.tar.bz2
Fix for bug 81. It's now like in todolist
If neither description nor note is inserted it'll be discarded
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--core/pim/datebook/datebook.cpp2
-rw-r--r--core/pim/datebook/dateentryimpl.cpp11
2 files changed, 8 insertions, 5 deletions
diff --git a/core/pim/datebook/datebook.cpp b/core/pim/datebook/datebook.cpp
index e10842a..76260e2 100644
--- a/core/pim/datebook/datebook.cpp
+++ b/core/pim/datebook/datebook.cpp
@@ -48,768 +48,770 @@
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 <qregexp.h>
59#include <qtextcodec.h> 59#include <qtextcodec.h>
60#include <qtextstream.h> 60#include <qtextstream.h>
61#include <qtimer.h> 61#include <qtimer.h>
62#include <qtl.h> 62#include <qtl.h>
63#include <qwidgetstack.h> 63#include <qwidgetstack.h>
64#include <qwindowsystem_qws.h> 64#include <qwindowsystem_qws.h>
65 65
66#include <sys/stat.h> 66#include <sys/stat.h>
67#include <sys/types.h> 67#include <sys/types.h>
68#include <fcntl.h> 68#include <fcntl.h>
69#include <unistd.h> 69#include <unistd.h>
70 70
71#include <stdlib.h> 71#include <stdlib.h>
72 72
73#define DAY 1 73#define DAY 1
74#define WEEK 2 74#define WEEK 2
75#define WEEKLST 4 75#define WEEKLST 4
76#define MONTH 3 76#define MONTH 3
77 77
78 78
79DateBook::DateBook( QWidget *parent, const char *, WFlags f ) 79DateBook::DateBook( QWidget *parent, const char *, WFlags f )
80 : QMainWindow( parent, "datebook", f ), 80 : QMainWindow( parent, "datebook", f ),
81 aPreset( FALSE ), 81 aPreset( FALSE ),
82 presetTime( -1 ), 82 presetTime( -1 ),
83 startTime( 8 ), // an acceptable default 83 startTime( 8 ), // an acceptable default
84 rowStyle( 0 ), 84 rowStyle( 0 ),
85 bJumpToCurTime(FALSE), 85 bJumpToCurTime(FALSE),
86 syncing(FALSE), 86 syncing(FALSE),
87 inSearch(FALSE), 87 inSearch(FALSE),
88 alarmCounter(0) 88 alarmCounter(0)
89{ 89{
90 bool needEvilHack= false; // if we need an Evil Hack 90 bool needEvilHack= false; // if we need an Evil Hack
91 QTime t; 91 QTime t;
92 t.start(); 92 t.start();
93 db = new DateBookDBHack; 93 db = new DateBookDBHack;
94 qDebug("loading db t=%d", t.elapsed() ); 94 qDebug("loading db t=%d", t.elapsed() );
95 loadSettings(); 95 loadSettings();
96 setCaption( tr("Calendar") ); 96 setCaption( tr("Calendar") );
97 setIcon( Resource::loadPixmap( "datebook_icon" ) ); 97 setIcon( Resource::loadPixmap( "datebook_icon" ) );
98 98
99 setToolBarsMovable( FALSE ); 99 setToolBarsMovable( FALSE );
100 100
101 views = new QWidgetStack( this ); 101 views = new QWidgetStack( this );
102 setCentralWidget( views ); 102 setCentralWidget( views );
103 103
104 dayView = 0; 104 dayView = 0;
105 weekView = 0; 105 weekView = 0;
106 weekLstView = 0; 106 weekLstView = 0;
107 monthView = 0; 107 monthView = 0;
108 108
109 QPEToolBar *bar = new QPEToolBar( this ); 109 QPEToolBar *bar = new QPEToolBar( this );
110 bar->setHorizontalStretchable( TRUE ); 110 bar->setHorizontalStretchable( TRUE );
111 111
112 QPEMenuBar *mb = new QPEMenuBar( bar ); 112 QPEMenuBar *mb = new QPEMenuBar( bar );
113 mb->setMargin( 0 ); 113 mb->setMargin( 0 );
114 114
115 QPEToolBar *sub_bar = new QPEToolBar(this); 115 QPEToolBar *sub_bar = new QPEToolBar(this);
116 116
117 QPopupMenu *view = new QPopupMenu( this ); 117 QPopupMenu *view = new QPopupMenu( this );
118 QPopupMenu *settings = new QPopupMenu( this ); 118 QPopupMenu *settings = new QPopupMenu( this );
119 119
120 mb->insertItem( tr( "View" ), view ); 120 mb->insertItem( tr( "View" ), view );
121 mb->insertItem( tr( "Settings" ), settings ); 121 mb->insertItem( tr( "Settings" ), settings );
122 122
123 QActionGroup *g = new QActionGroup( this ); 123 QActionGroup *g = new QActionGroup( this );
124 g->setExclusive( TRUE ); 124 g->setExclusive( TRUE );
125 125
126 QAction *a = new QAction( tr( "New" ), Resource::loadPixmap( "new" ), 126 QAction *a = new QAction( tr( "New" ), Resource::loadPixmap( "new" ),
127 QString::null, 0, this, 0 ); 127 QString::null, 0, this, 0 );
128 connect( a, SIGNAL( activated() ), this, SLOT( fileNew() ) ); 128 connect( a, SIGNAL( activated() ), this, SLOT( fileNew() ) );
129 a->addTo( sub_bar ); 129 a->addTo( sub_bar );
130 130
131 a = new QAction( tr( "Today" ), Resource::loadPixmap( "to_day" ), QString::null, 0, g, 0 ); 131 a = new QAction( tr( "Today" ), Resource::loadPixmap( "to_day" ), QString::null, 0, g, 0 );
132 connect( a, SIGNAL( activated() ), this, SLOT( slotToday() ) ); 132 connect( a, SIGNAL( activated() ), this, SLOT( slotToday() ) );
133 a->addTo( sub_bar ); 133 a->addTo( sub_bar );
134 a->addTo( view ); 134 a->addTo( view );
135 135
136 a = new QAction( tr( "Day" ), Resource::loadPixmap( "day" ), QString::null, 0, g, 0 ); 136 a = new QAction( tr( "Day" ), Resource::loadPixmap( "day" ), QString::null, 0, g, 0 );
137 connect( a, SIGNAL( activated() ), this, SLOT( viewDay() ) ); 137 connect( a, SIGNAL( activated() ), this, SLOT( viewDay() ) );
138 a->addTo( sub_bar ); 138 a->addTo( sub_bar );
139 a->addTo( view ); 139 a->addTo( view );
140 a->setToggleAction( TRUE ); 140 a->setToggleAction( TRUE );
141 a->setOn( TRUE ); 141 a->setOn( TRUE );
142 dayAction = a; 142 dayAction = a;
143 143
144 a = new QAction( tr( "Week" ), Resource::loadPixmap( "week" ), QString::null, 0, g, 0 ); 144 a = new QAction( tr( "Week" ), Resource::loadPixmap( "week" ), QString::null, 0, g, 0 );
145 connect( a, SIGNAL( activated() ), this, SLOT( viewWeek() ) ); 145 connect( a, SIGNAL( activated() ), this, SLOT( viewWeek() ) );
146 a->addTo( sub_bar ); 146 a->addTo( sub_bar );
147 a->addTo( view ); 147 a->addTo( view );
148 a->setToggleAction( TRUE ); 148 a->setToggleAction( TRUE );
149 weekAction = a; 149 weekAction = a;
150 150
151 a = new QAction( tr( "WeekLst" ), Resource::loadPixmap( "weeklst" ), QString::null, 0, g, 0 ); 151 a = new QAction( tr( "WeekLst" ), Resource::loadPixmap( "weeklst" ), QString::null, 0, g, 0 );
152 connect( a, SIGNAL( activated() ), this, SLOT( viewWeekLst() ) ); 152 connect( a, SIGNAL( activated() ), this, SLOT( viewWeekLst() ) );
153 a->addTo( sub_bar ); 153 a->addTo( sub_bar );
154 a->addTo( view ); 154 a->addTo( view );
155 a->setToggleAction( TRUE ); 155 a->setToggleAction( TRUE );
156 weekLstAction = a; 156 weekLstAction = a;
157 157
158 a = new QAction( tr( "Month" ), Resource::loadPixmap( "month" ), QString::null, 0, g, 0 ); 158 a = new QAction( tr( "Month" ), Resource::loadPixmap( "month" ), QString::null, 0, g, 0 );
159 connect( a, SIGNAL( activated() ), this, SLOT( viewMonth() ) ); 159 connect( a, SIGNAL( activated() ), this, SLOT( viewMonth() ) );
160 a->addTo( sub_bar ); 160 a->addTo( sub_bar );
161 a->addTo( view ); 161 a->addTo( view );
162 a->setToggleAction( TRUE ); 162 a->setToggleAction( TRUE );
163 monthAction = a; 163 monthAction = a;
164 164
165 a = new QAction( tr( "Find" ), Resource::loadPixmap( "mag" ), QString::null, 0, g, 0 ); 165 a = new QAction( tr( "Find" ), Resource::loadPixmap( "mag" ), QString::null, 0, g, 0 );
166 connect( a, SIGNAL(activated()), this, SLOT(slotFind()) ); 166 connect( a, SIGNAL(activated()), this, SLOT(slotFind()) );
167 a->addTo( sub_bar ); 167 a->addTo( sub_bar );
168 168
169 a = new QAction( tr( "Alarm and Start Time..." ), QString::null, 0, 0 ); 169 a = new QAction( tr( "Alarm and Start Time..." ), QString::null, 0, 0 );
170 connect( a, SIGNAL( activated() ), this, SLOT( slotSettings() ) ); 170 connect( a, SIGNAL( activated() ), this, SLOT( slotSettings() ) );
171 a->addTo( settings ); 171 a->addTo( settings );
172 172
173 QPopupMenu *default_view = new QPopupMenu(this); 173 QPopupMenu *default_view = new QPopupMenu(this);
174 settings->insertItem( tr( "Default View" ),default_view ); 174 settings->insertItem( tr( "Default View" ),default_view );
175 default_view->setCheckable(TRUE); 175 default_view->setCheckable(TRUE);
176 176
177 Config config("DateBook"); 177 Config config("DateBook");
178 config.setGroup("Main"); 178 config.setGroup("Main");
179 int current=config.readNumEntry("defaultview", DAY); 179 int current=config.readNumEntry("defaultview", DAY);
180 180
181 QActionGroup *ag = new QActionGroup(this); 181 QActionGroup *ag = new QActionGroup(this);
182 a = new QAction( tr( "Day" ), QString::null, 0, 0, 0, true ); 182 a = new QAction( tr( "Day" ), QString::null, 0, 0, 0, true );
183 if (current==DAY) a->setOn(true), viewDay(); 183 if (current==DAY) a->setOn(true), viewDay();
184 ag->insert(a); 184 ag->insert(a);
185 a = new QAction( tr( "Week" ), QString::null, 0, 0, 0, true ); 185 a = new QAction( tr( "Week" ), QString::null, 0, 0, 0, true );
186 if (current==WEEK) a->setOn(true), /*viewWeek(),*/ needEvilHack = true; 186 if (current==WEEK) a->setOn(true), /*viewWeek(),*/ needEvilHack = true;
187 ag->insert(a); 187 ag->insert(a);
188 a = new QAction( tr( "WeekLst" ), QString::null, 0, 0, 0, true ); 188 a = new QAction( tr( "WeekLst" ), QString::null, 0, 0, 0, true );
189 if (current==WEEKLST) a->setOn(true), viewWeekLst(); 189 if (current==WEEKLST) a->setOn(true), viewWeekLst();
190 ag->insert(a); 190 ag->insert(a);
191 a = new QAction( tr( "Month" ), QString::null, 0, 0, 0, true ); 191 a = new QAction( tr( "Month" ), QString::null, 0, 0, 0, true );
192 if (current==MONTH) a->setOn(true), viewMonth(); 192 if (current==MONTH) a->setOn(true), viewMonth();
193 ag->insert(a); 193 ag->insert(a);
194 194
195 ag->addTo(default_view); 195 ag->addTo(default_view);
196 connect(ag, SIGNAL( selected ( QAction * ) ), 196 connect(ag, SIGNAL( selected ( QAction * ) ),
197 this, SLOT( newDefaultView(QAction *) ) 197 this, SLOT( newDefaultView(QAction *) )
198 ); 198 );
199 199
200 connect( qApp, SIGNAL(clockChanged(bool)), 200 connect( qApp, SIGNAL(clockChanged(bool)),
201 this, SLOT(changeClock(bool)) ); 201 this, SLOT(changeClock(bool)) );
202 connect( qApp, SIGNAL(weekChanged(bool)), 202 connect( qApp, SIGNAL(weekChanged(bool)),
203 this, SLOT(changeWeek(bool)) ); 203 this, SLOT(changeWeek(bool)) );
204 204
205#if defined(Q_WS_QWS) && !defined(QT_NO_COP) 205#if defined(Q_WS_QWS) && !defined(QT_NO_COP)
206 connect( qApp, SIGNAL(appMessage(const QCString&, const QByteArray&)), 206 connect( qApp, SIGNAL(appMessage(const QCString&, const QByteArray&)),
207 this, SLOT(appMessage(const QCString&, const QByteArray&)) ); 207 this, SLOT(appMessage(const QCString&, const QByteArray&)) );
208#endif 208#endif
209 209
210 // listen on QPE/System 210 // listen on QPE/System
211#if defined(Q_WS_QWS) 211#if defined(Q_WS_QWS)
212#if !defined(QT_NO_COP) 212#if !defined(QT_NO_COP)
213 QCopChannel *channel = new QCopChannel( "QPE/System", this ); 213 QCopChannel *channel = new QCopChannel( "QPE/System", this );
214 connect( channel, SIGNAL(received(const QCString&, const QByteArray&)), 214 connect( channel, SIGNAL(received(const QCString&, const QByteArray&)),
215 this, SLOT(receive(const QCString&, const QByteArray&)) ); 215 this, SLOT(receive(const QCString&, const QByteArray&)) );
216 channel = new QCopChannel( "QPE/Datebook", this ); 216 channel = new QCopChannel( "QPE/Datebook", this );
217 connect( channel, SIGNAL(received(const QCString&, const QByteArray&)), 217 connect( channel, SIGNAL(received(const QCString&, const QByteArray&)),
218 this, SLOT(receive(const QCString&, const QByteArray&)) ); 218 this, SLOT(receive(const QCString&, const QByteArray&)) );
219 qDebug("olle\n"); 219 qDebug("olle\n");
220#endif 220#endif
221#endif 221#endif
222 222
223 qDebug("done t=%d", t.elapsed() ); 223 qDebug("done t=%d", t.elapsed() );
224 224
225 /* 225 /*
226 * Here is a problem description: 226 * Here is a problem description:
227 * When Weekview is the default view 227 * When Weekview is the default view
228 * a DateBookWeekView get's created 228 * a DateBookWeekView get's created
229 * redraw() get's called. So what? 229 * redraw() get's called. So what?
230 * Remember that we're still in the c'tor 230 * Remember that we're still in the c'tor
231 * and no final layout has happened? Ok 231 * and no final layout has happened? Ok
232 * now all Events get arranged. Their x 232 * now all Events get arranged. Their x
233 * position get's determined by a QHeader 233 * position get's determined by a QHeader
234 * position. But the QHeader isn't layouted or 234 * position. But the QHeader isn't layouted or
235 * at the right position. redraw() is a slot 235 * at the right position. redraw() is a slot
236 * so we'll call it then via a singleShot 236 * so we'll call it then via a singleShot
237 * from view() 237 * from view()
238 */ 238 */
239 if( needEvilHack ){ 239 if( needEvilHack ){
240 QTimer::singleShot( 500, this, SLOT(viewWeek()) ); 240 QTimer::singleShot( 500, this, SLOT(viewWeek()) );
241 } 241 }
242} 242}
243 243
244void DateBook::receive( const QCString &msg, const QByteArray &data ) 244void DateBook::receive( const QCString &msg, const QByteArray &data )
245{ 245{
246 QDataStream stream( data, IO_ReadOnly ); 246 QDataStream stream( data, IO_ReadOnly );
247 if ( msg == "timeChange(QString)" ) { 247 if ( msg == "timeChange(QString)" ) {
248 // update active view! 248 // update active view!
249 if ( dayAction->isOn() ) 249 if ( dayAction->isOn() )
250 viewDay(); 250 viewDay();
251 else if ( weekAction->isOn() ) 251 else if ( weekAction->isOn() )
252 viewWeek(); 252 viewWeek();
253 else if ( monthAction->isOn() ) 253 else if ( monthAction->isOn() )
254 viewMonth(); 254 viewMonth();
255 } 255 }
256 else if (msg == "editEvent(int)") { 256 else if (msg == "editEvent(int)") {
257 int uid; 257 int uid;
258 stream >> uid; 258 stream >> uid;
259 Event e=db->eventByUID(uid); 259 Event e=db->eventByUID(uid);
260 editEvent(e); 260 editEvent(e);
261 } 261 }
262} 262}
263 263
264DateBook::~DateBook() 264DateBook::~DateBook()
265{ 265{
266} 266}
267 267
268void DateBook::slotSettings() 268void DateBook::slotSettings()
269{ 269{
270 DateBookSettings frmSettings( ampm, this ); 270 DateBookSettings frmSettings( ampm, this );
271 frmSettings.setStartTime( startTime ); 271 frmSettings.setStartTime( startTime );
272 frmSettings.setAlarmPreset( aPreset, presetTime ); 272 frmSettings.setAlarmPreset( aPreset, presetTime );
273 frmSettings.setJumpToCurTime( bJumpToCurTime ); 273 frmSettings.setJumpToCurTime( bJumpToCurTime );
274 frmSettings.setRowStyle( rowStyle ); 274 frmSettings.setRowStyle( rowStyle );
275#if defined (Q_WS_QWS) || defined(_WS_QWS_) 275#if defined (Q_WS_QWS) || defined(_WS_QWS_)
276 frmSettings.showMaximized(); 276 frmSettings.showMaximized();
277#endif 277#endif
278 278
279 if ( frmSettings.exec() ) { 279 if ( frmSettings.exec() ) {
280 aPreset = frmSettings.alarmPreset(); 280 aPreset = frmSettings.alarmPreset();
281 presetTime = frmSettings.presetTime(); 281 presetTime = frmSettings.presetTime();
282 startTime = frmSettings.startTime(); 282 startTime = frmSettings.startTime();
283 bJumpToCurTime = frmSettings.jumpToCurTime(); 283 bJumpToCurTime = frmSettings.jumpToCurTime();
284 rowStyle = frmSettings.rowStyle(); 284 rowStyle = frmSettings.rowStyle();
285 if ( dayView ) 285 if ( dayView )
286 dayView->setStartViewTime( startTime ); 286 dayView->setStartViewTime( startTime );
287 dayView->setJumpToCurTime( bJumpToCurTime ); 287 dayView->setJumpToCurTime( bJumpToCurTime );
288 dayView->setRowStyle( rowStyle ); 288 dayView->setRowStyle( rowStyle );
289 if ( weekView ) 289 if ( weekView )
290 weekView->setStartViewTime( startTime ); 290 weekView->setStartViewTime( startTime );
291 saveSettings(); 291 saveSettings();
292 292
293 // make the change obvious 293 // make the change obvious
294 if ( views->visibleWidget() ) { 294 if ( views->visibleWidget() ) {
295 if ( views->visibleWidget() == dayView ) 295 if ( views->visibleWidget() == dayView )
296 dayView->redraw(); 296 dayView->redraw();
297 else if ( views->visibleWidget() == weekView ) 297 else if ( views->visibleWidget() == weekView )
298 weekView->redraw(); 298 weekView->redraw();
299 } 299 }
300 } 300 }
301} 301}
302 302
303void DateBook::fileNew() 303void DateBook::fileNew()
304{ 304{
305 slotNewEventFromKey(""); 305 slotNewEventFromKey("");
306} 306}
307 307
308QString DateBook::checkEvent(const Event &e) 308QString DateBook::checkEvent(const Event &e)
309{ 309{
310 /* check if overlaps with itself */ 310 /* check if overlaps with itself */
311 bool checkFailed = FALSE; 311 bool checkFailed = FALSE;
312 312
313 /* check the next 12 repeats. should catch most problems */ 313 /* check the next 12 repeats. should catch most problems */
314 QDate current_date = e.start().date(); 314 QDate current_date = e.start().date();
315 Event previous = e; 315 Event previous = e;
316 for(int i = 0; i < 12; i++) 316 for(int i = 0; i < 12; i++)
317 { 317 {
318 QDateTime next; 318 QDateTime next;
319 if (!nextOccurance(previous, current_date.addDays(1), next)) { 319 if (!nextOccurance(previous, current_date.addDays(1), next)) {
320 break; // no more repeats 320 break; // no more repeats
321 } 321 }
322 if(next < previous.end()) { 322 if(next < previous.end()) {
323 checkFailed = TRUE; 323 checkFailed = TRUE;
324 break; 324 break;
325 } 325 }
326 current_date = next.date(); 326 current_date = next.date();
327 } 327 }
328 328
329 if(checkFailed) 329 if(checkFailed)
330 return tr("Event duration is potentially longer\n" 330 return tr("Event duration is potentially longer\n"
331 "than interval between repeats."); 331 "than interval between repeats.");
332 332
333 return QString::null; 333 return QString::null;
334} 334}
335 335
336QDate DateBook::currentDate() 336QDate DateBook::currentDate()
337{ 337{
338 QDate d = QDate::currentDate(); 338 QDate d = QDate::currentDate();
339 339
340 if ( dayView && views->visibleWidget() == dayView ) { 340 if ( dayView && views->visibleWidget() == dayView ) {
341 d = dayView->date(); 341 d = dayView->date();
342 } else if ( weekView && views->visibleWidget() == weekView ) { 342 } else if ( weekView && views->visibleWidget() == weekView ) {
343 d = weekView->date(); 343 d = weekView->date();
344 } else if ( weekLstView && views->visibleWidget() == weekLstView ) { 344 } else if ( weekLstView && views->visibleWidget() == weekLstView ) {
345 d = weekLstView->date(); 345 d = weekLstView->date();
346 } else if ( monthView && views->visibleWidget() == monthView ) { 346 } else if ( monthView && views->visibleWidget() == monthView ) {
347 d = monthView->selectedDate(); 347 d = monthView->selectedDate();
348 } 348 }
349 349
350 return d; 350 return d;
351} 351}
352 352
353void DateBook::view(int v, const QDate &d) { 353void DateBook::view(int v, const QDate &d) {
354 if (v==DAY) { 354 if (v==DAY) {
355 initDay(); 355 initDay();
356 dayAction->setOn( TRUE ); 356 dayAction->setOn( TRUE );
357 dayView->setDate( d ); 357 dayView->setDate( d );
358 views->raiseWidget( dayView ); 358 views->raiseWidget( dayView );
359 dayView->redraw(); 359 dayView->redraw();
360 } else if (v==WEEK) { 360 } else if (v==WEEK) {
361 initWeek(); 361 initWeek();
362 weekAction->setOn( TRUE ); 362 weekAction->setOn( TRUE );
363 weekView->setDate( d ); 363 weekView->setDate( d );
364 views->raiseWidget( weekView ); 364 views->raiseWidget( weekView );
365 weekView->redraw(); 365 weekView->redraw();
366 } else if (v==WEEKLST) { 366 } else if (v==WEEKLST) {
367 initWeekLst(); 367 initWeekLst();
368 weekLstAction->setOn( TRUE ); 368 weekLstAction->setOn( TRUE );
369 weekLstView->setDate(d); 369 weekLstView->setDate(d);
370 views->raiseWidget( weekLstView ); 370 views->raiseWidget( weekLstView );
371 weekLstView->redraw(); 371 weekLstView->redraw();
372 } else if (v==MONTH) { 372 } else if (v==MONTH) {
373 initMonth(); 373 initMonth();
374 monthAction->setOn( TRUE ); 374 monthAction->setOn( TRUE );
375 monthView->setDate( d.year(), d.month(), d.day() ); 375 monthView->setDate( d.year(), d.month(), d.day() );
376 views->raiseWidget( monthView ); 376 views->raiseWidget( monthView );
377 monthView->redraw(); 377 monthView->redraw();
378 } 378 }
379} 379}
380 380
381void DateBook::viewDefault(const QDate &d) { 381void DateBook::viewDefault(const QDate &d) {
382 Config config("DateBook"); 382 Config config("DateBook");
383 config.setGroup("Main"); 383 config.setGroup("Main");
384 int current=config.readNumEntry("defaultview", DAY); 384 int current=config.readNumEntry("defaultview", DAY);
385 385
386 view(current,d); 386 view(current,d);
387} 387}
388 388
389void DateBook::viewDay() { 389void DateBook::viewDay() {
390 view(DAY,currentDate()); 390 view(DAY,currentDate());
391} 391}
392 392
393void DateBook::viewWeek() { 393void DateBook::viewWeek() {
394 view(WEEK,currentDate()); 394 view(WEEK,currentDate());
395} 395}
396 396
397void DateBook::viewWeekLst() { 397void DateBook::viewWeekLst() {
398 view(WEEKLST,currentDate()); 398 view(WEEKLST,currentDate());
399} 399}
400 400
401void DateBook::viewMonth() { 401void DateBook::viewMonth() {
402 view(MONTH,currentDate()); 402 view(MONTH,currentDate());
403} 403}
404 404
405void DateBook::editEvent( const Event &e ) 405void DateBook::editEvent( const Event &e )
406{ 406{
407 if (syncing) { 407 if (syncing) {
408 QMessageBox::warning( this, tr("Calendar"), 408 QMessageBox::warning( this, tr("Calendar"),
409 tr( "Can not edit data, currently syncing") ); 409 tr( "Can not edit data, currently syncing") );
410 return; 410 return;
411 } 411 }
412 412
413 // workaround added for text input. 413 // workaround added for text input.
414 QDialog editDlg( this, 0, TRUE ); 414 QDialog editDlg( this, 0, TRUE );
415 DateEntry *entry; 415 DateEntry *entry;
416 editDlg.setCaption( tr("Edit Event") ); 416 editDlg.setCaption( tr("Edit Event") );
417 QVBoxLayout *vb = new QVBoxLayout( &editDlg ); 417 QVBoxLayout *vb = new QVBoxLayout( &editDlg );
418 QScrollView *sv = new QScrollView( &editDlg, "scrollview" ); 418 QScrollView *sv = new QScrollView( &editDlg, "scrollview" );
419 sv->setResizePolicy( QScrollView::AutoOneFit ); 419 sv->setResizePolicy( QScrollView::AutoOneFit );
420 // KLUDGE!!! 420 // KLUDGE!!!
421 sv->setHScrollBarMode( QScrollView::AlwaysOff ); 421 sv->setHScrollBarMode( QScrollView::AlwaysOff );
422 vb->addWidget( sv ); 422 vb->addWidget( sv );
423 entry = new DateEntry( onMonday, e, ampm, &editDlg, "editor" ); 423 entry = new DateEntry( onMonday, e, ampm, &editDlg, "editor" );
424 entry->timezone->setEnabled( FALSE ); 424 entry->timezone->setEnabled( FALSE );
425 sv->addChild( entry ); 425 sv->addChild( entry );
426 426
427#if defined(Q_WS_QWS) || defined(_WS_QWS_) 427#if defined(Q_WS_QWS) || defined(_WS_QWS_)
428 editDlg.showMaximized(); 428 editDlg.showMaximized();
429#endif 429#endif
430 while (editDlg.exec() ) { 430 while (editDlg.exec() ) {
431 Event newEv = entry->event(); 431 Event newEv = entry->event();
432 if(newEv.description().isEmpty() && newEv.notes().isEmpty() )
433 break;
432 newEv.setUid(e.uid()); // FIXME: Hack not to clear uid 434 newEv.setUid(e.uid()); // FIXME: Hack not to clear uid
433 QString error = checkEvent(newEv); 435 QString error = checkEvent(newEv);
434 if (!error.isNull()) { 436 if (!error.isNull()) {
435 if (QMessageBox::warning(this, "error box", 437 if (QMessageBox::warning(this, "error box",
436 error, "Fix it", "Continue", 438 error, "Fix it", "Continue",
437 0, 0, 1) == 0) 439 0, 0, 1) == 0)
438 continue; 440 continue;
439 } 441 }
440 db->editEvent(e, newEv); 442 db->editEvent(e, newEv);
441 emit newEvent(); 443 emit newEvent();
442 break; 444 break;
443 } 445 }
444} 446}
445 447
446void DateBook::removeEvent( const Event &e ) 448void DateBook::removeEvent( const Event &e )
447{ 449{
448 if (syncing) { 450 if (syncing) {
449 QMessageBox::warning( this, tr("Calendar"), 451 QMessageBox::warning( this, tr("Calendar"),
450 tr( "Can not edit data, currently syncing") ); 452 tr( "Can not edit data, currently syncing") );
451 return; 453 return;
452 } 454 }
453 455
454 QString strName = e.description(); 456 QString strName = e.description();
455 457
456 if ( !QPEMessageBox::confirmDelete( this, tr( "Calendar" ),strName ) ) 458 if ( !QPEMessageBox::confirmDelete( this, tr( "Calendar" ),strName ) )
457 return; 459 return;
458 460
459 db->removeEvent( e ); 461 db->removeEvent( e );
460 if ( views->visibleWidget() == dayView && dayView ) 462 if ( views->visibleWidget() == dayView && dayView )
461 dayView->redraw(); 463 dayView->redraw();
462} 464}
463 465
464void DateBook::addEvent( const Event &e ) 466void DateBook::addEvent( const Event &e )
465{ 467{
466 QDate d = e.start().date(); 468 QDate d = e.start().date();
467 initDay(); 469 initDay();
468 dayView->setDate( d ); 470 dayView->setDate( d );
469} 471}
470 472
471void DateBook::showDay( int year, int month, int day ) 473void DateBook::showDay( int year, int month, int day )
472{ 474{
473 QDate d(year, month, day); 475 QDate d(year, month, day);
474 view(DAY,d); 476 view(DAY,d);
475} 477}
476 478
477void DateBook::initDay() 479void DateBook::initDay()
478{ 480{
479 if ( !dayView ) { 481 if ( !dayView ) {
480 dayView = new DateBookDay( ampm, onMonday, db, views, "day view" ); 482 dayView = new DateBookDay( ampm, onMonday, db, views, "day view" );
481 views->addWidget( dayView, DAY ); 483 views->addWidget( dayView, DAY );
482 dayView->setStartViewTime( startTime ); 484 dayView->setStartViewTime( startTime );
483 dayView->setJumpToCurTime( bJumpToCurTime ); 485 dayView->setJumpToCurTime( bJumpToCurTime );
484 dayView->setRowStyle( rowStyle ); 486 dayView->setRowStyle( rowStyle );
485 connect( this, SIGNAL( newEvent() ), 487 connect( this, SIGNAL( newEvent() ),
486 dayView, SLOT( redraw() ) ); 488 dayView, SLOT( redraw() ) );
487 connect( dayView, SIGNAL( newEvent() ), 489 connect( dayView, SIGNAL( newEvent() ),
488 this, SLOT( fileNew() ) ); 490 this, SLOT( fileNew() ) );
489 connect( dayView, SIGNAL( removeEvent( const Event & ) ), 491 connect( dayView, SIGNAL( removeEvent( const Event & ) ),
490 this, SLOT( removeEvent( const Event & ) ) ); 492 this, SLOT( removeEvent( const Event & ) ) );
491 connect( dayView, SIGNAL( editEvent( const Event & ) ), 493 connect( dayView, SIGNAL( editEvent( const Event & ) ),
492 this, SLOT( editEvent( const Event & ) ) ); 494 this, SLOT( editEvent( const Event & ) ) );
493 connect( dayView, SIGNAL( beamEvent( const Event & ) ), 495 connect( dayView, SIGNAL( beamEvent( const Event & ) ),
494 this, SLOT( beamEvent( const Event & ) ) ); 496 this, SLOT( beamEvent( const Event & ) ) );
495 connect( dayView, SIGNAL(sigNewEvent(const QString &)), 497 connect( dayView, SIGNAL(sigNewEvent(const QString &)),
496 this, SLOT(slotNewEventFromKey(const QString &)) ); 498 this, SLOT(slotNewEventFromKey(const QString &)) );
497 } 499 }
498} 500}
499 501
500void DateBook::initWeek() 502void DateBook::initWeek()
501{ 503{
502 if ( !weekView ) { 504 if ( !weekView ) {
503 weekView = new DateBookWeek( ampm, onMonday, db, views, "week view" ); 505 weekView = new DateBookWeek( ampm, onMonday, db, views, "week view" );
504 weekView->setStartViewTime( startTime ); 506 weekView->setStartViewTime( startTime );
505 views->addWidget( weekView, WEEK ); 507 views->addWidget( weekView, WEEK );
506 connect( weekView, SIGNAL( showDate( int, int, int ) ), 508 connect( weekView, SIGNAL( showDate( int, int, int ) ),
507 this, SLOT( showDay( int, int, int ) ) ); 509 this, SLOT( showDay( int, int, int ) ) );
508 connect( this, SIGNAL( newEvent() ), 510 connect( this, SIGNAL( newEvent() ),
509 weekView, SLOT( redraw() ) ); 511 weekView, SLOT( redraw() ) );
510 } 512 }
511 //But also get it right: the year that we display can be different 513 //But also get it right: the year that we display can be different
512 //from the year of the current date. So, first find the year 514 //from the year of the current date. So, first find the year
513 //number of the current week. 515 //number of the current week.
514 516
515 int yearNumber, totWeeks; 517 int yearNumber, totWeeks;
516 calcWeek( currentDate(), totWeeks, yearNumber, onMonday ); 518 calcWeek( currentDate(), totWeeks, yearNumber, onMonday );
517 519
518 QDate d = QDate( yearNumber, 12, 31 ); 520 QDate d = QDate( yearNumber, 12, 31 );
519 calcWeek( d, totWeeks, yearNumber, onMonday ); 521 calcWeek( d, totWeeks, yearNumber, onMonday );
520 522
521 while ( totWeeks == 1 ) { 523 while ( totWeeks == 1 ) {
522 d = d.addDays( -1 ); 524 d = d.addDays( -1 );
523 calcWeek( d, totWeeks, yearNumber, onMonday ); 525 calcWeek( d, totWeeks, yearNumber, onMonday );
524 } 526 }
525 if ( totWeeks != weekView->totalWeeks() ) 527 if ( totWeeks != weekView->totalWeeks() )
526 weekView->setTotalWeeks( totWeeks ); 528 weekView->setTotalWeeks( totWeeks );
527} 529}
528void DateBook::initWeekLst() { 530void DateBook::initWeekLst() {
529 if ( !weekLstView ) { 531 if ( !weekLstView ) {
530 weekLstView = new DateBookWeekLst( ampm, onMonday, db, 532 weekLstView = new DateBookWeekLst( ampm, onMonday, db,
531 views, "weeklst view" ); 533 views, "weeklst view" );
532 views->addWidget( weekLstView, WEEKLST ); 534 views->addWidget( weekLstView, WEEKLST );
533 535
534 //weekLstView->setStartViewTime( startTime ); 536 //weekLstView->setStartViewTime( startTime );
535 connect( weekLstView, SIGNAL( showDate( int, int, int ) ), 537 connect( weekLstView, SIGNAL( showDate( int, int, int ) ),
536 this, SLOT( showDay( int, int, int ) ) ); 538 this, SLOT( showDay( int, int, int ) ) );
537 connect( weekLstView, SIGNAL( addEvent( const QDateTime &, 539 connect( weekLstView, SIGNAL( addEvent( const QDateTime &,
538 const QDateTime &, 540 const QDateTime &,
539 const QString & ) ), 541 const QString & ) ),
540 this, SLOT( slotNewEntry( const QDateTime &, 542 this, SLOT( slotNewEntry( const QDateTime &,
541 const QDateTime &, 543 const QDateTime &,
542 const QString & ) ) ); 544 const QString & ) ) );
543 connect( this, SIGNAL( newEvent() ), 545 connect( this, SIGNAL( newEvent() ),
544 weekLstView, SLOT( redraw() ) ); 546 weekLstView, SLOT( redraw() ) );
545 connect( weekLstView, SIGNAL( editEvent( const Event & ) ), 547 connect( weekLstView, SIGNAL( editEvent( const Event & ) ),
546 this, SLOT( editEvent( const Event & ) ) ); 548 this, SLOT( editEvent( const Event & ) ) );
547 } 549 }
548} 550}
549 551
550 552
551void DateBook::initMonth() 553void DateBook::initMonth()
552{ 554{
553 if ( !monthView ) { 555 if ( !monthView ) {
554 monthView = new DateBookMonth( views, "month view", FALSE, db ); 556 monthView = new DateBookMonth( views, "month view", FALSE, db );
555 views->addWidget( monthView, MONTH ); 557 views->addWidget( monthView, MONTH );
556 connect( monthView, SIGNAL( dateClicked( int, int, int ) ), 558 connect( monthView, SIGNAL( dateClicked( int, int, int ) ),
557 this, SLOT( showDay( int, int, int ) ) ); 559 this, SLOT( showDay( int, int, int ) ) );
558 connect( this, SIGNAL( newEvent() ), 560 connect( this, SIGNAL( newEvent() ),
559 monthView, SLOT( redraw() ) ); 561 monthView, SLOT( redraw() ) );
560 qApp->processEvents(); 562 qApp->processEvents();
561 } 563 }
562} 564}
563 565
564void DateBook::loadSettings() 566void DateBook::loadSettings()
565{ 567{
566 { 568 {
567 Config config( "qpe" ); 569 Config config( "qpe" );
568 config.setGroup("Time"); 570 config.setGroup("Time");
569 ampm = config.readBoolEntry( "AMPM", TRUE ); 571 ampm = config.readBoolEntry( "AMPM", TRUE );
570 onMonday = config.readBoolEntry( "MONDAY" ); 572 onMonday = config.readBoolEntry( "MONDAY" );
571 } 573 }
572 574
573 { 575 {
574 Config config("DateBook"); 576 Config config("DateBook");
575 config.setGroup("Main"); 577 config.setGroup("Main");
576 startTime = config.readNumEntry("startviewtime", 8); 578 startTime = config.readNumEntry("startviewtime", 8);
577 aPreset = config.readBoolEntry("alarmpreset"); 579 aPreset = config.readBoolEntry("alarmpreset");
578 presetTime = config.readNumEntry("presettime"); 580 presetTime = config.readNumEntry("presettime");
579 bJumpToCurTime = config.readBoolEntry("jumptocurtime"); 581 bJumpToCurTime = config.readBoolEntry("jumptocurtime");
580 rowStyle = config.readNumEntry("rowstyle"); 582 rowStyle = config.readNumEntry("rowstyle");
581 } 583 }
582} 584}
583 585
584void DateBook::saveSettings() 586void DateBook::saveSettings()
585{ 587{
586 Config config( "qpe" ); 588 Config config( "qpe" );
587 Config configDB( "DateBook" ); 589 Config configDB( "DateBook" );
588 configDB.setGroup( "Main" ); 590 configDB.setGroup( "Main" );
589 configDB.writeEntry("startviewtime",startTime); 591 configDB.writeEntry("startviewtime",startTime);
590 configDB.writeEntry("alarmpreset",aPreset); 592 configDB.writeEntry("alarmpreset",aPreset);
591 configDB.writeEntry("presettime",presetTime); 593 configDB.writeEntry("presettime",presetTime);
592 configDB.writeEntry("jumptocurtime", bJumpToCurTime); 594 configDB.writeEntry("jumptocurtime", bJumpToCurTime);
593 configDB.writeEntry("rowstyle", rowStyle); 595 configDB.writeEntry("rowstyle", rowStyle);
594} 596}
595 597
596void DateBook::newDefaultView(QAction *a) { 598void DateBook::newDefaultView(QAction *a) {
597 int val=DAY; 599 int val=DAY;
598 if (a->text() == "Day") val=DAY; 600 if (a->text() == "Day") val=DAY;
599 if (a->text() == "Week") val=WEEK; 601 if (a->text() == "Week") val=WEEK;
600 if (a->text() == "WeekLst") val=WEEKLST; 602 if (a->text() == "WeekLst") val=WEEKLST;
601 if (a->text() == "Month") val=MONTH; 603 if (a->text() == "Month") val=MONTH;
602 604
603 Config configDB( "DateBook" ); 605 Config configDB( "DateBook" );
604 configDB.setGroup( "Main" ); 606 configDB.setGroup( "Main" );
605 configDB.writeEntry("defaultview",val); 607 configDB.writeEntry("defaultview",val);
606} 608}
607 609
608void DateBook::appMessage(const QCString& msg, const QByteArray& data) 610void DateBook::appMessage(const QCString& msg, const QByteArray& data)
609{ 611{
610 bool needShow = FALSE; 612 bool needShow = FALSE;
611 if ( msg == "alarm(QDateTime,int)" ) { 613 if ( msg == "alarm(QDateTime,int)" ) {
612 QDataStream ds(data,IO_ReadOnly); 614 QDataStream ds(data,IO_ReadOnly);
613 QDateTime when; int warn; 615 QDateTime when; int warn;
614 ds >> when >> warn; 616 ds >> when >> warn;
615 617
616 // check to make it's okay to continue, 618 // check to make it's okay to continue,
617 // this is the case that the time was set ahead, and 619 // this is the case that the time was set ahead, and
618 // we are forced given a stale alarm... 620 // we are forced given a stale alarm...
619 QDateTime current = QDateTime::currentDateTime(); 621 QDateTime current = QDateTime::currentDateTime();
620 if ( current.time().hour() != when.time().hour() 622 if ( current.time().hour() != when.time().hour()
621 && current.time().minute() != when.time().minute() ) 623 && current.time().minute() != when.time().minute() )
622 return; 624 return;
623 625
624 QValueList<EffectiveEvent> list = db->getEffectiveEvents(when.addSecs(warn*60)); 626 QValueList<EffectiveEvent> list = db->getEffectiveEvents(when.addSecs(warn*60));
625 if ( list.count() > 0 ) { 627 if ( list.count() > 0 ) {
626 QString msg; 628 QString msg;
627 bool bSound = FALSE; 629 bool bSound = FALSE;
628 int stopTimer = 0; 630 int stopTimer = 0;
629 bool found = FALSE; 631 bool found = FALSE;
630 for ( QValueList<EffectiveEvent>::ConstIterator it=list.begin(); 632 for ( QValueList<EffectiveEvent>::ConstIterator it=list.begin();
631 it!=list.end(); ++it ) { 633 it!=list.end(); ++it ) {
632 if ( (*it).event().hasAlarm() ) { 634 if ( (*it).event().hasAlarm() ) {
633 found = TRUE; 635 found = TRUE;
634 msg += "<CENTER><B>" + (*it).description() + "</B>" 636 msg += "<CENTER><B>" + (*it).description() + "</B>"
635 + "<BR>" + (*it).location() + "<BR>" 637 + "<BR>" + (*it).location() + "<BR>"
636 + TimeString::dateString((*it).event().start(),ampm) 638 + TimeString::dateString((*it).event().start(),ampm)
637 + (warn 639 + (warn
638 ? tr(" (in " + QString::number(warn) 640 ? tr(" (in " + QString::number(warn)
639 + tr(" minutes)")) 641 + tr(" minutes)"))
640 : QString("")) 642 : QString(""))
641 + "<BR>" 643 + "<BR>"
642 + (*it).notes() + "</CENTER>"; 644 + (*it).notes() + "</CENTER>";
643 if ( (*it).event().alarmSound() != Event::Silent ) { 645 if ( (*it).event().alarmSound() != Event::Silent ) {
644 bSound = TRUE; 646 bSound = TRUE;
645 } 647 }
646 } 648 }
647 } 649 }
648 if ( found ) { 650 if ( found ) {
649 if ( bSound ) { 651 if ( bSound ) {
650 Sound::soundAlarm(); 652 Sound::soundAlarm();
651 alarmCounter = 0; 653 alarmCounter = 0;
652 stopTimer = startTimer( 5000 ); 654 stopTimer = startTimer( 5000 );
653 } 655 }
654 656
655 QDialog dlg( this, 0, TRUE ); 657 QDialog dlg( this, 0, TRUE );
656 QVBoxLayout *vb = new QVBoxLayout( &dlg ); 658 QVBoxLayout *vb = new QVBoxLayout( &dlg );
657 QScrollView *view = new QScrollView( &dlg, "scrollView"); 659 QScrollView *view = new QScrollView( &dlg, "scrollView");
658 view->setResizePolicy( QScrollView::AutoOneFit ); 660 view->setResizePolicy( QScrollView::AutoOneFit );
659 vb->addWidget( view ); 661 vb->addWidget( view );
660 QLabel *lblMsg = new QLabel( msg, &dlg ); 662 QLabel *lblMsg = new QLabel( msg, &dlg );
661 view->addChild( lblMsg ); 663 view->addChild( lblMsg );
662 QPushButton *cmdOk = new QPushButton( tr("OK"), &dlg ); 664 QPushButton *cmdOk = new QPushButton( tr("OK"), &dlg );
663 connect( cmdOk, SIGNAL(clicked()), &dlg, SLOT(accept()) ); 665 connect( cmdOk, SIGNAL(clicked()), &dlg, SLOT(accept()) );
664 vb->addWidget( cmdOk ); 666 vb->addWidget( cmdOk );
665 667
666#if defined(Q_WS_QWS) || defined(_WS_QWS_) 668#if defined(Q_WS_QWS) || defined(_WS_QWS_)
667 dlg.showMaximized(); 669 dlg.showMaximized();
668#endif 670#endif
669 needShow = dlg.exec(); 671 needShow = dlg.exec();
670 672
671 if ( bSound ) 673 if ( bSound )
672 killTimer( stopTimer ); 674 killTimer( stopTimer );
673 } 675 }
674 } 676 }
675 } else if ( msg == "nextView()" ) { 677 } else if ( msg == "nextView()" ) {
676 QWidget* cur = views->visibleWidget(); 678 QWidget* cur = views->visibleWidget();
677 if ( cur ) { 679 if ( cur ) {
678 if ( cur == dayView ) 680 if ( cur == dayView )
679 viewWeek(); 681 viewWeek();
680 else if ( cur == weekView ) 682 else if ( cur == weekView )
681 viewWeekLst(); 683 viewWeekLst();
682 else if ( cur == weekLstView ) 684 else if ( cur == weekLstView )
683 viewMonth(); 685 viewMonth();
684 else if ( cur == monthView ) 686 else if ( cur == monthView )
685 viewDay(); 687 viewDay();
686 needShow = TRUE; 688 needShow = TRUE;
687 } 689 }
688 } 690 }
689 if ( needShow ) { 691 if ( needShow ) {
690#if defined(Q_WS_QWS) || defined(_WS_QWS_) 692#if defined(Q_WS_QWS) || defined(_WS_QWS_)
691 showMaximized(); 693 showMaximized();
692#else 694#else
693 show(); 695 show();
694#endif 696#endif
695 raise(); 697 raise();
696 QPEApplication::setKeepRunning(); 698 QPEApplication::setKeepRunning();
697 setActiveWindow(); 699 setActiveWindow();
698 } 700 }
699} 701}
700 702
701void DateBook::reload() 703void DateBook::reload()
702{ 704{
703 db->reload(); 705 db->reload();
704 if ( dayAction->isOn() ) 706 if ( dayAction->isOn() )
705 viewDay(); 707 viewDay();
706 else if ( weekAction->isOn() ) 708 else if ( weekAction->isOn() )
707 viewWeek(); 709 viewWeek();
708 else if ( monthAction->isOn() ) 710 else if ( monthAction->isOn() )
709 viewMonth(); 711 viewMonth();
710 syncing = FALSE; 712 syncing = FALSE;
711} 713}
712 714
713void DateBook::flush() 715void DateBook::flush()
714{ 716{
715 syncing = TRUE; 717 syncing = TRUE;
716 db->save(); 718 db->save();
717} 719}
718 720
719void DateBook::timerEvent( QTimerEvent *e ) 721void DateBook::timerEvent( QTimerEvent *e )
720{ 722{
721 if ( alarmCounter < 10 ) { 723 if ( alarmCounter < 10 ) {
722 alarmCounter++; 724 alarmCounter++;
723 Sound::soundAlarm(); 725 Sound::soundAlarm();
724 } 726 }
725 else 727 else
726 killTimer( e->timerId() ); 728 killTimer( e->timerId() );
727} 729}
728 730
729void DateBook::changeClock( bool newClock ) 731void DateBook::changeClock( bool newClock )
730{ 732{
731 ampm = newClock; 733 ampm = newClock;
732 // repaint the affected objects... 734 // repaint the affected objects...
733 if (dayView) dayView->redraw(); 735 if (dayView) dayView->redraw();
734 if (weekView) weekView->redraw(); 736 if (weekView) weekView->redraw();
735 if (weekLstView) weekLstView->redraw(); 737 if (weekLstView) weekLstView->redraw();
736} 738}
737 739
738void DateBook::changeWeek( bool m ) 740void DateBook::changeWeek( bool m )
739{ 741{
740 /* no need to redraw, each widget catches. Do need to 742 /* no need to redraw, each widget catches. Do need to
741 store though for widgets we haven't made yet */ 743 store though for widgets we haven't made yet */
742 onMonday = m; 744 onMonday = m;
743} 745}
744 746
745void DateBook::slotToday() 747void DateBook::slotToday()
746{ 748{
747 // we need to view today using default view 749 // we need to view today using default view
748 viewDefault(QDate::currentDate()); 750 viewDefault(QDate::currentDate());
749} 751}
750 752
751void DateBook::closeEvent( QCloseEvent *e ) 753void DateBook::closeEvent( QCloseEvent *e )
752{ 754{
753 if(syncing) { 755 if(syncing) {
754 /* no need to save, did that at flush */ 756 /* no need to save, did that at flush */
755 e->accept(); 757 e->accept();
756 return; 758 return;
757 } 759 }
758 760
759 // save settings will generate it's own error messages, no 761 // save settings will generate it's own error messages, no
760 // need to do checking ourselves. 762 // need to do checking ourselves.
761 saveSettings(); 763 saveSettings();
762 if ( db->save() ) 764 if ( db->save() )
763 e->accept(); 765 e->accept();
764 else { 766 else {
765 if ( QMessageBox::critical( this, tr( "Out of space" ), 767 if ( QMessageBox::critical( this, tr( "Out of space" ),
766 tr("Calendar was unable to save\n" 768 tr("Calendar was unable to save\n"
767 "your changes.\n" 769 "your changes.\n"
768 "Free up some space and try again.\n" 770 "Free up some space and try again.\n"
769 "\nQuit anyway?"), 771 "\nQuit anyway?"),
770 QMessageBox::Yes|QMessageBox::Escape, 772 QMessageBox::Yes|QMessageBox::Escape,
771 QMessageBox::No|QMessageBox::Default ) 773 QMessageBox::No|QMessageBox::Default )
772 != QMessageBox::No ) 774 != QMessageBox::No )
773 e->accept(); 775 e->accept();
774 else 776 else
775 e->ignore(); 777 e->ignore();
776 } 778 }
777} 779}
778 780
779// Entering directly from the "keyboard" 781// Entering directly from the "keyboard"
780void DateBook::slotNewEventFromKey( const QString &str ) 782void DateBook::slotNewEventFromKey( const QString &str )
781{ 783{
782 if (syncing) { 784 if (syncing) {
783 QMessageBox::warning( this, tr("Calendar"), 785 QMessageBox::warning( this, tr("Calendar"),
784 tr( "Can not edit data, currently syncing") ); 786 tr( "Can not edit data, currently syncing") );
785 return; 787 return;
786 } 788 }
787 789
788 // We get to here from a key pressed in the Day View 790 // We get to here from a key pressed in the Day View
789 // So we can assume some things. We want the string 791 // So we can assume some things. We want the string
790 // passed in to be part of the description. 792 // passed in to be part of the description.
791 QDateTime start, end; 793 QDateTime start, end;
792 if ( views->visibleWidget() == dayView ) { 794 if ( views->visibleWidget() == dayView ) {
793 dayView->selectedDates( start, end ); 795 dayView->selectedDates( start, end );
794 } else if ( views->visibleWidget() == monthView ) { 796 } else if ( views->visibleWidget() == monthView ) {
795 QDate d = monthView->selectedDate(); 797 QDate d = monthView->selectedDate();
796 start = end = d; 798 start = end = d;
797 start.setTime( QTime( 10, 0 ) ); 799 start.setTime( QTime( 10, 0 ) );
798 end.setTime( QTime( 12, 0 ) ); 800 end.setTime( QTime( 12, 0 ) );
799 } else if ( views->visibleWidget() == weekView ) { 801 } else if ( views->visibleWidget() == weekView ) {
800 QDate d = weekView->date(); 802 QDate d = weekView->date();
801 start = end = d; 803 start = end = d;
802 start.setTime( QTime( 10, 0 ) ); 804 start.setTime( QTime( 10, 0 ) );
803 end.setTime( QTime( 12, 0 ) ); 805 end.setTime( QTime( 12, 0 ) );
804 } 806 }
805 slotNewEntry(start, end, str); 807 slotNewEntry(start, end, str);
806} 808}
807void DateBook::slotNewEntry(const QDateTime &start, const QDateTime &end, const QString &str) { 809void DateBook::slotNewEntry(const QDateTime &start, const QDateTime &end, const QString &str) {
808 // argh! This really needs to be encapsulated in a class 810 // argh! This really needs to be encapsulated in a class
809 // or function. 811 // or function.
810 QDialog newDlg( this, 0, TRUE ); 812 QDialog newDlg( this, 0, TRUE );
811 newDlg.setCaption( DateEntryBase::tr("New Event") ); 813 newDlg.setCaption( DateEntryBase::tr("New Event") );
812 DateEntry *e; 814 DateEntry *e;
813 QVBoxLayout *vb = new QVBoxLayout( &newDlg ); 815 QVBoxLayout *vb = new QVBoxLayout( &newDlg );
814 QScrollView *sv = new QScrollView( &newDlg ); 816 QScrollView *sv = new QScrollView( &newDlg );
815 sv->setResizePolicy( QScrollView::AutoOneFit ); 817 sv->setResizePolicy( QScrollView::AutoOneFit );
diff --git a/core/pim/datebook/dateentryimpl.cpp b/core/pim/datebook/dateentryimpl.cpp
index dab3375..2cdda9d 100644
--- a/core/pim/datebook/dateentryimpl.cpp
+++ b/core/pim/datebook/dateentryimpl.cpp
@@ -1,572 +1,573 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved. 2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3** 3**
4** This file is part of Qtopia Environment. 4** This file is part of Qtopia Environment.
5** 5**
6** This file may be distributed and/or modified under the terms of the 6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software 7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the 8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file. 9** packaging of this file.
10** 10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13** 13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information. 14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15** 15**
16** Contact info@trolltech.com if any conditions of this licensing are 16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you. 17** not clear to you.
18** 18**
19**********************************************************************/ 19**********************************************************************/
20 20
21#include "dateentryimpl.h" 21#include "dateentryimpl.h"
22#include "repeatentry.h" 22#include "repeatentry.h"
23 23
24#include <qpe/qpeapplication.h> 24#include <qpe/qpeapplication.h>
25#include <qpe/categoryselect.h> 25#include <qpe/categoryselect.h>
26#include <qpe/datebookmonth.h> 26#include <qpe/datebookmonth.h>
27#include <qpe/global.h> 27#include <qpe/global.h>
28#include <qpe/timeconversion.h> 28#include <qpe/timeconversion.h>
29#include <qpe/timestring.h> 29#include <qpe/timestring.h>
30#include <qpe/tzselect.h> 30#include <qpe/tzselect.h>
31 31
32#include <qevent.h> 32#include <qevent.h>
33#include <qcheckbox.h> 33#include <qcheckbox.h>
34#include <qcombobox.h> 34#include <qcombobox.h>
35#include <qlayout.h> 35#include <qlayout.h>
36#include <qlineedit.h> 36#include <qlineedit.h>
37#include <qmultilineedit.h> 37#include <qmultilineedit.h>
38#include <qpopupmenu.h> 38#include <qpopupmenu.h>
39#include <qscrollview.h> 39#include <qscrollview.h>
40#include <qspinbox.h> 40#include <qspinbox.h>
41#include <qtoolbutton.h> 41#include <qtoolbutton.h>
42 42
43#include "timepicker.h" 43#include "timepicker.h"
44#include "onoteedit.h" 44#include "onoteedit.h"
45 45
46#include <stdlib.h> 46#include <stdlib.h>
47#include <stdio.h> 47#include <stdio.h>
48 48
49/* 49/*
50 * Constructs a DateEntry which is a child of 'parent', with the 50 * Constructs a DateEntry which is a child of 'parent', with the
51 * name 'name' and widget flags set to 'f' 51 * name 'name' and widget flags set to 'f'
52 * 52 *
53 * The dialog will by default be modeless, unless you set 'modal' to 53 * The dialog will by default be modeless, unless you set 'modal' to
54 * TRUE to construct a modal dialog. 54 * TRUE to construct a modal dialog.
55 */ 55 */
56 56
57DateEntry::DateEntry( bool startOnMonday, const QDateTime &start, 57DateEntry::DateEntry( bool startOnMonday, const QDateTime &start,
58 const QDateTime &end, bool whichClock, QWidget* parent, 58 const QDateTime &end, bool whichClock, QWidget* parent,
59 const char* name ) 59 const char* name )
60 : DateEntryBase( parent, name ), 60 : DateEntryBase( parent, name ),
61 ampm( whichClock ), 61 ampm( whichClock ),
62 startWeekOnMonday( startOnMonday ), 62 startWeekOnMonday( startOnMonday ),
63 m_showStart(true) 63 m_showStart(true)
64{ 64{
65 init(); 65 init();
66 setDates(start,end); 66 setDates(start,end);
67 setFocusProxy(comboDescription); 67 setFocusProxy(comboDescription);
68} 68}
69 69
70bool DateEntry::eventFilter(QObject *obj, QEvent *ev ) 70bool DateEntry::eventFilter(QObject *obj, QEvent *ev )
71{ 71{
72 if( ev->type() == QEvent::FocusIn ){ 72 if( ev->type() == QEvent::FocusIn ){
73 if( obj == comboStart ){ 73 if( obj == comboStart ){
74 timePickerStart->setHour(startTime.hour()); 74 timePickerStart->setHour(startTime.hour());
75 timePickerStart->setMinute(startTime.minute()); 75 timePickerStart->setMinute(startTime.minute());
76 TimePickerLabel->setText( tr("Start Time" ) ); 76 TimePickerLabel->setText( tr("Start Time" ) );
77 m_showStart= true; 77 m_showStart= true;
78 }else if( obj == comboEnd ){ 78 }else if( obj == comboEnd ){
79 timePickerStart->setHour(endTime.hour()); 79 timePickerStart->setHour(endTime.hour());
80 timePickerStart->setMinute(endTime.minute()); 80 timePickerStart->setMinute(endTime.minute());
81 TimePickerLabel->setText( tr("End Time") ); 81 TimePickerLabel->setText( tr("End Time") );
82 m_showStart = false; 82 m_showStart = false;
83 } 83 }
84 } else if( ev->type() == QEvent::FocusOut ){ 84 } else if( ev->type() == QEvent::FocusOut ){
85 if( obj == comboEnd ){ 85 if( obj == comboEnd ){
86 QString s; 86 QString s;
87 s.sprintf("%.2d:%.2d",endTime.hour(), endTime.minute()); 87 s.sprintf("%.2d:%.2d",endTime.hour(), endTime.minute());
88 comboEnd->setText(s); 88 comboEnd->setText(s);
89 } 89 }
90 else if( obj == comboStart ){ 90 else if( obj == comboStart ){
91 QString s; 91 QString s;
92 s.sprintf("%.2d:%.2d",startTime.hour(), startTime.minute()); 92 s.sprintf("%.2d:%.2d",startTime.hour(), startTime.minute());
93 comboStart->setText(s); 93 comboStart->setText(s);
94 } 94 }
95 } 95 }
96 96
97 return false; 97 return false;
98} 98}
99 99
100static void addOrPick( QComboBox* combo, const QString& t ) 100static void addOrPick( QComboBox* combo, const QString& t )
101{ 101{
102 // Pick an item if one excists 102 // Pick an item if one excists
103 for (int i=0; i<combo->count(); i++) { 103 for (int i=0; i<combo->count(); i++) {
104 if ( combo->text(i) == t ) { 104 if ( combo->text(i) == t ) {
105 combo->setCurrentItem(i); 105 combo->setCurrentItem(i);
106 return; 106 return;
107 } 107 }
108 } 108 }
109 109
110 // Else add one 110 // Else add one
111 combo->insertItem(t); 111 combo->insertItem(t);
112 combo->setCurrentItem(combo->count()-1); 112 combo->setCurrentItem(combo->count()-1);
113} 113}
114 114
115DateEntry::DateEntry( bool startOnMonday, const Event &event, bool whichClock, 115DateEntry::DateEntry( bool startOnMonday, const Event &event, bool whichClock,
116 QWidget* parent, const char* name ) 116 QWidget* parent, const char* name )
117 : DateEntryBase( parent, name ), 117 : DateEntryBase( parent, name ),
118 ampm( whichClock ), 118 ampm( whichClock ),
119 startWeekOnMonday( startOnMonday ), 119 startWeekOnMonday( startOnMonday ),
120 m_showStart(true) 120 m_showStart(true)
121 121
122{ 122{
123 init(); 123 init();
124 setDates(event.start(),event.end()); 124 setDates(event.start(),event.end());
125 comboCategory->setCategories( event.categories(), "Calendar", tr("Calendar") ); 125 comboCategory->setCategories( event.categories(), "Calendar", tr("Calendar") );
126 if(!event.description().isEmpty()) 126 if(!event.description().isEmpty())
127 addOrPick( comboDescription, event.description() ); 127 addOrPick( comboDescription, event.description() );
128 if(!event.location().isEmpty()) 128 if(!event.location().isEmpty())
129 addOrPick( comboLocation, event.location() ); 129 addOrPick( comboLocation, event.location() );
130 checkAlarm->setChecked( event.hasAlarm() ); 130 checkAlarm->setChecked( event.hasAlarm() );
131 checkAllDay->setChecked( event.type() == Event::AllDay ); 131 checkAllDay->setChecked( event.type() == Event::AllDay );
132 if(!event.notes().isEmpty()) noteStr=event.notes(); 132 if(!event.notes().isEmpty()) noteStr=event.notes();
133 else noteStr=""; 133 else noteStr="";
134 spinAlarm->setValue(event.alarmTime()); 134 spinAlarm->setValue(event.alarmTime());
135 if ( event.alarmSound() != Event::Silent ) 135 if ( event.alarmSound() != Event::Silent )
136 comboSound->setCurrentItem( 1 ); 136 comboSound->setCurrentItem( 1 );
137 if ( event.hasRepeat() ) { 137 if ( event.hasRepeat() ) {
138 rp = event.repeatPattern(); 138 rp = event.repeatPattern();
139 cmdRepeat->setText( tr("Repeat...") ); 139 cmdRepeat->setText( tr("Repeat...") );
140 } 140 }
141 setRepeatLabel(); 141 setRepeatLabel();
142} 142}
143 143
144void DateEntry::setDates( const QDateTime& s, const QDateTime& e ) 144void DateEntry::setDates( const QDateTime& s, const QDateTime& e )
145{ 145{
146 startDate = s.date(); 146 startDate = s.date();
147 endDate = e.date(); 147 endDate = e.date();
148 startTime = s.time(); 148 startTime = s.time();
149 endTime = e.time(); 149 endTime = e.time();
150 150
151 startDateChanged( s.date().year(), s.date().month(), s.date().day() ); 151 startDateChanged( s.date().year(), s.date().month(), s.date().day() );
152 endDateChanged( e.date().year(), e.date().month(), e.date().day() ); 152 endDateChanged( e.date().year(), e.date().month(), e.date().day() );
153 153
154 updateTimeEdit(true,true); 154 updateTimeEdit(true,true);
155} 155}
156 156
157void DateEntry::updateTimeEdit(bool s, bool e) { 157void DateEntry::updateTimeEdit(bool s, bool e) {
158 158
159 // Comboboxes 159 // Comboboxes
160 QString strStart, strEnd; 160 QString strStart, strEnd;
161 int shour, ehour; 161 int shour, ehour;
162 if ( ampm ) { 162 if ( ampm ) {
163 shour = startTime.hour(); 163 shour = startTime.hour();
164 ehour = endTime.hour(); 164 ehour = endTime.hour();
165 if ( shour >= 12 ) { 165 if ( shour >= 12 ) {
166 if ( shour > 12 ) 166 if ( shour > 12 )
167 shour -= 12; 167 shour -= 12;
168 strStart.sprintf( "%d:%02d PM", shour, startTime.minute() ); 168 strStart.sprintf( "%d:%02d PM", shour, startTime.minute() );
169 } else { 169 } else {
170 if ( shour == 0 ) 170 if ( shour == 0 )
171 shour = 12; 171 shour = 12;
172 strStart.sprintf( "%d:%02d AM", shour, startTime.minute() ); 172 strStart.sprintf( "%d:%02d AM", shour, startTime.minute() );
173 } 173 }
174 if ( ehour == 24 && endTime.minute() == 0 ) { 174 if ( ehour == 24 && endTime.minute() == 0 ) {
175 strEnd = "11:59 PM"; // or "midnight" 175 strEnd = "11:59 PM"; // or "midnight"
176 } else if ( ehour >= 12 ) { 176 } else if ( ehour >= 12 ) {
177 if ( ehour > 12 ) 177 if ( ehour > 12 )
178 ehour -= 12; 178 ehour -= 12;
179 strEnd.sprintf( "%d:%02d PM", ehour, endTime.minute() ); 179 strEnd.sprintf( "%d:%02d PM", ehour, endTime.minute() );
180 } else { 180 } else {
181 if ( ehour == 0 ) 181 if ( ehour == 0 )
182 ehour = 12; 182 ehour = 12;
183 strEnd.sprintf( "%d:%02d AM", ehour, endTime.minute() ); 183 strEnd.sprintf( "%d:%02d AM", ehour, endTime.minute() );
184 } 184 }
185 } else { 185 } else {
186 strStart.sprintf( "%02d:%02d", startTime.hour(), startTime.minute() ); 186 strStart.sprintf( "%02d:%02d", startTime.hour(), startTime.minute() );
187 strEnd.sprintf( "%02d:%02d", endTime.hour(), endTime.minute() ); 187 strEnd.sprintf( "%02d:%02d", endTime.hour(), endTime.minute() );
188 } 188 }
189 189
190 if (s) comboStart->setText(strStart); 190 if (s) comboStart->setText(strStart);
191 if (e) comboEnd->setText(strEnd); 191 if (e) comboEnd->setText(strEnd);
192} 192}
193 193
194void DateEntry::init() 194void DateEntry::init()
195{ 195{
196 comboDescription->setInsertionPolicy(QComboBox::AtCurrent); 196 comboDescription->setInsertionPolicy(QComboBox::AtCurrent);
197 comboLocation->setInsertionPolicy(QComboBox::AtCurrent); 197 comboLocation->setInsertionPolicy(QComboBox::AtCurrent);
198 198
199 initCombos(); 199 initCombos();
200 QPopupMenu *m1 = new QPopupMenu( this ); 200 QPopupMenu *m1 = new QPopupMenu( this );
201 startPicker = new DateBookMonth( m1, 0, TRUE ); 201 startPicker = new DateBookMonth( m1, 0, TRUE );
202 m1->insertItem( startPicker ); 202 m1->insertItem( startPicker );
203 buttonStart->setPopup( m1 ); 203 buttonStart->setPopup( m1 );
204 connect( startPicker, SIGNAL( dateClicked( int, int, int ) ), 204 connect( startPicker, SIGNAL( dateClicked( int, int, int ) ),
205 this, SLOT( startDateChanged( int, int, int ) ) ); 205 this, SLOT( startDateChanged( int, int, int ) ) );
206 206
207 //Let start button change both start and end dates 207 //Let start button change both start and end dates
208 connect( startPicker, SIGNAL( dateClicked( int, int, int ) ), 208 connect( startPicker, SIGNAL( dateClicked( int, int, int ) ),
209 this, SLOT( endDateChanged( int, int, int ) ) ); 209 this, SLOT( endDateChanged( int, int, int ) ) );
210 connect( qApp, SIGNAL( clockChanged( bool ) ), 210 connect( qApp, SIGNAL( clockChanged( bool ) ),
211 this, SLOT( slotChangeClock( bool ) ) ); 211 this, SLOT( slotChangeClock( bool ) ) );
212 connect( qApp, SIGNAL(weekChanged(bool)), 212 connect( qApp, SIGNAL(weekChanged(bool)),
213 this, SLOT(slotChangeStartOfWeek(bool)) ); 213 this, SLOT(slotChangeStartOfWeek(bool)) );
214 214
215 connect( editNote, SIGNAL(clicked()), 215 connect( editNote, SIGNAL(clicked()),
216 this, SLOT(slotEditNote()) ); 216 this, SLOT(slotEditNote()) );
217 217
218 QPopupMenu *m2 = new QPopupMenu( this ); 218 QPopupMenu *m2 = new QPopupMenu( this );
219 endPicker = new DateBookMonth( m2, 0, TRUE ); 219 endPicker = new DateBookMonth( m2, 0, TRUE );
220 m2->insertItem( endPicker ); 220 m2->insertItem( endPicker );
221 buttonEnd->setPopup( m2 ); 221 buttonEnd->setPopup( m2 );
222 connect( endPicker, SIGNAL( dateClicked( int, int, int ) ), 222 connect( endPicker, SIGNAL( dateClicked( int, int, int ) ),
223 this, SLOT( endDateChanged( int, int, int ) ) ); 223 this, SLOT( endDateChanged( int, int, int ) ) );
224 224
225 connect(timePickerStart, SIGNAL( timeChanged(const QTime &) ), 225 connect(timePickerStart, SIGNAL( timeChanged(const QTime &) ),
226 this, SLOT( startTimePicked(const QTime &) )); 226 this, SLOT( startTimePicked(const QTime &) ));
227 // install eventFilters 227 // install eventFilters
228 comboEnd->installEventFilter( this ); 228 comboEnd->installEventFilter( this );
229 comboStart->installEventFilter( this ); 229 comboStart->installEventFilter( this );
230} 230}
231 231
232/* 232/*
233 * Destroys the object and frees any allocated resources 233 * Destroys the object and frees any allocated resources
234 */ 234 */
235DateEntry::~DateEntry() 235DateEntry::~DateEntry()
236{ 236{
237 // no need to delete child widgets, Qt does it all for us 237 // no need to delete child widgets, Qt does it all for us
238 //cout << "Del: " << comboStart->currentText() << endl; 238 //cout << "Del: " << comboStart->currentText() << endl;
239} 239}
240 240
241/* 241/*
242 * public slot 242 * public slot
243 */ 243 */
244 244
245void DateEntry::slotEditNote() { 245void DateEntry::slotEditNote() {
246 QString s; 246 QString s;
247 s.sprintf("<B>%d/%d</B> ", startDate.day(), startDate.month()); 247 s.sprintf("<B>%d/%d</B> ", startDate.day(), startDate.month());
248 NoteEntry noteDlg(s+comboDescription->currentText(), noteStr, 248 NoteEntry noteDlg(s+comboDescription->currentText(), noteStr,
249 this,0,TRUE); 249 this,0,TRUE);
250 250
251#if defined(Q_WS_QWS) || defined(_WS_QWS_) 251#if defined(Q_WS_QWS) || defined(_WS_QWS_)
252 noteDlg.showMaximized(); 252 noteDlg.showMaximized();
253#endif 253#endif
254 if (noteDlg.exec() ) { 254 if (noteDlg.exec() ) {
255 noteStr=noteDlg.note->text(); 255 noteStr=noteDlg.note->text();
256 } 256 }
257 257
258} 258}
259 259
260void DateEntry::endDateChanged( int y, int m, int d ) 260void DateEntry::endDateChanged( int y, int m, int d )
261{ 261{
262 endDate.setYMD( y, m, d ); 262 endDate.setYMD( y, m, d );
263 if ( endDate < startDate ) { 263 if ( endDate < startDate ) {
264 endDate = startDate; 264 endDate = startDate;
265 } 265 }
266 266
267 buttonEnd->setText( TimeString::shortDate( endDate ) ); 267 buttonEnd->setText( TimeString::shortDate( endDate ) );
268 268
269 endPicker->setDate( endDate.year(), endDate.month(), endDate.day() ); 269 endPicker->setDate( endDate.year(), endDate.month(), endDate.day() );
270} 270}
271 271
272static QTime parseTime( const QString& s, bool ampm ) 272static QTime parseTime( const QString& s, bool ampm )
273{ 273{
274 QTime tmpTime; 274 QTime tmpTime;
275 QStringList l = QStringList::split( ':', s ); 275 QStringList l = QStringList::split( ':', s );
276 int hour = l[0].toInt(); 276 int hour = l[0].toInt();
277 if ( ampm ) { 277 if ( ampm ) {
278 int i=0; 278 int i=0;
279 while (i<int(l[1].length()) && l[1][i]>='0' && l[1][i]<='9') 279 while (i<int(l[1].length()) && l[1][i]>='0' && l[1][i]<='9')
280 i++; 280 i++;
281 QString digits = l[1].left(i); 281 QString digits = l[1].left(i);
282 if ( l[1].contains( "PM", FALSE ) ) { 282 if ( l[1].contains( "PM", FALSE ) ) {
283 if ( hour != 12 ) 283 if ( hour != 12 )
284 hour += 12; 284 hour += 12;
285 } else { 285 } else {
286 if ( hour == 12 ) 286 if ( hour == 12 )
287 hour = 0; 287 hour = 0;
288 } 288 }
289 l[1] = digits; 289 l[1] = digits;
290 } 290 }
291 int minute = l[1].toInt(); 291 int minute = l[1].toInt();
292 if ( minute > 59 ) 292 if ( minute > 59 )
293 minute = 59; 293 minute = 59;
294 else if ( minute < 0 ) 294 else if ( minute < 0 )
295 minute = 0; 295 minute = 0;
296 if ( hour > 23 ) { 296 if ( hour > 23 ) {
297 hour = 23; 297 hour = 23;
298 minute = 59; 298 minute = 59;
299 } else if ( hour < 0 ) 299 } else if ( hour < 0 )
300 hour = 0; 300 hour = 0;
301 tmpTime.setHMS( hour, minute, 0 ); 301 tmpTime.setHMS( hour, minute, 0 );
302 return tmpTime; 302 return tmpTime;
303} 303}
304 304
305/* 305/*
306 * public slot 306 * public slot
307 */ 307 */
308void DateEntry::endTimeChanged( const QString &s ) 308void DateEntry::endTimeChanged( const QString &s )
309{ 309{
310 endTimeChanged( parseTime(s,ampm) ); 310 endTimeChanged( parseTime(s,ampm) );
311} 311}
312 312
313void DateEntry::endTimeChanged( const QTime &t ) { 313void DateEntry::endTimeChanged( const QTime &t ) {
314 if ( endDate > startDate || t >= startTime ) { 314 if ( endDate > startDate || t >= startTime ) {
315 endTime = t; 315 endTime = t;
316 } else { 316 } else {
317 endTime = startTime; 317 endTime = startTime;
318 //comboEnd->setCurrentItem( comboStart->currentItem() ); 318 //comboEnd->setCurrentItem( comboStart->currentItem() );
319 } 319 }
320 timePickerStart->setHour(endTime.hour()); 320 timePickerStart->setHour(endTime.hour());
321 timePickerStart->setMinute(endTime.minute()); 321 timePickerStart->setMinute(endTime.minute());
322} 322}
323 323
324/* 324/*
325 * public slot 325 * public slot
326 */ 326 */
327void DateEntry::startDateChanged( int y, int m, int d ) 327void DateEntry::startDateChanged( int y, int m, int d )
328{ 328{
329 QDate prev = startDate; 329 QDate prev = startDate;
330 startDate.setYMD( y, m, d ); 330 startDate.setYMD( y, m, d );
331 if ( rp.type == Event::Weekly && 331 if ( rp.type == Event::Weekly &&
332 startDate.dayOfWeek() != prev.dayOfWeek() ) { 332 startDate.dayOfWeek() != prev.dayOfWeek() ) {
333 // if we change the start of a weekly repeating event 333 // if we change the start of a weekly repeating event
334 // set the repeating day appropriately 334 // set the repeating day appropriately
335 char mask = 1 << (prev.dayOfWeek()-1); 335 char mask = 1 << (prev.dayOfWeek()-1);
336 rp.days &= (~mask); 336 rp.days &= (~mask);
337 rp.days |= 1 << (startDate.dayOfWeek()-1); 337 rp.days |= 1 << (startDate.dayOfWeek()-1);
338 } 338 }
339 339
340 buttonStart->setText( TimeString::shortDate( startDate ) ); 340 buttonStart->setText( TimeString::shortDate( startDate ) );
341 341
342 // our pickers must be reset... 342 // our pickers must be reset...
343 startPicker->setDate( y, m, d ); 343 startPicker->setDate( y, m, d );
344 endPicker->setDate( y, m, d ); 344 endPicker->setDate( y, m, d );
345} 345}
346 346
347/* 347/*
348 * public slot 348 * public slot
349 */ 349 */
350void DateEntry::startTimeEdited( const QString &s ) 350void DateEntry::startTimeEdited( const QString &s )
351{ 351{
352 startTimeChanged(parseTime(s,ampm)); 352 startTimeChanged(parseTime(s,ampm));
353 updateTimeEdit(false,true); 353 updateTimeEdit(false,true);
354 timePickerStart->setHour(startTime.hour()); 354 timePickerStart->setHour(startTime.hour());
355 timePickerStart->setMinute(startTime.minute()); 355 timePickerStart->setMinute(startTime.minute());
356} 356}
357 357
358void DateEntry::startTimeChanged( const QTime &t ) 358void DateEntry::startTimeChanged( const QTime &t )
359{ 359{
360 int duration=startTime.secsTo(endTime); 360 int duration=startTime.secsTo(endTime);
361 startTime = t; 361 startTime = t;
362 endTime=t.addSecs(duration); 362 endTime=t.addSecs(duration);
363} 363}
364void DateEntry::startTimePicked( const QTime &t ) { 364void DateEntry::startTimePicked( const QTime &t ) {
365 if(m_showStart ){ 365 if(m_showStart ){
366 startTimeChanged(t); 366 startTimeChanged(t);
367 updateTimeEdit(true,true); 367 updateTimeEdit(true,true);
368 }else{ 368 }else{
369 endTimeChanged(t); 369 endTimeChanged(t);
370 updateTimeEdit(false, true ); 370 updateTimeEdit(false, true );
371 } 371 }
372} 372}
373 373
374/* 374/*
375 * public slot 375 * public slot
376 */ 376 */
377void DateEntry::typeChanged( const QString &s ) 377void DateEntry::typeChanged( const QString &s )
378{ 378{
379 bool b = s != "All Day"; 379 bool b = s != "All Day";
380 buttonStart->setEnabled( b ); 380 buttonStart->setEnabled( b );
381 comboStart->setEnabled( b ); 381 comboStart->setEnabled( b );
382 comboEnd->setEnabled( b ); 382 comboEnd->setEnabled( b );
383} 383}
384 384
385void DateEntry::slotRepeat() 385void DateEntry::slotRepeat()
386{ 386{
387 // Work around for compiler Bug.. 387 // Work around for compiler Bug..
388 RepeatEntry *e; 388 RepeatEntry *e;
389 389
390 // it is better in my opinion to just grab this from the mother, 390 // it is better in my opinion to just grab this from the mother,
391 // since, this dialog doesn't need to keep track of it... 391 // since, this dialog doesn't need to keep track of it...
392 if ( rp.type != Event::NoRepeat ) 392 if ( rp.type != Event::NoRepeat )
393 e = new RepeatEntry( startWeekOnMonday, rp, startDate, this); 393 e = new RepeatEntry( startWeekOnMonday, rp, startDate, this);
394 else 394 else
395 e = new RepeatEntry( startWeekOnMonday, startDate, this ); 395 e = new RepeatEntry( startWeekOnMonday, startDate, this );
396 396
397#if defined(Q_WS_QWS) || defined(_WS_QWS_) 397#if defined(Q_WS_QWS) || defined(_WS_QWS_)
398 e->showMaximized(); 398 e->showMaximized();
399#endif 399#endif
400 if ( e->exec() ) { 400 if ( e->exec() ) {
401 rp = e->repeatPattern(); 401 rp = e->repeatPattern();
402 setRepeatLabel(); 402 setRepeatLabel();
403 } 403 }
404} 404}
405 405
406void DateEntry::slotChangeStartOfWeek( bool onMonday ) 406void DateEntry::slotChangeStartOfWeek( bool onMonday )
407{ 407{
408 startWeekOnMonday = onMonday; 408 startWeekOnMonday = onMonday;
409} 409}
410 410
411Event DateEntry::event() 411Event DateEntry::event()
412{ 412{
413 Event ev; 413 Event ev;
414 Event::SoundTypeChoice st; 414 Event::SoundTypeChoice st;
415 ev.setDescription( comboDescription->currentText() ); 415 ev.setDescription( comboDescription->currentText() );
416 ev.setLocation( comboLocation->currentText() ); 416 ev.setLocation( comboLocation->currentText() );
417 ev.setCategories( comboCategory->currentCategories() ); 417 ev.setCategories( comboCategory->currentCategories() );
418 ev.setType( checkAllDay->isChecked() ? Event::AllDay : Event::Normal ); 418 ev.setType( checkAllDay->isChecked() ? Event::AllDay : Event::Normal );
419 if ( startDate > endDate ) { 419 if ( startDate > endDate ) {
420 QDate tmp = endDate; 420 QDate tmp = endDate;
421 endDate = startDate; 421 endDate = startDate;
422 startDate = tmp; 422 startDate = tmp;
423 } 423 }
424 424
425 // This is now done in the changed slots 425 // This is now done in the changed slots
426 // startTime = parseTime( comboStart->text(), ampm ); 426 // startTime = parseTime( comboStart->text(), ampm );
427 //endTime = parseTime( comboEnd->text(), ampm ); 427 //endTime = parseTime( comboEnd->text(), ampm );
428 428
429 if ( startTime > endTime && endDate == startDate ) { 429 if ( startTime > endTime && endDate == startDate ) {
430 QTime tmp = endTime; 430 QTime tmp = endTime;
431 endTime = startTime; 431 endTime = startTime;
432 startTime = tmp; 432 startTime = tmp;
433 } 433 }
434 // don't set the time if theres no need too 434 // don't set the time if theres no need too
435 if ( ev.type() == Event::AllDay ) { 435 if ( ev.type() == Event::AllDay ) {
436 startTime.setHMS( 0, 0, 0 ); 436 startTime.setHMS( 0, 0, 0 );
437 endTime.setHMS( 23, 59, 59 ); 437 endTime.setHMS( 23, 59, 59 );
438 } 438 }
439 439
440 // adjust start and end times based on timezone 440 // adjust start and end times based on timezone
441 QDateTime start( startDate, startTime ); 441 QDateTime start( startDate, startTime );
442 QDateTime end( endDate, endTime ); 442 QDateTime end( endDate, endTime );
443 time_t start_utc, end_utc; 443 time_t start_utc, end_utc;
444 444
445// qDebug( "tz: %s", timezone->currentZone().latin1() ); 445// qDebug( "tz: %s", timezone->currentZone().latin1() );
446 446
447 // get real timezone 447 // get real timezone
448 QString realTZ; 448 QString realTZ;
449 realTZ = QString::fromLocal8Bit( getenv("TZ") ); 449 realTZ = QString::fromLocal8Bit( getenv("TZ") );
450 450
451 // set timezone 451 // set timezone
452 if ( setenv( "TZ", timezone->currentZone(), true ) != 0 ) 452 if ( setenv( "TZ", timezone->currentZone(), true ) != 0 )
453 qWarning( "There was a problem setting the timezone." ); 453 qWarning( "There was a problem setting the timezone." );
454 454
455 // convert to UTC based on selected TZ (calling tzset internally) 455 // convert to UTC based on selected TZ (calling tzset internally)
456 start_utc = TimeConversion::toUTC( start ); 456 start_utc = TimeConversion::toUTC( start );
457 end_utc = TimeConversion::toUTC( end ); 457 end_utc = TimeConversion::toUTC( end );
458 458
459 // done playing around... put it all back 459 // done playing around... put it all back
460 unsetenv( "TZ" ); 460 unsetenv( "TZ" );
461 if ( !realTZ.isNull() ) 461 if ( !realTZ.isNull() )
462 if ( setenv( "TZ", realTZ, true ) != 0 ) 462 if ( setenv( "TZ", realTZ, true ) != 0 )
463 qWarning( "There was a problem setting the timezone." ); 463 qWarning( "There was a problem setting the timezone." );
464 464
465 // convert UTC to local time (calling tzset internally) 465 // convert UTC to local time (calling tzset internally)
466 ev.setStart( TimeConversion::fromUTC( start_utc ) ); 466 ev.setStart( TimeConversion::fromUTC( start_utc ) );
467 ev.setEnd( TimeConversion::fromUTC( end_utc ) ); 467 ev.setEnd( TimeConversion::fromUTC( end_utc ) );
468 468
469 // we only have one type of sound at the moment... LOUD!!! 469 // we only have one type of sound at the moment... LOUD!!!
470 if ( comboSound->currentItem() != 0 ) 470 if ( comboSound->currentItem() != 0 )
471 st = Event::Loud; 471 st = Event::Loud;
472 else 472 else
473 st = Event::Silent; 473 st = Event::Silent;
474 ev.setAlarm( checkAlarm->isChecked(), spinAlarm->value(), st ); 474 ev.setAlarm( checkAlarm->isChecked(), spinAlarm->value(), st );
475 if ( rp.type != Event::NoRepeat ) 475 if ( rp.type != Event::NoRepeat )
476 ev.setRepeat( TRUE, rp ); 476 ev.setRepeat( TRUE, rp );
477 ev.setNotes( noteStr ); 477 ev.setNotes( noteStr );
478 478
479 //cout << "Start: " << comboStart->currentText() << endl; 479 //cout << "Start: " << comboStart->currentText() << endl;
480 480
481 return ev; 481 return ev;
482} 482}
483 483
484void DateEntry::setRepeatLabel() 484void DateEntry::setRepeatLabel()
485{ 485{
486 486
487 switch( rp.type ) { 487 switch( rp.type ) {
488 case Event::Daily: 488 case Event::Daily:
489 cmdRepeat->setText( tr("Daily...") ); 489 cmdRepeat->setText( tr("Daily...") );
490 break; 490 break;
491 case Event::Weekly: 491 case Event::Weekly:
492 cmdRepeat->setText( tr("Weekly...") ); 492 cmdRepeat->setText( tr("Weekly...") );
493 break; 493 break;
494 case Event::MonthlyDay: 494 case Event::MonthlyDay:
495 case Event::MonthlyDate: 495 case Event::MonthlyDate:
496 cmdRepeat->setText( tr("Monthly...") ); 496 cmdRepeat->setText( tr("Monthly...") );
497 break; 497 break;
498 case Event::Yearly: 498 case Event::Yearly:
499 cmdRepeat->setText( tr("Yearly...") ); 499 cmdRepeat->setText( tr("Yearly...") );
500 break; 500 break;
501 default: 501 default:
502 cmdRepeat->setText( tr("No Repeat...") ); 502 cmdRepeat->setText( tr("No Repeat...") );
503 } 503 }
504} 504}
505 505
506void DateEntry::setAlarmEnabled( bool alarmPreset, int presetTime, Event::SoundTypeChoice sound ) 506void DateEntry::setAlarmEnabled( bool alarmPreset, int presetTime, Event::SoundTypeChoice sound )
507{ 507{
508 checkAlarm->setChecked( alarmPreset ); 508 checkAlarm->setChecked( alarmPreset );
509 spinAlarm->setValue( presetTime ); 509 spinAlarm->setValue( presetTime );
510 if ( sound != Event::Silent ) 510 if ( sound != Event::Silent )
511 comboSound->setCurrentItem( 1 ); 511 comboSound->setCurrentItem( 1 );
512 else 512 else
513 comboSound->setCurrentItem( 0 ); 513 comboSound->setCurrentItem( 0 );
514} 514}
515 515
516void DateEntry::initCombos() 516void DateEntry::initCombos()
517{ 517{
518 /* 518 /*
519 comboStart->clear(); 519 comboStart->clear();
520 comboEnd->clear(); 520 comboEnd->clear();
521 if ( ampm ) { 521 if ( ampm ) {
522 for ( int i = 0; i < 24; i++ ) { 522 for ( int i = 0; i < 24; i++ ) {
523 if ( i == 0 ) { 523 if ( i == 0 ) {
524 comboStart->insertItem( "12:00 AM" ); 524 comboStart->insertItem( "12:00 AM" );
525 comboStart->insertItem( "12:30 AM" ); 525 comboStart->insertItem( "12:30 AM" );
526 comboEnd->insertItem( "12:00 AM" ); 526 comboEnd->insertItem( "12:00 AM" );
527 comboEnd->insertItem( "12:30 AM" ); 527 comboEnd->insertItem( "12:30 AM" );
528 } else if ( i == 12 ) { 528 } else if ( i == 12 ) {
529 comboStart->insertItem( "12:00 PM" ); 529 comboStart->insertItem( "12:00 PM" );
530 comboStart->insertItem( "12:30 PM" ); 530 comboStart->insertItem( "12:30 PM" );
531 comboEnd->insertItem( "12:00 PM" ); 531 comboEnd->insertItem( "12:00 PM" );
532 comboEnd->insertItem( "12:30 PM" ); 532 comboEnd->insertItem( "12:30 PM" );
533 } else if ( i > 12 ) { 533 } else if ( i > 12 ) {
534 comboStart->insertItem( QString::number( i - 12 ) + ":00 PM" ); 534 comboStart->insertItem( QString::number( i - 12 ) + ":00 PM" );
535 comboStart->insertItem( QString::number( i - 12 ) + ":30 PM" ); 535 comboStart->insertItem( QString::number( i - 12 ) + ":30 PM" );
536 comboEnd->insertItem( QString::number( i - 12 ) + ":00 PM" ); 536 comboEnd->insertItem( QString::number( i - 12 ) + ":00 PM" );
537 comboEnd->insertItem( QString::number( i - 12 ) + ":30 PM" ); 537 comboEnd->insertItem( QString::number( i - 12 ) + ":30 PM" );
538 } else { 538 } else {
539 comboStart->insertItem( QString::number( i) + ":00 AM" ); 539 comboStart->insertItem( QString::number( i) + ":00 AM" );
540 comboStart->insertItem( QString::number( i ) + ":30 AM" ); 540 comboStart->insertItem( QString::number( i ) + ":30 AM" );
541 comboEnd->insertItem( QString::number( i ) + ":00 AM" ); 541 comboEnd->insertItem( QString::number( i ) + ":00 AM" );
542 comboEnd->insertItem( QString::number( i ) + ":30 AM" ); 542 comboEnd->insertItem( QString::number( i ) + ":30 AM" );
543 } 543 }
544 } 544 }
545 } else { 545 } else {
546 for ( int i = 0; i < 24; i++ ) { 546 for ( int i = 0; i < 24; i++ ) {
547 if ( i < 10 ) { 547 if ( i < 10 ) {
548 comboStart->insertItem( QString("0") 548 comboStart->insertItem( QString("0")
549 + QString::number(i) + ":00" ); 549 + QString::number(i) + ":00" );
550 comboStart->insertItem( QString("0") 550 comboStart->insertItem( QString("0")
551 + QString::number(i) + ":30" ); 551 + QString::number(i) + ":30" );
552 comboEnd->insertItem( QString("0") 552 comboEnd->insertItem( QString("0")
553 + QString::number(i) + ":00" ); 553 + QString::number(i) + ":00" );
554 comboEnd->insertItem( QString("0") 554 comboEnd->insertItem( QString("0")
555 + QString::number(i) + ":30" ); 555 + QString::number(i) + ":30" );
556 } else { 556 } else {
557 comboStart->insertItem( QString::number(i) + ":00" ); 557 comboStart->insertItem( QString::number(i) + ":00" );
558 comboStart->insertItem( QString::number(i) + ":30" ); 558 comboStart->insertItem( QString::number(i) + ":30" );
559 comboEnd->insertItem( QString::number(i) + ":00" ); 559 comboEnd->insertItem( QString::number(i) + ":00" );
560 comboEnd->insertItem( QString::number(i) + ":30" ); 560 comboEnd->insertItem( QString::number(i) + ":30" );
561 } 561 }
562 } 562 }
563 } 563 }
564 */ 564 */
565} 565}
566 566
567void DateEntry::slotChangeClock( bool whichClock ) 567void DateEntry::slotChangeClock( bool whichClock )
568{ 568{
569 ampm = whichClock; 569 ampm = whichClock;
570 initCombos(); 570 initCombos();
571 setDates( QDateTime( startDate, startTime ), QDateTime( endDate, endTime ) ); 571 setDates( QDateTime( startDate, startTime ), QDateTime( endDate, endTime ) );
572} 572}
573