summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--core/pim/datebook/datebook.cpp48
-rw-r--r--core/pim/datebook/datebookday.cpp236
-rw-r--r--core/pim/datebook/datebookday.h54
3 files changed, 288 insertions, 50 deletions
diff --git a/core/pim/datebook/datebook.cpp b/core/pim/datebook/datebook.cpp
index 2c2965e..c0d45c9 100644
--- a/core/pim/datebook/datebook.cpp
+++ b/core/pim/datebook/datebook.cpp
@@ -1,989 +1,991 @@
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 <qregexp.h>
59#include <qtextcodec.h> 59#include <qtextcodec.h>
60#include <qtextstream.h> 60#include <qtextstream.h>
61#include <qtl.h> 61#include <qtl.h>
62#include <qwidgetstack.h> 62#include <qwidgetstack.h>
63#include <qwindowsystem_qws.h> 63#include <qwindowsystem_qws.h>
64 64
65#include <sys/stat.h> 65#include <sys/stat.h>
66#include <sys/types.h> 66#include <sys/types.h>
67#include <fcntl.h> 67#include <fcntl.h>
68#include <unistd.h> 68#include <unistd.h>
69 69
70#include <stdlib.h> 70#include <stdlib.h>
71 71
72#define DAY 1 72#define DAY 1
73#define WEEK 2 73#define WEEK 2
74#define WEEKLST 4 74#define WEEKLST 4
75#define MONTH 3 75#define MONTH 3
76 76
77 77
78DateBook::DateBook( QWidget *parent, const char *, WFlags f ) 78DateBook::DateBook( QWidget *parent, const char *, WFlags f )
79 : QMainWindow( parent, "datebook", f ), 79 : QMainWindow( parent, "datebook", f ),
80 aPreset( FALSE ), 80 aPreset( FALSE ),
81 presetTime( -1 ), 81 presetTime( -1 ),
82 startTime( 8 ), // an acceptable default 82 startTime( 8 ), // an acceptable default
83 syncing(FALSE), 83 syncing(FALSE),
84 inSearch(FALSE), 84 inSearch(FALSE),
85 alarmCounter(0) 85 alarmCounter(0)
86{ 86{
87 QTime t; 87 QTime t;
88 t.start(); 88 t.start();
89 db = new DateBookDBHack; 89 db = new DateBookDBHack;
90 qDebug("loading db t=%d", t.elapsed() ); 90 qDebug("loading db t=%d", t.elapsed() );
91 loadSettings(); 91 loadSettings();
92 setCaption( tr("Calendar") ); 92 setCaption( tr("Calendar") );
93 setIcon( Resource::loadPixmap( "datebook_icon" ) ); 93 setIcon( Resource::loadPixmap( "datebook_icon" ) );
94 94
95 setToolBarsMovable( FALSE ); 95 setToolBarsMovable( FALSE );
96 96
97 views = new QWidgetStack( this ); 97 views = new QWidgetStack( this );
98 setCentralWidget( views ); 98 setCentralWidget( views );
99 99
100 dayView = 0; 100 dayView = 0;
101 weekView = 0; 101 weekView = 0;
102 weekLstView = 0; 102 weekLstView = 0;
103 monthView = 0; 103 monthView = 0;
104 104
105 QPEToolBar *bar = new QPEToolBar( this ); 105 QPEToolBar *bar = new QPEToolBar( this );
106 bar->setHorizontalStretchable( TRUE ); 106 bar->setHorizontalStretchable( TRUE );
107 107
108 QPEMenuBar *mb = new QPEMenuBar( bar ); 108 QPEMenuBar *mb = new QPEMenuBar( bar );
109 mb->setMargin( 0 ); 109 mb->setMargin( 0 );
110 110
111 QPEToolBar *sub_bar = new QPEToolBar(this); 111 QPEToolBar *sub_bar = new QPEToolBar(this);
112 112
113 QPopupMenu *view = new QPopupMenu( this ); 113 QPopupMenu *view = new QPopupMenu( this );
114 QPopupMenu *settings = new QPopupMenu( this ); 114 QPopupMenu *settings = new QPopupMenu( this );
115 115
116 mb->insertItem( tr( "View" ), view ); 116 mb->insertItem( tr( "View" ), view );
117 mb->insertItem( tr( "Settings" ), settings ); 117 mb->insertItem( tr( "Settings" ), settings );
118 118
119 QActionGroup *g = new QActionGroup( this ); 119 QActionGroup *g = new QActionGroup( this );
120 g->setExclusive( TRUE ); 120 g->setExclusive( TRUE );
121 121
122 QAction *a = new QAction( tr( "New" ), Resource::loadPixmap( "new" ), 122 QAction *a = new QAction( tr( "New" ), Resource::loadPixmap( "new" ),
123 QString::null, 0, this, 0 ); 123 QString::null, 0, this, 0 );
124 connect( a, SIGNAL( activated() ), this, SLOT( fileNew() ) ); 124 connect( a, SIGNAL( activated() ), this, SLOT( fileNew() ) );
125 a->addTo( sub_bar ); 125 a->addTo( sub_bar );
126 126
127 a = new QAction( tr( "Today" ), Resource::loadPixmap( "to_day" ), QString::null, 0, g, 0 ); 127 a = new QAction( tr( "Today" ), Resource::loadPixmap( "to_day" ), QString::null, 0, g, 0 );
128 connect( a, SIGNAL( activated() ), this, SLOT( slotToday() ) ); 128 connect( a, SIGNAL( activated() ), this, SLOT( slotToday() ) );
129 a->addTo( sub_bar ); 129 a->addTo( sub_bar );
130 a->addTo( view ); 130 a->addTo( view );
131 131
132 a = new QAction( tr( "Day" ), Resource::loadPixmap( "day" ), QString::null, 0, g, 0 ); 132 a = new QAction( tr( "Day" ), Resource::loadPixmap( "day" ), QString::null, 0, g, 0 );
133 connect( a, SIGNAL( activated() ), this, SLOT( viewDay() ) ); 133 connect( a, SIGNAL( activated() ), this, SLOT( viewDay() ) );
134 a->addTo( sub_bar ); 134 a->addTo( sub_bar );
135 a->addTo( view ); 135 a->addTo( view );
136 a->setToggleAction( TRUE ); 136 a->setToggleAction( TRUE );
137 a->setOn( TRUE ); 137 a->setOn( TRUE );
138 dayAction = a; 138 dayAction = a;
139 139
140 a = new QAction( tr( "Week" ), Resource::loadPixmap( "week" ), QString::null, 0, g, 0 ); 140 a = new QAction( tr( "Week" ), Resource::loadPixmap( "week" ), QString::null, 0, g, 0 );
141 connect( a, SIGNAL( activated() ), this, SLOT( viewWeek() ) ); 141 connect( a, SIGNAL( activated() ), this, SLOT( viewWeek() ) );
142 a->addTo( sub_bar ); 142 a->addTo( sub_bar );
143 a->addTo( view ); 143 a->addTo( view );
144 a->setToggleAction( TRUE ); 144 a->setToggleAction( TRUE );
145 weekAction = a; 145 weekAction = a;
146 146
147 a = new QAction( tr( "WeekLst" ), Resource::loadPixmap( "weeklst" ), QString::null, 0, g, 0 ); 147 a = new QAction( tr( "WeekLst" ), Resource::loadPixmap( "weeklst" ), QString::null, 0, g, 0 );
148 connect( a, SIGNAL( activated() ), this, SLOT( viewWeekLst() ) ); 148 connect( a, SIGNAL( activated() ), this, SLOT( viewWeekLst() ) );
149 a->addTo( sub_bar ); 149 a->addTo( sub_bar );
150 a->addTo( view ); 150 a->addTo( view );
151 a->setToggleAction( TRUE ); 151 a->setToggleAction( TRUE );
152 weekLstAction = a; 152 weekLstAction = a;
153 153
154 a = new QAction( tr( "Month" ), Resource::loadPixmap( "month" ), QString::null, 0, g, 0 ); 154 a = new QAction( tr( "Month" ), Resource::loadPixmap( "month" ), QString::null, 0, g, 0 );
155 connect( a, SIGNAL( activated() ), this, SLOT( viewMonth() ) ); 155 connect( a, SIGNAL( activated() ), this, SLOT( viewMonth() ) );
156 a->addTo( sub_bar ); 156 a->addTo( sub_bar );
157 a->addTo( view ); 157 a->addTo( view );
158 a->setToggleAction( TRUE ); 158 a->setToggleAction( TRUE );
159 monthAction = a; 159 monthAction = a;
160 160
161 a = new QAction( tr( "Find" ), Resource::loadPixmap( "mag" ), QString::null, 0, g, 0 ); 161 a = new QAction( tr( "Find" ), Resource::loadPixmap( "mag" ), QString::null, 0, g, 0 );
162 connect( a, SIGNAL(activated()), this, SLOT(slotFind()) ); 162 connect( a, SIGNAL(activated()), this, SLOT(slotFind()) );
163 a->addTo( sub_bar ); 163 a->addTo( sub_bar );
164 164
165 a = new QAction( tr( "Alarm and Start Time..." ), QString::null, 0, 0 ); 165 a = new QAction( tr( "Alarm and Start Time..." ), QString::null, 0, 0 );
166 connect( a, SIGNAL( activated() ), this, SLOT( slotSettings() ) ); 166 connect( a, SIGNAL( activated() ), this, SLOT( slotSettings() ) );
167 a->addTo( settings ); 167 a->addTo( settings );
168 168
169 QPopupMenu *default_view = new QPopupMenu(this); 169 QPopupMenu *default_view = new QPopupMenu(this);
170 settings->insertItem( tr( "Default View" ),default_view ); 170 settings->insertItem( tr( "Default View" ),default_view );
171 default_view->setCheckable(TRUE); 171 default_view->setCheckable(TRUE);
172 172
173 Config config("DateBook"); 173 Config config("DateBook");
174 config.setGroup("Main"); 174 config.setGroup("Main");
175 int current=config.readNumEntry("defaultview", DAY); 175 int current=config.readNumEntry("defaultview", DAY);
176 176
177 QActionGroup *ag = new QActionGroup(this); 177 QActionGroup *ag = new QActionGroup(this);
178 a = new QAction( tr( "Day" ), QString::null, 0, 0, 0, true ); 178 a = new QAction( tr( "Day" ), QString::null, 0, 0, 0, true );
179 if (current==DAY) a->setOn(true), viewDay(); 179 if (current==DAY) a->setOn(true), viewDay();
180 ag->insert(a); 180 ag->insert(a);
181 a = new QAction( tr( "Week" ), QString::null, 0, 0, 0, true ); 181 a = new QAction( tr( "Week" ), QString::null, 0, 0, 0, true );
182 if (current==WEEK) a->setOn(true), viewWeek(); 182 if (current==WEEK) a->setOn(true), viewWeek();
183 ag->insert(a); 183 ag->insert(a);
184 a = new QAction( tr( "WeekLst" ), QString::null, 0, 0, 0, true ); 184 a = new QAction( tr( "WeekLst" ), QString::null, 0, 0, 0, true );
185 if (current==WEEKLST) a->setOn(true), viewWeekLst(); 185 if (current==WEEKLST) a->setOn(true), viewWeekLst();
186 ag->insert(a); 186 ag->insert(a);
187 a = new QAction( tr( "Month" ), QString::null, 0, 0, 0, true ); 187 a = new QAction( tr( "Month" ), QString::null, 0, 0, 0, true );
188 if (current==MONTH) a->setOn(true), viewMonth(); 188 if (current==MONTH) a->setOn(true), viewMonth();
189 ag->insert(a); 189 ag->insert(a);
190 190
191 ag->addTo(default_view); 191 ag->addTo(default_view);
192 connect(ag, SIGNAL( selected ( QAction * ) ), 192 connect(ag, SIGNAL( selected ( QAction * ) ),
193 this, SLOT( newDefaultView(QAction *) ) 193 this, SLOT( newDefaultView(QAction *) )
194 ); 194 );
195 195
196 connect( qApp, SIGNAL(clockChanged(bool)), 196 connect( qApp, SIGNAL(clockChanged(bool)),
197 this, SLOT(changeClock(bool)) ); 197 this, SLOT(changeClock(bool)) );
198 connect( qApp, SIGNAL(weekChanged(bool)), 198 connect( qApp, SIGNAL(weekChanged(bool)),
199 this, SLOT(changeWeek(bool)) ); 199 this, SLOT(changeWeek(bool)) );
200 200
201#if defined(Q_WS_QWS) && !defined(QT_NO_COP) 201#if defined(Q_WS_QWS) && !defined(QT_NO_COP)
202 connect( qApp, SIGNAL(appMessage(const QCString&, const QByteArray&)), 202 connect( qApp, SIGNAL(appMessage(const QCString&, const QByteArray&)),
203 this, SLOT(appMessage(const QCString&, const QByteArray&)) ); 203 this, SLOT(appMessage(const QCString&, const QByteArray&)) );
204#endif 204#endif
205 205
206 // listen on QPE/System 206 // listen on QPE/System
207#if defined(Q_WS_QWS) 207#if defined(Q_WS_QWS)
208#if !defined(QT_NO_COP) 208#if !defined(QT_NO_COP)
209 QCopChannel *channel = new QCopChannel( "QPE/System", this ); 209 QCopChannel *channel = new QCopChannel( "QPE/System", this );
210 connect( channel, SIGNAL(received(const QCString&, const QByteArray&)), 210 connect( channel, SIGNAL(received(const QCString&, const QByteArray&)),
211 this, SLOT(receive(const QCString&, const QByteArray&)) ); 211 this, SLOT(receive(const QCString&, const QByteArray&)) );
212 channel = new QCopChannel( "QPE/Datebook", this ); 212 channel = new QCopChannel( "QPE/Datebook", this );
213 connect( channel, SIGNAL(received(const QCString&, const QByteArray&)), 213 connect( channel, SIGNAL(received(const QCString&, const QByteArray&)),
214 this, SLOT(receive(const QCString&, const QByteArray&)) ); 214 this, SLOT(receive(const QCString&, const QByteArray&)) );
215 qDebug("olle\n"); 215 qDebug("olle\n");
216#endif 216#endif
217#endif 217#endif
218 218
219 qDebug("done t=%d", t.elapsed() ); 219 qDebug("done t=%d", t.elapsed() );
220 220
221} 221}
222 222
223void DateBook::receive( const QCString &msg, const QByteArray &data ) 223void DateBook::receive( const QCString &msg, const QByteArray &data )
224{ 224{
225 QDataStream stream( data, IO_ReadOnly ); 225 QDataStream stream( data, IO_ReadOnly );
226 if ( msg == "timeChange(QString)" ) { 226 if ( msg == "timeChange(QString)" ) {
227 // update active view! 227 // update active view!
228 if ( dayAction->isOn() ) 228 if ( dayAction->isOn() )
229 viewDay(); 229 viewDay();
230 else if ( weekAction->isOn() ) 230 else if ( weekAction->isOn() )
231 viewWeek(); 231 viewWeek();
232 else if ( monthAction->isOn() ) 232 else if ( monthAction->isOn() )
233 viewMonth(); 233 viewMonth();
234 } 234 }
235 else if (msg == "editEvent(int)") { 235 else if (msg == "editEvent(int)") {
236 int uid; 236 int uid;
237 stream >> uid; 237 stream >> uid;
238 Event e=db->eventByUID(uid); 238 Event e=db->eventByUID(uid);
239 editEvent(e); 239 editEvent(e);
240 } 240 }
241} 241}
242 242
243DateBook::~DateBook() 243DateBook::~DateBook()
244{ 244{
245} 245}
246 246
247void DateBook::slotSettings() 247void DateBook::slotSettings()
248{ 248{
249 DateBookSettings frmSettings( ampm, this ); 249 DateBookSettings frmSettings( ampm, this );
250 frmSettings.setStartTime( startTime ); 250 frmSettings.setStartTime( startTime );
251 frmSettings.setAlarmPreset( aPreset, presetTime ); 251 frmSettings.setAlarmPreset( aPreset, presetTime );
252#if defined (Q_WS_QWS) || defined(_WS_QWS_) 252#if defined (Q_WS_QWS) || defined(_WS_QWS_)
253 frmSettings.showMaximized(); 253 frmSettings.showMaximized();
254#endif 254#endif
255 255
256 if ( frmSettings.exec() ) { 256 if ( frmSettings.exec() ) {
257 aPreset = frmSettings.alarmPreset(); 257 aPreset = frmSettings.alarmPreset();
258 presetTime = frmSettings.presetTime(); 258 presetTime = frmSettings.presetTime();
259 startTime = frmSettings.startTime(); 259 startTime = frmSettings.startTime();
260 if ( dayView ) 260 if ( dayView )
261 dayView->setStartViewTime( startTime ); 261 dayView->setStartViewTime( startTime );
262 if ( weekView ) 262 if ( weekView )
263 weekView->setStartViewTime( startTime ); 263 weekView->setStartViewTime( startTime );
264 saveSettings(); 264 saveSettings();
265 265
266 // make the change obvious 266 // make the change obvious
267 if ( views->visibleWidget() ) { 267 if ( views->visibleWidget() ) {
268 if ( views->visibleWidget() == dayView ) 268 if ( views->visibleWidget() == dayView )
269 dayView->redraw(); 269 dayView->redraw();
270 else if ( views->visibleWidget() == weekView ) 270 else if ( views->visibleWidget() == weekView )
271 weekView->redraw(); 271 weekView->redraw();
272 } 272 }
273 } 273 }
274} 274}
275 275
276void DateBook::fileNew() 276void DateBook::fileNew()
277{ 277{
278 slotNewEventFromKey(""); 278 slotNewEventFromKey("");
279} 279}
280 280
281QString DateBook::checkEvent(const Event &e) 281QString DateBook::checkEvent(const Event &e)
282{ 282{
283 /* check if overlaps with itself */ 283 /* check if overlaps with itself */
284 bool checkFailed = FALSE; 284 bool checkFailed = FALSE;
285 285
286 /* check the next 12 repeats. should catch most problems */ 286 /* check the next 12 repeats. should catch most problems */
287 QDate current_date = e.start().date(); 287 QDate current_date = e.start().date();
288 Event previous = e; 288 Event previous = e;
289 for(int i = 0; i < 12; i++) 289 for(int i = 0; i < 12; i++)
290 { 290 {
291 QDateTime next; 291 QDateTime next;
292 if (!nextOccurance(previous, current_date.addDays(1), next)) { 292 if (!nextOccurance(previous, current_date.addDays(1), next)) {
293 break; // no more repeats 293 break; // no more repeats
294 } 294 }
295 if(next < previous.end()) { 295 if(next < previous.end()) {
296 checkFailed = TRUE; 296 checkFailed = TRUE;
297 break; 297 break;
298 } 298 }
299 current_date = next.date(); 299 current_date = next.date();
300 } 300 }
301 301
302 if(checkFailed) 302 if(checkFailed)
303 return tr("Event duration is potentially longer\n" 303 return tr("Event duration is potentially longer\n"
304 "than interval between repeats."); 304 "than interval between repeats.");
305 305
306 return QString::null; 306 return QString::null;
307} 307}
308 308
309QDate DateBook::currentDate() 309QDate DateBook::currentDate()
310{ 310{
311 QDate d = QDate::currentDate(); 311 QDate d = QDate::currentDate();
312 312
313 if ( dayView && views->visibleWidget() == dayView ) { 313 if ( dayView && views->visibleWidget() == dayView ) {
314 d = dayView->date(); 314 d = dayView->date();
315 } else if ( weekView && views->visibleWidget() == weekView ) { 315 } else if ( weekView && views->visibleWidget() == weekView ) {
316 d = weekView->date(); 316 d = weekView->date();
317 } else if ( weekLstView && views->visibleWidget() == weekLstView ) { 317 } else if ( weekLstView && views->visibleWidget() == weekLstView ) {
318 d = weekLstView->date(); 318 d = weekLstView->date();
319 } else if ( monthView && views->visibleWidget() == monthView ) { 319 } else if ( monthView && views->visibleWidget() == monthView ) {
320 d = monthView->selectedDate(); 320 d = monthView->selectedDate();
321 } 321 }
322 322
323 return d; 323 return d;
324} 324}
325 325
326void DateBook::view(int v, const QDate &d) { 326void DateBook::view(int v, const QDate &d) {
327 if (v==DAY) { 327 if (v==DAY) {
328 initDay(); 328 initDay();
329 dayAction->setOn( TRUE ); 329 dayAction->setOn( TRUE );
330 dayView->setDate( d ); 330 dayView->setDate( d );
331 views->raiseWidget( dayView ); 331 views->raiseWidget( dayView );
332 dayView->redraw(); 332 dayView->redraw();
333 } else if (v==WEEK) { 333 } else if (v==WEEK) {
334 initWeek(); 334 initWeek();
335 weekAction->setOn( TRUE ); 335 weekAction->setOn( TRUE );
336 weekView->setDate( d ); 336 weekView->setDate( d );
337 views->raiseWidget( weekView ); 337 views->raiseWidget( weekView );
338 weekView->redraw(); 338 weekView->redraw();
339 } else if (v==WEEKLST) { 339 } else if (v==WEEKLST) {
340 initWeekLst(); 340 initWeekLst();
341 weekLstAction->setOn( TRUE ); 341 weekLstAction->setOn( TRUE );
342 weekLstView->setDate(d); 342 weekLstView->setDate(d);
343 views->raiseWidget( weekLstView ); 343 views->raiseWidget( weekLstView );
344 weekLstView->redraw(); 344 weekLstView->redraw();
345 } else if (v==MONTH) { 345 } else if (v==MONTH) {
346 initMonth(); 346 initMonth();
347 monthAction->setOn( TRUE ); 347 monthAction->setOn( TRUE );
348 monthView->setDate( d.year(), d.month(), d.day() ); 348 monthView->setDate( d.year(), d.month(), d.day() );
349 views->raiseWidget( monthView ); 349 views->raiseWidget( monthView );
350 monthView->redraw(); 350 monthView->redraw();
351 } 351 }
352} 352}
353 353
354void DateBook::viewDefault(const QDate &d) { 354void DateBook::viewDefault(const QDate &d) {
355 Config config("DateBook"); 355 Config config("DateBook");
356 config.setGroup("Main"); 356 config.setGroup("Main");
357 int current=config.readNumEntry("defaultview", DAY); 357 int current=config.readNumEntry("defaultview", DAY);
358 358
359 view(current,d); 359 view(current,d);
360} 360}
361 361
362void DateBook::viewDay() { 362void DateBook::viewDay() {
363 view(DAY,currentDate()); 363 view(DAY,currentDate());
364} 364}
365 365
366void DateBook::viewWeek() { 366void DateBook::viewWeek() {
367 view(WEEK,currentDate()); 367 view(WEEK,currentDate());
368} 368}
369 369
370void DateBook::viewWeekLst() { 370void DateBook::viewWeekLst() {
371 view(WEEKLST,currentDate()); 371 view(WEEKLST,currentDate());
372} 372}
373 373
374void DateBook::viewMonth() { 374void DateBook::viewMonth() {
375 view(MONTH,currentDate()); 375 view(MONTH,currentDate());
376} 376}
377 377
378void DateBook::editEvent( const Event &e ) 378void DateBook::editEvent( const Event &e )
379{ 379{
380 if (syncing) { 380 if (syncing) {
381 QMessageBox::warning( this, tr("Calendar"), 381 QMessageBox::warning( this, tr("Calendar"),
382 tr( "Can not edit data, currently syncing") ); 382 tr( "Can not edit data, currently syncing") );
383 return; 383 return;
384 } 384 }
385 385
386 // workaround added for text input. 386 // workaround added for text input.
387 QDialog editDlg( this, 0, TRUE ); 387 QDialog editDlg( this, 0, TRUE );
388 DateEntry *entry; 388 DateEntry *entry;
389 editDlg.setCaption( tr("Edit Event") ); 389 editDlg.setCaption( tr("Edit Event") );
390 QVBoxLayout *vb = new QVBoxLayout( &editDlg ); 390 QVBoxLayout *vb = new QVBoxLayout( &editDlg );
391 QScrollView *sv = new QScrollView( &editDlg, "scrollview" ); 391 QScrollView *sv = new QScrollView( &editDlg, "scrollview" );
392 sv->setResizePolicy( QScrollView::AutoOneFit ); 392 sv->setResizePolicy( QScrollView::AutoOneFit );
393 // KLUDGE!!! 393 // KLUDGE!!!
394 sv->setHScrollBarMode( QScrollView::AlwaysOff ); 394 sv->setHScrollBarMode( QScrollView::AlwaysOff );
395 vb->addWidget( sv ); 395 vb->addWidget( sv );
396 entry = new DateEntry( onMonday, e, ampm, &editDlg, "editor" ); 396 entry = new DateEntry( onMonday, e, ampm, &editDlg, "editor" );
397 entry->timezone->setEnabled( FALSE ); 397 entry->timezone->setEnabled( FALSE );
398 sv->addChild( entry ); 398 sv->addChild( entry );
399 399
400#if defined(Q_WS_QWS) || defined(_WS_QWS_) 400#if defined(Q_WS_QWS) || defined(_WS_QWS_)
401 editDlg.showMaximized(); 401 editDlg.showMaximized();
402#endif 402#endif
403 while (editDlg.exec() ) { 403 while (editDlg.exec() ) {
404 Event newEv = entry->event(); 404 Event newEv = entry->event();
405 newEv.setUid(e.uid()); // FIXME: Hack not to clear uid 405 newEv.setUid(e.uid()); // FIXME: Hack not to clear uid
406 QString error = checkEvent(newEv); 406 QString error = checkEvent(newEv);
407 if (!error.isNull()) { 407 if (!error.isNull()) {
408 if (QMessageBox::warning(this, "error box", 408 if (QMessageBox::warning(this, "error box",
409 error, "Fix it", "Continue", 409 error, "Fix it", "Continue",
410 0, 0, 1) == 0) 410 0, 0, 1) == 0)
411 continue; 411 continue;
412 } 412 }
413 db->editEvent(e, newEv); 413 db->editEvent(e, newEv);
414 emit newEvent(); 414 emit newEvent();
415 break; 415 break;
416 } 416 }
417} 417}
418 418
419void DateBook::removeEvent( const Event &e ) 419void DateBook::removeEvent( const Event &e )
420{ 420{
421 if (syncing) { 421 if (syncing) {
422 QMessageBox::warning( this, tr("Calendar"), 422 QMessageBox::warning( this, tr("Calendar"),
423 tr( "Can not edit data, currently syncing") ); 423 tr( "Can not edit data, currently syncing") );
424 return; 424 return;
425 } 425 }
426 426
427 QString strName = e.description(); 427 QString strName = e.description();
428 428
429 if ( !QPEMessageBox::confirmDelete( this, tr( "Calendar" ),strName ) ) 429 if ( !QPEMessageBox::confirmDelete( this, tr( "Calendar" ),strName ) )
430 return; 430 return;
431 431
432 db->removeEvent( e ); 432 db->removeEvent( e );
433 if ( views->visibleWidget() == dayView && dayView ) 433 if ( views->visibleWidget() == dayView && dayView )
434 dayView->redraw(); 434 dayView->redraw();
435} 435}
436 436
437void DateBook::addEvent( const Event &e ) 437void DateBook::addEvent( const Event &e )
438{ 438{
439 QDate d = e.start().date(); 439 QDate d = e.start().date();
440 initDay(); 440 initDay();
441 dayView->setDate( d ); 441 dayView->setDate( d );
442} 442}
443 443
444void DateBook::showDay( int year, int month, int day ) 444void DateBook::showDay( int year, int month, int day )
445{ 445{
446 QDate d(year, month, day); 446 QDate d(year, month, day);
447 view(DAY,d); 447 view(DAY,d);
448} 448}
449 449
450void DateBook::initDay() 450void DateBook::initDay()
451{ 451{
452 if ( !dayView ) { 452 if ( !dayView ) {
453 dayView = new DateBookDay( ampm, onMonday, db, views, "day view" ); 453 dayView = new DateBookDay( ampm, onMonday, db, views, "day view" );
454 views->addWidget( dayView, DAY ); 454 views->addWidget( dayView, DAY );
455 dayView->setStartViewTime( startTime ); 455 dayView->setStartViewTime( startTime );
456 connect( this, SIGNAL( newEvent() ), 456 connect( this, SIGNAL( newEvent() ),
457 dayView, SLOT( redraw() ) ); 457 dayView, SLOT( redraw() ) );
458 connect( dayView, SIGNAL( newEvent() ), 458 connect( dayView, SIGNAL( newEvent() ),
459 this, SLOT( fileNew() ) ); 459 this, SLOT( fileNew() ) );
460 connect( dayView, SIGNAL( removeEvent( const Event & ) ), 460 connect( dayView, SIGNAL( removeEvent( const Event & ) ),
461 this, SLOT( removeEvent( const Event & ) ) ); 461 this, SLOT( removeEvent( const Event & ) ) );
462 connect( dayView, SIGNAL( editEvent( const Event & ) ), 462 connect( dayView, SIGNAL( editEvent( const Event & ) ),
463 this, SLOT( editEvent( const Event & ) ) ); 463 this, SLOT( editEvent( const Event & ) ) );
464 connect( dayView, SIGNAL( beamEvent( const Event & ) ), 464 connect( dayView, SIGNAL( beamEvent( const Event & ) ),
465 this, SLOT( beamEvent( const Event & ) ) ); 465 this, SLOT( beamEvent( const Event & ) ) );
466 connect( dayView, SIGNAL(sigNewEvent(const QString &)), 466 connect( dayView, SIGNAL(sigNewEvent(const QString &)),
467 this, SLOT(slotNewEventFromKey(const QString &)) ); 467 this, SLOT(slotNewEventFromKey(const QString &)) );
468 } 468 }
469} 469}
470 470
471void DateBook::initWeek() 471void DateBook::initWeek()
472{ 472{
473 if ( !weekView ) { 473 if ( !weekView ) {
474 weekView = new DateBookWeek( ampm, onMonday, db, views, "week view" ); 474 weekView = new DateBookWeek( ampm, onMonday, db, views, "week view" );
475 weekView->setStartViewTime( startTime ); 475 weekView->setStartViewTime( startTime );
476 views->addWidget( weekView, WEEK ); 476 views->addWidget( weekView, WEEK );
477 connect( weekView, SIGNAL( showDate( int, int, int ) ), 477 connect( weekView, SIGNAL( showDate( int, int, int ) ),
478 this, SLOT( showDay( int, int, int ) ) ); 478 this, SLOT( showDay( int, int, int ) ) );
479 connect( this, SIGNAL( newEvent() ), 479 connect( this, SIGNAL( newEvent() ),
480 weekView, SLOT( redraw() ) ); 480 weekView, SLOT( redraw() ) );
481 } 481 }
482 //But also get it right: the year that we display can be different 482 //But also get it right: the year that we display can be different
483 //from the year of the current date. So, first find the year 483 //from the year of the current date. So, first find the year
484 //number of the current week. 484 //number of the current week.
485 485
486 int yearNumber, totWeeks; 486 int yearNumber, totWeeks;
487 calcWeek( currentDate(), totWeeks, yearNumber, onMonday ); 487 calcWeek( currentDate(), totWeeks, yearNumber, onMonday );
488 488
489 QDate d = QDate( yearNumber, 12, 31 ); 489 QDate d = QDate( yearNumber, 12, 31 );
490 calcWeek( d, totWeeks, yearNumber, onMonday ); 490 calcWeek( d, totWeeks, yearNumber, onMonday );
491 491
492 while ( totWeeks == 1 ) { 492 while ( totWeeks == 1 ) {
493 d = d.addDays( -1 ); 493 d = d.addDays( -1 );
494 calcWeek( d, totWeeks, yearNumber, onMonday ); 494 calcWeek( d, totWeeks, yearNumber, onMonday );
495 } 495 }
496 if ( totWeeks != weekView->totalWeeks() ) 496 if ( totWeeks != weekView->totalWeeks() )
497 weekView->setTotalWeeks( totWeeks ); 497 weekView->setTotalWeeks( totWeeks );
498} 498}
499void DateBook::initWeekLst() { 499void DateBook::initWeekLst() {
500 if ( !weekLstView ) { 500 if ( !weekLstView ) {
501 weekLstView = new DateBookWeekLst( ampm, onMonday, db, 501 weekLstView = new DateBookWeekLst( ampm, onMonday, db,
502 views, "weeklst view" ); 502 views, "weeklst view" );
503 views->addWidget( weekLstView, WEEKLST ); 503 views->addWidget( weekLstView, WEEKLST );
504 504
505 //weekLstView->setStartViewTime( startTime ); 505 //weekLstView->setStartViewTime( startTime );
506 connect( weekLstView, SIGNAL( showDate( int, int, int ) ), 506 connect( weekLstView, SIGNAL( showDate( int, int, int ) ),
507 this, SLOT( showDay( int, int, int ) ) ); 507 this, SLOT( showDay( int, int, int ) ) );
508 connect( weekLstView, SIGNAL( addEvent( const QDateTime &, 508 connect( weekLstView, SIGNAL( addEvent( const QDateTime &,
509 const QDateTime &, 509 const QDateTime &,
510 const QString & ) ), 510 const QString & ) ),
511 this, SLOT( slotNewEntry( const QDateTime &, 511 this, SLOT( slotNewEntry( const QDateTime &,
512 const QDateTime &, 512 const QDateTime &,
513 const QString & ) ) ); 513 const QString & ) ) );
514 connect( this, SIGNAL( newEvent() ), 514 connect( this, SIGNAL( newEvent() ),
515 weekLstView, SLOT( redraw() ) ); 515 weekLstView, SLOT( redraw() ) );
516 connect( weekLstView, SIGNAL( editEvent( const Event & ) ), 516 connect( weekLstView, SIGNAL( editEvent( const Event & ) ),
517 this, SLOT( editEvent( const Event & ) ) ); 517 this, SLOT( editEvent( const Event & ) ) );
518 } 518 }
519} 519}
520 520
521 521
522void DateBook::initMonth() 522void DateBook::initMonth()
523{ 523{
524 if ( !monthView ) { 524 if ( !monthView ) {
525 monthView = new DateBookMonth( views, "month view", FALSE, db ); 525 monthView = new DateBookMonth( views, "month view", FALSE, db );
526 views->addWidget( monthView, MONTH ); 526 views->addWidget( monthView, MONTH );
527 connect( monthView, SIGNAL( dateClicked( int, int, int ) ), 527 connect( monthView, SIGNAL( dateClicked( int, int, int ) ),
528 this, SLOT( showDay( int, int, int ) ) ); 528 this, SLOT( showDay( int, int, int ) ) );
529 connect( this, SIGNAL( newEvent() ), 529 connect( this, SIGNAL( newEvent() ),
530 monthView, SLOT( redraw() ) ); 530 monthView, SLOT( redraw() ) );
531 qApp->processEvents(); 531 qApp->processEvents();
532 } 532 }
533} 533}
534 534
535void DateBook::loadSettings() 535void DateBook::loadSettings()
536{ 536{
537 { 537 {
538 Config config( "qpe" ); 538 Config config( "qpe" );
539 config.setGroup("Time"); 539 config.setGroup("Time");
540 ampm = config.readBoolEntry( "AMPM", TRUE ); 540 ampm = config.readBoolEntry( "AMPM", TRUE );
541 onMonday = config.readBoolEntry( "MONDAY" ); 541 onMonday = config.readBoolEntry( "MONDAY" );
542 } 542 }
543 543
544 { 544 {
545 Config config("DateBook"); 545 Config config("DateBook");
546 config.setGroup("Main"); 546 config.setGroup("Main");
547 startTime = config.readNumEntry("startviewtime", 8); 547 startTime = config.readNumEntry("startviewtime", 8);
548 aPreset = config.readBoolEntry("alarmpreset"); 548 aPreset = config.readBoolEntry("alarmpreset");
549 presetTime = config.readNumEntry("presettime"); 549 presetTime = config.readNumEntry("presettime");
550 } 550 }
551} 551}
552 552
553void DateBook::saveSettings() 553void DateBook::saveSettings()
554{ 554{
555 Config config( "qpe" ); 555 Config config( "qpe" );
556 Config configDB( "DateBook" ); 556 Config configDB( "DateBook" );
557 configDB.setGroup( "Main" ); 557 configDB.setGroup( "Main" );
558 configDB.writeEntry("startviewtime",startTime); 558 configDB.writeEntry("startviewtime",startTime);
559 configDB.writeEntry("alarmpreset",aPreset); 559 configDB.writeEntry("alarmpreset",aPreset);
560 configDB.writeEntry("presettime",presetTime); 560 configDB.writeEntry("presettime",presetTime);
561} 561}
562 562
563void DateBook::newDefaultView(QAction *a) { 563void DateBook::newDefaultView(QAction *a) {
564 int val=DAY; 564 int val=DAY;
565 if (a->text() == "Day") val=DAY; 565 if (a->text() == "Day") val=DAY;
566 if (a->text() == "Week") val=WEEK; 566 if (a->text() == "Week") val=WEEK;
567 if (a->text() == "WeekLst") val=WEEKLST; 567 if (a->text() == "WeekLst") val=WEEKLST;
568 if (a->text() == "Month") val=MONTH; 568 if (a->text() == "Month") val=MONTH;
569 569
570 Config configDB( "DateBook" ); 570 Config configDB( "DateBook" );
571 configDB.setGroup( "Main" ); 571 configDB.setGroup( "Main" );
572 configDB.writeEntry("defaultview",val); 572 configDB.writeEntry("defaultview",val);
573} 573}
574 574
575void DateBook::appMessage(const QCString& msg, const QByteArray& data) 575void DateBook::appMessage(const QCString& msg, const QByteArray& data)
576{ 576{
577 bool needShow = FALSE; 577 bool needShow = FALSE;
578 if ( msg == "alarm(QDateTime,int)" ) { 578 if ( msg == "alarm(QDateTime,int)" ) {
579 QDataStream ds(data,IO_ReadOnly); 579 QDataStream ds(data,IO_ReadOnly);
580 QDateTime when; int warn; 580 QDateTime when; int warn;
581 ds >> when >> warn; 581 ds >> when >> warn;
582 582
583 // check to make it's okay to continue, 583 // check to make it's okay to continue,
584 // this is the case that the time was set ahead, and 584 // this is the case that the time was set ahead, and
585 // we are forced given a stale alarm... 585 // we are forced given a stale alarm...
586 QDateTime current = QDateTime::currentDateTime(); 586 QDateTime current = QDateTime::currentDateTime();
587 if ( current.time().hour() != when.time().hour() 587 if ( current.time().hour() != when.time().hour()
588 && current.time().minute() != when.time().minute() ) 588 && current.time().minute() != when.time().minute() )
589 return; 589 return;
590 590
591 QValueList<EffectiveEvent> list = db->getEffectiveEvents(when.addSecs(warn*60)); 591 QValueList<EffectiveEvent> list = db->getEffectiveEvents(when.addSecs(warn*60));
592 if ( list.count() > 0 ) { 592 if ( list.count() > 0 ) {
593 QString msg; 593 QString msg;
594 bool bSound = FALSE; 594 bool bSound = FALSE;
595 int stopTimer = 0; 595 int stopTimer = 0;
596 bool found = FALSE; 596 bool found = FALSE;
597 for ( QValueList<EffectiveEvent>::ConstIterator it=list.begin(); 597 for ( QValueList<EffectiveEvent>::ConstIterator it=list.begin();
598 it!=list.end(); ++it ) { 598 it!=list.end(); ++it ) {
599 if ( (*it).event().hasAlarm() ) { 599 if ( (*it).event().hasAlarm() ) {
600 found = TRUE; 600 found = TRUE;
601 msg += "<CENTER><B>" + (*it).description() + "</B>" 601 msg += "<CENTER><B>" + (*it).description() + "</B>"
602 + "<BR>" + (*it).location() + "<BR>" 602 + "<BR>" + (*it).location() + "<BR>"
603 + TimeString::dateString((*it).event().start(),ampm) 603 + TimeString::dateString((*it).event().start(),ampm)
604 + (warn 604 + (warn
605 ? tr(" (in " + QString::number(warn) 605 ? tr(" (in " + QString::number(warn)
606 + tr(" minutes)")) 606 + tr(" minutes)"))
607 : QString("")) 607 : QString(""))
608 + "<BR>" 608 + "<BR>"
609 + (*it).notes() + "</CENTER>"; 609 + (*it).notes() + "</CENTER>";
610 if ( (*it).event().alarmSound() != Event::Silent ) { 610 if ( (*it).event().alarmSound() != Event::Silent ) {
611 bSound = TRUE; 611 bSound = TRUE;
612 } 612 }
613 } 613 }
614 } 614 }
615 if ( found ) { 615 if ( found ) {
616 if ( bSound ) { 616 if ( bSound ) {
617 Sound::soundAlarm(); 617 Sound::soundAlarm();
618 alarmCounter = 0; 618 alarmCounter = 0;
619 stopTimer = startTimer( 5000 ); 619 stopTimer = startTimer( 5000 );
620 } 620 }
621 621
622 QDialog dlg( this, 0, TRUE ); 622 QDialog dlg( this, 0, TRUE );
623 QVBoxLayout *vb = new QVBoxLayout( &dlg ); 623 QVBoxLayout *vb = new QVBoxLayout( &dlg );
624 QScrollView *view = new QScrollView( &dlg, "scrollView"); 624 QScrollView *view = new QScrollView( &dlg, "scrollView");
625 view->setResizePolicy( QScrollView::AutoOneFit ); 625 view->setResizePolicy( QScrollView::AutoOneFit );
626 vb->addWidget( view ); 626 vb->addWidget( view );
627 QLabel *lblMsg = new QLabel( msg, &dlg ); 627 QLabel *lblMsg = new QLabel( msg, &dlg );
628 view->addChild( lblMsg ); 628 view->addChild( lblMsg );
629 QPushButton *cmdOk = new QPushButton( tr("OK"), &dlg ); 629 QPushButton *cmdOk = new QPushButton( tr("OK"), &dlg );
630 connect( cmdOk, SIGNAL(clicked()), &dlg, SLOT(accept()) ); 630 connect( cmdOk, SIGNAL(clicked()), &dlg, SLOT(accept()) );
631 vb->addWidget( cmdOk ); 631 vb->addWidget( cmdOk );
632 632
633#if defined(Q_WS_QWS) || defined(_WS_QWS_) 633#if defined(Q_WS_QWS) || defined(_WS_QWS_)
634 dlg.showMaximized(); 634 dlg.showMaximized();
635#endif 635#endif
636 needShow = dlg.exec(); 636 needShow = dlg.exec();
637 637
638 if ( bSound ) 638 if ( bSound )
639 killTimer( stopTimer ); 639 killTimer( stopTimer );
640 } 640 }
641 } 641 }
642 } else if ( msg == "nextView()" ) { 642 } else if ( msg == "nextView()" ) {
643 QWidget* cur = views->visibleWidget(); 643 QWidget* cur = views->visibleWidget();
644 if ( cur ) { 644 if ( cur ) {
645 if ( cur == dayView ) 645 if ( cur == dayView )
646 viewWeek(); 646 viewWeek();
647 else if ( cur == weekView ) 647 else if ( cur == weekView )
648 viewWeekLst(); 648 viewWeekLst();
649 else if ( cur == weekLstView ) 649 else if ( cur == weekLstView )
650 viewMonth(); 650 viewMonth();
651 else if ( cur == monthView ) 651 else if ( cur == monthView )
652 viewDay(); 652 viewDay();
653 needShow = TRUE; 653 needShow = TRUE;
654 } 654 }
655 } 655 }
656 if ( needShow ) { 656 if ( needShow ) {
657#if defined(Q_WS_QWS) || defined(_WS_QWS_) 657#if defined(Q_WS_QWS) || defined(_WS_QWS_)
658 showMaximized(); 658 showMaximized();
659#else 659#else
660 show(); 660 show();
661#endif 661#endif
662 raise(); 662 raise();
663 QPEApplication::setKeepRunning(); 663 QPEApplication::setKeepRunning();
664 setActiveWindow(); 664 setActiveWindow();
665 } 665 }
666} 666}
667 667
668void DateBook::reload() 668void DateBook::reload()
669{ 669{
670 db->reload(); 670 db->reload();
671 if ( dayAction->isOn() ) 671 if ( dayAction->isOn() )
672 viewDay(); 672 viewDay();
673 else if ( weekAction->isOn() ) 673 else if ( weekAction->isOn() )
674 viewWeek(); 674 viewWeek();
675 else if ( monthAction->isOn() ) 675 else if ( monthAction->isOn() )
676 viewMonth(); 676 viewMonth();
677 syncing = FALSE; 677 syncing = FALSE;
678} 678}
679 679
680void DateBook::flush() 680void DateBook::flush()
681{ 681{
682 syncing = TRUE; 682 syncing = TRUE;
683 db->save(); 683 db->save();
684} 684}
685 685
686void DateBook::timerEvent( QTimerEvent *e ) 686void DateBook::timerEvent( QTimerEvent *e )
687{ 687{
688 if ( alarmCounter < 10 ) { 688 if ( alarmCounter < 10 ) {
689 alarmCounter++; 689 alarmCounter++;
690 Sound::soundAlarm(); 690 Sound::soundAlarm();
691 } 691 }
692 else 692 else
693 killTimer( e->timerId() ); 693 killTimer( e->timerId() );
694} 694}
695 695
696void DateBook::changeClock( bool newClock ) 696void DateBook::changeClock( bool newClock )
697{ 697{
698 ampm = newClock; 698 ampm = newClock;
699 // repaint the affected objects... 699 // repaint the affected objects...
700 if (dayView) dayView->redraw(); 700 if (dayView) dayView->redraw();
701 if (weekView) weekView->redraw(); 701 if (weekView) weekView->redraw();
702 if (weekLstView) weekLstView->redraw(); 702 if (weekLstView) weekLstView->redraw();
703} 703}
704 704
705void DateBook::changeWeek( bool m ) 705void DateBook::changeWeek( bool m )
706{ 706{
707 /* no need to redraw, each widget catches. Do need to 707 /* no need to redraw, each widget catches. Do need to
708 store though for widgets we haven't made yet */ 708 store though for widgets we haven't made yet */
709 onMonday = m; 709 onMonday = m;
710} 710}
711 711
712void DateBook::slotToday() 712void DateBook::slotToday()
713{ 713{
714 // we need to view today using default view 714 // we need to view today using default view
715 viewDefault(QDate::currentDate()); 715 viewDefault(QDate::currentDate());
716} 716}
717 717
718void DateBook::closeEvent( QCloseEvent *e ) 718void DateBook::closeEvent( QCloseEvent *e )
719{ 719{
720 if(syncing) { 720 if(syncing) {
721 /* no need to save, did that at flush */ 721 /* no need to save, did that at flush */
722 e->accept(); 722 e->accept();
723 return; 723 return;
724 } 724 }
725 725
726 // save settings will generate it's own error messages, no 726 // save settings will generate it's own error messages, no
727 // need to do checking ourselves. 727 // need to do checking ourselves.
728 saveSettings(); 728 saveSettings();
729 if ( db->save() ) 729 if ( db->save() )
730 e->accept(); 730 e->accept();
731 else { 731 else {
732 if ( QMessageBox::critical( this, tr( "Out of space" ), 732 if ( QMessageBox::critical( this, tr( "Out of space" ),
733 tr("Calendar was unable to save\n" 733 tr("Calendar was unable to save\n"
734 "your changes.\n" 734 "your changes.\n"
735 "Free up some space and try again.\n" 735 "Free up some space and try again.\n"
736 "\nQuit anyway?"), 736 "\nQuit anyway?"),
737 QMessageBox::Yes|QMessageBox::Escape, 737 QMessageBox::Yes|QMessageBox::Escape,
738 QMessageBox::No|QMessageBox::Default ) 738 QMessageBox::No|QMessageBox::Default )
739 != QMessageBox::No ) 739 != QMessageBox::No )
740 e->accept(); 740 e->accept();
741 else 741 else
742 e->ignore(); 742 e->ignore();
743 } 743 }
744} 744}
745 745
746// Entering directly from the "keyboard" 746// Entering directly from the "keyboard"
747void DateBook::slotNewEventFromKey( const QString &str ) 747void DateBook::slotNewEventFromKey( const QString &str )
748{ 748{
749 if (syncing) { 749 if (syncing) {
750 QMessageBox::warning( this, tr("Calendar"), 750 QMessageBox::warning( this, tr("Calendar"),
751 tr( "Can not edit data, currently syncing") ); 751 tr( "Can not edit data, currently syncing") );
752 return; 752 return;
753 } 753 }
754 754
755 // We get to here from a key pressed in the Day View 755 // We get to here from a key pressed in the Day View
756 // So we can assume some things. We want the string 756 // So we can assume some things. We want the string
757 // passed in to be part of the description. 757 // passed in to be part of the description.
758 QDateTime start, end; 758 QDateTime start, end;
759 if ( views->visibleWidget() == dayView ) { 759 if ( views->visibleWidget() == dayView ) {
760 dayView->selectedDates( start, end ); 760 dayView->selectedDates( start, end );
761 } else if ( views->visibleWidget() == monthView ) { 761 } else if ( views->visibleWidget() == monthView ) {
762 QDate d = monthView->selectedDate(); 762 QDate d = monthView->selectedDate();
763 start = end = d; 763 start = end = d;
764 start.setTime( QTime( 10, 0 ) ); 764 start.setTime( QTime( 10, 0 ) );
765 end.setTime( QTime( 12, 0 ) ); 765 end.setTime( QTime( 12, 0 ) );
766 } else if ( views->visibleWidget() == weekView ) { 766 } else if ( views->visibleWidget() == weekView ) {
767 QDate d = weekView->date(); 767 QDate d = weekView->date();
768 start = end = d; 768 start = end = d;
769 start.setTime( QTime( 10, 0 ) ); 769 start.setTime( QTime( 10, 0 ) );
770 end.setTime( QTime( 12, 0 ) ); 770 end.setTime( QTime( 12, 0 ) );
771 } 771 }
772 slotNewEntry(start, end, str); 772 slotNewEntry(start, end, str);
773} 773}
774void DateBook::slotNewEntry(const QDateTime &start, const QDateTime &end, const QString &str) { 774void DateBook::slotNewEntry(const QDateTime &start, const QDateTime &end, const QString &str) {
775 // argh! This really needs to be encapsulated in a class 775 // argh! This really needs to be encapsulated in a class
776 // or function. 776 // or function.
777 QDialog newDlg( this, 0, TRUE ); 777 QDialog newDlg( this, 0, TRUE );
778 newDlg.setCaption( DateEntryBase::tr("New Event") ); 778 newDlg.setCaption( DateEntryBase::tr("New Event") );
779 DateEntry *e; 779 DateEntry *e;
780 QVBoxLayout *vb = new QVBoxLayout( &newDlg ); 780 QVBoxLayout *vb = new QVBoxLayout( &newDlg );
781 QScrollView *sv = new QScrollView( &newDlg ); 781 QScrollView *sv = new QScrollView( &newDlg );
782 sv->setResizePolicy( QScrollView::AutoOneFit ); 782 sv->setResizePolicy( QScrollView::AutoOneFit );
783 sv->setFrameStyle( QFrame::NoFrame ); 783 sv->setFrameStyle( QFrame::NoFrame );
784 sv->setHScrollBarMode( QScrollView::AlwaysOff ); 784 sv->setHScrollBarMode( QScrollView::AlwaysOff );
785 vb->addWidget( sv ); 785 vb->addWidget( sv );
786 786
787 Event ev; 787 Event ev;
788 ev.setDescription( str ); 788 ev.setDescription( str );
789 // When the new gui comes in, change this... 789 // When the new gui comes in, change this...
790 ev.setLocation( tr("(Unknown)") ); 790 ev.setLocation( tr("(Unknown)") );
791 ev.setStart( start ); 791 ev.setStart( start );
792 ev.setEnd( end ); 792 ev.setEnd( end );
793 793
794 e = new DateEntry( onMonday, ev, ampm, &newDlg ); 794 e = new DateEntry( onMonday, ev, ampm, &newDlg );
795 e->setAlarmEnabled( aPreset, presetTime, Event::Loud ); 795 e->setAlarmEnabled( aPreset, presetTime, Event::Loud );
796 sv->addChild( e ); 796 sv->addChild( e );
797#if defined(Q_WS_QWS) || defined(_WS_QWS_) 797#if defined(Q_WS_QWS) || defined(_WS_QWS_)
798 newDlg.showMaximized(); 798 newDlg.showMaximized();
799#endif 799#endif
800 while (newDlg.exec()) { 800 while (newDlg.exec()) {
801 ev = e->event(); 801 ev = e->event();
802 ev.assignUid(); 802 ev.assignUid();
803 QString error = checkEvent( ev ); 803 QString error = checkEvent( ev );
804 if ( !error.isNull() ) { 804 if ( !error.isNull() ) {
805 if ( QMessageBox::warning( this, tr("Error!"), 805 if ( QMessageBox::warning( this, tr("Error!"),
806 error, tr("Fix it"), tr("Continue"), 0, 0, 1 ) == 0 ) 806 error, tr("Fix it"), tr("Continue"), 0, 0, 1 ) == 0 )
807 continue; 807 continue;
808 } 808 }
809 db->addEvent( ev ); 809 db->addEvent( ev );
810 emit newEvent(); 810 emit newEvent();
811 break; 811 break;
812 } 812 }
813} 813}
814 814
815void DateBook::setDocument( const QString &filename ) 815void DateBook::setDocument( const QString &filename )
816{ 816{
817 if ( filename.find(".vcs") != int(filename.length()) - 4 ) return; 817 if ( filename.find(".vcs") != int(filename.length()) - 4 ) return;
818 818
819 QValueList<Event> tl = Event::readVCalendar( filename ); 819 QValueList<Event> tl = Event::readVCalendar( filename );
820 for( QValueList<Event>::Iterator it = tl.begin(); it != tl.end(); ++it ) { 820 for( QValueList<Event>::Iterator it = tl.begin(); it != tl.end(); ++it ) {
821 db->addEvent( *it ); 821 db->addEvent( *it );
822 } 822 }
823} 823}
824 824
825static const char * beamfile = "/tmp/obex/event.vcs"; 825static const char * beamfile = "/tmp/obex/event.vcs";
826 826
827void DateBook::beamEvent( const Event &e ) 827void DateBook::beamEvent( const Event &e )
828{ 828{
829 qDebug("trying to beamn"); 829 qDebug("trying to beamn");
830 unlink( beamfile ); // delete if exists 830 unlink( beamfile ); // delete if exists
831 mkdir("/tmp/obex/", 0755); 831 mkdir("/tmp/obex/", 0755);
832 Event::writeVCalendar( beamfile, e ); 832 Event::writeVCalendar( beamfile, e );
833 Ir *ir = new Ir( this ); 833 Ir *ir = new Ir( this );
834 connect( ir, SIGNAL( done( Ir * ) ), this, SLOT( beamDone( Ir * ) ) ); 834 connect( ir, SIGNAL( done( Ir * ) ), this, SLOT( beamDone( Ir * ) ) );
835 QString description = e.description(); 835 QString description = e.description();
836 ir->send( beamfile, description, "text/x-vCalendar" ); 836 ir->send( beamfile, description, "text/x-vCalendar" );
837} 837}
838 838
839void DateBook::beamDone( Ir *ir ) 839void DateBook::beamDone( Ir *ir )
840{ 840{
841 delete ir; 841 delete ir;
842 unlink( beamfile ); 842 unlink( beamfile );
843} 843}
844 844
845void DateBook::slotFind() 845void DateBook::slotFind()
846{ 846{
847 // move it to the day view... 847 // move it to the day view...
848 viewDay(); 848 viewDay();
849 FindDialog frmFind( "Calendar", this ); 849 FindDialog frmFind( "Calendar", this );
850 frmFind.setUseDate( true ); 850 frmFind.setUseDate( true );
851 frmFind.setDate( currentDate() ); 851 frmFind.setDate( currentDate() );
852 QObject::connect( &frmFind, 852 QObject::connect( &frmFind,
853 SIGNAL(signalFindClicked(const QString&, const QDate&, 853 SIGNAL(signalFindClicked(const QString&, const QDate&,
854 bool, bool, int)), 854 bool, bool, int)),
855 this, 855 this,
856 SLOT(slotDoFind(const QString&, const QDate&, 856 SLOT(slotDoFind(const QString&, const QDate&,
857 bool, bool, int)) ); 857 bool, bool, int)) );
858 QObject::connect( this, 858 QObject::connect( this,
859 SIGNAL(signalNotFound()), 859 SIGNAL(signalNotFound()),
860 &frmFind, 860 &frmFind,
861 SLOT(slotNotFound()) ); 861 SLOT(slotNotFound()) );
862 QObject::connect( this, 862 QObject::connect( this,
863 SIGNAL(signalWrapAround()), 863 SIGNAL(signalWrapAround()),
864 &frmFind, 864 &frmFind,
865 SLOT(slotWrapAround()) ); 865 SLOT(slotWrapAround()) );
866 frmFind.exec(); 866 frmFind.exec();
867 inSearch = false; 867 inSearch = false;
868} 868}
869 869
870bool catComp( QArray<int> cats, int category ) 870bool catComp( QArray<int> cats, int category )
871{ 871{
872 bool returnMe; 872 bool returnMe;
873 int i, 873 int i,
874 count; 874 count;
875 875
876 count = int(cats.count()); 876 count = int(cats.count());
877 returnMe = false; 877 returnMe = false;
878 if ( (category == -1 && count == 0) || category == -2 ) 878 if ( (category == -1 && count == 0) || category == -2 )
879 returnMe = true; 879 returnMe = true;
880 else { 880 else {
881 for ( i = 0; i < count; i++ ) { 881 for ( i = 0; i < count; i++ ) {
882 if ( category == cats[i] ) { 882 if ( category == cats[i] ) {
883 returnMe = true; 883 returnMe = true;
884 break; 884 break;
885 } 885 }
886 } 886 }
887 } 887 }
888 return returnMe; 888 return returnMe;
889} 889}
890 890
891 891
892void DateBook::slotDoFind( const QString& txt, const QDate &dt, 892void DateBook::slotDoFind( const QString& txt, const QDate &dt,
893 bool caseSensitive, bool /*backwards*/, 893 bool caseSensitive, bool /*backwards*/,
894 int category ) 894 int category )
895{ 895{
896 QDateTime dtEnd( QDate(3001, 1, 1), QTime(0, 0, 0) ), 896 QDateTime dtEnd( QDate(3001, 1, 1), QTime(0, 0, 0) ),
897 next; 897 next;
898 898
899 QRegExp r( txt ); 899 QRegExp r( txt );
900 r.setCaseSensitive( caseSensitive ); 900 r.setCaseSensitive( caseSensitive );
901 901
902 902
903 static Event rev, 903 static Event rev,
904 nonrev; 904 nonrev;
905 if ( !inSearch ) { 905 if ( !inSearch ) {
906 rev.setStart( QDateTime(QDate(1960, 1, 1), QTime(0, 0, 0)) ); 906 rev.setStart( QDateTime(QDate(1960, 1, 1), QTime(0, 0, 0)) );
907 nonrev.setStart( rev.start() ); 907 nonrev.setStart( rev.start() );
908 inSearch = true; 908 inSearch = true;
909 } 909 }
910 static QDate searchDate = dt; 910 static QDate searchDate = dt;
911 static bool wrapAround = true; 911 static bool wrapAround = true;
912 bool candidtate; 912 bool candidtate;
913 candidtate = false; 913 candidtate = false;
914 914
915 QValueList<Event> repeats = db->getRawRepeats(); 915 QValueList<Event> repeats = db->getRawRepeats();
916 916
917 // find the candidate for the first repeat that matches... 917 // find the candidate for the first repeat that matches...
918 QValueListConstIterator<Event> it; 918 QValueListConstIterator<Event> it;
919 QDate start = dt; 919 QDate start = dt;
920 for ( it = repeats.begin(); it != repeats.end(); ++it ) { 920 for ( it = repeats.begin(); it != repeats.end(); ++it ) {
921 if ( catComp( (*it).categories(), category ) ) { 921 if ( catComp( (*it).categories(), category ) ) {
922 while ( nextOccurance( *it, start, next ) ) { 922 while ( nextOccurance( *it, start, next ) ) {
923 if ( next < dtEnd ) { 923 if ( next < dtEnd ) {
924 if ( (*it).match( r ) && !(next <= rev.start()) ) { 924 if ( (*it).match( r ) && !(next <= rev.start()) ) {
925 rev = *it; 925 rev = *it;
926 dtEnd = next; 926 dtEnd = next;
927 rev.setStart( next ); 927 rev.setStart( next );
928 candidtate = true; 928 candidtate = true;
929 wrapAround = true; 929 wrapAround = true;
930 start = dt; 930 start = dt;
931 break; 931 break;
932 } else 932 } else
933 start = next.date().addDays( 1 ); 933 start = next.date().addDays( 1 );
934 } 934 }
935 } 935 }
936 } 936 }
937 } 937 }
938 938
939 // now the for first non repeat... 939 // now the for first non repeat...
940 QValueList<Event> nonRepeats = db->getNonRepeatingEvents( dt, dtEnd.date() ); 940 QValueList<Event> nonRepeats = db->getNonRepeatingEvents( dt, dtEnd.date() );
941 qHeapSort( nonRepeats.begin(), nonRepeats.end() ); 941 qHeapSort( nonRepeats.begin(), nonRepeats.end() );
942 for ( it = nonRepeats.begin(); it != nonRepeats.end(); ++it ) { 942 for ( it = nonRepeats.begin(); it != nonRepeats.end(); ++it ) {
943 if ( catComp( (*it).categories(), category ) ) { 943 if ( catComp( (*it).categories(), category ) ) {
944 if ( (*it).start() < dtEnd ) { 944 if ( (*it).start() < dtEnd ) {
945 if ( (*it).match( r ) && !(*it <= nonrev) ) { 945 if ( (*it).match( r ) && !(*it <= nonrev) ) {
946 nonrev = *it; 946 nonrev = *it;
947 dtEnd = nonrev.start(); 947 dtEnd = nonrev.start();
948 candidtate = true; 948 candidtate = true;
949 wrapAround = true; 949 wrapAround = true;
950 break; 950 break;
951 } 951 }
952 } 952 }
953 } 953 }
954 } 954 }
955 if ( candidtate ) { 955 if ( candidtate ) {
956 dayView->setStartViewTime( dtEnd.time().hour() ); 956 dayView->setStartViewTime( dtEnd.time().hour() );
957 dayView->setDate( dtEnd.date().year(), dtEnd.date().month(), 957 dayView->setDate( dtEnd.date().year(), dtEnd.date().month(),
958 dtEnd.date().day() ); 958 dtEnd.date().day() );
959 } else { 959 } else {
960 if ( wrapAround ) { 960 if ( wrapAround ) {
961 emit signalWrapAround(); 961 emit signalWrapAround();
962 rev.setStart( QDateTime(QDate(1960, 1, 1), QTime(0, 0, 0)) ); 962 rev.setStart( QDateTime(QDate(1960, 1, 1), QTime(0, 0, 0)) );
963 nonrev.setStart( rev.start() ); 963 nonrev.setStart( rev.start() );
964 } else 964 } else
965 emit signalNotFound(); 965 emit signalNotFound();
966 wrapAround = !wrapAround; 966 wrapAround = !wrapAround;
967 } 967 }
968} 968}
969 969
970Event DateBookDBHack::eventByUID(int uid) { 970Event DateBookDBHack::eventByUID(int uid) {
971 971
972 // FIXME: Dirty Hacks to get hold of the private event lists 972 // FIXME: Dirty Hacks to get hold of the private event lists
973 QDate start; 973 QDate start;
974 QDate end=start.addDays(-1); 974 QDate end=start.addDays(-1);
975 QValueList<Event> myEventList=getNonRepeatingEvents(start,end); 975 QValueList<Event> myEventList=getNonRepeatingEvents(start,end);
976 QValueList<Event> myRepeatEvents=getRawRepeats(); 976 QValueList<Event> myRepeatEvents=getRawRepeats();
977 977
978 QValueList<Event>::ConstIterator it; 978 QValueList<Event>::ConstIterator it;
979 979
980 for (it = myEventList.begin(); it != myEventList.end(); it++) { 980 for (it = myEventList.begin(); it != myEventList.end(); it++) {
981 if ((*it).uid() == uid) return *it; 981 if ((*it).uid() == uid) return *it;
982 } 982 }
983 for (it = myRepeatEvents.begin(); it != myRepeatEvents.end(); it++) { 983 for (it = myRepeatEvents.begin(); it != myRepeatEvents.end(); it++) {
984 if ((*it).uid() == uid) return *it; 984 if ((*it).uid() == uid) return *it;
985 } 985 }
986 986
987 qDebug("Event not found: uid=%d\n", uid); 987 qDebug("Event not found: uid=%d\n", uid);
988 Event ev;
989 return ev; // return at least
988} 990}
989 991
diff --git a/core/pim/datebook/datebookday.cpp b/core/pim/datebook/datebookday.cpp
index 67a88e9..c15ccef 100644
--- a/core/pim/datebook/datebookday.cpp
+++ b/core/pim/datebook/datebookday.cpp
@@ -1,553 +1,739 @@
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#include <qmessagebox.h>
20 21
21#include "datebookday.h" 22#include "datebookday.h"
22#include "datebookdayheaderimpl.h" 23#include "datebookdayheaderimpl.h"
23 24
24#include <qpe/datebookdb.h> 25#include <qpe/datebookdb.h>
25#include <qpe/resource.h> 26#include <qpe/resource.h>
26#include <qpe/event.h> 27#include <qpe/event.h>
27#include <qpe/qpeapplication.h> 28#include <qpe/qpeapplication.h>
28#include <qpe/timestring.h> 29#include <qpe/timestring.h>
29#include <qpe/qpedebug.h> 30#include <qpe/qpedebug.h>
30 31
31#include <qheader.h> 32#include <qheader.h>
32#include <qdatetime.h> 33#include <qdatetime.h>
33#include <qpainter.h> 34#include <qpainter.h>
34#include <qsimplerichtext.h> 35#include <qsimplerichtext.h>
35#include <qpopupmenu.h> 36#include <qpopupmenu.h>
36#include <qtextcodec.h> 37#include <qtextcodec.h>
37#include <qpalette.h> 38#include <qpalette.h>
38 39
40#include <qtimer.h>
41
39DateBookDayView::DateBookDayView( bool whichClock, QWidget *parent, 42DateBookDayView::DateBookDayView( bool whichClock, QWidget *parent,
40 const char *name ) 43 const char *name )
41 : QTable( 24, 1, parent, name ), 44 : QTable( 24, 1, parent, name ),
42 ampm( whichClock ) 45 ampm( whichClock )
43{ 46{
44 enableClipper(TRUE); 47 enableClipper(TRUE);
45 setTopMargin( 0 ); 48 setTopMargin( 0 );
46 horizontalHeader()->hide(); 49 horizontalHeader()->hide();
47 setLeftMargin(38); 50 setLeftMargin(38);
48 setColumnStretchable( 0, TRUE ); 51 setColumnStretchable( 0, TRUE );
49 setHScrollBarMode( QScrollView::AlwaysOff ); 52 setHScrollBarMode( QScrollView::AlwaysOff );
50 verticalHeader()->setPalette(white); 53 verticalHeader()->setPalette(white);
51 verticalHeader()->setResizeEnabled(FALSE); 54 verticalHeader()->setResizeEnabled(FALSE);
52 setSelectionMode( Single ); 55 setSelectionMode( Single );
53 56
54 // get rid of being able to edit things... 57 // get rid of being able to edit things...
55 QTableItem *tmp; 58 QTableItem *tmp;
56 int row; 59 int row;
57 for ( row = 0; row < numRows(); row++ ) { 60 for ( row = 0; row < numRows(); row++ ) {
58 tmp = new QTableItem( this, QTableItem::Never, QString::null); 61 tmp = new QTableItem( this, QTableItem::Never, QString::null);
59 setItem( row, 0, tmp ); 62 setItem( row, 0, tmp );
63 setRowHeight( row, 40);
60 } 64 }
61 initHeader(); 65 initHeader();
62 QObject::connect( qApp, SIGNAL(clockChanged(bool)), 66 QObject::connect( qApp, SIGNAL(clockChanged(bool)),
63 this, SLOT(slotChangeClock(bool)) ); 67 this, SLOT(slotChangeClock(bool)) );
64} 68}
65 69
66void DateBookDayView::initHeader() 70void DateBookDayView::initHeader()
67{ 71{
68 QString strTmp; 72 QString strTmp;
69 for ( int i = 0; i < 24; ++i ) { 73 for ( int i = 0; i < 24; ++i ) {
70 if ( ampm ) { 74 if ( ampm ) {
71 if ( i == 0 ) 75 if ( i == 0 )
72 strTmp = QString::number(12) + ":00"; 76 strTmp = QString::number(12) + ":00";
73 else if ( i == 12 ) 77 else if ( i == 12 )
74 strTmp = QString::number(12) + tr(":00p"); 78 strTmp = QString::number(12) + tr(":00p");
75 else if ( i > 12 ) 79 else if ( i > 12 )
76 strTmp = QString::number( i - 12 ) + tr(":00p"); 80 strTmp = QString::number( i - 12 ) + tr(":00p");
77 else 81 else
78 strTmp = QString::number(i) + ":00"; 82 strTmp = QString::number(i) + ":00";
79 } else { 83 } else {
80 if ( i < 10 ) 84 if ( i < 10 )
81 strTmp = "0" + QString::number(i) + ":00"; 85 strTmp = "0" + QString::number(i) + ":00";
82 else 86 else
83 strTmp = QString::number(i) + ":00"; 87 strTmp = QString::number(i) + ":00";
84 } 88 }
85 strTmp = strTmp.rightJustify( 6, ' ' ); 89 strTmp = strTmp.rightJustify( 6, ' ' );
86 verticalHeader()->setLabel( i, strTmp ); 90 verticalHeader()->setLabel( i, strTmp );
87 setRowStretchable( i, FALSE ); 91 setRowStretchable( i, FALSE );
88 } 92 }
89} 93}
90 94
91void DateBookDayView::slotChangeClock( bool newClock ) 95void DateBookDayView::slotChangeClock( bool newClock )
92{ 96{
93 ampm = newClock; 97 ampm = newClock;
94 initHeader(); 98 initHeader();
95} 99}
96 100
97bool DateBookDayView::whichClock() const 101bool DateBookDayView::whichClock() const
98{ 102{
99 return ampm; 103 return ampm;
100} 104}
101 105
102void DateBookDayView::moveUp() 106void DateBookDayView::moveUp()
103{ 107{
104 scrollBy(0, -20); 108 scrollBy(0, -20);
105} 109}
106 110
107void DateBookDayView::moveDown() 111void DateBookDayView::moveDown()
108{ 112{
109 scrollBy(0, 20); 113 scrollBy(0, 20);
110} 114}
111 115
112void DateBookDayView::paintCell( QPainter *p, int, int, const QRect &cr, bool ) 116void DateBookDayView::paintCell( QPainter *p, int, int, const QRect &cr, bool )
113{ 117{
114 int w = cr.width(); 118 int w = cr.width();
115 int h = cr.height(); 119 int h = cr.height();
116 p->fillRect( 0, 0, w, h, colorGroup().brush( QColorGroup::Base ) ); 120 p->fillRect( 0, 0, w, h, colorGroup().brush( QColorGroup::Base ) );
117 if ( showGrid() ) { 121 if ( showGrid() ) {
118 // Draw our lines 122 // Draw our lines
119 int x2 = w - 1; 123 int x2 = w - 1;
120 int y2 = h - 1; 124 int y2 = h - 1;
121 QPen pen( p->pen() ); 125 QPen pen( p->pen() );
122 p->setPen( colorGroup().mid() ); 126 p->setPen( colorGroup().dark() );
123 p->drawLine( x2, 0, x2, y2 ); 127 p->drawLine( x2, 0, x2, y2 );
124 p->drawLine( 0, y2, x2, y2 ); 128 p->drawLine( 0, y2, x2, y2 );
129
130 p->setPen( colorGroup().midlight() );
131 p->drawLine( 0, y2 - h/2, x2, y2 - h/2);
132
125 p->setPen( pen ); 133 p->setPen( pen );
126 } 134 }
127} 135}
128 136
129void DateBookDayView::paintFocus( QPainter *, const QRect & ) 137void DateBookDayView::paintFocus( QPainter *, const QRect & )
130{ 138{
131} 139}
132 140
133 141
134void DateBookDayView::resizeEvent( QResizeEvent *e ) 142void DateBookDayView::resizeEvent( QResizeEvent *e )
135{ 143{
136 QTable::resizeEvent( e ); 144 QTable::resizeEvent( e );
137 columnWidthChanged( 0 ); 145 columnWidthChanged( 0 );
138 emit sigColWidthChanged(); 146 emit sigColWidthChanged();
139} 147}
140 148
141void DateBookDayView::keyPressEvent( QKeyEvent *e ) 149void DateBookDayView::keyPressEvent( QKeyEvent *e )
142{ 150{
143 QString txt = e->text(); 151 QString txt = e->text();
144 if ( !txt.isNull() && txt[0] > ' ' && e->key() < 0x1000 ) { 152 if ( !txt.isNull() && txt[0] > ' ' && e->key() < 0x1000 ) {
145 // we this is some sort of thing we know about... 153 // we this is some sort of thing we know about...
146 e->accept(); 154 e->accept();
147 emit sigCapturedKey( txt ); 155 emit sigCapturedKey( txt );
148 } else { 156 } else {
149 // I don't know what this key is, do you? 157 // I don't know what this key is, do you?
150 e->ignore(); 158 e->ignore();
151 } 159 }
152} 160}
153 161
154 162
155//=========================================================================== 163//===========================================================================
156 164
157DateBookDay::DateBookDay( bool ampm, bool startOnMonday, 165DateBookDay::DateBookDay( bool ampm, bool startOnMonday,
158 DateBookDB *newDb, QWidget *parent, 166 DateBookDB *newDb, QWidget *parent,
159 const char *name ) 167 const char *name )
160 : QVBox( parent, name ), 168 : QVBox( parent, name ),
161 currDate( QDate::currentDate() ), 169 currDate( QDate::currentDate() ),
162 db( newDb ), 170 db( newDb ),
163 startTime( 0 ) 171 startTime( 0 )
164{ 172{
165 widgetList.setAutoDelete( true ); 173 widgetList.setAutoDelete( true );
166 header = new DateBookDayHeader( startOnMonday, this, "day header" ); 174 header = new DateBookDayHeader( startOnMonday, this, "day header" );
167 header->setDate( currDate.year(), currDate.month(), currDate.day() ); 175 header->setDate( currDate.year(), currDate.month(), currDate.day() );
168 view = new DateBookDayView( ampm, this, "day view" ); 176 view = new DateBookDayView( ampm, this, "day view" );
169 connect( header, SIGNAL( dateChanged( int, int, int ) ), 177 connect( header, SIGNAL( dateChanged( int, int, int ) ),
170 this, SLOT( dateChanged( int, int, int ) ) ); 178 this, SLOT( dateChanged( int, int, int ) ) );
171 connect( view, SIGNAL( sigColWidthChanged() ), 179 connect( view, SIGNAL( sigColWidthChanged() ),
172 this, SLOT( slotColWidthChanged() ) ); 180 this, SLOT( slotColWidthChanged() ) );
173 connect( qApp, SIGNAL(weekChanged(bool)), 181 connect( qApp, SIGNAL(weekChanged(bool)),
174 this, SLOT(slotWeekChanged(bool)) ); 182 this, SLOT(slotWeekChanged(bool)) );
175 connect( view, SIGNAL(sigCapturedKey(const QString &)), 183 connect( view, SIGNAL(sigCapturedKey(const QString &)),
176 this, SIGNAL(sigNewEvent(const QString&)) ); 184 this, SIGNAL(sigNewEvent(const QString&)) );
185
186 QTimer *timer = new QTimer( this );
187
188 connect( timer, SIGNAL(timeout()),
189 this, SLOT(updateView()) );//connect timer for updating timeMarker & daywidgetcolors
190 timer->start( 1000*60*5, FALSE ); //update every 5min
191
192 selectedWidget = 0;
193
194 timeMarker = new DateBookDayTimeMarker( this );
195 timeMarker->setTime( QTime::currentTime() );
196}
197
198void DateBookDay::updateView( void )
199{
200 timeMarker->setTime( QTime::currentTime() );
201 //need to find a way to update all DateBookDayWidgets
202}
203
204void DateBookDay::setSelectedWidget( DateBookDayWidget *w )
205{
206 selectedWidget = w;
207}
208
209DateBookDayWidget * DateBookDay::getSelectedWidget( void )
210{
211 return selectedWidget;
177} 212}
178 213
179void DateBookDay::selectedDates( QDateTime &start, QDateTime &end ) 214void DateBookDay::selectedDates( QDateTime &start, QDateTime &end )
180{ 215{
181 start.setDate( currDate ); 216 start.setDate( currDate );
182 end.setDate( currDate ); 217 end.setDate( currDate );
183 218
184 int sh=99,eh=-1; 219 int sh=99,eh=-1;
185 220
186 int n = dayView()->numSelections(); 221 int n = dayView()->numSelections();
187 222
188 for (int i=0; i<n; i++) { 223 for (int i=0; i<n; i++) {
189 QTableSelection sel = dayView()->selection( i ); 224 QTableSelection sel = dayView()->selection( i );
190 sh = QMIN(sh,sel.topRow()); 225 sh = QMIN(sh,sel.topRow());
191 eh = QMAX(sh,sel.bottomRow()+1); 226 eh = QMAX(sh,sel.bottomRow()+1);
192 } 227 }
193 if (sh > 23 || eh < 1) { 228 if (sh > 23 || eh < 1) {
194 sh=8; 229 sh=8;
195 eh=9; 230 eh=9;
196 } 231 }
197 232
198 start.setTime( QTime( sh, 0, 0 ) ); 233 start.setTime( QTime( sh, 0, 0 ) );
199 end.setTime( QTime( eh, 0, 0 ) ); 234 end.setTime( QTime( eh, 0, 0 ) );
200} 235}
201 236
202void DateBookDay::setDate( int y, int m, int d ) 237void DateBookDay::setDate( int y, int m, int d )
203{ 238{
204 header->setDate( y, m, d ); 239 header->setDate( y, m, d );
240
241 selectedWidget = 0;
205} 242}
206 243
207void DateBookDay::setDate( QDate d) 244void DateBookDay::setDate( QDate d)
208{ 245{
209 header->setDate( d.year(), d.month(), d.day() ); 246 header->setDate( d.year(), d.month(), d.day() );
247
248 selectedWidget = 0;
210} 249}
211 250
212void DateBookDay::dateChanged( int y, int m, int d ) 251void DateBookDay::dateChanged( int y, int m, int d )
213{ 252{
214 QDate date( y, m, d ); 253 QDate date( y, m, d );
215 if ( currDate == date ) 254 if ( currDate == date )
216 return; 255 return;
217 currDate.setYMD( y, m, d ); 256 currDate.setYMD( y, m, d );
218 relayoutPage(); 257 relayoutPage();
219 dayView()->clearSelection(); 258 dayView()->clearSelection();
220 QTableSelection ts; 259 QTableSelection ts;
221 ts.init( startTime, 0 ); 260 ts.init( startTime, 0 );
222 ts.expandTo( startTime, 0 ); 261 ts.expandTo( startTime, 0 );
223 dayView()->addSelection( ts ); 262 dayView()->addSelection( ts );
263
264 selectedWidget = 0;
265
266 if (this->date() == QDate::currentDate())
267 timeMarker->show(); else timeMarker->hide();
268
224} 269}
225 270
226void DateBookDay::redraw() 271void DateBookDay::redraw()
227{ 272{
228 if ( isUpdatesEnabled() ) 273 if ( isUpdatesEnabled() )
229 relayoutPage(); 274 relayoutPage();
230} 275}
231 276
232void DateBookDay::getEvents() 277void DateBookDay::getEvents()
233{ 278{
234 widgetList.clear(); 279 widgetList.clear();
235 280
236 QValueList<EffectiveEvent> eventList = db->getEffectiveEvents( currDate, 281 QValueList<EffectiveEvent> eventList = db->getEffectiveEvents( currDate,
237 currDate ); 282 currDate );
238 QValueListIterator<EffectiveEvent> it; 283 QValueListIterator<EffectiveEvent> it;
239 for ( it = eventList.begin(); it != eventList.end(); ++it ) { 284 for ( it = eventList.begin(); it != eventList.end(); ++it ) {
240 DateBookDayWidget* w = new DateBookDayWidget( *it, this ); 285 DateBookDayWidget* w = new DateBookDayWidget( *it, this );
241 connect( w, SIGNAL( deleteMe( const Event & ) ), 286 connect( w, SIGNAL( deleteMe( const Event & ) ),
242 this, SIGNAL( removeEvent( const Event & ) ) ); 287 this, SIGNAL( removeEvent( const Event & ) ) );
243 connect( w, SIGNAL( editMe( const Event & ) ), 288 connect( w, SIGNAL( editMe( const Event & ) ),
244 this, SIGNAL( editEvent( const Event & ) ) ); 289 this, SIGNAL( editEvent( const Event & ) ) );
245 connect( w, SIGNAL( beamMe( const Event & ) ), 290 connect( w, SIGNAL( beamMe( const Event & ) ),
246 this, SIGNAL( beamEvent( const Event & ) ) ); 291 this, SIGNAL( beamEvent( const Event & ) ) );
247 widgetList.append( w ); 292 widgetList.append( w );
248 } 293 }
294
249} 295}
250 296
251static int place( const DateBookDayWidget *item, bool *used, int maxn ) 297static int place( const DateBookDayWidget *item, bool *used, int maxn )
252{ 298{
253 int place = 0; 299 int place = 0;
254 int start = item->event().start().hour(); 300 int start = item->event().start().hour();
255 QTime e = item->event().end(); 301 QTime e = item->event().end();
256 int end = e.hour(); 302 int end = e.hour();
257 if ( e.minute() < 5 ) 303 if ( e.minute() < 5 )
258 end--; 304 end--;
259 if ( end < start ) 305 if ( end < start )
260 end = start; 306 end = start;
261 while ( place < maxn ) { 307 while ( place < maxn ) {
262 bool free = TRUE; 308 bool free = TRUE;
263 int s = start; 309 int s = start;
264 while( s <= end ) { 310 while( s <= end ) {
265 if ( used[10*s+place] ) { 311 if ( used[10*s+place] ) {
266 free = FALSE; 312 free = FALSE;
267 break; 313 break;
268 } 314 }
269 s++; 315 s++;
270 } 316 }
271 if ( free ) break; 317 if ( free ) break;
272 place++; 318 place++;
273 } 319 }
274 if ( place == maxn ) { 320 if ( place == maxn ) {
275 return -1; 321 return -1;
276 } 322 }
277 while( start <= end ) { 323 while( start <= end ) {
278 used[10*start+place] = TRUE; 324 used[10*start+place] = TRUE;
279 start++; 325 start++;
280 } 326 }
281 return place; 327 return place;
282} 328}
283 329
284 330
285void DateBookDay::relayoutPage( bool fromResize ) 331void DateBookDay::relayoutPage( bool fromResize )
286{ 332{
287 setUpdatesEnabled( FALSE ); 333 setUpdatesEnabled( FALSE );
288 if ( !fromResize ) 334 if ( !fromResize )
289 getEvents(); // no need we already have them! 335 getEvents(); // no need we already have them!
290 336
337 widgetList.sort();
338 //sorts the widgetList by the heights of the widget so that the tallest widgets are at the beginning
339 //this is needed for the simple algo below to work correctly, otherwise some widgets would be drawn outside the view
340
291 int wCount = widgetList.count(); 341 int wCount = widgetList.count();
292 int wid = view->columnWidth(0)-1; 342 int wid = view->columnWidth(0)-1;
343 int wd;
293 int n = 1; 344 int n = 1;
294 345
346 QArray<int> anzIntersect(wCount); //this stores the number of maximal intersections of each widget
347
348 for (int i = 0; i<wCount; anzIntersect[i] = 1, i++);
349
295 if ( wCount < 20 ) { 350 if ( wCount < 20 ) {
296 for ( int i = 0; i < wCount; ) { 351
352 QArray<QRect> geometries(wCount);
353 for (int i = 0; i < wCount; geometries[i] = widgetList.at(i)->geometry(), i++);//stores geometry for each widget in vector
354
355 for ( int i = 0; i < wCount; i++)
356 {
357 QValueList<int> intersectedWidgets;
358
359 //find all widgets intersecting with widgetList.at(i)
360 for ( int j = 0; j < wCount; j++)
361 if (i != j)
362 if (geometries[j].intersects(geometries[i]))
363 intersectedWidgets.append(j);
364
365 //for each of these intersecting widgets find out how many widgets are they intersecting with
366 for ( uint j = 0; j < intersectedWidgets.count(); j++)
367 {
368 QArray<int> inter(wCount);
369 inter[j]=1;
370
371 if (intersectedWidgets[j] != -1)
372 for ( uint k = j; k < intersectedWidgets.count(); k++)
373 if (j != k && intersectedWidgets[k] != -1)
374 if (geometries[intersectedWidgets[k]].intersects(geometries[intersectedWidgets[j]]))
375 {
376 inter[j]++;
377 intersectedWidgets[k] = -1;
378 }
379 if (inter[j] > anzIntersect[i]) anzIntersect[i] = inter[j] + 1;
380 }
381
382 if (anzIntersect[i] == 1 && intersectedWidgets.count()) anzIntersect[i]++;
383 }
384
385
386 for ( int i = 0; i < wCount; i++) {
297 DateBookDayWidget *w = widgetList.at(i); 387 DateBookDayWidget *w = widgetList.at(i);
298 int x = 0;
299 int xp = 0;
300 QRect geom = w->geometry(); 388 QRect geom = w->geometry();
301 geom.setX( x ); 389
302 geom.setWidth( wid ); 390 geom.setX( 0 );
303 while ( xp < n && intersects( w, geom ) ) { 391
304 x += wid; 392 wd = (view->columnWidth(0)-1) / anzIntersect[i] - (anzIntersect[i]>1?2:0);
305 xp++; 393
306 geom.moveBy( wid, 0 ); 394 geom.setWidth( wd );
307 } 395
308 if ( xp >= n ) { 396 while ( intersects( w, geom ) ) {
309 n++; 397 geom.moveBy( wd + 2 + 1, 0 );
310 wid = ( view->columnWidth(0)-1 ) / n;
311 i = 0;
312 } else {
313 w->setGeometry( geom );
314 i++;
315 } 398 }
399 w->setGeometry( geom );
316 } 400 }
401
317 view->setContentsPos( 0, startTime * view->rowHeight(0) ); 402 view->setContentsPos( 0, startTime * view->rowHeight(0) );
403
404
318 } else { 405 } else {
319 406
320 407
321 int hours[24]; 408 int hours[24];
322 memset( hours, 0, 24*sizeof( int ) ); 409 memset( hours, 0, 24*sizeof( int ) );
323 bool overFlow = FALSE; 410 bool overFlow = FALSE;
324 for ( int i = 0; i < wCount; i++ ) { 411 for ( int i = 0; i < wCount; i++ ) {
325 DateBookDayWidget *w = widgetList.at(i); 412 DateBookDayWidget *w = widgetList.at(i);
326 int start = w->event().start().hour(); 413 int start = w->event().start().hour();
327 QTime e = w->event().end(); 414 QTime e = w->event().end();
328 int end = e.hour(); 415 int end = e.hour();
329 if ( e.minute() < 5 ) 416 if ( e.minute() < 5 )
330 end--; 417 end--;
331 if ( end < start ) 418 if ( end < start )
332 end = start; 419 end = start;
333 while( start <= end ) { 420 while( start <= end ) {
334 hours[start]++; 421 hours[start]++;
335 if ( hours[start] >= 10 ) 422 if ( hours[start] >= 10 )
336 overFlow = TRUE; 423 overFlow = TRUE;
337 ++start; 424 ++start;
338 } 425 }
339 if ( overFlow ) 426 if ( overFlow )
340 break; 427 break;
341 } 428 }
342 for ( int i = 0; i < 24; i++ ) { 429 for ( int i = 0; i < 24; i++ ) {
343 n = QMAX( n, hours[i] ); 430 n = QMAX( n, hours[i] );
344 } 431 }
345 wid = ( view->columnWidth(0)-1 ) / n; 432 wid = ( view->columnWidth(0)-1 ) / n;
346 433
347 bool used[24*10]; 434 bool used[24*10];
348 memset( used, FALSE, 24*10*sizeof( bool ) ); 435 memset( used, FALSE, 24*10*sizeof( bool ) );
349 436
350 for ( int i = 0; i < wCount; i++ ) { 437 for ( int i = 0; i < wCount; i++ ) {
351 DateBookDayWidget *w = widgetList.at(i); 438 DateBookDayWidget *w = widgetList.at(i);
352 int xp = place( w, used, n ); 439 int xp = place( w, used, n );
353 if ( xp != -1 ) { 440 if ( xp != -1 ) {
354 QRect geom = w->geometry(); 441 QRect geom = w->geometry();
355 geom.setX( xp*wid ); 442 geom.setX( xp*(wid+2) );
356 geom.setWidth( wid ); 443 geom.setWidth( wid );
357 w->setGeometry( geom ); 444 w->setGeometry( geom );
358 } 445 }
359 } 446 }
360 view->setContentsPos( 0, startTime * view->rowHeight(0) ); 447 view->setContentsPos( 0, startTime * view->rowHeight(0) );
361 } 448 }
449
450 timeMarker->setTime( QTime::currentTime() );//display timeMarker
451 timeMarker->raise(); //on top of all widgets
362 setUpdatesEnabled( TRUE ); 452 setUpdatesEnabled( TRUE );
363 return; 453 return;
364} 454}
365 455
366DateBookDayWidget *DateBookDay::intersects( const DateBookDayWidget *item, const QRect &geom ) 456DateBookDayWidget *DateBookDay::intersects( const DateBookDayWidget *item, const QRect &geom )
367{ 457{
368 int i = 0; 458 int i = 0;
369 DateBookDayWidget *w = widgetList.at(i); 459 DateBookDayWidget *w = widgetList.at(i);
370 int wCount = widgetList.count(); 460 int wCount = widgetList.count();
371 while ( i < wCount && w != item ) { 461 while ( i < wCount && w != item ) {
372 if ( w->geometry().intersects( geom ) ) { 462 if ( w->geometry().intersects( geom ) ) {
373 return w; 463 return w;
374 } 464 }
375 w = widgetList.at(++i); 465 w = widgetList.at(++i);
376 } 466 }
377 467
378 return 0; 468 return 0;
379} 469}
380 470
381 471
382QDate DateBookDay::date() const 472QDate DateBookDay::date() const
383{ 473{
384 return currDate; 474 return currDate;
385} 475}
386 476
387void DateBookDay::setStartViewTime( int startHere ) 477void DateBookDay::setStartViewTime( int startHere )
388{ 478{
389 startTime = startHere; 479 startTime = startHere;
390 dayView()->clearSelection(); 480 dayView()->clearSelection();
391 QTableSelection ts; 481 QTableSelection ts;
392 ts.init( startTime, 0 ); 482 ts.init( startTime, 0 );
393 ts.expandTo( startTime, 0 ); 483 ts.expandTo( startTime, 0 );
394 dayView()->addSelection( ts ); 484 dayView()->addSelection( ts );
395} 485}
396 486
397int DateBookDay::startViewTime() const 487int DateBookDay::startViewTime() const
398{ 488{
399 return startTime; 489 return startTime;
400} 490}
401 491
402void DateBookDay::slotWeekChanged( bool bStartOnMonday ) 492void DateBookDay::slotWeekChanged( bool bStartOnMonday )
403{ 493{
404 header->setStartOfWeek( bStartOnMonday ); 494 header->setStartOfWeek( bStartOnMonday );
405 // redraw(); 495 // redraw();
406} 496}
407 497
408void DateBookDay::keyPressEvent(QKeyEvent *e) 498void DateBookDay::keyPressEvent(QKeyEvent *e)
409{ 499{
410 switch(e->key()) { 500 switch(e->key()) {
411 case Key_Up: 501 case Key_Up:
412 view->moveUp(); 502 view->moveUp();
413 break; 503 break;
414 case Key_Down: 504 case Key_Down:
415 view->moveDown(); 505 view->moveDown();
416 break; 506 break;
417 case Key_Left: 507 case Key_Left:
418 setDate(QDate(currDate).addDays(-1)); 508 setDate(QDate(currDate).addDays(-1));
419 break; 509 break;
420 case Key_Right: 510 case Key_Right:
421 setDate(QDate(currDate).addDays(1)); 511 setDate(QDate(currDate).addDays(1));
422 break; 512 break;
423 default: 513 default:
424 e->ignore(); 514 e->ignore();
425 } 515 }
426} 516}
427 517
428//=========================================================================== 518//===========================================================================
429 519
430DateBookDayWidget::DateBookDayWidget( const EffectiveEvent &e, 520DateBookDayWidget::DateBookDayWidget( const EffectiveEvent &e,
431 DateBookDay *db ) 521 DateBookDay *db )
432 : QWidget( db->dayView()->viewport() ), ev( e ), dateBook( db ) 522 : QWidget( db->dayView()->viewport() ), ev( e ), dateBook( db )
433{ 523{
434 bool whichClock = db->dayView()->whichClock(); 524 bool whichClock = db->dayView()->whichClock();
435 525
436 // why would someone use "<"? Oh well, fix it up... 526 // why would someone use "<"? Oh well, fix it up...
437 // I wonder what other things may be messed up... 527 // I wonder what other things may be messed up...
438 QString strDesc = ev.description(); 528 QString strDesc = ev.description();
439 int where = strDesc.find( "<" ); 529 int where = strDesc.find( "<" );
440 while ( where != -1 ) { 530 while ( where != -1 ) {
441 strDesc.remove( where, 1 ); 531 strDesc.remove( where, 1 );
442 strDesc.insert( where, "&#60;" ); 532 strDesc.insert( where, "&#60;" );
443 where = strDesc.find( "<", where ); 533 where = strDesc.find( "<", where );
444 } 534 }
445 535
446 QString strCat; 536 QString strCat;
447 // ### Fix later... 537 // ### Fix later...
448// QString strCat = ev.category(); 538// QString strCat = ev.category();
449// where = strCat.find( "<" ); 539// where = strCat.find( "<" );
450// while ( where != -1 ) { 540// while ( where != -1 ) {
451 // strCat.remove( where, 1 ); 541 // strCat.remove( where, 1 );
452 // strCat.insert( where, "&#60;" ); 542 // strCat.insert( where, "&#60;" );
453 // where = strCat.find( "<", where ); 543 // where = strCat.find( "<", where );
454// } 544// }
455 545
456 QString strNote = ev.notes(); 546 QString strNote = ev.notes();
457 where = strNote.find( "<" ); 547 where = strNote.find( "<" );
458 while ( where != -1 ) { 548 while ( where != -1 ) {
459 strNote.remove( where, 1 ); 549 strNote.remove( where, 1 );
460 strNote.insert( where, "&#60;" ); 550 strNote.insert( where, "&#60;" );
461 where = strNote.find( "<", where ); 551 where = strNote.find( "<", where );
462 } 552 }
463 553
464 text = "<b>" + strDesc + "</b><br>" + "<i>" 554 text = "<b>" + strDesc + "</b><br>" + "<i>"
465 + strCat + "</i>" 555 + strCat + "</i>"
466 + "<br><b>" + tr("Start") + "</b>: "; 556 + "<br><b>" + tr("Start") + "</b>: ";
467 557
468 558
469 if ( e.startDate() != ev.date() ) { 559 if ( e.startDate() != ev.date() ) {
470 // multi-day event. Show start date 560 // multi-day event. Show start date
471 text += TimeString::longDateString( e.startDate() ); 561 text += TimeString::longDateString( e.startDate() );
472 } else { 562 } else {
473 // Show start time. 563 // Show start time.
474 text += TimeString::timeString( ev.start(), whichClock, FALSE ); 564 text += TimeString::timeString( ev.start(), whichClock, FALSE );
475 } 565 }
476 566
477 text += "<br><b>" + tr("End") + "</b>: "; 567 text += "<br><b>" + tr("End") + "</b>: ";
478 if ( e.endDate() != ev.date() ) { 568 if ( e.endDate() != ev.date() ) {
479 // multi-day event. Show end date 569 // multi-day event. Show end date
480 text += TimeString::longDateString( e.endDate() ); 570 text += TimeString::longDateString( e.endDate() );
481 } else { 571 } else {
482 // Show end time. 572 // Show end time.
483 text += TimeString::timeString( ev.end(), whichClock, FALSE ); 573 text += TimeString::timeString( ev.end(), whichClock, FALSE );
484 } 574 }
485 text += "<br><br>" + strNote; 575 text += "<br><br>" + strNote;
486 setBackgroundMode( PaletteBase ); 576 setBackgroundMode( PaletteBase );
487 577
488 QTime start = ev.start(); 578 QTime start = ev.start();
489 QTime end = ev.end(); 579 QTime end = ev.end();
490 int y = start.hour()*60+start.minute(); 580 int y = start.hour()*60+start.minute();
491 int h = end.hour()*60+end.minute()-y; 581 int h = end.hour()*60+end.minute()-y;
492 int rh = dateBook->dayView()->rowHeight(0); 582 int rh = dateBook->dayView()->rowHeight(0);
493 y = y*rh/60; 583 y = y*rh/60;
494 h = h*rh/60; 584 h = h*rh/60;
495 if ( h < 3 ) 585 if ( h < 3 )
496 h = 3; 586 h = 3;
497 geom.setY( y ); 587 geom.setY( y );
498 geom.setHeight( h ); 588 geom.setHeight( h );
589 geom.setX( 0 );
590 geom.setWidth(dateBook->dayView()->columnWidth(0)-1);
591
499} 592}
500 593
501DateBookDayWidget::~DateBookDayWidget() 594DateBookDayWidget::~DateBookDayWidget()
502{ 595{
503} 596}
504 597
505void DateBookDayWidget::paintEvent( QPaintEvent *e ) 598void DateBookDayWidget::paintEvent( QPaintEvent *e )
506{ 599{
507 QPainter p( this ); 600 QPainter p( this );
601
602 if (dateBook->getSelectedWidget() == this)
603 {
604 p.setBrush( QColor( 155, 240, 230 ) ); // selected item
605 } else
606 {
607 if (dateBook->date() == QDate::currentDate())
608 {
609 QTime curTime = QTime::currentTime();
610
611 if (ev.end() < curTime)
612 {
613 p.setBrush( QColor( 180, 180, 180 ) ); // grey, inactive
614 } else
615 {
616 //change color in dependence of the time till the event starts
617 int duration = curTime.secsTo(ev.start());
618 if (duration < 0) duration = 0;
619 int colChange = duration*160/86400; //86400: secs per day, 160: max color shift
620
621 p.setBrush( QColor( 200-colChange, 200-colChange, 255 ) ); //blue
622 }
623 } else
624 {
625 p.setBrush( QColor( 220, 220, 220 ) ); //light grey, inactive (not current date)
626 //perhaps make a distinction between future/past dates
627 }
628 }
629
508 p.setPen( QColor(100, 100, 100) ); 630 p.setPen( QColor(100, 100, 100) );
509 p.setBrush( QColor( 255, 240, 230 ) ); // based on priority?
510 p.drawRect(rect()); 631 p.drawRect(rect());
511 632
633 // p.drawRect(0,0, 5, height());
634
512 int y = 0; 635 int y = 0;
513 int d = 0; 636 int d = 0;
514 637
515 if ( ev.event().hasAlarm() ) { 638 if ( ev.event().hasAlarm() ) {
516 p.drawPixmap( width() - 16, 0, Resource::loadPixmap( "bell" ) ); 639 p.drawPixmap( width() - 16, 0, Resource::loadPixmap( "bell" ) );
517 y = 20; 640 y = 20;
518 d = 20; 641 d = 20;
519 } 642 }
520 643
521 if ( ev.event().hasRepeat() ) { 644 if ( ev.event().hasRepeat() ) {
522 p.drawPixmap( width() - 16, y, Resource::loadPixmap( "repeat" ) ); 645 p.drawPixmap( width() - 16, y, Resource::loadPixmap( "repeat" ) );
523 d = 20; 646 d = 20;
524 } 647 }
525 648
526 QSimpleRichText rt( text, font() ); 649 QSimpleRichText rt( text, font() );
527 rt.setWidth( geom.width() - d - 6 ); 650 rt.setWidth( geom.width() - d - 6 );
528 rt.draw( &p, 3, 0, e->region(), colorGroup() ); 651 rt.draw( &p, 7, 0, e->region(), colorGroup() );
529} 652}
530 653
531void DateBookDayWidget::mousePressEvent( QMouseEvent *e ) 654void DateBookDayWidget::mousePressEvent( QMouseEvent *e )
532{ 655{
656 DateBookDayWidget *item;
657
658 item = dateBook->getSelectedWidget();
659 if (item) item->update();
660
661 dateBook->setSelectedWidget(this);
662 update();
663 dateBook->repaint();
664
533 QPopupMenu m; 665 QPopupMenu m;
534 m.insertItem( tr( "Edit" ), 1 ); 666 m.insertItem( tr( "Edit" ), 1 );
535 m.insertItem( tr( "Delete" ), 2 ); 667 m.insertItem( tr( "Delete" ), 2 );
536 m.insertItem( tr( "Beam" ), 3 ); 668 m.insertItem( tr( "Beam" ), 3 );
537 int r = m.exec( e->globalPos() ); 669 int r = m.exec( e->globalPos() );
538 if ( r == 1 ) { 670 if ( r == 1 ) {
539 emit editMe( ev.event() ); 671 emit editMe( ev.event() );
540 } else if ( r == 2 ) { 672 } else if ( r == 2 ) {
541 emit deleteMe( ev.event() ); 673 emit deleteMe( ev.event() );
542 } else if ( r == 3 ) { 674 } else if ( r == 3 ) {
543 emit beamMe( ev.event() ); 675 emit beamMe( ev.event() );
544 } 676 }
545} 677}
546 678
547void DateBookDayWidget::setGeometry( const QRect &r ) 679void DateBookDayWidget::setGeometry( const QRect &r )
548{ 680{
549 geom = r; 681 geom = r;
550 setFixedSize( r.width()+1, r.height()+1 ); 682 setFixedSize( r.width()+1, r.height()+1 );
551 dateBook->dayView()->moveChild( this, r.x(), r.y()-1 ); 683 dateBook->dayView()->moveChild( this, r.x(), r.y()-1 );
552 show(); 684 show();
553} 685}
686
687
688//---------------------------------------------------------------------------------------------
689//---------------------------------------------------------------------------------------------
690
691
692DateBookDayTimeMarker::DateBookDayTimeMarker( DateBookDay *db )
693 : QWidget( db->dayView()->viewport() ), dateBook( db )
694{
695 setBackgroundMode( PaletteBase );
696}
697
698DateBookDayTimeMarker::~DateBookDayTimeMarker()
699{
700}
701
702void DateBookDayTimeMarker::paintEvent( QPaintEvent */*e*/ )
703{
704 QPainter p( this );
705 p.setBrush( QColor( 255, 0, 0 ) );
706
707 QPen pen;
708 pen.setStyle(NoPen);
709
710 p.setPen( pen );
711 p.drawRect(rect());
712}
713
714void DateBookDayTimeMarker::setTime( const QTime &t )
715{
716 int y = t.hour()*60+t.minute();
717 int rh = dateBook->dayView()->rowHeight(0);
718 y = y*rh/60;
719
720 geom.setX( 0 );
721
722 int x = dateBook->dayView()->columnWidth(0)-1;
723 geom.setWidth( x );
724
725 geom.setY( y );
726 geom.setHeight( 1 );
727
728 setGeometry( geom );
729
730 time = t;
731}
732
733void DateBookDayTimeMarker::setGeometry( const QRect &r )
734{
735 geom = r;
736 setFixedSize( r.width()+1, r.height()+1 );
737 dateBook->dayView()->moveChild( this, r.x(), r.y()-1 );
738 show();
739}
diff --git a/core/pim/datebook/datebookday.h b/core/pim/datebook/datebookday.h
index 531fded..db0f3b6 100644
--- a/core/pim/datebook/datebookday.h
+++ b/core/pim/datebook/datebookday.h
@@ -1,138 +1,188 @@
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#ifndef DATEBOOKDAY_H 20#ifndef DATEBOOKDAY_H
21#define DATEBOOKDAY_H 21#define DATEBOOKDAY_H
22 22
23#include <qpe/event.h> 23#include <qpe/event.h>
24 24
25#include <qdatetime.h> 25#include <qdatetime.h>
26#include <qtable.h> 26#include <qtable.h>
27#include <qvbox.h> 27#include <qvbox.h>
28#include <qlist.h> 28#include <qlist.h>
29 29
30class DateBookDayHeader; 30class DateBookDayHeader;
31class DateBookDB; 31class DateBookDB;
32class QDateTime; 32class QDateTime;
33class QMouseEvent; 33class QMouseEvent;
34class QPaintEvent; 34class QPaintEvent;
35class QResizeEvent; 35class QResizeEvent;
36 36
37class DateBookDayView : public QTable 37class DateBookDayView : public QTable
38{ 38{
39 Q_OBJECT 39 Q_OBJECT
40public: 40public:
41 DateBookDayView( bool hourClock, QWidget *parent, const char *name ); 41 DateBookDayView( bool hourClock, QWidget *parent, const char *name );
42 bool whichClock() const; 42 bool whichClock() const;
43 43
44public slots: 44public slots:
45 void moveUp(); 45 void moveUp();
46 void moveDown(); 46 void moveDown();
47 47
48signals: 48signals:
49 void sigColWidthChanged(); 49 void sigColWidthChanged();
50 void sigCapturedKey( const QString &txt ); 50 void sigCapturedKey( const QString &txt );
51protected slots: 51protected slots:
52 void slotChangeClock( bool ); 52 void slotChangeClock( bool );
53protected: 53protected:
54 virtual void paintCell( QPainter *p, int row, int col, const QRect &cr, bool selected ); 54 virtual void paintCell( QPainter *p, int row, int col, const QRect &cr, bool selected );
55 virtual void paintFocus( QPainter *p, const QRect &cr ); 55 virtual void paintFocus( QPainter *p, const QRect &cr );
56
56 virtual void resizeEvent( QResizeEvent *e ); 57 virtual void resizeEvent( QResizeEvent *e );
57 void keyPressEvent( QKeyEvent *e ); 58 void keyPressEvent( QKeyEvent *e );
58 void initHeader(); 59 void initHeader();
59private: 60private:
60 bool ampm; 61 bool ampm;
61}; 62};
62 63
63class DateBookDay; 64class DateBookDay;
64class DateBookDayWidget : public QWidget 65class DateBookDayWidget : public QWidget
65{ 66{
66 Q_OBJECT 67 Q_OBJECT
67 68
68public: 69public:
69 DateBookDayWidget( const EffectiveEvent &e, DateBookDay *db ); 70 DateBookDayWidget( const EffectiveEvent &e, DateBookDay *db );
70 ~DateBookDayWidget(); 71 ~DateBookDayWidget();
71 72
72 const QRect &geometry() { return geom; } 73 const QRect &geometry() { return geom; }
73 void setGeometry( const QRect &r ); 74 void setGeometry( const QRect &r );
74 75
75 const EffectiveEvent &event() const { return ev; } 76 const EffectiveEvent &event() const { return ev; }
76 77
77signals: 78signals:
78 void deleteMe( const Event &e ); 79 void deleteMe( const Event &e );
79 void editMe( const Event &e ); 80 void editMe( const Event &e );
80 void beamMe( const Event &e ); 81 void beamMe( const Event &e );
81 82
82protected: 83protected:
83 void paintEvent( QPaintEvent *e ); 84 void paintEvent( QPaintEvent *e );
84 void mousePressEvent( QMouseEvent *e ); 85 void mousePressEvent( QMouseEvent *e );
85 86
86private: 87private:
87 const EffectiveEvent ev; 88 const EffectiveEvent ev;
88 DateBookDay *dateBook; 89 DateBookDay *dateBook;
89 QString text; 90 QString text;
90 QRect geom; 91 QRect geom;
91}; 92};
92 93
94//Marker for current time in the dayview
95class DateBookDayTimeMarker : public QWidget
96{
97 Q_OBJECT
98
99public:
100 DateBookDayTimeMarker( DateBookDay *db );
101 ~DateBookDayTimeMarker();
102
103 const QRect &geometry() { return geom; }
104 void setGeometry( const QRect &r );
105 void setTime( const QTime &t );
106
107signals:
108
109protected:
110 void paintEvent( QPaintEvent *e );
111
112private:
113 QRect geom;
114 QTime time;
115 DateBookDay *dateBook;
116};
117
118//reimplemented the compareItems function so that it sorts DayWidgets by geometry heights
119class WidgetListClass : public QList<DateBookDayWidget>
120 {
121 private:
122
123 int compareItems( QCollection::Item s1, QCollection::Item s2 )
124 {
125 //hmm, don't punish me for that ;)
126 if (reinterpret_cast<DateBookDayWidget*>(s1)->geometry().height() > reinterpret_cast<DateBookDayWidget*>(s2)->geometry().height())
127 {
128 return -1;
129 } else
130 {
131 return 1;
132 }
133 }
134
135
136};
137
93class DateBookDay : public QVBox 138class DateBookDay : public QVBox
94{ 139{
95 Q_OBJECT 140 Q_OBJECT
96 141
97public: 142public:
98 DateBookDay( bool ampm, bool startOnMonday, DateBookDB *newDb, 143 DateBookDay( bool ampm, bool startOnMonday, DateBookDB *newDb,
99 QWidget *parent, const char *name ); 144 QWidget *parent, const char *name );
100 void selectedDates( QDateTime &start, QDateTime &end ); 145 void selectedDates( QDateTime &start, QDateTime &end );
101 QDate date() const; 146 QDate date() const;
102 DateBookDayView *dayView() const { return view; } 147 DateBookDayView *dayView() const { return view; }
103 void setStartViewTime( int startHere ); 148 void setStartViewTime( int startHere );
104 int startViewTime() const; 149 int startViewTime() const;
150 void setSelectedWidget( DateBookDayWidget * );
151 DateBookDayWidget * getSelectedWidget( void );
105 152
106public slots: 153public slots:
107 void setDate( int y, int m, int d ); 154 void setDate( int y, int m, int d );
108 void setDate( QDate ); 155 void setDate( QDate );
109 void redraw(); 156 void redraw();
110 void slotWeekChanged( bool bStartOnMonday ); 157 void slotWeekChanged( bool bStartOnMonday );
158 void updateView();//updates TimeMarker and DayWidget-colors
111 159
112signals: 160signals:
113 void removeEvent( const Event& ); 161 void removeEvent( const Event& );
114 void editEvent( const Event& ); 162 void editEvent( const Event& );
115 void beamEvent( const Event& ); 163 void beamEvent( const Event& );
116 void newEvent(); 164 void newEvent();
117 void sigNewEvent( const QString & ); 165 void sigNewEvent( const QString & );
118 166
119protected slots: 167protected slots:
120 void keyPressEvent(QKeyEvent *); 168 void keyPressEvent(QKeyEvent *);
121 169
122private slots: 170private slots:
123 void dateChanged( int y, int m, int d ); 171 void dateChanged( int y, int m, int d );
124 void slotColWidthChanged() { relayoutPage(); }; 172 void slotColWidthChanged() { relayoutPage(); };
125 173
126private: 174private:
127 void getEvents(); 175 void getEvents();
128 void relayoutPage( bool fromResize = false ); 176 void relayoutPage( bool fromResize = false );
129 DateBookDayWidget *intersects( const DateBookDayWidget *item, const QRect &geom ); 177 DateBookDayWidget *intersects( const DateBookDayWidget *item, const QRect &geom );
130 QDate currDate; 178 QDate currDate;
131 DateBookDayView *view; 179 DateBookDayView *view;
132 DateBookDayHeader *header; 180 DateBookDayHeader *header;
133 DateBookDB *db; 181 DateBookDB *db;
134 QList<DateBookDayWidget> widgetList; 182 WidgetListClass widgetList;//reimplemented QList for sorting widgets by height
135 int startTime; 183 int startTime;
184 DateBookDayWidget *selectedWidget; //actual selected widget (obviously)
185 DateBookDayTimeMarker *timeMarker;//marker for current time
136}; 186};
137 187
138#endif 188#endif