From d6b622a7a291fa1ded8b7e35b7746ec84146f9f6 Mon Sep 17 00:00:00 2001 From: JunjieBai Date: Fri, 4 Aug 2023 09:54:53 +0800 Subject: [PATCH] refactor(app-database-service):remove the redundant slots inherited from QThread. --- .../app-db-manager.cpp | 1 + ukui-search-app-data-service/app-db-manager.h | 2 + .../dbus/app-database-adaptor.cpp | 111 ++++++++++++++++++ .../dbus/app-database-adaptor.h | 100 ++++++++++++++++ .../dbus/app-database-dbus.pri | 7 ++ .../dbus/org.ukui.appdatabase.xml | 46 ++++++++ .../ukui-search-app-data-service.cpp | 2 +- .../ukui-search-app-data-service.pro | 1 + 8 files changed, 269 insertions(+), 1 deletion(-) create mode 100644 ukui-search-app-data-service/dbus/app-database-adaptor.cpp create mode 100644 ukui-search-app-data-service/dbus/app-database-adaptor.h create mode 100644 ukui-search-app-data-service/dbus/app-database-dbus.pri create mode 100644 ukui-search-app-data-service/dbus/org.ukui.appdatabase.xml diff --git a/ukui-search-app-data-service/app-db-manager.cpp b/ukui-search-app-data-service/app-db-manager.cpp index e7003bc..152e8a7 100644 --- a/ukui-search-app-data-service/app-db-manager.cpp +++ b/ukui-search-app-data-service/app-db-manager.cpp @@ -179,6 +179,7 @@ AppDBManager::AppDBManager(QObject *parent) : QThread(parent), m_database(QSqlDa } } }); + m_adaptor = new AppDBManagerAdaptor(this); } else { qDebug() << "App-db-manager does nothing."; } diff --git a/ukui-search-app-data-service/app-db-manager.h b/ukui-search-app-data-service/app-db-manager.h index f9bc6ec..8df9718 100644 --- a/ukui-search-app-data-service/app-db-manager.h +++ b/ukui-search-app-data-service/app-db-manager.h @@ -33,6 +33,7 @@ #include "pending-app-info-queue.h" #include "file-system-watcher.h" #include "application-property.h" +#include "app-database-adaptor.h" #define APP_DATABASE_PATH QDir::homePath()+"/.config/org.ukui/ukui-search/appdata/" #define APP_DATABASE_NAME "app-info.db" @@ -223,6 +224,7 @@ private: //原本额外排除的目录,不知道额外的原因,有可能之后有问题--bjj20220621 "/usr/share/applications/screensavers" }; + AppDBManagerAdaptor *m_adaptor = nullptr; Q_SIGNALS: //操作数据库 diff --git a/ukui-search-app-data-service/dbus/app-database-adaptor.cpp b/ukui-search-app-data-service/dbus/app-database-adaptor.cpp new file mode 100644 index 0000000..59d58fc --- /dev/null +++ b/ukui-search-app-data-service/dbus/app-database-adaptor.cpp @@ -0,0 +1,111 @@ +/* + * This file was generated by qdbusxml2cpp version 0.8 + * Command line was: qdbusxml2cpp org.ukui.appdatabase.xml -a app-database-adaptor -i ../../libsearch/appdata/application-property.h + * + * qdbusxml2cpp is Copyright (C) 2020 The Qt Company Ltd. + * + * This is an auto-generated file. + * Do not edit! All changes made to it will be lost. + */ + +#include "app-database-adaptor.h" +#include +#include +#include +#include +#include +#include +#include + +/* + * Implementation of adaptor class AppDBManagerAdaptor + */ + +AppDBManagerAdaptor::AppDBManagerAdaptor(QObject *parent) + : QDBusAbstractAdaptor(parent) +{ + // constructor + setAutoRelaySignals(true); +} + +AppDBManagerAdaptor::~AppDBManagerAdaptor() +{ + // destructor +} + +void AppDBManagerAdaptor::deleteDBItem(const QString &desktopfd) +{ + // handle method call org.ukui.search.appDBManager.deleteDBItem + QMetaObject::invokeMethod(parent(), "deleteDBItem", Q_ARG(QString, desktopfd)); +} + +QString AppDBManagerAdaptor::desktopFilePathFromName(const QString &desktopFileName) +{ + // handle method call org.ukui.search.appDBManager.desktopFilePathFromName + QString out0; + QMetaObject::invokeMethod(parent(), "desktopFilePathFromName", Q_RETURN_ARG(QString, out0), Q_ARG(QString, desktopFileName)); + return out0; +} + +void AppDBManagerAdaptor::insertDBItem(const QString &desktopfd) +{ + // handle method call org.ukui.search.appDBManager.insertDBItem + QMetaObject::invokeMethod(parent(), "insertDBItem", Q_ARG(QString, desktopfd)); +} + +void AppDBManagerAdaptor::setValue(UkuiSearch::ApplicationInfoMap infos2BSet) +{ + // handle method call org.ukui.search.appDBManager.setValue + QMetaObject::invokeMethod(parent(), "setValue", Q_ARG(UkuiSearch::ApplicationInfoMap, infos2BSet)); +} + +QString AppDBManagerAdaptor::tranPidToDesktopFp(uint pid) +{ + // handle method call org.ukui.search.appDBManager.tranPidToDesktopFp + QString out0; + QMetaObject::invokeMethod(parent(), "tranPidToDesktopFp", Q_RETURN_ARG(QString, out0), Q_ARG(uint, pid)); + return out0; +} + +void AppDBManagerAdaptor::updateDBItem(const QString &desktopfd) +{ + // handle method call org.ukui.search.appDBManager.updateDBItem + QMetaObject::invokeMethod(parent(), "updateDBItem", Q_ARG(QString, desktopfd)); +} + +void AppDBManagerAdaptor::updateFavoritesState(const QString &desktopFilePath) +{ + // handle method call org.ukui.search.appDBManager.updateFavoritesState + QMetaObject::invokeMethod(parent(), "updateFavoritesState", Q_ARG(QString, desktopFilePath)); +} + +void AppDBManagerAdaptor::updateFavoritesState(const QString &desktopFilePath, uint num) +{ + // handle method call org.ukui.search.appDBManager.updateFavoritesState + QMetaObject::invokeMethod(parent(), "updateFavoritesState", Q_ARG(QString, desktopFilePath), Q_ARG(uint, num)); +} + +void AppDBManagerAdaptor::updateLaunchTimes(const QString &desktopFilePath) +{ + // handle method call org.ukui.search.appDBManager.updateLaunchTimes + QMetaObject::invokeMethod(parent(), "updateLaunchTimes", Q_ARG(QString, desktopFilePath)); +} + +void AppDBManagerAdaptor::updateLocaleData(const QString &desktopFilePath) +{ + // handle method call org.ukui.search.appDBManager.updateLocaleData + QMetaObject::invokeMethod(parent(), "updateLocaleData", Q_ARG(QString, desktopFilePath)); +} + +void AppDBManagerAdaptor::updateTopState(const QString &desktopFilePath) +{ + // handle method call org.ukui.search.appDBManager.updateTopState + QMetaObject::invokeMethod(parent(), "updateTopState", Q_ARG(QString, desktopFilePath)); +} + +void AppDBManagerAdaptor::updateTopState(const QString &desktopFilePath, uint num) +{ + // handle method call org.ukui.search.appDBManager.updateTopState + QMetaObject::invokeMethod(parent(), "updateTopState", Q_ARG(QString, desktopFilePath), Q_ARG(uint, num)); +} + diff --git a/ukui-search-app-data-service/dbus/app-database-adaptor.h b/ukui-search-app-data-service/dbus/app-database-adaptor.h new file mode 100644 index 0000000..365f578 --- /dev/null +++ b/ukui-search-app-data-service/dbus/app-database-adaptor.h @@ -0,0 +1,100 @@ +/* + * This file was generated by qdbusxml2cpp version 0.8 + * Command line was: qdbusxml2cpp org.ukui.appdatabase.xml -a app-database-adaptor -i ../../libsearch/appdata/application-property.h + * + * qdbusxml2cpp is Copyright (C) 2020 The Qt Company Ltd. + * + * This is an auto-generated file. + * This file may have been hand-edited. Look for HAND-EDIT comments + * before re-generating it. + */ + +#ifndef APPDATABASEADAPTOR_H +#define APPDATABASEADAPTOR_H + +#include +#include +#include "../../libsearch/appdata/application-property.h" +QT_BEGIN_NAMESPACE +class QByteArray; +template class QList; +template class QMap; +class QString; +class QStringList; +class QVariant; +QT_END_NAMESPACE + +/* + * Adaptor class for interface org.ukui.search.appDBManager + */ +class AppDBManagerAdaptor: public QDBusAbstractAdaptor +{ + Q_OBJECT + Q_CLASSINFO("D-Bus Interface", "org.ukui.search.appDBManager") + Q_CLASSINFO("D-Bus Introspection", "" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" + "") +public: + AppDBManagerAdaptor(QObject *parent); + virtual ~AppDBManagerAdaptor(); + +public: // PROPERTIES +public Q_SLOTS: // METHODS + void deleteDBItem(const QString &desktopfd); + QString desktopFilePathFromName(const QString &desktopFileName); + void insertDBItem(const QString &desktopfd); + void setValue(UkuiSearch::ApplicationInfoMap infos2BSet); + QString tranPidToDesktopFp(uint pid); + void updateDBItem(const QString &desktopfd); + void updateFavoritesState(const QString &desktopFilePath); + void updateFavoritesState(const QString &desktopFilePath, uint num); + void updateLaunchTimes(const QString &desktopFilePath); + void updateLocaleData(const QString &desktopFilePath); + void updateTopState(const QString &desktopFilePath); + void updateTopState(const QString &desktopFilePath, uint num); +Q_SIGNALS: // SIGNALS +}; + +#endif diff --git a/ukui-search-app-data-service/dbus/app-database-dbus.pri b/ukui-search-app-data-service/dbus/app-database-dbus.pri new file mode 100644 index 0000000..7352e31 --- /dev/null +++ b/ukui-search-app-data-service/dbus/app-database-dbus.pri @@ -0,0 +1,7 @@ +INCLUDEPATH += $$PWD + +HEADERS += \ + $$PWD/app-database-adaptor.h + +SOURCES += \ + $$PWD/app-database-adaptor.cpp diff --git a/ukui-search-app-data-service/dbus/org.ukui.appdatabase.xml b/ukui-search-app-data-service/dbus/org.ukui.appdatabase.xml new file mode 100644 index 0000000..1b79c5b --- /dev/null +++ b/ukui-search-app-data-service/dbus/org.ukui.appdatabase.xml @@ -0,0 +1,46 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/ukui-search-app-data-service/ukui-search-app-data-service.cpp b/ukui-search-app-data-service/ukui-search-app-data-service.cpp index 13ac366..054c36b 100644 --- a/ukui-search-app-data-service/ukui-search-app-data-service.cpp +++ b/ukui-search-app-data-service/ukui-search-app-data-service.cpp @@ -51,7 +51,7 @@ UkuiSearchAppDataService::UkuiSearchAppDataService(int &argc, char *argv[], cons qCritical() << "QDbus register service failed reason:" << sessionBus.lastError(); } - if(!sessionBus.registerObject("/org/ukui/search/appDataBase/dbManager", AppDBManager::getInstance(), QDBusConnection::ExportAllSlots)) { + if(!sessionBus.registerObject("/org/ukui/search/appDataBase/dbManager", AppDBManager::getInstance(), QDBusConnection::ExportAdaptors)) { qCritical() << "ukui-search-app-db-manager dbus register object failed reason:" << sessionBus.lastError(); } diff --git a/ukui-search-app-data-service/ukui-search-app-data-service.pro b/ukui-search-app-data-service/ukui-search-app-data-service.pro index 2645230..9d80df9 100644 --- a/ukui-search-app-data-service/ukui-search-app-data-service.pro +++ b/ukui-search-app-data-service/ukui-search-app-data-service.pro @@ -22,6 +22,7 @@ QMAKE_CXXFLAGS += -Werror=return-type -Werror=return-local-addr -Werror=uninitia #include(../libsearch/appdata/appdata.pri) include(../3rd-parties/qtsingleapplication/qtsingleapplication.pri) +include(./dbus/app-database-dbus.pri) LIBS += -lQt5Xdg