diff --git a/kcms/baloo/filteredfoldermodel.h b/kcms/baloo/filteredfoldermodel.h --- a/kcms/baloo/filteredfoldermodel.h +++ b/kcms/baloo/filteredfoldermodel.h @@ -23,6 +23,7 @@ #define FILTEREDFOLDERMODEL_H #include +#include class BalooSettings; @@ -34,10 +35,13 @@ enum Roles { Folder = Qt::UserRole + 1, - Url + Url, + EnableIndex, + Deletable, }; QVariant data(const QModelIndex& idx, int role) const override; + bool setData(const QModelIndex& idx, const QVariant& value, int role) override; int rowCount(const QModelIndex& parent) const override; Q_INVOKABLE void addFolder(const QString& folder); @@ -48,19 +52,21 @@ void updateDirectoryList(); private: - QString folderDisplayName(const QString& url) const; + BalooSettings *m_settings; + Baloo::IndexerConfig m_runtimeConfig; + + struct FolderInfo { + QString url; + QString displayName; + QString icon; + bool enableIndex; + bool isFromConfig; + }; - /** - * @brief Get the theme valid icon name for \p path. - * - * @param path Path to be analysed. - * @return One of: "user-home", "drive-harddisk" or "folder" - */ - QString iconName(QString path) const; + QVector m_folderList; + QStringList m_deletedSettings; //< track deleted entries - BalooSettings *m_settings; - QStringList m_mountPoints; - QStringList m_excludeList; + void syncFolderConfig(const FolderInfo& entry); }; #endif // FILTEREDFOLDERMODEL_H diff --git a/kcms/baloo/filteredfoldermodel.cpp b/kcms/baloo/filteredfoldermodel.cpp --- a/kcms/baloo/filteredfoldermodel.cpp +++ b/kcms/baloo/filteredfoldermodel.cpp @@ -39,15 +39,11 @@ return input; } - QStringList addTrailingSlashes(const QStringList& input) { - QStringList output = input; - - for (QString& str : output) { - if (!str.endsWith('/')) - str += QLatin1Char('/'); + QStringList addTrailingSlashes(QStringList&& list) { + for (QString& str : list) { + str = normalizeTrailingSlashes(std::move(str)); } - - return output; + return list; } QString makeHomePretty(const QString& url) { @@ -72,15 +68,17 @@ QStringList settingsIncluded = addTrailingSlashes(m_settings->folders()); QStringList settingsExcluded = addTrailingSlashes(m_settings->excludedFolders()); - QString homePath = normalizeTrailingSlashes(QDir::homePath()); + const QString homePath = normalizeTrailingSlashes(QDir::homePath()); - auto folderListEntry = [homePath] (const QString& url, bool include, bool fromConfig) + auto folderListEntry = [&homePath] (const QString& url, bool include, bool fromConfig) { QString displayName = url; - if (displayName.size() > 1) + if (displayName.size() > 1) { displayName.chop(1); - if (displayName.startsWith(homePath)) + } + if (displayName.startsWith(homePath)) { displayName.replace(0, homePath.length(), QStringLiteral("~/")); + } QString icon = QStringLiteral("folder"); if (url == homePath) { @@ -166,8 +164,8 @@ void FilteredFolderModel::addFolder(const QString& url) { - QString nUrl = QUrl(url).toLocalFile(); - nUrl = normalizeTrailingSlashes(std::move(nUrl)); + QString nUrl = normalizeTrailingSlashes(QUrl(url).toLocalFile()); + auto it = std::find_if(m_folderList.begin(), m_folderList.end(), [nUrl](const FolderInfo& folder) { return folder.url == nUrl; diff --git a/kcms/baloo/package/contents/ui/main.qml b/kcms/baloo/package/contents/ui/main.qml --- a/kcms/baloo/package/contents/ui/main.qml +++ b/kcms/baloo/package/contents/ui/main.qml @@ -78,7 +78,7 @@ Layout.preferredHeight: Kirigami.Units.gridUnit } QQC2.Label { - text: i18n("Do not search in these locations:") + text: i18n("Folder specific configuration:") } QQC2.ScrollView { @@ -88,33 +88,95 @@ Layout.fillHeight: true ListView { - id: fileExcludeList - + id: directoryConfigList clip: true + currentIndex: -1 + model: kcm.filteredModel - delegate: Kirigami.BasicListItem { - icon: model.decoration - label: model.folder - onClicked: fileExcludeList.currentIndex = index - } + delegate: directoryConfigDelegate } } RowLayout { + Layout.alignment: Qt.AlignRight + QQC2.Button { id: addFolder - icon.name: "list-add" + icon.name: "folder-add" + text: i18n("Add folder configuration...") onClicked: fileDialogLoader.active = true } + } + } + + Component { + id: directoryConfigDelegate + Kirigami.SwipeListItem { + id: listItem + onClicked: { + directoryConfigList.currentIndex = index + } + property int iconSize: Kirigami.Units.iconSizes.smallMedium + property bool selected: directoryConfigList.currentIndex === index + + RowLayout { + Kirigami.Icon { + source: model.enableIndex ? "search" : "list-remove" + height: listItem.iconSize + width: listItem.iconSize + } + Item { + width: units.smallSpacing + } - QQC2.Button{ - id: removeFolder - icon.name: "list-remove" - enabled: fileExcludeList.currentIndex !== -1 - onClicked: { - kcm.filteredModel.removeFolder(fileExcludeList.currentIndex) + ColumnLayout { + RowLayout { + Kirigami.Icon { + source: model.decoration + height: listItem.iconSize + width: listItem.iconSize + } + Item { + width: units.smallSpacing + } + QQC2.Label { + text: model.folder + elide: Text.ElideRight + Layout.fillWidth: true + } + } + QQC2.Label { + text: (model.enableIndex ? i18n("%1 is included.", model.url) + : i18n("%1 is excluded.", model.url)) + elide: Text.ElideRight + Layout.fillWidth: true + opacity: listItem.hovered ? 0.8 : 0.6 + visible: listItem.selected + } + } + + QQC2.ToolButton { + visible: listItem.hovered && listItem.actionsVisible + height: listItem.iconSize + icon.name: "search" + text: model.enableIndex ? i18n("Disable indexing") : i18n("Enable indexing") + onClicked: { + model.enableIndex = !model.enableIndex + } } } + + actions: [ + Kirigami.Action { + id: removeFolder + enabled: model.deletable + icon.name: "user-trash" + tooltip: i18n("Delete entry") + onTriggered: { + kcm.filteredModel.removeFolder(index) + } + } + ] } }