MainWindow.cpp 31.5 KB
Newer Older
Ludovic Fauvet's avatar
Ludovic Fauvet committed
1
/*****************************************************************************
2
 * MainWindow.cpp: VLMC MainWindow
Ludovic Fauvet's avatar
Ludovic Fauvet committed
3
 *****************************************************************************
Ludovic Fauvet's avatar
Ludovic Fauvet committed
4
 * Copyright (C) 2008-2010 VideoLAN
Ludovic Fauvet's avatar
Ludovic Fauvet committed
5 6
 *
 * Authors: Ludovic Fauvet <etix@l0cal.com>
7
 *          Hugo 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 <QNetworkProxy>
32
#include <QSettings>
33
#include <QDebug>
Hugo Beauzee-Luyssen's avatar
Hugo Beauzee-Luyssen committed
34

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

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

/* Widgets */
#include "DockWidgetManager.h"
51
#include "EffectsListView.h"
52
#include "ImportController.h"
53
#include "MediaLibrary.h"
54
#include "NotificationZone.h"
55
#include "PreviewWidget.h"
56 57
#include "timeline/Timeline.h"
#include "timeline/TracksView.h"
58
#include "UndoStack.h"
59 60

/* Settings / Preferences */
61
#include "project/GuiProjectManager.h"
Ludovic Fauvet's avatar
Ludovic Fauvet committed
62 63
#include "ProjectWizard.h"
#include "Settings.h"
64
#include "SettingsManager.h"
65
#include "LanguageHelper.h"
Ludovic Fauvet's avatar
Ludovic Fauvet committed
66

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

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

75
    //We only install message handler here cause it uses configuration.
76
//    VlmcDebug::getInstance()->setup();
77

78
    //VLC Instance:
79
    LibVLCpp::Instance::getInstance();
80

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

84 85 86
    //Preferences
    initVlmcPreferences();

87
    // GUI
88
    DockWidgetManager::getInstance( this )->setMainWindow( this );
89
    createGlobalPreferences();
90
    createProjectPreferences();
91
    initializeDockWidgets();
92
    initToolbar();
93
    createStatusBar();
94 95
    checkFolders();
    loadGlobalProxySettings();
Ludovic Fauvet's avatar
Ludovic Fauvet committed
96
#ifdef WITH_CRASHBUTTON
97 98
    setupCrashTester();
#endif
99

Ludovic Fauvet's avatar
Ludovic Fauvet committed
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
    connect( GUIProjectManager::getInstance(), SIGNAL( projectUpdated( const QString&, bool ) ),
111
             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

127
#ifdef WITH_CRASHHANDLER
128
    if ( restoreSession() == true )
129 130
        return ;
#endif
131
    QSettings s;
132

133 134 135 136 137
    // Restore the geometry
    restoreGeometry( s.value( "MainWindowGeometry" ).toByteArray() );
    // Restore the layout
    restoreState( s.value( "MainWindowState" ).toByteArray() );

138
    if ( s.value( "ShowWizardStartup", true ).toBool() )
Hugo Beauzee-Luyssen's avatar
Hugo Beauzee-Luyssen committed
139
    {
140
        //If a project was opened from the command line: don't show the wizard.
141 142
        if ( qApp->arguments().size() == 1 )
            m_pWizard->show();
Hugo Beauzee-Luyssen's avatar
Hugo Beauzee-Luyssen committed
143
    }
Ludovic Fauvet's avatar
Ludovic Fauvet committed
144 145
}

146 147
MainWindow::~MainWindow()
{
148 149
    if ( m_fileRenderer )
        delete m_fileRenderer;
150
    delete m_importController;
151
    LibVLCpp::Instance::destroyInstance();
152 153
}

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

168
//use this helper when the shortcut is binded to a menu action
169 170 171
#define CREATE_MENU_SHORTCUT( key, defaultValue, name, desc, actionInstance  )      \
        VLMC_CREATE_PREFERENCE_KEYBOARD( key, defaultValue, name, desc );           \
        new KeyboardShortcutHelper( key, m_ui.actionInstance, this );
172

