Ejemplo n.º 1
0
int main(int argc, char *argv[])
{
  try
  {
    QCommandLineParser parser;
    parser.setApplicationDescription("Plex Media Player");
    parser.addHelpOption();
    parser.addVersionOption();
    parser.addOptions({{{"l", "licenses"}, "Show license information"}});
    parser.addOptions({{{"a", "from-auto-update"}, "When invoked from auto-update"}});

    char **newArgv = appendCommandLineArguments(argc, argv, g_qtFlags);
    argc += g_qtFlags.size();

    // Suppress SSL related warnings on OSX
    // See https://bugreports.qt.io/browse/QTBUG-43173 for more info
    //
#ifdef Q_OS_MAC
    qputenv("QT_LOGGING_RULES", "qt.network.ssl.warning=false");
#endif

    // Qt calls setlocale(LC_ALL, "") in a bunch of places, which breaks
    // float/string processing in mpv and ffmpeg.
#ifdef Q_OS_UNIX
    qputenv("LC_ALL", "C");
    qputenv("LC_NUMERIC", "C");
#endif

    detectOpenGLEarly();

    preinitQt();

    QGuiApplication app(argc, newArgv);
    app.setWindowIcon(QIcon(":/images/icon.png"));

    // Get the arguments from the app, this is the parsed version of newArgc and newArgv
    QStringList args = app.arguments();

    // Remove the qt flags above so that our command line parser doesn't get cranky.
    for (auto flag : g_qtFlags)
      args.removeAll(flag);

    // Now parse the command line.
    parser.process(args);

    if (parser.isSet("licenses"))
    {
      ShowLicenseInfo();
      return EXIT_SUCCESS;
    }

    // init breakpad.
    setupCrashDumper();

    UniqueApplication* uniqueApp = new UniqueApplication();
    if (!uniqueApp->ensureUnique())
      return EXIT_SUCCESS;

#ifdef Q_OS_UNIX
    // install signals handlers for proper app closing.
    SignalManager signalManager(&app);
    Q_UNUSED(signalManager);
#endif

    Log::Init();

    // Quit app and apply update if we find one.
    if (UpdateManager::CheckForUpdates())
    {
      app.quit();
      return 0;
    }

    detectOpenGLLate();

#ifdef Q_OS_WIN32
    initD3DDevice();
#endif

    Codecs::preinitCodecs();

    // Initialize all the components. This needs to be done
    // early since most everything else relies on it
    //
    ComponentManager::Get().initialize();

    // enable remote inspection if we have the correct setting for it.
    if (SettingsComponent::Get().value(SETTINGS_SECTION_MAIN, "remoteInspector").toBool())
      qputenv("QTWEBENGINE_REMOTE_DEBUGGING", "0.0.0.0:9992");

    QtWebEngine::initialize();

    // start our helper
    HelperLauncher::Get().connectToHelper();

    // load QtWebChannel so that we can register our components with it.
    QQmlApplicationEngine *engine = Globals::Engine();

    KonvergoWindow::RegisterClass();
    Globals::SetContextProperty("components", &ComponentManager::Get().getQmlPropertyMap());

    // the only way to detect if QML parsing fails is to hook to this signal and then see
    // if we get a valid object passed to it. Any error messages will be reported on stderr
    // but since no normal user should ever see this it should be fine
    //
    QObject::connect(engine, &QQmlApplicationEngine::objectCreated, [=](QObject* object, const QUrl& url)
    {
      Q_UNUSED(url);

      if (object == nullptr)
        throw FatalException(QObject::tr("Failed to parse application engine script."));

      KonvergoWindow* window = Globals::MainWindow();

      QObject* webChannel = qvariant_cast<QObject*>(window->property("webChannel"));
      Q_ASSERT(webChannel);
      ComponentManager::Get().setWebChannel(qobject_cast<QWebChannel*>(webChannel));

      QObject::connect(uniqueApp, &UniqueApplication::otherApplicationStarted, window, &KonvergoWindow::otherAppFocus);
    });
    engine->load(QUrl(QStringLiteral("qrc:/ui/webview.qml")));

    Log::UpdateLogLevel();

    // run our application
    int ret = app.exec();

    delete uniqueApp;
    Globals::EngineDestroy();

    Log::Uninit();
    return ret;
  }
  catch (FatalException& e)
  {
    QLOG_FATAL() << "Unhandled FatalException:" << qPrintable(e.message());
    QApplication errApp(argc, argv);

    auto  msg = new ErrorMessage(e.message(), true);
    msg->show();

    errApp.exec();

    Log::Uninit();
    return 1;
  }
}
Ejemplo n.º 2
0
int main(int argc, char *argv[])
{
    qputenv("QTWEBENGINE_REMOTE_DEBUGGING", "19260");

#if (QT_VERSION >= QT_VERSION_CHECK(5, 6, 0))
    QApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
#endif

    detectOpenGLEarly();

    Application a(argc, argv);
    if (!a.parseArgs())
        return 0;

    detectOpenGLLate();


    // Print python error to console on Windows
#ifdef Q_OS_WIN
    qputenv("PYTHONHOME", getAppPath().toUtf8());
    qputenv("PYTHONPATH", getAppPath().toUtf8() + "/Lib;" + getAppPath().toUtf8() + "/DLLs");
    bool win_debug = AttachConsole(ATTACH_PARENT_PROCESS);
    if (win_debug)
    {
        freopen("CON", "w", stdout);
        freopen("CON", "w", stderr);
        freopen("CON", "r", stdin);
    }
#endif

    //for mpv
    setlocale(LC_NUMERIC, "C");

    //init
    access_manager = new NetworkAccessManager(&a);
    printf("Initialize settings...\n");
    initSettings();

    printf("Initialize API for Python...\n");
    initPython();

    // Translate moonplayer
    printf("Initialize language support...\n");
    QTranslator qtTranslator;
    if (qtTranslator.load("qt_" + QLocale::system().name(), getQtTranslationsPath()))
        a.installTranslator(&qtTranslator);

    QTranslator translator;
    if (translator.load("moonplayer_" + QLocale::system().name(), getAppPath() + "/translations"))
        a.installTranslator(&translator);

    // Create window
    PlayerView *player_view = new PlayerView;
    player_view->show();

    // Create video parsers
    parser_ykdl = new ParserYkdl(&a);
    parser_youtubedl = new ParserYoutubeDL(&a);
#ifdef MP_ENABLE_WEBENGINE
    parser_webcatch = new ParserWebCatch(&a);
#endif

    a.exec();
    Py_Finalize();
    delete player_view;
    return 0;
}