8#include "kwalletwizard.h"
10#include "ui_kwalletwizardpageexplanation.h"
11#include "ui_kwalletwizardpageintro.h"
12#include "ui_kwalletwizardpageoptions.h"
13#include "ui_kwalletwizardpagepassword.h"
15#include "ui_kwalletwizardpagegpgkey.h"
16#include "ui_kwalletwizardpagepasswordgpg.h"
19#include <KLocalizedString>
20#include <QButtonGroup>
27#include <gpgme++/context.h>
28#include <gpgme++/key.h>
29#include <gpgme++/keylistresult.h>
40 ui.ktitlewidget->setText(
"<h1>" +
i18n(
"KWallet") +
"</h1>");
41 ui.ktitlewidget->setIcon(
QIcon::fromTheme(QStringLiteral(
"kwalletmanager")));
49 ui._basic->setChecked(
true);
55 Ui::KWalletWizardPageIntro ui;
61 explicit PagePassword(KWalletWizard *
parent)
71 registerField(QStringLiteral(
"useBlowfish"), ui._radioBlowfish);
78 ui._useWallet->setChecked(
true);
81 int nextId()
const override
85 if (
field(QStringLiteral(
"useWallet")).toBool()) {
86 if (
field(QStringLiteral(
"useBlowfish")).toBool()) {
87 nextId =
static_cast<KWalletWizard *
>(
wizard())->wizardType() == KWalletWizard::Basic
89 : KWalletWizard::PageOptionsId;
91 nextId = KWalletWizard::PageGpgKeyId;
97 return static_cast<KWalletWizard *
>(
wizard())->wizardType() == KWalletWizard::Basic ? -1 : KWalletWizard::PageOptionsId;
101 void setMatchLabelText(
const QString &text)
103 ui._matchLabel->setText(text);
108 Ui::KWalletWizardPagePasswordGpg ui;
110 Ui::KWalletWizardPagePassword ui;
115typedef std::vector<GpgME::Key> KeysVector;
116Q_DECLARE_METATYPE(GpgME::Key)
118struct AddKeyToCombo {
124 void operator()(
const GpgME::Key &k)
126 QString text = QStringLiteral(
"%1 (%2)").
arg(k.shortKeyID(), k.userID(0).email());
136 explicit PageGpgKey(
QWidget *parent)
138 , userHasGpgKeys(false)
145 GpgME::initializeLibrary();
146 GpgME::Error err = GpgME::checkEngine(GpgME::OpenPGP);
148 qDebug() <<
"OpenPGP not supported on your system!";
151 i18n(
"The GpgME library failed to initialize for the OpenPGP protocol. Please check your system's configuration then try again."));
153 std::shared_ptr<GpgME::Context> ctx(GpgME::Context::createForProtocol(GpgME::OpenPGP));
154 if (
nullptr == ctx) {
157 i18n(
"The GpgME library failed to initialize for the OpenPGP protocol. Please check your system's configuration then try again."));
159 ctx->setKeyListMode(GpgME::KeyListMode::Local);
160 err = ctx->startKeyListing();
162 GpgME::Key k = ctx->nextKey(err);
166 if (!k.isInvalid() && k.canEncrypt() && (k.ownerTrust() == GpgME::Key::Ultimate)) {
170 ctx->endKeyListing();
173 std::for_each(keys.begin(), keys.end(), AddKeyToCombo(ui._gpgKey));
175 userHasGpgKeys = keys.size() > 0;
176 if (userHasGpgKeys) {
177 ui.stackedWidget->setCurrentWidget(ui._pageWhenHasKeys);
179 ui.stackedWidget->setCurrentWidget(ui._pageNoKeys);
185 int nextId()
const override
187 return static_cast<KWalletWizard *
>(
wizard())->wizardType() == KWalletWizard::Basic ? -1 : KWalletWizard::PageOptionsId;
192 return userHasGpgKeys;
195 bool hasGpgKeys()
const
197 return userHasGpgKeys;
200 GpgME::Key gpgKey()
const
202 QVariant varKey = ui._gpgKey->itemData(
field(QStringLiteral(
"gpgKey")).toInt());
203 return varKey.
value<GpgME::Key>();
207 Ui::KWalletWizardPageGpgKey ui;
220 registerField(QStringLiteral(
"closeWhenIdle"), ui._closeIdle);
221 registerField(QStringLiteral(
"networkWallet"), ui._networkWallet);
225 Ui::KWalletWizardPageOptions ui;
239 Ui::KWalletWizardPageExplanation ui;
242KWalletWizard::KWalletWizard(
QWidget *parent)
245 setOption(HaveFinishButtonOnEarlyPages);
247 m_pageIntro =
new PageIntro(
this);
248 setPage(PageIntroId, m_pageIntro);
249 m_pagePasswd =
new PagePassword(
this);
250 setPage(PagePasswordId, m_pagePasswd);
252 m_pageGpgKey =
new PageGpgKey(
this);
253 setPage(PageGpgKeyId, m_pageGpgKey);
255 setPage(PageOptionsId,
new PageOptions(
this));
256 setPage(PageExplanationId,
new PageExplanation(
this));
261void KWalletWizard::passwordPageUpdate()
263 bool complete =
true;
264 if (
field(QStringLiteral(
"useWallet")).toBool()) {
266 if (
field(QStringLiteral(
"useBlowfish")).toBool()) {
272 m_pagePasswd->setMatchLabelText(
i18n(
"<qt>Password is empty. <b>(WARNING: Insecure)</b></qt>"));
274 m_pagePasswd->setMatchLabelText(
i18n(
"Passwords match."));
277 m_pagePasswd->setMatchLabelText(
i18n(
"Passwords do not match."));
288 m_pagePasswd->setMatchLabelText(
QString());
293KWalletWizard::WizardType KWalletWizard::wizardType()
const
295 return (KWalletWizard::WizardType)m_pageIntro->bg->
checkedId();
298void KWalletWizard::initializePage(
int id)
301 case PagePasswordId: {
302 bool islast = m_pageIntro->bg->
checkedId() == 0;
311GpgME::Key KWalletWizard::gpgKey()
const
313 return m_pageGpgKey->gpgKey();
317#include "moc_kwalletwizard.cpp"
QString i18n(const char *text, const TYPE &arg...)
char * toString(const EngineQuery &query)
void error(QWidget *parent, const QString &text, const QString &title, const KGuiItem &buttonOk, Options options=Notify)
KIOCORE_EXPORT QStringList list(const QString &fileClass)
void addItem(const QIcon &icon, const QString &text, const QVariant &userData)
QIcon fromTheme(const QString &name)
void textChanged(const QString &text)
QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, Functor functor)
QObject * parent() const const
QString arg(Args &&... args) const const
void setValue(QVariant &&value)
QVariant field(const QString &name) const const
QVariant field(const QString &name) const const
virtual bool isComplete() const const
virtual int nextId() const const
void registerField(const QString &name, QWidget *widget, const char *property, const char *changedSignal)
void setFinalPage(bool finalPage)
QWizard * wizard() const const