From 84eac14c642a217aa677e83b2f12ffee6d100367 Mon Sep 17 00:00:00 2001
From: Jean-Baptiste Kempf <jb@videolan.org>
Date: Mon, 3 Dec 2007 14:21:35 +0000
Subject: [PATCH] Qt4 - MainInterface cleaning, FIXME labelling,
 Simplification, put the delay of status Toolip to 3s, re-ask the privacy
 dialog if closed the previous time without a correct validation before.
 Commit from NYC/NY/Columbia University ;)

---
 modules/gui/qt4/Modules.am                    |  6 +-
 .../gui/qt4/components/interface_widgets.cpp  |  2 +
 .../gui/qt4/components/interface_widgets.hpp  |  2 +-
 .../components/{open.cpp => open_panels.cpp}  |  2 +-
 .../components/{open.hpp => open_panels.hpp}  |  0
 modules/gui/qt4/dialogs/open.cpp              |  1 -
 modules/gui/qt4/dialogs/open.hpp              |  2 +-
 modules/gui/qt4/dialogs_provider.cpp          |  1 +
 modules/gui/qt4/input_manager.cpp             | 19 +++--
 modules/gui/qt4/input_manager.hpp             | 18 ++--
 modules/gui/qt4/main_interface.cpp            | 82 ++++++++++---------
 modules/gui/qt4/main_interface.hpp            |  3 +-
 12 files changed, 73 insertions(+), 65 deletions(-)
 rename modules/gui/qt4/components/{open.cpp => open_panels.cpp} (99%)
 rename modules/gui/qt4/components/{open.hpp => open_panels.hpp} (100%)

diff --git a/modules/gui/qt4/Modules.am b/modules/gui/qt4/Modules.am
index 8a808765a4e1..aa66cc58631e 100644
--- a/modules/gui/qt4/Modules.am
+++ b/modules/gui/qt4/Modules.am
@@ -36,7 +36,7 @@ nodist_SOURCES_qt4 = \
 		components/preferences_widgets.moc.cpp \
 		components/complete_preferences.moc.cpp \
 		components/simple_preferences.moc.cpp \
-		components/open.moc.cpp \
+		components/open_panels.moc.cpp \
 		components/interface_widgets.moc.cpp \
 		components/playlist/panels.moc.cpp \
 		components/playlist/selector.moc.cpp \
@@ -102,7 +102,7 @@ SOURCES_qt4 = 	qt4.cpp \
 		components/preferences_widgets.cpp \
 		components/complete_preferences.cpp \
 		components/simple_preferences.cpp \
-		components/open.cpp \
+		components/open_panels.cpp \
 		components/interface_widgets.cpp \
 		components/playlist/standardpanel.cpp \
 		components/playlist/selector.cpp \
@@ -134,7 +134,7 @@ noinst_HEADERS = \
 	components/preferences_widgets.hpp \
 	components/complete_preferences.hpp \
 	components/simple_preferences.hpp \
-	components/open.hpp \
+	components/open_panels.hpp \
 	components/interface_widgets.hpp \
 	components/playlist/panels.hpp \
 	components/playlist/selector.hpp \
diff --git a/modules/gui/qt4/components/interface_widgets.cpp b/modules/gui/qt4/components/interface_widgets.cpp
index 6a558e96c337..22a05af5831e 100644
--- a/modules/gui/qt4/components/interface_widgets.cpp
+++ b/modules/gui/qt4/components/interface_widgets.cpp
@@ -339,6 +339,7 @@ void AdvControlsWidget::frame(){}
  * DA Control Widget !
  *****************************/
 ControlsWidget::ControlsWidget( intf_thread_t *_p_i,
+                                MainInterface *_p_mi,
                                 bool b_advControls,
                                 bool b_shiny ) :
                                 QFrame( NULL ), p_intf( _p_i )
