ukui-search/libsearch/appdata/app-info-table.h

102 lines
3.5 KiB
C++

#ifndef APPINFOTABLE_H
#define APPINFOTABLE_H
#include <QObject>
#include <QSqlQuery>
#include <QDir>
#include "application-property.h"
namespace UkuiSearch {
const static QString APP_DATABASE_PATH = QDir::homePath()+"/.config/org.ukui/ukui-search/appdata/";
const static QString APP_DATABASE_NAME = "app-info.db";
class AppInfoTablePrivate;
class AppInfoTable : public QObject
{
Q_OBJECT
public:
static AppInfoTable* self();
AppInfoTable(AppInfoTable &) = delete;
AppInfoTable &operator =(const AppInfoTable &) = delete;
bool query(PropertyMap &propertyMap, const QString &desktopFile, Properties properties);
bool query(ApplicationInfoMap &infoMap, Properties properties);
bool query(ApplicationInfoMap &infoMap, Properties properties, PropertyMap restrictions);
bool query(ApplicationInfoMap &infoMap, Properties properties, const QString &keyword, PropertyMap restrictions);
bool query(ApplicationInfoMap &infoMap, Properties properties, const QStringList &keywords, PropertyMap restrictions);
/**
* @brief AppInfoTable::setAppFavoritesState
* set the favorites state of the app
* @param desktopfp: the desktop file path of app
* @param num: the favorites app's order(from 1)
*/
void setAppFavoritesState(const QString &desktopfp, size_t num);
/**
* @brief AppInfoTable::setAppTopState
* set the top state of the app
* @param desktopfp: the desktop file path of app
* @param num: the top app's order(from 1)
*/
void setAppTopState(const QString &desktopfp, size_t num);
/**
* @brief AppInfoTable::changeFavoriteAppPos
* change the position of the app which is one of the Favorites Apps
* @param desktopfp: desktop file path of app
* @param pos: the position which the app will be changed into
*/
bool changeFavoriteAppPos(const QString &desktopfp, size_t pos);
/**
* @brief AppInfoTable::changeTopAppPos
* hange the position of the app which is one of the Top Apps
* @param desktopfp: desktop file path of app
* @param pos: the position which the app will be changed into
* @return bool: true if success, else false
*/
bool changeTopAppPos(const QString &desktopfp, size_t pos);
bool searchInstallApp(QString &keyWord, QStringList &installAppInfoRes);
bool searchInstallApp(QStringList &keyWord, QStringList &installAppInfoRes);
/**
* @brief AppInfoTable::lastError
* the last error of the database
* @return QString: the text of the last error
*/
QString lastError(void) const;
/**
* @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);
private:
//暂不外放的接口
bool setAppLaunchTimes(const QString &desktopfp, size_t num);
bool setAppLockState(const QString &desktopfp, size_t num);
bool updateAppLaunchTimes(const QString &desktopfp);
private:
explicit AppInfoTable(QObject *parent = nullptr);
AppInfoTablePrivate *d;
Q_SIGNALS:
void DBOpenFailed();
void appDBItems2BUpdate(ApplicationInfoMap);
void appDBItems2BUpdateAll(QStringList);
void appDBItems2BAdd(QStringList);
void appDBItems2BDelete(QStringList);
};
}
#endif // APPINFOTABLE_H