MainWindow.cpp 20.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
39
#include "ProjectManager.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
58
#include "ProjectWizard.h"
#include "Settings.h"
59
#include "SettingsManager.h"
Ludovic Fauvet's avatar
Ludovic Fauvet committed
60

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

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

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

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

76
77
78
    //VLC Instance:
    LibVLCpp::Instance::getInstance( this );

79
80
81
82
83
84
    //Preferences
    initVlmcPreferences();

    //Creating the project manager first (so it can create all the project variables)
    ProjectManager::getInstance();

85
    // GUI
86
    DockWidgetManager::instance( this )->setMainWindow( this );
87
    createGlobalPreferences();
88
    createProjectPreferences();
89
90
    initializeDockWidgets();
    createStatusBar();
91
    initializeMenuKeyboardShortcut();
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
98
    connect( this, SIGNAL( translateDockWidgetTitle() ),
             DockWidgetManager::instance(), 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
111
    connect( ProjectManager::getInstance(), SIGNAL( projectUpdated( const QString&, bool ) ),
             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
#ifdef WITH_CRASHHANDLER
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();
    }
133
134
135
#else
    m_pWizard->show();
#endif
Ludovic Fauvet's avatar
Ludovic Fauvet committed
136
137
}

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

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

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

166
167
168
void
MainWindow::initVlmcPreferences()
{
169
170
171
172
    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" );
173
    //A bit nasty, but we better use what Qt's providing as default shortcut
174
175
176
177
178
179
180
181
182
183
184
185
186
187
    VLMC_CREATE_PREFERENCE_KEYBOARD( "keyboard/undo", QKeySequence( QKeySequence::Undo ).toString().toLocal8Bit(), "Undo", "Undo the last action" );
    VLMC_CREATE_PREFERENCE_KEYBOARD( "keyboard/redo", QKeySequence( QKeySequence::Redo ).toString().toLocal8Bit(), "Redo", "Redo the last action" );
    VLMC_CREATE_PREFERENCE_KEYBOARD( "keyboard/help", QKeySequence( QKeySequence::HelpContents ).toString().toLocal8Bit(), "Help", "Toggle the help page" );
    VLMC_CREATE_PREFERENCE_KEYBOARD( "keyboard/quit", "Ctrl+Q", "Quit", "Quit VLMC" );
    VLMC_CREATE_PREFERENCE_KEYBOARD( "keyboard/preferences", "Alt+P", "Preferences", "Open VLMC preferences" );
    VLMC_CREATE_PREFERENCE_KEYBOARD( "keyboard/fullscreen", "F", "Fullscreen", "Switch to fullscreen mode" );
    VLMC_CREATE_PREFERENCE_KEYBOARD( "keyboard/newproject", QKeySequence( QKeySequence::New ).toString().toLocal8Bit(), "New project", "Open the new project wizzard" );
    VLMC_CREATE_PREFERENCE_KEYBOARD( "keyboard/openproject", QKeySequence( QKeySequence::Open ).toString().toLocal8Bit(), "Open a project", "Open an existing project" );
    VLMC_CREATE_PREFERENCE_KEYBOARD( "keyboard/save", QKeySequence( QKeySequence::Save ).toString().toLocal8Bit(), "Save", "Save the current project" );
    VLMC_CREATE_PREFERENCE_KEYBOARD( "keyboard/saveas", "Ctrl+Shift+S", "Save as", "Save the current project to a new file" );
    VLMC_CREATE_PREFERENCE_KEYBOARD( "keyboard/closeproject", QKeySequence( QKeySequence::Close ).toString().toLocal8Bit(), "Close the project", "Close the current project" );
    VLMC_CREATE_PREFERENCE_KEYBOARD( "keyboard/importmedia", "Ctrl+I", "Import media", "Open the import window" );
    VLMC_CREATE_PREFERENCE_KEYBOARD( "keyboard/renderproject", "Ctrl+R", "Render the project", "Render the project to a file" );

188
    VLMC_CREATE_PREFERENCE_LANGUAGE( "general/VLMCLang", "en_US", "Langage", "The VLMC's UI language" );
189
190
}

