MainWindow.cpp 25.1 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 Beauzée-Luyssen <beauze.h@gmail.com>
Ludovic Fauvet's avatar
Ludovic Fauvet committed
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
 *****************************************************************************/

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

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

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

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

/* Settings / Preferences */
55
#include "project/GuiProjectManager.h"
Ludovic Fauvet's avatar
Ludovic Fauvet committed
56 57
#include "ProjectWizard.h"
#include "Settings.h"
58
#include "SettingsManager.h"
59
#include "LanguageHelper.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
    //VLC Instance:
77
    LibVLCpp::Instance::getInstance();
78

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

82 83 84
    //Preferences
    initVlmcPreferences();

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

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

105
    connect( GUIProjectManager::getInstance(), SIGNAL( projectUpdated( const QString&, bool ) ),
106
             this, SLOT( projectUpdated( const QString&, bool ) ) );
107

108 109 110 111 112 113 114 115 116
    // 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
117 118 119 120
    // Wizard
    m_pWizard = new ProjectWizard( this );
    m_pWizard->setModal( true );

121

122
#ifdef WITH_CRASHHANDLER
123
    if ( restoreSession() == true )
124 125
        return ;
#endif
126
    QSettings s;
127

128
    if ( s.value( "ShowWizardStartup", true ).toBool() )
Hugo Beauzee-Luyssen's avatar
Hugo Beauzee-Luyssen committed
129
    {
130
        //If a project was opened from the command line: don't show the wizard.
131 132
        if ( qApp->arguments().size() == 1 )
            m_pWizard->show();
Hugo Beauzee-Luyssen's avatar
Hugo Beauzee-Luyssen committed
133
    }
Ludovic Fauvet's avatar
Ludovic Fauvet committed
134 135
}

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

146 147
    if ( m_fileRenderer )
        delete m_fileRenderer;
148
    delete m_importController;
149
    LibVLCpp::Instance::destroyInstance();
150 151
}

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

Hugo Beauzee-Luyssen's avatar
Hugo Beauzee-Luyssen committed
165
//use this helper when the shortcut is binded to a menu action
166 167 168
#define CREATE_MENU_SHORTCUT( key, defaultValue, name, desc, actionInstance  )      \
        VLMC_CREATE_PREFERENCE_KEYBOARD( key, defaultValue, name, desc );           \
        new KeyboardShortcutHelper( key, m_ui.actionInstance, this );
Hugo Beauzee-Luyssen's avatar
Hugo Beauzee-Luyssen committed
169