173 174 175
void
MainWindow::initVlmcPreferences()
{
176
    //Setup VLMC Keyboard Preference...
177 178 179
    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" ) );
180

181 182 183
    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" ) );
184

185
    //A bit nasty, but we better use what Qt's providing as default shortcut
186 187 188 189
    CREATE_MENU_SHORTCUT( "keyboard/undo",
                          QKeySequence( QKeySequence::Undo ).toString().toLocal8Bit(),
                          QT_TRANSLATE_NOOP( "PreferenceWidget", "Undo" ),
                          QT_TRANSLATE_NOOP( "PreferenceWidget", "Undo the last action" ), actionUndo );
190

191 192 193 194
    CREATE_MENU_SHORTCUT( "keyboard/redo",
                          QKeySequence( QKeySequence::Redo ).toString().toLocal8Bit(),
                          QT_TRANSLATE_NOOP( "PreferenceWidget", "Redo" ),
                          QT_TRANSLATE_NOOP( "PreferenceWidget", "Redo the last action" ), actionRedo );
195

196 197 198 199
    CREATE_MENU_SHORTCUT( "keyboard/help",
                          QKeySequence( QKeySequence::HelpContents ).toString().toLocal8Bit(),
                          QT_TRANSLATE_NOOP( "PreferenceWidget", "Help" ),
                          QT_TRANSLATE_NOOP( "PreferenceWidget", "Toggle the help page" ), actionHelp );
200

201 202 203
    CREATE_MENU_SHORTCUT( "keyboard/quit", "Ctrl+Q",
                          QT_TRANSLATE_NOOP( "PreferenceWidget", "Quit" ),
                          QT_TRANSLATE_NOOP( "PreferenceWidget", "Quit VLMC" ), actionQuit );
204

205 206 207
    CREATE_MENU_SHORTCUT( "keyboard/preferences", "Alt+P",
                          QT_TRANSLATE_NOOP( "PreferenceWidget", "Preferences" ),
                          QT_TRANSLATE_NOOP( "PreferenceWidget", "Open VLMC preferences" ), actionPreferences );
208

209 210 211 212
    CREATE_MENU_SHORTCUT( "keyboard/projectpreferences", "Ctrl+P",
                          QT_TRANSLATE_NOOP( "PreferenceWidget", "Project preferences" ),
                          QT_TRANSLATE_NOOP( "PreferenceWidget", "Open the project preferences"), actionProject_Preferences );

213 214 215
    CREATE_MENU_SHORTCUT( "keyboard/fullscreen", "F",
                          QT_TRANSLATE_NOOP( "PreferenceWidget", "Fullscreen" ),
                          QT_TRANSLATE_NOOP( "PreferenceWidget", "Switch to fullscreen mode" ), actionFullscreen );
216

217 218 219
    CREATE_MENU_SHORTCUT( "keyboard/newproject",
                          QKeySequence( QKeySequence::New ).toString().toLocal8Bit(),
                          QT_TRANSLATE_NOOP( "PreferenceWidget", "New project" ),
220
                          QT_TRANSLATE_NOOP( "PreferenceWidget", "Open the new project wizard" ), actionNew_Project );
221

222 223 224 225
    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 );
226

227 228 229 230
    CREATE_MENU_SHORTCUT( "keyboard/save",
                          QKeySequence( QKeySequence::Save ).toString().toLocal8Bit(),
                          QT_TRANSLATE_NOOP( "PreferenceWidget", "Save" ),
                          QT_TRANSLATE_NOOP( "PreferenceWidget", "Save the current project" ), actionSave );
231

232 233 234
    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 );
235

236 237 238 239
    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 );
240

241 242 243
    CREATE_MENU_SHORTCUT( "keyboard/importmedia", "Ctrl+I",
                          QT_TRANSLATE_NOOP( "PreferenceWidget", "Import media" ),
                          QT_TRANSLATE_NOOP( "PreferenceWidget", "Open the import window" ), actionImport );
244

245 246 247 248
    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 );

249 250 251 252 253 254 255 256
    CREATE_MENU_SHORTCUT( "keyboard/defaultmode", "n",
                          QT_TRANSLATE_NOOP( "PreferenceWidget", "Selection mode" ),
                          QT_TRANSLATE_NOOP( "PreferenceWidget", "Select the selection tool in the timeline" ), actionSelection_mode );

    CREATE_MENU_SHORTCUT( "keyboard/cutmode", "x",
                          QT_TRANSLATE_NOOP( "PreferenceWidget", "Cut mode" ),
                          QT_TRANSLATE_NOOP( "PreferenceWidget", "Select the cut/razor tool in the timeline" ), actionCut_mode );

257
    //Setup VLMC Lang. Preferences...
258
    VLMC_CREATE_PREFERENCE_LANGUAGE( "general/VLMCLang", "default",
259
                                     QT_TRANSLATE_NOOP( "PreferenceWidget", "Language" ),
260
                                     QT_TRANSLATE_NOOP( "PreferenceWidget", "The VLMC's UI language" ) );
