]> git.sesse.net Git - vlc/blobdiff - modules/gui/qt4/dialogs/mediainfo.cpp
Missing header (was included by ncurses.h in previous releases)
[vlc] / modules / gui / qt4 / dialogs / mediainfo.cpp
index b843d6b76768ea21ab66d63fecc1e1403bcf0027..619ab4712b6469b6ee4a5037af48c42e1165eca3 100644 (file)
@@ -21,6 +21,9 @@
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
  ******************************************************************************/
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
 
 #include "dialogs/mediainfo.hpp"
 #include "input_manager.hpp"
 #include <QLineEdit>
 #include <QLabel>
 
-static int ItemChanged( vlc_object_t *p_this, const char *psz_var,
-                        vlc_value_t oldval, vlc_value_t newval, void *param );
 MediaInfoDialog *MediaInfoDialog::instance = NULL;
 
+/* This Dialog has two main modes:
+    - General Mode that shows the current Played item, and the stats
+    - Single mode that shows the info on ONE SINGLE Item on the playlist
+   Please be Careful of not breaking one the modes behaviour... */
+
 MediaInfoDialog::MediaInfoDialog( intf_thread_t *_p_intf,
                                   input_item_t *_p_item,
                                   bool _mainInput,
@@ -42,9 +48,9 @@ MediaInfoDialog::MediaInfoDialog( intf_thread_t *_p_intf,
                                   QVLCFrame( _p_intf ), mainInput(_mainInput),
                                   stats( _stats )
 {
-    i_runs = 0;
     p_item = _p_item;
-    b_need_update = true;
+    b_cleaned = true;
+    i_runs = 0;
 
     setWindowTitle( qtr( "Media information" ) );
     resize( 600 , 480 );
@@ -65,7 +71,7 @@ MediaInfoDialog::MediaInfoDialog( intf_thread_t *_p_intf,
 
     QGridLayout *layout = new QGridLayout( this );
 
-    /* FIXME GNOME/KDE ? */
+    /* No need to use a QDialogButtonBox here */
     saveMetaButton = new QPushButton( qtr( "&Save Metadata" ) );
     saveMetaButton->hide();
     QPushButton *closeButton = new QPushButton( qtr( "&Close" ) );
@@ -91,25 +97,34 @@ MediaInfoDialog::MediaInfoDialog( intf_thread_t *_p_intf,
 
     CONNECT( IT, currentChanged( int ), this, updateButtons( int ) );
 
-    /* Create the main Update function with a time (150ms) */
-    if( mainInput ) {
-        ON_TIMEOUT( updateOnTimeOut() );
-        var_AddCallback( THEPL, "item-change", ItemChanged, this );
+    /* If using the General Mode */
+    if( !p_item )
+    {
+        msg_Dbg( p_intf, "Using a general windows" );
+        CONNECT( THEMIM, inputChanged( input_thread_t * ),
+                 this, update( input_thread_t * ) );
+
+        if( THEMIM->getInput() )
+            p_item = input_GetItem( THEMIM->getInput() );
     }
+
+    /* Call update by hand, so info is shown from current item too */
+    if( p_item )
+        update( p_item, true, true );
+
+    if( stats )
+        ON_TIMEOUT( updateOnTimeOut() );
 }
 
 MediaInfoDialog::~MediaInfoDialog()
 {
-    if( mainInput ) {
-        var_DelCallback( THEPL, "item-change", ItemChanged, this );
-    }
     writeSettings( "mediainfo" );
 }
 
 void MediaInfoDialog::showTab( int i_tab = 0 )
 {
-    this->show();
     IT->setCurrentIndex( i_tab );
+    show();
 }
 
 void MediaInfoDialog::showMetaSaveButton()
@@ -123,15 +138,27 @@ void MediaInfoDialog::saveMeta()
     saveMetaButton->hide();
 }
 
-static int ItemChanged( vlc_object_t *p_this, const char *psz_var,
-        vlc_value_t oldval, vlc_value_t newval, void *param )
+/* Function called on inputChanged-update*/
+void MediaInfoDialog::update( input_thread_t *p_input )
 {
-    MediaInfoDialog *p_d = (MediaInfoDialog *)param;
-    p_d->b_need_update = VLC_TRUE;
-    return VLC_SUCCESS;
+    if( !p_input || p_input->b_dead )
+    {
+        if( !b_cleaned )
+        {
+            clear();
+            b_cleaned = true;
+        }
+        return;
+    }
+
+    /* Launch the update in all the panels */
+    vlc_object_yield( p_input );
+
+    update( input_GetItem(p_input), true, true);
+
+    vlc_object_release( p_input );
 }
 
-/* Function called on TimeOut */
 void MediaInfoDialog::updateOnTimeOut()
 {
     /* Timer runs at 150 ms, dont' update more than 2 times per second */
@@ -140,19 +167,13 @@ void MediaInfoDialog::updateOnTimeOut()
 
     /* Get Input and clear if non-existant */
     input_thread_t *p_input = THEMIM->getInput();
-    if( !p_input || p_input->b_dead )
+
+    if( p_input && !p_input->b_dead )
     {
-        clear();
-        return;
+        vlc_object_yield( p_input );
+        update( input_GetItem(p_input), false, false);
+        vlc_object_release( p_input );
     }
-
-    /* Launch the update in all the panels */
-    vlc_object_yield( p_input );
-
-    update( input_GetItem(p_input), b_need_update, b_need_update );
-    b_need_update = false;
-
-    vlc_object_release( p_input );
 }
 
 void MediaInfoDialog::update( input_item_t *p_item,
@@ -176,12 +197,19 @@ void MediaInfoDialog::clear()
     MP->clear();
     EMP->clear();
     if( stats ) ISP->clear();
+    b_cleaned = true;
 }
 
 void MediaInfoDialog::close()
 {
-    this->toggleVisible();
+    toggleVisible();
 
+    /* if dialog is closed, revert editing if not saved */
+    if( MP->isInEditMode() )
+    {
+        MP->setEditMode( false );
+        updateButtons( 0 );
+    }
     if( mainInput == false ) {
         deleteLater();
     }