main.cpp 9.18 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
/***************************************************************************
 *   Copyright (C) 2007 by Marco Gittler (g.marco@freenet.de)              *
 *   Copyright (C) 2008 by Jean-Baptiste Mardelle (jb@kdenlive.org)        *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program; if not, write to the                         *
 *   Free Software Foundation, Inc.,                                       *
 *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA          *
 ***************************************************************************/

21
#include <config-kdenlive.h>
22 23 24
#include "core.h"

#include <mlt++/Mlt.h>
25

26 27
#include "kxmlgui_version.h"

28
#include <KAboutData>
Vincent Pinon's avatar
Vincent Pinon committed
29 30 31 32
#ifdef USE_DRMINGW
#   include <exchndl.h>
#elif defined(KF5_USE_CRASH)
#   include <KCrash>
Vincent Pinon's avatar
Vincent Pinon committed
33
#endif
Vincent Pinon's avatar
Vincent Pinon committed
34

35
#include <KIconLoader>
36
#include <KSharedConfig>
37
#include <KConfigGroup>
38

Laurent Montel's avatar
Laurent Montel committed
39
#include "kdenlive_debug.h"
40
#include <QUrl> //new
41
#include <QDir>
42
#include <QApplication>
43
#include <klocalizedstring.h>
44 45
#include <QCommandLineParser>
#include <QCommandLineOption>
46
#include <KDBusService>
47
#include <QProcess>
48
#include <QIcon>
49

