MainWindow.cpp 19.3 KB
Newer Older
Ludovic Fauvet's avatar
Ludovic Fauvet committed
1
/*****************************************************************************
2
 * MainWindow.cpp: VLMC MainWindow
Ludovic Fauvet's avatar
Ludovic Fauvet committed
3 4 5 6
 *****************************************************************************
 * Copyright (C) 2008-2009 the VLMC team
 *
 * 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

MainWindow::MainWindow( QWidget *parent ) :
68
    QMainWindow( parent ), m_renderer( NULL )
Ludovic Fauvet's avatar
Ludovic Fauvet committed
69 70
{
    m_ui.setupUi( this );
71

72
    qRegisterMetaType<MainWorkflow::TrackType>( "MainWorkflow::TrackType" );
73
    qRegisterMetaType<MainWorkflow::FrameChangedReason>( "MainWorkflow::FrameChangedReason" );
74
    qRegisterMetaType<QVariant>( "QVariant" );
75 76 77 78

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

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

Ludovic Fauvet's avatar
Ludovic Fauvet committed
94
    // Translations
95 96
    connect( this, SIGNAL( translateDockWidgetTitle() ),
             DockWidgetManager::instance(), SLOT( transLateWidgetTitle() ) );
Ludovic Fauvet's avatar
Ludovic Fauvet committed
97 98

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

108 109
    connect( ProjectManager::getInstance(), SIGNAL( projectUpdated( const QString&, bool ) ),
             this, SLOT( projectUpdated( const QString&, bool ) ) );
110

Hugo Beauzee-Luyssen's avatar
Hugo Beauzee-Luyssen committed
111 112 113 114
    // Wizard
    m_pWizard = new ProjectWizard( this );
    m_pWizard->setModal( true );

115 116 117
    QSettings s;
    if ( s.value( "ShowWizardStartup", true ).toBool() &&
         restoreSession() == false )
Hugo Beauzee-Luyssen's avatar
Hugo Beauzee-Luyssen committed
118 119 120
    {
        m_pWizard->show();
    }
Ludovic Fauvet's avatar
Ludovic Fauvet committed
121 122
}

123 124
MainWindow::~MainWindow()
{
125 126 127 128 129
    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
130
    s.setValue( "CleanQuit", true );
131 132
    s.sync();

133 134
    if ( m_renderer )
        delete m_renderer;
135
    LibVLCpp::Instance::destroyInstance();
136 137
}

Ludovic Fauvet's avatar
Ludovic Fauvet committed
138 139 140 141 142 143
void MainWindow::changeEvent( QEvent *e )
{
    switch ( e->type() )
    {
    case QEvent::LanguageChange:
        m_ui.retranslateUi( this );
144
        emit translateDockWidgetTitle();
Ludovic Fauvet's avatar
Ludovic Fauvet committed
145 146 147 148 149 150
        break;
    default:
        break;
    }
}

Hugo Beauzee-Luyssen's avatar
Hugo Beauzee-Luyssen committed
151 152 153
void        MainWindow::setupLibrary()
{
    //GUI part :
154

155
    MediaLibraryWidget* mediaLibraryWidget = new MediaLibraryWidget( this );
156
    m_importController = new ImportController( this );
Hugo Beauzee-Luyssen's avatar
Hugo Beauzee-Luyssen committed
157

158 159 160 161
    DockWidgetManager::instance()->addDockedWidget( mediaLibraryWidget,
                                                    tr( "Media Library" ),
                                                    Qt::AllDockWidgetAreas,
                                                    QDockWidget::AllDockWidgetFeatures,
162

163
                                                    Qt::LeftDockWidgetArea );
Geoffroy Lacarriere's avatar
Geoffroy Lacarriere committed
164 165
    connect( mediaLibraryWidget, SIGNAL( mediaSelected( Media* ) ),
             m_clipPreview->getGenericRenderer(), SLOT( setMedia( Media* ) ) );
166

167 168
    connect( Library::getInstance(), SIGNAL( mediaRemoved( const QUuid& ) ),
             m_clipPreview->getGenericRenderer(), SLOT( mediaUnloaded( QUuid ) ) );
169 170

    connect( mediaLibraryWidget, SIGNAL( importRequired() ), this, SLOT( on_actionImport_triggered() ) );
171 172

    connect( m_clipPreview, SIGNAL( addClip( Clip* ) ), mediaLibraryWidget, SLOT( clipAdded( Clip* ) ) );
173 174 175

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

178 179
void    MainWindow::on_actionSave_triggered()
{
180
    ProjectManager::getInstance()->saveProject();
181 182
}

Hugo Beauzee-Luyssen's avatar
Hugo Beauzee-Luyssen committed
183 184 185 186 187
void    MainWindow::on_actionSave_As_triggered()
{
    ProjectManager::getInstance()->saveProject( true );
}

188 189
void    MainWindow::on_actionLoad_Project_triggered()
{
190 191
    ProjectManager* pm = ProjectManager::getInstance();
    pm->loadProject( pm->loadProjectFile() );
192 193
}

194 195
void MainWindow::createStatusBar()
{
196 197
    // Mouse (default) tool
    QToolButton* mouseTool = new QToolButton( this );
198
    mouseTool->setAutoRaise( true );
199 200 201 202 203 204
    mouseTool->setCheckable( true );
    mouseTool->setIcon( QIcon( ":/images/mouse" ) );
    m_ui.statusbar->addPermanentWidget( mouseTool );

    // Cut/Split tool
    QToolButton* splitTool = new QToolButton( this );
205
    splitTool->setAutoRaise( true );
206 207 208 209 210 211 212 213 214 215 216
    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 );

217 218 219 220 221 222
    //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() ) );

223 224 225 226 227 228 229 230
    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
231 232 233 234 235 236
    // Zoom Out
    QToolButton* zoomOutButton = new QToolButton( this );
    zoomOutButton->setIcon( QIcon( ":/images/zoomout" ) );
    m_ui.statusbar->addPermanentWidget( zoomOutButton );
    connect( zoomOutButton, SIGNAL( clicked() ),
             this, SLOT( zoomOut() ) );
237 238

    // Zoom slider
239 240 241 242 243 244 245 246 247
    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
248
    m_zoomSlider->setInvertedAppearance( true );
249
    m_ui.statusbar->addPermanentWidget( m_zoomSlider );
250

Ludovic Fauvet's avatar
Ludovic Fauvet committed
251 252 253 254 255 256
    // Zoom IN
    QToolButton* zoomInButton = new QToolButton( this );
    zoomInButton->setIcon( QIcon( ":/images/zoomin" ) );
    m_ui.statusbar->addPermanentWidget( zoomInButton );
    connect( zoomInButton, SIGNAL( clicked() ),
             this, SLOT( zoomIn() ) );
257 258
}

259
void MainWindow::initializeDockWidgets( void )
260
{
261
    WorkflowRenderer*    workflowRenderer = new WorkflowRenderer();
262
    workflowRenderer->initializeRenderer();
263
    m_timeline = new Timeline( workflowRenderer, this );
264 265 266
    m_timeline->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding );
    m_timeline->show();
    setCentralWidget( m_timeline );
267

268 269
    DockWidgetManager *dockManager = DockWidgetManager::instance();

270 271
    m_clipPreview = new PreviewWidget( new ClipRenderer, this );
    dockManager->addDockedWidget( m_clipPreview,
272
                                  tr( "Clip Preview" ),
geoff's avatar
geoff committed
273 274 275
                                  Qt::AllDockWidgetAreas,
                                  QDockWidget::AllDockWidgetFeatures,
                                  Qt::TopDockWidgetArea );
276
    KeyboardShortcutHelper* clipShortcut = new KeyboardShortcutHelper( "Launch media preview", this );
277
    connect( clipShortcut, SIGNAL( activated() ), m_clipPreview, SLOT( on_pushButtonPlay_clicked() ) );
278

279
    m_projectPreview = new PreviewWidget( workflowRenderer, this );
280
    dockManager->addDockedWidget( m_projectPreview,
281 282 283
                                  tr( "Project Preview" ),
                                  Qt::AllDockWidgetAreas,
                                  QDockWidget::AllDockWidgetFeatures,
284
                                  Qt::TopDockWidgetArea );
285
    KeyboardShortcutHelper* renderShortcut = new KeyboardShortcutHelper( "Start render preview", this );
286
    connect( renderShortcut, SIGNAL( activated() ), m_projectPreview, SLOT( on_pushButtonPlay_clicked() ) );
287

288
    dockManager->addDockedWidget( UndoStack::getInstance( this ),
289 290 291 292
                                  tr( "History" ),
                                  Qt::AllDockWidgetAreas,
                                  QDockWidget::AllDockWidgetFeatures,
                                  Qt::LeftDockWidgetArea );
293
    setupLibrary();
294 295
}

296 297
void        MainWindow::createGlobalPreferences()
{
298
    m_globalPreferences = new Settings( false, "VLMC", this );
299
    m_globalPreferences->addWidget("VLMC",
Ludovic Fauvet's avatar
Ludovic Fauvet committed
300
                                   new VLMCPreferences( m_globalPreferences ),
301
                                   QIcon( ":/images/images/vlmc.png" ),
302
                                   "VLMC settings");
303 304
    m_globalPreferences->addWidget("Language preferences",
                                   new LanguagePreferences( m_globalPreferences ),
305
                                   QIcon( ":/images/images/vlmc.png" ),
306
                                   "Langage settings");
307 308 309 310
    m_globalPreferences->addWidget( "Keyboard",
                                     new KeyboardShortcut( m_globalPreferences ),
                                     QIcon( ":/images/keyboard" ),
                                     tr( "Keyboard Settings" ) );
311 312
}

313 314
void	    MainWindow::createProjectPreferences()
{
315
    m_projectPreferences = new Settings( false, "project", this );
316 317
    m_projectPreferences->addWidget("Project",
                                   new ProjectPreferences,
318
                                   QIcon( ":/images/images/vlmc.png" ),
319 320
                                   "Project settings" );
    m_projectPreferences->addWidget( "Video",
321
                                   new VideoProjectPreferences,
322
                                   QIcon( ":/images/images/video.png" ),
323 324
                                   "Video settings" );
    m_projectPreferences->addWidget( "Audio",
325
                                   new AudioProjectPreferences,
326
                                   QIcon( ":/images/images/audio.png" ),
327
                                   "Audio settings" );
328 329
}

330

331 332
//Private slots definition

Ludovic Fauvet's avatar
Ludovic Fauvet committed
333 334 335 336
void MainWindow::on_actionQuit_triggered()
{
    QApplication::quit();
}
337 338 339

void MainWindow::on_actionPreferences_triggered()
{
340
   m_globalPreferences->show();
341
}
Ludovic Fauvet's avatar
Ludovic Fauvet committed
342 343 344 345 346

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

348
void MainWindow::on_actionTranscode_triggered()
349
{
350 351
    QMessageBox::information( this, tr( "Sorry" ),
                              tr( "This feature is currently disabled." ) );
352
    //Transcode::instance( this )->exec();
353
}
354

355 356
void    MainWindow::on_actionRender_triggered()
{
357
    if ( MainWorkflow::getInstance()->getLengthFrame() <= 0 )
358 359 360 361 362 363
    {
        QMessageBox::warning( NULL, "VLMC Renderer", "There is nothing to render." );
        return ;
    }
    QString outputFileName =
            QFileDialog::getSaveFileName( NULL, "Enter the output file name",
364
                                          QDir::currentPath(), "Videos(*.avi *.mpg)" );
365 366 367 368 369 370
    if ( outputFileName.length() == 0 )
        return ;
    else
    {
        if ( m_renderer )
            delete m_renderer;
371
        m_renderer = new WorkflowFileRenderer( outputFileName );
372
        m_renderer->initializeRenderer();
373 374 375 376
        m_renderer->run();
    }
}

377 378 379 380
void MainWindow::on_actionNew_Project_triggered()
{
    //TODO : clear the library, the timeline, and show the configuration box
    //of the newly created project
381

382
    m_pWizard->restart();
383
    m_pWizard->show();
384 385
}

386
void    MainWindow::on_actionHelp_triggered()
387 388
{
    QDesktopServices::openUrl( QUrl( "http://vlmc.org" ) );
389 390
}

391
void    MainWindow::zoomIn()
Ludovic Fauvet's avatar
Ludovic Fauvet committed
392 393 394 395
{
    m_zoomSlider->setValue( m_zoomSlider->value() - 1 );
}

396
void    MainWindow::zoomOut()
Ludovic Fauvet's avatar
Ludovic Fauvet committed
397 398 399
{
    m_zoomSlider->setValue( m_zoomSlider->value() + 1 );
}
Ludovic Fauvet's avatar
Ludovic Fauvet committed
400

401
void    MainWindow::on_actionFullscreen_triggered( bool checked )
Ludovic Fauvet's avatar
Ludovic Fauvet committed
402 403 404 405 406 407
{
    if ( checked )
        showFullScreen();
    else
        showNormal();
}
408

409
void    MainWindow::registerWidgetInWindowMenu( QDockWidget* widget )
410
{
411
    m_ui.menuWindow->addAction( widget->toggleViewAction() );
412
}
413

414
void    MainWindow::toolButtonClicked( int id )
415 416 417
{
    emit toolChanged( (ToolButtons)id );
}
418

419 420 421 422 423 424 425 426 427 428 429
void MainWindow::on_actionBypass_effects_engine_toggled(bool toggled)
{
    EffectsEngine*  ee;

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

431 432
void MainWindow::on_actionProject_Preferences_triggered()
{
433
  m_projectPreferences->show( "project" );
434
}
435

436 437
void    MainWindow::closeEvent( QCloseEvent* e )
{
438
    if ( ProjectManager::getInstance()->askForSaveIfModified() )
439
        e->accept();
440 441
    else
        e->ignore();
442
}
443

444
void    MainWindow::projectUpdated( const QString& projectName, bool savedStatus )
445 446
{
    QString title = tr( "VideoLAN Movie Creator" );
447
    title += " - ";
448 449 450 451 452
    title += projectName;
    if ( savedStatus == false )
        title += " *";
    setWindowTitle( title );
}
453

454 455 456 457 458
void    MainWindow::on_actionClose_Project_triggered()
{
    ProjectManager::getInstance()->closeProject();
}

459
#define INIT_SHORTCUT( instName, shortcutName, actionInstance )      \
460 461
            const SettingValue* instName = SettingsManager::getInstance()->getValue( "keyboard_shortcut", shortcutName );\
            KeyboardShortcutHelper* helper##instName = new KeyboardShortcutHelper( shortcutName, this, true ); \
462 463
            connect( helper##instName, SIGNAL( changed( const QString&, const QString&) ), this, SLOT( keyboardShortcutChanged(QString,QString)) ); \
            m_ui.actionInstance->setShortcut( instName->get().toString() );
464 465 466

void    MainWindow::initializeMenuKeyboardShortcut()
{
467 468 469 470 471 472 473 474
    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 );
475
    INIT_SHORTCUT( closeProject, "Close project", actionClose_Project );
476
    INIT_SHORTCUT( importProject, "Import media", actionImport );
477 478
}

479 480
#undef INIT_SHORTCUT

481 482 483 484 485
void    MainWindow::keyboardShortcutChanged( const QString& name, const QString& val )
{
    qDebug() << "shortcut" << name << "changed to" << val;
    if ( name == "Help" )
        m_ui.actionHelp->setShortcut( val );
486 487 488 489 490 491 492 493 494 495 496 497 498 499
    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 );
500 501
    else if ( name == "Close project" )
        m_ui.actionClose_Project->setShortcut( val );
502 503
    else if ( name == "Import media" )
        m_ui.actionImport->setShortcut( val );
504 505
    else
        qWarning() << "Unknown shortcut:" << name;
506
}
Hugo Beauzee-Luyssen's avatar
Hugo Beauzee-Luyssen committed
507 508 509

void    MainWindow::on_actionCrash_triggered()
{
510 511 512 513 514
    //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
515
}
Hugo Beauzee-Luyssen's avatar
Hugo Beauzee-Luyssen committed
516 517 518 519

bool    MainWindow::restoreSession()
{
    QSettings   s;
520
    bool        fileCreated = false;
Hugo Beauzee-Luyssen's avatar
Hugo Beauzee-Luyssen committed
521 522
    bool        ret = false;

523 524
    fileCreated = s.contains( "VlmcVersion" );
    if ( fileCreated == true )
Hugo Beauzee-Luyssen's avatar
Hugo Beauzee-Luyssen committed
525
    {
526 527 528 529 530 531 532 533
        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
534
        {
535 536 537 538 539 540 541 542 543
            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
544 545 546 547 548 549
        }
    }
    s.setValue( "CleanQuit", false );
    s.sync();
    return ret;
}
550 551 552 553 554

void    MainWindow::on_actionImport_triggered()
{
    m_importController->exec();
}
555 556 557 558 559 560 561 562 563 564 565

#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