aheinecke@404: /* Copyright (C) 2014 by Bundesamt für Sicherheit in der Informationstechnik aheinecke@404: * Software engineering by Intevation GmbH aheinecke@404: * aheinecke@404: * This file is Free Software under the GNU GPL (v>=2) aheinecke@404: * and comes with ABSOLUTELY NO WARRANTY! aheinecke@404: * See LICENSE.txt for details. aheinecke@404: */ aheinecke@0: #include "mainwindow.h" andre@612: #include "processhelp.h" andre@631: #include "logging.h" andre@634: #include "selftest.h" andre@876: #include "util.h" andre@827: #ifdef WIN32 andre@827: #include "taskscheduler.h" andre@827: #endif aheinecke@0: aheinecke@0: #include andre@840: #include aheinecke@0: #include aheinecke@0: #include aheinecke@17: #include aheinecke@423: #include aheinecke@423: #include aheinecke@0: andre@672: #include andre@876: #include andre@672: aheinecke@16: #ifndef VERSION aheinecke@16: #define VERSION "0.0.1" aheinecke@16: #endif aheinecke@16: aheinecke@16: #ifndef APPNAME aheinecke@407: #define APPNAME "TrustBridge" aheinecke@16: #endif aheinecke@16: andre@840: #ifndef STARTUP_FILE_NAME andre@840: #define STARTUP_FILE_NAME "trustbridge-tray-starter.cfg" andre@840: #endif andre@840: aheinecke@16: #ifndef ORGANIZATION aheinecke@409: #define ORGANIZATION "BSI" aheinecke@16: #endif aheinecke@0: andre@829: #define COPYRIGHT "Copyright (C) 2014 by Bundesamt für Sicherheit in der Informationstechnik \n" \ andre@829: "Software engineering by Intevation GmbH \n\n" \ andre@829: "This file is Free Software under the GNU GPL (v>=2)\n" \ andre@829: "and comes with ABSOLUTELY NO WARRANTY!\n" andre@829: aheinecke@0: #ifdef Q_OS_WIN aheinecke@0: Q_IMPORT_PLUGIN(QWindowsIntegrationPlugin) aheinecke@0: #else aheinecke@0: Q_IMPORT_PLUGIN(QXcbIntegrationPlugin) aheinecke@0: #endif aheinecke@0: andre@1315: #ifdef IS_TAG_BUILD andre@1058: bool g_debug = false; andre@1072: #else andre@1072: bool g_debug = true; andre@1072: #endif andre@1072: andre@1058: QtMessageHandler g_default_msg_handler = NULL; andre@1058: andre@1072: void filterDebugOutput(QtMsgType type, const QMessageLogContext &context, const QString &msg) andre@1058: { andre@1072: if (!g_debug && type == QtDebugMsg) { andre@1058: return; andre@1058: } andre@1058: andre@1058: if (g_default_msg_handler) { andre@1058: (*g_default_msg_handler)(type, context, msg); andre@1058: } andre@1058: } andre@1058: andre@1058: aheinecke@0: int main(int argc, char **argv) aheinecke@0: { andre@1365: time_t signed_time = 0; andre@939: #ifdef WIN32 andre@939: /* First verify integrity even before calling QApplication. andre@939: * We only do this on Windows as we have a PKCS#7 embedded andre@939: * signature there which we check with OS methods. andre@939: * andre@939: * On GNU/Linux platforms you should use an IDS system to andre@939: * monitor executable corruptions. andre@939: */ andre@1365: if (!selftest(&signed_time)) { andre@1076: syslog_error_printf("Integrity check failed."); andre@1076: MessageBoxW(NULL, andre@1076: L"TrustBridge wurde nach der Installation modifizert.\n" bernhard@1078: L"Um ihr System zu schützen wurde das Starten der Anwendung abgebrochen.\n" andre@1076: L"Bitte installieren Sie TrustBridge erneut.\n\n" emanuel@1079: L"TrustBridge has been modified after installation.\n" andre@1076: L"To protect your system the application launch has been aborted.\n" andre@1076: L"Please reinstall TrustBridge.", andre@1076: L"Integritätsprüfung fehlgeschlagen / Integrity check failed.", andre@1076: MB_ICONERROR | MB_OK); andre@631: return -1; andre@634: } andre@939: #endif andre@631: aheinecke@0: QApplication app (argc, argv); aheinecke@0: rrenkert@482: QApplication::setQuitOnLastWindowClosed(false); rrenkert@482: QApplication::setOrganizationName(QString::fromLatin1(ORGANIZATION)); rrenkert@482: QApplication::setApplicationName(QString::fromLatin1(APPNAME)); rrenkert@482: QApplication::setApplicationVersion(QString::fromLatin1(VERSION)); rrenkert@482: QSettings::setDefaultFormat(QSettings::IniFormat); andre@1058: QStringList arguments = QApplication::arguments(); andre@1058: andre@1058: if (arguments.contains("--debug")) { andre@1058: g_debug = true; andre@1058: } andre@1072: g_default_msg_handler = qInstallMessageHandler(filterDebugOutput); rrenkert@482: andre@672: qDebug() << "Application style is: " << app.style()->metaObject()->className(); andre@672: qDebug() << "Available styles: " << QStyleFactory::keys().join(", "); andre@876: qDebug() << "Font is: " << app.font(); andre@672: rrenkert@154: bool trayMode = arguments.contains("--tray"); rrenkert@154: andre@829: if (arguments.contains("--version")) { andre@829: printf (APPNAME " Version: %s \n", andre@829: QApplication::applicationVersion().toLocal8Bit().constData()); andre@1387: #ifndef RELEASE_BUILD andre@1394: printf ("Test Version! - Not for productive use!\n"); andre@1387: #endif andre@829: printf (COPYRIGHT); andre@829: return 0; andre@829: } andre@829: rrenkert@482: QSettings settings; rrenkert@482: settings.beginGroup("settings"); aheinecke@499: bool autoStart = settings.value("autostart", true).toBool(); rrenkert@482: settings.endGroup(); rrenkert@482: aheinecke@499: if (trayMode && !autoStart) { rrenkert@482: return 0; rrenkert@482: } rrenkert@482: andre@612: if (ProcessHelp::otherProcessesExist(APPNAME)) { andre@612: qDebug() << "Another " << APPNAME << " process is already running. Exiting."; andre@612: ProcessHelp::activateWindowForProcess(APPNAME); andre@612: return 0; andre@612: } andre@612: aheinecke@423: QTranslator translator; aheinecke@423: if (QLocale::system().name() == "C") { aheinecke@423: /* Useful for testing / development as the primary target is german */ aheinecke@423: translator.load(":/l10n/trustbridge_de_DE"); aheinecke@423: } else { aheinecke@423: qDebug() << "Loading translations for: " << "trustbridge_" + aheinecke@423: QLocale::system().name(); andre@993: if (!translator.load(":/l10n/trustbridge_" + QLocale::system().name())) { andre@993: qDebug() << "Failed."; andre@993: } aheinecke@423: } aheinecke@423: app.installTranslator(&translator); andre@871: /* andre@712: if ((!QSystemTrayIcon::isSystemTrayAvailable() || andre@712: !QSystemTrayIcon::supportsMessages()) && trayMode) { aheinecke@16: QMessageBox::critical(0, QString::fromLatin1(APPNAME), aheinecke@0: QObject::tr("Couldn't detect any system tray " aheinecke@0: "on this system. This software can only " aheinecke@0: "be used in a desktop environment.")); aheinecke@0: return 1; aheinecke@0: } andre@871: */ andre@827: #ifdef Q_OS_WIN andre@827: { andre@827: TaskScheduler taskSched; andre@827: qDebug() << " task sched done: " << taskSched.createDailyTask(QCoreApplication::applicationFilePath(), andre@827: QString::fromLatin1("--tray"), QTime::currentTime()); andre@827: } andre@840: #else andre@840: /* Save the display on start so that it might later be used by the cron startup script. */ andre@840: QFile startup_file (settings.fileName().replace(APPNAME ".ini", STARTUP_FILE_NAME)); andre@840: startup_file.open(QIODevice::WriteOnly); andre@840: startup_file.write(QString::fromLatin1("DISPLAY=%1\n").arg(qgetenv("DISPLAY").constData()).toUtf8()); andre@840: startup_file.close(); andre@827: #endif andre@876: andre@876: /* Install static fonts */ andre@876: andre@879: /* The putenv here works around a bug in qt (#29192). Qt thinks it is a fatal andre@876: * error if the font directory does not exist. */ andre@876: qputenv("QT_QPA_FONTDIR", get_install_dir()); andre@876: int fontId = QFontDatabase::addApplicationFont(":/fonts/DejaVuSans.ttf"); andre@876: if (fontId != -1) andre@876: { andre@876: QFont font("DejaVuSans"); andre@876: font.setPointSize(9); andre@876: app.setFont(font); andre@876: } andre@876: andre@1371: andre@1371: QDateTime sigDt; andre@1371: #ifndef Q_OS_WIN andre@1371: /* Read it from the install config. */ andre@1371: sigDt = ProcessHelp::getSigDtFromInstSettings(); andre@1371: Q_UNUSED(signed_time); andre@1371: #else andre@1365: if (signed_time != 0 && signed_time != -1) { andre@1371: /* Take it from the selftest result. */ andre@1371: sigDt = QDateTime::fromTime_t(signed_time); andre@1365: } andre@1371: #endif andre@1365: andre@1371: MainWindow mainWin(trayMode, sigDt); aheinecke@0: aheinecke@0: return app.exec(); aheinecke@0: }