MainWindow.cpp 21.9 KB
Newer Older
Ludovic Fauvet's avatar
Ludovic Fauvet committed
1
/*****************************************************************************
2
 * MainWindow.cpp: VLMC MainWindow
Ludovic Fauvet's avatar
Ludovic Fauvet committed
3
 *****************************************************************************
Ludovic Fauvet's avatar
Ludovic Fauvet committed
4
 * Copyright (C) 2008-2010 VideoLAN
Ludovic Fauvet's avatar
Ludovic Fauvet committed
5 6
 *
 * Authors: Ludovic Fauvet <etix@l0cal.com>
7
 *          Hugo Beauzee-Luyssen <beauze.h@gmail.com>
Ludovic Fauvet's avatar
Ludovic Fauvet committed
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
 *
 * 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.
 *****************************************************************************/

24
#include <QSizePolicy>
Christophe Courtaut's avatar
Christophe Courtaut committed
25
#include <QDockWidget>
26
#include <QFileDialog>
27
#include <QSlider>
28
#include <QMessageBox>
29 30
#include <QDesktopServices>
#include <QUrl>
31
#include <QSettings>
Hugo Beauzee-Luyssen's avatar
Hugo Beauzee-Luyssen committed
32

Ludovic Fauvet's avatar
Ludovic Fauvet committed
33
#include "MainWindow.h"
34
#include "config.h"
Hugo Beauzee-Luyssen's avatar
Hugo Beauzee-Luyssen committed
35
#include "Library.h"
Ludovic Fauvet's avatar
Ludovic Fauvet committed
36
#include "About.h"
37 38
#include "VlmcDebug.h"

Ludovic Fauvet's avatar
Ludovic Fauvet committed
39
#include "MainWorkflow.h"
40
#include "export/RendererSettings.h"
Ludovic Fauvet's avatar
Ludovic Fauvet committed
41
#include "WorkflowFileRenderer.h"
42
#include "WorkflowRenderer.h"
43
#include "ClipRenderer.h"
Ludovic Fauvet's avatar
Ludovic Fauvet committed
44
#include "EffectsEngine.h"
45 46 47

/* Widgets */
#include "DockWidgetManager.h"
48 49
#include "ImportController.h"
#include "MediaListView.h"
50
#include "PreviewWidget.h"
51 52
#include "timeline/Timeline.h"
#include "timeline/TracksView.h"
53
#include "UndoStack.h"
54 55

/* Settings / Preferences */
56
#include "project/GuiProjectManager.h"
Ludovic Fauvet's avatar
Ludovic Fauvet committed
57 58
#include "ProjectWizard.h"
#include "Settings.h"
59
#include "SettingsManager.h"
60
#include "LanguageHelper.h"
Ludovic Fauvet's avatar
Ludovic Fauvet committed
61

62 63 64
/* VLCpp */
#include "VLCInstance.h"

Ludovic Fauvet's avatar
Ludovic Fauvet committed
65
MainWindow::MainWindow( QWidget *parent ) :
66
    QMainWindow( parent ), m_fileRenderer( NULL )
