]> git.sesse.net Git - vlc/blob - modules/gui/skins2/src/skin_main.cpp
* skins2/src/skin_main.cpp: Transparency is default disabled
[vlc] / modules / gui / skins2 / src / skin_main.cpp
1 /*****************************************************************************
2  * skin_main.cpp
3  *****************************************************************************
4  * Copyright (C) 2003 VideoLAN
5  * $Id$
6  *
7  * Authors: Cyril Deguet     <asmax@via.ecp.fr>
8  *          Olivier Teulière <ipkiss@via.ecp.fr>
9  *
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.
14  *
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.
19  *
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  *****************************************************************************/
24
25 #include <stdlib.h>
26 #include "dialogs.hpp"
27 #include "os_factory.hpp"
28 #include "os_loop.hpp"
29 #include "var_manager.hpp"
30 #include "vlcproc.hpp"
31 #include "theme_loader.hpp"
32 #include "theme.hpp"
33 #include "../parser/interpreter.hpp"
34 #include "../commands/async_queue.hpp"
35 #include "../commands/cmd_quit.hpp"
36
37
38 //---------------------------------------------------------------------------
39 // Exported interface functions.
40 //---------------------------------------------------------------------------
41 #ifdef WIN32_SKINS
42 extern "C" __declspec( dllexport )
43     int __VLC_SYMBOL( vlc_entry ) ( module_t *p_module );
44 #endif
45
46
47 //---------------------------------------------------------------------------
48 // Local prototypes.
49 //---------------------------------------------------------------------------
50 static int  Open  ( vlc_object_t * );
51 static void Close ( vlc_object_t * );
52 static void Run   ( intf_thread_t * );
53
54
55 //---------------------------------------------------------------------------
56 // Open: initialize interface
57 //---------------------------------------------------------------------------
58 static int Open( vlc_object_t *p_this )
59 {
60     intf_thread_t *p_intf = (intf_thread_t *)p_this;
61
62     // Allocate instance and initialize some members
63     p_intf->p_sys = (intf_sys_t *) malloc( sizeof( intf_sys_t ) );
64     if( p_intf->p_sys == NULL )
65     {
66         msg_Err( p_intf, "out of memory" );
67         return( VLC_ENOMEM );
68     };
69
70     p_intf->pf_run = Run;
71
72     // Suscribe to messages bank
73     p_intf->p_sys->p_sub = msg_Subscribe( p_intf );
74
75     p_intf->p_sys->p_input = NULL;
76     p_intf->p_sys->p_playlist = (playlist_t *)vlc_object_find( p_intf,
77         VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
78     if( p_intf->p_sys->p_playlist == NULL )
79     {
80         msg_Err( p_intf, "No playlist object found" );
81         return VLC_EGENERIC;
82     }
83
84     // Initialize "singleton" objects
85     p_intf->p_sys->p_logger = NULL;
86     p_intf->p_sys->p_queue = NULL;
87     p_intf->p_sys->p_dialogs = NULL;
88     p_intf->p_sys->p_interpreter = NULL;
89     p_intf->p_sys->p_osFactory = NULL;
90     p_intf->p_sys->p_osLoop = NULL;
91     p_intf->p_sys->p_varManager = NULL;
92     p_intf->p_sys->p_vlcProc = NULL;
93
94     // No theme yet
95     p_intf->p_sys->p_theme = NULL;
96
97     // Initialize singletons
98     if( OSFactory::instance( p_intf ) == NULL )
99     {
100         msg_Err( p_intf, "Cannot initialize OSFactory" );
101         return VLC_EGENERIC;
102     }
103     if( AsyncQueue::instance( p_intf ) == NULL )
104     {
105         msg_Err( p_intf, "Cannot initialize AsyncQueue" );
106         return VLC_EGENERIC;
107     }
108     if( Interpreter::instance( p_intf ) == NULL )
109     {
110         msg_Err( p_intf, "Cannot instanciate Interpreter" );
111         return VLC_EGENERIC;
112     }
113     if( VarManager::instance( p_intf ) == NULL )
114     {
115         msg_Err( p_intf, "Cannot instanciate VarManager" );
116         return VLC_EGENERIC;
117     }
118     if( VlcProc::instance( p_intf ) == NULL )
119     {
120         msg_Err( p_intf, "Cannot initialize VLCProc" );
121         return VLC_EGENERIC;
122     }
123     Dialogs::instance( p_intf );
124
125     /* We support play on start */
126     p_intf->b_play = VLC_TRUE;
127
128     return( VLC_SUCCESS );
129 }
130
131 //---------------------------------------------------------------------------
132 // Close: destroy interface
133 //---------------------------------------------------------------------------
134 static void Close( vlc_object_t *p_this )
135 {
136     intf_thread_t *p_intf = (intf_thread_t *)p_this;
137
138     // Destroy "singleton" objects
139     OSFactory::instance( p_intf )->destroyOSLoop();
140     Dialogs::destroy( p_intf );
141     Interpreter::destroy( p_intf );
142     AsyncQueue::destroy( p_intf );
143     VarManager::destroy( p_intf );
144     VlcProc::destroy( p_intf );
145     OSFactory::destroy( p_intf );
146
147     if( p_intf->p_sys->p_playlist )
148     {
149         vlc_object_release( p_intf->p_sys->p_playlist );
150     }
151
152    // Unsuscribe to messages bank
153     msg_Unsubscribe( p_intf, p_intf->p_sys->p_sub );
154
155     // Destroy structure
156     free( p_intf->p_sys );
157 }
158
159
160 //---------------------------------------------------------------------------
161 // Run: main loop
162 //---------------------------------------------------------------------------
163 static void Run( intf_thread_t *p_intf )
164 {
165     // Load a theme
166     ThemeLoader *pLoader = new ThemeLoader( p_intf );
167     char *skin_last = config_GetPsz( p_intf, "skins2-last" );
168
169     if( !skin_last || !*skin_last || !pLoader->load( skin_last ) )
170     {
171         // Get the resource path and try to load the default skin
172         OSFactory *pOSFactory = OSFactory::instance( p_intf );
173         const list<string> &resPath = pOSFactory->getResourcePath();
174         const string &sep = pOSFactory->getDirSeparator();
175
176         list<string>::const_iterator it;
177         for( it = resPath.begin(); it != resPath.end(); it++ )
178         {
179             string path = (*it) + sep + "default" + sep + "theme.xml";
180             if( pLoader->load( path ) )
181             {
182                 // Theme loaded successfully
183                 break;
184             }
185         }
186         if( it == resPath.end() )
187         {
188             // Last chance: the user can select a new theme file
189             Dialogs *pDialogs = Dialogs::instance( p_intf );
190             if( pDialogs )
191             {
192                 pDialogs->showChangeSkin();
193             }
194             else
195             {
196                 // No dialogs provider, just quit...
197                 CmdQuit *pCmd = new CmdQuit( p_intf );
198                 AsyncQueue *pQueue = AsyncQueue::instance( p_intf );
199                 pQueue->push( CmdGenericPtr( pCmd ) );
200                 msg_Err( p_intf, "Cannot show the \"open skin\" dialog: exiting...");
201             }
202         }
203     }
204     delete pLoader;
205
206     if( skin_last )
207     {
208         free( skin_last );
209     }
210
211     // Get the instance of OSLoop
212     OSLoop *loop = OSFactory::instance( p_intf )->getOSLoop();
213
214     // Check if we need to start playing
215     if( p_intf->b_play )
216     {
217         playlist_t *p_playlist =
218             (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
219                                            FIND_ANYWHERE );
220         if( p_playlist )
221         {
222             playlist_Play( p_playlist );
223             vlc_object_release( p_playlist );
224         }
225     }
226
227     // Enter the main event loop
228     loop->run();
229
230     // Delete the theme and save the configuration of the windows
231     if( p_intf->p_sys->p_theme )
232     {
233         p_intf->p_sys->p_theme->saveConfig();
234         delete p_intf->p_sys->p_theme;
235         p_intf->p_sys->p_theme = NULL;
236     }
237 }
238
239 //---------------------------------------------------------------------------
240 // Module descriptor
241 //---------------------------------------------------------------------------
242 #define SKINS2_LAST      N_("Last skin used")
243 #define SKINS2_LAST_LONG N_("Select the path to the last skin used.")
244 #define SKINS2_CONFIG      N_("Config of last used skin")
245 #define SKINS2_CONFIG_LONG N_("Config of last used skin.")
246 #define SKINS2_TRANSPARENCY      N_("Enable transparency effects")
247 #define SKINS2_TRANSPARENCY_LONG N_("You can disable all transparency effects"\
248     " if you want. This is mainly useful when moving windows does not behave" \
249     " correctly.")
250
251 vlc_module_begin();
252     add_string( "skins2-last", "", NULL, SKINS2_LAST, SKINS2_LAST_LONG,
253                 VLC_TRUE );
254     add_string( "skins2-config", "", NULL, SKINS2_CONFIG, SKINS2_CONFIG_LONG,
255                 VLC_TRUE );
256 #ifdef WIN32
257     add_bool( "skins2-transparency", VLC_FALSE, NULL, SKINS2_TRANSPARENCY,
258               SKINS2_TRANSPARENCY_LONG, VLC_FALSE );
259 #endif
260     set_description( _("Skinnable Interface") );
261     set_capability( "interface", 30 );
262     set_callbacks( Open, Close );
263     set_program( "s2vlc" );
264 vlc_module_end();