summaryrefslogtreecommitdiff
path: root/core/pim/today/today.cpp
Unidiff
Diffstat (limited to 'core/pim/today/today.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--core/pim/today/today.cpp140
1 files changed, 41 insertions, 99 deletions
diff --git a/core/pim/today/today.cpp b/core/pim/today/today.cpp
index 1936518..2dc96fc 100644
--- a/core/pim/today/today.cpp
+++ b/core/pim/today/today.cpp
@@ -18,10 +18,7 @@
18 ***************************************************************************/ 18 ***************************************************************************/
19 19
20#include "today.h" 20#include "today.h"
21#include "minidom.h"
22#include "TodoItem.h"
23 21
24#include <qpe/datebookdb.h>
25#include <qpe/timestring.h> 22#include <qpe/timestring.h>
26#include <qpe/config.h> 23#include <qpe/config.h>
27#include <qpe/qcopenvelope_qws.h> 24#include <qpe/qcopenvelope_qws.h>
@@ -56,8 +53,8 @@ int SHOW_NOTES;
56// show only later dates 53// show only later dates
57int ONLY_LATER; 54int ONLY_LATER;
58int AUTOSTART; 55int AUTOSTART;
59
60int NEW_START=1; 56int NEW_START=1;
57
61/* 58/*
62 * Constructs a Example which is a child of 'parent', with the 59 * Constructs a Example which is a child of 'parent', with the
63 * name 'name' and widget flags set to 'f' 60 * name 'name' and widget flags set to 'f'
@@ -77,8 +74,10 @@ Today::Today( QWidget* parent, const char* name, WFlags fl )
77#endif 74#endif
78#endif 75#endif
79 76
80 draw();
81 setOwnerField(); 77 setOwnerField();
78 todo = new ToDoDB;
79 getTodo();
80 draw();
82 autoStart(); 81 autoStart();
83} 82}
84 83
@@ -144,9 +143,15 @@ void Today::draw() {
144 init(); 143 init();
145 getDates(); 144 getDates();
146 getMail(); 145 getMail();
147 getTodo(); 146
147 // if the todolist.xml file was not modified in between, do not parse it.
148 if (checkIfModified()) {
149 todo = new ToDoDB;
150 getTodo();
151 }
152
148 // how often refresh 153 // how often refresh
149 QTimer::singleShot( 10*1000, this, SLOT(draw() ) ); 154 QTimer::singleShot( 20*1000, this, SLOT(draw() ) );
150} 155}
151 156
152/* 157/*
@@ -182,9 +187,9 @@ void Today::init() {
182 QDate date = QDate::currentDate(); 187 QDate date = QDate::currentDate();
183 QString time = (tr( date.toString()) ); 188 QString time = (tr( date.toString()) );
184 189
185 TextLabel1->setText(time); 190 TextLabel1->setText(QString("<font color=#FFFFFF>" + time + "</font>"));
186 db = new DateBookDB; 191 db = new DateBookDB;
187 192
188 // read config 193 // read config
189 Config cfg("today"); 194 Config cfg("today");
190 cfg.setGroup("BaseConfig"); 195 cfg.setGroup("BaseConfig");
@@ -263,7 +268,7 @@ void Today::startConfig() {
263 */ 268 */
264void Today::getDates() { 269void Today::getDates() {
265 QDate date = QDate::currentDate(); 270 QDate date = QDate::currentDate();
266 271
267 if (AllDateBookEvents) delete AllDateBookEvents; 272 if (AllDateBookEvents) delete AllDateBookEvents;
268 AllDateBookEvents = new QWidget( ); 273 AllDateBookEvents = new QWidget( );
269 QVBoxLayout* layoutDates = new QVBoxLayout(AllDateBookEvents); 274 QVBoxLayout* layoutDates = new QVBoxLayout(AllDateBookEvents);
@@ -322,70 +327,6 @@ void Today::getDates() {
322 AllDateBookEvents->show(); 327 AllDateBookEvents->show();
323} 328}
324 329
325/*
326 * Parse in the todolist.xml
327 */
328QList<TodoItem> Today::loadTodo(const char *filename) {
329 DOM *todo;
330 ELE *tasks;
331 ELE **tasklist;
332 ATT **attlist;
333 int i, j;
334 char *description;
335 int completed;
336 int priority;
337 TodoItem *tmp;
338 QList<TodoItem> loadtodolist;
339
340 todo = minidom_load(filename);
341
342 tasks = todo->el;
343 tasks = tasks->el[0]; /*!DOCTYPE-quickhack*/
344 if(tasks) {
345 tasklist = tasks->el;
346 i = 0;
347 while((tasklist) && (tasklist[i])) {
348 attlist = tasklist[i]->at;
349 j = 0;
350 description = NULL;
351 priority = -1;
352 completed = -1;
353 while((attlist) && (attlist[j])) {
354 if(!attlist[j]->name) {
355 continue;
356 }
357 if(!strcmp(attlist[j]->name, "Description")) {
358 description = attlist[j]->value;
359 }
360 // get Completed tag (0 or 1)
361 if(!strcmp(attlist[j]->name, "Completed")) {
362 QString s = attlist[j]->name;
363 if(s == "Completed") {
364 completed = QString(attlist[j]->value).toInt();
365 }
366 }
367 // get Priority (1 to 5)
368 if(!strcmp(attlist[j]->name, "Priority")) {
369 QString s = attlist[j]->name;
370 if(s == "Priority") {
371 priority = QString(attlist[j]->value).toInt();
372 }
373 }
374 j++;
375 }
376 if(description) {
377 tmp = new TodoItem(description, completed, priority);
378 loadtodolist.append(tmp);
379 }
380 i++;
381 }
382 }
383
384 minidom_free(todo);
385
386 return loadtodolist;
387}
388
389 330
390void Today::getMail() { 331void Today::getMail() {
391 Config cfg("opiemail"); 332 Config cfg("opiemail");
@@ -406,35 +347,39 @@ void Today::getMail() {
406 */ 347 */
407void Today::getTodo() { 348void Today::getTodo() {
408 349
409 // if the todolist.xml file was not modified in between, do not parse it.
410 if (!checkIfModified() && !NEW_START) {
411 return;
412 }
413 // since it was the new start or the return from config dialog, set it to 0 again.
414 NEW_START=0;
415
416 QString output; 350 QString output;
417 QString tmpout; 351 QString tmpout;
418 int count = 0; 352 int count = 0;
419 353 int ammount = 0;
420 QDir dir; 354
421 QString homedir = dir.homeDirPath (); 355 // get overdue todos first
422 // see if todolist.xml does exist. 356 QValueList<ToDoEvent> overDueList = todo->overDue();
423 QFile f(homedir +"/Applications/todolist/todolist.xml"); 357 qBubbleSort(overDueList);
424 if ( f.exists() ) { 358 for ( QValueList<ToDoEvent>::Iterator it=overDueList.begin();
425 QList<TodoItem> todolist = loadTodo(homedir +"/Applications/todolist/todolist.xml"); 359 it!=overDueList.end(); ++it ) {
426 360 if (!(*it).isCompleted() && ( ammount < MAX_LINES_TASK) ) {
427 TodoItem *item; 361 tmpout += "<font color=#e00000><b>-" +((*it).description()).mid(0, MAX_CHAR_CLIP) + "</b></font><br>";
428 for( item = todolist.first(); item; item = todolist.next()) { 362 ammount++;
429 if (!(item->getCompleted() == 1) ) { 363 }
430 count++;
431 if (count <= MAX_LINES_TASK) {
432 tmpout += "<b>- </b>" + QString(((item)->getDescription().mid(0, MAX_CHAR_CLIP) + ("<br>")));
433 } 364 }
365
366 // get total number of still open todos
367 QValueList<ToDoEvent> open = todo->rawToDos();
368 qBubbleSort(open);
369 for ( QValueList<ToDoEvent>::Iterator it=open.begin();
370 it!=open.end(); ++it ) {
371 if (!(*it).isCompleted()){
372 count +=1;
373 // not the overdues, we allready got them, and not if we are
374 // over the maxlines
375 if (!(*it).isOverdue() && ( ammount < MAX_LINES_TASK) ) {
376 tmpout += "<b>-</b>" + ((*it).description()).mid(0, MAX_CHAR_CLIP) + "<br>";
377 ammount++;
434 } 378 }
435 } 379 }
436 } 380 }
437 381
382
438 if (count > 0) { 383 if (count > 0) {
439 if( count == 1 ) { 384 if( count == 1 ) {
440 output = tr("There is <b> 1</b> active task: <br>" ); 385 output = tr("There is <b> 1</b> active task: <br>" );
@@ -503,7 +448,7 @@ DateBookEvent::DateBookEvent(const EffectiveEvent &ev,
503 ClickableLabel(parent,name,fl), event(ev) { 448 ClickableLabel(parent,name,fl), event(ev) {
504 449
505 QString msg; 450 QString msg;
506 QTime time = QTime::currentTime(); 451 //QTime time = QTime::currentTime();
507 452
508 if (!ONLY_LATER) { 453 if (!ONLY_LATER) {
509 msg += "<B>" + (ev).description() + "</B>"; 454 msg += "<B>" + (ev).description() + "</B>";
@@ -571,9 +516,6 @@ DateBookEventLater::DateBookEventLater(const EffectiveEvent &ev,
571 } 516 }
572 } 517 }
573 518
574 // if (msg.isEmpty()) {
575 // msg = tr("No more appointments today");
576 // }
577 setText(msg); 519 setText(msg);
578 connect(this, SIGNAL(clicked()), this, SLOT(editMe())); 520 connect(this, SIGNAL(clicked()), this, SLOT(editMe()));
579 setAlignment( int( QLabel::WordBreak | QLabel::AlignLeft ) ); 521 setAlignment( int( QLabel::WordBreak | QLabel::AlignLeft ) );