author | zecke <zecke> | 2002-03-20 21:45:51 (UTC) |
---|---|---|
committer | zecke <zecke> | 2002-03-20 21:45:51 (UTC) |
commit | e9189f8d0cc46b0532fdcbcb2377ae3d108666d5 (patch) (unidiff) | |
tree | 20af6104c262510595b82e619ee69b0958596ddd | |
parent | 0b39bb8d62f67a86128a6bd16afbd2aae004637c (diff) | |
download | opie-e9189f8d0cc46b0532fdcbcb2377ae3d108666d5.zip opie-e9189f8d0cc46b0532fdcbcb2377ae3d108666d5.tar.gz opie-e9189f8d0cc46b0532fdcbcb2377ae3d108666d5.tar.bz2 |
vCal Resource for the tododb
-rw-r--r-- | core/pim/todo/mainwindow.cpp | 8 | ||||
-rw-r--r-- | core/pim/todo/mainwindow.h | 3 | ||||
-rw-r--r-- | core/pim/todo/todoentryimpl.cpp | 2 | ||||
-rw-r--r-- | libopie/libopie.pro | 2 | ||||
-rw-r--r-- | libopie/tododb.cpp | 8 | ||||
-rw-r--r-- | libopie/todoevent.cpp | 6 | ||||
-rw-r--r-- | libopie/todovcalresource.cpp | 153 |
7 files changed, 175 insertions, 7 deletions
diff --git a/core/pim/todo/mainwindow.cpp b/core/pim/todo/mainwindow.cpp index fb85a09..6709811 100644 --- a/core/pim/todo/mainwindow.cpp +++ b/core/pim/todo/mainwindow.cpp | |||
@@ -1,229 +1,233 @@ | |||
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 | ||
22 | |||
21 | #include "mainwindow.h" | 23 | #include "mainwindow.h" |
22 | #include "todoentryimpl.h" | 24 | #include "todoentryimpl.h" |
23 | #include "todotable.h" | 25 | #include "todotable.h" |
24 | 26 | ||
25 | #include <qpe/qpeapplication.h> | 27 | #include <qpe/qpeapplication.h> |
26 | #include <qpe/config.h> | 28 | #include <qpe/config.h> |
27 | #include <qpe/finddialog.h> | 29 | #include <qpe/finddialog.h> |
28 | #include <qpe/global.h> | 30 | #include <qpe/global.h> |
29 | #include <qpe/ir.h> | 31 | #include <qpe/ir.h> |
30 | #include <qpe/qpemenubar.h> | 32 | #include <qpe/qpemenubar.h> |
31 | #include <qpe/qpemessagebox.h> | 33 | #include <qpe/qpemessagebox.h> |
32 | #include <qpe/resource.h> | 34 | #include <qpe/resource.h> |
33 | #include <qpe/task.h> | 35 | #include <qpe/task.h> |
34 | #include <qpe/qpetoolbar.h> | 36 | #include <qpe/qpetoolbar.h> |
35 | 37 | ||
36 | #include <qaction.h> | 38 | #include <qaction.h> |
37 | #include <qarray.h> | 39 | #include <qarray.h> |
38 | #include <qdatastream.h> | 40 | #include <qdatastream.h> |
39 | #include <qdatetime.h> | 41 | #include <qdatetime.h> |
40 | #include <qfile.h> | 42 | #include <qfile.h> |
41 | #include <qmessagebox.h> | 43 | #include <qmessagebox.h> |
42 | #include <qpopupmenu.h> | 44 | #include <qpopupmenu.h> |
43 | 45 | ||
44 | #include <sys/stat.h> | 46 | #include <sys/stat.h> |
45 | #include <sys/types.h> | 47 | #include <sys/types.h> |
46 | #include <fcntl.h> | 48 | #include <fcntl.h> |
47 | #include <unistd.h> | 49 | #include <unistd.h> |
48 | 50 | ||
49 | #include <stdlib.h> | 51 | #include <stdlib.h> |
50 | 52 | ||
51 | static QString todolistXMLFilename() | 53 | static QString todolistXMLFilename() |
52 | { | 54 | { |
53 | return Global::applicationFileName("todolist","todolist.xml"); | 55 | return Global::applicationFileName("todolist","todolist.xml"); |
54 | } | 56 | } |
55 | 57 | ||
56 | static QString categoriesXMLFilename() | 58 | static QString categoriesXMLFilename() |
57 | { | 59 | { |
58 | return Global::applicationFileName("todolist","categories.xml"); | 60 | return Global::applicationFileName("todolist","categories.xml"); |
59 | } | 61 | } |
60 | 62 | ||
61 | TodoWindow::TodoWindow( QWidget *parent, const char *name, WFlags f = 0 ) : | 63 | TodoWindow::TodoWindow( QWidget *parent, const char *name, WFlags f = 0 ) : |
62 | QMainWindow( parent, name, f ), syncing(FALSE) | 64 | QMainWindow( parent, name, f ), syncing(FALSE) |
63 | { | 65 | { |
64 | // QTime t; | 66 | // QTime t; |
65 | // t.start(); | 67 | // t.start(); |
66 | 68 | ||
67 | setCaption( tr("Todo") ); | 69 | setCaption( tr("Todo") ); |
68 | QString str; | 70 | QString str; |
69 | table = new TodoTable( this ); | 71 | table = new TodoTable( this ); |
70 | table->setColumnWidth( 2, 10 ); | 72 | table->setColumnWidth( 2, 10 ); |
71 | table->setPaintingEnabled( FALSE ); | 73 | table->setPaintingEnabled( FALSE ); |
72 | table->setUpdatesEnabled( FALSE ); | 74 | table->setUpdatesEnabled( FALSE ); |
73 | table->viewport()->setUpdatesEnabled( FALSE ); | 75 | table->viewport()->setUpdatesEnabled( FALSE ); |
74 | 76 | ||
75 | { | 77 | { |
76 | str = todolistXMLFilename(); | 78 | str = todolistXMLFilename(); |
77 | if ( str.isNull() ) | 79 | if ( str.isNull() ) |
78 | QMessageBox::critical( this, | 80 | QMessageBox::critical( this, |
79 | tr("Out of Space"), | 81 | tr("Out of Space"), |
80 | tr("Unable to create startup files\n" | 82 | tr("Unable to create startup files\n" |
81 | "Free up some space\n" | 83 | "Free up some space\n" |
82 | "before you enter any data") ); | 84 | "before you enter any data") ); |
83 | else | 85 | else |
84 | table->load( str ); | 86 | table->load( str ); |
85 | } | 87 | } |
86 | 88 | ||
87 | // repeat for categories... | 89 | // repeat for categories... |
88 | str = categoriesXMLFilename(); | 90 | str = categoriesXMLFilename(); |
89 | if ( str.isNull() ) | 91 | if ( str.isNull() ) |
90 | QMessageBox::critical( this, | 92 | QMessageBox::critical( this, |
91 | tr( "Out of Space" ), | 93 | tr( "Out of Space" ), |
92 | tr( "Unable to create startup files\n" | 94 | tr( "Unable to create startup files\n" |
93 | "Free up some space\n" | 95 | "Free up some space\n" |
94 | "before you enter any data") ); | 96 | "before you enter any data") ); |
95 | 97 | ||
96 | setCentralWidget( table ); | 98 | setCentralWidget( table ); |
97 | setToolBarsMovable( FALSE ); | 99 | setToolBarsMovable( FALSE ); |
98 | 100 | ||
99 | // qDebug("after load: t=%d", t.elapsed() ); | 101 | // qDebug("after load: t=%d", t.elapsed() ); |
100 | 102 | ||
101 | Config config( "todo" ); | 103 | Config config( "todo" ); |
102 | config.setGroup( "View" ); | 104 | config.setGroup( "View" ); |
103 | bool complete = config.readBoolEntry( "ShowComplete", true ); | 105 | bool complete = config.readBoolEntry( "ShowComplete", true ); |
104 | table->setShowCompleted( complete ); | 106 | table->setShowCompleted( complete ); |
105 | QString category = config.readEntry( "Category", QString::null ); | 107 | QString category = config.readEntry( "Category", QString::null ); |
106 | table->setShowCategory( category ); | 108 | table->setShowCategory( category ); |
107 | 109 | ||
108 | QPEToolBar *bar = new QPEToolBar( this ); | 110 | QPEToolBar *bar = new QPEToolBar( this ); |
109 | bar->setHorizontalStretchable( TRUE ); | 111 | bar->setHorizontalStretchable( TRUE ); |
110 | 112 | ||
111 | QPEMenuBar *mb = new QPEMenuBar( bar ); | 113 | QPEMenuBar *mb = new QPEMenuBar( bar ); |
112 | 114 | ||
113 | catMenu = new QPopupMenu( this ); | 115 | catMenu = new QPopupMenu( this ); |
114 | QPopupMenu *edit = new QPopupMenu( this ); | 116 | QPopupMenu *edit = new QPopupMenu( this ); |
115 | contextMenu = new QPopupMenu( this ); | 117 | contextMenu = new QPopupMenu( this ); |
116 | 118 | ||
117 | bar = new QPEToolBar( this ); | 119 | bar = new QPEToolBar( this ); |
118 | 120 | ||
119 | QAction *a = new QAction( tr( "New Task" ), Resource::loadPixmap( "new" ), | 121 | QAction *a = new QAction( tr( "New Task" ), Resource::loadPixmap( "new" ), |
120 | QString::null, 0, this, 0 ); | 122 | QString::null, 0, this, 0 ); |
121 | connect( a, SIGNAL( activated() ), | 123 | connect( a, SIGNAL( activated() ), |
122 | this, SLOT( slotNew() ) ); | 124 | this, SLOT( slotNew() ) ); |
123 | a->addTo( bar ); | 125 | a->addTo( bar ); |
124 | a->addTo( edit ); | 126 | a->addTo( edit ); |
127 | |||
125 | a = new QAction( tr( "Edit" ), Resource::loadIconSet( "edit" ), | 128 | a = new QAction( tr( "Edit" ), Resource::loadIconSet( "edit" ), |
126 | QString::null, 0, this, 0 ); | 129 | QString::null, 0, this, 0 ); |
127 | connect( a, SIGNAL( activated() ), | 130 | connect( a, SIGNAL( activated() ), |
128 | this, SLOT( slotEdit() ) ); | 131 | this, SLOT( slotEdit() ) ); |
129 | a->addTo( bar ); | 132 | a->addTo( bar ); |
130 | a->addTo( edit ); | 133 | a->addTo( edit ); |
131 | a->addTo( contextMenu ); | 134 | a->addTo( contextMenu ); |
132 | a->setEnabled( FALSE ); | 135 | a->setEnabled( FALSE ); |
133 | editAction = a; | 136 | editAction = a; |
137 | |||
134 | a = new QAction( tr( "Delete" ), Resource::loadIconSet( "trash" ), | 138 | a = new QAction( tr( "Delete" ), Resource::loadIconSet( "trash" ), |
135 | QString::null, 0, this, 0 ); | 139 | QString::null, 0, this, 0 ); |
136 | connect( a, SIGNAL( activated() ), | 140 | connect( a, SIGNAL( activated() ), |
137 | this, SLOT( slotDelete() ) ); | 141 | this, SLOT( slotDelete() ) ); |
138 | a->addTo( bar ); | 142 | a->addTo( bar ); |
139 | a->addTo( edit ); | 143 | a->addTo( edit ); |
140 | a->addTo( contextMenu ); | 144 | a->addTo( contextMenu ); |
141 | a->setEnabled( FALSE ); | 145 | a->setEnabled( FALSE ); |
142 | deleteAction = a; | 146 | deleteAction = a; |
143 | 147 | ||
144 | if ( Ir::supported() ) { | 148 | if ( Ir::supported() ) { |
145 | a = new QAction( tr( "Beam" ), Resource::loadPixmap( "beam" ), | 149 | a = new QAction( tr( "Beam" ), Resource::loadPixmap( "beam" ), |
146 | QString::null, 0, this, 0 ); | 150 | QString::null, 0, this, 0 ); |
147 | connect( a, SIGNAL( activated() ), | 151 | connect( a, SIGNAL( activated() ), |
148 | this, SLOT( slotBeam() ) ); | 152 | this, SLOT( slotBeam() ) ); |
149 | a->addTo( edit ); | 153 | a->addTo( edit ); |
150 | a->addTo( bar ); | 154 | a->addTo( bar ); |
151 | } | 155 | } |
152 | 156 | ||
153 | a = new QAction( tr( "Find" ), Resource::loadIconSet( "mag" ), | 157 | a = new QAction( tr( "Find" ), Resource::loadIconSet( "mag" ), |
154 | QString::null, 0, this, 0 ); | 158 | QString::null, 0, this, 0 ); |
155 | connect( a, SIGNAL( activated() ), | 159 | connect( a, SIGNAL( activated() ), |
156 | this, SLOT( slotFind() ) ); | 160 | this, SLOT( slotFind() ) ); |
157 | a->addTo( bar ); | 161 | a->addTo( bar ); |
158 | a->addTo( edit ); | 162 | a->addTo( edit ); |
159 | if ( table->numRows() ) | 163 | if ( table->numRows() ) |
160 | a->setEnabled( TRUE ); | 164 | a->setEnabled( TRUE ); |
161 | else | 165 | else |
162 | a->setEnabled( FALSE ); | 166 | a->setEnabled( FALSE ); |
163 | 167 | ||
164 | //a->setEnabled( FALSE ); | 168 | //a->setEnabled( FALSE ); |
165 | findAction = a; | 169 | findAction = a; |
166 | // qDebug("mainwindow #2: t=%d", t.elapsed() ); | 170 | // qDebug("mainwindow #2: t=%d", t.elapsed() ); |
167 | 171 | ||
168 | completedAction = new QAction( QString::null, tr("Completed tasks"), 0, this, 0, TRUE ); | 172 | completedAction = new QAction( QString::null, tr("Completed tasks"), 0, this, 0, TRUE ); |
169 | 173 | ||
170 | catMenu->setCheckable( true ); | 174 | catMenu->setCheckable( true ); |
171 | populateCategories(); | 175 | populateCategories(); |
172 | 176 | ||
173 | mb->insertItem( tr( "Task" ), edit ); | 177 | mb->insertItem( tr( "Task" ), edit ); |
174 | mb->insertItem( tr( "View" ), catMenu ); | 178 | mb->insertItem( tr( "View" ), catMenu ); |
175 | 179 | ||
176 | resize( 200, 300 ); | 180 | resize( 200, 300 ); |
177 | if ( table->numRows() > 0 ) | 181 | if ( table->numRows() > 0 ) |
178 | currentEntryChanged( 0, 0 ); | 182 | currentEntryChanged( 0, 0 ); |
179 | connect( table, SIGNAL( signalEdit() ), | 183 | connect( table, SIGNAL( signalEdit() ), |
180 | this, SLOT( slotEdit() ) ); | 184 | this, SLOT( slotEdit() ) ); |
181 | connect( table, SIGNAL(signalShowMenu(const QPoint &)), | 185 | connect( table, SIGNAL(signalShowMenu(const QPoint &)), |
182 | this, SLOT( slotShowPopup(const QPoint &)) ); | 186 | this, SLOT( slotShowPopup(const QPoint &)) ); |
183 | 187 | ||
184 | // qDebug("mainwindow #3: t=%d", t.elapsed() ); | 188 | // qDebug("mainwindow #3: t=%d", t.elapsed() ); |
185 | table->updateVisible(); | 189 | table->updateVisible(); |
186 | table->setUpdatesEnabled( TRUE ); | 190 | table->setUpdatesEnabled( TRUE ); |
187 | table->setPaintingEnabled( TRUE ); | 191 | table->setPaintingEnabled( TRUE ); |
188 | table->viewport()->setUpdatesEnabled( TRUE ); | 192 | table->viewport()->setUpdatesEnabled( TRUE ); |
189 | 193 | ||
190 | connect( completedAction, SIGNAL( toggled(bool) ), this, SLOT( showCompleted(bool) ) ); | 194 | connect( completedAction, SIGNAL( toggled(bool) ), this, SLOT( showCompleted(bool) ) ); |
191 | connect( catMenu, SIGNAL(activated(int)), this, SLOT(setCategory(int)) ); | 195 | connect( catMenu, SIGNAL(activated(int)), this, SLOT(setCategory(int)) ); |
192 | connect( table, SIGNAL( currentChanged( int, int ) ), | 196 | connect( table, SIGNAL( currentChanged( int, int ) ), |
193 | this, SLOT( currentEntryChanged( int, int ) ) ); | 197 | this, SLOT( currentEntryChanged( int, int ) ) ); |
194 | 198 | ||
195 | // qDebug("done: t=%d", t.elapsed() ); | 199 | // qDebug("done: t=%d", t.elapsed() ); |
196 | } | 200 | } |
197 | 201 | ||
198 | void TodoWindow::slotNew() | 202 | void TodoWindow::slotNew() |
199 | { | 203 | { |
200 | if(syncing) { | 204 | if(syncing) { |
201 | QMessageBox::warning(this, tr("Todo"), | 205 | QMessageBox::warning(this, tr("Todo"), |
202 | tr("Can not edit data, currently syncing")); | 206 | tr("Can not edit data, currently syncing")); |
203 | return; | 207 | return; |
204 | } | 208 | } |
205 | 209 | ||
206 | int id; | 210 | int id; |
207 | id = -1; | 211 | id = -1; |
208 | QArray<int> ids; | 212 | QArray<int> ids; |
209 | ids = table->currentEntry().categories(); | 213 | ids = table->currentEntry().categories(); |
210 | if ( ids.count() ) | 214 | if ( ids.count() ) |
211 | id = ids[0]; | 215 | id = ids[0]; |
212 | NewTaskDialog e( id, this, 0, TRUE ); | 216 | NewTaskDialog e( id, this, 0, TRUE ); |
213 | 217 | ||
214 | Task todo; | 218 | Task todo; |
215 | 219 | ||
216 | #if defined(Q_WS_QWS) || defined(_WS_QWS_) | 220 | #if defined(Q_WS_QWS) || defined(_WS_QWS_) |
217 | e.showMaximized(); | 221 | e.showMaximized(); |
218 | #endif | 222 | #endif |
219 | int ret = e.exec(); | 223 | int ret = e.exec(); |
220 | 224 | ||
221 | if ( ret == QDialog::Accepted ) { | 225 | if ( ret == QDialog::Accepted ) { |
222 | table->setPaintingEnabled( false ); | 226 | table->setPaintingEnabled( false ); |
223 | todo = e.todoEntry(); | 227 | todo = e.todoEntry(); |
224 | todo.assignUid(); | 228 | todo.assignUid(); |
225 | table->addEntry( todo ); | 229 | table->addEntry( todo ); |
226 | table->setPaintingEnabled( true ); | 230 | table->setPaintingEnabled( true ); |
227 | findAction->setEnabled( TRUE ); | 231 | findAction->setEnabled( TRUE ); |
228 | } | 232 | } |
229 | // I'm afraid we must call this every time now, otherwise | 233 | // I'm afraid we must call this every time now, otherwise |
@@ -233,215 +237,215 @@ void TodoWindow::slotNew() | |||
233 | 237 | ||
234 | TodoWindow::~TodoWindow() | 238 | TodoWindow::~TodoWindow() |
235 | { | 239 | { |
236 | } | 240 | } |
237 | 241 | ||
238 | void TodoWindow::slotDelete() | 242 | void TodoWindow::slotDelete() |
239 | { | 243 | { |
240 | if(syncing) { | 244 | if(syncing) { |
241 | QMessageBox::warning(this, tr("Todo"), | 245 | QMessageBox::warning(this, tr("Todo"), |
242 | tr("Can not edit data, currently syncing")); | 246 | tr("Can not edit data, currently syncing")); |
243 | return; | 247 | return; |
244 | } | 248 | } |
245 | 249 | ||
246 | if ( table->currentRow() == -1 ) | 250 | if ( table->currentRow() == -1 ) |
247 | return; | 251 | return; |
248 | 252 | ||
249 | QString strName = table->text( table->currentRow(), 2 ).left( 30 ); | 253 | QString strName = table->text( table->currentRow(), 2 ).left( 30 ); |
250 | 254 | ||
251 | if ( !QPEMessageBox::confirmDelete( this, tr( "Todo" ), strName ) ) | 255 | if ( !QPEMessageBox::confirmDelete( this, tr( "Todo" ), strName ) ) |
252 | return; | 256 | return; |
253 | 257 | ||
254 | 258 | ||
255 | 259 | ||
256 | table->setPaintingEnabled( false ); | 260 | table->setPaintingEnabled( false ); |
257 | table->removeCurrentEntry(); | 261 | table->removeCurrentEntry(); |
258 | table->setPaintingEnabled( true ); | 262 | table->setPaintingEnabled( true ); |
259 | 263 | ||
260 | if ( table->numRows() == 0 ) { | 264 | if ( table->numRows() == 0 ) { |
261 | currentEntryChanged( -1, 0 ); | 265 | currentEntryChanged( -1, 0 ); |
262 | findAction->setEnabled( FALSE ); | 266 | findAction->setEnabled( FALSE ); |
263 | } | 267 | } |
264 | } | 268 | } |
265 | 269 | ||
266 | void TodoWindow::slotEdit() | 270 | void TodoWindow::slotEdit() |
267 | { | 271 | { |
268 | if(syncing) { | 272 | if(syncing) { |
269 | QMessageBox::warning(this, tr("Todo"), | 273 | QMessageBox::warning(this, tr("Todo"), |
270 | tr("Can not edit data, currently syncing")); | 274 | tr("Can not edit data, currently syncing")); |
271 | return; | 275 | return; |
272 | } | 276 | } |
273 | 277 | ||
274 | Task todo = table->currentEntry(); | 278 | Task todo = table->currentEntry(); |
275 | 279 | ||
276 | NewTaskDialog e( todo, this, 0, TRUE ); | 280 | NewTaskDialog e( todo, this, 0, TRUE ); |
277 | e.setCaption( tr( "Edit Task" ) ); | 281 | e.setCaption( tr( "Edit Task" ) ); |
278 | 282 | ||
279 | #if defined(Q_WS_QWS) || defined(_WS_QWS_) | 283 | #if defined(Q_WS_QWS) || defined(_WS_QWS_) |
280 | e.showMaximized(); | 284 | e.showMaximized(); |
281 | #endif | 285 | #endif |
282 | int ret = e.exec(); | 286 | int ret = e.exec(); |
283 | 287 | ||
284 | if ( ret == QDialog::Accepted ) { | 288 | if ( ret == QDialog::Accepted ) { |
285 | table->setPaintingEnabled( false ); | 289 | table->setPaintingEnabled( false ); |
286 | todo = e.todoEntry(); | 290 | todo = e.todoEntry(); |
287 | table->replaceCurrentEntry( todo ); | 291 | table->replaceCurrentEntry( todo ); |
288 | table->setPaintingEnabled( true ); | 292 | table->setPaintingEnabled( true ); |
289 | } | 293 | } |
290 | populateCategories(); | 294 | populateCategories(); |
291 | 295 | ||
292 | } | 296 | } |
293 | 297 | ||
294 | void TodoWindow::slotShowPopup( const QPoint &p ) | 298 | void TodoWindow::slotShowPopup( const QPoint &p ) |
295 | { | 299 | { |
296 | contextMenu->popup( p ); | 300 | contextMenu->popup( p ); |
297 | } | 301 | } |
298 | 302 | ||
299 | void TodoWindow::showCompleted( bool s ) | 303 | void TodoWindow::showCompleted( bool s ) |
300 | { | 304 | { |
301 | if ( !table->isUpdatesEnabled() ) | 305 | if ( !table->isUpdatesEnabled() ) |
302 | return; | 306 | return; |
303 | table->setPaintingEnabled( false ); | 307 | table->setPaintingEnabled( false ); |
304 | table->setShowCompleted( s ); | 308 | table->setShowCompleted( s ); |
305 | table->setPaintingEnabled( true ); | 309 | table->setPaintingEnabled( true ); |
306 | } | 310 | } |
307 | 311 | ||
308 | void TodoWindow::currentEntryChanged( int r, int ) | 312 | void TodoWindow::currentEntryChanged( int r, int ) |
309 | { | 313 | { |
310 | if ( r != -1 && table->rowHeight( r ) > 0 ) { | 314 | if ( r != -1 && table->rowHeight( r ) > 0 ) { |
311 | editAction->setEnabled( TRUE ); | 315 | editAction->setEnabled( TRUE ); |
312 | deleteAction->setEnabled( TRUE ); | 316 | deleteAction->setEnabled( TRUE ); |
313 | } else { | 317 | } else { |
314 | editAction->setEnabled( FALSE ); | 318 | editAction->setEnabled( FALSE ); |
315 | deleteAction->setEnabled( FALSE ); | 319 | deleteAction->setEnabled( FALSE ); |
316 | } | 320 | } |
317 | } | 321 | } |
318 | 322 | ||
319 | void TodoWindow::setCategory( int c ) | 323 | void TodoWindow::setCategory( int c ) |
320 | { | 324 | { |
321 | if ( c <= 0 ) return; | 325 | if ( c <= 0 ) return; |
322 | if ( !table->isUpdatesEnabled() ) | 326 | if ( !table->isUpdatesEnabled() ) |
323 | return; | 327 | return; |
324 | table->setPaintingEnabled( false ); | 328 | table->setPaintingEnabled( false ); |
325 | for ( unsigned int i = 1; i < catMenu->count(); i++ ) | 329 | for ( unsigned int i = 1; i < catMenu->count(); i++ ) |
326 | catMenu->setItemChecked( i, c == (int)i ); | 330 | catMenu->setItemChecked( i, c == (int)i ); |
327 | if ( c == 1 ) { | 331 | if ( c == 1 ) { |
328 | table->setShowCategory( QString::null ); | 332 | table->setShowCategory( QString::null ); |
329 | setCaption( tr("Todo") + " - " + tr( "All" ) ); | 333 | setCaption( tr("Todo") + " - " + tr( "All Categories" ) ); |
330 | } else if ( c == (int)catMenu->count() - 1 ) { | 334 | } else if ( c == (int)catMenu->count() - 1 ) { |
331 | table->setShowCategory( tr( "Unfiled" ) ); | 335 | table->setShowCategory( tr( "Unfiled" ) ); |
332 | setCaption( tr("Todo") + " - " + tr( "Unfiled" ) ); | 336 | setCaption( tr("Todo") + " - " + tr( "Unfiled" ) ); |
333 | } else { | 337 | } else { |
334 | QString cat = table->categories()[c - 2]; | 338 | QString cat = table->categories()[c - 2]; |
335 | table->setShowCategory( cat ); | 339 | table->setShowCategory( cat ); |
336 | setCaption( tr("Todo") + " - " + cat ); | 340 | setCaption( tr("Todo") + " - " + cat ); |
337 | } | 341 | } |
338 | table->setPaintingEnabled( true ); | 342 | table->setPaintingEnabled( true ); |
339 | } | 343 | } |
340 | 344 | ||
341 | void TodoWindow::populateCategories() | 345 | void TodoWindow::populateCategories() |
342 | { | 346 | { |
343 | catMenu->clear(); | 347 | catMenu->clear(); |
344 | 348 | ||
345 | completedAction->addTo( catMenu ); | 349 | completedAction->addTo( catMenu ); |
346 | completedAction->setOn( table->showCompleted() ); | 350 | completedAction->setOn( table->showCompleted() ); |
347 | 351 | ||
348 | int id, | 352 | int id, |
349 | rememberId; | 353 | rememberId; |
350 | id = 1; | 354 | id = 1; |
351 | catMenu->insertItem( tr( "All" ), id++ ); | 355 | catMenu->insertItem( tr( "All Categories" ), id++ ); |
352 | // catMenu->insertSeparator(); | 356 | // catMenu->insertSeparator(); |
353 | QStringList categories = table->categories(); | 357 | QStringList categories = table->categories(); |
354 | categories.append( tr( "Unfiled" ) ); | 358 | categories.append( tr( "Unfiled" ) ); |
355 | for ( QStringList::Iterator it = categories.begin(); | 359 | for ( QStringList::Iterator it = categories.begin(); |
356 | it != categories.end(); ++it ) { | 360 | it != categories.end(); ++it ) { |
357 | catMenu->insertItem( *it, id ); | 361 | catMenu->insertItem( *it, id ); |
358 | if ( *it == table->showCategory() ) | 362 | if ( *it == table->showCategory() ) |
359 | rememberId = id; | 363 | rememberId = id; |
360 | ++id; | 364 | ++id; |
361 | } | 365 | } |
362 | if ( table->showCategory().isEmpty() ) | 366 | if ( table->showCategory().isEmpty() ) |
363 | setCategory( 1 ); | 367 | setCategory( 1 ); |
364 | else | 368 | else |
365 | setCategory( rememberId ); | 369 | setCategory( rememberId ); |
366 | } | 370 | } |
367 | 371 | ||
368 | void TodoWindow::reload() | 372 | void TodoWindow::reload() |
369 | { | 373 | { |
370 | table->clear(); | 374 | table->clear(); |
371 | table->load( todolistXMLFilename() ); | 375 | table->load( todolistXMLFilename() ); |
372 | syncing = FALSE; | 376 | syncing = FALSE; |
373 | } | 377 | } |
374 | 378 | ||
375 | void TodoWindow::flush() | 379 | void TodoWindow::flush() |
376 | { | 380 | { |
377 | syncing = TRUE; | 381 | syncing = TRUE; |
378 | table->save( todolistXMLFilename() ); | 382 | table->save( todolistXMLFilename() ); |
379 | } | 383 | } |
380 | 384 | ||
381 | void TodoWindow::closeEvent( QCloseEvent *e ) | 385 | void TodoWindow::closeEvent( QCloseEvent *e ) |
382 | { | 386 | { |
383 | if(syncing) { | 387 | if(syncing) { |
384 | /* no need to save if in the middle of syncing */ | 388 | /* no need to save if in the middle of syncing */ |
385 | e->accept(); | 389 | e->accept(); |
386 | return; | 390 | return; |
387 | } | 391 | } |
388 | 392 | ||
389 | if ( table->save( todolistXMLFilename() ) ) { | 393 | if ( table->save( todolistXMLFilename() ) ) { |
390 | e->accept(); | 394 | e->accept(); |
391 | // repeat for categories... | 395 | // repeat for categories... |
392 | // if writing configs fail, it will emit an | 396 | // if writing configs fail, it will emit an |
393 | // error, but I feel that it is "ok" for us to exit | 397 | // error, but I feel that it is "ok" for us to exit |
394 | // espically since we aren't told if the write succeeded... | 398 | // espically since we aren't told if the write succeeded... |
395 | Config config( "todo" ); | 399 | Config config( "todo" ); |
396 | config.setGroup( "View" ); | 400 | config.setGroup( "View" ); |
397 | config.writeEntry( "ShowComplete", table->showCompleted() ); | 401 | config.writeEntry( "ShowComplete", table->showCompleted() ); |
398 | config.writeEntry( "Category", table->showCategory() ); | 402 | config.writeEntry( "Category", table->showCategory() ); |
399 | } else { | 403 | } else { |
400 | if ( QMessageBox::critical( this, tr("Out of space"), | 404 | if ( QMessageBox::critical( this, tr("Out of space"), |
401 | tr("Todo was unable\n" | 405 | tr("Todo was unable\n" |
402 | "to save your changes.\n" | 406 | "to save your changes.\n" |
403 | "Free up some space\n" | 407 | "Free up some space\n" |
404 | "and try again.\n" | 408 | "and try again.\n" |
405 | "\nQuit Anyway?"), | 409 | "\nQuit Anyway?"), |
406 | QMessageBox::Yes|QMessageBox::Escape, | 410 | QMessageBox::Yes|QMessageBox::Escape, |
407 | QMessageBox::No|QMessageBox::Default) | 411 | QMessageBox::No|QMessageBox::Default) |
408 | != QMessageBox::No ) | 412 | != QMessageBox::No ) |
409 | e->accept(); | 413 | e->accept(); |
410 | else | 414 | else |
411 | e->ignore(); | 415 | e->ignore(); |
412 | } | 416 | } |
413 | } | 417 | } |
414 | 418 | ||
415 | void TodoWindow::slotFind() | 419 | void TodoWindow::slotFind() |
416 | { | 420 | { |
417 | // put everything back to view all for searching... | 421 | // put everything back to view all for searching... |
418 | if ( !catMenu->isItemChecked( 0 ) ) | 422 | if ( !catMenu->isItemChecked( 0 ) ) |
419 | setCategory( 0 ); | 423 | setCategory( 0 ); |
420 | 424 | ||
421 | FindDialog dlg( "Todo List", this ); | 425 | FindDialog dlg( "Todo List", this ); |
422 | QObject::connect( &dlg, | 426 | QObject::connect( &dlg, |
423 | SIGNAL(signalFindClicked(const QString &, | 427 | SIGNAL(signalFindClicked(const QString &, |
424 | bool, bool, int)), | 428 | bool, bool, int)), |
425 | table, | 429 | table, |
426 | SLOT(slotDoFind(const QString&, bool, bool, int)) ); | 430 | SLOT(slotDoFind(const QString&, bool, bool, int)) ); |
427 | QObject::connect( table, SIGNAL(signalNotFound()), &dlg, | 431 | QObject::connect( table, SIGNAL(signalNotFound()), &dlg, |
428 | SLOT(slotNotFound()) ); | 432 | SLOT(slotNotFound()) ); |
429 | QObject::connect( table, SIGNAL(signalWrapAround()), &dlg, | 433 | QObject::connect( table, SIGNAL(signalWrapAround()), &dlg, |
430 | SLOT(slotWrapAround()) ); | 434 | SLOT(slotWrapAround()) ); |
431 | dlg.exec(); | 435 | dlg.exec(); |
432 | if ( table->numSelections() ) | 436 | if ( table->numSelections() ) |
433 | table->clearSelection(); | 437 | table->clearSelection(); |
434 | table->clearFindRow(); | 438 | table->clearFindRow(); |
435 | } | 439 | } |
436 | 440 | ||
437 | 441 | ||
438 | void TodoWindow::setDocument( const QString &filename ) | 442 | void TodoWindow::setDocument( const QString &filename ) |
439 | { | 443 | { |
440 | if ( filename.find(".vcs") != int(filename.length()) - 4 ) return; | 444 | if ( filename.find(".vcs") != int(filename.length()) - 4 ) return; |
441 | 445 | ||
442 | QValueList<Task> tl = Task::readVCalendar( filename ); | 446 | QValueList<Task> tl = Task::readVCalendar( filename ); |
443 | for( QValueList<Task>::Iterator it = tl.begin(); it != tl.end(); ++it ) { | 447 | for( QValueList<Task>::Iterator it = tl.begin(); it != tl.end(); ++it ) { |
444 | table->addEntry( *it ); | 448 | table->addEntry( *it ); |
445 | } | 449 | } |
446 | } | 450 | } |
447 | 451 | ||
diff --git a/core/pim/todo/mainwindow.h b/core/pim/todo/mainwindow.h index f4fcd1b..856dcb4 100644 --- a/core/pim/todo/mainwindow.h +++ b/core/pim/todo/mainwindow.h | |||
@@ -1,73 +1,74 @@ | |||
1 | /********************************************************************** | 1 | /********************************************************************** |
2 | Copyright (C) 2002 Holger 'zecke' Freyther <freyther@kde.org> | ||
2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. | 3 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. |
3 | ** | 4 | ** |
4 | ** This file is part of Qtopia Environment. | 5 | ** This file is part of Qtopia and Opi Environment. |
5 | ** | 6 | ** |
6 | ** This file may be distributed and/or modified under the terms of the | 7 | ** 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 | 8 | ** GNU General Public License version 2 as published by the Free Software |
8 | ** Foundation and appearing in the file LICENSE.GPL included in the | 9 | ** Foundation and appearing in the file LICENSE.GPL included in the |
9 | ** packaging of this file. | 10 | ** packaging of this file. |
10 | ** | 11 | ** |
11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | 12 | ** 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. | 13 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
13 | ** | 14 | ** |
14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | 15 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. |
15 | ** | 16 | ** |
16 | ** Contact info@trolltech.com if any conditions of this licensing are | 17 | ** Contact info@trolltech.com if any conditions of this licensing are |
17 | ** not clear to you. | 18 | ** not clear to you. |
18 | ** | 19 | ** |
19 | **********************************************************************/ | 20 | **********************************************************************/ |
20 | 21 | ||
21 | #ifndef MAINWINDOW_H | 22 | #ifndef MAINWINDOW_H |
22 | #define MAINWINDOW_H | 23 | #define MAINWINDOW_H |
23 | 24 | ||
24 | #include <qmainwindow.h> | 25 | #include <qmainwindow.h> |
25 | 26 | ||
26 | class TodoTable; | 27 | class TodoTable; |
27 | class QAction; | 28 | class QAction; |
28 | class QPopupMenu; | 29 | class QPopupMenu; |
29 | class Ir; | 30 | class Ir; |
30 | 31 | ||
31 | class TodoWindow : public QMainWindow | 32 | class TodoWindow : public QMainWindow |
32 | { | 33 | { |
33 | Q_OBJECT | 34 | Q_OBJECT |
34 | 35 | ||
35 | public: | 36 | public: |
36 | TodoWindow( QWidget *parent = 0, const char *name = 0, WFlags f = 0 ); | 37 | TodoWindow( QWidget *parent = 0, const char *name = 0, WFlags f = 0 ); |
37 | ~TodoWindow(); | 38 | ~TodoWindow(); |
38 | 39 | ||
39 | public slots: | 40 | public slots: |
40 | void flush(); | 41 | void flush(); |
41 | void reload(); | 42 | void reload(); |
42 | 43 | ||
43 | protected slots: | 44 | protected slots: |
44 | void slotNew(); | 45 | void slotNew(); |
45 | void slotDelete(); | 46 | void slotDelete(); |
46 | void slotEdit(); | 47 | void slotEdit(); |
47 | void slotShowPopup( const QPoint & ); | 48 | void slotShowPopup( const QPoint & ); |
48 | void showCompleted( bool ); | 49 | void showCompleted( bool ); |
49 | void currentEntryChanged( int r, int c ); | 50 | void currentEntryChanged( int r, int c ); |
50 | void setCategory( int ); | 51 | void setCategory( int ); |
51 | void slotFind(); | 52 | void slotFind(); |
52 | void setDocument( const QString & ); | 53 | void setDocument( const QString & ); |
53 | void slotBeam(); | 54 | void slotBeam(); |
54 | void beamDone( Ir * ); | 55 | void beamDone( Ir * ); |
55 | 56 | ||
56 | protected: | 57 | protected: |
57 | void closeEvent( QCloseEvent *e ); | 58 | void closeEvent( QCloseEvent *e ); |
58 | 59 | ||
59 | private: | 60 | private: |
60 | void populateCategories(); | 61 | void populateCategories(); |
61 | 62 | ||
62 | private: | 63 | private: |
63 | TodoTable *table; | 64 | TodoTable *table; |
64 | QAction *editAction, | 65 | QAction *editAction, |
65 | *deleteAction, | 66 | *deleteAction, |
66 | *findAction, | 67 | *findAction, |
67 | * completedAction; | 68 | * completedAction; |
68 | QPopupMenu *contextMenu, *catMenu; | 69 | QPopupMenu *contextMenu, *catMenu; |
69 | 70 | ||
70 | bool syncing; | 71 | bool syncing; |
71 | }; | 72 | }; |
72 | 73 | ||
73 | #endif | 74 | #endif |
diff --git a/core/pim/todo/todoentryimpl.cpp b/core/pim/todo/todoentryimpl.cpp index 79206de..c957715 100644 --- a/core/pim/todo/todoentryimpl.cpp +++ b/core/pim/todo/todoentryimpl.cpp | |||
@@ -40,103 +40,103 @@ | |||
40 | 40 | ||
41 | 41 | ||
42 | NewTaskDialog::NewTaskDialog( const Task& task, QWidget *parent, | 42 | NewTaskDialog::NewTaskDialog( const Task& task, QWidget *parent, |
43 | const char *name, bool modal, WFlags fl ) | 43 | const char *name, bool modal, WFlags fl ) |
44 | : NewTaskDialogBase( parent, name, modal, fl ), | 44 | : NewTaskDialogBase( parent, name, modal, fl ), |
45 | todo( task ) | 45 | todo( task ) |
46 | { | 46 | { |
47 | todo.setCategories( task.categories() ); | 47 | todo.setCategories( task.categories() ); |
48 | if ( todo.hasDueDate() ) | 48 | if ( todo.hasDueDate() ) |
49 | date = todo.dueDate(); | 49 | date = todo.dueDate(); |
50 | else | 50 | else |
51 | date = QDate::currentDate(); | 51 | date = QDate::currentDate(); |
52 | 52 | ||
53 | init(); | 53 | init(); |
54 | comboPriority->setCurrentItem( task.priority() - 1 ); | 54 | comboPriority->setCurrentItem( task.priority() - 1 ); |
55 | 55 | ||
56 | checkCompleted->setChecked( task.isCompleted() ); | 56 | checkCompleted->setChecked( task.isCompleted() ); |
57 | checkDate->setChecked( task.hasDueDate() ); | 57 | checkDate->setChecked( task.hasDueDate() ); |
58 | buttonDate->setText( TimeString::longDateString( date ) ); | 58 | buttonDate->setText( TimeString::longDateString( date ) ); |
59 | 59 | ||
60 | txtTodo->setText( task.description() ); | 60 | txtTodo->setText( task.description() ); |
61 | } | 61 | } |
62 | 62 | ||
63 | /* | 63 | /* |
64 | * Constructs a NewTaskDialog which is a child of 'parent', with the | 64 | * Constructs a NewTaskDialog which is a child of 'parent', with the |
65 | * name 'name' and widget flags set to 'f' | 65 | * name 'name' and widget flags set to 'f' |
66 | * | 66 | * |
67 | * The dialog will by default be modeless, unless you set 'modal' to | 67 | * The dialog will by default be modeless, unless you set 'modal' to |
68 | * TRUE to construct a modal dialog. | 68 | * TRUE to construct a modal dialog. |
69 | */ | 69 | */ |
70 | NewTaskDialog::NewTaskDialog( int id, QWidget* parent, const char* name, bool modal, | 70 | NewTaskDialog::NewTaskDialog( int id, QWidget* parent, const char* name, bool modal, |
71 | WFlags fl ) | 71 | WFlags fl ) |
72 | : NewTaskDialogBase( parent, name, modal, fl ), | 72 | : NewTaskDialogBase( parent, name, modal, fl ), |
73 | date( QDate::currentDate() ) | 73 | date( QDate::currentDate() ) |
74 | { | 74 | { |
75 | if ( id != -1 ) { | 75 | if ( id != -1 ) { |
76 | QArray<int> ids( 1 ); | 76 | QArray<int> ids( 1 ); |
77 | ids[0] = id; | 77 | ids[0] = id; |
78 | todo.setCategories( ids ); | 78 | todo.setCategories( ids ); |
79 | } | 79 | } |
80 | init(); | 80 | init(); |
81 | } | 81 | } |
82 | 82 | ||
83 | void NewTaskDialog::init() | 83 | void NewTaskDialog::init() |
84 | { | 84 | { |
85 | QPopupMenu *m1 = new QPopupMenu( this ); | 85 | QPopupMenu *m1 = new QPopupMenu( this ); |
86 | picker = new DateBookMonth( m1, 0, TRUE ); | 86 | picker = new DateBookMonth( m1, 0, TRUE ); |
87 | m1->insertItem( picker ); | 87 | m1->insertItem( picker ); |
88 | buttonDate->setPopup( m1 ); | 88 | buttonDate->setPopup( m1 ); |
89 | comboCategory->setCategories( todo.categories(), "Todo List", tr("Todo List") ); | 89 | comboCategory->setCategories( todo.categories(), "Todo List", tr("Todo List") ); |
90 | 90 | ||
91 | connect( picker, SIGNAL( dateClicked( int, int, int ) ), | 91 | connect( picker, SIGNAL( dateClicked( int, int, int ) ), |
92 | this, SLOT( dateChanged( int, int, int ) ) ); | 92 | this, SLOT( dateChanged( int, int, int ) ) ); |
93 | 93 | ||
94 | buttonDate->setText( TimeString::longDateString( date ) ); | 94 | buttonDate->setText( TimeString::longDateString( date ) ); |
95 | picker->setDate( date.year(), date.month(), date.day() ); | 95 | picker->setDate( date.year(), date.month(), date.day() ); |
96 | } | 96 | } |
97 | 97 | ||
98 | /* | 98 | /* |
99 | * Destroys the object and frees any allocated resources | 99 | * Destroys the object and frees any allocated resources |
100 | */ | 100 | */ |
101 | NewTaskDialog::~NewTaskDialog() | 101 | NewTaskDialog::~NewTaskDialog() |
102 | { | 102 | { |
103 | // no need to delete child widgets, Qt does it all for us | 103 | // no need to delete child widgets, Qt does it all for us |
104 | } | 104 | } |
105 | void NewTaskDialog::dateChanged( int y, int m, int d ) | 105 | void NewTaskDialog::dateChanged( int y, int m, int d ) |
106 | { | 106 | { |
107 | date = QDate( y, m, d ); | 107 | date = QDate( y, m, d ); |
108 | buttonDate->setText( TimeString::longDateString( date ) ); | 108 | buttonDate->setText( TimeString::longDateString( date ) ); |
109 | } | 109 | } |
110 | 110 | ||
111 | /*! | 111 | /*! |
112 | */ | 112 | */ |
113 | 113 | ||
114 | Task NewTaskDialog::todoEntry() | 114 | Task NewTaskDialog::todoEntry() |
115 | { | 115 | { |
116 | todo.setDueDate( date, checkDate->isChecked() ); | 116 | todo.setDueDate( date, checkDate->isChecked() ); |
117 | if ( comboCategory->currentCategory() != -1 ) { | 117 | if ( comboCategory->currentCategory() != -1 ) { |
118 | todo.setCategories( comboCategory->currentCategories() ); | 118 | todo.setCategories( comboCategory->currentCategories() ); |
119 | } | 119 | } |
120 | todo.setPriority( comboPriority->currentItem() + 1 ); | 120 | todo.setPriority( comboPriority->currentItem() + 1 ); |
121 | todo.setCompleted( checkCompleted->isChecked() ); | 121 | todo.setCompleted( checkCompleted->isChecked() ); |
122 | 122 | ||
123 | todo.setDescription( txtTodo->text() ); | 123 | todo.setDescription( txtTodo->text() ); |
124 | 124 | ||
125 | return todo; | 125 | return todo; |
126 | } | 126 | } |
127 | 127 | ||
128 | 128 | ||
129 | /*! | 129 | /*! |
130 | 130 | ||
131 | */ | 131 | */ |
132 | 132 | ||
133 | void NewTaskDialog::accept() | 133 | void NewTaskDialog::accept() |
134 | { | 134 | { |
135 | QString strText = txtTodo->text(); | 135 | QString strText = txtTodo->text(); |
136 | if ( !strText || strText == "") { | 136 | if ( strText.isEmpty() ) { |
137 | // hmm... just decline it then, the user obviously didn't care about it | 137 | // hmm... just decline it then, the user obviously didn't care about it |
138 | QDialog::reject(); | 138 | QDialog::reject(); |
139 | return; | 139 | return; |
140 | } | 140 | } |
141 | QDialog::accept(); | 141 | QDialog::accept(); |
142 | } | 142 | } |
diff --git a/libopie/libopie.pro b/libopie/libopie.pro index fb00422..1c0bf7b 100644 --- a/libopie/libopie.pro +++ b/libopie/libopie.pro | |||
@@ -1,7 +1,7 @@ | |||
1 | TEMPLATE = lib | 1 | TEMPLATE = lib |
2 | CONFIG += qte warn_on release | 2 | CONFIG += qte warn_on release |
3 | HEADERS = $(OPIEDIR)/include/opie/xmltree.h | 3 | HEADERS = $(OPIEDIR)/include/opie/xmltree.h |
4 | SOURCES = xmltree.cc tododb.cpp todoevent.cpp | 4 | SOURCES = xmltree.cc tododb.cpp todoevent.cpp todovcalresource.cpp |
5 | TARGET = opie | 5 | TARGET = opie |
6 | INCLUDEPATH += $(OPIEDIR)/include | 6 | INCLUDEPATH += $(OPIEDIR)/include |
7 | DESTDIR = $(QTDIR)/lib$(PROJMAK) | 7 | DESTDIR = $(QTDIR)/lib$(PROJMAK) |
diff --git a/libopie/tododb.cpp b/libopie/tododb.cpp index b1b35d0..f9756c6 100644 --- a/libopie/tododb.cpp +++ b/libopie/tododb.cpp | |||
@@ -45,173 +45,181 @@ public: | |||
45 | tasks->save(stream ); | 45 | tasks->save(stream ); |
46 | delete tasks; | 46 | delete tasks; |
47 | file.close(); | 47 | file.close(); |
48 | return true; | 48 | return true; |
49 | } | 49 | } |
50 | return false; | 50 | return false; |
51 | } | 51 | } |
52 | QValueList<ToDoEvent> load( const QString &name ){ | 52 | QValueList<ToDoEvent> load( const QString &name ){ |
53 | qWarning("loading tododb" ); | 53 | qWarning("loading tododb" ); |
54 | QValueList<ToDoEvent> m_todos; | 54 | QValueList<ToDoEvent> m_todos; |
55 | XMLElement *root = XMLElement::load( name ); | 55 | XMLElement *root = XMLElement::load( name ); |
56 | if(root != 0l ){ // start parsing | 56 | if(root != 0l ){ // start parsing |
57 | qWarning("ToDoDB::load tagName(): %s", root->tagName().latin1() ); | 57 | qWarning("ToDoDB::load tagName(): %s", root->tagName().latin1() ); |
58 | //if( root->tagName() == QString::fromLatin1("Tasks" ) ){// Start | 58 | //if( root->tagName() == QString::fromLatin1("Tasks" ) ){// Start |
59 | XMLElement *element = root->firstChild(); | 59 | XMLElement *element = root->firstChild(); |
60 | element = element->firstChild(); | 60 | element = element->firstChild(); |
61 | while( element ){ | 61 | while( element ){ |
62 | qWarning("ToDoDB::load element tagName() : %s", element->tagName().latin1() ); | 62 | qWarning("ToDoDB::load element tagName() : %s", element->tagName().latin1() ); |
63 | QString dummy; | 63 | QString dummy; |
64 | ToDoEvent event; | 64 | ToDoEvent event; |
65 | bool ok; | 65 | bool ok; |
66 | int dumInt; | 66 | int dumInt; |
67 | // completed | 67 | // completed |
68 | dummy = element->attribute("Completed" ); | 68 | dummy = element->attribute("Completed" ); |
69 | dumInt = dummy.toInt(&ok ); | 69 | dumInt = dummy.toInt(&ok ); |
70 | if(ok ) event.setCompleted( dumInt == 0 ? false : true ); | 70 | if(ok ) event.setCompleted( dumInt == 0 ? false : true ); |
71 | // hasDate | 71 | // hasDate |
72 | dummy = element->attribute("HasDate" ); | 72 | dummy = element->attribute("HasDate" ); |
73 | dumInt = dummy.toInt(&ok ); | 73 | dumInt = dummy.toInt(&ok ); |
74 | if(ok ) event.setHasDate( dumInt == 0 ? false: true ); | 74 | if(ok ) event.setHasDate( dumInt == 0 ? false: true ); |
75 | // set the date | 75 | // set the date |
76 | bool hasDa = dumInt; | 76 | bool hasDa = dumInt; |
77 | if ( hasDa ) { //parse the date | 77 | if ( hasDa ) { //parse the date |
78 | int year, day, month = 0; | 78 | int year, day, month = 0; |
79 | year = day = month; | 79 | year = day = month; |
80 | // year | 80 | // year |
81 | dummy = element->attribute("DateYear" ); | 81 | dummy = element->attribute("DateYear" ); |
82 | dumInt = dummy.toInt(&ok ); | 82 | dumInt = dummy.toInt(&ok ); |
83 | if( ok ) year = dumInt; | 83 | if( ok ) year = dumInt; |
84 | // month | 84 | // month |
85 | dummy = element->attribute("DateMonth" ); | 85 | dummy = element->attribute("DateMonth" ); |
86 | dumInt = dummy.toInt(&ok ); | 86 | dumInt = dummy.toInt(&ok ); |
87 | if(ok ) month = dumInt; | 87 | if(ok ) month = dumInt; |
88 | dummy = element->attribute("DateDay" ); | 88 | dummy = element->attribute("DateDay" ); |
89 | dumInt = dummy.toInt(&ok ); | 89 | dumInt = dummy.toInt(&ok ); |
90 | if(ok ) day = dumInt; | 90 | if(ok ) day = dumInt; |
91 | // set the date | 91 | // set the date |
92 | QDate date( year, month, day ); | 92 | QDate date( year, month, day ); |
93 | event.setDate( date); | 93 | event.setDate( date); |
94 | } | 94 | } |
95 | dummy = element->attribute("Priority" ); | 95 | dummy = element->attribute("Priority" ); |
96 | dumInt = dummy.toInt(&ok ); | 96 | dumInt = dummy.toInt(&ok ); |
97 | if(!ok ) dumInt = ToDoEvent::NORMAL; | 97 | if(!ok ) dumInt = ToDoEvent::NORMAL; |
98 | event.setPriority( dumInt ); | 98 | event.setPriority( dumInt ); |
99 | //description | 99 | //description |
100 | dummy = element->attribute("Description" ); | 100 | dummy = element->attribute("Description" ); |
101 | event.setDescription( dummy ); | 101 | event.setDescription( dummy ); |
102 | // category | 102 | // category |
103 | dummy = element->attribute("Categories" ); | 103 | dummy = element->attribute("Categories" ); |
104 | dumInt = dummy.toInt(&ok ); | 104 | dumInt = dummy.toInt(&ok ); |
105 | if(ok ) { | 105 | if(ok ) { |
106 | QArray<int> arrat(1); | 106 | QArray<int> arrat(1); |
107 | arrat[0] = dumInt; | 107 | arrat[0] = dumInt; |
108 | event.setCategory( Qtopia::Record::idsToString( arrat ) ); | 108 | event.setCategory( Qtopia::Record::idsToString( arrat ) ); |
109 | } | 109 | } |
110 | //uid | 110 | //uid |
111 | dummy = element->attribute("Uid" ); | 111 | dummy = element->attribute("Uid" ); |
112 | dumInt = dummy.toInt(&ok ); | 112 | dumInt = dummy.toInt(&ok ); |
113 | if(ok ) event.setUid( dumInt ); | 113 | if(ok ) event.setUid( dumInt ); |
114 | m_todos.append( event ); | 114 | m_todos.append( event ); |
115 | element = element->nextChild(); // next element | 115 | element = element->nextChild(); // next element |
116 | } | 116 | } |
117 | //} | 117 | //} |
118 | }else { | 118 | }else { |
119 | qWarning("could not load" ); | 119 | qWarning("could not load" ); |
120 | } | 120 | } |
121 | delete root; | 121 | delete root; |
122 | qWarning("returning" ); | 122 | qWarning("returning" ); |
123 | return m_todos; | 123 | return m_todos; |
124 | } | 124 | } |
125 | }; | 125 | }; |
126 | 126 | ||
127 | } | 127 | } |
128 | 128 | ||
129 | ToDoDB::ToDoDB(const QString &fileName = QString::null, ToDoResource *res ){ | 129 | ToDoDB::ToDoDB(const QString &fileName = QString::null, ToDoResource *res ){ |
130 | m_fileName = fileName; | 130 | m_fileName = fileName; |
131 | if( fileName.isEmpty() && res == 0 ){ | 131 | if( fileName.isEmpty() && res == 0 ){ |
132 | m_fileName = Global::applicationFileName("todolist","todolist.xml"); | 132 | m_fileName = Global::applicationFileName("todolist","todolist.xml"); |
133 | res = new FileToDoResource(); | 133 | res = new FileToDoResource(); |
134 | //qWarning("%s", m_fileName.latin1() ); | 134 | //qWarning("%s", m_fileName.latin1() ); |
135 | }else if(res == 0 ){ // let's create a ToDoResource for xml | 135 | }else if(res == 0 ){ // let's create a ToDoResource for xml |
136 | res = new FileToDoResource(); | 136 | res = new FileToDoResource(); |
137 | } | 137 | } |
138 | m_res = res; | 138 | m_res = res; |
139 | load(); | 139 | load(); |
140 | } | 140 | } |
141 | ToDoResource* ToDoDB::resource(){ | ||
142 | return m_res; | ||
143 | }; | ||
144 | void ToDoDB::setResource( ToDoResource *res ) | ||
145 | { | ||
146 | delete m_res; | ||
147 | m_res = res; | ||
148 | } | ||
141 | ToDoDB::~ToDoDB() | 149 | ToDoDB::~ToDoDB() |
142 | { | 150 | { |
143 | delete m_res; | 151 | delete m_res; |
144 | } | 152 | } |
145 | QValueList<ToDoEvent> ToDoDB::effectiveToDos(const QDate &from, const QDate &to, | 153 | QValueList<ToDoEvent> ToDoDB::effectiveToDos(const QDate &from, const QDate &to, |
146 | bool all ) | 154 | bool all ) |
147 | { | 155 | { |
148 | QValueList<ToDoEvent> events; | 156 | QValueList<ToDoEvent> events; |
149 | for( QValueList<ToDoEvent>::Iterator it = m_todos.begin(); it!= m_todos.end(); ++it ){ | 157 | for( QValueList<ToDoEvent>::Iterator it = m_todos.begin(); it!= m_todos.end(); ++it ){ |
150 | if( (*it).hasDate() ){ | 158 | if( (*it).hasDate() ){ |
151 | if( (*it).date() >= from && (*it).date() <= to ) | 159 | if( (*it).date() >= from && (*it).date() <= to ) |
152 | events.append( (*it) ); | 160 | events.append( (*it) ); |
153 | }else if( all ){ | 161 | }else if( all ){ |
154 | events.append( (*it) ); | 162 | events.append( (*it) ); |
155 | } | 163 | } |
156 | } | 164 | } |
157 | return events; | 165 | return events; |
158 | } | 166 | } |
159 | QValueList<ToDoEvent> ToDoDB::effectiveToDos(const QDate &from, | 167 | QValueList<ToDoEvent> ToDoDB::effectiveToDos(const QDate &from, |
160 | bool all) | 168 | bool all) |
161 | { | 169 | { |
162 | return effectiveToDos( from, QDate::currentDate(), all ); | 170 | return effectiveToDos( from, QDate::currentDate(), all ); |
163 | } | 171 | } |
164 | QValueList<ToDoEvent> ToDoDB::overDue() | 172 | QValueList<ToDoEvent> ToDoDB::overDue() |
165 | { | 173 | { |
166 | QValueList<ToDoEvent> events; | 174 | QValueList<ToDoEvent> events; |
167 | for( QValueList<ToDoEvent>::Iterator it = m_todos.begin(); it!= m_todos.end(); ++it ){ | 175 | for( QValueList<ToDoEvent>::Iterator it = m_todos.begin(); it!= m_todos.end(); ++it ){ |
168 | if( (*it).isOverdue() ) | 176 | if( (*it).isOverdue() ) |
169 | events.append((*it) ); | 177 | events.append((*it) ); |
170 | } | 178 | } |
171 | return events; | 179 | return events; |
172 | } | 180 | } |
173 | QValueList<ToDoEvent> ToDoDB::rawToDos() | 181 | QValueList<ToDoEvent> ToDoDB::rawToDos() |
174 | { | 182 | { |
175 | return m_todos; | 183 | return m_todos; |
176 | } | 184 | } |
177 | void ToDoDB::addEvent( const ToDoEvent &event ) | 185 | void ToDoDB::addEvent( const ToDoEvent &event ) |
178 | { | 186 | { |
179 | m_todos.append( event ); | 187 | m_todos.append( event ); |
180 | } | 188 | } |
181 | void ToDoDB::editEvent( const ToDoEvent &event ) | 189 | void ToDoDB::editEvent( const ToDoEvent &event ) |
182 | { | 190 | { |
183 | m_todos.remove( event ); | 191 | m_todos.remove( event ); |
184 | m_todos.append( event ); | 192 | m_todos.append( event ); |
185 | } | 193 | } |
186 | void ToDoDB::removeEvent( const ToDoEvent &event ) | 194 | void ToDoDB::removeEvent( const ToDoEvent &event ) |
187 | { | 195 | { |
188 | m_todos.remove( event ); | 196 | m_todos.remove( event ); |
189 | } | 197 | } |
190 | void ToDoDB::reload() | 198 | void ToDoDB::reload() |
191 | { | 199 | { |
192 | load(); | 200 | load(); |
193 | } | 201 | } |
194 | void ToDoDB::setFileName(const QString &file ) | 202 | void ToDoDB::setFileName(const QString &file ) |
195 | { | 203 | { |
196 | m_fileName =file; | 204 | m_fileName =file; |
197 | } | 205 | } |
198 | QString ToDoDB::fileName()const | 206 | QString ToDoDB::fileName()const |
199 | { | 207 | { |
200 | return m_fileName; | 208 | return m_fileName; |
201 | } | 209 | } |
202 | void ToDoDB::load() | 210 | void ToDoDB::load() |
203 | { | 211 | { |
204 | m_todos = m_res->load( m_fileName ); | 212 | m_todos = m_res->load( m_fileName ); |
205 | } | 213 | } |
206 | bool ToDoDB::save() | 214 | bool ToDoDB::save() |
207 | { | 215 | { |
208 | return m_res->save( m_fileName, m_todos ); | 216 | return m_res->save( m_fileName, m_todos ); |
209 | } | 217 | } |
210 | 218 | ||
211 | 219 | ||
212 | 220 | ||
213 | 221 | ||
214 | 222 | ||
215 | 223 | ||
216 | 224 | ||
217 | 225 | ||
diff --git a/libopie/todoevent.cpp b/libopie/todoevent.cpp index 4cfe1c0..5fa4472 100644 --- a/libopie/todoevent.cpp +++ b/libopie/todoevent.cpp | |||
@@ -1,150 +1,152 @@ | |||
1 | 1 | ||
2 | #include <opie/todoevent.h> | 2 | #include <opie/todoevent.h> |
3 | #include <qpe/palmtopuidgen.h> | 3 | #include <qpe/palmtopuidgen.h> |
4 | #include <qpe/stringutil.h> | ||
5 | //#include <qpe/palmtoprecord.h> | ||
4 | 6 | ||
5 | ToDoEvent::ToDoEvent(bool completed, int priority, const QString &category, | 7 | ToDoEvent::ToDoEvent(bool completed, int priority, const QString &category, |
6 | const QString &description, bool hasDate, QDate date, int uid ) | 8 | const QString &description, bool hasDate, QDate date, int uid ) |
7 | { | 9 | { |
8 | qWarning("todoEvent c'tor" ); | 10 | qWarning("todoEvent c'tor" ); |
9 | m_date = date; | 11 | m_date = date; |
10 | m_isCompleted = completed; | 12 | m_isCompleted = completed; |
11 | m_hasDate = hasDate; | 13 | m_hasDate = hasDate; |
12 | m_priority = priority; | 14 | m_priority = priority; |
13 | m_category = category; | 15 | m_category = category; |
14 | m_desc = description; | 16 | m_desc = Qtopia::simplifyMultiLineSpace(description ); |
15 | if (uid == -1 ) { | 17 | if (uid == -1 ) { |
16 | Qtopia::UidGen *uidgen = new Qtopia::UidGen(); | 18 | Qtopia::UidGen *uidgen = new Qtopia::UidGen(); |
17 | uid = uidgen->generate(); | 19 | uid = uidgen->generate(); |
18 | delete uidgen; | 20 | delete uidgen; |
19 | }// generate the ids | 21 | }// generate the ids |
20 | m_uid = uid; | 22 | m_uid = uid; |
21 | } | 23 | } |
22 | bool ToDoEvent::isCompleted() const | 24 | bool ToDoEvent::isCompleted() const |
23 | { | 25 | { |
24 | return m_isCompleted; | 26 | return m_isCompleted; |
25 | } | 27 | } |
26 | bool ToDoEvent::hasDate() const | 28 | bool ToDoEvent::hasDate() const |
27 | { | 29 | { |
28 | return m_hasDate; | 30 | return m_hasDate; |
29 | } | 31 | } |
30 | int ToDoEvent::priority()const | 32 | int ToDoEvent::priority()const |
31 | { | 33 | { |
32 | return m_priority; | 34 | return m_priority; |
33 | } | 35 | } |
34 | QString ToDoEvent::category()const | 36 | QString ToDoEvent::category()const |
35 | { | 37 | { |
36 | return m_category; | 38 | return m_category; |
37 | } | 39 | } |
38 | QDate ToDoEvent::date()const | 40 | QDate ToDoEvent::date()const |
39 | { | 41 | { |
40 | return m_date; | 42 | return m_date; |
41 | } | 43 | } |
42 | QString ToDoEvent::description()const | 44 | QString ToDoEvent::description()const |
43 | { | 45 | { |
44 | return m_desc; | 46 | return m_desc; |
45 | } | 47 | } |
46 | void ToDoEvent::setCompleted( bool completed ) | 48 | void ToDoEvent::setCompleted( bool completed ) |
47 | { | 49 | { |
48 | m_isCompleted = completed; | 50 | m_isCompleted = completed; |
49 | } | 51 | } |
50 | void ToDoEvent::setHasDate( bool hasDate ) | 52 | void ToDoEvent::setHasDate( bool hasDate ) |
51 | { | 53 | { |
52 | m_hasDate = hasDate; | 54 | m_hasDate = hasDate; |
53 | } | 55 | } |
54 | void ToDoEvent::setDescription(const QString &desc ) | 56 | void ToDoEvent::setDescription(const QString &desc ) |
55 | { | 57 | { |
56 | m_desc = desc; | 58 | m_desc = Qtopia::simplifyMultiLineSpace(desc ); |
57 | } | 59 | } |
58 | void ToDoEvent::setCategory( const QString &cat ) | 60 | void ToDoEvent::setCategory( const QString &cat ) |
59 | { | 61 | { |
60 | m_category = cat; | 62 | m_category = cat; |
61 | } | 63 | } |
62 | void ToDoEvent::setPriority(int prio ) | 64 | void ToDoEvent::setPriority(int prio ) |
63 | { | 65 | { |
64 | m_priority = prio; | 66 | m_priority = prio; |
65 | } | 67 | } |
66 | void ToDoEvent::setDate( QDate date ) | 68 | void ToDoEvent::setDate( QDate date ) |
67 | { | 69 | { |
68 | m_date = date; | 70 | m_date = date; |
69 | } | 71 | } |
70 | bool ToDoEvent::isOverdue( ) | 72 | bool ToDoEvent::isOverdue( ) |
71 | { | 73 | { |
72 | if( m_hasDate ) | 74 | if( m_hasDate ) |
73 | return QDate::currentDate() > m_date; | 75 | return QDate::currentDate() > m_date; |
74 | return false; | 76 | return false; |
75 | } | 77 | } |
76 | bool ToDoEvent::operator<( const ToDoEvent &toDoEvent )const{ | 78 | bool ToDoEvent::operator<( const ToDoEvent &toDoEvent )const{ |
77 | if( !hasDate() && !toDoEvent.hasDate() ) return true; | 79 | if( !hasDate() && !toDoEvent.hasDate() ) return true; |
78 | if( !hasDate() && toDoEvent.hasDate() ) return true; | 80 | if( !hasDate() && toDoEvent.hasDate() ) return true; |
79 | if( hasDate() && toDoEvent.hasDate() ){ | 81 | if( hasDate() && toDoEvent.hasDate() ){ |
80 | if( date() == toDoEvent.date() ){ // let's the priority decide | 82 | if( date() == toDoEvent.date() ){ // let's the priority decide |
81 | return priority() < toDoEvent.priority(); | 83 | return priority() < toDoEvent.priority(); |
82 | }else{ | 84 | }else{ |
83 | return date() < toDoEvent.date(); | 85 | return date() < toDoEvent.date(); |
84 | } | 86 | } |
85 | } | 87 | } |
86 | return false; | 88 | return false; |
87 | } | 89 | } |
88 | bool ToDoEvent::operator<=(const ToDoEvent &toDoEvent )const | 90 | bool ToDoEvent::operator<=(const ToDoEvent &toDoEvent )const |
89 | { | 91 | { |
90 | if( !hasDate() && !toDoEvent.hasDate() ) return true; | 92 | if( !hasDate() && !toDoEvent.hasDate() ) return true; |
91 | if( !hasDate() && toDoEvent.hasDate() ) return true; | 93 | if( !hasDate() && toDoEvent.hasDate() ) return true; |
92 | if( hasDate() && toDoEvent.hasDate() ){ | 94 | if( hasDate() && toDoEvent.hasDate() ){ |
93 | if( date() == toDoEvent.date() ){ // let's the priority decide | 95 | if( date() == toDoEvent.date() ){ // let's the priority decide |
94 | return priority() <= toDoEvent.priority(); | 96 | return priority() <= toDoEvent.priority(); |
95 | }else{ | 97 | }else{ |
96 | return date() <= toDoEvent.date(); | 98 | return date() <= toDoEvent.date(); |
97 | } | 99 | } |
98 | } | 100 | } |
99 | return true; | 101 | return true; |
100 | } | 102 | } |
101 | bool ToDoEvent::operator>(const ToDoEvent &toDoEvent )const | 103 | bool ToDoEvent::operator>(const ToDoEvent &toDoEvent )const |
102 | { | 104 | { |
103 | if( !hasDate() && !toDoEvent.hasDate() ) return false; | 105 | if( !hasDate() && !toDoEvent.hasDate() ) return false; |
104 | if( !hasDate() && toDoEvent.hasDate() ) return false; | 106 | if( !hasDate() && toDoEvent.hasDate() ) return false; |
105 | if( hasDate() && toDoEvent.hasDate() ){ | 107 | if( hasDate() && toDoEvent.hasDate() ){ |
106 | if( date() == toDoEvent.date() ){ // let's the priority decide | 108 | if( date() == toDoEvent.date() ){ // let's the priority decide |
107 | return priority() > toDoEvent.priority(); | 109 | return priority() > toDoEvent.priority(); |
108 | }else{ | 110 | }else{ |
109 | return date() > toDoEvent.date(); | 111 | return date() > toDoEvent.date(); |
110 | } | 112 | } |
111 | } | 113 | } |
112 | return false; | 114 | return false; |
113 | } | 115 | } |
114 | bool ToDoEvent::operator>=(const ToDoEvent &toDoEvent )const | 116 | bool ToDoEvent::operator>=(const ToDoEvent &toDoEvent )const |
115 | { | 117 | { |
116 | if( !hasDate() && !toDoEvent.hasDate() ) return true; | 118 | if( !hasDate() && !toDoEvent.hasDate() ) return true; |
117 | if( !hasDate() && toDoEvent.hasDate() ) return false; | 119 | if( !hasDate() && toDoEvent.hasDate() ) return false; |
118 | if( hasDate() && toDoEvent.hasDate() ){ | 120 | if( hasDate() && toDoEvent.hasDate() ){ |
119 | if( date() == toDoEvent.date() ){ // let's the priority decide | 121 | if( date() == toDoEvent.date() ){ // let's the priority decide |
120 | return priority() > toDoEvent.priority(); | 122 | return priority() > toDoEvent.priority(); |
121 | }else{ | 123 | }else{ |
122 | return date() > toDoEvent.date(); | 124 | return date() > toDoEvent.date(); |
123 | } | 125 | } |
124 | } | 126 | } |
125 | return true; | 127 | return true; |
126 | } | 128 | } |
127 | bool ToDoEvent::operator==(const ToDoEvent &toDoEvent )const | 129 | bool ToDoEvent::operator==(const ToDoEvent &toDoEvent )const |
128 | { | 130 | { |
129 | if( m_date == toDoEvent.m_date && m_isCompleted == toDoEvent.m_isCompleted && m_hasDate == toDoEvent.m_hasDate && m_priority == toDoEvent.m_priority && m_category == toDoEvent.m_category && m_desc == toDoEvent.m_category ) | 131 | if( m_date == toDoEvent.m_date && m_isCompleted == toDoEvent.m_isCompleted && m_hasDate == toDoEvent.m_hasDate && m_priority == toDoEvent.m_priority && m_category == toDoEvent.m_category && m_desc == toDoEvent.m_category ) |
130 | return true; | 132 | return true; |
131 | return false; | 133 | return false; |
132 | } | 134 | } |
133 | ToDoEvent &ToDoEvent::operator=(const ToDoEvent &item ) | 135 | ToDoEvent &ToDoEvent::operator=(const ToDoEvent &item ) |
134 | { | 136 | { |
135 | m_date = item.m_date; | 137 | m_date = item.m_date; |
136 | m_isCompleted = item.m_isCompleted; | 138 | m_isCompleted = item.m_isCompleted; |
137 | m_hasDate = item.m_hasDate; | 139 | m_hasDate = item.m_hasDate; |
138 | m_priority = item.m_priority; | 140 | m_priority = item.m_priority; |
139 | m_category = item.m_category; | 141 | m_category = item.m_category; |
140 | m_desc = item.m_desc; | 142 | m_desc = item.m_desc; |
141 | return *this; | 143 | return *this; |
142 | } | 144 | } |
143 | 145 | ||
144 | 146 | ||
145 | 147 | ||
146 | 148 | ||
147 | 149 | ||
148 | 150 | ||
149 | 151 | ||
150 | 152 | ||
diff --git a/libopie/todovcalresource.cpp b/libopie/todovcalresource.cpp new file mode 100644 index 0000000..a6afe68 --- a/dev/null +++ b/libopie/todovcalresource.cpp | |||
@@ -0,0 +1,153 @@ | |||
1 | /* | ||
2 | =. This file is part of the OPIE Project | ||
3 | .=l. Copyright (c) 2002 Holger Freyther <freyther@kde.org> | ||
4 | .>+-= the use of vobject was inspired by libkcal | ||
5 | _;:, .> :=|. This library is free software; you can | ||
6 | .> <`_, > . <= redistribute it and/or modify it under | ||
7 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public | ||
8 | .="- .-=="i, .._ License as published by the Free Software | ||
9 | - . .-<_> .<> Foundation; either version 2 of the License, | ||
10 | ._= =} : or (at your option) any later version. | ||
11 | .%`+i> _;_. | ||
12 | .i_,=:_. -<s. This library is distributed in the hope that | ||
13 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | ||
14 | : .. .:, . . . without even the implied warranty of | ||
15 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | ||
16 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU | ||
17 | ..}^=.= = ; Library General Public License for more | ||
18 | ++= -. .` .: details. | ||
19 | : = ...= . :.=- | ||
20 | -. .:....=;==+<; You should have received a copy of the GNU | ||
21 | -_. . . )=. = Library General Public License along with | ||
22 | -- :-=` this library; see the file COPYING.LIB. | ||
23 | If not, write to the Free Software Foundation, | ||
24 | Inc., 59 Temple Place - Suite 330, | ||
25 | Boston, MA 02111-1307, USA. | ||
26 | |||
27 | */ | ||
28 | |||
29 | #include <qfile.h> | ||
30 | #include <qvaluelist.h> | ||
31 | #include <opie/todoevent.h> | ||
32 | #include <opie/todovcalresource.h> | ||
33 | |||
34 | #include "../library/backend/vobject_p.h" | ||
35 | #include "../library/backend/timeconversion.h" | ||
36 | #include "../library/backend/qfiledirect_p.h" | ||
37 | |||
38 | static VObject *vobjByEvent( const ToDoEvent &event ) | ||
39 | { | ||
40 | VObject *task = newVObject( VCTodoProp ); | ||
41 | if( task == 0 ) | ||
42 | return 0l; | ||
43 | if( event.hasDate() ) | ||
44 | addPropValue( task, VCDueProp, TimeConversion::toISO8601( event.date() ) ); | ||
45 | |||
46 | if( event.isCompleted() ) | ||
47 | addPropValue( task, VCStatusProp, "COMPLETED"); | ||
48 | |||
49 | QString string = QString::number(event.priority() ); | ||
50 | addPropValue( task, VCPriorityProp, string.local8Bit() ); | ||
51 | addPropValue( task, VCCategoriesProp, event.category().local8Bit() ); | ||
52 | addPropValue( task, VCDescriptionProp, event.description().local8Bit() ); | ||
53 | addPropValue( task, VCSummaryProp, event.description().left(15).local8Bit() ); | ||
54 | return task; | ||
55 | }; | ||
56 | |||
57 | static ToDoEvent eventByVObj( VObject *obj ){ | ||
58 | ToDoEvent event; | ||
59 | VObject *ob; | ||
60 | QCString name; | ||
61 | // no uid, attendees, ... and no fun | ||
62 | // description | ||
63 | if( ( ob = isAPropertyOf( obj, VCDescriptionProp )) != 0 ){ | ||
64 | name = vObjectStringZValue( ob ); | ||
65 | event.setDescription( name ); | ||
66 | } | ||
67 | // completed | ||
68 | if( ( ob = isAPropertyOf( obj, VCStatusProp )) != 0 ){ | ||
69 | name = vObjectStringZValue( ob ); | ||
70 | if( name == "COMPLETED" ){ | ||
71 | event.setCompleted( true ); | ||
72 | }else{ | ||
73 | event.setCompleted( false ); | ||
74 | } | ||
75 | }else | ||
76 | event.setCompleted( false ); | ||
77 | // priority | ||
78 | if ((ob = isAPropertyOf(obj, VCPriorityProp))) { | ||
79 | name = vObjectStringZValue( ob ); | ||
80 | bool ok; | ||
81 | event.setPriority(name.toInt(&ok) ); | ||
82 | } | ||
83 | //due date | ||
84 | if((ob = isAPropertyOf(obj, VCDueProp)) ){ | ||
85 | event.setHasDate( true ); | ||
86 | name = vObjectStringZValue( ob ); | ||
87 | event.setDate( TimeConversion::fromISO8601( name).date() ); | ||
88 | } | ||
89 | // categories | ||
90 | if((ob = isAPropertyOf( obj, VCCategoriesProp )) != 0 ){ | ||
91 | name = vObjectStringZValue( ob ); | ||
92 | qWarning("Categories:%s", name.data() ); | ||
93 | } | ||
94 | |||
95 | return event; | ||
96 | }; | ||
97 | |||
98 | |||
99 | QValueList<ToDoEvent> ToDoVCalResource::load(const QString &file) | ||
100 | { | ||
101 | QValueList<ToDoEvent> events; | ||
102 | VObject *vcal = 0l; | ||
103 | vcal = Parse_MIME_FromFileName( (char *)file.utf8().data() ); // from vobject | ||
104 | if(!vcal ) | ||
105 | return events; | ||
106 | // start parsing | ||
107 | |||
108 | VObjectIterator it; | ||
109 | VObject *vobj; | ||
110 | initPropIterator(&it, vcal); | ||
111 | |||
112 | while( moreIteration( &it ) ) { | ||
113 | vobj = ::nextVObject( &it ); | ||
114 | QCString name = ::vObjectName( vobj ); | ||
115 | //QCString objVal = ::vObjectStringZValue( vobj ); | ||
116 | // let's find out the type | ||
117 | if( name == VCTodoProp ){ | ||
118 | events.append( eventByVObj( vobj ) ); | ||
119 | |||
120 | } // parse the value | ||
121 | } | ||
122 | return events; | ||
123 | } | ||
124 | bool ToDoVCalResource::save(const QString &fileName, const QValueList<ToDoEvent>&list ) | ||
125 | { | ||
126 | QFileDirect file ( fileName ); | ||
127 | if(!file.open(IO_WriteOnly ) ) | ||
128 | return false; | ||
129 | // obj | ||
130 | VObject *obj; | ||
131 | obj = newVObject( VCCalProp ); | ||
132 | addPropValue( obj, VCVersionProp, "1.0" ); | ||
133 | VObject *vo; | ||
134 | for(QValueList<ToDoEvent>::ConstIterator it = list.begin(); it != list.end(); ++it ){ | ||
135 | vo = vobjByEvent( (*it) ); | ||
136 | addVObjectProp(obj, vo ); | ||
137 | } | ||
138 | writeVObject( file.directHandle(), obj ); | ||
139 | cleanVObject( obj ); | ||
140 | cleanStrTbl(); | ||
141 | |||
142 | return true; | ||
143 | } | ||
144 | |||
145 | |||
146 | |||
147 | |||
148 | |||
149 | |||
150 | |||
151 | |||
152 | |||
153 | |||