]> git.sesse.net Git - vlc/blobdiff - modules/gui/qt4/input_manager.cpp
Trailing ;
[vlc] / modules / gui / qt4 / input_manager.cpp
index 1bc8602bae0e5d42999ee345946759f08030930e..2dc83e7fc057e506e5b73176a6dcf4834f3b45b5 100644 (file)
@@ -31,6 +31,8 @@
 
 #include <QApplication>
 
+#include <assert.h>
+
 static int ItemChanged( vlc_object_t *, const char *,
                         vlc_value_t, vlc_value_t, void * );
 static int PLItemChanged( vlc_object_t *, const char *,
@@ -61,7 +63,7 @@ InputManager::InputManager( QObject *parent, intf_thread_t *_p_intf) :
     b_video      = false;
     timeA        = 0;
     timeB        = 0;
-
+    f_cache      = -1.; /* impossible initial value, different from all */
 }
 
 InputManager::~InputManager()
@@ -141,7 +143,7 @@ void InputManager::customEvent( QEvent *event )
     int i_type = event->type();
     IMEvent *ple = static_cast<IMEvent *>(event);
 
-    if ( i_type != PositionUpdate_Type &&
+    assert( !( i_type != PositionUpdate_Type &&
          i_type != ItemChanged_Type &&
          i_type != ItemRateChanged_Type &&
          i_type != ItemTitleChanged_Type &&
@@ -156,8 +158,8 @@ void InputManager::customEvent( QEvent *event )
          i_type != SynchroChanged_Type &&
          i_type != CachingEvent_Type &&
          i_type != BookmarksChanged_Type &&
-         i_type != InterfaceAoutUpdate_Type )
-        return;
+         i_type != InterfaceAoutUpdate_Type &&
+         i_type != RecordingEvent_Type ) );
 
     if( !hasInput() ) return;
 
@@ -176,7 +178,8 @@ void InputManager::customEvent( QEvent *event )
           i_type != InfoChanged_Type &&
           i_type != SynchroChanged_Type &&
           i_type != BookmarksChanged_Type &&
-          i_type != InterfaceAoutUpdate_Type
+          i_type != InterfaceAoutUpdate_Type &&
+          i_type != RecordingEvent_Type
         )
         && ( i_input_id != ple->i_id ) )
         return;
@@ -199,7 +202,7 @@ void InputManager::customEvent( QEvent *event )
     case ItemChanged_Type:
         UpdateStatus();
         // UpdateName();
-        // UpdateArt();
+        UpdateArt();
         break;
     case ItemStateChanged_Type:
         // TODO: Fusion with above state
@@ -247,6 +250,9 @@ void InputManager::customEvent( QEvent *event )
     case InterfaceAoutUpdate_Type:
         UpdateAout();
         break;
+    case RecordingEvent_Type:
+        UpdateRecord();
+        break;
     default:
         msg_Warn( p_intf, "This shouldn't happen: %i", i_type );
     }
@@ -271,7 +277,7 @@ static int ItemChanged( vlc_object_t *p_this, const char *psz_var,
     InputManager *im = (InputManager*)param;
 
     IMEvent *event = new IMEvent( ItemChanged_Type, newval.i_int );
-    QApplication::postEvent( im, static_cast<QEvent*>(event) );
+    QApplication::postEvent( im, event );
     return VLC_SUCCESS;
 }
 
@@ -340,10 +346,8 @@ static int InputEvent( vlc_object_t *p_this, const char *,
         break;
 
     case INPUT_EVENT_RECORD:
-        /* This happens when a recording starts. What do we do then?
-           Display a red light? */
-        /* event = new IMEvent( RecordingEvent_Type, 0 );
-        break; */
+        event = new IMEvent( RecordingEvent_Type, 0 );
+        break;
 
     case INPUT_EVENT_PROGRAM:
         /* This is for PID changes */
@@ -359,7 +363,7 @@ static int InputEvent( vlc_object_t *p_this, const char *,
     }
 
     if( event )
-        QApplication::postEvent( im, static_cast<QEvent*>(event) );
+        QApplication::postEvent( im, event );
     return VLC_SUCCESS;
 }
 void InputManager::UpdatePosition()
