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_demux.h>
33 #include <vlc_playlist.h>
34 #include <vlc_threads.h>
35 #include <vlc_vout_window.h>
37 #include "dialogs.hpp"
38 #include "os_factory.hpp"
39 #include "os_loop.hpp"
40 #include "var_manager.hpp"
41 #include "vlcproc.hpp"
42 #include "theme_loader.hpp"
44 #include "theme_repository.hpp"
45 #include "vout_window.hpp"
46 #include "vout_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 static int DemuxOpen( vlc_object_t * );
71 static int Demux( demux_t * );
72 static int DemuxControl( demux_t *, int, va_list );
74 //---------------------------------------------------------------------------
75 // Prototypes for configuration callbacks
76 //---------------------------------------------------------------------------
77 static int onSystrayChange( vlc_object_t *pObj, const char *pVariable,
78 vlc_value_t oldVal, vlc_value_t newVal,
80 static int onTaskBarChange( vlc_object_t *pObj, const char *pVariable,
81 vlc_value_t oldVal, vlc_value_t newVal,
88 } skin_load = { NULL, VLC_STATIC_MUTEX };
90 //---------------------------------------------------------------------------
91 // Open: initialize interface
92 //---------------------------------------------------------------------------
93 static int Open( vlc_object_t *p_this )
95 intf_thread_t *p_intf = (intf_thread_t *)p_this;
97 // Allocate instance and initialize some members
98 p_intf->p_sys = (intf_sys_t *) calloc( 1, sizeof( intf_sys_t ) );
99 if( p_intf->p_sys == NULL )
102 // Suscribe to messages bank
104 p_intf->p_sys->p_sub = msg_Subscribe( p_intf );
107 p_intf->p_sys->p_input = NULL;
108 p_intf->p_sys->p_playlist = pl_Hold( p_intf );
109 if( !p_intf->p_sys->p_playlist )
111 free( p_intf->p_sys );
115 // Initialize "singleton" objects
116 p_intf->p_sys->p_logger = NULL;
117 p_intf->p_sys->p_queue = NULL;
118 p_intf->p_sys->p_dialogs = NULL;
119 p_intf->p_sys->p_interpreter = NULL;
120 p_intf->p_sys->p_osFactory = NULL;
121 p_intf->p_sys->p_osLoop = NULL;
122 p_intf->p_sys->p_varManager = NULL;
123 p_intf->p_sys->p_voutManager = NULL;
124 p_intf->p_sys->p_vlcProc = NULL;
125 p_intf->p_sys->p_repository = NULL;
128 p_intf->p_sys->p_theme = NULL;
130 // Create a variable to be notified of skins to be loaded
131 var_Create( p_intf, "skin-to-load", VLC_VAR_STRING );
133 vlc_mutex_init( &p_intf->p_sys->vout_lock );
134 vlc_cond_init( &p_intf->p_sys->vout_wait );
136 vlc_mutex_init( &p_intf->p_sys->init_lock );
137 vlc_cond_init( &p_intf->p_sys->init_wait );
139 vlc_mutex_lock( &p_intf->p_sys->init_lock );
140 p_intf->p_sys->b_ready = false;
142 if( vlc_clone( &p_intf->p_sys->thread, Run, p_intf,
143 VLC_THREAD_PRIORITY_LOW ) )
145 vlc_mutex_unlock( &p_intf->p_sys->init_lock );
147 vlc_cond_destroy( &p_intf->p_sys->init_wait );
148 vlc_mutex_destroy( &p_intf->p_sys->init_lock );
149 vlc_cond_destroy( &p_intf->p_sys->vout_wait );
150 vlc_mutex_destroy( &p_intf->p_sys->vout_lock );
151 pl_Release( p_intf->p_sys->p_playlist );
152 free( p_intf->p_sys );
156 while( !p_intf->p_sys->b_ready )
157 vlc_cond_wait( &p_intf->p_sys->init_wait, &p_intf->p_sys->init_lock );
158 vlc_mutex_unlock( &p_intf->p_sys->init_lock );
160 vlc_mutex_lock( &skin_load.mutex );
161 skin_load.intf = p_intf;
162 vlc_mutex_unlock( &skin_load.mutex );
167 //---------------------------------------------------------------------------
168 // Close: destroy interface
169 //---------------------------------------------------------------------------
170 static void Close( vlc_object_t *p_this )
172 intf_thread_t *p_intf = (intf_thread_t *)p_this;
174 msg_Dbg( p_intf, "closing skins2 module" );
176 vlc_mutex_lock( &skin_load.mutex );
177 skin_load.intf = NULL;
178 vlc_mutex_unlock( &skin_load.mutex);
180 vlc_join( p_intf->p_sys->thread, NULL );
182 vlc_mutex_destroy( &p_intf->p_sys->init_lock );
183 vlc_cond_destroy( &p_intf->p_sys->init_wait );
185 if( p_intf->p_sys->p_playlist )
186 pl_Release( p_this );
188 // Unsubscribe from messages bank
190 msg_Unsubscribe( p_intf, p_intf->p_sys->p_sub );
193 vlc_cond_destroy( &p_intf->p_sys->vout_wait );
194 vlc_mutex_destroy( &p_intf->p_sys->vout_lock );
197 free( p_intf->p_sys );
201 //---------------------------------------------------------------------------
203 //---------------------------------------------------------------------------
204 static void *Run( void * p_obj )
206 int canc = vlc_savecancel();
208 intf_thread_t *p_intf = (intf_thread_t *)p_obj;
210 bool b_error = false;
211 char *skin_last = NULL;
212 ThemeLoader *pLoader = NULL;
215 vlc_mutex_lock( &p_intf->p_sys->init_lock );
217 // Initialize singletons
218 if( OSFactory::instance( p_intf ) == NULL )
220 msg_Err( p_intf, "cannot initialize OSFactory" );
224 if( AsyncQueue::instance( p_intf ) == NULL )
226 msg_Err( p_intf, "cannot initialize AsyncQueue" );
230 if( Interpreter::instance( p_intf ) == NULL )
232 msg_Err( p_intf, "cannot instanciate Interpreter" );
236 if( VarManager::instance( p_intf ) == NULL )
238 msg_Err( p_intf, "cannot instanciate VarManager" );
242 if( VlcProc::instance( p_intf ) == NULL )
244 msg_Err( p_intf, "cannot initialize VLCProc" );
248 if( VoutManager::instance( p_intf ) == NULL )
250 msg_Err( p_intf, "cannot instanciate VoutManager" );
254 if( ThemeRepository::instance( p_intf ) == NULL )
256 msg_Err( p_intf, "cannot instanciate ThemeRepository" );
260 if( Dialogs::instance( p_intf ) == NULL )
262 msg_Err( p_intf, "cannot instanciate qt4 dialogs provider" );
268 skin_last = config_GetPsz( p_intf, "skins2-last" );
269 pLoader = new ThemeLoader( p_intf );
271 if( !skin_last || !pLoader->load( skin_last ) )
273 // No skins (not even the default one). let's quit
274 CmdQuit *pCmd = new CmdQuit( p_intf );
275 AsyncQueue *pQueue = AsyncQueue::instance( p_intf );
276 pQueue->push( CmdGenericPtr( pCmd ) );
277 msg_Err( p_intf, "no skins found : exiting");
283 // Get the instance of OSLoop
284 loop = OSFactory::instance( p_intf )->getOSLoop();
286 // Signal the main thread this thread is now ready
287 p_intf->p_sys->b_ready = true;
288 vlc_cond_signal( &p_intf->p_sys->init_wait );
289 vlc_mutex_unlock( &p_intf->p_sys->init_lock );
291 // Enter the main event loop
295 OSFactory::instance( p_intf )->destroyOSLoop();
297 // save and delete the theme
298 if( p_intf->p_sys->p_theme )
300 p_intf->p_sys->p_theme->saveConfig();
302 delete p_intf->p_sys->p_theme;
303 p_intf->p_sys->p_theme = NULL;
305 msg_Dbg( p_intf, "current theme deleted" );
309 config_SaveConfigFile( p_intf, NULL );
312 // Destroy "singleton" objects
313 Dialogs::destroy( p_intf );
314 ThemeRepository::destroy( p_intf );
315 VoutManager::destroy( p_intf );
316 VlcProc::destroy( p_intf );
317 VarManager::destroy( p_intf );
318 Interpreter::destroy( p_intf );
319 AsyncQueue::destroy( p_intf );
320 OSFactory::destroy( p_intf );
324 p_intf->p_sys->b_ready = true;
325 vlc_cond_signal( &p_intf->p_sys->init_wait );
326 vlc_mutex_unlock( &p_intf->p_sys->init_lock );
328 libvlc_Quit( p_intf->p_libvlc );
331 vlc_restorecancel(canc);
335 static vlc_mutex_t serializer = VLC_STATIC_MUTEX;
337 // Callbacks for vout requests
338 static int WindowOpen( vlc_object_t *p_this )
340 vout_window_t *pWnd = (vout_window_t *)p_this;
342 vlc_mutex_lock( &skin_load.mutex );
343 intf_thread_t *pIntf = skin_load.intf;
345 vlc_object_hold( pIntf );
346 vlc_mutex_unlock( &skin_load.mutex );
351 if( !config_GetInt( pIntf, "skinned-video") )
353 vlc_object_release( pIntf );
357 vlc_mutex_lock( &serializer );
359 pWnd->handle.hwnd = VoutManager::getWindow( pIntf, pWnd );
361 if( pWnd->handle.hwnd )
363 pWnd->control = &VoutManager::controlWindow;
364 pWnd->sys = (vout_window_sys_t*)pIntf;
366 vlc_mutex_unlock( &serializer );
371 vlc_object_release( pIntf );
372 vlc_mutex_unlock( &serializer );
377 static void WindowClose( vlc_object_t *p_this )
379 vout_window_t *pWnd = (vout_window_t *)p_this;
380 intf_thread_t *pIntf = (intf_thread_t *)pWnd->sys;
382 VoutManager::releaseWindow( pIntf, pWnd );
384 vlc_object_release( pIntf );
387 //---------------------------------------------------------------------------
388 // DemuxOpen: initialize demux
389 //---------------------------------------------------------------------------
390 static int DemuxOpen( vlc_object_t *p_this )
392 demux_t *p_demux = (demux_t*)p_this;
393 intf_thread_t *p_intf;
397 p_demux->pf_demux = Demux;
398 p_demux->pf_control = DemuxControl;
400 // Test that we have a valid .vlt or .wsz file, based on the extension
401 if( ( ext = strrchr( p_demux->psz_path, '.' ) ) == NULL ||
402 ( strcasecmp( ext, ".vlt" ) && strcasecmp( ext, ".wsz" ) ) )
407 vlc_mutex_lock( &skin_load.mutex );
408 p_intf = skin_load.intf;
410 vlc_object_hold( p_intf );
411 vlc_mutex_unlock( &skin_load.mutex );
415 playlist_t *p_playlist = pl_Hold( p_this );
418 // Make sure the item is deleted afterwards
419 /// \bug does not always work
420 playlist_CurrentPlayingItem( p_playlist )->i_flags |= PLAYLIST_REMOVE_FLAG;
423 pl_Release( p_this );
425 var_SetString( p_intf, "skin-to-load", p_demux->psz_path );
426 vlc_object_release( p_intf );
431 "skin could not be loaded (not using skins2 intf)" );
438 //---------------------------------------------------------------------------
440 //---------------------------------------------------------------------------
441 static int Demux( demux_t *p_demux )
447 //---------------------------------------------------------------------------
449 //---------------------------------------------------------------------------
450 static int DemuxControl( demux_t *p_demux, int i_query, va_list args )
454 case DEMUX_GET_PTS_DELAY:
456 int64_t *pi_pts_delay = va_arg( args, int64_t * );
467 //---------------------------------------------------------------------------
469 //---------------------------------------------------------------------------
471 /// Callback for the systray configuration option
472 static int onSystrayChange( vlc_object_t *pObj, const char *pVariable,
473 vlc_value_t oldVal, vlc_value_t newVal,
476 intf_thread_t *pIntf;
478 vlc_mutex_lock( &skin_load.mutex );
479 pIntf = skin_load.intf;
481 vlc_object_hold( pIntf );
482 vlc_mutex_unlock( &skin_load.mutex );
489 AsyncQueue *pQueue = AsyncQueue::instance( pIntf );
492 CmdAddInTray *pCmd = new CmdAddInTray( pIntf );
493 pQueue->push( CmdGenericPtr( pCmd ) );
497 CmdRemoveFromTray *pCmd = new CmdRemoveFromTray( pIntf );
498 pQueue->push( CmdGenericPtr( pCmd ) );
501 vlc_object_release( pIntf );
506 /// Callback for the systray configuration option
507 static int onTaskBarChange( vlc_object_t *pObj, const char *pVariable,
508 vlc_value_t oldVal, vlc_value_t newVal,
511 intf_thread_t *pIntf;
513 vlc_mutex_lock( &skin_load.mutex );
514 pIntf = skin_load.intf;
516 vlc_object_hold( pIntf );
517 vlc_mutex_unlock( &skin_load.mutex );
524 AsyncQueue *pQueue = AsyncQueue::instance( pIntf );
527 CmdAddInTaskBar *pCmd = new CmdAddInTaskBar( pIntf );
528 pQueue->push( CmdGenericPtr( pCmd ) );
532 CmdRemoveFromTaskBar *pCmd = new CmdRemoveFromTaskBar( pIntf );
533 pQueue->push( CmdGenericPtr( pCmd ) );
536 vlc_object_release( pIntf );
541 //---------------------------------------------------------------------------
543 //---------------------------------------------------------------------------
544 #define SKINS2_LAST N_("Skin to use")
545 #define SKINS2_LAST_LONG N_("Path to the skin to use.")
546 #define SKINS2_CONFIG N_("Config of last used skin")
547 #define SKINS2_CONFIG_LONG N_("Windows configuration of the last skin used. " \
548 "This option is updated automatically, do not touch it." )
549 #define SKINS2_SYSTRAY N_("Systray icon")
550 #define SKINS2_SYSTRAY_LONG N_("Show a systray icon for VLC")
551 #define SKINS2_TASKBAR N_("Show VLC on the taskbar")
552 #define SKINS2_TASKBAR_LONG N_("Show VLC on the taskbar")
553 #define SKINS2_TRANSPARENCY N_("Enable transparency effects")
554 #define SKINS2_TRANSPARENCY_LONG N_("You can disable all transparency effects"\
555 " if you want. This is mainly useful when moving windows does not behave" \
557 #define SKINS2_PLAYLIST N_("Use a skinned playlist")
558 #define SKINS2_PLAYLIST_LONG N_("Use a skinned playlist")
559 #define SKINS2_VIDEO N_("Display video in a skinned window if any")
560 #define SKINS2_VIDEO_LONG N_( \
561 "When set to 'no', this parameter is intended to give old skins a chance" \
562 " to play back video even though no video tag is implemented")
565 set_category( CAT_INTERFACE )
566 set_subcategory( SUBCAT_INTERFACE_MAIN )
567 add_file( "skins2-last", "", NULL, SKINS2_LAST, SKINS2_LAST_LONG,
570 add_string( "skins2-config", "", NULL, SKINS2_CONFIG, SKINS2_CONFIG_LONG,
575 add_bool( "skins2-systray", false, onSystrayChange, SKINS2_SYSTRAY,
576 SKINS2_SYSTRAY_LONG, false );
577 add_bool( "skins2-taskbar", true, onTaskBarChange, SKINS2_TASKBAR,
578 SKINS2_TASKBAR_LONG, false );
580 add_bool( "skins2-transparency", false, NULL, SKINS2_TRANSPARENCY,
581 SKINS2_TRANSPARENCY_LONG, false );
583 add_bool( "skinned-playlist", true, NULL, SKINS2_PLAYLIST,
584 SKINS2_PLAYLIST_LONG, false );
585 add_bool( "skinned-video", true, NULL, SKINS2_VIDEO,
586 SKINS2_VIDEO_LONG, false );
587 set_shortname( N_("Skins"))
588 set_description( N_("Skinnable Interface") )
589 set_capability( "interface", 30 )
590 set_callbacks( Open, Close )
591 add_shortcut( "skins" )
595 set_capability( "vout window hwnd", 51 )
597 set_capability( "vout window xid", 51 )
599 set_callbacks( WindowOpen, WindowClose )
602 set_description( N_("Skins loader demux") )
603 set_capability( "access_demux", 5 )
604 set_callbacks( DemuxOpen, NULL )
605 add_shortcut( "skins" )