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