]> git.sesse.net Git - vlc/blob - modules/gui/gtk2/gnome2.c
* modules/*: sanitization of the modules description strings.
[vlc] / modules / gui / gtk2 / gnome2.c
1 /*****************************************************************************
2  * gnome2.c : GNOME 2 plugin for vlc
3  *****************************************************************************
4  * Copyright (C) 2003 VideoLAN
5  * $Id: gnome2.c,v 1.2 2003/03/30 18:14:37 gbazin Exp $
6  *
7  * Authors: Samuel Hocevar <sam@zoy.org>
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 <gnome.h>
36
37 #include "gnome2_interface.h"
38 #include "gnome2_support.h"
39
40 /*****************************************************************************
41  * Local prototypes.
42  *****************************************************************************/
43 static int  Open         ( vlc_object_t * );
44 static void Close        ( vlc_object_t * );
45
46 static void Run          ( intf_thread_t * );
47 static int  Manage       ( intf_thread_t * );
48
49 /*****************************************************************************
50  * Module descriptor
51  *****************************************************************************/
52 vlc_module_begin();
53     int i = getenv( "DISPLAY" ) == NULL ? 15 : 95;
54     set_description( _("Gtk2 interface") );
55     set_capability( "interface", i );
56     set_callbacks( Open, Close );
57     set_program( "gvlc" );
58 vlc_module_end();
59
60 /*****************************************************************************
61  * intf_sys_t
62  *****************************************************************************/
63 struct intf_sys_t
64 {
65     module_t *p_gui_helper;
66
67     GtkWidget *p_app;
68 };
69
70 /*****************************************************************************
71  * Open: initialize and create window
72  *****************************************************************************/
73 static int Open( vlc_object_t *p_this )
74 {
75     intf_thread_t *p_intf = (intf_thread_t *)p_this;
76
77     /* Allocate instance and initialize some members */
78     p_intf->p_sys = malloc( sizeof( intf_sys_t ) );
79     if( p_intf->p_sys == NULL )
80     {
81         msg_Err( p_intf, "out of memory" );
82         return VLC_ENOMEM;
83     }
84
85 #ifdef NEED_GTK2_MAIN
86     p_intf->p_sys->p_gui_helper = module_Need( p_this, "gui-helper", "gnome2" );
87     if( p_intf->p_sys->p_gui_helper == NULL )
88     {
89         free( p_intf->p_sys );
90         return VLC_ENOMOD;
91     }
92 #endif
93
94     p_intf->pf_run = Run;
95
96     return VLC_SUCCESS;
97 }
98
99 /*****************************************************************************
100  * Close: destroy interface window
101  *****************************************************************************/
102 static void Close( vlc_object_t *p_this )
103 {
104     intf_thread_t *p_intf = (intf_thread_t *)p_this;
105
106 #ifdef NEED_GTK2_MAIN
107     module_Unneed( p_intf, p_intf->p_sys->p_gui_helper );
108 #endif
109
110     /* Destroy structure */
111     free( p_intf->p_sys );
112 }
113
114 /*****************************************************************************
115  * Run: Gtk+ thread
116  *****************************************************************************
117  * this part of the interface is in a separate thread so that we can call
118  * gtk_main() from within it without annoying the rest of the program.
119  *****************************************************************************/
120 static void Run( intf_thread_t *p_intf )
121 {
122 #ifdef NEED_GTK2_MAIN
123     gdk_threads_enter();
124 #else
125     /* gnome_program_init needs to know the command line. We don't care, so
126      * we give it an empty one */
127     char  *p_args[] = { "", NULL };
128     int    i_args   = 1;
129     int    i_dummy;
130
131     gtk_set_locale();
132     gnome_program_init( PACKAGE, VERSION, LIBGNOMEUI_MODULE,
133                         i_args, p_args,
134                         GNOME_PARAM_APP_DATADIR, "",//PACKAGE_DATA_DIR,
135                         NULL );
136 #endif
137
138     /* Create some useful widgets that will certainly be used */
139     p_intf->p_sys->p_app = create_app1();
140
141     /* Set the title of the main window */
142     //gtk_window_set_title( GTK_WINDOW(p_intf->p_sys->p_app),
143     //                      VOUT_TITLE " (Gtk+ interface)" );
144
145     /* Show the control window */
146     gtk_widget_show( p_intf->p_sys->p_app );
147
148 #ifdef NEED_GTK2_MAIN
149     while( !p_intf->b_die )
150     {
151         Manage( p_intf );
152
153         /* Sleep to avoid using all CPU - since some interfaces need to
154          * access keyboard events, a 100ms delay is a good compromise */
155         gdk_threads_leave();
156         msleep( INTF_IDLE_SLEEP );
157         gdk_threads_enter();
158     }
159 #else
160     /* Sleep to avoid using all CPU - since some interfaces needs to access
161      * keyboard events, a 100ms delay is a good compromise */
162     i_dummy = gtk_timeout_add( INTF_IDLE_SLEEP / 1000, (GtkFunction)Manage,
163                                p_intf );
164     /* Enter Gtk mode */
165     gtk_main();
166     /* Remove the timeout */
167     gtk_timeout_remove( i_dummy );
168 #endif
169
170     gtk_object_destroy( GTK_OBJECT(p_intf->p_sys->p_app) );
171
172 #ifdef NEED_GTK2_MAIN
173     gdk_threads_leave();
174 #endif
175 }
176
177 /* following functions are local */
178
179 /*****************************************************************************
180  * Manage: manage main thread messages
181  *****************************************************************************
182  * In this function, called approx. 10 times a second, we check what the
183  * main program wanted to tell us.
184  *****************************************************************************/
185 static int Manage( intf_thread_t *p_intf )
186 {
187 #ifndef NEED_GTK2_MAIN
188     if( p_intf->b_die )
189     {
190         gtk_main_quit();
191
192         return FALSE;
193     }
194 #endif
195
196     return TRUE;
197 }