Commit 056bae88 authored by Laurent Montel's avatar Laurent Montel 😁
Browse files

Split more class

parent a1c1fea5
......@@ -61,8 +61,9 @@ install(TARGETS
set(kcm_korganizer_PART_SRCS
kcmdesignerfields.cpp
koprefsuserfeedback.cpp
koprefsdesignerfields.cpp
prefs/koprefsuserfeedback.cpp
prefs/koprefsdesignerfields.cpp
prefs/koprefsdialogplugins.cpp
korganizer_debug.cpp
prefs/koprefsdialog.cpp
widgets/kitemiconcheckcombo.cpp
......
......@@ -66,8 +66,3 @@ QString KOPrefsDesignerFields::applicationName()
{
return QStringLiteral("KORGANIZER");
}
KOPrefsDesignerFields::KOPrefsDesignerFields()
{
}
......@@ -83,11 +83,6 @@
#include <QFontDialog>
#include <QCheckBox>
#ifdef WITH_KUSERFEEDBACK
#include <KUserFeedback/FeedbackConfigWidget>
#include "userfeedback/userfeedbackmanager.h"
#endif
KOPrefsDialogMain::KOPrefsDialogMain(QWidget *parent)
: KCModule(parent)
{
......@@ -1426,322 +1421,3 @@ Q_DECL_EXPORT KCModule *create_korganizerconfigfreebusy(QWidget *parent, const c
}
}
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
class PluginItem : public QTreeWidgetItem
{
public:
PluginItem(QTreeWidget *parent, const KService::Ptr &service)
: QTreeWidgetItem(parent, QStringList(service->name()))
, mService(service)
{
}
PluginItem(QTreeWidgetItem *parent, const KService::Ptr &service)
: QTreeWidgetItem(parent, QStringList(service->name()))
, mService(service)
{
}
KService::Ptr service()
{
return mService;
}
private:
KService::Ptr mService;
};
/**
Dialog for selecting and configuring KOrganizer plugins
*/
KOPrefsDialogPlugins::KOPrefsDialogPlugins(QWidget *parent)
: KCModule(parent)
{
QBoxLayout *topTopLayout = new QVBoxLayout(this);
mTreeWidget = new QTreeWidget(this);
mTreeWidget->setColumnCount(1);
mTreeWidget->setHeaderLabel(i18nc("@title:column plugin name", "Name"));
topTopLayout->addWidget(mTreeWidget);
mDescription = new QLabel(this);
mDescription->setAlignment(Qt::AlignVCenter);
mDescription->setWordWrap(true);
mDescription->setFrameShape(QLabel::Panel);
mDescription->setFrameShadow(QLabel::Sunken);
mDescription->setMinimumSize(QSize(0, 55));
QSizePolicy policy(QSizePolicy::MinimumExpanding, QSizePolicy::Fixed);
policy.setHorizontalStretch(0);
policy.setVerticalStretch(0);
policy.setHeightForWidth(mDescription->sizePolicy().hasHeightForWidth());
mDescription->setSizePolicy(policy);
topTopLayout->addWidget(mDescription);
QWidget *buttonRow = new QWidget(this);
QBoxLayout *buttonRowLayout = new QHBoxLayout(buttonRow);
buttonRowLayout->setContentsMargins(0, 0, 0, 0);
mConfigureButton = new QPushButton(buttonRow);
KGuiItem::assign(mConfigureButton, KGuiItem(i18nc("@action:button", "Configure &Plugin..."),
QStringLiteral("configure"), QString(),
i18nc("@info:whatsthis",
"This button allows you to configure"
" the plugin that you have selected in the list above")));
buttonRowLayout->addWidget(mConfigureButton);
buttonRowLayout->addItem(new QSpacerItem(1, 1, QSizePolicy::Expanding));
topTopLayout->addWidget(buttonRow);
mPositioningGroupBox = new QGroupBox(i18nc("@title:group", "Position"), this);
//mPositionMonthTop = new QCheckBox(
//i18nc( "@option:check", "Show in the month view" ), mPositioningGroupBox );
mPositionAgendaTop = new QRadioButton(
i18nc("@option:check", "Show at the top of the agenda views"), mPositioningGroupBox);
mPositionAgendaBottom = new QRadioButton(
i18nc("@option:check", "Show at the bottom of the agenda views"), mPositioningGroupBox);
QVBoxLayout *positioningLayout = new QVBoxLayout(mPositioningGroupBox);
//positioningLayout->addWidget( mPositionMonthTop );
positioningLayout->addWidget(mPositionAgendaTop);
positioningLayout->addWidget(mPositionAgendaBottom);
positioningLayout->addStretch(1);
topTopLayout->addWidget(mPositioningGroupBox);
connect(mConfigureButton, &QPushButton::clicked, this, &KOPrefsDialogPlugins::configure);
connect(mPositionAgendaTop, &QRadioButton::clicked, this,
&KOPrefsDialogPlugins::positioningChanged);
connect(mPositionAgendaBottom, &QRadioButton::clicked, this,
&KOPrefsDialogPlugins::positioningChanged);
connect(mTreeWidget, &QTreeWidget::itemSelectionChanged, this,
&KOPrefsDialogPlugins::selectionChanged);
connect(mTreeWidget, &QTreeWidget::itemChanged, this, &KOPrefsDialogPlugins::selectionChanged);
connect(mTreeWidget, &QTreeWidget::itemClicked, this, &KOPrefsDialogPlugins::slotConfigChanged);
load();
selectionChanged();
}
KOPrefsDialogPlugins::~KOPrefsDialogPlugins()
{
delete mDecorations;
delete mOthers;
}
void KOPrefsDialogPlugins::slotConfigChanged()
{
Q_EMIT markAsChanged();
}
void KOPrefsDialogPlugins::load()
{
mTreeWidget->clear();
const KService::List plugins = KOCore::self()->availablePlugins() + KOCore::self()->availableParts();
EventViews::PrefsPtr viewPrefs = KOPrefs::instance()->eventViewsPreferences();
QStringList selectedPlugins = viewPrefs->selectedPlugins();
mDecorations = new QTreeWidgetItem(mTreeWidget,
QStringList(i18nc("@title:group", "Calendar Decorations")));
mOthers = new QTreeWidgetItem(mTreeWidget,
QStringList(i18nc("@title:group", "Other Plugins")));
KService::List::ConstIterator it;
KService::List::ConstIterator end(plugins.constEnd());
for (it = plugins.constBegin(); it != end; ++it) {
QTreeWidgetItem *item = nullptr;
if ((*it)->hasServiceType(EventViews::CalendarDecoration::Decoration::serviceType())) {
item = new PluginItem(mDecorations, *it);
} else {
continue;
}
if (selectedPlugins.contains((*it)->desktopEntryName())) {
item->setCheckState(0, Qt::Checked);
} else {
item->setCheckState(0, Qt::Unchecked);
}
}
mDecorations->setExpanded(true);
mOthers->setExpanded(true);
//Disable for the moment it crashs. Not understand why
#if QT_VERSION < QT_VERSION_CHECK(5, 14, 0)
mDecorationsAtMonthViewTop = KOPrefs::instance()->decorationsAtMonthViewTop().toSet();
mDecorationsAtAgendaViewTop = viewPrefs->decorationsAtAgendaViewTop().toSet();
mDecorationsAtAgendaViewBottom = viewPrefs->decorationsAtAgendaViewBottom().toSet();
#else
const auto monthViewTop = KOPrefs::instance()->decorationsAtMonthViewTop();
mDecorationsAtMonthViewTop = QSet<QString>(monthViewTop.begin(), monthViewTop.end());
const auto agendaViewTop = viewPrefs->decorationsAtAgendaViewTop();
mDecorationsAtAgendaViewTop = QSet<QString>(agendaViewTop.begin(), agendaViewTop.end());
const auto agendaViewBottom = viewPrefs->decorationsAtAgendaViewBottom();
mDecorationsAtAgendaViewBottom = QSet<QString>(agendaViewBottom.begin(), agendaViewBottom.end());
#endif
}
void KOPrefsDialogPlugins::save()
{
QStringList selectedPlugins;
for (int i = 0; i < mTreeWidget->topLevelItemCount(); ++i) {
QTreeWidgetItem *serviceTypeGroup = mTreeWidget->topLevelItem(i);
for (int j = 0; j < serviceTypeGroup->childCount(); ++j) {
PluginItem *item = static_cast<PluginItem *>(serviceTypeGroup->child(j));
if (item->checkState(0) == Qt::Checked) {
selectedPlugins.append(item->service()->desktopEntryName());
}
}
}
EventViews::PrefsPtr viewPrefs = KOPrefs::instance()->eventViewsPreferences();
viewPrefs->setSelectedPlugins(selectedPlugins);
KOPrefs::instance()->setDecorationsAtMonthViewTop(mDecorationsAtMonthViewTop.values());
viewPrefs->setDecorationsAtAgendaViewTop(mDecorationsAtAgendaViewTop.values());
viewPrefs->setDecorationsAtAgendaViewBottom(mDecorationsAtAgendaViewBottom.values());
}
void KOPrefsDialogPlugins::configure()
{
if (mTreeWidget->selectedItems().count() != 1) {
return;
}
PluginItem *item = static_cast<PluginItem *>(mTreeWidget->selectedItems().last());
if (!item) {
return;
}
CalendarSupport::Plugin *plugin = KOCore::self()->loadPlugin(item->service());
if (plugin) {
plugin->configure(this);
delete plugin;
slotConfigChanged();
} else {
KMessageBox::sorry(this,
i18nc("@info", "Unable to configure this plugin"),
QStringLiteral("PluginConfigUnable"));
}
}
void KOPrefsDialogPlugins::positioningChanged()
{
if (mTreeWidget->selectedItems().count() != 1) {
return;
}
PluginItem *item = dynamic_cast<PluginItem *>(mTreeWidget->selectedItems().last());
if (!item) {
return;
}
const QString decoration = item->service()->desktopEntryName();
/*if ( mPositionMonthTop->checkState() == Qt::Checked ) {
if ( !mDecorationsAtMonthViewTop.contains( decoration ) ) {
mDecorationsAtMonthViewTop.insert( decoration );
}
} else {
mDecorationsAtMonthViewTop.remove( decoration );
}*/
if (mPositionAgendaTop->isChecked()) {
if (!mDecorationsAtAgendaViewTop.contains(decoration)) {
mDecorationsAtAgendaViewTop.insert(decoration);
}
} else {
mDecorationsAtAgendaViewTop.remove(decoration);
}
if (mPositionAgendaBottom->isChecked()) {
if (!mDecorationsAtAgendaViewBottom.contains(decoration)) {
mDecorationsAtAgendaViewBottom.insert(decoration);
}
} else {
mDecorationsAtAgendaViewBottom.remove(decoration);
}
slotConfigChanged();
}
void KOPrefsDialogPlugins::selectionChanged()
{
mPositioningGroupBox->hide();
//mPositionMonthTop->setChecked( false );
mPositionAgendaTop->setChecked(false);
mPositionAgendaBottom->setChecked(false);
if (mTreeWidget->selectedItems().count() != 1) {
mConfigureButton->setEnabled(false);
mDescription->setText(QString());
return;
}
PluginItem *item = dynamic_cast<PluginItem *>(mTreeWidget->selectedItems().last());
if (!item) {
mConfigureButton->setEnabled(false);
mConfigureButton->hide();
mDescription->setText(QString());
return;
}
QVariant variant = item->service()->property(QStringLiteral("X-KDE-KOrganizer-HasSettings"));
bool hasSettings = false;
if (variant.isValid()) {
hasSettings = variant.toBool();
}
mDescription->setText(item->service()->comment());
if (!hasSettings) {
mConfigureButton->hide();
} else {
mConfigureButton->show();
mConfigureButton->setEnabled(item->checkState(0) == Qt::Checked);
}
if (item->service()->hasServiceType(
EventViews::CalendarDecoration::Decoration::serviceType())) {
bool hasPosition = false;
QString decoration = item->service()->desktopEntryName();
/*if ( mDecorationsAtMonthViewTop.contains( decoration ) ) {
mPositionMonthTop->setChecked( true );
hasPosition = true;
}*/
if (mDecorationsAtAgendaViewTop.contains(decoration)) {
mPositionAgendaTop->setChecked(true);
hasPosition = true;
}
if (mDecorationsAtAgendaViewBottom.contains(decoration)) {
mPositionAgendaBottom->setChecked(true);
hasPosition = true;
}
if (!hasPosition) {
// no position has been selected, so default to Agenda Top
mDecorationsAtAgendaViewTop << decoration;
mPositionAgendaTop->setChecked(true);
}
mPositioningGroupBox->setEnabled(item->checkState(0) == Qt::Checked);
mPositioningGroupBox->show();
}
slotConfigChanged();
}
extern "C"
{
Q_DECL_EXPORT KCModule *create_korganizerconfigplugins(QWidget *parent, const char *)
{
return new KOPrefsDialogPlugins(parent);
}
}
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
......@@ -161,38 +161,4 @@ private:
Ui::KOGroupwarePrefsPage *mGroupwarePage = nullptr;
};
class KCM_KORGANIZER_EXPORT KOPrefsDialogPlugins : public KCModule
{
Q_OBJECT
public:
explicit KOPrefsDialogPlugins(QWidget *parent);
~KOPrefsDialogPlugins() override;
void save() override;
void load() override;
protected Q_SLOTS:
void configure();
void selectionChanged();
void positioningChanged();
private:
void slotConfigChanged();
void buildList();
QTreeWidget *mTreeWidget = nullptr;
QLabel *mDescription = nullptr;
QPushButton *mConfigureButton = nullptr;
QGroupBox *mPositioningGroupBox = nullptr;
QRadioButton *mPositionAgendaTop = nullptr;
QRadioButton *mPositionAgendaBottom = nullptr;
QTreeWidgetItem *mDecorations = nullptr;
QTreeWidgetItem *mOthers = nullptr;
QSet<QString> mDecorationsAtMonthViewTop;
QSet<QString> mDecorationsAtAgendaViewTop;
QSet<QString> mDecorationsAtAgendaViewBottom;
};
#endif
/*
This file is part of KOrganizer.
Copyright (c) 2000,2001,2002,2003 Cornelius Schumacher <schumacher@kde.org>
Copyright (C) 2003-2004 Reinhold Kainhofer <reinhold@kainhofer.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, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
As a special exception, permission is given to link this program
with any edition of Qt, and distribute the resulting executable,
without including the source code for Qt in the source distribution.
*/
#include "koprefsdialogplugins.h"
#include "koprefs.h"
#include "kocore.h"
#include <KGuiItem>
#include <KService>
#include <KMessageBox>
#include <KLocalizedString>
#include <QLabel>
#include <QTreeWidget>
#include <QGroupBox>
#include <QRadioButton>
#include <QPushButton>
#include <QVBoxLayout>
#include <CalendarSupport/KCalPrefs>
class PluginItem : public QTreeWidgetItem
{
public:
PluginItem(QTreeWidget *parent, const KService::Ptr &service)
: QTreeWidgetItem(parent, QStringList(service->name()))
, mService(service)
{
}
PluginItem(QTreeWidgetItem *parent, const KService::Ptr &service)
: QTreeWidgetItem(parent, QStringList(service->name()))
, mService(service)
{
}
KService::Ptr service()
{
return mService;
}
private:
KService::Ptr mService;
};
/**
Dialog for selecting and configuring KOrganizer plugins
*/
KOPrefsDialogPlugins::KOPrefsDialogPlugins(QWidget *parent)
: KCModule(parent)
{
QBoxLayout *topTopLayout = new QVBoxLayout(this);
mTreeWidget = new QTreeWidget(this);
mTreeWidget->setColumnCount(1);
mTreeWidget->setHeaderLabel(i18nc("@title:column plugin name", "Name"));
topTopLayout->addWidget(mTreeWidget);
mDescription = new QLabel(this);
mDescription->setAlignment(Qt::AlignVCenter);
mDescription->setWordWrap(true);
mDescription->setFrameShape(QLabel::Panel);
mDescription->setFrameShadow(QLabel::Sunken);
mDescription->setMinimumSize(QSize(0, 55));
QSizePolicy policy(QSizePolicy::MinimumExpanding, QSizePolicy::Fixed);
policy.setHorizontalStretch(0);
policy.setVerticalStretch(0);
policy.setHeightForWidth(mDescription->sizePolicy().hasHeightForWidth());
mDescription->setSizePolicy(policy);
topTopLayout->addWidget(mDescription);
QWidget *buttonRow = new QWidget(this);
QBoxLayout *buttonRowLayout = new QHBoxLayout(buttonRow);
buttonRowLayout->setContentsMargins(0, 0, 0, 0);
mConfigureButton = new QPushButton(buttonRow);
KGuiItem::assign(mConfigureButton, KGuiItem(i18nc("@action:button", "Configure &Plugin..."),
QStringLiteral("configure"), QString(),
i18nc("@info:whatsthis",
"This button allows you to configure"
" the plugin that you have selected in the list above")));
buttonRowLayout->addWidget(mConfigureButton);
buttonRowLayout->addItem(new QSpacerItem(1, 1, QSizePolicy::Expanding));
topTopLayout->addWidget(buttonRow);
mPositioningGroupBox = new QGroupBox(i18nc("@title:group", "Position"), this);
//mPositionMonthTop = new QCheckBox(
//i18nc( "@option:check", "Show in the month view" ), mPositioningGroupBox );
mPositionAgendaTop = new QRadioButton(
i18nc("@option:check", "Show at the top of the agenda views"), mPositioningGroupBox);
mPositionAgendaBottom = new QRadioButton(
i18nc("@option:check", "Show at the bottom of the agenda views"), mPositioningGroupBox);
QVBoxLayout *positioningLayout = new QVBoxLayout(mPositioningGroupBox);
//positioningLayout->addWidget( mPositionMonthTop );
positioningLayout->addWidget(mPositionAgendaTop);
positioningLayout->addWidget(mPositionAgendaBottom);
positioningLayout->addStretch(1);
topTopLayout->addWidget(mPositioningGroupBox);
connect(mConfigureButton, &QPushButton::clicked, this, &KOPrefsDialogPlugins::configure);
connect(mPositionAgendaTop, &QRadioButton::clicked, this,
&KOPrefsDialogPlugins::positioningChanged);
connect(mPositionAgendaBottom, &QRadioButton::clicked, this,
&KOPrefsDialogPlugins::positioningChanged);
connect(mTreeWidget, &QTreeWidget::itemSelectionChanged, this,
&KOPrefsDialogPlugins::selectionChanged);
connect(mTreeWidget, &QTreeWidget::itemChanged, this, &KOPrefsDialogPlugins::selectionChanged);
connect(mTreeWidget, &QTreeWidget::itemClicked, this, &KOPrefsDialogPlugins::slotConfigChanged);
load();
selectionChanged();
}
KOPrefsDialogPlugins::~KOPrefsDialogPlugins()
{
delete mDecorations;
delete mOthers;
}
void KOPrefsDialogPlugins::slotConfigChanged()
{
Q_EMIT markAsChanged();
}
void KOPrefsDialogPlugins::load()
{
mTreeWidget->clear();
const KService::List plugins = KOCore::self()->availablePlugins() + KOCore::self()->availableParts();
EventViews::PrefsPtr viewPrefs = KOPrefs::instance()->eventViewsPreferences();
QStringList selectedPlugins = viewPrefs->selectedPlugins();
mDecorations = new QTreeWidgetItem(mTreeWidget,
QStringList(i18nc("@title:group", "Calendar Decorations")));
mOthers = new QTreeWidgetItem(mTreeWidget,
QStringList(i18nc("@title:group", "Other Plugins")));
KService::List::ConstIterator it;
KService::List::ConstIterator end(plugins.constEnd());
for (it = plugins.constBegin(); it != end; ++it) {
QTreeWidgetItem *item = nullptr;
if ((*it)->hasServiceType(EventViews::CalendarDecoration::Decoration::serviceType())) {
item = new PluginItem(mDecorations, *it);
} else {
continue;
}
if (selectedPlugins.contains((*it)->desktopEntryName())) {
item->setCheckState(0, Qt::Checked);
} else {
item->setCheckState(0, Qt::Unchecked);
}
}
mDecorations->setExpanded(true);
mOthers->setExpanded(true);
//Disable for the moment it crashs. Not understand why
#if QT_VERSION < QT_VERSION_CHECK(5, 14, 0)
mDecorationsAtMonthViewTop = KOPrefs::instance()->decorationsAtMonthViewTop().toSet();
mDecorationsAtAgendaViewTop = viewPrefs->decorationsAtAgendaViewTop().toSet();
mDecorationsAtAgendaViewBottom = viewPrefs->decorationsAtAgendaViewBottom().toSet();
#else
const auto monthViewTop = KOPrefs::instance()->decorationsAtMonthViewTop();
mDecorationsAtMonthViewTop = QSet<QString>(monthViewTop.begin(), monthViewTop.end());
const auto agendaViewTop = viewPrefs->decorationsAtAgendaViewTop();
mDecorationsAtAgendaViewTop = QSet<QString>(agendaViewTop.begin(), agendaViewTop.end());
const auto agendaViewBottom = viewPrefs->decorationsAtAgendaViewBottom();
mDecorationsAtAgendaViewBottom = QSet<QString>(agendaViewBottom.begin(), agendaViewBottom.end());
#endif
}
void KOPrefsDialogPlugins::save()
{
QStringList selectedPlugins;
for (int i = 0; i < mTreeWidget->topLevelItemCount(); ++i) {
QTreeWidgetItem *serviceTypeGroup = mTreeWidget->topLevelItem(i);
for (int j = 0; j < serviceTypeGroup->childCount(); ++j) {
PluginItem *item = static_cast<PluginItem *>(serviceTypeGroup->child(j));
if (item->checkState(0) == Qt::Checked) {
selectedPlugins.append(item->service()->desktopEntryName());
}
}
}
EventViews::PrefsPtr viewPrefs = KOPrefs::instance()->eventViewsPreferences();