Diffstat (limited to 'pwmanager/pwmanager/pwmviewstyle.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | pwmanager/pwmanager/pwmviewstyle.cpp | 205 |
1 files changed, 205 insertions, 0 deletions
diff --git a/pwmanager/pwmanager/pwmviewstyle.cpp b/pwmanager/pwmanager/pwmviewstyle.cpp new file mode 100644 index 0000000..67b5197 --- a/dev/null +++ b/pwmanager/pwmanager/pwmviewstyle.cpp | |||
@@ -0,0 +1,205 @@ | |||
1 | /*************************************************************************** | ||
2 | * * | ||
3 | * copyright (C) 2004 by Michael Buesch * | ||
4 | * email: mbuesch@freenet.de * | ||
5 | * * | ||
6 | * This program is free software; you can redistribute it and/or modify * | ||
7 | * it under the terms of the GNU General Public License version 2 * | ||
8 | * as published by the Free Software Foundation. * | ||
9 | * * | ||
10 | ***************************************************************************/ | ||
11 | |||
12 | |||
13 | /*************************************************************************** | ||
14 | * copyright (C) 2004 by Ulf Schenk | ||
15 | * This file is originaly based on version 1.0.1 of pwmanager | ||
16 | * and was modified to run on embedded devices that run microkde | ||
17 | * | ||
18 | * $Id$ | ||
19 | **************************************************************************/ | ||
20 | |||
21 | #include "pwmviewstyle.h" | ||
22 | #include "pwmexception.h" | ||
23 | #include "pwmviewstyle_0.h" | ||
24 | #include "pwmviewstyle_1.h" | ||
25 | #include "listviewpwm.h" | ||
26 | #include "pwmview.h" | ||
27 | #include "commentbox.h" | ||
28 | |||
29 | |||
30 | PwMViewStyle::PwMViewStyle(QWidget *parent, const char *name) | ||
31 | : QWidget(parent, name) | ||
32 | { | ||
33 | curStyle = style_notset; | ||
34 | s0 = 0; | ||
35 | s1 = 0; | ||
36 | } | ||
37 | |||
38 | PwMViewStyle::~PwMViewStyle() | ||
39 | { | ||
40 | delete_ifnot_null(s0); | ||
41 | delete_ifnot_null(s1); | ||
42 | } | ||
43 | |||
44 | void PwMViewStyle::initStyle(style_t style) | ||
45 | { | ||
46 | printDebug(string("initializing style ") + tostr(style)); | ||
47 | bool wasMaximized = v->isMaximized(); | ||
48 | if (v->isVisible()) | ||
49 | v->hide(); | ||
50 | switch (style) { | ||
51 | case style_0: | ||
52 | delete_ifnot_null(s0); | ||
53 | delete_ifnot_null(s1); | ||
54 | s0 = new PwMViewStyle_0(v); | ||
55 | lv = s0->getLv(); | ||
56 | commentBox = s0->getCommentBox(); | ||
57 | break; | ||
58 | case style_1: | ||
59 | delete_ifnot_null(s0); | ||
60 | delete_ifnot_null(s1); | ||
61 | s1 = new PwMViewStyle_1(v); | ||
62 | lv = s1->getLv(); | ||
63 | commentBox = s1->getCommentBox(); | ||
64 | break; | ||
65 | default: | ||
66 | BUG(); | ||
67 | return; | ||
68 | } | ||
69 | curStyle = style; | ||
70 | connect(lv, SIGNAL(pressed(QListViewItem *)), | ||
71 | v, SLOT(handleToggle(QListViewItem *))); | ||
72 | connect(lv, SIGNAL(rightButtonClicked(QListViewItem *, const QPoint &, int)), | ||
73 | v, SLOT(handleRightClick(QListViewItem *, const QPoint &, int))); | ||
74 | connect(lv, SIGNAL(clicked(QListViewItem *)), | ||
75 | v, SLOT(refreshCommentTextEdit(QListViewItem *))); | ||
76 | lv->addColumn(i18n("Description"), 180); | ||
77 | lv->addColumn(i18n("Username"), 150); | ||
78 | lv->addColumn(i18n("Password"), 150); | ||
79 | lv->addColumn(i18n("URL"), 180); | ||
80 | lv->addColumn(i18n("Launcher"), 120); | ||
81 | v->tmpReEnableSort(); | ||
82 | resizeView(v->size()); | ||
83 | v->updateView(); | ||
84 | if (wasMaximized) { | ||
85 | v->showMaximized(); | ||
86 | } else { | ||
87 | v->show(); | ||
88 | } | ||
89 | connect(lv, SIGNAL(layoutChanged()), | ||
90 | v, SLOT(reorgLp())); | ||
91 | } | ||
92 | |||
93 | void PwMViewStyle::resizeView(const QSize &size) | ||
94 | { | ||
95 | switch (curStyle) { | ||
96 | case style_0: | ||
97 | PWM_ASSERT(s0); | ||
98 | s0->resize(size); | ||
99 | return; | ||
100 | case style_1: | ||
101 | PWM_ASSERT(s1); | ||
102 | s1->resize(size); | ||
103 | return; | ||
104 | default: | ||
105 | BUG(); | ||
106 | } | ||
107 | } | ||
108 | |||
109 | QString PwMViewStyle::getCurrentCategory() | ||
110 | { | ||
111 | switch (curStyle) { | ||
112 | case style_0: | ||
113 | PWM_ASSERT(s0); | ||
114 | return s0->getCurrentCategory(); | ||
115 | case style_1: | ||
116 | PWM_ASSERT(s1); | ||
117 | return s1->getCurrentCategory(); | ||
118 | default: | ||
119 | BUG(); | ||
120 | } | ||
121 | return ""; | ||
122 | } | ||
123 | |||
124 | void PwMViewStyle::addCategory(const QString &cat) | ||
125 | { | ||
126 | switch (curStyle) { | ||
127 | case style_0: | ||
128 | PWM_ASSERT(s0); | ||
129 | s0->addCategory(cat); | ||
130 | return; | ||
131 | case style_1: | ||
132 | PWM_ASSERT(s1); | ||
133 | s1->addCategory(cat); | ||
134 | return; | ||
135 | default: | ||
136 | BUG(); | ||
137 | } | ||
138 | } | ||
139 | |||
140 | void PwMViewStyle::delCategory(const QString &cat) | ||
141 | { | ||
142 | switch (curStyle) { | ||
143 | case style_0: | ||
144 | PWM_ASSERT(s0); | ||
145 | s0->delCategory(cat); | ||
146 | return; | ||
147 | case style_1: | ||
148 | PWM_ASSERT(s1); | ||
149 | s1->delCategory(cat); | ||
150 | return; | ||
151 | default: | ||
152 | BUG(); | ||
153 | } | ||
154 | } | ||
155 | |||
156 | void PwMViewStyle::delAllCategories() | ||
157 | { | ||
158 | switch (curStyle) { | ||
159 | case style_0: | ||
160 | PWM_ASSERT(s0); | ||
161 | s0->delAllCategories(); | ||
162 | return; | ||
163 | case style_1: | ||
164 | PWM_ASSERT(s1); | ||
165 | s1->delAllCategories(); | ||
166 | return; | ||
167 | default: | ||
168 | BUG(); | ||
169 | } | ||
170 | } | ||
171 | |||
172 | void PwMViewStyle::selectCategory(const QString &cat) | ||
173 | { | ||
174 | switch (curStyle) { | ||
175 | case style_0: | ||
176 | PWM_ASSERT(s0); | ||
177 | s0->selectCategory(cat); | ||
178 | return; | ||
179 | case style_1: | ||
180 | PWM_ASSERT(s1); | ||
181 | s1->selectCategory(cat); | ||
182 | return; | ||
183 | default: | ||
184 | BUG(); | ||
185 | } | ||
186 | } | ||
187 | |||
188 | int PwMViewStyle::numCategories() | ||
189 | { | ||
190 | switch (curStyle) { | ||
191 | case style_0: | ||
192 | PWM_ASSERT(s0); | ||
193 | return s0->numCategories(); | ||
194 | case style_1: | ||
195 | PWM_ASSERT(s1); | ||
196 | return s1->numCategories(); | ||
197 | default: | ||
198 | BUG(); | ||
199 | } | ||
200 | return 0; | ||
201 | } | ||
202 | |||
203 | #ifndef PWM_EMBEDDED | ||
204 | #include "pwmviewstyle.moc" | ||
205 | #endif | ||