示例#1
0
文件: main.cpp 项目: vadi2/Mudlet2
int main(int argc, char *argv[])
{
//    #ifdef QT_DEBUG
//        debugStreamFile.open(QFile::WriteOnly | QFile::Truncate);
//    #endif

    //FIXME qInstallMsgHandler( debugOutput );
    spDebugConsole = 0;

    Q_INIT_RESOURCE(mudlet_alpha);
    QApplication app(argc, argv);
    app.setOrganizationName("Mudlet");
    app.setApplicationName("Mudlet");
    app.setApplicationVersion(APP_VERSION);
    QPixmap pixmap(":/Mudlet_splashscreen_main.png");
    QSplashScreen splash(pixmap);
    QString startupMessage;
    if( QByteArray( APP_BUILD ).isEmpty() )
        startupMessage = QString("Mudlet\n(Release version: ") % APP_VERSION % QString(")\n\n");
    else
        startupMessage = QString("Mudlet\n(Development version: ") % APP_VERSION % APP_BUILD % QString(")\n\n");

    // Following is suggested by GPL documentation
    startupMessage.append("Copyright " % QChar(169) % "2014   Heiko K" % QChar(246) % "hn\n\n");
    startupMessage.append("Mudlet comes with\nABSOLUTELY NO WARRANTY\n\n");
    startupMessage.append("This is free software, and you are welcome to\n");
    startupMessage.append("redistribute it under certain conditions;\nselect the 'About' item for details.\n\nLoading profiles...");

    splash.show();
    splash.showMessage(startupMessage, Qt::AlignHCenter);

    app.processEvents();
    //qt_ntfs_permission_lookup++; // turn permission checking on on NTFS file systems
    QTime t;
    t.start();
    while( t.elapsed() < 1000 )
        ; // Do nothing here for a second

    QString directory = QDir::homePath()+"/.config/mudlet";
    QDir dir;
    if( ! dir.exists( directory ) )
    {
        dir.mkpath( directory );
    }

    // QFile file_doc(":/mudlet_documentation.html");
    // QFile file_doc_old;
    // file_doc_old.setFileName( directory+"/mudlet_documentation.html" );
    // if( file_doc_old.exists() )
    // {
        //NOTE: B. von Roeder found out that the removal of old versions may *sometimes* fail on windows 7 due permission issues
        // if( ! file_doc_old.setPermissions( QFile::WriteOwner | QFile::ReadOwner | QFile::ReadUser | QFile::WriteUser | QFile::ReadOther | QFile::WriteOther ) )
        // {
            // cout << "[ERROR] could not set file permissions of the old version of the manual" << endl;
            // gSysErrors << "[ERROR] could not set file permissions of the old version of the manual";
        // }
        // string old_man_path = directory.toLatin1().data();
        // old_man_path += "/mudlet_documentation.html";
        // bool ok=file_doc_old.remove();
        // if( ok )
        // {
            // cout << "[INFO] deleted old version of the manual: " << old_man_path << endl;
        // }
        // else
        // {
            // cout << "[ERROR] could not remove old version of the manual: " << old_man_path << endl;
            // QString _m = "[ERROR] could not remove old version of the manual: ";
            // _m.append( old_man_path.c_str() );
            // gSysErrors << _m;
        // }
    // }
    // else
    // {
        // gSysErrors << "[INFO] no old version of the manual found";
    // }
    // if( file_doc.copy( directory+"/mudlet_documentation.html" ) )
    // {
        // cout << "[OK] successfully copied new version of the manual" << endl;
        // QString _m = "[INFO] local manual: ";
        // _m.append( directory );
        // gSysErrors << _m;
    // }
    // else
    // {
        // cout << "[ERROR] copy of new version of the manual failed" << endl;
        // gSysErrors << "[ERROR] copy of new version of the manual failed";
    // }
    // QFile file_lua(":/LuaGlobal.lua");

    // QFile file_lua_old( directory+"/LuaGlobal.lua" );
    // if( ! file_lua_old.setPermissions( QFile::WriteOwner | QFile::ReadOwner | QFile::ReadUser | QFile::WriteUser | QFile::ReadOther | QFile::WriteOther ) )
    // {
        // cout << "[ERROR] failed to set file permissions for the old version of LuaGlobal.lua" << endl;
        // gSysErrors << "[ERROR] failed to set file permissions for the old version of LuaGlobal.lua";
    // }
    // else
    // {
        // cout << "[OK] successfully set file permissions for the old version of LuaGlobal.lua" << endl;
    // }
    // if( file_lua_old.remove() )
    // {
        // cout << "[OK] old LuaGlobal.lua removed successfully" << endl;
        // gSysErrors << "[INFO] old LuaGlobal.lua removed successfully";
    // }
    // else
    // {
        // cout << "[ERROR] failed to remove the old version of LuaGlobal.lua" << endl;
        // gSysErrors << "[ERROR] failed to remove the old version of LuaGlobal.lua";
    // }
    // if( file_lua.copy( directory+"/LuaGlobal.lua" ) )
    // {
        // cout << "[OK] new version of LuaGlobal.lua copied successfully" << endl;
        // gSysErrors << "[INFO] LuaGlobal.lua restored successfully";
        // QFile file_lua_new(directory+"/LuaGlobal.lua");
        // if( ! file_lua_new.setPermissions( QFile::WriteOwner | QFile::ReadOwner | QFile::ReadUser | QFile::WriteUser | QFile::ReadOther | QFile::WriteOther ) )
        // {
            // cout << "[ERROR] failed to set file permissions for the new version of LuaGlobal.lua" << endl;
            // gSysErrors << "[ERROR] failed to set file permissions for the new version of LuaGlobal.lua";
        // }
        // else
        // {
            // cout << "[OK] successfully set file permissions for the new version of LuaGlobal.lua" << endl;
        // }
    // }

    // QFile file_db(":/db.lua");

    // QFile file_db_old( directory+"/db.lua" );
    // if( ! file_db_old.setPermissions( QFile::WriteOwner | QFile::ReadOwner | QFile::ReadUser | QFile::WriteUser | QFile::ReadOther | QFile::WriteOther ) )
    // {
        // cout << "[ERROR] failed to set file permissions for the old version of db.lua" << endl;
        // gSysErrors << "[ERROR] failed to set file permissions for the old version of db.lua";
    // }
    // else
    // {
        // cout << "[OK] successfully set file permissions for the old version of db.lua" << endl;
    // }
    // if( file_db_old.remove() )
    // {
        // cout << "[OK] old db.lua removed successfully" << endl;
        // gSysErrors << "[INFO] old db.lua removed successfully";
    // }
    // else
    // {
        // cout << "[ERROR] failed to remove the old version of db.lua" << endl;
        // gSysErrors << "[ERROR] failed to remove the old version of db.lua";
    // }
    // if( file_db.copy( directory+"/db.lua" ) )
    // {
        // cout << "[OK] new version of db.lua copied successfully" << endl;
        // gSysErrors << "[INFO] db.lua restored successfully";
        // QFile file_db_new(directory+"/db.lua");
        // if( ! file_db_new.setPermissions( QFile::WriteOwner | QFile::ReadOwner | QFile::ReadUser | QFile::WriteUser | QFile::ReadOther | QFile::WriteOther ) )
        // {
            // cout << "[ERROR] failed to set file permissions for the new version of db.lua" << endl;
            // gSysErrors << "[ERROR] failed to set file permissions for the new version of db.lua";
        // }
        // else
        // {
            // cout << "[OK] successfully set file permissions for the new version of db.lua" << endl;
        // }
    // }
    startupMessage.append(" Done.\nLoading font files...");
    splash.showMessage(startupMessage, Qt::AlignHCenter);
    app.processEvents();
    t.restart();
    while( t.elapsed() < 1000 )
        ; // Do nothing here for a second


    QFile file_f1(":/fonts/ttf-bitstream-vera-1.10/COPYRIGHT.TXT");
    file_f1.copy( directory+"/COPYRIGHT.TXT" );

    QFile file_f2(":/fonts/ttf-bitstream-vera-1.10/RELEASENOTES.TXT");
    file_f2.copy( directory+"/RELEASENOTES.TXT" );

    QFile file_f3(":/fonts/ttf-bitstream-vera-1.10/VeraMoIt.ttf");
    file_f3.copy( directory+"/VeraMoIt.ttf" );

    QFile file_f4(":/fonts/ttf-bitstream-vera-1.10/local.conf");
    file_f4.copy( directory+"/local.conf" );

    QFile file_f5(":/fonts/ttf-bitstream-vera-1.10/VeraMoBd.ttf");
    file_f5.copy( directory+"/VeraMoBd.ttf" );

    QFile file_f6(":/fonts/ttf-bitstream-vera-1.10/VeraMoBd.ttf");
    file_f6.copy( directory+"/VeraMoBd.ttf" );

    QFile file_f7(":/fonts/ttf-bitstream-vera-1.10/README.TXT");
    file_f7.copy( directory+"/README.TXT" );

    QFile file_f8(":/fonts/ttf-bitstream-vera-1.10/VeraMoBI.ttf");
    file_f8.copy( directory+"/VeraMoBI.ttf" );

    QFile file_f9(":/fonts/ttf-bitstream-vera-1.10/VeraMono.ttf");
    file_f9.copy( directory+"/VeraMono.ttf" );

    /*QFile file_f(":/fonts/ttf-bitstream-vera-1.10/");
    file_f.copy( directory+"/" );

    QFile file_f(":/fonts/ttf-bitstream-vera-1.10/");
    file_f.copy( directory+"/" );

    QFile file_f(":/fonts/ttf-bitstream-vera-1.10/");
    file_f.copy( directory+"/" );  */
    startupMessage.append(" Done.\nAll data has been loaded successfully.\nStarting...\n\n\nHave fun!");
    splash.showMessage(startupMessage, Qt::AlignHCenter);
    app.processEvents();
    t.restart();
    while( t.elapsed() < 1000 )
        ; // Do nothing here for a second

    splash.finish( mudlet::self() );  // This seems to be the point at which instance of mudlet is created!!!
    mudlet::debugMode = false;
    HostManager::self();
    FontManager fm;
    fm.addFonts();
    QString home = QDir::homePath()+"/.config/mudlet";
    QString homeLink = QDir::homePath()+"/mudlet-data";
    QFile::link(home, homeLink);
    mudlet::self()->show();
    app.exec();
}
示例#2
0
文件: main.cpp 项目: olostan/mudlet
int main(int argc, char *argv[])
{

    debugStreamFile.open(QFile::WriteOnly | QFile::Truncate);

    spDebugConsole = 0;
    qInstallMsgHandler( debugOutput );

    Q_INIT_RESOURCE(mudlet_alpha);
    QApplication app(argc, argv);
    app.setApplicationName("Mudlet");
    QPixmap pixmap(":/Mudlet_splashscreen_main");
    QSplashScreen splash(pixmap);
    splash.show();

    splash.showMessage("Loading profiles ...");

    app.processEvents();
    //qt_ntfs_permission_lookup++; // turn permission checking on on NTFS file systems

    QString directory = QDir::homePath()+"/.config/mudlet";
    QDir dir;
    if( ! dir.exists( directory ) )
    {
        dir.mkpath( directory );
    }

    // QFile file_doc(":/mudlet_documentation.html");
    // QFile file_doc_old;
    // file_doc_old.setFileName( directory+"/mudlet_documentation.html" );
    // if( file_doc_old.exists() )
    // {
        //NOTE: B. von Roeder found out that the removal of old versions may *sometimes* fail on windows 7 due permission issues
        // if( ! file_doc_old.setPermissions( QFile::WriteOwner | QFile::ReadOwner | QFile::ReadUser | QFile::WriteUser | QFile::ReadOther | QFile::WriteOther ) )
        // {
            // cout << "[ERROR] could not set file permissions of the old version of the manual" << endl;
            // gSysErrors << "[ERROR] could not set file permissions of the old version of the manual";
        // }
        // string old_man_path = directory.toLatin1().data();
        // old_man_path += "/mudlet_documentation.html";
        // bool ok=file_doc_old.remove();
        // if( ok )
        // {
            // cout << "[INFO] deleted old version of the manual: " << old_man_path << endl;
        // }
        // else
        // {
            // cout << "[ERROR] could not remove old version of the manual: " << old_man_path << endl;
            // QString _m = "[ERROR] could not remove old version of the manual: ";
            // _m.append( old_man_path.c_str() );
            // gSysErrors << _m;
        // }
    // }
    // else
    // {
        // gSysErrors << "[INFO] no old version of the manual found";
    // }
    // if( file_doc.copy( directory+"/mudlet_documentation.html" ) )
    // {
        // cout << "[OK] successfully copied new version of the manual" << endl;
        // QString _m = "[INFO] local manual: ";
        // _m.append( directory );
        // gSysErrors << _m;
    // }
    // else
    // {
        // cout << "[ERROR] copy of new version of the manual failed" << endl;
        // gSysErrors << "[ERROR] copy of new version of the manual failed";
    // }
    // QFile file_lua(":/LuaGlobal.lua");

    // QFile file_lua_old( directory+"/LuaGlobal.lua" );
    // if( ! file_lua_old.setPermissions( QFile::WriteOwner | QFile::ReadOwner | QFile::ReadUser | QFile::WriteUser | QFile::ReadOther | QFile::WriteOther ) )
    // {
        // cout << "[ERROR] failed to set file permissions for the old version of LuaGlobal.lua" << endl;
        // gSysErrors << "[ERROR] failed to set file permissions for the old version of LuaGlobal.lua";
    // }
    // else
    // {
        // cout << "[OK] successfully set file permissions for the old version of LuaGlobal.lua" << endl;
    // }
    // if( file_lua_old.remove() )
    // {
        // cout << "[OK] old LuaGlobal.lua removed successfully" << endl;
        // gSysErrors << "[INFO] old LuaGlobal.lua removed successfully";
    // }
    // else
    // {
        // cout << "[ERROR] failed to remove the old version of LuaGlobal.lua" << endl;
        // gSysErrors << "[ERROR] failed to remove the old version of LuaGlobal.lua";
    // }
    // if( file_lua.copy( directory+"/LuaGlobal.lua" ) )
    // {
        // cout << "[OK] new version of LuaGlobal.lua copied successfully" << endl;
        // gSysErrors << "[INFO] LuaGlobal.lua restored successfully";
        // QFile file_lua_new(directory+"/LuaGlobal.lua");
        // if( ! file_lua_new.setPermissions( QFile::WriteOwner | QFile::ReadOwner | QFile::ReadUser | QFile::WriteUser | QFile::ReadOther | QFile::WriteOther ) )
        // {
            // cout << "[ERROR] failed to set file permissions for the new version of LuaGlobal.lua" << endl;
            // gSysErrors << "[ERROR] failed to set file permissions for the new version of LuaGlobal.lua";
        // }
        // else
        // {
            // cout << "[OK] successfully set file permissions for the new version of LuaGlobal.lua" << endl;
        // }
    // }

    // QFile file_db(":/db.lua");

    // QFile file_db_old( directory+"/db.lua" );
    // if( ! file_db_old.setPermissions( QFile::WriteOwner | QFile::ReadOwner | QFile::ReadUser | QFile::WriteUser | QFile::ReadOther | QFile::WriteOther ) )
    // {
        // cout << "[ERROR] failed to set file permissions for the old version of db.lua" << endl;
        // gSysErrors << "[ERROR] failed to set file permissions for the old version of db.lua";
    // }
    // else
    // {
        // cout << "[OK] successfully set file permissions for the old version of db.lua" << endl;
    // }
    // if( file_db_old.remove() )
    // {
        // cout << "[OK] old db.lua removed successfully" << endl;
        // gSysErrors << "[INFO] old db.lua removed successfully";
    // }
    // else
    // {
        // cout << "[ERROR] failed to remove the old version of db.lua" << endl;
        // gSysErrors << "[ERROR] failed to remove the old version of db.lua";
    // }
    // if( file_db.copy( directory+"/db.lua" ) )
    // {
        // cout << "[OK] new version of db.lua copied successfully" << endl;
        // gSysErrors << "[INFO] db.lua restored successfully";
        // QFile file_db_new(directory+"/db.lua");
        // if( ! file_db_new.setPermissions( QFile::WriteOwner | QFile::ReadOwner | QFile::ReadUser | QFile::WriteUser | QFile::ReadOther | QFile::WriteOther ) )
        // {
            // cout << "[ERROR] failed to set file permissions for the new version of db.lua" << endl;
            // gSysErrors << "[ERROR] failed to set file permissions for the new version of db.lua";
        // }
        // else
        // {
            // cout << "[OK] successfully set file permissions for the new version of db.lua" << endl;
        // }
    // }


    QFile file_f1(":/fonts/ttf-bitstream-vera-1.10/COPYRIGHT.TXT");
    file_f1.copy( directory+"/COPYRIGHT.TXT" );

    QFile file_f2(":/fonts/ttf-bitstream-vera-1.10/RELEASENOTES.TXT");
    file_f2.copy( directory+"/RELEASENOTES.TXT" );

    QFile file_f3(":/fonts/ttf-bitstream-vera-1.10/VeraMoIt.ttf");
    file_f3.copy( directory+"/VeraMoIt.ttf" );

    QFile file_f4(":/fonts/ttf-bitstream-vera-1.10/local.conf");
    file_f4.copy( directory+"/local.conf" );

    QFile file_f5(":/fonts/ttf-bitstream-vera-1.10/VeraMoBd.ttf");
    file_f5.copy( directory+"/VeraMoBd.ttf" );

    QFile file_f6(":/fonts/ttf-bitstream-vera-1.10/VeraMoBd.ttf");
    file_f6.copy( directory+"/VeraMoBd.ttf" );

    QFile file_f7(":/fonts/ttf-bitstream-vera-1.10/README.TXT");
    file_f7.copy( directory+"/README.TXT" );

    QFile file_f8(":/fonts/ttf-bitstream-vera-1.10/VeraMoBI.ttf");
    file_f8.copy( directory+"/VeraMoBI.ttf" );

    QFile file_f9(":/fonts/ttf-bitstream-vera-1.10/VeraMono.ttf");
    file_f9.copy( directory+"/VeraMono.ttf" );

    /*QFile file_f(":/fonts/ttf-bitstream-vera-1.10/");
    file_f.copy( directory+"/" );

    QFile file_f(":/fonts/ttf-bitstream-vera-1.10/");
    file_f.copy( directory+"/" );

    QFile file_f(":/fonts/ttf-bitstream-vera-1.10/");
    file_f.copy( directory+"/" );  */
    splash.showMessage("All data has been loaded successfully.\n\nHave fun!");
    QTime t;
    t.start();
    while( t.elapsed() < 1500 );
    splash.finish( mudlet::self() );
    mudlet::debugMode = false;
    HostManager::self();
    FontManager fm;
    fm.addFonts();
    mudlet::self()->show();
    app.exec();
}
示例#3
0
文件: main.cpp 项目: SlySven/Mudlet
int main(int argc, char* argv[])
{
#if defined(_MSC_VER) && defined(_DEBUG)
    // Enable leak detection for MSVC debug builds.
    {
        // Check for a debugger and prompt if one is not attached.
        while (!IsDebuggerPresent()
               && IDYES == MessageBox(0,
                                      "You are starting debug mudlet without a debugger attached. If you wish to attach one and verify that it worked, click yes. To continue without a debugger, click no.",
                                      "Mudlet Debug",
                                      MB_ICONINFORMATION | MB_YESNO | MB_DEFBUTTON2))
            ;

        // _CRTDBG_ALLOC_MEM_DF: Enable heap debugging.
        // _CRTDBG_LEAK_CHECK_DF: Check for leaks at program exit.
        _CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF);

        // Create a log file for writing leaks.
        HANDLE hLogFile = CreateFile("stderr.txt", GENERIC_WRITE,
            FILE_SHARE_WRITE, NULL, CREATE_ALWAYS,
            FILE_ATTRIBUTE_NORMAL, NULL);
        _CrtSetReportMode(_CRT_WARN, _CRTDBG_MODE_FILE);
        _CrtSetReportFile(_CRT_WARN, hLogFile);

        // Set this to break on the allocation number shown in the debug output above.
        // _crtBreakAlloc = 0;

        pcre_malloc = pcre_malloc_dbg;
        pcre_free = pcre_free_dbg;
        pcre_stack_malloc = pcre_malloc_dbg;
        pcre_stack_free = pcre_free_dbg;
    }
