-rw-r--r-- | core/pim/today/today.cpp | 159 |
1 files changed, 97 insertions, 62 deletions
diff --git a/core/pim/today/today.cpp b/core/pim/today/today.cpp index d715fc1..69bcb68 100644 --- a/core/pim/today/today.cpp +++ b/core/pim/today/today.cpp | |||
@@ -18,79 +18,82 @@ | |||
18 | ***************************************************************************/ | 18 | ***************************************************************************/ |
19 | 19 | ||
20 | #include "today.h" | 20 | #include "today.h" |
21 | #include "minidom.h" | 21 | #include "minidom.h" |
22 | #include "TodoItem.h" | 22 | #include "TodoItem.h" |
23 | 23 | ||
24 | #include <qpe/datebookdb.h> | 24 | #include <qpe/datebookdb.h> |
25 | #include <qpe/timestring.h> | 25 | #include <qpe/timestring.h> |
26 | #include <qpe/config.h> | 26 | #include <qpe/config.h> |
27 | #include <qpe/qcopenvelope_qws.h> | 27 | #include <qpe/qcopenvelope_qws.h> |
28 | #include <qpe/qprocess.h> | 28 | #include <qpe/qprocess.h> |
29 | #include <qpe/resource.h> | 29 | #include <qpe/resource.h> |
30 | 30 | ||
31 | #include <qdir.h> | 31 | #include <qdir.h> |
32 | #include <qfile.h> | 32 | #include <qfile.h> |
33 | #include <qdatetime.h> | 33 | #include <qdatetime.h> |
34 | #include <qtextstream.h> | 34 | #include <qtextstream.h> |
35 | #include <qcheckbox.h> | 35 | #include <qcheckbox.h> |
36 | #include <qspinbox.h> | 36 | #include <qspinbox.h> |
37 | #include <qpushbutton.h> | 37 | #include <qpushbutton.h> |
38 | #include <qlabel.h> | 38 | #include <qlabel.h> |
39 | #include <qtimer.h> | 39 | #include <qtimer.h> |
40 | #include <qpixmap.h> | 40 | #include <qpixmap.h> |
41 | #include <qfileinfo.h> | 41 | #include <qfileinfo.h> |
42 | #include <qlayout.h> | ||
42 | 43 | ||
43 | //#include <iostream.h> | 44 | //#include <iostream.h> |
44 | //#include <unistd.h> | 45 | //#include <unistd.h> |
45 | #include <stdlib.h> | 46 | #include <stdlib.h> |
46 | 47 | ||
47 | 48 | ||
49 | |||
48 | int MAX_LINES_TASK; | 50 | int MAX_LINES_TASK; |
49 | int MAX_CHAR_CLIP; | 51 | int MAX_CHAR_CLIP; |
50 | int MAX_LINES_MEET; | 52 | int MAX_LINES_MEET; |
51 | int SHOW_LOCATION; | 53 | int SHOW_LOCATION; |
52 | int SHOW_NOTES; | 54 | int SHOW_NOTES; |
53 | // show only later dates | 55 | // show only later dates |
54 | int ONLY_LATER; | 56 | int ONLY_LATER; |
55 | int AUTOSTART; | 57 | int AUTOSTART; |
58 | |||
59 | int NEW_START=1; | ||
56 | /* | 60 | /* |
57 | * Constructs a Example which is a child of 'parent', with the | 61 | * Constructs a Example which is a child of 'parent', with the |
58 | * name 'name' and widget flags set to 'f' | 62 | * name 'name' and widget flags set to 'f' |
59 | */ | 63 | */ |
60 | Today::Today( QWidget* parent, const char* name, WFlags fl ) | 64 | Today::Today( QWidget* parent, const char* name, WFlags fl ) |
61 | : TodayBase( parent, name, fl ) { | 65 | : TodayBase( parent, name, fl ) { |
62 | QObject::connect( (QObject*)PushButton1, SIGNAL( clicked() ), this, SLOT(startConfig() ) ); | 66 | QObject::connect( (QObject*)PushButton1, SIGNAL( clicked() ), this, SLOT(startConfig() ) ); |
63 | QObject::connect( (QObject*)TodoButton, SIGNAL( clicked() ), this, SLOT(startTodo() ) ); | 67 | QObject::connect( (QObject*)TodoButton, SIGNAL( clicked() ), this, SLOT(startTodo() ) ); |
64 | QObject::connect( (QObject*)DatesButton, SIGNAL( clicked() ), this, SLOT(startDatebook() ) ); | 68 | QObject::connect( (QObject*)DatesButton, SIGNAL( clicked() ), this, SLOT(startDatebook() ) ); |
65 | QObject::connect( (QObject*)MailButton, SIGNAL( clicked() ), this, SLOT(startMail() ) ); | 69 | QObject::connect( (QObject*)MailButton, SIGNAL( clicked() ), this, SLOT(startMail() ) ); |
66 | 70 | ||
67 | 71 | ||
68 | autoStart(); | 72 | autoStart(); |
69 | draw(); | 73 | draw(); |
70 | } | 74 | } |
71 | 75 | ||
72 | |||
73 | void Today::autoStart() { | 76 | void Today::autoStart() { |
74 | Config cfg("today"); | 77 | Config cfg("today"); |
75 | cfg.setGroup("Autostart"); | 78 | cfg.setGroup("Autostart"); |
76 | AUTOSTART = cfg.readNumEntry("autostart",1); | 79 | AUTOSTART = cfg.readNumEntry("autostart",1); |
77 | if (AUTOSTART) { | 80 | if (AUTOSTART) { |
78 | QCopEnvelope e("QPE/System", "autoStart(QString,QString)"); | 81 | QCopEnvelope e("QPE/System", "autoStart(QString,QString)"); |
79 | e << QString("add"); | 82 | e << QString("add"); |
80 | e << QString("today"); | 83 | e << QString("today"); |
81 | } else { | 84 | } else { |
82 | QCopEnvelope e("QPE/System", "autoStart(QString,QString)"); | 85 | QCopEnvelope e("QPE/System", "autoStart(QString,QString)"); |
83 | e << QString("remove"); | 86 | e << QString("remove"); |
84 | e << QString("today"); | 87 | e << QString("today"); |
85 | } | 88 | } |
86 | } | 89 | } |
87 | 90 | ||
88 | void Today::draw() { | 91 | void Today::draw() { |
89 | init(); | 92 | init(); |
90 | getDates(); | 93 | getDates(); |
91 | getMail(); | 94 | getMail(); |
92 | getTodo(); | 95 | getTodo(); |
93 | // how often refresh | 96 | // how often refresh |
94 | QTimer::singleShot( 30*1000, this, SLOT(draw()) ); | 97 | QTimer::singleShot( 30*1000, this, SLOT(draw()) ); |
95 | } | 98 | } |
96 | 99 | ||
@@ -182,128 +185,88 @@ void Today::startConfig() { | |||
182 | int maxcharclip = conf->SpinBox7->value(); | 185 | int maxcharclip = conf->SpinBox7->value(); |
183 | int onlylater = conf->CheckBox3->isChecked(); | 186 | int onlylater = conf->CheckBox3->isChecked(); |
184 | int autostart =conf->CheckBoxAuto->isChecked(); | 187 | int autostart =conf->CheckBoxAuto->isChecked(); |
185 | 188 | ||
186 | cfg.writeEntry("maxlinestask",maxlinestask); | 189 | cfg.writeEntry("maxlinestask",maxlinestask); |
187 | cfg.writeEntry("maxcharclip", maxcharclip); | 190 | cfg.writeEntry("maxcharclip", maxcharclip); |
188 | cfg.writeEntry("maxlinesmeet",maxmeet); | 191 | cfg.writeEntry("maxlinesmeet",maxmeet); |
189 | cfg.writeEntry("showlocation",location); | 192 | cfg.writeEntry("showlocation",location); |
190 | cfg.writeEntry("shownotes", notes); | 193 | cfg.writeEntry("shownotes", notes); |
191 | cfg.writeEntry("onlylater", onlylater); | 194 | cfg.writeEntry("onlylater", onlylater); |
192 | cfg.setGroup("Autostart"); | 195 | cfg.setGroup("Autostart"); |
193 | cfg.writeEntry("autostart", autostart); | 196 | cfg.writeEntry("autostart", autostart); |
194 | // sync it to "disk" | 197 | // sync it to "disk" |
195 | cfg.write(); | 198 | cfg.write(); |
196 | autoStart(); | 199 | autoStart(); |
197 | draw(); | 200 | draw(); |
198 | } | 201 | } |
199 | 202 | ||
200 | 203 | ||
201 | /* | 204 | /* |
202 | * Get all events that are in the datebook xml file for today | 205 | * Get all events that are in the datebook xml file for today |
203 | */ | 206 | */ |
204 | void Today::getDates() { | 207 | void Today::getDates() { |
205 | QDate date = QDate::currentDate(); | 208 | QDate date = QDate::currentDate(); |
206 | QTime time = QTime::currentTime(); | 209 | QWidget* AllDateBookEvents = new QWidget( ); |
210 | QVBoxLayout* layoutDates = new QVBoxLayout(AllDateBookEvents); | ||
211 | //QTime time = QTime::currentTime(); | ||
212 | |||
207 | QValueList<EffectiveEvent> list = db->getEffectiveEvents(date, date); | 213 | QValueList<EffectiveEvent> list = db->getEffectiveEvents(date, date); |
208 | 214 | ||
209 | Config config( "qpe" ); | 215 | Config config( "qpe" ); |
210 | // if 24 h format | 216 | // if 24 h format |
211 | //bool ampm = config.readBoolEntry( "AMPM", TRUE ); | 217 | //bool ampm = config.readBoolEntry( "AMPM", TRUE ); |
212 | 218 | ||
213 | int count=0; | 219 | int count=0; |
214 | 220 | ||
215 | if ( list.count() > 0 ) { | 221 | if ( list.count() > 0 ) { |
216 | QString msg; | 222 | QString msg; |
217 | 223 | ||
218 | for ( QValueList<EffectiveEvent>::ConstIterator it=list.begin(); | 224 | for ( QValueList<EffectiveEvent>::ConstIterator it=list.begin(); |
219 | it!=list.end(); ++it ) { | 225 | it!=list.end(); ++it ) { |
220 | 226 | ||
221 | count++; | 227 | count++; |
222 | 228 | ||
223 | if ( count <= MAX_LINES_MEET ) { | 229 | if ( count <= MAX_LINES_MEET ) { |
224 | //cout << time.toString() << endl; | 230 | |
225 | //cout << TimeString::dateString((*it).event().end()) << endl; | 231 | |
226 | 232 | DateBookEvent *l=new DateBookEvent(*it, AllDateBookEvents); | |
227 | // decide if to get all day or only later appointments | 233 | layoutDates->addWidget(l); |
228 | if (!ONLY_LATER) { | 234 | connect (l, SIGNAL(editEvent(const Event &)), |
229 | msg += "<B>" + (*it).description() + "</B>"; | 235 | this, SIGNAL(editEvent(const Event &))); |
230 | if ( (*it).event().hasAlarm() ) { | ||
231 | msg += " <b>[with alarm]</b>"; | ||
232 | } | ||
233 | // include location or not | ||
234 | if (SHOW_LOCATION == 1) { | ||
235 | msg += "<BR><i>" + (*it).location(); | ||
236 | msg += "</i>"; | ||
237 | } | ||
238 | |||
239 | if ( (TimeString::timeString(QTime((*it).event().start().time()) ) == "00:00") && (TimeString::timeString(QTime((*it).event().end().time()) ) == "23:59") ) { | ||
240 | msg += "<br>All day"; | ||
241 | } else { | ||
242 | // start time of event | ||
243 | msg += "<br>" + TimeString::timeString(QTime((*it).event().start().time()) ) | ||
244 | // end time of event | ||
245 | + "<b> - </b>" + TimeString::timeString(QTime((*it).event().end().time()) ); | ||
246 | } | ||
247 | msg += "<BR>"; | ||
248 | // include possible note or not | ||
249 | if (SHOW_NOTES == 1) { | ||
250 | msg += " <i>note</i>:" +((*it).notes()).mid(0, MAX_CHAR_CLIP) + "<br>"; | ||
251 | } | ||
252 | } else if ((time.toString() <= TimeString::dateString((*it).event().end())) ) { | ||
253 | msg += "<B>" + (*it).description() + "</B>"; | ||
254 | if ( (*it).event().hasAlarm() ) { | ||
255 | msg += " <b>[with alarm]</b>"; | ||
256 | } | ||
257 | // include location or not | ||
258 | if (SHOW_LOCATION == 1) { | ||
259 | msg+= "<BR><i>" + (*it).location(); | ||
260 | msg += "</i>"; | ||
261 | } | ||
262 | |||
263 | if ( (TimeString::timeString(QTime((*it).event().start().time()) ) == "00:00") && (TimeString::timeString(QTime((*it).event().end().time()) ) == "23:59") ) { | ||
264 | msg += "<br>All day"; | ||
265 | } else { | ||
266 | // start time of event | ||
267 | msg += "<br>" + TimeString::timeString(QTime((*it).event().start().time()) ) | ||
268 | // end time of event | ||
269 | + "<b> - </b>" + TimeString::timeString(QTime((*it).event().end().time()) ); | ||
270 | } | ||
271 | msg += "<BR>"; | ||
272 | // include possible note or not | ||
273 | if (SHOW_NOTES == 1) { | ||
274 | msg += " <i>note</i>:" +((*it).notes()).mid(0, MAX_CHAR_CLIP) + "<br>"; | ||
275 | } | ||
276 | } | ||
277 | } | 236 | } |
278 | } | 237 | |
279 | if (msg.isEmpty()) { | 238 | } |
280 | msg = tr("No more appointments today"); | 239 | layoutDates->addItem(new QSpacerItem(1,1, QSizePolicy::Minimum, QSizePolicy::Expanding)); |
281 | } | 240 | sv1->addChild(AllDateBookEvents); |
282 | DatesField->setText(msg); | 241 | |
242 | //if (msg.isEmpty()) { | ||
243 | // msg = tr("No more appointments today"); | ||
244 | //} | ||
245 | //DatesField->setText(msg); | ||
283 | } | 246 | } |
284 | } | 247 | } |
285 | 248 | ||
286 | /* | 249 | /* |
287 | * Parse in the todolist.xml | 250 | * Parse in the todolist.xml |
288 | */ | 251 | */ |
289 | QList<TodoItem> Today::loadTodo(const char *filename) { | 252 | QList<TodoItem> Today::loadTodo(const char *filename) { |
290 | DOM *todo; | 253 | DOM *todo; |
291 | ELE *tasks; | 254 | ELE *tasks; |
292 | ELE **tasklist; | 255 | ELE **tasklist; |
293 | ATT **attlist; | 256 | ATT **attlist; |
294 | int i, j; | 257 | int i, j; |
295 | char *description; | 258 | char *description; |
296 | int completed; | 259 | int completed; |
297 | int priority; | 260 | int priority; |
298 | TodoItem *tmp; | 261 | TodoItem *tmp; |
299 | QList<TodoItem> loadtodolist; | 262 | QList<TodoItem> loadtodolist; |
300 | 263 | ||
301 | todo = minidom_load(filename); | 264 | todo = minidom_load(filename); |
302 | 265 | ||
303 | tasks = todo->el; | 266 | tasks = todo->el; |
304 | tasks = tasks->el[0]; /*!DOCTYPE-quickhack*/ | 267 | tasks = tasks->el[0]; /*!DOCTYPE-quickhack*/ |
305 | if(tasks) { | 268 | if(tasks) { |
306 | tasklist = tasks->el; | 269 | tasklist = tasks->el; |
307 | i = 0; | 270 | i = 0; |
308 | while((tasklist) && (tasklist[i])) { | 271 | while((tasklist) && (tasklist[i])) { |
309 | attlist = tasklist[i]->at; | 272 | attlist = tasklist[i]->at; |
@@ -350,51 +313,52 @@ QList<TodoItem> Today::loadTodo(const char *filename) { | |||
350 | 313 | ||
351 | void Today::getMail() { | 314 | void Today::getMail() { |
352 | Config cfg("opiemail"); | 315 | Config cfg("opiemail"); |
353 | cfg.setGroup("today"); | 316 | cfg.setGroup("today"); |
354 | 317 | ||
355 | // how many lines should be showed in the task section | 318 | // how many lines should be showed in the task section |
356 | int NEW_MAILS = cfg.readNumEntry("newmails",0); | 319 | int NEW_MAILS = cfg.readNumEntry("newmails",0); |
357 | int OUTGOING = cfg.readNumEntry("outgoing",0); | 320 | int OUTGOING = cfg.readNumEntry("outgoing",0); |
358 | 321 | ||
359 | 322 | ||
360 | QString output = tr("<b>%1</b> new mail(s), <b>%2</b> outgoing").arg(NEW_MAILS).arg(OUTGOING); | 323 | QString output = tr("<b>%1</b> new mail(s), <b>%2</b> outgoing").arg(NEW_MAILS).arg(OUTGOING); |
361 | 324 | ||
362 | 325 | ||
363 | MailField->setText(output); | 326 | MailField->setText(output); |
364 | } | 327 | } |
365 | 328 | ||
366 | 329 | ||
367 | /* | 330 | /* |
368 | * Get the todos | 331 | * Get the todos |
369 | * | 332 | * |
370 | */ | 333 | */ |
371 | void Today::getTodo() { | 334 | void Today::getTodo() { |
372 | 335 | ||
373 | // if the todolist.xml file was not modified in between, do not parse it. | 336 | // if the todolist.xml file was not modified in between, do not parse it. |
374 | if (!checkIfModified()) { | 337 | if (!checkIfModified() && !NEW_START) { |
375 | return; | 338 | return; |
376 | } | 339 | } |
340 | NEW_START=0; | ||
377 | 341 | ||
378 | QString output; | 342 | QString output; |
379 | QString tmpout; | 343 | QString tmpout; |
380 | int count = 0; | 344 | int count = 0; |
381 | 345 | ||
382 | QDir dir; | 346 | QDir dir; |
383 | QString homedir = dir.homeDirPath (); | 347 | QString homedir = dir.homeDirPath (); |
384 | // see if todolist.xml does exist. | 348 | // see if todolist.xml does exist. |
385 | QFile f(homedir +"/Applications/todolist/todolist.xml"); | 349 | QFile f(homedir +"/Applications/todolist/todolist.xml"); |
386 | if ( f.exists() ) { | 350 | if ( f.exists() ) { |
387 | QList<TodoItem> todolist = loadTodo(homedir +"/Applications/todolist/todolist.xml"); | 351 | QList<TodoItem> todolist = loadTodo(homedir +"/Applications/todolist/todolist.xml"); |
388 | 352 | ||
389 | TodoItem *item; | 353 | TodoItem *item; |
390 | for( item = todolist.first(); item; item = todolist.next()) { | 354 | for( item = todolist.first(); item; item = todolist.next()) { |
391 | if (!(item->getCompleted() == 1) ) { | 355 | if (!(item->getCompleted() == 1) ) { |
392 | count++; | 356 | count++; |
393 | if (count <= MAX_LINES_TASK) { | 357 | if (count <= MAX_LINES_TASK) { |
394 | tmpout += "<b>- </b>" + QString(((item)->getDescription().mid(0, MAX_CHAR_CLIP) + ("<br>"))); | 358 | tmpout += "<b>- </b>" + QString(((item)->getDescription().mid(0, MAX_CHAR_CLIP) + ("<br>"))); |
395 | } | 359 | } |
396 | } | 360 | } |
397 | } | 361 | } |
398 | } | 362 | } |
399 | 363 | ||
400 | if (count > 0) { | 364 | if (count > 0) { |
@@ -420,24 +384,95 @@ void Today::startDatebook() { | |||
420 | } | 384 | } |
421 | 385 | ||
422 | /* | 386 | /* |
423 | * launches todolist | 387 | * launches todolist |
424 | */ | 388 | */ |
425 | void Today::startTodo() { | 389 | void Today::startTodo() { |
426 | QCopEnvelope e("QPE/System", "execute(QString)"); | 390 | QCopEnvelope e("QPE/System", "execute(QString)"); |
427 | e << QString("todolist"); | 391 | e << QString("todolist"); |
428 | } | 392 | } |
429 | 393 | ||
430 | /* | 394 | /* |
431 | * launch opiemail | 395 | * launch opiemail |
432 | */ | 396 | */ |
433 | void Today::startMail() { | 397 | void Today::startMail() { |
434 | QCopEnvelope e("QPE/System", "execute(QString)"); | 398 | QCopEnvelope e("QPE/System", "execute(QString)"); |
435 | e << QString("opiemail"); | 399 | e << QString("opiemail"); |
436 | } | 400 | } |
437 | 401 | ||
438 | /* | 402 | /* |
439 | * Destroys the object and frees any allocated resources | 403 | * Destroys the object and frees any allocated resources |
440 | */ | 404 | */ |
441 | Today::~Today() { | 405 | Today::~Today() { |
442 | // no need to delete child widgets, Qt does it all for us | 406 | // no need to delete child widgets, Qt does it all for us |
443 | } | 407 | } |
408 | |||
409 | |||
410 | DateBookEvent::DateBookEvent(const EffectiveEvent &ev, | ||
411 | QWidget* parent = 0, | ||
412 | const char* name = 0, | ||
413 | WFlags fl = 0) : | ||
414 | ClickableLabel(parent,name,fl), event(ev) { | ||
415 | |||
416 | QString msg; | ||
417 | QTime time = QTime::currentTime(); | ||
418 | |||
419 | if (!ONLY_LATER) { | ||
420 | msg += "<B>" + (ev).description() + "</B>"; | ||
421 | if ( (ev).event().hasAlarm() ) { | ||
422 | msg += " <b>[with alarm]</b>"; | ||
423 | } | ||
424 | // include location or not | ||
425 | if (SHOW_LOCATION == 1) { | ||
426 | msg += "<BR><i>" + (ev).location(); | ||
427 | msg += "</i>"; | ||
428 | } | ||
429 | |||
430 | if ( (TimeString::timeString(QTime((ev).event().start().time()) ) == "00:00") && (TimeString::timeString(QTime((ev).event().end().time()) ) == "23:59") ) { | ||
431 | msg += "<br>All day"; | ||
432 | } else { | ||
433 | // start time of event | ||
434 | msg += "<br>" + TimeString::timeString(QTime((ev).event().start().time()) ) | ||
435 | // end time of event | ||
436 | + "<b> - </b>" + TimeString::timeString(QTime((ev).event().end().time()) ); | ||
437 | } | ||
438 | msg += "<BR>"; | ||
439 | // include possible note or not | ||
440 | if (SHOW_NOTES == 1) { | ||
441 | msg += " <i>note</i>:" +((ev).notes()).mid(0, MAX_CHAR_CLIP) + "<br>"; | ||
442 | } | ||
443 | } else if ((time.toString() <= TimeString::dateString((ev).event().end())) ) { | ||
444 | msg += "<B>" + (ev).description() + "</B>"; | ||
445 | if ( (ev).event().hasAlarm() ) { | ||
446 | msg += " <b>[with alarm]</b>"; | ||
447 | } | ||
448 | // include location or not | ||
449 | if (SHOW_LOCATION == 1) { | ||
450 | msg+= "<BR><i>" + (ev).location(); | ||
451 | msg += "</i>"; | ||
452 | } | ||
453 | |||
454 | if ( (TimeString::timeString(QTime((ev).event().start().time()) ) == "00:00") && (TimeString::timeString(QTime((ev).event().end().time()) ) == "23:59") ) { | ||
455 | msg += "<br>All day"; | ||
456 | } else { | ||
457 | // start time of event | ||
458 | msg += "<br>" + TimeString::timeString(QTime((ev).event().start().time()) ) | ||
459 | // end time of event | ||
460 | + "<b> - </b>" + TimeString::timeString(QTime((ev).event().end().time()) ); | ||
461 | } | ||
462 | // include possible note or not | ||
463 | if (SHOW_NOTES == 1) { | ||
464 | msg += "<br> <i>note</i>:" +((ev).notes()).mid(0, MAX_CHAR_CLIP) + "<br>"; | ||
465 | } | ||
466 | } | ||
467 | |||
468 | setText(msg); | ||
469 | connect(this, SIGNAL(clicked()), this, SLOT(editMe())); | ||
470 | setAlignment( int( QLabel::WordBreak | QLabel::AlignLeft ) ); | ||
471 | } | ||
472 | |||
473 | void DateBookEvent::editMe() { | ||
474 | emit editEvent(event.event()); | ||
475 | } | ||
476 | |||
477 | |||
478 | |||