261

262 263 264 265
    SettingsManager::getInstance()->watchValue( "general/VLMCLang",
                                                LanguageHelper::getInstance(),
                                                SLOT( languageChanged( const QVariant& ) ),
                                                SettingsManager::Vlmc );
266

267
    //Setup VLMC General Preferences...
268
    VLMC_CREATE_PREFERENCE_BOOL( "general/ConfirmDeletion", true,
269
                                 QT_TRANSLATE_NOOP( "PreferenceWidget", "Confirm clip deletion"),
270
                                 QT_TRANSLATE_NOOP( "PreferenceWidget", "Ask for confirmation before deleting a clip from the timeline" ) );
271

272
    VLMC_CREATE_PREFERENCE_PATH( "general/DefaultProjectLocation", QDir::homePath(),
273 274 275
                                    QT_TRANSLATE_NOOP( "PreferencesWidget", "Project default location" ),
                                    QT_TRANSLATE_NOOP( "PreferenceWidget", "The default location where to store projects folders" ) );

276
    VLMC_CREATE_PREFERENCE_PATH( "general/TempFolderLocation", QDir::tempPath() + "/VLMC/",
277 278 279
                                    QT_TRANSLATE_NOOP( "PreferencesWidget", "Temporary folder" ),
                                    QT_TRANSLATE_NOOP( "PreferenceWidget", "The temporary folder used by VLMC to process videos." ) );

280 281 282
    //Setup VLMC Youtube Preference...
    VLMC_CREATE_PREFERENCE_STRING( "youtube/DeveloperKey", "AI39si7FOtp165Vq644xVkuka84TVQNbztQmQ1dC9stheBfh3-33RZaTu7eJkYJzvxp6XNbvlr4M6-ULjXDERFl62WIo6AQIEQ",
                                     QT_TRANSLATE_NOOP( "PreferenceWidget", "Youtube Developer Key" ),
283
                                     QT_TRANSLATE_NOOP( "PreferenceWidget", "VLMC's Youtube Developer Key" ) );
284 285 286

    VLMC_CREATE_PREFERENCE_STRING( "youtube/Username", "username",
                                     QT_TRANSLATE_NOOP( "PreferenceWidget", "Youtube Username" ),
287 288 289 290 291
                                     QT_TRANSLATE_NOOP( "PreferenceWidget", "Valid YouTube username" ) );

    VLMC_CREATE_PREFERENCE_PASSWORD( "youtube/Password", "",
                                     QT_TRANSLATE_NOOP( "PreferenceWidget", "Youtube Password" ),
                                     QT_TRANSLATE_NOOP( "PreferenceWidget", "Leave this field, password will be stored in unencryped form." ) );
292 293

    //Setup VLMC Proxy Settings
294 295 296 297 298 299 300
    VLMC_CREATE_PREFERENCE_BOOL( "network/UseProxy", false,
                                     QT_TRANSLATE_NOOP( "PreferenceWidget", "Enable Proxy for VLMC"),
                                     QT_TRANSLATE_NOOP( "PreferenceWidget", "Enables Global Network Proxy for VLMC." ) );

    VLMC_CREATE_PREFERENCE_STRING( "network/ProxyHost", "",
                                     QT_TRANSLATE_NOOP( "PreferenceWidget", "Proxy Hostname" ),
                                     QT_TRANSLATE_NOOP( "PreferenceWidget", "Set Proxy Hostname." ) );
301 302 303

    VLMC_CREATE_PREFERENCE_STRING( "network/ProxyPort", "",
                                     QT_TRANSLATE_NOOP( "PreferenceWidget", "Proxy Port" ),
304
                                     QT_TRANSLATE_NOOP( "PreferenceWidget", "Set Proxy Port." ) );
305 306 307

    VLMC_CREATE_PREFERENCE_STRING( "network/ProxyUsername", "",
                                     QT_TRANSLATE_NOOP( "PreferenceWidget", "Proxy Username" ),
308
                                     QT_TRANSLATE_NOOP( "PreferenceWidget", "Set Proxy Username, if any." ) );
309

310
    VLMC_CREATE_PREFERENCE_PASSWORD( "network/ProxyPassword", "",
311
                                     QT_TRANSLATE_NOOP( "PreferenceWidget", "Proxy Password" ),
312
                                     QT_TRANSLATE_NOOP( "PreferenceWidget", "Set Proxy Password, if any." ) );
313

314
    //Load saved preferences :
