forked from openkylin/ukui-search
Add app infos in autostart dir.
Add DONT_DISPLAY field to database. Use ApplicationInfoMap instead of the previous structure to transform apps' data.
This commit is contained in:
parent
b1a8486bd1
commit
f9a638c05b
|
@ -1,30 +0,0 @@
|
|||
#ifndef APPDBCOMMON_H
|
||||
#define APPDBCOMMON_H
|
||||
|
||||
#include <QDir>
|
||||
|
||||
namespace UkuiSearch {
|
||||
|
||||
#define APP_DATABASE_PATH QDir::homePath()+"/.config/org.ukui/ukui-search/appdata/"
|
||||
#define APP_DATABASE_NAME "app-info.db"
|
||||
|
||||
struct AppInfoResult
|
||||
{
|
||||
public:
|
||||
QString desktopPath;
|
||||
QString iconName;
|
||||
QString appLocalName;
|
||||
QString firstLetter;
|
||||
QString category;
|
||||
int top;
|
||||
int favorite;
|
||||
int launchTimes;
|
||||
int lock;
|
||||
|
||||
AppInfoResult() : top(0), favorite(0), launchTimes(0), lock(0) {}
|
||||
};
|
||||
}
|
||||
|
||||
Q_DECLARE_METATYPE(UkuiSearch::AppInfoResult)
|
||||
|
||||
#endif // APPDBCOMMON_H
|
|
@ -1,31 +0,0 @@
|
|||
#ifndef APPINFODBUSARGUMENT_H
|
||||
#define APPINFODBUSARGUMENT_H
|
||||
|
||||
#include <QDBusArgument>
|
||||
#include "app-db-common.h"
|
||||
|
||||
namespace UkuiSearch {
|
||||
|
||||
QDBusArgument &operator << (QDBusArgument &argument, const AppInfoResult &infoResult)
|
||||
{
|
||||
argument.beginStructure();
|
||||
argument << infoResult.desktopPath << infoResult.iconName << infoResult.appLocalName << infoResult.firstLetter
|
||||
<< infoResult.category << infoResult.top << infoResult.favorite << infoResult.launchTimes << infoResult.lock;
|
||||
argument.endStructure();
|
||||
return argument;
|
||||
}
|
||||
|
||||
const QDBusArgument &operator >> (const QDBusArgument &argument, AppInfoResult &infoResult)
|
||||
{
|
||||
argument.beginStructure();
|
||||
argument >> infoResult.desktopPath >> infoResult.iconName >> infoResult.appLocalName >> infoResult.firstLetter
|
||||
>> infoResult.category >> infoResult.top >> infoResult.favorite >> infoResult.launchTimes >> infoResult.lock;
|
||||
|
||||
argument.endStructure();
|
||||
return argument;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
#endif // APPINFODBUSARGUMENT_H
|
|
@ -0,0 +1,82 @@
|
|||
#ifndef APPINFODBUSARGUMENT_H
|
||||
#define APPINFODBUSARGUMENT_H
|
||||
|
||||
#include <QDBusArgument>
|
||||
#include "application-property.h"
|
||||
|
||||
namespace UkuiSearch {
|
||||
|
||||
QDBusArgument &operator << (QDBusArgument &argument, const ApplicationProperty::Property &property) {
|
||||
argument.beginStructure();
|
||||
argument << static_cast<int>(property);
|
||||
argument.endStructure();
|
||||
return argument;
|
||||
}
|
||||
|
||||
const QDBusArgument &operator >> (const QDBusArgument &argument, ApplicationProperty::Property &property) {
|
||||
int value;
|
||||
argument.beginStructure();
|
||||
argument >> value;
|
||||
argument.endStructure();
|
||||
property = static_cast<ApplicationProperty::Property>(value);
|
||||
return argument;
|
||||
}
|
||||
|
||||
QDBusArgument &operator << (QDBusArgument &argument, const PropertyMap &appPropertyInfo)
|
||||
{
|
||||
argument.beginMap(/*qMetaTypeId<ApplicationProperty::Property>()*/QVariant::Int, qMetaTypeId<QDBusVariant>());
|
||||
for (auto i = appPropertyInfo.constBegin(); i != appPropertyInfo.constEnd(); ++i) {
|
||||
QDBusVariant dbusVariant(i.value());
|
||||
argument.beginMapEntry();
|
||||
argument << static_cast<int>(i.key()) << dbusVariant;
|
||||
argument.endMapEntry();
|
||||
}
|
||||
argument.endMap();
|
||||
return argument;
|
||||
}
|
||||
|
||||
const QDBusArgument &operator >> (const QDBusArgument &argument, PropertyMap &appPropertyInfo)
|
||||
{
|
||||
argument.beginMap();
|
||||
while (!argument.atEnd()) {
|
||||
int key;
|
||||
QVariant value;
|
||||
argument.beginMapEntry();
|
||||
argument >> key >> value;
|
||||
argument.endMapEntry();
|
||||
appPropertyInfo.insert(static_cast<ApplicationProperty::Property>(key), value);
|
||||
}
|
||||
argument.endMap();
|
||||
return argument;
|
||||
}
|
||||
|
||||
QDBusArgument &operator << (QDBusArgument &argument, const ApplicationInfoMap &appInfo)
|
||||
{
|
||||
argument.beginMap(QVariant::String, qMetaTypeId<PropertyMap>());
|
||||
for (auto i = appInfo.constBegin(); i != appInfo.constEnd(); ++i) {
|
||||
argument.beginMapEntry();
|
||||
argument << i.key() << i.value();
|
||||
argument.endMapEntry();
|
||||
}
|
||||
argument.endMap();
|
||||
return argument;
|
||||
}
|
||||
|
||||
const QDBusArgument &operator >> (const QDBusArgument &argument, ApplicationInfoMap &appInfo)
|
||||
{
|
||||
argument.beginMap();
|
||||
while (!argument.atEnd()) {
|
||||
QString key;
|
||||
PropertyMap value;
|
||||
argument.beginMapEntry();
|
||||
argument >> key >> value;
|
||||
argument.endMapEntry();
|
||||
appInfo.insert(key, value);
|
||||
}
|
||||
argument.endMap();
|
||||
return argument;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#endif // APPINFODBUSARGUMENT_H
|
|
@ -6,7 +6,8 @@ HEADERS += \
|
|||
# $$PWD/application-info-storage.h \
|
||||
$$PWD/application-info.h \
|
||||
$$PWD/application-property-helper.h \
|
||||
$$PWD/application-property.h
|
||||
$$PWD/application-property.h \
|
||||
$$PWD/app-info-dbus-argument.h
|
||||
|
||||
SOURCES += \
|
||||
$$PWD/app-info-table.cpp \
|
||||
|
|
|
@ -4,7 +4,9 @@
|
|||
#include <QObject>
|
||||
#include <QMap>
|
||||
#include <QVector>
|
||||
#include <QVariant>
|
||||
namespace UkuiSearch {
|
||||
|
||||
namespace ApplicationProperty {
|
||||
/**
|
||||
* @brief 表示应用基础信息
|
||||
|
@ -39,5 +41,4 @@ typedef QMap<ApplicationProperty::Property, QVariant> PropertyMap;
|
|||
typedef QMap<QString, PropertyMap> ApplicationInfoMap; // desktopFile->PropertyMap
|
||||
}
|
||||
Q_DECLARE_METATYPE(UkuiSearch::ApplicationProperty::Property)
|
||||
|
||||
#endif // APPLICATIONPROPERTY_H
|
||||
|
|
|
@ -53,8 +53,6 @@ SOURCES += \
|
|||
libsearch.cpp
|
||||
|
||||
HEADERS += \
|
||||
app-db-common.h \
|
||||
app-info-dbus-argument.h \
|
||||
common.h \
|
||||
file-utils.h \
|
||||
global-settings.h \
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -11,12 +11,14 @@
|
|||
#include <QMutex>
|
||||
#include <QSettings>
|
||||
#include <QThread>
|
||||
#include "app-db-common.h"
|
||||
#include "pending-app-info-queue.h"
|
||||
#include "file-system-watcher.h"
|
||||
#include "application-property.h"
|
||||
|
||||
#define APP_DATABASE_PATH QDir::homePath()+"/.config/org.ukui/ukui-search/appdata/"
|
||||
#define APP_DATABASE_NAME "app-info.db"
|
||||
#define CONNECTION_NAME QLatin1String("ukss-appdb-connection")
|
||||
static const QString APP_DATABASE_VERSION = QStringLiteral("1.0");
|
||||
static const QString APP_DATABASE_VERSION = QStringLiteral("1.1");
|
||||
|
||||
namespace UkuiSearch {
|
||||
/**
|
||||
|
@ -24,18 +26,6 @@ namespace UkuiSearch {
|
|||
* 功能:1.遍历并且监听desktop文件目录,建立并且维护应用信息数据库。
|
||||
* 2.监听应用安装,打开事件,收藏等事件,更新数据库
|
||||
*/
|
||||
class NameString {
|
||||
public:
|
||||
explicit NameString(const QString &str_) : app_name(str_) {}
|
||||
NameString() = default;
|
||||
QString app_name;
|
||||
bool operator<(const NameString& name) const {
|
||||
return this->app_name.length() <= name.app_name.length();
|
||||
}
|
||||
bool operator==(const NameString& name) const {
|
||||
return this->app_name == name.app_name;
|
||||
}
|
||||
};
|
||||
|
||||
class AppDBManager : public QThread
|
||||
{
|
||||
|
@ -52,7 +42,7 @@ public:
|
|||
static AppDBManager *getInstance();
|
||||
|
||||
//刷新数据库数据
|
||||
void refreshAllData2DB();
|
||||
void refreshAllData2DB(const QStringList &appPaths);
|
||||
|
||||
//获取desktop文件的md5值
|
||||
QString getAppDesktopMd5(const QString &desktopfd);
|
||||
|
@ -60,16 +50,15 @@ public:
|
|||
bool startTransaction();
|
||||
bool startCommit();
|
||||
|
||||
bool handleDBItemInsert(const QString &desktopfd);
|
||||
bool handleDBItemUpdate(const QString &desktopfp);
|
||||
bool handleDBItemDelete(const QString &desktopfd);
|
||||
bool handleDBItemInsert(const QString &desktopFilePath);
|
||||
bool handleDBItemUpdate(const QString &desktopFilePath);
|
||||
bool handleDBItemDelete(const QString &desktopFilePath);
|
||||
|
||||
bool handleLocaleDataUpdate(const QString &desktopfp);
|
||||
bool handleLaunchTimesUpdate(const QString &desktopfp, int num);
|
||||
bool handleFavoritesStateUpdate(const QString &desktopfp, int num, bool isOrderChanged = false);
|
||||
bool handleTopStateUpdate(const QString &desktopfp, int num, bool isOrderChanged = false);
|
||||
bool handleLockStateUpdate(const QString &desktopfp, int num);
|
||||
bool createAppInfoResult(const QString &desktopfp, AppInfoResult &result);
|
||||
bool handleLocaleDataUpdate(const QString &desktopFilePath);
|
||||
bool handleLaunchTimesUpdate(const QString &desktopFilePath, int num);
|
||||
bool handleFavoritesStateUpdate(const QString &desktopFilePath, int num, bool isOrderChanged = false);
|
||||
bool handleTopStateUpdate(const QString &desktopFilePath, int num, bool isOrderChanged = false);
|
||||
bool handleLockStateUpdate(const QString &desktopFilePath, int num);
|
||||
|
||||
public Q_SLOTS:
|
||||
//通过pid查找对应的desktop文件
|
||||
|
@ -81,25 +70,15 @@ public Q_SLOTS:
|
|||
void deleteDBItem(const QString &desktopfd);
|
||||
|
||||
//对数据库某字段进行update
|
||||
void updateLocaleData(const QString &desktopfp);
|
||||
void updateLaunchTimes(const QString &desktopfp);
|
||||
void updateFavoritesState(const QString &desktopfp, int num, bool isOrderChanged = false);
|
||||
void updateTopState(const QString &desktopfp, int num, bool isOrderChanged = false);
|
||||
void udpateLockState(const QString &desktopfp, int num);
|
||||
void updateLocaleData(const QString &desktopFilePath);
|
||||
void updateLaunchTimes(const QString &desktopFilePath);
|
||||
void updateFavoritesState(const QString &desktopFilePath, int num, bool isOrderChanged = false);
|
||||
void updateTopState(const QString &desktopFilePath, int num, bool isOrderChanged = false);
|
||||
void udpateLockState(const QString &desktopFilePath, int num);
|
||||
|
||||
//拖动改变置顶和收藏应用位置
|
||||
bool changeFavoriteAppPos(const QString &desktopfp, int pos);
|
||||
bool changeTopAppPos(const QString &desktopfp, int pos);
|
||||
|
||||
//获取数据库中全部信息
|
||||
QVector<AppInfoResult> getAppInfoResults();
|
||||
|
||||
//查询某应用的某个字段的值
|
||||
int getAppLockState(const QString &desktopfp);
|
||||
int getAppTopState(const QString &desktopfp);
|
||||
int getAppLaunchedState(const QString &desktopfp);
|
||||
int getAppFavoriteState(const QString &desktopfp);
|
||||
QString getAppCategory(const QString &desktopfp);
|
||||
bool changeFavoriteAppPos(const QString &desktopFilePath, int pos);
|
||||
bool changeTopAppPos(const QString &desktopFilePath, int pos);
|
||||
|
||||
protected:
|
||||
void run() override;
|
||||
|
@ -114,7 +93,6 @@ private:
|
|||
//数据库查找指定字段不存在则添加到最后并设置初始值
|
||||
bool addItem2BackIfNotExist(QString itemName, QString itemDataType, QVariant defult = QVariant());
|
||||
|
||||
|
||||
//链接数据库
|
||||
bool openDataBase();
|
||||
//刷新数据库
|
||||
|
@ -125,12 +103,6 @@ private:
|
|||
//创建数据库字段
|
||||
void buildAppInfoDB();
|
||||
|
||||
//暂时弃用
|
||||
void updateAppInfoDB();
|
||||
void getAllDesktopFilePath(QString path);
|
||||
void getFilePathList(QStringList &pathList);
|
||||
void getInstallAppMap(QMap<QString, QStringList> &installAppMap);
|
||||
|
||||
private:
|
||||
static QMutex s_mutex;
|
||||
bool m_localeChanged;
|
||||
|
@ -150,6 +122,31 @@ private:
|
|||
QString m_snapdPath;
|
||||
FileSystemWatcher *m_snapdWatcher = nullptr;
|
||||
|
||||
//数据库当前所有字段
|
||||
QMap<QString, QString> m_namesOfAppinfoTable = {
|
||||
{"DESKTOP_FILE_PATH", "TEXT"},
|
||||
{"MODIFYED_TIME", "TEXT"},
|
||||
{"INSERT_TIME","TEXT"},
|
||||
{"LOCAL_NAME", "TEXT"},
|
||||
{"NAME_EN", "TEXT"},
|
||||
{"NAME_ZH", "TEXT"},
|
||||
{"PINYIN_NAME", "TEXT"},
|
||||
{"FIRST_LETTER_OF_PINYIN", "TEXT"},
|
||||
{"FIRST_LETTER_ALL", "TEXT"},
|
||||
{"ICON", "TEXT"},
|
||||
{"TYPE", "TEXT"},
|
||||
{"CATEGORY", "TEXT"},
|
||||
{"EXEC", "TEXT"},
|
||||
{"COMMENT", "TEXT"},
|
||||
{"MD5", "TEXT"},
|
||||
{"LAUNCH_TIMES", "INT"},
|
||||
{"FAVORITES", "INT"},
|
||||
{"LAUNCHED", "INT"},
|
||||
{"TOP", "INT"},
|
||||
{"LOCK", "INT"},
|
||||
{"DONT_DISPLAY", "INT"}
|
||||
};
|
||||
|
||||
//应用黑名单
|
||||
QStringList m_excludedDesktopfiles = {
|
||||
"/usr/share/applications/software-properties-livepatch.desktop",
|
||||
|
@ -199,13 +196,11 @@ private:
|
|||
"/usr/share/applications/screensavers"
|
||||
};
|
||||
|
||||
//暂时弃用
|
||||
QMap<NameString, QStringList> m_installAppMap;
|
||||
|
||||
Q_SIGNALS:
|
||||
//操作数据库
|
||||
void appDBItemUpdate(const AppInfoResult&);
|
||||
void appDBItemAdd(const AppInfoResult&);
|
||||
void appDBItemUpdate(const ApplicationInfoMap&);
|
||||
void appDBItemUpdateAll(const QString&);
|
||||
void appDBItemAdd(const QString&);
|
||||
void appDBItemDelete(const QString&);
|
||||
void finishHandleAppDB();
|
||||
|
||||
|
|
|
@ -8,22 +8,33 @@ SignalTransformer *SignalTransformer::getTransformer()
|
|||
return instance;
|
||||
}
|
||||
|
||||
void SignalTransformer::handleItemInsert(const AppInfoResult &item)
|
||||
void SignalTransformer::handleItemInsert(const QString &desktopFilePath)
|
||||
{
|
||||
QMutexLocker locker(&s_mutex);
|
||||
m_items2BInsert.append(item);
|
||||
m_items2BInsert.append(desktopFilePath);
|
||||
}
|
||||
|
||||
void SignalTransformer::handleItemUpdate(const AppInfoResult &item)
|
||||
void SignalTransformer::handleItemUpdate(const ApplicationInfoMap &item)
|
||||
{
|
||||
QMutexLocker locker(&s_mutex);
|
||||
m_items2BUpdate.append(item);
|
||||
for(auto it = item.constBegin(); it != item.constEnd(); it++) {
|
||||
PropertyMap propertyinfo = it.value();
|
||||
for (auto i = propertyinfo.constBegin(); i != propertyinfo.constEnd(); i++) {
|
||||
m_items2BUpdate[it.key()].insert(i.key(), i.value());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void SignalTransformer::handleItemDelete(const QString &desktopfp)
|
||||
void SignalTransformer::handleItemUpdateAll(const QString &desktopFilePath)
|
||||
{
|
||||
QMutexLocker locker(&s_mutex);
|
||||
m_items2BDelete.append(desktopfp);
|
||||
m_items2BUpdateAll.append(desktopFilePath);
|
||||
}
|
||||
|
||||
void SignalTransformer::handleItemDelete(const QString &desktopFilePath)
|
||||
{
|
||||
QMutexLocker locker(&s_mutex);
|
||||
m_items2BDelete.append(desktopFilePath);
|
||||
}
|
||||
|
||||
void SignalTransformer::handleSignalTransform()
|
||||
|
@ -39,6 +50,11 @@ void SignalTransformer::handleSignalTransform()
|
|||
m_items2BUpdate.clear();
|
||||
}
|
||||
|
||||
if (!m_items2BUpdateAll.isEmpty()) {
|
||||
Q_EMIT this->appDBItemsUpdateAll(m_items2BUpdateAll);
|
||||
m_items2BUpdateAll.clear();
|
||||
}
|
||||
|
||||
if (!m_items2BDelete.isEmpty()) {
|
||||
Q_EMIT this->appDBItemsDelete(m_items2BDelete);
|
||||
m_items2BDelete.clear();
|
||||
|
@ -50,6 +66,7 @@ SignalTransformer::SignalTransformer(QObject *parent) : QObject(parent)
|
|||
connect(AppDBManager::getInstance(), &AppDBManager::appDBItemAdd, this, &SignalTransformer::handleItemInsert);
|
||||
connect(AppDBManager::getInstance(), &AppDBManager::appDBItemUpdate, this, &SignalTransformer::handleItemUpdate);
|
||||
connect(AppDBManager::getInstance(), &AppDBManager::appDBItemDelete, this, &SignalTransformer::handleItemDelete);
|
||||
connect(AppDBManager::getInstance(), &AppDBManager::appDBItemUpdateAll, this, &SignalTransformer::handleItemUpdateAll);
|
||||
connect(AppDBManager::getInstance(), &AppDBManager::finishHandleAppDB, this, &SignalTransformer::handleSignalTransform);
|
||||
}
|
||||
|
||||
|
|
|
@ -20,9 +20,10 @@ public:
|
|||
static QMutex s_mutex;
|
||||
|
||||
public Q_SLOTS:
|
||||
void handleItemInsert(const AppInfoResult &item);
|
||||
void handleItemUpdate(const AppInfoResult &item);
|
||||
void handleItemDelete(const QString &desktopfp);
|
||||
void handleItemUpdate(const ApplicationInfoMap &item);
|
||||
void handleItemUpdateAll(const QString &desktopFilePath);
|
||||
void handleItemInsert(const QString &desktopFilePath);
|
||||
void handleItemDelete(const QString &desktopFilePath);
|
||||
void handleSignalTransform();
|
||||
|
||||
private:
|
||||
|
@ -30,14 +31,16 @@ private:
|
|||
SignalTransformer(const SignalTransformer &) = delete;
|
||||
SignalTransformer& operator = (const SignalTransformer&) = delete;
|
||||
|
||||
QVector<AppInfoResult> m_items2BUpdate;
|
||||
QVector<AppInfoResult> m_items2BInsert;
|
||||
ApplicationInfoMap m_items2BUpdate;
|
||||
QStringList m_items2BUpdateAll;
|
||||
QStringList m_items2BInsert;
|
||||
QStringList m_items2BDelete;
|
||||
|
||||
Q_SIGNALS:
|
||||
void appDBItemsUpdate(QVector<AppInfoResult>);
|
||||
void appDBItemsAdd(QVector<AppInfoResult>);
|
||||
void appDBItemsDelete(QStringList);
|
||||
void appDBItemsUpdateAll(const QStringList&);
|
||||
void appDBItemsUpdate(const ApplicationInfoMap&);
|
||||
void appDBItemsAdd(const QStringList&);
|
||||
void appDBItemsDelete(const QStringList&);
|
||||
};
|
||||
|
||||
#endif // SIGNALTRANSFORMER_H
|
||||
|
|
|
@ -20,11 +20,11 @@ UkuiSearchAppDataService::UkuiSearchAppDataService(int &argc, char *argv[], cons
|
|||
if (!this->isRunning()) {
|
||||
qDebug() << "First running, I'm in app-db manager dbus rigister.";
|
||||
|
||||
qRegisterMetaType<AppInfoResult>("AppInfoResult");
|
||||
qRegisterMetaType<QVector<AppInfoResult>>("QVector<AppInfoResult>");
|
||||
qRegisterMetaType<PropertyMap>("PropertyMap");
|
||||
qDBusRegisterMetaType<PropertyMap>();
|
||||
|
||||
qDBusRegisterMetaType<AppInfoResult>();
|
||||
qDBusRegisterMetaType<QVector<AppInfoResult>>();
|
||||
qRegisterMetaType<ApplicationInfoMap>("ApplicationInfoMap");
|
||||
qDBusRegisterMetaType<ApplicationInfoMap>();
|
||||
|
||||
AppDBManager::getInstance();
|
||||
|
||||
|
|
|
@ -59,5 +59,6 @@ DEPENDPATH += $$PWD/../libchinese-segmentation
|
|||
|
||||
LIBS += -L$$OUT_PWD/../libsearch/ -lukui-search
|
||||
INCLUDEPATH += $$PWD/../libsearch \
|
||||
$$PWD/../libsearch/filesystemwatcher
|
||||
$$PWD/../libsearch/filesystemwatcher \
|
||||
$$PWD/../libsearch/appdata
|
||||
DEPENDPATH += $$PWD/../libsearch
|
||||
|
|
Loading…
Reference in New Issue