File indexing completed on 2024-05-19 05:21:55
0001 /* 0002 * Copyright (C) 2007 by Mathias Soeken <msoeken@tzi.de> 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 TIMETRACKER_WIDGET_H 0024 #define TIMETRACKER_WIDGET_H 0025 0026 #include <QDateTime> 0027 #include <QUrl> 0028 #include <QWidget> 0029 0030 QT_BEGIN_NAMESPACE 0031 class QAction; 0032 QT_END_NAMESPACE 0033 0034 class KActionCollection; 0035 0036 class Task; 0037 class TaskView; 0038 class SearchLine; 0039 class TasksWidget; 0040 0041 class TimeTrackerWidget : public QWidget 0042 { 0043 Q_OBJECT 0044 0045 public: 0046 explicit TimeTrackerWidget(QWidget *parent); 0047 ~TimeTrackerWidget() override = default; 0048 0049 private: 0050 /** 0051 * Load the specified file in the tasks widget. 0052 * @param url Must not be empty. 0053 */ 0054 void addTaskView(const QUrl &url); 0055 0056 public: 0057 /** 0058 Returns the TaskView widget of the current opened tabpage. 0059 */ 0060 TaskView *currentTaskView() const; 0061 0062 /** 0063 Returns the current task of the current opened TaskView widget. 0064 */ 0065 Task *currentTask(); 0066 0067 /** 0068 initializes the KActionCollection object of a main window for example. 0069 The actions are connected to the TreeWidget itself to ensure reusability. 0070 0071 @param actionCollection The KActionCollection instance of the host 0072 object. 0073 */ 0074 void setupActions(KActionCollection *actionCollection); 0075 0076 /** 0077 returns a generated action by name. You have to call setupActions before. 0078 0079 @param name The name of the action 0080 @returns A pointer to a QAction instance 0081 */ 0082 QAction *action(const QString &name) const; 0083 0084 public Q_SLOTS: 0085 /** 0086 * Load the specified .ics file in the tasks widget. 0087 * @param url Must not be empty. 0088 */ 0089 void openFile(const QUrl &url); 0090 0091 void openFileDialog(); 0092 0093 /** 0094 closes the current opened tab widget and saves the data 0095 of the corresponding taskview. 0096 0097 @returns whether the file has been closed. 0098 */ 0099 bool closeFile(); 0100 0101 /** 0102 saves the current taskview. This is especially important on unsaved 0103 files to give them a non-temporary filename. 0104 */ 0105 void saveFile(); 0106 0107 /** 0108 this method puts the input focus onto the search bar 0109 */ 0110 int focusSearchBar(); 0111 0112 /** 0113 shows/hides the search bar. 0114 */ 0115 void showSearchBar(bool visible); 0116 0117 /** 0118 tries to close all files. This slot has to be called before quitting 0119 the application to ensure that no data is lost. 0120 0121 @returns true if the user has saved or consciously not saved all files, 0122 otherwise false. 0123 */ 0124 bool closeAllFiles(); 0125 0126 /** Open export dialog. */ 0127 void exportDialog(); 0128 0129 //BEGIN wrapper slots 0130 /* 0131 * The following slots are wrapper slots which fires the corresponding 0132 * slot of the current taskview. 0133 */ 0134 void startCurrentTimer(); 0135 void stopCurrentTimer(); 0136 void stopAllTimers(); 0137 /** Calls newTask dialog with caption "New Task". */ 0138 void newTask(); 0139 void newSubTask(); 0140 void editTask(); 0141 void editTaskTime(); 0142 void deleteTask(); 0143 void markTaskAsComplete(); 0144 void markTaskAsIncomplete(); 0145 void startNewSession(); 0146 void editHistory(); 0147 void resetAllTimes(); 0148 void focusTracking(); 0149 void slotSearchBar(); 0150 //END 0151 0152 /** \defgroup dbus slots ‘‘dbus slots’’ */ 0153 /* @{ */ 0154 QString version() const; 0155 QStringList taskIdsFromName(const QString &taskName) const; 0156 void addTask(const QString &taskName); 0157 void addSubTask(const QString &taskName, const QString &taskId); 0158 void deleteTask(const QString &taskId); 0159 void setPercentComplete(const QString &taskId, int percent); 0160 int bookTime(const QString &taskId, const QString &dateTime, int64_t minutes); 0161 int changeTime(const QString &taskId, int64_t minutes); 0162 QString error(int errorCode) const; 0163 bool isIdleDetectionPossible() const; 0164 int totalMinutesForTaskId(const QString &taskId) const; 0165 void startTimerFor(const QString &taskId); 0166 void stopTimerFor(const QString &taskId); 0167 0168 bool startTimerForTaskName(const QString &taskName); 0169 bool stopTimerForTaskName(const QString &taskName); 0170 0171 // FIXME rename, when the wrapper slot is removed 0172 void stopAllTimersDBUS(); 0173 QString exportCSVFile(const QString &filename, 0174 const QString &from, 0175 const QString &to, 0176 int type, 0177 bool decimalMinutes, 0178 bool allTasks, 0179 const QString &delimiter, 0180 const QString "e); 0181 void importPlannerFile(const QString &filename); 0182 0183 /** return all task names, e.g. for batch processing */ 0184 QStringList tasks() const; 0185 0186 QStringList activeTasks() const; 0187 bool isActive(const QString &taskId) const; 0188 bool isTaskNameActive(const QString &taskName) const; 0189 void saveAll(); 0190 void quit(); 0191 // END of dbus slots group 0192 /* @} */ 0193 0194 // Triggered on changes in the Settings dialog 0195 void loadSettings(); 0196 0197 protected: 0198 bool event(QEvent *event) override; // inherited from QWidget 0199 0200 public Q_SLOTS: 0201 void showSettingsDialog(); 0202 0203 private Q_SLOTS: 0204 void slotCurrentChanged(); 0205 void slotAddTask(const QString &taskName); 0206 void slotUpdateButtons(); 0207 0208 Q_SIGNALS: 0209 void currentFileChanged(const QUrl &file); 0210 void currentTaskChanged(); 0211 void currentTaskViewChanged(); 0212 void updateButtons(); 0213 void statusBarTextChangeRequested(const QString &text); 0214 void contextMenuRequested(const QPoint &pos); 0215 void timersActive(); 0216 void timersInactive(); 0217 0218 // Used to update text in tray icon 0219 // and window title if the window title is configured to display the active tasks 0220 void tasksChanged(const QList<Task *> &activeTasks); 0221 0222 // update recorded minutes of current task 0223 // if the window title is configured to display the active tasks 0224 void minutesUpdated(const QList<Task *> &activeTasks); 0225 0226 private: 0227 void fillLayout(TasksWidget *tasksWidget); 0228 void registerDBus(); 0229 0230 SearchLine *m_searchLine; 0231 TaskView *m_taskView; 0232 KActionCollection *m_actionCollection; 0233 }; 0234 0235 #endif