diff --git a/kcms/colors/CMakeLists.txt b/kcms/colors/CMakeLists.txt --- a/kcms/colors/CMakeLists.txt +++ b/kcms/colors/CMakeLists.txt @@ -9,8 +9,12 @@ scmeditoreffects.cpp previewwidget.cpp setpreviewwidget.cpp + colorscm.cpp + ../krdb/krdb.cpp ) +set(klauncher_xml ${KINIT_DBUS_INTERFACES_DIR}/kf5_org.kde.KLauncher.xml) + ki18n_wrap_ui(scheme_editor_SRCS scmeditordialog.ui scmeditoroptions.ui @@ -20,6 +24,8 @@ setpreview.ui ) +qt5_add_dbus_interface(scheme_editor_SRCS ${klauncher_xml} klauncher_iface) + add_executable(kcolorschemeeditor ${scheme_editor_SRCS}) target_link_libraries(kcolorschemeeditor @@ -30,6 +36,9 @@ KF5::CoreAddons KF5::NewStuff ) +if(X11_FOUND) + target_link_libraries(kcolorschemeeditor ${X11_LIBRARIES} Qt5::X11Extras) +endif() install(TARGETS kcolorschemeeditor DESTINATION ${INSTALL_TARGETS_DEFAULT_ARGS}) install(FILES org.kde.kcolorschemeeditor.desktop DESTINATION ${XDG_APPS_INSTALL_DIR}) @@ -46,7 +55,7 @@ setpreviewwidget.cpp ) -set(klauncher_xml ${KINIT_DBUS_INTERFACES_DIR}/kf5_org.kde.KLauncher.xml) + qt5_add_dbus_interface(kcm_colors_SRCS ${klauncher_xml} klauncher_iface) ki18n_wrap_ui(kcm_colors_SRCS diff --git a/kcms/colors/colorscm.h b/kcms/colors/colorscm.h --- a/kcms/colors/colorscm.h +++ b/kcms/colors/colorscm.h @@ -60,6 +60,11 @@ */ virtual void defaults(); + /** + * Update all keys of the Global config with the theme ones. + */ + void updateConfig(KSharedConfigPtr config); + private Q_SLOTS: @@ -120,11 +125,6 @@ */ void populateSchemeList(); - /** - * Update all keys of the Global config with the theme ones. - */ - void updateConfig(KSharedConfigPtr config); - QString m_currentColorScheme; diff --git a/kcms/colors/colorscm.cpp b/kcms/colors/colorscm.cpp --- a/kcms/colors/colorscm.cpp +++ b/kcms/colors/colorscm.cpp @@ -126,6 +126,11 @@ icon = createSchemePreviewIcon(m_config); schemeList->insertItem(0, new QListWidgetItem(icon, i18nc("Default color scheme", "Default"))); m_config->setReadDefaults(false); + + // add current scheme entry + icon = createSchemePreviewIcon(m_config); + QListWidgetItem *currentitem = new QListWidgetItem(icon, i18nc("Current color scheme", "Current")); + schemeList->insertItem(0, currentitem); } @@ -166,9 +171,16 @@ config->setReadDefaults(true); loadScheme(config); config->setReadDefaults(false); + schemeEditButton->setEnabled(true); // load the default scheme emit changed(true); } + else if (name == i18nc("Current color scheme", "Current")) + { + loadInternal(); + schemeRemoveButton->setEnabled(false); + schemeEditButton->setEnabled(true); + } else { const QString path = QStandardPaths::locate(QStandardPaths::GenericDataLocation, @@ -423,12 +435,26 @@ const QString path = QStandardPaths::locate(QStandardPaths::GenericDataLocation, "color-schemes/" + fileBaseName + ".colors"); - SchemeEditorDialog* dialog = new SchemeEditorDialog(path, this); + SchemeEditorDialog* dialog; + + //Current scheme + if (schemeList->currentItem()->text() == i18nc("Default color scheme", "Default")) { + dialog = new SchemeEditorDialog(m_config, this); + //Default scheme + } else if (schemeList->currentItem()->text() == i18nc("Current color scheme", "Current")) { + KSharedConfigPtr config = m_config; + config->setReadDefaults(true); + dialog = new SchemeEditorDialog(config, this); + } else { + dialog = new SchemeEditorDialog(path, this); + } + dialog->setAttribute(Qt::WA_DeleteOnClose); // avoid mem-leak dialog->setModal(true); dialog->show(); connect(dialog, &SchemeEditorDialog::accepted, [=](){ this->populateSchemeList(); }); connect(dialog, &SchemeEditorDialog::rejected, [=](){ this->populateSchemeList(); }); + connect(dialog, &SchemeEditorDialog::applied, [=](){ this->populateSchemeList(); }); } void KColorCm::updateConfig(KSharedConfigPtr config) diff --git a/kcms/colors/scmeditordialog.h b/kcms/colors/scmeditordialog.h --- a/kcms/colors/scmeditordialog.h +++ b/kcms/colors/scmeditordialog.h @@ -32,16 +32,19 @@ class SchemeEditorOptions; class SchemeEditorColors; class SchemeEditorEffects; +class KColorCm; class SchemeEditorDialog : public QDialog, public Ui::ScmEditorDialog { Q_OBJECT public: - SchemeEditorDialog(const QString &path, QWidget *parent=Q_NULLPTR); + SchemeEditorDialog(const QString &path, KColorCm *parent = Q_NULLPTR); + SchemeEditorDialog(KSharedConfigPtr config, KColorCm *parent = Q_NULLPTR); Q_SIGNALS: void changed(bool); + void applied(); private Q_SLOTS: @@ -53,6 +56,8 @@ void updateTabs(bool byUser=false); private: + void init(); + void applyScheme(); /** save the current scheme */ void saveScheme(); void setUnsavedChanges(bool changes); @@ -67,6 +72,7 @@ SchemeEditorColors *m_colorTab; SchemeEditorEffects *m_disabledTab; SchemeEditorEffects *m_inactiveTab; + KColorCm *m_kcm; }; #endif diff --git a/kcms/colors/scmeditordialog.cpp b/kcms/colors/scmeditordialog.cpp --- a/kcms/colors/scmeditordialog.cpp +++ b/kcms/colors/scmeditordialog.cpp @@ -21,6 +21,7 @@ #include "scmeditoroptions.h" #include "scmeditorcolors.h" #include "scmeditoreffects.h" +#include "colorscm.h" #include #include @@ -34,23 +35,37 @@ #include -SchemeEditorDialog::SchemeEditorDialog(const QString &path, QWidget *parent) +SchemeEditorDialog::SchemeEditorDialog(KSharedConfigPtr config, KColorCm *parent) + : QDialog( parent ) + , m_disableUpdates(false) + , m_unsavedChanges(false) + , m_kcm(parent) +{ + m_config = config; + init(); +} + +SchemeEditorDialog::SchemeEditorDialog(const QString &path, KColorCm *parent) : QDialog( parent ) , m_filePath(path) , m_disableUpdates(false) , m_unsavedChanges(false) + , m_kcm(parent) { - if (!path.isEmpty()) { - m_config = KSharedConfig::openConfig(path); - } else { - m_config = KSharedConfig::openConfig(QStringLiteral("kdeglobals")); - m_config->setReadDefaults(true); - } + m_config = KSharedConfig::openConfig(path); + m_schemeName = KConfigGroup(m_config, "General").readEntry("Name"); + this->setWindowTitle(m_schemeName); + init(); +} +void SchemeEditorDialog::init() +{ setupUi(this); - if (!path.isEmpty()) { - this->setWindowTitle(m_schemeName); + + //we are in standalone appication mode? don't show the apply button + if (!m_kcm) { + buttonBox->button(QDialogButtonBox::Apply)->setVisible(false); } schemeKnsUploadButton->setIcon( QIcon::fromTheme(QStringLiteral("get-hot-new-stuff")) ); @@ -114,6 +129,11 @@ { saveScheme(); } + else if (buttonBox->standardButton(button) == QDialogButtonBox::Apply) + { + applyScheme(); + emit applied(); + } else if (buttonBox->standardButton(button) == QDialogButtonBox::Close) { if (m_unsavedChanges) { @@ -131,6 +151,16 @@ } } +void SchemeEditorDialog::applyScheme() +{ + if (!m_kcm) { + return; + } + + m_kcm->updateConfig(m_config); + m_kcm->save(); +} + void SchemeEditorDialog::saveScheme() { // prompt for the name to save as diff --git a/kcms/colors/scmeditordialog.ui b/kcms/colors/scmeditordialog.ui --- a/kcms/colors/scmeditordialog.ui +++ b/kcms/colors/scmeditordialog.ui @@ -49,7 +49,7 @@ - QDialogButtonBox::Close|QDialogButtonBox::Reset|QDialogButtonBox::Save + QDialogButtonBox::Close|QDialogButtonBox::Reset|QDialogButtonBox::Apply|QDialogButtonBox::Save