1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-08-12 17:14:00 +02:00

* PlaylistItems don't need to worry about playlists being loaded anymore.

This commit is contained in:
Christian Muehlhaeuser
2013-04-26 03:12:59 +02:00
parent efb00795e5
commit f024fb5fc8
2 changed files with 75 additions and 62 deletions

View File

@@ -1,20 +1,20 @@
/* /* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
* *
* Copyright 2010-2012, Leo Franchi <lfranchi@kde.org> * Copyright 2010-2012, Leo Franchi <lfranchi@kde.org>
* Copyright 2010-2013, Christian Muehlhaeuser <muesli@tomahawk-player.org>
* *
* This program is free software; you can redistribute it and/or modify * Tomahawk is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or * the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version. * (at your option) any later version.
* *
* This program is distributed in the hope that it will be useful, * Tomahawk is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License along * You should have received a copy of the GNU General Public License
* with this program; if not, write to the Free Software Foundation, Inc., * along with Tomahawk. If not, see <http://www.gnu.org/licenses/>.
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/ */
#include "PlaylistItems.h" #include "PlaylistItems.h"
@@ -39,7 +39,6 @@ using namespace Tomahawk;
PlaylistItem::PlaylistItem( SourcesModel* mdl, SourceTreeItem* parent, const playlist_ptr& pl, int index ) PlaylistItem::PlaylistItem( SourcesModel* mdl, SourceTreeItem* parent, const playlist_ptr& pl, int index )
: SourceTreeItem( mdl, parent, SourcesModel::StaticPlaylist, index ) : SourceTreeItem( mdl, parent, SourcesModel::StaticPlaylist, index )
, m_loaded( false )
, m_canSubscribe( false ) , m_canSubscribe( false )
, m_showSubscribed( false ) , m_showSubscribed( false )
, m_playlist( pl ) , m_playlist( pl )
@@ -76,7 +75,6 @@ PlaylistItem::onPlaylistLoaded( Tomahawk::PlaylistRevision revision )
{ {
Q_UNUSED( revision ); Q_UNUSED( revision );
m_loaded = true;
emit updated(); emit updated();
} }
@@ -123,8 +121,8 @@ PlaylistItem::flags() const
Qt::ItemFlags flags = SourceTreeItem::flags(); Qt::ItemFlags flags = SourceTreeItem::flags();
flags |= Qt::ItemIsDragEnabled | Qt::ItemIsDropEnabled; flags |= Qt::ItemIsDragEnabled | Qt::ItemIsDropEnabled;
if ( !m_loaded ) /* if ( !playlist()->loaded() )
flags &= !Qt::ItemIsEnabled; flags &= !Qt::ItemIsEnabled;*/
if ( playlist()->author()->isLocal() ) if ( playlist()->author()->isLocal() )
flags |= Qt::ItemIsEditable; flags |= Qt::ItemIsEditable;
@@ -158,20 +156,16 @@ PlaylistItem::doubleClicked()
} }
void
PlaylistItem::setLoaded( bool loaded )
{
m_loaded = loaded;
}
bool bool
PlaylistItem::willAcceptDrag( const QMimeData* data ) const PlaylistItem::willAcceptDrag( const QMimeData* data ) const
{ {
Q_UNUSED( data ); return m_playlist
return !m_playlist.isNull() && m_playlist->author()->isLocal() && DropJob::acceptsMimeData( data, DropJob::Track ) && !m_playlist->busy(); && !m_playlist->busy()
&& m_playlist->author()->isLocal()
&& DropJob::acceptsMimeData( data, DropJob::Track );
} }
PlaylistItem::DropTypes PlaylistItem::DropTypes
PlaylistItem::supportedDropTypes( const QMimeData* data ) const PlaylistItem::supportedDropTypes( const QMimeData* data ) const
{ {
@@ -231,7 +225,10 @@ PlaylistItem::dropMimeData( const QMimeData* data, Qt::DropAction action )
if ( data->hasFormat( "application/tomahawk.playlist.id" ) && if ( data->hasFormat( "application/tomahawk.playlist.id" ) &&
data->data( "application/tomahawk.playlist.id" ) == m_playlist->guid() ) data->data( "application/tomahawk.playlist.id" ) == m_playlist->guid() )
return false; // don't allow dropping on ourselves {
// don't allow dropping on ourselves
return false;
}
if ( !DropJob::acceptsMimeData( data, DropJob::Track ) ) if ( !DropJob::acceptsMimeData( data, DropJob::Track ) )
return false; return false;
@@ -240,7 +237,8 @@ PlaylistItem::dropMimeData( const QMimeData* data, Qt::DropAction action )
dj->setDropTypes( DropJob::Track ); dj->setDropTypes( DropJob::Track );
dj->setDropAction( DropJob::Append ); dj->setDropAction( DropJob::Append );
connect( dj, SIGNAL( tracks( QList< Tomahawk::query_ptr > ) ), this, SLOT( parsedDroppedTracks( QList< Tomahawk::query_ptr > ) ) ); connect( dj, SIGNAL( tracks( QList< Tomahawk::query_ptr > ) ),
SLOT( parsedDroppedTracks( QList< Tomahawk::query_ptr > ) ) );
if ( dropType() == DropTypeAllFromArtist ) if ( dropType() == DropTypeAllFromArtist )
dj->setGetWholeArtists( true ); dj->setGetWholeArtists( true );
@@ -268,13 +266,14 @@ PlaylistItem::dropMimeData( const QMimeData* data, Qt::DropAction action )
void void
PlaylistItem::parsedDroppedTracks( const QList< query_ptr >& tracks ) PlaylistItem::parsedDroppedTracks( const QList< query_ptr >& tracks )
{ {
qDebug() << "adding" << tracks.count() << "tracks"; if ( tracks.count() && m_playlist && m_playlist->author()->isLocal() )
if ( tracks.count() && !m_playlist.isNull() && m_playlist->author()->isLocal() )
{ {
qDebug() << "on playlist:" << m_playlist->title() << m_playlist->guid() << m_playlist->currentrevision(); tDebug( LOGVERBOSE ) << Q_FUNC_INFO << "Adding" << tracks.count() << "tracks on playlist:" << m_playlist->title() << m_playlist->guid() << m_playlist->currentrevision();
m_playlist->addEntries( tracks, m_playlist->currentrevision() ); m_playlist->addEntries( tracks, m_playlist->currentrevision() );
} }
else
tDebug() << "ERROR: Could not add" << tracks.count() << "to playlist!";
} }
@@ -285,10 +284,10 @@ PlaylistItem::onUpdated()
if ( !newOverlay && !m_overlaidIcon.isNull() ) if ( !newOverlay && !m_overlaidIcon.isNull() )
m_overlaidIcon = QIcon(); m_overlaidIcon = QIcon();
emit updated(); emit updated();
} }
bool bool
PlaylistItem::collaborative() const PlaylistItem::collaborative() const
{ {
@@ -301,10 +300,10 @@ PlaylistItem::collaborative() const
foreach ( PlaylistUpdaterInterface* updater, m_playlist->updaters() ) foreach ( PlaylistUpdaterInterface* updater, m_playlist->updaters() )
{ {
if( !updater->collaborative() ) if ( !updater->collaborative() )
continue; continue;
/// @note: We only care for collaborations if in sync /// @note: We only care for collaborations if in sync
if( !updater->sync() ) if ( !updater->sync() )
continue; continue;
collaborative = updater->collaborative(); collaborative = updater->collaborative();
} }
@@ -370,7 +369,6 @@ PlaylistItem::createOverlay()
overlayRect.moveLeft( 0 ); overlayRect.moveLeft( 0 );
} }
p.end(); p.end();
m_overlaidIcon.addPixmap( base ); m_overlaidIcon.addPixmap( base );
@@ -403,10 +401,11 @@ PlaylistItem::setData( const QVariant& v, bool role )
return false; return false;
} }
SourceTreeItem* SourceTreeItem*
PlaylistItem::activateCurrent() PlaylistItem::activateCurrent()
{ {
if( ViewManager::instance()->pageForPlaylist( m_playlist ) == ViewManager::instance()->currentPage() ) if ( ViewManager::instance()->pageForPlaylist( m_playlist ) == ViewManager::instance()->currentPage() )
{ {
model()->linkSourceItemToPage( this, ViewManager::instance()->currentPage() ); model()->linkSourceItemToPage( this, ViewManager::instance()->currentPage() );
emit selectRequest( this ); emit selectRequest( this );
@@ -469,7 +468,6 @@ DynamicPlaylistItem::activate()
void void
DynamicPlaylistItem::onDynamicPlaylistLoaded( DynamicPlaylistRevision revision ) DynamicPlaylistItem::onDynamicPlaylistLoaded( DynamicPlaylistRevision revision )
{ {
setLoaded( true );
checkReparentHackNeeded( revision ); checkReparentHackNeeded( revision );
// END HACK // END HACK
emit updated(); emit updated();
@@ -499,15 +497,20 @@ DynamicPlaylistItem::checkReparentHackNeeded( const DynamicPlaylistRevision& rev
CategoryItem* cat = qobject_cast< CategoryItem* >( parent() ); CategoryItem* cat = qobject_cast< CategoryItem* >( parent() );
// qDebug() << "with category" << cat; // qDebug() << "with category" << cat;
// if( cat ) qDebug() << "and cat type:" << cat->categoryType(); // if ( cat ) qDebug() << "and cat type:" << cat->categoryType();
if( cat )
if ( cat )
{ {
CategoryItem* from = cat; CategoryItem* from = cat;
CategoryItem* to = 0; CategoryItem* to = 0;
if( cat->categoryType() == SourcesModel::PlaylistsCategory && revision.mode == OnDemand ) { // WRONG if ( cat->categoryType() == SourcesModel::PlaylistsCategory && revision.mode == OnDemand )
{
// WRONG
SourceItem* col = qobject_cast< SourceItem* >( cat->parent() ); SourceItem* col = qobject_cast< SourceItem* >( cat->parent() );
to = col->stationsCategory(); to = col->stationsCategory();
if( !to ) { // you have got to be fucking kidding me if ( !to )
{
// you have got to be fucking kidding me
int fme = col->children().count(); int fme = col->children().count();
col->beginRowsAdded( fme, fme ); col->beginRowsAdded( fme, fme );
to = new CategoryItem( model(), col, SourcesModel::StationsCategory, false ); to = new CategoryItem( model(), col, SourcesModel::StationsCategory, false );
@@ -515,11 +518,17 @@ DynamicPlaylistItem::checkReparentHackNeeded( const DynamicPlaylistRevision& rev
col->endRowsAdded(); col->endRowsAdded();
col->setStationsCategory( to ); col->setStationsCategory( to );
} }
} else if( cat->categoryType() == SourcesModel::StationsCategory && revision.mode == Static ) { // WRONG }
else if ( cat->categoryType() == SourcesModel::StationsCategory && revision.mode == Static )
{
// WRONG
SourceItem* col = qobject_cast< SourceItem* >( cat->parent() ); SourceItem* col = qobject_cast< SourceItem* >( cat->parent() );
to = col->playlistsCategory(); to = col->playlistsCategory();
// qDebug() << "TRYING TO HACK TO:" << to; // qDebug() << "TRYING TO HACK TO:" << to;
if( !to ) { // you have got to be fucking kidding me
if ( !to )
{
// you have got to be fucking kidding me
int fme = col->children().count(); int fme = col->children().count();
col->beginRowsAdded( fme, fme ); col->beginRowsAdded( fme, fme );
to = new CategoryItem( model(), col, SourcesModel::PlaylistsCategory, false ); to = new CategoryItem( model(), col, SourcesModel::PlaylistsCategory, false );
@@ -528,7 +537,8 @@ DynamicPlaylistItem::checkReparentHackNeeded( const DynamicPlaylistRevision& rev
col->setPlaylistsCategory( to ); col->setPlaylistsCategory( to );
} }
} }
if( to ) { if ( to )
{
// qDebug() << "HACKING! moving dynamic playlist from" << from->text() << "to:" << to->text(); // qDebug() << "HACKING! moving dynamic playlist from" << from->text() << "to:" << to->text();
// remove and add // remove and add
int idx = from->children().indexOf( this ); int idx = from->children().indexOf( this );
@@ -582,10 +592,11 @@ DynamicPlaylistItem::icon() const
} }
} }
SourceTreeItem* SourceTreeItem*
DynamicPlaylistItem::activateCurrent() DynamicPlaylistItem::activateCurrent()
{ {
if( ViewManager::instance()->pageForDynPlaylist( m_dynplaylist ) == ViewManager::instance()->currentPage() ) if ( ViewManager::instance()->pageForDynPlaylist( m_dynplaylist ) == ViewManager::instance()->currentPage() )
{ {
model()->linkSourceItemToPage( this, ViewManager::instance()->currentPage() ); model()->linkSourceItemToPage( this, ViewManager::instance()->currentPage() );
emit selectRequest( this ); emit selectRequest( this );
@@ -596,6 +607,7 @@ DynamicPlaylistItem::activateCurrent()
return 0; return 0;
} }
bool bool
DynamicPlaylistItem::isBeingPlayed() const DynamicPlaylistItem::isBeingPlayed() const
{ {

View File

@@ -1,19 +1,20 @@
/* /* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
* Copyright 2010-2012, Leo Franchi <lfranchi@kde.org>
* *
* This program is free software; you can redistribute it and/or modify * Copyright 2010-2012, Leo Franchi <lfranchi@kde.org>
* Copyright 2010-2013, Christian Muehlhaeuser <muesli@tomahawk-player.org>
*
* Tomahawk is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or * the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version. * (at your option) any later version.
* *
* This program is distributed in the hope that it will be useful, * Tomahawk is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License along * You should have received a copy of the GNU General Public License
* with this program; if not, write to the Free Software Foundation, Inc., * along with Tomahawk. If not, see <http://www.gnu.org/licenses/>.
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/ */
#ifndef PLAYLIST_ITEM_H #ifndef PLAYLIST_ITEM_H
@@ -65,7 +66,7 @@ private slots:
private: private:
bool createOverlay(); bool createOverlay();
bool m_loaded, m_canSubscribe, m_showSubscribed; bool m_canSubscribe, m_showSubscribed;
Tomahawk::playlist_ptr m_playlist; Tomahawk::playlist_ptr m_playlist;
QIcon m_overlaidIcon; QIcon m_overlaidIcon;
QPixmap m_subscribedOnIcon, m_subscribedOffIcon; QPixmap m_subscribedOnIcon, m_subscribedOffIcon;