summaryrefslogtreecommitdiff
authorharlekin <harlekin>2002-03-05 22:23:54 (UTC)
committer harlekin <harlekin>2002-03-05 22:23:54 (UTC)
commitc84da23a6ff2a8ff51b4da70f83b261f1e548be1 (patch) (unidiff)
tree4d87cf43f7b9c48765b4879e4ee5c6e9ca5841b3
parent3ccfa79645d8bd99c7b559f9fa315d028db2c75d (diff)
downloadopie-c84da23a6ff2a8ff51b4da70f83b261f1e548be1.zip
opie-c84da23a6ff2a8ff51b4da70f83b261f1e548be1.tar.gz
opie-c84da23a6ff2a8ff51b4da70f83b261f1e548be1.tar.bz2
cosmetic changes on request from zecke
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--core/pim/today/today.cpp294
1 files changed, 127 insertions, 167 deletions
diff --git a/core/pim/today/today.cpp b/core/pim/today/today.cpp
index c63a9ef..6a0e9fc 100644
--- a/core/pim/today/today.cpp
+++ b/core/pim/today/today.cpp
@@ -46,74 +46,69 @@
46int MAX_LINES_TASK; 46int MAX_LINES_TASK;
47int MAX_CHAR_CLIP; 47int MAX_CHAR_CLIP;
48int MAX_LINES_MEET; 48int MAX_LINES_MEET;
49int SHOW_LOCATION; 49int SHOW_LOCATION;
50int SHOW_NOTES; 50int SHOW_NOTES;
51// show only later dates 51// show only later dates
52int ONLY_LATER; 52int ONLY_LATER;
53/* 53/*
54 * Constructs a Example which is a child of 'parent', with the 54 * Constructs a Example which is a child of 'parent', with the
55 * name 'name' and widget flags set to 'f' 55 * name 'name' and widget flags set to 'f'
56 */ 56 */
57Today::Today( QWidget* parent, const char* name, WFlags fl ) 57Today::Today( QWidget* parent, const char* name, WFlags fl )
58 : TodayBase( parent, name, fl ) 58 : TodayBase( parent, name, fl ) {
59{
60 QObject::connect( (QObject*)PushButton1, SIGNAL( clicked() ), this, SLOT(startConfig() ) ); 59 QObject::connect( (QObject*)PushButton1, SIGNAL( clicked() ), this, SLOT(startConfig() ) );
61 QObject::connect( (QObject*)TodoButton, SIGNAL( clicked() ), this, SLOT(startTodo() ) ); 60 QObject::connect( (QObject*)TodoButton, SIGNAL( clicked() ), this, SLOT(startTodo() ) );
62 QObject::connect( (QObject*)DatesButton, SIGNAL( clicked() ), this, SLOT(startDatebook() ) ); 61 QObject::connect( (QObject*)DatesButton, SIGNAL( clicked() ), this, SLOT(startDatebook() ) );
63 QObject::connect( (QObject*)MailButton, SIGNAL( clicked() ), this, SLOT(startMail() ) ); 62 QObject::connect( (QObject*)MailButton, SIGNAL( clicked() ), this, SLOT(startMail() ) );
64 63
65 draw(); 64 draw();
66} 65}
67 66
68 67
69void Today::draw() 68void Today::draw() {
70{
71 init(); 69 init();
72 getDates(); 70 getDates();
73 getMail(); 71 getMail();
74 getTodo(); 72 getTodo();
75 // how often refresh 73 // how often refresh
76 QTimer::singleShot( 5*1000, this, SLOT(draw()) ); 74 QTimer::singleShot( 5*1000, this, SLOT(draw()) );
77
78} 75}
79 76
80void Today::init() 77void Today::init() {
81{
82 QDate date = QDate::currentDate(); 78 QDate date = QDate::currentDate();
83 QString time = (date.toString()); 79 QString time = (date.toString());
84 80
85 TextLabel1->setText("<qt><font color=white>" +time + "<font></qt>"); 81 TextLabel1->setText("<qt><font color=white>" +time + "<font></qt>");
86 db = new DateBookDB; 82 db = new DateBookDB;
87 83
88 // read config 84 // read config
89 Config cfg("today"); 85 Config cfg("today");
90 cfg.setGroup("BaseConfig"); 86 cfg.setGroup("BaseConfig");
91 87
92 // how many lines should be showed in the task section 88 // how many lines should be showed in the task section
93 MAX_LINES_TASK = cfg.readNumEntry("maxlinestask",5); 89 MAX_LINES_TASK = cfg.readNumEntry("maxlinestask",5);
94 // 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
95 MAX_CHAR_CLIP = cfg.readNumEntry("maxcharclip",30); 91 MAX_CHAR_CLIP = cfg.readNumEntry("maxcharclip",30);
96 // how many lines should be showed in the datebook section 92 // how many lines should be showed in the datebook section
97 MAX_LINES_MEET = cfg.readNumEntry("maxlinesmeet",5); 93 MAX_LINES_MEET = cfg.readNumEntry("maxlinesmeet",5);
98 // If location is to be showed too, 1 to activate it. 94 // If location is to be showed too, 1 to activate it.
99 SHOW_LOCATION = cfg.readNumEntry("showlocation",1); 95 SHOW_LOCATION = cfg.readNumEntry("showlocation",1);
100 // if notes should be shown 96 // if notes should be shown
101 SHOW_NOTES = cfg.readNumEntry("shownotes",0); 97 SHOW_NOTES = cfg.readNumEntry("shownotes",0);
102 ONLY_LATER = cfg.readNumEntry("onlylater",1); 98 ONLY_LATER = cfg.readNumEntry("onlylater",1);
103 99
104} 100}
105 101
106void Today::startConfig() 102void Today::startConfig() {
107{
108 conf = new todayconfig ( this, "", true ); 103 conf = new todayconfig ( this, "", true );
109 104
110 105
111 //Config cfg = new Config("today"); 106 //Config cfg = new Config("today");
112 107
113 // read the config 108 // read the config
114 Config cfg("today"); 109 Config cfg("today");
115 cfg.setGroup("BaseConfig"); 110 cfg.setGroup("BaseConfig");
116 111
117 //init(); 112 //init();
118 113
119 conf->SpinBox1->setValue(MAX_LINES_MEET); 114 conf->SpinBox1->setValue(MAX_LINES_MEET);
@@ -144,281 +139,246 @@ void Today::startConfig()
144 cfg.writeEntry("shownotes", notes); 139 cfg.writeEntry("shownotes", notes);
145 cfg.writeEntry("onlylater", onlylater); 140 cfg.writeEntry("onlylater", onlylater);
146 // sync it to "disk" 141 // sync it to "disk"
147 cfg.write(); 142 cfg.write();
148 143
149 draw(); 144 draw();
150} 145}
151 146
152 147
153/* 148/*
154 * Get all events that are in the datebook xml file for today 149 * Get all events that are in the datebook xml file for today
155 */ 150 */
156void Today::getDates() 151void Today::getDates() {
157{
158 QDate date = QDate::currentDate(); 152 QDate date = QDate::currentDate();
159 QTime time = QTime::currentTime(); 153 QTime time = QTime::currentTime();
160 QValueList<EffectiveEvent> list = db->getEffectiveEvents(date, date); 154 QValueList<EffectiveEvent> list = db->getEffectiveEvents(date, date);
161 155
162 Config config( "qpe" ); 156 Config config( "qpe" );
163 // if 24 h format 157 // if 24 h format
164 //bool ampm = config.readBoolEntry( "AMPM", TRUE ); 158 //bool ampm = config.readBoolEntry( "AMPM", TRUE );
165 159
166 int count=0; 160 int count=0;
167 161
168 if ( list.count() > 0 ) { 162 if ( list.count() > 0 ) {
169 QString msg; 163 QString msg;
170 164
171 for ( QValueList<EffectiveEvent>::ConstIterator it=list.begin(); 165 for ( QValueList<EffectiveEvent>::ConstIterator it=list.begin();
172 it!=list.end(); ++it ) { 166 it!=list.end(); ++it ) {
173 167
174 count++; 168 count++;
175 169
176 if ( count <= MAX_LINES_MEET ) 170 if ( count <= MAX_LINES_MEET ) {
177 { 171 //cout << time.toString() << endl;
178 //cout << time.toString() << endl; 172 //cout << TimeString::dateString((*it).event().end()) << endl;
179 //cout << TimeString::dateString((*it).event().end()) << endl; 173
174 // decide if to get all day or only later appointments
175 if (!ONLY_LATER) {
176 msg += "<B>" + (*it).description() + "</B>";
177 if ( (*it).event().hasAlarm() ) {
178 msg += " <b>[with alarm]</b>";
179 }
180 // include location or not
181 if (SHOW_LOCATION == 1) {
182 msg += "<BR><i>" + (*it).location();
183 msg += "</i>";
184 }
185
186 if ( (TimeString::timeString(QTime((*it).event().start().time()) ) == "00:00") && (TimeString::timeString(QTime((*it).event().end().time()) ) == "23:59") ) {
187 msg += "<br>All day";
188 } else {
189 // start time of event
190 msg += "<br>" + TimeString::timeString(QTime((*it).event().start().time()) )
191 // end time of event
192 + "<b> - </b>" + TimeString::timeString(QTime((*it).event().end().time()) );
193 }
194 msg += "<BR>";
195 // include possible note or not
196 if (SHOW_NOTES == 1) {
197 msg += " <i>note</i>:" +((*it).notes()).mid(0, MAX_CHAR_CLIP) + "<br>";
198 }
199 } else if ((time.toString() <= TimeString::dateString((*it).event().end())) ) {
200 msg += "<B>" + (*it).description() + "</B>";
201 if ( (*it).event().hasAlarm() ) {
202 msg += " <b>[with alarm]</b>";
203 }
204 // include location or not
205 if (SHOW_LOCATION == 1) {
206 msg+= "<BR><i>" + (*it).location();
207 msg += "</i>";
208 }
180 209
181 // decide if to get all day or only later appointments 210 if ( (TimeString::timeString(QTime((*it).event().start().time()) ) == "00:00") && (TimeString::timeString(QTime((*it).event().end().time()) ) == "23:59") ) {
182 if (!ONLY_LATER) 211 msg += "<br>All day";
183 { 212 } else {
184 msg += "<B>" + (*it).description() + "</B>"; 213 // start time of event
185 if ( (*it).event().hasAlarm() ) 214 msg += "<br>" + TimeString::timeString(QTime((*it).event().start().time()) )
186 { 215 // end time of event
187 msg += " <b>[with alarm]</b>"; 216 + "<b> - </b>" + TimeString::timeString(QTime((*it).event().end().time()) );
188 } 217 }
189 // include location or not 218 msg += "<BR>";
190 if (SHOW_LOCATION == 1) 219 // include possible note or not
191 { 220 if (SHOW_NOTES == 1) {
192 msg += "<BR><i>" + (*it).location(); 221 msg += " <i>note</i>:" +((*it).notes()).mid(0, MAX_CHAR_CLIP) + "<br>";
193 msg += "</i>"; 222 }
194 }
195
196 if ( (TimeString::timeString(QTime((*it).event().start().time()) ) == "00:00") && (TimeString::timeString(QTime((*it).event().end().time()) ) == "23:59") )
197 {
198 msg += "<br>All day";
199 }
200 else
201 {
202 // start time of event
203 msg += "<br>" + TimeString::timeString(QTime((*it).event().start().time()) )
204 // end time of event
205 + "<b> - </b>" + TimeString::timeString(QTime((*it).event().end().time()) );
206 }
207 msg += "<BR>";
208 // include possible note or not
209 if (SHOW_NOTES == 1)
210 {
211 msg += " <i>note</i>:" +((*it).notes()).mid(0, MAX_CHAR_CLIP) + "<br>";
212 }
213 }
214 else if ((time.toString() <= TimeString::dateString((*it).event().end())) )
215 {
216 msg += "<B>" + (*it).description() + "</B>";
217 if ( (*it).event().hasAlarm() )
218 {
219 msg += " <b>[with alarm]</b>";
220 }
221 // include location or not
222 if (SHOW_LOCATION == 1)
223 {
224 msg+= "<BR><i>" + (*it).location();
225 msg += "</i>";
226 }
227
228 if ( (TimeString::timeString(QTime((*it).event().start().time()) ) == "00:00") && (TimeString::timeString(QTime((*it).event().end().time()) ) == "23:59") )
229 {
230 msg += "<br>All day";
231 }
232 else
233 {
234 // start time of event
235 msg += "<br>" + TimeString::timeString(QTime((*it).event().start().time()) )
236 // end time of event
237 + "<b> - </b>" + TimeString::timeString(QTime((*it).event().end().time()) );
238 }
239 msg += "<BR>";
240 // include possible note or not
241 if (SHOW_NOTES == 1)
242 {
243 msg += " <i>note</i>:" +((*it).notes()).mid(0, MAX_CHAR_CLIP) + "<br>";
244 }
245 }
246 } 223 }
247 }
248 if (msg.isEmpty())
249 {
250 msg = "No more appointments today";
251 } 224 }
225 }
226 if (msg.isEmpty()) {
227 msg = "No more appointments today";
228 }
252 DatesField->setText(msg); 229 DatesField->setText(msg);
253 } 230 }
254} 231}
255 232
256/* 233/*
257 * Parse in the todolist.xml 234 * Parse in the todolist.xml
258 */ 235 */
259QList<TodoItem> Today::loadTodo(const char *filename) 236QList<TodoItem> Today::loadTodo(const char *filename) {
260{
261 DOM *todo; 237 DOM *todo;
262 ELE *tasks; 238 ELE *tasks;
263 ELE **tasklist; 239 ELE **tasklist;
264 ATT **attlist; 240 ATT **attlist;
265 int i, j; 241 int i, j;
266 char *description; 242 char *description;
267 int completed; 243 int completed;
268 int priority; 244 int priority;
269 TodoItem *tmp; 245 TodoItem *tmp;
270 QList<TodoItem> loadtodolist; 246 QList<TodoItem> loadtodolist;
271 247
272 todo = minidom_load(filename); 248 todo = minidom_load(filename);
273 249
274 tasks = todo->el; 250 tasks = todo->el;
275 tasks = tasks->el[0]; /*!DOCTYPE-quickhack*/ 251 tasks = tasks->el[0]; /*!DOCTYPE-quickhack*/
276 if(tasks) 252 if(tasks) {
277 { 253 tasklist = tasks->el;
278 tasklist = tasks->el; 254 i = 0;
279 i = 0; 255 while((tasklist) && (tasklist[i])) {
280 while((tasklist) && (tasklist[i])) 256 attlist = tasklist[i]->at;
281 { 257 j = 0;
282 attlist = tasklist[i]->at; 258 description = NULL;
283 j = 0; 259 priority = -1;
284 description = NULL; 260 completed = -1;
285 priority = -1; 261 while((attlist) && (attlist[j])) {
286 completed = -1; 262 if(!attlist[j]->name) {
287 while((attlist) && (attlist[j])) 263 continue;
288 {
289 // SEGFAULT HERE WITH MORE THAN 7 ENTRIES
290 if(!attlist[j]->name) continue;
291 if(!strcmp(attlist[j]->name, "Description"))
292 {
293 description = attlist[j]->value;
294 }
295 // get Completed tag (0 or 1)
296 if(!strcmp(attlist[j]->name, "Completed"))
297 {
298 QString s = attlist[j]->name;
299 if(s == "Completed")
300 {
301 completed = QString(attlist[j]->value).toInt();
302 }
303 }
304 // get Priority (1 to 5)
305 if(!strcmp(attlist[j]->name, "Priority"))
306 {
307 QString s = attlist[j]->name;
308 if(s == "Priority")
309 {
310 priority = QString(attlist[j]->value).toInt();
311 }
312 }
313 j++;
314 }
315 if(description)
316 {
317 tmp = new TodoItem(description, completed, priority);
318 loadtodolist.append(tmp);
319 }
320 i++;
321 } 264 }
265 if(!strcmp(attlist[j]->name, "Description")) {
266 description = attlist[j]->value;
267 }
268 // get Completed tag (0 or 1)
269 if(!strcmp(attlist[j]->name, "Completed")) {
270 QString s = attlist[j]->name;
271 if(s == "Completed") {
272 completed = QString(attlist[j]->value).toInt();
273 }
274 }
275 // get Priority (1 to 5)
276 if(!strcmp(attlist[j]->name, "Priority")) {
277 QString s = attlist[j]->name;
278 if(s == "Priority") {
279 priority = QString(attlist[j]->value).toInt();
280 }
281 }
282 j++;
283 }
284 if(description) {
285 tmp = new TodoItem(description, completed, priority);
286 loadtodolist.append(tmp);
287 }
288 i++;
322 } 289 }
323 290 }
291
324 minidom_free(todo); 292 minidom_free(todo);
325 293
326 return loadtodolist; 294 return loadtodolist;
327} 295}
328 296
329 297
330void Today::getMail() 298void Today::getMail() {
331{
332 Config cfg("opiemail"); 299 Config cfg("opiemail");
333 cfg.setGroup("today"); 300 cfg.setGroup("today");
334 301
335 // how many lines should be showed in the task section 302 // how many lines should be showed in the task section
336 int NEW_MAILS = cfg.readNumEntry("newmails",0); 303 int NEW_MAILS = cfg.readNumEntry("newmails",0);
337 int OUTGOING = cfg.readNumEntry("outgoing",0); 304 int OUTGOING = cfg.readNumEntry("outgoing",0);
338 305
339 QString output = tr("<b>%1</b> new mails, <b>%2</b> outgoing").arg(NEW_MAILS).arg(OUTGOING); 306
307 QString output = tr("<b>%1</b> new mail(s), <b>%2</b> outgoing").arg(NEW_MAILS).arg(OUTGOING);
340 308
341 309
342 MailField->setText(output); 310 MailField->setText(output);
343} 311}
344 312
345 313
346/* 314/*
347 * Get the todos 315 * Get the todos
348 * 316 *
349 */ 317 */
350void Today::getTodo() 318void Today::getTodo() {
351{
352 QString output; 319 QString output;
353 QString tmpout; 320 QString tmpout;
354 int count = 0; 321 int count = 0;
355 322
356 QDir dir; 323 QDir dir;
357 QString homedir = dir.homeDirPath (); 324 QString homedir = dir.homeDirPath ();
358 // see if todolist.xml does exist. 325 // see if todolist.xml does exist.
359 QFile f(homedir +"/Applications/todolist/todolist.xml"); 326 QFile f(homedir +"/Applications/todolist/todolist.xml");
360 if ( f.exists() ) 327 if ( f.exists() ) {
361 { 328 QList<TodoItem> todolist = loadTodo(homedir +"/Applications/todolist/todolist.xml");
362 QList<TodoItem> todolist = loadTodo(homedir +"/Applications/todolist/todolist.xml"); 329
363 330 TodoItem *item;
364 TodoItem *item; 331 for( item = todolist.first(); item; item = todolist.next()) {
365 for( item = todolist.first(); item; item = todolist.next()) 332 if (!(item->getCompleted() == 1) ) {
366 { 333 count++;
367 if (!(item->getCompleted() == 1) ) 334 if (count <= MAX_LINES_TASK) {
368 { 335 tmpout += "<b>- </b>" + QString(((item)->getDescription().mid(0, MAX_CHAR_CLIP) + ("<br>")));
369 count++;
370 if (count <= MAX_LINES_TASK)
371 {
372 tmpout += "<b>- </b>" + QString(((item)->getDescription().mid(0, MAX_CHAR_CLIP) + ("<br>")));
373 }
374 }
375 } 336 }
337 }
376 } 338 }
339 }
377 340
378 if (count > 0) 341 if (count > 0) {
379 { 342 if( count == 1 ) {
343 output = QString("There is <b> 1</b> active task: <br>" );
344 } else {
380 output = QString("There are <b> %1</b> active tasks: <br>").arg(count); 345 output = QString("There are <b> %1</b> active tasks: <br>").arg(count);
381 output += tmpout;
382 }
383 else
384 {
385 output = ("No active tasks");
386 } 346 }
347 output += tmpout;
348 } else {
349 output = ("No active tasks");
350 }
387 351
388 TodoField->setText(output); 352 TodoField->setText(output);
389} 353}
390 354
391/* 355/*
392 * launches datebook 356 * launches datebook
393 */ 357 */
394void Today::startDatebook() 358void Today::startDatebook() {
395{
396 QCopEnvelope e("QPE/System", "execute(QString)"); 359 QCopEnvelope e("QPE/System", "execute(QString)");
397 e << QString("datebook"); 360 e << QString("datebook");
398} 361}
399 362
400/* 363/*
401 * launches todolist 364 * launches todolist
402 */ 365 */
403void Today::startTodo() 366void Today::startTodo() {
404{
405 QCopEnvelope e("QPE/System", "execute(QString)"); 367 QCopEnvelope e("QPE/System", "execute(QString)");
406 e << QString("todolist"); 368 e << QString("todolist");
407} 369}
408 370
409/* 371/*
410 * launch opiemail 372 * launch opiemail
411 */ 373 */
412void Today::startMail() 374void Today::startMail() {
413{
414 QCopEnvelope e("QPE/System", "execute(QString)"); 375 QCopEnvelope e("QPE/System", "execute(QString)");
415 e << QString("opiemail"); 376 e << QString("opiemail");
416} 377}
417 378
418/* 379/*
419 * Destroys the object and frees any allocated resources 380 * Destroys the object and frees any allocated resources
420 */ 381 */
421Today::~Today() 382Today::~Today() {
422{
423 // no need to delete child widgets, Qt does it all for us 383 // no need to delete child widgets, Qt does it all for us
424} 384}