]> git.sesse.net Git - vlc/blobdiff - plugins/gtk/intf_gtk.c
* Fixed the BeOS compile typo.
[vlc] / plugins / gtk / intf_gtk.c
index 3d4b0266edc9b2047648c02bd62ce84b77330b40..3398b810df73f4624466ae83f4f4f0bdaff6e2b3 100644 (file)
@@ -2,9 +2,10 @@
  * intf_gtk.c: Gtk+ interface
  *****************************************************************************
  * Copyright (C) 1999, 2000 VideoLAN
- * $Id: intf_gtk.c,v 1.1 2001/02/21 11:49:18 sam Exp $
+ * $Id: intf_gtk.c,v 1.22 2001/05/30 17:03:12 sam Exp $
  *
  * Authors: Samuel Hocevar <sam@zoy.org>
+ *          Stéphane Borel <stef@via.ecp.fr>
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
 #include "threads.h"
 #include "mtime.h"
 #include "tests.h"
-#include "modules.h"
 
 #include "stream_control.h"
 #include "input_ext-intf.h"
 
-#include "intf_msg.h"
 #include "interface.h"
+#include "intf_msg.h"
+#include "intf_playlist.h"
 
-#include "gtk_sys.h"
+#include "video.h"
+#include "video_output.h"
+
+#include "gtk_callbacks.h"
 #include "gtk_interface.h"
 #include "gtk_support.h"
+#include "gtk_menu.h"
+#include "gtk_display.h"
+#include "intf_gtk.h"
 
 #include "main.h"
 
+#include "modules.h"
+#include "modules_export.h"
+
 /*****************************************************************************
  * Local prototypes.
  *****************************************************************************/
-static int  intf_Probe     ( probedata_t *p_data );
-static int  intf_Open      ( intf_thread_t *p_intf );
-static void intf_Close     ( intf_thread_t *p_intf );
-static void intf_Run       ( intf_thread_t *p_intf );
+static int  intf_Probe      ( probedata_t *p_data );
+static int  intf_Open       ( intf_thread_t *p_intf );
+static void intf_Close      ( intf_thread_t *p_intf );
+static void intf_Run        ( intf_thread_t *p_intf );
 
-static gint GtkManage    ( gpointer p_data );
+static gint GtkManage       ( gpointer p_data );
 
 /*****************************************************************************
  * g_atexit: kludge to avoid the Gtk+ thread to segfault at exit
@@ -114,6 +124,11 @@ static int intf_Probe( probedata_t *p_data )
         return( 999 );
     }
 
+    if( TestProgram( "gvlc" ) )
+    {
+        return( 190 );
+    }
+
     return( 90 );
 }
 
@@ -135,14 +150,12 @@ static int intf_Open( intf_thread_t *p_intf )
     p_intf->p_sys->b_window_changed = 0;
     p_intf->p_sys->b_playlist_changed = 0;
 
-    p_intf->p_sys->b_scale_isfree = 1;
+    p_intf->p_sys->i_playing = -1;
+    p_intf->p_sys->b_slider_free = 1;
 
     p_intf->p_sys->pf_gtk_callback = NULL;
     p_intf->p_sys->pf_gdk_callback = NULL;
 
-    /* Initialize lock */
-    vlc_mutex_init( &p_intf->p_sys->change_lock );
-
     return( 0 );
 }
 
@@ -151,9 +164,6 @@ static int intf_Open( intf_thread_t *p_intf )
  *****************************************************************************/
 static void intf_Close( intf_thread_t *p_intf )
 {
-    /* Destroy lock */
-    vlc_mutex_destroy( &p_intf->p_sys->change_lock );
-
     /* Destroy structure */
     free( p_intf->p_sys );
 }
@@ -170,9 +180,9 @@ static void intf_Run( intf_thread_t *p_intf )
 {
     /* gtk_init needs to know the command line. We don't care, so we
      * give it an empty one */
-    char *p_args[] = { "" };
-    char **pp_args = p_args;
-    int i_args = 1;
+    char  *p_args[] = { "" };
+    char **pp_args  = p_args;
+    int    i_args   = 1;
 
     /* The data types we are allowed to receive */
     static GtkTargetEntry target_table[] =
@@ -181,13 +191,17 @@ static void intf_Run( intf_thread_t *p_intf )
         { "text/plain", 0, DROP_ACCEPT_TEXT_PLAIN }
     };
 
+    /* intf_Manage callback timeout */
+    int i_timeout;
+
     /* Initialize Gtk+ */
     gtk_init( &i_args, &pp_args );
 
     /* Create some useful widgets that will certainly be used */
     p_intf->p_sys->p_window = create_intf_window( );
     p_intf->p_sys->p_popup = create_intf_popup( );
