]> git.sesse.net Git - vlc/blobdiff - plugins/gtk/gnome.c
* ALL: new module API. Makes a few things a lot simpler, and we gain
[vlc] / plugins / gtk / gnome.c
index fbaac117c0735a98a01bb39044829dda6e0471e7..3ea6b4277a5e573f7c91f1cf461aa9db1aacded0 100644 (file)
@@ -2,10 +2,10 @@
  * gnome.c : Gnome plugin for vlc
  *****************************************************************************
  * Copyright (C) 2000 VideoLAN
- * $Id: gnome.c,v 1.6 2002/01/07 02:12:29 sam Exp $
+ * $Id: gnome.c,v 1.32 2002/07/31 20:56:51 sam Exp $
  *
  * Authors: Samuel Hocevar <sam@zoy.org>
- *      
+ *
  * 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
  * the Free Software Foundation; either version 2 of the License, or
 #include <string.h>                                            /* strerror() */
 #include <stdio.h>
 
-#include <videolan/vlc.h>
+#include <vlc/vlc.h>
+#include <vlc/intf.h>
 
 #include <gnome.h>
 
-#include "stream_control.h"
-#include "input_ext-intf.h"
-
-#include "interface.h"
-#include "intf_playlist.h"
-
-#include "video.h"
-#include "video_output.h"
-
 #include "gnome_callbacks.h"
 #include "gnome_interface.h"
 #include "gnome_support.h"
 /*****************************************************************************
  * Local prototypes.
  *****************************************************************************/
-static void intf_getfunctions( function_list_t * p_function_list );
-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  Open         ( vlc_object_t * );
+static void Close        ( vlc_object_t * );
 
-static gint GnomeManage      ( gpointer p_data );
+static void Run          ( intf_thread_t * );
+static gint Manage       ( gpointer );
 
 /*****************************************************************************
- * Building configuration tree
+ * Local variables (mutex-protected).
  *****************************************************************************/
-MODULE_CONFIG_START
-MODULE_CONFIG_STOP
+static void ** pp_global_data = NULL;
 
-MODULE_INIT_START
-    SET_DESCRIPTION( "Gnome interface module" )
-#ifndef WIN32
-    if( getenv( "DISPLAY" ) == NULL )
-    {
-        ADD_CAPABILITY( INTF, 15 )
-    }
-    else
+/*****************************************************************************
+ * Module descriptor
+ *****************************************************************************/
+#define TOOLTIPS_TEXT N_("show tooltips")
+#define TOOLTIPS_LONGTEXT N_("Show tooltips for configuration options.")
+
+#define TOOLBAR_TEXT N_("show text on toolbar buttons")
+#define TOOLBAR_LONGTEXT N_("Show the text below icons on the toolbar.")
+
+#define PREFS_MAXH_TEXT N_("maximum height for the configuration windows")
+#define PREFS_MAXH_LONGTEXT N_( \
+    "You can set the maximum height that the configuration windows in the " \
+    "preferences menu will occupy.")
+
+vlc_module_begin();
+#ifdef WIN32
+    int i = 90;
+#else
+    int i = getenv( "DISPLAY" ) == NULL ? 15 : 100;
 #endif
