27 #include <KCmdLineArgs> 
   30 #include <KStandardDirs> 
   31 #include <kontactinterface/pimuniqueapplication.h> 
   32 #include <kuniqueapplication.h> 
   34 #include "kdepim-version.h" 
   36 #include "mainadaptor.h" 
   43     const char* description = I18N_NOOP(
"KDE Time tracker tool");
 
   47         kDebug(5970) << i18n(
"Just caught a software interrupt.");
 
   55     if ( args->count() > 0 ) 
 
   57         result = args->
arg( 0 );
 
   58         KUrl* icsfileurl=
new KUrl(args->arg( 0 ));
 
   59         if (( icsfileurl->protocol() == 
"http" ) || ( icsfileurl->protocol() == 
"ftp" ) || ( icsfileurl->isLocalFile() ))
 
   66             result = KCmdLineArgs::cwd() + 
'/' + result;
 
   72         result=
QString(KStandardDirs::locate( 
"data", 
"ktimetracker/ktimetracker.ics" ));
 
   75             QFile oldFile( KStandardDirs::locate( 
"data", 
"karm/karm.ics" ) );
 
   76             result = KStandardDirs::locateLocal( 
"appdata", 
QString::fromLatin1( 
"ktimetracker.ics" ) );
 
   78                 oldFile.
