2022-04-24 14:52:13 +08:00
|
|
|
/*
|
2022-05-15 12:10:42 +08:00
|
|
|
* Copyright (C) 2021 ~ 2022 Deepin Technology Co., Ltd.
|
2022-04-24 14:52:13 +08:00
|
|
|
*
|
|
|
|
* Author: weizhixiang <weizhixiang@uniontech.com>
|
|
|
|
*
|
|
|
|
* Maintainer: weizhixiang <weizhixiang@uniontech.com>
|
|
|
|
*
|
|
|
|
* 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 <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef LAUNCHER_H
|
|
|
|
#define LAUNCHER_H
|
|
|
|
|
|
|
|
#include "common.h"
|
|
|
|
#include "synmodule.h"
|
|
|
|
#include "category.h"
|
2022-05-19 13:13:55 +08:00
|
|
|
#include "launcheriteminfolist.h"
|
2022-04-24 14:52:13 +08:00
|
|
|
|
|
|
|
#include <QObject>
|
|
|
|
#include <QMap>
|
|
|
|
#include <QVector>
|
|
|
|
#include <QDBusMessage>
|
|
|
|
#include <QDBusContext>
|
|
|
|
|
|
|
|
// 同步数据
|
|
|
|
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;
|
2022-05-19 13:13:55 +08:00
|
|
|
//QStringList keywords; // 存放前端搜索关键字 name enName
|
2022-04-24 14:52:13 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
// 应用信息类
|
|
|
|
struct Item {
|
|
|
|
inline bool isValid() {return !info.path.isEmpty();}
|
|
|
|
|
2022-05-19 13:13:55 +08:00
|
|
|
LauncherItemInfo info;
|
|
|
|
QStringList desktopKeywords; //desktop file keywords
|
2022-04-24 14:52:13 +08:00
|
|
|
QStringList categories;
|
|
|
|
QString xDeepinCategory;
|
|
|
|
QString exec;
|
|
|
|
QString genericName;
|
|
|
|
QString comment;
|
|
|
|
std::map<QString, int> 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<QString, Item> *getItems();
|
|
|
|
|
|
|
|
int getDisplayMode();
|
|
|
|
bool getFullScreen();
|
|
|
|
void setDisplayMode(int value);
|
2022-05-19 13:13:55 +08:00
|
|
|
void setFullscreen(bool isFull);
|
2022-04-24 14:52:13 +08:00
|
|
|
|
2022-05-19 13:13:55 +08:00
|
|
|
LauncherItemInfoList getAllItemInfos();
|
2022-04-24 14:52:13 +08:00
|
|
|
QStringList getAllNewInstalledApps();
|
|
|
|
bool getDisableScaling(QString appId);
|
2022-05-19 13:13:55 +08:00
|
|
|
LauncherItemInfo getItemInfo(QString appId);
|
2022-04-24 14:52:13 +08:00
|
|
|
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:
|
2022-05-19 13:13:55 +08:00
|
|
|
void itemChanged(QString status, LauncherItemInfo itemInfo, qint64 ty);
|
|
|
|
void newAppLaunched(QString appId);
|
|
|
|
void uninstallSuccess(QString appId);
|
|
|
|
void uninstallFailed(QString appId, QString errMsg);
|
2022-04-24 14:52:13 +08:00
|
|
|
|
|
|
|
void displayModeChanged(int mode);
|
|
|
|
void fullScreenChanged(bool isFull);
|
2022-07-13 10:45:22 +08:00
|
|
|
void appSuffixChanged();
|
2022-04-24 14:52:13 +08:00
|
|
|
|
2022-08-24 18:18:47 +08:00
|
|
|
void uninstallStatusChanged(const bool status);
|
|
|
|
|
2022-04-24 14:52:13 +08:00
|
|
|
private Q_SLOTS:
|
|
|
|
void handleFSWatcherEvents(QDBusMessage msg);
|
2022-07-13 10:45:22 +08:00
|
|
|
void onAppSuffixNameChanged(bool hidden);
|
2022-08-19 16:07:41 +08:00
|
|
|
void onCheckDesktopFile(const QString &filePath, int type = 0);
|
|
|
|
void onNewAppLaunched(const QString &filePath);
|
2022-08-24 18:18:47 +08:00
|
|
|
void onHandleUninstall(const QDBusMessage &message);
|
2022-04-24 14:52:13 +08:00
|
|
|
|
|
|
|
private:
|
2022-08-19 16:07:41 +08:00
|
|
|
void initConnection();
|
2022-04-24 14:52:13 +08:00
|
|
|
void initSettings();
|
|
|
|
void loadDesktopPkgMap();
|
|
|
|
void loadPkgCategoryMap();
|
|
|
|
void handleAppHiddenChanged();
|
|
|
|
void loadNameMap();
|
|
|
|
void initItems();
|
|
|
|
QString getAppIdByFilePath(QString filePath, QStringList dirs);
|
|
|
|
bool isDeepinCustomDesktopFile(QString fileName);
|
|
|
|
Item NewItemWithDesktopInfo(DesktopInfo &info);
|
2022-08-19 16:07:41 +08:00
|
|
|
void addItem(Item &item);
|
2022-04-24 14:52:13 +08:00
|
|
|
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);
|
|
|
|
|
2022-07-13 10:45:22 +08:00
|
|
|
private:
|
2022-07-22 15:17:43 +08:00
|
|
|
QMap<QString, Item> itemsMap; // appId, Item
|
2022-04-24 14:52:13 +08:00
|
|
|
QMap<QString, QString> desktopPkgMap;
|
|
|
|
QMap<QString, Categorytype> pkgCategoryMap;
|
2022-07-22 15:17:43 +08:00
|
|
|
QMap<QString, QString> nameMap; // appId, Name
|
2022-04-24 14:52:13 +08:00
|
|
|
QMap<QString, int> noPkgItemIds;
|
|
|
|
QVector<QString> appsHidden;
|
2022-07-13 10:45:22 +08:00
|
|
|
|
2022-04-24 14:52:13 +08:00
|
|
|
QStringList appDirs;
|
2022-07-22 15:17:43 +08:00
|
|
|
|
|
|
|
QMap<QString, Item> m_desktopAndItemMap; // desktoppath,Item
|
2022-04-24 14:52:13 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // LAUNCHER_H
|