From 2c56ba622f0454cbcc493f3b10ea8b8449ab7af9 Mon Sep 17 00:00:00 2001 From: Zhang Sheng Date: Thu, 27 Jun 2024 17:54:36 +0800 Subject: [PATCH 1/2] chore: code style 1. remove Qt5 adaptor 2. adjust code style log: as title --- CMakeLists.txt | 4 ++-- .../dfm-framework/lifecycle/pluginmetaobject.h | 2 +- .../lifecycle/pluginquickmetadata.h | 2 +- include/dfm-gui/dfm_gui_global.h | 2 +- include/dfm-gui/windowmanager.h | 14 ++++++++------ src/apps/dde-file-manager/main.cpp | 2 -- .../lifecycle/pluginquickmetadata.cpp | 3 ++- .../lifecycle/private/pluginmanager_p.cpp | 16 ++++++++-------- src/dfm-gui/appletmanager.cpp | 5 +++-- 9 files changed, 26 insertions(+), 24 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 8d8cc65acc..dadfdc39f7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -24,7 +24,7 @@ include(install_plugin_quick_module) include(install_dconfig) # Select major version. -find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Core) +find_package(QT NAMES Qt6 REQUIRED COMPONENTS Core) message("Using Qt version: ${QT_VERSION_MAJOR}") if(QT_VERSION_MAJOR EQUAL "6") @@ -36,7 +36,7 @@ endif() find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Widgets REQUIRED) find_package(Dtk${DTK_VERSION_MAJOR}CMake REQUIRED) -#if no debug, can't out in code define key '__FUNCTION__' and so on +#if no debug, can't out in codke define key '__FUNCTION__' and so on add_definitions(-DQT_MESSAGELOGCONTEXT) # TODO: control it by CI. (Automation Testing) diff --git a/include/dfm-framework/lifecycle/pluginmetaobject.h b/include/dfm-framework/lifecycle/pluginmetaobject.h index 4750456a75..67332f48fd 100644 --- a/include/dfm-framework/lifecycle/pluginmetaobject.h +++ b/include/dfm-framework/lifecycle/pluginmetaobject.h @@ -5,7 +5,7 @@ #ifndef PLUGINMETAOBJECT_H #define PLUGINMETAOBJECT_H -#include "dfm-framework/lifecycle/pluginquickmetadata.h" +#include #include #include diff --git a/include/dfm-framework/lifecycle/pluginquickmetadata.h b/include/dfm-framework/lifecycle/pluginquickmetadata.h index 45d67b3e09..3c62ddd474 100644 --- a/include/dfm-framework/lifecycle/pluginquickmetadata.h +++ b/include/dfm-framework/lifecycle/pluginquickmetadata.h @@ -40,7 +40,7 @@ class PluginQuickMetaData final private: QScopedPointer d; - Q_DISABLE_COPY(PluginQuickMetaData); + Q_DISABLE_COPY(PluginQuickMetaData) }; using PluginQuickMetaPtr = QSharedPointer; diff --git a/include/dfm-gui/dfm_gui_global.h b/include/dfm-gui/dfm_gui_global.h index d8f3129db1..7df0555ce2 100644 --- a/include/dfm-gui/dfm_gui_global.h +++ b/include/dfm-gui/dfm_gui_global.h @@ -13,7 +13,7 @@ #define DFMGUI_END_NAMESPACE } #define DFMGUI_USE_NAMESPACE using namespace DFMGUI_NAMESPACE; -#include +#include Q_DECLARE_LOGGING_CATEGORY(logDFMGui) diff --git a/include/dfm-gui/windowmanager.h b/include/dfm-gui/windowmanager.h index bc23b59564..b75ea97959 100644 --- a/include/dfm-gui/windowmanager.h +++ b/include/dfm-gui/windowmanager.h @@ -20,9 +20,7 @@ class WindowManagerPrivate; class WindowManager : public QObject { Q_OBJECT - - explicit WindowManager(); - ~WindowManager() override; + Q_DISABLE_COPY_MOVE(WindowManager) public: using Handle = QPointer; @@ -32,7 +30,7 @@ class WindowManager : public QObject QSharedPointer engine() const; Handle createWindow(const QUrl &url, const QString &pluginName, - const QString &quickId, const QVariantMap &var = {}); + const QString &quickId, const QVariantMap &var = {}); void showWindow(const Handle &handle) const; bool activeExistsWindowByUrl(const QUrl &url) const; @@ -55,10 +53,14 @@ class WindowManager : public QObject void lastWindowClosed(quint64 windId); void currentUrlChanged(quint64 windId, const QUrl &url); +private: + explicit WindowManager(); + ~WindowManager() override; + private: QScopedPointer dptr; - Q_DECLARE_PRIVATE_D(dptr, WindowManager); - Q_DISABLE_COPY(WindowManager) + + Q_DECLARE_PRIVATE_D(dptr, WindowManager) }; using WindowHandle = WindowManager::Handle; diff --git a/src/apps/dde-file-manager/main.cpp b/src/apps/dde-file-manager/main.cpp index a557122af6..e91bf8e328 100644 --- a/src/apps/dde-file-manager/main.cpp +++ b/src/apps/dde-file-manager/main.cpp @@ -18,12 +18,10 @@ #include -// #include #include #include #include -// #include #include #include #include diff --git a/src/dfm-framework/lifecycle/pluginquickmetadata.cpp b/src/dfm-framework/lifecycle/pluginquickmetadata.cpp index bd063b609b..596c7cd6dd 100644 --- a/src/dfm-framework/lifecycle/pluginquickmetadata.cpp +++ b/src/dfm-framework/lifecycle/pluginquickmetadata.cpp @@ -2,9 +2,10 @@ // // SPDX-License-Identifier: GPL-3.0-or-later -#include #include "private/pluginquickmetadata_p.h" +#include + DPF_BEGIN_NAMESPACE PluginQuickMetaData::PluginQuickMetaData() diff --git a/src/dfm-framework/lifecycle/private/pluginmanager_p.cpp b/src/dfm-framework/lifecycle/private/pluginmanager_p.cpp index 52552aee68..ea824d2a60 100644 --- a/src/dfm-framework/lifecycle/private/pluginmanager_p.cpp +++ b/src/dfm-framework/lifecycle/private/pluginmanager_p.cpp @@ -262,17 +262,17 @@ void PluginManagerPrivate::jsonToMeta(PluginMetaObjectPointer metaObject, const metaObject->d->state = PluginMetaObject::kReaded; // QML 组件信息 - QJsonArray quickArray = metaData.value(kQuick).toArray(); - for (auto quickItr : quickArray) { - QJsonObject quick = quickItr.toObject(); + QJsonArray &&quickArray = metaData.value(kQuick).toArray(); + for (const auto &quickItr : quickArray) { + const QJsonObject &quick = quickItr.toObject(); QString quickParent = quick.value(kQuickParent).toString(); // Quick plugin 的 parent 必须在 Depends 字段存在 - if (!quickParent.isEmpty()) { - QString parPlugin = quickParent.split('.').first(); - QList &depends = metaObject->d->depends; - QList::iterator findItr = std::find_if(depends.begin(), depends.end(), [&](const PluginDepend &depend) { - return depend.pluginName == parPlugin; + if (!quickParent.isEmpty() && quickParent.contains(".")) { + QString parentPlugin = quickParent.split('.').first(); + const QList &depends = metaObject->d->depends; + auto findItr = std::find_if(depends.cbegin(), depends.cend(), [&parentPlugin](const PluginDepend &depend) { + return depend.pluginName == parentPlugin; }); if (findItr == metaObject->d->depends.end()) { diff --git a/src/dfm-gui/appletmanager.cpp b/src/dfm-gui/appletmanager.cpp index 7214b87fc2..eefd76824f 100644 --- a/src/dfm-gui/appletmanager.cpp +++ b/src/dfm-gui/appletmanager.cpp @@ -53,9 +53,10 @@ void AppletManagerPrivate::parseDefaultRootTemplates() QList quickInfoList = metaPtr->quickMetaData(); for (const dpf::PluginQuickMetaPtr &infoPtr : quickInfoList) { - if (!q->registeApplet(infoPtr)) { + bool ret { q->registeApplet(infoPtr) }; + Q_ASSERT_X(ret, "dfm-gui", errorString.toLocal8Bit().data()); + if (!ret) qCWarning(logDFMGui) << errorString; - } } } } From 9f21b3db4f191703c8548c4addf346a2cffd45e5 Mon Sep 17 00:00:00 2001 From: Zhang Sheng Date: Mon, 1 Jul 2024 14:09:35 +0800 Subject: [PATCH 2/2] refacotr: remove all v23 tags The system version number will continue to evolve, the new version of this DFM do not have to consider the compatibility of v20 log: as title --- CMakeLists.txt | 14 +- .../dde-desktop/data/applications/dfm-open.sh | 21 +-- src/dfm-base/utils/fileutils.cpp | 25 ++-- src/dfm-base/utils/universalutils.cpp | 128 +++--------------- 4 files changed, 46 insertions(+), 142 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index dadfdc39f7..709483f025 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -35,7 +35,6 @@ else() endif() find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Widgets REQUIRED) -find_package(Dtk${DTK_VERSION_MAJOR}CMake REQUIRED) #if no debug, can't out in codke define key '__FUNCTION__' and so on add_definitions(-DQT_MESSAGELOGCONTEXT) @@ -47,15 +46,10 @@ if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT) endif() #Indentify the version -if (${DEEPIN_OS_VERSION} MATCHES "23") - add_definitions(-DCOMPILE_ON_V23) - set(COMPLIE_ON_V23 TRUE) - message("COMPILE ON v23") -else() - add_definitions(-DCOMPILE_ON_V20) - set(COMPLIE_ON_V20 TRUE) - message("COMPILE ON v20") -endif() +# TODO: remove it +add_definitions(-DCOMPILE_ON_V23) +set(COMPLIE_ON_V23 TRUE) +message("COMPILE ON v23") # TODO(zhangs): enable it # Disbale qDebug(), qInfo(), qWaring(), qCritical() diff --git a/src/apps/dde-desktop/data/applications/dfm-open.sh b/src/apps/dde-desktop/data/applications/dfm-open.sh index 54e0f71511..b2806b8a17 100755 --- a/src/apps/dde-desktop/data/applications/dfm-open.sh +++ b/src/apps/dde-desktop/data/applications/dfm-open.sh @@ -4,8 +4,8 @@ # # SPDX-License-Identifier: GPL-3.0-or-later -sys_name=$(grep "^SystemName=" /etc/os-version | cut -d'=' -f2) -sys_ver=$(grep "^MajorVersion=" /etc/os-version | cut -d'=' -f2) +# sys_name=$(grep "^SystemName=" /etc/os-version | cut -d'=' -f2) +# sys_ver=$(grep "^MajorVersion=" /etc/os-version | cut -d'=' -f2) # this is for adapt the new ApplicationManager. # open computer/trash root with 'gio open', @@ -16,11 +16,14 @@ sys_ver=$(grep "^MajorVersion=" /etc/os-version | cut -d'=' -f2) # So, after opening a directory with xdg-open, # the application's cgroup can be categorized into the file manager as expected. -if [ "$sys_name" = "Deepin" ] && [ "$sys_ver" = "23" ]; then - echo "open $1 with xdg-open." - xdg-open $1 -else - echo "open $1 with gio open." - gio open $1 -fi +# if [ "$sys_name" = "Deepin" ] && [ "$sys_ver" = "23" ]; then +# echo "open $1 with xdg-open." +# xdg-open $1 +# else +# echo "open $1 with gio open." +# gio open $1 +# fi + +echo "open $1 with xdg-open." +xdg-open $1 diff --git a/src/dfm-base/utils/fileutils.cpp b/src/dfm-base/utils/fileutils.cpp index 7559320534..62b7a9a01b 100644 --- a/src/dfm-base/utils/fileutils.cpp +++ b/src/dfm-base/utils/fileutils.cpp @@ -52,13 +52,8 @@ #include #include -#ifdef COMPILE_ON_V23 -# define APPEARANCE_SERVICE "org.deepin.dde.Appearance1" -# define APPEARANCE_PATH "/org/deepin/dde/Appearance1" -#else -# define APPEARANCE_SERVICE "com.deepin.daemon.Appearance" -# define APPEARANCE_PATH "/com/deepin/daemon/Appearance" -#endif +#define APPEARANCE_SERVICE "org.deepin.dde.Appearance1" +#define APPEARANCE_PATH "/org/deepin/dde/Appearance1" namespace dfmbase { @@ -772,16 +767,16 @@ QString FileUtils::toUnicode(const QByteArray &data, const QString &fileName) if (data.isEmpty()) return QString(); -// const QByteArray &encoding = detectCharset(data, fileName); + // const QByteArray &encoding = detectCharset(data, fileName); -// if (QTextCodec *codec = QTextCodec::codecForName(encoding)) { -// return codec->toUnicode(data); -// } + // if (QTextCodec *codec = QTextCodec::codecForName(encoding)) { + // return codec->toUnicode(data); + // } -// // auto decoder = QStringDecoder(QStringEncoder::System); -// // QString decoding = decoder.decode(encoding); -// // if (!decoding.isEmpty()) -// // return decoding; + // // auto decoder = QStringDecoder(QStringEncoder::System); + // // QString decoding = decoder.decode(encoding); + // // if (!decoding.isEmpty()) + // // return decoding; return QString::fromLocal8Bit(data); } diff --git a/src/dfm-base/utils/universalutils.cpp b/src/dfm-base/utils/universalutils.cpp index b975261b1f..eb3c16b096 100644 --- a/src/dfm-base/utils/universalutils.cpp +++ b/src/dfm-base/utils/universalutils.cpp @@ -21,47 +21,25 @@ #include #include -#ifdef COMPILE_ON_V23 -# define APP_MANAGER_SERVICE "org.desktopspec.ApplicationManager1" -# define APP_MANAGER_PATH_PREFIX "/org/desktopspec/ApplicationManager1" -# define APP_INTERFACE "org.desktopspec.ApplicationManager1.Application" - -# define SYSTEM_SYSTEMINFO_SERVICE "org.deepin.dde.SystemInfo1" -# define SYSTEM_SYSTEMINFO_PATH "/org/deepin/dde/SystemInfo1" -# define SYSTEM_SYSTEMINFO_INTERFACE "org.deepin.dde.SystemInfo1" - -# define DEAMON_SYSTEMINFO_SERVICE "org.deepin.daemon.SystemInfo1" -# define DEAMON_SYSTEMINFO_PATH "/org/deepin/daemon/SystemInfo1" -# define DEAMON_SYSTEMINFO_INTERFACE "org.deepin.daemon.SystemInfo1" - -# define DEAMON_DOCK_SERVICE "org.deepin.dde.daemon.Dock1" -# define DEAMON_DOCK_PATH "/org/deepin/dde/daemon/Dock1" -# define DEAMON_DOCK_INTERFACE "org.deepin.dde.daemon.Dock1" - -# define DDE_LOCKSERVICE_SERVICE "org.deepin.dde.LockService1" -# define DDE_LOCKSERVICE_PATH "/org/deepin/dde/LockService1" -# define DDE_LOCKSERVICE_INTERFACE "org.deepin.dde.LockService1" -#else -# define APP_MANAGER_SERVICE "com.deepin.SessionManager" -# define APP_MANAGER_PATH "/com/deepin/StartManager" -# define APP_MANAGER_INTERFACE "com.deepin.StartManager" - -# define SYSTEM_SYSTEMINFO_SERVICE "com.deepin.system.SystemInfo" -# define SYSTEM_SYSTEMINFO_PATH "/com/deepin/system/SystemInfo" -# define SYSTEM_SYSTEMINFO_INTERFACE "com.deepin.system.SystemInfo" - -# define DEAMON_SYSTEMINFO_SERVICE "com.deepin.daemon.SystemInfo" -# define DEAMON_SYSTEMINFO_PATH "/com/deepin/daemon/SystemInfo" -# define DEAMON_SYSTEMINFO_INTERFACE "com.deepin.daemon.SystemInfo" - -# define DEAMON_DOCK_SERVICE "com.deepin.dde.daemon.Dock" -# define DEAMON_DOCK_PATH "/com/deepin/dde/daemon/Dock" -# define DEAMON_DOCK_INTERFACE "com.deepin.dde.daemon.Dock" - -# define DDE_LOCKSERVICE_SERVICE "com.deepin.dde.LockService" -# define DDE_LOCKSERVICE_PATH "/com/deepin/dde/LockService" -# define DDE_LOCKSERVICE_INTERFACE "com.deepin.dde.LockService" -#endif +#define APP_MANAGER_SERVICE "org.desktopspec.ApplicationManager1" +#define APP_MANAGER_PATH_PREFIX "/org/desktopspec/ApplicationManager1" +#define APP_INTERFACE "org.desktopspec.ApplicationManager1.Application" + +#define SYSTEM_SYSTEMINFO_SERVICE "org.deepin.dde.SystemInfo1" +#define SYSTEM_SYSTEMINFO_PATH "/org/deepin/dde/SystemInfo1" +#define SYSTEM_SYSTEMINFO_INTERFACE "org.deepin.dde.SystemInfo1" + +#define DEAMON_SYSTEMINFO_SERVICE "org.deepin.daemon.SystemInfo1" +#define DEAMON_SYSTEMINFO_PATH "/org/deepin/daemon/SystemInfo1" +#define DEAMON_SYSTEMINFO_INTERFACE "org.deepin.daemon.SystemInfo1" + +#define DEAMON_DOCK_SERVICE "org.deepin.dde.daemon.Dock1" +#define DEAMON_DOCK_PATH "/org/deepin/dde/daemon/Dock1" +#define DEAMON_DOCK_INTERFACE "org.deepin.dde.daemon.Dock1" + +#define DDE_LOCKSERVICE_SERVICE "org.deepin.dde.LockService1" +#define DDE_LOCKSERVICE_PATH "/org/deepin/dde/LockService1" +#define DDE_LOCKSERVICE_INTERFACE "org.deepin.dde.LockService1" namespace dfmbase { @@ -260,39 +238,13 @@ bool UniversalUtils::checkLaunchAppInterface() initStatus = false; return; } -#ifndef COMPILE_ON_V23 - QDBusInterface introspect(APP_MANAGER_SERVICE, - APP_MANAGER_PATH, - "org.freedesktop.DBus.Introspectable", - QDBusConnection::sessionBus()); - introspect.setTimeout(1000); - QDBusPendingReply reply = introspect.asyncCallWithArgumentList(QStringLiteral("Introspect"), {}); - reply.waitForFinished(); - if (reply.isFinished() && reply.isValid() && !reply.isError()) { - QString xmlCode = reply.argumentAt(0).toString(); - if (xmlCode.contains(APP_MANAGER_INTERFACE)) { - if (xmlCode.contains("LaunchApp")) { - initStatus = true; - } else { - qCWarning(logDFMBase) << QString("%1 : doesn't have LaunchApp interface.").arg(APP_MANAGER_SERVICE); - initStatus = false; - } - } else { - qCWarning(logDFMBase) << QString("%1 : Introspect error").arg(APP_MANAGER_SERVICE) << xmlCode; - initStatus = false; - } - } else { - initStatus = false; - } -#endif }); return initStatus; } bool UniversalUtils::launchAppByDBus(const QString &desktopFile, const QStringList &filePaths) { -#ifdef COMPILE_ON_V23 - const auto &file = QFileInfo{desktopFile}; + const auto &file = QFileInfo { desktopFile }; constexpr auto kDesktopSuffix { u8"desktop" }; if (file.suffix() != kDesktopSuffix) { @@ -311,52 +263,12 @@ bool UniversalUtils::launchAppByDBus(const QString &desktopFile, const QStringLi auto reply = appManager.callWithArgumentList(QDBus::Block, QStringLiteral("Launch"), { QVariant::fromValue(QString {}), QVariant::fromValue(filePaths), QVariant::fromValue(QVariantMap {}) }); return reply.type() == QDBusMessage::ReplyMessage; - -#else - QDBusInterface appManager(APP_MANAGER_SERVICE, - APP_MANAGER_PATH, - APP_MANAGER_INTERFACE, - QDBusConnection::sessionBus()); - - QList argumentList; - argumentList << QVariant::fromValue(desktopFile) << QVariant::fromValue(static_cast(QX11Info::getTimestamp())) << QVariant::fromValue(filePaths); - appManager.asyncCallWithArgumentList(QStringLiteral("LaunchApp"), argumentList); - return true; -#endif } bool UniversalUtils::runCommand(const QString &cmd, const QStringList &args, const QString &wd) { -#ifdef COMPILE_ON_V23 qCDebug(logDFMBase) << "new AM wouldn't provide any method to run Command, so launch cmd by qt:" << cmd << args; return QProcess::startDetached(cmd, args, wd); -#else - if (checkLaunchAppInterface()) { - qCDebug(logDFMBase) << "launch cmd by dbus:" << cmd << args; - QDBusInterface appManager(APP_MANAGER_SERVICE, - APP_MANAGER_PATH, - APP_MANAGER_INTERFACE, - QDBusConnection::sessionBus()); - - QList argumentList; - argumentList << QVariant::fromValue(cmd) << QVariant::fromValue(args); - - if (!wd.isEmpty()) { - QVariantMap opt = { { "dir", wd } }; - argumentList << QVariant::fromValue(opt); - appManager.asyncCallWithArgumentList(QStringLiteral("RunCommandWithOptions"), argumentList); - } else { - appManager.asyncCallWithArgumentList(QStringLiteral("RunCommand"), argumentList); - } - - return true; - } else { - qCDebug(logDFMBase) << "launch cmd by qt:" << cmd << args; - return QProcess::startDetached(cmd, args, wd); - } - - return false; -#endif } int UniversalUtils::dockHeight()