mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-03-25 02:09:48 +01:00
sort playlists by date added
allow users to drag tracks onto the New Playlist item to seed a new plsylist
This commit is contained in:
parent
e6c7a73110
commit
062cf35324
@ -21,6 +21,9 @@
|
||||
#include "widgets/newplaylistwidget.h"
|
||||
#include "viewmanager.h"
|
||||
#include "viewpage.h"
|
||||
#include "sourcelist.h"
|
||||
|
||||
#include <QMimeData>
|
||||
|
||||
using namespace Tomahawk;
|
||||
|
||||
@ -89,6 +92,47 @@ CategoryAddItem::icon() const
|
||||
return QIcon( RESPATH "images/add.png" );
|
||||
}
|
||||
|
||||
bool
|
||||
CategoryAddItem::willAcceptDrag( const QMimeData* data ) const
|
||||
{
|
||||
if( m_categoryType == SourcesModel::PlaylistsCategory && data->hasFormat( "application/tomahawk.query.list" ) ) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool
|
||||
CategoryAddItem::dropMimeData( const QMimeData* data, Qt::DropAction action )
|
||||
{
|
||||
// Create a new playlist seeded with these items
|
||||
if( m_categoryType == SourcesModel::PlaylistsCategory && data->hasFormat( "application/tomahawk.query.list" ) ) {
|
||||
QByteArray itemData = data->data( "application/tomahawk.query.list" );
|
||||
QDataStream stream( &itemData, QIODevice::ReadOnly );
|
||||
QList< Tomahawk::query_ptr > queries;
|
||||
|
||||
while ( !stream.atEnd() )
|
||||
{
|
||||
qlonglong qptr;
|
||||
stream >> qptr;
|
||||
|
||||
Tomahawk::query_ptr* query = reinterpret_cast<Tomahawk::query_ptr*>(qptr);
|
||||
if ( query && !query->isNull() )
|
||||
{
|
||||
qDebug() << "Dropped query item:" << query->data()->artist() << "-" << query->data()->track();
|
||||
queries << *query;
|
||||
}
|
||||
}
|
||||
|
||||
playlist_ptr newpl = Playlist::create( SourceList::instance()->getLocal(), uuid(), "New Playlist", "", SourceList::instance()->getLocal()->friendlyName(), false );
|
||||
newpl->addEntries( queries, newpl->currentrevision() );
|
||||
ViewManager::instance()->show( newpl );
|
||||
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/// CategoryItem
|
||||
|
||||
CategoryItem::CategoryItem( SourcesModel* model, SourceTreeItem* parent, SourcesModel::CategoryType category, bool showAddItem )
|
||||
|
@ -31,6 +31,10 @@ public:
|
||||
virtual void activate();
|
||||
virtual QIcon icon() const;
|
||||
|
||||
virtual bool willAcceptDrag(const QMimeData* data) const;
|
||||
virtual bool dropMimeData(const QMimeData* data, Qt::DropAction action);
|
||||
|
||||
|
||||
private:
|
||||
SourcesModel::CategoryType m_categoryType;
|
||||
};
|
||||
|
@ -89,6 +89,18 @@ CollectionItem::text() const
|
||||
return m_source.isNull() ? tr( "Super Collection" ) : m_source->friendlyName();
|
||||
}
|
||||
|
||||
int
|
||||
CollectionItem::peerSortValue() const
|
||||
{
|
||||
if( m_source.isNull() )
|
||||
return -1;
|
||||
if( m_source->isLocal() )
|
||||
return 0;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
CollectionItem::activate()
|
||||
{
|
||||
|
@ -30,6 +30,7 @@ public:
|
||||
virtual QString text() const;
|
||||
virtual void activate();
|
||||
virtual QIcon icon() const;
|
||||
virtual int peerSortValue() const;
|
||||
|
||||
Tomahawk::source_ptr source() const;
|
||||
|
||||
|
@ -66,6 +66,13 @@ PlaylistItem::onPlaylistChanged()
|
||||
emit updated();
|
||||
}
|
||||
|
||||
int
|
||||
PlaylistItem::peerSortValue() const
|
||||
{
|
||||
return m_playlist->createdOn();
|
||||
}
|
||||
|
||||
|
||||
Qt::ItemFlags
|
||||
PlaylistItem::flags() const
|
||||
{
|
||||
@ -187,6 +194,13 @@ DynamicPlaylistItem::onDynamicPlaylistLoaded( DynamicPlaylistRevision revision )
|
||||
emit updated();
|
||||
}
|
||||
|
||||
int
|
||||
DynamicPlaylistItem::peerSortValue() const
|
||||
{
|
||||
return m_dynplaylist->createdOn();
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
DynamicPlaylistItem::checkReparentHackNeeded( const DynamicPlaylistRevision& revision )
|
||||
{
|
||||
|
@ -34,6 +34,7 @@ public:
|
||||
virtual bool dropMimeData( const QMimeData* data, Qt::DropAction action );
|
||||
virtual QIcon icon() const;
|
||||
virtual bool setData(const QVariant& v, bool role);
|
||||
virtual int peerSortValue() const;
|
||||
|
||||
protected:
|
||||
void setLoaded( bool loaded );
|
||||
@ -59,6 +60,7 @@ public:
|
||||
Tomahawk::dynplaylist_ptr dynPlaylist() const;
|
||||
virtual bool willAcceptDrag( const QMimeData* data ) const;
|
||||
virtual void activate();
|
||||
virtual int peerSortValue() const;
|
||||
|
||||
private slots:
|
||||
void onDynamicPlaylistLoaded( Tomahawk::DynamicPlaylistRevision revision );
|
||||
|
@ -52,6 +52,7 @@ public:
|
||||
virtual bool willAcceptDrag( const QMimeData* data ) const { return false; }
|
||||
virtual bool dropMimeData( const QMimeData* data, Qt::DropAction action ) { return false; }
|
||||
virtual bool setData( const QVariant& v, bool role ) { return false; }
|
||||
virtual int peerSortValue() const { return 0; } // How to sort relative to peers in the tree.
|
||||
|
||||
/// don't call me unless you are a sourcetreeitem. i prefer this to making everyone a friend
|
||||
void beginRowsAdded( int from, int to ) { emit beginChildRowsAdded( from, to ); }
|
||||
|
@ -77,6 +77,8 @@ SourcesModel::data( const QModelIndex& index, int role ) const
|
||||
return itemFromIndex( index )->text();
|
||||
case Qt::DecorationRole:
|
||||
return itemFromIndex( index )->icon();
|
||||
case SourcesModel::SortRole:
|
||||
return itemFromIndex( index )->peerSortValue();
|
||||
}
|
||||
return QVariant();
|
||||
}
|
||||
|
@ -59,10 +59,12 @@ public:
|
||||
};
|
||||
|
||||
enum Roles {
|
||||
SourceTreeItemRole = Qt::UserRole + 10,
|
||||
SourceTreeItemTypeRole = Qt::UserRole + 11
|
||||
SourceTreeItemRole = Qt::UserRole + 10,
|
||||
SourceTreeItemTypeRole = Qt::UserRole + 11,
|
||||
SortRole = Qt::UserRole + 12
|
||||
};
|
||||
|
||||
|
||||
SourcesModel( QObject* parent = 0 );
|
||||
virtual ~SourcesModel();
|
||||
|
||||
|
@ -31,7 +31,7 @@ SourcesProxyModel::SourcesProxyModel( SourcesModel* model, QObject* parent )
|
||||
, m_filtered( false )
|
||||
{
|
||||
setDynamicSortFilter( true );
|
||||
// setSortRole( SourcesModel::SortRole );
|
||||
setSortRole( SourcesModel::SortRole );
|
||||
|
||||
setSourceModel( model );
|
||||
|
||||
|
@ -78,9 +78,8 @@ SourceTreeView::SourceTreeView( QWidget* parent )
|
||||
setAllColumnsShowFocus( true );
|
||||
setUniformRowHeights( false );
|
||||
setIndentation( 16 );
|
||||
|
||||
// setSortingEnabled( true );
|
||||
// sortByColumn( 1, Qt::AscendingOrder );
|
||||
setSortingEnabled( true );
|
||||
sortByColumn( 1, Qt::AscendingOrder );
|
||||
|
||||
// TODO animation conflicts with the expanding-playlists-when-collection-is-null
|
||||
// so investigate
|
||||
|
Loading…
x
Reference in New Issue
Block a user