This repository has been archived by the owner on Apr 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
SettingsDialog.cpp
145 lines (111 loc) · 3.89 KB
/
SettingsDialog.cpp
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
/* Copyright 2015, Martin Koller, kollix@aon.at
This file is part of airsyncDownload.
airsyncDownload 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 3 of the License, or
(at your option) any later version.
airsyncDownload is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with airsyncDownload. If not, see <http://www.gnu.org/licenses/>.
*/
#include <SettingsDialog.h>
#include <MailResource.h>
#include "settings.h"
#include <AkonadiCore/Collection>
#include <AkonadiCore/CollectionFetchJob>
#include <AkonadiAgentBase/ResourceSettings>
#include <Akonadi/KMime/SpecialMailCollections>
#include <Akonadi/KMime/SpecialMailCollectionsRequestJob>
#include <KWindowSystem>
#include <KUser>
#include <kwallet.h>
using namespace Akonadi;
using namespace KWallet;
//--------------------------------------------------------------------------------
SettingsDialog::SettingsDialog(MailResource *res, WId parentWindow)
: resource(res), wallet(0)
{
ui.setupUi(mainWidget());
KWindowSystem::setMainWindow(this, parentWindow);
//setWindowIcon(KIcon("network-server"));
setWindowTitle(i18n("AirSyncDownload Account Settings"));
setButtons(Ok|Cancel|User1);
setButtonText(KDialog::User1, i18n("Clear sync state"));
loadSettings();
}
//--------------------------------------------------------------------------------
SettingsDialog::~SettingsDialog()
{
delete wallet;
}
//--------------------------------------------------------------------------------
void SettingsDialog::loadSettings()
{
ui.nameEdit->setText(resource->name());
ui.nameEdit->setFocus();
ui.serverEdit->setText(Settings::self()->server());
ui.userNameEdit->setText(Settings::self()->userName().length() ? Settings::self()->userName() :
KUser().loginName());
wallet = Wallet::openWallet(Wallet::NetworkWallet(), winId());
if ( wallet )
{
if ( !wallet->hasFolder(Wallet::PasswordFolder()) )
wallet->createFolder(Wallet::PasswordFolder());
wallet->setFolder(Wallet::PasswordFolder()); // set current folder
QString password;
if ( wallet->readPassword(resource->identifier(), password) == 0 )
ui.passwordEdit->setText(password);
}
else
{
ui.passwordEdit->setClickMessage(i18n("Wallet disabled in system settings"));
}
connect(ui.showPasswordCheck, SIGNAL(toggled(bool)), this, SLOT(showPasswordChecked(bool)));
}
//--------------------------------------------------------------------------------
void SettingsDialog::showPasswordChecked(bool checked)
{
if ( checked )
ui.passwordEdit->setEchoMode(QLineEdit::Normal);
else
ui.passwordEdit->setEchoMode(QLineEdit::Password);
}
//--------------------------------------------------------------------------------
void SettingsDialog::slotButtonClicked(int button)
{
switch( button )
{
case Ok:
{
saveSettings();
accept();
break;
}
case Cancel:
{
reject();
break;
}
case User1:
{
Settings::self()->setSyncState("");
Settings::self()->writeConfig();
}
}
}
//--------------------------------------------------------------------------------
void SettingsDialog::saveSettings()
{
resource->setName(ui.nameEdit->text());
Settings::self()->setServer(ui.serverEdit->text().trimmed());
Settings::self()->setUserName(ui.userNameEdit->text().trimmed());
Settings::self()->writeConfig();
if ( wallet )
{
wallet->writePassword(resource->identifier(), ui.passwordEdit->text());
}
}
//--------------------------------------------------------------------------------