summaryrefslogtreecommitdiff
authorzecke <zecke>2002-03-21 00:26:39 (UTC)
committer zecke <zecke>2002-03-21 00:26:39 (UTC)
commit8bfe366ce8667addc539f11fc560250c306340ae (patch) (unidiff)
tree4b890a47d86621d3e1f0aacde2485457862f02c8
parente8f15a98c611b0c6030e8210672b249b42107526 (diff)
downloadopie-8bfe366ce8667addc539f11fc560250c306340ae.zip
opie-8bfe366ce8667addc539f11fc560250c306340ae.tar.gz
opie-8bfe366ce8667addc539f11fc560250c306340ae.tar.bz2
Move todolist to tododb
Please test todolist
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--core/pim/todo/mainwindow.cpp27
-rw-r--r--core/pim/todo/todo.pro2
-rw-r--r--core/pim/todo/todoentryimpl.cpp53
-rw-r--r--core/pim/todo/todoentryimpl.h8
-rw-r--r--core/pim/todo/todotable.cpp274
-rw-r--r--core/pim/todo/todotable.h21
-rw-r--r--libopie/todoevent.cpp22
-rw-r--r--libopie/todoevent.h3
8 files changed, 134 insertions, 276 deletions
diff --git a/core/pim/todo/mainwindow.cpp b/core/pim/todo/mainwindow.cpp
index 6709811..f3afa5f 100644
--- a/core/pim/todo/mainwindow.cpp
+++ b/core/pim/todo/mainwindow.cpp
@@ -1,470 +1,475 @@
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#define QTOPIA_INTERNAL_FD 21#define QTOPIA_INTERNAL_FD
22 22
23#include "mainwindow.h" 23#include "mainwindow.h"
24#include "todoentryimpl.h" 24#include "todoentryimpl.h"
25#include "todotable.h" 25#include "todotable.h"
26 26
27#include <opie/tododb.h>
28#include <opie/todovcalresource.h>
29
27#include <qpe/qpeapplication.h> 30#include <qpe/qpeapplication.h>
28#include <qpe/config.h> 31#include <qpe/config.h>
29#include <qpe/finddialog.h> 32#include <qpe/finddialog.h>
30#include <qpe/global.h> 33#include <qpe/global.h>
31#include <qpe/ir.h> 34#include <qpe/ir.h>
32#include <qpe/qpemenubar.h> 35#include <qpe/qpemenubar.h>
33#include <qpe/qpemessagebox.h> 36#include <qpe/qpemessagebox.h>
34#include <qpe/resource.h> 37#include <qpe/resource.h>
35#include <qpe/task.h> 38//#include <qpe/task.h>
36#include <qpe/qpetoolbar.h> 39#include <qpe/qpetoolbar.h>
37 40
38#include <qaction.h> 41#include <qaction.h>
39#include <qarray.h> 42#include <qarray.h>
40#include <qdatastream.h> 43#include <qdatastream.h>
41#include <qdatetime.h> 44#include <qdatetime.h>
42#include <qfile.h> 45#include <qfile.h>
43#include <qmessagebox.h> 46#include <qmessagebox.h>
44#include <qpopupmenu.h> 47#include <qpopupmenu.h>
45 48
46#include <sys/stat.h> 49#include <sys/stat.h>
47#include <sys/types.h> 50#include <sys/types.h>
48#include <fcntl.h> 51#include <fcntl.h>
49#include <unistd.h> 52#include <unistd.h>
50 53
51#include <stdlib.h> 54#include <stdlib.h>
52 55
53static QString todolistXMLFilename() 56static QString todolistXMLFilename()
54{ 57{
55 return Global::applicationFileName("todolist","todolist.xml"); 58 return Global::applicationFileName("todolist","todolist.xml");
56} 59}
57 60
58static QString categoriesXMLFilename() 61static QString categoriesXMLFilename()
59{ 62{
60 return Global::applicationFileName("todolist","categories.xml"); 63 return Global::applicationFileName("todolist","categories.xml");
61} 64}
62 65
63TodoWindow::TodoWindow( QWidget *parent, const char *name, WFlags f = 0 ) : 66TodoWindow::TodoWindow( QWidget *parent, const char *name, WFlags f = 0 ) :
64 QMainWindow( parent, name, f ), syncing(FALSE) 67 QMainWindow( parent, name, f ), syncing(FALSE)
65{ 68{
66// QTime t; 69// QTime t;
67// t.start(); 70// t.start();
68 71
69 setCaption( tr("Todo") ); 72 setCaption( tr("Todo") );
70 QString str; 73 QString str;
71 table = new TodoTable( this ); 74 table = new TodoTable( this );
72 table->setColumnWidth( 2, 10 ); 75 table->setColumnWidth( 2, 10 );
73 table->setPaintingEnabled( FALSE ); 76 table->setPaintingEnabled( FALSE );
74 table->setUpdatesEnabled( FALSE ); 77 table->setUpdatesEnabled( FALSE );
75 table->viewport()->setUpdatesEnabled( FALSE ); 78 table->viewport()->setUpdatesEnabled( FALSE );
76 79
77 { 80 {
78 str = todolistXMLFilename(); 81 str = todolistXMLFilename();
79 if ( str.isNull() ) 82 if ( str.isNull() )
80 QMessageBox::critical( this, 83 QMessageBox::critical( this,
81 tr("Out of Space"), 84 tr("Out of Space"),
82 tr("Unable to create startup files\n" 85 tr("Unable to create startup files\n"
83 "Free up some space\n" 86 "Free up some space\n"
84 "before you enter any data") ); 87 "before you enter any data") );
85 else 88 else
86 table->load( str ); 89 table->load( str );
87 } 90 }
88 91
89 // repeat for categories... 92 // repeat for categories...
90 str = categoriesXMLFilename(); 93 str = categoriesXMLFilename();
91 if ( str.isNull() ) 94 if ( str.isNull() )
92 QMessageBox::critical( this, 95 QMessageBox::critical( this,
93 tr( "Out of Space" ), 96 tr( "Out of Space" ),
94 tr( "Unable to create startup files\n" 97 tr( "Unable to create startup files\n"
95 "Free up some space\n" 98 "Free up some space\n"
96 "before you enter any data") ); 99 "before you enter any data") );
97 100
98 setCentralWidget( table ); 101 setCentralWidget( table );
99 setToolBarsMovable( FALSE ); 102 setToolBarsMovable( FALSE );
100 103
101// qDebug("after load: t=%d", t.elapsed() ); 104// qDebug("after load: t=%d", t.elapsed() );
102 105
103 Config config( "todo" ); 106 Config config( "todo" );
104 config.setGroup( "View" ); 107 config.setGroup( "View" );
105 bool complete = config.readBoolEntry( "ShowComplete", true ); 108 bool complete = config.readBoolEntry( "ShowComplete", true );
106 table->setShowCompleted( complete ); 109 table->setShowCompleted( complete );
107 QString category = config.readEntry( "Category", QString::null ); 110 QString category = config.readEntry( "Category", QString::null );
108 table->setShowCategory( category ); 111 table->setShowCategory( category );
109 112
110 QPEToolBar *bar = new QPEToolBar( this ); 113 QPEToolBar *bar = new QPEToolBar( this );
111 bar->setHorizontalStretchable( TRUE ); 114 bar->setHorizontalStretchable( TRUE );
112 115
113 QPEMenuBar *mb = new QPEMenuBar( bar ); 116 QPEMenuBar *mb = new QPEMenuBar( bar );
114 117
115 catMenu = new QPopupMenu( this ); 118 catMenu = new QPopupMenu( this );
116 QPopupMenu *edit = new QPopupMenu( this ); 119 QPopupMenu *edit = new QPopupMenu( this );
117 contextMenu = new QPopupMenu( this ); 120 contextMenu = new QPopupMenu( this );
118 121
119 bar = new QPEToolBar( this ); 122 bar = new QPEToolBar( this );
120 123
121 QAction *a = new QAction( tr( "New Task" ), Resource::loadPixmap( "new" ), 124 QAction *a = new QAction( tr( "New Task" ), Resource::loadPixmap( "new" ),
122 QString::null, 0, this, 0 ); 125 QString::null, 0, this, 0 );
123 connect( a, SIGNAL( activated() ), 126 connect( a, SIGNAL( activated() ),
124 this, SLOT( slotNew() ) ); 127 this, SLOT( slotNew() ) );
125 a->addTo( bar ); 128 a->addTo( bar );
126 a->addTo( edit ); 129 a->addTo( edit );
127 130
128 a = new QAction( tr( "Edit" ), Resource::loadIconSet( "edit" ), 131 a = new QAction( tr( "Edit" ), Resource::loadIconSet( "edit" ),
129 QString::null, 0, this, 0 ); 132 QString::null, 0, this, 0 );
130 connect( a, SIGNAL( activated() ), 133 connect( a, SIGNAL( activated() ),
131 this, SLOT( slotEdit() ) ); 134 this, SLOT( slotEdit() ) );
132 a->addTo( bar ); 135 a->addTo( bar );
133 a->addTo( edit ); 136 a->addTo( edit );
134 a->addTo( contextMenu ); 137 a->addTo( contextMenu );
135 a->setEnabled( FALSE ); 138 a->setEnabled( FALSE );
136 editAction = a; 139 editAction = a;
137 140
138 a = new QAction( tr( "Delete" ), Resource::loadIconSet( "trash" ), 141 a = new QAction( tr( "Delete" ), Resource::loadIconSet( "trash" ),
139 QString::null, 0, this, 0 ); 142 QString::null, 0, this, 0 );
140 connect( a, SIGNAL( activated() ), 143 connect( a, SIGNAL( activated() ),
141 this, SLOT( slotDelete() ) ); 144 this, SLOT( slotDelete() ) );
142 a->addTo( bar ); 145 a->addTo( bar );
143 a->addTo( edit ); 146 a->addTo( edit );
144 a->addTo( contextMenu ); 147 a->addTo( contextMenu );
145 a->setEnabled( FALSE ); 148 a->setEnabled( FALSE );
146 deleteAction = a; 149 deleteAction = a;
147 150
148 if ( Ir::supported() ) { 151 if ( Ir::supported() ) {
149 a = new QAction( tr( "Beam" ), Resource::loadPixmap( "beam" ), 152 a = new QAction( tr( "Beam" ), Resource::loadPixmap( "beam" ),
150 QString::null, 0, this, 0 ); 153 QString::null, 0, this, 0 );
151 connect( a, SIGNAL( activated() ), 154 connect( a, SIGNAL( activated() ),
152 this, SLOT( slotBeam() ) ); 155 this, SLOT( slotBeam() ) );
153 a->addTo( edit ); 156 a->addTo( edit );
154 a->addTo( bar ); 157 a->addTo( bar );
155 } 158 }
156 159
157 a = new QAction( tr( "Find" ), Resource::loadIconSet( "mag" ), 160 a = new QAction( tr( "Find" ), Resource::loadIconSet( "mag" ),
158 QString::null, 0, this, 0 ); 161 QString::null, 0, this, 0 );
159 connect( a, SIGNAL( activated() ), 162 connect( a, SIGNAL( activated() ),
160 this, SLOT( slotFind() ) ); 163 this, SLOT( slotFind() ) );
161 a->addTo( bar ); 164 a->addTo( bar );
162 a->addTo( edit ); 165 a->addTo( edit );
163 if ( table->numRows() ) 166 if ( table->numRows() )
164 a->setEnabled( TRUE ); 167 a->setEnabled( TRUE );
165 else 168 else
166 a->setEnabled( FALSE ); 169 a->setEnabled( FALSE );
167 170
168 //a->setEnabled( FALSE ); 171 //a->setEnabled( FALSE );
169 findAction = a; 172 findAction = a;
170// qDebug("mainwindow #2: t=%d", t.elapsed() ); 173// qDebug("mainwindow #2: t=%d", t.elapsed() );
171 174
172 completedAction = new QAction( QString::null, tr("Completed tasks"), 0, this, 0, TRUE ); 175 completedAction = new QAction( QString::null, tr("Completed tasks"), 0, this, 0, TRUE );
173 176
174 catMenu->setCheckable( true ); 177 catMenu->setCheckable( true );
175 populateCategories(); 178 populateCategories();
176 179
177 mb->insertItem( tr( "Task" ), edit ); 180 mb->insertItem( tr( "Task" ), edit );
178 mb->insertItem( tr( "View" ), catMenu ); 181 mb->insertItem( tr( "View" ), catMenu );
179 182
180 resize( 200, 300 ); 183 resize( 200, 300 );
181 if ( table->numRows() > 0 ) 184 if ( table->numRows() > 0 )
182 currentEntryChanged( 0, 0 ); 185 currentEntryChanged( 0, 0 );
183 connect( table, SIGNAL( signalEdit() ), 186 connect( table, SIGNAL( signalEdit() ),
184 this, SLOT( slotEdit() ) ); 187 this, SLOT( slotEdit() ) );
185 connect( table, SIGNAL(signalShowMenu(const QPoint &)), 188 connect( table, SIGNAL(signalShowMenu(const QPoint &)),
186 this, SLOT( slotShowPopup(const QPoint &)) ); 189 this, SLOT( slotShowPopup(const QPoint &)) );
187 190
188// qDebug("mainwindow #3: t=%d", t.elapsed() ); 191// qDebug("mainwindow #3: t=%d", t.elapsed() );
189 table->updateVisible(); 192 table->updateVisible();
190 table->setUpdatesEnabled( TRUE ); 193 table->setUpdatesEnabled( TRUE );
191 table->setPaintingEnabled( TRUE ); 194 table->setPaintingEnabled( TRUE );
192 table->viewport()->setUpdatesEnabled( TRUE ); 195 table->viewport()->setUpdatesEnabled( TRUE );
193 196
194 connect( completedAction, SIGNAL( toggled(bool) ), this, SLOT( showCompleted(bool) ) ); 197 connect( completedAction, SIGNAL( toggled(bool) ), this, SLOT( showCompleted(bool) ) );
195 connect( catMenu, SIGNAL(activated(int)), this, SLOT(setCategory(int)) ); 198 connect( catMenu, SIGNAL(activated(int)), this, SLOT(setCategory(int)) );
196 connect( table, SIGNAL( currentChanged( int, int ) ), 199 connect( table, SIGNAL( currentChanged( int, int ) ),
197 this, SLOT( currentEntryChanged( int, int ) ) ); 200 this, SLOT( currentEntryChanged( int, int ) ) );
198 201
199// qDebug("done: t=%d", t.elapsed() ); 202// qDebug("done: t=%d", t.elapsed() );
200} 203}
201 204
202void TodoWindow::slotNew() 205void TodoWindow::slotNew()
203{ 206{
204 if(syncing) { 207 if(syncing) {
205 QMessageBox::warning(this, tr("Todo"), 208 QMessageBox::warning(this, tr("Todo"),
206 tr("Can not edit data, currently syncing")); 209 tr("Can not edit data, currently syncing"));
207 return; 210 return;
208 } 211 }
209 212
210 int id; 213 int id;
211 id = -1; 214 id = -1;
212 QArray<int> ids; 215 QArray<int> ids;
213 ids = table->currentEntry().categories(); 216 ids = table->currentEntry().categories();
214 if ( ids.count() ) 217 if ( ids.count() )
215 id = ids[0]; 218 id = ids[0];
216 NewTaskDialog e( id, this, 0, TRUE ); 219 NewTaskDialog e( id, this, 0, TRUE );
217 220
218 Task todo; 221 ToDoEvent todo;
219 222
220#if defined(Q_WS_QWS) || defined(_WS_QWS_) 223#if defined(Q_WS_QWS) || defined(_WS_QWS_)
221 e.showMaximized(); 224 e.showMaximized();
222#endif 225#endif
223 int ret = e.exec(); 226 int ret = e.exec();
224 227 qWarning("finished" );
225 if ( ret == QDialog::Accepted ) { 228 if ( ret == QDialog::Accepted ) {
226 table->setPaintingEnabled( false ); 229 table->setPaintingEnabled( false );
227 todo = e.todoEntry(); 230 todo = e.todoEntry();
228 todo.assignUid(); 231 //todo.assignUid();
229 table->addEntry( todo ); 232 table->addEntry( todo );
230 table->setPaintingEnabled( true ); 233 table->setPaintingEnabled( true );
231 findAction->setEnabled( TRUE ); 234 findAction->setEnabled( TRUE );
232 } 235 }
233 // I'm afraid we must call this every time now, otherwise 236 // I'm afraid we must call this every time now, otherwise
234 // spend expensive time comparing all these strings... 237 // spend expensive time comparing all these strings...
235 populateCategories(); 238 populateCategories();
236} 239}
237 240
238TodoWindow::~TodoWindow() 241TodoWindow::~TodoWindow()
239{ 242{
240} 243}
241 244
242void TodoWindow::slotDelete() 245void TodoWindow::slotDelete()
243{ 246{
244 if(syncing) { 247 if(syncing) {
245 QMessageBox::warning(this, tr("Todo"), 248 QMessageBox::warning(this, tr("Todo"),
246 tr("Can not edit data, currently syncing")); 249 tr("Can not edit data, currently syncing"));
247 return; 250 return;
248 } 251 }
249 252
250 if ( table->currentRow() == -1 ) 253 if ( table->currentRow() == -1 )
251 return; 254 return;
252 255
253 QString strName = table->text( table->currentRow(), 2 ).left( 30 ); 256 QString strName = table->text( table->currentRow(), 2 ).left( 30 );
254 257
255 if ( !QPEMessageBox::confirmDelete( this, tr( "Todo" ), strName ) ) 258 if ( !QPEMessageBox::confirmDelete( this, tr( "Todo" ), strName ) )
256 return; 259 return;
257 260
258 261
259 262
260 table->setPaintingEnabled( false ); 263 table->setPaintingEnabled( false );
261 table->removeCurrentEntry(); 264 table->removeCurrentEntry();
262 table->setPaintingEnabled( true ); 265 table->setPaintingEnabled( true );
263 266
264 if ( table->numRows() == 0 ) { 267 if ( table->numRows() == 0 ) {
265 currentEntryChanged( -1, 0 ); 268 currentEntryChanged( -1, 0 );
266 findAction->setEnabled( FALSE ); 269 findAction->setEnabled( FALSE );
267 } 270 }
268} 271}
269 272
270void TodoWindow::slotEdit() 273void TodoWindow::slotEdit()
271{ 274{
272 if(syncing) { 275 if(syncing) {
273 QMessageBox::warning(this, tr("Todo"), 276 QMessageBox::warning(this, tr("Todo"),
274 tr("Can not edit data, currently syncing")); 277 tr("Can not edit data, currently syncing"));
275 return; 278 return;
276 } 279 }
277 280
278 Task todo = table->currentEntry(); 281 ToDoEvent todo = table->currentEntry();
279 282
280 NewTaskDialog e( todo, this, 0, TRUE ); 283 NewTaskDialog e( todo, this, 0, TRUE );
281 e.setCaption( tr( "Edit Task" ) ); 284 e.setCaption( tr( "Edit Task" ) );
282 285
283#if defined(Q_WS_QWS) || defined(_WS_QWS_) 286#if defined(Q_WS_QWS) || defined(_WS_QWS_)
284 e.showMaximized(); 287 e.showMaximized();
285#endif 288#endif
286 int ret = e.exec(); 289 int ret = e.exec();
287 290
288 if ( ret == QDialog::Accepted ) { 291 if ( ret == QDialog::Accepted ) {
289 table->setPaintingEnabled( false ); 292 table->setPaintingEnabled( false );
290 todo = e.todoEntry(); 293 todo = e.todoEntry();
291 table->replaceCurrentEntry( todo ); 294 table->replaceCurrentEntry( todo );
292 table->setPaintingEnabled( true ); 295 table->setPaintingEnabled( true );
293 } 296 }
294 populateCategories(); 297 populateCategories();
295 298
296} 299}
297 300
298void TodoWindow::slotShowPopup( const QPoint &p ) 301void TodoWindow::slotShowPopup( const QPoint &p )
299{ 302{
300 contextMenu->popup( p ); 303 contextMenu->popup( p );
301} 304}
302 305
303void TodoWindow::showCompleted( bool s ) 306void TodoWindow::showCompleted( bool s )
304{ 307{
305 if ( !table->isUpdatesEnabled() ) 308 if ( !table->isUpdatesEnabled() )
306 return; 309 return;
307 table->setPaintingEnabled( false ); 310 table->setPaintingEnabled( false );
308 table->setShowCompleted( s ); 311 table->setShowCompleted( s );
309 table->setPaintingEnabled( true ); 312 table->setPaintingEnabled( true );
310} 313}
311 314
312void TodoWindow::currentEntryChanged( int r, int ) 315void TodoWindow::currentEntryChanged( int r, int )
313{ 316{
314 if ( r != -1 && table->rowHeight( r ) > 0 ) { 317 if ( r != -1 && table->rowHeight( r ) > 0 ) {
315 editAction->setEnabled( TRUE ); 318 editAction->setEnabled( TRUE );
316 deleteAction->setEnabled( TRUE ); 319 deleteAction->setEnabled( TRUE );
317 } else { 320 } else {
318 editAction->setEnabled( FALSE ); 321 editAction->setEnabled( FALSE );
319 deleteAction->setEnabled( FALSE ); 322 deleteAction->setEnabled( FALSE );
320 } 323 }
321} 324}
322 325
323void TodoWindow::setCategory( int c ) 326void TodoWindow::setCategory( int c )
324{ 327{
325 if ( c <= 0 ) return; 328 if ( c <= 0 ) return;
326 if ( !table->isUpdatesEnabled() ) 329 if ( !table->isUpdatesEnabled() )
327 return; 330 return;
328 table->setPaintingEnabled( false ); 331 table->setPaintingEnabled( false );
329 for ( unsigned int i = 1; i < catMenu->count(); i++ ) 332 for ( unsigned int i = 1; i < catMenu->count(); i++ )
330 catMenu->setItemChecked( i, c == (int)i ); 333 catMenu->setItemChecked( i, c == (int)i );
331 if ( c == 1 ) { 334 if ( c == 1 ) {
332 table->setShowCategory( QString::null ); 335 table->setShowCategory( QString::null );
333 setCaption( tr("Todo") + " - " + tr( "All Categories" ) ); 336 setCaption( tr("Todo") + " - " + tr( "All Categories" ) );
334 } else if ( c == (int)catMenu->count() - 1 ) { 337 } else if ( c == (int)catMenu->count() - 1 ) {
335 table->setShowCategory( tr( "Unfiled" ) ); 338 table->setShowCategory( tr( "Unfiled" ) );
336 setCaption( tr("Todo") + " - " + tr( "Unfiled" ) ); 339 setCaption( tr("Todo") + " - " + tr( "Unfiled" ) );
337 } else { 340 } else {
338 QString cat = table->categories()[c - 2]; 341 QString cat = table->categories()[c - 2];
339 table->setShowCategory( cat ); 342 table->setShowCategory( cat );
340 setCaption( tr("Todo") + " - " + cat ); 343 setCaption( tr("Todo") + " - " + cat );
341 } 344 }
342 table->setPaintingEnabled( true ); 345 table->setPaintingEnabled( true );
343} 346}
344 347
345void TodoWindow::populateCategories() 348void TodoWindow::populateCategories()
346{ 349{
347 catMenu->clear(); 350 catMenu->clear();
348 351
349 completedAction->addTo( catMenu ); 352 completedAction->addTo( catMenu );
350 completedAction->setOn( table->showCompleted() ); 353 completedAction->setOn( table->showCompleted() );
351 354
352 int id, 355 int id, rememberId;
353 rememberId;
354 id = 1; 356 id = 1;
355 catMenu->insertItem( tr( "All Categories" ), id++ ); 357 catMenu->insertItem( tr( "All Categories" ), id++ );
356// catMenu->insertSeparator(); 358// catMenu->insertSeparator();
357 QStringList categories = table->categories(); 359 QStringList categories = table->categories();
358 categories.append( tr( "Unfiled" ) ); 360 categories.append( tr( "Unfiled" ) );
359 for ( QStringList::Iterator it = categories.begin(); 361 for ( QStringList::Iterator it = categories.begin();
360 it != categories.end(); ++it ) { 362 it != categories.end(); ++it ) {
361 catMenu->insertItem( *it, id ); 363 catMenu->insertItem( *it, id );
362 if ( *it == table->showCategory() ) 364 if ( *it == table->showCategory() )
363 rememberId = id; 365 rememberId = id;
364 ++id; 366 ++id;
365 } 367 }
366 if ( table->showCategory().isEmpty() ) 368 if ( table->showCategory().isEmpty() )
367 setCategory( 1 ); 369 setCategory( 1 );
368 else 370 else
369 setCategory( rememberId ); 371 setCategory( rememberId );
370} 372}
371 373
372void TodoWindow::reload() 374void TodoWindow::reload()
373{ 375{
374 table->clear(); 376 table->clear();
375 table->load( todolistXMLFilename() ); 377 table->load( todolistXMLFilename() );
376 syncing = FALSE; 378 syncing = FALSE;
377} 379}
378 380
379void TodoWindow::flush() 381void TodoWindow::flush()
380{ 382{
381 syncing = TRUE; 383 syncing = TRUE;
382 table->save( todolistXMLFilename() ); 384 table->save( todolistXMLFilename() );
383} 385}
384 386
385void TodoWindow::closeEvent( QCloseEvent *e ) 387void TodoWindow::closeEvent( QCloseEvent *e )
386{ 388{
387 if(syncing) { 389 if(syncing) {
388 /* no need to save if in the middle of syncing */ 390 /* no need to save if in the middle of syncing */
389 e->accept(); 391 e->accept();
390 return; 392 return;
391 } 393 }
392 394
393 if ( table->save( todolistXMLFilename() ) ) { 395 if ( table->save( todolistXMLFilename() ) ) {
394 e->accept(); 396 e->accept();
395 // repeat for categories... 397 // repeat for categories...
396 // if writing configs fail, it will emit an 398 // if writing configs fail, it will emit an
397 // error, but I feel that it is "ok" for us to exit 399 // error, but I feel that it is "ok" for us to exit
398 // espically since we aren't told if the write succeeded... 400 // espically since we aren't told if the write succeeded...
399 Config config( "todo" ); 401 Config config( "todo" );
400 config.setGroup( "View" ); 402 config.setGroup( "View" );
401 config.writeEntry( "ShowComplete", table->showCompleted() ); 403 config.writeEntry( "ShowComplete", table->showCompleted() );
402 config.writeEntry( "Category", table->showCategory() ); 404 config.writeEntry( "Category", table->showCategory() );
403 } else { 405 } else {
404 if ( QMessageBox::critical( this, tr("Out of space"), 406 if ( QMessageBox::critical( this, tr("Out of space"),
405 tr("Todo was unable\n" 407 tr("Todo was unable\n"
406 "to save your changes.\n" 408 "to save your changes.\n"
407 "Free up some space\n" 409 "Free up some space\n"
408 "and try again.\n" 410 "and try again.\n"
409 "\nQuit Anyway?"), 411 "\nQuit Anyway?"),
410 QMessageBox::Yes|QMessageBox::Escape, 412 QMessageBox::Yes|QMessageBox::Escape,
411 QMessageBox::No|QMessageBox::Default) 413 QMessageBox::No|QMessageBox::Default)
412 != QMessageBox::No ) 414 != QMessageBox::No )
413 e->accept(); 415 e->accept();
414 else 416 else
415 e->ignore(); 417 e->ignore();
416 } 418 }
417} 419}
418 420
419void TodoWindow::slotFind() 421void TodoWindow::slotFind()
420{ 422{
421 // put everything back to view all for searching... 423 // put everything back to view all for searching...
422 if ( !catMenu->isItemChecked( 0 ) ) 424 if ( !catMenu->isItemChecked( 0 ) )
423 setCategory( 0 ); 425 setCategory( 0 );
424 426
425 FindDialog dlg( "Todo List", this ); 427 FindDialog dlg( "Todo List", this );
426 QObject::connect( &dlg, 428 QObject::connect( &dlg,
427 SIGNAL(signalFindClicked(const QString &, 429 SIGNAL(signalFindClicked(const QString &,
428 bool, bool, int)), 430 bool, bool, int)),
429 table, 431 table,
430 SLOT(slotDoFind(const QString&, bool, bool, int)) ); 432 SLOT(slotDoFind(const QString&, bool, bool, int)) );
431 QObject::connect( table, SIGNAL(signalNotFound()), &dlg, 433 QObject::connect( table, SIGNAL(signalNotFound()), &dlg,
432 SLOT(slotNotFound()) ); 434 SLOT(slotNotFound()) );
433 QObject::connect( table, SIGNAL(signalWrapAround()), &dlg, 435 QObject::connect( table, SIGNAL(signalWrapAround()), &dlg,
434 SLOT(slotWrapAround()) ); 436 SLOT(slotWrapAround()) );
435 dlg.exec(); 437 dlg.exec();
436 if ( table->numSelections() ) 438 if ( table->numSelections() )
437 table->clearSelection(); 439 table->clearSelection();
438 table->clearFindRow(); 440 table->clearFindRow();
439} 441}
440 442
441 443
442void TodoWindow::setDocument( const QString &filename ) 444void TodoWindow::setDocument( const QString &filename )
443{ 445{
444 if ( filename.find(".vcs") != int(filename.length()) - 4 ) return; 446 if ( filename.find(".vcs") != int(filename.length()) - 4 ) return;
445 447
446 QValueList<Task> tl = Task::readVCalendar( filename ); 448 ToDoDB todoDB(filename, new ToDoVCalResource() );
447 for( QValueList<Task>::Iterator it = tl.begin(); it != tl.end(); ++it ) { 449 QValueList<ToDoEvent> tl = todoDB.rawToDos();
450 for( QValueList<ToDoEvent>::Iterator it = tl.begin(); it != tl.end(); ++it ) {
448 table->addEntry( *it ); 451 table->addEntry( *it );
449 } 452 }
450} 453}
451 454
452static const char * beamfile = "/tmp/obex/todo.vcs"; 455static const char * beamfile = "/tmp/obex/todo.vcs";
453 456
454void TodoWindow::slotBeam() 457void TodoWindow::slotBeam()
455{ 458{
456 unlink( beamfile ); // delete if exists 459 unlink( beamfile ); // delete if exists
457 Task c = table->currentEntry(); 460 ToDoEvent c = table->currentEntry();
458 mkdir("/tmp/obex/", 0755); 461 mkdir("/tmp/obex/", 0755);
459 Task::writeVCalendar( beamfile, c ); 462 ToDoDB todoDB( beamfile, new ToDoVCalResource() );
463 todoDB.addEvent( c );
464 todoDB.save();
460 Ir *ir = new Ir( this ); 465 Ir *ir = new Ir( this );
461 connect( ir, SIGNAL( done( Ir * ) ), this, SLOT( beamDone( Ir * ) ) ); 466 connect( ir, SIGNAL( done( Ir * ) ), this, SLOT( beamDone( Ir * ) ) );
462 QString description = c.description(); 467 QString description = c.description();
463 ir->send( beamfile, description, "text/x-vCalendar" ); 468 ir->send( beamfile, description, "text/x-vCalendar" );
464} 469}
465 470
466void TodoWindow::beamDone( Ir *ir ) 471void TodoWindow::beamDone( Ir *ir )
467{ 472{
468 delete ir; 473 delete ir;
469 unlink( beamfile ); 474 unlink( beamfile );
470} 475}
diff --git a/core/pim/todo/todo.pro b/core/pim/todo/todo.pro
index 18f70fe..7f9ddd5 100644
--- a/core/pim/todo/todo.pro
+++ b/core/pim/todo/todo.pro
@@ -1,20 +1,20 @@
1 TEMPLATE= app 1 TEMPLATE= app
2 CONFIG = qt warn_on release 2 CONFIG = qt warn_on release
3 DESTDIR = $(OPIEDIR)/bin 3 DESTDIR = $(OPIEDIR)/bin
4 HEADERS= mainwindow.h \ 4 HEADERS= mainwindow.h \
5 todotable.h \ 5 todotable.h \
6 todoentryimpl.h 6 todoentryimpl.h
7 SOURCES= main.cpp \ 7 SOURCES= main.cpp \
8 mainwindow.cpp \ 8 mainwindow.cpp \
9 todotable.cpp \ 9 todotable.cpp \
10 todoentryimpl.cpp 10 todoentryimpl.cpp
11 11
12 INTERFACES= todoentry.ui 12 INTERFACES= todoentry.ui
13 13
14 TARGET = todolist 14 TARGET = todolist
15INCLUDEPATH += $(OPIEDIR)/include 15INCLUDEPATH += $(OPIEDIR)/include
16 DEPENDPATH+= $(OPIEDIR)/include 16 DEPENDPATH+= $(OPIEDIR)/include
17LIBS += -lqpe 17LIBS += -lqpe -lopie
18 18
19TRANSLATIONS = ../i18n/de/todolist.ts 19TRANSLATIONS = ../i18n/de/todolist.ts
20TRANSLATIONS += ../i18n/pt_BR/todolist.ts 20TRANSLATIONS += ../i18n/pt_BR/todolist.ts
diff --git a/core/pim/todo/todoentryimpl.cpp b/core/pim/todo/todoentryimpl.cpp
index c957715..1dc1d44 100644
--- a/core/pim/todo/todoentryimpl.cpp
+++ b/core/pim/todo/todoentryimpl.cpp
@@ -1,142 +1,159 @@
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 "todoentryimpl.h" 21#include "todoentryimpl.h"
22 22
23#include <opie/todoevent.h>
24#include <opie/tododb.h>
25
23#include <qpe/categoryselect.h> 26#include <qpe/categoryselect.h>
24#include <qpe/datebookmonth.h> 27#include <qpe/datebookmonth.h>
25#include <qpe/global.h> 28#include <qpe/global.h>
26#include <qpe/imageedit.h> 29#include <qpe/imageedit.h>
27#include <qpe/task.h>
28#include <qpe/timestring.h> 30#include <qpe/timestring.h>
31#include <qpe/palmtoprecord.h>
29 32
30#include <qmessagebox.h> 33#include <qmessagebox.h>
31#include <qpopupmenu.h> 34#include <qpopupmenu.h>
32#include <qtoolbutton.h> 35#include <qtoolbutton.h>
33#include <qcombobox.h> 36#include <qcombobox.h>
34#include <qcheckbox.h> 37#include <qcheckbox.h>
35#include <qlineedit.h> 38#include <qlineedit.h>
36#include <qmultilineedit.h> 39#include <qmultilineedit.h>
37#include <qlabel.h> 40#include <qlabel.h>
38#include <qtimer.h> 41#include <qtimer.h>
39#include <qapplication.h> 42#include <qapplication.h>
40 43
41 44
42NewTaskDialog::NewTaskDialog( const Task& task, QWidget *parent, 45NewTaskDialog::NewTaskDialog( const ToDoEvent& task, QWidget *parent,
43 const char *name, bool modal, WFlags fl ) 46 const char *name, bool modal, WFlags fl )
44 : NewTaskDialogBase( parent, name, modal, fl ), 47 : NewTaskDialogBase( parent, name, modal, fl ),
45 todo( task ) 48 todo( task )
46{ 49{
47 todo.setCategories( task.categories() ); 50 qWarning("setting category" );
48 if ( todo.hasDueDate() ) 51 todo.setCategory( task.category() );
49 date = todo.dueDate(); 52 if ( todo.hasDate() )
53 date = todo.date();
50 else 54 else
51 date = QDate::currentDate(); 55 date = QDate::currentDate();
52 56
53 init(); 57 init();
54 comboPriority->setCurrentItem( task.priority() - 1 ); 58 comboPriority->setCurrentItem( task.priority() - 1 );
55 59
56 checkCompleted->setChecked( task.isCompleted() ); 60 checkCompleted->setChecked( task.isCompleted() );
57 checkDate->setChecked( task.hasDueDate() ); 61 checkDate->setChecked( task.hasDate() );
58 buttonDate->setText( TimeString::longDateString( date ) ); 62 buttonDate->setText( TimeString::longDateString( date ) );
59 63
60 txtTodo->setText( task.description() ); 64 txtTodo->setText( task.description() );
61} 65}
62 66
63/* 67/*
64 * Constructs a NewTaskDialog which is a child of 'parent', with the 68 * Constructs a NewTaskDialog which is a child of 'parent', with the
65 * name 'name' and widget flags set to 'f' 69 * name 'name' and widget flags set to 'f'
66 * 70 *
67 * The dialog will by default be modeless, unless you set 'modal' to 71 * The dialog will by default be modeless, unless you set 'modal' to
68 * TRUE to construct a modal dialog. 72 * TRUE to construct a modal dialog.
69 */ 73 */
70NewTaskDialog::NewTaskDialog( int id, QWidget* parent, const char* name, bool modal, 74NewTaskDialog::NewTaskDialog( int id, QWidget* parent, const char* name, bool modal,
71 WFlags fl ) 75 WFlags fl )
72 : NewTaskDialogBase( parent, name, modal, fl ), 76 : NewTaskDialogBase( parent, name, modal, fl ),
73 date( QDate::currentDate() ) 77 date( QDate::currentDate() )
74{ 78{
75 if ( id != -1 ) { 79 if ( id != -1 ) {
76 QArray<int> ids( 1 ); 80 QArray<int> ids( 1 );
77 ids[0] = id; 81 ids[0] = id;
78 todo.setCategories( ids ); 82 todo.setCategory( Qtopia::Record::idsToString( ids ) );
79 } 83 }
80 init(); 84 init();
81} 85}
82 86
83void NewTaskDialog::init() 87void NewTaskDialog::init()
84{ 88{
85 QPopupMenu *m1 = new QPopupMenu( this ); 89 QPopupMenu *m1 = new QPopupMenu( this );
86 picker = new DateBookMonth( m1, 0, TRUE ); 90 picker = new DateBookMonth( m1, 0, TRUE );
87 m1->insertItem( picker ); 91 m1->insertItem( picker );
88 buttonDate->setPopup( m1 ); 92 buttonDate->setPopup( m1 );
89 comboCategory->setCategories( todo.categories(), "Todo List", tr("Todo List") ); 93 comboCategory->setCategories( todo.categories(), "Todo List", tr("Todo List") );
90 94
91 connect( picker, SIGNAL( dateClicked( int, int, int ) ), 95 connect( picker, SIGNAL( dateClicked( int, int, int ) ),
92 this, SLOT( dateChanged( int, int, int ) ) ); 96 this, SLOT( dateChanged( int, int, int ) ) );
93 97
94 buttonDate->setText( TimeString::longDateString( date ) ); 98 buttonDate->setText( TimeString::longDateString( date ) );
95 picker->setDate( date.year(), date.month(), date.day() ); 99 picker->setDate( date.year(), date.month(), date.day() );
96} 100}
97 101
98/* 102/*
99 * Destroys the object and frees any allocated resources 103 * Destroys the object and frees any allocated resources
100 */ 104 */
101NewTaskDialog::~NewTaskDialog() 105NewTaskDialog::~NewTaskDialog()
102{ 106{
107 qWarning("d'tor" );
103 // no need to delete child widgets, Qt does it all for us 108 // no need to delete child widgets, Qt does it all for us
104} 109}
105void NewTaskDialog::dateChanged( int y, int m, int d ) 110void NewTaskDialog::dateChanged( int y, int m, int d )
106{ 111{
107 date = QDate( y, m, d ); 112 date = QDate( y, m, d );
108 buttonDate->setText( TimeString::longDateString( date ) ); 113 buttonDate->setText( TimeString::longDateString( date ) );
109} 114}
110 115
111/*! 116/*!
112*/ 117*/
113 118
114Task NewTaskDialog::todoEntry() 119ToDoEvent NewTaskDialog::todoEntry()
115{ 120{
116 todo.setDueDate( date, checkDate->isChecked() ); 121 qWarning("todoEntry()" );
117 if ( comboCategory->currentCategory() != -1 ) { 122 if( checkDate->isChecked() ){
118 todo.setCategories( comboCategory->currentCategories() ); 123 todo.setDate( date );
119 } 124 todo.setHasDate( true );
120 todo.setPriority( comboPriority->currentItem() + 1 ); 125 }else{
121 todo.setCompleted( checkCompleted->isChecked() ); 126 todo.setHasDate( false );
122 127 }
123 todo.setDescription( txtTodo->text() ); 128 qWarning("todoEntry::category()" );
124 129 if ( comboCategory->currentCategory() != -1 ) {
125 return todo; 130 QArray<int> arr = comboCategory->currentCategories();
131 int id = arr[0];
132 qWarning("id 0: %d",id );
133 todo.setCategory( Qtopia::Record::idsToString( arr ) );
134 qWarning("saving category");
135 }
136 todo.setPriority( comboPriority->currentItem() + 1 );
137 todo.setCompleted( checkCompleted->isChecked() );
138
139 todo.setDescription( txtTodo->text() );
140
141 return todo;
126} 142}
127 143
128 144
129/*! 145/*!
130 146
131*/ 147*/
132 148
133void NewTaskDialog::accept() 149void NewTaskDialog::accept()
134{ 150{
151 qWarning("accept" );
135 QString strText = txtTodo->text(); 152 QString strText = txtTodo->text();
136 if ( strText.isEmpty() ) { 153 if ( strText.isEmpty() ) {
137 // hmm... just decline it then, the user obviously didn't care about it 154 // hmm... just decline it then, the user obviously didn't care about it
138 QDialog::reject(); 155 QDialog::reject();
139 return; 156 return;
140 } 157 }
141 QDialog::accept(); 158 QDialog::accept();
142} 159}
diff --git a/core/pim/todo/todoentryimpl.h b/core/pim/todo/todoentryimpl.h
index 932d66e..6407eb4 100644
--- a/core/pim/todo/todoentryimpl.h
+++ b/core/pim/todo/todoentryimpl.h
@@ -1,61 +1,61 @@
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#ifndef NEWTASKDIALOG_H 21#ifndef NEWTASKDIALOG_H
22#define NEWTASKDIALOG_H 22#define NEWTASKDIALOG_H
23 23
24#include "todoentry.h" 24#include "todoentry.h"
25 25
26#include <qpe/task.h> 26#include <opie/todoevent.h>
27 27
28#include <qdatetime.h> 28#include <qdatetime.h>
29#include <qpalette.h> 29#include <qpalette.h>
30 30
31class QLabel; 31class QLabel;
32class QTimer; 32class QTimer;
33class DateBookMonth; 33class DateBookMonth;
34 34
35class NewTaskDialog : public NewTaskDialogBase 35class NewTaskDialog : public NewTaskDialogBase
36{ 36{
37 Q_OBJECT 37 Q_OBJECT
38 38
39public: 39public:
40 NewTaskDialog( const Task &task, QWidget *parent = 0, const char* name = 0, 40 NewTaskDialog( const ToDoEvent &task, QWidget *parent = 0, const char* name = 0,
41 bool modal = FALSE, WFlags fl = 0 ); 41 bool modal = FALSE, WFlags fl = 0 );
42 NewTaskDialog( int id, QWidget* parent = 0, const char* name = 0, 42 NewTaskDialog( int id, QWidget* parent = 0, const char* name = 0,
43 bool modal = FALSE, WFlags fl = 0 ); 43 bool modal = FALSE, WFlags fl = 0 );
44 ~NewTaskDialog(); 44 ~NewTaskDialog();
45 45
46 Task todoEntry(); 46 ToDoEvent todoEntry();
47 47
48protected slots: 48protected slots:
49 void dateChanged( int y, int m, int d ); 49 void dateChanged( int y, int m, int d );
50 50
51protected: 51protected:
52 virtual void accept(); 52 virtual void accept();
53 53
54private: 54private:
55 void init(); 55 void init();
56 Task todo; 56 ToDoEvent todo;
57 QDate date; 57 QDate date;
58 DateBookMonth *picker; 58 DateBookMonth *picker;
59}; 59};
60 60
61#endif // NEWTASKDIALOG_H 61#endif // NEWTASKDIALOG_H
diff --git a/core/pim/todo/todotable.cpp b/core/pim/todo/todotable.cpp
index 77d3389..2bb95a2 100644
--- a/core/pim/todo/todotable.cpp
+++ b/core/pim/todo/todotable.cpp
@@ -1,859 +1,673 @@
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 "todotable.h" 21#include "todotable.h"
22 22
23#include <opie/tododb.h>
23#include <qpe/categoryselect.h> 24#include <qpe/categoryselect.h>
24#include <qpe/xmlreader.h> 25#include <qpe/xmlreader.h>
25 26
26#include <qasciidict.h> 27#include <qasciidict.h>
27#include <qcombobox.h> 28#include <qcombobox.h>
28#include <qfile.h> 29#include <qfile.h>
29#include <qpainter.h> 30#include <qpainter.h>
30#include <qtextcodec.h> 31#include <qtextcodec.h>
31#include <qtimer.h> 32#include <qtimer.h>
32#include <qdatetime.h> 33#include <qdatetime.h>
33 34
34#include <qcursor.h> 35#include <qcursor.h>
35#include <qregexp.h> 36#include <qregexp.h>
36 37
37#include <errno.h> 38#include <errno.h>
38#include <stdlib.h> 39#include <stdlib.h>
39 40
40 41
41 42
42static bool taskCompare( const Task &task, const QRegExp &r, int category ); 43static bool taskCompare( const ToDoEvent &task, const QRegExp &r, int category );
43 44
44static QString journalFileName(); 45static QString journalFileName();
45 46
46CheckItem::CheckItem( QTable *t, const QString &key ) 47CheckItem::CheckItem( QTable *t, const QString &key )
47 : QTableItem( t, Never, "" ), checked( FALSE ), sortKey( key ) 48 : QTableItem( t, Never, "" ), checked( FALSE ), sortKey( key )
48{ 49{
49} 50}
50 51
51QString CheckItem::key() const 52QString CheckItem::key() const
52{ 53{
53 return sortKey; 54 return sortKey;
54} 55}
55 56
56void CheckItem::setChecked( bool b ) 57void CheckItem::setChecked( bool b )
57{ 58{
58 checked = b; 59 checked = b;
59 table()->updateCell( row(), col() ); 60 table()->updateCell( row(), col() );
60} 61}
61 62
62void CheckItem::toggle() 63void CheckItem::toggle()
63{ 64{
64 TodoTable *parent = static_cast<TodoTable*>(table()); 65 TodoTable *parent = static_cast<TodoTable*>(table());
65 Task newTodo = parent->currentEntry(); 66 ToDoEvent newTodo = parent->currentEntry();
66 checked = !checked; 67 checked = !checked;
67 newTodo.setCompleted( checked ); 68 newTodo.setCompleted( checked );
68 table()->updateCell( row(), col() ); 69 table()->updateCell( row(), col() );
69 parent->replaceCurrentEntry( newTodo, true ); 70 parent->replaceCurrentEntry( newTodo, true );
70} 71}
71 72
72bool CheckItem::isChecked() const 73bool CheckItem::isChecked() const
73{ 74{
74 return checked; 75 return checked;
75} 76}
76 77
77static const int BoxSize = 10; 78static const int BoxSize = 10;
78 79
79void CheckItem::paint( QPainter *p, const QColorGroup &cg, const QRect &cr, 80void CheckItem::paint( QPainter *p, const QColorGroup &cg, const QRect &cr,
80 bool ) 81 bool )
81{ 82{
82 p->fillRect( 0, 0, cr.width(), cr.height(), cg.brush( QColorGroup::Base ) ); 83 p->fillRect( 0, 0, cr.width(), cr.height(), cg.brush( QColorGroup::Base ) );
83 84
84 int marg = ( cr.width() - BoxSize ) / 2; 85 int marg = ( cr.width() - BoxSize ) / 2;
85 int x = 0; 86 int x = 0;
86 int y = ( cr.height() - BoxSize ) / 2; 87 int y = ( cr.height() - BoxSize ) / 2;
87 p->setPen( QPen( cg.text() ) ); 88 p->setPen( QPen( cg.text() ) );
88 p->drawRect( x + marg, y, BoxSize, BoxSize ); 89 p->drawRect( x + marg, y, BoxSize, BoxSize );
89 p->drawRect( x + marg+1, y+1, BoxSize-2, BoxSize-2 ); 90 p->drawRect( x + marg+1, y+1, BoxSize-2, BoxSize-2 );
90 p->setPen( darkGreen ); 91 p->setPen( darkGreen );
91 x += 1; 92 x += 1;
92 y += 1; 93 y += 1;
93 if ( checked ) { 94 if ( checked ) {
94 QPointArray a( 7*2 ); 95 QPointArray a( 7*2 );
95 int i, xx, yy; 96 int i, xx, yy;
96 xx = x+1+marg; 97 xx = x+1+marg;
97 yy = y+2; 98 yy = y+2;
98 for ( i=0; i<3; i++ ) { 99 for ( i=0; i<3; i++ ) {
99 a.setPoint( 2*i, xx, yy ); 100 a.setPoint( 2*i, xx, yy );
100 a.setPoint( 2*i+1, xx, yy+2 ); 101 a.setPoint( 2*i+1, xx, yy+2 );
101 xx++; yy++; 102 xx++; yy++;
102 } 103 }
103 yy -= 2; 104 yy -= 2;
104 for ( i=3; i<7; i++ ) { 105 for ( i=3; i<7; i++ ) {
105 a.setPoint( 2*i, xx, yy ); 106 a.setPoint( 2*i, xx, yy );
106 a.setPoint( 2*i+1, xx, yy+2 ); 107 a.setPoint( 2*i+1, xx, yy+2 );
107 xx++; yy--; 108 xx++; yy--;
108 } 109 }
109 p->drawLineSegments( a ); 110 p->drawLineSegments( a );
110 } 111 }
111} 112}
112 113
113 114
114ComboItem::ComboItem( QTable *t, EditType et ) 115ComboItem::ComboItem( QTable *t, EditType et )
115 : QTableItem( t, et, "3" ), cb( 0 ) 116 : QTableItem( t, et, "3" ), cb( 0 )
116{ 117{
117 setReplaceable( FALSE ); 118 setReplaceable( FALSE );
118} 119}
119 120
120QWidget *ComboItem::createEditor() const 121QWidget *ComboItem::createEditor() const
121{ 122{
122 QString txt = text(); 123 QString txt = text();
123 ( (ComboItem*)this )->cb = new QComboBox( table()->viewport() ); 124 ( (ComboItem*)this )->cb = new QComboBox( table()->viewport() );
124 cb->insertItem( "1" ); 125 cb->insertItem( "1" );
125 cb->insertItem( "2" ); 126 cb->insertItem( "2" );
126 cb->insertItem( "3" ); 127 cb->insertItem( "3" );
127 cb->insertItem( "4" ); 128 cb->insertItem( "4" );
128 cb->insertItem( "5" ); 129 cb->insertItem( "5" );
129 cb->setCurrentItem( txt.toInt() - 1 ); 130 cb->setCurrentItem( txt.toInt() - 1 );
130 return cb; 131 return cb;
131} 132}
132 133
133void ComboItem::setContentFromEditor( QWidget *w ) 134void ComboItem::setContentFromEditor( QWidget *w )
134{ 135{
135 TodoTable *parent = static_cast<TodoTable*>(table()); 136 TodoTable *parent = static_cast<TodoTable*>(table());
136 Task newTodo = parent->currentEntry(); 137 ToDoEvent newTodo = parent->currentEntry();
137 138
138 if ( w->inherits( "QComboBox" ) ) 139 if ( w->inherits( "QComboBox" ) )
139 setText( ( (QComboBox*)w )->currentText() ); 140 setText( ( (QComboBox*)w )->currentText() );
140 else 141 else
141 QTableItem::setContentFromEditor( w ); 142 QTableItem::setContentFromEditor( w );
142 newTodo.setPriority( text().toInt() ); 143 newTodo.setPriority( text().toInt() );
143 parent->replaceCurrentEntry( newTodo, true ); 144 parent->replaceCurrentEntry( newTodo, true );
144} 145}
145 146
146void ComboItem::setText( const QString &s ) 147void ComboItem::setText( const QString &s )
147{ 148{
148 if ( cb ) 149 if ( cb )
149 cb->setCurrentItem( s.toInt() - 1 ); 150 cb->setCurrentItem( s.toInt() - 1 );
150 QTableItem::setText( s ); 151 QTableItem::setText( s );
151} 152}
152 153
153QString ComboItem::text() const 154QString ComboItem::text() const
154{ 155{
155 if ( cb ) 156 if ( cb )
156 return cb->currentText(); 157 return cb->currentText();
157 return QTableItem::text(); 158 return QTableItem::text();
158} 159}
159 160
160 161
161 162
162TodoTable::TodoTable( QWidget *parent, const char *name ) 163TodoTable::TodoTable( QWidget *parent, const char *name )
163// #ifdef QT_QTABLE_NOHEADER_CONSTRUCTOR 164// #ifdef QT_QTABLE_NOHEADER_CONSTRUCTOR
164// : QTable( 0, 3, parent, name, TRUE ), 165// : QTable( 0, 3, parent, name, TRUE ),
165// #else 166// #else
166 : QTable( 0, 3, parent, name ), 167 : QTable( 0, 3, parent, name ),
167// #endif 168// #endif
168 showComp( true ), 169 showComp( true ),
169 enablePainting( true ), 170 enablePainting( true ),
170 mCat( 0 ), 171 mCat( 0 ),
171 currFindRow( -2 ) 172 currFindRow( -2 )
172{ 173{
173 mCat.load( categoryFileName() ); 174 mCat.load( categoryFileName() );
174 setSorting( TRUE ); 175 setSorting( TRUE );
175 setSelectionMode( NoSelection ); 176 setSelectionMode( NoSelection );
176 setColumnStretchable( 2, TRUE ); 177 setColumnStretchable( 2, TRUE );
177 setColumnWidth( 0, 20 ); 178 setColumnWidth( 0, 20 );
178 setColumnWidth( 1, 35 ); 179 setColumnWidth( 1, 35 );
179 setLeftMargin( 0 ); 180 setLeftMargin( 0 );
180 verticalHeader()->hide(); 181 verticalHeader()->hide();
181 horizontalHeader()->setLabel( 0, tr( "C." ) ); 182 horizontalHeader()->setLabel( 0, tr( "C." ) );
182 horizontalHeader()->setLabel( 1, tr( "Prior." ) ); 183 horizontalHeader()->setLabel( 1, tr( "Prior." ) );
183 horizontalHeader()->setLabel( 2, tr( "Description" ) ); 184 horizontalHeader()->setLabel( 2, tr( "Description" ) );
184 connect( this, SIGNAL( clicked( int, int, int, const QPoint & ) ), 185 connect( this, SIGNAL( clicked( int, int, int, const QPoint & ) ),
185 this, SLOT( slotClicked( int, int, int, const QPoint & ) ) ); 186 this, SLOT( slotClicked( int, int, int, const QPoint & ) ) );
186 connect( this, SIGNAL( pressed( int, int, int, const QPoint & ) ), 187 connect( this, SIGNAL( pressed( int, int, int, const QPoint & ) ),
187 this, SLOT( slotPressed( int, int, int, const QPoint & ) ) ); 188 this, SLOT( slotPressed( int, int, int, const QPoint & ) ) );
188 connect( this, SIGNAL( valueChanged( int, int ) ), 189 connect( this, SIGNAL( valueChanged( int, int ) ),
189 this, SLOT( slotCheckPriority( int, int ) ) ); 190 this, SLOT( slotCheckPriority( int, int ) ) );
190 connect( this, SIGNAL( currentChanged( int, int ) ), 191 connect( this, SIGNAL( currentChanged( int, int ) ),
191 this, SLOT( slotCurrentChanged( int, int ) ) ); 192 this, SLOT( slotCurrentChanged( int, int ) ) );
192 193
193 menuTimer = new QTimer( this ); 194 menuTimer = new QTimer( this );
194 connect( menuTimer, SIGNAL(timeout()), this, SLOT(slotShowMenu()) ); 195 connect( menuTimer, SIGNAL(timeout()), this, SLOT(slotShowMenu()) );
195} 196}
196 197
197void TodoTable::addEntry( const Task &todo ) 198void TodoTable::addEntry( const ToDoEvent &todo )
198{ 199{
199 int row = numRows(); 200 int row = numRows();
200 setNumRows( row + 1 ); 201 setNumRows( row + 1 );
201 updateJournal( todo, ACTION_ADD ); 202 updateJournal( todo, ACTION_ADD );
202 insertIntoTable( new Task(todo), row ); 203 insertIntoTable( new ToDoEvent(todo), row );
203 setCurrentCell(row, currentColumn()); 204 setCurrentCell(row, currentColumn());
204 updateVisible(); 205 updateVisible();
205} 206}
206 207
207void TodoTable::slotClicked( int row, int col, int, const QPoint &pos ) 208void TodoTable::slotClicked( int row, int col, int, const QPoint &pos )
208{ 209{
209 if ( !cellGeometry( row, col ).contains(pos) ) 210 if ( !cellGeometry( row, col ).contains(pos) )
210 return; 211 return;
211 // let's switch on the column number... 212 // let's switch on the column number...
212 switch ( col ) 213 switch ( col )
213 { 214 {
214 case 0: { 215 case 0: {
215 CheckItem *i = static_cast<CheckItem*>(item( row, col )); 216 CheckItem *i = static_cast<CheckItem*>(item( row, col ));
216 if ( i ) { 217 if ( i ) {
217 int x = pos.x() - columnPos( col ); 218 int x = pos.x() - columnPos( col );
218 int y = pos.y() - rowPos( row ); 219 int y = pos.y() - rowPos( row );
219 int w = columnWidth( col ); 220 int w = columnWidth( col );
220 int h = rowHeight( row ); 221 int h = rowHeight( row );
221 if ( i && x >= ( w - BoxSize ) / 2 && x <= ( w - BoxSize ) / 2 + BoxSize && 222 if ( i && x >= ( w - BoxSize ) / 2 && x <= ( w - BoxSize ) / 2 + BoxSize &&
222 y >= ( h - BoxSize ) / 2 && y <= ( h - BoxSize ) / 2 + BoxSize ) { 223 y >= ( h - BoxSize ) / 2 && y <= ( h - BoxSize ) / 2 + BoxSize ) {
223 i->toggle(); 224 i->toggle();
224 } 225 }
225 emit signalDoneChanged( i->isChecked() ); 226 emit signalDoneChanged( i->isChecked() );
226 } 227 }
227 } 228 }
228 break; 229 break;
229 case 1: 230 case 1:
230 break; 231 break;
231 case 2: 232 case 2:
232 // may as well edit it... 233 // may as well edit it...
233 menuTimer->stop(); 234 menuTimer->stop();
234// emit signalEdit(); 235// emit signalEdit();
235 break; 236 break;
236 } 237 }
237} 238}
238 239
239void TodoTable::slotPressed( int row, int col, int, const QPoint &pos ) 240void TodoTable::slotPressed( int row, int col, int, const QPoint &pos )
240{ 241{
241 if ( col == 2 && cellGeometry( row, col ).contains(pos) ) 242 if ( col == 2 && cellGeometry( row, col ).contains(pos) )
242 menuTimer->start( 750, TRUE ); 243 menuTimer->start( 750, TRUE );
243} 244}
244 245
245void TodoTable::slotShowMenu() 246void TodoTable::slotShowMenu()
246{ 247{
247 emit signalShowMenu( QCursor::pos() ); 248 emit signalShowMenu( QCursor::pos() );
248} 249}
249 250
250void TodoTable::slotCurrentChanged( int, int ) 251void TodoTable::slotCurrentChanged( int, int )
251{ 252{
252 menuTimer->stop(); 253 menuTimer->stop();
253} 254}
254 255
255void TodoTable::internalAddEntries( QList<Task> &list ) 256void TodoTable::internalAddEntries( QList<ToDoEvent> &list )
256{ 257{
257 setNumRows( list.count() ); 258 setNumRows( list.count() );
258 int row = 0; 259 int row = 0;
259 Task *it; 260 ToDoEvent *it;
260 for ( it = list.first(); it; it = list.next() ) 261 for ( it = list.first(); it; it = list.next() )
261 insertIntoTable( it, row++ ); 262 insertIntoTable( it, row++ );
262} 263}
263 264
264 265
265Task TodoTable::currentEntry() const 266ToDoEvent TodoTable::currentEntry() const
266{ 267{
267 QTableItem *i = item( currentRow(), 0 ); 268 QTableItem *i = item( currentRow(), 0 );
268 if ( !i || rowHeight( currentRow() ) <= 0 ) 269 if ( !i || rowHeight( currentRow() ) <= 0 )
269 return Task(); 270 return ToDoEvent();
270 Task *todo = todoList[(CheckItem*)i]; 271 ToDoEvent *todo = todoList[(CheckItem*)i];
271 todo->setCompleted( ( (CheckItem*)item( currentRow(), 0 ) )->isChecked() ); 272 todo->setCompleted( ( (CheckItem*)item( currentRow(), 0 ) )->isChecked() );
272 todo->setPriority( ( (ComboItem*)item( currentRow(), 1 ) )->text().toInt() ); 273 todo->setPriority( ( (ComboItem*)item( currentRow(), 1 ) )->text().toInt() );
273 return *todo; 274 return *todo;
274} 275}
275 276
276void TodoTable::replaceCurrentEntry( const Task &todo, bool fromTableItem ) 277void TodoTable::replaceCurrentEntry( const ToDoEvent &todo, bool fromTableItem )
277{ 278{
278 int row = currentRow(); 279 int row = currentRow();
279 updateJournal( todo, ACTION_REPLACE, row ); 280 updateJournal( todo, ACTION_REPLACE, row );
280 281
281 if ( !fromTableItem ) { 282 if ( !fromTableItem ) {
282 journalFreeReplaceEntry( todo, row ); 283 journalFreeReplaceEntry( todo, row );
283 updateVisible(); 284 updateVisible();
284 } 285 }
285} 286}
286 287
287void TodoTable::removeCurrentEntry() 288void TodoTable::removeCurrentEntry()
288{ 289{
289 Task *oldTodo; 290 ToDoEvent *oldTodo;
290 int row = currentRow(); 291 int row = currentRow();
291 CheckItem *chk; 292 CheckItem *chk;
292 293
293 chk = static_cast<CheckItem*>(item(row, 0 )); 294 chk = static_cast<CheckItem*>(item(row, 0 ));
294 if ( !chk ) 295 if ( !chk )
295 return; 296 return;
296 oldTodo = todoList[chk]; 297 oldTodo = todoList[chk];
297 todoList.remove( chk ); 298 todoList.remove( chk );
298 oldTodo->setCompleted( chk->isChecked() ); 299 oldTodo->setCompleted( chk->isChecked() );
299 oldTodo->setPriority( static_cast<ComboItem*>(item(row, 1))->text().toInt() ); 300 oldTodo->setPriority( static_cast<ComboItem*>(item(row, 1))->text().toInt() );
300 realignTable( row ); 301 realignTable( row );
301 updateVisible(); 302 updateVisible();
302 updateJournal( *oldTodo, ACTION_REMOVE, row ); 303 updateJournal( *oldTodo, ACTION_REMOVE, row );
303 delete oldTodo; 304 delete oldTodo;
304} 305}
305 306
306 307
307bool TodoTable::save( const QString &fn ) 308bool TodoTable::save( const QString &fn )
308{ 309{
309 QString strNewFile = fn + ".new"; 310 QString strNewFile = fn + ".new";
310 QFile f( strNewFile ); 311 QFile::remove( strNewFile ); // just to be sure
311 if ( !f.open( IO_WriteOnly|IO_Raw ) ) 312 ToDoDB todoDB( strNewFile );
312 return false; 313 for ( QMap<CheckItem*, ToDoEvent *>::Iterator it = todoList.begin();
313
314 QString buf("<!DOCTYPE Tasks>\n<Tasks>\n");
315 QCString str;
316 int total_written;
317
318 for ( QMap<CheckItem*, Task *>::Iterator it = todoList.begin();
319 it != todoList.end(); ++it ) { 314 it != todoList.end(); ++it ) {
320 if ( !item( it.key()->row(), 0 ) ) 315 if ( !item( it.key()->row(), 0 ) )
321 continue; 316 continue;
322 Task *todo = *it; 317 ToDoEvent *todo = *it;
323 // sync item with table 318 // sync item with table
324 todo->setCompleted( ((CheckItem*)item(it.key()->row(), 0))->isChecked() ); 319 todo->setCompleted( ((CheckItem*)item(it.key()->row(), 0))->isChecked() );
325 todo->setPriority( ((ComboItem*)item( it.key()->row(), 1))->text().toInt() ); 320 todo->setPriority( ((ComboItem*)item( it.key()->row(), 1))->text().toInt() );
326 buf += "<Task"; 321 todoDB.addEvent( *todo );
327 todo->save( buf );
328 buf += " />\n";
329 str = buf.utf8();
330 total_written = f.writeBlock( str.data(), str.length() );
331 if ( total_written != int(str.length()) ) {
332 f.close();
333 QFile::remove( strNewFile );
334 return false;
335 }
336 buf = "";
337 }
338
339 buf += "</Tasks>\n";
340 str = buf.utf8();
341 total_written = f.writeBlock( str.data(), str.length() );
342 if ( total_written != int(str.length()) ) {
343 f.close();
344 QFile::remove( strNewFile );
345 return false;
346 } 322 }
347 f.close(); 323 if(!todoDB.save() ){
348 324 QFile::remove( strNewFile );
325 return false;
326 };
349 // now do the rename 327 // now do the rename
350 if ( ::rename( strNewFile, fn ) < 0 ) 328 if ( ::rename( strNewFile, fn ) < 0 )
351 qWarning( "problem renaming file %s to %s errno %d", 329 qWarning( "problem renaming file %s to %s errno %d",
352 strNewFile.latin1(), fn.latin1(), errno ); 330 strNewFile.latin1(), fn.latin1(), errno );
353 331
354 // remove the journal 332 // remove the journal
355 QFile::remove( journalFileName() ); 333 QFile::remove( journalFileName() );
356 return true; 334 return true;
357} 335}
358 336
359void TodoTable::load( const QString &fn ) 337void TodoTable::load( const QString &fn )
360{ 338{
361 loadFile( fn, false ); 339 loadFile( fn, false );
362 if ( QFile::exists(journalFileName()) ) { 340 if ( QFile::exists(journalFileName()) ) {
363 loadFile( journalFileName(), true ); 341 loadFile( journalFileName(), true );
364 save( fn ); 342 save( fn );
365 } 343 }
366// QTable::sortColumn(2,TRUE,TRUE); 344// QTable::sortColumn(2,TRUE,TRUE);
367// QTable::sortColumn(1,TRUE,TRUE); 345// QTable::sortColumn(1,TRUE,TRUE);
368 QTable::sortColumn(0,TRUE,TRUE); 346 QTable::sortColumn(0,TRUE,TRUE);
369 setCurrentCell( 0, 2 ); 347 setCurrentCell( 0, 2 );
370} 348}
371 349
372void TodoTable::updateVisible() 350void TodoTable::updateVisible()
373{ 351{
374 if ( !isUpdatesEnabled() ) 352 if ( !isUpdatesEnabled() )
375 return; 353 return;
376 354
377// qDebug("--> updateVisible!"); 355// qDebug("--> updateVisible!");
378 356
379 int visible = 0; 357 int visible = 0;
380 int id = mCat.id( "Todo List", showCat ); 358 int id = mCat.id( "Todo List", showCat );
381 for ( int row = 0; row < numRows(); row++ ) { 359 for ( int row = 0; row < numRows(); row++ ) {
382 CheckItem *ci = (CheckItem *)item( row, 0 ); 360 CheckItem *ci = (CheckItem *)item( row, 0 );
383 Task *t = todoList[ci]; 361 ToDoEvent *t = todoList[ci];
384 QArray<int> vlCats = t->categories(); 362 QArray<int> vlCats = t->categories();
385 bool hide = false; 363 bool hide = false;
386 if ( !showComp && ci->isChecked() ) 364 if ( !showComp && ci->isChecked() )
387 hide = true; 365 hide = true;
388 if ( !showCat.isEmpty() ) { 366 if ( !showCat.isEmpty() ) {
389 if ( showCat == tr( "Unfiled" ) ) { 367 if ( showCat == tr( "Unfiled" ) ) {
390 if ( vlCats.count() > 0 ) 368 if ( vlCats.count() > 0 )
391 hide = true; 369 hide = true;
392 } else { 370 } else {
393 // do some comparing, we have to reverse our idea here... 371 // do some comparing, we have to reverse our idea here...
394 if ( !hide ) { 372 if ( !hide ) {
395 hide = true; 373 hide = true;
396 for ( uint it = 0; it < vlCats.count(); ++it ) { 374 for ( uint it = 0; it < vlCats.count(); ++it ) {
397 if ( vlCats[it] == id ) { 375 if ( vlCats[it] == id ) {
398 hide = false; 376 hide = false;
399 break; 377 break;
400 } 378 }
401 } 379 }
402 } 380 }
403 } 381 }
404 } 382 }
405 if ( hide ) { 383 if ( hide ) {
406 if ( currentRow() == row ) 384 if ( currentRow() == row )
407 setCurrentCell( -1, 0 ); 385 setCurrentCell( -1, 0 );
408 if ( rowHeight( row ) > 0 ) 386 if ( rowHeight( row ) > 0 )
409 hideRow( row ); 387 hideRow( row );
410 } else { 388 } else {
411 if ( rowHeight( row ) == 0 ) { 389 if ( rowHeight( row ) == 0 ) {
412 showRow( row ); 390 showRow( row );
413 adjustRow( row ); 391 adjustRow( row );
414 } 392 }
415 visible++; 393 visible++;
416 } 394 }
417 } 395 }
418 if ( !visible ) 396 if ( !visible )
419 setCurrentCell( -1, 0 ); 397 setCurrentCell( -1, 0 );
420} 398}
421 399
422void TodoTable::viewportPaintEvent( QPaintEvent *pe ) 400void TodoTable::viewportPaintEvent( QPaintEvent *pe )
423{ 401{
424 if ( enablePainting ) 402 if ( enablePainting )
425 QTable::viewportPaintEvent( pe ); 403 QTable::viewportPaintEvent( pe );
426} 404}
427 405
428void TodoTable::setPaintingEnabled( bool e ) 406void TodoTable::setPaintingEnabled( bool e )
429{ 407{
430 if ( e != enablePainting ) { 408 if ( e != enablePainting ) {
431 if ( !enablePainting ) { 409 if ( !enablePainting ) {
432 enablePainting = true; 410 enablePainting = true;
433 rowHeightChanged( 0 ); 411 rowHeightChanged( 0 );
434 viewport()->update(); 412 viewport()->update();
435 } else { 413 } else {
436 enablePainting = false; 414 enablePainting = false;
437 } 415 }
438 } 416 }
439} 417}
440 418
441void TodoTable::clear() 419void TodoTable::clear()
442{ 420{
443 for ( QMap<CheckItem*, Task *>::Iterator it = todoList.begin(); 421 for ( QMap<CheckItem*, ToDoEvent *>::Iterator it = todoList.begin();
444 it != todoList.end(); ++it ) { 422 it != todoList.end(); ++it ) {
445 Task *todo = *it; 423 ToDoEvent *todo = *it;
446 delete todo; 424 delete todo;
447 } 425 }
448 todoList.clear(); 426 todoList.clear();
449 for ( int r = 0; r < numRows(); ++r ) { 427 for ( int r = 0; r < numRows(); ++r ) {
450 for ( int c = 0; c < numCols(); ++c ) { 428 for ( int c = 0; c < numCols(); ++c ) {
451 if ( cellWidget( r, c ) ) 429 if ( cellWidget( r, c ) )
452 clearCellWidget( r, c ); 430 clearCellWidget( r, c );
453 clearCell( r, c ); 431 clearCell( r, c );
454 } 432 }
455 } 433 }
456 setNumRows( 0 ); 434 setNumRows( 0 );
457} 435}
458 436
459void TodoTable::sortColumn( int col, bool /*ascending*/, bool /*wholeRows*/ ) 437void TodoTable::sortColumn( int col, bool /*ascending*/, bool /*wholeRows*/ )
460{ 438{
461 // The default for wholeRows is false, however 439 // The default for wholeRows is false, however
462 // for this todo table we want to exchange complete 440 // for this todo table we want to exchange complete
463 // rows when sorting. Also, we always want ascending, since 441 // rows when sorting. Also, we always want ascending, since
464 // the values have a logical order. 442 // the values have a logical order.
465 QTable::sortColumn( col, TRUE, TRUE ); 443 QTable::sortColumn( col, TRUE, TRUE );
466 updateVisible(); 444 updateVisible();
467} 445}
468 446
469void TodoTable::slotCheckPriority(int row, int col ) 447void TodoTable::slotCheckPriority(int row, int col )
470{ 448{
471 // kludgey work around to make forward along the updated priority... 449 // kludgey work around to make forward along the updated priority...
472 if ( col == 1 ) { 450 if ( col == 1 ) {
473 // let everyone know!! 451 // let everyone know!!
474 ComboItem* i = static_cast<ComboItem*>( item( row, col ) ); 452 ComboItem* i = static_cast<ComboItem*>( item( row, col ) );
475 emit signalPriorityChanged( i->text().toInt() ); 453 emit signalPriorityChanged( i->text().toInt() );
476 } 454 }
477} 455}
478 456
479 457
480void TodoTable::updateJournal( const Task &todo, journal_action action, int row ) 458void TodoTable::updateJournal( const ToDoEvent &todo, journal_action action, int row )
481{ 459{
482 QFile f( journalFileName() ); 460 QFile f( journalFileName() );
483 if ( !f.open(IO_WriteOnly|IO_Append) ) 461 if ( !f.open(IO_WriteOnly|IO_Append) )
484 return; 462 return;
485 QString buf; 463 QString buf;
486 QCString str; 464 QCString str;
487 buf = "<Task"; 465 buf = "<Task";
488 todo.save( buf ); 466 // todo.save( buf );
489 buf += " Action=\"" + QString::number( int(action) ) + "\""; 467 buf += " Action=\"" + QString::number( int(action) ) + "\"";
490 buf += " Row=\"" + QString::number( row ) + "\""; 468 buf += " Row=\"" + QString::number( row ) + "\"";
491 buf += "/>\n"; 469 buf += "/>\n";
492 str = buf.utf8(); 470 str = buf.utf8();
493 f.writeBlock( str.data(), str.length() ); 471 f.writeBlock( str.data(), str.length() );
494 f.close(); 472 f.close();
495} 473}
496 474
497void TodoTable::rowHeightChanged( int row ) 475void TodoTable::rowHeightChanged( int row )
498{ 476{
499 if ( enablePainting ) 477 if ( enablePainting )
500 QTable::rowHeightChanged( row ); 478 QTable::rowHeightChanged( row );
501} 479}
502 480
503void TodoTable::loadFile( const QString &strFile, bool fromJournal ) 481void TodoTable::loadFile( const QString &strFile, bool fromJournal )
504{ 482{
505 QFile f( strFile );
506 if ( !f.open(IO_ReadOnly) )
507 return;
508
509 int action, row;
510 action = 0; row = 0;
511
512 enum Attribute {
513 FCompleted = 0,
514 FHasDate,
515 FPriority,
516 FCategories,
517 FDescription,
518 FDateYear,
519 FDateMonth,
520 FDateDay,
521 FUid,
522 FAction,
523 FRow
524 };
525
526 QAsciiDict<int> dict( 31 );
527 QList<Task> list;
528 dict.setAutoDelete( TRUE );
529 dict.insert( "Completed", new int(FCompleted) );
530 dict.insert( "HasDate", new int(FHasDate) );
531 dict.insert( "Priority", new int(FPriority) );
532 dict.insert( "Categories", new int(FCategories) );
533 dict.insert( "Description", new int(FDescription) );
534 dict.insert( "DateYear", new int(FDateYear) );
535 dict.insert( "DateMonth", new int(FDateMonth) );
536 dict.insert( "DateDay", new int(FDateDay) );
537 dict.insert( "Uid", new int(FUid) );
538 dict.insert( "Action", new int(FAction) );
539 dict.insert( "Row", new int(FRow) );
540
541 QByteArray ba = f.readAll();
542 f.close();
543 char* dt = ba.data();
544 int len = ba.size();
545 bool hasDueDate = FALSE;
546
547 action = ACTION_ADD;
548 int i = 0;
549 char *point;
550 while ( ( point = strstr( dt+i, "<Task " ) ) != NULL ) {
551 // new Task
552 i = point - dt;
553 Task *todo = new Task;
554 int dtY = 0, dtM = 0, dtD = 0;
555
556 i += 5;
557
558 while( 1 ) {
559 while ( i < len && (dt[i] == ' ' || dt[i] == '\n' || dt[i] == '\r') )
560 ++i;
561 if ( i >= len-2 || (dt[i] == '/' && dt[i+1] == '>') )
562 break;
563 // we have another attribute, read it.
564 int j = i;
565 while ( j < len && dt[j] != '=' )
566 ++j;
567 char *attr = dt+i;
568 dt[j] = '\0';
569 i = ++j; // skip =
570 while ( i < len && dt[i] != '"' )
571 ++i;
572 j = ++i;
573 bool haveUtf = FALSE;
574 bool haveEnt = FALSE;
575 while ( j < len && dt[j] != '"' ) {
576 if ( ((unsigned char)dt[j]) > 0x7f )
577 haveUtf = TRUE;
578 if ( dt[j] == '&' )
579 haveEnt = TRUE;
580 ++j;
581 }
582 if ( i == j ) {
583 // empty value
584 i = j + 1;
585 continue;
586 }
587 QCString value( dt+i, j-i+1 );
588 i = j + 1;
589 int *lookup = dict[ attr ];
590 if ( !lookup ) {
591 todo->setCustomField(attr, value);
592 continue;
593 }
594 switch( *lookup ) {
595 case FCompleted:
596 todo->setCompleted( value.toInt() );
597 break;
598 case FHasDate:
599 // leave...
600 hasDueDate = value.toInt();
601 break;
602 case FPriority:
603 todo->setPriority( value.toInt() );
604 break;
605 case FCategories: {
606 //QString str = Qtopia::plainString( value );
607 todo->setCategories( Qtopia::Record::idsFromString( value ) );
608 break;
609 }
610 case FDescription:
611 {
612 QString str = (haveUtf ? QString::fromUtf8( value )
613 : QString::fromLatin1( value ) );
614 if ( haveEnt )
615 str = Qtopia::plainString( str );
616 todo->setDescription( str );
617 break;
618 }
619 case FDateYear:
620 dtY = value.toInt();
621 break;
622 case FDateMonth:
623 dtM = value.toInt();
624 break;
625 case FDateDay:
626 dtD = value.toInt();
627 break;
628 case FUid:
629 todo->setUid( value.toInt() );
630 break;
631 case FAction:
632 action = value.toInt();
633 break;
634 case FRow:
635 row = value.toInt();
636 break;
637 default:
638 qDebug( "huh??? missing enum? -- attr.: %s", attr );
639 break;
640 }
641 }
642
643 if ( dtY != 0 && dtM != 0 && dtD != 0 )
644 todo->setDueDate( QDate( dtY, dtM, dtD), hasDueDate );
645 else
646 todo->setHasDueDate( hasDueDate );
647
648// if ( categoryList.find( todo.category() ) == categoryList.end() )
649// categoryList.append( todo.category() );
650
651 483
652 // sadly we can't delay adding of items from the journal to get 484 QList<ToDoEvent> list;
653 // the proper effect, but then, the journal should _never_ be 485 ToDoDB todoDB;
654 // that huge 486 QValueList<ToDoEvent> vaList = todoDB.rawToDos();
655 487 for(QValueList<ToDoEvent>::ConstIterator it = vaList.begin(); it != vaList.end(); ++it ){
656 switch( action ) { 488 list.append( new ToDoEvent( (*it) ) );
657 case ACTION_ADD: 489 }
658 if ( fromJournal ) { 490 vaList.clear();
659 int myrows = numRows(); 491 // qDebug("parsing done=%d", t.elapsed() );
660 setNumRows( myrows + 1 ); 492 if ( list.count() > 0 ) {
661 insertIntoTable( todo, myrows ); 493 internalAddEntries( list );
662 delete todo; 494 list.clear();
663 } else 495 }
664 list.append( todo );
665 break;
666 case ACTION_REMOVE:
667 journalFreeRemoveEntry( row );
668 break;
669 case ACTION_REPLACE:
670 journalFreeReplaceEntry( *todo, row );
671 delete todo;
672 break;
673 default:
674 break;
675 }
676 }
677// qDebug("parsing done=%d", t.elapsed() );
678 if ( list.count() > 0 ) {
679 internalAddEntries( list );
680 list.clear();
681 }
682// qDebug("loading done: t=%d", t.elapsed() ); 496// qDebug("loading done: t=%d", t.elapsed() );
683} 497}
684 498
685void TodoTable::journalFreeReplaceEntry( const Task &todo, int row ) 499void TodoTable::journalFreeReplaceEntry( const ToDoEvent &todo, int row )
686{ 500{
687 QString strTodo; 501 QString strTodo;
688 strTodo = todo.description().left(40).simplifyWhiteSpace(); 502 strTodo = todo.description().left(40).simplifyWhiteSpace();
689 if ( row == -1 ) { 503 if ( row == -1 ) {
690 QMapIterator<CheckItem*, Task *> it; 504 QMapIterator<CheckItem*, ToDoEvent *> it;
691 for ( it = todoList.begin(); it != todoList.end(); ++it ) { 505 for ( it = todoList.begin(); it != todoList.end(); ++it ) {
692 if ( *(*it) == todo ) { 506 if ( *(*it) == todo ) {
693 row = it.key()->row(); 507 row = it.key()->row();
694 it.key()->setChecked( todo.isCompleted() ); 508 it.key()->setChecked( todo.isCompleted() );
695 static_cast<ComboItem*>(item(row, 1))->setText( QString::number(todo.priority()) ); 509 static_cast<ComboItem*>(item(row, 1))->setText( QString::number(todo.priority()) );
696 item( row, 2 )->setText( strTodo ); 510 item( row, 2 )->setText( strTodo );
697 *(*it) = todo; 511 *(*it) = todo;
698 } 512 }
699 } 513 }
700 } else { 514 } else {
701 Task *t = todoList[static_cast<CheckItem*>(item(row, 0))]; 515 ToDoEvent *t = todoList[static_cast<CheckItem*>(item(row, 0))];
702 todoList.remove( static_cast<CheckItem*>(item(row, 0)) ); 516 todoList.remove( static_cast<CheckItem*>(item(row, 0)) );
703 delete t; 517 delete t;
704 static_cast<CheckItem*>(item(row, 0))->setChecked( todo.isCompleted() ); 518 static_cast<CheckItem*>(item(row, 0))->setChecked( todo.isCompleted() );
705 static_cast<ComboItem*>(item(row, 1))->setText( QString::number(todo.priority()) ); 519 static_cast<ComboItem*>(item(row, 1))->setText( QString::number(todo.priority()) );
706 item( row, 2 )->setText( strTodo ); 520 item( row, 2 )->setText( strTodo );
707 todoList.insert( static_cast<CheckItem*>(item(row,0)), new Task(todo) ); 521 todoList.insert( static_cast<CheckItem*>(item(row,0)), new ToDoEvent(todo) );
708 } 522 }
709} 523}
710 524
711void TodoTable::journalFreeRemoveEntry( int row ) 525void TodoTable::journalFreeRemoveEntry( int row )
712{ 526{
713 CheckItem *chk; 527 CheckItem *chk;
714 chk = static_cast<CheckItem*>(item(row, 0 )); 528 chk = static_cast<CheckItem*>(item(row, 0 ));
715 if ( !chk ) 529 if ( !chk )
716 return; 530 return;
717 todoList.remove( chk ); 531 todoList.remove( chk );
718 532
719 realignTable( row ); 533 realignTable( row );
720} 534}
721 535
722void TodoTable::keyPressEvent( QKeyEvent *e ) 536void TodoTable::keyPressEvent( QKeyEvent *e )
723{ 537{
724 if ( e->key() == Key_Space || e->key() == Key_Return ) { 538 if ( e->key() == Key_Space || e->key() == Key_Return ) {
725 switch ( currentColumn() ) { 539 switch ( currentColumn() ) {
726 case 0: { 540 case 0: {
727 CheckItem *i = static_cast<CheckItem*>(item(currentRow(), 541 CheckItem *i = static_cast<CheckItem*>(item(currentRow(),
728 currentColumn())); 542 currentColumn()));
729 if ( i ) 543 if ( i )
730 i->toggle(); 544 i->toggle();
731 break; 545 break;
732 } 546 }
733 case 1: 547 case 1:
734 break; 548 break;
735 case 2: 549 case 2:
736 emit signalEdit(); 550 emit signalEdit();
737 default: 551 default:
738 break; 552 break;
739 } 553 }
740 } else { 554 } else {
741 QTable::keyPressEvent( e ); 555 QTable::keyPressEvent( e );
742 } 556 }
743} 557}
744 558
745QStringList TodoTable::categories() 559QStringList TodoTable::categories()
746{ 560{
747 // This is called seldom, so calling a load in here 561 // This is called seldom, so calling a load in here
748 // should be fine. 562 // should be fine.
749 mCat.load( categoryFileName() ); 563 mCat.load( categoryFileName() );
750 QStringList categoryList = mCat.labels( "Todo List" ); 564 QStringList categoryList = mCat.labels( "Todo List" );
751 return categoryList; 565 return categoryList;
752} 566}
753 567
754void TodoTable::slotDoFind( const QString &findString, bool caseSensitive, 568void TodoTable::slotDoFind( const QString &findString, bool caseSensitive,
755 bool backwards, int category ) 569 bool backwards, int category )
756{ 570{
757 // we have to iterate through the table, this gives the illusion that 571 // we have to iterate through the table, this gives the illusion that
758 // sorting is actually being used. 572 // sorting is actually being used.
759 if ( currFindRow < -1 ) 573 if ( currFindRow < -1 )
760 currFindRow = currentRow() - 1; 574 currFindRow = currentRow() - 1;
761 clearSelection( TRUE ); 575 clearSelection( TRUE );
762 int rows, 576 int rows,
763 row; 577 row;
764 CheckItem *chk; 578 CheckItem *chk;
765 QRegExp r( findString ); 579 QRegExp r( findString );
766 580
767 r.setCaseSensitive( caseSensitive ); 581 r.setCaseSensitive( caseSensitive );
768 rows = numRows(); 582 rows = numRows();
769 static bool wrapAround = true; 583 static bool wrapAround = true;
770 584
771 if ( !backwards ) { 585 if ( !backwards ) {
772 for ( row = currFindRow + 1; row < rows; row++ ) { 586 for ( row = currFindRow + 1; row < rows; row++ ) {
773 chk = static_cast<CheckItem*>( item(row, 0) ); 587 chk = static_cast<CheckItem*>( item(row, 0) );
774 if ( taskCompare(*(todoList[chk]), r, category) ) 588 if ( taskCompare(*(todoList[chk]), r, category) )
775 break; 589 break;
776 } 590 }
777 } else { 591 } else {
778 for ( row = currFindRow - 1; row > -1; row-- ) { 592 for ( row = currFindRow - 1; row > -1; row-- ) {
779 chk = static_cast<CheckItem*>( item(row, 0) ); 593 chk = static_cast<CheckItem*>( item(row, 0) );
780 if ( taskCompare(*(todoList[chk]), r, category) ) 594 if ( taskCompare(*(todoList[chk]), r, category) )
781 break; 595 break;
782 } 596 }
783 } 597 }
784 if ( row >= rows || row < 0 ) { 598 if ( row >= rows || row < 0 ) {
785 if ( row < 0 ) 599 if ( row < 0 )
786 currFindRow = rows; 600 currFindRow = rows;
787 else 601 else
788 currFindRow = -1; 602 currFindRow = -1;
789 if ( wrapAround ) 603 if ( wrapAround )
790 emit signalWrapAround(); 604 emit signalWrapAround();
791 else 605 else
792 emit signalNotFound(); 606 emit signalNotFound();
793 wrapAround = !wrapAround; 607 wrapAround = !wrapAround;
794 } else { 608 } else {
795 currFindRow = row; 609 currFindRow = row;
796 QTableSelection foundSelection; 610 QTableSelection foundSelection;
797 foundSelection.init( currFindRow, 0 ); 611 foundSelection.init( currFindRow, 0 );
798 foundSelection.expandTo( currFindRow, numCols() - 1 ); 612 foundSelection.expandTo( currFindRow, numCols() - 1 );
799 addSelection( foundSelection ); 613 addSelection( foundSelection );
800 setCurrentCell( currFindRow, numCols() - 1 ); 614 setCurrentCell( currFindRow, numCols() - 1 );
801 // we should always be able to wrap around and find this again, 615 // we should always be able to wrap around and find this again,
802 // so don't give confusing not found message... 616 // so don't give confusing not found message...
803 wrapAround = true; 617 wrapAround = true;
804 } 618 }
805} 619}
806 620
807int TodoTable::showCategoryId() const 621int TodoTable::showCategoryId() const
808{ 622{
809 int id; 623 int id;
810 id = -1; 624 id = -1;
811 // if allcategories are selected, you get unfiled... 625 // if allcategories are selected, you get unfiled...
812 if ( showCat != tr( "Unfiled" ) && showCat != tr( "All" ) ) 626 if ( showCat != tr( "Unfiled" ) && showCat != tr( "All" ) )
813 id = mCat.id( "Todo List", showCat ); 627 id = mCat.id( "Todo List", showCat );
814 return id; 628 return id;
815} 629}
816 630
817static bool taskCompare( const Task &task, const QRegExp &r, int category ) 631static bool taskCompare( const ToDoEvent &task, const QRegExp &r, int category )
818{ 632{
819 bool returnMe; 633 bool returnMe;
820 QArray<int> cats; 634 QArray<int> cats;
821 cats = task.categories(); 635 cats = task.categories();
822 636
823 returnMe = false; 637 returnMe = false;
824 if ( (category == -1 && cats.count() == 0) || category == -2 ) 638 if ( (category == -1 && cats.count() == 0) || category == -2 )
825 returnMe = task.match( r ); 639 returnMe = task.match( r );
826 else { 640 else {
827 int i; 641 int i;
828 for ( i = 0; i < int(cats.count()); i++ ) { 642 for ( i = 0; i < int(cats.count()); i++ ) {
829 if ( cats[i] == category ) { 643 if ( cats[i] == category ) {
830 returnMe = task.match( r ); 644 returnMe = task.match( r );
831 break; 645 break;
832 } 646 }
833 } 647 }
834 } 648 }
835 return returnMe; 649 return returnMe;
836} 650}
837 651
838static QString journalFileName() 652static QString journalFileName()
839{ 653{
840 QString str; 654 QString str;
841 str = getenv( "HOME" ); 655 str = getenv( "HOME" );
842 str += "/.todojournal"; 656 str += "/.todojournal";
843 return str; 657 return str;
844} 658}
845 659
846// int TodoTable::rowHeight( int ) const 660// int TodoTable::rowHeight( int ) const
847// { 661// {
848// return 18; 662// return 18;
849// } 663// }
850 664
851// int TodoTable::rowPos( int row ) const 665// int TodoTable::rowPos( int row ) const
852// { 666// {
853// return 18*row; 667// return 18*row;
854// } 668// }
855 669
856// int TodoTable::rowAt( int pos ) const 670// int TodoTable::rowAt( int pos ) const
857// { 671// {
858// return QMIN( pos/18, numRows()-1 ); 672// return QMIN( pos/18, numRows()-1 );
859// } 673// }
diff --git a/core/pim/todo/todotable.h b/core/pim/todo/todotable.h
index 4f3a064..2746ce7 100644
--- a/core/pim/todo/todotable.h
+++ b/core/pim/todo/todotable.h
@@ -1,207 +1,208 @@
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#ifndef TODOTABLE_H 21#ifndef TODOTABLE_H
22#define TODOTABLE_H 22#define TODOTABLE_H
23 23
24#include <qpe/categories.h> 24#include <qpe/categories.h>
25#include <qpe/stringutil.h> 25#include <qpe/stringutil.h>
26#include <qpe/task.h> 26//#include <qpe/task.h>
27#include <opie/todoevent.h>
27 28
28#include <qtable.h> 29#include <qtable.h>
29#include <qmap.h> 30#include <qmap.h>
30#include <qguardedptr.h> 31#include <qguardedptr.h>
31 32
32class Node; 33class Node;
33class QComboBox; 34class QComboBox;
34class QTimer; 35class QTimer;
35 36
36class CheckItem : public QTableItem 37class CheckItem : public QTableItem
37{ 38{
38public: 39public:
39 CheckItem( QTable *t, const QString &sortkey ); 40 CheckItem( QTable *t, const QString &sortkey );
40 41
41 void setChecked( bool b ); 42 void setChecked( bool b );
42 void toggle(); 43 void toggle();
43 bool isChecked() const; 44 bool isChecked() const;
44 void setKey( const QString &key ) { sortKey = key; } 45 void setKey( const QString &key ) { sortKey = key; }
45 QString key() const; 46 QString key() const;
46 47
47 void paint( QPainter *p, const QColorGroup &cg, const QRect &cr, bool selected ); 48 void paint( QPainter *p, const QColorGroup &cg, const QRect &cr, bool selected );
48 49
49private: 50private:
50 bool checked; 51 bool checked;
51 QString sortKey; 52 QString sortKey;
52}; 53};
53 54
54class ComboItem : public QTableItem 55class ComboItem : public QTableItem
55{ 56{
56public: 57public:
57 ComboItem( QTable *t, EditType et ); 58 ComboItem( QTable *t, EditType et );
58 QWidget *createEditor() const; 59 QWidget *createEditor() const;
59 void setContentFromEditor( QWidget *w ); 60 void setContentFromEditor( QWidget *w );
60 void setText( const QString &s ); 61 void setText( const QString &s );
61 int alignment() const { return Qt::AlignCenter; } 62 int alignment() const { return Qt::AlignCenter; }
62 63
63 QString text() const; 64 QString text() const;
64 65
65private: 66private:
66 QGuardedPtr<QComboBox> cb; 67 QGuardedPtr<QComboBox> cb;
67 68
68}; 69};
69 70
70class TodoTextItem : public QTableItem 71class TodoTextItem : public QTableItem
71{ 72{
72public: 73public:
73 TodoTextItem( QTable *t, const QString & str ) 74 TodoTextItem( QTable *t, const QString & str )
74 :QTableItem( t, QTableItem::Never, str ) {} 75 :QTableItem( t, QTableItem::Never, str ) {}
75 76
76 QString key () const { return Qtopia::buildSortKey( text() ); } 77 QString key () const { return Qtopia::buildSortKey( text() ); }
77}; 78};
78 79
79 80
80 81
81enum journal_action { ACTION_ADD, ACTION_REMOVE, ACTION_REPLACE }; 82enum journal_action { ACTION_ADD, ACTION_REMOVE, ACTION_REPLACE };
82 83
83class TodoTable : public QTable 84class TodoTable : public QTable
84{ 85{
85 Q_OBJECT 86 Q_OBJECT
86 87
87public: 88public:
88 TodoTable( QWidget *parent = 0, const char * name = 0 ); 89 TodoTable( QWidget *parent = 0, const char * name = 0 );
89 void addEntry( const Task &todo ); 90 void addEntry( const ToDoEvent &todo );
90 void clearFindRow() { currFindRow = -2; } 91 void clearFindRow() { currFindRow = -2; }
91 92
92 Task currentEntry() const; 93 ToDoEvent currentEntry() const;
93 void replaceCurrentEntry( const Task &todo, bool fromTableItem = false ); 94 void replaceCurrentEntry( const ToDoEvent &todo, bool fromTableItem = false );
94 95
95 QStringList categories(); 96 QStringList categories();
96 97
97 void setShowCompleted( bool sc ) { showComp = sc; updateVisible(); } 98 void setShowCompleted( bool sc ) { showComp = sc; updateVisible(); }
98 bool showCompleted() const { return showComp; } 99 bool showCompleted() const { return showComp; }
99 100
100 void setShowCategory( const QString &c ) { showCat = c; updateVisible(); } 101 void setShowCategory( const QString &c ) { showCat = c; updateVisible(); }
101 const QString &showCategory() const { return showCat; } 102 const QString &showCategory() const { return showCat; }
102 int showCategoryId() const; 103 int showCategoryId() const;
103 104
104 bool save( const QString &fn ); 105 bool save( const QString &fn );
105 void load( const QString &fn ); 106 void load( const QString &fn );
106 void clear(); 107 void clear();
107 void removeCurrentEntry(); 108 void removeCurrentEntry();
108 109
109 void setPaintingEnabled( bool e ); 110 void setPaintingEnabled( bool e );
110 111
111 virtual void sortColumn( int col, bool ascending, bool /*wholeRows*/ ); 112 virtual void sortColumn( int col, bool ascending, bool /*wholeRows*/ );
112 113
113// int rowHeight( int ) const; 114// int rowHeight( int ) const;
114// int rowPos( int row ) const; 115// int rowPos( int row ) const;
115// virtual int rowAt( int pos ) const; 116// virtual int rowAt( int pos ) const;
116 117
117signals: 118signals:
118 void signalEdit(); 119 void signalEdit();
119 void signalDoneChanged( bool b ); 120 void signalDoneChanged( bool b );
120 void signalPriorityChanged( int i ); 121 void signalPriorityChanged( int i );
121 void signalShowMenu( const QPoint & ); 122 void signalShowMenu( const QPoint & );
122 void signalNotFound(); 123 void signalNotFound();
123 void signalWrapAround(); 124 void signalWrapAround();
124 125
125protected: 126protected:
126 void keyPressEvent( QKeyEvent *e ); 127 void keyPressEvent( QKeyEvent *e );
127 128
128private: 129private:
129 void updateVisible(); 130 void updateVisible();
130 void viewportPaintEvent( QPaintEvent * ); 131 void viewportPaintEvent( QPaintEvent * );
131 void internalAddEntries( QList<Task> &list); 132 void internalAddEntries( QList<ToDoEvent> &list);
132 inline void insertIntoTable( Task *todo, int row ); 133 inline void insertIntoTable( ToDoEvent *todo, int row );
133 void updateJournal( const Task &todo, journal_action action, int row = -1); 134 void updateJournal( const ToDoEvent &todo, journal_action action, int row = -1);
134 void mergeJournal(); 135 void mergeJournal();
135 void journalFreeReplaceEntry( const Task &todo, int row ); 136 void journalFreeReplaceEntry( const ToDoEvent &todo, int row );
136 void journalFreeRemoveEntry( int row ); 137 void journalFreeRemoveEntry( int row );
137 inline void realignTable( int row ); 138 inline void realignTable( int row );
138 void loadFile( const QString &strFile, bool fromJournal = false ); 139 void loadFile( const QString &strFile, bool fromJournal = false );
139 140
140private slots: 141private slots:
141 void slotClicked( int row, int col, int button, const QPoint &pos ); 142 void slotClicked( int row, int col, int button, const QPoint &pos );
142 void slotPressed( int row, int col, int button, const QPoint &pos ); 143 void slotPressed( int row, int col, int button, const QPoint &pos );
143 void slotCheckPriority(int row, int col ); 144 void slotCheckPriority(int row, int col );
144 void slotCurrentChanged(int row, int col ); 145 void slotCurrentChanged(int row, int col );
145 void slotDoFind( const QString &findString, bool caseSensetive, 146 void slotDoFind( const QString &findString, bool caseSensetive,
146 bool backwards, int category ); 147 bool backwards, int category );
147 void slotShowMenu(); 148 void slotShowMenu();
148 void rowHeightChanged( int row ); 149 void rowHeightChanged( int row );
149 150
150private: 151private:
151 friend class TodoWindow; 152 friend class TodoWindow;
152 153
153 QMap<CheckItem*, Task *> todoList; 154 QMap<CheckItem*, ToDoEvent *> todoList;
154 QStringList categoryList; 155 QStringList categoryList;
155 bool showComp; 156 bool showComp;
156 QString showCat; 157 QString showCat;
157 QTimer *menuTimer; 158 QTimer *menuTimer;
158 bool enablePainting; 159 bool enablePainting;
159 Categories mCat; 160 Categories mCat;
160 int currFindRow; 161 int currFindRow;
161}; 162};
162 163
163 164
164inline void TodoTable::insertIntoTable( Task *todo, int row ) 165inline void TodoTable::insertIntoTable( ToDoEvent *todo, int row )
165{ 166{
166 QString sortKey = (char) ((todo->isCompleted() ? 'a' : 'A') 167 QString sortKey = (char) ((todo->isCompleted() ? 'a' : 'A')
167 + todo->priority() ) 168 + todo->priority() )
168 + Qtopia::buildSortKey( todo->description() ); 169 + Qtopia::buildSortKey( todo->description() );
169 CheckItem *chk = new CheckItem( this, sortKey ); 170 CheckItem *chk = new CheckItem( this, sortKey );
170 chk->setChecked( todo->isCompleted() ); 171 chk->setChecked( todo->isCompleted() );
171 ComboItem *cmb = new ComboItem( this, QTableItem::WhenCurrent ); 172 ComboItem *cmb = new ComboItem( this, QTableItem::WhenCurrent );
172 cmb->setText( QString::number( todo->priority() ) ); 173 cmb->setText( QString::number( todo->priority() ) );
173 QTableItem *ti = new TodoTextItem( this, todo->description().left(40).simplifyWhiteSpace() ); 174 QTableItem *ti = new TodoTextItem( this, todo->description().left(40).simplifyWhiteSpace() );
174 ti->setReplaceable( false ); 175 ti->setReplaceable( false );
175 176
176 setItem( row, 0, chk ); 177 setItem( row, 0, chk );
177 setItem( row, 1, cmb ); 178 setItem( row, 1, cmb );
178 setItem( row, 2, ti ); 179 setItem( row, 2, ti );
179 180
180 todoList.insert( chk, todo ); 181 todoList.insert( chk, todo );
181} 182}
182 183
183inline void TodoTable::realignTable( int row ) 184inline void TodoTable::realignTable( int row )
184{ 185{
185 QTableItem *ti1, 186 QTableItem *ti1,
186 *ti2, 187 *ti2,
187 *ti3; 188 *ti3;
188 int totalRows = numRows(); 189 int totalRows = numRows();
189 for ( int curr = row; curr < totalRows - 1; curr++ ) { 190 for ( int curr = row; curr < totalRows - 1; curr++ ) {
190 // this is bad, we must take the item out and then 191 // this is bad, we must take the item out and then
191 // set it. In the end, it behaves no worse (time wise) 192 // set it. In the end, it behaves no worse (time wise)
192 // then the old way of saving the entries to file, clearing 193 // then the old way of saving the entries to file, clearing
193 // the table re-reading in the file and resetting the table 194 // the table re-reading in the file and resetting the table
194 ti1 = item( curr + 1, 0 ); 195 ti1 = item( curr + 1, 0 );
195 ti2 = item( curr + 1, 1 ); 196 ti2 = item( curr + 1, 1 );
196 ti3 = item( curr + 1, 2 ); 197 ti3 = item( curr + 1, 2 );
197 takeItem( ti1 ); 198 takeItem( ti1 );
198 takeItem( ti2 ); 199 takeItem( ti2 );
199 takeItem( ti3 ); 200 takeItem( ti3 );
200 setItem( curr, 0, ti1 ); 201 setItem( curr, 0, ti1 );
201 setItem( curr, 1, ti2 ); 202 setItem( curr, 1, ti2 );
202 setItem( curr, 2, ti3 ); 203 setItem( curr, 2, ti3 );
203 } 204 }
204 setNumRows( totalRows - 1 ); 205 setNumRows( totalRows - 1 );
205} 206}
206 207
207#endif 208#endif
diff --git a/libopie/todoevent.cpp b/libopie/todoevent.cpp
index daa25f4..7dbf907 100644
--- a/libopie/todoevent.cpp
+++ b/libopie/todoevent.cpp
@@ -1,158 +1,176 @@
1 1
2#include <opie/todoevent.h> 2#include <opie/todoevent.h>
3#include <qpe/palmtopuidgen.h> 3#include <qpe/palmtopuidgen.h>
4#include <qpe/stringutil.h> 4#include <qpe/stringutil.h>
5//#include <qpe/palmtoprecord.h> 5#include <qpe/palmtoprecord.h>
6 6
7ToDoEvent::ToDoEvent(const ToDoEvent &event ) 7ToDoEvent::ToDoEvent(const ToDoEvent &event )
8{ 8{
9 *this = event; 9 *this = event;
10} 10}
11 11
12ToDoEvent::ToDoEvent(bool completed, int priority, const QString &category, 12ToDoEvent::ToDoEvent(bool completed, int priority, const QString &category,
13 const QString &description, bool hasDate, QDate date, int uid ) 13 const QString &description, bool hasDate, QDate date, int uid )
14{ 14{
15 qWarning("todoEvent c'tor" ); 15 qWarning("todoEvent c'tor" );
16 m_date = date; 16 m_date = date;
17 m_isCompleted = completed; 17 m_isCompleted = completed;
18 m_hasDate = hasDate; 18 m_hasDate = hasDate;
19 m_priority = priority; 19 m_priority = priority;
20 m_category = category; 20 m_category = category;
21 m_desc = Qtopia::simplifyMultiLineSpace(description ); 21 m_desc = Qtopia::simplifyMultiLineSpace(description );
22 if (uid == -1 ) { 22 if (uid == -1 ) {
23 Qtopia::UidGen *uidgen = new Qtopia::UidGen(); 23 Qtopia::UidGen *uidgen = new Qtopia::UidGen();
24 uid = uidgen->generate(); 24 uid = uidgen->generate();
25 delete uidgen; 25 delete uidgen;
26 }// generate the ids 26 }// generate the ids
27 m_uid = uid; 27 m_uid = uid;
28} 28}
29QArray<int> ToDoEvent::categories()const
30{
31 QArray<int> array(1); // currently the datebook can be only in one category
32 array = Qtopia::Record::idsFromString( category() );
33 return array;
34}
35bool ToDoEvent::match( const QRegExp &regExp )const
36{
37 if( QString::number( m_priority ).find( regExp ) != -1 ){
38 return true;
39 }else if( m_hasDate && m_date.toString().find( regExp) != -1 ){
40 return true;
41 }else if(m_desc.find( regExp ) != -1 ){
42 return true;
43 }
44 return false;
45}
29bool ToDoEvent::isCompleted() const 46bool ToDoEvent::isCompleted() const
30{ 47{
31 return m_isCompleted; 48 return m_isCompleted;
32} 49}
33bool ToDoEvent::hasDate() const 50bool ToDoEvent::hasDate() const
34{ 51{
35 return m_hasDate; 52 return m_hasDate;
36} 53}
37int ToDoEvent::priority()const 54int ToDoEvent::priority()const
38{ 55{
39 return m_priority; 56 return m_priority;
40} 57}
41QString ToDoEvent::category()const 58QString ToDoEvent::category()const
42{ 59{
43 return m_category; 60 return m_category;
44} 61}
45QDate ToDoEvent::date()const 62QDate ToDoEvent::date()const
46{ 63{
47 return m_date; 64 return m_date;
48} 65}
49QString ToDoEvent::description()const 66QString ToDoEvent::description()const
50{ 67{
51 return m_desc; 68 return m_desc;
52} 69}
53void ToDoEvent::setCompleted( bool completed ) 70void ToDoEvent::setCompleted( bool completed )
54{ 71{
55 m_isCompleted = completed; 72 m_isCompleted = completed;
56} 73}
57void ToDoEvent::setHasDate( bool hasDate ) 74void ToDoEvent::setHasDate( bool hasDate )
58{ 75{
59 m_hasDate = hasDate; 76 m_hasDate = hasDate;
60} 77}
61void ToDoEvent::setDescription(const QString &desc ) 78void ToDoEvent::setDescription(const QString &desc )
62{ 79{
63 m_desc = Qtopia::simplifyMultiLineSpace(desc ); 80 m_desc = Qtopia::simplifyMultiLineSpace(desc );
64} 81}
65void ToDoEvent::setCategory( const QString &cat ) 82void ToDoEvent::setCategory( const QString &cat )
66{ 83{
67 m_category = cat; 84 qWarning("setCategory %s", cat.latin1() );
85 m_category = cat;
68} 86}
69void ToDoEvent::setPriority(int prio ) 87void ToDoEvent::setPriority(int prio )
70{ 88{
71 m_priority = prio; 89 m_priority = prio;
72} 90}
73void ToDoEvent::setDate( QDate date ) 91void ToDoEvent::setDate( QDate date )
74{ 92{
75 m_date = date; 93 m_date = date;
76} 94}
77bool ToDoEvent::isOverdue( ) 95bool ToDoEvent::isOverdue( )
78{ 96{
79 if( m_hasDate ) 97 if( m_hasDate )
80 return QDate::currentDate() > m_date; 98 return QDate::currentDate() > m_date;
81 return false; 99 return false;
82} 100}
83bool ToDoEvent::operator<( const ToDoEvent &toDoEvent )const{ 101bool ToDoEvent::operator<( const ToDoEvent &toDoEvent )const{
84 if( !hasDate() && !toDoEvent.hasDate() ) return true; 102 if( !hasDate() && !toDoEvent.hasDate() ) return true;
85 if( !hasDate() && toDoEvent.hasDate() ) return true; 103 if( !hasDate() && toDoEvent.hasDate() ) return true;
86 if( hasDate() && toDoEvent.hasDate() ){ 104 if( hasDate() && toDoEvent.hasDate() ){
87 if( date() == toDoEvent.date() ){ // let's the priority decide 105 if( date() == toDoEvent.date() ){ // let's the priority decide
88 return priority() < toDoEvent.priority(); 106 return priority() < toDoEvent.priority();
89 }else{ 107 }else{
90 return date() < toDoEvent.date(); 108 return date() < toDoEvent.date();
91 } 109 }
92 } 110 }
93 return false; 111 return false;
94} 112}
95bool ToDoEvent::operator<=(const ToDoEvent &toDoEvent )const 113bool ToDoEvent::operator<=(const ToDoEvent &toDoEvent )const
96{ 114{
97 if( !hasDate() && !toDoEvent.hasDate() ) return true; 115 if( !hasDate() && !toDoEvent.hasDate() ) return true;
98 if( !hasDate() && toDoEvent.hasDate() ) return true; 116 if( !hasDate() && toDoEvent.hasDate() ) return true;
99 if( hasDate() && toDoEvent.hasDate() ){ 117 if( hasDate() && toDoEvent.hasDate() ){
100 if( date() == toDoEvent.date() ){ // let's the priority decide 118 if( date() == toDoEvent.date() ){ // let's the priority decide
101 return priority() <= toDoEvent.priority(); 119 return priority() <= toDoEvent.priority();
102 }else{ 120 }else{
103 return date() <= toDoEvent.date(); 121 return date() <= toDoEvent.date();
104 } 122 }
105 } 123 }
106 return true; 124 return true;
107} 125}
108bool ToDoEvent::operator>(const ToDoEvent &toDoEvent )const 126bool ToDoEvent::operator>(const ToDoEvent &toDoEvent )const
109{ 127{
110 if( !hasDate() && !toDoEvent.hasDate() ) return false; 128 if( !hasDate() && !toDoEvent.hasDate() ) return false;
111 if( !hasDate() && toDoEvent.hasDate() ) return false; 129 if( !hasDate() && toDoEvent.hasDate() ) return false;
112 if( hasDate() && toDoEvent.hasDate() ){ 130 if( hasDate() && toDoEvent.hasDate() ){
113 if( date() == toDoEvent.date() ){ // let's the priority decide 131 if( date() == toDoEvent.date() ){ // let's the priority decide
114 return priority() > toDoEvent.priority(); 132 return priority() > toDoEvent.priority();
115 }else{ 133 }else{
116 return date() > toDoEvent.date(); 134 return date() > toDoEvent.date();
117 } 135 }
118 } 136 }
119 return false; 137 return false;
120} 138}
121bool ToDoEvent::operator>=(const ToDoEvent &toDoEvent )const 139bool ToDoEvent::operator>=(const ToDoEvent &toDoEvent )const
122{ 140{
123 if( !hasDate() && !toDoEvent.hasDate() ) return true; 141 if( !hasDate() && !toDoEvent.hasDate() ) return true;
124 if( !hasDate() && toDoEvent.hasDate() ) return false; 142 if( !hasDate() && toDoEvent.hasDate() ) return false;
125 if( hasDate() && toDoEvent.hasDate() ){ 143 if( hasDate() && toDoEvent.hasDate() ){
126 if( date() == toDoEvent.date() ){ // let's the priority decide 144 if( date() == toDoEvent.date() ){ // let's the priority decide
127 return priority() > toDoEvent.priority(); 145 return priority() > toDoEvent.priority();
128 }else{ 146 }else{
129 return date() > toDoEvent.date(); 147 return date() > toDoEvent.date();
130 } 148 }
131 } 149 }
132 return true; 150 return true;
133} 151}
134bool ToDoEvent::operator==(const ToDoEvent &toDoEvent )const 152bool ToDoEvent::operator==(const ToDoEvent &toDoEvent )const
135{ 153{
136 if( m_date == toDoEvent.m_date && m_isCompleted == toDoEvent.m_isCompleted && m_hasDate == toDoEvent.m_hasDate && m_priority == toDoEvent.m_priority && m_category == toDoEvent.m_category && m_desc == toDoEvent.m_category ) 154 if( m_date == toDoEvent.m_date && m_isCompleted == toDoEvent.m_isCompleted && m_hasDate == toDoEvent.m_hasDate && m_priority == toDoEvent.m_priority && m_category == toDoEvent.m_category && m_desc == toDoEvent.m_category )
137 return true; 155 return true;
138 return false; 156 return false;
139} 157}
140ToDoEvent &ToDoEvent::operator=(const ToDoEvent &item ) 158ToDoEvent &ToDoEvent::operator=(const ToDoEvent &item )
141{ 159{
142 m_date = item.m_date; 160 m_date = item.m_date;
143 m_isCompleted = item.m_isCompleted; 161 m_isCompleted = item.m_isCompleted;
144 m_hasDate = item.m_hasDate; 162 m_hasDate = item.m_hasDate;
145 m_priority = item.m_priority; 163 m_priority = item.m_priority;
146 m_category = item.m_category; 164 m_category = item.m_category;
147 m_desc = item.m_desc; 165 m_desc = item.m_desc;
148 m_uid = item.m_uid; 166 m_uid = item.m_uid;
149 return *this; 167 return *this;
150} 168}
151 169
152 170
153 171
154 172
155 173
156 174
157 175
158 176
diff --git a/libopie/todoevent.h b/libopie/todoevent.h
index bca7f6e..ac996a1 100644
--- a/libopie/todoevent.h
+++ b/libopie/todoevent.h
@@ -1,54 +1,57 @@
1 1
2#ifndef todoevent_h 2#ifndef todoevent_h
3#define todoevent_h 3#define todoevent_h
4 4
5#include <qdatetime.h> 5#include <qdatetime.h>
6 6
7class ToDoEvent { 7class ToDoEvent {
8 friend class ToDoDB; 8 friend class ToDoDB;
9 public: 9 public:
10 enum Priority { VERYHIGH=1, HIGH, NORMAL, LOW, VERYLOW }; 10 enum Priority { VERYHIGH=1, HIGH, NORMAL, LOW, VERYLOW };
11 ToDoEvent( bool completed = false, int priority = NORMAL, 11 ToDoEvent( bool completed = false, int priority = NORMAL,
12 const QString &category = QString::null, 12 const QString &category = QString::null,
13 const QString &description = QString::null , 13 const QString &description = QString::null ,
14 bool hasDate = false, QDate date = QDate::currentDate(), int uid = -1 ); 14 bool hasDate = false, QDate date = QDate::currentDate(), int uid = -1 );
15 ToDoEvent(const ToDoEvent & ); 15 ToDoEvent(const ToDoEvent & );
16 bool isCompleted() const; 16 bool isCompleted() const;
17 bool hasDate() const; 17 bool hasDate() const;
18 int priority()const ; 18 int priority()const ;
19 QString category()const; 19 QString category()const;
20 QArray<int> categories() const;
20 QDate date()const; 21 QDate date()const;
21 QString description()const; 22 QString description()const;
22 23
23 int uid()const { return m_uid;}; 24 int uid()const { return m_uid;};
24 void setCompleted(bool completed ); 25 void setCompleted(bool completed );
25 void setHasDate( bool hasDate ); 26 void setHasDate( bool hasDate );
26 // if the category doesn't exist we will create it 27 // if the category doesn't exist we will create it
27 void setCategory( const QString &category ); 28 void setCategory( const QString &category );
28 void setPriority(int priority ); 29 void setPriority(int priority );
29 void setDate( QDate date ); 30 void setDate( QDate date );
30 void setDescription(const QString& ); 31 void setDescription(const QString& );
31 bool isOverdue(); 32 bool isOverdue();
32 33
34 bool match( const QRegExp &r )const;
35
33 void setUid(int id) {m_uid = id; }; 36 void setUid(int id) {m_uid = id; };
34 bool operator<(const ToDoEvent &toDoEvent )const; 37 bool operator<(const ToDoEvent &toDoEvent )const;
35 bool operator<=(const ToDoEvent &toDoEvent )const; 38 bool operator<=(const ToDoEvent &toDoEvent )const;
36 bool operator!=(const ToDoEvent &toDoEvent )const { return !(*this == toDoEvent); }; 39 bool operator!=(const ToDoEvent &toDoEvent )const { return !(*this == toDoEvent); };
37 bool operator>(const ToDoEvent &toDoEvent )const; 40 bool operator>(const ToDoEvent &toDoEvent )const;
38 bool operator>=(const ToDoEvent &toDoEvent)const; 41 bool operator>=(const ToDoEvent &toDoEvent)const;
39 bool operator==(const ToDoEvent &toDoEvent )const; 42 bool operator==(const ToDoEvent &toDoEvent )const;
40 ToDoEvent &operator=(const ToDoEvent &toDoEvent ); 43 ToDoEvent &operator=(const ToDoEvent &toDoEvent );
41 private: 44 private:
42 class ToDoEventPrivate; 45 class ToDoEventPrivate;
43 ToDoEventPrivate *d; 46 ToDoEventPrivate *d;
44 QDate m_date; 47 QDate m_date;
45 bool m_isCompleted:1; 48 bool m_isCompleted:1;
46 bool m_hasDate:1; 49 bool m_hasDate:1;
47 int m_priority; 50 int m_priority;
48 QString m_category; 51 QString m_category;
49 QString m_desc; 52 QString m_desc;
50 int m_uid; 53 int m_uid;
51}; 54};
52 55
53 56
54#endif 57#endif