Skip to content

Commit

Permalink
Render shelf as if disabled during connection process
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
eikehein committed Dec 15, 2024
1 parent 5157cf1 commit 4a00e0e
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 30 deletions.
25 changes: 20 additions & 5 deletions src/declarative/Gui.qml
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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) {
Expand Down
21 changes: 13 additions & 8 deletions src/remoteshelfmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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()) {
Expand Down Expand Up @@ -277,7 +279,7 @@ void RemoteShelfModel::updateSource()
delete m_remotingServer;
m_remotingServer = nullptr;

Q_EMIT connectedChanged();
Q_EMIT readyChanged();

Q_EMIT enabledChanged();

Expand Down Expand Up @@ -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<RemoteShelfModelIfaceReplica>();
Expand All @@ -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());
Expand Down
34 changes: 17 additions & 17 deletions src/remoteshelfmodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -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:.
Expand All @@ -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)

Expand Down Expand Up @@ -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:.
Expand All @@ -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
Expand Down Expand Up @@ -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.
/*!
Expand Down

0 comments on commit 4a00e0e

Please sign in to comment.