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_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 "../parser/interpreter.hpp"
45 #include "../commands/async_queue.hpp"
46 #include "../commands/cmd_quit.hpp"
47 #include "../commands/cmd_dialogs.hpp"
48 #include "../commands/cmd_minimize.hpp"
50 //---------------------------------------------------------------------------
51 // Exported interface functions.
52 //---------------------------------------------------------------------------
54 extern "C" __declspec( dllexport )
55 int __VLC_SYMBOL( vlc_entry ) ( module_t *p_module );
59 //---------------------------------------------------------------------------
61 //---------------------------------------------------------------------------
62 static int Open ( vlc_object_t * );
63 static void Close ( vlc_object_t * );
64 static void Run ( intf_thread_t * );
66 static int DemuxOpen( vlc_object_t * );
67 static int Demux( demux_t * );
68 static int DemuxControl( demux_t *, int, va_list );
70 //---------------------------------------------------------------------------
71 // Prototypes for configuration callbacks
72 //---------------------------------------------------------------------------
73 static int onSystrayChange( vlc_object_t *pObj, const char *pVariable,
74 vlc_value_t oldVal, vlc_value_t newVal,
76 static int onTaskBarChange( vlc_object_t *pObj, const char *pVariable,
77 vlc_value_t oldVal, vlc_value_t newVal,
81 //---------------------------------------------------------------------------
82 // Open: initialize interface
83 //---------------------------------------------------------------------------
84 static int Open( vlc_object_t *p_this )
86 intf_thread_t *p_intf = (intf_thread_t *)p_this;
88 // Allocate instance and initialize some members
89 p_intf->p_sys = (intf_sys_t *) malloc( sizeof( intf_sys_t ) );
90 if( p_intf->p_sys == NULL )
92 msg_Err( p_intf, "out of memory" );
98 // Suscribe to messages bank
100 p_intf->p_sys->p_sub = msg_Subscribe( p_intf );
103 p_intf->p_sys->p_input = NULL;
104 p_intf->p_sys->p_playlist = pl_Hold( p_intf );
106 // Initialize "singleton" objects
107 p_intf->p_sys->p_logger = NULL;
108 p_intf->p_sys->p_queue = NULL;
109 p_intf->p_sys->p_dialogs = NULL;
110 p_intf->p_sys->p_interpreter = NULL;
111 p_intf->p_sys->p_osFactory = NULL;
112 p_intf->p_sys->p_osLoop = NULL;
113 p_intf->p_sys->p_varManager = NULL;
114 p_intf->p_sys->p_vlcProc = NULL;
115 p_intf->p_sys->p_repository = NULL;
118 p_intf->p_sys->p_theme = NULL;
120 // Create a variable to be notified of skins to be loaded
121 var_Create( p_intf, "skin-to-load", VLC_VAR_STRING );
123 // Initialize singletons
124 if( OSFactory::instance( p_intf ) == NULL )
126 msg_Err( p_intf, "cannot initialize OSFactory" );
127 vlc_object_release( p_intf->p_sys->p_playlist );
129 msg_Unsubscribe( p_intf, p_intf->p_sys->p_sub );
133 if( AsyncQueue::instance( p_intf ) == NULL )
135 msg_Err( p_intf, "cannot initialize AsyncQueue" );
136 vlc_object_release( p_intf->p_sys->p_playlist );
138 msg_Unsubscribe( p_intf, p_intf->p_sys->p_sub );
142 if( Interpreter::instance( p_intf ) == NULL )
144 msg_Err( p_intf, "cannot instanciate Interpreter" );
145 vlc_object_release( p_intf->p_sys->p_playlist );
147 msg_Unsubscribe( p_intf, p_intf->p_sys->p_sub );
151 if( VarManager::instance( p_intf ) == NULL )
153 msg_Err( p_intf, "cannot instanciate VarManager" );
154 vlc_object_release( p_intf->p_sys->p_playlist );
156 msg_Unsubscribe( p_intf, p_intf->p_sys->p_sub );
160 if( VlcProc::instance( p_intf ) == NULL )
162 msg_Err( p_intf, "cannot initialize VLCProc" );
163 vlc_object_release( p_intf->p_sys->p_playlist );
165 msg_Unsubscribe( p_intf, p_intf->p_sys->p_sub );
169 Dialogs::instance( p_intf );
170 ThemeRepository::instance( p_intf );
173 p_intf->b_should_run_on_first_thread = true;
176 return( VLC_SUCCESS );
179 //---------------------------------------------------------------------------
180 // Close: destroy interface
181 //---------------------------------------------------------------------------
182 static void Close( vlc_object_t *p_this )
184 intf_thread_t *p_intf = (intf_thread_t *)p_this;
186 // Destroy "singleton" objects
187 OSFactory::instance( p_intf )->destroyOSLoop();
188 ThemeRepository::destroy( p_intf );
189 Dialogs::destroy( p_intf );
190 Interpreter::destroy( p_intf );
191 AsyncQueue::destroy( p_intf );
192 VarManager::destroy( p_intf );
193 VlcProc::destroy( p_intf );
194 OSFactory::destroy( p_intf );
196 if( p_intf->p_sys->p_playlist )
198 vlc_object_release( p_intf->p_sys->p_playlist );
201 // Unsubscribe from messages bank
203 msg_Unsubscribe( p_intf, p_intf->p_sys->p_sub );
207 free( p_intf->p_sys );
211 //---------------------------------------------------------------------------
213 //---------------------------------------------------------------------------
214 static void Run( intf_thread_t *p_intf )
216 int canc = vlc_savecancel();
218 ThemeLoader *pLoader = new ThemeLoader( p_intf );
219 char *skin_last = config_GetPsz( p_intf, "skins2-last" );
221 if( !skin_last || !*skin_last || !pLoader->load( skin_last ) )
223 // Get the resource path and try to load the default skin
224 OSFactory *pOSFactory = OSFactory::instance( p_intf );
225 const list<string> &resPath = pOSFactory->getResourcePath();
226 const string &sep = pOSFactory->getDirSeparator();
228 list<string>::const_iterator it;
229 for( it = resPath.begin(); it != resPath.end(); it++ )
231 string path = (*it) + sep + "default.vlt";
232 if( pLoader->load( path ) )
234 // Theme loaded successfully
238 if( it == resPath.end() )
240 // Last chance: the user can select a new theme file
241 if( Dialogs::instance( p_intf ) )
243 CmdDlgChangeSkin *pCmd = new CmdDlgChangeSkin( p_intf );
244 AsyncQueue *pQueue = AsyncQueue::instance( p_intf );
245 pQueue->push( CmdGenericPtr( pCmd ) );
249 // No dialogs provider, just quit...
250 CmdQuit *pCmd = new CmdQuit( p_intf );
251 AsyncQueue *pQueue = AsyncQueue::instance( p_intf );
252 pQueue->push( CmdGenericPtr( pCmd ) );
254 "cannot show the \"open skin\" dialog: exiting...");
262 // Get the instance of OSLoop
263 OSLoop *loop = OSFactory::instance( p_intf )->getOSLoop();
265 // Enter the main event loop
268 // Delete the theme and save the configuration of the windows
269 if( p_intf->p_sys->p_theme )
271 p_intf->p_sys->p_theme->saveConfig();
272 delete p_intf->p_sys->p_theme;
273 p_intf->p_sys->p_theme = NULL;
275 vlc_restorecancel(canc);
279 // Callbacks for vout requests
280 static int WindowOpen( vlc_object_t *p_this )
282 vout_window_t *pWnd = (vout_window_t *)p_this;
283 intf_thread_t *pIntf = (intf_thread_t *)
284 vlc_object_find_name( p_this, "skins2", FIND_ANYWHERE );
289 /* FIXME: most probably not thread-safe,
290 * albeit no worse than ever before */
291 pWnd->handle = VlcProc::getWindow( pIntf, pWnd->vout,
292 &pWnd->pos_x, &pWnd->pos_y,
293 &pWnd->width, &pWnd->height );
294 pWnd->p_private = pIntf;
295 pWnd->control = &VlcProc::controlWindow;
300 static void WindowClose( vlc_object_t *p_this )
302 vout_window_t *pWnd = (vout_window_t *)p_this;
303 intf_thread_t *pIntf = (intf_thread_t *)p_this->p_private;
305 VlcProc::releaseWindow( pIntf, pWnd->handle );
308 //---------------------------------------------------------------------------
309 // DemuxOpen: initialize demux
310 //---------------------------------------------------------------------------
311 static int DemuxOpen( vlc_object_t *p_this )
313 demux_t *p_demux = (demux_t*)p_this;
314 intf_thread_t *p_intf;
318 p_demux->pf_demux = Demux;
319 p_demux->pf_control = DemuxControl;
321 // Test that we have a valid .vlt or .wsz file, based on the extension
322 // TODO: an actual check of the contents would be better...
323 if( ( ext = strchr( p_demux->psz_path, '.' ) ) == NULL ||
324 ( strcasecmp( ext, ".vlt" ) && strcasecmp( ext, ".wsz" ) ) )
329 p_intf = (intf_thread_t *)vlc_object_find( p_this, VLC_OBJECT_INTF,
333 // Do nothing is skins2 is not the main interface
334 if( var_Type( p_intf, "skin-to-load" ) == VLC_VAR_STRING )
336 playlist_t *p_playlist = pl_Hold( p_this );
337 // Make sure the item is deleted afterwards
338 /// \bug does not always work
339 playlist_CurrentPlayingItem( p_playlist )->i_flags |= PLAYLIST_REMOVE_FLAG;
340 vlc_object_release( p_playlist );
343 val.psz_string = p_demux->psz_path;
344 var_Set( p_intf, "skin-to-load", val );
349 "skin could not be loaded (not using skins2 intf)" );
352 vlc_object_release( p_intf );
359 //---------------------------------------------------------------------------
361 //---------------------------------------------------------------------------
362 static int Demux( demux_t *p_demux )
368 //---------------------------------------------------------------------------
370 //---------------------------------------------------------------------------
371 static int DemuxControl( demux_t *p_demux, int i_query, va_list args )
373 return demux_vaControlHelper( p_demux->s, 0, 0, 0, 1, i_query, args );
377 //---------------------------------------------------------------------------
379 //---------------------------------------------------------------------------
381 /// Callback for the systray configuration option
382 static int onSystrayChange( vlc_object_t *pObj, const char *pVariable,
383 vlc_value_t oldVal, vlc_value_t newVal,
386 intf_thread_t *pIntf =
387 (intf_thread_t*)vlc_object_find( pObj, VLC_OBJECT_INTF, FIND_ANYWHERE );
394 // Check that we found the correct interface (same check as for the demux)
395 if( var_Type( pIntf, "skin-to-load" ) == VLC_VAR_STRING )
397 AsyncQueue *pQueue = AsyncQueue::instance( pIntf );
400 CmdAddInTray *pCmd = new CmdAddInTray( pIntf );
401 pQueue->push( CmdGenericPtr( pCmd ) );
405 CmdRemoveFromTray *pCmd = new CmdRemoveFromTray( pIntf );
406 pQueue->push( CmdGenericPtr( pCmd ) );
410 vlc_object_release( pIntf );
415 /// Callback for the systray configuration option
416 static int onTaskBarChange( vlc_object_t *pObj, const char *pVariable,
417 vlc_value_t oldVal, vlc_value_t newVal,
420 intf_thread_t *pIntf =
421 (intf_thread_t*)vlc_object_find( pObj, VLC_OBJECT_INTF, FIND_ANYWHERE );
428 // Check that we found the correct interface (same check as for the demux)
429 if( var_Type( pIntf, "skin-to-load" ) == VLC_VAR_STRING )
431 AsyncQueue *pQueue = AsyncQueue::instance( pIntf );
434 CmdAddInTaskBar *pCmd = new CmdAddInTaskBar( pIntf );
435 pQueue->push( CmdGenericPtr( pCmd ) );
439 CmdRemoveFromTaskBar *pCmd = new CmdRemoveFromTaskBar( pIntf );
440 pQueue->push( CmdGenericPtr( pCmd ) );
444 vlc_object_release( pIntf );
449 //---------------------------------------------------------------------------
451 //---------------------------------------------------------------------------
452 #define SKINS2_LAST N_("Skin to use")
453 #define SKINS2_LAST_LONG N_("Path to the skin to use.")
454 #define SKINS2_CONFIG N_("Config of last used skin")
455 #define SKINS2_CONFIG_LONG N_("Windows configuration of the last skin used. " \
456 "This option is updated automatically, do not touch it." )
457 #define SKINS2_SYSTRAY N_("Systray icon")
458 #define SKINS2_SYSTRAY_LONG N_("Show a systray icon for VLC")
459 #define SKINS2_TASKBAR N_("Show VLC on the taskbar")
460 #define SKINS2_TASKBAR_LONG N_("Show VLC on the taskbar")
461 #define SKINS2_TRANSPARENCY N_("Enable transparency effects")
462 #define SKINS2_TRANSPARENCY_LONG N_("You can disable all transparency effects"\
463 " if you want. This is mainly useful when moving windows does not behave" \
465 #define SKINS2_PLAYLIST N_("Use a skinned playlist")
466 #define SKINS2_PLAYLIST_LONG N_("Use a skinned playlist")
469 set_category( CAT_INTERFACE );
470 set_subcategory( SUBCAT_INTERFACE_MAIN );
471 add_file( "skins2-last", "", NULL, SKINS2_LAST, SKINS2_LAST_LONG,
474 add_string( "skins2-config", "", NULL, SKINS2_CONFIG, SKINS2_CONFIG_LONG,
479 add_bool( "skins2-systray", false, onSystrayChange, SKINS2_SYSTRAY,
480 SKINS2_SYSTRAY_LONG, false );
481 add_bool( "skins2-taskbar", true, onTaskBarChange, SKINS2_TASKBAR,
482 SKINS2_TASKBAR_LONG, false );
483 add_bool( "skins2-transparency", false, NULL, SKINS2_TRANSPARENCY,
484 SKINS2_TRANSPARENCY_LONG, false );
487 add_bool( "skinned-playlist", true, NULL, SKINS2_PLAYLIST,
488 SKINS2_PLAYLIST_LONG, false );
489 set_shortname( N_("Skins"));
490 set_description( N_("Skinnable Interface") );
491 set_capability( "interface", 30 );
492 set_callbacks( Open, Close );
493 add_shortcut( "skins" );
496 set_capability( "vout window", 51 );
497 set_callbacks( WindowOpen, WindowClose );
500 set_description( N_("Skins loader demux") );
501 set_capability( "demux", 5 );
502 set_callbacks( DemuxOpen, NULL );