karmstorage.h
00001 /* 00002 * This file only: 00003 * Copyright (C) 2003 Mark Bucciarelli <mark@hubcapconsutling.com> 00004 * 00005 * This program is free software; you can redistribute it and/or modify 00006 * it under the terms of the GNU General Public License as published by 00007 * the Free Software Foundation; either version 2 of the License, or 00008 * (at your option) any later version. 00009 * 00010 * This program is distributed in the hope that it will be useful, 00011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 * GNU General Public License for more details. 00014 * 00015 * You should have received a copy of the GNU General Public License along 00016 * with this program; if not, write to the 00017 * Free Software Foundation, Inc. 00018 * 51 Franklin Street, Fifth Floor 00019 * Boston, MA 02110-1301 USA. 00020 * 00021 */ 00022 00023 #ifndef KARM_STORAGE_H 00024 #define KARM_STORAGE_H 00025 00026 #include <tqdict.h> 00027 #include <tqptrstack.h> 00028 00029 #include "journal.h" 00030 #include "reportcriteria.h" 00031 00032 #include "desktoplist.h" 00033 00034 #include <calendarresources.h> 00035 #include <vector> 00036 #include "resourcecalendar.h" 00037 #include <tdepimmacros.h> 00038 00039 class TQDateTime; 00040 class Preferences; 00041 class Task; 00042 class TaskView; 00043 class HistoryEvent; 00044 00067 class KarmStorage 00068 { 00069 public: 00070 /* 00071 * Return reference to storage singleton. 00072 * 00073 * The constructors are private, so this must be used to create a 00074 * KarmStorage instance. 00075 */ 00076 static KarmStorage *instance(); 00077 00078 /* 00079 * Load the list view with tasks read from iCalendar file. 00080 * 00081 * Parses iCalendar file, builds list view items in the proper 00082 * hierarchy, and loads them into the list view widget. 00083 * 00084 * If the file name passed in is the same as the last file name that was 00085 * loaded, this method does nothing. 00086 * 00087 * This method considers any of the following conditions errors: 00088 * 00089 * @li the iCalendar file does not exist 00090 * @li the iCalendar file is not readable 00091 * @li the list group currently has list items 00092 * @li an iCalendar todo has no related to attribute 00093 * @li a todo is related to another todo which does not exist 00094 * 00095 * @param taskview The list group used in the TaskView 00096 * @param preferences The current KArm preferences. 00097 * @param fileName Override preferences' filename 00098 * 00099 * @return empty string if success, error message if error. 00100 * 00101 */ 00102 TQString load(TaskView* taskview, const Preferences* preferences, TQString fileName="" ); 00103 00104 /* 00105 * Return the name of the iCal file 00106 */ 00107 TQString icalfile(); 00108 00109 /* 00110 * Build up the taskview. 00111 * 00112 * This is needed if the iCal file has been modified 00113 */ 00114 TQString buildTaskView(KCal::ResourceCalendar *rc, TaskView *view); 00115 00116 /* Close calendar and clear view. Release lock if holding one. */ 00117 void closeStorage(TaskView* view); 00118 00119 /* 00120 * Save all tasks and their totals to an iCalendar file. 00121 * 00122 * All tasks must have an associated VTODO object already created in the 00123 * calendar file; that is, the task->uid() must refer to a valid VTODO in 00124 * the calender. 00125 * Delivers empty string if successful, else error msg. 00126 * 00127 * @param taskview The list group used in the TaskView 00128 */ 00129 TQString save(TaskView* taskview); 00130 00144 TQString loadFromFlatFile(TaskView* taskview, const TQString& filename); 00145 00154 TQString loadFromFlatFileCumulative(TaskView* taskview, 00155 const TQString& filename); 00156 00160 TQString report( TaskView *taskview, const ReportCriteria &rc ); 00161 00187 void changeTime(const Task* task, const long deltaSeconds); 00188 00205 bool bookTime(const Task* task, const TQDateTime& startDateTime, 00206 long durationInSeconds); 00207 00219 void setName(const Task* task, const TQString& oldname) { Q_UNUSED(task); Q_UNUSED(oldname); } 00220 00221 00230 void startTimer(const Task* task) { Q_UNUSED(task); } 00231 00241 void stopTimer(const Task* task, TQDateTime when=TQDateTime::currentDateTime()); 00242 00252 void addComment(const Task* task, const TQString& comment); 00253 00254 00263 bool removeTask(Task* task); 00264 00277 TQString addTask(const Task* task, const Task* parent); 00278 00284 bool isEmpty(); 00285 00296 bool isNewStorage(const Preferences* preferences) const; 00297 00299 TQValueList<HistoryEvent> getHistory(const TQDate& from, const TQDate& to); 00300 00301 private: 00302 static KarmStorage *_instance; 00303 KCal::ResourceCalendar *_calendar; 00304 TQString _icalfile; 00305 00306 KarmStorage(); 00307 void adjustFromLegacyFileFormat(Task* task); 00308 bool parseLine(TQString line, long *time, TQString *name, int *level, 00309 DesktopList* desktopList); 00310 TQString writeTaskAsTodo 00311 (Task* task, const int level, TQPtrStack< KCal::Todo >& parents); 00312 bool saveCalendar(); 00313 00314 KCal::Event* baseEvent(const Task*); 00315 bool remoteResource( const TQString& file ) const; 00316 00324 TQString exportcsvFile( TaskView *taskview, const ReportCriteria &rc ); 00325 00329 TQString exportcsvHistory ( 00330 TaskView* taskview, 00331 const TQDate& from, 00332 const TQDate& to, 00333 const ReportCriteria &rc 00334 ); 00335 00336 long printTaskHistory ( 00337 const Task *task, 00338 const TQMap<TQString,long>& taskdaytotals, 00339 TQMap<TQString,long>& daytotals, 00340 const TQDate& from, 00341 const TQDate& to, 00342 const int level, 00343 std::vector <TQString> &matrix, 00344 const ReportCriteria &rc 00345 ); 00346 }; 00347 00355 class HistoryEvent 00356 { 00357 public: 00359 HistoryEvent() {} 00360 HistoryEvent(TQString uid, TQString name, long duration, 00361 TQDateTime start, TQDateTime stop, TQString todoUid); 00362 TQString uid() {return _uid; } 00363 TQString name() {return _name; } 00365 long duration() {return _duration; } 00366 TQDateTime start() {return _start; } 00367 TQDateTime stop() { return _stop; } 00368 TQString todoUid() {return _todoUid; } 00369 00370 private: 00371 TQString _uid; 00372 TQString _todoUid; 00373 TQString _name; 00374 long _duration; 00375 TQDateTime _start; 00376 TQDateTime _stop; 00377 00378 }; 00379 00380 #endif // KARM_STORAGE_H