27 #include <KCmdLineArgs>
30 #include <KStandardDirs>
31 #include <kontactinterface/pimuniqueapplication.h>
35 #include "mainadaptor.h"
42 const char* description = I18N_NOOP(
"KDE Time tracker tool");
46 kDebug(5970) << i18n(
"Just caught a software interrupt.");
51 QString
icsfile(
const KCmdLineArgs* args )
54 if ( args->count() > 0 )
56 result = args->arg( 0 );
57 KUrl* icsfileurl=
new KUrl(args->arg( 0 ));
58 if (( icsfileurl->protocol() ==
"http" ) || ( icsfileurl->protocol() ==
"ftp" ) || ( icsfileurl->isLocalFile() ))
65 result = KCmdLineArgs::cwd() +
'/' + result;
71 result=QString(KStandardDirs::locate(
"data",
"ktimetracker/ktimetracker.ics" ));
72 if ( !QFile::exists( result ) )
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 );
83 int main(
int argc,
char *argv[] )
85 KAboutData aboutData(
"ktimetracker", 0, ki18n(
"KTimeTracker"),
86 KTIMETRACKER_VERSION, ki18n(description), KAboutData::License_GPL,
87 ki18n(
"(c) 1997-2010, KDE PIM Developers") );
89 aboutData.addAuthor( ki18n(
"Thorsten Stärk"), ki18n(
"Current Maintainer" ),
91 aboutData.addAuthor( ki18n(
"Sirtaj Singh Kang"), ki18n(
"Original Author" ),
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 );
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();
115 bool konsolemode=
false;
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;
126 KontactInterface::PimUniqueApplication myApp;
134 signal( SIGQUIT, cleanup );
135 signal( SIGINT, cleanup );
137 int ret = myApp.exec();
144 kDebug(5970) <<
"We are running in konsole mode";
145 KCmdLineArgs::addCmdLineOptions( options );
146 KApplication myApp(
false);
147 KCmdLineArgs *args = KCmdLineArgs::parsedArgs();
149 if ( args->isSet(
"listtasknames") )
153 QStringList tasknameslist=sto->
taskNames();
154 for (
int i=0; i<tasknameslist.count(); ++i )
156 char* line = tasknameslist[i].toLatin1().data();
157 std::cout << line << std::endl;
162 if ( !args->getOption(
"addtask").isEmpty() )
166 const QString& s=args->getOption(
"addtask");
170 Task* task=
new Task( s,(
long int) 0,(
long int) 0, dl, 0,
true );
176 if ( !args->getOption(
"deletetask").isEmpty() )
180 const QString& taskid=args->getOption(
"deletetask");
185 if ( !args->getOption(
"taskidsfromname").isEmpty() )
189 const QString& taskname=args->getOption(
"taskidsfromname");
191 for (
int i=0; i<taskids.count(); ++i )
193 char* line = taskids[i].toLatin1().data();
194 std::cout << line << std::endl;
199 if ( !args->getOption(
"totalminutesfortaskid").isEmpty() )
203 Task* task=sto->
task( args->getOption(
"totalminutesfortaskid"), 0 );
206 kDebug(5970) <<
"taskname=" << task->
name();
212 if ( !args->getOption(
"starttask").isEmpty() )
216 sto->
startTimer(args->getOption(
"starttask"));
220 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.
int main(int argc, char *argv[])
QStringList taskidsfromname(QString taskname)
Return a list of all task ids for taskname.
bool removeTask(Task *task)
Remove this task from iCalendar file.
QString icsfile(const KCmdLineArgs *args)
QVector< int > DesktopList
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 save(TaskView *taskview)
Save all tasks and their totals to an iCalendar file.
QString addTask(const Task *task, const Task *parent=0)
Add this task from iCalendar file.
A class representing a task.
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.