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