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

Port to new API

parent 96ffba38
......@@ -11,14 +11,13 @@ kconfig_add_kcfg_files(vcarddirresource_common_SRCS
set( vcarddirresource_SRCS
${vcarddirresource_common_SRCS}
vcarddirresource.cpp
dirsettingsdialog.cpp
)
ecm_qt_declare_logging_category(vcarddirresource_SRCS HEADER vcarddirresource_debug.h IDENTIFIER VCARDDIRRESOURCE_LOG CATEGORY_NAME org.kde.pim.vcarddirresource)
kcfg_generate_dbus_interface(${CMAKE_CURRENT_SOURCE_DIR}/vcarddirresource.kcfg org.kde.Akonadi.VCardDirectory.Settings)
qt5_add_dbus_adaptor(vcarddirresource_SRCS
${CMAKE_CURRENT_BINARY_DIR}/org.kde.Akonadi.VCardDirectory.Settings.xml settings.h Settings
${CMAKE_CURRENT_BINARY_DIR}/org.kde.Akonadi.VCardDirectory.Settings.xml settings.h VcardDirResourceSettings
)
install( FILES vcarddirresource.desktop DESTINATION "${KDE_INSTALL_DATAROOTDIR}/akonadi/agents" )
......@@ -51,28 +50,27 @@ add_subdirectory(wizard)
install(TARGETS akonadi_vcarddir_resource ${KDE_INSTALL_TARGETS_DEFAULT_ARGS})
############################## Config plugin ################################
#set(contactsconfig_ui_SRCS)
#ki18n_wrap_ui(contactsconfig_ui_SRCS contactsagentsettingswidget.ui)
#set(contactsconfig_SRCS
# contactssettingswidget.cpp
# ${contactsconfig_ui_SRCS}
# ${vcarddirresource_common_SRCS}
# )
#kcoreaddons_add_plugin(contactsconfig
# SOURCES ${contactsconfig_SRCS}
# JSON "contactsconfig.json"
# INSTALL_NAMESPACE "akonadi/config"
# )
#target_link_libraries(contactsconfig
# KF5::AkonadiCore
# KF5::CalendarCore
# KF5::Codecs
# KF5::AkonadiAgentBase
# KF5::Contacts
# KF5::AkonadiWidgets
# KF5::I18n
# KF5::KIOWidgets
# )
set(vcarddirconfig_ui_SRCS)
ki18n_wrap_ui(vcarddirconfig_ui_SRCS vcarddiragentsettingswidget.ui)
set(vcarddirconfig_SRCS
vcarddirsettingswidget.cpp
${vcarddirconfig_ui_SRCS}
${vcarddirresource_common_SRCS}
)
kcoreaddons_add_plugin(vcarddirconfig
SOURCES ${vcarddirconfig_SRCS}
JSON "vcarddirconfig.json"
INSTALL_NAMESPACE "akonadi/config"
)
target_link_libraries(vcarddirconfig
KF5::AkonadiCore
KF5::CalendarCore
KF5::AkonadiAgentBase
KF5::AkonadiWidgets
KF5::I18n
KF5::KIOWidgets
KF5::TextWidgets
)
;File=vcarddirresource.kcfg
;ClassName=VcardDirResourceSettings
;Mutators=true
;ItemAccessors=true
;SetUserTexts=true
;Singleton=true
;GlobalEnums=true
;TranslationSystem=kde
# Code generation options for kconfig_compiler
File=vcarddirresource.kcfg
ClassName=Settings
ClassName=VcardDirResourceSettings
Mutators=true
ItemAccessors=true
SetUserTexts=true
Singleton=true
GlobalEnums=true
TranslationSystem=kde
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>VcardDirsAgentSettingsWidget</class>
<widget class="QWidget" name="VcardDirsAgentSettingsWidget">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>547</width>
<height>386</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="QTabWidget" name="ktabwidget">
<property name="currentIndex">
<number>0</number>
</property>
<widget class="QWidget" name="tab">
<attribute name="title">
<string>Directory</string>
</attribute>
<layout class="QVBoxLayout" name="verticalLayout_4">
<item>
<widget class="QGroupBox" name="groupBox_2">
<property name="title">
<string>Directory Name</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_3">
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QLabel" name="label">
<property name="text">
<string>Di&amp;rectory:</string>
</property>
<property name="buddy">
<cstring>kcfg_Path</cstring>
</property>
</widget>
</item>
<item>
<widget class="KUrlRequester" name="kcfg_Path"/>
</item>
</layout>
</item>
<item>
<widget class="QLabel" name="label_3">
<property name="text">
<string>Select the directory whose contents should be represented by this resource. If the directory does not exist, it will be created.</string>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="groupBox">
<property name="title">
<string>Access Rights</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<widget class="QCheckBox" name="kcfg_ReadOnly">
<property name="text">
<string>Read only</string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label_2">
<property name="text">
<string>If read-only mode is enabled, no changes will be written to the directory selected above. Read-only mode will be automatically enabled if you do not have write access to the directory.</string>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>4</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
<widget class="QWidget" name="tab_2">
<attribute name="title">
<string>Tuning</string>
</attribute>
<layout class="QVBoxLayout" name="verticalLayout_5">
<item>
<widget class="QLabel" name="label_4">
<property name="text">
<string>The options on this page allow you to change parameters that balance data safety and consistency against performance. In general you should be careful with changing anything here, the defaults are good enough in most cases.</string>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QLabel" name="autosaveLabel">
<property name="text">
<string>Autosave delay:</string>
</property>
</widget>
</item>
<item>
<widget class="KPluralHandlingSpinBox" name="kcfg_AutosaveInterval">
<property name="minimum">
<number>0</number>
</property>
<property name="value">
<number>1</number>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item>
<spacer name="verticalSpacer_2">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>138</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
</widget>
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>KUrlRequester</class>
<extends>QFrame</extends>
<header>kurlrequester.h</header>
<container>1</container>
</customwidget>
<customwidget>
<class>KPluralHandlingSpinBox</class>
<extends>QSpinBox</extends>
<header>KPluralHandlingSpinBox</header>
</customwidget>
</customwidgets>
<resources/>
<connections>
<connection>
<sender>kcfg_ReadOnly</sender>
<signal>toggled(bool)</signal>
<receiver>kcfg_AutosaveInterval</receiver>
<slot>setDisabled(bool)</slot>
<hints>
<hint type="sourcelabel">
<x>273</x>
<y>205</y>
</hint>
<hint type="destinationlabel">
<x>157</x>
<y>101</y>
</hint>
</hints>
</connection>
<connection>
<sender>kcfg_ReadOnly</sender>
<signal>toggled(bool)</signal>
<receiver>autosaveLabel</receiver>
<slot>setDisabled(bool)</slot>
<hints>
<hint type="sourcelabel">
<x>273</x>
<y>205</y>
</hint>
<hint type="destinationlabel">
<x>56</x>
<y>101</y>
</hint>
</hints>
</connection>
</connections>
</ui>
......@@ -22,7 +22,6 @@
#include "settingsadaptor.h"
#include "vcarddirresource_debug.h"
#include "dirsettingsdialog.h"
#include <QDir>
#include <QDirIterator>
......@@ -34,19 +33,20 @@
#include <QIcon>
#include <KLocalizedString>
#include <QDebug>
using namespace Akonadi;
VCardDirResource::VCardDirResource(const QString &id)
: ResourceBase(id)
{
VcardDirResourceSettings::instance(KSharedConfig::openConfig());
// setup the resource
new SettingsAdaptor(Settings::self());
new SettingsAdaptor(VcardDirResourceSettings::self());
QDBusConnection::sessionBus().registerObject(QStringLiteral("/Settings"),
Settings::self(), QDBusConnection::ExportAdaptors);
VcardDirResourceSettings::self(), QDBusConnection::ExportAdaptors);
changeRecorder()->itemFetchScope().fetchFullPayload();
connect(this, &VCardDirResource::reloadConfiguration, this, &VCardDirResource::slotReloadConfig);
}
VCardDirResource::~VCardDirResource()
......@@ -55,25 +55,17 @@ VCardDirResource::~VCardDirResource()
mAddressees.clear();
}
void VCardDirResource::aboutToQuit()
void VCardDirResource::slotReloadConfig()
{
Settings::self()->save();
initializeVCardDirectory();
loadAddressees();
synchronize();
}
void VCardDirResource::configure(WId windowId)
void VCardDirResource::aboutToQuit()
{
SettingsDialog dlg(windowId);
dlg.setWindowIcon(QIcon::fromTheme(QStringLiteral("text-directory")));
if (dlg.exec()) {
initializeVCardDirectory();
loadAddressees();
synchronize();
Q_EMIT configurationDialogAccepted();
} else {
Q_EMIT configurationDialogRejected();
}
VcardDirResourceSettings::self()->save();
}
bool VCardDirResource::loadAddressees()
......@@ -121,7 +113,7 @@ bool VCardDirResource::retrieveItem(const Akonadi::Item &item, const QSet<QByteA
void VCardDirResource::itemAdded(const Akonadi::Item &item, const Akonadi::Collection &)
{
if (Settings::self()->readOnly()) {
if (VcardDirResourceSettings::self()->readOnly()) {
Q_EMIT error(i18n("Trying to write to a read-only directory: '%1'", vCardDirectoryName()));
cancelTask();
return;
......@@ -155,7 +147,7 @@ void VCardDirResource::itemAdded(const Akonadi::Item &item, const Akonadi::Colle
void VCardDirResource::itemChanged(const Akonadi::Item &item, const QSet<QByteArray> &)
{
if (Settings::self()->readOnly()) {
if (VcardDirResourceSettings::self()->readOnly()) {
Q_EMIT error(i18n("Trying to write to a read-only directory: '%1'", vCardDirectoryName()));
cancelTask();
return;
......@@ -191,7 +183,7 @@ void VCardDirResource::itemChanged(const Akonadi::Item &item, const QSet<QByteAr
void VCardDirResource::itemRemoved(const Akonadi::Item &item)
{
if (Settings::self()->readOnly()) {
if (VcardDirResourceSettings::self()->readOnly()) {
Q_EMIT error(i18n("Trying to write to a read-only directory: '%1'", vCardDirectoryName()));
cancelTask();
return;
......@@ -215,7 +207,7 @@ void VCardDirResource::retrieveCollections()
QStringList mimeTypes;
mimeTypes << KContacts::Addressee::mimeType();
c.setContentMimeTypes(mimeTypes);
if (Settings::self()->readOnly()) {
if (VcardDirResourceSettings::self()->readOnly()) {
c.setRights(Collection::ReadOnly);
} else {
Collection::Rights rights;
......@@ -252,12 +244,12 @@ void VCardDirResource::retrieveItems(const Akonadi::Collection &)
QString VCardDirResource::vCardDirectoryName() const
{
return Settings::self()->path();
return VcardDirResourceSettings::self()->path();
}
QString VCardDirResource::vCardDirectoryFileName(const QString &file) const
{
return Settings::self()->path() + QDir::separator() + file;
return VcardDirResourceSettings::self()->path() + QDir::separator() + file;
}
void VCardDirResource::initializeVCardDirectory() const
......
......@@ -30,11 +30,10 @@ class VCardDirResource : public Akonadi::ResourceBase, public Akonadi::AgentBase
Q_OBJECT
public:
VCardDirResource(const QString &id);
~VCardDirResource();
explicit VCardDirResource(const QString &id);
~VCardDirResource() override;
public Q_SLOTS:
void configure(WId windowId) override;
void aboutToQuit() override;
protected:
......@@ -51,6 +50,7 @@ protected:
void itemRemoved(const Akonadi::Item &item) override;
private:
void slotReloadConfig();
bool loadAddressees();
QString vCardDirectoryName() const;
QString vCardDirectoryFileName(const QString &file) const;
......
......@@ -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 vCard directory</label>
......
/*
Copyright (c) 2009 Tobias Koenig <tokoe@kde.org>
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,12 +18,11 @@
02110-1301, USA.
*/
#include "dirsettingsdialog.h"
#include "vcarddirsettingswidget.h"
#include "settings.h"
#include <KConfigDialogManager>
#include <KWindowSystem>
#include <KLocalizedString>
#include <QUrl>
......@@ -31,54 +31,32 @@
#include <QPushButton>
#include <QVBoxLayout>
using namespace Akonadi;
SettingsDialog::SettingsDialog(WId windowId)
: QDialog()
VcardDirSettingsWidget::VcardDirSettingsWidget(const KSharedConfigPtr &config, QWidget *parent, const QVariantList &args)
: Akonadi::AgentConfigurationBase(config, parent, args)
{
QWidget *mainWidget = new QWidget(this);
QVBoxLayout *mainLayout = new QVBoxLayout(this);
mainLayout->addWidget(mainWidget);
VcardDirResourceSettings::instance(config);
QWidget *mainWidget = new QWidget(parent);
ui.setupUi(mainWidget);
parent->layout()->addWidget(mainWidget);
ui.kcfg_Path->setMode(KFile::LocalOnly | KFile::Directory);
QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, this);
mOkButton = buttonBox->button(QDialogButtonBox::Ok);
mOkButton->setDefault(true);
mOkButton->setShortcut(Qt::CTRL | Qt::Key_Return);
connect(buttonBox, &QDialogButtonBox::accepted, this, &SettingsDialog::accept);
connect(buttonBox, &QDialogButtonBox::rejected, this, &SettingsDialog::reject);
mainLayout->addWidget(buttonBox);
if (windowId) {
KWindowSystem::setMainWindow(this, windowId);
}
connect(mOkButton, &QPushButton::clicked, this, &SettingsDialog::save);
connect(ui.kcfg_Path, &KUrlRequester::textChanged, this, &VcardDirSettingsWidget::validate);
connect(ui.kcfg_ReadOnly, &QCheckBox::toggled, this, &VcardDirSettingsWidget::validate);
connect(ui.kcfg_Path, &KUrlRequester::textChanged, this, &SettingsDialog::validate);
connect(ui.kcfg_ReadOnly, &QCheckBox::toggled, this, &SettingsDialog::validate);
QTimer::singleShot(0, this, &SettingsDialog::validate);
ui.label_2->setMinimumSize(ui.label_2->sizeHint());
ui.label_3->setMinimumSize(ui.label_3->sizeHint());
ui.kcfg_Path->setUrl(QUrl::fromLocalFile(Settings::self()->path()));
ui.kcfg_Path->setUrl(QUrl::fromLocalFile(VcardDirResourceSettings::self()->path()));
ui.kcfg_AutosaveInterval->setSuffix(ki18np(" minute", " minutes"));
mManager = new KConfigDialogManager(this, Settings::self());
mManager->updateWidgets();
}
void SettingsDialog::save()
{
mManager->updateSettings();
Settings::self()->setPath(ui.kcfg_Path->url().toLocalFile());
Settings::self()->save();
mManager = new KConfigDialogManager(mainWidget, VcardDirResourceSettings::self());
}
void SettingsDialog::validate()
void VcardDirSettingsWidget::validate()
{
const QUrl currentUrl = ui.kcfg_Path->url();
if (currentUrl.isEmpty()) {
mOkButton->setEnabled(false);
Q_EMIT enableOkButton(false);
return;
}
......@@ -89,5 +67,20 @@ void SettingsDialog::validate()
} else {
ui.kcfg_ReadOnly->setEnabled(true);
}
mOkButton->setEnabled(true);
Q_EMIT enableOkButton(true);
}
void VcardDirSettingsWidget::load()
{
mManager->updateWidgets();
QTimer::singleShot(0, this, &VcardDirSettingsWidget::validate);
}
bool VcardDirSettingsWidget::save() const
{
mManager->updateSettings();
VcardDirResourceSettings::self()->setPath(ui.kcfg_Path->url().toLocalFile());
VcardDirResourceSettings::self()->save();
return true;
}
/*
Copyright (c) 2009 Tobias Koenig <tokoe@kde.org>
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
......@@ -20,27 +21,26 @@
#ifndef DIRSETTINGSDIALOG_H
#define DIRSETTINGSDIALOG_H
#include "ui_settingsdialog.h"
#include "ui_vcarddiragentsettingswidget.h"
#include <AkonadiCore/AgentConfigurationBase>
#include <QDialog>
#include <QPushButton>
class KConfigDialogManager;
namespace Akonadi {
class SettingsDialog : public QDialog
class VcardDirSettingsWidget : public Akonadi::AgentConfigurationBase
{
Q_OBJECT
public:
explicit SettingsDialog(WId windowId);
explicit VcardDirSettingsWidget(const KSharedConfigPtr &config, QWidget *parent, const QVariantList &args);
void load() override;
bool save() const override;
private:
void save();
void validate();
Ui::SettingsDialog ui;
Ui::VcardDirsAgentSettingsWidget ui;
KConfigDialogManager *mManager = nullptr;
QPushButton *mOkButton = nullptr;
};
}
AKONADI_AGENTCONFIG_FACTORY(VcardDirSettingsWidgetFactory, "vcarddirconfig.json", VcardDirSettingsWidget)
#endif
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