00001
00002
00003
00004
00005 #include "simple.h"
00006
00007
00008
00009 #include <opie2/odebug.h>
00010 #include <opie2/oapplicationfactory.h>
00011 #include <opie2/oresource.h>
00012 #include <opie2/otabwidget.h>
00013 #include <opie2/owait.h>
00014 #include <qpe/qpeapplication.h>
00015 #include <qpe/sound.h>
00016 #include <qpe/qcopenvelope_qws.h>
00017 #include <qpe/datebookmonth.h>
00018 #include <qpe/timestring.h>
00019 using namespace Opie::Core;
00020
00021
00022 #include <qaction.h>
00023 #include <qmenubar.h>
00024 #include <qtoolbar.h>
00025 #include <qlabel.h>
00026 #include <qpushbutton.h>
00027 #include <qlayout.h>
00028 #include <qtimer.h>
00029 #include <qdatetime.h>
00030 #include <qtextview.h>
00031 #include <qdialog.h>
00032 #include <qwhatsthis.h>
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049 OPIE_EXPORT_APP( OApplicationFactory<MainWindow> )
00050
00051 MainWindow::MainWindow(QWidget *parent, const char* name, WFlags fl )
00052 : QMainWindow( parent, name, fl ) {
00053 setCaption(tr("My MainWindow") );
00054
00055 m_desktopChannel = 0;
00056 m_loading = 0;
00057
00058 initUI();
00059
00060
00061
00062
00063
00064 m_tab = new Opie::Ui::OTabWidget(this);
00065
00066 setCentralWidget( m_tab );
00067
00068 m_todoView = new PIMListView(m_tab, "Todo view" );
00069 m_tab->addTab( m_todoView,"todo/TodoList", tr("Todos") );
00070
00071 m_dateView = new PIMListView(m_tab, "Datebook view" );
00072 m_tab->addTab( m_dateView, "datebook/DateBook", tr("Events") );
00073
00074
00075
00076
00077
00078
00079
00080 connect(m_fire, SIGNAL(activated() ),
00081 this, SLOT(slotShow() ) );
00082
00083
00084
00085
00086 connect(m_dateAction, SIGNAL(activated() ),
00087 this, SLOT(slotDate() ) );
00088
00089
00090
00091
00092
00093 connect(m_todoView, SIGNAL(showRecord(const Opie::OPimRecord&) ),
00094 this, SLOT(slotShowRecord(const Opie::OPimRecord&) ) );
00095 connect(m_dateView, SIGNAL(showRecord(const Opie::OPimRecord&) ),
00096 this, SLOT(slotShowRecord(const Opie::OPimRecord&) ) );
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109 QTimer::singleShot( 10, this, SLOT(slotLoad() ) );
00110 }
00111
00112 MainWindow::~MainWindow() {
00113
00114 }
00115
00116
00117 void MainWindow::setDocument( const QString& ) {
00118 }
00119
00120
00121 void MainWindow::initUI() {
00122
00123 setToolBarsMovable( false );
00124
00125 QToolBar *menuBarHolder = new QToolBar( this );
00126
00127 menuBarHolder->setHorizontalStretchable( true );
00128 QMenuBar *mb = new QMenuBar( menuBarHolder );
00129 QToolBar *tb = new QToolBar( this );
00130
00131 QPopupMenu *fileMenu = new QPopupMenu( this );
00132
00133
00134 QAction *a = new QAction( tr("Quit"), Opie::Core::OResource::loadPixmap("quit_icon", Opie::Core::OResource::SmallIcon),
00135 QString::null, 0, this, "quit_action" );
00136
00137
00138
00139 connect(a, SIGNAL(activated() ),
00140 qApp, SLOT(quit() ) );
00141 a->addTo( fileMenu );
00142
00143 a = new QAction(tr("View Current"),
00144 Opie::Core::OResource::loadPixmap("zoom", Opie::Core::OResource::SmallIcon),
00145 QString::null, 0, this, "view current");
00146
00147 a->setWhatsThis(tr("Views the current record") );
00148
00149
00150
00151 a->addTo( fileMenu );
00152 a->addTo( tb );
00153 m_fire = a;
00154
00155 a = new QAction(tr("Choose Date"),
00156 Opie::Core::OResource::loadPixmap("day", Opie::Core::OResource::SmallIcon),
00157 QString::null, 0, this, "choose date" );
00158 a->addTo( fileMenu );
00159 a->addTo( tb );
00160 m_dateAction = a;
00161
00162 mb->insertItem(tr("File"), fileMenu );
00163
00164 }
00165
00166 void MainWindow::slotLoad() {
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183
00184
00185
00186
00187
00188
00189
00190 if (!QCopChannel::isRegistered("QPE/Application/todolist") &&
00191 !QCopChannel::isRegistered("QPE/Application/datebook") ) {
00192 m_db.load();
00193 m_tb.load();
00194 return slotLoadForDay( QDate::currentDate() );
00195 }
00196
00197
00198
00199
00200
00201
00202 m_desktopChannel = new QCopChannel("QPE/Desktop");
00203 connect(m_desktopChannel, SIGNAL(received(const QCString&,const QByteArray&) ),
00204 this, SLOT(slotDesktopReceive(const QCString&,const QByteArray&) ) );
00205
00206 m_synced = 0;
00207
00208
00209
00210
00211
00212
00213 if ( QCopChannel::isRegistered("QPE/Application/todolist") ) {
00214 QCopEnvelope env("QPE/Application/todolist", "flush()" );
00215
00216 }else
00217 m_synced++;
00218
00219 if ( QCopChannel::isRegistered("QPE/Application/datebook") ) {
00220 QCopEnvelope env("QPE/Application/datebook", "flush()" );
00221 }else
00222 m_synced++;
00223
00224
00225 m_loading = new Opie::Ui::OWait(this, "wait screen" );
00226 }
00227
00228 void MainWindow::slotDesktopReceive(const QCString& cmd, const QByteArray& data ) {
00229
00230
00231
00232 QDataStream stream(data, IO_ReadOnly );
00233
00234
00235
00236 if ( cmd == "flushDone(QString)" ) {
00237 QString appname;
00238 stream >> appname;
00239 if (appname == QString::fromLatin1("datebook") ||
00240 appname == QString::fromLatin1("todolist") )
00241 m_synced++;
00242 }
00243
00244
00245
00246
00247
00248
00249 if (m_synced >= 2 ) {
00250 delete m_loading;
00251 delete m_desktopChannel;
00252
00253 m_tb.load();
00254 m_db.load();
00255 {
00256
00257 QCopEnvelope("QPE/Application/todolist", "reload()");
00258 QCopEnvelope("QPE/Application/datebook", "reload()");
00259 }
00260 slotLoadForDay( QDate::currentDate() );
00261 }
00262
00263 }
00264
00265
00266 void MainWindow::slotLoadForDay(int y, int m, int d) {
00267
00268 slotLoadForDay( QDate(y, m, d ) );
00269 }
00270
00271 void MainWindow::slotLoadForDay(const QDate& date) {
00272
00273
00274
00275 m_todoView->set( m_tb.effectiveToDos(date, date ) );
00276 m_dateView->set( m_db.occurrences( date, date ) );
00277 }
00278
00279
00280 void MainWindow::slotShow() {
00281
00282 PIMListView *view = static_cast<PIMListView*>(m_tab->currentWidget() );
00283
00284
00285 view->showCurrentRecord();
00286
00287 }
00288
00289
00290 void MainWindow::slotShowRecord( const Opie::OPimRecord& rec) {
00291
00292 QDialog* dia = new QDialog(this,"dialog",TRUE );
00293 QVBoxLayout *box = new QVBoxLayout( dia );
00294 dia->setCaption( tr("View Record") );
00295
00296
00297 QTextView *view = new QTextView(dia );
00298 view->setText( rec.toRichText() );
00299 box->addWidget( view );
00300
00301
00302
00303
00304
00305 dia->showMaximized();
00306 QPEApplication::execDialog( dia );
00307 delete dia;
00308 }
00309
00310
00311 void MainWindow::slotDate() {
00312
00313
00314
00315
00316
00317 odebug << "slot Date" << oendl;
00318 QPopupMenu *menu = new QPopupMenu();
00319
00320 DateBookMonth *month = new DateBookMonth(menu, 0, true );
00321 connect(month, SIGNAL(dateClicked(int,int,int) ),
00322 this, SLOT(slotLoadForDay(int,int,int) ) );
00323
00324 menu->insertItem( month );
00325
00326 menu->exec( QCursor::pos() );
00327
00328
00329
00330
00331
00332
00333 delete menu;
00334 }
00335
00336
00337
00338
00339
00340 namespace {
00341
00342 const int RTTI = 5050;
00343
00344
00345
00346
00347
00348
00349
00350
00351
00352
00353 struct PIMListViewItem : public QListViewItem {
00354
00355
00356
00357
00358 PIMListViewItem( QListView*, Opie::OPimRecord* record );
00359 ~PIMListViewItem();
00360
00361
00362
00363 int rtti()const;
00364 Opie::OPimRecord* record()const;
00365
00366 private:
00367 Opie::OPimRecord* m_record;
00368 };
00369
00370 PIMListViewItem::PIMListViewItem( QListView *p, Opie::OPimRecord* rec )
00371 : QListViewItem(p), m_record( rec ) {
00372 }
00373
00374 PIMListViewItem::~PIMListViewItem() {
00375
00376 delete m_record;
00377 }
00378
00379 Opie::OPimRecord* PIMListViewItem::record()const {
00380 return m_record;
00381 }
00382
00383 }
00384
00385
00386 PIMListView::PIMListView( QWidget* widget, const char* name, WFlags fl )
00387 : QListView(widget, name, fl )
00388 {
00389 addColumn("Summary");
00390 }
00391
00392 PIMListView::~PIMListView() {
00393
00394 }
00395
00396 void PIMListView::set( Opie::OPimTodoAccess::List list ) {
00397
00398 clear();
00399
00400 Opie::OPimTodoAccess::List::Iterator it;
00401 for (it = list.begin(); it != list.end(); ++it ) {
00402
00403
00404
00405
00406 PIMListViewItem *i = new PIMListViewItem(this, new Opie::OPimTodo( *it ) );
00407 i->setText(0, (*it).summary() );
00408 }
00409 }
00410
00411 void PIMListView::set( const Opie::OPimOccurrence::List& lst ) {
00412
00413 clear();
00414
00415 Opie::OPimOccurrence::List::ConstIterator it;
00416 for ( it = lst.begin(); it != lst.end(); ++it ) {
00417 PIMListViewItem *i = new PIMListViewItem(this, new Opie::OPimEvent( (*it).toEvent() ) );
00418 i->setText( 0, PIMListView::makeString( (*it) ) );
00419 }
00420
00421 }
00422
00423 void PIMListView::showCurrentRecord() {
00424
00425 if (!currentItem() )
00426 return;
00427
00428
00429
00430
00431
00432
00433 PIMListViewItem *item = static_cast<PIMListViewItem*>( currentItem() );
00434
00435
00436 emit showRecord( (*item->record() ) );
00437 }
00438
00439 QString PIMListView::makeString( const Opie::OPimOccurrence& _ev ) {
00440 QString str;
00441 str += _ev.summary();
00442
00443 Opie::OPimEvent ev = _ev.toEvent();
00444 if ( !ev.isAllDay() ) {
00445 #if 0
00446 if ( ev.startDate() != ev.endDate() ) {
00447 str += tr("Start ") + TimeString::timeString( ev.startDateTime().time() );
00448 str += " - " + TimeString::longDateString( ev.startDateTime().date() );
00449 str += tr("End ") + TimeString::timeString( ev.endDateTime().time() );
00450 str += " - " + TimeString::longDateString( ev.endDateTime().date() );
00451 }else
00452 #endif
00453 {
00454 str += tr("Time ") + TimeString::timeString( _ev.startTime() );
00455 str += " - " + TimeString::timeString( _ev.endTime() );
00456 }
00457 }else
00458 str += tr(" This is an All-Day Event");
00459
00460 return str;
00461 }