1 /*****************************************************************************
2 * familiar.c : familiar plugin for vlc
3 *****************************************************************************
4 * Copyright (C) 2002 VideoLAN
5 * $Id: familiar.c,v 1.15 2002/12/15 22:45:35 jpsaman Exp $
7 * Authors: Jean-Paul Saman <jpsaman@wxs.nl>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
22 *****************************************************************************/
24 /*****************************************************************************
26 *****************************************************************************/
27 #include <stdlib.h> /* malloc(), free() */
28 #include <errno.h> /* ENOMEM */
29 #include <string.h> /* strerror() */
37 #ifdef HAVE_GPE_INIT_H
41 #include "callbacks.h"
42 #include "interface.h"
46 /*****************************************************************************
48 *****************************************************************************/
49 static int Open ( vlc_object_t * );
50 static void Close ( vlc_object_t * );
52 static void Run ( intf_thread_t * );
54 void GtkAutoPlayFile( vlc_object_t * );
56 /*****************************************************************************
58 *****************************************************************************/
59 #define AUTOPLAYFILE_TEXT N_("autoplay selected file")
60 #define AUTOPLAYFILE_LONGTEXT N_("automatically play a file when selected in the "\
61 "file selection list")
63 /*****************************************************************************
65 *****************************************************************************/
67 add_category_hint( N_("Miscellaneous"), NULL );
68 add_bool( "familiar-autoplayfile", 1, GtkAutoPlayFile, AUTOPLAYFILE_TEXT, AUTOPLAYFILE_LONGTEXT );
69 set_description( _("Familiar Linux Gtk+ interface module") );
70 set_capability( "interface", 70 );
71 set_callbacks( Open, Close );
74 /*****************************************************************************
75 * Open: initialize and create window
76 *****************************************************************************/
77 static int Open( vlc_object_t *p_this )
79 intf_thread_t *p_intf = (intf_thread_t *)p_this;
81 /* Allocate instance and initialize some members */
82 p_intf->p_sys = malloc( sizeof( intf_sys_t ) );
83 if( p_intf->p_sys == NULL )
85 msg_Err( p_intf, "out of memory" );
90 p_intf->p_sys->p_gtk_main = module_Need( p_this, "gtk_main", "gtk" );
91 if( p_intf->p_sys->p_gtk_main == NULL )
93 free( p_intf->p_sys );
98 /* Initialize Gtk+ thread */
99 p_intf->p_sys->p_input = NULL;
101 p_intf->p_sys->b_autoplayfile = 1;
102 p_intf->p_sys->b_filelist_update = 0;
103 p_intf->pf_run = Run;
108 /*****************************************************************************
109 * Close: destroy interface window
110 *****************************************************************************/
111 static void Close( vlc_object_t *p_this )
113 intf_thread_t *p_intf = (intf_thread_t *)p_this;
115 if( p_intf->p_sys->p_input )
117 vlc_object_release( p_intf->p_sys->p_input );
121 module_Unneed( p_intf, p_intf->p_sys->p_gtk_main );
124 /* Destroy structure */
125 free( p_intf->p_sys );
128 /*****************************************************************************
130 *****************************************************************************
131 * this part of the interface is in a separate thread so that we can call
132 * gtk_main() from within it without annoying the rest of the program.
133 *****************************************************************************/
134 static void Run( intf_thread_t *p_intf )
136 #ifdef HAVE_GPE_INIT_H
137 char *p_args[] = { "" };
138 char **pp_args = p_args;
141 /* Initialize GPE interface */
142 if (gpe_application_init(&i_args, &pp_args) == FALSE)
145 # ifdef NEED_GTK_MAIN
146 /* Initialize Gtk+ */
150 /* gtk_init needs to know the command line. We don't care, so we
151 * give it an empty one */
152 char *p_args[] = { "" };
153 char **pp_args = p_args;
158 gtk_init( &i_args, &pp_args );
161 /* Create some useful widgets that will certainly be used */
164 add_pixmap_directory("share");
165 add_pixmap_directory("/usr/share/videolan");
167 p_intf->p_sys->p_window = create_familiar();
168 if (p_intf->p_sys->p_window == NULL)
170 msg_Err( p_intf, "unable to create familiar interface" );
173 /* Set the title of the main window */
174 gtk_window_set_title( GTK_WINDOW(p_intf->p_sys->p_window),
175 VOUT_TITLE " (Familiar Linux interface)");
177 p_intf->p_sys->p_notebook = GTK_NOTEBOOK( gtk_object_get_data(
178 GTK_OBJECT( p_intf->p_sys->p_window ), "notebook" ) );
179 // gtk_widget_hide( GTK_WIDGET(p_intf->p_sys->p_notebook) );
181 p_intf->p_sys->p_progess = GTK_PROGRESS_BAR( gtk_object_get_data(
182 GTK_OBJECT( p_intf->p_sys->p_window ), "progress" ) );
183 gtk_widget_hide( GTK_WIDGET(p_intf->p_sys->p_progess) );
185 p_intf->p_sys->p_clist = GTK_CLIST( gtk_object_get_data(
186 GTK_OBJECT( p_intf->p_sys->p_window ), "clistmedia" ) );
187 gtk_clist_set_column_visibility (GTK_CLIST (p_intf->p_sys->p_clist), 2, FALSE);
188 gtk_clist_set_column_visibility (GTK_CLIST (p_intf->p_sys->p_clist), 3, FALSE);
189 gtk_clist_set_column_visibility (GTK_CLIST (p_intf->p_sys->p_clist), 4, FALSE);
190 gtk_clist_column_titles_show (GTK_CLIST (p_intf->p_sys->p_clist));
192 /* Store p_intf to keep an eye on it */
193 gtk_object_set_data( GTK_OBJECT(p_intf->p_sys->p_window),
195 /* Show the control window */
196 gtk_widget_show( p_intf->p_sys->p_window );
197 ReadDirectory(p_intf->p_sys->p_clist, "/mnt");
200 /* Sleep to avoid using all CPU - since some interfaces need to
201 * access keyboard events, a 100ms delay is a good compromise */
202 while( !p_intf->b_die )
205 msleep( INTF_IDLE_SLEEP );
210 gtk_object_destroy( GTK_OBJECT(p_intf->p_sys->p_window) );
219 /*****************************************************************************
220 * GtkAutoplayFile: Autoplay file depending on configuration settings
221 *****************************************************************************/
222 void GtkAutoPlayFile( vlc_object_t *p_this )
224 GtkWidget *cbautoplay;
225 intf_thread_t *p_intf;
227 vlc_list_t list = vlc_list_find( p_this, VLC_OBJECT_INTF,
230 for( i_index = 0; i_index < list.i_count; i_index++ )
232 p_intf = (intf_thread_t *)list.p_values[i_index].p_object ;
234 if( strcmp( MODULE_STRING, p_intf->p_module->psz_object_name ) )
239 cbautoplay = GTK_WIDGET( gtk_object_get_data(
240 GTK_OBJECT( p_intf->p_sys->p_window ),
243 if( !config_GetInt( p_this, "familiar-autoplayfile" ) )
245 p_intf->p_sys->b_autoplayfile = VLC_FALSE;
249 p_intf->p_sys->b_autoplayfile = VLC_TRUE;
252 gtk_toggle_button_set_active( GTK_TOGGLE_BUTTON( cbautoplay ),
253 p_intf->p_sys->b_autoplayfile );
256 vlc_list_release( &list );