]> git.sesse.net Git - vlc/blobdiff - modules/gui/qt4/qt4.cpp
vout_window_t: simplify via anynomous union
[vlc] / modules / gui / qt4 / qt4.cpp
index 1f30b3a7a0c1dec9bb669710967cdd2c72f363c4..92b4672614118bfb42cd7d3b827c482d79ca1cc4 100644 (file)
 #endif
 
 #include <QApplication>
-#include <QLocale>
-#include <QTranslator>
 #include <QDate>
-#include <QMutex>
-#include <QMutexLocker>
-#include <QWaitCondition>
 
 #include "qt4.hpp"
 
@@ -51,7 +46,7 @@
 #include "../../../share/vlc32x32-christmas.xpm"
 #include <vlc_plugin.h>
 
-#ifdef WIN32
+#ifdef WIN32 /* For static builds */
  #include <QtPlugin>
  Q_IMPORT_PLUGIN(qjpeg)
  Q_IMPORT_PLUGIN(qtaccessiblewidgets)
@@ -263,11 +258,7 @@ vlc_module_end ()
 /*****************************************/
 
 /* Ugly, but the Qt4 interface assumes single instance anyway */
-static struct
-{
-    QMutex lock;
-    QWaitCondition ready;
-} iface;
+static vlc_sem_t ready;
 
 /*****************************************************************************
  * Module callbacks
@@ -288,6 +279,7 @@ static int Open( vlc_object_t *p_this )
         return VLC_EGENERIC;
     }
     XCloseDisplay( p_display );
+    putenv( (char *)"XLIB_SKIP_ARGB_VISUALS=1" );
 #endif
 
     /* Allocations of p_sys */
@@ -298,6 +290,7 @@ static int Open( vlc_object_t *p_this )
     p_sys->p_playlist = pl_Hold( p_intf );
 
     /* */
+    vlc_sem_init (&ready, 0);
     if( vlc_clone( &p_sys->thread, Thread, p_intf, VLC_THREAD_PRIORITY_LOW ) )
     {
         pl_Release (p_sys->p_playlist);
@@ -306,13 +299,12 @@ static int Open( vlc_object_t *p_this )
     }
 
     /* */
-    QMutexLocker locker (&iface.lock);
-    vlc_value_t val;
+    vlc_sem_wait (&ready);
+    vlc_sem_destroy (&ready);
 