315 316 317 318 319 320 321
    QSettings       s;
    if ( s.value( "VlmcVersion" ).toString() != PROJECT_VERSION )
        s.clear();
    else
    {
        loadVlmcPreferences( "keyboard" );
        loadVlmcPreferences( "general" );
322 323
        loadVlmcPreferences( "youtube" );
        loadVlmcPreferences( "network" );
324 325
    }
    s.setValue( "VlmcVersion", PROJECT_VERSION );
326 327 328 329 330 331 332 333 334 335 336 337
}

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 );
    }
338 339
}

340 341
#undef CREATE_MENU_SHORTCUT

342 343
void
MainWindow::on_actionSave_triggered()
344
{
345
    GUIProjectManager::getInstance()->saveProject();
346 347
}

348
void
349
MainWindow::on_actionSave_As_triggered()
Hugo Beauzee-Luyssen's avatar
Hugo Beauzee-Luyssen committed
350
{
351
    GUIProjectManager::getInstance()->saveProject( true );
Hugo Beauzee-Luyssen's avatar
Hugo Beauzee-Luyssen committed
352 353
}

354
void
355
MainWindow::on_actionLoad_Project_triggered()
356
{
357
    GUIProjectManager::getInstance()->loadProject();
358 359
}

360 361 362 363 364 365 366 367 368 369
void
MainWindow::createNotificationZone()
{
    QWidget *notifSpacer = new QWidget( this );
    notifSpacer->setFixedWidth( 75 );
    m_ui.statusbar->addPermanentWidget( notifSpacer );

    m_ui.statusbar->addPermanentWidget( NotificationZone::getInstance() );
}

370
void
371
MainWindow::createStatusBar()
372
{
373 374 375
    //Notifications:
    createNotificationZone();

376 377 378 379 380
    // Spacer
    QWidget* spacer = new QWidget( this );
    spacer->setFixedWidth( 20 );
    m_ui.statusbar->addPermanentWidget( spacer );

Ludovic Fauvet's avatar
Ludovic Fauvet committed
381 382 383
    // Zoom Out
    QToolButton* zoomOutButton = new QToolButton( this );
    zoomOutButton->setIcon( QIcon( ":/images/zoomout" ) );
Ludovic Fauvet's avatar
Ludovic Fauvet committed
384
    zoomOutButton->setStatusTip( tr( "Zoom out" ) );
Ludovic Fauvet's avatar
Ludovic Fauvet committed
385 386 387
    m_ui.statusbar->addPermanentWidget( zoomOutButton );
    connect( zoomOutButton, SIGNAL( clicked() ),
             this, SLOT( zoomOut() ) );
388 389

    // Zoom slider
390 391 392 393 394 395 396 397 398
    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
399
    m_zoomSlider->setInvertedAppearance( true );
400
    m_ui.statusbar->addPermanentWidget( m_zoomSlider );
401

Ludovic Fauvet's avatar
Ludovic Fauvet committed
402 403 404
    // Zoom IN
    QToolButton* zoomInButton = new QToolButton( this );
    zoomInButton->setIcon( QIcon( ":/images/zoomin" ) );
Ludovic Fauvet's avatar
Ludovic Fauvet committed
405
    zoomInButton->setStatusTip( tr( "Zoom in" ) );
Ludovic Fauvet's avatar
Ludovic Fauvet committed
406 407 408
    m_ui.statusbar->addPermanentWidget( zoomInButton );
    connect( zoomInButton, SIGNAL( clicked() ),
             this, SLOT( zoomIn() ) );
409 410
}

411
void
412
MainWindow::initializeDockWidgets( void )
413
{
414 415 416
    m_renderer = new WorkflowRenderer();
    m_renderer->initializeRenderer();
    m_timeline = new Timeline( m_renderer, this );
417 418 419
    m_timeline->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding );
    m_timeline->show();
    setCentralWidget( m_timeline );
420

421
    m_importController = new ImportController();
422

423 424 425 426 427 428 429
    setupEffectsList();
    setupClipPreview();
    setupProjectPreview();
    //Clip renderer must exist before this method is called, as it connects the library with the renderer.
    setupLibrary();
    setupUndoRedoWidget();
}
430

431 432 433 434 435 436 437 438 439 440
void
MainWindow::setupUndoRedoWidget()
{
    QDockWidget     *dockedWidget = DockWidgetManager::getInstance()->createDockedWidget(
                                      QT_TRANSLATE_NOOP( "DockWidgetManager", "History" ),
                                      Qt::AllDockWidgetAreas,
                                      QDockWidget::AllDockWidgetFeatures );
    QWidget         *undoRedoWidget = UndoStack::getInstance( dockedWidget );
    DockWidgetManager::getInstance()->addDockedWidget( dockedWidget, undoRedoWidget, Qt::LeftDockWidgetArea );
}
441

