From 364b4370f7712021a54e418a14cbc88f226e518b Mon Sep 17 00:00:00 2001 From: Martin Kampas Date: Wed, 16 Nov 2016 09:30:41 +0100 Subject: Bench: Encapsulate host's available state in Host class Change-Id: I7379bfe0c570f0bf9129f4eded1c136c71781057 Reviewed-by: Juergen Bocklage-Ryannel --- src/bench/host.cpp | 7 +++++++ src/bench/host.h | 3 +++ src/bench/hostwidget.cpp | 17 ++++++++--------- src/bench/hostwidget.h | 2 +- 4 files changed, 19 insertions(+), 10 deletions(-) diff --git a/src/bench/host.cpp b/src/bench/host.cpp index fc54513..27aad11 100644 --- a/src/bench/host.cpp +++ b/src/bench/host.cpp @@ -144,6 +144,8 @@ void Host::setOnline(bool arg) if (m_online != arg) { m_online = arg; emit onlineChanged(arg); + if (m_type == AutoDiscovery) + emit availableChanged(arg); } } @@ -191,6 +193,11 @@ bool Host::online() const return m_online; } +bool Host::available() const +{ + return m_type == Manual || m_online; +} + bool Host::followTreeSelection() const { return m_followTreeSelection; diff --git a/src/bench/host.h b/src/bench/host.h index e04b4a8..0e7d1bb 100644 --- a/src/bench/host.h +++ b/src/bench/host.h @@ -58,6 +58,7 @@ public: Q_PROPERTY(int yOffset READ yOffset WRITE setYOffset NOTIFY yOffsetChanged) Q_PROPERTY(int rotation READ rotation WRITE setRotation NOTIFY rotationChanged) Q_PROPERTY(bool online READ online WRITE setOnline NOTIFY onlineChanged) + Q_PROPERTY(bool available READ available NOTIFY availableChanged) Q_PROPERTY(bool followTreeSelection READ followTreeSelection WRITE setFollowTreeSelection NOTIFY followTreeSelectionChanged) Q_PROPERTY(QUuid autoDiscoveryId READ autoDiscoveryId WRITE setAutoDiscoveryId NOTIFY autoDiscoveryIdChanged) Q_PROPERTY(QString productVersion READ productVersion WRITE setProductVersion) @@ -76,6 +77,7 @@ public: Type type() const; bool online() const; + bool available() const; bool followTreeSelection() const; QUuid autoDiscoveryId() const; QString productVersion() const; @@ -95,6 +97,7 @@ signals: void yOffsetChanged(int arg); void rotationChanged(int arg); void onlineChanged(bool arg); + void availableChanged(bool arg); void followTreeSelectionChanged(bool arg); void autoDiscoveryIdChanged(QUuid arg); diff --git a/src/bench/hostwidget.cpp b/src/bench/hostwidget.cpp index 4341eb9..032eb41 100644 --- a/src/bench/hostwidget.cpp +++ b/src/bench/hostwidget.cpp @@ -124,14 +124,14 @@ void HostWidget::setHost(Host *host) updateTitle(); updateFile(m_host->currentFile()); - updateOnlineState(m_host->online()); + updateAvailableState(m_host->available()); m_followTreeSelectionAction->setChecked(m_host->followTreeSelection()); connect(host, SIGNAL(addressChanged(QString)), this, SLOT(updateTitle())); connect(host, SIGNAL(addressChanged(QString)), this, SLOT(scheduleConnectToServer())); connect(host, SIGNAL(portChanged(int)), this, SLOT(updateTitle())); connect(host, SIGNAL(portChanged(int)), this, SLOT(scheduleConnectToServer())); - connect(host, SIGNAL(onlineChanged(bool)), this, SLOT(updateOnlineState(bool))); + connect(host, SIGNAL(availableChanged(bool)), this, SLOT(updateAvailableState(bool))); connect(host, SIGNAL(currentFileChanged(LiveDocument)), this, SLOT(updateFile(LiveDocument))); connect(host, SIGNAL(nameChanged(QString)), this, SLOT(updateTitle())); connect(host, SIGNAL(xOffsetChanged(int)), this, SLOT(sendXOffset(int))); @@ -220,11 +220,9 @@ void HostWidget::refreshDocumentLabel() setUpdateFile(m_host->currentFile()); } -void HostWidget::updateOnlineState(bool online) +void HostWidget::updateAvailableState(bool available) { - qDebug() << "updateOnline"; - - bool available = online || m_host->type() == Host::Manual; + qDebug() << "updateAvailableState"; if (available) scheduleConnectToServer(); @@ -253,7 +251,7 @@ void HostWidget::connectToServer() return; } - if (m_host->online() || m_host->type() == Host::Manual) { + if (m_host->available()) { m_publisher.connectToServer(m_host->address(), m_host->port()); m_activateId = QUuid(); m_rotationId = QUuid(); @@ -450,10 +448,11 @@ void HostWidget::showPinDialog() void HostWidget::dragEnterEvent(QDragEnterEvent *event) { - if (event->mimeData()->hasFormat("text/uri-list") && (m_host->online() || m_host->type() == Host::Manual)) { + if (!m_host->available()) + return; + if (event->mimeData()->hasFormat("text/uri-list")) event->acceptProposedAction(); - } } void HostWidget::dropEvent(QDropEvent *event) diff --git a/src/bench/hostwidget.h b/src/bench/hostwidget.h index 1867932..1cae316 100644 --- a/src/bench/hostwidget.h +++ b/src/bench/hostwidget.h @@ -71,7 +71,7 @@ private slots: void updateFile(const LiveDocument& file); void setUpdateFile(const LiveDocument& file); void refreshDocumentLabel(); - void updateOnlineState(bool online); + void updateAvailableState(bool available); void updateFollowTreeSelection(bool follow); void scheduleConnectToServer(); -- cgit v1.2.3