main.cpp 15.1 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 "core.h"
Nicolas Carion's avatar
Nicolas Carion committed
22
#include "logger.hpp"
23
#include "dialogs/splash.hpp"
Nicolas Carion's avatar
Nicolas Carion committed
24
#include <config-kdenlive.h>
25
26

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

28
#include "kxmlgui_version.h"
29
#include "mainwindow.h"
30

31
#include <KAboutData>
Nicolas Carion's avatar
Nicolas Carion committed
32
#include <KConfigGroup>
Vincent Pinon's avatar
Vincent Pinon committed
33
#ifdef USE_DRMINGW
34
#include <exchndl.h>
Vincent Pinon's avatar
Vincent Pinon committed
35
#elif defined(KF5_USE_CRASH)
36
#include <KCrash>
Vincent Pinon's avatar
Vincent Pinon committed
37
#endif
Vincent Pinon's avatar
Vincent Pinon committed
38

39
#include <KIconLoader>
40
#include <KSharedConfig>
41

42
#include "definitions.h"
Laurent Montel's avatar
Laurent Montel committed
43
#include "kdenlive_debug.h"
Nicolas Carion's avatar
Nicolas Carion committed
44
#include <KDBusService>
45
#include <KIconTheme>
Vincent Pinon's avatar
Vincent Pinon committed
46
#include <kiconthemes_version.h>
Vincent Pinon's avatar
Vincent Pinon committed
47
#include <QResource>
48
49
#include <QApplication>
#include <QCommandLineOption>
Nicolas Carion's avatar
Nicolas Carion committed
50
51
#include <QCommandLineParser>
#include <QDir>
52
#include <QIcon>
Nicolas Carion's avatar
Nicolas Carion committed
53
#include <QProcess>
54
#include <QQmlEngine>
Nicolas Carion's avatar
Nicolas Carion committed
55
56
#include <QUrl> //new
#include <klocalizedstring.h>
57
#include <QSplashScreen>
Jean-Baptiste Mardelle's avatar
Jean-Baptiste Mardelle committed
58

Jean-Baptiste Mardelle's avatar
Jean-Baptiste Mardelle committed
59
60
61
62
#ifdef Q_OS_WIN
extern "C"
{
    // Inform the driver we could make use of the discrete gpu
63
64
    // __declspec(dllexport) DWORD NvOptimusEnablement = 0x00000001;
    // __declspec(dllexport) int AmdPowerXpressRequestHighPerformance = 1;
Jean-Baptiste Mardelle's avatar
Jean-Baptiste Mardelle committed
65
66
67
68
}
#endif


