]> git.sesse.net Git - vlc/blob - modules/misc/qte_main.cpp
Remove most stray semi-colons in module descriptions
[vlc] / modules / misc / qte_main.cpp
1 /*****************************************************************************
2  * qte_main.c : QT Embedded wrapper for gte_main
3  *****************************************************************************
4  * Copyright (C) 2003 the VideoLAN team
5  * $Id$
6  *
7  * Authors: Jean-Paul Saman <jpsaman _at_ videolan _dot_ 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 /*****************************************************************************
25  * Preamble
26  *****************************************************************************/
27 extern "C"
28 {
29 #ifdef HAVE_CONFIG_H
30 # include "config.h"
31 #endif
32
33 #include <vlc_common.h>
34 #include <vlc_plugin.h>
35 }
36
37 #include <qapplication.h>
38 #include <qpainter.h>
39
40 extern "C"
41 {
42
43 typedef struct qte_thread_t
44 {
45     VLC_COMMON_MEMBERS
46
47     QApplication*       p_qte_application;
48     QWidget*            p_qte_widget;
49     bool                b_gui_server;
50
51 } qte_thread_t;
52
53 /*****************************************************************************
54  * Local prototypes.
55  *****************************************************************************/
56 static int  Open    ( vlc_object_t * );
57 static void Close   ( vlc_object_t * );
58
59 static void* QteMain( vlc_object_t * );
60
61 /*****************************************************************************
62  * Local variables (mutex-protected).
63  *****************************************************************************/
64 static int            i_refcount = 0;
65 static qte_thread_t * p_qte_main = NULL;
66
67 /*****************************************************************************
68  * Module descriptor
69  *****************************************************************************/
70 #define STANDALONE_TEXT N_("Run as standalone Qt/Embedded GUI Server")
71 #define STANDALONE_LONGTEXT N_("Use this option to run as standalone " \
72     "Qt/Embedded GUI Server. This option is equivalent to the -qws option " \
73     "from normal Qt.")
74
75 vlc_module_begin ()
76     set_description( N_("Qt Embedded GUI helper") )
77     set_capability( "gui-helper", 90 )
78     add_bool( "qte-guiserver", 0, NULL, STANDALONE_TEXT, STANDALONE_LONGTEXT, false )
79     add_shortcut( "qte" )
80     set_callbacks( Open, Close )
81 vlc_module_end ()
82
83 } /* extern "C" */
84
85 static vlc_mutex_t qte_lock = VLC_STATIC_MUTEX;
86
87 /*****************************************************************************
88  * Open: initialize and create window
89  *****************************************************************************/
90 static int Open( vlc_object_t *p_this )
91 {
92     vlc_mutex_lock( &qte_lock );
93
94     if( i_refcount > 0 )
95     {
96         i_refcount++;
97         vlc_mutex_unlock( &qte_lock );
98
99         return VLC_SUCCESS;
100     }
101
102     p_qte_main = (qte_thread_t *) vlc_object_create( p_this, sizeof(qte_thread_t) );
103
104     /* Launch the QApplication::exec() thread. It will not return until the
105      * application is properly initialized, which ensures us thread safety. */
106     if( vlc_thread_create( p_qte_main, "qte_main", QteMain,
107                            VLC_THREAD_PRIORITY_LOW, true ) )
108     {
109         vlc_object_release( p_qte_main );
110         i_refcount--;
111         vlc_mutex_unlock( lock );
112         return VLC_ETHREAD;
113     }
114
115     i_refcount++;
116     vlc_mutex_unlock( &qte_lock );
117
118     vlc_object_attach( p_qte_main, p_this );
119     msg_Dbg( p_this, "qte_main running" );
120
121     return VLC_SUCCESS;
122 }
123
124 /*****************************************************************************
125  * Close: destroy interface window
126  *****************************************************************************/
127 static void Close( vlc_object_t *p_this )
128 {
129     vlc_mutex_lock( &qte_lock );
130
131     i_refcount--;
132
133     if( i_refcount > 0 )
134     {
135         vlc_mutex_unlock( lock );
136         return;
137     }
138     p_qte_main->p_qte_application->quit();
139
140     /* Cleanup allocated classes. */
141     delete p_qte_main->p_qte_widget;
142     delete p_qte_main->p_qte_application;
143
144     msg_Dbg( p_this, "Detaching qte_main" );
145     vlc_object_detach( p_qte_main );
146
147     vlc_object_release( p_qte_main );
148     p_qte_main = NULL;
149
150     vlc_mutex_unlock( &qte_lock );
151 }
152
153 /*****************************************************************************
154  * QteMain: Qt Embedded thread
155  *****************************************************************************
156  * this part of the interface is in a separate thread so that we can call
157  * qte_main() from within it without annoying the rest of the program.
158  *****************************************************************************/
159 static void* QteMain( vlc_object_t* p_vlc_obj )
160 {
161     qte_thread_t *p_this = (qte_thread_t*)p_vlc_obj;
162     int i_argc = 1;
163     int canc = vlc_savecancel ();
164
165     p_this->b_gui_server = false;
166     if( config_GetInt( p_this, "qte-guiserver" ) )
167     {
168         msg_Dbg( p_this, "Running as Qt Embedded standalone GuiServer" );
169         p_this->b_gui_server = true;
170     }
171
172     /* Run as standalone GuiServer or as GuiClient. */
173     QApplication* pApp = new QApplication(i_argc, NULL,
174         (p_this->b_gui_server ? (QApplication::GuiServer):(QApplication::GuiClient)) );
175     if( pApp )
176     {
177         p_this->p_qte_application = pApp;
178     }
179
180     QWidget* pWidget = new QWidget(0, _("video") );
181     if( pWidget )
182     {
183         p_this->p_qte_widget = pWidget;
184     }
185
186     /* signal the creation of the window */
187     p_this->p_qte_application->setMainWidget(p_this->p_qte_widget);
188     p_this->p_qte_widget->show();
189
190     vlc_thread_ready( p_this );
191     p_this->p_qte_application->exec();
192
193     vlc_restorecancel (canc);
194     return NULL;
195 }