170 171 172
void
MainWindow::initVlmcPreferences()
{
Hugo Beauzee-Luyssen's avatar
Hugo Beauzee-Luyssen committed
173

174 175 176 177 178 179 180 181 182 183 184 185
    VLMC_CREATE_PREFERENCE_KEYBOARD( "keyboard/defaultmode", "n",
                                     QT_TRANSLATE_NOOP( "PreferenceWidget", "Select mode" ),
                                     QT_TRANSLATE_NOOP( "PreferenceWidget", "Select the selection tool in the timeline" ) );
    VLMC_CREATE_PREFERENCE_KEYBOARD( "keyboard/cutmode", "x",
                                     QT_TRANSLATE_NOOP( "PreferenceWidget", "Cut mode" ),
                                     QT_TRANSLATE_NOOP( "PreferenceWidget", "Select the cut/razor tool in the timeline" ) );
    VLMC_CREATE_PREFERENCE_KEYBOARD( "keyboard/mediapreview", "Ctrl+Return",
                                     QT_TRANSLATE_NOOP( "PreferenceWidget", "Media preview" ),
                                     QT_TRANSLATE_NOOP( "PreferenceWidget", "Preview the selected media, or pause the current preview" ) );
    VLMC_CREATE_PREFERENCE_KEYBOARD( "keyboard/renderpreview", "Space",
                                     QT_TRANSLATE_NOOP( "PreferenceWidget", "Render preview" ),
                                     QT_TRANSLATE_NOOP( "PreferenceWidget", "Preview the project, or pause the current preview" ) );
186
    //A bit nasty, but we better use what Qt's providing as default shortcut
187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210
    CREATE_MENU_SHORTCUT( "keyboard/undo",
                          QKeySequence( QKeySequence::Undo ).toString().toLocal8Bit(),
                          QT_TRANSLATE_NOOP( "PreferenceWidget", "Undo" ),
                          QT_TRANSLATE_NOOP( "PreferenceWidget", "Undo the last action" ), actionUndo );
    CREATE_MENU_SHORTCUT( "keyboard/redo",
                          QKeySequence( QKeySequence::Redo ).toString().toLocal8Bit(),
                          QT_TRANSLATE_NOOP( "PreferenceWidget", "Redo" ),
                          QT_TRANSLATE_NOOP( "PreferenceWidget", "Redo the last action" ), actionRedo );
    CREATE_MENU_SHORTCUT( "keyboard/help",
                          QKeySequence( QKeySequence::HelpContents ).toString().toLocal8Bit(),
                          QT_TRANSLATE_NOOP( "PreferenceWidget", "Help" ),
                          QT_TRANSLATE_NOOP( "PreferenceWidget", "Toggle the help page" ), actionHelp );
    CREATE_MENU_SHORTCUT( "keyboard/quit", "Ctrl+Q",
                          QT_TRANSLATE_NOOP( "PreferenceWidget", "Quit" ),
                          QT_TRANSLATE_NOOP( "PreferenceWidget", "Quit VLMC" ), actionQuit );
    CREATE_MENU_SHORTCUT( "keyboard/preferences", "Alt+P",
                          QT_TRANSLATE_NOOP( "PreferenceWidget", "Preferences" ),
                          QT_TRANSLATE_NOOP( "PreferenceWidget", "Open VLMC preferences" ), actionPreferences );
    CREATE_MENU_SHORTCUT( "keyboard/fullscreen", "F",
                          QT_TRANSLATE_NOOP( "PreferenceWidget", "Fullscreen" ),
                          QT_TRANSLATE_NOOP( "PreferenceWidget", "Switch to fullscreen mode" ), actionFullscreen );
    CREATE_MENU_SHORTCUT( "keyboard/newproject",
                          QKeySequence( QKeySequence::New ).toString().toLocal8Bit(),
                          QT_TRANSLATE_NOOP( "PreferenceWidget", "New project" ),
211
                          QT_TRANSLATE_NOOP( "PreferenceWidget", "Open the new project wizard" ), actionNew_Project );
212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234
    CREATE_MENU_SHORTCUT( "keyboard/openproject",
                          QKeySequence( QKeySequence::Open ).toString().toLocal8Bit(),
                          QT_TRANSLATE_NOOP( "PreferenceWidget", "Open a project" ),
                          QT_TRANSLATE_NOOP( "PreferenceWidget", "Open an existing project" ), actionLoad_Project );
    CREATE_MENU_SHORTCUT( "keyboard/save",
                          QKeySequence( QKeySequence::Save ).toString().toLocal8Bit(),
                          QT_TRANSLATE_NOOP( "PreferenceWidget", "Save" ),
                          QT_TRANSLATE_NOOP( "PreferenceWidget", "Save the current project" ), actionSave );
    CREATE_MENU_SHORTCUT( "keyboard/saveas", "Ctrl+Shift+S",
                          QT_TRANSLATE_NOOP( "PreferenceWidget", "Save as" ),
                          QT_TRANSLATE_NOOP( "PreferenceWidget", "Save the current project to a new file" ), actionSave_As );
    CREATE_MENU_SHORTCUT( "keyboard/closeproject",
                          QKeySequence( QKeySequence::Close ).toString().toLocal8Bit(),
                          QT_TRANSLATE_NOOP( "PreferenceWidget", "Close the project" ),
                          QT_TRANSLATE_NOOP( "PreferenceWidget", "Close the current project" ), actionClose_Project );
    CREATE_MENU_SHORTCUT( "keyboard/importmedia", "Ctrl+I",
                          QT_TRANSLATE_NOOP( "PreferenceWidget", "Import media" ),
                          QT_TRANSLATE_NOOP( "PreferenceWidget", "Open the import window" ), actionImport );
    CREATE_MENU_SHORTCUT( "keyboard/renderproject", "Ctrl+R",
                          QT_TRANSLATE_NOOP( "PreferenceWidget", "Render the project" ),
                          QT_TRANSLATE_NOOP( "PreferenceWidget", "Render the project to a file" ), actionRender );

    VLMC_CREATE_PREFERENCE_LANGUAGE( "general/VLMCLang", "default",
235
                                     QT_TRANSLATE_NOOP( "PreferenceWidget", "Language" ),
236
                                     QT_TRANSLATE_NOOP( "PreferenceWidget", "The VLMC's UI language" ) );
237 238 239 240
    SettingsManager::getInstance()->watchValue( "general/VLMCLang",
                                                LanguageHelper::getInstance(),
                                                SLOT( languageChanged( const QVariant& ) ),
                                                SettingsManager::Vlmc );
241
    VLMC_CREATE_PREFERENCE_BOOL( "general/ConfirmDeletion", true,
242
                                 QT_TRANSLATE_NOOP( "PreferenceWidget", "Confirm clip deletion"),
243
                                 QT_TRANSLATE_NOOP( "PreferenceWidget", "Ask for confirmation before deleting a clip from the timeline" ) );
244 245

    //Load saved preferences :
246 247 248 249 250 251 252 253 254
    QSettings       s;
    if ( s.value( "VlmcVersion" ).toString() != PROJECT_VERSION )
        s.clear();
    else
    {
        loadVlmcPreferences( "keyboard" );
        loadVlmcPreferences( "general" );
    }
    s.setValue( "VlmcVersion", PROJECT_VERSION );
255 256 257 258 259 260 261 262 263 264 265 266
}

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

