int main(int argc, char *argv[]) { qRegisterMetaTypeStreamOperators<SQProfile>("SQProfile"); QApplication a(argc, argv); signal(SIGINT, onSIGINT_TERM); signal(SIGTERM, onSIGINT_TERM); a.setApplicationName(QString("shadowsocks-qt5")); a.setApplicationDisplayName(QString("Shadowsocks-Qt5")); a.setApplicationVersion(APP_VERSION); #ifdef Q_OS_WIN if (QLocale::system().country() == QLocale::China) { a.setFont(QFont("Microsoft Yahei", 9, QFont::Normal, false)); } else { a.setFont(QFont("Segoe UI", 9, QFont::Normal, false)); } QIcon::setThemeName("Breeze"); #endif QTranslator ssqt5t; ssqt5t.load(QLocale::system(), "ss-qt5", "_", ":/i18n"); a.installTranslator(&ssqt5t); MainWindow w; QSharedMemory sharedMem; sharedMem.setKey("Shadowsocks-Qt5"); if (w.isOnlyOneInstance()) { if (!sharedMem.create(1)) { QMessageBox::critical(&w, QObject::tr("Error"), QObject::tr("Another instance of Shadowsocks-Qt5 is already running.")); return -1; } } w.show(); if (w.isHideWindowOnStartup()) { if (w.isUsingAppIndicator()) { QTimer::singleShot(5, &w, SLOT(minimizeToSysTray())); } else { w.minimizeToSysTray(); } } return a.exec(); }
void MainWindow::changeEvent(QEvent *e) { if (e->type() == QEvent::WindowStateChange && this->isMinimized()) { minimizeToSysTray(); } }
void MainWindow::closeEvent(QCloseEvent *) { minimizeToSysTray(); }