1 /***************************************************************************
2 * Copyright (C) 2006 by Petri Damsten *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) any later version. *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19 ***************************************************************************/
26 #include <qtoolbutton.h>
27 #include <qbuttongroup.h>
28 #include <qradiobutton.h>
30 #include <kiconloader.h>
31 #include <kmessagebox.h>
36 PasswordDlg::PasswordDlg(QWidget
*parent
, const char *name
)
37 :KDialogBase(Plain
, i18n("Password Protection"), Ok
|Cancel
, Ok
,
38 parent
, name
, /*modal=*/true, /*separator=*/true), w(0)
40 QHBoxLayout
* toplayout
= new QHBoxLayout(plainPage(), 0, 0);
41 w
= new Password(plainPage());
42 toplayout
->addWidget(w
, 1);
45 PasswordDlg::~PasswordDlg()
50 void PasswordDlg::slotOk()
53 if(n
== Basket::PrivateKeyEncryption
&& key().isEmpty())
54 KMessageBox::error(w
, i18n("No private key selected."));
56 KDialogBase::slotOk();
59 QString
PasswordDlg::key() const
61 QString s
= w
->keyCombo
->currentText();
64 int n
= s
.findRev(' ');
70 int PasswordDlg::type() const
72 return w
->buttonGroup
->selectedId();
75 void PasswordDlg::setKey(const QString
& key
)
77 for(int i
= 0; i
< w
->keyCombo
->count(); ++i
)
79 if(w
->keyCombo
->text(i
).find(key
) >= 0)
81 w
->keyCombo
->setCurrentItem(i
);
87 void PasswordDlg::setType(int type
)
89 w
->buttonGroup
->setButton(type
);
92 Password::Password(QWidget
*parent
, const char *name
)
93 : PasswordLayout(parent
, name
)
97 KGpgKeyList list
= gpg
.keys(true);
98 for(KGpgKeyList::iterator it
= list
.begin(); it
!= list
.end(); ++it
) {
99 QString name
= gpg
.checkForUtf8((*it
).name
);
101 keyCombo
->insertItem(QString("%1 <%2> %3").arg(name
).arg((*it
).email
).arg((*it
).id
));
103 publicPrivateRadioButton
->setEnabled(keyCombo
->count() > 0);
104 keyCombo
->setEnabled(keyCombo
->count() > 0);
108 Password::~Password()
112 #include "password.moc"