Hugo Beauzee-Luyssen's avatar
Hugo Beauzee-Luyssen committed
269 270
#undef CREATE_MENU_SHORTCUT

271 272
void
MainWindow::setupLibrary()
Hugo Beauzee-Luyssen's avatar
Hugo Beauzee-Luyssen committed
273
{
274
    m_importController = new ImportController();
Hugo Beauzee-Luyssen's avatar
Hugo Beauzee-Luyssen committed
275 276
    const ClipRenderer* clipRenderer = qobject_cast<const ClipRenderer*>( m_clipPreview->getGenericRenderer() );
    Q_ASSERT( clipRenderer != NULL );
Hugo Beauzee-Luyssen's avatar
Hugo Beauzee-Luyssen committed
277

278 279 280
    MediaLibrary    *mediaLibrary = new MediaLibrary();

    DockWidgetManager::getInstance()->addDockedWidget( mediaLibrary, QT_TRANSLATE_NOOP( "DockWidgetManager", "Media Library" ),
281 282 283
                                                    Qt::AllDockWidgetAreas,
                                                    QDockWidget::AllDockWidgetFeatures,
                                                    Qt::LeftDockWidgetArea );
284
    connect( mediaLibrary, SIGNAL( clipSelected( Clip* ) ),
Hugo Beauzee-Luyssen's avatar
Hugo Beauzee-Luyssen committed
285
             clipRenderer, SLOT( setClip( Clip* ) ) );
286 287
    connect( mediaLibrary, SIGNAL( importRequired() ),
             this, SLOT( on_actionImport_triggered() ) );
288 289
    connect( Library::getInstance(), SIGNAL( clipRemoved( const QUuid& ) ),
             clipRenderer, SLOT( clipUnloaded( const QUuid& ) ) );
Hugo Beauzee-Luyssen's avatar
Hugo Beauzee-Luyssen committed
290 291
}

292 293
void    MainWindow::on_actionSave_triggered()
{
294
    GUIProjectManager::getInstance()->saveProject();
295 296
}

Hugo Beauzee-Luyssen's avatar
Hugo Beauzee-Luyssen committed
297 298
void    MainWindow::on_actionSave_As_triggered()
{
299
    GUIProjectManager::getInstance()->saveProject( true );
Hugo Beauzee-Luyssen's avatar
Hugo Beauzee-Luyssen committed
300 301
}

302 303
void    MainWindow::on_actionLoad_Project_triggered()
{
304
    GUIProjectManager::getInstance()->loadProject();
305 306
}

307 308
void MainWindow::createStatusBar()
{
309 310
    // Mouse (default) tool
    QToolButton* mouseTool = new QToolButton( this );
311
    mouseTool->setAutoRaise( true );
312 313
    mouseTool->setCheckable( true );
    mouseTool->setIcon( QIcon( ":/images/mouse" ) );
Ludovic Fauvet's avatar
Ludovic Fauvet committed
314
    mouseTool->setStatusTip( tr( "Use the mouse tool to manipulate regions in the timeline" ) );
315 316 317 318
    m_ui.statusbar->addPermanentWidget( mouseTool );

    // Cut/Split tool
    QToolButton* splitTool = new QToolButton( this );
319
    splitTool->setAutoRaise( true );
320 321
    splitTool->setCheckable( true );
    splitTool->setIcon( QIcon( ":/images/editcut" ) );
Ludovic Fauvet's avatar
Ludovic Fauvet committed
322
    splitTool->setStatusTip( tr( "Use the scissors to cut regions in the timeline" ) );
323 324 325 326 327 328 329 330 331
    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 );

