MainWindow.cpp 20.5 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"
Hugo Beauzee-Luyssen's avatar
Hugo Beauzee-Luyssen committed
34
#include "Library.h"
Ludovic Fauvet's avatar
Ludovic Fauvet committed
35
#include "About.h"
36 37 38 39
#include "ProjectManager.h"
#include "KeyboardShortcut.h"
#include "VlmcDebug.h"

Ludovic Fauvet's avatar
Ludovic Fauvet committed
40 41
#include "MainWorkflow.h"
#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
#include "UndoStack.h"
49
#include "PreviewWidget.h"
50 51 52 53 54 55 56
#include "MediaLibraryWidget.h"
#include "timeline/Timeline.h"
#include "timeline/TracksView.h"
#include "ImportController.h"

/* Settings / Preferences */
#include "ProjectManager.h"
Ludovic Fauvet's avatar
Ludovic Fauvet committed
57
#include "ProjectWizard.h"
58
#include "ProjectPreferences.h"
59 60
#include "VLMCPreferences.h"
#include "VLMCSettingsDefault.h"
61 62
#include "AudioProjectPreferences.h"
#include "VideoProjectPreferences.h"
63
#include "LanguagePreferences.h"
Ludovic Fauvet's avatar
Ludovic Fauvet committed
64
#include "Settings.h"
65
#include "SettingsManager.h"
Ludovic Fauvet's avatar
Ludovic Fauvet committed
66

67 68 69
/* VLCpp */
#include "VLCInstance.h"

Ludovic Fauvet's avatar
Ludovic Fauvet committed
70
MainWindow::MainWindow( QWidget *parent ) :
71
    QMainWindow( parent ), m_fileRenderer( NULL )
Ludovic Fauvet's avatar
Ludovic Fauvet committed
72 73
{
    m_ui.setupUi( this );
74

75
    qRegisterMetaType<MainWorkflow::TrackType>( "MainWorkflow::TrackType" );
76
    qRegisterMetaType<MainWorkflow::FrameChangedReason>( "MainWorkflow::FrameChangedReason" );
77
    qRegisterMetaType<QVariant>( "QVariant" );
78 79 80 81

    // Settings
    VLMCSettingsDefault::load( "default" );
    VLMCSettingsDefault::load( "VLMC" );
82
    VLMCSettingsDefault::loadKeyboardShortcutDefaults();
Hugo Beauzee-Luyssen's avatar
Hugo Beauzee-Luyssen committed
83
    //We only install message handler here cause it uses configuration.
84
    VlmcDebug::getInstance()->setup();
85 86

    // GUI
87
    DockWidgetManager::instance( this )->setMainWindow( this );
88
    initializeDockWidgets();
89
    createStatusBar();
90
    createGlobalPreferences();
91
    createProjectPreferences();
92
    initializeMenuKeyboardShortcut();
93 94 95
#ifdef DEBUG_CRASHHANDLER
    setupCrashTester();
#endif
96

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

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

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

114 115 116 117 118 119 120 121 122
    // 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
123 124 125 126
    // Wizard
    m_pWizard = new ProjectWizard( this );
    m_pWizard->setModal( true );

127 128 129
    QSettings s;
    if ( s.value( "ShowWizardStartup", true ).toBool() &&
         restoreSession() == false )
Hugo Beauzee-Luyssen's avatar
Hugo Beauzee-Luyssen committed
130 131 132
    {
        m_pWizard->show();
    }
Ludovic Fauvet's avatar
Ludovic Fauvet committed
133 134
}

135 136
MainWindow::~MainWindow()
{
137 138 139 140 141
    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
142
    s.setValue( "CleanQuit", true );
143 144
    s.sync();

145 146
    if ( m_fileRenderer )
        delete m_fileRenderer;
147
    LibVLCpp::Instance::destroyInstance();
148 149
}

Ludovic Fauvet's avatar
Ludovic Fauvet committed
150 151 152 153 154 155
void MainWindow::changeEvent( QEvent *e )
{
    switch ( e->type() )
    {
    case QEvent::LanguageChange:
        m_ui.retranslateUi( this );
156
        emit translateDockWidgetTitle();
Ludovic Fauvet's avatar
Ludovic Fauvet committed
157 158 159 160 161 162
        break;
    default:
        break;
    }
}

