]> git.sesse.net Git - vlc/commitdiff
Allow thread-cancelation in qt4-module, and define cancelation function
authorIlkka Ollakka <ileoo@videolan.org>
Thu, 16 Oct 2008 12:15:33 +0000 (15:15 +0300)
committerIlkka Ollakka <ileoo@videolan.org>
Thu, 16 Oct 2008 12:18:54 +0000 (15:18 +0300)
Cancelation function emits event to main-interface to shut down. Thanks to
courmisch for pointing out this possibility.

Should be final issue on ticket #1365 and this commit should fix it

modules/gui/qt4/main_interface.cpp
modules/gui/qt4/main_interface.hpp
modules/gui/qt4/qt4.cpp
modules/gui/qt4/qt4.hpp

index 943c6dd00b226b234a0d33716a6225abab2b6593..7836abd692411b8200cff830cd5933fd58f57e05 100644 (file)
@@ -186,11 +186,6 @@ MainInterface::MainInterface( intf_thread_t *_p_intf ) : QVLCMW( _p_intf )
     /* END CONNECTS ON IM */
 
 
-    /** OnTimeOut **/
-    /* TODO Remove this function, but so far, there is no choice because there
-       is no intf-should-die variable #1365 */
-    ON_TIMEOUT( updateOnTimer() );
-
     /************
      * Callbacks
      ************/
@@ -876,16 +871,6 @@ void MainInterface::setRate( int rate )
     speedControl->updateControls( rate );
 }
 
-void MainInterface::updateOnTimer()
-{
-    /* No event for dying */
-    if( !vlc_object_alive( p_intf ) )
-    {
-        QApplication::closeAllWindows();
-        QApplication::quit();
-    }
-}
-
 /*****************************************************************************
  * Systray Icon and Systray Menu
  *****************************************************************************/
@@ -1103,6 +1088,11 @@ void MainInterface::customEvent( QEvent *event )
             setWindowFlags(windowFlags() & ~Qt::WindowStaysOnTopHint);
         show(); /* necessary to apply window flags?? */
     }
+    if ( event->type() == MainInterfaceClose_Type )
+    {
+        QApplication::closeAllWindows();
+        QApplication::quit();
+    }
 }
 
 void MainInterface::keyPressEvent( QKeyEvent *e )
index 111979f14dd4f0935f57481be6f99d0317f4b725..8be4405576bc65a00824ca42ed50e820a4ac3596 100644 (file)
@@ -164,7 +164,6 @@ public slots:
 
 private slots:
     void debug();
-    void updateOnTimer();
     void doComponentsUpdate();
     void setStatus( int );
     void setRate( int );
index ac00b62d8fb7031f67353981648341c34c1f60cd..84a493486276696dd2b767488118bd3b00ea127e 100755 (executable)
@@ -315,15 +315,20 @@ static void Run( intf_thread_t *p_intf )
     }
     else
     {
-        int canc = vlc_savecancel ();
         Init( VLC_OBJECT(p_intf) );
-        vlc_restorecancel( canc );
     }
 }
 
 static QMutex windowLock;
 static QWaitCondition windowWait;
 
+static void ThreadCleanup( void *param)
+{
+    intf_thread_t *p_intf = (intf_thread_t *)param;
+    QEvent *event = new QEvent((QEvent::Type)(MainInterfaceClose_Type) );
+    QApplication::postEvent( p_intf->p_sys->p_mi, event );
+}
+
 static void *Init( vlc_object_t *obj )
 {
     intf_thread_t *p_intf = (intf_thread_t *)obj;
@@ -333,6 +338,8 @@ static void *Init( vlc_object_t *obj )
     int argc = 1;
     int canc = vlc_savecancel ();
 
+    msg_Dbg( p_intf, "Setting ThreadCleanup");
+    vlc_cleanup_push( ThreadCleanup, (void*)p_intf );
     Q_INIT_RESOURCE( vlc );
 
 #if !defined(WIN32) && !defined(__APPLE__)
@@ -447,10 +454,12 @@ static void *Init( vlc_object_t *obj )
     p_intf->p_sys->psz_filepath = EMPTY_STR( psz_path ) ? config_GetHomeDir()
                                                         : psz_path;
 
+    vlc_restorecancel (canc);
     /* Launch */
     app->exec();
 
     /* And quit */
+    canc = vlc_savecancel ();
     msg_Dbg( p_intf, "Quitting the Qt4 Interface" );
 
     if (miP)
@@ -490,6 +499,7 @@ static void *Init( vlc_object_t *obj )
     config_PutPsz( p_intf, "qt-filedialog-path", p_intf->p_sys->psz_filepath );
     free( psz_path );
     vlc_restorecancel (canc);
+    vlc_cleanup_pop();
     return NULL;
 }
 
index f9a46636caed4c609cb662f9136fd7e29cc7f85c..7a75028c6a9e1761bca0597ec7f2ef8b91d2b506 100755 (executable)
@@ -48,6 +48,7 @@ class DialogsProvider;
 class VideoWidget;
 class QSettings;
 
+
 #if defined(Q_WS_WIN)
 #include <QApplication>
 
@@ -158,6 +159,7 @@ static const int DialogEvent_Type = QEvent::User + DialogEventType + 1;
 //static const int PLUndockEvent_Type = QEvent::User + DialogEventType + 2;
 //static const int PLDockEvent_Type = QEvent::User + DialogEventType + 3;
 static const int SetVideoOnTopEvent_Type = QEvent::User + DialogEventType + 4;
+static const int MainInterfaceClose_Type  = QEvent::User + 404;
 
 class DialogEvent : public QEvent
 {