Implement input position control
authorRafaël Carré <funman@videolan.org>
Tue, 21 Nov 2006 14:31:01 +0000 (14:31 +0000)
committerRafaël Carré <funman@videolan.org>
Tue, 21 Nov 2006 14:31:01 +0000 (14:31 +0000)
extras/dbus-vlc.glade
extras/dbus-vlc.py
modules/control/dbus.c
modules/control/dbus.h

index 1f1ea20..45c9b25 100644 (file)
@@ -1,6 +1,6 @@
 <?xml version="1.0" encoding="UTF-8" standalone="no"?>
 <!DOCTYPE glade-interface SYSTEM "glade-2.0.dtd">
-<!--Generated with glade3 3.0.2 on Tue Nov 21 12:55:24 2006 by fun@zod-->
+<!--Generated with glade3 3.0.2 on Tue Nov 21 15:28:41 2006 by fun@zod-->
 <glade-interface>
   <widget class="GtkWindow" id="window1">
     <property name="resizable">False</property>
         <child>
           <widget class="GtkExpander" id="expander2">
             <property name="visible">True</property>
-            <property name="expanded">True</property>
             <property name="tooltip" translatable="yes">Show more options</property>
             <child>
               <widget class="GtkVBox" id="vbox2">
                   <widget class="GtkHBox" id="hbox2">
                     <property name="visible">True</property>
                     <child>
-                      <widget class="GtkHScale" id="times">
+                      <widget class="GtkHScale" id="time_s">
                         <property name="width_request">107</property>
                         <property name="height_request">20</property>
                         <property name="visible">True</property>
                         <property name="value_pos">GTK_POS_RIGHT</property>
                       </widget>
                     </child>
-                    <child>
-                      <widget class="GtkLabel" id="timel">
-                        <property name="width_request">30</property>
-                        <property name="height_request">20</property>
-                        <property name="visible">True</property>
-                        <property name="label" translatable="yes">time</property>
-                      </widget>
-                      <packing>
-                        <property name="position">1</property>
-                      </packing>
-                    </child>
                     <child>
                       <widget class="GtkSpinButton" id="vol">
                         <property name="width_request">42</property>
                         <property name="height_request">20</property>
                         <property name="visible">True</property>
                         <property name="can_focus">True</property>
+                        <property name="editable">False</property>
                         <property name="adjustment">100 0 100 1 10 10</property>
                         <property name="snap_to_ticks">True</property>
                         <property name="numeric">True</property>
-                        <property name="wrap">True</property>
+                        <property name="update_policy">GTK_UPDATE_IF_VALID</property>
                       </widget>
                       <packing>
                         <property name="expand">False</property>
-                        <property name="position">2</property>
+                        <property name="position">1</property>
                       </packing>
                     </child>
                   </widget>
index 23f8f24..2d2c603 100755 (executable)
@@ -25,9 +25,11 @@ import dbus.glib
 import gtk
 import gtk.glade
 import egg.trayicon
+import gobject
 import os
 
 global position
+global timer
 
 def itemchange_handler(item):
     l_item.set_text(item)
@@ -67,11 +69,14 @@ def update(widget):
     GetPlayStatus(0)
 
 def GetPlayStatus(widget):
+    global timer
     status = str(interface.GetPlayStatus())
     if status == "playing":
         img_bt_toggle.set_from_stock("gtk-media-pause", gtk.ICON_SIZE_SMALL_TOOLBAR)
+        timer = gobject.timeout_add( 2000, timeset)
     else:
         img_bt_toggle.set_from_stock("gtk-media-play", gtk.ICON_SIZE_SMALL_TOOLBAR)
+        gobject.timeout_remove(timer)
 
 def Quit(widget):
     interface.Quit()
@@ -84,8 +89,15 @@ def TogglePause(widget):
         img_bt_toggle.set_from_stock(gtk.STOCK_MEDIA_PLAY, gtk.ICON_SIZE_SMALL_TOOLBAR)
     update(0)
 
-def volchange(widget):
-    interface.VolumeSet(vol.get_value_as_int())
+def volchange(widget, data):
+    interface.VolumeSet(vol.get_value_as_int(), reply_handler=(lambda: None), error_handler=(lambda: None))
+
+def timechange(widget, x=None, y=None):
+    interface.PositionSet(time_s.get_value() * 10, reply_handler=(lambda: None), error_handler=(lambda: None))
+
+def timeset():
+    time_s.set_value(interface.PositionGet() / 10)
+    return True
 
 def expander(widget):
     if exp.get_expanded() == False:
@@ -138,6 +150,8 @@ menu        = xml.get_widget('menu1')
 menuitem    = xml.get_widget('menuquit')
 vlcicon     = xml.get_widget('eventicon')
 vol         = xml.get_widget('vol')
+time_s      = xml.get_widget('time_s')
+time_l      = xml.get_widget('time_l')
 
 window.connect('delete_event',  delete_event)
 window.connect('destroy',       destroy)
