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"
Vincent Pinon's avatar
Vincent Pinon committed
22
#ifdef CRASH_AUTO_TEST
Nicolas Carion's avatar
Nicolas Carion committed
23
#include "logger.hpp"
Vincent Pinon's avatar
Vincent Pinon committed
24
#endif
25
#include "dialogs/splash.hpp"
Nicolas Carion's avatar
Nicolas Carion committed
26
#include <config-kdenlive.h>
27
28

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

30
#include "kxmlgui_version.h"
31
#include "mainwindow.h"
32

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

41
#include <KIconLoader>
42
#include <KSharedConfig>
43

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

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


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

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

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

Vincent Pinon's avatar
Vincent Pinon committed
115
#ifdef Q_OS_WIN
116
117
118
119
    qputenv("KDE_FORK_SLAVES", "1");
    QString path = qApp->applicationDirPath() + QLatin1Char(';') + qgetenv("PATH");
    qputenv("PATH", path.toUtf8().constData());

Vincent Pinon's avatar
Vincent Pinon committed
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
    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
138
    KSharedConfigPtr config = KSharedConfig::openConfig();
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
    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
155
156
157
158
#if KICONTHEMES_VERSION < QT_VERSION_CHECK(5,60,0)
    // work around bug in Kirigami2 resetting icon theme path
    qputenv("XDG_CURRENT_DESKTOP","KDE");
#endif
159

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

Jean-Baptiste Mardelle's avatar
Jean-Baptiste Mardelle committed
169
    // Create KAboutData
Nicolas Carion's avatar
Nicolas Carion committed
170
    KAboutData aboutData(QByteArray("kdenlive"), i18n("Kdenlive"), KDENLIVE_VERSION, i18n("An open source video editor."), KAboutLicense::GPL,
Eugen Mohr's avatar
Eugen Mohr committed
171
                         i18n("Copyright © 2007–2021 Kdenlive authors"), i18n("Please report bugs to https://bugs.kde.org"),
172
                         QStringLiteral("https://kdenlive.org"));
Julius Künzel's avatar
Julius Künzel committed
173
    // main developers (alphabetical)
174
    aboutData.addAuthor(i18n("Jean-Baptiste Mardelle"), i18n("MLT and KDE SC 4 / KF5 port, main developer and maintainer"), QStringLiteral("jb@kdenlive.org"));
Julius Künzel's avatar
Julius Künzel committed
175
    // active developers with major involvement
Vincent Pinon's avatar
Vincent Pinon committed
176
177
    aboutData.addAuthor(i18n("Nicolas Carion"), i18n("Code re-architecture & timeline rewrite"), QStringLiteral("french.ebook.lover@gmail.com"));
    aboutData.addAuthor(i18n("Simon A. Eugster"), i18n("Color scopes, bug fixing, etc."), QStringLiteral("simon.eu@gmail.com"));
Julius Künzel's avatar
Julius Künzel committed
178
179
180
181
182
183
    aboutData.addAuthor(i18n("Vincent Pinon"), i18n("KF5 port, Windows cross-build, packaging, bug fixing"), QStringLiteral("vpinon@kde.org"));
    // other active developers (alphabetical)
    aboutData.addAuthor(i18n("Dan Dennedy"), i18n("MLT, Bug fixing, etc."), QStringLiteral("dan@dennedy.org"));
    aboutData.addAuthor(i18n("Julius Künzel"), i18n("Bug fixing, etc."), QStringLiteral("jk.kdedev@smartlab.uber.space"));
    aboutData.addAuthor(i18n("Sashmita Raghav"), i18n("Subtitle feature (GSoC), timeline colours"));
    // non active developers with major improvement (alphabetical)
184
    aboutData.addAuthor(i18n("Jason Wood"), i18n("Original KDE 3 version author (not active anymore)"), QStringLiteral("jasonwood@blueyonder.co.uk"));
Julius Künzel's avatar
Julius Künzel committed
185
186
187
188
189
190
191
    // non developers (alphabetical)
    aboutData.addCredit(i18n("Farid Abdelnour"), i18n("Logo, Promotion, testing"));
    aboutData.addCredit(i18n("Eugen Mohr"), i18n("Bug triage, testing"));
    aboutData.addCredit(i18n("Nara Oliveira"), i18n("Logo"));
    aboutData.addCredit(i18n("Bruno Santos"), i18n("Testing"));
    aboutData.addCredit(i18n("Massimo Stella"), i18n("Expert advice, testing"));

192
    aboutData.setTranslator(i18n("NAME OF TRANSLATORS"), i18n("EMAIL OF TRANSLATORS"));
