1 /*****************************************************************************
2 * qte_main.c : QT Embedded wrapper for gte_main
3 *****************************************************************************
4 * Copyright (C) 2003 VideoLAN
5 * $Id: qte_main.cpp,v 1.4 2003/03/06 10:11:33 jpsaman Exp $
7 * Authors: Jean-Paul Saman <jpsaman@wxs.nl>
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.
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.
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., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
22 *****************************************************************************/
24 /*****************************************************************************
26 *****************************************************************************/
30 #include <stdlib.h> /* atexit() */
33 #include <qapplication.h>
39 typedef struct qte_thread_t
43 QApplication* p_qte_application;
44 QWidget* p_qte_widget;
48 /*****************************************************************************
50 *****************************************************************************/
51 static int Open ( vlc_object_t * );
52 static void Close ( vlc_object_t * );
54 static void QteMain ( qte_thread_t * );
56 /*****************************************************************************
57 * Local variables (mutex-protected).
58 *****************************************************************************/
59 static int i_refcount = 0;
60 static qte_thread_t * p_qte_main = NULL;
62 /*****************************************************************************
64 *****************************************************************************/
66 set_description( _("Qt Embedded helper module") );
67 set_capability( "qte_main", 90 );
68 add_shortcut( "qte" );
69 set_callbacks( Open, Close );
74 /*****************************************************************************
75 * Open: initialize and create window
76 *****************************************************************************/
77 static int Open( vlc_object_t *p_this )
81 /* FIXME: put this in the module (de)initialization ASAP */
82 var_Create( p_this->p_libvlc, "qte", VLC_VAR_MUTEX );
84 var_Get( p_this->p_libvlc, "qte", &lockval );
85 vlc_mutex_lock( (vlc_mutex_t *) lockval.p_address );
90 vlc_mutex_unlock( (vlc_mutex_t *) lockval.p_address );
95 p_qte_main = (qte_thread_t *) vlc_object_create( p_this, sizeof(qte_thread_t) );
97 /* Launch the gtk_main() thread. It will not return until it has
98 * called gdk_threads_enter(), which ensures us thread safety. */
99 if( vlc_thread_create( p_qte_main, "qte_main", QteMain,
100 VLC_THREAD_PRIORITY_LOW, VLC_TRUE ) )
102 vlc_object_destroy( p_qte_main );
104 vlc_mutex_unlock( (vlc_mutex_t *) lockval.p_address );
105 var_Destroy( p_this->p_libvlc, "qte" );
110 vlc_mutex_unlock( (vlc_mutex_t *) lockval.p_address );
115 /*****************************************************************************
116 * Close: destroy interface window
117 *****************************************************************************/
118 static void Close( vlc_object_t *p_this )
122 var_Get( p_this->p_libvlc, "qte", &lockval );
123 vlc_mutex_lock( (vlc_mutex_t *) lockval.p_address );
129 vlc_mutex_unlock( (vlc_mutex_t *) lockval.p_address );
130 var_Destroy( p_this->p_libvlc, "qte" );
133 p_qte_main->p_qte_application->quit();
135 /* Cleanup allocated classes. */
136 delete p_qte_main->p_qte_widget;
137 delete p_qte_main->p_qte_application;
139 vlc_object_destroy( p_qte_main );
142 vlc_mutex_unlock( (vlc_mutex_t *) lockval.p_address );
143 var_Destroy( p_this->p_libvlc, "qte" );
146 /*****************************************************************************
147 * QteMain: Qt Embedded thread
148 *****************************************************************************
149 * this part of the interface is in a separate thread so that we can call
150 * qte_main() from within it without annoying the rest of the program.
151 *****************************************************************************/
152 static void QteMain( qte_thread_t *p_this )
156 QApplication* pApp = new QApplication(argc, NULL);
159 p_this->p_qte_application = pApp;
162 QWidget* pWidget = new QWidget();
165 p_this->p_qte_widget = pWidget;
168 /* signal the creation of the window */
169 p_this->p_qte_application->setMainWidget(p_this->p_qte_widget);
170 p_this->p_qte_widget->show();
172 vlc_thread_ready( p_this );
173 p_this->p_qte_application->exec();