summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--library/backend/categories.cpp2
1 files changed, 1 insertions, 1 deletions
diff --git a/library/backend/categories.cpp b/library/backend/categories.cpp
index e37b3b9..2e84089 100644
--- a/library/backend/categories.cpp
+++ b/library/backend/categories.cpp
@@ -1,212 +1,212 @@
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/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