-    {
-        ADD_CAPABILITY( INTF, 100 )
-    }
-    ADD_SHORTCUT( "gtk" )
-    ADD_PROGRAM( "gnome-vlc" )
-MODULE_INIT_STOP
-
-MODULE_ACTIVATE_START
-    intf_getfunctions( &p_module->p_functions->intf );
-MODULE_ACTIVATE_STOP
-
-MODULE_DEACTIVATE_START
-MODULE_DEACTIVATE_STOP
+    pp_global_data = p_module->p_vlc->pp_global_data;
+    
+    add_category_hint( N_("Miscellaneous"), NULL );
+    add_bool( "gnome-tooltips", 1, GtkHideTooltips,
+              TOOLTIPS_TEXT, TOOLTIPS_LONGTEXT );
+    add_bool( "gnome-toolbartext", 1, GtkHideToolbarText, TOOLBAR_TEXT,
+              TOOLBAR_LONGTEXT );
+    add_integer( "gnome-prefs-maxh", 480, NULL,
+                 PREFS_MAXH_TEXT, PREFS_MAXH_LONGTEXT );
+    
+    set_description( _("GNOME interface module") );
+    set_capability( "interface", i );
+    set_callbacks( Open, Close );
+    set_program( "gnome-vlc" );
+vlc_module_end();
 
 /*****************************************************************************
  * g_atexit: kludge to avoid the Gnome thread to segfault at exit
@@ -98,9 +100,22 @@ MODULE_DEACTIVATE_STOP
  *****************************************************************************/
 void g_atexit( GVoidFunc func )
 {
-    intf_thread_t *p_intf = p_main->p_intf;
+    intf_thread_t *p_intf;
+
     int i_dummy;
 
+    if( pp_global_data == NULL )
+    {
+        atexit( func );
+        return;
+    }
+
+    p_intf = (intf_thread_t *)*pp_global_data;
+    if( p_intf == NULL )
+    {
+        return;
+    }
+
     for( i_dummy = 0;
          i_dummy < MAX_ATEXIT && p_intf->p_sys->pf_callback[i_dummy] != NULL;
          i_dummy++ )
@@ -110,7 +125,7 @@ void g_atexit( GVoidFunc func )
 
     if( i_dummy >= MAX_ATEXIT - 1 )
     {
-        intf_ErrMsg( "intf error: too many atexit() callbacks to register" );
+        msg_Err( p_intf, "too many atexit() callbacks to register" );
         return;
     }
 
@@ -119,80 +134,68 @@ void g_atexit( GVoidFunc func )
 }
 
 /*****************************************************************************
- * Functions exported as capabilities. They are declared as static so that
- * we don't pollute the namespace too much.
+ * Open: initialize and create window
  *****************************************************************************/
-static void intf_getfunctions( function_list_t * p_function_list )
+static int Open( vlc_object_t *p_this )
 {
-    p_function_list->pf_probe = intf_Probe;
-    p_function_list->functions.intf.pf_open  = intf_Open;
-    p_function_list->functions.intf.pf_close = intf_Close;
-    p_function_list->functions.intf.pf_run   = intf_Run;
-}
-
-/*****************************************************************************
- * intf_Probe: probe the interface and return a score
- *****************************************************************************
- * This function tries to initialize Gnome and returns a score to the
- * plugin manager so that it can select the best plugin.
- *****************************************************************************/
-static int intf_Probe( probedata_t *p_data )
-{
-#ifndef WIN32
-    if( getenv( "DISPLAY" ) == NULL )
-    {
-        return( 15 );
-    }
-#endif
-
-    return( 100 );
-}
+    intf_thread_t *p_intf = (intf_thread_t *)p_this;
 
-/*****************************************************************************
- * intf_Open: initialize and create window
- *****************************************************************************/
-static int intf_Open( intf_thread_t *p_intf )
-{
     /* Allocate instance and initialize some members */
     p_intf->p_sys = malloc( sizeof( intf_sys_t ) );
     if( p_intf->p_sys == NULL )
     {
-        intf_ErrMsg("error: %s", strerror(ENOMEM));
+        msg_Err( p_intf, "out of memory" );
         return( 1 );
     }
 
+    p_intf->pf_run = Run;
+
+    p_intf->p_sys->p_sub = msg_Subscribe( p_intf );
+
     /* Initialize Gnome thread */
-    p_intf->p_sys->b_playing = 1;
+    p_intf->p_sys->b_playing = 0;
     p_intf->p_sys->b_popup_changed = 0;
     p_intf->p_sys->b_window_changed = 0;
     p_intf->p_sys->b_playlist_changed = 0;
 
+    p_intf->p_sys->p_input = NULL;
     p_intf->p_sys->i_playing = -1;
     p_intf->p_sys->b_slider_free = 1;
 
     p_intf->p_sys->pf_callback[0] = NULL;
 
+    p_intf->p_sys->i_part = 0;
+
     return( 0 );
 }
 
 /*****************************************************************************
- * intf_Close: destroy interface window
+ * Close: destroy interface window
  *****************************************************************************/
-static void intf_Close( intf_thread_t *p_intf )
+static void Close( vlc_object_t *p_this )
 {
+    intf_thread_t *p_intf = (intf_thread_t *)p_this;
+
+    if( p_intf->p_sys->p_input )
+    {
+        vlc_object_release( p_intf->p_sys->p_input );
+    }
+
+    msg_Unsubscribe( p_intf, p_intf->p_sys->p_sub );
+
     /* Destroy structure */
     free( p_intf->p_sys );
 }
 
 /*****************************************************************************
- * intf_Run: Gnome thread
+ * Run: Gnome thread
  *****************************************************************************
  * this part of the interface is in a separate thread so that we can call
  * gtk_main() from within it without annoying the rest of the program.
  * XXX: the approach may look kludgy, and probably is, but I could not find
  * a better way to dynamically load a Gnome interface at runtime.
  *****************************************************************************/
