diff --git a/src/localFileConfiguration/localfileconfiguration.cpp b/src/localFileConfiguration/localfileconfiguration.cpp index 508e78a0..f9855976 100644 --- a/src/localFileConfiguration/localfileconfiguration.cpp +++ b/src/localFileConfiguration/localfileconfiguration.cpp @@ -1,117 +1,122 @@ /* * Copyright 2017 Matthieu Gallien * * This library 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 3 of the License, or (at your option) any later version. * * This library 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 * Library General Public License for more details. * * You should have received a copy of the GNU Library General Public License * along with this library; see the file COPYING.LIB. If not, write to * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "localfileconfiguration.h" #include "elisa_settings.h" #include #include #include #include K_PLUGIN_FACTORY_WITH_JSON(KCMElisaLocalFileFactory, "kcm_elisa_local_file.json", registerPlugin();) KCMElisaLocalFile::KCMElisaLocalFile(QObject* parent, const QVariantList &args) : ConfigModule(parent, args) { KAboutData *about = new KAboutData(QStringLiteral("kcm_elisa_local_file"), i18n("Elisa Local Files Indexer Configuration"), QStringLiteral("0.1"), {}, KAboutLicense::LGPL_V3, i18n("Copyright 20017 Matthieu Gallien ")); about->addAuthor(i18n("Matthieu Gallien"),i18n("Author"), QStringLiteral("mgallien@mgallien.fr")); setAboutData(about); auto configurationFileName = QStandardPaths::writableLocation(QStandardPaths::ConfigLocation); configurationFileName += QStringLiteral("/elisarc"); Elisa::ElisaConfiguration::instance(configurationFileName); connect(Elisa::ElisaConfiguration::self(), &Elisa::ElisaConfiguration::configChanged, this, &KCMElisaLocalFile::configChanged); + connect(&mConfigFileWatcher, &QFileSystemWatcher::fileChanged, + this, &KCMElisaLocalFile::configChanged); + setRootPath(Elisa::ElisaConfiguration::rootPath()); Elisa::ElisaConfiguration::setRootPath(mRootPath); Elisa::ElisaConfiguration::self()->save(); + + mConfigFileWatcher.addPath(Elisa::ElisaConfiguration::self()->config()->name()); } KCMElisaLocalFile::~KCMElisaLocalFile() { } QStringList KCMElisaLocalFile::rootPath() const { return mRootPath; } void KCMElisaLocalFile::defaults() { setRootPath(QStandardPaths::standardLocations(QStandardPaths::MusicLocation)); } void KCMElisaLocalFile::load() { setRootPath(Elisa::ElisaConfiguration::rootPath()); } void KCMElisaLocalFile::save() { Elisa::ElisaConfiguration::setRootPath(mRootPath); Elisa::ElisaConfiguration::self()->save(); } void KCMElisaLocalFile::setRootPath(QStringList rootPath) { - if (mRootPath == rootPath) { + if (mRootPath == rootPath && !mRootPath.isEmpty()) { return; } mRootPath.clear(); for (const auto &onePath : rootPath) { if (onePath.startsWith(QStringLiteral("file:///"))) { mRootPath.push_back(onePath.mid(7)); } else if (onePath.startsWith(QStringLiteral("file:/"))) { mRootPath.push_back(onePath.mid(5)); } else { mRootPath.push_back(onePath); } } if (mRootPath.isEmpty()) { for (const auto &musicPath : QStandardPaths::standardLocations(QStandardPaths::MusicLocation)) { mRootPath.push_back(musicPath); } } Q_EMIT rootPathChanged(mRootPath); setNeedsSave(true); Q_EMIT needsSaveChanged(); } void KCMElisaLocalFile::configChanged() { setRootPath(Elisa::ElisaConfiguration::rootPath()); } #include "localfileconfiguration.moc" diff --git a/src/localFileConfiguration/localfileconfiguration.h b/src/localFileConfiguration/localfileconfiguration.h index 878d26d6..885c90ce 100644 --- a/src/localFileConfiguration/localfileconfiguration.h +++ b/src/localFileConfiguration/localfileconfiguration.h @@ -1,68 +1,71 @@ /* * Copyright 2017 Matthieu Gallien * * This library 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 3 of the License, or (at your option) any later version. * * This library 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 * Library General Public License for more details. * * You should have received a copy of the GNU Library General Public License * along with this library; see the file COPYING.LIB. If not, write to * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #if !defined LOCALFILECONFIGURATION_H_ #define LOCALFILECONFIGURATION_H_ #include #include +#include class KCMElisaLocalFile : public KQuickAddons::ConfigModule { Q_OBJECT Q_PROPERTY(QStringList rootPath READ rootPath WRITE setRootPath NOTIFY rootPathChanged) public: explicit KCMElisaLocalFile(QObject *parent, const QVariantList &args); virtual ~KCMElisaLocalFile(); QStringList rootPath() const; Q_SIGNALS: void rootPathChanged(QStringList rootPath); public Q_SLOTS: void defaults() override final; void load() override final; void save() override final; void setRootPath(QStringList rootPath); private Q_SLOTS: void configChanged(); private: QStringList mRootPath; + QFileSystemWatcher mConfigFileWatcher; + }; #endif