mirror of
https://github.com/tnodir/fort
synced 2024-11-15 07:15:39 +00:00
UI: Add WindowManagerFake for service mode.
This commit is contained in:
parent
c930b07704
commit
121619a939
@ -107,7 +107,7 @@ SOURCES += \
|
||||
rpc/rpcmanager.cpp \
|
||||
rpc/statmanagerrpc.cpp \
|
||||
rpc/taskmanagerrpc.cpp \
|
||||
rpc/windowmanagerrpc.cpp \
|
||||
rpc/windowmanagerfake.cpp \
|
||||
serviceinfo/serviceinfomanager.cpp \
|
||||
stat/quotamanager.cpp \
|
||||
stat/statmanager.cpp \
|
||||
@ -258,7 +258,7 @@ HEADERS += \
|
||||
rpc/rpcmanager.h \
|
||||
rpc/statmanagerrpc.h \
|
||||
rpc/taskmanagerrpc.h \
|
||||
rpc/windowmanagerrpc.h \
|
||||
rpc/windowmanagerfake.h \
|
||||
serviceinfo/serviceinfomanager.h \
|
||||
stat/quotamanager.h \
|
||||
stat/statmanager.h \
|
||||
|
@ -411,11 +411,7 @@ IniUser *ConfManager::iniUser() const
|
||||
|
||||
void ConfManager::showErrorMessage(const QString &errorMessage)
|
||||
{
|
||||
logWarning() << "Error:" << errorMessage;
|
||||
|
||||
if (!IoC<FortSettings>()->isService()) {
|
||||
IoC<WindowManager>()->showErrorBox(errorMessage, tr("Configuration Error"));
|
||||
}
|
||||
IoC<WindowManager>()->showErrorBox(errorMessage, tr("Configuration Error"));
|
||||
}
|
||||
|
||||
void ConfManager::setUp()
|
||||
|
@ -1,6 +1,8 @@
|
||||
#include "fortmanager.h"
|
||||
|
||||
#include <QApplication>
|
||||
#include <QDebug>
|
||||
#include <QMessageBox>
|
||||
#include <QProcess>
|
||||
#include <QThreadPool>
|
||||
|
||||
@ -26,7 +28,7 @@
|
||||
#include "rpc/rpcmanager.h"
|
||||
#include "rpc/statmanagerrpc.h"
|
||||
#include "rpc/taskmanagerrpc.h"
|
||||
#include "rpc/windowmanagerrpc.h"
|
||||
#include "rpc/windowmanagerfake.h"
|
||||
#include "task/taskinfozonedownloader.h"
|
||||
#include "user/usersettings.h"
|
||||
#include "util/dateutil.h"
|
||||
@ -48,16 +50,20 @@ FortManager::~FortManager()
|
||||
OsUtil::closeMutex(m_instanceMutex);
|
||||
}
|
||||
|
||||
bool FortManager::checkRunningInstance()
|
||||
bool FortManager::checkRunningInstance(bool isService)
|
||||
{
|
||||
bool isSingleInstance;
|
||||
m_instanceMutex = OsUtil::createMutex(
|
||||
IoC<FortSettings>()->isService() ? "Global\\" APP_BASE : APP_BASE, isSingleInstance);
|
||||
m_instanceMutex =
|
||||
OsUtil::createMutex(isService ? "Global\\" APP_BASE : APP_BASE, isSingleInstance);
|
||||
if (isSingleInstance)
|
||||
return true;
|
||||
|
||||
if (!isSingleInstance) {
|
||||
IoC<WindowManager>()->showErrorBox(tr("Application is already running!"));
|
||||
if (isService) {
|
||||
qWarning() << "Quit due Service is already running!";
|
||||
} else {
|
||||
QMessageBox::warning(nullptr, QString(), tr("Application is already running!"));
|
||||
}
|
||||
return isSingleInstance;
|
||||
return false;
|
||||
}
|
||||
|
||||
void FortManager::initialize()
|
||||
@ -133,7 +139,6 @@ void FortManager::createManagers()
|
||||
appInfoManager = new AppInfoManager(settings->cacheFilePath());
|
||||
logManager = new LogManager();
|
||||
taskManager = new TaskManager();
|
||||
windowManager = new WindowManager();
|
||||
} else {
|
||||
confManager = new ConfManagerRpc(settings->confFilePath());
|
||||
quotaManager = new QuotaManagerRpc();
|
||||
@ -142,7 +147,16 @@ void FortManager::createManagers()
|
||||
appInfoManager = new AppInfoManagerRpc(settings->cacheFilePath());
|
||||
logManager = new LogManagerRpc();
|
||||
taskManager = new TaskManagerRpc();
|
||||
windowManager = new WindowManagerRpc();
|
||||
}
|
||||
|
||||
if (settings->isService()) {
|
||||
windowManager = new WindowManagerFake();
|
||||
} else {
|
||||
windowManager = new WindowManager();
|
||||
|
||||
ioc->setService(new HotKeyManager());
|
||||
ioc->setService(new UserSettings());
|
||||
ioc->setService(new TranslationManager());
|
||||
}
|
||||
|
||||
ioc->setService(confManager);
|
||||
@ -154,19 +168,11 @@ void FortManager::createManagers()
|
||||
ioc->setService(taskManager);
|
||||
ioc->setService(windowManager);
|
||||
|
||||
ioc->setService(new NativeEventFilter());
|
||||
ioc->setService(new AppInfoCache());
|
||||
ioc->setService(new HostInfoCache());
|
||||
|
||||
ioc->setService(new NativeEventFilter());
|
||||
ioc->setService(new HotKeyManager());
|
||||
|
||||
ioc->setService(new ZoneListModel());
|
||||
|
||||
if (!settings->isService()) {
|
||||
ioc->setService(new UserSettings());
|
||||
ioc->setService(new TranslationManager());
|
||||
}
|
||||
|
||||
ioc->setUpAll();
|
||||
}
|
||||
|
||||
@ -254,12 +260,10 @@ void FortManager::setupConfManager()
|
||||
|
||||
void FortManager::setupQuotaManager()
|
||||
{
|
||||
if (!IoC<FortSettings>()->isService()) {
|
||||
connect(IoC<QuotaManager>(), &QuotaManager::alert, this, [&](qint8 alertType) {
|
||||
IoC<WindowManager>()->showInfoBox(
|
||||
QuotaManager::alertTypeText(alertType), tr("Quota Alert"));
|
||||
});
|
||||
}
|
||||
connect(IoC<QuotaManager>(), &QuotaManager::alert, this, [&](qint8 alertType) {
|
||||
IoC<WindowManager>()->showInfoBox(
|
||||
QuotaManager::alertTypeText(alertType), tr("Quota Alert"));
|
||||
});
|
||||
}
|
||||
|
||||
void FortManager::setupTaskManager()
|
||||
@ -314,7 +318,7 @@ void FortManager::loadConf()
|
||||
|
||||
QString viaVersion;
|
||||
if (!settings->canMigrate(viaVersion)) {
|
||||
IoC<WindowManager>()->showInfoBox(
|
||||
IoC<WindowManager>()->showErrorBox(
|
||||
tr("Please first install Fort Firewall v%1 and save Options from it.")
|
||||
.arg(viaVersion));
|
||||
abort(); // Abort the program
|
||||
|
@ -16,7 +16,7 @@ public:
|
||||
~FortManager() override;
|
||||
CLASS_DELETE_COPY_MOVE(FortManager)
|
||||
|
||||
bool checkRunningInstance();
|
||||
bool checkRunningInstance(bool isService);
|
||||
|
||||
void initialize();
|
||||
|
||||
|
@ -1,6 +1,7 @@
|
||||
#include "windowmanager.h"
|
||||
|
||||
#include <QApplication>
|
||||
#include <QDebug>
|
||||
#include <QMessageBox>
|
||||
#include <QMouseEvent>
|
||||
#include <QStyle>
|
||||
@ -43,6 +44,11 @@ void WindowManager::setUp()
|
||||
connect(qApp, &QCoreApplication::aboutToQuit, this, &WindowManager::closeAll);
|
||||
}
|
||||
|
||||
void WindowManager::tearDown()
|
||||
{
|
||||
closeAll();
|
||||
}
|
||||
|
||||
void WindowManager::setupMainWindow()
|
||||
{
|
||||
m_mainWindow = new MainWindow();
|
||||
@ -66,7 +72,8 @@ void WindowManager::closeMainWindow()
|
||||
nativeEventFilter->unregisterHotKeys();
|
||||
nativeEventFilter->unregisterSessionNotification(mainWindow()->winId());
|
||||
|
||||
delete mainWindow();
|
||||
m_mainWindow->deleteLater();
|
||||
m_mainWindow = nullptr;
|
||||
}
|
||||
|
||||
void WindowManager::setupTrayIcon()
|
||||
|
@ -31,6 +31,7 @@ public:
|
||||
GraphWindow *graphWindow() const { return m_graphWindow; }
|
||||
|
||||
void setUp() override;
|
||||
void tearDown() override;
|
||||
|
||||
signals:
|
||||
void optWindowChanged(bool visible);
|
||||
@ -66,8 +67,8 @@ public slots:
|
||||
void quitByCheckPassword();
|
||||
bool checkPassword();
|
||||
|
||||
void showErrorBox(const QString &text, const QString &title = QString());
|
||||
void showInfoBox(const QString &text, const QString &title = QString());
|
||||
virtual void showErrorBox(const QString &text, const QString &title = QString());
|
||||
virtual void showInfoBox(const QString &text, const QString &title = QString());
|
||||
bool showQuestionBox(const QString &text, const QString &title = QString());
|
||||
bool showYesNoBox(const QString &text, const QString &yesText, const QString &noText,
|
||||
const QString &title = QString());
|
||||
@ -90,10 +91,6 @@ private:
|
||||
static void activateModalWidget();
|
||||
|
||||
private:
|
||||
bool m_initialized : 1;
|
||||
|
||||
void *m_instanceMutex = nullptr;
|
||||
|
||||
TrayMessageType m_lastMessageType = MessageOptions;
|
||||
|
||||
TrayIcon *m_trayIcon = nullptr;
|
||||
|
15
src/ui/rpc/windowmanagerfake.cpp
Normal file
15
src/ui/rpc/windowmanagerfake.cpp
Normal file
@ -0,0 +1,15 @@
|
||||
#include "windowmanagerfake.h"
|
||||
|
||||
#include <QDebug>
|
||||
|
||||
WindowManagerFake::WindowManagerFake(QObject *parent) : WindowManager(parent) { }
|
||||
|
||||
void WindowManagerFake::showErrorBox(const QString &text, const QString &title)
|
||||
{
|
||||
qWarning() << title << ":" << text;
|
||||
}
|
||||
|
||||
void WindowManagerFake::showInfoBox(const QString &text, const QString &title)
|
||||
{
|
||||
qInfo() << title << ":" << text;
|
||||
}
|
21
src/ui/rpc/windowmanagerfake.h
Normal file
21
src/ui/rpc/windowmanagerfake.h
Normal file
@ -0,0 +1,21 @@
|
||||
#ifndef WINDOWMANAGERFAKE_H
|
||||
#define WINDOWMANAGERFAKE_H
|
||||
|
||||
#include "../manager/windowmanager.h"
|
||||
|
||||
class WindowManagerFake : public WindowManager
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit WindowManagerFake(QObject *parent = nullptr);
|
||||
|
||||
void setUp() override { }
|
||||
void tearDown() override { }
|
||||
|
||||
public slots:
|
||||
void showErrorBox(const QString &text, const QString &title = QString()) override;
|
||||
void showInfoBox(const QString &text, const QString &title = QString()) override;
|
||||
};
|
||||
|
||||
#endif // WINDOWMANAGERFAKE_H
|
@ -1,3 +0,0 @@
|
||||
#include "windowmanagerrpc.h"
|
||||
|
||||
WindowManagerRpc::WindowManagerRpc(QObject *parent) : WindowManager(parent) { }
|
@ -1,16 +0,0 @@
|
||||
#ifndef WINDOWMANAGERRPC_H
|
||||
#define WINDOWMANAGERRPC_H
|
||||
|
||||
#include "../manager/windowmanager.h"
|
||||
|
||||
class WindowManagerRpc : public WindowManager
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit WindowManagerRpc(QObject *parent = nullptr);
|
||||
|
||||
void setUp() override { }
|
||||
};
|
||||
|
||||
#endif // WINDOWMANAGERRPC_H
|
@ -128,7 +128,7 @@ int main(int argc, char *argv[])
|
||||
ioc.set<FortManager>(fortManager);
|
||||
|
||||
// Check running instance
|
||||
if (!fortManager.checkRunningInstance())
|
||||
if (!fortManager.checkRunningInstance(settings.isService()))
|
||||
return FORT_ERROR_INSTANCE;
|
||||
|
||||
fortManager.initialize();
|
||||
|
Loading…
Reference in New Issue
Block a user