summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCaroline Chao <caroline.chao@digia.com>2014-10-23 13:54:41 +0200
committerCaroline Chao <caroline.chao@theqtcompany.com>2014-10-27 12:24:59 +0100
commit3ebad4c248611b199a835c2e6e028ee4bdc94772 (patch)
treec6367d2e3ce1cc51cb5e3a685c33eef6c1123c5c
parent35ad7b5db4a94cea47732088051c62b8bbb7c4a8 (diff)
Improve offline to online handling
Enable data loading without restarting the application. Change-Id: I7e4d9ba221759426c5e8df770d53787ce0f61524 Reviewed-by: Caroline Chao <caroline.chao@theqtcompany.com>
-rw-r--r--qml/components/HomeScreen.qml2
-rw-r--r--qml/components/ModelsSingleton.qml5
-rw-r--r--qml/main.qml29
-rw-r--r--src/applicationclient.cpp46
-rw-r--r--src/applicationclient.h4
5 files changed, 74 insertions, 12 deletions
diff --git a/qml/components/HomeScreen.qml b/qml/components/HomeScreen.qml
index 56279ff..11149b2 100644
--- a/qml/components/HomeScreen.qml
+++ b/qml/components/HomeScreen.qml
@@ -200,6 +200,8 @@ Rectangle {
model: sortModelNextEvents
clip: true
function reloadUpcoming() {
+ // Attempt to authenticate if not already
+ applicationClient.checkIfAuthenticated()
emptyUpcoming.visible = true
emptyUpcoming.text = Theme.text.loading
if (visible && sortModelNextEvents.rowCount() > 0) {
diff --git a/qml/components/ModelsSingleton.qml b/qml/components/ModelsSingleton.qml
index ce2c0e7..c6eab08 100644
--- a/qml/components/ModelsSingleton.qml
+++ b/qml/components/ModelsSingleton.qml
@@ -275,7 +275,8 @@ QtObject {
})
}
- onConferenceIdChanged: {
+ function reloadModels()
+ {
if (object.conferenceId === "")
return
@@ -310,4 +311,6 @@ QtObject {
trackModel.onFinished(tracksQuery)
})
}
+
+ onConferenceIdChanged: reloadModels()
}
diff --git a/qml/main.qml b/qml/main.qml
index 2b4fe13..f12a67a 100644
--- a/qml/main.qml
+++ b/qml/main.qml
@@ -278,13 +278,39 @@ ApplicationWindow {
Rectangle {
id: initConferenceSwitcher
anchors.fill: parent
- visible: ModelsSingleton.conferenceId === ""
+ visible: ModelsSingleton.conferenceId === "" || applicationClient.noNetworkNoInitialisation
color: Theme.colors.white
Text {
anchors.centerIn: parent
visible: applicationClient.noNetworkNoInitialisation
font.pointSize: Theme.fonts.seven_pt
text: Theme.text.networkErrorInit
+ Image {
+ id: reload
+ anchors.top: parent.bottom
+ anchors.horizontalCenter: parent.horizontalCenter
+ source: Theme.images.loading
+ sourceSize.height: Theme.sizes.reloadButtonSize
+ sourceSize.width: Theme.sizes.reloadButtonSize
+ MouseArea {
+ anchors.centerIn: parent
+ width: Theme.sizes.homeTitleHeight
+ height: Theme.sizes.homeTitleHeight
+ onClicked: {
+ rotationReload.running = true
+ applicationClient.checkIfAuthenticated()
+ }
+ }
+ RotationAnimation {
+ id: rotationReload
+ target: reload
+ property: "rotation"
+ running: false
+ duration: 800
+ from: 0
+ to: 360
+ }
+ }
}
Image {
@@ -311,5 +337,6 @@ ApplicationWindow {
Connections {
target: applicationClient
onConferencesModelChanged: if (initConferenceSwitcher.visible) logo.opacity = 1
+ onAuthenticationSuccessful: if (ModelsSingleton.eventModel.rowCount() === 0) ModelsSingleton.reloadModels()
}
}
diff --git a/src/applicationclient.cpp b/src/applicationclient.cpp
index bb104f3..8902828 100644
--- a/src/applicationclient.cpp
+++ b/src/applicationclient.cpp
@@ -90,11 +90,24 @@ ApplicationClient::ApplicationClient()
}
connect(m_client, SIGNAL(sessionAuthenticated(EnginioReply*)), this, SLOT(authenticationSuccess(EnginioReply*)));
- connect(m_client, SIGNAL(sessionAuthenticationError(EnginioReply*)), this, SLOT(errorClient(EnginioReply*)));
+ connect(m_client, SIGNAL(sessionAuthenticationError(EnginioReply*)), this, SLOT(errorAuthentication(EnginioReply*)));
connect(m_client, SIGNAL(error(EnginioReply*)), this, SLOT(errorClient(EnginioReply*)));
getUserCredentials();
}
+void ApplicationClient::checkIfAuthenticated()
+{
+ // qDebug() << "checkIfAuthenticated, current state:" << m_client->authenticationState();
+ if (m_client->authenticationState() == Enginio::NotAuthenticated ||
+ m_client->authenticationState() == Enginio::AuthenticationFailure ||
+ m_conferenceModel->rowCount() == 0) {
+ if (m_noNetworkNoInitialisation)
+ getUserCredentials();
+ else
+ authenticate();
+ }
+}
+
void ApplicationClient::errorClient(EnginioReply *reply)
{
//qDebug() << "Error" << reply->errorString() << m_client->authenticationState();
@@ -102,6 +115,13 @@ void ApplicationClient::errorClient(EnginioReply *reply)
reply->deleteLater();
}
+void ApplicationClient::errorAuthentication(EnginioReply *reply)
+{
+ Q_UNUSED(reply);
+ //qDebug() << "Clear identity on authentication error";
+ m_client->setIdentity(0);
+}
+
void ApplicationClient::getUserCredentials()
{
//qDebug() << "Get user credentials";
@@ -144,6 +164,8 @@ void ApplicationClient::userCreationReply(EnginioReply *reply)
emit error(reply->errorString());
} else {
//qDebug() << "User Created";
+ m_noNetworkNoInitialisation = false;
+ emit noNetworkNoInitialisationChanged();
m_userData->write(QString("%1 %2").arg(currentUsername).arg(currentPassword));
authenticate();
}
@@ -166,14 +188,20 @@ void ApplicationClient::authenticationSuccess(EnginioReply *reply)
emptyFeedbackCache();
int timeout = (reply->data().value("expires_in").toInt() - 20*60)*1000;
- timer->setSingleShot(true);
- timer->start(timeout);
- if (init) { // Query the conference only once
- QJsonObject query;
- query["objectType"] = QString::fromUtf8("objects.Conference");
- const EnginioReply *replyConf = m_client->query(query);
- connect(replyConf, SIGNAL(finished(EnginioReply*)), this, SLOT(queryConferenceReply(EnginioReply*)));
- init = false;
+ if (timeout > 0) {
+ timer->stop();
+ timer->setSingleShot(true);
+ timer->start(timeout);
+ if (init) { // Query the conference only once
+ QJsonObject query;
+ query["objectType"] = QString::fromUtf8("objects.Conference");
+ const EnginioReply *replyConf = m_client->query(query);
+ connect(replyConf, SIGNAL(finished(EnginioReply*)), this, SLOT(queryConferenceReply(EnginioReply*)));
+ init = false;
+ } else {
+ // To trigger reload of other models
+ emit authenticationSuccessful();
+ }
}
}
diff --git a/src/applicationclient.h b/src/applicationclient.h
index 521dbf7..3989319 100644
--- a/src/applicationclient.h
+++ b/src/applicationclient.h
@@ -78,6 +78,7 @@ public:
Q_INVOKABLE void cacheFeedback(QString feedback);
Q_INVOKABLE void cacheFavorite(QString favorite, bool isAdded);
+ Q_INVOKABLE void checkIfAuthenticated();
protected:
void getUserCredentials();
@@ -87,15 +88,16 @@ protected:
signals:
void error(QString errorMessage);
- void askQueryConferences();
void currentConferenceIdChanged();
void currentConferenceDetailsChanged();
void conferencesModelChanged();
void noNetworkNoInitialisationChanged();
+ void authenticationSuccessful();
public slots:
void authenticationSuccess(EnginioReply *reply);
void errorClient(EnginioReply *reply);
+ void errorAuthentication(EnginioReply *reply);
void userCreationReply(EnginioReply *reply);
void queryConferenceReply(EnginioReply *reply);
void createFeedbackReply(EnginioReply *reply);