karm

mainwindow.cpp

00001 /*
00002 * Top Level window for KArm.
00003 * Distributed under the GPL.
00004 */
00005 
00006 #include <numeric>
00007 
00008 #include "kaccelmenuwatch.h"
00009 #include <dcopclient.h>
00010 #include <kaccel.h>
00011 #include <kaction.h>
00012 #include <kapplication.h>       // kapp
00013 #include <kconfig.h>
00014 #include <kdebug.h>
00015 #include <kglobal.h>
00016 #include <kkeydialog.h>
00017 #include <klocale.h>            // i18n
00018 #include <kmessagebox.h>
00019 #include <kstatusbar.h>         // statusBar()
00020 #include <kstdaction.h>
00021 #include <qkeycode.h>
00022 #include <qpopupmenu.h>
00023 #include <qptrlist.h>
00024 #include <qstring.h>
00025 
00026 #include "karmerrors.h"
00027 #include "karmutility.h"
00028 #include "mainwindow.h"
00029 #include "preferences.h"
00030 #include "print.h"
00031 #include "task.h"
00032 #include "taskview.h"
00033 #include "timekard.h"
00034 #include "tray.h"
00035 #include "version.h"
00036 
00037 MainWindow::MainWindow( const QString &icsfile )
00038   : DCOPObject ( "KarmDCOPIface" ),
00039     KParts::MainWindow(), 
00040     _accel     ( new KAccel( this ) ),
00041     _watcher   ( new KAccelMenuWatch( _accel, this ) ),
00042     _totalSum  ( 0 ),
00043     _sessionSum( 0 )
00044 {
00045 
00046   _taskView  = new TaskView( this, 0, icsfile );
00047 
00048   setCentralWidget( _taskView );
00049   // status bar
00050   startStatusBar();
00051 
00052   // setup PreferenceDialog.
00053   _preferences = Preferences::instance();
00054 
00055   // popup menus
00056   makeMenus();
00057   _watcher->updateMenus();
00058 
00059   // connections
00060   connect( _taskView, SIGNAL( totalTimesChanged( long, long ) ),
00061            this, SLOT( updateTime( long, long ) ) );
00062   connect( _taskView, SIGNAL( selectionChanged ( QListViewItem * )),
00063            this, SLOT(slotSelectionChanged()));
00064   connect( _taskView, SIGNAL( updateButtons() ),
00065            this, SLOT(slotSelectionChanged()));
00066 
00067   loadGeometry();
00068 
00069   // Setup context menu request handling
00070   connect( _taskView,
00071            SIGNAL( contextMenuRequested( QListViewItem*, const QPoint&, int )),
00072            this,
00073            SLOT( contextMenuRequest( QListViewItem*, const QPoint&, int )));
00074 
00075   _tray = new KarmTray( this );
00076 
00077   connect( _tray, SIGNAL( quitSelected() ), SLOT( quit() ) );
00078 
00079   connect( _taskView, SIGNAL( timersActive() ), _tray, SLOT( startClock() ) );
00080   connect( _taskView, SIGNAL( timersActive() ), this,  SLOT( enableStopAll() ));
00081   connect( _taskView, SIGNAL( timersInactive() ), _tray, SLOT( stopClock() ) );
00082   connect( _taskView, SIGNAL( timersInactive() ),  this,  SLOT( disableStopAll()));
00083   connect( _taskView, SIGNAL( tasksChanged( QPtrList<Task> ) ),
00084                       _tray, SLOT( updateToolTip( QPtrList<Task> ) ));
00085 
00086   _taskView->load();
00087 
00088   // Everything that uses Preferences has been created now, we can let it
00089   // emit its signals
00090   _preferences->emitSignals();
00091   slotSelectionChanged();
00092 
00093   // Register with DCOP
00094   if ( !kapp->dcopClient()->isRegistered() ) 
00095   {
00096     kapp->dcopClient()->registerAs( "karm" );
00097     kapp->dcopClient()->setDefaultObject( objId() );
00098   }
00099 
00100   // Set up DCOP error messages
00101   m_error[ KARM_ERR_GENERIC_SAVE_FAILED ] = 
00102     i18n( "Save failed, most likely because the file could not be locked." );
00103   m_error[ KARM_ERR_COULD_NOT_MODIFY_RESOURCE ] = 
00104     i18n( "Could not modify calendar resource." );
00105   m_error[ KARM_ERR_MEMORY_EXHAUSTED ] = 
00106     i18n( "Out of memory--could not create object." );
00107   m_error[ KARM_ERR_UID_NOT_FOUND ] = 
00108     i18n( "UID not found." );
00109   m_error[ KARM_ERR_INVALID_DATE ] = 
00110     i18n( "Invalidate date--format is YYYY-MM-DD." );
00111   m_error[ KARM_ERR_INVALID_TIME ] = 
00112     i18n( "Invalid time--format is YYYY-MM-DDTHH:MM:SS." );
00113   m_error[ KARM_ERR_INVALID_DURATION ] = 
00114     i18n( "Invalid task duration--must be greater than zero." );
00115 }
00116 
00117 void MainWindow::slotSelectionChanged()
00118 {
00119   Task* item= _taskView->current_item();
00120   actionDelete->setEnabled(item);
00121   actionEdit->setEnabled(item);
00122   actionStart->setEnabled(item && !item->isRunning() && !item->isComplete());
00123   actionStop->setEnabled(item && item->isRunning());
00124   actionMarkAsComplete->setEnabled(item && !item->isComplete());
00125   actionMarkAsIncomplete->setEnabled(item && item->isComplete());
00126 }
00127 
00128 // This is _old_ code, but shows how to enable/disable add comment menu item.
00129 // We'll need this kind of logic when comments are implemented.
00130 //void MainWindow::timeLoggingChanged(bool on)
00131 //{
00132 //  actionAddComment->setEnabled( on );
00133 //}
00134 
00135 bool MainWindow::save()
00136 {
00137   kdDebug(5970) << "Saving time data to disk." << endl;
00138   QString err=_taskView->save();  // untranslated error msg.
00139   if (err.isEmpty()) statusBar()->message(i18n("Successfully saved tasks and history"),1807);
00140   else statusBar()->message(i18n(err.ascii()),7707); // no msgbox since save is called when exiting
00141   saveGeometry();
00142   return true;
00143 }
00144 
00145 void MainWindow::exportcsvHistory()
00146 {
00147   kdDebug(5970) << "Exporting History to disk." << endl;
00148   QString err=_taskView->exportcsvHistory();
00149   if (err.isEmpty()) statusBar()->message(i18n("Successfully exported History to CSV-file"),1807);
00150   else KMessageBox::error(this, err.ascii());
00151   saveGeometry();
00152   
00153 }
00154 
00155 void MainWindow::quit()
00156 {
00157   kapp->quit();
00158 }
00159 
00160 
00161 MainWindow::~MainWindow()
00162 {
00163   kdDebug(5970) << "MainWindow::~MainWindows: Quitting karm." << endl;
00164   _taskView->stopAllTimers();
00165   save();
00166   _taskView->closeStorage();
00167 }
00168 
00169 void MainWindow::enableStopAll()
00170 {
00171   actionStopAll->setEnabled(true);
00172 }
00173 
00174 void MainWindow::disableStopAll()
00175 {
00176   actionStopAll->setEnabled(false);
00177 }
00178 
00179 
00185 void MainWindow::updateTime( long sessionDiff, long totalDiff )
00186 {
00187   _sessionSum += sessionDiff;
00188   _totalSum   += totalDiff;
00189 
00190   updateStatusBar();
00191 }
00192 
00193 void MainWindow::updateStatusBar( )
00194 {
00195   QString time;
00196 
00197   time = formatTime( _sessionSum );
00198   statusBar()->changeItem( i18n("Session: %1").arg(time), 0 );
00199 
00200   time = formatTime( _totalSum );
00201   statusBar()->changeItem( i18n("Total: %1" ).arg(time), 1);
00202 }
00203 
00204 void MainWindow::startStatusBar()
00205 {
00206   statusBar()->insertItem( i18n("Session"), 0, 0, true );
00207   statusBar()->insertItem( i18n("Total" ), 1, 0, true );
00208 }
00209 
00210 void MainWindow::saveProperties( KConfig* cfg )
00211 {
00212   _taskView->stopAllTimers();
00213   _taskView->save();
00214   cfg->writeEntry( "WindowShown", isVisible());
00215 }
00216 
00217 void MainWindow::readProperties( KConfig* cfg )
00218 {
00219   if( cfg->readBoolEntry( "WindowShown", true ))
00220     show();
00221 }
00222 
00223 void MainWindow::keyBindings()
00224 {
00225   KKeyDialog::configure( actionCollection(), this );
00226 }
00227 
00228 void MainWindow::startNewSession()
00229 {
00230   _taskView->startNewSession();
00231 }
00232 
00233 void MainWindow::resetAllTimes()
00234 {
00235   if ( KMessageBox::warningContinueCancel( this, i18n( "Do you really want to reset the time to zero for all tasks?" ),
00236        i18n( "Confirmation Required" ), KGuiItem( i18n( "Reset All Times" ) ) ) == KMessageBox::Continue )
00237     _taskView->resetTimeForAllTasks();
00238 }
00239 
00240 void MainWindow::makeMenus()
00241 {
00242   KAction
00243     *actionKeyBindings,
00244     *actionNew,
00245     *actionNewSub;
00246 
00247   (void) KStdAction::quit(  this, SLOT( quit() ),  actionCollection());
00248   (void) KStdAction::print( this, SLOT( print() ), actionCollection());
00249   actionKeyBindings = KStdAction::keyBindings( this, SLOT( keyBindings() ),
00250       actionCollection() );
00251   actionPreferences = KStdAction::preferences(_preferences,
00252       SLOT(showDialog()),
00253       actionCollection() );
00254   (void) KStdAction::save( this, SLOT( save() ), actionCollection() );
00255   KAction* actionStartNewSession = new KAction( i18n("Start &New Session"),
00256       0,
00257       this,
00258       SLOT( startNewSession() ),
00259       actionCollection(),
00260       "start_new_session");
00261   KAction* actionResetAll = new KAction( i18n("&Reset All Times"),
00262       0,
00263       this,
00264       SLOT( resetAllTimes() ),
00265       actionCollection(),
00266       "reset_all_times");
00267   actionStart = new KAction( i18n("&Start"),
00268       QString::fromLatin1("1rightarrow"), Key_S,
00269       _taskView,
00270       SLOT( startCurrentTimer() ), actionCollection(),
00271       "start");
00272   actionStop = new KAction( i18n("S&top"),
00273       QString::fromLatin1("stop"), 0,
00274       _taskView,
00275       SLOT( stopCurrentTimer() ), actionCollection(),
00276       "stop");
00277   actionStopAll = new KAction( i18n("Stop &All Timers"),
00278       Key_Escape,
00279       _taskView,
00280       SLOT( stopAllTimers() ), actionCollection(),
00281       "stopAll");
00282   actionStopAll->setEnabled(false);
00283 
00284   actionNew = new KAction( i18n("&New..."),
00285       QString::fromLatin1("filenew"), CTRL+Key_N,
00286       _taskView,
00287       SLOT( newTask() ), actionCollection(),
00288       "new_task");
00289   actionNewSub = new KAction( i18n("New &Subtask..."),
00290       QString::fromLatin1("kmultiple"), CTRL+ALT+Key_N,
00291       _taskView,
00292       SLOT( newSubTask() ), actionCollection(),
00293       "new_sub_task");
00294   actionDelete = new KAction( i18n("&Delete"),
00295       QString::fromLatin1("editdelete"), Key_Delete,
00296       _taskView,
00297       SLOT( deleteTask() ), actionCollection(),
00298       "delete_task");
00299   actionEdit = new KAction( i18n("&Edit..."),
00300       QString::fromLatin1("edit"), CTRL + Key_E,
00301       _taskView,
00302       SLOT( editTask() ), actionCollection(),
00303       "edit_task");
00304 //  actionAddComment = new KAction( i18n("&Add Comment..."),
00305 //      QString::fromLatin1("document"),
00306 //      CTRL+ALT+Key_E,
00307 //      _taskView,
00308 //      SLOT( addCommentToTask() ),
00309 //      actionCollection(),
00310 //      "add_comment_to_task");
00311   actionMarkAsComplete = new KAction( i18n("&Mark as Complete"),
00312       QString::fromLatin1("document"),
00313       CTRL+Key_M,
00314       _taskView,
00315       SLOT( markTaskAsComplete() ),
00316       actionCollection(),
00317       "mark_as_complete");
00318   actionMarkAsIncomplete = new KAction( i18n("&Mark as Incomplete"),
00319       QString::fromLatin1("document"),
00320       CTRL+Key_M,
00321       _taskView,
00322       SLOT( markTaskAsIncomplete() ),
00323       actionCollection(),
00324       "mark_as_incomplete");
00325   actionClipTotals = new KAction( i18n("&Copy Totals to Clipboard"),
00326       QString::fromLatin1("klipper"),
00327       CTRL+Key_C,
00328       _taskView,
00329       SLOT( clipTotals() ),
00330       actionCollection(),
00331       "clip_totals");
00332   actionClipHistory = new KAction( i18n("Copy &History to Clipboard"),
00333       QString::fromLatin1("klipper"),
00334       CTRL+ALT+Key_C,
00335       _taskView,
00336       SLOT( clipHistory() ),
00337       actionCollection(),
00338       "clip_history");
00339 
00340   new KAction( i18n("Import &Legacy Flat File..."), 0,
00341       _taskView, SLOT(loadFromFlatFile()), actionCollection(),
00342       "import_flatfile");
00343   new KAction( i18n("&Export to CSV File..."), 0,
00344       _taskView, SLOT(exportcsvFile()), actionCollection(),
00345       "export_csvfile");
00346   new KAction( i18n("Export &History to CSV File..."), 0,
00347       this, SLOT(exportcsvHistory()), actionCollection(),
00348       "export_csvhistory");
00349   new KAction( i18n("Import Tasks From &Planner..."), 0,
00350       _taskView, SLOT(importPlanner()), actionCollection(),
00351       "import_planner");  
00352 
00353 /*
00354   new KAction( i18n("Import E&vents"), 0,
00355                             _taskView,
00356                             SLOT( loadFromKOrgEvents() ), actionCollection(),
00357                             "import_korg_events");
00358   */
00359 
00360   setXMLFile( QString::fromLatin1("karmui.rc") );
00361   createGUI( 0 );
00362 
00363   // Tool tips must be set after the createGUI.
00364   actionKeyBindings->setToolTip( i18n("Configure key bindings") );
00365   actionKeyBindings->setWhatsThis( i18n("This will let you configure key"
00366                                         "bindings which is specific to karm") );
00367 
00368   actionStartNewSession->setToolTip( i18n("Start a new session") );
00369   actionStartNewSession->setWhatsThis( i18n("This will reset the session time "
00370                                             "to 0 for all tasks, to start a "
00371                                             "new session, without affecting "
00372                                             "the totals.") );
00373   actionResetAll->setToolTip( i18n("Reset all times") );
00374   actionResetAll->setWhatsThis( i18n("This will reset the session and total "
00375                                      "time to 0 for all tasks, to restart from "
00376                                      "scratch.") );
00377 
00378   actionStart->setToolTip( i18n("Start timing for selected task") );
00379   actionStart->setWhatsThis( i18n("This will start timing for the selected "
00380                                   "task.\n"
00381                                   "It is even possible to time several tasks "
00382                                   "simultaneously.\n\n"
00383                                   "You may also start timing of a tasks by "
00384                                   "double clicking the left mouse "
00385                                   "button on a given task. This will, however, "
00386                                   "stop timing of other tasks."));
00387 
00388   actionStop->setToolTip( i18n("Stop timing of the selected task") );
00389   actionStop->setWhatsThis( i18n("Stop timing of the selected task") );
00390 
00391   actionStopAll->setToolTip( i18n("Stop all of the active timers") );
00392   actionStopAll->setWhatsThis( i18n("Stop all of the active timers") );
00393 
00394   actionNew->setToolTip( i18n("Create new top level task") );
00395   actionNew->setWhatsThis( i18n("This will create a new top level task.") );
00396 
00397   actionDelete->setToolTip( i18n("Delete selected task") );
00398   actionDelete->setWhatsThis( i18n("This will delete the selected task and "
00399                                    "all its subtasks.") );
00400 
00401   actionEdit->setToolTip( i18n("Edit name or times for selected task") );
00402   actionEdit->setWhatsThis( i18n("This will bring up a dialog box where you "
00403                                  "may edit the parameters for the selected "
00404                                  "task."));
00405   //actionAddComment->setToolTip( i18n("Add a comment to a task") );
00406   //actionAddComment->setWhatsThis( i18n("This will bring up a dialog box where "
00407   //                                     "you can add a comment to a task. The "
00408   //                                     "comment can for instance add information on what you "
00409   //                                     "are currently doing. The comment will "
00410   //                                     "be logged in the log file."));
00411   actionClipTotals->setToolTip(i18n("Copy task totals to clipboard"));
00412   actionClipHistory->setToolTip(i18n("Copy time card history to clipboard."));
00413 
00414   slotSelectionChanged();
00415 }
00416 
00417 void MainWindow::print()
00418 {
00419   MyPrinter printer(_taskView);
00420   printer.print();
00421 }
00422 
00423 void MainWindow::loadGeometry()
00424 {
00425   if (initialGeometrySet()) setAutoSaveSettings();
00426   else
00427   {
00428     KConfig &config = *kapp->config();
00429 
00430     config.setGroup( QString::fromLatin1("Main Window Geometry") );
00431     int w = config.readNumEntry( QString::fromLatin1("Width"), 100 );
00432     int h = config.readNumEntry( QString::fromLatin1("Height"), 100 );
00433     w = QMAX( w, sizeHint().width() );
00434     h = QMAX( h, sizeHint().height() );
00435     resize(w, h);
00436   }
00437 }
00438 
00439 
00440 void MainWindow::saveGeometry()
00441 {
00442   KConfig &config = *KGlobal::config();
00443   config.setGroup( QString::fromLatin1("Main Window Geometry"));
00444   config.writeEntry( QString::fromLatin1("Width"), width());
00445   config.writeEntry( QString::fromLatin1("Height"), height());
00446   config.sync();
00447 }
00448 
00449 bool MainWindow::queryClose()
00450 {
00451   if ( !kapp->sessionSaving() ) {
00452     hide();
00453     return false;
00454   }
00455   return KMainWindow::queryClose();
00456 }
00457 
00458 void MainWindow::contextMenuRequest( QListViewItem*, const QPoint& point, int )
00459 {
00460     QPopupMenu* pop = dynamic_cast<QPopupMenu*>(
00461                           factory()->container( i18n( "task_popup" ), this ) );
00462     if ( pop )
00463       pop->popup( point );
00464 }
00465 
00466 //----------------------------------------------------------------------------
00467 //
00468 //                       D C O P   I N T E R F A C E
00469 //
00470 //----------------------------------------------------------------------------
00471 
00472 QString MainWindow::version() const
00473 {
00474   return KARM_VERSION;
00475 }
00476 
00477 QString MainWindow::deletetodo()
00478 {
00479   _taskView->deleteTask();
00480   return "";
00481 }
00482 
00483 bool MainWindow::getpromptdelete()
00484 {
00485   return _preferences->promptDelete();
00486 }
00487 
00488 QString MainWindow::setpromptdelete( bool prompt )
00489 {
00490   _preferences->setPromptDelete( prompt );
00491   return "";
00492 }
00493 
00494 QString MainWindow::taskIdFromName( const QString &taskname ) const
00495 {
00496   QString rval = "";
00497 
00498   Task* task = _taskView->first_child();
00499   while ( rval.isEmpty() && task )
00500   {
00501     rval = _hasTask( task, taskname );
00502     task = task->nextSibling();
00503   }
00504   
00505   return rval;
00506 }
00507 
00508 int MainWindow::addTask( const QString& taskname ) 
00509 {
00510   DesktopList desktopList;
00511   QString uid = _taskView->addTask( taskname, 0, 0, desktopList );
00512   kdDebug(5970) << "MainWindow::addTask( " << taskname << " ) returns " << uid << endl;
00513   if ( uid.length() > 0 ) return 0;
00514   else
00515   {
00516     // We can't really tell what happened, b/c the resource framework only
00517     // returns a boolean.
00518     return KARM_ERR_GENERIC_SAVE_FAILED;
00519   }
00520 }
00521 
00522 QString MainWindow::setPerCentComplete( const QString& taskName, int perCent )
00523 {
00524   int index;
00525   QString err="no such task";
00526   for (int i=0; i<_taskView->count(); i++)
00527   {
00528     if ((_taskView->item_at_index(i)->name()==taskName))
00529     {
00530       index=i;
00531       if (err==QString::null) err="task name is abigious";
00532       if (err=="no such task") err=QString::null;
00533     }
00534   }
00535   if (err==QString::null) 
00536   {
00537     _taskView->item_at_index(index)->setPercentComplete( perCent, _taskView->storage() );
00538   }
00539   return err;
00540 }
00541 
00542 int MainWindow::bookTime
00543 ( const QString& taskId, const QString& datetime, long minutes )
00544 {
00545   int rval = 0;
00546   QDate startDate;
00547   QTime startTime;
00548   QDateTime startDateTime;
00549   Task *task, *t;
00550 
00551   if ( minutes <= 0 ) rval = KARM_ERR_INVALID_DURATION;
00552 
00553   // Find task
00554   task = _taskView->first_child();
00555   t = NULL;
00556   while ( !t && task )
00557   {
00558     t = _hasUid( task, taskId );
00559     task = task->nextSibling();
00560   }
00561   if ( t == NULL ) rval = KARM_ERR_UID_NOT_FOUND;
00562 
00563   // Parse datetime
00564   if ( !rval ) 
00565   {
00566     startDate = QDate::fromString( datetime, Qt::ISODate );
00567     if ( datetime.length() > 10 )  // "YYYY-MM-DD".length() = 10
00568     {
00569       startTime = QTime::fromString( datetime, Qt::ISODate );
00570     }
00571     else startTime = QTime( 12, 0 );
00572     if ( startDate.isValid() && startTime.isValid() )
00573     {
00574       startDateTime = QDateTime( startDate, startTime );
00575     }
00576     else rval = KARM_ERR_INVALID_DATE;
00577 
00578   }
00579 
00580   // Update task totals (session and total) and save to disk
00581   if ( !rval )
00582   {
00583     t->changeTotalTimes( t->sessionTime() + minutes, t->totalTime() + minutes );
00584     if ( ! _taskView->storage()->bookTime( t, startDateTime, minutes * 60 ) )
00585     {
00586       rval = KARM_ERR_GENERIC_SAVE_FAILED;
00587     }
00588   }
00589 
00590   return rval;
00591 }
00592 
00593 // There was something really bad going on with DCOP when I used a particular
00594 // argument name; if I recall correctly, the argument name was errno.
00595 QString MainWindow::getError( int mkb ) const
00596 {
00597   if ( mkb <= KARM_MAX_ERROR_NO ) return m_error[ mkb ];
00598   else return i18n( "Invalid error number: %1" ).arg( mkb );
00599 }
00600 
00601 int MainWindow::totalMinutesForTaskId( const QString& taskId )
00602 {
00603   int rval = 0;
00604   Task *task, *t;
00605   
00606   kdDebug(5970) << "MainWindow::totalTimeForTask( " << taskId << " )" << endl;
00607 
00608   // Find task
00609   task = _taskView->first_child();
00610   t = NULL;
00611   while ( !t && task )
00612   {
00613     t = _hasUid( task, taskId );
00614     task = task->nextSibling();
00615   }
00616   if ( t != NULL ) 
00617   {
00618     rval = t->totalTime();
00619     kdDebug(5970) << "MainWindow::totalTimeForTask - task found: rval = " << rval << endl;
00620   }
00621   else 
00622   {
00623     kdDebug(5970) << "MainWindow::totalTimeForTask - task not found" << endl;
00624     rval = KARM_ERR_UID_NOT_FOUND;
00625   }
00626 
00627   return rval;
00628 }
00629 
00630 QString MainWindow::_hasTask( Task* task, const QString &taskname ) const
00631 {
00632   QString rval = "";
00633   if ( task->name() == taskname ) 
00634   {
00635     rval = task->uid();
00636   }
00637   else
00638   {
00639     Task* nexttask = task->firstChild();
00640     while ( rval.isEmpty() && nexttask )
00641     {
00642       rval = _hasTask( nexttask, taskname );
00643       nexttask = nexttask->nextSibling();
00644     }
00645   }
00646   return rval;
00647 }
00648 
00649 Task* MainWindow::_hasUid( Task* task, const QString &uid ) const
00650 {
00651   Task *rval = NULL;
00652 
00653   //kdDebug(5970) << "MainWindow::_hasUid( " << task << ", " << uid << " )" << endl;
00654 
00655   if ( task->uid() == uid ) rval = task;
00656   else
00657   {
00658     Task* nexttask = task->firstChild();
00659     while ( !rval && nexttask )
00660     {
00661       rval = _hasUid( nexttask, uid );
00662       nexttask = nexttask->nextSibling();
00663     }
00664   }
00665   return rval;
00666 }
00667 QString MainWindow::starttimerfor( const QString& taskname )
00668 {
00669   int index;
00670   QString err="no such task";
00671   for (int i=0; i<_taskView->count(); i++)
00672   {
00673     if ((_taskView->item_at_index(i)->name()==taskname))
00674     {
00675       index=i;
00676       if (err==QString::null) err="task name is abigious";
00677       if (err=="no such task") err=QString::null;
00678     }
00679   }
00680   if (err==QString::null) _taskView->startTimerFor( _taskView->item_at_index(index) );
00681   return err;
00682 }
00683 
00684 QString MainWindow::stoptimerfor( const QString& taskname )
00685 {
00686   int index;
00687   QString err="no such task";
00688   for (int i=0; i<_taskView->count(); i++)
00689   {
00690     if ((_taskView->item_at_index(i)->name()==taskname))
00691     {
00692       index=i;
00693       if (err==QString::null) err="task name is abigious";
00694       if (err=="no such task") err=QString::null;
00695     }
00696   }
00697   if (err==QString::null) _taskView->stopTimerFor( _taskView->item_at_index(index) );
00698   return err;
00699 }
00700 
00701 QString MainWindow::exportcsvfile( QString filename, QString from, QString to, int type, bool decimalMinutes, bool allTasks, QString delimiter, QString quote )
00702 {
00703   ReportCriteria rc;
00704   rc.url=filename;
00705   rc.from=QDate::fromString( from );
00706   if ( rc.from.isNull() ) rc.from=QDate::fromString( from, Qt::ISODate );
00707   kdDebug(5970) << "rc.from " << rc.from << endl;
00708   rc.to=QDate::fromString( to );
00709   if ( rc.to.isNull() ) rc.to=QDate::fromString( to, Qt::ISODate );
00710   kdDebug(5970) << "rc.to " << rc.to << endl;
00711   rc.reportType=(ReportCriteria::REPORTTYPE) type;  // history report or totals report 
00712   rc.decimalMinutes=decimalMinutes;
00713   rc.allTasks=allTasks;
00714   rc.delimiter=delimiter;
00715   rc.quote=quote;
00716   return _taskView->report( rc );
00717 }
00718 
00719 QString MainWindow::importplannerfile( QString fileName )
00720 {
00721   return _taskView->importPlanner(fileName);
00722 }
00723 
00724 
00725 #include "mainwindow.moc"
KDE Home | KDE Accessibility Home | Description of Access Keys