summaryrefslogtreecommitdiff
path: root/library/backend
authorzecke <zecke>2003-04-16 10:57:59 (UTC)
committer zecke <zecke>2003-04-16 10:57:59 (UTC)
commiteeb29547890a2d162de66d7d5b98d3840a7e2d79 (patch) (unidiff)
tree973c6de7aae2fd5ba368efb87fa24234f0e12aa3 /library/backend
parentdfa2d294b3af09bf3757a3c2294a925093e72fc6 (diff)
downloadopie-eeb29547890a2d162de66d7d5b98d3840a7e2d79.zip
opie-eeb29547890a2d162de66d7d5b98d3840a7e2d79.tar.gz
opie-eeb29547890a2d162de66d7d5b98d3840a7e2d79.tar.bz2
Fix API docu
Diffstat (limited to 'library/backend') (more/less context) (ignore whitespace changes)
-rw-r--r--library/backend/categories.cpp9
-rw-r--r--library/backend/categories.h2
-rw-r--r--library/backend/event.cpp4
-rw-r--r--library/backend/palmtoprecord.h12
4 files changed, 17 insertions, 10 deletions
diff --git a/library/backend/categories.cpp b/library/backend/categories.cpp
index 2e84089..cce9f38 100644
--- a/library/backend/categories.cpp
+++ b/library/backend/categories.cpp
@@ -1,936 +1,931 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. 2** Copyright (C) 2000-2002 Trolltech AS. All rights reserved.
3** 3**
4** This file is part of the Qtopia Environment. 4** This file is part of the 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#include <qtopia/private/categories.h> 20#include <qtopia/private/categories.h>
21#include <qtopia/stringutil.h> 21#include <qtopia/stringutil.h>
22#include <qfile.h> 22#include <qfile.h>
23#include <qcstring.h> 23#include <qcstring.h>
24#include <qtextstream.h> 24#include <qtextstream.h>
25 25
26using namespace Qtopia; 26using namespace Qtopia;
27 27
28/*********************************************************** 28/***********************************************************
29 * 29 *
30 * CategoryGroup 30 * CategoryGroup
31 * 31 *
32 **********************************************************/ 32 **********************************************************/
33 33
34#ifdef PALMTOPCENTER 34#ifdef PALMTOPCENTER
35UidGen CategoryGroup::sUidGen( UidGen::PalmtopCenter ); 35UidGen CategoryGroup::sUidGen( UidGen::PalmtopCenter );
36#else 36#else
37UidGen CategoryGroup::sUidGen( UidGen::Qtopia ); 37UidGen CategoryGroup::sUidGen( UidGen::Qtopia );
38#endif 38#endif
39 39
40/*! \class CategoryGroup categories.h 40/*! \class CategoryGroup categories.h
41 \brief Helper class that is used by Categories 41 \brief Helper class that is used by Categories
42 42
43 CategoryGroup is a group of categories that is associated with an 43 CategoryGroup is a group of categories that is associated with an
44 application or global set. Mainly it defines a map of ids to 44 application or global set. Mainly it defines a map of ids to
45 category labels and category labels to ids. Lookups can be done with 45 category labels and category labels to ids. Lookups can be done with
46 labels or unique idenifiers. 46 labels or unique idenifiers.
47 47
48 \ingroup qtopiaemb 48 \ingroup qtopiaemb
49 \ingroup qtopiadesktop 49 \ingroup qtopiadesktop
50 \warning Categories API will likely change between Qtopia 1.5 and Qtopia 3 50 \warning Categories API will likely change between Qtopia 1.5 and Qtopia 3
51 \sa Categories::appGroupMap(), Categories::globalGroup() 51 \sa Categories::appGroupMap(), Categories::globalGroup()
52 */ 52 */
53 53
54/*! Add \a label and return the UID. If failure, then 0 is returned. Note 54/*! Add \a label and return the UID. If failure, then 0 is returned. Note
55 that All and Unfiled are reserved labels. 55 that All and Unfiled are reserved labels.
56 \internal 56 \internal
57*/ 57*/
58int CategoryGroup::add( const QString &label ) 58int CategoryGroup::add( const QString &label )
59{ 59{
60 if ( label == QObject::tr("All") || label == QObject::tr("Unfiled") ) 60 if ( label == QObject::tr("All") || label == QObject::tr("Unfiled") )
61 return 0; 61 return 0;
62 62
63 QMap<QString,int>::Iterator findIt = mLabelIdMap.find( label ); 63 QMap<QString,int>::Iterator findIt = mLabelIdMap.find( label );
64 if ( findIt != mLabelIdMap.end() ) 64 if ( findIt != mLabelIdMap.end() )
65 return 0; 65 return 0;
66 int newUid = uidGen().generate(); 66 int newUid = uidGen().generate();
67 insert( newUid, label ); 67 insert( newUid, label );
68 return newUid; 68 return newUid;
69} 69}
70 70
71void CategoryGroup::insert( int uid, const QString &label ) 71void CategoryGroup::insert( int uid, const QString &label )
72{ 72{
73 uidGen().store( uid ); 73 uidGen().store( uid );
74 mIdLabelMap[uid] = label; 74 mIdLabelMap[uid] = label;
75 mLabelIdMap[label] = uid; 75 mLabelIdMap[label] = uid;
76} 76}
77 77
78/*! \internal 78/*! \internal
79 */ 79 */
80bool CategoryGroup::add( int uid, const QString &label ) 80bool CategoryGroup::add( int uid, const QString &label )
81{ 81{
82 if ( label == QObject::tr("All") || label == QObject::tr("Unfiled") ) 82 if ( label == QObject::tr("All") || label == QObject::tr("Unfiled") )
83 return FALSE; 83 return FALSE;
84 84
85 QMap<QString,int>::ConstIterator labelIt = mLabelIdMap.find( label ); 85 QMap<QString,int>::ConstIterator labelIt = mLabelIdMap.find( label );
86 if ( labelIt != mLabelIdMap.end() ) 86 if ( labelIt != mLabelIdMap.end() )
87 return FALSE; 87 return FALSE;
88 QMap<int,QString>::ConstIterator idIt = mIdLabelMap.find( uid ); 88 QMap<int,QString>::ConstIterator idIt = mIdLabelMap.find( uid );
89 if ( idIt != mIdLabelMap.end() ) 89 if ( idIt != mIdLabelMap.end() )
90 return FALSE; 90 return FALSE;
91 insert( uid, label ); 91 insert( uid, label );
92 return TRUE; 92 return TRUE;
93} 93}
94 94
95/*! Returns TRUE if \a label was removed from the group, FALSE if not. 95/*! Returns TRUE if \a label was removed from the group, FALSE if not.
96 \internal 96 \internal
97 */ 97 */
98bool CategoryGroup::remove( const QString &label ) 98bool CategoryGroup::remove( const QString &label )
99{ 99{
100 QMap<QString,int>::Iterator findIt = mLabelIdMap.find( label ); 100 QMap<QString,int>::Iterator findIt = mLabelIdMap.find( label );
101 if ( findIt == mLabelIdMap.end() ) 101 if ( findIt == mLabelIdMap.end() )
102 return FALSE; 102 return FALSE;
103 103
104 mIdLabelMap.remove( *findIt ); 104 mIdLabelMap.remove( *findIt );
105 mLabelIdMap.remove( findIt ); 105 mLabelIdMap.remove( findIt );
106 106
107 return TRUE; 107 return TRUE;
108} 108}
109 109
110/*! Returns TRUE if \a uid was removed from the group, FALSE if not. 110/*! Returns TRUE if \a uid was removed from the group, FALSE if not.
111 \internal 111 \internal
112 */ 112 */
113bool CategoryGroup::remove( int uid ) 113bool CategoryGroup::remove( int uid )
114{ 114{
115 QMap<int,QString>::Iterator idIt = mIdLabelMap.find( uid ); 115 QMap<int,QString>::Iterator idIt = mIdLabelMap.find( uid );
116 if ( idIt == mIdLabelMap.end() ) 116 if ( idIt == mIdLabelMap.end() )
117 return FALSE; 117 return FALSE;
118 118
119 mLabelIdMap.remove( *idIt ); 119 mLabelIdMap.remove( *idIt );
120 mIdLabelMap.remove( idIt ); 120 mIdLabelMap.remove( idIt );
121 121
122 return TRUE; 122 return TRUE;
123} 123}
124 124
125/*! \internal 125/*! \internal
126 */ 126 */
127bool CategoryGroup::rename( int uid, const QString &newLabel ) 127bool CategoryGroup::rename( int uid, const QString &newLabel )
128{ 128{
129 if ( newLabel == QObject::tr("All") || newLabel == QObject::tr("Unfiled") ) 129 if ( newLabel == QObject::tr("All") || newLabel == QObject::tr("Unfiled") )
130 return FALSE; 130 return FALSE;
131 131
132 QMap<int, QString>::Iterator idIt = mIdLabelMap.find( uid ); 132 QMap<int, QString>::Iterator idIt = mIdLabelMap.find( uid );
133 if ( idIt == mIdLabelMap.end() ) 133 if ( idIt == mIdLabelMap.end() )
134 return FALSE; 134 return FALSE;
135 135
136 mLabelIdMap.remove( *idIt ); 136 mLabelIdMap.remove( *idIt );
137 mLabelIdMap[newLabel] = uid; 137 mLabelIdMap[newLabel] = uid;
138 *idIt = newLabel; 138 *idIt = newLabel;
139 139
140 return TRUE; 140 return TRUE;
141} 141}
142 142
143/*! \internal 143/*! \internal
144 */ 144 */
145bool CategoryGroup::rename( const QString &oldLabel, const QString &newLabel ) 145bool CategoryGroup::rename( const QString &oldLabel, const QString &newLabel )
146{ 146{
147 return rename( id(oldLabel), newLabel ); 147 return rename( id(oldLabel), newLabel );
148} 148}
149 149
150/*! Returns TRUE if \a uid is stored in this group, FALSE if not. */ 150/*! Returns TRUE if \a uid is stored in this group, FALSE if not. */
151bool CategoryGroup::contains(int uid) const 151bool CategoryGroup::contains(int uid) const
152{ 152{
153 return ( mIdLabelMap.find( uid ) != mIdLabelMap.end() ); 153 return ( mIdLabelMap.find( uid ) != mIdLabelMap.end() );
154} 154}
155 155
156/*! Returns TRUE if \a label is stored in this group, FALSE if not. */ 156/*! Returns TRUE if \a label is stored in this group, FALSE if not. */
157bool CategoryGroup::contains(const QString &label) const 157bool CategoryGroup::contains(const QString &label) const
158{ 158{
159 return ( mLabelIdMap.find( label ) != mLabelIdMap.end() ); 159 return ( mLabelIdMap.find( label ) != mLabelIdMap.end() );
160} 160}
161 161
162/*! Returns label associated with the \a uid or QString::null if 162/*! Returns label associated with the \a uid or QString::null if
163 not found 163 not found
164 */ 164 */
165const QString &CategoryGroup::label(int uid) const 165const QString &CategoryGroup::label(int uid) const
166{ 166{
167 QMap<int,QString>::ConstIterator idIt = mIdLabelMap.find( uid ); 167 QMap<int,QString>::ConstIterator idIt = mIdLabelMap.find( uid );
168 if ( idIt == mIdLabelMap.end() ) 168 if ( idIt == mIdLabelMap.end() )
169 return QString::null; 169 return QString::null;
170 return *idIt; 170 return *idIt;
171} 171}
172 172
173/*! Returns the uid associated with \a label or 0 if not found */ 173/*! Returns the uid associated with \a label or 0 if not found */
174int CategoryGroup::id(const QString &label) const 174int CategoryGroup::id(const QString &label) const
175{ 175{
176 QMap<QString,int>::ConstIterator labelIt = mLabelIdMap.find( label ); 176 QMap<QString,int>::ConstIterator labelIt = mLabelIdMap.find( label );
177 if ( labelIt == mLabelIdMap.end() ) 177 if ( labelIt == mLabelIdMap.end() )
178 return 0; 178 return 0;
179 return *labelIt; 179 return *labelIt;
180} 180}
181 181
182/*! Returns a list of all labels stored in this group. */ 182/*! Returns a list of all labels stored in this group. */
183QStringList CategoryGroup::labels() const 183QStringList CategoryGroup::labels() const
184{ 184{
185 QStringList labels; 185 QStringList labels;
186 for ( QMap<int, QString>::ConstIterator it = mIdLabelMap.begin(); 186 for ( QMap<int, QString>::ConstIterator it = mIdLabelMap.begin();
187 it != mIdLabelMap.end(); ++it ) 187 it != mIdLabelMap.end(); ++it )
188 labels += *it; 188 labels += *it;
189 // ### I don't think this is the place for this... 189 // ### I don't think this is the place for this...
190// labels.sort(); 190// labels.sort();
191 return labels; 191 return labels;
192} 192}
193 193
194/*! Returns a list of all labels associated with the \a catids */ 194/*! Returns a list of all labels associated with the \a catids */
195QStringList CategoryGroup::labels(const QArray<int> &catids ) const 195QStringList CategoryGroup::labels(const QArray<int> &catids ) const
196{ 196{
197 QStringList labels; 197 QStringList labels;
198 if ( catids.count() == 0 ) 198 if ( catids.count() == 0 )
199 return labels; 199 return labels;
200 for ( QMap<int, QString>::ConstIterator it = mIdLabelMap.begin(); 200 for ( QMap<int, QString>::ConstIterator it = mIdLabelMap.begin();
201 it != mIdLabelMap.end(); ++it ) 201 it != mIdLabelMap.end(); ++it )
202 if ( catids.find( it.key() ) != -1 ) 202 if ( catids.find( it.key() ) != -1 )
203 labels += *it; 203 labels += *it;
204 return labels; 204 return labels;
205} 205}
206 206
207/*********************************************************** 207/***********************************************************
208 * 208 *
209 * Categories 209 * Categories
210 * 210 *
211 **********************************************************/ 211 **********************************************************/
212 212
213/*! 213/*!
214 \class Categories categories.h 214 \class Categories categories.h
215 \brief The Categories class is a database that groups categories and maps ids to names. 215 \brief The Categories class is a database that groups categories and maps ids to names.
216 216
217 The Categories class is the low level Categories accessor class. To 217 The Categories class is the low level Categories accessor class. To
218 add a category menu and filter for your application, see CategoryMenu. 218 add a category menu and filter for your application, see CategoryMenu.
219 219
220 The Categories class allows the developer to add, remove, and rename 220 The Categories class allows the developer to add, remove, and rename
221 categories. Categories can be created for an individual application 221 categories. Categories can be created for an individual application
222 such as Todo List or to be used for all applications. Categories 222 such as Todo List or to be used for all applications. Categories
223 that can be used by all applications are called global 223 that can be used by all applications are called global
224 categories. Each PalmtopRecord subclass stores categories as an 224 categories. Each PalmtopRecord subclass stores categories as an
225 QArray<int> using PalmtopRecord::setCategories() and 225 QArray<int> using PalmtopRecord::setCategories() and
226 PalmtopRecord::categories(). This allows each record to be assigned 226 PalmtopRecord::categories(). This allows each record to be assigned
227 to multiple categories. This also allows the user to rename a 227 to multiple categories. This also allows the user to rename a
228 category and for it to update automatically in all records. 228 category and for it to update automatically in all records.
229 229
230 This class provides several methods to convert between a category id 230 This class provides several methods to convert between a category id
231 and it's associated string such as id(), ids(), label() and labels(). A 231 and it's associated string such as id(), ids(), label() and labels(). A
232 helper class called CategoryGroup is used to access categories of a 232 helper class called CategoryGroup is used to access categories of a
233 single application group, such as Todo List. Global categories can 233 single application group, such as Todo List. Global categories can
234 also be accessed via CategoryGroup objects. See appGroupMap() and 234 also be accessed via CategoryGroup objects. See appGroupMap() and
235 globalGroup() for the appropriate accessor methods. 235 globalGroup() for the appropriate accessor methods.
236 236
237 Categories are stored in an xml file in the Settings directory 237 Categories are stored in an xml file in the Settings directory
238 (Categories.xml). A global function called categoryFileName() will 238 (Categories.xml). A global function called categoryFileName() will
239 return to appropriate QString file location to be passed to load() 239 return to appropriate QString file location to be passed to load()
240 and save() for the master categories database. 240 and save() for the master categories database.
241 241
242 \ingroup qtopiaemb 242 \ingroup qtopiaemb
243 \ingroup qtopiadesktop 243 \ingroup qtopiadesktop
244 \warning Categories API will likely change between Qtopia 1.5 and Qtopia 3 244 \warning Categories API will likely change between Qtopia 1.5 and Qtopia 3
245 \sa CategoryGroup, CategoryMenu 245 \sa CategoryGroup, CategoryMenu
246*/ 246*/
247 247
248 248
249/*! 249/*!
250 Add the category name as long as it doesn't already exist locally or 250 Add the category name as long as it doesn't already exist locally or
251 globally. The \a uid is assigned to the category if successfully 251 globally. The \a uid is assigned to the category if successfully
252 added. Return \a uid if added, 0 if conflicts (error). 252 added. Return \a uid if added, 0 if conflicts (error).
253 253
254 \internal 254 \internal
255*/ 255*/
256int Categories::addCategory( const QString &appname, 256int Categories::addCategory( const QString &appname,
257 const QString &catname, 257 const QString &catname,
258 int uid ) 258 int uid )
259{ 259{
260 if ( mGlobalCats.contains(catname) ) 260 if ( mGlobalCats.contains(catname) )
261 return 0; 261 return 0;
262 262
263 QMap< QString, CategoryGroup >::Iterator 263 QMap< QString, CategoryGroup >::Iterator
264 appIt = mAppCats.find( appname ); 264 appIt = mAppCats.find( appname );
265 265
266 if ( appIt == mAppCats.end() ) { 266 if ( appIt == mAppCats.end() ) {
267 CategoryGroup newgroup; 267 CategoryGroup newgroup;
268 newgroup.add( uid, catname ); 268 newgroup.add( uid, catname );
269 mAppCats.insert( appname, newgroup ); 269 mAppCats.insert( appname, newgroup );
270 emit categoryAdded( *this, appname, uid ); 270 emit categoryAdded( *this, appname, uid );
271 return uid; 271 return uid;
272 } 272 }
273 273
274 CategoryGroup &cats = *appIt; 274 CategoryGroup &cats = *appIt;
275 cats.add( uid, catname ); 275 cats.add( uid, catname );
276 emit categoryAdded( *this, appname, uid ); 276 emit categoryAdded( *this, appname, uid );
277 return uid; 277 return uid;
278} 278}
279 279
280/*! 280/*!
281 Add the category name as long as it doesn't already exist locally or 281 Add the category name as long as it doesn't already exist locally or
282 globally. Return UID if added, 0 if conflicts (error). 282 globally. Return UID if added, 0 if conflicts (error).
283*/ 283*/
284 284
285int Categories::addCategory( const QString &appname, 285int Categories::addCategory( const QString &appname,
286 const QString &catname ) 286 const QString &catname )
287{ 287{
288 if ( mGlobalCats.contains(catname) ) 288 if ( mGlobalCats.contains(catname) )
289 return 0; 289 return 0;
290 290
291 QMap< QString, CategoryGroup >::Iterator 291 QMap< QString, CategoryGroup >::Iterator
292 appIt = mAppCats.find( appname ); 292 appIt = mAppCats.find( appname );
293 293
294 if ( appIt == mAppCats.end() ) { 294 if ( appIt == mAppCats.end() ) {
295 CategoryGroup newgroup; 295 CategoryGroup newgroup;
296 int uid = newgroup.add( catname ); 296 int uid = newgroup.add( catname );
297 mAppCats.insert( appname, newgroup ); 297 mAppCats.insert( appname, newgroup );
298 emit categoryAdded( *this, appname, uid ); 298 emit categoryAdded( *this, appname, uid );
299 return uid; 299 return uid;
300 } 300 }
301 301
302 CategoryGroup &cats = *appIt; 302 CategoryGroup &cats = *appIt;
303 int uid = cats.add( catname ); 303 int uid = cats.add( catname );
304 if ( !uid ) 304 if ( !uid )
305 return 0; 305 return 0;
306 emit categoryAdded( *this, appname, uid ); 306 emit categoryAdded( *this, appname, uid );
307 return uid; 307 return uid;
308} 308}
309 309
310/*! 310/*!
311 \internal 311 \internal
312*/ 312*/
313int Categories::addGlobalCategory( const QString &catname, int uid ) 313int Categories::addGlobalCategory( const QString &catname, int uid )
314{ 314{
315 mGlobalCats.add( uid, catname ); 315 mGlobalCats.add( uid, catname );
316 emit categoryAdded( *this, QString::null, uid ); 316 emit categoryAdded( *this, QString::null, uid );
317 return uid; 317 return uid;
318} 318}
319 319
320/*! 320/*!
321 Add the global category \a catname while checking that it doesn't 321 Add the global category \a catname while checking that it doesn't
322 already exist globally. Return UID if added, 0 if conflicts. 322 already exist globally. Return UID if added, 0 if conflicts.
323 323
324 \sa addCategory() 324 \sa addCategory()
325 */ 325 */
326int Categories::addGlobalCategory( const QString &catname ) 326int Categories::addGlobalCategory( const QString &catname )
327{ 327{
328 int uid = mGlobalCats.add( catname ); 328 int uid = mGlobalCats.add( catname );
329 if ( !uid ) 329 if ( !uid )
330 return 0; 330 return 0;
331 emit categoryAdded( *this, QString::null, uid ); 331 emit categoryAdded( *this, QString::null, uid );
332 return uid; 332 return uid;
333} 333}
334 334
335/*! 335/*!
336 336
337 Removes the \a catname from the application group. If it is not 337 Removes the \a catname from the application group. If it is not
338 found in the application group and \a checkGlobal is TRUE, then it 338 found in the application group and \a checkGlobal is TRUE, then it
339 attempts to remove it from the global list 339 attempts to remove it from the global list
340*/ 340*/
341bool Categories::removeCategory( const QString &appname, 341bool Categories::removeCategory( const QString &appname,
342 const QString &catname, 342 const QString &catname,
343 bool checkGlobal ) 343 bool checkGlobal )
344{ 344{
345 QMap< QString, CategoryGroup >::Iterator 345 QMap< QString, CategoryGroup >::Iterator
346 appIt = mAppCats.find( appname ); 346 appIt = mAppCats.find( appname );
347 if ( appIt != mAppCats.end() ) { 347 if ( appIt != mAppCats.end() ) {
348 CategoryGroup &cats = *appIt; 348 CategoryGroup &cats = *appIt;
349 int uid = cats.id( catname ); 349 int uid = cats.id( catname );
350 if ( cats.remove( uid ) ) { 350 if ( cats.remove( uid ) ) {
351 emit categoryRemoved( *this, appname, uid ); 351 emit categoryRemoved( *this, appname, uid );
352 return TRUE; 352 return TRUE;
353 } 353 }
354 } 354 }
355 if ( !checkGlobal ) 355 if ( !checkGlobal )
356 return FALSE; 356 return FALSE;
357 return removeGlobalCategory( catname ); 357 return removeGlobalCategory( catname );
358} 358}
359 359
360 360
361/*! 361/*!
362 Removes the \a uid from the application group \a appname. Returns TRUE 362 Removes the \a uid from the application group \a appname. Returns TRUE
363 if success, FALSE if not found. 363 if success, FALSE if not found.
364*/ 364*/
365bool Categories::removeCategory( const QString &appname, int uid ) 365bool Categories::removeCategory( const QString &appname, int uid )
366{ 366{
367 QMap< QString, CategoryGroup >::Iterator 367 QMap< QString, CategoryGroup >::Iterator
368 appIt = mAppCats.find( appname ); 368 appIt = mAppCats.find( appname );
369 if ( appIt != mAppCats.end() ) { 369 if ( appIt != mAppCats.end() ) {
370 CategoryGroup &cats = *appIt; 370 CategoryGroup &cats = *appIt;
371 if ( cats.remove( uid ) ) { 371 if ( cats.remove( uid ) ) {
372 emit categoryRemoved( *this, appname, uid ); 372 emit categoryRemoved( *this, appname, uid );
373 return TRUE; 373 return TRUE;
374 } 374 }
375 } 375 }
376 return FALSE; 376 return FALSE;
377} 377}
378 378
379/*! 379/*!
380 Removes the global category \a catname. Returns TRUE 380 Removes the global category \a catname. Returns TRUE
381 if success, FALSE if not found. 381 if success, FALSE if not found.
382*/ 382*/
383bool Categories::removeGlobalCategory( const QString &catname ) 383bool Categories::removeGlobalCategory( const QString &catname )
384{ 384{
385 int uid = mGlobalCats.id( catname ); 385 int uid = mGlobalCats.id( catname );
386 if ( mGlobalCats.remove( uid ) ) { 386 if ( mGlobalCats.remove( uid ) ) {
387 emit categoryRemoved( *this, QString::null, uid ); 387 emit categoryRemoved( *this, QString::null, uid );
388 return TRUE; 388 return TRUE;
389 } 389 }
390 return FALSE; 390 return FALSE;
391} 391}
392 392
393/*! 393/*!
394 Removes the global category \a uid. Returns TRUE 394 Removes the global category \a uid. Returns TRUE
395 if success, FALSE if not found. 395 if success, FALSE if not found.
396*/ 396*/
397bool Categories::removeGlobalCategory( int uid ) 397bool Categories::removeGlobalCategory( int uid )
398{ 398{
399 if ( mGlobalCats.remove( uid ) ) { 399 if ( mGlobalCats.remove( uid ) ) {
400 emit categoryRemoved( *this, QString::null, uid ); 400 emit categoryRemoved( *this, QString::null, uid );
401 return TRUE; 401 return TRUE;
402 } 402 }
403 return FALSE; 403 return FALSE;
404} 404}
405 405
406/*! 406/*!
407 Returns the sorted list of all categories that are associated with 407 Returns the sorted list of all categories that are associated with
408 the \a app. If \a includeGlobal is TRUE then the returned 408 the \a app. If \a includeGlobal is TRUE then the returned
409 categories will include the global category items. 409 categories will include the global category items.
410 */ 410 */
411QStringList Categories::labels( const QString &app, 411QStringList Categories::labels( const QString &app,
412 bool includeGlobal, 412 bool includeGlobal,
413 ExtraLabels extra ) const 413 ExtraLabels extra ) const
414{ 414{
415 QMap< QString, CategoryGroup >::ConstIterator 415 QMap< QString, CategoryGroup >::ConstIterator
416 appIt = mAppCats.find( app ); 416 appIt = mAppCats.find( app );
417 QStringList cats; 417 QStringList cats;
418 418
419 if ( appIt != mAppCats.end() ) 419 if ( appIt != mAppCats.end() )
420 cats += (*appIt).labels(); 420 cats += (*appIt).labels();
421 //else qDebug("Categories::labels didn't find app %s", app.latin1() ); 421 //else qDebug("Categories::labels didn't find app %s", app.latin1() );
422 if ( includeGlobal ) 422 if ( includeGlobal )
423 cats += mGlobalCats.labels(); 423 cats += mGlobalCats.labels();
424 424
425 cats.sort(); 425 cats.sort();
426 switch ( extra ) { 426 switch ( extra ) {
427 case NoExtra: break; 427 case NoExtra: break;
428 case AllUnfiled: 428 case AllUnfiled:
429 cats.append( tr("All") ); 429 cats.append( tr("All") );
430 cats.append( tr("Unfiled") ); 430 cats.append( tr("Unfiled") );
431 break; 431 break;
432 case AllLabel: 432 case AllLabel:
433 cats.append( tr("All") ); 433 cats.append( tr("All") );
434 break; 434 break;
435 case UnfiledLabel: 435 case UnfiledLabel:
436 cats.append( tr("Unfiled") ); 436 cats.append( tr("Unfiled") );
437 break; 437 break;
438 } 438 }
439 439
440 return cats; 440 return cats;
441} 441}
442 442
443/*! 443/*!
444 Returns the label associated with the id 444 Returns the label associated with the id
445*/ 445*/
446QString Categories::label( const QString &app, int id ) const 446QString Categories::label( const QString &app, int id ) const
447{ 447{
448 if ( mGlobalCats.contains( id ) ) 448 if ( mGlobalCats.contains( id ) )
449 return mGlobalCats.label( id ); 449 return mGlobalCats.label( id );
450 QMap< QString, CategoryGroup >::ConstIterator 450 QMap< QString, CategoryGroup >::ConstIterator
451 appIt = mAppCats.find( app ); 451 appIt = mAppCats.find( app );
452 if ( appIt == mAppCats.end() ) 452 if ( appIt == mAppCats.end() )
453 return QString::null; 453 return QString::null;
454 return (*appIt).label( id ); 454 return (*appIt).label( id );
455} 455}
456 456
457/*! 457/*!
458 Returns a single string associated with \a catids for display in a 458 Returns a single string associated with \a catids for display in a
459 combobox or any area that requires one string. If \a catids are empty 459 combobox or any area that requires one string. If \a catids are empty
460 then "Unfiled" will be returned. If multiple categories are 460 then "Unfiled" will be returned. If multiple categories are
461 assigned then the behavior depends on the DisplaySingle type. 461 assigned then the behavior depends on the DisplaySingle type.
462 462
463 If \a display is set to ShowMulti then " (multi)" appended to the 463 If \a display is set to ShowMulti then " (multi)" appended to the
464 first string. If \a display is set to ShowAll, then a space 464 first string. If \a display is set to ShowAll, then a space
465 seperated string is returned with all categories. If ShowFirst is 465 seperated string is returned with all categories. If ShowFirst is
466 set, the just the first string is returned. 466 set, the just the first string is returned.
467*/ 467*/
468QString Categories::displaySingle( const QString &app, 468QString Categories::displaySingle( const QString &app,
469 const QArray<int> &catids, 469 const QArray<int> &catids,
470 DisplaySingle display ) const 470 DisplaySingle display ) const
471{ 471{
472 QStringList strs = labels( app, catids ); 472 QStringList strs = labels( app, catids );
473 if ( !strs.count() ) 473 if ( !strs.count() )
474 return tr("Unfiled"); 474 return tr("Unfiled");
475 strs.sort(); 475 strs.sort();
476 QString r; 476 QString r;
477 if ( strs.count() > 1 ) { 477 if ( strs.count() > 1 ) {
478 switch ( display ) { 478 switch ( display ) {
479 case ShowFirst: 479 case ShowFirst:
480 r = strs.first(); 480 r = strs.first();
481 break; 481 break;
482 case ShowMulti: 482 case ShowMulti:
483 r = strs.first() + tr(" (multi.)"); 483 r = strs.first() + tr(" (multi.)");
484 break; 484 break;
485 case ShowAll: 485 case ShowAll:
486 r = strs.join(" "); 486 r = strs.join(" ");
487 break; 487 break;
488 } 488 }
489 } 489 }
490 else r = strs.first(); 490 else r = strs.first();
491 return r; 491 return r;
492} 492}
493 493
494/*! 494/*!
495 495
496 Returns all ids associated with the application CategoryGroup \a app 496 Returns all ids associated with the application CategoryGroup \a app
497 and the passed in \a labels in that group. 497 and the passed in \a labels in that group.
498*/ 498*/
499QArray<int> Categories::ids( const QString &app, const QStringList &labels) const 499QArray<int> Categories::ids( const QString &app, const QStringList &labels) const
500{ 500{
501 QArray<int> results; 501 QArray<int> results;
502 QStringList::ConstIterator it; 502 QStringList::ConstIterator it;
503 int i; 503 int i;
504 504
505 for ( i=0, it=labels.begin(); it!=labels.end(); i++, ++it ) { 505 for ( i=0, it=labels.begin(); it!=labels.end(); i++, ++it ) {
506 int value = id( app, *it ); 506 int value = id( app, *it );
507 if ( value != 0 ) { 507 if ( value != 0 ) {
508 int tmp = results.size(); 508 int tmp = results.size();
509 results.resize( tmp + 1 ); 509 results.resize( tmp + 1 );
510 results[ tmp ] = value; 510 results[ tmp ] = value;
511 } 511 }
512 } 512 }
513 return results; 513 return results;
514} 514}
515 515
516/*! 516/*!
517 Returns the id associated with the app. If the id is not found in the 517 Returns the id associated with the app. If the id is not found in the
518 application CategoryGroup, then it searches the global CategoryGroup. 518 application CategoryGroup, then it searches the global CategoryGroup.
519 If it is not found it either, 0 is returned. 519 If it is not found it either, 0 is returned.
520*/ 520*/
521int Categories::id( const QString &app, const QString &cat ) const 521int Categories::id( const QString &app, const QString &cat ) const
522{ 522{
523 if ( cat == tr("Unfiled") || cat.contains( tr(" (multi.)") ) ) 523 if ( cat == tr("Unfiled") || cat.contains( tr(" (multi.)") ) )
524 return 0; 524 return 0;
525 int uid = mGlobalCats.id( cat ); 525 int uid = mGlobalCats.id( cat );
526 if ( uid != 0 ) 526 if ( uid != 0 )
527 return uid; 527 return uid;
528 return mAppCats[app].id( cat ); 528 return mAppCats[app].id( cat );
529} 529}
530 530
531 531
532/*! 532/*!
533 Return TRUE if renaming succeeded; FALSE if \a appname or \a oldName 533 Return TRUE if renaming succeeded; FALSE if \a appname or \a oldName
534 is not found, or if \a newName conflicts with an existing category 534 is not found, or if \a newName conflicts with an existing category
535 in the CategoryGroup. 535 in the CategoryGroup.
536 536
537 It will first search the CategoryGroup associated with \a appname 537 It will first search the CategoryGroup associated with \a appname
538 and if not found it will try to replace in global CategoryGroup. 538 and if not found it will try to replace in global CategoryGroup.
539 */ 539 */
540bool Categories::renameCategory( const QString &appname, 540bool Categories::renameCategory( const QString &appname,
541 const QString &oldName, 541 const QString &oldName,
542 const QString &newName ) 542 const QString &newName )
543{ 543{
544 QMap< QString, CategoryGroup >::Iterator 544 QMap< QString, CategoryGroup >::Iterator
545 appIt = mAppCats.find( appname ); 545 appIt = mAppCats.find( appname );
546 546
547 if ( appIt != mAppCats.end() ) { 547 if ( appIt != mAppCats.end() ) {
548 CategoryGroup &cats = *appIt; 548 CategoryGroup &cats = *appIt;
549 int id = cats.id( oldName ); 549 int id = cats.id( oldName );
550 if ( id != 0 && cats.rename( id, newName ) ) { 550 if ( id != 0 && cats.rename( id, newName ) ) {
551 emit categoryRenamed( *this, appname, id ); 551 emit categoryRenamed( *this, appname, id );
552 return TRUE; 552 return TRUE;
553 } 553 }
554 } 554 }
555 return renameGlobalCategory( oldName, newName ); 555 return renameGlobalCategory( oldName, newName );
556} 556}
557 557
558/*! 558/*!
559 Return TRUE if renaming succeeded; FALSE if \a appname or \a oldName 559 Return TRUE if renaming succeeded; FALSE if \a appname or \a oldName
560 is not found, or if \a newName conflicts with an existing category 560 is not found, or if \a newName conflicts with an existing category
561 in the CategoryGroup. This function will only rename categories found 561 in the CategoryGroup. This function will only rename categories found
562 in the global CategoryGroup. 562 in the global CategoryGroup.
563 */ 563 */
564bool Categories::renameGlobalCategory( const QString &oldName, 564bool Categories::renameGlobalCategory( const QString &oldName,
565 const QString &newName ) 565 const QString &newName )
566{ 566{
567 int uid = mGlobalCats.id( oldName ); 567 int uid = mGlobalCats.id( oldName );
568 if ( uid != 0 && mGlobalCats.rename( uid, newName ) ) { 568 if ( uid != 0 && mGlobalCats.rename( uid, newName ) ) {
569 emit categoryRenamed( *this, QString::null, uid ); 569 emit categoryRenamed( *this, QString::null, uid );
570 return TRUE; 570 return TRUE;
571 } 571 }
572 return FALSE; 572 return FALSE;
573} 573}
574 574
575/*! 575/*!
576 Changes the grouping of a category. If a category was global and \a global 576 Changes the grouping of a category. If a category was global and \a global
577 is set to TRUE, then the \a catname will be moved to the \a appname group. 577 is set to TRUE, then the \a catname will be moved to the \a appname group.
578*/ 578*/
579void Categories::setGlobal( const QString &appname, 579void Categories::setGlobal( const QString &appname,
580 const QString &catname, 580 const QString &catname,
581 bool global ) 581 bool global )
582{ 582{
583 // if in global and should be in app; then move it 583 // if in global and should be in app; then move it
584 if ( mGlobalCats.contains( catname ) && !global ) { 584 if ( mGlobalCats.contains( catname ) && !global ) {
585 mGlobalCats.remove( catname ); 585 mGlobalCats.remove( catname );
586 addCategory( appname, catname ); 586 addCategory( appname, catname );
587 return ; 587 return ;
588 } 588 }
589 589
590 // if in app and should be in global, then move it 590 // if in app and should be in global, then move it
591 if ( !global ) 591 if ( !global )
592 return; 592 return;
593 if ( removeCategory( appname, catname, FALSE ) ) 593 if ( removeCategory( appname, catname, FALSE ) )
594 addGlobalCategory( catname ); 594 addGlobalCategory( catname );
595} 595}
596 596
597/*! 597/*!
598 Returns TRUE if the \a catname is in the global CategoryGroup, FALSE if not. 598 Returns TRUE if the \a catname is in the global CategoryGroup, FALSE if not.
599*/ 599*/
600bool Categories::isGlobal( const QString &catname ) const 600bool Categories::isGlobal( const QString &catname ) const
601{ 601{
602 return mGlobalCats.contains( catname ); 602 return mGlobalCats.contains( catname );
603} 603}
604 604
605 605
606/*! 606/*!
607 Returns true if the \a catname is associated with any CategoryGroup, 607 Returns true if the \a catname is associated with any CategoryGroup,
608 including global. 608 including global.
609 */ 609 */
610bool Categories::exists( const QString &catname ) const 610bool Categories::exists( const QString &catname ) const
611{ 611{
612 if ( isGlobal(catname) ) 612 if ( isGlobal(catname) )
613 return TRUE; 613 return TRUE;
614 614
615 for ( QMap<QString, CategoryGroup>::ConstIterator appsIt = mAppCats.begin(); appsIt != mAppCats.end(); ++appsIt ) 615 for ( QMap<QString, CategoryGroup>::ConstIterator appsIt = mAppCats.begin(); appsIt != mAppCats.end(); ++appsIt )
616 if ( exists( appsIt.key(), catname ) ) 616 if ( exists( appsIt.key(), catname ) )
617 return TRUE; 617 return TRUE;
618 618
619 return FALSE; 619 return FALSE;
620} 620}
621 621
622/*! 622/*!
623 Returns TRUE if the \a catname is associated with the \a appname 623 Returns TRUE if the \a catname is associated with the \a appname
624 CategoryGroup, FALSE if not found. 624 CategoryGroup, FALSE if not found.
625 */ 625 */
626bool Categories::exists( const QString &appname, 626bool Categories::exists( const QString &appname,
627 const QString &catname) const 627 const QString &catname) const
628{ 628{
629 QMap< QString, CategoryGroup >::ConstIterator 629 QMap< QString, CategoryGroup >::ConstIterator
630 appIt = mAppCats.find( appname ); 630 appIt = mAppCats.find( appname );
631 631
632 if ( appIt == mAppCats.end() ) 632 if ( appIt == mAppCats.end() )
633 return FALSE; 633 return FALSE;
634 634
635 return (*appIt).contains( catname ); 635 return (*appIt).contains( catname );
636} 636}
637 637
638/*! 638/*!
639 Saves the Categories database to the \a fname. See categoryFileName() 639 Saves the Categories database to the \a fname. See categoryFileName()
640 for the default file name string used for the shared category database. 640 for the default file name string used for the shared category database.
641 641
642 Returns FALSE if there is error writing the file or TRUE on success. 642 Returns FALSE if there is error writing the file or TRUE on success.
643 */ 643 */
644bool Categories::save( const QString &fname ) const 644bool Categories::save( const QString &fname ) const
645{ 645{
646 QString strNewFile = fname + ".new"; 646 QString strNewFile = fname + ".new";
647 QFile f( strNewFile ); 647 QFile f( strNewFile );
648 QString out; 648 QString out;
649 int total_written; 649 int total_written;
650 650
651 if ( !f.open( IO_WriteOnly|IO_Raw ) ) { 651 if ( !f.open( IO_WriteOnly|IO_Raw ) ) {
652 qWarning("Unable to write to %s", fname.latin1()); 652 qWarning("Unable to write to %s", fname.latin1());
653 return FALSE; 653 return FALSE;
654 } 654 }
655 655
656 out = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"; 656 out = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
657 out += "<!DOCTYPE CategoryList>\n"; 657 out += "<!DOCTYPE CategoryList>\n";
658 658
659 out += "<Categories>\n"; 659 out += "<Categories>\n";
660 660
661 for ( QMap<int, QString>::ConstIterator git = mGlobalCats.idMap().begin(); 661 for ( QMap<int, QString>::ConstIterator git = mGlobalCats.idMap().begin();
662 git != mGlobalCats.idMap().end(); ++git ) 662 git != mGlobalCats.idMap().end(); ++git )
663 out += "<Category id=\"" + QString::number(git.key()) + "\"" + 663 out += "<Category id=\"" + QString::number(git.key()) + "\"" +
664 " name=\"" + escapeString(*git) + "\" />\n"; 664 " name=\"" + escapeString(*git) + "\" />\n";
665 665
666 for ( QMap<QString, CategoryGroup>::ConstIterator appsIt=mAppCats.begin(); 666 for ( QMap<QString, CategoryGroup>::ConstIterator appsIt=mAppCats.begin();
667 appsIt != mAppCats.end(); ++appsIt ) { 667 appsIt != mAppCats.end(); ++appsIt ) {
668 const QString &app = appsIt.key(); 668 const QString &app = appsIt.key();
669 const QMap<int, QString> &appcats = (*appsIt).idMap(); 669 const QMap<int, QString> &appcats = (*appsIt).idMap();
670 for ( QMap<int, QString>::ConstIterator appcatit = appcats.begin(); 670 for ( QMap<int, QString>::ConstIterator appcatit = appcats.begin();
671 appcatit != appcats.end(); ++appcatit ) 671 appcatit != appcats.end(); ++appcatit )
672 out += "<Category id=\"" + QString::number(appcatit.key()) + "\"" + 672 out += "<Category id=\"" + QString::number(appcatit.key()) + "\"" +
673 " app=\"" + escapeString(app) + "\"" + 673 " app=\"" + escapeString(app) + "\"" +
674 " name=\"" + escapeString(*appcatit) + "\" />\n"; 674 " name=\"" + escapeString(*appcatit) + "\" />\n";
675 } 675 }
676 out += "</Categories>\n"; 676 out += "</Categories>\n";
677 677
678 QCString cstr = out.utf8(); 678 QCString cstr = out.utf8();
679 total_written = f.writeBlock( cstr.data(), cstr.length() ); 679 total_written = f.writeBlock( cstr.data(), cstr.length() );
680 if ( total_written != int(cstr.length()) ) { 680 if ( total_written != int(cstr.length()) ) {
681 f.close(); 681 f.close();
682 QFile::remove( strNewFile ); 682 QFile::remove( strNewFile );
683 return FALSE; 683 return FALSE;
684 } 684 }
685 f.close(); 685 f.close();
686 686
687#ifdef Q_OS_WIN32 687#ifdef Q_OS_WIN32
688 QFile::remove( fname ); 688 QFile::remove( fname );
689#endif 689#endif
690 if ( ::rename( strNewFile.latin1(), fname.latin1() ) < 0 ) { 690 if ( ::rename( strNewFile.latin1(), fname.latin1() ) < 0 ) {
691 qWarning( "problem renaming file %s to %s", 691 qWarning( "problem renaming file %s to %s",
692 strNewFile.latin1(), fname.latin1()); 692 strNewFile.latin1(), fname.latin1());
693 // remove the tmp file... 693 // remove the tmp file...
694 QFile::remove( strNewFile ); 694 QFile::remove( strNewFile );
695 } 695 }
696 696
697 return TRUE; 697 return TRUE;
698} 698}
699 699
700/*! 700/*!
701 Loads the Categories database using \a fname. See categoryFileName() 701 Loads the Categories database using \a fname. See categoryFileName()
702 for the default file name string used for the shared category database. 702 for the default file name string used for the shared category database.
703 703
704 Returns FALSE if there is error reading the file or TRUE on success. 704 Returns FALSE if there is error reading the file or TRUE on success.
705 */ 705 */
706bool Categories::load( const QString &fname ) 706bool Categories::load( const QString &fname )
707{ 707{
708 QFile file( fname ); 708 QFile file( fname );
709 if ( !file.open( IO_ReadOnly ) ) { 709 if ( !file.open( IO_ReadOnly ) ) {
710 qWarning("Unable to open %s", fname.latin1()); 710 qWarning("Unable to open %s", fname.latin1());
711 711
712 addGlobalCategory(tr("Business")); 712 addGlobalCategory(tr("Business"));
713 addGlobalCategory(tr("Personal")); 713 addGlobalCategory(tr("Personal"));
714 save(fname); 714 save(fname);
715 715
716 return FALSE; 716 return FALSE;
717 } 717 }
718 718
719 clear(); 719 clear();
720 QByteArray ba = file.readAll(); 720 QByteArray ba = file.readAll();
721 QString data = QString::fromUtf8( ba.data(), ba.size() ); 721 QString data = QString::fromUtf8( ba.data(), ba.size() );
722 QChar *uc = (QChar *)data.unicode(); 722 QChar *uc = (QChar *)data.unicode();
723 int len = data.length(); 723 int len = data.length();
724 724
725 // QTime t; 725 // QTime t;
726 // t.start(); 726 // t.start();
727 QString name; 727 QString name;
728 QString id; 728 QString id;
729 QString app; 729 QString app;
730 int i = 0; 730 int i = 0;
731 while ( (i = data.find( "<Category ", i)) != -1 ) { 731 while ( (i = data.find( "<Category ", i)) != -1 ) {
732 732
733 i += 10; 733 i += 10;
734 name = QString::null; 734 name = QString::null;
735 app = QString::null; 735 app = QString::null;
736 while ( 1 ) { 736 while ( 1 ) {
737 // skip white space 737 // skip white space
738 while ( i < len && 738 while ( i < len &&
739 (uc[i] == ' ' || uc[i] == '\n' || uc[i] == '\r') ) 739 (uc[i] == ' ' || uc[i] == '\n' || uc[i] == '\r') )
740 i++; 740 i++;
741 // if at the end, then done 741 // if at the end, then done
742 if ( i >= len-2 || (uc[i] == '/' && uc[i+1] == '>') ) 742 if ( i >= len-2 || (uc[i] == '/' && uc[i+1] == '>') )
743 break; 743 break;
744 // we have another attribute read it. 744 // we have another attribute read it.
745 int j = i; 745 int j = i;
746 while ( j < len && uc[j] != '=' ) 746 while ( j < len && uc[j] != '=' )
747 j++; 747 j++;
748 QString attr = QConstString( uc+i, j-i ).string(); 748 QString attr = QConstString( uc+i, j-i ).string();
749 i = ++j; // skip = 749 i = ++j; // skip =
750 while ( i < len && uc[i] != '"' ) 750 while ( i < len && uc[i] != '"' )
751 i++; 751 i++;
752 j = ++i; 752 j = ++i;
753 while ( j < len && uc[j] != '"' ) 753 while ( j < len && uc[j] != '"' )
754 j++; 754 j++;
755 QString value = Qtopia::plainString( QConstString( uc+i, j-i ).string() ); 755 QString value = Qtopia::plainString( QConstString( uc+i, j-i ).string() );
756 i = j + 1; 756 i = j + 1;
757 757
758 // qDebug("attr='%s' value='%s'", attr.latin1(), value.latin1() ); 758 // qDebug("attr='%s' value='%s'", attr.latin1(), value.latin1() );
759 if ( attr == "id" ) 759 if ( attr == "id" )
760 id = value; 760 id = value;
761 else if ( attr == "app" ) 761 else if ( attr == "app" )
762 app = value; 762 app = value;
763 763
764 else if ( attr == "name" ) 764 else if ( attr == "name" )
765 name = value; 765 name = value;
766 } 766 }
767 767
768 if ( name.isNull() || id.isNull() ) { 768 if ( name.isNull() || id.isNull() ) {
769 qWarning("No name or id in the category"); 769 qWarning("No name or id in the category");
770 continue; 770 continue;
771 } 771 }
772 if ( app.isNull() ) 772 if ( app.isNull() )
773 mGlobalCats.add( id.toInt(), name ); 773 mGlobalCats.add( id.toInt(), name );
774 else 774 else
775 mAppCats[ app ].add( id.toInt(), name ); 775 mAppCats[ app ].add( id.toInt(), name );
776 } 776 }
777 777
778 return TRUE; 778 return TRUE;
779} 779}
780 780
781/*! 781/*!
782 Clear the categories in memory. Equivelent to creating an empty Categories 782 Clear the categories in memory. Equivelent to creating an empty Categories
783 object. 783 object.
784*/ 784*/
785void Categories::clear() 785void Categories::clear()
786{ 786{
787 mGlobalCats.clear(); 787 mGlobalCats.clear();
788 mAppCats.clear(); 788 mAppCats.clear();
789} 789}
790 790
791/*! 791/*!
792 Dump the contents to standard out. Used for debugging only. 792 Dump the contents to standard out. Used for debugging only.
793*/ 793*/
794void Categories::dump() const 794void Categories::dump() const
795{ 795{
796 qDebug("\tglobal categories = %s", mGlobalCats.labels().join(", ").latin1() ); 796 qDebug("\tglobal categories = %s", mGlobalCats.labels().join(", ").latin1() );
797 for ( QMap<QString, CategoryGroup>::ConstIterator appsIt = mAppCats.begin(); appsIt != mAppCats.end(); ++appsIt ) { 797 for ( QMap<QString, CategoryGroup>::ConstIterator appsIt = mAppCats.begin(); appsIt != mAppCats.end(); ++appsIt ) {
798 const QString &app = appsIt.key(); 798 const QString &app = appsIt.key();
799 QStringList appcats = (*appsIt).labels(); 799 QStringList appcats = (*appsIt).labels();
800 qDebug("\tapp = %s\tcategories = %s", app.latin1(), 800 qDebug("\tapp = %s\tcategories = %s", app.latin1(),
801 appcats.join(", ").latin1() ); 801 appcats.join(", ").latin1() );
802 802
803 } 803 }
804} 804}
805 805
806QStringList CheckedListView::checked() const 806QStringList CheckedListView::checked() const
807{ 807{
808 QStringList strs; 808 QStringList strs;
809 for ( QCheckListItem *i = (QCheckListItem *) firstChild(); 809 for ( QCheckListItem *i = (QCheckListItem *) firstChild();
810 i; i = (QCheckListItem *)i->nextSibling() ) 810 i; i = (QCheckListItem *)i->nextSibling() )
811 if ( i->isOn() ) 811 if ( i->isOn() )
812 strs += i->text( 0 ); 812 strs += i->text( 0 );
813 return strs; 813 return strs;
814} 814}
815 815
816void CheckedListView::addCheckableList( const QStringList &options ) 816void CheckedListView::addCheckableList( const QStringList &options )
817{ 817{
818 for ( QStringList::ConstIterator it = options.begin(); 818 for ( QStringList::ConstIterator it = options.begin();
819 it != options.end(); ++it ) { 819 it != options.end(); ++it ) {
820 (void) new QCheckListItem( this, *it, 820 (void) new QCheckListItem( this, *it,
821 QCheckListItem::CheckBox ); 821 QCheckListItem::CheckBox );
822 } 822 }
823} 823}
824 824
825void CheckedListView::setChecked( const QStringList &checked ) 825void CheckedListView::setChecked( const QStringList &checked )
826{ 826{
827 // iterate over all items 827 // iterate over all items
828 bool showingChecked = FALSE; 828 bool showingChecked = FALSE;
829 for ( QCheckListItem *i = (QCheckListItem *) firstChild(); 829 for ( QCheckListItem *i = (QCheckListItem *) firstChild();
830 i; i = (QCheckListItem *)i->nextSibling() ) 830 i; i = (QCheckListItem *)i->nextSibling() )
831 // see if the item should be checked by searching the 831 // see if the item should be checked by searching the
832 // checked list 832 // checked list
833 if ( checked.find( i->text( 0 ) ) != checked.end() ) { 833 if ( checked.find( i->text( 0 ) ) != checked.end() ) {
834 i->setOn( TRUE ); 834 i->setOn( TRUE );
835 // make sure it is showing at least one checked item 835 // make sure it is showing at least one checked item
836 if ( !showingChecked ) { 836 if ( !showingChecked ) {
837 ensureItemVisible( i ); 837 ensureItemVisible( i );
838 showingChecked = TRUE; 838 showingChecked = TRUE;
839 } 839 }
840 } 840 }
841 else 841 else
842 i->setOn( FALSE ); 842 i->setOn( FALSE );
843} 843}
844 844
845/*! \fn Categories &Categories::operator= ( const Categories &c ) 845/*! \fn Categories &Categories::operator= ( const Categories &c )
846 846
847 Performs deep copy. 847 Performs deep copy.
848 */ 848 */
849 849
850 850
851/*! \fn QStringList Categories::labels( const QString & app, const QArray<int> &catids ) const
852
853 Returns list of labels associated with the application and catids
854*/
855
856/*! \fn QStringList Categories::globalCategories() const 851/*! \fn QStringList Categories::globalCategories() const
857 852
858 Returns list of all global category labels 853 Returns list of all global category labels
859*/ 854*/
860 855
861/*! \fn const QMap<QString, CategoryGroup> &Categories::appGroupMap() const 856/*! \fn const QMap<QString, CategoryGroup> &Categories::appGroupMap() const
862 857
863 Returns a map of application names to CategoryGroup. The CategoryGroup 858 Returns a map of application names to CategoryGroup. The CategoryGroup
864 class defines a map of ids to category labels and category labels to ids. 859 class defines a map of ids to category labels and category labels to ids.
865*/ 860*/
866 861
867/*! \fn const CategoryGroup &Categories::globalGroup() const 862/*! \fn const CategoryGroup &Categories::globalGroup() const
868 863
869 Returns the global CategoryGroup. The CategoryGroup 864 Returns the global CategoryGroup. The CategoryGroup
870 class defines a map of ids to category labels and category labels to ids. 865 class defines a map of ids to category labels and category labels to ids.
871*/ 866*/
872 867
873/*! \fn void Categories::categoryAdded( const Categories &cats, const QString &appname, int uid) 868/*! \fn void Categories::categoryAdded( const Categories &cats, const QString &appname, int uid)
874 869
875 Emitted if a category is added. 870 Emitted if a category is added.
876 871
877 \a cats is a const reference to this object 872 \a cats is a const reference to this object
878 \a appname is the CategoryGroup application name that the category was added to or QString::null if it was global 873 \a appname is the CategoryGroup application name that the category was added to or QString::null if it was global
879 \a uid is the unique identifier associated with the added category 874 \a uid is the unique identifier associated with the added category
880 */ 875*/
881 876
882/*! \fn void Categories::categoryRemoved( const Categories &cats, const QString &appname, 877/*! \fn void Categories::categoryRemoved( const Categories &cats, const QString &appname,
883 int uid) 878 int uid)
884 879
885 Emitted if removed category is removed. 880 Emitted if removed category is removed.
886 881
887 \a cats is a const reference to this object 882 \a cats is a const reference to this object
888 \a appname is the CategoryGroup application name that the category was removed from or QString::null if it was the global CategoryGroup 883 \a appname is the CategoryGroup application name that the category was removed from or QString::null if it was the global CategoryGroup
889 \a uid is the unique identifier associated with the removed category 884 \a uid is the unique identifier associated with the removed category
890*/ 885*/
891 886
892 887
893/*! \fn void Categories::categoryRenamed( const Categories &cats, const QString &appname, 888/*! \fn void Categories::categoryRenamed( const Categories &cats, const QString &appname,
894 int uid) 889 int uid)
895 890
896 Emitted if \a uid in the \a appname CategoryGroup is renamed in \a cats 891 Emitted if \a uid in the \a appname CategoryGroup is renamed in \a cats
897 object. 892 object.
898 893
899 \a cats is a const reference to this object 894 \a cats is a const reference to this object
900 \a appname is the CategoryGroup application name that the category was renamed in or QString::null if it was the global CategoryGroup 895 \a appname is the CategoryGroup application name that the category was renamed in or QString::null if it was the global CategoryGroup
901 \a uid is the unique identifier associated with the renamed category 896 \a uid is the unique identifier associated with the renamed category
902*/ 897*/
903 898
904/*! \fn Categories::Categories( QObject *parent=0, const char *name = 0 ) 899/*! \fn Categories::Categories( QObject *parent=0, const char *name = 0 )
905 900
906 Constructor for an empty Categories object. 901 Constructor for an empty Categories object.
907*/ 902*/
908 903
909/*! \fn Categories::Categories( const Categories &copyFrom ) 904/*! \fn Categories::Categories( const Categories &copyFrom )
910 905
911 Deep copy constructor 906 Deep copy constructor
912*/ 907*/
913 908
914/*! \fn Categories::~Categories() 909/*! \fn Categories::~Categories()
915 910
916 Empty destructor. Call save() before destruction if there are changes 911 Empty destructor. Call save() before destruction if there are changes
917 that need to be saved. 912 that need to be saved.
918*/ 913*/
919 914
920/*! \fn CategoryGroup::clear() 915/*! \fn CategoryGroup::clear()
921 \internal 916 \internal
922*/ 917*/
923 918
924/*! \fn const QMap<int, QString> &CategoryGroup::idMap() const 919/*! \fn const QMap<int, QString> &CategoryGroup::idMap() const
925 920
926 Returns a const reference to the id to label QMap 921 Returns a const reference to the id to label QMap
927*/ 922*/
928 923
929/*! \fn CategoryGroup::CategoryGroup() 924/*! \fn CategoryGroup::CategoryGroup()
930 \internal 925 \internal
931*/ 926*/
932 927
933/*! \fn CategoryGroup::CategoryGroup(const CategoryGroup &c) 928/*! \fn CategoryGroup::CategoryGroup(const CategoryGroup &c)
934 \internal 929 \internal
935*/ 930*/
936 931
diff --git a/library/backend/categories.h b/library/backend/categories.h
index ba65ee3..d5b3669 100644
--- a/library/backend/categories.h
+++ b/library/backend/categories.h
@@ -1,226 +1,226 @@
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 7** GNU General Public License version 2 as published by the Free
8** Software Foundation and appearing in the file LICENSE.GPL included 8** Software Foundation and appearing in the file LICENSE.GPL included
9** in the packaging of this file. 9** in the packaging of this file.
10** 10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING 11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING
12** THE WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A 12** THE WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A
13** PARTICULAR PURPOSE. 13** PARTICULAR PURPOSE.
14** 14**
15** See http://www.trolltech.com/gpl/ for GPL licensing information. 15** See http://www.trolltech.com/gpl/ for GPL licensing information.
16** 16**
17** Contact info@trolltech.com if any conditions of this licensing are 17** Contact info@trolltech.com if any conditions of this licensing are
18** not clear to you. 18** not clear to you.
19** 19**
20**********************************************************************/ 20**********************************************************************/
21 21
22#ifndef QTPALMTOP_CATEGORIES_H 22#ifndef QTPALMTOP_CATEGORIES_H
23#define QTPALMTOP_CATEGORIES_H 23#define QTPALMTOP_CATEGORIES_H
24 24
25#include <qstring.h> 25#include <qstring.h>
26#include <qstringlist.h> 26#include <qstringlist.h>
27#include <qmap.h> 27#include <qmap.h>
28#include <qlistview.h> 28#include <qlistview.h>
29#include <qarray.h> 29#include <qarray.h>
30#include "qpcglobal.h" 30#include "qpcglobal.h"
31#include "palmtopuidgen.h" 31#include "palmtopuidgen.h"
32 32
33class CategoryGroup; 33class CategoryGroup;
34 34
35#if defined(QPC_TEMPLATEDLL) 35#if defined(QPC_TEMPLATEDLL)
36// MOC_SKIP_BEGIN 36// MOC_SKIP_BEGIN
37template class QPC_EXPORT QMap<int, QString>; 37template class QPC_EXPORT QMap<int, QString>;
38template class QPC_EXPORT QMap<QString, int>; 38template class QPC_EXPORT QMap<QString, int>;
39template class QPC_EXPORT QMap< QString, CategoryGroup >; 39template class QPC_EXPORT QMap< QString, CategoryGroup >;
40// MOC_SKIP_END 40// MOC_SKIP_END
41#endif 41#endif
42 42
43class QPC_EXPORT CategoryGroup 43class QPC_EXPORT CategoryGroup
44{ 44{
45 friend class Categories; 45 friend class Categories;
46public: 46public:
47 CategoryGroup(): mIdLabelMap(), mLabelIdMap() { } 47 CategoryGroup(): mIdLabelMap(), mLabelIdMap() { }
48 CategoryGroup( const CategoryGroup &c ) : 48 CategoryGroup( const CategoryGroup &c ) :
49 mIdLabelMap( c.mIdLabelMap), mLabelIdMap( c.mLabelIdMap ) { } 49 mIdLabelMap( c.mIdLabelMap), mLabelIdMap( c.mLabelIdMap ) { }
50 50
51 void clear() { mIdLabelMap.clear(); mLabelIdMap.clear(); } 51 void clear() { mIdLabelMap.clear(); mLabelIdMap.clear(); }
52 52
53 int add( const QString &label ); 53 int add( const QString &label );
54 bool add( int uid, const QString &label ); 54 bool add( int uid, const QString &label );
55 55
56 bool remove( const QString &label ); 56 bool remove( const QString &label );
57 bool remove( int uid ); 57 bool remove( int uid );
58 58
59 bool rename( int uid, const QString &newLabel ); 59 bool rename( int uid, const QString &newLabel );
60 bool rename( const QString &oldLabel, const QString &newLabel ); 60 bool rename( const QString &oldLabel, const QString &newLabel );
61 61
62 bool contains(int id) const; 62 bool contains(int id) const;
63 bool contains(const QString &label) const; 63 bool contains(const QString &label) const;
64 64
65 /** Returns label associated with the uid or QString::null if 65 /** Returns label associated with the uid or QString::null if
66 * not found 66 * not found
67 */ 67 */
68 const QString &label(int id) const; 68 const QString &label(int id) const;
69 /** Returns the uid associated with label or 0 if not found */ 69 /** Returns the uid associated with label or 0 if not found */
70 int id(const QString &label) const; 70 int id(const QString &label) const;
71 71
72 /** Returns a sorted list of labels */ 72 /** Returns a sorted list of labels */
73 QStringList labels() const; 73 QStringList labels() const;
74 74
75 QStringList labels( const QArray<int> &catids ) const; 75 QStringList labels( const QArray<int> &catids ) const;
76 76
77 const QMap<int, QString> &idMap() const { return mIdLabelMap; } 77 const QMap<int, QString> &idMap() const { return mIdLabelMap; }
78 78
79private: 79private:
80 void insert( int uid, const QString &label ); 80 void insert( int uid, const QString &label );
81 QMap<int, QString> mIdLabelMap; 81 QMap<int, QString> mIdLabelMap;
82 QMap<QString, int> mLabelIdMap; 82 QMap<QString, int> mLabelIdMap;
83 83
84 static Qtopia::UidGen &uidGen() { return sUidGen; } 84 static Qtopia::UidGen &uidGen() { return sUidGen; }
85 static Qtopia::UidGen sUidGen; 85 static Qtopia::UidGen sUidGen;
86}; 86};
87 87
88/** Map from application name to categories */ 88/* Map from application name to categories */
89class QPC_EXPORT Categories : public QObject 89class QPC_EXPORT Categories : public QObject
90{ 90{
91 Q_OBJECT 91 Q_OBJECT
92public: 92public:
93 Categories( QObject *parent=0, const char *name = 0 ) 93 Categories( QObject *parent=0, const char *name = 0 )
94 : QObject( parent, name ), mGlobalCats(), mAppCats() { } 94 : QObject( parent, name ), mGlobalCats(), mAppCats() { }
95 Categories( const Categories &copyFrom ) : QObject( copyFrom.parent() ), 95 Categories( const Categories &copyFrom ) : QObject( copyFrom.parent() ),
96 mGlobalCats( copyFrom.mGlobalCats ), 96 mGlobalCats( copyFrom.mGlobalCats ),
97 mAppCats( copyFrom.mAppCats ) { } 97 mAppCats( copyFrom.mAppCats ) { }
98 virtual ~Categories() { } 98 virtual ~Categories() { }
99 99
100 Categories &operator= ( const Categories &c ) 100 Categories &operator= ( const Categories &c )
101{ mAppCats = c.mAppCats; mGlobalCats = c.mGlobalCats; return *this; } 101{ mAppCats = c.mAppCats; mGlobalCats = c.mGlobalCats; return *this; }
102 102
103 void clear(); 103 void clear();
104 104
105 /** Add the category name as long as it doesn't already exist 105 /** Add the category name as long as it doesn't already exist
106 * locally or globally. Return UID if added, 0 if conflicts 106 * locally or globally. Return UID if added, 0 if conflicts
107 * (error). 107 * (error).
108 */ 108 */
109 int addCategory( const QString &appname, const QString &catname); 109 int addCategory( const QString &appname, const QString &catname);
110 /** Add the category name as long as it doesn't already exist 110 /** Add the category name as long as it doesn't already exist
111 * locally or globally. Return UID if added, 0 if conflicts 111 * locally or globally. Return UID if added, 0 if conflicts
112 * (error). 112 * (error).
113 */ 113 */
114 int addCategory( const QString &appname, const QString &catname, int uid); 114 int addCategory( const QString &appname, const QString &catname, int uid);
115 /** Add the global category just checking that it doesn't 115 /** Add the global category just checking that it doesn't
116 * already exist globally. Return UID if added, 0 if conflicts. 116 * already exist globally. Return UID if added, 0 if conflicts.
117 */ 117 */
118 int addGlobalCategory( const QString &catname ); 118 int addGlobalCategory( const QString &catname );
119 /** Add the global category just checking that it doesn't 119 /** Add the global category just checking that it doesn't
120 * already exist globally. Return UID if added, 0 if conflicts. 120 * already exist globally. Return UID if added, 0 if conflicts.
121 */ 121 */
122 int addGlobalCategory( const QString &catname, int uid ); 122 int addGlobalCategory( const QString &catname, int uid );
123 /** Removes the category from the application; if it is not found 123 /** Removes the category from the application; if it is not found
124 * in the application, then it removes it from the global list 124 * in the application, then it removes it from the global list
125 */ 125 */
126 bool removeCategory( const QString &appName, const QString &catName, 126 bool removeCategory( const QString &appName, const QString &catName,
127 bool checkGlobal = TRUE); 127 bool checkGlobal = TRUE);
128 bool removeCategory( const QString &appName, int uid ); 128 bool removeCategory( const QString &appName, int uid );
129 bool removeGlobalCategory( const QString &catName ); 129 bool removeGlobalCategory( const QString &catName );
130 bool removeGlobalCategory( int uid ); 130 bool removeGlobalCategory( int uid );
131 131
132 QArray<int> ids( const QString &app, const QStringList &labels) const; 132 QArray<int> ids( const QString &app, const QStringList &labels) const;
133 133
134 /** Returns the id associated with the app */ 134 /** Returns the id associated with the app */
135 int id( const QString &app, const QString &cat ) const; 135 int id( const QString &app, const QString &cat ) const;
136 /** Returns the label associated with the id */ 136 /** Returns the label associated with the id */
137 QString label( const QString &app, int id ) const; 137 QString label( const QString &app, int id ) const;
138 138
139 enum ExtraLabels { NoExtra, AllUnfiled, AllLabel, UnfiledLabel }; 139 enum ExtraLabels { NoExtra, AllUnfiled, AllLabel, UnfiledLabel };
140 /** Returns the sorted list of all categories that are 140 /** Returns the sorted list of all categories that are
141 * associated with the app. 141 * associated with the app.
142 * If includeGlobal parameter is TRUE then the returned 142 * If includeGlobal parameter is TRUE then the returned
143 * categories will include the global category items. 143 * categories will include the global category items.
144 * If extra = NoExtra, then 144 * If extra = NoExtra, then
145 * If extra = AllUnfiled, then All and Unfiled will be prepended to 145 * If extra = AllUnfiled, then All and Unfiled will be prepended to
146 * the list 146 * the list
147 * If extra = AllLabel, then All is prepended 147 * If extra = AllLabel, then All is prepended
148 * If extra = UnfiledLabel, then Unfiled is prepended 148 * If extra = UnfiledLabel, then Unfiled is prepended
149 */ 149 */
150 QStringList labels( const QString &app, 150 QStringList labels( const QString &app,
151 bool includeGlobal = TRUE, 151 bool includeGlobal = TRUE,
152 ExtraLabels extra = NoExtra ) const; 152 ExtraLabels extra = NoExtra ) const;
153 153
154 enum DisplaySingle { ShowMulti, ShowAll, ShowFirst }; 154 enum DisplaySingle { ShowMulti, ShowAll, ShowFirst };
155 155
156 /** Returns a single string associated with the cat ids for display in 156 /** Returns a single string associated with the cat ids for display in
157 * a combobox or any area that requires one string. If catids are empty 157 * a combobox or any area that requires one string. If catids are empty
158 * then "Unfiled" will be returned. If multiple categories are assigned 158 * then "Unfiled" will be returned. If multiple categories are assigned
159 * then the behavior depends on the DisplaySingle type. 159 * then the behavior depends on the DisplaySingle type.
160 * If /a display is set to ShowMulti then " (multi)" appended to the 160 * If /a display is set to ShowMulti then " (multi)" appended to the
161 * first string. If /a display is set to ShowAll, then a space seperated 161 * first string. If /a display is set to ShowAll, then a space seperated
162 * string is returned with all categories. If ShowFirst is returned, 162 * string is returned with all categories. If ShowFirst is returned,
163 * the just the first string is returned. 163 * the just the first string is returned.
164 */ 164 */
165 QString displaySingle( const QString &app, 165 QString displaySingle( const QString &app,
166 const QArray<int> &catids, 166 const QArray<int> &catids,
167 DisplaySingle display ) const; 167 DisplaySingle display ) const;
168 168
169 QStringList globalCategories() const { return mGlobalCats.labels();} 169 QStringList globalCategories() const { return mGlobalCats.labels();}
170 170
171 bool renameCategory( const QString &appname, 171 bool renameCategory( const QString &appname,
172 const QString &oldName, 172 const QString &oldName,
173 const QString &newName ); 173 const QString &newName );
174 bool renameGlobalCategory( const QString &oldName, 174 bool renameGlobalCategory( const QString &oldName,
175 const QString &newName ); 175 const QString &newName );
176 176
177 void setGlobal( const QString &appname, const QString &catname, 177 void setGlobal( const QString &appname, const QString &catname,
178 bool value ); 178 bool value );
179 bool isGlobal( const QString &catname ) const; 179 bool isGlobal( const QString &catname ) const;
180 180
181 181
182 /** Returns true if the catname is associated with any application 182 /** Returns true if the catname is associated with any application
183 */ 183 */
184 bool exists( const QString &catname ) const; 184 bool exists( const QString &catname ) const;
185 bool exists( const QString &appname, const QString &catname) const; 185 bool exists( const QString &appname, const QString &catname) const;
186 186
187 bool save( const QString &fname ) const; 187 bool save( const QString &fname ) const;
188 bool load( const QString &fname ); 188 bool load( const QString &fname );
189 189
190 // for debugging 190 // for debugging
191 void dump() const; 191 void dump() const;
192 192
193 const QMap<QString, CategoryGroup> &appGroupMap() const{ return mAppCats; } 193 const QMap<QString, CategoryGroup> &appGroupMap() const{ return mAppCats; }
194 const CategoryGroup &globalGroup() const { return mGlobalCats; } 194 const CategoryGroup &globalGroup() const { return mGlobalCats; }
195 195
196signals: 196signals:
197 /** emitted if added a category; 197 /** emitted if added a category;
198 * the second param is the application the category was added to 198 * the second param is the application the category was added to
199 * or null if global 199 * or null if global
200 * the third param is the uid of the newly added category 200 * the third param is the uid of the newly added category
201 */ 201 */
202 void categoryAdded( const Categories &, const QString &, int ); 202 void categoryAdded( const Categories &, const QString &, int );
203 /** emitted if removed a category 203 /** emitted if removed a category
204 * the second param is the application the category was removed from 204 * the second param is the application the category was removed from
205 * or null if global 205 * or null if global
206 * the third param is the uid of the removed category 206 * the third param is the uid of the removed category
207 */ 207 */
208 void categoryRemoved( const Categories &, const QString &, int ); 208 void categoryRemoved( const Categories &, const QString &, int );
209 /** emitted if a category is renamed; the second param is the uid of 209 /** emitted if a category is renamed; the second param is the uid of
210 * the removed category */ 210 * the removed category */
211 void categoryRenamed( const Categories &, const QString &, int ); 211 void categoryRenamed( const Categories &, const QString &, int );
212 212
213private: 213private:
214 CategoryGroup mGlobalCats; 214 CategoryGroup mGlobalCats;
215 QMap< QString, CategoryGroup > mAppCats; 215 QMap< QString, CategoryGroup > mAppCats;
216}; 216};
217 217
218class QPC_EXPORT CheckedListView : public QListView 218class QPC_EXPORT CheckedListView : public QListView
219{ 219{
220public: 220public:
221 void addCheckableList( const QStringList &options ); 221 void addCheckableList( const QStringList &options );
222 void setChecked( const QStringList &checked ); 222 void setChecked( const QStringList &checked );
223 QStringList checked() const; 223 QStringList checked() const;
224}; 224};
225 225
226#endif 226#endif
diff --git a/library/backend/event.cpp b/library/backend/event.cpp
index d906f19..4c24ab3 100644
--- a/library/backend/event.cpp
+++ b/library/backend/event.cpp
@@ -1,688 +1,688 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. 2** Copyright (C) 2000-2002 Trolltech AS. All rights reserved.
3** 3**
4** This file is part of the Qtopia Environment. 4** This file is part of the Qtopia Environment.
5** 5**
6** This file may be distributed and/or modified under the terms of the 6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software 7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the 8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file. 9** packaging of this file.
10** 10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13** 13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information. 14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15** 15**
16** Contact info@trolltech.com if any conditions of this licensing are 16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you. 17** not clear to you.
18** 18**
19**********************************************************************/ 19**********************************************************************/
20 20
21#include "event.h" 21#include "event.h"
22#include "qfiledirect_p.h" 22#include "qfiledirect_p.h"
23#include <qtopia/timeconversion.h> 23#include <qtopia/timeconversion.h>
24#include <qtopia/stringutil.h> 24#include <qtopia/stringutil.h>
25#include <qtopia/private/recordfields.h> 25#include <qtopia/private/recordfields.h>
26#include <qbuffer.h> 26#include <qbuffer.h>
27#include <time.h> 27#include <time.h>
28#include "vobject_p.h" 28#include "vobject_p.h"
29 29
30#include <stdio.h> 30#include <stdio.h>
31 31
32using namespace Qtopia; 32using namespace Qtopia;
33 33
34static void write( QString& buf, const Event::RepeatPattern &r ) 34static void write( QString& buf, const Event::RepeatPattern &r )
35{ 35{
36 buf += " rtype=\""; 36 buf += " rtype=\"";
37 switch ( r.type ) { 37 switch ( r.type ) {
38 case Event::Daily: 38 case Event::Daily:
39 buf += "Daily"; 39 buf += "Daily";
40 break; 40 break;
41 case Event::Weekly: 41 case Event::Weekly:
42 buf += "Weekly"; 42 buf += "Weekly";
43 break; 43 break;
44 case Event::MonthlyDay: 44 case Event::MonthlyDay:
45 buf += "MonthlyDay"; 45 buf += "MonthlyDay";
46 break; 46 break;
47 case Event::MonthlyDate: 47 case Event::MonthlyDate:
48 buf += "MonthlyDate"; 48 buf += "MonthlyDate";
49 break; 49 break;
50 case Event::Yearly: 50 case Event::Yearly:
51 buf += "Yearly"; 51 buf += "Yearly";
52 break; 52 break;
53 default: 53 default:
54 buf += "NoRepeat"; 54 buf += "NoRepeat";
55 break; 55 break;
56 } 56 }
57 buf += "\""; 57 buf += "\"";
58 if ( r.days > 0 ) 58 if ( r.days > 0 )
59 buf += " rweekdays=\"" + QString::number( static_cast<int>( r.days ) ) + "\""; 59 buf += " rweekdays=\"" + QString::number( static_cast<int>( r.days ) ) + "\"";
60 if ( r.position != 0 ) 60 if ( r.position != 0 )
61 buf += " rposition=\"" + QString::number( r.position ) + "\""; 61 buf += " rposition=\"" + QString::number( r.position ) + "\"";
62 62
63 buf += " rfreq=\"" + QString::number( r.frequency ) + "\""; 63 buf += " rfreq=\"" + QString::number( r.frequency ) + "\"";
64 buf += " rhasenddate=\"" + QString::number( static_cast<int>( r.hasEndDate ) ) + "\""; 64 buf += " rhasenddate=\"" + QString::number( static_cast<int>( r.hasEndDate ) ) + "\"";
65 if ( r.hasEndDate ) 65 if ( r.hasEndDate )
66 buf += " enddt=\"" 66 buf += " enddt=\""
67 + QString::number( r.endDateUTC ? r.endDateUTC : time( 0 ) ) 67 + QString::number( r.endDateUTC ? r.endDateUTC : time( 0 ) )
68 + "\""; 68 + "\"";
69 buf += " created=\"" + QString::number( r.createTime ) + "\""; 69 buf += " created=\"" + QString::number( r.createTime ) + "\"";
70} 70}
71 71
72Qtopia::UidGen Event::sUidGen( Qtopia::UidGen::Qtopia ); 72Qtopia::UidGen Event::sUidGen( Qtopia::UidGen::Qtopia );
73 73
74/*! 74/*!
75 \class Event event.h 75 \class Event event.h
76 \brief The Event class holds the data of a calendar event. 76 \brief The Event class holds the data of a calendar event.
77 77
78 This data includes descriptive data of the event and schedualing information. 78 This data includes descriptive data of the event and schedualing information.
79 79
80 \ingroup qtopiaemb 80 \ingroup qtopiaemb
81 \ingroup qtopiadesktop 81 \ingroup qtopiadesktop
82*/ 82*/
83 83
84/*! 84/*!
85 \class Event::RepeatPattern 85 \class Event::RepeatPattern
86 \class The Event::RepeatPattern class is internal. 86 \class The Event::RepeatPattern class is internal.
87 \internal 87 \internal
88*/ 88*/
89 89
90/*! 90/*!
91 \enum Event::Days 91 \enum Event::Days
92 \internal 92 \internal
93*/ 93*/
94 94
95/*! 95/*!
96 \enum Event::Type 96 \enum Event::Type
97 \internal 97 \internal
98*/ 98*/
99 99
100/*! 100/*!
101 \enum Event::SoundTypeChoice 101 \enum Event::SoundTypeChoice
102 102
103 This enum type defines what kind of sound is made when an alarm occurs 103 This enum type defines what kind of sound is made when an alarm occurs
104 for an event. The currently defined types are: 104 for an event. The currently defined types are:
105 105
106 <ul> 106 <ul>
107 <li>\c Silent - No sound is produced. 107 <li>\c Silent - No sound is produced.
108 <li>\c Loud - A loud sound is produced. 108 <li>\c Loud - A loud sound is produced.
109 </ul> 109 </ul>
110*/ 110*/
111 111
112/*! 112/*!
113 \fn bool Event::operator<( const Event & ) const 113 \fn bool Event::operator<( const Event & ) const
114 \internal 114 \internal
115*/ 115*/
116 116
117/*! 117/*!
118 \fn bool Event::operator<=( const Event & ) const 118 \fn bool Event::operator<=( const Event & ) const
119 \internal 119 \internal
120*/ 120*/
121 121
122/*! 122/*!
123 \fn bool Event::operator!=( const Event & ) const 123 \fn bool Event::operator!=( const Event & ) const
124 \internal 124 \internal
125*/ 125*/
126 126
127/*! 127/*!
128 \fn bool Event::operator>( const Event & ) const 128 \fn bool Event::operator>( const Event & ) const
129 \internal 129 \internal
130*/ 130*/
131 131
132/*! 132/*!
133 \fn bool Event::operator>=( const Event & ) const 133 \fn bool Event::operator>=( const Event & ) const
134 \internal 134 \internal
135*/ 135*/
136 136
137/*! 137/*!
138 \enum Event::RepeatType 138 \enum Event::RepeatType
139 139
140 This enum defines how a event will repeat, if at all. 140 This enum defines how a event will repeat, if at all.
141 141
142 <ul> 142 <ul>
143 <li>\c NoRepeat - Event does not repeat. 143 <li>\c NoRepeat - Event does not repeat.
144 <li>\c Daily - Event occurs every n days. 144 <li>\c Daily - Event occurs every n days.
145 <li>\c Weekly - Event occurs every n weeks. 145 <li>\c Weekly - Event occurs every n weeks.
146 <li>\c MonthlyDay - Event occurs every n months. Event will always occur in 146 <li>\c MonthlyDay - Event occurs every n months. Event will always occur in
147 the same week and same day of week as the first event. 147 the same week and same day of week as the first event.
148 <li>\c MonthlyDate - Event occurs every n months. Event will always occur 148 <li>\c MonthlyDate - Event occurs every n months. Event will always occur
149 on the same day of the month as the first event. 149 on the same day of the month as the first event.
150 <li>\c Yearly - Event occurs every n years. 150 <li>\c Yearly - Event occurs every n years.
151 </ul> 151 </ul>
152*/ 152*/
153 153
154/*! 154/*!
155 \fn bool Event::isAllDay() const 155 \fn bool Event::isAllDay() const
156 156
157 Returns TRUE if the event is an all day event. Otherwise returns FALSE. 157 Returns TRUE if the event is an all day event. Otherwise returns FALSE.
158*/ 158*/
159 159
160/*! 160/*!
161 \fn void Event::setAllDay(bool allday) 161 \fn void Event::setAllDay(bool allday)
162 162
163 If \a allday is TRUE, will set the event to be an all day event. 163 If \a allday is TRUE, will set the event to be an all day event.
164 Otherwise sets the event to not be an all day event. 164 Otherwise sets the event to not be an all day event.
165 165
166 \warning This function may affect the start and end times of the event. 166 \warning This function may affect the start and end times of the event.
167*/ 167*/
168 168
169/*! 169/*!
170 \fn QDateTime Event::start() const 170 \fn QDateTime Event::start(bool) const
171 171
172 Returns the start date and time of the first occurance of the event. 172 Returns the start date and time of the first occurance of the event.
173*/ 173*/
174 174
175/*! 175/*!
176 \fn QDateTime Event::end() const 176 \fn QDateTime Event::end(bool) const
177 177
178 Returns the end date and time of the first occurance of the event. 178 Returns the end date and time of the first occurance of the event.
179*/ 179*/
180 180
181/*! 181/*!
182 \fn time_t Event::startTime() const 182 \fn time_t Event::startTime() const
183 \internal 183 \internal
184*/ 184*/
185 185
186/*! 186/*!
187 \fn time_t Event::endTime() const 187 \fn time_t Event::endTime() const
188 \internal 188 \internal
189*/ 189*/
190 190
191/*! 191/*!
192 \fn void Event::setAlarm(int delay, SoundTypeChoice s) 192 \fn void Event::setAlarm(int delay, SoundTypeChoice s)
193 193
194 Sets the alarm delay of the event to \a delay and the sound type of the 194 Sets the alarm delay of the event to \a delay and the sound type of the
195 alarm to \a s. 195 alarm to \a s.
196*/ 196*/
197 197
198/*! 198/*!
199 \fn void Event::clearAlarm() 199 \fn void Event::clearAlarm()
200 200
201 Clears the alarm for the event. 201 Clears the alarm for the event.
202*/ 202*/
203 203
204/*! 204/*!
205 \fn int Event::alarmDelay() const 205 \fn int Event::alarmDelay() const
206 206
207 Returns the delay in minutes between the alarm for an event and the 207 Returns the delay in minutes between the alarm for an event and the
208 start of the event. 208 start of the event.
209*/ 209*/
210 210
211/*! 211/*!
212 \fn Event::RepeatType Event::repeatType() const 212 \fn Event::RepeatType Event::repeatType() const
213 213
214 Returns the repeat pattern type for the event. 214 Returns the repeat pattern type for the event.
215 215
216 \sa frequency() 216 \sa frequency()
217*/ 217*/
218 218
219/*! 219/*!
220 \fn int Event::weekOffset() const 220 \fn int Event::weekOffset() const
221 221
222 Returns the number of weeks from the start of the month that this event 222 Returns the number of weeks from the start of the month that this event
223 occurs. 223 occurs.
224*/ 224*/
225 225
226/*! 226/*!
227 \fn QDate Event::repeatTill() const 227 \fn QDate Event::repeatTill() const
228 228
229 Returns the date that the event will continue to repeat until. If the event 229 Returns the date that the event will continue to repeat until. If the event
230 repeats forever the value returned is undefined. 230 repeats forever the value returned is undefined.
231 231
232 \sa repeatForever() 232 \sa repeatForever()
233*/ 233*/
234 234
235/*! 235/*!
236 \fn bool Event::repeatForever() const 236 \fn bool Event::repeatForever() const
237 237
238 Returns FALSE if there is a date set for the event to continue until. 238 Returns FALSE if there is a date set for the event to continue until.
239 Otherwise returns TRUE. 239 Otherwise returns TRUE.
240*/ 240*/
241 241
242/*! 242/*!
243 \fn bool Event::doRepeat() const 243 \fn bool Event::doRepeat() const
244 \internal 244 \internal
245*/ 245*/
246 246
247/*! 247/*!
248 \fn bool Event::repeatOnWeekDay(int day) const 248 \fn bool Event::repeatOnWeekDay(int day) const
249 249
250 Returns TRUE if the event has a RepeatType of Weekly and is set to occur on 250 Returns TRUE if the event has a RepeatType of Weekly and is set to occur on
251 \a day each week. Otherwise returns FALSE. 251 \a day each week. Otherwise returns FALSE.
252 252
253 \sa QDate::dayName() 253 \sa QDate::dayName()
254*/ 254*/
255 255
256/*! 256/*!
257 \fn void Event::setRepeatOnWeekDay(int day, bool enable) 257 \fn void Event::setRepeatOnWeekDay(int day, bool enable)
258 258
259 If \a enable is TRUE then sets the event to occur on \a day each week. 259 If \a enable is TRUE then sets the event to occur on \a day each week.
260 Otherwise sets the event not to occur on \a day. 260 Otherwise sets the event not to occur on \a day.
261 261
262 \warning this function is only relavent for a event with RepeatType of 262 \warning this function is only relavent for a event with RepeatType of
263 Weekly. 263 Weekly.
264 264
265 \sa QDate::dayName() 265 \sa QDate::dayName()
266*/ 266*/
267 267
268/*! 268/*!
269 \fn int Event::frequency() const 269 \fn int Event::frequency() const
270 270
271 Returns how often the event repeats. 271 Returns how often the event repeats.
272 272
273 \sa repeatType() 273 \sa repeatType()
274*/ 274*/
275 275
276/*! 276/*!
277 \fn void Event::setRepeatType(RepeatType t) 277 \fn void Event::setRepeatType(RepeatType t)
278 278
279 Sets the repeat pattern type of the event to \a t. 279 Sets the repeat pattern type of the event to \a t.
280 280
281 \sa setFrequency() 281 \sa setFrequency()
282*/ 282*/
283 283
284/*! 284/*!
285 \fn void Event::setFrequency(int n) 285 \fn void Event::setFrequency(int n)
286 286
287 Sets how often the event occurs with in its repeat pattern. 287 Sets how often the event occurs with in its repeat pattern.
288 288
289 \sa setRepeatType() 289 \sa setRepeatType()
290*/ 290*/
291 291
292/*! 292/*!
293 \fn void Event::setRepeatTill(const QDate &d) 293 \fn void Event::setRepeatTill(const QDate &d)
294 294
295 Sets the event to repeat until \a d. 295 Sets the event to repeat until \a d.
296*/ 296*/
297 297
298/*! 298/*!
299 \fn void Event::setRepeatForever(bool enable) 299 \fn void Event::setRepeatForever(bool enable)
300 300
301 If \a enable is TRUE, sets the event to repeat forever. Otherwise 301 If \a enable is TRUE, sets the event to repeat forever. Otherwise
302 sets the event to stop repeating at some date. 302 sets the event to stop repeating at some date.
303 303
304 \warning This function may affect the specific date the event will repeat 304 \warning This function may affect the specific date the event will repeat
305 till. 305 till.
306*/ 306*/
307 307
308/*! 308/*!
309 \fn bool Event::match(const QRegExp &r) const 309 \fn bool Event::match(const QRegExp &r) const
310 310
311 Returns TRUE if the event matches the regular expression \a r. 311 Returns TRUE if the event matches the regular expression \a r.
312 Otherwise returns FALSE. 312 Otherwise returns FALSE.
313*/ 313*/
314 314
315/*! 315/*!
316 \fn char Event::day(int) 316 \fn char Event::day(int)
317 \internal 317 \internal
318*/ 318*/
319 319
320/*! 320/*!
321 Creates a new, empty event. 321 Creates a new, empty event.
322*/ 322*/
323Event::Event() : Record() 323Event::Event() : Record()
324{ 324{
325 startUTC = endUTC = time( 0 ); 325 startUTC = endUTC = time( 0 );
326 typ = Normal; 326 typ = Normal;
327 hAlarm = FALSE; 327 hAlarm = FALSE;
328 hRepeat = FALSE; 328 hRepeat = FALSE;
329 aMinutes = 0; 329 aMinutes = 0;
330 aSound = Silent; 330 aSound = Silent;
331 pattern.type = NoRepeat; 331 pattern.type = NoRepeat;
332 pattern.frequency = -1; 332 pattern.frequency = -1;
333} 333}
334 334
335/*! 335/*!
336 \internal 336 \internal
337*/ 337*/
338Event::Event( const QMap<int, QString> &map ) 338Event::Event( const QMap<int, QString> &map )
339{ 339{
340 setDescription( map[DatebookDescription] ); 340 setDescription( map[DatebookDescription] );
341 setLocation( map[Location] ); 341 setLocation( map[Location] );
342 setCategories( idsFromString( map[DatebookCategory] ) ); 342 setCategories( idsFromString( map[DatebookCategory] ) );
343 setTimeZone( map[TimeZone] ); 343 setTimeZone( map[TimeZone] );
344 setNotes( map[Note] ); 344 setNotes( map[Note] );
345 setStart( TimeConversion::fromUTC( map[StartDateTime].toUInt() ) ); 345 setStart( TimeConversion::fromUTC( map[StartDateTime].toUInt() ) );
346 setEnd( TimeConversion::fromUTC( map[EndDateTime].toUInt() ) ); 346 setEnd( TimeConversion::fromUTC( map[EndDateTime].toUInt() ) );
347 setType( (Event::Type) map[DatebookType].toInt() ); 347 setType( (Event::Type) map[DatebookType].toInt() );
348 setAlarm( ( map[HasAlarm] == "1" ? TRUE : FALSE ), map[AlarmTime].toInt(), (Event::SoundTypeChoice)map[SoundType].toInt() ); 348 setAlarm( ( map[HasAlarm] == "1" ? TRUE : FALSE ), map[AlarmTime].toInt(), (Event::SoundTypeChoice)map[SoundType].toInt() );
349 Event::RepeatPattern p; 349 Event::RepeatPattern p;
350 p.type = (Event::RepeatType) map[ RepeatPatternType ].toInt(); 350 p.type = (Event::RepeatType) map[ RepeatPatternType ].toInt();
351 p.frequency = map[ RepeatPatternFrequency ].toInt(); 351 p.frequency = map[ RepeatPatternFrequency ].toInt();
352 p.position = map[ RepeatPatternPosition ].toInt(); 352 p.position = map[ RepeatPatternPosition ].toInt();
353 p.days = map[ RepeatPatternDays ].toInt(); 353 p.days = map[ RepeatPatternDays ].toInt();
354 p.hasEndDate = map[ RepeatPatternHasEndDate ].toInt(); 354 p.hasEndDate = map[ RepeatPatternHasEndDate ].toInt();
355 p.endDateUTC = map[ RepeatPatternEndDate ].toUInt(); 355 p.endDateUTC = map[ RepeatPatternEndDate ].toUInt();
356 setRepeat( p ); 356 setRepeat( p );
357 357
358 setUid( map[ DatebookUid ].toInt() ); 358 setUid( map[ DatebookUid ].toInt() );
359} 359}
360 360
361/*! 361/*!
362 Destroys an event. 362 Destroys an event.
363*/ 363*/
364Event::~Event() 364Event::~Event()
365{ 365{
366} 366}
367 367
368/*! 368/*!
369 \internal 369 \internal
370*/ 370*/
371int Event::week( const QDate& date ) 371int Event::week( const QDate& date )
372{ 372{
373 // Calculates the week this date is in within that 373 // Calculates the week this date is in within that
374 // month. Equals the "row" is is in in the month view 374 // month. Equals the "row" is is in in the month view
375 int week = 1; 375 int week = 1;
376 QDate tmp( date.year(), date.month(), 1 ); 376 QDate tmp( date.year(), date.month(), 1 );
377 377
378 if ( date.dayOfWeek() < tmp.dayOfWeek() ) 378 if ( date.dayOfWeek() < tmp.dayOfWeek() )
379 ++week; 379 ++week;
380 380
381 week += ( date.day() - 1 ) / 7; 381 week += ( date.day() - 1 ) / 7;
382 return week; 382 return week;
383} 383}
384 384
385/*! 385/*!
386 \internal 386 \internal
387*/ 387*/
388int Event::occurrence( const QDate& date ) 388int Event::occurrence( const QDate& date )
389{ 389{
390 // calculates the number of occurrances of this day of the 390 // calculates the number of occurrances of this day of the
391 // week till the given date (e.g 3rd Wednesday of the month) 391 // week till the given date (e.g 3rd Wednesday of the month)
392 return ( date.day() - 1 ) / 7 + 1; 392 return ( date.day() - 1 ) / 7 + 1;
393} 393}
394 394
395/*! 395/*!
396 \internal 396 \internal
397*/ 397*/
398int Event::dayOfWeek( char day ) 398int Event::dayOfWeek( char day )
399{ 399{
400 int dayOfWeek = 1; 400 int dayOfWeek = 1;
401 char i = Event::MON; 401 char i = Event::MON;
402 while ( !( i & day ) && i <= Event::SUN ) { 402 while ( !( i & day ) && i <= Event::SUN ) {
403 i <<= 1; 403 i <<= 1;
404 ++dayOfWeek; 404 ++dayOfWeek;
405 } 405 }
406 return dayOfWeek; 406 return dayOfWeek;
407} 407}
408 408
409/*! 409/*!
410 \internal 410 \internal
411*/ 411*/
412int Event::monthDiff( const QDate& first, const QDate& second ) 412int Event::monthDiff( const QDate& first, const QDate& second )
413{ 413{
414 return ( second.year() - first.year() ) * 12 + 414 return ( second.year() - first.year() ) * 12 +
415 second.month() - first.month(); 415 second.month() - first.month();
416} 416}
417 417
418/*! 418/*!
419 \internal 419 \internal
420*/ 420*/
421QMap<int, QString> Event::toMap() const 421QMap<int, QString> Event::toMap() const
422{ 422{
423 QMap<int, QString> m; 423 QMap<int, QString> m;
424 424
425 if ( !description().isEmpty() ) 425 if ( !description().isEmpty() )
426 m.insert( DatebookDescription, description() ); 426 m.insert( DatebookDescription, description() );
427 if ( !location().isEmpty() ) 427 if ( !location().isEmpty() )
428 m.insert ( Location, location() ); 428 m.insert ( Location, location() );
429 if ( categories().count() ) 429 if ( categories().count() )
430 m.insert ( DatebookCategory, idsToString( categories() ) ); 430 m.insert ( DatebookCategory, idsToString( categories() ) );
431 if ( !timeZone().isEmpty() ) 431 if ( !timeZone().isEmpty() )
432 m.insert ( TimeZone, timeZone() ); 432 m.insert ( TimeZone, timeZone() );
433 if ( !notes().isEmpty() ) 433 if ( !notes().isEmpty() )
434 m.insert ( Note, notes() ); 434 m.insert ( Note, notes() );
435 435
436 m.insert ( StartDateTime, QString::number( TimeConversion::toUTC( start() ) ) ); 436 m.insert ( StartDateTime, QString::number( TimeConversion::toUTC( start() ) ) );
437 m.insert ( EndDateTime, QString::number( TimeConversion::toUTC( end() ) ) ); 437 m.insert ( EndDateTime, QString::number( TimeConversion::toUTC( end() ) ) );
438 m.insert ( DatebookType, QString::number( (int)type() ) ); 438 m.insert ( DatebookType, QString::number( (int)type() ) );
439 m.insert ( HasAlarm, ( hasAlarm() ? "1" : "0" ) ); 439 m.insert ( HasAlarm, ( hasAlarm() ? "1" : "0" ) );
440 m.insert ( SoundType, QString::number( (int)alarmSound() ) ); 440 m.insert ( SoundType, QString::number( (int)alarmSound() ) );
441 m.insert ( AlarmTime, QString::number( alarmTime() ) ); 441 m.insert ( AlarmTime, QString::number( alarmTime() ) );
442 m.insert ( RepeatPatternType, QString::number( static_cast<int>( repeatPattern().type ) ) ); 442 m.insert ( RepeatPatternType, QString::number( static_cast<int>( repeatPattern().type ) ) );
443 m.insert ( RepeatPatternFrequency, QString::number( repeatPattern().frequency ) ); 443 m.insert ( RepeatPatternFrequency, QString::number( repeatPattern().frequency ) );
444 m.insert ( RepeatPatternPosition, QString::number( repeatPattern().position ) ); 444 m.insert ( RepeatPatternPosition, QString::number( repeatPattern().position ) );
445 m.insert ( RepeatPatternDays, QString::number( repeatPattern().days ) ); 445 m.insert ( RepeatPatternDays, QString::number( repeatPattern().days ) );
446 m.insert ( RepeatPatternHasEndDate, QString::number( static_cast<int>( repeatPattern().hasEndDate ) ) ); 446 m.insert ( RepeatPatternHasEndDate, QString::number( static_cast<int>( repeatPattern().hasEndDate ) ) );
447 m.insert ( RepeatPatternEndDate, QString::number( repeatPattern().endDateUTC ) ); 447 m.insert ( RepeatPatternEndDate, QString::number( repeatPattern().endDateUTC ) );
448 448
449 m.insert( DatebookUid, QString::number( uid()) ); 449 m.insert( DatebookUid, QString::number( uid()) );
450 450
451 return m; 451 return m;
452} 452}
453 453
454/*! 454/*!
455 \internal 455 \internal
456*/ 456*/
457void Event::setRepeat( const RepeatPattern &p ) 457void Event::setRepeat( const RepeatPattern &p )
458{ 458{
459 setRepeat( p.type != NoRepeat, p ); 459 setRepeat( p.type != NoRepeat, p );
460} 460}
461 461
462/*! 462/*!
463 Sets the description of the event to \a s. 463 Sets the description of the event to \a s.
464*/ 464*/
465void Event::setDescription( const QString &s ) 465void Event::setDescription( const QString &s )
466{ 466{
467 descript = s; 467 descript = s;
468} 468}
469 469
470/*! 470/*!
471 Sets the location of the event to \a s. 471 Sets the location of the event to \a s.
472*/ 472*/
473void Event::setLocation( const QString &s ) 473void Event::setLocation( const QString &s )
474{ 474{
475 locat = s; 475 locat = s;
476} 476}
477 477
478// void Event::setCategory( const QString &s ) 478// void Event::setCategory( const QString &s )
479// { 479// {
480// categ = s; 480// categ = s;
481// } 481// }
482 482
483/*! 483/*!
484 \internal 484 \internal
485*/ 485*/
486void Event::setType( Type t ) 486void Event::setType( Type t )
487{ 487{
488 typ = t; 488 typ = t;
489} 489}
490 490
491/*! 491/*!
492 Sets the start date and time of the first or only occurance of this event 492 Sets the start date and time of the first or only occurance of this event
493 to the date and time \a d. \a d should be in local time. 493 to the date and time \a d. \a d should be in local time.
494*/ 494*/
495void Event::setStart( const QDateTime &d ) 495void Event::setStart( const QDateTime &d )
496{ 496{
497 startUTC = TimeConversion::toUTC( d ); 497 startUTC = TimeConversion::toUTC( d );
498} 498}
499 499
500/*! 500/*!
501 \internal 501 \internal
502*/ 502*/
503void Event::setStart( time_t time ) 503void Event::setStart( time_t time )
504{ 504{
505 startUTC = time; 505 startUTC = time;
506} 506}
507 507
508/*! 508/*!
509 Sets the end date and time of the first or only occurance of this event 509 Sets the end date and time of the first or only occurance of this event
510 to the date and time \a d. \a d should be in local time. 510 to the date and time \a d. \a d should be in local time.
511*/ 511*/
512void Event::setEnd( const QDateTime &d ) 512void Event::setEnd( const QDateTime &d )
513{ 513{
514 endUTC = TimeConversion::toUTC( d ); 514 endUTC = TimeConversion::toUTC( d );
515} 515}
516 516
517/*! 517/*!
518 \internal 518 \internal
519*/ 519*/
520void Event::setEnd( time_t time ) 520void Event::setEnd( time_t time )
521{ 521{
522 endUTC = time; 522 endUTC = time;
523} 523}
524 524
525/*! 525/*!
526 \internal 526 \internal
527*/ 527*/
528void Event::setTimeZone( const QString &z ) 528void Event::setTimeZone( const QString &z )
529{ 529{
530 tz = z; 530 tz = z;
531} 531}
532 532
533/*! 533/*!
534 \internal 534 \internal
535*/ 535*/
536void Event::setAlarm( bool b, int minutes, SoundTypeChoice s ) 536void Event::setAlarm( bool b, int minutes, SoundTypeChoice s )
537{ 537{
538 hAlarm = b; 538 hAlarm = b;
539 aMinutes = minutes; 539 aMinutes = minutes;
540 aSound = s; 540 aSound = s;
541} 541}
542 542
543/*! 543/*!
544 \internal 544 \internal
545*/ 545*/
546void Event::setRepeat( bool b, const RepeatPattern &p ) 546void Event::setRepeat( bool b, const RepeatPattern &p )
547{ 547{
548 hRepeat = b; 548 hRepeat = b;
549 pattern = p; 549 pattern = p;
550} 550}
551 551
552/*! 552/*!
553 Sets the notes for the event to \a n. 553 Sets the notes for the event to \a n.
554*/ 554*/
555void Event::setNotes( const QString &n ) 555void Event::setNotes( const QString &n )
556{ 556{
557 note = n; 557 note = n;
558} 558}
559 559
560/*! 560/*!
561 Returns the description of the event. 561 Returns the description of the event.
562*/ 562*/
563const QString &Event::description() const 563const QString &Event::description() const
564{ 564{
565 return descript; 565 return descript;
566} 566}
567 567
568/*! 568/*!
569 Returns the location of the event. 569 Returns the location of the event.
570*/ 570*/
571const QString &Event::location() const 571const QString &Event::location() const
572{ 572{
573 return locat; 573 return locat;
574} 574}
575 575
576// QString Event::category() const 576// QString Event::category() const
577// { 577// {
578// return categ; 578// return categ;
579// } 579// }
580 580
581/*! 581/*!
582 \internal 582 \internal
583*/ 583*/
584Event::Type Event::type() const 584Event::Type Event::type() const
585{ 585{
586 return typ; 586 return typ;
587} 587}
588/* 588/*
589QDateTime Event::start() const { 589QDateTime Event::start() const {
590 return start( TRUE ); 590 return start( TRUE );
591} 591}
592*/ 592*/
593/*! 593/*!
594 \internal 594 \internal
595*/ 595*/
596QDateTime Event::start( bool actual ) const 596QDateTime Event::start( bool actual ) const
597{ 597{
598 QDateTime dt = TimeConversion::fromUTC( startUTC ); 598 QDateTime dt = TimeConversion::fromUTC( startUTC );
599 599
600 if ( actual && typ == AllDay ) { 600 if ( actual && typ == AllDay ) {
601 QTime t = dt.time(); 601 QTime t = dt.time();
602 t.setHMS( 0, 0, 0 ); 602 t.setHMS( 0, 0, 0 );
603 dt.setTime( t ); 603 dt.setTime( t );
604 } 604 }
605 return dt; 605 return dt;
606} 606}
607/* 607/*
608QDateTime Event::end() const { 608QDateTime Event::end() const {
609 return end( TRUE ); 609 return end( TRUE );
610} 610}
611*/ 611*/
612/*! 612/*!
613 \internal 613 \internal
614*/ 614*/
615QDateTime Event::end( bool actual ) const 615QDateTime Event::end( bool actual ) const
616{ 616{
617 /* small work around... */ 617 /* small work around... */
618 if ( actual && typ == AllDay ) { 618 if ( actual && typ == AllDay ) {
619 return QDateTime( TimeConversion::fromUTC( startUTC ).date(), QTime(23, 59, 59 ) ); 619 return QDateTime( TimeConversion::fromUTC( startUTC ).date(), QTime(23, 59, 59 ) );
620 } 620 }
621 return TimeConversion::fromUTC( endUTC ); 621 return TimeConversion::fromUTC( endUTC );
622} 622}
623 623
624/*! 624/*!
625 \internal 625 \internal
626*/ 626*/
627const QString &Event::timeZone() const 627const QString &Event::timeZone() const
628{ 628{
629 return tz; 629 return tz;
630} 630}
631 631
632/*! 632/*!
633 \internal 633 \internal
634*/ 634*/
635bool Event::hasAlarm() const 635bool Event::hasAlarm() const
636{ 636{
637 return hAlarm; 637 return hAlarm;
638} 638}
639 639
640/*! 640/*!
641 \internal 641 \internal
642*/ 642*/
643int Event::alarmTime() const 643int Event::alarmTime() const
644{ 644{
645 return aMinutes; 645 return aMinutes;
646} 646}
647 647
648/*! 648/*!
649 Returns the sound type for the alarm of this event. 649 Returns the sound type for the alarm of this event.
650*/ 650*/
651Event::SoundTypeChoice Event::alarmSound() const 651Event::SoundTypeChoice Event::alarmSound() const
652{ 652{
653 return aSound; 653 return aSound;
654} 654}
655 655
656/*! 656/*!
657 \internal 657 \internal
658*/ 658*/
659bool Event::hasRepeat() const 659bool Event::hasRepeat() const
660{ 660{
661 return doRepeat(); 661 return doRepeat();
662} 662}
663 663
664/*! 664/*!
665 \internal 665 \internal
666*/ 666*/
667const Event::RepeatPattern &Event::repeatPattern() const 667const Event::RepeatPattern &Event::repeatPattern() const
668{ 668{
669 return pattern; 669 return pattern;
670} 670}
671 671
672/*! 672/*!
673 \internal 673 \internal
674*/ 674*/
675Event::RepeatPattern &Event::repeatPattern() 675Event::RepeatPattern &Event::repeatPattern()
676{ 676{
677 return pattern; 677 return pattern;
678} 678}
679 679
680/*! 680/*!
681 Returns the notes for the event. 681 Returns the notes for the event.
682*/ 682*/
683const QString &Event::notes() const 683const QString &Event::notes() const
684{ 684{
685 return note; 685 return note;
686} 686}
687 687
688/*! 688/*!
diff --git a/library/backend/palmtoprecord.h b/library/backend/palmtoprecord.h
index 72f7d1c..15cdd6a 100644
--- a/library/backend/palmtoprecord.h
+++ b/library/backend/palmtoprecord.h
@@ -1,95 +1,107 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. 2** Copyright (C) 2000-2002 Trolltech AS. All rights reserved.
3** 3**
4** This file is part of the Qtopia Environment. 4** This file is part of the 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#ifndef QTPALMTOP_RECORD_H 20#ifndef QTPALMTOP_RECORD_H
21#define QTPALMTOP_RECORD_H 21#define QTPALMTOP_RECORD_H
22#include <qglobal.h> 22#include <qglobal.h>
23#include "qpcglobal.h" 23#include "qpcglobal.h"
24#include "palmtopuidgen.h" 24#include "palmtopuidgen.h"
25#include <qarray.h> 25#include <qarray.h>
26#include <qmap.h> 26#include <qmap.h>
27 27
28#if defined(QPC_TEMPLATEDLL) 28#if defined(QPC_TEMPLATEDLL)
29// MOC_SKIP_BEGIN 29// MOC_SKIP_BEGIN
30QPC_TEMPLATEEXTERN template class QPC_EXPORT QMap<QString, QString>; 30QPC_TEMPLATEEXTERN template class QPC_EXPORT QMap<QString, QString>;
31// MOC_SKIP_END 31// MOC_SKIP_END
32#endif 32#endif
33 33
34class QRegExp; 34class QRegExp;
35/**
36 * @short Qtopia namespace
37 * The namespace of Qtopia
38 */
35namespace Qtopia { 39namespace Qtopia {
36 40
37class RecordPrivate; 41class RecordPrivate;
42/**
43 * @short The base class of all Records
44 *
45 * The base class for Records in Qtopia
46 * @see Task
47 * @see Event
48 * @see Contact
49 */
38class QPC_EXPORT Record 50class QPC_EXPORT Record
39{ 51{
40public: 52public:
41 Record() : mUid(0), mCats() { } 53 Record() : mUid(0), mCats() { }
42 Record( const Record &c ) :mUid( c.mUid ), mCats ( c.mCats ), customMap(c.customMap) { } 54 Record( const Record &c ) :mUid( c.mUid ), mCats ( c.mCats ), customMap(c.customMap) { }
43 virtual ~Record() { } 55 virtual ~Record() { }
44 56
45 Record &operator=( const Record &c ); 57 Record &operator=( const Record &c );
46 58
47 virtual bool match( const QRegExp & ) const { return FALSE; } 59 virtual bool match( const QRegExp & ) const { return FALSE; }
48 60
49 void setCategories( const QArray<int> &v ) { mCats = v; mCats.sort(); } 61 void setCategories( const QArray<int> &v ) { mCats = v; mCats.sort(); }
50 void setCategories( int single ); 62 void setCategories( int single );
51 const QArray<int> &categories() const { return mCats; } 63 const QArray<int> &categories() const { return mCats; }
52 64
53 void reassignCategoryId( int oldId, int newId ) 65 void reassignCategoryId( int oldId, int newId )
54 { 66 {
55 int index = mCats.find( oldId ); 67 int index = mCats.find( oldId );
56 if ( index >= 0 ) 68 if ( index >= 0 )
57 mCats[index] = newId; 69 mCats[index] = newId;
58 } 70 }
59 71
60 int uid() const { return mUid; }; 72 int uid() const { return mUid; };
61 virtual void setUid( int i ) { mUid = i; uidGen().store( mUid ); } 73 virtual void setUid( int i ) { mUid = i; uidGen().store( mUid ); }
62 bool isValidUid() const { return mUid != 0; } 74 bool isValidUid() const { return mUid != 0; }
63 void assignUid() { setUid( uidGen().generate() ); } 75 void assignUid() { setUid( uidGen().generate() ); }
64 76
65 virtual QString customField(const QString &) const; 77 virtual QString customField(const QString &) const;
66 virtual void setCustomField(const QString &, const QString &); 78 virtual void setCustomField(const QString &, const QString &);
67 virtual void removeCustomField(const QString &); 79 virtual void removeCustomField(const QString &);
68 80
69 virtual bool operator == ( const Record &r ) const 81 virtual bool operator == ( const Record &r ) const
70{ return mUid == r.mUid; } 82{ return mUid == r.mUid; }
71 virtual bool operator != ( const Record &r ) const 83 virtual bool operator != ( const Record &r ) const
72{ return mUid != r.mUid; } 84{ return mUid != r.mUid; }
73 85
74 // convenience methods provided for loading and saving to xml 86 // convenience methods provided for loading and saving to xml
75 static QString idsToString( const QArray<int> &ids ); 87 static QString idsToString( const QArray<int> &ids );
76 // convenience methods provided for loading and saving to xml 88 // convenience methods provided for loading and saving to xml
77 static QArray<int> idsFromString( const QString &str ); 89 static QArray<int> idsFromString( const QString &str );
78 90
79 // for debugging 91 // for debugging
80 static void dump( const QMap<int, QString> &map ); 92 static void dump( const QMap<int, QString> &map );
81 93
82protected: 94protected:
83 virtual UidGen &uidGen() = 0; 95 virtual UidGen &uidGen() = 0;
84 virtual QString customToXml() const; 96 virtual QString customToXml() const;
85private: 97private:
86 int mUid; 98 int mUid;
87 QArray<int> mCats; 99 QArray<int> mCats;
88 QMap<QString, QString> customMap; 100 QMap<QString, QString> customMap;
89 RecordPrivate *d; 101 RecordPrivate *d;
90}; 102};
91 103
92} 104}
93 105
94#endif 106#endif
95 107