skin_main.cpp 7.71 KB
Newer Older
1
2
3
4
/*****************************************************************************
 * skin_main.cpp
 *****************************************************************************
 * Copyright (C) 2003 VideoLAN
5
 * $Id$
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
 *
 * Authors: Cyril Deguet     <asmax@via.ecp.fr>
 *          Olivier Teulire <ipkiss@via.ecp.fr>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
 *****************************************************************************/

#include <stdlib.h>
#include "dialogs.hpp"
#include "os_factory.hpp"
#include "os_loop.hpp"
#include "var_manager.hpp"
#include "vlcproc.hpp"
#include "theme_loader.hpp"
32
#include "theme.hpp"
Cyril Deguet's avatar
Cyril Deguet committed
33
#include "../parser/interpreter.hpp"
34
#include "../commands/async_queue.hpp"
35
#include "../commands/cmd_quit.hpp"
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87


//---------------------------------------------------------------------------
// Exported interface functions.
//---------------------------------------------------------------------------
#ifdef WIN32_SKINS
extern "C" __declspec( dllexport )
    int __VLC_SYMBOL( vlc_entry ) ( module_t *p_module );
#endif


//---------------------------------------------------------------------------
// Local prototypes.
//---------------------------------------------------------------------------
static int  Open  ( vlc_object_t * );
static void Close ( vlc_object_t * );
static void Run   ( intf_thread_t * );


