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