69
70
int main(int argc, char *argv[])
{
71
72
73
#ifdef USE_DRMINGW
    ExcHndlInit();
#endif
74
    // Force QDomDocument to use a deterministic XML attribute order
75
    qSetGlobalQHashSeed(0);
76
77

    Logger::init();
78
    QCoreApplication::setAttribute(Qt::AA_UseHighDpiPixmaps);
Jean-Baptiste Mardelle's avatar
Jean-Baptiste Mardelle committed
79
    //TODO: is it a good option ?
80
    QCoreApplication::setAttribute(Qt::AA_ShareOpenGLContexts, true);
81
82
    
#if defined(Q_OS_WIN)
83
84
    KSharedConfigPtr configWin = KSharedConfig::openConfig("kdenliverc");
    KConfigGroup grp1(configWin, "misc");
85
86
87
88
89
    if (grp1.exists()) {
        int glMode = grp1.readEntry("opengl_backend", 0);
        if (glMode > 0) {
            QCoreApplication::setAttribute((Qt::ApplicationAttribute)glMode, true);
        }
90
91
92
    } else {
        // Default to OpenGLES (QtAngle) on first start
        QCoreApplication::setAttribute(Qt::AA_UseOpenGLES, true);
93
    }
94
#endif
95
    qputenv("LANG", QLocale().name().toUtf8());
96
    QApplication app(argc, argv);
97
    app.setApplicationName(QStringLiteral("kdenlive"));
Jean-Baptiste Mardelle's avatar
Jean-Baptiste Mardelle committed
98
    app.setOrganizationDomain(QStringLiteral("kde.org"));
Laurent Montel's avatar
Minor    
Laurent Montel committed
99
    app.setWindowIcon(QIcon(QStringLiteral(":/pics/kdenlive.png")));
100
    KLocalizedString::setApplicationDomain("kdenlive");
101
102
103

    QPixmap pixmap(":/pics/splash-background.png");
    qApp->processEvents(QEventLoop::AllEvents);
104
    Splash splash(pixmap);
105
    qApp->processEvents(QEventLoop::AllEvents);
Jean-Baptiste Mardelle's avatar
Jean-Baptiste Mardelle committed
106
    splash.showMessage(i18n("Version %1", QString(KDENLIVE_VERSION)), Qt::AlignRight | Qt::AlignBottom, Qt::white);
107
108
109
    splash.show();
    qApp->processEvents(QEventLoop::AllEvents);

Vincent Pinon's avatar
Vincent Pinon committed
110
#ifdef Q_OS_WIN
111
112
113
114
    qputenv("KDE_FORK_SLAVES", "1");
    QString path = qApp->applicationDirPath() + QLatin1Char(';') + qgetenv("PATH");
    qputenv("PATH", path.toUtf8().constData());

Vincent Pinon's avatar
Vincent Pinon committed
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
    const QStringList themes {"/icons/breeze/breeze-icons.rcc", "/icons/breeze-dark/breeze-icons-dark.rcc"};
    for(const QString theme : themes ) {
        const QString themePath = QStandardPaths::locate(QStandardPaths::AppDataLocation, theme);
        if (!themePath.isEmpty()) {
            const QString iconSubdir = theme.left(theme.lastIndexOf('/'));
            if (QResource::registerResource(themePath, iconSubdir)) {
                if (QFileInfo::exists(QLatin1Char(':') + iconSubdir + QStringLiteral("/index.theme"))) {
                    qDebug() << "Loaded icon theme:" << theme;
                } else {
                    qWarning() << "No index.theme found in" << theme;
                    QResource::unregisterResource(themePath, iconSubdir);
                }
            } else {
                qWarning() << "Invalid rcc file" << theme;
            }
        }
    }
#endif
133
    KSharedConfigPtr config = KSharedConfig::openConfig();
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
    KConfigGroup grp(config, "unmanaged");
    if (!grp.exists()) {
        QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
        if (env.contains(QStringLiteral("XDG_CURRENT_DESKTOP")) && env.value(QStringLiteral("XDG_CURRENT_DESKTOP")).toLower() == QLatin1String("kde")) {
            qCDebug(KDENLIVE_LOG) << "KDE Desktop detected, using system icons";
        } else {
            // We are not on a KDE desktop, force breeze icon theme
            // Check if breeze theme is available
            QStringList iconThemes = KIconTheme::list();
            if (iconThemes.contains(QStringLiteral("breeze"))) {
                grp.writeEntry("force_breeze", true);
                grp.writeEntry("use_dark_breeze", true);
                qCDebug(KDENLIVE_LOG) << "Non KDE Desktop detected, forcing Breeze icon theme";
            }
        }
    }
Vincent Pinon's avatar
Vincent Pinon committed
150
151
152
153
#if KICONTHEMES_VERSION < QT_VERSION_CHECK(5,60,0)
    // work around bug in Kirigami2 resetting icon theme path
    qputenv("XDG_CURRENT_DESKTOP","KDE");
#endif
154

155
156
157
158
    // Init DBus services
    KDBusService programDBusService;
    bool forceBreeze = grp.readEntry("force_breeze", QVariant(false)).toBool();
    if (forceBreeze) {
159
160
        bool darkBreeze = grp.readEntry("use_dark_breeze", QVariant(false)).toBool();
        QIcon::setThemeName(darkBreeze ? QStringLiteral("breeze-dark") : QStringLiteral("breeze"));
161
    }
162
    qApp->processEvents(QEventLoop::AllEvents);
163

Jean-Baptiste Mardelle's avatar
Jean-Baptiste Mardelle committed
164
    // Create KAboutData
Nicolas Carion's avatar
Nicolas Carion committed
165
    KAboutData aboutData(QByteArray("kdenlive"), i18n("Kdenlive"), KDENLIVE_VERSION, i18n("An open source video editor."), KAboutLicense::GPL,
Eugen Mohr's avatar
Eugen Mohr committed
166
                         i18n("Copyright © 2007–2021 Kdenlive authors"), i18n("Please report bugs to https://bugs.kde.org"),
167
168
                         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"));
Vincent Pinon's avatar
Vincent Pinon committed
169
170
    aboutData.addAuthor(i18n("Nicolas Carion"), i18n("Code re-architecture & timeline rewrite"), QStringLiteral("french.ebook.lover@gmail.com"));
    aboutData.addAuthor(i18n("Vincent Pinon"), i18n("KF5 port, Windows cross-build, bugs fixing"), QStringLiteral("vpinon@kde.org"));
171
    aboutData.addAuthor(i18n("Laurent Montel"), i18n("Bugs fixing, clean up code, optimization etc."), QStringLiteral("montel@kde.org"));
Vincent Pinon's avatar
Vincent Pinon committed
172
173
    aboutData.addAuthor(i18n("Till Theato"), i18n("Bug fixing, etc."), QStringLiteral("root@ttill.de"));
    aboutData.addAuthor(i18n("Simon A. Eugster"), i18n("Color scopes, bug fixing, etc."), QStringLiteral("simon.eu@gmail.com"));
174
175
176
177
178
179
180
    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("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"));
181
    aboutData.addCredit(i18n("Nara Oliveira and Farid Abdelnour | Estúdio Gunga"), i18n("Kdenlive 16.08 icon"));
182
    aboutData.setTranslator(i18n("NAME OF TRANSLATORS"), i18n("EMAIL OF TRANSLATORS"));
Jean-Baptiste Mardelle's avatar
Jean-Baptiste Mardelle committed
183
    aboutData.setOrganizationDomain(QByteArray("kde.org"));
Nicolas Carion's avatar
Nicolas Carion committed
184
185
    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()));
