Patch from Romain H. to create notes from the DCOP interface.
[basket4.git] / src / password.cpp
blob2824612e590eb07f4114713dc36c9467651151fc
1 /***************************************************************************
2 * Copyright (C) 2006 by Petri Damsten *
3 * damu@iki.fi *
4 * *
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. *
9 * *
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. *
14 * *
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 ***************************************************************************/
21 #include "password.h"
23 #ifdef HAVE_LIBGPGME
25 #include <qlayout.h>
26 #include <qtoolbutton.h>
27 #include <qbuttongroup.h>
28 #include <qradiobutton.h>
29 #include <klocale.h>
30 #include <kiconloader.h>
31 #include <kmessagebox.h>
33 #include "basket.h"
34 #include "kgpgme.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()
47 delete w;
50 void PasswordDlg::slotOk()
52 int n = type();
53 if(n == Basket::PrivateKeyEncryption && key().isEmpty())
54 KMessageBox::error(w, i18n("No private key selected."));
55 else
56 KDialogBase::slotOk();
59 QString PasswordDlg::key() const
61 QString s = w->keyCombo->currentText();
62 if(s.length() < 16)
63 return "";
64 int n = s.findRev(' ');
65 if(n < 0)
66 return "";
67 return s.mid(n+1);
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);
82 return;
87 void PasswordDlg::setType(int type)
89 w->buttonGroup->setButton(type);
92 Password::Password(QWidget *parent, const char *name)
93 : PasswordLayout(parent, name)
95 KGpgMe gpg;
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"
114 #endif