File indexing completed on 2024-03-24 05:51:22
0001 /*********************************************************************** 0002 * SPDX-FileCopyrightText: 2003-2004 Max Howell <max.howell@methylblue.com> 0003 * SPDX-FileCopyrightText: 2008-2009 Martin Sandsmark <martin.sandsmark@kde.org> 0004 * SPDX-FileCopyrightText: 2022 Harald Sitter <sitter@kde.org> 0005 * 0006 * SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL 0007 ***********************************************************************/ 0008 0009 #include "Config.h" 0010 0011 #include <KConfig> 0012 #include <KConfigGroup> 0013 #include <KLocalizedString> 0014 #include <KMessageBox> 0015 #include <KSharedConfig> 0016 0017 #include <QDebug> 0018 #include <QFileDialog> 0019 #include <QFont> 0020 0021 void Config::read() 0022 { 0023 const KConfigGroup config = KSharedConfig::openConfig()->group(QStringLiteral("filelight_part")); 0024 0025 scanAcrossMounts = config.readEntry("scanAcrossMounts", false); 0026 scanRemoteMounts = config.readEntry("scanRemoteMounts", false); 0027 showSmallFiles = config.readEntry("showSmallFiles", false); 0028 contrast = config.readEntry("contrast", 75); 0029 scheme = (Filelight::MapScheme)config.readEntry("scheme", 0); 0030 skipList = config.readEntry("skipList", QStringList()); 0031 0032 Q_EMIT changed(); 0033 } 0034 0035 void Config::write() const 0036 { 0037 KConfigGroup config = KSharedConfig::openConfig()->group(QStringLiteral("filelight_part")); 0038 0039 config.writeEntry("scanAcrossMounts", scanAcrossMounts); 0040 config.writeEntry("scanRemoteMounts", scanRemoteMounts); 0041 config.writeEntry("showSmallFiles", showSmallFiles); 0042 config.writeEntry("contrast", contrast); 0043 config.writeEntry("scheme", (int)scheme); // TODO: make the enum belong to a qwidget, 0044 // and use magic macros to make it save this properly 0045 config.writePathEntry("skipList", skipList); 0046 0047 config.sync(); 0048 } 0049 0050 Config *Config::instance() 0051 { 0052 static Config self; 0053 return &self; 0054 } 0055 0056 void Config::addFolder() 0057 { 0058 const QString urlString = QFileDialog::getExistingDirectory(nullptr, i18n("Select path to ignore"), QDir::rootPath()); 0059 const QUrl url = QUrl::fromLocalFile(urlString); 0060 0061 // TODO error handling! 0062 // TODO wrong protocol handling! 0063 0064 if (!url.isEmpty()) { 0065 const QString path = url.toLocalFile(); 0066 0067 if (!skipList.contains(path)) { 0068 skipList.append(path); 0069 Q_EMIT changed(); 0070 } else { 0071 KMessageBox::information(nullptr, i18n("That folder is already set to be excluded from scans."), i18n("Folder already ignored")); 0072 } 0073 } 0074 } 0075 0076 void Config::removeFolder(const QString &url) 0077 { 0078 qDebug() << url; 0079 skipList.removeAll(url); 0080 Q_EMIT changed(); 0081 }