]> git.sesse.net Git - vlc/blob - modules/gui/qt4/dialogs/extensions.hpp
Merge branch 'master' into lpcm_encoder
[vlc] / modules / gui / qt4 / dialogs / extensions.hpp
1 /*****************************************************************************
2  * extensions.hpp: Extensions manager for Qt: dialogs manager
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_HPP
25 #define EXTENSIONS_HPP
26
27 #include "qt4.hpp"
28 #include <vlc_extensions.h>
29
30 #include "assert.h"
31
32 #include <QDialog>
33 class QObject;
34 class QGridLayout;
35 class QSignalMapper;
36 class QCloseEvent;
37
38 class ExtensionsDialogProvider;
39 class ExtensionDialog;
40 class WidgetMapper;
41
42 class ExtensionsDialogProvider : public QObject
43 {
44     /** This is the dialog provider for Extensions dialogs
45      * @todo Make this class be a public Singleton<EDP>
46      * @todo Add a setExtManager() function (with vlc_object_hold)
47      **/
48
49     Q_OBJECT
50
51 private:
52     static ExtensionsDialogProvider *instance;
53     intf_thread_t *p_intf;
54     extensions_manager_t *p_extensions_manager;
55
56 private slots:
57     ExtensionDialog* CreateExtDialog( extension_dialog_t *p_dialog );
58     int DestroyExtDialog( extension_dialog_t *p_dialog );
59     ExtensionDialog* UpdateExtDialog( extension_dialog_t *p_dialog );
60
61 public:
62     ExtensionsDialogProvider( intf_thread_t *p_intf,
63                               extensions_manager_t *p_mgr );
64     virtual ~ExtensionsDialogProvider();
65
66     static ExtensionsDialogProvider* getInstance( intf_thread_t *p_intf = NULL,
67                                                   extensions_manager_t *p_mgr = NULL )
68     {
69         if( !instance )
70         {
71             assert( p_intf != NULL && p_mgr != NULL );
72             instance = new ExtensionsDialogProvider( p_intf, p_mgr );
73         }
74         return instance;
75     }
76     static void killInstance()
77     {
78         delete instance;
79         instance = NULL;
80     }
81
82     void ManageDialog( extension_dialog_t *p_dialog );
83
84 signals:
85     void SignalDialog( extension_dialog_t *p_dialog );
86 };
87
88
89 class ExtensionDialog : public QDialog
90 {
91     Q_OBJECT
92 private:
93     intf_thread_t *p_intf;
94     extensions_manager_t *p_extensions_manager;
95     extension_t *p_extension;
96     extension_dialog_t *p_dialog;
97     bool has_lock; ///< Indicates whether Qt thread owns the lock
98     QGridLayout *layout;
99     QSignalMapper *clickMapper;
100     QSignalMapper *inputMapper;
101     QSignalMapper *selectMapper;
102
103     QWidget *CreateWidget( extension_widget_t *p_widget );
104     QWidget *UpdateWidget( extension_widget_t *p_widget );
105     void DestroyWidget( extension_widget_t *p_widget, bool b_cond = true );
106
107 protected:
108     virtual void closeEvent( QCloseEvent* );
109
110 private slots:
111     int TriggerClick( QObject *object );
112     void SyncInput( QObject *object );
113     void SyncSelection( QObject *object );
114     void parentDestroyed();
115
116 signals:
117     void destroyDialog( extension_dialog_t *p_dialog );
118
119 public:
120     ExtensionDialog( intf_thread_t *p_intf,
121                      extensions_manager_t *p_mgr,
122                      extension_dialog_t *p_dialog );
123     virtual ~ExtensionDialog();
124
125     void UpdateWidgets();
126
127     // FIXME: This totally sucks (access to has_lock)
128     friend class ExtensionsDialogProvider;
129 };
130
131 class WidgetMapper : public QObject
132 {
133     Q_OBJECT
134 private:
135     extension_widget_t *p_widget;
136 public:
137     WidgetMapper( extension_widget_t *_p_widget ) :
138             QObject(NULL), p_widget(_p_widget) {}
139     ~WidgetMapper() {}
140     extension_widget_t* getWidget() { return p_widget; }
141 };
142
143 #endif // EXTENSIONS_HPP