Commit 3988b4dd authored by Daniel Vrátil's avatar Daniel Vrátil 🤖

Port the MixedMaildirResource to the new config API

parent 6de03aee
......@@ -11,23 +11,23 @@ add_definitions(-DTRANSLATION_DOMAIN=\"akonadi_mixedmaildir_resource\")
add_subdirectory(kmindexreader)
########### next target ###############
set(mixedmaildir_common_SRCS)
kconfig_add_kcfg_files(mixedmaildir_common_SRCS settings.kcfgc)
############################# Resource #######################################
set( mixedmaildirresource_SRCS
mixedmaildirresource_debug.cpp
compactchangehelper.cpp
configdialog.cpp
mixedmaildirresource.cpp
mixedmaildirstore.cpp
retrieveitemsjob.cpp
mixedmaildir_debug.cpp
${mixedmaildir_common_SRCS}
)
install( FILES mixedmaildirresource.desktop DESTINATION "${KDE_INSTALL_DATAROOTDIR}/akonadi/agents" )
ki18n_wrap_ui(mixedmaildirresource_SRCS settings.ui)
kconfig_add_kcfg_files(mixedmaildirresource_SRCS settings.kcfgc)
kcfg_generate_dbus_interface(${CMAKE_CURRENT_SOURCE_DIR}/mixedmaildirresource.kcfg org.kde.Akonadi.MixedMaildir.Settings)
......@@ -54,9 +54,6 @@ target_link_libraries(akonadi_mixedmaildir_resource
KF5::Mime
KF5::AkonadiAgentBase
KF5::I18n
KF5::KIOWidgets
KF5::ConfigWidgets
KF5::WindowSystem
akonadi-singlefileresource
)
......@@ -68,3 +65,25 @@ install(FILES ${CMAKE_CURRENT_BINARY_DIR}/org.kde.Akonadi.MixedMaildir.Settings.
if (BUILD_TESTING)
add_subdirectory( autotests )
endif ()
###################################### Config Plugin #########################
set(mixedmaildirconfig_SRCS
mixedmaildirconfig.cpp
configwidget.cpp
${mixedmaildir_common_SRCS}
)
ki18n_wrap_ui(mixedmaildirconfig_SRCS settings.ui)
kcoreaddons_add_plugin(mixedmaildirconfig
SOURCES ${mixedmaildirconfig_SRCS}
JSON "mixedmaildirconfig.json"
INSTALL_NAMESPACE "akonadi/config"
)
target_link_libraries(mixedmaildirconfig
KF5::AkonadiCore
KF5::I18n
KF5::KIOWidgets
KF5::ConfigWidgets
maildir
)
......@@ -17,7 +17,7 @@
02110-1301, USA.
*/
#include "configdialog.h"
#include "configwidget.h"
#include "settings.h"
#include "libmaildir/maildir.h"
......@@ -29,38 +29,20 @@
#include <QDialogButtonBox>
using KPIM::Maildir;
ConfigDialog::ConfigDialog(QWidget *parent)
: QDialog(parent)
ConfigWidget::ConfigWidget(Settings *settings, QWidget *parent)
: QWidget(parent)
, mManager(new KConfigDialogManager(this, settings))
{
setWindowTitle(i18n("Select a KMail Mail folder"));
QWidget *mainWidget = new QWidget(this);
QVBoxLayout *mainLayout = new QVBoxLayout(this);
mainLayout->addWidget(mainWidget);
ui.setupUi(mainWidget);
mManager = new KConfigDialogManager(this, Settings::self());
mManager->updateWidgets();
ui.kcfg_Path->setMode(KFile::Directory | KFile::ExistingOnly);
ui.kcfg_Path->setUrl(QUrl::fromLocalFile(Settings::self()->path()));
QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, this);
mainLayout->addWidget(buttonBox);
mOkButton = buttonBox->button(QDialogButtonBox::Ok);
mOkButton->setDefault(true);
mOkButton->setShortcut(Qt::CTRL | Qt::Key_Return);
connect(buttonBox, &QDialogButtonBox::accepted, this, &ConfigDialog::accept);
connect(buttonBox, &QDialogButtonBox::rejected, this, &ConfigDialog::reject);
connect(mOkButton, &QPushButton::clicked, this, &ConfigDialog::save);
connect(ui.kcfg_Path->lineEdit(), &QLineEdit::textChanged, this, &ConfigDialog::checkPath);
ui.setupUi(this);
connect(ui.kcfg_Path->lineEdit(), &QLineEdit::textChanged, this, &ConfigWidget::checkPath);
ui.kcfg_Path->lineEdit()->setFocus();
checkPath();
}
void ConfigDialog::checkPath()
void ConfigWidget::checkPath()
{
if (ui.kcfg_Path->url().isEmpty()) {
ui.statusLabel->setText(i18n("The selected path is empty."));
mOkButton->setEnabled(false);
Q_EMIT okEnabled(false);
return;
}
bool ok = false;
......@@ -91,13 +73,20 @@ void ConfigDialog::checkPath()
ui.statusLabel->setText(i18n("The selected path does not exist."));
}
}
mOkButton->setEnabled(ok);
Q_EMIT okEnabled(ok);
}
void ConfigWidget::load(Settings* settings)
{
mManager->updateWidgets();
ui.kcfg_Path->setMode(KFile::Directory | KFile::ExistingOnly);
ui.kcfg_Path->setUrl(QUrl::fromLocalFile(settings->path()));
checkPath();
}
void ConfigDialog::save()
void ConfigWidget::save(Settings *settings) const
{
mManager->updateSettings();
Settings::self()->setPath(ui.kcfg_Path->url().isLocalFile() ? ui.kcfg_Path->url().toLocalFile() : ui.kcfg_Path->url().path());
Settings::self()->setTopLevelIsContainer(mToplevelIsContainer);
Settings::self()->save();
settings->setPath(ui.kcfg_Path->url().isLocalFile() ? ui.kcfg_Path->url().toLocalFile() : ui.kcfg_Path->url().path());
settings->setTopLevelIsContainer(mToplevelIsContainer);
}
......@@ -17,28 +17,32 @@
02110-1301, USA.
*/
#ifndef CONFIGDIALOG_H
#define CONFIGDIALOG_H
#ifndef CONFIGWIDGET_H
#define CONFIGWIDGET_H
#include <QDialog>
#include "ui_settings.h"
class QPushButton;
class KConfigDialogManager;
class ConfigDialog : public QDialog
class Settings;
class ConfigWidget : public QWidget
{
Q_OBJECT
public:
explicit ConfigDialog(QWidget *parent = nullptr);
explicit ConfigWidget(Settings *settings, QWidget *parent = nullptr);
void load(Settings *settings);
void save(Settings *settings) const;
Q_SIGNALS:
void okEnabled(bool enabled);
private Q_SLOTS:
void checkPath();
void save();
private:
Ui::ConfigDialog ui;
Ui::ConfigWidget ui;
KConfigDialogManager *mManager = nullptr;
QPushButton *mOkButton = nullptr;
bool mToplevelIsContainer = false;
......
/* Copyright (C) 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) 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 "configwidget.h"
#include "settings.h"
class MixedMaildirConfig : public Akonadi::AgentConfigurationBase
{
Q_OBJECT
public:
MixedMaildirConfig(KSharedConfigPtr config, QWidget *parent, const QVariantList &args)
: Akonadi::AgentConfigurationBase(config, parent, args)
{
Settings::instance(config);
mSettings.reset(Settings::self());
mWidget.reset(new ConfigWidget(mSettings.data(), parent));
}
void load() override
{
Akonadi::AgentConfigurationBase::load();
mWidget->load(mSettings.data());
}
bool save() const override
{
mWidget->save(mSettings.data());
mSettings->save();
return Akonadi::AgentConfigurationBase::save();
}
private:
QScopedPointer<Settings> mSettings;
QScopedPointer<ConfigWidget> mWidget;
};
AKONADI_AGENTCONFIG_FACTORY(MixedMaildirConfigFactory, "mixedmaildirconfig.json", MixedMaildirConfig)
#include "mixedmaildirconfig.moc"
{
"X-Akonadi-PluginType": "AgentConfig",
"X-Akonadi-Library": "mixedmaildirconfig",
"X-Akonadi-AgentConfig-Type": "akonadi_mixedmaildir_resource"
}
......@@ -24,7 +24,6 @@
#include "mixedmaildir_debug.h"
#include "compactchangehelper.h"
#include "configdialog.h"
#include "mixedmaildirstore.h"
#include "settings.h"
#include "settingsadaptor.h"
......@@ -57,7 +56,6 @@
#include "mixedmaildirresource_debug.h"
#include <KLocalizedString>
#include <KWindowSystem>
#include <QDir>
#include <QDBusConnection>
......@@ -71,6 +69,7 @@ MixedMaildirResource::MixedMaildirResource(const QString &id)
, mStore(new MixedMaildirStore())
, mCompactHelper(nullptr)
{
Settings::instance(KSharedConfig::openConfig());
new SettingsAdaptor(Settings::self());
QDBusConnection::sessionBus().registerObject(QStringLiteral("/Settings"),
Settings::self(), QDBusConnection::ExportAdaptors);
......@@ -102,6 +101,7 @@ MixedMaildirResource::MixedMaildirResource(const QString &id)
MixedMaildirResource::~MixedMaildirResource()
{
delete mStore;
delete Settings::self();
}
void MixedMaildirResource::aboutToQuit()
......@@ -111,42 +111,6 @@ void MixedMaildirResource::aboutToQuit()
Settings::self()->save();
}
void MixedMaildirResource::configure(WId windowId)
{
ConfigDialog dlg;
if (windowId) {
KWindowSystem::setMainWindow(&dlg, windowId);
}
dlg.setWindowIcon(QIcon::fromTheme(QStringLiteral("message-rfc822")));
bool fullSync = false;
if (dlg.exec()) {
const bool changeName = name().isEmpty() || name() == identifier()
|| name() == mStore->topLevelCollection().name();
const QString oldPath = mStore->path();
mStore->setPath(Settings::self()->path());
fullSync = oldPath != mStore->path();
if (changeName) {
setName(mStore->topLevelCollection().name());
}
Q_EMIT configurationDialogAccepted();
} else {
Q_EMIT configurationDialogRejected();
}
if (ensureDirExists()) {
if (fullSync) {
mSynchronizedCollections.clear();
mPendingSynchronizeCollections.clear();
}
synchronizeCollectionTree();
}
}
void MixedMaildirResource::itemAdded(const Item &item, const Collection &collection)
{
/* qCDebug(MIXEDMAILDIRRESOURCE_LOG) << "item.id=" << item.id() << "col=" << collection.remoteId();*/
......@@ -452,6 +416,12 @@ void MixedMaildirResource::checkForInvalidatedIndexCollections(KJob *job)
void MixedMaildirResource::reapplyConfiguration()
{
const bool changeName = name().isEmpty() || name() == identifier()
|| name() == mStore->topLevelCollection().name();
if (changeName) {
setName(mStore->topLevelCollection().name());
}
if (ensureSaneConfiguration() && ensureDirExists()) {
const QString oldPath = mStore->path();
mStore->setPath(Settings::self()->path());
......
......@@ -37,9 +37,6 @@ public:
explicit MixedMaildirResource(const QString &id);
~MixedMaildirResource();
public Q_SLOTS:
void configure(WId windowId) override;
protected Q_SLOTS:
void retrieveCollections() override;
void retrieveItems(const Akonadi::Collection &col) override;
......
......@@ -4,7 +4,7 @@
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="Path" type="Path">
<label>Path to KMail mail folder</label>
......
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<author>Till Adam &lt;adam@kde.org&gt;</author>
<class>ConfigDialog</class>
<widget class="QWidget" name="ConfigDialog">
<class>ConfigWidget</class>
<widget class="QWidget" name="ConfigWidget">
<property name="geometry">
<rect>
<x>0</x>
......
......@@ -40,6 +40,7 @@ public:
: SingleFileResourceConfigWidgetBase(parent)
, mSettings(settings)
{
mManager = new KConfigDialogManager(this, mSettings);
}
bool save() const override
......
......@@ -38,12 +38,6 @@ using namespace Akonadi;
SingleFileResourceConfigWidgetBase::SingleFileResourceConfigWidgetBase(QWidget *parent)
: QWidget(parent)
, mManager(nullptr)
, mStatJob(nullptr)
, mAppendedWidget(nullptr)
, mDirUrlChecked(false)
, mMonitorEnabled(true)
, mLocalFileOnly(false)
{
QWidget *mainWidget = new QWidget(this);
QVBoxLayout *mainLayout = new QVBoxLayout(this);
......
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