From 1983b0b7b9ac704bfefd65e5fed651a7f1ec6e0e Mon Sep 17 00:00:00 2001 From: Nodir Temirkhodjaev Date: Mon, 4 Sep 2017 18:53:45 +0500 Subject: [PATCH] UI: Fix driver setup. --- src/ui/fortmanager.cpp | 47 ++++++++++++++++++++++++++++-------------- src/ui/fortmanager.h | 8 ++++--- src/ui/main.cpp | 5 ----- 3 files changed, 37 insertions(+), 23 deletions(-) diff --git a/src/ui/fortmanager.cpp b/src/ui/fortmanager.cpp index e16378dd..c0a62057 100644 --- a/src/ui/fortmanager.cpp +++ b/src/ui/fortmanager.cpp @@ -25,7 +25,9 @@ FortManager::FortManager(QObject *parent) : m_firewallConfToEdit(nullConf()), m_driverManager(new DriverManager(this)) { - m_fortSettings->readConf(*m_firewallConf); + setupDriver(); + + loadSettings(m_firewallConf); registerQmlTypes(); @@ -50,6 +52,16 @@ void FortManager::registerQmlTypes() qmlRegisterType("com.fortfirewall", 1, 0, "LogEntry"); } +bool FortManager::setupDriver() +{ + if (!m_driverManager->openDevice()) { + showErrorBox(m_driverManager->errorMessage()); + return false; + } + + return true; +} + void FortManager::setupTrayIcon() { m_trayIcon->setToolTip(qApp->applicationDisplayName()); @@ -75,16 +87,6 @@ void FortManager::setupEngine() Q_ASSERT(m_appWindow); } -bool FortManager::setupDriver() -{ - if (!m_driverManager->openDevice()) { - showErrorBox(m_driverManager->errorMessage()); - return false; - } - - return true; -} - void FortManager::showTrayIcon() { m_trayIcon->show(); @@ -140,6 +142,16 @@ void FortManager::setFirewallConfToEdit(FirewallConf *conf) emit firewallConfToEditChanged(); } +bool FortManager::loadSettings(FirewallConf *conf) +{ + if (!m_fortSettings->readConf(*conf)) { + showErrorBox(m_fortSettings->errorMessage()); + return false; + } + + return updateDriverConf(conf); +} + bool FortManager::saveSettings(FirewallConf *newConf) { if (!m_fortSettings->writeConf(*newConf)) { @@ -152,8 +164,13 @@ bool FortManager::saveSettings(FirewallConf *newConf) updateTrayMenu(); + return updateDriverConf(m_firewallConf); +} + +bool FortManager::updateDriverConf(FirewallConf *conf) +{ // Update driver - if (!m_driverManager->writeConf(*m_firewallConf)) { + if (!m_driverManager->writeConf(*conf)) { showErrorBox(m_driverManager->errorMessage()); return false; } @@ -161,7 +178,7 @@ bool FortManager::saveSettings(FirewallConf *newConf) return true; } -bool FortManager::updateDriverFlags(FirewallConf *conf) +bool FortManager::updateDriverConfFlags(FirewallConf *conf) { // Update driver if (!m_driverManager->writeConfFlags(*conf)) { @@ -176,7 +193,7 @@ void FortManager::setAppLogBlocked(bool enable) { m_firewallConf->setAppLogBlocked(enable); - updateDriverFlags(m_firewallConf); + updateDriverConfFlags(m_firewallConf); } void FortManager::saveTrayFlags() @@ -197,7 +214,7 @@ void FortManager::saveTrayFlags() m_fortSettings->writeConfFlags(*m_firewallConf); - updateDriverFlags(m_firewallConf); + updateDriverConfFlags(m_firewallConf); } FirewallConf *FortManager::cloneConf(const FirewallConf &conf) diff --git a/src/ui/fortmanager.h b/src/ui/fortmanager.h index 3b5a8244..1289d6f3 100644 --- a/src/ui/fortmanager.h +++ b/src/ui/fortmanager.h @@ -34,8 +34,6 @@ signals: void firewallConfToEditChanged(); public slots: - bool setupDriver(); - void showTrayIcon(); void showWindow(); @@ -58,11 +56,15 @@ private: static void registerQmlTypes(); + bool setupDriver(); void setupTrayIcon(); void setupEngine(); + bool loadSettings(FirewallConf *conf); bool saveSettings(FirewallConf *newConf); - bool updateDriverFlags(FirewallConf *conf); + + bool updateDriverConf(FirewallConf *conf); + bool updateDriverConfFlags(FirewallConf *conf); FirewallConf *cloneConf(const FirewallConf &conf); diff --git a/src/ui/main.cpp b/src/ui/main.cpp index 338216f0..bc23a207 100644 --- a/src/ui/main.cpp +++ b/src/ui/main.cpp @@ -22,11 +22,6 @@ int main(int argc, char *argv[]) return FortCommon::provRegister(true); } - // Open the driver device - if (!fortManager.setupDriver()) { - return 1; - } - fortManager.showTrayIcon(); return app.exec();