summaryrefslogtreecommitdiff
path: root/core/pim/today/today.cpp
Unidiff
Diffstat (limited to 'core/pim/today/today.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--core/pim/today/today.cpp708
1 files changed, 188 insertions, 520 deletions
diff --git a/core/pim/today/today.cpp b/core/pim/today/today.cpp
index 62becb0..09540bd 100644
--- a/core/pim/today/today.cpp
+++ b/core/pim/today/today.cpp
@@ -1,637 +1,305 @@
1/* 1/*
2 * today.cpp : main class 2 * today.cpp
3 * 3 *
4 * ---------------------
5 *
6 * begin : Sun 10 17:20:00 CEST 2002
7 * copyright : (c) 2002 by Maximilian Reiß 4 * copyright : (c) 2002 by Maximilian Reiß
8 * email : max.reiss@gmx.de 5 * email : harlekin@handhelds.org
9 * 6 *
10 */ 7 */
11/*************************************************************************** 8/***************************************************************************
12 * * 9 * *
13 * This program is free software; you can redistribute it and/or modify * 10 * 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 * 11 * 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 * 12 * the Free Software Foundation; either version 2 of the License, or *
16 * (at your option) any later version. * 13 * (at your option) any later version. *
17 * * 14 * *
18 ***************************************************************************/ 15 ***************************************************************************/
19 16
17
20#include "today.h" 18#include "today.h"
19#include "configwidget.h"
21 20
22#include <qpe/timestring.h>
23#include <qpe/config.h> 21#include <qpe/config.h>
24#include <qpe/qcopenvelope_qws.h> 22#include <qpe/qcopenvelope_qws.h>
25#include <qpe/resource.h> 23#include <qpe/resource.h>
26#include <qpe/contact.h>
27#include <qpe/global.h> 24#include <qpe/global.h>
28#include <qpe/qpeapplication.h> 25#include <qpe/qpeapplication.h>
26#include <qpe/contact.h>
29 27
30#include <qdir.h> 28#include <qdir.h>
31#include <qfile.h> 29#include <qfile.h>
32#include <qdatetime.h>
33#include <qtextstream.h>
34#include <qcheckbox.h>
35#include <qspinbox.h>
36#include <qpushbutton.h> 30#include <qpushbutton.h>
37#include <qlabel.h> 31#include <qlabel.h>
38#include <qtimer.h> 32#include <qtimer.h>
39#include <qpixmap.h> 33#include <qpixmap.h>
40#include <qlayout.h> 34#include <qlayout.h>
41#include <qtl.h> 35#include <qtabwidget.h>
42 36#include <qdialog.h>
43 37
44#include <unistd.h>
45#include <stdlib.h>
46 38
47int MAX_LINES_TASK; 39static QValueList<TodayPlugin> pluginList;
48int MAX_CHAR_CLIP;
49int MAX_LINES_MEET;
50int SHOW_LOCATION;
51int SHOW_NOTES;
52// show only later dates
53int ONLY_LATER;
54int AUTOSTART;
55int NEW_START=1;
56QString AUTOSTART_TIMER;
57int NEXTDAYS=1;
58 40
59
60/* Constructs a Example which is a child of 'parent', with the
61 * name 'name' and widget flags set to 'f'
62 */
63Today::Today( QWidget* parent, const char* name, WFlags fl ) 41Today::Today( QWidget* parent, const char* name, WFlags fl )
64 : TodayBase( parent, name, fl ), AllDateBookEvents(NULL) { 42 : TodayBase( parent, name, fl ) {
65 QObject::connect( (QObject*)PushButton1, SIGNAL( clicked() ), this, SLOT(startConfig() ) ); 43
66 QObject::connect( (QObject*)TodoButton, SIGNAL( clicked() ), this, SLOT(startTodo() ) ); 44 QObject::connect( (QObject*)ConfigButton, SIGNAL( clicked() ), this, SLOT( startConfig() ) );
67 QObject::connect( (QObject*)DatesButton, SIGNAL( clicked() ), this, SLOT(startDatebook() ) ); 45 QObject::connect( (QObject*)OwnerField, SIGNAL( clicked() ), this, SLOT( editCard() ) );
68 QObject::connect( (QObject*)MailButton, SIGNAL( clicked() ), this, SLOT(startMail() ) );
69 QObject::connect( (QObject*)OwnerField, SIGNAL( clicked() ), this, SLOT(editCard() ) );
70 46
71#if defined(Q_WS_QWS) 47#if defined(Q_WS_QWS)
72#if !defined(QT_NO_COP) 48#if !defined(QT_NO_COP)
73 QCopChannel *todayChannel = new QCopChannel("QPE/Today" , this ); 49 QCopChannel *todayChannel = new QCopChannel( "QPE/Today" , this );
74 connect (todayChannel, SIGNAL( received(const QCString &, const QByteArray &)), 50 connect ( todayChannel, SIGNAL( received( const QCString &, const QByteArray &) ),
75 this, SLOT ( channelReceived(const QCString &, const QByteArray &)) ); 51 this, SLOT ( channelReceived( const QCString &, const QByteArray &) ) );
76#endif 52#endif
77#endif 53#endif
78 54
55 pluginLayout = 0l;
79 56
80 57 setOwnerField();
81 db = NULL; 58 init();
82 setOwnerField(); 59 refresh();
83 todo = new ToDoDB; 60 showMaximized();
84 draw();
85 getTodo();
86 autoStart();
87} 61}
88 62
89/* 63/**
90 * Qcop receive method. 64 * Qcop receive method.
91 */ 65 */
92void Today::channelReceived(const QCString &msg, const QByteArray & data) { 66void Today::channelReceived( const QCString &msg, const QByteArray & data ) {
93 QDataStream stream(data, IO_ReadOnly ); 67 QDataStream stream( data, IO_ReadOnly );
94 if ( msg == "message(QString)" ) { 68 if ( msg == "message(QString)" ) {
95 QString message; 69 QString message;
96 stream >> message; 70 stream >> message;
97 setOwnerField(message); 71 setOwnerField( message );
98 } 72 }
99
100} 73}
101 74
102/* 75/**
103 * Initialises the owner field with the default value, the username 76 * Initialises the owner field with the default value, the username
104 */ 77 */
105void Today::setOwnerField() { 78void Today::setOwnerField() {
106 QString file = Global::applicationFileName("addressbook", "businesscard.vcf"); 79 QString file = Global::applicationFileName( "addressbook", "businesscard.vcf" );
107 if (QFile::exists(file)) { 80 if ( QFile::exists( file ) ) {
108 Contact cont = Contact::readVCard(file)[0]; 81 Contact cont = Contact::readVCard( file )[0];
109 QString returnString = cont.fullName(); 82 QString returnString = cont.fullName();
110 OwnerField->setText( "<b>" +tr ("Owned by ") + returnString + "</b>"); 83 OwnerField->setText( "<b>" + tr ( "Owned by " ) + returnString + "</b>" );
111 } else { 84 } else {
112 OwnerField->setText( "<b>" + tr ("Please fill out the business card")+" </b>"); 85 OwnerField->setText( "<b>" + tr ( "Please fill out the business card" ) + " </b>" );
113 } 86 }
114} 87}
115 88
116/* 89/**
117 * Set the owner field with a given QString, for example per qcop. 90 * Set the owner field with a given QString, for example per qcop.
118 */ 91 */
119void Today::setOwnerField(QString &message) { 92void Today::setOwnerField( QString &message ) {
120 if (!message.isEmpty()) { 93 if ( !message.isEmpty() ) {
121 OwnerField->setText("<b>" + message + "</b>"); 94 OwnerField->setText( "<b>" + message + "</b>" );
122 }
123}
124
125/*
126 * Autostart, uses the new (opie only) autostart method in the launcher code.
127 * If registered against that today ist started on each resume.
128 */
129void Today::autoStart() {
130 Config cfg("today");
131 cfg.setGroup("Autostart");
132 int AUTOSTART = cfg.readNumEntry("autostart",1);
133// qDebug(QString("%1").arg(AUTOSTART));
134 if (AUTOSTART) {
135 QCopEnvelope e("QPE/System", "autoStart(QString,QString,QString)");
136 e << QString("add");
137 e << QString("today");
138 e << AUTOSTART_TIMER;
139 } else {
140 qDebug("Nun in else bei autostart");
141 QCopEnvelope e("QPE/System", "autoStart(QString,QString)");
142 e << QString("remove");
143 e << QString("today");
144 } 95 }
145} 96}
146 97
147/*
148 * Repaint method. Reread all fields.
149 */
150void Today::draw() {
151 init();
152 getDates();
153 getMail();
154
155 // if the todolist.xml file was not modified in between, do not parse it.
156 if (checkIfModified() || NEW_START==1) {
157 if (todo) delete todo;
158 todo = new ToDoDB;
159 getTodo();
160 }
161
162 // how often refresh
163 QTimer::singleShot( 20*1000, this, SLOT(draw() ) );
164}
165 98
166/* 99/**
167 * Check if the todolist.xml was modified (if there are new entries. 100 * Init stuff needed for today. Reads the config file.
168 * Returns true if it was modified.
169 */ 101 */
170bool Today::checkIfModified() { 102void Today::init() {
171 103
172 QDir dir; 104 QDate date = QDate::currentDate();
173 QString homedir = dir.homeDirPath (); 105 QString time = ( tr( date.toString() ) );
174 QString time;
175 106
176 Config cfg("today"); 107 DateLabel->setText( QString( "<font color=#FFFFFF>" + time + "</font>" ) );
177 cfg.setGroup("Files");
178 time = cfg.readEntry("todolisttimestamp", "");
179 108
180 QFileInfo file = (homedir +"/Applications/todolist/todolist.xml"); 109 // read config
181 QDateTime fileTime = file.lastModified(); 110 Config cfg( "today" );
182 if (time.compare(fileTime.toString()) == 0) { 111
183 return false; 112 cfg.setGroup( "Applets" );
184 } else { 113 m_excludeApplets = cfg.readListEntry( "ExcludeApplets", ',' );
185 cfg.writeEntry("todolisttimestamp", fileTime.toString() );
186 cfg.write();
187 return true;
188 }
189} 114}
190 115
191 116
192/* 117/**
193 * Init stuff needed for today. Reads the config file. 118 * Load the plugins
194 */ 119 */
195void Today::init() { 120void Today::loadPlugins() {
196 QDate date = QDate::currentDate();
197 QString time = (tr( date.toString()) );
198
199 TextLabel1->setText(QString("<font color=#FFFFFF>" + time + "</font>"));
200
201 // read config
202 Config cfg("today");
203 cfg.setGroup("BaseConfig");
204
205 // -- config file section --
206 // how many lines should be showed in the task section
207 MAX_LINES_TASK = cfg.readNumEntry("maxlinestask",5);
208 // after how many chars should the be cut off on tasks and notes
209 MAX_CHAR_CLIP = cfg.readNumEntry("maxcharclip",40);
210 // how many lines should be showed in the datebook section
211 MAX_LINES_MEET = cfg.readNumEntry("maxlinesmeet",5);
212 // If location is to be showed too, 1 to activate it.
213 SHOW_LOCATION = cfg.readNumEntry("showlocation",1);
214 // if notes should be shown
215 SHOW_NOTES = cfg.readNumEntry("shownotes",0);
216 // should only later appointments be shown or all for the current day.
217 ONLY_LATER = cfg.readNumEntry("onlylater",1);
218
219 cfg.setGroup("Autostart");
220 AUTOSTART = cfg.readNumEntry("autostart",1);
221 AUTOSTART_TIMER = cfg.readEntry("autostartdelay", "0");
222
223 //db = new DateBookDB;
224}
225 121
226/* 122 QValueList<TodayPlugin>::Iterator tit;
227 * The method for the configuration dialog. 123 for ( tit = pluginList.begin(); tit != pluginList.end(); ++tit ) {
228 */ 124 (*tit).library->unload();
229void Today::startConfig() { 125 delete (*tit).library;
126 }
230 127
231 conf = new todayconfig ( this, "", true ); 128 QString path = QPEApplication::qpeDir() + "/plugins/today";
232 // read the config 129 QDir dir( path, "lib*.so" );
233 Config cfg("today"); 130
234 cfg.setGroup("BaseConfig"); 131 QStringList list = dir.entryList();
235 132 QStringList::Iterator it;
236 //init(); 133
237 134 uint count = 0;
238 conf->SpinBox1->setValue(MAX_LINES_MEET); 135 for ( it = list.begin(); it != list.end(); ++it ) {
239 // location show box 136 TodayPluginInterface *iface = 0;
240 conf->CheckBox1->setChecked(SHOW_LOCATION); 137 QLibrary *lib = new QLibrary( path + "/" + *it );
241 // notes show box 138
242 conf->CheckBox2->setChecked(SHOW_NOTES); 139 qDebug( "querying: %s", QString( path + "/" + *it ).latin1() );
243 // task lines 140 if ( lib->queryInterface( IID_TodayPluginInterface, (QUnknownInterface**)&iface ) == QS_OK ) {
244 conf->SpinBox2->setValue(MAX_LINES_TASK); 141 qDebug( "loading: %s", QString( path + "/" + *it ).latin1() );
245 // clip when? 142 qDebug( QString(*it).latin1() );
246 conf->SpinBox7->setValue(MAX_CHAR_CLIP); 143 TodayPlugin plugin;
247 // only later 144 plugin.library = lib;
248 conf->CheckBox3->setChecked(ONLY_LATER); 145 plugin.iface = iface;
249 // if today should be autostarted 146 plugin.name = QString(*it).latin1();
250 conf->CheckBoxAuto->setChecked(AUTOSTART); 147
251 // autostart only if device has been suspended for X minutes 148 if ( m_excludeApplets.grep( *it ).isEmpty() ) {
252 conf->SpinBoxTime->setValue( AUTOSTART_TIMER.toInt() ); 149 plugin.active = true;
253 150 } else {
254 conf->exec(); 151 plugin.active = false;
255 152 }
256 int maxlinestask = conf->SpinBox2->value(); 153 plugin.guiPart = plugin.iface->guiPart();
257 int maxmeet = conf->SpinBox1->value(); 154 pluginList.append( plugin );
258 int location = conf->CheckBox1->isChecked(); 155 count++;
259 int notes = conf->CheckBox2->isChecked(); 156 } else {
260 int maxcharclip = conf->SpinBox7->value(); 157 qDebug( "could not recognize %s", QString( path + "/" + *it ).latin1() );
261 int onlylater = conf->CheckBox3->isChecked(); 158 delete lib;
262 int autostart = conf->CheckBoxAuto->isChecked(); 159 }
263 int autostartdelay = conf->SpinBoxTime->value(); 160 }
264
265
266 cfg.writeEntry("maxlinestask",maxlinestask);
267 cfg.writeEntry("maxcharclip", maxcharclip);
268 cfg.writeEntry("maxlinesmeet",maxmeet);
269 cfg.writeEntry("showlocation",location);
270 cfg.writeEntry("shownotes", notes);
271 cfg.writeEntry("onlylater", onlylater);
272 cfg.setGroup("Autostart");
273 cfg.writeEntry("autostart", autostart);
274 cfg.writeEntry("autostartdelay", autostartdelay);
275
276 // sync it to "disk"
277 cfg.write();
278 NEW_START=1;
279 draw();
280 AUTOSTART=autostart;
281 autoStart();
282} 161}
283 162
284 163
285/* 164/**
286 * Get all events that are in the datebook xml file for today 165 * Repaint method. Reread all fields.
287 */ 166 */
288void Today::getDates() { 167void Today::draw() {
289 QDate date = QDate::currentDate();
290
291 if (AllDateBookEvents) delete AllDateBookEvents;
292 AllDateBookEvents = new QWidget( );
293 QVBoxLayout* layoutDates = new QVBoxLayout(AllDateBookEvents);
294
295 if (db) {
296 delete db;
297 }
298 db = new DateBookDB;
299
300 QValueList<EffectiveEvent> list = db->getEffectiveEvents(date, date);
301
302 qBubbleSort(list);
303 // printf("Get dates\n");
304
305 Config config( "qpe" );
306 // if 24 h format
307 //bool ampm = config.readBoolEntry( "AMPM", TRUE );
308
309 int count=0;
310
311 if ( list.count() > 0 ) {
312
313 for ( QValueList<EffectiveEvent>::ConstIterator it=list.begin();
314 it!=list.end(); ++it ) {
315
316
317 if ( count <= MAX_LINES_MEET ) {
318 168
319 QTime time = QTime::currentTime(); 169 if ( pluginLayout ) {
170 delete pluginLayout;
171 }
172 pluginLayout = new QVBoxLayout( layout );
320 173
321 if (!ONLY_LATER) { 174 if ( pluginList.count() == 0 ) {
322 count++; 175 QLabel *noPlugins = new QLabel( this );
323 DateBookEvent *l=new DateBookEvent(*it, AllDateBookEvents, SHOW_LOCATION, SHOW_NOTES); 176 noPlugins->setText( tr( "No plugins found" ) );
324 layoutDates->addWidget(l); 177 layout->addWidget( noPlugins );
325 connect (l, SIGNAL(editEvent(const Event &)), 178 return;
326 this, SLOT(editEvent(const Event &))); 179 }
327 } else if ((time.toString() <= TimeString::dateString((*it).event().end())) ) {
328 count++;
329 180
330 // show only later appointments 181 uint count = 0;
331 DateBookEventLater *l=new DateBookEventLater(*it, AllDateBookEvents, SHOW_LOCATION, SHOW_NOTES); 182 TodayPlugin plugin;
332 layoutDates->addWidget(l); 183 for ( uint i = 0; i < pluginList.count(); i++ ) {
333 connect (l, SIGNAL(editEvent(const Event &)), 184 plugin = pluginList[i];
334 this, SLOT(editEvent(const Event &))); 185
186 if ( plugin.active ) {
187 QHBoxLayout* plugLayout = new QHBoxLayout( this );
188 QPixmap plugPix;
189 plugPix.convertFromImage( Resource::loadImage( plugin.guiPart->pixmapNameWidget() ).smoothScale( 18, 18 ), 0 );
190 OClickableLabel* plugIcon = new OClickableLabel( this );
191 plugIcon->setPixmap( plugPix );
192 QScrollView* sv = new QScrollView( this );
193 QWidget* plugWidget = plugin.guiPart->widget( sv->viewport() );
194 // plugWidget->reparent( sv->viewport(), QPoint( 0, 0 ) );
195 sv->setMinimumHeight( plugin.guiPart->minHeight() );
196 //sv->setMaximumHeight( plugin.guiPart->maxHeight() );
197
198 sv->setResizePolicy( QScrollView::AutoOneFit );
199 sv->setHScrollBarMode( QScrollView::AlwaysOff );
200 sv->setFrameShape( QFrame::NoFrame );
201 sv->addChild( plugWidget );
202
203 plugLayout->addWidget( plugIcon, 0, AlignTop );
204 plugLayout->addWidget( sv, 0, AlignTop );
205 plugLayout->setStretchFactor( plugIcon, 1 );
206 plugLayout->setStretchFactor( sv, 9 );
207 pluginLayout->addLayout( plugLayout );
208 count++;
335 } 209 }
336 }
337 } 210 }
338 if (ONLY_LATER && count==0) {
339 QLabel* noMoreEvents = new QLabel(AllDateBookEvents);
340 noMoreEvents->setText(tr("No more appointments today"));
341 layoutDates->addWidget(noMoreEvents);
342 }
343 } else {
344 QLabel* noEvents = new QLabel(AllDateBookEvents);
345 noEvents->setText(tr("No appointments today"));
346 layoutDates->addWidget(noEvents);
347 }
348 211
349 layoutDates->addItem(new QSpacerItem(1,1, QSizePolicy::Minimum, QSizePolicy::Expanding)); 212 if ( count == 0 ) {
350 sv1->addChild(AllDateBookEvents); 213 QLabel *noPluginsActive = new QLabel( this );
351 AllDateBookEvents->show(); 214 noPluginsActive->setText( tr( "No plugins activated" ) );
352} 215 layout->addWidget( noPluginsActive );
216 }
353 217
218 layout->addItem( new QSpacerItem( 1,1, QSizePolicy::Minimum, QSizePolicy::Expanding ) );
354 219
355void Today::getMail() {
356 Config cfg("opiemail");
357 cfg.setGroup("today");
358 220
359 // how many lines should be showed in the task section 221 // how often refresh - later have qcop update calls in *db
360 int NEW_MAILS = cfg.readNumEntry("newmails",0); 222 // QTimer::singleShot( 20*1000, this, SLOT( draw() ) );
361 int OUTGOING = cfg.readNumEntry("outgoing",0); 223}
362 224
363 QString output = tr("<b>%1</b> new mail(s), <b>%2</b> outgoing").arg(NEW_MAILS).arg(OUTGOING);
364 225
365 MailField->setText(output); 226void Today::refresh() {
227 loadPlugins();
228 draw();
229 qDebug( "redraw" );
230// QTimer::singleShot( 30*1000, this, SLOT( refresh() ) );
366} 231}
367 232
368 233
369/* 234/**
370 * Get the todos 235 * The method for the configuration dialog.
371 */ 236 */
372void Today::getTodo() { 237void Today::startConfig() {
373 238 conf = new TodayConfig ( this, "", true );
374 QString output; 239
375 QString tmpout; 240 uint count = 0;
376 int count = 0; 241 TodayPlugin plugin;
377 int ammount = 0; 242
378 243 QList<ConfigWidget> configWidgetList;
379 // get overdue todos first 244 for ( uint i = 0; i < pluginList.count(); i++ ) {
380 QValueList<ToDoEvent> overDueList = todo->overDue(); 245 plugin = pluginList[i];
381 qBubbleSort(overDueList);
382 for ( QValueList<ToDoEvent>::Iterator it=overDueList.begin();
383 it!=overDueList.end(); ++it ) {
384 if (!(*it).isCompleted() && ( ammount < MAX_LINES_TASK) ) {
385 QString desc = (*it).summary();
386 if( desc.isEmpty() ) {
387 desc = (*it).description();
388 }
389 tmpout += "<font color=#e00000><b>-" + desc.mid(0, MAX_CHAR_CLIP) + "</b></font><br>";
390
391 ammount++;
392 }
393 }
394 246
395 // get total number of still open todos 247 // load the config widgets in the tabs
396 QValueList<ToDoEvent> openTodo = todo->rawToDos(); 248 if ( plugin.guiPart->configWidget( this ) != 0l ) {
397 qBubbleSort(openTodo); 249 ConfigWidget* widget = plugin.guiPart->configWidget( this );
398 for ( QValueList<ToDoEvent>::Iterator it=openTodo.begin(); 250 widget->reparent( conf , QPoint( 0,0 ) );
399 it!=openTodo.end(); ++it ) { 251 configWidgetList.append( widget );
400 if (!(*it).isCompleted()){ 252 conf->TabWidget3->insertTab( widget, plugin.guiPart->appName() );
401 count +=1;
402 // not the overdues, we allready got them, and not if we are
403 // over the maxlines
404 if (!(*it).isOverdue() && ( ammount < MAX_LINES_TASK) ) {
405 QString desc = (*it).summary();
406 if( desc.isEmpty() ) {
407 desc = (*it).description();
408 }
409 tmpout += "<b>-</b>" + desc.mid(0, MAX_CHAR_CLIP) + "<br>";
410 ammount++;
411 }
412 } 253 }
254 // set the order/activate tab
255 conf->pluginManagement( plugin.name, plugin.guiPart->pluginName(),
256 Resource::loadPixmap( plugin.guiPart->pixmapNameWidget() ) );
257 count++;
413 } 258 }
414 259
260 conf->showMaximized();
415 261
416 if (count > 0) { 262 if ( conf->exec() == QDialog::Accepted ) {
417 if( count == 1 ) { 263 ConfigWidget *confWidget;
418 output = tr("There is <b> 1</b> active task: <br>" ); 264 for ( confWidget=configWidgetList.first(); confWidget != 0;
419 } else { 265 confWidget = configWidgetList.next() ) {
420 output = tr("There are <b> %1</b> active tasks: <br>").arg(count); 266 confWidget->writeConfig();
421 } 267 }
422 output += tmpout; 268 conf->writeConfig();
423 } else {
424 output = tr("No active tasks");
425 }
426 269
427 TodoField->setText(tr(output)); 270 init();
271 loadPlugins();
272 draw();
273 }
274 delete conf;
428} 275}
429 276
430 277
431void Today::startAddressbook() { 278void Today::startAddressbook() {
432 QCopEnvelope e("QPE/System", "execute(QString)"); 279 QCopEnvelope e( "QPE/System", "execute(QString)" );
433 e << QString("addressbook"); 280 e << QString( "addressbook" );
434} 281}
435 282
436extern QPEApplication *todayApp;
437 283
438/* 284/**
439 * launch addressbook (personal card) 285 * launch addressbook (personal card)
440 */ 286 */
441void Today::editCard() { 287void Today::editCard() {
442
443 startAddressbook(); 288 startAddressbook();
444 289 while( !QCopChannel::isRegistered( "QPE/Addressbook" ) ) {
445 while( !QCopChannel::isRegistered("QPE/Addressbook")) todayApp->processEvents(); 290 qApp->processEvents();
446 QCopEnvelope v("QPE/Addressbook", "editPersonalAndClose()"); 291 }
447} 292 QCopEnvelope v( "QPE/Addressbook", "editPersonalAndClose()" );
448
449/*
450 * launches datebook
451 */
452void Today::startDatebook() {
453 QCopEnvelope e("QPE/System", "execute(QString)");
454 e << QString("datebook");
455}
456
457/*
458 * starts the edit dialog as known from datebook
459 */
460void Today::editEvent(const Event &e) {
461 startDatebook();
462
463 while(!QCopChannel::isRegistered("QPE/Datebook")) todayApp->processEvents();
464 QCopEnvelope env("QPE/Datebook", "editEvent(int)");
465 env << e.uid();
466}
467
468/*
469 * launches todolist
470 */
471void Today::startTodo() {
472 QCopEnvelope e("QPE/System", "execute(QString)");
473 e << QString("todolist");
474} 293}
475 294
476/* 295/*
477 * launch opiemail 296 * launches an App
478 */ 297 */
479void Today::startMail() { 298void Today::launchApp( QString appName ) {
480 QCopEnvelope e("QPE/System", "execute(QString)"); 299 QCopEnvelope e( "QPE/System", "execute(QString)" );
481 e << QString("opiemail"); 300 e << QString( appName );
482//Right now start both, maybe decide which to rum via config file ..
483 QCopEnvelope f("QPE/System", "execute(QString)");
484 f << QString("qtmail");
485} 301}
486 302
487
488Today::~Today() { 303Today::~Today() {
489} 304}
490 305
491/*
492 * Gets the events for the current day, if it should get all dates
493 */
494DateBookEvent::DateBookEvent(const EffectiveEvent &ev,
495 QWidget* parent,
496 int SHOW_LOCATION,
497 int SHOW_NOTES,
498 const char* name,
499 WFlags fl) :
500 OClickableLabel(parent,name,fl), event(ev) {
501
502 QString msg;
503 //QTime time = QTime::currentTime();
504
505 Config config( "qpe" );
506 config.setGroup( "Time" );
507 // if 24 h format
508 ampm = config.readBoolEntry( "AMPM", TRUE );
509
510
511 if (!ONLY_LATER) {
512 msg += "<B>" + (ev).description() + "</B>";
513 if ( (ev).event().hasAlarm() ) {
514 msg += " <b>[with alarm]</b>";
515 }
516 // include location or not
517 if (SHOW_LOCATION == 1) {
518 msg += "<BR><i>" + (ev).location() + "</i>";
519 }
520
521 if ( (TimeString::timeString(QTime((ev).event().start().time()) ) == "00:00") && (TimeString::timeString(QTime((ev).event().end().time()) ) == "23:59") ) {
522 msg += "<br>All day";
523 } else {
524 // start time of event
525 msg += "<br>" + ampmTime(QTime((ev).event().start().time()) )
526 // end time of event
527 + "<b> - </b>" + ampmTime(QTime((ev).event().end().time()) );
528 }
529
530 // include possible note or not
531 if (SHOW_NOTES == 1) {
532 msg += "<br> <i>note</i>:" +((ev).notes()).mid(0, MAX_CHAR_CLIP);
533 }
534 }
535 setText(msg);
536 connect(this, SIGNAL(clicked()), this, SLOT(editMe()));
537 setAlignment( int( QLabel::WordBreak | QLabel::AlignLeft ) );
538}
539
540
541QString DateBookEvent::ampmTime(QTime tm) {
542
543 QString s;
544 if( ampm ) {
545 int hour = tm.hour();
546 if (hour == 0)
547 hour = 12;
548 if (hour > 12)
549 hour -= 12;
550 s.sprintf( "%2d:%02d %s", hour, tm.minute(),
551 (tm.hour() >= 12) ? "PM" : "AM" );
552 return s;
553 } else {
554 s.sprintf( "%2d:%02d", tm.hour(), tm.minute() );
555 return s;
556 }
557
558}
559
560
561DateBookEventLater::DateBookEventLater(const EffectiveEvent &ev,
562 QWidget* parent,
563 int SHOW_LOCATION,
564 int SHOW_NOTES,
565 const char* name,
566 WFlags fl) :
567 OClickableLabel(parent,name,fl), event(ev) {
568
569 QString msg;
570 QTime time = QTime::currentTime();
571
572 Config config( "qpe" );
573 config.setGroup( "Time" );
574 // if 24 h format
575 ampm = config.readBoolEntry( "AMPM", TRUE );
576
577
578 if ((time.toString() <= TimeString::dateString((ev).event().end())) ) {
579 // show only later appointments
580 msg += "<B>" + (ev).description() + "</B>";
581 if ( (ev).event().hasAlarm() ) {
582 msg += " <b>[with alarm]</b>";
583 }
584 // include location or not
585 if (SHOW_LOCATION == 1) {
586 msg += "<BR><i>" + (ev).location() + "</i>";
587 }
588
589 if ( (TimeString::timeString(QTime((ev).event().start().time()) ) == "00:00") && (TimeString::timeString(QTime((ev).event().end().time()) ) == "23:59") ) {
590 msg += "<br>All day";
591 } else {
592 // start time of event
593 msg += "<br>" + ampmTime(QTime((ev).event().start().time()) )
594 // end time of event
595 + "<b> - </b>" + ampmTime(QTime((ev).event().end().time()) );
596 }
597 // include possible note or not
598 if (SHOW_NOTES == 1) {
599 msg += "<br> <i>note</i>:" +((ev).notes()).mid(0, MAX_CHAR_CLIP);
600 }
601 }
602
603 setText(msg);
604 connect(this, SIGNAL(clicked()), this, SLOT(editMe()));
605 setAlignment( int( QLabel::WordBreak | QLabel::AlignLeft ) );
606}
607
608
609QString DateBookEventLater::ampmTime(QTime tm) {
610
611 QString s;
612 if( ampm ) {
613 int hour = tm.hour();
614 if (hour == 0)
615 hour = 12;
616 if (hour > 12)
617 hour -= 12;
618 s.sprintf( "%2d:%02d %s", hour, tm.minute(),
619 (tm.hour() >= 12) ? "PM" : "AM" );
620 return s;
621 } else {
622 s.sprintf( "%2d:%02d", tm.hour(), tm.minute() );
623 return s;
624 }
625
626}
627
628
629void DateBookEvent::editMe() {
630 emit editEvent(event.event());
631}
632
633void DateBookEventLater::editMe() {
634 emit editEvent(event.event());
635}
636
637