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"
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 ( intf_thread_t * );
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,
89 } skin_load = { NULL, VLC_STATIC_MUTEX };
91 //---------------------------------------------------------------------------
92 // Open: initialize interface
93 //---------------------------------------------------------------------------
94 static int Open( vlc_object_t *p_this )
96 intf_thread_t *p_intf = (intf_thread_t *)p_this;
98 // Allocate instance and initialize some members
99 p_intf->p_sys = (intf_sys_t *) malloc( sizeof( intf_sys_t ) );
100 if( p_intf->p_sys == NULL )
101 return( VLC_ENOMEM );
103 p_intf->pf_run = Run;
105 // Suscribe to messages bank
107 p_intf->p_sys->p_sub = msg_Subscribe( p_intf );
110 p_intf->p_sys->p_input = NULL;
111 p_intf->p_sys->p_playlist = pl_Hold( p_intf );
113 // Initialize "singleton" objects
114 p_intf->p_sys->p_logger = NULL;
115 p_intf->p_sys->p_queue = NULL;
116 p_intf->p_sys->p_dialogs = NULL;
117 p_intf->p_sys->p_interpreter = NULL;
118 p_intf->p_sys->p_osFactory = NULL;
119 p_intf->p_sys->p_osLoop = NULL;
120 p_intf->p_sys->p_varManager = NULL;
121 p_intf->p_sys->p_voutManager = NULL;
122 p_intf->p_sys->p_vlcProc = NULL;
123 p_intf->p_sys->p_repository = NULL;
126 p_intf->p_sys->b_exitRequested = false;
127 p_intf->p_sys->b_exitOK = false;
131 p_intf->p_sys->p_theme = NULL;
133 // Create a variable to be notified of skins to be loaded
134 var_Create( p_intf, "skin-to-load", VLC_VAR_STRING );
136 // Initialize singletons
137 if( OSFactory::instance( p_intf ) == NULL )
139 msg_Err( p_intf, "cannot initialize OSFactory" );
140 pl_Release( p_intf );
142 msg_Unsubscribe( p_intf, p_intf->p_sys->p_sub );
146 if( AsyncQueue::instance( p_intf ) == NULL )
148 msg_Err( p_intf, "cannot initialize AsyncQueue" );
149 pl_Release( p_intf );
151 msg_Unsubscribe( p_intf, p_intf->p_sys->p_sub );
155 if( Interpreter::instance( p_intf ) == NULL )
157 msg_Err( p_intf, "cannot instanciate Interpreter" );
158 pl_Release( p_intf );
160 msg_Unsubscribe( p_intf, p_intf->p_sys->p_sub );
164 if( VarManager::instance( p_intf ) == NULL )
166 msg_Err( p_intf, "cannot instanciate VarManager" );
167 pl_Release( p_intf );
169 msg_Unsubscribe( p_intf, p_intf->p_sys->p_sub );
173 if( VlcProc::instance( p_intf ) == NULL )
175 msg_Err( p_intf, "cannot initialize VLCProc" );
176 pl_Release( p_intf );
178 msg_Unsubscribe( p_intf, p_intf->p_sys->p_sub );
182 if( VoutManager::instance( p_intf ) == NULL )
184 msg_Err( p_intf, "cannot instanciate VoutManager" );
185 pl_Release( p_intf );
188 vlc_mutex_lock( &skin_load.mutex );
189 skin_load.intf = p_intf;
190 vlc_mutex_unlock( &skin_load.mutex );
192 Dialogs::instance( p_intf );
193 ThemeRepository::instance( p_intf );
196 char *skin_last = config_GetPsz( p_intf, "skins2-last" );
198 ThemeLoader *pLoader = new ThemeLoader( p_intf );
200 if( !skin_last || !*skin_last || !pLoader->load( skin_last ) )
202 // Get the resource path and try to load the default skin
203 OSFactory *pOSFactory = OSFactory::instance( p_intf );
204 const list<string> &resPath = pOSFactory->getResourcePath();
205 const string &sep = pOSFactory->getDirSeparator();
207 list<string>::const_iterator it;
208 for( it = resPath.begin(); it != resPath.end(); it++ )
210 string path = (*it) + sep + "default.vlt";
211 if( pLoader->load( path ) )
213 // Theme loaded successfully
217 if( it == resPath.end() )
219 // Last chance: the user can select a new theme file
220 if( Dialogs::instance( p_intf ) )
222 CmdDlgChangeSkin *pCmd = new CmdDlgChangeSkin( p_intf );
223 AsyncQueue *pQueue = AsyncQueue::instance( p_intf );
224 pQueue->push( CmdGenericPtr( pCmd ) );
228 // No dialogs provider, just quit...
229 CmdQuit *pCmd = new CmdQuit( p_intf );
230 AsyncQueue *pQueue = AsyncQueue::instance( p_intf );
231 pQueue->push( CmdGenericPtr( pCmd ) );
233 "cannot show the \"open skin\" dialog: exiting...");
243 p_intf->b_should_run_on_first_thread = true;
245 // enqueue a command to automatically start the first playlist item
246 AsyncQueue *pQueue = AsyncQueue::instance( p_intf );
247 CmdPlaylistFirst *pCmd = new CmdPlaylistFirst( p_intf );
248 pQueue->push( CmdGenericPtr( pCmd ) );
252 return( VLC_SUCCESS );
255 //---------------------------------------------------------------------------
256 // Close: destroy interface
257 //---------------------------------------------------------------------------
258 static void Close( vlc_object_t *p_this )
260 intf_thread_t *p_intf = (intf_thread_t *)p_this;
262 msg_Dbg( p_intf, "closing skins2 module" );
264 vlc_mutex_lock( &skin_load.mutex );
265 skin_load.intf = NULL;
266 vlc_mutex_unlock( &skin_load.mutex);
268 if( p_intf->p_sys->p_theme )
270 delete p_intf->p_sys->p_theme;
271 p_intf->p_sys->p_theme = NULL;
272 msg_Dbg( p_intf, "current theme deleted" );
275 // Destroy "singleton" objects
276 OSFactory::instance( p_intf )->destroyOSLoop();
277 ThemeRepository::destroy( p_intf );
278 VoutManager::destroy( p_intf );
279 //Dialogs::destroy( p_intf );
280 Interpreter::destroy( p_intf );
281 AsyncQueue::destroy( p_intf );
282 VarManager::destroy( p_intf );
283 VlcProc::destroy( p_intf );
284 OSFactory::destroy( p_intf );
286 if( p_intf->p_sys->p_playlist )
288 vlc_object_release( p_intf->p_sys->p_playlist );
291 // Unsubscribe from messages bank
293 msg_Unsubscribe( p_intf, p_intf->p_sys->p_sub );
297 free( p_intf->p_sys );
301 //---------------------------------------------------------------------------
303 //---------------------------------------------------------------------------
304 static void Run( intf_thread_t *p_intf )
306 int canc = vlc_savecancel();
308 // Get the instance of OSLoop
309 OSLoop *loop = OSFactory::instance( p_intf )->getOSLoop();
311 // Enter the main event loop
314 // Delete the theme and save the configuration of the windows
315 if( p_intf->p_sys->p_theme )
317 p_intf->p_sys->p_theme->saveConfig();
320 // cannot be called in "Close", because it refcounts skins2
321 Dialogs::destroy( p_intf );
324 config_SaveConfigFile( p_intf, NULL );
326 vlc_restorecancel(canc);
330 // Callbacks for vout requests
331 static int WindowOpen( vlc_object_t *p_this )
333 vout_window_t *pWnd = (vout_window_t *)p_this;
334 intf_thread_t *pIntf = (intf_thread_t *)
335 vlc_object_find_name( p_this, "skins2", FIND_ANYWHERE );
340 vlc_object_release( pIntf );
342 pWnd->handle.hwnd = VoutManager::getWindow( pIntf, pWnd );
344 if( pWnd->handle.hwnd )
346 pWnd->p_private = pIntf;
347 pWnd->control = &VoutManager::controlWindow;
356 static void WindowClose( vlc_object_t *p_this )
358 vout_window_t *pWnd = (vout_window_t *)p_this;
359 intf_thread_t *pIntf = (intf_thread_t *)p_this->p_private;
361 VoutManager::releaseWindow( pIntf, pWnd );
364 //---------------------------------------------------------------------------
365 // DemuxOpen: initialize demux
366 //---------------------------------------------------------------------------
367 static int DemuxOpen( vlc_object_t *p_this )
369 demux_t *p_demux = (demux_t*)p_this;
370 intf_thread_t *p_intf;
374 p_demux->pf_demux = Demux;
375 p_demux->pf_control = DemuxControl;
377 // Test that we have a valid .vlt or .wsz file, based on the extension
378 // TODO: an actual check of the contents would be better...
379 if( ( ext = strchr( p_demux->psz_path, '.' ) ) == NULL ||
380 ( strcasecmp( ext, ".vlt" ) && strcasecmp( ext, ".wsz" ) ) )
385 vlc_mutex_lock( &skin_load.mutex );
386 p_intf = skin_load.intf;
388 vlc_object_hold( p_intf );
389 vlc_mutex_unlock( &skin_load.mutex );
393 playlist_t *p_playlist = pl_Hold( p_this );
394 // Make sure the item is deleted afterwards
395 /// \bug does not always work
396 playlist_CurrentPlayingItem( p_playlist )->i_flags |= PLAYLIST_REMOVE_FLAG;
397 pl_Release( p_this );
399 var_SetString( p_intf, "skin-to-load", p_demux->psz_path );
400 vlc_object_release( p_intf );
405 "skin could not be loaded (not using skins2 intf)" );
412 //---------------------------------------------------------------------------
414 //---------------------------------------------------------------------------
415 static int Demux( demux_t *p_demux )
421 //---------------------------------------------------------------------------
423 //---------------------------------------------------------------------------
424 static int DemuxControl( demux_t *p_demux, int i_query, va_list args )
426 return demux_vaControlHelper( p_demux->s, 0, 0, 0, 1, i_query, args );
430 //---------------------------------------------------------------------------
432 //---------------------------------------------------------------------------
434 /// Callback for the systray configuration option
435 static int onSystrayChange( vlc_object_t *pObj, const char *pVariable,
436 vlc_value_t oldVal, vlc_value_t newVal,
439 intf_thread_t *pIntf;
441 vlc_mutex_lock( &skin_load.mutex );
442 pIntf = skin_load.intf;
444 vlc_object_hold( pIntf );
445 vlc_mutex_unlock( &skin_load.mutex );
452 AsyncQueue *pQueue = AsyncQueue::instance( pIntf );
455 CmdAddInTray *pCmd = new CmdAddInTray( pIntf );
456 pQueue->push( CmdGenericPtr( pCmd ) );
460 CmdRemoveFromTray *pCmd = new CmdRemoveFromTray( pIntf );
461 pQueue->push( CmdGenericPtr( pCmd ) );
464 vlc_object_release( pIntf );
469 /// Callback for the systray configuration option
470 static int onTaskBarChange( vlc_object_t *pObj, const char *pVariable,
471 vlc_value_t oldVal, vlc_value_t newVal,
474 intf_thread_t *pIntf;
476 vlc_mutex_lock( &skin_load.mutex );
477 pIntf = skin_load.intf;
479 vlc_object_hold( pIntf );
480 vlc_mutex_unlock( &skin_load.mutex );
487 AsyncQueue *pQueue = AsyncQueue::instance( pIntf );
490 CmdAddInTaskBar *pCmd = new CmdAddInTaskBar( pIntf );
491 pQueue->push( CmdGenericPtr( pCmd ) );
495 CmdRemoveFromTaskBar *pCmd = new CmdRemoveFromTaskBar( pIntf );
496 pQueue->push( CmdGenericPtr( pCmd ) );
499 vlc_object_release( pIntf );
504 //---------------------------------------------------------------------------
506 //---------------------------------------------------------------------------
507 #define SKINS2_LAST N_("Skin to use")
508 #define SKINS2_LAST_LONG N_("Path to the skin to use.")
509 #define SKINS2_CONFIG N_("Config of last used skin")
510 #define SKINS2_CONFIG_LONG N_("Windows configuration of the last skin used. " \
511 "This option is updated automatically, do not touch it." )
512 #define SKINS2_SYSTRAY N_("Systray icon")
513 #define SKINS2_SYSTRAY_LONG N_("Show a systray icon for VLC")
514 #define SKINS2_TASKBAR N_("Show VLC on the taskbar")
515 #define SKINS2_TASKBAR_LONG N_("Show VLC on the taskbar")
516 #define SKINS2_TRANSPARENCY N_("Enable transparency effects")
517 #define SKINS2_TRANSPARENCY_LONG N_("You can disable all transparency effects"\
518 " if you want. This is mainly useful when moving windows does not behave" \
520 #define SKINS2_PLAYLIST N_("Use a skinned playlist")
521 #define SKINS2_PLAYLIST_LONG N_("Use a skinned playlist")
524 set_category( CAT_INTERFACE )
525 set_subcategory( SUBCAT_INTERFACE_MAIN )
526 add_file( "skins2-last", "", NULL, SKINS2_LAST, SKINS2_LAST_LONG,
529 add_string( "skins2-config", "", NULL, SKINS2_CONFIG, SKINS2_CONFIG_LONG,
534 add_bool( "skins2-systray", false, onSystrayChange, SKINS2_SYSTRAY,
535 SKINS2_SYSTRAY_LONG, false );
536 add_bool( "skins2-taskbar", true, onTaskBarChange, SKINS2_TASKBAR,
537 SKINS2_TASKBAR_LONG, false );
538 add_bool( "skins2-transparency", false, NULL, SKINS2_TRANSPARENCY,
539 SKINS2_TRANSPARENCY_LONG, false );
542 add_bool( "skinned-playlist", true, NULL, SKINS2_PLAYLIST,
543 SKINS2_PLAYLIST_LONG, false );
544 set_shortname( N_("Skins"))
545 set_description( N_("Skinnable Interface") )
546 set_capability( "interface", 30 )
547 set_callbacks( Open, Close )
548 add_shortcut( "skins" )
552 set_capability( "xwindow", 51 )
554 set_capability( "hwnd", 51 )
556 set_callbacks( WindowOpen, WindowClose )
559 set_description( N_("Skins loader demux") )
560 set_capability( "demux", 5 )
561 set_callbacks( DemuxOpen, NULL )
562 add_shortcut( "skins" )