Commit e9f67828 authored by Laurent Montel's avatar Laurent Montel
Browse files

Fix Bug 431126 - KNotes cannot be configured using the GUI

BUG: 431126
parent 7d31abff
Pipeline #46786 passed with stage
in 15 minutes and 27 seconds
......@@ -123,7 +123,7 @@ install(TARGETS knotes ${KDE_INSTALL_TARGETS_DEFAULT_ARGS} )
########### next target ###############
set(kcm_knotes_PART_SRCS configdialog/knotedisplayconfigwidget.cpp configdialog/knoteeditorconfigwidget.cpp configdialog/knotecollectionconfigwidget.cpp knotes_debug.cpp)
set(kcm_knotes_PART_SRCS knoteconfigmodule.cpp kcm_knotes.cpp configdialog/knotedisplayconfigwidget.cpp configdialog/knoteeditorconfigwidget.cpp configdialog/knotecollectionconfigwidget.cpp knotes_debug.cpp)
add_library(kcm_knote MODULE ${kcm_knotes_PART_SRCS} )
if (COMPILE_WITH_UNITY_CMAKE_SUPPORT)
......
......@@ -10,7 +10,6 @@
#include "knoteconfigdialog.h"
#include "notesharedglobalconfig.h"
#include "knotecollectionconfigwidget.h"
#include "knotedisplayconfigwidget.h"
#include "knoteeditorconfigwidget.h"
#include "knotesglobalconfig.h"
......@@ -63,248 +62,3 @@ void KNoteConfigDialog::slotOk()
KNotesGlobalConfig::self()->save();
}
extern "C"
{
Q_DECL_EXPORT KCModule *create_knote_config_display(QWidget *parent)
{
return new KNoteDisplayConfig(parent);
}
}
extern "C"
{
Q_DECL_EXPORT KCModule *create_knote_config_collection(QWidget *parent)
{
return new KNoteCollectionConfig(parent);
}
}
extern "C"
{
Q_DECL_EXPORT KCModule *create_knote_config_editor(QWidget *parent)
{
return new KNoteEditorConfig(parent);
}
}
extern "C"
{
Q_DECL_EXPORT KCModule *create_knote_config_action(QWidget *parent)
{
return new NoteShared::NoteActionConfig(parent);
}
}
extern "C"
{
Q_DECL_EXPORT KCModule *create_knote_config_network(QWidget *parent)
{
return new NoteShared::NoteNetworkConfig(parent);
}
}
extern "C"
{
Q_DECL_EXPORT KCModule *create_knote_config_print(QWidget *parent)
{
return new KNotePrintConfig(parent);
}
}
extern "C"
{
Q_DECL_EXPORT KCModule *create_knote_config_misc(QWidget *parent)
{
return new KNoteMiscConfig(parent);
}
}
KNoteDisplayConfig::KNoteDisplayConfig(QWidget *parent)
: KCModule(parent)
{
auto *lay = new QVBoxLayout(this);
QWidget *w = new KNoteDisplayConfigWidget(true);
lay->addWidget(w);
lay->addStretch();
addConfig(KNotesGlobalConfig::self(), w);
load();
}
void KNoteDisplayConfig::load()
{
KCModule::load();
}
void KNoteDisplayConfig::save()
{
KCModule::save();
}
KNoteEditorConfig::KNoteEditorConfig(QWidget *parent)
: KCModule(parent)
{
auto *lay = new QVBoxLayout(this);
QWidget *w = new KNoteEditorConfigWidget(this);
lay->addWidget(w);
lay->addStretch();
addConfig(KNotesGlobalConfig::self(), w);
load();
}
void KNoteEditorConfig::save()
{
KCModule::save();
}
void KNoteEditorConfig::load()
{
KCModule::load();
}
KNoteMiscConfig::KNoteMiscConfig(QWidget *parent)
: KCModule(parent)
{
auto *lay = new QVBoxLayout(this);
lay->setContentsMargins(0, 0, 0, 0);
QCheckBox *kcfg_SystemTrayShowNotes = new QCheckBox(i18n("Show number of notes in tray icon"), this);
kcfg_SystemTrayShowNotes->setObjectName(QStringLiteral("kcfg_SystemTrayShowNotes"));
lay->addWidget(kcfg_SystemTrayShowNotes);
auto *hbox = new QHBoxLayout;
lay->addLayout(hbox);
QLabel *label_DefaultTitle = new QLabel(i18n("Default Title:"), this);
hbox->addWidget(label_DefaultTitle);
mDefaultTitle = new QLineEdit(this);
label_DefaultTitle->setBuddy(mDefaultTitle);
hbox->addWidget(mDefaultTitle);
QLabel *howItWorks = new QLabel(i18n("<a href=\"whatsthis\">How does this work?</a>"));
connect(howItWorks, &QLabel::linkActivated, this, &KNoteMiscConfig::slotHelpLinkClicked);
lay->addWidget(howItWorks);
addConfig(KNotesGlobalConfig::self(), this);
howItWorks->setContextMenuPolicy(Qt::NoContextMenu);
lay->addStretch();
load();
connect(mDefaultTitle, &QLineEdit::textChanged, this, &KNoteMiscConfig::markAsChanged);
}
void KNoteMiscConfig::load()
{
KCModule::load();
mDefaultTitle->setText(NoteShared::NoteSharedGlobalConfig::self()->defaultTitle());
}
void KNoteMiscConfig::save()
{
KCModule::save();
NoteShared::NoteSharedGlobalConfig::self()->setDefaultTitle(mDefaultTitle->text());
NoteShared::NoteSharedGlobalConfig::self()->save();
}
void KNoteMiscConfig::defaults()
{
KCModule::defaults();
const bool bUseDefaults = NoteShared::NoteSharedGlobalConfig::self()->useDefaults(true);
mDefaultTitle->setText(NoteShared::NoteSharedGlobalConfig::self()->defaultTitle());
NoteShared::NoteSharedGlobalConfig::self()->useDefaults(bUseDefaults);
}
void KNoteMiscConfig::slotHelpLinkClicked(const QString &)
{
const QString help
= i18n("<qt>"
"<p>You can customize title note. "
"You can use:</p>"
"<ul>"
"<li>%d current date (short format)</li>"
"<li>%l current date (long format)</li>"
"<li>%t current time</li>"
"</ul>"
"</qt>");
QWhatsThis::showText(QCursor::pos(), help);
}
KNotePrintConfig::KNotePrintConfig(QWidget *parent)
: KCModule(parent)
{
auto *lay = new QVBoxLayout(this);
QWidget *w = new QWidget(this);
lay->addWidget(w);
auto *layout = new QGridLayout(w);
layout->setContentsMargins(0, 0, 0, 0);
QLabel *label_PrintAction = new QLabel(i18n("Theme:"), this);
layout->addWidget(label_PrintAction, 0, 0);
mSelectTheme = new KNotePrintSelectThemeComboBox(this);
connect(mSelectTheme, qOverload<int>(&QComboBox::activated), this, &KNotePrintConfig::slotThemeChanged);
label_PrintAction->setBuddy(mSelectTheme);
layout->addWidget(mSelectTheme, 0, 1);
if (KAuthorized::authorize(QStringLiteral("ghns"))) {
auto *getNewTheme = new QToolButton;
getNewTheme->setIcon(QIcon::fromTheme(QStringLiteral("get-hot-new-stuff")));
getNewTheme->setToolTip(i18n("Download new printing themes"));
connect(getNewTheme, &QToolButton::clicked, this, &KNotePrintConfig::slotDownloadNewThemes);
layout->addWidget(getNewTheme, 0, 2);
}
lay->addStretch();
load();
}
void KNotePrintConfig::slotDownloadNewThemes()
{
QPointer<KNS3::DownloadDialog> downloadThemesDialog
= new KNS3::DownloadDialog(QStringLiteral("knotes_printing_theme.knsrc"));
if (downloadThemesDialog->exec()) {
if (!downloadThemesDialog->changedEntries().isEmpty()) {
mSelectTheme->loadThemes();
}
}
delete downloadThemesDialog;
}
void KNotePrintConfig::slotThemeChanged()
{
Q_EMIT changed(true);
}
void KNotePrintConfig::save()
{
KNotesGlobalConfig::self()->setTheme(mSelectTheme->selectedTheme());
}
void KNotePrintConfig::load()
{
mSelectTheme->loadThemes();
}
void KNotePrintConfig::defaults()
{
mSelectTheme->selectDefaultTheme();
Q_EMIT changed(true);
}
KNoteCollectionConfig::KNoteCollectionConfig(QWidget *parent)
: KCModule(parent)
{
auto *lay = new QHBoxLayout(this);
mCollectionConfigWidget = new KNoteCollectionConfigWidget;
lay->addWidget(mCollectionConfigWidget);
connect(mCollectionConfigWidget, &KNoteCollectionConfigWidget::emitChanged, this, &KNoteCollectionConfig::markAsChanged);
load();
}
void KNoteCollectionConfig::save()
{
mCollectionConfigWidget->save();
}
void KNoteCollectionConfig::load()
{
//Nothing
}
......@@ -14,11 +14,6 @@
#include <KCModule>
#include <KCMultiDialog>
class KNoteCollectionConfigWidget;
class KNotePrintSelectThemeComboBox;
class QLineEdit;
class KNOTES_EXPORT KNoteConfigDialog : public KCMultiDialog
{
Q_OBJECT
......@@ -30,70 +25,4 @@ public Q_SLOTS:
void slotOk();
};
class KNoteDisplayConfig : public KCModule
{
Q_OBJECT
public:
explicit KNoteDisplayConfig(QWidget *parent);
/** Reimplemented from KCModule. */
void load() override;
void save() override;
};
class KNoteEditorConfig : public KCModule
{
Q_OBJECT
public:
explicit KNoteEditorConfig(QWidget *parent);
/** Reimplemented from KCModule. */
void load() override;
void save() override;
};
class KNoteMiscConfig : public KCModule
{
Q_OBJECT
public:
explicit KNoteMiscConfig(QWidget *parent);
/** Reimplemented from KCModule. */
void load() override;
void save() override;
void defaults() override;
private Q_SLOTS:
void slotHelpLinkClicked(const QString &);
private:
QLineEdit *mDefaultTitle = nullptr;
};
class KNotePrintConfig : public KCModule
{
Q_OBJECT
public:
explicit KNotePrintConfig(QWidget *parent);
/** Reimplemented from KCModule. */
void load() override;
void save() override;
void defaults() override;
private Q_SLOTS:
void slotThemeChanged();
void slotDownloadNewThemes();
private:
KNotePrintSelectThemeComboBox *mSelectTheme = nullptr;
};
class KNoteCollectionConfig : public KCModule
{
Q_OBJECT
public:
explicit KNoteCollectionConfig(QWidget *parent);
/** Reimplemented from KCModule. */
void load() override;
void save() override;
private:
KNoteCollectionConfigWidget *mCollectionConfigWidget = nullptr;
};
#endif
/*
SPDX-FileCopyrightText: 2021 Laurent Montel <montel@kde.org>
SPDX-License-Identifier: GPL-2.0-or-later
*/
#include <KCModule>
#include <config/noteactionconfig.h>
#include <config/notenetworkconfig.h>
#include "knoteconfigmodule.h"
extern "C"
{
Q_DECL_EXPORT KCModule *create_knote_config_display(QWidget *parent)
{
return new KNoteDisplayConfig(parent);
}
}
extern "C"
{
Q_DECL_EXPORT KCModule *create_knote_config_collection(QWidget *parent)
{
return new KNoteCollectionConfig(parent);
}
}
extern "C"
{
Q_DECL_EXPORT KCModule *create_knote_config_editor(QWidget *parent)
{
return new KNoteEditorConfig(parent);
}
}
extern "C"
{
Q_DECL_EXPORT KCModule *create_knote_config_action(QWidget *parent)
{
return new NoteShared::NoteActionConfig(parent);
}
}
extern "C"
{
Q_DECL_EXPORT KCModule *create_knote_config_network(QWidget *parent)
{
return new NoteShared::NoteNetworkConfig(parent);
}
}
extern "C"
{
Q_DECL_EXPORT KCModule *create_knote_config_print(QWidget *parent)
{
return new KNotePrintConfig(parent);
}
}
extern "C"
{
Q_DECL_EXPORT KCModule *create_knote_config_misc(QWidget *parent)
{
return new KNoteMiscConfig(parent);
}
}
/*
SPDX-FileCopyrightText: 2021 Laurent Montel <montel@kde.org>
SPDX-License-Identifier: GPL-2.0-or-later
*/
#include "knoteconfigmodule.h"
#include <config-knotes.h>
#include "knotesglobalconfig.h"
#include "notesharedglobalconfig.h"
#include "config/noteactionconfig.h"
#include "config/notenetworkconfig.h"
#include "print/knoteprintselectthemecombobox.h"
#include <KAuthorized>
#include <KLocalizedString>
#include <KNS3/DownloadDialog>
#include "configdialog/knotedisplayconfigwidget.h"
#include "configdialog/knoteeditorconfigwidget.h"
#include "configdialog/knotecollectionconfigwidget.h"
#include <QCheckBox>
#include <QLabel>
#include <QLineEdit>
#include <QPointer>
#include <QPushButton>
#include <QToolButton>
#include <QVBoxLayout>
#include <QWhatsThis>
KNoteDisplayConfig::KNoteDisplayConfig(QWidget *parent)
: KCModule(parent)
{
auto *lay = new QVBoxLayout(this);
QWidget *w = new KNoteDisplayConfigWidget(true);
lay->addWidget(w);
lay->addStretch();
addConfig(KNotesGlobalConfig::self(), w);
load();
}
void KNoteDisplayConfig::load()
{
KCModule::load();
}
void KNoteDisplayConfig::save()
{
KCModule::save();
}
KNoteEditorConfig::KNoteEditorConfig(QWidget *parent)
: KCModule(parent)
{
auto *lay = new QVBoxLayout(this);
QWidget *w = new KNoteEditorConfigWidget(this);
lay->addWidget(w);
lay->addStretch();
addConfig(KNotesGlobalConfig::self(), w);
load();
}
void KNoteEditorConfig::save()
{
KCModule::save();
}
void KNoteEditorConfig::load()
{
KCModule::load();
}
KNoteMiscConfig::KNoteMiscConfig(QWidget *parent)
: KCModule(parent)
{
auto *lay = new QVBoxLayout(this);
lay->setContentsMargins(0, 0, 0, 0);
QCheckBox *kcfg_SystemTrayShowNotes = new QCheckBox(i18n("Show number of notes in tray icon"), this);
kcfg_SystemTrayShowNotes->setObjectName(QStringLiteral("kcfg_SystemTrayShowNotes"));
lay->addWidget(kcfg_SystemTrayShowNotes);
auto *hbox = new QHBoxLayout;
lay->addLayout(hbox);
QLabel *label_DefaultTitle = new QLabel(i18n("Default Title:"), this);
hbox->addWidget(label_DefaultTitle);
mDefaultTitle = new QLineEdit(this);
label_DefaultTitle->setBuddy(mDefaultTitle);
hbox->addWidget(mDefaultTitle);
QLabel *howItWorks = new QLabel(i18n("<a href=\"whatsthis\">How does this work?</a>"));
connect(howItWorks, &QLabel::linkActivated, this, &KNoteMiscConfig::slotHelpLinkClicked);
lay->addWidget(howItWorks);
addConfig(KNotesGlobalConfig::self(), this);
howItWorks->setContextMenuPolicy(Qt::NoContextMenu);
lay->addStretch();
load();
connect(mDefaultTitle, &QLineEdit::textChanged, this, &KNoteMiscConfig::markAsChanged);
}
void KNoteMiscConfig::load()
{
KCModule::load();
mDefaultTitle->setText(NoteShared::NoteSharedGlobalConfig::self()->defaultTitle());
}
void KNoteMiscConfig::save()
{
KCModule::save();
NoteShared::NoteSharedGlobalConfig::self()->setDefaultTitle(mDefaultTitle->text());
NoteShared::NoteSharedGlobalConfig::self()->save();
}
void KNoteMiscConfig::defaults()
{
KCModule::defaults();
const bool bUseDefaults = NoteShared::NoteSharedGlobalConfig::self()->useDefaults(true);
mDefaultTitle->setText(NoteShared::NoteSharedGlobalConfig::self()->defaultTitle());
NoteShared::NoteSharedGlobalConfig::self()->useDefaults(bUseDefaults);
}
void KNoteMiscConfig::slotHelpLinkClicked(const QString &)
{
const QString help
= i18n("<qt>"
"<p>You can customize title note. "
"You can use:</p>"
"<ul>"
"<li>%d current date (short format)</li>"
"<li>%l current date (long format)</li>"
"<li>%t current time</li>"
"</ul>"
"</qt>");
QWhatsThis::showText(QCursor::pos(), help);
}
KNotePrintConfig::KNotePrintConfig(QWidget *parent)
: KCModule(parent)
{
auto *lay = new QVBoxLayout(this);
QWidget *w = new QWidget(this);
lay->addWidget(w);
auto *layout = new QGridLayout(w);
layout->setContentsMargins(0, 0, 0, 0);
QLabel *label_PrintAction = new QLabel(i18n("Theme:"), this);
layout->addWidget(label_PrintAction, 0, 0);
mSelectTheme = new KNotePrintSelectThemeComboBox(this);
connect(mSelectTheme, qOverload<int>(&QComboBox::activated), this, &KNotePrintConfig::slotThemeChanged);
label_PrintAction->setBuddy(mSelectTheme);
layout->addWidget(mSelectTheme, 0, 1);
if (KAuthorized::authorize(QStringLiteral("ghns"))) {
auto *getNewTheme = new QToolButton;
getNewTheme->setIcon(QIcon::fromTheme(QStringLiteral("get-hot-new-stuff")));
getNewTheme->setToolTip(i18n("Download new printing themes"));
connect(getNewTheme, &QToolButton::clicked, this, &KNotePrintConfig::slotDownloadNewThemes);
layout->addWidget(getNewTheme, 0, 2);
}
lay->addStretch();
load();
}
void KNotePrintConfig::slotDownloadNewThemes()
{
QPointer<KNS3::DownloadDialog> downloadThemesDialog
= new KNS3::DownloadDialog(QStringLiteral("knotes_printing_theme.knsrc"));
if (downloadThemesDialog->exec()) {
if (!downloadThemesDialog->changedEntries().isEmpty()) {
mSelectTheme->loadThemes();
}
}
delete downloadThemesDialog;
}
void KNotePrintConfig::slotThemeChanged()
{
Q_EMIT changed(true);
}
void KNotePrintConfig::save()
{
KNotesGlobalConfig::self()->setTheme(mSelectTheme->selectedTheme());
}
void KNotePrintConfig::load()
{
mSelectTheme->loadThemes();
}
void KNotePrintConfig::defaults()
{
mSelectTheme->selectDefaultTheme();
Q_EMIT changed(true);
}
KNoteCollectionConfig::KNoteCollectionConfig(QWidget *parent)