diff --git a/model/foldermodel.cpp b/model/foldermodel.cpp index 40af04c..b42e410 100644 --- a/model/foldermodel.cpp +++ b/model/foldermodel.cpp @@ -5,6 +5,7 @@ * Copyright (C) 2011 Marco Martin * * Copyright (C) 2014 by Eike Hein * * Copyright (C) 2021 Reven Martin * + * Copyright (C) 2021 Reion Wong * * * * 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 * @@ -50,6 +51,7 @@ #include #include #include +#include #include // Qt Quick @@ -77,6 +79,7 @@ FolderModel::FolderModel(QObject *parent) , m_sortMode(0) , m_sortDesc(false) , m_sortDirsFirst(true) + , m_showHiddenFiles(false) , m_filterMode(NoFilter) , m_filterPatternMatchAll(true) , m_complete(false) @@ -88,13 +91,17 @@ FolderModel::FolderModel(QObject *parent) , m_mimeAppManager(MimeAppManager::self()) , m_sizeJob(nullptr) { - DirLister *dirLister = new DirLister(this); - dirLister->setDelayedMimeTypes(true); - dirLister->setAutoErrorHandlingEnabled(false, nullptr); + QSettings settings("cutefishos", qApp->applicationName()); + m_showHiddenFiles = settings.value("showHiddenFiles", false).toBool(); + + m_dirLister = new DirLister(this); + m_dirLister->setDelayedMimeTypes(true); + m_dirLister->setAutoErrorHandlingEnabled(false, nullptr); + m_dirLister->setShowingDotFiles(m_showHiddenFiles); // connect(dirLister, &DirLister::error, this, &FolderModel::notification); m_dirModel = new KDirModel(this); - m_dirModel->setDirLister(dirLister); + m_dirModel->setDirLister(m_dirLister); m_dirModel->setDropsAllowed(KDirModel::DropOnDirectory | KDirModel::DropOnLocalExecutable); m_dirModel->moveToThread(qApp->thread()); @@ -143,6 +150,7 @@ QHash FolderModel::staticRoleNames() roleNames[BlankRole] = "blank"; roleNames[SelectedRole] = "selected"; roleNames[IsDirRole] = "isDir"; + roleNames[IsHiddenRole] = "isHidden"; roleNames[UrlRole] = "url"; roleNames[DisplayNameRole] = "displayName"; roleNames[FileNameRole] = "fileName"; @@ -180,6 +188,12 @@ QVariant FolderModel::data(const QModelIndex &index, int role) const case IsDesktopFileRole: { return item.isDesktopFile(); } + case IsDirRole: { + return item.isDir(); + } + case IsHiddenRole: { + return item.isHidden(); + } case FileSizeRole: { if (item.isDir()) { QDir dir(item.url().toLocalFile()); @@ -998,6 +1012,8 @@ void FolderModel::openContextMenu(QQuickItem *visualParent, Qt::KeyboardModifier menu->addAction(m_actionCollection.action("changeBackground")); } + menu->addAction(m_actionCollection.action("showHidden")); + menu->addSeparator(); menu->addAction(m_actionCollection.action("emptyTrash")); menu->addAction(m_actionCollection.action("properties")); @@ -1283,6 +1299,26 @@ bool FolderModel::matchPattern(const KFileItem &item) const return false; } +bool FolderModel::showHiddenFiles() const +{ + return m_showHiddenFiles; +} + +void FolderModel::setShowHiddenFiles(bool showHiddenFiles) +{ + if (m_showHiddenFiles != showHiddenFiles) { + m_showHiddenFiles = showHiddenFiles; + + m_dirLister->setShowingDotFiles(m_showHiddenFiles); + m_dirLister->emitChanges(); + + QSettings settings("cutefishos", qApp->applicationName()); + settings.setValue("showHiddenFiles", m_showHiddenFiles); + + emit showHiddenFilesChanged(); + } +} + QString FolderModel::selectedItemSize() const { return m_selectedItemSize; @@ -1365,6 +1401,11 @@ void FolderModel::createActions() QAction *restore = new QAction(tr("Restore"), this); QObject::connect(restore, &QAction::triggered, this, &FolderModel::restoreFromTrash); + QAction *showHidden = new QAction(tr("Show hidden files"), this); + QObject::connect(showHidden, &QAction::triggered, this, [=] { + setShowHiddenFiles(!m_showHiddenFiles); + }); + m_actionCollection.addAction(QStringLiteral("open"), open); m_actionCollection.addAction(QStringLiteral("openWith"), openWith); m_actionCollection.addAction(QStringLiteral("cut"), cut); @@ -1380,6 +1421,7 @@ void FolderModel::createActions() m_actionCollection.addAction(QStringLiteral("properties"), properties); m_actionCollection.addAction(QStringLiteral("changeBackground"), changeBackground); m_actionCollection.addAction(QStringLiteral("restore"), restore); + m_actionCollection.addAction(QStringLiteral("showHidden"), showHidden); } void FolderModel::updateActions() @@ -1485,6 +1527,11 @@ void FolderModel::updateActions() if (QAction *properties = m_actionCollection.action("properties")) { properties->setVisible(!isTrash); } + + if (QAction *showHidden = m_actionCollection.action("showHidden")) { + showHidden->setCheckable(true); + showHidden->setChecked(m_showHiddenFiles); + } } void FolderModel::addDragImage(QDrag *drag, int x, int y) diff --git a/model/foldermodel.h b/model/foldermodel.h index 503edc4..f5e93de 100644 --- a/model/foldermodel.h +++ b/model/foldermodel.h @@ -59,12 +59,14 @@ class FolderModel : public QSortFilterProxyModel, public QQmlParserStatus Q_PROPERTY(int count READ count NOTIFY countChanged) Q_PROPERTY(QStringList filterMimeTypes READ filterMimeTypes WRITE setFilterMimeTypes NOTIFY filterMimeTypesChanged) Q_PROPERTY(QString selectedItemSize READ selectedItemSize NOTIFY selectedItemSizeChanged) + Q_PROPERTY(bool showHiddenFiles READ showHiddenFiles WRITE setShowHiddenFiles NOTIFY showHiddenFilesChanged) public: enum DataRole { BlankRole = Qt::UserRole + 1, SelectedRole, IsDirRole, + IsHiddenRole, UrlRole, DisplayNameRole, FileNameRole, @@ -209,6 +211,9 @@ public: QString selectedItemSize() const; + bool showHiddenFiles() const; + void setShowHiddenFiles(bool showHiddenFiles); + signals: void urlChanged(); void resolvedUrlChanged(); @@ -226,6 +231,7 @@ signals: void filterPatternChanged(); void filterMimeTypesChanged(); void selectedItemSizeChanged(); + void showHiddenFilesChanged(); void notification(const QString &message); @@ -250,6 +256,7 @@ protected: private: KDirModel *m_dirModel; KDirWatch *m_dirWatch; + KDirLister *m_dirLister; QItemSelectionModel *m_selectionModel; QItemSelection m_pinnedSelection; @@ -260,6 +267,8 @@ private: bool m_sortDesc; bool m_sortDirsFirst; + bool m_showHiddenFiles; + FilterMode m_filterMode; QString m_filterPattern; bool m_filterPatternMatchAll; diff --git a/qml/FolderGridItem.qml b/qml/FolderGridItem.qml index a04f53c..aa0e8b2 100644 --- a/qml/FolderGridItem.qml +++ b/qml/FolderGridItem.qml @@ -86,6 +86,8 @@ Item { width: parent.width - FishUI.Units.largeSpacing * 2 height: control.GridView.view.iconSize + opacity: model.isHidden ? 0.5 : 1.0 + Image { id: _icon width: control.GridView.view.iconSize @@ -197,7 +199,9 @@ Item { wrapMode: Text.Wrap text: model.fileName color: control.GridView.view.isDesktopView ? "white" - : selected ? FishUI.Theme.highlightedTextColor : FishUI.Theme.textColor + : selected ? FishUI.Theme.highlightedTextColor + : FishUI.Theme.textColor + opacity: model.isHidden ? 0.8 : 1.0 } Rectangle { diff --git a/qml/FolderListItem.qml b/qml/FolderListItem.qml index dac5d35..bc62534 100644 --- a/qml/FolderListItem.qml +++ b/qml/FolderListItem.qml @@ -75,6 +75,7 @@ Item { id: iconItem Layout.fillHeight: true width: parent.height * 0.8 + opacity: model.isHidden ? 0.5 : 1.0 Image { id: _icon @@ -127,6 +128,7 @@ Item { color: selected ? FishUI.Theme.highlightedTextColor : FishUI.Theme.textColor textFormat: Text.PlainText elide: Qt.ElideMiddle + opacity: model.isHidden ? 0.8 : 1.0 } Label { @@ -135,6 +137,7 @@ Item { color: selected ? FishUI.Theme.highlightedTextColor : FishUI.Theme.disabledTextColor textFormat: Text.PlainText Layout.fillWidth: true + opacity: model.isHidden ? 0.8 : 1.0 } } @@ -142,6 +145,7 @@ Item { text: model.modified textFormat: Text.PlainText color: selected ? FishUI.Theme.highlightedTextColor : FishUI.Theme.disabledTextColor + opacity: model.isHidden ? 0.8 : 1.0 } } } diff --git a/qml/FolderPage.qml b/qml/FolderPage.qml index a90f618..7a81225 100644 --- a/qml/FolderPage.qml +++ b/qml/FolderPage.qml @@ -32,6 +32,7 @@ Item { id: folderPage property alias currentUrl: dirModel.url + property alias model: dirModel property Item currentView: _viewLoader.item property int statusBarHeight: 22 @@ -142,6 +143,7 @@ Item { id: dirModel viewAdapter: viewAdapter sortMode: settings.sortMode + // showHiddenFiles: settings.showHiddenFiles Component.onCompleted: { if (arg) diff --git a/qml/GlobalSettings.qml b/qml/GlobalSettings.qml index b580b1d..2fa5f54 100644 --- a/qml/GlobalSettings.qml +++ b/qml/GlobalSettings.qml @@ -22,7 +22,9 @@ import Qt.labs.settings 1.0 Settings { property int viewMethod: 1 // controls display mode: list or grid - property bool showHidden: false + + // Port to C++ + // property bool showHiddenFiles: false // Name, Date, Size property int orderBy: 0 diff --git a/translations/en_US.ts b/translations/en_US.ts index 59e1106..46bcec2 100644 --- a/translations/en_US.ts +++ b/translations/en_US.ts @@ -114,12 +114,12 @@ FilePropertiesDialog - + Properties - + %1 files @@ -127,191 +127,196 @@ FolderModel - + %1 item - + %1 items - + The file or folder %1 does not exist. - + Select All - + File Manager - + Open - + Open with - + Cut - + Copy - + Paste - + New Folder - + Move To Trash - + Empty Trash - + Delete - + Rename - + Open in Terminal - + Set as Wallpaper - + Properties - + Change background - + Restore + + + Show hidden files + + FolderPage - + Empty folder - + Open - - + + Properties - + File - + New Folder - + Quit - + Edit - + Select All - + Cut - + Copy - + Paste - + Help - + About - + %1 item - + %1 items - + %1 selected - + Empty Trash diff --git a/translations/zh_CN.ts b/translations/zh_CN.ts index 86b8940..80e6a22 100644 --- a/translations/zh_CN.ts +++ b/translations/zh_CN.ts @@ -114,12 +114,12 @@ FilePropertiesDialog - + Properties 属性 - + %1 files %1 项 @@ -127,191 +127,196 @@ FolderModel - + %1 item %1 项 - + %1 items %1 项 - + The file or folder %1 does not exist. 文件或文件夹 %1 不存在 - + Select All 全选 - + File Manager - 文件管理器 + 文件管理器 - + Open 打开 - + Open with 打开方式 - + Cut 剪切 - + Copy 复制 - + Paste 粘贴 - + New Folder 新建文件夹 - + Move To Trash 移动到回收站 - + Empty Trash 清空回收站 - + Delete 删除 - + Rename 重命名 - + Open in Terminal 在终端中打开 - + Set as Wallpaper 设置为壁纸 - + Properties 属性 - + Change background 更改桌面背景 - + Restore 恢复 + + + Show hidden files + 显示隐藏文件 + FolderPage - + Empty folder 空文件夹 - + Open 打开 - - + + Properties 属性 - + File 文件 - + New Folder 新建文件夹 - + Quit 退出 - + Edit 编辑 - + Select All 全选 - + Cut 剪切 - + Copy 复制 - + Paste 粘贴 - + Help 帮助 - + About 关于 - + %1 item %1 项 - + %1 items %1 项 - + %1 selected 选中了 %1 项 - + Empty Trash 清空回收站