1 /* Copyright (C) 2013 Pali Rohár <pali.rohar@gmail.com>
3 This file is part of the Trojita Qt IMAP e-mail client,
4 http://trojita.flaska.net/
6 This program is free software; you can redistribute it and/or
7 modify it under the terms of the GNU General Public License as
8 published by the Free Software Foundation; either version 2 of
9 the License or (at your option) version 3 or any later version
10 accepted by the membership of KDE e.V. (or its successor approved
11 by the membership of KDE e.V.), which shall act as a proxy
12 defined in Section 14 of version 3 of the license.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program. If not, see <http://www.gnu.org/licenses/>.
26 #include "ClearTextPassword.h"
30 static QString imapPassKey
, smtpPassKey
;
32 QString
Settings::imapPassKey
= QStringLiteral("imap.auth.pass");
33 QString
Settings::smtpPassKey
= QStringLiteral("msa.smtp.auth.pass");
35 ClearTextPasswordJob::ClearTextPasswordJob(const QString
&accountId
, const QString
&accountType
, const QString
&password
,
36 enum Type type
, QObject
*parent
, QSettings
*settings
) :
37 PasswordJob(parent
), m_accountId(accountId
), m_accountType(accountType
), m_password(password
), m_type(type
), m_settings(settings
)
41 void ClearTextPasswordJob::doStart()
46 if (m_accountType
== QLatin1String("imap")) {
47 password
= m_settings
->value(Settings::imapPassKey
);
48 } else if (m_accountType
== QLatin1String("smtp")) {
49 password
= m_settings
->value(Settings::smtpPassKey
);
51 emit
error(PasswordJob::UnknownError
, tr("This plugin only supports storing of IMAP and SMTP passwords"));
54 if (password
.type() != QVariant::String
|| password
.toString().isEmpty()) {
55 emit
error(PasswordJob::NoSuchPassword
, QString());
57 emit
passwordAvailable(password
.toString());
62 if (m_accountType
== QLatin1String("imap")) {
63 m_settings
->setValue(Settings::imapPassKey
, m_password
);
64 } else if (m_accountType
== QLatin1String("smtp")) {
65 m_settings
->setValue(Settings::smtpPassKey
, m_password
);
67 emit
error(PasswordJob::UnknownError
, tr("This plugin only supports storing of IMAP and SMTP passwords"));
70 emit
passwordStored();
74 if (m_accountType
== QLatin1String("imap")) {
75 m_settings
->remove(Settings::imapPassKey
);
76 } else if (m_accountType
== QLatin1String("smtp")) {
77 m_settings
->remove(Settings::smtpPassKey
);
79 emit
error(PasswordJob::UnknownError
, tr("This plugin only supports storing of IMAP and SMTP passwords"));
82 emit
passwordDeleted();
87 void ClearTextPasswordJob::doStop()
89 emit
error(PasswordJob::Stopped
, QString());
92 ClearTextPassword::ClearTextPassword(QObject
*parent
, QSettings
*settings
) : PasswordPlugin(parent
), m_settings(settings
)
96 PasswordPlugin::Features
ClearTextPassword::features() const
101 PasswordJob
*ClearTextPassword::requestPassword(const QString
&accountId
, const QString
&accountType
)
103 return new ClearTextPasswordJob(accountId
, accountType
, QString(), ClearTextPasswordJob::Request
, this, m_settings
);
106 PasswordJob
*ClearTextPassword::storePassword(const QString
&accountId
, const QString
&accountType
, const QString
&password
)
108 return new ClearTextPasswordJob(accountId
, accountType
, password
, ClearTextPasswordJob::Store
, this, m_settings
);
111 PasswordJob
*ClearTextPassword::deletePassword(const QString
&accountId
, const QString
&accountType
)
113 return new ClearTextPasswordJob(accountId
, accountType
, QString(), ClearTextPasswordJob::Delete
, this, m_settings
);
116 QString
trojita_plugin_ClearTextPasswordPlugin::name() const
118 return QStringLiteral("cleartextpassword");
121 QString
trojita_plugin_ClearTextPasswordPlugin::description() const
123 return trUtf8("Trojitá's settings");
126 Plugins::PasswordPlugin
*trojita_plugin_ClearTextPasswordPlugin::create(QObject
*parent
, QSettings
*settings
)
129 return new ClearTextPassword(parent
, settings
);
132 // vim: set et ts=4 sts=4 sw=4