diff options
author | Martin Kampas <martin.kampas@jolla.com> | 2016-11-16 16:07:09 +0100 |
---|---|---|
committer | Juergen Bocklage-Ryannel <juergen.bocklage-ryannel@pelagicore.com> | 2016-11-23 07:17:39 +0000 |
commit | a5851207bb3c606ec46e3683da1d0c6befbe7138 (patch) | |
tree | bb2cc028199a44d4da9ed371bdb9a2bab08f110b | |
parent | 3fcebb918fc5aea49eda78c74a92807fa3c6597d (diff) |
Improve active document handling
- Let bench display the actual host's active document
- Do not reload active document unnecesarily (especially when connection
with host is established)
- Clearly separate the effect of each host action:
- "Online/Offline" button allows to connect/disconnect. It does not
reload active document. It loads different document only when
follow-tree-selection is enabled.
- Similar applies to auto-connect on Bench startup or using
'qmllivebench --probe HOST'
- "Reload" button allows to reload active document. It is not
enabled unless the host is online and it has an active document.
- "Upload" button allows to upload whole workspace. It is not
enabled unless the host is online
- Toggled-on the "Follow" button immediately loads the currently
selected document unless it it already host's active document (it
does not reload).
- It is automatically toggled-off when a document is dropped onto
the host widget.
- Include necessary fixes to host's online state tracking.
Change-Id: I4f270f95eb9a52adda9b484b9bd776725df8ff60
Reviewed-by: Juergen Bocklage-Ryannel <juergen.bocklage-ryannel@pelagicore.com>
-rw-r--r-- | src/bench/host.cpp | 2 | ||||
-rw-r--r-- | src/bench/hostwidget.cpp | 104 | ||||
-rw-r--r-- | src/bench/hostwidget.h | 3 | ||||
-rw-r--r-- | src/livenodeengine.cpp | 4 | ||||
-rw-r--r-- | src/livenodeengine.h | 2 | ||||
-rw-r--r-- | src/remotepublisher.cpp | 20 | ||||
-rw-r--r-- | src/remotepublisher.h | 1 | ||||
-rw-r--r-- | src/remotereceiver.cpp | 16 | ||||
-rw-r--r-- | src/remotereceiver.h | 1 |
9 files changed, 112 insertions, 41 deletions
diff --git a/src/bench/host.cpp b/src/bench/host.cpp index 27aad11..2103e43 100644 --- a/src/bench/host.cpp +++ b/src/bench/host.cpp @@ -215,7 +215,6 @@ void Host::saveToSettings(QSettings *s) s->setValue("xOffset", xOffset()); s->setValue("yOffset", yOffset()); s->setValue("rotation", rotation()); - s->setValue("currentFile", currentFile().relativeFilePath()); s->setValue("autoDiscoveryId", autoDiscoveryId().toString()); s->setValue("systemName", systemName()); s->setValue("productVersion", productVersion()); @@ -233,7 +232,6 @@ void Host::restoreFromSettings(QSettings *s) setXOffset(s->value("xOffset").toInt()); setYOffset(s->value("yOffset").toInt()); setRotation(s->value("rotation").toInt()); - setCurrentFile(LiveDocument(s->value("currentFile").toString())); setAutoDiscoveryId(QUuid(s->value("autoDiscoveryId").toString())); setSystemName(s->value("systemName").toString()); setProductVersion(s->value("productVersion").toString()); diff --git a/src/bench/hostwidget.cpp b/src/bench/hostwidget.cpp index 032eb41..25247e5 100644 --- a/src/bench/hostwidget.cpp +++ b/src/bench/hostwidget.cpp @@ -36,6 +36,9 @@ #include <QMessageBox> +Q_DECLARE_LOGGING_CATEGORY(csLog) +Q_LOGGING_CATEGORY(csLog, "QmlLive.Bench.ConnectionState", QtWarningMsg) + const int LABEL_STACK_INDEX=0; const int PROGRESS_STACK_INDEX=1; @@ -47,7 +50,7 @@ HostWidget::HostWidget(QWidget *parent) : m_connectDisconnectAction = new QAction("Offline", this); m_connectDisconnectAction->setIcon(QIcon(":images/error_ball.svg")); - connect(m_connectDisconnectAction, SIGNAL(triggered(bool)), this, SLOT(connectAndSendFile())); + connect(m_connectDisconnectAction, SIGNAL(triggered(bool)), this, SLOT(connectToServer())); m_refreshAction = new QAction("Refresh", this); m_refreshAction->setIcon(QIcon(":images/refresh.svg")); @@ -114,8 +117,6 @@ HostWidget::HostWidget(QWidget *parent) : connect(&m_publisher, SIGNAL(remoteLog(int,QString,QUrl,int,int)), this, SIGNAL(remoteLog(int,QString,QUrl,int,int))); connect(&m_publisher, SIGNAL(clearLog()), this, SIGNAL(clearLog())); - - onDisconnected(); } void HostWidget::setHost(Host *host) @@ -124,7 +125,6 @@ void HostWidget::setHost(Host *host) updateTitle(); updateFile(m_host->currentFile()); - updateAvailableState(m_host->available()); m_followTreeSelectionAction->setChecked(m_host->followTreeSelection()); connect(host, SIGNAL(addressChanged(QString)), this, SLOT(updateTitle())); @@ -141,6 +141,10 @@ void HostWidget::setHost(Host *host) this, SLOT(updateFollowTreeSelection(bool))); connect(m_followTreeSelectionAction, SIGNAL(triggered(bool)), host, SLOT(setFollowTreeSelection(bool))); + connect(&m_publisher, SIGNAL(activeDocumentChanged(LiveDocument)), m_host, SLOT(setCurrentFile(LiveDocument))); + + updateAvailableState(m_host->available()); + updateRemoteActions(); } void HostWidget::setLiveHubEngine(LiveHubEngine *engine) @@ -159,7 +163,10 @@ void HostWidget::setLiveHubEngine(LiveHubEngine *engine) void HostWidget::setCurrentFile(const LiveDocument ¤tFile) { - m_host->setCurrentFile(currentFile); + if (m_publisher.state() != QAbstractSocket::ConnectedState) + return; + + m_publisher.activateDocument(currentFile); } bool HostWidget::followTreeSelection() const @@ -177,21 +184,18 @@ void HostWidget::updateTitle() void HostWidget::updateFile(const LiveDocument &file) { - setUpdateFile(file); - - connectAndSendFile(); -} - -void HostWidget::setUpdateFile(const LiveDocument &file) -{ QFont font(this->font()); QPalette palette(this->palette()); QString text; QString toolTip; if (file.isNull()) { - text = tr("No active document"); - toolTip = tr("No active document. Drop one."); + if (m_publisher.state() != QAbstractSocket::ConnectedState) { + text = tr("Host offline"); + } else { + text = tr("No active document"); + toolTip = tr("No active document. Drop one."); + } font.setItalic(true); } else { text = file.relativeFilePath(); @@ -211,18 +215,23 @@ void HostWidget::setUpdateFile(const LiveDocument &file) m_documentLabel->setText(metrics.elidedText(text, Qt::ElideLeft, m_documentLabel->width())); m_documentLabel->setToolTip(toolTip); + + if (m_host->followTreeSelection() && !file.isNull() && file != m_engine->activePath()) { + if (m_publisher.state() == QAbstractSocket::ConnectedState) + m_publisher.activateDocument(m_engine->activePath()); + } + + updateRemoteActions(); } void HostWidget::refreshDocumentLabel() { - if (!m_host) - return; - setUpdateFile(m_host->currentFile()); + updateFile(m_host->currentFile()); } void HostWidget::updateAvailableState(bool available) { - qDebug() << "updateAvailableState"; + qCDebug(csLog) << "updateAvailableState()" << available; if (available) scheduleConnectToServer(); @@ -234,22 +243,33 @@ void HostWidget::updateFollowTreeSelection(bool follow) { m_followTreeSelectionAction->setChecked(follow); - if (follow) - m_host->setCurrentFile(m_engine->activePath()); + if (follow && m_publisher.state() == QAbstractSocket::ConnectedState + && m_host->currentFile() != m_engine->activePath()) { + m_publisher.activateDocument(m_engine->activePath()); + } +} + +void HostWidget::updateRemoteActions() +{ + m_refreshAction->setEnabled(m_publisher.state() == QAbstractSocket::ConnectedState + && !m_host->currentFile().isNull()); + m_publishAction->setEnabled(m_publisher.state() == QAbstractSocket::ConnectedState); } void HostWidget::scheduleConnectToServer() { + qCDebug(csLog) << "scheduleConnectToServer()" << m_host->name(); + m_connectToServerTimer.start(0, this); } void HostWidget::connectToServer() { - qDebug() << "connectToServer"; + qCDebug(csLog) << "connectToServer()" << m_host->name() + << m_publisher.state() << "available:" << m_host->available(); - if (m_publisher.state() == QAbstractSocket::ConnectedState || m_publisher.state() == QAbstractSocket::ConnectingState) { + if (m_publisher.state() != QAbstractSocket::UnconnectedState) return; - } if (m_host->available()) { m_publisher.connectToServer(m_host->address(), m_host->port()); @@ -261,19 +281,17 @@ void HostWidget::connectToServer() } } -void HostWidget::connectAndSendFile() -{ - connectToServer(); - if (!m_host->currentFile().isNull()) - m_activateId = m_publisher.activateDocument(m_host->currentFile()); -} - void HostWidget::onConnected() { + qCDebug(csLog) << "Host connected:" << m_host->name(); + m_connectDisconnectAction->setIcon(QIcon(":images/okay_ball.svg")); m_connectDisconnectAction->setToolTip("Host online"); m_connectDisconnectAction->setText("Online"); + updateFile(m_host->currentFile()); + updateRemoteActions(); + sendXOffset(m_host->xOffset()); sendYOffset(m_host->yOffset()); sendRotation(m_host->rotation()); @@ -284,17 +302,24 @@ void HostWidget::onConnected() void HostWidget::onDisconnected() { + qCDebug(csLog) << "Host disconnected:" << m_host->name(); + m_connectDisconnectAction->setIcon(QIcon(":images/error_ball.svg")); m_connectDisconnectAction->setToolTip("Host Offline"); m_connectDisconnectAction->setText("Offline"); resetProgressBar(); + m_host->setCurrentFile(LiveDocument()); + updateRemoteActions(); + disconnect(m_connectDisconnectAction, SIGNAL(triggered()), 0, 0); connect(m_connectDisconnectAction, SIGNAL(triggered()), this, SLOT(connectToServer())); } void HostWidget::onConnectionError(QAbstractSocket::SocketError error) { + qCDebug(csLog) << "Host connection error:" << m_host->name() << error; + m_connectDisconnectAction->setToolTip(m_publisher.errorToString(error)); m_connectDisconnectAction->setIcon(QIcon(":images/warning_ball.svg")); @@ -307,7 +332,11 @@ void HostWidget::onConnectionError(QAbstractSocket::SocketError error) void HostWidget::refresh() { - connectAndSendFile(); + if (m_publisher.state() != QAbstractSocket::ConnectedState) + return; + + if (!m_host->currentFile().isNull()) + m_publisher.activateDocument(m_host->currentFile()); } void HostWidget::probe() @@ -317,7 +346,9 @@ void HostWidget::probe() void HostWidget::publishWorkspace() { - connectToServer(); + if (m_publisher.state() != QAbstractSocket::ConnectedState) + return; + connect(m_engine.data(), SIGNAL(publishFile(LiveDocument)), this, SLOT(sendDocument(LiveDocument))); m_engine->publishWorkspace(); disconnect(m_engine.data(), SIGNAL(publishFile(LiveDocument)), this, SLOT(sendDocument(LiveDocument))); @@ -448,7 +479,7 @@ void HostWidget::showPinDialog() void HostWidget::dragEnterEvent(QDragEnterEvent *event) { - if (!m_host->available()) + if (m_publisher.state() != QAbstractSocket::ConnectedState) return; if (event->mimeData()->hasFormat("text/uri-list")) @@ -457,13 +488,18 @@ void HostWidget::dragEnterEvent(QDragEnterEvent *event) void HostWidget::dropEvent(QDropEvent *event) { + if (m_publisher.state() != QAbstractSocket::ConnectedState) + return; + event->acceptProposedAction(); QUrl url(event->mimeData()->text()); if (url.isLocalFile()) { LiveDocument document = LiveDocument::resolve(m_engine->workspace(), url.toLocalFile()); if (!document.isNull() && document.isFileIn(m_engine->workspace())) { - m_host->setCurrentFile(document); + if (m_host->followTreeSelection() && document != m_engine->activePath()) + m_host->setFollowTreeSelection(false); + m_publisher.activateDocument(document); } else { QMessageBox::warning(this, tr("Not a workspace document"), tr("The dropped document is not a file in the current workspace:<br/>%1") diff --git a/src/bench/hostwidget.h b/src/bench/hostwidget.h index 1cae316..7bb3366 100644 --- a/src/bench/hostwidget.h +++ b/src/bench/hostwidget.h @@ -69,14 +69,13 @@ protected: private slots: void updateTitle(); void updateFile(const LiveDocument& file); - void setUpdateFile(const LiveDocument& file); void refreshDocumentLabel(); void updateAvailableState(bool available); void updateFollowTreeSelection(bool follow); + void updateRemoteActions(); void scheduleConnectToServer(); void connectToServer(); - void connectAndSendFile(); void onConnected(); void onDisconnected(); diff --git a/src/livenodeengine.cpp b/src/livenodeengine.cpp index ff1fab8..b72917b 100644 --- a/src/livenodeengine.cpp +++ b/src/livenodeengine.cpp @@ -500,7 +500,7 @@ QUrl LiveNodeEngine::queryDocumentViewer(const QUrl& url) void LiveNodeEngine::setActiveDocument(const LiveDocument &document) { loadDocument(document); - emit activateDocument(document); + emit activeDocumentChanged(document); } /*! @@ -647,7 +647,7 @@ void LiveNodeEngine::onSizeChanged() } /*! - * \fn void LiveNodeEngine::activateDocument(const LiveDocument& document) + * \fn void LiveNodeEngine::activeDocumentChanged(const LiveDocument& document) * * The document \a document was activated */ diff --git a/src/livenodeengine.h b/src/livenodeengine.h index 2b16489..c7ddc16 100644 --- a/src/livenodeengine.h +++ b/src/livenodeengine.h @@ -95,7 +95,7 @@ public Q_SLOTS: void updateDocument(const LiveDocument &document, const QByteArray &content); Q_SIGNALS: - void activateDocument(const LiveDocument& document); + void activeDocumentChanged(const LiveDocument& document); void clearLog(); void logIgnoreMessages(bool on); void documentLoaded(); diff --git a/src/remotepublisher.cpp b/src/remotepublisher.cpp index 08908a8..7bba61d 100644 --- a/src/remotepublisher.cpp +++ b/src/remotepublisher.cpp @@ -296,6 +296,19 @@ void RemotePublisher::handleCall(const QString &method, const QByteArray &conten emit remoteLog(msgType, description, url, line, column); } else if (method == "clearLog()") { emit clearLog(); + } else if (method == "activeDocumentChanged(QString)") { + QString path; + + QDataStream in(content); + in >> path; + + if (path.isEmpty() || !QDir::isRelativePath(path)) { + qCritical() << "Invalid argument to remote call activeDocumentChanged." + << "Relative file path expected:" << path; + return; + } + + emit activeDocumentChanged(LiveDocument(path)); } } @@ -352,6 +365,13 @@ void RemotePublisher::handleCall(const QString &method, const QByteArray &conten * to indicate the client asks for (re)sending all workspace documents. */ +/*! + * \fn RemotePublisher::activeDocumentChanged(const LiveDocument &document) + * + * The signal is emitted after receiving the activeDocumentChanged IPC call, + * to indicate the client's active \a document has changed. + */ + /*! \fn RemotePublisher::sentSuccessfully(const QUuid& uuid) * * The signal is emitted after the package identified by \a uuid has been send diff --git a/src/remotepublisher.h b/src/remotepublisher.h index 9df2601..13840f4 100644 --- a/src/remotepublisher.h +++ b/src/remotepublisher.h @@ -58,6 +58,7 @@ Q_SIGNALS: void connectionError(QAbstractSocket::SocketError error); void needsPinAuthentication(); void needsPublishWorkspace(); + void activeDocumentChanged(const LiveDocument &document); void pinOk(bool ok); void remoteLog(int type, const QString &msg, const QUrl &url = QUrl(), int line = -1, int column = -1); void clearLog(); diff --git a/src/remotereceiver.cpp b/src/remotereceiver.cpp index 7dbdb36..e871399 100644 --- a/src/remotereceiver.cpp +++ b/src/remotereceiver.cpp @@ -251,6 +251,7 @@ void RemoteReceiver::registerNode(LiveNodeEngine *node) m_node = node; connect(m_node, SIGNAL(logErrors(QList<QQmlError>)), this, SLOT(appendToLog(QList<QQmlError>))); connect(m_node, SIGNAL(clearLog()), this, SLOT(clearLog())); + connect(m_node, SIGNAL(activeDocumentChanged(LiveDocument)), this, SLOT(onActiveDocumentChanged(LiveDocument))); connect(this, SIGNAL(activateDocument(LiveDocument)), m_node, SLOT(setActiveDocument(LiveDocument))); connect(this, SIGNAL(updateDocument(LiveDocument,QByteArray)), m_node, SLOT(updateDocument(LiveDocument,QByteArray))); connect(this, SIGNAL(xOffsetChanged(int)), m_node, SLOT(setXOffset(int))); @@ -306,6 +307,9 @@ void RemoteReceiver::maybeStartUpdateDocumentsOnConnect() void RemoteReceiver::finishConnectionInitialization() { + if (!m_node->activeDocument().isNull()) + onActiveDocumentChanged(m_node->activeDocument()); + m_logSentPosition = 0; flushLog(); } @@ -363,6 +367,18 @@ void RemoteReceiver::clearLog() } /*! + * Called to notify bench about active document change + */ +void RemoteReceiver::onActiveDocumentChanged(const LiveDocument &document) +{ + QByteArray bytes; + QDataStream out(&bytes, QIODevice::WriteOnly); + out << document.relativeFilePath(); + + m_client->send("activeDocumentChanged(QString)", bytes); +} + +/*! * \fn void RemoteReceiver::activateDocument(const LiveDocument& document) * * This signal is emitted when the remote active document \a document has changed diff --git a/src/remotereceiver.h b/src/remotereceiver.h index b67d22d..4309a30 100644 --- a/src/remotereceiver.h +++ b/src/remotereceiver.h @@ -99,6 +99,7 @@ private Q_SLOTS: void appendToLog(const QList<QQmlError> &errors); void clearLog(); + void onActiveDocumentChanged(const LiveDocument &document); void onClientConnected(QTcpSocket *socket); void onClientDisconnected(QTcpSocket *socket); |