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