442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457
void
MainWindow::setupEffectsList()
{
    QDockWidget     *dockedWidget = DockWidgetManager::getInstance()->createDockedWidget(
                                        QT_TRANSLATE_NOOP( "DockWidgetManager", "Effects List" ),
                                        Qt::AllDockWidgetAreas,
                                        QDockWidget::AllDockWidgetFeatures );
    m_effectsList = new EffectsListView( dockedWidget );
    m_effectsList->setType( Effect::Filter );
    EffectsEngine::getInstance()->loadEffects();
    DockWidgetManager::getInstance()->addDockedWidget( dockedWidget, m_effectsList, Qt::LeftDockWidgetArea );
}

void
MainWindow::setupLibrary()
{
458 459 460
    const ClipRenderer* clipRenderer = qobject_cast<const ClipRenderer*>( m_clipPreview->getGenericRenderer() );
    Q_ASSERT( clipRenderer != NULL );

461 462 463 464 465
    QDockWidget     *dockedLibrary = DockWidgetManager::getInstance()->createDockedWidget(
                                                    QT_TRANSLATE_NOOP( "DockWidgetManager", "Media Library" ),
                                                    Qt::AllDockWidgetAreas,
                                                    QDockWidget::AllDockWidgetFeatures );
    m_mediaLibrary = new MediaLibrary( dockedLibrary );
466 467 468 469 470 471
    connect( m_mediaLibrary, SIGNAL( clipSelected( Clip* ) ),
             clipRenderer, SLOT( setClip( Clip* ) ) );
    connect( m_mediaLibrary, SIGNAL( importRequired() ),
             this, SLOT( on_actionImport_triggered() ) );
    connect( Library::getInstance(), SIGNAL( clipRemoved( const QUuid& ) ),
             clipRenderer, SLOT( clipUnloaded( const QUuid& ) ) );
472
    DockWidgetManager::getInstance()->addDockedWidget( dockedLibrary, m_mediaLibrary, Qt::LeftDockWidgetArea );
473 474 475
}

void
476
MainWindow::setupClipPreview()
477
{
478 479 480 481 482 483
    QDockWidget *dockedWidget = DockWidgetManager::getInstance()->createDockedWidget(
                                                QT_TRANSLATE_NOOP( "DockWidgetManager", "Clip Preview" ),
                                                Qt::AllDockWidgetAreas,
                                                QDockWidget::AllDockWidgetFeatures );
    m_clipPreview = new PreviewWidget( dockedWidget );
    m_clipPreview->setRenderer( new ClipRenderer );
484

485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502
    KeyboardShortcutHelper* clipShortcut = new KeyboardShortcutHelper( "keyboard/mediapreview", this );
    connect( clipShortcut, SIGNAL( activated() ), m_clipPreview, SLOT( on_pushButtonPlay_clicked() ) );
    DockWidgetManager::getInstance()->addDockedWidget( dockedWidget, m_clipPreview, Qt::TopDockWidgetArea );
}

void
MainWindow::setupProjectPreview()
{
    QDockWidget     *dockedWidget = DockWidgetManager::getInstance()->createDockedWidget(
                                        QT_TRANSLATE_NOOP( "DockWidgetManager", "Project Preview" ),
                                        Qt::AllDockWidgetAreas,
                                        QDockWidget::AllDockWidgetFeatures );

    m_projectPreview = new PreviewWidget( dockedWidget );
    m_projectPreview->setRenderer( m_renderer );
    KeyboardShortcutHelper* renderShortcut = new KeyboardShortcutHelper( "keyboard/renderpreview", this );
    connect( renderShortcut, SIGNAL( activated() ), m_projectPreview, SLOT( on_pushButtonPlay_clicked() ) );
    DockWidgetManager::getInstance()->addDockedWidget( dockedWidget, m_projectPreview, Qt::TopDockWidgetArea );
503 504
}

505 506 507 508 509 510 511 512 513 514 515 516 517
void
MainWindow::initToolbar()
{
    QActionGroup    *mouseActions = new QActionGroup( m_ui.toolBar );
    mouseActions->addAction( m_ui.actionSelection_mode );
    mouseActions->addAction( m_ui.actionCut_mode );
    m_ui.actionSelection_mode->setChecked( true );
    m_ui.toolBar->addActions( mouseActions->actions() );
    connect( mouseActions, SIGNAL( triggered(QAction*) ),
             this, SLOT( toolButtonClicked( QAction* ) ) );
    m_ui.menuTools->addActions( mouseActions->actions() );
}

