Members of the KDE Community are recommended to subscribe to the kde-community mailing list at https://mail.kde.org/mailman/listinfo/kde-community to allow them to participate in important discussions and receive other important announcements

Commit b7a68505 authored by Daniel Vrátil's avatar Daniel Vrátil 🤖

Port the POP3 resource to the new config API

parent 2b94de3e
add_definitions(-DTRANSLATION_DOMAIN=\"akonadi_pop3_resource\")
set(pop3_common_SRCS
settings.cpp
)
kconfig_add_kcfg_files(pop3_common_SRCS settingsbase.kcfgc)
ecm_qt_declare_logging_category(pop3_common_SRCS HEADER pop3resource_debug.h IDENTIFIER POP3RESOURCE_LOG CATEGORY_NAME org.kde.pim.pop3resource)
kcfg_generate_dbus_interface(${CMAKE_CURRENT_SOURCE_DIR}/settings.kcfg org.kde.Akonadi.POP3.Settings)
qt5_add_dbus_adaptor(pop3_common_SRCS
${CMAKE_CURRENT_BINARY_DIR}/org.kde.Akonadi.POP3.Settings.xml settings.h Settings
)
########### next target ###############
################################# Resource ####################################
set( pop3resource_SRCS
pop3resource.cpp
accountdialog.cpp
jobs.cpp
settings.cpp
${pop3_common_SRCS}
)
ecm_qt_declare_logging_category(pop3resource_SRCS HEADER pop3resource_debug.h IDENTIFIER POP3RESOURCE_LOG CATEGORY_NAME org.kde.pim.pop3resource)
install( FILES pop3resource.desktop DESTINATION "${KDE_INSTALL_DATAROOTDIR}/akonadi/agents" )
ki18n_wrap_ui( pop3resource_SRCS popsettings.ui)
kconfig_add_kcfg_files(pop3resource_SRCS settingsbase.kcfgc)
kcfg_generate_dbus_interface(${CMAKE_CURRENT_SOURCE_DIR}/settings.kcfg org.kde.Akonadi.POP3.Settings)
qt5_add_dbus_adaptor(pop3resource_SRCS
${CMAKE_CURRENT_BINARY_DIR}/org.kde.Akonadi.POP3.Settings.xml settings.h Settings
)
#add_executable(akonadi_pop3_resource RUN_UNINSTALLED ${pop3resource_SRCS})
add_executable(akonadi_pop3_resource ${pop3resource_SRCS})
......@@ -39,12 +38,7 @@ target_link_libraries( akonadi_pop3_resource
KF5::Mime
KF5::MailTransport
KF5::AkonadiAgentBase
KF5::AkonadiWidgets
KF5::I18n
KF5::TextWidgets
KF5::Completion
KF5::WidgetsAddons
KF5::WindowSystem
KF5::Notifications
Qt5::DBus
KF5::PimCommon
......@@ -58,3 +52,30 @@ add_subdirectory( wizard )
install(TARGETS akonadi_pop3_resource ${KDE_INSTALL_TARGETS_DEFAULT_ARGS})
install(FILES akonadi_pop3_resource.notifyrc DESTINATION ${KDE_INSTALL_KNOTIFY5RCDIR})
################################## Config plugin ##############################
set(pop3config_SRCS
pop3config.cpp
accountwidget.cpp
${pop3_common_SRCS}
)
ki18n_wrap_ui(pop3config_SRCS popsettings.ui)
kcoreaddons_add_plugin(pop3config
SOURCES ${pop3config_SRCS}
JSON "pop3config.json"
INSTALL_NAMESPACE "akonadi/config"
)
target_link_libraries(pop3config
KF5::AkonadiCore
KF5::TextWidgets
KF5::Completion
KF5::WidgetsAddons
KF5::I18n
KF5::MailTransport
KF5::AkonadiWidgets
KF5::AkonadiAgentBase
KF5::AkonadiMime
)
......@@ -20,8 +20,8 @@
*
*/
#ifndef _ACCOUNT_DIALOG_H_
#define _ACCOUNT_DIALOG_H_
#ifndef _ACCOUNT_WIDGET_H_
#define _ACCOUNT_WIDGET_H_
#include "ui_popsettings.h"
......@@ -35,13 +35,19 @@ class Wallet;
class POP3Resource;
class KJob;
class AccountDialog : public QDialog, private Ui::PopPage
class AccountWidget : public QWidget, private Ui::PopPage
{
Q_OBJECT
public:
AccountDialog(POP3Resource *parentResource, WId parentWindow);
~AccountDialog() override;
AccountWidget(const QString &identifier, QWidget *parent);
~AccountWidget() override;
void loadSettings();
void saveSettings();
Q_SIGNALS:
void okEnabled(bool enabled);
private Q_SLOTS:
void slotEnablePopInterval(bool state);
......@@ -65,21 +71,18 @@ private Q_SLOTS:
void slotAccepted();
private:
void setupWidgets();
void loadSettings();
void saveSettings();
void checkHighest(QButtonGroup *);
void enablePopFeatures();
void populateDefaultAuthenticationOptions();
private:
POP3Resource *mParentResource = nullptr;
QButtonGroup *encryptionButtonGroup = nullptr;
MailTransport::ServerTest *mServerTest = nullptr;
QRegExpValidator mValidator;
bool mServerTestFailed = false;
KWallet::Wallet *mWallet = nullptr;
QString mInitalPassword;
QPushButton *mOkButton = nullptr;
QString mIdentifier;
};
#endif
/* Copyright 2018 Daniel Vrátil <dvratil@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 ) version 3 or, at the discretion of KDE e.V.
( which shall act as a proxy as in section 14 of the GPLv3 ), 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 <AkonadiCore/AgentConfigurationBase>
#include "settings.h"
#include "accountwidget.h"
class Pop3Config : public Akonadi::AgentConfigurationBase
{
Q_OBJECT
public:
Pop3Config(KSharedConfigPtr config, QWidget *parent, const QVariantList &args)
: Akonadi::AgentConfigurationBase(config, parent, args)
, mSettings(new Settings(config))
, mWidget(new AccountWidget(identifier(), parent))
{
}
void load() override
{
Akonadi::AgentConfigurationBase::load();
mWidget->loadSettings();
}
bool save() const override
{
mWidget->saveSettings();
return Akonadi::AgentConfigurationBase::save();
}
QScopedPointer<Settings> mSettings;
QScopedPointer<AccountWidget> mWidget;
};
AKONADI_AGENTCONFIG_FACTORY(Pop3ConfigFactory, "pop3config.json", Pop3Config)
#include "pop3config.moc"
{
"X-Akonadi-PluginType": "AgentConfig",
"X-Akonadi-Library": "pop3config",
"X-Akonadi-AgentConfig-Type": "akonadi_pop3_resource"
}
......@@ -16,8 +16,8 @@
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#include "pop3resource.h"
#include "accountdialog.h"
#include "settings.h"
#include "jobs.h"
......@@ -58,9 +58,18 @@ POP3Resource::POP3Resource(const QString &id)
, mIdsToSaveValid(false)
, mDeleteJob(nullptr)
{
new Settings(KSharedConfig::openConfig());
Akonadi::AttributeFactory::registerAttribute<Akonadi::Pop3ResourceAttribute>();
setNeedsNetwork(true);
Settings::self()->setResourceId(identifier());
if (Settings::self()->name().isEmpty()) {
if (name() == identifier()) {
Settings::self()->setName(i18n("POP3 Account"));
} else {
Settings::self()->setName(name());
}
}
setName(Settings::self()->name());
resetState();
connect(this, &POP3Resource::abortRequested, this, &POP3Resource::slotAbortRequested);
......@@ -78,8 +87,8 @@ POP3Resource::~POP3Resource()
void POP3Resource::configurationChanged()
{
Settings::self()->save();
updateIntervalTimer();
mPassword.clear();
}
void POP3Resource::updateIntervalTimer()
......@@ -117,19 +126,6 @@ void POP3Resource::slotAbortRequested()
}
}
void POP3Resource::configure(WId windowId)
{
QPointer<AccountDialog> accountDialog(new AccountDialog(this, windowId));
if (accountDialog->exec() == QDialog::Accepted) {
updateIntervalTimer();
Q_EMIT configurationDialogAccepted();
} else {
Q_EMIT configurationDialogRejected();
}
delete accountDialog;
}
void POP3Resource::retrieveItems(const Akonadi::Collection &collection)
{
Q_UNUSED(collection);
......
......@@ -48,9 +48,6 @@ public:
void cleanup() override;
public Q_SLOTS:
void configure(WId windowId) override;
protected:
using ResourceBase::retrieveItems; // Suppress -Woverload-virtual
......
......@@ -43,23 +43,21 @@ Q_GLOBAL_STATIC(SettingsHelper, s_globalSettings)
Settings *Settings::self()
{
if (!s_globalSettings->q) {
new Settings;
s_globalSettings->q->load();
}
Q_ASSERT_X(s_globalSettings->q, "Settings::self()", "You must create an instance first!");
return s_globalSettings->q;
}
Settings::Settings()
Settings::Settings(KSharedConfigPtr config)
: SettingsBase(config)
{
Q_ASSERT(!s_globalSettings->q);
s_globalSettings->q = this;
new SettingsAdaptor(this);
QDBusConnection::sessionBus().registerObject(QStringLiteral("/Settings"), this,
QDBusConnection::ExportAdaptors | QDBusConnection::ExportScriptableContents);
}
void Settings::setWindowId(WId id)
{
mWinId = id;
......
......@@ -32,7 +32,8 @@ class Settings : public SettingsBase
Q_OBJECT
Q_CLASSINFO("D-Bus Interface", "org.kde.Akonadi.POP3.Wallet")
public:
Settings();
Settings(KSharedConfigPtr config);
void setWindowId(WId id);
void setResourceId(const QString &resourceIdentifier);
static Settings *self();
......
......@@ -4,8 +4,12 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.kde.org/standards/kcfg/1.0
http://www.kde.org/standards/kcfg/1.0/kcfg.xsd" >
<kcfgfile/>
<kcfgfile arg="true"/>
<group name="General">
<entry name="name" type="String">
<label></label>
<default></default>
</entry>
<entry name="unitTestPassword" type="String">
<label></label>
<default></default>
......
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