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

ktimetracker

  • sources
  • kde-4.14
  • kdepim
  • ktimetracker
main.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (C) 1997 by Stephan Kulow <coolo@kde.org>
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License along
15  * with this program; if not, write to the
16  * Free Software Foundation, Inc.
17  * 51 Franklin Street, Fifth Floor
18  * Boston, MA 02110-1301 USA.
19  *
20  */
21 
22 #include "desktoplist.h"
23 #include <iostream>
24 #include <signal.h>
25 #include <QFile>
26 #include <KAboutData>
27 #include <KCmdLineArgs>
28 #include <KDebug>
29 #include <KLocale>
30 #include <KStandardDirs>
31 #include <kontactinterface/pimuniqueapplication.h>
32 #include <kuniqueapplication.h>
33 
34 #include "kdepim-version.h"
35 #include "mainwindow.h"
36 #include "mainadaptor.h"
37 #include "timetrackerstorage.h"
38 #include "task.h"
39 #include <QDebug>
40 
41 namespace
42 {
43  const char* description = I18N_NOOP("KDE Time tracker tool");
44 
45  void cleanup( int )
46  {
47  kDebug(5970) << i18n("Just caught a software interrupt.");
48  kapp->exit();
49  }
50 }
51 
52 QString icsfile( const KCmdLineArgs* args ) // deliver the name of the iCalendar file to be used
53 {
54  QString result;
55  if ( args->count() > 0 ) // file is given as parameter
56  {
57  result = args->arg( 0 );
58  KUrl* icsfileurl=new KUrl(args->arg( 0 ));
59  if (( icsfileurl->protocol() == "http" ) || ( icsfileurl->protocol() == "ftp" ) || ( icsfileurl->isLocalFile() ))
60  {
61  // leave as is
62  ;
63  }
64  else
65  {
66  result = KCmdLineArgs::cwd() + '/' + result;
67  }
68  delete icsfileurl;
69  }
70  else // file is not given as parameter
71  {
72  result=QString(KStandardDirs::locate( "data", "ktimetracker/ktimetracker.ics" ));
73  if ( !QFile::exists( result ) )
74  {
75  QFile oldFile( KStandardDirs::locate( "data", "karm/karm.ics" ) );
76  result = KStandardDirs::locateLocal( "appdata", QString::fromLatin1( "ktimetracker.ics" ) );
77  if ( oldFile.exists() )
78  oldFile.copy( result );
79  }
80  }
81  return result;
82 }
83 
84 int main( int argc, char *argv[] )
85 {
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") );
90 
91  aboutData.addAuthor( ki18n("Thorsten Stärk"), ki18n( "Current Maintainer" ),
92  "kde@staerk.de" );
93  aboutData.addAuthor( ki18n("Sirtaj Singh Kang"), ki18n( "Original Author" ),
94  "taj@kde.org" );
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 );
102 
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();
115  int err=0; // error code
116  bool konsolemode=false; // open a gui and wait for user input?
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;
124 
125  if ( !konsolemode )
126  { // no konsole mode
127  if (!KUniqueApplication::start()) {
128  kDebug(5970) << "Other instance is already running, exiting!";
129  return 0;
130  }
131  KUniqueApplication myApp;
132  MainWindow *mainWindow;
133  mainWindow = new MainWindow( icsfile( args ) );
134  if (kapp->isSessionRestored() && KMainWindow::canBeRestored( 1 ))
135  mainWindow->restore( 1, false );
136  else
137  mainWindow->show();
138 
139  signal( SIGQUIT, cleanup );
140  signal( SIGINT, cleanup );
141  args->clear();
142  int ret = myApp.exec();
143 
144  delete mainWindow;
145  return ret;
146  }
147  else // we are running in konsole mode
148  {
149  kDebug(5970) << "We are running in konsole mode";
150  KCmdLineArgs::addCmdLineOptions( options );
151  KApplication myApp(false);
152  KCmdLineArgs *args = KCmdLineArgs::parsedArgs();
153  // listtasknames
154  if ( args->isSet("listtasknames") )
155  {
156  timetrackerstorage* sto=new timetrackerstorage();
157  sto->load( 0, icsfile( args ) );
158  QStringList tasknameslist=sto->taskNames();
159  for ( int i=0; i<tasknameslist.count(); ++i )
160  {
161  char* line = tasknameslist[i].toLatin1().data();
162  std::cout << line << std::endl;
163  }
164  delete sto; // make valgrind happy
165  }
166  // addtask
167  if ( !args->getOption("addtask").isEmpty() )
168  {
169  timetrackerstorage* sto=new timetrackerstorage();
170  sto->load( 0, icsfile( args ) );
171  const QString& s=args->getOption("addtask");
172  QVector<int> vec;
173  DesktopList dl=vec;
174  Task* task=new Task( s, QString(), (long int) 0,(long int) 0, dl, 0, true );
175  sto->addTask( task );
176  sto->save( 0 );
177  delete sto;
178  }
179  // deletetask
180  if ( !args->getOption("deletetask").isEmpty() )
181  {
182  timetrackerstorage* sto=new timetrackerstorage();
183  sto->load( 0, icsfile( args ) );
184  const QString& taskid=args->getOption("deletetask");
185  sto->removeTask( taskid );
186  delete sto;
187  }
188  // taskidsfromname
189  if ( !args->getOption("taskidsfromname").isEmpty() )
190  {
191  timetrackerstorage* sto=new timetrackerstorage();
192  sto->load( 0, icsfile( args ) );
193  const QString& taskname=args->getOption("taskidsfromname");
194  QStringList taskids=sto->taskidsfromname( taskname );
195  for ( int i=0; i<taskids.count(); ++i )
196  {
197  char* line = taskids[i].toLatin1().data();
198  std::cout << line << std::endl;
199  }
200  delete sto;
201  }
202  // totalminutesfortaskid
203  if ( !args->getOption("totalminutesfortaskid").isEmpty() )
204  {
205  timetrackerstorage* sto=new timetrackerstorage();
206  sto->load( 0, icsfile( args ) );
207  Task* task=sto->task( args->getOption("totalminutesfortaskid"), 0 );
208  if (task!=0)
209  {
210  kDebug(5970) << "taskname=" << task->name();
211  std::cout << task->totalTime();
212  }
213  delete sto;
214  }
215  // starttask
216  if ( !args->getOption("starttask").isEmpty() )
217  {
218  timetrackerstorage* sto=new timetrackerstorage();
219  sto->load( 0, icsfile( args ) );
220  sto->startTimer(args->getOption("starttask"));
221  delete sto;
222  }
223  // stoptask
224  if ( !args->getOption("stoptask").isEmpty() )
225  {
226  timetrackerstorage* sto=new timetrackerstorage();
227  sto->load( 0, icsfile( args ) );
228  sto->stopTimer(sto->task( args->getOption("stoptask"), 0 ));
229  delete sto;
230  }
231  args->clear();
232  }
233  return err;
234 }
timetrackerstorage::startTimer
void startTimer(const Task *task, const KDateTime &when=KDateTime::currentLocalDateTime())
Log the event that a timer has started for a task.
Definition: timetrackerstorage.cpp:897
Task::name
QString name() const
returns the name of this task.
Definition: task.cpp:695
QByteArray
timetrackerstorage::taskidsfromname
QStringList taskidsfromname(QString taskname)
Return a list of all task ids for taskname.
Definition: timetrackerstorage.cpp:470
QFile::exists
bool exists() const
QFile
QFile::copy
bool copy(const QString &newName)
desktoplist.h
QList::count
int count(const T &value) const
mainwindow.h
timetrackerstorage::removeTask
bool removeTask(Task *task)
Remove this task from iCalendar file.
Definition: timetrackerstorage.cpp:510
QString
QStringList
task.h
QVector< int >
timetrackerstorage::stopTimer
void stopTimer(const Task *task, const QDateTime &when=QDateTime::currentDateTime())
Log the event that the timer has stopped for this task.
Definition: timetrackerstorage.cpp:929
timetrackerstorage::task
Task * task(const QString &uid, TaskView *view)
Find the task with the given uid.
Definition: timetrackerstorage.cpp:208
QString::fromLatin1
QString fromLatin1(const char *str, int size)
QWidget::show
void show()
timetrackerstorage::save
QString save(TaskView *taskview)
Save all tasks and their totals to an iCalendar file.
Definition: timetrackerstorage.cpp:367
icsfile
QString icsfile(const KCmdLineArgs *args)
Definition: main.cpp:52
timetrackerstorage::addTask
QString addTask(const Task *task, const Task *parent=0)
Add this task from iCalendar file.
Definition: timetrackerstorage.cpp:442
main
int main(int argc, char *argv[])
Definition: main.cpp:84
Task
A class representing a task.
Definition: task.h:54
QString::arg
QString arg(qlonglong a, int fieldWidth, int base, const QChar &fillChar) const
timetrackerstorage::taskNames
QStringList taskNames() const
Return a list of all task names.
Definition: timetrackerstorage.cpp:484
timetrackerstorage.h
timetrackerstorage::load
QString load(TaskView *taskview, const QString &fileName)
Load the list view with tasks read from iCalendar file.
Definition: timetrackerstorage.cpp:99
MainWindow
Main window to tie the application together.
Definition: mainwindow.h:43
timetrackerstorage
Class to store/retrieve KTimeTracker data to/from persistent storage.
Definition: timetrackerstorage.h:57
Task::totalTime
long totalTime() const
Definition: task.h:206
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:31:34 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

ktimetracker

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

kdepim API Reference

Skip menu "kdepim API Reference"
  • akonadi_next
  • akregator
  • blogilo
  • calendarsupport
  • console
  •   kabcclient
  •   konsolekalendar
  • kaddressbook
  • kalarm
  •   lib
  • kdgantt2
  • kjots
  • kleopatra
  • kmail
  • knode
  • knotes
  • kontact
  • korgac
  • korganizer
  • ktimetracker
  • libkdepim
  • libkleo
  • libkpgp
  • mailcommon
  • messagelist
  • messageviewer
  • pimprint

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal