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 * );
74 } skin_load = { NULL, VLC_STATIC_MUTEX };
76 //---------------------------------------------------------------------------
77 // Open: initialize interface
78 //---------------------------------------------------------------------------
79 static int Open( vlc_object_t *p_this )
81 intf_thread_t *p_intf = (intf_thread_t *)p_this;
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 )
88 // Suscribe to messages bank
90 p_intf->p_sys->p_sub = msg_Subscribe( p_intf );
93 p_intf->p_sys->p_input = NULL;
94 p_intf->p_sys->p_playlist = pl_Get( p_intf );
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;
109 p_intf->p_sys->p_theme = NULL;
111 vlc_mutex_init( &p_intf->p_sys->vout_lock );
112 vlc_cond_init( &p_intf->p_sys->vout_wait );
114 vlc_mutex_init( &p_intf->p_sys->init_lock );
115 vlc_cond_init( &p_intf->p_sys->init_wait );
117 vlc_mutex_lock( &p_intf->p_sys->init_lock );
118 p_intf->p_sys->b_ready = false;
120 if( vlc_clone( &p_intf->p_sys->thread, Run, p_intf,
121 VLC_THREAD_PRIORITY_LOW ) )
123 vlc_mutex_unlock( &p_intf->p_sys->init_lock );
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 );
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 );
137 vlc_mutex_lock( &skin_load.mutex );
138 skin_load.intf = p_intf;
139 vlc_mutex_unlock( &skin_load.mutex );
144 //---------------------------------------------------------------------------
145 // Close: destroy interface
146 //---------------------------------------------------------------------------
147 static void Close( vlc_object_t *p_this )
149 intf_thread_t *p_intf = (intf_thread_t *)p_this;
151 msg_Dbg( p_intf, "closing skins2 module" );
153 vlc_mutex_lock( &skin_load.mutex );
154 skin_load.intf = NULL;
155 vlc_mutex_unlock( &skin_load.mutex);
157 vlc_join( p_intf->p_sys->thread, NULL );
159 vlc_mutex_destroy( &p_intf->p_sys->init_lock );
160 vlc_cond_destroy( &p_intf->p_sys->init_wait );
162 // Unsubscribe from messages bank
164 msg_Unsubscribe( p_intf, p_intf->p_sys->p_sub );
167 vlc_cond_destroy( &p_intf->p_sys->vout_wait );
168 vlc_mutex_destroy( &p_intf->p_sys->vout_lock );
171 free( p_intf->p_sys );
175 //---------------------------------------------------------------------------
177 //---------------------------------------------------------------------------
178 static void *Run( void * p_obj )
180 int canc = vlc_savecancel();
182 intf_thread_t *p_intf = (intf_thread_t *)p_obj;
184 bool b_error = false;
185 char *skin_last = NULL;
186 ThemeLoader *pLoader = NULL;
189 vlc_mutex_lock( &p_intf->p_sys->init_lock );
191 // Initialize singletons
192 if( OSFactory::instance( p_intf ) == NULL )
194 msg_Err( p_intf, "cannot initialize OSFactory" );
198 if( AsyncQueue::instance( p_intf ) == NULL )
200 msg_Err( p_intf, "cannot initialize AsyncQueue" );
204 if( Interpreter::instance( p_intf ) == NULL )
206 msg_Err( p_intf, "cannot instantiate Interpreter" );
210 if( VarManager::instance( p_intf ) == NULL )
212 msg_Err( p_intf, "cannot instantiate VarManager" );
216 if( VlcProc::instance( p_intf ) == NULL )
218 msg_Err( p_intf, "cannot initialize VLCProc" );
222 if( VoutManager::instance( p_intf ) == NULL )
224 msg_Err( p_intf, "cannot instantiate VoutManager" );
228 if( ArtManager::instance( p_intf ) == NULL )
230 msg_Err( p_intf, "cannot instantiate ArtManager" );
234 if( ThemeRepository::instance( p_intf ) == NULL )
236 msg_Err( p_intf, "cannot instantiate ThemeRepository" );
240 if( Dialogs::instance( p_intf ) == NULL )
242 msg_Err( p_intf, "cannot instantiate qt4 dialogs provider" );
248 skin_last = config_GetPsz( p_intf, "skins2-last" );
249 pLoader = new ThemeLoader( p_intf );
251 if( !skin_last || !pLoader->load( skin_last ) )
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");
263 // Get the instance of OSLoop
264 loop = OSFactory::instance( p_intf )->getOSLoop();
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 );
271 // Enter the main event loop
275 OSFactory::instance( p_intf )->destroyOSLoop();
277 // save and delete the theme
278 if( p_intf->p_sys->p_theme )
280 p_intf->p_sys->p_theme->saveConfig();
282 delete p_intf->p_sys->p_theme;
283 p_intf->p_sys->p_theme = NULL;
285 msg_Dbg( p_intf, "current theme deleted" );
289 config_SaveConfigFile( p_intf, NULL );
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 );
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 );
309 libvlc_Quit( p_intf->p_libvlc );
312 vlc_restorecancel(canc);
316 static vlc_mutex_t serializer = VLC_STATIC_MUTEX;
318 // Callbacks for vout requests
319 static int WindowOpen( vlc_object_t *p_this )
321 vout_window_t *pWnd = (vout_window_t *)p_this;
323 vlc_mutex_lock( &skin_load.mutex );
324 intf_thread_t *pIntf = skin_load.intf;
326 vlc_object_hold( pIntf );
327 vlc_mutex_unlock( &skin_load.mutex );
332 if( !vlc_object_alive( pIntf ) ||
333 !var_InheritBool( pIntf, "skinned-video") ||
334 pWnd->cfg->is_standalone )
336 vlc_object_release( pIntf );
340 vlc_mutex_lock( &serializer );
342 pWnd->handle.hwnd = VoutManager::getWindow( pIntf, pWnd );
344 if( pWnd->handle.hwnd )
346 pWnd->control = &VoutManager::controlWindow;
347 pWnd->sys = (vout_window_sys_t*)pIntf;
349 vlc_mutex_unlock( &serializer );
354 vlc_object_release( pIntf );
355 vlc_mutex_unlock( &serializer );
360 static void WindowClose( vlc_object_t *p_this )
362 vout_window_t *pWnd = (vout_window_t *)p_this;
363 intf_thread_t *pIntf = (intf_thread_t *)pWnd->sys;
365 VoutManager::releaseWindow( pIntf, pWnd );
367 vlc_object_release( pIntf );
371 //---------------------------------------------------------------------------
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" \
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")
395 set_category( CAT_INTERFACE )
396 set_subcategory( SUBCAT_INTERFACE_MAIN )
397 add_loadfile( "skins2-last", "", SKINS2_LAST, SKINS2_LAST_LONG,
400 add_string( "skins2-config", "", SKINS2_CONFIG, SKINS2_CONFIG_LONG,
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 );
410 add_bool( "skins2-transparency", false, SKINS2_TRANSPARENCY,
411 SKINS2_TRANSPARENCY_LONG, false );
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" )
425 set_capability( "vout window hwnd", 51 )
427 set_capability( "vout window xid", 51 )
429 set_callbacks( WindowOpen, WindowClose )