UI: TaskManager: Fix tray messages showing

This commit is contained in:
Nodir Temirkhodjaev 2023-05-15 15:32:30 +03:00
parent 8365b92115
commit 2edfd6d7a1
12 changed files with 74 additions and 29 deletions

View File

@ -64,6 +64,8 @@ const char *const commandString(Command cmd)
CASE_STRING(Rpc_TaskManager_abortTask)
CASE_STRING(Rpc_TaskManager_taskStarted)
CASE_STRING(Rpc_TaskManager_taskFinished)
CASE_STRING(Rpc_TaskManager_appVersionDownloaded)
CASE_STRING(Rpc_TaskManager_zonesDownloaded)
default:
return nullptr;
@ -147,6 +149,8 @@ RpcManager managerByCommand(Command cmd)
Rpc_TaskManager, // Rpc_TaskManager_abortTask,
Rpc_TaskManager, // Rpc_TaskManager_taskStarted,
Rpc_TaskManager, // Rpc_TaskManager_taskFinished,
Rpc_TaskManager, // Rpc_TaskManager_appVersionDownloaded,
Rpc_TaskManager, // Rpc_TaskManager_zonesDownloaded,
};
return g_commandManagers[cmd];
@ -209,6 +213,8 @@ bool commandRequiresValidation(Command cmd)
true, // Rpc_TaskManager_abortTask,
0, // Rpc_TaskManager_taskStarted,
0, // Rpc_TaskManager_taskFinished,
0, // Rpc_TaskManager_appVersionDownloaded,
0, // Rpc_TaskManager_zonesDownloaded,
};
return g_commandValidations[cmd];

View File

@ -64,6 +64,8 @@ enum Command : qint8 {
Rpc_TaskManager_abortTask,
Rpc_TaskManager_taskStarted,
Rpc_TaskManager_taskFinished,
Rpc_TaskManager_appVersionDownloaded,
Rpc_TaskManager_zonesDownloaded,
};
enum RpcManager : qint8 {

View File

@ -73,6 +73,5 @@ void AboutPage::setupNewVersionUpdate()
refreshNewVersion();
connect(taskManager()->taskInfoUpdateChecker(), &TaskInfoUpdateChecker::versionChanged, this,
refreshNewVersion);
connect(taskManager(), &TaskManager::appVersionUpdated, this, refreshNewVersion);
}

View File

