X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=modules%2Fmisc%2Fqte_main.cpp;h=61f4c92799d342a0e699928228b117ec2f5165d1;hb=818a663ea9987aad38d748b7010c9f0d0de863b5;hp=0e3796e64e2c2c7b4c71fdf9c5490a79ea8424b9;hpb=5fec93e17a9a45fb7c20dec7be0ca59775abbe39;p=vlc diff --git a/modules/misc/qte_main.cpp b/modules/misc/qte_main.cpp index 0e3796e64e..61f4c92799 100644 --- a/modules/misc/qte_main.cpp +++ b/modules/misc/qte_main.cpp @@ -1,10 +1,10 @@ /***************************************************************************** * qte_main.c : QT Embedded wrapper for gte_main ***************************************************************************** - * Copyright (C) 2003 VideoLAN - * $Id: qte_main.cpp,v 1.1 2003/01/19 22:16:13 jpsaman Exp $ + * Copyright (C) 2003 the VideoLAN team + * $Id$ * - * Authors: Jean-Paul Saman + * Authors: Jean-Paul Saman * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -18,7 +18,7 @@ * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA. + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA. *****************************************************************************/ /***************************************************************************** @@ -26,20 +26,26 @@ *****************************************************************************/ extern "C" { +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + #include -#include /* atexit() */ } #include +#include extern "C" { typedef struct qte_thread_t { - VLC_COMMON_MEMBERS + VLC_COMMON_MEMBERS QApplication* p_qte_application; + QWidget* p_qte_widget; + bool b_gui_server; } qte_thread_t; @@ -60,9 +66,15 @@ static qte_thread_t * p_qte_main = NULL; /***************************************************************************** * Module descriptor *****************************************************************************/ +#define STANDALONE_TEXT N_("Run as standalone Qt/Embedded GUI Server") +#define STANDALONE_LONGTEXT N_("Use this option to run as standalone " \ + "Qt/Embedded GUI Server. This option is equivalent to the -qws option " \ + "from normal Qt.") + vlc_module_begin(); - set_description( _("Qt Embedded helper module") ); - set_capability( "qte_main", 90 ); + set_description( _("Qt Embedded GUI helper") ); + set_capability( "gui-helper", 90 ); + add_bool( "qte-guiserver", 0, NULL, STANDALONE_TEXT, STANDALONE_LONGTEXT, VLC_FALSE ); add_shortcut( "qte" ); set_callbacks( Open, Close ); vlc_module_end(); @@ -74,38 +86,36 @@ vlc_module_end(); *****************************************************************************/ static int Open( vlc_object_t *p_this ) { - vlc_value_t lockval; + vlc_mutex_t *lock; - /* FIXME: put this in the module (de)initialization ASAP */ - var_Create( p_this->p_libvlc, "qte", VLC_VAR_MUTEX ); - - var_Get( p_this->p_libvlc, "qte", &lockval ); - vlc_mutex_lock( (vlc_mutex_t *) lockval.p_address ); + lock = var_AcquireMutex( "qte" ); if( i_refcount > 0 ) { i_refcount++; - vlc_mutex_unlock( (vlc_mutex_t *) lockval.p_address ); + vlc_mutex_unlock( lock ); return VLC_SUCCESS; } p_qte_main = (qte_thread_t *) vlc_object_create( p_this, sizeof(qte_thread_t) ); - /* Launch the gtk_main() thread. It will not return until it has - * called gdk_threads_enter(), which ensures us thread safety. */ + /* Launch the QApplication::exec() thread. It will not return until the + * application is properly initialized, which ensures us thread safety. */ if( vlc_thread_create( p_qte_main, "qte_main", QteMain, VLC_THREAD_PRIORITY_LOW, VLC_TRUE ) ) { - vlc_object_destroy( p_qte_main ); + vlc_object_release( p_qte_main ); i_refcount--; - vlc_mutex_unlock( (vlc_mutex_t *) lockval.p_address ); - var_Destroy( p_this->p_libvlc, "qte" ); + vlc_mutex_unlock( lock ); return VLC_ETHREAD; } i_refcount++; - vlc_mutex_unlock( (vlc_mutex_t *) lockval.p_address ); + vlc_mutex_unlock( lock ); + + vlc_object_attach( p_qte_main, p_this ); + msg_Dbg( p_this, "qte_main running" ); return VLC_SUCCESS; } @@ -115,28 +125,30 @@ static int Open( vlc_object_t *p_this ) *****************************************************************************/ static void Close( vlc_object_t *p_this ) { - vlc_value_t lockval; + vlc_mutex_t *lock; - var_Get( p_this->p_libvlc, "qte", &lockval ); - vlc_mutex_lock( (vlc_mutex_t *) lockval.p_address ); + lock = var_AcquireMutex( "qte" ); i_refcount--; if( i_refcount > 0 ) { - vlc_mutex_unlock( (vlc_mutex_t *) lockval.p_address ); - var_Destroy( p_this->p_libvlc, "qte" ); + vlc_mutex_unlock( lock ); return; } - p_qte_main->p_qte_application->quit(); - vlc_thread_join( p_qte_main ); - vlc_object_destroy( p_qte_main ); + /* Cleanup allocated classes. */ + delete p_qte_main->p_qte_widget; + delete p_qte_main->p_qte_application; + + msg_Dbg( p_this, "Detaching qte_main" ); + vlc_object_detach( p_qte_main ); + + vlc_object_release( p_qte_main ); p_qte_main = NULL; - vlc_mutex_unlock( (vlc_mutex_t *) lockval.p_address ); - var_Destroy( p_this->p_libvlc, "qte" ); + vlc_mutex_unlock( lock ); } /***************************************************************************** @@ -147,21 +159,33 @@ static void Close( vlc_object_t *p_this ) *****************************************************************************/ static void QteMain( qte_thread_t *p_this ) { - int argc = 0; + int i_argc = 1; + + p_this->b_gui_server = VLC_FALSE; + if( config_GetInt( p_this, "qte-guiserver" ) ) + { + msg_Dbg( p_this, "Running as Qt Embedded standalone GuiServer" ); + p_this->b_gui_server = VLC_TRUE; + } - msg_Dbg( p_this, "qte_main: enter" ); - QApplication* pApp = new QApplication(argc, NULL); - if(pApp) + /* Run as standalone GuiServer or as GuiClient. */ + QApplication* pApp = new QApplication(i_argc, NULL, + (p_this->b_gui_server ? (QApplication::GuiServer):(QApplication::GuiClient)) ); + if( pApp ) { p_this->p_qte_application = pApp; } - msg_Dbg( p_this, "qte_main: qte application created" ); + + QWidget* pWidget = new QWidget(0, _("video") ); + if( pWidget ) + { + p_this->p_qte_widget = pWidget; + } /* signal the creation of the window */ - vlc_thread_ready( p_this ); - msg_Dbg( p_this, "qte_main: qte application thread ready" ); + p_this->p_qte_application->setMainWidget(p_this->p_qte_widget); + p_this->p_qte_widget->show(); + vlc_thread_ready( p_this ); p_this->p_qte_application->exec(); - msg_Dbg( p_this, "qte_main: leaving" ); } -