@@ -491,6 +492,7 @@ ControlsWidget::ControlsWidget( intf_thread_t *_p_i,
     setupSmallButton( playlistButton );
     controlLayout->addWidget( playlistButton, 3, 11, Qt::AlignBottom );
     BUTTON_SET_IMG( playlistButton, "" , playlist.png, qtr( "Show playlist" ) );
+    CONNECT( playlistButton, clicked(), _p_mi, togglePlaylist() );
 
     /** extended Settings **/
     QPushButton *extSettingsButton = new QPushButton( "F" );
diff --git a/modules/gui/qt4/components/interface_widgets.hpp b/modules/gui/qt4/components/interface_widgets.hpp
index 258119071781..70a90a1d1eda 100644
--- a/modules/gui/qt4/components/interface_widgets.hpp
+++ b/modules/gui/qt4/components/interface_widgets.hpp
@@ -145,7 +145,7 @@ class ControlsWidget : public QFrame
     Q_OBJECT
 public:
     /* p_intf, advanced control visible or not, blingbling or not */
-    ControlsWidget( intf_thread_t *, bool, bool );
+    ControlsWidget( intf_thread_t *, MainInterface*, bool, bool );
 //    QSize sizeHint() const;
     virtual ~ControlsWidget();
 
diff --git a/modules/gui/qt4/components/open.cpp b/modules/gui/qt4/components/open_panels.cpp
similarity index 99%
rename from modules/gui/qt4/components/open.cpp
rename to modules/gui/qt4/components/open_panels.cpp
index cd496d1166e2..cff5e85f2254 100644
--- a/modules/gui/qt4/components/open.cpp
+++ b/modules/gui/qt4/components/open_panels.cpp
@@ -28,7 +28,7 @@
 
 
 #include "qt4.hpp"
-#include "components/open.hpp"
+#include "components/open_panels.hpp"
 #include "dialogs/open.hpp"
 #include "dialogs_provider.hpp"
 #include "components/preferences_widgets.hpp"
diff --git a/modules/gui/qt4/components/open.hpp b/modules/gui/qt4/components/open_panels.hpp
similarity index 100%
rename from modules/gui/qt4/components/open.hpp
rename to modules/gui/qt4/components/open_panels.hpp
diff --git a/modules/gui/qt4/dialogs/open.cpp b/modules/gui/qt4/dialogs/open.cpp
index 3449a820b156..8c3b105008dd 100644
--- a/modules/gui/qt4/dialogs/open.cpp
+++ b/modules/gui/qt4/dialogs/open.cpp
@@ -24,7 +24,6 @@
 #include "input_manager.hpp"
 
 #include "dialogs/open.hpp"
-#include "components/open.hpp"
 
 #include <QTabWidget>
 #include <QGridLayout>
diff --git a/modules/gui/qt4/dialogs/open.hpp b/modules/gui/qt4/dialogs/open.hpp
index 3e083c5a0ebf..782a60d3fa5a 100644
--- a/modules/gui/qt4/dialogs/open.hpp
+++ b/modules/gui/qt4/dialogs/open.hpp
@@ -29,7 +29,7 @@
 #include "util/qvlcframe.hpp"
 #include "dialogs_provider.hpp"
 #include "ui/open.h"
-#include "components/open.hpp"
+#include "components/open_panels.hpp"
 
 class QString;
 class QToolButton;
diff --git a/modules/gui/qt4/dialogs_provider.cpp b/modules/gui/qt4/dialogs_provider.cpp
index 1eb9ea778123..92d4c6f400a8 100644
--- a/modules/gui/qt4/dialogs_provider.cpp
+++ b/modules/gui/qt4/dialogs_provider.cpp
@@ -77,6 +77,7 @@ DialogsProvider::~DialogsProvider()
 void DialogsProvider::quit()
 {
     vlc_object_kill( p_intf );
+    QApplication::closeAllWindows();
     QApplication::quit();
 }
 
diff --git a/modules/gui/qt4/input_manager.cpp b/modules/gui/qt4/input_manager.cpp
index 39e9b2f3ce20..241999b111d9 100644
--- a/modules/gui/qt4/input_manager.cpp
+++ b/modules/gui/qt4/input_manager.cpp
@@ -79,6 +79,7 @@ void InputManager::delInput()
     }
 }
 
