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 "../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"
53 //---------------------------------------------------------------------------
54 // Exported interface functions.
55 //---------------------------------------------------------------------------
57 extern "C" __declspec( dllexport )
58 int __VLC_SYMBOL( vlc_entry ) ( module_t *p_module );
62 //---------------------------------------------------------------------------
64 //---------------------------------------------------------------------------
65 static int Open ( vlc_object_t * );
66 static void Close ( vlc_object_t * );
67 static void *Run ( void * );
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,
75 static int onTaskBarChange( vlc_object_t *pObj, const char *pVariable,
76 vlc_value_t oldVal, vlc_value_t newVal,
83 } skin_load = { NULL, VLC_STATIC_MUTEX };
85 //---------------------------------------------------------------------------
86 // Open: initialize interface
87 //---------------------------------------------------------------------------
88 static int Open( vlc_object_t *p_this )
90 intf_thread_t *p_intf = (intf_thread_t *)p_this;
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 )
97 // Suscribe to messages bank
99 p_intf->p_sys->p_sub = msg_Subscribe( p_intf );
102 p_intf->p_sys->p_input = NULL;
103 p_intf->p_sys->p_playlist = pl_Get( p_intf );
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;
118 p_intf->p_sys->p_theme = NULL;
120 vlc_mutex_init( &p_intf->p_sys->vout_lock );
121 vlc_cond_init( &p_intf->p_sys->vout_wait );
123 vlc_mutex_init( &p_intf->p_sys->init_lock );
124 vlc_cond_init( &p_intf->p_sys->init_wait );
126 vlc_mutex_lock( &p_intf->p_sys->init_lock );
127 p_intf->p_sys->b_ready = false;
129 if( vlc_clone( &p_intf->p_sys->thread, Run, p_intf,
130 VLC_THREAD_PRIORITY_LOW ) )
132 vlc_mutex_unlock( &p_intf->p_sys->init_lock );
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 );
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 );
146 vlc_mutex_lock( &skin_load.mutex );
147 skin_load.intf = p_intf;
148 vlc_mutex_unlock( &skin_load.mutex );
153 //---------------------------------------------------------------------------
154 // Close: destroy interface
155 //---------------------------------------------------------------------------
156 static void Close( vlc_object_t *p_this )
158 intf_thread_t *p_intf = (intf_thread_t *)p_this;
160 msg_Dbg( p_intf, "closing skins2 module" );
162 vlc_mutex_lock( &skin_load.mutex );
163 skin_load.intf = NULL;
164 vlc_mutex_unlock( &skin_load.mutex);
166 vlc_join( p_intf->p_sys->thread, NULL );
168 vlc_mutex_destroy( &p_intf->p_sys->init_lock );
169 vlc_cond_destroy( &p_intf->p_sys->init_wait );
171 // Unsubscribe from messages bank
173 msg_Unsubscribe( p_intf, p_intf->p_sys->p_sub );
176 vlc_cond_destroy( &p_intf->p_sys->vout_wait );
177 vlc_mutex_destroy( &p_intf->p_sys->vout_lock );
180 free( p_intf->p_sys );
184 //---------------------------------------------------------------------------
186 //---------------------------------------------------------------------------
187 static void *Run( void * p_obj )
189 int canc = vlc_savecancel();
191 intf_thread_t *p_intf = (intf_thread_t *)p_obj;
193 bool b_error = false;
194 char *skin_last = NULL;
195 ThemeLoader *pLoader = NULL;
198 vlc_mutex_lock( &p_intf->p_sys->init_lock );
200 // Initialize singletons
201 if( OSFactory::instance( p_intf ) == NULL )
203 msg_Err( p_intf, "cannot initialize OSFactory" );
207 if( AsyncQueue::instance( p_intf ) == NULL )
209 msg_Err( p_intf, "cannot initialize AsyncQueue" );
213 if( Interpreter::instance( p_intf ) == NULL )
215 msg_Err( p_intf, "cannot instanciate Interpreter" );
219 if( VarManager::instance( p_intf ) == NULL )
221 msg_Err( p_intf, "cannot instanciate VarManager" );
225 if( VlcProc::instance( p_intf ) == NULL )
227 msg_Err( p_intf, "cannot initialize VLCProc" );
231 if( VoutManager::instance( p_intf ) == NULL )
233 msg_Err( p_intf, "cannot instanciate VoutManager" );
237 if( ThemeRepository::instance( p_intf ) == NULL )
239 msg_Err( p_intf, "cannot instanciate ThemeRepository" );
243 if( Dialogs::instance( p_intf ) == NULL )
245 msg_Err( p_intf, "cannot instanciate qt4 dialogs provider" );
251 skin_last = config_GetPsz( p_intf, "skins2-last" );
252 pLoader = new ThemeLoader( p_intf );
254 if( !skin_last || !pLoader->load( skin_last ) )
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");
266 // Get the instance of OSLoop
267 loop = OSFactory::instance( p_intf )->getOSLoop();
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 );
274 // Enter the main event loop
278 OSFactory::instance( p_intf )->destroyOSLoop();
280 // save and delete the theme
281 if( p_intf->p_sys->p_theme )
283 p_intf->p_sys->p_theme->saveConfig();
285 delete p_intf->p_sys->p_theme;
286 p_intf->p_sys->p_theme = NULL;
288 msg_Dbg( p_intf, "current theme deleted" );
292 config_SaveConfigFile( p_intf, NULL );
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 );
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 );
311 libvlc_Quit( p_intf->p_libvlc );
314 vlc_restorecancel(canc);
318 static vlc_mutex_t serializer = VLC_STATIC_MUTEX;
320 // Callbacks for vout requests
321 static int WindowOpen( vlc_object_t *p_this )
323 vout_window_t *pWnd = (vout_window_t *)p_this;
325 vlc_mutex_lock( &skin_load.mutex );
326 intf_thread_t *pIntf = skin_load.intf;
328 vlc_object_hold( pIntf );
329 vlc_mutex_unlock( &skin_load.mutex );
334 if( !vlc_object_alive( pIntf ) ||
335 !var_InheritBool( pIntf, "skinned-video") ||
336 pWnd->cfg->is_standalone )
338 vlc_object_release( pIntf );
342 vlc_mutex_lock( &serializer );
344 pWnd->handle.hwnd = VoutManager::getWindow( pIntf, pWnd );
346 if( pWnd->handle.hwnd )
348 pWnd->control = &VoutManager::controlWindow;
349 pWnd->sys = (vout_window_sys_t*)pIntf;
351 vlc_mutex_unlock( &serializer );
356 vlc_object_release( pIntf );
357 vlc_mutex_unlock( &serializer );
362 static void WindowClose( vlc_object_t *p_this )
364 vout_window_t *pWnd = (vout_window_t *)p_this;
365 intf_thread_t *pIntf = (intf_thread_t *)pWnd->sys;
367 VoutManager::releaseWindow( pIntf, pWnd );
369 vlc_object_release( pIntf );
373 //---------------------------------------------------------------------------
375 //---------------------------------------------------------------------------
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,
382 intf_thread_t *pIntf;
384 vlc_mutex_lock( &skin_load.mutex );
385 pIntf = skin_load.intf;
387 vlc_object_hold( pIntf );
388 vlc_mutex_unlock( &skin_load.mutex );
395 AsyncQueue *pQueue = AsyncQueue::instance( pIntf );
398 CmdAddInTray *pCmd = new CmdAddInTray( pIntf );
399 pQueue->push( CmdGenericPtr( pCmd ) );
403 CmdRemoveFromTray *pCmd = new CmdRemoveFromTray( pIntf );
404 pQueue->push( CmdGenericPtr( pCmd ) );
407 vlc_object_release( pIntf );
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,
417 intf_thread_t *pIntf;
419 vlc_mutex_lock( &skin_load.mutex );
420 pIntf = skin_load.intf;
422 vlc_object_hold( pIntf );
423 vlc_mutex_unlock( &skin_load.mutex );
430 AsyncQueue *pQueue = AsyncQueue::instance( pIntf );
433 CmdAddInTaskBar *pCmd = new CmdAddInTaskBar( pIntf );
434 pQueue->push( CmdGenericPtr( pCmd ) );
438 CmdRemoveFromTaskBar *pCmd = new CmdRemoveFromTaskBar( pIntf );
439 pQueue->push( CmdGenericPtr( pCmd ) );
442 vlc_object_release( pIntf );
447 //---------------------------------------------------------------------------
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" \
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")
471 set_category( CAT_INTERFACE )
472 set_subcategory( SUBCAT_INTERFACE_MAIN )
473 add_file( "skins2-last", "", NULL, SKINS2_LAST, SKINS2_LAST_LONG,
476 add_string( "skins2-config", "", NULL, SKINS2_CONFIG, SKINS2_CONFIG_LONG,
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 );
486 add_bool( "skins2-transparency", false, NULL, SKINS2_TRANSPARENCY,
487 SKINS2_TRANSPARENCY_LONG, false );
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" )
501 set_capability( "vout window hwnd", 51 )
503 set_capability( "vout window xid", 51 )
505 set_callbacks( WindowOpen, WindowClose )