Diffstat (limited to 'core/pim/todo/mainwindow.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | core/pim/todo/mainwindow.cpp | 27 |
1 files changed, 16 insertions, 11 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,83 +1,86 @@ | |||
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 | ||
53 | static QString todolistXMLFilename() | 56 | static QString todolistXMLFilename() |
54 | { | 57 | { |
55 | return Global::applicationFileName("todolist","todolist.xml"); | 58 | return Global::applicationFileName("todolist","todolist.xml"); |
56 | } | 59 | } |
57 | 60 | ||
58 | static QString categoriesXMLFilename() | 61 | static QString categoriesXMLFilename() |
59 | { | 62 | { |
60 | return Global::applicationFileName("todolist","categories.xml"); | 63 | return Global::applicationFileName("todolist","categories.xml"); |
61 | } | 64 | } |
62 | 65 | ||
63 | TodoWindow::TodoWindow( QWidget *parent, const char *name, WFlags f = 0 ) : | 66 | TodoWindow::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" |
@@ -170,301 +173,303 @@ TodoWindow::TodoWindow( QWidget *parent, const char *name, WFlags f = 0 ) : | |||
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 | ||
202 | void TodoWindow::slotNew() | 205 | void 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 | ||
238 | TodoWindow::~TodoWindow() | 241 | TodoWindow::~TodoWindow() |
239 | { | 242 | { |
240 | } | 243 | } |
241 | 244 | ||
242 | void TodoWindow::slotDelete() | 245 | void 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 | ||
270 | void TodoWindow::slotEdit() | 273 | void 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 | ||
298 | void TodoWindow::slotShowPopup( const QPoint &p ) | 301 | void TodoWindow::slotShowPopup( const QPoint &p ) |
299 | { | 302 | { |
300 | contextMenu->popup( p ); | 303 | contextMenu->popup( p ); |
301 | } | 304 | } |
302 | 305 | ||
303 | void TodoWindow::showCompleted( bool s ) | 306 | void 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 | ||
312 | void TodoWindow::currentEntryChanged( int r, int ) | 315 | void 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 | ||
323 | void TodoWindow::setCategory( int c ) | 326 | void 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 | ||
345 | void TodoWindow::populateCategories() | 348 | void 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 | ||
372 | void TodoWindow::reload() | 374 | void 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 | ||
379 | void TodoWindow::flush() | 381 | void TodoWindow::flush() |
380 | { | 382 | { |
381 | syncing = TRUE; | 383 | syncing = TRUE; |
382 | table->save( todolistXMLFilename() ); | 384 | table->save( todolistXMLFilename() ); |
383 | } | 385 | } |
384 | 386 | ||
385 | void TodoWindow::closeEvent( QCloseEvent *e ) | 387 | void 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 | ||
419 | void TodoWindow::slotFind() | 421 | void 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 | ||
442 | void TodoWindow::setDocument( const QString &filename ) | 444 | void 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 | ||
452 | static const char * beamfile = "/tmp/obex/todo.vcs"; | 455 | static const char * beamfile = "/tmp/obex/todo.vcs"; |
453 | 456 | ||
454 | void TodoWindow::slotBeam() | 457 | void 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 | ||
466 | void TodoWindow::beamDone( Ir *ir ) | 471 | void TodoWindow::beamDone( Ir *ir ) |
467 | { | 472 | { |
468 | delete ir; | 473 | delete ir; |
469 | unlink( beamfile ); | 474 | unlink( beamfile ); |
470 | } | 475 | } |