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

ktimetracker

  • sources
  • kde-4.12
  • kdepim
  • ktimetracker
  • new
new/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 
33 #include "version.h"
34 #include "mainwindow.h"
35 #include "mainadaptor.h"
36 #include "timetrackerstorage.h"
37 #include "task.h"
38 #include <QDebug>
39 
40 namespace
41 {
42  const char* description = I18N_NOOP("KDE Time tracker tool");
43 
44  void cleanup( int )
45  {
46  kDebug(5970) << i18n("Just caught a software interrupt.");
47  kapp->exit();
48  }
49 }
50 
51 QString icsfile( const KCmdLineArgs* args ) // deliver the name of the iCalendar file to be used
52 {
53  QString result;
54  if ( args->count() > 0 ) // file is given as parameter
55  {
56  result = args->arg( 0 );
57  KUrl* icsfileurl=new KUrl(args->arg( 0 ));
58  if (( icsfileurl->protocol() == "http" ) || ( icsfileurl->protocol() == "ftp" ) || ( icsfileurl->isLocalFile() ))
59  {
60  // leave as is
61  ;
62  }
63  else
64  {
65  result = KCmdLineArgs::cwd() + '/' + result;
66  }
67  delete icsfileurl;
68  }
69  else // file is not given as parameter
70  {
71  result=QString(KStandardDirs::locate( "data", "ktimetracker/ktimetracker.ics" ));
72  if ( !QFile::exists( result ) )
73  {
74  QFile oldFile( KStandardDirs::locate( "data", "karm/karm.ics" ) );
75  result = KStandardDirs::locateLocal( "appdata", QString::fromLatin1( "ktimetracker.ics" ) );
76  if ( oldFile.exists() )
77  oldFile.copy( result );
78  }
79  }
80  return result;
81 }
82 
83 int main( int argc, char *argv[] )
84 {
85  KAboutData aboutData( "ktimetracker", 0, ki18n("KTimeTracker"),
86  KTIMETRACKER_VERSION, ki18n(description), KAboutData::License_GPL,
87  ki18n("(c) 1997-2010, KDE PIM Developers") );
88 
89  aboutData.addAuthor( ki18n("Thorsten St&auml;rk"), ki18n( "Current Maintainer" ),
90  "kde@staerk.de" );
91  aboutData.addAuthor( ki18n("Sirtaj Singh Kang"), ki18n( "Original Author" ),
92  "taj@kde.org" );
93  aboutData.addAuthor( ki18n("Allen Winter"), KLocalizedString(), "winter@kde.org" );
94  aboutData.addAuthor( ki18n("David Faure"), KLocalizedString(), "faure@kde.org" );
95  aboutData.addAuthor( ki18n("Mathias Soeken"), KLocalizedString(), "msoeken@tzi.de" );
96  aboutData.addAuthor( ki18n("Jesper Pedersen"), KLocalizedString(), "blackie@kde.org" );
97  aboutData.addAuthor( ki18n("Kalle Dalheimer"), KLocalizedString(), "kalle@kde.org" );
98  aboutData.addAuthor( ki18n("Mark Bucciarelli"), KLocalizedString(), "mark@hubcapconsulting.com" );
99  KCmdLineArgs::init( argc, argv, &aboutData );
100 
101  KCmdLineOptions options;
102  options.add("+file", ki18n( "The iCalendar file to open" ));
103  options.add("listtasknames", ki18n( "List all tasks as text output" ));
104  options.add("addtask <taskname>", ki18n( "Add task <taskname>" ));
105  options.add("deletetask <taskid>", ki18n( "Delete task <taskid>" ));
106  options.add("taskidsfromname <taskname>", ki18n( "Print the task ids for all tasks named <taskname>" ));
107  options.add("starttask <taskid>", ki18n( "Start timer for task <taskid>" ));
108  options.add("stoptask <taskid>", ki18n( "Stop timer for task <taskid>" ));
109  options.add("totalminutesfortaskid <taskid>", ki18n( "Deliver total minutes for task id" ));
110  options.add("version", ki18n( "Outputs the version" ));
111  KCmdLineArgs::addCmdLineOptions( options );
112  KUniqueApplication::addCmdLineOptions();
113  KCmdLineArgs *args = KCmdLineArgs::parsedArgs();
114  int err=0; // error code
115  bool konsolemode=false; // open a gui and wait for user input?
116  if ( args->isSet("listtasknames") ) konsolemode=true;
117  if ( !args->getOption("addtask").isEmpty() ) konsolemode=true;
118  if ( !args->getOption("deletetask").isEmpty() ) konsolemode=true;
119  if ( !args->getOption("taskidsfromname").isEmpty() ) konsolemode=true;
120  if ( !args->getOption("totalminutesfortaskid").isEmpty() ) konsolemode=true;
121  if ( !args->getOption("starttask").isEmpty() ) konsolemode=true;
122  if ( !args->getOption("stoptask").isEmpty() ) konsolemode=true;
123 
124  if ( !konsolemode )
125  { // no konsole mode
126  KontactInterface::PimUniqueApplication myApp;
127  MainWindow *mainWindow;
128  mainWindow = new MainWindow( icsfile( args ) );
129  // if (kapp->isSessionRestored() && KMainWindow::canBeRestored( 1 ))
130  // mainWindow->restore( 1, false );
131  //else
132  mainWindow->show();
133 
134  signal( SIGQUIT, cleanup );
135  signal( SIGINT, cleanup );
136  args->clear();
137  int ret = myApp.exec();
138 
139  delete mainWindow;
140  return ret;
141  }
142  else // we are running in konsole mode
143  {
144  kDebug(5970) << "We are running in konsole mode";
145  KCmdLineArgs::addCmdLineOptions( options );
146  KApplication myApp(false);
147  KCmdLineArgs *args = KCmdLineArgs::parsedArgs();
148  // listtasknames
149  if ( args->isSet("listtasknames") )
150  {
151  timetrackerstorage* sto=new timetrackerstorage();
152  sto->load( 0, icsfile( args ) );
153  QStringList tasknameslist=sto->taskNames();
154  for ( int i=0; i<tasknameslist.count(); ++i )
155  {
156  char* line = tasknameslist[i].toLatin1().data();
157  std::cout << line << std::endl;
158  }
159  delete sto; // make valgrind happy
160  }
161  // addtask
162  if ( !args->getOption("addtask").isEmpty() )
163  {
164  timetrackerstorage* sto=new timetrackerstorage();
165  sto->load( 0, icsfile( args ) );
166  const QString& s=args->getOption("addtask");
167  QVector<int> vec;
168  vec.push_back(0);
169  DesktopList dl=vec;
170  Task* task=new Task( s,(long int) 0,(long int) 0, dl, 0, true );
171  sto->addTask( task );
172  sto->save( 0 );
173  delete sto;
174  }
175  // deletetask
176  if ( !args->getOption("deletetask").isEmpty() )
177  {
178  timetrackerstorage* sto=new timetrackerstorage();
179  sto->load( 0, icsfile( args ) );
180  const QString& taskid=args->getOption("deletetask");
181  sto->removeTask( taskid );
182  delete sto;
183  }
184  // taskidsfromname
185  if ( !args->getOption("taskidsfromname").isEmpty() )
186  {
187  timetrackerstorage* sto=new timetrackerstorage();
188  sto->load( 0, icsfile( args ) );
189  const QString& taskname=args->getOption("taskidsfromname");
190  QStringList taskids=sto->taskidsfromname( taskname );
191  for ( int i=0; i<taskids.count(); ++i )
192  {
193  char* line = taskids[i].toLatin1().data();
194  std::cout << line << std::endl;
195  }
196  delete sto;
197  }
198  // totalminutesfortaskid
199  if ( !args->getOption("totalminutesfortaskid").isEmpty() )
200  {
201  timetrackerstorage* sto=new timetrackerstorage();
202  sto->load( 0, icsfile( args ) );
203  Task* task=sto->task( args->getOption("totalminutesfortaskid"), 0 );
204  if (task!=0)
205  {
206  kDebug(5970) << "taskname=" << task->name();
207  std::cout << task->totalTime();
208  }
209  delete sto;
210  }
211  // starttask
212  if ( !args->getOption("starttask").isEmpty() )
213  {
214  timetrackerstorage* sto=new timetrackerstorage();
215  sto->load( 0, icsfile( args ) );
216  sto->startTimer(args->getOption("starttask"));
217  delete sto;
218  }
219  // stoptask
220  if ( !args->getOption("stoptask").isEmpty() )
221  {
222  timetrackerstorage* sto=new timetrackerstorage();
223  sto->load( 0, icsfile( args ) );
224  sto->stopTimer(sto->task( args->getOption("stoptask"), 0 ));
225  delete sto;
226  }
227  args->clear();
228  }
229  return err;
230 }
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:680
main
int main(int argc, char *argv[])
Definition: new/main.cpp:83
timetrackerstorage::taskidsfromname
QStringList taskidsfromname(QString taskname)
Return a list of all task ids for taskname.
Definition: timetrackerstorage.cpp:470
desktoplist.h
timetrackerstorage::removeTask
bool removeTask(Task *task)
Remove this task from iCalendar file.
Definition: timetrackerstorage.cpp:510
icsfile
QString icsfile(const KCmdLineArgs *args)
Definition: new/main.cpp:51
DesktopList
QVector< int > DesktopList
Definition: desktoplist.h:28
task.h
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
timetrackerstorage::save
QString save(TaskView *taskview)
Save all tasks and their totals to an iCalendar file.
Definition: timetrackerstorage.cpp:367
timetrackerstorage::addTask
QString addTask(const Task *task, const Task *parent=0)
Add this task from iCalendar file.
Definition: timetrackerstorage.cpp:442
mainwindow.h
Task
A class representing a task.
Definition: task.h:54
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-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:55:10 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

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