]> git.sesse.net Git - vlc/blobdiff - modules/gui/qt4/main_interface.cpp
Qt4 - trailing spaces... Post-commit script ?
[vlc] / modules / gui / qt4 / main_interface.cpp
index 197f538309f029a47f7cf2073506f250312f6e7d..8261c9496772712b29625ca2be5f3fd9abeb6476 100644 (file)
@@ -91,25 +91,8 @@ MainInterface::MainInterface( intf_thread_t *_p_intf ) : QVLCMW( _p_intf )
     videoIsActive = false;
     input_name = "";
 
-    /**
-     * Ask for the network policy on FIRST STARTUP
-     **/
-    if( config_GetInt( p_intf, "privacy-ask") )
-    {
-        QList<ConfigControl *> controls;
-        if( privacyDialog( controls ) == QDialog::Accepted )
-        {
-            QList<ConfigControl *>::Iterator i;
-            for(  i = controls.begin() ; i != controls.end() ; i++ )
-            {
-                ConfigControl *c = qobject_cast<ConfigControl *>(*i);
-                c->doApply( p_intf );
-            }
-
-            config_PutInt( p_intf,  "privacy-ask" , 0 );
-            config_SaveConfigFile( p_intf, NULL );
-        }
-    }
+    /* Ask for privacy */
+    privacy();
 
     /**
      *  Configuration and settings
@@ -147,11 +130,12 @@ MainInterface::MainInterface( intf_thread_t *_p_intf ) : QVLCMW( _p_intf )
     /* Create a Dock to get the playlist */
     dockPL = new QDockWidget( qtr( "Playlist" ), this );
     dockPL->setSizePolicy( QSizePolicy::Preferred,
-                           QSizePolicy::MinimumExpanding );
+                           QSizePolicy::Expanding );
     dockPL->setFeatures( QDockWidget::AllDockWidgetFeatures );
     dockPL->setAllowedAreas( Qt::LeftDockWidgetArea
                            | Qt::RightDockWidgetArea
                            | Qt::BottomDockWidgetArea );
+    dockPL->hide();
 
     /************
      * Menu Bar
@@ -161,7 +145,6 @@ MainInterface::MainInterface( intf_thread_t *_p_intf ) : QVLCMW( _p_intf )
     /****************
      *  Status Bar  *
      ****************/
-
     /* Widgets Creation*/
     b_remainingTime = false;
     timeLabel = new TimeLabel;
@@ -218,24 +201,26 @@ MainInterface::MainInterface( intf_thread_t *_p_intf ) : QVLCMW( _p_intf )
     if( config_GetInt( p_intf, "qt-minimal-view" ) )
         toggleMinimalView();
 
-    /* Init input manager */
+    /********************
+     * Input Manager    *
+     ********************/
     MainInputManager::getInstance( p_intf );
-    ON_TIMEOUT( updateOnTimer() );
-    //ON_TIMEOUT( debug() ):;
 
     /********************
      * Various CONNECTs *
      ********************/
-
     /* Connect the input manager to the GUI elements it manages */
+
     /* It is also connected to the control->slider, see the ControlsWidget */
     CONNECT( THEMIM->getIM(), positionUpdated( float, int, int ),
              this, setDisplayPosition( float, int, int ) );
-
+    /* Change the SpeedRate in the Status */
     CONNECT( THEMIM->getIM(), rateChanged( int ), this, setRate( int ) );
 
     /**
      * Connects on nameChanged()
+     * Those connects are not merged because different options can trigger
+     * them down.
      */
     /* Naming in the controller statusbar */
     CONNECT( THEMIM->getIM(), nameChanged( QString ), this,
@@ -253,7 +238,9 @@ MainInterface::MainInterface( intf_thread_t *_p_intf ) : QVLCMW( _p_intf )
              setVLCWindowsTitle( QString ) );
     }
 
-    /** CONNECTS on PLAY_STATUS **/
+    /**
+     * CONNECTS on PLAY_STATUS
+     **/
     /* Status on the main controller */
     CONNECT( THEMIM->getIM(), statusChanged( int ), this, setStatus( int ) );
     /* and in the systray */
@@ -263,6 +250,11 @@ MainInterface::MainInterface( intf_thread_t *_p_intf ) : QVLCMW( _p_intf )
                  updateSystrayTooltipStatus( int ) );
     }
 