Ludovic Fauvet's avatar
Ludovic Fauvet committed
67 68
{
    m_ui.setupUi( this );
69

70
    qRegisterMetaType<MainWorkflow::TrackType>( "MainWorkflow::TrackType" );
71
    qRegisterMetaType<MainWorkflow::FrameChangedReason>( "MainWorkflow::FrameChangedReason" );
72
    qRegisterMetaType<QVariant>( "QVariant" );
73

Hugo Beauzee-Luyssen's avatar
Hugo Beauzee-Luyssen committed
74
    //We only install message handler here cause it uses configuration.
75
//    VlmcDebug::getInstance()->setup();
76

77
    //VLC Instance:
78
    LibVLCpp::Instance::getInstance();
79

80
    //Creating the project manager first (so it can create all the project variables)
81
    GUIProjectManager::getInstance();
82

83 84 85
    //Preferences
    initVlmcPreferences();

86
    // GUI
87
    DockWidgetManager::getInstance( this )->setMainWindow( this );
88
    createGlobalPreferences();
89
    createProjectPreferences();
90 91
    initializeDockWidgets();
    createStatusBar();
Ludovic Fauvet's avatar
Ludovic Fauvet committed
92
#ifdef WITH_CRASHBUTTON
93 94
    setupCrashTester();
#endif
95

Ludovic Fauvet's avatar
Ludovic Fauvet committed
96
    // Translations
97
    connect( this, SIGNAL( translateDockWidgetTitle() ),
98
             DockWidgetManager::getInstance(), SLOT( transLateWidgetTitle() ) );
Ludovic Fauvet's avatar
Ludovic Fauvet committed
99 100

    // Zoom
101 102
    connect( m_zoomSlider, SIGNAL( valueChanged( int ) ),
             m_timeline, SLOT( changeZoom( int ) ) );
Ludovic Fauvet's avatar
Ludovic Fauvet committed
103 104 105 106
    connect( m_timeline->tracksView(), SIGNAL( zoomIn() ),
             this, SLOT( zoomIn() ) );
    connect( m_timeline->tracksView(), SIGNAL( zoomOut() ),
             this, SLOT( zoomOut() ) );
107 108
    connect( this, SIGNAL( toolChanged( ToolButtons ) ),
             m_timeline, SLOT( setTool( ToolButtons ) ) );
109

110
    connect( GUIProjectManager::getInstance(), SIGNAL( projectUpdated( const QString&, bool ) ),
111
             this, SLOT( projectUpdated( const QString&, bool ) ) );
112

113 114 115 116 117 118 119 120 121
    // Undo/Redo
    connect( UndoStack::getInstance( this ), SIGNAL( canRedoChanged( bool ) ),
             this, SLOT( canRedoChanged( bool ) ) );
    connect( UndoStack::getInstance( this ), SIGNAL( canUndoChanged( bool ) ),
             this, SLOT( canUndoChanged( bool ) ) );
    canRedoChanged( UndoStack::getInstance( this )->canRedo() );
    canUndoChanged( UndoStack::getInstance( this )->canUndo() );


Hugo Beauzee-Luyssen's avatar
Hugo Beauzee-Luyssen committed
122 123 124 125
    // Wizard
    m_pWizard = new ProjectWizard( this );
    m_pWizard->setModal( true );

126

127
#ifdef WITH_CRASHHANDLER
128
    if ( restoreSession() == true )
129 130
        return ;
#endif
131
    QSettings s;
132

133
    if ( s.value( "ShowWizardStartup", true ).toBool() )
Hugo Beauzee-Luyssen's avatar
Hugo Beauzee-Luyssen committed
134
    {
135 136 137
        //If a project was opened from the command line: don't show the wizzard.
        if ( qApp->arguments().size() == 1 )
            m_pWizard->show();
Hugo Beauzee-Luyssen's avatar
Hugo Beauzee-Luyssen committed
138
    }
Ludovic Fauvet's avatar
Ludovic Fauvet committed
139 140
}

141 142
MainWindow::~MainWindow()
{
143 144 145 146 147
    QSettings s;
    // Save the current geometry
    s.setValue( "MainWindowGeometry", saveGeometry() );
    // Save the current layout
    s.setValue( "MainWindowState", saveState() );
Hugo Beauzee-Luyssen's avatar
Hugo Beauzee-Luyssen committed
148
    s.setValue( "CleanQuit", true );
149 150
    s.sync();

151 152
    if ( m_fileRenderer )
        delete m_fileRenderer;
153
    delete m_importController;
154
    LibVLCpp::Instance::destroyInstance();
155 156
}

Ludovic Fauvet's avatar
Ludovic Fauvet committed
157 158 159 160 161 162
void MainWindow::changeEvent( QEvent *e )
{
    switch ( e->type() )
    {
    case QEvent::LanguageChange:
        m_ui.retranslateUi( this );
163
        emit translateDockWidgetTitle();
Ludovic Fauvet's avatar
Ludovic Fauvet committed
164 165 166 167 168 169
        break;
    default:
        break;
    }
}

