更新应用数据服务的接口定义(未完成)
This commit is contained in:
parent
498147414d
commit
b1a8486bd1
|
@ -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;
|
||||
|
|
|
@ -14,10 +14,13 @@
|
|||
#include <QTime>
|
||||
#include <QSqlQuery>
|
||||
#include <QSqlError>
|
||||
#include <QApplication>
|
||||
#include <qt5xdg/XdgDesktopFile>
|
||||
#include <mutex>
|
||||
#include <QFile>
|
||||
#include <application-property-helper.h>
|
||||
|
||||
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<bool> isExist = iface.call("CheckIfExist", desktopfp);
|
||||
if(isExist) {
|
||||
qWarning() << "Add shortcut to panel failed, because it is already existed!";
|
||||
} else {
|
||||
QDBusReply<bool> 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();
|
||||
|
|
|
@ -2,7 +2,9 @@
|
|||
#define APPINFOTABLE_H
|
||||
|
||||
#include <QObject>
|
||||
#include <QSqlQuery>
|
||||
#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:
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -0,0 +1,69 @@
|
|||
#include "application-info-storage.h"
|
||||
#include <QMap>
|
||||
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<ApplicationProperty::Property, QVariant> info = d->m_data.value(desktopFile);
|
||||
info.insert(property, value);
|
||||
d->m_data.insert(desktopFile, info);
|
||||
} else {
|
||||
d->m_data.insert(desktopFile, QMap<ApplicationProperty::Property, QVariant>{{property, value}});
|
||||
}
|
||||
}
|
|
@ -0,0 +1,41 @@
|
|||
#ifndef APPLICATIONINFOSTORAGE_H
|
||||
#define APPLICATIONINFOSTORAGE_H
|
||||
|
||||
#include <QVariant>
|
||||
#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<ApplicationProperty::Property>
|
||||
*/
|
||||
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
|
|
@ -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;
|
||||
}
|
|
@ -0,0 +1,44 @@
|
|||
#ifndef APPLICATIONINFO_H
|
||||
#define APPLICATIONINFO_H
|
||||
|
||||
#include <QObject>
|
||||
|
||||
#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
|
|
@ -0,0 +1,163 @@
|
|||
#include "application-property-helper.h"
|
||||
#include <QDateTime>
|
||||
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;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,30 @@
|
|||
#ifndef APPLICATIONINFOHELPER_H
|
||||
#define APPLICATIONINFOHELPER_H
|
||||
|
||||
#include "application-property.h"
|
||||
#include <QMetaType>
|
||||
#include <QVariant>
|
||||
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
|
|
@ -0,0 +1,43 @@
|
|||
#ifndef APPLICATIONPROPERTY_H
|
||||
#define APPLICATIONPROPERTY_H
|
||||
|
||||
#include <QObject>
|
||||
#include <QMap>
|
||||
#include <QVector>
|
||||
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<ApplicationProperty::Property> Properties;
|
||||
typedef QMap<ApplicationProperty::Property, QVariant> PropertyMap;
|
||||
typedef QMap<QString, PropertyMap> ApplicationInfoMap; // desktopFile->PropertyMap
|
||||
}
|
||||
Q_DECLARE_METATYPE(UkuiSearch::ApplicationProperty::Property)
|
||||
|
||||
#endif // APPLICATIONPROPERTY_H
|
|
@ -48,8 +48,6 @@ private:
|
|||
void appNameMatch(QString keyWord, size_t uniqueSymbol, DataQueue<SearchPluginIface::ResultInfo> *searchResult);
|
||||
void parseSoftWareCenterReturn(QList<QMap<QString, QString>> list, size_t uniqueSymbol, DataQueue<SearchPluginIface::ResultInfo> *searchResult);
|
||||
//void creatResultInfo(SearchPluginIface::ResultInfo &ri, QMapIterator<UkuiSearch::NameString, QStringList> &iter, bool isInstalled = true);
|
||||
|
||||
AppInfoTable *m_appInfoTable = nullptr;
|
||||
QString m_sourceText;
|
||||
size_t m_uniqueSymbol;
|
||||
DataQueue<SearchPluginIface::ResultInfo> *m_search_result = nullptr;
|
||||
|
|
|
@ -1 +0,0 @@
|
|||
#include "app-info-table.h"
|
|
@ -1 +0,0 @@
|
|||
#include "search-controller.h"
|
|
@ -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"
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -15,11 +15,11 @@ public:
|
|||
DataQueue<ResultItem>* refreshDataqueue();
|
||||
DataQueue<ResultItem>* 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);
|
||||
|
|
|
@ -42,7 +42,7 @@ DataQueue<ResultItem> *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<ResultItem> *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);
|
||||
}
|
||||
|
|
|
@ -26,11 +26,11 @@ public:
|
|||
DataQueue<ResultItem>* 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);
|
||||
|
|
|
@ -12,7 +12,7 @@ AppSearchTask::AppSearchTask(QObject *parent)
|
|||
this->setParent(parent);
|
||||
qRegisterMetaType<size_t>("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;
|
||||
|
|
|
@ -32,7 +32,6 @@ public:
|
|||
Q_INVOKABLE void sendFinishSignal(size_t searchId);
|
||||
|
||||
private:
|
||||
AppInfoTable *m_appInfoTable = nullptr;
|
||||
QThreadPool *m_pool = nullptr;
|
||||
};
|
||||
|
||||
|
|
|
@ -19,10 +19,10 @@ public:
|
|||
explicit UkuiSearchTaskPrivate(UkuiSearchTask* parent);
|
||||
~UkuiSearchTaskPrivate();
|
||||
DataQueue<ResultItem>* 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);
|
||||
|
|
|
@ -22,7 +22,7 @@ DataQueue<ResultItem> *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<ResultItem> *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);
|
||||
}
|
||||
|
|
|
@ -13,10 +13,10 @@ public:
|
|||
explicit UkuiSearchTask(QObject *parent = nullptr);
|
||||
~UkuiSearchTask();
|
||||
DataQueue<ResultItem>* 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);
|
||||
|
|
|
@ -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 <QDir>
|
||||
#include <QObject>
|
||||
#include <QSqlDatabase>
|
||||
|
@ -16,8 +11,9 @@
|
|||
#include <QMutex>
|
||||
#include <QSettings>
|
||||
#include <QThread>
|
||||
//#include <QTimer>
|
||||
//#include <QFileSystemWatcher>
|
||||
#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");
|
||||
|
|
Loading…
Reference in New Issue