diff options
Diffstat (limited to 'src/session.cpp')
-rw-r--r-- | src/session.cpp | 117 |
1 files changed, 87 insertions, 30 deletions
diff --git a/src/session.cpp b/src/session.cpp index d48de39..e4d3c95 100644 --- a/src/session.cpp +++ b/src/session.cpp @@ -47,6 +47,11 @@ Session::Session(QObject *parent, MainQMLAdaptor* main_gui) : QObject(parent) { SIGNAL(urlChanged(QString)), main_gui, SLOT(setURL(QString))); + // session::setSessionID --sessionIDChanged--> MainQMLAdaptor::setSessionID --sessionIDChanged--> QML + QObject::connect(this, + SIGNAL(sessionIDChanged(QString)), + main_gui, + SLOT(setSessionID(QString))); // QML -> MainQMLAdaptor::onCloseHandler --onCloseSignal--> session::onCloseHandler QObject::connect(main_gui, @@ -64,7 +69,8 @@ void Session::statusTimerEvent() { void Session::init_vars() { setPin("-----"); - setId(-1); + setSessionID("-----"); + setId("-----"); setURL(tr("Not available yet")); setStatus("unknown"); @@ -83,8 +89,12 @@ QString Session::getURL() { return _url; } -int Session::getId() { - return _id; +QString Session::getId() { + return QString(_id); +} + +QString Session::getSessionID() { + return QString(_session_id); } QString Session::getPin() { @@ -187,18 +197,25 @@ void Session::setURL(QString url) { emit urlChanged(url); } -void Session::setId(int id) { +void Session::setId(QString id) { _id = id; emit idChanged(id); } +void Session::setSessionID(QString session_id) { + _session_id = session_id; + emit sessionIDChanged(session_id); +} + void Session::setPin(QString pin) { _pin = pin; emit pinChanged(pin); } void Session::handleConnectButtonClick(bool checked) { - qDebug() << "-----Connect button handler-----\nCurrent session #" << this->getId(); + qDebug() << "-----Connect button handler-----" << + "\nCurrent service-session #" << this->getId() << + "\nCurrent support-session #" << this->getSessionID(); // Stopping even if nothing is running this->stop_request_dbus(this->getId()); @@ -281,38 +298,68 @@ void Session::start_dbus_replied(QDBusPendingCallWatcher *call) { return; } - // Session ID == PID - int sessionid = mainMap["id"].toInt(); - this->setId(sessionid); + // Service ID == PID + bool ok; + long long service_id = mainMap["id"].toLongLong(&ok); + this->setId(QString::number(service_id)); + // Sanity Check + if(ok == false){ + qErrnoWarning("Unable to parse <service_id> out of dbus answer!"); + init_vars(); + return; + } // URL of remote web app frontend QString url = mainMap["url"].toString(); this->setURL(url); // PIN - QString pin = mainMap["pin"].toString(); - this->setPin(pin); + long long pin = mainMap["pin"].toLongLong(); + this->setPin(QString::number(pin)); + // Sanity Check + if(ok == false){ + qErrnoWarning("Unable to parse <pin> out of dbus answer!"); + init_vars(); + return; + } - qDebug() << "Got session id:" << sessionid; - qDebug() << "Got url:" << url; - qDebug() << "Got pin:" << pin; + // session_id = remote support id from the rwa-server + long long session_id = mainMap["session_id"].toLongLong(); + this->setSessionID(QString::number(session_id)); + // Sanity Check + if(ok == false){ + qErrnoWarning("Unable to parse <pin> out of dbus answer!"); + init_vars(); + return; + } - emit pinChanged(pin); + qDebug() << "Got service_id:" << service_id << + "\nGot session_id:" << session_id << + "\nGot url:" << url << + "\nGot pin:" << pin; + + emit pinChanged(QString::number(pin)); emit urlChanged(url); - emit idChanged(sessionid); + emit idChanged(QString::number(service_id)); + emit sessionIDChanged(QString::number(session_id)); } -void Session::stop_request_dbus(int pid) { - if (pid <= 0 ){ - qDebug() << "Won't send a request to D-Bus service to stop a session when session ID <= 0"; +void Session::stop_request_dbus(QString id) { + bool ok; + if (id.toLongLong(&ok) == 0 ){ + qDebug() << "Won't send a request to D-Bus service to stop a session when session ID == 0"; + return; + } + if(ok == false){ + qErrnoWarning("Unable to convert <QString> id to <long long>"); return; } // Stopping now. - qDebug() << "Requesting D-Bus session service to stop session #" << pid; + qDebug() << "Requesting D-Bus session service to stop session #" << id; // Make an asynchrous 'stop' call (Response will be sent to 'stop_dbus_replied') - QDBusPendingCall async = _dbus_rwa->asyncCall("stop", pid); + QDBusPendingCall async = _dbus_rwa->asyncCall("stop", id); QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(async, this); QObject::connect(watcher, SIGNAL(finished(QDBusPendingCallWatcher*)), @@ -359,34 +406,44 @@ void Session::stop_dbus_replied(QDBusPendingCallWatcher *call) { this->setStatus(new_status); } -void Session::status_request_dbus(int pid) { - if (pid <= 0 ){ - qDebug() << "Won't send a request to D-Bus service of a session's status when session ID <= 0"; +void Session::status_request_dbus(QString id) { + bool ok; + if (id.toLongLong(&ok) == 0 ){ + qDebug() << "Won't send a request to D-Bus service of a session's status when session ID == 0"; + return; + } + if(ok == false){ + qErrnoWarning("Unable to convert <QString> id to <long long>"); return; } // Requesting status now. - qDebug() << "Requesting status for session #" << pid; + qDebug() << "Requesting status for session #" << id; // Make an asynchrous 'status' call (Response will be sent to 'status_dbus_replied') - QDBusPendingCall async = _dbus_rwa->asyncCall("status", pid); + QDBusPendingCall async = _dbus_rwa->asyncCall("status", id); QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(async, this); QObject::connect(watcher, SIGNAL(finished(QDBusPendingCallWatcher*)), this, SLOT(stop_dbus_replied(QDBusPendingCallWatcher*))); } -void Session::refresh_status_request_dbus(int pid) { - if (pid <= 0 ){ - qDebug() << "Won't send a request to D-Bus service to refresh the status of a session when session ID <= 0"; +void Session::refresh_status_request_dbus(QString id) { + bool ok; + if (id.toLongLong(&ok) == 0){ + qDebug() << "Won't send a request to D-Bus service to refresh the status of a session when session ID == 0"; + return; + } + if(ok == false){ + qErrnoWarning("Unable to convert <QString> id to <long long>"); return; } // Refreshing status - qDebug() << "Requesting status refresh for session #" << pid; + qDebug() << "Requesting status refresh for session #" << id; // Make an asynchrous 'refresh_status' call (Response will be sent to 'status_dbus_replied') - QDBusPendingCall async = _dbus_rwa->asyncCall("refresh_status", pid); + QDBusPendingCall async = _dbus_rwa->asyncCall("refresh_status", id); QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(async, this); QObject::connect(watcher, SIGNAL(finished(QDBusPendingCallWatcher*)), |