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