Commit 4656c39c authored by Laurent Montel's avatar Laurent Montel 😁

Add config dialog

parent 89ff3433
set(mailtransport_smtpplugin_SRCS
smtpmailtransportplugin.cpp
smtpconfigdialog.cpp
)
kcoreaddons_add_plugin(mailtransport_smtpplugin JSON smtpmailtransport.json SOURCES
${mailtransport_smtpplugin_SRCS} INSTALL_NAMESPACE mailtransport)
target_link_libraries(mailtransport_smtpplugin
KF5::MailTransport KF5::CoreAddons KF5::I18n
KF5::MailTransport KF5::CoreAddons KF5::I18n Qt5::Widgets KF5::ConfigWidgets
)
/*
Copyright (c) 2017 Laurent Montel <montel@kde.org>
This library is free software; you can redistribute it and/or modify it
under the terms of the GNU Library General Public License as published by
the Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
This library 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 Library General Public
License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301, USA.
*/
#include "smtpconfigdialog.h"
#include "transport.h"
//#include "smtpconfigwidget.h"
#include "transportmanager.h"
#include "transporttype.h"
#include "smtp/smtpconfigwidget.h"
#include <QDialogButtonBox>
#include <QLabel>
#include <QString>
#include <QVBoxLayout>
#include <QPushButton>
#include "mailtransport_debug.h"
#include <KLocalizedString>
using namespace MailTransport;
class MailTransport::SmtpConfigDialog::Private
{
public:
Private(SmtpConfigDialog *qq)
: transport(nullptr)
, configWidget(nullptr)
, q(qq)
, okButton(nullptr)
{
}
Transport *transport;
SMTPConfigWidget *configWidget;
SmtpConfigDialog *q;
QPushButton *okButton;
void okClicked();
void slotTextChanged(const QString &text);
void slotEnabledOkButton(bool);
};
void SmtpConfigDialog::Private::slotEnabledOkButton(bool b)
{
okButton->setEnabled(b);
}
void SmtpConfigDialog::Private::okClicked()
{
configWidget->apply();
transport->save();
}
void SmtpConfigDialog::Private::slotTextChanged(const QString &text)
{
okButton->setEnabled(!text.isEmpty());
}
SmtpConfigDialog::SmtpConfigDialog(Transport *transport, QWidget *parent)
: QDialog(parent)
, d(new Private(this))
{
Q_ASSERT(transport);
d->transport = transport;
QVBoxLayout *mainLayout = new QVBoxLayout(this);
bool pathIsEmpty = false;
d->configWidget = new SMTPConfigWidget(transport, this);
mainLayout->addWidget(d->configWidget);
QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, this);
d->okButton = buttonBox->button(QDialogButtonBox::Ok);
d->okButton->setEnabled(false);
d->okButton->setShortcut(Qt::CTRL | Qt::Key_Return);
mainLayout->addWidget(buttonBox);
connect(d->okButton, SIGNAL(clicked()), this, SLOT(okClicked()));
connect(buttonBox, &QDialogButtonBox::accepted, this, &SmtpConfigDialog::accept);
connect(buttonBox, &QDialogButtonBox::rejected, this, &SmtpConfigDialog::reject);
d->okButton->setEnabled(!pathIsEmpty);
}
SmtpConfigDialog::~SmtpConfigDialog()
{
delete d;
}
#include "moc_smtpconfigdialog.cpp"
/*
Copyright (c) 2017 Laurent Montel <montel@kde.org>
This library is free software; you can redistribute it and/or modify it
under the terms of the GNU Library General Public License as published by
the Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
This library 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 Library General Public
License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301, USA.
*/
#ifndef MAILTRANSPORT_SMTPTRANSPORTCONFIGDIALOG_H
#define MAILTRANSPORT_SMTPTRANSPORTCONFIGDIALOG_H
#include <QDialog>
namespace MailTransport {
class Transport;
class SmtpConfigDialog : public QDialog
{
Q_OBJECT
public:
explicit SmtpConfigDialog(Transport *transport, QWidget *parent = nullptr);
virtual ~SmtpConfigDialog();
private:
class Private;
Private *const d;
Q_PRIVATE_SLOT(d, void okClicked())
Q_PRIVATE_SLOT(d, void slotTextChanged(const QString &))
Q_PRIVATE_SLOT(d, void slotEnabledOkButton(bool))
};
} // namespace MailTransport
#endif
......@@ -18,6 +18,7 @@
*/
#include "smtpmailtransportplugin.h"
#include "smtpconfigdialog.h"
#include <kpluginfactory.h>
#include <KLocalizedString>
......@@ -45,8 +46,13 @@ QVector<MailTransport::TransportAbstractPluginInfo> SMTPMailTransportPlugin::nam
bool SMTPMailTransportPlugin::configureTransport(const QString &identifier, MailTransport::Transport *transport, QWidget *parent)
{
//TODO FIXME
return false;
Q_UNUSED(identifier);
QPointer<MailTransport::SmtpConfigDialog> transportConfigDialog
= new MailTransport::SmtpConfigDialog(transport, parent);
transportConfigDialog->setWindowTitle(i18n("Configure account"));
bool okClicked = (transportConfigDialog->exec() == QDialog::Accepted);
delete transportConfigDialog;
return okClicked;
}
void SMTPMailTransportPlugin::cleanUp(const QString &identifier)
......
......@@ -27,7 +27,7 @@
#define MAILTRANSPORT_SMTPCONFIGWIDGET_H
#include "widgets/transportconfigwidget.h"
#include "mailtransport_export.h"
namespace MailTransport {
class Transport;
......@@ -40,7 +40,7 @@ class SMTPConfigWidgetPrivate;
@internal
Configuration widget for a SMTP transport.
*/
class SMTPConfigWidget : public TransportConfigWidget
class MAILTRANSPORT_EXPORT SMTPConfigWidget : public TransportConfigWidget
{
Q_OBJECT
......
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