+//FIXME break that
 void InputManager::update()
 {
     /// \todo Emit the signals only if it changed
@@ -122,14 +123,15 @@ void InputManager::update()
     {
         val.i_int = 0;
         var_Change( p_input, "chapter", VLC_VAR_CHOICESCOUNT, &val, NULL );
-        if( val.i_int > 0 )
+        emit navigationChanged( (val.i_int > 0) ? 1 : 2 );
+        /*if( val.i_int > 0 )
         {
             emit navigationChanged( 1 ); // 1 = chapter, 2 = title, 0 = NO
         }
         else
         {
             emit navigationChanged( 2 );
-        }
+        }*/
     }
     else
     {
@@ -180,24 +182,23 @@ void InputManager::update()
 
 void InputManager::sliderUpdate( float new_pos )
 {
-    if( hasInput() )
-        var_SetFloat( p_input, "position", new_pos );
+    if( hasInput() ) var_SetFloat( p_input, "position", new_pos );
 }
 
 void InputManager::togglePlayPause()
 {
     vlc_value_t state;
     var_Get( p_input, "state", &state );
-    if( state.i_int != PAUSE_S )
-    {
+    state.i_int = ( ( state.i_int != PAUSE_S ) ? PAUSE_S : PLAYING_S );
+    /*{
         /* A stream is being played, pause it */
-        state.i_int = PAUSE_S;
+       /* state.i_int = PAUSE_S;
     }
     else
     {
         /* Stream is paused, resume it */
-        state.i_int = PLAYING_S;
-    }
+        /*state.i_int = PLAYING_S;
+    }*/
     var_Set( p_input, "state", state );
     emit statusChanged( state.i_int );
 }
diff --git a/modules/gui/qt4/input_manager.hpp b/modules/gui/qt4/input_manager.hpp
index 26f1ea90b909..fcfa4df5683f 100644
--- a/modules/gui/qt4/input_manager.hpp
+++ b/modules/gui/qt4/input_manager.hpp
@@ -42,11 +42,11 @@ public:
     bool hasVideo() { return b_has_video; }
     bool b_has_audio, b_has_video, b_had_audio, b_had_video;
 private:
-    intf_thread_t *p_intf;
+    intf_thread_t  *p_intf;
     input_thread_t *p_input;
-    int i_old_playing_status;
-    QString old_name;
-    int i_rate;
+    int             i_old_playing_status;
+    QString         old_name;
+    int             i_rate;
 public slots:
     void togglePlayPause();
     void update(); ///< Periodic updates
@@ -89,11 +89,12 @@ public:
     InputManager *getIM() { return im; };
 
 private:
-    InputManager *im;
-    intf_thread_t *p_intf;
-    input_thread_t *p_input;
-    static MainInputManager *instance;
     MainInputManager( intf_thread_t *);
+
+    InputManager            *im;
+    intf_thread_t           *p_intf;
+    input_thread_t          *p_input;
+    static MainInputManager *instance;
 public slots:
     void togglePlayPause();
     void stop();
@@ -105,5 +106,4 @@ signals:
     void inputChanged( input_thread_t *);
 };
 
-
 #endif
diff --git a/modules/gui/qt4/main_interface.cpp b/modules/gui/qt4/main_interface.cpp
index e81f36c5628e..de2635dc5192 100644
--- a/modules/gui/qt4/main_interface.cpp
+++ b/modules/gui/qt4/main_interface.cpp
@@ -84,9 +84,9 @@ static int DoControl( intf_thread_t *p_intf, void *p_win, int i_q, va_list a )
 MainInterface::MainInterface( intf_thread_t *_p_intf ) : QVLCMW( _p_intf )
 {
     /* Variables initialisation */
-    need_components_update = false;
+    // need_components_update = false;
     bgWidget = NULL; videoWidget = NULL; playlistWidget = NULL;
-    embeddedPlaylistWasActive = videoIsActive = false;
+    videoIsActive = false;
     input_name = "";
 
     /**
@@ -95,17 +95,18 @@ MainInterface::MainInterface( intf_thread_t *_p_intf ) : QVLCMW( _p_intf )
     if( config_GetInt( p_intf, "privacy-ask") )
     {
         QList<ConfigControl *> controls;
-        privacyDialog( controls );
-
-        QList<ConfigControl *>::Iterator i;
-        for(  i = controls.begin() ; i != controls.end() ; i++ )
+        if( privacyDialog( controls ) == QDialog::Accepted )
         {
-            ConfigControl *c = qobject_cast<ConfigControl *>(*i);
-            c->doApply( p_intf );
-        }
+            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 );
+            config_PutInt( p_intf,  "privacy-ask" , 0 );
+            config_SaveConfigFile( p_intf, NULL );
+        }
     }
 
     /**
@@ -122,15 +123,16 @@ MainInterface::MainInterface( intf_thread_t *_p_intf ) : QVLCMW( _p_intf )
 
     /* Set The Video In emebedded Mode or not */
     videoEmbeddedFlag = false;
-    if( config_GetInt( p_intf, "embedded-video" ) )
-        videoEmbeddedFlag = true;
+    if( config_GetInt( p_intf, "embedded-video" ) ) videoEmbeddedFlag = true;
 
+    /* Are we in the enhanced always-video mode or not ? */
     alwaysVideoFlag = false;
     if( videoEmbeddedFlag && config_GetInt( p_intf, "qt-always-video" ) )
         alwaysVideoFlag = true;
 
     /* Set the other interface settings */
-    visualSelectorEnabled = settings->value( "visual-selector", false ).toBool();
+    //FIXME I don't like that code
+    visualSelectorEnabled = settings->value( "visual-selector", false ).toBool(); 
     notificationEnabled = config_GetInt( p_intf, "qt-notification" )
                           ? true : false;
 
@@ -142,7 +144,8 @@ 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 );
+    dockPL->setSizePolicy( QSizePolicy::Preferred,
+                           QSizePolicy::MinimumExpanding );
     dockPL->setFeatures( QDockWidget::AllDockWidgetFeatures );
     dockPL->setAllowedAreas( Qt::LeftDockWidgetArea
                            | Qt::RightDockWidgetArea
@@ -216,7 +219,7 @@ MainInterface::MainInterface( intf_thread_t *_p_intf ) : QVLCMW( _p_intf )
     /* Init input manager */
     MainInputManager::getInstance( p_intf );
     ON_TIMEOUT( updateOnTimer() );
-    //ON_TIMEOUT( debug() );
+    //ON_TIMEOUT( debug() ):;
 
     /********************
      * Various CONNECTs *
@@ -281,7 +284,6 @@ MainInterface::MainInterface( intf_thread_t *_p_intf ) : QVLCMW( _p_intf )
     // DEBUG FIXME
     hide();
 
-
     updateGeometry();
     settings->endGroup();
 }
@@ -341,31 +343,28 @@ void MainInterface::setVLCWindowsTitle( QString aTitle )
 void MainInterface::handleMainUi( QSettings *settings )
 {
     /* Create the main Widget and the mainLayout */
-    QWidget *main = new QWidget( this );
-    mainLayout = new QVBoxLayout( main );
+    QWidget *main = new QWidget;
     setCentralWidget( main );
+    mainLayout = new QVBoxLayout( main );
 
     /* Margins, spacing */
     main->setContentsMargins( 0, 0, 0, 0 );
     mainLayout->setMargin( 0 );
 
     /* Create the CONTROLS Widget */
-    bool b_shiny = config_GetInt( p_intf, "qt-blingbling" );
-    controls = new ControlsWidget( p_intf,
+    /* bool b_shiny = config_GetInt( p_intf, "qt-blingbling" ); */
+    controls = new ControlsWidget( p_intf, this, 
                    settings->value( "adv-controls", false ).toBool(),
-                   b_shiny );
-
-    /* Configure the Controls, the playlist button doesn't trigger THEDP
-       but the toggle from this MainInterface */
-    BUTTONACT( controls->playlistButton, togglePlaylist() );
+                   config_GetInt( p_intf, "qt-blingbling" ) );
 
     /* Add the controls Widget to the main Widget */
-    mainLayout->addWidget( controls );
+    mainLayout->insertWidget( 0, controls );
 
     /* Create the Speed Control Widget */
     speedControl = new SpeedControlWidget( p_intf );
     speedControlMenu = new QMenu( this );
-    QWidgetAction *widgetAction = new QWidgetAction( this );
+
+    QWidgetAction *widgetAction = new QWidgetAction( speedControl );
     widgetAction->setDefaultWidget( speedControl );
     speedControlMenu->addAction( widgetAction );
 
@@ -382,7 +381,7 @@ void MainInterface::handleMainUi( QSettings *settings )
     {
         bgWidget = new BackgroundWidget( p_intf );
         bgWidget->widgetSize = settings->value( "backgroundSize",
-                                           QSize( 300, 300 ) ).toSize();
+                                           QSize( 300, 200 ) ).toSize();
         bgWidget->resize( bgWidget->widgetSize );
         bgWidget->updateGeometry();
         mainLayout->insertWidget( 0, bgWidget );
@@ -405,7 +404,7 @@ void MainInterface::handleMainUi( QSettings *settings )
     updateGeometry();
 }
 
-void MainInterface::privacyDialog( QList<ConfigControl *> controls )
+int MainInterface::privacyDialog( QList<ConfigControl *> controls )
 {
     QDialog *privacy = new QDialog( this );
 
@@ -467,7 +466,7 @@ void MainInterface::privacyDialog( QList<ConfigControl *> controls )
     gLayout->addWidget( ok, 2, 2 );
 
     CONNECT( ok, clicked(), privacy, accept() );
-    privacy->exec();
+    return privacy->exec();
 }
 
 //FIXME remove me at the end...
@@ -506,7 +505,7 @@ QSize MainInterface::sizeHint() const
 }
 
 #if 0
