]> git.sesse.net Git - vlc/blob - modules/gui/skins2/src/skin_main.cpp
skins2: remove dead code
[vlc] / modules / gui / skins2 / src / skin_main.cpp
1 /*****************************************************************************
2  * skin_main.cpp
3  *****************************************************************************
4  * Copyright (C) 2003 the VideoLAN team
5  * $Id$
6  *
7  * Authors: Cyril Deguet     <asmax@via.ecp.fr>
8  *          Olivier Teulière <ipkiss@via.ecp.fr>
9  *
10  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program; if not, write to the Free Software
22  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
23  *****************************************************************************/
24
25 #ifdef HAVE_CONFIG_H
26 # include "config.h"
27 #endif
28
29 #include <vlc_common.h>
30 #include <vlc_plugin.h>
31 #include <vlc_input.h>
32 #include <vlc_playlist.h>
33 #include <vlc_threads.h>
34 #include <vlc_vout_window.h>
35
36 #include "dialogs.hpp"
37 #include "os_factory.hpp"
38 #include "os_loop.hpp"
39 #include "var_manager.hpp"
40 #include "vlcproc.hpp"
41 #include "theme_loader.hpp"
42 #include "theme.hpp"
43 #include "theme_repository.hpp"
44 #include "vout_window.hpp"
45 #include "vout_manager.hpp"
46 #include "art_manager.hpp"
47 #include "../parser/interpreter.hpp"
48 #include "../commands/async_queue.hpp"
49 #include "../commands/cmd_quit.hpp"
50 #include "../commands/cmd_dialogs.hpp"
51 #include "../commands/cmd_minimize.hpp"
52 #include "../commands/cmd_playlist.hpp"
53
54 //---------------------------------------------------------------------------
55 // Exported interface functions.
56 //---------------------------------------------------------------------------
57 #ifdef WIN32_SKINS
58 extern "C" __declspec( dllexport )
59     int __VLC_SYMBOL( vlc_entry ) ( module_t *p_module );
60 #endif
61
62
63 //---------------------------------------------------------------------------
64 // Local prototypes
65 //---------------------------------------------------------------------------
66 static int  Open  ( vlc_object_t * );
67 static void Close ( vlc_object_t * );
68 static void *Run  ( void * );
69
70 static struct
71 {
72     intf_thread_t *intf;
73     vlc_mutex_t mutex;
74 } skin_load = { NULL, VLC_STATIC_MUTEX };
75
76 //---------------------------------------------------------------------------
77 // Open: initialize interface
78 //---------------------------------------------------------------------------
79 static int Open( vlc_object_t *p_this )
80 {
81     intf_thread_t *p_intf = (intf_thread_t *)p_this;
82
83     // Allocate instance and initialize some members
84     p_intf->p_sys = (intf_sys_t *) calloc( 1, sizeof( intf_sys_t ) );
85     if( p_intf->p_sys == NULL )
86         return VLC_ENOMEM;
87
88     // Suscribe to messages bank
89 #if 0
90     p_intf->p_sys->p_sub = msg_Subscribe( p_intf );
91 #endif
92
93     p_intf->p_sys->p_input = NULL;
94     p_intf->p_sys->p_playlist = pl_Get( p_intf );
95
96     // Initialize "singleton" objects
97     p_intf->p_sys->p_logger = NULL;
98     p_intf->p_sys->p_queue = NULL;
99     p_intf->p_sys->p_dialogs = NULL;
100     p_intf->p_sys->p_interpreter = NULL;
101     p_intf->p_sys->p_osFactory = NULL;
102     p_intf->p_sys->p_osLoop = NULL;
103     p_intf->p_sys->p_varManager = NULL;
104     p_intf->p_sys->p_voutManager = NULL;
105     p_intf->p_sys->p_vlcProc = NULL;
106     p_intf->p_sys->p_repository = NULL;
107
108     // No theme yet
109     p_intf->p_sys->p_theme = NULL;
110
111     vlc_mutex_init( &p_intf->p_sys->vout_lock );
112     vlc_cond_init( &p_intf->p_sys->vout_wait );
113
114     vlc_mutex_init( &p_intf->p_sys->init_lock );
115     vlc_cond_init( &p_intf->p_sys->init_wait );
116
117     vlc_mutex_lock( &p_intf->p_sys->init_lock );
118     p_intf->p_sys->b_ready = false;
119
120     if( vlc_clone( &p_intf->p_sys->thread, Run, p_intf,
121                                VLC_THREAD_PRIORITY_LOW ) )
122     {
123         vlc_mutex_unlock( &p_intf->p_sys->init_lock );
124
125         vlc_cond_destroy( &p_intf->p_sys->init_wait );
126         vlc_mutex_destroy( &p_intf->p_sys->init_lock );
127         vlc_cond_destroy( &p_intf->p_sys->vout_wait );
128         vlc_mutex_destroy( &p_intf->p_sys->vout_lock );
129         free( p_intf->p_sys );
130         return VLC_EGENERIC;
131     }
132
133     while( !p_intf->p_sys->b_ready )
134         vlc_cond_wait( &p_intf->p_sys->init_wait, &p_intf->p_sys->init_lock );
135     vlc_mutex_unlock( &p_intf->p_sys->init_lock );
136
137     vlc_mutex_lock( &skin_load.mutex );
138     skin_load.intf = p_intf;
139     vlc_mutex_unlock( &skin_load.mutex );
140
141     return VLC_SUCCESS;
142 }
143
144 //---------------------------------------------------------------------------
145 // Close: destroy interface
146 //---------------------------------------------------------------------------
147 static void Close( vlc_object_t *p_this )
148 {
149     intf_thread_t *p_intf = (intf_thread_t *)p_this;
150
151     msg_Dbg( p_intf, "closing skins2 module" );
152
153     vlc_mutex_lock( &skin_load.mutex );
154     skin_load.intf = NULL;
155     vlc_mutex_unlock( &skin_load.mutex);
156
157     vlc_join( p_intf->p_sys->thread, NULL );
158
159     vlc_mutex_destroy( &p_intf->p_sys->init_lock );
160     vlc_cond_destroy( &p_intf->p_sys->init_wait );
161
162     // Unsubscribe from messages bank
163 #if 0
164     msg_Unsubscribe( p_intf, p_intf->p_sys->p_sub );
165 #endif
166
167     vlc_cond_destroy( &p_intf->p_sys->vout_wait );
168     vlc_mutex_destroy( &p_intf->p_sys->vout_lock );
169
170     // Destroy structure
171     free( p_intf->p_sys );
172 }
173
174
175 //---------------------------------------------------------------------------
176 // Run: main loop
177 //---------------------------------------------------------------------------
178 static void *Run( void * p_obj )
179 {
180     int canc = vlc_savecancel();
181
182     intf_thread_t *p_intf = (intf_thread_t *)p_obj;
183
184     bool b_error = false;
185     char *skin_last = NULL;
186     ThemeLoader *pLoader = NULL;
187     OSLoop *loop = NULL;
188
189     vlc_mutex_lock( &p_intf->p_sys->init_lock );
190
191     // Initialize singletons
192     if( OSFactory::instance( p_intf ) == NULL )
193     {
194         msg_Err( p_intf, "cannot initialize OSFactory" );
195         b_error = true;
196         goto end;
197     }
198     if( AsyncQueue::instance( p_intf ) == NULL )
199     {
200         msg_Err( p_intf, "cannot initialize AsyncQueue" );
201         b_error = true;
202         goto end;
203     }
204     if( Interpreter::instance( p_intf ) == NULL )
205     {
206         msg_Err( p_intf, "cannot instantiate Interpreter" );
207         b_error = true;
208         goto end;
209     }
210     if( VarManager::instance( p_intf ) == NULL )
211     {
212         msg_Err( p_intf, "cannot instantiate VarManager" );
213         b_error = true;
214         goto end;
215     }
216     if( VlcProc::instance( p_intf ) == NULL )
217     {
218         msg_Err( p_intf, "cannot initialize VLCProc" );
219         b_error = true;
220         goto end;
221     }
222     if( VoutManager::instance( p_intf ) == NULL )
223     {
224         msg_Err( p_intf, "cannot instantiate VoutManager" );
225         b_error = true;
226         goto end;
227     }
228     if( ArtManager::instance( p_intf ) == NULL )
229     {
230         msg_Err( p_intf, "cannot instantiate ArtManager" );
231         b_error = true;
232         goto end;
233     }
234     if( ThemeRepository::instance( p_intf ) == NULL )
235     {
236         msg_Err( p_intf, "cannot instantiate ThemeRepository" );
237         b_error = true;
238         goto end;
239     }
240     if( Dialogs::instance( p_intf ) == NULL )
241     {
242         msg_Err( p_intf, "cannot instantiate qt4 dialogs provider" );
243         b_error = true;
244         goto end;
245     }
246
247     // Load a theme
248     skin_last = config_GetPsz( p_intf, "skins2-last" );
249     pLoader = new ThemeLoader( p_intf );
250
251     if( !skin_last || !pLoader->load( skin_last ) )
252     {
253         // No skins (not even the default one). let's quit
254         CmdQuit *pCmd = new CmdQuit( p_intf );
255         AsyncQueue *pQueue = AsyncQueue::instance( p_intf );
256         pQueue->push( CmdGenericPtr( pCmd ) );
257         msg_Err( p_intf, "no skins found : exiting");
258     }
259
260     delete pLoader;
261     free( skin_last );
262
263     // Get the instance of OSLoop
264     loop = OSFactory::instance( p_intf )->getOSLoop();
265
266     // Signal the main thread this thread is now ready
267     p_intf->p_sys->b_ready = true;
268     vlc_cond_signal( &p_intf->p_sys->init_wait );
269     vlc_mutex_unlock( &p_intf->p_sys->init_lock );
270
271     // Enter the main event loop
272     loop->run();
273
274     // Destroy OSLoop
275     OSFactory::instance( p_intf )->destroyOSLoop();
276
277     // save and delete the theme
278     if( p_intf->p_sys->p_theme )
279     {
280         p_intf->p_sys->p_theme->saveConfig();
281
282         delete p_intf->p_sys->p_theme;
283         p_intf->p_sys->p_theme = NULL;
284
285         msg_Dbg( p_intf, "current theme deleted" );
286     }
287
288     // save config file
289     config_SaveConfigFile( p_intf, NULL );
290
291 end:
292     // Destroy "singleton" objects
293     Dialogs::destroy( p_intf );
294     ThemeRepository::destroy( p_intf );
295     ArtManager::destroy( p_intf );
296     VoutManager::destroy( p_intf );
297     VlcProc::destroy( p_intf );
298     VarManager::destroy( p_intf );
299     Interpreter::destroy( p_intf );
300     AsyncQueue::destroy( p_intf );
301     OSFactory::destroy( p_intf );
302
303     if( b_error )
304     {
305         p_intf->p_sys->b_ready = true;
306         vlc_cond_signal( &p_intf->p_sys->init_wait );
307         vlc_mutex_unlock( &p_intf->p_sys->init_lock );
308
309         libvlc_Quit( p_intf->p_libvlc );
310     }
311
312     vlc_restorecancel(canc);
313     return NULL;
314 }
315
316 static vlc_mutex_t serializer = VLC_STATIC_MUTEX;
317
318 // Callbacks for vout requests
319 static int WindowOpen( vlc_object_t *p_this )
320 {
321     vout_window_t *pWnd = (vout_window_t *)p_this;
322
323     vlc_mutex_lock( &skin_load.mutex );
324     intf_thread_t *pIntf = skin_load.intf;
325     if( pIntf )
326         vlc_object_hold( pIntf );
327     vlc_mutex_unlock( &skin_load.mutex );
328
329     if( pIntf == NULL )
330         return VLC_EGENERIC;
331
332     if( !vlc_object_alive( pIntf ) ||
333         !var_InheritBool( pIntf, "skinned-video") ||
334         pWnd->cfg->is_standalone )
335     {
336         vlc_object_release( pIntf );
337         return VLC_EGENERIC;
338     }
339
340     vlc_mutex_lock( &serializer );
341
342     pWnd->handle.hwnd = VoutManager::getWindow( pIntf, pWnd );
343
344     if( pWnd->handle.hwnd )
345     {
346         pWnd->control = &VoutManager::controlWindow;
347         pWnd->sys = (vout_window_sys_t*)pIntf;
348
349         vlc_mutex_unlock( &serializer );
350         return VLC_SUCCESS;
351     }
352     else
353     {
354         vlc_object_release( pIntf );
355         vlc_mutex_unlock( &serializer );
356         return VLC_EGENERIC;
357     }
358 }
359
360 static void WindowClose( vlc_object_t *p_this )
361 {
362     vout_window_t *pWnd = (vout_window_t *)p_this;
363     intf_thread_t *pIntf = (intf_thread_t *)pWnd->sys;
364
365     VoutManager::releaseWindow( pIntf, pWnd );
366
367     vlc_object_release( pIntf );
368 }
369
370
371 //---------------------------------------------------------------------------
372 // Module descriptor
373 //---------------------------------------------------------------------------
374 #define SKINS2_LAST      N_("Skin to use")
375 #define SKINS2_LAST_LONG N_("Path to the skin to use.")
376 #define SKINS2_CONFIG      N_("Config of last used skin")
377 #define SKINS2_CONFIG_LONG N_("Windows configuration of the last skin used. " \
378         "This option is updated automatically, do not touch it." )
379 #define SKINS2_SYSTRAY      N_("Systray icon")
380 #define SKINS2_SYSTRAY_LONG N_("Show a systray icon for VLC")
381 #define SKINS2_TASKBAR      N_("Show VLC on the taskbar")
382 #define SKINS2_TASKBAR_LONG N_("Show VLC on the taskbar")
383 #define SKINS2_TRANSPARENCY      N_("Enable transparency effects")
384 #define SKINS2_TRANSPARENCY_LONG N_("You can disable all transparency effects"\
385     " if you want. This is mainly useful when moving windows does not behave" \
386     " correctly.")
387 #define SKINS2_PLAYLIST N_("Use a skinned playlist")
388 #define SKINS2_PLAYLIST_LONG N_("Use a skinned playlist")
389 #define SKINS2_VIDEO N_("Display video in a skinned window if any")
390 #define SKINS2_VIDEO_LONG N_( \
391     "When set to 'no', this parameter is intended to give old skins a chance" \
392     " to play back video even though no video tag is implemented")
393
394 vlc_module_begin ()
395     set_category( CAT_INTERFACE )
396     set_subcategory( SUBCAT_INTERFACE_MAIN )
397     add_loadfile( "skins2-last", "", SKINS2_LAST, SKINS2_LAST_LONG,
398                   true )
399         change_autosave ()
400     add_string( "skins2-config", "", SKINS2_CONFIG, SKINS2_CONFIG_LONG,
401                 true )
402         change_autosave ()
403         change_private ()
404 #ifdef WIN32
405     add_bool( "skins2-systray", true, SKINS2_SYSTRAY,
406               SKINS2_SYSTRAY_LONG, false );
407     add_bool( "skins2-taskbar", true, SKINS2_TASKBAR,
408               SKINS2_TASKBAR_LONG, false );
409 #endif
410     add_bool( "skins2-transparency", false, SKINS2_TRANSPARENCY,
411               SKINS2_TRANSPARENCY_LONG, false );
412
413     add_bool( "skinned-playlist", true, SKINS2_PLAYLIST,
414               SKINS2_PLAYLIST_LONG, false );
415     add_bool( "skinned-video", true, SKINS2_VIDEO,
416               SKINS2_VIDEO_LONG, false );
417     set_shortname( N_("Skins"))
418     set_description( N_("Skinnable Interface") )
419     set_capability( "interface", 30 )
420     set_callbacks( Open, Close )
421     add_shortcut( "skins" )
422
423     add_submodule ()
424 #ifdef WIN32
425         set_capability( "vout window hwnd", 51 )
426 #else
427         set_capability( "vout window xid", 51 )
428 #endif
429         set_callbacks( WindowOpen, WindowClose )
430
431 vlc_module_end ()