diff --git a/libsearch/appdata/app-db-manager.cpp b/libsearch/appdata/app-db-manager.cpp new file mode 100644 index 0000000..d37a053 --- /dev/null +++ b/libsearch/appdata/app-db-manager.cpp @@ -0,0 +1,40 @@ +#include "app-db-manager.h" +#include +#include +#include +#include +#include +using namespace UkuiSearch; +#define APP_DATABASE_PATH QDir::homePath()+"/.config/org.ukui/ukui-search/appdata/"+"app-info.db" +#define CONNECTION_NAME QLatin1String("ukss-appdb-connection") +static AppDBManager *global_instance = nullptr; +AppDBManager *AppDBManager::getInstance() +{ + if (!global_instance) { + global_instance = new AppDBManager(); + } + return global_instance; +} +AppDBManager::AppDBManager(QObject *parent) : QObject(parent), m_database(QSqlDatabase::addDatabase("QSQLITE",CONNECTION_NAME)) +{ +} + +AppDBManager::~AppDBManager() +{ + +} +void AppDBManager::initDateBaseConnection() +{ + if(!m_database->isValid()) { + qWarning() << m_database->lastError(); + QApplication::quit(); + } + m_database->setDatabaseName(APP_DATABASE_PATH); + if(!m_database->open()) { + qWarning() << m_database->lastError(); + QApplication::quit(); + } + //todo: 建表 +} + + diff --git a/libsearch/appdata/app-db-manager.h b/libsearch/appdata/app-db-manager.h new file mode 100644 index 0000000..a5076b3 --- /dev/null +++ b/libsearch/appdata/app-db-manager.h @@ -0,0 +1,27 @@ +#ifndef APPDBMANAGER_H +#define APPDBMANAGER_H + +#include +#include +namespace UkuiSearch { +/** + * @brief The AppDBManager class + * 功能:1.遍历并且监听desktop文件目录,建立并且维护应用信息数据库。 + * 2.监听应用安装,打开事件,收藏等事件,更新数据库 + */ + +class AppDBManager : public QObject +{ + Q_OBJECT +public: + static AppDBManager *getInstance(); + void initDateBaseConnection(); +private: + explicit AppDBManager(QObject *parent = nullptr); + ~AppDBManager(); + QSqlDatabase *m_database = nullptr; + +}; +} + +#endif // APPDBMANAGER_H diff --git a/libsearch/appdata/app-info-table-private.h b/libsearch/appdata/app-info-table-private.h new file mode 100644 index 0000000..e4b7ba8 --- /dev/null +++ b/libsearch/appdata/app-info-table-private.h @@ -0,0 +1,21 @@ +#ifndef APPINFOTABLEPRIVATE_H +#define APPINFOTABLEPRIVATE_H +#include +#include +namespace UkuiSearch { +class AppInfoTablePrivate : public QObject +{ + Q_OBJECT +public: + explicit AppInfoTablePrivate(AppInfoTable *parent = nullptr); + AppInfoTablePrivate(AppInfoTablePrivate &) = delete; + AppInfoTablePrivate &operator =(const AppInfoTablePrivate &) = delete; + +private: + AppInfoTable *q; + +}; + + +} +#endif // APPINFOTABLEPRIVATE_H diff --git a/libsearch/appdata/app-info-table.cpp b/libsearch/appdata/app-info-table.cpp new file mode 100644 index 0000000..dfe2356 --- /dev/null +++ b/libsearch/appdata/app-info-table.cpp @@ -0,0 +1,10 @@ +#include "app-info-table.h" +#include "app-info-table-private.h" +using namespace UkuiSearch; +AppInfoTablePrivate::AppInfoTablePrivate(AppInfoTable *parent) : QObject(parent), q(parent) +{ +} + +AppInfoTable::AppInfoTable(QObject *parent) : QObject(parent), d(new AppInfoTablePrivate(this)) +{ +} diff --git a/libsearch/appdata/app-info-table.h b/libsearch/appdata/app-info-table.h new file mode 100644 index 0000000..c177700 --- /dev/null +++ b/libsearch/appdata/app-info-table.h @@ -0,0 +1,35 @@ +#ifndef APPINFOTABLE_H +#define APPINFOTABLE_H + +#include +namespace UkuiSearch { +class AppInfoTablePrivate; +/** + * @brief The AppInfoTable class + * TODO:提供查询接口(待定),包括: + * 1.查询全部已安装应用信息(图标,名称,分类等),并且根据系统语言切换 + * 2.查询收藏应用信息 + * 3.查询置顶顺序信息 + * 4.收藏顺序修改 + * 5.置顶顺序修改 + * 6.添加到桌面快捷方式 + * 7.固定到任务栏快捷方式 + * 8.应用启动 + * 9.应用卸载 + * 注意事项:修改接口实现时注意事务操作 + */ +class AppInfoTable : public QObject +{ + Q_OBJECT +public: + explicit AppInfoTable(QObject *parent = nullptr); + AppInfoTable(AppInfoTable &) = delete; + AppInfoTable &operator =(const AppInfoTable &) = delete; + +private: + AppInfoTablePrivate *d; + +}; +} + +#endif // APPINFOTABLE_H diff --git a/libsearch/appdata/appdata.pri b/libsearch/appdata/appdata.pri index 6c7eb7d..c6b5e43 100644 --- a/libsearch/appdata/appdata.pri +++ b/libsearch/appdata/appdata.pri @@ -1,6 +1,11 @@ INCLUDEPATH += $$PWD HEADERS += \ + $$PWD/app-db-manager.h \ + $$PWD/app-info-table-private.h \ + $$PWD/app-info-table.h -SOURCES += \ +SOURCES += \ \ + $$PWD/app-db-manager.cpp \ + $$PWD/app-info-table.cpp diff --git a/libsearch/file-utils.h b/libsearch/file-utils.h index 1d7e6ce..0dc6393 100644 --- a/libsearch/file-utils.h +++ b/libsearch/file-utils.h @@ -40,14 +40,14 @@ #include #include -#include +#include #include #include #include #include #include #include -#include +#include #include //#include #include diff --git a/libsearch/libsearch.pro b/libsearch/libsearch.pro index 064a772..da08517 100644 --- a/libsearch/libsearch.pro +++ b/libsearch/libsearch.pro @@ -1,4 +1,4 @@ -QT += core xml widgets dbus concurrent +QT += core xml widgets dbus concurrent sql VERSION = 1.0.0 DEFINES += VERSION='\\"$${VERSION}\\"'