518 519
void
MainWindow::createGlobalPreferences()
520
{
521
    m_globalPreferences = new Settings( SettingsManager::Vlmc, this );
522
    m_globalPreferences->addCategory( QT_TRANSLATE_NOOP( "Settings", "general" ), SettingsManager::Vlmc,
523
                                     QIcon( ":/images/vlmc" ),
Nikoli's avatar
Nikoli committed
524
                                     tr ( "General" ) );
525
    m_globalPreferences->addCategory( QT_TRANSLATE_NOOP( "Settings", "keyboard" ), SettingsManager::Vlmc,
526
                                     QIcon( ":/images/keyboard" ),
Nikoli's avatar
Nikoli committed
527
                                     tr( "Keyboard" ) );
528 529
    m_globalPreferences->addCategory( QT_TRANSLATE_NOOP( "Settings", "youtube" ), SettingsManager::Vlmc,
                                     QIcon( ":/images/youtube" ),
Nikoli's avatar
Nikoli committed
530
                                     tr( "Youtube" ) );
531 532
    m_globalPreferences->addCategory( QT_TRANSLATE_NOOP( "Settings", "network" ), SettingsManager::Vlmc,
                                     QIcon( ":/images/network" ),
Nikoli's avatar
Nikoli committed
533
                                     tr( "Network" ) );
534 535
}

536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554
void
MainWindow::loadGlobalProxySettings()
{
    if( VLMC_GET_BOOL( "network/UseProxy" ) )
    {
        /* Updates Global Proxy for VLMC */
        QNetworkProxy proxy;
        proxy.setType( QNetworkProxy::HttpProxy );
        proxy.setHostName( VLMC_GET_STRING( "network/ProxyHost" ) );
        proxy.setPort( VLMC_GET_STRING( "network/ProxyPort" ).toInt() );
        proxy.setUser( VLMC_GET_STRING( "network/ProxyUsername" ) );
        proxy.setPassword( VLMC_GET_STRING( "network/ProxyPassword" ) );
        QNetworkProxy::setApplicationProxy( proxy );
        return;
    }

    QNetworkProxy::setApplicationProxy( QNetworkProxy::NoProxy );
}

555 556
void
MainWindow::createProjectPreferences()
557
{
558
    m_projectPreferences = new Settings( SettingsManager::Project, this );
559
    m_projectPreferences->addCategory( QT_TRANSLATE_NOOP( "Settings", "general" ), SettingsManager::Project,
560
                                   QIcon( ":/images/vlmc" ),
Nikoli's avatar
Nikoli committed
561
                                   tr ( "General" ) );
562
    m_projectPreferences->addCategory( QT_TRANSLATE_NOOP( "Settings", "video" ), SettingsManager::Project,
563
                                   QIcon( ":/images/video" ),
Nikoli's avatar
Nikoli committed
564
                                   tr ( "Video" ) );
565
    m_projectPreferences->addCategory( QT_TRANSLATE_NOOP( "Settings", "audio" ), SettingsManager::Project,
566
                                   QIcon( ":/images/audio" ),
Nikoli's avatar
Nikoli committed
567
                                   tr ( "Audio" ) );
568 569
}

570 571 572 573 574 575 576 577 578 579 580
void
MainWindow::checkFolders()
{
    QDir dirUtil;
    if( !dirUtil.exists( VLMC_GET_STRING( "general/DefaultProjectLocation" ) ) )
        dirUtil.mkdir( VLMC_GET_STRING( "general/DefaultProjectLocation" ) );

    if( !dirUtil.exists( VLMC_GET_STRING( "general/TempFolderLocation" ) ) )
        dirUtil.mkdir( VLMC_GET_STRING( "general/TempFolderLocation" ) );
}

581

582 583
//Private slots definition

584
void
585
MainWindow::on_actionQuit_triggered()
Ludovic Fauvet's avatar
Ludovic Fauvet committed
586 587 588
{
    QApplication::quit();
}
589

590
void
591
MainWindow::on_actionPreferences_triggered()
592
{
593
   m_globalPreferences->show();
594
}
Ludovic Fauvet's avatar
Ludovic Fauvet committed
595

596
void
597
MainWindow::on_actionAbout_triggered()
Ludovic Fauvet's avatar
Ludovic Fauvet committed
598
{
599
    About::getInstance()->exec();
Ludovic Fauvet's avatar
Ludovic Fauvet committed
600
}
601

