mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-07-31 11:20:22 +02: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:
@@ -21,6 +21,9 @@
|
|||||||
#include "widgets/newplaylistwidget.h"
|
#include "widgets/newplaylistwidget.h"
|
||||||
#include "viewmanager.h"
|
#include "viewmanager.h"
|
||||||
#include "viewpage.h"
|
#include "viewpage.h"
|
||||||
|
#include "sourcelist.h"
|
||||||
|
|
||||||
|
#include <QMimeData>
|
||||||
|
|
||||||
using namespace Tomahawk;
|
using namespace Tomahawk;
|
||||||
|
|
||||||
@@ -89,6 +92,47 @@ CategoryAddItem::icon() const
|
|||||||
return QIcon( RESPATH "images/add.png" );
|
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::CategoryItem( SourcesModel* model, SourceTreeItem* parent, SourcesModel::CategoryType category, bool showAddItem )
|
CategoryItem::CategoryItem( SourcesModel* model, SourceTreeItem* parent, SourcesModel::CategoryType category, bool showAddItem )
|
||||||
|
@@ -31,6 +31,10 @@ public:
|
|||||||
virtual void activate();
|
virtual void activate();
|
||||||
virtual QIcon icon() const;
|
virtual QIcon icon() const;
|
||||||
|
|
||||||
|
virtual bool willAcceptDrag(const QMimeData* data) const;
|
||||||
|
virtual bool dropMimeData(const QMimeData* data, Qt::DropAction action);
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
SourcesModel::CategoryType m_categoryType;
|
SourcesModel::CategoryType m_categoryType;
|
||||||
};
|
};
|
||||||
|
@@ -89,6 +89,18 @@ CollectionItem::text() const
|
|||||||
return m_source.isNull() ? tr( "Super Collection" ) : m_source->friendlyName();
|
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
|
void
|
||||||
CollectionItem::activate()
|
CollectionItem::activate()
|
||||||
{
|
{
|
||||||
|
@@ -30,6 +30,7 @@ public:
|
|||||||
virtual QString text() const;
|
virtual QString text() const;
|
||||||
virtual void activate();
|
virtual void activate();
|
||||||
virtual QIcon icon() const;
|
virtual QIcon icon() const;
|
||||||
|
virtual int peerSortValue() const;
|
||||||
|
|
||||||
Tomahawk::source_ptr source() const;
|
Tomahawk::source_ptr source() const;
|
||||||
|
|
||||||
|
@@ -66,6 +66,13 @@ PlaylistItem::onPlaylistChanged()
|
|||||||
emit updated();
|
emit updated();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
PlaylistItem::peerSortValue() const
|
||||||
|
{
|
||||||
|
return m_playlist->createdOn();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
Qt::ItemFlags
|
Qt::ItemFlags
|
||||||
PlaylistItem::flags() const
|
PlaylistItem::flags() const
|
||||||
{
|
{
|
||||||
@@ -187,6 +194,13 @@ DynamicPlaylistItem::onDynamicPlaylistLoaded( DynamicPlaylistRevision revision )
|
|||||||
emit updated();
|
emit updated();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
DynamicPlaylistItem::peerSortValue() const
|
||||||
|
{
|
||||||
|
return m_dynplaylist->createdOn();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
DynamicPlaylistItem::checkReparentHackNeeded( const DynamicPlaylistRevision& revision )
|
DynamicPlaylistItem::checkReparentHackNeeded( const DynamicPlaylistRevision& revision )
|
||||||
{
|
{
|
||||||
|
@@ -34,6 +34,7 @@ public:
|
|||||||
virtual bool dropMimeData( const QMimeData* data, Qt::DropAction action );
|
virtual bool dropMimeData( const QMimeData* data, Qt::DropAction action );
|
||||||
virtual QIcon icon() const;
|
virtual QIcon icon() const;
|
||||||
virtual bool setData(const QVariant& v, bool role);
|
virtual bool setData(const QVariant& v, bool role);
|
||||||
|
virtual int peerSortValue() const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void setLoaded( bool loaded );
|
void setLoaded( bool loaded );
|
||||||
@@ -59,6 +60,7 @@ public:
|
|||||||
Tomahawk::dynplaylist_ptr dynPlaylist() const;
|
Tomahawk::dynplaylist_ptr dynPlaylist() const;
|
||||||
virtual bool willAcceptDrag( const QMimeData* data ) const;
|
virtual bool willAcceptDrag( const QMimeData* data ) const;
|
||||||
virtual void activate();
|
virtual void activate();
|
||||||
|
virtual int peerSortValue() const;
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void onDynamicPlaylistLoaded( Tomahawk::DynamicPlaylistRevision revision );
|
void onDynamicPlaylistLoaded( Tomahawk::DynamicPlaylistRevision revision );
|
||||||
|
@@ -52,6 +52,7 @@ public:
|
|||||||
virtual bool willAcceptDrag( const QMimeData* data ) const { return false; }
|
virtual bool willAcceptDrag( const QMimeData* data ) const { return false; }
|
||||||
virtual bool dropMimeData( const QMimeData* data, Qt::DropAction action ) { return false; }
|
virtual bool dropMimeData( const QMimeData* data, Qt::DropAction action ) { return false; }
|
||||||
virtual bool setData( const QVariant& v, bool role ) { 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
|
/// 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 ); }
|
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();
|
return itemFromIndex( index )->text();
|
||||||
case Qt::DecorationRole:
|
case Qt::DecorationRole:
|
||||||
return itemFromIndex( index )->icon();
|
return itemFromIndex( index )->icon();
|
||||||
|
case SourcesModel::SortRole:
|
||||||
|
return itemFromIndex( index )->peerSortValue();
|
||||||
}
|
}
|
||||||
return QVariant();
|
return QVariant();
|
||||||
}
|
}
|
||||||
|
@@ -59,10 +59,12 @@ public:
|
|||||||
};
|
};
|
||||||
|
|
||||||
enum Roles {
|
enum Roles {
|
||||||
SourceTreeItemRole = Qt::UserRole + 10,
|
SourceTreeItemRole = Qt::UserRole + 10,
|
||||||
SourceTreeItemTypeRole = Qt::UserRole + 11
|
SourceTreeItemTypeRole = Qt::UserRole + 11,
|
||||||
|
SortRole = Qt::UserRole + 12
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
SourcesModel( QObject* parent = 0 );
|
SourcesModel( QObject* parent = 0 );
|
||||||
virtual ~SourcesModel();
|
virtual ~SourcesModel();
|
||||||
|
|
||||||
|
@@ -31,7 +31,7 @@ SourcesProxyModel::SourcesProxyModel( SourcesModel* model, QObject* parent )
|
|||||||
, m_filtered( false )
|
, m_filtered( false )
|
||||||
{
|
{
|
||||||
setDynamicSortFilter( true );
|
setDynamicSortFilter( true );
|
||||||
// setSortRole( SourcesModel::SortRole );
|
setSortRole( SourcesModel::SortRole );
|
||||||
|
|
||||||
setSourceModel( model );
|
setSourceModel( model );
|
||||||
|
|
||||||
|
@@ -78,9 +78,8 @@ SourceTreeView::SourceTreeView( QWidget* parent )
|
|||||||
setAllColumnsShowFocus( true );
|
setAllColumnsShowFocus( true );
|
||||||
setUniformRowHeights( false );
|
setUniformRowHeights( false );
|
||||||
setIndentation( 16 );
|
setIndentation( 16 );
|
||||||
|
setSortingEnabled( true );
|
||||||
// setSortingEnabled( true );
|
sortByColumn( 1, Qt::AscendingOrder );
|
||||||
// sortByColumn( 1, Qt::AscendingOrder );
|
|
||||||
|
|
||||||
// TODO animation conflicts with the expanding-playlists-when-collection-is-null
|
// TODO animation conflicts with the expanding-playlists-when-collection-is-null
|
||||||
// so investigate
|
// so investigate
|
||||||
|
Reference in New Issue
Block a user