From e6dd4cff3149322d020a059fc6c860c60fe61c20 Mon Sep 17 00:00:00 2001 From: zhaoyingzhen Date: Tue, 25 Oct 2022 15:40:57 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E8=A7=A3=E5=86=B3=E4=BB=BB=E5=8A=A1?= =?UTF-8?q?=E6=A0=8F=E8=B7=A8=E7=AB=AF=E5=8D=8F=E5=90=8C=E5=9C=A8paired?= =?UTF-8?q?=E7=8A=B6=E6=80=81=E5=8F=98=E5=8C=96=E5=90=8E=E4=B8=BB=E5=8A=A8?= =?UTF-8?q?=E8=AF=B7=E6=B1=82=E5=8D=8F=E5=90=8C=E8=BF=9E=E6=8E=A5=E7=9A=84?= =?UTF-8?q?=E9=97=AE=E9=A2=98=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 其他地方操作跨端协同连接导致设备paired状态变化,任务栏跨端协同功能主动请求协同连接后续操作,会导致其他地方操作pair后直接设备共享的问题。 Log: 解决任务栏跨端协同在paired状态变化后主动请求协同连接的问题。 Influence: 任务栏设备协同连接功能。 Change-Id: Ie821de0cb36ad43476c860d5b3721be5a77b0699 --- frame/model/collaborationdevmodel.cpp | 14 +++++++++++--- frame/model/collaborationdevmodel.h | 6 +++++- frame/window/components/devcollaborationwidget.cpp | 4 +++- 3 files changed, 19 insertions(+), 5 deletions(-) diff --git a/frame/model/collaborationdevmodel.cpp b/frame/model/collaborationdevmodel.cpp index a987e1b00..6305ec88a 100644 --- a/frame/model/collaborationdevmodel.cpp +++ b/frame/model/collaborationdevmodel.cpp @@ -126,7 +126,7 @@ void CollaborationDevModel::updateDevice(const QStringList &devPaths) emit devicesChanged(); } -const CollaborationDevice *CollaborationDevModel::getDevice(const QString &machinePath) +CollaborationDevice *CollaborationDevModel::getDevice(const QString &machinePath) { return m_devices.value(machinePath, nullptr); } @@ -138,6 +138,7 @@ CollaborationDevice::CollaborationDevice(const QString &devPath, QObject *parent , m_isPaired(false) , m_isCooperated(false) , m_isValid(false) + , m_isCooperating(false) , m_devDbusInter(new QDBusInterface(CollaborationService, devPath, CollaborationInterface + QString(".Machine"), QDBusConnection::sessionBus(), this)) { @@ -204,6 +205,11 @@ bool CollaborationDevice::isCooperated() const return m_isCooperated; } +void CollaborationDevice::setDeviceIsCooperating(bool isCooperating) +{ + m_isCooperating = isCooperating; +} + void CollaborationDevice::onPropertyChanged(const QDBusMessage &msg) { QList arguments = msg.arguments(); @@ -218,10 +224,12 @@ void CollaborationDevice::onPropertyChanged(const QDBusMessage &msg) if (changedProps.contains("Paired")) { bool isPaired = changedProps.value("Paired").value(); m_isPaired = isPaired; - if (isPaired) { + if (isPaired && m_isCooperating) { // paired 成功之后再去请求cooperate requestCooperate(); - } else { + } + + if (!isPaired){ Q_EMIT pairedStateChanged(false); } } else if (changedProps.contains("Cooperating")) { diff --git a/frame/model/collaborationdevmodel.h b/frame/model/collaborationdevmodel.h index cab4b4db2..013624211 100644 --- a/frame/model/collaborationdevmodel.h +++ b/frame/model/collaborationdevmodel.h @@ -46,7 +46,7 @@ public: void checkServiceValid(); QList devices() const; - const CollaborationDevice *getDevice(const QString &machinePath); + CollaborationDevice *getDevice(const QString &machinePath); private slots: void onPropertyChanged(const QDBusMessage &msg); @@ -86,6 +86,7 @@ public: QString deviceIcon() const; bool isPaired() const; bool isCooperated() const; + void setDeviceIsCooperating(bool isCooperating); private slots: void onPropertyChanged(const QDBusMessage &msg); @@ -112,6 +113,9 @@ private: bool m_isCooperated; bool m_isValid; + // 标记任务栏点击触发协同连接 + bool m_isCooperating; + QDBusInterface *m_devDbusInter; }; diff --git a/frame/window/components/devcollaborationwidget.cpp b/frame/window/components/devcollaborationwidget.cpp index 68ceffd7d..846957e03 100644 --- a/frame/window/components/devcollaborationwidget.cpp +++ b/frame/window/components/devcollaborationwidget.cpp @@ -189,11 +189,12 @@ void DevCollaborationWidget::resetWidgetSize() void DevCollaborationWidget::itemClicked(const QModelIndex &index) { QString machinePath = index.data(DevItemDelegate::MachinePathDataRole).toString(); - const CollaborationDevice *device = m_deviceModel->getDevice(machinePath); + CollaborationDevice *device = m_deviceModel->getDevice(machinePath); if (!device) return; if (!device->isPaired()) { + device->setDeviceIsCooperating(true); device->pair(); if (!m_connectingDevices.contains(machinePath)) m_connectingDevices.append(machinePath); @@ -217,6 +218,7 @@ void DevCollaborationWidget::itemStatusChanged() if (!device) return; + device->setDeviceIsCooperating(false); QString machinePath = device->machinePath(); if (m_deviceItemMap.contains(machinePath) && m_deviceItemMap[machinePath]) { // 更新item的连接状态