602 603
bool
MainWindow::checkVideoLength()
604
{
605
    if ( MainWorkflow::getInstance()->getLengthFrame() <= 0 )
606
    {
607
        QMessageBox::warning( NULL, tr ( "VLMC Renderer" ), tr( "There is nothing to render." ) );
608
        return false;
609
    }
610 611 612
    return true;
}

613
bool
614 615 616 617 618
MainWindow::renderVideo( const QString& outputFileName, quint32 width, quint32 height, double fps, quint32 vbitrate, quint32 abitrate )
{
    if ( m_fileRenderer )
        delete m_fileRenderer;
    m_fileRenderer = new WorkflowFileRenderer();
619

Rohit Yadav's avatar
Rohit Yadav committed
620
    WorkflowFileRendererDialog  *dialog = new WorkflowFileRendererDialog( m_fileRenderer, width, height );
621 622 623 624 625
    dialog->setModal( true );
    dialog->setOutputFileName( outputFileName );

    m_fileRenderer->initializeRenderer();
    m_fileRenderer->run( outputFileName, width, height, fps, vbitrate, abitrate );
626 627 628 629 630 631 632

    if ( dialog->exec() == QDialog::Rejected )
    {
        delete dialog;
        return false;
    }

633
    delete dialog;
634 635 636 637 638 639 640 641 642 643 644 645 646 647
    return true;
}

bool
MainWindow::renderVideoSettings( bool exportType )
{
    RendererSettings *settings = new RendererSettings( exportType );

    if ( settings->exec() == QDialog::Rejected )
    {
        delete settings;
        return false;
    }

648
    QString     outputFileName = settings->outputFileName();
649 650 651 652 653 654
    quint32     width          = settings->width();
    quint32     height         = settings->height();
    double      fps            = settings->fps();
    quint32     vbitrate       = settings->videoBitrate();
    quint32     abitrate       = settings->audioBitrate();

655 656
    delete settings;

657
    return renderVideo( outputFileName, width, height, fps, vbitrate, abitrate );
658 659
}

660
void
661 662 663
MainWindow::on_actionRender_triggered()
{
    if ( checkVideoLength() )
664
    {
665
        m_renderer->killRenderer();
666
        //Setup dialog box for querying render parameters.
667
        renderVideoSettings( false );
668
    }
669 670
}

671
void
672
MainWindow::on_actionShare_On_Internet_triggered()
673 674 675 676 677
{
    if ( checkVideoLength() )
    {
        m_renderer->killRenderer();

678 679
        if( !renderVideoSettings( true ) )
            return;
680

681 682
        checkFolders();
        QString fileName = VLMC_GET_STRING( "general/TempFolderLocation" ) + "/" +
683
                           VLMC_PROJECT_GET_STRING( "general/ProjectName" ) +
684
                           "-vlmc.mp4";
685

686
        loadGlobalProxySettings();
687

688 689
        ShareOnInternet *shareVideo = new ShareOnInternet();
        shareVideo->setVideoFile( fileName );
690

691 692 693 694 695
        if ( shareVideo->exec() == QDialog::Rejected )
        {
            delete shareVideo;
            return;
        }
696

697
        delete shareVideo;
698 699 700
    }
}

701
void
702
MainWindow::on_actionNew_Project_triggered()
703
{
704
    m_pWizard->restart();
705
    m_pWizard->show();
706 707
}

708
void
709
MainWindow::on_actionHelp_triggered()
710 711
{
    QDesktopServices::openUrl( QUrl( "http://vlmc.org" ) );
712 713
}

714
void
715
MainWindow::zoomIn()
Ludovic Fauvet's avatar
Ludovic Fauvet committed
716 717 718 719
{
    m_zoomSlider->setValue( m_zoomSlider->value() - 1 );
}

720
void
721
MainWindow::zoomOut()
Ludovic Fauvet's avatar
Ludovic Fauvet committed
722 723 724
{
    m_zoomSlider->setValue( m_zoomSlider->value() + 1 );
}
Ludovic Fauvet's avatar
Ludovic Fauvet committed
725

726
void
727
MainWindow::on_actionFullscreen_triggered( bool checked )
Ludovic Fauvet's avatar
Ludovic Fauvet committed
728 729 730 731 732 733
{
    if ( checked )
        showFullScreen();
    else
        showNormal();
}
734