-/* This is dead code and need to be removed AT THE END */
+/* FIXME This is dead code and need to be removed AT THE END */
 void MainInterface::resizeEvent( QResizeEvent *e )
 {
     if( videoWidget )
@@ -765,7 +764,8 @@ void MainInterface::setDisplayPosition( float pos, int time, int length )
 
 void MainInterface::toggleTimeDisplay()
 {
-    b_remainingTime = ( b_remainingTime ? false : true );
+    b_remainingTime = !b_remainingTime;
+    //b_remainingTime = ( b_remainingTime ? false : true );
 }
 
 void MainInterface::setName( QString name )
@@ -795,14 +795,14 @@ void MainInterface::setRate( int rate )
     speedControl->updateControls( rate );
 }
 
+//FIXME Remove this function at the end...
 void MainInterface::updateOnTimer()
 {
-    /* \todo Make this event-driven */
-    if( intf_ShouldDie( p_intf ) )
+ /*   if( intf_ShouldDie( p_intf ) )
     {
         QApplication::closeAllWindows();
         QApplication::quit();
-    }
+    }*/
 #if 0
     if( need_components_update )
     {
@@ -843,6 +843,7 @@ void MainInterface::createSystray()
  */
 void MainInterface::toggleUpdateSystrayMenu()
 {
+    /* If hidden, show it */
     if( isHidden() )
     {
         show();
@@ -850,11 +851,13 @@ void MainInterface::toggleUpdateSystrayMenu()
     }
     else if( isMinimized() )
     {
+        /* Minimized */
         showNormal();
         activateWindow();
     }
     else
     {
+        /* Visible */
 #ifdef WIN32
         /* check if any visible window is above vlc in the z-order,
          * but ignore the ones always on top */
@@ -891,7 +894,7 @@ void MainInterface::handleSystrayClick(
         case QSystemTrayIcon::MiddleClick:
             sysTray->showMessage( qtr( "VLC media player" ),
                     qtr( "Control menu for the player" ),
-                    QSystemTrayIcon::Information, 4000 );
+                    QSystemTrayIcon::Information, 3000 );
             break;
     }
 }
@@ -912,7 +915,7 @@ void MainInterface::updateSystrayTooltipName( QString name )
         if( notificationEnabled && ( isHidden() || isMinimized() ) )
         {
             sysTray->showMessage( qtr( "VLC media player" ), name,
-                    QSystemTrayIcon::NoIcon, 4000 );
+                    QSystemTrayIcon::NoIcon, 3000 );
         }
     }
 }
