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     QString buildTaskView(KCal::ResourceCalendar *rc, TaskView *view);
00106     
00107     /* Close calendar and clear view.  Release lock if holding one. */
00108     void closeStorage(TaskView* view);
00109 
00110     /*
00111      * Save all tasks and their totals to an iCalendar file.
00112      *
00113      * All tasks must have an associated VTODO object already created in the
00114      * calendar file; that is, the task->uid() must refer to a valid VTODO in
00115      * the calender.
00116      * Delivers empty string if successful, else error msg.
00117      *
00118      * @param taskview    The list group used in the TaskView
00119      */
00120     QString save(TaskView* taskview);
00121 
00135     QString loadFromFlatFile(TaskView* taskview, const QString& filename);
00136 
00145     QString loadFromFlatFileCumulative(TaskView* taskview,
00146         const QString& filename);
00147 
00151     QString report( TaskView *taskview, const ReportCriteria &rc );
00152 
00153     /*
00154      * Log the change in a task's time.
00155      *
00156      * We create an iCalendar event to store each change.  The event start
00157      * date is set to the current datetime.  If time is added to the task, the
00158      * task end date is set to start time + delta.  If the time is negative,
00159      * the end date is set to the start time.
00160      *
00161      * In both cases (postive or negative delta), we create a custom iCalendar
00162      * property that stores the delta (in seconds).  This property is called
00163      * X-KDE-karm-duration.
00164      *
00165      * Note that the KArm UI allows the user to change both the session and
00166      * the total task time, and this routine does not account for all posibile
00167      * cases.  For example, it is possible for the user to do something crazy
00168      * like add 10 minutes to the session time and subtract 50 minutes from
00169      * the total time.  Although this change violates a basic law of physics,
00170      * it is allowed.
00171      *
00172      * For now, you should pass in the change to the total task time.
00173      * Eventually, the UI should be changed.
00174      *
00175      * @param task   The task the change is for.
00176      * @param delta  Change in task time, in seconds.  Can be negative.
00177      */
00178     void changeTime(const Task* task, const long deltaSeconds);
00179 
00196     bool bookTime(const Task* task, const QDateTime& startDateTime, 
00197                   long durationInSeconds);
00198 
00210     void setName(const Task* task, const QString& oldname) { Q_UNUSED(task); Q_UNUSED(oldname); }
00211 
00212 
00221     void startTimer(const Task* task) { Q_UNUSED(task); }
00222 
00232     void stopTimer(const Task* task);
00233 
00243     void addComment(const Task* task, const QString& comment);
00244 
00245 
00254     bool removeTask(Task* task);
00255 
00268     QString addTask(const Task* task, const Task* parent);
00269 
00275     bool isEmpty();
00276 
00287     bool isNewStorage(const Preferences* preferences) const;
00288 
00290     QValueList<HistoryEvent> getHistory(const QDate& from, const QDate& to);
00291 
00292   private:
00293     static KarmStorage                *_instance;
00294     KCal::ResourceCalendar            *_calendar;
00295     QString                           _icalfile;
00296 
00297     KarmStorage();
00298     void adjustFromLegacyFileFormat(Task* task);
00299     bool parseLine(QString line, long *time, QString *name, int *level,
00300         DesktopList* desktopList);
00301     QString writeTaskAsTodo
00302       (Task* task, const int level, QPtrStack< KCal::Todo >& parents);
00303     bool saveCalendar();
00304 
00305     KCal::Event* baseEvent(const Task*);
00306     bool remoteResource( const QString& file ) const;
00307 
00315     QString exportcsvFile( TaskView *taskview, const ReportCriteria &rc );
00316 
00320     QString exportcsvHistory (
00321             TaskView* taskview,
00322             const QDate& from,
00323             const QDate& to,
00324             const ReportCriteria &rc
00325             );
00326 
00327     long printTaskHistory (
00328             const Task *task,
00329             const QMap<QString,long>& taskdaytotals,
00330             QMap<QString,long>& daytotals,
00331             const QDate& from,
00332             const QDate& to,
00333             const int level, 
00334         std::vector <QString> &matrix,
00335             const ReportCriteria &rc
00336             );
00337 };
00338 
00346 class HistoryEvent
00347 {
00348   public:
00350     HistoryEvent() {}
00351     HistoryEvent(QString uid, QString name, long duration,
00352         QDateTime start, QDateTime stop, QString todoUid);
00353     QString uid() {return _uid; }
00354     QString name() {return _name; }
00356     long duration() {return _duration; }
00357     QDateTime start() {return _start; }
00358     QDateTime stop() { return _stop; }
00359     QString todoUid() {return _todoUid; }
00360 
00361   private:
00362     QString _uid;
00363     QString _todoUid;
00364     QString _name;
00365     long _duration;
00366     QDateTime _start;
00367     QDateTime _stop;
00368 
00369 };
00370 
00371 #endif // KARM_STORAGE_H
KDE Home | KDE Accessibility Home | Description of Access Keys