-rw-r--r-- | library/backend/categories.h | 232 |
1 files changed, 232 insertions, 0 deletions
diff --git a/library/backend/categories.h b/library/backend/categories.h new file mode 100644 index 0000000..82d765b --- a/dev/null +++ b/library/backend/categories.h | |||
@@ -0,0 +1,232 @@ | |||
1 | /********************************************************************** | ||
2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. | ||
3 | ** | ||
4 | ** This file is part of Qtopia Environment. | ||
5 | ** | ||
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 | ||
8 | ** Software Foundation and appearing in the file LICENSE.GPL included | ||
9 | ** in the packaging of this file. | ||
10 | ** | ||
11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING | ||
12 | ** THE WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A | ||
13 | ** PARTICULAR PURPOSE. | ||
14 | ** | ||
15 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | ||
16 | ** | ||
17 | ** Contact info@trolltech.com if any conditions of this licensing are | ||
18 | ** not clear to you. | ||
19 | ** | ||
20 | **********************************************************************/ | ||
21 | |||
22 | #ifndef QTPALMTOP_CATEGORIES_H | ||
23 | #define QTPALMTOP_CATEGORIES_H | ||
24 | |||
25 | #include <qstring.h> | ||
26 | #include <qstringlist.h> | ||
27 | #include <qmap.h> | ||
28 | #include <qlistview.h> | ||
29 | #include <qarray.h> | ||
30 | #include "qpcglobal.h" | ||
31 | #include "palmtopuidgen.h" | ||
32 | |||
33 | class CategoryGroup; | ||
34 | |||
35 | #if defined(QPC_TEMPLATEDLL) | ||
36 | // MOC_SKIP_BEGIN | ||
37 | template class QPC_EXPORT QMap<int, QString>; | ||
38 | template class QPC_EXPORT QMap<QString, int>; | ||
39 | template class QPC_EXPORT QMap< QString, CategoryGroup >; | ||
40 | // MOC_SKIP_END | ||
41 | #endif | ||
42 | |||
43 | class QPC_EXPORT CategoryGroup | ||
44 | { | ||
45 | friend class Categories; | ||
46 | public: | ||
47 | CategoryGroup(): mIdLabelMap(), mLabelIdMap() { } | ||
48 | CategoryGroup( const CategoryGroup &c ) : | ||
49 | mIdLabelMap( c.mIdLabelMap), mLabelIdMap( c.mLabelIdMap ) { } | ||
50 | |||
51 | void clear() { mIdLabelMap.clear(); mLabelIdMap.clear(); } | ||
52 | |||
53 | int add( const QString &label ); | ||
54 | bool add( int uid, const QString &label ); | ||
55 | |||
56 | bool remove( const QString &label ); | ||
57 | bool remove( int uid ); | ||
58 | |||
59 | bool rename( int uid, const QString &newLabel ); | ||
60 | bool rename( const QString &oldLabel, const QString &newLabel ); | ||
61 | |||
62 | bool contains(int id) const; | ||
63 | bool contains(const QString &label) const; | ||
64 | |||
65 | /** Returns label associated with the uid or QString::null if | ||
66 | * not found | ||
67 | */ | ||
68 | const QString &label(int id) const; | ||
69 | /** Returns the uid associated with label or 0 if not found */ | ||
70 | int id(const QString &label) const; | ||
71 | |||
72 | /** Returns a sorted list of labels */ | ||
73 | QStringList labels() const; | ||
74 | QArray<int> ids( const QStringList &cats ) const; | ||
75 | QArray<int> ids() const; | ||
76 | QStringList labels( const QArray<int> &catids ) const; | ||
77 | |||
78 | const QMap<int, QString> &idMap() const { return mIdLabelMap; } | ||
79 | |||
80 | private: | ||
81 | void insert( int uid, const QString &label ); | ||
82 | QMap<int, QString> mIdLabelMap; | ||
83 | QMap<QString, int> mLabelIdMap; | ||
84 | |||
85 | static Qtopia::UidGen &uidGen() { return sUidGen; } | ||
86 | static Qtopia::UidGen sUidGen; | ||
87 | }; | ||
88 | |||
89 | /** Map from application name to categories */ | ||
90 | class QPC_EXPORT Categories : public QObject | ||
91 | { | ||
92 | Q_OBJECT | ||
93 | public: | ||
94 | Categories( QObject *parent=0, const char *name = 0 ) | ||
95 | : QObject( parent, name ), mGlobalCats(), mAppCats() { } | ||
96 | Categories( const Categories ©From ) : QObject( copyFrom.parent() ), | ||
97 | mGlobalCats( copyFrom.mGlobalCats ), | ||
98 | mAppCats( copyFrom.mAppCats ) { } | ||
99 | virtual ~Categories() { } | ||
100 | |||
101 | Categories &operator= ( const Categories &c ) | ||
102 | { mAppCats = c.mAppCats; mGlobalCats = c.mGlobalCats; return *this; } | ||
103 | |||
104 | void clear(); | ||
105 | |||
106 | /** Add the category name as long as it doesn't already exist | ||
107 | * locally or globally. Return UID if added, 0 if conflicts | ||
108 | * (error). | ||
109 | */ | ||
110 | int addCategory( const QString &appname, const QString &catname); | ||
111 | /** Add the category name as long as it doesn't already exist | ||
112 | * locally or globally. Return UID if added, 0 if conflicts | ||
113 | * (error). | ||
114 | */ | ||
115 | int addCategory( const QString &appname, const QString &catname, int uid); | ||
116 | /** Add the global category just checking that it doesn't | ||
117 | * already exist globally. Return UID if added, 0 if conflicts. | ||
118 | */ | ||
119 | int addGlobalCategory( const QString &catname ); | ||
120 | /** Add the global category just checking that it doesn't | ||
121 | * already exist globally. Return UID if added, 0 if conflicts. | ||
122 | */ | ||
123 | int addGlobalCategory( const QString &catname, int uid ); | ||
124 | /** Removes the category from the application; if it is not found | ||
125 | * in the application, then it removes it from the global list | ||
126 | */ | ||
127 | bool removeCategory( const QString &appName, const QString &catName, | ||
128 | bool checkGlobal = TRUE); | ||
129 | bool removeCategory( const QString &appName, int uid ); | ||
130 | bool removeGlobalCategory( const QString &catName ); | ||
131 | bool removeGlobalCategory( int uid ); | ||
132 | |||
133 | QArray<int> ids( const QString &app ) const; | ||
134 | QArray<int> ids( const QString &app, | ||
135 | const QStringList &cats ) const; | ||
136 | /** Returns the id associated with the app */ | ||
137 | int id( const QString &app, const QString &cat ) const; | ||
138 | /** Returns the label associated with the id */ | ||
139 | QString label( const QString &app, int id ) const; | ||
140 | |||
141 | enum ExtraLabels { NoExtra, AllUnfiled, AllLabel, UnfiledLabel }; | ||
142 | /** Returns the sorted list of all categories that are | ||
143 | * associated with the app. | ||
144 | * If includeGlobal parameter is TRUE then the returned | ||
145 | * categories will include the global category items. | ||
146 | * If extra = NoExtra, then | ||
147 | * If extra = AllUnfiled, then All and Unfiled will be prepended to | ||
148 | * the list | ||
149 | * If extra = AllLabel, then All is prepended | ||
150 | * If extra = UnfiledLabel, then Unfiled is prepended | ||
151 | */ | ||
152 | QStringList labels( const QString &app, | ||
153 | bool includeGlobal = TRUE, | ||
154 | ExtraLabels extra = NoExtra ) const; | ||
155 | |||
156 | /** Returns the labels of the categories associated with the uids */ | ||
157 | QStringList labels( const QString & app, | ||
158 | const QArray<int> &catids ) const; | ||
159 | |||
160 | enum DisplaySingle { ShowMulti, ShowAll, ShowFirst }; | ||
161 | |||
162 | /** Returns a single string associated with the cat ids for display in | ||
163 | * a combobox or any area that requires one string. If catids are empty | ||
164 | * then "Unfiled" will be returned. If multiple categories are assigned | ||
165 | * then the behavior depends on the DisplaySingle type. | ||
166 | * If /a display is set to ShowMulti then " (multi)" appended to the | ||
167 | * first string. If /a display is set to ShowAll, then a space seperated | ||
168 | * string is returned with all categories. If ShowFirst is returned, | ||
169 | * the just the first string is returned. | ||
170 | */ | ||
171 | QString displaySingle( const QString &app, | ||
172 | const QArray<int> &catids, | ||
173 | DisplaySingle display ) const; | ||
174 | |||
175 | QStringList globalCategories() const { return mGlobalCats.labels();} | ||
176 | |||
177 | bool renameCategory( const QString &appname, | ||
178 | const QString &oldName, | ||
179 | const QString &newName ); | ||
180 | bool renameGlobalCategory( const QString &oldName, | ||
181 | const QString &newName ); | ||
182 | |||
183 | void setGlobal( const QString &appname, const QString &catname, | ||
184 | bool value ); | ||
185 | bool isGlobal( const QString &catname ) const; | ||
186 | |||
187 | |||
188 | /** Returns true if the catname is associated with any application | ||
189 | */ | ||
190 | bool exists( const QString &catname ) const; | ||
191 | bool exists( const QString &appname, const QString &catname) const; | ||
192 | |||
193 | bool save( const QString &fname ) const; | ||
194 | bool load( const QString &fname ); | ||
195 | |||
196 | // for debugging | ||
197 | void dump() const; | ||
198 | |||
199 | const QMap<QString, CategoryGroup> &appGroupMap() const{ return mAppCats; } | ||
200 | const CategoryGroup &globalGroup() const { return mGlobalCats; } | ||
201 | |||
202 | signals: | ||
203 | /** emitted if added a category; | ||
204 | * the second param is the application the category was added to | ||
205 | * or null if global | ||
206 | * the third param is the uid of the newly added category | ||
207 | */ | ||
208 | void categoryAdded( const Categories &, const QString &, int ); | ||
209 | /** emitted if removed a category | ||
210 | * the second param is the application the category was removed from | ||
211 | * or null if global | ||
212 | * the third param is the uid of the removed category | ||
213 | */ | ||
214 | void categoryRemoved( const Categories &, const QString &, int ); | ||
215 | /** emitted if a category is renamed; the second param is the uid of | ||
216 | * the removed category */ | ||
217 | void categoryRenamed( const Categories &, const QString &, int ); | ||
218 | |||
219 | private: | ||
220 | CategoryGroup mGlobalCats; | ||
221 | QMap< QString, CategoryGroup > mAppCats; | ||
222 | }; | ||
223 | |||
224 | class QPC_EXPORT CheckedListView : public QListView | ||
225 | { | ||
226 | public: | ||
227 | void addCheckableList( const QStringList &options ); | ||
228 | void setChecked( const QStringList &checked ); | ||
229 | QStringList checked() const; | ||
230 | }; | ||
231 | |||
232 | #endif | ||