@@ -153,13 +167,10 @@ eventbox.add(image)
 image.set_from_icon_name("vlc", gtk.ICON_SIZE_MENU)
 tray.show_all()
 
-def fuck():
-    return
-
 def icon_clicked(widget, event):
     update(0)
 
-menu.attach_to_widget(eventbox, fuck)
+menu.attach_to_widget(eventbox,None)
 
 bt_close.connect('clicked',     destroy)
 bt_quit.connect('clicked',      Quit)
@@ -172,7 +183,11 @@ exp.connect('activate',         expander)
 menuitem.connect('activate',    destroy)
 vlcicon.set_events(gtk.gdk.BUTTON_PRESS_MASK)
 vlcicon.connect('button_press_event', icon_clicked)
-vol.connect('value-changed',    volchange)
+vol.connect('change-value',     volchange)
+vol.connect('scroll-event',     volchange)
+time_s.connect('adjust-bounds', timechange)
+
+time_s.set_update_policy(gtk.UPDATE_DISCONTINUOUS)
 
 library = "/media/mp3"
 
index c1b7cfe..dad21f5 100644 (file)
@@ -110,8 +110,63 @@ DBUS_METHOD( Quit )
     REPLY_SEND;
 }
 
+DBUS_METHOD( PositionGet )
+{ /* returns position as an int in the range [0;1000] */
+    REPLY_INIT;
+    OUT_ARGUMENTS;
+    vlc_value_t position;
+    dbus_uint16_t i_pos;
+
+    playlist_t *p_playlist = pl_Yield( ((vlc_object_t*) p_this) );
+    input_thread_t *p_input = p_playlist->p_input;
+
+    if( !p_input )
+        i_pos = 0;
+    else
+    {
+        var_Get( p_input, "position", &position );
+        i_pos = position.f_float * 1000 ;
+    }
+    ADD_UINT16( &i_pos );
+    pl_Release( ((vlc_object_t*) p_this) );
+    REPLY_SEND;
+}
+
+DBUS_METHOD( PositionSet )
+{ /* set position from an int in the range [0;1000] */
+
+    REPLY_INIT;
+    vlc_value_t position;
+    dbus_uint16_t i_pos;
+
+    DBusError error;
+    dbus_error_init( &error );
+
+    dbus_message_get_args( p_from, &error,
+            DBUS_TYPE_UINT16, &i_pos,
+            DBUS_TYPE_INVALID );
+
+    if( dbus_error_is_set( &error ) )
+    {
+        msg_Err( (vlc_object_t*) p_this, "D-Bus message reading : %s\n",
+                error.message );
+        dbus_error_free( &error );
+        return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+    }
+    playlist_t *p_playlist = pl_Yield( ((vlc_object_t*) p_this) );
+    input_thread_t *p_input = p_playlist->p_input;
+
+    if( p_input )
+    {
+        position.f_float = ((float)i_pos) / 1000;
+        var_Set( p_input, "position", position );
+    }
+    pl_Release( ((vlc_object_t*) p_this) );
+    REPLY_SEND;
+}
+
 DBUS_METHOD( VolumeGet )
-{ /* get volume in percentage */
+{ /* returns volume in percentage */
     REPLY_INIT;
     OUT_ARGUMENTS;
     dbus_uint16_t i_vol;
@@ -332,6 +387,8 @@ DBUS_METHOD( handle_messages )
     METHOD_FUNC( "Stop",            Stop );
     METHOD_FUNC( "VolumeSet",       VolumeSet );
     METHOD_FUNC( "VolumeGet",       VolumeGet );
+    METHOD_FUNC( "PositionSet",     PositionSet );
+    METHOD_FUNC( "PositionGet",     PositionGet );
 
     return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
 }
index 581448f..55ea47b 100644 (file)
@@ -68,6 +68,7 @@
 #define ADD_BOOL( b ) DBUS_ADD( DBUS_TYPE_BOOLEAN, b )
 #define ADD_UINT32( i ) DBUS_ADD( DBUS_TYPE_UINT32, i )
 #define ADD_UINT16( i ) DBUS_ADD( DBUS_TYPE_UINT16, i )
+#define ADD_BYTE( b ) DBUS_ADD( DBUS_TYPE_BYTE, b )
 
 /* XML data to answer org.freedesktop.DBus.Introspectable.Introspect requests */
 
@@ -110,6 +111,12 @@ const char* psz_introspection_xml_data =
 "    <method name=\"VolumeGet\">\n"
 "      <arg type=\"q\" direction=\"out\" />\n"
 "    </method>\n"
+"    <method name=\"PositionSet\">\n"
+"      <arg type=\"q\" direction=\"in\" />\n"
+"    </method>\n"
+"    <method name=\"PositionGet\">\n"
+"      <arg type=\"q\" direction=\"out\" />\n"
+"    </method>\n"
 "  </interface>\n"
 "</node>\n"
 ;