]> git.sesse.net Git - vlc/commitdiff
Qt4 - Systray Icon and menu to control VLC. Play/Pause Stop Previous Next Quit for...
authorJean-Baptiste Kempf <jb@videolan.org>
Wed, 2 May 2007 19:58:03 +0000 (19:58 +0000)
committerJean-Baptiste Kempf <jb@videolan.org>
Wed, 2 May 2007 19:58:03 +0000 (19:58 +0000)
modules/gui/qt4/main_interface.cpp
modules/gui/qt4/main_interface.hpp
modules/gui/qt4/menus.cpp
modules/gui/qt4/menus.hpp
modules/gui/qt4/qt4.cpp
modules/gui/qt4/res.qrc

index a1977c255530b463a2fb0a84d749fee1b3bef69c..2a3694dc71cadbb806077013ba1057add5721170 100644 (file)
@@ -38,6 +38,7 @@
 #include <QStatusBar>
 #include <QKeyEvent>
 #include <QUrl>
+#include <QSystemTrayIcon>
 
 #include <assert.h>
 #include <vlc_keys.h>
@@ -130,7 +131,10 @@ MainInterface::MainInterface( intf_thread_t *_p_intf ) : QVLCMW( _p_intf )
              this, setDisplay( float, int, int ) );
     CONNECT( THEMIM->getIM(), nameChanged( QString ), this,setName( QString ) );
     CONNECT( THEMIM->getIM(), statusChanged( int ), this, setStatus( int ) );
-    CONNECT( THEMIM->getIM(), navigationChanged( int ), this, setNavigation(int) );
+    CONNECT( THEMIM->getIM(), statusChanged( int ), this,
+             updateSystrayMenu( int ) );
+    CONNECT( THEMIM->getIM(), navigationChanged( int ), 
+             this, setNavigation(int) );
     CONNECT( slider, sliderDragged( float ),
              THEMIM->getIM(), sliderUpdate( float ) );
 
@@ -146,21 +150,24 @@ MainInterface::MainInterface( intf_thread_t *_p_intf ) : QVLCMW( _p_intf )
     p_intf->b_interaction = VLC_TRUE;
 
     /* Register callback for the intf-popupmenu variable */
