summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--core/pim/datebook/datebook.cpp33
-rw-r--r--core/pim/datebook/datebooktypes.h8
2 files changed, 39 insertions, 2 deletions
diff --git a/core/pim/datebook/datebook.cpp b/core/pim/datebook/datebook.cpp
index 36c4bd7..a7f6691 100644
--- a/core/pim/datebook/datebook.cpp
+++ b/core/pim/datebook/datebook.cpp
@@ -1,1194 +1,1227 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved. 2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3** 3**
4** This file is part of Qtopia Environment. 4** This file is part of Qtopia Environment.
5** 5**
6** This file may be distributed and/or modified under the terms of the 6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software 7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the 8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file. 9** packaging of this file.
10** 10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13** 13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information. 14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15** 15**
16** Contact info@trolltech.com if any conditions of this licensing are 16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you. 17** not clear to you.
18** 18**
19** $Id$ 19** $Id$
20** 20**
21**********************************************************************/ 21**********************************************************************/
22 22
23#define QTOPIA_INTERNAL_FD 23#define QTOPIA_INTERNAL_FD
24 24
25#include "datebook.h" 25#include "datebook.h"
26#include "datebookday.h" 26#include "datebookday.h"
27#include "datebooksettings.h" 27#include "datebooksettings.h"
28#include "datebookweek.h" 28#include "datebookweek.h"
29#include "datebookweeklst.h" 29#include "datebookweeklst.h"
30#include "dateentryimpl.h" 30#include "dateentryimpl.h"
31 31
32#include <opie2/odebug.h> 32#include <opie2/odebug.h>
33#include <opie2/oholidaypluginif.h> 33#include <opie2/oholidaypluginif.h>
34#include <opie2/oholidayplugin.h> 34#include <opie2/oholidayplugin.h>
35#include <opie2/opluginloader.h>
36#include <opie2/todayplugininterface.h>
35 37
36#include <qpe/datebookmonth.h> 38#include <qpe/datebookmonth.h>
37#include <qpe/qpeapplication.h> 39#include <qpe/qpeapplication.h>
38#include <qpe/config.h> 40#include <qpe/config.h>
39#include <qpe/finddialog.h> 41#include <qpe/finddialog.h>
40#include <qpe/ir.h> 42#include <qpe/ir.h>
41#include <qpe/qpemessagebox.h> 43#include <qpe/qpemessagebox.h>
42#include <qpe/resource.h> 44#include <qpe/resource.h>
43#include <qpe/sound.h> 45#include <qpe/sound.h>
44#include <qpe/tzselect.h> 46#include <qpe/tzselect.h>
45 47
46#include <qaction.h> 48#include <qaction.h>
47#include <qcopchannel_qws.h> 49#include <qcopchannel_qws.h>
48#include <qlayout.h> 50#include <qlayout.h>
49#include <qmessagebox.h> 51#include <qmessagebox.h>
50#include <qtimer.h> 52#include <qtimer.h>
51#include <qtl.h> 53#include <qtl.h>
52#include <qtoolbar.h> 54#include <qtoolbar.h>
53#include <qwidgetstack.h> 55#include <qwidgetstack.h>
54#include <qdir.h> 56#include <qdir.h>
55#include <qtopia/qlibrary.h> 57#include <qtopia/qlibrary.h>
56 58
57#include <sys/stat.h> 59#include <sys/stat.h>
58#include <sys/types.h> 60#include <sys/types.h>
59#include <fcntl.h> 61#include <fcntl.h>
60#include <unistd.h> 62#include <unistd.h>
61 63
62#include <stdlib.h> 64#include <stdlib.h>
63 65
64DateBook::DateBook( QWidget *parent, const char *, WFlags f ) 66DateBook::DateBook( QWidget *parent, const char *, WFlags f )
65 : QMainWindow( parent, "datebook", f ), 67 : QMainWindow( parent, "datebook", f ),
66 aPreset( FALSE ), 68 aPreset( FALSE ),
67 presetTime( -1 ), 69 presetTime( -1 ),
68 startTime( 8 ), // an acceptable default 70 startTime( 8 ), // an acceptable default
69 rowStyle( 0 ), 71 rowStyle( 0 ),
70 bJumpToCurTime(FALSE), 72 bJumpToCurTime(FALSE),
71 syncing(FALSE), 73 syncing(FALSE),
72 inSearch(FALSE), 74 inSearch(FALSE),
73 alarmCounter(0) 75 alarmCounter(0)
74{ 76{
75 bool needEvilHack= false; // if we need an Evil Hack 77 bool needEvilHack= false; // if we need an Evil Hack
76 QTime t; 78 QTime t;
77 t.start(); 79 t.start();
78 db = new DateBookDBHoliday; 80 db = new DateBookDBHoliday;
79 odebug << "loading db t=" << t.elapsed() << oendl; 81 odebug << "loading db t=" << t.elapsed() << oendl;
80 db_holiday = new DateBookHoliday(); 82 db_holiday = new DateBookHoliday();
81 db->db_holiday=db_holiday; 83 db->db_holiday=db_holiday;
82 84
83 loadSettings(); 85 loadSettings();
84 setCaption( tr("Calendar") ); 86 setCaption( tr("Calendar") );
85 setIcon( Resource::loadPixmap( "datebook_icon" ) ); 87 setIcon( Resource::loadPixmap( "datebook_icon" ) );
86 88
87 setToolBarsMovable( FALSE ); 89 setToolBarsMovable( FALSE );
88 90
89 views = new QWidgetStack( this ); 91 views = new QWidgetStack( this );
90 setCentralWidget( views ); 92 setCentralWidget( views );
91 93
92 dayView = 0; 94 dayView = 0;
93 weekView = 0; 95 weekView = 0;
94 weekLstView = 0; 96 weekLstView = 0;
95 monthView = 0; 97 monthView = 0;
96 98
97// QToolBar *bar = new QToolBar( this ); 99// QToolBar *bar = new QToolBar( this );
98// bar->setHorizontalStretchable( TRUE ); 100// bar->setHorizontalStretchable( TRUE );
99 101
100// QMenuBar *mb = new QMenuBar( bar ); 102// QMenuBar *mb = new QMenuBar( bar );
101// mb->setMargin( 0 ); 103// mb->setMargin( 0 );
102 104
103// QPopupMenu *view = new QPopupMenu( this ); 105// QPopupMenu *view = new QPopupMenu( this );
104// mb->insertItem( tr( "View" ), view ); 106// mb->insertItem( tr( "View" ), view );
105 107
106 QToolBar *sub_bar = new QToolBar(this); 108 QToolBar *sub_bar = new QToolBar(this);
107 sub_bar->setHorizontalStretchable(TRUE); 109 sub_bar->setHorizontalStretchable(TRUE);
108 110
109 QActionGroup *g = new QActionGroup( this ); 111 QActionGroup *g = new QActionGroup( this );
110 g->setExclusive( TRUE ); 112 g->setExclusive( TRUE );
111 113
112 QAction *a = new QAction( tr( "New" ), Resource::loadPixmap( "new" ), QString::null, 0, this, 0 ); 114 QAction *a = new QAction( tr( "New" ), Resource::loadPixmap( "new" ), QString::null, 0, this, 0 );
113 connect( a, SIGNAL( activated() ), this, SLOT( fileNew() ) ); 115 connect( a, SIGNAL( activated() ), this, SLOT( fileNew() ) );
114 a->addTo( sub_bar ); 116 a->addTo( sub_bar );
115 117
116 sub_bar->addSeparator(); 118 sub_bar->addSeparator();
117 119
118 a = new QAction( tr( "Today" ), Resource::loadPixmap( "datebook/to_day" ), QString::null, 0, g, 0 ); 120 a = new QAction( tr( "Today" ), Resource::loadPixmap( "datebook/to_day" ), QString::null, 0, g, 0 );
119 connect( a, SIGNAL( activated() ), this, SLOT( slotToday() ) ); 121 connect( a, SIGNAL( activated() ), this, SLOT( slotToday() ) );
120 a->addTo( sub_bar ); 122 a->addTo( sub_bar );
121// a->addTo( view ); 123// a->addTo( view );
122 124
123 sub_bar->addSeparator(); 125 sub_bar->addSeparator();
124 126
125 a = new QAction( tr( "Day" ), Resource::loadPixmap( "day" ), QString::null, 0, g, 0 ); 127 a = new QAction( tr( "Day" ), Resource::loadPixmap( "day" ), QString::null, 0, g, 0 );
126 connect( a, SIGNAL( activated() ), this, SLOT( viewDay() ) ); 128 connect( a, SIGNAL( activated() ), this, SLOT( viewDay() ) );
127 a->addTo( sub_bar ); 129 a->addTo( sub_bar );
128// a->addTo( view ); 130// a->addTo( view );
129 a->setToggleAction( TRUE ); 131 a->setToggleAction( TRUE );
130 a->setOn( TRUE ); 132 a->setOn( TRUE );
131 dayAction = a; 133 dayAction = a;
132 134
133 a = new QAction( tr( "Week" ), Resource::loadPixmap( "week" ), QString::null, 0, g, 0 ); 135 a = new QAction( tr( "Week" ), Resource::loadPixmap( "week" ), QString::null, 0, g, 0 );
134 connect( a, SIGNAL( activated() ), this, SLOT( viewWeek() ) ); 136 connect( a, SIGNAL( activated() ), this, SLOT( viewWeek() ) );
135 a->addTo( sub_bar ); 137 a->addTo( sub_bar );
136// a->addTo( view ); 138// a->addTo( view );
137 a->setToggleAction( TRUE ); 139 a->setToggleAction( TRUE );
138 weekAction = a; 140 weekAction = a;
139 141
140 a = new QAction( tr( "WeekLst" ), Resource::loadPixmap( "datebook/weeklst" ), QString::null, 0, g, 0 ); 142 a = new QAction( tr( "WeekLst" ), Resource::loadPixmap( "datebook/weeklst" ), QString::null, 0, g, 0 );
141 connect( a, SIGNAL( activated() ), this, SLOT( viewWeekLst() ) ); 143 connect( a, SIGNAL( activated() ), this, SLOT( viewWeekLst() ) );
142 a->addTo( sub_bar ); 144 a->addTo( sub_bar );
143// a->addTo( view ); 145// a->addTo( view );
144 a->setToggleAction( TRUE ); 146 a->setToggleAction( TRUE );
145 weekLstAction = a; 147 weekLstAction = a;
146 148
147 a = new QAction( tr( "Month" ), Resource::loadPixmap( "month" ), QString::null, 0, g, 0 ); 149 a = new QAction( tr( "Month" ), Resource::loadPixmap( "month" ), QString::null, 0, g, 0 );
148 connect( a, SIGNAL( activated() ), this, SLOT( viewMonth() ) ); 150 connect( a, SIGNAL( activated() ), this, SLOT( viewMonth() ) );
149 a->addTo( sub_bar ); 151 a->addTo( sub_bar );
150// a->addTo( view ); 152// a->addTo( view );
151 a->setToggleAction( TRUE ); 153 a->setToggleAction( TRUE );
152 monthAction = a; 154 monthAction = a;
153 155
154 sub_bar->addSeparator(); 156 sub_bar->addSeparator();
155 157
156 a = new QAction( tr( "Find" ), Resource::loadPixmap( "mag" ), QString::null, 0, this, 0 ); 158 a = new QAction( tr( "Find" ), Resource::loadPixmap( "mag" ), QString::null, 0, this, 0 );
157 connect( a, SIGNAL(activated()), this, SLOT(slotFind()) ); 159 connect( a, SIGNAL(activated()), this, SLOT(slotFind()) );
158 a->addTo( sub_bar ); 160 a->addTo( sub_bar );
159 161
160 a = new QAction( tr( "Edit..." ), Resource::loadPixmap("SettingsIcon"), QString::null, 0, this, 0 ); 162 a = new QAction( tr( "Edit..." ), Resource::loadPixmap("SettingsIcon"), QString::null, 0, this, 0 );
161 connect( a, SIGNAL( activated() ), this, SLOT( slotSettings() ) ); 163 connect( a, SIGNAL( activated() ), this, SLOT( slotSettings() ) );
162 a->addTo( sub_bar ); 164 a->addTo( sub_bar );
163 165
164 if(defaultView==DAY) viewDay(); 166 if(defaultView==DAY) viewDay();
165 if(defaultView==WEEK) needEvilHack=true; // viewWeek(); 167 if(defaultView==WEEK) needEvilHack=true; // viewWeek();
166 if(defaultView==WEEKLST) viewWeekLst(); 168 if(defaultView==WEEKLST) viewWeekLst();
167 if(defaultView==MONTH) viewMonth(); 169 if(defaultView==MONTH) viewMonth();
168 170
169 connect( qApp, SIGNAL(clockChanged(bool)), this, SLOT(changeClock(bool)) ); 171 connect( qApp, SIGNAL(clockChanged(bool)), this, SLOT(changeClock(bool)) );
170 connect( qApp, SIGNAL(weekChanged(bool)), this, SLOT(changeWeek(bool)) ); 172 connect( qApp, SIGNAL(weekChanged(bool)), this, SLOT(changeWeek(bool)) );
171 173
172#if defined(Q_WS_QWS) && !defined(QT_NO_COP) 174#if defined(Q_WS_QWS) && !defined(QT_NO_COP)
173 connect( qApp, SIGNAL(appMessage(const QCString&,const QByteArray&)), this, SLOT(appMessage(const QCString&,const QByteArray&)) ); 175 connect( qApp, SIGNAL(appMessage(const QCString&,const QByteArray&)), this, SLOT(appMessage(const QCString&,const QByteArray&)) );
174#endif 176#endif
175 177
176 // listen on QPE/System 178 // listen on QPE/System
177#if defined(Q_WS_QWS) 179#if defined(Q_WS_QWS)
178#if !defined(QT_NO_COP) 180#if !defined(QT_NO_COP)
179 QCopChannel *channel = new QCopChannel( "QPE/System", this ); 181 QCopChannel *channel = new QCopChannel( "QPE/System", this );
180 connect( channel, SIGNAL(received(const QCString&,const QByteArray&)), this, SLOT(receive(const QCString&,const QByteArray&)) ); 182 connect( channel, SIGNAL(received(const QCString&,const QByteArray&)), this, SLOT(receive(const QCString&,const QByteArray&)) );
181 channel = new QCopChannel( "QPE/Datebook", this ); 183 channel = new QCopChannel( "QPE/Datebook", this );
182 connect( channel, SIGNAL(received(const QCString&,const QByteArray&)), this, SLOT(receive(const QCString&,const QByteArray&)) ); 184 connect( channel, SIGNAL(received(const QCString&,const QByteArray&)), this, SLOT(receive(const QCString&,const QByteArray&)) );
183#endif 185#endif
184#endif 186#endif
185 187
186 odebug << "done t=" << t.elapsed() << oendl; 188 odebug << "done t=" << t.elapsed() << oendl;
187 189
188 connect( qApp, SIGNAL( flush() ), this, SLOT( flush() ) ); 190 connect( qApp, SIGNAL( flush() ), this, SLOT( flush() ) );
189 connect( qApp, SIGNAL( reload()), this, SLOT( reload() ) ); 191 connect( qApp, SIGNAL( reload()), this, SLOT( reload() ) );
190 /* 192 /*
191 * Here is a problem description: 193 * Here is a problem description:
192 * When Weekview is the default view 194 * When Weekview is the default view
193 * a DateBookWeekView get's created 195 * a DateBookWeekView get's created
194 * redraw() get's called. So what? 196 * redraw() get's called. So what?
195 * Remember that we're still in the c'tor 197 * Remember that we're still in the c'tor
196 * and no final layout has happened? Ok 198 * and no final layout has happened? Ok
197 * now all Events get arranged. Their x 199 * now all Events get arranged. Their x
198 * position get's determined by a QHeader 200 * position get's determined by a QHeader
199 * position. But the QHeader isn't layouted or 201 * position. But the QHeader isn't layouted or
200 * at the right position. redraw() is a slot 202 * at the right position. redraw() is a slot
201 * so we'll call it then via a singleShot 203 * so we'll call it then via a singleShot
202 * from view() 204 * from view()
203 */ 205 */
204 if( needEvilHack ){ 206 if( needEvilHack ){
205 QTimer::singleShot( 500, this, SLOT(viewWeek()) ); 207 QTimer::singleShot( 500, this, SLOT(viewWeek()) );
206 } 208 }
207} 209}
208 210
209void DateBook::receive( const QCString &msg, const QByteArray &data ) 211void DateBook::receive( const QCString &msg, const QByteArray &data )
210{ 212{
211 QDataStream stream( data, IO_ReadOnly ); 213 QDataStream stream( data, IO_ReadOnly );
212 if ( msg == "timeChange(QString)" ) { 214 if ( msg == "timeChange(QString)" ) {
213 // update active view! 215 // update active view!
214 if ( dayAction->isOn() ) 216 if ( dayAction->isOn() )
215 viewDay(); 217 viewDay();
216 else if ( weekAction->isOn() ) 218 else if ( weekAction->isOn() )
217 viewWeek(); 219 viewWeek();
218 else if ( monthAction->isOn() ) 220 else if ( monthAction->isOn() )
219 viewMonth(); 221 viewMonth();
220 } 222 }
221 else if (msg == "editEvent(int)") { 223 else if (msg == "editEvent(int)") {
222 int uid; 224 int uid;
223 stream >> uid; 225 stream >> uid;
224 Event e=db->eventByUID(uid); 226 Event e=db->eventByUID(uid);
225 editEvent(e); 227 editEvent(e);
226 }else if (msg == "viewDefault(QDate)"){ 228 }else if (msg == "viewDefault(QDate)"){
227 QDate day; 229 QDate day;
228 stream >> day; 230 stream >> day;
229 viewDefault(day); 231 viewDefault(day);
230 } 232 }
231} 233}
232 234
233DateBook::~DateBook() 235DateBook::~DateBook()
234{ 236{
235 delete db_holiday; 237 delete db_holiday;
236} 238}
237 239
238void DateBook::slotSettings() 240void DateBook::slotSettings()
239{ 241{
240 DateBookSettings frmSettings( ampm, this ); 242 DateBookSettings frmSettings( ampm, this );
241 frmSettings.setStartTime( startTime ); 243 frmSettings.setStartTime( startTime );
242 frmSettings.setAlarmPreset( aPreset, presetTime ); 244 frmSettings.setAlarmPreset( aPreset, presetTime );
243 frmSettings.setJumpToCurTime( bJumpToCurTime ); 245 frmSettings.setJumpToCurTime( bJumpToCurTime );
244 frmSettings.setRowStyle( rowStyle ); 246 frmSettings.setRowStyle( rowStyle );
245 frmSettings.comboDefaultView->setCurrentItem(defaultView-1); 247 frmSettings.comboDefaultView->setCurrentItem(defaultView-1);
246 frmSettings.comboWeekListView->setCurrentItem(weeklistviewconfig); 248 frmSettings.comboWeekListView->setCurrentItem(weeklistviewconfig);
247 249
248 bool found=false; 250 bool found=false;
249 for (int i=0; i<(frmSettings.comboLocation->count()); i++) { 251 for (int i=0; i<(frmSettings.comboLocation->count()); i++) {
250 if ( frmSettings.comboLocation->text(i) == defaultLocation ) { 252 if ( frmSettings.comboLocation->text(i) == defaultLocation ) {
251 frmSettings.comboLocation->setCurrentItem(i); 253 frmSettings.comboLocation->setCurrentItem(i);
252 found=true; 254 found=true;
253 break; 255 break;
254 } 256 }
255 } 257 }
256 if(!found) { 258 if(!found) {
257 frmSettings.comboLocation->insertItem(defaultLocation); 259 frmSettings.comboLocation->insertItem(defaultLocation);
258 frmSettings.comboLocation->setCurrentItem(frmSettings.comboLocation->count()-1); 260 frmSettings.comboLocation->setCurrentItem(frmSettings.comboLocation->count()-1);
259 } 261 }
260 frmSettings.comboCategory->setCategories(defaultCategories,"Calendar", tr("Calendar")); 262 frmSettings.comboCategory->setCategories(defaultCategories,"Calendar", tr("Calendar"));
261 263
262 if ( QPEApplication::execDialog( &frmSettings ) ) { 264 if ( QPEApplication::execDialog( &frmSettings ) ) {
263 aPreset = frmSettings.alarmPreset(); 265 aPreset = frmSettings.alarmPreset();
264 presetTime = frmSettings.presetTime(); 266 presetTime = frmSettings.presetTime();
265 startTime = frmSettings.startTime(); 267 startTime = frmSettings.startTime();
266 bJumpToCurTime = frmSettings.jumpToCurTime(); 268 bJumpToCurTime = frmSettings.jumpToCurTime();
267 rowStyle = frmSettings.rowStyle(); 269 rowStyle = frmSettings.rowStyle();
268 defaultView=frmSettings.comboDefaultView->currentItem()+1; 270 defaultView=frmSettings.comboDefaultView->currentItem()+1;
269 weeklistviewconfig=frmSettings.comboWeekListView->currentItem(); 271 weeklistviewconfig=frmSettings.comboWeekListView->currentItem();
270 defaultLocation=frmSettings.comboLocation->currentText(); 272 defaultLocation=frmSettings.comboLocation->currentText();
271 defaultCategories=frmSettings.comboCategory->currentCategories(); 273 defaultCategories=frmSettings.comboCategory->currentCategories();
272 274
273 if ( dayView ) { 275 if ( dayView ) {
274 dayView->setStartViewTime( startTime ); 276 dayView->setStartViewTime( startTime );
275 dayView->setJumpToCurTime( bJumpToCurTime ); 277 dayView->setJumpToCurTime( bJumpToCurTime );
276 dayView->setRowStyle( rowStyle ); 278 dayView->setRowStyle( rowStyle );
277 } 279 }
278 if ( weekView ) { 280 if ( weekView ) {
279 weekView->setStartViewTime( startTime ); 281 weekView->setStartViewTime( startTime );
280 } 282 }
281 saveSettings(); 283 saveSettings();
282 284
283 // make the change obvious 285 // make the change obvious
284 if ( views->visibleWidget() ) { 286 if ( views->visibleWidget() ) {
285 if ( views->visibleWidget() == dayView ) 287 if ( views->visibleWidget() == dayView )
286 dayView->redraw(); 288 dayView->redraw();
287 else if ( views->visibleWidget() == weekView ) 289 else if ( views->visibleWidget() == weekView )
288 weekView->redraw(); 290 weekView->redraw();
289 else if ( views->visibleWidget() == weekLstView ) 291 else if ( views->visibleWidget() == weekLstView )
290 weekLstView->redraw(); 292 weekLstView->redraw();
291 } 293 }
292 } 294 }
293} 295}
294 296
295void DateBook::fileNew() 297void DateBook::fileNew()
296{ 298{
297 slotNewEventFromKey(""); 299 slotNewEventFromKey("");
298} 300}
299 301
300QString DateBook::checkEvent(const Event &e) 302QString DateBook::checkEvent(const Event &e)
301{ 303{
302 /* check if overlaps with itself */ 304 /* check if overlaps with itself */
303 bool checkFailed = FALSE; 305 bool checkFailed = FALSE;
304 306
305 /* check the next 12 repeats. should catch most problems */ 307 /* check the next 12 repeats. should catch most problems */
306 QDate current_date = e.start().date(); 308 QDate current_date = e.start().date();
307 Event previous = e; 309 Event previous = e;
308 for(int i = 0; i < 12; i++) 310 for(int i = 0; i < 12; i++)
309 { 311 {
310 QDateTime next; 312 QDateTime next;
311 if (!nextOccurance(previous, current_date.addDays(1), next)) { 313 if (!nextOccurance(previous, current_date.addDays(1), next)) {
312 break; // no more repeats 314 break; // no more repeats
313 } 315 }
314 if(next < previous.end()) { 316 if(next < previous.end()) {
315 checkFailed = TRUE; 317 checkFailed = TRUE;
316 break; 318 break;
317 } 319 }
318 current_date = next.date(); 320 current_date = next.date();
319 } 321 }
320 322
321 if(checkFailed) 323 if(checkFailed)
322 return tr("Event duration is potentially longer\n" 324 return tr("Event duration is potentially longer\n"
323 "than interval between repeats."); 325 "than interval between repeats.");
324 326
325 return QString::null; 327 return QString::null;
326} 328}
327 329
328QDate DateBook::currentDate() 330QDate DateBook::currentDate()
329{ 331{
330 QDate d = QDate::currentDate(); 332 QDate d = QDate::currentDate();
331 333
332 if ( dayView && views->visibleWidget() == dayView ) { 334 if ( dayView && views->visibleWidget() == dayView ) {
333 d = dayView->date(); 335 d = dayView->date();
334 } else if ( weekView && views->visibleWidget() == weekView ) { 336 } else if ( weekView && views->visibleWidget() == weekView ) {
335 d = weekView->date(); 337 d = weekView->date();
336 } else if ( weekLstView && views->visibleWidget() == weekLstView ) { 338 } else if ( weekLstView && views->visibleWidget() == weekLstView ) {
337 d = weekLstView->date(); 339 d = weekLstView->date();
338 } else if ( monthView && views->visibleWidget() == monthView ) { 340 } else if ( monthView && views->visibleWidget() == monthView ) {
339 d = monthView->selectedDate(); 341 d = monthView->selectedDate();
340 } 342 }
341 343
342 return d; 344 return d;
343} 345}
344 346
345void DateBook::view(int v, const QDate &d) { 347void DateBook::view(int v, const QDate &d) {
346 if (v==DAY) { 348 if (v==DAY) {
347 initDay(); 349 initDay();
348 dayAction->setOn( TRUE ); 350 dayAction->setOn( TRUE );
349 dayView->setDate( d ); 351 dayView->setDate( d );
350 views->raiseWidget( dayView ); 352 views->raiseWidget( dayView );
351 dayView->redraw(); 353 dayView->redraw();
352 } else if (v==WEEK) { 354 } else if (v==WEEK) {
353 initWeek(); 355 initWeek();
354 weekAction->setOn( TRUE ); 356 weekAction->setOn( TRUE );
355 weekView->setDate( d ); 357 weekView->setDate( d );
356 views->raiseWidget( weekView ); 358 views->raiseWidget( weekView );
357 weekView->redraw(); 359 weekView->redraw();
358 } else if (v==WEEKLST) { 360 } else if (v==WEEKLST) {
359 initWeekLst(); 361 initWeekLst();
360 weekLstAction->setOn( TRUE ); 362 weekLstAction->setOn( TRUE );
361 weekLstView->setDate(d); 363 weekLstView->setDate(d);
362 views->raiseWidget( weekLstView ); 364 views->raiseWidget( weekLstView );
363 weekLstView->redraw(); 365 weekLstView->redraw();
364 } else if (v==MONTH) { 366 } else if (v==MONTH) {
365 initMonth(); 367 initMonth();
366 monthAction->setOn( TRUE ); 368 monthAction->setOn( TRUE );
367 monthView->setDate( d.year(), d.month(), d.day() ); 369 monthView->setDate( d.year(), d.month(), d.day() );
368 views->raiseWidget( monthView ); 370 views->raiseWidget( monthView );
369 monthView->redraw(); 371 monthView->redraw();
370 } 372 }
371} 373}
372 374
373void DateBook::viewDefault(const QDate &d) { 375void DateBook::viewDefault(const QDate &d) {
374 view(defaultView,d); 376 view(defaultView,d);
375} 377}
376 378
377void DateBook::viewDay() { 379void DateBook::viewDay() {
378 view(DAY,currentDate()); 380 view(DAY,currentDate());
379} 381}
380 382
381void DateBook::viewWeek() { 383void DateBook::viewWeek() {
382 view(WEEK,currentDate()); 384 view(WEEK,currentDate());
383} 385}
384 386
385void DateBook::viewWeekLst() { 387void DateBook::viewWeekLst() {
386 view(WEEKLST,currentDate()); 388 view(WEEKLST,currentDate());
387} 389}
388 390
389void DateBook::viewMonth() { 391void DateBook::viewMonth() {
390 view(MONTH,currentDate()); 392 view(MONTH,currentDate());
391} 393}
392 394
393void DateBook::insertEvent( const Event &e ) 395void DateBook::insertEvent( const Event &e )
394{ 396{
395 Event dupEvent=e; 397 Event dupEvent=e;
396 if(!dupEvent.isValidUid() ) // tkcRom seems to be different 398 if(!dupEvent.isValidUid() ) // tkcRom seems to be different
397 dupEvent.assignUid(); 399 dupEvent.assignUid();
398 dupEvent.setLocation(defaultLocation); 400 dupEvent.setLocation(defaultLocation);
399 dupEvent.setCategories(defaultCategories); 401 dupEvent.setCategories(defaultCategories);
400 db->addEvent(dupEvent); 402 db->addEvent(dupEvent);
401 emit newEvent(); 403 emit newEvent();
402} 404}
403 405
404void DateBook::duplicateEvent( const Event &e ) 406void DateBook::duplicateEvent( const Event &e )
405{ 407{
406 // Alot of code duplication, as this is almost like editEvent(); 408 // Alot of code duplication, as this is almost like editEvent();
407 if (syncing) { 409 if (syncing) {
408 QMessageBox::warning( this, tr("Calendar"), tr( "Can not edit data, currently syncing") ); 410 QMessageBox::warning( this, tr("Calendar"), tr( "Can not edit data, currently syncing") );
409 return; 411 return;
410 } 412 }
411 413
412 Event dupevent(e); // Make a duplicate. 414 Event dupevent(e); // Make a duplicate.
413 415
414 // workaround added for text input. 416 // workaround added for text input.
415 QDialog editDlg( this, 0, TRUE ); 417 QDialog editDlg( this, 0, TRUE );
416 DateEntry *entry; 418 DateEntry *entry;
417 editDlg.setCaption( tr("Duplicate Event") ); 419 editDlg.setCaption( tr("Duplicate Event") );
418 QVBoxLayout *vb = new QVBoxLayout( &editDlg ); 420 QVBoxLayout *vb = new QVBoxLayout( &editDlg );
419 QScrollView *sv = new QScrollView( &editDlg, "scrollview" ); 421 QScrollView *sv = new QScrollView( &editDlg, "scrollview" );
420 sv->setResizePolicy( QScrollView::AutoOneFit ); 422 sv->setResizePolicy( QScrollView::AutoOneFit );
421 // KLUDGE!!! 423 // KLUDGE!!!
422 sv->setHScrollBarMode( QScrollView::AlwaysOff ); 424 sv->setHScrollBarMode( QScrollView::AlwaysOff );
423 vb->addWidget( sv ); 425 vb->addWidget( sv );
424 entry = new DateEntry( onMonday, dupevent, ampm, &editDlg, "editor" ); 426 entry = new DateEntry( onMonday, dupevent, ampm, &editDlg, "editor" );
425 entry->timezone->setEnabled( FALSE ); 427 entry->timezone->setEnabled( FALSE );
426 sv->addChild( entry ); 428 sv->addChild( entry );
427 429
428 while ( QPEApplication::execDialog( &editDlg ) ) { 430 while ( QPEApplication::execDialog( &editDlg ) ) {
429 Event newEv = entry->event(); 431 Event newEv = entry->event();
430 QString error = checkEvent(newEv); 432 QString error = checkEvent(newEv);
431 if (!error.isNull()) { 433 if (!error.isNull()) {
432 if (QMessageBox::warning(this, tr("error box"), error, tr("Fix it"), tr("Continue"), 0, 0, 1) == 0) 434 if (QMessageBox::warning(this, tr("error box"), error, tr("Fix it"), tr("Continue"), 0, 0, 1) == 0)
433 continue; 435 continue;
434 } 436 }
435 /* 437 /*
436 * The problem: 438 * The problem:
437 * DateBookDB does remove repeating events not by uid but by the time 439 * DateBookDB does remove repeating events not by uid but by the time
438 * the recurrence was created 440 * the recurrence was created
439 * so we need to update that time as well 441 * so we need to update that time as well
440 */ 442 */
441 Event::RepeatPattern rp = newEv.repeatPattern(); 443 Event::RepeatPattern rp = newEv.repeatPattern();
442 rp.createTime = ::time( NULL ); 444 rp.createTime = ::time( NULL );
443 newEv.setRepeat( TRUE, rp ); // has repeat and repeatPattern... 445 newEv.setRepeat( TRUE, rp ); // has repeat and repeatPattern...
444 if( newEv.uid() == e.uid() || !newEv.isValidUid() ) 446 if( newEv.uid() == e.uid() || !newEv.isValidUid() )
445 newEv.assignUid(); 447 newEv.assignUid();
446 448
447 db->addEvent(newEv); 449 db->addEvent(newEv);
448 emit newEvent(); 450 emit newEvent();
449 break; 451 break;
450 } 452 }
451} 453}
452 454
453void DateBook::editEvent( const Event &e ) 455void DateBook::editEvent( const Event &e )
454{ 456{
455 if (syncing) { 457 if (syncing) {
456 QMessageBox::warning( this, tr("Calendar"), tr( "Can not edit data, currently syncing") ); 458 QMessageBox::warning( this, tr("Calendar"), tr( "Can not edit data, currently syncing") );
457 return; 459 return;
458 } 460 }
459 461
460 // workaround added for text input. 462 // workaround added for text input.
461 QDialog editDlg( this, 0, TRUE ); 463 QDialog editDlg( this, 0, TRUE );
462 DateEntry *entry; 464 DateEntry *entry;
463 editDlg.setCaption( tr("Edit Event") ); 465 editDlg.setCaption( tr("Edit Event") );
464 QVBoxLayout *vb = new QVBoxLayout( &editDlg ); 466 QVBoxLayout *vb = new QVBoxLayout( &editDlg );
465 QScrollView *sv = new QScrollView( &editDlg, "scrollview" ); 467 QScrollView *sv = new QScrollView( &editDlg, "scrollview" );
466 sv->setResizePolicy( QScrollView::AutoOneFit ); 468 sv->setResizePolicy( QScrollView::AutoOneFit );
467 // KLUDGE!!! 469 // KLUDGE!!!
468 sv->setHScrollBarMode( QScrollView::AlwaysOff ); 470 sv->setHScrollBarMode( QScrollView::AlwaysOff );
469 vb->addWidget( sv ); 471 vb->addWidget( sv );
470 entry = new DateEntry( onMonday, e, ampm, &editDlg, "editor" ); 472 entry = new DateEntry( onMonday, e, ampm, &editDlg, "editor" );
471 entry->timezone->setEnabled( FALSE ); 473 entry->timezone->setEnabled( FALSE );
472 sv->addChild( entry ); 474 sv->addChild( entry );
473 475
474 while ( QPEApplication::execDialog( &editDlg ) ) { 476 while ( QPEApplication::execDialog( &editDlg ) ) {
475 Event newEv = entry->event(); 477 Event newEv = entry->event();
476 if(newEv.description().isEmpty() && newEv.notes().isEmpty() ) 478 if(newEv.description().isEmpty() && newEv.notes().isEmpty() )
477 break; 479 break;
478 newEv.setUid(e.uid()); // FIXME: Hack not to clear uid 480 newEv.setUid(e.uid()); // FIXME: Hack not to clear uid
479 QString error = checkEvent(newEv); 481 QString error = checkEvent(newEv);
480 if (!error.isNull()) { 482 if (!error.isNull()) {
481 if (QMessageBox::warning(this, tr("error box"), error, tr("Fix it"), tr("Continue"), 0, 0, 1) == 0) continue; 483 if (QMessageBox::warning(this, tr("error box"), error, tr("Fix it"), tr("Continue"), 0, 0, 1) == 0) continue;
482 } 484 }
483 db->editEvent(e, newEv); 485 db->editEvent(e, newEv);
484 emit newEvent(); 486 emit newEvent();
485 break; 487 break;
486 } 488 }
487} 489}
488 490
489void DateBook::removeEvent( const Event &e ) 491void DateBook::removeEvent( const Event &e )
490{ 492{
491 if (syncing) { 493 if (syncing) {
492 QMessageBox::warning( this, tr("Calendar"), tr( "Can not edit data, currently syncing") ); 494 QMessageBox::warning( this, tr("Calendar"), tr( "Can not edit data, currently syncing") );
493 return; 495 return;
494 } 496 }
495 497
496 QString strName = e.description(); 498 QString strName = e.description();
497 499
498 if ( !QPEMessageBox::confirmDelete( this, tr( "Calendar" ),strName ) ) 500 if ( !QPEMessageBox::confirmDelete( this, tr( "Calendar" ),strName ) )
499 return; 501 return;
500 502
501 db->removeEvent( e ); 503 db->removeEvent( e );
502 if ( views->visibleWidget() == dayView && dayView ) 504 if ( views->visibleWidget() == dayView && dayView )
503 dayView->redraw(); 505 dayView->redraw();
504 506
505} 507}
506 508
507void DateBook::addEvent( const Event &e ) 509void DateBook::addEvent( const Event &e )
508{ 510{
509 QDate d = e.start().date(); 511 QDate d = e.start().date();
510 initDay(); 512 initDay();
511 dayView->setDate( d ); 513 dayView->setDate( d );
512} 514}
513 515
514void DateBook::showDay( int year, int month, int day ) 516void DateBook::showDay( int year, int month, int day )
515{ 517{
516 QDate d(year, month, day); 518 QDate d(year, month, day);
517 view(DAY,d); 519 view(DAY,d);
518} 520}
519 521
520void DateBook::initDay() 522void DateBook::initDay()
521{ 523{
522 if ( !dayView ) { 524 if ( !dayView ) {
523 dayView = new DateBookDay( ampm, onMonday, db, db_holiday, views, "day view" ); 525 dayView = new DateBookDay( ampm, onMonday, db, db_holiday, views, "day view" );
524 views->addWidget( dayView, DAY ); 526 views->addWidget( dayView, DAY );
525 dayView->setJumpToCurTime( bJumpToCurTime ); 527 dayView->setJumpToCurTime( bJumpToCurTime );
526 dayView->setStartViewTime( startTime ); 528 dayView->setStartViewTime( startTime );
527 dayView->setRowStyle( rowStyle ); 529 dayView->setRowStyle( rowStyle );
528 connect( this, SIGNAL( newEvent() ), dayView, SLOT( redraw() ) ); 530 connect( this, SIGNAL( newEvent() ), dayView, SLOT( redraw() ) );
529 connect( dayView, SIGNAL( newEvent() ), this, SLOT( fileNew() ) ); 531 connect( dayView, SIGNAL( newEvent() ), this, SLOT( fileNew() ) );
530 connect( dayView, SIGNAL( removeEvent(const Event&) ), this, SLOT( removeEvent(const Event&) ) ); 532 connect( dayView, SIGNAL( removeEvent(const Event&) ), this, SLOT( removeEvent(const Event&) ) );
531 connect( dayView, SIGNAL( editEvent(const Event&) ), this, SLOT( editEvent(const Event&) ) ); 533 connect( dayView, SIGNAL( editEvent(const Event&) ), this, SLOT( editEvent(const Event&) ) );
532 connect( dayView, SIGNAL( duplicateEvent(const Event&) ), this, SLOT( duplicateEvent(const Event&) ) ); 534 connect( dayView, SIGNAL( duplicateEvent(const Event&) ), this, SLOT( duplicateEvent(const Event&) ) );
533 connect( dayView, SIGNAL( beamEvent(const Event&) ), this, SLOT( beamEvent(const Event&) ) ); 535 connect( dayView, SIGNAL( beamEvent(const Event&) ), this, SLOT( beamEvent(const Event&) ) );
534 connect( dayView, SIGNAL(sigNewEvent(const QString&)), this, SLOT(slotNewEventFromKey(const QString&)) ); 536 connect( dayView, SIGNAL(sigNewEvent(const QString&)), this, SLOT(slotNewEventFromKey(const QString&)) );
535 } 537 }
536} 538}
537 539
538void DateBook::initWeek() 540void DateBook::initWeek()
539{ 541{
540 if ( !weekView ) { 542 if ( !weekView ) {
541 weekView = new DateBookWeek( ampm, onMonday, db, views, "week view" ); 543 weekView = new DateBookWeek( ampm, onMonday, db, views, "week view" );
542 weekView->setStartViewTime( startTime ); 544 weekView->setStartViewTime( startTime );
543 views->addWidget( weekView, WEEK ); 545 views->addWidget( weekView, WEEK );
544 connect( weekView, SIGNAL( showDate(int,int,int) ), this, SLOT( showDay(int,int,int) ) ); 546 connect( weekView, SIGNAL( showDate(int,int,int) ), this, SLOT( showDay(int,int,int) ) );
545 connect( this, SIGNAL( newEvent() ), weekView, SLOT( redraw() ) ); 547 connect( this, SIGNAL( newEvent() ), weekView, SLOT( redraw() ) );
546 } 548 }
547 549
548 //But also get it right: the year that we display can be different 550 //But also get it right: the year that we display can be different
549 //from the year of the current date. So, first find the year 551 //from the year of the current date. So, first find the year
550 //number of the current week. 552 //number of the current week.
551 int yearNumber, totWeeks; 553 int yearNumber, totWeeks;
552 calcWeek( currentDate(), totWeeks, yearNumber, onMonday ); 554 calcWeek( currentDate(), totWeeks, yearNumber, onMonday );
553 555
554 QDate d = QDate( yearNumber, 12, 31 ); 556 QDate d = QDate( yearNumber, 12, 31 );
555 calcWeek( d, totWeeks, yearNumber, onMonday ); 557 calcWeek( d, totWeeks, yearNumber, onMonday );
556 558
557 while ( totWeeks == 1 ) { 559 while ( totWeeks == 1 ) {
558 d = d.addDays( -1 ); 560 d = d.addDays( -1 );
559 calcWeek( d, totWeeks, yearNumber, onMonday ); 561 calcWeek( d, totWeeks, yearNumber, onMonday );
560 } 562 }
561} 563}
562 564
563void DateBook::initWeekLst() { 565void DateBook::initWeekLst() {
564 if ( !weekLstView ) { 566 if ( !weekLstView ) {
565 weekLstView = new DateBookWeekLst( ampm, onMonday, db, views, "weeklst view" ); 567 weekLstView = new DateBookWeekLst( ampm, onMonday, db, views, "weeklst view" );
566 views->addWidget( weekLstView, WEEKLST ); 568 views->addWidget( weekLstView, WEEKLST );
567 569
568 //weekLstView->setStartViewTime( startTime ); 570 //weekLstView->setStartViewTime( startTime );
569 connect( weekLstView, SIGNAL( showDate(int,int,int) ), this, SLOT( showDay(int,int,int) ) ); 571 connect( weekLstView, SIGNAL( showDate(int,int,int) ), this, SLOT( showDay(int,int,int) ) );
570 connect( weekLstView, SIGNAL( addEvent(const QDateTime&,const QDateTime&,const QString&, const QString&) ), 572 connect( weekLstView, SIGNAL( addEvent(const QDateTime&,const QDateTime&,const QString&, const QString&) ),
571 this, SLOT( slotNewEntry(const QDateTime&,const QDateTime&,const QString&, const QString&) ) ); 573 this, SLOT( slotNewEntry(const QDateTime&,const QDateTime&,const QString&, const QString&) ) );
572 connect( this, SIGNAL( newEvent() ), weekLstView, SLOT( redraw() ) ); 574 connect( this, SIGNAL( newEvent() ), weekLstView, SLOT( redraw() ) );
573 connect( weekLstView, SIGNAL( editEvent(const Event&) ), this, SLOT( editEvent(const Event&) ) ); 575 connect( weekLstView, SIGNAL( editEvent(const Event&) ), this, SLOT( editEvent(const Event&) ) );
574 connect( weekLstView, SIGNAL( duplicateEvent( const Event & ) ), this, SLOT( duplicateEvent( const Event & ) ) ); 576 connect( weekLstView, SIGNAL( duplicateEvent( const Event & ) ), this, SLOT( duplicateEvent( const Event & ) ) );
575 connect( weekLstView, SIGNAL( beamEvent(const Event&) ), this, SLOT( beamEvent(const Event&) ) ); 577 connect( weekLstView, SIGNAL( beamEvent(const Event&) ), this, SLOT( beamEvent(const Event&) ) );
576 connect( weekLstView, SIGNAL( removeEvent( const Event & ) ), this, SLOT( removeEvent( const Event & ) ) ); 578 connect( weekLstView, SIGNAL( removeEvent( const Event & ) ), this, SLOT( removeEvent( const Event & ) ) );
577 } 579 }
578} 580}
579 581
580 582
581void DateBook::initMonth() 583void DateBook::initMonth()
582{ 584{
583 if ( !monthView ) { 585 if ( !monthView ) {
584 monthView = new DateBookMonth( views, "month view", FALSE, db ); 586 monthView = new DateBookMonth( views, "month view", FALSE, db );
585 views->addWidget( monthView, MONTH ); 587 views->addWidget( monthView, MONTH );
586 connect( monthView, SIGNAL( dateClicked(int,int,int) ), this, SLOT( showDay(int,int,int) ) ); 588 connect( monthView, SIGNAL( dateClicked(int,int,int) ), this, SLOT( showDay(int,int,int) ) );
587 connect( this, SIGNAL( newEvent() ), monthView, SLOT( redraw() ) ); 589 connect( this, SIGNAL( newEvent() ), monthView, SLOT( redraw() ) );
588 qApp->processEvents(); 590 qApp->processEvents();
589 } 591 }
590} 592}
591 593
592void DateBook::loadSettings() 594void DateBook::loadSettings()
593{ 595{
594 Config qpeconfig( "qpe" ); 596 Config qpeconfig( "qpe" );
595 qpeconfig.setGroup("Time"); 597 qpeconfig.setGroup("Time");
596 ampm = qpeconfig.readBoolEntry( "AMPM", TRUE ); 598 ampm = qpeconfig.readBoolEntry( "AMPM", TRUE );
597 onMonday = qpeconfig.readBoolEntry( "MONDAY" ); 599 onMonday = qpeconfig.readBoolEntry( "MONDAY" );
598 600
599 Config config("DateBook"); 601 Config config("DateBook");
600 config.setGroup("Main"); 602 config.setGroup("Main");
601 startTime = config.readNumEntry("startviewtime", 8); 603 startTime = config.readNumEntry("startviewtime", 8);
602 aPreset = config.readBoolEntry("alarmpreset"); 604 aPreset = config.readBoolEntry("alarmpreset");
603 presetTime = config.readNumEntry("presettime"); 605 presetTime = config.readNumEntry("presettime");
604 bJumpToCurTime = config.readBoolEntry("jumptocurtime"); 606 bJumpToCurTime = config.readBoolEntry("jumptocurtime");
605 rowStyle = config.readNumEntry("rowstyle"); 607 rowStyle = config.readNumEntry("rowstyle");
606 defaultView = config.readNumEntry("defaultview",DAY); 608 defaultView = config.readNumEntry("defaultview",DAY);
607 weeklistviewconfig = config.readNumEntry("weeklistviewconfig",NORMAL); 609 weeklistviewconfig = config.readNumEntry("weeklistviewconfig",NORMAL);
608 610
609 defaultLocation=config.readEntry("defaultLocation"); 611 defaultLocation=config.readEntry("defaultLocation");
610 QString tmpString=config.readEntry("defaultCategories"); 612 QString tmpString=config.readEntry("defaultCategories");
611 QStringList tmpStringList=QStringList::split(",",tmpString); 613 QStringList tmpStringList=QStringList::split(",",tmpString);
612 defaultCategories.truncate(0); 614 defaultCategories.truncate(0);
613 615
614 for( QStringList::Iterator i=tmpStringList.begin(); i!=tmpStringList.end(); i++) { 616 for( QStringList::Iterator i=tmpStringList.begin(); i!=tmpStringList.end(); i++) {
615 defaultCategories.resize(defaultCategories.count()+1); 617 defaultCategories.resize(defaultCategories.count()+1);
616 defaultCategories[defaultCategories.count()-1]=(*i).toInt(); 618 defaultCategories[defaultCategories.count()-1]=(*i).toInt();
617 } 619 }
618} 620}
619 621
620void DateBook::saveSettings() 622void DateBook::saveSettings()
621{ 623{
622 Config config( "qpe" ); 624 Config config( "qpe" );
623 Config configDB( "DateBook" ); 625 Config configDB( "DateBook" );
624 configDB.setGroup( "Main" ); 626 configDB.setGroup( "Main" );
625 configDB.writeEntry("startviewtime",startTime); 627 configDB.writeEntry("startviewtime",startTime);
626 configDB.writeEntry("alarmpreset",aPreset); 628 configDB.writeEntry("alarmpreset",aPreset);
627 configDB.writeEntry("presettime",presetTime); 629 configDB.writeEntry("presettime",presetTime);
628 configDB.writeEntry("jumptocurtime", bJumpToCurTime); 630 configDB.writeEntry("jumptocurtime", bJumpToCurTime);
629 configDB.writeEntry("rowstyle", rowStyle); 631 configDB.writeEntry("rowstyle", rowStyle);
630 configDB.writeEntry("defaultview",defaultView); 632 configDB.writeEntry("defaultview",defaultView);
631 configDB.writeEntry("weeklistviewconfig",weeklistviewconfig); 633 configDB.writeEntry("weeklistviewconfig",weeklistviewconfig);
632 634
633 configDB.writeEntry("defaultLocation",defaultLocation); 635 configDB.writeEntry("defaultLocation",defaultLocation);
634 QStringList tmpStringList; 636 QStringList tmpStringList;
635 for( uint i=0; i<defaultCategories.count(); i++) { 637 for( uint i=0; i<defaultCategories.count(); i++) {
636 tmpStringList << QString::number(defaultCategories[i]); 638 tmpStringList << QString::number(defaultCategories[i]);
637 } 639 }
638 configDB.writeEntry("defaultCategories",tmpStringList.join(",")); 640 configDB.writeEntry("defaultCategories",tmpStringList.join(","));
639} 641}
640 642
641void DateBook::appMessage(const QCString& msg, const QByteArray& data) 643void DateBook::appMessage(const QCString& msg, const QByteArray& data)
642{ 644{
643 bool needShow = FALSE; 645 bool needShow = FALSE;
644 if ( msg == "alarm(QDateTime,int)" ) { 646 if ( msg == "alarm(QDateTime,int)" ) {
645 QDataStream ds(data,IO_ReadOnly); 647 QDataStream ds(data,IO_ReadOnly);
646 QDateTime when; int warn; 648 QDateTime when; int warn;
647 ds >> when >> warn; 649 ds >> when >> warn;
648 650
649 // check to make it's okay to continue, 651 // check to make it's okay to continue,
650 // this is the case that the time was set ahead, and 652 // this is the case that the time was set ahead, and
651 // we are forced given a stale alarm... 653 // we are forced given a stale alarm...
652 QDateTime current = QDateTime::currentDateTime(); 654 QDateTime current = QDateTime::currentDateTime();
653 if ( current.time().hour() != when.time().hour() && current.time().minute() != when.time().minute() ) 655 if ( current.time().hour() != when.time().hour() && current.time().minute() != when.time().minute() )
654 return; 656 return;
655 657
656 QValueList<EffectiveEvent> list = db->getEffectiveEvents(when.addSecs(warn*60)); 658 QValueList<EffectiveEvent> list = db->getEffectiveEvents(when.addSecs(warn*60));
657 if ( list.count() > 0 ) { 659 if ( list.count() > 0 ) {
658 QString msg; 660 QString msg;
659 bool bSound = FALSE; 661 bool bSound = FALSE;
660 int stopTimer = 0; 662 int stopTimer = 0;
661 bool found = FALSE; 663 bool found = FALSE;
662 for ( QValueList<EffectiveEvent>::ConstIterator it=list.begin(); it!=list.end(); ++it ) { 664 for ( QValueList<EffectiveEvent>::ConstIterator it=list.begin(); it!=list.end(); ++it ) {
663 if ( (*it).event().hasAlarm() ) { 665 if ( (*it).event().hasAlarm() ) {
664 found = TRUE; 666 found = TRUE;
665 msg += "<CENTER><B>" + (*it).description() + "</B>" 667 msg += "<CENTER><B>" + (*it).description() + "</B>"
666 + "<BR>" + (*it).location() + "<BR>" 668 + "<BR>" + (*it).location() + "<BR>"
667 + TimeString::dateString((*it).event().start(),ampm) 669 + TimeString::dateString((*it).event().start(),ampm)
668 + (warn 670 + (warn
669 ? tr(" (in " + QString::number(warn) 671 ? tr(" (in " + QString::number(warn)
670 + tr(" minutes)")) 672 + tr(" minutes)"))
671 : QString("")) 673 : QString(""))
672 + "<BR>" 674 + "<BR>"
673 + (*it).notes() + "</CENTER>"; 675 + (*it).notes() + "</CENTER>";
674 if ( (*it).event().alarmSound() != Event::Silent ) { 676 if ( (*it).event().alarmSound() != Event::Silent ) {
675 bSound = TRUE; 677 bSound = TRUE;
676 } 678 }
677 } 679 }
678 } 680 }
679 if ( found ) { 681 if ( found ) {
680 if ( bSound ) { 682 if ( bSound ) {
681 Sound::soundAlarm(); 683 Sound::soundAlarm();
682 alarmCounter = 0; 684 alarmCounter = 0;
683 stopTimer = startTimer( 5000 ); 685 stopTimer = startTimer( 5000 );
684 } 686 }
685 QDialog dlg( this, 0, TRUE ); 687 QDialog dlg( this, 0, TRUE );
686 QVBoxLayout *vb = new QVBoxLayout( &dlg ); 688 QVBoxLayout *vb = new QVBoxLayout( &dlg );
687 QScrollView *view = new QScrollView( &dlg, "scrollView"); 689 QScrollView *view = new QScrollView( &dlg, "scrollView");
688 view->setResizePolicy( QScrollView::AutoOneFit ); 690 view->setResizePolicy( QScrollView::AutoOneFit );
689 vb->addWidget( view ); 691 vb->addWidget( view );
690 QLabel *lblMsg = new QLabel( msg, &dlg ); 692 QLabel *lblMsg = new QLabel( msg, &dlg );
691 view->addChild( lblMsg ); 693 view->addChild( lblMsg );
692 QPushButton *cmdOk = new QPushButton( tr("OK"), &dlg ); 694 QPushButton *cmdOk = new QPushButton( tr("OK"), &dlg );
693 connect( cmdOk, SIGNAL(clicked()), &dlg, SLOT(accept()) ); 695 connect( cmdOk, SIGNAL(clicked()), &dlg, SLOT(accept()) );
694 vb->addWidget( cmdOk ); 696 vb->addWidget( cmdOk );
695 697
696 needShow = QPEApplication::execDialog( &dlg ); 698 needShow = QPEApplication::execDialog( &dlg );
697 699
698 if ( bSound ) 700 if ( bSound )
699 killTimer( stopTimer ); 701 killTimer( stopTimer );
700 } 702 }
701 } 703 }
702 } else if ( msg == "nextView()" ) { 704 } else if ( msg == "nextView()" ) {
703 needShow = true; 705 needShow = true;
704 if ( !qApp-> activeWindow ( )) { 706 if ( !qApp-> activeWindow ( )) {
705 needShow = TRUE; 707 needShow = TRUE;
706 } else { 708 } else {
707 QWidget* cur = views->visibleWidget(); 709 QWidget* cur = views->visibleWidget();
708 if ( cur ) { 710 if ( cur ) {
709 if ( cur == dayView ) 711 if ( cur == dayView )
710 viewWeek(); 712 viewWeek();
711 else if ( cur == weekView ) 713 else if ( cur == weekView )
712 viewWeekLst(); 714 viewWeekLst();
713 else if ( cur == weekLstView ) 715 else if ( cur == weekLstView )
714 viewMonth(); 716 viewMonth();
715 else if ( cur == monthView ) 717 else if ( cur == monthView )
716 viewDay(); 718 viewDay();
717 needShow = TRUE; 719 needShow = TRUE;
718 } 720 }
719 } 721 }
720 } else if (msg == "editEvent(int)") { 722 } else if (msg == "editEvent(int)") {
721 /* simple copy from receive */ 723 /* simple copy from receive */
722 QDataStream stream(data,IO_ReadOnly); 724 QDataStream stream(data,IO_ReadOnly);
723 int uid; 725 int uid;
724 stream >> uid; 726 stream >> uid;
725 Event e=db->eventByUID(uid); 727 Event e=db->eventByUID(uid);
726 editEvent(e); 728 editEvent(e);
727 } else if (msg == "viewDefault(QDate)"){ 729 } else if (msg == "viewDefault(QDate)"){
728 /* simple copy from receive */ 730 /* simple copy from receive */
729 QDataStream stream(data,IO_ReadOnly); 731 QDataStream stream(data,IO_ReadOnly);
730 QDate day; 732 QDate day;
731 stream >> day; 733 stream >> day;
732 viewDefault(day); 734 viewDefault(day);
733 needShow = true; 735 needShow = true;
734 } 736 }
735 737
736 if ( needShow ) { 738 if ( needShow ) {
737#if defined(Q_WS_QWS) || defined(_WS_QWS_) 739#if defined(Q_WS_QWS) || defined(_WS_QWS_)
738// showMaximized(); 740// showMaximized();
739#else 741#else
740// show(); 742// show();
741#endif 743#endif
742// raise(); 744// raise();
743 QPEApplication::setKeepRunning(); 745 QPEApplication::setKeepRunning();
744// setActiveWindow(); 746// setActiveWindow();
745 } 747 }
746} 748}
747 749
748void DateBook::reload() 750void DateBook::reload()
749{ 751{
750 db->reload(); 752 db->reload();
751 if ( dayAction->isOn() ) viewDay(); 753 if ( dayAction->isOn() ) viewDay();
752 else if ( weekAction->isOn() ) viewWeek(); 754 else if ( weekAction->isOn() ) viewWeek();
753 else if ( monthAction->isOn() ) viewMonth(); 755 else if ( monthAction->isOn() ) viewMonth();
754 syncing = FALSE; 756 syncing = FALSE;
755} 757}
756 758
757void DateBook::flush() 759void DateBook::flush()
758{ 760{
759 syncing = TRUE; 761 syncing = TRUE;
760 db->save(); 762 db->save();
761} 763}
762 764
763void DateBook::timerEvent( QTimerEvent *e ) 765void DateBook::timerEvent( QTimerEvent *e )
764{ 766{
765 if ( alarmCounter < 10 ) { 767 if ( alarmCounter < 10 ) {
766 alarmCounter++; 768 alarmCounter++;
767 Sound::soundAlarm(); 769 Sound::soundAlarm();
768 } else { 770 } else {
769 killTimer( e->timerId() ); 771 killTimer( e->timerId() );
770 } 772 }
771} 773}
772 774
773void DateBook::changeClock( bool newClock ) 775void DateBook::changeClock( bool newClock )
774{ 776{
775 ampm = newClock; 777 ampm = newClock;
776 // repaint the affected objects... 778 // repaint the affected objects...
777 if (dayView) dayView->redraw(); 779 if (dayView) dayView->redraw();
778 if (weekView) weekView->redraw(); 780 if (weekView) weekView->redraw();
779 if (weekLstView) weekLstView->redraw(); 781 if (weekLstView) weekLstView->redraw();
780} 782}
781 783
782void DateBook::changeWeek( bool m ) 784void DateBook::changeWeek( bool m )
783{ 785{
784 /* no need to redraw, each widget catches. Do need to 786 /* no need to redraw, each widget catches. Do need to
785 store though for widgets we haven't made yet */ 787 store though for widgets we haven't made yet */
786 onMonday = m; 788 onMonday = m;
787} 789}
788 790
789void DateBook::slotToday() 791void DateBook::slotToday()
790{ 792{
791 // we need to view today using default view 793 // we need to view today using default view
792 view(defaultView,QDate::currentDate()); 794 view(defaultView,QDate::currentDate());
793} 795}
794 796
795void DateBook::closeEvent( QCloseEvent *e ) 797void DateBook::closeEvent( QCloseEvent *e )
796{ 798{
797 if(syncing) { 799 if(syncing) {
798 /* no need to save, did that at flush */ 800 /* no need to save, did that at flush */
799 e->accept(); 801 e->accept();
800 return; 802 return;
801 } 803 }
802 804
803 // save settings will generate it's own error messages, no 805 // save settings will generate it's own error messages, no
804 // need to do checking ourselves. 806 // need to do checking ourselves.
805 saveSettings(); 807 saveSettings();
806 if ( db->save() ) { 808 if ( db->save() ) {
807 e->accept(); 809 e->accept();
808 } else { 810 } else {
809 if ( QMessageBox::critical( this, tr( "Out of space" ), 811 if ( QMessageBox::critical( this, tr( "Out of space" ),
810 tr("Calendar was unable to save\n" 812 tr("Calendar was unable to save\n"
811 "your changes.\n" 813 "your changes.\n"
812 "Free up some space and try again.\n" 814 "Free up some space and try again.\n"
813 "\nQuit anyway?"), 815 "\nQuit anyway?"),
814 QMessageBox::Yes|QMessageBox::Escape, 816 QMessageBox::Yes|QMessageBox::Escape,
815 QMessageBox::No|QMessageBox::Default ) 817 QMessageBox::No|QMessageBox::Default )
816 != QMessageBox::No ) 818 != QMessageBox::No )
817 e->accept(); 819 e->accept();
818 else 820 else
819 e->ignore(); 821 e->ignore();
820 } 822 }
821} 823}
822 824
823// Entering directly from the "keyboard" 825// Entering directly from the "keyboard"
824void DateBook::slotNewEventFromKey( const QString &str ) 826void DateBook::slotNewEventFromKey( const QString &str )
825{ 827{
826 if (syncing) { 828 if (syncing) {
827 QMessageBox::warning( this, tr("Calendar"), 829 QMessageBox::warning( this, tr("Calendar"),
828 tr( "Can not edit data, currently syncing") ); 830 tr( "Can not edit data, currently syncing") );
829 return; 831 return;
830 } 832 }
831 833
832 // We get to here from a key pressed in the Day View 834 // We get to here from a key pressed in the Day View
833 // So we can assume some things. We want the string 835 // So we can assume some things. We want the string
834 // passed in to be part of the description. 836 // passed in to be part of the description.
835 QDateTime start, end; 837 QDateTime start, end;
836 if ( views->visibleWidget() == dayView ) { 838 if ( views->visibleWidget() == dayView ) {
837 dayView->selectedDates( start, end ); 839 dayView->selectedDates( start, end );
838 } else if ( views->visibleWidget() == monthView ) { 840 } else if ( views->visibleWidget() == monthView ) {
839 QDate d = monthView->selectedDate(); 841 QDate d = monthView->selectedDate();
840 start = end = d; 842 start = end = d;
841 start.setTime( QTime( 10, 0 ) ); 843 start.setTime( QTime( 10, 0 ) );
842 end.setTime( QTime( 12, 0 ) ); 844 end.setTime( QTime( 12, 0 ) );
843 } else if ( views->visibleWidget() == weekView ) { 845 } else if ( views->visibleWidget() == weekView ) {
844 QDate d = weekView->date(); 846 QDate d = weekView->date();
845 start = end = d; 847 start = end = d;
846 start.setTime( QTime( 10, 0 ) ); 848 start.setTime( QTime( 10, 0 ) );
847 end.setTime( QTime( 12, 0 ) ); 849 end.setTime( QTime( 12, 0 ) );
848 } else if ( views->visibleWidget() == weekLstView ) { 850 } else if ( views->visibleWidget() == weekLstView ) {
849 QDate d = weekLstView->date(); 851 QDate d = weekLstView->date();
850 start = end = d; 852 start = end = d;
851 start.setTime( QTime( 10, 0 ) ); 853 start.setTime( QTime( 10, 0 ) );
852 end.setTime( QTime( 12, 0 ) ); 854 end.setTime( QTime( 12, 0 ) );
853 } 855 }
854 slotNewEntry(start, end, str); 856 slotNewEntry(start, end, str);
855} 857}
856void DateBook::slotNewEntry(const QDateTime &start, const QDateTime &end, const QString &str, const QString &location) { 858void DateBook::slotNewEntry(const QDateTime &start, const QDateTime &end, const QString &str, const QString &location) {
857 // argh! This really needs to be encapsulated in a class 859 // argh! This really needs to be encapsulated in a class
858 // or function. 860 // or function.
859 QDialog newDlg( this, 0, TRUE ); 861 QDialog newDlg( this, 0, TRUE );
860 newDlg.setCaption( DateEntryBase::tr("New Event") ); 862 newDlg.setCaption( DateEntryBase::tr("New Event") );
861 DateEntry *e; 863 DateEntry *e;
862 QVBoxLayout *vb = new QVBoxLayout( &newDlg ); 864 QVBoxLayout *vb = new QVBoxLayout( &newDlg );
863 QScrollView *sv = new QScrollView( &newDlg ); 865 QScrollView *sv = new QScrollView( &newDlg );
864 sv->setResizePolicy( QScrollView::AutoOneFit ); 866 sv->setResizePolicy( QScrollView::AutoOneFit );
865 sv->setFrameStyle( QFrame::NoFrame ); 867 sv->setFrameStyle( QFrame::NoFrame );
866 sv->setHScrollBarMode( QScrollView::AlwaysOff ); 868 sv->setHScrollBarMode( QScrollView::AlwaysOff );
867 vb->addWidget( sv ); 869 vb->addWidget( sv );
868 870
869 Event ev; 871 Event ev;
870 ev.setDescription( str ); 872 ev.setDescription( str );
871 // When the new gui comes in, change this... 873 // When the new gui comes in, change this...
872 if(location==0) { 874 if(location==0) {
873 if(defaultLocation.isEmpty()) { 875 if(defaultLocation.isEmpty()) {
874 ev.setLocation(tr("(Unknown)")); 876 ev.setLocation(tr("(Unknown)"));
875 } else { 877 } else {
876 ev.setLocation( defaultLocation ); 878 ev.setLocation( defaultLocation );
877 } 879 }
878 } else { 880 } else {
879 ev.setLocation(location); 881 ev.setLocation(location);
880 } 882 }
881 ev.setCategories(defaultCategories); 883 ev.setCategories(defaultCategories);
882 ev.setStart( start ); 884 ev.setStart( start );
883 ev.setEnd( end ); 885 ev.setEnd( end );
884 886
885 e = new DateEntry( onMonday, ev, ampm, &newDlg ); 887 e = new DateEntry( onMonday, ev, ampm, &newDlg );
886 e->setAlarmEnabled( aPreset, presetTime, Event::Loud ); 888 e->setAlarmEnabled( aPreset, presetTime, Event::Loud );
887 sv->addChild( e ); 889 sv->addChild( e );
888 while ( QPEApplication::execDialog( &newDlg ) ) { 890 while ( QPEApplication::execDialog( &newDlg ) ) {
889 ev = e->event(); 891 ev = e->event();
890 ev.assignUid(); 892 ev.assignUid();
891 QString error = checkEvent( ev ); 893 QString error = checkEvent( ev );
892 if ( !error.isNull() ) { 894 if ( !error.isNull() ) {
893 if ( QMessageBox::warning( this, tr("Error!"), error, tr("Fix it"), tr("Continue"), 0, 0, 1 ) == 0 ) 895 if ( QMessageBox::warning( this, tr("Error!"), error, tr("Fix it"), tr("Continue"), 0, 0, 1 ) == 0 )
894 continue; 896 continue;
895 } 897 }
896 db->addEvent( ev ); 898 db->addEvent( ev );
897 emit newEvent(); 899 emit newEvent();
898 break; 900 break;
899 } 901 }
900} 902}
901 903
902void DateBook::setDocument( const QString &filename ) 904void DateBook::setDocument( const QString &filename )
903{ 905{
904 if ( filename.find(".vcs") != int(filename.length()) - 4 ) return; 906 if ( filename.find(".vcs") != int(filename.length()) - 4 ) return;
905 907
906 QValueList<Event> tl = Event::readVCalendar( filename ); 908 QValueList<Event> tl = Event::readVCalendar( filename );
907 for( QValueList<Event>::Iterator it = tl.begin(); it != tl.end(); ++it ) { 909 for( QValueList<Event>::Iterator it = tl.begin(); it != tl.end(); ++it ) {
908 db->addEvent( *it ); 910 db->addEvent( *it );
909 } 911 }
910} 912}
911 913
912static const char * beamfile = "/tmp/obex/event.vcs"; 914static const char * beamfile = "/tmp/obex/event.vcs";
913 915
914void DateBook::beamEvent( const Event &e ) 916void DateBook::beamEvent( const Event &e )
915{ 917{
916 odebug << "trying to beam" << oendl; 918 odebug << "trying to beam" << oendl;
917 unlink( beamfile ); // delete if exists 919 unlink( beamfile ); // delete if exists
918 mkdir("/tmp/obex/", 0755); 920 mkdir("/tmp/obex/", 0755);
919 Event::writeVCalendar( beamfile, e ); 921 Event::writeVCalendar( beamfile, e );
920 Ir *ir = new Ir( this ); 922 Ir *ir = new Ir( this );
921 connect( ir, SIGNAL( done(Ir*) ), this, SLOT( beamDone(Ir*) ) ); 923 connect( ir, SIGNAL( done(Ir*) ), this, SLOT( beamDone(Ir*) ) );
922 QString description = e.description(); 924 QString description = e.description();
923 ir->send( beamfile, description, "text/x-vCalendar" ); 925 ir->send( beamfile, description, "text/x-vCalendar" );
924} 926}
925 927
926void DateBook::beamDone( Ir *ir ) 928void DateBook::beamDone( Ir *ir )
927{ 929{
928 delete ir; 930 delete ir;
929 unlink( beamfile ); 931 unlink( beamfile );
930} 932}
931 933
932void DateBook::slotFind() 934void DateBook::slotFind()
933{ 935{
934 // move it to the day view... 936 // move it to the day view...
935 viewDay(); 937 viewDay();
936 FindDialog frmFind( "Calendar", this ); // no tr needed 938 FindDialog frmFind( "Calendar", this ); // no tr needed
937 frmFind.setUseDate( true ); 939 frmFind.setUseDate( true );
938 frmFind.setDate( currentDate() ); 940 frmFind.setDate( currentDate() );
939 QObject::connect( &frmFind, 941 QObject::connect( &frmFind,
940 SIGNAL(signalFindClicked(const QString&,const QDate&,bool,bool,int)), 942 SIGNAL(signalFindClicked(const QString&,const QDate&,bool,bool,int)),
941 this, 943 this,
942 SLOT(slotDoFind(const QString&,const QDate&,bool,bool,int)) ); 944 SLOT(slotDoFind(const QString&,const QDate&,bool,bool,int)) );
943 QObject::connect( this, 945 QObject::connect( this,
944 SIGNAL(signalNotFound()), 946 SIGNAL(signalNotFound()),
945 &frmFind, 947 &frmFind,
946 SLOT(slotNotFound()) ); 948 SLOT(slotNotFound()) );
947 QObject::connect( this, 949 QObject::connect( this,
948 SIGNAL(signalWrapAround()), 950 SIGNAL(signalWrapAround()),
949 &frmFind, 951 &frmFind,
950 SLOT(slotWrapAround()) ); 952 SLOT(slotWrapAround()) );
951 frmFind.move(0,0); 953 frmFind.move(0,0);
952 frmFind.exec(); 954 frmFind.exec();
953 inSearch = false; 955 inSearch = false;
954} 956}
955 957
956bool catComp( QArray<int> cats, int category ) 958bool catComp( QArray<int> cats, int category )
957{ 959{
958 bool returnMe; 960 bool returnMe;
959 int i, 961 int i,
960 count; 962 count;
961 963
962 count = int(cats.count()); 964 count = int(cats.count());
963 returnMe = false; 965 returnMe = false;
964 if ( (category == -1 && count == 0) || category == -2 ) 966 if ( (category == -1 && count == 0) || category == -2 )
965 returnMe = true; 967 returnMe = true;
966 else { 968 else {
967 for ( i = 0; i < count; i++ ) { 969 for ( i = 0; i < count; i++ ) {
968 if ( category == cats[i] ) { 970 if ( category == cats[i] ) {
969 returnMe = true; 971 returnMe = true;
970 break; 972 break;
971 } 973 }
972 } 974 }
973 } 975 }
974 return returnMe; 976 return returnMe;
975} 977}
976 978
977 979
978void DateBook::slotDoFind( const QString& txt, const QDate &dt, 980void DateBook::slotDoFind( const QString& txt, const QDate &dt,
979 bool caseSensitive, bool /*backwards*/, 981 bool caseSensitive, bool /*backwards*/,
980 int category ) 982 int category )
981{ 983{
982 QDateTime dtEnd( QDate(3001, 1, 1), QTime(0, 0, 0) ), 984 QDateTime dtEnd( QDate(3001, 1, 1), QTime(0, 0, 0) ),
983 next; 985 next;
984 986
985 QRegExp r( txt ); 987 QRegExp r( txt );
986 r.setCaseSensitive( caseSensitive ); 988 r.setCaseSensitive( caseSensitive );
987 989
988 990
989 static Event rev, nonrev; 991 static Event rev, nonrev;
990 if ( !inSearch ) { 992 if ( !inSearch ) {
991 rev.setStart( QDateTime(QDate(1960, 1, 1), QTime(0, 0, 0)) ); 993 rev.setStart( QDateTime(QDate(1960, 1, 1), QTime(0, 0, 0)) );
992 nonrev.setStart( rev.start() ); 994 nonrev.setStart( rev.start() );
993 inSearch = true; 995 inSearch = true;
994 } 996 }
995 static QDate searchDate = dt; 997 static QDate searchDate = dt;
996 // if true at the end we will start at the begin again and afterwards 998 // if true at the end we will start at the begin again and afterwards
997 // we will emit string not found 999 // we will emit string not found
998 static bool wrapAround = true; 1000 static bool wrapAround = true;
999 bool candidtate; 1001 bool candidtate;
1000 candidtate = false; 1002 candidtate = false;
1001 1003
1002 QValueList<Event> repeats = db->getRawRepeats(); 1004 QValueList<Event> repeats = db->getRawRepeats();
1003 1005
1004 // find the candidate for the first repeat that matches... 1006 // find the candidate for the first repeat that matches...
1005 // first check if there can ever be a match and then compute 1007 // first check if there can ever be a match and then compute
1006 // the next occurence from start. See if this event is closer 1008 // the next occurence from start. See if this event is closer
1007 // to the beginning (start. next < dtEnd) and not smaller then the last 1009 // to the beginning (start. next < dtEnd) and not smaller then the last
1008 // result. If we find a canditate we set the dtEnd to the time 1010 // result. If we find a canditate we set the dtEnd to the time
1009 // of the ocurrence and rev to this occurence. 1011 // of the ocurrence and rev to this occurence.
1010 // set wrap around to true because there might be more events coming 1012 // set wrap around to true because there might be more events coming
1011 // and we're not at the end. 1013 // and we're not at the end.
1012 QValueListConstIterator<Event> it; 1014 QValueListConstIterator<Event> it;
1013 QDate start = dt; 1015 QDate start = dt;
1014 for ( it = repeats.begin(); it != repeats.end(); ++it ) { 1016 for ( it = repeats.begin(); it != repeats.end(); ++it ) {
1015 if ( catComp( (*it).categories(), category ) ) { 1017 if ( catComp( (*it).categories(), category ) ) {
1016 if ( (*it).match( r ) ) { 1018 if ( (*it).match( r ) ) {
1017 if ( nextOccurance( *it, start, next ) ) { 1019 if ( nextOccurance( *it, start, next ) ) {
1018 if ( next < dtEnd && !(next <= rev.start() ) ) { 1020 if ( next < dtEnd && !(next <= rev.start() ) ) {
1019 rev = *it; 1021 rev = *it;
1020 dtEnd = next; 1022 dtEnd = next;
1021 rev.setStart( next ); 1023 rev.setStart( next );
1022 candidtate = true; 1024 candidtate = true;
1023 wrapAround = true; 1025 wrapAround = true;
1024 } 1026 }
1025 } 1027 }
1026 } 1028 }
1027 } 1029 }
1028 } 1030 }
1029 1031
1030 // now the for first non repeat... 1032 // now the for first non repeat...
1031 // dtEnd is set by the previous iteration of repeatingEvents 1033 // dtEnd is set by the previous iteration of repeatingEvents
1032 // check if we find a closer item. Also set dtEnd to find even 1034 // check if we find a closer item. Also set dtEnd to find even
1033 // more close occurrence 1035 // more close occurrence
1034 QValueList<Event> nonRepeats = db->getNonRepeatingEvents( dt, dtEnd.date() ); 1036 QValueList<Event> nonRepeats = db->getNonRepeatingEvents( dt, dtEnd.date() );
1035 qHeapSort( nonRepeats.begin(), nonRepeats.end() ); 1037 qHeapSort( nonRepeats.begin(), nonRepeats.end() );
1036 for ( it = nonRepeats.begin(); it != nonRepeats.end(); ++it ) { 1038 for ( it = nonRepeats.begin(); it != nonRepeats.end(); ++it ) {
1037 if ( catComp( (*it).categories(), category ) ) { 1039 if ( catComp( (*it).categories(), category ) ) {
1038 if ( (*it).start() < dtEnd ) { 1040 if ( (*it).start() < dtEnd ) {
1039 if ( (*it).match( r ) && !(*it <= nonrev) ) { 1041 if ( (*it).match( r ) && !(*it <= nonrev) ) {
1040 nonrev = *it; 1042 nonrev = *it;
1041 dtEnd = nonrev.start(); 1043 dtEnd = nonrev.start();
1042 candidtate = true; 1044 candidtate = true;
1043 wrapAround = true; 1045 wrapAround = true;
1044 break; 1046 break;
1045 } 1047 }
1046 } 1048 }
1047 } 1049 }
1048 } 1050 }
1049 if ( candidtate ) { 1051 if ( candidtate ) {
1050 dayView->setStartViewTime( dtEnd.time().hour() ); 1052 dayView->setStartViewTime( dtEnd.time().hour() );
1051 dayView->setDate( dtEnd.date().year(), dtEnd.date().month(), 1053 dayView->setDate( dtEnd.date().year(), dtEnd.date().month(),
1052 dtEnd.date().day() ); 1054 dtEnd.date().day() );
1053 } else { 1055 } else {
1054 if ( wrapAround ) { 1056 if ( wrapAround ) {
1055 emit signalWrapAround(); 1057 emit signalWrapAround();
1056 rev.setStart( QDateTime(QDate(1960, 1, 1), QTime(0, 0, 0)) ); 1058 rev.setStart( QDateTime(QDate(1960, 1, 1), QTime(0, 0, 0)) );
1057 nonrev.setStart( rev.start() ); 1059 nonrev.setStart( rev.start() );
1058 } else 1060 } else
1059 emit signalNotFound(); 1061 emit signalNotFound();
1060 wrapAround = !wrapAround; 1062 wrapAround = !wrapAround;
1061 } 1063 }
1062} 1064}
1063 1065
1064Event DateBookDBHack::eventByUID(int uid) { 1066Event DateBookDBHack::eventByUID(int uid) {
1065 1067
1066 // FIXME: Dirty Hacks to get hold of the private event lists 1068 // FIXME: Dirty Hacks to get hold of the private event lists
1067 QDate start; 1069 QDate start;
1068 QDate end=start.addDays(-1); 1070 QDate end=start.addDays(-1);
1069 QValueList<Event> myEventList=getNonRepeatingEvents(start,end); 1071 QValueList<Event> myEventList=getNonRepeatingEvents(start,end);
1070 QValueList<Event> myRepeatEvents=getRawRepeats(); 1072 QValueList<Event> myRepeatEvents=getRawRepeats();
1071 1073
1072 QValueList<Event>::ConstIterator it; 1074 QValueList<Event>::ConstIterator it;
1073 1075
1074 for (it = myEventList.begin(); it != myEventList.end(); it++) { 1076 for (it = myEventList.begin(); it != myEventList.end(); it++) {
1075 if ((*it).uid() == uid) return *it; 1077 if ((*it).uid() == uid) return *it;
1076 } 1078 }
1077 for (it = myRepeatEvents.begin(); it != myRepeatEvents.end(); it++) { 1079 for (it = myRepeatEvents.begin(); it != myRepeatEvents.end(); it++) {
1078 if ((*it).uid() == uid) return *it; 1080 if ((*it).uid() == uid) return *it;
1079 } 1081 }
1080 1082
1081 Event ev; 1083 Event ev;
1082 return ev; // return at least 1084 return ev; // return at least
1083} 1085}
1084 1086
1085DateBookHoliday::DateBookHoliday() 1087DateBookHoliday::DateBookHoliday()
1086{ 1088{
1087 _pluginlist.clear(); 1089 _pluginlist.clear();
1090 m_pluginLoader = new Opie::Core::OPluginLoader("holidays",false);
1091 m_pluginLoader->setAutoDelete(true);
1088 init(); 1092 init();
1089} 1093}
1090 1094
1091DateBookHoliday::~DateBookHoliday() 1095DateBookHoliday::~DateBookHoliday()
1092{ 1096{
1093 deinit(); 1097 deinit();
1098 delete m_pluginLoader;
1094} 1099}
1095 1100
1096void DateBookHoliday::deinit() 1101void DateBookHoliday::deinit()
1097{ 1102{
1103/*
1098 QValueList<HPlugin*>::Iterator it; 1104 QValueList<HPlugin*>::Iterator it;
1099 for (it=_pluginlist.begin();it!=_pluginlist.end();++it) { 1105 for (it=_pluginlist.begin();it!=_pluginlist.end();++it) {
1100 HPlugin*_pl = *it; 1106 HPlugin*_pl = *it;
1101 // destructs itself? 1107 // destructs itself?
1102 _pl->_if->release(); 1108 _pl->_if->release();
1103 _pl->_lib->unload(); 1109 _pl->_lib->unload();
1104 delete _pl->_lib; 1110 delete _pl->_lib;
1105 delete _pl; 1111 delete _pl;
1106 } 1112 }
1107 _pluginlist.clear(); 1113 _pluginlist.clear();
1114*/
1108} 1115}
1109 1116
1117#if 0
1118void debugLst( const Opie::Core::OPluginItem::List& lst ) {
1119 for ( Opie::Core::OPluginItem::List::ConstIterator it = lst.begin(); it != lst.end(); ++it )
1120 odebug << "Name " << (*it).name() << " " << (*it).path() << " " << (*it).position() << oendl;
1121}
1122#endif
1123
1110void DateBookHoliday::init() 1124void DateBookHoliday::init()
1111{ 1125{
1126#if 0
1112 deinit(); 1127 deinit();
1128#endif
1129 Opie::Core::OPluginItem::List lst = m_pluginLoader->allAvailable( false );
1130// debugLst( lst );
1131 for( Opie::Core::OPluginItem::List::Iterator it = lst.begin(); it != lst.end(); ++it ){
1132 Opie::Datebook::HolidayPluginIf*hif = m_pluginLoader->load<Opie::Datebook::HolidayPluginIf>(*it,IID_HOLIDAY_PLUGIN);
1133 if (hif) {
1134 Opie::Datebook::HolidayPlugin*pl = hif->plugin();
1135 if (pl) {
1136 HPlugin*_pl=new HPlugin;
1137 _pl->_plugin = pl;
1138 odebug << "Found holiday " << pl->description()<<oendl;
1139 _pluginlist.append(_pl);
1140 //_pl->_if = hif;
1141 }
1142 }
1143 }
1144#if 0
1113 QString path = QPEApplication::qpeDir() + "plugins/datebook/holiday"; 1145 QString path = QPEApplication::qpeDir() + "plugins/datebook/holiday";
1114 QDir dir( path, "lib*.so" ); 1146 QDir dir( path, "lib*.so" );
1115 QStringList list = dir.entryList(); 1147 QStringList list = dir.entryList();
1116 QStringList::Iterator it; 1148 QStringList::Iterator it;
1117 for (it=list.begin();it!=list.end();++it) { 1149 for (it=list.begin();it!=list.end();++it) {
1118 Opie::Datebook::HolidayPluginIf*hif = 0; 1150 Opie::Datebook::HolidayPluginIf*hif = 0;
1119 QLibrary*lib=new QLibrary(path+"/"+*it); 1151 QLibrary*lib=new QLibrary(path+"/"+*it);
1120 if ((lib->queryInterface(IID_HOLIDAY_PLUGIN,(QUnknownInterface**)&hif) == QS_OK) && hif) { 1152 if ((lib->queryInterface(IID_HOLIDAY_PLUGIN,(QUnknownInterface**)&hif) == QS_OK) && hif) {
1121 Opie::Datebook::HolidayPlugin*pl = hif->plugin(); 1153 Opie::Datebook::HolidayPlugin*pl = hif->plugin();
1122 if (pl) { 1154 if (pl) {
1123 HPlugin*_pl=new HPlugin; 1155 HPlugin*_pl=new HPlugin;
1124 _pl->_plugin = pl; 1156 _pl->_plugin = pl;
1125 odebug << "Found holiday " << pl->description()<<oendl; 1157 odebug << "Found holiday " << pl->description()<<oendl;
1126 _pl->_lib = lib; 1158 _pl->_lib = lib;
1127 _pl->_if = hif; 1159 _pl->_if = hif;
1128 _pluginlist.append(_pl); 1160 _pluginlist.append(_pl);
1129 } else { 1161 } else {
1130 } 1162 }
1131 } else { 1163 } else {
1132 delete lib; 1164 delete lib;
1133 } 1165 }
1134 } 1166 }
1167#endif
1135} 1168}
1136 1169
1137QStringList DateBookHoliday::holidaylist(const QDate&aDate) 1170QStringList DateBookHoliday::holidaylist(const QDate&aDate)
1138{ 1171{
1139 QStringList ret; 1172 QStringList ret;
1140 QValueList<HPlugin*>::Iterator it; 1173 QValueList<HPlugin*>::Iterator it;
1141 for (it=_pluginlist.begin();it!=_pluginlist.end();++it) { 1174 for (it=_pluginlist.begin();it!=_pluginlist.end();++it) {
1142 HPlugin*_pl = *it; 1175 HPlugin*_pl = *it;
1143 ret+=_pl->_plugin->entries(aDate); 1176 ret+=_pl->_plugin->entries(aDate);
1144 } 1177 }
1145 return ret; 1178 return ret;
1146} 1179}
1147 1180
1148QStringList DateBookHoliday::holidaylist(unsigned year, unsigned month, unsigned day) 1181QStringList DateBookHoliday::holidaylist(unsigned year, unsigned month, unsigned day)
1149{ 1182{
1150 return holidaylist(QDate(year,month,day)); 1183 return holidaylist(QDate(year,month,day));
1151} 1184}
1152 1185
1153QValueList<EffectiveEvent> DateBookHoliday::getEffectiveEvents(const QDate &from,const QDate &to ) 1186QValueList<EffectiveEvent> DateBookHoliday::getEffectiveEvents(const QDate &from,const QDate &to )
1154{ 1187{
1155 QValueList<EffectiveEvent> ret; 1188 QValueList<EffectiveEvent> ret;
1156 QValueList<HPlugin*>::Iterator it; 1189 QValueList<HPlugin*>::Iterator it;
1157 for (it=_pluginlist.begin();it!=_pluginlist.end();++it) { 1190 for (it=_pluginlist.begin();it!=_pluginlist.end();++it) {
1158 HPlugin*_pl = *it; 1191 HPlugin*_pl = *it;
1159 ret+=_pl->_plugin->events(from,to); 1192 ret+=_pl->_plugin->events(from,to);
1160 } 1193 }
1161 return ret; 1194 return ret;
1162} 1195}
1163 1196
1164QValueList<EffectiveEvent> DateBookDBHoliday::getEffectiveEventsNoHoliday(const QDate &from,const QDate &to ) 1197QValueList<EffectiveEvent> DateBookDBHoliday::getEffectiveEventsNoHoliday(const QDate &from,const QDate &to )
1165{ 1198{
1166 return DateBookDBHack::getEffectiveEvents(from,to); 1199 return DateBookDBHack::getEffectiveEvents(from,to);
1167} 1200}
1168 1201
1169QValueList<EffectiveEvent> DateBookDBHoliday::getEffectiveEventsNoHoliday(const QDateTime &start) 1202QValueList<EffectiveEvent> DateBookDBHoliday::getEffectiveEventsNoHoliday(const QDateTime &start)
1170{ 1203{
1171 return DateBookDBHack::getEffectiveEvents(start); 1204 return DateBookDBHack::getEffectiveEvents(start);
1172} 1205}
1173 1206
1174QValueList<EffectiveEvent> DateBookHoliday::getEffectiveEvents(const QDateTime &start) 1207QValueList<EffectiveEvent> DateBookHoliday::getEffectiveEvents(const QDateTime &start)
1175{ 1208{
1176 return getEffectiveEvents(start.date(),start.date()); 1209 return getEffectiveEvents(start.date(),start.date());
1177} 1210}
1178 1211
1179QValueList<EffectiveEvent> DateBookDBHoliday::getEffectiveEvents(const QDate &from,const QDate &to ) 1212QValueList<EffectiveEvent> DateBookDBHoliday::getEffectiveEvents(const QDate &from,const QDate &to )
1180{ 1213{
1181 QValueList<EffectiveEvent> ret; 1214 QValueList<EffectiveEvent> ret;
1182 odebug << "Ueberlagert 1" << oendl; 1215 odebug << "Ueberlagert 1" << oendl;
1183 if (db_holiday) { 1216 if (db_holiday) {
1184 ret+=db_holiday->getEffectiveEvents(from,to); 1217 ret+=db_holiday->getEffectiveEvents(from,to);
1185 } 1218 }
1186 ret+=getEffectiveEventsNoHoliday(from,to); 1219 ret+=getEffectiveEventsNoHoliday(from,to);
1187 return ret; 1220 return ret;
1188} 1221}
1189 1222
1190QValueList<EffectiveEvent> DateBookDBHoliday::getEffectiveEvents( const QDateTime &start) 1223QValueList<EffectiveEvent> DateBookDBHoliday::getEffectiveEvents( const QDateTime &start)
1191{ 1224{
1192 odebug << "Ueberlagert 2" << oendl; 1225 odebug << "Ueberlagert 2" << oendl;
1193 return DateBookDBHack::getEffectiveEvents(start); 1226 return DateBookDBHack::getEffectiveEvents(start);
1194} 1227}
diff --git a/core/pim/datebook/datebooktypes.h b/core/pim/datebook/datebooktypes.h
index 9eb7e89..f944e84 100644
--- a/core/pim/datebook/datebooktypes.h
+++ b/core/pim/datebook/datebooktypes.h
@@ -1,59 +1,63 @@
1#ifndef _DATEBOOK_TYPES_H 1#ifndef _DATEBOOK_TYPES_H
2#define _DATEBOOK_TYPES_H 2#define _DATEBOOK_TYPES_H
3 3
4#include <qpe/datebookdb.h> 4#include <qpe/datebookdb.h>
5 5
6#include <qvaluelist.h> 6#include <qvaluelist.h>
7#include <qstringlist.h> 7#include <qstringlist.h>
8 8
9namespace Opie { 9namespace Opie {
10namespace Datebook { 10namespace Datebook {
11 class HolidayPlugin; 11 class HolidayPlugin;
12 class HolidayPluginIf; 12 class HolidayPluginIf;
13} 13}
14namespace Core {
15 class OPluginLoader;
16}
14} 17}
15 18
16class QLibrary; 19class QLibrary;
17 20
18class DateBookDBHack : virtual public DateBookDB { 21class DateBookDBHack : virtual public DateBookDB {
19 public: 22 public:
20 virtual ~DateBookDBHack(){} 23 virtual ~DateBookDBHack(){}
21 Event eventByUID(int id); 24 Event eventByUID(int id);
22}; 25};
23 26
24class DateBookHoliday 27class DateBookHoliday
25{ 28{
26public: 29public:
27 DateBookHoliday(); 30 DateBookHoliday();
28 virtual ~DateBookHoliday(); 31 virtual ~DateBookHoliday();
29 32
30 QStringList holidaylist(const QDate&); 33 QStringList holidaylist(const QDate&);
31 QStringList holidaylist(unsigned year, unsigned month, unsigned day); 34 QStringList holidaylist(unsigned year, unsigned month, unsigned day);
32 virtual QValueList<EffectiveEvent> getEffectiveEvents(const QDate &from,const QDate &to ); 35 virtual QValueList<EffectiveEvent> getEffectiveEvents(const QDate &from,const QDate &to );
33 virtual QValueList<EffectiveEvent> getEffectiveEvents(const QDateTime &start); 36 virtual QValueList<EffectiveEvent> getEffectiveEvents(const QDateTime &start);
34 37
35protected: 38protected:
36 void init(); 39 void init();
37 void deinit(); 40 void deinit();
38 41
39 struct HPlugin { 42 struct HPlugin {
40 Opie::Datebook::HolidayPlugin*_plugin; 43 Opie::Datebook::HolidayPlugin*_plugin;
41 QLibrary*_lib; 44 //QLibrary*_lib;
42 Opie::Datebook::HolidayPluginIf*_if; 45 //Opie::Datebook::HolidayPluginIf*_if;
43 }; 46 };
44 QValueList<HPlugin*>_pluginlist; 47 QValueList<HPlugin*>_pluginlist;
48 Opie::Core::OPluginLoader*m_pluginLoader;
45}; 49};
46 50
47class DateBookDBHoliday:virtual public DateBookDBHack { 51class DateBookDBHoliday:virtual public DateBookDBHack {
48public: 52public:
49 DateBookDBHoliday():DateBookDBHack(){db_holiday=0;} 53 DateBookDBHoliday():DateBookDBHack(){db_holiday=0;}
50 virtual ~DateBookDBHoliday(){} 54 virtual ~DateBookDBHoliday(){}
51 virtual QValueList<EffectiveEvent> getEffectiveEvents(const QDate &from,const QDate &to ); 55 virtual QValueList<EffectiveEvent> getEffectiveEvents(const QDate &from,const QDate &to );
52 virtual QValueList<EffectiveEvent> getEffectiveEvents(const QDateTime &start); 56 virtual QValueList<EffectiveEvent> getEffectiveEvents(const QDateTime &start);
53 virtual QValueList<EffectiveEvent> getEffectiveEventsNoHoliday(const QDate &from,const QDate &to ); 57 virtual QValueList<EffectiveEvent> getEffectiveEventsNoHoliday(const QDate &from,const QDate &to );
54 virtual QValueList<EffectiveEvent> getEffectiveEventsNoHoliday(const QDateTime &start); 58 virtual QValueList<EffectiveEvent> getEffectiveEventsNoHoliday(const QDateTime &start);
55 59
56 DateBookHoliday*db_holiday; 60 DateBookHoliday*db_holiday;
57}; 61};
58 62
59#endif 63#endif