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