//---------------------------------------------------------------------------
// Open: initialize interface
//---------------------------------------------------------------------------
static int Open( vlc_object_t *p_this )
{
    intf_thread_t *p_intf = (intf_thread_t *)p_this;

    // Allocate instance and initialize some members
    p_intf->p_sys = (intf_sys_t *) malloc( sizeof( intf_sys_t ) );
    if( p_intf->p_sys == NULL )
    {
        msg_Err( p_intf, "out of memory" );
        return( VLC_ENOMEM );
    };

    p_intf->pf_run = Run;

    // Suscribe to messages bank
    p_intf->p_sys->p_sub = msg_Subscribe( p_intf );

    p_intf->p_sys->p_input = NULL;
    p_intf->p_sys->p_playlist = (playlist_t *)vlc_object_find( p_intf,
        VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
    if( p_intf->p_sys->p_playlist == NULL )
    {
        msg_Err( p_intf, "No playlist object found" );
        return VLC_EGENERIC;
    }

    // Initialize "singleton" objects
    p_intf->p_sys->p_logger = NULL;
    p_intf->p_sys->p_queue = NULL;
    p_intf->p_sys->p_dialogs = NULL;
Cyril Deguet's avatar
Cyril Deguet committed
88
    p_intf->p_sys->p_interpreter = NULL;
89
90
91
92
93
94
95
96
97
    p_intf->p_sys->p_osFactory = NULL;
    p_intf->p_sys->p_osLoop = NULL;
    p_intf->p_sys->p_varManager = NULL;
    p_intf->p_sys->p_vlcProc = NULL;

    // No theme yet
    p_intf->p_sys->p_theme = NULL;

    // Initialize singletons
98
99
100
101
102
    if( OSFactory::instance( p_intf ) == NULL )
    {
        msg_Err( p_intf, "Cannot initialize OSFactory" );
        return VLC_EGENERIC;
    }
103
104
105
106
107
    if( AsyncQueue::instance( p_intf ) == NULL )
    {
        msg_Err( p_intf, "Cannot initialize AsyncQueue" );
        return VLC_EGENERIC;
    }
Cyril Deguet's avatar
Cyril Deguet committed
108
109
110
111
112
    if( Interpreter::instance( p_intf ) == NULL )
    {
        msg_Err( p_intf, "Cannot instanciate Interpreter" );
        return VLC_EGENERIC;
    }
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
    if( VarManager::instance( p_intf ) == NULL )
    {
        msg_Err( p_intf, "Cannot instanciate VarManager" );
        return VLC_EGENERIC;
    }
    if( VlcProc::instance( p_intf ) == NULL )
    {
        msg_Err( p_intf, "Cannot initialize VLCProc" );
        return VLC_EGENERIC;
    }
    Dialogs::instance( p_intf );

    return( VLC_SUCCESS );
}

//---------------------------------------------------------------------------
// Close: destroy interface
//---------------------------------------------------------------------------
static void Close( vlc_object_t *p_this )
{
    intf_thread_t *p_intf = (intf_thread_t *)p_this;

    // Destroy "singleton" objects
    OSFactory::instance( p_intf )->destroyOSLoop();
    Dialogs::destroy( p_intf );
Cyril Deguet's avatar
Cyril Deguet committed
138
    Interpreter::destroy( p_intf );
139
140
    AsyncQueue::destroy( p_intf );
    VarManager::destroy( p_intf );
141
    VlcProc::destroy( p_intf );
142
    OSFactory::destroy( p_intf );
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163

    if( p_intf->p_sys->p_playlist )
    {
        vlc_object_release( p_intf->p_sys->p_playlist );
    }

   // Unsuscribe to messages bank
    msg_Unsubscribe( p_intf, p_intf->p_sys->p_sub );

    // Destroy structure
    free( p_intf->p_sys );
}


//---------------------------------------------------------------------------
// Run: main loop
//---------------------------------------------------------------------------
static void Run( intf_thread_t *p_intf )
{
    // Load a theme
    ThemeLoader *pLoader = new ThemeLoader( p_intf );
gbazin's avatar
   
gbazin committed
164
    char *skin_last = config_GetPsz( p_intf, "skins2-last" );
165
166
167
168
169
170

    if( skin_last == NULL || !pLoader->load( skin_last ) )
    {
        // Too bad, it failed. Let's try with the default theme
#ifdef WIN32_SKINS
        string default_dir = (string)p_intf->p_libvlc->psz_vlcpath +
gbazin's avatar
   
gbazin committed
171
                             "\\skins2\\default\\theme.xml";
172
173
174
        if( !pLoader->load( default_dir ) )
#else
        string user_skin = (string)p_intf->p_vlc->psz_homedir +
gbazin's avatar
   
gbazin committed
175
                           "/" + CONFIG_DIR + "/skins2/default/theme.xml";
176

gbazin's avatar
   
gbazin committed
177
        string default_skin = (string)DATA_PATH + "/skins2/default/theme.xml";
178
179
180
181
182
        if( !pLoader->load( user_skin ) && !pLoader->load( default_skin ) )
#endif
        {
            // Last chance: the user can select a new theme file (blocking call)
            Dialogs *pDialogs = Dialogs::instance( p_intf );
183
184
185
186
187
188
189
190
191
192
193
194
            if( pDialogs )
            {
                pDialogs->showChangeSkin();
            }
            else
            {
                // No dialogs provider, just quit...
                CmdQuit *pCmd = new CmdQuit( p_intf );
                AsyncQueue *pQueue = AsyncQueue::instance( p_intf );
                pQueue->push( CmdGenericPtr( pCmd ) );
                msg_Err( p_intf, "Cannot show the \"open skin\" dialog: exiting...");
            }
195
196
197
198
199
200
201
202
203
204
205
        }
    }
    delete pLoader;

    if( skin_last )
    {
        free( skin_last );
    }

    // Get the instance of OSLoop
    OSLoop *loop = OSFactory::instance( p_intf )->getOSLoop();
206
207

    // Enter the main event loop
208
209
    loop->run();

210
    // Delete the theme and save the configuration of the windows
211
212
    if( p_intf->p_sys->p_theme )
    {
213
        p_intf->p_sys->p_theme->saveConfig();
214
215
216
217
218
219
220
221
222
        delete p_intf->p_sys->p_theme;
        p_intf->p_sys->p_theme = NULL;
    }
}

//---------------------------------------------------------------------------
// Module descriptor
//---------------------------------------------------------------------------
#define DEFAULT_SKIN        N_("Last skin used")
223
#define DEFAULT_SKIN_LONG   N_("Select the path to the last skin used.")
224
225
#define SKIN_CONFIG         N_("Config of last used skin")
#define SKIN_CONFIG_LONG    N_("Config of last used skin.")
226
227

vlc_module_begin();
gbazin's avatar
   
gbazin committed
228
    add_string( "skins2-last", "", NULL, DEFAULT_SKIN, DEFAULT_SKIN_LONG,
229
                VLC_TRUE );
gbazin's avatar
   
gbazin committed
230
    add_string( "skins2-config", "", NULL, SKIN_CONFIG, SKIN_CONFIG_LONG,
231
232
233
234
                VLC_TRUE );
    set_description( _("Skinnable Interface") );
    set_capability( "interface", 30 );
    set_callbacks( Open, Close );
gbazin's avatar
   
gbazin committed
235
    set_program( "s2vlc" );
236
vlc_module_end();