+    /** OnTimeOut **/
+    // TODO
+    ON_TIMEOUT( updateOnTimer() );
+    //ON_TIMEOUT( debug() );
+
     /**
      * Callbacks
      **/
@@ -280,12 +272,17 @@ MainInterface::MainInterface( intf_thread_t *_p_intf ) : QVLCMW( _p_intf )
         vlc_object_release( p_playlist );
     }
 
+    /* VideoWidget connect mess to avoid different threads speaking to each other */
     CONNECT( this, askReleaseVideo( void * ), this, releaseVideoSlot( void * ) );
+    CONNECT( this, askVideoToResize( unsigned int, unsigned int ),
+             videoWidget, SetSizing( unsigned int, unsigned int ) );
+    CONNECT( this, askUpdate(), this, doComponentsUpdate() );
 
     CONNECT( dockPL, topLevelChanged( bool ), this, doComponentsUpdate() );
-    CONNECT( controls, advancedControlsToggled( bool ), 
+    CONNECT( controls, advancedControlsToggled( bool ),
              this, doComponentsUpdate() );
 
+    resize( settings->value( "size", QSize( 350, 60 ) ).toSize() );
     updateGeometry();
     settings->endGroup();
 }
@@ -298,9 +295,10 @@ MainInterface::~MainInterface()
 
     settings->beginGroup( "MainWindow" );
     settings->setValue( "playlist-floats", dockPL->isFloating() );
