notifies from systray when stopped
[Sak.git] / sak.h
blob58e16849d27510f87a4a6c4b6c8e411964bc89e2
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 stop();
46 Task loadTaskFromFile(const QString& filePath);
47 void flush();
48 void open(const QStringList& filePaths = QStringList());
49 // void saveAsDb();
50 void exportDbCsv();
51 void logInGmail();
52 void saveToGmail();
53 void importFromGmail();
54 protected slots:
55 void init();
56 void destroy();
57 // tasks
58 void addDefaultTask();
59 void exportHits();
60 void populateTasks();
61 // commit changes on current tasks for temporary previews
62 void commitCurrentTask();
63 // permanentely save changes on tasks
64 void saveTaskChanges();
65 // permanentely save changes on hits
66 void saveHitChanges();
67 void selectedTask();
68 void doubleClickedTask(QTreeWidgetItem* i, int column);
69 void selectColor();
70 void grabKeyboard(); // delayed grab of keayboard
71 // popup task selection
72 void popup();
73 // popup subtask selection
74 void popupSubtasks(const QString& taskname);
75 // save current selected hit (after popup)
76 void workingOnTask(const QString& taskname, const QString& subtask);
77 void focusedSubTask();
78 void clearView();
79 void trayIconActivated(QSystemTrayIcon::ActivationReason);
80 // create a list of hits merging tasks
81 QList<HitElement> createHitsList(const QDateTime& from = QDateTime(), const QDateTime& to = QDateTime());
82 QMap<double, QPair<Task*, QString> > createSummaryList(const QList<HitElement>& hits);
83 void selectedStartDate(const QDate& date);
84 void selectedEndDate(const QDate& date);
85 void hitsListItemChanged(QTreeWidgetItem*, int column);
86 void hitsSelectedInList(QTreeWidgetItem*, QTreeWidgetItem*);
87 void hitsSelectedInTimeline(HitItem*);
88 void populateHitsList(const QList<HitElement>&, QTreeWidget* t = 0);
89 void populateHitsTimeline(const QList<HitElement>&, Timeline* t = 0);
90 void addDefaultHit();
91 void interactiveMergeHits();
92 private:
93 int m_timerId, m_timeoutPopup, m_autoSaveTimer;
94 bool m_stopped;
95 QDateTime m_nextTimerEvent;
96 QMainWindow* m_settings;
97 QHash<QString, Task> m_tasks;
98 QHash<QString, Task> m_editedTasks;
99 QMultiMap<int, SakWidget*> m_widgets;
100 QMultiMap<int, SakSubWidget*> m_subwidgets;
101 class QGraphicsEllipseItem* m_marker;
102 QMap<int, SakWidget*>::iterator m_widgetsIterator;
103 QMap<int, SakSubWidget*>::iterator m_subwidgetsIterator;
104 int m_subWidgetRank;
105 QList<QString> m_taskSelectionHistory;
106 QHash< QString, QList< QString > > m_subtaskSelectionHistory;
107 QCompleter* m_subtaskCompleter;
108 int m_currentInterval;
109 QRect m_desktopRect;
111 bool m_previewing;
112 bool m_changedHit, m_changedTask;
113 bool m_subtaskView;
114 static int taskCounter;
116 QAction* m_addTaskAction;
117 QMenu* m_addTaskMenu;
119 QMenu* m_addHitMenu;
120 QAction* m_addHitAction;
121 QAction* m_exportDataAction;
122 QString currentTask, currentSubtask;
123 class GView* m_view;
124 class Backupper* m_backupper;
125 class Incremental* m_incremental;
126 class GmailPyInterface* m_gmail;
128 //BEGIN Settings data:
129 public:
130 void setVisible(bool visible);
131 private:
132 QRect Layouting( const QList<SakWidget*>& sortedWidgets);
133 void layoutSubTasks( const QMap<int, SakSubWidget*> sortedWidgets, int currentRank);
135 QTreeWidget* newHitsList();
136 QTreeWidget* newTaskSummaryList();
137 void setupSettingsWidget();
138 void createActions();
140 void scrollTasks(int npos);
141 void scrollSubTasks(int npos);
143 QTabWidget* tabs;
144 QWidget* tab1;
145 QWidget* tab2;
146 QWidget* tab3;
147 QWidget* tab4;
148 QPushButton* previewButton;
149 QPushButton* bgColorButton;
150 QPushButton* fgColorButton;
152 QLabel *durationLabel, *durationLabel1;
153 QLabel *durationWarningLabel;
154 QLabel *bodyLabel;
155 QSpinBox *durationSpinBox;
156 QTextEdit *bodyEdit;
158 QTreeWidget* tasksTree;
159 QComboBox* taskSelector;
160 QTreeWidget* hitsList, *summaryList;
161 Timeline* hitsTimeline;
162 QCalendarWidget* cal1, *cal2, *cal3, *cal4;
163 PixmapViewer* taskPixmapViewer;
164 QTextEdit* taskTextEditor;
165 QLineEdit* taskTitleEditor;
166 QSpinBox* estimatedHoursEditor;
167 QDateEdit* dueEditor;
169 QAction *minimizeAction;
170 QAction *maximizeAction;
171 QAction *restoreAction;
172 QAction *startAction;
173 QAction *stopAction;
174 QAction *flushAction;
175 QAction *quitAction;
176 QAction *saveAsDbAction;
177 QAction *openAction;
178 QAction *exportDbCsvAction;
179 QAction *gmailLoginAction;
180 QAction *saveToGmailAction;
181 QAction *sendByEmailAction;
183 QSystemTrayIcon *trayIcon;
184 QMenu *trayIconMenu;
188 class MyDateItemDelegate : public QItemDelegate
190 public:
191 MyDateItemDelegate(QObject *parent = 0);
193 QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option,
194 const QModelIndex &index) const;
196 void setEditorData(QWidget *editor, const QModelIndex &index) const;
197 void setModelData(QWidget *editor, QAbstractItemModel *model,
198 const QModelIndex &index) const;
200 void updateEditorGeometry(QWidget *editor,
201 const QStyleOptionViewItem &option, const QModelIndex &index) const;
204 class TaskItemDelegate : public QItemDelegate
206 public:
207 TaskItemDelegate(Sak* sak, QObject *parent = 0);
209 QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option,
210 const QModelIndex &index) const;
212 void setEditorData(QWidget *editor, const QModelIndex &index) const;
213 void setModelData(QWidget *editor, QAbstractItemModel *model,
214 const QModelIndex &index) const;
216 void updateEditorGeometry(QWidget *editor,
217 const QStyleOptionViewItem &option, const QModelIndex &index) const;
218 private:
219 Sak* m_sak;
223 class SubTaskItemDelegate : public QItemDelegate
225 public:
226 SubTaskItemDelegate(Sak* sak, QObject *parent = 0);
228 QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option,
229 const QModelIndex &index) const;
231 void setEditorData(QWidget *editor, const QModelIndex &index) const;
232 void setModelData(QWidget *editor, QAbstractItemModel *model,
233 const QModelIndex &index) const;
235 void updateEditorGeometry(QWidget *editor,
236 const QStyleOptionViewItem &option, const QModelIndex &index) const;
237 private:
238 Sak* m_sak;
243 #endif