1 /*****************************************************************************
3 *****************************************************************************
4 * Copyright (C) 2003 VideoLAN
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., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
23 *****************************************************************************/
26 #include <vlc/input.h>
27 #include "dialogs.hpp"
28 #include "os_factory.hpp"
29 #include "os_loop.hpp"
30 #include "var_manager.hpp"
31 #include "vlcproc.hpp"
32 #include "theme_loader.hpp"
34 #include "../parser/interpreter.hpp"
35 #include "../commands/async_queue.hpp"
36 #include "../commands/cmd_quit.hpp"
39 //---------------------------------------------------------------------------
40 // Exported interface functions.
41 //---------------------------------------------------------------------------
43 extern "C" __declspec( dllexport )
44 int __VLC_SYMBOL( vlc_entry ) ( module_t *p_module );
48 //---------------------------------------------------------------------------
50 //---------------------------------------------------------------------------
51 static int Open ( vlc_object_t * );
52 static void Close ( vlc_object_t * );
53 static void Run ( intf_thread_t * );
55 static int DemuxOpen( vlc_object_t * );
56 static int Demux( demux_t * );
57 static int DemuxControl( demux_t *, int, va_list );
60 //---------------------------------------------------------------------------
61 // Open: initialize interface
62 //---------------------------------------------------------------------------
63 static int Open( vlc_object_t *p_this )
65 intf_thread_t *p_intf = (intf_thread_t *)p_this;
67 // Allocate instance and initialize some members
68 p_intf->p_sys = (intf_sys_t *) malloc( sizeof( intf_sys_t ) );
69 if( p_intf->p_sys == NULL )
71 msg_Err( p_intf, "out of memory" );
77 // Suscribe to messages bank
78 p_intf->p_sys->p_sub = msg_Subscribe( p_intf );
80 p_intf->p_sys->p_input = NULL;
81 p_intf->p_sys->p_playlist = (playlist_t *)vlc_object_find( p_intf,
82 VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
83 if( p_intf->p_sys->p_playlist == NULL )
85 msg_Err( p_intf, "No playlist object found" );
89 // Initialize "singleton" objects
90 p_intf->p_sys->p_logger = NULL;
91 p_intf->p_sys->p_queue = NULL;
92 p_intf->p_sys->p_dialogs = NULL;
93 p_intf->p_sys->p_interpreter = NULL;
94 p_intf->p_sys->p_osFactory = NULL;
95 p_intf->p_sys->p_osLoop = NULL;
96 p_intf->p_sys->p_varManager = NULL;
97 p_intf->p_sys->p_vlcProc = NULL;
100 p_intf->p_sys->p_theme = NULL;
102 // Create a variable to be notified of skins to be loaded
103 var_Create( p_intf, "skin-to-load", VLC_VAR_STRING );
105 // Initialize singletons
106 if( OSFactory::instance( p_intf ) == NULL )
108 msg_Err( p_intf, "Cannot initialize OSFactory" );
111 if( AsyncQueue::instance( p_intf ) == NULL )
113 msg_Err( p_intf, "Cannot initialize AsyncQueue" );
116 if( Interpreter::instance( p_intf ) == NULL )
118 msg_Err( p_intf, "Cannot instanciate Interpreter" );
121 if( VarManager::instance( p_intf ) == NULL )
123 msg_Err( p_intf, "Cannot instanciate VarManager" );
126 if( VlcProc::instance( p_intf ) == NULL )
128 msg_Err( p_intf, "Cannot initialize VLCProc" );
131 Dialogs::instance( p_intf );
133 // We support play on start
134 p_intf->b_play = VLC_TRUE;
136 return( VLC_SUCCESS );
139 //---------------------------------------------------------------------------
140 // Close: destroy interface
141 //---------------------------------------------------------------------------
142 static void Close( vlc_object_t *p_this )
144 intf_thread_t *p_intf = (intf_thread_t *)p_this;
146 // Destroy "singleton" objects
147 OSFactory::instance( p_intf )->destroyOSLoop();
148 Dialogs::destroy( p_intf );
149 Interpreter::destroy( p_intf );
150 AsyncQueue::destroy( p_intf );
151 VarManager::destroy( p_intf );
152 VlcProc::destroy( p_intf );
153 OSFactory::destroy( p_intf );
155 if( p_intf->p_sys->p_playlist )
157 vlc_object_release( p_intf->p_sys->p_playlist );
160 // Unsubscribe from messages bank
161 msg_Unsubscribe( p_intf, p_intf->p_sys->p_sub );
164 free( p_intf->p_sys );
168 //---------------------------------------------------------------------------
170 //---------------------------------------------------------------------------
171 static void Run( intf_thread_t *p_intf )
174 ThemeLoader *pLoader = new ThemeLoader( p_intf );
175 char *skin_last = config_GetPsz( p_intf, "skins2-last" );
177 if( !skin_last || !*skin_last || !pLoader->load( skin_last ) )
179 // Get the resource path and try to load the default skin
180 OSFactory *pOSFactory = OSFactory::instance( p_intf );
181 const list<string> &resPath = pOSFactory->getResourcePath();
182 const string &sep = pOSFactory->getDirSeparator();
184 list<string>::const_iterator it;
185 for( it = resPath.begin(); it != resPath.end(); it++ )
187 string path = (*it) + sep + "default" + sep + "theme.xml";
188 if( pLoader->load( path ) )
190 // Theme loaded successfully
194 if( it == resPath.end() )
196 // Last chance: the user can select a new theme file
197 Dialogs *pDialogs = Dialogs::instance( p_intf );
200 pDialogs->showChangeSkin();
204 // No dialogs provider, just quit...
205 CmdQuit *pCmd = new CmdQuit( p_intf );
206 AsyncQueue *pQueue = AsyncQueue::instance( p_intf );
207 pQueue->push( CmdGenericPtr( pCmd ) );
209 "Cannot show the \"open skin\" dialog: exiting...");
220 // Get the instance of OSLoop
221 OSLoop *loop = OSFactory::instance( p_intf )->getOSLoop();
223 // Check if we need to start playing
226 playlist_t *p_playlist =
227 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
231 playlist_Play( p_playlist );
232 vlc_object_release( p_playlist );
236 // Enter the main event loop
239 // Delete the theme and save the configuration of the windows
240 if( p_intf->p_sys->p_theme )
242 p_intf->p_sys->p_theme->saveConfig();
243 delete p_intf->p_sys->p_theme;
244 p_intf->p_sys->p_theme = NULL;
249 //---------------------------------------------------------------------------
250 // DemuxOpen: initialize demux
251 //---------------------------------------------------------------------------
252 static int DemuxOpen( vlc_object_t *p_this )
254 demux_t *p_demux = (demux_t*)p_this;
255 intf_thread_t *p_intf;
259 p_demux->pf_demux = Demux;
260 p_demux->pf_control = DemuxControl;
262 // Test that we have a valid .vlt file, based on the extension
263 // TODO: an actual check of the contents would be better...
264 if( ( ext = strchr( p_demux->psz_path, '.' ) ) == NULL ||
265 strcasecmp( ext, ".vlt" ) )
270 p_intf = (intf_thread_t *)vlc_object_find( p_this, VLC_OBJECT_INTF,
274 // Do nothing is skins2 is not the main interface
275 if( var_Type( p_intf, "skin-to-load" ) != VLC_VAR_STRING )
277 playlist_t *p_playlist =
278 (playlist_t *) vlc_object_find( p_this, VLC_OBJECT_PLAYLIST,
280 if( p_playlist != NULL )
282 // Make sure the item is deleted afterwards
283 p_playlist->pp_items[p_playlist->i_index]->b_autodeletion =
285 vlc_object_release( p_playlist );
289 val.psz_string = p_demux->psz_path;
290 var_Set( p_intf, "skin-to-load", val );
295 "skin could not be loaded (not using skins2 intf)" );
298 vlc_object_release( p_intf );
305 //---------------------------------------------------------------------------
307 //---------------------------------------------------------------------------
308 static int Demux( demux_t *p_demux )
314 //---------------------------------------------------------------------------
316 //---------------------------------------------------------------------------
317 static int DemuxControl( demux_t *p_demux, int i_query, va_list args )
319 return demux2_vaControlHelper( p_demux->s, 0, 0, 0, 1, i_query, args );
323 //---------------------------------------------------------------------------
325 //---------------------------------------------------------------------------
326 #define SKINS2_LAST N_("Last skin used")
327 #define SKINS2_LAST_LONG N_("Select the path to the last skin used.")
328 #define SKINS2_CONFIG N_("Config of last used skin")
329 #define SKINS2_CONFIG_LONG N_("Config of last used skin.")
330 #define SKINS2_TRANSPARENCY N_("Enable transparency effects")
331 #define SKINS2_TRANSPARENCY_LONG N_("You can disable all transparency effects"\
332 " if you want. This is mainly useful when moving windows does not behave" \
336 add_string( "skins2-last", "", NULL, SKINS2_LAST, SKINS2_LAST_LONG,
338 add_string( "skins2-config", "", NULL, SKINS2_CONFIG, SKINS2_CONFIG_LONG,
341 add_bool( "skins2-transparency", VLC_FALSE, NULL, SKINS2_TRANSPARENCY,
342 SKINS2_TRANSPARENCY_LONG, VLC_FALSE );
344 set_description( _("Skinnable Interface") );
345 set_capability( "interface", 30 );
346 set_callbacks( Open, Close );
347 set_program( "svlc" );
350 set_description( _("Skins loader demux") );
351 set_capability( "demux2", 5 );
352 set_callbacks( DemuxOpen, NULL );