summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--core/pim/todo/mainwindow.cpp3
-rw-r--r--core/pim/todo/tableitems.cpp4
-rw-r--r--core/pim/todo/tableview.cpp233
-rw-r--r--core/pim/todo/tableview.h44
-rw-r--r--core/pim/todo/todoview.h2
5 files changed, 126 insertions, 160 deletions
diff --git a/core/pim/todo/mainwindow.cpp b/core/pim/todo/mainwindow.cpp
index 47c0160..7e7d2f7 100644
--- a/core/pim/todo/mainwindow.cpp
+++ b/core/pim/todo/mainwindow.cpp
@@ -1,637 +1,638 @@
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 <qmenubar.h> 29#include <qmenubar.h>
30#include <qmessagebox.h> 30#include <qmessagebox.h>
31#include <qtoolbar.h> 31#include <qtoolbar.h>
32#include <qpopupmenu.h> 32#include <qpopupmenu.h>
33#include <qwidgetstack.h> 33#include <qwidgetstack.h>
34#include <qaction.h> 34#include <qaction.h>
35#include <qtimer.h> 35#include <qtimer.h>
36 36
37#include <qpe/config.h> 37#include <qpe/config.h>
38#include <qpe/ir.h> 38#include <qpe/ir.h>
39#include <qpe/resource.h> 39#include <qpe/resource.h>
40#include <qpe/qpemessagebox.h> 40#include <qpe/qpemessagebox.h>
41 41
42 42
43#include "todotemplatemanager.h" 43#include "todotemplatemanager.h"
44#include "templateeditor.h" 44#include "templateeditor.h"
45#include "todoentryimpl.h" 45#include "todoentryimpl.h"
46#include "tableview.h" 46#include "tableview.h"
47 47
48#include "textviewshow.h" 48#include "textviewshow.h"
49#include "todoeditor.h" 49#include "todoeditor.h"
50#include "mainwindow.h" 50#include "mainwindow.h"
51 51
52 52
53using namespace Todo; 53using namespace Todo;
54 54
55MainWindow::MainWindow( QWidget* parent, 55MainWindow::MainWindow( QWidget* parent,
56 const char* name ) { 56 const char* name ) {
57 57
58 m_syncing = false; 58 m_syncing = false;
59 m_counter = 0; 59 m_counter = 0;
60 m_tempManager = new TemplateManager(); 60 m_tempManager = new TemplateManager();
61 m_tempManager->load(); 61 m_tempManager->load();
62 62
63 initUI(); 63 initUI();
64 initConfig(); 64 initConfig();
65 initViews(); 65 initViews();
66 initActions(); 66 initActions();
67 initEditor(); 67 initEditor();
68 initShow(); 68 initShow();
69 initTemplate(); 69 initTemplate();
70 70
71 populateTemplates(); 71 populateTemplates();
72 raiseCurrentView(); 72 raiseCurrentView();
73 QTimer::singleShot(0, this, SLOT(populateCategories() ) ); 73 QTimer::singleShot(0, this, SLOT(populateCategories() ) );
74} 74}
75void MainWindow::initTemplate() { 75void MainWindow::initTemplate() {
76 m_curTempEd = new TemplateEditor( this, templateManager() ); 76 m_curTempEd = new TemplateEditor( this, templateManager() );
77} 77}
78void MainWindow::initActions() { 78void MainWindow::initActions() {
79 QAction* a = new QAction( tr("New Task" ), Resource::loadPixmap( "new" ), 79 QAction* a = new QAction( tr("New Task" ), Resource::loadPixmap( "new" ),
80 QString::null, 0, this, 0 ); 80 QString::null, 0, this, 0 );
81 connect(a, SIGNAL( activated() ), 81 connect(a, SIGNAL( activated() ),
82 this, SLOT( slotNew() ) ); 82 this, SLOT( slotNew() ) );
83 a->addTo(m_tool ); 83 a->addTo(m_tool );
84 a->addTo(m_edit ); 84 a->addTo(m_edit );
85 85
86 a = new QAction( tr("Edit Task"), Resource::loadIconSet( "edit" ), 86 a = new QAction( tr("Edit Task"), Resource::loadIconSet( "edit" ),
87 QString::null, 0, this, 0 ); 87 QString::null, 0, this, 0 );
88 connect(a, SIGNAL(activated() ), 88 connect(a, SIGNAL(activated() ),
89 this, SLOT( slotEdit() ) ); 89 this, SLOT( slotEdit() ) );
90 a->addTo( m_tool ); 90 a->addTo( m_tool );
91 a->addTo( m_edit ); 91 a->addTo( m_edit );
92 m_editAction = a; 92 m_editAction = a;
93 93
94 a = new QAction( QString::null, tr("View Task"), 0, this, 0 ); 94 a = new QAction( QString::null, tr("View Task"), 0, this, 0 );
95 connect(a, SIGNAL( activated() ), 95 connect(a, SIGNAL( activated() ),
96 this, SLOT( slotShowDetails() ) ); 96 this, SLOT( slotShowDetails() ) );
97 a->addTo( m_edit ); 97 a->addTo( m_edit );
98 98
99 m_edit->insertSeparator(); 99 m_edit->insertSeparator();
100 100
101 a = new QAction( tr("Delete..."), Resource::loadIconSet( "trash" ), 101 a = new QAction( tr("Delete..."), Resource::loadIconSet( "trash" ),
102 QString::null, 0, this, 0 ); 102 QString::null, 0, this, 0 );
103 connect(a, SIGNAL(activated() ), 103 connect(a, SIGNAL(activated() ),
104 this, SLOT(slotDelete() ) ); 104 this, SLOT(slotDelete() ) );
105 a->addTo( m_tool ); 105 a->addTo( m_tool );
106 a->addTo( m_edit ); 106 a->addTo( m_edit );
107 m_deleteAction = a; 107 m_deleteAction = a;
108 108
109 a = new QAction( QString::null, tr("Delete all..."), 0, this, 0 ); 109 a = new QAction( QString::null, tr("Delete all..."), 0, this, 0 );
110 connect(a, SIGNAL( activated() ), 110 connect(a, SIGNAL( activated() ),
111 this, SLOT( slotDeleteAll() ) ); 111 this, SLOT( slotDeleteAll() ) );
112 a->addTo(m_edit ); 112 a->addTo(m_edit );
113 m_deleteAllAction = a; 113 m_deleteAllAction = a;
114 114
115 a = new QAction( QString::null, tr("Delete completed"), 115 a = new QAction( QString::null, tr("Delete completed"),
116 0, this, 0 ); 116 0, this, 0 );
117 connect(a, SIGNAL( activated() ), 117 connect(a, SIGNAL( activated() ),
118 this, SLOT( slotDeleteCompleted() ) ); 118 this, SLOT( slotDeleteCompleted() ) );
119 a->addTo(m_edit ); 119 a->addTo(m_edit );
120 a->setEnabled( TRUE ); 120 a->setEnabled( TRUE );
121 m_deleteCompleteAction = a; 121 m_deleteCompleteAction = a;
122 122
123 m_edit->insertSeparator(); 123 m_edit->insertSeparator();
124 124
125 a = new QAction( QString::null, tr("Duplicate"), 0, this, 0 ); 125 a = new QAction( QString::null, tr("Duplicate"), 0, this, 0 );
126 connect(a, SIGNAL( activated() ), 126 connect(a, SIGNAL( activated() ),
127 this, SLOT( slotDuplicate() ) ); 127 this, SLOT( slotDuplicate() ) );
128 a->addTo(m_edit ); 128 a->addTo(m_edit );
129 m_duplicateAction = a; 129 m_duplicateAction = a;
130 130
131 m_edit->insertSeparator(); 131 m_edit->insertSeparator();
132 132
133 if ( Ir::supported() ) { 133 if ( Ir::supported() ) {
134 a = new QAction( tr( "Beam" ), Resource::loadPixmap( "beam" ), 134 a = new QAction( tr( "Beam" ), Resource::loadPixmap( "beam" ),
135 QString::null, 0, this, 0 ); 135 QString::null, 0, this, 0 );
136 connect( a, SIGNAL( activated() ), 136 connect( a, SIGNAL( activated() ),
137 this, SLOT( slotBeam() ) ); 137 this, SLOT( slotBeam() ) );
138 a->addTo( m_edit ); 138 a->addTo( m_edit );
139 a->addTo( m_tool ); 139 a->addTo( m_tool );
140 } 140 }
141 141
142 a = new QAction( tr("Find"), Resource::loadIconSet( "mag" ), 142 a = new QAction( tr("Find"), Resource::loadIconSet( "mag" ),
143 QString::null, 0, this, 0 ); 143 QString::null, 0, this, 0 );
144 connect(a, SIGNAL( activated() ), 144 connect(a, SIGNAL( activated() ),
145 this, SLOT( slotFind() ) ); 145 this, SLOT( slotFind() ) );
146 a->addTo( m_options ); 146 a->addTo( m_options );
147 m_findAction = a; 147 m_findAction = a;
148 148
149 m_options->insertSeparator(); 149 m_options->insertSeparator();
150 150
151 m_completedAction = new QAction( QString::null, tr("Completed tasks"), 151 m_completedAction = new QAction( QString::null, tr("Completed tasks"),
152 0, this, 0, TRUE ); 152 0, this, 0, TRUE );
153 m_completedAction->addTo( m_options ); 153 m_completedAction->addTo( m_options );
154 m_completedAction->setOn( showCompleted() ); 154 m_completedAction->setOn( showCompleted() );
155 connect(m_completedAction, SIGNAL( toggled(bool) ), 155 connect(m_completedAction, SIGNAL( toggled(bool) ),
156 this, SLOT(slotShowCompleted(bool) ) ); 156 this, SLOT(slotShowCompleted(bool) ) );
157 157
158 m_showDeadLineAction = new QAction( QString::null, tr("Show Deadline"), 158 m_showDeadLineAction = new QAction( QString::null, tr("Show Deadline"),
159 0, this, 0, TRUE ); 159 0, this, 0, TRUE );
160 m_showDeadLineAction->addTo( m_options ); 160 m_showDeadLineAction->addTo( m_options );
161 m_showDeadLineAction->setOn( showDeadline() ); 161 m_showDeadLineAction->setOn( showDeadline() );
162 connect(m_showDeadLineAction, SIGNAL(toggled(bool) ), 162 connect(m_showDeadLineAction, SIGNAL(toggled(bool) ),
163 this, SLOT( slotShowDeadLine( bool ) ) ); 163 this, SLOT( slotShowDeadLine( bool ) ) );
164 164
165 m_options->insertSeparator(); 165 m_options->insertSeparator();
166 166
167 m_bar->insertItem( tr("Data") ,m_edit ); 167 m_bar->insertItem( tr("Data") ,m_edit );
168 m_bar->insertItem( tr("Category"), m_catMenu ); 168 m_bar->insertItem( tr("Category"), m_catMenu );
169 m_bar->insertItem( tr("Options"), m_options ); 169 m_bar->insertItem( tr("Options"), m_options );
170 170
171 /* initialize the view menu */ 171 /* initialize the view menu */
172 a = new QAction( QString::null, tr("Show over due"), 172 a = new QAction( QString::null, tr("Show over due"),
173 0, this, 0, TRUE ); 173 0, this, 0, TRUE );
174 a->addTo( m_view ); 174 a->addTo( m_view );
175 a->setOn( showOverDue() ); 175 a->setOn( showOverDue() );
176 connect(a, SIGNAL(toggled(bool)), 176 connect(a, SIGNAL(toggled(bool)),
177 this, SLOT(slotShowDue(bool) ) ); 177 this, SLOT(slotShowDue(bool) ) );
178 m_view->insertSeparator(); 178 m_view->insertSeparator();
179 179
180 m_bar->insertItem( tr("View"), m_view ); 180 m_bar->insertItem( tr("View"), m_view );
181 181
182 /* templates */ 182 /* templates */
183 m_edit->insertItem(tr("New from template"), m_template, 183 m_edit->insertItem(tr("New from template"), m_template,
184 -1, 0 ); 184 -1, 0 );
185 185
186} 186}
187/* m_curCat from Config */ 187/* m_curCat from Config */
188void MainWindow::initConfig() { 188void MainWindow::initConfig() {
189 Config config( "todo" ); 189 Config config( "todo" );
190 config.setGroup( "View" ); 190 config.setGroup( "View" );
191 m_completed = config.readBoolEntry( "ShowComplete", TRUE ); 191 m_completed = config.readBoolEntry( "ShowComplete", TRUE );
192 m_curCat = config.readEntry( "Category", QString::null ); 192 m_curCat = config.readEntry( "Category", QString::null );
193 m_deadline = config.readBoolEntry( "ShowDeadLine", TRUE); 193 m_deadline = config.readBoolEntry( "ShowDeadLine", TRUE);
194 m_overdue = config.readBoolEntry("ShowOverDue", TRUE ); 194 m_overdue = config.readBoolEntry("ShowOverDue", TRUE );
195} 195}
196void MainWindow::initUI() { 196void MainWindow::initUI() {
197 m_stack = new QWidgetStack(this, "main stack"); 197 m_stack = new QWidgetStack(this, "main stack");
198 setCentralWidget( m_stack ); 198 setCentralWidget( m_stack );
199 199
200 setToolBarsMovable( FALSE ); 200 setToolBarsMovable( FALSE );
201 201
202 m_tool = new QToolBar( this ); 202 m_tool = new QToolBar( this );
203 m_tool->setHorizontalStretchable( TRUE ); 203 m_tool->setHorizontalStretchable( TRUE );
204 204
205 m_bar = new QMenuBar( m_tool ); 205 m_bar = new QMenuBar( m_tool );
206 206
207 /** QPopupMenu */ 207 /** QPopupMenu */
208 m_edit = new QPopupMenu( this ); 208 m_edit = new QPopupMenu( this );
209 m_options = new QPopupMenu( this ); 209 m_options = new QPopupMenu( this );
210 m_view = new QPopupMenu( this ); 210 m_view = new QPopupMenu( this );
211 m_catMenu = new QPopupMenu( this ); 211 m_catMenu = new QPopupMenu( this );
212 m_template = new QPopupMenu( this ); 212 m_template = new QPopupMenu( this );
213 213
214 m_catMenu->setCheckable( TRUE ); 214 m_catMenu->setCheckable( TRUE );
215 m_template->setCheckable( TRUE ); 215 m_template->setCheckable( TRUE );
216 216
217 connect(m_catMenu, SIGNAL(activated(int) ), 217 connect(m_catMenu, SIGNAL(activated(int) ),
218 this, SLOT(setCategory(int) ) ); 218 this, SLOT(setCategory(int) ) );
219 connect(m_template, SIGNAL(activated(int) ), 219 connect(m_template, SIGNAL(activated(int) ),
220 this, SLOT(slotNewFromTemplate(int) ) ); 220 this, SLOT(slotNewFromTemplate(int) ) );
221} 221}
222void MainWindow::initViews() { 222void MainWindow::initViews() {
223 TableView* tableView = new TableView( this, this ); 223 TableView* tableView = new TableView( this, this );
224 m_stack->addWidget( tableView, m_counter++ ); 224 m_stack->addWidget( tableView, m_counter++ );
225 m_views.append( tableView ); 225 m_views.append( tableView );
226 m_curView = tableView; 226 m_curView = tableView;
227 connectBase( tableView ); 227 connectBase( tableView );
228 /* add QString type + QString configname to 228 /* add QString type + QString configname to
229 * the View menu 229 * the View menu
230 * and subdirs for multiple views 230 * and subdirs for multiple views
231 */ 231 */
232} 232}
233void MainWindow::initEditor() { 233void MainWindow::initEditor() {
234 m_curEdit = new Editor(); 234 m_curEdit = new Editor();
235} 235}
236void MainWindow::initShow() { 236void MainWindow::initShow() {
237 m_curShow = new TextViewShow(this); 237 m_curShow = new TextViewShow(this);
238 m_stack->addWidget( m_curShow->widget() , m_counter++ ); 238 m_stack->addWidget( m_curShow->widget() , m_counter++ );
239} 239}
240MainWindow::~MainWindow() { 240MainWindow::~MainWindow() {
241 delete templateManager(); 241 delete templateManager();
242} 242}
243void MainWindow::connectBase( ViewBase* base) { 243void MainWindow::connectBase( ViewBase* base) {
244 base->connectShow( this, SLOT(slotShow(int) ) ); 244 base->connectShow( this, SLOT(slotShow(int) ) );
245 base->connectEdit( this, SLOT(slotEdit(int) ) ); 245 base->connectEdit( this, SLOT(slotEdit(int) ) );
246 base->connectUpdateSmall( this, 246 base->connectUpdateSmall( this,
247 SLOT(slotUpate1(int, const Todo::SmallTodo&) )); 247 SLOT(slotUpate1(int, const Todo::SmallTodo&) ));
248 base->connectUpdateBig( this, 248 base->connectUpdateBig( this,
249 SLOT(slotUpate2(int, const OTodo& ) ) ); 249 SLOT(slotUpate2(int, const OTodo& ) ) );
250 base->connectUpdateView( this, SLOT(slotUpdate3( QWidget* ) ) ) ; 250 base->connectUpdateView( this, SLOT(slotUpdate3( QWidget* ) ) ) ;
251 base->connectRemove(&m_todoMgr, 251 base->connectRemove(&m_todoMgr,
252 SLOT(remove(int)) ); 252 SLOT(remove(int)) );
253} 253}
254QPopupMenu* MainWindow::contextMenu( int uid ) { 254QPopupMenu* MainWindow::contextMenu( int uid ) {
255 QPopupMenu* menu = new QPopupMenu(); 255 QPopupMenu* menu = new QPopupMenu();
256 256
257 m_editAction->addTo( menu ); 257 m_editAction->addTo( menu );
258 m_deleteAction->addTo( menu ); 258 m_deleteAction->addTo( menu );
259 m_duplicateAction->addTo( menu ); 259 m_duplicateAction->addTo( menu );
260 menu->insertSeparator(); 260 menu->insertSeparator();
261 261
262 return menu; 262 return menu;
263} 263}
264QPopupMenu* MainWindow::options() { 264QPopupMenu* MainWindow::options() {
265 qWarning("Options"); 265 qWarning("Options");
266 return m_options; 266 return m_options;
267} 267}
268QPopupMenu* MainWindow::edit() { 268QPopupMenu* MainWindow::edit() {
269 return m_edit; 269 return m_edit;
270} 270}
271QPopupMenu* MainWindow::view() { 271QPopupMenu* MainWindow::view() {
272 return m_view; 272 return m_view;
273} 273}
274QToolBar* MainWindow::toolbar() { 274QToolBar* MainWindow::toolbar() {
275 return m_tool; 275 return m_tool;
276} 276}
277OTodoAccess::List MainWindow::list()const { 277OTodoAccess::List MainWindow::list()const {
278 return m_todoMgr.list(); 278 return m_todoMgr.list();
279} 279}
280OTodoAccess::List MainWindow::sorted( bool asc, int sortOrder ) { 280OTodoAccess::List MainWindow::sorted( bool asc, int sortOrder ) {
281 int cat = 0; 281 int cat = 0;
282 if ( m_curCat == tr("All Categories") ) 282 if ( m_curCat == tr("All Categories") )
283 cat = currentCatId(); 283 cat = currentCatId();
284 284
285 int filter = 1; 285 int filter = 1;
286 286
287 if (!m_completed ) 287 if (!m_completed )
288 filter |= 4; 288 filter |= 4;
289 if (m_overdue) 289 if (m_overdue)
290 filter |= 2; 290 filter |= 2;
291 291
292 return m_todoMgr.sorted( asc, sortOrder, filter, cat ); 292 return m_todoMgr.sorted( asc, sortOrder, filter, cat );
293} 293}
294OTodoAccess::List MainWindow::sorted( bool asc, int sortOrder, int addFilter) { 294OTodoAccess::List MainWindow::sorted( bool asc, int sortOrder, int addFilter) {
295 int cat = 0; 295 int cat = 0;
296 if ( m_curCat == tr("All Categories") ) 296 if ( m_curCat == tr("All Categories") )
297 cat = currentCatId(); 297 cat = currentCatId();
298 298
299 return m_todoMgr.sorted(asc, sortOrder, addFilter, cat ); 299 return m_todoMgr.sorted(asc, sortOrder, addFilter, cat );
300} 300}
301OTodo MainWindow::event( int uid ) { 301OTodo MainWindow::event( int uid ) {
302 return m_todoMgr.event( uid ); 302 return m_todoMgr.event( uid );
303} 303}
304bool MainWindow::isSyncing()const { 304bool MainWindow::isSyncing()const {
305 return m_syncing; 305 return m_syncing;
306} 306}
307TemplateManager* MainWindow::templateManager() { 307TemplateManager* MainWindow::templateManager() {
308 return m_tempManager; 308 return m_tempManager;
309} 309}
310Editor* MainWindow::currentEditor() { 310Editor* MainWindow::currentEditor() {
311 return m_curEdit; 311 return m_curEdit;
312} 312}
313TodoShow* MainWindow::currentShow() { 313TodoShow* MainWindow::currentShow() {
314 return m_curShow; 314 return m_curShow;
315} 315}
316void MainWindow::slotReload() { 316void MainWindow::slotReload() {
317 m_todoMgr.reload(); 317 m_todoMgr.reload();
318 currentView()->updateView( ); 318 currentView()->updateView( );
319 raiseCurrentView(); 319 raiseCurrentView();
320} 320}
321void MainWindow::closeEvent( QCloseEvent* e ) { 321void MainWindow::closeEvent( QCloseEvent* e ) {
322 if (m_stack->visibleWidget() == currentShow()->widget() ) { 322 if (m_stack->visibleWidget() == currentShow()->widget() ) {
323 raiseCurrentView(); 323 raiseCurrentView();
324 e->ignore(); 324 e->ignore();
325 return; 325 return;
326 } 326 }
327 /* 327 /*
328 * we should have flushed and now we're still saving 328 * we should have flushed and now we're still saving
329 * so there is no need to flush 329 * so there is no need to flush
330 */ 330 */
331 if (m_syncing ) { 331 if (m_syncing ) {
332 e->accept(); 332 e->accept();
333 return; 333 return;
334 } 334 }
335 bool quit = false; 335 bool quit = false;
336 if ( m_todoMgr.saveAll() ){ 336 if ( m_todoMgr.saveAll() ){
337 qWarning("saved"); 337 qWarning("saved");
338 quit = true; 338 quit = true;
339 }else { 339 }else {
340 if ( QMessageBox::critical( this, tr("Out of space"), 340 if ( QMessageBox::critical( this, tr("Out of space"),
341 tr("Todo was unable\n" 341 tr("Todo was unable\n"
342 "to save your changes.\n" 342 "to save your changes.\n"
343 "Free up some space\n" 343 "Free up some space\n"
344 "and try again.\n" 344 "and try again.\n"
345 "\nQuit Anyway?"), 345 "\nQuit Anyway?"),
346 QMessageBox::Yes|QMessageBox::Escape, 346 QMessageBox::Yes|QMessageBox::Escape,
347 QMessageBox::No|QMessageBox::Default) 347 QMessageBox::No|QMessageBox::Default)
348 != QMessageBox::No ) { 348 != QMessageBox::No ) {
349 e->accept(); 349 e->accept();
350 quit = true; 350 quit = true;
351 }else 351 }else
352 e->ignore(); 352 e->ignore();
353 353
354 } 354 }
355 355
356 if (quit ) { 356 if (quit ) {
357 Config config( "todo" ); 357 Config config( "todo" );
358 config.setGroup( "View" ); 358 config.setGroup( "View" );
359 config.writeEntry( "ShowComplete", showCompleted() ); 359 config.writeEntry( "ShowComplete", showCompleted() );
360 config.writeEntry( "Category", currentCategory() ); 360 config.writeEntry( "Category", currentCategory() );
361 config.writeEntry( "ShowDeadLine", showDeadline()); 361 config.writeEntry( "ShowDeadLine", showDeadline());
362 config.writeEntry( "ShowOverDue", showOverDue() ); 362 config.writeEntry( "ShowOverDue", showOverDue() );
363 /* svae templates */ 363 /* svae templates */
364 templateManager()->save(); 364 templateManager()->save();
365 e->accept(); 365 e->accept();
366 } 366 }
367} 367}
368void MainWindow::populateTemplates() { 368void MainWindow::populateTemplates() {
369 m_template->clear(); 369 m_template->clear();
370 QStringList list = templateManager()->templates(); 370 QStringList list = templateManager()->templates();
371 QStringList::Iterator it; 371 QStringList::Iterator it;
372 for ( it = list.begin(); it != list.end(); ++it ) { 372 for ( it = list.begin(); it != list.end(); ++it ) {
373 m_template->insertItem( (*it) ); 373 m_template->insertItem( (*it) );
374 } 374 }
375} 375}
376/* 376/*
377 * slotNewFromTemplate 377 * slotNewFromTemplate
378 * We use the edit widget to do 378 * We use the edit widget to do
379 * the config but we setUid(-1) 379 * the config but we setUid(-1)
380 * to get a new uid 380 * to get a new uid
381 */ 381 */
382/* 382/*
383 * first we get the name of the template 383 * first we get the name of the template
384 * then we will use the TemplateManager 384 * then we will use the TemplateManager
385 */ 385 */
386void MainWindow::slotNewFromTemplate( int id ) { 386void MainWindow::slotNewFromTemplate( int id ) {
387 QString name = m_template->text( id ); 387 QString name = m_template->text( id );
388 388
389 OTodo event = templateManager()->templateEvent( name ); 389 OTodo event = templateManager()->templateEvent( name );
390 event = currentEditor()->edit(this, 390 event = currentEditor()->edit(this,
391 event ); 391 event );
392 392
393 if ( currentEditor()->accepted() ) { 393 if ( currentEditor()->accepted() ) {
394 /* assign new todo */ 394 /* assign new todo */
395 event.setUid( -1 ); 395 event.setUid( -1 );
396 currentView()->addEvent( event ); 396 currentView()->addEvent( event );
397 m_todoMgr.add( event ); 397 m_todoMgr.add( event );
398 398
399 populateCategories(); 399 populateCategories();
400 } 400 }
401} 401}
402void MainWindow::slotNew() { 402void MainWindow::slotNew() {
403 if(m_syncing) { 403 if(m_syncing) {
404 QMessageBox::warning(this, tr("Todo"), 404 QMessageBox::warning(this, tr("Todo"),
405 tr("Can not edit data, currently syncing")); 405 tr("Can not edit data, currently syncing"));
406 return; 406 return;
407 } 407 }
408 408
409 409
410 OTodo todo = currentEditor()->newTodo( currentCatId(), 410 OTodo todo = currentEditor()->newTodo( currentCatId(),
411 this ); 411 this );
412 412
413 if ( currentEditor()->accepted() ) { 413 if ( currentEditor()->accepted() ) {
414 //todo.assignUid(); 414 //todo.assignUid();
415 currentView()->addEvent( todo ); 415 currentView()->addEvent( todo );
416 m_todoMgr.add( todo ); 416 m_todoMgr.add( todo );
417 417
418 // I'm afraid we must call this every time now, otherwise 418 // I'm afraid we must call this every time now, otherwise
419 // spend expensive time comparing all these strings... 419 // spend expensive time comparing all these strings...
420 // but only call if we changed something -zecke 420 // but only call if we changed something -zecke
421 populateCategories(); 421 populateCategories();
422 } 422 }
423 423
424 raiseCurrentView( ); 424 raiseCurrentView( );
425} 425}
426void MainWindow::slotDuplicate() { 426void MainWindow::slotDuplicate() {
427 if(m_syncing) { 427 if(m_syncing) {
428 QMessageBox::warning(this, tr("Todo"), 428 QMessageBox::warning(this, tr("Todo"),
429 tr("Can not edit data, currently syncing")); 429 tr("Can not edit data, currently syncing"));
430 return; 430 return;
431 } 431 }
432 OTodo ev = m_todoMgr.event( currentView()->current() ); 432 OTodo ev = m_todoMgr.event( currentView()->current() );
433 /* let's generate a new uid */ 433 /* let's generate a new uid */
434 ev.setUid(-1); 434 ev.setUid(-1);
435 m_todoMgr.add( ev ); 435 m_todoMgr.add( ev );
436 436
437 currentView()->addEvent( ev ); 437 currentView()->addEvent( ev );
438 raiseCurrentView(); 438 raiseCurrentView();
439} 439}
440void MainWindow::slotDelete() { 440void MainWindow::slotDelete() {
441 if (!currentView()->current() ) 441 if (!currentView()->current() )
442 return; 442 return;
443 443
444 if(m_syncing) { 444 if(m_syncing) {
445 QMessageBox::warning(this, tr("Todo"), 445 QMessageBox::warning(this, tr("Todo"),
446 tr("Can not edit data, currently syncing")); 446 tr("Can not edit data, currently syncing"));
447 return; 447 return;
448 } 448 }
449 QString strName = currentView()->currentRepresentation(); 449 QString strName = currentView()->currentRepresentation();
450 if (!QPEMessageBox::confirmDelete(this, tr("Todo"), strName ) ) 450 if (!QPEMessageBox::confirmDelete(this, tr("Todo"), strName ) )
451 return; 451 return;
452 452
453 m_todoMgr.remove( currentView()->current() ); 453 m_todoMgr.remove( currentView()->current() );
454 currentView()->removeEvent( currentView()->current() ); 454 currentView()->removeEvent( currentView()->current() );
455 raiseCurrentView(); 455 raiseCurrentView();
456} 456}
457void MainWindow::slotDeleteAll() { 457void MainWindow::slotDeleteAll() {
458 if(m_syncing) { 458 if(m_syncing) {
459 QMessageBox::warning(this, tr("Todo"), 459 QMessageBox::warning(this, tr("Todo"),
460 tr("Can not edit data, currently syncing")); 460 tr("Can not edit data, currently syncing"));
461 return; 461 return;
462 } 462 }
463 463
464 //QString strName = table->text( table->currentRow(), 2 ).left( 30 ); 464 //QString strName = table->text( table->currentRow(), 2 ).left( 30 );
465 465
466 if ( !QPEMessageBox::confirmDelete( this, tr( "Todo" ), tr("all tasks?") ) ) 466 if ( !QPEMessageBox::confirmDelete( this, tr( "Todo" ), tr("all tasks?") ) )
467 return; 467 return;
468 468
469 m_todoMgr.removeAll(); 469 m_todoMgr.removeAll();
470 currentView()->clear(); 470 currentView()->clear();
471 471
472 raiseCurrentView(); 472 raiseCurrentView();
473} 473}
474void MainWindow::slotDeleteCompleted() { 474void MainWindow::slotDeleteCompleted() {
475 if(m_syncing) { 475 if(m_syncing) {
476 QMessageBox::warning(this, tr("Todo"), 476 QMessageBox::warning(this, tr("Todo"),
477 tr("Can not edit data, currently syncing")); 477 tr("Can not edit data, currently syncing"));
478 return; 478 return;
479 } 479 }
480 480
481 if ( !QPEMessageBox::confirmDelete( this, tr( "Todo" ), tr("all completed tasks?") ) ) 481 if ( !QPEMessageBox::confirmDelete( this, tr( "Todo" ), tr("all completed tasks?") ) )
482 return; 482 return;
483 483
484 m_todoMgr.remove( currentView()->completed() ); 484 // FIXME
485 //m_todoMgr.remove( currentView()->completed() );
485 currentView()->updateView( ); 486 currentView()->updateView( );
486} 487}
487void MainWindow::slotFind() { 488void MainWindow::slotFind() {
488 489
489} 490}
490void MainWindow::slotEdit() { 491void MainWindow::slotEdit() {
491 slotEdit( currentView()->current() ); 492 slotEdit( currentView()->current() );
492} 493}
493/* 494/*
494 * set the category 495 * set the category
495 */ 496 */
496void MainWindow::setCategory( int c) { 497void MainWindow::setCategory( int c) {
497 if ( c <= 0 ) return; 498 if ( c <= 0 ) return;
498 499
499 qWarning("Iterating over cats %d", c ); 500 qWarning("Iterating over cats %d", c );
500 for ( unsigned int i = 1; i < m_catMenu->count(); i++ ) 501 for ( unsigned int i = 1; i < m_catMenu->count(); i++ )
501 m_catMenu->setItemChecked(i, c == (int)i ); 502 m_catMenu->setItemChecked(i, c == (int)i );
502 503
503 if (c == 1 ) { 504 if (c == 1 ) {
504 m_curCat = QString::null; 505 m_curCat = QString::null;
505 setCaption( tr("Todo") + " - " + tr("All Categories" ) ); 506 setCaption( tr("Todo") + " - " + tr("All Categories" ) );
506 507
507 }else if ( c == (int)m_catMenu->count() - 1 ) { 508 }else if ( c == (int)m_catMenu->count() - 1 ) {
508 m_curCat = tr("Unfiled"); 509 m_curCat = tr("Unfiled");
509 setCaption( tr("Todo") + " - " + tr("Unfiled") ); 510 setCaption( tr("Todo") + " - " + tr("Unfiled") );
510 }else { 511 }else {
511 m_curCat = m_todoMgr.categories()[c-2]; 512 m_curCat = m_todoMgr.categories()[c-2];
512 setCaption( tr("Todo") + " - " + m_curCat ); 513 setCaption( tr("Todo") + " - " + m_curCat );
513 } 514 }
514 m_catMenu->setItemChecked( c, true ); 515 m_catMenu->setItemChecked( c, true );
515 currentView()->setShowCategory( m_curCat ); 516 currentView()->setShowCategory( m_curCat );
516 raiseCurrentView(); 517 raiseCurrentView();
517} 518}
518void MainWindow::slotShowDeadLine( bool dead) { 519void MainWindow::slotShowDeadLine( bool dead) {
519 m_deadline = dead; 520 m_deadline = dead;
520 currentView()->setShowDeadline( dead ); 521 currentView()->setShowDeadline( dead );
521} 522}
522void MainWindow::slotShowCompleted( bool show) { 523void MainWindow::slotShowCompleted( bool show) {
523 m_completed = show; 524 m_completed = show;
524 currentView()->setShowCompleted( m_completed ); 525 currentView()->setShowCompleted( m_completed );
525} 526}
526bool MainWindow::showOverDue()const { 527bool MainWindow::showOverDue()const {
527 return m_overdue; 528 return m_overdue;
528} 529}
529void MainWindow::setDocument( const QString& ) { 530void MainWindow::setDocument( const QString& ) {
530 531
531} 532}
532void MainWindow::slotBeam() { 533void MainWindow::slotBeam() {
533 534
534} 535}
535void MainWindow::beamDone( Ir* ) { 536void MainWindow::beamDone( Ir* ) {
536 537
537} 538}
538 539
539void MainWindow::slotFlush() { 540void MainWindow::slotFlush() {
540 m_syncing = FALSE; 541 m_syncing = FALSE;
541 m_todoMgr.save(); 542 m_todoMgr.save();
542} 543}
543void MainWindow::slotShowDetails() { 544void MainWindow::slotShowDetails() {
544 slotShow( currentView()->current() ); 545 slotShow( currentView()->current() );
545} 546}
546/* 547/*
547 * populate the Categories 548 * populate the Categories
548 * Menu 549 * Menu
549 */ 550 */
550void MainWindow::populateCategories() { 551void MainWindow::populateCategories() {
551 if (m_todoMgr.isLoaded() ) 552 if (m_todoMgr.isLoaded() )
552 m_todoMgr.load(); 553 m_todoMgr.load();
553 554
554 m_catMenu->clear(); 555 m_catMenu->clear();
555 int id, rememberId; 556 int id, rememberId;
556 id = 1; 557 id = 1;
557 rememberId = 1; 558 rememberId = 1;
558 559
559 m_catMenu->insertItem( tr( "All Categories" ), id++ ); 560 m_catMenu->insertItem( tr( "All Categories" ), id++ );
560 m_catMenu->insertSeparator(); 561 m_catMenu->insertSeparator();
561 QStringList categories = m_todoMgr.categories(); 562 QStringList categories = m_todoMgr.categories();
562 categories.append( tr( "Unfiled" ) ); 563 categories.append( tr( "Unfiled" ) );
563 for ( QStringList::Iterator it = categories.begin(); 564 for ( QStringList::Iterator it = categories.begin();
564 it != categories.end(); ++it ) { 565 it != categories.end(); ++it ) {
565 m_catMenu->insertItem( *it, id ); 566 m_catMenu->insertItem( *it, id );
566 if ( *it == currentCategory() ) 567 if ( *it == currentCategory() )
567 rememberId = id; 568 rememberId = id;
568 ++id; 569 ++id;
569 } 570 }
570 setCategory( rememberId ); 571 setCategory( rememberId );
571} 572}
572bool MainWindow::showCompleted()const { 573bool MainWindow::showCompleted()const {
573 return m_completed; 574 return m_completed;
574} 575}
575bool MainWindow::showDeadline()const { 576bool MainWindow::showDeadline()const {
576 return m_deadline; 577 return m_deadline;
577} 578}
578QString MainWindow::currentCategory()const { 579QString MainWindow::currentCategory()const {
579 return m_curCat; 580 return m_curCat;
580} 581}
581int MainWindow::currentCatId() { 582int MainWindow::currentCatId() {
582 return m_todoMgr.catId( m_curCat ); 583 return m_todoMgr.catId( m_curCat );
583} 584}
584ViewBase* MainWindow::currentView() { 585ViewBase* MainWindow::currentView() {
585 return m_curView; 586 return m_curView;
586} 587}
587void MainWindow::raiseCurrentView() { 588void MainWindow::raiseCurrentView() {
588 m_stack->raiseWidget( m_curView->widget() ); 589 m_stack->raiseWidget( m_curView->widget() );
589} 590}
590void MainWindow::slotShowDue(bool ov) { 591void MainWindow::slotShowDue(bool ov) {
591 m_overdue = ov; 592 m_overdue = ov;
592 currentView()->showOverDue( ov ); 593 currentView()->showOverDue( ov );
593 raiseCurrentView(); 594 raiseCurrentView();
594} 595}
595void MainWindow::slotShow( int uid ) { 596void MainWindow::slotShow( int uid ) {
596 qWarning("slotShow"); 597 qWarning("slotShow");
597 currentShow()->slotShow( event( uid ) ); 598 currentShow()->slotShow( event( uid ) );
598 m_stack->raiseWidget( currentShow()->widget() ); 599 m_stack->raiseWidget( currentShow()->widget() );
599} 600}
600void MainWindow::slotEdit( int uid ) { 601void MainWindow::slotEdit( int uid ) {
601 if(m_syncing) { 602 if(m_syncing) {
602 QMessageBox::warning(this, tr("Todo"), 603 QMessageBox::warning(this, tr("Todo"),
603 tr("Can not edit data, currently syncing")); 604 tr("Can not edit data, currently syncing"));
604 return; 605 return;
605 } 606 }
606 607
607 OTodo todo = m_todoMgr.event( uid ); 608 OTodo todo = m_todoMgr.event( uid );
608 609
609 todo = currentEditor()->edit(this, todo ); 610 todo = currentEditor()->edit(this, todo );
610 611
611 /* if completed */ 612 /* if completed */
612 if ( currentEditor()->accepted() ) { 613 if ( currentEditor()->accepted() ) {
613 qWarning("Replacing now" ); 614 qWarning("Replacing now" );
614 m_todoMgr.update( todo.uid(), todo ); 615 m_todoMgr.update( todo.uid(), todo );
615 currentView()->replaceEvent( todo ); 616 currentView()->replaceEvent( todo );
616 populateCategories(); 617 populateCategories();
617 } 618 }
618 619
619 raiseCurrentView(); 620 raiseCurrentView();
620} 621}
621/* 622/*
622void MainWindow::slotUpdate1( int uid, const SmallTodo& ev) { 623void MainWindow::slotUpdate1( int uid, const SmallTodo& ev) {
623 m_todoMgr.update( uid, ev ); 624 m_todoMgr.update( uid, ev );
624} 625}
625*/ 626*/
626void MainWindow::updateTodo( const OTodo& ev) { 627void MainWindow::updateTodo( const OTodo& ev) {
627 m_todoMgr.update( ev.uid() , ev ); 628 m_todoMgr.update( ev.uid() , ev );
628} 629}
629/* The view changed it's configuration 630/* The view changed it's configuration
630 * update the view menu 631 * update the view menu
631 */ 632 */
632void MainWindow::slotUpdate3( QWidget* ) { 633void MainWindow::slotUpdate3( QWidget* ) {
633 634
634} 635}
635void MainWindow::updateList() { 636void MainWindow::updateList() {
636 m_todoMgr.updateList(); 637 m_todoMgr.updateList();
637} 638}
diff --git a/core/pim/todo/tableitems.cpp b/core/pim/todo/tableitems.cpp
index ebfefc8..86fe07d 100644
--- a/core/pim/todo/tableitems.cpp
+++ b/core/pim/todo/tableitems.cpp
@@ -1,181 +1,181 @@
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#include "tableview.h" 28#include "tableview.h"
29 29
30#include "tableitems.h" 30#include "tableitems.h"
31#include <string.h> 31#include <string.h>
32 32
33using namespace Todo; 33using namespace Todo;
34 34
35CheckItem::CheckItem( QTable* t, 35CheckItem::CheckItem( QTable* t,
36 const QString& sortKey, 36 const QString& sortKey,
37 int uid, 37 int uid,
38 const QArray<int>& lis) 38 const QArray<int>& lis)
39 : OCheckItem(t, sortKey), m_uid(uid ), m_cat( lis ) 39 : OCheckItem(t, sortKey), m_uid(uid ), m_cat( lis )
40{ 40{
41} 41}
42CheckItem::~CheckItem() { 42CheckItem::~CheckItem() {
43} 43}
44void CheckItem::setChecked( bool b ) { 44void CheckItem::setChecked( bool b ) {
45 OCheckItem::setChecked(b); 45 OCheckItem::setChecked(b);
46} 46}
47void CheckItem::toggle() { 47void CheckItem::toggle() {
48 TableView* view = static_cast<TableView*>( table() ); 48 TableView* view = static_cast<TableView*>( table() );
49 OTodo ev = view->find( view->current() ); 49 OTodo ev = view->find( view->current() );
50 ev.setCompleted(!isChecked() ); 50 ev.setCompleted(!isChecked() );
51 view->updateFromTable( ev ); 51 //view->updateFromTable( ev );
52 52
53 OCheckItem::toggle(); 53 OCheckItem::toggle();
54 table()->updateCell( row(), col() ); 54 table()->updateCell( row(), col() );
55} 55}
56int CheckItem::uid() const { 56int CheckItem::uid() const {
57 return m_uid; 57 return m_uid;
58} 58}
59QArray<int> CheckItem::cats() { 59QArray<int> CheckItem::cats() {
60 return m_cat; 60 return m_cat;
61} 61}
62 62
63/* ComboItem */ 63/* ComboItem */
64ComboItem::ComboItem( QTable* t, EditType et ) 64ComboItem::ComboItem( QTable* t, EditType et )
65 : QTableItem( t, et, "3" ), m_cb(0) 65 : QTableItem( t, et, "3" ), m_cb(0)
66{ 66{
67 setReplaceable( FALSE ); 67 setReplaceable( FALSE );
68} 68}
69ComboItem::~ComboItem() { 69ComboItem::~ComboItem() {
70 70
71} 71}
72QWidget* ComboItem::createEditor()const { 72QWidget* ComboItem::createEditor()const {
73 qWarning( "create editor"); 73 qWarning( "create editor");
74 QString txt = text(); 74 QString txt = text();
75 75
76 ( (ComboItem*)this)-> m_cb = new QComboBox( table()->viewport() ); 76 ( (ComboItem*)this)-> m_cb = new QComboBox( table()->viewport() );
77 77
78 m_cb->insertItem( "1" ); 78 m_cb->insertItem( "1" );
79 m_cb->insertItem( "2" ); 79 m_cb->insertItem( "2" );
80 m_cb->insertItem( "3" ); 80 m_cb->insertItem( "3" );
81 m_cb->insertItem( "4" ); 81 m_cb->insertItem( "4" );
82 m_cb->insertItem( "5" ); 82 m_cb->insertItem( "5" );
83 m_cb->setCurrentItem( txt.toInt() - 1 ); 83 m_cb->setCurrentItem( txt.toInt() - 1 );
84 84
85 return m_cb; 85 return m_cb;
86} 86}
87void ComboItem::setContentFromEditor( QWidget* w) { 87void ComboItem::setContentFromEditor( QWidget* w) {
88 TableView* view = static_cast<TableView*>( table() ); 88 TableView* view = static_cast<TableView*>( table() );
89 OTodo ev = view->find( view->current() ); 89 OTodo ev = view->find( view->current() );
90 90
91 if ( w->inherits( "QComboBox" ) ) 91 if ( w->inherits( "QComboBox" ) )
92 setText( ( (QComboBox*)w )->currentText() ); 92 setText( ( (QComboBox*)w )->currentText() );
93 else 93 else
94 QTableItem::setContentFromEditor( w ); 94 QTableItem::setContentFromEditor( w );
95 95
96 ev.setPriority( text().toInt() ); 96 ev.setPriority( text().toInt() );
97 view->updateFromTable( ev ); 97 //view->updateFromTable( ev );
98} 98}
99void ComboItem::setText( const QString& s ) { 99void ComboItem::setText( const QString& s ) {
100 if ( m_cb ) 100 if ( m_cb )
101 m_cb->setCurrentItem( s.toInt()-1 ); 101 m_cb->setCurrentItem( s.toInt()-1 );
102 102
103 QTableItem::setText( s ); 103 QTableItem::setText( s );
104} 104}
105QString ComboItem::text()const { 105QString ComboItem::text()const {
106 if ( m_cb) 106 if ( m_cb)
107 return m_cb->currentText(); 107 return m_cb->currentText();
108 108
109 return QTableItem::text(); 109 return QTableItem::text();
110} 110}
111 111
112/* TodoTextItem */ 112/* TodoTextItem */
113TodoTextItem::~TodoTextItem() { 113TodoTextItem::~TodoTextItem() {
114 114
115} 115}
116TodoTextItem::TodoTextItem( QTable* t, 116TodoTextItem::TodoTextItem( QTable* t,
117 const QString& string ) 117 const QString& string )
118 : QTableItem( t, QTableItem::Never, string ) 118 : QTableItem( t, QTableItem::Never, string )
119{} 119{}
120 120
121/* DueTextItem */ 121/* DueTextItem */
122DueTextItem::DueTextItem( QTable* t, const OTodo& ev) 122DueTextItem::DueTextItem( QTable* t, const OTodo& ev)
123 : QTableItem(t, Never, QString::null ) 123 : QTableItem(t, Never, QString::null )
124{ 124{
125 setToDoEvent( ev ); 125 setToDoEvent( ev );
126} 126}
127DueTextItem::~DueTextItem() { 127DueTextItem::~DueTextItem() {
128 128
129} 129}
130QString DueTextItem::key() const { 130QString DueTextItem::key() const {
131 QString key; 131 QString key;
132 132
133 if( m_hasDate ){ 133 if( m_hasDate ){
134 if(m_off == 0 ){ 134 if(m_off == 0 ){
135 key.append("b"); 135 key.append("b");
136 }else if( m_off > 0 ){ 136 }else if( m_off > 0 ){
137 key.append("c"); 137 key.append("c");
138 }else if( m_off < 0 ){ 138 }else if( m_off < 0 ){
139 key.append("a"); 139 key.append("a");
140 } 140 }
141 key.append(QString::number(m_off ) ); 141 key.append(QString::number(m_off ) );
142 }else{ 142 }else{
143 key.append("d"); 143 key.append("d");
144 } 144 }
145 return key; 145 return key;
146} 146}
147void DueTextItem::setCompleted( bool comp ) { 147void DueTextItem::setCompleted( bool comp ) {
148 m_completed = comp; 148 m_completed = comp;
149 table()->updateCell( row(), col() ); 149 table()->updateCell( row(), col() );
150} 150}
151void DueTextItem::setToDoEvent( const OTodo& ev ) { 151void DueTextItem::setToDoEvent( const OTodo& ev ) {
152 m_hasDate = ev.hasDueDate(); 152 m_hasDate = ev.hasDueDate();
153 m_completed = ev.isCompleted(); 153 m_completed = ev.isCompleted();
154 154
155 if( ev.hasDueDate() ){ 155 if( ev.hasDueDate() ){
156 QDate today = QDate::currentDate(); 156 QDate today = QDate::currentDate();
157 m_off = today.daysTo(ev.dueDate() ); 157 m_off = today.daysTo(ev.dueDate() );
158 setText( QString::number(m_off) + " day(s) " ); 158 setText( QString::number(m_off) + " day(s) " );
159 }else{ 159 }else{
160 setText("n.d." ); 160 setText("n.d." );
161 m_off = 0; 161 m_off = 0;
162 } 162 }
163} 163}
164void DueTextItem::paint( QPainter* p, const QColorGroup &cg, 164void DueTextItem::paint( QPainter* p, const QColorGroup &cg,
165 const QRect& cr, bool selected ) { 165 const QRect& cr, bool selected ) {
166 QColorGroup cg2(cg); 166 QColorGroup cg2(cg);
167 167
168 QColor text = cg.text(); 168 QColor text = cg.text();
169 if( m_hasDate && !m_completed ){ 169 if( m_hasDate && !m_completed ){
170 if( m_off < 0 ){ 170 if( m_off < 0 ){
171 cg2.setColor(QColorGroup::Text, QColor(red ) ); 171 cg2.setColor(QColorGroup::Text, QColor(red ) );
172 }else if( m_off == 0 ){ 172 }else if( m_off == 0 ){
173 cg2.setColor(QColorGroup::Text, QColor(yellow) ); // orange isn't predefined 173 cg2.setColor(QColorGroup::Text, QColor(yellow) ); // orange isn't predefined
174 }else if( m_off > 0){ 174 }else if( m_off > 0){
175 cg2.setColor(QColorGroup::Text, QColor(green ) ); 175 cg2.setColor(QColorGroup::Text, QColor(green ) );
176 } 176 }
177 } 177 }
178 QTableItem::paint(p, cg2, cr, selected ); 178 QTableItem::paint(p, cg2, cr, selected );
179 /* restore default color */ 179 /* restore default color */
180 cg2.setColor(QColorGroup::Text, text ); 180 cg2.setColor(QColorGroup::Text, text );
181} 181}
diff --git a/core/pim/todo/tableview.cpp b/core/pim/todo/tableview.cpp
index eaaf1bc..5594b13 100644
--- a/core/pim/todo/tableview.cpp
+++ b/core/pim/todo/tableview.cpp
@@ -1,368 +1,359 @@
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 <qtimer.h> 29#include <qtimer.h>
30#include <qpoint.h> 30#include <qpoint.h>
31#include <qpopupmenu.h> 31#include <qpopupmenu.h>
32 32
33#include "mainwindow.h" 33#include "mainwindow.h"
34//#include "tableitems.h" 34//#include "tableitems.h"
35#include "tableview.h" 35#include "tableview.h"
36 36
37using namespace Todo; 37using namespace Todo;
38 38
39namespace {
40 static const int BoxSize = 14;
41 static const int RowHeight = 20;
42}
43
39 44
40TableView::TableView( MainWindow* window, QWidget* wid ) 45TableView::TableView( MainWindow* window, QWidget* wid )
41 : QTable( wid ), TodoView( window ) { 46 : QTable( wid ), TodoView( window ) {
42 setUpdatesEnabled( false ); 47 setUpdatesEnabled( false );
43 viewport()->setUpdatesEnabled( false ); 48 viewport()->setUpdatesEnabled( false );
44 m_enablePaint = false; 49 m_enablePaint = false;
45 setNumRows(0); 50 setNumRows(0);
46 setNumCols(4); 51 setNumCols(4);
47 52
48 setSorting( TRUE ); 53 setSorting( TRUE );
49 setSelectionMode( NoSelection ); 54 setSelectionMode( NoSelection );
50 setColumnStretchable( 2, TRUE ); 55 setColumnStretchable( 2, TRUE );
51 setColumnWidth(0, 20 ); 56 setColumnWidth(0, 20 );
52 setColumnWidth(1, 35 ); 57 setColumnWidth(1, 35 );
53 58
54 setLeftMargin( 0 ); 59 setLeftMargin( 0 );
55 verticalHeader()->hide(); 60 verticalHeader()->hide();
56 61
57 horizontalHeader()->setLabel(0, tr("C.") ); 62 horizontalHeader()->setLabel(0, tr("C.") );
58 horizontalHeader()->setLabel(1, tr("Prior.") ); 63 horizontalHeader()->setLabel(1, tr("Prior.") );
59 horizontalHeader()->setLabel(2, tr("Description" ) ); 64 horizontalHeader()->setLabel(2, tr("Description" ) );
60 65
61 setColumnStretchable(3, FALSE ); 66 setColumnStretchable(3, FALSE );
62 setColumnWidth(3, 20 ); 67 setColumnWidth(3, 20 );
63 horizontalHeader()->setLabel(3, tr("Deadline") ); 68 horizontalHeader()->setLabel(3, tr("Deadline") );
64 69
65 if ( todoWindow()->showDeadline() ) 70 if ( todoWindow()->showDeadline() )
66 showColumn( 3); 71 showColumn( 3);
67 else 72 else
68 hideColumn(3 ); 73 hideColumn(3 );
69 74
70 connect((QTable*)this, SIGNAL( clicked( int, int, int, const QPoint& ) ), 75 connect((QTable*)this, SIGNAL( clicked( int, int, int, const QPoint& ) ),
71 this, SLOT( slotClicked(int, int, int, const QPoint& ) ) ); 76 this, SLOT( slotClicked(int, int, int, const QPoint& ) ) );
72 connect((QTable*)this, SIGNAL( pressed( int, int, int, const QPoint& ) ), 77 connect((QTable*)this, SIGNAL( pressed( int, int, int, const QPoint& ) ),
73 this, SLOT( slotPressed(int, int, int, const QPoint& ) ) ); 78 this, SLOT( slotPressed(int, int, int, const QPoint& ) ) );
74 connect((QTable*)this, SIGNAL(valueChanged(int, int) ), 79 connect((QTable*)this, SIGNAL(valueChanged(int, int) ),
75 this, SLOT( slotValueChanged(int, int) ) ); 80 this, SLOT( slotValueChanged(int, int) ) );
76 connect((QTable*)this, SIGNAL(currentChanged(int, int) ), 81 connect((QTable*)this, SIGNAL(currentChanged(int, int) ),
77 this, SLOT( slotCurrentChanged(int, int) ) ); 82 this, SLOT( slotCurrentChanged(int, int) ) );
78 83
79 m_menuTimer = new QTimer( this ); 84 m_menuTimer = new QTimer( this );
80 connect( m_menuTimer, SIGNAL(timeout()), 85 connect( m_menuTimer, SIGNAL(timeout()),
81 this, SLOT(slotShowMenu()) ); 86 this, SLOT(slotShowMenu()) );
82 87
83 m_enablePaint = true; 88 m_enablePaint = true;
84 setUpdatesEnabled( true ); 89 setUpdatesEnabled( true );
85 viewport()->setUpdatesEnabled( true ); 90 viewport()->setUpdatesEnabled( true );
86 viewport()->update(); 91 viewport()->update();
87} 92}
88/* a new day has started 93/* a new day has started
89 * update the day 94 * update the day
90 */ 95 */
91void TableView::newDay() { 96void TableView::newDay() {
92 clear(); 97 clear();
93 updateView(); 98 updateView();
94} 99}
95TableView::~TableView() { 100TableView::~TableView() {
96 101
97} 102}
98void TableView::slotShowMenu() { 103void TableView::slotShowMenu() {
99 QPopupMenu *menu = todoWindow()->contextMenu( current() ); 104 QPopupMenu *menu = todoWindow()->contextMenu( current() );
100 menu->exec(QCursor::pos() ); 105 menu->exec(QCursor::pos() );
101 delete menu; 106 delete menu;
102} 107}
103OTodo TableView::find(int uid ) {
104 OTodo ev = TodoView::event( uid );
105 return ev;
106}
107void TableView::updateFromTable( const OTodo& ev, CheckItem* item ) {
108 TodoView::update( ev.uid(), ev );
109
110 /* update the other columns */
111 /* if completed or not we need to update
112 * the table
113 *
114 * We've two cases
115 * either item or !item
116 * this makes cases more easy
117 */
118 if ( !item ) {
119 item = m_cache[ev.uid()];
120 }
121 DueTextItem *due = dueItem( item->row() );
122 due->setCompleted( ev.isCompleted() );
123}
124QString TableView::type() const { 108QString TableView::type() const {
125 return QString::fromLatin1( tr("Table View") ); 109 return QString::fromLatin1( tr("Table View") );
126} 110}
127int TableView::current() { 111int TableView::current() {
128 int cur = 0; 112 int cur = 0;
129 CheckItem* i = checkItem( currentRow() ); 113 // FIXME
130 if (i )
131 cur = i->uid();
132
133 return cur; 114 return cur;
134} 115}
135QString TableView::currentRepresentation() { 116QString TableView::currentRepresentation() {
136 return text( currentRow(), 2); 117 return text( currentRow(), 2);
137} 118}
138/* show overdue */ 119/* show overdue */
139void TableView::showOverDue( bool ) { 120void TableView::showOverDue( bool ) {
140 clear(); 121 clear();
141 updateView(); 122 updateView();
142} 123}
143 124
144void TableView::updateView( ) { 125void TableView::updateView( ) {
145 setSortOrder( 0 ); 126 setSortOrder( 0 );
146 setAscending( true ); 127 setAscending( true );
147 sort(); 128 sort();
148 OTodoAccess::List::Iterator it, end; 129 OTodoAccess::List::Iterator it, end;
149 it = sorted().begin(); 130 it = sorted().begin();
150 end = sorted().end(); 131 end = sorted().end();
132
151 qWarning("setTodos"); 133 qWarning("setTodos");
152 QTime time; 134 QTime time;
153 time.start(); 135 time.start();
154 m_enablePaint = false; 136 m_enablePaint = false;
155 setUpdatesEnabled( false ); 137 setUpdatesEnabled( false );
156 viewport()->setUpdatesEnabled( false ); 138 viewport()->setUpdatesEnabled( false );
157 clear(); 139
158 QString currentCat = todoWindow()->currentCategory();
159 bool showCompleted = todoWindow()->showCompleted();
160 bool showOverDue = todoWindow()->showOverDue();
161 qWarning( "Current Category:" + todoWindow()->currentCategory() );
162 int id = todoWindow()->currentCatId();
163 QTime t; 140 QTime t;
164 t.start(); 141 t.start();
165 setNumRows( it.count() ); 142 setNumRows( it.count() );
166 uint i = 0;
167 for (; it != end; ++it ) {
168 OTodo todo = (*it);
169 /* test if the categories match */
170 if ( !currentCat.isEmpty() &&
171 !todo.categories().contains( id ) ) {
172 continue;
173 }
174 /* the item is completed but we shouldn't show it */
175 if ( !showCompleted && todo.isCompleted() ) {
176 qWarning("isCompleted ");
177 continue;
178 }
179 /* the item is not overdue but we should only show overdue */
180 if ( showOverDue && !todo.isOverdue() ) {
181 continue;
182 }
183 /* now it's fine to add it */
184 insertTodo( todo, i );
185 i++;
186 }
187 setNumRows( i );
188 int elc = time.elapsed(); 143 int elc = time.elapsed();
189 qWarning("Adding took %d", elc/1000 ); 144 qWarning("Adding took %d", elc/1000 );
190 setUpdatesEnabled( true ); 145 setUpdatesEnabled( true );
191 viewport()->setUpdatesEnabled( true ); 146 viewport()->setUpdatesEnabled( true );
192 viewport()->update(); 147 viewport()->update();
148
193 m_enablePaint = true; 149 m_enablePaint = true;
194 int el = time.elapsed(); 150 int el = time.elapsed();
195 qWarning("adding took %d", el/1000 ); 151 qWarning("adding took %d", el/1000 );
196} 152}
197void TableView::setTodo( int uid, const OTodo& ev ) { 153void TableView::setTodo( int, const OTodo&) {
198 QMap<int, CheckItem*>::Iterator it = m_cache.find( uid ); 154 sort();
199
200 if ( it != m_cache.end() ) {
201 int row = it.data()->row();
202
203 /* update checked */
204 CheckItem* check = checkItem(row );
205 if (check)
206 check->setChecked( ev.isCompleted() );
207
208 /* update the text */
209 QString sum = ev.summary();
210 setText(row, 2, sum.isEmpty() ?
211 ev.description().left(40).simplifyWhiteSpace() :
212 sum );
213
214 /* update priority */
215 setText(row, 1, QString::number( ev.priority() ) );
216 155
217 /* update DueDate */ 156 /* repaint */
218 DueTextItem *due = dueItem( row ); 157 QTable::update();
219 due->setToDoEvent( ev );
220 }
221} 158}
222void TableView::addEvent( const OTodo& ev) { 159void TableView::addEvent( const OTodo&) {
223 int row= numRows(); 160 sort();
224 setNumRows( row + 1 ); 161
225 insertTodo( ev, row ); 162 QTable::update();
226} 163}
227/* 164/*
228 * find the event 165 * find the event
229 * and then replace the complete row 166 * and then replace the complete row
230 */ 167 */
231void TableView::replaceEvent( const OTodo& ev) { 168void TableView::replaceEvent( const OTodo& ev) {
232 setTodo( ev.uid(), ev ); 169 addEvent( ev );
233} 170}
234/* 171/*
235 * re aligning table can be slow too 172 * re aligning table can be slow too
236 * FIXME: look what performs better 173 * FIXME: look what performs better
237 * either this or the old align table 174 * either this or the old align table
238 */ 175 */
239void TableView::removeEvent( int ) { 176void TableView::removeEvent( int ) {
240 clear();
241 updateView(); 177 updateView();
242} 178}
243void TableView::setShowCompleted( bool b) { 179void TableView::setShowCompleted( bool b) {
244 qWarning("Show Completed %d" + b ); 180 qWarning("Show Completed %d" + b );
245 updateView(); 181 updateView();
246} 182}
247void TableView::setShowDeadline( bool b) { 183void TableView::setShowDeadline( bool b) {
248 qWarning("Show DeadLine %d" + b ); 184 qWarning("Show DeadLine %d" + b );
249 if (b) 185 if (b)
250 showColumn(3 ); 186 showColumn(3 );
251 else 187 else
252 hideColumn(3 ); 188 hideColumn(3 );
253} 189}
254void TableView::setShowCategory( const QString& ) { 190void TableView::setShowCategory( const QString& ) {
255 qWarning("setShowCategory"); 191 qWarning("setShowCategory");
256 updateView(); 192 updateView();
257} 193}
258void TableView::clear() { 194void TableView::clear() {
259 m_cache.clear(); 195 setNumRows(0);
260 int rows = numRows();
261 for (int r = 0; r < rows; r++ ) {
262 for (int c = 0; c < numCols(); c++ ) {
263 if ( cellWidget(r, c) )
264 clearCellWidget(r, c );
265 clearCell(r, c);
266 }
267 }
268 setNumRows( 0);
269}
270QArray<int> TableView::completed() {
271 int row = numRows();
272 QArray<int> ids( row );
273
274 int j=0;
275 for (int i = 0; i < row; i++ ) {
276 CheckItem* item = checkItem(i );
277 if (item->isChecked() ) {
278 ids[j] = item->uid();
279 j++;
280 }
281 }
282 ids.resize( j );
283 return ids;
284} 196}
285void TableView::slotClicked(int row, int col, int, 197void TableView::slotClicked(int row, int col, int,
286 const QPoint& point) { 198 const QPoint& point) {
287 if ( !cellGeometry(row, col ).contains(point ) ) 199 if ( !cellGeometry(row, col ).contains(point ) )
288 return; 200 return;
201 int ui=0; // FIXME = uid(row);
289 202
290 203
291 switch( col ) { 204 switch( col ) {
292 case 0: { 205 case 0: {
293 CheckItem* item = checkItem( row ); 206 // FIXME
207 CheckItem* item = 0l;
294 /* 208 /*
295 * let's see if we centered clicked 209 * let's see if we centered clicked
296 */ 210 */
297 if ( item ) { 211 if ( item ) {
298 int x = point.x() -columnPos( col ); 212 int x = point.x() -columnPos( col );
299 int y = point.y() -rowPos( row ); 213 int y = point.y() -rowPos( row );
300 int w = columnWidth( col ); 214 int w = columnWidth( col );
301 int h = rowHeight( row ); 215 int h = rowHeight( row );
302 if ( x >= ( w - OCheckItem::BoxSize ) / 2 && 216 if ( x >= ( w - OCheckItem::BoxSize ) / 2 &&
303 x <= ( w - OCheckItem::BoxSize ) / 2 + OCheckItem::BoxSize && 217 x <= ( w - OCheckItem::BoxSize ) / 2 + OCheckItem::BoxSize &&
304 y >= ( h - OCheckItem::BoxSize ) / 2 && 218 y >= ( h - OCheckItem::BoxSize ) / 2 &&
305 y <= ( h - OCheckItem::BoxSize ) / 2 + OCheckItem::BoxSize ) 219 y <= ( h - OCheckItem::BoxSize ) / 2 + OCheckItem::BoxSize )
306 item->toggle(); 220 item->toggle();
307 } 221 }
308 } 222 }
309 break; 223 break;
310 224
311 case 1: 225 case 1:
312 break; 226 break;
313 227
314 case 2: { 228 case 2: {
315 m_menuTimer->stop(); 229 m_menuTimer->stop();
316 showTodo( checkItem(row)->uid() ); 230 showTodo( ui );
317 break; 231 break;
318 } 232 }
319 case 3: { 233 case 3: {
320 m_menuTimer->stop(); 234 m_menuTimer->stop();
321 TodoView::edit( checkItem(row)->uid() ); 235 TodoView::edit( ui );
322 break; 236 break;
323 } 237 }
324 } 238 }
325 239
326 240
327} 241}
328void TableView::slotPressed(int row, int col, int, 242void TableView::slotPressed(int row, int col, int,
329 const QPoint& point) { 243 const QPoint& point) {
330 244
331 /* TextColumn column */ 245 /* TextColumn column */
332 if ( col == 2 && cellGeometry( row, col ).contains( point ) ) 246 if ( col == 2 && cellGeometry( row, col ).contains( point ) )
333 m_menuTimer->start( 750, TRUE ); 247 m_menuTimer->start( 750, TRUE );
334} 248}
335void TableView::slotValueChanged( int, int ) { 249void TableView::slotValueChanged( int, int ) {
336 qWarning("Value Changed"); 250 qWarning("Value Changed");
337} 251}
338void TableView::slotCurrentChanged(int, int ) { 252void TableView::slotCurrentChanged(int, int ) {
339 m_menuTimer->stop(); 253 m_menuTimer->stop();
340} 254}
341/*
342 * hardcode to column 0
343 */
344CheckItem* TableView::checkItem( int row ) {
345 CheckItem *i = static_cast<CheckItem*>( item( row, 0 ) );
346 return i;
347}
348DueTextItem* TableView::dueItem( int row ) {
349 DueTextItem* i = static_cast<DueTextItem*> ( item(row, 3 ) );
350 return i;
351}
352QWidget* TableView::widget() { 255QWidget* TableView::widget() {
353 return this; 256 return this;
354} 257}
355/* 258/*
356 * We need to overwrite sortColumn 259 * We need to overwrite sortColumn
357 * because we want to sort whole row 260 * because we want to sort whole row
358 * based 261 * based
262 * We event want to set the setOrder
263 * to a sort() and update()
359 */ 264 */
360void TableView::sortColumn( int row, bool asc, bool ) { 265void TableView::sortColumn( int row, bool asc, bool ) {
361 QTable::sortColumn( row, asc, TRUE ); 266 QTable::sortColumn( row, asc, TRUE );
362 267
363} 268}
364void TableView::viewportPaintEvent( QPaintEvent* e) { 269void TableView::viewportPaintEvent( QPaintEvent* e) {
365 qWarning("Paint event" ); 270 qWarning("Paint event" );
366 if (m_enablePaint ) 271 if (m_enablePaint )
367 QTable::viewportPaintEvent( e ); 272 QTable::viewportPaintEvent( e );
368} 273}
274/*
275 * This segment is copyrighted by TT
276 * it was taken from their todolist
277 * application this code is GPL
278 */
279void TableView::paintCell(QPainter* p, int row, int col, const QRect& cr, bool ) {
280 const QColorGroup &cg = colorGroup();
281
282 p->save();
283
284 OTodo task = sorted()[row];
285
286 p->fillRect( 0, 0, cr.width(), cr.height(), cg.brush( QColorGroup::Base ) );
287
288 QPen op = p->pen();
289 p->setPen(cg.mid());
290 p->drawLine( 0, cr.height() - 1, cr.width() - 1, cr.height() - 1 );
291 p->drawLine( cr.width() - 1, 0, cr.width() - 1, cr.height() - 1 );
292 p->setPen(op);
293
294 QFont f = p->font();
295 QFontMetrics fm(f);
296
297 switch(col) {
298 case 0:
299 {
300 // completed field
301 int marg = ( cr.width() - BoxSize ) / 2;
302 int x = 0;
303 int y = ( cr.height() - BoxSize ) / 2;
304 p->setPen( QPen( cg.text() ) );
305 p->drawRect( x + marg, y, BoxSize, BoxSize );
306 p->drawRect( x + marg+1, y+1, BoxSize-2, BoxSize-2 );
307 p->setPen( darkGreen );
308 x += 1;
309 y += 1;
310 if ( task.isCompleted() ) {
311 QPointArray a( 9*2 );
312 int i, xx, yy;
313 xx = x+2+marg;
314 yy = y+4;
315 for ( i=0; i<4; i++ ) {
316 a.setPoint( 2*i, xx, yy );
317 a.setPoint( 2*i+1, xx, yy+2 );
318 xx++; yy++;
319 }
320 yy -= 2;
321 for ( i=4; i<9; i++ ) {
322 a.setPoint( 2*i, xx, yy );
323 a.setPoint( 2*i+1, xx, yy+2 );
324 xx++; yy--;
325 }
326 p->drawLineSegments( a );
327 }
328 }
329 break;
330 case 1:
331 // priority field
332 {
333 QString text = QString::number(task.priority());
334 p->drawText(2,2 + fm.ascent(), text);
335 }
336 break;
337 case 2:
338 // description field
339 {
340 QString text = task.summary().isEmpty() ?
341 task.description() :
342 task.summary();
343 p->drawText(2,2 + fm.ascent(), text);
344 }
345 break;
346 case 3:
347 {
348 QString text;
349 if (task.hasDueDate()) {
350 text = "HAS";
351 } else {
352 text = tr("None");
353 }
354 p->drawText(2,2 + fm.ascent(), text);
355 }
356 break;
357 }
358 p->restore();
359}
diff --git a/core/pim/todo/tableview.h b/core/pim/todo/tableview.h
index 1fa21b2..b608204 100644
--- a/core/pim/todo/tableview.h
+++ b/core/pim/todo/tableview.h
@@ -1,119 +1,93 @@
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#ifndef OPIE_TABLE_VIEW_H 29#ifndef OPIE_TABLE_VIEW_H
30#define OPIE_TABLE_VIEW_H 30#define OPIE_TABLE_VIEW_H
31 31
32#include <qtable.h> 32#include <qtable.h>
33#include <qmap.h> 33#include <qmap.h>
34 34
35#include "tableitems.h" 35#include "tableitems.h"
36#include "todoview.h" 36#include "todoview.h"
37 37
38class QTimer; 38class QTimer;
39 39
40namespace Todo { 40namespace Todo {
41 class CheckItem; 41 class CheckItem;
42 class DueTextItem; 42 class DueTextItem;
43 class TableView : public QTable, public TodoView { 43 class TableView : public QTable, public TodoView {
44 Q_OBJECT 44 Q_OBJECT
45 public: 45 public:
46 TableView( MainWindow*, QWidget* parent ); 46 TableView( MainWindow*, QWidget* parent );
47 ~TableView(); 47 ~TableView();
48 48
49 void updateFromTable( const OTodo&, CheckItem* = 0 );
50 OTodo find(int uid);
51 49
52 QString type()const; 50 QString type()const;
53 int current(); 51 int current();
54 QString currentRepresentation(); 52 QString currentRepresentation();
55 53
54 void clear();
56 void showOverDue( bool ); 55 void showOverDue( bool );
57 void updateView(); 56 void updateView();
58 void setTodo( int uid, const OTodo& ); 57 void setTodo( int uid, const OTodo& );
59 void addEvent( const OTodo& event ); 58 void addEvent( const OTodo& event );
60 void replaceEvent( const OTodo& ); 59 void replaceEvent( const OTodo& );
61 void removeEvent( int uid ); 60 void removeEvent( int uid );
62 void setShowCompleted( bool ); 61 void setShowCompleted( bool );
63 void setShowDeadline( bool ); 62 void setShowDeadline( bool );
64 63
65 void setShowCategory(const QString& =QString::null ); 64 void setShowCategory(const QString& =QString::null );
66 void clear();
67 void newDay(); 65 void newDay();
68 QArray<int> completed();
69 QWidget* widget(); 66 QWidget* widget();
70 void sortColumn(int, bool, bool ); 67 void sortColumn(int, bool, bool );
68
69 /*
70 * we do our drawing ourselves
71 * because we don't want to have
72 * 40.000 QTableItems for 10.000
73 * OTodos where we only show 10 at a time!
74 */
75 void paintCell(QPainter* p, int row, int col, const QRect&, bool );
71 private: 76 private:
72 /* reimplented for internal reasons */ 77 /* reimplented for internal reasons */
73 void viewportPaintEvent( QPaintEvent* ); 78 void viewportPaintEvent( QPaintEvent* );
74 inline void insertTodo( const OTodo&, int row );
75 CheckItem* checkItem( int row );
76 DueTextItem* dueItem( int row );
77 QTimer *m_menuTimer; 79 QTimer *m_menuTimer;
78 QMap<int, CheckItem*> m_cache;
79 bool m_enablePaint:1; 80 bool m_enablePaint:1;
80 81
81private slots: 82private slots:
82 void slotShowMenu(); 83 void slotShowMenu();
83 void slotClicked(int, int, int, 84 void slotClicked(int, int, int,
84 const QPoint& ); 85 const QPoint& );
85 void slotPressed(int, int, int, 86 void slotPressed(int, int, int,
86 const QPoint& ); 87 const QPoint& );
87 void slotValueChanged(int, int); 88 void slotValueChanged(int, int);
88 void slotCurrentChanged(int, int ); 89 void slotCurrentChanged(int, int );
89 }; 90 };
90 inline void TableView::insertTodo( const OTodo& event, int row ) {
91
92
93 QString sortKey = (char) ( (event.isCompleted() ? 'a' : 'A' )
94 + event.priority() )
95 + Qtopia::buildSortKey( event.description() );
96 CheckItem *chk = new CheckItem( this, sortKey, event.uid(), event.categories() );
97 chk->setChecked( event.isCompleted() );
98
99 ComboItem *cmb = new ComboItem(this, QTableItem::WhenCurrent );
100 cmb->setText( QString::number( event.priority() ) );
101
102 QString sum = event.summary();
103 QTableItem* ti = new TodoTextItem( this, sum.isEmpty() ?
104 event.description().left(40).simplifyWhiteSpace() :
105 sum );
106 ti->setReplaceable( FALSE );
107
108 DueTextItem *due = new DueTextItem(this, event );
109
110 setItem( row, 0, chk );
111 setItem( row, 1, cmb );
112 setItem( row, 2, ti );
113 setItem( row, 3, due );
114
115 m_cache.insert( event.uid(), chk );
116 }
117}; 91};
118 92
119#endif 93#endif
diff --git a/core/pim/todo/todoview.h b/core/pim/todo/todoview.h
index 81ace3a..9408ef1 100644
--- a/core/pim/todo/todoview.h
+++ b/core/pim/todo/todoview.h
@@ -1,188 +1,188 @@
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#ifndef TODO_VIEW_H 29#ifndef TODO_VIEW_H
30#define TODO_VIEW_H 30#define TODO_VIEW_H
31 31
32#include <qarray.h> 32#include <qarray.h>
33#include <qstring.h> 33#include <qstring.h>
34#include <qvaluelist.h> 34#include <qvaluelist.h>
35#include <qwidget.h> 35#include <qwidget.h>
36 36
37#include <opie/otodoaccess.h> 37#include <opie/otodoaccess.h>
38 38
39#include "smalltodo.h" 39#include "smalltodo.h"
40 40
41 41
42namespace Todo { 42namespace Todo {
43 43
44 /** 44 /**
45 * According to tronical it's not possible 45 * According to tronical it's not possible
46 * to have Q_OBJECT in a template at all 46 * to have Q_OBJECT in a template at all
47 * so this is a hack widget not meant 47 * so this is a hack widget not meant
48 * to be public 48 * to be public
49 */ 49 */
50 class InternQtHack : public QObject { 50 class InternQtHack : public QObject {
51 Q_OBJECT 51 Q_OBJECT
52 public: 52 public:
53 InternQtHack() : QObject() {}; 53 InternQtHack() : QObject() {};
54 void emitShow(int uid) { emit showTodo(uid); } 54 void emitShow(int uid) { emit showTodo(uid); }
55 void emitEdit(int uid) { emit edit(uid ); } 55 void emitEdit(int uid) { emit edit(uid ); }
56 void emitUpdate( int uid, 56 void emitUpdate( int uid,
57 const SmallTodo& to) { 57 const SmallTodo& to) {
58 emit update(uid, to ); 58 emit update(uid, to );
59 } 59 }
60 void emitUpdate( int uid, 60 void emitUpdate( int uid,
61 const OTodo& ev ){ 61 const OTodo& ev ){
62 emit update(uid, ev ); 62 emit update(uid, ev );
63 } 63 }
64 void emitRemove( int uid ) { 64 void emitRemove( int uid ) {
65 emit remove( uid ); 65 emit remove( uid );
66 } 66 }
67 void emitUpdate( QWidget* wid ) { 67 void emitUpdate( QWidget* wid ) {
68 emit update( wid ); 68 emit update( wid );
69 } 69 }
70 signals: 70 signals:
71 void showTodo(int uid ); 71 void showTodo(int uid );
72 void edit(int uid ); 72 void edit(int uid );
73 void update( int uid, const Todo::SmallTodo& ); 73 void update( int uid, const Todo::SmallTodo& );
74 void update( int uid, const OTodo& ); 74 void update( int uid, const OTodo& );
75 /* sorry you need to cast */; 75 /* sorry you need to cast */;
76 void update( QWidget* wid ); 76 void update( QWidget* wid );
77 void remove( int uid ); 77 void remove( int uid );
78 78
79 }; 79 };
80 class MainWindow; 80 class MainWindow;
81 81
82 /** 82 /**
83 * due to inheretince problems we need this base class 83 * due to inheretince problems we need this base class
84 */ 84 */
85 class ViewBase { 85 class ViewBase {
86 public: 86 public:
87 virtual QWidget* widget() = 0; 87 virtual QWidget* widget() = 0;
88 virtual QString type()const = 0; 88 virtual QString type()const = 0;
89 virtual int current() = 0; 89 virtual int current() = 0;
90 virtual QString currentRepresentation() = 0; 90 virtual QString currentRepresentation() = 0;
91 virtual void showOverDue( bool ) = 0; 91 virtual void showOverDue( bool ) = 0;
92 92
93 /* 93 /*
94 * update the view 94 * update the view
95 */ 95 */
96 virtual void updateView() = 0; 96 virtual void updateView() = 0;
97 97
98 virtual void addEvent( const OTodo& ) = 0; 98 virtual void addEvent( const OTodo& ) = 0;
99 virtual void replaceEvent( const OTodo& ) = 0; 99 virtual void replaceEvent( const OTodo& ) = 0;
100 virtual void removeEvent( int uid ) = 0; 100 virtual void removeEvent( int uid ) = 0;
101 virtual void setShowCompleted( bool ) = 0; 101 virtual void setShowCompleted( bool ) = 0;
102 virtual void setShowDeadline( bool ) = 0; 102 virtual void setShowDeadline( bool ) = 0;
103 virtual void setShowCategory( const QString& = QString::null ) = 0; 103 virtual void setShowCategory( const QString& = QString::null ) = 0;
104 virtual void clear() = 0; 104 virtual void clear() = 0;
105 virtual QArray<int> completed() = 0; 105/* virtual QArray<int> completed() = 0; */
106 virtual void newDay() = 0; 106 virtual void newDay() = 0;
107 107
108 virtual void connectShow( QObject*, const char* ) = 0; 108 virtual void connectShow( QObject*, const char* ) = 0;
109 virtual void connectEdit( QObject*, const char* ) = 0; 109 virtual void connectEdit( QObject*, const char* ) = 0;
110 virtual void connectUpdateSmall( QObject*, const char* ) = 0; 110 virtual void connectUpdateSmall( QObject*, const char* ) = 0;
111 virtual void connectUpdateBig( QObject*, const char* ) = 0; 111 virtual void connectUpdateBig( QObject*, const char* ) = 0;
112 virtual void connectUpdateView( QObject*, const char*) = 0; 112 virtual void connectUpdateView( QObject*, const char*) = 0;
113 virtual void connectRemove( QObject*, const char* ) = 0; 113 virtual void connectRemove( QObject*, const char* ) = 0;
114 114
115 }; 115 };
116 116
117 /** 117 /**
118 * A base class for all TodoView which are showing 118 * A base class for all TodoView which are showing
119 * a list of todos. 119 * a list of todos.
120 * Either in a QTable, QListView or any other QWidget 120 * Either in a QTable, QListView or any other QWidget
121 * derived class 121 * derived class
122 * Through the MainWindow( dispatcher ) one can access 122 * Through the MainWindow( dispatcher ) one can access
123 * the relevant informations 123 * the relevant informations
124 * 124 *
125 * It's not possible to have signal and slots from within 125 * It's not possible to have signal and slots from within
126 * templates this way you've to register for a signal 126 * templates this way you've to register for a signal
127 */ 127 */
128 class TodoView : public ViewBase{ 128 class TodoView : public ViewBase{
129 129
130 public: 130 public:
131 /** 131 /**
132 * c'tor 132 * c'tor
133 */ 133 */
134 TodoView( MainWindow* win ); 134 TodoView( MainWindow* win );
135 135
136 /** 136 /**
137 *d'tor 137 *d'tor
138 */ 138 */
139 virtual ~TodoView(); 139 virtual ~TodoView();
140 140
141 /* connect to the show signal */ 141 /* connect to the show signal */
142 void connectShow(QObject* obj, 142 void connectShow(QObject* obj,
143 const char* slot ); 143 const char* slot );
144 144
145 /* connect to edit */ 145 /* connect to edit */
146 void connectEdit( QObject* obj, 146 void connectEdit( QObject* obj,
147 const char* slot ); 147 const char* slot );
148 void connectUpdateSmall( QObject* obj, 148 void connectUpdateSmall( QObject* obj,
149 const char* slot ); 149 const char* slot );
150 void connectUpdateBig( QObject* obj, 150 void connectUpdateBig( QObject* obj,
151 const char* slot ) ; 151 const char* slot ) ;
152 void connectUpdateView( QObject* obj, 152 void connectUpdateView( QObject* obj,
153 const char* slot ); 153 const char* slot );
154 void connectRemove( QObject* obj, 154 void connectRemove( QObject* obj,
155 const char* slot ); 155 const char* slot );
156 protected: 156 protected:
157 MainWindow* todoWindow(); 157 MainWindow* todoWindow();
158 OTodo event(int uid ); 158 OTodo event(int uid );
159 OTodoAccess::List list(); 159 OTodoAccess::List list();
160 OTodoAccess::List sorted(); 160 OTodoAccess::List sorted();
161 void sort(); 161 void sort();
162 void sort(int sort ); 162 void sort(int sort );
163 void setSortOrder( int order ); 163 void setSortOrder( int order );
164 void setAscending( bool ); 164 void setAscending( bool );
165 165
166 /* 166 /*
167 These things needs to be implemented 167 These things needs to be implemented
168 in a implementation 168 in a implementation
169 signals: 169 signals:
170 */ 170 */
171 protected: 171 protected:
172 void showTodo( int uid ) { hack->emitShow(uid); } 172 void showTodo( int uid ) { hack->emitShow(uid); }
173 void edit( int uid ) { hack->emitEdit(uid); } 173 void edit( int uid ) { hack->emitEdit(uid); }
174 void update(int uid, const SmallTodo& to ); 174 void update(int uid, const SmallTodo& to );
175 void update(int uid, const OTodo& ev); 175 void update(int uid, const OTodo& ev);
176 void remove( int uid ) { 176 void remove( int uid ) {
177 hack->emitRemove( uid ); 177 hack->emitRemove( uid );
178 } 178 }
179 private: 179 private:
180 InternQtHack* hack; 180 InternQtHack* hack;
181 MainWindow *m_main; 181 MainWindow *m_main;
182 OTodoAccess::List m_sort; 182 OTodoAccess::List m_sort;
183 bool m_asc : 1; 183 bool m_asc : 1;
184 int m_sortOrder; 184 int m_sortOrder;
185 }; 185 };
186}; 186};
187 187
188#endif 188#endif