@@ -926,6 +929,7 @@ void MainInterface::updateSystrayTooltipStatus( int i_status )
     switch( i_status )
     {
         case  0:
+        case  END_S:
             {
                 sysTray->setToolTip( qtr( "VLC media player" ) );
                 break;
@@ -1047,6 +1051,8 @@ void MainInterface::closeEvent( QCloseEvent *e )
 {
     hide();
     vlc_object_kill( p_intf );
+    QApplication::closeAllWindows();
+    QApplication::quit();
 }
 
 /*****************************************************************************
diff --git a/modules/gui/qt4/main_interface.hpp b/modules/gui/qt4/main_interface.hpp
index 43d62be2a151..00887a6e2f51 100644
--- a/modules/gui/qt4/main_interface.hpp
+++ b/modules/gui/qt4/main_interface.hpp
@@ -99,14 +99,13 @@ private:
     void handleSystray();
 
     void createSystray();
-    void privacyDialog( QList<ConfigControl *> controls );
+    int privacyDialog( QList<ConfigControl *> controls );
 
     /* Video */
     VideoWidget         *videoWidget;
     virtual void keyPressEvent( QKeyEvent *);
     virtual void wheelEvent( QWheelEvent * );
 
-    bool                 embeddedPlaylistWasActive;
     bool                 videoIsActive;
     QSize                savedVideoSize;
 
-- 
GitLab