-rw-r--r-- | core/pim/today/today.cpp | 29 |
1 files changed, 15 insertions, 14 deletions
diff --git a/core/pim/today/today.cpp b/core/pim/today/today.cpp index 58ba4f4..aef0a9b 100644 --- a/core/pim/today/today.cpp +++ b/core/pim/today/today.cpp | |||
@@ -26,294 +26,295 @@ | |||
26 | #include <qpe/resource.h> | 26 | #include <qpe/resource.h> |
27 | #include <qpe/contact.h> | 27 | #include <qpe/contact.h> |
28 | #include <qpe/global.h> | 28 | #include <qpe/global.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 | #include <qtimer.h> |
39 | #include <qpixmap.h> | 39 | #include <qpixmap.h> |
40 | #include <qfileinfo.h> | 40 | #include <qfileinfo.h> |
41 | #include <qlayout.h> | 41 | #include <qlayout.h> |
42 | #include <qtl.h> | 42 | #include <qtl.h> |
43 | 43 | ||
44 | //#include <iostream.h> | 44 | //#include <iostream.h> |
45 | #include <unistd.h> | 45 | #include <unistd.h> |
46 | #include <stdlib.h> | 46 | #include <stdlib.h> |
47 | 47 | ||
48 | int MAX_LINES_TASK; | 48 | int MAX_LINES_TASK; |
49 | int MAX_CHAR_CLIP; | 49 | int MAX_CHAR_CLIP; |
50 | int MAX_LINES_MEET; | 50 | int MAX_LINES_MEET; |
51 | int SHOW_LOCATION; | 51 | int SHOW_LOCATION; |
52 | int SHOW_NOTES; | 52 | int SHOW_NOTES; |
53 | // show only later dates | 53 | // show only later dates |
54 | int ONLY_LATER; | 54 | int ONLY_LATER; |
55 | int AUTOSTART; | 55 | int AUTOSTART; |
56 | int NEW_START=1; | 56 | int NEW_START=1; |
57 | 57 | ||
58 | /* | 58 | /* |
59 | * Constructs a Example which is a child of 'parent', with the | 59 | * Constructs a Example which is a child of 'parent', with the |
60 | * name 'name' and widget flags set to 'f' | 60 | * name 'name' and widget flags set to 'f' |
61 | */ | 61 | */ |
62 | Today::Today( QWidget* parent, const char* name, WFlags fl ) | 62 | Today::Today( QWidget* parent, const char* name, WFlags fl ) |
63 | : TodayBase( parent, name, fl ), AllDateBookEvents(NULL) { | 63 | : TodayBase( parent, name, fl ), AllDateBookEvents(NULL) { |
64 | QObject::connect( (QObject*)PushButton1, SIGNAL( clicked() ), this, SLOT(startConfig() ) ); | 64 | QObject::connect( (QObject*)PushButton1, SIGNAL( clicked() ), this, SLOT(startConfig() ) ); |
65 | QObject::connect( (QObject*)TodoButton, SIGNAL( clicked() ), this, SLOT(startTodo() ) ); | 65 | QObject::connect( (QObject*)TodoButton, SIGNAL( clicked() ), this, SLOT(startTodo() ) ); |
66 | QObject::connect( (QObject*)DatesButton, SIGNAL( clicked() ), this, SLOT(startDatebook() ) ); | 66 | QObject::connect( (QObject*)DatesButton, SIGNAL( clicked() ), this, SLOT(startDatebook() ) ); |
67 | QObject::connect( (QObject*)MailButton, SIGNAL( clicked() ), this, SLOT(startMail() ) ); | 67 | QObject::connect( (QObject*)MailButton, SIGNAL( clicked() ), this, SLOT(startMail() ) ); |
68 | 68 | ||
69 | #if defined(Q_WS_QWS) | 69 | #if defined(Q_WS_QWS) |
70 | #if !defined(QT_NO_COP) | 70 | #if !defined(QT_NO_COP) |
71 | QCopChannel *todayChannel = new QCopChannel("QPE/Today" , this ); | 71 | QCopChannel *todayChannel = new QCopChannel("QPE/Today" , this ); |
72 | connect (todayChannel, SIGNAL( received(const QCString &, const QByteArray &)), | 72 | connect (todayChannel, SIGNAL( received(const QCString &, const QByteArray &)), |
73 | this, SLOT ( channelReceived(const QCString &, const QByteArray &)) ); | 73 | this, SLOT ( channelReceived(const QCString &, const QByteArray &)) ); |
74 | #endif | 74 | #endif |
75 | #endif | 75 | #endif |
76 | 76 | ||
77 | setOwnerField(); | 77 | setOwnerField(); |
78 | todo = new ToDoDB; | 78 | todo = new ToDoDB; |
79 | getTodo(); | 79 | getTodo(); |
80 | draw(); | 80 | draw(); |
81 | autoStart(); | 81 | autoStart(); |
82 | } | 82 | } |
83 | 83 | ||
84 | /* | 84 | /* |
85 | * Qcop receive method. | 85 | * Qcop receive method. |
86 | */ | 86 | */ |
87 | void Today::channelReceived(const QCString &msg, const QByteArray & data) { | 87 | void Today::channelReceived(const QCString &msg, const QByteArray & data) { |
88 | QDataStream stream(data, IO_ReadOnly ); | 88 | QDataStream stream(data, IO_ReadOnly ); |
89 | if ( msg == "message(QString)" ) { | 89 | if ( msg == "message(QString)" ) { |
90 | QString message; | 90 | QString message; |
91 | stream >> message; | 91 | stream >> message; |
92 | setOwnerField(message); | 92 | setOwnerField(message); |
93 | } | 93 | } |
94 | 94 | ||
95 | } | 95 | } |
96 | 96 | ||
97 | /* | 97 | /* |
98 | * Initialises the owner field with the default value, the username | 98 | * Initialises the owner field with the default value, the username |
99 | */ | 99 | */ |
100 | void Today::setOwnerField() { | 100 | void Today::setOwnerField() { |
101 | QString file = Global::applicationFileName("addressbook", "businesscard.vcf"); | 101 | QString file = Global::applicationFileName("addressbook", "businesscard.vcf"); |
102 | if (QFile::exists(file)) { | 102 | if (QFile::exists(file)) { |
103 | Contact cont = Contact::readVCard(file)[0]; | 103 | Contact cont = Contact::readVCard(file)[0]; |
104 | QString returnString = cont.fullName(); | 104 | QString returnString = cont.fullName(); |
105 | OwnerField->setText( tr ("<b>Owned by " + returnString + "</b>")); | 105 | OwnerField->setText( tr ("<b>Owned by " + returnString + "</b>")); |
106 | } else { | 106 | } else { |
107 | OwnerField->setText( tr ("<b>Please fill out the business card </b>")); | 107 | OwnerField->setText( tr ("<b>Please fill out the business card </b>")); |
108 | } | 108 | } |
109 | } | 109 | } |
110 | 110 | ||
111 | /* | 111 | /* |
112 | * Set the owner field with a given QString, for example per qcop. | 112 | * Set the owner field with a given QString, for example per qcop. |
113 | */ | 113 | */ |
114 | void Today::setOwnerField(QString &message) { | 114 | void Today::setOwnerField(QString &message) { |
115 | if (!message.isEmpty()) { | 115 | if (!message.isEmpty()) { |
116 | OwnerField->setText("<b>" + message + "</b>"); | 116 | OwnerField->setText("<b>" + message + "</b>"); |
117 | } | 117 | } |
118 | } | 118 | } |
119 | 119 | ||
120 | /* | 120 | /* |
121 | * Autostart, uses the new (opie only) autostart method in the launcher code. | 121 | * Autostart, uses the new (opie only) autostart method in the launcher code. |
122 | * If registered against that today ist started on each resume. | 122 | * If registered against that today ist started on each resume. |
123 | */ | 123 | */ |
124 | void Today::autoStart() { | 124 | void Today::autoStart() { |
125 | Config cfg("today"); | 125 | Config cfg("today"); |
126 | cfg.setGroup("Autostart"); | 126 | cfg.setGroup("Autostart"); |
127 | AUTOSTART = cfg.readNumEntry("autostart",1); | 127 | AUTOSTART = cfg.readNumEntry("autostart",1); |
128 | if (AUTOSTART) { | 128 | if (AUTOSTART) { |
129 | QCopEnvelope e("QPE/System", "autoStart(QString,QString)"); | 129 | QCopEnvelope e("QPE/System", "autoStart(QString,QString)"); |
130 | e << QString("add"); | 130 | e << QString("add"); |
131 | e << QString("today"); | 131 | e << QString("today"); |
132 | } else { | 132 | } else { |
133 | QCopEnvelope e("QPE/System", "autoStart(QString,QString)"); | 133 | QCopEnvelope e("QPE/System", "autoStart(QString,QString)"); |
134 | e << QString("remove"); | 134 | e << QString("remove"); |
135 | e << QString("today"); | 135 | e << QString("today"); |
136 | } | 136 | } |
137 | } | 137 | } |
138 | 138 | ||
139 | /* | 139 | /* |
140 | * Repaint method. Reread all fields. | 140 | * Repaint method. Reread all fields. |
141 | */ | 141 | */ |
142 | void Today::draw() { | 142 | void Today::draw() { |
143 | init(); | 143 | init(); |
144 | getDates(); | 144 | getDates(); |
145 | getMail(); | 145 | getMail(); |
146 | 146 | ||
147 | // if the todolist.xml file was not modified in between, do not parse it. | 147 | // if the todolist.xml file was not modified in between, do not parse it. |
148 | if (checkIfModified()) { | 148 | if (checkIfModified()) { |
149 | if (todo) delete todo; | ||
149 | todo = new ToDoDB; | 150 | todo = new ToDoDB; |
150 | getTodo(); | 151 | getTodo(); |
151 | } | 152 | } |
152 | 153 | ||
153 | // how often refresh | 154 | // how often refresh |
154 | QTimer::singleShot( 20*1000, this, SLOT(draw() ) ); | 155 | QTimer::singleShot( 20*1000, this, SLOT(draw() ) ); |
155 | } | 156 | } |
156 | 157 | ||
157 | /* | 158 | /* |
158 | * Check if the todolist.xml was modified (if there are new entries. | 159 | * Check if the todolist.xml was modified (if there are new entries. |
159 | * Returns true if it was modified. | 160 | * Returns true if it was modified. |
160 | */ | 161 | */ |
161 | bool Today::checkIfModified() { | 162 | bool Today::checkIfModified() { |
162 | 163 | ||
163 | QDir dir; | 164 | QDir dir; |
164 | QString homedir = dir.homeDirPath (); | 165 | QString homedir = dir.homeDirPath (); |
165 | QString time; | 166 | QString time; |
166 | 167 | ||
167 | Config cfg("today"); | 168 | Config cfg("today"); |
168 | cfg.setGroup("Files"); | 169 | cfg.setGroup("Files"); |
169 | time = cfg.readEntry("todolisttimestamp", ""); | 170 | time = cfg.readEntry("todolisttimestamp", ""); |
170 | 171 | ||
171 | QFileInfo file = (homedir +"/Applications/todolist/todolist.xml"); | 172 | QFileInfo file = (homedir +"/Applications/todolist/todolist.xml"); |
172 | QDateTime fileTime = file.lastModified(); | 173 | QDateTime fileTime = file.lastModified(); |
173 | if (time.compare(fileTime.toString()) == 0) { | 174 | if (time.compare(fileTime.toString()) == 0) { |
174 | return false; | 175 | return false; |
175 | } else { | 176 | } else { |
176 | cfg.writeEntry("todolisttimestamp", fileTime.toString() ); | 177 | cfg.writeEntry("todolisttimestamp", fileTime.toString() ); |
177 | cfg.write(); | 178 | cfg.write(); |
178 | return true; | 179 | return true; |
179 | } | 180 | } |
180 | } | 181 | } |
181 | 182 | ||
182 | 183 | ||
183 | /* | 184 | /* |
184 | * Init stuff needed for today. Reads the config file. | 185 | * Init stuff needed for today. Reads the config file. |
185 | */ | 186 | */ |
186 | void Today::init() { | 187 | void Today::init() { |
187 | QDate date = QDate::currentDate(); | 188 | QDate date = QDate::currentDate(); |
188 | QString time = (tr( date.toString()) ); | 189 | QString time = (tr( date.toString()) ); |
189 | 190 | ||
190 | TextLabel1->setText(QString("<font color=#FFFFFF>" + time + "</font>")); | 191 | TextLabel1->setText(QString("<font color=#FFFFFF>" + time + "</font>")); |
191 | 192 | ||
192 | // read config | 193 | // read config |
193 | Config cfg("today"); | 194 | Config cfg("today"); |
194 | cfg.setGroup("BaseConfig"); | 195 | cfg.setGroup("BaseConfig"); |
195 | 196 | ||
196 | // -- config file section -- | 197 | // -- config file section -- |
197 | // how many lines should be showed in the task section | 198 | // how many lines should be showed in the task section |
198 | MAX_LINES_TASK = cfg.readNumEntry("maxlinestask",5); | 199 | MAX_LINES_TASK = cfg.readNumEntry("maxlinestask",5); |
199 | // after how many chars should the be cut off on tasks and notes | 200 | // after how many chars should the be cut off on tasks and notes |
200 | MAX_CHAR_CLIP = cfg.readNumEntry("maxcharclip",40); | 201 | MAX_CHAR_CLIP = cfg.readNumEntry("maxcharclip",40); |
201 | // how many lines should be showed in the datebook section | 202 | // how many lines should be showed in the datebook section |
202 | MAX_LINES_MEET = cfg.readNumEntry("maxlinesmeet",5); | 203 | MAX_LINES_MEET = cfg.readNumEntry("maxlinesmeet",5); |
203 | // If location is to be showed too, 1 to activate it. | 204 | // If location is to be showed too, 1 to activate it. |
204 | SHOW_LOCATION = cfg.readNumEntry("showlocation",1); | 205 | SHOW_LOCATION = cfg.readNumEntry("showlocation",1); |
205 | // if notes should be shown | 206 | // if notes should be shown |
206 | SHOW_NOTES = cfg.readNumEntry("shownotes",0); | 207 | SHOW_NOTES = cfg.readNumEntry("shownotes",0); |
207 | // should only later appointments be shown or all for the current day. | 208 | // should only later appointments be shown or all for the current day. |
208 | ONLY_LATER = cfg.readNumEntry("onlylater",1); | 209 | ONLY_LATER = cfg.readNumEntry("onlylater",1); |
209 | 210 | ||
210 | db = new DateBookDB; | 211 | db = new DateBookDB; |
211 | } | 212 | } |
212 | 213 | ||
213 | /* | 214 | /* |
214 | * The method for the configuration dialog. | 215 | * The method for the configuration dialog. |
215 | */ | 216 | */ |
216 | void Today::startConfig() { | 217 | void Today::startConfig() { |
217 | 218 | ||
218 | conf = new todayconfig ( this, "", true ); | 219 | conf = new todayconfig ( this, "", true ); |
219 | // read the config | 220 | // read the config |
220 | Config cfg("today"); | 221 | Config cfg("today"); |
221 | cfg.setGroup("BaseConfig"); | 222 | cfg.setGroup("BaseConfig"); |
222 | 223 | ||
223 | //init(); | 224 | //init(); |
224 | 225 | ||
225 | conf->SpinBox1->setValue(MAX_LINES_MEET); | 226 | conf->SpinBox1->setValue(MAX_LINES_MEET); |
226 | // location show box | 227 | // location show box |
227 | conf->CheckBox1->setChecked(SHOW_LOCATION); | 228 | conf->CheckBox1->setChecked(SHOW_LOCATION); |
228 | // notes show box | 229 | // notes show box |
229 | conf->CheckBox2->setChecked(SHOW_NOTES); | 230 | conf->CheckBox2->setChecked(SHOW_NOTES); |
230 | // task lines | 231 | // task lines |
231 | conf->SpinBox2->setValue(MAX_LINES_TASK); | 232 | conf->SpinBox2->setValue(MAX_LINES_TASK); |
232 | // clip when? | 233 | // clip when? |
233 | conf->SpinBox7->setValue(MAX_CHAR_CLIP); | 234 | conf->SpinBox7->setValue(MAX_CHAR_CLIP); |
234 | // only later | 235 | // only later |
235 | conf->CheckBox3->setChecked(ONLY_LATER); | 236 | conf->CheckBox3->setChecked(ONLY_LATER); |
236 | // if today should be autostarted | 237 | // if today should be autostarted |
237 | conf->CheckBoxAuto->setChecked(AUTOSTART); | 238 | conf->CheckBoxAuto->setChecked(AUTOSTART); |
238 | 239 | ||
239 | conf->exec(); | 240 | conf->exec(); |
240 | 241 | ||
241 | int maxlinestask = conf->SpinBox2->value(); | 242 | int maxlinestask = conf->SpinBox2->value(); |
242 | int maxmeet = conf->SpinBox1->value(); | 243 | int maxmeet = conf->SpinBox1->value(); |
243 | int location = conf->CheckBox1->isChecked(); | 244 | int location = conf->CheckBox1->isChecked(); |
244 | int notes = conf->CheckBox2->isChecked(); | 245 | int notes = conf->CheckBox2->isChecked(); |
245 | int maxcharclip = conf->SpinBox7->value(); | 246 | int maxcharclip = conf->SpinBox7->value(); |
246 | int onlylater = conf->CheckBox3->isChecked(); | 247 | int onlylater = conf->CheckBox3->isChecked(); |
247 | int autostart =conf->CheckBoxAuto->isChecked(); | 248 | int autostart =conf->CheckBoxAuto->isChecked(); |
248 | 249 | ||
249 | cfg.writeEntry("maxlinestask",maxlinestask); | 250 | cfg.writeEntry("maxlinestask",maxlinestask); |
250 | cfg.writeEntry("maxcharclip", maxcharclip); | 251 | cfg.writeEntry("maxcharclip", maxcharclip); |
251 | cfg.writeEntry("maxlinesmeet",maxmeet); | 252 | cfg.writeEntry("maxlinesmeet",maxmeet); |
252 | cfg.writeEntry("showlocation",location); | 253 | cfg.writeEntry("showlocation",location); |
253 | cfg.writeEntry("shownotes", notes); | 254 | cfg.writeEntry("shownotes", notes); |
254 | cfg.writeEntry("onlylater", onlylater); | 255 | cfg.writeEntry("onlylater", onlylater); |
255 | cfg.setGroup("Autostart"); | 256 | cfg.setGroup("Autostart"); |
256 | cfg.writeEntry("autostart", autostart); | 257 | cfg.writeEntry("autostart", autostart); |
257 | 258 | ||
258 | // sync it to "disk" | 259 | // sync it to "disk" |
259 | cfg.write(); | 260 | cfg.write(); |
260 | NEW_START=1; | 261 | NEW_START=1; |
261 | draw(); | 262 | draw(); |
262 | autoStart(); | 263 | autoStart(); |
263 | } | 264 | } |
264 | 265 | ||
265 | 266 | ||
266 | /* | 267 | /* |
267 | * Get all events that are in the datebook xml file for today | 268 | * Get all events that are in the datebook xml file for today |
268 | */ | 269 | */ |
269 | void Today::getDates() { | 270 | void Today::getDates() { |
270 | QDate date = QDate::currentDate(); | 271 | QDate date = QDate::currentDate(); |
271 | 272 | ||
272 | if (AllDateBookEvents) delete AllDateBookEvents; | 273 | if (AllDateBookEvents) delete AllDateBookEvents; |
273 | AllDateBookEvents = new QWidget( ); | 274 | AllDateBookEvents = new QWidget( ); |
274 | QVBoxLayout* layoutDates = new QVBoxLayout(AllDateBookEvents); | 275 | QVBoxLayout* layoutDates = new QVBoxLayout(AllDateBookEvents); |
275 | 276 | ||
276 | QValueList<EffectiveEvent> list = db->getEffectiveEvents(date, date); | 277 | QValueList<EffectiveEvent> list = db->getEffectiveEvents(date, date); |
277 | 278 | ||
278 | qBubbleSort(list); | 279 | qBubbleSort(list); |
279 | // printf("Get dates\n"); | 280 | // printf("Get dates\n"); |
280 | 281 | ||
281 | Config config( "qpe" ); | 282 | Config config( "qpe" ); |
282 | // if 24 h format | 283 | // if 24 h format |
283 | //bool ampm = config.readBoolEntry( "AMPM", TRUE ); | 284 | //bool ampm = config.readBoolEntry( "AMPM", TRUE ); |
284 | 285 | ||
285 | int count=0; | 286 | int count=0; |
286 | 287 | ||
287 | if ( list.count() > 0 ) { | 288 | if ( list.count() > 0 ) { |
288 | 289 | ||
289 | for ( QValueList<EffectiveEvent>::ConstIterator it=list.begin(); | 290 | for ( QValueList<EffectiveEvent>::ConstIterator it=list.begin(); |
290 | it!=list.end(); ++it ) { | 291 | it!=list.end(); ++it ) { |
291 | 292 | ||
292 | 293 | ||
293 | if ( count <= MAX_LINES_MEET ) { | 294 | if ( count <= MAX_LINES_MEET ) { |
294 | 295 | ||
295 | QTime time = QTime::currentTime(); | 296 | QTime time = QTime::currentTime(); |
296 | 297 | ||
297 | if (!ONLY_LATER) { | 298 | if (!ONLY_LATER) { |
298 | count++; | 299 | count++; |
299 | DateBookEvent *l=new DateBookEvent(*it, AllDateBookEvents, SHOW_LOCATION, SHOW_NOTES); | 300 | DateBookEvent *l=new DateBookEvent(*it, AllDateBookEvents, SHOW_LOCATION, SHOW_NOTES); |
300 | layoutDates->addWidget(l); | 301 | layoutDates->addWidget(l); |
301 | connect (l, SIGNAL(editEvent(const Event &)), | 302 | connect (l, SIGNAL(editEvent(const Event &)), |
302 | this, SLOT(editEvent(const Event &))); | 303 | this, SLOT(editEvent(const Event &))); |
303 | } else if ((time.toString() <= TimeString::dateString((*it).event().end())) ) { | 304 | } else if ((time.toString() <= TimeString::dateString((*it).event().end())) ) { |
304 | count++; | 305 | count++; |
305 | 306 | ||
306 | // show only later appointments | 307 | // show only later appointments |
307 | DateBookEventLater *l=new DateBookEventLater(*it, AllDateBookEvents, SHOW_LOCATION, SHOW_NOTES); | 308 | DateBookEventLater *l=new DateBookEventLater(*it, AllDateBookEvents, SHOW_LOCATION, SHOW_NOTES); |
308 | layoutDates->addWidget(l); | 309 | layoutDates->addWidget(l); |
309 | connect (l, SIGNAL(editEvent(const Event &)), | 310 | connect (l, SIGNAL(editEvent(const Event &)), |
310 | this, SLOT(editEvent(const Event &))); | 311 | this, SLOT(editEvent(const Event &))); |
311 | } | 312 | } |
312 | } | 313 | } |
313 | } | 314 | } |
314 | if (ONLY_LATER && count==0) { | 315 | if (ONLY_LATER && count==0) { |
315 | QLabel* noMoreEvents = new QLabel(AllDateBookEvents); | 316 | QLabel* noMoreEvents = new QLabel(AllDateBookEvents); |
316 | noMoreEvents->setText("No more appointments today"); | 317 | noMoreEvents->setText("No more appointments today"); |
317 | layoutDates->addWidget(noMoreEvents); | 318 | layoutDates->addWidget(noMoreEvents); |
318 | } | 319 | } |
319 | } else { | 320 | } else { |