2023-04-11 10:19:35 +08:00
|
|
|
/*
|
|
|
|
*
|
|
|
|
* Copyright (C) 2023, KylinSoft Co., Ltd.
|
|
|
|
*
|
|
|
|
* 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
|
|
|
|
* (at your option) 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 <https://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
* Authors: iaom <zhangpengfei@kylinos.cn>
|
|
|
|
*/
|
2022-03-01 17:39:53 +08:00
|
|
|
#ifndef APPINFOTABLE_H
|
|
|
|
#define APPINFOTABLE_H
|
|
|
|
|
|
|
|
#include <QObject>
|
2023-03-07 17:33:08 +08:00
|
|
|
#include <QSqlQuery>
|
2023-03-14 14:01:28 +08:00
|
|
|
#include <QDir>
|
2023-03-07 17:33:08 +08:00
|
|
|
#include "application-property.h"
|
2022-06-28 11:20:36 +08:00
|
|
|
|
2022-03-01 17:39:53 +08:00
|
|
|
namespace UkuiSearch {
|
2022-06-28 11:20:36 +08:00
|
|
|
|
2023-03-14 14:01:28 +08:00
|
|
|
const static QString APP_DATABASE_PATH = QDir::homePath()+"/.config/org.ukui/ukui-search/appdata/";
|
|
|
|
const static QString APP_DATABASE_NAME = "app-info.db";
|
|
|
|
|
2022-03-01 17:39:53 +08:00
|
|
|
class AppInfoTablePrivate;
|
|
|
|
class AppInfoTable : public QObject
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
2023-03-07 17:33:08 +08:00
|
|
|
static AppInfoTable* self();
|
|
|
|
|
2022-03-01 17:39:53 +08:00
|
|
|
AppInfoTable(AppInfoTable &) = delete;
|
|
|
|
AppInfoTable &operator =(const AppInfoTable &) = delete;
|
2023-03-15 16:39:38 +08:00
|
|
|
|
|
|
|
bool query(ApplicationPropertyMap &propertyMap, const QString &desktopFile, ApplicationProperties properties);
|
|
|
|
bool query(ApplicationInfoMap &infoMap, ApplicationProperties properties);
|
|
|
|
bool query(ApplicationInfoMap &infoMap, ApplicationProperties properties, ApplicationPropertyMap restrictions);
|
|
|
|
bool query(ApplicationInfoMap &infoMap, ApplicationProperties properties, const QStringList &keywords, ApplicationPropertyMap restrictions);
|
2022-03-01 17:39:53 +08:00
|
|
|
|
2022-06-28 11:20:36 +08:00
|
|
|
/**
|
|
|
|
* @brief AppInfoTable::setAppFavoritesState
|
2023-03-31 17:24:06 +08:00
|
|
|
* set the app to favorites apps(default is at 1)
|
2022-06-28 11:20:36 +08:00
|
|
|
* @param desktopfp: the desktop file path of app
|
|
|
|
*/
|
2023-03-31 17:24:06 +08:00
|
|
|
void setAppFavoritesState(const QString &desktopfp);
|
2022-06-28 11:20:36 +08:00
|
|
|
|
|
|
|
/**
|
2023-03-31 17:24:06 +08:00
|
|
|
* @brief AppInfoTable::setAppFavoritesState
|
|
|
|
* set the favorites state of the app, you can also use to change the position of the app which is one of the Favorites Apps
|
2022-06-28 11:20:36 +08:00
|
|
|
* @param desktopfp: the desktop file path of app
|
2023-03-31 17:24:06 +08:00
|
|
|
* @param num: the favorites app's order(from 1)
|
2022-06-28 11:20:36 +08:00
|
|
|
*/
|
2023-03-31 17:24:06 +08:00
|
|
|
void setAppFavoritesState(const QString &desktopfp, size_t num);
|
2022-06-13 13:38:47 +08:00
|
|
|
|
|
|
|
/**
|
2023-03-31 17:24:06 +08:00
|
|
|
* @brief AppInfoTable::setAppTopState
|
|
|
|
* set the app to top apps(default is at 1)
|
2022-06-28 11:20:36 +08:00
|
|
|
* @param desktopfp: desktop file path of app
|
2022-06-13 13:38:47 +08:00
|
|
|
*/
|
2023-03-31 17:24:06 +08:00
|
|
|
void setAppTopState(const QString &desktopfp);
|
2022-06-28 11:20:36 +08:00
|
|
|
|
|
|
|
/**
|
2023-03-31 17:24:06 +08:00
|
|
|
* @brief AppInfoTable::setAppTopState
|
|
|
|
* set the top state of the app, you can also use to change the position of the app which is one of the Top Apps
|
|
|
|
* @param desktopfp: the desktop file path of app
|
|
|
|
* @param num: the top app's order(from 1)
|
2022-06-28 11:20:36 +08:00
|
|
|
*/
|
2023-03-31 17:24:06 +08:00
|
|
|
void setAppTopState(const QString &desktopfp, size_t num);
|
2022-06-28 11:20:36 +08:00
|
|
|
|
2022-06-13 13:38:47 +08:00
|
|
|
bool searchInstallApp(QString &keyWord, QStringList &installAppInfoRes);
|
|
|
|
bool searchInstallApp(QStringList &keyWord, QStringList &installAppInfoRes);
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2022-06-28 11:20:36 +08:00
|
|
|
* @brief AppInfoTable::lastError
|
|
|
|
* the last error of the database
|
|
|
|
* @return QString: the text of the last error
|
2022-06-13 13:38:47 +08:00
|
|
|
*/
|
|
|
|
QString lastError(void) const;
|
|
|
|
|
2023-02-17 15:55:10 +08:00
|
|
|
/**
|
|
|
|
* @brief AppInfoTable::tranPid2DesktopFp
|
|
|
|
* find the desktop file path of the process which corresponds to the pid
|
|
|
|
* @param pid: the pid of the process which need to get its desktop file path
|
|
|
|
* @param desktopfp: the desktop file path of the process corresponding to pid
|
|
|
|
* @return bool:true if success,else false
|
|
|
|
*/
|
|
|
|
bool tranPidToDesktopFp(int pid, QString &desktopfp);
|
|
|
|
|
2022-03-01 17:39:53 +08:00
|
|
|
private:
|
2022-06-28 14:00:57 +08:00
|
|
|
//暂不外放的接口
|
2023-03-14 16:06:37 +08:00
|
|
|
bool setAppLaunchTimes(const QString &desktopfp, size_t num);
|
|
|
|
bool setAppLockState(const QString &desktopfp, size_t num);
|
|
|
|
bool updateAppLaunchTimes(const QString &desktopfp);
|
2022-06-13 13:38:47 +08:00
|
|
|
|
2022-06-28 14:00:57 +08:00
|
|
|
private:
|
2023-03-07 17:33:08 +08:00
|
|
|
explicit AppInfoTable(QObject *parent = nullptr);
|
2022-03-01 17:39:53 +08:00
|
|
|
AppInfoTablePrivate *d;
|
2022-06-28 11:20:36 +08:00
|
|
|
|
2022-06-23 10:12:02 +08:00
|
|
|
Q_SIGNALS:
|
|
|
|
void DBOpenFailed();
|
2023-03-14 14:01:28 +08:00
|
|
|
void appDBItems2BUpdate(ApplicationInfoMap);
|
|
|
|
void appDBItems2BUpdateAll(QStringList);
|
|
|
|
void appDBItems2BAdd(QStringList);
|
2022-06-28 11:20:36 +08:00
|
|
|
void appDBItems2BDelete(QStringList);
|
2022-03-01 17:39:53 +08:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif // APPINFOTABLE_H
|