Commit 6bad7106 authored by Laurent Montel's avatar Laurent Montel 😁

improve imapsettings here too

parent 7934d279
......@@ -45,7 +45,7 @@ set(KDEPIM_LIB_VERSION "${KDEPIM_VERSION_NUMBER}")
set(KDEPIM_LIB_SOVERSION "5")
set(MESSAGELIB_LIB_VERSION_LIB "5.4.40")
set(LIBKSIEVE_LIB_VERSION_LIB "5.4.46")
set(LIBKSIEVE_LIB_VERSION_LIB "5.4.47")
set(PIMCOMMON_LIB_VERSION_LIB "5.4.40")
set(QT_REQUIRED_VERSION "5.6.0")
......
......@@ -20,8 +20,9 @@
#include "serversievesettings.h"
#include "ui_serversievesettings.h"
#include <MailTransport/mailtransport/transport.h>
#include <MailTransport/ServerTest>
#include <KLocalizedString>
#include <KMessageBox>
#include "sieveeditor_debug.h"
/** static helper functions **/
......@@ -79,10 +80,17 @@ static void setCurrentAuthMode(QComboBox *authCombo, MailTransport::Transport::E
ServerSieveSettings::ServerSieveSettings(QWidget *parent) :
QWidget(parent),
ui(new Ui::ServerSieveSettings)
ui(new Ui::ServerSieveSettings),
mServerTest(Q_NULLPTR)
{
ui->setupUi(this);
ui->serversievelabel->setMinimumSize(ui->serversievelabel->sizeHint());
ui->testInfo->clear();
ui->testInfo->hide();
ui->testProgress->hide();
connect(ui->testButton, &QPushButton::pressed, this, &ServerSieveSettings::slotTest);
populateDefaultAuthenticationOptions();
connect(ui->serverName, &QLineEdit::textChanged, this, &ServerSieveSettings::slotUserServerNameChanged);
connect(ui->userName, &QLineEdit::textChanged, this, &ServerSieveSettings::slotUserServerNameChanged);
......@@ -171,3 +179,97 @@ SieveEditorUtil::SieveServerConfig ServerSieveSettings::serverSieveConfig() cons
conf.account.setAuthenticationType(authtype);
return conf;
}
void ServerSieveSettings::slotTest()
{
//qCDebug(SIEVEEDITOR_LOG) << ui->imapServer->text();
ui->testButton->setEnabled(false);
ui->safeImap->setEnabled(false);
ui->authenticationCombo->setEnabled(false);
ui->testInfo->clear();
ui->testInfo->hide();
delete mServerTest;
mServerTest = new MailTransport::ServerTest(this);
#ifndef QT_NO_CURSOR
qApp->setOverrideCursor(Qt::BusyCursor);
#endif
const QString server = serverName();
const int portValue = ui->portSpin->value();
qCDebug(SIEVEEDITOR_LOG) << "server: " << server << "port: " << portValue;
mServerTest->setServer(server);
if (portValue != 143 && portValue != 993) {
mServerTest->setPort(MailTransport::Transport::EnumEncryption::None, portValue);
mServerTest->setPort(MailTransport::Transport::EnumEncryption::SSL, portValue);
}
mServerTest->setProtocol(QStringLiteral("imap"));
mServerTest->setProgressBar(ui->testProgress);
connect(mServerTest, &MailTransport::ServerTest::finished, this, &ServerSieveSettings::slotFinished);
mServerTest->start();
}
void ServerSieveSettings::slotFinished(const QList<int> &testResult)
{
qCDebug(SIEVEEDITOR_LOG) << testResult;
#ifndef QT_NO_CURSOR
qApp->restoreOverrideCursor();
#endif
using namespace MailTransport;
if (!mServerTest->isNormalPossible() && !mServerTest->isSecurePossible()) {
KMessageBox::sorry(this, i18n("Unable to connect to the server, please verify the server address."));
}
ui->testInfo->show();
ui->sslRadio->setEnabled(testResult.contains(Transport::EnumEncryption::SSL));
ui->tlsRadio->setEnabled(testResult.contains(Transport::EnumEncryption::TLS));
ui->noRadio->setEnabled(testResult.contains(Transport::EnumEncryption::None));
QString text;
if (testResult.contains(Transport::EnumEncryption::TLS)) {
ui->tlsRadio->setChecked(true);
text = i18n("<qt><b>TLS is supported and recommended.</b></qt>");
} else if (testResult.contains(Transport::EnumEncryption::SSL)) {
ui->sslRadio->setChecked(true);
text = i18n("<qt><b>SSL is supported and recommended.</b></qt>");
} else if (testResult.contains(Transport::EnumEncryption::None)) {
ui->noRadio->setChecked(true);
text = i18n("<qt><b>No security is supported. It is not "
"recommended to connect to this server.</b></qt>");
} else {
text = i18n("<qt><b>It is not possible to use this server.</b></qt>");
}
ui->testInfo->setText(text);
ui->testButton->setEnabled(true);
ui->safeImap->setEnabled(true);
ui->authenticationCombo->setEnabled(true);
//slotEncryptionRadioChanged();
//slotSafetyChanged();
}
void ServerSieveSettings::slotEncryptionRadioChanged()
{
#if 0
// TODO these really should be defined somewhere else
switch (ui->safeImapGroup->checkedId()) {
case KIMAP::LoginJob::Unencrypted:
case KIMAP::LoginJob::TlsV1:
m_ui->portSpin->setValue(143);
break;
case KIMAP::LoginJob::AnySslVersion:
m_ui->portSpin->setValue(993);
break;
default:
qFatal("Shouldn't happen");
}
#endif
}
......@@ -27,7 +27,9 @@ namespace Ui
{
class ServerSieveSettings;
}
namespace MailTransport {
class ServerTest;
}
class ServerSieveSettings : public QWidget
{
Q_OBJECT
......@@ -56,10 +58,14 @@ Q_SIGNALS:
private Q_SLOTS:
void slotUserServerNameChanged();
void slotTest();
void slotFinished(const QList<int> &testResult);
void slotEncryptionRadioChanged();
private:
void populateDefaultAuthenticationOptions();
Ui::ServerSieveSettings *ui;
MailTransport::ServerTest *mServerTest;
};
#endif // SERVERSIEVESETTINGS_H
......@@ -120,7 +120,7 @@ void SieveEditorMainWidget::slotScriptRenamed(const QUrl &oldUrl, const QUrl &ne
updateStackedWidget();
}
void SieveEditorMainWidget::slotCreateScriptPage(const QUrl &url, const QStringList &capabilities, bool isNewScript)
void SieveEditorMainWidget::slotCreateScriptPage(const QUrl &url, const QStringList &capabilities, bool isNewScript, const KSieveUi::SieveImapAccountSettings &sieveAccount)
{
QWidget *page = hasExistingPage(url);
if (page) {
......@@ -135,7 +135,7 @@ void SieveEditorMainWidget::slotCreateScriptPage(const QUrl &url, const QStringL
connect(editor, &SieveEditorPageWidget::copyAvailable, this, &SieveEditorMainWidget::copyAvailable);
connect(editor, &SieveEditorPageWidget::sieveEditorTabCurrentChanged, this, &SieveEditorMainWidget::sieveEditorTabCurrentChanged);
editor->setIsNewScript(isNewScript);
editor->loadScript(url, capabilities);
editor->loadScript(url, capabilities, sieveAccount);
mTabWidget->addTab(editor, url.fileName());
mTabWidget->setCurrentWidget(editor);
if (isNewScript) {
......
......@@ -101,7 +101,7 @@ Q_SIGNALS:
void sieveEditorTabCurrentChanged();
private Q_SLOTS:
void slotCreateScriptPage(const QUrl &url, const QStringList &capabilities, bool isNewScript);
void slotCreateScriptPage(const QUrl &url, const QStringList &capabilities, bool isNewScript, const KSieveUi::SieveImapAccountSettings &sieveAccount);
void slotScriptDeleted(const QUrl &url);
void slotScriptRenamed(const QUrl &oldUrl, const QUrl &newUrl);
void slotScriptModified(bool modified, SieveEditorPageWidget *page);
......
......@@ -61,6 +61,7 @@ bool SieveEditorManageSieveWidget::refreshList()
last->setText(0, i18n("(Disabled) %1", last->text(0)));
} else {
KManageSieve::SieveJob *job = KManageSieve::SieveJob::list(u);
job->setProperty("sieveaccount", QVariant::fromValue(conf.account));
connect(job, &KManageSieve::SieveJob::gotList, this, &SieveEditorManageSieveWidget::slotGotList);
mJobs.insert(job, last);
mUrls.insert(last, u);
......
......@@ -85,10 +85,11 @@ void SieveEditorPageWidget::setIsNewScript(bool isNewScript)
mIsNewScript = isNewScript;
}
void SieveEditorPageWidget::loadScript(const QUrl &url, const QStringList &capabilities)
void SieveEditorPageWidget::loadScript(const QUrl &url, const QStringList &capabilities, const KSieveUi::SieveImapAccountSettings &sieveAccount)
{
mCurrentURL = url;
mSieveEditorWidget->setSieveCapabilities(capabilities);
mSieveEditorWidget->setSieveImapAccountSettings(sieveAccount);
mSieveEditorWidget->setReadOnly(true);
mSieveEditorWidget->wordWrap(SieveEditorGlobalConfig::self()->wrapText());
KManageSieve::SieveJob *job = KManageSieve::SieveJob::get(url);
......
......@@ -38,7 +38,7 @@ public:
explicit SieveEditorPageWidget(QWidget *parent = Q_NULLPTR);
~SieveEditorPageWidget();
void loadScript(const QUrl &url, const QStringList &capabilities);
void loadScript(const QUrl &url, const QStringList &capabilities, const KSieveUi::SieveImapAccountSettings &sieveAccount);
QUrl currentUrl() const;
void setCurrentUrl(const QUrl &url);
void setIsNewScript(bool isNewScript);
......
......@@ -54,14 +54,14 @@ void SieveEditorScriptManagerWidget::slotUpdateButtons(QTreeWidgetItem *item)
Q_EMIT updateButtons(newScriptAction, editScriptAction, deleteScriptAction, desactivateScriptAction);
}
void SieveEditorScriptManagerWidget::slotEditScript(const QUrl &url, const QStringList &capabilities)
void SieveEditorScriptManagerWidget::slotEditScript(const QUrl &url, const QStringList &capabilities, const KSieveUi::SieveImapAccountSettings &sieveAccount)
{
Q_EMIT createScriptPage(url, capabilities, false);
Q_EMIT createScriptPage(url, capabilities, false, sieveAccount);
}
void SieveEditorScriptManagerWidget::slotNewScript(const QUrl &url, const QStringList &capabilities)
void SieveEditorScriptManagerWidget::slotNewScript(const QUrl &url, const QStringList &capabilities, const KSieveUi::SieveImapAccountSettings &sieveAccount)
{
Q_EMIT createScriptPage(url, capabilities, true);
Q_EMIT createScriptPage(url, capabilities, true, sieveAccount);
}
void SieveEditorScriptManagerWidget::slotCreateNewScript()
......
......@@ -25,6 +25,10 @@
class SieveEditorManageSieveWidget;
class QTreeWidgetItem;
namespace KSieveUi
{
class SieveImapAccountSettings;
}
class SieveEditorScriptManagerWidget : public QWidget
{
Q_OBJECT
......@@ -38,7 +42,7 @@ public:
void refreshList();
Q_SIGNALS:
void createScriptPage(const QUrl &url, const QStringList &capabilities, bool isNewScript);
void createScriptPage(const QUrl &url, const QStringList &capabilities, bool isNewScript, const KSieveUi::SieveImapAccountSettings &sieveAccount);
void updateButtons(bool newScriptAction, bool editScriptAction, bool deleteScriptAction, bool desactivateScriptAction);
void scriptDeleted(const QUrl &url);
void serverSieveFound(bool hasServerSieve);
......@@ -50,8 +54,8 @@ public Q_SLOTS:
void slotRefreshList();
private Q_SLOTS:
void slotNewScript(const QUrl &url, const QStringList &capabilities);
void slotEditScript(const QUrl &url, const QStringList &capabilities);
void slotNewScript(const QUrl &url, const QStringList &capabilities, const KSieveUi::SieveImapAccountSettings &sieveAccount);
void slotEditScript(const QUrl &url, const QStringList &capabilities, const KSieveUi::SieveImapAccountSettings &sieveAccount);
void slotUpdateButtons(QTreeWidgetItem *item);
private:
......
......@@ -23,7 +23,7 @@
#include <QString>
#include <QUrl>
#include <MailTransport/mailtransport/transport.h>
#include <KSieveUi/SieveAccount>
#include <KSieveUi/SieveImapAccountSettings>
namespace KWallet
{
class Wallet;
......@@ -38,7 +38,7 @@ struct SieveServerConfig {
}
QUrl url() const;
KSieveUi::SieveAccount account;
KSieveUi::SieveImapAccountSettings account;
bool enabled;
};
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment