Commit 45ec9d3c authored by Shashwat Jolly's avatar Shashwat Jolly
Browse files

Implement resource configuration dialog

Note: Implementation is currently buggy. Settings are saved, but accessible only on restarting the agent instance.
parent 53cea8d4
set(etesyncresource_common_SRCS)
kconfig_add_kcfg_files(etesyncresource_common_SRCS
${CMAKE_CURRENT_SOURCE_DIR}/settings.kcfgc
)
set(etesyncresource_SRCS
etesyncresource.cpp
${etesyncresource_common_SRCS}
)
ecm_qt_declare_logging_category(etesyncresource_SRCS
HEADER debug.h
HEADER etesync_debug.h
IDENTIFIER ETESYNC_LOG
CATEGORY_NAME org.kde.pim.google
CATEGORY_NAME org.kde.pim.etesync
DESCRIPTION "resource etesync (kdepim-runtime)"
)
kconfig_add_kcfg_files(etesyncresource_SRCS
${CMAKE_CURRENT_SOURCE_DIR}/settings.kcfgc
EXPORT KDEPIMRUNTIME
)
kcfg_generate_dbus_interface(
${CMAKE_CURRENT_SOURCE_DIR}/settings.kcfg
${CMAKE_CURRENT_SOURCE_DIR}/etesyncresource.kcfg
org.kde.Akonadi.etesync.Settings
)
......@@ -36,6 +39,7 @@ target_link_libraries(akonadi_etesync_resource
KF5::AkonadiAgentBase
KF5::ConfigCore
KF5::Contacts
KF5::I18n
)
ecm_install_icons(
......@@ -56,3 +60,35 @@ install(TARGETS akonadi_etesync_resource ${KDE_INSTALL_TARGETS_DEFAULT_ARGS})
install(FILES etesyncresource.desktop
DESTINATION ${KDE_INSTALL_DATAROOTDIR}/akonadi/agents
)
################################### Config plugin ############################
set(etesyncconfig_SRCS
configwidget.cpp
etesyncconfig.cpp
${etesyncresource_common_SRCS}
)
ecm_qt_declare_logging_category(etesyncconfig_SRCS
HEADER etesyncconfig_debug.h
IDENTIFIER ETESYNC_CONFIG_LOG
CATEGORY_NAME org.kde.pim.etesync.config
DESCRIPTION "resource etesync (kdepim-runtime)"
EXPORT KDEPIMRUNTIME
)
ki18n_wrap_ui(etesyncconfig_SRCS configwidget.ui)
kcoreaddons_add_plugin(etesyncconfig
SOURCES ${etesyncconfig_SRCS}
JSON "etesyncconfig.json"
INSTALL_NAMESPACE "akonadi/config"
)
target_link_libraries(etesyncconfig
KF5::AkonadiCore
KF5::I18n
KF5::Completion
KF5::ConfigWidgets
KF5::KIOCore
)
\ No newline at end of file
/*
* Copyright (C) 2020 by Shashwat Jolly <shashwat.jolly@gmail.com>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include "configwidget.h"
#include <KConfigDialogManager>
#include <KLocalizedString>
#include <KMessageBox>
#include <QPushButton>
#include "etesyncconfig_debug.h"
#include "settings.h"
#include "ui_configwidget.h"
ConfigWidget::ConfigWidget(Settings *settings, QWidget *parent)
: QWidget(parent)
{
Ui::ConfigWidget ui;
ui.setupUi(this);
ui.kcfg_BaseUrl->setWhatsThis(i18n("Enter the http or https URL of your EteSync server here."));
ui.kcfg_Username->setWhatsThis(i18n("Enter the username of your EteSync account here."));
ui.kcfg_Password->setWhatsThis(i18n("Enter the password of your EteSync account here."));
ui.kcfg_EncryptionPassword->setWhatsThis(i18n("Enter the encryption password for your EteSync account here."));
ui.kcfg_BaseUrl->setText(QStringLiteral("https://api.etesync.com"));
mServerEdit = ui.kcfg_BaseUrl;
mUserEdit = ui.kcfg_Username;
mPasswordEdit = ui.kcfg_Password;
mEncryptionPasswordEdit = ui.kcfg_EncryptionPassword;
mManager = new KConfigDialogManager(this, settings);
setMinimumSize(QSize(380, 180));
}
void ConfigWidget::load()
{
mManager->updateWidgets();
}
void ConfigWidget::save() const
{
mManager->updateSettings();
}
\ No newline at end of file
/*
* Copyright (C) 2020 by Shashwat Jolly <shashwat.jolly@gmail.com>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#ifndef CONFIGWIDGET_H
#define CONFIGWIDGET_H
#include <QWidget>
class KConfigDialogManager;
class QLineEdit;
class QPushButton;
class Settings;
class ConfigWidget : public QWidget
{
Q_OBJECT
public:
explicit ConfigWidget(Settings *settings, QWidget *parent);
void load();
void save() const;
private:
KConfigDialogManager *mManager = nullptr;
QLineEdit *mServerEdit = nullptr;
QLineEdit *mUserEdit = nullptr;
QLineEdit *mPasswordEdit = nullptr;
QLineEdit *mEncryptionPasswordEdit = nullptr;
};
#endif
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>ConfigWidget</class>
<widget class="QWidget" name="ConfigWidget">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>380</width>
<height>180</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="QGroupBox" name="groupBox">
<property name="title">
<string>Configuration</string>
</property>
<property name="checkable">
<bool>false</bool>
</property>
<layout class="QFormLayout" name="formLayout">
<item row="0" column="0">
<widget class="QLabel" name="label_BaseUrl">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>120</width>
<height>0</height>
</size>
</property>
<property name="text">
<string>Server URL:</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLineEdit" name="kcfg_BaseUrl">
<property name="toolTip">
<string>The URL of the EteSync server</string>
</property>
<property name="whatsThis">
<string>The URL of the EteSync server</string>
</property>
<property name="placeholderText">
<string notr="true">https://api.etesync.com</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_Username">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>120</width>
<height>0</height>
</size>
</property>
<property name="text">
<string>Username:</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QLineEdit" name="kcfg_Username">
<property name="toolTip">
<string>The username that is used to log into the EteSync server</string>
</property>
<property name="whatsThis">
<string>The username that is used to log into the EteSync server</string>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label_Password">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>120</width>
<height>0</height>
</size>
</property>
<property name="text">
<string>Password:</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QLineEdit" name="kcfg_Password">
<property name="toolTip">
<string>The password that is used to log into the EteSync server</string>
</property>
<property name="whatsThis">
<string>The password that is used to log into the EteSync server</string>
</property>
<property name="echoMode">
<enum>QLineEdit::Password</enum>
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QLabel" name="label_EncryptionPassword">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>120</width>
<height>0</height>
</size>
</property>
<property name="text">
<string>Encryption Password:</string>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QLineEdit" name="kcfg_EncryptionPassword">
<property name="toolTip">
<string>Encryption password for your EteSync account</string>
</property>
<property name="whatsThis">
<string>Encryption password for your EteSync account</string>
</property>
<property name="echoMode">
<enum>QLineEdit::Password</enum>
</property>
</widget>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>
/*
* Copyright (C) 2020 by Shashwat Jolly <shashwat.jolly@gmail.com>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include <etesync/etesync.h>
QString QStringFromCharArr(const char *str) { return QLatin1String(str); }
......
/*
* Copyright (C) 2020 by Shashwat Jolly <shashwat.jolly@gmail.com>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include <AkonadiCore/AgentConfigurationBase>
#include "configwidget.h"
#include "etesyncconfig_debug.h"
#include "settings.h"
class EteSyncConfig : public Akonadi::AgentConfigurationBase
{
Q_OBJECT
public:
EteSyncConfig(const 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();
}
bool save() const override
{
mWidget->save();
return Akonadi::AgentConfigurationBase::save();
}
QScopedPointer<Settings> mSettings;
QScopedPointer<ConfigWidget> mWidget;
};
AKONADI_AGENTCONFIG_FACTORY(EteSyncConfigFactory, "etesyncconfig.json", EteSyncConfig)
#include "etesyncconfig.moc"
{
"X-Akonadi-PluginType": "AgentConfig",
"X-Akonadi-Library": "etesyncconfig",
"X-Akonadi-AgentConfig-Type": "akonadi_etesync_resource"
}
......@@ -19,7 +19,7 @@
#include <QDBusConnection>
#include "debug.h"
#include "etesync_debug.h"
#include "etesyncadapter.h"
#include "settings.h"
#include "settingsadaptor.h"
......@@ -29,12 +29,25 @@ using namespace Akonadi;
etesyncResource::etesyncResource(const QString &id)
: ResourceBase(id)
{
Settings::instance(KSharedConfig::openConfig());
new SettingsAdaptor(Settings::self());
QDBusConnection::sessionBus().registerObject(QStringLiteral("/Settings"),
Settings::self(),
QDBusConnection::ExportAdaptors);
QLoggingCategory::setFilterRules(QStringLiteral("ETESYNC_LOG.debug = true"));
serverUrl = Settings::self()->baseUrl();
username = Settings::self()->username();
password = Settings::self()->password();
encryptionPassword = Settings::self()->encryptionPassword();
/// TODO: Fix hack
QString emptyStr = QStringLiteral("");
if (serverUrl != emptyStr && username != emptyStr && password != emptyStr && encryptionPassword != emptyStr) initialise();
setNeedsNetwork(true);
connect(this, &Akonadi::AgentBase::reloadConfiguration, this, &etesyncResource::onReloadConfiguration);
qCDebug(ETESYNC_LOG) << "Resource started";
}
......@@ -151,29 +164,21 @@ void etesyncResource::aboutToQuit()
// event loop. The resource will terminate after this method returns
}
void etesyncResource::configure(WId windowId)
void etesyncResource::onReloadConfiguration()
{
// TODO: this method is usually called when a new resource is being
// added to the Akonadi setup. You can do any kind of user interaction here,
// e.g. showing dialogs.
// The given window ID is usually useful to get the correct
// "on top of parent" behavior if the running window manager applies any
// kind of focus stealing prevention technique
//
// If the configuration dialog has been accepted by the user by clicking Ok,
// the signal configurationDialogAccepted() has to be emitted, otherwise, if
// the user canceled the dialog, configurationDialogRejected() has to be
// emitted.
/// TODO: Implement config dialog and move settings to kcfg
QString username = QStringLiteral("test@localhost");
QString password = QStringLiteral("testetesync");
QString encryptionPassword = QStringLiteral("etesync");
QString serverUrl = QStringLiteral("http://192.168.29.145:9966");
serverUrl = Settings::self()->baseUrl();
username = Settings::self()->username();
password = Settings::self()->password();
encryptionPassword = Settings::self()->encryptionPassword();
// Initialise EteSync client state
qCDebug(ETESYNC_LOG) << "Resource config reload";
initialise();
}
void etesyncResource::initialise()
{
// Initialise EteSync client state
etesync = etesync_new(QStringLiteral("Akonadi EteSync Resource"), serverUrl);
derived = etesync_crypto_derive_key(etesync, username, encryptionPassword);
QString token = etesync_auth_get_token(etesync, username, password);
......
[Desktop Entry]
Name=Etesync Groupware Resource
Comment=An Akonadi resource plugin for etesync
Name=EteSync Groupware Resource
Comment=Access your encrypted EteSync Calendars, Contacts and Tasks from KDE
Type=AkonadiResource
Exec=akonadi_etesync_resource
Icon=akonadi-etesync
......
......@@ -33,9 +33,6 @@ public:
explicit etesyncResource(const QString &id);
~etesyncResource() override;
public Q_SLOTS:
void configure(WId windowId) override;
protected Q_SLOTS:
void retrieveCollections() override;
void retrieveItems(const Akonadi::Collection &col) override;
......@@ -51,11 +48,17 @@ protected:
const QSet<QByteArray> &parts) override;
void itemRemoved(const Akonadi::Item &item) override;
void initialise();
private Q_SLOTS:
void onReloadConfiguration();
private:
EteSync *etesync;
QString derived;
EteSyncJournalManager *journalManager;
EteSyncAsymmetricKeyPair *keypair;
QString username, password, serverUrl, encryptionPassword;
};
#endif
<?xml version="1.0" encoding="UTF-8"?>
<kcfg xmlns="http://www.kde.org/standards/kcfg/1.0"
xmlns:kcfg="http://www.kde.org/standards/kcfg/1.0"
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 arg="true" />
<group name="General">
<entry name="BaseUrl" type="String">
<label>Server URL</label>
<tooltip>The URL of the EteSync server, should be something like https://myserver.org/</tooltip>
<whatsthis>The URL of the EteSync server, should be something like https://myserver.org/</whatsthis>
</entry>
<entry name="Username" type="String">
<label context="the username to login on server">Username</label>
<tooltip>The username that is used to log into the EteSync server</tooltip>
<whatsthis>The username that is used to log into the EteSync server</whatsthis>
</entry>
<entry name="Password" type="Password">
<label>Password</label>
<tooltip>The password that is used to log into the EteSync server</tooltip>
<whatsthis>The password that is used to log into the EteSync server</whatsthis>
</entry>
<entry name="EncryptionPassword" type="Password">
<label>Encryption Password</label>
<tooltip>Encryption password for your EteSync account</tooltip>
<whatsthis>Encryption password for your EteSync account</whatsthis>
</entry>
</group>
</kcfg>
<?xml version="1.0" encoding="UTF-8"?>
<kcfg xmlns="http://www.kde.org/standards/kcfg/1.0"
xmlns:kcfg="http://www.kde.org/standards/kcfg/1.0"
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/>
<group name="General">
<entry name="ReadOnly" type="Bool">
<label>Do not change the actual backend data.</label>
<default>false</default>
</entry>
</group>
</kcfg>
File=settings.kcfg
File=etesyncresource.kcfg
ClassName=Settings
Mutators=true
ItemAccessors=true
SetUserTexts=true
Singleton=true
#IncludeFiles=
GlobalEnums=true
TranslationSystem=kde
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