]> git.sesse.net Git - vlc/blob - modules/gui/familiar/familiar.c
Make distinction between GPE and GTK_NEED_MAIN way of handling interface.
[vlc] / modules / gui / familiar / familiar.c
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 $
6  *
7  * Authors: Jean-Paul Saman <jpsaman@wxs.nl>
8  *
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.
13  *
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.
18  *
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  *****************************************************************************/
23
24 /*****************************************************************************
25  * Preamble
26  *****************************************************************************/
27 #include <stdlib.h>                                      /* malloc(), free() */
28 #include <errno.h>                                                 /* ENOMEM */
29 #include <string.h>                                            /* strerror() */
30 #include <stdio.h>
31
32 #include <vlc/vlc.h>
33 #include <vlc/intf.h>
34
35 #include <gtk/gtk.h>
36
37 #ifdef HAVE_GPE_INIT_H
38 #include <gpe/init.h>
39 #endif
40
41 #include "callbacks.h"
42 #include "interface.h"
43 #include "support.h"
44 #include "familiar.h"
45
46 /*****************************************************************************
47  * Local prototypes.
48  *****************************************************************************/
49 static int  Open         ( vlc_object_t * );
50 static void Close        ( vlc_object_t * );
51
52 static void Run          ( intf_thread_t * );
53
54 void GtkAutoPlayFile( vlc_object_t * );
55
56 /*****************************************************************************
57  * Module descriptor
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")
62
63 /*****************************************************************************
64  * Module descriptor
65  *****************************************************************************/
66 vlc_module_begin();
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 );
72 vlc_module_end();
73
74 /*****************************************************************************
75  * Open: initialize and create window
76  *****************************************************************************/
77 static int Open( vlc_object_t *p_this )
78 {
79     intf_thread_t *p_intf = (intf_thread_t *)p_this;
80
81     /* Allocate instance and initialize some members */
82     p_intf->p_sys = malloc( sizeof( intf_sys_t ) );
83     if( p_intf->p_sys == NULL )
84     {
85         msg_Err( p_intf, "out of memory" );
86         return VLC_ENOMEM;
87     }
88
89 #ifdef NEED_GTK_MAIN
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 )
92     {
93         free( p_intf->p_sys );
94         return VLC_ENOMOD;
95     }
96 #endif
97
98     /* Initialize Gtk+ thread */
99     p_intf->p_sys->p_input = NULL;
100
101     p_intf->p_sys->b_autoplayfile = 1;
102     p_intf->p_sys->b_filelist_update = 0;
103     p_intf->pf_run = Run;
104
105     return VLC_SUCCESS;
106 }
107
108 /*****************************************************************************
109  * Close: destroy interface window
110  *****************************************************************************/
111 static void Close( vlc_object_t *p_this )
112 {
113     intf_thread_t *p_intf = (intf_thread_t *)p_this;
114
115     if( p_intf->p_sys->p_input )
116     {
117         vlc_object_release( p_intf->p_sys->p_input );
118     }
119
120 #ifdef NEED_GTK_MAIN
121     module_Unneed( p_intf, p_intf->p_sys->p_gtk_main );
122 #endif
123
124     /* Destroy structure */
125     free( p_intf->p_sys );
126 }
127
128 /*****************************************************************************
129  * Run: Gtk+ thread
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 )
135 {
136 #ifdef HAVE_GPE_INIT_H
137     char  *p_args[] = { "" };
138     char **pp_args  = p_args;
139     int    i_args   = 1;
140
141     /* Initialize GPE interface */
142     if (gpe_application_init(&i_args, &pp_args) == FALSE)
143         exit (1);
144 #else
145 # ifdef NEED_GTK_MAIN
146     /* Initialize Gtk+ */
147     gtk_set_locale ();
148     gdk_threads_enter();
149 # else
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;
154     int    i_args   = 1;
155     int    i_dummy;
156
157     gtk_set_locale ();
158     gtk_init( &i_args, &pp_args );
159 # endif
160 #endif
161     /* Create some useful widgets that will certainly be used */
162
163 // FIXME: magic path
164     add_pixmap_directory("share");
165     add_pixmap_directory("/usr/share/videolan");
166
167     p_intf->p_sys->p_window = create_familiar();
168     if (p_intf->p_sys->p_window == NULL)
169     {
170         msg_Err( p_intf, "unable to create familiar interface" );
171     }
172
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)");
176
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) );
180
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) );
184
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));
191
192     /* Store p_intf to keep an eye on it */
193     gtk_object_set_data( GTK_OBJECT(p_intf->p_sys->p_window),
194                          "p_intf", p_intf );
195     /* Show the control window */
196     gtk_widget_show( p_intf->p_sys->p_window );
197     ReadDirectory(p_intf->p_sys->p_clist, "/mnt");
198
199 #ifdef NEED_GTK_MAIN
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 )
203     {
204         gdk_threads_leave();
205         msleep( INTF_IDLE_SLEEP );
206         gdk_threads_enter();
207     }
208 #endif
209
210     gtk_object_destroy( GTK_OBJECT(p_intf->p_sys->p_window) );
211
212 #ifdef NEED_GTK_MAIN
213     gdk_threads_leave();
214 #else
215     gtk_main_quit();
216 #endif
217 }
218
219 /*****************************************************************************
220  * GtkAutoplayFile: Autoplay file depending on configuration settings
221  *****************************************************************************/
222 void GtkAutoPlayFile( vlc_object_t *p_this )
223 {
224     GtkWidget *cbautoplay;
225     intf_thread_t *p_intf;
226     int i_index;
227     vlc_list_t list = vlc_list_find( p_this, VLC_OBJECT_INTF,
228                                                 FIND_ANYWHERE );
229
230     for( i_index = 0; i_index < list.i_count; i_index++ )
231     {
232         p_intf = (intf_thread_t *)list.p_values[i_index].p_object ;
233
234         if( strcmp( MODULE_STRING, p_intf->p_module->psz_object_name ) )
235         {
236             continue;
237         }
238
239         cbautoplay = GTK_WIDGET( gtk_object_get_data(
240                             GTK_OBJECT( p_intf->p_sys->p_window ),
241                             "cbautoplay" ) );
242
243         if( !config_GetInt( p_this, "familiar-autoplayfile" ) )
244         {
245             p_intf->p_sys->b_autoplayfile = VLC_FALSE;
246         }
247         else
248         {
249             p_intf->p_sys->b_autoplayfile = VLC_TRUE;
250         }
251
252         gtk_toggle_button_set_active( GTK_TOGGLE_BUTTON( cbautoplay ),
253                                       p_intf->p_sys->b_autoplayfile );
254     }
255
256     vlc_list_release( &list );
257 }
258