author | harlekin <harlekin> | 2002-02-16 13:47:42 (UTC) |
---|---|---|
committer | harlekin <harlekin> | 2002-02-16 13:47:42 (UTC) |
commit | 992d35bb675392922fe1971cb24d76acd3a63747 (patch) (unidiff) | |
tree | f67ae67aebcfcba77b8198a4e5be25b3c2f15eec | |
parent | f866bbd2fd77f07cff04a702eb52e59fcc0013b7 (diff) | |
download | opie-992d35bb675392922fe1971cb24d76acd3a63747.zip opie-992d35bb675392922fe1971cb24d76acd3a63747.tar.gz opie-992d35bb675392922fe1971cb24d76acd3a63747.tar.bz2 |
QCopEnvelope instead of system()
-rw-r--r-- | core/pim/today/today.cpp | 23 |
1 files changed, 11 insertions, 12 deletions
diff --git a/core/pim/today/today.cpp b/core/pim/today/today.cpp index 381ae6b..00a8842 100644 --- a/core/pim/today/today.cpp +++ b/core/pim/today/today.cpp | |||
@@ -1,335 +1,334 @@ | |||
1 | /* | 1 | /* |
2 | * today.cpp : main class | 2 | * today.cpp : main class |
3 | * | 3 | * |
4 | * --------------------- | 4 | * --------------------- |
5 | * | 5 | * |
6 | * begin : Sun 10 17:20:00 CEST 2002 | 6 | * begin : Sun 10 17:20:00 CEST 2002 |
7 | * copyright : (c) 2002 by Maximilian Reiß | 7 | * copyright : (c) 2002 by Maximilian Reiß |
8 | * email : max.reiss@gmx.de | 8 | * email : max.reiss@gmx.de |
9 | * | 9 | * |
10 | */ | 10 | */ |
11 | /*************************************************************************** | 11 | /*************************************************************************** |
12 | * * | 12 | * * |
13 | * This program is free software; you can redistribute it and/or modify * | 13 | * This program is free software; you can redistribute it and/or modify * |
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 <qpushbutton.h> | ||
25 | #include <qlabel.h> | ||
26 | |||
27 | #include <qpe/datebookdb.h> | 24 | #include <qpe/datebookdb.h> |
28 | #include <qpe/timestring.h> | 25 | #include <qpe/timestring.h> |
29 | #include <qpe/config.h> | 26 | #include <qpe/config.h> |
30 | 27 | #include <qpe/qcopenvelope_qws.h> | |
31 | #include <qpe/qprocess.h> | 28 | #include <qpe/qprocess.h> |
29 | |||
32 | #include <qdir.h> | 30 | #include <qdir.h> |
33 | #include <qfile.h> | 31 | #include <qfile.h> |
34 | #include <qdatetime.h> | 32 | #include <qdatetime.h> |
35 | #include <qtextstream.h> | 33 | #include <qtextstream.h> |
36 | #include <qcheckbox.h> | 34 | #include <qcheckbox.h> |
37 | #include <qspinbox.h> | 35 | #include <qspinbox.h> |
36 | #include <qpushbutton.h> | ||
37 | #include <qlabel.h> | ||
38 | 38 | ||
39 | //#include <iostream.h> | 39 | //#include <iostream.h> |
40 | //#include <unistd.h> | 40 | //#include <unistd.h> |
41 | #include <stdlib.h> | 41 | #include <stdlib.h> |
42 | 42 | ||
43 | int MAX_LINES_TASK; | 43 | int MAX_LINES_TASK; |
44 | int MAX_CHAR_CLIP; | 44 | int MAX_CHAR_CLIP; |
45 | int MAX_LINES_MEET; | 45 | int MAX_LINES_MEET; |
46 | int SHOW_LOCATION; | 46 | int SHOW_LOCATION; |
47 | int SHOW_NOTES; | 47 | int SHOW_NOTES; |
48 | // show only later dates | 48 | // show only later dates |
49 | int ONLY_LATER = 1; | 49 | int ONLY_LATER = 1; |
50 | /* | 50 | /* |
51 | * Constructs a Example which is a child of 'parent', with the | 51 | * Constructs a Example which is a child of 'parent', with the |
52 | * name 'name' and widget flags set to 'f' | 52 | * name 'name' and widget flags set to 'f' |
53 | */ | 53 | */ |
54 | Today::Today( QWidget* parent, const char* name, WFlags fl ) | 54 | Today::Today( QWidget* parent, const char* name, WFlags fl ) |
55 | : TodayBase( parent, name, fl ) | 55 | : TodayBase( parent, name, fl ) |
56 | { | 56 | { |
57 | QObject::connect( (QObject*)PushButton1, SIGNAL( clicked() ), this, SLOT(startConfig() ) ); | 57 | QObject::connect( (QObject*)PushButton1, SIGNAL( clicked() ), this, SLOT(startConfig() ) ); |
58 | QObject::connect( (QObject*)TodoButton, SIGNAL( clicked() ), this, SLOT(startTodo() ) ); | 58 | QObject::connect( (QObject*)TodoButton, SIGNAL( clicked() ), this, SLOT(startTodo() ) ); |
59 | QObject::connect( (QObject*)DatesButton, SIGNAL( clicked() ), this, SLOT(startDatebook() ) ); | 59 | QObject::connect( (QObject*)DatesButton, SIGNAL( clicked() ), this, SLOT(startDatebook() ) ); |
60 | 60 | ||
61 | QDate date = QDate::currentDate(); | 61 | QDate date = QDate::currentDate(); |
62 | QString time = (date.toString()); | 62 | QString time = (date.toString()); |
63 | TextLabel1->setText(time); | 63 | TextLabel1->setText(time); |
64 | db = new DateBookDB; | 64 | db = new DateBookDB; |
65 | 65 | ||
66 | init(); | 66 | init(); |
67 | getDates(); | 67 | getDates(); |
68 | getTodo(); | 68 | getTodo(); |
69 | } | 69 | } |
70 | 70 | ||
71 | 71 | ||
72 | void Today::init() | 72 | void Today::init() |
73 | { | 73 | { |
74 | // read config | 74 | // read config |
75 | Config cfg("today"); | 75 | Config cfg("today"); |
76 | cfg.setGroup("BaseConfig"); | 76 | cfg.setGroup("BaseConfig"); |
77 | 77 | ||
78 | // how many lines should be showed in the task section | 78 | // how many lines should be showed in the task section |
79 | MAX_LINES_TASK = cfg.readNumEntry("maxlinestask",5); | 79 | MAX_LINES_TASK = cfg.readNumEntry("maxlinestask",5); |
80 | // after how many chars should the be cut off on tasks and notes | 80 | // after how many chars should the be cut off on tasks and notes |
81 | MAX_CHAR_CLIP = cfg.readNumEntry("maxcharclip",30); | 81 | MAX_CHAR_CLIP = cfg.readNumEntry("maxcharclip",30); |
82 | // how many lines should be showed in the datebook section | 82 | // how many lines should be showed in the datebook section |
83 | MAX_LINES_MEET = cfg.readNumEntry("maxlinesmeet",5); | 83 | MAX_LINES_MEET = cfg.readNumEntry("maxlinesmeet",5); |
84 | // If location is to be showed too, 1 to activate it. | 84 | // If location is to be showed too, 1 to activate it. |
85 | SHOW_LOCATION = cfg.readNumEntry("showlocation",1); | 85 | SHOW_LOCATION = cfg.readNumEntry("showlocation",1); |
86 | // if notes should be shown | 86 | // if notes should be shown |
87 | SHOW_NOTES = cfg.readNumEntry("shownotes",0); | 87 | SHOW_NOTES = cfg.readNumEntry("shownotes",0); |
88 | } | 88 | } |
89 | 89 | ||
90 | void Today::startConfig() | 90 | void Today::startConfig() |
91 | { | 91 | { |
92 | conf = new todayconfig ( this, "", true ); | 92 | conf = new todayconfig ( this, "", true ); |
93 | 93 | ||
94 | 94 | ||
95 | //Config cfg = new Config("today"); | 95 | //Config cfg = new Config("today"); |
96 | 96 | ||
97 | // read the config | 97 | // read the config |
98 | Config cfg("today"); | 98 | Config cfg("today"); |
99 | cfg.setGroup("BaseConfig"); | 99 | cfg.setGroup("BaseConfig"); |
100 | 100 | ||
101 | //init(); | 101 | //init(); |
102 | 102 | ||
103 | conf->SpinBox1->setValue(MAX_LINES_MEET); | 103 | conf->SpinBox1->setValue(MAX_LINES_MEET); |
104 | // location show box | 104 | // location show box |
105 | conf->CheckBox1->setChecked(SHOW_LOCATION); | 105 | conf->CheckBox1->setChecked(SHOW_LOCATION); |
106 | // notes show box | 106 | // notes show box |
107 | conf->CheckBox2->setChecked(SHOW_NOTES); | 107 | conf->CheckBox2->setChecked(SHOW_NOTES); |
108 | // task lines | 108 | // task lines |
109 | conf->SpinBox2->setValue(MAX_LINES_TASK); | 109 | conf->SpinBox2->setValue(MAX_LINES_TASK); |
110 | // clip when? | 110 | // clip when? |
111 | conf->SpinBox7->setValue(MAX_CHAR_CLIP); | 111 | conf->SpinBox7->setValue(MAX_CHAR_CLIP); |
112 | 112 | ||
113 | conf->exec(); | 113 | conf->exec(); |
114 | 114 | ||
115 | int maxlinestask = conf->SpinBox2->value(); | 115 | int maxlinestask = conf->SpinBox2->value(); |
116 | int maxmeet = conf->SpinBox1->value(); | 116 | int maxmeet = conf->SpinBox1->value(); |
117 | int location = conf->CheckBox1->isChecked(); | 117 | int location = conf->CheckBox1->isChecked(); |
118 | int notes = conf->CheckBox2->isChecked(); | 118 | int notes = conf->CheckBox2->isChecked(); |
119 | int maxcharclip = conf->SpinBox7->value(); | 119 | int maxcharclip = conf->SpinBox7->value(); |
120 | 120 | ||
121 | cfg.writeEntry("maxlinestask",maxlinestask); | 121 | cfg.writeEntry("maxlinestask",maxlinestask); |
122 | cfg.writeEntry("maxcharclip", maxcharclip); | 122 | cfg.writeEntry("maxcharclip", maxcharclip); |
123 | cfg.writeEntry("maxlinesmeet",maxmeet); | 123 | cfg.writeEntry("maxlinesmeet",maxmeet); |
124 | cfg.writeEntry("showlocation",location); | 124 | cfg.writeEntry("showlocation",location); |
125 | cfg.writeEntry("shownotes", notes); | 125 | cfg.writeEntry("shownotes", notes); |
126 | // sync it to "disk" | 126 | // sync it to "disk" |
127 | cfg.write(); | 127 | cfg.write(); |
128 | 128 | ||
129 | init(); | 129 | init(); |
130 | getDates(); | 130 | getDates(); |
131 | getTodo(); | 131 | getTodo(); |
132 | //cout << location << endl; | 132 | //cout << location << endl; |
133 | } | 133 | } |
134 | 134 | ||
135 | 135 | ||
136 | /* | 136 | /* |
137 | * Get all events that are in the datebook xml file for today | 137 | * Get all events that are in the datebook xml file for today |
138 | */ | 138 | */ |
139 | void Today::getDates() | 139 | void Today::getDates() |
140 | { | 140 | { |
141 | QDate date = QDate::currentDate(); | 141 | QDate date = QDate::currentDate(); |
142 | QTime time = QTime::currentTime(); | 142 | QTime time = QTime::currentTime(); |
143 | QValueList<EffectiveEvent> list = db->getEffectiveEvents(date, date); | 143 | QValueList<EffectiveEvent> list = db->getEffectiveEvents(date, date); |
144 | 144 | ||
145 | Config config( "qpe" ); | 145 | Config config( "qpe" ); |
146 | // if 24 h format | 146 | // if 24 h format |
147 | // bool ampm = config.readBoolEntry( "AMPM", TRUE ); | 147 | // bool ampm = config.readBoolEntry( "AMPM", TRUE ); |
148 | 148 | ||
149 | int count=0; | 149 | int count=0; |
150 | 150 | ||
151 | if ( list.count() > 0 ) { | 151 | if ( list.count() > 0 ) { |
152 | QString msg; | 152 | QString msg; |
153 | 153 | ||
154 | for ( QValueList<EffectiveEvent>::ConstIterator it=list.begin(); | 154 | for ( QValueList<EffectiveEvent>::ConstIterator it=list.begin(); |
155 | it!=list.end(); ++it ) { | 155 | it!=list.end(); ++it ) { |
156 | 156 | ||
157 | count++; | 157 | count++; |
158 | 158 | ||
159 | if ( count <= MAX_LINES_MEET ) | 159 | if ( count <= MAX_LINES_MEET ) |
160 | { | 160 | { |
161 | //only get events past current time (start or end??) | 161 | //only get events past current time (start or end??) |
162 | //cout << time.toString() << endl; | 162 | //cout << time.toString() << endl; |
163 | //cout << TimeString::dateString((*it).event().end()) << endl; | 163 | //cout << TimeString::dateString((*it).event().end()) << endl; |
164 | // still some bug in here, 1 h off | 164 | // still some bug in here, 1 h off |
165 | if ((time.toString() <= TimeString::dateString((*it).event().end())) && ONLY_LATER ) | 165 | if ((time.toString() <= TimeString::dateString((*it).event().end())) && ONLY_LATER ) |
166 | { | 166 | { |
167 | msg += "<B>" + (*it).description() + "</B>"; | 167 | msg += "<B>" + (*it).description() + "</B>"; |
168 | // include location or not | 168 | // include location or not |
169 | if (SHOW_LOCATION == 1) | 169 | if (SHOW_LOCATION == 1) |
170 | { | 170 | { |
171 | msg+= "<BR>" + (*it).location(); | 171 | msg+= "<BR>" + (*it).location(); |
172 | } | 172 | } |
173 | msg += "<BR>" | 173 | msg += "<BR>" |
174 | // start time of event | 174 | // start time of event |
175 | + TimeString::timeString(QTime((*it).event().start().time()) ) | 175 | + TimeString::timeString(QTime((*it).event().start().time()) ) |
176 | // end time of event | 176 | // end time of event |
177 | + "<b> - </b>" + TimeString::timeString(QTime((*it).event().end().time()) ) | 177 | + "<b> - </b>" + TimeString::timeString(QTime((*it).event().end().time()) ) |
178 | + "<BR>"; | 178 | + "<BR>"; |
179 | // include possible note or not | 179 | // include possible note or not |
180 | if (SHOW_NOTES == 1) | 180 | if (SHOW_NOTES == 1) |
181 | { | 181 | { |
182 | msg += " <i>note</i>:" +((*it).notes()).mid(0, MAX_CHAR_CLIP) + "<br>"; | 182 | msg += " <i>note</i>:" +((*it).notes()).mid(0, MAX_CHAR_CLIP) + "<br>"; |
183 | } | 183 | } |
184 | } | 184 | } |
185 | } | 185 | } |
186 | } | 186 | } |
187 | DatesField->setText(msg); | 187 | DatesField->setText(msg); |
188 | } | 188 | } |
189 | } | 189 | } |
190 | 190 | ||
191 | /* | 191 | /* |
192 | * | 192 | * Parse in the todolist.xml |
193 | * | 193 | * |
194 | */ | 194 | */ |
195 | QList<TodoItem> Today::loadTodo(const char *filename) | 195 | QList<TodoItem> Today::loadTodo(const char *filename) |
196 | { | 196 | { |
197 | DOM *todo; | 197 | DOM *todo; |
198 | ELE *tasks; | 198 | ELE *tasks; |
199 | ELE **tasklist; | 199 | ELE **tasklist; |
200 | ATT **attlist; | 200 | ATT **attlist; |
201 | int i, j; | 201 | int i, j; |
202 | char *description; | 202 | char *description; |
203 | int completed; | 203 | int completed; |
204 | int priority; | 204 | int priority; |
205 | TodoItem *tmp; | 205 | TodoItem *tmp; |
206 | QList<TodoItem> loadtodolist; | 206 | QList<TodoItem> loadtodolist; |
207 | 207 | ||
208 | todo = minidom_load(filename); | 208 | todo = minidom_load(filename); |
209 | 209 | ||
210 | tasks = todo->el; | 210 | tasks = todo->el; |
211 | tasks = tasks->el[0]; /*!DOCTYPE-quickhack*/ | 211 | tasks = tasks->el[0]; /*!DOCTYPE-quickhack*/ |
212 | if(tasks) | 212 | if(tasks) |
213 | { | 213 | { |
214 | tasklist = tasks->el; | 214 | tasklist = tasks->el; |
215 | i = 0; | 215 | i = 0; |
216 | while((tasklist) && (tasklist[i])) | 216 | while((tasklist) && (tasklist[i])) |
217 | { | 217 | { |
218 | attlist = tasklist[i]->at; | 218 | attlist = tasklist[i]->at; |
219 | j = 0; | 219 | j = 0; |
220 | description = NULL; | 220 | description = NULL; |
221 | priority = -1; | 221 | priority = -1; |
222 | completed = -1; | 222 | completed = -1; |
223 | while((attlist) && (attlist[j])) | 223 | while((attlist) && (attlist[j])) |
224 | { | 224 | { |
225 | if(!attlist[i]->name) continue; | 225 | if(!attlist[i]->name) continue; |
226 | if(!strcmp(attlist[j]->name, "Description")) | 226 | if(!strcmp(attlist[j]->name, "Description")) |
227 | { | 227 | { |
228 | description = attlist[j]->value; | 228 | description = attlist[j]->value; |
229 | } | 229 | } |
230 | // get Completed tag (0 or 1) | 230 | // get Completed tag (0 or 1) |
231 | if(!strcmp(attlist[j]->name, "Completed")) | 231 | if(!strcmp(attlist[j]->name, "Completed")) |
232 | { | 232 | { |
233 | QString s = attlist[j]->name; | 233 | QString s = attlist[j]->name; |
234 | if(s == "Completed") | 234 | if(s == "Completed") |
235 | { | 235 | { |
236 | completed = QString(attlist[j]->value).toInt(); | 236 | completed = QString(attlist[j]->value).toInt(); |
237 | } | 237 | } |
238 | } | 238 | } |
239 | // get Priority (1 to 5) | 239 | // get Priority (1 to 5) |
240 | if(!strcmp(attlist[j]->name, "Priority")) | 240 | if(!strcmp(attlist[j]->name, "Priority")) |
241 | { | 241 | { |
242 | QString s = attlist[j]->name; | 242 | QString s = attlist[j]->name; |
243 | if(s == "Priority") | 243 | if(s == "Priority") |
244 | { | 244 | { |
245 | priority = QString(attlist[j]->value).toInt(); | 245 | priority = QString(attlist[j]->value).toInt(); |
246 | } | 246 | } |
247 | } | 247 | } |
248 | j++; | 248 | j++; |
249 | } | 249 | } |
250 | if(description) | 250 | if(description) |
251 | { | 251 | { |
252 | tmp = new TodoItem(description, completed, priority); | 252 | tmp = new TodoItem(description, completed, priority); |
253 | loadtodolist.append(tmp); | 253 | loadtodolist.append(tmp); |
254 | } | 254 | } |
255 | i++; | 255 | i++; |
256 | } | 256 | } |
257 | } | 257 | } |
258 | 258 | ||
259 | minidom_free(todo); | 259 | minidom_free(todo); |
260 | 260 | ||
261 | return loadtodolist; | 261 | return loadtodolist; |
262 | } | 262 | } |
263 | 263 | ||
264 | 264 | ||
265 | /* | 265 | /* |
266 | * Get the todos | 266 | * Get the todos |
267 | * | 267 | * |
268 | */ | 268 | */ |
269 | void Today::getTodo() | 269 | void Today::getTodo() |
270 | { | 270 | { |
271 | QString output; | 271 | QString output; |
272 | QString tmpout; | 272 | QString tmpout; |
273 | int count = 0; | 273 | int count = 0; |
274 | 274 | ||
275 | QDir dir; | 275 | QDir dir; |
276 | QString homedir = dir.homeDirPath (); | 276 | QString homedir = dir.homeDirPath (); |
277 | // see if todolist.xml does exist. | 277 | // see if todolist.xml does exist. |
278 | QFile f(homedir +"/Applications/todolist/todolist.xml"); | 278 | QFile f(homedir +"/Applications/todolist/todolist.xml"); |
279 | if ( f.exists() ) | 279 | if ( f.exists() ) |
280 | { | 280 | { |
281 | QList<TodoItem> todolist = loadTodo(homedir +"/Applications/todolist/todolist.xml"); | 281 | QList<TodoItem> todolist = loadTodo(homedir +"/Applications/todolist/todolist.xml"); |
282 | 282 | ||
283 | TodoItem *item; | 283 | TodoItem *item; |
284 | for( item = todolist.first(); item; item = todolist.next()) | 284 | for( item = todolist.first(); item; item = todolist.next()) |
285 | { | 285 | { |
286 | if (!(item->getCompleted() == 1) ) | 286 | if (!(item->getCompleted() == 1) ) |
287 | { | 287 | { |
288 | count++; | 288 | count++; |
289 | if (count <= MAX_LINES_TASK) | 289 | if (count <= MAX_LINES_TASK) |
290 | { | 290 | { |
291 | tmpout += "<b>- </b>" + QString(((item)->getDescription().mid(0, MAX_CHAR_CLIP) + ("<br>"))); | 291 | tmpout += "<b>- </b>" + QString(((item)->getDescription().mid(0, MAX_CHAR_CLIP) + ("<br>"))); |
292 | } | 292 | } |
293 | } | 293 | } |
294 | } | 294 | } |
295 | } | 295 | } |
296 | 296 | ||
297 | if (count > 0) | 297 | if (count > 0) |
298 | { | 298 | { |
299 | output = QString("There are <b> %1</b> active tasks: <br>").arg(count); | 299 | output = QString("There are <b> %1</b> active tasks: <br>").arg(count); |
300 | output += tmpout; | 300 | output += tmpout; |
301 | } | 301 | } |
302 | else | 302 | else |
303 | { | 303 | { |
304 | output = ("No active tasks"); | 304 | output = ("No active tasks"); |
305 | } | 305 | } |
306 | 306 | ||
307 | TodoField->setText(output); | 307 | TodoField->setText(output); |
308 | } | 308 | } |
309 | 309 | ||
310 | /* | 310 | /* |
311 | * lanches datebook | 311 | * lanches datebook |
312 | */ | 312 | */ |
313 | void Today::startDatebook() | 313 | void Today::startDatebook() |
314 | { | 314 | { |
315 | //ugly but working | 315 | QCopEnvelope e("QPE/System", "execute(QString)"); |
316 | system("/opt/QtPalmtop/bin/datebook"); | 316 | e << QString("datebook"); |
317 | } | 317 | } |
318 | 318 | ||
319 | /* | 319 | /* |
320 | * lanches todolist | 320 | * lanches todolist |
321 | */ | 321 | */ |
322 | void Today::startTodo() | 322 | void Today::startTodo() |
323 | { | 323 | { |
324 | // QProcess *datelanch = new QProcess( this, "datebook"); | 324 | QCopEnvelope e("QPE/System", "execute(QString)"); |
325 | //datelanch->start(); | 325 | e << QString("todolist"); |
326 | system("/opt/QtPalmtop/bin/todolist"); | ||
327 | } | 326 | } |
328 | 327 | ||
329 | /* | 328 | /* |
330 | * Destroys the object and frees any allocated resources | 329 | * Destroys the object and frees any allocated resources |
331 | */ | 330 | */ |
332 | Today::~Today() | 331 | Today::~Today() |
333 | { | 332 | { |
334 | // no need to delete child widgets, Qt does it all for us | 333 | // no need to delete child widgets, Qt does it all for us |
335 | } | 334 | } |