Mercurial > clickerconvert
view src/main.cpp @ 13:101ee762f021
Add commented out Grouping
author | Andre Heinecke <andre.heinecke@intevation.de> |
---|---|
date | Tue, 22 Mar 2016 17:21:44 +0100 |
parents | 5c256892042c |
children | 03dad1cff5b9 |
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 QCoreApplication. */ #include "constants.h" #include "strhelp.h" #include "converter.h" #include "cconvert_options.h" #include <QCoreApplication> #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) { /* QCoreApplication setup */ QCoreApplication app (argc, argv); QCoreApplication::setOrganizationName(QStringLiteral(APPNAME)); QCoreApplication::setApplicationName(QStringLiteral(APPNAME)); QCoreApplication::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); } ConvertFormat fmt = Format_XLSX; /* Initialize the converter. */ if (parser.isSet(QStringLiteral("pdf"))) { fmt = Format_PDF; } QString infile; if (args.size()) { infile = args.first(); } Converter conv(infile, parser.value("output"), fmt, 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; }