Hugo Beauzee-Luyssen's avatar
Hugo Beauzee-Luyssen committed
170 171 172 173 174
//use this helper when the shortcut is binded to a menu action
#define CREATE_MENU_SHORTCUT( key, defaultValue, name, desc, actionInstance  )       \
        VLMC_CREATE_PREFERENCE_KEYBOARD( key, defaultValue, name, desc );    \
        KeyboardShortcutHelper  *helper##actionInstance = new KeyboardShortcutHelper( key, m_ui.actionInstance, this );

175 176 177
void
MainWindow::initVlmcPreferences()
{
Hugo Beauzee-Luyssen's avatar
Hugo Beauzee-Luyssen committed
178

179 180 181 182
    VLMC_CREATE_PREFERENCE_KEYBOARD( "keyboard/defaultmode", "n", "Select mode", "Select the selection tool in the timeline" );
    VLMC_CREATE_PREFERENCE_KEYBOARD( "keyboard/cutmode", "x", "Cut mode", "Select the cut/razor tool in the timeline" );
    VLMC_CREATE_PREFERENCE_KEYBOARD( "keyboard/mediapreview", "Ctrl+Return", "Media preview", "Preview the selected media, or pause the current preview" );
    VLMC_CREATE_PREFERENCE_KEYBOARD( "keyboard/renderpreview", "Space", "Render preview", "Preview the project, or pause the current preview" );
183
    //A bit nasty, but we better use what Qt's providing as default shortcut
Hugo Beauzee-Luyssen's avatar
Hugo Beauzee-Luyssen committed
184 185 186 187 188 189 190 191 192 193 194 195 196
    CREATE_MENU_SHORTCUT( "keyboard/undo", QKeySequence( QKeySequence::Undo ).toString().toLocal8Bit(), "Undo", "Undo the last action", actionUndo );
    CREATE_MENU_SHORTCUT( "keyboard/redo", QKeySequence( QKeySequence::Redo ).toString().toLocal8Bit(), "Redo", "Redo the last action", actionRedo );
    CREATE_MENU_SHORTCUT( "keyboard/help", QKeySequence( QKeySequence::HelpContents ).toString().toLocal8Bit(), "Help", "Toggle the help page", actionHelp );
    CREATE_MENU_SHORTCUT( "keyboard/quit", "Ctrl+Q", "Quit", "Quit VLMC", actionQuit );
    CREATE_MENU_SHORTCUT( "keyboard/preferences", "Alt+P", "Preferences", "Open VLMC preferences", actionPreferences );
    CREATE_MENU_SHORTCUT( "keyboard/fullscreen", "F", "Fullscreen", "Switch to fullscreen mode", actionFullscreen );
    CREATE_MENU_SHORTCUT( "keyboard/newproject", QKeySequence( QKeySequence::New ).toString().toLocal8Bit(), "New project", "Open the new project wizzard", actionNew_Project );
    CREATE_MENU_SHORTCUT( "keyboard/openproject", QKeySequence( QKeySequence::Open ).toString().toLocal8Bit(), "Open a project", "Open an existing project", actionLoad_Project );
    CREATE_MENU_SHORTCUT( "keyboard/save", QKeySequence( QKeySequence::Save ).toString().toLocal8Bit(), "Save", "Save the current project", actionSave );
    CREATE_MENU_SHORTCUT( "keyboard/saveas", "Ctrl+Shift+S", "Save as", "Save the current project to a new file", actionSave_As );
    CREATE_MENU_SHORTCUT( "keyboard/closeproject", QKeySequence( QKeySequence::Close ).toString().toLocal8Bit(), "Close the project", "Close the current project", actionClose_Project );
    CREATE_MENU_SHORTCUT( "keyboard/importmedia", "Ctrl+I", "Import media", "Open the import window", actionImport );
    CREATE_MENU_SHORTCUT( "keyboard/renderproject", "Ctrl+R", "Render the project", "Render the project to a file", actionRender );
197

198
    VLMC_CREATE_PREFERENCE_LANGUAGE( "general/VLMCLang", "en_US", "Langage", "The VLMC's UI language" );
199 200 201 202
    SettingsManager::getInstance()->watchValue( "general/VLMCLang",
                                                LanguageHelper::getInstance(),
                                                SLOT( languageChanged( const QVariant& ) ),
                                                SettingsManager::Vlmc );
203 204

    //Load saved preferences :
205 206 207 208 209 210 211 212 213
    QSettings       s;
    if ( s.value( "VlmcVersion" ).toString() != PROJECT_VERSION )
        s.clear();
    else
    {
        loadVlmcPreferences( "keyboard" );
        loadVlmcPreferences( "general" );
    }
    s.setValue( "VlmcVersion", PROJECT_VERSION );
214 215 216 217 218 219 220 221 222 223 224 225
}

