aboutsummaryrefslogtreecommitdiff
path: root/src/session.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/session.cpp')
-rw-r--r--src/session.cpp34
1 files changed, 24 insertions, 10 deletions
diff --git a/src/session.cpp b/src/session.cpp
index 32aca7d..a524afe 100644
--- a/src/session.cpp
+++ b/src/session.cpp
@@ -310,22 +310,36 @@ void Session::start_response(QJsonDocument *doc) {
emit pinChanged(QString::number(pin));
emit urlChanged(url);
emit sessionIDChanged(QString::number(session_id));
-}
-void Session::stop() {
- _dbus_api->stop_request(_host, this->getSessionID());
+ started = true;
- // Clear current variables
- this->init_vars();
+ // Ask status every 1000 millisecond
- // Disable connect button to reduce spam.
- // And don't enable it as long there is no status update.
- // (Or something fails)
- _main_gui->setConnectButtonEnabled(false);
+ QTimer *timer = new QTimer(this);
+ connect(timer, &QTimer::timeout, this,
+ QOverload<>::of(&Session::statusTimerEvent));
+ timer->start(1000);
+
+ qDebug() << "Successfully started a session.";
+ this->setStatus("start_session_success");
+
+ emit startSucceeded();
+}
+
+void Session::stop() {
+ if (started)
+ _dbus_api->stop_request(getHost(), getSessionID());
}
void Session::stop_response(QJsonDocument *doc) {
- Q_ASSERT(doc != nullptr);
+ // Q_ASSERT lets the program crash immediatly after method call
+ // when the session service is not started.
+ // Don't use Q_ASSERT(doc != nullptr); instead use:
+ if (doc == nullptr) {
+ emit stopFailed(tr("Can't connect to underlying session service! "
+ "Is the session service started?"));
+ return;
+ }
QJsonObject jObject = doc->object();
QVariantMap mainMap = jObject.toVariantMap();