Commit e89fc639 authored by Francois Cartegnie's avatar Francois Cartegnie Committed by Jean-Baptiste Kempf

Qt: menus: make next/prev to behave accordingly to playlist's content.

Move EnableStatic from local to MenuManager's private (only used there).
Use flags instead of string for action data.
(cherry picked from commit 77d242cce1aacbb6b4c29606c2f6db68f4bd33af)
Signed-off-by: default avatarJean-Baptiste Kempf <jb@videolan.org>
parent 2b0185d4
...@@ -1033,6 +1033,10 @@ void MainInputManager::customEvent( QEvent *event ) ...@@ -1033,6 +1033,10 @@ void MainInputManager::customEvent( QEvent *event )
plEv = static_cast<PLEvent*>( event ); plEv = static_cast<PLEvent*>( event );
emit playlistItemRemoved( plEv->i_item ); emit playlistItemRemoved( plEv->i_item );
return; return;
case PLEmpty_Type:
plEv = static_cast<PLEvent*>( event );
emit playlistNotEmpty( plEv->i_item >= 0 );
return;
case RandomChanged_Type: case RandomChanged_Type:
emit randomChanged( var_GetBool( THEPL, "random" ) ); emit randomChanged( var_GetBool( THEPL, "random" ) );
return; return;
...@@ -1179,6 +1183,14 @@ bool MainInputManager::getPlayExitState() ...@@ -1179,6 +1183,14 @@ bool MainInputManager::getPlayExitState()
return var_GetBool( THEPL, "play-and-exit" ); return var_GetBool( THEPL, "play-and-exit" );
} }
bool MainInputManager::hasEmptyPlaylist()
{
playlist_Lock( THEPL );
bool b_empty = playlist_IsEmpty( THEPL );
playlist_Unlock( THEPL );
return b_empty;
}
/**************************** /****************************
* Static callbacks for MIM * * Static callbacks for MIM *
****************************/ ****************************/
...@@ -1234,23 +1246,31 @@ static int PLItemAppended ...@@ -1234,23 +1246,31 @@ static int PLItemAppended
( vlc_object_t * obj, const char *var, vlc_value_t old, vlc_value_t cur, void *data ) ( vlc_object_t * obj, const char *var, vlc_value_t old, vlc_value_t cur, void *data )
{ {
VLC_UNUSED( obj ); VLC_UNUSED( var ); VLC_UNUSED( old ); VLC_UNUSED( obj ); VLC_UNUSED( var ); VLC_UNUSED( old );
MainInputManager *mim = static_cast<MainInputManager*>(data); MainInputManager *mim = static_cast<MainInputManager*>(data);
playlist_add_t *p_add = static_cast<playlist_add_t*>( cur.p_address ); playlist_add_t *p_add = static_cast<playlist_add_t*>( cur.p_address );
PLEvent *event = new PLEvent( PLItemAppended_Type, p_add->i_item, p_add->i_node ); PLEvent *event = new PLEvent( PLItemAppended_Type, p_add->i_item, p_add->i_node );
QApplication::postEvent( mim, event ); QApplication::postEvent( mim, event );
event = new PLEvent( PLEmpty_Type, p_add->i_item, 0 );
QApplication::postEvent( mim, event );
return VLC_SUCCESS; return VLC_SUCCESS;
} }
static int PLItemRemoved static int PLItemRemoved
( vlc_object_t * obj, const char *var, vlc_value_t old, vlc_value_t cur, void *data ) ( vlc_object_t * obj, const char *var, vlc_value_t old, vlc_value_t cur, void *data )
{ {
VLC_UNUSED( obj ); VLC_UNUSED( var ); VLC_UNUSED( old ); VLC_UNUSED( var ); VLC_UNUSED( old );
playlist_t *pl = (playlist_t *) obj;
MainInputManager *mim = static_cast<MainInputManager*>(data); MainInputManager *mim = static_cast<MainInputManager*>(data);
PLEvent *event = new PLEvent( PLItemRemoved_Type, cur.i_int, 0 ); PLEvent *event = new PLEvent( PLItemRemoved_Type, cur.i_int, 0 );
QApplication::postEvent( mim, event ); QApplication::postEvent( mim, event );
// can't use playlist_IsEmpty( ) as it isn't true yet
if ( pl->items.i_size == 1 ) // lock is held
{
event = new PLEvent( PLEmpty_Type, -1, 0 );
QApplication::postEvent( mim, event );
}
return VLC_SUCCESS; return VLC_SUCCESS;
} }
......
...@@ -101,7 +101,8 @@ private: ...@@ -101,7 +101,8 @@ private:
enum PLEventTypes enum PLEventTypes
{ {
PLItemAppended_Type = QEvent::User + PLEventType + 1, PLItemAppended_Type = QEvent::User + PLEventType + 1,
PLItemRemoved_Type PLItemRemoved_Type,
PLEmpty_Type
}; };
class PLEvent : public QEvent class PLEvent : public QEvent
...@@ -262,6 +263,7 @@ public: ...@@ -262,6 +263,7 @@ public:
audio_output_t *getAout(); audio_output_t *getAout();
bool getPlayExitState(); bool getPlayExitState();
bool hasEmptyPlaylist();
private: private:
MainInputManager( intf_thread_t * ); MainInputManager( intf_thread_t * );
virtual ~MainInputManager(); virtual ~MainInputManager();
...@@ -292,6 +294,7 @@ signals: ...@@ -292,6 +294,7 @@ signals:
void soundMuteChanged(); void soundMuteChanged();
void playlistItemAppended( int itemId, int parentId ); void playlistItemAppended( int itemId, int parentId );
void playlistItemRemoved( int itemId ); void playlistItemRemoved( int itemId );
void playlistNotEmpty( bool );
void randomChanged( bool ); void randomChanged( bool );
void repeatLoopChanged( int ); void repeatLoopChanged( int );
void leafBecameParent( int ); void leafBecameParent( int );
......
...@@ -73,9 +73,6 @@ ...@@ -73,9 +73,6 @@
Just before one of those menus are aboutToShow(), they are rebuild. Just before one of those menus are aboutToShow(), they are rebuild.
*/ */
#define STATIC_ENTRY "__static__"
#define ENTRY_ALWAYS_ENABLED "__ignore__"
enum enum
{ {
ITEM_NORMAL, /* not a checkbox, nor a radio */ ITEM_NORMAL, /* not a checkbox, nor a radio */
...@@ -116,7 +113,7 @@ QAction *addDPStaticEntry( QMenu *menu, ...@@ -116,7 +113,7 @@ QAction *addDPStaticEntry( QMenu *menu,
else else
action = menu->addAction( text, THEDP, member ); action = menu->addAction( text, THEDP, member );
} }
action->setData( STATIC_ENTRY ); action->setData( QVLCMenuManager::ACTION_STATIC );
return action; return action;
} }
...@@ -142,7 +139,10 @@ QAction* addMIMStaticEntry( intf_thread_t *p_intf, ...@@ -142,7 +139,10 @@ QAction* addMIMStaticEntry( intf_thread_t *p_intf,
{ {
action = menu->addAction( text, THEMIM, member ); action = menu->addAction( text, THEMIM, member );
} }
action->setData( bStatic ? STATIC_ENTRY : ENTRY_ALWAYS_ENABLED ); action->setData( QVLCMenuManager::ACTION_STATIC |
( bStatic ) ? QVLCMenuManager::ACTION_ALWAYS_ENABLED
: QVLCMenuManager::ACTION_NONE
);
return action; return action;
} }
...@@ -151,17 +151,20 @@ QAction* addMIMStaticEntry( intf_thread_t *p_intf, ...@@ -151,17 +151,20 @@ QAction* addMIMStaticEntry( intf_thread_t *p_intf,
* @param menu the menu in which the entries will be disabled * @param menu the menu in which the entries will be disabled
* @param enable if false, disable all entries * @param enable if false, disable all entries
**/ **/
void EnableStaticEntries( QMenu *menu, bool enable = true ) void QVLCMenuManager::EnableStaticEntries( QMenu *menu, bool enable = true )
{ {
if( !menu ) return; if( !menu ) return;
QList< QAction* > actions = menu->actions(); QList< QAction* > actions = menu->actions();
for( int i = 0; i < actions.count(); ++i ) for( int i = 0; i < actions.count(); ++i )
{ {
actions[i]->setEnabled( actions[i]->data().toString() int actionflags = actions[i]->data().toInt();
== ENTRY_ALWAYS_ENABLED || if ( actionflags & ACTION_MANAGED )
/* Be careful here, because data("string").toBool is true */ actions[i]->setEnabled(
( enable && (actions[i]->data().toString() == STATIC_ENTRY ) ) ); ( actionflags & ACTION_ALWAYS_ENABLED )
||
enable
);
} }
} }
...@@ -177,10 +180,10 @@ inline int DeleteNonStaticEntries( QMenu *menu ) ...@@ -177,10 +180,10 @@ inline int DeleteNonStaticEntries( QMenu *menu )
QList< QAction* > actions = menu->actions(); QList< QAction* > actions = menu->actions();
for( int i = 0; i < actions.count(); ++i ) for( int i = 0; i < actions.count(); ++i )
{ {
if( actions[i]->data().toString() != STATIC_ENTRY ) if( actions[i]->data().toInt() & QVLCMenuManager::ACTION_NO_CLEANUP )
delete actions[i];
else
i_ret++; i_ret++;
else
delete actions[i];
} }
return i_ret; return i_ret;
} }
...@@ -568,13 +571,13 @@ static inline void VolumeEntries( intf_thread_t *p_intf, QMenu *current ) ...@@ -568,13 +571,13 @@ static inline void VolumeEntries( intf_thread_t *p_intf, QMenu *current )
QAction *action = current->addAction( qtr( "Increase Volume" ), QAction *action = current->addAction( qtr( "Increase Volume" ),
ActionsManager::getInstance( p_intf ), SLOT( AudioUp() ) ); ActionsManager::getInstance( p_intf ), SLOT( AudioUp() ) );
action->setData( STATIC_ENTRY ); action->setData( QVLCMenuManager::ACTION_STATIC );
action = current->addAction( qtr( "Decrease Volume" ), action = current->addAction( qtr( "Decrease Volume" ),
ActionsManager::getInstance( p_intf ), SLOT( AudioDown() ) ); ActionsManager::getInstance( p_intf ), SLOT( AudioDown() ) );
action->setData( STATIC_ENTRY ); action->setData( QVLCMenuManager::ACTION_STATIC );
action = current->addAction( qtr( "Mute" ), action = current->addAction( qtr( "Mute" ),
ActionsManager::getInstance( p_intf ), SLOT( toggleMuteAudio() ) ); ActionsManager::getInstance( p_intf ), SLOT( toggleMuteAudio() ) );
action->setData( STATIC_ENTRY ); action->setData( QVLCMenuManager::ACTION_STATIC );
} }
/** /**
...@@ -808,20 +811,20 @@ void QVLCMenuManager::PopupMenuControlEntries( QMenu *menu, intf_thread_t *p_int ...@@ -808,20 +811,20 @@ void QVLCMenuManager::PopupMenuControlEntries( QMenu *menu, intf_thread_t *p_int
#ifndef __APPLE__ /* No icons in menus in Mac */ #ifndef __APPLE__ /* No icons in menus in Mac */
action->setIcon( QIcon( ":/toolbar/faster2") ); action->setIcon( QIcon( ":/toolbar/faster2") );
#endif #endif
action->setData( STATIC_ENTRY ); action->setData( ACTION_STATIC );
} }
action = rateMenu->addAction( qtr( "Faster (fine)" ), THEMIM->getIM(), action = rateMenu->addAction( qtr( "Faster (fine)" ), THEMIM->getIM(),
SLOT( littlefaster() ) ); SLOT( littlefaster() ) );
action->setData( STATIC_ENTRY ); action->setData( ACTION_STATIC );
action = rateMenu->addAction( qtr( "N&ormal Speed" ), THEMIM->getIM(), action = rateMenu->addAction( qtr( "N&ormal Speed" ), THEMIM->getIM(),
SLOT( normalRate() ) ); SLOT( normalRate() ) );
action->setData( STATIC_ENTRY ); action->setData( ACTION_STATIC );
action = rateMenu->addAction( qtr( "Slower (fine)" ), THEMIM->getIM(), action = rateMenu->addAction( qtr( "Slower (fine)" ), THEMIM->getIM(),
SLOT( littleslower() ) ); SLOT( littleslower() ) );
action->setData( STATIC_ENTRY ); action->setData( ACTION_STATIC );
if( b_normal ) if( b_normal )
{ {
...@@ -830,11 +833,11 @@ void QVLCMenuManager::PopupMenuControlEntries( QMenu *menu, intf_thread_t *p_int ...@@ -830,11 +833,11 @@ void QVLCMenuManager::PopupMenuControlEntries( QMenu *menu, intf_thread_t *p_int
#ifndef __APPLE__ /* No icons in menus in Mac */ #ifndef __APPLE__ /* No icons in menus in Mac */
action->setIcon( QIcon( ":/toolbar/slower2") ); action->setIcon( QIcon( ":/toolbar/slower2") );
#endif #endif
action->setData( STATIC_ENTRY ); action->setData( ACTION_STATIC );
} }
action = menu->addMenu( rateMenu ); action = menu->addMenu( rateMenu );
action->setData( STATIC_ENTRY ); action->setData( ACTION_STATIC );
menu->addSeparator(); menu->addSeparator();
...@@ -845,14 +848,14 @@ void QVLCMenuManager::PopupMenuControlEntries( QMenu *menu, intf_thread_t *p_int ...@@ -845,14 +848,14 @@ void QVLCMenuManager::PopupMenuControlEntries( QMenu *menu, intf_thread_t *p_int
#ifndef __APPLE__ /* No icons in menus in Mac */ #ifndef __APPLE__ /* No icons in menus in Mac */
action->setIcon( QIcon( ":/toolbar/skip_fw") ); action->setIcon( QIcon( ":/toolbar/skip_fw") );
#endif #endif
action->setData( STATIC_ENTRY ); action->setData( ACTION_STATIC );
action = menu->addAction( qtr( "Jump Bac&kward" ), THEMIM->getIM(), action = menu->addAction( qtr( "Jump Bac&kward" ), THEMIM->getIM(),
SLOT( jumpBwd() ) ); SLOT( jumpBwd() ) );
#ifndef __APPLE__ /* No icons in menus in Mac */ #ifndef __APPLE__ /* No icons in menus in Mac */
action->setIcon( QIcon( ":/toolbar/skip_back") ); action->setIcon( QIcon( ":/toolbar/skip_back") );
#endif #endif
action->setData( STATIC_ENTRY ); action->setData( ACTION_STATIC );
addDPStaticEntry( menu, qtr( I_MENU_GOTOTIME ),"", addDPStaticEntry( menu, qtr( I_MENU_GOTOTIME ),"",
SLOT( gotoTimeDialog() ), "Ctrl+T" ); SLOT( gotoTimeDialog() ), "Ctrl+T" );
menu->addSeparator(); menu->addSeparator();
...@@ -862,6 +865,7 @@ void QVLCMenuManager::PopupMenuPlaylistControlEntries( QMenu *menu, ...@@ -862,6 +865,7 @@ void QVLCMenuManager::PopupMenuPlaylistControlEntries( QMenu *menu,
intf_thread_t *p_intf ) intf_thread_t *p_intf )
{ {
bool bEnable = THEMIM->getInput() != NULL; bool bEnable = THEMIM->getInput() != NULL;
bool bPlaylistEmpty = THEMIM->hasEmptyPlaylist();
QAction *action = QAction *action =
addMIMStaticEntry( p_intf, menu, qtr( "&Stop" ), ":/menu/stop", addMIMStaticEntry( p_intf, menu, qtr( "&Stop" ), ":/menu/stop",
SLOT( stop() ), true ); SLOT( stop() ), true );
...@@ -870,10 +874,17 @@ void QVLCMenuManager::PopupMenuPlaylistControlEntries( QMenu *menu, ...@@ -870,10 +874,17 @@ void QVLCMenuManager::PopupMenuPlaylistControlEntries( QMenu *menu,
action->setEnabled( false ); action->setEnabled( false );
/* Next / Previous */ /* Next / Previous */
addMIMStaticEntry( p_intf, menu, qtr( "Pre&vious" ), action = addMIMStaticEntry( p_intf, menu, qtr( "Pre&vious" ),
":/menu/previous", SLOT( prev() ) ); ":/menu/previous", SLOT( prev() ), true );
addMIMStaticEntry( p_intf, menu, qtr( "Ne&xt" ), action->setEnabled( !bPlaylistEmpty );
":/menu/next", SLOT( next() ) ); action->setData( ACTION_NO_CLEANUP );
CONNECT( THEMIM, playlistNotEmpty(bool), action, setEnabled(bool) );
action = addMIMStaticEntry( p_intf, menu, qtr( "Ne&xt" ),
":/menu/next", SLOT( next() ), true );
action->setEnabled( !bPlaylistEmpty );
action->setData( ACTION_NO_CLEANUP );
CONNECT( THEMIM, playlistNotEmpty(bool), action, setEnabled(bool) );
menu->addSeparator(); menu->addSeparator();
} }
......
...@@ -90,6 +90,14 @@ public: ...@@ -90,6 +90,14 @@ public:
/* Actions */ /* Actions */
static void DoAction( QObject * ); static void DoAction( QObject * );
enum actionflag {
ACTION_NONE = 0x0,
ACTION_ALWAYS_ENABLED = 0x1,
ACTION_MANAGED = 0x2, /* managed using EnableStatic(bool)? */
ACTION_NO_CLEANUP = 0x4,
ACTION_STATIC = 0x6 /* legacy shortcut */
};
Q_DECLARE_FLAGS(actionflags, actionflag)
private: private:
/* All main Menus */ /* All main Menus */
...@@ -139,6 +147,7 @@ private: ...@@ -139,6 +147,7 @@ private:
static void UpdateItem( intf_thread_t *, QMenu *, const char *, static void UpdateItem( intf_thread_t *, QMenu *, const char *,
vlc_object_t *, bool ); vlc_object_t *, bool );
static int CreateChoicesMenu( QMenu *,const char *, vlc_object_t *, bool ); static int CreateChoicesMenu( QMenu *,const char *, vlc_object_t *, bool );
static void EnableStaticEntries( QMenu *, bool );
/* recentMRL menu */ /* recentMRL menu */
static QMenu *recentsMenu; static QMenu *recentsMenu;
...@@ -146,6 +155,7 @@ private: ...@@ -146,6 +155,7 @@ private:
public slots: public slots:
static void updateRecents( intf_thread_t * ); static void updateRecents( intf_thread_t * );
}; };
Q_DECLARE_OPERATORS_FOR_FLAGS(QVLCMenuManager::actionflags)
class MenuFunc : public QObject class MenuFunc : public QObject
{ {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment