1 /*****************************************************************************
3 *****************************************************************************
4 * Copyright (C) 2003 the VideoLAN team
7 * Authors: Cyril Deguet <asmax@via.ecp.fr>
8 * Olivier Teulière <ipkiss@via.ecp.fr>
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.
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.
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 *****************************************************************************/
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>
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"
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"
54 //---------------------------------------------------------------------------
55 // Exported interface functions.
56 //---------------------------------------------------------------------------
58 extern "C" __declspec( dllexport )
59 int __VLC_SYMBOL( vlc_entry ) ( module_t *p_module );
63 //---------------------------------------------------------------------------
65 //---------------------------------------------------------------------------
66 static int Open ( vlc_object_t * );
67 static void Close ( vlc_object_t * );
68 static void *Run ( void * );
70 //---------------------------------------------------------------------------
71 // Prototypes for configuration callbacks
72 //---------------------------------------------------------------------------
73 static int onSystrayChange( vlc_object_t *pObj, const char *pVariable,
74 vlc_value_t oldVal, vlc_value_t newVal,
76 static int onTaskBarChange( vlc_object_t *pObj, const char *pVariable,
77 vlc_value_t oldVal, vlc_value_t newVal,
84 } skin_load = { NULL, VLC_STATIC_MUTEX };
86 //---------------------------------------------------------------------------
87 // Open: initialize interface
88 //---------------------------------------------------------------------------
89 static int Open( vlc_object_t *p_this )
91 intf_thread_t *p_intf = (intf_thread_t *)p_this;
93 // Allocate instance and initialize some members
94 p_intf->p_sys = (intf_sys_t *) calloc( 1, sizeof( intf_sys_t ) );
95 if( p_intf->p_sys == NULL )
98 // Suscribe to messages bank
100 p_intf->p_sys->p_sub = msg_Subscribe( p_intf );
103 p_intf->p_sys->p_input = NULL;
104 p_intf->p_sys->p_playlist = pl_Get( p_intf );
106 // Initialize "singleton" objects
107 p_intf->p_sys->p_logger = NULL;
108 p_intf->p_sys->p_queue = NULL;
109 p_intf->p_sys->p_dialogs = NULL;
110 p_intf->p_sys->p_interpreter = NULL;
111 p_intf->p_sys->p_osFactory = NULL;
112 p_intf->p_sys->p_osLoop = NULL;
113 p_intf->p_sys->p_varManager = NULL;
114 p_intf->p_sys->p_voutManager = NULL;
115 p_intf->p_sys->p_vlcProc = NULL;
116 p_intf->p_sys->p_repository = NULL;
119 p_intf->p_sys->p_theme = NULL;
121 vlc_mutex_init( &p_intf->p_sys->vout_lock );
122 vlc_cond_init( &p_intf->p_sys->vout_wait );
124 vlc_mutex_init( &p_intf->p_sys->init_lock );
125 vlc_cond_init( &p_intf->p_sys->init_wait );
127 vlc_mutex_lock( &p_intf->p_sys->init_lock );
128 p_intf->p_sys->b_ready = false;
130 if( vlc_clone( &p_intf->p_sys->thread, Run, p_intf,
131 VLC_THREAD_PRIORITY_LOW ) )
133 vlc_mutex_unlock( &p_intf->p_sys->init_lock );
135 vlc_cond_destroy( &p_intf->p_sys->init_wait );
136 vlc_mutex_destroy( &p_intf->p_sys->init_lock );
137 vlc_cond_destroy( &p_intf->p_sys->vout_wait );
138 vlc_mutex_destroy( &p_intf->p_sys->vout_lock );
139 free( p_intf->p_sys );
143 while( !p_intf->p_sys->b_ready )
144 vlc_cond_wait( &p_intf->p_sys->init_wait, &p_intf->p_sys->init_lock );
145 vlc_mutex_unlock( &p_intf->p_sys->init_lock );
147 vlc_mutex_lock( &skin_load.mutex );
148 skin_load.intf = p_intf;
149 vlc_mutex_unlock( &skin_load.mutex );
154 //---------------------------------------------------------------------------
155 // Close: destroy interface
156 //---------------------------------------------------------------------------
157 static void Close( vlc_object_t *p_this )
159 intf_thread_t *p_intf = (intf_thread_t *)p_this;
161 msg_Dbg( p_intf, "closing skins2 module" );
163 vlc_mutex_lock( &skin_load.mutex );
164 skin_load.intf = NULL;
165 vlc_mutex_unlock( &skin_load.mutex);
167 vlc_join( p_intf->p_sys->thread, NULL );
169 vlc_mutex_destroy( &p_intf->p_sys->init_lock );
170 vlc_cond_destroy( &p_intf->p_sys->init_wait );
172 // Unsubscribe from messages bank
174 msg_Unsubscribe( p_intf, p_intf->p_sys->p_sub );
177 vlc_cond_destroy( &p_intf->p_sys->vout_wait );
178 vlc_mutex_destroy( &p_intf->p_sys->vout_lock );
181 free( p_intf->p_sys );
185 //---------------------------------------------------------------------------
187 //---------------------------------------------------------------------------
188 static void *Run( void * p_obj )
190 int canc = vlc_savecancel();
192 intf_thread_t *p_intf = (intf_thread_t *)p_obj;
194 bool b_error = false;
195 char *skin_last = NULL;
196 ThemeLoader *pLoader = NULL;
199 vlc_mutex_lock( &p_intf->p_sys->init_lock );
201 // Initialize singletons
202 if( OSFactory::instance( p_intf ) == NULL )
204 msg_Err( p_intf, "cannot initialize OSFactory" );
208 if( AsyncQueue::instance( p_intf ) == NULL )
210 msg_Err( p_intf, "cannot initialize AsyncQueue" );
214 if( Interpreter::instance( p_intf ) == NULL )
216 msg_Err( p_intf, "cannot instantiate Interpreter" );
220 if( VarManager::instance( p_intf ) == NULL )
222 msg_Err( p_intf, "cannot instantiate VarManager" );
226 if( VlcProc::instance( p_intf ) == NULL )
228 msg_Err( p_intf, "cannot initialize VLCProc" );
232 if( VoutManager::instance( p_intf ) == NULL )
234 msg_Err( p_intf, "cannot instantiate VoutManager" );
238 if( ArtManager::instance( p_intf ) == NULL )
240 msg_Err( p_intf, "cannot instantiate ArtManager" );
244 if( ThemeRepository::instance( p_intf ) == NULL )
246 msg_Err( p_intf, "cannot instantiate ThemeRepository" );
250 if( Dialogs::instance( p_intf ) == NULL )
252 msg_Err( p_intf, "cannot instantiate qt4 dialogs provider" );
258 skin_last = config_GetPsz( p_intf, "skins2-last" );
259 pLoader = new ThemeLoader( p_intf );
261 if( !skin_last || !pLoader->load( skin_last ) )
263 // No skins (not even the default one). let's quit
264 CmdQuit *pCmd = new CmdQuit( p_intf );
265 AsyncQueue *pQueue = AsyncQueue::instance( p_intf );
266 pQueue->push( CmdGenericPtr( pCmd ) );
267 msg_Err( p_intf, "no skins found : exiting");
273 // Get the instance of OSLoop
274 loop = OSFactory::instance( p_intf )->getOSLoop();
276 // Signal the main thread this thread is now ready
277 p_intf->p_sys->b_ready = true;
278 vlc_cond_signal( &p_intf->p_sys->init_wait );
279 vlc_mutex_unlock( &p_intf->p_sys->init_lock );
281 // Enter the main event loop
285 OSFactory::instance( p_intf )->destroyOSLoop();
287 // save and delete the theme
288 if( p_intf->p_sys->p_theme )
290 p_intf->p_sys->p_theme->saveConfig();
292 delete p_intf->p_sys->p_theme;
293 p_intf->p_sys->p_theme = NULL;
295 msg_Dbg( p_intf, "current theme deleted" );
299 config_SaveConfigFile( p_intf, NULL );
302 // Destroy "singleton" objects
303 Dialogs::destroy( p_intf );
304 ThemeRepository::destroy( p_intf );
305 ArtManager::destroy( p_intf );
306 VoutManager::destroy( p_intf );
307 VlcProc::destroy( p_intf );
308 VarManager::destroy( p_intf );
309 Interpreter::destroy( p_intf );
310 AsyncQueue::destroy( p_intf );
311 OSFactory::destroy( p_intf );
315 p_intf->p_sys->b_ready = true;
316 vlc_cond_signal( &p_intf->p_sys->init_wait );
317 vlc_mutex_unlock( &p_intf->p_sys->init_lock );
319 libvlc_Quit( p_intf->p_libvlc );
322 vlc_restorecancel(canc);
326 static vlc_mutex_t serializer = VLC_STATIC_MUTEX;
328 // Callbacks for vout requests
329 static int WindowOpen( vlc_object_t *p_this )
331 vout_window_t *pWnd = (vout_window_t *)p_this;
333 vlc_mutex_lock( &skin_load.mutex );
334 intf_thread_t *pIntf = skin_load.intf;
336 vlc_object_hold( pIntf );
337 vlc_mutex_unlock( &skin_load.mutex );
342 if( !vlc_object_alive( pIntf ) ||
343 !var_InheritBool( pIntf, "skinned-video") ||
344 pWnd->cfg->is_standalone )
346 vlc_object_release( pIntf );
350 vlc_mutex_lock( &serializer );
352 pWnd->handle.hwnd = VoutManager::getWindow( pIntf, pWnd );
354 if( pWnd->handle.hwnd )
356 pWnd->control = &VoutManager::controlWindow;
357 pWnd->sys = (vout_window_sys_t*)pIntf;
359 vlc_mutex_unlock( &serializer );
364 vlc_object_release( pIntf );
365 vlc_mutex_unlock( &serializer );
370 static void WindowClose( vlc_object_t *p_this )
372 vout_window_t *pWnd = (vout_window_t *)p_this;
373 intf_thread_t *pIntf = (intf_thread_t *)pWnd->sys;
375 VoutManager::releaseWindow( pIntf, pWnd );
377 vlc_object_release( pIntf );
381 //---------------------------------------------------------------------------
383 //---------------------------------------------------------------------------
385 /// Callback for the systray configuration option
386 static int onSystrayChange( vlc_object_t *pObj, const char *pVariable,
387 vlc_value_t oldVal, vlc_value_t newVal,
390 intf_thread_t *pIntf;
392 vlc_mutex_lock( &skin_load.mutex );
393 pIntf = skin_load.intf;
395 vlc_object_hold( pIntf );
396 vlc_mutex_unlock( &skin_load.mutex );
403 AsyncQueue *pQueue = AsyncQueue::instance( pIntf );
406 CmdAddInTray *pCmd = new CmdAddInTray( pIntf );
407 pQueue->push( CmdGenericPtr( pCmd ) );
411 CmdRemoveFromTray *pCmd = new CmdRemoveFromTray( pIntf );
412 pQueue->push( CmdGenericPtr( pCmd ) );
415 vlc_object_release( pIntf );
420 /// Callback for the systray configuration option
421 static int onTaskBarChange( vlc_object_t *pObj, const char *pVariable,
422 vlc_value_t oldVal, vlc_value_t newVal,
425 intf_thread_t *pIntf;
427 vlc_mutex_lock( &skin_load.mutex );
428 pIntf = skin_load.intf;
430 vlc_object_hold( pIntf );
431 vlc_mutex_unlock( &skin_load.mutex );
438 AsyncQueue *pQueue = AsyncQueue::instance( pIntf );
441 CmdAddInTaskBar *pCmd = new CmdAddInTaskBar( pIntf );
442 pQueue->push( CmdGenericPtr( pCmd ) );
446 CmdRemoveFromTaskBar *pCmd = new CmdRemoveFromTaskBar( pIntf );
447 pQueue->push( CmdGenericPtr( pCmd ) );
450 vlc_object_release( pIntf );
455 //---------------------------------------------------------------------------
457 //---------------------------------------------------------------------------
458 #define SKINS2_LAST N_("Skin to use")
459 #define SKINS2_LAST_LONG N_("Path to the skin to use.")
460 #define SKINS2_CONFIG N_("Config of last used skin")
461 #define SKINS2_CONFIG_LONG N_("Windows configuration of the last skin used. " \
462 "This option is updated automatically, do not touch it." )
463 #define SKINS2_SYSTRAY N_("Systray icon")
464 #define SKINS2_SYSTRAY_LONG N_("Show a systray icon for VLC")
465 #define SKINS2_TASKBAR N_("Show VLC on the taskbar")
466 #define SKINS2_TASKBAR_LONG N_("Show VLC on the taskbar")
467 #define SKINS2_TRANSPARENCY N_("Enable transparency effects")
468 #define SKINS2_TRANSPARENCY_LONG N_("You can disable all transparency effects"\
469 " if you want. This is mainly useful when moving windows does not behave" \
471 #define SKINS2_PLAYLIST N_("Use a skinned playlist")
472 #define SKINS2_PLAYLIST_LONG N_("Use a skinned playlist")
473 #define SKINS2_VIDEO N_("Display video in a skinned window if any")
474 #define SKINS2_VIDEO_LONG N_( \
475 "When set to 'no', this parameter is intended to give old skins a chance" \
476 " to play back video even though no video tag is implemented")
479 set_category( CAT_INTERFACE )
480 set_subcategory( SUBCAT_INTERFACE_MAIN )
481 add_file( "skins2-last", "", NULL, SKINS2_LAST, SKINS2_LAST_LONG,
484 add_string( "skins2-config", "", NULL, SKINS2_CONFIG, SKINS2_CONFIG_LONG,
489 add_bool( "skins2-systray", false, onSystrayChange, SKINS2_SYSTRAY,
490 SKINS2_SYSTRAY_LONG, false );
491 add_bool( "skins2-taskbar", true, onTaskBarChange, SKINS2_TASKBAR,
492 SKINS2_TASKBAR_LONG, false );
494 add_bool( "skins2-transparency", false, NULL, SKINS2_TRANSPARENCY,
495 SKINS2_TRANSPARENCY_LONG, false );
497 add_bool( "skinned-playlist", true, NULL, SKINS2_PLAYLIST,
498 SKINS2_PLAYLIST_LONG, false );
499 add_bool( "skinned-video", true, NULL, SKINS2_VIDEO,
500 SKINS2_VIDEO_LONG, false );
501 set_shortname( N_("Skins"))
502 set_description( N_("Skinnable Interface") )
503 set_capability( "interface", 30 )
504 set_callbacks( Open, Close )
505 add_shortcut( "skins" )
509 set_capability( "vout window hwnd", 51 )
511 set_capability( "vout window xid", 51 )
513 set_callbacks( WindowOpen, WindowClose )