332
    //Shortcut part:
333 334
    KeyboardShortcutHelper* defaultModeShortcut = new KeyboardShortcutHelper( "keyboard/defaultmode", this );
    KeyboardShortcutHelper* cutModeShortcut = new KeyboardShortcutHelper( "keyboard/cutmode", this );
335 336 337
    connect( defaultModeShortcut, SIGNAL( activated() ), mouseTool, SLOT( click() ) );
    connect( cutModeShortcut, SIGNAL( activated() ), splitTool, SLOT( click() ) );

338 339 340 341 342 343 344 345
    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
346 347 348
    // Zoom Out
    QToolButton* zoomOutButton = new QToolButton( this );
    zoomOutButton->setIcon( QIcon( ":/images/zoomout" ) );
Ludovic Fauvet's avatar
Ludovic Fauvet committed
349
    zoomOutButton->setStatusTip( tr( "Zoom out" ) );
Ludovic Fauvet's avatar
Ludovic Fauvet committed
350 351 352
    m_ui.statusbar->addPermanentWidget( zoomOutButton );
    connect( zoomOutButton, SIGNAL( clicked() ),
             this, SLOT( zoomOut() ) );
353 354

    // Zoom slider
355 356 357 358 359 360 361 362 363
    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
364
    m_zoomSlider->setInvertedAppearance( true );
365
    m_ui.statusbar->addPermanentWidget( m_zoomSlider );
366

Ludovic Fauvet's avatar
Ludovic Fauvet committed
367 368 369
    // Zoom IN
    QToolButton* zoomInButton = new QToolButton( this );
    zoomInButton->setIcon( QIcon( ":/images/zoomin" ) );
Ludovic Fauvet's avatar
Ludovic Fauvet committed
370
    zoomInButton->setStatusTip( tr( "Zoom in" ) );
Ludovic Fauvet's avatar
Ludovic Fauvet committed
371 372 373
    m_ui.statusbar->addPermanentWidget( zoomInButton );
    connect( zoomInButton, SIGNAL( clicked() ),
             this, SLOT( zoomIn() ) );
374 375
}

376
void MainWindow::initializeDockWidgets( void )
377
{
378 379 380
    m_renderer = new WorkflowRenderer();
    m_renderer->initializeRenderer();
    m_timeline = new Timeline( m_renderer, this );
381 382 383
    m_timeline->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding );
    m_timeline->show();
    setCentralWidget( m_timeline );
384

385
    DockWidgetManager *dockManager = DockWidgetManager::getInstance();
386

387 388
    m_clipPreview = new PreviewWidget( new ClipRenderer, this );
    dockManager->addDockedWidget( m_clipPreview,
Ludovic Fauvet's avatar
Ludovic Fauvet committed
389
                                  QT_TRANSLATE_NOOP( "DockWidgetManager", "Clip Preview" ),
geoff's avatar
geoff committed
390 391 392
                                  Qt::AllDockWidgetAreas,
                                  QDockWidget::AllDockWidgetFeatures,
                                  Qt::TopDockWidgetArea );
393
    KeyboardShortcutHelper* clipShortcut = new KeyboardShortcutHelper( "keyboard/mediapreview", this );
394
    connect( clipShortcut, SIGNAL( activated() ), m_clipPreview, SLOT( on_pushButtonPlay_clicked() ) );
395

396
    m_projectPreview = new PreviewWidget( m_renderer, this );
397
    dockManager->addDockedWidget( m_projectPreview,
Ludovic Fauvet's avatar
Ludovic Fauvet committed
398
                                  QT_TRANSLATE_NOOP( "DockWidgetManager", "Project Preview" ),
399 400
                                  Qt::AllDockWidgetAreas,
                                  QDockWidget::AllDockWidgetFeatures,
401
                                  Qt::TopDockWidgetArea );
402
    KeyboardShortcutHelper* renderShortcut = new KeyboardShortcutHelper( "keyboard/renderpreview", this );
403
    connect( renderShortcut, SIGNAL( activated() ), m_projectPreview, SLOT( on_pushButtonPlay_clicked() ) );
404

405
    QDockWidget* dock = dockManager->addDockedWidget( UndoStack::getInstance( this ),
Ludovic Fauvet's avatar
Ludovic Fauvet committed
406
                                  QT_TRANSLATE_NOOP( "DockWidgetManager", "History" ),
407 408 409
                                  Qt::AllDockWidgetAreas,
                                  QDockWidget::AllDockWidgetFeatures,
                                  Qt::LeftDockWidgetArea );
