extragear/multimedia/amarok/src
Bart Cerneels
bart.cerneels at kde.org
Sun Jan 25 09:41:04 CET 2009
SVN commit 916367 by shanachie:
Move the selected index saving to PodcastModel as it's cleaner.
This still doesn't make the actions defined in SqlPodcastProvider work though. PodcastModel::selectedEpisodes() returns something else if it's called from PodcastModel itself or from SqlPodcastProvider, almost like there are 2 PodcastModel instances!
Like I promised before: cookies and eternal praise for who can solve this.
CCMAIL:amarok-devel at kde.org
M +2 -18 browsers/playlistbrowser/PodcastCategory.cpp
M +0 -2 browsers/playlistbrowser/PodcastCategory.h
M +91 -110 browsers/playlistbrowser/PodcastModel.cpp
M +7 -2 browsers/playlistbrowser/PodcastModel.h
M +1 -0 podcasts/sql/SqlPodcastProvider.cpp
--- trunk/extragear/multimedia/amarok/src/browsers/playlistbrowser/PodcastCategory.cpp #916366:916367
@@ -152,21 +152,6 @@
{
}
-QModelIndexList
-PodcastCategory::currentItems() const
-{
- DEBUG_BLOCK
- if( m_podcastTreeView )
- {
- debug() << m_podcastTreeView->currentItems().count() << " selectedIndexes";
- return m_podcastTreeView->currentItems();
- }
- else
- debug() << "m_podcastTreeView is null";
-
- return QModelIndexList();
-}
-
void
PodcastCategory::showInfo( const QModelIndex & index )
{
@@ -389,7 +374,7 @@
if( m_pd && m_pd->isHidden() )
{
- QList<PopupDropperAction*> actions = m_podcastModel->actionsFor( currentItems() );
+ QList<PopupDropperAction*> actions = m_podcastModel->actionsFor( selectedIndexes() );
foreach( PopupDropperAction * action, actions )
{
@@ -417,8 +402,7 @@
DEBUG_BLOCK
KMenu menu;
- QModelIndexList indices = currentItems();
- debug() << indices.count() << " selectedIndexes";
+ QModelIndexList indices = selectedIndexes();
QList<PopupDropperAction *> actions =
m_podcastModel->actionsFor( indices );
--- trunk/extragear/multimedia/amarok/src/browsers/playlistbrowser/PodcastCategory.h #916366:916367
@@ -50,7 +50,6 @@
public:
static PodcastCategory *instance();
static void destroy();
- QModelIndexList currentItems() const;
private:
static PodcastCategory* s_instance;
@@ -91,7 +90,6 @@
public:
explicit PodcastView( PodcastModel *model, QWidget *parent = 0 );
~PodcastView();
- QModelIndexList currentItems() const { return selectionModel()->selectedIndexes(); }
protected:
void mousePressEvent( QMouseEvent *event );
--- trunk/extragear/multimedia/amarok/src/browsers/playlistbrowser/PodcastModel.cpp #916366:916367
@@ -535,109 +535,6 @@
}
}
-QList<PopupDropperAction *>
-PlaylistBrowserNS::PodcastModel::actionsFor( const QModelIndexList &indices )
-{
- DEBUG_BLOCK
- QList<PopupDropperAction *> actions;
- Meta::PodcastEpisodeList episodes;
- Meta::PodcastChannelList channels;
-
- if( indices.isEmpty() )
- return actions;
-
- foreach( const QModelIndex &index, indices )
- {
- if( index.isValid() && index.internalPointer() )
- {
- Meta::PodcastMetaCommon *pmc =
- static_cast<Meta::PodcastMetaCommon *>(index.internalPointer());
-
- switch( pmc->podcastType() )
- {
- case Meta::EpisodeType:
- {
- episodes << Meta::PodcastEpisodePtr(
- dynamic_cast<Meta::PodcastEpisode *>(pmc) );
- break;
- }
- case Meta::ChannelType:
- {
- channels << Meta::PodcastChannelPtr(
- dynamic_cast<Meta::PodcastChannel *>(pmc) );
- break;
- }
- }
- }
- }
-
- actions << createCommonActions( indices );
-
- //HACK: since we only have one PodcastProvider implementation
- PodcastProvider *provider = The::playlistManager()->defaultPodcasts();
- if( provider )
- {
- if( !episodes.isEmpty() )
- actions << provider->episodeActions( episodes );
- if( !channels.isEmpty() )
- actions << provider->channelActions( channels );
- }
-
- return actions;
-}
-
-QList< PopupDropperAction * >
-PlaylistBrowserNS::PodcastModel::createCommonActions( QModelIndexList indices )
-{
- Q_UNUSED( indices )
- QList< PopupDropperAction * > actions;
-
- if( m_appendAction == 0 )
- {
- m_appendAction = new PopupDropperAction(
- The::svgHandler()->getRenderer( "amarok/images/pud_items.svg" ),
- "append",
- KIcon( "media-track-add-amarok" ),
- i18n( "&Append to Playlist" ),
- this
- );
- connect( m_appendAction, SIGNAL( triggered() ), this, SLOT( slotAppend() ) );
- }
-
- if( m_loadAction == 0 )
- {
- m_loadAction = new PopupDropperAction(
- The::svgHandler()->getRenderer( "amarok/images/pud_items.svg" ),
- "load",
- KIcon( "folder-open" ),
- i18nc( "Replace the currently loaded tracks with these",
- "&Load" ),
- this
- );
- connect( m_loadAction, SIGNAL( triggered() ), this, SLOT( slotLoad() ) );
- }
-
- /*TODO: rename episodes
- if( m_renameAction == 0 )
- {
- m_renameAction = new PopupDropperAction(
- The::svgHandler()->getRenderer( "amarok/images/pud_items.svg" ),
- "edit",
- KIcon( "media-track-edit-amarok" ),
- i18n( "&Rename" ),
- this
- );
- connect( m_renameAction, SIGNAL( triggered() ), this, SLOT( slotRename() ) );
- }
- */
-
- actions << m_appendAction;
- actions << m_loadAction;
-// actions << m_renameAction;
-
- return actions;
-}
-
void
PlaylistBrowserNS::PodcastModel::deleteItems( QModelIndexList list )
{
@@ -741,12 +638,95 @@
emit( layoutChanged() );
}
+QList<PopupDropperAction *>
+PlaylistBrowserNS::PodcastModel::actionsFor( const QModelIndexList &indices )
+{
+ DEBUG_BLOCK
+ QList<PopupDropperAction *> actions;
+
+ m_selectedEpisodes.clear();
+ m_selectedChannels.clear();
+ m_selectedEpisodes << selectedEpisodes( indices );
+ debug() << m_selectedEpisodes.count() << " episodes selected";
+ m_selectedChannels << selectedChannels( indices );
+
+ if( indices.isEmpty() )
+ return actions;
+
+ actions << createCommonActions( indices );
+
+ //HACK: since we only have one PodcastProvider implementation
+ PodcastProvider *provider = The::playlistManager()->defaultPodcasts();
+ if( provider )
+ {
+ if( !m_selectedEpisodes.isEmpty() )
+ actions << provider->episodeActions( m_selectedEpisodes );
+ if( !m_selectedChannels.isEmpty() )
+ actions << provider->channelActions( m_selectedChannels );
+ }
+
+ return actions;
+}
+
+QList< PopupDropperAction * >
+PlaylistBrowserNS::PodcastModel::createCommonActions( QModelIndexList indices )
+{
+ Q_UNUSED( indices )
+ QList< PopupDropperAction * > actions;
+
+ if( m_appendAction == 0 )
+ {
+ m_appendAction = new PopupDropperAction(
+ The::svgHandler()->getRenderer( "amarok/images/pud_items.svg" ),
+ "append",
+ KIcon( "media-track-add-amarok" ),
+ i18n( "&Append to Playlist" ),
+ this
+ );
+ connect( m_appendAction, SIGNAL( triggered() ), this, SLOT( slotAppend() ) );
+ }
+
+ if( m_loadAction == 0 )
+ {
+ m_loadAction = new PopupDropperAction(
+ The::svgHandler()->getRenderer( "amarok/images/pud_items.svg" ),
+ "load",
+ KIcon( "folder-open" ),
+ i18nc( "Replace the currently loaded tracks with these",
+ "&Load" ),
+ this
+ );
+ connect( m_loadAction, SIGNAL( triggered() ), this, SLOT( slotLoad() ) );
+ }
+
+ /*TODO: rename episodes
+ if( m_renameAction == 0 )
+ {
+ m_renameAction = new PopupDropperAction(
+ The::svgHandler()->getRenderer( "amarok/images/pud_items.svg" ),
+ "edit",
+ KIcon( "media-track-edit-amarok" ),
+ i18n( "&Rename" ),
+ this
+ );
+ connect( m_renameAction, SIGNAL( triggered() ), this, SLOT( slotRename() ) );
+ }
+ */
+
+ actions << m_appendAction;
+ actions << m_loadAction;
+// actions << m_renameAction;
+
+ return actions;
+}
+
Meta::PodcastChannelList
-PlaylistBrowserNS::PodcastModel::selectedChannels()
+PlaylistBrowserNS::PodcastModel::selectedChannels( const QModelIndexList &indices )
{
Meta::PodcastChannelList channels;
- Meta::PodcastMetaCommon *pmc;
- foreach( const QModelIndex &index, The::podcastCategory()->currentItems() )
+ Meta::PodcastMetaCommon *pmc = 0;
+ debug() << indices.count() << " indices selected";
+ foreach( const QModelIndex &index, indices )
{
if( !index.isValid() )
break;
@@ -768,13 +748,13 @@
}
Meta::PodcastEpisodeList
-PlaylistBrowserNS::PodcastModel::selectedEpisodes()
+PlaylistBrowserNS::PodcastModel::selectedEpisodes( const QModelIndexList &indices )
{
DEBUG_BLOCK
Meta::PodcastEpisodeList episodes;
- Meta::PodcastMetaCommon *pmc;
- debug() << The::podcastCategory()->currentItems().count() << " items selected";
- foreach( const QModelIndex &index, The::podcastCategory()->currentItems() )
+ Meta::PodcastMetaCommon *pmc = 0;
+ debug() << indices.count() << " indices selected";
+ foreach( const QModelIndex &index, indices )
{
if( !index.isValid() )
break;
@@ -812,6 +792,7 @@
DEBUG_BLOCK
Meta::PodcastEpisodeList episodes = selectedEpisodes();
+ debug() << episodes.count() << " selectedEpisodes";
if( !episodes.empty() )
{
--- trunk/extragear/multimedia/amarok/src/browsers/playlistbrowser/PodcastModel.h #916366:916367
@@ -25,6 +25,7 @@
#include <QAbstractItemModel>
#include <QModelIndex>
+#include <QPersistentModelIndex>
#include <QVariant>
class PopupDropperAction;
@@ -74,12 +75,12 @@
/** @returns all channels currently selected
**/
- Meta::PodcastChannelList selectedChannels();
+ Meta::PodcastChannelList selectedChannels() { return m_selectedChannels; }
/** @returns all episodes currently selected, this includes children of a selected
* channel
**/
- Meta::PodcastEpisodeList selectedEpisodes();
+ Meta::PodcastEpisodeList selectedEpisodes() { return m_selectedEpisodes; }
public slots:
void slotUpdate();
@@ -99,9 +100,13 @@
Q_DISABLE_COPY( PodcastModel )
+ Meta::PodcastChannelList selectedChannels( const QModelIndexList &indices );
+ Meta::PodcastEpisodeList selectedEpisodes( const QModelIndexList &indices );
QList<PopupDropperAction *> createCommonActions( QModelIndexList indices );
PopupDropperAction * m_appendAction;
PopupDropperAction * m_loadAction;
+ Meta::PodcastEpisodeList m_selectedEpisodes;
+ Meta::PodcastChannelList m_selectedChannels;
/** A convenience function to convert a PodcastEpisodeList into a TrackList.
**/
--- trunk/extragear/multimedia/amarok/src/podcasts/sql/SqlPodcastProvider.cpp #916366:916367
@@ -403,6 +403,7 @@
{
DEBUG_BLOCK
Meta::PodcastEpisodeList episodes = The::podcastModel()->selectedEpisodes();
+ debug() << episodes.count() << " episodes selected";
foreach( Meta::PodcastEpisodePtr episode, episodes )
{
Meta::SqlPodcastEpisodePtr sqlEpisode =
More information about the Amarok-devel
mailing list