summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--core/pim/todo/mainwindow.cpp1
1 files changed, 1 insertions, 0 deletions
diff --git a/core/pim/todo/mainwindow.cpp b/core/pim/todo/mainwindow.cpp
index 1358f1c..fa9c221 100644
--- a/core/pim/todo/mainwindow.cpp
+++ b/core/pim/todo/mainwindow.cpp
@@ -1,627 +1,628 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved. 2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3** Copyright (C) 2002 zecke 3** Copyright (C) 2002 zecke
4** Copyright (C) 2002 Stefan Eilers (se, eilers.stefan@epost.de) 4** Copyright (C) 2002 Stefan Eilers (se, eilers.stefan@epost.de)
5** 5**
6** This file is part of Qtopia Environment. 6** This file is part of Qtopia Environment.
7** 7**
8** This file may be distributed and/or modified under the terms of the 8** This file may be distributed and/or modified under the terms of the
9** GNU General Public License version 2 as published by the Free Software 9** GNU General Public License version 2 as published by the Free Software
10** Foundation and appearing in the file LICENSE.GPL included in the 10** Foundation and appearing in the file LICENSE.GPL included in the
11** packaging of this file. 11** packaging of this file.
12** 12**
13** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 13** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
14** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 14** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
15** 15**
16** See http://www.trolltech.com/gpl/ for GPL licensing information. 16** See http://www.trolltech.com/gpl/ for GPL licensing information.
17** 17**
18** Contact info@trolltech.com if any conditions of this licensing are 18** Contact info@trolltech.com if any conditions of this licensing are
19** not clear to you. 19** not clear to you.
20** 20**
21**********************************************************************/ 21**********************************************************************/
22 22
23#define QTOPIA_INTERNAL_FD 23#define QTOPIA_INTERNAL_FD
24 24
25#include "mainwindow.h" 25#include "mainwindow.h"
26#include "todoentryimpl.h" 26#include "todoentryimpl.h"
27#include "todotable.h" 27#include "todotable.h"
28#include "todolabel.h" 28#include "todolabel.h"
29 29
30#include <opie/tododb.h> 30#include <opie/tododb.h>
31#include <opie/todovcalresource.h> 31#include <opie/todovcalresource.h>
32#include <opie/ofontmenu.h> 32#include <opie/ofontmenu.h>
33 33
34#include <qpe/qpeapplication.h> 34#include <qpe/qpeapplication.h>
35#include <qpe/config.h> 35#include <qpe/config.h>
36#include <qpe/finddialog.h> 36#include <qpe/finddialog.h>
37#include <qpe/global.h> 37#include <qpe/global.h>
38#include <qpe/ir.h> 38#include <qpe/ir.h>
39#include <qpe/qpemenubar.h> 39#include <qpe/qpemenubar.h>
40#include <qpe/qpemessagebox.h> 40#include <qpe/qpemessagebox.h>
41#include <qpe/resource.h> 41#include <qpe/resource.h>
42//#include <qpe/task.h> 42//#include <qpe/task.h>
43#include <qpe/qpetoolbar.h> 43#include <qpe/qpetoolbar.h>
44 44
45#include <qaction.h> 45#include <qaction.h>
46#include <qarray.h> 46#include <qarray.h>
47#include <qdatastream.h> 47#include <qdatastream.h>
48#include <qdatetime.h> 48#include <qdatetime.h>
49#include <qfile.h> 49#include <qfile.h>
50#include <qmessagebox.h> 50#include <qmessagebox.h>
51#include <qpopupmenu.h> 51#include <qpopupmenu.h>
52#include <qwidgetstack.h> 52#include <qwidgetstack.h>
53 53
54#include <sys/stat.h> 54#include <sys/stat.h>
55#include <sys/types.h> 55#include <sys/types.h>
56#include <fcntl.h> 56#include <fcntl.h>
57#include <unistd.h> 57#include <unistd.h>
58 58
59#include <stdlib.h> 59#include <stdlib.h>
60 60
61static QString todolistXMLFilename() 61static QString todolistXMLFilename()
62{ 62{
63 return Global::applicationFileName("todolist","todolist.xml"); 63 return Global::applicationFileName("todolist","todolist.xml");
64} 64}
65 65
66static QString categoriesXMLFilename() 66static QString categoriesXMLFilename()
67{ 67{
68 return Global::applicationFileName("todolist","categories.xml"); 68 return Global::applicationFileName("todolist","categories.xml");
69} 69}
70 70
71TodoWindow::TodoWindow( QWidget *parent, const char *name, WFlags f ) : 71TodoWindow::TodoWindow( QWidget *parent, const char *name, WFlags f ) :
72 QMainWindow( parent, name, f ), syncing(FALSE) 72 QMainWindow( parent, name, f ), syncing(FALSE)
73{ 73{
74// QTime t; 74// QTime t;
75// t.start(); 75// t.start();
76 mView = 0l; 76 mView = 0l;
77 mStack = new QWidgetStack(this, "main stack"); 77 mStack = new QWidgetStack(this, "main stack");
78 setCentralWidget( mStack );
78 setCaption( tr("Todo") ); 79 setCaption( tr("Todo") );
79 QString str; 80 QString str;
80 table = new TodoTable( this ); 81 table = new TodoTable( this );
81 table->setColumnWidth( 2, 10 ); 82 table->setColumnWidth( 2, 10 );
82 table->setPaintingEnabled( FALSE ); 83 table->setPaintingEnabled( FALSE );
83 table->setUpdatesEnabled( FALSE ); 84 table->setUpdatesEnabled( FALSE );
84 table->viewport()->setUpdatesEnabled( FALSE ); 85 table->viewport()->setUpdatesEnabled( FALSE );
85 86
86 { 87 {
87 str = todolistXMLFilename(); 88 str = todolistXMLFilename();
88 if ( str.isNull() ) 89 if ( str.isNull() )
89 QMessageBox::critical( this, 90 QMessageBox::critical( this,
90 tr("Out of Space"), 91 tr("Out of Space"),
91 tr("Unable to create startup files\n" 92 tr("Unable to create startup files\n"
92 "Free up some space\n" 93 "Free up some space\n"
93 "before you enter any data") ); 94 "before you enter any data") );
94 else 95 else
95 table->load( str ); 96 table->load( str );
96 } 97 }
97 98
98 // repeat for categories... 99 // repeat for categories...
99 str = categoriesXMLFilename(); 100 str = categoriesXMLFilename();
100 if ( str.isNull() ) 101 if ( str.isNull() )
101 QMessageBox::critical( this, 102 QMessageBox::critical( this,
102 tr( "Out of Space" ), 103 tr( "Out of Space" ),
103 tr( "Unable to create startup files\n" 104 tr( "Unable to create startup files\n"
104 "Free up some space\n" 105 "Free up some space\n"
105 "before you enter any data") ); 106 "before you enter any data") );
106 107
107 mStack->addWidget(table, 1 ); 108 mStack->addWidget(table, 1 );
108 mStack->raiseWidget( 1 ); 109 mStack->raiseWidget( 1 );
109 setCentralWidget( mStack ); 110 setCentralWidget( mStack );
110 setToolBarsMovable( FALSE ); 111 setToolBarsMovable( FALSE );
111 112
112// qDebug("after load: t=%d", t.elapsed() ); 113// qDebug("after load: t=%d", t.elapsed() );
113 114
114 Config config( "todo" ); 115 Config config( "todo" );
115 config.setGroup( "View" ); 116 config.setGroup( "View" );
116 bool complete = config.readBoolEntry( "ShowComplete", true ); 117 bool complete = config.readBoolEntry( "ShowComplete", true );
117 table->setShowCompleted( complete ); 118 table->setShowCompleted( complete );
118 119
119 bool showdeadline = config.readBoolEntry("ShowDeadLine", true); 120 bool showdeadline = config.readBoolEntry("ShowDeadLine", true);
120 table->setShowDeadline (showdeadline); 121 table->setShowDeadline (showdeadline);
121 122
122 QString category = config.readEntry( "Category", QString::null ); 123 QString category = config.readEntry( "Category", QString::null );
123 table->setShowCategory( category ); 124 table->setShowCategory( category );
124 125
125 QPEToolBar *bar = new QPEToolBar( this ); 126 QPEToolBar *bar = new QPEToolBar( this );
126 bar->setHorizontalStretchable( TRUE ); 127 bar->setHorizontalStretchable( TRUE );
127 128
128 QPEMenuBar *mb = new QPEMenuBar( bar ); 129 QPEMenuBar *mb = new QPEMenuBar( bar );
129 130
130 catMenu = new QPopupMenu( this ); 131 catMenu = new QPopupMenu( this );
131 QPopupMenu *edit = new QPopupMenu( this ); 132 QPopupMenu *edit = new QPopupMenu( this );
132 QPopupMenu *options = new QPopupMenu(this ); 133 QPopupMenu *options = new QPopupMenu(this );
133 134
134 contextMenu = new QPopupMenu( this ); 135 contextMenu = new QPopupMenu( this );
135 136
136 bar = new QPEToolBar( this ); 137 bar = new QPEToolBar( this );
137 138
138 QAction *a = new QAction( tr( "New Task" ), Resource::loadPixmap( "new" ), 139 QAction *a = new QAction( tr( "New Task" ), Resource::loadPixmap( "new" ),
139 QString::null, 0, this, 0 ); 140 QString::null, 0, this, 0 );
140 connect( a, SIGNAL( activated() ), 141 connect( a, SIGNAL( activated() ),
141 this, SLOT( slotNew() ) ); 142 this, SLOT( slotNew() ) );
142 a->addTo( bar ); 143 a->addTo( bar );
143 a->addTo( edit ); 144 a->addTo( edit );
144 145
145 a = new QAction( tr( "Edit Task" ), Resource::loadIconSet( "edit" ), 146 a = new QAction( tr( "Edit Task" ), Resource::loadIconSet( "edit" ),
146 QString::null, 0, this, 0 ); 147 QString::null, 0, this, 0 );
147 connect( a, SIGNAL( activated() ), 148 connect( a, SIGNAL( activated() ),
148 this, SLOT( slotEdit() ) ); 149 this, SLOT( slotEdit() ) );
149 a->addTo( bar ); 150 a->addTo( bar );
150 a->addTo( edit ); 151 a->addTo( edit );
151 a->addTo( contextMenu ); 152 a->addTo( contextMenu );
152 a->setEnabled( FALSE ); 153 a->setEnabled( FALSE );
153 editAction = a; 154 editAction = a;
154 155
155 a = new QAction( QString::null, tr("View Task"), 0, this, 0 ); 156 a = new QAction( QString::null, tr("View Task"), 0, this, 0 );
156 a->addTo( edit ); 157 a->addTo( edit );
157 a->addTo( contextMenu ); 158 a->addTo( contextMenu );
158 connect( a, SIGNAL( activated() ), 159 connect( a, SIGNAL( activated() ),
159 this, SLOT(slotShowDetails() ) ); 160 this, SLOT(slotShowDetails() ) );
160 161
161 edit->insertSeparator(); 162 edit->insertSeparator();
162 163
163 a = new QAction( tr( "Delete..." ), Resource::loadIconSet( "trash" ), 164 a = new QAction( tr( "Delete..." ), Resource::loadIconSet( "trash" ),
164 QString::null, 0, this, 0 ); 165 QString::null, 0, this, 0 );
165 connect( a, SIGNAL( activated() ), 166 connect( a, SIGNAL( activated() ),
166 this, SLOT( slotDelete() ) ); 167 this, SLOT( slotDelete() ) );
167 a->addTo( bar ); 168 a->addTo( bar );
168 a->addTo( edit ); 169 a->addTo( edit );
169 a->addTo( contextMenu ); 170 a->addTo( contextMenu );
170 a->setEnabled( FALSE ); 171 a->setEnabled( FALSE );
171 deleteAction = a; 172 deleteAction = a;
172 173
173 // delete All in category is missing.... 174 // delete All in category is missing....
174 // set All Done 175 // set All Done
175 // set All Done in category 176 // set All Done in category
176 177
177 a = new QAction( QString::null, tr( "Delete all..."), 0, this, 0 ); 178 a = new QAction( QString::null, tr( "Delete all..."), 0, this, 0 );
178 connect(a, SIGNAL( activated() ), 179 connect(a, SIGNAL( activated() ),
179 this, SLOT( slotDeleteAll() ) ); 180 this, SLOT( slotDeleteAll() ) );
180 a->addTo(edit ); 181 a->addTo(edit );
181 a->setEnabled( FALSE ); 182 a->setEnabled( FALSE );
182 deleteAllAction = a; 183 deleteAllAction = a;
183 184
184 edit->insertSeparator(); 185 edit->insertSeparator();
185 a = new QAction( QString::null, tr("Duplicate" ), 0, this, 0 ); 186 a = new QAction( QString::null, tr("Duplicate" ), 0, this, 0 );
186 connect(a, SIGNAL( activated() ), 187 connect(a, SIGNAL( activated() ),
187 this, SLOT( slotDuplicate() ) ); 188 this, SLOT( slotDuplicate() ) );
188 a->addTo(edit ); 189 a->addTo(edit );
189 a->setEnabled( FALSE ); 190 a->setEnabled( FALSE );
190 duplicateAction = a; 191 duplicateAction = a;
191 edit->insertSeparator(); 192 edit->insertSeparator();
192 193
193 194
194 195
195 if ( Ir::supported() ) { 196 if ( Ir::supported() ) {
196 a = new QAction( tr( "Beam" ), Resource::loadPixmap( "beam" ), 197 a = new QAction( tr( "Beam" ), Resource::loadPixmap( "beam" ),
197 QString::null, 0, this, 0 ); 198 QString::null, 0, this, 0 );
198 connect( a, SIGNAL( activated() ), 199 connect( a, SIGNAL( activated() ),
199 this, SLOT( slotBeam() ) ); 200 this, SLOT( slotBeam() ) );
200 a->addTo( edit ); 201 a->addTo( edit );
201 a->addTo( bar ); 202 a->addTo( bar );
202 } 203 }
203 204
204 a = new QAction( tr( "Find" ), Resource::loadIconSet( "mag" ), 205 a = new QAction( tr( "Find" ), Resource::loadIconSet( "mag" ),
205 QString::null, 0, this, 0 ); 206 QString::null, 0, this, 0 );
206 connect( a, SIGNAL( activated() ), 207 connect( a, SIGNAL( activated() ),
207 this, SLOT( slotFind() ) ); 208 this, SLOT( slotFind() ) );
208 a->addTo( bar ); 209 a->addTo( bar );
209 a->addTo( options ); 210 a->addTo( options );
210 options->insertSeparator(); 211 options->insertSeparator();
211 212
212 if ( table->numRows() ) 213 if ( table->numRows() )
213 a->setEnabled( TRUE ); 214 a->setEnabled( TRUE );
214 else 215 else
215 a->setEnabled( FALSE ); 216 a->setEnabled( FALSE );
216 217
217 //a->setEnabled( FALSE ); 218 //a->setEnabled( FALSE );
218 findAction = a; 219 findAction = a;
219// qDebug("mainwindow #2: t=%d", t.elapsed() ); 220// qDebug("mainwindow #2: t=%d", t.elapsed() );
220 221
221 completedAction = new QAction( QString::null, tr("Completed tasks"), 0, this, 0, TRUE ); 222 completedAction = new QAction( QString::null, tr("Completed tasks"), 0, this, 0, TRUE );
222 223
223 showdeadlineAction = new QAction( QString::null, tr( "Show Deadline" ), 0, this, 0, TRUE ); 224 showdeadlineAction = new QAction( QString::null, tr( "Show Deadline" ), 0, this, 0, TRUE );
224 225
225 catMenu->setCheckable( true ); 226 catMenu->setCheckable( true );
226 populateCategories(); 227 populateCategories();
227 228
228 229
229 completedAction->addTo( options ); 230 completedAction->addTo( options );
230 completedAction->setOn( table->showCompleted() ); 231 completedAction->setOn( table->showCompleted() );
231 showdeadlineAction->addTo( options ); 232 showdeadlineAction->addTo( options );
232 showdeadlineAction->setOn( table->showDeadline() ); 233 showdeadlineAction->setOn( table->showDeadline() );
233 options->insertSeparator( ); 234 options->insertSeparator( );
234 QList<QWidget> list; 235 QList<QWidget> list;
235 list.append(table ); 236 list.append(table );
236 OFontMenu *menu = new OFontMenu(this, "menu",list ); 237 OFontMenu *menu = new OFontMenu(this, "menu",list );
237 menu->forceSize( table->horizontalHeader(), 10 ); 238 menu->forceSize( table->horizontalHeader(), 10 );
238 //catMenu->insertItem(tr("Fonts"), menu ); 239 //catMenu->insertItem(tr("Fonts"), menu );
239 list.clear(); 240 list.clear();
240 options->insertItem( tr("Fonts"), menu ); 241 options->insertItem( tr("Fonts"), menu );
241 242
242 243
243 mb->insertItem( tr( "Data" ), edit ); 244 mb->insertItem( tr( "Data" ), edit );
244 mb->insertItem( tr( "Category" ), catMenu ); 245 mb->insertItem( tr( "Category" ), catMenu );
245 mb->insertItem( tr( "Options"), options ); 246 mb->insertItem( tr( "Options"), options );
246 resize( 200, 300 ); 247 resize( 200, 300 );
247 if ( table->numRows() > 0 ) 248 if ( table->numRows() > 0 )
248 currentEntryChanged( 0, 0 ); 249 currentEntryChanged( 0, 0 );
249 connect( table, SIGNAL( signalEdit() ), 250 connect( table, SIGNAL( signalEdit() ),
250 this, SLOT( slotEdit() ) ); 251 this, SLOT( slotEdit() ) );
251 connect( table, SIGNAL(signalShowMenu(const QPoint &)), 252 connect( table, SIGNAL(signalShowMenu(const QPoint &)),
252 this, SLOT( slotShowPopup(const QPoint &)) ); 253 this, SLOT( slotShowPopup(const QPoint &)) );
253 254
254// qDebug("mainwindow #3: t=%d", t.elapsed() ); 255// qDebug("mainwindow #3: t=%d", t.elapsed() );
255 table->updateVisible(); 256 table->updateVisible();
256 table->setUpdatesEnabled( TRUE ); 257 table->setUpdatesEnabled( TRUE );
257 table->setPaintingEnabled( TRUE ); 258 table->setPaintingEnabled( TRUE );
258 table->viewport()->setUpdatesEnabled( TRUE ); 259 table->viewport()->setUpdatesEnabled( TRUE );
259 260
260 // Initialize the table 261 // Initialize the table
261 table->updateVisible(); 262 table->updateVisible();
262 263
263 connect( completedAction, SIGNAL( toggled(bool) ), this, SLOT( showCompleted(bool) ) ); 264 connect( completedAction, SIGNAL( toggled(bool) ), this, SLOT( showCompleted(bool) ) );
264 connect( showdeadlineAction, SIGNAL( toggled(bool) ), this, SLOT( showDeadline(bool) ) ); 265 connect( showdeadlineAction, SIGNAL( toggled(bool) ), this, SLOT( showDeadline(bool) ) );
265 connect( catMenu, SIGNAL(activated(int)), this, SLOT(setCategory(int)) ); 266 connect( catMenu, SIGNAL(activated(int)), this, SLOT(setCategory(int)) );
266 connect( table, SIGNAL( currentChanged( int, int ) ), 267 connect( table, SIGNAL( currentChanged( int, int ) ),
267 this, SLOT( currentEntryChanged( int, int ) ) ); 268 this, SLOT( currentEntryChanged( int, int ) ) );
268 269
269 connect( table, SIGNAL(showDetails(const ToDoEvent &) ), 270 connect( table, SIGNAL(showDetails(const ToDoEvent &) ),
270 this, SLOT(slotShowDetails(const ToDoEvent & ) ) ); 271 this, SLOT(slotShowDetails(const ToDoEvent & ) ) );
271// qDebug("done: t=%d", t.elapsed() ); 272// qDebug("done: t=%d", t.elapsed() );
272} 273}
273 274
274void TodoWindow::slotNew() 275void TodoWindow::slotNew()
275{ 276{
276 if(syncing) { 277 if(syncing) {
277 QMessageBox::warning(this, tr("Todo"), 278 QMessageBox::warning(this, tr("Todo"),
278 tr("Can not edit data, currently syncing")); 279 tr("Can not edit data, currently syncing"));
279 return; 280 return;
280 } 281 }
281 282
282 int id; 283 int id;
283 id = -1; 284 id = -1;
284 QArray<int> ids; 285 QArray<int> ids;
285 ids = table->currentEntry().categories(); 286 ids = table->currentEntry().categories();
286 if ( ids.count() ) 287 if ( ids.count() )
287 id = ids[0]; 288 id = ids[0];
288 NewTaskDialog e( id, this, 0, TRUE ); 289 NewTaskDialog e( id, this, 0, TRUE );
289 290
290 ToDoEvent todo; 291 ToDoEvent todo;
291 292
292#if defined(Q_WS_QWS) || defined(_WS_QWS_) 293#if defined(Q_WS_QWS) || defined(_WS_QWS_)
293 e.showMaximized(); 294 e.showMaximized();
294#endif 295#endif
295 int ret = e.exec(); 296 int ret = e.exec();
296// qWarning("finished" ); 297// qWarning("finished" );
297 if ( ret == QDialog::Accepted ) { 298 if ( ret == QDialog::Accepted ) {
298 table->setPaintingEnabled( false ); 299 table->setPaintingEnabled( false );
299 todo = e.todoEntry(); 300 todo = e.todoEntry();
300 //todo.assignUid(); 301 //todo.assignUid();
301 table->addEntry( todo ); 302 table->addEntry( todo );
302 table->setPaintingEnabled( true ); 303 table->setPaintingEnabled( true );
303 findAction->setEnabled( TRUE ); 304 findAction->setEnabled( TRUE );
304 } 305 }
305 // I'm afraid we must call this every time now, otherwise 306 // I'm afraid we must call this every time now, otherwise
306 // spend expensive time comparing all these strings... 307 // spend expensive time comparing all these strings...
307 populateCategories(); 308 populateCategories();
308 mStack->raiseWidget(1 ); 309 mStack->raiseWidget(1 );
309} 310}
310 311
311TodoWindow::~TodoWindow() 312TodoWindow::~TodoWindow()
312{ 313{
313} 314}
314 315
315void TodoWindow::slotDelete() 316void TodoWindow::slotDelete()
316{ 317{
317 if(syncing) { 318 if(syncing) {
318 QMessageBox::warning(this, tr("Todo"), 319 QMessageBox::warning(this, tr("Todo"),
319 tr("Can not edit data, currently syncing")); 320 tr("Can not edit data, currently syncing"));
320 return; 321 return;
321 } 322 }
322 323
323 if ( table->currentRow() == -1 ) 324 if ( table->currentRow() == -1 )
324 return; 325 return;
325 326
326 QString strName = table->text( table->currentRow(), 2 ).left( 30 ); 327 QString strName = table->text( table->currentRow(), 2 ).left( 30 );
327 328
328 if ( !QPEMessageBox::confirmDelete( this, tr( "Todo" ), strName ) ) 329 if ( !QPEMessageBox::confirmDelete( this, tr( "Todo" ), strName ) )
329 return; 330 return;
330 331
331 332
332 333
333 table->setPaintingEnabled( false ); 334 table->setPaintingEnabled( false );
334 table->removeCurrentEntry(); 335 table->removeCurrentEntry();
335 table->setPaintingEnabled( true ); 336 table->setPaintingEnabled( true );
336 337
337 if ( table->numRows() == 0 ) { 338 if ( table->numRows() == 0 ) {
338 currentEntryChanged( -1, 0 ); 339 currentEntryChanged( -1, 0 );
339 findAction->setEnabled( FALSE ); 340 findAction->setEnabled( FALSE );
340 } 341 }
341 mStack->raiseWidget(1); 342 mStack->raiseWidget(1);
342} 343}
343void TodoWindow::slotDeleteAll() 344void TodoWindow::slotDeleteAll()
344{ 345{
345 if(syncing) { 346 if(syncing) {
346 QMessageBox::warning(this, tr("Todo"), 347 QMessageBox::warning(this, tr("Todo"),
347 tr("Can not edit data, currently syncing")); 348 tr("Can not edit data, currently syncing"));
348 return; 349 return;
349 } 350 }
350 351
351 //QString strName = table->text( table->currentRow(), 2 ).left( 30 ); 352 //QString strName = table->text( table->currentRow(), 2 ).left( 30 );
352 353
353 if ( !QPEMessageBox::confirmDelete( this, tr( "Todo" ), tr("Delete all tasks?") ) ) 354 if ( !QPEMessageBox::confirmDelete( this, tr( "Todo" ), tr("Delete all tasks?") ) )
354 return; 355 return;
355 356
356 357
357 358
358 table->setPaintingEnabled( false ); 359 table->setPaintingEnabled( false );
359 table->removeAllEntries(); 360 table->removeAllEntries();
360 table->setPaintingEnabled( true ); 361 table->setPaintingEnabled( true );
361 362
362 if ( table->numRows() == 0 ) { 363 if ( table->numRows() == 0 ) {
363 currentEntryChanged( -1, 0 ); 364 currentEntryChanged( -1, 0 );
364 findAction->setEnabled( FALSE ); 365 findAction->setEnabled( FALSE );
365 } 366 }
366 mStack->raiseWidget(1 ); 367 mStack->raiseWidget(1 );
367} 368}
368 369
369void TodoWindow::slotEdit() 370void TodoWindow::slotEdit()
370{ 371{
371 if(syncing) { 372 if(syncing) {
372 QMessageBox::warning(this, tr("Todo"), 373 QMessageBox::warning(this, tr("Todo"),
373 tr("Can not edit data, currently syncing")); 374 tr("Can not edit data, currently syncing"));
374 return; 375 return;
375 } 376 }
376 377
377 ToDoEvent todo = table->currentEntry(); 378 ToDoEvent todo = table->currentEntry();
378 qWarning("slotEdit" ); 379 qWarning("slotEdit" );
379 NewTaskDialog e( todo, this, 0, TRUE ); 380 NewTaskDialog e( todo, this, 0, TRUE );
380 e.setCaption( tr( "Edit Task" ) ); 381 e.setCaption( tr( "Edit Task" ) );
381 382
382#if defined(Q_WS_QWS) || defined(_WS_QWS_) 383#if defined(Q_WS_QWS) || defined(_WS_QWS_)
383 e.showMaximized(); 384 e.showMaximized();
384#endif 385#endif
385 int ret = e.exec(); 386 int ret = e.exec();
386 387
387 if ( ret == QDialog::Accepted ) { 388 if ( ret == QDialog::Accepted ) {
388 qWarning("Replacing now" ); 389 qWarning("Replacing now" );
389 table->setPaintingEnabled( false ); 390 table->setPaintingEnabled( false );
390 todo = e.todoEntry(); 391 todo = e.todoEntry();
391 table->replaceCurrentEntry( todo ); 392 table->replaceCurrentEntry( todo );
392 table->setPaintingEnabled( true ); 393 table->setPaintingEnabled( true );
393 } 394 }
394 populateCategories(); 395 populateCategories();
395 mStack->raiseWidget( 1 ); 396 mStack->raiseWidget( 1 );
396} 397}
397void TodoWindow::slotDuplicate() 398void TodoWindow::slotDuplicate()
398{ 399{
399 if(syncing) { 400 if(syncing) {
400 QMessageBox::warning(this, tr("Todo"), 401 QMessageBox::warning(this, tr("Todo"),
401 tr("Can not edit data, currently syncing")); 402 tr("Can not edit data, currently syncing"));
402 return; 403 return;
403 } 404 }
404 ToDoEvent ev = table->currentEntry(); 405 ToDoEvent ev = table->currentEntry();
405 ToDoEvent ev2 = ToDoEvent( ev ); // what about the uid 406 ToDoEvent ev2 = ToDoEvent( ev ); // what about the uid
406 int uid; 407 int uid;
407 { // uid 408 { // uid
408 Qtopia::UidGen *uidgen = new Qtopia::UidGen(); 409 Qtopia::UidGen *uidgen = new Qtopia::UidGen();
409 uid = uidgen->generate(); 410 uid = uidgen->generate();
410 delete uidgen; 411 delete uidgen;
411 } 412 }
412 ev2.setUid( uid ); 413 ev2.setUid( uid );
413 table->setPaintingEnabled( false ); 414 table->setPaintingEnabled( false );
414 table->addEntry( ev2 ); 415 table->addEntry( ev2 );
415 table->setPaintingEnabled( true ); 416 table->setPaintingEnabled( true );
416 417
417 mStack->raiseWidget( 1 ); 418 mStack->raiseWidget( 1 );
418} 419}
419void TodoWindow::slotShowPopup( const QPoint &p ) 420void TodoWindow::slotShowPopup( const QPoint &p )
420{ 421{
421 contextMenu->popup( p ); 422 contextMenu->popup( p );
422} 423}
423 424
424void TodoWindow::showCompleted( bool s ) 425void TodoWindow::showCompleted( bool s )
425{ 426{
426 if ( !table->isUpdatesEnabled() ) 427 if ( !table->isUpdatesEnabled() )
427 return; 428 return;
428 table->setPaintingEnabled( false ); 429 table->setPaintingEnabled( false );
429 table->setShowCompleted( s ); 430 table->setShowCompleted( s );
430 table->setPaintingEnabled( true ); 431 table->setPaintingEnabled( true );
431 mStack->raiseWidget( 1 ); 432 mStack->raiseWidget( 1 );
432} 433}
433 434
434void TodoWindow::currentEntryChanged( int r, int ) 435void TodoWindow::currentEntryChanged( int r, int )
435{ 436{
436 if ( r != -1 && table->rowHeight( r ) > 0 ) { 437 if ( r != -1 && table->rowHeight( r ) > 0 ) {
437 editAction->setEnabled( TRUE ); 438 editAction->setEnabled( TRUE );
438 deleteAction->setEnabled( TRUE ); 439 deleteAction->setEnabled( TRUE );
439 duplicateAction->setEnabled( TRUE ); 440 duplicateAction->setEnabled( TRUE );
440 deleteAllAction->setEnabled( TRUE ); 441 deleteAllAction->setEnabled( TRUE );
441 } else { 442 } else {
442 editAction->setEnabled( FALSE ); 443 editAction->setEnabled( FALSE );
443 deleteAction->setEnabled( FALSE ); 444 deleteAction->setEnabled( FALSE );
444 duplicateAction->setEnabled( FALSE ); 445 duplicateAction->setEnabled( FALSE );
445 deleteAllAction->setEnabled( FALSE ); 446 deleteAllAction->setEnabled( FALSE );
446 } 447 }
447} 448}
448 449
449void TodoWindow::setCategory( int c ) 450void TodoWindow::setCategory( int c )
450{ 451{
451 if ( c <= 0 ) return; 452 if ( c <= 0 ) return;
452 if ( !table->isUpdatesEnabled() ) 453 if ( !table->isUpdatesEnabled() )
453 return; 454 return;
454 table->setPaintingEnabled( false ); 455 table->setPaintingEnabled( false );
455 for ( unsigned int i = 1; i < catMenu->count(); i++ ) 456 for ( unsigned int i = 1; i < catMenu->count(); i++ )
456 catMenu->setItemChecked( i, c == (int)i ); 457 catMenu->setItemChecked( i, c == (int)i );
457 if ( c == 1 ) { 458 if ( c == 1 ) {
458 table->setShowCategory( QString::null ); 459 table->setShowCategory( QString::null );
459 setCaption( tr("Todo") + " - " + tr( "All Categories" ) ); 460 setCaption( tr("Todo") + " - " + tr( "All Categories" ) );
460 } else if ( c == (int)catMenu->count() - 1 ) { 461 } else if ( c == (int)catMenu->count() - 1 ) {
461 table->setShowCategory( tr( "Unfiled" ) ); 462 table->setShowCategory( tr( "Unfiled" ) );
462 setCaption( tr("Todo") + " - " + tr( "Unfiled" ) ); 463 setCaption( tr("Todo") + " - " + tr( "Unfiled" ) );
463 } else { 464 } else {
464 QString cat = table->categories()[c - 2]; 465 QString cat = table->categories()[c - 2];
465 table->setShowCategory( cat ); 466 table->setShowCategory( cat );
466 setCaption( tr("Todo") + " - " + cat ); 467 setCaption( tr("Todo") + " - " + cat );
467 } 468 }
468 table->setPaintingEnabled( true ); 469 table->setPaintingEnabled( true );
469 470
470 mStack->raiseWidget( 1 ); 471 mStack->raiseWidget( 1 );
471} 472}
472 473
473void TodoWindow::populateCategories() 474void TodoWindow::populateCategories()
474{ 475{
475 catMenu->clear(); 476 catMenu->clear();
476 int id, rememberId; 477 int id, rememberId;
477 id = 1; 478 id = 1;
478 rememberId = 0; 479 rememberId = 0;
479 catMenu->insertItem( tr( "All Categories" ), id++ ); 480 catMenu->insertItem( tr( "All Categories" ), id++ );
480 catMenu->insertSeparator(); 481 catMenu->insertSeparator();
481 QStringList categories = table->categories(); 482 QStringList categories = table->categories();
482 categories.append( tr( "Unfiled" ) ); 483 categories.append( tr( "Unfiled" ) );
483 for ( QStringList::Iterator it = categories.begin(); 484 for ( QStringList::Iterator it = categories.begin();
484 it != categories.end(); ++it ) { 485 it != categories.end(); ++it ) {
485 catMenu->insertItem( *it, id ); 486 catMenu->insertItem( *it, id );
486 if ( *it == table->showCategory() ) 487 if ( *it == table->showCategory() )
487 rememberId = id; 488 rememberId = id;
488 ++id; 489 ++id;
489 } 490 }
490 if ( table->showCategory().isEmpty() ) 491 if ( table->showCategory().isEmpty() )
491 setCategory( 1 ); 492 setCategory( 1 );
492 else 493 else
493 setCategory( rememberId ); 494 setCategory( rememberId );
494} 495}
495 496
496void TodoWindow::reload() 497void TodoWindow::reload()
497{ 498{
498 table->clear(); 499 table->clear();
499 table->load( todolistXMLFilename() ); 500 table->load( todolistXMLFilename() );
500 syncing = FALSE; 501 syncing = FALSE;
501} 502}
502 503
503void TodoWindow::flush() 504void TodoWindow::flush()
504{ 505{
505 syncing = TRUE; 506 syncing = TRUE;
506 table->save( todolistXMLFilename() ); 507 table->save( todolistXMLFilename() );
507} 508}
508 509
509void TodoWindow::closeEvent( QCloseEvent *e ) 510void TodoWindow::closeEvent( QCloseEvent *e )
510{ 511{
511 if( mStack->visibleWidget() != table ){ 512 if( mStack->visibleWidget() != table ){
512 mStack->raiseWidget( 1 ); 513 mStack->raiseWidget( 1 );
513 e->ignore(); 514 e->ignore();
514 return; 515 return;
515 } 516 }
516 if(syncing) { 517 if(syncing) {
517 /* no need to save if in the middle of syncing */ 518 /* no need to save if in the middle of syncing */
518 e->accept(); 519 e->accept();
519 return; 520 return;
520 } 521 }
521 522
522 if ( table->save( todolistXMLFilename() ) ) { 523 if ( table->save( todolistXMLFilename() ) ) {
523 e->accept(); 524 e->accept();
524 // repeat for categories... 525 // repeat for categories...
525 // if writing configs fail, it will emit an 526 // if writing configs fail, it will emit an
526 // error, but I feel that it is "ok" for us to exit 527 // error, but I feel that it is "ok" for us to exit
527 // espically since we aren't told if the write succeeded... 528 // espically since we aren't told if the write succeeded...
528 Config config( "todo" ); 529 Config config( "todo" );
529 config.setGroup( "View" ); 530 config.setGroup( "View" );
530 config.writeEntry( "ShowComplete", table->showCompleted() ); 531 config.writeEntry( "ShowComplete", table->showCompleted() );
531 config.writeEntry( "Category", table->showCategory() ); 532 config.writeEntry( "Category", table->showCategory() );
532 /* added 20.01.2k2 by se */ 533 /* added 20.01.2k2 by se */
533 config.writeEntry( "ShowDeadLine", table->showDeadline()); 534 config.writeEntry( "ShowDeadLine", table->showDeadline());
534 } else { 535 } else {
535 if ( QMessageBox::critical( this, tr("Out of space"), 536 if ( QMessageBox::critical( this, tr("Out of space"),
536 tr("Todo was unable\n" 537 tr("Todo was unable\n"
537 "to save your changes.\n" 538 "to save your changes.\n"
538 "Free up some space\n" 539 "Free up some space\n"
539 "and try again.\n" 540 "and try again.\n"
540 "\nQuit Anyway?"), 541 "\nQuit Anyway?"),
541 QMessageBox::Yes|QMessageBox::Escape, 542 QMessageBox::Yes|QMessageBox::Escape,
542 QMessageBox::No|QMessageBox::Default) 543 QMessageBox::No|QMessageBox::Default)
543 != QMessageBox::No ) 544 != QMessageBox::No )
544 e->accept(); 545 e->accept();
545 else 546 else
546 e->ignore(); 547 e->ignore();
547 } 548 }
548} 549}
549 550
550void TodoWindow::slotFind() 551void TodoWindow::slotFind()
551{ 552{
552 // put everything back to view all for searching... 553 // put everything back to view all for searching...
553 mStack->raiseWidget( 1 ); 554 mStack->raiseWidget( 1 );
554 if ( !catMenu->isItemChecked( 0 ) ) 555 if ( !catMenu->isItemChecked( 0 ) )
555 setCategory( 0 ); 556 setCategory( 0 );
556 557
557 FindDialog dlg( "Todo List", this ); 558 FindDialog dlg( "Todo List", this );
558 QObject::connect( &dlg, 559 QObject::connect( &dlg,
559 SIGNAL(signalFindClicked(const QString &, 560 SIGNAL(signalFindClicked(const QString &,
560 bool, bool, int)), 561 bool, bool, int)),
561 table, 562 table,
562 SLOT(slotDoFind(const QString&, bool, bool, int)) ); 563 SLOT(slotDoFind(const QString&, bool, bool, int)) );
563 QObject::connect( table, SIGNAL(signalNotFound()), &dlg, 564 QObject::connect( table, SIGNAL(signalNotFound()), &dlg,
564 SLOT(slotNotFound()) ); 565 SLOT(slotNotFound()) );
565 QObject::connect( table, SIGNAL(signalWrapAround()), &dlg, 566 QObject::connect( table, SIGNAL(signalWrapAround()), &dlg,
566 SLOT(slotWrapAround()) ); 567 SLOT(slotWrapAround()) );
567 dlg.exec(); 568 dlg.exec();
568 if ( table->numSelections() ) 569 if ( table->numSelections() )
569 table->clearSelection(); 570 table->clearSelection();
570 table->clearFindRow(); 571 table->clearFindRow();
571} 572}
572 573
573 574
574void TodoWindow::setDocument( const QString &filename ) 575void TodoWindow::setDocument( const QString &filename )
575{ 576{
576 if ( filename.find(".vcs") != int(filename.length()) - 4 ) return; 577 if ( filename.find(".vcs") != int(filename.length()) - 4 ) return;
577 578
578 ToDoDB todoDB(filename, new ToDoVCalResource() ); 579 ToDoDB todoDB(filename, new ToDoVCalResource() );
579 QValueList<ToDoEvent> tl = todoDB.rawToDos(); 580 QValueList<ToDoEvent> tl = todoDB.rawToDos();
580 for( QValueList<ToDoEvent>::Iterator it = tl.begin(); it != tl.end(); ++it ) { 581 for( QValueList<ToDoEvent>::Iterator it = tl.begin(); it != tl.end(); ++it ) {
581 table->addEntry( *it ); 582 table->addEntry( *it );
582 } 583 }
583} 584}
584 585
585static const char * beamfile = "/tmp/obex/todo.vcs"; 586static const char * beamfile = "/tmp/obex/todo.vcs";
586 587
587void TodoWindow::slotBeam() 588void TodoWindow::slotBeam()
588{ 589{
589 unlink( beamfile ); // delete if exists 590 unlink( beamfile ); // delete if exists
590 ToDoEvent c = table->currentEntry(); 591 ToDoEvent c = table->currentEntry();
591 mkdir("/tmp/obex/", 0755); 592 mkdir("/tmp/obex/", 0755);
592 ToDoDB todoDB( beamfile, new ToDoVCalResource() ); 593 ToDoDB todoDB( beamfile, new ToDoVCalResource() );
593 todoDB.addEvent( c ); 594 todoDB.addEvent( c );
594 todoDB.save(); 595 todoDB.save();
595 Ir *ir = new Ir( this ); 596 Ir *ir = new Ir( this );
596 connect( ir, SIGNAL( done( Ir * ) ), this, SLOT( beamDone( Ir * ) ) ); 597 connect( ir, SIGNAL( done( Ir * ) ), this, SLOT( beamDone( Ir * ) ) );
597 QString description = c.summary(); 598 QString description = c.summary();
598 ir->send( beamfile, description, "text/x-vCalendar" ); 599 ir->send( beamfile, description, "text/x-vCalendar" );
599} 600}
600 601
601void TodoWindow::beamDone( Ir *ir ) 602void TodoWindow::beamDone( Ir *ir )
602{ 603{
603 delete ir; 604 delete ir;
604 unlink( beamfile ); 605 unlink( beamfile );
605} 606}
606 607
607void TodoWindow::showDeadline( bool s ) 608void TodoWindow::showDeadline( bool s )
608{ 609{
609 table->setPaintingEnabled( false ); 610 table->setPaintingEnabled( false );
610 table->setShowDeadline( s ); 611 table->setShowDeadline( s );
611 table->setPaintingEnabled( true ); 612 table->setPaintingEnabled( true );
612} 613}
613void TodoWindow::slotShowDetails() 614void TodoWindow::slotShowDetails()
614{ 615{
615 ToDoEvent event = table->currentEntry(); 616 ToDoEvent event = table->currentEntry();
616 slotShowDetails( event ); 617 slotShowDetails( event );
617} 618}
618void TodoWindow::slotShowDetails( const ToDoEvent &event ) 619void TodoWindow::slotShowDetails( const ToDoEvent &event )
619{ 620{
620 if( mView == 0l ){ 621 if( mView == 0l ){
621 mView = new TodoLabel(mStack); 622 mView = new TodoLabel(mStack);
622 mStack->addWidget( mView, 2 ); 623 mStack->addWidget( mView, 2 );
623 } 624 }
624 mView->init( event ); 625 mView->init( event );
625 mView->sync(); 626 mView->sync();
626 mStack->raiseWidget( 2); 627 mStack->raiseWidget( 2);
627} 628}