00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 extern "C"
00028 {
00029 #include <vlc/vlc.h>
00030 #include <stdlib.h>
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
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
00059
00060 static int i_refcount = 0;
00061 static qte_thread_t * p_qte_main = NULL;
00062
00063
00064
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 }
00080
00081
00082
00083
00084 static int Open( vlc_object_t *p_this )
00085 {
00086 vlc_value_t lockval;
00087
00088
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
00105
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
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
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
00161
00162
00163
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
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
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