• Skip to content
  • Skip to link menu
KDE 4.2 API Reference
  • KDE API Reference
  • kdepim
  • Sitemap
  • Contact Us
 

ktimetracker

main.cpp

Go to the documentation of this file.
00001 /*
00002  *     Copyright (C) 1997 by Stephan Kulow <coolo@kde.org>
00003  *
00004  *   This program is free software; you can redistribute it and/or modify
00005  *   it under the terms of the GNU General Public License as published by
00006  *   the Free Software Foundation; either version 2 of the License, or
00007  *   (at your option) any later version.
00008  *
00009  *   This program is distributed in the hope that it will be useful,
00010  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  *   GNU General Public License for more details.
00013  *
00014  *   You should have received a copy of the GNU General Public License along
00015  *   with this program; if not, write to the
00016  *      Free Software Foundation, Inc.
00017  *      51 Franklin Street, Fifth Floor
00018  *      Boston, MA  02110-1301  USA.
00019  *
00020  */
00021 
00022 #include "desktoplist.h"
00023 #include <iostream>
00024 #include <signal.h>
00025 #include <QFile>
00026 #include <KAboutData>
00027 #include <KCmdLineArgs>
00028 #include <KDebug>
00029 #include <KLocale>
00030 #include <KStandardDirs>
00031 #include <libkdepim/pimapplication.h>
00032 
00033 #include "version.h"
00034 #include "mainwindow.h"
00035 #include "mainadaptor.h"
00036 #include "karmstorage.h"
00037 #include "task.h"
00038 #include <QDebug>
00039 
00040 namespace
00041 {
00042   const char* description = I18N_NOOP("KDE Time tracker tool");
00043 
00044   void cleanup( int )
00045   {
00046     kDebug(5970) << i18n("Just caught a software interrupt.");
00047     kapp->exit();
00048   }
00049 }
00050 
00051 QString icsfile( const KCmdLineArgs* args ) // deliver the name of the iCalendar file to be used
00052 {
00053   QString result;
00054   if ( args->count() > 0 ) // file is given as parameter
00055   {
00056     result = args->arg( 0 );
00057     KUrl* icsfileurl=new KUrl(args->arg( 0 ));
00058     if (( icsfileurl->protocol() == "http" ) || ( icsfileurl->protocol() == "ftp" ) || ( icsfileurl->isLocalFile() ))
00059     {
00060       // leave as is
00061       ;
00062     }
00063     else
00064     {
00065       result = KCmdLineArgs::cwd() + '/' + result;
00066     }
00067     delete icsfileurl;
00068   }
00069   else // file is not given as parameter
00070   {
00071     result=QString(KStandardDirs::locate( "data", "ktimetracker/ktimetracker.ics" ));
00072     if ( !QFile::exists( result ) )
00073     {
00074       QFile oldFile( KStandardDirs::locate( "data", "karm/karm.ics" ) );
00075       result = KStandardDirs::locateLocal( "appdata", QString::fromLatin1( "ktimetracker.ics" ) );
00076       if ( oldFile.exists() )
00077         oldFile.copy( result );
00078     }
00079   }
00080   return result;
00081 }
00082 
00083 int main( int argc, char *argv[] )
00084 {
00085   KAboutData aboutData( "ktimetracker", 0, ki18n("KTimeTracker"),
00086       KTIMETRACKER_VERSION, ki18n(description), KAboutData::License_GPL,
00087       ki18n("(c) 1997-2008, KDE PIM Developers") );
00088 
00089   aboutData.addAuthor( ki18n("Thorsten St&auml;rk"), ki18n( "Current Maintainer" ),
00090                        "kde@staerk.de" );
00091   aboutData.addAuthor( ki18n("Sirtaj Singh Kang"), ki18n( "Original Author" ),
00092                        "taj@kde.org" );
00093   aboutData.addAuthor( ki18n("Allen Winter"),      KLocalizedString(), "winterz@verizon.net" );
00094   aboutData.addAuthor( ki18n("David Faure"),       KLocalizedString(), "faure@kde.org" );
00095   aboutData.addAuthor( ki18n("Mathias Soeken"),    KLocalizedString(), "msoeken@tzi.de" );
00096   aboutData.addAuthor( ki18n("Jesper Pedersen"),   KLocalizedString(), "blackie@kde.org" );
00097   aboutData.addAuthor( ki18n("Kalle Dalheimer"),   KLocalizedString(), "kalle@kde.org" );
00098   aboutData.addAuthor( ki18n("Mark Bucciarelli"),  KLocalizedString(), "mark@hubcapconsulting.com" );
00099   KCmdLineArgs::init( argc, argv, &aboutData );
00100 
00101   KCmdLineOptions options;
00102   options.add("+file", ki18n( "The iCalendar file to open" ));
00103   options.add("listtasknames", ki18n( "List all tasks as text output" ));
00104   options.add("addtask <taskname>", ki18n( "Add task <taskname>" ));
00105   options.add("deletetask <taskid>", ki18n( "Delete task <taskid>" ));
00106   options.add("taskidsfromname <taskname>", ki18n( "Print the task ids for all tasks named <taskname>" ));
00107   options.add("starttask <taskid>", ki18n( "Start timer for task <taskid>" ));
00108   options.add("stoptask <taskid>", ki18n( "Stop timer for task <taskid>" ));
00109   options.add("totalminutesfortaskid <taskid>", ki18n( "Deliver total minutes for task id" ));
00110   options.add("version", ki18n( "Outputs the version" ));
00111   KCmdLineArgs::addCmdLineOptions( options );
00112   KUniqueApplication::addCmdLineOptions();
00113   KCmdLineArgs *args = KCmdLineArgs::parsedArgs();
00114   int err=0;  // error code
00115   bool konsolemode=false;  // open a gui and wait for user input?
00116   if ( args->isSet("listtasknames") ) konsolemode=true;
00117   if ( !args->getOption("addtask").isEmpty() ) konsolemode=true;
00118   if ( !args->getOption("deletetask").isEmpty() ) konsolemode=true;
00119   if ( !args->getOption("taskidsfromname").isEmpty() ) konsolemode=true;
00120   if ( !args->getOption("totalminutesfortaskid").isEmpty() ) konsolemode=true;
00121   if ( !args->getOption("starttask").isEmpty() ) konsolemode=true;
00122   if ( !args->getOption("stoptask").isEmpty() ) konsolemode=true;
00123 
00124   if ( !konsolemode )
00125   {  // no konsole mode
00126     KPIM::PimApplication myApp;
00127     MainWindow *mainWindow;
00128     mainWindow = new MainWindow( icsfile( args ) );
00129     if (kapp->isSessionRestored() && KMainWindow::canBeRestored( 1 ))
00130       mainWindow->restore( 1, false );
00131     else
00132       mainWindow->show();
00133 
00134     signal( SIGQUIT, cleanup );
00135     signal( SIGINT, cleanup );
00136     args->clear();
00137     int ret = myApp.exec();
00138 
00139     delete mainWindow;
00140     return ret;
00141   }
00142   else // we are running in konsole mode
00143   {
00144     kDebug(5970) << "We are running in konsole mode";
00145     KCmdLineArgs::addCmdLineOptions( options );
00146     KApplication myApp(false);
00147     KCmdLineArgs *args = KCmdLineArgs::parsedArgs();
00148     // listtasknames
00149     if ( args->isSet("listtasknames") )
00150     {
00151       KarmStorage* sto=new KarmStorage();
00152       sto->load( 0, icsfile( args ) );
00153       QStringList tasknameslist=sto->taskNames();
00154       for ( int i=0; i<tasknameslist.count(); ++i )
00155       {
00156         char* line = tasknameslist[i].toLatin1().data();
00157         std::cout << line << std::endl;
00158       }
00159       delete sto;  // make valgrind happy 
00160     }
00161     // addtask
00162     if ( !args->getOption("addtask").isEmpty() )
00163     {
00164       KarmStorage* sto=new KarmStorage();
00165       sto->load( 0, icsfile( args ) );
00166       const QString& s=args->getOption("addtask");
00167       QVector<int> vec;
00168       vec.push_back(0);
00169       DesktopList dl=vec;
00170       Task* task=new Task( s,(long int) 0,(long int) 0, dl, 0, true );
00171       sto->addTask( task );
00172       sto->save( 0 );
00173       delete sto;
00174     }
00175     // deletetask
00176     if ( !args->getOption("deletetask").isEmpty() )
00177     {
00178       KarmStorage* sto=new KarmStorage();
00179       sto->load( 0, icsfile( args ) );
00180       const QString& taskid=args->getOption("deletetask");
00181       sto->removeTask( taskid );
00182       delete sto;
00183     }
00184     // taskidsfromname
00185     if ( !args->getOption("taskidsfromname").isEmpty() )
00186     {
00187       KarmStorage* sto=new KarmStorage();
00188       sto->load( 0, icsfile( args ) );
00189       const QString& taskname=args->getOption("taskidsfromname");
00190       QStringList taskids=sto->taskidsfromname( taskname );
00191       for ( int i=0; i<taskids.count(); ++i )
00192       {
00193         char* line = taskids[i].toLatin1().data();
00194         std::cout << line << std::endl;
00195       }
00196       delete sto;
00197     }
00198     // totalminutesfortaskid
00199     if ( !args->getOption("totalminutesfortaskid").isEmpty() )
00200     {
00201       KarmStorage* sto=new KarmStorage();
00202       sto->load( 0, icsfile( args ) );
00203       Task* task=sto->task( args->getOption("totalminutesfortaskid"), 0 );
00204       if (task!=0)
00205       {
00206         kDebug(5970) << "taskname=" << task->name();
00207         std::cout << task->totalTime();
00208       }
00209       delete sto;
00210     }
00211     // starttask
00212     if ( !args->getOption("starttask").isEmpty() )
00213     {
00214       KarmStorage* sto=new KarmStorage();
00215       sto->load( 0, icsfile( args ) );
00216       sto->startTimer(args->getOption("starttask"));
00217       delete sto;
00218     }
00219     // stoptask
00220     if ( !args->getOption("stoptask").isEmpty() )
00221     {
00222       KarmStorage* sto=new KarmStorage();
00223       sto->load( 0, icsfile( args ) );
00224       sto->stopTimer(sto->task( args->getOption("stoptask"), 0 ));
00225       delete sto;
00226     }
00227     args->clear();
00228   }
00229   return err;
00230 }
00231 

ktimetracker

Skip menu "ktimetracker"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Class Members

kdepim

Skip menu "kdepim"
  • akonadi
  •   clients
  •   kabc
  •   kcal
  •   kcm
  • akregator
  • console
  •   kabcclient
  •   konsolekalendar
  • kaddressbook
  • kalarm
  •   lib
  • kdgantt
  • kdgantt1
  • kjots
  • kleopatra
  • kmail
  • kmobiletools
  • knode
  • knotes
  • kontact
  • kontactinterfaces
  • korganizer
  •   korgac
  • kpilot
  • ktimetracker
  •   doc
  • libkdepim
  • libkholidays
  • libkleo
  • libkpgp
  • maildir
Generated for kdepim by doxygen 1.5.4
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal