]> git.sesse.net Git - vlc/blobdiff - modules/gui/qt4/main_interface.cpp
Simplify and remove duplicate code.
[vlc] / modules / gui / qt4 / main_interface.cpp
index bc5ff63e187ae8e5bfd2c1823421cfbe3f662cbf..f3b7515c55ee9376e4f3a074d07ab0bb029c4273 100644 (file)
@@ -51,7 +51,9 @@
 #include <QLabel>
 #include <QSlider>
 #include <QWidgetAction>
+#if 0
 #include <QDockWidget>
+#endif
 #include <QToolBar>
 #include <QGroupBox>
 #include <QDate>
@@ -80,10 +82,19 @@ static void *DoRequest( intf_thread_t *p_intf, vout_thread_t *p_vout,
 {
     return p_intf->p_sys->p_mi->requestVideo( p_vout, pi1, pi2, pi3, pi4 );
 }
+
+static void *DoNotEmbeddedRequest( intf_thread_t *p_intf, vout_thread_t *p_vout,
+                        int *pi1, int *pi2, unsigned int*pi3,unsigned int*pi4)
+{
+    p_intf->p_sys->p_mi->requestNotEmbeddedVideo( p_vout );
+    return NULL;
+}
+
 static void DoRelease( intf_thread_t *p_intf, void *p_win )
 {
     return p_intf->p_sys->p_mi->releaseVideo( p_win );
 }
+
 static int DoControl( intf_thread_t *p_intf, void *p_win, int i_q, va_list a )
 {
     return p_intf->p_sys->p_mi->controlVideo( p_win, i_q, a );
@@ -136,14 +147,14 @@ MainInterface::MainInterface( intf_thread_t *_p_intf ) : QVLCMW( _p_intf )
 
 #if 0
     /* Create a Dock to get the playlist */
-/*    dockPL = new QDockWidget( qtr( "Playlist" ), this );
+    dockPL = new QDockWidget( qtr( "Playlist" ), this );
     dockPL->setSizePolicy( QSizePolicy::Preferred,
                            QSizePolicy::Expanding );
     dockPL->setFeatures( QDockWidget::AllDockWidgetFeatures );
     dockPL->setAllowedAreas( Qt::LeftDockWidgetArea
                            | Qt::RightDockWidgetArea
                            | Qt::BottomDockWidgetArea );
-    dockPL->hide();*/
+    dockPL->hide();
 #endif
 
     /************
@@ -218,17 +229,14 @@ MainInterface::MainInterface( intf_thread_t *_p_intf ) : QVLCMW( _p_intf )
      **/
     var_Create( p_intf, "interaction", VLC_VAR_ADDRESS );
     var_AddCallback( p_intf, "interaction", InteractCallback, this );
-    p_intf->b_interaction = VLC_TRUE;
+    p_intf->b_interaction = true;
+
+    var_AddCallback( p_intf->p_libvlc, "intf-show", IntfShowCB, p_intf );
 
     /* Register callback for the intf-popupmenu variable */
-    playlist_t *p_playlist = (playlist_t *)vlc_object_find( p_intf,
-                                        VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
-    if( p_playlist != NULL )
-    {
-        var_AddCallback( p_playlist, "intf-popupmenu", PopupMenuCB, p_intf );
-        var_AddCallback( p_playlist, "intf-show", IntfShowCB, p_intf );
-        vlc_object_release( p_playlist );
-    }
+    playlist_t *p_playlist = pl_Yield( p_intf );
+    var_AddCallback( p_playlist, "intf-popupmenu", PopupMenuCB, p_intf );
+    pl_Release( p_intf );
 
     /* VideoWidget connect mess to avoid different threads speaking to each other */
     CONNECT( this, askReleaseVideo( void * ),
@@ -241,14 +249,16 @@ MainInterface::MainInterface( intf_thread_t *_p_intf ) : QVLCMW( _p_intf )
     CONNECT( controls, advancedControlsToggled( bool ),
              this, doComponentsUpdate() );
 
+    CONNECT( fullscreenControls, advancedControlsToggled( bool ),
+             this, doComponentsUpdate() );
+
+    CONNECT( THEMIM->getIM(), inputUnset(),
+            fullscreenControls, unregFullscreenCallback() );
+
+
     /* Size and placement of interface */
-    move( settings->value( "pos", QPoint( 0, 0 ) ).toPoint() );
+    QVLCTools::restoreWidgetPosition(settings,this,QSize(350,60));
 
-    QSize newSize = settings->value( "size", QSize( 350, 60 ) ).toSize();
-    if( newSize.isValid() )
-        resize( newSize );
-    else
-        msg_Warn( p_intf, "Invalid size in constructor" );
 
     /* Playlist */
     if( settings->value( "playlist-visible", 0 ).toInt() ) togglePlaylist();
@@ -272,32 +282,33 @@ MainInterface::~MainInterface()
 {
     msg_Dbg( p_intf, "Destroying the main interface" );
 
-    if( playlistWidget ) playlistWidget->savingSettings( settings );
+    if( playlistWidget )
+        playlistWidget->savingSettings( settings );
 
     settings->beginGroup( "MainWindow" );
-//    settings->setValue( "playlist-floats", (int)(dockPL->isFloating()) );
+
+    // settings->setValue( "playlist-floats", (int)(dockPL->isFloating()) );
     settings->setValue( "playlist-visible", (int)playlistVisible );
     settings->setValue( "adv-controls",
                         getControlsVisibilityStatus() & CONTROLS_ADVANCED );
-    settings->setValue( "pos", pos() );
-    settings->setValue( "size", size() );
+
+    if( !videoIsActive )
+        QVLCTools::saveWidgetPosition(settings, this);
+
     if( bgWidget )
         settings->setValue( "backgroundSize", bgWidget->size() );
 
     settings->endGroup();
     delete settings;
 
+    var_DelCallback( p_intf->p_libvlc, "intf-show", IntfShowCB, p_intf );
+
     /* Unregister callback for the intf-popupmenu variable */
-    playlist_t *p_playlist = (playlist_t *)vlc_object_find( p_intf,
-                                        VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
-    if( p_playlist != NULL )
-    {
-        var_DelCallback( p_playlist, "intf-popupmenu", PopupMenuCB, p_intf );
-        var_DelCallback( p_playlist, "intf-show", IntfShowCB, p_intf );
-        vlc_object_release( p_playlist );
-    }
+    playlist_t *p_playlist = pl_Yield( p_intf );
+    var_DelCallback( p_playlist, "intf-popupmenu", PopupMenuCB, p_intf );
+    pl_Release( p_intf );
 
-    p_intf->b_interaction = VLC_FALSE;
+    p_intf->b_interaction = false;
     var_DelCallback( p_intf, "interaction", InteractCallback, this );
 
     p_intf->pf_request_window = NULL;
@@ -323,7 +334,7 @@ inline void MainInterface::createStatusBar()
     nameLabel = new QLabel;
     nameLabel->setTextInteractionFlags( Qt::TextSelectableByMouse
                                       | Qt::TextSelectableByKeyboard );
-    speedLabel = new QLabel( "1.00x" );
+    speedLabel = new SpeedLabel( p_intf, "1.00x" );
     speedLabel->setContextMenuPolicy ( Qt::CustomContextMenu );
 
     /* Styling those labels */
@@ -401,6 +412,7 @@ void MainInterface::handleMainUi( QSettings *settings )
     /* Margins, spacing */
     main->setContentsMargins( 0, 0, 0, 0 );
     main->setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Maximum );
+    mainLayout->setSpacing( 0 );
     mainLayout->setMargin( 0 );
 
     /* Create the CONTROLS Widget */
@@ -409,8 +421,14 @@ void MainInterface::handleMainUi( QSettings *settings )
                    settings->value( "adv-controls", false ).toBool(),
                    config_GetInt( p_intf, "qt-blingbling" ) );
 
+    /* Create the FULLSCREEN CONTROLS Widget */
+    /* bool b_shiny = config_GetInt( p_intf, "qt-blingbling" ); */
+    fullscreenControls = new FullscreenControllerWidget( p_intf, this,
+                   settings->value( "adv-controls", false ).toBool(),
+                   config_GetInt( p_intf, "qt-blingbling" ) );
+
     /* Add the controls Widget to the main Widget */
-    mainLayout->insertWidget( 0, controls );
+    mainLayout->insertWidget( 0, controls, 0, Qt::AlignBottom );
 
     /* Create the Speed Control Widget */
     speedControl = new SpeedControlWidget( p_intf );
@@ -449,6 +467,10 @@ void MainInterface::handleMainUi( QSettings *settings )
         p_intf->pf_release_window  = ::DoRelease;
         p_intf->pf_control_window  = ::DoControl;
     }
+    else
+    {
+        p_intf->pf_request_window  = ::DoNotEmbeddedRequest;
+    }
 
     /* Finish the sizing */
     main->updateGeometry();
@@ -480,7 +502,7 @@ inline void MainInterface::askForPrivacy()
 
 int MainInterface::privacyDialog( QList<ConfigControl *> controls )
 {
-    QDialog *privacy = new QDialog( this );
+    QDialog *privacy = new QDialog();
 
     privacy->setWindowTitle( qtr( "Privacy and Network policies" ) );
 
@@ -536,6 +558,7 @@ int MainInterface::privacyDialog( QList<ConfigControl *> controls )
     CONFIG_GENERIC_NOBOOL( "qt-updates-notif", Bool ); line++;
     CONFIG_GENERIC_NOBOOL( "qt-updates-days", Integer ); line++;
 #endif
+
     QPushButton *ok = new QPushButton( qtr( "Ok" ) );
 
     gLayout->addWidget( ok, 2, 2 );
@@ -621,7 +644,7 @@ void MainInterface::debug()
 {
     msg_Dbg( p_intf, "size: %i - %i", size().height(), size().width() );
     msg_Dbg( p_intf, "sizeHint: %i - %i", sizeHint().height(), sizeHint().width() );
-    if( videoWidget->isVisible() )
+    if( videoWidget && videoWidget->isVisible() )
     {
 //    sleep( 10 );
     msg_Dbg( p_intf, "size: %i - %i", size().height(), size().width() );
@@ -699,10 +722,19 @@ void *MainInterface::requestVideo( vout_thread_t *p_nvout, int *pi_x,
 
         emit askVideoToResize( *pi_width, *pi_height );
         emit askUpdate();
+
+        fullscreenControls->regFullscreenCallback( p_nvout );
     }
     return ret;
 }
 
+/* function called from ::DoRequest in order to show a nice VideoWidget
+    at the good size */
+void MainInterface::requestNotEmbeddedVideo( vout_thread_t *p_nvout )
+{
+    fullscreenControls->regFullscreenCallback( p_nvout );
+}
+
 void MainInterface::releaseVideo( void *p_win )
 {
     emit askReleaseVideo( p_win );
@@ -899,8 +931,15 @@ void MainInterface::setName( QString name )
 
 void MainInterface::setStatus( int status )
 {
+    msg_Dbg( p_intf, "I was here, updating your status" );
     /* Forward the status to the controls to toggle Play/Pause */
     controls->setStatus( status );
+    fullscreenControls->setStatus( status );
+
+    controls->updateInput();
+    fullscreenControls->updateInput();
+    speedControl->setEnable( THEMIM->getIM()->hasInput() );
+
     /* And in the systray for the menu */
     if( sysTray )
         QVLCMenu::updateSystrayMenu( this, p_intf );
@@ -1078,7 +1117,7 @@ void MainInterface::dropEvent(QDropEvent *event)
         {
             if( input_AddSubtitles( THEMIM->getInput(),
                                     qtu( mimeData->urls()[0].toString() ),
-                                    VLC_TRUE ) )
+                                    true ) )
             {
                 event->acceptProposedAction();
                 return;
@@ -1086,12 +1125,13 @@ void MainInterface::dropEvent(QDropEvent *event)
         }
      }
      bool first = true;
-     foreach( QUrl url, mimeData->urls() ) {
-        QString s = url.toString();
+     foreach( QUrl url, mimeData->urls() )
+     {
+        QString s = url.toLocalFile();
         if( s.length() > 0 ) {
             playlist_Add( THEPL, qtu(s), NULL,
                           PLAYLIST_APPEND | (first ? PLAYLIST_GO:0),
-                          PLAYLIST_END, VLC_TRUE, VLC_FALSE );
+                          PLAYLIST_END, true, false );
             first = false;
         }
      }
@@ -1200,7 +1240,6 @@ static int PopupMenuCB( vlc_object_t *p_this, const char *psz_variable,
                         vlc_value_t old_val, vlc_value_t new_val, void *param )
 {
     intf_thread_t *p_intf = (intf_thread_t *)param;
-    msg_Dbg( p_this, "Menu Requested" ); // DEBUG to track the non disparition of the menu...
 
     if( p_intf->pf_show_dialog )
     {
@@ -1212,13 +1251,12 @@ static int PopupMenuCB( vlc_object_t *p_this, const char *psz_variable,
 }
 
 /*****************************************************************************
- * IntfShowCB: callback triggered by the intf-show playlist variable.
+ * IntfShowCB: callback triggered by the intf-show libvlc variable.
  *****************************************************************************/
 static int IntfShowCB( vlc_object_t *p_this, const char *psz_variable,
                        vlc_value_t old_val, vlc_value_t new_val, void *param )
 {
     intf_thread_t *p_intf = (intf_thread_t *)param;
-    msg_Dbg( p_this, "Intf Show Requested" ); // DEBUG to track the non disparition of the menu...
     p_intf->p_sys->p_mi->requestLayoutUpdate();
 
     return VLC_SUCCESS;