void
MainWindow::loadVlmcPreferences( const QString &subPart )
{
    QSettings       s;
    s.beginGroup( subPart );
    foreach ( QString key, s.allKeys() )
    {
        SettingsManager::getInstance()->setValue( subPart + "/" + key, s.value( key ),
                                                  SettingsManager::Vlmc );
    }
226 227
}

Hugo Beauzee-Luyssen's avatar
Hugo Beauzee-Luyssen committed
228 229
#undef CREATE_MENU_SHORTCUT

230 231
void
MainWindow::setupLibrary()
Hugo Beauzee-Luyssen's avatar
Hugo Beauzee-Luyssen committed
232 233
{
    //GUI part :
234
    QWidget     *libraryWidget = new QWidget( this );
235
    libraryWidget->setMinimumWidth( 280 );
236 237 238 239 240

    QPushButton *button = new QPushButton( tr( "Import" ), this );
    connect( button, SIGNAL( clicked() ), this, SLOT( on_actionImport_triggered() ) );

    StackViewController *nav = new StackViewController( libraryWidget );
241 242
    MediaListView   *mediaView = new MediaListView( nav, Library::getInstance() );
    nav->pushViewController( mediaView );
243
    libraryWidget->layout()->addWidget( button );
244

245
    m_importController = new ImportController();
Hugo Beauzee-Luyssen's avatar
Hugo Beauzee-Luyssen committed
246 247
    const ClipRenderer* clipRenderer = qobject_cast<const ClipRenderer*>( m_clipPreview->getGenericRenderer() );
    Q_ASSERT( clipRenderer != NULL );
Hugo Beauzee-Luyssen's avatar
Hugo Beauzee-Luyssen committed
248

249
    DockWidgetManager::getInstance()->addDockedWidget( libraryWidget, tr( "Media Library" ),
250 251 252
                                                    Qt::AllDockWidgetAreas,
                                                    QDockWidget::AllDockWidgetFeatures,
                                                    Qt::LeftDockWidgetArea );
253
    connect( mediaView, SIGNAL( clipSelected( Clip* ) ),
Hugo Beauzee-Luyssen's avatar
Hugo Beauzee-Luyssen committed
254
             clipRenderer, SLOT( setClip( Clip* ) ) );
255

256 257
    connect( Library::getInstance(), SIGNAL( clipRemoved( const QUuid& ) ),
             clipRenderer, SLOT( clipUnloaded( const QUuid& ) ) );
Hugo Beauzee-Luyssen's avatar
Hugo Beauzee-Luyssen committed
258 259
}

260 261
void    MainWindow::on_actionSave_triggered()
{
262
    GUIProjectManager::getInstance()->saveProject();
263 264
}

Hugo Beauzee-Luyssen's avatar
Hugo Beauzee-Luyssen committed
265 266
void    MainWindow::on_actionSave_As_triggered()
{
267
    GUIProjectManager::getInstance()->saveProject( true );
Hugo Beauzee-Luyssen's avatar
Hugo Beauzee-Luyssen committed
268 269
}

