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 ab848433 authored by Laurent Montel's avatar Laurent Montel 😁

Port tomboynotes to new api

parent 92ffe052
......@@ -3,8 +3,13 @@ add_definitions(-DTRANSLATION_DOMAIN=\"akonadi_tomboynotes_resource\")
########### next target ###############
set(tomboynotesresource_common_SRCS)
kconfig_add_kcfg_files(tomboynotesresource_common_SRCS
settings.kcfgc
)
set(tomboynotesresource_SRCS
configdialog.cpp
tomboynotesresource.cpp
tomboycollectionsdownloadjob.cpp
tomboyitemdownloadjob.cpp
......@@ -33,7 +38,7 @@ ecm_qt_declare_logging_category(tomboynotesresource_SRCS
CATEGORY_NAME org.kde.pim.tomboynotesresource
)
ki18n_wrap_ui(tomboynotesresource_SRCS configdialog.ui)
kconfig_add_kcfg_files(tomboynotesresource_SRCS
${CMAKE_CURRENT_SOURCE_DIR}/settings.kcfgc
......@@ -75,3 +80,28 @@ install(TARGETS akonadi_tomboynotes_resource ${KDE_INSTALL_TARGETS_DEFAULT_ARGS}
install(FILES tomboynotesresource.desktop
DESTINATION "${KDE_INSTALL_DATAROOTDIR}/akonadi/agents"
)
############################# Config plugin ################################
set(tomboynotesconfig_ui_SRCS)
ki18n_wrap_ui(tomboynotesconfig_ui_SRCS tomboynotesagentconfigwidget.ui)
set(tomboynotesconfig_SRCS
tomboynotesconfigwidget.cpp
${tomboynotesconfig_ui_SRCS}
${tomboynotesresource_common_SRCS}
)
kcoreaddons_add_plugin(tomboynotesconfig
SOURCES ${tomboynotesconfig_SRCS}
JSON "tomboynotesconfig.json"
INSTALL_NAMESPACE "akonadi/config"
)
target_link_libraries(tomboynotesconfig
KF5::AkonadiCore
KF5::CalendarCore
KF5::Contacts
KF5::AkonadiWidgets
KF5::I18n
KF5::ConfigWidgets
KF5::Completion
)
<?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>TomboyNotesAgentConfigWidget</class>
<widget class="QWidget" name="TomboyNotesAgentConfigWidget">
<property name="geometry">
<rect>
<x>0</x>
......
{
"X-Akonadi-PluginType": "AgentConfig",
"X-Akonadi-Library": "tomboynotesconfig",
"X-Akonadi-AgentConfig-Type": "akonadi_tomboynotes_resource"
}
/*
Copyright (c) 2016 Stefan Stäglich <sstaeglich@kdemail.net>
Copyright (c) 2018 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
......@@ -17,60 +18,45 @@
02110-1301, USA.
*/
#include "configdialog.h"
#include "ui_configdialog.h"
#include "tomboynotesconfigwidget.h"
#include "ui_tomboynotesagentconfigwidget.h"
#include "settings.h"
#include <kconfigdialogmanager.h>
#include <KConfigGroup>
#include <klocalizedstring.h>
#include <QDialogButtonBox>
ConfigDialog::ConfigDialog(Settings *settings, QWidget *parent)
: QDialog(parent)
, ui(new Ui::ConfigDialog)
, mSettings(settings)
TomboyNotesConfigWidget::TomboyNotesConfigWidget(const KSharedConfigPtr &config, QWidget *parent, const QVariantList &args)
: Akonadi::AgentConfigurationBase(config, parent, args)
, ui(new Ui::TomboyNotesAgentConfigWidget)
{
// Create window
setWindowTitle(i18n("Select a Tomboy server"));
QWidget *mainWidget = new QWidget(this);
QVBoxLayout *mainLayout = new QVBoxLayout(this);
mainLayout->addWidget(mainWidget);
Settings::instance(config);
QWidget *mainWidget = new QWidget(parent);
ui->setupUi(mainWidget);
parent->layout()->addWidget(mainWidget);
// KSettings stuff. Works not in the initialization list!
mManager = new KConfigDialogManager(this, settings);
mManager = new KConfigDialogManager(mainWidget, Settings::self());
mManager->updateWidgets();
QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, this);
mainLayout->addWidget(buttonBox);
// Set the button actions
connect(buttonBox, &QDialogButtonBox::accepted, this, &ConfigDialog::accept);
connect(buttonBox, &QDialogButtonBox::rejected, this, &ConfigDialog::reject);
// Load config dialog window size settings
KConfigGroup group(KSharedConfig::openConfig(), "ConfigDialog");
const QSize size = group.readEntry("Size", QSize(600, 400));
if (size.isValid()) {
resize(size);
}
ui->kcfg_ServerURL->setReadOnly(!mSettings->requestToken().isEmpty());
ui->kcfg_ServerURL->setReadOnly(!Settings::self()->requestToken().isEmpty());
}
ConfigDialog::~ConfigDialog()
TomboyNotesConfigWidget::~TomboyNotesConfigWidget()
{
// Save config dialog window size
KConfigGroup group(KSharedConfig::openConfig(), "ConfigDialog");
group.writeEntry("Size", size());
group.sync();
delete ui;
}
void ConfigDialog::saveSettings()
void TomboyNotesConfigWidget::load()
{
}
bool TomboyNotesConfigWidget::save() const
{
if (ui->kcfg_ServerURL->text() != mSettings->serverURL()) {
mSettings->setRequestToken(QString());
mSettings->setRequestTokenSecret(QString());
if (ui->kcfg_ServerURL->text() != Settings::self()->serverURL()) {
Settings::self()->setRequestToken(QString());
Settings::self()->setRequestTokenSecret(QString());
}
if (ui->kcfg_collectionName->text().isEmpty()) {
......@@ -78,5 +64,19 @@ void ConfigDialog::saveSettings()
}
mManager->updateSettings();
mSettings->save();
Settings::self()->save();
return true;
}
QSize TomboyNotesConfigWidget::restoreDialogSize() const
{
auto group = config()->group("TomboyNotesConfigWidget");
const QSize size = group.readEntry("Size", QSize(600, 400));
return size;
}
void TomboyNotesConfigWidget::saveDialogSize(const QSize &size)
{
auto group = config()->group("TomboyNotesConfigWidget");
group.writeEntry("Size", size);
}
/*
Copyright (c) 2016 Stefan Stäglich <sstaeglich@kdemail.net>
Copyright (c) 2018 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
......@@ -17,34 +18,32 @@
02110-1301, USA.
*/
#ifndef CONFIGDIALOG_H
#define CONFIGDIALOG_H
#include <QDialog>
#ifndef TomboyNotesConfigWidget_H
#define TomboyNotesConfigWidget_H
#include <AkonadiCore/AgentConfigurationBase>
class KConfigDialogManager;
class Settings;
namespace Ui {
class ConfigDialog;
class TomboyNotesAgentConfigWidget;
}
class ConfigDialog : public QDialog
class TomboyNotesConfigWidget : public Akonadi::AgentConfigurationBase
{
Q_OBJECT
public:
explicit ConfigDialog(Settings *settings, QWidget *parent = nullptr);
~ConfigDialog();
explicit TomboyNotesConfigWidget(const KSharedConfigPtr &config, QWidget *parent, const QVariantList &args);
~TomboyNotesConfigWidget() override;
void saveSettings();
void load() override;
bool save() const override;
QSize restoreDialogSize() const override;
void saveDialogSize(const QSize &size) override;
private:
Ui::ConfigDialog *ui = nullptr;
Ui::TomboyNotesAgentConfigWidget *ui = nullptr;
KConfigDialogManager *mManager = nullptr;
Settings *mSettings = nullptr;
};
#endif // CONFIGDIALOG_H
AKONADI_AGENTCONFIG_FACTORY(TomboyNotesConfigWidgetFactory, "tomboynotesconfig.json", TomboyNotesConfigWidget)
#endif // TomboyNotesConfigWidget_H
......@@ -19,7 +19,6 @@
#include "tomboynotesresource.h"
#include "debug.h"
#include "configdialog.h"
#include "settings.h"
#include "settingsadaptor.h"
#include "tomboyserverauthenticatejob.h"
......@@ -31,7 +30,6 @@
#include <ItemFetchScope>
#include <klocalizedstring.h>
#include <ksslinfodialog.h>
#include <kwindowsystem.h>
#include <QSslCipher>
#include <QDBusConnection>
......@@ -62,6 +60,7 @@ TomboyNotesResource::TomboyNotesResource(const QString &id)
connect(mManager, &KIO::AccessManager::sslErrors, this, &TomboyNotesResource::onSslError);
qCDebug(TOMBOYNOTESRESOURCE_LOG) << "Resource started";
connect(this, &TomboyNotesResource::reloadConfiguration, this, &TomboyNotesResource::slotReloadConfig);
}
TomboyNotesResource::~TomboyNotesResource()
......@@ -220,34 +219,20 @@ void TomboyNotesResource::aboutToQuit()
// event loop. The resource will terminate after this method returns
}
void TomboyNotesResource::configure(WId windowId)
void TomboyNotesResource::slotReloadConfig()
{
qCDebug(TOMBOYNOTESRESOURCE_LOG) << "Resource configuration started";
setAgentName(Settings::collectionName());
ConfigDialog dialog(Settings::self());
if (windowId) {
KWindowSystem::setMainWindow(&dialog, windowId);
}
// Run the configuration dialog an save settings if accepted
if (dialog.exec() == QDialog::Accepted) {
dialog.saveSettings();
setAgentName(Settings::collectionName());
if (configurationNotValid()) {
auto job = new TomboyServerAuthenticateJob(mManager, this);
job->setServerURL(Settings::serverURL(), QString());
connect(job, &KJob::result, this, &TomboyNotesResource::onAuthorizationFinished);
job->start();
qCDebug(TOMBOYNOTESRESOURCE_LOG) << "Authorization job started";
} else {
synchronize();
}
Q_EMIT configurationDialogAccepted();
if (configurationNotValid()) {
auto job = new TomboyServerAuthenticateJob(mManager, this);
job->setServerURL(Settings::serverURL(), QString());
connect(job, &KJob::result, this, &TomboyNotesResource::onAuthorizationFinished);
job->start();
qCDebug(TOMBOYNOTESRESOURCE_LOG) << "Authorization job started";
} else {
Q_EMIT configurationDialogRejected();
synchronize();
}
}
void TomboyNotesResource::itemAdded(const Akonadi::Item &item, const Akonadi::Collection &collection)
......
......@@ -31,8 +31,6 @@ public:
explicit TomboyNotesResource(const QString &id);
~TomboyNotesResource() override;
public Q_SLOTS:
void configure(WId windowId) override;
protected:
using ResourceBase::retrieveItems; // Suppress -Woverload-virtual
......@@ -64,6 +62,7 @@ protected:
private:
bool configurationNotValid() const;
void slotReloadConfig();
void retryAfterFailure(const QString &errorMessage);
// Status handling
......
......@@ -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="collectionName" type="String">
<label>The display name of this resource</label>
......
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