Hugo Beauzee-Luyssen's avatar
Hugo Beauzee-Luyssen committed
191
192
193
void        MainWindow::setupLibrary()
{
    //GUI part :
194

195
    MediaLibraryWidget* mediaLibraryWidget = new MediaLibraryWidget( this );
196
    m_importController = new ImportController();
Hugo Beauzee-Luyssen's avatar
Hugo Beauzee-Luyssen committed
197

198
199
200
201
202
    DockWidgetManager::instance()->addDockedWidget( mediaLibraryWidget,
                                                    tr( "Media Library" ),
                                                    Qt::AllDockWidgetAreas,
                                                    QDockWidget::AllDockWidgetFeatures,
                                                    Qt::LeftDockWidgetArea );
Geoffroy Lacarriere's avatar
Geoffroy Lacarriere committed
203
204
    connect( mediaLibraryWidget, SIGNAL( mediaSelected( Media* ) ),
             m_clipPreview->getGenericRenderer(), SLOT( setMedia( Media* ) ) );
205

206
207
    connect( Library::getInstance(), SIGNAL( mediaRemoved( const QUuid& ) ),
             m_clipPreview->getGenericRenderer(), SLOT( mediaUnloaded( QUuid ) ) );
208
209

    connect( mediaLibraryWidget, SIGNAL( importRequired() ), this, SLOT( on_actionImport_triggered() ) );
210
211

    connect( m_clipPreview, SIGNAL( addClip( Clip* ) ), mediaLibraryWidget, SLOT( clipAdded( Clip* ) ) );
212
213
214

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

217
218
void    MainWindow::on_actionSave_triggered()
{
219
    ProjectManager::getInstance()->saveProject();
220
221
}

Hugo Beauzee-Luyssen's avatar
Hugo Beauzee-Luyssen committed
222
223
224
225
226
void    MainWindow::on_actionSave_As_triggered()
{
    ProjectManager::getInstance()->saveProject( true );
}

227
228
void    MainWindow::on_actionLoad_Project_triggered()
{
229
    ProjectManager* pm = ProjectManager::getInstance();
230
    pm->loadProject( pm->acquireProjectFileName() );
231
232
}

233
234
void MainWindow::createStatusBar()
{
235
236
    // Mouse (default) tool
    QToolButton* mouseTool = new QToolButton( this );
237
    mouseTool->setAutoRaise( true );
238
239
240
241
242
243
    mouseTool->setCheckable( true );
    mouseTool->setIcon( QIcon( ":/images/mouse" ) );
    m_ui.statusbar->addPermanentWidget( mouseTool );

    // Cut/Split tool
    QToolButton* splitTool = new QToolButton( this );
244
    splitTool->setAutoRaise( true );
245
246
247
248
249
250
251
252
253
254
255
    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 );

256
    //Shortcut part:
257
258
    KeyboardShortcutHelper* defaultModeShortcut = new KeyboardShortcutHelper( "keyboard/defaultmode", this );
    KeyboardShortcutHelper* cutModeShortcut = new KeyboardShortcutHelper( "keyboard/cutmode", this );
259
260
261
    connect( defaultModeShortcut, SIGNAL( activated() ), mouseTool, SLOT( click() ) );
    connect( cutModeShortcut, SIGNAL( activated() ), splitTool, SLOT( click() ) );

262
263
264
265
266
267
268
269
    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
270
271
272
273
274
275
    // Zoom Out
    QToolButton* zoomOutButton = new QToolButton( this );
    zoomOutButton->setIcon( QIcon( ":/images/zoomout" ) );
    m_ui.statusbar->addPermanentWidget( zoomOutButton );
    connect( zoomOutButton, SIGNAL( clicked() ),
             this, SLOT( zoomOut() ) );
276
277

    // Zoom slider
278
279
280
281
282
283
284
285
286
    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
287
    m_zoomSlider->setInvertedAppearance( true );
288
    m_ui.statusbar->addPermanentWidget( m_zoomSlider );
289

Ludovic Fauvet's avatar
Ludovic Fauvet committed
290
291
292
293
294
295
    // Zoom IN
    QToolButton* zoomInButton = new QToolButton( this );
    zoomInButton->setIcon( QIcon( ":/images/zoomin" ) );
    m_ui.statusbar->addPermanentWidget( zoomInButton );
    connect( zoomInButton, SIGNAL( clicked() ),
             this, SLOT( zoomIn() ) );
296
297
}

298
void MainWindow::initializeDockWidgets( void )
299
{
300
301
302
    m_renderer = new WorkflowRenderer();
    m_renderer->initializeRenderer();
    m_timeline = new Timeline( m_renderer, this );
303
304
305
    m_timeline->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding );
    m_timeline->show();
    setCentralWidget( m_timeline );
306

307
308
    DockWidgetManager *dockManager = DockWidgetManager::instance();

