/* * Copyright (C) 2021 ~ 2022 Deepin Technology Co., Ltd. * * Author: weizhixiang * * Maintainer: weizhixiang * * 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 * the Free Software Foundation, either version 3 of the License, or * any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ #ifndef LAUNCHER_H #define LAUNCHER_H #include "common.h" #include "synmodule.h" #include "category.h" #include "launcheriteminfolist.h" #include #include #include #include #include // 同步数据 struct SyncData { QString version; QString display_mode; bool fullscreen; }; // 应用类型 enum class AppType { Flatpak, ChromeShortcut, CrossOver, WineApp, Default }; // 应用基本信息 struct ItemInfo { QString path; QString name; QString id; QString icon; Categorytype categoryId; int64_t timeInstalled; //QStringList keywords; // 存放前端搜索关键字 name enName }; // 应用信息类 struct Item { inline bool isValid() {return !info.path.isEmpty();} LauncherItemInfo info; QStringList desktopKeywords; //desktop file keywords QStringList categories; QString xDeepinCategory; QString exec; QString genericName; QString comment; std::map searchTargets; }; class DesktopInfo; class Launcher : public SynModule, public QDBusContext { Q_OBJECT public: explicit Launcher(QObject *parent); ~Launcher(); // 设置配置 void setSynConfig(QByteArray ba); QByteArray getSyncConfig(); const QMap *getItems(); int getDisplayMode(); bool getFullScreen(); void setDisplayMode(int value); void setFullscreen(bool isFull); LauncherItemInfoList getAllItemInfos(); QStringList getAllNewInstalledApps(); bool getDisableScaling(QString appId); LauncherItemInfo getItemInfo(QString appId); bool getUseProxy(QString appId); bool isItemOnDesktop(QString appId); bool requestRemoveFromDesktop(QString appId); bool requestSendToDesktop(QString appId); void requestUninstall(QString appId); void setDisableScaling(QString appId, bool value); void setUseProxy(QString appId, bool value); Q_SIGNALS: void itemChanged(QString status, LauncherItemInfo itemInfo, qint64 ty); void newAppLaunched(QString appId); void uninstallSuccess(QString appId); void uninstallFailed(QString appId, QString errMsg); void displayModeChanged(int mode); void fullScreenChanged(bool isFull); void appSuffixChanged(); private Q_SLOTS: void handleFSWatcherEvents(QDBusMessage msg); void onAppSuffixNameChanged(bool hidden); private: void initSettings(); void loadDesktopPkgMap(); void loadPkgCategoryMap(); void checkDesktopFile(QString filePath); void handleAppHiddenChanged(); void loadNameMap(); void initItems(); QString getAppIdByFilePath(QString filePath, QStringList dirs); bool isDeepinCustomDesktopFile(QString fileName); Item NewItemWithDesktopInfo(DesktopInfo &info); void addItem(Item item); Categorytype queryCategoryId(const Item *item); Categorytype getXCategory(const Item *item); QString queryPkgName(const QString &itemID, const QString &itemPath); QString queryPkgNameWithDpkg(const QString &itemPath); Item getItemByPath(QString itemPath); void emitItemChanged(const Item *item, QString status); AppType getAppType(DesktopInfo &info, const Item &item); bool doUninstall(DesktopInfo &info, const Item &item); bool uninstallFlatpak(DesktopInfo &info, const Item &item); bool uninstallWineApp(const Item &item); bool uninstallSysApp(const QString &name, const QString &pkg); bool removeDesktop(const Item &item); void notifyUninstallDone(const Item &item, bool result); private: QMap itemsMap; // appKey, Item QMap desktopPkgMap; QMap pkgCategoryMap; QMap nameMap; QMap noPkgItemIds; QVector appsHidden; QStringList appDirs; }; #endif // LAUNCHER_H