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