]> git.sesse.net Git - vlc/blobdiff - modules/gui/qt4/main_interface.cpp
Qt: correctly delete callbacks
[vlc] / modules / gui / qt4 / main_interface.cpp
index 41fea294005025813505cc1a9ea1ecbdadd90109..3589d9129a7e1f3febdee973b244d0fb14a3eee1 100644 (file)
@@ -1,7 +1,7 @@
 /*****************************************************************************
  * main_interface.cpp : Main interface
  ****************************************************************************
- * Copyright (C) 2006-2010 VideoLAN and AUTHORS
+ * Copyright (C) 2006-2011 VideoLAN and AUTHORS
  * $Id$
  *
  * Authors: ClĂ©ment Stenac <zorglub@videolan.org>
@@ -70,6 +70,9 @@ static int IntfShowCB( vlc_object_t *p_this, const char *psz_variable,
                        vlc_value_t old_val, vlc_value_t new_val, void *param );
 static int IntfBossCB( vlc_object_t *p_this, const char *psz_variable,
                        vlc_value_t old_val, vlc_value_t new_val, void *param );
+static int IntfRaiseMainCB( vlc_object_t *p_this, const char *psz_variable,
+                           vlc_value_t old_val, vlc_value_t new_val,
+                           void *param );
 
 MainInterface::MainInterface( intf_thread_t *_p_intf ) : QVLCMW( _p_intf )
 {
@@ -138,11 +141,6 @@ MainInterface::MainInterface( intf_thread_t *_p_intf ) : QVLCMW( _p_intf )
 
     settings->endGroup( );
 
-    /*********************************
-     * Create the Systray Management *
-     *********************************/
-    initSystray();
-
     /**************************
      *  UI and Widgets design
      **************************/
@@ -174,9 +172,15 @@ MainInterface::MainInterface( intf_thread_t *_p_intf ) : QVLCMW( _p_intf )
     taskbar_wmsg = RegisterWindowMessage("TaskbarButtonCreated");
 #endif
 
-    /************************************************************
-     * Connect the input manager to the GUI elements it manages *
-     ************************************************************/
+    /*********************************
+     * Create the Systray Management *
+     *********************************/
+    initSystray();
+
+    /*************************************************************
+     * Connect the input manager to the GUI elements it manages  *
+     * Beware initSystray did some connects on input manager too *
+     *************************************************************/
     /**
      * Connects on nameChanged()
      * Those connects are different because options can impeach them to trigger.
@@ -184,33 +188,12 @@ MainInterface::MainInterface( intf_thread_t *_p_intf ) : QVLCMW( _p_intf )
     /* Main Interface statusbar */
     CONNECT( THEMIM->getIM(), nameChanged( const QString& ),
              this, setName( const QString& ) );
-    /* and systray */
-#ifndef HAVE_MAEMO
-    if( sysTray )
-    {
-        CONNECT( THEMIM->getIM(), nameChanged( const QString& ),
-                 this, updateSystrayTooltipName( const QString& ) );
-    }
-#endif
     /* and title of the Main Interface*/
     if( var_InheritBool( p_intf, "qt-name-in-title" ) )
     {
         CONNECT( THEMIM->getIM(), nameChanged( const QString& ),
                  this, setVLCWindowsTitle( const QString& ) );
     }
-
-    /**
-     * CONNECTS on PLAY_STATUS
-     **/
-    /* Status on the systray */
-#ifndef HAVE_MAEMO
-    if( sysTray )
-    {
-        CONNECT( THEMIM->getIM(), playingStatusChanged( int ),
-                 this, updateSystrayTooltipStatus( int ) );
-    }
-#endif
-
     /* END CONNECTS ON IM */
 
     /* VideoWidget connects for asynchronous calls */
@@ -241,6 +224,7 @@ MainInterface::MainInterface( intf_thread_t *_p_intf ) : QVLCMW( _p_intf )
     CONNECT( this, askToQuit(), THEDP, quit() );
 
     CONNECT( this, askBoss(), this, setBoss() );
+    CONNECT( this, askRaise(), this, setRaise() );
 
     /** END of CONNECTS**/
 
@@ -248,8 +232,9 @@ MainInterface::MainInterface( intf_thread_t *_p_intf ) : QVLCMW( _p_intf )
     /************
      * Callbacks
      ************/
-    var_AddCallback( p_intf->p_libvlc, "intf-show", IntfShowCB, p_intf );
+    var_AddCallback( p_intf->p_libvlc, "intf-toggle-fscontrol", IntfShowCB, p_intf );
     var_AddCallback( p_intf->p_libvlc, "intf-boss", IntfBossCB, p_intf );
