#include #include "client.h" #include "Dialog.h" #include "Proxifier.h" #include "ProxyClientApp.h" #include "UpdatedConfig.h" using namespace std; ProxyClientApp::ProxyClientApp(int &argc, char *argv[]): QApplication(argc, argv) { /* initiates UpdatedConfig singleton that start sending configuration requests */ UpdatedConfig *cfg = UpdatedConfig::CurrentConfig(); connect(cfg, SIGNAL(updated()), this, SLOT(configUpdated())); if (!QSystemTrayIcon::isSystemTrayAvailable()) { Logger::Fatal("No system tray available! Terminating.\n"); return; } QApplication::setQuitOnLastWindowClosed(false); // create system tray menu QMenu *trayMenu = new QMenu; QAction *showAction = new QAction(tr("&Show"), this); showAction->setStatusTip(tr("Open dialog to choose a proxy")); connect(showAction, SIGNAL(triggered()), this, SLOT(showProxyDialog())); QAction *quitAction = new QAction(tr("&Quit"), this); quitAction->setStatusTip(tr("Close this application")); connect(quitAction, SIGNAL(triggered()), this, SLOT(quitApp())); trayMenu->addAction(showAction); trayMenu->addAction(quitAction); QIcon *icon = new QIcon(":/icon.png"); trayIcon = new QSystemTrayIcon(*icon); connect(trayIcon, SIGNAL(activated(QSystemTrayIcon::ActivationReason)), this, SLOT(trayActivated(QSystemTrayIcon::ActivationReason))); trayIcon->setContextMenu(trayMenu); trayIcon->show(); delete icon; QString cssFile = applicationDirPath()+ "/style.qss"; QFileInfo cssFIleInfo(cssFile); if (cssFIleInfo.exists()) { Logger::Info("CSS stylesheet found. Trying to apply.\n"); QFile file(cssFile); file.open(QFile::ReadOnly); QString cssStr = QString::fromLocal8Bit(file.readAll()); file.close(); setStyleSheet(cssStr); } else { Logger::Info("CSS stylesheet file 'style.qss' wasn't found.\n"); } /** * @todo FIX: trying to access cfg while it is being updated * (note that initial config is still read from config.cfg) */ QString msg = QString::fromLocal8Bit(cfg->WelcomeMsg.c_str()); QMessageBox welcomeMsg; welcomeMsg.setText(msg); welcomeMsg.setWindowTitle("Information"); welcomeMsg.setStandardButtons(QMessageBox::Ok); welcomeMsg.setIcon(QMessageBox::Information); welcomeMsg.exec(); } void ProxyClientApp::trayActivated(QSystemTrayIcon::ActivationReason reason) { if (reason == QSystemTrayIcon::DoubleClick) { showProxyDialog(); } } void ProxyClientApp::showProxyDialog() { Logger::Trace("Creating proxy dialog.\n"); ProxyDialog *dialog = new ProxyDialog(); dialog->show(); } void ProxyClientApp::configUpdated() { // start downloading files in seperate thread // (all necessary check are done by the thread) fileOpThread.start(QThread::NormalPriority); UpdatedConfig *cfg = UpdatedConfig::CurrentConfig(); Proxifier *proxifier = Proxifier::GetInstance(); //update Proxifier Rules if (proxifier->IsValid()) { proxifier->ApplyFirewallRules(cfg->GetFirewallList()); if (!proxifier->ReloadConfig()) { Logger::Error("Unable to reload Proxifier's configuration!\n"); } } else { Logger::Error("No valid proxifier configuration file found!\n"); } // show message when config updated /* QString msg = QString::fromLocal8Bit(cfg->ConfigLoadedMsg.c_str()); QMessageBox updatedMsg; updatedMsg.setText(msg); updatedMsg.setWindowTitle("Information"); updatedMsg.setStandardButtons(QMessageBox::Ok); updatedMsg.setIcon(QMessageBox::Information); updatedMsg.exec(); */ } void ProxyClientApp::quitApp() { Logger::Info("Terminating\n"); trayIcon->hide(); QApplication::exit(0); }