copy( result );
 
   84 int main( 
int argc, 
char *argv[] )
 
   86     KAboutData aboutData( 
"ktimetracker", 0, ki18n(
"KTimeTracker"),
 
   87         KDEPIM_VERSION, ki18n(description), KAboutData::License_GPL,
 
   88         ki18n(
"Copyright © 1997-2012 KDE PIM authors"), KLocalizedString(),
 
   89         QByteArray(
"http://userbase.kde.org/KTimeTracker") );
 
   91     aboutData.addAuthor( ki18n(
"Thorsten Stärk"), ki18n( 
"Current Maintainer" ),
 
   93     aboutData.addAuthor( ki18n(
"Sirtaj Singh Kang"), ki18n( 
"Original Author" ),
 
   95     aboutData.addAuthor( ki18n(
"Allen Winter"),      KLocalizedString(), 
"winter@kde.org" );
 
   96     aboutData.addAuthor( ki18n(
"David Faure"),       KLocalizedString(), 
"faure@kde.org" );
 
   97     aboutData.addAuthor( ki18n(
"Mathias Soeken"),    KLocalizedString(), 
"msoeken@tzi.de" );
 
   98     aboutData.addAuthor( ki18n(
"Jesper Pedersen"),   KLocalizedString(), 
"blackie@kde.org" );
 
   99     aboutData.addAuthor( ki18n(
"Kalle Dalheimer"),   KLocalizedString(), 
"kalle@kde.org" );
 
  100     aboutData.addAuthor( ki18n(
"Mark Bucciarelli"),  KLocalizedString(), 
"mark@hubcapconsulting.com" );
 
  101     KCmdLineArgs::init( argc, argv, &aboutData );
 
  103     KCmdLineOptions options;
 
  104     options.add(
"+file", ki18n( 
"The iCalendar file to open" ));
 
  105     options.add(
"listtasknames", ki18n( 
"List all tasks as text output" ));
 
  106     options.add(
"addtask <taskname>", ki18n( 
"Add task <taskname>" ));
 
  107     options.add(
"deletetask <taskid>", ki18n( 
"Delete task <taskid>" ));
 
  108     options.add(
"taskidsfromname <taskname>", ki18n( 
"Print the task ids for all tasks named <taskname>" ));
 
  109     options.add(
"starttask <taskid>", ki18n( 
"Start timer for task <taskid>" ));
 
  110     options.add(
"stoptask <taskid>", ki18n( 
"Stop timer for task <taskid>" ));
 
  111     options.add(
"totalminutesfortaskid <taskid>", ki18n( 
"Deliver total minutes for task id" ));
 
  112     options.add(
"version", ki18n( 
"Outputs the version" ));
 
  113     KCmdLineArgs::addCmdLineOptions( options );
 
  114     KCmdLineArgs *args = KCmdLineArgs::parsedArgs();
 
  116     bool konsolemode=
false;  
 
  117     if ( args->isSet(
"listtasknames") ) konsolemode=
true;
 
  118     if ( !args->getOption(
"addtask").isEmpty() ) konsolemode=
true;
 
  119     if ( !args->getOption(
"deletetask").isEmpty() ) konsolemode=
true;
 
  120     if ( !args->getOption(
"taskidsfromname").isEmpty() ) konsolemode=
true;
 
  121     if ( !args->getOption(
"totalminutesfortaskid").isEmpty() ) konsolemode=
true;
 
  122     if ( !args->getOption(
"starttask").isEmpty() ) konsolemode=
true;
 
  123     if ( !args->getOption(
"stoptask").isEmpty() ) konsolemode=
true;
 
  127         if (!KUniqueApplication::start()) {
 
  128             kDebug(5970) << 
"Other instance is already running, exiting!";
 
  131         KUniqueApplication myApp;
 
  134         if (kapp->isSessionRestored() && KMainWindow::canBeRestored( 1 ))
 
  135             mainWindow->restore( 1, 
false );
 
  139         signal( SIGQUIT, cleanup );
 
  140         signal( SIGINT, cleanup );
 
  142         int ret = myApp.exec();
 
  149         kDebug(5970) << 
"We are running in konsole mode";
 
  150         KCmdLineArgs::addCmdLineOptions( options );
 
  151         KApplication myApp(
false);
 
  152         KCmdLineArgs *args = KCmdLineArgs::parsedArgs();
 
  154         if ( args->isSet(
"listtasknames") )
 
  159             for ( 
int i=0; i<tasknameslist.
count(); ++i )
 
  161                 char* line = tasknameslist[i].toLatin1().data();
 
  162                 std::cout << line << std::endl;
 
  167         if ( !args->getOption(
"addtask").isEmpty() )
 
  171             const QString& s=args->getOption(
"addtask");
 
  174             Task* task=
new Task( s, 
QString(), (
long int) 0,(
long int) 0, dl, 0, 
true );
 
  180         if ( !args->getOption(
"deletetask").isEmpty() )
 
  184             const QString& taskid=args->getOption(
"deletetask");
 
  189         if ( !args->getOption(
"taskidsfromname").isEmpty() )
 
  193             const QString& taskname=args->getOption(
"taskidsfromname");
 
  195             for ( 
int i=0; i<taskids.
count(); ++i )
 
  197                 char* line = taskids[i].toLatin1().data();
 
  198                 std::cout << line << std::endl;
 
  203         if ( !args->getOption(
"totalminutesfortaskid").isEmpty() )
 
  207             Task* task=sto->
task( args->getOption(
"totalminutesfortaskid"), 0 );
 
  210                 kDebug(5970) << 
"taskname=" << task->
name();
 
  216         if ( !args->getOption(
"starttask").isEmpty() )
 
  220             sto->
startTimer(args->getOption(
"starttask"));
 
  224         if ( !args->getOption(
"stoptask").isEmpty() )
 
void startTimer(const Task *task, const KDateTime &when=KDateTime::currentLocalDateTime())
Log the event that a timer has started for a task. 
QString name() const 
returns the name of this task. 
QStringList taskidsfromname(QString taskname)
Return a list of all task ids for taskname. 
bool copy(const QString &newName)
int count(const T &value) const
bool removeTask(Task *task)
Remove this task from iCalendar file. 
void stopTimer(const Task *task, const QDateTime &when=QDateTime::currentDateTime())
Log the event that the timer has stopped for this task. 
Task * task(const QString &uid, TaskView *view)
Find the task with the given uid. 
QString fromLatin1(const char *str, int size)
QString save(TaskView *taskview)
Save all tasks and their totals to an iCalendar file. 
QString icsfile(const KCmdLineArgs *args)
QString addTask(const Task *task, const Task *parent=0)
Add this task from iCalendar file. 
int main(int argc, char *argv[])
A class representing a task. 
QString arg(qlonglong a, int fieldWidth, int base, const QChar &fillChar) const
QStringList taskNames() const 
Return a list of all task names. 
QString load(TaskView *taskview, const QString &fileName)
Load the list view with tasks read from iCalendar file. 
Main window to tie the application together. 
Class to store/retrieve KTimeTracker data to/from persistent storage.