00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #include <vlc/vlc.h>
00028
00029 #include <stdlib.h>
00030
00031 #include <gtk/gtk.h>
00032
00033 #if defined(MODULE_NAME_IS_gtk2_main)
00034 # include <glib.h>
00035 #endif
00036
00037 #if defined(MODULE_NAME_IS_gnome_main) || defined(MODULE_NAME_IS_gnome2_main)
00038 # include <gnome.h>
00039 #endif
00040
00041
00042
00043
00044 static int Open ( vlc_object_t * );
00045 static void Close ( vlc_object_t * );
00046
00047 static void GtkMain ( vlc_object_t * );
00048
00049
00050
00051
00052 static int i_refcount = 0;
00053 static vlc_object_t * p_gtk_main = NULL;
00054
00055
00056
00057
00058 vlc_module_begin();
00059 int i_cap;
00060 set_description( _("Gtk+ GUI helper") );
00061 #if defined(MODULE_NAME_IS_gtk_main)
00062 i_cap = 90;
00063 add_shortcut( "gtk" );
00064 #elif defined(MODULE_NAME_IS_gnome_main)
00065 i_cap = 100;
00066 add_shortcut( "gtk" );
00067 add_shortcut( "gnome" );
00068 #elif defined(MODULE_NAME_IS_gtk2_main)
00069 i_cap = 95;
00070 add_shortcut( "gtk2" );
00071 #elif defined(MODULE_NAME_IS_gnome2_main)
00072 i_cap = 105;
00073 add_shortcut( "gtk2" );
00074 add_shortcut( "gnome2" );
00075 #endif
00076 set_capability( "gui-helper", i_cap );
00077 set_callbacks( Open, Close );
00078 linked_with_a_crap_library_which_uses_atexit();
00079 vlc_module_end();
00080
00081
00082
00083
00084 static int Open( vlc_object_t *p_this )
00085 {
00086 vlc_value_t lockval;
00087
00088
00089 var_Create( p_this->p_libvlc, "gtk", VLC_VAR_MUTEX );
00090
00091 var_Get( p_this->p_libvlc, "gtk", &lockval );
00092 vlc_mutex_lock( lockval.p_address );
00093
00094 if( i_refcount > 0 )
00095 {
00096 i_refcount++;
00097 vlc_mutex_unlock( lockval.p_address );
00098
00099 return VLC_SUCCESS;
00100 }
00101
00102 p_gtk_main = vlc_object_create( p_this, VLC_OBJECT_GENERIC );
00103
00104
00105 if( !g_thread_supported() )
00106 {
00107 g_thread_init( NULL );
00108 }
00109
00110
00111
00112 if( vlc_thread_create( p_gtk_main, "gtk_main", GtkMain,
00113 VLC_THREAD_PRIORITY_LOW, VLC_TRUE ) )
00114 {
00115 vlc_object_destroy( p_gtk_main );
00116 i_refcount--;
00117 vlc_mutex_unlock( lockval.p_address );
00118 var_Destroy( p_this->p_libvlc, "gtk" );
00119 return VLC_ETHREAD;
00120 }
00121
00122 i_refcount++;
00123 vlc_mutex_unlock( lockval.p_address );
00124
00125 return VLC_SUCCESS;
00126 }
00127
00128
00129
00130
00131 static void Close( vlc_object_t *p_this )
00132 {
00133 vlc_value_t lockval;
00134
00135 var_Get( p_this->p_libvlc, "gtk", &lockval );
00136 vlc_mutex_lock( lockval.p_address );
00137
00138 i_refcount--;
00139
00140 if( i_refcount > 0 )
00141 {
00142 vlc_mutex_unlock( lockval.p_address );
00143 var_Destroy( p_this->p_libvlc, "gtk" );
00144 return;
00145 }
00146
00147 gtk_main_quit();
00148 vlc_thread_join( p_gtk_main );
00149
00150 vlc_object_destroy( p_gtk_main );
00151 p_gtk_main = NULL;
00152
00153 vlc_mutex_unlock( lockval.p_address );
00154 var_Destroy( p_this->p_libvlc, "gtk" );
00155 }
00156
00157 static gint foo( gpointer bar ) { return TRUE; }
00158
00159
00160
00161
00162
00163
00164
00165 static void GtkMain( vlc_object_t *p_this )
00166 {
00167
00168
00169 static char *p_args[] = { "", NULL };
00170 #if defined(MODULE_NAME_IS_gtk_main) || defined(MODULE_NAME_IS_gtk2_main)
00171 static char **pp_args = p_args;
00172 #endif
00173 static int i_args = 1;
00174
00175
00176 #if defined(MODULE_NAME_IS_gtk2_main) || defined(MODULE_NAME_IS_gnome2_main)
00177 gdk_threads_init();
00178 #endif
00179
00180 #if defined(MODULE_NAME_IS_gnome_main)
00181 gnome_init( p_this->p_vlc->psz_object_name, VERSION, i_args, p_args );
00182 #elif defined(MODULE_NAME_IS_gnome2_main)
00183 gnome_program_init( PACKAGE, VERSION, LIBGNOMEUI_MODULE,
00184 i_args, p_args,
00185 GNOME_PARAM_APP_DATADIR, "",
00186 NULL );
00187 #else
00188 gtk_set_locale();
00189 gtk_init( &i_args, &pp_args );
00190 #endif
00191
00192 gdk_threads_enter();
00193
00194 vlc_thread_ready( p_this );
00195
00196
00197
00198 gtk_timeout_add( INTF_IDLE_SLEEP / 1000, foo, p_this );
00199
00200
00201 gtk_main();
00202
00203 gdk_threads_leave();
00204 }
00205