410 411
    if ( dock != 0 )
        dock->hide();
412
    setupLibrary();
413 414
}

415 416
void        MainWindow::createGlobalPreferences()
{
417
    m_globalPreferences = new Settings( SettingsManager::Vlmc, this );
418
    m_globalPreferences->addCategory( QT_TRANSLATE_NOOP( "Settings", "general" ), SettingsManager::Vlmc,
419 420
                                   QIcon( ":/images/images/vlmc.png" ),
                                   tr ( "VLMC settings" ) );
421
    m_globalPreferences->addCategory( QT_TRANSLATE_NOOP( "Settings", "keyboard" ), SettingsManager::Vlmc,
422 423
                                     QIcon( ":/images/keyboard" ),
                                     tr( "Keyboard Settings" ) );
424 425
}

426
void    MainWindow::createProjectPreferences()
427
{
428
    m_projectPreferences = new Settings( SettingsManager::Project, this );
429
    m_projectPreferences->addCategory( QT_TRANSLATE_NOOP( "Settings", "general" ), SettingsManager::Project,
430 431
                                   QIcon( ":/images/images/vlmc.png" ),
                                   tr ( "Project settings" ) );
432
    m_projectPreferences->addCategory( QT_TRANSLATE_NOOP( "Settings", "video" ), SettingsManager::Project,
433 434
                                   QIcon( ":/images/images/video.png" ),
                                   tr ( "Video settings" ) );
435
    m_projectPreferences->addCategory( QT_TRANSLATE_NOOP( "Settings", "audio" ), SettingsManager::Project,
436 437
                                   QIcon( ":/images/images/audio.png" ),
                                   tr ( "Audio settings" ) );
438 439
}

440

441 442
//Private slots definition

Ludovic Fauvet's avatar
Ludovic Fauvet committed
443 444 445 446
void MainWindow::on_actionQuit_triggered()
{
    QApplication::quit();
}
447 448 449

void MainWindow::on_actionPreferences_triggered()
{
450
   m_globalPreferences->show();
451
}
Ludovic Fauvet's avatar
Ludovic Fauvet committed
452 453 454

void MainWindow::on_actionAbout_triggered()
{
455
    About::getInstance()->exec();
Ludovic Fauvet's avatar
Ludovic Fauvet committed
456
}
457

458
void MainWindow::on_actionTranscode_triggered()
459
{
460 461
    QMessageBox::information( this, tr( "Sorry" ),
                              tr( "This feature is currently disabled." ) );
462
    //Transcode::instance( this )->exec();
463
}
464

465 466
void    MainWindow::on_actionRender_triggered()
{
467
    if ( MainWorkflow::getInstance()->getLengthFrame() <= 0 )
468
    {
469
        QMessageBox::warning( NULL, tr ( "VLMC Renderer" ), tr( "There is nothing to render." ) );
470 471
        return ;
    }
472 473
    else
    {
474
        m_renderer->killRenderer();
475 476 477 478 479 480 481 482 483 484 485 486 487 488
        //Setup dialog box for querying render parameters.
        RendererSettings    *settings = new RendererSettings;
        if ( settings->exec() == QDialog::Rejected )
        {
            delete settings;
            return ;
        }
        QString     outputFileName = settings->outputFileName();
        quint32     width = settings->width();
        quint32     height = settings->height();
        double      fps = settings->fps();
        quint32     vbitrate = settings->videoBitrate();
        quint32     abitrate = settings->audioBitrate();
        delete settings;
489

490 491 492
        if ( m_fileRenderer )
            delete m_fileRenderer;
        m_fileRenderer = new WorkflowFileRenderer();
493 494 495 496
        WorkflowFileRendererDialog  *dialog = new WorkflowFileRendererDialog( m_fileRenderer, width, height );
        dialog->setModal( true );
        dialog->setOutputFileName( outputFileName );

497
        m_fileRenderer->initializeRenderer();
498
        m_fileRenderer->run( outputFileName, width, height, fps, vbitrate, abitrate );
499 500
        dialog->exec();
        delete dialog;
501
    }
502 503
}

504 505
void MainWindow::on_actionNew_Project_triggered()
{
506
    m_pWizard->restart();
507
    m_pWizard->show();
508 509
}

510
void    MainWindow::on_actionHelp_triggered()
511 512
{
    QDesktopServices::openUrl( QUrl( "http://vlmc.org" ) );
513 514
}

