2020-06-13 15:33:43 +00:00
|
|
|
#include <QGuiApplication>
|
|
|
|
#include <QMessageBox>
|
2020-06-13 15:56:09 +00:00
|
|
|
#include <QDesktopServices>
|
2020-06-13 15:33:43 +00:00
|
|
|
|
2020-06-13 15:25:16 +00:00
|
|
|
#include "accounthelper.h"
|
|
|
|
#include "loginwindow.h"
|
2020-06-13 08:19:49 +00:00
|
|
|
#include "refreshservice.h"
|
2020-06-13 15:56:09 +00:00
|
|
|
#include "config.h"
|
2020-06-14 13:10:06 +00:00
|
|
|
#include "aboutdialog.h"
|
2020-06-13 08:19:49 +00:00
|
|
|
|
|
|
|
RefreshService *RefreshService::svc = nullptr;
|
|
|
|
|
|
|
|
|
|
|
|
void RefreshService::startService()
|
|
|
|
{
|
|
|
|
if(svc != nullptr)
|
|
|
|
return;
|
|
|
|
|
2020-06-13 12:59:02 +00:00
|
|
|
QGuiApplication::setQuitOnLastWindowClosed(false);
|
|
|
|
|
2020-06-13 08:19:49 +00:00
|
|
|
svc = new RefreshService();
|
|
|
|
}
|
|
|
|
|
|
|
|
void RefreshService::stopService()
|
|
|
|
{
|
|
|
|
if(svc != nullptr)
|
|
|
|
svc->deleteLater();
|
2020-06-13 12:59:02 +00:00
|
|
|
|
|
|
|
QGuiApplication::setQuitOnLastWindowClosed(true);
|
|
|
|
|
2020-06-13 08:19:49 +00:00
|
|
|
svc = nullptr;
|
|
|
|
}
|
|
|
|
|
2020-06-13 15:25:16 +00:00
|
|
|
void RefreshService::signOutUser()
|
|
|
|
{
|
|
|
|
AccountHelper::RemoveLoginToken();
|
|
|
|
RefreshService::stopService();
|
2020-06-13 15:33:43 +00:00
|
|
|
(new LoginWindow())->show();
|
2020-06-13 15:25:16 +00:00
|
|
|
}
|
|
|
|
|
2020-06-13 12:14:01 +00:00
|
|
|
void RefreshService::connectedToWebSocket()
|
|
|
|
{
|
|
|
|
mNotifsHelper.getNewNotificationsNumbers();
|
|
|
|
}
|
|
|
|
|
2020-06-13 12:59:02 +00:00
|
|
|
void RefreshService::onNewNumberNotifications(NotificationsNumber numbers)
|
|
|
|
{
|
|
|
|
mNumbers = numbers;
|
|
|
|
|
|
|
|
mTrayIcon.onNewNumber(numbers);
|
|
|
|
}
|
|
|
|
|
|
|
|
void RefreshService::onNewNeumberUnreadNotifs(int num)
|
|
|
|
{
|
|
|
|
mNumbers.setNewNotifs(num);
|
|
|
|
mTrayIcon.onNewNumber(mNumbers);
|
|
|
|
}
|
|
|
|
|
|
|
|
void RefreshService::onNewNeumberUnreadConvs(int num)
|
|
|
|
{
|
|
|
|
mNumbers.setUnreadConversations(num);
|
|
|
|
mTrayIcon.onNewNumber(mNumbers);
|
|
|
|
}
|
|
|
|
|
2020-06-13 15:56:09 +00:00
|
|
|
void RefreshService::openComunic()
|
|
|
|
{
|
|
|
|
QDesktopServices::openUrl(QUrl(COMUNIC_URL));
|
|
|
|
}
|
|
|
|
|
2020-06-14 13:10:06 +00:00
|
|
|
void RefreshService::openAboutDialog()
|
2020-06-13 16:05:06 +00:00
|
|
|
{
|
2020-06-14 13:10:06 +00:00
|
|
|
AboutDialog().exec();
|
2020-06-13 16:05:06 +00:00
|
|
|
}
|
|
|
|
|
2020-06-13 15:33:43 +00:00
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
2020-06-13 08:19:49 +00:00
|
|
|
RefreshService::RefreshService()
|
|
|
|
{
|
|
|
|
qDebug("Start refresh service");
|
2020-06-13 12:14:01 +00:00
|
|
|
|
|
|
|
connect(&mWsClient, &WsClient::connected, this, &RefreshService::connectedToWebSocket);
|
2020-06-13 12:59:02 +00:00
|
|
|
connect(&mNotifsHelper, &NotificationsHelper::onNewNumber, this, &RefreshService::onNewNumberNotifications);
|
|
|
|
connect(&mWsClient, &WsClient::newNumberNotifs, this, &RefreshService::onNewNeumberUnreadNotifs);
|
|
|
|
connect(&mWsClient, &WsClient::newNumberConvs, this, &RefreshService::onNewNeumberUnreadConvs);
|
2020-06-13 15:33:43 +00:00
|
|
|
connect(&mTrayIcon, &TrayIcon::askForSignOut, this, &RefreshService::confirmSignOut);
|
2020-06-14 13:10:06 +00:00
|
|
|
connect(&mTrayIcon, &TrayIcon::showAboutDialog, this, &RefreshService::openAboutDialog);
|
2020-06-13 15:56:09 +00:00
|
|
|
connect(&mTrayIcon, &TrayIcon::onOpenComunic, this, &RefreshService::openComunic);
|
2020-06-13 08:19:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
RefreshService::~RefreshService()
|
|
|
|
{
|
|
|
|
qDebug("Stop refresh service");
|
|
|
|
}
|