-    settings->setValue( "adv-controls", 
+    settings->setValue( "adv-controls",
                         getControlsVisibilityStatus() & CONTROLS_ADVANCED );
     settings->setValue( "pos", pos() );
+    settings->setValue( "size", size() );
 
     settings->endGroup();
     delete settings;
@@ -352,6 +350,7 @@ void MainInterface::handleMainUi( QSettings *settings )
 
     /* Margins, spacing */
     main->setContentsMargins( 0, 0, 0, 0 );
+   // main->setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Maximum );
     mainLayout->setMargin( 0 );
 
     /* Create the CONTROLS Widget */
@@ -394,7 +393,8 @@ void MainInterface::handleMainUi( QSettings *settings )
     if( videoEmbeddedFlag )
     {
         videoWidget = new VideoWidget( p_intf );
-        videoWidget->widgetSize = QSize( 1, 1 );
+        //videoWidget->widgetSize = QSize( 16, 16 );
+        //videoWidget->hide();
         //videoWidget->resize( videoWidget->widgetSize );
         mainLayout->insertWidget( 0, videoWidget );
 
@@ -407,6 +407,29 @@ void MainInterface::handleMainUi( QSettings *settings )
     updateGeometry();
 }
 
+inline void MainInterface::privacy()
+{
+    /**
+     * Ask for the network policy on FIRST STARTUP
+     **/
+    if( config_GetInt( p_intf, "privacy-ask") )
+    {
+        QList<ConfigControl *> controls;
+        if( privacyDialog( controls ) == QDialog::Accepted )
+        {
+            QList<ConfigControl *>::Iterator i;
+            for(  i = controls.begin() ; i != controls.end() ; i++ )
+            {
+                ConfigControl *c = qobject_cast<ConfigControl *>(*i);
+                c->doApply( p_intf );
+            }
+
+            config_PutInt( p_intf,  "privacy-ask" , 0 );
+            config_SaveConfigFile( p_intf, NULL );
+        }
+    }
+}
+
 int MainInterface::privacyDialog( QList<ConfigControl *> controls )
 {
     QDialog *privacy = new QDialog( this );
@@ -493,18 +516,31 @@ void MainInterface::debug()
 */
 QSize MainInterface::sizeHint() const
 {
-    QSize tempSize = controls->sizeHint() +
-        QSize( 100, menuBar()->size().height() + statusBar()->size().height() );
+    int nwidth = controls->sizeHint().width();
+    int nheight = controls->sizeHint().height();
+                + menuBar()->size().height()
+                + statusBar()->size().height();
 
+    msg_Dbg( p_intf, "1 %i %i", nheight, nwidth );
     if( VISIBLE( bgWidget ) )
-        tempSize += bgWidget->sizeHint();
+    {
+        nheight += bgWidget->size().height();
+        nwidth  = bgWidget->size().width();
+    }
     else if( videoIsActive )
-        tempSize += videoWidget->size();
-
+    {
+        nheight += videoWidget->size().height();
+        nwidth  = videoWidget->size().width();
+        msg_Dbg( p_intf, "2 %i %i", nheight, nwidth );
+    }
     if( !dockPL->isFloating() && dockPL->widget() )
-        tempSize += dockPL->widget()->size();
-
-    return tempSize;
+    {
+        nheight += dockPL->size().height();
+        nwidth = MAX( nwidth, dockPL->size().width() );
+        msg_Dbg( p_intf, "3 %i %i", nheight, nwidth );
+    }
+    msg_Dbg( p_intf, "4 %i %i", nheight, nwidth );
+    return QSize( nwidth, nheight );
 }
 
 #if 0
@@ -556,36 +592,41 @@ private:
     bool onTop;
 };
 
+/* function called from ::DoRequest in order to show a nice VideoWidget
+    at the good size */
 void *MainInterface::requestVideo( vout_thread_t *p_nvout, int *pi_x,
                                    int *pi_y, unsigned int *pi_width,
                                    unsigned int *pi_height )
 {
+    bool bgWasVisible = false;
+
+    /* Request the videoWidget */
     void *ret = videoWidget->request( p_nvout,pi_x, pi_y, pi_width, pi_height );
-    if( ret )
+    if( ret ) /* The videoWidget is available */
     {
-        videoIsActive = true;
-        bool bgWasVisible = false;
-
-        /* Did we have a bg ? */
+        /* Did we have a bg ? Hide it! */
         if( VISIBLE( bgWidget) )
         {
             bgWasVisible = true;
             emit askBgWidgetToToggle();
         }
 
-        if( THEMIM->getIM()->hasVideo() || !bgWasVisible )
+        /*if( THEMIM->getIM()->hasVideo() || !bgWasVisible )
         {
             videoWidget->widgetSize = QSize( *pi_width, *pi_height );
         }
         else /* Background widget available, use its size */
-        {
+        /*{
             /* Ok, our visualizations are bad, so don't do this for the moment
              * use the requested size anyway */
             // videoWidget->widgetSize = bgWidget->widgeTSize;
-            videoWidget->widgetSize = QSize( *pi_width, *pi_height );
-        }
-        videoWidget->updateGeometry(); // Needed for deinterlace
-        updateGeometry();
+          /*  videoWidget->widgetSize = QSize( *pi_width, *pi_height );
+        }*/
+
+        videoIsActive = true;
+
+        emit askVideoToResize( *pi_width, *pi_height );
+        emit askUpdate();
     }
     return ret;
 }
@@ -600,11 +641,11 @@ void MainInterface::releaseVideoSlot( void *p_win )
     videoWidget->release( p_win );
     videoWidget->hide();
 
-    if( bgWidget )
+    if( bgWidget )// WORONG
         bgWidget->show();
 
     videoIsActive = false;
-    updateGeometry();
+    emit askUpdate();
 }
 
 int MainInterface::controlVideo( void *p_window, int i_query, va_list args )
@@ -625,8 +666,8 @@ int MainInterface::controlVideo( void *p_window, int i_query, va_list args )
         {
             unsigned int i_width  = va_arg( args, unsigned int );
             unsigned int i_height = va_arg( args, unsigned int );
-            videoWidget->widgetSize = QSize( i_width, i_height );
-            videoWidget->updateGeometry();
+            emit askVideoToResize( i_width, i_height );
+            emit askUpdate();
             updateGeometry();
             i_ret = VLC_SUCCESS;
             break;
@@ -704,7 +745,9 @@ void MainInterface::toggleMinimalView()
 /* Well, could it, actually ? Probably dangerous ... */
 void MainInterface::doComponentsUpdate()
 {
+    msg_Dbg( p_intf, "coi " );
     updateGeometry();
+    resize( sizeHint() );
 }
 
 /* toggling advanced controls buttons */
@@ -764,7 +807,6 @@ void MainInterface::setDisplayPosition( float pos, int time, int length )
 void MainInterface::toggleTimeDisplay()
 {
     b_remainingTime = !b_remainingTime;
-    //b_remainingTime = ( b_remainingTime ? false : true );
 }
 
 void MainInterface::setName( QString name )