From 20a2642e7468a54b02530cda26c1cb0449a4f856 Mon Sep 17 00:00:00 2001 From: songwentao Date: Wed, 13 Jul 2022 10:45:22 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E7=8E=B2=E7=8F=91=E5=8C=85=E5=90=8E?= =?UTF-8?q?=E7=BC=80=E6=8F=90=E4=BE=9B=E9=85=8D=E7=BD=AE=E5=8A=9F=E8=83=BD?= =?UTF-8?q?=E5=AE=9E=E7=8E=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 玲珑包后缀提供配置功能的实现 Log: Influence: 默认隐藏后缀,开启,玲珑应用则显示,否则,隐藏. Task: https://pms.uniontech.com/task-view-152805.html Change-Id: I72e390a8e25396454c451cde28a795e923b28144 --- misc/dconf/com.deepin.dde.launcher.json | 10 ++++++++++ src/modules/launcher/common.h | 1 + src/modules/launcher/dbusadaptorlauncher.cpp | 1 + src/modules/launcher/dbusadaptorlauncher.h | 5 ++++- src/modules/launcher/launcher.cpp | 18 ++++++++++++++---- src/modules/launcher/launcher.h | 7 +++++-- src/modules/launcher/launchersettings.cpp | 17 +++++++++++++++++ src/modules/launcher/launchersettings.h | 4 ++++ src/service/main.cpp | 2 +- 9 files changed, 57 insertions(+), 8 deletions(-) diff --git a/misc/dconf/com.deepin.dde.launcher.json b/misc/dconf/com.deepin.dde.launcher.json index 696cd65..dcd474c 100644 --- a/misc/dconf/com.deepin.dde.launcher.json +++ b/misc/dconf/com.deepin.dde.launcher.json @@ -241,6 +241,16 @@ "description": "Launcher display mode.", "permissions": "readwrite", "visibility": "private" + }, + "MagicaVoxelApp_Hide_SuffixName": { + "value": false, + "serial": 0, + "flags": [], + "name": "MagicaVoxelApp_Hide_SuffixName", + "name[zh_CN]": "玲珑包后缀提供配置,默认隐藏; 开启, 玲珑应用显示后缀, 关闭, 后缀隐藏", + "description": "***", + "permissions": "readwrite", + "visibility": "private" } } } diff --git a/src/modules/launcher/common.h b/src/modules/launcher/common.h index 9773942..d47e81e 100644 --- a/src/modules/launcher/common.h +++ b/src/modules/launcher/common.h @@ -37,6 +37,7 @@ const QString keyAppsUseProxy = "Apps_Use_Proxy"; const QString keyAppsDisableScaling = "Apps_Disable_Scaling"; const QString keyAppsHidden = "Apps_Hidden"; const QString keyPackageNameSearch = "Search_Package_Name"; +const QString keySuffixHidden = "MagicaVoxelApp_Hide_SuffixName"; // 应用配置 const QString lastoreDataDir = "/var/lib/lastore"; diff --git a/src/modules/launcher/dbusadaptorlauncher.cpp b/src/modules/launcher/dbusadaptorlauncher.cpp index 2e432a1..2e2b6db 100644 --- a/src/modules/launcher/dbusadaptorlauncher.cpp +++ b/src/modules/launcher/dbusadaptorlauncher.cpp @@ -34,6 +34,7 @@ DBusAdaptorLauncher::DBusAdaptorLauncher(QObject *parent) connect(launcher, &Launcher::uninstallSuccess, this, &DBusAdaptorLauncher::UninstallSuccess); connect(launcher, &Launcher::displayModeChanged, this, &DBusAdaptorLauncher::DisplayModeChanged); connect(launcher, &Launcher::fullScreenChanged, this, &DBusAdaptorLauncher::FullScreenChanged); + connect(launcher, &Launcher::appSuffixChanged, this, &DBusAdaptorLauncher::AppSuffixChanged); } } diff --git a/src/modules/launcher/dbusadaptorlauncher.h b/src/modules/launcher/dbusadaptorlauncher.h index 5503216..f647263 100644 --- a/src/modules/launcher/dbusadaptorlauncher.h +++ b/src/modules/launcher/dbusadaptorlauncher.h @@ -116,10 +116,11 @@ public: public: // PROPERTIES Q_PROPERTY(int DisplayMode READ displayMode WRITE setDisplayMode NOTIFY DisplayModeChanged) + Q_PROPERTY(bool Fullscreen READ fullscreen WRITE setFullscreen NOTIFY FullScreenChanged) + int displayMode() const; void setDisplayMode(int value); - Q_PROPERTY(bool Fullscreen READ fullscreen WRITE setFullscreen NOTIFY FullScreenChanged) bool fullscreen() const; void setFullscreen(bool value); @@ -135,6 +136,7 @@ public Q_SLOTS: // METHODS void RequestUninstall(const QString &id); void SetDisableScaling(const QString &id, bool value); void SetUseProxy(const QString &id, bool value); + Q_SIGNALS: // SIGNALS void ItemChanged(const QString &status, const LauncherItemInfo &itemInfo, qlonglong categoryID); void NewAppLaunched(const QString &appID); @@ -143,6 +145,7 @@ Q_SIGNALS: // SIGNALS void DisplayModeChanged(int mode); void FullScreenChanged(bool isFull); + void AppSuffixChanged(); }; #endif diff --git a/src/modules/launcher/launcher.cpp b/src/modules/launcher/launcher.cpp index 021f60c..5a07b6a 100644 --- a/src/modules/launcher/launcher.cpp +++ b/src/modules/launcher/launcher.cpp @@ -51,6 +51,7 @@ Launcher::Launcher(QObject *parent) : SynModule(parent) { registeModule("launcher"); + appsHidden = SETTING->getHiddenApps(); initSettings(); for (auto dir : BaseDir::appDirs()) { @@ -443,6 +444,13 @@ void Launcher::handleFSWatcherEvents(QDBusMessage msg) } } +void Launcher::onAppSuffixNameChanged(bool) +{ + initItems(); + + Q_EMIT appSuffixChanged(); +} + /** * @brief Launcher::initSettings 初始化启动器配置 */ @@ -453,8 +461,7 @@ void Launcher::initSettings() }); connect(SETTING, &LauncherSettings::fullscreenChanged, this, &Launcher::fullScreenChanged); connect(SETTING, &LauncherSettings::hiddenAppsChanged, this, &Launcher::handleAppHiddenChanged); - - appsHidden = SETTING->getHiddenApps(); + connect(SETTING, &LauncherSettings::appSuffixNameChanged, this, &Launcher::onAppSuffixNameChanged); } /** @@ -695,7 +702,6 @@ Categorytype Launcher::queryCategoryId(const Item *item) if (category != Categorytype::CategoryErr) return category; - return getXCategory(item); } @@ -1131,7 +1137,7 @@ bool Launcher::isDeepinCustomDesktopFile(QString fileName) && fileInfo.baseName().startsWith("deepin-custom-"); } -Item Launcher:: NewItemWithDesktopInfo(DesktopInfo &info) +Item Launcher::NewItemWithDesktopInfo(DesktopInfo &info) { QString enName(info.getKeyFile()->getStr(MainSection, KeyName).c_str()); QString enComment(info.getKeyFile()->getStr(MainSection, KeyComment).c_str()); @@ -1165,6 +1171,10 @@ Item Launcher:: NewItemWithDesktopInfo(DesktopInfo &info) item.info.icon = info.getIcon().c_str(); } + // 玲珑应用添加后缀, 默认隐藏 + if (SETTING->getMagicaVoxelSuffixHidden() && appFileName.startsWith("/persistent/linglong/entries/share/applications/")) + item.info.name = QString("%1(%2)").arg(appName).arg(tr("magicaVoxel")); + xDeepinCategory = xDeepinCategory.toLower(); for (auto &keyWord : info.getKeywords()) { diff --git a/src/modules/launcher/launcher.h b/src/modules/launcher/launcher.h index ac8338e..7e724dc 100644 --- a/src/modules/launcher/launcher.h +++ b/src/modules/launcher/launcher.h @@ -114,9 +114,11 @@ Q_SIGNALS: void displayModeChanged(int mode); void fullScreenChanged(bool isFull); + void appSuffixChanged(); private Q_SLOTS: void handleFSWatcherEvents(QDBusMessage msg); + void onAppSuffixNameChanged(bool hidden); private: void initSettings(); @@ -144,13 +146,14 @@ private: bool removeDesktop(const Item &item); void notifyUninstallDone(const Item &item, bool result); - - QMap itemsMap; +private: + QMap itemsMap; // appKey, Item QMap desktopPkgMap; QMap pkgCategoryMap; QMap nameMap; QMap noPkgItemIds; QVector appsHidden; + QStringList appDirs; }; diff --git a/src/modules/launcher/launchersettings.cpp b/src/modules/launcher/launchersettings.cpp index da876f4..79f99d7 100644 --- a/src/modules/launcher/launchersettings.cpp +++ b/src/modules/launcher/launchersettings.cpp @@ -42,6 +42,8 @@ LauncherSettings::LauncherSettings(QObject *parent) Q_EMIT fullscreenChanged(m_dconfig->value(key).toBool()); } else if (key == keyAppsHidden) { Q_EMIT hiddenAppsChanged(); + } else if (key == keySuffixHidden) { + Q_EMIT appSuffixNameChanged(m_dconfig->value(key).toBool()); } }); } @@ -163,3 +165,18 @@ QVector LauncherSettings::getHiddenApps() } return ret; } + +bool LauncherSettings::getMagicaVoxelSuffixHidden() const +{ + return m_dconfig ? m_dconfig->value(keySuffixHidden, false).toBool() : false; +} + +void LauncherSettings::setMagicaVoxelSuffixHidden(bool state) +{ + if (!m_dconfig) { + qInfo() << Q_FUNC_INFO << "set magicaVoxel suffix failed!"; + return; + } + + m_dconfig->setValue(keySuffixHidden, state); +} diff --git a/src/modules/launcher/launchersettings.h b/src/modules/launcher/launchersettings.h index 240c6dd..8b8a781 100644 --- a/src/modules/launcher/launchersettings.h +++ b/src/modules/launcher/launchersettings.h @@ -64,10 +64,14 @@ public: QVector getHiddenApps(); + bool getMagicaVoxelSuffixHidden() const; + void setMagicaVoxelSuffixHidden(bool hidden); + Q_SIGNALS: void displayModeChanged(QString mode); void fullscreenChanged(bool isFull); void hiddenAppsChanged(); + void appSuffixNameChanged(bool); }; #endif // LAUNCHERSETTINGS_H diff --git a/src/service/main.cpp b/src/service/main.cpp index edb7413..bc38221 100644 --- a/src/service/main.cpp +++ b/src/service/main.cpp @@ -53,7 +53,7 @@ QList> scanFiles() user = getpwent(); } endpwent(); - auto linglong = scan("/deepin/linglong/entries/share/applications/"); + auto linglong = scan("/persistent/linglong/entries/share/applications/"); for (const QFileInfo &info : linglong) { applications << QSharedPointer(new Application( "linglong",