309
310
    m_clipPreview = new PreviewWidget( new ClipRenderer, this );
    dockManager->addDockedWidget( m_clipPreview,
311
                                  tr( "Clip Preview" ),
geoff's avatar
geoff committed
312
313
314
                                  Qt::AllDockWidgetAreas,
                                  QDockWidget::AllDockWidgetFeatures,
                                  Qt::TopDockWidgetArea );
315
    KeyboardShortcutHelper* clipShortcut = new KeyboardShortcutHelper( "keyboard/mediapreview", this );
316
    connect( clipShortcut, SIGNAL( activated() ), m_clipPreview, SLOT( on_pushButtonPlay_clicked() ) );
317

318
    m_projectPreview = new PreviewWidget( m_renderer, this );
319
    dockManager->addDockedWidget( m_projectPreview,
320
321
322
                                  tr( "Project Preview" ),
                                  Qt::AllDockWidgetAreas,
                                  QDockWidget::AllDockWidgetFeatures,
323
                                  Qt::TopDockWidgetArea );
324
    KeyboardShortcutHelper* renderShortcut = new KeyboardShortcutHelper( "keyboard/renderpreview", this );
325
    connect( renderShortcut, SIGNAL( activated() ), m_projectPreview, SLOT( on_pushButtonPlay_clicked() ) );
326

327
    QDockWidget* dock = dockManager->addDockedWidget( UndoStack::getInstance( this ),
328
329
330
331
                                  tr( "History" ),
                                  Qt::AllDockWidgetAreas,
                                  QDockWidget::AllDockWidgetFeatures,
                                  Qt::LeftDockWidgetArea );
332
333
    if ( dock != 0 )
        dock->hide();
334
    setupLibrary();
335
336
}

337
338
void        MainWindow::createGlobalPreferences()
{
339
    m_globalPreferences = new Settings( this );
340
341
342
343
344
345
    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" ) );
346
347
}

348
void    MainWindow::createProjectPreferences()
349
{
350
    m_projectPreferences = new Settings( this );
351
352
353
354
355
356
357
358
359
    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" ) );
360
361
}

362

363
364
//Private slots definition

Ludovic Fauvet's avatar
Ludovic Fauvet committed
365
366
367
368
void MainWindow::on_actionQuit_triggered()
{
    QApplication::quit();
}
369
370
371

void MainWindow::on_actionPreferences_triggered()
{
372
   m_globalPreferences->show();
373
}
Ludovic Fauvet's avatar
Ludovic Fauvet committed
374
375
376
377
378

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

380
void MainWindow::on_actionTranscode_triggered()
381
{
382
383
    QMessageBox::information( this, tr( "Sorry" ),
                              tr( "This feature is currently disabled." ) );
384
    //Transcode::instance( this )->exec();
385
}
386

387
388
void    MainWindow::on_actionRender_triggered()
{
389
    if ( MainWorkflow::getInstance()->getLengthFrame() <= 0 )
390
    {
391
        QMessageBox::warning( NULL, tr ( "VLMC Renderer" ), tr( "There is nothing to render." ) );
392
393
        return ;
    }
394
395
    else
    {
396
        m_renderer->killRenderer();
397
398
        if ( m_fileRenderer )
            delete m_fileRenderer;
Hugo Beauzee-Luyssen's avatar
Hugo Beauzee-Luyssen committed
399
        m_fileRenderer = new WorkflowFileRenderer();
400
401
        m_fileRenderer->initializeRenderer();
        m_fileRenderer->run();
402
    }
403
404
}

405
406
407
408
void MainWindow::on_actionNew_Project_triggered()
{
    //TODO : clear the library, the timeline, and show the configuration box
    //of the newly created project
409

410
    m_pWizard->restart();
411
    m_pWizard->show();
412
413
}

414
void    MainWindow::on_actionHelp_triggered()
415
416
{
    QDesktopServices::openUrl( QUrl( "http://vlmc.org" ) );
417
418
}

419
void    MainWindow::zoomIn()
Ludovic Fauvet's avatar
Ludovic Fauvet committed
420
421
422
423
{
    m_zoomSlider->setValue( m_zoomSlider->value() - 1 );
}

424
void    MainWindow::zoomOut()
Ludovic Fauvet's avatar
Ludovic Fauvet committed
425
426
427
{
    m_zoomSlider->setValue( m_zoomSlider->value() + 1 );
}
Ludovic Fauvet's avatar
Ludovic Fauvet committed
428

429
void    MainWindow::on_actionFullscreen_triggered( bool checked )
Ludovic Fauvet's avatar
Ludovic Fauvet committed
430
431
432
433
434
435
{
    if ( checked )
        showFullScreen();
    else
        showNormal();
}
436

