-rw-r--r-- | core/pim/today/today.cpp | 46 |
1 files changed, 39 insertions, 7 deletions
diff --git a/core/pim/today/today.cpp b/core/pim/today/today.cpp index 00a8842..eb8b50c 100644 --- a/core/pim/today/today.cpp +++ b/core/pim/today/today.cpp | |||
@@ -14,81 +14,91 @@ | |||
14 | * it under the terms of the GNU General Public License as published by * | 14 | * it under the terms of the GNU General Public License as published by * |
15 | * the Free Software Foundation; either version 2 of the License, or * | 15 | * the Free Software Foundation; either version 2 of the License, or * |
16 | * (at your option) any later version. * | 16 | * (at your option) any later version. * |
17 | * * | 17 | * * |
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 | 29 | ||
30 | #include <qdir.h> | 30 | #include <qdir.h> |
31 | #include <qfile.h> | 31 | #include <qfile.h> |
32 | #include <qdatetime.h> | 32 | #include <qdatetime.h> |
33 | #include <qtextstream.h> | 33 | #include <qtextstream.h> |
34 | #include <qcheckbox.h> | 34 | #include <qcheckbox.h> |
35 | #include <qspinbox.h> | 35 | #include <qspinbox.h> |
36 | #include <qpushbutton.h> | 36 | #include <qpushbutton.h> |
37 | #include <qlabel.h> | 37 | #include <qlabel.h> |
38 | #include <qtimer.h> | ||
38 | 39 | ||
39 | //#include <iostream.h> | 40 | //#include <iostream.h> |
40 | //#include <unistd.h> | 41 | //#include <unistd.h> |
41 | #include <stdlib.h> | 42 | #include <stdlib.h> |
42 | 43 | ||
43 | int MAX_LINES_TASK; | 44 | int MAX_LINES_TASK; |
44 | int MAX_CHAR_CLIP; | 45 | int MAX_CHAR_CLIP; |
45 | int MAX_LINES_MEET; | 46 | int MAX_LINES_MEET; |
46 | int SHOW_LOCATION; | 47 | int SHOW_LOCATION; |
47 | int SHOW_NOTES; | 48 | int SHOW_NOTES; |
48 | // show only later dates | 49 | // show only later dates |
49 | int ONLY_LATER = 1; | 50 | int ONLY_LATER = 1; |
50 | /* | 51 | /* |
51 | * Constructs a Example which is a child of 'parent', with the | 52 | * Constructs a Example which is a child of 'parent', with the |
52 | * name 'name' and widget flags set to 'f' | 53 | * name 'name' and widget flags set to 'f' |
53 | */ | 54 | */ |
54 | Today::Today( QWidget* parent, const char* name, WFlags fl ) | 55 | Today::Today( QWidget* parent, const char* name, WFlags fl ) |
55 | : TodayBase( parent, name, fl ) | 56 | : TodayBase( parent, name, fl ) |
56 | { | 57 | { |
57 | QObject::connect( (QObject*)PushButton1, SIGNAL( clicked() ), this, SLOT(startConfig() ) ); | 58 | QObject::connect( (QObject*)PushButton1, SIGNAL( clicked() ), this, SLOT(startConfig() ) ); |
58 | QObject::connect( (QObject*)TodoButton, SIGNAL( clicked() ), this, SLOT(startTodo() ) ); | 59 | QObject::connect( (QObject*)TodoButton, SIGNAL( clicked() ), this, SLOT(startTodo() ) ); |
59 | QObject::connect( (QObject*)DatesButton, SIGNAL( clicked() ), this, SLOT(startDatebook() ) ); | 60 | QObject::connect( (QObject*)DatesButton, SIGNAL( clicked() ), this, SLOT(startDatebook() ) ); |
61 | QObject::connect( (QObject*)DatesButton, SIGNAL( clicked() ), this, SLOT(startMail() ) ); | ||
60 | 62 | ||
61 | QDate date = QDate::currentDate(); | 63 | QDate date = QDate::currentDate(); |
62 | QString time = (date.toString()); | 64 | QString time = (date.toString()); |
63 | TextLabel1->setText(time); | 65 | TextLabel1->setText(time); |
64 | db = new DateBookDB; | 66 | db = new DateBookDB; |
65 | 67 | ||
68 | draw(); | ||
69 | } | ||
70 | |||
71 | |||
72 | void Today::draw() | ||
73 | { | ||
66 | init(); | 74 | init(); |
67 | getDates(); | 75 | getDates(); |
76 | getMail(); | ||
68 | getTodo(); | 77 | getTodo(); |
69 | } | 78 | QTimer::singleShot( 60*1000, this, SLOT(draw()) ); |
70 | 79 | ||
80 | } | ||
71 | 81 | ||
72 | void Today::init() | 82 | void Today::init() |
73 | { | 83 | { |
74 | // read config | 84 | // read config |
75 | Config cfg("today"); | 85 | Config cfg("today"); |
76 | cfg.setGroup("BaseConfig"); | 86 | cfg.setGroup("BaseConfig"); |
77 | 87 | ||
78 | // how many lines should be showed in the task section | 88 | // how many lines should be showed in the task section |
79 | MAX_LINES_TASK = cfg.readNumEntry("maxlinestask",5); | 89 | MAX_LINES_TASK = cfg.readNumEntry("maxlinestask",5); |
80 | // after how many chars should the be cut off on tasks and notes | 90 | // after how many chars should the be cut off on tasks and notes |
81 | MAX_CHAR_CLIP = cfg.readNumEntry("maxcharclip",30); | 91 | MAX_CHAR_CLIP = cfg.readNumEntry("maxcharclip",30); |
82 | // how many lines should be showed in the datebook section | 92 | // how many lines should be showed in the datebook section |
83 | MAX_LINES_MEET = cfg.readNumEntry("maxlinesmeet",5); | 93 | MAX_LINES_MEET = cfg.readNumEntry("maxlinesmeet",5); |
84 | // If location is to be showed too, 1 to activate it. | 94 | // If location is to be showed too, 1 to activate it. |
85 | SHOW_LOCATION = cfg.readNumEntry("showlocation",1); | 95 | SHOW_LOCATION = cfg.readNumEntry("showlocation",1); |
86 | // if notes should be shown | 96 | // if notes should be shown |
87 | SHOW_NOTES = cfg.readNumEntry("shownotes",0); | 97 | SHOW_NOTES = cfg.readNumEntry("shownotes",0); |
88 | } | 98 | } |
89 | 99 | ||
90 | void Today::startConfig() | 100 | void Today::startConfig() |
91 | { | 101 | { |
92 | conf = new todayconfig ( this, "", true ); | 102 | conf = new todayconfig ( this, "", true ); |
93 | 103 | ||
94 | 104 | ||
@@ -105,52 +115,49 @@ void Today::startConfig() | |||
105 | conf->CheckBox1->setChecked(SHOW_LOCATION); | 115 | conf->CheckBox1->setChecked(SHOW_LOCATION); |
106 | // notes show box | 116 | // notes show box |
107 | conf->CheckBox2->setChecked(SHOW_NOTES); | 117 | conf->CheckBox2->setChecked(SHOW_NOTES); |
108 | // task lines | 118 | // task lines |
109 | conf->SpinBox2->setValue(MAX_LINES_TASK); | 119 | conf->SpinBox2->setValue(MAX_LINES_TASK); |
110 | // clip when? | 120 | // clip when? |
111 | conf->SpinBox7->setValue(MAX_CHAR_CLIP); | 121 | conf->SpinBox7->setValue(MAX_CHAR_CLIP); |
112 | 122 | ||
113 | conf->exec(); | 123 | conf->exec(); |
114 | 124 | ||
115 | int maxlinestask = conf->SpinBox2->value(); | 125 | int maxlinestask = conf->SpinBox2->value(); |
116 | int maxmeet = conf->SpinBox1->value(); | 126 | int maxmeet = conf->SpinBox1->value(); |
117 | int location = conf->CheckBox1->isChecked(); | 127 | int location = conf->CheckBox1->isChecked(); |
118 | int notes = conf->CheckBox2->isChecked(); | 128 | int notes = conf->CheckBox2->isChecked(); |
119 | int maxcharclip = conf->SpinBox7->value(); | 129 | int maxcharclip = conf->SpinBox7->value(); |
120 | 130 | ||
121 | cfg.writeEntry("maxlinestask",maxlinestask); | 131 | cfg.writeEntry("maxlinestask",maxlinestask); |
122 | cfg.writeEntry("maxcharclip", maxcharclip); | 132 | cfg.writeEntry("maxcharclip", maxcharclip); |
123 | cfg.writeEntry("maxlinesmeet",maxmeet); | 133 | cfg.writeEntry("maxlinesmeet",maxmeet); |
124 | cfg.writeEntry("showlocation",location); | 134 | cfg.writeEntry("showlocation",location); |
125 | cfg.writeEntry("shownotes", notes); | 135 | cfg.writeEntry("shownotes", notes); |
126 | // sync it to "disk" | 136 | // sync it to "disk" |
127 | cfg.write(); | 137 | cfg.write(); |
128 | 138 | ||
129 | init(); | 139 | draw(); |
130 | getDates(); | ||
131 | getTodo(); | ||
132 | //cout << location << endl; | ||
133 | } | 140 | } |
134 | 141 | ||
135 | 142 | ||
136 | /* | 143 | /* |
137 | * Get all events that are in the datebook xml file for today | 144 | * Get all events that are in the datebook xml file for today |
138 | */ | 145 | */ |
139 | void Today::getDates() | 146 | void Today::getDates() |
140 | { | 147 | { |
141 | QDate date = QDate::currentDate(); | 148 | QDate date = QDate::currentDate(); |
142 | QTime time = QTime::currentTime(); | 149 | QTime time = QTime::currentTime(); |
143 | QValueList<EffectiveEvent> list = db->getEffectiveEvents(date, date); | 150 | QValueList<EffectiveEvent> list = db->getEffectiveEvents(date, date); |
144 | 151 | ||
145 | Config config( "qpe" ); | 152 | Config config( "qpe" ); |
146 | // if 24 h format | 153 | // if 24 h format |
147 | // bool ampm = config.readBoolEntry( "AMPM", TRUE ); | 154 | // bool ampm = config.readBoolEntry( "AMPM", TRUE ); |
148 | 155 | ||
149 | int count=0; | 156 | int count=0; |
150 | 157 | ||
151 | if ( list.count() > 0 ) { | 158 | if ( list.count() > 0 ) { |
152 | QString msg; | 159 | QString msg; |
153 | 160 | ||
154 | for ( QValueList<EffectiveEvent>::ConstIterator it=list.begin(); | 161 | for ( QValueList<EffectiveEvent>::ConstIterator it=list.begin(); |
155 | it!=list.end(); ++it ) { | 162 | it!=list.end(); ++it ) { |
156 | 163 | ||
@@ -241,94 +248,119 @@ QList<TodoItem> Today::loadTodo(const char *filename) | |||
241 | { | 248 | { |
242 | QString s = attlist[j]->name; | 249 | QString s = attlist[j]->name; |
243 | if(s == "Priority") | 250 | if(s == "Priority") |
244 | { | 251 | { |
245 | priority = QString(attlist[j]->value).toInt(); | 252 | priority = QString(attlist[j]->value).toInt(); |
246 | } | 253 | } |
247 | } | 254 | } |
248 | j++; | 255 | j++; |
249 | } | 256 | } |
250 | if(description) | 257 | if(description) |
251 | { | 258 | { |
252 | tmp = new TodoItem(description, completed, priority); | 259 | tmp = new TodoItem(description, completed, priority); |
253 | loadtodolist.append(tmp); | 260 | loadtodolist.append(tmp); |
254 | } | 261 | } |
255 | i++; | 262 | i++; |
256 | } | 263 | } |
257 | } | 264 | } |
258 | 265 | ||
259 | minidom_free(todo); | 266 | minidom_free(todo); |
260 | 267 | ||
261 | return loadtodolist; | 268 | return loadtodolist; |
262 | } | 269 | } |
263 | 270 | ||
264 | 271 | ||
272 | void Today::getMail() | ||
273 | { | ||
274 | Config cfg("opiemail"); | ||
275 | cfg.setGroup("today"); | ||
276 | |||
277 | // how many lines should be showed in the task section | ||
278 | int NEW_MAILS = cfg.readNumEntry("newmails",0); | ||
279 | int OUTGOING = cfg.readNumEntry("outgoing",0); | ||
280 | |||
281 | QString output = tr("<b>%1</b> new mails, <b>%2</b> outgoing").arg(NEW_MAILS).arg(OUTGOING); | ||
282 | |||
283 | |||
284 | MailField->setText(output); | ||
285 | } | ||
286 | |||
287 | |||
265 | /* | 288 | /* |
266 | * Get the todos | 289 | * Get the todos |
267 | * | 290 | * |
268 | */ | 291 | */ |
269 | void Today::getTodo() | 292 | void Today::getTodo() |
270 | { | 293 | { |
271 | QString output; | 294 | QString output; |
272 | QString tmpout; | 295 | QString tmpout; |
273 | int count = 0; | 296 | int count = 0; |
274 | 297 | ||
275 | QDir dir; | 298 | QDir dir; |
276 | QString homedir = dir.homeDirPath (); | 299 | QString homedir = dir.homeDirPath (); |
277 | // see if todolist.xml does exist. | 300 | // see if todolist.xml does exist. |
278 | QFile f(homedir +"/Applications/todolist/todolist.xml"); | 301 | QFile f(homedir +"/Applications/todolist/todolist.xml"); |
279 | if ( f.exists() ) | 302 | if ( f.exists() ) |
280 | { | 303 | { |
281 | QList<TodoItem> todolist = loadTodo(homedir +"/Applications/todolist/todolist.xml"); | 304 | QList<TodoItem> todolist = loadTodo(homedir +"/Applications/todolist/todolist.xml"); |
282 | 305 | ||
283 | TodoItem *item; | 306 | TodoItem *item; |
284 | for( item = todolist.first(); item; item = todolist.next()) | 307 | for( item = todolist.first(); item; item = todolist.next()) |
285 | { | 308 | { |
286 | if (!(item->getCompleted() == 1) ) | 309 | if (!(item->getCompleted() == 1) ) |
287 | { | 310 | { |
288 | count++; | 311 | count++; |
289 | if (count <= MAX_LINES_TASK) | 312 | if (count <= MAX_LINES_TASK) |
290 | { | 313 | { |
291 | tmpout += "<b>- </b>" + QString(((item)->getDescription().mid(0, MAX_CHAR_CLIP) + ("<br>"))); | 314 | tmpout += "<b>- </b>" + QString(((item)->getDescription().mid(0, MAX_CHAR_CLIP) + ("<br>"))); |
292 | } | 315 | } |
293 | } | 316 | } |
294 | } | 317 | } |
295 | } | 318 | } |
296 | 319 | ||
297 | if (count > 0) | 320 | if (count > 0) |
298 | { | 321 | { |
299 | output = QString("There are <b> %1</b> active tasks: <br>").arg(count); | 322 | output = QString("There are <b> %1</b> active tasks: <br>").arg(count); |
300 | output += tmpout; | 323 | output += tmpout; |
301 | } | 324 | } |
302 | else | 325 | else |
303 | { | 326 | { |
304 | output = ("No active tasks"); | 327 | output = ("No active tasks"); |
305 | } | 328 | } |
306 | 329 | ||
307 | TodoField->setText(output); | 330 | TodoField->setText(output); |
308 | } | 331 | } |
309 | 332 | ||
310 | /* | 333 | /* |
311 | * lanches datebook | 334 | * launches datebook |
312 | */ | 335 | */ |
313 | void Today::startDatebook() | 336 | void Today::startDatebook() |
314 | { | 337 | { |
315 | QCopEnvelope e("QPE/System", "execute(QString)"); | 338 | QCopEnvelope e("QPE/System", "execute(QString)"); |
316 | e << QString("datebook"); | 339 | e << QString("datebook"); |
317 | } | 340 | } |
318 | 341 | ||
319 | /* | 342 | /* |
320 | * lanches todolist | 343 | * launches todolist |
321 | */ | 344 | */ |
322 | void Today::startTodo() | 345 | void Today::startTodo() |
323 | { | 346 | { |
324 | QCopEnvelope e("QPE/System", "execute(QString)"); | 347 | QCopEnvelope e("QPE/System", "execute(QString)"); |
325 | e << QString("todolist"); | 348 | e << QString("todolist"); |
326 | } | 349 | } |
327 | 350 | ||
328 | /* | 351 | /* |
352 | * launch opiemail | ||
353 | */ | ||
354 | void Today::startMail() | ||
355 | { | ||
356 | QCopEnvelope e("QPE/System", "execute(QString)"); | ||
357 | e << QString("opiemail"); | ||
358 | } | ||
359 | |||
360 | /* | ||
329 | * Destroys the object and frees any allocated resources | 361 | * Destroys the object and frees any allocated resources |
330 | */ | 362 | */ |
331 | Today::~Today() | 363 | Today::~Today() |
332 | { | 364 | { |
333 | // no need to delete child widgets, Qt does it all for us | 365 | // no need to delete child widgets, Qt does it all for us |
334 | } | 366 | } |