@ -303,13 +303,30 @@ void FortManager::setupTaskManager()
{
auto taskManager = IoC<TaskManager>();
connect(taskManager, &TaskManager::appVersionDownloaded, this, [&](const QString &version) {
IoC<WindowManager>()->showTrayMessage(
tr("New version v%1 available!").arg(version), WindowManager::MessageNewVersion);
});
connect(taskManager, &TaskManager::zonesDownloaded, this, [&](const QStringList &zoneNames) {
IoC<WindowManager>()->showTrayMessage(
tr("Zone Addresses Updated: %1.").arg(zoneNames.join(", ")),
WindowManager::MessageZones);
});
connect(taskManager, &TaskManager::zonesUpdated, IoC<ConfManager>(),
&ConfManager::updateDriverZones);
connect(taskManager, &TaskManager::taskDoubleClicked, this, [&](qint8 taskType) {
if (taskType == TaskInfo::ZoneDownloader) {
switch (taskType) {
case TaskInfo::UpdateChecker: {
IoC<WindowManager>()->showHomeWindowAbout();
} break;
case TaskInfo::ZoneDownloader: {
IoC<WindowManager>()->showZonesWindow();
} break;
}
});
connect(taskManager->taskInfoZoneDownloader(), &TaskInfoZoneDownloader::zonesUpdated,
IoC<ConfManager>(), &ConfManager::updateDriverZones);
}
void FortManager::setupTranslationManager()

View File

@ -290,6 +290,12 @@ void WindowManager::closeHomeWindow()
m_homeWindow = nullptr;
}
void WindowManager::showHomeWindowAbout()
{
showHomeWindow();
homeWindow()->selectAboutTab();
}
void WindowManager::showProgramsWindow()
{
if (!widgetVisibleByCheckPassword(m_progWindow))
@ -620,8 +626,7 @@ void WindowManager::onTrayMessageClicked()
{
switch (m_lastMessageType) {
case MessageNewVersion: {
showHomeWindow();
homeWindow()->selectAboutTab();
showHomeWindowAbout();
} break;
case MessageZones: {
showZonesWindow();

View File

@ -59,6 +59,8 @@ public slots:
void showHomeWindow();
void closeHomeWindow();
void showHomeWindowAbout();
void showProgramsWindow();
void closeProgramsWindow();

View File

@ -487,6 +487,12 @@ bool processTaskManagerRpc(const ProcessCommandArgs &p, QVariantList & /*resArgs
return processTaskManager_taskStarted(taskManager, p);
case Control::Rpc_TaskManager_taskFinished:
return processTaskManager_taskFinished(taskManager, p);
case Control::Rpc_TaskManager_appVersionDownloaded:
emit taskManager->appVersionDownloaded(p.args[0].toString());
return true;
case Control::Rpc_TaskManager_zonesDownloaded:
emit taskManager->zonesDownloaded(p.args[0].toStringList());
return true;
default:
return false;
}
@ -614,6 +620,13 @@ void RpcManager::setupTaskManagerSignals()
connect(taskManager, &TaskManager::taskFinished, this, [&](qint8 taskType) {
invokeOnClients(Control::Rpc_TaskManager_taskFinished, { taskType });
});
connect(taskManager, &TaskManager::appVersionDownloaded, this, [&](const QString &version) {
invokeOnClients(Control::Rpc_TaskManager_appVersionDownloaded, { version });
});
connect(taskManager, &TaskManager::zonesDownloaded, this, [&](const QStringList &zoneNames) {
invokeOnClients(Control::Rpc_TaskManager_zonesDownloaded, { zoneNames });
});
}
void RpcManager::setupClient()

View File

@ -5,9 +5,7 @@
#include <fort_version.h>
#include <manager/windowmanager.h>
#include <util/ioc/ioccontainer.h>
#include "taskmanager.h"
#include "taskupdatechecker.h"
#define TASK_INFO_VERSION 2
@ -63,7 +61,7 @@ void TaskInfoUpdateChecker::setData(const QByteArray &data)
stream >> m_version >> m_downloadUrl >> m_releaseText;
emit versionChanged();
emitAppVersionUpdated();
}
TaskUpdateChecker *TaskInfoUpdateChecker::updateChecker() const
@ -85,12 +83,16 @@ bool TaskInfoUpdateChecker::processResult(bool success)
m_downloadUrl = worker->downloadUrl();
m_releaseText = worker->releaseText();
emit versionChanged();
emitAppVersionUpdated();
if (isNewVersion()) {
IoC<WindowManager>()->showTrayMessage(
tr("New version v%1 available!").arg(m_version), WindowManager::MessageNewVersion);
emit taskManager()->appVersionDownloaded(m_version);
}
return true;
}
void TaskInfoUpdateChecker::emitAppVersionUpdated()
{
emit taskManager()->appVersionUpdated(m_version);
}

View File

@ -8,9 +8,6 @@ class TaskUpdateChecker;
class TaskInfoUpdateChecker : public TaskInfo
{
Q_OBJECT
Q_PROPERTY(QString version READ version NOTIFY versionChanged)
Q_PROPERTY(QString downloadUrl READ downloadUrl NOTIFY versionChanged)
Q_PROPERTY(QString releaseText READ releaseText NOTIFY versionChanged)
public:
explicit TaskInfoUpdateChecker(TaskManager &taskManager);
@ -25,12 +22,12 @@ public:
TaskUpdateChecker *updateChecker() const;
signals:
void versionChanged();
public slots:
bool processResult(bool success) override;
private:
void emitAppVersionUpdated();
private:
QString m_version;
QString m_downloadUrl;

View File

@ -4,13 +4,13 @@
#include <conf/confmanager.h>
#include <fortsettings.h>
#include <manager/windowmanager.h>
#include <model/zonelistmodel.h>
#include <model/zonesourcewrapper.h>
#include <model/zonetypewrapper.h>
#include <util/fileutil.h>
#include <util/ioc/ioccontainer.h>
#include "taskmanager.h"
#include "taskzonedownloader.h"
TaskInfoZoneDownloader::TaskInfoZoneDownloader(TaskManager &taskManager) :
@ -33,9 +33,8 @@ bool TaskInfoZoneDownloader::processResult(bool success)
if (!success)
return false;
IoC<WindowManager>()->showTrayMessage(
tr("Zone Addresses Updated: %1.").arg(m_zoneNames.join(", ")),
WindowManager::MessageZones);
emit taskManager()->zonesDownloaded(m_zoneNames);
return true;
}
@ -192,7 +191,7 @@ void TaskInfoZoneDownloader::addSubResult(TaskZoneDownloader *worker, bool succe
void TaskInfoZoneDownloader::emitZonesUpdated()
{
emit zonesUpdated(m_dataZonesMask, m_enabledMask, m_dataSize, m_zonesData);
emit taskManager()->zonesUpdated(m_dataZonesMask, m_enabledMask, m_dataSize, m_zonesData);
removeOrphanCacheFiles();

View File

@ -18,10 +18,6 @@ public:
TaskZoneDownloader *zoneDownloader() const;
ZoneListModel *zoneListModel() const;
signals:
void zonesUpdated(quint32 zonesMask, quint32 enabledMask, quint32 dataSize,
const QList<QByteArray> &zonesData);
public slots:
bool processResult(bool success) override;

View File

@ -32,6 +32,13 @@ signals:
void taskDoubleClicked(qint8 taskType);
void appVersionUpdated(const QString &version);
void appVersionDownloaded(const QString &version);
void zonesUpdated(quint32 zonesMask, quint32 enabledMask, quint32 dataSize,
const QList<QByteArray> &zonesData);
void zonesDownloaded(const QStringList &zoneNames);
public slots:
void loadSettings();
bool saveSettings();