Hugo Beauzee-Luyssen's avatar
Hugo Beauzee-Luyssen committed
163 164 165
void        MainWindow::setupLibrary()
{
    //GUI part :
166

167
    MediaLibraryWidget* mediaLibraryWidget = new MediaLibraryWidget( this );
168
    m_importController = new ImportController( this );
Hugo Beauzee-Luyssen's avatar
Hugo Beauzee-Luyssen committed
169

170 171 172 173
    DockWidgetManager::instance()->addDockedWidget( mediaLibraryWidget,
                                                    tr( "Media Library" ),
                                                    Qt::AllDockWidgetAreas,
                                                    QDockWidget::AllDockWidgetFeatures,
174

175
                                                    Qt::LeftDockWidgetArea );
Geoffroy Lacarriere's avatar
Geoffroy Lacarriere committed
176 177
    connect( mediaLibraryWidget, SIGNAL( mediaSelected( Media* ) ),
             m_clipPreview->getGenericRenderer(), SLOT( setMedia( Media* ) ) );
178

179 180
    connect( Library::getInstance(), SIGNAL( mediaRemoved( const QUuid& ) ),
             m_clipPreview->getGenericRenderer(), SLOT( mediaUnloaded( QUuid ) ) );
181 182

    connect( mediaLibraryWidget, SIGNAL( importRequired() ), this, SLOT( on_actionImport_triggered() ) );
183 184

    connect( m_clipPreview, SIGNAL( addClip( Clip* ) ), mediaLibraryWidget, SLOT( clipAdded( Clip* ) ) );
185 186 187

    connect( mediaLibraryWidget, SIGNAL( previewClipSetted( Clip* ) ),
            m_clipPreview->getGenericRenderer(), SLOT( setClip( Clip* ) ) );
Hugo Beauzee-Luyssen's avatar
Hugo Beauzee-Luyssen committed
188 189
}

190 191
void    MainWindow::on_actionSave_triggered()
{
192
    ProjectManager::getInstance()->saveProject();
193 194
}

Hugo Beauzee-Luyssen's avatar
Hugo Beauzee-Luyssen committed
195 196 197 198 199
void    MainWindow::on_actionSave_As_triggered()
{
    ProjectManager::getInstance()->saveProject( true );
}

200 201
void    MainWindow::on_actionLoad_Project_triggered()
{
202 203
    ProjectManager* pm = ProjectManager::getInstance();
    pm->loadProject( pm->loadProjectFile() );
204 205
}

206 207
void MainWindow::createStatusBar()
{
208 209
    // Mouse (default) tool
    QToolButton* mouseTool = new QToolButton( this );
210
    mouseTool->setAutoRaise( true );
211 212 213 214 215 216
    mouseTool->setCheckable( true );
    mouseTool->setIcon( QIcon( ":/images/mouse" ) );
    m_ui.statusbar->addPermanentWidget( mouseTool );

    // Cut/Split tool
    QToolButton* splitTool = new QToolButton( this );
217
    splitTool->setAutoRaise( true );
218 219 220 221 222 223 224 225 226 227 228
    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 );

229 230 231 232 233 234
    //Shortcut part:
    KeyboardShortcutHelper* defaultModeShortcut = new KeyboardShortcutHelper( "Default mode", this );
    KeyboardShortcutHelper* cutModeShortcut = new KeyboardShortcutHelper( "Cut mode", this );
    connect( defaultModeShortcut, SIGNAL( activated() ), mouseTool, SLOT( click() ) );
    connect( cutModeShortcut, SIGNAL( activated() ), splitTool, SLOT( click() ) );

235 236 237 238 239 240 241 242
    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
243 244 245 246 247 248
    // Zoom Out
    QToolButton* zoomOutButton = new QToolButton( this );
    zoomOutButton->setIcon( QIcon( ":/images/zoomout" ) );
    m_ui.statusbar->addPermanentWidget( zoomOutButton );
    connect( zoomOutButton, SIGNAL( clicked() ),
             this, SLOT( zoomOut() ) );
249 250

    // Zoom slider
251 252 253 254 255 256 257 258 259
    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
260
    m_zoomSlider->setInvertedAppearance( true );
261
    m_ui.statusbar->addPermanentWidget( m_zoomSlider );
262

