]> git.sesse.net Git - vlc/blob - modules/gui/qt4/extensions_manager.hpp
7659357260921d1db78c11a99d126c1c926710d1
[vlc] / modules / gui / qt4 / extensions_manager.hpp
1 /*****************************************************************************
2  * extensions_manager.hpp: Extensions manager for Qt
3  ****************************************************************************
4  * Copyright (C) 2009-2010 VideoLAN and authors
5  * $Id$
6  *
7  * Authors: Jean-Philippe AndrĂ© < jpeg # videolan.org >
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22  *****************************************************************************/
23
24 #ifndef EXTENSIONS_MANAGER_HPP
25 #define EXTENSIONS_MANAGER_HPP
26
27 #ifdef HAVE_CONFIG_H
28 # include "config.h"
29 #endif
30
31 #include <vlc_extensions.h>
32
33 #include "qt4.hpp"
34
35 #include <QObject>
36 #include <QMenu>
37 #include <QSignalMapper>
38
39 class ExtensionsDialogProvider;
40
41 class ExtensionsManager : public QObject
42 {
43     Q_OBJECT
44 public:
45     static ExtensionsManager *getInstance( intf_thread_t *_p_intf,
46                                            QObject *_parent = 0 )
47     {
48         if( !instance )
49             instance = new ExtensionsManager( _p_intf, _parent );
50         return instance;
51     }
52     static void killInstance()
53     {
54         delete instance;
55         instance = NULL;
56     }
57
58     ExtensionsManager( intf_thread_t *p_intf, QObject *parent );
59     virtual ~ExtensionsManager();
60
61     inline bool isLoaded() { return p_extensions_manager != NULL; }
62     inline bool cannotLoad() { return b_unloading || b_failed; }
63     inline bool isUnloading() { return b_unloading; }
64     void menu( QMenu *current );
65
66     /** Get the extensions_manager_t if it is loaded and hold the object */
67     extensions_manager_t* getManager()
68     {
69         if( !p_extensions_manager ) return NULL;
70         vlc_object_hold( p_extensions_manager );
71         return p_extensions_manager;
72     }
73
74 public slots:
75     bool loadExtensions();
76     void unloadExtensions();
77     void reloadExtensions();
78
79 private slots:
80     void triggerMenu( int id );
81     void inputChanged( input_thread_t *p_input );
82
83 private:
84     static ExtensionsManager* instance;
85     intf_thread_t *p_intf;
86     extensions_manager_t *p_extensions_manager;
87     ExtensionsDialogProvider *p_edp;
88
89     QSignalMapper *menuMapper;
90     bool b_unloading;  ///< Work around threads + emit issues, see isUnloading
91     bool b_failed; ///< Flag set to true if we could not load the module
92
93 signals:
94     void extensionsUpdated();
95 };
96
97 #endif // EXTENSIONS_MANAGER_HPP