-
+    p_intf->p_sys->p_playlist = create_intf_playlist();
+    
     /* Set the title of the main window */
     gtk_window_set_title( GTK_WINDOW(p_intf->p_sys->p_window),
                           VOUT_TITLE " (Gtk+ interface)");
@@ -197,11 +211,40 @@ static void intf_Run( intf_thread_t *p_intf )
                        GTK_DEST_DEFAULT_ALL, target_table,
                        1, GDK_ACTION_COPY );
 
+    /* Accept file drops on the playlist window */
+    gtk_drag_dest_set( GTK_WIDGET( lookup_widget( p_intf->p_sys->p_playlist,
+                                   "playlist_clist") ),
+                       GTK_DEST_DEFAULT_ALL, target_table,
+                       1, GDK_ACTION_COPY );
+
+    /* Get the interface labels */
+    p_intf->p_sys->p_slider_frame = GTK_FRAME( gtk_object_get_data(
+        GTK_OBJECT(p_intf->p_sys->p_window ), "slider_frame" ) ); 
+
+#define P_LABEL( name ) GTK_LABEL( gtk_object_get_data( \
+                         GTK_OBJECT( p_intf->p_sys->p_window ), name ) )
+    p_intf->p_sys->p_label_title = P_LABEL( "title_label" );
+    p_intf->p_sys->p_label_chapter = P_LABEL( "chapter_label" );
+#undef P_LABEL
+
+    /* Connect the date display to the slider */
+#define P_SLIDER GTK_RANGE( gtk_object_get_data( \
+                         GTK_OBJECT( p_intf->p_sys->p_window ), "slider" ) )
+    p_intf->p_sys->p_adj = gtk_range_get_adjustment( P_SLIDER );
+
+    gtk_signal_connect ( GTK_OBJECT( p_intf->p_sys->p_adj ), "value_changed",
+                         GTK_SIGNAL_FUNC( GtkDisplayDate ), NULL );
+    p_intf->p_sys->f_adj_oldvalue = 0;
+#undef P_SLIDER
+
     /* We don't create these ones yet because we perhaps won't need them */
     p_intf->p_sys->p_about = NULL;
-    p_intf->p_sys->p_playlist = NULL;
     p_intf->p_sys->p_modules = NULL;
     p_intf->p_sys->p_fileopen = NULL;
