Commit a17a75ad authored by Laurent Montel's avatar Laurent Montel 😁
Browse files

Continue to implement plugin support

parent 037e0af2
......@@ -26,6 +26,7 @@ set(mailtransport_widgets_srcs
widgets/transportlistview.cpp
widgets/transportmanagementwidget.cpp
widgets/transportconfigdialog.cpp
widgets/addtransportdialogng.cpp
)
set(mailtransport_plugins_srcs
......@@ -175,6 +176,7 @@ install(FILES
if(BUILD_TESTING)
add_subdirectory(tests)
add_subdirectory(autotests)
add_subdirectory(plugins/tests)
endif()
......
......@@ -278,6 +278,12 @@ bool TransportManager::showTransportCreationDialog(QWidget *parent, ShowConditio
return accepted;
}
bool TransportManager::configureTransport(const QString &identifier, Transport *transport, QWidget *parent)
{
//FIXME
return false;
}
bool TransportManager::configureTransport(Transport *transport, QWidget *parent)
{
QPointer<TransportConfigDialog> transportConfigDialog
......
......@@ -187,6 +187,8 @@ public:
*/
bool configureTransport(Transport *transport, QWidget *parent);
bool configureTransport(const QString &identifier, Transport *transport, QWidget *parent);
public Q_SLOTS:
/**
Returns true if there are no mail transports at all.
......
......@@ -69,3 +69,8 @@ QString TransportType::description() const
{
return d->mDescription;
}
QString TransportType::identifier() const
{
return d->mIdentifier;
}
......@@ -98,6 +98,11 @@ public:
*/
QString description() const;
/**
* Returns a plugin identifier
*/
QString identifier() const;
private:
//@cond PRIVATE
class Private;
......
......@@ -41,11 +41,13 @@ public:
mType = other.mType;
mName = other.mName;
mDescription = other.mDescription;
mIdentifier = other.mIdentifier;
}
int mType;
QString mName;
QString mDescription;
QString mIdentifier;
};
} // namespace MailTransport
......
/*
Copyright (c) 2009 Constantin Berzan <exit3219@gmail.com>
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 "addtransportdialogng.h"
#include "transport.h"
#include "transportconfigwidget.h"
#include "transportmanager.h"
#include "transporttype.h"
#include "ui_addtransportdialog.h"
#include "mailtransport_debug.h"
#include <QDialogButtonBox>
#include <QPushButton>
using namespace MailTransport;
/**
@internal
*/
class AddTransportDialogNG::Private
{
public:
Private(AddTransportDialogNG *qq)
: q(qq)
, okButton(nullptr)
{
}
QString selectedType() const;
/**
Enables the OK button if a type is selected.
*/
void updateOkButton(); // slot
void doubleClicked(); //slot
void writeConfig();
void readConfig();
AddTransportDialogNG *const q;
QPushButton *okButton;
::Ui::AddTransportDialog ui;
};
void AddTransportDialogNG::Private::writeConfig()
{
KConfigGroup group(KSharedConfig::openConfig(), "AddTransportDialog");
group.writeEntry("Size", q->size());
}
void AddTransportDialogNG::Private::readConfig()
{
KConfigGroup group(KSharedConfig::openConfig(), "AddTransportDialog");
const QSize sizeDialog = group.readEntry("Size", QSize(300, TransportManager::self()->types().size() > 1 ? 200 : 80));
if (sizeDialog.isValid()) {
q->resize(sizeDialog);
}
}
QString AddTransportDialogNG::Private::selectedType() const
{
QList<QTreeWidgetItem *> sel = ui.typeListView->selectedItems();
if (!sel.empty()) {
return sel.first()->data(0, Qt::UserRole).toString();
}
return {};
}
void AddTransportDialogNG::Private::doubleClicked()
{
if (!selectedType().isEmpty() && !ui.name->text().trimmed().isEmpty()) {
q->accept();
}
}
void AddTransportDialogNG::Private::updateOkButton()
{
// Make sure a type is selected before allowing the user to continue.
okButton->setEnabled(!selectedType().isEmpty() && !ui.name->text().trimmed().isEmpty());
}
AddTransportDialogNG::AddTransportDialogNG(QWidget *parent)
: QDialog(parent)
, d(new Private(this))
{
// Setup UI.
{
QVBoxLayout *mainLayout = new QVBoxLayout(this);
QWidget *widget = new QWidget(this);
d->ui.setupUi(widget);
mainLayout->addWidget(widget);
setWindowTitle(i18n("Create Outgoing Account"));
QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, this);
d->okButton = buttonBox->button(QDialogButtonBox::Ok);
d->okButton->setText(i18nc("create and configure a mail transport", "Create and Configure"));
d->okButton->setEnabled(false);
d->okButton->setShortcut(Qt::CTRL | Qt::Key_Return);
mainLayout->addWidget(buttonBox);
connect(buttonBox, &QDialogButtonBox::accepted, this, &AddTransportDialogNG::accept);
connect(buttonBox, &QDialogButtonBox::rejected, this, &AddTransportDialogNG::reject);
}
// Populate type list.
const auto transportTypes = TransportManager::self()->types();
for (const TransportType &type : transportTypes) {
QTreeWidgetItem *treeItem = new QTreeWidgetItem(d->ui.typeListView);
treeItem->setText(0, type.name());
treeItem->setText(1, type.description());
treeItem->setData(0, Qt::UserRole, type.identifier()); // the transport type
//PORT ME
/*
if (type.type() == TransportBase::EnumType::SMTP) {
treeItem->setSelected(true); // select SMTP by default
}
*/
}
d->ui.typeListView->resizeColumnToContents(0);
// if we only have one type, don't bother the user with this
if (d->ui.typeListView->invisibleRootItem()->childCount() == 1) {
d->ui.descLabel->hide();
d->ui.typeListView->hide();
}
updateGeometry();
d->ui.typeListView->setFocus();
// Connect user input.
connect(d->ui.typeListView, SIGNAL(itemClicked(QTreeWidgetItem *,int)),
this, SLOT(updateOkButton()));
connect(d->ui.typeListView, SIGNAL(itemSelectionChanged()),
this, SLOT(updateOkButton()));
connect(d->ui.typeListView, SIGNAL(itemDoubleClicked(QTreeWidgetItem *,int)),
this, SLOT(doubleClicked()));
connect(d->ui.name, SIGNAL(textChanged(QString)),
this, SLOT(updateOkButton()));
d->readConfig();
}
AddTransportDialogNG::~AddTransportDialogNG()
{
d->writeConfig();
delete d;
}
void AddTransportDialogNG::accept()
{
if (d->selectedType().isEmpty()) {
return;
}
// Create a new transport and configure it.
Transport *transport = TransportManager::self()->createTransport();
transport->setName(d->ui.name->text().trimmed());
transport->forceUniqueName();
if (TransportManager::self()->configureTransport(d->selectedType(), transport, this)) {
// The user clicked OK and the transport settings were saved.
TransportManager::self()->addTransport(transport);
if (d->ui.setDefault->isChecked()) {
TransportManager::self()->setDefaultTransport(transport->id());
}
QDialog::accept();
}
}
#include "moc_addtransportdialogng.cpp"
/*
Copyright (c) 2009 Constantin Berzan <exit3219@gmail.com>
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_AddTransportDialogNG_H
#define MAILTRANSPORT_AddTransportDialogNG_H
#include <QDialog>
namespace MailTransport {
/**
@internal
A dialog for creating a new transport. It asks the user for the transport
type and name, and then proceeds to configure the new transport.
To create a new transport from applications, use
TransportManager::showNewTransportDialog().
@author Constantin Berzan <exit3219@gmail.com>
@since 4.4
*/
class AddTransportDialogNG : public QDialog
{
Q_OBJECT
public:
/**
Creates a new AddTransportDialogNG.
*/
explicit AddTransportDialogNG(QWidget *parent = nullptr);
/**
Destroys the AddTransportDialogNG.
*/
virtual ~AddTransportDialogNG();
/* reimpl */
void accept() override;
private:
class Private;
Private *const d;
Q_PRIVATE_SLOT(d, void updateOkButton())
Q_PRIVATE_SLOT(d, void doubleClicked())
};
} // namespace MailTransport
#endif
set(mailtransport_akonadiplugin_SRCS
akonadimailtransportplugin.cpp
)
akonadimailtransportplugin.cpp
)
kcoreaddons_add_plugin(mailtransport_akonadiplugin JSON akonadimailtransport.json SOURCES
${mailtransport_akonadiplugin_SRCS} INSTALL_NAMESPACE mailtransport)
target_link_libraries(mailtransport_akonadiplugin
KF5::MailTransport KF5::CoreAddons
)
KF5::MailTransport
KF5::CoreAddons
KF5::AkonadiCore
)
......@@ -19,9 +19,12 @@
#include "akonadimailtransportplugin.h"
#include <kpluginfactory.h>
#include <AkonadiCore/AgentManager>
#include <MailTransport/TransportAbstractPlugin>
using namespace Akonadi;
K_PLUGIN_FACTORY_WITH_JSON(AkonadiMailTransportPluginFactory, "akonadimailtransport.json", registerPlugin<AkonadiMailTransportPlugin>();
)
)
AkonadiMailTransportPlugin::AkonadiMailTransportPlugin(QObject *parent, const QList<QVariant> &)
: MailTransport::TransportAbstractPlugin(parent)
......@@ -40,14 +43,35 @@ void AkonadiMailTransportPlugin::cleanUp(const QString &identifier)
QVector<MailTransport::TransportAbstractPluginInfo> AkonadiMailTransportPlugin::names() const
{
//TODO
return {};
QVector<MailTransport::TransportAbstractPluginInfo> lst;
for (const AgentType &atype : AgentManager::self()->types()) {
// TODO probably the string "MailTransport" should be #defined somewhere
// and used like that in the resources (?)
if ( atype.capabilities().contains( QStringLiteral( "MailTransport" ) ) ) {
MailTransport::TransportAbstractPluginInfo info;
info.name = atype.name();
info.description = atype.description();
info.identifier = atype.identifier();
lst << info;
/*
TransportType type;
type.d->mType = Transport::EnumType::Akonadi;
type.d->mAgentType = atype;
type.d->mName = atype.name();
type.d->mDescription = atype.description();
types << type;
kDebug() << "Found Akonadi type" << atype.name();
*/
}
}
return lst;
}
bool AkonadiMailTransportPlugin::configureTransport(const QString &identifier, MailTransport::Transport *transport, QWidget *parent)
{
//TODO
return {};
return false;
}
#include "akonadimailtransportplugin.moc"
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