270 271
void    MainWindow::on_actionLoad_Project_triggered()
{
272
    GUIProjectManager* pm = GUIProjectManager::getInstance();
273
    pm->loadProject( pm->acquireProjectFileName() );
274 275
}

276 277
void MainWindow::createStatusBar()
{
278 279
    // Mouse (default) tool
    QToolButton* mouseTool = new QToolButton( this );
280
    mouseTool->setAutoRaise( true );
281 282 283 284 285 286
    mouseTool->setCheckable( true );
    mouseTool->setIcon( QIcon( ":/images/mouse" ) );
    m_ui.statusbar->addPermanentWidget( mouseTool );

    // Cut/Split tool
    QToolButton* splitTool = new QToolButton( this );
287
    splitTool->setAutoRaise( true );
288 289 290 291 292 293 294 295 296 297 298
    splitTool->setCheckable( true );
    splitTool->setIcon( QIcon( ":/images/editcut" ) );
    m_ui.statusbar->addPermanentWidget( splitTool );

    // Group the two previous buttons
    QButtonGroup* toolButtonGroup = new QButtonGroup( this );
    toolButtonGroup->addButton( mouseTool, TOOL_DEFAULT);
    toolButtonGroup->addButton( splitTool, TOOL_CUT );
    toolButtonGroup->setExclusive( true );
    mouseTool->setChecked( true );

299
    //Shortcut part:
300 301
    KeyboardShortcutHelper* defaultModeShortcut = new KeyboardShortcutHelper( "keyboard/defaultmode", this );
    KeyboardShortcutHelper* cutModeShortcut = new KeyboardShortcutHelper( "keyboard/cutmode", this );
302 303 304
    connect( defaultModeShortcut, SIGNAL( activated() ), mouseTool, SLOT( click() ) );
    connect( cutModeShortcut, SIGNAL( activated() ), splitTool, SLOT( click() ) );

305 306 307 308 309 310 311 312
    connect( toolButtonGroup, SIGNAL( buttonClicked( int ) ),
             this, SLOT( toolButtonClicked( int ) ) );

    // Spacer
    QWidget* spacer = new QWidget( this );
    spacer->setFixedWidth( 20 );
    m_ui.statusbar->addPermanentWidget( spacer );

Ludovic Fauvet's avatar
Ludovic Fauvet committed
313 314 315 316 317 318
    // Zoom Out
    QToolButton* zoomOutButton = new QToolButton( this );
    zoomOutButton->setIcon( QIcon( ":/images/zoomout" ) );
    m_ui.statusbar->addPermanentWidget( zoomOutButton );
    connect( zoomOutButton, SIGNAL( clicked() ),
             this, SLOT( zoomOut() ) );
319 320

    // Zoom slider
321 322 323 324 325 326 327 328 329
    m_zoomSlider = new QSlider( this );
    m_zoomSlider->setOrientation( Qt::Horizontal );
    m_zoomSlider->setTickInterval( 1 );
    m_zoomSlider->setSingleStep( 1 );
    m_zoomSlider->setPageStep( 1 );
    m_zoomSlider->setMinimum( 0 );
    m_zoomSlider->setMaximum( 13 );
    m_zoomSlider->setValue( 10 );
    m_zoomSlider->setFixedWidth( 80 );
Ludovic Fauvet's avatar
Ludovic Fauvet committed
330
    m_zoomSlider->setInvertedAppearance( true );
331
    m_ui.statusbar->addPermanentWidget( m_zoomSlider );
332

Ludovic Fauvet's avatar
Ludovic Fauvet committed
333 334 335 336 337 338
    // Zoom IN
    QToolButton* zoomInButton = new QToolButton( this );
    zoomInButton->setIcon( QIcon( ":/images/zoomin" ) );
    m_ui.statusbar->addPermanentWidget( zoomInButton );
    connect( zoomInButton, SIGNAL( clicked() ),
             this, SLOT( zoomIn() ) );
339 340
}