437
void    MainWindow::registerWidgetInWindowMenu( QDockWidget* widget )
438
{
439
    m_ui.menuWindow->addAction( widget->toggleViewAction() );
440
}
441

442
void    MainWindow::toolButtonClicked( int id )
443
444
445
{
    emit toolChanged( (ToolButtons)id );
}
446

447
448
449
450
451
452
453
454
455
456
457
void MainWindow::on_actionBypass_effects_engine_toggled(bool toggled)
{
    EffectsEngine*  ee;

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

459
460
void MainWindow::on_actionProject_Preferences_triggered()
{
461
  m_projectPreferences->show();
462
}
463

464
465
void    MainWindow::closeEvent( QCloseEvent* e )
{
466
    if ( ProjectManager::getInstance()->askForSaveIfModified() )
467
        e->accept();
468
469
    else
        e->ignore();
470
}
471

472
void    MainWindow::projectUpdated( const QString& projectName, bool savedStatus )
473
474
{
    QString title = tr( "VideoLAN Movie Creator" );
475
    title += " - ";
476
477
478
479
480
    title += projectName;
    if ( savedStatus == false )
        title += " *";
    setWindowTitle( title );
}
481

482
483
484
485
486
void    MainWindow::on_actionClose_Project_triggered()
{
    ProjectManager::getInstance()->closeProject();
}

487
488
489
490
491
492
493
494
495
496
void    MainWindow::on_actionUndo_triggered()
{
    UndoStack::getInstance( this )->undo();
}

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

497
#define INIT_SHORTCUT( instName, shortcutName, actionInstance  )      \
498
            QString instName = VLMC_GET_STRING( shortcutName ); \
499
            KeyboardShortcutHelper* helper##instName = new KeyboardShortcutHelper( shortcutName, m_ui.actionInstance, this ); \
500
            m_ui.actionInstance->setShortcut( instName );
501
502
503

void    MainWindow::initializeMenuKeyboardShortcut()
{
504
505
506
507
508
509
510
511
512
513
514
515
516
    INIT_SHORTCUT( help, "keyboard/help", actionHelp );
    INIT_SHORTCUT( quit, "keyboard/quit", actionQuit );
    INIT_SHORTCUT( preferences, "keyboard/preferences", actionPreferences );
    INIT_SHORTCUT( fullscreen, "keyboard/fullscreen", actionFullscreen );
    INIT_SHORTCUT( newProject, "keyboard/newproject", actionNew_Project );
    INIT_SHORTCUT( openProject, "keyboard/openproject", actionLoad_Project );
    INIT_SHORTCUT( save, "keyboard/save", actionSave );
    INIT_SHORTCUT( saveAs, "keyboard/saveas", actionSave_As );
    INIT_SHORTCUT( closeProject, "keyboard/closeproject", actionClose_Project );
    INIT_SHORTCUT( importProject, "keyboard/importmedia", actionImport );
    INIT_SHORTCUT( renderProject, "keyboard/renderproject", actionRender );
    INIT_SHORTCUT( undo, "keyboard/undo", actionUndo );
    INIT_SHORTCUT( redo, "keyboard/redo", actionRedo );
517
518
}

519
520
#undef INIT_SHORTCUT

Hugo Beauzee-Luyssen's avatar
Hugo Beauzee-Luyssen committed
521
522
void    MainWindow::on_actionCrash_triggered()
{
523
524
525
526
527
    //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
528
}
Hugo Beauzee-Luyssen's avatar
Hugo Beauzee-Luyssen committed
529
530
531
532

bool    MainWindow::restoreSession()
{
    QSettings   s;
533
    bool        fileCreated = false;
Hugo Beauzee-Luyssen's avatar
Hugo Beauzee-Luyssen committed
534
535
    bool        ret = false;

536
537
    fileCreated = s.contains( "VlmcVersion" );
    if ( fileCreated == true )
Hugo Beauzee-Luyssen's avatar
Hugo Beauzee-Luyssen committed
538
    {
539
540
541
542
543
544
545
546
        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
547
        {
548
549
550
551
552
553
554
555
556
            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
557
558
559
560
561
562
        }
    }
    s.setValue( "CleanQuit", false );
    s.sync();
    return ret;
}
563
564
565
566
567

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

569
570
571
572
573
574
575
576
577
578
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
579
#ifdef WITH_CRASHBUTTON
580
581
582
583
584
585
586
587
588
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