view src/main.cpp @ 38:5354cbda7188

Fix HTML Layout. Support multiple formats at once. More handling. This commit is a bad mix of multiple changes. It addresses: - HTML Width is now relative and should fix some pdf creation problems. - Format is now taken from the extension of the file names provided. - Multiple file names are accepted at once. - Parser now handles missing values in Multiple choice answers - Parser now handles unfilled multiple choice values
author Andre Heinecke <andre.heinecke@intevation.de>
date Fri, 15 Apr 2016 15:19:04 +0200
parents 927794e3cc52
children 36ee5dd46fd3
line wrap: on
line source
/* Copyright (C) 2016 by ETH Zürich
 * Software engineering by Intevation GmbH
 *
 * This file is Free Software under the GNU GPL (v>=2)
 * and comes with ABSOLUTELY NO WARRANTY!
 * See LICENSE.txt for details.
 */

/** @file Main entry point for the application.
 *
 * This file is the wrapper around the qt application.
 * Does command line parsing and preparation of the QApplication.
 */
#include "constants.h"

#include "strhelp.h"
#include "converter.h"
#include "cconvert_options.h"

#include <QApplication>
#include <QCommandLineParser>
#include <QtPlugin>
#include <QDebug>
#include <QTranslator>
#include <QSettings>
#include <QTimer>

#ifdef Q_OS_WIN

 #include <windows.h>
 #include <shlobj.h>

 Q_IMPORT_PLUGIN(QWindowsIntegrationPlugin)
#elif defined(Q_OS_MAC)
 Q_IMPORT_PLUGIN(QCocoaIntegrationPlugin)
#else
/* this is only necessary if we build statically for GNU/Linux */
// Q_IMPORT_PLUGIN(QXcbIntegrationPlugin)
#endif

bool g_debug = false;

QtMessageHandler g_default_msg_handler = NULL;

void filterDebugOutput(QtMsgType type, const QMessageLogContext &context, const QString &msg)
{
    if (!g_debug && type == QtDebugMsg) {
        return;
    }

    if (g_default_msg_handler) {
        (*g_default_msg_handler)(type, context, msg);
    }
}

int realMain(int argc, char **argv);

#if defined(WIN32) && defined(UNICODE)

/** @brief Unicode entry point.
 *
 * Converts arguments to UTF-8 and executes the real
 * entry point realMain.
 */
int wmain(int argc, wchar_t **argv, wchar_t **envp)
{
    char **utf8args = NULL;

    utf8args = (char**) xmalloc0 ((argc + 1) * sizeof(char*));

    for (int i = 0; i < argc; i++) {
        utf8args[i] = wchar_to_utf8(argv[i], wcslen(argv[i]));
        if (utf8args[i] == NULL) {
            printf ("Fatal: could not convert arguments to UTF-8.\n");
            exit(-1);
        }
    }
    int ret = realMain(argc, utf8args);
    strv_free(utf8args);

    return ret;
}
#else
int main(int argc, char **argv)
{
    return realMain(argc, argv);
}
#endif

/** @brief The real entry point to the application.
 *
 * @param [in] argc the count of the arguments.
 * @param [in] argv On GNU/Linux this function expects argv to be in the
 * native system encoding. On Windows the arguments
 * shall be UTF-8
 *
 * @returns 0 on success an error code otherwise. */
int realMain(int argc, char **argv)
{
    /* QApplication setup */
    QApplication app (argc, argv);
    QApplication::setOrganizationName(QStringLiteral(APPNAME));
    QApplication::setApplicationName(QStringLiteral(APPNAME));
    QApplication::setApplicationVersion(QStringLiteral(VERSION));
//    QSettings::setDefaultFormat(QSettings::IniFormat);

    /* Setup translations */
    QTranslator translator;
    if (QLocale::system().name() == "C") {
        /* Useful for testing / development as the primary target is german */
        translator.load(":/l10n/main_de_DE");
    } else {
        translator.load(":/l10n/main_" + QLocale::system().name());
    }
    app.installTranslator(&translator);

    /* Parse the command line */
    QCommandLineParser parser;
    cconvert_options(parser);

    parser.process(app);

    g_debug = parser.isSet("debug");
    g_default_msg_handler = qInstallMessageHandler(filterDebugOutput);


    const QStringList args = parser.positionalArguments();
    if (args.size() > 1) {
        parser.showHelp(1);
    }

    QString infile;
    if (args.size()) {
        infile = args.first();
    }
    Converter conv(infile, parser.values("output"),
                   parser.value("title"));

    conv.start();
    conv.wait();

    const QStringList errors = conv.errors();
    if (errors.isEmpty()) {
        return 0;
    } else {
        Q_FOREACH (const QString err, errors) {
            qCritical() << err;
        }
    }
    return 1;
}
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)