Jean-Baptiste Mardelle's avatar
Jean-Baptiste Mardelle committed
193
    aboutData.setOrganizationDomain(QByteArray("kde.org"));
Nicolas Carion's avatar
Nicolas Carion committed
194
195
    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()));
196
    aboutData.setDesktopFileName(QStringLiteral("org.kde.kdenlive"));
Jean-Baptiste Mardelle's avatar
Jean-Baptiste Mardelle committed
197
198

    // Register about data
199
    KAboutData::setApplicationData(aboutData);
200

Jean-Baptiste Mardelle's avatar
Jean-Baptiste Mardelle committed
201
202
203
204
    // Set app stuff from about data
    app.setApplicationDisplayName(aboutData.displayName());
    app.setOrganizationDomain(aboutData.organizationDomain());
    app.setApplicationVersion(aboutData.version());
205
    app.setAttribute(Qt::AA_DontCreateNativeWidgetSiblings, true);
206
    qApp->processEvents(QEventLoop::AllEvents);
207

Jean-Baptiste Mardelle's avatar
Jean-Baptiste Mardelle committed
208
209
    // Create command line parser with options
    QCommandLineParser parser;
210
    aboutData.setupCommandLine(&parser);
Jean-Baptiste Mardelle's avatar
Jean-Baptiste Mardelle committed
211
    parser.setApplicationDescription(aboutData.shortDescription());
212

Nicolas Carion's avatar
Nicolas Carion committed
213
214
    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")));
215
216
    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")));
217
    parser.addPositionalArgument(QStringLiteral("file"), i18n("Document to open"));
Jean-Baptiste Mardelle's avatar
Jean-Baptiste Mardelle committed
218
219
220
221
222

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

223
224
    qApp->processEvents(QEventLoop::AllEvents);

Vincent Pinon's avatar
Vincent Pinon committed
225
226
227
#ifdef USE_DRMINGW
    ExcHndlInit();
#elif defined(KF5_USE_CRASH)
228
    KCrash::initialize();
Vincent Pinon's avatar
Vincent Pinon committed
229
#endif
230

231
232
233
234
235
    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");
236
237
238
239
240
    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");
241
    qmlRegisterUncreatableMetaObject(ClipType::staticMetaObject, // static meta object
242
243
244
                                     "com.enums",                // import statement
                                     1, 0,                       // major and minor version of the import
                                     "ProducerType",             // name in QML
245
                                     "Error: only enums");
246
247
248
249
250
    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");
251
    if (parser.value(QStringLiteral("mlt-log")) == QStringLiteral("verbose")) {
252
        mlt_log_set_level(MLT_LOG_VERBOSE);
253
    } else if (parser.value(QStringLiteral("mlt-log")) == QStringLiteral("debug")) {
254
        mlt_log_set_level(MLT_LOG_DEBUG);
255
    }
256
    const QString clipsToLoad = parser.value(QStringLiteral("i"));
257
    QUrl url;
Nicolas Carion's avatar
Nicolas Carion committed
258
    if (parser.positionalArguments().count() != 0) {
259
260
261
262
263
264
        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());
        }
265
    }
266
    qApp->processEvents(QEventLoop::AllEvents);
267
    int result = 0;
268
    if (!Core::build()) {
269
270
271
272
273
274
275
        // 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());
        });
276
        pCore->initGUI(!parser.value(QStringLiteral("config")).isEmpty(), parser.value(QStringLiteral("mlt-path")), url, clipsToLoad);
277
278
        result = app.exec();
    }
279
    Core::clean();
280
    if (result == EXIT_RESTART || result == EXIT_CLEAN_RESTART) {
Laurent Montel's avatar
Laurent Montel committed
281
        qCDebug(KDENLIVE_LOG) << "restarting app";
282
283
284
285
286
        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
287
                QFile f(QStandardPaths::locate(QStandardPaths::GenericConfigLocation, config->name(), QStandardPaths::LocateFile));
288
289
290
291
292
                if (f.exists()) {
                    qDebug()<<" = = = =\nGOT Deleted file: "<<f.fileName();
                    f.remove();
                }
            }
293
294
295
296
297
298
299
300
301
302
303
304
            // 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();
                }
            }
305
        }
306
307
308
309
310
311
312
        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
313
        auto *restart = new QProcess;
314
        restart->start(app.applicationFilePath(), progArgs);
315
316
317
318
        restart->waitForReadyRead();
        restart->waitForFinished(1000);
        result = EXIT_SUCCESS;
    }
319
    return result;
Jean-Baptiste Mardelle's avatar
Jean-Baptiste Mardelle committed
320
}