- recover from backup files
[Sak.git] / sak.h
blob3cca876b5c171df27f7eb147f7f600cb2de2fb1c
1 /***************************************************************************
2 * Copyright (C) 2007 by Arrigo Zanette *
3 * zanettea@gmail.com *
4 ***************************************************************************/
7 #ifndef __SAK_H__
8 #define __SAK_H__
10 #include <QtGui>
11 #include <QFont>
12 #include <QList>
13 #include <QHash>
14 #include <QPair>
15 #include <QObject>
16 #include <QDateTime>
17 #include <QPixmap>
18 #include <QRectF>
19 #include <QDebug>
21 #include "task.h"
24 class SakWidget;
25 class SakSubWidget;
26 class SakMessageItem;
27 class PixmapViewer;
28 class Timeline;
29 class HitItem;
31 class Sak : public QObject
33 Q_OBJECT;
34 public:
35 Sak(QObject* parent = 0);
36 virtual ~Sak();
37 QHash<QString, Task>* tasks() { return &m_tasks; }
38 protected:
39 void timerEvent(QTimerEvent* e);
40 bool eventFilter(QObject* obj, QEvent* e);
41 bool taskTreeEventFilter(QEvent* e);
42 bool hitsListEventFilter(QEvent* e);
43 public slots:
44 void start();
45 void pause();
46 void stop();
47 void workingOn();
48 Task loadTaskFromFile(const QString& filePath, bool tryRecover=true);
49 // recover from error using backup file for given file taskXmlFile
50 Task recoverTaskFromBackup(QFile& taskXmlFile, const QString& error);
51 void flush();
52 void flushSettings();
53 void open(const QStringList& filePaths = QStringList());
54 // void saveAsDb();
55 void exportDbCsv();
56 void logInGmail();
57 void saveToGmail();
58 void importFromGmail();
59 void selectTodayDate();
60 void selectThisWeeDate();
61 void selectThisMonthDate();
62 void selectLastWeekDate();
63 void selectLastMonthDate();
64 protected slots:
65 void init();
66 void destroy();
67 // tasks
68 void addDefaultTask();
69 void exportHits();
70 void populateTasks();
71 // commit changes on current tasks for temporary previews
72 void commitCurrentTask();
73 // permanentely save changes on tasks
74 void saveTaskChanges();
75 // permanentely save changes on hits
76 void saveHitChanges();
77 void selectedTask();
78 void doubleClickedTask(QTreeWidgetItem* i, int column);
79 void selectColor();
80 void grabKeyboard(); // delayed grab of keayboard
81 // popup task selection
82 void popup();
83 // popup subtask selection
84 void popupSubtasks(const QString& taskname);
85 // save current selected hit (after popup)
86 void workingOnTask(const QString& taskname, const QString& subtask);
87 void focusedSubTask();
88 void clearView();
89 void trayIconActivated(QSystemTrayIcon::ActivationReason);
90 // create a list of hits merging tasks
91 QList<HitElement> createHitsList(const QDateTime& from = QDateTime(), const QDateTime& to = QDateTime());
92 QMap<double, QPair<Task*, QString> > createSummaryList(const QList<HitElement>& hits);
93 void selectedStartDate(const QDate& date);
94 void selectedEndDate(const QDate& date);
95 void hitsListItemChanged(QTreeWidgetItem*, int column);
96 void hitsSelectedInList(QTreeWidgetItem*, QTreeWidgetItem*);
97 void hitsSelectedInTimeline(HitItem*);
98 void populateHitsList(const QList<HitElement>&, QTreeWidget* t = 0);
99 void populateHitsTimeline(const QList<HitElement>&, Timeline* t = 0);
100 void addDefaultHit();
101 void interactiveMergeHits();
102 private:
103 int m_timerId, m_timeoutPopup, m_autoSaveTimer, m_getFocusTimer;
104 bool m_stopped;
105 QDateTime m_nextTimerEvent;
106 QMainWindow* m_settings;
107 QHash<QString, Task> m_tasks;
108 QHash<QString, Task> m_editedTasks;
109 QMultiMap<int, SakWidget*> m_widgets;
110 QMultiMap<int, SakSubWidget*> m_subwidgets;
111 class QGraphicsEllipseItem* m_marker;
112 QMap<int, SakWidget*>::iterator m_widgetsIterator;
113 QMap<int, SakSubWidget*>::iterator m_subwidgetsIterator;
114 int m_subWidgetRank;
115 QList<QString> m_taskSelectionHistory;
116 QHash< QString, QList< QString > > m_subtaskSelectionHistory;
117 QCompleter* m_subtaskCompleter;
118 int m_currentInterval;
119 QRect m_desktopRect;
121 double workingOnDeclared;
122 bool m_previewing;
123 bool m_changedHit, m_changedTask;
124 bool m_subtaskView;
125 static int taskCounter;
126 bool m_yesToBackup;
128 QAction* m_addTaskAction;
129 QMenu* m_addTaskMenu;
131 QMenu* m_addHitMenu;
132 QAction* m_addHitAction;
133 QAction* m_exportDataAction;
134 QString currentTask, currentSubtask;
135 class GView* m_view;
136 class Backupper* m_backupper;
137 class Incremental* m_incremental;
138 class GmailPyInterface* m_gmail;
140 //BEGIN Settings data:
141 public:
142 void setVisible(bool visible);
143 private:
144 QRect Layouting( const QList<SakWidget*>& sortedWidgets);
145 void layoutSubTasks( const QMap<int, SakSubWidget*> sortedWidgets, int currentRank);
147 QTreeWidget* newHitsList();
148 QTreeWidget* newTaskSummaryList();
149 void setupSettingsWidget();
150 void createActions();
152 void scrollTasks(int npos);
153 void scrollSubTasks(int npos);
155 QTabWidget* tabs;
156 QWidget* tab1;
157 QWidget* tab2;
158 QWidget* tab3;
159 QWidget* tab4;
160 QPushButton* previewButton;
161 QPushButton* bgColorButton;
162 QPushButton* fgColorButton;
164 QLabel *durationLabel, *durationLabel1;
165 QLabel *durationWarningLabel;
166 QLabel *bodyLabel;
167 QSpinBox *durationSpinBox;
168 QTextEdit *bodyEdit;
169 PixmapViewer* askingLady;
170 PixmapViewer* viewBackground;
173 QTreeWidget* tasksTree;
174 QComboBox* taskSelector;
175 QTreeWidget* hitsList, *summaryList;
176 Timeline* hitsTimeline;
177 QCalendarWidget* cal1, *cal2, *cal3, *cal4;
178 QPushButton* today1, *thisWeek1, *thisMonth1, *lastWeek1, *lastMonth1;
179 QPushButton* today2, *thisWeek2, *thisMonth2, *lastWeek2, *lastMonth2;
180 PixmapViewer* taskPixmapViewer;
181 QTextEdit* taskTextEditor;
182 QLineEdit* taskTitleEditor;
183 QLineEdit* taskTagsEditor;
184 QLineEdit* taskUrlEditor;
185 QSpinBox* estimatedHoursEditor;
186 QDateEdit* dueEditor;
187 QGraphicsView* summaryView;
188 class TaskSummaryPieChart* summaryChart;
190 QAction *minimizeAction;
191 QAction *maximizeAction;
192 QAction *restoreAction;
193 QAction *startAction;
194 QAction *stopAction;
195 QAction *workingOnAction;
196 QAction *flushAction;
197 QAction *quitAction;
198 QAction *saveAsDbAction;
199 QAction *openAction;
200 QAction *exportDbCsvAction;
201 QAction *gmailLoginAction;
202 QAction *saveToGmailAction;
203 QAction *sendByEmailAction;
205 QSystemTrayIcon *trayIcon;
206 QMenu *trayIconMenu;
208 QTimer *workingOnTimer;
210 /*! Avoids recursion and crash when updating hitList as a result of updating timeline */
211 bool m_updatingFromTimeline;
214 class MyDateItemDelegate : public QItemDelegate
216 public:
217 MyDateItemDelegate(QObject *parent = 0);
219 QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option,
220 const QModelIndex &index) const;
222 void setEditorData(QWidget *editor, const QModelIndex &index) const;
223 void setModelData(QWidget *editor, QAbstractItemModel *model,
224 const QModelIndex &index) const;
226 void updateEditorGeometry(QWidget *editor,
227 const QStyleOptionViewItem &option, const QModelIndex &index) const;
230 class TaskItemDelegate : public QItemDelegate
232 public:
233 TaskItemDelegate(Sak* sak, QObject *parent = 0);
235 QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option,
236 const QModelIndex &index) const;
238 void setEditorData(QWidget *editor, const QModelIndex &index) const;
239 void setModelData(QWidget *editor, QAbstractItemModel *model,
240 const QModelIndex &index) const;
242 void updateEditorGeometry(QWidget *editor,
243 const QStyleOptionViewItem &option, const QModelIndex &index) const;
244 private:
245 Sak* m_sak;
249 class SubTaskItemDelegate : public QItemDelegate
251 public:
252 SubTaskItemDelegate(Sak* sak, QObject *parent = 0);
254 QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option,
255 const QModelIndex &index) const;
257 void setEditorData(QWidget *editor, const QModelIndex &index) const;
258 void setModelData(QWidget *editor, QAbstractItemModel *model,
259 const QModelIndex &index) const;
261 void updateEditorGeometry(QWidget *editor,
262 const QStyleOptionViewItem &option, const QModelIndex &index) const;
263 private:
264 Sak* m_sak;
269 #endif