341
void MainWindow::initializeDockWidgets( void )
342
{
343 344 345
    m_renderer = new WorkflowRenderer();
    m_renderer->initializeRenderer();
    m_timeline = new Timeline( m_renderer, this );
346 347 348
    m_timeline->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding );
    m_timeline->show();
    setCentralWidget( m_timeline );
349

350
    DockWidgetManager *dockManager = DockWidgetManager::getInstance();
351

352 353
    m_clipPreview = new PreviewWidget( new ClipRenderer, this );
    dockManager->addDockedWidget( m_clipPreview,
354
                                  tr( "Clip Preview" ),
geoff's avatar
geoff committed
355 356 357
                                  Qt::AllDockWidgetAreas,
                                  QDockWidget::AllDockWidgetFeatures,
                                  Qt::TopDockWidgetArea );
358
    KeyboardShortcutHelper* clipShortcut = new KeyboardShortcutHelper( "keyboard/mediapreview", this );
359
    connect( clipShortcut, SIGNAL( activated() ), m_clipPreview, SLOT( on_pushButtonPlay_clicked() ) );
360

361
    m_projectPreview = new PreviewWidget( m_renderer, this );
362
    dockManager->addDockedWidget( m_projectPreview,
363 364 365
                                  tr( "Project Preview" ),
                                  Qt::AllDockWidgetAreas,
                                  QDockWidget::AllDockWidgetFeatures,
366
                                  Qt::TopDockWidgetArea );
367
    KeyboardShortcutHelper* renderShortcut = new KeyboardShortcutHelper( "keyboard/renderpreview", this );
368
    connect( renderShortcut, SIGNAL( activated() ), m_projectPreview, SLOT( on_pushButtonPlay_clicked() ) );
369

370
    QDockWidget* dock = dockManager->addDockedWidget( UndoStack::getInstance( this ),
371 372 373 374
                                  tr( "History" ),
                                  Qt::AllDockWidgetAreas,
                                  QDockWidget::AllDockWidgetFeatures,
                                  Qt::LeftDockWidgetArea );
375 376
    if ( dock != 0 )
        dock->hide();
377
    setupLibrary();
378 379
}

380 381
void        MainWindow::createGlobalPreferences()
{
382
    m_globalPreferences = new Settings( SettingsManager::Vlmc, this );
383 384 385 386 387 388
    m_globalPreferences->addCategorie( "general", SettingsManager::Vlmc,
                                   QIcon( ":/images/images/vlmc.png" ),
                                   tr ( "VLMC settings" ) );
    m_globalPreferences->addCategorie( "keyboard", SettingsManager::Vlmc,
                                     QIcon( ":/images/keyboard" ),
                                     tr( "Keyboard Settings" ) );
389 390
}

391
void    MainWindow::createProjectPreferences()
392
{
393
    m_projectPreferences = new Settings( SettingsManager::Project, this );
394 395 396 397 398 399 400 401 402
    m_projectPreferences->addCategorie( "general", SettingsManager::Project,
                                   QIcon( ":/images/images/vlmc.png" ),
                                   tr ( "Project settings" ) );
    m_projectPreferences->addCategorie( "video", SettingsManager::Project,
                                   QIcon( ":/images/images/video.png" ),
                                   tr ( "Video settings" ) );
    m_projectPreferences->addCategorie( "audio", SettingsManager::Project,
                                   QIcon( ":/images/images/audio.png" ),
                                   tr ( "Audio settings" ) );
403 404
}

405

406 407
//Private slots definition

Ludovic Fauvet's avatar
Ludovic Fauvet committed
408 409 410 411
void MainWindow::on_actionQuit_triggered()
{
    QApplication::quit();
}
412 413 414

void MainWindow::on_actionPreferences_triggered()
{
415
   m_globalPreferences->show();
416
}
Ludovic Fauvet's avatar
Ludovic Fauvet committed
417 418 419

void MainWindow::on_actionAbout_triggered()
{
420
    About::getInstance()->exec();
Ludovic Fauvet's avatar
Ludovic Fauvet committed
421
}
422

