summaryrefslogtreecommitdiff
path: root/library/backend/categories.cpp
Unidiff
Diffstat (limited to 'library/backend/categories.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--library/backend/categories.cpp327
1 files changed, 293 insertions, 34 deletions
diff --git a/library/backend/categories.cpp b/library/backend/categories.cpp
index 6e011c4..e37b3b9 100644
--- a/library/backend/categories.cpp
+++ b/library/backend/categories.cpp
@@ -1,14 +1,13 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved. 2** Copyright (C) 2000-2002 Trolltech AS. All rights reserved.
3** 3**
4** This file is part of 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 7** GNU General Public License version 2 as published by the Free Software
8** Software Foundation and appearing in the file LICENSE.GPL included 8** Foundation and appearing in the file LICENSE.GPL included in the
9** in the 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 11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** THE WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A 12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13** PARTICULAR PURPOSE.
14** 13**
@@ -20,3 +19,4 @@
20**********************************************************************/ 19**********************************************************************/
21#include "categories.h" 20#include <qtopia/categories.h>
21#include <qtopia/stringutil.h>
22#include <qfile.h> 22#include <qfile.h>
@@ -24,3 +24,2 @@
24#include <qtextstream.h> 24#include <qtextstream.h>
25#include "stringutil.h"
26 25
@@ -40,2 +39,20 @@ UidGen CategoryGroup::sUidGen( UidGen::Qtopia );
40 39
40/*! \class CategoryGroup categories.h
41 \brief Helper class that is used by Categories
42
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
45 category labels and category labels to ids. Lookups can be done with
46 labels or unique idenifiers.
47
48 \ingroup qtopiaemb
49 \ingroup qtopiadesktop
50 \warning Categories API will likely change between Qtopia 1.5 and Qtopia 3
51 \sa Categories::appGroupMap(), Categories::globalGroup()
52 */
53
54/*! Add \a label and return the UID. If failure, then 0 is returned. Note
55 that All and Unfiled are reserved labels.
56 \internal
57*/
41int CategoryGroup::add( const QString &label ) 58int CategoryGroup::add( const QString &label )
@@ -60,2 +77,4 @@ void CategoryGroup::insert( int uid, const QString &label )
60 77
78/*! \internal
79 */
61bool CategoryGroup::add( int uid, const QString &label ) 80bool CategoryGroup::add( int uid, const QString &label )
@@ -75,2 +94,5 @@ bool CategoryGroup::add( int uid, const QString &label )
75 94
95/*! Returns TRUE if \a label was removed from the group, FALSE if not.
96 \internal
97 */
76bool CategoryGroup::remove( const QString &label ) 98bool CategoryGroup::remove( const QString &label )
@@ -87,2 +109,5 @@ bool CategoryGroup::remove( const QString &label )
87 109
110/*! Returns TRUE if \a uid was removed from the group, FALSE if not.
111 \internal
112 */
88bool CategoryGroup::remove( int uid ) 113bool CategoryGroup::remove( int uid )
@@ -99,2 +124,4 @@ bool CategoryGroup::remove( int uid )
99 124
125/*! \internal
126 */
100bool CategoryGroup::rename( int uid, const QString &newLabel ) 127bool CategoryGroup::rename( int uid, const QString &newLabel )
@@ -115,2 +142,4 @@ bool CategoryGroup::rename( int uid, const QString &newLabel )
115 142
143/*! \internal
144 */
116bool CategoryGroup::rename( const QString &oldLabel, const QString &newLabel ) 145bool CategoryGroup::rename( const QString &oldLabel, const QString &newLabel )
@@ -120,2 +149,3 @@ bool CategoryGroup::rename( const QString &oldLabel, const QString &newLabel )
120 149
150/*! Returns TRUE if \a uid is stored in this group, FALSE if not. */
121bool CategoryGroup::contains(int uid) const 151bool CategoryGroup::contains(int uid) const
@@ -125,2 +155,3 @@ bool CategoryGroup::contains(int uid) const
125 155
156/*! Returns TRUE if \a label is stored in this group, FALSE if not. */
126bool CategoryGroup::contains(const QString &label) const 157bool CategoryGroup::contains(const QString &label) const
@@ -130,4 +161,4 @@ bool CategoryGroup::contains(const QString &label) const
130 161
131/** Returns label associated with the uid or QString::null if 162/*! Returns label associated with the \a uid or QString::null if
132 * not found 163 not found
133 */ 164 */
@@ -141,3 +172,3 @@ const QString &CategoryGroup::label(int uid) const
141 172
142/** Returns the uid associated with label or 0 if not found */ 173/*! Returns the uid associated with \a label or 0 if not found */
143int CategoryGroup::id(const QString &label) const 174int CategoryGroup::id(const QString &label) const
@@ -150,2 +181,3 @@ int CategoryGroup::id(const QString &label) const
150 181
182/*! Returns a list of all labels stored in this group. */
151QStringList CategoryGroup::labels() const 183QStringList CategoryGroup::labels() const
@@ -161,2 +193,3 @@ QStringList CategoryGroup::labels() const
161 193
194/*! Returns a list of all labels associated with the \a catids */
162QStringList CategoryGroup::labels(const QArray<int> &catids ) const 195QStringList CategoryGroup::labels(const QArray<int> &catids ) const
@@ -179,5 +212,45 @@ QStringList CategoryGroup::labels(const QArray<int> &catids ) const
179 212
180/** Add the category name as long as it doesn't already exist locally 213/*!
181 * or globally. Return TRUE if added, FALSE if conflicts. 214 \class Categories categories.h
182 */ 215 \brief The Categories class is a database that groups categories and maps ids to names.
216
217 The Categories class is the low level Categories accessor class. To
218 add a category menu and filter for your application, see CategoryMenu.
219
220 The Categories class allows the developer to add, remove, and rename
221 categories. Categories can be created for an individual application
222 such as Todo List or to be used for all applications. Categories
223 that can be used by all applications are called global
224 categories. Each PalmtopRecord subclass stores categories as an
225 QArray<int> using PalmtopRecord::setCategories() and
226 PalmtopRecord::categories(). This allows each record to be assigned
227 to multiple categories. This also allows the user to rename a
228 category and for it to update automatically in all records.
229
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
232 helper class called CategoryGroup is used to access categories of a
233 single application group, such as Todo List. Global categories can
234 also be accessed via CategoryGroup objects. See appGroupMap() and
235 globalGroup() for the appropriate accessor methods.
236
237 Categories are stored in an xml file in the Settings directory
238 (Categories.xml). A global function called categoryFileName() will
239 return to appropriate QString file location to be passed to load()
240 and save() for the master categories database.
241
242 \ingroup qtopiaemb
243 \ingroup qtopiadesktop
244 \warning Categories API will likely change between Qtopia 1.5 and Qtopia 3
245 \sa CategoryGroup, CategoryMenu
246*/
247
248
249/*!
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
252 added. Return \a uid if added, 0 if conflicts (error).
253
254 \internal
255*/
183int Categories::addCategory( const QString &appname, 256int Categories::addCategory( const QString &appname,
@@ -206,2 +279,7 @@ int Categories::addCategory( const QString &appname,
206 279
280/*!
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).
283*/
284
207int Categories::addCategory( const QString &appname, 285int Categories::addCategory( const QString &appname,
@@ -231,2 +309,5 @@ int Categories::addCategory( const QString &appname,
231 309
310/*!
311 \internal
312*/
232int Categories::addGlobalCategory( const QString &catname, int uid ) 313int Categories::addGlobalCategory( const QString &catname, int uid )
@@ -238,2 +319,8 @@ int Categories::addGlobalCategory( const QString &catname, int uid )
238 319
320/*!
321 Add the global category \a catname while checking that it doesn't
322 already exist globally. Return UID if added, 0 if conflicts.
323
324 \sa addCategory()
325 */
239int Categories::addGlobalCategory( const QString &catname ) 326int Categories::addGlobalCategory( const QString &catname )
@@ -247,6 +334,8 @@ int Categories::addGlobalCategory( const QString &catname )
247 334
248/** Removes the category from the application; if it is not found 335/*!
249 * in the application, then it attempts to remove it from 336
250 * the global list 337 Removes the \a catname from the application group. If it is not
251 */ 338 found in the application group and \a checkGlobal is TRUE, then it
339 attempts to remove it from the global list
340*/
252bool Categories::removeCategory( const QString &appname, 341bool Categories::removeCategory( const QString &appname,
@@ -270,2 +359,7 @@ bool Categories::removeCategory( const QString &appname,
270 359
360
361/*!
362 Removes the \a uid from the application group \a appname. Returns TRUE
363 if success, FALSE if not found.
364*/
271bool Categories::removeCategory( const QString &appname, int uid ) 365bool Categories::removeCategory( const QString &appname, int uid )
@@ -284,2 +378,6 @@ bool Categories::removeCategory( const QString &appname, int uid )
284 378
379/*!
380 Removes the global category \a catname. Returns TRUE
381 if success, FALSE if not found.
382*/
285bool Categories::removeGlobalCategory( const QString &catname ) 383bool Categories::removeGlobalCategory( const QString &catname )
@@ -294,3 +392,6 @@ bool Categories::removeGlobalCategory( const QString &catname )
294 392
295 393/*!
394 Removes the global category \a uid. Returns TRUE
395 if success, FALSE if not found.
396*/
296bool Categories::removeGlobalCategory( int uid ) 397bool Categories::removeGlobalCategory( int uid )
@@ -304,5 +405,6 @@ bool Categories::removeGlobalCategory( int uid )
304 405
305/** Returns the sorted list of all categories that are associated with 406/*!
306 * the app. If includeGlobal parameter is TRUE then the returned 407 Returns the sorted list of all categories that are associated with
307 * categories will include the global category items. 408 the \a app. If \a includeGlobal is TRUE then the returned
409 categories will include the global category items.
308 */ 410 */
@@ -318,3 +420,3 @@ QStringList Categories::labels( const QString &app,
318 cats += (*appIt).labels(); 420 cats += (*appIt).labels();
319 else qDebug("Categories::labels didn't find app %s", app.latin1() ); 421 //else qDebug("Categories::labels didn't find app %s", app.latin1() );
320 if ( includeGlobal ) 422 if ( includeGlobal )
@@ -340,2 +442,5 @@ QStringList Categories::labels( const QString &app,
340 442
443/*!
444 Returns the label associated with the id
445*/
341QString Categories::label( const QString &app, int id ) const 446QString Categories::label( const QString &app, int id ) const
@@ -351,7 +456,13 @@ QString Categories::label( const QString &app, int id ) const
351 456
352/** Returns a single string associated with the cat ids for display in 457/*!
353 * a combobox or any area that requires one string. If catids are empty 458 Returns a single string associated with \a catids for display in a
354 * then "Unfiled" will be returned. If multiple categories are assigned 459 combobox or any area that requires one string. If \a catids are empty
355 * the first cat id is shown with " (multi)" appended to the string. 460 then "Unfiled" will be returned. If multiple categories are
356 */ 461 assigned then the behavior depends on the DisplaySingle type.
462
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
465 seperated string is returned with all categories. If ShowFirst is
466 set, the just the first string is returned.
467*/
357QString Categories::displaySingle( const QString &app, 468QString Categories::displaySingle( const QString &app,
@@ -382,2 +493,7 @@ QString Categories::displaySingle( const QString &app,
382 493
494/*!
495
496 Returns all ids associated with the application CategoryGroup \a app
497 and the passed in \a labels in that group.
498*/
383QArray<int> Categories::ids( const QString &app, const QStringList &labels) const 499QArray<int> Categories::ids( const QString &app, const QStringList &labels) const
@@ -387,3 +503,3 @@ QArray<int> Categories::ids( const QString &app, const QStringList &labels) cons
387 int i; 503 int i;
388 504
389 for ( i=0, it=labels.begin(); it!=labels.end(); i++, ++it ) { 505 for ( i=0, it=labels.begin(); it!=labels.end(); i++, ++it ) {
@@ -399,2 +515,7 @@ QArray<int> Categories::ids( const QString &app, const QStringList &labels) cons
399 515
516/*!
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.
519 If it is not found it either, 0 is returned.
520*/
400int Categories::id( const QString &app, const QString &cat ) const 521int Categories::id( const QString &app, const QString &cat ) const
@@ -410,4 +531,9 @@ int Categories::id( const QString &app, const QString &cat ) const
410 531
411/** Return TRUE if renaming succeeded; FALSE if app name not found, 532/*!
412 * or if there was a name conflict 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
535 in the CategoryGroup.
536
537 It will first search the CategoryGroup associated with \a appname
538 and if not found it will try to replace in global CategoryGroup.
413 */ 539 */
@@ -431,2 +557,8 @@ bool Categories::renameCategory( const QString &appname,
431 557
558/*!
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
561 in the CategoryGroup. This function will only rename categories found
562 in the global CategoryGroup.
563 */
432bool Categories::renameGlobalCategory( const QString &oldName, 564bool Categories::renameGlobalCategory( const QString &oldName,
@@ -442,2 +574,6 @@ bool Categories::renameGlobalCategory( const QString &oldName,
442 574
575/*!
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.
578*/
443void Categories::setGlobal( const QString &appname, 579void Categories::setGlobal( const QString &appname,
@@ -460,2 +596,5 @@ void Categories::setGlobal( const QString &appname,
460 596
597/*!
598 Returns TRUE if the \a catname is in the global CategoryGroup, FALSE if not.
599*/
461bool Categories::isGlobal( const QString &catname ) const 600bool Categories::isGlobal( const QString &catname ) const
@@ -466,3 +605,5 @@ bool Categories::isGlobal( const QString &catname ) const
466 605
467/** Returns true if the catname is associated with any application 606/*!
607 Returns true if the \a catname is associated with any CategoryGroup,
608 including global.
468 */ 609 */
@@ -480,2 +621,6 @@ bool Categories::exists( const QString &catname ) const
480 621
622/*!
623 Returns TRUE if the \a catname is associated with the \a appname
624 CategoryGroup, FALSE if not found.
625 */
481bool Categories::exists( const QString &appname, 626bool Categories::exists( const QString &appname,
@@ -492,3 +637,8 @@ bool Categories::exists( const QString &appname,
492 637
638/*!
639 Saves the Categories database to the \a fname. See categoryFileName()
640 for the default file name string used for the shared category database.
493 641
642 Returns FALSE if there is error writing the file or TRUE on success.
643 */
494bool Categories::save( const QString &fname ) const 644bool Categories::save( const QString &fname ) const
@@ -536,2 +686,5 @@ bool Categories::save( const QString &fname ) const
536 686
687#ifdef Q_OS_WIN32
688 QFile::remove( fname );
689#endif
537 if ( ::rename( strNewFile.latin1(), fname.latin1() ) < 0 ) { 690 if ( ::rename( strNewFile.latin1(), fname.latin1() ) < 0 ) {
@@ -546,2 +699,8 @@ bool Categories::save( const QString &fname ) const
546 699
700/*!
701 Loads the Categories database using \a fname. See categoryFileName()
702 for the default file name string used for the shared category database.
703
704 Returns FALSE if there is error reading the file or TRUE on success.
705 */
547bool Categories::load( const QString &fname ) 706bool Categories::load( const QString &fname )
@@ -621,2 +780,6 @@ bool Categories::load( const QString &fname )
621 780
781/*!
782 Clear the categories in memory. Equivelent to creating an empty Categories
783 object.
784*/
622void Categories::clear() 785void Categories::clear()
@@ -627,2 +790,5 @@ void Categories::clear()
627 790
791/*!
792 Dump the contents to standard out. Used for debugging only.
793*/
628void Categories::dump() const 794void Categories::dump() const
@@ -677 +843,94 @@ void CheckedListView::setChecked( const QStringList &checked )
677} 843}
844
845/*! \fn Categories &Categories::operator= ( const Categories &c )
846
847 Performs deep copy.
848 */
849
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
857
858 Returns list of all global category labels
859*/
860
861/*! \fn const QMap<QString, CategoryGroup> &Categories::appGroupMap() const
862
863 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.
865*/
866
867/*! \fn const CategoryGroup &Categories::globalGroup() const
868
869 Returns the global CategoryGroup. The CategoryGroup
870 class defines a map of ids to category labels and category labels to ids.
871*/
872
873/*! \fn void Categories::categoryAdded( const Categories &cats, const QString &appname, int uid)
874
875 Emitted if a category is added.
876
877 \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
879 \a uid is the unique identifier associated with the added category
880 */
881
882/*! \fn void Categories::categoryRemoved( const Categories &cats, const QString &appname,
883 int uid)
884
885 Emitted if removed category is removed.
886
887 \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
889 \a uid is the unique identifier associated with the removed category
890*/
891
892
893/*! \fn void Categories::categoryRenamed( const Categories &cats, const QString &appname,
894 int uid)
895
896 Emitted if \a uid in the \a appname CategoryGroup is renamed in \a cats
897 object.
898
899 \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
901 \a uid is the unique identifier associated with the renamed category
902*/
903
904/*! \fn Categories::Categories( QObject *parent=0, const char *name = 0 )
905
906 Constructor for an empty Categories object.
907*/
908
909/*! \fn Categories::Categories( const Categories &copyFrom )
910
911 Deep copy constructor
912*/
913
914/*! \fn Categories::~Categories()
915
916 Empty destructor. Call save() before destruction if there are changes
917 that need to be saved.
918*/
919
920/*! \fn CategoryGroup::clear()
921 \internal
922*/
923
924/*! \fn const QMap<int, QString> &CategoryGroup::idMap() const
925
926 Returns a const reference to the id to label QMap
927*/
928
929/*! \fn CategoryGroup::CategoryGroup()
930 \internal
931*/
932
933/*! \fn CategoryGroup::CategoryGroup(const CategoryGroup &c)
934 \internal
935*/
936