From 10cd03b167cd443ad1c5249248590ec66a640f40 Mon Sep 17 00:00:00 2001 From: Pierre HUBERT Date: Sat, 13 Jun 2020 17:33:43 +0200 Subject: [PATCH] Can sign out from account --- refreshservice.cpp | 16 +++++++++++++--- refreshservice.h | 1 + trayicon.cpp | 4 ++++ trayicon.h | 1 + 4 files changed, 19 insertions(+), 3 deletions(-) diff --git a/refreshservice.cpp b/refreshservice.cpp index 897710a..31a1a1a 100644 --- a/refreshservice.cpp +++ b/refreshservice.cpp @@ -1,9 +1,10 @@ +#include +#include + #include "accounthelper.h" #include "loginwindow.h" #include "refreshservice.h" -#include - RefreshService *RefreshService::svc = nullptr; @@ -31,7 +32,7 @@ void RefreshService::signOutUser() { AccountHelper::RemoveLoginToken(); RefreshService::stopService(); - LoginWindow().exec(); + (new LoginWindow())->show(); } void RefreshService::connectedToWebSocket() @@ -58,6 +59,14 @@ void RefreshService::onNewNeumberUnreadConvs(int num) mTrayIcon.onNewNumber(mNumbers); } +void RefreshService::confirmSignOut() +{ + if(QMessageBox::question(nullptr, tr("Sign out"), tr("Do you really want to disconnect ComunicWatcher from your Comunic account?")) != QMessageBox::Yes) + return; + + signOutUser(); +} + RefreshService::RefreshService() { qDebug("Start refresh service"); @@ -66,6 +75,7 @@ RefreshService::RefreshService() connect(&mNotifsHelper, &NotificationsHelper::onNewNumber, this, &RefreshService::onNewNumberNotifications); connect(&mWsClient, &WsClient::newNumberNotifs, this, &RefreshService::onNewNeumberUnreadNotifs); connect(&mWsClient, &WsClient::newNumberConvs, this, &RefreshService::onNewNeumberUnreadConvs); + connect(&mTrayIcon, &TrayIcon::askForSignOut, this, &RefreshService::confirmSignOut); } RefreshService::~RefreshService() diff --git a/refreshservice.h b/refreshservice.h index 6073977..4ccdfa1 100644 --- a/refreshservice.h +++ b/refreshservice.h @@ -27,6 +27,7 @@ private slots: void onNewNumberNotifications(NotificationsNumber number); void onNewNeumberUnreadNotifs(int num); void onNewNeumberUnreadConvs(int num); + void confirmSignOut(); private: RefreshService(); diff --git a/trayicon.cpp b/trayicon.cpp index fbc3638..650c73d 100644 --- a/trayicon.cpp +++ b/trayicon.cpp @@ -9,6 +9,9 @@ TrayIcon::TrayIcon(QObject *parent) : QObject(parent) { mMenu = new QMenu; + QAction *signOutAction = mMenu->addAction(tr("Sign out")); + connect(signOutAction, &QAction::triggered, this, &TrayIcon::askForSignOut); + QAction *closeAction = mMenu->addAction(tr("Quit")); connect(closeAction, &QAction::triggered, this, &TrayIcon::onQuit); @@ -37,6 +40,7 @@ void TrayIcon::onQuit() QApplication::exit(); } + void TrayIcon::showNotification(const NotificationsNumber &n) { QString msg; diff --git a/trayicon.h b/trayicon.h index fb3e28f..cca62d0 100644 --- a/trayicon.h +++ b/trayicon.h @@ -22,6 +22,7 @@ public slots: void onNewNumber(const NotificationsNumber &number); signals: + void askForSignOut(); private slots: void onQuit();