186
    aboutData.setDesktopFileName(QStringLiteral("org.kde.kdenlive"));
Jean-Baptiste Mardelle's avatar
Jean-Baptiste Mardelle committed
187
188

    // Register about data
189
    KAboutData::setApplicationData(aboutData);
190

Jean-Baptiste Mardelle's avatar
Jean-Baptiste Mardelle committed
191
192
193
194
    // Set app stuff from about data
    app.setApplicationDisplayName(aboutData.displayName());
    app.setOrganizationDomain(aboutData.organizationDomain());
    app.setApplicationVersion(aboutData.version());
195
    app.setAttribute(Qt::AA_DontCreateNativeWidgetSiblings, true);
196
    qApp->processEvents(QEventLoop::AllEvents);
197

Jean-Baptiste Mardelle's avatar
Jean-Baptiste Mardelle committed
198
199
    // Create command line parser with options
    QCommandLineParser parser;
200
    aboutData.setupCommandLine(&parser);
Jean-Baptiste Mardelle's avatar
Jean-Baptiste Mardelle committed
201
    parser.setApplicationDescription(aboutData.shortDescription());
202

Nicolas Carion's avatar
Nicolas Carion committed
203
204
    parser.addOption(QCommandLineOption(QStringList() << QStringLiteral("config"), i18n("Set a custom config file name"), QStringLiteral("config")));
    parser.addOption(QCommandLineOption(QStringList() << QStringLiteral("mlt-path"), i18n("Set the path for MLT environment"), QStringLiteral("mlt-path")));
205
206
    parser.addOption(QCommandLineOption(QStringList() << QStringLiteral("mlt-log"), i18n("MLT log level"), QStringLiteral("verbose/debug")));
    parser.addOption(QCommandLineOption(QStringList() << QStringLiteral("i"), i18n("Comma separated list of clips to add"), QStringLiteral("clips")));
207
    parser.addPositionalArgument(QStringLiteral("file"), i18n("Document to open"));
Jean-Baptiste Mardelle's avatar
Jean-Baptiste Mardelle committed
208
209
210
211
212

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

213
214
    qApp->processEvents(QEventLoop::AllEvents);

Vincent Pinon's avatar
Vincent Pinon committed
215
216
217
#ifdef USE_DRMINGW
    ExcHndlInit();
#elif defined(KF5_USE_CRASH)
218
    KCrash::initialize();
Vincent Pinon's avatar
Vincent Pinon committed
219
#endif
220

221
222
223
224
225
    qmlRegisterUncreatableMetaObject(PlaylistState::staticMetaObject, // static meta object
                                     "com.enums",                     // import statement
                                     1, 0,                            // major and minor version of the import
                                     "ClipState",                     // name in QML
                                     "Error: only enums");
226
227
228
229
230
    qmlRegisterUncreatableMetaObject(FileStatus::staticMetaObject, // static meta object
                                     "com.enums",                     // import statement
                                     1, 0,                            // major and minor version of the import
                                     "ClipStatus",                     // name in QML
                                     "Error: only enums");