423
void MainWindow::on_actionTranscode_triggered()
424
{
425 426
    QMessageBox::information( this, tr( "Sorry" ),
                              tr( "This feature is currently disabled." ) );
427
    //Transcode::instance( this )->exec();
428
}
429

430 431
void    MainWindow::on_actionRender_triggered()
{
432
    if ( MainWorkflow::getInstance()->getLengthFrame() <= 0 )
433
    {
434
        QMessageBox::warning( NULL, tr ( "VLMC Renderer" ), tr( "There is nothing to render." ) );
435 436
        return ;
    }
437 438
    else
    {
439
        m_renderer->killRenderer();
440 441
        if ( m_fileRenderer )
            delete m_fileRenderer;
Hugo Beauzee-Luyssen's avatar
Hugo Beauzee-Luyssen committed
442
        m_fileRenderer = new WorkflowFileRenderer();
443 444 445 446 447 448 449 450 451 452 453 454 455 456
        //Setup dialog box for querying render parameters.
        RendererSettings    *settings = new RendererSettings;
        if ( settings->exec() == QDialog::Rejected )
        {
            delete settings;
            return ;
        }
        QString     outputFileName = settings->outputFileName();
        quint32     width = settings->width();
        quint32     height = settings->height();
        double      fps = settings->fps();
        quint32     vbitrate = settings->videoBitrate();
        quint32     abitrate = settings->audioBitrate();
        delete settings;
457
        m_fileRenderer->initializeRenderer();
458
        m_fileRenderer->run( outputFileName, width, height, fps, vbitrate, abitrate );
459
    }
460 461
}

462 463
void MainWindow::on_actionNew_Project_triggered()
{
464
    m_pWizard->restart();
465
    m_pWizard->show();
466 467
}

468
void    MainWindow::on_actionHelp_triggered()
469 470
{
    QDesktopServices::openUrl( QUrl( "http://vlmc.org" ) );
471 472
}

473
void    MainWindow::zoomIn()
Ludovic Fauvet's avatar
Ludovic Fauvet committed
474 475 476 477
{
    m_zoomSlider->setValue( m_zoomSlider->value() - 1 );
}

478
void    MainWindow::zoomOut()
Ludovic Fauvet's avatar
Ludovic Fauvet committed
479 480 481
{
    m_zoomSlider->setValue( m_zoomSlider->value() + 1 );
}
Ludovic Fauvet's avatar
Ludovic Fauvet committed
482

483
void    MainWindow::on_actionFullscreen_triggered( bool checked )
Ludovic Fauvet's avatar
Ludovic Fauvet committed
484 485 486 487 488 489
{
    if ( checked )
        showFullScreen();
    else
        showNormal();
}
490

491
void    MainWindow::registerWidgetInWindowMenu( QDockWidget* widget )
492
{
493
    m_ui.menuWindow->addAction( widget->toggleViewAction() );
494
}
495

496
void    MainWindow::toolButtonClicked( int id )
497 498 499
{
    emit toolChanged( (ToolButtons)id );
}
500

501 502 503 504 505 506 507 508 509 510 511
void MainWindow::on_actionBypass_effects_engine_toggled(bool toggled)
{
    EffectsEngine*  ee;

    ee = MainWorkflow::getInstance()->getEffectsEngine();
    if (toggled)
        ee->enable();
    else
       ee->disable();
    return ;
}
512

513 514
void MainWindow::on_actionProject_Preferences_triggered()
{
515
  m_projectPreferences->show();
516
}
517

518 519
void    MainWindow::closeEvent( QCloseEvent* e )
{
520 521
    GUIProjectManager   *pm = GUIProjectManager::getInstance();
    if ( pm->askForSaveIfModified() )
522
        e->accept();
523 524
    else
        e->ignore();
525
}
526

527
void    MainWindow::projectUpdated( const QString& projectName, bool savedStatus )
528 529
{
    QString title = tr( "VideoLAN Movie Creator" );
530
    title += " - ";
531 532 533 534 535
    title += projectName;
    if ( savedStatus == false )
        title += " *";
    setWindowTitle( title );
}
536

