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 )
plEv = static_cast<PLEvent*>( event );
emit playlistItemRemoved( plEv->i_item );
return;
case PLEmpty_Type:
plEv = static_cast<PLEvent*>( event );
emit playlistNotEmpty( plEv->i_item >= 0 );
return;
case RandomChanged_Type:
emit randomChanged( var_GetBool( THEPL, "random" ) );
return;
......@@ -1179,6 +1183,14 @@ bool MainInputManager::getPlayExitState()
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 *
****************************/
......@@ -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_UNUSED( obj ); VLC_UNUSED( var ); VLC_UNUSED( old );
MainInputManager *mim = static_cast<MainInputManager*>(data);
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 );
QApplication::postEvent( mim, event );
event = new PLEvent( PLEmpty_Type, p_add->i_item, 0 );
QApplication::postEvent( mim, event );
return VLC_SUCCESS;
}
static int PLItemRemoved
( 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);
PLEvent *event = new PLEvent( PLItemRemoved_Type, cur.i_int, 0 );
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;
}
......
......@@ -101,7 +101,8 @@ private:
enum PLEventTypes
{
PLItemAppended_Type = QEvent::User + PLEventType + 1,
PLItemRemoved_Type
PLItemRemoved_Type,
PLEmpty_Type
};
class PLEvent : public QEvent
......@@ -262,6 +263,7 @@ public:
audio_output_t *getAout();
bool getPlayExitState();
bool hasEmptyPlaylist();
private:
MainInputManager( intf_thread_t * );
virtual ~MainInputManager();
......@@ -292,6 +294,7 @@ signals:
void soundMuteChanged();
void playlistItemAppended( int itemId, int parentId );
void playlistItemRemoved( int itemId );
void playlistNotEmpty( bool );
void randomChanged( bool );
void repeatLoopChanged( int );
void leafBecameParent( int );
......
......@@ -73,9 +73,6 @@
Just before one of those menus are aboutToShow(), they are rebuild.
*/
#define STATIC_ENTRY "__static__"
#define ENTRY_ALWAYS_ENABLED "__ignore__"
enum
{
ITEM_NORMAL, /* not a checkbox, nor a radio */
......@@ -116,7 +113,7 @@ QAction *addDPStaticEntry( QMenu *menu,
else
action = menu->addAction( text, THEDP, member );
}
action->setData( STATIC_ENTRY );
action->setData( QVLCMenuManager::ACTION_STATIC );
return action;
}
......@@ -142,7 +139,10 @@ QAction* addMIMStaticEntry( intf_thread_t *p_intf,
{
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;
}
......@@ -151,17 +151,20 @@ QAction* addMIMStaticEntry( intf_thread_t *p_intf,
* @param menu the menu in which the entries will be disabled
* @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;
QList< QAction* > actions = menu->actions();
for( int i = 0; i < actions.count(); ++i )
{
actions[i]->setEnabled( actions[i]->data().toString()
== ENTRY_ALWAYS_ENABLED ||
/* Be careful here, because data("string").toBool is true */
( enable && (actions[i]->data().toString() == STATIC_ENTRY ) ) );
int actionflags = actions[i]->data().toInt();
if ( actionflags & ACTION_MANAGED )
actions[i]->setEnabled(
( actionflags & ACTION_ALWAYS_ENABLED )
||
enable
);
}
}
......@@ -177,10 +180,10 @@ inline int DeleteNonStaticEntries( QMenu *menu )
QList< QAction* > actions = menu->actions();
for( int i = 0; i < actions.count(); ++i )
{
if( actions[i]->data().toString() != STATIC_ENTRY )
delete actions[i];
else
if( actions[i]->data().toInt() & QVLCMenuManager::ACTION_NO_CLEANUP )
i_ret++;
else
delete actions[i];
}
return i_ret;
}
......@@ -568,13 +571,13 @@ static inline void VolumeEntries( intf_thread_t *p_intf, QMenu *current )
QAction *action = current->addAction( qtr( "Increase Volume" ),
ActionsManager::getInstance( p_intf ), SLOT( AudioUp() ) );
action->setData( STATIC_ENTRY );
action->setData( QVLCMenuManager::ACTION_STATIC );
action = current->addAction( qtr( "Decrease Volume" ),
ActionsManager::getInstance( p_intf ), SLOT( AudioDown() ) );
action->setData( STATIC_ENTRY );
action->setData( QVLCMenuManager::ACTION_STATIC );
action = current->addAction( qtr( "Mute" ),
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
#ifndef __APPLE__ /* No icons in menus in Mac */
action->setIcon( QIcon( ":/toolbar/faster2") );
#endif
action->setData( STATIC_ENTRY );
action->setData( ACTION_STATIC );
}
action = rateMenu->addAction( qtr( "Faster (fine)" ), THEMIM->getIM(),
SLOT( littlefaster() ) );
action->setData( STATIC_ENTRY );
action->setData( ACTION_STATIC );
action = rateMenu->addAction( qtr( "N&ormal Speed" ), THEMIM->getIM(),
SLOT( normalRate() ) );
action->setData( STATIC_ENTRY );
action->setData( ACTION_STATIC );
action = rateMenu->addAction( qtr( "Slower (fine)" ), THEMIM->getIM(),
SLOT( littleslower() ) );
action->setData( STATIC_ENTRY );
action->setData( ACTION_STATIC );
if( b_normal )
{
......@@ -830,11 +833,11 @@ void QVLCMenuManager::PopupMenuControlEntries( QMenu *menu, intf_thread_t *p_int
#ifndef __APPLE__ /* No icons in menus in Mac */
action->setIcon( QIcon( ":/toolbar/slower2") );
#endif
action->setData( STATIC_ENTRY );
action->setData( ACTION_STATIC );
}
action = menu->addMenu( rateMenu );
action->setData( STATIC_ENTRY );
action->setData( ACTION_STATIC );
menu->addSeparator();
......@@ -845,14 +848,14 @@ void QVLCMenuManager::PopupMenuControlEntries( QMenu *menu, intf_thread_t *p_int
#ifndef __APPLE__ /* No icons in menus in Mac */
action->setIcon( QIcon( ":/toolbar/skip_fw") );
#endif
action->setData( STATIC_ENTRY );
action->setData( ACTION_STATIC );
action = menu->addAction( qtr( "Jump Bac&kward" ), THEMIM->getIM(),
SLOT( jumpBwd() ) );
#ifndef __APPLE__ /* No icons in menus in Mac */
action->setIcon( QIcon( ":/toolbar/skip_back") );
#endif
action->setData( STATIC_ENTRY );
action->setData( ACTION_STATIC );
addDPStaticEntry( menu, qtr( I_MENU_GOTOTIME ),"",
SLOT( gotoTimeDialog() ), "Ctrl+T" );
menu->addSeparator();
......@@ -862,6 +865,7 @@ void QVLCMenuManager::PopupMenuPlaylistControlEntries( QMenu *menu,
intf_thread_t *p_intf )
{
bool bEnable = THEMIM->getInput() != NULL;
bool bPlaylistEmpty = THEMIM->hasEmptyPlaylist();
QAction *action =
addMIMStaticEntry( p_intf, menu, qtr( "&Stop" ), ":/menu/stop",
SLOT( stop() ), true );
......@@ -870,10 +874,17 @@ void QVLCMenuManager::PopupMenuPlaylistControlEntries( QMenu *menu,
action->setEnabled( false );
/* Next / Previous */
addMIMStaticEntry( p_intf, menu, qtr( "Pre&vious" ),
":/menu/previous", SLOT( prev() ) );
addMIMStaticEntry( p_intf, menu, qtr( "Ne&xt" ),
":/menu/next", SLOT( next() ) );
action = addMIMStaticEntry( p_intf, menu, qtr( "Pre&vious" ),
":/menu/previous", SLOT( prev() ), true );
action->setEnabled( !bPlaylistEmpty );
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();
}
......
......@@ -90,6 +90,14 @@ public:
/* Actions */
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:
/* All main Menus */
......@@ -139,6 +147,7 @@ private:
static void UpdateItem( intf_thread_t *, QMenu *, const char *,
vlc_object_t *, bool );
static int CreateChoicesMenu( QMenu *,const char *, vlc_object_t *, bool );
static void EnableStaticEntries( QMenu *, bool );
/* recentMRL menu */
static QMenu *recentsMenu;
......@@ -146,6 +155,7 @@ private:
public slots:
static void updateRecents( intf_thread_t * );
};
Q_DECLARE_OPERATORS_FOR_FLAGS(QVLCMenuManager::actionflags)
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