author | hakan <hakan> | 2002-03-31 12:56:14 (UTC) |
---|---|---|
committer | hakan <hakan> | 2002-03-31 12:56:14 (UTC) |
commit | 7208583b0b7ff339e6019b188332d8bcb8f30973 (patch) (unidiff) | |
tree | 4d0b064f1aa0a8553703af4f6e481393cf0ee13c | |
parent | a386e428cbd6b468d4dbff5bf2df4fdba6df9b6e (diff) | |
download | opie-7208583b0b7ff339e6019b188332d8bcb8f30973.zip opie-7208583b0b7ff339e6019b188332d8bcb8f30973.tar.gz opie-7208583b0b7ff339e6019b188332d8bcb8f30973.tar.bz2 |
Moved getEvent(uid) into some hack DateBookDBHack::eventByUID(uid) in the datbeook that might work as long as the QDate implementation are not chnaged.
-rw-r--r-- | core/pim/datebook/datebook.cpp | 25 | ||||
-rw-r--r-- | core/pim/datebook/datebook.h | 7 | ||||
-rw-r--r-- | library/datebookdb.cpp | 14 | ||||
-rw-r--r-- | library/datebookdb.h | 1 |
4 files changed, 29 insertions, 18 deletions
diff --git a/core/pim/datebook/datebook.cpp b/core/pim/datebook/datebook.cpp index 97c305c..c23129a 100644 --- a/core/pim/datebook/datebook.cpp +++ b/core/pim/datebook/datebook.cpp | |||
@@ -1,967 +1,988 @@ | |||
1 | /********************************************************************** | 1 | /********************************************************************** |
2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. | 2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. |
3 | ** | 3 | ** |
4 | ** This file is part of Qtopia Environment. | 4 | ** This file is part of Qtopia Environment. |
5 | ** | 5 | ** |
6 | ** This file may be distributed and/or modified under the terms of the | 6 | ** This file may be distributed and/or modified under the terms of the |
7 | ** GNU General Public License version 2 as published by the Free Software | 7 | ** GNU General Public License version 2 as published by the Free Software |
8 | ** Foundation and appearing in the file LICENSE.GPL included in the | 8 | ** Foundation and appearing in the file LICENSE.GPL included in the |
9 | ** packaging of this file. | 9 | ** packaging of this file. |
10 | ** | 10 | ** |
11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | 11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE |
12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | 12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
13 | ** | 13 | ** |
14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | 14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. |
15 | ** | 15 | ** |
16 | ** Contact info@trolltech.com if any conditions of this licensing are | 16 | ** Contact info@trolltech.com if any conditions of this licensing are |
17 | ** not clear to you. | 17 | ** not clear to you. |
18 | ** | 18 | ** |
19 | ** $Id$ | 19 | ** $Id$ |
20 | ** | 20 | ** |
21 | **********************************************************************/ | 21 | **********************************************************************/ |
22 | 22 | ||
23 | #define QTOPIA_INTERNAL_FD | 23 | #define QTOPIA_INTERNAL_FD |
24 | 24 | ||
25 | #include "datebook.h" | 25 | #include "datebook.h" |
26 | #include "datebookday.h" | 26 | #include "datebookday.h" |
27 | #include "datebooksettings.h" | 27 | #include "datebooksettings.h" |
28 | #include "datebookweek.h" | 28 | #include "datebookweek.h" |
29 | #include "datebookweeklst.h" | 29 | #include "datebookweeklst.h" |
30 | #include "dateentryimpl.h" | 30 | #include "dateentryimpl.h" |
31 | 31 | ||
32 | #include <qpe/datebookmonth.h> | 32 | #include <qpe/datebookmonth.h> |
33 | #include <qpe/qpeapplication.h> | 33 | #include <qpe/qpeapplication.h> |
34 | #include <qpe/config.h> | 34 | #include <qpe/config.h> |
35 | #include <qpe/qpedebug.h> | 35 | #include <qpe/qpedebug.h> |
36 | #include <qpe/event.h> | 36 | #include <qpe/event.h> |
37 | #include <qpe/finddialog.h> | 37 | #include <qpe/finddialog.h> |
38 | #include <qpe/ir.h> | 38 | #include <qpe/ir.h> |
39 | #include <qpe/qpemenubar.h> | 39 | #include <qpe/qpemenubar.h> |
40 | #include <qpe/qpemessagebox.h> | 40 | #include <qpe/qpemessagebox.h> |
41 | #include <qpe/resource.h> | 41 | #include <qpe/resource.h> |
42 | #include <qpe/sound.h> | 42 | #include <qpe/sound.h> |
43 | #include <qpe/timestring.h> | 43 | #include <qpe/timestring.h> |
44 | #include <qpe/qpetoolbar.h> | 44 | #include <qpe/qpetoolbar.h> |
45 | #include <qpe/tzselect.h> | 45 | #include <qpe/tzselect.h> |
46 | #include <qpe/xmlreader.h> | 46 | #include <qpe/xmlreader.h> |
47 | 47 | ||
48 | #include <qaction.h> | 48 | #include <qaction.h> |
49 | #include <qcopchannel_qws.h> | 49 | #include <qcopchannel_qws.h> |
50 | #include <qdatetime.h> | 50 | #include <qdatetime.h> |
51 | #include <qdialog.h> | 51 | #include <qdialog.h> |
52 | #include <qfile.h> | 52 | #include <qfile.h> |
53 | #include <qlabel.h> | 53 | #include <qlabel.h> |
54 | #include <qlayout.h> | 54 | #include <qlayout.h> |
55 | #include <qmessagebox.h> | 55 | #include <qmessagebox.h> |
56 | #include <qpopupmenu.h> | 56 | #include <qpopupmenu.h> |
57 | #include <qpushbutton.h> | 57 | #include <qpushbutton.h> |
58 | #include <qtextcodec.h> | 58 | #include <qtextcodec.h> |
59 | #include <qtextstream.h> | 59 | #include <qtextstream.h> |
60 | #include <qtl.h> | 60 | #include <qtl.h> |
61 | #include <qwidgetstack.h> | 61 | #include <qwidgetstack.h> |
62 | #include <qwindowsystem_qws.h> | 62 | #include <qwindowsystem_qws.h> |
63 | 63 | ||
64 | #include <sys/stat.h> | 64 | #include <sys/stat.h> |
65 | #include <sys/types.h> | 65 | #include <sys/types.h> |
66 | #include <fcntl.h> | 66 | #include <fcntl.h> |
67 | #include <unistd.h> | 67 | #include <unistd.h> |
68 | 68 | ||
69 | #include <stdlib.h> | 69 | #include <stdlib.h> |
70 | 70 | ||
71 | #define DAY 1 | 71 | #define DAY 1 |
72 | #define WEEK 2 | 72 | #define WEEK 2 |
73 | #define WEEKLST 4 | 73 | #define WEEKLST 4 |
74 | #define MONTH 3 | 74 | #define MONTH 3 |
75 | 75 | ||
76 | 76 | ||
77 | DateBook::DateBook( QWidget *parent, const char *, WFlags f ) | 77 | DateBook::DateBook( QWidget *parent, const char *, WFlags f ) |
78 | : QMainWindow( parent, "datebook", f ), | 78 | : QMainWindow( parent, "datebook", f ), |
79 | aPreset( FALSE ), | 79 | aPreset( FALSE ), |
80 | presetTime( -1 ), | 80 | presetTime( -1 ), |
81 | startTime( 8 ), // an acceptable default | 81 | startTime( 8 ), // an acceptable default |
82 | syncing(FALSE), | 82 | syncing(FALSE), |
83 | inSearch(FALSE) | 83 | inSearch(FALSE) |
84 | { | 84 | { |
85 | QTime t; | 85 | QTime t; |
86 | t.start(); | 86 | t.start(); |
87 | db = new DateBookDB; | 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 | QPEToolBar *bar = new QPEToolBar( this ); | 103 | QPEToolBar *bar = new QPEToolBar( this ); |
104 | bar->setHorizontalStretchable( TRUE ); | 104 | bar->setHorizontalStretchable( TRUE ); |
105 | 105 | ||
106 | QPEMenuBar *mb = new QPEMenuBar( bar ); | 106 | QPEMenuBar *mb = new QPEMenuBar( bar ); |
107 | mb->setMargin( 0 ); | 107 | mb->setMargin( 0 ); |
108 | 108 | ||
109 | QPEToolBar *sub_bar = new QPEToolBar(this); | 109 | QPEToolBar *sub_bar = new QPEToolBar(this); |
110 | 110 | ||
111 | QPopupMenu *view = new QPopupMenu( this ); | 111 | QPopupMenu *view = new QPopupMenu( this ); |
112 | QPopupMenu *settings = new QPopupMenu( this ); | 112 | QPopupMenu *settings = new QPopupMenu( this ); |
113 | 113 | ||
114 | mb->insertItem( tr( "View" ), view ); | 114 | mb->insertItem( tr( "View" ), view ); |
115 | mb->insertItem( tr( "Settings" ), settings ); | 115 | mb->insertItem( tr( "Settings" ), settings ); |
116 | 116 | ||
117 | QActionGroup *g = new QActionGroup( this ); | 117 | QActionGroup *g = new QActionGroup( this ); |
118 | g->setExclusive( TRUE ); | 118 | g->setExclusive( TRUE ); |
119 | 119 | ||
120 | QAction *a = new QAction( tr( "New" ), Resource::loadPixmap( "new" ), | 120 | QAction *a = new QAction( tr( "New" ), Resource::loadPixmap( "new" ), |
121 | QString::null, 0, this, 0 ); | 121 | QString::null, 0, this, 0 ); |
122 | connect( a, SIGNAL( activated() ), this, SLOT( fileNew() ) ); | 122 | connect( a, SIGNAL( activated() ), this, SLOT( fileNew() ) ); |
123 | a->addTo( sub_bar ); | 123 | a->addTo( sub_bar ); |
124 | 124 | ||
125 | a = new QAction( tr( "Today" ), Resource::loadPixmap( "to_day" ), QString::null, 0, g, 0 ); | 125 | a = new QAction( tr( "Today" ), Resource::loadPixmap( "to_day" ), QString::null, 0, g, 0 ); |
126 | connect( a, SIGNAL( activated() ), this, SLOT( slotToday() ) ); | 126 | connect( a, SIGNAL( activated() ), this, SLOT( slotToday() ) ); |
127 | a->addTo( sub_bar ); | 127 | a->addTo( sub_bar ); |
128 | a->addTo( view ); | 128 | a->addTo( view ); |
129 | 129 | ||
130 | a = new QAction( tr( "Day" ), Resource::loadPixmap( "day" ), QString::null, 0, g, 0 ); | 130 | a = new QAction( tr( "Day" ), Resource::loadPixmap( "day" ), QString::null, 0, g, 0 ); |
131 | connect( a, SIGNAL( activated() ), this, SLOT( viewDay() ) ); | 131 | connect( a, SIGNAL( activated() ), this, SLOT( viewDay() ) ); |
132 | a->addTo( sub_bar ); | 132 | a->addTo( sub_bar ); |
133 | a->addTo( view ); | 133 | a->addTo( view ); |
134 | a->setToggleAction( TRUE ); | 134 | a->setToggleAction( TRUE ); |
135 | a->setOn( TRUE ); | 135 | a->setOn( TRUE ); |
136 | dayAction = a; | 136 | dayAction = a; |
137 | 137 | ||
138 | a = new QAction( tr( "Week" ), Resource::loadPixmap( "week" ), QString::null, 0, g, 0 ); | 138 | a = new QAction( tr( "Week" ), Resource::loadPixmap( "week" ), QString::null, 0, g, 0 ); |
139 | connect( a, SIGNAL( activated() ), this, SLOT( viewWeek() ) ); | 139 | connect( a, SIGNAL( activated() ), this, SLOT( viewWeek() ) ); |
140 | a->addTo( sub_bar ); | 140 | a->addTo( sub_bar ); |
141 | a->addTo( view ); | 141 | a->addTo( view ); |
142 | a->setToggleAction( TRUE ); | 142 | a->setToggleAction( TRUE ); |
143 | weekAction = a; | 143 | weekAction = a; |
144 | 144 | ||
145 | a = new QAction( tr( "WeekLst" ), Resource::loadPixmap( "weeklst" ), QString::null, 0, g, 0 ); | 145 | a = new QAction( tr( "WeekLst" ), Resource::loadPixmap( "weeklst" ), QString::null, 0, g, 0 ); |
146 | connect( a, SIGNAL( activated() ), this, SLOT( viewWeekLst() ) ); | 146 | connect( a, SIGNAL( activated() ), this, SLOT( viewWeekLst() ) ); |
147 | a->addTo( sub_bar ); | 147 | a->addTo( sub_bar ); |
148 | a->addTo( view ); | 148 | a->addTo( view ); |
149 | a->setToggleAction( TRUE ); | 149 | a->setToggleAction( TRUE ); |
150 | weekLstAction = a; | 150 | weekLstAction = a; |
151 | 151 | ||
152 | a = new QAction( tr( "Month" ), Resource::loadPixmap( "month" ), QString::null, 0, g, 0 ); | 152 | a = new QAction( tr( "Month" ), Resource::loadPixmap( "month" ), QString::null, 0, g, 0 ); |
153 | connect( a, SIGNAL( activated() ), this, SLOT( viewMonth() ) ); | 153 | connect( a, SIGNAL( activated() ), this, SLOT( viewMonth() ) ); |
154 | a->addTo( sub_bar ); | 154 | a->addTo( sub_bar ); |
155 | a->addTo( view ); | 155 | a->addTo( view ); |
156 | a->setToggleAction( TRUE ); | 156 | a->setToggleAction( TRUE ); |
157 | monthAction = a; | 157 | monthAction = a; |
158 | 158 | ||
159 | a = new QAction( tr( "Find" ), Resource::loadPixmap( "mag" ), QString::null, 0, g, 0 ); | 159 | a = new QAction( tr( "Find" ), Resource::loadPixmap( "mag" ), QString::null, 0, g, 0 ); |
160 | connect( a, SIGNAL(activated()), this, SLOT(slotFind()) ); | 160 | connect( a, SIGNAL(activated()), this, SLOT(slotFind()) ); |
161 | a->addTo( sub_bar ); | 161 | a->addTo( sub_bar ); |
162 | 162 | ||
163 | a = new QAction( tr( "Alarm and Start Time..." ), QString::null, 0, 0 ); | 163 | a = new QAction( tr( "Alarm and Start Time..." ), QString::null, 0, 0 ); |
164 | connect( a, SIGNAL( activated() ), this, SLOT( slotSettings() ) ); | 164 | connect( a, SIGNAL( activated() ), this, SLOT( slotSettings() ) ); |
165 | a->addTo( settings ); | 165 | a->addTo( settings ); |
166 | 166 | ||
167 | QPopupMenu *default_view = new QPopupMenu(this); | 167 | QPopupMenu *default_view = new QPopupMenu(this); |
168 | settings->insertItem( tr( "Default View" ),default_view ); | 168 | settings->insertItem( tr( "Default View" ),default_view ); |
169 | default_view->setCheckable(TRUE); | 169 | default_view->setCheckable(TRUE); |
170 | 170 | ||
171 | Config config("DateBook"); | 171 | Config config("DateBook"); |
172 | config.setGroup("Main"); | 172 | config.setGroup("Main"); |
173 | int current=config.readNumEntry("defaultview", DAY); | 173 | int current=config.readNumEntry("defaultview", DAY); |
174 | 174 | ||
175 | QActionGroup *ag = new QActionGroup(this); | 175 | QActionGroup *ag = new QActionGroup(this); |
176 | a = new QAction( tr( "Day" ), QString::null, 0, 0, 0, true ); | 176 | a = new QAction( tr( "Day" ), QString::null, 0, 0, 0, true ); |
177 | if (current==DAY) a->setOn(true), viewDay(); | 177 | if (current==DAY) a->setOn(true), viewDay(); |
178 | ag->insert(a); | 178 | ag->insert(a); |
179 | a = new QAction( tr( "Week" ), QString::null, 0, 0, 0, true ); | 179 | a = new QAction( tr( "Week" ), QString::null, 0, 0, 0, true ); |
180 | if (current==WEEK) a->setOn(true), viewWeek(); | 180 | if (current==WEEK) a->setOn(true), viewWeek(); |
181 | ag->insert(a); | 181 | ag->insert(a); |
182 | a = new QAction( tr( "WeekLst" ), QString::null, 0, 0, 0, true ); | 182 | a = new QAction( tr( "WeekLst" ), QString::null, 0, 0, 0, true ); |
183 | if (current==WEEKLST) a->setOn(true), viewWeekLst(); | 183 | if (current==WEEKLST) a->setOn(true), viewWeekLst(); |
184 | ag->insert(a); | 184 | ag->insert(a); |
185 | a = new QAction( tr( "Month" ), QString::null, 0, 0, 0, true ); | 185 | a = new QAction( tr( "Month" ), QString::null, 0, 0, 0, true ); |
186 | if (current==MONTH) a->setOn(true), viewMonth(); | 186 | if (current==MONTH) a->setOn(true), viewMonth(); |
187 | ag->insert(a); | 187 | ag->insert(a); |
188 | 188 | ||
189 | ag->addTo(default_view); | 189 | ag->addTo(default_view); |
190 | connect(ag, SIGNAL( selected ( QAction * ) ), | 190 | connect(ag, SIGNAL( selected ( QAction * ) ), |
191 | this, SLOT( newDefaultView(QAction *) ) | 191 | this, SLOT( newDefaultView(QAction *) ) |
192 | ); | 192 | ); |
193 | 193 | ||
194 | connect( qApp, SIGNAL(clockChanged(bool)), | 194 | connect( qApp, SIGNAL(clockChanged(bool)), |
195 | this, SLOT(changeClock(bool)) ); | 195 | this, SLOT(changeClock(bool)) ); |
196 | connect( qApp, SIGNAL(weekChanged(bool)), | 196 | connect( qApp, SIGNAL(weekChanged(bool)), |
197 | this, SLOT(changeWeek(bool)) ); | 197 | this, SLOT(changeWeek(bool)) ); |
198 | 198 | ||
199 | #if defined(Q_WS_QWS) && !defined(QT_NO_COP) | 199 | #if defined(Q_WS_QWS) && !defined(QT_NO_COP) |
200 | connect( qApp, SIGNAL(appMessage(const QCString&, const QByteArray&)), | 200 | connect( qApp, SIGNAL(appMessage(const QCString&, const QByteArray&)), |
201 | this, SLOT(appMessage(const QCString&, const QByteArray&)) ); | 201 | this, SLOT(appMessage(const QCString&, const QByteArray&)) ); |
202 | #endif | 202 | #endif |
203 | 203 | ||
204 | // listen on QPE/System | 204 | // listen on QPE/System |
205 | #if defined(Q_WS_QWS) | 205 | #if defined(Q_WS_QWS) |
206 | #if !defined(QT_NO_COP) | 206 | #if !defined(QT_NO_COP) |
207 | QCopChannel *channel = new QCopChannel( "QPE/System", this ); | 207 | QCopChannel *channel = new QCopChannel( "QPE/System", this ); |
208 | connect( channel, SIGNAL(received(const QCString&, const QByteArray&)), | 208 | connect( channel, SIGNAL(received(const QCString&, const QByteArray&)), |
209 | this, SLOT(receive(const QCString&, const QByteArray&)) ); | 209 | this, SLOT(receive(const QCString&, const QByteArray&)) ); |
210 | channel = new QCopChannel( "QPE/Datebook", this ); | 210 | channel = new QCopChannel( "QPE/Datebook", this ); |
211 | connect( channel, SIGNAL(received(const QCString&, const QByteArray&)), | 211 | connect( channel, SIGNAL(received(const QCString&, const QByteArray&)), |
212 | this, SLOT(receive(const QCString&, const QByteArray&)) ); | 212 | this, SLOT(receive(const QCString&, const QByteArray&)) ); |
213 | qDebug("olle\n"); | 213 | qDebug("olle\n"); |
214 | #endif | 214 | #endif |
215 | #endif | 215 | #endif |
216 | 216 | ||
217 | qDebug("done t=%d", t.elapsed() ); | 217 | qDebug("done t=%d", t.elapsed() ); |
218 | 218 | ||
219 | } | 219 | } |
220 | 220 | ||
221 | void DateBook::receive( const QCString &msg, const QByteArray &data ) | 221 | void DateBook::receive( const QCString &msg, const QByteArray &data ) |
222 | { | 222 | { |
223 | QDataStream stream( data, IO_ReadOnly ); | 223 | QDataStream stream( data, IO_ReadOnly ); |
224 | if ( msg == "timeChange(QString)" ) { | 224 | if ( msg == "timeChange(QString)" ) { |
225 | // update active view! | 225 | // update active view! |
226 | if ( dayAction->isOn() ) | 226 | if ( dayAction->isOn() ) |
227 | viewDay(); | 227 | viewDay(); |
228 | else if ( weekAction->isOn() ) | 228 | else if ( weekAction->isOn() ) |
229 | viewWeek(); | 229 | viewWeek(); |
230 | else if ( monthAction->isOn() ) | 230 | else if ( monthAction->isOn() ) |
231 | viewMonth(); | 231 | viewMonth(); |
232 | } | 232 | } |
233 | else if (msg == "editEvent(int)") { | 233 | else if (msg == "editEvent(int)") { |
234 | int uid; | 234 | int uid; |
235 | stream >> uid; | 235 | stream >> uid; |
236 | Event e=db->getEvent(uid); | 236 | Event e=db->eventByUID(uid); |
237 | editEvent(e); | 237 | editEvent(e); |
238 | } | 238 | } |
239 | } | 239 | } |
240 | 240 | ||
241 | DateBook::~DateBook() | 241 | DateBook::~DateBook() |
242 | { | 242 | { |
243 | } | 243 | } |
244 | 244 | ||
245 | void DateBook::slotSettings() | 245 | void DateBook::slotSettings() |
246 | { | 246 | { |
247 | DateBookSettings frmSettings( ampm, this ); | 247 | DateBookSettings frmSettings( ampm, this ); |
248 | frmSettings.setStartTime( startTime ); | 248 | frmSettings.setStartTime( startTime ); |
249 | frmSettings.setAlarmPreset( aPreset, presetTime ); | 249 | frmSettings.setAlarmPreset( aPreset, presetTime ); |
250 | #if defined (Q_WS_QWS) || defined(_WS_QWS_) | 250 | #if defined (Q_WS_QWS) || defined(_WS_QWS_) |
251 | frmSettings.showMaximized(); | 251 | frmSettings.showMaximized(); |
252 | #endif | 252 | #endif |
253 | 253 | ||
254 | if ( frmSettings.exec() ) { | 254 | if ( frmSettings.exec() ) { |
255 | aPreset = frmSettings.alarmPreset(); | 255 | aPreset = frmSettings.alarmPreset(); |
256 | presetTime = frmSettings.presetTime(); | 256 | presetTime = frmSettings.presetTime(); |
257 | startTime = frmSettings.startTime(); | 257 | startTime = frmSettings.startTime(); |
258 | if ( dayView ) | 258 | if ( dayView ) |
259 | dayView->setStartViewTime( startTime ); | 259 | dayView->setStartViewTime( startTime ); |
260 | if ( weekView ) | 260 | if ( weekView ) |
261 | weekView->setStartViewTime( startTime ); | 261 | weekView->setStartViewTime( startTime ); |
262 | saveSettings(); | 262 | saveSettings(); |
263 | 263 | ||
264 | // make the change obvious | 264 | // make the change obvious |
265 | if ( views->visibleWidget() ) { | 265 | if ( views->visibleWidget() ) { |
266 | if ( views->visibleWidget() == dayView ) | 266 | if ( views->visibleWidget() == dayView ) |
267 | dayView->redraw(); | 267 | dayView->redraw(); |
268 | else if ( views->visibleWidget() == weekView ) | 268 | else if ( views->visibleWidget() == weekView ) |
269 | weekView->redraw(); | 269 | weekView->redraw(); |
270 | } | 270 | } |
271 | } | 271 | } |
272 | } | 272 | } |
273 | 273 | ||
274 | void DateBook::fileNew() | 274 | void DateBook::fileNew() |
275 | { | 275 | { |
276 | slotNewEventFromKey(""); | 276 | slotNewEventFromKey(""); |
277 | } | 277 | } |
278 | 278 | ||
279 | QString DateBook::checkEvent(const Event &e) | 279 | QString DateBook::checkEvent(const Event &e) |
280 | { | 280 | { |
281 | /* check if overlaps with itself */ | 281 | /* check if overlaps with itself */ |
282 | bool checkFailed = FALSE; | 282 | bool checkFailed = FALSE; |
283 | 283 | ||
284 | /* check the next 12 repeats. should catch most problems */ | 284 | /* check the next 12 repeats. should catch most problems */ |
285 | QDate current_date = e.start().date(); | 285 | QDate current_date = e.start().date(); |
286 | Event previous = e; | 286 | Event previous = e; |
287 | for(int i = 0; i < 12; i++) | 287 | for(int i = 0; i < 12; i++) |
288 | { | 288 | { |
289 | QDateTime next; | 289 | QDateTime next; |
290 | if (!nextOccurance(previous, current_date.addDays(1), next)) { | 290 | if (!nextOccurance(previous, current_date.addDays(1), next)) { |
291 | break; // no more repeats | 291 | break; // no more repeats |
292 | } | 292 | } |
293 | if(next < previous.end()) { | 293 | if(next < previous.end()) { |
294 | checkFailed = TRUE; | 294 | checkFailed = TRUE; |
295 | break; | 295 | break; |
296 | } | 296 | } |
297 | current_date = next.date(); | 297 | current_date = next.date(); |
298 | } | 298 | } |
299 | 299 | ||
300 | if(checkFailed) | 300 | if(checkFailed) |
301 | return tr("Event duration is potentially longer\n" | 301 | return tr("Event duration is potentially longer\n" |
302 | "than interval between repeats."); | 302 | "than interval between repeats."); |
303 | 303 | ||
304 | return QString::null; | 304 | return QString::null; |
305 | } | 305 | } |
306 | 306 | ||
307 | QDate DateBook::currentDate() | 307 | QDate DateBook::currentDate() |
308 | { | 308 | { |
309 | QDate d = QDate::currentDate(); | 309 | QDate d = QDate::currentDate(); |
310 | 310 | ||
311 | if ( dayView && views->visibleWidget() == dayView ) { | 311 | if ( dayView && views->visibleWidget() == dayView ) { |
312 | d = dayView->date(); | 312 | d = dayView->date(); |
313 | } else if ( weekView && views->visibleWidget() == weekView ) { | 313 | } else if ( weekView && views->visibleWidget() == weekView ) { |
314 | d = weekView->date(); | 314 | d = weekView->date(); |
315 | } else if ( weekLstView && views->visibleWidget() == weekLstView ) { | 315 | } else if ( weekLstView && views->visibleWidget() == weekLstView ) { |
316 | d = weekLstView->date(); | 316 | d = weekLstView->date(); |
317 | } else if ( monthView && views->visibleWidget() == monthView ) { | 317 | } else if ( monthView && views->visibleWidget() == monthView ) { |
318 | d = monthView->selectedDate(); | 318 | d = monthView->selectedDate(); |
319 | } | 319 | } |
320 | 320 | ||
321 | return d; | 321 | return d; |
322 | } | 322 | } |
323 | 323 | ||
324 | void DateBook::view(int v, const QDate &d) { | 324 | void DateBook::view(int v, const QDate &d) { |
325 | if (v==DAY) { | 325 | if (v==DAY) { |
326 | initDay(); | 326 | initDay(); |
327 | dayAction->setOn( TRUE ); | 327 | dayAction->setOn( TRUE ); |
328 | dayView->setDate( d ); | 328 | dayView->setDate( d ); |
329 | views->raiseWidget( dayView ); | 329 | views->raiseWidget( dayView ); |
330 | dayView->redraw(); | 330 | dayView->redraw(); |
331 | } else if (v==WEEK) { | 331 | } else if (v==WEEK) { |
332 | initWeek(); | 332 | initWeek(); |
333 | weekAction->setOn( TRUE ); | 333 | weekAction->setOn( TRUE ); |
334 | weekView->setDate( d ); | 334 | weekView->setDate( d ); |
335 | views->raiseWidget( weekView ); | 335 | views->raiseWidget( weekView ); |
336 | weekView->redraw(); | 336 | weekView->redraw(); |
337 | } else if (v==WEEKLST) { | 337 | } else if (v==WEEKLST) { |
338 | initWeekLst(); | 338 | initWeekLst(); |
339 | weekLstAction->setOn( TRUE ); | 339 | weekLstAction->setOn( TRUE ); |
340 | weekLstView->setDate(d); | 340 | weekLstView->setDate(d); |
341 | views->raiseWidget( weekLstView ); | 341 | views->raiseWidget( weekLstView ); |
342 | weekLstView->redraw(); | 342 | weekLstView->redraw(); |
343 | } else if (v==MONTH) { | 343 | } else if (v==MONTH) { |
344 | initMonth(); | 344 | initMonth(); |
345 | monthAction->setOn( TRUE ); | 345 | monthAction->setOn( TRUE ); |
346 | monthView->setDate( d.year(), d.month(), d.day() ); | 346 | monthView->setDate( d.year(), d.month(), d.day() ); |
347 | views->raiseWidget( monthView ); | 347 | views->raiseWidget( monthView ); |
348 | monthView->redraw(); | 348 | monthView->redraw(); |
349 | } | 349 | } |
350 | } | 350 | } |
351 | 351 | ||
352 | void DateBook::viewDefault(const QDate &d) { | 352 | void DateBook::viewDefault(const QDate &d) { |
353 | Config config("DateBook"); | 353 | Config config("DateBook"); |
354 | config.setGroup("Main"); | 354 | config.setGroup("Main"); |
355 | int current=config.readNumEntry("defaultview", DAY); | 355 | int current=config.readNumEntry("defaultview", DAY); |
356 | 356 | ||
357 | view(current,d); | 357 | view(current,d); |
358 | } | 358 | } |
359 | 359 | ||
360 | void DateBook::viewDay() { | 360 | void DateBook::viewDay() { |
361 | view(DAY,currentDate()); | 361 | view(DAY,currentDate()); |
362 | } | 362 | } |
363 | 363 | ||
364 | void DateBook::viewWeek() { | 364 | void DateBook::viewWeek() { |
365 | view(WEEK,currentDate()); | 365 | view(WEEK,currentDate()); |
366 | } | 366 | } |
367 | 367 | ||
368 | void DateBook::viewWeekLst() { | 368 | void DateBook::viewWeekLst() { |
369 | view(WEEKLST,currentDate()); | 369 | view(WEEKLST,currentDate()); |
370 | } | 370 | } |
371 | 371 | ||
372 | void DateBook::viewMonth() { | 372 | void DateBook::viewMonth() { |
373 | view(MONTH,currentDate()); | 373 | view(MONTH,currentDate()); |
374 | } | 374 | } |
375 | 375 | ||
376 | void DateBook::editEvent( const Event &e ) | 376 | void DateBook::editEvent( const Event &e ) |
377 | { | 377 | { |
378 | if (syncing) { | 378 | if (syncing) { |
379 | QMessageBox::warning( this, tr("Calendar"), | 379 | QMessageBox::warning( this, tr("Calendar"), |
380 | tr( "Can not edit data, currently syncing") ); | 380 | tr( "Can not edit data, currently syncing") ); |
381 | return; | 381 | return; |
382 | } | 382 | } |
383 | 383 | ||
384 | // workaround added for text input. | 384 | // workaround added for text input. |
385 | QDialog editDlg( this, 0, TRUE ); | 385 | QDialog editDlg( this, 0, TRUE ); |
386 | DateEntry *entry; | 386 | DateEntry *entry; |
387 | editDlg.setCaption( tr("Edit Event") ); | 387 | editDlg.setCaption( tr("Edit Event") ); |
388 | QVBoxLayout *vb = new QVBoxLayout( &editDlg ); | 388 | QVBoxLayout *vb = new QVBoxLayout( &editDlg ); |
389 | QScrollView *sv = new QScrollView( &editDlg, "scrollview" ); | 389 | QScrollView *sv = new QScrollView( &editDlg, "scrollview" ); |
390 | sv->setResizePolicy( QScrollView::AutoOneFit ); | 390 | sv->setResizePolicy( QScrollView::AutoOneFit ); |
391 | // KLUDGE!!! | 391 | // KLUDGE!!! |
392 | sv->setHScrollBarMode( QScrollView::AlwaysOff ); | 392 | sv->setHScrollBarMode( QScrollView::AlwaysOff ); |
393 | vb->addWidget( sv ); | 393 | vb->addWidget( sv ); |
394 | entry = new DateEntry( onMonday, e, ampm, &editDlg, "editor" ); | 394 | entry = new DateEntry( onMonday, e, ampm, &editDlg, "editor" ); |
395 | entry->timezone->setEnabled( FALSE ); | 395 | entry->timezone->setEnabled( FALSE ); |
396 | sv->addChild( entry ); | 396 | sv->addChild( entry ); |
397 | 397 | ||
398 | #if defined(Q_WS_QWS) || defined(_WS_QWS_) | 398 | #if defined(Q_WS_QWS) || defined(_WS_QWS_) |
399 | editDlg.showMaximized(); | 399 | editDlg.showMaximized(); |
400 | #endif | 400 | #endif |
401 | while (editDlg.exec() ) { | 401 | while (editDlg.exec() ) { |
402 | Event newEv = entry->event(); | 402 | Event newEv = entry->event(); |
403 | newEv.setUid(e.uid()); // FIXME: Hack not to clear uid | 403 | newEv.setUid(e.uid()); // FIXME: Hack not to clear uid |
404 | QString error = checkEvent(newEv); | 404 | QString error = checkEvent(newEv); |
405 | if (!error.isNull()) { | 405 | if (!error.isNull()) { |
406 | if (QMessageBox::warning(this, "error box", | 406 | if (QMessageBox::warning(this, "error box", |
407 | error, "Fix it", "Continue", | 407 | error, "Fix it", "Continue", |
408 | 0, 0, 1) == 0) | 408 | 0, 0, 1) == 0) |
409 | continue; | 409 | continue; |
410 | } | 410 | } |
411 | db->editEvent(e, newEv); | 411 | db->editEvent(e, newEv); |
412 | emit newEvent(); | 412 | emit newEvent(); |
413 | break; | 413 | break; |
414 | } | 414 | } |
415 | } | 415 | } |
416 | 416 | ||
417 | void DateBook::removeEvent( const Event &e ) | 417 | void DateBook::removeEvent( const Event &e ) |
418 | { | 418 | { |
419 | if (syncing) { | 419 | if (syncing) { |
420 | QMessageBox::warning( this, tr("Calendar"), | 420 | QMessageBox::warning( this, tr("Calendar"), |
421 | tr( "Can not edit data, currently syncing") ); | 421 | tr( "Can not edit data, currently syncing") ); |
422 | return; | 422 | return; |
423 | } | 423 | } |
424 | 424 | ||
425 | QString strName = e.description(); | 425 | QString strName = e.description(); |
426 | 426 | ||
427 | if ( !QPEMessageBox::confirmDelete( this, tr( "Calendar" ),strName ) ) | 427 | if ( !QPEMessageBox::confirmDelete( this, tr( "Calendar" ),strName ) ) |
428 | return; | 428 | return; |
429 | 429 | ||
430 | db->removeEvent( e ); | 430 | db->removeEvent( e ); |
431 | if ( views->visibleWidget() == dayView && dayView ) | 431 | if ( views->visibleWidget() == dayView && dayView ) |
432 | dayView->redraw(); | 432 | dayView->redraw(); |
433 | } | 433 | } |
434 | 434 | ||
435 | void DateBook::addEvent( const Event &e ) | 435 | void DateBook::addEvent( const Event &e ) |
436 | { | 436 | { |
437 | QDate d = e.start().date(); | 437 | QDate d = e.start().date(); |
438 | initDay(); | 438 | initDay(); |
439 | dayView->setDate( d ); | 439 | dayView->setDate( d ); |
440 | } | 440 | } |
441 | 441 | ||
442 | void DateBook::showDay( int year, int month, int day ) | 442 | void DateBook::showDay( int year, int month, int day ) |
443 | { | 443 | { |
444 | QDate d(year, month, day); | 444 | QDate d(year, month, day); |
445 | view(DAY,d); | 445 | view(DAY,d); |
446 | } | 446 | } |
447 | 447 | ||
448 | void DateBook::initDay() | 448 | void DateBook::initDay() |
449 | { | 449 | { |
450 | if ( !dayView ) { | 450 | if ( !dayView ) { |
451 | dayView = new DateBookDay( ampm, onMonday, db, views, "day view" ); | 451 | dayView = new DateBookDay( ampm, onMonday, db, views, "day view" ); |
452 | views->addWidget( dayView, DAY ); | 452 | views->addWidget( dayView, DAY ); |
453 | dayView->setStartViewTime( startTime ); | 453 | dayView->setStartViewTime( startTime ); |
454 | connect( this, SIGNAL( newEvent() ), | 454 | connect( this, SIGNAL( newEvent() ), |
455 | dayView, SLOT( redraw() ) ); | 455 | dayView, SLOT( redraw() ) ); |
456 | connect( dayView, SIGNAL( newEvent() ), | 456 | connect( dayView, SIGNAL( newEvent() ), |
457 | this, SLOT( fileNew() ) ); | 457 | this, SLOT( fileNew() ) ); |
458 | connect( dayView, SIGNAL( removeEvent( const Event & ) ), | 458 | connect( dayView, SIGNAL( removeEvent( const Event & ) ), |
459 | this, SLOT( removeEvent( const Event & ) ) ); | 459 | this, SLOT( removeEvent( const Event & ) ) ); |
460 | connect( dayView, SIGNAL( editEvent( const Event & ) ), | 460 | connect( dayView, SIGNAL( editEvent( const Event & ) ), |
461 | this, SLOT( editEvent( const Event & ) ) ); | 461 | this, SLOT( editEvent( const Event & ) ) ); |
462 | connect( dayView, SIGNAL( beamEvent( const Event & ) ), | 462 | connect( dayView, SIGNAL( beamEvent( const Event & ) ), |
463 | this, SLOT( beamEvent( const Event & ) ) ); | 463 | this, SLOT( beamEvent( const Event & ) ) ); |
464 | connect( dayView, SIGNAL(sigNewEvent(const QString &)), | 464 | connect( dayView, SIGNAL(sigNewEvent(const QString &)), |
465 | this, SLOT(slotNewEventFromKey(const QString &)) ); | 465 | this, SLOT(slotNewEventFromKey(const QString &)) ); |
466 | } | 466 | } |
467 | } | 467 | } |
468 | 468 | ||
469 | void DateBook::initWeek() | 469 | void DateBook::initWeek() |
470 | { | 470 | { |
471 | if ( !weekView ) { | 471 | if ( !weekView ) { |
472 | weekView = new DateBookWeek( ampm, onMonday, db, views, "week view" ); | 472 | weekView = new DateBookWeek( ampm, onMonday, db, views, "week view" ); |
473 | weekView->setStartViewTime( startTime ); | 473 | weekView->setStartViewTime( startTime ); |
474 | views->addWidget( weekView, WEEK ); | 474 | views->addWidget( weekView, WEEK ); |
475 | connect( weekView, SIGNAL( showDate( int, int, int ) ), | 475 | connect( weekView, SIGNAL( showDate( int, int, int ) ), |
476 | this, SLOT( showDay( int, int, int ) ) ); | 476 | this, SLOT( showDay( int, int, int ) ) ); |
477 | connect( this, SIGNAL( newEvent() ), | 477 | connect( this, SIGNAL( newEvent() ), |
478 | weekView, SLOT( redraw() ) ); | 478 | weekView, SLOT( redraw() ) ); |
479 | } | 479 | } |
480 | //But also get it right: the year that we display can be different | 480 | //But also get it right: the year that we display can be different |
481 | //from the year of the current date. So, first find the year | 481 | //from the year of the current date. So, first find the year |
482 | //number of the current week. | 482 | //number of the current week. |
483 | 483 | ||
484 | int yearNumber, totWeeks; | 484 | int yearNumber, totWeeks; |
485 | calcWeek( currentDate(), totWeeks, yearNumber, onMonday ); | 485 | calcWeek( currentDate(), totWeeks, yearNumber, onMonday ); |
486 | 486 | ||
487 | QDate d = QDate( yearNumber, 12, 31 ); | 487 | QDate d = QDate( yearNumber, 12, 31 ); |
488 | calcWeek( d, totWeeks, yearNumber, onMonday ); | 488 | calcWeek( d, totWeeks, yearNumber, onMonday ); |
489 | 489 | ||
490 | while ( totWeeks == 1 ) { | 490 | while ( totWeeks == 1 ) { |
491 | d = d.addDays( -1 ); | 491 | d = d.addDays( -1 ); |
492 | calcWeek( d, totWeeks, yearNumber, onMonday ); | 492 | calcWeek( d, totWeeks, yearNumber, onMonday ); |
493 | } | 493 | } |
494 | if ( totWeeks != weekView->totalWeeks() ) | 494 | if ( totWeeks != weekView->totalWeeks() ) |
495 | weekView->setTotalWeeks( totWeeks ); | 495 | weekView->setTotalWeeks( totWeeks ); |
496 | } | 496 | } |
497 | void DateBook::initWeekLst() { | 497 | void DateBook::initWeekLst() { |
498 | if ( !weekLstView ) { | 498 | if ( !weekLstView ) { |
499 | weekLstView = new DateBookWeekLst( ampm, onMonday, db, | 499 | weekLstView = new DateBookWeekLst( ampm, onMonday, db, |
500 | views, "weeklst view" ); | 500 | views, "weeklst view" ); |
501 | views->addWidget( weekLstView, WEEKLST ); | 501 | views->addWidget( weekLstView, WEEKLST ); |
502 | 502 | ||
503 | //weekLstView->setStartViewTime( startTime ); | 503 | //weekLstView->setStartViewTime( startTime ); |
504 | connect( weekLstView, SIGNAL( showDate( int, int, int ) ), | 504 | connect( weekLstView, SIGNAL( showDate( int, int, int ) ), |
505 | this, SLOT( showDay( int, int, int ) ) ); | 505 | this, SLOT( showDay( int, int, int ) ) ); |
506 | connect( weekLstView, SIGNAL( addEvent( const QDateTime &, | 506 | connect( weekLstView, SIGNAL( addEvent( const QDateTime &, |
507 | const QDateTime &, | 507 | const QDateTime &, |
508 | const QString & ) ), | 508 | const QString & ) ), |
509 | this, SLOT( slotNewEntry( const QDateTime &, | 509 | this, SLOT( slotNewEntry( const QDateTime &, |
510 | const QDateTime &, | 510 | const QDateTime &, |
511 | const QString & ) ) ); | 511 | const QString & ) ) ); |
512 | connect( this, SIGNAL( newEvent() ), | 512 | connect( this, SIGNAL( newEvent() ), |
513 | weekLstView, SLOT( redraw() ) ); | 513 | weekLstView, SLOT( redraw() ) ); |
514 | connect( weekLstView, SIGNAL( editEvent( const Event & ) ), | 514 | connect( weekLstView, SIGNAL( editEvent( const Event & ) ), |
515 | this, SLOT( editEvent( const Event & ) ) ); | 515 | this, SLOT( editEvent( const Event & ) ) ); |
516 | } | 516 | } |
517 | } | 517 | } |
518 | 518 | ||
519 | 519 | ||
520 | void DateBook::initMonth() | 520 | void DateBook::initMonth() |
521 | { | 521 | { |
522 | if ( !monthView ) { | 522 | if ( !monthView ) { |
523 | monthView = new DateBookMonth( views, "month view", FALSE, db ); | 523 | monthView = new DateBookMonth( views, "month view", FALSE, db ); |
524 | views->addWidget( monthView, MONTH ); | 524 | views->addWidget( monthView, MONTH ); |
525 | connect( monthView, SIGNAL( dateClicked( int, int, int ) ), | 525 | connect( monthView, SIGNAL( dateClicked( int, int, int ) ), |
526 | this, SLOT( showDay( int, int, int ) ) ); | 526 | this, SLOT( showDay( int, int, int ) ) ); |
527 | connect( this, SIGNAL( newEvent() ), | 527 | connect( this, SIGNAL( newEvent() ), |
528 | monthView, SLOT( redraw() ) ); | 528 | monthView, SLOT( redraw() ) ); |
529 | qApp->processEvents(); | 529 | qApp->processEvents(); |
530 | } | 530 | } |
531 | } | 531 | } |
532 | 532 | ||
533 | void DateBook::loadSettings() | 533 | void DateBook::loadSettings() |
534 | { | 534 | { |
535 | { | 535 | { |
536 | Config config( "qpe" ); | 536 | Config config( "qpe" ); |
537 | config.setGroup("Time"); | 537 | config.setGroup("Time"); |
538 | ampm = config.readBoolEntry( "AMPM", TRUE ); | 538 | ampm = config.readBoolEntry( "AMPM", TRUE ); |
539 | onMonday = config.readBoolEntry( "MONDAY" ); | 539 | onMonday = config.readBoolEntry( "MONDAY" ); |
540 | } | 540 | } |
541 | 541 | ||
542 | { | 542 | { |
543 | Config config("DateBook"); | 543 | Config config("DateBook"); |
544 | config.setGroup("Main"); | 544 | config.setGroup("Main"); |
545 | startTime = config.readNumEntry("startviewtime", 8); | 545 | startTime = config.readNumEntry("startviewtime", 8); |
546 | aPreset = config.readBoolEntry("alarmpreset"); | 546 | aPreset = config.readBoolEntry("alarmpreset"); |
547 | presetTime = config.readNumEntry("presettime"); | 547 | presetTime = config.readNumEntry("presettime"); |
548 | } | 548 | } |
549 | } | 549 | } |
550 | 550 | ||
551 | void DateBook::saveSettings() | 551 | void DateBook::saveSettings() |
552 | { | 552 | { |
553 | Config config( "qpe" ); | 553 | Config config( "qpe" ); |
554 | Config configDB( "DateBook" ); | 554 | Config configDB( "DateBook" ); |
555 | configDB.setGroup( "Main" ); | 555 | configDB.setGroup( "Main" ); |
556 | configDB.writeEntry("startviewtime",startTime); | 556 | configDB.writeEntry("startviewtime",startTime); |
557 | configDB.writeEntry("alarmpreset",aPreset); | 557 | configDB.writeEntry("alarmpreset",aPreset); |
558 | configDB.writeEntry("presettime",presetTime); | 558 | configDB.writeEntry("presettime",presetTime); |
559 | } | 559 | } |
560 | 560 | ||
561 | void DateBook::newDefaultView(QAction *a) { | 561 | void DateBook::newDefaultView(QAction *a) { |
562 | int val=DAY; | 562 | int val=DAY; |
563 | if (a->text() == "Day") val=DAY; | 563 | if (a->text() == "Day") val=DAY; |
564 | if (a->text() == "Week") val=WEEK; | 564 | if (a->text() == "Week") val=WEEK; |
565 | if (a->text() == "WeekLst") val=WEEKLST; | 565 | if (a->text() == "WeekLst") val=WEEKLST; |
566 | if (a->text() == "Month") val=MONTH; | 566 | if (a->text() == "Month") val=MONTH; |
567 | 567 | ||
568 | Config configDB( "DateBook" ); | 568 | Config configDB( "DateBook" ); |
569 | configDB.setGroup( "Main" ); | 569 | configDB.setGroup( "Main" ); |
570 | configDB.writeEntry("defaultview",val); | 570 | configDB.writeEntry("defaultview",val); |
571 | } | 571 | } |
572 | 572 | ||
573 | void DateBook::appMessage(const QCString& msg, const QByteArray& data) | 573 | void DateBook::appMessage(const QCString& msg, const QByteArray& data) |
574 | { | 574 | { |
575 | bool needShow = FALSE; | 575 | bool needShow = FALSE; |
576 | if ( msg == "alarm(QDateTime,int)" ) { | 576 | if ( msg == "alarm(QDateTime,int)" ) { |
577 | QDataStream ds(data,IO_ReadOnly); | 577 | QDataStream ds(data,IO_ReadOnly); |
578 | QDateTime when; int warn; | 578 | QDateTime when; int warn; |
579 | ds >> when >> warn; | 579 | ds >> when >> warn; |
580 | 580 | ||
581 | // check to make it's okay to continue, | 581 | // check to make it's okay to continue, |
582 | // this is the case that the time was set ahead, and | 582 | // this is the case that the time was set ahead, and |
583 | // we are forced given a stale alarm... | 583 | // we are forced given a stale alarm... |
584 | QDateTime current = QDateTime::currentDateTime(); | 584 | QDateTime current = QDateTime::currentDateTime(); |
585 | if ( current.time().hour() != when.time().hour() | 585 | if ( current.time().hour() != when.time().hour() |
586 | && current.time().minute() != when.time().minute() ) | 586 | && current.time().minute() != when.time().minute() ) |
587 | return; | 587 | return; |
588 | 588 | ||
589 | QValueList<EffectiveEvent> list = db->getEffectiveEvents(when.addSecs(warn*60)); | 589 | QValueList<EffectiveEvent> list = db->getEffectiveEvents(when.addSecs(warn*60)); |
590 | if ( list.count() > 0 ) { | 590 | if ( list.count() > 0 ) { |
591 | QString msg; | 591 | QString msg; |
592 | bool bSound = FALSE; | 592 | bool bSound = FALSE; |
593 | int stopTimer = 0; | 593 | int stopTimer = 0; |
594 | bool found = FALSE; | 594 | bool found = FALSE; |
595 | for ( QValueList<EffectiveEvent>::ConstIterator it=list.begin(); | 595 | for ( QValueList<EffectiveEvent>::ConstIterator it=list.begin(); |
596 | it!=list.end(); ++it ) { | 596 | it!=list.end(); ++it ) { |
597 | if ( (*it).event().hasAlarm() ) { | 597 | if ( (*it).event().hasAlarm() ) { |
598 | found = TRUE; | 598 | found = TRUE; |
599 | msg += "<CENTER><B>" + (*it).description() + "</B>" | 599 | msg += "<CENTER><B>" + (*it).description() + "</B>" |
600 | + "<BR>" + (*it).location() + "<BR>" | 600 | + "<BR>" + (*it).location() + "<BR>" |
601 | + TimeString::dateString((*it).event().start(),ampm) | 601 | + TimeString::dateString((*it).event().start(),ampm) |
602 | + (warn | 602 | + (warn |
603 | ? tr(" (in " + QString::number(warn) | 603 | ? tr(" (in " + QString::number(warn) |
604 | + tr(" minutes)")) | 604 | + tr(" minutes)")) |
605 | : QString("")) | 605 | : QString("")) |
606 | + "<BR>" | 606 | + "<BR>" |
607 | + (*it).notes() + "</CENTER>"; | 607 | + (*it).notes() + "</CENTER>"; |
608 | if ( (*it).event().alarmSound() != Event::Silent ) { | 608 | if ( (*it).event().alarmSound() != Event::Silent ) { |
609 | bSound = TRUE; | 609 | bSound = TRUE; |
610 | } | 610 | } |
611 | } | 611 | } |
612 | } | 612 | } |
613 | if ( found ) { | 613 | if ( found ) { |
614 | if ( bSound ) { | 614 | if ( bSound ) { |
615 | Sound::soundAlarm(); | 615 | Sound::soundAlarm(); |
616 | stopTimer = startTimer( 5000 ); | 616 | stopTimer = startTimer( 5000 ); |
617 | } | 617 | } |
618 | 618 | ||
619 | QDialog dlg( this, 0, TRUE ); | 619 | QDialog dlg( this, 0, TRUE ); |
620 | QVBoxLayout *vb = new QVBoxLayout( &dlg ); | 620 | QVBoxLayout *vb = new QVBoxLayout( &dlg ); |
621 | QScrollView *view = new QScrollView( &dlg, "scrollView"); | 621 | QScrollView *view = new QScrollView( &dlg, "scrollView"); |
622 | view->setResizePolicy( QScrollView::AutoOneFit ); | 622 | view->setResizePolicy( QScrollView::AutoOneFit ); |
623 | vb->addWidget( view ); | 623 | vb->addWidget( view ); |
624 | QLabel *lblMsg = new QLabel( msg, &dlg ); | 624 | QLabel *lblMsg = new QLabel( msg, &dlg ); |
625 | view->addChild( lblMsg ); | 625 | view->addChild( lblMsg ); |
626 | QPushButton *cmdOk = new QPushButton( tr("OK"), &dlg ); | 626 | QPushButton *cmdOk = new QPushButton( tr("OK"), &dlg ); |
627 | connect( cmdOk, SIGNAL(clicked()), &dlg, SLOT(accept()) ); | 627 | connect( cmdOk, SIGNAL(clicked()), &dlg, SLOT(accept()) ); |
628 | vb->addWidget( cmdOk ); | 628 | vb->addWidget( cmdOk ); |
629 | 629 | ||
630 | #if defined(Q_WS_QWS) || defined(_WS_QWS_) | 630 | #if defined(Q_WS_QWS) || defined(_WS_QWS_) |
631 | dlg.showMaximized(); | 631 | dlg.showMaximized(); |
632 | #endif | 632 | #endif |
633 | needShow = dlg.exec(); | 633 | needShow = dlg.exec(); |
634 | 634 | ||
635 | if ( bSound ) | 635 | if ( bSound ) |
636 | killTimer( stopTimer ); | 636 | killTimer( stopTimer ); |
637 | } | 637 | } |
638 | } | 638 | } |
639 | } else if ( msg == "nextView()" ) { | 639 | } else if ( msg == "nextView()" ) { |
640 | QWidget* cur = views->visibleWidget(); | 640 | QWidget* cur = views->visibleWidget(); |
641 | if ( cur ) { | 641 | if ( cur ) { |
642 | if ( cur == dayView ) | 642 | if ( cur == dayView ) |
643 | viewWeek(); | 643 | viewWeek(); |
644 | else if ( cur == weekView ) | 644 | else if ( cur == weekView ) |
645 | viewWeekLst(); | 645 | viewWeekLst(); |
646 | else if ( cur == weekLstView ) | 646 | else if ( cur == weekLstView ) |
647 | viewMonth(); | 647 | viewMonth(); |
648 | else if ( cur == monthView ) | 648 | else if ( cur == monthView ) |
649 | viewDay(); | 649 | viewDay(); |
650 | needShow = TRUE; | 650 | needShow = TRUE; |
651 | } | 651 | } |
652 | } | 652 | } |
653 | if ( needShow ) { | 653 | if ( needShow ) { |
654 | #if defined(Q_WS_QWS) || defined(_WS_QWS_) | 654 | #if defined(Q_WS_QWS) || defined(_WS_QWS_) |
655 | showMaximized(); | 655 | showMaximized(); |
656 | #else | 656 | #else |
657 | show(); | 657 | show(); |
658 | #endif | 658 | #endif |
659 | raise(); | 659 | raise(); |
660 | QPEApplication::setKeepRunning(); | 660 | QPEApplication::setKeepRunning(); |
661 | setActiveWindow(); | 661 | setActiveWindow(); |
662 | } | 662 | } |
663 | } | 663 | } |
664 | 664 | ||
665 | void DateBook::reload() | 665 | void DateBook::reload() |
666 | { | 666 | { |
667 | db->reload(); | 667 | db->reload(); |
668 | if ( dayAction->isOn() ) | 668 | if ( dayAction->isOn() ) |
669 | viewDay(); | 669 | viewDay(); |
670 | else if ( weekAction->isOn() ) | 670 | else if ( weekAction->isOn() ) |
671 | viewWeek(); | 671 | viewWeek(); |
672 | else if ( monthAction->isOn() ) | 672 | else if ( monthAction->isOn() ) |
673 | viewMonth(); | 673 | viewMonth(); |
674 | syncing = FALSE; | 674 | syncing = FALSE; |
675 | } | 675 | } |
676 | 676 | ||
677 | void DateBook::flush() | 677 | void DateBook::flush() |
678 | { | 678 | { |
679 | syncing = TRUE; | 679 | syncing = TRUE; |
680 | db->save(); | 680 | db->save(); |
681 | } | 681 | } |
682 | 682 | ||
683 | void DateBook::timerEvent( QTimerEvent *e ) | 683 | void DateBook::timerEvent( QTimerEvent *e ) |
684 | { | 684 | { |
685 | static int stop = 0; | 685 | static int stop = 0; |
686 | if ( stop < 10 ) { | 686 | if ( stop < 10 ) { |
687 | Sound::soundAlarm(); | 687 | Sound::soundAlarm(); |
688 | stop++; | 688 | stop++; |
689 | } else { | 689 | } else { |
690 | stop = 0; | 690 | stop = 0; |
691 | killTimer( e->timerId() ); | 691 | killTimer( e->timerId() ); |
692 | } | 692 | } |
693 | } | 693 | } |
694 | 694 | ||
695 | void DateBook::changeClock( bool newClock ) | 695 | void DateBook::changeClock( bool newClock ) |
696 | { | 696 | { |
697 | ampm = newClock; | 697 | ampm = newClock; |
698 | // repaint the affected objects... | 698 | // repaint the affected objects... |
699 | if (dayView) dayView->redraw(); | 699 | if (dayView) dayView->redraw(); |
700 | if (weekView) weekView->redraw(); | 700 | if (weekView) weekView->redraw(); |
701 | if (weekLstView) weekLstView->redraw(); | 701 | if (weekLstView) weekLstView->redraw(); |
702 | } | 702 | } |
703 | 703 | ||
704 | void DateBook::changeWeek( bool m ) | 704 | void DateBook::changeWeek( bool m ) |
705 | { | 705 | { |
706 | /* no need to redraw, each widget catches. Do need to | 706 | /* no need to redraw, each widget catches. Do need to |
707 | store though for widgets we haven't made yet */ | 707 | store though for widgets we haven't made yet */ |
708 | onMonday = m; | 708 | onMonday = m; |
709 | } | 709 | } |
710 | 710 | ||
711 | void DateBook::slotToday() | 711 | void DateBook::slotToday() |
712 | { | 712 | { |
713 | // we need to view today using default view | 713 | // we need to view today using default view |
714 | viewDefault(QDate::currentDate()); | 714 | viewDefault(QDate::currentDate()); |
715 | } | 715 | } |
716 | 716 | ||
717 | void DateBook::closeEvent( QCloseEvent *e ) | 717 | void DateBook::closeEvent( QCloseEvent *e ) |
718 | { | 718 | { |
719 | if(syncing) { | 719 | if(syncing) { |
720 | /* no need to save, did that at flush */ | 720 | /* no need to save, did that at flush */ |
721 | e->accept(); | 721 | e->accept(); |
722 | return; | 722 | return; |
723 | } | 723 | } |
724 | 724 | ||
725 | // save settings will generate it's own error messages, no | 725 | // save settings will generate it's own error messages, no |
726 | // need to do checking ourselves. | 726 | // need to do checking ourselves. |
727 | saveSettings(); | 727 | saveSettings(); |
728 | if ( db->save() ) | 728 | if ( db->save() ) |
729 | e->accept(); | 729 | e->accept(); |
730 | else { | 730 | else { |
731 | if ( QMessageBox::critical( this, tr( "Out of space" ), | 731 | if ( QMessageBox::critical( this, tr( "Out of space" ), |
732 | tr("Calendar was unable to save\n" | 732 | tr("Calendar was unable to save\n" |
733 | "your changes.\n" | 733 | "your changes.\n" |
734 | "Free up some space and try again.\n" | 734 | "Free up some space and try again.\n" |
735 | "\nQuit anyway?"), | 735 | "\nQuit anyway?"), |
736 | QMessageBox::Yes|QMessageBox::Escape, | 736 | QMessageBox::Yes|QMessageBox::Escape, |
737 | QMessageBox::No|QMessageBox::Default ) | 737 | QMessageBox::No|QMessageBox::Default ) |
738 | != QMessageBox::No ) | 738 | != QMessageBox::No ) |
739 | e->accept(); | 739 | e->accept(); |
740 | else | 740 | else |
741 | e->ignore(); | 741 | e->ignore(); |
742 | } | 742 | } |
743 | } | 743 | } |
744 | 744 | ||
745 | // Entering directly from the "keyboard" | 745 | // Entering directly from the "keyboard" |
746 | void DateBook::slotNewEventFromKey( const QString &str ) | 746 | void DateBook::slotNewEventFromKey( const QString &str ) |
747 | { | 747 | { |
748 | if (syncing) { | 748 | if (syncing) { |
749 | QMessageBox::warning( this, tr("Calendar"), | 749 | QMessageBox::warning( this, tr("Calendar"), |
750 | tr( "Can not edit data, currently syncing") ); | 750 | tr( "Can not edit data, currently syncing") ); |
751 | return; | 751 | return; |
752 | } | 752 | } |
753 | 753 | ||
754 | // We get to here from a key pressed in the Day View | 754 | // We get to here from a key pressed in the Day View |
755 | // So we can assume some things. We want the string | 755 | // So we can assume some things. We want the string |
756 | // passed in to be part of the description. | 756 | // passed in to be part of the description. |
757 | QDateTime start, end; | 757 | QDateTime start, end; |
758 | if ( views->visibleWidget() == dayView ) { | 758 | if ( views->visibleWidget() == dayView ) { |
759 | dayView->selectedDates( start, end ); | 759 | dayView->selectedDates( start, end ); |
760 | } else if ( views->visibleWidget() == monthView ) { | 760 | } else if ( views->visibleWidget() == monthView ) { |
761 | QDate d = monthView->selectedDate(); | 761 | QDate d = monthView->selectedDate(); |
762 | start = end = d; | 762 | start = end = d; |
763 | start.setTime( QTime( 10, 0 ) ); | 763 | start.setTime( QTime( 10, 0 ) ); |
764 | end.setTime( QTime( 12, 0 ) ); | 764 | end.setTime( QTime( 12, 0 ) ); |
765 | } else if ( views->visibleWidget() == weekView ) { | 765 | } else if ( views->visibleWidget() == weekView ) { |
766 | QDate d = weekView->date(); | 766 | QDate d = weekView->date(); |
767 | start = end = d; | 767 | start = end = d; |
768 | start.setTime( QTime( 10, 0 ) ); | 768 | start.setTime( QTime( 10, 0 ) ); |
769 | end.setTime( QTime( 12, 0 ) ); | 769 | end.setTime( QTime( 12, 0 ) ); |
770 | } | 770 | } |
771 | slotNewEntry(start, end, str); | 771 | slotNewEntry(start, end, str); |
772 | } | 772 | } |
773 | void DateBook::slotNewEntry(const QDateTime &start, const QDateTime &end, const QString &str) { | 773 | void DateBook::slotNewEntry(const QDateTime &start, const QDateTime &end, const QString &str) { |
774 | // argh! This really needs to be encapsulated in a class | 774 | // argh! This really needs to be encapsulated in a class |
775 | // or function. | 775 | // or function. |
776 | QDialog newDlg( this, 0, TRUE ); | 776 | QDialog newDlg( this, 0, TRUE ); |
777 | newDlg.setCaption( DateEntryBase::tr("New Event") ); | 777 | newDlg.setCaption( DateEntryBase::tr("New Event") ); |
778 | DateEntry *e; | 778 | DateEntry *e; |
779 | QVBoxLayout *vb = new QVBoxLayout( &newDlg ); | 779 | QVBoxLayout *vb = new QVBoxLayout( &newDlg ); |
780 | QScrollView *sv = new QScrollView( &newDlg ); | 780 | QScrollView *sv = new QScrollView( &newDlg ); |
781 | sv->setResizePolicy( QScrollView::AutoOneFit ); | 781 | sv->setResizePolicy( QScrollView::AutoOneFit ); |
782 | sv->setFrameStyle( QFrame::NoFrame ); | 782 | sv->setFrameStyle( QFrame::NoFrame ); |
783 | sv->setHScrollBarMode( QScrollView::AlwaysOff ); | 783 | sv->setHScrollBarMode( QScrollView::AlwaysOff ); |
784 | vb->addWidget( sv ); | 784 | vb->addWidget( sv ); |
785 | 785 | ||
786 | Event ev; | 786 | Event ev; |
787 | ev.setDescription( str ); | 787 | ev.setDescription( str ); |
788 | // When the new gui comes in, change this... | 788 | // When the new gui comes in, change this... |
789 | ev.setLocation( tr("(Unknown)") ); | 789 | ev.setLocation( tr("(Unknown)") ); |
790 | ev.setStart( start ); | 790 | ev.setStart( start ); |
791 | ev.setEnd( end ); | 791 | ev.setEnd( end ); |
792 | 792 | ||
793 | e = new DateEntry( onMonday, ev, ampm, &newDlg ); | 793 | e = new DateEntry( onMonday, ev, ampm, &newDlg ); |
794 | e->setAlarmEnabled( aPreset, presetTime, Event::Loud ); | 794 | e->setAlarmEnabled( aPreset, presetTime, Event::Loud ); |
795 | sv->addChild( e ); | 795 | sv->addChild( e ); |
796 | #if defined(Q_WS_QWS) || defined(_WS_QWS_) | 796 | #if defined(Q_WS_QWS) || defined(_WS_QWS_) |
797 | newDlg.showMaximized(); | 797 | newDlg.showMaximized(); |
798 | #endif | 798 | #endif |
799 | while (newDlg.exec()) { | 799 | while (newDlg.exec()) { |
800 | ev = e->event(); | 800 | ev = e->event(); |
801 | ev.assignUid(); | 801 | ev.assignUid(); |
802 | QString error = checkEvent( ev ); | 802 | QString error = checkEvent( ev ); |
803 | if ( !error.isNull() ) { | 803 | if ( !error.isNull() ) { |
804 | if ( QMessageBox::warning( this, tr("Error!"), | 804 | if ( QMessageBox::warning( this, tr("Error!"), |
805 | error, tr("Fix it"), tr("Continue"), 0, 0, 1 ) == 0 ) | 805 | error, tr("Fix it"), tr("Continue"), 0, 0, 1 ) == 0 ) |
806 | continue; | 806 | continue; |
807 | } | 807 | } |
808 | db->addEvent( ev ); | 808 | db->addEvent( ev ); |
809 | emit newEvent(); | 809 | emit newEvent(); |
810 | break; | 810 | break; |
811 | } | 811 | } |
812 | } | 812 | } |
813 | 813 | ||
814 | void DateBook::setDocument( const QString &filename ) | 814 | void DateBook::setDocument( const QString &filename ) |
815 | { | 815 | { |
816 | if ( filename.find(".vcs") != int(filename.length()) - 4 ) return; | 816 | if ( filename.find(".vcs") != int(filename.length()) - 4 ) return; |
817 | 817 | ||
818 | QValueList<Event> tl = Event::readVCalendar( filename ); | 818 | QValueList<Event> tl = Event::readVCalendar( filename ); |
819 | for( QValueList<Event>::Iterator it = tl.begin(); it != tl.end(); ++it ) { | 819 | for( QValueList<Event>::Iterator it = tl.begin(); it != tl.end(); ++it ) { |
820 | db->addEvent( *it ); | 820 | db->addEvent( *it ); |
821 | } | 821 | } |
822 | } | 822 | } |
823 | 823 | ||
824 | static const char * beamfile = "/tmp/obex/event.vcs"; | 824 | static const char * beamfile = "/tmp/obex/event.vcs"; |
825 | 825 | ||
826 | void DateBook::beamEvent( const Event &e ) | 826 | void DateBook::beamEvent( const Event &e ) |
827 | { | 827 | { |
828 | qDebug("trying to beamn"); | 828 | qDebug("trying to beamn"); |
829 | unlink( beamfile ); // delete if exists | 829 | unlink( beamfile ); // delete if exists |
830 | mkdir("/tmp/obex/", 0755); | 830 | mkdir("/tmp/obex/", 0755); |
831 | Event::writeVCalendar( beamfile, e ); | 831 | Event::writeVCalendar( beamfile, e ); |
832 | Ir *ir = new Ir( this ); | 832 | Ir *ir = new Ir( this ); |
833 | connect( ir, SIGNAL( done( Ir * ) ), this, SLOT( beamDone( Ir * ) ) ); | 833 | connect( ir, SIGNAL( done( Ir * ) ), this, SLOT( beamDone( Ir * ) ) ); |
834 | QString description = e.description(); | 834 | QString description = e.description(); |
835 | ir->send( beamfile, description, "text/x-vCalendar" ); | 835 | ir->send( beamfile, description, "text/x-vCalendar" ); |
836 | } | 836 | } |
837 | 837 | ||
838 | void DateBook::beamDone( Ir *ir ) | 838 | void DateBook::beamDone( Ir *ir ) |
839 | { | 839 | { |
840 | delete ir; | 840 | delete ir; |
841 | unlink( beamfile ); | 841 | unlink( beamfile ); |
842 | } | 842 | } |
843 | 843 | ||
844 | void DateBook::slotFind() | 844 | void DateBook::slotFind() |
845 | { | 845 | { |
846 | // move it to the day view... | 846 | // move it to the day view... |
847 | viewDay(); | 847 | viewDay(); |
848 | FindDialog frmFind( "Calendar", this ); | 848 | FindDialog frmFind( "Calendar", this ); |
849 | frmFind.setUseDate( true ); | 849 | frmFind.setUseDate( true ); |
850 | frmFind.setDate( currentDate() ); | 850 | frmFind.setDate( currentDate() ); |
851 | QObject::connect( &frmFind, | 851 | QObject::connect( &frmFind, |
852 | SIGNAL(signalFindClicked(const QString&, const QDate&, | 852 | SIGNAL(signalFindClicked(const QString&, const QDate&, |
853 | bool, bool, int)), | 853 | bool, bool, int)), |
854 | this, | 854 | this, |
855 | SLOT(slotDoFind(const QString&, const QDate&, | 855 | SLOT(slotDoFind(const QString&, const QDate&, |
856 | bool, bool, int)) ); | 856 | bool, bool, int)) ); |
857 | QObject::connect( this, | 857 | QObject::connect( this, |
858 | SIGNAL(signalNotFound()), | 858 | SIGNAL(signalNotFound()), |
859 | &frmFind, | 859 | &frmFind, |
860 | SLOT(slotNotFound()) ); | 860 | SLOT(slotNotFound()) ); |
861 | QObject::connect( this, | 861 | QObject::connect( this, |
862 | SIGNAL(signalWrapAround()), | 862 | SIGNAL(signalWrapAround()), |
863 | &frmFind, | 863 | &frmFind, |
864 | SLOT(slotWrapAround()) ); | 864 | SLOT(slotWrapAround()) ); |
865 | frmFind.exec(); | 865 | frmFind.exec(); |
866 | inSearch = false; | 866 | inSearch = false; |
867 | } | 867 | } |
868 | 868 | ||
869 | bool catComp( QArray<int> cats, int category ) | 869 | bool catComp( QArray<int> cats, int category ) |
870 | { | 870 | { |
871 | bool returnMe; | 871 | bool returnMe; |
872 | int i, | 872 | int i, |
873 | count; | 873 | count; |
874 | 874 | ||
875 | count = int(cats.count()); | 875 | count = int(cats.count()); |
876 | returnMe = false; | 876 | returnMe = false; |
877 | if ( (category == -1 && count == 0) || category == -2 ) | 877 | if ( (category == -1 && count == 0) || category == -2 ) |
878 | returnMe = true; | 878 | returnMe = true; |
879 | else { | 879 | else { |
880 | for ( i = 0; i < count; i++ ) { | 880 | for ( i = 0; i < count; i++ ) { |
881 | if ( category == cats[i] ) { | 881 | if ( category == cats[i] ) { |
882 | returnMe = true; | 882 | returnMe = true; |
883 | break; | 883 | break; |
884 | } | 884 | } |
885 | } | 885 | } |
886 | } | 886 | } |
887 | return returnMe; | 887 | return returnMe; |
888 | } | 888 | } |
889 | 889 | ||
890 | 890 | ||
891 | void DateBook::slotDoFind( const QString& txt, const QDate &dt, | 891 | void DateBook::slotDoFind( const QString& txt, const QDate &dt, |
892 | bool caseSensitive, bool /*backwards*/, | 892 | bool caseSensitive, bool /*backwards*/, |
893 | int category ) | 893 | int category ) |
894 | { | 894 | { |
895 | QDateTime dtEnd( QDate(3001, 1, 1), QTime(0, 0, 0) ), | 895 | QDateTime dtEnd( QDate(3001, 1, 1), QTime(0, 0, 0) ), |
896 | next; | 896 | next; |
897 | 897 | ||
898 | QRegExp r( txt ); | 898 | QRegExp r( txt ); |
899 | r.setCaseSensitive( caseSensitive ); | 899 | r.setCaseSensitive( caseSensitive ); |
900 | 900 | ||
901 | 901 | ||
902 | static Event rev, | 902 | static Event rev, |
903 | nonrev; | 903 | nonrev; |
904 | if ( !inSearch ) { | 904 | if ( !inSearch ) { |
905 | rev.setStart( QDateTime(QDate(1960, 1, 1), QTime(0, 0, 0)) ); | 905 | rev.setStart( QDateTime(QDate(1960, 1, 1), QTime(0, 0, 0)) ); |
906 | nonrev.setStart( rev.start() ); | 906 | nonrev.setStart( rev.start() ); |
907 | inSearch = true; | 907 | inSearch = true; |
908 | } | 908 | } |
909 | static QDate searchDate = dt; | 909 | static QDate searchDate = dt; |
910 | static bool wrapAround = true; | 910 | static bool wrapAround = true; |
911 | bool candidtate; | 911 | bool candidtate; |
912 | candidtate = false; | 912 | candidtate = false; |
913 | 913 | ||
914 | QValueList<Event> repeats = db->getRawRepeats(); | 914 | QValueList<Event> repeats = db->getRawRepeats(); |
915 | 915 | ||
916 | // find the candidate for the first repeat that matches... | 916 | // find the candidate for the first repeat that matches... |
917 | QValueListConstIterator<Event> it; | 917 | QValueListConstIterator<Event> it; |
918 | QDate start = dt; | 918 | QDate start = dt; |
919 | for ( it = repeats.begin(); it != repeats.end(); ++it ) { | 919 | for ( it = repeats.begin(); it != repeats.end(); ++it ) { |
920 | if ( catComp( (*it).categories(), category ) ) { | 920 | if ( catComp( (*it).categories(), category ) ) { |
921 | while ( nextOccurance( *it, start, next ) ) { | 921 | while ( nextOccurance( *it, start, next ) ) { |
922 | if ( next < dtEnd ) { | 922 | if ( next < dtEnd ) { |
923 | if ( (*it).match( r ) && !(next <= rev.start()) ) { | 923 | if ( (*it).match( r ) && !(next <= rev.start()) ) { |
924 | rev = *it; | 924 | rev = *it; |
925 | dtEnd = next; | 925 | dtEnd = next; |
926 | rev.setStart( next ); | 926 | rev.setStart( next ); |
927 | candidtate = true; | 927 | candidtate = true; |
928 | wrapAround = true; | 928 | wrapAround = true; |
929 | start = dt; | 929 | start = dt; |
930 | break; | 930 | break; |
931 | } else | 931 | } else |
932 | start = next.date().addDays( 1 ); | 932 | start = next.date().addDays( 1 ); |
933 | } | 933 | } |
934 | } | 934 | } |
935 | } | 935 | } |
936 | } | 936 | } |
937 | 937 | ||
938 | // now the for first non repeat... | 938 | // now the for first non repeat... |
939 | QValueList<Event> nonRepeats = db->getNonRepeatingEvents( dt, dtEnd.date() ); | 939 | QValueList<Event> nonRepeats = db->getNonRepeatingEvents( dt, dtEnd.date() ); |
940 | qHeapSort( nonRepeats.begin(), nonRepeats.end() ); | 940 | qHeapSort( nonRepeats.begin(), nonRepeats.end() ); |
941 | for ( it = nonRepeats.begin(); it != nonRepeats.end(); ++it ) { | 941 | for ( it = nonRepeats.begin(); it != nonRepeats.end(); ++it ) { |
942 | if ( catComp( (*it).categories(), category ) ) { | 942 | if ( catComp( (*it).categories(), category ) ) { |
943 | if ( (*it).start() < dtEnd ) { | 943 | if ( (*it).start() < dtEnd ) { |
944 | if ( (*it).match( r ) && !(*it <= nonrev) ) { | 944 | if ( (*it).match( r ) && !(*it <= nonrev) ) { |
945 | nonrev = *it; | 945 | nonrev = *it; |
946 | dtEnd = nonrev.start(); | 946 | dtEnd = nonrev.start(); |
947 | candidtate = true; | 947 | candidtate = true; |
948 | wrapAround = true; | 948 | wrapAround = true; |
949 | break; | 949 | break; |
950 | } | 950 | } |
951 | } | 951 | } |
952 | } | 952 | } |
953 | } | 953 | } |
954 | if ( candidtate ) { | 954 | if ( candidtate ) { |
955 | dayView->setStartViewTime( dtEnd.time().hour() ); | 955 | dayView->setStartViewTime( dtEnd.time().hour() ); |
956 | dayView->setDate( dtEnd.date().year(), dtEnd.date().month(), | 956 | dayView->setDate( dtEnd.date().year(), dtEnd.date().month(), |
957 | dtEnd.date().day() ); | 957 | dtEnd.date().day() ); |
958 | } else { | 958 | } else { |
959 | if ( wrapAround ) { | 959 | if ( wrapAround ) { |
960 | emit signalWrapAround(); | 960 | emit signalWrapAround(); |
961 | rev.setStart( QDateTime(QDate(1960, 1, 1), QTime(0, 0, 0)) ); | 961 | rev.setStart( QDateTime(QDate(1960, 1, 1), QTime(0, 0, 0)) ); |
962 | nonrev.setStart( rev.start() ); | 962 | nonrev.setStart( rev.start() ); |
963 | } else | 963 | } else |
964 | emit signalNotFound(); | 964 | emit signalNotFound(); |
965 | wrapAround = !wrapAround; | 965 | wrapAround = !wrapAround; |
966 | } | 966 | } |
967 | } | 967 | } |
968 | |||
969 | Event DateBookDBHack::eventByUID(int uid) { | ||
970 | |||
971 | // FIXME: Dirty Hacks to get hold of the private event lists | ||
972 | QDate start; | ||
973 | QDate end=start.addDays(-1); | ||
974 | QValueList<Event> myEventList=getNonRepeatingEvents(start,end); | ||
975 | QValueList<Event> myRepeatEvents=getRawRepeats(); | ||
976 | |||
977 | QValueList<Event>::ConstIterator it; | ||
978 | |||
979 | for (it = myEventList.begin(); it != myEventList.end(); it++) { | ||
980 | if ((*it).uid() == uid) return *it; | ||
981 | } | ||
982 | for (it = myRepeatEvents.begin(); it != myRepeatEvents.end(); it++) { | ||
983 | if ((*it).uid() == uid) return *it; | ||
984 | } | ||
985 | |||
986 | qDebug("Event not found: uid=%d\n", uid); | ||
987 | } | ||
988 | |||
diff --git a/core/pim/datebook/datebook.h b/core/pim/datebook/datebook.h index 2ffcdbe..d1fe90d 100644 --- a/core/pim/datebook/datebook.h +++ b/core/pim/datebook/datebook.h | |||
@@ -1,121 +1,126 @@ | |||
1 | /********************************************************************** | 1 | /********************************************************************** |
2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. | 2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. |
3 | ** | 3 | ** |
4 | ** This file is part of Qtopia Environment. | 4 | ** This file is part of Qtopia Environment. |
5 | ** | 5 | ** |
6 | ** This file may be distributed and/or modified under the terms of the | 6 | ** This file may be distributed and/or modified under the terms of the |
7 | ** GNU General Public License version 2 as published by the Free Software | 7 | ** GNU General Public License version 2 as published by the Free Software |
8 | ** Foundation and appearing in the file LICENSE.GPL included in the | 8 | ** Foundation and appearing in the file LICENSE.GPL included in the |
9 | ** packaging of this file. | 9 | ** packaging of this file. |
10 | ** | 10 | ** |
11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | 11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE |
12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | 12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
13 | ** | 13 | ** |
14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | 14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. |
15 | ** | 15 | ** |
16 | ** Contact info@trolltech.com if any conditions of this licensing are | 16 | ** Contact info@trolltech.com if any conditions of this licensing are |
17 | ** not clear to you. | 17 | ** not clear to you. |
18 | ** | 18 | ** |
19 | **********************************************************************/ | 19 | **********************************************************************/ |
20 | #ifndef DATEBOOK_H | 20 | #ifndef DATEBOOK_H |
21 | #define DATEBOOK_H | 21 | #define DATEBOOK_H |
22 | 22 | ||
23 | #include <qpe/datebookdb.h> | 23 | #include <qpe/datebookdb.h> |
24 | 24 | ||
25 | #include <qmainwindow.h> | 25 | #include <qmainwindow.h> |
26 | 26 | ||
27 | class QAction; | 27 | class QAction; |
28 | class QWidgetStack; | 28 | class QWidgetStack; |
29 | class DateBookDay; | 29 | class DateBookDay; |
30 | class DateBookWeek; | 30 | class DateBookWeek; |
31 | class DateBookWeekLst; | 31 | class DateBookWeekLst; |
32 | class DateBookMonth; | 32 | class DateBookMonth; |
33 | class Event; | 33 | class Event; |
34 | class QDate; | 34 | class QDate; |
35 | class Ir; | 35 | class Ir; |
36 | 36 | ||
37 | class DateBookDBHack : public DateBookDB { | ||
38 | public: | ||
39 | Event eventByUID(int id); | ||
40 | }; | ||
41 | |||
37 | class DateBook : public QMainWindow | 42 | class DateBook : public QMainWindow |
38 | { | 43 | { |
39 | Q_OBJECT | 44 | Q_OBJECT |
40 | 45 | ||
41 | public: | 46 | public: |
42 | DateBook( QWidget *parent = 0, const char *name = 0, WFlags f = 0 ); | 47 | DateBook( QWidget *parent = 0, const char *name = 0, WFlags f = 0 ); |
43 | ~DateBook(); | 48 | ~DateBook(); |
44 | 49 | ||
45 | signals: | 50 | signals: |
46 | void newEvent(); | 51 | void newEvent(); |
47 | void signalNotFound(); | 52 | void signalNotFound(); |
48 | void signalWrapAround(); | 53 | void signalWrapAround(); |
49 | 54 | ||
50 | protected: | 55 | protected: |
51 | QDate currentDate(); | 56 | QDate currentDate(); |
52 | void timerEvent( QTimerEvent *e ); | 57 | void timerEvent( QTimerEvent *e ); |
53 | void closeEvent( QCloseEvent *e ); | 58 | void closeEvent( QCloseEvent *e ); |
54 | 59 | ||
55 | void view(int v, const QDate &d); | 60 | void view(int v, const QDate &d); |
56 | 61 | ||
57 | public slots: | 62 | public slots: |
58 | void flush(); | 63 | void flush(); |
59 | void reload(); | 64 | void reload(); |
60 | 65 | ||
61 | private slots: | 66 | private slots: |
62 | void fileNew(); | 67 | void fileNew(); |
63 | void slotNewEntry(const QDateTime &start, const QDateTime &end, const QString &str); | 68 | void slotNewEntry(const QDateTime &start, const QDateTime &end, const QString &str); |
64 | void slotSettings(); | 69 | void slotSettings(); |
65 | void newDefaultView(QAction *a); | 70 | void newDefaultView(QAction *a); |
66 | void slotToday();// view today | 71 | void slotToday();// view today |
67 | void changeClock( bool newClock ); | 72 | void changeClock( bool newClock ); |
68 | void changeWeek( bool newDay ); | 73 | void changeWeek( bool newDay ); |
69 | void appMessage(const QCString& msg, const QByteArray& data); | 74 | void appMessage(const QCString& msg, const QByteArray& data); |
70 | // handle key events in the day view... | 75 | // handle key events in the day view... |
71 | void slotNewEventFromKey( const QString &str ); | 76 | void slotNewEventFromKey( const QString &str ); |
72 | void slotFind(); | 77 | void slotFind(); |
73 | void slotDoFind( const QString &, const QDate &, bool, bool, int ); | 78 | void slotDoFind( const QString &, const QDate &, bool, bool, int ); |
74 | 79 | ||
75 | void viewDefault(const QDate &d); | 80 | void viewDefault(const QDate &d); |
76 | 81 | ||
77 | void viewDay(); | 82 | void viewDay(); |
78 | void viewWeek(); | 83 | void viewWeek(); |
79 | void viewWeekLst(); | 84 | void viewWeekLst(); |
80 | void viewMonth(); | 85 | void viewMonth(); |
81 | 86 | ||
82 | void showDay( int y, int m, int d ); | 87 | void showDay( int y, int m, int d ); |
83 | 88 | ||
84 | void editEvent( const Event &e ); | 89 | void editEvent( const Event &e ); |
85 | void removeEvent( const Event &e ); | 90 | void removeEvent( const Event &e ); |
86 | 91 | ||
87 | void receive( const QCString &msg, const QByteArray &data ); | 92 | void receive( const QCString &msg, const QByteArray &data ); |
88 | void setDocument( const QString & ); | 93 | void setDocument( const QString & ); |
89 | void beamEvent( const Event &e ); | 94 | void beamEvent( const Event &e ); |
90 | void beamDone( Ir *ir ); | 95 | void beamDone( Ir *ir ); |
91 | 96 | ||
92 | private: | 97 | private: |
93 | void addEvent( const Event &e ); | 98 | void addEvent( const Event &e ); |
94 | void initDay(); | 99 | void initDay(); |
95 | void initWeek(); | 100 | void initWeek(); |
96 | void initWeekLst(); | 101 | void initWeekLst(); |
97 | void initMonth(); | 102 | void initMonth(); |
98 | void loadSettings(); | 103 | void loadSettings(); |
99 | void saveSettings(); | 104 | void saveSettings(); |
100 | 105 | ||
101 | private: | 106 | private: |
102 | DateBookDB *db; | 107 | DateBookDBHack *db; |
103 | QWidgetStack *views; | 108 | QWidgetStack *views; |
104 | DateBookDay *dayView; | 109 | DateBookDay *dayView; |
105 | DateBookWeek *weekView; | 110 | DateBookWeek *weekView; |
106 | DateBookMonth *monthView; | 111 | DateBookMonth *monthView; |
107 | DateBookWeekLst *weekLstView; | 112 | DateBookWeekLst *weekLstView; |
108 | QAction *dayAction, *weekAction, *weekLstAction, *monthAction; | 113 | QAction *dayAction, *weekAction, *weekLstAction, *monthAction; |
109 | bool aPreset; // have everything set to alarm? | 114 | bool aPreset; // have everything set to alarm? |
110 | int presetTime; // the standard time for the alarm | 115 | int presetTime; // the standard time for the alarm |
111 | int startTime; | 116 | int startTime; |
112 | bool ampm; | 117 | bool ampm; |
113 | bool onMonday; | 118 | bool onMonday; |
114 | 119 | ||
115 | bool syncing; | 120 | bool syncing; |
116 | bool inSearch; | 121 | bool inSearch; |
117 | 122 | ||
118 | QString checkEvent(const Event &); | 123 | QString checkEvent(const Event &); |
119 | }; | 124 | }; |
120 | 125 | ||
121 | #endif | 126 | #endif |
diff --git a/library/datebookdb.cpp b/library/datebookdb.cpp index da5a797..2ac9a0c 100644 --- a/library/datebookdb.cpp +++ b/library/datebookdb.cpp | |||
@@ -206,782 +206,768 @@ bool nextOccurance(const Event &e, const QDate &from, QDateTime &next) | |||
206 | tmpDate = QDate( iyear, imonth, 1 ); | 206 | tmpDate = QDate( iyear, imonth, 1 ); |
207 | /* these loops could go for a while, check end case now */ | 207 | /* these loops could go for a while, check end case now */ |
208 | if ((tmpDate > e.repeatPattern().endDate()) && e.repeatPattern().hasEndDate) | 208 | if ((tmpDate > e.repeatPattern().endDate()) && e.repeatPattern().hasEndDate) |
209 | return FALSE; | 209 | return FALSE; |
210 | iday = 1; | 210 | iday = 1; |
211 | iday += (7 + dayOfWeek - tmpDate.dayOfWeek()) % 7; | 211 | iday += (7 + dayOfWeek - tmpDate.dayOfWeek()) % 7; |
212 | iday += 7 * weekOfMonth; | 212 | iday += 7 * weekOfMonth; |
213 | } while (iday > tmpDate.daysInMonth()); | 213 | } while (iday > tmpDate.daysInMonth()); |
214 | tmpDate = QDate(iyear, imonth, iday); | 214 | tmpDate = QDate(iyear, imonth, iday); |
215 | 215 | ||
216 | next = QDateTime(tmpDate, e.start().time()); | 216 | next = QDateTime(tmpDate, e.start().time()); |
217 | if ((next.date() > e.repeatPattern().endDate()) && e.repeatPattern().hasEndDate) | 217 | if ((next.date() > e.repeatPattern().endDate()) && e.repeatPattern().hasEndDate) |
218 | return FALSE; | 218 | return FALSE; |
219 | return TRUE; | 219 | return TRUE; |
220 | case Event::MonthlyDate: | 220 | case Event::MonthlyDate: |
221 | iday = e.start().date().day(); | 221 | iday = e.start().date().day(); |
222 | iyear = from.year(); | 222 | iyear = from.year(); |
223 | imonth = from.month(); | 223 | imonth = from.month(); |
224 | 224 | ||
225 | a = from.year() - e.start().date().year(); | 225 | a = from.year() - e.start().date().year(); |
226 | a *= 12; | 226 | a *= 12; |
227 | a = a + (imonth - e.start().date().month()); | 227 | a = a + (imonth - e.start().date().month()); |
228 | /* a is e.start()monthsFrom(from); */ | 228 | /* a is e.start()monthsFrom(from); */ |
229 | if(a % freq) { | 229 | if(a % freq) { |
230 | a = freq - (a % freq); | 230 | a = freq - (a % freq); |
231 | imonth = from.month() + a; | 231 | imonth = from.month() + a; |
232 | if (imonth > 12) { | 232 | if (imonth > 12) { |
233 | imonth--; | 233 | imonth--; |
234 | iyear += imonth / 12; | 234 | iyear += imonth / 12; |
235 | imonth = imonth % 12; | 235 | imonth = imonth % 12; |
236 | imonth++; | 236 | imonth++; |
237 | } | 237 | } |
238 | } | 238 | } |
239 | /* imonth is now the first month after or on | 239 | /* imonth is now the first month after or on |
240 | from that matches the frequencey given */ | 240 | from that matches the frequencey given */ |
241 | 241 | ||
242 | /* this could go for a while, worse case, 4*12 iterations, probably */ | 242 | /* this could go for a while, worse case, 4*12 iterations, probably */ |
243 | while(!QDate::isValid(iyear, imonth, iday) ) { | 243 | while(!QDate::isValid(iyear, imonth, iday) ) { |
244 | imonth += freq; | 244 | imonth += freq; |
245 | if (imonth > 12) { | 245 | if (imonth > 12) { |
246 | imonth--; | 246 | imonth--; |
247 | iyear += imonth / 12; | 247 | iyear += imonth / 12; |
248 | imonth = imonth % 12; | 248 | imonth = imonth % 12; |
249 | imonth++; | 249 | imonth++; |
250 | } | 250 | } |
251 | /* these loops could go for a while, check end case now */ | 251 | /* these loops could go for a while, check end case now */ |
252 | if ((QDate(iyear, imonth, 1) > e.repeatPattern().endDate()) && e.repeatPattern().hasEndDate) | 252 | if ((QDate(iyear, imonth, 1) > e.repeatPattern().endDate()) && e.repeatPattern().hasEndDate) |
253 | return FALSE; | 253 | return FALSE; |
254 | } | 254 | } |
255 | 255 | ||
256 | if(QDate(iyear, imonth, iday) >= from) { | 256 | if(QDate(iyear, imonth, iday) >= from) { |
257 | /* done */ | 257 | /* done */ |
258 | next = QDateTime(QDate(iyear, imonth, iday), | 258 | next = QDateTime(QDate(iyear, imonth, iday), |
259 | e.start().time()); | 259 | e.start().time()); |
260 | if ((next.date() > e.repeatPattern().endDate()) && e.repeatPattern().hasEndDate) | 260 | if ((next.date() > e.repeatPattern().endDate()) && e.repeatPattern().hasEndDate) |
261 | return FALSE; | 261 | return FALSE; |
262 | return TRUE; | 262 | return TRUE; |
263 | } | 263 | } |
264 | 264 | ||
265 | /* ok, need to cycle */ | 265 | /* ok, need to cycle */ |
266 | imonth += freq; | 266 | imonth += freq; |
267 | imonth--; | 267 | imonth--; |
268 | iyear += imonth / 12; | 268 | iyear += imonth / 12; |
269 | imonth = imonth % 12; | 269 | imonth = imonth % 12; |
270 | imonth++; | 270 | imonth++; |
271 | 271 | ||
272 | while(!QDate::isValid(iyear, imonth, iday) ) { | 272 | while(!QDate::isValid(iyear, imonth, iday) ) { |
273 | imonth += freq; | 273 | imonth += freq; |
274 | imonth--; | 274 | imonth--; |
275 | iyear += imonth / 12; | 275 | iyear += imonth / 12; |
276 | imonth = imonth % 12; | 276 | imonth = imonth % 12; |
277 | imonth++; | 277 | imonth++; |
278 | if ((QDate(iyear, imonth, 1) > e.repeatPattern().endDate()) && e.repeatPattern().hasEndDate) | 278 | if ((QDate(iyear, imonth, 1) > e.repeatPattern().endDate()) && e.repeatPattern().hasEndDate) |
279 | return FALSE; | 279 | return FALSE; |
280 | } | 280 | } |
281 | 281 | ||
282 | next = QDateTime(QDate(iyear, imonth, iday), e.start().time()); | 282 | next = QDateTime(QDate(iyear, imonth, iday), e.start().time()); |
283 | if ((next.date() > e.repeatPattern().endDate()) && e.repeatPattern().hasEndDate) | 283 | if ((next.date() > e.repeatPattern().endDate()) && e.repeatPattern().hasEndDate) |
284 | return FALSE; | 284 | return FALSE; |
285 | return TRUE; | 285 | return TRUE; |
286 | case Event::Yearly: | 286 | case Event::Yearly: |
287 | iday = e.start().date().day(); | 287 | iday = e.start().date().day(); |
288 | imonth = e.start().date().month(); | 288 | imonth = e.start().date().month(); |
289 | iyear = from.year(); // after all, we want to start in this year | 289 | iyear = from.year(); // after all, we want to start in this year |
290 | 290 | ||
291 | diff = 1; | 291 | diff = 1; |
292 | if(imonth == 2 && iday > 28) { | 292 | if(imonth == 2 && iday > 28) { |
293 | /* leap year, and it counts, calculate actual frequency */ | 293 | /* leap year, and it counts, calculate actual frequency */ |
294 | if(freq % 4) | 294 | if(freq % 4) |
295 | if (freq % 2) | 295 | if (freq % 2) |
296 | freq = freq * 4; | 296 | freq = freq * 4; |
297 | else | 297 | else |
298 | freq = freq * 2; | 298 | freq = freq * 2; |
299 | /* else divides by 4 already, leave freq alone */ | 299 | /* else divides by 4 already, leave freq alone */ |
300 | diff = 4; | 300 | diff = 4; |
301 | } | 301 | } |
302 | 302 | ||
303 | a = from.year() - e.start().date().year(); | 303 | a = from.year() - e.start().date().year(); |
304 | if(a % freq) { | 304 | if(a % freq) { |
305 | a = freq - (a % freq); | 305 | a = freq - (a % freq); |
306 | iyear = iyear + a; | 306 | iyear = iyear + a; |
307 | } | 307 | } |
308 | 308 | ||
309 | /* under the assumption we won't hit one of the special not-leap years twice */ | 309 | /* under the assumption we won't hit one of the special not-leap years twice */ |
310 | if(!QDate::isValid(iyear, imonth, iday)) { | 310 | if(!QDate::isValid(iyear, imonth, iday)) { |
311 | /* must have been skipping by leap years and hit one that wasn't, (e.g. 2100) */ | 311 | /* must have been skipping by leap years and hit one that wasn't, (e.g. 2100) */ |
312 | iyear += freq; | 312 | iyear += freq; |
313 | } | 313 | } |
314 | 314 | ||
315 | if(QDate(iyear, imonth, iday) >= from) { | 315 | if(QDate(iyear, imonth, iday) >= from) { |
316 | next = QDateTime(QDate(iyear, imonth, iday), | 316 | next = QDateTime(QDate(iyear, imonth, iday), |
317 | e.start().time()); | 317 | e.start().time()); |
318 | if ((next.date() > e.repeatPattern().endDate()) && e.repeatPattern().hasEndDate) | 318 | if ((next.date() > e.repeatPattern().endDate()) && e.repeatPattern().hasEndDate) |
319 | return FALSE; | 319 | return FALSE; |
320 | return TRUE; | 320 | return TRUE; |
321 | } | 321 | } |
322 | /* iyear == from.year(), need to advance again */ | 322 | /* iyear == from.year(), need to advance again */ |
323 | iyear += freq; | 323 | iyear += freq; |
324 | /* under the assumption we won't hit one of the special not-leap years twice */ | 324 | /* under the assumption we won't hit one of the special not-leap years twice */ |
325 | if(!QDate::isValid(iyear, imonth, iday)) { | 325 | if(!QDate::isValid(iyear, imonth, iday)) { |
326 | /* must have been skipping by leap years and hit one that wasn't, (e.g. 2100) */ | 326 | /* must have been skipping by leap years and hit one that wasn't, (e.g. 2100) */ |
327 | iyear += freq; | 327 | iyear += freq; |
328 | } | 328 | } |
329 | 329 | ||
330 | next = QDateTime(QDate(iyear, imonth, iday), e.start().time()); | 330 | next = QDateTime(QDate(iyear, imonth, iday), e.start().time()); |
331 | if ((next.date() > e.repeatPattern().endDate()) && e.repeatPattern().hasEndDate) | 331 | if ((next.date() > e.repeatPattern().endDate()) && e.repeatPattern().hasEndDate) |
332 | return FALSE; | 332 | return FALSE; |
333 | return TRUE; | 333 | return TRUE; |
334 | default: | 334 | default: |
335 | return FALSE; | 335 | return FALSE; |
336 | } | 336 | } |
337 | } | 337 | } |
338 | 338 | ||
339 | static bool nextAlarm( const Event &ev, QDateTime& when, int& warn) | 339 | static bool nextAlarm( const Event &ev, QDateTime& when, int& warn) |
340 | { | 340 | { |
341 | QDateTime now = QDateTime::currentDateTime(); | 341 | QDateTime now = QDateTime::currentDateTime(); |
342 | if ( ev.hasRepeat() ) { | 342 | if ( ev.hasRepeat() ) { |
343 | QDateTime ralarm; | 343 | QDateTime ralarm; |
344 | if (nextOccurance(ev, now.date(), ralarm)) { | 344 | if (nextOccurance(ev, now.date(), ralarm)) { |
345 | ralarm = ralarm.addSecs(-ev.alarmTime()*60); | 345 | ralarm = ralarm.addSecs(-ev.alarmTime()*60); |
346 | if ( ralarm > now ) { | 346 | if ( ralarm > now ) { |
347 | when = ralarm; | 347 | when = ralarm; |
348 | warn = ev.alarmTime(); | 348 | warn = ev.alarmTime(); |
349 | } else if ( nextOccurance(ev, now.date().addDays(1), ralarm) ) { | 349 | } else if ( nextOccurance(ev, now.date().addDays(1), ralarm) ) { |
350 | ralarm = ralarm.addSecs( -ev.alarmTime()*60 ); | 350 | ralarm = ralarm.addSecs( -ev.alarmTime()*60 ); |
351 | if ( ralarm > now ) { | 351 | if ( ralarm > now ) { |
352 | when = ralarm; | 352 | when = ralarm; |
353 | warn = ev.alarmTime(); | 353 | warn = ev.alarmTime(); |
354 | } | 354 | } |
355 | } | 355 | } |
356 | } | 356 | } |
357 | } else { | 357 | } else { |
358 | warn = ev.alarmTime(); | 358 | warn = ev.alarmTime(); |
359 | when = ev.start().addSecs( -ev.alarmTime()*60 ); | 359 | when = ev.start().addSecs( -ev.alarmTime()*60 ); |
360 | } | 360 | } |
361 | return when > now; | 361 | return when > now; |
362 | } | 362 | } |
363 | 363 | ||
364 | static void addEventAlarm( const Event &ev ) | 364 | static void addEventAlarm( const Event &ev ) |
365 | { | 365 | { |
366 | QDateTime when; | 366 | QDateTime when; |
367 | int warn; | 367 | int warn; |
368 | if ( nextAlarm(ev,when,warn) ) | 368 | if ( nextAlarm(ev,when,warn) ) |
369 | AlarmServer::addAlarm( when, | 369 | AlarmServer::addAlarm( when, |
370 | "QPE/Application/datebook", | 370 | "QPE/Application/datebook", |
371 | "alarm(QDateTime,int)", warn ); | 371 | "alarm(QDateTime,int)", warn ); |
372 | } | 372 | } |
373 | 373 | ||
374 | static void delEventAlarm( const Event &ev ) | 374 | static void delEventAlarm( const Event &ev ) |
375 | { | 375 | { |
376 | QDateTime when; | 376 | QDateTime when; |
377 | int warn; | 377 | int warn; |
378 | if ( nextAlarm(ev,when,warn) ) | 378 | if ( nextAlarm(ev,when,warn) ) |
379 | AlarmServer::deleteAlarm( when, | 379 | AlarmServer::deleteAlarm( when, |
380 | "QPE/Application/datebook", | 380 | "QPE/Application/datebook", |
381 | "alarm(QDateTime,int)", warn ); | 381 | "alarm(QDateTime,int)", warn ); |
382 | } | 382 | } |
383 | 383 | ||
384 | 384 | ||
385 | DateBookDB::DateBookDB() | 385 | DateBookDB::DateBookDB() |
386 | { | 386 | { |
387 | init(); | 387 | init(); |
388 | } | 388 | } |
389 | 389 | ||
390 | DateBookDB::~DateBookDB() | 390 | DateBookDB::~DateBookDB() |
391 | { | 391 | { |
392 | save(); | 392 | save(); |
393 | eventList.clear(); | 393 | eventList.clear(); |
394 | repeatEvents.clear(); | 394 | repeatEvents.clear(); |
395 | } | 395 | } |
396 | 396 | ||
397 | 397 | ||
398 | //#### Why is this code duplicated in getEffectiveEvents ????? | 398 | //#### Why is this code duplicated in getEffectiveEvents ????? |
399 | //#### Addendum. Don't use this function, lets faze it out if we can. | 399 | //#### Addendum. Don't use this function, lets faze it out if we can. |
400 | QValueList<Event> DateBookDB::getEvents( const QDate &from, const QDate &to ) | 400 | QValueList<Event> DateBookDB::getEvents( const QDate &from, const QDate &to ) |
401 | { | 401 | { |
402 | QValueList<Event> tmpList; | 402 | QValueList<Event> tmpList; |
403 | tmpList = getNonRepeatingEvents( from, to ); | 403 | tmpList = getNonRepeatingEvents( from, to ); |
404 | 404 | ||
405 | // check for repeating events... | 405 | // check for repeating events... |
406 | for (QValueList<Event>::ConstIterator it = repeatEvents.begin(); | 406 | for (QValueList<Event>::ConstIterator it = repeatEvents.begin(); |
407 | it != repeatEvents.end(); ++it) { | 407 | it != repeatEvents.end(); ++it) { |
408 | QDate itDate = from; | 408 | QDate itDate = from; |
409 | QDateTime due; | 409 | QDateTime due; |
410 | 410 | ||
411 | /* create a false end date, to short circuit on hard | 411 | /* create a false end date, to short circuit on hard |
412 | MonthlyDay recurences */ | 412 | MonthlyDay recurences */ |
413 | Event dummy_event = *it; | 413 | Event dummy_event = *it; |
414 | Event::RepeatPattern r = dummy_event.repeatPattern(); | 414 | Event::RepeatPattern r = dummy_event.repeatPattern(); |
415 | if ( !r.hasEndDate || r.endDate() > to ) { | 415 | if ( !r.hasEndDate || r.endDate() > to ) { |
416 | r.setEndDate( to ); | 416 | r.setEndDate( to ); |
417 | r.hasEndDate = TRUE; | 417 | r.hasEndDate = TRUE; |
418 | } | 418 | } |
419 | dummy_event.setRepeat(TRUE, r); | 419 | dummy_event.setRepeat(TRUE, r); |
420 | 420 | ||
421 | while (nextOccurance(dummy_event, itDate, due)) { | 421 | while (nextOccurance(dummy_event, itDate, due)) { |
422 | if (due.date() > to) | 422 | if (due.date() > to) |
423 | break; | 423 | break; |
424 | Event newEvent = *it; | 424 | Event newEvent = *it; |
425 | newEvent.setStart(due); | 425 | newEvent.setStart(due); |
426 | newEvent.setEnd(due.addSecs((*it).start().secsTo((*it).end()))); | 426 | newEvent.setEnd(due.addSecs((*it).start().secsTo((*it).end()))); |
427 | 427 | ||
428 | tmpList.append(newEvent); | 428 | tmpList.append(newEvent); |
429 | itDate = due.date().addDays(1); /* the next event */ | 429 | itDate = due.date().addDays(1); /* the next event */ |
430 | } | 430 | } |
431 | } | 431 | } |
432 | qHeapSort(tmpList); | 432 | qHeapSort(tmpList); |
433 | return tmpList; | 433 | return tmpList; |
434 | } | 434 | } |
435 | 435 | ||
436 | QValueList<Event> DateBookDB::getEvents( const QDateTime &start ) | 436 | QValueList<Event> DateBookDB::getEvents( const QDateTime &start ) |
437 | { | 437 | { |
438 | QValueList<Event> day = getEvents(start.date(),start.date()); | 438 | QValueList<Event> day = getEvents(start.date(),start.date()); |
439 | 439 | ||
440 | QValueListConstIterator<Event> it; | 440 | QValueListConstIterator<Event> it; |
441 | QDateTime dtTmp; | 441 | QDateTime dtTmp; |
442 | QValueList<Event> tmpList; | 442 | QValueList<Event> tmpList; |
443 | for (it = day.begin(); it != day.end(); ++it ) { | 443 | for (it = day.begin(); it != day.end(); ++it ) { |
444 | dtTmp = (*it).start(TRUE); | 444 | dtTmp = (*it).start(TRUE); |
445 | if ( dtTmp == start ) | 445 | if ( dtTmp == start ) |
446 | tmpList.append( *it ); | 446 | tmpList.append( *it ); |
447 | } | 447 | } |
448 | return tmpList; | 448 | return tmpList; |
449 | } | 449 | } |
450 | 450 | ||
451 | //#### Why is this code duplicated in getEvents ????? | 451 | //#### Why is this code duplicated in getEvents ????? |
452 | 452 | ||
453 | QValueList<EffectiveEvent> DateBookDB::getEffectiveEvents( const QDate &from, | 453 | QValueList<EffectiveEvent> DateBookDB::getEffectiveEvents( const QDate &from, |
454 | const QDate &to ) | 454 | const QDate &to ) |
455 | { | 455 | { |
456 | QValueList<EffectiveEvent> tmpList; | 456 | QValueList<EffectiveEvent> tmpList; |
457 | QValueListIterator<Event> it; | 457 | QValueListIterator<Event> it; |
458 | 458 | ||
459 | EffectiveEvent effEv; | 459 | EffectiveEvent effEv; |
460 | QDateTime dtTmp, | 460 | QDateTime dtTmp, |
461 | dtEnd; | 461 | dtEnd; |
462 | 462 | ||
463 | for (it = eventList.begin(); it != eventList.end(); ++it ) { | 463 | for (it = eventList.begin(); it != eventList.end(); ++it ) { |
464 | if (!(*it).isValidUid()) | 464 | if (!(*it).isValidUid()) |
465 | (*it).assignUid(); // FIXME: Hack to restore cleared uids | 465 | (*it).assignUid(); // FIXME: Hack to restore cleared uids |
466 | 466 | ||
467 | dtTmp = (*it).start(TRUE); | 467 | dtTmp = (*it).start(TRUE); |
468 | dtEnd = (*it).end(TRUE); | 468 | dtEnd = (*it).end(TRUE); |
469 | 469 | ||
470 | if ( dtTmp.date() >= from && dtTmp.date() <= to ) { | 470 | if ( dtTmp.date() >= from && dtTmp.date() <= to ) { |
471 | Event tmpEv = *it; | 471 | Event tmpEv = *it; |
472 | effEv.setEvent(tmpEv); | 472 | effEv.setEvent(tmpEv); |
473 | effEv.setDate( dtTmp.date() ); | 473 | effEv.setDate( dtTmp.date() ); |
474 | effEv.setStart( dtTmp.time() ); | 474 | effEv.setStart( dtTmp.time() ); |
475 | if ( dtTmp.date() != dtEnd.date() ) | 475 | if ( dtTmp.date() != dtEnd.date() ) |
476 | effEv.setEnd( QTime(23, 59, 0) ); | 476 | effEv.setEnd( QTime(23, 59, 0) ); |
477 | else | 477 | else |
478 | effEv.setEnd( dtEnd.time() ); | 478 | effEv.setEnd( dtEnd.time() ); |
479 | tmpList.append( effEv ); | 479 | tmpList.append( effEv ); |
480 | } | 480 | } |
481 | // we must also check for end date information... | 481 | // we must also check for end date information... |
482 | if ( dtEnd.date() != dtTmp.date() && dtEnd.date() >= from ) { | 482 | if ( dtEnd.date() != dtTmp.date() && dtEnd.date() >= from ) { |
483 | QDateTime dt = dtTmp.addDays( 1 ); | 483 | QDateTime dt = dtTmp.addDays( 1 ); |
484 | dt.setTime( QTime(0, 0, 0) ); | 484 | dt.setTime( QTime(0, 0, 0) ); |
485 | QDateTime dtStop; | 485 | QDateTime dtStop; |
486 | if ( dtEnd > to ) { | 486 | if ( dtEnd > to ) { |
487 | dtStop = to; | 487 | dtStop = to; |
488 | } else | 488 | } else |
489 | dtStop = dtEnd; | 489 | dtStop = dtEnd; |
490 | while ( dt <= dtStop ) { | 490 | while ( dt <= dtStop ) { |
491 | Event tmpEv = *it; | 491 | Event tmpEv = *it; |
492 | effEv.setEvent( tmpEv ); | 492 | effEv.setEvent( tmpEv ); |
493 | effEv.setDate( dt.date() ); | 493 | effEv.setDate( dt.date() ); |
494 | if ( dt >= from ) { | 494 | if ( dt >= from ) { |
495 | effEv.setStart( QTime(0, 0, 0) ); | 495 | effEv.setStart( QTime(0, 0, 0) ); |
496 | if ( dt.date() == dtEnd.date() ) | 496 | if ( dt.date() == dtEnd.date() ) |
497 | effEv.setEnd( dtEnd.time() ); | 497 | effEv.setEnd( dtEnd.time() ); |
498 | else | 498 | else |
499 | effEv.setEnd( QTime(23, 59, 59) ); | 499 | effEv.setEnd( QTime(23, 59, 59) ); |
500 | tmpList.append( effEv ); | 500 | tmpList.append( effEv ); |
501 | } | 501 | } |
502 | dt = dt.addDays( 1 ); | 502 | dt = dt.addDays( 1 ); |
503 | } | 503 | } |
504 | } | 504 | } |
505 | } | 505 | } |
506 | // check for repeating events... | 506 | // check for repeating events... |
507 | QDateTime repeat; | 507 | QDateTime repeat; |
508 | for ( it = repeatEvents.begin(); it != repeatEvents.end(); ++it ) { | 508 | for ( it = repeatEvents.begin(); it != repeatEvents.end(); ++it ) { |
509 | if (!(*it).isValidUid()) | 509 | if (!(*it).isValidUid()) |
510 | (*it).assignUid(); // FIXME: Hack to restore cleared uids | 510 | (*it).assignUid(); // FIXME: Hack to restore cleared uids |
511 | 511 | ||
512 | /* create a false end date, to short circuit on hard | 512 | /* create a false end date, to short circuit on hard |
513 | MonthlyDay recurences */ | 513 | MonthlyDay recurences */ |
514 | Event dummy_event = *it; | 514 | Event dummy_event = *it; |
515 | int duration = (*it).start().date().daysTo( (*it).end().date() ); | 515 | int duration = (*it).start().date().daysTo( (*it).end().date() ); |
516 | QDate itDate = from.addDays(-duration); | 516 | QDate itDate = from.addDays(-duration); |
517 | 517 | ||
518 | Event::RepeatPattern r = dummy_event.repeatPattern(); | 518 | Event::RepeatPattern r = dummy_event.repeatPattern(); |
519 | if ( !r.hasEndDate || r.endDate() > to ) { | 519 | if ( !r.hasEndDate || r.endDate() > to ) { |
520 | r.setEndDate( to ); | 520 | r.setEndDate( to ); |
521 | r.hasEndDate = TRUE; | 521 | r.hasEndDate = TRUE; |
522 | } | 522 | } |
523 | dummy_event.setRepeat(TRUE, r); | 523 | dummy_event.setRepeat(TRUE, r); |
524 | 524 | ||
525 | while (nextOccurance(dummy_event, itDate, repeat)) { | 525 | while (nextOccurance(dummy_event, itDate, repeat)) { |
526 | if(repeat.date() > to) | 526 | if(repeat.date() > to) |
527 | break; | 527 | break; |
528 | effEv.setDate( repeat.date() ); | 528 | effEv.setDate( repeat.date() ); |
529 | if ((*it).type() == Event::AllDay) { | 529 | if ((*it).type() == Event::AllDay) { |
530 | effEv.setStart( QTime(0,0,0) ); | 530 | effEv.setStart( QTime(0,0,0) ); |
531 | effEv.setEnd( QTime(23,59,59) ); | 531 | effEv.setEnd( QTime(23,59,59) ); |
532 | } else { | 532 | } else { |
533 | /* we only occur by days, not hours/minutes/seconds. Hence | 533 | /* we only occur by days, not hours/minutes/seconds. Hence |
534 | the actual end and start times will be the same for | 534 | the actual end and start times will be the same for |
535 | every repeated event. For multi day events this is | 535 | every repeated event. For multi day events this is |
536 | fixed up later if on wronge day span */ | 536 | fixed up later if on wronge day span */ |
537 | effEv.setStart( (*it).start().time() ); | 537 | effEv.setStart( (*it).start().time() ); |
538 | effEv.setEnd( (*it).end().time() ); | 538 | effEv.setEnd( (*it).end().time() ); |
539 | } | 539 | } |
540 | if ( duration != 0 ) { | 540 | if ( duration != 0 ) { |
541 | // multi-day repeating events | 541 | // multi-day repeating events |
542 | QDate sub_it = QMAX( repeat.date(), from ); | 542 | QDate sub_it = QMAX( repeat.date(), from ); |
543 | QDate startDate = repeat.date(); | 543 | QDate startDate = repeat.date(); |
544 | QDate endDate = startDate.addDays( duration ); | 544 | QDate endDate = startDate.addDays( duration ); |
545 | 545 | ||
546 | while ( sub_it <= endDate && sub_it <= to ) { | 546 | while ( sub_it <= endDate && sub_it <= to ) { |
547 | EffectiveEvent tmpEffEv = effEv; | 547 | EffectiveEvent tmpEffEv = effEv; |
548 | Event tmpEv = *it; | 548 | Event tmpEv = *it; |
549 | tmpEffEv.setEvent( tmpEv ); | 549 | tmpEffEv.setEvent( tmpEv ); |
550 | 550 | ||
551 | if ( sub_it != startDate ) | 551 | if ( sub_it != startDate ) |
552 | tmpEffEv.setStart( QTime(0,0,0) ); | 552 | tmpEffEv.setStart( QTime(0,0,0) ); |
553 | if ( sub_it != endDate ) | 553 | if ( sub_it != endDate ) |
554 | tmpEffEv.setEnd( QTime(23,59,59) ); | 554 | tmpEffEv.setEnd( QTime(23,59,59) ); |
555 | tmpEffEv.setDate( sub_it ); | 555 | tmpEffEv.setDate( sub_it ); |
556 | tmpEffEv.setEffectiveDates( startDate, endDate ); | 556 | tmpEffEv.setEffectiveDates( startDate, endDate ); |
557 | tmpList.append( tmpEffEv ); | 557 | tmpList.append( tmpEffEv ); |
558 | sub_it = sub_it.addDays( 1 ); | 558 | sub_it = sub_it.addDays( 1 ); |
559 | } | 559 | } |
560 | itDate = endDate; | 560 | itDate = endDate; |
561 | } else { | 561 | } else { |
562 | Event tmpEv = *it; | 562 | Event tmpEv = *it; |
563 | effEv.setEvent( tmpEv ); | 563 | effEv.setEvent( tmpEv ); |
564 | tmpList.append( effEv ); | 564 | tmpList.append( effEv ); |
565 | itDate = repeat.date().addDays( 1 ); | 565 | itDate = repeat.date().addDays( 1 ); |
566 | } | 566 | } |
567 | } | 567 | } |
568 | } | 568 | } |
569 | 569 | ||
570 | qHeapSort( tmpList ); | 570 | qHeapSort( tmpList ); |
571 | return tmpList; | 571 | return tmpList; |
572 | } | 572 | } |
573 | 573 | ||
574 | QValueList<EffectiveEvent> DateBookDB::getEffectiveEvents( const QDateTime &dt) | 574 | QValueList<EffectiveEvent> DateBookDB::getEffectiveEvents( const QDateTime &dt) |
575 | { | 575 | { |
576 | QValueList<EffectiveEvent> day = getEffectiveEvents(dt.date(), dt.date()); | 576 | QValueList<EffectiveEvent> day = getEffectiveEvents(dt.date(), dt.date()); |
577 | QValueListConstIterator<EffectiveEvent> it; | 577 | QValueListConstIterator<EffectiveEvent> it; |
578 | QValueList<EffectiveEvent> tmpList; | 578 | QValueList<EffectiveEvent> tmpList; |
579 | QDateTime dtTmp; | 579 | QDateTime dtTmp; |
580 | 580 | ||
581 | for (it = day.begin(); it != day.end(); ++it ) { | 581 | for (it = day.begin(); it != day.end(); ++it ) { |
582 | dtTmp = QDateTime( (*it).date(), (*it).start() ); | 582 | dtTmp = QDateTime( (*it).date(), (*it).start() ); |
583 | // at the moment we don't have second granularity, be nice about that.. | 583 | // at the moment we don't have second granularity, be nice about that.. |
584 | if ( QABS(dt.secsTo(dtTmp)) < 60 ) | 584 | if ( QABS(dt.secsTo(dtTmp)) < 60 ) |
585 | tmpList.append( *it ); | 585 | tmpList.append( *it ); |
586 | } | 586 | } |
587 | return tmpList; | 587 | return tmpList; |
588 | } | 588 | } |
589 | 589 | ||
590 | Event DateBookDB::getEvent( int uid ) { | ||
591 | QValueList<Event>::ConstIterator it; | ||
592 | |||
593 | for (it = eventList.begin(); it != eventList.end(); it++) { | ||
594 | if ((*it).uid() == uid) return *it; | ||
595 | } | ||
596 | for (it = repeatEvents.begin(); it != repeatEvents.end(); it++) { | ||
597 | if ((*it).uid() == uid) return *it; | ||
598 | } | ||
599 | |||
600 | qDebug("Event not found: uid=%d\n", uid); | ||
601 | } | ||
602 | |||
603 | |||
604 | void DateBookDB::addEvent( const Event &ev, bool doalarm ) | 590 | void DateBookDB::addEvent( const Event &ev, bool doalarm ) |
605 | { | 591 | { |
606 | // write to the journal... | 592 | // write to the journal... |
607 | saveJournalEntry( ev, ACTION_ADD, -1, false ); | 593 | saveJournalEntry( ev, ACTION_ADD, -1, false ); |
608 | addJFEvent( ev, doalarm ); | 594 | addJFEvent( ev, doalarm ); |
609 | d->clean = false; | 595 | d->clean = false; |
610 | } | 596 | } |
611 | 597 | ||
612 | void DateBookDB::addJFEvent( const Event &ev, bool doalarm ) | 598 | void DateBookDB::addJFEvent( const Event &ev, bool doalarm ) |
613 | { | 599 | { |
614 | if ( doalarm && ev.hasAlarm() ) | 600 | if ( doalarm && ev.hasAlarm() ) |
615 | addEventAlarm( ev ); | 601 | addEventAlarm( ev ); |
616 | if ( ev.hasRepeat() ) | 602 | if ( ev.hasRepeat() ) |
617 | repeatEvents.append( ev ); | 603 | repeatEvents.append( ev ); |
618 | else | 604 | else |
619 | eventList.append( ev ); | 605 | eventList.append( ev ); |
620 | } | 606 | } |
621 | 607 | ||
622 | void DateBookDB::editEvent( const Event &old, Event &editedEv ) | 608 | void DateBookDB::editEvent( const Event &old, Event &editedEv ) |
623 | { | 609 | { |
624 | int oldIndex=0; | 610 | int oldIndex=0; |
625 | bool oldHadRepeat = old.hasRepeat(); | 611 | bool oldHadRepeat = old.hasRepeat(); |
626 | Event orig; | 612 | Event orig; |
627 | 613 | ||
628 | // write to the journal... | 614 | // write to the journal... |
629 | if ( oldHadRepeat ) { | 615 | if ( oldHadRepeat ) { |
630 | if ( origRepeat( old, orig ) ) // should work always... | 616 | if ( origRepeat( old, orig ) ) // should work always... |
631 | oldIndex = repeatEvents.findIndex( orig ); | 617 | oldIndex = repeatEvents.findIndex( orig ); |
632 | } else | 618 | } else |
633 | oldIndex = eventList.findIndex( old ); | 619 | oldIndex = eventList.findIndex( old ); |
634 | saveJournalEntry( editedEv, ACTION_REPLACE, oldIndex, oldHadRepeat ); | 620 | saveJournalEntry( editedEv, ACTION_REPLACE, oldIndex, oldHadRepeat ); |
635 | 621 | ||
636 | // Delete old event | 622 | // Delete old event |
637 | if ( old.hasAlarm() ) | 623 | if ( old.hasAlarm() ) |
638 | delEventAlarm( old ); | 624 | delEventAlarm( old ); |
639 | if ( oldHadRepeat ) { | 625 | if ( oldHadRepeat ) { |
640 | if ( editedEv.hasRepeat() ) { // This mean that origRepeat was run above and | 626 | if ( editedEv.hasRepeat() ) { // This mean that origRepeat was run above and |
641 | // orig is initialized | 627 | // orig is initialized |
642 | // assumption, when someone edits a repeating event, they | 628 | // assumption, when someone edits a repeating event, they |
643 | // want to change them all, maybe not perfect, but it works | 629 | // want to change them all, maybe not perfect, but it works |
644 | // for the moment... | 630 | // for the moment... |
645 | repeatEvents.remove( orig ); | 631 | repeatEvents.remove( orig ); |
646 | } else | 632 | } else |
647 | removeRepeat( old ); | 633 | removeRepeat( old ); |
648 | } else { | 634 | } else { |
649 | QValueList<Event>::Iterator it = eventList.find( old ); | 635 | QValueList<Event>::Iterator it = eventList.find( old ); |
650 | if ( it != eventList.end() ) | 636 | if ( it != eventList.end() ) |
651 | eventList.remove( it ); | 637 | eventList.remove( it ); |
652 | } | 638 | } |
653 | 639 | ||
654 | // Add new event | 640 | // Add new event |
655 | if ( editedEv.hasAlarm() ) | 641 | if ( editedEv.hasAlarm() ) |
656 | addEventAlarm( editedEv ); | 642 | addEventAlarm( editedEv ); |
657 | if ( editedEv.hasRepeat() ) | 643 | if ( editedEv.hasRepeat() ) |
658 | repeatEvents.append( editedEv ); | 644 | repeatEvents.append( editedEv ); |
659 | else | 645 | else |
660 | eventList.append( editedEv ); | 646 | eventList.append( editedEv ); |
661 | 647 | ||
662 | d->clean = false; | 648 | d->clean = false; |
663 | } | 649 | } |
664 | 650 | ||
665 | void DateBookDB::removeEvent( const Event &ev ) | 651 | void DateBookDB::removeEvent( const Event &ev ) |
666 | { | 652 | { |
667 | // write to the journal... | 653 | // write to the journal... |
668 | saveJournalEntry( ev, ACTION_REMOVE, -1, false ); | 654 | saveJournalEntry( ev, ACTION_REMOVE, -1, false ); |
669 | removeJFEvent( ev ); | 655 | removeJFEvent( ev ); |
670 | d->clean = false; | 656 | d->clean = false; |
671 | } | 657 | } |
672 | 658 | ||
673 | void DateBookDB::removeJFEvent( const Event&ev ) | 659 | void DateBookDB::removeJFEvent( const Event&ev ) |
674 | { | 660 | { |
675 | if ( ev.hasAlarm() ) | 661 | if ( ev.hasAlarm() ) |
676 | delEventAlarm( ev ); | 662 | delEventAlarm( ev ); |
677 | if ( ev.hasRepeat() ) { | 663 | if ( ev.hasRepeat() ) { |
678 | removeRepeat( ev ); | 664 | removeRepeat( ev ); |
679 | } else { | 665 | } else { |
680 | QValueList<Event>::Iterator it = eventList.find( ev ); | 666 | QValueList<Event>::Iterator it = eventList.find( ev ); |
681 | if ( it != eventList.end() ) | 667 | if ( it != eventList.end() ) |
682 | eventList.remove( it ); | 668 | eventList.remove( it ); |
683 | } | 669 | } |
684 | } | 670 | } |
685 | 671 | ||
686 | // also handles journaling... | 672 | // also handles journaling... |
687 | void DateBookDB::loadFile( const QString &strFile ) | 673 | void DateBookDB::loadFile( const QString &strFile ) |
688 | { | 674 | { |
689 | 675 | ||
690 | QFile f( strFile ); | 676 | QFile f( strFile ); |
691 | if ( !f.open( IO_ReadOnly ) ) | 677 | if ( !f.open( IO_ReadOnly ) ) |
692 | return; | 678 | return; |
693 | 679 | ||
694 | enum Attribute { | 680 | enum Attribute { |
695 | FDescription = 0, | 681 | FDescription = 0, |
696 | FLocation, | 682 | FLocation, |
697 | FCategories, | 683 | FCategories, |
698 | FUid, | 684 | FUid, |
699 | FType, | 685 | FType, |
700 | FAlarm, | 686 | FAlarm, |
701 | FSound, | 687 | FSound, |
702 | FRType, | 688 | FRType, |
703 | FRWeekdays, | 689 | FRWeekdays, |
704 | FRPosition, | 690 | FRPosition, |
705 | FRFreq, | 691 | FRFreq, |
706 | FRHasEndDate, | 692 | FRHasEndDate, |
707 | FREndDate, | 693 | FREndDate, |
708 | FRStart, | 694 | FRStart, |
709 | FREnd, | 695 | FREnd, |
710 | FNote, | 696 | FNote, |
711 | FCreated, | 697 | FCreated, |
712 | FAction, | 698 | FAction, |
713 | FActionKey, | 699 | FActionKey, |
714 | FJournalOrigHadRepeat | 700 | FJournalOrigHadRepeat |
715 | }; | 701 | }; |
716 | 702 | ||
717 | QAsciiDict<int> dict( 97 ); | 703 | QAsciiDict<int> dict( 97 ); |
718 | dict.setAutoDelete( TRUE ); | 704 | dict.setAutoDelete( TRUE ); |
719 | dict.insert( "description", new int(FDescription) ); | 705 | dict.insert( "description", new int(FDescription) ); |
720 | dict.insert( "location", new int(FLocation) ); | 706 | dict.insert( "location", new int(FLocation) ); |
721 | dict.insert( "categories", new int(FCategories) ); | 707 | dict.insert( "categories", new int(FCategories) ); |
722 | dict.insert( "uid", new int(FUid) ); | 708 | dict.insert( "uid", new int(FUid) ); |
723 | dict.insert( "type", new int(FType) ); | 709 | dict.insert( "type", new int(FType) ); |
724 | dict.insert( "alarm", new int(FAlarm) ); | 710 | dict.insert( "alarm", new int(FAlarm) ); |
725 | dict.insert( "sound", new int(FSound) ); | 711 | dict.insert( "sound", new int(FSound) ); |
726 | dict.insert( "rtype", new int(FRType) ); | 712 | dict.insert( "rtype", new int(FRType) ); |
727 | dict.insert( "rweekdays", new int(FRWeekdays) ); | 713 | dict.insert( "rweekdays", new int(FRWeekdays) ); |
728 | dict.insert( "rposition", new int(FRPosition) ); | 714 | dict.insert( "rposition", new int(FRPosition) ); |
729 | dict.insert( "rfreq", new int(FRFreq) ); | 715 | dict.insert( "rfreq", new int(FRFreq) ); |
730 | dict.insert( "rhasenddate", new int(FRHasEndDate) ); | 716 | dict.insert( "rhasenddate", new int(FRHasEndDate) ); |
731 | dict.insert( "enddt", new int(FREndDate) ); | 717 | dict.insert( "enddt", new int(FREndDate) ); |
732 | dict.insert( "start", new int(FRStart) ); | 718 | dict.insert( "start", new int(FRStart) ); |
733 | dict.insert( "end", new int(FREnd) ); | 719 | dict.insert( "end", new int(FREnd) ); |
734 | dict.insert( "note", new int(FNote) ); | 720 | dict.insert( "note", new int(FNote) ); |
735 | dict.insert( "created", new int(FCreated) ); | 721 | dict.insert( "created", new int(FCreated) ); |
736 | dict.insert( "action", new int(FAction) ); | 722 | dict.insert( "action", new int(FAction) ); |
737 | dict.insert( "actionkey", new int(FActionKey) ); | 723 | dict.insert( "actionkey", new int(FActionKey) ); |
738 | dict.insert( "actionorig", new int (FJournalOrigHadRepeat) ); | 724 | dict.insert( "actionorig", new int (FJournalOrigHadRepeat) ); |
739 | 725 | ||
740 | 726 | ||
741 | QByteArray ba = f.readAll(); | 727 | QByteArray ba = f.readAll(); |
742 | char* dt = ba.data(); | 728 | char* dt = ba.data(); |
743 | int len = ba.size(); | 729 | int len = ba.size(); |
744 | int currentAction, | 730 | int currentAction, |
745 | journalKey, | 731 | journalKey, |
746 | origHadRepeat; // should be bool, but we need tri-state(not being used) | 732 | origHadRepeat; // should be bool, but we need tri-state(not being used) |
747 | 733 | ||
748 | int i = 0; | 734 | int i = 0; |
749 | char *point; | 735 | char *point; |
750 | while ( ( point = strstr( dt+i, "<event " ) ) != 0 ) { | 736 | while ( ( point = strstr( dt+i, "<event " ) ) != 0 ) { |
751 | i = point - dt; | 737 | i = point - dt; |
752 | // if we are reading in events in the general case, | 738 | // if we are reading in events in the general case, |
753 | // we are just adding them, so let the actions represent that... | 739 | // we are just adding them, so let the actions represent that... |
754 | currentAction = ACTION_ADD; | 740 | currentAction = ACTION_ADD; |
755 | journalKey = -1; | 741 | journalKey = -1; |
756 | origHadRepeat = -1; | 742 | origHadRepeat = -1; |
757 | // some temporary variables for dates and times ... | 743 | // some temporary variables for dates and times ... |
758 | //int startY = 0, startM = 0, startD = 0, starth = 0, startm = 0, starts = 0; | 744 | //int startY = 0, startM = 0, startD = 0, starth = 0, startm = 0, starts = 0; |
759 | //int endY = 0, endM = 0, endD = 0, endh = 0, endm = 0, ends = 0; | 745 | //int endY = 0, endM = 0, endD = 0, endh = 0, endm = 0, ends = 0; |
760 | //int enddtY = 0, enddtM = 0, enddtD = 0; | 746 | //int enddtY = 0, enddtM = 0, enddtD = 0; |
761 | 747 | ||
762 | // ... for the alarm settings ... | 748 | // ... for the alarm settings ... |
763 | int alarmTime = -1; Event::SoundTypeChoice alarmSound = Event::Silent; | 749 | int alarmTime = -1; Event::SoundTypeChoice alarmSound = Event::Silent; |
764 | // ... and for the recurrence | 750 | // ... and for the recurrence |
765 | Event::RepeatPattern rp; | 751 | Event::RepeatPattern rp; |
766 | Event e; | 752 | Event e; |
767 | 753 | ||
768 | i += 7; | 754 | i += 7; |
769 | 755 | ||
770 | while( 1 ) { | 756 | while( 1 ) { |
771 | while ( i < len && (dt[i] == ' ' || dt[i] == '\n' || dt[i] == '\r') ) | 757 | while ( i < len && (dt[i] == ' ' || dt[i] == '\n' || dt[i] == '\r') ) |
772 | ++i; | 758 | ++i; |
773 | if ( i >= len-2 || (dt[i] == '/' && dt[i+1] == '>') ) | 759 | if ( i >= len-2 || (dt[i] == '/' && dt[i+1] == '>') ) |
774 | break; | 760 | break; |
775 | // we have another attribute, read it. | 761 | // we have another attribute, read it. |
776 | int j = i; | 762 | int j = i; |
777 | while ( j < len && dt[j] != '=' ) | 763 | while ( j < len && dt[j] != '=' ) |
778 | ++j; | 764 | ++j; |
779 | char *attr = dt+i; | 765 | char *attr = dt+i; |
780 | dt[j] = '\0'; | 766 | dt[j] = '\0'; |
781 | i = ++j; // skip = | 767 | i = ++j; // skip = |
782 | while ( i < len && dt[i] != '"' ) | 768 | while ( i < len && dt[i] != '"' ) |
783 | ++i; | 769 | ++i; |
784 | j = ++i; | 770 | j = ++i; |
785 | bool haveAmp = FALSE; | 771 | bool haveAmp = FALSE; |
786 | bool haveUtf = FALSE; | 772 | bool haveUtf = FALSE; |
787 | while ( j < len && dt[j] != '"' ) { | 773 | while ( j < len && dt[j] != '"' ) { |
788 | if ( dt[j] == '&' ) | 774 | if ( dt[j] == '&' ) |
789 | haveAmp = TRUE; | 775 | haveAmp = TRUE; |
790 | if ( ((unsigned char)dt[j]) > 0x7f ) | 776 | if ( ((unsigned char)dt[j]) > 0x7f ) |
791 | haveUtf = TRUE; | 777 | haveUtf = TRUE; |
792 | ++j; | 778 | ++j; |
793 | } | 779 | } |
794 | 780 | ||
795 | if ( i == j ) { | 781 | if ( i == j ) { |
796 | // leave out empty attributes | 782 | // leave out empty attributes |
797 | i = j + 1; | 783 | i = j + 1; |
798 | continue; | 784 | continue; |
799 | } | 785 | } |
800 | 786 | ||
801 | QString value = haveUtf ? QString::fromUtf8( dt+i, j-i ) | 787 | QString value = haveUtf ? QString::fromUtf8( dt+i, j-i ) |
802 | : QString::fromLatin1( dt+i, j-i ); | 788 | : QString::fromLatin1( dt+i, j-i ); |
803 | if ( haveAmp ) | 789 | if ( haveAmp ) |
804 | value = Qtopia::plainString( value ); | 790 | value = Qtopia::plainString( value ); |
805 | i = j + 1; | 791 | i = j + 1; |
806 | 792 | ||
807 | //qDebug("attr='%s' value='%s'", attr.data(), value.latin1() ); | 793 | //qDebug("attr='%s' value='%s'", attr.data(), value.latin1() ); |
808 | int * find = dict[ attr ]; | 794 | int * find = dict[ attr ]; |
809 | #if 1 | 795 | #if 1 |
810 | if ( !find ) { | 796 | if ( !find ) { |
811 | // custom field | 797 | // custom field |
812 | e.setCustomField(attr, value); | 798 | e.setCustomField(attr, value); |
813 | continue; | 799 | continue; |
814 | } | 800 | } |
815 | 801 | ||
816 | switch( *find ) { | 802 | switch( *find ) { |
817 | case FDescription: | 803 | case FDescription: |
818 | e.setDescription( value ); | 804 | e.setDescription( value ); |
819 | break; | 805 | break; |
820 | case FLocation: | 806 | case FLocation: |
821 | e.setLocation( value ); | 807 | e.setLocation( value ); |
822 | break; | 808 | break; |
823 | case FCategories: | 809 | case FCategories: |
824 | e.setCategories( Qtopia::Record::idsFromString( value ) ); | 810 | e.setCategories( Qtopia::Record::idsFromString( value ) ); |
825 | break; | 811 | break; |
826 | case FUid: | 812 | case FUid: |
827 | e.setUid( value.toInt() ); | 813 | e.setUid( value.toInt() ); |
828 | break; | 814 | break; |
829 | case FType: | 815 | case FType: |
830 | if ( value == "AllDay" ) | 816 | if ( value == "AllDay" ) |
831 | e.setType( Event::AllDay ); | 817 | e.setType( Event::AllDay ); |
832 | else | 818 | else |
833 | e.setType( Event::Normal ); | 819 | e.setType( Event::Normal ); |
834 | break; | 820 | break; |
835 | case FAlarm: | 821 | case FAlarm: |
836 | alarmTime = value.toInt(); | 822 | alarmTime = value.toInt(); |
837 | break; | 823 | break; |
838 | case FSound: | 824 | case FSound: |
839 | alarmSound = value == "loud" ? Event::Loud : Event::Silent; | 825 | alarmSound = value == "loud" ? Event::Loud : Event::Silent; |
840 | break; | 826 | break; |
841 | // recurrence stuff | 827 | // recurrence stuff |
842 | case FRType: | 828 | case FRType: |
843 | if ( value == "Daily" ) | 829 | if ( value == "Daily" ) |
844 | rp.type = Event::Daily; | 830 | rp.type = Event::Daily; |
845 | else if ( value == "Weekly" ) | 831 | else if ( value == "Weekly" ) |
846 | rp.type = Event::Weekly; | 832 | rp.type = Event::Weekly; |
847 | else if ( value == "MonthlyDay" ) | 833 | else if ( value == "MonthlyDay" ) |
848 | rp.type = Event::MonthlyDay; | 834 | rp.type = Event::MonthlyDay; |
849 | else if ( value == "MonthlyDate" ) | 835 | else if ( value == "MonthlyDate" ) |
850 | rp.type = Event::MonthlyDate; | 836 | rp.type = Event::MonthlyDate; |
851 | else if ( value == "Yearly" ) | 837 | else if ( value == "Yearly" ) |
852 | rp.type = Event::Yearly; | 838 | rp.type = Event::Yearly; |
853 | else | 839 | else |
854 | rp.type = Event::NoRepeat; | 840 | rp.type = Event::NoRepeat; |
855 | break; | 841 | break; |
856 | case FRWeekdays: | 842 | case FRWeekdays: |
857 | rp.days = value.toInt(); | 843 | rp.days = value.toInt(); |
858 | break; | 844 | break; |
859 | case FRPosition: | 845 | case FRPosition: |
860 | rp.position = value.toInt(); | 846 | rp.position = value.toInt(); |
861 | break; | 847 | break; |
862 | case FRFreq: | 848 | case FRFreq: |
863 | rp.frequency = value.toInt(); | 849 | rp.frequency = value.toInt(); |
864 | break; | 850 | break; |
865 | case FRHasEndDate: | 851 | case FRHasEndDate: |
866 | rp.hasEndDate = value.toInt(); | 852 | rp.hasEndDate = value.toInt(); |
867 | break; | 853 | break; |
868 | case FREndDate: { | 854 | case FREndDate: { |
869 | rp.endDateUTC = (time_t) value.toLong(); | 855 | rp.endDateUTC = (time_t) value.toLong(); |
870 | break; | 856 | break; |
871 | } | 857 | } |
872 | case FRStart: { | 858 | case FRStart: { |
873 | e.setStart( (time_t) value.toLong() ); | 859 | e.setStart( (time_t) value.toLong() ); |
874 | break; | 860 | break; |
875 | } | 861 | } |
876 | case FREnd: { | 862 | case FREnd: { |
877 | e.setEnd( (time_t) value.toLong() ); | 863 | e.setEnd( (time_t) value.toLong() ); |
878 | break; | 864 | break; |
879 | } | 865 | } |
880 | case FNote: | 866 | case FNote: |
881 | e.setNotes( value ); | 867 | e.setNotes( value ); |
882 | break; | 868 | break; |
883 | case FCreated: | 869 | case FCreated: |
884 | rp.createTime = value.toInt(); | 870 | rp.createTime = value.toInt(); |
885 | break; | 871 | break; |
886 | case FAction: | 872 | case FAction: |
887 | currentAction = value.toInt(); | 873 | currentAction = value.toInt(); |
888 | break; | 874 | break; |
889 | case FActionKey: | 875 | case FActionKey: |
890 | journalKey = value.toInt(); | 876 | journalKey = value.toInt(); |
891 | break; | 877 | break; |
892 | case FJournalOrigHadRepeat: | 878 | case FJournalOrigHadRepeat: |
893 | origHadRepeat = value.toInt(); | 879 | origHadRepeat = value.toInt(); |
894 | break; | 880 | break; |
895 | default: | 881 | default: |
896 | qDebug( "huh??? missing enum? -- attr.: %s", attr ); | 882 | qDebug( "huh??? missing enum? -- attr.: %s", attr ); |
897 | break; | 883 | break; |
898 | } | 884 | } |
899 | #endif | 885 | #endif |
900 | } | 886 | } |
901 | // "post processing" (dates, times, alarm, recurrence) | 887 | // "post processing" (dates, times, alarm, recurrence) |
902 | // start date/time | 888 | // start date/time |
903 | e.setRepeat( rp.type != Event::NoRepeat, rp ); | 889 | e.setRepeat( rp.type != Event::NoRepeat, rp ); |
904 | 890 | ||
905 | if ( alarmTime != -1 ) | 891 | if ( alarmTime != -1 ) |
906 | e.setAlarm( TRUE, alarmTime, alarmSound ); | 892 | e.setAlarm( TRUE, alarmTime, alarmSound ); |
907 | 893 | ||
908 | // now do our action based on the current action... | 894 | // now do our action based on the current action... |
909 | switch ( currentAction ) { | 895 | switch ( currentAction ) { |
910 | case ACTION_ADD: | 896 | case ACTION_ADD: |
911 | addJFEvent( e ); | 897 | addJFEvent( e ); |
912 | break; | 898 | break; |
913 | case ACTION_REMOVE: | 899 | case ACTION_REMOVE: |
914 | removeJFEvent( e ); | 900 | removeJFEvent( e ); |
915 | break; | 901 | break; |
916 | case ACTION_REPLACE: | 902 | case ACTION_REPLACE: |
917 | // be a little bit careful, | 903 | // be a little bit careful, |
918 | // in case of a messed up journal... | 904 | // in case of a messed up journal... |
919 | if ( journalKey > -1 && origHadRepeat > -1 ) { | 905 | if ( journalKey > -1 && origHadRepeat > -1 ) { |
920 | // get the original from proper list... | 906 | // get the original from proper list... |
921 | if ( origHadRepeat ) | 907 | if ( origHadRepeat ) |
922 | removeJFEvent( *(repeatEvents.at(journalKey)) ); | 908 | removeJFEvent( *(repeatEvents.at(journalKey)) ); |
923 | else | 909 | else |
924 | removeJFEvent( *(eventList.at(journalKey)) ); | 910 | removeJFEvent( *(eventList.at(journalKey)) ); |
925 | addJFEvent( e ); | 911 | addJFEvent( e ); |
926 | } | 912 | } |
927 | break; | 913 | break; |
928 | default: | 914 | default: |
929 | break; | 915 | break; |
930 | } | 916 | } |
931 | } | 917 | } |
932 | f.close(); | 918 | f.close(); |
933 | } | 919 | } |
934 | 920 | ||
935 | void DateBookDB::init() | 921 | void DateBookDB::init() |
936 | { | 922 | { |
937 | d = new DateBookDBPrivate; | 923 | d = new DateBookDBPrivate; |
938 | d->clean = false; | 924 | d->clean = false; |
939 | QString str = dateBookFilename(); | 925 | QString str = dateBookFilename(); |
940 | if ( str.isNull() ) { | 926 | if ( str.isNull() ) { |
941 | QMessageBox::warning( 0, QObject::tr("Out of Space"), | 927 | QMessageBox::warning( 0, QObject::tr("Out of Space"), |
942 | QObject::tr("Unable to create start up files\n" | 928 | QObject::tr("Unable to create start up files\n" |
943 | "Please free up some space\n" | 929 | "Please free up some space\n" |
944 | "before entering data") ); | 930 | "before entering data") ); |
945 | } | 931 | } |
946 | // continuing along, we call this datebook filename again, | 932 | // continuing along, we call this datebook filename again, |
947 | // because they may fix it before continuing, though it seems | 933 | // because they may fix it before continuing, though it seems |
948 | // pretty unlikely... | 934 | // pretty unlikely... |
949 | loadFile( dateBookFilename() ); | 935 | loadFile( dateBookFilename() ); |
950 | 936 | ||
951 | if ( QFile::exists( dateBookJournalFile() ) ) { | 937 | if ( QFile::exists( dateBookJournalFile() ) ) { |
952 | // merge the journal | 938 | // merge the journal |
953 | loadFile( dateBookJournalFile() ); | 939 | loadFile( dateBookJournalFile() ); |
954 | // save in our changes and remove the journal... | 940 | // save in our changes and remove the journal... |
955 | save(); | 941 | save(); |
956 | } | 942 | } |
957 | d->clean = true; | 943 | d->clean = true; |
958 | } | 944 | } |
959 | 945 | ||
960 | bool DateBookDB::save() | 946 | bool DateBookDB::save() |
961 | { | 947 | { |
962 | if ( d->clean == true ) | 948 | if ( d->clean == true ) |
963 | return true; | 949 | return true; |
964 | QValueListIterator<Event> it; | 950 | QValueListIterator<Event> it; |
965 | int total_written; | 951 | int total_written; |
966 | QString strFileNew = dateBookFilename() + ".new"; | 952 | QString strFileNew = dateBookFilename() + ".new"; |
967 | 953 | ||
968 | QFile f( strFileNew ); | 954 | QFile f( strFileNew ); |
969 | if ( !f.open( IO_WriteOnly|IO_Raw ) ) | 955 | if ( !f.open( IO_WriteOnly|IO_Raw ) ) |
970 | return FALSE; | 956 | return FALSE; |
971 | 957 | ||
972 | QString buf( "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" ); | 958 | QString buf( "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" ); |
973 | buf += "<!DOCTYPE DATEBOOK><DATEBOOK>\n"; | 959 | buf += "<!DOCTYPE DATEBOOK><DATEBOOK>\n"; |
974 | buf += "<events>\n"; | 960 | buf += "<events>\n"; |
975 | QCString str = buf.utf8(); | 961 | QCString str = buf.utf8(); |
976 | total_written = f.writeBlock( str.data(), str.length() ); | 962 | total_written = f.writeBlock( str.data(), str.length() ); |
977 | if ( total_written != int(str.length()) ) { | 963 | if ( total_written != int(str.length()) ) { |
978 | f.close(); | 964 | f.close(); |
979 | QFile::remove( strFileNew ); | 965 | QFile::remove( strFileNew ); |
980 | return false; | 966 | return false; |
981 | } | 967 | } |
982 | 968 | ||
983 | for ( it = eventList.begin(); it != eventList.end(); ++it ) { | 969 | for ( it = eventList.begin(); it != eventList.end(); ++it ) { |
984 | buf = "<event"; | 970 | buf = "<event"; |
985 | (*it).save( buf ); | 971 | (*it).save( buf ); |
986 | buf += " />\n"; | 972 | buf += " />\n"; |
987 | str = buf.utf8(); | 973 | str = buf.utf8(); |
diff --git a/library/datebookdb.h b/library/datebookdb.h index e4c251c..0add028 100644 --- a/library/datebookdb.h +++ b/library/datebookdb.h | |||
@@ -1,88 +1,87 @@ | |||
1 | /********************************************************************** | 1 | /********************************************************************** |
2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. | 2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. |
3 | ** | 3 | ** |
4 | ** This file is part of Qtopia Environment. | 4 | ** This file is part of Qtopia Environment. |
5 | ** | 5 | ** |
6 | ** This file may be distributed and/or modified under the terms of the | 6 | ** This file may be distributed and/or modified under the terms of the |
7 | ** GNU General Public License version 2 as published by the Free Software | 7 | ** GNU General Public License version 2 as published by the Free Software |
8 | ** Foundation and appearing in the file LICENSE.GPL included in the | 8 | ** Foundation and appearing in the file LICENSE.GPL included in the |
9 | ** packaging of this file. | 9 | ** packaging of this file. |
10 | ** | 10 | ** |
11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | 11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE |
12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | 12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
13 | ** | 13 | ** |
14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | 14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. |
15 | ** | 15 | ** |
16 | ** Contact info@trolltech.com if any conditions of this licensing are | 16 | ** Contact info@trolltech.com if any conditions of this licensing are |
17 | ** not clear to you. | 17 | ** not clear to you. |
18 | ** | 18 | ** |
19 | **********************************************************************/ | 19 | **********************************************************************/ |
20 | 20 | ||
21 | #ifndef DATEBOOKDB_H | 21 | #ifndef DATEBOOKDB_H |
22 | #define DATEBOOKDB_H | 22 | #define DATEBOOKDB_H |
23 | 23 | ||
24 | #include <qdatetime.h> | 24 | #include <qdatetime.h> |
25 | #include <qfile.h> | 25 | #include <qfile.h> |
26 | #include <qvaluelist.h> | 26 | #include <qvaluelist.h> |
27 | #include <qpe/event.h> | 27 | #include <qpe/event.h> |
28 | 28 | ||
29 | // journal actions... | 29 | // journal actions... |
30 | enum journal_action { ACTION_ADD, ACTION_REMOVE, ACTION_REPLACE }; | 30 | enum journal_action { ACTION_ADD, ACTION_REMOVE, ACTION_REPLACE }; |
31 | 31 | ||
32 | class DateBookDBPrivate; | 32 | class DateBookDBPrivate; |
33 | class DateBookDB | 33 | class DateBookDB |
34 | { | 34 | { |
35 | public: | 35 | public: |
36 | DateBookDB(); | 36 | DateBookDB(); |
37 | ~DateBookDB(); | 37 | ~DateBookDB(); |
38 | 38 | ||
39 | // very depreciated now!!! | 39 | // very depreciated now!!! |
40 | QValueList<Event> getEvents( const QDate &from, const QDate &to ); | 40 | QValueList<Event> getEvents( const QDate &from, const QDate &to ); |
41 | QValueList<Event> getEvents( const QDateTime &start ); | 41 | QValueList<Event> getEvents( const QDateTime &start ); |
42 | 42 | ||
43 | // USE THESE!!! | 43 | // USE THESE!!! |
44 | QValueList<EffectiveEvent> getEffectiveEvents( const QDate &from, | 44 | QValueList<EffectiveEvent> getEffectiveEvents( const QDate &from, |
45 | const QDate &to ); | 45 | const QDate &to ); |
46 | QValueList<EffectiveEvent> getEffectiveEvents( const QDateTime &start ); | 46 | QValueList<EffectiveEvent> getEffectiveEvents( const QDateTime &start ); |
47 | Event getEvent( int uid ); | ||
48 | 47 | ||
49 | QValueList<Event> getRawRepeats() const; | 48 | QValueList<Event> getRawRepeats() const; |
50 | QValueList<Event> getNonRepeatingEvents( const QDate &from, | 49 | QValueList<Event> getNonRepeatingEvents( const QDate &from, |
51 | const QDate &to ) const; | 50 | const QDate &to ) const; |
52 | 51 | ||
53 | // Use these when dealing with adding removing events... | 52 | // Use these when dealing with adding removing events... |
54 | void addEvent( const Event &ev, bool doalarm=TRUE ); | 53 | void addEvent( const Event &ev, bool doalarm=TRUE ); |
55 | void removeEvent( const Event &ev ); | 54 | void removeEvent( const Event &ev ); |
56 | void editEvent( const Event &old, Event &ev ); | 55 | void editEvent( const Event &old, Event &ev ); |
57 | // add/remove event without journaling ( these ended up in public by accident, never | 56 | // add/remove event without journaling ( these ended up in public by accident, never |
58 | // use them unless you know what you are doing...), | 57 | // use them unless you know what you are doing...), |
59 | // please put them in private if we ever can change the class... | 58 | // please put them in private if we ever can change the class... |
60 | void addJFEvent( const Event &ev, bool doalarm=TRUE ); | 59 | void addJFEvent( const Event &ev, bool doalarm=TRUE ); |
61 | void removeJFEvent( const Event &ev ); | 60 | void removeJFEvent( const Event &ev ); |
62 | 61 | ||
63 | bool save(); | 62 | bool save(); |
64 | void reload(); | 63 | void reload(); |
65 | private: | 64 | private: |
66 | //find the real repeat... | 65 | //find the real repeat... |
67 | bool origRepeat( const Event &ev, Event &orig ) const; | 66 | bool origRepeat( const Event &ev, Event &orig ) const; |
68 | bool removeRepeat( const Event &ev ); | 67 | bool removeRepeat( const Event &ev ); |
69 | void init(); | 68 | void init(); |
70 | void loadFile( const QString &strFile ); | 69 | void loadFile( const QString &strFile ); |
71 | // depreciated... | 70 | // depreciated... |
72 | void saveJournalEntry( const Event &ev, journal_action action ); | 71 | void saveJournalEntry( const Event &ev, journal_action action ); |
73 | // new version, uncomment the "= -1" when we remove the above | 72 | // new version, uncomment the "= -1" when we remove the above |
74 | // function.. | 73 | // function.. |
75 | bool saveJournalEntry( const Event &ev, journal_action action, | 74 | bool saveJournalEntry( const Event &ev, journal_action action, |
76 | int key/* = -1*/, bool origHadRepeat = false ); | 75 | int key/* = -1*/, bool origHadRepeat = false ); |
77 | 76 | ||
78 | QValueList<Event> eventList; // non-repeating events... | 77 | QValueList<Event> eventList; // non-repeating events... |
79 | QValueList<Event> repeatEvents; // the repeating events... | 78 | QValueList<Event> repeatEvents; // the repeating events... |
80 | DateBookDBPrivate *d; | 79 | DateBookDBPrivate *d; |
81 | QFile journalFile; | 80 | QFile journalFile; |
82 | 81 | ||
83 | intrecordIdMax; // ADDITION | 82 | intrecordIdMax; // ADDITION |
84 | }; | 83 | }; |
85 | 84 | ||
86 | /* helper functions, also useful to other apps. */ | 85 | /* helper functions, also useful to other apps. */ |
87 | bool nextOccurance( const Event &e, const QDate &from, QDateTime &next); | 86 | bool nextOccurance( const Event &e, const QDate &from, QDateTime &next); |
88 | #endif | 87 | #endif |