summaryrefslogtreecommitdiffabout
path: root/pwmanager/pwmanager/addentrywndimpl.cpp
blob: c952ead8248cd084e2d3bd00eedb120cc49f10dd (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
/***************************************************************************
 *                                                                         *
 *   copyright (C) 2003, 2004 by Michael Buesch                            *
 *   email: mbuesch@freenet.de                                             *
 *                                                                         *
 *   Many very good improvements and the original implementations of       *
 *   them came from Matt Scifo <mscifo@o1.com>                             *
 *                                                                         *
 *   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 "addentrywndimpl.h"
#include "pwmexception.h"
#include "pwgenwndimpl.h"
#ifndef PWM_EMBEDDED
#include "advcommeditimpl.h"
#endif
#include "htmlgen.h"

#include <kmessagebox.h>
#include <klocale.h>

#include <qpushbutton.h>
#include <qlabel.h>
#include <qlayout.h>


#ifndef PWM_EMBEDDED
AddEntryWndImpl::AddEntryWndImpl()
  : addEntryWnd( 0, "AddEntryWndImpl", TRUE)
#else
AddEntryWndImpl::AddEntryWndImpl( PwMDoc* doc, QWidget* parent, const char* name)
  : addEntryWnd( doc, parent, name)
#endif
{
	categoryComboBox->setSizePolicy( QSizePolicy( QSizePolicy::Expanding,QSizePolicy::Preferred ));
#ifndef PWM_EMBEDDED
	editAdvCommentButton = 0;
	commentTextEdit = 0;
#endif
	switchComment(false);
	pwGen = new PwGenWndImpl(this);
}

AddEntryWndImpl::~AddEntryWndImpl()
{
#ifndef PWM_EMBEDDED
	delete_ifnot_null(editAdvCommentButton);
	delete_ifnot_null(commentTextEdit);
#endif
	delete pwGen;
}

#ifdef PWM_EMBEDDED
void AddEntryWndImpl::slotOk()
{
  slotApply();

  if (pwLineEdit->text().isEmpty()) {
    KMessageBox::error(this,
	i18n("Sorry, you haven't set a password."),
	i18n("no password"));
    return;
  }
  
  if (descLineEdit->text().isEmpty()) {
    KMessageBox::error(this,
	i18n("You haven't set a \"Description\"."),
	i18n("Description not set"));
    return;
  }
 
  KDialogBase::slotOk();
}
#else

void AddEntryWndImpl::okButton_slot()
{
	if (pwLineEdit->text().isEmpty()) {
		KMessageBox::error(this,
				   i18n("Sorry, you haven't set a password."),
				   i18n("no password"));
		return;
	}
	if (descLineEdit->text().isEmpty()) {
		KMessageBox::error(this,
				   i18n
				   ("You haven't set a \"Description\"."),
				   i18n("Description not set"));
		return;
	}
	done(1);
}

void AddEntryWndImpl::cancelButton_slot()
{
	done(2);
}
#endif

void AddEntryWndImpl::setCurrCategory(const QString &cat)
{
	int i, count = categoryComboBox->count();

	for (i = 0; i < count; ++i) {
		if (categoryComboBox->text(i) == cat) {
			categoryComboBox->setCurrentItem(i);
#ifdef PWM_EMBEDDED
			categorySelected(cat);
#endif
			return;
		}
	}
	BUG();
}

void AddEntryWndImpl::revealButton_slot()
{
	if (revealButton->isOn()) {
		pwLineEdit->setEchoMode(QLineEdit::Normal);
	} else {
		pwLineEdit->setEchoMode(QLineEdit::Password);
	}
}

void AddEntryWndImpl::generateButton_slot()
{
	if (!pwGen->exec())
		return;
	setPassword(pwGen->getPassword());
}

QString AddEntryWndImpl::getComment()
{
#ifndef PWM_EMBEDDED
	if (isAdvancedComment()) {
		return advCommentDta;
	}
#endif
	return commentTextEdit->text();
}

void AddEntryWndImpl::setComment(const QString &comm)
{
#ifndef PWM_EMBEDDED
	if (HtmlGen::isHtml(comm)) {
		advancedCommentButton->setOn(true);
		advCommentDta = comm;
	} else {
		advancedCommentButton->setOn(false);
		commentTextEdit->setText(comm);
	}
#else
	commentTextEdit->setText(comm);
#endif
}

void AddEntryWndImpl::advancedCommentButton_slot(bool on)
{
#ifndef PWM_EMBEDDED
	switchComment(on);
#endif
}

void AddEntryWndImpl::switchComment(bool toAdvanced)
{
#ifndef PWM_EMBEDDED

	useAdvComment = toAdvanced;
	if (toAdvanced) {
		if (commentTextEdit) {
			savedCommentText = commentTextEdit->text();
			delete_and_null(commentTextEdit);
		}
		if (editAdvCommentButton)
			return;
		editAdvCommentButton = new QPushButton(i18n("Edit advanced comment..."),
						       commentDummy);
		editAdvCommentButton->resize(commentDummy->size().width(), 50);
		connect(editAdvCommentButton, SIGNAL(clicked()),
			this, SLOT(editAdvCommentButton_slot()));
		editAdvCommentButton->show();
	} else {
		delete_ifnot_null(editAdvCommentButton);
		if (commentTextEdit)
			return;

		commentTextEdit = new Q3TextEdit(commentDummy);
		commentTextEdit->setTextFormat(Qt::PlainText);
		commentTextEdit->resize(commentDummy->size());
		commentTextEdit->setText(savedCommentText);
		commentTextEdit->show();
	}
#endif
}

void AddEntryWndImpl::editAdvCommentButton_slot()
{
#ifndef PWM_EMBEDDED
	AdvCommEditImpl editor(this);
	editor.setHtmlDta(advCommentDta);
	if (editor.exec())
		return;
	advCommentDta = editor.getHtmlDta();
#endif
}

#ifndef PWM_EMBEDDED_
#include "moc_addentrywndimpl.cpp"
#endif