karm

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 <qdict.h>
00027 #include <qptrstack.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 <kdepimmacros.h>
00038 
00039 class QDateTime;
00040 class Preferences;
00041 class Task;
00042 class TaskView;
00043 class HistoryEvent;
00044 class KCal::Todo;
00045 
00068 class KarmStorage
00069 {
00070   public:
00071     /*
00072      * Return reference to storage singleton.
00073      *
00074      * The constructors are private, so this must be used to create a
00075      * KarmStorage instance.
00076      */
00077     static KarmStorage *instance();
00078 
00079     /*
00080      * Load the list view with tasks read from iCalendar file.
00081      *
00082      * Parses iCalendar file, builds list view items in the proper
00083      * hierarchy, and loads them into the list view widget.
00084      *
00085      * If the file name passed in is the same as the last file name that was
00086      * loaded, this method does nothing.
00087      *
00088      * This method considers any of the following conditions errors:
00089      *
00090      *    @li the iCalendar file does not exist
00091      *    @li the iCalendar file is not readable
00092      *    @li the list group currently has list items
00093      *    @li an iCalendar todo has no related to attribute
00094      *    @li a todo is related to another todo which does not exist
00095      *
00096      * @param taskview     The list group used in the TaskView
00097      * @param preferences  The current KArm preferences.
00098      * @param fileName     Override preferences' filename
00099      *
00100      * @return empty string if success, error message if error.
00101      *
00102      */
00103     QString load(TaskView* taskview, const Preferences* preferences, QString fileName="" );
00104 
00105     /*
00106      * Return the name of the iCal file
00107      */
00108     QString icalfile();
00109 
00110     /*
00111      * Build up the taskview.
00112      *
00113      * This is needed if the iCal file has been modified
00114      */
00115     QString buildTaskView(KCal::ResourceCalendar *rc, TaskView *view);
00116     
00117     /* Close calendar and clear view.  Release lock if holding one. */
00118     void closeStorage(TaskView* view);
00119 
00120     /*
00121      * Save all tasks and their totals to an iCalendar file.
00122      *
00123      * All tasks must have an associated VTODO object already created in the
00124      * calendar file; that is, the task->uid() must refer to a valid VTODO in
00125      * the calender.
00126      * Delivers empty string if successful, else error msg.
00127      *
00128      * @param taskview    The list group used in the TaskView
00129      */
00130     QString save(TaskView* taskview);
00131 
00145     QString loadFromFlatFile(TaskView* taskview, const QString& filename);
00146 
00155     QString loadFromFlatFileCumulative(TaskView* taskview,
00156         const QString& filename);
00157 
00161     QString report( TaskView *taskview, const ReportCriteria &rc );
00162 
00188     void changeTime(const Task* task, const long deltaSeconds);
00189 
00206     bool bookTime(const Task* task, const QDateTime& startDateTime, 
00207                   long durationInSeconds);
00208 
00220     void setName(const Task* task, const QString& oldname) { Q_UNUSED(task); Q_UNUSED(oldname); }
00221 
00222 
00231     void startTimer(const Task* task) { Q_UNUSED(task); }
00232 
00242     void stopTimer(const Task* task, QDateTime when=QDateTime::currentDateTime());
00243 
00253     void addComment(const Task* task, const QString& comment);
00254 
00255 
00264     bool removeTask(Task* task);
00265 
00278     QString addTask(const Task* task, const Task* parent);
00279 
00285     bool isEmpty();
00286 
00297     bool isNewStorage(const Preferences* preferences) const;
00298 
00300     QValueList<HistoryEvent> getHistory(const QDate& from, const QDate& to);
00301 
00302   private:
00303     static KarmStorage                *_instance;
00304     KCal::ResourceCalendar            *_calendar;
00305     QString                           _icalfile;
00306 
00307     KarmStorage();
00308     void adjustFromLegacyFileFormat(Task* task);
00309     bool parseLine(QString line, long *time, QString *name, int *level,
00310         DesktopList* desktopList);
00311     QString writeTaskAsTodo
00312       (Task* task, const int level, QPtrStack< KCal::Todo >& parents);
00313     bool saveCalendar();
00314 
00315     KCal::Event* baseEvent(const Task*);
00316     bool remoteResource( const QString& file ) const;
00317 
00325     QString exportcsvFile( TaskView *taskview, const ReportCriteria &rc );
00326 
00330     QString exportcsvHistory (
00331             TaskView* taskview,
00332             const QDate& from,
00333             const QDate& to,
00334             const ReportCriteria &rc
00335             );
00336 
00337     long printTaskHistory (
00338             const Task *task,
00339             const QMap<QString,long>& taskdaytotals,
00340             QMap<QString,long>& daytotals,
00341             const QDate& from,
00342             const QDate& to,
00343             const int level, 
00344         std::vector <QString> &matrix,
00345             const ReportCriteria &rc
00346             );
00347 };
00348 
00356 class HistoryEvent
00357 {
00358   public:
00360     HistoryEvent() {}
00361     HistoryEvent(QString uid, QString name, long duration,
00362         QDateTime start, QDateTime stop, QString todoUid);
00363     QString uid() {return _uid; }
00364     QString name() {return _name; }
00366     long duration() {return _duration; }
00367     QDateTime start() {return _start; }
00368     QDateTime stop() { return _stop; }
00369     QString todoUid() {return _todoUid; }
00370 
00371   private:
00372     QString _uid;
00373     QString _todoUid;
00374     QString _name;
00375     long _duration;
00376     QDateTime _start;
00377     QDateTime _stop;
00378 
00379 };
00380 
00381 #endif // KARM_STORAGE_H
KDE Home | KDE Accessibility Home | Description of Access Keys