50 51
int main(int argc, char *argv[])
{
52 53 54
#ifdef USE_DRMINGW
    ExcHndlInit();
#endif
55
    // Force QDomDocument to use a deterministic XML attribute order
56 57 58
#if (QT_VERSION >= QT_VERSION_CHECK(5, 6, 0))
    qSetGlobalQHashSeed(0);
#else
59 60
    extern Q_CORE_EXPORT QBasicAtomicInt qt_qhash_seed;
    qt_qhash_seed.store(0);
61 62
#endif

Vincent Pinon's avatar
Vincent Pinon committed
63 64 65
    // Init application
    QApplication app(argc, argv);

66
    QCoreApplication::setAttribute(Qt::AA_UseHighDpiPixmaps);
67
    QCoreApplication::setAttribute(Qt::AA_ShareOpenGLContexts, true);
68 69 70
#if defined(Q_OS_UNIX) && !defined(Q_OS_MAC)
    QCoreApplication::setAttribute(Qt::AA_X11InitThreads);
#endif
71

72 73 74 75
#ifdef KF5_USE_CRASH
    KCrash::initialize();
#endif

76 77
#ifdef Q_OS_WIN
    qputenv("KDE_FORK_SLAVES", "1");
78 79
    QString path = qApp->applicationDirPath() + QLatin1Char(';') + qgetenv("PATH");
    qputenv("PATH", path.toUtf8().constData());
80 81
#endif

82
    app.setApplicationName(QStringLiteral("kdenlive"));
83
    app.setOrganizationDomain(QStringLiteral("kde.org"));
Laurent Montel's avatar
Laurent Montel committed
84
    app.setWindowIcon(QIcon(QStringLiteral(":/pics/kdenlive.png")));
85
    KLocalizedString::setApplicationDomain("kdenlive");
86
    KSharedConfigPtr config = KSharedConfig::openConfig();
87 88 89 90
    KConfigGroup grp(config, "unmanaged");
    KConfigGroup initialGroup(config, "version");
    if (!initialGroup.exists()) {
        QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
Vincent Pinon's avatar
Vincent Pinon committed
91
        if (env.contains(QStringLiteral("XDG_CURRENT_DESKTOP")) && env.value(QStringLiteral("XDG_CURRENT_DESKTOP")).toLower() == QLatin1String("kde")) {
Laurent Montel's avatar
Laurent Montel committed
92
            qCDebug(KDENLIVE_LOG) << "KDE Desktop detected, using system icons";
Vincent Pinon's avatar
Vincent Pinon committed
93 94 95
        } else {
            // We are not on a KDE desktop, force breeze icon theme
            grp.writeEntry("force_breeze", true);
Laurent Montel's avatar
Laurent Montel committed
96
            qCDebug(KDENLIVE_LOG) << "Non KDE Desktop detected, forcing Breeze icon theme";
97 98 99
        }
    }

100 101 102 103 104 105 106 107
    // Init DBus services
    KDBusService programDBusService;

    bool forceBreeze = grp.readEntry("force_breeze", QVariant(false)).toBool();
    if (forceBreeze) {
        QIcon::setThemeName("breeze");
    }

108
    // Create KAboutData
109
    KAboutData aboutData(QByteArray("kdenlive"),
110 111
                         i18n("Kdenlive"), KDENLIVE_VERSION,
                         i18n("An open source video editor."),
112
                         KAboutLicense::GPL,
113
                         i18n("Copyright © 2007–2019 Kdenlive authors"),
114
                         i18n("Please report bugs to http://bugs.kde.org"),
115 116
                         QStringLiteral("https://kdenlive.org"));
    aboutData.addAuthor(i18n("Jean-Baptiste Mardelle"), i18n("MLT and KDE SC 4 / KF5 port, main developer and maintainer"), QStringLiteral("jb@kdenlive.org"));
117
    aboutData.addAuthor(i18n("Vincent Pinon"), i18n("Interim maintainer, Windows cross-build, KF5 port, bugs fixing, minor functions, profiles updates, etc."), QStringLiteral("vpinon@april.org"));
118 119 120 121 122 123 124 125 126 127
    aboutData.addAuthor(i18n("Laurent Montel"), i18n("Bugs fixing, clean up code, optimization etc."), QStringLiteral("montel@kde.org"));
    aboutData.addAuthor(i18n("Marco Gittler"), i18n("MLT transitions and effects, timeline, audio thumbs"), QStringLiteral("g.marco@freenet.de"));
    aboutData.addAuthor(i18n("Dan Dennedy"), i18n("Bug fixing, etc."), QStringLiteral("dan@dennedy.org"));
    aboutData.addAuthor(i18n("Simon A. Eugster"), i18n("Color scopes, bug fixing, etc."), QStringLiteral("simon.eu@gmail.com"));
    aboutData.addAuthor(i18n("Till Theato"), i18n("Bug fixing, etc."), QStringLiteral("root@ttill.de"));
    aboutData.addAuthor(i18n("Alberto Villa"), i18n("Bug fixing, logo, etc."), QStringLiteral("avilla@FreeBSD.org"));
    aboutData.addAuthor(i18n("Jean-Michel Poure"), i18n("Rendering profiles customization"), QStringLiteral("jm@poure.com"));
    aboutData.addAuthor(i18n("Ray Lehtiniemi"), i18n("Bug fixing, etc."), QStringLiteral("rayl@mail.com"));
    aboutData.addAuthor(i18n("Steve Guilford"), i18n("Bug fixing, etc."), QStringLiteral("s.guilford@dbplugins.com"));
    aboutData.addAuthor(i18n("Jason Wood"), i18n("Original KDE 3 version author (not active anymore)"), QStringLiteral("jasonwood@blueyonder.co.uk"));
128
    aboutData.addCredit(i18n("Nara Oliveira and Farid Abdelnour | Estúdio Gunga"), i18n("Kdenlive 16.08 icon"));
129
    aboutData.setTranslator(i18n("NAME OF TRANSLATORS"), i18n("EMAIL OF TRANSLATORS"));
130
    aboutData.setOrganizationDomain(QByteArray("kde.org"));
131
    aboutData.setOtherText(i18n("Using:\n<a href=\"https://mltframework.org\">MLT</a> version %1\n<a href=\"https://ffmpeg.org\">FFmpeg</a> libraries", mlt_version_get_string()));
132
    aboutData.setDesktopFileName(QStringLiteral("org.kde.kdenlive"));
133 134

    // Register about data
135
    KAboutData::setApplicationData(aboutData);
136

137 138 139 140
    // Add rcc stored icons to the search path so that we always find our icons
    KIconLoader *loader = KIconLoader::global();
    loader->reconfigure("kdenlive", QStringList() << QStringLiteral(":/pics"));

141 142 143 144
    // Set app stuff from about data
    app.setApplicationDisplayName(aboutData.displayName());
    app.setOrganizationDomain(aboutData.organizationDomain());
    app.setApplicationVersion(aboutData.version());
145

146 147
    // Create command line parser with options
    QCommandLineParser parser;
148
    aboutData.setupCommandLine(&parser);
149 150 151
    parser.setApplicationDescription(aboutData.shortDescription());
    parser.addVersionOption();
    parser.addHelpOption();
152

153
    parser.addOption(QCommandLineOption(QStringList() <<  QStringLiteral("config"), i18n("Set a custom config file name"), QStringLiteral("config")));
154
    parser.addOption(QCommandLineOption(QStringList() <<  QStringLiteral("mlt-path"), i18n("Set the path for MLT environment"), QStringLiteral("mlt-path")));
155
    parser.addOption(QCommandLineOption(QStringList() <<  QStringLiteral("mlt-log"), i18n("MLT log level"), QStringLiteral("verbose/debug")));
156 157
    parser.addOption(QCommandLineOption(QStringList() <<  QStringLiteral("i"), i18n("Comma separated list of clips to add"), QStringLiteral("clips")));
    parser.addPositionalArgument(QStringLiteral("file"), i18n("Document to open"));
158 159 160 161 162

    // Parse command line
    parser.process(app);
    aboutData.processCommandLine(&parser);

163 164
    QString clipsToLoad = parser.value(QStringLiteral("i"));
    QString mltPath = parser.value(QStringLiteral("mlt-path"));
165 166 167 168 169
    if (parser.value(QStringLiteral("mlt-log")) == QStringLiteral("verbose")) {
        mlt_log_set_level( MLT_LOG_VERBOSE );
    } else if (parser.value(QStringLiteral("mlt-log")) == QStringLiteral("debug")) {
        mlt_log_set_level( MLT_LOG_DEBUG );
    }
170 171 172 173 174 175 176
    QUrl url;
    if (parser.positionalArguments().count()) {
        url = QUrl::fromLocalFile(parser.positionalArguments().at(0));
        // Make sure we get an absolute URL so that we can autosave correctly
        QString currentPath = QDir::currentPath();
        QUrl startup = QUrl::fromLocalFile(currentPath.endsWith(QDir::separator()) ? currentPath : currentPath + QDir::separator());
        url = startup.resolved(url);
177
    }
178
    Core::build(mltPath, url, clipsToLoad);
179
    int result = app.exec();
180

181
    if (EXIT_RESTART == result) {
Laurent Montel's avatar
Laurent Montel committed
182
        qCDebug(KDENLIVE_LOG) << "restarting app";
Laurent Montel's avatar
Laurent Montel committed
183
        QProcess *restart = new QProcess;
184 185 186 187 188
        restart->start(app.applicationFilePath(), QStringList());
        restart->waitForReadyRead();
        restart->waitForFinished(1000);
        result = EXIT_SUCCESS;
    }
189
    return result;
190
}