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