]> git.sesse.net Git - vlc/blob - modules/gui/skins2/src/skin_main.cpp
Skins2: remove skins demux
[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 "../parser/interpreter.hpp"
47 #include "../commands/async_queue.hpp"
48 #include "../commands/cmd_quit.hpp"
49 #include "../commands/cmd_dialogs.hpp"
50 #include "../commands/cmd_minimize.hpp"
51 #include "../commands/cmd_playlist.hpp"
52
53 //---------------------------------------------------------------------------
54 // Exported interface functions.
55 //---------------------------------------------------------------------------
56 #ifdef WIN32_SKINS
57 extern "C" __declspec( dllexport )
58     int __VLC_SYMBOL( vlc_entry ) ( module_t *p_module );
59 #endif
60
61
62 //---------------------------------------------------------------------------
63 // Local prototypes
64 //---------------------------------------------------------------------------
65 static int  Open  ( vlc_object_t * );
66 static void Close ( vlc_object_t * );
67 static void *Run  ( void * );
68
69 //---------------------------------------------------------------------------
70 // Prototypes for configuration callbacks
71 //---------------------------------------------------------------------------
72 static int onSystrayChange( vlc_object_t *pObj, const char *pVariable,
73                             vlc_value_t oldVal, vlc_value_t newVal,
74                             void *pParam );
75 static int onTaskBarChange( vlc_object_t *pObj, const char *pVariable,
76                             vlc_value_t oldVal, vlc_value_t newVal,
77                             void *pParam );
78
79 static struct
80 {
81     intf_thread_t *intf;
82     vlc_mutex_t mutex;
83 } skin_load = { NULL, VLC_STATIC_MUTEX };
84
85 //---------------------------------------------------------------------------
86 // Open: initialize interface
87 //---------------------------------------------------------------------------
88 static int Open( vlc_object_t *p_this )
89 {
90     intf_thread_t *p_intf = (intf_thread_t *)p_this;
91
92     // Allocate instance and initialize some members
93     p_intf->p_sys = (intf_sys_t *) calloc( 1, sizeof( intf_sys_t ) );
94     if( p_intf->p_sys == NULL )
95         return VLC_ENOMEM;
96
97     // Suscribe to messages bank
98 #if 0
99     p_intf->p_sys->p_sub = msg_Subscribe( p_intf );
100 #endif
101
102     p_intf->p_sys->p_input = NULL;
103     p_intf->p_sys->p_playlist = pl_Get( p_intf );
104
105     // Initialize "singleton" objects
106     p_intf->p_sys->p_logger = NULL;
107     p_intf->p_sys->p_queue = NULL;
108     p_intf->p_sys->p_dialogs = NULL;
109     p_intf->p_sys->p_interpreter = NULL;
110     p_intf->p_sys->p_osFactory = NULL;
111     p_intf->p_sys->p_osLoop = NULL;
112     p_intf->p_sys->p_varManager = NULL;
113     p_intf->p_sys->p_voutManager = NULL;
114     p_intf->p_sys->p_vlcProc = NULL;
115     p_intf->p_sys->p_repository = NULL;
116
117     // No theme yet
118     p_intf->p_sys->p_theme = NULL;
119
120     vlc_mutex_init( &p_intf->p_sys->vout_lock );
121     vlc_cond_init( &p_intf->p_sys->vout_wait );
122
123     vlc_mutex_init( &p_intf->p_sys->init_lock );
124     vlc_cond_init( &p_intf->p_sys->init_wait );
125
126     vlc_mutex_lock( &p_intf->p_sys->init_lock );
127     p_intf->p_sys->b_ready = false;
128
129     if( vlc_clone( &p_intf->p_sys->thread, Run, p_intf,
130                                VLC_THREAD_PRIORITY_LOW ) )
131     {
132         vlc_mutex_unlock( &p_intf->p_sys->init_lock );
133
134         vlc_cond_destroy( &p_intf->p_sys->init_wait );
135         vlc_mutex_destroy( &p_intf->p_sys->init_lock );
136         vlc_cond_destroy( &p_intf->p_sys->vout_wait );
137         vlc_mutex_destroy( &p_intf->p_sys->vout_lock );
138         free( p_intf->p_sys );
139         return VLC_EGENERIC;
140     }
141
142     while( !p_intf->p_sys->b_ready )
143         vlc_cond_wait( &p_intf->p_sys->init_wait, &p_intf->p_sys->init_lock );
144     vlc_mutex_unlock( &p_intf->p_sys->init_lock );
145
146     vlc_mutex_lock( &skin_load.mutex );
147     skin_load.intf = p_intf;
148     vlc_mutex_unlock( &skin_load.mutex );
149
150     return VLC_SUCCESS;
151 }
152
153 //---------------------------------------------------------------------------
154 // Close: destroy interface
155 //---------------------------------------------------------------------------
156 static void Close( vlc_object_t *p_this )
157 {
158     intf_thread_t *p_intf = (intf_thread_t *)p_this;
159
160     msg_Dbg( p_intf, "closing skins2 module" );
161
162     vlc_mutex_lock( &skin_load.mutex );
163     skin_load.intf = NULL;
164     vlc_mutex_unlock( &skin_load.mutex);
165
166     vlc_join( p_intf->p_sys->thread, NULL );
167
168     vlc_mutex_destroy( &p_intf->p_sys->init_lock );
169     vlc_cond_destroy( &p_intf->p_sys->init_wait );
170
171     // Unsubscribe from messages bank
172 #if 0
173     msg_Unsubscribe( p_intf, p_intf->p_sys->p_sub );
174 #endif
175
176     vlc_cond_destroy( &p_intf->p_sys->vout_wait );
177     vlc_mutex_destroy( &p_intf->p_sys->vout_lock );
178
179     // Destroy structure
180     free( p_intf->p_sys );
181 }
182
183
184 //---------------------------------------------------------------------------
185 // Run: main loop
186 //---------------------------------------------------------------------------
187 static void *Run( void * p_obj )
188 {
189     int canc = vlc_savecancel();
190
191     intf_thread_t *p_intf = (intf_thread_t *)p_obj;
192
193     bool b_error = false;
194     char *skin_last = NULL;
195     ThemeLoader *pLoader = NULL;
196     OSLoop *loop = NULL;
197
198     vlc_mutex_lock( &p_intf->p_sys->init_lock );
199
200     // Initialize singletons
201     if( OSFactory::instance( p_intf ) == NULL )
202     {
203         msg_Err( p_intf, "cannot initialize OSFactory" );
204         b_error = true;
205         goto end;
206     }
207     if( AsyncQueue::instance( p_intf ) == NULL )
208     {
209         msg_Err( p_intf, "cannot initialize AsyncQueue" );
210         b_error = true;
211         goto end;
212     }
213     if( Interpreter::instance( p_intf ) == NULL )
214     {
215         msg_Err( p_intf, "cannot instanciate Interpreter" );
216         b_error = true;
217         goto end;
218     }
219     if( VarManager::instance( p_intf ) == NULL )
220     {
221         msg_Err( p_intf, "cannot instanciate VarManager" );
222         b_error = true;
223         goto end;
224     }
225     if( VlcProc::instance( p_intf ) == NULL )
226     {
227         msg_Err( p_intf, "cannot initialize VLCProc" );
228         b_error = true;
229         goto end;
230     }
231     if( VoutManager::instance( p_intf ) == NULL )
232     {
233         msg_Err( p_intf, "cannot instanciate VoutManager" );
234         b_error = true;
235         goto end;
236     }
237     if( ThemeRepository::instance( p_intf ) == NULL )
238     {
239         msg_Err( p_intf, "cannot instanciate ThemeRepository" );
240         b_error = true;
241         goto end;
242     }
243     if( Dialogs::instance( p_intf ) == NULL )
244     {
245         msg_Err( p_intf, "cannot instanciate qt4 dialogs provider" );
246         b_error = true;
247         goto end;
248     }
249
250     // Load a theme
251     skin_last = config_GetPsz( p_intf, "skins2-last" );
252     pLoader = new ThemeLoader( p_intf );
253
254     if( !skin_last || !pLoader->load( skin_last ) )
255     {
256         // No skins (not even the default one). let's quit
257         CmdQuit *pCmd = new CmdQuit( p_intf );
258         AsyncQueue *pQueue = AsyncQueue::instance( p_intf );
259         pQueue->push( CmdGenericPtr( pCmd ) );
260         msg_Err( p_intf, "no skins found : exiting");
261     }
262
263     delete pLoader;
264     free( skin_last );
265
266     // Get the instance of OSLoop
267     loop = OSFactory::instance( p_intf )->getOSLoop();
268
269     // Signal the main thread this thread is now ready
270     p_intf->p_sys->b_ready = true;
271     vlc_cond_signal( &p_intf->p_sys->init_wait );
272     vlc_mutex_unlock( &p_intf->p_sys->init_lock );
273
274     // Enter the main event loop
275     loop->run();
276
277     // Destroy OSLoop
278     OSFactory::instance( p_intf )->destroyOSLoop();
279
280     // save and delete the theme
281     if( p_intf->p_sys->p_theme )
282     {
283         p_intf->p_sys->p_theme->saveConfig();
284
285         delete p_intf->p_sys->p_theme;
286         p_intf->p_sys->p_theme = NULL;
287
288         msg_Dbg( p_intf, "current theme deleted" );
289     }
290
291     // save config file
292     config_SaveConfigFile( p_intf, NULL );
293
294 end:
295     // Destroy "singleton" objects
296     Dialogs::destroy( p_intf );
297     ThemeRepository::destroy( p_intf );
298     VoutManager::destroy( p_intf );
299     VlcProc::destroy( p_intf );
300     VarManager::destroy( p_intf );
301     Interpreter::destroy( p_intf );
302     AsyncQueue::destroy( p_intf );
303     OSFactory::destroy( p_intf );
304
305     if( b_error )
306     {
307         p_intf->p_sys->b_ready = true;
308         vlc_cond_signal( &p_intf->p_sys->init_wait );
309         vlc_mutex_unlock( &p_intf->p_sys->init_lock );
310
311         libvlc_Quit( p_intf->p_libvlc );
312     }
313
314     vlc_restorecancel(canc);
315     return NULL;
316 }
317
318 static vlc_mutex_t serializer = VLC_STATIC_MUTEX;
319
320 // Callbacks for vout requests
321 static int WindowOpen( vlc_object_t *p_this )
322 {
323     vout_window_t *pWnd = (vout_window_t *)p_this;
324
325     vlc_mutex_lock( &skin_load.mutex );
326     intf_thread_t *pIntf = skin_load.intf;
327     if( pIntf )
328         vlc_object_hold( pIntf );
329     vlc_mutex_unlock( &skin_load.mutex );
330
331     if( pIntf == NULL )
332         return VLC_EGENERIC;
333
334     if( !vlc_object_alive( pIntf ) ||
335         !var_InheritBool( pIntf, "skinned-video") ||
336         pWnd->cfg->is_standalone )
337     {
338         vlc_object_release( pIntf );
339         return VLC_EGENERIC;
340     }
341
342     vlc_mutex_lock( &serializer );
343
344     pWnd->handle.hwnd = VoutManager::getWindow( pIntf, pWnd );
345
346     if( pWnd->handle.hwnd )
347     {
348         pWnd->control = &VoutManager::controlWindow;
349         pWnd->sys = (vout_window_sys_t*)pIntf;
350
351         vlc_mutex_unlock( &serializer );
352         return VLC_SUCCESS;
353     }
354     else
355     {
356         vlc_object_release( pIntf );
357         vlc_mutex_unlock( &serializer );
358         return VLC_EGENERIC;
359     }
360 }
361
362 static void WindowClose( vlc_object_t *p_this )
363 {
364     vout_window_t *pWnd = (vout_window_t *)p_this;
365     intf_thread_t *pIntf = (intf_thread_t *)pWnd->sys;
366
367     VoutManager::releaseWindow( pIntf, pWnd );
368
369     vlc_object_release( pIntf );
370 }
371
372
373 //---------------------------------------------------------------------------
374 // Callbacks
375 //---------------------------------------------------------------------------
376
377 /// Callback for the systray configuration option
378 static int onSystrayChange( vlc_object_t *pObj, const char *pVariable,
379                             vlc_value_t oldVal, vlc_value_t newVal,
380                             void *pParam )
381 {
382     intf_thread_t *pIntf;
383
384     vlc_mutex_lock( &skin_load.mutex );
385     pIntf = skin_load.intf;
386     if( pIntf )
387         vlc_object_hold( pIntf );
388     vlc_mutex_unlock( &skin_load.mutex );
389
390     if( pIntf == NULL )
391     {
392         return VLC_EGENERIC;
393     }
394
395     AsyncQueue *pQueue = AsyncQueue::instance( pIntf );
396     if( newVal.b_bool )
397     {
398         CmdAddInTray *pCmd = new CmdAddInTray( pIntf );
399         pQueue->push( CmdGenericPtr( pCmd ) );
400     }
401     else
402     {
403         CmdRemoveFromTray *pCmd = new CmdRemoveFromTray( pIntf );
404         pQueue->push( CmdGenericPtr( pCmd ) );
405     }
406
407     vlc_object_release( pIntf );
408     return VLC_SUCCESS;
409 }
410
411
412 /// Callback for the systray configuration option
413 static int onTaskBarChange( vlc_object_t *pObj, const char *pVariable,
414                             vlc_value_t oldVal, vlc_value_t newVal,
415                             void *pParam )
416 {
417     intf_thread_t *pIntf;
418
419     vlc_mutex_lock( &skin_load.mutex );
420     pIntf = skin_load.intf;
421     if( pIntf )
422         vlc_object_hold( pIntf );
423     vlc_mutex_unlock( &skin_load.mutex );
424
425     if( pIntf == NULL )
426     {
427         return VLC_EGENERIC;
428     }
429
430     AsyncQueue *pQueue = AsyncQueue::instance( pIntf );
431     if( newVal.b_bool )
432     {
433         CmdAddInTaskBar *pCmd = new CmdAddInTaskBar( pIntf );
434         pQueue->push( CmdGenericPtr( pCmd ) );
435     }
436     else
437     {
438         CmdRemoveFromTaskBar *pCmd = new CmdRemoveFromTaskBar( pIntf );
439         pQueue->push( CmdGenericPtr( pCmd ) );
440     }
441
442     vlc_object_release( pIntf );
443     return VLC_SUCCESS;
444 }
445
446
447 //---------------------------------------------------------------------------
448 // Module descriptor
449 //---------------------------------------------------------------------------
450 #define SKINS2_LAST      N_("Skin to use")
451 #define SKINS2_LAST_LONG N_("Path to the skin to use.")
452 #define SKINS2_CONFIG      N_("Config of last used skin")
453 #define SKINS2_CONFIG_LONG N_("Windows configuration of the last skin used. " \
454         "This option is updated automatically, do not touch it." )
455 #define SKINS2_SYSTRAY      N_("Systray icon")
456 #define SKINS2_SYSTRAY_LONG N_("Show a systray icon for VLC")
457 #define SKINS2_TASKBAR      N_("Show VLC on the taskbar")
458 #define SKINS2_TASKBAR_LONG N_("Show VLC on the taskbar")
459 #define SKINS2_TRANSPARENCY      N_("Enable transparency effects")
460 #define SKINS2_TRANSPARENCY_LONG N_("You can disable all transparency effects"\
461     " if you want. This is mainly useful when moving windows does not behave" \
462     " correctly.")
463 #define SKINS2_PLAYLIST N_("Use a skinned playlist")
464 #define SKINS2_PLAYLIST_LONG N_("Use a skinned playlist")
465 #define SKINS2_VIDEO N_("Display video in a skinned window if any")
466 #define SKINS2_VIDEO_LONG N_( \
467     "When set to 'no', this parameter is intended to give old skins a chance" \
468     " to play back video even though no video tag is implemented")
469
470 vlc_module_begin ()
471     set_category( CAT_INTERFACE )
472     set_subcategory( SUBCAT_INTERFACE_MAIN )
473     add_file( "skins2-last", "", NULL, SKINS2_LAST, SKINS2_LAST_LONG,
474               true )
475         change_autosave ()
476     add_string( "skins2-config", "", NULL, SKINS2_CONFIG, SKINS2_CONFIG_LONG,
477                 true )
478         change_autosave ()
479         change_private ()
480 #ifdef WIN32
481     add_bool( "skins2-systray", false, onSystrayChange, SKINS2_SYSTRAY,
482               SKINS2_SYSTRAY_LONG, false );
483     add_bool( "skins2-taskbar", true, onTaskBarChange, SKINS2_TASKBAR,
484               SKINS2_TASKBAR_LONG, false );
485 #endif
486     add_bool( "skins2-transparency", false, NULL, SKINS2_TRANSPARENCY,
487               SKINS2_TRANSPARENCY_LONG, false );
488
489     add_bool( "skinned-playlist", true, NULL, SKINS2_PLAYLIST,
490               SKINS2_PLAYLIST_LONG, false );
491     add_bool( "skinned-video", true, NULL, SKINS2_VIDEO,
492               SKINS2_VIDEO_LONG, false );
493     set_shortname( N_("Skins"))
494     set_description( N_("Skinnable Interface") )
495     set_capability( "interface", 30 )
496     set_callbacks( Open, Close )
497     add_shortcut( "skins" )
498
499     add_submodule ()
500 #ifdef WIN32
501         set_capability( "vout window hwnd", 51 )
502 #else
503         set_capability( "vout window xid", 51 )
504 #endif
505         set_callbacks( WindowOpen, WindowClose )
506
507 vlc_module_end ()