231
    qmlRegisterUncreatableMetaObject(ClipType::staticMetaObject, // static meta object
232
233
234
                                     "com.enums",                // import statement
                                     1, 0,                       // major and minor version of the import
                                     "ProducerType",             // name in QML
235
                                     "Error: only enums");
236
237
238
239
240
    qmlRegisterUncreatableMetaObject(AssetListType::staticMetaObject, // static meta object
                                     "com.enums",                // import statement
                                     1, 0,                       // major and minor version of the import
                                     "AssetType",             // name in QML
                                     "Error: only enums");
241
    if (parser.value(QStringLiteral("mlt-log")) == QStringLiteral("verbose")) {
242
        mlt_log_set_level(MLT_LOG_VERBOSE);
243
    } else if (parser.value(QStringLiteral("mlt-log")) == QStringLiteral("debug")) {
244
        mlt_log_set_level(MLT_LOG_DEBUG);
245
    }
246
    const QString clipsToLoad = parser.value(QStringLiteral("i"));
247
    QUrl url;
Nicolas Carion's avatar
Nicolas Carion committed
248
    if (parser.positionalArguments().count() != 0) {
249
250
251
252
253
254
        const QString inputFilename = parser.positionalArguments().at(0);
        const QFileInfo fileInfo(inputFilename);
        url = QUrl(inputFilename);
        if (fileInfo.exists() || url.scheme().isEmpty()) { // easiest way to detect "invalid"/unintended URLs is no scheme
            url = QUrl::fromLocalFile(fileInfo.absoluteFilePath());
        }
255
    }
256
    qApp->processEvents(QEventLoop::AllEvents);
257
258
259
260
261
262
263
264
265
266
267
268
    int result = 0;
    if (!Core::build(!parser.value(QStringLiteral("config")).isEmpty(), parser.value(QStringLiteral("mlt-path")))) {
        // App is crashing, delete config files and restart
        result = EXIT_CLEAN_RESTART;
    } else {
        QObject::connect(pCore.get(), &Core::loadingMessageUpdated, &splash, &Splash::showProgressMessage, Qt::DirectConnection);
        QObject::connect(pCore.get(), &Core::closeSplash, [&] () {
            splash.finish(pCore->window());
        });
        pCore->initGUI(url, clipsToLoad);
        result = app.exec();
    }
269
    Core::clean();
270
    if (result == EXIT_RESTART || result == EXIT_CLEAN_RESTART) {
Laurent Montel's avatar
Laurent Montel committed
271
        qCDebug(KDENLIVE_LOG) << "restarting app";
272
273
274
275
276
277
278
279
280
281
282
        if (result == EXIT_CLEAN_RESTART) {
            // Delete config file
            KSharedConfigPtr config = KSharedConfig::openConfig();
            if (config->name().contains(QLatin1String("kdenlive"))) {
                // Make sure we delete our config file
                QFile f(QStandardPaths::locate(QStandardPaths::ConfigLocation, config->name(), QStandardPaths::LocateFile));
                if (f.exists()) {
                    qDebug()<<" = = = =\nGOT Deleted file: "<<f.fileName();
                    f.remove();
                }
            }
283
284
285
286
287
288
289
290
291
292
293
294
            // Delete xml ui rc file
            QDir dir(QStandardPaths::locate(QStandardPaths::GenericDataLocation, QStringLiteral("kxmlgui5"), QStandardPaths::LocateDirectory));
            if (dir.exists()) {
                dir.cd(QStringLiteral("kdenlive"));
            }
            if (dir.exists()) {
                QFile f(dir.absoluteFilePath(QStringLiteral("kdenliveui.rc")));
                if (f.exists()) {
                    qDebug()<<" = = = =\nGOT Deleted file: "<<f.fileName();
                    f.remove();
                }
            }
295
        }
296
297
298
299
300
301
302
        QStringList progArgs;
        if (argc > 1) {
            // Start at 1 to remove app name
            for (int i = 1; i < argc; i++) {
                progArgs << QString(argv[i]);
            }
        }
Nicolas Carion's avatar
Nicolas Carion committed
303
        auto *restart = new QProcess;
304
        restart->start(app.applicationFilePath(), progArgs);
305
306
307
308
        restart->waitForReadyRead();
        restart->waitForFinished(1000);
        result = EXIT_SUCCESS;
    }
309
    return result;
Jean-Baptiste Mardelle's avatar
Jean-Baptiste Mardelle committed
310
}