summaryrefslogtreecommitdiffabout
path: root/pwmanager/pwmanager/pwmviewstyle.cpp
blob: ee35472584c5829aefde788e97cbf578cbdf7315 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
/***************************************************************************
 *                                                                         *
 *   copyright (C) 2004 by Michael Buesch                                  *
 *   email: mbuesch@freenet.de                                             *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License version 2        *
 *   as published by the Free Software Foundation.                         *
 *                                                                         *
 ***************************************************************************/


/***************************************************************************
 * copyright (C) 2004 by Ulf Schenk
 * This file is originaly based on version 1.0.1 of pwmanager
 * and was modified to run on embedded devices that run microkde
 *
 * $Id$
 **************************************************************************/  

#include "pwmviewstyle.h"
#include "pwmexception.h"
#include "pwmviewstyle_0.h"
#include "pwmviewstyle_1.h"
#include "listviewpwm.h"
#include "pwmview.h"
#include "commentbox.h"
#ifndef PWM_EMBEDDED
#include "configuration.h"
#else
#include "pwmprefs.h"
#endif

PwMViewStyle::PwMViewStyle(QWidget *parent, const char *name)
 : QWidget(parent, name)
{
	curStyle = style_notset;
	s0 = 0;
	s1 = 0;
}

PwMViewStyle::~PwMViewStyle()
{
	//US ENH : store the size of the listviewcolumns
        switch (curStyle)
	  {
	  case style_0:
	    s0->saveSettings(PWMPrefs::instance());
	    break;
	  case style_1:
	    s1->saveSettings(PWMPrefs::instance());
	    break;
	  default:
		BUG();
	  }


	PWMPrefs::instance()->writeConfig();

	delete_ifnot_null(s0);
	delete_ifnot_null(s1);
}

void PwMViewStyle::editPassWord( QListViewItem * i )
{
    if ( !i )
        return;
    emit editPW();
}
void PwMViewStyle::initStyle(style_t style)
{
	printDebug(string("initializing style ") + tostr(style));
	bool wasMaximized = v->isMaximized();
	if (v->isVisible())
		v->hide();
	switch (style) {
	case style_0:
		delete_ifnot_null(s0);
		delete_ifnot_null(s1);
		s0 = new PwMViewStyle_0(v);
		lv = s0->getLv();
		commentBox = s0->getCommentBox();
		break;
	case style_1:
		delete_ifnot_null(s0);
		delete_ifnot_null(s1);
		s1 = new PwMViewStyle_1(v);
		lv = s1->getLv();
		commentBox = s1->getCommentBox();
		break;
	default:
		BUG();
		return;
	}
	curStyle = style;
	connect(lv, SIGNAL(pressed(QListViewItem *)),
		v, SLOT(handleToggle(QListViewItem *)));
	connect(lv, SIGNAL(rightButtonClicked(QListViewItem *, const QPoint &, int)),
		v, SLOT(handleRightClick(QListViewItem *, const QPoint &, int)));
	connect(lv, SIGNAL(clicked(QListViewItem *)),
		v, SLOT(refreshCommentTextEdit(QListViewItem *)));
	connect(lv, SIGNAL(returnPressed(QListViewItem *)),
		this, SLOT(editPassWord(QListViewItem *)));
	connect(lv, SIGNAL(doubleClicked(QListViewItem *)),
		this, SLOT(editPassWord(QListViewItem *)));
	connect(lv, SIGNAL(insertPW()),
		this, SIGNAL( insertPW() ));
	connect(lv, SIGNAL(deletePW()),
		this, SIGNAL( deletePW() ));

	lv->addColumn(i18n("Description"), 180);
	lv->addColumn(i18n("Username"), 150);
	lv->addColumn(i18n("Password"), 150);
	lv->addColumn(i18n("URL"), 180);
	lv->addColumn(i18n("Launcher"), 120);
	v->tmpReEnableSort();

	//US ENH : load the size of the listviewcolumns
	switch (curStyle)
	  {
	  case style_0:
	    s0->restoreSettings(PWMPrefs::instance());
	    break;
	  case style_1:
	    s1->restoreSettings(PWMPrefs::instance());
	    break;
	  default:
		BUG();
	  }

	resizeView(v->size());
	v->updateView();
	if (wasMaximized) {
		v->showMaximized();
	} else {
		v->show();
	}
	connect(lv, SIGNAL(layoutChanged()),
		v, SLOT(reorgLp()));
}

void PwMViewStyle::resizeView(const QSize &size)
{
	switch (curStyle) {
	case style_0:
		PWM_ASSERT(s0);
		s0->resize(size);
		return;
	case style_1:
		PWM_ASSERT(s1);
		s1->resize(size);
		return;
	default:
		BUG();
	}
}

QString PwMViewStyle::getCurrentCategory()
{
	switch (curStyle) {
	case style_0:
		PWM_ASSERT(s0);
		return s0->getCurrentCategory();
	case style_1:
		PWM_ASSERT(s1);
		return s1->getCurrentCategory();
	default:
		BUG();
	}
	return "";
}

void PwMViewStyle::addCategory(const QString &cat)
{
	switch (curStyle) {
	case style_0:
		PWM_ASSERT(s0);
		s0->addCategory(cat);
		return;
	case style_1:
		PWM_ASSERT(s1);
		s1->addCategory(cat);
		return;
	default:
		BUG();
	}
}

void PwMViewStyle::delCategory(const QString &cat)
{
	switch (curStyle) {
	case style_0:
		PWM_ASSERT(s0);
		s0->delCategory(cat);
		return;
	case style_1:
		PWM_ASSERT(s1);
		s1->delCategory(cat);
		return;
	default:
		BUG();
	}
}

void PwMViewStyle::delAllCategories()
{
	switch (curStyle) {
	case style_0:
		PWM_ASSERT(s0);
		s0->delAllCategories();
		return;
	case style_1:
		PWM_ASSERT(s1);
		s1->delAllCategories();
		return;
	default:
		BUG();
	}
}

void PwMViewStyle::selectCategory(const QString &cat)
{
	switch (curStyle) {
	case style_0:
		PWM_ASSERT(s0);
		s0->selectCategory(cat);
		return;
	case style_1:
		PWM_ASSERT(s1);
		s1->selectCategory(cat);
		return;
	default:
		BUG();
	}
}

int PwMViewStyle::numCategories()
{
	switch (curStyle) {
	case style_0:
		PWM_ASSERT(s0);
		return s0->numCategories();
	case style_1:
		PWM_ASSERT(s1);
		return s1->numCategories();
	default:
		BUG();
	}
	return 0;
}

#ifndef PWM_EMBEDDED
#include "pwmviewstyle.moc"
#endif