File indexing completed on 2024-05-19 05:21:54
0001 /* 0002 * Copyright (C) 2003 by Scott Monachello <smonach@cox.net> 0003 * Copyright (C) 2019 Alexander Potashev <aspotashev@gmail.com> 0004 * 0005 * This program is free software; you can redistribute it and/or modify 0006 * it under the terms of the GNU General Public License as published by 0007 * the Free Software Foundation; either version 2 of the License, or 0008 * (at your option) any later version. 0009 * 0010 * This program is distributed in the hope that it will be useful, 0011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 0012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 0013 * GNU General Public License for more details. 0014 * 0015 * You should have received a copy of the GNU General Public License along 0016 * with this program; if not, write to the 0017 * Free Software Foundation, Inc. 0018 * 51 Franklin Street, Fifth Floor 0019 * Boston, MA 02110-1301 USA. 0020 * 0021 */ 0022 0023 #ifndef KTIMETRACKER_TASK_VIEW 0024 #define KTIMETRACKER_TASK_VIEW 0025 0026 #include <QList> 0027 0028 #include "desktoplist.h" 0029 #include "reportcriteria.h" 0030 #include "timetrackerstorage.h" 0031 0032 QT_BEGIN_NAMESPACE 0033 class QTimer; 0034 class QSortFilterProxyModel; 0035 class QMenu; 0036 QT_END_NAMESPACE 0037 0038 class DesktopTracker; 0039 class IdleTimeDetector; 0040 class Task; 0041 class TimeTrackerStorage; 0042 class FocusDetector; 0043 class TasksModel; 0044 class TasksWidget; 0045 0046 /** 0047 * Container and interface for the tasks. 0048 */ 0049 class TaskView : public QObject 0050 { 0051 Q_OBJECT 0052 0053 public: 0054 explicit TaskView(QWidget *parent = nullptr); 0055 ~TaskView() override; 0056 0057 /** 0058 * Load the view from storage. 0059 * 0060 * Must be called only once. If you need to open another file, 0061 * please create a new TaskView object. 0062 */ 0063 void load(const QUrl &url); 0064 0065 /** Close the storage and release lock. */ 0066 void closeStorage(); 0067 0068 /** Add a task to view and storage. */ 0069 Task *addTask(const QString &taskname, 0070 const QString &taskdescription = QString(), 0071 int64_t total = 0, 0072 int64_t session = 0, 0073 const DesktopList &desktops = QVector<int>(0, 0), 0074 Task *parent = nullptr); 0075 0076 /** Returns whether the focus tracking is currently active. */ 0077 bool isFocusTrackingActive() const; 0078 0079 TasksWidget *tasksWidget() { return m_tasksWidget; } 0080 0081 public Q_SLOTS: 0082 /** Save to persistent storage. */ 0083 void save(); 0084 0085 /** Start the timer on the current item (task) in view. */ 0086 void startCurrentTimer(); 0087 0088 /** Stop the timer for the current item in the view. */ 0089 void stopCurrentTimer(); 0090 0091 /** Stop all running timers. 0092 * @param when When the timer stopped - this makes sense if the idletime- 0093 * detector detects the user stopped working 5 minutes ago. 0094 */ 0095 void stopAllTimers(const QDateTime &when = QDateTime::currentDateTime()); 0096 0097 /** Toggles the automatic tracking of focused windows 0098 */ 0099 void toggleFocusTracking(); 0100 0101 /** Display edit task dialog and create a new task with results. 0102 * @param caption Window title of the edit task dialog 0103 */ 0104 void newTask(const QString &caption, Task *parent); 0105 0106 /** used to import tasks from imendio planner */ 0107 void importPlanner(const QString &fileName); 0108 0109 /** Calls newTask dialog with caption "New Sub Task". */ 0110 void newSubTask(); 0111 0112 /** Calls editTask dialog for the current task. */ 0113 void editTask(); 0114 0115 /** 0116 * Returns a pointer to storage object. 0117 * 0118 * This is poor object oriented design--the task view should 0119 * expose wrappers around the storage methods we want to access instead of 0120 * giving clients full access to objects that we own. 0121 * 0122 * Hopefully, this will be redesigned as part of the Qt4 migration. 0123 */ 0124 TimeTrackerStorage *storage(); 0125 0126 /** 0127 * Deletes the given or the current task (and children) from the view. 0128 * It does this in batch mode, no user dialog. 0129 * @param task Task to be deleted. If empty, the current task is deleted. 0130 * if non-existent, an error message is displayed. 0131 */ 0132 void deleteTaskBatch(Task *task); 0133 0134 /** 0135 * Deletes the given or the current task (and children) from the view. 0136 * Depending on configuration, there may be a user dialog. 0137 * @param task Task to be deleted. If empty, the current task is deleted. 0138 * if non-existent, an error message is displayed. 0139 */ 0140 void deleteTask(Task *task = nullptr); 0141 0142 /** Sets % completed for the current task. 0143 * @param completion The percentage complete to mark the task as. */ 0144 void setPerCentComplete(int completion); 0145 void markTaskAsComplete(); 0146 void markTaskAsIncomplete(); 0147 0148 /** Subtracts time from all active tasks, and does not log event. */ 0149 void subtractTime(int64_t minutes); 0150 /** receiving signal that a task is being deleted */ 0151 void taskAboutToBeRemoved(const QModelIndex &parent, int first, int last); 0152 /** receiving signal that a task has been deleted */ 0153 void taskRemoved(const QModelIndex &parent, int first, int last); 0154 0155 /** starts timer for task. 0156 * @param task task to start timer of 0157 * @param startTime if taskview has been modified by another program, we 0158 have to set the starting time to not-now. */ 0159 void startTimerFor(Task *task, const QDateTime &startTime); 0160 void startTimerForNow(Task *task); 0161 void stopTimerFor(Task *task); 0162 0163 /** Reconfigures taskView depending on current configuration. */ 0164 void reconfigureModel(); 0165 0166 /** Refresh the times of the tasks, e.g. when the history has been changed by the user */ 0167 QString reFreshTimes(); 0168 0169 void onTaskDoubleClicked(Task *task); 0170 0171 void editTaskTime(const QString &taskUid, int64_t minutes); 0172 0173 Q_SIGNALS: 0174 void updateButtons(); 0175 void timersActive(); 0176 void timersInactive(); 0177 0178 /** Used to update text in tray icon */ 0179 void tasksChanged(const QList<Task *> &activeTasks); 0180 void minutesUpdated(const QList<Task *> &activeTasks); 0181 0182 void setStatusBarText(const QString &text); 0183 void contextMenuRequested(const QPoint &); 0184 0185 private: // member variables 0186 QSortFilterProxyModel *m_filterProxyModel; 0187 0188 IdleTimeDetector *m_idleTimeDetector; 0189 QTimer *m_minuteTimer; 0190 QTimer *m_autoSaveTimer; 0191 DesktopTracker *m_desktopTracker; 0192 0193 TimeTrackerStorage *m_storage; 0194 bool m_focusTrackingActive; 0195 Task *m_lastTaskWithFocus; 0196 0197 FocusDetector *m_focusDetector; 0198 0199 TasksWidget *m_tasksWidget; 0200 0201 public Q_SLOTS: 0202 void minuteUpdate(); 0203 0204 /** React on the focus having changed to Window QString **/ 0205 void newFocusWindowDetected(const QString &); 0206 0207 void slotColumnToggled(int); 0208 }; 0209 0210 #endif // KTIMETRACKER_TASK_VIEW