From afc9bc49b05864120e2eaf4ab176bbb1b877ac6a Mon Sep 17 00:00:00 2001 From: ck Date: Fri, 10 Nov 2023 14:02:57 +0800 Subject: [PATCH] feat: move ddesktopservices to dtkgui move ddesktopservices from dtkwidget to dtkgui Issue: linuxdeepin/dtk#134 --- include/DWidget/DDesktopServices | 1 - include/util/ddesktopservices.h | 4 +- src/util/ddesktopservices_linux.cpp | 176 ++++------------------------ 3 files changed, 29 insertions(+), 152 deletions(-) delete mode 100644 include/DWidget/DDesktopServices diff --git a/include/DWidget/DDesktopServices b/include/DWidget/DDesktopServices deleted file mode 100644 index 6d5336c39..000000000 --- a/include/DWidget/DDesktopServices +++ /dev/null @@ -1 +0,0 @@ -#include "ddesktopservices.h" diff --git a/include/util/ddesktopservices.h b/include/util/ddesktopservices.h index 4d158b488..50adf27f7 100644 --- a/include/util/ddesktopservices.h +++ b/include/util/ddesktopservices.h @@ -11,7 +11,9 @@ DWIDGET_BEGIN_NAMESPACE -class DDesktopServices +class + D_DECL_DEPRECATED_X("Use Dtk::Gui::DDesktopServices") + DDesktopServices { public: diff --git a/src/util/ddesktopservices_linux.cpp b/src/util/ddesktopservices_linux.cpp index c4a7a119a..90e1e4a4f 100644 --- a/src/util/ddesktopservices_linux.cpp +++ b/src/util/ddesktopservices_linux.cpp @@ -6,245 +6,121 @@ #include #include #include -#if QT_VERSION < QT_VERSION_CHECK(6,0,0) -#include -#endif -DWIDGET_BEGIN_NAMESPACE - -#define EASY_CALL_DBUS(name) \ - QDBusInterface *interface = fileManager1DBusInterface(); \ - return interface && \ - interface->call(#name, urls2uris(urls), startupId).type() != \ - QDBusMessage::ErrorMessage; - -static const QStringList SOUND_EFFECT_LIST { - "message", - "camera-shutter", - "trash-empty", - "x-deepin-app-sent-to-desktop", - "desktop-login", - "system-shutdown", - "desktop-logout", - "suspend-resume", - "audio-volume-change", - "power-unplug-battery-low", - "power-plug", - "power-unplug", - "device-added", - "device-removed", - "dialog-error", -}; - -static QDBusInterface *fileManager1DBusInterface() -{ - static QDBusInterface interface(QStringLiteral("org.freedesktop.FileManager1"), - QStringLiteral("/org/freedesktop/FileManager1"), - QStringLiteral("org.freedesktop.FileManager1")); - return &interface; -} - -static QStringList urls2uris(const QList &urls) -{ - QStringList list; - - list.reserve(urls.size()); - - for (const QUrl &url : urls) { - list << url.toString(); - } - - return list; -} - -static QList path2urls(const QList &paths) -{ - QList list; - - list.reserve(paths.size()); - - for (const QString &path : paths) { - list << QUrl::fromLocalFile(path); - } - - return list; -} - -/*! - \brief Converts \a name from 'key-name' notation - to camel case 'keyName' or 'KeyName'. - This function converts GSettings key names to names - suitable for Qt getters and setters. - - Well fsck this. - - \a name key name - \return key name converted to camel case - \internal - */ -#if QT_VERSION < QT_VERSION_CHECK(6,0,0) -static QString GSettingsKeyToCamelCase(const QString name) -{ - QStringList parts = name.split('-',Qt::SkipEmptyParts); - for (int i=1; i +using DGuiDesktopServices = DTK_GUI_NAMESPACE::DDesktopServices; +using DGuiSystemSoundEffect = DGuiDesktopServices::SystemSoundEffect; - const bool effEnabled = settings.get("enabled").toBool(); - QString newName = GSettingsKeyToCamelCase(name); - - if (effEnabled) { - const QStringList list = settings.keys(); - if (!list.contains(newName)) { - return false; - } - - return settings.get(newName).toBool(); - } - - return effEnabled; -#else - return false; -#endif -} +DWIDGET_BEGIN_NAMESPACE bool DDesktopServices::showFolder(QString localFilePath, const QString &startupId) { - return showFolder(QUrl::fromLocalFile(localFilePath), startupId); + return DGuiDesktopServices::showFolder(localFilePath, startupId); } bool DDesktopServices::showFolders(const QList localFilePaths, const QString &startupId) { - return showFolders(path2urls(localFilePaths), startupId); + return DGuiDesktopServices::showFolders(localFilePaths, startupId); } bool DDesktopServices::showFolder(QUrl url, const QString &startupId) { - return showFolders(QList() << url, startupId); + return DGuiDesktopServices::showFolder(url, startupId); } bool DDesktopServices::showFolders(const QList urls, const QString &startupId) { - EASY_CALL_DBUS(ShowFolders) + return DGuiDesktopServices::showFolders(urls, startupId); } bool DDesktopServices::showFileItemPropertie(QString localFilePath, const QString &startupId) { - return showFileItemPropertie(QUrl::fromLocalFile(localFilePath), startupId); + return DGuiDesktopServices::showFileItemPropertie(localFilePath , startupId); } bool DDesktopServices::showFileItemProperties(const QList localFilePaths, const QString &startupId) { - return showFileItemProperties(path2urls(localFilePaths), startupId); + return DGuiDesktopServices::showFileItemProperties(localFilePaths, startupId); } bool DDesktopServices::showFileItemPropertie(QUrl url, const QString &startupId) { - return showFileItemProperties(QList() << url, startupId); + return DGuiDesktopServices::showFileItemPropertie(url, startupId); } bool DDesktopServices::showFileItemProperties(const QList urls, const QString &startupId) { - EASY_CALL_DBUS(ShowItemProperties) + return DGuiDesktopServices::showFileItemProperties(urls, startupId); } bool DDesktopServices::showFileItem(QString localFilePath, const QString &startupId) { - return showFileItem(QUrl::fromLocalFile(localFilePath), startupId); + return DGuiDesktopServices::showFileItem(localFilePath, startupId); } bool DDesktopServices::showFileItems(const QList localFilePaths, const QString &startupId) { - return showFileItems(path2urls(localFilePaths), startupId); + return DGuiDesktopServices::showFileItems(localFilePaths, startupId); } bool DDesktopServices::showFileItem(QUrl url, const QString &startupId) { - return showFileItems(QList() << url, startupId); + return DGuiDesktopServices::showFileItem(url, startupId); } bool DDesktopServices::showFileItems(const QList urls, const QString &startupId) { - EASY_CALL_DBUS(ShowItems) + return DGuiDesktopServices::showFileItems(urls, startupId); } bool DDesktopServices::trash(QString localFilePath) { - return trash(QUrl::fromLocalFile(localFilePath)); + return DGuiDesktopServices::trash(localFilePath); } bool DDesktopServices::trash(const QList localFilePaths) { - return trash(path2urls(localFilePaths)); + return DGuiDesktopServices::trash(localFilePaths); } bool DDesktopServices::trash(QUrl url) { - return trash(QList() << url); + return DGuiDesktopServices::trash(url); } bool DDesktopServices::trash(const QList urls) { - QDBusInterface *interface = fileManager1DBusInterface(); - return interface && interface->call("Trash", urls2uris(urls)).type() != QDBusMessage::ErrorMessage; + return DGuiDesktopServices::trash(urls); } bool DDesktopServices::playSystemSoundEffect(const DDesktopServices::SystemSoundEffect &effect) { - return playSystemSoundEffect(SOUND_EFFECT_LIST.at(static_cast(effect))); + return DGuiDesktopServices::playSystemSoundEffect(DGuiSystemSoundEffect(effect)); } bool DDesktopServices::playSystemSoundEffect(const QString &name) { - if (!systemSoundEffectEnabled(name)) { - return false; - } - - return previewSystemSoundEffect(name); + return DGuiDesktopServices::playSystemSoundEffect(name); } bool DDesktopServices::previewSystemSoundEffect(const DDesktopServices::SystemSoundEffect &effect) { - return previewSystemSoundEffect(SOUND_EFFECT_LIST.at(static_cast(effect))); + return DGuiDesktopServices::previewSystemSoundEffect(DGuiSystemSoundEffect(effect)); } bool DDesktopServices::previewSystemSoundEffect(const QString &name) { - if (name.isEmpty()) { - return false; - } - -#if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0) - const auto& infc = QDBusConnection::sessionBus().interface(); - QStringList activatableServiceNames = infc->activatableServiceNames(); - bool isNewInterface = activatableServiceNames.contains(QLatin1String("org.deepin.dde.SoundEffect1")); -#else - bool isNewInterface = false; // Qt 5.14 以下就直接用旧的接口 -#endif - const QLatin1String service(isNewInterface ? "org.deepin.dde.SoundEffect1" :"com.deepin.daemon.SoundEffect"); - const QLatin1String path(isNewInterface ? "/org/deepin/dde/SoundEffect1" : "/com/deepin/daemon/SoundEffect"); - const QLatin1String interface(isNewInterface ? "org.deepin.dde.SoundEffect1" :"com.deepin.daemon.SoundEffect"); - - // 使用后端 dbus 接口播放系统音频,音频存放目录: /usr/share/sounds/deepin/stereo/ - return QDBusInterface(service, path, interface).call("PlaySound", name).type() != QDBusMessage::ErrorMessage; + return DGuiDesktopServices::previewSystemSoundEffect(name); } QString DDesktopServices::getNameByEffectType(const DDesktopServices::SystemSoundEffect &effect) { - return SOUND_EFFECT_LIST.at(static_cast(effect)); + return DGuiDesktopServices::getNameByEffectType(DGuiSystemSoundEffect(effect)); } QString DDesktopServices::errorMessage() { - return fileManager1DBusInterface()->lastError().message(); + return DGuiDesktopServices::errorMessage(); } DWIDGET_END_NAMESPACE