Fix Bug 362152 - Font selection is not honored
[kdepim.git] / sieveeditor / serversievesettings.cpp
blob5c2046ddd7afd64b7c06cfc403813a1fd2b9e5d3
1 /*
2 Copyright (c) 2013-2016 Montel Laurent <montel@kde.org>
4 This library is free software; you can redistribute it and/or modify it
5 under the terms of the GNU Library General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or (at your
7 option) any later version.
9 This library is distributed in the hope that it will be useful, but WITHOUT
10 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
12 License for more details.
14 You should have received a copy of the GNU Library General Public License
15 along with this library; see the file COPYING.LIB. If not, write to the
16 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17 02110-1301, USA.
21 #include "serversievesettings.h"
22 #include "ui_serversievesettings.h"
23 #include <MailTransport/mailtransport/transport.h>
25 #include <KLocalizedString>
26 #include "sieveeditor_debug.h"
28 /** static helper functions **/
29 static QString authenticationModeString(MailTransport::Transport::EnumAuthenticationType::type mode)
31 switch (mode) {
32 case MailTransport::Transport::EnumAuthenticationType::LOGIN:
33 return QStringLiteral("LOGIN");
34 case MailTransport::Transport::EnumAuthenticationType::PLAIN:
35 return QStringLiteral("PLAIN");
36 case MailTransport::Transport::EnumAuthenticationType::CRAM_MD5:
37 return QStringLiteral("CRAM-MD5");
38 case MailTransport::Transport::EnumAuthenticationType::DIGEST_MD5:
39 return QStringLiteral("DIGEST-MD5");
40 case MailTransport::Transport::EnumAuthenticationType::GSSAPI:
41 return QStringLiteral("GSSAPI");
42 case MailTransport::Transport::EnumAuthenticationType::NTLM:
43 return QStringLiteral("NTLM");
44 case MailTransport::Transport::EnumAuthenticationType::CLEAR:
45 return i18nc("Authentication method", "Clear text");
46 case MailTransport::Transport::EnumAuthenticationType::ANONYMOUS:
47 return i18nc("Authentication method", "Anonymous");
48 default:
49 break;
51 return QString();
54 static void addAuthenticationItem(QComboBox *authCombo, MailTransport::Transport::EnumAuthenticationType::type authtype)
56 //qCDebug(SIEVEEDITOR_LOG) << "adding auth item " << authenticationModeString( authtype );
57 authCombo->addItem(authenticationModeString(authtype), QVariant(authtype));
60 static MailTransport::Transport::EnumAuthenticationType::type getCurrentAuthMode(QComboBox *authCombo)
62 MailTransport::Transport::EnumAuthenticationType::type authtype = (MailTransport::Transport::EnumAuthenticationType::type) authCombo->itemData(authCombo->currentIndex()).toInt();
63 //qCDebug(SIEVEEDITOR_LOG) << "current auth mode: " << authenticationModeString( authtype );
64 return authtype;
67 static void setCurrentAuthMode(QComboBox *authCombo, MailTransport::Transport::EnumAuthenticationType::type authtype)
69 //qCDebug(SIEVEEDITOR_LOG) << "setting authcombo: " << authenticationModeString( authtype );
70 int index = authCombo->findData(authtype);
71 if (index == -1) {
72 qCWarning(SIEVEEDITOR_LOG) << "desired authmode not in the combo";
74 //qCDebug(SIEVEEDITOR_LOG) << "found corresponding index: " << index << "with data" << authenticationModeString( (MailTransport::Transport::EnumAuthenticationType::type) authCombo->itemData( index ).toInt() );
75 authCombo->setCurrentIndex(index);
76 MailTransport::Transport::EnumAuthenticationType::type t = (MailTransport::Transport::EnumAuthenticationType::type) authCombo->itemData(authCombo->currentIndex()).toInt();
77 //qCDebug(SIEVEEDITOR_LOG) << "selected auth mode:" << authenticationModeString( t );
78 Q_ASSERT(t == authtype);
81 ServerSieveSettings::ServerSieveSettings(QWidget *parent) :
82 QWidget(parent),
83 ui(new Ui::ServerSieveSettings)
85 ui->setupUi(this);
86 populateDefaultAuthenticationOptions();
87 connect(ui->serverName, &QLineEdit::textChanged, this, &ServerSieveSettings::slotUserServerNameChanged);
88 connect(ui->userName, &QLineEdit::textChanged, this, &ServerSieveSettings::slotUserServerNameChanged);
91 ServerSieveSettings::~ServerSieveSettings()
93 delete ui;
96 void ServerSieveSettings::populateDefaultAuthenticationOptions()
98 ui->authenticationCombo->clear();
99 addAuthenticationItem(ui->authenticationCombo, MailTransport::Transport::EnumAuthenticationType::CLEAR);
100 addAuthenticationItem(ui->authenticationCombo, MailTransport::Transport::EnumAuthenticationType::LOGIN);
101 addAuthenticationItem(ui->authenticationCombo, MailTransport::Transport::EnumAuthenticationType::PLAIN);
102 addAuthenticationItem(ui->authenticationCombo, MailTransport::Transport::EnumAuthenticationType::CRAM_MD5);
103 addAuthenticationItem(ui->authenticationCombo, MailTransport::Transport::EnumAuthenticationType::DIGEST_MD5);
104 addAuthenticationItem(ui->authenticationCombo, MailTransport::Transport::EnumAuthenticationType::NTLM);
105 addAuthenticationItem(ui->authenticationCombo, MailTransport::Transport::EnumAuthenticationType::GSSAPI);
106 addAuthenticationItem(ui->authenticationCombo, MailTransport::Transport::EnumAuthenticationType::ANONYMOUS);
109 void ServerSieveSettings::slotUserServerNameChanged()
111 Q_EMIT enableOkButton(!ui->userName->text().trimmed().isEmpty() && !ui->serverName->text().trimmed().isEmpty());
114 QString ServerSieveSettings::serverName() const
116 return ui->serverName->text().trimmed();
119 void ServerSieveSettings::setServerName(const QString &name)
121 ui->serverName->setText(name);
124 int ServerSieveSettings::port() const
126 return ui->port->value();
129 void ServerSieveSettings::setPort(int value)
131 ui->port->setValue(value);
134 QString ServerSieveSettings::userName() const
136 return ui->userName->text().trimmed();
139 void ServerSieveSettings::setUserName(const QString &name)
141 ui->userName->setText(name);
144 QString ServerSieveSettings::password() const
146 return ui->password->text();
149 void ServerSieveSettings::setPassword(const QString &pass)
151 ui->password->setText(pass);
154 void ServerSieveSettings::setServerSieveConfig(const SieveEditorUtil::SieveServerConfig &conf)
156 setPassword(conf.password);
157 setPort(conf.port);
158 setServerName(conf.serverName);
159 setUserName(conf.userName);
160 setCurrentAuthMode(ui->authenticationCombo, conf.authenticationType);
163 SieveEditorUtil::SieveServerConfig ServerSieveSettings::serverSieveConfig() const
165 SieveEditorUtil::SieveServerConfig conf;
166 conf.password = password();
167 conf.port = port();
168 conf.serverName = serverName();
169 conf.userName = userName();
170 const MailTransport::Transport::EnumAuthenticationType::type authtype = getCurrentAuthMode(ui->authenticationCombo);
171 conf.authenticationType = authtype;
172 return conf;