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_Get( p_intf );
110 // Initialize "singleton" objects
111 p_intf->p_sys->p_logger = NULL;
112 p_intf->p_sys->p_queue = NULL;
113 p_intf->p_sys->p_dialogs = NULL;
114 p_intf->p_sys->p_interpreter = NULL;
115 p_intf->p_sys->p_osFactory = NULL;
116 p_intf->p_sys->p_osLoop = NULL;
117 p_intf->p_sys->p_varManager = NULL;
118 p_intf->p_sys->p_voutManager = NULL;
119 p_intf->p_sys->p_vlcProc = NULL;
120 p_intf->p_sys->p_repository = NULL;
123 p_intf->p_sys->p_theme = NULL;
125 // Create a variable to be notified of skins to be loaded
126 var_Create( p_intf, "skin-to-load", VLC_VAR_STRING );
128 vlc_mutex_init( &p_intf->p_sys->vout_lock );
129 vlc_cond_init( &p_intf->p_sys->vout_wait );
131 vlc_mutex_init( &p_intf->p_sys->init_lock );
132 vlc_cond_init( &p_intf->p_sys->init_wait );
134 vlc_mutex_lock( &p_intf->p_sys->init_lock );
135 p_intf->p_sys->b_ready = false;
137 if( vlc_clone( &p_intf->p_sys->thread, Run, p_intf,
138 VLC_THREAD_PRIORITY_LOW ) )
140 vlc_mutex_unlock( &p_intf->p_sys->init_lock );
142 vlc_cond_destroy( &p_intf->p_sys->init_wait );
143 vlc_mutex_destroy( &p_intf->p_sys->init_lock );
144 vlc_cond_destroy( &p_intf->p_sys->vout_wait );
145 vlc_mutex_destroy( &p_intf->p_sys->vout_lock );
146 free( p_intf->p_sys );
150 while( !p_intf->p_sys->b_ready )
151 vlc_cond_wait( &p_intf->p_sys->init_wait, &p_intf->p_sys->init_lock );
152 vlc_mutex_unlock( &p_intf->p_sys->init_lock );
154 vlc_mutex_lock( &skin_load.mutex );
155 skin_load.intf = p_intf;
156 vlc_mutex_unlock( &skin_load.mutex );
161 //---------------------------------------------------------------------------
162 // Close: destroy interface
163 //---------------------------------------------------------------------------
164 static void Close( vlc_object_t *p_this )
166 intf_thread_t *p_intf = (intf_thread_t *)p_this;
168 msg_Dbg( p_intf, "closing skins2 module" );
170 vlc_mutex_lock( &skin_load.mutex );
171 skin_load.intf = NULL;
172 vlc_mutex_unlock( &skin_load.mutex);
174 vlc_join( p_intf->p_sys->thread, NULL );
176 vlc_mutex_destroy( &p_intf->p_sys->init_lock );
177 vlc_cond_destroy( &p_intf->p_sys->init_wait );
179 // Unsubscribe from messages bank
181 msg_Unsubscribe( p_intf, p_intf->p_sys->p_sub );
184 vlc_cond_destroy( &p_intf->p_sys->vout_wait );
185 vlc_mutex_destroy( &p_intf->p_sys->vout_lock );
188 free( p_intf->p_sys );
192 //---------------------------------------------------------------------------
194 //---------------------------------------------------------------------------
195 static void *Run( void * p_obj )
197 int canc = vlc_savecancel();
199 intf_thread_t *p_intf = (intf_thread_t *)p_obj;
201 bool b_error = false;
202 char *skin_last = NULL;
203 ThemeLoader *pLoader = NULL;
206 vlc_mutex_lock( &p_intf->p_sys->init_lock );
208 // Initialize singletons
209 if( OSFactory::instance( p_intf ) == NULL )
211 msg_Err( p_intf, "cannot initialize OSFactory" );
215 if( AsyncQueue::instance( p_intf ) == NULL )
217 msg_Err( p_intf, "cannot initialize AsyncQueue" );
221 if( Interpreter::instance( p_intf ) == NULL )
223 msg_Err( p_intf, "cannot instanciate Interpreter" );
227 if( VarManager::instance( p_intf ) == NULL )
229 msg_Err( p_intf, "cannot instanciate VarManager" );
233 if( VlcProc::instance( p_intf ) == NULL )
235 msg_Err( p_intf, "cannot initialize VLCProc" );
239 if( VoutManager::instance( p_intf ) == NULL )
241 msg_Err( p_intf, "cannot instanciate VoutManager" );
245 if( ThemeRepository::instance( p_intf ) == NULL )
247 msg_Err( p_intf, "cannot instanciate ThemeRepository" );
251 if( Dialogs::instance( p_intf ) == NULL )
253 msg_Err( p_intf, "cannot instanciate qt4 dialogs provider" );
259 skin_last = config_GetPsz( p_intf, "skins2-last" );
260 pLoader = new ThemeLoader( p_intf );
262 if( !skin_last || !pLoader->load( skin_last ) )
264 // No skins (not even the default one). let's quit
265 CmdQuit *pCmd = new CmdQuit( p_intf );
266 AsyncQueue *pQueue = AsyncQueue::instance( p_intf );
267 pQueue->push( CmdGenericPtr( pCmd ) );
268 msg_Err( p_intf, "no skins found : exiting");
274 // Get the instance of OSLoop
275 loop = OSFactory::instance( p_intf )->getOSLoop();
277 // Signal the main thread this thread is now ready
278 p_intf->p_sys->b_ready = true;
279 vlc_cond_signal( &p_intf->p_sys->init_wait );
280 vlc_mutex_unlock( &p_intf->p_sys->init_lock );
282 // Enter the main event loop
286 OSFactory::instance( p_intf )->destroyOSLoop();
288 // save and delete the theme
289 if( p_intf->p_sys->p_theme )
291 p_intf->p_sys->p_theme->saveConfig();
293 delete p_intf->p_sys->p_theme;
294 p_intf->p_sys->p_theme = NULL;
296 msg_Dbg( p_intf, "current theme deleted" );
300 config_SaveConfigFile( p_intf, NULL );
303 // Destroy "singleton" objects
304 Dialogs::destroy( p_intf );
305 ThemeRepository::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( !config_GetInt( pIntf, "skinned-video") ||
343 pWnd->cfg->is_standalone )
345 vlc_object_release( pIntf );
349 vlc_mutex_lock( &serializer );
351 pWnd->handle.hwnd = VoutManager::getWindow( pIntf, pWnd );
353 if( pWnd->handle.hwnd )
355 pWnd->control = &VoutManager::controlWindow;
356 pWnd->sys = (vout_window_sys_t*)pIntf;
358 vlc_mutex_unlock( &serializer );
363 vlc_object_release( pIntf );
364 vlc_mutex_unlock( &serializer );
369 static void WindowClose( vlc_object_t *p_this )
371 vout_window_t *pWnd = (vout_window_t *)p_this;
372 intf_thread_t *pIntf = (intf_thread_t *)pWnd->sys;
374 VoutManager::releaseWindow( pIntf, pWnd );
376 vlc_object_release( pIntf );
379 //---------------------------------------------------------------------------
380 // DemuxOpen: initialize demux
381 //---------------------------------------------------------------------------
382 static int DemuxOpen( vlc_object_t *p_this )
384 demux_t *p_demux = (demux_t*)p_this;
385 intf_thread_t *p_intf;
389 p_demux->pf_demux = Demux;
390 p_demux->pf_control = DemuxControl;
392 // Test that we have a valid .vlt or .wsz file, based on the extension
393 if( ( ext = strrchr( p_demux->psz_path, '.' ) ) == NULL ||
394 ( strcasecmp( ext, ".vlt" ) && strcasecmp( ext, ".wsz" ) ) )
399 vlc_mutex_lock( &skin_load.mutex );
400 p_intf = skin_load.intf;
402 vlc_object_hold( p_intf );
403 vlc_mutex_unlock( &skin_load.mutex );
407 playlist_t *p_playlist = pl_Get( p_this );
410 // Make sure the item is deleted afterwards
411 /// \bug does not always work
412 playlist_CurrentPlayingItem( p_playlist )->i_flags |= PLAYLIST_REMOVE_FLAG;
415 var_SetString( p_intf, "skin-to-load", p_demux->psz_path );
416 vlc_object_release( p_intf );
421 "skin could not be loaded (not using skins2 intf)" );
428 //---------------------------------------------------------------------------
430 //---------------------------------------------------------------------------
431 static int Demux( demux_t *p_demux )
437 //---------------------------------------------------------------------------
439 //---------------------------------------------------------------------------
440 static int DemuxControl( demux_t *p_demux, int i_query, va_list args )
444 case DEMUX_GET_PTS_DELAY:
446 int64_t *pi_pts_delay = va_arg( args, int64_t * );
457 //---------------------------------------------------------------------------
459 //---------------------------------------------------------------------------
461 /// Callback for the systray configuration option
462 static int onSystrayChange( vlc_object_t *pObj, const char *pVariable,
463 vlc_value_t oldVal, vlc_value_t newVal,
466 intf_thread_t *pIntf;
468 vlc_mutex_lock( &skin_load.mutex );
469 pIntf = skin_load.intf;
471 vlc_object_hold( pIntf );
472 vlc_mutex_unlock( &skin_load.mutex );
479 AsyncQueue *pQueue = AsyncQueue::instance( pIntf );
482 CmdAddInTray *pCmd = new CmdAddInTray( pIntf );
483 pQueue->push( CmdGenericPtr( pCmd ) );
487 CmdRemoveFromTray *pCmd = new CmdRemoveFromTray( pIntf );
488 pQueue->push( CmdGenericPtr( pCmd ) );
491 vlc_object_release( pIntf );
496 /// Callback for the systray configuration option
497 static int onTaskBarChange( vlc_object_t *pObj, const char *pVariable,
498 vlc_value_t oldVal, vlc_value_t newVal,
501 intf_thread_t *pIntf;
503 vlc_mutex_lock( &skin_load.mutex );
504 pIntf = skin_load.intf;
506 vlc_object_hold( pIntf );
507 vlc_mutex_unlock( &skin_load.mutex );
514 AsyncQueue *pQueue = AsyncQueue::instance( pIntf );
517 CmdAddInTaskBar *pCmd = new CmdAddInTaskBar( pIntf );
518 pQueue->push( CmdGenericPtr( pCmd ) );
522 CmdRemoveFromTaskBar *pCmd = new CmdRemoveFromTaskBar( pIntf );
523 pQueue->push( CmdGenericPtr( pCmd ) );
526 vlc_object_release( pIntf );
531 //---------------------------------------------------------------------------
533 //---------------------------------------------------------------------------
534 #define SKINS2_LAST N_("Skin to use")
535 #define SKINS2_LAST_LONG N_("Path to the skin to use.")
536 #define SKINS2_CONFIG N_("Config of last used skin")
537 #define SKINS2_CONFIG_LONG N_("Windows configuration of the last skin used. " \
538 "This option is updated automatically, do not touch it." )
539 #define SKINS2_SYSTRAY N_("Systray icon")
540 #define SKINS2_SYSTRAY_LONG N_("Show a systray icon for VLC")
541 #define SKINS2_TASKBAR N_("Show VLC on the taskbar")
542 #define SKINS2_TASKBAR_LONG N_("Show VLC on the taskbar")
543 #define SKINS2_TRANSPARENCY N_("Enable transparency effects")
544 #define SKINS2_TRANSPARENCY_LONG N_("You can disable all transparency effects"\
545 " if you want. This is mainly useful when moving windows does not behave" \
547 #define SKINS2_PLAYLIST N_("Use a skinned playlist")
548 #define SKINS2_PLAYLIST_LONG N_("Use a skinned playlist")
549 #define SKINS2_VIDEO N_("Display video in a skinned window if any")
550 #define SKINS2_VIDEO_LONG N_( \
551 "When set to 'no', this parameter is intended to give old skins a chance" \
552 " to play back video even though no video tag is implemented")
555 set_category( CAT_INTERFACE )
556 set_subcategory( SUBCAT_INTERFACE_MAIN )
557 add_file( "skins2-last", "", NULL, SKINS2_LAST, SKINS2_LAST_LONG,
560 add_string( "skins2-config", "", NULL, SKINS2_CONFIG, SKINS2_CONFIG_LONG,
565 add_bool( "skins2-systray", false, onSystrayChange, SKINS2_SYSTRAY,
566 SKINS2_SYSTRAY_LONG, false );
567 add_bool( "skins2-taskbar", true, onTaskBarChange, SKINS2_TASKBAR,
568 SKINS2_TASKBAR_LONG, false );
570 add_bool( "skins2-transparency", false, NULL, SKINS2_TRANSPARENCY,
571 SKINS2_TRANSPARENCY_LONG, false );
573 add_bool( "skinned-playlist", true, NULL, SKINS2_PLAYLIST,
574 SKINS2_PLAYLIST_LONG, false );
575 add_bool( "skinned-video", true, NULL, SKINS2_VIDEO,
576 SKINS2_VIDEO_LONG, false );
577 set_shortname( N_("Skins"))
578 set_description( N_("Skinnable Interface") )
579 set_capability( "interface", 30 )
580 set_callbacks( Open, Close )
581 add_shortcut( "skins" )
585 set_capability( "vout window hwnd", 51 )
587 set_capability( "vout window xid", 51 )
589 set_callbacks( WindowOpen, WindowClose )
592 set_description( N_("Skins loader demux") )
593 set_capability( "access_demux", 5 )
594 set_callbacks( DemuxOpen, NULL )
595 add_shortcut( "skins" )