qt4 - Systray Menu - Add hide/show handling, open dialog, help menu, and some click...
authorJean-Baptiste Kempf <jb@videolan.org>
Wed, 2 May 2007 22:57:51 +0000 (22:57 +0000)
committerJean-Baptiste Kempf <jb@videolan.org>
Wed, 2 May 2007 22:57:51 +0000 (22:57 +0000)
modules/gui/qt4/main_interface.cpp
modules/gui/qt4/main_interface.hpp
modules/gui/qt4/menus.cpp
modules/gui/qt4/menus.hpp

index 2a3694d..acf626c 100644 (file)
@@ -129,11 +129,12 @@ MainInterface::MainInterface( intf_thread_t *_p_intf ) : QVLCMW( _p_intf )
              slider, setPosition( float,int, int ) );
     CONNECT( THEMIM->getIM(), positionUpdated( float, int, int ),
              this, setDisplay( float, int, int ) );
-    CONNECT( THEMIM->getIM(), nameChanged( QString ), this,setName( QString ) );
+    CONNECT( THEMIM->getIM(), nameChanged( QString ), this,
+                                                        setName( QString ) );
     CONNECT( THEMIM->getIM(), statusChanged( int ), this, setStatus( int ) );
     CONNECT( THEMIM->getIM(), statusChanged( int ), this,
              updateSystrayMenu( int ) );
-    CONNECT( THEMIM->getIM(), navigationChanged( int ), 
+    CONNECT( THEMIM->getIM(), navigationChanged( int ),
              this, setNavigation(int) );
     CONNECT( slider, sliderDragged( float ),
              THEMIM->getIM(), sliderUpdate( float ) );
@@ -273,10 +274,14 @@ void MainInterface::handleMainUi( QSettings *settings )
 
 void MainInterface::createSystrayMenu()
 {
-    sysTray = new QSystemTrayIcon( QIcon( QPixmap( ":/vlc128.png" ) ) );
+    QIcon iconVLC =  QIcon( QPixmap( ":/vlc128.png" ) );
+    sysTray = new QSystemTrayIcon( iconVLC );
     systrayMenu = new QMenu( qtr( "VLC media player" ), this );
-    QVLCMenu::updateSystrayMenu( this, p_intf );
+    systrayMenu->setIcon( iconVLC );
+    QVLCMenu::updateSystrayMenu( this, p_intf, true );
     sysTray->show();
+    CONNECT( sysTray, activated(  QSystemTrayIcon::ActivationReason ),
+            this, handleSystrayClick( QSystemTrayIcon::ActivationReason ) );
 }
 
 void MainInterface::updateSystrayMenu( int status )
@@ -284,6 +289,20 @@ void MainInterface::updateSystrayMenu( int status )
     QVLCMenu::updateSystrayMenu( this, p_intf ) ;
 }
 
+void MainInterface::handleSystrayClick( QSystemTrayIcon::ActivationReason reason )
+{
+    switch( reason )
+    {
+        case QSystemTrayIcon::Trigger:
+            this->show(); break;
+        case QSystemTrayIcon::MiddleClick:
+            sysTray->showMessage( qtr( "VLC media player" ),
+                    qtr( "Control menu for the player" ),
+                    QSystemTrayIcon::Information, 4000 );
+            break;
+    }
+}
+
 /**********************************************************************
  * Handling of the components
  **********************************************************************/
index 9ef47af..9af6e12 100644 (file)
@@ -131,6 +131,7 @@ private slots:
     void advanced();
     void updateVolume( int sliderVolume );
     void updateSystrayMenu( int );
+    void handleSystrayClick(  QSystemTrayIcon::ActivationReason );
 };
 
 
index e519e22..cc248e8 100644 (file)
@@ -591,8 +591,8 @@ void QVLCMenu::PopupMenu( intf_thread_t *p_intf, bool show )
  * Systray Menu                                                         *
  ************************************************************************/
 
-void QVLCMenu::updateSystrayMenu( MainInterface *mi, intf_thread_t *p_intf
-                                  )
+void QVLCMenu::updateSystrayMenu( MainInterface *mi, intf_thread_t *p_intf,
+                                    bool b_force_visible )
 {
     POPUP_BOILERPLATE;
     QMenu *sysMenu = mi->getSysTrayMenu();
@@ -600,7 +600,15 @@ void QVLCMenu::updateSystrayMenu( MainInterface *mi, intf_thread_t *p_intf
     POPUP_PLAY_ENTRIES( sysMenu );
     sysMenu->addSeparator();
 
-    /* FIXME DP_SADD( menu, qtr("&Hide/show") , "", "", quit(), "" );*/
+    if( mi->isVisible() || b_force_visible )
+    {
+        sysMenu->addAction( qtr("Hide Interface"), mi, SLOT( hide() ) );
+    }
+    else
+    {
+        sysMenu->addAction( qtr("Show Interface"), mi, SLOT( show() ) );
+    }
+    DP_SADD( sysMenu, qtr("&Open" ), "", "", openFileDialog(), "" );
     DP_SADD( sysMenu, qtr("&Quit") , "", "", quit(), "" );
 
     mi->getSysTray()->setContextMenu( sysMenu );
index 2561b14..666028b 100644 (file)
@@ -84,7 +84,8 @@ public:
     static void PopupMenu( intf_thread_t *, bool );
 
     /* Systray */
-    static void updateSystrayMenu( MainInterface *,intf_thread_t  * );
+    static void updateSystrayMenu( MainInterface *,intf_thread_t  *,
+                                   bool b_force_visible = false);
 
     /* Actions */
     static void DoAction( intf_thread_t *, QObject * );