]> git.sesse.net Git - vlc/blob - modules/gui/familiar/familiar.c
Stopping vlc from the Familiar interface is possible again.
[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.7 2002/08/21 19:30:03 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 #include "callbacks.h"
38 #include "interface.h"
39 #include "support.h"
40 #include "familiar.h"
41
42 /*****************************************************************************
43  * Local prototypes.
44  *****************************************************************************/
45 static int  Open         ( vlc_object_t * );
46 static void Close        ( vlc_object_t * );             
47
48 static void Run          ( intf_thread_t * );                  
49
50 /*****************************************************************************
51  * Module descriptor
52  *****************************************************************************/
53 vlc_module_begin();
54     set_description( _("Familiar Linux Gtk+ interface module") );
55     set_capability( "interface", 70 );
56     set_callbacks( Open, Close );
57 vlc_module_end();
58
59 /*****************************************************************************
60  * Open: initialize and create window
61  *****************************************************************************/
62 static int Open( vlc_object_t *p_this )
63 {   
64     intf_thread_t *p_intf = (intf_thread_t *)p_this;
65
66     /* Allocate instance and initialize some members */
67     p_intf->p_sys = malloc( sizeof( intf_sys_t ) );
68     if( p_intf->p_sys == NULL )
69     {
70         msg_Err( p_intf, "out of memory" );
71         return VLC_ENOMEM;
72     }
73
74     p_intf->p_sys->p_gtk_main = module_Need( p_this, "gtk_main", "gtk" );
75     if( p_intf->p_sys->p_gtk_main == NULL )
76     {
77         free( p_intf->p_sys );
78         return VLC_EMODULE;
79     }
80
81     /* Initialize Gtk+ thread */
82     p_intf->p_sys->p_input = NULL;
83
84     p_intf->p_sys->b_autoplayfile = 1;
85
86     p_intf->pf_run = Run;
87
88     return VLC_SUCCESS;
89 }
90
91 /*****************************************************************************
92  * Close: destroy interface window
93  *****************************************************************************/
94 static void Close( vlc_object_t *p_this )
95 {   
96     intf_thread_t *p_intf = (intf_thread_t *)p_this;
97
98     if( p_intf->p_sys->p_input )
99     {
100         vlc_object_release( p_intf->p_sys->p_input );
101     }
102
103     module_Unneed( p_intf, p_intf->p_sys->p_gtk_main );
104
105     /* Destroy structure */
106     free( p_intf->p_sys );
107 }
108
109 /*****************************************************************************
110  * Run: Gtk+ thread
111  *****************************************************************************
112  * this part of the interface is in a separate thread so that we can call
113  * gtk_main() from within it without annoying the rest of the program.
114  *****************************************************************************/
115 static void Run( intf_thread_t *p_intf )
116 {
117     gdk_threads_enter();
118
119     /* Create some useful widgets that will certainly be used */
120 // FIXME: magic path
121     add_pixmap_directory("share");
122     p_intf->p_sys->p_window = create_familiar();
123     if (p_intf->p_sys->p_window == NULL)
124     {
125         msg_Err( p_intf, "unable to create familiar interface" );
126     }
127
128     /* Set the title of the main window */
129     gtk_window_set_title( GTK_WINDOW(p_intf->p_sys->p_window),
130                           VOUT_TITLE " (Familiar Linux interface)");
131
132     p_intf->p_sys->p_notebook = GTK_NOTEBOOK( gtk_object_get_data(
133         GTK_OBJECT( p_intf->p_sys->p_window ), "notebook" ) );
134 //    gtk_widget_hide( GTK_WIDGET(p_intf->p_sys->p_notebook) );
135
136     p_intf->p_sys->p_clist = GTK_CLIST( gtk_object_get_data(
137         GTK_OBJECT( p_intf->p_sys->p_window ), "clistmedia" ) );
138     gtk_clist_set_column_visibility (GTK_CLIST (p_intf->p_sys->p_clist), 2, FALSE);
139     gtk_clist_set_column_visibility (GTK_CLIST (p_intf->p_sys->p_clist), 3, FALSE);
140     gtk_clist_set_column_visibility (GTK_CLIST (p_intf->p_sys->p_clist), 4, FALSE);
141     gtk_clist_column_titles_show (GTK_CLIST (p_intf->p_sys->p_clist));
142
143     /* Store p_intf to keep an eye on it */
144     gtk_object_set_data( GTK_OBJECT(p_intf->p_sys->p_window),
145                          "p_intf", p_intf );
146     /* Show the control window */
147     gtk_widget_show( p_intf->p_sys->p_window );
148
149     /* Sleep to avoid using all CPU - since some interfaces need to
150      * access keyboard events, a 100ms delay is a good compromise */
151     while( !p_intf->b_die )
152     {
153         gdk_threads_leave();
154         msleep( INTF_IDLE_SLEEP );
155         gdk_threads_enter();
156     }
157
158     gtk_object_destroy( GTK_OBJECT(p_intf->p_sys->p_window) );
159
160     gdk_threads_leave();
161     gtk_main_quit();
162 }
163