1 /*****************************************************************************
2 * familiar.c : familiar plugin for vlc
3 *****************************************************************************
4 * Copyright (C) 2002 VideoLAN
5 * $Id: familiar.c,v 1.12 2002/12/12 12:24:23 sam 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" );
89 p_intf->p_sys->p_gtk_main = module_Need( p_this, "gtk_main", "gtk" );
90 if( p_intf->p_sys->p_gtk_main == NULL )
92 free( p_intf->p_sys );
96 /* Initialize Gtk+ thread */
97 p_intf->p_sys->p_input = NULL;
99 p_intf->p_sys->b_autoplayfile = 1;
101 p_intf->pf_run = Run;
106 /*****************************************************************************
107 * Close: destroy interface window
108 *****************************************************************************/
109 static void Close( vlc_object_t *p_this )
111 intf_thread_t *p_intf = (intf_thread_t *)p_this;
113 if( p_intf->p_sys->p_input )
115 vlc_object_release( p_intf->p_sys->p_input );
118 module_Unneed( p_intf, p_intf->p_sys->p_gtk_main );
120 /* Destroy structure */
121 free( p_intf->p_sys );
124 /*****************************************************************************
126 *****************************************************************************
127 * this part of the interface is in a separate thread so that we can call
128 * gtk_main() from within it without annoying the rest of the program.
129 *****************************************************************************/
130 static void Run( intf_thread_t *p_intf )
132 #ifdef HAVE_GPE_INIT_H
133 /* Initialize GPE interface */
134 if (gpe_application_init(&i_args, &pp_args) == FALSE)
137 /* Initialize Gtk+ */
142 /* Create some useful widgets that will certainly be used */
145 add_pixmap_directory("share");
146 add_pixmap_directory("/usr/share/videolan");
148 p_intf->p_sys->p_window = create_familiar();
149 if (p_intf->p_sys->p_window == NULL)
151 msg_Err( p_intf, "unable to create familiar interface" );
154 /* Set the title of the main window */
155 gtk_window_set_title( GTK_WINDOW(p_intf->p_sys->p_window),
156 VOUT_TITLE " (Familiar Linux interface)");
158 p_intf->p_sys->p_notebook = GTK_NOTEBOOK( gtk_object_get_data(
159 GTK_OBJECT( p_intf->p_sys->p_window ), "notebook" ) );
160 // gtk_widget_hide( GTK_WIDGET(p_intf->p_sys->p_notebook) );
162 p_intf->p_sys->p_progess = GTK_PROGRESS_BAR( gtk_object_get_data(
163 GTK_OBJECT( p_intf->p_sys->p_window ), "progress" ) );
164 gtk_widget_hide( GTK_WIDGET(p_intf->p_sys->p_progess) );
166 p_intf->p_sys->p_clist = GTK_CLIST( gtk_object_get_data(
167 GTK_OBJECT( p_intf->p_sys->p_window ), "clistmedia" ) );
168 gtk_clist_set_column_visibility (GTK_CLIST (p_intf->p_sys->p_clist), 2, FALSE);
169 gtk_clist_set_column_visibility (GTK_CLIST (p_intf->p_sys->p_clist), 3, FALSE);
170 gtk_clist_set_column_visibility (GTK_CLIST (p_intf->p_sys->p_clist), 4, FALSE);
171 gtk_clist_column_titles_show (GTK_CLIST (p_intf->p_sys->p_clist));
173 /* Store p_intf to keep an eye on it */
174 gtk_object_set_data( GTK_OBJECT(p_intf->p_sys->p_window),
176 /* Show the control window */
177 gtk_widget_show( p_intf->p_sys->p_window );
178 ReadDirectory(p_intf->p_sys->p_clist, "/mnt");
180 /* Sleep to avoid using all CPU - since some interfaces need to
181 * access keyboard events, a 100ms delay is a good compromise */
182 while( !p_intf->b_die )
185 msleep( INTF_IDLE_SLEEP );
189 gtk_object_destroy( GTK_OBJECT(p_intf->p_sys->p_window) );
195 /*****************************************************************************
196 * GtkAutoplayFile: Autoplay file depending on configuration settings
197 *****************************************************************************/
198 void GtkAutoPlayFile( vlc_object_t *p_this )
200 GtkWidget *cbautoplay;
201 intf_thread_t **pp_intf;
202 vlc_list_t *p_list = vlc_list_find( p_this, VLC_OBJECT_INTF,
205 for( pp_intf = (intf_thread_t **)p_list->pp_objects ;
209 if( strcmp( MODULE_STRING, (*pp_intf)->p_module->psz_object_name ) )
214 cbautoplay = GTK_WIDGET( gtk_object_get_data(
215 GTK_OBJECT( (*pp_intf)->p_sys->p_window ),
218 if( !config_GetInt( p_this, "familiar-autoplayfile" ) )
220 (*pp_intf)->p_sys->b_autoplayfile = VLC_FALSE;
224 (*pp_intf)->p_sys->b_autoplayfile = VLC_TRUE;
227 gtk_toggle_button_set_active( GTK_TOGGLE_BUTTON( cbautoplay ),
228 (*pp_intf)->p_sys->b_autoplayfile );
231 vlc_list_release( p_list );