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
|
/* This file is part of the KDE project
Copyright (C) 2008 Urs Wolfer <uwolfer @ kde.org>
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
*/
#include "dlgwebinterface.h"
#include "settings.h"
#include <KMessageBox>
#include <kwallet.h>
DlgWebinterface::DlgWebinterface(KDialog *parent)
: QWidget(parent),
m_wallet(0)
{
setupUi(this);
readConfig();
connect(parent, SIGNAL(accepted()), SLOT(saveSettings()));
connect(webinterfacePwd, SIGNAL(textChanged(QString)), SIGNAL(changed()));
}
DlgWebinterface::~DlgWebinterface()
{
delete m_wallet;
}
void DlgWebinterface::readConfig()
{
if (Settings::webinterfaceEnabled()) {
m_wallet = KWallet::Wallet::openWallet(KWallet::Wallet::LocalWallet(),
winId(),///Use MainWindow?
KWallet::Wallet::Asynchronous);
if (m_wallet) {
connect(m_wallet, SIGNAL(walletOpened(bool)), SLOT(walletOpened(bool)));
} else {
KMessageBox::error(0, i18n("Could not open KWallet"));
}
}
}
void DlgWebinterface::walletOpened(bool opened)
{
if (opened &&
(m_wallet->hasFolder("KGet") ||
m_wallet->createFolder("KGet")) &&
m_wallet->setFolder("KGet")) {
QString pwd;
m_wallet->readPassword("Webinterface", pwd);
webinterfacePwd->setText(pwd);
} else {
KMessageBox::error(0, i18n("Could not open KWallet"));
}
}
void DlgWebinterface::saveSettings()
{
if (m_wallet) {
m_wallet->writePassword("Webinterface", webinterfacePwd->text());
}
emit saved();
}
#include "dlgwebinterface.moc"
|