diff --git a/kcms/colors/CMakeLists.txt b/kcms/colors/CMakeLists.txt index 9b7ede0a6..7180d595e 100644 --- a/kcms/colors/CMakeLists.txt +++ b/kcms/colors/CMakeLists.txt @@ -1,81 +1,81 @@ # KI18N Translation Domain for this library add_definitions(-DTRANSLATION_DOMAIN=\"kcmcolors\") set(scheme_editor_SRCS - schemeeditor.cpp + kcolorschemeeditor.cpp scmeditordialog.cpp scmeditoroptions.cpp scmeditorcolors.cpp scmeditoreffects.cpp previewwidget.cpp setpreviewwidget.cpp ) ki18n_wrap_ui(scheme_editor_SRCS scmeditordialog.ui scmeditoroptions.ui scmeditorcolors.ui scmeditoreffects.ui preview.ui setpreview.ui ) -add_executable(scheme_editor ${scheme_editor_SRCS}) +add_executable(kcolorschemeeditor ${scheme_editor_SRCS}) -target_link_libraries(scheme_editor +target_link_libraries(kcolorschemeeditor KF5::KCMUtils KF5::GuiAddons KF5::I18n KF5::KIOCore KF5::CoreAddons KF5::NewStuff ) -install(TARGETS scheme_editor DESTINATION ${INSTALL_TARGETS_DEFAULT_ARGS}) -#install( FILES scheme_editor.desktop DESTINATION ${SERVICES_INSTALL_DIR} ) +install(TARGETS kcolorschemeeditor DESTINATION ${INSTALL_TARGETS_DEFAULT_ARGS}) +install(FILES kcolorschemeeditor.desktop DESTINATION ${XDG_APPS_INSTALL_DIR}) # ---------------- set(kcm_colors_SRCS ../krdb/krdb.cpp colorscm.cpp scmeditordialog.cpp scmeditoroptions.cpp scmeditorcolors.cpp scmeditoreffects.cpp previewwidget.cpp 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 colorsettings.ui scmeditordialog.ui scmeditoroptions.ui scmeditorcolors.ui scmeditoreffects.ui preview.ui setpreview.ui) add_library(kcm_colors MODULE ${kcm_colors_SRCS}) target_link_libraries(kcm_colors KF5::KCMUtils KF5::GuiAddons KF5::I18n KF5::KIOCore KF5::CoreAddons Qt5::DBus KF5::NewStuff) if(X11_FOUND) target_link_libraries(kcm_colors ${X11_LIBRARIES} Qt5::X11Extras) endif() install(TARGETS kcm_colors DESTINATION ${PLUGIN_INSTALL_DIR}) install( FILES colors.desktop DESTINATION ${SERVICES_INSTALL_DIR} ) install( FILES colorschemes.knsrc DESTINATION ${CONFIG_INSTALL_DIR} ) # built-in color schemes file(GLOB schemefiles schemes/*.colors) install( FILES ${schemefiles} DESTINATION ${DATA_INSTALL_DIR}/color-schemes ) diff --git a/kcms/colors/colorscm.cpp b/kcms/colors/colorscm.cpp index ecfafe3f1..8aaeef3ed 100644 --- a/kcms/colors/colorscm.cpp +++ b/kcms/colors/colorscm.cpp @@ -1,521 +1,513 @@ /* KDE Display color scheme setup module * Copyright (C) 2007 Matthew Woehlke * Copyright (C) 2007 Jeremy Whiting * Copyright (C) 2016 Olivier Churlaud * * 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; see the file COPYING. If not, write to * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "colorscm.h" #include "../krdb/krdb.h" #include "scmeditordialog.h" #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include K_PLUGIN_FACTORY( KolorFactory, registerPlugin(); ) K_EXPORT_PLUGIN( KolorFactory("kcmcolors") ) KColorCm::KColorCm(QWidget *parent, const QVariantList &) : KCModule( parent ), m_dontLoadSelectedScheme(false), m_previousSchemeItem(0) { KAboutData* about = new KAboutData( QStringLiteral("kcmcolors"), i18n("Colors"), QStringLiteral("1.0"), QString(), KAboutLicense::GPL, i18n("(c) 2007 Matthew Woehlke") ); about->addAuthor( i18n("Matthew Woehlke"), QString(), QStringLiteral("mw_triad@users.sourceforge.net") ); about->addAuthor( i18n("Jeremy Whiting"), QString(), QStringLiteral("jpwhiting@kde.org")); setAboutData( about ); m_config = KSharedConfig::openConfig(QStringLiteral("kdeglobals")); setupUi(this); connect(applyToAlien, &QCheckBox::toggled, [=](){ emit changed(true); }); connect(schemeList, SIGNAL(currentItemChanged(QListWidgetItem*,QListWidgetItem*)), this, SLOT(loadScheme(QListWidgetItem*,QListWidgetItem*))); schemeKnsButton->setIcon( QIcon::fromTheme(QStringLiteral("get-hot-new-stuff")) ); } KColorCm::~KColorCm() { m_config->markAsClean(); } void KColorCm::populateSchemeList() { // clear the list in case this is being called from reset button click schemeList->clear(); // add entries QIcon icon; QStringList schemeFiles; const QStringList schemeDirs = QStandardPaths::locateAll(QStandardPaths::GenericDataLocation, QStringLiteral("color-schemes"), QStandardPaths::LocateDirectory); Q_FOREACH (const QString &dir, schemeDirs) { const QStringList fileNames = QDir(dir).entryList(QStringList()<setData(Qt::UserRole, info.baseName()); schemeList->addItem(newItem); } schemeList->sortItems(); // add default entry (do this here so that the current and default entry appear at the top) m_config->setReadDefaults(true); 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); - schemeList->blockSignals(true); // don't emit changed signals - schemeList->setCurrentItem(currentitem); - schemeList->blockSignals(false);*/ } void KColorCm::loadScheme(KSharedConfigPtr config) // const QString &path) { schemePreview->setPalette(config); updateConfig(config); } void KColorCm::selectPreviousSchemeAgain() { m_dontLoadSelectedScheme = true; schemeList->setCurrentItem(m_previousSchemeItem); m_dontLoadSelectedScheme = false; } void KColorCm::loadScheme(QListWidgetItem *currentItem, QListWidgetItem *previousItem) { m_previousSchemeItem = previousItem; if (m_dontLoadSelectedScheme) { qDebug() << "dontload"; return; } if (currentItem != NULL) { // load it const QString name = currentItem->text(); m_currentColorScheme = name; const QString fileBaseName = currentItem->data(Qt::UserRole).toString(); if (name == i18nc("Default color scheme", "Default")) { schemeRemoveButton->setEnabled(false); KSharedConfigPtr config = m_config; config->setReadDefaults(true); loadScheme(config); config->setReadDefaults(false); // load the default scheme emit changed(true); } else { const QString path = QStandardPaths::locate(QStandardPaths::GenericDataLocation, "color-schemes/" + fileBaseName + ".colors"); const int permissions = QFile(path).permissions(); const bool canWrite = (permissions & QFile::WriteUser); qDebug() << "checking permissions of " << path; schemeRemoveButton->setEnabled(canWrite); KSharedConfigPtr config = KSharedConfig::openConfig(path); loadScheme(config); emit changed(true); } } } void KColorCm::on_schemeRemoveButton_clicked() { if (schemeList->currentItem() != NULL) { const QString path = QStandardPaths::locate(QStandardPaths::GenericDataLocation, "color-schemes/" + schemeList->currentItem()->data(Qt::UserRole).toString() + ".colors"); KIO::DeleteJob *job = KIO::del(QUrl::fromLocalFile(path)); qDebug() << path; job->uiDelegate()->setParent(this); if (job->exec()) { delete schemeList->takeItem(schemeList->currentRow()); } else { // deletion failed, so show an error message KMessageBox::error(this, i18n("You do not have permission to delete that scheme"), i18n("Error")); } } } void KColorCm::on_schemeImportButton_clicked() { // get the path to the scheme to import QUrl url = QUrl::fromLocalFile(QFileDialog::getOpenFileName(this, i18n("Import Color Scheme"))); if(!url.isValid()) { return; } // TODO: possibly untar or uncompress it // open it // load the scheme KSharedConfigPtr config = KSharedConfig::openConfig(url.path()); if (config->groupList().contains(QStringLiteral("Color Scheme"))) { KMessageBox::sorry(this, i18n("The scheme you have selected appears to be a KDE3 scheme.\n\n" "This is not supported anymore."), i18n("Notice")); return; } // Do not overwrite another scheme KConfigGroup group(config, "General"); QString name = group.readEntry("Name"); int increment = 0; QString newName = name; QString testpath = ""; do { if (increment) { newName = name + QString::number(increment); } testpath = QStandardPaths::locate(QStandardPaths::GenericDataLocation, "color-schemes/" + newName + ".colors"); increment++; } while (!testpath.isEmpty()); QString newpath = QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + "/color-schemes/"; QDir dir; dir.mkpath(newpath); newpath += newName + ".colors"; QFile::copy(url.toLocalFile(), newpath); // Update name KSharedConfigPtr config2 = KSharedConfig::openConfig(newpath); KConfigGroup group2(config2, "General"); group2.writeEntry("Name", newName); config2->sync(); this->populateSchemeList(); QList itemList = schemeList->findItems(newName, Qt::MatchExactly); if (!itemList.isEmpty()) { schemeList->setCurrentItem(itemList.first()); } } void KColorCm::on_schemeKnsButton_clicked() { KNS3::DownloadDialog dialog(QStringLiteral("colorschemes.knsrc"), this); dialog.exec(); if ( ! dialog.changedEntries().isEmpty() ) { populateSchemeList(); for ( auto t : dialog.installedEntries()) qDebug() << t.name(); } } QPixmap KColorCm::createSchemePreviewIcon(const KSharedConfigPtr &config) { const uchar bits1[] = { 0xff, 0xff, 0xff, 0x2c, 0x16, 0x0b }; const uchar bits2[] = { 0x68, 0x34, 0x1a, 0xff, 0xff, 0xff }; const QSize bitsSize(24,2); const QBitmap b1 = QBitmap::fromData(bitsSize, bits1); const QBitmap b2 = QBitmap::fromData(bitsSize, bits2); QPixmap pixmap(23, 16); pixmap.fill(Qt::black); // ### use some color other than black for borders? QPainter p(&pixmap); KConfigGroup group(config, "WM"); // NOTE: keep this in sync with kdelibs/kdeui/kernel/kglobalsettings.cpp QColor activeBackground = group.readEntry("activeBackground", QColor(48, 174, 232)); QColor activeForeground = group.readEntry("activeForeground", QColor(255, 255, 255)); QColor inactiveBackground = group.readEntry("inactiveBackground", QColor(224, 223, 222)); QColor inactiveForeground = group.readEntry("inactiveForeground", QColor(75, 71, 67)); KColorScheme windowScheme(QPalette::Active, KColorScheme::Window, config); p.fillRect( 1, 1, 7, 7, windowScheme.background()); p.fillRect( 2, 2, 5, 2, QBrush(windowScheme.foreground().color(), b1)); KColorScheme buttonScheme(QPalette::Active, KColorScheme::Button, config); p.fillRect( 8, 1, 7, 7, buttonScheme.background()); p.fillRect( 9, 2, 5, 2, QBrush(buttonScheme.foreground().color(), b1)); p.fillRect(15, 1, 7, 7, activeBackground); p.fillRect(16, 2, 5, 2, QBrush(activeForeground, b1)); KColorScheme viewScheme(QPalette::Active, KColorScheme::View, config); p.fillRect( 1, 8, 7, 7, viewScheme.background()); p.fillRect( 2, 12, 5, 2, QBrush(viewScheme.foreground().color(), b2)); KColorScheme selectionScheme(QPalette::Active, KColorScheme::Selection, config); p.fillRect( 8, 8, 7, 7, selectionScheme.background()); p.fillRect( 9, 12, 5, 2, QBrush(selectionScheme.foreground().color(), b2)); p.fillRect(15, 8, 7, 7, inactiveBackground); p.fillRect(16, 12, 5, 2, QBrush(inactiveForeground, b2)); p.end(); return pixmap; } void KColorCm::load() { loadInternal(); // get colorscheme name from global settings KConfigGroup group(m_config, "General"); m_currentColorScheme = group.readEntry("ColorScheme"); QList itemList = schemeList->findItems(m_currentColorScheme, Qt::MatchExactly); if(!itemList.isEmpty()) // "Default" is already selected, so don't handle the case that itemList is empty schemeList->setCurrentItem(itemList.at(0)); KConfig cfg(QStringLiteral("kcmdisplayrc"), KConfig::NoGlobals); group = KConfigGroup(&cfg, "X11"); applyToAlien->blockSignals(true); // don't emit SIGNAL(toggled(bool)) which would call SLOT(emitChanged()) applyToAlien->setChecked(group.readEntry("exportKDEColors", true)); applyToAlien->blockSignals(false); } void KColorCm::loadInternal() { // clean the config, in case we have changed the in-memory kconfig m_config->markAsClean(); m_config->reparseConfiguration(); // fill in the color scheme list populateSchemeList(); schemePreview->setPalette(m_config); emit changed(false); } void KColorCm::save() { QIcon icon = createSchemePreviewIcon(m_config); schemeList->item(0)->setIcon(icon); m_config->sync(); KConfig cfg(QStringLiteral("kcmdisplayrc"), KConfig::NoGlobals); KConfigGroup displayGroup(&cfg, "X11"); displayGroup.writeEntry("exportKDEColors", applyToAlien->isChecked()); cfg.sync(); qDebug() << KRdbExportQtColors << KRdbExportGtkTheme << KRdbExportColors ; runRdb(KRdbExportQtColors | KRdbExportGtkTheme | ( applyToAlien->isChecked() ? KRdbExportColors : 0 ) ); qDebug() << "icic"; QDBusMessage message = QDBusMessage::createSignal(QStringLiteral("/KGlobalSettings"), QStringLiteral("org.kde.KGlobalSettings"), QStringLiteral("notifyChange") ); QList args; args.append(0);//previous KGlobalSettings::PaletteChanged. This is now private API in khintsettings args.append(0);//unused in palette changed but needed for the DBus signature message.setArguments(args); qDebug() << KConfigGroup(m_config, "General").readEntry("Name"); QDBusConnection::sessionBus().send(message); if (qApp->platformName() == QStringLiteral("xcb")) { // Send signal to all kwin instances QDBusMessage message = QDBusMessage::createSignal(QStringLiteral("/KWin"), QStringLiteral("org.kde.KWin"), QStringLiteral("reloadConfig")); QDBusConnection::sessionBus().send(message); } emit changed(false); } void KColorCm::defaults() { // Switch to default scheme for(int i = 0; i < schemeList->count(); ++i) { QListWidgetItem *item = schemeList->item(i); if(item->text() == i18nc("Default color scheme", "Default")) { // If editing the default scheme, force a reload, else select the default scheme if(schemeList->currentItem() == item) loadScheme(item, item); else schemeList->setCurrentItem(item); m_currentColorScheme = item->text(); break; } } KCModule::defaults(); emit changed(true); } void KColorCm::on_schemeEditButton_clicked() { QListWidgetItem *currentItem = schemeList->currentItem(); const QString fileBaseName = currentItem->data(Qt::UserRole).toString(); const QString path = QStandardPaths::locate(QStandardPaths::GenericDataLocation, "color-schemes/" + fileBaseName + ".colors"); if (path.isEmpty()) { KMessageBox::sorry(this, i18n("This scheme was not found."), i18n("File not found")); return; } SchemeEditorDialog* dialog = new SchemeEditorDialog(path, this); dialog->setModal(true); dialog->show(); connect(dialog, &SchemeEditorDialog::accepted, [=](){ this->populateSchemeList(); }); connect(dialog, &SchemeEditorDialog::rejected, [=](){ this->populateSchemeList(); }); } void KColorCm::updateConfig(KSharedConfigPtr config) { // store colorscheme name in global settings KConfigGroup groupOut(m_config, "General"); groupOut.writeEntry("ColorScheme", m_currentColorScheme); QStringList colorItemList; colorItemList << "BackgroundNormal" << "BackgroundAlternate" << "ForegroundNormal" << "ForegroundInactive" << "ForegroundActive" << "ForegroundLink" << "ForegroundVisited" << "ForegroundNegative" << "ForegroundNeutral" << "ForegroundPositive" << "DecorationFocus" << "DecorationHover"; QStringList colorSetGroupList; colorSetGroupList << "Colors:Window" << "Colors:Button" << "Colors:Selection" << "Colors:Tooltip" << "Colors:View"; for (const QString &colorSetGroup : colorSetGroupList) { KConfigGroup groupOut(m_config, colorSetGroup); KConfigGroup groupTheme(config, colorSetGroup); for (const QString &coloritem : colorItemList) { groupOut.writeEntry(coloritem, groupTheme.readEntry(coloritem)); } } KConfigGroup groupWMTheme(config, "WM"); KConfigGroup groupWMOut(m_config, "WM"); QStringList colorItemListWM; colorItemListWM << "activeBackground" << "activeForeground" << "inactiveBackground" << "inactiveForeground" << "activeBlend" << "inactiveBlend"; for (const QString &coloritem : colorItemListWM) { groupWMOut.writeEntry(coloritem, groupWMTheme.readEntry(coloritem)); } QStringList groupNameList; groupNameList << "ColorEffects:Inactive" << "ColorEffects:Disabled"; QStringList effectList; effectList << "IntensityEffect" << "IntensityAmount" << "ColorEffect" << "ColorAmount" << "Color" << "ContrastEffect" << "ContrastAmount"; for (const QString &groupName : groupNameList) { KConfigGroup groupEffectOut(m_config, groupName); KConfigGroup groupEffectTheme(config, groupName); for (const QString &effect : effectList) { groupEffectOut.writeEntry(effect, groupEffectTheme.readEntry("effect")); } } } #include "colorscm.moc" diff --git a/kcms/colors/colorsettings.ui b/kcms/colors/colorsettings.ui index febe86ed5..e81752bda 100644 --- a/kcms/colors/colorsettings.ui +++ b/kcms/colors/colorsettings.ui @@ -1,149 +1,149 @@ colorSettings 0 0 736 422 0 0 0 0 Configure the current color scheme - Config Scheme + Edit Scheme false Qt::Horizontal 40 20 false Remove the selected scheme Remove Scheme false Get new color schemes from the Internet Get &New Scheme 0 0 23 16 0 0 0 10 Import a color scheme from a file &Install from File true Apply colors to &non-Qt applications PreviewWidget QWidget
previewwidget.h
1
schemeList
diff --git a/kcms/colors/kcolorschemeeditor.cpp b/kcms/colors/kcolorschemeeditor.cpp new file mode 100644 index 000000000..ff9ec5e2f --- /dev/null +++ b/kcms/colors/kcolorschemeeditor.cpp @@ -0,0 +1,76 @@ +/* KDE Display scheme editor + * Copyright (C) 2016 Olivier Churlaud + * + * 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; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include "scmeditordialog.h" + +#include +#include +#include + +#include + +int main(int argc, char* argv[]) +{ + + QApplication app(argc, argv); + + KAboutData aboutData( + QStringLiteral("kcolorschemeeditor"), + i18n("KColorSchemeEditor"), + QStringLiteral("0.1"), + i18n("Utility to edit and create color schemes"), + KAboutLicense::GPL_V3 + ); + aboutData.addAuthor(i18n("Olivier Churlaud"), i18n("Utility creation"), + QStringLiteral("olivier@churlaud.com")); + aboutData.addAuthor(i18n("Jeremy Whiting"), i18n("KCM code (reused in here)"), + QStringLiteral("jpwhiting@kde.org")); + aboutData.addAuthor(i18n("Matthew Woehlke"), i18n("KCM code (reused in here)"), + QStringLiteral("mw_triad@users.sourceforge.net")); + KAboutData::setApplicationData(aboutData); + + QCommandLineParser parser; + parser.addHelpOption(); + parser.addVersionOption(); + parser.addPositionalArgument("theme", i18n("Scheme to edit or to use as a base."), + QStringLiteral("kcolorschemeeditor ThemeName")); + aboutData.setupCommandLine(&parser); + parser.process(app); + aboutData.processCommandLine(&parser); + + const QStringList args = parser.positionalArguments(); + QString path = ""; + if (args.count() == 1) + { + const QString fileBaseName(args.at(0)); + path = QStandardPaths::locate(QStandardPaths::GenericDataLocation, + "color-schemes/" + fileBaseName + ".colors"); + } + if (path.isEmpty()) + { + QTextStream out(stderr); + out << i18n("Scheme not found, falling back to current one.\n"); + } + + SchemeEditorDialog dialog(path); + + dialog.show(); + + return app.exec(); +} diff --git a/kcms/colors/kcolorschemeeditor.desktop b/kcms/colors/kcolorschemeeditor.desktop new file mode 100644 index 000000000..b7fb76e3e --- /dev/null +++ b/kcms/colors/kcolorschemeeditor.desktop @@ -0,0 +1,11 @@ +[Desktop Entry] +GenericName=Color scheme editor +Name=KColorSchemeEditor +Comment=Plasma color scheme editor +MimeType=text/plain; +Exec=kcolorschemeeditor +StartupNotify=true +Icon=preferences-desktop-color +Type=Application +Terminal=false +Categories=Qt;KDE;X-KDE-settings-looknfeel; diff --git a/kcms/colors/schemeeditor.cpp b/kcms/colors/schemeeditor.cpp deleted file mode 100644 index 86df15a30..000000000 --- a/kcms/colors/schemeeditor.cpp +++ /dev/null @@ -1,46 +0,0 @@ -/* KDE Display scheme editor - * Copyright (C) 2016 Olivier Churlaud - * - * 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; see the file COPYING. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. - */ - -#include "scmeditordialog.h" - -#include - -int main(int argc, char* argv[]) -{ - - if (argc < 2) { - return -1; - } - QApplication app(argc, argv); - - - const QString fileBaseName(argv[1]); - const QString path = QStandardPaths::locate(QStandardPaths::GenericDataLocation, - "color-schemes/" + fileBaseName + ".colors"); - - if (path.isEmpty()) { - //FIXME:: dialog + return - return -1; - } - SchemeEditorDialog dialog(path); - - dialog.show(); - - return app.exec(); -} diff --git a/kcms/colors/scmeditordialog.cpp b/kcms/colors/scmeditordialog.cpp index 6ab942e81..f40ec557e 100644 --- a/kcms/colors/scmeditordialog.cpp +++ b/kcms/colors/scmeditordialog.cpp @@ -1,231 +1,230 @@ /* ColorEdit widget for KDE Display color scheme setup module * Copyright (C) 2016 Olivier Churlaud * * 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; see the file COPYING. If not, write to * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "scmeditordialog.h" #include "scmeditoroptions.h" #include "scmeditorcolors.h" #include "scmeditoreffects.h" #include #include #include #include #include #include #include #include #include SchemeEditorDialog::SchemeEditorDialog(const QString &path, QWidget *parent) : QDialog( parent ) , m_disableUpdates(false) , m_filePath(path) , m_unsavedChanges(false) { m_config = KSharedConfig::openConfig(path); m_schemeName = KConfigGroup(m_config, "General").readEntry("Name"); setupUi(this); this->setWindowTitle(m_schemeName); schemeKnsUploadButton->setIcon( QIcon::fromTheme(QStringLiteral("get-hot-new-stuff")) ); m_optionTab = new SchemeEditorOptions(m_config); m_colorTab = new SchemeEditorColors(m_config); m_disabledTab = new SchemeEditorEffects(m_config, QPalette::Disabled); m_inactiveTab = new SchemeEditorEffects(m_config, QPalette::Inactive); tabWidget->insertTab(OptionTab, m_optionTab, i18n("Options")); tabWidget->insertTab(ColorTab, m_colorTab, i18n("Colors")); tabWidget->insertTab(DisabledTab, m_disabledTab, i18n("Disabled")); connect(m_optionTab, &SchemeEditorOptions::changed, this, &SchemeEditorDialog::updateTabs); connect(m_colorTab, &SchemeEditorColors::changed, this, &SchemeEditorDialog::updateTabs); connect(m_disabledTab, &SchemeEditorEffects::changed, this, &SchemeEditorDialog::updateTabs); connect(m_inactiveTab, &SchemeEditorEffects::changed, this, &SchemeEditorDialog::updateTabs); buttonBox->button(QDialogButtonBox::Save)->setEnabled(false); buttonBox->button(QDialogButtonBox::Reset)->setEnabled(false); updateTabs(); } void SchemeEditorDialog::on_schemeKnsUploadButton_clicked() { if (m_unsavedChanges) { KMessageBox::ButtonCode reallyUpload = KMessageBox::questionYesNo( this, i18n("This colour scheme was not saved. Continue?"), i18n("Do you really want to upload?")); if (reallyUpload == KMessageBox::No) { return; } } // find path const QString path = QStandardPaths::locate(QStandardPaths::GenericDataLocation, "color-schemes/" + m_schemeName + ".colors"); if (path.isEmpty() ) // if the color scheme file wasn't found { qDebug() << "path for color scheme " << m_schemeName << " couldn't be found"; return; } // upload KNS3::UploadDialog dialog(QStringLiteral("colorschemes.knsrc"), this); dialog.setUploadFile(QUrl::fromLocalFile(path) ); dialog.exec(); } void SchemeEditorDialog::on_buttonBox_clicked(QAbstractButton *button) { if (buttonBox->standardButton(button) == QDialogButtonBox::Reset) { m_config->markAsClean();; m_config->reparseConfiguration(); updateTabs(); setUnsavedChanges(false); } else if (buttonBox->standardButton(button) == QDialogButtonBox::Save) { saveScheme(); } else if (buttonBox->standardButton(button) == QDialogButtonBox::Close) { if (m_unsavedChanges) { KMessageBox::ButtonCode ans = KMessageBox::questionYesNo( this, i18n("You have unsaved changes. Do you really want to quit?"), i18n("Unsaved changes")); if (ans == KMessageBox::No) { return; } } this->accept(); } } void SchemeEditorDialog::saveScheme() { // prompt for the name to save as bool ok; QString schemeName = KConfigGroup(m_config, "General").readEntry("Name"); QString name = QInputDialog::getText(this, i18n("Save Color Scheme"), i18n("&Enter a name for the color scheme:"), QLineEdit::Normal, m_schemeName, &ok); if (!ok) { return; } QString filename = name; filename.remove('\''); // So Foo's does not become FooS QRegExp fixer(QStringLiteral("[\\W,.-]+(.?)")); int offset; while ((offset = fixer.indexIn(filename)) >= 0) filename.replace(offset, fixer.matchedLength(), fixer.cap(1).toUpper()); filename.replace(0, 1, filename.at(0).toUpper()); // check if that name is already in the list const QString path = QStandardPaths::locate(QStandardPaths::GenericDataLocation, "color-schemes/" + filename + ".colors"); QFile file(path); const int permissions = file.permissions(); const bool canWrite = (permissions & QFile::WriteUser); // or if we can overwrite it if it exists if (path.isEmpty() || !file.exists() || canWrite) { if(canWrite){ int ret = KMessageBox::questionYesNo(this, i18n("A color scheme with that name already exists.\nDo you want to overwrite it?"), i18n("Save Color Scheme"), KStandardGuiItem::overwrite(), KStandardGuiItem::cancel()); //on don't overwrite, call again the functionn if(ret == KMessageBox::No){ this->saveScheme(); return; } } // go ahead and save it QString newpath = QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + "/color-schemes/"; QDir dir; dir.mkpath(newpath); newpath += filename + ".colors"; KConfig *config = m_config->copyTo(newpath); KConfigGroup group(config, "General"); group.writeEntry("Name", name); // sync it and delete pointer config->sync(); delete config; // reopen and update window m_config = KSharedConfig::openConfig(newpath); m_schemeName = name; setWindowTitle(name); setUnsavedChanges(false); } else if (!canWrite && file.exists()) { KMessageBox::error(this, i18n("You do not have permission to overwrite that scheme"), i18n("Error")); } } void SchemeEditorDialog::updateTabs(bool madeByUser) { if (madeByUser) { - qDebug() <<"update"; setUnsavedChanges(true); } KConfigGroup group(m_config, "ColorEffects:Inactive"); bool hideInactiveTab = group.readEntry("Enable", QVariant(true)).toBool(); if ( hideInactiveTab ) { tabWidget->insertTab(InactiveTab, m_inactiveTab, i18n("Inactive")); } else { tabWidget->removeTab(InactiveTab); } m_optionTab->updateValues(); m_colorTab->updateValues(); m_inactiveTab->updateValues(); m_disabledTab->updateValues(); } void SchemeEditorDialog::setUnsavedChanges(bool changes) { m_unsavedChanges = changes; if (changes) { buttonBox->button(QDialogButtonBox::Save)->setEnabled(true); buttonBox->button(QDialogButtonBox::Reset)->setEnabled(true); } else { buttonBox->button(QDialogButtonBox::Save)->setEnabled(false); buttonBox->button(QDialogButtonBox::Reset)->setEnabled(false); } } diff --git a/kcms/colors/scmeditoroptions.cpp b/kcms/colors/scmeditoroptions.cpp index 9061a3335..c2701d860 100644 --- a/kcms/colors/scmeditoroptions.cpp +++ b/kcms/colors/scmeditoroptions.cpp @@ -1,101 +1,100 @@ /* KDE Display color scheme setup module * Copyright (C) 2007 Matthew Woehlke * Copyright (C) 2007 Jeremy Whiting * * 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; see the file COPYING. If not, write to * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "scmeditoroptions.h" #include #include SchemeEditorOptions::SchemeEditorOptions(KSharedConfigPtr config, QWidget *parent) : QWidget( parent ) , m_config( config ) { setupUi(this); m_disableUpdates = false; loadOptions(); } void SchemeEditorOptions::updateValues() { loadOptions(); } void SchemeEditorOptions::loadOptions() { KConfigGroup generalGroup(KSharedConfig::openConfig(), "General"); shadeSortedColumn->setChecked(generalGroup.readEntry("shadeSortColumn", true)); KConfigGroup KDEgroup(m_config, "KDE"); contrastSlider->setValue(KDEgroup.readEntry("contrast", KColorScheme::contrast())); KConfigGroup group(m_config, "ColorEffects:Inactive"); useInactiveEffects->setChecked(group.readEntry("Enable", false)); // NOTE: keep this in sync with kdelibs/kdeui/colors/kcolorscheme.cpp // NOTE: remove extra logic from updateFromOptions and on_useInactiveEffects_stateChanged when this changes! inactiveSelectionEffect->setChecked(group.readEntry("ChangeSelectionColor", group.readEntry("Enable", true))); } // Option slot void SchemeEditorOptions::on_contrastSlider_valueChanged(int value) { KConfigGroup group(m_config, "KDE"); group.writeEntry("contrast", value); emit changed(true); } void SchemeEditorOptions::on_shadeSortedColumn_stateChanged(int state) { - qDebug() << "shade"; if (m_disableUpdates) return; KConfigGroup group(m_config, "General"); group.writeEntry("shadeSortColumn", bool(state != Qt::Unchecked)); emit changed(true); } void SchemeEditorOptions::on_useInactiveEffects_stateChanged(int state) { KConfigGroup group(m_config, "ColorEffects:Inactive"); group.writeEntry("Enable", bool(state != Qt::Unchecked)); m_disableUpdates = true; printf("re-init\n"); inactiveSelectionEffect->setChecked(group.readEntry("ChangeSelectionColor", bool(state != Qt::Unchecked))); m_disableUpdates = false; emit changed(true); } void SchemeEditorOptions::on_inactiveSelectionEffect_stateChanged(int state) { if (m_disableUpdates) { // don't write the config as we are reading it! return; } KConfigGroup group(m_config, "ColorEffects:Inactive"); group.writeEntry("ChangeSelectionColor", bool(state != Qt::Unchecked)); emit changed(true); }