Commit d3bb0249 authored by Shashwat Jolly's avatar Shashwat Jolly

Fix config dialog bug

Fix bug where resource was not able to get updated settings in the current instance
parent 45ec9d3c
......@@ -64,7 +64,6 @@ install(FILES etesyncresource.desktop
################################### Config plugin ############################
set(etesyncconfig_SRCS
configwidget.cpp
etesyncconfig.cpp
${etesyncresource_common_SRCS}
)
......@@ -77,7 +76,7 @@ ecm_qt_declare_logging_category(etesyncconfig_SRCS
EXPORT KDEPIMRUNTIME
)
ki18n_wrap_ui(etesyncconfig_SRCS configwidget.ui)
ki18n_wrap_ui(etesyncconfig_SRCS etesyncconfigwidget.ui)
kcoreaddons_add_plugin(etesyncconfig
SOURCES ${etesyncconfig_SRCS}
......
/*
* 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
......@@ -15,40 +15,45 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include <AkonadiCore/AgentConfigurationBase>
#include "etesyncconfig.h"
#include <KConfigDialogManager>
#include <KSharedConfig>
#include "configwidget.h"
#include "etesyncconfig_debug.h"
#include "settings.h"
class EteSyncConfig : public Akonadi::AgentConfigurationBase
namespace {
static const char myConfigGroupName[] = "EteSyncConfigDialog";
}
EteSyncConfig::EteSyncConfig(const KSharedConfigPtr &config, QWidget *parent, const QVariantList &args)
: Akonadi::AgentConfigurationBase(config, parent, args)
{
Settings::instance(config);
QWidget *mainWidget = new QWidget(parent);
ui.setupUi(mainWidget);
parent->layout()->addWidget(mainWidget);
mManager = new KConfigDialogManager(mainWidget, Settings::self());
mManager->updateWidgets();
}
bool EteSyncConfig::save() const
{
mManager->updateSettings();
return Akonadi::AgentConfigurationBase::save();
}
QSize EteSyncConfig::restoreDialogSize() const
{
auto group = config()->group(myConfigGroupName);
const QSize size = group.readEntry("Size", QSize(380, 180));
return size;
}
void EteSyncConfig::saveDialogSize(const QSize &size)
{
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"
auto group = config()->group(myConfigGroupName);
group.writeEntry("Size", size);
}
......@@ -15,31 +15,29 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#ifndef CONFIGWIDGET_H
#define CONFIGWIDGET_H
#ifndef ETESYNCCONFIG_H
#define ETESYNCCONFIG_H
#include <QWidget>
#include <AkonadiCore/AgentConfigurationBase>
#include "ui_etesyncconfigwidget.h"
class KConfigDialogManager;
class QLineEdit;
class QPushButton;
class Settings;
class ConfigWidget : public QWidget
class EteSyncConfig : public Akonadi::AgentConfigurationBase
{
Q_OBJECT
public:
explicit ConfigWidget(Settings *settings, QWidget *parent);
explicit EteSyncConfig(const KSharedConfigPtr &config, QWidget *parent, const QVariantList &args);
void load();
void save() const;
bool save() const override;
QSize restoreDialogSize() const override;
void saveDialogSize(const QSize &size) override;
private:
Ui::EteSyncConfigWidget ui;
KConfigDialogManager *mManager = nullptr;
QLineEdit *mServerEdit = nullptr;
QLineEdit *mUserEdit = nullptr;
QLineEdit *mPasswordEdit = nullptr;
QLineEdit *mEncryptionPasswordEdit = nullptr;
};
AKONADI_AGENTCONFIG_FACTORY(EteSyncConfigFactory, "etesyncconfig.json", EteSyncConfig)
#endif
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>ConfigWidget</class>
<class>EteSyncConfigWidget</class>
<widget class="QWidget" name="ConfigWidget">
<property name="geometry">
<rect>
......
......@@ -17,6 +17,7 @@
#include "etesyncresource.h"
#include <KLocalizedString>
#include <QDBusConnection>
#include "etesync_debug.h"
......@@ -36,14 +37,7 @@ etesyncResource::etesyncResource(const QString &id)
Settings::self(),
QDBusConnection::ExportAdaptors);
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();
setName(i18n("EteSync Resource"));
setNeedsNetwork(true);
......@@ -121,8 +115,8 @@ void etesyncResource::retrieveItems(const Akonadi::Collection &collection)
const KContacts::Addressee contact = converter.parseVCard(content);
if (action == QStringLiteral(ETESYNC_SYNC_ENTRY_ACTION_ADD) || action == QStringLiteral(ETESYNC_SYNC_ENTRY_ACTION_CHANGE)) {
qCDebug(ETESYNC_LOG) << action;
qCDebug(ETESYNC_LOG) << contact.uid();
// qCDebug(ETESYNC_LOG) << action;
// qCDebug(ETESYNC_LOG) << contact.uid();
contacts[contact.uid()] = contact;
remoteIDs[contact.uid()] = QStringFromCharArr(etesync_entry_get_uid(entry));
} else if (action == QStringLiteral(ETESYNC_SYNC_ENTRY_ACTION_DELETE)) {
......@@ -166,6 +160,7 @@ void etesyncResource::aboutToQuit()
void etesyncResource::onReloadConfiguration()
{
Settings::self()->load();
serverUrl = Settings::self()->baseUrl();
username = Settings::self()->username();
password = Settings::self()->password();
......
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