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:  */
rrenkert@333: #include "administratorwindow.h"
andre@876: #include "util.h"
rrenkert@333: 
rrenkert@333: #include <QApplication>
rrenkert@333: #include <QtPlugin>
rrenkert@333: #include <QMessageBox>
rrenkert@333: #include <QSettings>
aheinecke@420: #include <QTranslator>
aheinecke@420: #include <QDebug>
andre@832: #include <QTextCodec>
andre@876: #include <QFontDatabase>
rrenkert@333: 
rrenkert@333: #ifndef VERSION
rrenkert@333: #define VERSION "0.0.1"
rrenkert@333: #endif
rrenkert@333: 
rrenkert@333: #ifndef APPNAME
aheinecke@520: #define APPNAME "trustbridge-admin"
rrenkert@333: #endif
rrenkert@333: 
rrenkert@333: #ifndef ORGANIZATION
aheinecke@409: #define ORGANIZATION "BSI"
rrenkert@333: #endif
rrenkert@333: 
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: 
rrenkert@333: #ifdef Q_OS_WIN
rrenkert@333:  Q_IMPORT_PLUGIN(QWindowsIntegrationPlugin)
rrenkert@333: #else
rrenkert@333:  Q_IMPORT_PLUGIN(QXcbIntegrationPlugin)
rrenkert@333: #endif
rrenkert@333: 
andre@1315: #ifdef IS_TAG_BUILD
andre@1059: bool g_debug = false;
andre@1072: #else
andre@1072: bool g_debug = true;
andre@1072: #endif
andre@1072: 
andre@1059: QtMessageHandler g_default_msg_handler = NULL;
andre@1059: 
andre@1072: void filterDebugOutput(QtMsgType type, const QMessageLogContext &context, const QString &msg)
andre@1059: {
andre@1072:     if (!g_debug && type == QtDebugMsg) {
andre@1059:         return;
andre@1059:     }
andre@1059: 
andre@1059:     if (g_default_msg_handler) {
andre@1059:         (*g_default_msg_handler)(type, context, msg);
andre@1059:     }
andre@1059: }
andre@1059: 
rrenkert@333: int main(int argc, char **argv)
rrenkert@333: {
rrenkert@333:     QApplication app (argc, argv);
rrenkert@333: 
rrenkert@333:     QStringList arguments = QApplication::arguments();
rrenkert@333: 
rrenkert@333:     QApplication::setOrganizationName(QString::fromLatin1(ORGANIZATION));
rrenkert@333:     QApplication::setApplicationName(QString::fromLatin1(APPNAME));
rrenkert@333:     QApplication::setApplicationVersion(QString::fromLatin1(VERSION));
rrenkert@333:     QSettings::setDefaultFormat(QSettings::IniFormat);
rrenkert@333: 
andre@829:     if (QApplication::arguments().contains("--version")) {
andre@829:         printf (APPNAME " Version: %s \n",
andre@829:                 QApplication::applicationVersion().toLocal8Bit().constData());
andre@829:         printf (COPYRIGHT);
andre@829:         return 0;
andre@829:     }
andre@829: 
andre@1059:     if (arguments.contains("--debug")) {
andre@1059:         g_debug = true;
andre@1059:     }
andre@1072:     g_default_msg_handler = qInstallMessageHandler(filterDebugOutput);
andre@1059: 
aheinecke@420:     QTranslator translator;
aheinecke@420:     if (QLocale::system().name() == "C") {
aheinecke@420:         /* Useful for testing / development as the primary target is german */
aheinecke@420:         translator.load(":/l10n/administrator_de_DE");
aheinecke@420:     } else {
aheinecke@420:         translator.load(":/l10n/administrator_" + QLocale::system().name());
aheinecke@420:         qDebug() << "Loading translations for: " << "administrator_" +
aheinecke@420:             QLocale::system().name();
aheinecke@420:     }
aheinecke@420:     app.installTranslator(&translator);
aheinecke@420: 
andre@832:     /* Out of process calls need to be encoded in latin-1 so that they
andre@832:      * look decent on western europe's windows */
andre@832:     QTextCodec::setCodecForLocale(QTextCodec::codecForName ("ISO-8859-1"));
andre@832: 
andre@876:     /* Install static fonts */
andre@876: 
andre@876:     /* The putenv here works around a bug in qt. 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: 
rrenkert@333:     AdministratorWindow adminWin;
rrenkert@333:     adminWin.show();
rrenkert@333: 
rrenkert@333:     return app.exec();
rrenkert@333: }