main.cpp 8.28 KB
Newer Older
1 2 3
/*****************************************************************************
 * main.cpp: VLMC main
 *****************************************************************************
4
 * Copyright (C) 2008-2016 the VLMC team
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
 *
 * Authors: Ludovic Fauvet <etix@l0cal.com>
 *
 * 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.
 *****************************************************************************/

/** \file
 *  This file contain the main function.
 *  It will initialize the QT application,
 *  and start it.
 */

29 30 31
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
32

33
#include "Tools/VlmcDebug.h"
34
#include "Workflow/Types.h"
35
#include "Renderer/ConsoleRenderer.h"
36
#include "Project/Project.h"
luyikei's avatar
luyikei committed
37
#include "Backend/IBackend.h"
38
#include "Main/Core.h"
39
#include "Settings/Settings.h"
40
#ifdef HAVE_GUI
41 42 43
#include "Gui/MainWindow.h"
#include "Gui/IntroDialog.h"
#include "Gui/LanguageHelper.h"
44
#include "Gui/wizard/firstlaunch/FirstLaunchWizard.h"
45
#endif
46

47
#ifdef HAVE_GUI
48 49 50
#include <QApplication>
#include <QColor>
#include <QPalette>
51 52 53 54
#else
#include <QCoreApplication>
#endif
#include <QFile>
55 56
#include <QSettings>
#include <QUuid>
57
#include <QTextCodec>
58
#include <QCommandLineParser>
59

60 61 62 63
#ifdef Q_WS_X11
#include <X11/Xlib.h>
#endif

64
static void
65
setupCommandLine( QCommandLineParser& parser )
66
{
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91
    parser.setSingleDashWordOptionMode( QCommandLineParser::ParseAsLongOptions );
    parser.setApplicationDescription(
                QString(
                    "VideoLAN Movie Creator (VLMC) is a cross-platform, non-linear\n"
                    "video editing software."
                    ) );
    parser.addHelpOption();
    parser.addVersionOption();

    parser.addPositionalArgument( "project",
                                  QCoreApplication::translate( "main", "Project file to open." ),
                                  "[filename|URI]" );
    parser.addPositionalArgument( "output",
                                  QCoreApplication::translate( "main", "Output file to write to." ),
                                  "[filename]" );

    parser.addOption( { "v",
                        QCoreApplication::translate( "main", "Log level - Verbose" ) } );
    parser.addOption( { "vv",
                        QCoreApplication::translate( "main", "Log level - Debug" ) } );
    parser.addOption( { { "b", "backendverbose" },
                        QCoreApplication::translate( "main", "Backend Log level to set" ),
                        "value" } );
    parser.process( *qApp );
}
92

Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
93

94 95 96
static void
VLMCmainCommon( Backend::IBackend** backend )
{
97 98 99 100
    qRegisterMetaType<Workflow::TrackType>( "Workflow::TrackType" );
    qRegisterMetaType<Vlmc::FrameChangedReason>( "Vlmc::FrameChangedReason" );
    qRegisterMetaType<QVariant>( "QVariant" );
    qRegisterMetaType<QUuid>( "QUuid" );
101

luyikei's avatar
luyikei committed
102
    *backend = Backend::instance();
103 104
}

105 106 107 108 109
/**
 *  VLMC Entry point
 *  \brief this is the VLMC entry point
 *  \return Return value of vlmc
 */
