]> git.sesse.net Git - vlc/blob - modules/gui/skins2/src/skin_main.cpp
string review by Christophe Mutricy aka xtophe
[vlc] / modules / gui / skins2 / src / skin_main.cpp
1 /*****************************************************************************
2  * skin_main.cpp
3  *****************************************************************************
4  * Copyright (C) 2003 VideoLAN
5  * $Id: skin_main.cpp,v 1.4 2004/01/25 17:20:19 kuehne Exp $
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 "generic_window.hpp"
27 #include "dialogs.hpp"
28 #include "os_factory.hpp"
29 #include "os_loop.hpp"
30 #include "window_manager.hpp"
31 #include "var_manager.hpp"
32 #include "vlcproc.hpp"
33 #include "theme.hpp"
34 #include "theme_loader.hpp"
35 #include "../parser/interpreter.hpp"
36 #include "../commands/async_queue.hpp"
37
38
39 //---------------------------------------------------------------------------
40 // Exported interface functions.
41 //---------------------------------------------------------------------------
42 #ifdef WIN32_SKINS
43 extern "C" __declspec( dllexport )
44     int __VLC_SYMBOL( vlc_entry ) ( module_t *p_module );
45 #endif
46
47
48 //---------------------------------------------------------------------------
49 // Local prototypes.
50 //---------------------------------------------------------------------------
51 static int  Open  ( vlc_object_t * );
52 static void Close ( vlc_object_t * );
53 static void Run   ( intf_thread_t * );
54
55
56 //---------------------------------------------------------------------------
57 // Open: initialize interface
58 //---------------------------------------------------------------------------
59 static int Open( vlc_object_t *p_this )
60 {
61     intf_thread_t *p_intf = (intf_thread_t *)p_this;
62
63     // Allocate instance and initialize some members
64     p_intf->p_sys = (intf_sys_t *) malloc( sizeof( intf_sys_t ) );
65     if( p_intf->p_sys == NULL )
66     {
67         msg_Err( p_intf, "out of memory" );
68         return( VLC_ENOMEM );
69     };
70
71     p_intf->pf_run = Run;
72
73     // Suscribe to messages bank
74     p_intf->p_sys->p_sub = msg_Subscribe( p_intf );
75
76     p_intf->p_sys->p_input = NULL;
77     p_intf->p_sys->p_playlist = (playlist_t *)vlc_object_find( p_intf,
78         VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
79     if( p_intf->p_sys->p_playlist == NULL )
80     {
81         msg_Err( p_intf, "No playlist object found" );
82         return VLC_EGENERIC;
83     }
84
85     // Initialize "singleton" objects
86     p_intf->p_sys->p_logger = NULL;
87     p_intf->p_sys->p_queue = NULL;
88     p_intf->p_sys->p_dialogs = NULL;
89     p_intf->p_sys->p_interpreter = NULL;
90     p_intf->p_sys->p_osFactory = NULL;
91     p_intf->p_sys->p_osLoop = NULL;
92     p_intf->p_sys->p_varManager = NULL;
93     p_intf->p_sys->p_vlcProc = NULL;
94
95     // No theme yet
96     p_intf->p_sys->p_theme = NULL;
97
98     // Initialize singletons
99     if( OSFactory::instance( p_intf ) == NULL )
100     {
101         msg_Err( p_intf, "Cannot initialize OSFactory" );
102         return VLC_EGENERIC;
103     }
104     if( AsyncQueue::instance( p_intf ) == NULL )
105     {
106         msg_Err( p_intf, "Cannot initialize AsyncQueue" );
107         return VLC_EGENERIC;
108     }
109     if( Interpreter::instance( p_intf ) == NULL )
110     {
111         msg_Err( p_intf, "Cannot instanciate Interpreter" );
112         return VLC_EGENERIC;
113     }
114     if( VarManager::instance( p_intf ) == NULL )
115     {
116         msg_Err( p_intf, "Cannot instanciate VarManager" );
117         return VLC_EGENERIC;
118     }
119     if( VlcProc::instance( p_intf ) == NULL )
120     {
121         msg_Err( p_intf, "Cannot initialize VLCProc" );
122         return VLC_EGENERIC;
123     }
124     Dialogs::instance( p_intf );
125
126     return( VLC_SUCCESS );
127 }
128
129 //---------------------------------------------------------------------------
130 // Close: destroy interface
131 //---------------------------------------------------------------------------
132 static void Close( vlc_object_t *p_this )
133 {
134     intf_thread_t *p_intf = (intf_thread_t *)p_this;
135
136     // Destroy "singleton" objects
137     VlcProc::destroy( p_intf );
138     OSFactory::instance( p_intf )->destroyOSLoop();
139     OSFactory::destroy( p_intf );
140     Dialogs::destroy( p_intf );
141     Interpreter::destroy( p_intf );
142     AsyncQueue::destroy( p_intf );
143     VarManager::destroy( p_intf );
144
145     if( p_intf->p_sys->p_input )
146     {
147         vlc_object_release( p_intf->p_sys->p_input );
148     }
149
150     if( p_intf->p_sys->p_playlist )
151     {
152         vlc_object_release( p_intf->p_sys->p_playlist );
153     }
154
155    // Unsuscribe to messages bank
156     msg_Unsubscribe( p_intf, p_intf->p_sys->p_sub );
157
158     // Destroy structure
159     free( p_intf->p_sys );
160 }
161
162
163 //---------------------------------------------------------------------------
164 // Run: main loop
165 //---------------------------------------------------------------------------
166 static void Run( intf_thread_t *p_intf )
167 {
168     // Load a theme
169     ThemeLoader *pLoader = new ThemeLoader( p_intf );
170     char *skin_last = config_GetPsz( p_intf, "skin_last2" );
171
172     if( skin_last == NULL || !pLoader->load( skin_last ) )
173     {
174         // Too bad, it failed. Let's try with the default theme
175 #ifdef WIN32_SKINS
176         string default_dir = (string)p_intf->p_libvlc->psz_vlcpath +
177                              "\\skins\\default\\theme.xml";
178         if( !pLoader->load( default_dir ) )
179 #else
180         string user_skin = (string)p_intf->p_vlc->psz_homedir +
181                            "/" + CONFIG_DIR + "/skins/default/theme.xml";
182
183         string default_skin = (string)DATA_PATH + "/skins/default/theme.xml";
184         if( !pLoader->load( user_skin ) && !pLoader->load( default_skin ) )
185 #endif
186         {
187             // Last chance: the user can select a new theme file (blocking call)
188             Dialogs *pDialogs = Dialogs::instance( p_intf );
189             pDialogs->showChangeSkin();
190         }
191     }
192     delete pLoader;
193
194     if( skin_last )
195     {
196         free( skin_last );
197     }
198
199     // Get the instance of OSLoop
200     OSLoop *loop = OSFactory::instance( p_intf )->getOSLoop();
201     loop->run();
202
203     // Delete the theme
204     if( p_intf->p_sys->p_theme )
205     {
206         delete p_intf->p_sys->p_theme;
207         p_intf->p_sys->p_theme = NULL;
208     }
209 }
210
211 //---------------------------------------------------------------------------
212 // Module descriptor
213 //---------------------------------------------------------------------------
214 #define DEFAULT_SKIN        N_("Last skin used")
215 #define DEFAULT_SKIN_LONG   N_("Select the path to the last skin used.")
216
217 vlc_module_begin();
218 // XXX
219     add_string( "skin_last2", "", NULL, DEFAULT_SKIN, DEFAULT_SKIN_LONG,
220                 VLC_TRUE );
221     set_description( _("Skinnable Interface") );
222     set_capability( "interface", 30 );
223     set_callbacks( Open, Close );
224     set_program( "svlc" );
225 vlc_module_end();
226