]> git.sesse.net Git - vlc/blobdiff - modules/gui/qt4/dialogs/mediainfo.cpp
Layout fixes in COPYING (and use spaces instead of tabs). Use a fixed width font...
[vlc] / modules / gui / qt4 / dialogs / mediainfo.cpp
index d41f46eeb02b1eb795e890f523ecce056b9bffae..a80b687c7f25d0f536edfe7dfed217b48410a42d 100644 (file)
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
  ******************************************************************************/
 
-#include <QTabWidget>
-#include <QGridLayout>
-
 #include "dialogs/mediainfo.hpp"
+#include "components/infopanels.hpp"
 #include "input_manager.hpp"
 #include "dialogs_provider.hpp"
-#include "util/qvlcframe.hpp"
-#include "components/infopanels.hpp"
-#include "qt4.hpp"
 
+#include <QTabWidget>
+#include <QGridLayout>
+#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 );
@@ -44,12 +43,12 @@ MediaInfoDialog::MediaInfoDialog( intf_thread_t *_p_intf, bool _mainInput,
 {
     i_runs = 0;
     p_input = NULL;
+    b_need_update = true;
 
     setWindowTitle( qtr( "Media information" ) );
-    resize( 600 , 450 );
-
-    QGridLayout *layout = new QGridLayout( this );
+    resize( 600 , 480 );
 
+    /* TabWidgets and Tabs creation */
     IT = new QTabWidget;
     MP = new MetaPanel( IT, p_intf );
     IT->addTab( MP, qtr( "&General" ) );
@@ -60,17 +59,38 @@ MediaInfoDialog::MediaInfoDialog( intf_thread_t *_p_intf, bool _mainInput,
     if( stats )
     {
         ISP = new InputStatsPanel( IT, p_intf );
-        IT->addTab( ISP, qtr( "&Stats" ) );
+        IT->addTab( ISP, qtr( "&Statistics" ) );
     }
 
+    QGridLayout *layout = new QGridLayout( this );
+
+    /* FIXME GNOME/KDE ? */
+    saveMetaButton = new QPushButton( qtr( "&Save Metadata" ) );
+    saveMetaButton->hide();
     QPushButton *closeButton = new QPushButton( qtr( "&Close" ) );
     closeButton->setDefault( true );
 
-    layout->addWidget( IT, 0, 0, 1, 3 );
-    layout->addWidget( closeButton, 1, 2 );
+    uriLine = new QLineEdit;
+    QLabel *uriLabel = new QLabel( qtr( "Location :" ) );
+
+    layout->addWidget( IT, 0, 0, 1, 8 );
+    layout->addWidget( uriLabel, 1, 0, 1, 1 );
+    layout->addWidget( uriLine, 1, 1, 1, 7 );
+    layout->addWidget( saveMetaButton, 2, 6 );
+    layout->addWidget( closeButton, 2, 7 );
 
     BUTTONACT( closeButton, close() );
 
+    /* The tabs buttons are shown in the main dialog for space and cosmetics */
+    CONNECT( saveMetaButton, clicked(), this, saveMeta() );
+
+    /* Let the MetaData Panel update the URI */
+    CONNECT( MP, uriSet( QString ), uriLine, setText( QString ) );
+    CONNECT( MP, editing(), this, editMeta() );
+
+    CONNECT( IT, currentChanged( int ), this, updateButtons( int ) );
+
+    /* Create the main Update function with a time (150ms) */
     if( mainInput ) {
         ON_TIMEOUT( update() );
         var_AddCallback( THEPL, "item-change", ItemChanged, this );
@@ -85,34 +105,51 @@ MediaInfoDialog::~MediaInfoDialog()
     writeSettings( "mediainfo" );
 }
 
-void MediaInfoDialog::showTab(int i_tab=0)
+void MediaInfoDialog::showTab( int i_tab = 0 )
 {
     this->show();
     IT->setCurrentIndex( i_tab );
 }
 
+void MediaInfoDialog::editMeta()
+{
+    saveMetaButton->show();
+}
+
+void MediaInfoDialog::saveMeta()
+{
+    MP->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 )
 {
     MediaInfoDialog *p_d = (MediaInfoDialog *)param;
-    p_d->need_update = VLC_TRUE;
+    p_d->b_need_update = VLC_TRUE;
     return VLC_SUCCESS;
 }
 
-void MediaInfoDialog::setInput(input_item_t *p_input)
+void MediaInfoDialog::setInput( input_item_t *p_input )
 {
     clear();
-    vlc_mutex_lock( &p_input->lock );
     update( p_input, true, true );
-    vlc_mutex_unlock( &p_input->lock );
+    /* if info is from current input, don't set default to edit, if user opens
+     * some other item, se default to edit, so it won't be updated to current item metas
+     *
+     * This really doesn't seem as clean solution as it could be
+     */
+    input_thread_t *p_current =
+                     MainInputManager::getInstance( p_intf )->getInput();
+    MP->setEditMode( ( !p_current || p_current->b_dead || input_GetItem( p_current ) != p_input ) ?
+                            true: false );
 }
 
 void MediaInfoDialog::update()
 {
-    msg_Dbg( p_intf, "updating MetaData Info" );
     /* Timer runs at 150 ms, dont' update more than 2 times per second */
-    if( i_runs % 3 != 0 ) return;
     i_runs++;
+    if( i_runs % 4 != 0 ) return;
 
     /* Get Input and clear if non-existant */
     input_thread_t *p_input =
@@ -124,18 +161,18 @@ void MediaInfoDialog::update()
     }
 
     vlc_object_yield( p_input );
-    vlc_mutex_lock( &input_GetItem(p_input)->lock );
 
-    update( input_GetItem(p_input), need_update, need_update );
-    need_update = false;
+    update( input_GetItem(p_input), b_need_update, b_need_update );
+    b_need_update = false;
 
-    vlc_mutex_unlock( &input_GetItem(p_input)->lock );
     vlc_object_release( p_input );
 }
 
-void MediaInfoDialog::update( input_item_t *p_item, bool update_info,
-                                                    bool update_meta )
+void MediaInfoDialog::update( input_item_t *p_item,
+                                                 bool update_info,
+                                                 bool update_meta )
 {
+    MP->setInput( p_item );
     if( update_info )
         IP->update( p_item );
     if( update_meta )
@@ -162,4 +199,13 @@ void MediaInfoDialog::close()
     if( mainInput == false ) {
         deleteLater();
     }
+    MP->setEditMode( false );
+}
+
+void MediaInfoDialog::updateButtons( int i_tab )
+{
+    if( MP->isInEditMode() && i_tab == 0 )
+        saveMetaButton->show();
+    else
+        saveMetaButton->hide();
 }