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_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"
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 ( intf_thread_t * );
69 static int DemuxOpen( vlc_object_t * );
70 static int Demux( demux_t * );
71 static int DemuxControl( demux_t *, int, va_list );
73 //---------------------------------------------------------------------------
74 // Prototypes for configuration callbacks
75 //---------------------------------------------------------------------------
76 static int onSystrayChange( vlc_object_t *pObj, const char *pVariable,
77 vlc_value_t oldVal, vlc_value_t newVal,
79 static int onTaskBarChange( vlc_object_t *pObj, const char *pVariable,
80 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 *) malloc( sizeof( intf_sys_t ) );
99 if( p_intf->p_sys == NULL )
100 return( VLC_ENOMEM );
102 p_intf->pf_run = Run;
104 // Suscribe to messages bank
106 p_intf->p_sys->p_sub = msg_Subscribe( p_intf );
109 p_intf->p_sys->p_input = NULL;
110 p_intf->p_sys->p_playlist = pl_Hold( p_intf );
112 // Initialize "singleton" objects
113 p_intf->p_sys->p_logger = NULL;
114 p_intf->p_sys->p_queue = NULL;
115 p_intf->p_sys->p_dialogs = NULL;
116 p_intf->p_sys->p_interpreter = NULL;
117 p_intf->p_sys->p_osFactory = NULL;
118 p_intf->p_sys->p_osLoop = NULL;
119 p_intf->p_sys->p_varManager = NULL;
120 p_intf->p_sys->p_voutManager = NULL;
121 p_intf->p_sys->p_vlcProc = NULL;
122 p_intf->p_sys->p_repository = NULL;
125 p_intf->p_sys->p_theme = NULL;
127 // Create a variable to be notified of skins to be loaded
128 var_Create( p_intf, "skin-to-load", VLC_VAR_STRING );
130 // Initialize singletons
131 if( OSFactory::instance( p_intf ) == NULL )
133 msg_Err( p_intf, "cannot initialize OSFactory" );
134 pl_Release( p_intf );
136 msg_Unsubscribe( p_intf, p_intf->p_sys->p_sub );
140 if( AsyncQueue::instance( p_intf ) == NULL )
142 msg_Err( p_intf, "cannot initialize AsyncQueue" );
143 pl_Release( p_intf );
145 msg_Unsubscribe( p_intf, p_intf->p_sys->p_sub );
149 if( Interpreter::instance( p_intf ) == NULL )
151 msg_Err( p_intf, "cannot instanciate Interpreter" );
152 pl_Release( p_intf );
154 msg_Unsubscribe( p_intf, p_intf->p_sys->p_sub );
158 if( VarManager::instance( p_intf ) == NULL )
160 msg_Err( p_intf, "cannot instanciate VarManager" );
161 pl_Release( p_intf );
163 msg_Unsubscribe( p_intf, p_intf->p_sys->p_sub );
167 if( VlcProc::instance( p_intf ) == NULL )
169 msg_Err( p_intf, "cannot initialize VLCProc" );
170 pl_Release( p_intf );
172 msg_Unsubscribe( p_intf, p_intf->p_sys->p_sub );
176 if( VoutManager::instance( p_intf ) == NULL )
178 msg_Err( p_intf, "cannot instanciate VoutManager" );
179 pl_Release( p_intf );
182 vlc_mutex_lock( &skin_load.mutex );
183 skin_load.intf = p_intf;
184 vlc_mutex_unlock( &skin_load.mutex );
186 Dialogs::instance( p_intf );
187 ThemeRepository::instance( p_intf );
190 char *skin_last = config_GetPsz( p_intf, "skins2-last" );
192 ThemeLoader *pLoader = new ThemeLoader( p_intf );
194 if( !skin_last || !*skin_last || !pLoader->load( skin_last ) )
196 // Get the resource path and try to load the default skin
197 OSFactory *pOSFactory = OSFactory::instance( p_intf );
198 const list<string> &resPath = pOSFactory->getResourcePath();
199 const string &sep = pOSFactory->getDirSeparator();
201 list<string>::const_iterator it;
202 for( it = resPath.begin(); it != resPath.end(); it++ )
204 string path = (*it) + sep + "default.vlt";
205 if( pLoader->load( path ) )
207 // Theme loaded successfully
211 if( it == resPath.end() )
213 // Last chance: the user can select a new theme file
214 if( Dialogs::instance( p_intf ) )
216 CmdDlgChangeSkin *pCmd = new CmdDlgChangeSkin( p_intf );
217 AsyncQueue *pQueue = AsyncQueue::instance( p_intf );
218 pQueue->push( CmdGenericPtr( pCmd ) );
222 // No dialogs provider, just quit...
223 CmdQuit *pCmd = new CmdQuit( p_intf );
224 AsyncQueue *pQueue = AsyncQueue::instance( p_intf );
225 pQueue->push( CmdGenericPtr( pCmd ) );
227 "cannot show the \"open skin\" dialog: exiting...");
236 p_intf->b_should_run_on_first_thread = true;
239 return( VLC_SUCCESS );
242 //---------------------------------------------------------------------------
243 // Close: destroy interface
244 //---------------------------------------------------------------------------
245 static void Close( vlc_object_t *p_this )
247 intf_thread_t *p_intf = (intf_thread_t *)p_this;
249 msg_Dbg( p_intf, "closing skins2 module" );
251 vlc_mutex_lock( &skin_load.mutex );
252 skin_load.intf = NULL;
253 vlc_mutex_unlock( &skin_load.mutex);
255 if( p_intf->p_sys->p_theme )
257 delete p_intf->p_sys->p_theme;
258 p_intf->p_sys->p_theme = NULL;
259 msg_Dbg( p_intf, "current theme deleted" );
262 // Destroy "singleton" objects
263 OSFactory::instance( p_intf )->destroyOSLoop();
264 ThemeRepository::destroy( p_intf );
265 VoutManager::destroy( p_intf );
266 //Dialogs::destroy( p_intf );
267 Interpreter::destroy( p_intf );
268 AsyncQueue::destroy( p_intf );
269 VarManager::destroy( p_intf );
270 VlcProc::destroy( p_intf );
271 OSFactory::destroy( p_intf );
273 if( p_intf->p_sys->p_playlist )
275 vlc_object_release( p_intf->p_sys->p_playlist );
278 // Unsubscribe from messages bank
280 msg_Unsubscribe( p_intf, p_intf->p_sys->p_sub );
284 free( p_intf->p_sys );
288 //---------------------------------------------------------------------------
290 //---------------------------------------------------------------------------
291 static void Run( intf_thread_t *p_intf )
293 int canc = vlc_savecancel();
295 // Get the instance of OSLoop
296 OSLoop *loop = OSFactory::instance( p_intf )->getOSLoop();
298 // Enter the main event loop
301 // Delete the theme and save the configuration of the windows
302 if( p_intf->p_sys->p_theme )
304 p_intf->p_sys->p_theme->saveConfig();
307 // cannot be called in "Close", because it refcounts skins2
308 Dialogs::destroy( p_intf );
310 vlc_restorecancel(canc);
314 // Callbacks for vout requests
315 static int WindowOpen( vlc_object_t *p_this )
317 vout_window_t *pWnd = (vout_window_t *)p_this;
318 intf_thread_t *pIntf = (intf_thread_t *)
319 vlc_object_find_name( p_this, "skins2", FIND_ANYWHERE );
324 vlc_object_release( pIntf );
326 pWnd->handle.hwnd = VoutManager::getWindow( pIntf, pWnd );
328 if( pWnd->handle.hwnd )
330 pWnd->p_private = pIntf;
331 pWnd->control = &VoutManager::controlWindow;
340 static void WindowClose( vlc_object_t *p_this )
342 vout_window_t *pWnd = (vout_window_t *)p_this;
343 intf_thread_t *pIntf = (intf_thread_t *)p_this->p_private;
345 VoutManager::releaseWindow( pIntf, pWnd );
348 //---------------------------------------------------------------------------
349 // DemuxOpen: initialize demux
350 //---------------------------------------------------------------------------
351 static int DemuxOpen( vlc_object_t *p_this )
353 demux_t *p_demux = (demux_t*)p_this;
354 intf_thread_t *p_intf;
358 p_demux->pf_demux = Demux;
359 p_demux->pf_control = DemuxControl;
361 // Test that we have a valid .vlt or .wsz file, based on the extension
362 // TODO: an actual check of the contents would be better...
363 if( ( ext = strchr( p_demux->psz_path, '.' ) ) == NULL ||
364 ( strcasecmp( ext, ".vlt" ) && strcasecmp( ext, ".wsz" ) ) )
369 vlc_mutex_lock( &skin_load.mutex );
370 p_intf = skin_load.intf;
372 vlc_object_hold( p_intf );
373 vlc_mutex_unlock( &skin_load.mutex );
377 playlist_t *p_playlist = pl_Hold( p_this );
378 // Make sure the item is deleted afterwards
379 /// \bug does not always work
380 playlist_CurrentPlayingItem( p_playlist )->i_flags |= PLAYLIST_REMOVE_FLAG;
381 pl_Release( p_this );
383 var_SetString( p_intf, "skin-to-load", p_demux->psz_path );
384 vlc_object_release( p_intf );
389 "skin could not be loaded (not using skins2 intf)" );
396 //---------------------------------------------------------------------------
398 //---------------------------------------------------------------------------
399 static int Demux( demux_t *p_demux )
405 //---------------------------------------------------------------------------
407 //---------------------------------------------------------------------------
408 static int DemuxControl( demux_t *p_demux, int i_query, va_list args )
410 return demux_vaControlHelper( p_demux->s, 0, 0, 0, 1, i_query, args );
414 //---------------------------------------------------------------------------
416 //---------------------------------------------------------------------------
418 /// Callback for the systray configuration option
419 static int onSystrayChange( vlc_object_t *pObj, const char *pVariable,
420 vlc_value_t oldVal, vlc_value_t newVal,
423 intf_thread_t *pIntf;
425 vlc_mutex_lock( &skin_load.mutex );
426 pIntf = skin_load.intf;
428 vlc_object_hold( pIntf );
429 vlc_mutex_unlock( &skin_load.mutex );
436 AsyncQueue *pQueue = AsyncQueue::instance( pIntf );
439 CmdAddInTray *pCmd = new CmdAddInTray( pIntf );
440 pQueue->push( CmdGenericPtr( pCmd ) );
444 CmdRemoveFromTray *pCmd = new CmdRemoveFromTray( pIntf );
445 pQueue->push( CmdGenericPtr( pCmd ) );
448 vlc_object_release( pIntf );
453 /// Callback for the systray configuration option
454 static int onTaskBarChange( vlc_object_t *pObj, const char *pVariable,
455 vlc_value_t oldVal, vlc_value_t newVal,
458 intf_thread_t *pIntf;
460 vlc_mutex_lock( &skin_load.mutex );
461 pIntf = skin_load.intf;
463 vlc_object_hold( pIntf );
464 vlc_mutex_unlock( &skin_load.mutex );
471 AsyncQueue *pQueue = AsyncQueue::instance( pIntf );
474 CmdAddInTaskBar *pCmd = new CmdAddInTaskBar( pIntf );
475 pQueue->push( CmdGenericPtr( pCmd ) );
479 CmdRemoveFromTaskBar *pCmd = new CmdRemoveFromTaskBar( pIntf );
480 pQueue->push( CmdGenericPtr( pCmd ) );
483 vlc_object_release( pIntf );
488 //---------------------------------------------------------------------------
490 //---------------------------------------------------------------------------
491 #define SKINS2_LAST N_("Skin to use")
492 #define SKINS2_LAST_LONG N_("Path to the skin to use.")
493 #define SKINS2_CONFIG N_("Config of last used skin")
494 #define SKINS2_CONFIG_LONG N_("Windows configuration of the last skin used. " \
495 "This option is updated automatically, do not touch it." )
496 #define SKINS2_SYSTRAY N_("Systray icon")
497 #define SKINS2_SYSTRAY_LONG N_("Show a systray icon for VLC")
498 #define SKINS2_TASKBAR N_("Show VLC on the taskbar")
499 #define SKINS2_TASKBAR_LONG N_("Show VLC on the taskbar")
500 #define SKINS2_TRANSPARENCY N_("Enable transparency effects")
501 #define SKINS2_TRANSPARENCY_LONG N_("You can disable all transparency effects"\
502 " if you want. This is mainly useful when moving windows does not behave" \
504 #define SKINS2_PLAYLIST N_("Use a skinned playlist")
505 #define SKINS2_PLAYLIST_LONG N_("Use a skinned playlist")
508 set_category( CAT_INTERFACE )
509 set_subcategory( SUBCAT_INTERFACE_MAIN )
510 add_file( "skins2-last", "", NULL, SKINS2_LAST, SKINS2_LAST_LONG,
513 add_string( "skins2-config", "", NULL, SKINS2_CONFIG, SKINS2_CONFIG_LONG,
518 add_bool( "skins2-systray", false, onSystrayChange, SKINS2_SYSTRAY,
519 SKINS2_SYSTRAY_LONG, false );
520 add_bool( "skins2-taskbar", true, onTaskBarChange, SKINS2_TASKBAR,
521 SKINS2_TASKBAR_LONG, false );
522 add_bool( "skins2-transparency", false, NULL, SKINS2_TRANSPARENCY,
523 SKINS2_TRANSPARENCY_LONG, false );
526 add_bool( "skinned-playlist", true, NULL, SKINS2_PLAYLIST,
527 SKINS2_PLAYLIST_LONG, false );
528 set_shortname( N_("Skins"))
529 set_description( N_("Skinnable Interface") )
530 set_capability( "interface", 30 )
531 set_callbacks( Open, Close )
532 add_shortcut( "skins" )
536 set_capability( "xwindow", 51 )
538 set_capability( "hwnd", 51 )
540 set_callbacks( WindowOpen, WindowClose )
543 set_description( N_("Skins loader demux") )
544 set_capability( "demux", 5 )
545 set_callbacks( DemuxOpen, NULL )
546 add_shortcut( "skins" )