MainWindow.cpp 20.7 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 39 40
#include "ProjectManager.h"
#include "KeyboardShortcut.h"
#include "VlmcDebug.h"

Ludovic Fauvet's avatar
Ludovic Fauvet committed
41 42
#include "MainWorkflow.h"
#include "WorkflowFileRenderer.h"
43
#include "WorkflowRenderer.h"
44
#include "ClipRenderer.h"
Ludovic Fauvet's avatar
Ludovic Fauvet committed
45
#include "EffectsEngine.h"
46 47 48

/* Widgets */
#include "DockWidgetManager.h"
49
#include "UndoStack.h"
50
#include "PreviewWidget.h"
51 52 53 54 55 56 57
#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
58
#include "ProjectWizard.h"
59
#include "ProjectPreferences.h"
60 61
#include "VLMCPreferences.h"
#include "VLMCSettingsDefault.h"
62 63
#include "AudioProjectPreferences.h"
#include "VideoProjectPreferences.h"
64
#include "LanguagePreferences.h"
Ludovic Fauvet's avatar
Ludovic Fauvet committed
65
#include "Settings.h"
66
#include "SettingsManager.h"
Ludovic Fauvet's avatar
Ludovic Fauvet committed
67

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

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

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

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

87 88 89
    //VLC Instance:
    LibVLCpp::Instance::getInstance( this );

90
    // GUI
91
    DockWidgetManager::instance( this )->setMainWindow( this );
92
    initializeDockWidgets();
93
    createStatusBar();
94
    createGlobalPreferences();
95
    createProjectPreferences();
96
    initializeMenuKeyboardShortcut();
Ludovic Fauvet's avatar
Ludovic Fauvet committed
97
#ifdef WITH_CRASHBUTTON
98 99
    setupCrashTester();
#endif
100

Ludovic Fauvet's avatar
Ludovic Fauvet committed
101
    // Translations
102 103
    connect( this, SIGNAL( translateDockWidgetTitle() ),
             DockWidgetManager::instance(), SLOT( transLateWidgetTitle() ) );
Ludovic Fauvet's avatar
Ludovic Fauvet committed
104 105

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

115 116
    connect( ProjectManager::getInstance(), SIGNAL( projectUpdated( const QString&, bool ) ),
             this, SLOT( projectUpdated( const QString&, bool ) ) );
117

118 119 120 121 122 123 124 125 126
    // 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
127 128 129 130
    // Wizard
    m_pWizard = new ProjectWizard( this );
    m_pWizard->setModal( true );

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

139 140
MainWindow::~MainWindow()
{
141 142 143 144 145
    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
146
    s.setValue( "CleanQuit", true );
147 148
    s.sync();

149 150
    if ( m_fileRenderer )
        delete m_fileRenderer;
151
    delete m_importController;
152 153
}

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

Hugo Beauzee-Luyssen's avatar
Hugo Beauzee-Luyssen committed
167 168 169
void        MainWindow::setupLibrary()
{
    //GUI part :
170

171
    MediaLibraryWidget* mediaLibraryWidget = new MediaLibraryWidget( this );
172
    m_importController = new ImportController();
Hugo Beauzee-Luyssen's avatar
Hugo Beauzee-Luyssen committed
173

174 175 176 177 178
    DockWidgetManager::instance()->addDockedWidget( mediaLibraryWidget,
                                                    tr( "Media Library" ),
                                                    Qt::AllDockWidgetAreas,
                                                    QDockWidget::AllDockWidgetFeatures,
                                                    Qt::LeftDockWidgetArea );
Geoffroy Lacarriere's avatar
Geoffroy Lacarriere committed
179 180
    connect( mediaLibraryWidget, SIGNAL( mediaSelected( Media* ) ),
             m_clipPreview->getGenericRenderer(), SLOT( setMedia( Media* ) ) );
181

182 183
    connect( Library::getInstance(), SIGNAL( mediaRemoved( const QUuid& ) ),
             m_clipPreview->getGenericRenderer(), SLOT( mediaUnloaded( QUuid ) ) );
184 185

    connect( mediaLibraryWidget, SIGNAL( importRequired() ), this, SLOT( on_actionImport_triggered() ) );
186 187

    connect( m_clipPreview, SIGNAL( addClip( Clip* ) ), mediaLibraryWidget, SLOT( clipAdded( Clip* ) ) );
188 189 190

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

193 194
void    MainWindow::on_actionSave_triggered()
{
195
    ProjectManager::getInstance()->saveProject();
196 197
}

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

203 204
void    MainWindow::on_actionLoad_Project_triggered()
{
205 206
    ProjectManager* pm = ProjectManager::getInstance();
    pm->loadProject( pm->loadProjectFile() );
207 208
}

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

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

232 233 234 235 236 237
    //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() ) );

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

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

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

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

283 284
    DockWidgetManager *dockManager = DockWidgetManager::instance();

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

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

303
    QDockWidget* dock = dockManager->addDockedWidget( UndoStack::getInstance( this ),
304 305 306 307
                                  tr( "History" ),
                                  Qt::AllDockWidgetAreas,
                                  QDockWidget::AllDockWidgetFeatures,
                                  Qt::LeftDockWidgetArea );
308 309
    if ( dock != 0 )
        dock->hide();
310
    setupLibrary();
311 312
}

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

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