Ludovic Fauvet's avatar
Ludovic Fauvet committed
263 264 265 266 267 268
    // Zoom IN
    QToolButton* zoomInButton = new QToolButton( this );
    zoomInButton->setIcon( QIcon( ":/images/zoomin" ) );
    m_ui.statusbar->addPermanentWidget( zoomInButton );
    connect( zoomInButton, SIGNAL( clicked() ),
             this, SLOT( zoomIn() ) );
269 270
}

271
void MainWindow::initializeDockWidgets( void )
272
{
273 274 275
    m_renderer = new WorkflowRenderer();
    m_renderer->initializeRenderer();
    m_timeline = new Timeline( m_renderer, this );
276 277 278
    m_timeline->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding );
    m_timeline->show();
    setCentralWidget( m_timeline );
279

280 281
    DockWidgetManager *dockManager = DockWidgetManager::instance();

282 283
    m_clipPreview = new PreviewWidget( new ClipRenderer, this );
    dockManager->addDockedWidget( m_clipPreview,
284
                                  tr( "Clip Preview" ),
geoff's avatar
geoff committed
285 286 287
                                  Qt::AllDockWidgetAreas,
                                  QDockWidget::AllDockWidgetFeatures,
                                  Qt::TopDockWidgetArea );
288
    KeyboardShortcutHelper* clipShortcut = new KeyboardShortcutHelper( "Launch media preview", this );
289
    connect( clipShortcut, SIGNAL( activated() ), m_clipPreview, SLOT( on_pushButtonPlay_clicked() ) );
290

291
    m_projectPreview = new PreviewWidget( m_renderer, this );
292
    dockManager->addDockedWidget( m_projectPreview,
293 294 295
                                  tr( "Project Preview" ),
                                  Qt::AllDockWidgetAreas,
                                  QDockWidget::AllDockWidgetFeatures,
296
                                  Qt::TopDockWidgetArea );
297
    KeyboardShortcutHelper* renderShortcut = new KeyboardShortcutHelper( "Start render preview", this );
298
    connect( renderShortcut, SIGNAL( activated() ), m_projectPreview, SLOT( on_pushButtonPlay_clicked() ) );
299

300
    dockManager->addDockedWidget( UndoStack::getInstance( this ),
301 302 303 304
                                  tr( "History" ),
                                  Qt::AllDockWidgetAreas,
                                  QDockWidget::AllDockWidgetFeatures,
                                  Qt::LeftDockWidgetArea );
305
    setupLibrary();
306 307
}

308 309
void        MainWindow::createGlobalPreferences()
{
310
    m_globalPreferences = new Settings( false, "VLMC", this );
311
    m_globalPreferences->addWidget("VLMC",
Ludovic Fauvet's avatar
Ludovic Fauvet committed
312
                                   new VLMCPreferences( m_globalPreferences ),
313
                                   QIcon( ":/images/images/vlmc.png" ),
314
                                   "VLMC settings");
315 316
    m_globalPreferences->addWidget("Language preferences",
                                   new LanguagePreferences( m_globalPreferences ),
317
                                   QIcon( ":/images/images/vlmc.png" ),
318
                                   "Langage settings");
319 320 321 322
    m_globalPreferences->addWidget( "Keyboard",
                                     new KeyboardShortcut( m_globalPreferences ),
                                     QIcon( ":/images/keyboard" ),
                                     tr( "Keyboard Settings" ) );
323 324
}

325 326
void	    MainWindow::createProjectPreferences()
{
327
    m_projectPreferences = new Settings( false, "project", this );
328 329
    m_projectPreferences->addWidget("Project",
                                   new ProjectPreferences,
330
                                   QIcon( ":/images/images/vlmc.png" ),
331 332
                                   "Project settings" );
    m_projectPreferences->addWidget( "Video",
333
                                   new VideoProjectPreferences,
334
                                   QIcon( ":/images/images/video.png" ),
335 336
                                   "Video settings" );
    m_projectPreferences->addWidget( "Audio",
337
                                   new AudioProjectPreferences,
338
                                   QIcon( ":/images/images/audio.png" ),
339
                                   "Audio settings" );
340 341
}

342

343 344
//Private slots definition

Ludovic Fauvet's avatar
Ludovic Fauvet committed
345 346 347 348
void MainWindow::on_actionQuit_triggered()
{
    QApplication::quit();
}
349 350 351

void MainWindow::on_actionPreferences_triggered()
{
352
   m_globalPreferences->show();
353
}
Ludovic Fauvet's avatar
Ludovic Fauvet committed
354 355 356 357 358