-    playlist_t *p_playlist =
-        (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
+    playlist_t *p_playlist = (playlist_t *)vlc_object_find( p_intf,
+                                        VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
     if( p_playlist != NULL )
     {
         var_AddCallback( p_playlist, "intf-popupmenu", PopupMenuCB, p_intf );
         var_AddCallback( p_playlist, "intf-show", IntfShowCB, p_intf );
         vlc_object_release( p_playlist );
     }
+    if( QSystemTrayIcon::isSystemTrayAvailable() &&
+                              ( config_GetInt( p_intf, "qt-system-tray") == 1))
+            createSystrayMenu();
 }
 
 MainInterface::~MainInterface()
 {
     /* Unregister callback for the intf-popupmenu variable */
-    playlist_t *p_playlist =
-        (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
+    playlist_t *p_playlist = (playlist_t *)vlc_object_find( p_intf,
+                                        VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
     if( p_playlist != NULL )
     {
         var_DelCallback( p_playlist, "intf-popupmenu", PopupMenuCB, p_intf );
@@ -264,6 +271,19 @@ void MainInterface::handleMainUi( QSettings *settings )
     setMinimumSize( PREF_W, addSize.height() );
 }
 
+void MainInterface::createSystrayMenu()
+{
+    sysTray = new QSystemTrayIcon( QIcon( QPixmap( ":/vlc128.png" ) ) );
+    systrayMenu = new QMenu( qtr( "VLC media player" ), this );
+    QVLCMenu::updateSystrayMenu( this, p_intf );
+    sysTray->show();
+}
+
+void MainInterface::updateSystrayMenu( int status )
+{
+    QVLCMenu::updateSystrayMenu( this, p_intf ) ;
+}
+
 /**********************************************************************
  * Handling of the components
  **********************************************************************/
@@ -556,7 +576,7 @@ void MainInterface::customEvent( QEvent *event )
         if( p_event->OnTop() )
             setWindowFlags(windowFlags() | Qt::WindowStaysOnTopHint);
         else
-            setWindowFlags(windowFlags() & ~Qt::WindowStaysOnTopHint);            
+            setWindowFlags(windowFlags() & ~Qt::WindowStaysOnTopHint);
         show(); /* necessary to apply window flags?? */
     }
 }
index 6d2bab5004928e0c7500f934215e758f412f3f7e..9ef47af394d724c505d4b973d043f29bc68a8484 100644 (file)
@@ -30,6 +30,8 @@
 #include "util/qvlcframe.hpp"
 
 #include <QSize>
+#include <QSystemTrayIcon>
+#include <QMenu>
 
 class QSettings;
 class QCloseEvent;
@@ -44,6 +46,7 @@ class PlaylistWidget;
 class VolumeClickHandler;
 class VisualSelector;
 class ControlsWidget;
+class QMenu;
 
 class MainInterface : public QVLCMW
 {
@@ -57,6 +60,9 @@ public:
     void releaseVideo( void *);
     int controlVideo( void *p_window, int i_query, va_list args );
     void setVLCWindowsTitle( QString title = "" );
+
+    QSystemTrayIcon *getSysTray() { return sysTray; };
+    QMenu *getSysTrayMenu() { return systrayMenu; };
 protected:
     void resizeEvent( QResizeEvent * );
     void dropEvent( QDropEvent *);
@@ -69,11 +75,15 @@ protected:
 private:
     QSettings *settings;
     QSize mainSize, addSize;
+    QSystemTrayIcon *sysTray;
+    QMenu *systrayMenu;
 
     bool need_components_update;
     void calculateInterfaceSize();
     void handleMainUi( QSettings* );
+    void handleSystray();
     void doComponentsUpdate();
+    void createSystrayMenu();
 
     /* Video */
     VideoWidget         *videoWidget;
@@ -120,6 +130,7 @@ private slots:
     void visual();
     void advanced();
     void updateVolume( int sliderVolume );
+    void updateSystrayMenu( int );
 };
 
 
index 071c0de1022b276db80e8d2ddbc221c5af641ec2..e519e22ae752e7a7d74b05aacbc22f552e684721 100644 (file)
@@ -27,6 +27,7 @@
 #include <QAction>
 #include <QActionGroup>
 #include <QSignalMapper>
+#include <QSystemTrayIcon>
 
 #ifndef WIN32
 #   include <signal.h>
@@ -49,14 +50,14 @@ enum
 static QActionGroup *currentGroup;
 
 // Add static entries to menus
-#define DP_SADD( text, help, icon, slot, shortcut ) \
+#define DP_SADD( menu, text, help, icon, slot, shortcut ) \
 { \
     if( strlen(icon) > 0 ) \
     { \
         if( strlen(shortcut) > 0 ) \
         { \
             menu->addAction( QIcon(icon), text, THEDP, SLOT( slot ), \
-                    tr(shortcut) );\
+                    qtr(shortcut) );\
         } \
         else \
         { \
@@ -76,7 +77,7 @@ static QActionGroup *currentGroup;
         } \
     } \
 }
-#define MIM_SADD( text, help, icon, slot ) \
+#define MIM_SADD( menu, text, help, icon, slot ) \
 { \
     if( strlen(icon) > 0 ) \
     { \
@@ -177,7 +178,7 @@ void QVLCMenu::createMenuBar( MainInterface *mi, intf_thread_t *p_intf,
     pthread_sigmask (SIG_UNBLOCK, &set, NULL);
 #endif
     QMenuBar *bar = mi->menuBar();
-#ifndef WIN32 
+#ifndef WIN32
     pthread_sigmask (SIG_BLOCK, &set, NULL);
 #endif
     BAR_ADD( FileMenu(), qtr("&Media") );
@@ -196,18 +197,18 @@ void QVLCMenu::createMenuBar( MainInterface *mi, intf_thread_t *p_intf,
 QMenu *QVLCMenu::FileMenu()
 {
     QMenu *menu = new QMenu();
-    DP_SADD( qtr("Open &File..." ), "", "", openFileDialog(), "Ctrl+O" );
-    DP_SADD( qtr("Open &Disc..." ), "", "", openDiscDialog(), "Ctrl+D" );
-    DP_SADD( qtr("Open &Network..." ), "", "", openNetDialog(), "Ctrl+N" );
-    DP_SADD( qtr("Open &Capture Device..." ), "", "", openCaptureDialog(),
+    DP_SADD( menu, qtr("Open &File..." ), "", "", openFileDialog(), "Ctrl+O" );
+    DP_SADD( menu, qtr("Open &Disc..." ), "", "", openDiscDialog(), "Ctrl+D" );
+    DP_SADD( menu, qtr("Open &Network..." ), "", "", openNetDialog(), "Ctrl+N" );
+    DP_SADD( menu, qtr("Open &Capture Device..." ), "", "", openCaptureDialog(),
             "Ctrl+C" );
     menu->addSeparator();
-    DP_SADD( qtr("&Streaming..."), "", "", openThenStreamingDialogs(), 
+    DP_SADD( menu, qtr("&Streaming..."), "", "", openThenStreamingDialogs(), 
             "Ctrl+S" );
-    DP_SADD( qtr("Conve&rt / Save..."), "", "", openThenTranscodingDialogs(), 
+    DP_SADD( menu, qtr("Conve&rt / Save..."), "", "", openThenTranscodingDialogs(), 
             "Ctrl+R" );
     menu->addSeparator();
-    DP_SADD( qtr("&Quit") , "", "", quit(), "Ctrl+Q");
+    DP_SADD( menu, qtr("&Quit") , "", "", quit(), "Ctrl+Q");
     return menu;
 }
 
@@ -217,8 +218,8 @@ QMenu *QVLCMenu::PlaylistMenu( MainInterface *mi, intf_thread_t *p_intf )
     menu->addMenu( SDMenu( p_intf ) );
     menu->addSeparator();
 
-    DP_SADD( qtr(I_PL_LOAD), "", "", openPlaylist(), "Ctrl+L" );
-    DP_SADD( qtr(I_PL_SAVE), "", "", savePlaylist(), "Ctrl+K" );
+    DP_SADD( menu, qtr(I_PL_LOAD), "", "", openPlaylist(), "Ctrl+L" );
+    DP_SADD( menu, qtr(I_PL_SAVE), "", "", savePlaylist(), "Ctrl+K" );
     menu->addSeparator();
     menu->addAction( qtr("Undock from interface"), mi,
             SLOT( undockPlaylist() ), qtr("Ctrl+U") );
@@ -237,12 +238,12 @@ QMenu *QVLCMenu::ToolsMenu( intf_thread_t *p_intf, MainInterface *mi,
         menu->addMenu( intfmenu );
         menu->addSeparator();
     }
-    DP_SADD( qtr(I_MENU_MSG), "", "", messagesDialog(), "Ctrl+M" );
-    DP_SADD( qtr(I_MENU_INFO) , "", "", mediaInfoDialog(), "Ctrl+J" );
-    DP_SADD( qtr(I_MENU_CODECINFO) , "", "", mediaCodecDialog(), "Ctrl+I" );
-    DP_SADD( qtr(I_MENU_GOTOTIME), "","", gotoTimeDialog(), "Ctrl+T" );
-    DP_SADD( qtr(I_MENU_BOOKMARK), "","", bookmarksDialog(), "Ctrl+B" );
-    DP_SADD( qtr(I_MENU_VLM), "","", vlmDialog(), "Ctrl+V" );
+    DP_SADD( menu, qtr(I_MENU_MSG), "", "", messagesDialog(), "Ctrl+M" );
+    DP_SADD( menu, qtr(I_MENU_INFO) , "", "", mediaInfoDialog(), "Ctrl+J" );
+    DP_SADD( menu, qtr(I_MENU_CODECINFO) , "", "", mediaCodecDialog(), "Ctrl+I" );
+    DP_SADD( menu, qtr(I_MENU_GOTOTIME), "","", gotoTimeDialog(), "Ctrl+T" );
+    DP_SADD( menu, qtr(I_MENU_BOOKMARK), "","", bookmarksDialog(), "Ctrl+B" );
+    DP_SADD( menu, qtr(I_MENU_VLM), "","", vlmDialog(), "Ctrl+V" );
 
     menu->addSeparator();
     if( mi )
@@ -259,10 +260,10 @@ QMenu *QVLCMenu::ToolsMenu( intf_thread_t *p_intf, MainInterface *mi,
 #endif
         menu->addAction ( qtr( "Playlist"), mi, SLOT( playlist() ) );
     }
-    DP_SADD( qtr(I_MENU_EXT), "","",extendedDialog(), "Ctrl+E" );
-    DP_SADD( qtr("Hide Menus..."), "","",hideMenus(), "Ctrl+H" );
+    DP_SADD( menu, qtr(I_MENU_EXT), "","",extendedDialog(), "Ctrl+E" );
+    DP_SADD( menu, qtr("Hide Menus..."), "","",hideMenus(), "Ctrl+H" );
     menu->addSeparator();
-    DP_SADD( qtr("Preferences"), "", "", prefsDialog(), "Ctrl+P" );
+    DP_SADD( menu, qtr("Preferences"), "", "", prefsDialog(), "Ctrl+P" );
     return menu;
 }
 
@@ -398,15 +399,15 @@ QMenu *QVLCMenu::SDMenu( intf_thread_t *p_intf )
 QMenu *QVLCMenu::HelpMenu()
 {
     QMenu *menu = new QMenu();
-    DP_SADD( qtr("Help") , "", "", helpDialog(), "F1" );
+    DP_SADD( menu, qtr("Help") , "", "", helpDialog(), "F1" );
     menu->addSeparator();
-    DP_SADD( qtr(I_MENU_ABOUT), "", "", aboutDialog(), "Ctrl+F1");
+    DP_SADD( menu, qtr(I_MENU_ABOUT), "", "", aboutDialog(), "Ctrl+F1");
     return menu;
 }
 
 
 /*****************************************************************************
- * Popup menus
+ * Popup menus                                                               *
  *****************************************************************************/
 #define POPUP_BOILERPLATE \
     unsigned int i_last_separator = 0; \
@@ -422,22 +423,26 @@ QMenu *QVLCMenu::HelpMenu()
     p_intf->p_sys->p_popup_menu = NULL; \
     i_last_separator = 0;
 
-#define POPUP_STATIC_ENTRIES \
+#define POPUP_PLAY_ENTRIES( menu )\
     vlc_value_t val; \
     if( p_input ) \
     { \
         var_Get( p_input, "state", &val ); \
         if( val.i_int == PAUSE_S ) \
-            MIM_SADD( qtr("Play"), "", "", togglePlayPause() ) \
+            MIM_SADD( menu, qtr("Play"), "", "", togglePlayPause() ) \
         else \
-            MIM_SADD( qtr("Pause"), "", "", togglePlayPause() ) \
+            MIM_SADD( menu, qtr("Pause"), "", "", togglePlayPause() ) \
     } \
     else if( THEPL->items.i_size && THEPL->i_enabled ) \
-        MIM_SADD( qtr("Play"), "", "", togglePlayPause() );\
+        MIM_SADD( menu, qtr("Play"), "", "", togglePlayPause() ); \
+    \
+    MIM_SADD( menu, qtr("Stop"), "", "", stop() ); \
+    MIM_SADD( menu, qtr("Previous"), "", "", prev() ); \
+    MIM_SADD( menu, qtr("Next"), "", "", next() );
+
+#define POPUP_STATIC_ENTRIES \
+    POPUP_PLAY_ENTRIES( menu ); \
     \
-    MIM_SADD( qtr("Stop"), "", "", stop() ); \
-    MIM_SADD( qtr("Previous"), "", "", prev() ); \
-    MIM_SADD( qtr("Next"), "", "", next() ); \
     menu->addSeparator(); \
     QMenu *intfmenu = InterfacesMenu( p_intf, NULL ); \
     intfmenu->setTitle( qtr("Interfaces" ) ); \
@@ -460,7 +465,7 @@ QMenu *QVLCMenu::HelpMenu()
     helpmenu->setTitle( qtr("Help") ); \
     menu->addMenu( helpmenu ); \
     \
-    DP_SADD( qtr("Quit"), "", "", quit() , "Ctrl+Q" );
+    DP_SADD( menu, qtr("Quit"), "", "", quit() , "Ctrl+Q" );
 
 void QVLCMenu::VideoPopupMenu( intf_thread_t *p_intf )
 {
@@ -575,16 +580,36 @@ void QVLCMenu::PopupMenu( intf_thread_t *p_intf, bool show )
         p_intf->p_sys->p_popup_menu->popup( QCursor::pos() );
     }
     else
-    {    
+    {
         // destroy popup if there is one
         delete p_intf->p_sys->p_popup_menu;
         p_intf->p_sys->p_popup_menu = NULL;
     }
 }
 
+/************************************************************************
+ * Systray Menu                                                         *
+ ************************************************************************/
+
+void QVLCMenu::updateSystrayMenu( MainInterface *mi, intf_thread_t *p_intf
+                                  )
+{
+    POPUP_BOILERPLATE;
+    QMenu *sysMenu = mi->getSysTrayMenu();
+    sysMenu->clear();
+    POPUP_PLAY_ENTRIES( sysMenu );
+    sysMenu->addSeparator();
+
+    /* FIXME DP_SADD( menu, qtr("&Hide/show") , "", "", quit(), "" );*/
+    DP_SADD( sysMenu, qtr("&Quit") , "", "", quit(), "" );
+
+    mi->getSysTray()->setContextMenu( sysMenu );
+}
+
 #undef PUSH_VAR
 #undef PUSH_SEPARATOR
 
+
 /*************************************************************************
  * Builders for automenus
  *************************************************************************/
@@ -899,5 +924,4 @@ void QVLCMenu::DoAction( intf_thread_t *p_intf, QObject *data )
     if( p_object == NULL ) return;
 
     var_Set( p_object, itemData->psz_var, itemData->val );
-    vlc_object_release( p_object );
-}
+    vlc_object_release( p_object );}
index 1501bf10c3fd71dc2831e72d1315c6d55f9fb3e6..2561b14fe39057a4fc8424786f3edf6312c5c383 100644 (file)
@@ -26,6 +26,7 @@
 #include "qt4.hpp"
 #include <QObject>
 #include <vector>
+#include <QSystemTrayIcon>
 
 using namespace std;
 
@@ -61,7 +62,8 @@ class QVLCMenu : public QObject
 {
     Q_OBJECT;
 public:
-    static void createMenuBar( MainInterface *mi, intf_thread_t *, bool, bool, bool );
+    static void createMenuBar( MainInterface *mi, intf_thread_t *,
+                               bool, bool, bool );
 
     /* Menus */
     static QMenu *FileMenu();
@@ -75,12 +77,16 @@ public:
     static QMenu *InterfacesMenu( intf_thread_t *p_intf, QMenu * );
     static QMenu *HelpMenu();
 
-    /* Popups */
+    /* Popups Menus */
     static void AudioPopupMenu( intf_thread_t * );
     static void VideoPopupMenu( intf_thread_t * );
     static void MiscPopupMenu( intf_thread_t * );
     static void PopupMenu( intf_thread_t *, bool );
 
+    /* Systray */
+    static void updateSystrayMenu( MainInterface *,intf_thread_t  * );
+
+    /* Actions */
     static void DoAction( intf_thread_t *, QObject * );
 private:
     /* Generic automenu methods */
@@ -92,7 +98,6 @@ private:
                                   int, int, vlc_value_t, int, bool c = false );
     static void CreateItem( QMenu *, const char *, vlc_object_t *, bool );
     static int CreateChoicesMenu( QMenu *,const char *, vlc_object_t *, bool );
-
 };
 
 class MenuFunc : public QObject
index d4fc16640a0530691e4086d5b4c4f60a3777500a..360cf826f5bd2b1248ed5bc7ee4cac53033bb827 100644 (file)
@@ -48,6 +48,10 @@ static void ShowDialog   ( intf_thread_t *, int, int, intf_dialog_args_t * );
                                    "preferences when opening the preferences " \
                                    "dialog.")
 
+#define SYSTRAY_TEXT N_("Show a systray icon to control")
+#define SYSTRAY_LONGTEXT N_("Show in the taskbar, a systray icon" \
+                            "in order to control VLC for basic actions")
+
 vlc_module_begin();
     set_shortname( (char *)"Qt" );
     set_description( (char*)_("Qt interface") );
@@ -66,6 +70,8 @@ vlc_module_begin();
                 VLC_TRUE );
         add_bool( "qt-advanced-pref", VLC_FALSE, NULL, ADVANCED_PREFS_TEXT,
                 ADVANCED_PREFS_LONGTEXT, VLC_FALSE );
+        add_bool( "qt-system-tray", VLC_TRUE, NULL, SYSTRAY_TEXT,
+                SYSTRAY_LONGTEXT, VLC_FALSE);
         set_callbacks( OpenDialogs, Close );
 vlc_module_end();
 
index 41bd5c10e8c87a24881a9497651d0dd3f06d5127..f72a25bd5bd167d39f5fa1db18d0f5c8596b88ae 100644 (file)
@@ -9,6 +9,7 @@
   <file>pixmaps/volume-high.png</file>
   <file>pixmaps/go-next.png</file>
   <file alias="vlc128.png">../../../share/vlc128x128.png</file>
+  <file alias="vlc48.png">../../../share/vlc48x48.png</file>
   <file alias="noart.png">pixmaps/noart.png</file>
   <file>pixmaps/playlist_icon.png</file>
   <file>pixmaps/spref_cone_Audio_64.png</file>