karm

karmstorage.h
1/*
2 * This file only:
3 * Copyright (C) 2003 Mark Bucciarelli <mark@hubcapconsutling.com>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the
17 * Free Software Foundation, Inc.
18 * 51 Franklin Street, Fifth Floor
19 * Boston, MA 02110-1301 USA.
20 *
21 */
22
23#ifndef KARM_STORAGE_H
24#define KARM_STORAGE_H
25
26#include <tqdict.h>
27#include <tqptrstack.h>
28
29#include "journal.h"
30#include "reportcriteria.h"
31
32#include "desktoplist.h"
33
34#include <calendarresources.h>
35#include <vector>
36#include "resourcecalendar.h"
37#include <tdemacros.h>
38
39class TQDateTime;
40class Preferences;
41class Task;
42class TaskView;
43class HistoryEvent;
44
68{
69 public:
70 /*
71 * Return reference to storage singleton.
72 *
73 * The constructors are private, so this must be used to create a
74 * KarmStorage instance.
75 */
76 static KarmStorage *instance();
77
78 /*
79 * Load the list view with tasks read from iCalendar file.
80 *
81 * Parses iCalendar file, builds list view items in the proper
82 * hierarchy, and loads them into the list view widget.
83 *
84 * If the file name passed in is the same as the last file name that was
85 * loaded, this method does nothing.
86 *
87 * This method considers any of the following conditions errors:
88 *
89 * @li the iCalendar file does not exist
90 * @li the iCalendar file is not readable
91 * @li the list group currently has list items
92 * @li an iCalendar todo has no related to attribute
93 * @li a todo is related to another todo which does not exist
94 *
95 * @param taskview The list group used in the TaskView
96 * @param preferences The current KArm preferences.
97 * @param fileName Override preferences' filename
98 *
99 * @return empty string if success, error message if error.
100 *
101 */
102 TQString load(TaskView* taskview, const Preferences* preferences, TQString fileName="" );
103
104 /*
105 * Return the name of the iCal file
106 */
107 TQString icalfile();
108
109 /*
110 * Build up the taskview.
111 *
112 * This is needed if the iCal file has been modified
113 */
114 TQString buildTaskView(KCal::ResourceCalendar *rc, TaskView *view);
115
116 /* Close calendar and clear view. Release lock if holding one. */
117 void closeStorage(TaskView* view);
118
119 /*
120 * Save all tasks and their totals to an iCalendar file.
121 *
122 * All tasks must have an associated VTODO object already created in the
123 * calendar file; that is, the task->uid() must refer to a valid VTODO in
124 * the calender.
125 * Delivers empty string if successful, else error msg.
126 *
127 * @param taskview The list group used in the TaskView
128 */
129 TQString save(TaskView* taskview);
130
144 TQString loadFromFlatFile(TaskView* taskview, const TQString& filename);
145
154 TQString loadFromFlatFileCumulative(TaskView* taskview,
155 const TQString& filename);
156
160 TQString report( TaskView *taskview, const ReportCriteria &rc );
161
187 void changeTime(const Task* task, const long deltaSeconds);
188
205 bool bookTime(const Task* task, const TQDateTime& startDateTime,
206 long durationInSeconds);
207
219 void setName(const Task* task, const TQString& oldname) { Q_UNUSED(task); Q_UNUSED(oldname); }
220
221
230 void startTimer(const Task* task) { Q_UNUSED(task); }
231
241 void stopTimer(const Task* task, TQDateTime when=TQDateTime::currentDateTime());
242
252 void addComment(const Task* task, const TQString& comment);
253
254
263 bool removeTask(Task* task);
264
277 TQString addTask(const Task* task, const Task* parent);
278
284 bool isEmpty();
285
296 bool isNewStorage(const Preferences* preferences) const;
297
299 TQValueList<HistoryEvent> getHistory(const TQDate& from, const TQDate& to);
300
301 private:
302 static KarmStorage *_instance;
303 KCal::ResourceCalendar *_calendar;
304 TQString _icalfile;
305
306 KarmStorage();
307 void adjustFromLegacyFileFormat(Task* task);
308 bool parseLine(TQString line, long *time, TQString *name, int *level,
309 DesktopList* desktopList);
310 TQString writeTaskAsTodo
311 (Task* task, const int level, TQPtrStack< KCal::Todo >& parents);
312 bool saveCalendar();
313
314 KCal::Event* baseEvent(const Task*);
315 bool remoteResource( const TQString& file ) const;
316
324 TQString exportcsvFile( TaskView *taskview, const ReportCriteria &rc );
325
329 TQString exportcsvHistory (
330 TaskView* taskview,
331 const TQDate& from,
332 const TQDate& to,
333 const ReportCriteria &rc
334 );
335
336 long printTaskHistory (
337 const Task *task,
338 const TQMap<TQString,long>& taskdaytotals,
339 TQMap<TQString,long>& daytotals,
340 const TQDate& from,
341 const TQDate& to,
342 const int level,
343 std::vector <TQString> &matrix,
344 const ReportCriteria &rc
345 );
346};
347
356{
357 public:
360 HistoryEvent(TQString uid, TQString name, long duration,
361 TQDateTime start, TQDateTime stop, TQString todoUid);
362 TQString uid() {return _uid; }
363 TQString name() {return _name; }
365 long duration() {return _duration; }
366 TQDateTime start() {return _start; }
367 TQDateTime stop() { return _stop; }
368 TQString todoUid() {return _todoUid; }
369
370 private:
371 TQString _uid;
372 TQString _todoUid;
373 TQString _name;
374 long _duration;
375 TQDateTime _start;
376 TQDateTime _stop;
377
378};
379
380#endif // KARM_STORAGE_H
One start/stop event that has been logged.
Definition: karmstorage.h:356
long duration()
In seconds.
Definition: karmstorage.h:365
HistoryEvent()
Needed to be used in a value list.
Definition: karmstorage.h:359
Singleton to store/retrieve KArm data to/from persistent storage.
Definition: karmstorage.h:68
bool isNewStorage(const Preferences *preferences) const
Check if iCalendar file name in the preferences has changed since the last call to load.
TQString loadFromFlatFile(TaskView *taskview, const TQString &filename)
Read tasks and their total times from a text file (legacy storage).
TQString loadFromFlatFileCumulative(TaskView *taskview, const TQString &filename)
Reads tasks and their total times from text file (legacy).
void setName(const Task *task, const TQString &oldname)
Log a change to a task name.
Definition: karmstorage.h:219
bool isEmpty()
Check if the iCalendar file currently loaded has any Todos in it.
bool removeTask(Task *task)
Remove this task from iCalendar file.
bool bookTime(const Task *task, const TQDateTime &startDateTime, long durationInSeconds)
Book time to a task.
TQString addTask(const Task *task, const Task *parent)
Add this task from iCalendar file.
void startTimer(const Task *task)
Log the event that a timer has started for a task.
Definition: karmstorage.h:230
void stopTimer(const Task *task, TQDateTime when=TQDateTime::currentDateTime())
Log the event that the timer has stopped for this task.
TQString report(TaskView *taskview, const ReportCriteria &rc)
Output a report based on contents of ReportCriteria.
TQValueList< HistoryEvent > getHistory(const TQDate &from, const TQDate &to)
Return a list of start/stop events for the given date range.
void changeTime(const Task *task, const long deltaSeconds)
Log the change in a task's time.
void addComment(const Task *task, const TQString &comment)
Log a new comment for this task.
Provide an interface to the configuration options for the program.
Definition: preferences.h:17
Stores entries from export dialog.
Container and interface for the tasks.
Definition: taskview.h:43
A class representing a task.
Definition: task.h:42