-    while( p_sys->p_mi == NULL && !p_sys->b_isDialogProvider )
-        iface.ready.wait( &iface.lock );
     if( !p_sys->b_isDialogProvider )
     {
+        vlc_value_t val;
         var_Create (p_this->p_libvlc, "qt4-iface", VLC_VAR_ADDRESS);
         val.p_address = p_this;
         var_Set (p_this->p_libvlc, "qt4-iface", val);
@@ -338,7 +330,9 @@ static void Close( vlc_object_t *p_this )
     intf_thread_t *p_intf = (intf_thread_t *)p_this;
     intf_sys_t *p_sys = p_intf->p_sys;
 
-    var_Destroy (p_this->p_libvlc, "qt4-iface");
+    if( !p_sys->b_isDialogProvider )
+        var_Destroy (p_this->p_libvlc, "qt4-iface");
+
     QVLCApp::triggerQuit();
 
     vlc_join (p_sys->thread, NULL);
@@ -351,7 +345,7 @@ static void *Thread( void *obj )
     intf_thread_t *p_intf = (intf_thread_t *)obj;
     MainInterface *p_mi;
     char dummy[] = "vlc"; /* for WM_CLASS */
-    char *argv[] = { dummy, NULL, };
+    char *argv[4] = { dummy, NULL, };
     int argc = 1;
 
     Q_INIT_RESOURCE( vlc );
@@ -385,9 +379,9 @@ static void *Thread( void *obj )
 
     /* Icon setting */
     if( QDate::currentDate().dayOfYear() >= 352 ) /* One Week before Xmas */
-        app.setWindowIcon( QIcon( QPixmap(vlc_christmas_xpm) ) );
+        app.setWindowIcon( QIcon(vlc_christmas_xpm) );
     else
-        app.setWindowIcon( QIcon( QPixmap(vlc_xpm) ) );
+        app.setWindowIcon( QIcon(vlc_xpm) );
 
     /* Initialize timers and the Dialog Provider */
     DialogsProvider::getInstance( p_intf );
@@ -419,42 +413,13 @@ static void *Thread( void *obj )
         p_mi = NULL;
 
     /* */
-    iface.lock.lock();
     p_intf->p_sys->p_mi = p_mi;
     p_intf->p_sys->b_isDialogProvider = p_mi == NULL;
-    iface.ready.wakeAll();
-    iface.lock.unlock();
+    vlc_sem_post (&ready);
 
     /* Explain to the core how to show a dialog :D */
     p_intf->pf_show_dialog = ShowDialog;
 
-#ifdef ENABLE_NLS
-    // Translation - get locale
-#   if defined (WIN32) || defined (__APPLE__)
-    char* psz_tmp = config_GetPsz( p_intf, "language" );
-    QString lang = qfu( psz_tmp );
-    free( psz_tmp);
-    if (lang == "auto")
-        lang = QLocale::system().name();
-#   else
-    QString lang = QLocale::system().name();
-#   endif
-    // Translations for qt's own dialogs
-    QTranslator qtTranslator( 0 );
-    // Let's find the right path for the translation file
-#if !defined( WIN32 )
-    QString path =  QString( QT4LOCALEDIR );
-#else
-    QString path = QString( QString(config_GetDataDir()) + DIR_SEP +
-                            "locale" + DIR_SEP + "qt4" + DIR_SEP );
-#endif
-    // files depending on locale
-    bool b_loaded = qtTranslator.load( path + "qt_" + lang );
-    if (!b_loaded)
-        msg_Dbg( p_intf, "Error while initializing qt-specific localization" );
-    app.installTranslator( &qtTranslator );
-#endif  //ENABLE_NLS
-
     /* Last settings */
     app.setQuitOnLastWindowClosed( false );
 
@@ -467,7 +432,6 @@ static void *Thread( void *obj )
     if( s_style.compare("") != 0 )
         QApplication::setStyle( s_style );
 
-
     /* Launch */
     app.exec();
 
@@ -478,7 +442,7 @@ static void *Thread( void *obj )
 
     if (p_mi != NULL)
     {
-        QMutexLocker locker (&iface.lock);
+        /* FIXME: are we sure that video window is already destroyed? */
 
         msg_Dbg (p_intf, "destroying the main Qt4 interface");
         p_intf->p_sys->p_mi = NULL;
@@ -507,7 +471,6 @@ static void *Thread( void *obj )
     MainInputManager::killInstance();
 
 
-
     /* Delete the application automatically */
 #ifdef Q_WS_X11
     free( display );
@@ -543,8 +506,6 @@ static int WindowOpen( vlc_object_t *p_obj )
     if( p_wnd->cfg->is_standalone )
         return VLC_EGENERIC;
 
-    QMutexLocker( &iface.lock );
-
     vlc_value_t val;
 
     if( var_Get( p_obj->p_libvlc, "qt4-iface", &val ) )
@@ -567,13 +528,13 @@ static int WindowOpen( vlc_object_t *p_obj )
     unsigned i_height = p_wnd->cfg->height;
 
 #if defined (Q_WS_X11)
-    p_wnd->handle.xid = p_mi->getVideo( &i_x, &i_y, &i_width, &i_height );
-    if( !p_wnd->handle.xid )
+    p_wnd->xid = p_mi->getVideo( &i_x, &i_y, &i_width, &i_height );
+    if( !p_wnd->xid )
         return VLC_EGENERIC;
 
 #elif defined (WIN32)
-    p_wnd->handle.hwnd = p_mi->getVideo( &i_x, &i_y, &i_width, &i_height );
-    if( !p_wnd->handle.hwnd )
+    p_wnd->hwnd = p_mi->getVideo( &i_x, &i_y, &i_width, &i_height );
+    if( !p_wnd->hwnd )
         return VLC_EGENERIC;
 #endif
 
@@ -585,8 +546,6 @@ static int WindowOpen( vlc_object_t *p_obj )
 static int WindowControl( vout_window_t *p_wnd, int i_query, va_list args )
 {
     MainInterface *p_mi = (MainInterface *)p_wnd->sys;
-    QMutexLocker locker(&iface.lock);
-
     return p_mi->controlVideo( i_query, args );
 }
 
@@ -595,8 +554,7 @@ static void WindowClose( vlc_object_t *p_obj )
     vout_window_t *p_wnd = (vout_window_t*)p_obj;
     MainInterface *p_mi = (MainInterface *)p_wnd->sys;
 
-    QMutexLocker locker( &iface.lock );
-
     msg_Dbg( p_obj, "releasing video..." );
     p_mi->releaseVideo();
 }
+