537 538
void    MainWindow::on_actionClose_Project_triggered()
{
539
    GUIProjectManager::getInstance()->closeProject();
540 541
}

542 543 544 545 546 547 548 549 550 551
void    MainWindow::on_actionUndo_triggered()
{
    UndoStack::getInstance( this )->undo();
}

void    MainWindow::on_actionRedo_triggered()
{
    UndoStack::getInstance( this )->redo();
}

Hugo Beauzee-Luyssen's avatar
Hugo Beauzee-Luyssen committed
552 553
void    MainWindow::on_actionCrash_triggered()
{
554 555 556 557 558
    //WARNING: read this part at your own risk !!
    //I'm not responsible if you puke while reading this :D
    QString str;
    int test = 1 / str.length();
    Q_UNUSED( test );
Hugo Beauzee-Luyssen's avatar
Hugo Beauzee-Luyssen committed
559
}
Hugo Beauzee-Luyssen's avatar
Hugo Beauzee-Luyssen committed
560 561 562 563

bool    MainWindow::restoreSession()
{
    QSettings   s;
564
    bool        fileCreated = false;
Hugo Beauzee-Luyssen's avatar
Hugo Beauzee-Luyssen committed
565 566
    bool        ret = false;

567 568
    fileCreated = s.contains( "VlmcVersion" );
    if ( fileCreated == true )
Hugo Beauzee-Luyssen's avatar
Hugo Beauzee-Luyssen committed
569
    {
570 571 572 573 574 575 576 577
        bool        cleanQuit = s.value( "CleanQuit", false ).toBool();

        // Restore the geometry
        restoreGeometry( s.value( "MainWindowGeometry" ).toByteArray() );
        // Restore the layout
        restoreState( s.value( "MainWindowState" ).toByteArray() );

        if ( cleanQuit == false )
Hugo Beauzee-Luyssen's avatar
Hugo Beauzee-Luyssen committed
578
        {
579 580 581 582
            QMessageBox::StandardButton res = QMessageBox::question( this, tr( "Crash recovery" ), tr( "VLMC didn't closed nicely. Do you wan't to recover your project ?" ),
                                   QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes );
            if ( res == QMessageBox::Yes )
            {
583
                if ( GUIProjectManager::getInstance()->loadEmergencyBackup() == true )
584 585 586 587
                    ret = true;
                else
                    QMessageBox::warning( this, tr( "Can't restore project" ), tr( "VLMC didn't manage to restore your project. We appology for the inconvenience" ) );
            }
Hugo Beauzee-Luyssen's avatar
Hugo Beauzee-Luyssen committed
588 589 590 591 592 593
        }
    }
    s.setValue( "CleanQuit", false );
    s.sync();
    return ret;
}
594 595 596 597 598

void    MainWindow::on_actionImport_triggered()
{
    m_importController->exec();
}
599

600 601 602 603 604 605 606 607 608 609
void    MainWindow::canUndoChanged( bool canUndo )
{
    m_ui.actionUndo->setEnabled( canUndo );
}

void    MainWindow::canRedoChanged( bool canRedo )
{
    m_ui.actionRedo->setEnabled( canRedo );
}

Ludovic Fauvet's avatar
Ludovic Fauvet committed
610
#ifdef WITH_CRASHBUTTON
611 612 613 614 615 616 617 618 619
void    MainWindow::setupCrashTester()
{
    QAction* actionCrash = new QAction( this );
    actionCrash->setObjectName( QString::fromUtf8( "actionCrash" ) );
    m_ui.menuTools->addAction( actionCrash );
    actionCrash->setText( QApplication::translate( "MainWindow", "Crash", 0, QApplication::UnicodeUTF8 ) );
    connect( actionCrash, SIGNAL( triggered( bool ) ), this, SLOT( on_actionCrash_triggered() ) );
}
#endif
620