Main Page | Modules | Class Hierarchy | Class List | Directories | File List | Class Members | File Members | Related Pages

qte_main.cpp

00001 /*****************************************************************************
00002  * qte_main.c : QT Embedded wrapper for gte_main
00003  *****************************************************************************
00004  * Copyright (C) 2003 the VideoLAN team
00005  * $Id: qte_main.cpp 11664 2005-07-09 06:17:09Z courmisch $
00006  *
00007  * Authors: Jean-Paul Saman <[email protected]>
00008  *
00009  * This program is free software; you can redistribute it and/or modify
00010  * it under the terms of the GNU General Public License as published by
00011  * the Free Software Foundation; either version 2 of the License, or
00012  * (at your option) any later version.
00013  *
00014  * This program is distributed in the hope that it will be useful,
00015  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00016  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017  * GNU General Public License for more details.
00018  *
00019  * You should have received a copy of the GNU General Public License
00020  * along with this program; if not, write to the Free Software
00021  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
00022  *****************************************************************************/
00023 
00024 /*****************************************************************************
00025  * Preamble
00026  *****************************************************************************/
00027 extern "C"
00028 {
00029 #include <vlc/vlc.h>
00030 #include <stdlib.h>                                              /* atexit() */
00031 }
00032 
00033 #include <qapplication.h>
00034 #include <qpainter.h>
00035 
00036 extern "C"
00037 {
00038 
00039 typedef struct qte_thread_t
00040 {
00041     VLC_COMMON_MEMBERS
00042 
00043     QApplication*       p_qte_application;
00044     QWidget*            p_qte_widget;
00045     bool                b_gui_server;
00046 
00047 } qte_thread_t;
00048 
00049 /*****************************************************************************
00050  * Local prototypes.
00051  *****************************************************************************/
00052 static int  Open    ( vlc_object_t * );
00053 static void Close   ( vlc_object_t * );
00054 
00055 static void QteMain ( qte_thread_t * );
00056 
00057 /*****************************************************************************
00058  * Local variables (mutex-protected).
00059  *****************************************************************************/
00060 static int            i_refcount = 0;
00061 static qte_thread_t * p_qte_main = NULL;
00062 
00063 /*****************************************************************************
00064  * Module descriptor
00065  *****************************************************************************/
00066 #define STANDALONE_TEXT N_("Run as standalone Qt/Embedded GUI Server")
00067 #define STANDALONE_LONGTEXT N_("Use this option to run as standalone " \
00068     "Qt/Embedded GUI Server. This option is equivalent to the -qws option " \
00069     "from normal Qt.")
00070 
00071 vlc_module_begin();
00072     set_description( _("Qt Embedded GUI helper") );
00073     set_capability( "gui-helper", 90 );
00074     add_bool( "qte-guiserver", 0, NULL, STANDALONE_TEXT, STANDALONE_LONGTEXT, VLC_FALSE );
00075     add_shortcut( "qte" );
00076     set_callbacks( Open, Close );
00077 vlc_module_end();
00078 
00079 } /* extern "C" */
00080 
00081 /*****************************************************************************
00082  * Open: initialize and create window
00083  *****************************************************************************/
00084 static int Open( vlc_object_t *p_this )
00085 {
00086     vlc_value_t lockval;
00087 
00088     /* FIXME: put this in the module (de)initialization ASAP */
00089     var_Create( p_this->p_libvlc, "qte", VLC_VAR_MUTEX );
00090 
00091     var_Get( p_this->p_libvlc, "qte", &lockval );
00092     vlc_mutex_lock( (vlc_mutex_t *) lockval.p_address );
00093 
00094     if( i_refcount > 0 )
00095     {
00096         i_refcount++;
00097         vlc_mutex_unlock( (vlc_mutex_t *) lockval.p_address );
00098 
00099         return VLC_SUCCESS;
00100     }
00101 
00102     p_qte_main = (qte_thread_t *) vlc_object_create( p_this, sizeof(qte_thread_t) );
00103 
00104     /* Launch the QApplication::exec() thread. It will not return until the
00105      * application is properly initialized, which ensures us thread safety. */
00106     if( vlc_thread_create( p_qte_main, "qte_main", QteMain,
00107                            VLC_THREAD_PRIORITY_LOW, VLC_TRUE ) )
00108     {
00109         vlc_object_destroy( p_qte_main );
00110         i_refcount--;
00111         vlc_mutex_unlock( (vlc_mutex_t *) lockval.p_address );
00112         var_Destroy( p_this->p_libvlc, "qte" );
00113         return VLC_ETHREAD;
00114     }
00115 
00116     i_refcount++;
00117     vlc_mutex_unlock( (vlc_mutex_t *) lockval.p_address );
00118 
00119     vlc_object_attach( p_qte_main, p_this );
00120     msg_Dbg( p_this, "qte_main running" );
00121 
00122     return VLC_SUCCESS;
00123 }
00124 
00125 /*****************************************************************************
00126  * Close: destroy interface window
00127  *****************************************************************************/
00128 static void Close( vlc_object_t *p_this )
00129 {
00130     vlc_value_t lockval;
00131 
00132     var_Get( p_this->p_libvlc, "qte", &lockval );
00133     vlc_mutex_lock( (vlc_mutex_t *) lockval.p_address );
00134 
00135     i_refcount--;
00136 
00137     if( i_refcount > 0 )
00138     {
00139         vlc_mutex_unlock( (vlc_mutex_t *) lockval.p_address );
00140         var_Destroy( p_this->p_libvlc, "qte" );
00141         return;
00142     }
00143     p_qte_main->p_qte_application->quit();
00144 
00145     /* Cleanup allocated classes. */
00146     delete p_qte_main->p_qte_widget;
00147     delete p_qte_main->p_qte_application;
00148 
00149     msg_Dbg( p_this, "Detaching qte_main" );
00150     vlc_object_detach( p_qte_main );
00151 
00152     vlc_object_destroy( p_qte_main );
00153     p_qte_main = NULL;
00154 
00155     vlc_mutex_unlock( (vlc_mutex_t *) lockval.p_address );
00156     var_Destroy( p_this->p_libvlc, "qte" );
00157 }
00158 
00159 /*****************************************************************************
00160  * QteMain: Qt Embedded thread
00161  *****************************************************************************
00162  * this part of the interface is in a separate thread so that we can call
00163  * qte_main() from within it without annoying the rest of the program.
00164  *****************************************************************************/
00165 static void QteMain( qte_thread_t *p_this )
00166 {
00167     int i_argc = 1;
00168 
00169     p_this->b_gui_server = VLC_FALSE;
00170     if( config_GetInt( p_this, "qte-guiserver" ) )
00171     {
00172         msg_Dbg( p_this, "Running as Qt Embedded standalone GuiServer" );
00173         p_this->b_gui_server = VLC_TRUE;
00174     }
00175 
00176     /* Run as standalone GuiServer or as GuiClient. */
00177     QApplication* pApp = new QApplication(i_argc, NULL,
00178         (p_this->b_gui_server ? (QApplication::GuiServer):(QApplication::GuiClient)) );
00179     if(pApp)
00180     {
00181         p_this->p_qte_application = pApp;
00182     }
00183 
00184     QWidget* pWidget = new QWidget(0, _("video") );
00185     if(pWidget)
00186     {
00187         p_this->p_qte_widget = pWidget;
00188     }
00189 
00190     /* signal the creation of the window */
00191     p_this->p_qte_application->setMainWidget(p_this->p_qte_widget);
00192     p_this->p_qte_widget->show();
00193 
00194     vlc_thread_ready( p_this );
00195     p_this->p_qte_application->exec();
00196 }
00197 

Generated on Tue Dec 20 10:14:48 2005 for vlc-0.8.4a by  doxygen 1.4.2