void MainWindow::on_actionAbout_triggered()
{
    About::instance()->exec();
}
359

360
void MainWindow::on_actionTranscode_triggered()
361
{
362 363
    QMessageBox::information( this, tr( "Sorry" ),
                              tr( "This feature is currently disabled." ) );
364
    //Transcode::instance( this )->exec();
365
}
366

367 368
void    MainWindow::on_actionRender_triggered()
{
369
    if ( MainWorkflow::getInstance()->getLengthFrame() <= 0 )
370 371 372 373
    {
        QMessageBox::warning( NULL, "VLMC Renderer", "There is nothing to render." );
        return ;
    }
374 375 376 377 378 379 380
    QString outputFileName =
            QFileDialog::getSaveFileName( NULL, "Enter the output file name",
                                          QDir::currentPath(), "Videos(*.avi *.mpg)" );
    if ( outputFileName.length() == 0 )
        return ;
    else
    {
381 382 383 384 385 386
        m_renderer->stop();
        if ( m_fileRenderer )
            delete m_fileRenderer;
        m_fileRenderer = new WorkflowFileRenderer( outputFileName );
        m_fileRenderer->initializeRenderer();
        m_fileRenderer->run();
387
    }
388 389
}

390 391 392 393
void MainWindow::on_actionNew_Project_triggered()
{
    //TODO : clear the library, the timeline, and show the configuration box
    //of the newly created project
394

395
    m_pWizard->restart();
396
    m_pWizard->show();
397 398
}

399
void    MainWindow::on_actionHelp_triggered()
400 401
{
    QDesktopServices::openUrl( QUrl( "http://vlmc.org" ) );
402 403
}

404
void    MainWindow::zoomIn()
Ludovic Fauvet's avatar
Ludovic Fauvet committed
405 406 407 408
{
    m_zoomSlider->setValue( m_zoomSlider->value() - 1 );
}

409
void    MainWindow::zoomOut()
Ludovic Fauvet's avatar
Ludovic Fauvet committed
410 411 412
{
    m_zoomSlider->setValue( m_zoomSlider->value() + 1 );
}
Ludovic Fauvet's avatar
Ludovic Fauvet committed
413

414
void    MainWindow::on_actionFullscreen_triggered( bool checked )
Ludovic Fauvet's avatar
Ludovic Fauvet committed
415 416 417 418 419 420
{
    if ( checked )
        showFullScreen();
    else
        showNormal();
}
421

422
void    MainWindow::registerWidgetInWindowMenu( QDockWidget* widget )
423
{
424
    m_ui.menuWindow->addAction( widget->toggleViewAction() );
425
}
426

427
void    MainWindow::toolButtonClicked( int id )
428 429 430
{
    emit toolChanged( (ToolButtons)id );
}
431

