Skip to content

Commit

Permalink
chore: [dbus] Adapt V25 dde-file-manager dbus service name changed
Browse files Browse the repository at this point in the history
   Adapt V25 dde-file-manager dbus service name changed

Log: Adapt V25 dde-file-manager dbus service name changed
  • Loading branch information
starhcq committed Sep 5, 2024
1 parent cfb717b commit d368b44
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 9 deletions.
8 changes: 8 additions & 0 deletions src/src/unionimage/baseutils.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,14 @@
#include <QTimer>
#include <QColor>

#define V23_FILEMANAGER_DAEMON_SERVICE "org.deepin.filemanager.server"
#define V23_FILEMANAGER_DAEMON_PATH "/org/deepin/filemanager/server/DeviceManager"
#define V23_FILEMANAGER_DAEMON_INTERFACE "org.deepin.filemanager.server.DeviceManager"

#define V25_FILEMANAGER_DAEMON_SERVICE "org.deepin.Filemanager.Daemon"
#define V25_FILEMANAGER_DAEMON_PATH "/org/deepin/Filemanager/Daemon/DeviceManager"
#define V25_FILEMANAGER_DAEMON_INTERFACE "org.deepin.Filemanager.Daemon.DeviceManager"

/*!
\brief 拷贝自 dde-file-manager 代码,看图中仅使用 kRemovable 访问可能被卸载的设备
*/
Expand Down
22 changes: 19 additions & 3 deletions src/src/utils/devicehelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,14 @@
#include "devicehelper.h"
#include "unionimage/baseutils.h"
#include <dfm-mount/base/dmount_global.h>
#include <DSysInfo>

#include <QDBusReply>
#include <QDebug>
#include <QRegularExpression>

DCORE_USE_NAMESPACE

DeviceHelper *DeviceHelper::m_instance = nullptr;
using namespace dfmmount;

Expand All @@ -22,9 +26,21 @@ DeviceHelper::DeviceHelper(QObject *parent)
: QObject(parent)
{
// DFM 设备管理接口,访问文件挂载信息
m_dfmDeviceManager.reset(new QDBusInterface(QStringLiteral("org.deepin.filemanager.server"),
QStringLiteral("/org/deepin/filemanager/server/DeviceManager"),
QStringLiteral("org.deepin.filemanager.server.DeviceManager")));
if (DSysInfo::majorVersion() == "25") {
m_dfmDeviceManager.reset(new QDBusInterface(QStringLiteral(V25_FILEMANAGER_DAEMON_SERVICE),
QStringLiteral(V25_FILEMANAGER_DAEMON_PATH),
QStringLiteral(V25_FILEMANAGER_DAEMON_INTERFACE)));
} else {
m_dfmDeviceManager.reset(new QDBusInterface(QStringLiteral(V23_FILEMANAGER_DAEMON_SERVICE),
QStringLiteral(V23_FILEMANAGER_DAEMON_PATH),
QStringLiteral(V23_FILEMANAGER_DAEMON_INTERFACE)));
}

qInfo() << "m_dfmDeviceManager: majorVersion:" << DSysInfo::majorVersion()
<< "dbus service:" << m_dfmDeviceManager.data()->service()
<< "interface:" << m_dfmDeviceManager.data()->interface()
<< "object:" << m_dfmDeviceManager.data()->objectName()
<< "path:" << m_dfmDeviceManager.data()->path();
}

DeviceHelper::~DeviceHelper()
Expand Down
18 changes: 13 additions & 5 deletions src/src/utils/filetrashhelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "filetrashhelper.h"
#include "imagedata/imagefilewatcher.h"
#include "unionimage/baseutils.h"
#include <DSysInfo>

#include <QApplication>
#include <QDBusReply>
Expand All @@ -13,6 +14,7 @@
#include <QFileSystemWatcher>
#include <QRegularExpression>

DCORE_USE_NAMESPACE
/*!
\class FileTrashHelper::FileTrashHelper
\brief 文件回收站辅助类
Expand All @@ -23,9 +25,15 @@ FileTrashHelper::FileTrashHelper(QObject *parent)
: QObject(parent)
{
// DFM 设备管理接口,访问文件挂载信息
dfmDeviceManager.reset(new QDBusInterface(QStringLiteral("org.deepin.filemanager.server"),
QStringLiteral("/org/deepin/filemanager/server/DeviceManager"),
QStringLiteral("org.deepin.filemanager.server.DeviceManager")));
if (DSysInfo::majorVersion() == "25") {
m_dfmDeviceManager.reset(new QDBusInterface(QStringLiteral(V25_FILEMANAGER_DAEMON_SERVICE),
QStringLiteral(V25_FILEMANAGER_DAEMON_PATH),
QStringLiteral(V25_FILEMANAGER_DAEMON_INTERFACE)));
} else {
m_dfmDeviceManager.reset(new QDBusInterface(QStringLiteral(V23_FILEMANAGER_DAEMON_SERVICE),
QStringLiteral(V23_FILEMANAGER_DAEMON_PATH),
QStringLiteral(V23_FILEMANAGER_DAEMON_INTERFACE)));
}
}

/*!
Expand Down Expand Up @@ -114,15 +122,15 @@ void FileTrashHelper::queryMountInfo()

// 调用 DBus 接口查询可被卸载设备信息
// GetBlockDevicesIdList(int opts)
QDBusReply<QStringList> deviceListReply = dfmDeviceManager->call("GetBlockDevicesIdList", kRemovable);
QDBusReply<QStringList> deviceListReply = m_dfmDeviceManager->call("GetBlockDevicesIdList", kRemovable);
if (!deviceListReply.isValid()) {
qWarning() << qPrintable("DBus call GetBlockDevicesIdList failed") << deviceListReply.error().message();
return;
}

for (const QString &id : deviceListReply.value()) {
// QueryBlockDeviceInfo(const QString &id, bool reload)
QDBusReply<QVariantMap> deviceReply = dfmDeviceManager->call("QueryBlockDeviceInfo", id, false);
QDBusReply<QVariantMap> deviceReply = m_dfmDeviceManager->call("QueryBlockDeviceInfo", id, false);
if (!deviceReply.isValid()) {
qWarning() << qPrintable("DBus call QueryBlockDeviceInfo failed") << deviceReply.error().message();
continue;
Expand Down
2 changes: 1 addition & 1 deletion src/src/utils/filetrashhelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class FileTrashHelper : public QObject
bool moveFileToTrashWithDBus(const QUrl &url);

private:
QScopedPointer<QDBusInterface> dfmDeviceManager;
QScopedPointer<QDBusInterface> m_dfmDeviceManager;

bool initData { false }; // 挂载数据是否被初始化
QDir lastDir; // 上一次访问的文件目录
Expand Down

0 comments on commit d368b44

Please sign in to comment.