-static void intf_Run( intf_thread_t *p_intf )
+static void Run( intf_thread_t *p_intf )
 {
     /* gnome_init needs to know the command line. We don't care, so we
      * give it an empty one */
@@ -209,12 +212,19 @@ static void intf_Run( intf_thread_t *p_intf )
     };
 
     /* Initialize Gnome */
-    gnome_init( p_main->psz_arg0, VERSION, i_args, p_args );
+
+    /* gnome_init will register stuff with g_atexit, so we need to take
+     * the global lock if we want to be able to intercept the calls */
+    vlc_mutex_lock( p_intf->p_vlc->p_global_lock );
+    *p_intf->p_vlc->pp_global_data = p_intf;
+    gnome_init( p_intf->p_vlc->psz_object_name, VERSION, i_args, p_args );
+    vlc_mutex_unlock( p_intf->p_vlc->p_global_lock );
 
     /* 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();
+    p_intf->p_sys->p_playwin = create_intf_playlist();
+    p_intf->p_sys->p_messages = create_intf_messages();
 
     /* Set the title of the main window */
     gtk_window_set_title( GTK_WINDOW(p_intf->p_sys->p_window),
@@ -226,13 +236,21 @@ static void intf_Run( intf_thread_t *p_intf )
                        1, GDK_ACTION_COPY );
     /* Accept file drops on the playlist window */
     gtk_drag_dest_set( GTK_WIDGET( gtk_object_get_data( GTK_OBJECT(
-                            p_intf->p_sys->p_playlist ), "playlist_clist") ),
+                            p_intf->p_sys->p_playwin ), "playlist_clist") ),
                        GTK_DEST_DEFAULT_ALL, target_table,
                        1, GDK_ACTION_COPY );
 
-    /* Get the interface labels */
+    /* Get the slider object */
     p_intf->p_sys->p_slider_frame = gtk_object_get_data(
                       GTK_OBJECT( p_intf->p_sys->p_window ), "slider_frame" );
+
+    /* Configure the log window */
+    p_intf->p_sys->p_messages_text = GTK_TEXT( gtk_object_get_data(
+        GTK_OBJECT(p_intf->p_sys->p_messages ), "messages_textbox" ) );
+    gtk_text_set_line_wrap( p_intf->p_sys->p_messages_text, TRUE);
+    gtk_text_set_word_wrap( p_intf->p_sys->p_messages_text, FALSE);
+
+    /* Get the interface labels */
     #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" );
@@ -249,15 +267,28 @@ static void intf_Run( intf_thread_t *p_intf )
     p_intf->p_sys->f_adj_oldvalue = 0;
     #undef P_SLIDER
 
+    p_intf->p_sys->p_tooltips = gtk_tooltips_new();
+
     /* 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_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_open = NULL;
     p_intf->p_sys->p_jump = NULL;
 
+    /* Hide tooltips if the option is set */
+    if( !config_GetInt( p_intf, "gnome-tooltips" ) )
+    {
+        gtk_tooltips_disable( p_intf->p_sys->p_tooltips );
+    }
+
+    /* Hide toolbar text of the option is set */
+    if( !config_GetInt( p_intf, "gnome-toolbartext" ) )
+    {
+        gtk_toolbar_set_style(
+            GTK_TOOLBAR(lookup_widget( p_intf->p_sys->p_window, "toolbar" )),
+            GTK_TOOLBAR_ICONS );
+    }
+
     /* Store p_intf to keep an eye on it */
     gtk_object_set_data( GTK_OBJECT(p_intf->p_sys->p_window),
                          "p_intf", p_intf );
