summaryrefslogtreecommitdiffstats
path: root/karm/taskview.h
blob: a6444c3867e586d3b36ddf76d25eefed7c11fec1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
#ifndef KARM_TASK_VIEW_H
#define KARM_TASK_VIEW_H

#include <tqdict.h>
#include <tqptrlist.h>
#include <tqptrstack.h>

#include <klistview.h>

#include "desktoplist.h"
#include "resourcecalendar.h"
#include "karmstorage.h"
#include "mainwindow.h"
#include "reportcriteria.h"
#include <tqtimer.h>
//#include "desktoptracker.h"

//#include "karmutility.h"

class TQListBox;
class TQString;
class TQTextStream;
class TQTimer;

class KMenuBar;
class KToolBar;

class DesktopTracker;
class EditTaskDialog;
class IdleTimeDetector;
class Preferences;
class Task;
class KarmStorage;
class HistoryEvent;

using namespace KCal;

/**
 * Container and interface for the tasks.
 */

class TaskView : public KListView
{
  Q_OBJECT
  

  public:
    TaskView( TQWidget *parent = 0, const char *name = 0, const TQString &icsfile = "" );
    virtual ~TaskView();

    /**  Return the first item in the view, cast to a Task pointer.  */
    Task* first_child() const;

    /**  Return the current item in the view, cast to a Task pointer.  */
    Task* current_item() const;

    /**  Return the i'th item (zero-based), cast to a Task pointer.  */
    Task* item_at_index(int i);

    /** Load the view from storage.  */
    void load( TQString filename="" );

    /** Close the storage and release lock. */
    void closeStorage();

    /** Reset session time to zero for all tasks.   */
    void startNewSession();

    /** Reset session and total time to zero for all tasks.  */
    void resetTimeForAllTasks();

    /** Return the total number if items in the view.  */
    long count();

    /** Return list of start/stop events for given date range. */
    TQValueList<HistoryEvent> getHistory(const TQDate& from, const TQDate& to) const;

    /** Schedule that we should save very soon */
    void scheduleSave();

    /** Return preferences user selected on settings dialog. **/
    Preferences *preferences();

    /** Add a task to view and storage. */
    TQString addTask( const TQString& taskame, long total, long session, const DesktopList& desktops, 
                     Task* parent = 0 );

  public slots:
    /** Save to persistent storage. */
    TQString save();

    /** Start the timer on the current item (task) in view.  */
    void startCurrentTimer();

    /** Stop the timer for the current item in the view.  */
    void stopCurrentTimer();

    /** Stop all running timers.  */
    void stopAllTimers();

    /** Stop all running timers as if it was qdt */
    void stopAllTimersAt(TQDateTime qdt);

    /** Calls newTask dialog with caption "New Task".  */
    void newTask();

    /** Display edit task dialog and create a new task with results.  */
    void newTask( TQString caption, Task* parent );

     /** Used to refresh (e.g. after import) */
    void refresh();

   /** Used to import a legacy file format. */
    void loadFromFlatFile();

    /** used to import tasks from imendio planner */
    TQString importPlanner( TQString fileName="" );

    /** call export function for csv totals or history */
    TQString report( const ReportCriteria &rc );

    /** Export comma separated values format for task time totals. */
    void exportcsvFile();

    /** Export comma-separated values format for task history. */
    TQString exportcsvHistory();

    /** Calls newTask dialog with caption "New Sub Task". */
    void newSubTask();

    void editTask();

    /** 
     * Returns a pointer to storage object.
     *
     * This is poor object oriented design--the task view should 
     * expose wrappers around the storage methods we want to access instead of
     * giving clients full access to objects that we own.
     *
     * Hopefully, this will be redesigned as part of the TQt4 migration.
     */
    KarmStorage* storage();

    /**
     * Delete task (and children) from view.
     *
     * @param markingascomplete  If false (the default), deletes history for
     * current task and all children.  If markingascomplete is true, then sets
     * percent complete to 100 and removes task and all it's children from the
     * list view.
     */
    void deleteTask(bool markingascomplete=false);

    /** Reinstates the current task as incomplete.
     * @param completion The percentage complete to mark the task as. */
    void reinstateTask(int completion);
//    void addCommentToTask();
    void markTaskAsComplete();
    void markTaskAsIncomplete();

    /** Subtracts time from all active tasks, and does not log event. 
     * The time is stored in memory and in X-KDE-karm-duration. It is
     * increased automatically every minute to display the right duration.
     */
    void extractTime( int minutes );
    void taskTotalTimesChanged( long session, long total)
                                { emit totalTimesChanged( session, total); };
    void adaptColumns();
    /** receiving signal that a task is being deleted */
    void deletingTask(Task* deletedTask);

    /** starts timer for task. 
     * @param task      task to start timer of
     * @param startTime if taskview has been modified by another program, we 
			     have to set the starting time to not-now. */
    void startTimerFor( Task* task, TQDateTime startTime = TQDateTime::currentDateTime() );
    void stopTimerFor( Task* task );

    /** clears all active tasks. Needed e.g. if iCal file was modified by
       another program and taskview is cleared without stopping tasks 
	 IF YOU DO NOT KNOW WHAT YOU ARE DOING, CALL stopAllTimers INSTEAD */
    void clearActiveTasks();

    /** User might have picked a new iCalendar file on preferences screen. 
        Verify the file is not the same as before and load the new one. 
        This is not iCalFileModified. */
    void iCalFileChanged(TQString file);

    /** Copy totals for current and all sub tasks to clipboard. */
    void clipTotals();

    /** Copy session times for current and all sub tasks to clipboard */
    void clipSession();

    /** Copy history for current and all sub tasks to clipboard. */
    void clipHistory();

  signals:
    void totalTimesChanged( long session, long total );
    void updateButtons();
    void timersActive();
    void timersInactive();
    void tasksChanged( TQPtrList<Task> activeTasks );
    void setStatusBar( TQString );

  private: // member variables
    IdleTimeDetector *_idleTimeDetector;
    TQTimer *_minuteTimer;
    TQTimer *_autoSaveTimer;
    TQTimer *_manualSaveTimer;
    Preferences *_preferences;
    TQPtrList<Task> activeTasks;
    int previousColumnWidths[4];
    DesktopTracker* _desktopTracker;
    bool _isloading;

    //KCal::CalendarLocal _calendar;
    KarmStorage * _storage;

  private:
    void contentsMousePressEvent ( TQMouseEvent * e );
    void contentsMouseDoubleClickEvent ( TQMouseEvent * e );
    void updateParents( Task* task, long totalDiff, long sesssionDiff);
    void deleteChildTasks( Task *item );
    void addTimeToActiveTasks( int minutes, bool save_data = true );
    /** item state stores if a task is expanded so you can see the subtasks */
    void restoreItemState( TQListViewItem *item );

  protected slots:
    void autoSaveChanged( bool );
    void autoSavePeriodChanged( int period );
    void minuteUpdate();
    /** item state stores if a task is expanded so you can see the subtasks */
    void itemStateChanged( TQListViewItem *item );
    /** React on another process having modified the iCal file we rely on. */
    void iCalFileModified(ResourceCalendar *);
};

#endif // KARM_TASK_VIEW