+    p_intf->p_sys->p_disc = NULL;
+    p_intf->p_sys->p_network = NULL;
+    p_intf->p_sys->p_preferences = NULL;
+    p_intf->p_sys->p_jump = NULL;
 
     /* Store p_intf to keep an eye on it */
     gtk_object_set_data( GTK_OBJECT(p_intf->p_sys->p_window),
@@ -210,19 +253,26 @@ static void intf_Run( intf_thread_t *p_intf )
     gtk_object_set_data( GTK_OBJECT(p_intf->p_sys->p_popup),
                          "p_intf", p_intf );
 
+    gtk_object_set_data( GTK_OBJECT( p_intf->p_sys->p_playlist ),
+                         "p_intf", p_intf );
+
+    gtk_object_set_data( GTK_OBJECT(p_intf->p_sys->p_adj),
+                         "p_intf", p_intf );
+
     /* Show the control window */
     gtk_widget_show( p_intf->p_sys->p_window );
 
     /* Sleep to avoid using all CPU - since some interfaces needs to access
      * keyboard events, a 100ms delay is a good compromise */
-    p_intf->p_sys->i_timeout = gtk_timeout_add( INTF_IDLE_SLEEP / 1000,
-                                                GtkManage, p_intf );
+    i_timeout = gtk_timeout_add( INTF_IDLE_SLEEP / 1000, GtkManage, p_intf );
 
     /* Enter Gtk mode */
     gtk_main();
 
-    /* launch stored callbacks */
+    /* Remove the timeout */
+    gtk_timeout_remove( i_timeout );
+
+    /* Launch stored callbacks */
     if( p_intf->p_sys->pf_gtk_callback != NULL )
     {
         p_intf->p_sys->pf_gtk_callback();
@@ -244,10 +294,10 @@ static void intf_Run( intf_thread_t *p_intf )
  *****************************************************************************/
 static gint GtkManage( gpointer p_data )
 {
-    intf_thread_t *p_intf = (void *)p_data;
-
-    vlc_mutex_lock( &p_intf->p_sys->change_lock );
+#define p_intf ((intf_thread_t *)p_data)
 
+    vlc_mutex_lock( &p_intf->change_lock );
+    
     /* If the "display popup" flag has changed */
     if( p_intf->b_menu_change )
     {
@@ -257,33 +307,70 @@ static gint GtkManage( gpointer p_data )
             gtk_object_set_data( GTK_OBJECT( p_intf->p_sys->p_popup ),
                                  "p_popup", p_intf );
         }
-//        gtk_widget_show( p_intf->p_sys->p_popup );
         gtk_menu_popup( GTK_MENU( p_intf->p_sys->p_popup ),
                         NULL, NULL, NULL, NULL, 0, GDK_CURRENT_TIME );
         p_intf->b_menu_change = 0;
     }
 
-    /* Manage the slider */
-    if( p_intf->p_input != NULL && p_intf->p_sys->p_window != NULL
-         && p_intf->p_sys->b_scale_isfree )
+    /* update the playlist */
+    GtkPlayListManage( p_data );
+
+    if( p_intf->p_input != NULL && !p_intf->b_die )
     {
-        GtkWidget *p_scale;
-        GtkAdjustment *p_adj;
-   
-        p_scale = GTK_WIDGET( gtk_object_get_data( GTK_OBJECT(
-                                  p_intf->p_sys->p_window ), "hscale" ) );
-        p_adj = gtk_range_get_adjustment ( GTK_RANGE( p_scale ) );
-
-        /* Update the value */
-        p_adj->value = ( 100. *
-                         p_intf->p_input->stream.p_selected_area->i_tell ) /
-                         p_intf->p_input->stream.p_selected_area->i_size;
-
-        /* Gtv does it this way. Why not. */
-        gtk_range_set_adjustment ( GTK_RANGE( p_scale ), p_adj );
-        gtk_range_slider_update ( GTK_RANGE( p_scale ) );
-        gtk_range_clear_background ( GTK_RANGE( p_scale ) );
-        gtk_range_draw_background ( GTK_RANGE( p_scale ) );
+        vlc_mutex_lock( &p_intf->p_input->stream.stream_lock );
+
+        /* New input or stream map change */
+        if( p_intf->p_input->stream.b_changed )
+        {
+            GtkModeManage( p_intf );
+        }
+
+        /* Manage the slider */
+        if( p_intf->p_input->stream.b_seekable )
+        {
+            float newvalue = p_intf->p_sys->p_adj->value;
+    
+#define p_area p_intf->p_input->stream.p_selected_area
+            /* If the user hasn't touched the slider since the last time,
+             * then the input can safely change it */
+            if( newvalue == p_intf->p_sys->f_adj_oldvalue )
+            {
+                /* Update the value */
+                p_intf->p_sys->p_adj->value = p_intf->p_sys->f_adj_oldvalue =
+                    ( 100. * p_area->i_tell ) / p_area->i_size;
+    
+                gtk_signal_emit_by_name( GTK_OBJECT( p_intf->p_sys->p_adj ),
+                                         "value_changed" );
+            }
+            /* Otherwise, send message to the input if the user has
+             * finished dragging the slider */
+            else if( p_intf->p_sys->b_slider_free )
+            {
+                off_t i_seek = ( newvalue * p_area->i_size ) / 100;
+
+                /* release the lock to be able to seek */
+                vlc_mutex_unlock( &p_intf->p_input->stream.stream_lock );
+                input_Seek( p_intf->p_input, i_seek );
+                vlc_mutex_lock( &p_intf->p_input->stream.stream_lock );
+    
+                /* Update the old value */
+                p_intf->p_sys->f_adj_oldvalue = newvalue;
+            }
+#undef p_area
+        }
+        vlc_mutex_unlock( &p_intf->p_input->stream.stream_lock );
+
+        if( p_intf->p_sys->i_part !=
+            p_intf->p_input->stream.p_selected_area->i_part )
+        {
+            p_intf->p_sys->b_chapter_update = 1;
+            GtkSetupMenus( p_intf );
+        }
+
+    }
+    else if( !p_intf->b_die )
+    {
+        GtkModeManage( p_intf );
     }
 
     /* Manage core vlc functions through the callback */
@@ -291,18 +378,18 @@ static gint GtkManage( gpointer p_data )
 
     if( p_intf->b_die )
     {
-        /* Make sure we won't be called again */
-        gtk_timeout_remove( p_intf->p_sys->i_timeout );
-
-        vlc_mutex_unlock( &p_intf->p_sys->change_lock );
+        vlc_mutex_unlock( &p_intf->change_lock );
 
         /* Prepare to die, young Skywalker */
         gtk_main_quit();
+
+        /* Just in case */
         return( FALSE );
     }
 
-    vlc_mutex_unlock( &p_intf->p_sys->change_lock );
+    vlc_mutex_unlock( &p_intf->change_lock );
 
     return( TRUE );
-}
 
+#undef p_intf
+}