@@ -265,7 +296,10 @@ 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 ),
+    gtk_object_set_data( GTK_OBJECT( p_intf->p_sys->p_playwin ),
+                         "p_intf", p_intf );
+
+    gtk_object_set_data( GTK_OBJECT( p_intf->p_sys->p_messages ),
                          "p_intf", p_intf );
 
     gtk_object_set_data( GTK_OBJECT(p_intf->p_sys->p_adj),
@@ -276,7 +310,7 @@ static void intf_Run( intf_thread_t *p_intf )
 
     /* Sleep to avoid using all CPU - since some interfaces needs to access
      * keyboard events, a 100ms delay is a good compromise */
-    i_dummy = gtk_timeout_add( INTF_IDLE_SLEEP / 1000, GnomeManage, p_intf );
+    i_dummy = gtk_timeout_add( INTF_IDLE_SLEEP / 1000, Manage, p_intf );
 
     /* Enter gnome mode */
     gtk_main();
@@ -284,6 +318,9 @@ static void intf_Run( intf_thread_t *p_intf )
     /* Remove the timeout */
     gtk_timeout_remove( i_dummy );
 
+    /* Destroy the Tooltips structure */
+    gtk_object_destroy( GTK_OBJECT(p_intf->p_sys->p_tooltips) );
+
     /* Get rid of stored callbacks so we can unload the plugin */
     for( i_dummy = 0;
          i_dummy < MAX_ATEXIT && p_intf->p_sys->pf_callback[i_dummy] != NULL;
@@ -296,14 +333,15 @@ static void intf_Run( intf_thread_t *p_intf )
 /* following functions are local */
 
 /*****************************************************************************
- * GnomeManage: manage main thread messages
+ * Manage: manage main thread messages
  *****************************************************************************
  * In this function, called approx. 10 times a second, we check what the
  * main program wanted to tell us.
  *****************************************************************************/
-static gint GnomeManage( gpointer p_data )
+static gint Manage( gpointer p_data )
 {
 #define p_intf ((intf_thread_t *)p_data)
+    int i_start, i_stop;
 
     vlc_mutex_lock( &p_intf->change_lock );
 
@@ -322,63 +360,131 @@ static gint GnomeManage( gpointer p_data )
         p_intf->b_menu_change = 0;
     }
 
-    /* update the playlist */
-    GtkPlayListManage( p_intf ); 
+    /* Update the log window */
+    vlc_mutex_lock( p_intf->p_sys->p_sub->p_lock );
+    i_stop = *p_intf->p_sys->p_sub->pi_stop;
+    vlc_mutex_unlock( p_intf->p_sys->p_sub->p_lock );
 
-    if( p_input_bank->pp_input[0] != NULL && !p_intf->b_die )
+    if( p_intf->p_sys->p_sub->i_start != i_stop )
     {
-        vlc_mutex_lock( &p_input_bank->pp_input[0]->stream.stream_lock );
-
-        /* New input or stream map change */
-        if( p_input_bank->pp_input[0]->stream.b_changed )
+        static GdkColor white  = { 0, 0xffff, 0xffff, 0xffff };
+        static GdkColor gray   = { 0, 0xaaaa, 0xaaaa, 0xaaaa };
+        static GdkColor yellow = { 0, 0xffff, 0xffff, 0x6666 };
+        static GdkColor red    = { 0, 0xffff, 0x6666, 0x6666 };
+
+        static const char * ppsz_type[4] = { ": ", " error: ", " warning: ",
+                                             " debug: " };
+        static GdkColor *   pp_color[4] = { &white, &red, &yellow, &gray };
+
+        for( i_start = p_intf->p_sys->p_sub->i_start;
+             i_start != i_stop;
+             i_start = (i_start+1) % VLC_MSG_QSIZE )
         {
-            GtkModeManage( p_intf );
-            GtkSetupMenus( p_intf );
-            p_intf->p_sys->b_playing = 1;
+            /* Append all messages to log window */
+            gtk_text_insert( p_intf->p_sys->p_messages_text, NULL, &gray,
+             NULL, p_intf->p_sys->p_sub->p_msg[i_start].psz_module, -1 );
+
+            gtk_text_insert( p_intf->p_sys->p_messages_text, NULL, &gray,
+                NULL, ppsz_type[p_intf->p_sys->p_sub->p_msg[i_start].i_type],
+                -1 );
+
+            gtk_text_insert( p_intf->p_sys->p_messages_text, NULL,
+                pp_color[p_intf->p_sys->p_sub->p_msg[i_start].i_type], NULL,
+                p_intf->p_sys->p_sub->p_msg[i_start].psz_msg, -1 );
+
+            gtk_text_insert( p_intf->p_sys->p_messages_text, NULL, &gray,
+                NULL, "\n", -1 );
         }
 
-        /* Manage the slider */
-        if( p_input_bank->pp_input[0]->stream.b_seekable )
+        vlc_mutex_lock( p_intf->p_sys->p_sub->p_lock );
+        p_intf->p_sys->p_sub->i_start = i_start;
+        vlc_mutex_unlock( p_intf->p_sys->p_sub->p_lock );
+
+        gtk_text_set_point( p_intf->p_sys->p_messages_text,
+                    gtk_text_get_length( p_intf->p_sys->p_messages_text ) );
+    }
+
+    /* Update the playlist */
+    GtkPlayListManage( p_intf );
+
+    /* Update the input */
+    if( p_intf->p_sys->p_input != NULL )
+    {
+        if( p_intf->p_sys->p_input->b_dead )
         {
-            float           newvalue;
-            newvalue = p_intf->p_sys->p_adj->value;
+            vlc_object_release( p_intf->p_sys->p_input );
+            p_intf->p_sys->p_input = NULL;
+        }
+    }
     
-#define p_area p_input_bank->pp_input[0]->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 )
+    if( p_intf->p_sys->p_input == NULL )
+    {
+        p_intf->p_sys->p_input = vlc_object_find( p_intf, VLC_OBJECT_INPUT,
+                                                          FIND_ANYWHERE );
+    }
+
+    if( p_intf->p_sys->p_input )
+    {
+        input_thread_t *p_input = p_intf->p_sys->p_input;
+
+        vlc_mutex_lock( &p_input->stream.stream_lock );
+
+        if( !p_input->b_die )
+        {
+            /* New input or stream map change */
+            if( p_input->stream.b_changed )
             {
-                /* 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" );
+                GtkModeManage( p_intf );
+                GtkSetupMenus( p_intf );
+                p_intf->p_sys->b_playing = 1;
             }
-            /* Otherwise, send message to the input if the user has
-             * finished dragging the slider */
-            else if( p_intf->p_sys->b_slider_free )
+
+            /* Manage the slider */
+            if( p_input->stream.b_seekable && p_intf->p_sys->b_playing )
             {
-                off_t i_seek = ( newvalue * p_area->i_size ) / 100;
-    
-                vlc_mutex_unlock( &p_input_bank->pp_input[0]->stream.stream_lock );
-                input_Seek( p_input_bank->pp_input[0], i_seek );
-                vlc_mutex_lock( &p_input_bank->pp_input[0]->stream.stream_lock );
-    
-                /* Update the old value */
-                p_intf->p_sys->f_adj_oldvalue = newvalue;
-            }
+                float newvalue = p_intf->p_sys->p_adj->value;
+
+#define p_area 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 )
+                {
+                    if( newvalue > 0. && newvalue < 100. )
+                    {
+                        off_t i_seek = ( newvalue * p_area->i_size ) / 100;
+
+                        vlc_mutex_unlock( &p_input->stream.stream_lock );
+                        input_Seek( p_input, i_seek, INPUT_SEEK_SET );
+                        vlc_mutex_lock( &p_input->stream.stream_lock );
+                    }
+
+                    /* Update the old value */
+                    p_intf->p_sys->f_adj_oldvalue = newvalue;
+                }
 #undef p_area
-        }
+            }
 
-        if( p_intf->p_sys->i_part !=
-            p_input_bank->pp_input[0]->stream.p_selected_area->i_part )
-        {
-            p_intf->p_sys->b_chapter_update = 1;
-            GtkSetupMenus( p_intf );
+            if( p_intf->p_sys->i_part !=
+                p_input->stream.p_selected_area->i_part )
+            {
+                p_intf->p_sys->b_chapter_update = 1;
+                GtkSetupMenus( p_intf );
+            }
         }
 
-        vlc_mutex_unlock( &p_input_bank->pp_input[0]->stream.stream_lock );
+        vlc_mutex_unlock( &p_input->stream.stream_lock );
     }
     else if( p_intf->p_sys->b_playing && !p_intf->b_die )
     {
@@ -386,9 +492,6 @@ static gint GnomeManage( gpointer p_data )
         p_intf->p_sys->b_playing = 0;
     }
 
-    /* Manage core vlc functions through the callback */
-    p_intf->pf_manage( p_intf );
-
     if( p_intf->b_die )
     {
         vlc_mutex_unlock( &p_intf->change_lock );