summaryrefslogtreecommitdiffabout
path: root/pwmanager/pwmanager/addentrywndimpl.cpp
Unidiff
Diffstat (limited to 'pwmanager/pwmanager/addentrywndimpl.cpp') (more/less context) (show whitespace changes)
-rw-r--r--pwmanager/pwmanager/addentrywndimpl.cpp174
1 files changed, 174 insertions, 0 deletions
diff --git a/pwmanager/pwmanager/addentrywndimpl.cpp b/pwmanager/pwmanager/addentrywndimpl.cpp
new file mode 100644
index 0000000..9e0fde9
--- a/dev/null
+++ b/pwmanager/pwmanager/addentrywndimpl.cpp
@@ -0,0 +1,174 @@
1/***************************************************************************
2 * *
3 * copyright (C) 2003, 2004 by Michael Buesch *
4 * email: mbuesch@freenet.de *
5 * *
6 * Many very good improvements and the original implementations of *
7 * them came from Matt Scifo <mscifo@o1.com> *
8 * *
9 * This program is free software; you can redistribute it and/or modify *
10 * it under the terms of the GNU General Public License version 2 *
11 * as published by the Free Software Foundation. *
12 * *
13 ***************************************************************************/
14
15/***************************************************************************
16 * copyright (C) 2004 by Ulf Schenk
17 * This file is originaly based on version 1.0.1 of pwmanager
18 * and was modified to run on embedded devices that run microkde
19 *
20 * $Id$
21 **************************************************************************/
22
23#include "addentrywndimpl.h"
24#include "pwmexception.h"
25#include "pwgenwndimpl.h"
26#ifndef PWM_EMBEDDED
27#include "advcommeditimpl.h"
28#endif
29#include "htmlgen.h"
30
31#include <kmessagebox.h>
32#include <klocale.h>
33
34#include <qpushbutton.h>
35#include <qlabel.h>
36
37
38AddEntryWndImpl::AddEntryWndImpl()
39{
40 editAdvCommentButton = 0;
41 commentTextEdit = 0;
42 switchComment(false);
43 pwGen = new PwGenWndImpl(this);
44}
45
46AddEntryWndImpl::~AddEntryWndImpl()
47{
48 delete_ifnot_null(editAdvCommentButton);
49 delete_ifnot_null(commentTextEdit);
50 delete pwGen;
51}
52
53void AddEntryWndImpl::okButton_slot()
54{
55 if (pwLineEdit->text().isEmpty()) {
56 KMessageBox::error(this,
57 i18n("Sorry, you haven't set a password."),
58 i18n("no password"));
59 return;
60 }
61 if (descLineEdit->text().isEmpty()) {
62 KMessageBox::error(this,
63 i18n
64 ("You haven't set a \"Description\"."),
65 i18n("Description not set"));
66 return;
67 }
68 done(1);
69}
70
71void AddEntryWndImpl::cancelButton_slot()
72{
73 done(2);
74}
75
76void AddEntryWndImpl::setCurrCategory(const QString &cat)
77{
78 int i, count = categoryComboBox->count();
79
80 for (i = 0; i < count; ++i) {
81 if (categoryComboBox->text(i) == cat) {
82 categoryComboBox->setCurrentItem(i);
83 return;
84 }
85 }
86 BUG();
87}
88
89void AddEntryWndImpl::revealButton_slot()
90{
91 if (revealButton->isOn()) {
92 pwLineEdit->setEchoMode(QLineEdit::Normal);
93 } else {
94 pwLineEdit->setEchoMode(QLineEdit::Password);
95 }
96}
97
98void AddEntryWndImpl::generateButton_slot()
99{
100 if (!pwGen->exec())
101 return;
102 setPassword(pwGen->getPassword());
103}
104
105QString AddEntryWndImpl::getComment()
106{
107 if (isAdvancedComment()) {
108 return advCommentDta;
109 }
110 return commentTextEdit->text();
111}
112
113void AddEntryWndImpl::setComment(const QString &comm)
114{
115 if (HtmlGen::isHtml(comm)) {
116 advancedCommentButton->setOn(true);
117 advCommentDta = comm;
118 } else {
119 advancedCommentButton->setOn(false);
120 commentTextEdit->setText(comm);
121 }
122}
123
124void AddEntryWndImpl::advancedCommentButton_slot(bool on)
125{
126 switchComment(on);
127}
128
129void AddEntryWndImpl::switchComment(bool toAdvanced)
130{
131 useAdvComment = toAdvanced;
132 if (toAdvanced) {
133 if (commentTextEdit) {
134 savedCommentText = commentTextEdit->text();
135 delete_and_null(commentTextEdit);
136 }
137 if (editAdvCommentButton)
138 return;
139 editAdvCommentButton = new QPushButton(i18n("Edit advanced comment..."),
140 commentDummy);
141 editAdvCommentButton->resize(commentDummy->size().width(), 50);
142 connect(editAdvCommentButton, SIGNAL(clicked()),
143 this, SLOT(editAdvCommentButton_slot()));
144 editAdvCommentButton->show();
145 } else {
146 delete_ifnot_null(editAdvCommentButton);
147 if (commentTextEdit)
148 return;
149#ifndef PWM_EMBEDDED
150 commentTextEdit = new QTextEdit(commentDummy);
151 commentTextEdit->setTextFormat(Qt::PlainText);
152#else
153 commentTextEdit = new QMultiLineEdit(commentDummy);
154#endif
155 commentTextEdit->resize(commentDummy->size());
156 commentTextEdit->setText(savedCommentText);
157 commentTextEdit->show();
158 }
159}
160
161void AddEntryWndImpl::editAdvCommentButton_slot()
162{
163#ifndef PWM_EMBEDDED
164 AdvCommEditImpl editor(this);
165 editor.setHtmlDta(advCommentDta);
166 if (editor.exec())
167 return;
168 advCommentDta = editor.getHtmlDta();
169#endif
170}
171
172#ifndef PWM_EMBEDDED
173#include "addentrywndimpl.moc"
174#endif