@@ -384,10 +388,12 @@ void InputManager::UpdateNavigation()
     if( val.i_int > 0 )
     {
         emit titleChanged( true );
+        msg_Dbg( p_intf, "Title %i", val.i_int );
         /* p_input != NULL since val.i_int != 0 */
         val.i_int = 0;
         var_Change( p_input, "chapter", VLC_VAR_CHOICESCOUNT, &val, NULL );
         emit chapterChanged( (val.i_int > 0) );
+        msg_Dbg( p_intf, "Chapter: %i", val.i_int );
     }
     else
         emit titleChanged( false );
@@ -524,19 +530,48 @@ void InputManager::UpdateAout()
 }
 void InputManager::UpdateCaching()
 {
-    float f_newCache = var_GetFloat( p_input, "cache" );
+    if(!hasInput()) return;
+
+    float f_newCache = var_GetFloat ( p_input, "cache" );
     if( f_newCache != f_cache )
     {
-        f_newCache = f_cache;
+        f_cache = f_newCache;
         /* Update rate */
         emit cachingChanged( f_cache );
     }
 }
 
-inline void InputManager::UpdateArt()
+void InputManager::requestArtUpdate()
 {
+    if( hasInput() )
+    {
+        playlist_t *p_playlist = pl_Hold( p_intf );
+        playlist_AskForArtEnqueue( p_playlist, input_GetItem( p_input ), pl_Unlocked );
+        pl_Release( p_intf );
+    }
+    else
+    {
+        /* No input will signal the cover art to update,
+         * let's do it ourself */
+        UpdateArt();
+    }
+}
+
+void InputManager::UpdateArt()
+{
+    QString url;
+
+    if( hasInput() )
+    {
+        char *psz_art = input_item_GetArtURL( input_GetItem( p_input ) );
+        url = psz_art;
+        free( psz_art );
+    }
+    url = url.replace( "file://", QString("" ) );
+    /* Taglib seems to define a attachment://, It won't work yet */
+    url = url.replace( "attachment://", QString("" ) );
     /* Update Art meta */
-    emit artChanged( input_GetItem( p_input ) );
+    emit artChanged( url );
 }
 
 inline void InputManager::UpdateStats()
@@ -554,6 +589,14 @@ inline void InputManager::UpdateInfo()
     emit infoChanged( input_GetItem( p_input ) );
 }
 
+void InputManager::UpdateRecord()
+{
+    if( hasInput() )
+    {
+        emit recordingStateChanged( var_GetBool( p_input, "record" ) );
+    }
+}
+
 /* User update of the slider */
 void InputManager::sliderUpdate( float new_pos )
 {
@@ -796,8 +839,10 @@ MainInputManager::MainInputManager( intf_thread_t *_p_intf )
     /* emit check if playlist has allready started playing */
     vlc_value_t val;
     var_Change( THEPL, "playlist-current", VLC_VAR_CHOICESCOUNT, &val, NULL );
+
     IMEvent *event = new IMEvent( ItemChanged_Type, val.i_int);
-    QApplication::postEvent( this, static_cast<QEvent*>(event) );
+    customEvent( event );
+    delete event;
 }
 
 MainInputManager::~MainInputManager()
@@ -817,6 +862,16 @@ MainInputManager::~MainInputManager()
     var_DelCallback( THEPL, "playlist-current", PLItemChanged, this );
 }
 
+vout_thread_t* MainInputManager::getVout()
+{
+    return p_input ? input_GetVout( p_input ) : NULL;
+}
+
+aout_instance_t * MainInputManager::getAout()
+{
+    return p_input ? input_GetAout( p_input ) : NULL;
+}
+
 void MainInputManager::customEvent( QEvent *event )
 {
     int type = event->type();
@@ -901,7 +956,7 @@ static int PLItemChanged( vlc_object_t *p_this, const char *psz_var,
     MainInputManager *mim = (MainInputManager*)param;
 
     IMEvent *event = new IMEvent( ItemChanged_Type, newval.i_int );
-    QApplication::postEvent( mim, static_cast<QEvent*>(event) );
+    QApplication::postEvent( mim, event );
     return VLC_SUCCESS;
 }
 
@@ -911,7 +966,7 @@ static int VolumeChanged( vlc_object_t *p_this, const char *psz_var,
     MainInputManager *mim = (MainInputManager*)param;
 
     IMEvent *event = new IMEvent( VolumeChanged_Type, newval.i_int );
-    QApplication::postEvent( mim, static_cast<QEvent*>(event) );
+    QApplication::postEvent( mim, event );
     return VLC_SUCCESS;
 }