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