#endif // _MSC_VER && _DEBUG
    spDebugConsole = 0;
    unsigned int startupAction = 0;

    Q_INIT_RESOURCE(mudlet_alpha);

    QScopedPointer<QCoreApplication> initApp(createApplication(argc, argv, startupAction));

    QApplication* app = qobject_cast<QApplication*>(initApp.data());

    // Non-GUI actions --help and --version as suggested by GNU coding standards,
    // section 4.7: http://www.gnu.org/prep/standards/standards.html#Command_002dLine-Interfaces
    if (app == 0) {
        if (startupAction & 2) {
            // Do "version" action - wording and format is quite tightly specified by the coding standards
            std::cout << APP_TARGET << " " << APP_VERSION << APP_BUILD << std::endl;
            std::cout << "Qt libraries " << QT_VERSION_STR << "(compilation) " << qVersion() << "(runtime)" << std::endl;
            std::cout << "Copyright (C) 2008-" << std::string(__DATE__).substr(7, 4) << " Mudlet devs." << std::endl;
            std::cout << "Licence GPLv2+: GNU GPL version 2 or later <http://gnu.org/licenses/gpl.html>" << std::endl;
            std::cout << "This is free software: you are free to change and redistribute it." << std::endl;
            std::cout << "There is NO WARRANTY, to the extent permitted by law." << std::endl;
        }
        if (startupAction & 1) {
            // Do "help" action -
            std::cout << "Usage: " << std::string(APP_TARGET) << "[OPTION...]" << std::endl;
#if defined(Q_OS_WIN32)
            std::cout << "   /h, /help           displays this message." << std::endl;
            std::cout << "   /v, /version        displays version information." << std::endl;
            std::cout << "   /q, /quiet          no splash screen on startup." << std::endl;
#define OPT_PREFIX '/'
#else
            std::cout << "   -h, --help          displays this message." << std::endl;
            std::cout << "   -v, --version       displays version information." << std::endl;
            std::cout << "   -q, --quiet         no splash screen on startup." << std::endl;
#define OPT_PREFIX '-'
#endif
            std::cout << "There are other inherited options that arise from the Qt Libraries which" << std::endl;
            std::cout << "are not likely to be useful for normal use of this application:" << std::endl;
            // From documentation and from http://qt-project.org/doc/qt-5/qapplication.html:
            std::cout << "       " << OPT_PREFIX << "dograb         ignore any implicit or explicit -nograb." << std::endl;
            std::cout << "                       " << OPT_PREFIX << "dograb wins over " << OPT_PREFIX << "nograb even when" << std::endl;
            std::cout << "                       " << OPT_PREFIX << "nograb is last on the command line." << std::endl;
            std::cout << "       " << OPT_PREFIX << "nograb         the application should never grab the mouse or the" << std::endl;
#if defined(Q_OS_LINUX)
            std::cout << "                       keyboard. This option is set by default when Mudlet is" << std::endl;
            std::cout << "                       running in the gdb debugger under Linux." << std::endl;
#else
            std::cout << "                       keyboard." << std::endl;
#endif
            std::cout << "        " << OPT_PREFIX << "reverse       sets the application's layout direction to" << std::endl;
            std::cout << "                       right to left." << std::endl;
            std::cout << "        " << OPT_PREFIX << "style= style  sets the application GUI style. Possible values depend" << std::endl;
            std::cout << "                       on your system configuration. If Qt was compiled with" << std::endl;
            std::cout << "                       additional styles or has additional styles as plugins" << std::endl;
            std::cout << "                       these will be available to the -style command line" << std::endl;
            std::cout << "                       option. You can also set the style for all Qt" << std::endl;
            std::cout << "                       applications by setting the QT_STYLE_OVERRIDE environment" << std::endl;
            std::cout << "                       variable." << std::endl;
            std::cout << "        " << OPT_PREFIX << "style style   is the same as listed above." << std::endl;
            std::cout << "        " << OPT_PREFIX << "stylesheet= stylesheet" << std::endl;
            std::cout << "                       sets the application styleSheet." << std::endl;
            std::cout << "                       The value must be a path to a file that contains the" << std::endl;
            std::cout << "                       Style Sheet. Note: Relative URLs in the Style Sheet" << std::endl;
            std::cout << "                       file are relative to the Style Sheet file's path." << std::endl;
            std::cout << "        " << OPT_PREFIX << "stylesheet stylesheet" << std::endl;
            std::cout << "                       is the same as listed above." << std::endl;
#if defined(Q_OS_UNIX)
            std::cout << "        " << OPT_PREFIX << "sync          runs Mudlet in X synchronous mode. Synchronous mode" << std::endl;
            std::cout << "                       forces the X server to perform each X client request" << std::endl;
            std::cout << "                       immediately and not use buffer optimization. It makes" << std::endl;
            std::cout << "                       the program easier to debug and often much slower. The" << std::endl;
            std::cout << "                       -sync option is only valid for the X11 version of Qt." << std::endl;
#endif
            std::cout << "        " << OPT_PREFIX << "widgetcount   prints debug message at the end about number of widgets" << std::endl;
            std::cout << "                       left undestroyed and maximum number of widgets existing" << std::endl;
            std::cout << "                       at the same time." << std::endl;
            std::cout << "        " << OPT_PREFIX << "qmljsdebugger=1234[,block]" << std::endl;
            std::cout << "                       activates the QML/JS debugger with a specified port." << std::endl;
            std::cout << "                       The number is the port value and block is optional" << std::endl;
            std::cout << "                       and will make the application wait until a debugger" << std::endl;
            std::cout << "                       connects to it." << std::endl;
            std::cout << std::endl;
            std::cout << "Report bugs to: <https://github.com/Mudlet/Mudlet/issues>" << std::endl;
            std::cout << "pkg home page: <http://www.mudlet.org/>" << std::endl;
        }
        return 0;
    }

    // Turn the cursor into the waiting one during startup, so something shows
    // activity even if the quiet, no splashscreen startup has been used
    app->setOverrideCursor(QCursor(Qt::WaitCursor));
    app->setOrganizationName("Mudlet");
    app->setApplicationName("Mudlet");
    app->setApplicationVersion(APP_VERSION);

    bool show_splash = !(startupAction & 4); // Not --quiet.

    QImage splashImage(":/Mudlet_splashscreen_main.png");
    if (show_splash) {
        QPainter painter(&splashImage);
        unsigned fontSize = 16;
        QString sourceVersionText = QString("Version: " APP_VERSION APP_BUILD);

        bool isWithinSpace = false;
        while (!isWithinSpace) {
            QFont font("DejaVu Serif", fontSize, QFont::Bold | QFont::Serif | QFont::PreferMatch | QFont::PreferAntialias);
            QTextLayout versionTextLayout(sourceVersionText, font, painter.device());
            versionTextLayout.beginLayout();
            // Start work in this text item
            QTextLine versionTextline = versionTextLayout.createLine();
            // First draw (one line from) the text we have put in on the layout to
            // see how wide it is..., assuming accutally that it will only take one
            // line of text
            versionTextline.setLineWidth(280);
            //Splashscreen bitmap is (now) 320x360 - hopefully entire line will all fit into 280
            versionTextline.setPosition(QPointF(0, 0));
            // Only pretend, so we can see how much space it will take
            QTextLine dummy = versionTextLayout.createLine();
            if (!dummy.isValid()) {
                // No second line so have got all text in first so can do it
                isWithinSpace = true;
                qreal versionTextWidth = versionTextline.naturalTextWidth();
                // This is the ACTUAL width of the created text
                versionTextline.setPosition(QPointF((320 - versionTextWidth) / 2.0, 270));
                // And now we can place it centred horizontally
                versionTextLayout.endLayout();
                // end the layout process and paint it out
                painter.setPen(QColor(176, 64, 0, 255)); // #b04000
                versionTextLayout.draw(&painter, QPointF(0, 0));
            } else {
                // Too big - text has spilled over onto a second line - so try again
                fontSize--;
                versionTextLayout.clearLayout();
                versionTextLayout.endLayout();
            }
        }

        // Repeat for other text, but we know it will fit at given size
        QString sourceCopyrightText = QChar(169) % QString(" Mudlet makers 2008-") % QString(__DATE__).mid(7);
        QFont font("DejaVu Serif", 16, QFont::Bold | QFont::Serif | QFont::PreferMatch | QFont::PreferAntialias);
        QTextLayout copyrightTextLayout(sourceCopyrightText, font, painter.device());
        copyrightTextLayout.beginLayout();
        QTextLine copyrightTextline = copyrightTextLayout.createLine();
        copyrightTextline.setLineWidth(280);
        copyrightTextline.setPosition(QPointF(1, 1));
        qreal copyrightTextWidth = copyrightTextline.naturalTextWidth();
        copyrightTextline.setPosition(QPointF((320 - copyrightTextWidth) / 2.0, 340));
        copyrightTextLayout.endLayout();
        painter.setPen(QColor(112, 16, 0, 255)); // #701000
        copyrightTextLayout.draw(&painter, QPointF(0, 0));
    }
    QPixmap pixmap = QPixmap::fromImage(splashImage);
    QSplashScreen splash(pixmap);
    if (show_splash) {
        splash.show();
    }
    app->processEvents();

    QString splash_message;
    if (show_splash) {
        splash_message.append("\n\nMudlet comes with\n"
                              "ABSOLUTELY NO WARRANTY!\n"
                              "This is free software, and you are\n"
                              "welcome to redistribute it under\n"
                              "certain conditions; select the\n"
                              "'About' item for details.\n\n");
        splash_message.append("Locating profiles... ");
        splash.showMessage(splash_message, Qt::AlignHCenter | Qt::AlignTop);
        app->processEvents();
    }

    QString directory = QDir::homePath() + "/.config/mudlet";
    QDir dir;
    if (!dir.exists(directory)) {
        dir.mkpath(directory);
    }

    if (show_splash) {
        splash_message.append("Done.\n\nLoading font files... ");
        splash.showMessage(splash_message, Qt::AlignHCenter | Qt::AlignTop);
        app->processEvents();
    }

    if (!QFile::exists(directory + "/COPYRIGHT.TXT")) {
        QFile file_f1(":/fonts/ttf-bitstream-vera-1.10/COPYRIGHT.TXT");
        file_f1.copy(directory + "/COPYRIGHT.TXT");
    }

    if (!QFile::exists(directory + "/RELEASENOTES.TXT")) {
        QFile file_f2(":/fonts/ttf-bitstream-vera-1.10/RELEASENOTES.TXT");
        file_f2.copy(directory + "/RELEASENOTES.TXT");
    }

    if (!QFile::exists(directory + "/VeraMoIt.ttf")) {
        QFile file_f3(":/fonts/ttf-bitstream-vera-1.10/VeraMoIt.ttf");
        file_f3.copy(directory + "/VeraMoIt.ttf");
    }

    if (!QFile::exists(directory + "/local.conf")) {
        QFile file_f4(":/fonts/ttf-bitstream-vera-1.10/local.conf");
        file_f4.copy(directory + "/local.conf");
    }

    if (!QFile::exists(directory + "/VeraMoBd.ttf")) {
        QFile file_f5(":/fonts/ttf-bitstream-vera-1.10/VeraMoBd.ttf");
        file_f5.copy(directory + "/VeraMoBd.ttf");
    }

    if (!QFile::exists(directory + "/VeraMoBd.ttf")) {
        QFile file_f6(":/fonts/ttf-bitstream-vera-1.10/VeraMoBd.ttf");
        file_f6.copy(directory + "/VeraMoBd.ttf");
    }

    if (!QFile::exists(directory + "/README.TXT")) {
        QFile file_f7(":/fonts/ttf-bitstream-vera-1.10/README.TXT");
        file_f7.copy(directory + "/README.TXT");
    }

    if (!QFile::exists(directory + "/VeraMoBI.ttf")) {
        QFile file_f8(":/fonts/ttf-bitstream-vera-1.10/VeraMoBI.ttf");
        file_f8.copy(directory + "/VeraMoBI.ttf");
    }

    if (!QFile::exists(directory + "/VeraMono.ttf")) {
        QFile file_f9(":/fonts/ttf-bitstream-vera-1.10/VeraMono.ttf");
        file_f9.copy(directory + "/VeraMono.ttf");
    }

    if (show_splash) {
        splash_message.append("Done.\n\n"
                              "All data has been loaded successfully.\n\n"
                              "Starting... Have fun!\n\n");
        splash.showMessage(splash_message, Qt::AlignHCenter | Qt::AlignTop);
        app->processEvents();
    }

    mudlet::debugMode = false;
    FontManager fm;
    fm.addFonts();
    QString home = QDir::homePath() + "/.config/mudlet";
    QString homeLink = QDir::homePath() + "/mudlet-data";
    QFile::link(home, homeLink);
    mudlet::start();
    mudlet::self()->show();
    if (show_splash) {
        splash.finish(mudlet::self());
    }
    app->restoreOverrideCursor();
    // NOTE: Must restore cursor - BEWARE DEBUGGERS if you terminate application
    // without doing/reaching this restore - it can be quite hard to accurately
    // click something in a parent process to the application when you are stuck
    // with some OS's choice of wait cursor - you might wish to temparily disable
    // the earlier setOverrideCursor() line and this one.
    return app->exec();
}