From 4a00e0e7dca9adf2e09ca392a8b0305b1ccbfc69 Mon Sep 17 00:00:00 2001 From: Eike Hein Date: Sun, 15 Dec 2024 09:16:26 +0100 Subject: [PATCH] Render shelf as if disabled during connection process Instead of displaying nothing (i.e. the unobscured window background behind the shelf), render the shelf as if disabled before we have a connection and initial data. Going from disabled to the true state is less jarring and visually more pleasing than briefly flashing white. --- src/declarative/Gui.qml | 25 ++++++++++++++++++++----- src/remoteshelfmodel.cpp | 21 +++++++++++++-------- src/remoteshelfmodel.h | 34 +++++++++++++++++----------------- 3 files changed, 50 insertions(+), 30 deletions(-) diff --git a/src/declarative/Gui.qml b/src/declarative/Gui.qml index a6fbf72..ea833e9 100755 --- a/src/declarative/Gui.qml +++ b/src/declarative/Gui.qml @@ -113,7 +113,7 @@ Window { anchors.top: parent.top anchors.right: parent.right - active: !Startup.onboard && (!gui.model.connected + active: !Startup.onboard && (!gui.model.ready || NetworkInformation.reachability === NetworkInformation.Reachability.Disconnected) sourceComponent: connectionStatusComponent } @@ -149,11 +149,26 @@ Window { enabled: (curtain && curtain.open) || !curtain - // Unset to avoid unnecessary busy work while the display is off. - model: (curtain && curtain.open || !curtain) ? gui.model : null + model: { + // Unset to avoid unnecessary busy work while the display is off. + if (curtain && curtain.open || !curtain) { + // If we're acting as a client to a remote instance but aren't + // ready to render actual data yet, render the shelf visualization + // as if the shelf is disabled. This is visually more pleasing at + // startup instead of briefly flashing the white background before + // the true state streams in. + if (!Startup.onboard && !gui.model.ready) { + return Settings.rows * Settings.columns; + } + + return gui.model; + } + + return null; + } - rows: model ? model.rows : 0 - columns: model ? model.columns : 0 + rows: Qt.isQtObject(model) ? model.rows : Settings.rows + columns: Qt.isQtObject(model) ? model.columns : Settings.columns onTapped: function (square) { if (displayController) { diff --git a/src/remoteshelfmodel.cpp b/src/remoteshelfmodel.cpp index 9fcce0d..4831d79 100755 --- a/src/remoteshelfmodel.cpp +++ b/src/remoteshelfmodel.cpp @@ -30,11 +30,6 @@ RemoteShelfModel::~RemoteShelfModel() { } -bool RemoteShelfModel::connected() const -{ - return m_remoteModelIface && (m_remoteModelIface->state() == QRemoteObjectReplica::Valid); -} - QUrl RemoteShelfModel::serverAddress() const { return m_serverAddress; @@ -53,6 +48,13 @@ void RemoteShelfModel::setServerAddress(const QUrl &url) } } +bool RemoteShelfModel::ready() const +{ + return m_remoteModelIface + && m_remoteModel->isInitialized() + && (m_remoteModelIface->state() == QRemoteObjectReplica::Valid); +} + bool RemoteShelfModel::enabled() const { if (!m_remoteModelIface || !m_remoteModelIface->isInitialized()) { @@ -277,7 +279,7 @@ void RemoteShelfModel::updateSource() delete m_remotingServer; m_remotingServer = nullptr; - Q_EMIT connectedChanged(); + Q_EMIT readyChanged(); Q_EMIT enabledChanged(); @@ -324,6 +326,9 @@ void RemoteShelfModel::updateSource() return; } + QObject::connect(m_remoteModel, &QAbstractItemModelReplica::initialized, + this, &RemoteShelfModel::readyChanged); + setSourceModel(m_remoteModel); m_remoteModelIface = m_remotingServer->acquire(); @@ -334,10 +339,10 @@ void RemoteShelfModel::updateSource() return; } - Q_EMIT connectedChanged(); + Q_EMIT readyChanged(); QObject::connect(m_remoteModelIface, &QRemoteObjectReplica::stateChanged, - this, &RemoteShelfModel::connectedChanged); + this, &RemoteShelfModel::readyChanged); qCInfo(HYELICHT_REMOTING) << i18n("Connected to remoting API server at: %1", m_serverAddress.toString()); diff --git a/src/remoteshelfmodel.h b/src/remoteshelfmodel.h index f3a5d36..8a3902a 100755 --- a/src/remoteshelfmodel.h +++ b/src/remoteshelfmodel.h @@ -39,13 +39,6 @@ class RemoteShelfModel : public QIdentityProxyModel, public QQmlParserStatus Q_OBJECT Q_INTERFACES(QQmlParserStatus) - //! Whether there is a healthy connection to a ShelfModel. - /*! - * - * \sa serverAddress - */ - Q_PROPERTY(bool connected READ connected NOTIFY connectedChanged) - //! Address used to connect to a ShelfModel instance. /*! * Can be e.g. \c tcp:// or \c local:. @@ -57,6 +50,13 @@ class RemoteShelfModel : public QIdentityProxyModel, public QQmlParserStatus */ Q_PROPERTY(QUrl serverAddress READ serverAddress WRITE setServerAddress NOTIFY serverAddressChanged) + //! Whether the connection is healthy and remote data is available. + /*! + * + * \sa serverAddress + */ + Q_PROPERTY(bool ready READ ready NOTIFY readyChanged) + //! \sa ShelfModel::enabled Q_PROPERTY(bool enabled READ enabled WRITE setEnabled NOTIFY enabledChanged) @@ -95,13 +95,6 @@ class RemoteShelfModel : public QIdentityProxyModel, public QQmlParserStatus explicit RemoteShelfModel(QObject *parent = nullptr); ~RemoteShelfModel() override; - //! Whether there is a healthy connection to a ShelfModel. - /*! - * @return Connected or not. - * \sa serverAddress - */ - bool connected() const; - //! The address used to connect to a ShelfModel instance. /*! * @return Server address, e.g. \c tcp:// or \c local:. @@ -119,6 +112,13 @@ class RemoteShelfModel : public QIdentityProxyModel, public QQmlParserStatus */ void setServerAddress(const QUrl &url); + //! Whether the connection is healthy and remote data is available. + /*! + * @return Ready or not. + * \sa serverAddress + */ + bool ready() const; + //! \sa ShelfModel::enabled bool enabled() const; //! \sa ShelfModel::setEnabled @@ -179,11 +179,11 @@ class RemoteShelfModel : public QIdentityProxyModel, public QQmlParserStatus void componentComplete() override; Q_SIGNALS: - //! Whether there is a healthy connection to a ShelfModel has changed. + //! Whether the connection is healthy and remote data is available. /*! - * \sa connected + * \sa ready */ - void connectedChanged() const; + void readyChanged() const; //! The address used to connect to a ShelfModel instance has changed. /*!