515
void    MainWindow::zoomIn()
Ludovic Fauvet's avatar
Ludovic Fauvet committed
516 517 518 519
{
    m_zoomSlider->setValue( m_zoomSlider->value() - 1 );
}

520
void    MainWindow::zoomOut()
Ludovic Fauvet's avatar
Ludovic Fauvet committed
521 522 523
{
    m_zoomSlider->setValue( m_zoomSlider->value() + 1 );
}
Ludovic Fauvet's avatar
Ludovic Fauvet committed
524

525
void    MainWindow::on_actionFullscreen_triggered( bool checked )
Ludovic Fauvet's avatar
Ludovic Fauvet committed
526 527 528 529 530 531
{
    if ( checked )
        showFullScreen();
    else
        showNormal();
}
532

533
void    MainWindow::registerWidgetInWindowMenu( QDockWidget* widget )
534
{
535
    m_ui.menuWindow->addAction( widget->toggleViewAction() );
536
}
537

538
void    MainWindow::toolButtonClicked( int id )
539 540 541
{
    emit toolChanged( (ToolButtons)id );
}
542

543
void MainWindow::on_actionBypass_effects_engine_toggled(bool)
544
{
545 546 547 548 549 550 551
//    EffectsEngine*  ee;
//
//    ee = MainWorkflow::getInstance()->getEffectsEngine();
//    if (toggled)
//        ee->enable();
//    else
//       ee->disable();
552 553
    return ;
}
554

555 556
void MainWindow::on_actionProject_Preferences_triggered()
{
557
  m_projectPreferences->show();
558
}
559

560 561
void    MainWindow::closeEvent( QCloseEvent* e )
{
562 563
    GUIProjectManager   *pm = GUIProjectManager::getInstance();
    if ( pm->askForSaveIfModified() )
564
        e->accept();
565 566
    else
        e->ignore();
567
}
568

569
void    MainWindow::projectUpdated( const QString& projectName, bool savedStatus )
570 571
{
    QString title = tr( "VideoLAN Movie Creator" );
572
    title += " - ";
573 574 575 576 577
    title += projectName;
    if ( savedStatus == false )
        title += " *";
    setWindowTitle( title );
}
578

579 580
void    MainWindow::on_actionClose_Project_triggered()
{
581
    GUIProjectManager::getInstance()->closeProject();
582 583
}

584 585 586 587 588 589 590 591 592 593
void    MainWindow::on_actionUndo_triggered()
{
    UndoStack::getInstance( this )->undo();
}

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

Hugo Beauzee-Luyssen's avatar
Hugo Beauzee-Luyssen committed
594 595
void    MainWindow::on_actionCrash_triggered()
{
596 597 598 599 600
    //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
601
}
Hugo Beauzee-Luyssen's avatar
Hugo Beauzee-Luyssen committed
602 603 604 605

bool    MainWindow::restoreSession()
{
    QSettings   s;
606
    bool        fileCreated = false;
Hugo Beauzee-Luyssen's avatar
Hugo Beauzee-Luyssen committed
607 608
    bool        ret = false;

609 610
    fileCreated = s.contains( "VlmcVersion" );
    if ( fileCreated == true )
Hugo Beauzee-Luyssen's avatar
Hugo Beauzee-Luyssen committed
611
    {
612
        bool        cleanQuit = s.value( "CleanQuit", true ).toBool();
613 614 615 616 617 618 619

        // 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
620
        {
621
            QMessageBox::StandardButton res = QMessageBox::question( this, tr( "Crash recovery" ), tr( "VLMC didn't closed nicely. Do you wan't to recover your project?" ),
622 623 624
                                   QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes );
            if ( res == QMessageBox::Yes )
            {
625
                if ( GUIProjectManager::getInstance()->loadEmergencyBackup() == true )
626 627
                    ret = true;
                else
628
                    QMessageBox::warning( this, tr( "Can't restore project" ), tr( "VLMC didn't manage to restore your project. We apology for the inconvenience" ) );
629
            }
Hugo Beauzee-Luyssen's avatar
Hugo Beauzee-Luyssen committed
630 631 632 633 634 635
        }
    }
    s.setValue( "CleanQuit", false );
    s.sync();
    return ret;
}
636 637 638 639 640

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

642 643 644 645 646 647 648 649 650 651
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
652
#ifdef WITH_CRASHBUTTON
653 654 655 656 657 658 659 660 661
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
662