comunicwatcher/refreshservice.cpp
2020-06-13 17:25:16 +02:00

75 lines
1.7 KiB
C++

#include "accounthelper.h"
#include "loginwindow.h"
#include "refreshservice.h"
#include <QGuiApplication>
RefreshService *RefreshService::svc = nullptr;
void RefreshService::startService()
{
if(svc != nullptr)
return;
QGuiApplication::setQuitOnLastWindowClosed(false);
svc = new RefreshService();
}
void RefreshService::stopService()
{
if(svc != nullptr)
svc->deleteLater();
QGuiApplication::setQuitOnLastWindowClosed(true);
svc = nullptr;
}
void RefreshService::signOutUser()
{
AccountHelper::RemoveLoginToken();
RefreshService::stopService();
LoginWindow().exec();
}
void RefreshService::connectedToWebSocket()
{
mNotifsHelper.getNewNotificationsNumbers();
}
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);
}
RefreshService::RefreshService()
{
qDebug("Start refresh service");
connect(&mWsClient, &WsClient::connected, this, &RefreshService::connectedToWebSocket);
connect(&mNotifsHelper, &NotificationsHelper::onNewNumber, this, &RefreshService::onNewNumberNotifications);
connect(&mWsClient, &WsClient::newNumberNotifs, this, &RefreshService::onNewNeumberUnreadNotifs);
connect(&mWsClient, &WsClient::newNumberConvs, this, &RefreshService::onNewNeumberUnreadConvs);
}
RefreshService::~RefreshService()
{
qDebug("Stop refresh service");
}