]> git.sesse.net Git - vlc/blob - modules/gui/familiar/familiar.c
169afeeedd32bd4e3faa6353a7877d0394166e75
[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.12 2002/12/12 12:24:23 sam 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     p_intf->p_sys->p_gtk_main = module_Need( p_this, "gtk_main", "gtk" );
90     if( p_intf->p_sys->p_gtk_main == NULL )
91     {
92         free( p_intf->p_sys );
93         return VLC_ENOMOD;
94     }
95
96     /* Initialize Gtk+ thread */
97     p_intf->p_sys->p_input = NULL;
98
99     p_intf->p_sys->b_autoplayfile = 1;
100
101     p_intf->pf_run = Run;
102
103     return VLC_SUCCESS;
104 }
105
106 /*****************************************************************************
107  * Close: destroy interface window
108  *****************************************************************************/
109 static void Close( vlc_object_t *p_this )
110 {
111     intf_thread_t *p_intf = (intf_thread_t *)p_this;
112
113     if( p_intf->p_sys->p_input )
114     {
115         vlc_object_release( p_intf->p_sys->p_input );
116     }
117
118     module_Unneed( p_intf, p_intf->p_sys->p_gtk_main );
119
120     /* Destroy structure */
121     free( p_intf->p_sys );
122 }
123
124 /*****************************************************************************
125  * Run: Gtk+ thread
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 )
131 {
132 #ifdef HAVE_GPE_INIT_H
133    /* Initialize GPE interface */
134    if (gpe_application_init(&i_args, &pp_args) == FALSE)
135         exit (1);
136 #else
137    /* Initialize Gtk+ */
138    gtk_set_locale ();
139
140    gdk_threads_enter();
141 #endif
142     /* Create some useful widgets that will certainly be used */
143
144 // FIXME: magic path
145     add_pixmap_directory("share");
146     add_pixmap_directory("/usr/share/videolan");
147
148     p_intf->p_sys->p_window = create_familiar();
149     if (p_intf->p_sys->p_window == NULL)
150     {
151         msg_Err( p_intf, "unable to create familiar interface" );
152     }
153
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)");
157
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) );
161
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) );
165
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));
172
173     /* Store p_intf to keep an eye on it */
174     gtk_object_set_data( GTK_OBJECT(p_intf->p_sys->p_window),
175                          "p_intf", p_intf );
176     /* Show the control window */
177     gtk_widget_show( p_intf->p_sys->p_window );
178     ReadDirectory(p_intf->p_sys->p_clist, "/mnt");
179
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 )
183     {
184         gdk_threads_leave();
185         msleep( INTF_IDLE_SLEEP );
186         gdk_threads_enter();
187     }
188
189     gtk_object_destroy( GTK_OBJECT(p_intf->p_sys->p_window) );
190
191     gdk_threads_leave();
192     gtk_main_quit();
193 }
194
195 /*****************************************************************************
196  * GtkAutoplayFile: Autoplay file depending on configuration settings
197  *****************************************************************************/
198 void GtkAutoPlayFile( vlc_object_t *p_this )
199 {
200     GtkWidget *cbautoplay;
201     intf_thread_t **pp_intf;
202     vlc_list_t *p_list = vlc_list_find( p_this, VLC_OBJECT_INTF,
203                                                 FIND_ANYWHERE );
204
205     for( pp_intf = (intf_thread_t **)p_list->pp_objects ;
206          *pp_intf ;
207          pp_intf++ )
208     {
209         if( strcmp( MODULE_STRING, (*pp_intf)->p_module->psz_object_name ) )
210         {
211             continue;
212         }
213
214         cbautoplay = GTK_WIDGET( gtk_object_get_data(
215                             GTK_OBJECT( (*pp_intf)->p_sys->p_window ),
216                             "cbautoplay" ) );
217
218         if( !config_GetInt( p_this, "familiar-autoplayfile" ) )
219         {
220             (*pp_intf)->p_sys->b_autoplayfile = VLC_FALSE;
221         }
222         else
223         {
224             (*pp_intf)->p_sys->b_autoplayfile = VLC_TRUE;
225         }
226
227         gtk_toggle_button_set_active( GTK_TOGGLE_BUTTON( cbautoplay ),
228                                       (*pp_intf)->p_sys->b_autoplayfile );
229     }
230
231     vlc_list_release( p_list );
232 }
233