From b1a106192228cbba739dfa901086356690602214 Mon Sep 17 00:00:00 2001 From: kateleet Date: Sun, 26 Dec 2021 23:40:53 +0800 Subject: [PATCH] feat(sidebar): add a new name for the local disk --- helper/fm.cpp | 6 +++ helper/fm.h | 1 + model/placesmodel.cpp | 2 +- qml/SideBar.qml | 8 +++- translations/en_US.ts | 98 +++++++++++++++++++++++-------------------- translations/zh_CN.ts | 98 +++++++++++++++++++++++-------------------- 6 files changed, 118 insertions(+), 95 deletions(-) diff --git a/helper/fm.cpp b/helper/fm.cpp index 7c4b533..493e328 100644 --- a/helper/fm.cpp +++ b/helper/fm.cpp @@ -18,6 +18,7 @@ */ #include "fm.h" +#include #include Fm::Fm(QObject *parent) : QObject(parent) @@ -25,6 +26,11 @@ Fm::Fm(QObject *parent) : QObject(parent) } +QString Fm::rootPath() +{ + return QDir::rootPath(); +} + void Fm::emptyTrash() { KIO::Job *job = KIO::emptyTrash(); diff --git a/helper/fm.h b/helper/fm.h index 1c7e7f9..d32e2ed 100644 --- a/helper/fm.h +++ b/helper/fm.h @@ -29,6 +29,7 @@ class Fm : public QObject public: explicit Fm(QObject *parent = nullptr); + Q_INVOKABLE QString rootPath(); Q_INVOKABLE static void emptyTrash(); }; diff --git a/model/placesmodel.cpp b/model/placesmodel.cpp index 852e379..a8cc341 100644 --- a/model/placesmodel.cpp +++ b/model/placesmodel.cpp @@ -166,7 +166,7 @@ QVariant PlacesModel::data(const QModelIndex &index, int role) const switch (role) { case PlacesModel::NameRole: - return item->displayName(); + return item->url().toLocalFile() == QDir::rootPath() ? tr("Computer") : item->displayName(); break; case PlacesModel::IconNameRole: return item->iconName(); diff --git a/qml/SideBar.qml b/qml/SideBar.qml index 34400d4..0164413 100644 --- a/qml/SideBar.qml +++ b/qml/SideBar.qml @@ -36,6 +36,10 @@ ListView { target: sideBar } + Fm { + id: _fm + } + PlacesModel { id: placesModel onDeviceSetupDone: sideBar.clicked(filePath) // 设备挂载上后,模拟点击了该设备以打开该页面 @@ -148,7 +152,7 @@ ListView { visible: model.isDevice && !model.setupNeeded && model.isOpticalDisc && - !model.url.toString() === "/" + !model.url.toString() === _fm.rootPath() onTriggered: { placesModel.requestEject(index) @@ -161,7 +165,7 @@ ListView { visible: model.isDevice && !model.setupNeeded && !model.isOpticalDisc && - !model.url.toString() === "/" + !model.url.toString() === _fm.rootPath() onTriggered: { placesModel.requestTeardown(index) diff --git a/translations/en_US.ts b/translations/en_US.ts index 3b2c0e4..1353d83 100644 --- a/translations/en_US.ts +++ b/translations/en_US.ts @@ -127,112 +127,113 @@ FolderModel - + %1 item %1 item - + %1 items %1 items - + The file or folder %1 does not exist. The file or folder %1 does not exist. - + Select All Select All - + File Manager File Manager - + Open Open - + Open with Open with - + Cut Cut - + Copy Copy - + Paste Paste - + + New Folder New Folder - + Move To Trash Move To Trash - + Empty Trash Empty Trash - + Delete Delete - + Rename Rename - + Open in Terminal Open in Terminal - + Set as Wallpaper Set as Wallpaper - + Properties Properties - + Change background Change background - + Restore Restore - + Show hidden files Show hidden files - + Open in new window @@ -240,98 +241,98 @@ FolderPage - + Empty folder Empty folder - + Open Open - - + + Properties Properties - + File File - + New Folder New Folder - + Quit Quit - + Edit Edit - + Select All Select All - + Cut Cut - + Copy Copy - + Paste Paste - + Help Help - + About About - + File Manager File Manager - + A file manager designed for CutefishOS. - + %1 item %1 item - + %1 items %1 items - + %1 selected %1 selected - + Empty Trash Empty Trash @@ -445,6 +446,11 @@ Drives Drives + + + Computer + + PropertiesDialog @@ -497,22 +503,22 @@ SideBar - + Open Open - + Open in new window - + Eject - + Unmount diff --git a/translations/zh_CN.ts b/translations/zh_CN.ts index ebddd27..5a52b3a 100644 --- a/translations/zh_CN.ts +++ b/translations/zh_CN.ts @@ -127,112 +127,113 @@ 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 显示隐藏文件 - + Open in new window 在新窗口中打开 @@ -240,98 +241,98 @@ FolderPage - + Empty folder 空文件夹 - + Open 打开 - - + + Properties 属性 - + File 文件 - + New Folder 新建文件夹 - + Quit 退出 - + Edit 编辑 - + Select All 全选 - + Cut 剪切 - + Copy 复制 - + Paste 粘贴 - + Help 帮助 - + About 关于 - + File Manager 文件管理器 - + A file manager designed for CutefishOS. 专为 CutefishOS 打造的文件管理器 - + %1 item %1 项 - + %1 items %1 项 - + %1 selected 选中了 %1 项 - + Empty Trash 清空回收站 @@ -445,6 +446,11 @@ Drives 设备 + + + Computer + 计算机 + PropertiesDialog @@ -505,22 +511,22 @@ SideBar - + Open 打开 - + Open in new window 在新窗口中打开 - + Eject 弹出 - + Unmount 卸载