summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--core/pim/todo/main.cpp1
-rw-r--r--core/pim/todo/mainwindow.cpp16
-rw-r--r--core/pim/todo/tableview.cpp32
-rw-r--r--core/pim/todo/todomanager.cpp7
4 files changed, 22 insertions, 34 deletions
diff --git a/core/pim/todo/main.cpp b/core/pim/todo/main.cpp
index d070ff8..a336ba3 100644
--- a/core/pim/todo/main.cpp
+++ b/core/pim/todo/main.cpp
@@ -1,48 +1,47 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved. 2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3** 3**
4** This file is part of Qtopia Environment. 4** This file is part of Qtopia Environment.
5** 5**
6** This file may be distributed and/or modified under the terms of the 6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software 7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the 8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file. 9** packaging of this file.
10** 10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13** 13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information. 14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15** 15**
16** Contact info@trolltech.com if any conditions of this licensing are 16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you. 17** not clear to you.
18** 18**
19**********************************************************************/ 19**********************************************************************/
20 20
21#include "mainwindow.h" 21#include "mainwindow.h"
22 22
23#include <opie2/odebug.h> 23#include <opie2/odebug.h>
24 24
25#include <qpe/qpeapplication.h> 25#include <qpe/qpeapplication.h>
26 26
27void myMessages( QtMsgType, const char* ) { 27void myMessages( QtMsgType, const char* ) {
28 28
29} 29}
30 30
31int main( int argc, char **argv ) 31int main( int argc, char **argv )
32{ 32{
33 qInstallMsgHandler( myMessages ); 33 qInstallMsgHandler( myMessages );
34 QPEApplication a( argc, argv ); 34 QPEApplication a( argc, argv );
35 35
36 QTime time; 36 QTime time;
37 time.start(); 37 time.start();
38 Todo::MainWindow mw; 38 Todo::MainWindow mw;
39 int t = time.elapsed(); 39 int t = time.elapsed();
40 Opie::Core::owarn << "QTime " << t/1000 << oendl;
41 mw.setCaption( QObject::tr("Opie Todolist")); 40 mw.setCaption( QObject::tr("Opie Todolist"));
42 QObject::connect( &a, SIGNAL( flush() ), &mw, SLOT( slotFlush() ) ); 41 QObject::connect( &a, SIGNAL( flush() ), &mw, SLOT( slotFlush() ) );
43 QObject::connect( &a, SIGNAL( reload() ), &mw, SLOT( slotReload() ) ); 42 QObject::connect( &a, SIGNAL( reload() ), &mw, SLOT( slotReload() ) );
44 43
45 a.showMainWidget(&mw); 44 a.showMainWidget(&mw);
46 45
47 return a.exec(); 46 return a.exec();
48} 47}
diff --git a/core/pim/todo/mainwindow.cpp b/core/pim/todo/mainwindow.cpp
index 2002e87..9424c23 100644
--- a/core/pim/todo/mainwindow.cpp
+++ b/core/pim/todo/mainwindow.cpp
@@ -1,1042 +1,1032 @@
1/* 1/*
2               =. This file is part of the OPIE Project 2               =. This file is part of the OPIE Project
3             .=l. Copyright (c) 2002 <> 3             .=l. Copyright (c) 2002 <>
4           .>+-= 4           .>+-=
5 _;:,     .>    :=|. This program is free software; you can 5 _;:,     .>    :=|. This program is free software; you can
6.> <`_,   >  .   <= redistribute it and/or modify it under 6.> <`_,   >  .   <= redistribute it and/or modify it under
7:`=1 )Y*s>-.--   : the terms of the GNU General Public 7:`=1 )Y*s>-.--   : the terms of the GNU General Public
8.="- .-=="i,     .._ License as published by the Free Software 8.="- .-=="i,     .._ License as published by the Free Software
9 - .   .-<_>     .<> Foundation; either version 2 of the License, 9 - .   .-<_>     .<> Foundation; either version 2 of the License,
10     ._= =}       : or (at your option) any later version. 10     ._= =}       : or (at your option) any later version.
11    .%`+i>       _;_. 11    .%`+i>       _;_.
12    .i_,=:_.      -<s. This program is distributed in the hope that 12    .i_,=:_.      -<s. This program is distributed in the hope that
13     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY; 13     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
14    : ..    .:,     . . . without even the implied warranty of 14    : ..    .:,     . . . without even the implied warranty of
15    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A 15    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
16  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU 16  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU
17..}^=.=       =       ; Library General Public License for more 17..}^=.=       =       ; Library General Public License for more
18++=   -.     .`     .: details. 18++=   -.     .`     .: details.
19 :     =  ...= . :.=- 19 :     =  ...= . :.=-
20 -.   .:....=;==+<; You should have received a copy of the GNU 20 -.   .:....=;==+<; You should have received a copy of the GNU
21  -_. . .   )=.  = General Public License along with 21  -_. . .   )=.  = General Public License along with
22    --        :-=` this library; see the file COPYING.LIB. 22    --        :-=` this library; see the file COPYING.LIB.
23 If not, write to the Free Software Foundation, 23 If not, write to the Free Software Foundation,
24 Inc., 59 Temple Place - Suite 330, 24 Inc., 59 Temple Place - Suite 330,
25 Boston, MA 02111-1307, USA. 25 Boston, MA 02111-1307, USA.
26 26
27*/ 27*/
28 28
29#include <unistd.h> 29#include <unistd.h>
30 30
31#include <opie2/odebug.h> 31#include <opie2/odebug.h>
32#include <opie2/opimrecurrence.h> 32#include <opie2/opimrecurrence.h>
33#include <opie2/opimnotifymanager.h> 33#include <opie2/opimnotifymanager.h>
34#include <opie2/otodoaccessvcal.h> 34#include <opie2/otodoaccessvcal.h>
35#include <opie2/oapplicationfactory.h> 35#include <opie2/oapplicationfactory.h>
36 36
37#include <qpe/applnk.h> 37#include <qpe/applnk.h>
38#include <qpe/config.h> 38#include <qpe/config.h>
39#include <qpe/ir.h> 39#include <qpe/ir.h>
40#include <qpe/resource.h> 40#include <qpe/resource.h>
41#include <qpe/qpemessagebox.h> 41#include <qpe/qpemessagebox.h>
42#include <qpe/alarmserver.h> 42#include <qpe/alarmserver.h>
43#include <qpe/qpeapplication.h> 43#include <qpe/qpeapplication.h>
44 44
45#include <qmenubar.h> 45#include <qmenubar.h>
46#include <qmessagebox.h> 46#include <qmessagebox.h>
47#include <qpushbutton.h> 47#include <qpushbutton.h>
48#include <qaction.h> 48#include <qaction.h>
49#include <qtimer.h> 49#include <qtimer.h>
50#include <qlayout.h> 50#include <qlayout.h>
51#include <qwhatsthis.h> 51#include <qwhatsthis.h>
52 52
53#include "quickeditimpl.h" 53#include "quickeditimpl.h"
54#include "todotemplatemanager.h" 54#include "todotemplatemanager.h"
55#include "templateeditor.h" 55#include "templateeditor.h"
56#include "tableview.h" 56#include "tableview.h"
57 57
58#include "textviewshow.h" 58#include "textviewshow.h"
59#include "todoeditor.h" 59#include "todoeditor.h"
60#include "mainwindow.h" 60#include "mainwindow.h"
61 61
62using Opie::Core::OApplicationFactory; 62using Opie::Core::OApplicationFactory;
63OPIE_EXPORT_APP( OApplicationFactory<Todo::MainWindow> ) 63OPIE_EXPORT_APP( OApplicationFactory<Todo::MainWindow> )
64 64
65using namespace Opie; 65using namespace Opie;
66using namespace Todo; 66using namespace Todo;
67 67
68MainWindow::MainWindow( QWidget* parent, 68MainWindow::MainWindow( QWidget* parent,
69 const char* name, WFlags ) 69 const char* name, WFlags )
70 : Opie::OPimMainWindow( "Todolist", parent, name, WType_TopLevel | WStyle_ContextHelp ) 70 : Opie::OPimMainWindow( "Todolist", parent, name, WType_TopLevel | WStyle_ContextHelp )
71{ 71{
72 if (!name) 72 if (!name)
73 setName("todo window"); 73 setName("todo window");
74 74
75 m_syncing = false; 75 m_syncing = false;
76 m_showing = false; 76 m_showing = false;
77 m_counter = 0; 77 m_counter = 0;
78 m_tempManager = new TemplateManager(); 78 m_tempManager = new TemplateManager();
79 m_tempManager->load(); 79 m_tempManager->load();
80 80
81 initUI(); 81 initUI();
82 initConfig(); 82 initConfig();
83 initViews(); 83 initViews();
84 initActions(); 84 initActions();
85 initEditor(); 85 initEditor();
86 initShow(); 86 initShow();
87 initTemplate(); 87 initTemplate();
88 88
89 populateTemplates(); 89 populateTemplates();
90 raiseCurrentView(); 90 raiseCurrentView();
91 QTimer::singleShot(0, this, SLOT(populateCategories() ) ); 91 QTimer::singleShot(0, this, SLOT(populateCategories() ) );
92} 92}
93void MainWindow::initTemplate() { 93void MainWindow::initTemplate() {
94 m_curTempEd = new TemplateEditor( this, templateManager() ); 94 m_curTempEd = new TemplateEditor( this, templateManager() );
95} 95}
96void MainWindow::initActions() { 96void MainWindow::initActions() {
97 97
98 // Data menu 98 // Data menu
99 m_edit->insertItem(QWidget::tr("New from template"), m_template, 99 m_edit->insertItem(QWidget::tr("New from template"), m_template,
100 -1, 0 ); 100 -1, 0 );
101 101
102 QAction* a = new QAction( QWidget::tr("New Task" ), Resource::loadPixmap( "new" ), 102 QAction* a = new QAction( QWidget::tr("New Task" ), Resource::loadPixmap( "new" ),
103 QString::null, 0, this, 0 ); 103 QString::null, 0, this, 0 );
104 connect(a, SIGNAL( activated() ), 104 connect(a, SIGNAL( activated() ),
105 this, SLOT( slotNew() ) ); 105 this, SLOT( slotNew() ) );
106 a->setWhatsThis( QWidget::tr( "Click here to create a new task." ) ); 106 a->setWhatsThis( QWidget::tr( "Click here to create a new task." ) );
107 a->addTo(m_tool ); 107 a->addTo(m_tool );
108 a->addTo(m_edit ); 108 a->addTo(m_edit );
109 109
110 a = new QAction( QWidget::tr("Edit Task"), Resource::loadIconSet( "edit" ), 110 a = new QAction( QWidget::tr("Edit Task"), Resource::loadIconSet( "edit" ),
111 QString::null, 0, this, 0 ); 111 QString::null, 0, this, 0 );
112 connect(a, SIGNAL(activated() ), 112 connect(a, SIGNAL(activated() ),
113 this, SLOT( slotEdit() ) ); 113 this, SLOT( slotEdit() ) );
114 a->setWhatsThis( QWidget::tr( "Click here to modify the current task." ) ); 114 a->setWhatsThis( QWidget::tr( "Click here to modify the current task." ) );
115 a->addTo( m_tool ); 115 a->addTo( m_tool );
116 a->addTo( m_edit ); 116 a->addTo( m_edit );
117 m_editAction = a; 117 m_editAction = a;
118 118
119 a = new QAction( QString::null, QWidget::tr("View Task"), 0, this, 0 ); 119 a = new QAction( QString::null, QWidget::tr("View Task"), 0, this, 0 );
120 connect(a, SIGNAL( activated() ), 120 connect(a, SIGNAL( activated() ),
121 this, SLOT( slotShowDetails() ) ); 121 this, SLOT( slotShowDetails() ) );
122 a->addTo( m_edit ); 122 a->addTo( m_edit );
123 123
124 m_edit->insertSeparator(); 124 m_edit->insertSeparator();
125 125
126 a = new QAction( QWidget::tr("Delete..."), Resource::loadIconSet( "trash" ), 126 a = new QAction( QWidget::tr("Delete..."), Resource::loadIconSet( "trash" ),
127 QString::null, 0, this, 0 ); 127 QString::null, 0, this, 0 );
128 connect(a, SIGNAL(activated() ), 128 connect(a, SIGNAL(activated() ),
129 this, SLOT(slotDelete() ) ); 129 this, SLOT(slotDelete() ) );
130 a->setWhatsThis( QWidget::tr( "Click here to remove the current task." ) ); 130 a->setWhatsThis( QWidget::tr( "Click here to remove the current task." ) );
131 a->addTo( m_tool ); 131 a->addTo( m_tool );
132 a->addTo( m_edit ); 132 a->addTo( m_edit );
133 m_deleteAction = a; 133 m_deleteAction = a;
134 134
135 a = new QAction( QString::null, QWidget::tr("Delete all..."), 0, this, 0 ); 135 a = new QAction( QString::null, QWidget::tr("Delete all..."), 0, this, 0 );
136 connect(a, SIGNAL( activated() ), 136 connect(a, SIGNAL( activated() ),
137 this, SLOT( slotDeleteAll() ) ); 137 this, SLOT( slotDeleteAll() ) );
138 a->addTo(m_edit ); 138 a->addTo(m_edit );
139 m_deleteAllAction = a; 139 m_deleteAllAction = a;
140 140
141 a = new QAction( QString::null, QWidget::tr("Delete completed"), 141 a = new QAction( QString::null, QWidget::tr("Delete completed"),
142 0, this, 0 ); 142 0, this, 0 );
143 connect(a, SIGNAL( activated() ), 143 connect(a, SIGNAL( activated() ),
144 this, SLOT( slotDeleteCompleted() ) ); 144 this, SLOT( slotDeleteCompleted() ) );
145 a->addTo(m_edit ); 145 a->addTo(m_edit );
146 a->setEnabled( TRUE ); 146 a->setEnabled( TRUE );
147 m_deleteCompleteAction = a; 147 m_deleteCompleteAction = a;
148 148
149 m_edit->insertSeparator(); 149 m_edit->insertSeparator();
150 150
151 a = new QAction( QString::null, QWidget::tr("Duplicate"), 0, this, 0 ); 151 a = new QAction( QString::null, QWidget::tr("Duplicate"), 0, this, 0 );
152 connect(a, SIGNAL( activated() ), 152 connect(a, SIGNAL( activated() ),
153 this, SLOT( slotDuplicate() ) ); 153 this, SLOT( slotDuplicate() ) );
154 a->addTo(m_edit ); 154 a->addTo(m_edit );
155 m_duplicateAction = a; 155 m_duplicateAction = a;
156 156
157 m_edit->insertSeparator(); 157 m_edit->insertSeparator();
158 158
159 if ( Ir::supported() ) { 159 if ( Ir::supported() ) {
160 a = new QAction( QWidget::tr( "Beam" ), Resource::loadPixmap( "beam" ), QString::null, 0, this, 0 ); 160 a = new QAction( QWidget::tr( "Beam" ), Resource::loadPixmap( "beam" ), QString::null, 0, this, 0 );
161 connect( a, SIGNAL( activated() ), this, SLOT( slotBeam() ) ); 161 connect( a, SIGNAL( activated() ), this, SLOT( slotBeam() ) );
162 a->setWhatsThis( QWidget::tr( "Click here to send the current task to another device." ) ); 162 a->setWhatsThis( QWidget::tr( "Click here to send the current task to another device." ) );
163 a->addTo( m_edit ); 163 a->addTo( m_edit );
164 a->addTo( m_tool ); 164 a->addTo( m_tool );
165 } 165 }
166 166
167#if 0 167#if 0
168 // Options menu 168 // Options menu
169 a = new QAction( QWidget::tr("Find"), Resource::loadIconSet( "mag" ), 169 a = new QAction( QWidget::tr("Find"), Resource::loadIconSet( "mag" ),
170 QString::null, 0, this, 0 ); 170 QString::null, 0, this, 0 );
171 connect(a, SIGNAL( activated() ), this, SLOT( slotFind() ) ); 171 connect(a, SIGNAL( activated() ), this, SLOT( slotFind() ) );
172 a->addTo( m_options ); 172 a->addTo( m_options );
173 m_findAction = a; 173 m_findAction = a;
174 174
175 175
176 m_options->insertSeparator(); 176 m_options->insertSeparator();
177#endif 177#endif
178 178
179 m_completedAction = new QAction( QString::null, QWidget::tr("Show completed tasks"), 179 m_completedAction = new QAction( QString::null, QWidget::tr("Show completed tasks"),
180 0, this, 0, TRUE ); 180 0, this, 0, TRUE );
181 m_completedAction->addTo( m_options ); 181 m_completedAction->addTo( m_options );
182 m_completedAction->setOn( showCompleted() ); 182 m_completedAction->setOn( showCompleted() );
183 connect(m_completedAction, SIGNAL( toggled(bool) ), this, SLOT(slotShowCompleted(bool) ) ); 183 connect(m_completedAction, SIGNAL( toggled(bool) ), this, SLOT(slotShowCompleted(bool) ) );
184 184
185 a = new QAction( QString::null, QWidget::tr("Show only over-due tasks"), 185 a = new QAction( QString::null, QWidget::tr("Show only over-due tasks"),
186 0, this, 0, TRUE ); 186 0, this, 0, TRUE );
187 a->addTo( m_options ); 187 a->addTo( m_options );
188 a->setOn( showOverDue() ); 188 a->setOn( showOverDue() );
189 connect(a, SIGNAL(toggled(bool)), this, SLOT(slotShowDue(bool) ) ); 189 connect(a, SIGNAL(toggled(bool)), this, SLOT(slotShowDue(bool) ) );
190 190
191 m_showDeadLineAction = new QAction( QString::null, QWidget::tr("Show task deadlines"), 191 m_showDeadLineAction = new QAction( QString::null, QWidget::tr("Show task deadlines"),
192 0, this, 0, TRUE ); 192 0, this, 0, TRUE );
193 m_showDeadLineAction->addTo( m_options ); 193 m_showDeadLineAction->addTo( m_options );
194 m_showDeadLineAction->setOn( showDeadline() ); 194 m_showDeadLineAction->setOn( showDeadline() );
195 connect(m_showDeadLineAction, SIGNAL(toggled(bool) ), this, SLOT( slotShowDeadLine(bool) ) ); 195 connect(m_showDeadLineAction, SIGNAL(toggled(bool) ), this, SLOT( slotShowDeadLine(bool) ) );
196 196
197 m_showQuickTaskAction = new QAction( QString::null, QWidget::tr("Show quick task bar"), 197 m_showQuickTaskAction = new QAction( QString::null, QWidget::tr("Show quick task bar"),
198 0, this, 0, TRUE ); 198 0, this, 0, TRUE );
199 m_showQuickTaskAction->addTo( m_options ); 199 m_showQuickTaskAction->addTo( m_options );
200 m_showQuickTaskAction->setOn( showQuickTask() ); 200 m_showQuickTaskAction->setOn( showQuickTask() );
201 connect(m_showQuickTaskAction, SIGNAL( toggled(bool) ), this, SLOT(slotShowQuickTask(bool) ) ); 201 connect(m_showQuickTaskAction, SIGNAL( toggled(bool) ), this, SLOT(slotShowQuickTask(bool) ) );
202 202
203 m_options->insertSeparator(); 203 m_options->insertSeparator();
204 204
205 m_bar->insertItem( QWidget::tr("Data") ,m_edit ); 205 m_bar->insertItem( QWidget::tr("Data") ,m_edit );
206 m_bar->insertItem( QWidget::tr("Category"), m_catMenu ); 206 m_bar->insertItem( QWidget::tr("Category"), m_catMenu );
207 m_bar->insertItem( QWidget::tr("Options"), m_options ); 207 m_bar->insertItem( QWidget::tr("Options"), m_options );
208 208
209 m_curQuick = new QuickEditImpl( this, m_quicktask ); 209 m_curQuick = new QuickEditImpl( this, m_quicktask );
210 addToolBar( (QToolBar *)m_curQuick->widget(), QWidget::tr( "QuickEdit" ), QMainWindow::Top, TRUE ); 210 addToolBar( (QToolBar *)m_curQuick->widget(), QWidget::tr( "QuickEdit" ), QMainWindow::Top, TRUE );
211 m_curQuick->signal()->connect( this, SLOT(slotQuickEntered() ) ); 211 m_curQuick->signal()->connect( this, SLOT(slotQuickEntered() ) );
212 212
213} 213}
214/* m_curCat from Config */ 214/* m_curCat from Config */
215void MainWindow::initConfig() { 215void MainWindow::initConfig() {
216 Config config( "todo" ); 216 Config config( "todo" );
217 config.setGroup( "View" ); 217 config.setGroup( "View" );
218 m_completed = config.readBoolEntry( "ShowComplete", TRUE ); 218 m_completed = config.readBoolEntry( "ShowComplete", TRUE );
219 m_curCat = config.readEntry( "Category", QString::null ); 219 m_curCat = config.readEntry( "Category", QString::null );
220 m_deadline = config.readBoolEntry( "ShowDeadLine", TRUE); 220 m_deadline = config.readBoolEntry( "ShowDeadLine", TRUE);
221 m_overdue = config.readBoolEntry("ShowOverDue", FALSE ); 221 m_overdue = config.readBoolEntry("ShowOverDue", FALSE );
222 m_quicktask = config.readBoolEntry("ShowQuickTask", TRUE); 222 m_quicktask = config.readBoolEntry("ShowQuickTask", TRUE);
223} 223}
224void MainWindow::initUI() { 224void MainWindow::initUI() {
225 225
226 m_stack = new Opie::Ui::OWidgetStack(this, "main stack"); 226 m_stack = new Opie::Ui::OWidgetStack(this, "main stack");
227 227
228 setCentralWidget( m_stack ); 228 setCentralWidget( m_stack );
229 229
230 setToolBarsMovable( FALSE ); 230 setToolBarsMovable( FALSE );
231 231
232 QToolBar *menubarholder = new QToolBar( this ); 232 QToolBar *menubarholder = new QToolBar( this );
233 menubarholder->setHorizontalStretchable( TRUE ); 233 menubarholder->setHorizontalStretchable( TRUE );
234 m_bar = new QMenuBar( menubarholder ); 234 m_bar = new QMenuBar( menubarholder );
235 235
236 m_tool = new QToolBar( this ); 236 m_tool = new QToolBar( this );
237 237
238 /** QPopupMenu */ 238 /** QPopupMenu */
239 m_edit = new QPopupMenu( this ); 239 m_edit = new QPopupMenu( this );
240 m_options = new QPopupMenu( this ); 240 m_options = new QPopupMenu( this );
241 m_catMenu = new QPopupMenu( this ); 241 m_catMenu = new QPopupMenu( this );
242 m_template = new QPopupMenu( this ); 242 m_template = new QPopupMenu( this );
243 243
244 m_catMenu->setCheckable( TRUE ); 244 m_catMenu->setCheckable( TRUE );
245 m_template->setCheckable( TRUE ); 245 m_template->setCheckable( TRUE );
246 246
247 connect(m_catMenu, SIGNAL(activated(int) ), 247 connect(m_catMenu, SIGNAL(activated(int) ),
248 this, SLOT(setCategory(int) ) ); 248 this, SLOT(setCategory(int) ) );
249 connect(m_template, SIGNAL(activated(int) ), 249 connect(m_template, SIGNAL(activated(int) ),
250 this, SLOT(slotNewFromTemplate(int) ) ); 250 this, SLOT(slotNewFromTemplate(int) ) );
251} 251}
252void MainWindow::initViews() { 252void MainWindow::initViews() {
253 253
254 TableView* tableView = new TableView( this, m_stack ); 254 TableView* tableView = new TableView( this, m_stack );
255 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." ) ); 255 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." ) );
256 m_stack->addWidget( tableView, m_counter++ ); 256 m_stack->addWidget( tableView, m_counter++ );
257 m_views.append( tableView ); 257 m_views.append( tableView );
258 m_curView = tableView; 258 m_curView = tableView;
259 connectBase( tableView ); 259 connectBase( tableView );
260 /* add QString type + QString configname to 260 /* add QString type + QString configname to
261 * the View menu 261 * the View menu
262 * and subdirs for multiple views 262 * and subdirs for multiple views
263 */ 263 */
264} 264}
265void MainWindow::initEditor() { 265void MainWindow::initEditor() {
266 m_curEdit = new Editor(); 266 m_curEdit = new Editor();
267} 267}
268void MainWindow::initShow() { 268void MainWindow::initShow() {
269 m_curShow = new TextViewShow(this, this); 269 m_curShow = new TextViewShow(this, this);
270 m_stack->addWidget( m_curShow->widget() , m_counter++ ); 270 m_stack->addWidget( m_curShow->widget() , m_counter++ );
271} 271}
272MainWindow::~MainWindow() { 272MainWindow::~MainWindow() {
273 delete templateManager(); 273 delete templateManager();
274} 274}
275void MainWindow::connectBase( ViewBase* ) { 275void MainWindow::connectBase( ViewBase* ) {
276 // once templates and signals mix we'll use it again 276 // once templates and signals mix we'll use it again
277} 277}
278QPopupMenu* MainWindow::contextMenu( int , bool recur ) { 278QPopupMenu* MainWindow::contextMenu( int , bool recur ) {
279 QPopupMenu* menu = new QPopupMenu(); 279 QPopupMenu* menu = new QPopupMenu();
280 280
281 m_editAction->addTo( menu ); 281 m_editAction->addTo( menu );
282 m_deleteAction->addTo( menu ); 282 m_deleteAction->addTo( menu );
283 m_duplicateAction->addTo( menu ); 283 m_duplicateAction->addTo( menu );
284 284
285 menu->insertSeparator(); 285 menu->insertSeparator();
286 286
287 /* 287 /*
288 * if this event recurs we allow 288 * if this event recurs we allow
289 * to detach it. 289 * to detach it.
290 * remove all 290 * remove all
291 */ 291 */
292 if ( recur ) { 292 if ( recur ) {
293 ; // FIXME 293 ; // FIXME
294 } 294 }
295 295
296 return menu; 296 return menu;
297} 297}
298QPopupMenu* MainWindow::options() { 298QPopupMenu* MainWindow::options() {
299 owarn << "Options" << oendl;
300 return m_options; 299 return m_options;
301} 300}
302QPopupMenu* MainWindow::edit() { 301QPopupMenu* MainWindow::edit() {
303 return m_edit; 302 return m_edit;
304} 303}
305QToolBar* MainWindow::toolbar() { 304QToolBar* MainWindow::toolbar() {
306 return m_tool; 305 return m_tool;
307} 306}
308OPimTodoAccess::List MainWindow::list()const { 307OPimTodoAccess::List MainWindow::list()const {
309 return m_todoMgr.list(); 308 return m_todoMgr.list();
310} 309}
311OPimTodoAccess::List MainWindow::sorted( bool asc, int sortOrder ) { 310OPimTodoAccess::List MainWindow::sorted( bool asc, int sortOrder ) {
312 int cat = 0; 311 int cat = 0;
313 if ( m_curCat != QWidget::tr("All Categories") ) 312 if ( m_curCat != QWidget::tr("All Categories") )
314 cat = currentCatId(); 313 cat = currentCatId();
315 if ( m_curCat == QWidget::tr("Unfiled") ) 314 if ( m_curCat == QWidget::tr("Unfiled") )
316 cat = -1; 315 cat = -1;
317 316
318 owarn << " Category " << cat << " " << m_curCat << oendl; 317 int filter = OPimTodoAccess::FilterCategory;
319
320 int filter = 1;
321 318
322 if (!m_completed ) 319 if (!m_completed )
323 filter |= 4; 320 filter |= OPimTodoAccess::DoNotShowCompleted;
324 if (m_overdue) 321 if (m_overdue)
325 filter |= 2; 322 filter |= OPimTodoAccess::OnlyOverDue;
326 323
327 return m_todoMgr.sorted( asc, sortOrder, filter, cat ); 324 return m_todoMgr.sorted( asc, sortOrder, filter, cat );
328} 325}
329OPimTodoAccess::List MainWindow::sorted( bool asc, int sortOrder, int addFilter) { 326OPimTodoAccess::List MainWindow::sorted( bool asc, int sortOrder, int addFilter) {
330 int cat = 0; 327 int cat = 0;
331 if ( m_curCat != QWidget::tr("All Categories") ) 328 if ( m_curCat != QWidget::tr("All Categories") )
332 cat = currentCatId(); 329 cat = currentCatId();
333 330
334 if ( m_curCat == QWidget::tr("Unfiled") ) 331 if ( m_curCat == QWidget::tr("Unfiled") )
335 cat = -1; 332 cat = -1;
336 333
337 return m_todoMgr.sorted(asc, sortOrder, addFilter, cat ); 334 return m_todoMgr.sorted(asc, sortOrder, addFilter, cat );
338} 335}
339OPimTodo MainWindow::event( int uid ) { 336OPimTodo MainWindow::event( int uid ) {
340 return m_todoMgr.event( uid ); 337 return m_todoMgr.event( uid );
341} 338}
342bool MainWindow::isSyncing()const { 339bool MainWindow::isSyncing()const {
343 return m_syncing; 340 return m_syncing;
344} 341}
345TemplateManager* MainWindow::templateManager() { 342TemplateManager* MainWindow::templateManager() {
346 return m_tempManager; 343 return m_tempManager;
347} 344}
348Editor* MainWindow::currentEditor() { 345Editor* MainWindow::currentEditor() {
349 return m_curEdit; 346 return m_curEdit;
350} 347}
351TodoShow* MainWindow::currentShow() { 348TodoShow* MainWindow::currentShow() {
352 return m_curShow; 349 return m_curShow;
353} 350}
354void MainWindow::slotReload() { 351void MainWindow::slotReload() {
355 m_syncing = FALSE; 352 m_syncing = FALSE;
356 m_todoMgr.reload(); 353 m_todoMgr.reload();
357 currentView()->updateView( ); 354 currentView()->updateView( );
358 raiseCurrentView(); 355 raiseCurrentView();
359} 356}
360void MainWindow::closeEvent( QCloseEvent* e ) { 357void MainWindow::closeEvent( QCloseEvent* e ) {
361 if (m_stack->visibleWidget() == currentShow()->widget() ) { 358 if (m_stack->visibleWidget() == currentShow()->widget() ) {
362 m_showing = false; 359 m_showing = false;
363 raiseCurrentView(); 360 raiseCurrentView();
364 e->ignore(); 361 e->ignore();
365 return; 362 return;
366 } 363 }
367 /* 364 /*
368 * we should have flushed and now we're still saving 365 * we should have flushed and now we're still saving
369 * so there is no need to flush 366 * so there is no need to flush
370 */ 367 */
371 if (m_syncing ) { 368 if (m_syncing ) {
372 e->accept(); 369 e->accept();
373 return; 370 return;
374 } 371 }
375 bool quit = false; 372 bool quit = false;
376 if ( m_todoMgr.saveAll() ){ 373 if ( m_todoMgr.saveAll() ){
377 owarn << "saved" << oendl;
378 quit = true; 374 quit = true;
379 }else { 375 }else {
380 if ( QMessageBox::critical( this, QWidget::tr("Out of space"), 376 if ( QMessageBox::critical( this, QWidget::tr("Out of space"),
381 QWidget::tr("Todo was unable\n" 377 QWidget::tr("Todo was unable\n"
382 "to save your changes.\n" 378 "to save your changes.\n"
383 "Free up some space\n" 379 "Free up some space\n"
384 "and try again.\n" 380 "and try again.\n"
385 "\nQuit Anyway?"), 381 "\nQuit Anyway?"),
386 QMessageBox::Yes|QMessageBox::Escape, 382 QMessageBox::Yes|QMessageBox::Escape,
387 QMessageBox::No|QMessageBox::Default) 383 QMessageBox::No|QMessageBox::Default)
388 != QMessageBox::No ) { 384 != QMessageBox::No ) {
389 e->accept(); 385 e->accept();
390 quit = true; 386 quit = true;
391 }else 387 }else
392 e->ignore(); 388 e->ignore();
393 389
394 } 390 }
395 391
396 if (quit ) { 392 if (quit ) {
397 Config config( "todo" ); 393 Config config( "todo" );
398 config.setGroup( "View" ); 394 config.setGroup( "View" );
399 config.writeEntry( "ShowComplete", showCompleted() ); 395 config.writeEntry( "ShowComplete", showCompleted() );
400 config.writeEntry( "Category", currentCategory() ); 396 config.writeEntry( "Category", currentCategory() );
401 config.writeEntry( "ShowDeadLine", showDeadline()); 397 config.writeEntry( "ShowDeadLine", showDeadline());
402 config.writeEntry( "ShowOverDue", showOverDue() ); 398 config.writeEntry( "ShowOverDue", showOverDue() );
403 config.writeEntry( "ShowQuickTask", showQuickTask() ); 399 config.writeEntry( "ShowQuickTask", showQuickTask() );
404 /* save templates */ 400 /* save templates */
405 templateManager()->save(); 401 templateManager()->save();
406 e->accept(); 402 e->accept();
407 QTimer::singleShot(0, qApp, SLOT(closeAllWindows()) ); 403 QTimer::singleShot(0, qApp, SLOT(closeAllWindows()) );
408 } 404 }
409} 405}
410void MainWindow::populateTemplates() { 406void MainWindow::populateTemplates() {
411 m_template->clear(); 407 m_template->clear();
412 QStringList list = templateManager()->templates(); 408 QStringList list = templateManager()->templates();
413 QStringList::Iterator it; 409 QStringList::Iterator it;
414 for ( it = list.begin(); it != list.end(); ++it ) { 410 for ( it = list.begin(); it != list.end(); ++it ) {
415 m_template->insertItem( (*it) ); 411 m_template->insertItem( (*it) );
416 } 412 }
417} 413}
418/* 414/*
419 * slotNewFromTemplate 415 * slotNewFromTemplate
420 * We use the edit widget to do 416 * We use the edit widget to do
421 * the config but we setUid(1) 417 * the config but we setUid(1)
422 * to get a new uid 418 * to get a new uid
423 */ 419 */
424/* 420/*
425 * first we get the name of the template 421 * first we get the name of the template
426 * then we will use the TemplateManager 422 * then we will use the TemplateManager
427 */ 423 */
428void MainWindow::slotNewFromTemplate( int id ) { 424void MainWindow::slotNewFromTemplate( int id ) {
429 QString name = m_template->text( id ); 425 QString name = m_template->text( id );
430 426
431 OPimTodo event = templateManager()->templateEvent( name ); 427 OPimTodo event = templateManager()->templateEvent( name );
432 event = currentEditor()->edit(this, 428 event = currentEditor()->edit(this,
433 event ); 429 event );
434 430
435 if ( currentEditor()->accepted() ) { 431 if ( currentEditor()->accepted() ) {
436 /* assign new todo */ 432 /* assign new todo */
437 event.setUid( 1 ); 433 event.setUid( 1 );
438 handleAlarms( OPimTodo(), event ); 434 handleAlarms( OPimTodo(), event );
439 m_todoMgr.add( event ); 435 m_todoMgr.add( event );
440 currentView()->addEvent( event ); 436 currentView()->addEvent( event );
441 437
442 populateCategories(); 438 populateCategories();
443 } 439 }
444 raiseCurrentView(); 440 raiseCurrentView();
445} 441}
446void MainWindow::slotNew() { 442void MainWindow::slotNew() {
447 create(); 443 create();
448} 444}
449void MainWindow::slotDuplicate() { 445void MainWindow::slotDuplicate() {
450 if(m_syncing) { 446 if(m_syncing) {
451 QMessageBox::warning(this, QWidget::tr("Todo"), 447 QMessageBox::warning(this, QWidget::tr("Todo"),
452 QWidget::tr("Data can not be edited, currently syncing")); 448 QWidget::tr("Data can not be edited, currently syncing"));
453 return; 449 return;
454 } 450 }
455 OPimTodo ev = m_todoMgr.event( currentView()->current() ); 451 OPimTodo ev = m_todoMgr.event( currentView()->current() );
456 /* let's generate a new uid */ 452 /* let's generate a new uid */
457 ev.setUid(1); 453 ev.setUid(1);
458 m_todoMgr.add( ev ); 454 m_todoMgr.add( ev );
459 455
460 currentView()->addEvent( ev ); 456 currentView()->addEvent( ev );
461 raiseCurrentView(); 457 raiseCurrentView();
462} 458}
463void MainWindow::slotDelete() { 459void MainWindow::slotDelete() {
464 if (!currentView()->current() ) 460 if (!currentView()->current() )
465 return; 461 return;
466 462
467 if(m_syncing) { 463 if(m_syncing) {
468 QMessageBox::warning(this, QWidget::tr("Todo"), 464 QMessageBox::warning(this, QWidget::tr("Todo"),
469 QWidget::tr("Data can not be edited, currently syncing")); 465 QWidget::tr("Data can not be edited, currently syncing"));
470 return; 466 return;
471 } 467 }
472 QString strName = currentView()->currentRepresentation(); 468 QString strName = currentView()->currentRepresentation();
473 if (!QPEMessageBox::confirmDelete(this, QWidget::tr("Todo"), strName ) ) 469 if (!QPEMessageBox::confirmDelete(this, QWidget::tr("Todo"), strName ) )
474 return; 470 return;
475 471
476 handleAlarms( m_todoMgr.event( currentView()->current() ), OPimTodo() ); 472 handleAlarms( m_todoMgr.event( currentView()->current() ), OPimTodo() );
477 m_todoMgr.remove( currentView()->current() ); 473 m_todoMgr.remove( currentView()->current() );
478 currentView()->removeEvent( currentView()->current() ); 474 currentView()->removeEvent( currentView()->current() );
479 raiseCurrentView(); 475 raiseCurrentView();
480} 476}
481void MainWindow::slotDelete(int uid ) { 477void MainWindow::slotDelete(int uid ) {
482 if( uid == 0 ) return; 478 if( uid == 0 ) return;
483 if(m_syncing) { 479 if(m_syncing) {
484 QMessageBox::warning(this, QWidget::tr("Todo"), 480 QMessageBox::warning(this, QWidget::tr("Todo"),
485 QWidget::tr("Data can not be edited, currently syncing")); 481 QWidget::tr("Data can not be edited, currently syncing"));
486 return; 482 return;
487 } 483 }
488 OPimTodo to = m_todoMgr.event(uid); 484 OPimTodo to = m_todoMgr.event(uid);
489 if (!QPEMessageBox::confirmDelete(this, QWidget::tr("Todo"), to.toShortText() ) ) 485 if (!QPEMessageBox::confirmDelete(this, QWidget::tr("Todo"), to.toShortText() ) )
490 return; 486 return;
491 487
492 handleAlarms(to, OPimTodo() ); 488 handleAlarms(to, OPimTodo() );
493 m_todoMgr.remove( to.uid() ); 489 m_todoMgr.remove( to.uid() );
494 currentView()->removeEvent( to.uid() ); 490 currentView()->removeEvent( to.uid() );
495 raiseCurrentView(); 491 raiseCurrentView();
496} 492}
497void MainWindow::slotDeleteAll() { 493void MainWindow::slotDeleteAll() {
498 if(m_syncing) { 494 if(m_syncing) {
499 QMessageBox::warning(this, QWidget::tr("Todo"), 495 QMessageBox::warning(this, QWidget::tr("Todo"),
500 QWidget::tr("Data can not be edited, currently syncing")); 496 QWidget::tr("Data can not be edited, currently syncing"));
501 return; 497 return;
502 } 498 }
503 499
504 500
505 if ( !QPEMessageBox::confirmDelete( this, QWidget::tr( "Todo" ), QWidget::tr("all tasks?") ) ) 501 if ( !QPEMessageBox::confirmDelete( this, QWidget::tr( "Todo" ), QWidget::tr("all tasks?") ) )
506 return; 502 return;
507 503
508 m_todoMgr.removeAll(); 504 m_todoMgr.removeAll();
509 currentView()->clear(); 505 currentView()->clear();
510 506
511 raiseCurrentView(); 507 raiseCurrentView();
512} 508}
513void MainWindow::slotDeleteCompleted() { 509void MainWindow::slotDeleteCompleted() {
514 if(m_syncing) { 510 if(m_syncing) {
515 QMessageBox::warning(this, QWidget::tr("Todo"), 511 QMessageBox::warning(this, QWidget::tr("Todo"),
516 QWidget::tr("Data can not be edited, currently syncing")); 512 QWidget::tr("Data can not be edited, currently syncing"));
517 return; 513 return;
518 } 514 }
519 515
520 if ( !QPEMessageBox::confirmDelete( this, QWidget::tr( "Todo" ), QWidget::tr("all completed tasks?") ) ) 516 if ( !QPEMessageBox::confirmDelete( this, QWidget::tr( "Todo" ), QWidget::tr("all completed tasks?") ) )
521 return; 517 return;
522 518
523 519
524 m_todoMgr.removeCompleted(); 520 m_todoMgr.removeCompleted();
525 currentView()->updateView( ); 521 currentView()->updateView( );
526} 522}
527void MainWindow::slotFind() { 523void MainWindow::slotFind() {
528 524
529} 525}
530void MainWindow::slotEdit() { 526void MainWindow::slotEdit() {
531 slotEdit( currentView()->current() ); 527 slotEdit( currentView()->current() );
532} 528}
533/* 529/*
534 * set the category 530 * set the category
535 */ 531 */
536void MainWindow::setCategory( int c) { 532void MainWindow::setCategory( int c) {
537 if ( c <= 0 ) return; 533 if ( c <= 0 ) return;
538 534
539 535
540 owarn << "Iterating over cats " << c << oendl;
541 for ( unsigned int i = 1; i < m_catMenu->count(); i++ ) 536 for ( unsigned int i = 1; i < m_catMenu->count(); i++ )
542 m_catMenu->setItemChecked(i, c == (int)i ); 537 m_catMenu->setItemChecked(i, c == (int)i );
543 538
544 if (c == 1 ) { 539 if (c == 1 ) {
545 m_curCat = QString::null; 540 m_curCat = QString::null;
546 setCaption( QWidget::tr("Todo") + " - " + QWidget::tr("All Categories" ) ); 541 setCaption( QWidget::tr("Todo") + " - " + QWidget::tr("All Categories" ) );
547 542
548 }else if ( c == (int)m_catMenu->count() - 1 ) { 543 }else if ( c == (int)m_catMenu->count() - 1 ) {
549 m_curCat = QWidget::tr("Unfiled"); 544 m_curCat = QWidget::tr("Unfiled");
550 setCaption( QWidget::tr("Todo") + " - " + QWidget::tr("Unfiled") ); 545 setCaption( QWidget::tr("Todo") + " - " + QWidget::tr("Unfiled") );
551 }else { 546 }else {
552 m_curCat = m_todoMgr.categories()[c-2]; 547 m_curCat = m_todoMgr.categories()[c-2];
553 setCaption( QWidget::tr("Todo") + " - " + m_curCat ); 548 setCaption( QWidget::tr("Todo") + " - " + m_curCat );
554 } 549 }
555 m_catMenu->setItemChecked( c, true ); 550 m_catMenu->setItemChecked( c, true );
556 551
557 currentView()->setShowCategory( m_curCat ); 552 currentView()->setShowCategory( m_curCat );
558 raiseCurrentView(); 553 raiseCurrentView();
559} 554}
560void MainWindow::slotShowDeadLine( bool dead) { 555void MainWindow::slotShowDeadLine( bool dead) {
561 m_deadline = dead; 556 m_deadline = dead;
562 currentView()->setShowDeadline( dead ); 557 currentView()->setShowDeadline( dead );
563} 558}
564void MainWindow::slotShowCompleted( bool show) { 559void MainWindow::slotShowCompleted( bool show) {
565 m_completed = show; 560 m_completed = show;
566 currentView()->setShowCompleted( m_completed ); 561 currentView()->setShowCompleted( m_completed );
567} 562}
568void MainWindow::slotShowQuickTask( bool show ) { 563void MainWindow::slotShowQuickTask( bool show ) {
569 m_quicktask = show; 564 m_quicktask = show;
570 if ( m_quicktask ) 565 if ( m_quicktask )
571 m_curQuick->widget()->show(); 566 m_curQuick->widget()->show();
572 else 567 else
573 m_curQuick->widget()->hide(); 568 m_curQuick->widget()->hide();
574} 569}
575bool MainWindow::showOverDue()const { 570bool MainWindow::showOverDue()const {
576 return m_overdue; 571 return m_overdue;
577} 572}
578void MainWindow::setDocument( const QString& fi) { 573void MainWindow::setDocument( const QString& fi) {
579 DocLnk doc(fi); 574 DocLnk doc(fi);
580 if (doc.isValid() ) 575 if (doc.isValid() )
581 receiveFile(doc.file() ); 576 receiveFile(doc.file() );
582 else 577 else
583 receiveFile(fi ); 578 receiveFile(fi );
584} 579}
585 580
586static const char *beamfile = "/tmp/opie-todo.vcs"; 581static const char *beamfile = "/tmp/opie-todo.vcs";
587void MainWindow::slotBeam() { 582void MainWindow::slotBeam() {
588 beam( currentView()->current() ); 583 beam( currentView()->current() );
589} 584}
590void MainWindow::beamDone( Ir* ir) { 585void MainWindow::beamDone( Ir* ir) {
591 delete ir; 586 delete ir;
592 ::unlink( beamfile ); 587 ::unlink( beamfile );
593} 588}
594void MainWindow::receiveFile( const QString& filename ) { 589void MainWindow::receiveFile( const QString& filename ) {
595 OPimTodoAccessVCal* cal = new OPimTodoAccessVCal(filename ); 590 OPimTodoAccessVCal* cal = new OPimTodoAccessVCal(filename );
596 591
597 OPimTodoAccess acc( cal ); 592 OPimTodoAccess acc( cal );
598 acc.load(); 593 acc.load();
599 OPimTodoAccess::List list = acc.allRecords(); 594 OPimTodoAccess::List list = acc.allRecords();
600 595
601 if (list.count()){ 596 if (list.count()){
602 597
603 QString message = QWidget::tr("<P>%1 new tasks arrived.<p>Would you like to add them to your Todolist?").arg(list.count() ); 598 QString message = QWidget::tr("<P>%1 new tasks arrived.<p>Would you like to add them to your Todolist?").arg(list.count() );
604 599
605 if ( QMessageBox::information(this, QWidget::tr("New Tasks"), 600 if ( QMessageBox::information(this, QWidget::tr("New Tasks"),
606 message, QMessageBox::Ok, 601 message, QMessageBox::Ok,
607 QMessageBox::Cancel ) == QMessageBox::Ok ) { 602 QMessageBox::Cancel ) == QMessageBox::Ok ) {
608 OPimTodoAccess::List::Iterator it; 603 OPimTodoAccess::List::Iterator it;
609 for ( it = list.begin(); it != list.end(); ++it ) 604 for ( it = list.begin(); it != list.end(); ++it )
610 m_todoMgr.add( (*it) ); 605 m_todoMgr.add( (*it) );
611 606
612 currentView()->updateView(); 607 currentView()->updateView();
613 } 608 }
614 } 609 }
615} 610}
616 611
617void MainWindow::slotFlush() { 612void MainWindow::slotFlush() {
618 m_syncing = TRUE; 613 m_syncing = TRUE;
619 m_todoMgr.save(); 614 m_todoMgr.save();
620} 615}
621void MainWindow::slotShowDetails() { 616void MainWindow::slotShowDetails() {
622 slotShow( currentView()->current() ); 617 slotShow( currentView()->current() );
623} 618}
624/* 619/*
625 * populate the Categories 620 * populate the Categories
626 * Menu 621 * Menu
627 */ 622 */
628void MainWindow::populateCategories() { 623void MainWindow::populateCategories() {
629 m_todoMgr.load(); 624 m_todoMgr.load();
630 625
631 m_catMenu->clear(); 626 m_catMenu->clear();
632 int id, rememberId; 627 int id, rememberId;
633 id = 1; 628 id = 1;
634 rememberId = 1; 629 rememberId = 1;
635 630
636 m_catMenu->insertItem( QWidget::tr( "All Categories" ), id++ ); 631 m_catMenu->insertItem( QWidget::tr( "All Categories" ), id++ );
637 m_catMenu->insertSeparator(); 632 m_catMenu->insertSeparator();
638 QStringList categories = m_todoMgr.categories(); 633 QStringList categories = m_todoMgr.categories();
639 categories.append( QWidget::tr( "Unfiled" ) ); 634 categories.append( QWidget::tr( "Unfiled" ) );
640 for ( QStringList::Iterator it = categories.begin(); 635 for ( QStringList::Iterator it = categories.begin();
641 it != categories.end(); ++it ) { 636 it != categories.end(); ++it ) {
642 m_catMenu->insertItem( *it, id ); 637 m_catMenu->insertItem( *it, id );
643 if ( *it == currentCategory() ) 638 if ( *it == currentCategory() )
644 rememberId = id; 639 rememberId = id;
645 ++id; 640 ++id;
646 } 641 }
647 setCategory( rememberId ); 642 setCategory( rememberId );
648} 643}
649bool MainWindow::showCompleted()const { 644bool MainWindow::showCompleted()const {
650 return m_completed; 645 return m_completed;
651} 646}
652bool MainWindow::showDeadline()const { 647bool MainWindow::showDeadline()const {
653 return m_deadline; 648 return m_deadline;
654} 649}
655bool MainWindow::showQuickTask()const { 650bool MainWindow::showQuickTask()const {
656 return m_quicktask; 651 return m_quicktask;
657} 652}
658QString MainWindow::currentCategory()const { 653QString MainWindow::currentCategory()const {
659 return m_curCat; 654 return m_curCat;
660} 655}
661int MainWindow::currentCatId() { 656int MainWindow::currentCatId() {
662 return m_todoMgr.catId( m_curCat ); 657 return m_todoMgr.catId( m_curCat );
663} 658}
664ViewBase* MainWindow::currentView() { 659ViewBase* MainWindow::currentView() {
665 return m_curView; 660 return m_curView;
666} 661}
667void MainWindow::raiseCurrentView() { 662void MainWindow::raiseCurrentView() {
668 // due QPE/Application/todolist show(int) 663 // due QPE/Application/todolist show(int)
669 // we might not have the populateCategories slot called once 664 // we might not have the populateCategories slot called once
670 // we would show the otodo but then imediately switch to the currentView 665 // we would show the otodo but then imediately switch to the currentView
671 // if we're initially showing we shouldn't raise the table 666 // if we're initially showing we shouldn't raise the table
672 // in returnFromView we fix up m_showing 667 // in returnFromView we fix up m_showing
673 if (m_showing ) return; 668 if (m_showing ) return;
674 669
675 m_stack->raiseWidget( m_curView->widget() ); 670 m_stack->raiseWidget( m_curView->widget() );
676} 671}
677void MainWindow::slotShowDue(bool ov) { 672void MainWindow::slotShowDue(bool ov) {
678 m_overdue = ov; 673 m_overdue = ov;
679 currentView()->showOverDue( ov ); 674 currentView()->showOverDue( ov );
680 raiseCurrentView(); 675 raiseCurrentView();
681} 676}
682void MainWindow::slotShow( int uid ) { 677void MainWindow::slotShow( int uid ) {
683 if ( uid == 0 ) return; 678 if ( uid == 0 ) return;
684 679
685 680
686 owarn << "slotShow" << oendl;
687 currentShow()->slotShow( event( uid ) ); 681 currentShow()->slotShow( event( uid ) );
688 m_stack->raiseWidget( currentShow()->widget() ); 682 m_stack->raiseWidget( currentShow()->widget() );
689} 683}
690void MainWindow::slotShowNext() { 684void MainWindow::slotShowNext() {
691 int l = currentView()->next(); 685 int l = currentView()->next();
692 if (l!=0) 686 if (l!=0)
693 slotShow(l); 687 slotShow(l);
694} 688}
695void MainWindow::slotShowPrev() { 689void MainWindow::slotShowPrev() {
696 int l = currentView()->prev(); 690 int l = currentView()->prev();
697 if (l!=0) 691 if (l!=0)
698 slotShow(l); 692 slotShow(l);
699} 693}
700void MainWindow::slotEdit( int uid ) { 694void MainWindow::slotEdit( int uid ) {
701 if (uid == 0 ) return; 695 if (uid == 0 ) return;
702 if(m_syncing) { 696 if(m_syncing) {
703 QMessageBox::warning(this, QWidget::tr("Todo"), 697 QMessageBox::warning(this, QWidget::tr("Todo"),
704 QWidget::tr("Data can't be edited, currently syncing")); 698 QWidget::tr("Data can't be edited, currently syncing"));
705 return; 699 return;
706 } 700 }
707 701
708 OPimTodo old_todo = m_todoMgr.event( uid ); 702 OPimTodo old_todo = m_todoMgr.event( uid );
709 703
710 OPimTodo todo = currentEditor()->edit(this, old_todo ); 704 OPimTodo todo = currentEditor()->edit(this, old_todo );
711 705
712 /* if completed */ 706 /* if completed */
713 if ( currentEditor()->accepted() ) { 707 if ( currentEditor()->accepted() ) {
714 handleAlarms( old_todo, todo ); 708 handleAlarms( old_todo, todo );
715 m_todoMgr.update( todo.uid(), todo ); 709 m_todoMgr.update( todo.uid(), todo );
716 currentView()->replaceEvent( todo ); 710 currentView()->replaceEvent( todo );
717 /* a Category might have changed */ 711 /* a Category might have changed */
718 populateCategories(); 712 populateCategories();
719 } 713 }
720 714
721 raiseCurrentView(); 715 raiseCurrentView();
722} 716}
723/* 717/*
724void MainWindow::slotUpdate1( int uid, const SmallTodo& ev) { 718void MainWindow::slotUpdate1( int uid, const SmallTodo& ev) {
725 m_todoMgr.update( uid, ev ); 719 m_todoMgr.update( uid, ev );
726} 720}
727*/ 721*/
728void MainWindow::updateTodo( const OPimTodo& ev) { 722void MainWindow::updateTodo( const OPimTodo& ev) {
729 m_todoMgr.update( ev.uid() , ev ); 723 m_todoMgr.update( ev.uid() , ev );
730} 724}
731/* The view changed it's configuration 725/* The view changed it's configuration
732 * update the view menu 726 * update the view menu
733 */ 727 */
734void MainWindow::slotUpdate3( QWidget* ) { 728void MainWindow::slotUpdate3( QWidget* ) {
735 729
736} 730}
737void MainWindow::updateList() { 731void MainWindow::updateList() {
738 m_todoMgr.updateList(); 732 m_todoMgr.updateList();
739} 733}
740void MainWindow::setReadAhead( uint count ) { 734void MainWindow::setReadAhead( uint count ) {
741 if (m_todoMgr.todoDB() ) 735 if (m_todoMgr.todoDB() )
742 m_todoMgr.todoDB()->setReadAhead( count ); 736 m_todoMgr.todoDB()->setReadAhead( count );
743} 737}
744void MainWindow::slotQuickEntered() { 738void MainWindow::slotQuickEntered() {
745 owarn << "entered" << oendl;
746 OPimTodo todo = quickEditor()->todo(); 739 OPimTodo todo = quickEditor()->todo();
747 if (todo.isEmpty() ) 740 if (todo.isEmpty() )
748 return; 741 return;
749 742
750 m_todoMgr.add( todo ); 743 m_todoMgr.add( todo );
751 currentView()->addEvent( todo ); 744 currentView()->addEvent( todo );
752 raiseCurrentView(); 745 raiseCurrentView();
753} 746}
754QuickEditBase* MainWindow::quickEditor() { 747QuickEditBase* MainWindow::quickEditor() {
755 return m_curQuick; 748 return m_curQuick;
756} 749}
757void MainWindow::slotComplete( int uid ) { 750void MainWindow::slotComplete( int uid ) {
758 slotComplete( event(uid) ); 751 slotComplete( event(uid) );
759} 752}
760void MainWindow::slotComplete( const OPimTodo& todo ) { 753void MainWindow::slotComplete( const OPimTodo& todo ) {
761 OPimTodo to = todo; 754 OPimTodo to = todo;
762 to.setCompleted( !to.isCompleted() ); 755 to.setCompleted( !to.isCompleted() );
763 to.setCompletedDate( QDate::currentDate() ); 756 to.setCompletedDate( QDate::currentDate() );
764 757
765 /* 758 /*
766 * if the item does recur 759 * if the item does recur
767 * we need to spin it off 760 * we need to spin it off
768 * and update the items duedate to the next 761 * and update the items duedate to the next
769 * possible recurrance of this item... 762 * possible recurrance of this item...
770 * the spinned off one will loose the 763 * the spinned off one will loose the
771 * recurrence. 764 * recurrence.
772 * We calculate the difference between the old due date and the 765 * We calculate the difference between the old due date and the
773 * new one and add this diff to start, completed and alarm dates 766 * new one and add this diff to start, completed and alarm dates
774 * -zecke 767 * -zecke
775 */ 768 */
776 if ( to.hasRecurrence() && to.isCompleted() ) { 769 if ( to.hasRecurrence() && to.isCompleted() ) {
777 OPimTodo to2( to ); 770 OPimTodo to2( to );
778 771
779 /* the spinned off one won't recur anymore */ 772 /* the spinned off one won't recur anymore */
780 to.setRecurrence( OPimRecurrence() ); 773 to.setRecurrence( OPimRecurrence() );
781 774
782 OPimRecurrence rec = to2.recurrence(); 775 OPimRecurrence rec = to2.recurrence();
783 rec.setStart( to.dueDate() ); 776 rec.setStart( to.dueDate() );
784 to2.setRecurrence( rec ); 777 to2.setRecurrence( rec );
785 /* 778 /*
786 * if there is a next occurence 779 * if there is a next occurence
787 * from the duedate of the last recurrance 780 * from the duedate of the last recurrance
788 */ 781 */
789 QDate date; 782 QDate date;
790 if ( to2.recurrence().nextOcurrence( to2.dueDate().addDays(1), date ) ) { 783 if ( to2.recurrence().nextOcurrence( to2.dueDate().addDays(1), date ) ) {
791 int dayDiff = to.dueDate().daysTo( date ); 784 int dayDiff = to.dueDate().daysTo( date );
792 owarn << "day diff is " << dayDiff << oendl;
793 QDate inval; 785 QDate inval;
794 /* generate a new uid for the old record */ 786 /* generate a new uid for the old record */
795 to.setUid( 1 ); 787 to.setUid( 1 );
796 788
797 /* add the old one cause it has a new UID here cause it was spin off */ 789 /* add the old one cause it has a new UID here cause it was spin off */
798 m_todoMgr.add( to ); 790 m_todoMgr.add( to );
799 791
800 /* 792 /*
801 * update the due date 793 * update the due date
802 * start date 794 * start date
803 * and complete date 795 * and complete date
804 */ 796 */
805 to2.setDueDate( date ); 797 to2.setDueDate( date );
806 rec.setStart( date ); 798 rec.setStart( date );
807 to2.setRecurrence( rec ); // could be Monday, TuesDay, Thursday every week 799 to2.setRecurrence( rec ); // could be Monday, TuesDay, Thursday every week
808 800
809 /* move start date */ 801 /* move start date */
810 if (to2.hasStartDate() ) 802 if (to2.hasStartDate() )
811 to2.setStartDate( to2.startDate().addDays( dayDiff ) ); 803 to2.setStartDate( to2.startDate().addDays( dayDiff ) );
812 804
813 /* now the alarms */ 805 /* now the alarms */
814 if (to2.hasNotifiers() ) { 806 if (to2.hasNotifiers() ) {
815 OPimNotifyManager::Alarms _als = to2.notifiers().alarms(); 807 OPimNotifyManager::Alarms _als = to2.notifiers().alarms();
816 OPimNotifyManager::Alarms als; 808 OPimNotifyManager::Alarms als;
817 809
818 /* for every alarm move the day */ 810 /* for every alarm move the day */
819 for ( OPimNotifyManager::Alarms::Iterator it = _als.begin(); it != _als.end(); ++it ) { 811 for ( OPimNotifyManager::Alarms::Iterator it = _als.begin(); it != _als.end(); ++it ) {
820 OPimAlarm al = (*it); 812 OPimAlarm al = (*it);
821 al.setDateTime( al.dateTime().addDays( dayDiff ) ); 813 al.setDateTime( al.dateTime().addDays( dayDiff ) );
822 als.append( al ); 814 als.append( al );
823 } 815 }
824 to2.notifiers().setAlarms( als ); 816 to2.notifiers().setAlarms( als );
825 handleAlarms( OPimTodo(), todo ); 817 handleAlarms( OPimTodo(), todo );
826 } 818 }
827 to2.setCompletedDate( inval ); 819 to2.setCompletedDate( inval );
828 to2.setCompleted( false ); 820 to2.setCompleted( false );
829 821
830 updateTodo( to2 ); 822 updateTodo( to2 );
831 }else 823 }else
832 updateTodo( to ); 824 updateTodo( to );
833 }else 825 }else
834 updateTodo( to ); 826 updateTodo( to );
835 827
836 currentView()->updateView(); 828 currentView()->updateView();
837 raiseCurrentView(); 829 raiseCurrentView();
838} 830}
839void MainWindow::flush() { 831void MainWindow::flush() {
840 slotFlush(); 832 slotFlush();
841} 833}
842void MainWindow::reload() { 834void MainWindow::reload() {
843 slotReload(); 835 slotReload();
844} 836}
845int MainWindow::create() { 837int MainWindow::create() {
846 int uid = 0; 838 int uid = 0;
847 if(m_syncing) { 839 if(m_syncing) {
848 QMessageBox::warning(this, QWidget::tr("Todo"), 840 QMessageBox::warning(this, QWidget::tr("Todo"),
849 QWidget::tr("Data can not be edited, currently syncing")); 841 QWidget::tr("Data can not be edited, currently syncing"));
850 return uid; 842 return uid;
851 } 843 }
852 m_todoMgr.load(); 844 m_todoMgr.load();
853 845
854 846
855 OPimTodo todo = currentEditor()->newTodo( currentCatId(), 847 OPimTodo todo = currentEditor()->newTodo( currentCatId(),
856 this ); 848 this );
857 849
858 if ( currentEditor()->accepted() ) { 850 if ( currentEditor()->accepted() ) {
859 //todo.assignUid(); 851 //todo.assignUid();
860 uid = todo.uid(); 852 uid = todo.uid();
861 handleAlarms( OPimTodo(), todo ); 853 handleAlarms( OPimTodo(), todo );
862 m_todoMgr.add( todo ); 854 m_todoMgr.add( todo );
863 currentView()->addEvent( todo ); 855 currentView()->addEvent( todo );
864 856
865 857
866 // I'm afraid we must call this every time now, otherwise 858 // I'm afraid we must call this every time now, otherwise
867 // spend expensive time comparing all these strings... 859 // spend expensive time comparing all these strings...
868 // but only call if we changed something -zecke 860 // but only call if we changed something -zecke
869 populateCategories(); 861 populateCategories();
870 } 862 }
871 raiseCurrentView( ); 863 raiseCurrentView( );
872 864
873 return uid; 865 return uid;
874} 866}
875/* delete it silently... */ 867/* delete it silently... */
876bool MainWindow::remove( int uid ) { 868bool MainWindow::remove( int uid ) {
877 if (m_syncing) return false; 869 if (m_syncing) return false;
878 870
879 /* argh need to get the whole OEvent... to disable alarms -zecke */ 871 /* argh need to get the whole OEvent... to disable alarms -zecke */
880 handleAlarms( OPimTodo(), m_todoMgr.event( uid ) ); 872 handleAlarms( OPimTodo(), m_todoMgr.event( uid ) );
881 873
882 return m_todoMgr.remove( uid ); 874 return m_todoMgr.remove( uid );
883} 875}
884void MainWindow::beam( int uid) { 876void MainWindow::beam( int uid) {
885 if( uid == 0 ) return; 877 if( uid == 0 ) return;
886 878
887 ::unlink( beamfile ); 879 ::unlink( beamfile );
888 m_todoMgr.load(); 880 m_todoMgr.load();
889 881
890 OPimTodo todo = event( uid ); 882 OPimTodo todo = event( uid );
891 OPimTodoAccessVCal* cal = new OPimTodoAccessVCal(QString::fromLatin1(beamfile) ); 883 OPimTodoAccessVCal* cal = new OPimTodoAccessVCal(QString::fromLatin1(beamfile) );
892 OPimTodoAccess acc( cal ); 884 OPimTodoAccess acc( cal );
893 acc.load(); 885 acc.load();
894 acc.add( todo ); 886 acc.add( todo );
895 acc.save(); 887 acc.save();
896 Ir* ir = new Ir(this ); 888 Ir* ir = new Ir(this );
897 connect(ir, SIGNAL(done(Ir*) ), 889 connect(ir, SIGNAL(done(Ir*) ),
898 this, SLOT(beamDone(Ir*) ) ); 890 this, SLOT(beamDone(Ir*) ) );
899 ir->send(beamfile, todo.summary(), "text/x-vCalendar" ); 891 ir->send(beamfile, todo.summary(), "text/x-vCalendar" );
900} 892}
901void MainWindow::show( int uid ) { 893void MainWindow::show( int uid ) {
902 m_todoMgr.load(); // might not be loaded yet 894 m_todoMgr.load(); // might not be loaded yet
903 m_showing = true; 895 m_showing = true;
904 slotShow( uid ); 896 slotShow( uid );
905 raise(); 897 raise();
906 QPEApplication::setKeepRunning(); 898 QPEApplication::setKeepRunning();
907} 899}
908void MainWindow::edit( int uid ) { 900void MainWindow::edit( int uid ) {
909 m_todoMgr.load(); 901 m_todoMgr.load();
910 slotEdit( uid ); 902 slotEdit( uid );
911} 903}
912void MainWindow::add( const OPimRecord& rec) { 904void MainWindow::add( const OPimRecord& rec) {
913 OPimTodo test; 905 OPimTodo test;
914 if ( rec.rtti() != test.rtti() ) return; 906 if ( rec.rtti() != test.rtti() ) return;
915 m_todoMgr.load(); // might not be loaded 907 m_todoMgr.load(); // might not be loaded
916 908
917 const OPimTodo& todo = static_cast<const OPimTodo&>(rec); 909 const OPimTodo& todo = static_cast<const OPimTodo&>(rec);
918 910
919 m_todoMgr.add(todo ); 911 m_todoMgr.add(todo );
920 currentView()->addEvent( todo ); 912 currentView()->addEvent( todo );
921 913
922 914
923 // I'm afraid we must call this every time now, otherwise 915 // I'm afraid we must call this every time now, otherwise
924 // spend expensive time comparing all these strings... 916 // spend expensive time comparing all these strings...
925 // but only call if we changed something -zecke 917 // but only call if we changed something -zecke
926 populateCategories(); 918 populateCategories();
927} 919}
928void MainWindow::slotReturnFromView() { 920void MainWindow::slotReturnFromView() {
929 m_showing = false; 921 m_showing = false;
930 raiseCurrentView(); 922 raiseCurrentView();
931} 923}
932 924
933namespace { 925namespace {
934 OPimNotifyManager::Alarms findNonMatching( const OPimNotifyManager::Alarms& oldAls, 926 OPimNotifyManager::Alarms findNonMatching( const OPimNotifyManager::Alarms& oldAls,
935 const OPimNotifyManager::Alarms& newAls ) { 927 const OPimNotifyManager::Alarms& newAls ) {
936 OPimNotifyManager::Alarms nonMatching; 928 OPimNotifyManager::Alarms nonMatching;
937 OPimNotifyManager::Alarms::ConstIterator oldIt = oldAls.begin(); 929 OPimNotifyManager::Alarms::ConstIterator oldIt = oldAls.begin();
938 OPimNotifyManager::Alarms::ConstIterator newIt; 930 OPimNotifyManager::Alarms::ConstIterator newIt;
939 for ( ; oldIt != oldAls.end(); ++oldIt ) { 931 for ( ; oldIt != oldAls.end(); ++oldIt ) {
940 bool found = false; 932 bool found = false;
941 QDateTime oldDt = (*oldIt).dateTime(); 933 QDateTime oldDt = (*oldIt).dateTime();
942 for (newIt= newAls.begin(); newIt != newAls.end(); ++newIt ) { 934 for (newIt= newAls.begin(); newIt != newAls.end(); ++newIt ) {
943 if ( oldDt == (*newIt).dateTime() ) { 935 if ( oldDt == (*newIt).dateTime() ) {
944 found = true; 936 found = true;
945 break; 937 break;
946 } 938 }
947 } 939 }
948 if (!found) 940 if (!found)
949 nonMatching.append( (*oldIt) ); 941 nonMatching.append( (*oldIt) );
950 } 942 }
951 return nonMatching; 943 return nonMatching;
952 } 944 }
953 void addAlarms( const OPimNotifyManager::Alarms& als, int uid ) { 945 void addAlarms( const OPimNotifyManager::Alarms& als, int uid ) {
954 OPimNotifyManager::Alarms::ConstIterator it; 946 OPimNotifyManager::Alarms::ConstIterator it;
955 for ( it = als.begin(); it != als.end(); ++it ) { 947 for ( it = als.begin(); it != als.end(); ++it ) {
956 owarn << "Adding alarm for " << (*it).dateTime().toString() << oendl;
957 AlarmServer::addAlarm( (*it).dateTime(), "QPE/Application/todolist", "alarm(QDateTime,int)", uid ); 948 AlarmServer::addAlarm( (*it).dateTime(), "QPE/Application/todolist", "alarm(QDateTime,int)", uid );
958 } 949 }
959 950
960 } 951 }
961 void removeAlarms( const OPimNotifyManager::Alarms& als, int uid ) { 952 void removeAlarms( const OPimNotifyManager::Alarms& als, int uid ) {
962 OPimNotifyManager::Alarms::ConstIterator it; 953 OPimNotifyManager::Alarms::ConstIterator it;
963 for ( it = als.begin(); it != als.end(); ++it ) { 954 for ( it = als.begin(); it != als.end(); ++it ) {
964 owarn << "Removinf alarm for " << (*it).dateTime().toString() << oendl;
965 AlarmServer::deleteAlarm( (*it).dateTime(), "QPE/Application/todolist", "alarm(QDateTime,int)", uid ); 955 AlarmServer::deleteAlarm( (*it).dateTime(), "QPE/Application/todolist", "alarm(QDateTime,int)", uid );
966 } 956 }
967 } 957 }
968} 958}
969 959
970void MainWindow::handleAlarms( const OPimTodo& oldTodo, const OPimTodo& newTodo) { 960void MainWindow::handleAlarms( const OPimTodo& oldTodo, const OPimTodo& newTodo) {
971 /* 961 /*
972 * if oldTodo is not empty and has notifiers we need to find the deleted ones 962 * if oldTodo is not empty and has notifiers we need to find the deleted ones
973 */ 963 */
974 if(!oldTodo.isEmpty() && oldTodo.hasNotifiers() ) { 964 if(!oldTodo.isEmpty() && oldTodo.hasNotifiers() ) {
975 OPimNotifyManager::Alarms removed; 965 OPimNotifyManager::Alarms removed;
976 OPimNotifyManager::Alarms oldAls = oldTodo.notifiers().alarms(); 966 OPimNotifyManager::Alarms oldAls = oldTodo.notifiers().alarms();
977 if (!newTodo.hasNotifiers() ) 967 if (!newTodo.hasNotifiers() )
978 removed = oldAls; 968 removed = oldAls;
979 else 969 else
980 removed = findNonMatching( oldAls, newTodo.notifiers().alarms() ); 970 removed = findNonMatching( oldAls, newTodo.notifiers().alarms() );
981 971
982 removeAlarms( removed, oldTodo.uid() ); 972 removeAlarms( removed, oldTodo.uid() );
983 } 973 }
984 if ( newTodo.hasNotifiers() ) { 974 if ( newTodo.hasNotifiers() ) {
985 OPimNotifyManager::Alarms added; 975 OPimNotifyManager::Alarms added;
986 if ( oldTodo.isEmpty() || !oldTodo.hasNotifiers() ) 976 if ( oldTodo.isEmpty() || !oldTodo.hasNotifiers() )
987 added = newTodo.notifiers().alarms(); 977 added = newTodo.notifiers().alarms();
988 else 978 else
989 added = findNonMatching( newTodo.notifiers().alarms(), oldTodo.notifiers().alarms() ); 979 added = findNonMatching( newTodo.notifiers().alarms(), oldTodo.notifiers().alarms() );
990 980
991 addAlarms( added, newTodo.uid() ); 981 addAlarms( added, newTodo.uid() );
992 } 982 }
993} 983}
994/* we might have not loaded the db */ 984/* we might have not loaded the db */
995void MainWindow::doAlarm( const QDateTime& dt, int uid ) { 985void MainWindow::doAlarm( const QDateTime& dt, int uid ) {
996 m_todoMgr.load(); 986 m_todoMgr.load();
997 987
998 OPimTodo todo = m_todoMgr.event( uid ); 988 OPimTodo todo = m_todoMgr.event( uid );
999 if (!todo.hasNotifiers() ) return; 989 if (!todo.hasNotifiers() ) return;
1000 990
1001 /* 991 /*
1002 * let's find the right alarm and find out if silent 992 * let's find the right alarm and find out if silent
1003 * then show a richtext widget 993 * then show a richtext widget
1004 */ 994 */
1005 bool loud = false; 995 bool loud = false;
1006 OPimNotifyManager::Alarms als = todo.notifiers().alarms(); 996 OPimNotifyManager::Alarms als = todo.notifiers().alarms();
1007 OPimNotifyManager::Alarms::Iterator it; 997 OPimNotifyManager::Alarms::Iterator it;
1008 for ( it = als.begin(); it != als.end(); ++it ) { 998 for ( it = als.begin(); it != als.end(); ++it ) {
1009 if ( (*it).dateTime() == dt ) { 999 if ( (*it).dateTime() == dt ) {
1010 loud = ( (*it).sound() == OPimAlarm::Loud ); 1000 loud = ( (*it).sound() == OPimAlarm::Loud );
1011 break; 1001 break;
1012 } 1002 }
1013 } 1003 }
1014 if (loud) 1004 if (loud)
1015 startAlarm(); 1005 startAlarm();
1016 1006
1017 QDialog dlg(this, 0, TRUE ); 1007 QDialog dlg(this, 0, TRUE );
1018 QVBoxLayout* lay = new QVBoxLayout( &dlg ); 1008 QVBoxLayout* lay = new QVBoxLayout( &dlg );
1019 QTextView* view = new QTextView( &dlg ); 1009 QTextView* view = new QTextView( &dlg );
1020 lay->addWidget( view ); 1010 lay->addWidget( view );
1021 QPushButton* btnOk = new QPushButton( tr("Ok"), &dlg ); 1011 QPushButton* btnOk = new QPushButton( tr("Ok"), &dlg );
1022 connect( btnOk, SIGNAL(clicked() ), &dlg, SLOT(accept() ) ); 1012 connect( btnOk, SIGNAL(clicked() ), &dlg, SLOT(accept() ) );
1023 lay->addWidget( btnOk ); 1013 lay->addWidget( btnOk );
1024 1014
1025 QString text = tr("<h1>Alarm at %1</h1><br>").arg( TimeString::dateString( dt ) ); 1015 QString text = tr("<h1>Alarm at %1</h1><br>").arg( TimeString::dateString( dt ) );
1026 text += todo.toRichText(); 1016 text += todo.toRichText();
1027 view->setText( text ); 1017 view->setText( text );
1028 1018
1029 bool needToStay = QPEApplication::execDialog( &dlg ); 1019 bool needToStay = QPEApplication::execDialog( &dlg );
1030 1020
1031 if (loud) 1021 if (loud)
1032 killAlarm(); 1022 killAlarm();
1033 1023
1034 if (needToStay) { 1024 if (needToStay) {
1035// showMaximized(); 1025// showMaximized();
1036// raise(); 1026// raise();
1037 QPEApplication::setKeepRunning(); 1027 QPEApplication::setKeepRunning();
1038// setActiveWindow(); 1028// setActiveWindow();
1039 } 1029 }
1040 1030
1041} 1031}
1042 1032
diff --git a/core/pim/todo/tableview.cpp b/core/pim/todo/tableview.cpp
index b7458d8..221faca 100644
--- a/core/pim/todo/tableview.cpp
+++ b/core/pim/todo/tableview.cpp
@@ -1,640 +1,644 @@
1/* 1/*
2               =. This file is part of the OPIE Project 2               =. This file is part of the OPIE Project
3             .=l. Copyright (c) 2002 <zecke> 3             .=l. Copyright (c) 2002 <zecke>
4           .>+-= 4           .>+-=
5 _;:,     .>    :=|. This program is free software; you can 5 _;:,     .>    :=|. This program is free software; you can
6.> <`_,   >  .   <= redistribute it and/or modify it under 6.> <`_,   >  .   <= redistribute it and/or modify it under
7:`=1 )Y*s>-.--   : the terms of the GNU General Public 7:`=1 )Y*s>-.--   : the terms of the GNU General Public
8.="- .-=="i,     .._ License as published by the Free Software 8.="- .-=="i,     .._ License as published by the Free Software
9 - .   .-<_>     .<> Foundation; either version 2 of the License, 9 - .   .-<_>     .<> Foundation; either version 2 of the License,
10     ._= =}       : or (at your option) any later version. 10     ._= =}       : or (at your option) any later version.
11    .%`+i>       _;_. 11    .%`+i>       _;_.
12    .i_,=:_.      -<s. This program is distributed in the hope that 12    .i_,=:_.      -<s. This program is distributed in the hope that
13     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY; 13     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
14    : ..    .:,     . . . without even the implied warranty of 14    : ..    .:,     . . . without even the implied warranty of
15    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A 15    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
16  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU 16  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU
17..}^=.=       =       ; Library General Public License for more 17..}^=.=       =       ; Library General Public License for more
18++=   -.     .`     .: details. 18++=   -.     .`     .: details.
19 :     =  ...= . :.=- 19 :     =  ...= . :.=-
20 -.   .:....=;==+<; You should have received a copy of the GNU 20 -.   .:....=;==+<; You should have received a copy of the GNU
21  -_. . .   )=.  = Library General Public License along with 21  -_. . .   )=.  = Library General Public License along with
22    --        :-=` this library; see the file COPYING.LIB. 22    --        :-=` this library; see the file COPYING.LIB.
23 If not, write to the Free Software Foundation, 23 If not, write to the Free Software Foundation,
24 Inc., 59 Temple Place - Suite 330, 24 Inc., 59 Temple Place - Suite 330,
25 Boston, MA 02111-1307, USA. 25 Boston, MA 02111-1307, USA.
26 26
27*/ 27*/
28#include <stdlib.h> 28#include <stdlib.h>
29#include <cmath> 29#include <cmath>
30#include <cctype> 30#include <cctype>
31 31
32#include <opie2/odebug.h> 32#include <opie2/odebug.h>
33#include <opie2/opimrecurrence.h> 33#include <opie2/opimrecurrence.h>
34 34
35#include <qpe/config.h> 35#include <qpe/config.h>
36#include <qpe/resource.h> 36#include <qpe/resource.h>
37 37
38#include <qcombobox.h> 38#include <qcombobox.h>
39#include <qlineedit.h> 39#include <qlineedit.h>
40#include <qtimer.h> 40#include <qtimer.h>
41#include <qpopupmenu.h> 41#include <qpopupmenu.h>
42 42
43#include "mainwindow.h" 43#include "mainwindow.h"
44//#include "tableitems.h" 44//#include "tableitems.h"
45#include "tableview.h" 45#include "tableview.h"
46 46
47using namespace Todo; 47using namespace Todo;
48 48
49namespace { 49namespace {
50 static const int BoxSize = 14; 50 static const int BoxSize = 14;
51 static const int RowHeight = 20; 51 static const int RowHeight = 20;
52} 52}
53 53
54TableView::EditorWidget::EditorWidget() : m_wid(0l), m_row(-1), m_col(-1) { 54TableView::EditorWidget::EditorWidget() : m_wid(0l), m_row(-1), m_col(-1) {
55} 55}
56void TableView::EditorWidget::setCellWidget(QWidget* wid, int row, int col ) { 56void TableView::EditorWidget::setCellWidget(QWidget* wid, int row, int col ) {
57 m_wid = wid; 57 m_wid = wid;
58 m_row = row; 58 m_row = row;
59 m_col = col; 59 m_col = col;
60} 60}
61void TableView::EditorWidget::releaseCellWidget() { 61void TableView::EditorWidget::releaseCellWidget() {
62 m_wid = 0; 62 m_wid = 0;
63 m_row = m_col = -1; 63 m_row = m_col = -1;
64} 64}
65QWidget* TableView::EditorWidget::cellWidget()const { 65QWidget* TableView::EditorWidget::cellWidget()const {
66 return m_wid; 66 return m_wid;
67} 67}
68int TableView::EditorWidget::cellRow()const { 68int TableView::EditorWidget::cellRow()const {
69 return m_row; 69 return m_row;
70} 70}
71int TableView::EditorWidget::cellCol()const { 71int TableView::EditorWidget::cellCol()const {
72 return m_col; 72 return m_col;
73} 73}
74 74
75 75
76void TableView::initConfig() { 76void TableView::initConfig() {
77 Config config( "todo" ); 77 Config config( "todo" );
78 config.setGroup( "Options" ); 78 config.setGroup( "Options" );
79 m_completeStrokeWidth = config.readNumEntry( "CompleteStrokeWidth", 8 ); 79 m_completeStrokeWidth = config.readNumEntry( "CompleteStrokeWidth", 8 );
80 for (int i = 0; i < numCols(); i++ ) { 80 for (int i = 0; i < numCols(); i++ ) {
81 int width = config.readNumEntry("Width"+QString::number(i), -1 ); 81 int width = config.readNumEntry("Width"+QString::number(i), -1 );
82 setColumnWidth(i, width == -1 ? columnWidth(i) : width ); 82 setColumnWidth(i, width == -1 ? columnWidth(i) : width );
83 } 83 }
84} 84}
85 85
86TableView::TableView( MainWindow* window, QWidget* wid ) 86TableView::TableView( MainWindow* window, QWidget* wid )
87 : QTable( wid ), TodoView( window ) { 87 : QTable( wid ), TodoView( window ) {
88 88
89 setName("TableView"); 89 setName("TableView");
90 // Load icons 90 // Load icons
91 // TODO - probably should be done globally somewhere else, 91 // TODO - probably should be done globally somewhere else,
92 // see also quickeditimpl.cpp/h, taskeditoroverview.cpp/h 92 // see also quickeditimpl.cpp/h, taskeditoroverview.cpp/h
93 m_pic_completed = Resource::loadPixmap( "todo/completed" ); 93 m_pic_completed = Resource::loadPixmap( "todo/completed" );
94 QString namestr; 94 QString namestr;
95 for ( unsigned int i = 1; i < 6; i++ ) { 95 for ( unsigned int i = 1; i < 6; i++ ) {
96 namestr = "todo/priority"; 96 namestr = "todo/priority";
97 namestr.append( QString::number( i ) ); 97 namestr.append( QString::number( i ) );
98 m_pic_priority[ i - 1 ] = Resource::loadPixmap( namestr ); 98 m_pic_priority[ i - 1 ] = Resource::loadPixmap( namestr );
99 } 99 }
100 100
101 setUpdatesEnabled( false ); 101 setUpdatesEnabled( false );
102 viewport()->setUpdatesEnabled( false ); 102 viewport()->setUpdatesEnabled( false );
103 m_enablePaint = false; 103 m_enablePaint = false;
104 setNumRows(0); 104 setNumRows(0);
105 setNumCols(4); 105 setNumCols(4);
106 106
107 horizontalHeader()->setLabel( 0, QWidget::tr("C.") ); 107 horizontalHeader()->setLabel( 0, QWidget::tr("C.") );
108 horizontalHeader()->setLabel( 1, QWidget::tr("Priority") ); 108 horizontalHeader()->setLabel( 1, QWidget::tr("Priority") );
109 horizontalHeader()->setLabel( 2, QWidget::tr("Summary" ) ); 109 horizontalHeader()->setLabel( 2, QWidget::tr("Summary" ) );
110 horizontalHeader()->setLabel( 3, QWidget::tr("Deadline") ); 110 horizontalHeader()->setLabel( 3, QWidget::tr("Deadline") );
111 111
112 setShowDeadline( todoWindow()->showDeadline() ); 112 setShowDeadline( todoWindow()->showDeadline() );
113 113
114 setSorting( TRUE ); 114 setSorting( TRUE );
115 setSelectionMode( NoSelection ); 115 setSelectionMode( NoSelection );
116 116
117 setLeftMargin( 0 ); 117 setLeftMargin( 0 );
118 verticalHeader()->hide(); 118 verticalHeader()->hide();
119 119
120 connect((QTable*)this, SIGNAL( clicked(int,int,int,const QPoint&) ), 120 connect((QTable*)this, SIGNAL( clicked(int,int,int,const QPoint&) ),
121 this, SLOT( slotClicked(int,int,int,const QPoint&) ) ); 121 this, SLOT( slotClicked(int,int,int,const QPoint&) ) );
122 connect((QTable*)this, SIGNAL( pressed(int,int,int,const QPoint&) ), 122 connect((QTable*)this, SIGNAL( pressed(int,int,int,const QPoint&) ),
123 this, SLOT( slotPressed(int,int,int,const QPoint&) ) ); 123 this, SLOT( slotPressed(int,int,int,const QPoint&) ) );
124 connect((QTable*)this, SIGNAL(valueChanged(int,int) ), 124 connect((QTable*)this, SIGNAL(valueChanged(int,int) ),
125 this, SLOT( slotValueChanged(int,int) ) ); 125 this, SLOT( slotValueChanged(int,int) ) );
126 connect((QTable*)this, SIGNAL(currentChanged(int,int) ), 126 connect((QTable*)this, SIGNAL(currentChanged(int,int) ),
127 this, SLOT( slotCurrentChanged(int,int) ) ); 127 this, SLOT( slotCurrentChanged(int,int) ) );
128 128
129 m_menuTimer = new QTimer( this ); 129 m_menuTimer = new QTimer( this );
130 connect( m_menuTimer, SIGNAL(timeout()), 130 connect( m_menuTimer, SIGNAL(timeout()),
131 this, SLOT(slotShowMenu()) ); 131 this, SLOT(slotShowMenu()) );
132 132
133 /* now let's init the config */ 133 /* now let's init the config */
134 initConfig(); 134 initConfig();
135 135
136 136
137 m_enablePaint = true; 137 m_enablePaint = true;
138 setUpdatesEnabled( true ); 138 setUpdatesEnabled( true );
139 viewport()->setUpdatesEnabled( true ); 139 viewport()->setUpdatesEnabled( true );
140 viewport()->update(); 140 viewport()->update();
141 setSortOrder( 0 ); 141 setSortOrder( Opie::OPimTodoAccess::Completed );
142 setAscending( TRUE ); 142 setAscending( TRUE );
143 m_first = true; 143 m_first = true;
144 144
145 145
146} 146}
147/* a new day has started 147/* a new day has started
148 * update the day 148 * update the day
149 */ 149 */
150void TableView::newDay() { 150void TableView::newDay() {
151 clear(); 151 clear();
152 updateView(); 152 updateView();
153} 153}
154TableView::~TableView() { 154TableView::~TableView() {
155 Config config( "todo" ); 155 Config config( "todo" );
156 config.setGroup( "Options" ); 156 config.setGroup( "Options" );
157 for (int i = 0; i < numCols(); i++ ) 157 for (int i = 0; i < numCols(); i++ )
158 config.writeEntry("Width"+QString::number(i), columnWidth(i) ); 158 config.writeEntry("Width"+QString::number(i), columnWidth(i) );
159} 159}
160void TableView::slotShowMenu() { 160void TableView::slotShowMenu() {
161 QPopupMenu *menu = todoWindow()->contextMenu( current(), sorted()[currentRow()].recurrence().doesRecur() ); 161 QPopupMenu *menu = todoWindow()->contextMenu( current(), sorted()[currentRow()].recurrence().doesRecur() );
162 menu->exec(QCursor::pos() ); 162 menu->exec(QCursor::pos() );
163 delete menu; 163 delete menu;
164} 164}
165QString TableView::type() const { 165QString TableView::type() const {
166 return QString::fromLatin1( tr("Table View") ); 166 return QString::fromLatin1( tr("Table View") );
167} 167}
168int TableView::current() { 168int TableView::current() {
169 if (numRows() == 0 ) return 0; 169 if (numRows() == 0 ) return 0;
170 int uid = sorted().uidAt(currentRow() ); 170 int uid = sorted().uidAt(currentRow() );
171 171
172 return uid; 172 return uid;
173} 173}
174int TableView::next() { 174int TableView::next() {
175 if ( numRows() == 0 ) return 0; 175 if ( numRows() == 0 ) return 0;
176 if ( currentRow() + 1 >= numRows() ) return 0; 176 if ( currentRow() + 1 >= numRows() ) return 0;
177 setCurrentCell( currentRow() +1, currentColumn() ); 177 setCurrentCell( currentRow() +1, currentColumn() );
178 return sorted().uidAt( currentRow() ); 178 return sorted().uidAt( currentRow() );
179} 179}
180int TableView::prev() { 180int TableView::prev() {
181 if ( numRows() == 0 ) return 0; 181 if ( numRows() == 0 ) return 0;
182 if ( currentRow() - 1 < 0 ) return 0; 182 if ( currentRow() - 1 < 0 ) return 0;
183 setCurrentCell( currentRow() -1, currentColumn() ); 183 setCurrentCell( currentRow() -1, currentColumn() );
184 return sorted().uidAt( currentRow() ); 184 return sorted().uidAt( currentRow() );
185 185
186} 186}
187QString TableView::currentRepresentation() { 187QString TableView::currentRepresentation() {
188 OPimTodo to = sorted()[currentRow()]; 188 OPimTodo to = sorted()[currentRow()];
189 return to.summary().isEmpty() ? to.description().left(20) : to.summary() ; 189 return to.summary().isEmpty() ? to.description().left(20) : to.summary() ;
190} 190}
191/* show overdue */ 191/* show overdue */
192void TableView::showOverDue( bool ) { 192void TableView::showOverDue( bool ) {
193 clear(); 193 clear();
194 updateView(); 194 updateView();
195} 195}
196 196
197void TableView::updateView( ) { 197void TableView::updateView( ) {
198 owarn << "update view" << oendl;
199 m_row = false; 198 m_row = false;
200 static int id; 199 static int id;
201 id = startTimer(4000 ); 200 id = startTimer(4000 );
202 /* FIXME we want one page to be read! 201 /* FIXME we want one page to be read!
203 * 202 *
204 * Calculate that screensize 203 * Calculate that screensize
205 */ 204 */
206 todoWindow()->setReadAhead( 4 ); 205 todoWindow()->setReadAhead( 4 );
207 sort(); 206 sort();
208 OPimTodoAccess::List::Iterator it, end; 207 OPimTodoAccess::List::Iterator it, end;
209 it = sorted().begin(); 208 it = sorted().begin();
210 end = sorted().end(); 209 end = sorted().end();
211 210
212 owarn << "setTodos" << oendl;
213 QTime time; 211 QTime time;
214 time.start(); 212 time.start();
215 m_enablePaint = false; 213 m_enablePaint = false;
216 setUpdatesEnabled( false ); 214 setUpdatesEnabled( false );
217 viewport()->setUpdatesEnabled( false ); 215 viewport()->setUpdatesEnabled( false );
218 216
219 setNumRows( it.count() ); 217 setNumRows( it.count() );
220 if ( it.count() == 0 ) 218 if ( it.count() == 0 )
221 killTimer(id); 219 killTimer(id);
222 220
223// int elc = time.elapsed(); 221// int elc = time.elapsed();
224 setUpdatesEnabled( true ); 222 setUpdatesEnabled( true );
225 viewport()->setUpdatesEnabled( true ); 223 viewport()->setUpdatesEnabled( true );
226 viewport()->update(); 224 viewport()->update();
227 225
228 m_enablePaint = true; 226 m_enablePaint = true;
229// int el = time.elapsed(); 227// int el = time.elapsed();
230} 228}
231void TableView::setTodo( int, const OPimTodo&) { 229void TableView::setTodo( int, const OPimTodo&) {
232 sort(); 230 sort();
233 231
234 /* repaint */ 232 /* repaint */
235 repaint(); 233 repaint();
236} 234}
237void TableView::addEvent( const OPimTodo&) { 235void TableView::addEvent( const OPimTodo&) {
238 236
239 /* fix problems of not showing the 'Haken' */ 237 /* fix problems of not showing the 'Haken' */
240 updateView(); 238 updateView();
241} 239}
242/* 240/*
243 * find the event 241 * find the event
244 * and then replace the complete row 242 * and then replace the complete row
245 */ 243 */
246void TableView::replaceEvent( const OPimTodo& ev) { 244void TableView::replaceEvent( const OPimTodo& ev) {
247 addEvent( ev ); 245 addEvent( ev );
248} 246}
249/* 247/*
250 * re aligning table can be slow too 248 * re aligning table can be slow too
251 * FIXME: look what performs better 249 * FIXME: look what performs better
252 * either this or the old align table 250 * either this or the old align table
253 */ 251 */
254void TableView::removeEvent( int ) { 252void TableView::removeEvent( int ) {
255 updateView(); 253 updateView();
256} 254}
257void TableView::setShowCompleted( bool b) { 255void TableView::setShowCompleted( bool ) {
258 owarn << "Show Completed " << b << oendl;
259 updateView(); 256 updateView();
260} 257}
261void TableView::setShowDeadline( bool b ) { 258void TableView::setShowDeadline( bool b ) {
262 owarn << "Show Deadline " << b << oendl;
263 if ( b ) 259 if ( b )
264 showColumn( 3 ); 260 showColumn( 3 );
265 else 261 else
266 hideColumn( 3 ); 262 hideColumn( 3 );
267 263
268 // Try to intelligently size columns 264 // Try to intelligently size columns
269 // TODO - would use width() below, but doesn't have valid value at time of c'tor 265 // TODO - would use width() below, but doesn't have valid value at time of c'tor
270 int col2width = 238; 266 int col2width = 238;
271 int width = m_pic_completed.width(); 267 int width = m_pic_completed.width();
272 setColumnWidth( 0, width ); 268 setColumnWidth( 0, width );
273 col2width -= width; 269 col2width -= width;
274 width = fontMetrics().boundingRect( horizontalHeader()->label( 1 ) ).width() + 8; 270 width = fontMetrics().boundingRect( horizontalHeader()->label( 1 ) ).width() + 8;
275 setColumnWidth( 1, width ); 271 setColumnWidth( 1, width );
276 col2width -= width; 272 col2width -= width;
277 if ( b ) { 273 if ( b ) {
278 width = fontMetrics().boundingRect( horizontalHeader()->label( 3 ) ).width() + 8; 274 width = fontMetrics().boundingRect( horizontalHeader()->label( 3 ) ).width() + 8;
279 setColumnWidth( 3, width ); 275 setColumnWidth( 3, width );
280 col2width -= width; 276 col2width -= width;
281 } 277 }
282 setColumnWidth( 2, col2width ); 278 setColumnWidth( 2, col2width );
283} 279}
284void TableView::setShowCategory( const QString& str) { 280void TableView::setShowCategory( const QString& str) {
285 owarn << "setShowCategory" << oendl;
286 if ( str != m_oleCat || m_first ) 281 if ( str != m_oleCat || m_first )
287 updateView(); 282 updateView();
288 283
289 m_oleCat = str; 284 m_oleCat = str;
290 m_first = false; 285 m_first = false;
291 286
292} 287}
293void TableView::clear() { 288void TableView::clear() {
294 setNumRows(0); 289 setNumRows(0);
295} 290}
296void TableView::slotClicked(int row, int col, int, 291void TableView::slotClicked(int row, int col, int,
297 const QPoint& point) { 292 const QPoint& point) {
298 if ( m_editorWidget.cellWidget() ) { 293 if ( m_editorWidget.cellWidget() ) {
299 //setCellContentFromEditor(m_editorWidget.cellRow(), m_editorWidget.cellCol() ); 294 //setCellContentFromEditor(m_editorWidget.cellRow(), m_editorWidget.cellCol() );
300 endEdit(m_editorWidget.cellRow(), m_editorWidget.cellCol(), 295 endEdit(m_editorWidget.cellRow(), m_editorWidget.cellCol(),
301 true, true ); 296 true, true );
302 m_editorWidget.releaseCellWidget(); 297 m_editorWidget.releaseCellWidget();
303 } 298 }
304 299
305 if ( !cellGeometry(row, col ).contains(point ) ) 300 if ( !cellGeometry(row, col ).contains(point ) )
306 return; 301 return;
307 302
308 int ui= sorted().uidAt( row ); 303 int ui= sorted().uidAt( row );
309 304
310 305
311 switch( col ) { 306 switch( col ) {
312 case 0:{ 307 case 0:{
313 int x = point.x() -columnPos( col ); 308 int x = point.x() -columnPos( col );
314 int y = point.y() -rowPos( row ); 309 int y = point.y() -rowPos( row );
315 int w = columnWidth( col ); 310 int w = columnWidth( col );
316 int h = rowHeight( row ); 311 int h = rowHeight( row );
317 if ( x >= ( w - BoxSize ) / 2 && 312 if ( x >= ( w - BoxSize ) / 2 &&
318 x <= ( w - BoxSize ) / 2 + BoxSize && 313 x <= ( w - BoxSize ) / 2 + BoxSize &&
319 y >= ( h - BoxSize ) / 2 && 314 y >= ( h - BoxSize ) / 2 &&
320 y <= ( h - BoxSize ) / 2 + BoxSize ) { 315 y <= ( h - BoxSize ) / 2 + BoxSize ) {
321 TodoView::complete(sorted()[row] ); 316 TodoView::complete(sorted()[row] );
322 } 317 }
323 } 318 }
324 break; 319 break;
325 320
326 // Priority emit a double click... 321 // Priority emit a double click...
327 case 1:{ 322 case 1:{
328 QWidget* wid = beginEdit( row, col, FALSE ); 323 QWidget* wid = beginEdit( row, col, FALSE );
329 m_editorWidget.setCellWidget( wid, row, col ); 324 m_editorWidget.setCellWidget( wid, row, col );
330 } 325 }
331 break; 326 break;
332 327
333 case 2: { 328 case 2: {
334 m_menuTimer->stop(); 329 m_menuTimer->stop();
335 showTodo( ui ); 330 showTodo( ui );
336 break; 331 break;
337 } 332 }
338 case 3: { 333 case 3: {
339 m_menuTimer->stop(); 334 m_menuTimer->stop();
340 TodoView::edit( ui ); 335 TodoView::edit( ui );
341 break; 336 break;
342 } 337 }
343 } 338 }
344 339
345 340
346} 341}
347void TableView::slotPressed(int row, int col, int, 342void TableView::slotPressed(int row, int col, int,
348 const QPoint& point) { 343 const QPoint& point) {
349 344
350 owarn << "pressed row " << row << " col " << col << " x:" << point.x()
351 << "+y:" << point.y() << oendl;
352 m_prevP = point; 345 m_prevP = point;
353 /* TextColumn column */ 346 /* TextColumn column */
354 if ( col == 2 && cellGeometry( row, col ).contains( point ) ) 347 if ( col == 2 && cellGeometry( row, col ).contains( point ) )
355 m_menuTimer->start( 750, TRUE ); 348 m_menuTimer->start( 750, TRUE );
356} 349}
357void TableView::slotValueChanged( int, int ) { 350void TableView::slotValueChanged( int, int ) {
358 owarn << "Value Changed" << oendl;
359} 351}
360void TableView::slotCurrentChanged(int, int ) { 352void TableView::slotCurrentChanged(int, int ) {
361 m_menuTimer->stop(); 353 m_menuTimer->stop();
362} 354}
363QWidget* TableView::widget() { 355QWidget* TableView::widget() {
364 return this; 356 return this;
365} 357}
366/* 358/*
367 * We need to overwrite sortColumn 359 * We need to overwrite sortColumn
368 * because we want to sort whole row 360 * because we want to sort whole row
369 * based 361 * based
370 * We event want to set the setOrder 362 * We event want to set the setOrder
371 * to a sort() and update() 363 * to a sort() and update()
372 */ 364 */
373void TableView::sortColumn( int col, bool asc, bool ) { 365void TableView::sortColumn( int col, bool asc, bool ) {
374 owarn << "bool " << asc << oendl; 366 switch(col) {
367 case 1:
368 col = Opie::OPimTodoAccess::Priority;
369 break;
370 case 2:
371 col = Opie::OPimTodoAccess::SortSummary;
372 break;
373 case 3:
374 col = Opie::OPimTodoAccess::Deadline;
375 break;
376 case 0:
377 default:
378 col = Opie::OPimTodoAccess::Completed;
379 break;
380 }
381
375 setSortOrder( col ); 382 setSortOrder( col );
376 setAscending( asc ); 383 setAscending( asc );
377 updateView(); 384 updateView();
378} 385}
379void TableView::viewportPaintEvent( QPaintEvent* e) { 386void TableView::viewportPaintEvent( QPaintEvent* e) {
380 if (m_enablePaint ) 387 if (m_enablePaint )
381 QTable::viewportPaintEvent( e ); 388 QTable::viewportPaintEvent( e );
382} 389}
383/* 390/*
384 * This segment is copyrighted by TT 391 * This segment is copyrighted by TT
385 * it was taken from their todolist 392 * it was taken from their todolist
386 * application this code is GPL 393 * application this code is GPL
387 */ 394 */
388void TableView::paintCell(QPainter* p, int row, int col, const QRect& cr, bool ) { 395void TableView::paintCell(QPainter* p, int row, int col, const QRect& cr, bool ) {
389 const QColorGroup &cg = colorGroup(); 396 const QColorGroup &cg = colorGroup();
390 397
391 p->save(); 398 p->save();
392 399
393 OPimTodo task = sorted()[row]; 400 OPimTodo task = sorted()[row];
394 401
395 // TODO - give user option for grid or bars? 402 // TODO - give user option for grid or bars?
396 403
397 // Paint alternating background bars 404 // Paint alternating background bars
398 if ( (row % 2 ) == 0 ) { 405 if ( (row % 2 ) == 0 ) {
399 p->fillRect( 0, 0, cr.width(), cr.height(), cg.brush( QColorGroup::Base ) ); 406 p->fillRect( 0, 0, cr.width(), cr.height(), cg.brush( QColorGroup::Base ) );
400 p->setPen( QPen( cg.text() ) ); 407 p->setPen( QPen( cg.text() ) );
401 } 408 }
402 else { 409 else {
403 p->fillRect( 0, 0, cr.width(), cr.height(), cg.brush( QColorGroup::Background ) ); 410 p->fillRect( 0, 0, cr.width(), cr.height(), cg.brush( QColorGroup::Background ) );
404 p->setPen( QPen( cg.buttonText() ) ); 411 p->setPen( QPen( cg.buttonText() ) );
405 } 412 }
406 413
407 // Paint grid 414 // Paint grid
408 //p->fillRect( 0, 0, cr.width(), cr.height(), cg.brush( QColorGroup::Base ) ); 415 //p->fillRect( 0, 0, cr.width(), cr.height(), cg.brush( QColorGroup::Base ) );
409 //QPen op = p->pen(); 416 //QPen op = p->pen();
410 //p->setPen(cg.mid()); 417 //p->setPen(cg.mid());
411 //p->drawLine( 0, cr.height() - 1, cr.width() - 1, cr.height() - 1 ); 418 //p->drawLine( 0, cr.height() - 1, cr.width() - 1, cr.height() - 1 );
412 //p->drawLine( cr.width() - 1, 0, cr.width() - 1, cr.height() - 1 ); 419 //p->drawLine( cr.width() - 1, 0, cr.width() - 1, cr.height() - 1 );
413 //p->setPen(op); 420 //p->setPen(op);
414 421
415 QFont f = p->font(); 422 QFont f = p->font();
416 QFontMetrics fm(f); 423 QFontMetrics fm(f);
417 424
418 int marg = ( cr.width() - BoxSize ) / 2; 425 int marg = ( cr.width() - BoxSize ) / 2;
419 int x = 0; 426 int x = 0;
420 int y = ( cr.height() - BoxSize ) / 2; 427 int y = ( cr.height() - BoxSize ) / 2;
421 428
422 switch(col) { 429 switch(col) {
423 case 0: // completed field 430 case 0: // completed field
424 { 431 {
425 //p->setPen( QPen( cg.text() ) ); 432 //p->setPen( QPen( cg.text() ) );
426 //p->drawRect( x + marg, y, BoxSize, BoxSize ); 433 //p->drawRect( x + marg, y, BoxSize, BoxSize );
427 //p->drawRect( x + marg+1, y+1, BoxSize-2, BoxSize-2 ); 434 //p->drawRect( x + marg+1, y+1, BoxSize-2, BoxSize-2 );
428 if ( task.isCompleted() ) { 435 if ( task.isCompleted() ) {
429 p->drawPixmap( x + marg, y, m_pic_completed ); 436 p->drawPixmap( x + marg, y, m_pic_completed );
430 } 437 }
431 } 438 }
432 break; 439 break;
433 case 1: // priority field 440 case 1: // priority field
434 { 441 {
435 p->drawPixmap( x + marg, y, m_pic_priority[ task.priority() - 1 ] ); 442 p->drawPixmap( x + marg, y, m_pic_priority[ task.priority() - 1 ] );
436 } 443 }
437 break; 444 break;
438 case 2: // description field 445 case 2: // description field
439 { 446 {
440 QString text = task.summary().isEmpty() ? 447 QString text = task.summary().isEmpty() ?
441 task.description().left(20) : 448 task.description().left(20) :
442 task.summary(); 449 task.summary();
443 p->drawText(2,2 + fm.ascent(), text); 450 p->drawText(2,2 + fm.ascent(), text);
444 } 451 }
445 break; 452 break;
446 case 3: 453 case 3:
447 { 454 {
448 QString text; 455 QString text;
449 if (task.hasDueDate()) { 456 if (task.hasDueDate()) {
450 int off = QDate::currentDate().daysTo( task.dueDate() ); 457 int off = QDate::currentDate().daysTo( task.dueDate() );
451 text = tr( "%1 day(s)").arg(QString::number(off)); 458 text = tr( "%1 day(s)").arg(QString::number(off));
452 /* 459 /*
453 * set color if not completed 460 * set color if not completed
454 */ 461 */
455 if (!task.isCompleted() ) { 462 if (!task.isCompleted() ) {
456 QColor color = Qt::black; 463 QColor color = Qt::black;
457 if ( off < 0 ) 464 if ( off < 0 )
458 color = Qt::red; 465 color = Qt::red;
459 else if ( off == 0 ) 466 else if ( off == 0 )
460 color = Qt::yellow; 467 color = Qt::yellow;
461 else if ( off > 0 ) 468 else if ( off > 0 )
462 color = Qt::green; 469 color = Qt::green;
463 p->setPen(color ); 470 p->setPen(color );
464 } 471 }
465 } else { 472 } else {
466 text = tr("None"); 473 text = tr("None");
467 } 474 }
468 p->drawText(2,2 + fm.ascent(), text); 475 p->drawText(2,2 + fm.ascent(), text);
469 } 476 }
470 break; 477 break;
471 } 478 }
472 p->restore(); 479 p->restore();
473} 480}
474QWidget* TableView::createEditor(int row, int col, bool )const { 481QWidget* TableView::createEditor(int row, int col, bool )const {
475 switch( col ) { 482 switch( col ) {
476 case 1: { 483 case 1: {
477 /* the priority stuff */ 484 /* the priority stuff */
478 QComboBox* combo = new QComboBox( viewport() ); 485 QComboBox* combo = new QComboBox( viewport() );
479 for ( int i = 0; i < 5; i++ ) { 486 for ( int i = 0; i < 5; i++ ) {
480 combo->insertItem( m_pic_priority[ i ] ); 487 combo->insertItem( m_pic_priority[ i ] );
481 } 488 }
482 combo->setCurrentItem( sorted()[row].priority()-1 ); 489 combo->setCurrentItem( sorted()[row].priority()-1 );
483 return combo; 490 return combo;
484 } 491 }
485 /* summary */ 492 /* summary */
486 case 2:{ 493 case 2:{
487 QLineEdit* edit = new QLineEdit( viewport() ); 494 QLineEdit* edit = new QLineEdit( viewport() );
488 edit->setText( sorted()[row].summary() ); 495 edit->setText( sorted()[row].summary() );
489 return edit; 496 return edit;
490 } 497 }
491 case 0: 498 case 0:
492 default: 499 default:
493 return 0l; 500 return 0l;
494 } 501 }
495} 502}
496void TableView::setCellContentFromEditor(int row, int col ) { 503void TableView::setCellContentFromEditor(int row, int col ) {
497 owarn << "set cell content from editor" << oendl;
498 if ( col == 1 ) { 504 if ( col == 1 ) {
499 QWidget* wid = cellWidget(row, 1 ); 505 QWidget* wid = cellWidget(row, 1 );
500 if ( wid->inherits("QComboBox") ) { 506 if ( wid->inherits("QComboBox") ) {
501 int pri = ((QComboBox*)wid)->currentItem() + 1; 507 int pri = ((QComboBox*)wid)->currentItem() + 1;
502 OPimTodo todo = sorted()[row]; 508 OPimTodo todo = sorted()[row];
503 if ( todo.priority() != pri ) { 509 if ( todo.priority() != pri ) {
504 todo.setPriority( pri ); 510 todo.setPriority( pri );
505 TodoView::update( todo.uid(), todo ); 511 TodoView::update( todo.uid(), todo );
506 updateView(); 512 updateView();
507 } 513 }
508 } 514 }
509 }else if ( col == 2) { 515 }else if ( col == 2) {
510 QWidget* wid = cellWidget(row, 2); 516 QWidget* wid = cellWidget(row, 2);
511 if ( wid->inherits("QLineEdit") ) { 517 if ( wid->inherits("QLineEdit") ) {
512 QString text = ((QLineEdit*)wid)->text(); 518 QString text = ((QLineEdit*)wid)->text();
513 OPimTodo todo = sorted()[row]; 519 OPimTodo todo = sorted()[row];
514 if ( todo.summary() != text ) { 520 if ( todo.summary() != text ) {
515 todo.setSummary( text ); 521 todo.setSummary( text );
516 TodoView::update( todo.uid(), todo ); 522 TodoView::update( todo.uid(), todo );
517 updateView(); 523 updateView();
518 } 524 }
519 } 525 }
520 } 526 }
521} 527}
522void TableView::slotPriority() { 528void TableView::slotPriority() {
523 setCellContentFromEditor( currentRow(), currentColumn() ); 529 setCellContentFromEditor( currentRow(), currentColumn() );
524} 530}
525/* 531/*
526 * We'll use the TimerEvent to read ahead or to keep the cahce always 532 * We'll use the TimerEvent to read ahead or to keep the cahce always
527 * filled enough. 533 * filled enough.
528 * We will try to read ahead 4 items in both ways 534 * We will try to read ahead 4 items in both ways
529 * up and down. On odd or even we will currentRow()+-4 or +-9 535 * up and down. On odd or even we will currentRow()+-4 or +-9
530 * 536 *
531 */ 537 */
532void TableView::timerEvent( QTimerEvent* ) { 538void TableView::timerEvent( QTimerEvent* ) {
533// Opie::Core::owarn << "sorted " << sorted().count() << oendl;
534 if (sorted().count() == 0 ) 539 if (sorted().count() == 0 )
535 return; 540 return;
536 541
537 int row = currentRow(); 542 int row = currentRow();
538 if ( m_row ) { 543 if ( m_row ) {
539 int ro = row-4; 544 int ro = row-4;
540 if (ro < 0 ) ro = 0; 545 if (ro < 0 ) ro = 0;
541 sorted()[ro]; 546 sorted()[ro];
542 547
543 ro = row+4; 548 ro = row+4;
544 sorted()[ro]; 549 sorted()[ro];
545 } else { 550 } else {
546 int ro = row + 8; 551 int ro = row + 8;
547 sorted()[ro]; 552 sorted()[ro];
548 553
549 ro = row-8; 554 ro = row-8;
550 if (ro < 0 ) ro = 0; 555 if (ro < 0 ) ro = 0;
551 sorted()[ro]; 556 sorted()[ro];
552 } 557 }
553 558
554 m_row = !m_row; 559 m_row = !m_row;
555} 560}
556 561
557// We want a strike through completed ;) 562// We want a strike through completed ;)
558// durchstreichen to complete 563// durchstreichen to complete
559/* 564/*
560 * MouseTracking is off this mean we only receive 565 * MouseTracking is off this mean we only receive
561 * these events if the mouse button is pressed 566 * these events if the mouse button is pressed
562 * We've the previous point saved 567 * We've the previous point saved
563 * We check if the previous and current Point are 568 * We check if the previous and current Point are
564 * in the same row. 569 * in the same row.
565 * Then we check if they're some pixel horizontal away 570 * Then we check if they're some pixel horizontal away
566 * if the distance between the two points is greater than 571 * if the distance between the two points is greater than
567 * 8 we mark the underlying todo as completed and do a repaint 572 * 8 we mark the underlying todo as completed and do a repaint
568 * 573 *
569 * BUG: When clicking on the Due column and it's scrollable 574 * BUG: When clicking on the Due column and it's scrollable
570 * the todo is marked as completed... 575 * the todo is marked as completed...
571 * REASON: QTable is doing auto scrolling which leads to a move 576 * REASON: QTable is doing auto scrolling which leads to a move
572 * in the x coordinate and this way it's able to pass the 577 * in the x coordinate and this way it's able to pass the
573 * m_completeStrokeWidth criteria 578 * m_completeStrokeWidth criteria
574 * WORKAROUND: strike through needs to strike through the same 579 * WORKAROUND: strike through needs to strike through the same
575 * row and two columns! 580 * row and two columns!
576 */ 581 */
577void TableView::contentsMouseReleaseEvent( QMouseEvent* e) { 582void TableView::contentsMouseReleaseEvent( QMouseEvent* e) {
578 int row = rowAt(m_prevP.y()); 583 int row = rowAt(m_prevP.y());
579 int colOld = columnAt(m_prevP.x() ); 584 int colOld = columnAt(m_prevP.x() );
580 int colNew = columnAt(e->x() ); 585 int colNew = columnAt(e->x() );
581 owarn << "colNew: " << colNew << " colOld: " << colOld << oendl;
582 if ( row == rowAt( e->y() ) && row != -1 && 586 if ( row == rowAt( e->y() ) && row != -1 &&
583 colOld != colNew ) { 587 colOld != colNew ) {
584 TodoView::complete( sorted()[row] ); 588 TodoView::complete( sorted()[row] );
585 return; 589 return;
586 } 590 }
587 QTable::contentsMouseReleaseEvent( e ); 591 QTable::contentsMouseReleaseEvent( e );
588} 592}
589void TableView::contentsMouseMoveEvent( QMouseEvent* e ) { 593void TableView::contentsMouseMoveEvent( QMouseEvent* e ) {
590 m_menuTimer->stop(); 594 m_menuTimer->stop();
591 QTable::contentsMouseMoveEvent( e ); 595 QTable::contentsMouseMoveEvent( e );
592} 596}
593void TableView::keyPressEvent( QKeyEvent* event) { 597void TableView::keyPressEvent( QKeyEvent* event) {
594 if ( m_editorWidget.cellWidget() ) { 598 if ( m_editorWidget.cellWidget() ) {
595// setCellContentFromEditor(m_editorWidget.cellRow(), m_editorWidget.cellCol() ); 599// setCellContentFromEditor(m_editorWidget.cellRow(), m_editorWidget.cellCol() );
596 endEdit(m_editorWidget.cellRow(), m_editorWidget.cellCol(), 600 endEdit(m_editorWidget.cellRow(), m_editorWidget.cellCol(),
597 true, true ); 601 true, true );
598 m_editorWidget.releaseCellWidget(); 602 m_editorWidget.releaseCellWidget();
599 setFocus(); 603 setFocus();
600 } 604 }
601 605
602 if ( sorted().count() < 1 ) { 606 if ( sorted().count() < 1 ) {
603 QTable::keyPressEvent( event ); 607 QTable::keyPressEvent( event );
604 return; 608 return;
605 } 609 }
606 610
607 int row = currentRow(); 611 int row = currentRow();
608 int col = currentColumn(); 612 int col = currentColumn();
609 613
610 char key = ::toupper( event->ascii() ); 614 char key = ::toupper( event->ascii() );
611 /* let QTable also handle the d letter */ 615 /* let QTable also handle the d letter */
612 if ( key == 'D' ) { 616 if ( key == 'D' ) {
613 event->accept(); 617 event->accept();
614 removeQuery( sorted().uidAt( row ) ); 618 removeQuery( sorted().uidAt( row ) );
615 return; 619 return;
616 } 620 }
617 621
618 622
619 switch( event->key() ) { 623 switch( event->key() ) {
620 case Qt::Key_F33: 624 case Qt::Key_F33:
621 case Qt::Key_Enter: 625 case Qt::Key_Enter:
622 case Qt::Key_Return: 626 case Qt::Key_Return:
623 case Qt::Key_Space: 627 case Qt::Key_Space:
624 if ( col == 0 ) { 628 if ( col == 0 ) {
625 TodoView::complete(sorted()[row]); 629 TodoView::complete(sorted()[row]);
626 }else if ( col == 1 ) { 630 }else if ( col == 1 ) {
627 QWidget* wid = beginEdit(row, col, FALSE ); 631 QWidget* wid = beginEdit(row, col, FALSE );
628 m_editorWidget.setCellWidget( wid, row, col ); 632 m_editorWidget.setCellWidget( wid, row, col );
629 }else if ( col == 2 ) { 633 }else if ( col == 2 ) {
630 showTodo( sorted().uidAt( currentRow() ) ); 634 showTodo( sorted().uidAt( currentRow() ) );
631 }else if ( col == 3 ) { 635 }else if ( col == 3 ) {
632 TodoView::edit( sorted().uidAt(row) ); 636 TodoView::edit( sorted().uidAt(row) );
633 } 637 }
634 event->accept(); 638 event->accept();
635 break; 639 break;
636 default: 640 default:
637 QTable::keyPressEvent( event ); 641 QTable::keyPressEvent( event );
638 } 642 }
639} 643}
640 644
diff --git a/core/pim/todo/todomanager.cpp b/core/pim/todo/todomanager.cpp
index c4b8fbc..7136f9a 100644
--- a/core/pim/todo/todomanager.cpp
+++ b/core/pim/todo/todomanager.cpp
@@ -1,130 +1,125 @@
1/* 1/*
2               =. This file is part of the OPIE Project 2               =. This file is part of the OPIE Project
3             .=l. Copyright (c) 2002 <> 3             .=l. Copyright (c) 2002 <>
4           .>+-= 4           .>+-=
5 _;:,     .>    :=|. This program is free software; you can 5 _;:,     .>    :=|. This program is free software; you can
6.> <`_,   >  .   <= redistribute it and/or modify it under 6.> <`_,   >  .   <= redistribute it and/or modify it under
7:`=1 )Y*s>-.--   : the terms of the GNU General Public 7:`=1 )Y*s>-.--   : the terms of the GNU General Public
8.="- .-=="i,     .._ License as published by the Free Software 8.="- .-=="i,     .._ License as published by the Free Software
9 - .   .-<_>     .<> Foundation; either version 2 of the License, 9 - .   .-<_>     .<> Foundation; either version 2 of the License,
10     ._= =}       : or (at your option) any later version. 10     ._= =}       : or (at your option) any later version.
11    .%`+i>       _;_. 11    .%`+i>       _;_.
12    .i_,=:_.      -<s. This program is distributed in the hope that 12    .i_,=:_.      -<s. This program is distributed in the hope that
13     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY; 13     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
14    : ..    .:,     . . . without even the implied warranty of 14    : ..    .:,     . . . without even the implied warranty of
15    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A 15    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
16  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU 16  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU
17..}^=.=       =       ; Library General Public License for more 17..}^=.=       =       ; Library General Public License for more
18++=   -.     .`     .: details. 18++=   -.     .`     .: details.
19 :     =  ...= . :.=- 19 :     =  ...= . :.=-
20 -.   .:....=;==+<; You should have received a copy of the GNU 20 -.   .:....=;==+<; You should have received a copy of the GNU
21  -_. . .   )=.  = Library General Public License along with 21  -_. . .   )=.  = Library General Public License along with
22    --        :-=` this library; see the file COPYING.LIB. 22    --        :-=` this library; see the file COPYING.LIB.
23 If not, write to the Free Software Foundation, 23 If not, write to the Free Software Foundation,
24 Inc., 59 Temple Place - Suite 330, 24 Inc., 59 Temple Place - Suite 330,
25 Boston, MA 02111-1307, USA. 25 Boston, MA 02111-1307, USA.
26 26
27*/ 27*/
28 28
29#include <opie2/odebug.h> 29#include <opie2/odebug.h>
30 30
31#include <qpe/categoryselect.h> 31#include <qpe/categoryselect.h>
32 32
33#include "todomanager.h" 33#include "todomanager.h"
34 34
35using namespace Todo; 35using namespace Todo;
36 36
37TodoManager::TodoManager( QObject *obj ) 37TodoManager::TodoManager( QObject *obj )
38 : QObject( obj ) { 38 : QObject( obj ) {
39 m_db = 0l; 39 m_db = 0l;
40 QTime time;
41 time.start();
42 int el = time.elapsed();
43 owarn << "QTimer for loading " << el/1000 << oendl;
44} 40}
45TodoManager::~TodoManager() { 41TodoManager::~TodoManager() {
46 delete m_db; 42 delete m_db;
47} 43}
48OPimTodo TodoManager::event(int uid ) { 44OPimTodo TodoManager::event(int uid ) {
49 return m_db->find( uid ); 45 return m_db->find( uid );
50} 46}
51void TodoManager::updateList() { 47void TodoManager::updateList() {
52 owarn << "update lists" << oendl;
53 m_list = m_db->allRecords(); 48 m_list = m_db->allRecords();
54} 49}
55OPimTodoAccess::List TodoManager::list() const{ 50OPimTodoAccess::List TodoManager::list() const{
56 return m_list; 51 return m_list;
57} 52}
58OPimTodoAccess::List TodoManager::sorted( bool asc, int so, int f, int cat ) { 53OPimTodoAccess::List TodoManager::sorted( bool asc, int so, int f, int cat ) {
59 return m_db->sorted( asc, so, f, cat ); 54 return m_db->sorted( asc, so, f, cat );
60} 55}
61OPimTodoAccess::List::Iterator TodoManager::overDue() { 56OPimTodoAccess::List::Iterator TodoManager::overDue() {
62 int filter = 2 | 1; 57 int filter = Opie::OPimTodoAccess::FilterCategory | Opie::OPimTodoAccess::OnlyOverDue;
63 m_list = m_db->sorted(m_asc, m_sortOrder, filter, m_ca ); 58 m_list = m_db->sorted(m_asc, m_sortOrder, filter, m_ca );
64 m_it = m_list.begin(); 59 m_it = m_list.begin();
65 return m_it; 60 return m_it;
66} 61}
67OPimTodoAccess::List::Iterator TodoManager::fromTo( const QDate& start, 62OPimTodoAccess::List::Iterator TodoManager::fromTo( const QDate& start,
68 const QDate& end ) { 63 const QDate& end ) {
69 m_list = m_db->effectiveToDos( start, end ); 64 m_list = m_db->effectiveToDos( start, end );
70 m_it = m_list.begin(); 65 m_it = m_list.begin();
71 return m_it; 66 return m_it;
72} 67}
73OPimTodoAccess::List::Iterator TodoManager::query( const OPimTodo& ev, int query ) { 68OPimTodoAccess::List::Iterator TodoManager::query( const OPimTodo& ev, int query ) {
74 m_list = m_db->queryByExample( ev, query ); 69 m_list = m_db->queryByExample( ev, query );
75 m_it = m_list.begin(); 70 m_it = m_list.begin();
76 return m_it; 71 return m_it;
77} 72}
78OPimTodoAccess* TodoManager::todoDB() { 73OPimTodoAccess* TodoManager::todoDB() {
79 return m_db; 74 return m_db;
80} 75}
81void TodoManager::add( const OPimTodo& ev ) { 76void TodoManager::add( const OPimTodo& ev ) {
82 m_db->add( ev ); 77 m_db->add( ev );
83} 78}
84void TodoManager::update( int, const SmallTodo& ) { 79void TodoManager::update( int, const SmallTodo& ) {
85 80
86} 81}
87void TodoManager::update( int, const OPimTodo& ev) { 82void TodoManager::update( int, const OPimTodo& ev) {
88 m_db->replace( ev ); 83 m_db->replace( ev );
89} 84}
90bool TodoManager::remove( int uid ) { 85bool TodoManager::remove( int uid ) {
91 return m_db->remove( uid ); 86 return m_db->remove( uid );
92} 87}
93void TodoManager::removeAll() { 88void TodoManager::removeAll() {
94 m_db->clear(); 89 m_db->clear();
95} 90}
96void TodoManager::removeCompleted() { 91void TodoManager::removeCompleted() {
97 m_db->removeAllCompleted(); 92 m_db->removeAllCompleted();
98} 93}
99void TodoManager::save() { 94void TodoManager::save() {
100 m_db->save(); 95 m_db->save();
101} 96}
102bool TodoManager::saveAll() { 97bool TodoManager::saveAll() {
103 return m_db->save(); 98 return m_db->save();
104} 99}
105void TodoManager::reload() { 100void TodoManager::reload() {
106 m_db->reload(); 101 m_db->reload();
107} 102}
108QStringList TodoManager::categories() { 103QStringList TodoManager::categories() {
109 m_cat.load(categoryFileName() ); 104 m_cat.load(categoryFileName() );
110 return m_cat.labels( "Todo List"); 105 return m_cat.labels( "Todo List");
111} 106}
112/* 107/*
113 * we rely on load beeing called from populateCategories 108 * we rely on load beeing called from populateCategories
114 */ 109 */
115int TodoManager::catId( const QString& cats ) { 110int TodoManager::catId( const QString& cats ) {
116 return m_cat.id( "Todo List", cats ); 111 return m_cat.id( "Todo List", cats );
117} 112}
118void TodoManager::remove( const QArray<int>& ids) { 113void TodoManager::remove( const QArray<int>& ids) {
119 for (uint i=0; i < ids.size(); i++ ) 114 for (uint i=0; i < ids.size(); i++ )
120 remove( ids[i] ); 115 remove( ids[i] );
121} 116}
122bool TodoManager::isLoaded()const { 117bool TodoManager::isLoaded()const {
123 return (m_db == 0 ); 118 return (m_db == 0 );
124} 119}
125void TodoManager::load() { 120void TodoManager::load() {
126 if (!m_db) { 121 if (!m_db) {
127 m_db = new OPimTodoAccess(); 122 m_db = new OPimTodoAccess();
128 m_db->load(); 123 m_db->load();
129 } 124 }
130} 125}