110
#ifdef HAVE_GUI
111
int
112
VLMCGuimain( const QString& projectFile )
113
{
114 115 116
#ifdef Q_WS_X11
    XInitThreads();
#endif
117

luyikei's avatar
luyikei committed
118
    Backend::IBackend* backend;
119
    VLMCmainCommon( &backend );
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
120 121

    /* Translations */
122
    QSettings s;
luyikei's avatar
luyikei committed
123
    LanguageHelper::instance()->languageChanged(
124
            s.value( "vlmc/VLMCLang", "default" ) );
125

126
#if defined( Q_WS_WIN )
127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157
    QFile  css(":/styles/windows");
    if ( css.open( QIODevice::ReadOnly | QIODevice::Text ) )
    {
        QString styleSheet = css.readAll();
        if ( styleSheet != "" )
            app.setStyleSheet( styleSheet );
    }

    // Creating the color palette
    QPalette p;
    p.setColor( QPalette::WindowText,       QColor( 255, 255, 255, 255 ) );
    p.setColor( QPalette::Button,           QColor( 104, 103, 103, 255 ) );
    p.setColor( QPalette::Light,            QColor( 156, 155, 155, 255 ) );
    p.setColor( QPalette::Midlight,         QColor( 130, 129, 129, 255 ) );
    p.setColor( QPalette::Dark,             QColor( 52,  51,  51,  255 ) );
    p.setColor( QPalette::Mid,              QColor( 69,  68,  68,  255 ) );
    p.setColor( QPalette::Text,             QColor( 255, 255, 255, 255 ) );
    p.setColor( QPalette::BrightText,       QColor( 255, 255, 255, 255 ) );
    p.setColor( QPalette::ButtonText,       QColor( 255, 255, 255, 255 ) );
    p.setColor( QPalette::Base,             QColor( 104, 103, 103, 255 ) );
    p.setColor( QPalette::Window,           QColor( 73,  72,  72,  255 ) );
    p.setColor( QPalette::Shadow,           QColor( 0,   0,   0,   255 ) );
    p.setColor( QPalette::AlternateBase,    QColor( 52,  51,  51,  255 ) );
    p.setColor( QPalette::ToolTipBase,      QColor( 255, 255, 220, 255 ) );
    p.setColor( QPalette::ToolTipText,      QColor( 0,   0,   0,   255 ) );
    p.setColor( QPalette::WindowText,       QColor( 255, 255, 255, 255 ) );
    p.setColor( QPalette::WindowText,       QColor( 255, 255, 255, 255 ) );
    p.setColor( QPalette::WindowText,       QColor( 255, 255, 255, 255 ) );
    p.setColor( QPalette::WindowText,       QColor( 255, 255, 255, 255 ) );
    p.setColor( QPalette::Link,             QColor( 177, 202, 0,   255 ) );
    p.setColor( QPalette::LinkVisited,      QColor( 177, 202, 0,   255 ) );
158 159
    app.setPalette( p );
#endif
160 161 162 163 164

#ifndef QT_DEBUG
    IntroDialog d;
    d.exec();
#endif
165

166
    MainWindow w( backend );
167

168 169 170 171 172 173 174
    if ( FirstLaunchWizard::shouldRun() == true )
    {
        FirstLaunchWizard wiz;
        if ( wiz.exec() == QDialog::Rejected )
            return 1;
    }

175
    //Don't show the wizard if a project has been passed through command line.
176
    if ( projectFile.isEmpty() == true )
177
        w.showWizard();
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
178 179

    /* Main Window display */
180
    w.show();
181 182 183 184 185

    if ( projectFile.isEmpty() == false )
        Core::instance()->loadProject( projectFile );

    auto res = qApp->exec();
186 187
    Core::instance()->settings()->save();
    return res;
188
}
189
#endif
190

191 192 193 194 195 196
/**
 *  VLMC Entry point
 *  \brief this is the VLMC entry point
 *  \return Return value of vlmc
 */
int
197
VLMCCoremain( const QString& projectFile , const QString& outputFile)
198
{
luyikei's avatar
luyikei committed
199
    Backend::IBackend* backend;
200
    VLMCmainCommon( &backend );
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
201

202
    ConsoleRenderer renderer( outputFile );
203
    Project  *p = Core::instance()->project();
204

205
    QCoreApplication::connect( p, &Project::projectLoaded, &renderer, &ConsoleRenderer::startRender );
206
    QCoreApplication::connect( &renderer, &ConsoleRenderer::finished, qApp, &QCoreApplication::quit, Qt::QueuedConnection );
207
    Core::instance()->settings()->load();
208
    p->load( projectFile );
209

210
    auto res = qApp->exec();
211 212
    Core::instance()->settings()->save();
    return res;
213 214 215
}

int
216
VLMCmain( int argc, char **argv )
217
{
218
#ifdef HAVE_GUI
219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251
    QApplication app( argc, argv );
#else
    QCoreApplication app( argc, argv );
#endif

    app.setApplicationName( "VLMC" );
    app.setOrganizationName( "VideoLAN" );
    app.setOrganizationDomain( "videolan.org" );
    app.setApplicationVersion(
                QString(
                    "%1 '%2'\n"
                    "VideoLAN Movie Creator (VLMC) is a cross-platform, non-linear\n"
                    "video editing software.\n"
                    "Copyright (C) 2008-10 VideoLAN\n"
                    "This is free software; see the source for copying conditions. There is NO\n"
                    "warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n"
                    ).arg( PACKAGE_VERSION ).arg( CODENAME ) );

    QCommandLineParser parser;
    setupCommandLine( parser );

    const auto& args = parser.positionalArguments();

    if ( args.size() >= 2  )
        return VLMCCoremain( args.at( 0 ), args.at( 1 ) );
#ifdef HAVE_GUI
    else if ( args.size() == 1 )
        return VLMCGuimain( args.at( 0 ) );
    else
        return VLMCGuimain( "" );
#else
    else
        parser.showHelp( 1 ); // This function exits the application. No need to return any value.
252 253 254
#endif
}