432 433 434 435 436 437 438 439 440 441 442
void MainWindow::on_actionBypass_effects_engine_toggled(bool toggled)
{
    EffectsEngine*  ee;

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

444 445
void MainWindow::on_actionProject_Preferences_triggered()
{
446
  m_projectPreferences->show( "project" );
447
}
448

449 450
void    MainWindow::closeEvent( QCloseEvent* e )
{
451
    if ( ProjectManager::getInstance()->askForSaveIfModified() )
452
        e->accept();
453 454
    else
        e->ignore();
455
}
456

457
void    MainWindow::projectUpdated( const QString& projectName, bool savedStatus )
458 459
{
    QString title = tr( "VideoLAN Movie Creator" );
460
    title += " - ";
461 462 463 464 465
    title += projectName;
    if ( savedStatus == false )
        title += " *";
    setWindowTitle( title );
}
466

467 468 469 470 471
void    MainWindow::on_actionClose_Project_triggered()
{
    ProjectManager::getInstance()->closeProject();
}

472 473 474 475 476 477 478 479 480 481
void    MainWindow::on_actionUndo_triggered()
{
    UndoStack::getInstance( this )->undo();
}

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

482
#define INIT_SHORTCUT( instName, shortcutName, actionInstance )      \
483 484
            const SettingValue* instName = SettingsManager::getInstance()->getValue( "keyboard_shortcut", shortcutName );\
            KeyboardShortcutHelper* helper##instName = new KeyboardShortcutHelper( shortcutName, this, true ); \
485 486
            connect( helper##instName, SIGNAL( changed( const QString&, const QString&) ), this, SLOT( keyboardShortcutChanged(QString,QString)) ); \
            m_ui.actionInstance->setShortcut( instName->get().toString() );
487 488 489

void    MainWindow::initializeMenuKeyboardShortcut()
{
490 491 492 493 494 495 496 497
    INIT_SHORTCUT( help, "Help", actionHelp );
    INIT_SHORTCUT( quit, "Quit", actionQuit );
    INIT_SHORTCUT( preferences, "Preferences", actionPreferences );
    INIT_SHORTCUT( fullscreen, "Fullscreen", actionFullscreen );
    INIT_SHORTCUT( newProject, "New project", actionNew_Project );
    INIT_SHORTCUT( openProject, "Open project", actionLoad_Project );
    INIT_SHORTCUT( save, "Save", actionSave );
    INIT_SHORTCUT( saveAs, "Save as", actionSave_As );
498
    INIT_SHORTCUT( closeProject, "Close project", actionClose_Project );
499
    INIT_SHORTCUT( importProject, "Import media", actionImport );
500
    INIT_SHORTCUT( renderProject, "Render project", actionRender );
501 502
    INIT_SHORTCUT( undo, "Undo", actionUndo );
    INIT_SHORTCUT( redo, "Redo", actionRedo );
503 504
}

505 506
#undef INIT_SHORTCUT

507 508 509 510 511
void    MainWindow::keyboardShortcutChanged( const QString& name, const QString& val )
{
    qDebug() << "shortcut" << name << "changed to" << val;
    if ( name == "Help" )
        m_ui.actionHelp->setShortcut( val );
512 513 514 515 516 517 518 519 520 521 522 523 524 525
    else if ( name == "Quit" )
        m_ui.actionQuit->setShortcut( val );
    else if ( name == "Preferences" )
        m_ui.actionPreferences->setShortcut( val );
    else if ( name == "Fullscreen" )
        m_ui.actionFullscreen->setShortcut( val );
    else if ( name == "New project" )
        m_ui.actionNew_Project->setShortcut( val );
    else if ( name == "Open project" )
        m_ui.actionLoad_Project->setShortcut( val );
    else if ( name == "Save" )
        m_ui.actionSave->setShortcut( val );
    else if ( name == "Save as" )
        m_ui.actionSave_As->setShortcut( val );
526 527
    else if ( name == "Close project" )
        m_ui.actionClose_Project->setShortcut( val );
528 529
    else if ( name == "Import media" )
        m_ui.actionImport->setShortcut( val );
530 531
    else if ( name == "Render project" )
        m_ui.actionRender->setShortcut( val );
532 533 534 535
    else if ( name == "Undo" )
        m_ui.actionUndo->setShortcut( val );
    else if ( name == "Redo" )
        m_ui.actionRedo->setShortcut( val );
536 537
    else
        qWarning() << "Unknown shortcut:" << name;
538
}
Hugo Beauzee-Luyssen's avatar
Hugo Beauzee-Luyssen committed
539 540 541

void    MainWindow::on_actionCrash_triggered()
{
542 543 544 545 546
    //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
547
}
Hugo Beauzee-Luyssen's avatar
Hugo Beauzee-Luyssen committed
548 549 550 551

bool    MainWindow::restoreSession()
{
    QSettings   s;
552
    bool        fileCreated = false;
Hugo Beauzee-Luyssen's avatar
Hugo Beauzee-Luyssen committed
553 554
    bool        ret = false;

555 556
    fileCreated = s.contains( "VlmcVersion" );
    if ( fileCreated == true )
Hugo Beauzee-Luyssen's avatar
Hugo Beauzee-Luyssen committed
557
    {
558 559 560 561 562 563 564 565
        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
566
        {
567 568 569 570 571 572 573 574 575
            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 )
            {
                if ( ProjectManager::getInstance()->loadEmergencyBackup() == true )
                    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
576 577 578 579 580 581
        }
    }
    s.setValue( "CleanQuit", false );
    s.sync();
    return ret;
}
582 583 584 585 586

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

588 589 590 591 592 593 594 595 596 597
void    MainWindow::canUndoChanged( bool canUndo )
{
    m_ui.actionUndo->setEnabled( canUndo );
}

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

598 599 600 601 602 603 604 605 606 607
#ifdef DEBUG_CRASHHANDLER
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