-rw-r--r-- | core/pim/todo/mainwindow.cpp | 50 |
1 files changed, 29 insertions, 21 deletions
diff --git a/core/pim/todo/mainwindow.cpp b/core/pim/todo/mainwindow.cpp index b6ee16f..19a6675 100644 --- a/core/pim/todo/mainwindow.cpp +++ b/core/pim/todo/mainwindow.cpp | |||
@@ -1,861 +1,869 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of the Opie Project | 2 | This file is part of the Opie Project |
3 | 3 | ||
4 | Copyright (C) Opie Team <opie-devel@handhelds.org> | 4 | Copyright (C) Opie Team <opie-devel@handhelds.org> |
5 | =. | 5 | =. |
6 | .=l. | 6 | .=l. |
7 | .>+-= | 7 | .>+-= |
8 | _;:, .> :=|. This program is free software; you can | 8 | _;:, .> :=|. This program is free software; you can |
9 | .> <`_, > . <= redistribute it and/or modify it under | 9 | .> <`_, > . <= redistribute it and/or modify it under |
10 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public | 10 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public |
11 | .="- .-=="i, .._ License as published by the Free Software | 11 | .="- .-=="i, .._ License as published by the Free Software |
12 | - . .-<_> .<> Foundation; either version 2 of the License, | 12 | - . .-<_> .<> Foundation; either version 2 of the License, |
13 | ._= =} : or (at your option) any later version. | 13 | ._= =} : or (at your option) any later version. |
14 | .%`+i> _;_. | 14 | .%`+i> _;_. |
15 | .i_,=:_. -<s. This program is distributed in the hope that | 15 | .i_,=:_. -<s. This program is distributed in the hope that |
16 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | 16 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; |
17 | : .. .:, . . . without even the implied warranty of | 17 | : .. .:, . . . without even the implied warranty of |
18 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | 18 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A |
19 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU | 19 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU |
20 | ..}^=.= = ; Library General Public License for more | 20 | ..}^=.= = ; Library General Public License for more |
21 | ++= -. .` .: details. | 21 | ++= -. .` .: details. |
22 | : = ...= . :.=- | 22 | : = ...= . :.=- |
23 | -. .:....=;==+<; You should have received a copy of the GNU | 23 | -. .:....=;==+<; You should have received a copy of the GNU |
24 | -_. . . )=. = Library General Public License along with | 24 | -_. . . )=. = Library General Public License along with |
25 | -- :-=` this library; see the file COPYING.LIB. | 25 | -- :-=` this library; see the file COPYING.LIB. |
26 | If not, write to the Free Software Foundation, | 26 | If not, write to the Free Software Foundation, |
27 | Inc., 59 Temple Place - Suite 330, | 27 | Inc., 59 Temple Place - Suite 330, |
28 | Boston, MA 02111-1307, USA. | 28 | Boston, MA 02111-1307, USA. |
29 | */ | 29 | */ |
30 | 30 | ||
31 | #include <unistd.h> | 31 | #include <unistd.h> |
32 | 32 | ||
33 | #include <opie2/odebug.h> | 33 | #include <opie2/odebug.h> |
34 | #include <opie2/opimrecurrence.h> | 34 | #include <opie2/opimrecurrence.h> |
35 | #include <opie2/opimnotifymanager.h> | 35 | #include <opie2/opimnotifymanager.h> |
36 | #include <opie2/otodoaccessvcal.h> | 36 | #include <opie2/otodoaccessvcal.h> |
37 | #include <opie2/oapplicationfactory.h> | 37 | #include <opie2/oapplicationfactory.h> |
38 | 38 | ||
39 | #include <qpe/applnk.h> | 39 | #include <qpe/applnk.h> |
40 | #include <qpe/config.h> | 40 | #include <qpe/config.h> |
41 | #include <qpe/ir.h> | 41 | #include <qpe/ir.h> |
42 | #include <qpe/qpemessagebox.h> | 42 | #include <qpe/qpemessagebox.h> |
43 | #include <qpe/alarmserver.h> | 43 | #include <qpe/alarmserver.h> |
44 | #include <qpe/qpeapplication.h> | 44 | #include <qpe/qpeapplication.h> |
45 | 45 | ||
46 | #include <qaction.h> | 46 | #include <qaction.h> |
47 | #include <qlayout.h> | 47 | #include <qlayout.h> |
48 | #include <qmenubar.h> | 48 | #include <qmenubar.h> |
49 | #include <qmessagebox.h> | 49 | #include <qmessagebox.h> |
50 | #include <qpushbutton.h> | 50 | #include <qpushbutton.h> |
51 | #include <qstringlist.h> | 51 | #include <qstringlist.h> |
52 | #include <qtimer.h> | 52 | #include <qtimer.h> |
53 | #include <qwhatsthis.h> | 53 | #include <qwhatsthis.h> |
54 | 54 | ||
55 | #include "quickeditimpl.h" | 55 | #include "quickeditimpl.h" |
56 | #include "todotemplatemanager.h" | 56 | #include "todotemplatemanager.h" |
57 | #include "templatedialogimpl.h" | 57 | #include "templatedialogimpl.h" |
58 | #include "tableview.h" | 58 | #include "tableview.h" |
59 | 59 | ||
60 | #include "textviewshow.h" | 60 | #include "textviewshow.h" |
61 | #include "todoeditor.h" | 61 | #include "todoeditor.h" |
62 | #include "newtaskdlg.h" | 62 | #include "newtaskdlg.h" |
63 | #include "mainwindow.h" | 63 | #include "mainwindow.h" |
64 | 64 | ||
65 | using Opie::Core::OApplicationFactory; | 65 | using Opie::Core::OApplicationFactory; |
66 | OPIE_EXPORT_APP( OApplicationFactory<Todo::MainWindow> ) | 66 | OPIE_EXPORT_APP( OApplicationFactory<Todo::MainWindow> ) |
67 | 67 | ||
68 | using namespace Opie; | 68 | using namespace Opie; |
69 | using namespace Todo; | 69 | using namespace Todo; |
70 | 70 | ||
71 | MainWindow::MainWindow( QWidget* parent, | 71 | MainWindow::MainWindow( QWidget* parent, |
72 | const char* name, WFlags ) | 72 | const char* name, WFlags ) |
73 | : Opie::OPimMainWindow( "Todolist", "Todo List", tr( "Task" ), "todo", | 73 | : Opie::OPimMainWindow( "Todolist", "Todo List", tr( "Task" ), "todo", |
74 | parent, name, WType_TopLevel | WStyle_ContextHelp ) | 74 | parent, name, WType_TopLevel | WStyle_ContextHelp ) |
75 | { | 75 | { |
76 | setCaption( tr( "Todo List" ) ); | 76 | setCaption( tr( "Todo List" ) ); |
77 | if (!name) | 77 | if (!name) |
78 | setName("todo window"); | 78 | setName("todo window"); |
79 | 79 | ||
80 | m_syncing = false; | 80 | m_syncing = false; |
81 | m_showing = false; | 81 | m_showing = false; |
82 | m_counter = 0; | 82 | m_counter = 0; |
83 | m_tempManager = new TemplateManager(); | 83 | m_tempManager = new TemplateManager(); |
84 | m_tempManager->load(); | 84 | m_tempManager->load(); |
85 | 85 | ||
86 | initConfig(); | 86 | initConfig(); |
87 | initUI(); | 87 | initUI(); |
88 | initViews(); | 88 | initViews(); |
89 | initActions(); | 89 | initActions(); |
90 | initEditor(); | 90 | initEditor(); |
91 | initShow(); | 91 | initShow(); |
92 | 92 | ||
93 | raiseCurrentView(); | 93 | raiseCurrentView(); |
94 | QTimer::singleShot( 0, this, SLOT(initStuff()) ); | 94 | QTimer::singleShot( 0, this, SLOT(initStuff()) ); |
95 | } | 95 | } |
96 | void MainWindow::initStuff() { | 96 | void MainWindow::initStuff() { |
97 | m_todoMgr.load(); | 97 | m_todoMgr.load(); |
98 | setViewCategory( m_curCat ); | 98 | setViewCategory( m_curCat ); |
99 | setCategory( m_curCat ); | 99 | setCategory( m_curCat ); |
100 | } | 100 | } |
101 | void MainWindow::initActions() { | 101 | void MainWindow::initActions() { |
102 | // Insert Task menu items | 102 | // Insert Task menu items |
103 | QActionGroup *items = new QActionGroup( this, QString::null, false ); | 103 | QActionGroup *items = new QActionGroup( this, QString::null, false ); |
104 | 104 | ||
105 | m_deleteCompleteAction = new QAction( QString::null, QWidget::tr( "Delete completed" ), | 105 | m_deleteCompleteAction = new QAction( QString::null, QWidget::tr( "Delete completed" ), |
106 | 0, items, 0 ); | 106 | 0, items, 0 ); |
107 | connect( m_deleteCompleteAction, SIGNAL(activated()), this, SLOT(slotDeleteCompleted()) ); | 107 | connect( m_deleteCompleteAction, SIGNAL(activated()), this, SLOT(slotDeleteCompleted()) ); |
108 | 108 | ||
109 | insertItemMenuItems( items ); | 109 | insertItemMenuItems( items ); |
110 | 110 | ||
111 | // Insert View menu items | 111 | // Insert View menu items |
112 | items = new QActionGroup( this, QString::null, false ); | 112 | items = new QActionGroup( this, QString::null, false ); |
113 | 113 | ||
114 | m_completedAction = new QAction( QString::null, QWidget::tr("Show completed tasks"), | 114 | m_completedAction = new QAction( QString::null, QWidget::tr("Show completed tasks"), |
115 | 0, items, 0, true ); | 115 | 0, items, 0, true ); |
116 | m_completedAction->setOn( showCompleted() ); | 116 | m_completedAction->setOn( showCompleted() ); |
117 | connect( m_completedAction, SIGNAL(toggled(bool)), this, SLOT(slotShowCompleted(bool)) ); | 117 | connect( m_completedAction, SIGNAL(toggled(bool)), this, SLOT(slotShowCompleted(bool)) ); |
118 | 118 | ||
119 | QAction *a = new QAction( QString::null, QWidget::tr("Show only over-due tasks"), | 119 | QAction *a = new QAction( QString::null, QWidget::tr("Show only over-due tasks"), |
120 | 0, items, 0, true ); | 120 | 0, items, 0, true ); |
121 | a->setOn( showOverDue() ); | 121 | a->setOn( showOverDue() ); |
122 | connect( a, SIGNAL(toggled(bool)), this, SLOT(slotShowDue(bool)) ); | 122 | connect( a, SIGNAL(toggled(bool)), this, SLOT(slotShowDue(bool)) ); |
123 | 123 | ||
124 | m_showDeadLineAction = new QAction( QString::null, QWidget::tr("Show task deadlines"), | 124 | m_showDeadLineAction = new QAction( QString::null, QWidget::tr("Show task deadlines"), |
125 | 0, items, 0, true ); | 125 | 0, items, 0, true ); |
126 | m_showDeadLineAction->setOn( showDeadline() ); | 126 | m_showDeadLineAction->setOn( showDeadline() ); |
127 | connect( m_showDeadLineAction, SIGNAL(toggled(bool)), this, SLOT(slotShowDeadLine(bool)) ); | 127 | connect( m_showDeadLineAction, SIGNAL(toggled(bool)), this, SLOT(slotShowDeadLine(bool)) ); |
128 | 128 | ||
129 | m_showQuickTaskAction = new QAction( QString::null, QWidget::tr("Show quick task bar"), | 129 | m_showQuickTaskAction = new QAction( QString::null, QWidget::tr("Show quick task bar"), |
130 | 0, items, 0, true ); | 130 | 0, items, 0, true ); |
131 | m_showQuickTaskAction->setOn( showQuickTask() ); | 131 | m_showQuickTaskAction->setOn( showQuickTask() ); |
132 | connect( m_showQuickTaskAction, SIGNAL(toggled(bool)), this, SLOT(slotShowQuickTask(bool)) ); | 132 | connect( m_showQuickTaskAction, SIGNAL(toggled(bool)), this, SLOT(slotShowQuickTask(bool)) ); |
133 | 133 | ||
134 | insertViewMenuItems( items ); | 134 | insertViewMenuItems( items ); |
135 | } | 135 | } |
136 | /* m_curCat from Config */ | 136 | /* m_curCat from Config */ |
137 | void MainWindow::initConfig() { | 137 | void MainWindow::initConfig() { |
138 | Config config( "todo" ); | 138 | Config config( "todo" ); |
139 | config.setGroup( "View" ); | 139 | config.setGroup( "View" ); |
140 | m_completed = config.readBoolEntry( "ShowComplete", true ); | 140 | m_completed = config.readBoolEntry( "ShowComplete", true ); |
141 | m_curCat = config.readEntry( "Category", QString::null ); | 141 | m_curCat = config.readEntry( "Category", QString::null ); |
142 | m_deadline = config.readBoolEntry( "ShowDeadLine", true); | 142 | m_deadline = config.readBoolEntry( "ShowDeadLine", true); |
143 | m_overdue = config.readBoolEntry("ShowOverDue", false ); | 143 | m_overdue = config.readBoolEntry("ShowOverDue", false ); |
144 | m_quicktask = config.readBoolEntry("ShowQuickTask", true); | 144 | m_quicktask = config.readBoolEntry("ShowQuickTask", true); |
145 | } | 145 | } |
146 | void MainWindow::initUI() { | 146 | void MainWindow::initUI() { |
147 | // Create main widget stack | 147 | // Create main widget stack |
148 | m_stack = new Opie::Ui::OWidgetStack(this, "main stack"); | 148 | m_stack = new Opie::Ui::OWidgetStack(this, "main stack"); |
149 | setCentralWidget( m_stack ); | 149 | setCentralWidget( m_stack ); |
150 | connect( this, SIGNAL(categorySelected(const QString&)), | 150 | connect( this, SIGNAL(categorySelected(const QString&)), |
151 | this, SLOT(setCategory(const QString&)) ); | 151 | this, SLOT(setCategory(const QString&)) ); |
152 | 152 | ||
153 | // Create quick task toolbar | 153 | // Create quick task toolbar |
154 | m_curQuick = new QuickEditImpl( this, m_quicktask ); | 154 | m_curQuick = new QuickEditImpl( this, m_quicktask ); |
155 | addToolBar( (QToolBar *)m_curQuick->widget(), QWidget::tr( "QuickEdit" ), | 155 | addToolBar( (QToolBar *)m_curQuick->widget(), QWidget::tr( "QuickEdit" ), |
156 | QMainWindow::Top, true ); | 156 | QMainWindow::Top, true ); |
157 | m_curQuick->signal()->connect( this, SLOT(slotQuickEntered()) ); | 157 | m_curQuick->signal()->connect( this, SLOT(slotQuickEntered()) ); |
158 | } | 158 | } |
159 | void MainWindow::initViews() { | 159 | void MainWindow::initViews() { |
160 | 160 | ||
161 | TableView* tableView = new TableView( this, m_stack ); | 161 | TableView* tableView = new TableView( this, m_stack ); |
162 | QWhatsThis::add( tableView, QWidget::tr( "This is a listing of all current tasks.\n\nThe list displays the following information:\n1. Completed - A green checkmark indicates task is completed. Click here to complete a task.\n2. Priority - a graphical representation of task priority. Double-click here to modify.\n3. Description - description of task. Click here to select the task.\n4. Deadline - shows when task is due. This column can be shown or hidden by selecting Options->'Show task deadlines' from the menu above." ) ); | 162 | QWhatsThis::add( tableView, QWidget::tr( "This is a listing of all current tasks.\n\nThe list displays the following information:\n1. Completed - A green checkmark indicates task is completed. Click here to complete a task.\n2. Priority - a graphical representation of task priority. Double-click here to modify.\n3. Description - description of task. Click here to select the task.\n4. Deadline - shows when task is due. This column can be shown or hidden by selecting Options->'Show task deadlines' from the menu above." ) ); |
163 | m_stack->addWidget( tableView, m_counter++ ); | 163 | m_stack->addWidget( tableView, m_counter++ ); |
164 | m_views.append( tableView ); | 164 | m_views.append( tableView ); |
165 | m_curView = tableView; | 165 | m_curView = tableView; |
166 | connectBase( tableView ); | 166 | connectBase( tableView ); |
167 | /* add QString type + QString configname to | 167 | /* add QString type + QString configname to |
168 | * the View menu | 168 | * the View menu |
169 | * and subdirs for multiple views | 169 | * and subdirs for multiple views |
170 | */ | 170 | */ |
171 | } | 171 | } |
172 | void MainWindow::initEditor() { | 172 | void MainWindow::initEditor() { |
173 | m_curEdit = new Editor(); | 173 | m_curEdit = new Editor(); |
174 | } | 174 | } |
175 | void MainWindow::initShow() { | 175 | void MainWindow::initShow() { |
176 | m_curShow = new TextViewShow(this, this); | 176 | m_curShow = new TextViewShow(this, this); |
177 | m_stack->addWidget( m_curShow->widget() , m_counter++ ); | 177 | m_stack->addWidget( m_curShow->widget() , m_counter++ ); |
178 | } | 178 | } |
179 | MainWindow::~MainWindow() { | 179 | MainWindow::~MainWindow() { |
180 | delete templateManager(); | 180 | delete templateManager(); |
181 | } | 181 | } |
182 | void MainWindow::connectBase( ViewBase* ) { | 182 | void MainWindow::connectBase( ViewBase* ) { |
183 | // once templates and signals mix we'll use it again | 183 | // once templates and signals mix we'll use it again |
184 | } | 184 | } |
185 | QPopupMenu* MainWindow::contextMenu( int , bool /*recur*/ ) { | 185 | QPopupMenu* MainWindow::contextMenu( int , bool /*recur*/ ) { |
186 | return itemContextMenu(); | 186 | return itemContextMenu(); |
187 | } | 187 | } |
188 | OPimTodoAccess::List MainWindow::list()const { | 188 | OPimTodoAccess::List MainWindow::list()const { |
189 | return m_todoMgr.list(); | 189 | return m_todoMgr.list(); |
190 | } | 190 | } |
191 | OPimTodoAccess::List MainWindow::sorted( bool asc, int sortOrder ) { | 191 | OPimTodoAccess::List MainWindow::sorted( bool asc, int sortOrder ) { |
192 | int cat = 0; | 192 | int cat = 0; |
193 | if ( m_curCat != tr( "All" ) ) | 193 | if ( m_curCat != tr( "All" ) ) |
194 | cat = currentCatId(); | 194 | cat = currentCatId(); |
195 | if ( m_curCat == tr( "Unfiled" ) ) | 195 | if ( m_curCat == tr( "Unfiled" ) ) |
196 | cat = -1; | 196 | cat = -1; |
197 | 197 | ||
198 | int filter = OPimTodoAccess::FilterCategory; | 198 | int filter = OPimTodoAccess::FilterCategory; |
199 | 199 | ||
200 | if (!m_completed ) | 200 | if (!m_completed ) |
201 | filter |= OPimTodoAccess::DoNotShowCompleted; | 201 | filter |= OPimTodoAccess::DoNotShowCompleted; |
202 | if (m_overdue) | 202 | if (m_overdue) |
203 | filter |= OPimTodoAccess::OnlyOverDue; | 203 | filter |= OPimTodoAccess::OnlyOverDue; |
204 | 204 | ||
205 | return m_todoMgr.sorted( asc, sortOrder, filter, cat ); | 205 | return m_todoMgr.sorted( asc, sortOrder, filter, cat ); |
206 | } | 206 | } |
207 | OPimTodoAccess::List MainWindow::sorted( bool asc, int sortOrder, int addFilter) { | 207 | OPimTodoAccess::List MainWindow::sorted( bool asc, int sortOrder, int addFilter) { |
208 | int cat = 0; | 208 | int cat = 0; |
209 | if ( m_curCat != tr( "All" ) ) | 209 | if ( m_curCat != tr( "All" ) ) |
210 | cat = currentCatId(); | 210 | cat = currentCatId(); |
211 | 211 | ||
212 | if ( m_curCat == tr( "Unfiled" ) ) | 212 | if ( m_curCat == tr( "Unfiled" ) ) |
213 | cat = -1; | 213 | cat = -1; |
214 | 214 | ||
215 | return m_todoMgr.sorted(asc, sortOrder, addFilter, cat ); | 215 | return m_todoMgr.sorted(asc, sortOrder, addFilter, cat ); |
216 | } | 216 | } |
217 | OPimTodo MainWindow::event( int uid ) { | 217 | OPimTodo MainWindow::event( int uid ) { |
218 | return m_todoMgr.event( uid ); | 218 | return m_todoMgr.event( uid ); |
219 | } | 219 | } |
220 | bool MainWindow::isSyncing()const { | 220 | bool MainWindow::isSyncing()const { |
221 | return m_syncing; | 221 | return m_syncing; |
222 | } | 222 | } |
223 | TemplateManager* MainWindow::templateManager() { | 223 | TemplateManager* MainWindow::templateManager() { |
224 | return m_tempManager; | 224 | return m_tempManager; |
225 | } | 225 | } |
226 | Editor* MainWindow::currentEditor() { | 226 | Editor* MainWindow::currentEditor() { |
227 | return m_curEdit; | 227 | return m_curEdit; |
228 | } | 228 | } |
229 | TodoShow* MainWindow::currentShow() { | 229 | TodoShow* MainWindow::currentShow() { |
230 | return m_curShow; | 230 | return m_curShow; |
231 | } | 231 | } |
232 | void MainWindow::slotReload() { | 232 | void MainWindow::slotReload() { |
233 | m_syncing = false; | 233 | m_syncing = false; |
234 | m_todoMgr.reload(); | 234 | m_todoMgr.reload(); |
235 | currentView()->updateView( ); | 235 | currentView()->updateView( ); |
236 | raiseCurrentView(); | 236 | raiseCurrentView(); |
237 | } | 237 | } |
238 | void MainWindow::closeEvent( QCloseEvent* e ) { | 238 | void MainWindow::closeEvent( QCloseEvent* e ) { |
239 | if (m_stack->visibleWidget() == currentShow()->widget() ) { | 239 | if (m_stack->visibleWidget() == currentShow()->widget() ) { |
240 | m_showing = false; | 240 | m_showing = false; |
241 | raiseCurrentView(); | 241 | raiseCurrentView(); |
242 | e->ignore(); | 242 | e->ignore(); |
243 | return; | 243 | return; |
244 | } | 244 | } |
245 | /* | 245 | /* |
246 | * we should have flushed and now we're still saving | 246 | * we should have flushed and now we're still saving |
247 | * so there is no need to flush | 247 | * so there is no need to flush |
248 | */ | 248 | */ |
249 | if (m_syncing ) { | 249 | if (m_syncing ) { |
250 | e->accept(); | 250 | e->accept(); |
251 | return; | 251 | return; |
252 | } | 252 | } |
253 | bool quit = false; | 253 | bool quit = false; |
254 | if ( m_todoMgr.saveAll() ){ | 254 | if ( m_todoMgr.saveAll() ){ |
255 | quit = true; | 255 | quit = true; |
256 | }else { | 256 | }else { |
257 | if ( QMessageBox::critical( this, QWidget::tr("Out of space"), | 257 | if ( QMessageBox::critical( this, QWidget::tr("Out of space"), |
258 | QWidget::tr("Todo was unable\n" | 258 | QWidget::tr("Todo was unable\n" |
259 | "to save your changes.\n" | 259 | "to save your changes.\n" |
260 | "Free up some space\n" | 260 | "Free up some space\n" |
261 | "and try again.\n" | 261 | "and try again.\n" |
262 | "\nQuit Anyway?"), | 262 | "\nQuit Anyway?"), |
263 | QMessageBox::Yes|QMessageBox::Escape, | 263 | QMessageBox::Yes|QMessageBox::Escape, |
264 | QMessageBox::No|QMessageBox::Default) | 264 | QMessageBox::No|QMessageBox::Default) |
265 | != QMessageBox::No ) { | 265 | != QMessageBox::No ) { |
266 | e->accept(); | 266 | e->accept(); |
267 | quit = true; | 267 | quit = true; |
268 | }else | 268 | }else |
269 | e->ignore(); | 269 | e->ignore(); |
270 | 270 | ||
271 | } | 271 | } |
272 | 272 | ||
273 | if (quit ) { | 273 | if (quit ) { |
274 | Config config( "todo" ); | 274 | Config config( "todo" ); |
275 | config.setGroup( "View" ); | 275 | config.setGroup( "View" ); |
276 | config.writeEntry( "ShowComplete", showCompleted() ); | 276 | config.writeEntry( "ShowComplete", showCompleted() ); |
277 | config.writeEntry( "Category", currentCategory() ); | 277 | config.writeEntry( "Category", currentCategory() ); |
278 | config.writeEntry( "ShowDeadLine", showDeadline()); | 278 | config.writeEntry( "ShowDeadLine", showDeadline()); |
279 | config.writeEntry( "ShowOverDue", showOverDue() ); | 279 | config.writeEntry( "ShowOverDue", showOverDue() ); |
280 | config.writeEntry( "ShowQuickTask", showQuickTask() ); | 280 | config.writeEntry( "ShowQuickTask", showQuickTask() ); |
281 | /* save templates */ | 281 | /* save templates */ |
282 | templateManager()->save(); | 282 | templateManager()->save(); |
283 | e->accept(); | 283 | e->accept(); |
284 | QTimer::singleShot(0, qApp, SLOT(closeAllWindows()) ); | 284 | QTimer::singleShot(0, qApp, SLOT(closeAllWindows()) ); |
285 | } | 285 | } |
286 | } | 286 | } |
287 | void MainWindow::slotItemNew() { | 287 | void MainWindow::slotItemNew() { |
288 | NewTaskDlg dlg( templateManager()->templates(), this ); | 288 | QStringList templateList = templateManager()->templates(); |
289 | if ( QPEApplication::execDialog( &dlg ) == QDialog::Accepted ) { | 289 | if(templateList.isEmpty()) { |
290 | QString tempName = dlg.tempSelected(); | 290 | // No templates, just create a blank task |
291 | if ( tempName.isNull() ) | 291 | create(); |
292 | // Create new, blank task | 292 | } |
293 | create(); | 293 | else { |
294 | else { | 294 | // There are templates, so allow the user to select one |
295 | // Create new task from the template selected | 295 | NewTaskDlg dlg( templateList, this ); |
296 | OPimTodo event = templateManager()->templateEvent( tempName ); | 296 | if ( QPEApplication::execDialog( &dlg ) == QDialog::Accepted ) { |
297 | event = currentEditor()->edit( this, event ); | 297 | QString tempName = dlg.tempSelected(); |
298 | if ( currentEditor()->accepted() ) { | 298 | if ( tempName.isNull() ) |
299 | event.setUid( 1 ); | 299 | // Create new, blank task |
300 | handleAlarms( OPimTodo(), event ); | 300 | create(); |
301 | m_todoMgr.add( event ); | 301 | else { |
302 | currentView()->addEvent( event ); | 302 | // Create new task from the template selected |
303 | 303 | OPimTodo event = templateManager()->templateEvent( tempName ); | |
304 | reloadCategories(); | 304 | event = currentEditor()->edit( this, event ); |
305 | } | 305 | if ( currentEditor()->accepted() ) { |
306 | raiseCurrentView(); | 306 | event.setUid( 1 ); |
307 | } | 307 | handleAlarms( OPimTodo(), event ); |
308 | } | 308 | m_todoMgr.add( event ); |
309 | currentView()->addEvent( event ); | ||
310 | |||
311 | reloadCategories(); | ||
312 | } | ||
313 | raiseCurrentView(); | ||
314 | } | ||
315 | } | ||
316 | } | ||
309 | } | 317 | } |
310 | void MainWindow::slotItemEdit() { | 318 | void MainWindow::slotItemEdit() { |
311 | slotEdit( currentView()->current() ); | 319 | slotEdit( currentView()->current() ); |
312 | } | 320 | } |
313 | void MainWindow::slotItemDuplicate() { | 321 | void MainWindow::slotItemDuplicate() { |
314 | if(m_syncing) { | 322 | if(m_syncing) { |
315 | QMessageBox::warning(this, QWidget::tr("Todo"), | 323 | QMessageBox::warning(this, QWidget::tr("Todo"), |
316 | QWidget::tr("Data can not be edited, currently syncing")); | 324 | QWidget::tr("Data can not be edited, currently syncing")); |
317 | return; | 325 | return; |
318 | } | 326 | } |
319 | OPimTodo ev = m_todoMgr.event( currentView()->current() ); | 327 | OPimTodo ev = m_todoMgr.event( currentView()->current() ); |
320 | /* let's generate a new uid */ | 328 | /* let's generate a new uid */ |
321 | ev.setUid(1); | 329 | ev.setUid(1); |
322 | m_todoMgr.add( ev ); | 330 | m_todoMgr.add( ev ); |
323 | 331 | ||
324 | currentView()->addEvent( ev ); | 332 | currentView()->addEvent( ev ); |
325 | raiseCurrentView(); | 333 | raiseCurrentView(); |
326 | } | 334 | } |
327 | void MainWindow::slotItemDelete() { | 335 | void MainWindow::slotItemDelete() { |
328 | if (!currentView()->current() ) | 336 | if (!currentView()->current() ) |
329 | return; | 337 | return; |
330 | 338 | ||
331 | if(m_syncing) { | 339 | if(m_syncing) { |
332 | QMessageBox::warning(this, QWidget::tr("Todo"), | 340 | QMessageBox::warning(this, QWidget::tr("Todo"), |
333 | QWidget::tr("Data can not be edited, currently syncing")); | 341 | QWidget::tr("Data can not be edited, currently syncing")); |
334 | return; | 342 | return; |
335 | } | 343 | } |
336 | QString strName = currentView()->currentRepresentation(); | 344 | QString strName = currentView()->currentRepresentation(); |
337 | if (!QPEMessageBox::confirmDelete(this, QWidget::tr("Todo"), strName ) ) | 345 | if (!QPEMessageBox::confirmDelete(this, QWidget::tr("Todo"), strName ) ) |
338 | return; | 346 | return; |
339 | 347 | ||
340 | handleAlarms( m_todoMgr.event( currentView()->current() ), OPimTodo() ); | 348 | handleAlarms( m_todoMgr.event( currentView()->current() ), OPimTodo() ); |
341 | m_todoMgr.remove( currentView()->current() ); | 349 | m_todoMgr.remove( currentView()->current() ); |
342 | currentView()->removeEvent( currentView()->current() ); | 350 | currentView()->removeEvent( currentView()->current() ); |
343 | raiseCurrentView(); | 351 | raiseCurrentView(); |
344 | } | 352 | } |
345 | 353 | ||
346 | static const char *beamfile = "/tmp/opie-todo.vcs"; | 354 | static const char *beamfile = "/tmp/opie-todo.vcs"; |
347 | void MainWindow::slotItemBeam() { | 355 | void MainWindow::slotItemBeam() { |
348 | beam( currentView()->current() ); | 356 | beam( currentView()->current() ); |
349 | } | 357 | } |
350 | void MainWindow::slotItemFind() { | 358 | void MainWindow::slotItemFind() { |
351 | } | 359 | } |
352 | void MainWindow::slotConfigure() { | 360 | void MainWindow::slotConfigure() { |
353 | TemplateDialogImpl dlg( this, m_tempManager ); | 361 | TemplateDialogImpl dlg( this, m_tempManager ); |
354 | if ( QPEApplication::execDialog( &dlg ) != QDialog::Accepted ) | 362 | if ( QPEApplication::execDialog( &dlg ) != QDialog::Accepted ) |
355 | m_tempManager->load(); | 363 | m_tempManager->load(); |
356 | } | 364 | } |
357 | void MainWindow::slotDelete(int uid ) { | 365 | void MainWindow::slotDelete(int uid ) { |
358 | if( uid == 0 ) return; | 366 | if( uid == 0 ) return; |
359 | if(m_syncing) { | 367 | if(m_syncing) { |
360 | QMessageBox::warning(this, QWidget::tr("Todo"), | 368 | QMessageBox::warning(this, QWidget::tr("Todo"), |
361 | QWidget::tr("Data can not be edited, currently syncing")); | 369 | QWidget::tr("Data can not be edited, currently syncing")); |
362 | return; | 370 | return; |
363 | } | 371 | } |
364 | OPimTodo to = m_todoMgr.event(uid); | 372 | OPimTodo to = m_todoMgr.event(uid); |
365 | if (!QPEMessageBox::confirmDelete(this, QWidget::tr("Todo"), to.toShortText() ) ) | 373 | if (!QPEMessageBox::confirmDelete(this, QWidget::tr("Todo"), to.toShortText() ) ) |
366 | return; | 374 | return; |
367 | 375 | ||
368 | handleAlarms(to, OPimTodo() ); | 376 | handleAlarms(to, OPimTodo() ); |
369 | m_todoMgr.remove( to.uid() ); | 377 | m_todoMgr.remove( to.uid() ); |
370 | currentView()->removeEvent( to.uid() ); | 378 | currentView()->removeEvent( to.uid() ); |
371 | raiseCurrentView(); | 379 | raiseCurrentView(); |
372 | } | 380 | } |
373 | void MainWindow::slotDeleteAll() { | 381 | void MainWindow::slotDeleteAll() { |
374 | if(m_syncing) { | 382 | if(m_syncing) { |
375 | QMessageBox::warning(this, QWidget::tr("Todo"), | 383 | QMessageBox::warning(this, QWidget::tr("Todo"), |
376 | QWidget::tr("Data can not be edited, currently syncing")); | 384 | QWidget::tr("Data can not be edited, currently syncing")); |
377 | return; | 385 | return; |
378 | } | 386 | } |
379 | 387 | ||
380 | 388 | ||
381 | if ( !QPEMessageBox::confirmDelete( this, QWidget::tr( "Todo" ), QWidget::tr("all tasks?") ) ) | 389 | if ( !QPEMessageBox::confirmDelete( this, QWidget::tr( "Todo" ), QWidget::tr("all tasks?") ) ) |
382 | return; | 390 | return; |
383 | 391 | ||
384 | m_todoMgr.removeAll(); | 392 | m_todoMgr.removeAll(); |
385 | currentView()->clear(); | 393 | currentView()->clear(); |
386 | 394 | ||
387 | raiseCurrentView(); | 395 | raiseCurrentView(); |
388 | } | 396 | } |
389 | void MainWindow::slotDeleteCompleted() { | 397 | void MainWindow::slotDeleteCompleted() { |
390 | if(m_syncing) { | 398 | if(m_syncing) { |
391 | QMessageBox::warning(this, QWidget::tr("Todo"), | 399 | QMessageBox::warning(this, QWidget::tr("Todo"), |
392 | QWidget::tr("Data can not be edited, currently syncing")); | 400 | QWidget::tr("Data can not be edited, currently syncing")); |
393 | return; | 401 | return; |
394 | } | 402 | } |
395 | 403 | ||
396 | if ( !QPEMessageBox::confirmDelete( this, QWidget::tr( "Todo" ), QWidget::tr("all completed tasks?") ) ) | 404 | if ( !QPEMessageBox::confirmDelete( this, QWidget::tr( "Todo" ), QWidget::tr("all completed tasks?") ) ) |
397 | return; | 405 | return; |
398 | 406 | ||
399 | 407 | ||
400 | m_todoMgr.removeCompleted(); | 408 | m_todoMgr.removeCompleted(); |
401 | currentView()->updateView( ); | 409 | currentView()->updateView( ); |
402 | } | 410 | } |
403 | /* | 411 | /* |
404 | * set the category | 412 | * set the category |
405 | */ | 413 | */ |
406 | void MainWindow::setCategory( const QString &category ) { | 414 | void MainWindow::setCategory( const QString &category ) { |
407 | m_curCat = category; | 415 | m_curCat = category; |
408 | if ( m_curCat == tr( "All" ) ) | 416 | if ( m_curCat == tr( "All" ) ) |
409 | m_curCat = QString::null; | 417 | m_curCat = QString::null; |
410 | 418 | ||
411 | currentView()->setShowCategory( m_curCat ); | 419 | currentView()->setShowCategory( m_curCat ); |
412 | raiseCurrentView(); | 420 | raiseCurrentView(); |
413 | } | 421 | } |
414 | void MainWindow::slotShowDeadLine( bool dead) { | 422 | void MainWindow::slotShowDeadLine( bool dead) { |
415 | m_deadline = dead; | 423 | m_deadline = dead; |
416 | currentView()->setShowDeadline( dead ); | 424 | currentView()->setShowDeadline( dead ); |
417 | } | 425 | } |
418 | void MainWindow::slotShowCompleted( bool show) { | 426 | void MainWindow::slotShowCompleted( bool show) { |
419 | m_completed = show; | 427 | m_completed = show; |
420 | currentView()->setShowCompleted( m_completed ); | 428 | currentView()->setShowCompleted( m_completed ); |
421 | } | 429 | } |
422 | void MainWindow::slotShowQuickTask( bool show ) { | 430 | void MainWindow::slotShowQuickTask( bool show ) { |
423 | m_quicktask = show; | 431 | m_quicktask = show; |
424 | if ( m_quicktask ) | 432 | if ( m_quicktask ) |
425 | m_curQuick->widget()->show(); | 433 | m_curQuick->widget()->show(); |
426 | else | 434 | else |
427 | m_curQuick->widget()->hide(); | 435 | m_curQuick->widget()->hide(); |
428 | } | 436 | } |
429 | bool MainWindow::showOverDue()const { | 437 | bool MainWindow::showOverDue()const { |
430 | return m_overdue; | 438 | return m_overdue; |
431 | } | 439 | } |
432 | void MainWindow::setDocument( const QString& fi) { | 440 | void MainWindow::setDocument( const QString& fi) { |
433 | DocLnk doc(fi); | 441 | DocLnk doc(fi); |
434 | if (doc.isValid() ) | 442 | if (doc.isValid() ) |
435 | receiveFile(doc.file() ); | 443 | receiveFile(doc.file() ); |
436 | else | 444 | else |
437 | receiveFile(fi ); | 445 | receiveFile(fi ); |
438 | } | 446 | } |
439 | void MainWindow::beamDone( Ir* ir) { | 447 | void MainWindow::beamDone( Ir* ir) { |
440 | delete ir; | 448 | delete ir; |
441 | ::unlink( beamfile ); | 449 | ::unlink( beamfile ); |
442 | } | 450 | } |
443 | void MainWindow::receiveFile( const QString& filename ) { | 451 | void MainWindow::receiveFile( const QString& filename ) { |
444 | OPimTodoAccessVCal* cal = new OPimTodoAccessVCal(filename ); | 452 | OPimTodoAccessVCal* cal = new OPimTodoAccessVCal(filename ); |
445 | 453 | ||
446 | OPimTodoAccess acc( cal ); | 454 | OPimTodoAccess acc( cal ); |
447 | acc.load(); | 455 | acc.load(); |
448 | OPimTodoAccess::List list = acc.allRecords(); | 456 | OPimTodoAccess::List list = acc.allRecords(); |
449 | 457 | ||
450 | if (list.count()){ | 458 | if (list.count()){ |
451 | 459 | ||
452 | QString message = QWidget::tr("<P>%1 new tasks arrived.<p>Would you like to add them to your Todolist?").arg(list.count() ); | 460 | QString message = QWidget::tr("<P>%1 new tasks arrived.<p>Would you like to add them to your Todolist?").arg(list.count() ); |
453 | 461 | ||
454 | if ( QMessageBox::information(this, QWidget::tr("New Tasks"), | 462 | if ( QMessageBox::information(this, QWidget::tr("New Tasks"), |
455 | message, QMessageBox::Ok, | 463 | message, QMessageBox::Ok, |
456 | QMessageBox::Cancel ) == QMessageBox::Ok ) { | 464 | QMessageBox::Cancel ) == QMessageBox::Ok ) { |
457 | OPimTodoAccess::List::Iterator it; | 465 | OPimTodoAccess::List::Iterator it; |
458 | for ( it = list.begin(); it != list.end(); ++it ) | 466 | for ( it = list.begin(); it != list.end(); ++it ) |
459 | m_todoMgr.add( (*it) ); | 467 | m_todoMgr.add( (*it) ); |
460 | 468 | ||
461 | currentView()->updateView(); | 469 | currentView()->updateView(); |
462 | } | 470 | } |
463 | } | 471 | } |
464 | } | 472 | } |
465 | 473 | ||
466 | void MainWindow::slotFlush() { | 474 | void MainWindow::slotFlush() { |
467 | m_syncing = true; | 475 | m_syncing = true; |
468 | m_todoMgr.save(); | 476 | m_todoMgr.save(); |
469 | } | 477 | } |
470 | void MainWindow::slotShowDetails() { | 478 | void MainWindow::slotShowDetails() { |
471 | slotShow( currentView()->current() ); | 479 | slotShow( currentView()->current() ); |
472 | } | 480 | } |
473 | bool MainWindow::showCompleted()const { | 481 | bool MainWindow::showCompleted()const { |
474 | return m_completed; | 482 | return m_completed; |
475 | } | 483 | } |
476 | bool MainWindow::showDeadline()const { | 484 | bool MainWindow::showDeadline()const { |
477 | return m_deadline; | 485 | return m_deadline; |
478 | } | 486 | } |
479 | bool MainWindow::showQuickTask()const { | 487 | bool MainWindow::showQuickTask()const { |
480 | return m_quicktask; | 488 | return m_quicktask; |
481 | } | 489 | } |
482 | QString MainWindow::currentCategory()const { | 490 | QString MainWindow::currentCategory()const { |
483 | return m_curCat; | 491 | return m_curCat; |
484 | } | 492 | } |
485 | int MainWindow::currentCatId() { | 493 | int MainWindow::currentCatId() { |
486 | return m_todoMgr.catId( m_curCat ); | 494 | return m_todoMgr.catId( m_curCat ); |
487 | } | 495 | } |
488 | ViewBase* MainWindow::currentView() { | 496 | ViewBase* MainWindow::currentView() { |
489 | return m_curView; | 497 | return m_curView; |
490 | } | 498 | } |
491 | void MainWindow::raiseCurrentView() { | 499 | void MainWindow::raiseCurrentView() { |
492 | // due QPE/Application/todolist show(int) | 500 | // due QPE/Application/todolist show(int) |
493 | // we might not have the populateCategories slot called once | 501 | // we might not have the populateCategories slot called once |
494 | // we would show the otodo but then imediately switch to the currentView | 502 | // we would show the otodo but then imediately switch to the currentView |
495 | // if we're initially showing we shouldn't raise the table | 503 | // if we're initially showing we shouldn't raise the table |
496 | // in returnFromView we fix up m_showing | 504 | // in returnFromView we fix up m_showing |
497 | if (m_showing ) return; | 505 | if (m_showing ) return; |
498 | 506 | ||
499 | m_stack->raiseWidget( m_curView->widget() ); | 507 | m_stack->raiseWidget( m_curView->widget() ); |
500 | } | 508 | } |
501 | void MainWindow::slotShowDue(bool ov) { | 509 | void MainWindow::slotShowDue(bool ov) { |
502 | m_overdue = ov; | 510 | m_overdue = ov; |
503 | currentView()->showOverDue( ov ); | 511 | currentView()->showOverDue( ov ); |
504 | raiseCurrentView(); | 512 | raiseCurrentView(); |
505 | } | 513 | } |
506 | void MainWindow::slotShow( int uid ) { | 514 | void MainWindow::slotShow( int uid ) { |
507 | if ( uid == 0 ) return; | 515 | if ( uid == 0 ) return; |
508 | 516 | ||
509 | 517 | ||
510 | currentShow()->slotShow( event( uid ) ); | 518 | currentShow()->slotShow( event( uid ) ); |
511 | m_stack->raiseWidget( currentShow()->widget() ); | 519 | m_stack->raiseWidget( currentShow()->widget() ); |
512 | } | 520 | } |
513 | void MainWindow::slotShowNext() { | 521 | void MainWindow::slotShowNext() { |
514 | int l = currentView()->next(); | 522 | int l = currentView()->next(); |
515 | if (l!=0) | 523 | if (l!=0) |
516 | slotShow(l); | 524 | slotShow(l); |
517 | } | 525 | } |
518 | void MainWindow::slotShowPrev() { | 526 | void MainWindow::slotShowPrev() { |
519 | int l = currentView()->prev(); | 527 | int l = currentView()->prev(); |
520 | if (l!=0) | 528 | if (l!=0) |
521 | slotShow(l); | 529 | slotShow(l); |
522 | } | 530 | } |
523 | void MainWindow::slotEdit( int uid ) { | 531 | void MainWindow::slotEdit( int uid ) { |
524 | if (uid == 0 ) return; | 532 | if (uid == 0 ) return; |
525 | if(m_syncing) { | 533 | if(m_syncing) { |
526 | QMessageBox::warning(this, QWidget::tr("Todo"), | 534 | QMessageBox::warning(this, QWidget::tr("Todo"), |
527 | QWidget::tr("Data can't be edited, currently syncing")); | 535 | QWidget::tr("Data can't be edited, currently syncing")); |
528 | return; | 536 | return; |
529 | } | 537 | } |
530 | 538 | ||
531 | OPimTodo old_todo = m_todoMgr.event( uid ); | 539 | OPimTodo old_todo = m_todoMgr.event( uid ); |
532 | 540 | ||
533 | OPimTodo todo = currentEditor()->edit(this, old_todo ); | 541 | OPimTodo todo = currentEditor()->edit(this, old_todo ); |
534 | 542 | ||
535 | /* if completed */ | 543 | /* if completed */ |
536 | if ( currentEditor()->accepted() ) { | 544 | if ( currentEditor()->accepted() ) { |
537 | handleAlarms( old_todo, todo ); | 545 | handleAlarms( old_todo, todo ); |
538 | m_todoMgr.update( todo.uid(), todo ); | 546 | m_todoMgr.update( todo.uid(), todo ); |
539 | currentView()->replaceEvent( todo ); | 547 | currentView()->replaceEvent( todo ); |
540 | /* a Category might have changed */ | 548 | /* a Category might have changed */ |
541 | reloadCategories(); | 549 | reloadCategories(); |
542 | } | 550 | } |
543 | 551 | ||
544 | raiseCurrentView(); | 552 | raiseCurrentView(); |
545 | } | 553 | } |
546 | /* | 554 | /* |
547 | void MainWindow::slotUpdate1( int uid, const SmallTodo& ev) { | 555 | void MainWindow::slotUpdate1( int uid, const SmallTodo& ev) { |
548 | m_todoMgr.update( uid, ev ); | 556 | m_todoMgr.update( uid, ev ); |
549 | } | 557 | } |
550 | */ | 558 | */ |
551 | void MainWindow::updateTodo( const OPimTodo& ev) { | 559 | void MainWindow::updateTodo( const OPimTodo& ev) { |
552 | m_todoMgr.update( ev.uid() , ev ); | 560 | m_todoMgr.update( ev.uid() , ev ); |
553 | } | 561 | } |
554 | /* The view changed it's configuration | 562 | /* The view changed it's configuration |
555 | * update the view menu | 563 | * update the view menu |
556 | */ | 564 | */ |
557 | void MainWindow::slotUpdate3( QWidget* ) { | 565 | void MainWindow::slotUpdate3( QWidget* ) { |
558 | 566 | ||
559 | } | 567 | } |
560 | void MainWindow::updateList() { | 568 | void MainWindow::updateList() { |
561 | m_todoMgr.updateList(); | 569 | m_todoMgr.updateList(); |
562 | } | 570 | } |
563 | void MainWindow::setReadAhead( uint count ) { | 571 | void MainWindow::setReadAhead( uint count ) { |
564 | if (m_todoMgr.todoDB() ) | 572 | if (m_todoMgr.todoDB() ) |
565 | m_todoMgr.todoDB()->setReadAhead( count ); | 573 | m_todoMgr.todoDB()->setReadAhead( count ); |
566 | } | 574 | } |
567 | void MainWindow::slotQuickEntered() { | 575 | void MainWindow::slotQuickEntered() { |
568 | OPimTodo todo = quickEditor()->todo(); | 576 | OPimTodo todo = quickEditor()->todo(); |
569 | if (todo.isEmpty() ) | 577 | if (todo.isEmpty() ) |
570 | return; | 578 | return; |
571 | 579 | ||
572 | m_todoMgr.add( todo ); | 580 | m_todoMgr.add( todo ); |
573 | currentView()->addEvent( todo ); | 581 | currentView()->addEvent( todo ); |
574 | raiseCurrentView(); | 582 | raiseCurrentView(); |
575 | } | 583 | } |
576 | QuickEditBase* MainWindow::quickEditor() { | 584 | QuickEditBase* MainWindow::quickEditor() { |
577 | return m_curQuick; | 585 | return m_curQuick; |
578 | } | 586 | } |
579 | void MainWindow::slotComplete( int uid ) { | 587 | void MainWindow::slotComplete( int uid ) { |
580 | slotComplete( event(uid) ); | 588 | slotComplete( event(uid) ); |
581 | } | 589 | } |
582 | void MainWindow::slotComplete( const OPimTodo& todo ) { | 590 | void MainWindow::slotComplete( const OPimTodo& todo ) { |
583 | OPimTodo to = todo; | 591 | OPimTodo to = todo; |
584 | to.setCompleted( !to.isCompleted() ); | 592 | to.setCompleted( !to.isCompleted() ); |
585 | to.setCompletedDate( QDate::currentDate() ); | 593 | to.setCompletedDate( QDate::currentDate() ); |
586 | 594 | ||
587 | /* | 595 | /* |
588 | * if the item does recur | 596 | * if the item does recur |
589 | * we need to spin it off | 597 | * we need to spin it off |
590 | * and update the items duedate to the next | 598 | * and update the items duedate to the next |
591 | * possible recurrance of this item... | 599 | * possible recurrance of this item... |
592 | * the spinned off one will loose the | 600 | * the spinned off one will loose the |
593 | * recurrence. | 601 | * recurrence. |
594 | * We calculate the difference between the old due date and the | 602 | * We calculate the difference between the old due date and the |
595 | * new one and add this diff to start, completed and alarm dates | 603 | * new one and add this diff to start, completed and alarm dates |
596 | * -zecke | 604 | * -zecke |
597 | */ | 605 | */ |
598 | if ( to.hasRecurrence() && to.isCompleted() ) { | 606 | if ( to.hasRecurrence() && to.isCompleted() ) { |
599 | OPimTodo to2( to ); | 607 | OPimTodo to2( to ); |
600 | 608 | ||
601 | /* the spinned off one won't recur anymore */ | 609 | /* the spinned off one won't recur anymore */ |
602 | to.setRecurrence( OPimRecurrence() ); | 610 | to.setRecurrence( OPimRecurrence() ); |
603 | 611 | ||
604 | OPimRecurrence rec = to2.recurrence(); | 612 | OPimRecurrence rec = to2.recurrence(); |
605 | rec.setStart( to.dueDate() ); | 613 | rec.setStart( to.dueDate() ); |
606 | to2.setRecurrence( rec ); | 614 | to2.setRecurrence( rec ); |
607 | /* | 615 | /* |
608 | * if there is a next occurence | 616 | * if there is a next occurence |
609 | * from the duedate of the last recurrance | 617 | * from the duedate of the last recurrance |
610 | */ | 618 | */ |
611 | QDate date; | 619 | QDate date; |
612 | if ( to2.recurrence().nextOcurrence( to2.dueDate().addDays(1), date ) ) { | 620 | if ( to2.recurrence().nextOcurrence( to2.dueDate().addDays(1), date ) ) { |
613 | int dayDiff = to.dueDate().daysTo( date ); | 621 | int dayDiff = to.dueDate().daysTo( date ); |
614 | QDate inval; | 622 | QDate inval; |
615 | /* generate a new uid for the old record */ | 623 | /* generate a new uid for the old record */ |
616 | to.setUid( 1 ); | 624 | to.setUid( 1 ); |
617 | 625 | ||
618 | /* add the old one cause it has a new UID here cause it was spin off */ | 626 | /* add the old one cause it has a new UID here cause it was spin off */ |
619 | m_todoMgr.add( to ); | 627 | m_todoMgr.add( to ); |
620 | 628 | ||
621 | /* | 629 | /* |
622 | * update the due date | 630 | * update the due date |
623 | * start date | 631 | * start date |
624 | * and complete date | 632 | * and complete date |
625 | */ | 633 | */ |
626 | to2.setDueDate( date ); | 634 | to2.setDueDate( date ); |
627 | rec.setStart( date ); | 635 | rec.setStart( date ); |
628 | to2.setRecurrence( rec ); // could be Monday, TuesDay, Thursday every week | 636 | to2.setRecurrence( rec ); // could be Monday, TuesDay, Thursday every week |
629 | 637 | ||
630 | /* move start date */ | 638 | /* move start date */ |
631 | if (to2.hasStartDate() ) | 639 | if (to2.hasStartDate() ) |
632 | to2.setStartDate( to2.startDate().addDays( dayDiff ) ); | 640 | to2.setStartDate( to2.startDate().addDays( dayDiff ) ); |
633 | 641 | ||
634 | /* now the alarms */ | 642 | /* now the alarms */ |
635 | if (to2.hasNotifiers() ) { | 643 | if (to2.hasNotifiers() ) { |
636 | OPimNotifyManager::Alarms _als = to2.notifiers().alarms(); | 644 | OPimNotifyManager::Alarms _als = to2.notifiers().alarms(); |
637 | OPimNotifyManager::Alarms als; | 645 | OPimNotifyManager::Alarms als; |
638 | 646 | ||
639 | /* for every alarm move the day */ | 647 | /* for every alarm move the day */ |
640 | for ( OPimNotifyManager::Alarms::Iterator it = _als.begin(); it != _als.end(); ++it ) { | 648 | for ( OPimNotifyManager::Alarms::Iterator it = _als.begin(); it != _als.end(); ++it ) { |
641 | OPimAlarm al = (*it); | 649 | OPimAlarm al = (*it); |
642 | al.setDateTime( al.dateTime().addDays( dayDiff ) ); | 650 | al.setDateTime( al.dateTime().addDays( dayDiff ) ); |
643 | als.append( al ); | 651 | als.append( al ); |
644 | } | 652 | } |
645 | to2.notifiers().setAlarms( als ); | 653 | to2.notifiers().setAlarms( als ); |
646 | handleAlarms( OPimTodo(), todo ); | 654 | handleAlarms( OPimTodo(), todo ); |
647 | } | 655 | } |
648 | to2.setCompletedDate( inval ); | 656 | to2.setCompletedDate( inval ); |
649 | to2.setCompleted( false ); | 657 | to2.setCompleted( false ); |
650 | 658 | ||
651 | updateTodo( to2 ); | 659 | updateTodo( to2 ); |
652 | }else | 660 | }else |
653 | updateTodo( to ); | 661 | updateTodo( to ); |
654 | }else | 662 | }else |
655 | updateTodo( to ); | 663 | updateTodo( to ); |
656 | 664 | ||
657 | currentView()->updateView(); | 665 | currentView()->updateView(); |
658 | raiseCurrentView(); | 666 | raiseCurrentView(); |
659 | } | 667 | } |
660 | void MainWindow::flush() { | 668 | void MainWindow::flush() { |
661 | slotFlush(); | 669 | slotFlush(); |
662 | } | 670 | } |
663 | void MainWindow::reload() { | 671 | void MainWindow::reload() { |
664 | slotReload(); | 672 | slotReload(); |
665 | } | 673 | } |
666 | int MainWindow::create() { | 674 | int MainWindow::create() { |
667 | int uid = 0; | 675 | int uid = 0; |
668 | if(m_syncing) { | 676 | if(m_syncing) { |
669 | QMessageBox::warning(this, QWidget::tr("Todo"), | 677 | QMessageBox::warning(this, QWidget::tr("Todo"), |
670 | QWidget::tr("Data can not be edited, currently syncing")); | 678 | QWidget::tr("Data can not be edited, currently syncing")); |
671 | return uid; | 679 | return uid; |
672 | } | 680 | } |
673 | m_todoMgr.load(); | 681 | m_todoMgr.load(); |
674 | 682 | ||
675 | 683 | ||
676 | OPimTodo todo = currentEditor()->newTodo( currentCatId(), | 684 | OPimTodo todo = currentEditor()->newTodo( currentCatId(), |
677 | this ); | 685 | this ); |
678 | 686 | ||
679 | if ( currentEditor()->accepted() ) { | 687 | if ( currentEditor()->accepted() ) { |
680 | //todo.assignUid(); | 688 | //todo.assignUid(); |
681 | uid = todo.uid(); | 689 | uid = todo.uid(); |
682 | handleAlarms( OPimTodo(), todo ); | 690 | handleAlarms( OPimTodo(), todo ); |
683 | m_todoMgr.add( todo ); | 691 | m_todoMgr.add( todo ); |
684 | currentView()->addEvent( todo ); | 692 | currentView()->addEvent( todo ); |
685 | 693 | ||
686 | 694 | ||
687 | // I'm afraid we must call this every time now, otherwise | 695 | // I'm afraid we must call this every time now, otherwise |
688 | // spend expensive time comparing all these strings... | 696 | // spend expensive time comparing all these strings... |
689 | // but only call if we changed something -zecke | 697 | // but only call if we changed something -zecke |
690 | reloadCategories(); | 698 | reloadCategories(); |
691 | } | 699 | } |
692 | raiseCurrentView( ); | 700 | raiseCurrentView( ); |
693 | 701 | ||
694 | return uid; | 702 | return uid; |
695 | } | 703 | } |
696 | /* delete it silently... */ | 704 | /* delete it silently... */ |
697 | bool MainWindow::remove( int uid ) { | 705 | bool MainWindow::remove( int uid ) { |
698 | if (m_syncing) return false; | 706 | if (m_syncing) return false; |
699 | 707 | ||
700 | /* argh need to get the whole OEvent... to disable alarms -zecke */ | 708 | /* argh need to get the whole OEvent... to disable alarms -zecke */ |
701 | handleAlarms( OPimTodo(), m_todoMgr.event( uid ) ); | 709 | handleAlarms( OPimTodo(), m_todoMgr.event( uid ) ); |
702 | 710 | ||
703 | return m_todoMgr.remove( uid ); | 711 | return m_todoMgr.remove( uid ); |
704 | } | 712 | } |
705 | void MainWindow::beam( int uid) { | 713 | void MainWindow::beam( int uid) { |
706 | if( uid == 0 ) return; | 714 | if( uid == 0 ) return; |
707 | 715 | ||
708 | ::unlink( beamfile ); | 716 | ::unlink( beamfile ); |
709 | m_todoMgr.load(); | 717 | m_todoMgr.load(); |
710 | 718 | ||
711 | OPimTodo todo = event( uid ); | 719 | OPimTodo todo = event( uid ); |
712 | OPimTodoAccessVCal* cal = new OPimTodoAccessVCal(QString::fromLatin1(beamfile) ); | 720 | OPimTodoAccessVCal* cal = new OPimTodoAccessVCal(QString::fromLatin1(beamfile) ); |
713 | OPimTodoAccess acc( cal ); | 721 | OPimTodoAccess acc( cal ); |
714 | acc.load(); | 722 | acc.load(); |
715 | acc.add( todo ); | 723 | acc.add( todo ); |
716 | acc.save(); | 724 | acc.save(); |
717 | Ir* ir = new Ir(this ); | 725 | Ir* ir = new Ir(this ); |
718 | connect(ir, SIGNAL(done(Ir*) ), | 726 | connect(ir, SIGNAL(done(Ir*) ), |
719 | this, SLOT(beamDone(Ir*) ) ); | 727 | this, SLOT(beamDone(Ir*) ) ); |
720 | ir->send(beamfile, todo.summary(), "text/x-vCalendar" ); | 728 | ir->send(beamfile, todo.summary(), "text/x-vCalendar" ); |
721 | } | 729 | } |
722 | void MainWindow::show( int uid ) { | 730 | void MainWindow::show( int uid ) { |
723 | m_todoMgr.load(); // might not be loaded yet | 731 | m_todoMgr.load(); // might not be loaded yet |
724 | m_showing = true; | 732 | m_showing = true; |
725 | slotShow( uid ); | 733 | slotShow( uid ); |
726 | raise(); | 734 | raise(); |
727 | QPEApplication::setKeepRunning(); | 735 | QPEApplication::setKeepRunning(); |
728 | } | 736 | } |
729 | void MainWindow::edit( int uid ) { | 737 | void MainWindow::edit( int uid ) { |
730 | m_todoMgr.load(); | 738 | m_todoMgr.load(); |
731 | slotEdit( uid ); | 739 | slotEdit( uid ); |
732 | } | 740 | } |
733 | void MainWindow::add( const OPimRecord& rec) { | 741 | void MainWindow::add( const OPimRecord& rec) { |
734 | OPimTodo test; | 742 | OPimTodo test; |
735 | if ( rec.rtti() != test.rtti() ) return; | 743 | if ( rec.rtti() != test.rtti() ) return; |
736 | m_todoMgr.load(); // might not be loaded | 744 | m_todoMgr.load(); // might not be loaded |
737 | 745 | ||
738 | const OPimTodo& todo = static_cast<const OPimTodo&>(rec); | 746 | const OPimTodo& todo = static_cast<const OPimTodo&>(rec); |
739 | 747 | ||
740 | m_todoMgr.add(todo ); | 748 | m_todoMgr.add(todo ); |
741 | currentView()->addEvent( todo ); | 749 | currentView()->addEvent( todo ); |
742 | 750 | ||
743 | 751 | ||
744 | // I'm afraid we must call this every time now, otherwise | 752 | // I'm afraid we must call this every time now, otherwise |
745 | // spend expensive time comparing all these strings... | 753 | // spend expensive time comparing all these strings... |
746 | // but only call if we changed something -zecke | 754 | // but only call if we changed something -zecke |
747 | reloadCategories(); | 755 | reloadCategories(); |
748 | } | 756 | } |
749 | void MainWindow::slotReturnFromView() { | 757 | void MainWindow::slotReturnFromView() { |
750 | m_showing = false; | 758 | m_showing = false; |
751 | raiseCurrentView(); | 759 | raiseCurrentView(); |
752 | } | 760 | } |
753 | 761 | ||
754 | namespace { | 762 | namespace { |
755 | OPimNotifyManager::Alarms findNonMatching( const OPimNotifyManager::Alarms& oldAls, | 763 | OPimNotifyManager::Alarms findNonMatching( const OPimNotifyManager::Alarms& oldAls, |
756 | const OPimNotifyManager::Alarms& newAls ) { | 764 | const OPimNotifyManager::Alarms& newAls ) { |
757 | OPimNotifyManager::Alarms nonMatching; | 765 | OPimNotifyManager::Alarms nonMatching; |
758 | OPimNotifyManager::Alarms::ConstIterator oldIt = oldAls.begin(); | 766 | OPimNotifyManager::Alarms::ConstIterator oldIt = oldAls.begin(); |
759 | OPimNotifyManager::Alarms::ConstIterator newIt; | 767 | OPimNotifyManager::Alarms::ConstIterator newIt; |
760 | for ( ; oldIt != oldAls.end(); ++oldIt ) { | 768 | for ( ; oldIt != oldAls.end(); ++oldIt ) { |
761 | bool found = false; | 769 | bool found = false; |
762 | QDateTime oldDt = (*oldIt).dateTime(); | 770 | QDateTime oldDt = (*oldIt).dateTime(); |
763 | for (newIt= newAls.begin(); newIt != newAls.end(); ++newIt ) { | 771 | for (newIt= newAls.begin(); newIt != newAls.end(); ++newIt ) { |
764 | if ( oldDt == (*newIt).dateTime() ) { | 772 | if ( oldDt == (*newIt).dateTime() ) { |
765 | found = true; | 773 | found = true; |
766 | break; | 774 | break; |
767 | } | 775 | } |
768 | } | 776 | } |
769 | if (!found) | 777 | if (!found) |
770 | nonMatching.append( (*oldIt) ); | 778 | nonMatching.append( (*oldIt) ); |
771 | } | 779 | } |
772 | return nonMatching; | 780 | return nonMatching; |
773 | } | 781 | } |
774 | void addAlarms( const OPimNotifyManager::Alarms& als, int uid ) { | 782 | void addAlarms( const OPimNotifyManager::Alarms& als, int uid ) { |
775 | OPimNotifyManager::Alarms::ConstIterator it; | 783 | OPimNotifyManager::Alarms::ConstIterator it; |
776 | for ( it = als.begin(); it != als.end(); ++it ) { | 784 | for ( it = als.begin(); it != als.end(); ++it ) { |
777 | AlarmServer::addAlarm( (*it).dateTime(), "QPE/Application/todolist", "alarm(QDateTime,int)", uid ); | 785 | AlarmServer::addAlarm( (*it).dateTime(), "QPE/Application/todolist", "alarm(QDateTime,int)", uid ); |
778 | } | 786 | } |
779 | 787 | ||
780 | } | 788 | } |
781 | void removeAlarms( const OPimNotifyManager::Alarms& als, int uid ) { | 789 | void removeAlarms( const OPimNotifyManager::Alarms& als, int uid ) { |
782 | OPimNotifyManager::Alarms::ConstIterator it; | 790 | OPimNotifyManager::Alarms::ConstIterator it; |
783 | for ( it = als.begin(); it != als.end(); ++it ) { | 791 | for ( it = als.begin(); it != als.end(); ++it ) { |
784 | AlarmServer::deleteAlarm( (*it).dateTime(), "QPE/Application/todolist", "alarm(QDateTime,int)", uid ); | 792 | AlarmServer::deleteAlarm( (*it).dateTime(), "QPE/Application/todolist", "alarm(QDateTime,int)", uid ); |
785 | } | 793 | } |
786 | } | 794 | } |
787 | } | 795 | } |
788 | 796 | ||
789 | void MainWindow::handleAlarms( const OPimTodo& oldTodo, const OPimTodo& newTodo) { | 797 | void MainWindow::handleAlarms( const OPimTodo& oldTodo, const OPimTodo& newTodo) { |
790 | /* | 798 | /* |
791 | * if oldTodo is not empty and has notifiers we need to find the deleted ones | 799 | * if oldTodo is not empty and has notifiers we need to find the deleted ones |
792 | */ | 800 | */ |
793 | if(!oldTodo.isEmpty() && oldTodo.hasNotifiers() ) { | 801 | if(!oldTodo.isEmpty() && oldTodo.hasNotifiers() ) { |
794 | OPimNotifyManager::Alarms removed; | 802 | OPimNotifyManager::Alarms removed; |
795 | OPimNotifyManager::Alarms oldAls = oldTodo.notifiers().alarms(); | 803 | OPimNotifyManager::Alarms oldAls = oldTodo.notifiers().alarms(); |
796 | if (!newTodo.hasNotifiers() ) | 804 | if (!newTodo.hasNotifiers() ) |
797 | removed = oldAls; | 805 | removed = oldAls; |
798 | else | 806 | else |
799 | removed = findNonMatching( oldAls, newTodo.notifiers().alarms() ); | 807 | removed = findNonMatching( oldAls, newTodo.notifiers().alarms() ); |
800 | 808 | ||
801 | removeAlarms( removed, oldTodo.uid() ); | 809 | removeAlarms( removed, oldTodo.uid() ); |
802 | } | 810 | } |
803 | if ( newTodo.hasNotifiers() ) { | 811 | if ( newTodo.hasNotifiers() ) { |
804 | OPimNotifyManager::Alarms added; | 812 | OPimNotifyManager::Alarms added; |
805 | if ( oldTodo.isEmpty() || !oldTodo.hasNotifiers() ) | 813 | if ( oldTodo.isEmpty() || !oldTodo.hasNotifiers() ) |
806 | added = newTodo.notifiers().alarms(); | 814 | added = newTodo.notifiers().alarms(); |
807 | else | 815 | else |
808 | added = findNonMatching( newTodo.notifiers().alarms(), oldTodo.notifiers().alarms() ); | 816 | added = findNonMatching( newTodo.notifiers().alarms(), oldTodo.notifiers().alarms() ); |
809 | 817 | ||
810 | addAlarms( added, newTodo.uid() ); | 818 | addAlarms( added, newTodo.uid() ); |
811 | } | 819 | } |
812 | } | 820 | } |
813 | /* we might have not loaded the db */ | 821 | /* we might have not loaded the db */ |
814 | void MainWindow::doAlarm( const QDateTime& dt, int uid ) { | 822 | void MainWindow::doAlarm( const QDateTime& dt, int uid ) { |
815 | m_todoMgr.load(); | 823 | m_todoMgr.load(); |
816 | 824 | ||
817 | OPimTodo todo = m_todoMgr.event( uid ); | 825 | OPimTodo todo = m_todoMgr.event( uid ); |
818 | if (!todo.hasNotifiers() ) return; | 826 | if (!todo.hasNotifiers() ) return; |
819 | 827 | ||
820 | /* | 828 | /* |
821 | * let's find the right alarm and find out if silent | 829 | * let's find the right alarm and find out if silent |
822 | * then show a richtext widget | 830 | * then show a richtext widget |
823 | */ | 831 | */ |
824 | bool loud = false; | 832 | bool loud = false; |
825 | OPimNotifyManager::Alarms als = todo.notifiers().alarms(); | 833 | OPimNotifyManager::Alarms als = todo.notifiers().alarms(); |
826 | OPimNotifyManager::Alarms::Iterator it; | 834 | OPimNotifyManager::Alarms::Iterator it; |
827 | for ( it = als.begin(); it != als.end(); ++it ) { | 835 | for ( it = als.begin(); it != als.end(); ++it ) { |
828 | if ( (*it).dateTime() == dt ) { | 836 | if ( (*it).dateTime() == dt ) { |
829 | loud = ( (*it).sound() == OPimAlarm::Loud ); | 837 | loud = ( (*it).sound() == OPimAlarm::Loud ); |
830 | break; | 838 | break; |
831 | } | 839 | } |
832 | } | 840 | } |
833 | if (loud) | 841 | if (loud) |
834 | startAlarm(); | 842 | startAlarm(); |
835 | 843 | ||
836 | QDialog dlg(this, 0, true ); | 844 | QDialog dlg(this, 0, true ); |
837 | QVBoxLayout* lay = new QVBoxLayout( &dlg ); | 845 | QVBoxLayout* lay = new QVBoxLayout( &dlg ); |
838 | QTextView* view = new QTextView( &dlg ); | 846 | QTextView* view = new QTextView( &dlg ); |
839 | lay->addWidget( view ); | 847 | lay->addWidget( view ); |
840 | QPushButton* btnOk = new QPushButton( tr("Ok"), &dlg ); | 848 | QPushButton* btnOk = new QPushButton( tr("Ok"), &dlg ); |
841 | connect( btnOk, SIGNAL(clicked() ), &dlg, SLOT(accept() ) ); | 849 | connect( btnOk, SIGNAL(clicked() ), &dlg, SLOT(accept() ) ); |
842 | lay->addWidget( btnOk ); | 850 | lay->addWidget( btnOk ); |
843 | 851 | ||
844 | QString text = tr("<h1>Alarm at %1</h1><br>").arg( TimeString::dateString( dt ) ); | 852 | QString text = tr("<h1>Alarm at %1</h1><br>").arg( TimeString::dateString( dt ) ); |
845 | text += todo.toRichText(); | 853 | text += todo.toRichText(); |
846 | view->setText( text ); | 854 | view->setText( text ); |
847 | 855 | ||
848 | bool needToStay = QPEApplication::execDialog( &dlg ); | 856 | bool needToStay = QPEApplication::execDialog( &dlg ); |
849 | 857 | ||
850 | if (loud) | 858 | if (loud) |
851 | killAlarm(); | 859 | killAlarm(); |
852 | 860 | ||
853 | if (needToStay) { | 861 | if (needToStay) { |
854 | // showMaximized(); | 862 | // showMaximized(); |
855 | // raise(); | 863 | // raise(); |
856 | QPEApplication::setKeepRunning(); | 864 | QPEApplication::setKeepRunning(); |
857 | // setActiveWindow(); | 865 | // setActiveWindow(); |
858 | } | 866 | } |
859 | 867 | ||
860 | } | 868 | } |
861 | 869 | ||