summaryrefslogtreecommitdiff
path: root/core/pim/todo/mainwindow.cpp
Unidiff
Diffstat (limited to 'core/pim/todo/mainwindow.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--core/pim/todo/mainwindow.cpp213
1 files changed, 156 insertions, 57 deletions
diff --git a/core/pim/todo/mainwindow.cpp b/core/pim/todo/mainwindow.cpp
index 9b2423b..b2b3b8f 100644
--- a/core/pim/todo/mainwindow.cpp
+++ b/core/pim/todo/mainwindow.cpp
@@ -23,64 +23,67 @@
23 If not, write to the Free Software Foundation, 23 If not, write to the Free Software Foundation,
24 Inc., 59 Temple Place - Suite 330, 24 Inc., 59 Temple Place - Suite 330,
25 Boston, MA 02111-1307, USA. 25 Boston, MA 02111-1307, USA.
26 26
27*/ 27*/
28 28
29#include <unistd.h> 29#include <unistd.h>
30 30
31#include <qmenubar.h> 31#include <qmenubar.h>
32#include <qmessagebox.h> 32#include <qmessagebox.h>
33#include <qtoolbar.h> 33#include <qtoolbar.h>
34#include <qpopupmenu.h> 34#include <qpopupmenu.h>
35#include <qwidgetstack.h> 35#include <qwidgetstack.h>
36#include <qaction.h> 36#include <qaction.h>
37#include <qtimer.h> 37#include <qtimer.h>
38#include <qvbox.h> 38#include <qvbox.h>
39#include <qlineedit.h> 39#include <qlineedit.h>
40 40
41#include <qpe/applnk.h> 41#include <qpe/applnk.h>
42#include <qpe/config.h> 42#include <qpe/config.h>
43#include <qpe/ir.h> 43#include <qpe/ir.h>
44#include <qpe/resource.h> 44#include <qpe/resource.h>
45#include <qpe/qpemessagebox.h> 45#include <qpe/qpemessagebox.h>
46 46
47#include <opie/orecur.h>
47#include <opie/otodoaccessvcal.h> 48#include <opie/otodoaccessvcal.h>
48 49
49#include "quickeditimpl.h" 50#include "quickeditimpl.h"
50#include "todotemplatemanager.h" 51#include "todotemplatemanager.h"
51#include "templateeditor.h" 52#include "templateeditor.h"
52#include "tableview.h" 53#include "tableview.h"
53 54
54#include "textviewshow.h" 55#include "textviewshow.h"
55#include "todoeditor.h" 56#include "todoeditor.h"
56#include "mainwindow.h" 57#include "mainwindow.h"
57 58
58 59
59using namespace Todo; 60using namespace Todo;
60 61
61MainWindow::MainWindow( QWidget* parent, 62MainWindow::MainWindow( QWidget* parent,
62 const char* name ) { 63 const char* name )
64 : OPimMainWindow("Todolist")
65{
63 66
64 m_syncing = false; 67 m_syncing = false;
65 m_counter = 0; 68 m_counter = 0;
66 m_tempManager = new TemplateManager(); 69 m_tempManager = new TemplateManager();
67 m_tempManager->load(); 70 m_tempManager->load();
68 71
69 initUI(); 72 initUI();
70 initConfig(); 73 initConfig();
71 initViews(); 74 initViews();
72 initActions(); 75 initActions();
73 initEditor(); 76 initEditor();
74 initShow(); 77 initShow();
75 initTemplate(); 78 initTemplate();
76 79
77 populateTemplates(); 80 populateTemplates();
78 raiseCurrentView(); 81 raiseCurrentView();
79 QTimer::singleShot(0, this, SLOT(populateCategories() ) ); 82 QTimer::singleShot(0, this, SLOT(populateCategories() ) );
80} 83}
81void MainWindow::initTemplate() { 84void MainWindow::initTemplate() {
82 m_curTempEd = new TemplateEditor( this, templateManager() ); 85 m_curTempEd = new TemplateEditor( this, templateManager() );
83} 86}
84void MainWindow::initActions() { 87void MainWindow::initActions() {
85 QAction* a = new QAction( tr("New Task" ), Resource::loadPixmap( "new" ), 88 QAction* a = new QAction( tr("New Task" ), Resource::loadPixmap( "new" ),
86 QString::null, 0, this, 0 ); 89 QString::null, 0, this, 0 );
@@ -156,155 +159,150 @@ void MainWindow::initActions() {
156 159
157 m_completedAction = new QAction( QString::null, tr("Completed tasks"), 160 m_completedAction = new QAction( QString::null, tr("Completed tasks"),
158 0, this, 0, TRUE ); 161 0, this, 0, TRUE );
159 m_completedAction->addTo( m_options ); 162 m_completedAction->addTo( m_options );
160 m_completedAction->setOn( showCompleted() ); 163 m_completedAction->setOn( showCompleted() );
161 connect(m_completedAction, SIGNAL( toggled(bool) ), 164 connect(m_completedAction, SIGNAL( toggled(bool) ),
162 this, SLOT(slotShowCompleted(bool) ) ); 165 this, SLOT(slotShowCompleted(bool) ) );
163 166
164 m_showDeadLineAction = new QAction( QString::null, tr("Show Deadline"), 167 m_showDeadLineAction = new QAction( QString::null, tr("Show Deadline"),
165 0, this, 0, TRUE ); 168 0, this, 0, TRUE );
166 m_showDeadLineAction->addTo( m_options ); 169 m_showDeadLineAction->addTo( m_options );
167 m_showDeadLineAction->setOn( showDeadline() ); 170 m_showDeadLineAction->setOn( showDeadline() );
168 connect(m_showDeadLineAction, SIGNAL(toggled(bool) ), 171 connect(m_showDeadLineAction, SIGNAL(toggled(bool) ),
169 this, SLOT( slotShowDeadLine( bool ) ) ); 172 this, SLOT( slotShowDeadLine( bool ) ) );
170 173
171 m_options->insertSeparator(); 174 m_options->insertSeparator();
172 175
173 m_bar->insertItem( tr("Data") ,m_edit ); 176 m_bar->insertItem( tr("Data") ,m_edit );
174 m_bar->insertItem( tr("Category"), m_catMenu ); 177 m_bar->insertItem( tr("Category"), m_catMenu );
175 m_bar->insertItem( tr("Options"), m_options ); 178 m_bar->insertItem( tr("Options"), m_options );
176 179
177 /* initialize the view menu */ 180 /* initialize the view menu */
178 a = new QAction( QString::null, tr("Show only over due"), 181 a = new QAction( QString::null, tr("Show only over due"),
179 0, this, 0, TRUE ); 182 0, this, 0, TRUE );
180 a->addTo( m_view ); 183 a->addTo( m_options );
181 a->setOn( showOverDue() ); 184 a->setOn( showOverDue() );
182 connect(a, SIGNAL(toggled(bool)), 185 connect(a, SIGNAL(toggled(bool)),
183 this, SLOT(slotShowDue(bool) ) ); 186 this, SLOT(slotShowDue(bool) ) );
184 m_view->insertSeparator();
185
186 m_bar->insertItem( tr("View"), m_view );
187 187
188 /* templates */ 188 /* templates */
189 m_edit->insertItem(tr("New from template"), m_template, 189 m_edit->insertItem(tr("New from template"), m_template,
190 -1, 0 ); 190 -1, 0 );
191 191
192} 192}
193/* m_curCat from Config */ 193/* m_curCat from Config */
194void MainWindow::initConfig() { 194void MainWindow::initConfig() {
195 Config config( "todo" ); 195 Config config( "todo" );
196 config.setGroup( "View" ); 196 config.setGroup( "View" );
197 m_completed = config.readBoolEntry( "ShowComplete", TRUE ); 197 m_completed = config.readBoolEntry( "ShowComplete", TRUE );
198 m_curCat = config.readEntry( "Category", QString::null ); 198 m_curCat = config.readEntry( "Category", QString::null );
199 m_deadline = config.readBoolEntry( "ShowDeadLine", TRUE); 199 m_deadline = config.readBoolEntry( "ShowDeadLine", TRUE);
200 m_overdue = config.readBoolEntry("ShowOverDue", TRUE ); 200 m_overdue = config.readBoolEntry("ShowOverDue", TRUE );
201} 201}
202void MainWindow::initUI() { 202void MainWindow::initUI() {
203 m_mainBox = new QVBox(this, "main box "); 203 m_mainBox = new QVBox(this, "main box ");
204 m_curQuick = new QuickEditImpl(this, m_mainBox ); 204 m_curQuick = new QuickEditImpl(this, m_mainBox );
205 m_curQuick->signal()->connect( this, SLOT(slotQuickEntered() ) ); 205 m_curQuick->signal()->connect( this, SLOT(slotQuickEntered() ) );
206 m_quickEdit.append( m_curQuick ); 206 m_quickEdit.append( m_curQuick );
207 207
208 208
209 209
210 m_stack = new QWidgetStack(m_mainBox, "main stack"); 210 m_stack = new QWidgetStack(m_mainBox, "main stack");
211 setCentralWidget( m_mainBox ); 211 setCentralWidget( m_mainBox );
212 212
213 setToolBarsMovable( FALSE ); 213 setToolBarsMovable( FALSE );
214 214
215 m_tool = new QToolBar( this ); 215 m_tool = new QToolBar( this );
216 m_tool->setHorizontalStretchable( TRUE ); 216 m_tool->setHorizontalStretchable( TRUE );
217 217
218 m_bar = new QMenuBar( m_tool ); 218 m_bar = new QMenuBar( m_tool );
219 219
220 /** QPopupMenu */ 220 /** QPopupMenu */
221 m_edit = new QPopupMenu( this ); 221 m_edit = new QPopupMenu( this );
222 m_options = new QPopupMenu( this ); 222 m_options = new QPopupMenu( this );
223 m_view = new QPopupMenu( this );
224 m_catMenu = new QPopupMenu( this ); 223 m_catMenu = new QPopupMenu( this );
225 m_template = new QPopupMenu( this ); 224 m_template = new QPopupMenu( this );
226 225
227 m_catMenu->setCheckable( TRUE ); 226 m_catMenu->setCheckable( TRUE );
228 m_template->setCheckable( TRUE ); 227 m_template->setCheckable( TRUE );
229 228
230 connect(m_catMenu, SIGNAL(activated(int) ), 229 connect(m_catMenu, SIGNAL(activated(int) ),
231 this, SLOT(setCategory(int) ) ); 230 this, SLOT(setCategory(int) ) );
232 connect(m_template, SIGNAL(activated(int) ), 231 connect(m_template, SIGNAL(activated(int) ),
233 this, SLOT(slotNewFromTemplate(int) ) ); 232 this, SLOT(slotNewFromTemplate(int) ) );
234} 233}
235void MainWindow::initViews() { 234void MainWindow::initViews() {
236 TableView* tableView = new TableView( this, m_stack ); 235 TableView* tableView = new TableView( this, m_stack );
237 m_stack->addWidget( tableView, m_counter++ ); 236 m_stack->addWidget( tableView, m_counter++ );
238 m_views.append( tableView ); 237 m_views.append( tableView );
239 m_curView = tableView; 238 m_curView = tableView;
240 connectBase( tableView ); 239 connectBase( tableView );
241 /* add QString type + QString configname to 240 /* add QString type + QString configname to
242 * the View menu 241 * the View menu
243 * and subdirs for multiple views 242 * and subdirs for multiple views
244 */ 243 */
245} 244}
246void MainWindow::initEditor() { 245void MainWindow::initEditor() {
247 m_curEdit = new Editor(); 246 m_curEdit = new Editor();
248} 247}
249void MainWindow::initShow() { 248void MainWindow::initShow() {
250 m_curShow = new TextViewShow(this); 249 m_curShow = new TextViewShow(this);
251 m_stack->addWidget( m_curShow->widget() , m_counter++ ); 250 m_stack->addWidget( m_curShow->widget() , m_counter++ );
252} 251}
253MainWindow::~MainWindow() { 252MainWindow::~MainWindow() {
254 delete templateManager(); 253 delete templateManager();
255} 254}
256void MainWindow::connectBase( ViewBase* base) { 255void MainWindow::connectBase( ViewBase* base) {
257 base->connectShow( this, SLOT(slotShow(int) ) ); 256 // once templates and signals mix we'll use it again
258 base->connectEdit( this, SLOT(slotEdit(int) ) ); 257}
259 base->connectUpdateSmall( this, 258QPopupMenu* MainWindow::contextMenu( int , bool recur ) {
260 SLOT(slotUpate1(int, const Todo::SmallTodo&) ));
261 base->connectUpdateBig( this,
262 SLOT(slotUpate2(int, const OTodo& ) ) );
263 base->connectUpdateView( this, SLOT(slotUpdate3( QWidget* ) ) ) ;
264 base->connectRemove(&m_todoMgr,
265 SLOT(remove(int)) );
266}
267QPopupMenu* MainWindow::contextMenu( int uid ) {
268 QPopupMenu* menu = new QPopupMenu(); 259 QPopupMenu* menu = new QPopupMenu();
269 260
270 m_editAction->addTo( menu ); 261 m_editAction->addTo( menu );
271 m_deleteAction->addTo( menu ); 262 m_deleteAction->addTo( menu );
272 m_duplicateAction->addTo( menu ); 263 m_duplicateAction->addTo( menu );
264
273 menu->insertSeparator(); 265 menu->insertSeparator();
274 266
267 /*
268 * if this event recurs we allow
269 * to detach it.
270 * remove all
271 */
272 if ( recur ) {
273 ; // FIXME
274 }
275
275 return menu; 276 return menu;
276} 277}
277QPopupMenu* MainWindow::options() { 278QPopupMenu* MainWindow::options() {
278 qWarning("Options"); 279 qWarning("Options");
279 return m_options; 280 return m_options;
280} 281}
281QPopupMenu* MainWindow::edit() { 282QPopupMenu* MainWindow::edit() {
282 return m_edit; 283 return m_edit;
283} 284}
284QPopupMenu* MainWindow::view() {
285 return m_view;
286}
287QToolBar* MainWindow::toolbar() { 285QToolBar* MainWindow::toolbar() {
288 return m_tool; 286 return m_tool;
289} 287}
290OTodoAccess::List MainWindow::list()const { 288OTodoAccess::List MainWindow::list()const {
291 return m_todoMgr.list(); 289 return m_todoMgr.list();
292} 290}
293OTodoAccess::List MainWindow::sorted( bool asc, int sortOrder ) { 291OTodoAccess::List MainWindow::sorted( bool asc, int sortOrder ) {
294 int cat = 0; 292 int cat = 0;
295 if ( m_curCat != tr("All Categories") ) 293 if ( m_curCat != tr("All Categories") )
296 cat = currentCatId(); 294 cat = currentCatId();
297 295
298 int filter = 1; 296 int filter = 1;
299 297
300 if (!m_completed ) 298 if (!m_completed )
301 filter |= 4; 299 filter |= 4;
302 if (m_overdue) 300 if (m_overdue)
303 filter |= 2; 301 filter |= 2;
304 302
305 return m_todoMgr.sorted( asc, sortOrder, filter, cat ); 303 return m_todoMgr.sorted( asc, sortOrder, filter, cat );
306} 304}
307OTodoAccess::List MainWindow::sorted( bool asc, int sortOrder, int addFilter) { 305OTodoAccess::List MainWindow::sorted( bool asc, int sortOrder, int addFilter) {
308 int cat = 0; 306 int cat = 0;
309 if ( m_curCat != tr("All Categories") ) 307 if ( m_curCat != tr("All Categories") )
310 cat = currentCatId(); 308 cat = currentCatId();
@@ -392,131 +390,109 @@ void MainWindow::populateTemplates() {
392 * the config but we setUid(-1) 390 * the config but we setUid(-1)
393 * to get a new uid 391 * to get a new uid
394 */ 392 */
395/* 393/*
396 * first we get the name of the template 394 * first we get the name of the template
397 * then we will use the TemplateManager 395 * then we will use the TemplateManager
398 */ 396 */
399void MainWindow::slotNewFromTemplate( int id ) { 397void MainWindow::slotNewFromTemplate( int id ) {
400 QString name = m_template->text( id ); 398 QString name = m_template->text( id );
401 399
402 OTodo event = templateManager()->templateEvent( name ); 400 OTodo event = templateManager()->templateEvent( name );
403 event = currentEditor()->edit(this, 401 event = currentEditor()->edit(this,
404 event ); 402 event );
405 403
406 if ( currentEditor()->accepted() ) { 404 if ( currentEditor()->accepted() ) {
407 /* assign new todo */ 405 /* assign new todo */
408 event.setUid( -1 ); 406 event.setUid( -1 );
409 currentView()->addEvent( event ); 407 currentView()->addEvent( event );
410 m_todoMgr.add( event ); 408 m_todoMgr.add( event );
411 409
412 populateCategories(); 410 populateCategories();
413 } 411 }
414} 412}
415void MainWindow::slotNew() { 413void MainWindow::slotNew() {
416 if(m_syncing) { 414 create();
417 QMessageBox::warning(this, tr("Todo"),
418 tr("Can not edit data, currently syncing"));
419 return;
420 }
421
422
423 OTodo todo = currentEditor()->newTodo( currentCatId(),
424 this );
425
426 if ( currentEditor()->accepted() ) {
427 //todo.assignUid();
428 m_todoMgr.add( todo );
429 currentView()->addEvent( todo );
430
431
432 // I'm afraid we must call this every time now, otherwise
433 // spend expensive time comparing all these strings...
434 // but only call if we changed something -zecke
435 populateCategories();
436 }
437 raiseCurrentView( );
438} 415}
439void MainWindow::slotDuplicate() { 416void MainWindow::slotDuplicate() {
440 if(m_syncing) { 417 if(m_syncing) {
441 QMessageBox::warning(this, tr("Todo"), 418 QMessageBox::warning(this, tr("Todo"),
442 tr("Can not edit data, currently syncing")); 419 tr("Can not edit data, currently syncing"));
443 return; 420 return;
444 } 421 }
445 OTodo ev = m_todoMgr.event( currentView()->current() ); 422 OTodo ev = m_todoMgr.event( currentView()->current() );
446 /* let's generate a new uid */ 423 /* let's generate a new uid */
447 ev.setUid(-1); 424 ev.setUid(-1);
448 m_todoMgr.add( ev ); 425 m_todoMgr.add( ev );
449 426
450 currentView()->addEvent( ev ); 427 currentView()->addEvent( ev );
451 raiseCurrentView(); 428 raiseCurrentView();
452} 429}
453void MainWindow::slotDelete() { 430void MainWindow::slotDelete() {
454 if (!currentView()->current() ) 431 if (!currentView()->current() )
455 return; 432 return;
456 433
457 if(m_syncing) { 434 if(m_syncing) {
458 QMessageBox::warning(this, tr("Todo"), 435 QMessageBox::warning(this, tr("Todo"),
459 tr("Can not edit data, currently syncing")); 436 tr("Can not edit data, currently syncing"));
460 return; 437 return;
461 } 438 }
462 QString strName = currentView()->currentRepresentation(); 439 QString strName = currentView()->currentRepresentation();
463 if (!QPEMessageBox::confirmDelete(this, tr("Todo"), strName ) ) 440 if (!QPEMessageBox::confirmDelete(this, tr("Todo"), strName ) )
464 return; 441 return;
465 442
466 m_todoMgr.remove( currentView()->current() ); 443 m_todoMgr.remove( currentView()->current() );
467 currentView()->removeEvent( currentView()->current() ); 444 currentView()->removeEvent( currentView()->current() );
468 raiseCurrentView(); 445 raiseCurrentView();
469} 446}
470void MainWindow::slotDeleteAll() { 447void MainWindow::slotDeleteAll() {
471 if(m_syncing) { 448 if(m_syncing) {
472 QMessageBox::warning(this, tr("Todo"), 449 QMessageBox::warning(this, tr("Todo"),
473 tr("Can not edit data, currently syncing")); 450 tr("Can not edit data, currently syncing"));
474 return; 451 return;
475 } 452 }
476 453
477 //QString strName = table->text( table->currentRow(), 2 ).left( 30 );
478 454
479 if ( !QPEMessageBox::confirmDelete( this, tr( "Todo" ), tr("all tasks?") ) ) 455 if ( !QPEMessageBox::confirmDelete( this, tr( "Todo" ), tr("all tasks?") ) )
480 return; 456 return;
481 457
482 m_todoMgr.removeAll(); 458 m_todoMgr.removeAll();
483 currentView()->clear(); 459 currentView()->clear();
484 460
485 raiseCurrentView(); 461 raiseCurrentView();
486} 462}
487void MainWindow::slotDeleteCompleted() { 463void MainWindow::slotDeleteCompleted() {
488 if(m_syncing) { 464 if(m_syncing) {
489 QMessageBox::warning(this, tr("Todo"), 465 QMessageBox::warning(this, tr("Todo"),
490 tr("Can not edit data, currently syncing")); 466 tr("Can not edit data, currently syncing"));
491 return; 467 return;
492 } 468 }
493 469
494 if ( !QPEMessageBox::confirmDelete( this, tr( "Todo" ), tr("all completed tasks?") ) ) 470 if ( !QPEMessageBox::confirmDelete( this, tr( "Todo" ), tr("all completed tasks?") ) )
495 return; 471 return;
496 472
497 // FIXME 473
498 //m_todoMgr.remove( currentView()->completed() ); 474 m_todoMgr.removeCompleted();
499 currentView()->updateView( ); 475 currentView()->updateView( );
500} 476}
501void MainWindow::slotFind() { 477void MainWindow::slotFind() {
502 478
503} 479}
504void MainWindow::slotEdit() { 480void MainWindow::slotEdit() {
505 slotEdit( currentView()->current() ); 481 slotEdit( currentView()->current() );
506} 482}
507/* 483/*
508 * set the category 484 * set the category
509 */ 485 */
510void MainWindow::setCategory( int c) { 486void MainWindow::setCategory( int c) {
511 if ( c <= 0 ) return; 487 if ( c <= 0 ) return;
512 488
513 489
514 qWarning("Iterating over cats %d", c ); 490 qWarning("Iterating over cats %d", c );
515 for ( unsigned int i = 1; i < m_catMenu->count(); i++ ) 491 for ( unsigned int i = 1; i < m_catMenu->count(); i++ )
516 m_catMenu->setItemChecked(i, c == (int)i ); 492 m_catMenu->setItemChecked(i, c == (int)i );
517 493
518 if (c == 1 ) { 494 if (c == 1 ) {
519 m_curCat = QString::null; 495 m_curCat = QString::null;
520 setCaption( tr("Todo") + " - " + tr("All Categories" ) ); 496 setCaption( tr("Todo") + " - " + tr("All Categories" ) );
521 497
522 }else if ( c == (int)m_catMenu->count() - 1 ) { 498 }else if ( c == (int)m_catMenu->count() - 1 ) {
@@ -531,60 +507,49 @@ void MainWindow::setCategory( int c) {
531 currentView()->setShowCategory( m_curCat ); 507 currentView()->setShowCategory( m_curCat );
532 raiseCurrentView(); 508 raiseCurrentView();
533} 509}
534void MainWindow::slotShowDeadLine( bool dead) { 510void MainWindow::slotShowDeadLine( bool dead) {
535 m_deadline = dead; 511 m_deadline = dead;
536 currentView()->setShowDeadline( dead ); 512 currentView()->setShowDeadline( dead );
537} 513}
538void MainWindow::slotShowCompleted( bool show) { 514void MainWindow::slotShowCompleted( bool show) {
539 m_completed = show; 515 m_completed = show;
540 currentView()->setShowCompleted( m_completed ); 516 currentView()->setShowCompleted( m_completed );
541} 517}
542bool MainWindow::showOverDue()const { 518bool MainWindow::showOverDue()const {
543 return m_overdue; 519 return m_overdue;
544} 520}
545void MainWindow::setDocument( const QString& fi) { 521void MainWindow::setDocument( const QString& fi) {
546 DocLnk doc(fi); 522 DocLnk doc(fi);
547 if (doc.isValid() ) 523 if (doc.isValid() )
548 receiveFile(doc.file() ); 524 receiveFile(doc.file() );
549 else 525 else
550 receiveFile(fi ); 526 receiveFile(fi );
551} 527}
552 528
553static const char *beamfile = "/tmp/opie-todo.vcs"; 529static const char *beamfile = "/tmp/opie-todo.vcs";
554void MainWindow::slotBeam() { 530void MainWindow::slotBeam() {
555 ::unlink( beamfile ); 531 beam( currentView()->current() );
556 OTodo todo = event( currentView()->current() );
557 OTodoAccessVCal* cal = new OTodoAccessVCal(QString::fromLatin1(beamfile) );
558 OTodoAccess acc( cal );
559 acc.load();
560 acc.add( todo );
561 acc.save();
562 Ir* ir = new Ir(this );
563 connect(ir, SIGNAL(done(Ir*) ),
564 this, SLOT(beamDone(Ir*) ) );
565 ir->send( beamfile, todo.summary(), "text/x-vCalendar" );
566
567} 532}
568void MainWindow::beamDone( Ir* ir) { 533void MainWindow::beamDone( Ir* ir) {
569 delete ir; 534 delete ir;
570 ::unlink( beamfile ); 535 ::unlink( beamfile );
571} 536}
572void MainWindow::receiveFile( const QString& filename ) { 537void MainWindow::receiveFile( const QString& filename ) {
573 OTodoAccessVCal* cal = new OTodoAccessVCal(filename ); 538 OTodoAccessVCal* cal = new OTodoAccessVCal(filename );
574 OTodoAccess acc( cal ); 539 OTodoAccess acc( cal );
575 acc.load(); 540 acc.load();
576 OTodoAccess::List list = acc.allRecords(); 541 OTodoAccess::List list = acc.allRecords();
577 542
578 QString message = tr("<P>%1 new tasks arrived.<p>Would you like to add them to your Todolist?").arg(list.count() ); 543 QString message = tr("<P>%1 new tasks arrived.<p>Would you like to add them to your Todolist?").arg(list.count() );
579 544
580 if ( QMessageBox::information(this, tr("New Tasks"), 545 if ( QMessageBox::information(this, tr("New Tasks"),
581 message, QMessageBox::Ok, 546 message, QMessageBox::Ok,
582 QMessageBox::Cancel ) == QMessageBox::Ok ) { 547 QMessageBox::Cancel ) == QMessageBox::Ok ) {
583 OTodoAccess::List::Iterator it; 548 OTodoAccess::List::Iterator it;
584 for ( it = list.begin(); it != list.end(); ++it ) 549 for ( it = list.begin(); it != list.end(); ++it )
585 m_todoMgr.add( (*it) ); 550 m_todoMgr.add( (*it) );
586 551
587 currentView()->updateView(); 552 currentView()->updateView();
588 } 553 }
589} 554}
590 555
@@ -683,24 +648,158 @@ void MainWindow::updateTodo( const OTodo& ev) {
683 */ 648 */
684void MainWindow::slotUpdate3( QWidget* ) { 649void MainWindow::slotUpdate3( QWidget* ) {
685 650
686} 651}
687void MainWindow::updateList() { 652void MainWindow::updateList() {
688 m_todoMgr.updateList(); 653 m_todoMgr.updateList();
689} 654}
690void MainWindow::setReadAhead( uint count ) { 655void MainWindow::setReadAhead( uint count ) {
691 if (m_todoMgr.todoDB() ) 656 if (m_todoMgr.todoDB() )
692 m_todoMgr.todoDB()->setReadAhead( count ); 657 m_todoMgr.todoDB()->setReadAhead( count );
693} 658}
694void MainWindow::slotQuickEntered() { 659void MainWindow::slotQuickEntered() {
695 qWarning("entered"); 660 qWarning("entered");
696 OTodo todo = quickEditor()->todo(); 661 OTodo todo = quickEditor()->todo();
697 if (todo.isEmpty() ) 662 if (todo.isEmpty() )
698 return; 663 return;
699 664
700 m_todoMgr.add( todo ); 665 m_todoMgr.add( todo );
701 currentView()->addEvent( todo ); 666 currentView()->addEvent( todo );
702 raiseCurrentView(); 667 raiseCurrentView();
703} 668}
704QuickEditBase* MainWindow::quickEditor() { 669QuickEditBase* MainWindow::quickEditor() {
705 return m_curQuick; 670 return m_curQuick;
706} 671}
672void MainWindow::slotComplete( int uid ) {
673 slotComplete( event(uid) );
674}
675void MainWindow::slotComplete( const OTodo& todo ) {
676 OTodo to = todo;
677 to.setCompleted( !to.isCompleted() );
678 to.setCompletedDate( QDate::currentDate() );
679
680 /*
681 * if the item does recur
682 * we need to spin it off
683 * and update the items duedate to the next
684 * possible recurrance of this item...
685 * the spinned off one will loose the
686 */
687 if ( to.recurrence().doesRecur() && to.isCompleted() ) {
688 OTodo to2( to );
689
690 /* the spinned off one won't recur anymore */
691 to.setRecurrence( ORecur() );
692
693 ORecur rec = to2.recurrence();
694 rec.setStart( to.dueDate() );
695 to2.setRecurrence( rec );
696 /*
697 * if there is a next occurence
698 * from the duedate of the last recurrance
699 */
700 QDate date;
701 if ( to2.recurrence().nextOcurrence( to2.dueDate().addDays(1), date ) ) {
702 QDate inval;
703 /* generate a new uid for the old record */
704 to.setUid( 1 );
705
706 /* add the old one cause it has a new UID here cause it was spin off */
707 m_todoMgr.add( to );
708
709 /*
710 * update the due date
711 * start date
712 * and complete date
713 */
714 to2.setDueDate( date );
715 to2.setStartDate( inval );
716 to2.setCompletedDate( inval );
717 to2.setCompleted( false );
718 updateTodo( to2 );
719 }else
720 updateTodo( to );
721 }else
722 updateTodo( to );
723
724 currentView()->updateView();
725 raiseCurrentView();
726}
727void MainWindow::flush() {
728 slotFlush();
729}
730void MainWindow::reload() {
731 slotReload();
732}
733int MainWindow::create() {
734 int uid = 0;
735 if(m_syncing) {
736 QMessageBox::warning(this, tr("Todo"),
737 tr("Can not edit data, currently syncing"));
738 return uid;
739 }
740
741
742 OTodo todo = currentEditor()->newTodo( currentCatId(),
743 this );
744
745 if ( currentEditor()->accepted() ) {
746 //todo.assignUid();
747 uid = todo.uid();
748 m_todoMgr.add( todo );
749 currentView()->addEvent( todo );
750
751
752 // I'm afraid we must call this every time now, otherwise
753 // spend expensive time comparing all these strings...
754 // but only call if we changed something -zecke
755 populateCategories();
756 }
757 raiseCurrentView( );
758
759 return uid;
760}
761/* delete it silently... */
762bool MainWindow::remove( int uid ) {
763 if (m_syncing) return false;
764
765 return m_todoMgr.remove( uid );
766}
767void MainWindow::beam( int uid, int ) {
768 ::unlink( beamfile );
769 OTodo todo = event( uid );
770 OTodoAccessVCal* cal = new OTodoAccessVCal(QString::fromLatin1(beamfile) );
771 OTodoAccess acc( cal );
772 acc.load();
773 acc.add( todo );
774 acc.save();
775 Ir* ir = new Ir(this );
776 connect(ir, SIGNAL(done(Ir*) ),
777 this, SLOT(beamDone(Ir*) ) );
778 ir->send( beamfile, todo.summary(), "text/x-vCalendar" );
779}
780void MainWindow::show( int uid ) {
781 slotShow( uid );
782}
783void MainWindow::edit( int uid ) {
784 slotEdit( uid );
785}
786void MainWindow::add( const OPimRecord& rec) {
787 if ( rec.rtti() != OTodo::rtti() ) return;
788
789 const OTodo& todo = static_cast<const OTodo&>(rec);
790
791 m_todoMgr.add(todo );
792 currentView()->addEvent( todo );
793
794
795 // I'm afraid we must call this every time now, otherwise
796 // spend expensive time comparing all these strings...
797 // but only call if we changed something -zecke
798 populateCategories();
799}
800/* todo does not have the QDataStream<< and >> operators implemented :(
801 * FIXME
802 */
803OPimRecord* MainWindow::record( int rtti, const QByteArray& ) {
804 return 0l;
805}