From b1a8486bd130eab4024cc2824ce9a9aeff5116d3 Mon Sep 17 00:00:00 2001 From: iaom Date: Tue, 7 Mar 2023 17:33:08 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E5=BA=94=E7=94=A8=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E6=9C=8D=E5=8A=A1=E7=9A=84=E6=8E=A5=E5=8F=A3=E5=AE=9A?= =?UTF-8?q?=E4=B9=89=EF=BC=88=E6=9C=AA=E5=AE=8C=E6=88=90=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- libsearch/appdata/app-info-table-private.h | 3 +- libsearch/appdata/app-info-table.cpp | 162 +++++++---------- libsearch/appdata/app-info-table.h | 12 +- libsearch/appdata/appdata.pri | 11 +- .../appdata/application-info-storage.cpp | 69 ++++++++ libsearch/appdata/application-info-storage.h | 41 +++++ libsearch/appdata/application-info.cpp | 42 +++++ libsearch/appdata/application-info.h | 44 +++++ .../appdata/application-property-helper.cpp | 163 ++++++++++++++++++ .../appdata/application-property-helper.h | 30 ++++ libsearch/appdata/application-property.h | 43 +++++ libsearch/appsearch/app-match.h | 2 - .../header-files/UkuiSearchAppInfoTable | 1 - .../header-files/UkuiSearchController | 1 - .../header-files/UkuiSearchPluginIface | 2 + libsearch/libsearch.pro | 12 +- .../search-controller-private.h | 6 +- .../searchinterface/search-controller.cpp | 12 +- libsearch/searchinterface/search-controller.h | 6 +- .../searchtasks/app-search-task.cpp | 4 +- .../searchtasks/app-search-task.h | 1 - .../ukui-search-task-private.h | 6 +- .../searchinterface/ukui-search-task.cpp | 12 +- libsearch/searchinterface/ukui-search-task.h | 6 +- ukui-search-app-data-service/app-db-manager.h | 10 +- 25 files changed, 547 insertions(+), 154 deletions(-) create mode 100644 libsearch/appdata/application-info-storage.cpp create mode 100644 libsearch/appdata/application-info-storage.h create mode 100644 libsearch/appdata/application-info.cpp create mode 100644 libsearch/appdata/application-info.h create mode 100644 libsearch/appdata/application-property-helper.cpp create mode 100644 libsearch/appdata/application-property-helper.h create mode 100644 libsearch/appdata/application-property.h delete mode 100644 libsearch/development-files/header-files/UkuiSearchAppInfoTable delete mode 100644 libsearch/development-files/header-files/UkuiSearchController diff --git a/libsearch/appdata/app-info-table-private.h b/libsearch/appdata/app-info-table-private.h index 788a39e..b370f94 100644 --- a/libsearch/appdata/app-info-table-private.h +++ b/libsearch/appdata/app-info-table-private.h @@ -11,6 +11,7 @@ namespace UkuiSearch { class AppInfoTablePrivate : public QObject { Q_OBJECT + friend class AppInfoTable; public: explicit AppInfoTablePrivate(AppInfoTable *parent = nullptr); AppInfoTablePrivate(AppInfoTablePrivate &) = delete; @@ -42,8 +43,6 @@ public: bool searchInstallApp(QString &keyWord, QStringList &installAppInfoRes); bool searchInstallApp(QStringList &keyWord, QStringList &installAppInfoRes); - //卸载应用 - bool uninstallApp(QString &desktopfp); //数据库错误信息 QString lastError(void) const; diff --git a/libsearch/appdata/app-info-table.cpp b/libsearch/appdata/app-info-table.cpp index 2a39646..6e4f261 100644 --- a/libsearch/appdata/app-info-table.cpp +++ b/libsearch/appdata/app-info-table.cpp @@ -14,10 +14,13 @@ #include #include #include -#include -#include +#include +#include +#include using namespace UkuiSearch; +static std::once_flag flag; +static AppInfoTable *global_intance = nullptr; AppInfoTablePrivate::AppInfoTablePrivate(AppInfoTable *parent) : QObject(parent), q(parent), m_database(new QSqlDatabase()) { @@ -178,49 +181,6 @@ bool AppInfoTablePrivate::getAppCategory(QString &desktopfp, QString &category) } } -bool AppInfoTablePrivate::addAppShortcut2Desktop(QString &desktopfp) -{ - bool res(true); - QString dirpath = QStandardPaths::writableLocation(QStandardPaths::DesktopLocation); - QFileInfo fileInfo(desktopfp); - QString desktopfn = fileInfo.fileName(); - QFile file(desktopfp); - QString newName = QString(dirpath + "/" + desktopfn); - if(file.copy(QString(dirpath + "/" + desktopfn))) { - QProcess process; - process.startDetached(QString("chmod a+x %1").arg(newName)); - } else { - res = false; - } - return res; -} - -bool AppInfoTablePrivate::addAppShortcut2Panel(QString &desktopfp) -{ - bool res(true); - QDBusInterface iface("com.ukui.panel.desktop", - "/", - "com.ukui.panel.desktop", - QDBusConnection::sessionBus()); - if(iface.isValid()) { - QDBusReply isExist = iface.call("CheckIfExist", desktopfp); - if(isExist) { - qWarning() << "Add shortcut to panel failed, because it is already existed!"; - } else { - QDBusReply ret = iface.call("AddToTaskbar", desktopfp); - if (ret.value()) { - qDebug() << "Add shortcut to panel success."; - } else { - qWarning() << "Add shortcut to panel failed, reply:" << ret.error(); - res = false; - } - } - } else { - res = false; - } - return res; -} - bool AppInfoTablePrivate::searchInstallApp(QString &keyWord, QStringList &installAppInfoRes) { bool res(true); @@ -300,48 +260,6 @@ bool AppInfoTablePrivate::searchInstallApp(QStringList &keyWord, QStringList &in return res; } -bool AppInfoTablePrivate::uninstallApp(QString &desktopfp) -{ - bool res(false); - QString cmd = QString("kylin-uninstaller %1") - .arg(desktopfp.toLocal8Bit().data()); - res = QProcess::startDetached(cmd); - qDebug() << "kylin-uninstaller uninstall:" << cmd << res; - return res; - - /* - bool isOsReleaseUbuntu(false); - QFile file("/etc/os-release"); - if (file.open(QFile::ReadOnly)) { - QByteArray line = file.readLine(); - file.close(); - - if (QString(line).contains("Ubuntu")) { //目前已无效 - isOsReleaseUbuntu = true; - } - } - QString cmd; - QProcess process; - if (!isOsReleaseUbuntu) { - cmd = QString("kylin-uninstaller %1") - .arg(desktopfp.toLocal8Bit().data()); - res = QProcess::startDetached(cmd); - qDebug() << "kylin-uninstaller uninstall:" << cmd << res; - } else { - cmd = QString("dpkg -S " + desktopfp); - process.start("sh", QStringList() << "-c" << cmd); - process.waitForFinished(); - QString output = process.readAllStandardOutput().trimmed(); - QString packageName = output.split(":").at(0); - cmd = QString("kylin-installer -remove %0") - .arg(packageName.toLocal8Bit().data()); - res = QProcess::startDetached(cmd); - qDebug() << "dpkg -S uninstall:" << cmd << res; - } - return res; - */ -} - QString AppInfoTablePrivate::lastError() const { return m_database->lastError().text(); @@ -591,10 +509,65 @@ void AppInfoTablePrivate::sendAppDBItemsDelete(QStringList desktopfps) Q_EMIT q->appDBItems2BDelete(desktopfps); } +AppInfoTable *AppInfoTable::self() +{ + std::call_once(flag, [ & ] { + global_intance = new AppInfoTable(); + }); + return global_intance; +} + AppInfoTable::AppInfoTable(QObject *parent) : QObject(parent), d(new AppInfoTablePrivate(this)) { } +bool AppInfoTable::query(PropertyMap &propertyMap, const QString &desktopFile, Properties properties) +{ + QString field; + for(const ApplicationProperty::Property &pro : properties) { + field.append(ApplicationPropertyHelper(pro).dataBaseField() + ","); + } + field.remove(field.length() - 1, 1); + QSqlQuery query(*d->m_database); + query.setForwardOnly(true); + query.prepare(QString("SELECT %0 FROM APPINFO WHERE DESKTOP_FILE_PATH=:desktopFile").arg(field)); + query.bindValue(":desktopFile", desktopFile); + if (!query.exec()) { + qWarning() << d->m_database->lastError() << query.lastError(); + return false; + } + while (query.next()) { + for(int i = 0; i< properties.size(); i++) { + propertyMap.insert(properties.at(i), query.value(i)); + } + } + return true; +} + +bool AppInfoTable::query(ApplicationInfoMap &infoMap, Properties properties) +{ + QString field(ApplicationPropertyHelper(ApplicationProperty::Property::DesktopFilePath).dataBaseField()); + for(const ApplicationProperty::Property &pro : properties) { + field.append("," + ApplicationPropertyHelper(pro).dataBaseField()); + } + QString sql = QString("SELECT %0 FROM APPINFO").arg(field); + QSqlQuery query(*d->m_database); + query.setForwardOnly(true); + + if (!query.exec(sql)) { + qWarning() << d->m_database->lastError() << sql; + return false; + } + while (query.next()) { + PropertyMap propertyMap; + for(int i = 1; i< properties.size(); i++) { + propertyMap.insert(properties.at(i), query.value(i)); + } + infoMap.insert(query.value(0).toString(), propertyMap); + } + return true; +} + void AppInfoTable::setAppFavoritesState(QString &desktopfp, size_t num) { return d->setAppFavoritesState(desktopfp, num); @@ -645,16 +618,6 @@ bool AppInfoTable::getAppFavoriteState(QString &desktopfp, size_t &num) return d->getAppFavoriteState(desktopfp, num); } -bool AppInfoTable::addAppShortcut2Desktop(QString &desktopfp) -{ - return d->addAppShortcut2Desktop(desktopfp); -} - -bool AppInfoTable::addAppShortcut2Panel(QString &desktopfp) -{ - return d->addAppShortcut2Panel(desktopfp); -} - bool AppInfoTable::searchInstallApp(QString &keyWord, QStringList &installAppInfoRes) { return d->searchInstallApp(keyWord, installAppInfoRes); @@ -665,11 +628,6 @@ bool AppInfoTable::searchInstallApp(QStringList &keyWord, QStringList &installAp return d->searchInstallApp(keyWord, installAppInfoRes); } -bool AppInfoTable::uninstallApp(QString &desktopfp) -{ - return d->uninstallApp(desktopfp); -} - QString AppInfoTable::lastError() const { return d->lastError(); diff --git a/libsearch/appdata/app-info-table.h b/libsearch/appdata/app-info-table.h index 91cc4d2..07b4e3b 100644 --- a/libsearch/appdata/app-info-table.h +++ b/libsearch/appdata/app-info-table.h @@ -2,7 +2,9 @@ #define APPINFOTABLE_H #include +#include #include "app-db-common.h" +#include "application-property.h" namespace UkuiSearch { @@ -11,9 +13,12 @@ class AppInfoTable : public QObject { Q_OBJECT public: - explicit AppInfoTable(QObject *parent = nullptr); + 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); /** * @brief AppInfoTable::setAppFavoritesState @@ -62,13 +67,9 @@ public: bool getAppFavoriteState(QString &desktopfp, size_t &num); bool getAppCategory(QString &desktopfp, QString &category); - bool addAppShortcut2Desktop(QString &desktopfp); - bool addAppShortcut2Panel(QString &desktopfp); - bool searchInstallApp(QString &keyWord, QStringList &installAppInfoRes); bool searchInstallApp(QStringList &keyWord, QStringList &installAppInfoRes); - bool uninstallApp(QString &desktopfp); /** * @brief AppInfoTable::lastError @@ -97,6 +98,7 @@ private: bool getLaunchTimesAppList(QStringList &list); private: + explicit AppInfoTable(QObject *parent = nullptr); AppInfoTablePrivate *d; Q_SIGNALS: diff --git a/libsearch/appdata/appdata.pri b/libsearch/appdata/appdata.pri index c265c1e..24aa27a 100644 --- a/libsearch/appdata/appdata.pri +++ b/libsearch/appdata/appdata.pri @@ -2,8 +2,15 @@ INCLUDEPATH += $$PWD HEADERS += \ $$PWD/app-info-table-private.h \ - $$PWD/app-info-table.h + $$PWD/app-info-table.h \ +# $$PWD/application-info-storage.h \ + $$PWD/application-info.h \ + $$PWD/application-property-helper.h \ + $$PWD/application-property.h SOURCES += \ - $$PWD/app-info-table.cpp + $$PWD/app-info-table.cpp \ +# $$PWD/application-info-storage.cpp \ + $$PWD/application-info.cpp \ + $$PWD/application-property-helper.cpp diff --git a/libsearch/appdata/application-info-storage.cpp b/libsearch/appdata/application-info-storage.cpp new file mode 100644 index 0000000..534b0c2 --- /dev/null +++ b/libsearch/appdata/application-info-storage.cpp @@ -0,0 +1,69 @@ +#include "application-info-storage.h" +#include +using namespace UkuiSearch; +namespace UkuiSearch { +class ApplicationInfoStoragePrivate +{ + friend class ApplicationInfoStorage; +private: + Properties m_properties; + ApplicationInfoMap m_data; +}; +} +ApplicationInfoStorage::ApplicationInfoStorage(): d(new ApplicationInfoStoragePrivate) +{ +} + +ApplicationInfoStorage::ApplicationInfoStorage(Properties properties): d(new ApplicationInfoStoragePrivate) +{ + d->m_properties = properties; +} + +ApplicationInfoStorage::ApplicationInfoStorage(const ApplicationInfoStorage &other): d(new ApplicationInfoStoragePrivate(*other.d)) +{ +} + +ApplicationInfoStorage::~ApplicationInfoStorage() +{ + if(d) { + delete d; + d = nullptr; + } +} + +ApplicationInfoStorage &ApplicationInfoStorage::operator=(const ApplicationInfoStorage &rhs) +{ + *d = *rhs.d; + return *this; +} + +QStringList ApplicationInfoStorage::applicationKeys() const +{ + return d->m_data.keys(); +} + +Properties &ApplicationInfoStorage::applicationInfoKeys() const +{ + return d->m_properties; +} + +QVariant ApplicationInfoStorage::ApplicationInfo(const QString &desktopFile, ApplicationProperty::Property property) +{ + return d->m_data.value(desktopFile).value(property); +} + +ApplicationInfoMap &ApplicationInfoStorage::allData() +{ + return d->m_data; +} + +void ApplicationInfoStorage::addData(const QString &desktopFile, ApplicationProperty::Property property, const QVariant &value) +{ + if(d->m_data.contains(desktopFile)) { + QMap info = d->m_data.value(desktopFile); + info.insert(property, value); + d->m_data.insert(desktopFile, info); + } else { + d->m_data.insert(desktopFile, QMap{{property, value}}); + } +} diff --git a/libsearch/appdata/application-info-storage.h b/libsearch/appdata/application-info-storage.h new file mode 100644 index 0000000..bf6a56c --- /dev/null +++ b/libsearch/appdata/application-info-storage.h @@ -0,0 +1,41 @@ +#ifndef APPLICATIONINFOSTORAGE_H +#define APPLICATIONINFOSTORAGE_H + +#include +#include "application-property.h" +namespace UkuiSearch { +class ApplicationInfoStoragePrivate; +class ApplicationInfoStorage +{ +public: + ApplicationInfoStorage(); + ApplicationInfoStorage(Properties properties); + ApplicationInfoStorage(const ApplicationInfoStorage &other); + ~ApplicationInfoStorage(); + + ApplicationInfoStorage & operator=(const ApplicationInfoStorage &rhs); + /** + * @brief 查询当前容器内包含的应用列表 + * @return 所有desktop路径的QStringlist + */ + QStringList applicationKeys() const; + /** + * @brief 查询当前容器包含的信息种类 + * @return QVector + */ + Properties &applicationInfoKeys() const; + /** + * @brief 查询某个应用的某个信息 + * @param desktopFile + * @param info + * @return 以info的数据类型格式返回特定信息 + */ + QVariant ApplicationInfo(const QString &desktopFile, ApplicationProperty::Property property); + ApplicationInfoMap &allData(); + void addData(const QString &desktopFile, ApplicationProperty::Property property, const QVariant &value); + +private: + ApplicationInfoStoragePrivate *d = nullptr; +}; +} +#endif // APPLICATIONINFOSTORAGE_H diff --git a/libsearch/appdata/application-info.cpp b/libsearch/appdata/application-info.cpp new file mode 100644 index 0000000..f48d4dd --- /dev/null +++ b/libsearch/appdata/application-info.cpp @@ -0,0 +1,42 @@ +#include "application-info.h" +#include "app-info-table.h" +#include "application-property-helper.h" +using namespace UkuiSearch; +namespace UkuiSearch { +class ApplicationInfoPrivate +{ +}; +} +ApplicationInfo::ApplicationInfo(QObject *parent) + : QObject(parent), d(new ApplicationInfoPrivate) +{ +} + +ApplicationInfo::~ApplicationInfo() +{ + if(d) { + delete d; + d = nullptr; + } +} + +QVariant UkuiSearch::ApplicationInfo::getInfo(const QString &desktopFile, ApplicationProperty::Property property) +{ + PropertyMap map; + AppInfoTable::self()->query(map, desktopFile, Properties{property}); + return map.value(property);; +} + +PropertyMap ApplicationInfo::getInfo(const QString &desktopFile, Properties properties) +{ + PropertyMap propertyMap; + AppInfoTable::self()->query(propertyMap, desktopFile, properties); + return propertyMap; +} + +ApplicationInfoMap ApplicationInfo::getInfo(Properties properties) +{ + ApplicationInfoMap infoMap; + AppInfoTable::self()->query(infoMap, properties); + return infoMap; +} diff --git a/libsearch/appdata/application-info.h b/libsearch/appdata/application-info.h new file mode 100644 index 0000000..315f1e5 --- /dev/null +++ b/libsearch/appdata/application-info.h @@ -0,0 +1,44 @@ +#ifndef APPLICATIONINFO_H +#define APPLICATIONINFO_H + +#include + +#include "application-property.h" +namespace UkuiSearch { +class ApplicationInfoPrivate; +class ApplicationInfo : public QObject +{ + Q_OBJECT +public: + explicit ApplicationInfo(QObject *parent = nullptr); + ~ApplicationInfo(); + /** + * @brief getInfo 查询单个应用的单个属性 + * @param desktopFile + * @param property + * @return + */ + QVariant getInfo(const QString &desktopFile, ApplicationProperty::Property property); + /** + * @brief getInfo 查询单个应用的多个属性 + * @param desktopFile + * @param properties + * @return + */ + PropertyMap getInfo(const QString &desktopFile, Properties properties); + /** + * @brief getInfo 查询所有应用的多个属性 + * @param property + * @return + */ + ApplicationInfoMap getInfo(Properties properties); + + //TODO 搜索接口,设置收藏和置顶接口,应用更新卸载信号 + +private: + ApplicationInfoPrivate *d = nullptr; + +}; + +} +#endif // APPLICATIONINFO_H diff --git a/libsearch/appdata/application-property-helper.cpp b/libsearch/appdata/application-property-helper.cpp new file mode 100644 index 0000000..6d36b65 --- /dev/null +++ b/libsearch/appdata/application-property-helper.cpp @@ -0,0 +1,163 @@ +#include "application-property-helper.h" +#include +using namespace UkuiSearch; +namespace UkuiSearch { + +class ApplicationPropertyHelperPrivate +{ + friend class ApplicationPropertyHelper; +private: + ApplicationProperty::Property m_property; + QString m_databaseField; + QMetaType::Type m_valueType; +}; +} +ApplicationPropertyHelper::ApplicationPropertyHelper(): d(new ApplicationPropertyHelperPrivate) +{ + d->m_property = ApplicationProperty::Invalid; + d->m_valueType = QMetaType::UnknownType; +} + +ApplicationPropertyHelper::ApplicationPropertyHelper(ApplicationProperty::Property property): d(new ApplicationPropertyHelperPrivate) +{ + d->m_property = property; + switch (property) { + case ApplicationProperty::DesktopFilePath: + d->m_databaseField = "DESKTOP_FILE_PATH"; + d->m_valueType = QMetaType::QString; + break; + case ApplicationProperty::ModifiedTime: + d->m_databaseField = "MODIFYED_TIME"; + d->m_valueType = QMetaType::QDateTime; + break; + case ApplicationProperty::InsertTime: + d->m_databaseField = "INSERT_TIME"; + d->m_valueType = QMetaType::QDateTime; + break; + case ApplicationProperty::LocalName: + d->m_databaseField = "LOCAL_NAME"; + d->m_valueType = QMetaType::QString; + break; + case ApplicationProperty::NameEn: + d->m_databaseField = "NAME_EN"; + d->m_valueType = QMetaType::QString; + break; + case ApplicationProperty::NameZh: + d->m_databaseField = "NAME_EN"; + d->m_valueType = QMetaType::QString; + break; + case ApplicationProperty::PinyinName: + d->m_databaseField = "PINYIN_NAME"; + d->m_valueType = QMetaType::QString; + break; + case ApplicationProperty::FirstLetterOfPinyin: + d->m_databaseField = "FIRST_LETTER_OF_PINYIN"; + d->m_valueType = QMetaType::QString; + break; + case ApplicationProperty::FirstLetterAll: + d->m_databaseField = "FIRST_LETTER_ALL"; + d->m_valueType = QMetaType::QString; + break; + case ApplicationProperty::Icon: + d->m_databaseField = "ICON"; + d->m_valueType = QMetaType::QString; + break; + case ApplicationProperty::Type: + d->m_databaseField = "TYPE"; + d->m_valueType = QMetaType::QString; + break; + case ApplicationProperty::Category: + d->m_databaseField = "CATEGORY"; + d->m_valueType = QMetaType::QString; + break; + case ApplicationProperty::Exec: + d->m_databaseField = "EXEC"; + d->m_valueType = QMetaType::QString; + break; + case ApplicationProperty::Comment: + d->m_databaseField = "CATEGORY"; + d->m_valueType = QMetaType::QString; + break; + case ApplicationProperty::Md5: + d->m_databaseField = "MD5"; + d->m_valueType = QMetaType::QString; + break; + case ApplicationProperty::LaunchTimes: + d->m_databaseField = "LAUNCH_TIMES"; + d->m_valueType = QMetaType::Int; + break; + case ApplicationProperty::Favorites: + d->m_databaseField = "FAVORITES"; + d->m_valueType = QMetaType::Int; + break; + case ApplicationProperty::Launched: + d->m_databaseField = "LAUNCHED"; + d->m_valueType = QMetaType::Int; + break; + case ApplicationProperty::Top: + d->m_databaseField = "TOP"; + d->m_valueType = QMetaType::Int; + break; + case ApplicationProperty::Lock: + d->m_databaseField = "LOCK"; + d->m_valueType = QMetaType::Int; + break; + case ApplicationProperty::DontDisplay: + d->m_databaseField = "DONT_DISPLAY"; + d->m_valueType = QMetaType::Int; + } +} + +ApplicationPropertyHelper::ApplicationPropertyHelper(const ApplicationPropertyHelper &other): d(new ApplicationPropertyHelperPrivate(*other.d)) +{ + +} + +ApplicationPropertyHelper::~ApplicationPropertyHelper() +{ + if(d) { + delete d; + d = nullptr; + } +} + +ApplicationPropertyHelper &ApplicationPropertyHelper::operator =(const ApplicationPropertyHelper &rhs) +{ + *d = *rhs.d; + return *this; +} + +bool ApplicationPropertyHelper::operator ==(const ApplicationPropertyHelper &rhs) const +{ + return d->m_databaseField == rhs.d->m_databaseField && d->m_valueType == rhs.d->m_valueType; +} + +ApplicationProperty::Property ApplicationPropertyHelper::info() +{ + return d->m_property; +} + +QString ApplicationPropertyHelper::dataBaseField() +{ + return d->m_databaseField; +} + +QMetaType::Type ApplicationPropertyHelper::valueType() +{ + return d->m_valueType; +} + +QString ApplicationPropertyHelper::toDataBaseString(QVariant &value) +{ + switch (d->m_valueType) { + case QMetaType::Type::UnknownType: + return QString(); + case QMetaType::Type::QString: + return value.toString().replace("'", "''"); + case QMetaType::Type::QDateTime: + return value.toDateTime().toString("yyyy-MM-dd hh:mm:ss"); + default: + return {}; + break; + } +} diff --git a/libsearch/appdata/application-property-helper.h b/libsearch/appdata/application-property-helper.h new file mode 100644 index 0000000..e630eec --- /dev/null +++ b/libsearch/appdata/application-property-helper.h @@ -0,0 +1,30 @@ +#ifndef APPLICATIONINFOHELPER_H +#define APPLICATIONINFOHELPER_H + +#include "application-property.h" +#include +#include +namespace UkuiSearch { + +class ApplicationPropertyHelperPrivate; +class ApplicationPropertyHelper +{ +public: + ApplicationPropertyHelper(); + ApplicationPropertyHelper(ApplicationProperty::Property property); + ApplicationPropertyHelper(const ApplicationPropertyHelper &other); + ~ApplicationPropertyHelper(); + + ApplicationPropertyHelper& operator=(const ApplicationPropertyHelper &rhs); + bool operator==(const ApplicationPropertyHelper &rhs) const; + + ApplicationProperty::Property info(); + QString dataBaseField(); + QMetaType::Type valueType(); + QString toDataBaseString(QVariant &value); + +private: + ApplicationPropertyHelperPrivate *d = nullptr; +}; +} +#endif // APPLICATIONINFOHELPER_H diff --git a/libsearch/appdata/application-property.h b/libsearch/appdata/application-property.h new file mode 100644 index 0000000..f61a3a0 --- /dev/null +++ b/libsearch/appdata/application-property.h @@ -0,0 +1,43 @@ +#ifndef APPLICATIONPROPERTY_H +#define APPLICATIONPROPERTY_H + +#include +#include +#include +namespace UkuiSearch { +namespace ApplicationProperty { +/** + * @brief 表示应用基础信息 + */ +enum Property { + Invalid = 0, + DesktopFilePath, //desktop文件路径 + ModifiedTime, //数据修改时间 + InsertTime, //数据插入时间 + LocalName, //应用名(本地化) + NameEn, //应用英文名 + NameZh, //应用中文名 + PinyinName, //名称拼音 + FirstLetterOfPinyin, //拼音首字母 + FirstLetterAll, //名称首字母 + Icon, //应用图标 + Type, //种类(Application等) + Category, //分类(AudioVideo等) + Exec, //执行命令 + Comment, //简介 + Md5, //desktop文件的md5 + LaunchTimes, //启动次数 + Favorites, //收藏顺序(0 未收藏) + Launched, //是否从开始菜单启动过 + Top, //置顶顺序(0 未置顶) + Lock, //是否锁定(不允许显示或打开) + DontDisplay //是否不需要显示(设置了Nodisplay等字段) +}; +} //namespace ApplicationProperty +typedef QVector Properties; +typedef QMap PropertyMap; +typedef QMap ApplicationInfoMap; // desktopFile->PropertyMap +} +Q_DECLARE_METATYPE(UkuiSearch::ApplicationProperty::Property) + +#endif // APPLICATIONPROPERTY_H diff --git a/libsearch/appsearch/app-match.h b/libsearch/appsearch/app-match.h index 08cfbf7..aee056d 100644 --- a/libsearch/appsearch/app-match.h +++ b/libsearch/appsearch/app-match.h @@ -48,8 +48,6 @@ private: void appNameMatch(QString keyWord, size_t uniqueSymbol, DataQueue *searchResult); void parseSoftWareCenterReturn(QList> list, size_t uniqueSymbol, DataQueue *searchResult); //void creatResultInfo(SearchPluginIface::ResultInfo &ri, QMapIterator &iter, bool isInstalled = true); - - AppInfoTable *m_appInfoTable = nullptr; QString m_sourceText; size_t m_uniqueSymbol; DataQueue *m_search_result = nullptr; diff --git a/libsearch/development-files/header-files/UkuiSearchAppInfoTable b/libsearch/development-files/header-files/UkuiSearchAppInfoTable deleted file mode 100644 index 046c057..0000000 --- a/libsearch/development-files/header-files/UkuiSearchAppInfoTable +++ /dev/null @@ -1 +0,0 @@ -#include "app-info-table.h" diff --git a/libsearch/development-files/header-files/UkuiSearchController b/libsearch/development-files/header-files/UkuiSearchController deleted file mode 100644 index 6d87eca..0000000 --- a/libsearch/development-files/header-files/UkuiSearchController +++ /dev/null @@ -1 +0,0 @@ -#include "search-controller.h" diff --git a/libsearch/development-files/header-files/UkuiSearchPluginIface b/libsearch/development-files/header-files/UkuiSearchPluginIface index 94d4d98..2c75b88 100644 --- a/libsearch/development-files/header-files/UkuiSearchPluginIface +++ b/libsearch/development-files/header-files/UkuiSearchPluginIface @@ -1,6 +1,8 @@ #include "action-label.h" +#include "action-transmiter.h" #include "common-defines.h" #include "plugin-iface.h" #include "data-queue.h" #include "search-plugin-iface.h" #include "search-task-plugin-iface.h" +#include "separation-line.h" diff --git a/libsearch/libsearch.pro b/libsearch/libsearch.pro index 4ffdf0e..21396de 100644 --- a/libsearch/libsearch.pro +++ b/libsearch/libsearch.pro @@ -105,12 +105,14 @@ unix { INSTALLS += target header.path = /usr/include/ukui-search - header.files += *.h index/*.h appsearch/*.h settingsearch/*.h plugininterface/*.h websearch/*.h search-app-widget-plugin/*.h \ + header.files += libsearch_global.h \ + plugininterface/*.h \ + appdata/application-info.h \ + appdata/application-property.h \ + appdata/application-property-helper.h \ searchinterface/ukui-search-task.h \ - appdata/app-info-table.h \ - searchinterface/search-controller.h \ - searchinterface/result-item.h \ - filesystemwatcher/file-system-watcher.h + searchinterface/result-item.h + header.files += development-files/header-files/* INSTALLS += header diff --git a/libsearch/searchinterface/search-controller-private.h b/libsearch/searchinterface/search-controller-private.h index a89344f..4af3c3a 100644 --- a/libsearch/searchinterface/search-controller-private.h +++ b/libsearch/searchinterface/search-controller-private.h @@ -15,11 +15,11 @@ public: DataQueue* refreshDataqueue(); DataQueue* initDataQueue(); - void addSearchDir(QString &path); + void addSearchDir(const QString &path); void setRecurse(bool recurse = true); - void addKeyword(QString &keyword); + void addKeyword(const QString &keyword); void setActiveKeywordSegmentation(bool active); - void addFileLabel(QString &label); + void addFileLabel(const QString &label); void setOnlySearchFile(bool onlySearchFile); void setOnlySearchDir(bool onlySearchDir); void setSearchOnlineApps(bool searchOnlineApps); diff --git a/libsearch/searchinterface/search-controller.cpp b/libsearch/searchinterface/search-controller.cpp index d91bedd..0203c9e 100644 --- a/libsearch/searchinterface/search-controller.cpp +++ b/libsearch/searchinterface/search-controller.cpp @@ -42,7 +42,7 @@ DataQueue *SearchControllerPrivate::initDataQueue() return m_sharedDataQueue.get(); } -void SearchControllerPrivate::addSearchDir(QString &path) +void SearchControllerPrivate::addSearchDir(const QString &path) { m_searchDirs.append(path); } @@ -52,7 +52,7 @@ void SearchControllerPrivate::setRecurse(bool recurse) m_recurse = recurse; } -void SearchControllerPrivate::addKeyword(QString &keyword) +void SearchControllerPrivate::addKeyword(const QString &keyword) { m_keywords.append(keyword); } @@ -62,7 +62,7 @@ void SearchControllerPrivate::setActiveKeywordSegmentation(bool active) m_activeKeywordSegmentation = active; } -void SearchControllerPrivate::addFileLabel(QString &label) +void SearchControllerPrivate::addFileLabel(const QString &label) { m_FileLabels.append(label); } @@ -266,7 +266,7 @@ DataQueue *SearchController::initDataQueue() return d->initDataQueue(); } -void SearchController::addSearchDir(QString &path) +void SearchController::addSearchDir(const QString &path) { return d->addSearchDir(path); } @@ -276,7 +276,7 @@ void SearchController::setRecurse(bool recurse) d->setRecurse(recurse); } -void SearchController::addKeyword(QString &keyword) +void SearchController::addKeyword(const QString &keyword) { d->addKeyword(keyword); } @@ -306,7 +306,7 @@ void SearchController::setActiveKeywordSegmentation(bool active) d->setActiveKeywordSegmentation(active); } -void SearchController::addFileLabel(QString &label) +void SearchController::addFileLabel(const QString &label) { d->addFileLabel(label); } diff --git a/libsearch/searchinterface/search-controller.h b/libsearch/searchinterface/search-controller.h index 53b219a..d928595 100644 --- a/libsearch/searchinterface/search-controller.h +++ b/libsearch/searchinterface/search-controller.h @@ -26,11 +26,11 @@ public: DataQueue* initDataQueue(); void stop(); - void addSearchDir(QString &path); + void addSearchDir(const QString &path); void setRecurse(bool recurse = true); - void addKeyword(QString &keyword); + void addKeyword(const QString &keyword); void setActiveKeywordSegmentation(bool active); - void addFileLabel(QString &label); + void addFileLabel(const QString &label); void setOnlySearchFile(bool onlySearchFile); void setOnlySearchDir(bool onlySearchDir); void setSearchOnlineApps(bool searchOnlineApps); diff --git a/libsearch/searchinterface/searchtasks/app-search-task.cpp b/libsearch/searchinterface/searchtasks/app-search-task.cpp index ccba138..0cde8d2 100644 --- a/libsearch/searchinterface/searchtasks/app-search-task.cpp +++ b/libsearch/searchinterface/searchtasks/app-search-task.cpp @@ -12,7 +12,7 @@ AppSearchTask::AppSearchTask(QObject *parent) this->setParent(parent); qRegisterMetaType("size_t"); m_pool = new QThreadPool(this); - m_appInfoTable = new AppInfoTable(this); + AppInfoTable::self(); m_pool->setMaxThreadCount(1); } @@ -69,7 +69,7 @@ void AppSearchWorker::run() QStringList results; QStringList keyWords = m_searchController->getKeyword(); ResultDataTypes dataType = m_searchController->getResultDataType(SearchType::Application); - m_AppSearchTask->m_appInfoTable->searchInstallApp(keyWords, results); + AppInfoTable::self()->searchInstallApp(keyWords, results); for (int i = 0; i < results.size() / 3; i++) { if (m_searchController->beginSearchIdCheck(m_currentSearchId)) { QVariantList info; diff --git a/libsearch/searchinterface/searchtasks/app-search-task.h b/libsearch/searchinterface/searchtasks/app-search-task.h index be00f2f..adb3263 100644 --- a/libsearch/searchinterface/searchtasks/app-search-task.h +++ b/libsearch/searchinterface/searchtasks/app-search-task.h @@ -32,7 +32,6 @@ public: Q_INVOKABLE void sendFinishSignal(size_t searchId); private: - AppInfoTable *m_appInfoTable = nullptr; QThreadPool *m_pool = nullptr; }; diff --git a/libsearch/searchinterface/ukui-search-task-private.h b/libsearch/searchinterface/ukui-search-task-private.h index e7d6fa7..a622446 100644 --- a/libsearch/searchinterface/ukui-search-task-private.h +++ b/libsearch/searchinterface/ukui-search-task-private.h @@ -19,10 +19,10 @@ public: explicit UkuiSearchTaskPrivate(UkuiSearchTask* parent); ~UkuiSearchTaskPrivate(); DataQueue* init(); - void addSearchDir(QString &path); + void addSearchDir(const QString &path); void setRecurse(bool recurse = true); - void addKeyword(QString &keyword); - void addFileLabel(QString &label); + void addKeyword(const QString &keyword); + void addFileLabel(const QString &label); void setOnlySearchFile(bool onlySearchFile); void setOnlySearchDir(bool onlySearchDir); void setSearchOnlineApps(bool searchOnlineApps); diff --git a/libsearch/searchinterface/ukui-search-task.cpp b/libsearch/searchinterface/ukui-search-task.cpp index 396d311..42357bf 100644 --- a/libsearch/searchinterface/ukui-search-task.cpp +++ b/libsearch/searchinterface/ukui-search-task.cpp @@ -22,7 +22,7 @@ DataQueue *UkuiSearchTaskPrivate::init() return m_searchCotroller->initDataQueue(); } -void UkuiSearchTaskPrivate::addSearchDir(QString &path) +void UkuiSearchTaskPrivate::addSearchDir(const QString &path) { m_searchCotroller->addSearchDir(path); } @@ -32,12 +32,12 @@ void UkuiSearchTaskPrivate::setRecurse(bool recurse) m_searchCotroller->setRecurse(recurse); } -void UkuiSearchTaskPrivate::addKeyword(QString &keyword) +void UkuiSearchTaskPrivate::addKeyword(const QString &keyword) { m_searchCotroller->addKeyword(keyword); } -void UkuiSearchTaskPrivate::addFileLabel(QString &label) +void UkuiSearchTaskPrivate::addFileLabel(const QString &label) { m_searchCotroller->addFileLabel(label); } @@ -140,7 +140,7 @@ DataQueue *UkuiSearchTask::init() return d->init(); } -void UkuiSearchTask::addSearchDir(QString &path) +void UkuiSearchTask::addSearchDir(const QString &path) { d->addSearchDir(path); } @@ -150,12 +150,12 @@ void UkuiSearchTask::setRecurse(bool recurse) d->setRecurse(recurse); } -void UkuiSearchTask::addKeyword(QString &keyword) +void UkuiSearchTask::addKeyword(const QString &keyword) { d->addKeyword(keyword); } -void UkuiSearchTask::addFileLabel(QString &label) +void UkuiSearchTask::addFileLabel(const QString &label) { d->addFileLabel(label); } diff --git a/libsearch/searchinterface/ukui-search-task.h b/libsearch/searchinterface/ukui-search-task.h index b2d71e8..73f8337 100644 --- a/libsearch/searchinterface/ukui-search-task.h +++ b/libsearch/searchinterface/ukui-search-task.h @@ -13,10 +13,10 @@ public: explicit UkuiSearchTask(QObject *parent = nullptr); ~UkuiSearchTask(); DataQueue* init(); - void addSearchDir(QString &path); + void addSearchDir(const QString &path); void setRecurse(bool recurse = true); - void addKeyword(QString &keyword); - void addFileLabel(QString &label); + void addKeyword(const QString &keyword); + void addFileLabel(const QString &label); void setOnlySearchFile(bool onlySearchFile); void setOnlySearchDir(bool onlySearchDir); void setSearchOnlineApps(bool searchOnlineApps); diff --git a/ukui-search-app-data-service/app-db-manager.h b/ukui-search-app-data-service/app-db-manager.h index c40f5e8..058ca70 100644 --- a/ukui-search-app-data-service/app-db-manager.h +++ b/ukui-search-app-data-service/app-db-manager.h @@ -1,10 +1,5 @@ #ifndef APPDBMANAGER_H #define APPDBMANAGER_H - -#include "app-db-common.h" -#include "pending-app-info-queue.h" -#include "file-system-watcher.h" - #include #include #include @@ -16,8 +11,9 @@ #include #include #include -//#include -//#include +#include "app-db-common.h" +#include "pending-app-info-queue.h" +#include "file-system-watcher.h" #define CONNECTION_NAME QLatin1String("ukss-appdb-connection") static const QString APP_DATABASE_VERSION = QStringLiteral("1.0");