735
void
736
MainWindow::registerWidgetInWindowMenu( QDockWidget* widget )
737
{
738
    m_ui.menuWindow->addAction( widget->toggleViewAction() );
739
}
740

741
void
742
MainWindow::toolButtonClicked( QAction *action )
743
{
744 745 746 747 748 749
    if ( action == m_ui.actionSelection_mode )
        emit toolChanged( TOOL_DEFAULT );
    else if ( action == m_ui.actionCut_mode )
        emit toolChanged( TOOL_CUT );
    else
        qCritical() << "Unknown tool. This should not happen !";
750
}
751

752
void
753
MainWindow::on_actionProject_Preferences_triggered()
754
{
755
  m_projectPreferences->show();
756
}
757

758
void
759
MainWindow::closeEvent( QCloseEvent* e )
760
{
761 762
    GUIProjectManager   *pm = GUIProjectManager::getInstance();
    if ( pm->askForSaveIfModified() )
763
        e->accept();
764
    else
765
    {
766
        e->ignore();
767 768 769 770 771 772 773 774 775
        return ;
    }
    QSettings s;
    // Save the current geometry
    s.setValue( "MainWindowGeometry", saveGeometry() );
    // Save the current layout
    s.setValue( "MainWindowState", saveState() );
    s.setValue( "CleanQuit", true );
    s.sync();
776
}
777

778
void
779
MainWindow::projectUpdated( const QString& projectName, bool savedStatus )
780 781
{
    QString title = tr( "VideoLAN Movie Creator" );
782
    title += " - ";
783 784 785 786 787
    title += projectName;
    if ( savedStatus == false )
        title += " *";
    setWindowTitle( title );
}
788

789
void
790
MainWindow::on_actionClose_Project_triggered()
791
{
792
    GUIProjectManager::getInstance()->closeProject();
793 794
}

795
void
796
MainWindow::on_actionUndo_triggered()
797 798 799 800
{
    UndoStack::getInstance( this )->undo();
}

801
void
802
MainWindow::on_actionRedo_triggered()
803 804 805 806
{
    UndoStack::getInstance( this )->redo();
}

807
void
808
MainWindow::on_actionCrash_triggered()
809
{
810 811 812 813 814
    //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 );
815
}
Hugo Beauzee-Luyssen's avatar
Hugo Beauzee-Luyssen committed
816

817
bool
818
MainWindow::restoreSession()
Hugo Beauzee-Luyssen's avatar
Hugo Beauzee-Luyssen committed
819 820
{
    QSettings   s;
821
    bool        fileCreated = false;
Hugo Beauzee-Luyssen's avatar
Hugo Beauzee-Luyssen committed
822 823
    bool        ret = false;

824 825
    fileCreated = s.contains( "VlmcVersion" );
    if ( fileCreated == true )
Hugo Beauzee-Luyssen's avatar
Hugo Beauzee-Luyssen committed
826
    {
827
        bool        cleanQuit = s.value( "CleanQuit", true ).toBool();
828 829

        if ( cleanQuit == false )
Hugo Beauzee-Luyssen's avatar
Hugo Beauzee-Luyssen committed
830
        {
831
            QMessageBox::StandardButton res = QMessageBox::question( this, tr( "Crash recovery" ), tr( "VLMC didn't closed nicely. Do you want to recover your project?" ),
832 833 834
                                   QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes );
            if ( res == QMessageBox::Yes )
            {
835
                if ( GUIProjectManager::getInstance()->loadEmergencyBackup() == true )
836 837
                    ret = true;
                else
838
                    QMessageBox::warning( this, tr( "Can't restore project" ), tr( "VLMC didn't manage to restore your project. We apology for the inconvenience" ) );
839
            }
Hugo Beauzee-Luyssen's avatar
Hugo Beauzee-Luyssen committed
840 841 842 843 844 845
        }
    }
    s.setValue( "CleanQuit", false );
    s.sync();
    return ret;
}
846

847
void
848
MainWindow::on_actionImport_triggered()
849 850 851
{
    m_importController->exec();
}
852

853
void
854
MainWindow::canUndoChanged( bool canUndo )
855 856 857 858
{
    m_ui.actionUndo->setEnabled( canUndo );
}

859
void
860
MainWindow::canRedoChanged( bool canRedo )
861 862 863 864
{
    m_ui.actionRedo->setEnabled( canRedo );
}

Ludovic Fauvet's avatar
Ludovic Fauvet committed
865
#ifdef WITH_CRASHBUTTON
866 867
void
MainWindow::setupCrashTester()
868 869 870 871 872 873 874 875
{
    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
876