extragear/multimedia/amarok/src/playlist/view
Bart Cerneels
bart.cerneels at kde.org
Sat Mar 21 10:48:45 CET 2009
Yes, sorry about that. I quickly hacked in the 'PUD as context-menu'
and knew it was done ugly. Wanted to correct it later but never got to
it.
On 3/21/09, Seb Ruiz <ruiz at kde.org> wrote:
> SVN commit 942128 by seb:
>
> Fix regression of code duplication and breakage
> * We have Playlist::ViewCommon::trackMenu -- please use it for context
> menus in the playlist (even if it looks less and less likely to have
> multiple view implementations)
> This fixes the loss of separators in the playlist context menu.
> CCMAIL: amarok-devel at kde.org
> CCMAIL: bart.cerneels at kde.org
>
> M +66 -31 PlaylistViewCommon.cpp
> M +3 -0 PlaylistViewCommon.h
> M +3 -108 listview/PrettyListView.cpp
> M +0 -3 listview/PrettyListView.h
>
>
> ---
> trunk/extragear/multimedia/amarok/src/playlist/view/PlaylistViewCommon.cpp
> #942127:942128
> @@ -1,5 +1,6 @@
> /***************************************************************************
> * copyright : (C) 2008 Bonne Eggletson <b.eggleston at gmail.com>
> + * copyright : (C) 2009 Seb Ruiz <ruiz at kde.org>
> *
> * This program is free software; you can redistribute it and/or
> * modify it under the terms of the GNU General Public License as
> @@ -15,7 +16,7 @@
> * GNU General Public License for more details.
> *
> * You should have received a copy of the GNU General Public License
> - * along with this program. If not, see <http://www.gnu.org/licenses/>.
> + * along with parent program. If not, see <http://www.gnu.org/licenses/>.
>
> **************************************************************************/
>
>
> @@ -28,23 +29,35 @@
> #include "playlist/PlaylistModel.h"
> #include "covermanager/CoverFetchingActions.h"
> #include "meta/capabilities/CurrentTrackActionsCapability.h"
> -#include "context/popupdropper/libpud/PopupDropperAction.h"
>
> #include <QObject>
> #include <QModelIndex>
>
> #include <KMenu>
> -#include <KAction>
>
> void
> Playlist::ViewCommon::trackMenu( QWidget *parent, const QModelIndex *index,
> const QPoint &pos, bool coverActions )
> {
> DEBUG_BLOCK
>
> + KMenu *menu = new KMenu( parent );
> + QList<PopupDropperAction*> actions = actionsFor( parent, index,
> coverActions );
> + foreach( PopupDropperAction *action, actions )
> + menu->addAction( action );
> +
> + menu->exec( pos );
> +}
> +
> +QList<PopupDropperAction*>
> +Playlist::ViewCommon::actionsFor( QWidget *parent, const QModelIndex
> *index, bool coverActions )
> +{
> + QList<PopupDropperAction*> actions;
> +
> Meta::TrackPtr track = index->data( Playlist::TrackRole ).value<
> Meta::TrackPtr >();
>
> - KMenu *menu = new KMenu( parent );
> -
> + PopupDropperAction *separator = new PopupDropperAction( parent );
> + separator->setSeparator( true );
> +
> const bool isCurrentTrack = index->data( Playlist::ActiveTrackRole
> ).toBool();
>
> if( isCurrentTrack )
> @@ -53,43 +66,50 @@
> const KIcon icon = isPaused ? KIcon(
> "media-playback-start-amarok" ) : KIcon( "media-playback-pause-amarok" );
> const QString text = isPaused ? i18n( "&Play" ) : i18n( "&Pause");
>
> - KAction *playPauseAction = new KAction( icon, text, parent );
> + PopupDropperAction *playPauseAction = new PopupDropperAction( icon,
> text, parent );
> QObject::connect( playPauseAction, SIGNAL( triggered() ),
> The::engineController(), SLOT( playPause() ) );
>
> - menu->addAction( playPauseAction );
> + actions << playPauseAction;
> }
> else
> {
> - KAction *playAction = new KAction( KIcon(
> "media-playback-start-amarok" ), i18n( "&Play" ), parent );
> + PopupDropperAction *playAction = new PopupDropperAction( KIcon(
> "media-playback-start-amarok" ), i18n( "&Play" ), parent );
> playAction->setData( index->row() );
> QObject::connect( playAction, SIGNAL( triggered() ), parent, SLOT(
> playTrack() ) );
>
> - menu->addAction( playAction );
> + actions << playAction;
> }
>
> - debug() << "state: " << index->data( Playlist::StateRole ).toInt();
> - debug() << "queued: " << Item::Queued;
> + PopupDropperAction *stopAction = new PopupDropperAction( KIcon(
> "media-playback-stop-amarok" ), i18n( "Stop Playing After This Track" ),
> parent );
> + QObject::connect( stopAction, SIGNAL( triggered() ), parent, SLOT(
> stopAfterTrack() ) );
> + actions << stopAction;
>
> + actions << separator;
> +
> const bool isQueued = index->data( Playlist::StateRole ).toInt() &
> Item::Queued;
> - if( !isQueued )
> - menu->addAction( KIcon( "media-track-queue-amarok" ), i18n( "Queue
> Track" ), parent, SLOT( queueSelection() ) );
> + const QString queueText = !isQueued ? i18n( "Queue Track" ) : i18n(
> "Dequeue Track" );
> + PopupDropperAction *queueAction = new PopupDropperAction( KIcon(
> "media-track-queue-amarok" ), queueText, parent );
> + if( isQueued )
> + QObject::connect( queueAction, SIGNAL( triggered() ), parent, SLOT(
> dequeueSelection() ) );
> else
> - menu->addAction( KIcon( "media-track-queue-amarok" ), i18n(
> "Dequeue Track" ), parent, SLOT( dequeueSelection() ) );
> + QObject::connect( queueAction, SIGNAL( triggered() ), parent, SLOT(
> queueSelection() ) );
>
> - ( menu->addAction( KIcon( "media-playback-stop-amarok" ), i18n( "Stop
> Playing After Track" ), parent, SLOT( stopAfterTrack() ) ) )->setEnabled(
> true );
> -
> - menu->addSeparator();
> - ( menu->addAction( KIcon( "media-track-remove-amarok" ), i18n( "Remove
> From Playlist" ), parent, SLOT( removeSelection() ) ) )->setEnabled( true );
> - menu->addSeparator();
> - menu->addAction( KIcon( "media-track-edit-amarok" ), i18n( "Edit Track
> Details" ), parent, SLOT( editTrackInformation() ) );
> + actions << queueAction;
>
> - //lets see if this is the currently playing tracks, and if it has
> CurrentTrackActionsCapability
> + actions << separator;
> +
> + PopupDropperAction *removeAction = new PopupDropperAction( KIcon(
> "media-track-remove-amarok" ), i18n( "Remove From Playlist" ), parent );
> + QObject::connect( removeAction, SIGNAL( triggered() ), parent, SLOT(
> removeSelection() ) );
> + actions << removeAction;
> +
> + actions << separator;
> +
> + //lets see if parent is the currently playing tracks, and if it has
> CurrentTrackActionsCapability
> if( isCurrentTrack )
> {
> -
> - QList<QAction *> globalCurrentTrackActions =
> The::globalCurrentTrackActions()->actions();
> + QList<QAction*> globalCurrentTrackActions =
> The::globalCurrentTrackActions()->actions();
> foreach( QAction *action, globalCurrentTrackActions )
> - menu->addAction( action );
> + actions << PopupDropperAction::from( action );
>
> if ( track->hasCapabilityInterface(
> Meta::Capability::CurrentTrackActions ) )
> {
> @@ -99,12 +119,13 @@
> QList<PopupDropperAction *> actions = cac->customActions();
>
> foreach( PopupDropperAction *action, actions )
> - menu->addAction( action );
> + actions << action;
> }
> }
> }
> - menu->addSeparator();
>
> + actions << separator;
> +
> if ( coverActions )
> {
> Meta::AlbumPtr album = track->album();
> @@ -113,15 +134,29 @@
> Meta::CustomActionsCapability *cac =
> album->as<Meta::CustomActionsCapability>();
> if ( cac )
> {
> - QList<PopupDropperAction *> actions = cac->customActions();
> + QList<PopupDropperAction *> customActions =
> cac->customActions();
>
> - menu->addSeparator();
> - foreach( PopupDropperAction *action, actions )
> - menu->addAction( action );
> + foreach( PopupDropperAction *customAction, customActions )
> + actions << customAction;
> }
> }
> }
>
> - menu->exec( pos );
> + actions << separator;
> +
> + const bool isMultiSource = index->data( Playlist::MultiSourceRole
> ).toBool();
> + if( isMultiSource )
> + {
> + PopupDropperAction *selectSourceAction = new PopupDropperAction(
> KIcon( "media-playlist-repeat" ), i18n( "Select Source" ), parent );
> + QObject::connect( selectSourceAction, SIGNAL( triggered() ),
> parent, SLOT( selectSource() ) );
> +
> + actions << selectSourceAction;
> + }
> +
> + PopupDropperAction *editAction = new PopupDropperAction( KIcon(
> "media-track-edit-amarok" ), i18n( "Edit Track Details" ), parent );
> + QObject::connect( editAction, SIGNAL( triggered() ), parent, SLOT(
> editTrackInformation() ) );
> + actions << editAction;
> +
> + return actions;
> }
>
> --- trunk/extragear/multimedia/amarok/src/playlist/view/PlaylistViewCommon.h
> #942127:942128
> @@ -22,6 +22,8 @@
> #ifndef AMAROK_PLAYLISTVIEWCOMMON_H
> #define AMAROK_PLAYLISTVIEWCOMMON_H
>
> +#include "context/popupdropper/libpud/PopupDropperAction.h"
> +
> #include <QModelIndex>
> #include <QPoint>
>
> @@ -31,6 +33,7 @@
> {
> void editTrackInformation();
> void trackMenu( QWidget *, const QModelIndex *, const QPoint &pos,
> bool coverActions = false );
> + QList<PopupDropperAction*> actionsFor( QWidget *parent, const
> QModelIndex *index, bool coverActions );
> }
> }
>
> ---
> trunk/extragear/multimedia/amarok/src/playlist/view/listview/PrettyListView.cpp
> #942127:942128
> @@ -212,7 +212,7 @@
> if( event->modifiers() & Qt::ControlModifier )
> return;
>
> - trackMenu( this, index, event->globalPos(), true );
> + ViewCommon::trackMenu( this, &index, event->globalPos(), true );
> event->accept();
> }
>
> @@ -414,12 +414,10 @@
> qDebug() << "does play exist in renderer? " << (
> The::svgHandler()->getRenderer( "amarok/images/pud_items.svg"
> )->elementExists( "load" ) );
> QModelIndexList indices = selectedIndexes();
>
> - QList<PopupDropperAction*> actions =
> - actionsFor( indices.first(), true );
> + QList<PopupDropperAction*> actions = ViewCommon::actionsFor( this,
> &indices.first(), true );
>
> - foreach( PopupDropperAction * action, actions ) {
> + foreach( PopupDropperAction * action, actions )
> m_pd->addItem( The::popupDropperFactory()->createItem( action
> ), true );
> - }
>
> m_pd->show();
> }
> @@ -436,109 +434,6 @@
> ongoingDrags = false;
> }
>
> -void
> -Playlist::PrettyListView::trackMenu( QWidget *parent, const QModelIndex
> &index, const QPoint &pos, bool coverActions )
> -{
> - DEBUG_BLOCK
> - KMenu *menu = new KMenu( parent );
> -
> - QList<PopupDropperAction *> actions = actionsFor( index, coverActions
> );
> - foreach( PopupDropperAction *action, actions )
> - {
> - menu->addAction( action );
> - }
> - menu->exec( pos );
> -}
> -
> -QList<PopupDropperAction *>
> -Playlist::PrettyListView::actionsFor( const QModelIndex &index, bool
> coverActions )
> -{
> - DEBUG_BLOCK
> - QList<PopupDropperAction *> actions;
> -
> - Meta::TrackPtr track = index.data( Playlist::TrackRole ).value<
> Meta::TrackPtr >();
> -
> - const bool isCurrentTrack = index.data( Playlist::ActiveTrackRole
> ).toBool();
> -
> - PopupDropperAction *playAction = new PopupDropperAction( KIcon(
> "media-playback-start-amarok" ), i18n( "&Play" ), this );
> - connect( playAction, SIGNAL( triggered() ), The::engineController(),
> SLOT( playPause() ) );
> -
> - PopupDropperAction *pauseAction = new PopupDropperAction( KIcon(
> "media-playback-pause-amarok" ), i18n( "&Pause" ), this );
> - connect( pauseAction, SIGNAL( triggered() ), The::engineController(),
> SLOT( playPause() ) );
> -
> - const bool isPaused = The::engineController()->isPaused();
> - if( isCurrentTrack && !isPaused )
> - actions << pauseAction;
> - else
> - actions << playAction;
> -
> -
> - const bool isMultiSource = index.data( Playlist::MultiSourceRole
> ).toBool();
> - if ( isMultiSource ) {
> - PopupDropperAction *selectSourceAction = new PopupDropperAction(
> KIcon( "media-playlist-repeat" ), i18n( "Select Source" ), this );
> - connect( selectSourceAction, SIGNAL( triggered() ), this, SLOT(
> selectSource() ) );
> - actions << selectSourceAction;
> - }
> -
> - PopupDropperAction *queueAction = new PopupDropperAction( KIcon(
> "media-track-queue-amarok" ), i18n( "Queue Track" ), this );
> - connect( queueAction, SIGNAL( triggered() ), this, SLOT(
> queueSelection() ) );
> -
> - PopupDropperAction *dequeueAction = new PopupDropperAction( KIcon(
> "media-track-queue-amarok" ), i18n( "Dequeue Track" ), this );
> - connect( dequeueAction, SIGNAL( triggered() ), this, SLOT(
> dequeueSelection() ) );
> -
> - const bool isQueued = index.data( Playlist::StateRole ).toInt() &
> Item::Queued;
> - if( isQueued )
> - actions << dequeueAction;
> - else
> - actions << queueAction;
> -
> - PopupDropperAction *stopAction = new PopupDropperAction( KIcon(
> "media-playback-stop-amarok" ), i18n( "Stop Playing After This Track" ),
> this );
> - connect( stopAction, SIGNAL( triggered() ), this, SLOT(
> stopAfterTrack() ) );
> - actions << stopAction;
> -
> - PopupDropperAction *removeAction = new PopupDropperAction( KIcon(
> "media-track-remove-amarok" ), i18n( "Remove From Playlist" ), this );
> - connect( removeAction, SIGNAL( triggered() ), this, SLOT(
> removeSelection() ) );
> - actions << removeAction;
> -
> - PopupDropperAction *editAction = new PopupDropperAction( KIcon(
> "media-track-edit-amarok" ), i18n( "Edit Track Details" ), this );
> - connect( editAction, SIGNAL( triggered() ), this, SLOT(
> editTrackInformation() ) );
> - actions << editAction;
> -
> - //lets see if this is the currently playing tracks, and if it has
> CurrentTrackActionsCapability
> - if( isCurrentTrack )
> - {
> - QList<QAction *> globalCurrentTrackActions =
> The::globalCurrentTrackActions()->actions();
> - foreach( QAction *action, globalCurrentTrackActions )
> - actions << PopupDropperAction::from( action );
> -
> - if ( track->hasCapabilityInterface(
> Meta::Capability::CurrentTrackActions ) )
> - {
> - Meta::CurrentTrackActionsCapability *cac =
> track->as<Meta::CurrentTrackActionsCapability>();
> - if ( cac )
> - {
> - foreach( PopupDropperAction *action, cac->customActions() )
> - actions << action;
> - }
> - }
> - }
> -
> - if ( coverActions )
> - {
> - Meta::AlbumPtr album = track->album();
> - if ( album )
> - {
> - Meta::CustomActionsCapability *cac =
> album->as<Meta::CustomActionsCapability>();
> - if ( cac )
> - {
> - foreach( PopupDropperAction *action, cac->customActions() )
> - actions << action;
> - }
> - }
> - }
> -
> - return actions;
> -}
> -
> QItemSelectionModel::SelectionFlags
> Playlist::PrettyListView::headerPressSelectionCommand( const QModelIndex&
> index, const QMouseEvent* event ) const
> {
> ---
> trunk/extragear/multimedia/amarok/src/playlist/view/listview/PrettyListView.h
> #942127:942128
> @@ -96,9 +96,6 @@
>
> void startProxyUpdateTimeout();
>
> - void trackMenu( QWidget *, const QModelIndex &, const QPoint &pos, bool
> coverActions = false );
> - QList<PopupDropperAction *> actionsFor( const QModelIndex &index, bool
> coverActions );
> -
> QRect m_dropIndicator;
> QPersistentModelIndex m_headerPressIndex;
> bool m_mousePressInHeader;
>
--
Sent from my mobile device
More information about the Amarok-devel
mailing list