diff --git a/ksplash/ksplashqml/CMakeLists.txt b/ksplash/ksplashqml/CMakeLists.txt index 16c58a01b..734be69e6 100644 --- a/ksplash/ksplashqml/CMakeLists.txt +++ b/ksplash/ksplashqml/CMakeLists.txt @@ -6,6 +6,7 @@ set(ksplashqml_SRCS main.cpp SplashApp.cpp SplashWindow.cpp + ../../lookandfeelaccess/lookandfeelaccess.cpp ) add_executable(ksplashqml ${ksplashqml_SRCS}) diff --git a/ksplash/ksplashqml/SplashWindow.cpp b/ksplash/ksplashqml/SplashWindow.cpp index 23603f581..1a8c4f9c0 100644 --- a/ksplash/ksplashqml/SplashWindow.cpp +++ b/ksplash/ksplashqml/SplashWindow.cpp @@ -18,6 +18,7 @@ */ #include "SplashWindow.h" +#include "../../lookandfeelaccess/lookandfeelaccess.h" #include #include @@ -26,7 +27,6 @@ #include #include #include -#include SplashWindow::SplashWindow(bool testing, bool window) : QQuickView(), @@ -85,10 +85,8 @@ void SplashWindow::setGeometry(const QRect& rect) QQuickView::setGeometry(rect); if (oldGeometryEmpty) { - ShellPluginLoader::init(); - Plasma::Package pkg = Plasma::PluginLoader::self()->loadPackage("Plasma/LookAndFeel"); - pkg.setPath("org.kde.lookandfeel"); + LookAndFeelAccess access; - setSource(QUrl::fromLocalFile(pkg.filePath("splashmainscript"))); + setSource(QUrl::fromLocalFile(access.filePath("splashmainscript"))); } } diff --git a/lookandfeelaccess/lookandfeelaccess.cpp b/lookandfeelaccess/lookandfeelaccess.cpp new file mode 100644 index 000000000..9b1a2f5b6 --- /dev/null +++ b/lookandfeelaccess/lookandfeelaccess.cpp @@ -0,0 +1,120 @@ +/* + * Copyright 2014 Marco Martin + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU Library General Public License as + * published by the Free Software Foundation; either version 2, 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 Library 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. + */ + + +#include "lookandfeelaccess.h" + +#include "shellpluginloader.h" + +#include +#include +#include + +class LookAndFeelAccessPrivate +{ +public: + LookAndFeelAccessPrivate(LookAndFeelAccess *access) + : q(access) + { + } + + void settingsFileChanged(); + + + LookAndFeelAccess *q; + Plasma::Package package; + Plasma::Package defaultPackage; + KSharedConfig::Ptr config; +}; + +void LookAndFeelAccessPrivate::settingsFileChanged() +{ + config->reparseConfiguration(); + KConfigGroup cg(config, "KDE"); + + const QString packageName = cg.readEntry("LookAndFeelPackage", QString()); + const QString oldPackageName = package.isValid() ? package.metadata().pluginName() : QString(); + + if (packageName == oldPackageName) { + return; + } + + //Invalid + if (packageName.isEmpty() && !oldPackageName.isEmpty()) { + package = Plasma::Package(); + } else if (!packageName.isEmpty()) { + package = Plasma::PluginLoader::self()->loadPackage("Plasma/LookAndFeel"); + package.setPath(packageName); + } + + emit q->packageChanged(); +} + +LookAndFeelAccess::LookAndFeelAccess(QObject *parent) + : QObject(parent), + d(new LookAndFeelAccessPrivate(this)) +{ + ShellPluginLoader::init(); + d->defaultPackage = Plasma::PluginLoader::self()->loadPackage("Plasma/LookAndFeel"); + d->defaultPackage.setPath("org.kde.lookandfeel"); + + d->config = KSharedConfig::openConfig("kdeglobals"); + KConfigGroup cg(d->config, "KDE"); + const QString packageName = cg.readEntry("LookAndFeelPackage", QString()); + if (!packageName.isEmpty()) { + d->package = Plasma::PluginLoader::self()->loadPackage("Plasma/LookAndFeel"); + d->package.setPath(packageName); + } + + const QString configFile = QStandardPaths::writableLocation(QStandardPaths::GenericConfigLocation) + "/kdeglobals"; + KDirWatch::self()->addFile(configFile); + + // Catch both, direct changes to the config file ... + connect(KDirWatch::self(), SIGNAL(dirty()), this, SLOT(settingsFileChanged())); + // ... but also remove/recreate cycles, like KConfig does it + connect(KDirWatch::self(), SIGNAL(created()), this, SLOT(settingsFileChanged())); +} + +LookAndFeelAccess::~LookAndFeelAccess() +{ +} + + +QString LookAndFeelAccess::filePath(const char *key, const QString &filename) const +{ + const QString path = d->package.filePath(key, filename); + + if (!path.isEmpty()) { + return path; + } else { + return d->defaultPackage.filePath(key, filename); + } +} + +KPluginInfo LookAndFeelAccess::metadata() const +{ + if (d->package.isValid()) { + return d->package.metadata(); + } else { + return d->defaultPackage.metadata(); + } +} + + +#include "moc_lookandfeelaccess.cpp" diff --git a/lookandfeelaccess/lookandfeelaccess.h b/lookandfeelaccess/lookandfeelaccess.h new file mode 100644 index 000000000..207aacfda --- /dev/null +++ b/lookandfeelaccess/lookandfeelaccess.h @@ -0,0 +1,64 @@ +/* + * Copyright 2014 Marco Martin + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU Library General Public License as + * published by the Free Software Foundation; either version 2, 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 Library 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. + */ + +#ifndef LOOKANDFEELACCESS_H +#define LOOKANDFEELACCESS_H + +#include + +#include + +class LookAndFeelAccessPrivate; + +class LookAndFeelAccess : public QObject +{ + Q_OBJECT + +public: + LookAndFeelAccess(QObject *parent = 0); + ~LookAndFeelAccess(); + + /** + * Get the path to a given file based on the key and an optional filename. + * Example: finding the main script in a scripting package: + * filePath("mainscript") + * + * Example: finding a specific image in the images directory: + * filePath("images", "myimage.png") + * + * @param key the key of the file type to look for, + * @param filename optional name of the file to locate within the package + * @return path to the file on disk. QString() if not found. + **/ + QString filePath(const char *key, const QString &filename = QString()) const; + + /** + * @return the package metadata object. + */ + KPluginInfo metadata() const; + +Q_SIGNALS: + void packageChanged(); + +private: + LookAndFeelAccessPrivate *const d; + Q_PRIVATE_SLOT(d, void settingsFileChanged()) +}; + +#endif diff --git a/ksplash/ksplashqml/shellpluginloader.h b/lookandfeelaccess/shellpluginloader.h similarity index 100% rename from ksplash/ksplashqml/shellpluginloader.h rename to lookandfeelaccess/shellpluginloader.h