+    var_AddCallback( p_intf->p_libvlc, "intf-show", IntfRaiseMainCB, p_intf );
 
     /* Register callback for the intf-popupmenu variable */
     var_AddCallback( p_intf->p_libvlc, "intf-popupmenu", PopupMenuCB, p_intf );
@@ -335,7 +320,8 @@ MainInterface::~MainInterface()
 
     /* Unregister callbacks */
     var_DelCallback( p_intf->p_libvlc, "intf-boss", IntfBossCB, p_intf );
-    var_DelCallback( p_intf->p_libvlc, "intf-show", IntfShowCB, p_intf );
+    var_DelCallback( p_intf->p_libvlc, "intf-show", IntfRaiseMainCB, p_intf );
+    var_DelCallback( p_intf->p_libvlc, "intf-toggle-fscontrol", IntfShowCB, p_intf );
     var_DelCallback( p_intf->p_libvlc, "intf-popupmenu", PopupMenuCB, p_intf );
 
     p_intf->p_sys->p_mi = NULL;
@@ -997,6 +983,13 @@ void MainInterface::createSystray()
 
     CONNECT( sysTray, activated( QSystemTrayIcon::ActivationReason ),
              this, handleSystrayClick( QSystemTrayIcon::ActivationReason ) );
+
+    /* Connects on nameChanged() */
+    CONNECT( THEMIM->getIM(), nameChanged( const QString& ),
+             this, updateSystrayTooltipName( const QString& ) );
+    /* Connect PLAY_STATUS on the systray */
+    CONNECT( THEMIM->getIM(), playingStatusChanged( int ),
+             this, updateSystrayTooltipStatus( int ) );
 }
 
 /**
@@ -1044,9 +1037,11 @@ void MainInterface::toggleUpdateSystrayMenu()
         hide();
 #endif
     }
-    QVLCMenu::updateSystrayMenu( this, p_intf );
+    if( sysTray )
+        QVLCMenu::updateSystrayMenu( this, p_intf );
 }
 
+/* First Item of the systray menu */
 void MainInterface::showUpdateSystrayMenu()
 {
     if( isHidden() )
@@ -1058,12 +1053,14 @@ void MainInterface::showUpdateSystrayMenu()
     QVLCMenu::updateSystrayMenu( this, p_intf );
 }
 
+/* First Item of the systray menu */
 void MainInterface::hideUpdateSystrayMenu()
 {
     hide();
     QVLCMenu::updateSystrayMenu( this, p_intf );
 }
 
+/* Click on systray Icon */
 void MainInterface::handleSystrayClick(
                                     QSystemTrayIcon::ActivationReason reason )
 {
@@ -1308,6 +1305,16 @@ void MainInterface::setBoss()
     }
 }
 
+void MainInterface::emitRaise()
+{
+    emit askRaise();
+}
+void MainInterface::setRaise()
+{
+    activateWindow();
+    raise();
+}
+
 /*****************************************************************************
  * PopupMenuCB: callback triggered by the intf-popupmenu playlist variable.
  *  We don't show the menu directly here because we don't want the
@@ -1330,7 +1337,7 @@ static int PopupMenuCB( vlc_object_t *p_this, const char *psz_variable,
 }
 
 /*****************************************************************************
- * IntfShowCB: callback triggered by the intf-show libvlc variable.
+ * IntfShowCB: callback triggered by the intf-toggle-fscontrol libvlc variable.
  *****************************************************************************/
 static int IntfShowCB( vlc_object_t *p_this, const char *psz_variable,
                        vlc_value_t old_val, vlc_value_t new_val, void *param )
@@ -1345,6 +1352,21 @@ static int IntfShowCB( vlc_object_t *p_this, const char *psz_variable,
      return VLC_SUCCESS;
 }
 
+/*****************************************************************************
+ * IntfRaiseMainCB: callback triggered by the intf-show-main libvlc variable.
+ *****************************************************************************/
+static int IntfRaiseMainCB( vlc_object_t *p_this, const char *psz_variable,
+                       vlc_value_t old_val, vlc_value_t new_val, void *param )
+{
+    VLC_UNUSED( p_this ); VLC_UNUSED( psz_variable ); VLC_UNUSED( old_val );
+    VLC_UNUSED( new_val );
+
+    intf_thread_t *p_intf = (intf_thread_t *)param;
+    p_intf->p_sys->p_mi->emitRaise();
+
+    return VLC_SUCCESS;
+}
+
 /*****************************************************************************
  * IntfBossCB: callback triggered by the intf-boss libvlc variable.
  *****************************************************************************/