-rw-r--r-- | library/categorymenu.cpp | 110 |
1 files changed, 110 insertions, 0 deletions
diff --git a/library/categorymenu.cpp b/library/categorymenu.cpp new file mode 100644 index 0000000..52a127c --- a/dev/null +++ b/library/categorymenu.cpp | |||
@@ -0,0 +1,110 @@ | |||
1 | /********************************************************************** | ||
2 | ** Copyright (C) 2001 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 Software | ||
8 | ** Foundation and appearing in the file LICENSE.GPL included in the | ||
9 | ** packaging of this file. | ||
10 | ** | ||
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. | ||
13 | ** | ||
14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | ||
15 | ** | ||
16 | ** Contact info@trolltech.com if any conditions of this licensing are | ||
17 | ** not clear to you. | ||
18 | ** | ||
19 | **********************************************************************/ | ||
20 | |||
21 | #include "categorymenu.h" | ||
22 | #include "backend/categories.h" | ||
23 | #include "categoryselect.h" | ||
24 | #include <qstring.h> | ||
25 | #include <qmap.h> | ||
26 | |||
27 | CategoryMenu::CategoryMenu( const QString &n, bool ig = TRUE, | ||
28 | QWidget *parent = 0, const char *name = 0 ) : | ||
29 | QPopupMenu(parent, name), | ||
30 | appName(n), | ||
31 | includeGlobal(ig) | ||
32 | { | ||
33 | currentMid = 1; | ||
34 | reload(); | ||
35 | connect(this, SIGNAL(activated(int)), this, SLOT(mapMenuId(int))); | ||
36 | } | ||
37 | |||
38 | CategoryMenu::~CategoryMenu( ) | ||
39 | { | ||
40 | } | ||
41 | |||
42 | void CategoryMenu::reload() | ||
43 | { | ||
44 | clear(); | ||
45 | Categories c; | ||
46 | |||
47 | c.load(categoryFileName()); | ||
48 | |||
49 | QStringList sl = c.labels(appName, includeGlobal); | ||
50 | int mid = 1; | ||
51 | |||
52 | insertItem(tr("All"), mid); | ||
53 | mid++; | ||
54 | insertItem(tr("Unfiled"), mid); | ||
55 | mid++; | ||
56 | |||
57 | for (QStringList::Iterator it = sl.begin(); | ||
58 | it != sl.end(); ++it ) { | ||
59 | int cid = c.id(appName, *it); | ||
60 | insertItem(*it, mid); | ||
61 | menuToId.insert(mid, cid); | ||
62 | idToMenu.insert(cid, mid); | ||
63 | mid++; | ||
64 | } | ||
65 | |||
66 | setItemChecked(currentMid, TRUE ); | ||
67 | } | ||
68 | |||
69 | void CategoryMenu::mapMenuId(int id) | ||
70 | { | ||
71 | if (id == currentMid) | ||
72 | return; | ||
73 | setItemChecked( currentMid, FALSE ); | ||
74 | setItemChecked( id, TRUE ); | ||
75 | currentMid = id; | ||
76 | |||
77 | emit categoryChange(); | ||
78 | } | ||
79 | |||
80 | bool CategoryMenu::isSelected(const QArray<int> &cUids) const | ||
81 | { | ||
82 | if (currentMid == 1) | ||
83 | return TRUE; | ||
84 | |||
85 | if (currentMid == 2 && cUids.count() == 0) | ||
86 | return TRUE; | ||
87 | |||
88 | if (cUids.contains(menuToId[currentMid])) | ||
89 | return TRUE; | ||
90 | |||
91 | return FALSE; | ||
92 | } | ||
93 | |||
94 | void CategoryMenu::setCurrentCategory( int newCatUid ) | ||
95 | { | ||
96 | if (!idToMenu.contains(newCatUid)) | ||
97 | return; | ||
98 | |||
99 | mapMenuId(idToMenu[newCatUid]); | ||
100 | } | ||
101 | |||
102 | void CategoryMenu::setCurrentCategoryAll( ) | ||
103 | { | ||
104 | mapMenuId(1); | ||
105 | } | ||
106 | |||
107 | void CategoryMenu::setCurrentCategoryUnfiled( ) | ||
108 | { | ||
109 | mapMenuId(2); | ||
110 | } | ||