347

348 349
//Private slots definition

Ludovic Fauvet's avatar
Ludovic Fauvet committed
350 351 352 353
void MainWindow::on_actionQuit_triggered()
{
    QApplication::quit();
}
354 355 356

void MainWindow::on_actionPreferences_triggered()
{
357
   m_globalPreferences->show();
358
}
Ludovic Fauvet's avatar
Ludovic Fauvet committed
359 360 361 362 363

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

365
void MainWindow::on_actionTranscode_triggered()
366
{
367 368
    QMessageBox::information( this, tr( "Sorry" ),
                              tr( "This feature is currently disabled." ) );
369
    //Transcode::instance( this )->exec();
370
}
371

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

395 396 397 398
void MainWindow::on_actionNew_Project_triggered()
{
    //TODO : clear the library, the timeline, and show the configuration box
    //of the newly created project
399

400
    m_pWizard->restart();
401
    m_pWizard->show();
402 403
}

404
void    MainWindow::on_actionHelp_triggered()
405 406
{
    QDesktopServices::openUrl( QUrl( "http://vlmc.org" ) );
407 408
}

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

414
void    MainWindow::zoomOut()
Ludovic Fauvet's avatar
Ludovic Fauvet committed
415 416 417
{
    m_zoomSlider->setValue( m_zoomSlider->value() + 1 );
}
Ludovic Fauvet's avatar
Ludovic Fauvet committed
418

419
void    MainWindow::on_actionFullscreen_triggered( bool checked )
Ludovic Fauvet's avatar
Ludovic Fauvet committed
420 421 422 423 424 425
{
    if ( checked )
        showFullScreen();
    else
        showNormal();
}
426

427
void    MainWindow::registerWidgetInWindowMenu( QDockWidget* widget )
428
{
429
    m_ui.menuWindow->addAction( widget->toggleViewAction() );
430
}
431

432
void    MainWindow::toolButtonClicked( int id )
433 434 435
{
    emit toolChanged( (ToolButtons)id );
}
436

437 438 439 440 441 442 443 444 445 446 447
void MainWindow::on_actionBypass_effects_engine_toggled(bool toggled)
{
    EffectsEngine*  ee;

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

449 450
void MainWindow::on_actionProject_Preferences_triggered()
{
451
  m_projectPreferences->show( "project" );
452
}
453

454 455
void    MainWindow::closeEvent( QCloseEvent* e )
{
456
    if ( ProjectManager::getInstance()->askForSaveIfModified() )
457
        e->accept();
458 459
    else
        e->ignore();
460
}
461

462
void    MainWindow::projectUpdated( const QString& projectName, bool savedStatus )
463 464
{
    QString title = tr( "VideoLAN Movie Creator" );
465
    title += " - ";
466 467 468 469 470
    title += projectName;
    if ( savedStatus == false )
        title += " *";
    setWindowTitle( title );
}
471

472 473 474 475 476
void    MainWindow::on_actionClose_Project_triggered()
{
    ProjectManager::getInstance()->closeProject();
}

477 478 479 480 481 482 483 484 485 486
void    MainWindow::on_actionUndo_triggered()
{
    UndoStack::getInstance( this )->undo();
}

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

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

void    MainWindow::initializeMenuKeyboardShortcut()
{
495 496 497 498 499 500 501 502
    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 );
503
    INIT_SHORTCUT( closeProject, "Close project", actionClose_Project );
504
    INIT_SHORTCUT( importProject, "Import media", actionImport );
505
    INIT_SHORTCUT( renderProject, "Render project", actionRender );
506 507
    INIT_SHORTCUT( undo, "Undo", actionUndo );
    INIT_SHORTCUT( redo, "Redo", actionRedo );
508 509
}

510 511
#undef INIT_SHORTCUT

512 513 514 515 516
void    MainWindow::keyboardShortcutChanged( const QString& name, const QString& val )
{
    qDebug() << "shortcut" << name << "changed to" << val;
    if ( name == "Help" )
        m_ui.actionHelp->setShortcut( val );
517 518 519 520 521 522 523 524 525 526 527 528 529 530
    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 );
531 532
    else if ( name == "Close project" )
        m_ui.actionClose_Project->setShortcut( val );
533 534
    else if ( name == "Import media" )
        m_ui.actionImport->setShortcut( val );
535 536
    else if ( name == "Render project" )
        m_ui.actionRender->setShortcut( val );
537 538 539 540
    else if ( name == "Undo" )
        m_ui.actionUndo->setShortcut( val );
    else if ( name == "Redo" )
        m_ui.actionRedo->setShortcut( val );
541 542
    else
        qWarning() << "Unknown shortcut:" << name;
543
}
544 545 546

void    MainWindow::on_actionCrash_triggered()
{
547 548 549 550 551
    //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 );
552
}
Hugo Beauzee-Luyssen's avatar
Hugo Beauzee-Luyssen committed
553 554 555 556

bool    MainWindow::restoreSession()
{
    QSettings   s;
557
    bool        fileCreated = false;
Hugo Beauzee-Luyssen's avatar
Hugo Beauzee-Luyssen committed
558 559
    bool        ret = false;

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

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

593 594 595 596 597 598 599 600 601 602
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
603
#ifdef WITH_CRASHBUTTON
604 605 606 607 608 609 610 611 612
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