1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-04-01 14:42:25 +02:00

do lots of stuff.

rename playlistmanager to viewmanager. link pages in the viewmanager to indexes in the sourcetree, so it is never out of sync. yay!
This commit is contained in:
Leo Franchi 2011-04-20 22:14:45 -04:00
parent 22de39b96a
commit 74b310eb00
27 changed files with 382 additions and 287 deletions

View File

@ -22,7 +22,7 @@
#include <QNetworkReply>
#include "audio/audioengine.h"
#include "playlist/playlistmanager.h"
#include "viewmanager.h"
#include "utils/imagebutton.h"
#include "utils/tomahawkutils.h"
@ -408,21 +408,21 @@ AudioControls::onRepeatClicked()
case PlaylistInterface::NoRepeat:
{
// switch to RepeatOne
PlaylistManager::instance()->setRepeatMode( PlaylistInterface::RepeatOne );
ViewManager::instance()->setRepeatMode( PlaylistInterface::RepeatOne );
}
break;
case PlaylistInterface::RepeatOne:
{
// switch to RepeatAll
PlaylistManager::instance()->setRepeatMode( PlaylistInterface::RepeatAll );
ViewManager::instance()->setRepeatMode( PlaylistInterface::RepeatAll );
}
break;
case PlaylistInterface::RepeatAll:
{
// switch to NoRepeat
PlaylistManager::instance()->setRepeatMode( PlaylistInterface::NoRepeat );
ViewManager::instance()->setRepeatMode( PlaylistInterface::NoRepeat );
}
break;
@ -457,26 +457,26 @@ AudioControls::onShuffleModeChanged( bool enabled )
void
AudioControls::onShuffleClicked()
{
PlaylistManager::instance()->setShuffled( m_shuffled ^ true );
ViewManager::instance()->setShuffled( m_shuffled ^ true );
}
void
AudioControls::onArtistClicked()
{
PlaylistManager::instance()->show( m_currentTrack->artist() );
ViewManager::instance()->show( m_currentTrack->artist() );
}
void
AudioControls::onAlbumClicked()
{
PlaylistManager::instance()->show( m_currentTrack->album() );
ViewManager::instance()->show( m_currentTrack->album() );
}
void
AudioControls::onTrackClicked()
{
PlaylistManager::instance()->showCurrentTrack();
ViewManager::instance()->showCurrentTrack();
}

View File

@ -27,6 +27,7 @@ set( libSources
result.cpp
source.cpp
viewpage.cpp
viewmanager.cpp
sip/SipPlugin.cpp
@ -90,7 +91,6 @@ set( libSources
playlist/collectionproxymodel.cpp
playlist/collectionflatmodel.cpp
playlist/collectionview.cpp
playlist/playlistmanager.cpp
playlist/playlistmodel.cpp
playlist/playlistproxymodel.cpp
playlist/playlistview.cpp
@ -180,6 +180,7 @@ set( libHeaders
result.h
source.h
viewpage.h
viewmanager.h
artist.h
album.h
@ -257,7 +258,6 @@ set( libHeaders
playlist/collectionproxymodel.h
playlist/collectionflatmodel.h
playlist/collectionview.h
playlist/playlistmanager.h
playlist/playlistmodel.h
playlist/playlistproxymodel.h
playlist/playlistview.h

View File

@ -26,7 +26,7 @@
#include "dynamic/GeneratorInterface.h"
#include "network/servent.h"
#include "playlist/playlistmanager.h"
#include "viewmanager.h"
using namespace Tomahawk;
@ -92,7 +92,7 @@ DatabaseCommand_CreateDynamicPlaylist::postCommitHook()
qDebug() << Q_FUNC_INFO << "..reporting..";
if( m_playlist.isNull() ) {
source_ptr src = source();
QMetaObject::invokeMethod( PlaylistManager::instance(),
QMetaObject::invokeMethod( ViewManager::instance(),
"createDynamicPlaylist",
Qt::BlockingQueuedConnection,
QGenericArgument( "Tomahawk::source_ptr", (const void*)&src ),

View File

@ -21,7 +21,7 @@
#include <QSqlQuery>
#include "network/servent.h"
#include "playlist/playlistmanager.h"
#include "viewmanager.h"
using namespace Tomahawk;
@ -66,7 +66,7 @@ DatabaseCommand_CreatePlaylist::postCommitHook()
qDebug() << Q_FUNC_INFO << "..reporting..";
if( m_playlist.isNull() ) {
source_ptr src = source();
QMetaObject::invokeMethod( PlaylistManager::instance(),
QMetaObject::invokeMethod( ViewManager::instance(),
"createPlaylist",
Qt::BlockingQueuedConnection,
QGenericArgument( "Tomahawk::source_ptr", (const void*)&src ),

View File

@ -184,6 +184,7 @@ playlist_ptr
Playlist::load( const QString& guid )
{
playlist_ptr p;
qDebug() << "asked to load playlist:" << guid;
foreach( const Tomahawk::source_ptr& source, SourceList::instance()->sources() )
{

View File

@ -28,7 +28,7 @@
#include "tomahawksettings.h"
#include "albumitemdelegate.h"
#include "playlistmanager.h"
#include "viewmanager.h"
using namespace Tomahawk;
@ -106,7 +106,7 @@ AlbumView::onItemActivated( const QModelIndex& index )
// qDebug() << "Result activated:" << item->album()->tracks().first()->toString() << item->album()->tracks().first()->results().first()->url();
// APP->audioEngine()->playItem( item->album().data(), item->album()->tracks().first()->results().first() );
PlaylistManager::instance()->show( item->album() );
ViewManager::instance()->show( item->album() );
}
}

View File

@ -29,7 +29,7 @@
#include "tomahawksettings.h"
#include "treeheader.h"
#include "treeitemdelegate.h"
#include "playlistmanager.h"
#include "viewmanager.h"
static QString s_tmInfoIdentifier = QString( "TREEMODEL" );
@ -121,9 +121,9 @@ ArtistView::onItemActivated( const QModelIndex& index )
if ( item )
{
if ( !item->artist().isNull() )
PlaylistManager::instance()->show( item->artist() );
ViewManager::instance()->show( item->artist() );
else if ( !item->album().isNull() )
PlaylistManager::instance()->show( item->album() );
ViewManager::instance()->show( item->album() );
else if ( !item->result().isNull() )
AudioEngine::instance()->playItem( 0, item->result() );
}

View File

@ -34,7 +34,7 @@
#include "ReadOrWriteWidget.h"
#include "CollapsibleControls.h"
#include "DynamicControlWrapper.h"
#include "playlistmanager.h"
#include "viewmanager.h"
#include "dynamic/DynamicView.h"
#include <qevent.h>
#include "DynamicSetupWidget.h"

View File

@ -70,6 +70,7 @@ signals:
void shuffleModeChanged( bool enabled );
void itemSizeChanged( const QModelIndex& index );
void playlistDeleted();
private slots:
void onDataChanged();

View File

@ -20,7 +20,7 @@
#include <QDebug>
#include "playlist/playlistmanager.h"
#include "viewmanager.h"
using namespace Tomahawk;
@ -47,7 +47,7 @@ QueueProxyModel::siblingItem( int itemsAway )
qDebug() << "new rowcount:" << rowCount( QModelIndex() );
if ( rowCount( QModelIndex() ) == 1 )
PlaylistManager::instance()->hideQueue();
ViewManager::instance()->hideQueue();
removeIndex( currentItem() );

View File

@ -83,25 +83,25 @@ TopBar::TopBar( QWidget* parent )
onFlatMode();
connect( PlaylistManager::instance(), SIGNAL( numSourcesChanged( unsigned int ) ),
connect( ViewManager::instance(), SIGNAL( numSourcesChanged( unsigned int ) ),
SLOT( setNumSources( unsigned int ) ) );
connect( PlaylistManager::instance(), SIGNAL( numTracksChanged( unsigned int ) ),
connect( ViewManager::instance(), SIGNAL( numTracksChanged( unsigned int ) ),
SLOT( setNumTracks( unsigned int ) ) );
connect( PlaylistManager::instance(), SIGNAL( numArtistsChanged( unsigned int ) ),
connect( ViewManager::instance(), SIGNAL( numArtistsChanged( unsigned int ) ),
SLOT( setNumArtists( unsigned int ) ) );
connect( PlaylistManager::instance(), SIGNAL( numShownChanged( unsigned int ) ),
connect( ViewManager::instance(), SIGNAL( numShownChanged( unsigned int ) ),
SLOT( setNumShown( unsigned int ) ) );
connect( PlaylistManager::instance(), SIGNAL( statsAvailable( bool ) ),
connect( ViewManager::instance(), SIGNAL( statsAvailable( bool ) ),
SLOT( setStatsVisible( bool ) ) );
connect( PlaylistManager::instance(), SIGNAL( modesAvailable( bool ) ),
connect( ViewManager::instance(), SIGNAL( modesAvailable( bool ) ),
SLOT( setModesVisible( bool ) ) );
connect( PlaylistManager::instance(), SIGNAL( modeChanged( PlaylistInterface::ViewMode ) ),
connect( ViewManager::instance(), SIGNAL( modeChanged( PlaylistInterface::ViewMode ) ),
SLOT( onModeChanged( PlaylistInterface::ViewMode ) ) );
}

View File

@ -23,7 +23,7 @@
#include <QLabel>
#include <QList>
#include "playlist/playlistmanager.h"
#include "viewmanager.h"
#include "sourcelist.h"
#include "dllmacro.h"

View File

@ -29,7 +29,7 @@
#include "dynamic/widgets/LoadingSpinner.h"
#include "trackheader.h"
#include "playlistmanager.h"
#include "viewmanager.h"
#include "queueview.h"
#include "trackmodel.h"
#include "trackproxymodel.h"
@ -192,8 +192,8 @@ TrackView::addItemsToQueue()
TrackModelItem* item = model()->itemFromIndex( proxyModel()->mapToSource( idx ) );
if ( item && item->query()->numResults() )
{
PlaylistManager::instance()->queue()->model()->append( item->query() );
PlaylistManager::instance()->showQueue();
ViewManager::instance()->queue()->model()->append( item->query() );
ViewManager::instance()->showQueue();
}
}
}

View File

@ -16,7 +16,7 @@
* along with Tomahawk. If not, see <http://www.gnu.org/licenses/>.
*/
#include "playlistmanager.h"
#include "viewmanager.h"
#include <QVBoxLayout>
#include <QMetaMethod>
@ -47,23 +47,23 @@
#include "widgets/welcomewidget.h"
#include "widgets/infowidgets/sourceinfowidget.h"
#include <widgets/newplaylistwidget.h>
#include "widgets/newplaylistwidget.h"
#define FILTER_TIMEOUT 280
using namespace Tomahawk;
PlaylistManager* PlaylistManager::s_instance = 0;
ViewManager* ViewManager::s_instance = 0;
PlaylistManager*
PlaylistManager::instance()
ViewManager*
ViewManager::instance()
{
return s_instance;
}
PlaylistManager::PlaylistManager( QObject* parent )
ViewManager::ViewManager( QObject* parent )
: QObject( parent )
, m_widget( new QWidget() )
, m_welcomeWidget( new WelcomeWidget() )
@ -137,21 +137,21 @@ PlaylistManager::PlaylistManager( QObject* parent )
}
PlaylistManager::~PlaylistManager()
ViewManager::~ViewManager()
{
delete m_widget;
}
PlaylistView*
PlaylistManager::queue() const
ViewManager::queue() const
{
return m_queueView->queue();
}
bool
PlaylistManager::show( const Tomahawk::playlist_ptr& playlist )
Tomahawk::ViewPage*
ViewManager::show( const Tomahawk::playlist_ptr& playlist )
{
PlaylistView* view;
if ( !m_playlistViews.contains( playlist ) )
@ -175,12 +175,12 @@ PlaylistManager::show( const Tomahawk::playlist_ptr& playlist )
TomahawkSettings::instance()->appendRecentlyPlayedPlaylist( playlist );
emit numSourcesChanged( SourceList::instance()->count() );
return true;
return view;
}
bool
PlaylistManager::show( const Tomahawk::dynplaylist_ptr& playlist )
Tomahawk::ViewPage*
ViewManager::show( const Tomahawk::dynplaylist_ptr& playlist )
{
if ( !m_dynamicWidgets.contains( playlist ) )
{
@ -201,12 +201,12 @@ PlaylistManager::show( const Tomahawk::dynplaylist_ptr& playlist )
TomahawkSettings::instance()->appendRecentlyPlayedPlaylist( playlist );
emit numSourcesChanged( SourceList::instance()->count() );
return true;
return m_dynamicWidgets.value( playlist );
}
bool
PlaylistManager::show( const Tomahawk::artist_ptr& artist )
Tomahawk::ViewPage*
ViewManager::show( const Tomahawk::artist_ptr& artist )
{
PlaylistView* view;
@ -229,12 +229,12 @@ PlaylistManager::show( const Tomahawk::artist_ptr& artist )
setPage( view );
emit numSourcesChanged( 1 );
return true;
return view;
}
bool
PlaylistManager::show( const Tomahawk::album_ptr& album )
Tomahawk::ViewPage*
ViewManager::show( const Tomahawk::album_ptr& album )
{
PlaylistView* view;
if ( !m_albumViews.contains( album ) )
@ -256,15 +256,16 @@ PlaylistManager::show( const Tomahawk::album_ptr& album )
setPage( view );
emit numSourcesChanged( 1 );
return true;
return view;
}
bool
PlaylistManager::show( const Tomahawk::collection_ptr& collection )
Tomahawk::ViewPage*
ViewManager::show( const Tomahawk::collection_ptr& collection )
{
qDebug() << Q_FUNC_INFO << m_currentMode;
m_currentCollection = collection;
ViewPage* shown = 0;
if ( m_currentMode == 0 )
{
CollectionView* view;
@ -285,6 +286,7 @@ PlaylistManager::show( const Tomahawk::collection_ptr& collection )
view = m_collectionViews.value( collection );
}
shown = view;
setPage( view );
}
@ -308,6 +310,7 @@ PlaylistManager::show( const Tomahawk::collection_ptr& collection )
view = m_treeViews.value( collection );
}
shown = view;
setPage( view );
}
@ -330,17 +333,18 @@ PlaylistManager::show( const Tomahawk::collection_ptr& collection )
aview = m_collectionAlbumViews.value( collection );
}
shown = aview;
setPage( aview );
}
emit numSourcesChanged( 1 );
return true;
return shown;
}
bool
PlaylistManager::show( const Tomahawk::source_ptr& source )
Tomahawk::ViewPage*
ViewManager::show( const Tomahawk::source_ptr& source )
{
SourceInfoWidget* swidget;
if ( !m_sourceViews.contains( source ) )
@ -356,21 +360,21 @@ PlaylistManager::show( const Tomahawk::source_ptr& source )
setPage( swidget );
emit numSourcesChanged( 1 );
return true;
return swidget;
}
bool
PlaylistManager::show( ViewPage* page )
Tomahawk::ViewPage*
ViewManager::show( ViewPage* page )
{
setPage( page );
return true;
return page;
}
bool
PlaylistManager::showSuperCollection()
Tomahawk::ViewPage*
ViewManager::showSuperCollection()
{
if ( m_superCollections.isEmpty() )
m_superCollectionModel->addAllCollections();
@ -387,34 +391,37 @@ PlaylistManager::showSuperCollection()
m_superCollectionModel->setTitle( tr( "All available tracks" ) );
m_superAlbumModel->setTitle( tr( "All available albums" ) );
ViewPage* shown = 0;
if ( m_currentMode == 0 )
{
shown = m_superCollectionView;
setPage( m_superCollectionView );
}
else if ( m_currentMode == 1 )
{
shown = m_superCollectionView;
setPage( m_superCollectionView );
}
else if ( m_currentMode == 2 )
{
shown = m_superAlbumView;
setPage( m_superAlbumView );
}
emit numSourcesChanged( m_superCollections.count() );
return true;
return shown;
}
void
PlaylistManager::showWelcomePage()
ViewManager::showWelcomePage()
{
show( m_welcomeWidget );
}
void
PlaylistManager::setTableMode()
ViewManager::setTableMode()
{
qDebug() << Q_FUNC_INFO;
@ -428,7 +435,7 @@ PlaylistManager::setTableMode()
void
PlaylistManager::setTreeMode()
ViewManager::setTreeMode()
{
qDebug() << Q_FUNC_INFO;
@ -442,7 +449,7 @@ PlaylistManager::setTreeMode()
void
PlaylistManager::setAlbumMode()
ViewManager::setAlbumMode()
{
qDebug() << Q_FUNC_INFO;
@ -456,7 +463,7 @@ PlaylistManager::setAlbumMode()
void
PlaylistManager::showQueue()
ViewManager::showQueue()
{
if ( QThread::currentThread() != thread() )
{
@ -470,7 +477,7 @@ PlaylistManager::showQueue()
void
PlaylistManager::hideQueue()
ViewManager::hideQueue()
{
if ( QThread::currentThread() != thread() )
{
@ -484,7 +491,7 @@ PlaylistManager::hideQueue()
void
PlaylistManager::historyBack()
ViewManager::historyBack()
{
if ( m_historyPosition < 1 )
return;
@ -494,7 +501,7 @@ PlaylistManager::historyBack()
void
PlaylistManager::historyForward()
ViewManager::historyForward()
{
if ( m_historyPosition >= m_pageHistory.count() - 1 )
return;
@ -504,7 +511,7 @@ PlaylistManager::historyForward()
void
PlaylistManager::showHistory( int historyPosition )
ViewManager::showHistory( int historyPosition )
{
if ( historyPosition < 0 || historyPosition >= m_pageHistory.count() )
{
@ -521,7 +528,7 @@ PlaylistManager::showHistory( int historyPosition )
void
PlaylistManager::setFilter( const QString& filter )
ViewManager::setFilter( const QString& filter )
{
m_filter = filter;
@ -533,7 +540,7 @@ PlaylistManager::setFilter( const QString& filter )
void
PlaylistManager::applyFilter()
ViewManager::applyFilter()
{
qDebug() << Q_FUNC_INFO;
@ -543,7 +550,7 @@ PlaylistManager::applyFilter()
void
PlaylistManager::setPage( ViewPage* page, bool trackHistory )
ViewManager::setPage( ViewPage* page, bool trackHistory )
{
if ( !page )
return;
@ -581,6 +588,9 @@ PlaylistManager::setPage( ViewPage* page, bool trackHistory )
else if ( !currentPlaylistInterface() )
emit tempPageActivated();*/
qDebug() << "View page shown:" << page->title();
emit viewPageActivated( page );
if ( !AudioEngine::instance()->isPlaying() )
AudioEngine::instance()->setPlaylist( currentPlaylistInterface() );
@ -603,14 +613,14 @@ PlaylistManager::setPage( ViewPage* page, bool trackHistory )
}
bool
PlaylistManager::isNewPlaylistPageVisible() const
ViewManager::isNewPlaylistPageVisible() const
{
return dynamic_cast< NewPlaylistWidget* >( currentPage() ) != 0;
}
void
PlaylistManager::unlinkPlaylist()
ViewManager::unlinkPlaylist()
{
if ( currentPlaylistInterface() )
{
@ -630,7 +640,7 @@ PlaylistManager::unlinkPlaylist()
void
PlaylistManager::updateView()
ViewManager::updateView()
{
if ( currentPlaylistInterface() )
{
@ -683,7 +693,7 @@ PlaylistManager::updateView()
void
PlaylistManager::onWidgetDestroyed( QWidget* widget )
ViewManager::onWidgetDestroyed( QWidget* widget )
{
qDebug() << "Destroyed child:" << widget << widget->metaObject()->className();
@ -722,7 +732,7 @@ PlaylistManager::onWidgetDestroyed( QWidget* widget )
void
PlaylistManager::setRepeatMode( PlaylistInterface::RepeatMode mode )
ViewManager::setRepeatMode( PlaylistInterface::RepeatMode mode )
{
if ( currentPlaylistInterface() )
currentPlaylistInterface()->setRepeatMode( mode );
@ -730,7 +740,7 @@ PlaylistManager::setRepeatMode( PlaylistInterface::RepeatMode mode )
void
PlaylistManager::setShuffled( bool enabled )
ViewManager::setShuffled( bool enabled )
{
if ( currentPlaylistInterface() )
currentPlaylistInterface()->setShuffled( enabled );
@ -738,7 +748,7 @@ PlaylistManager::setShuffled( bool enabled )
void
PlaylistManager::createPlaylist( const Tomahawk::source_ptr& src,
ViewManager::createPlaylist( const Tomahawk::source_ptr& src,
const QVariant& contents )
{
Tomahawk::playlist_ptr p = Tomahawk::playlist_ptr( new Tomahawk::Playlist( src ) );
@ -748,7 +758,7 @@ PlaylistManager::createPlaylist( const Tomahawk::source_ptr& src,
void
PlaylistManager::createDynamicPlaylist( const Tomahawk::source_ptr& src,
ViewManager::createDynamicPlaylist( const Tomahawk::source_ptr& src,
const QVariant& contents )
{
Tomahawk::dynplaylist_ptr p = Tomahawk::dynplaylist_ptr( new Tomahawk::DynamicPlaylist( src, contents.toMap().value( "type", QString() ).toString() ) );
@ -756,9 +766,27 @@ PlaylistManager::createDynamicPlaylist( const Tomahawk::source_ptr& src,
p->reportCreated( p );
}
ViewPage*
ViewManager::pageForCollection( const collection_ptr& col ) const
{
return m_collectionViews.value( col, 0 );
}
ViewPage*
PlaylistManager::pageForInterface( PlaylistInterface* interface ) const
ViewManager::pageForDynPlaylist(const dynplaylist_ptr& pl) const
{
return m_dynamicWidgets.value( pl, 0 );
}
ViewPage*
ViewManager::pageForPlaylist(const playlist_ptr& pl) const
{
return m_playlistViews.value( pl, 0 );
}
ViewPage*
ViewManager::pageForInterface( PlaylistInterface* interface ) const
{
for ( int i = 0; i < m_pageHistory.count(); i++ )
{
@ -772,7 +800,7 @@ PlaylistManager::pageForInterface( PlaylistInterface* interface ) const
int
PlaylistManager::positionInHistory( ViewPage* page ) const
ViewManager::positionInHistory( ViewPage* page ) const
{
for ( int i = 0; i < m_pageHistory.count(); i++ )
{
@ -785,7 +813,7 @@ PlaylistManager::positionInHistory( ViewPage* page ) const
PlaylistInterface*
PlaylistManager::currentPlaylistInterface() const
ViewManager::currentPlaylistInterface() const
{
if ( currentPage() )
return currentPage()->playlistInterface();
@ -795,7 +823,7 @@ PlaylistManager::currentPlaylistInterface() const
Tomahawk::ViewPage*
PlaylistManager::currentPage() const
ViewManager::currentPage() const
{
if ( m_historyPosition >= 0 )
return m_pageHistory.at( m_historyPosition );
@ -805,7 +833,7 @@ PlaylistManager::currentPage() const
void
PlaylistManager::setHistoryPosition( int position )
ViewManager::setHistoryPosition( int position )
{
m_historyPosition = position;
@ -815,7 +843,7 @@ PlaylistManager::setHistoryPosition( int position )
Tomahawk::playlist_ptr
PlaylistManager::playlistForInterface( PlaylistInterface* interface ) const
ViewManager::playlistForInterface( PlaylistInterface* interface ) const
{
foreach ( PlaylistView* view, m_playlistViews.values() )
{
@ -830,7 +858,7 @@ PlaylistManager::playlistForInterface( PlaylistInterface* interface ) const
Tomahawk::dynplaylist_ptr
PlaylistManager::dynamicPlaylistForInterface( PlaylistInterface* interface ) const
ViewManager::dynamicPlaylistForInterface( PlaylistInterface* interface ) const
{
foreach ( DynamicWidget* view, m_dynamicWidgets.values() )
{
@ -845,7 +873,7 @@ PlaylistManager::dynamicPlaylistForInterface( PlaylistInterface* interface ) con
Tomahawk::collection_ptr
PlaylistManager::collectionForInterface( PlaylistInterface* interface ) const
ViewManager::collectionForInterface( PlaylistInterface* interface ) const
{
foreach ( CollectionView* view, m_collectionViews.values() )
{
@ -867,7 +895,7 @@ PlaylistManager::collectionForInterface( PlaylistInterface* interface ) const
bool
PlaylistManager::isSuperCollectionVisible() const
ViewManager::isSuperCollectionVisible() const
{
return ( m_pageHistory.count() &&
( currentPage()->playlistInterface() == m_superCollectionView->playlistInterface() ||
@ -876,7 +904,7 @@ PlaylistManager::isSuperCollectionVisible() const
void
PlaylistManager::showCurrentTrack()
ViewManager::showCurrentTrack()
{
ViewPage* page = pageForInterface( AudioEngine::instance()->currentTrackPlaylist() );
@ -889,14 +917,14 @@ PlaylistManager::showCurrentTrack()
void
PlaylistManager::onPlayClicked()
ViewManager::onPlayClicked()
{
emit playClicked();
}
void
PlaylistManager::onPauseClicked()
ViewManager::onPauseClicked()
{
emit pauseClicked();
}

View File

@ -54,15 +54,15 @@ namespace Tomahawk
class DynamicWidget;
}
class DLLEXPORT PlaylistManager : public QObject
class DLLEXPORT ViewManager : public QObject
{
Q_OBJECT
public:
static PlaylistManager* instance();
static ViewManager* instance();
explicit PlaylistManager( QObject* parent = 0 );
~PlaylistManager();
explicit ViewManager( QObject* parent = 0 );
~ViewManager();
QWidget* widget() const { return m_widget; }
PlaylistView* queue() const;
@ -75,14 +75,23 @@ public:
Tomahawk::ViewPage* pageForInterface( PlaylistInterface* interface ) const;
int positionInHistory( Tomahawk::ViewPage* page ) const;
bool show( const Tomahawk::playlist_ptr& playlist );
bool show( const Tomahawk::dynplaylist_ptr& playlist );
bool show( const Tomahawk::artist_ptr& artist );
bool show( const Tomahawk::album_ptr& album );
bool show( const Tomahawk::collection_ptr& collection );
bool show( const Tomahawk::source_ptr& source );
// Returns the shown viewpage
Tomahawk::ViewPage* show( const Tomahawk::playlist_ptr& playlist );
Tomahawk::ViewPage* show( const Tomahawk::dynplaylist_ptr& playlist );
Tomahawk::ViewPage* show( const Tomahawk::artist_ptr& artist );
Tomahawk::ViewPage* show( const Tomahawk::album_ptr& album );
Tomahawk::ViewPage* show( const Tomahawk::collection_ptr& collection );
Tomahawk::ViewPage* show( const Tomahawk::source_ptr& source );
bool show( Tomahawk::ViewPage* page );
Tomahawk::ViewPage* show( Tomahawk::ViewPage* page );
WelcomeWidget* welcomeWidget() const { return m_welcomeWidget; }
ArtistView* superCollectionView() const { return m_superCollectionView; }
/// Get the view page for the given item. Not pretty...
Tomahawk::ViewPage* pageForPlaylist( const Tomahawk::playlist_ptr& pl ) const;
Tomahawk::ViewPage* pageForDynPlaylist( const Tomahawk::dynplaylist_ptr& pl ) const;
Tomahawk::ViewPage* pageForCollection( const Tomahawk::collection_ptr& pl ) const;
signals:
void numSourcesChanged( unsigned int sources );
@ -110,9 +119,10 @@ signals:
void dynamicPlaylistActivated( const Tomahawk::dynplaylist_ptr& playlist );
void newPlaylistActivated();
void viewPageActivated( Tomahawk::ViewPage* );
public slots:
bool showSuperCollection();
Tomahawk::ViewPage* showSuperCollection();
void showWelcomePage();
void showCurrentTrack();
@ -189,7 +199,7 @@ private:
QTimer m_filterTimer;
QString m_filter;
static PlaylistManager* s_instance;
static ViewManager* s_instance;
};
#endif // PLAYLISTMANAGER_H

View File

@ -21,7 +21,7 @@
#include "utils/tomahawkutils.h"
#include "playlist/playlistmanager.h"
#include "viewmanager.h"
#include "playlist/albummodel.h"
#include "playlist/collectionflatmodel.h"
#include "playlist/playlistmodel.h"

View File

@ -24,7 +24,7 @@
#include "utils/tomahawkutils.h"
#include "playlist/playlistmanager.h"
#include "viewmanager.h"
#include "playlist/playlistmodel.h"
#include "widgets/overlaywidget.h"
@ -144,7 +144,7 @@ NewPlaylistWidget::savePlaylist()
playlist = Tomahawk::Playlist::create( SourceList::instance()->getLocal(), uuid(), ui->titleEdit->text(), "", "", false );
playlist->createNewRevision( uuid(), playlist->currentrevision(), m_entries );
PlaylistManager::instance()->show( playlist );
ViewManager::instance()->show( playlist );
cancel();
}

View File

@ -21,7 +21,7 @@
#include "utils/tomahawkutils.h"
#include "playlist/playlistmanager.h"
#include "viewmanager.h"
#include "playlist/playlistmodel.h"
#include "widgets/overlaywidget.h"
@ -130,9 +130,9 @@ WelcomeWidget::onPlaylistActivated( QListWidgetItem* item )
PlaylistWidgetItem* pwi = dynamic_cast<PlaylistWidgetItem*>(item);
if( Tomahawk::dynplaylist_ptr dynplaylist = pwi->playlist().dynamicCast< Tomahawk::DynamicPlaylist >() )
PlaylistManager::instance()->show( dynplaylist );
ViewManager::instance()->show( dynplaylist );
else
PlaylistManager::instance()->show( pwi->playlist() );
ViewManager::instance()->show( pwi->playlist() );
}

View File

@ -24,15 +24,16 @@
#include "collection.h"
#include "source.h"
#include "tomahawk/tomahawkapp.h"
#include "viewmanager.h"
#include <QMimeData>
#include <QSize>
#include <playlist/playlistmanager.h>
using namespace Tomahawk;
SourcesModel::SourcesModel( QObject* parent )
: QAbstractItemModel( parent )
, m_viewPageDelayedCacheItem( 0 )
{
m_rootItem = new SourceTreeItem( this, 0, Invalid );
@ -40,12 +41,13 @@ SourcesModel::SourcesModel( QObject* parent )
// add misc children of root node
GenericPageItem* recent = new GenericPageItem( this, m_rootItem->children().at( 0 ), tr( "Recently Played" ), QIcon( RESPATH "images/recently-played.png" ) );
connect( recent, SIGNAL( activated() ), PlaylistManager::instance(), SLOT( showWelcomePage() ) );
connect( recent, SIGNAL( activated() ), ViewManager::instance(), SLOT( showWelcomePage() ) );
onSourcesAdded( SourceList::instance()->sources() );
connect( SourceList::instance(), SIGNAL( sourceAdded( Tomahawk::source_ptr ) ), SLOT( onSourceAdded( Tomahawk::source_ptr ) ) );
connect( SourceList::instance(), SIGNAL( sourceRemoved( Tomahawk::source_ptr ) ), SLOT( onSourceRemoved( Tomahawk::source_ptr ) ) );
connect( ViewManager::instance(), SIGNAL( viewPageActivated( Tomahawk::ViewPage* ) ), this, SLOT( viewPageActivated( Tomahawk::ViewPage* ) ) );
}
SourcesModel::~SourcesModel()
@ -186,19 +188,8 @@ SourcesModel::appendItem( const Tomahawk::source_ptr& source )
beginInsertRows( QModelIndex(), rowCount(), rowCount() );
// append to end
CollectionItem* item = new CollectionItem( this, m_rootItem, source );
connect( item, SIGNAL( updated() ), this, SLOT( collectionUpdated() ) );
endInsertRows();
if ( !source.isNull() )
{
qDebug() << "Appending source item:" << item->source()->friendlyName();
connect( source.data(), SIGNAL( stats( QVariantMap ) ), SLOT( onSourceChanged() ) );
connect( source.data(), SIGNAL( playbackStarted( Tomahawk::query_ptr ) ), SLOT( onSourceChanged() ) );
connect( source.data(), SIGNAL( stateChanged() ), SLOT( onSourceChanged() ) );
}
}
bool
@ -229,6 +220,23 @@ SourcesModel::removeItem( const Tomahawk::source_ptr& source )
return false;
}
void
SourcesModel::viewPageActivated( Tomahawk::ViewPage* page )
{
if ( m_sourceTreeLinks.contains( page ) )
{
Q_ASSERT( m_sourceTreeLinks[ page ] );
qDebug() << "Got view page activated for itemL:" << m_sourceTreeLinks[ page ]->text();
QModelIndex idx = indexFromItem( m_sourceTreeLinks[ page ] );
Q_ASSERT( idx.isValid() );
emit selectRequest( idx );
} else {
m_viewPageDelayedCacheItem = page;
}
}
/*
QModelIndex
SourcesModel::indexFromPlaylist( const playlist_ptr& playlist )
{
@ -257,30 +265,7 @@ SourcesModel::indexFromPlaylist( const playlist_ptr& playlist )
}
qDebug() << "FAILED to find playlist in source tree:" << playlist->title();
return idx;
}
void
SourcesModel::onSourceChanged() {
Source* src = qobject_cast< Source* >( sender() );
Q_ASSERT( src );
qDebug() << "Searching for source item:" << src->friendlyName();
for( int i = 0; i < rowCount(); i++ )
{
QModelIndex idx = index( i, 0 , QModelIndex() );
if( idx.isValid() && itemFromIndex( idx ) && itemFromIndex( idx )->type() == Collection && // this is a source
static_cast< CollectionItem* >( itemFromIndex( idx ) )->source().data() == src ) // and it is the one we want
{
qDebug() << "Found changed source, emitting dataChanged:" << src->friendlyName();
emit dataChanged( idx, idx );
return;
}
}
}
}*/
void
SourcesModel::loadSources()
@ -314,11 +299,19 @@ SourcesModel::onSourceRemoved( const source_ptr& source )
}
void
SourcesModel::collectionUpdated()
SourcesModel::itemUpdated()
{
Q_ASSERT( qobject_cast< SourceTreeItem* >( sender() ) );
SourceTreeItem* item = qobject_cast< SourceTreeItem* >( sender() );
if( !item )
return;
QModelIndex idx = indexFromItem( item );
emit dataChanged( idx, idx );
}
void
SourcesModel::onItemRowsAddedBegin( int first, int last )
{
@ -362,6 +355,19 @@ SourcesModel::onItemRowsRemovedDone()
endRemoveRows();
}
void
SourcesModel::linkSourceItemToPage( SourceTreeItem* item, ViewPage* p )
{
// TODO handle removal
m_sourceTreeLinks[ p ] = item;
if( m_viewPageDelayedCacheItem = p )
emit selectRequest( indexFromItem( item ) );
m_viewPageDelayedCacheItem = 0;
}
SourceTreeItem*
SourcesModel::itemFromIndex( const QModelIndex& idx ) const
{

View File

@ -31,6 +31,7 @@ class SourceTreeItem;
namespace Tomahawk {
class Source;
class Playlist;
class ViewPage;
}
class SourcesModel : public QAbstractItemModel
@ -43,13 +44,10 @@ public:
Collection = 0,
Category = 1,
CategoryAdd = 2,
StaticPlaylist = 3,
AutomaticPlaylist = 4,
Stations = 5,
GenericPage = 6
@ -85,22 +83,26 @@ public:
void appendItem( const Tomahawk::source_ptr& source );
bool removeItem( const Tomahawk::source_ptr& source );
void linkSourceItemToPage( SourceTreeItem* item, Tomahawk::ViewPage* p );
// HACK i don't like this
// SLOW DON'T USE IF YOU CAN AVOID IT
QModelIndex indexFromPlaylist( const Tomahawk::playlist_ptr& playlist );
// QModelIndex indexFromPlaylist( const Tomahawk::playlist_ptr& playlist );
QModelIndex indexFromItem( SourceTreeItem* item ) const;
signals:
void selectRequest( const QModelIndex& idx );
private slots:
void onSourcesAdded( const QList<Tomahawk::source_ptr>& sources );
void onSourceAdded( const Tomahawk::source_ptr& source );
void onSourceRemoved( const Tomahawk::source_ptr& source );
void onSourceChanged();
void viewPageActivated( Tomahawk::ViewPage* );
public slots:
void loadSources();
void collectionUpdated();
void itemUpdated();
void onItemRowsAddedBegin( int first, int last );
void onItemRowsAddedDone();
void onItemRowsRemovedBegin( int first, int last );
@ -114,6 +116,9 @@ private:
// QModelIndex indexForCategory( const QModelIndex& sourceIndex, CategoryType type );
SourceTreeItem* m_rootItem;
QHash< Tomahawk::ViewPage*, SourceTreeItem* > m_sourceTreeLinks;
Tomahawk::ViewPage* m_viewPageDelayedCacheItem;
};
#endif // SOURCESMODEL_H

View File

@ -34,8 +34,9 @@ SourcesProxyModel::SourcesProxyModel( SourcesModel* model, QObject* parent )
// setSortRole( SourcesModel::SortRole );
setSourceModel( model );
connect( model, SIGNAL( askForExpand( QModelIndex ) ), this, SLOT( askedToExpand( QModelIndex ) ) );
connect( model, SIGNAL( selectRequest( QModelIndex ) ), this, SLOT( selectRequested( QModelIndex ) ) );
}
@ -73,3 +74,11 @@ SourcesProxyModel::filterAcceptsRow( int sourceRow, const QModelIndex& sourcePar
// accept rows that aren't sources
return true;
}
void
SourcesProxyModel::selectRequested( const QModelIndex& idx )
{
qDebug() << "asking for select from idx:" << idx << idx.model()->metaObject()->className();
emit selectRequest( mapFromSource( idx ) );
}

View File

@ -34,6 +34,11 @@ public slots:
void showOfflineSources();
void hideOfflineSources();
void selectRequested( const QModelIndex& );
signals:
void selectRequest( const QModelIndex& idx );
protected:
bool filterAcceptsRow( int sourceRow, const QModelIndex& sourceParent ) const;

View File

@ -20,10 +20,11 @@
#include "playlist.h"
#include "playlist/dynamic/DynamicPlaylist.h"
#include "source.h"
#include <playlist/playlistmanager.h>
#include "viewmanager.h"
#include "tomahawk/tomahawkapp.h"
#include "widgets/newplaylistwidget.h"
#include <QMimeData>
#include <widgets/newplaylistwidget.h>
using namespace Tomahawk;
@ -32,15 +33,16 @@ SourceTreeItem::SourceTreeItem( SourcesModel* model, SourceTreeItem* parent, Sou
, m_type( thisType )
, m_parent( parent )
, m_model( model )
{
{
connect( this, SIGNAL( beginChildRowsAdded( int,int ) ), m_model, SLOT( onItemRowsAddedBegin( int,int ) ) );
connect( this, SIGNAL( beginChildRowsRemoved( int,int ) ), m_model, SLOT( onItemRowsRemovedBegin( int,int ) ) );
connect( this, SIGNAL( childRowsAdded() ), m_model, SLOT( onItemRowsAddedDone() ) );
connect( this, SIGNAL( childRowsRemoved() ), m_model, SLOT( onItemRowsRemovedDone() ) );
connect( this, SIGNAL( updated() ), m_model, SLOT( itemUpdated() ) );
if( !m_parent )
return;
// caller must call begin/endInsertRows
if( index < 0 )
m_parent->appendChild( this );
@ -57,7 +59,7 @@ SourceTreeItem::~SourceTreeItem()
/// Category item
void
void
CategoryItem::activate()
{
if( m_category == SourcesModel::StationsCategory ) {
@ -77,82 +79,86 @@ PlaylistItem::PlaylistItem( SourcesModel* mdl, SourceTreeItem* parent, const pla
SLOT( onPlaylistLoaded( Tomahawk::PlaylistRevision ) ), Qt::QueuedConnection );
connect( pl.data(), SIGNAL( changed() ),
SIGNAL( updated() ), Qt::QueuedConnection );
if( ViewManager::instance()->pageForPlaylist( pl ) )
model()->linkSourceItemToPage( this, ViewManager::instance()->pageForPlaylist( pl ) );
}
QString
QString
PlaylistItem::text() const
{
return m_playlist->title();
}
Tomahawk::playlist_ptr
Tomahawk::playlist_ptr
PlaylistItem::playlist() const
{
return m_playlist;
}
void
void
PlaylistItem::onPlaylistLoaded( Tomahawk::PlaylistRevision revision )
{
m_loaded = true;
emit updated();
}
void
void
PlaylistItem::onPlaylistChanged()
{
emit updated();
}
Qt::ItemFlags
Qt::ItemFlags
PlaylistItem::flags() const
{
Qt::ItemFlags flags = SourceTreeItem::flags();
if( !m_loaded )
flags &= !Qt::ItemIsEnabled;
flags |= Qt::ItemIsDragEnabled | Qt::ItemIsDropEnabled;
if( playlist()->author()->isLocal() )
flags |= Qt::ItemIsEditable;
return flags;
}
void
void
PlaylistItem::activate()
{
PlaylistManager::instance()->show( m_playlist );
ViewPage* p = ViewManager::instance()->show( m_playlist );
model()->linkSourceItemToPage( this, p );
}
void
void
PlaylistItem::setLoaded( bool loaded )
{
m_loaded = loaded;
}
bool
bool
PlaylistItem::willAcceptDrag( const QMimeData* data ) const
{
return !m_playlist.isNull() && m_playlist->author()->isLocal();
}
bool
bool
PlaylistItem::dropMimeData( const QMimeData* data, Qt::DropAction action )
{
if( data->hasFormat( "application/tomahawk.query.list" ) ) {
if ( !m_playlist.isNull() && m_playlist->author()->isLocal() ) {
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() )
{
@ -160,21 +166,21 @@ PlaylistItem::dropMimeData( const QMimeData* data, Qt::DropAction action )
queries << *query;
}
}
qDebug() << "on playlist:" << m_playlist->title() << m_playlist->guid();
// TODO do we need to use this in the refactor?
// QString rev = item->currentlyLoadedPlaylistRevision( playlist->guid() );
m_playlist->addEntries( queries, m_playlist->currentrevision() );
return true;
}
}
return false;
}
QIcon
QIcon
PlaylistItem::icon() const
{
return QIcon( RESPATH "images/playlist-icon.png" );
@ -194,32 +200,32 @@ DynPlaylistItem::DynPlaylistItem( SourcesModel* mdl, SourceTreeItem* parent, con
}
QString
QString
DynPlaylistItem::text()
{
return m_dynplaylist->title();
}
Tomahawk::playlist_ptr
Tomahawk::playlist_ptr
DynPlaylistItem::playlist() const
{
return m_dynplaylist.staticCast<Tomahawk::Playlist>();
}
// Tomahawk::dynplaylist_ptr
// Tomahawk::dynplaylist_ptr
// DynPlaylistItem::playlist() const
// {
// return m_dynplaylist;
// }
void
void
DynPlaylistItem::activate()
{
PlaylistManager::instance()->show( m_playlist );
ViewManager::instance()->show( m_playlist );
}
void
void
DynPlaylistItem::onDynamicPlaylistLoaded( Tomahawk::DynamicPlaylistRevision revision )
{
setLoaded( true );
@ -239,27 +245,29 @@ CategoryAddItem::~CategoryAddItem()
}
QString
QString
CategoryAddItem::text() const
{
switch( m_categoryType ) {
case SourcesModel::PlaylistsCategory:
case SourcesModel::PlaylistsCategory:
return tr( "New Playlist" );
case SourcesModel::StationsCategory:
return tr( "New Station" );
}
return QString();
}
void
void
CategoryAddItem::activate()
{
switch( m_categoryType ) {
case SourcesModel::PlaylistsCategory:
case SourcesModel::PlaylistsCategory:
// only show if none is shown yet
if( !PlaylistManager::instance()->isNewPlaylistPageVisible() )
PlaylistManager::instance()->show( new NewPlaylistWidget() );
if( !ViewManager::instance()->isNewPlaylistPageVisible() ) {
ViewPage* p = ViewManager::instance()->show( new NewPlaylistWidget() );
model()->linkSourceItemToPage( this, p );
}
break;
case SourcesModel::StationsCategory:
// TODO
@ -267,13 +275,13 @@ CategoryAddItem::activate()
}
}
Qt::ItemFlags
Qt::ItemFlags
CategoryAddItem::flags() const
{
return Qt::ItemIsEnabled | Qt::ItemIsSelectable;
}
QIcon
QIcon
CategoryAddItem::icon() const
{
return QIcon( RESPATH "images/add.png" );
@ -295,19 +303,19 @@ CategoryItem::CategoryItem( SourcesModel* model, SourceTreeItem* parent, Sources
// endRowsAdded();
}
void
void
CategoryItem::insertItem( SourceTreeItem* item )
{
insertItems( QList< SourceTreeItem* >() << item );
}
void
void
CategoryItem::insertItems( QList< SourceTreeItem* > items )
{
// add the items to the category, and connect to the signals
int curCount = children().size();
if( m_showAdd ) // if there's an add item, add it before that
curCount--;
curCount--;
beginRowsAdded( curCount, curCount + items.size() - 1 );
foreach( SourceTreeItem* item, items ) {
int index = m_showAdd ? children().count() - 1 : children().count();
@ -319,7 +327,7 @@ CategoryItem::insertItems( QList< SourceTreeItem* > items )
/// CollectionItem
CollectionItem::CollectionItem( SourcesModel* mdl, SourceTreeItem* parent, const Tomahawk::source_ptr& source )
CollectionItem::CollectionItem( SourcesModel* mdl, SourceTreeItem* parent, const Tomahawk::source_ptr& source )
: SourceTreeItem( mdl, parent, SourcesModel::Collection )
, m_source( source )
, m_playlists( 0 )
@ -330,29 +338,37 @@ CollectionItem::CollectionItem( SourcesModel* mdl, SourceTreeItem* parent, cons
}
// create category items if there are playlists to show, or stations to show
QList< playlist_ptr > playlists = source->collection()->playlists();
if( !playlists.isEmpty() || source->isLocal() ) {
m_playlists = new CategoryItem( model(), this, SourcesModel::PlaylistsCategory, source->isLocal() );
m_playlists = new CategoryItem( model(), this, SourcesModel::PlaylistsCategory, source->isLocal() );
// ugh :( we're being added by the model, no need to notify for added rows now
// m_playlists->blockSignals( true );
onPlaylistsAdded( source->collection()->playlists() );
onPlaylistsAdded( playlists );
// m_playlists->blockSignals( false );
}
// TODO always show for now, till we actually support stations
// m_stations = new CategoryItem( model(), this, SourcesModel::StationsCategory, source->isLocal() );
if( ViewManager::instance()->pageForCollection( source->collection() ) )
model()->linkSourceItemToPage( this, ViewManager::instance()->pageForCollection( source->collection() ) );
// HACK to load only for now
source->collection()->dynamicPlaylists();
connect( source.data(), SIGNAL( stats( QVariantMap ) ), this, SIGNAL( updated() ) );
connect( source.data(), SIGNAL( playbackStarted( Tomahawk::query_ptr ) ), this, SIGNAL( updated() ) );
connect( source.data(), SIGNAL( stateChanged() ), this, SIGNAL( updated() ) );
connect( source.data(), SIGNAL( offline() ), this, SIGNAL( updated() ) );
connect( source.data(), SIGNAL( online() ), this, SIGNAL( updated() ) );
connect( source->collection().data(), SIGNAL( playlistsAdded( QList<Tomahawk::playlist_ptr> ) ),
SLOT( onPlaylistsAdded( QList<Tomahawk::playlist_ptr> ) ) );
SLOT( onPlaylistsAdded( QList<Tomahawk::playlist_ptr> ) ), Qt::QueuedConnection );
connect( source->collection().data(), SIGNAL( playlistsDeleted( QList<Tomahawk::playlist_ptr> ) ),
SLOT( onPlaylistsDeleted( QList<Tomahawk::playlist_ptr> ) ) );
SLOT( onPlaylistsDeleted( QList<Tomahawk::playlist_ptr> ) ), Qt::QueuedConnection );
}
Tomahawk::source_ptr
Tomahawk::source_ptr
CollectionItem::source() const
{
return m_source;
@ -364,17 +380,19 @@ CollectionItem::text() const
return m_source.isNull() ? tr( "Super Collection" ) : m_source->friendlyName();
}
void
void
CollectionItem::activate()
{
if( source().isNull() ) {
PlaylistManager::instance()->showSuperCollection();
ViewPage* p = ViewManager::instance()->showSuperCollection();
model()->linkSourceItemToPage( this, p );
} else {
PlaylistManager::instance()->show( source()->collection() );
ViewPage* p = ViewManager::instance()->show( source()->collection() );
model()->linkSourceItemToPage( this, p );
}
}
QIcon
QIcon
CollectionItem::icon() const
{
if( m_source.isNull() )
@ -384,23 +402,23 @@ CollectionItem::icon() const
}
void
void
CollectionItem::onPlaylistsAdded( const QList< playlist_ptr >& playlists )
{
if( playlists.isEmpty() )
return;
if( !m_playlists ) { // add the category too
m_playlists = new CategoryItem( model(), this, SourcesModel::PlaylistsCategory, source()->isLocal() );
m_playlists = new CategoryItem( model(), this, SourcesModel::PlaylistsCategory, source()->isLocal() );
}
QList< SourceTreeItem* > items;
int addOffset = playlists.first()->author()->isLocal() ? 1 : 0;
int from = m_playlists->children().count() - addOffset;
m_playlists->beginRowsAdded( from, from + playlists.count() - 1 );
foreach( const playlist_ptr& p, playlists )
{
{
PlaylistItem* plItem = new PlaylistItem( model(), m_playlists, p, m_playlists->children().count() - addOffset );
qDebug() << "Playlist added:" << p->title() << p->creator() << p->info();
p->loadRevision();
@ -409,7 +427,7 @@ CollectionItem::onPlaylistsAdded( const QList< playlist_ptr >& playlists )
m_playlists->endRowsAdded();
}
void
void
CollectionItem::onPlaylistsDeleted( const QList< playlist_ptr >& playlists )
{
Q_ASSERT( m_playlists ); // How can we delete playlists if we have none?
@ -442,26 +460,26 @@ GenericPageItem::~GenericPageItem()
}
void
void
GenericPageItem::activate()
{
emit activated();
}
QString
QString
GenericPageItem::text() const
{
return m_text;
}
QIcon
QIcon
GenericPageItem::icon() const
{
return m_icon;
}
bool
bool
GenericPageItem::willAcceptDrag(const QMimeData* data) const
{
return false;

View File

@ -26,15 +26,15 @@
#include <QIcon>
class QMimeData;
class SourceTreeItem : public QObject
class SourceTreeItem : public QObject
{
Q_OBJECT
public:
SourceTreeItem() : m_type( SourcesModel::Invalid ), m_parent( 0 ), m_model( 0 ) {}
SourceTreeItem( SourcesModel* model, SourceTreeItem* parent, SourcesModel::RowType thisType, int index = -1 ); // if index is -1, append at end of parent's child list
virtual ~SourceTreeItem();
// generic info used by the tree model
// generic info used by the tree model
SourcesModel::RowType type() const { return m_type; }
SourceTreeItem* parent() const { return m_parent; }
SourcesModel* model() const { return m_model; }
@ -43,7 +43,7 @@ public:
void appendChild( SourceTreeItem* item ) { m_children.append( item ); }
void insertChild( int index, SourceTreeItem* item ) { m_children.insert( index, item ); }
void removeChild( SourceTreeItem* item ) { m_children.removeAll( item ); }
// varies depending on the type of the item
virtual QString text() const { return QString(); }
virtual Qt::ItemFlags flags() const { return Qt::ItemIsSelectable | Qt::ItemIsEnabled; }
@ -51,7 +51,7 @@ public:
virtual QIcon icon() const { return QIcon(); }
virtual bool willAcceptDrag( const QMimeData* data ) const { return false; }
virtual bool dropMimeData( const QMimeData* data, Qt::DropAction action ) { return false; }
/// 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 endRowsAdded() { emit childRowsAdded(); }
@ -59,15 +59,15 @@ public:
void endRowsRemoved() { emit childRowsRemoved(); }
signals:
void updated();
void beginChildRowsAdded( int fromRow, int toRow );
void childRowsAdded();
void beginChildRowsRemoved( int fromRow, int toRow );
void childRowsRemoved();
private:
SourcesModel::RowType m_type;
SourceTreeItem* m_parent;
QList< SourceTreeItem* > m_children;
SourcesModel* m_model;
@ -79,12 +79,12 @@ class CategoryAddItem : public SourceTreeItem
public:
CategoryAddItem( SourcesModel* model, SourceTreeItem* parent, SourcesModel::CategoryType type );
~CategoryAddItem();
virtual Qt::ItemFlags flags() const;
virtual QString text() const;
virtual void activate();
virtual QIcon icon() const;
private:
SourcesModel::CategoryType m_categoryType;
};
@ -94,8 +94,8 @@ class CategoryItem : public SourceTreeItem
Q_OBJECT
public:
CategoryItem( SourcesModel* model, SourceTreeItem* parent, SourcesModel::CategoryType category, bool showAddItem );
virtual QString text() const {
virtual QString text() const {
switch( m_category )
{
case SourcesModel::PlaylistsCategory:
@ -107,13 +107,13 @@ public:
}
virtual void activate();
virtual Qt::ItemFlags flags() const { return Qt::ItemIsEnabled; }
// inserts an item at the end, but before the category add item
void insertItem( SourceTreeItem* item );
void insertItems( QList< SourceTreeItem* > item );
SourcesModel::CategoryType categoryType() { return m_category; }
private:
SourcesModel::CategoryType m_category;
CategoryAddItem* m_addItem;
@ -125,20 +125,20 @@ class CollectionItem : public SourceTreeItem
Q_OBJECT
public:
CollectionItem( SourcesModel* model, SourceTreeItem* parent, const Tomahawk::source_ptr& source );
virtual QString text() const;
virtual void activate();
virtual QIcon icon() const;
Tomahawk::source_ptr source() const;
private slots:
void onPlaylistsAdded( const QList<Tomahawk::playlist_ptr>& playlists );
void onPlaylistsDeleted( const QList<Tomahawk::playlist_ptr>& playlists );
private:
Tomahawk::source_ptr m_source;
CategoryItem* m_playlists;
CategoryItem* m_stations;
};
@ -148,7 +148,7 @@ class PlaylistItem : public SourceTreeItem
Q_OBJECT
public:
PlaylistItem( SourcesModel* model, SourceTreeItem* parent, const Tomahawk::playlist_ptr& pl, int index = -1 );
virtual QString text() const;
virtual Tomahawk::playlist_ptr playlist() const;
virtual Qt::ItemFlags flags() const;
@ -156,14 +156,14 @@ public:
virtual bool willAcceptDrag( const QMimeData* data ) const;
virtual bool dropMimeData( const QMimeData* data, Qt::DropAction action );
virtual QIcon icon() const;
protected:
void setLoaded( bool loaded );
private slots:
void onPlaylistLoaded( Tomahawk::PlaylistRevision revision );
void onPlaylistChanged();
private:
bool m_loaded;
Tomahawk::playlist_ptr m_playlist;
@ -175,15 +175,15 @@ class DynPlaylistItem : public PlaylistItem
Q_OBJECT
public:
DynPlaylistItem( SourcesModel* model, SourceTreeItem* parent, const Tomahawk::dynplaylist_ptr& pl );
virtual QString text() const;
virtual Tomahawk::playlist_ptr playlist() const;
// Tomahawk::dynplaylist_ptr playlist() const;
virtual void activate();
private slots:
void onDynamicPlaylistLoaded( Tomahawk::DynamicPlaylistRevision revision );
private:
Tomahawk::dynplaylist_ptr m_dynplaylist;
};*/
@ -195,15 +195,15 @@ class GenericPageItem : public SourceTreeItem
public:
GenericPageItem( SourcesModel* model, SourceTreeItem* parent, const QString& text, const QIcon& icon );
virtual ~GenericPageItem();
virtual QString text() const;
virtual void activate();
virtual bool willAcceptDrag( const QMimeData* data ) const;
virtual QIcon icon() const;
signals:
void activated();
private:
QIcon m_icon;
QString m_text;

View File

@ -19,7 +19,7 @@
#include "sourcetreeview.h"
#include "playlist.h"
#include "playlist/playlistmanager.h"
#include "viewmanager.h"
#include "sourcesproxymodel.h"
#include "sourcelist.h"
#include "sourcetree/sourcetreeitem.h"
@ -92,6 +92,8 @@ SourceTreeView::SourceTreeView( QWidget* parent )
m_model = new SourcesModel( this );
m_proxyModel = new SourcesProxyModel( m_model, this );
connect( m_proxyModel, SIGNAL( selectRequest( QModelIndex ) ), this, SLOT( selectRequest( QModelIndex ) ), Qt::QueuedConnection );
setModel( m_proxyModel );
header()->setStretchLastSection( false );
@ -104,17 +106,17 @@ SourceTreeView::SourceTreeView( QWidget* parent )
hideOfflineSources();
connect( PlaylistManager::instance(), SIGNAL( playlistActivated( Tomahawk::playlist_ptr ) ),
connect( ViewManager::instance(), SIGNAL( playlistActivated( Tomahawk::playlist_ptr ) ),
SLOT( onPlaylistActivated( Tomahawk::playlist_ptr ) ) );
// connect( PlaylistManager::instance(), SIGNAL( dynamicPlaylistActivated( Tomahawk::dynplaylist_ptr ) ),
// SLOT( onDynamicPlaylistActivated( Tomahawk::dynplaylist_ptr ) ) );
connect( PlaylistManager::instance(), SIGNAL( collectionActivated( Tomahawk::collection_ptr ) ),
connect( ViewManager::instance(), SIGNAL( collectionActivated( Tomahawk::collection_ptr ) ),
SLOT( onCollectionActivated( Tomahawk::collection_ptr ) ) );
connect( PlaylistManager::instance(), SIGNAL( superCollectionActivated() ),
connect( ViewManager::instance(), SIGNAL( superCollectionActivated() ),
SLOT( onSuperCollectionActivated() ) );
connect( PlaylistManager::instance(), SIGNAL( tempPageActivated() ),
connect( ViewManager::instance(), SIGNAL( tempPageActivated() ),
SLOT( onTempPageActivated() ) );
connect( PlaylistManager::instance(), SIGNAL( newPlaylistActivated() ),
connect( ViewManager::instance(), SIGNAL( newPlaylistActivated() ),
SLOT( onNewPlaylistPageActivated() ) );
}
@ -168,12 +170,12 @@ SourceTreeView::hideOfflineSources()
void
SourceTreeView::onPlaylistActivated( const Tomahawk::playlist_ptr& playlist )
{
QModelIndex idx = m_proxyModel->mapFromSource( m_model->indexFromPlaylist( playlist ) );
if ( idx.isValid() )
{
selectionModel()->select( idx, QItemSelectionModel::ClearAndSelect | QItemSelectionModel::Current );
// QModelIndex idx = m_proxyModel->mapFromSource( m_model->indexFromPlaylist( playlist ) );
// if ( idx.isValid() )
// {
// selectionModel()->select( idx, QItemSelectionModel::ClearAndSelect | QItemSelectionModel::Current );
// setCurrentIndex( idx );
}
// }
}
/*
@ -245,6 +247,14 @@ SourceTreeView::onItemExpanded( const QModelIndex& idx )
}
}
void
SourceTreeView::selectRequest( const QModelIndex& idx )
{
if( !selectionModel()->selectedIndexes().contains( idx ) )
selectionModel()->select( idx, QItemSelectionModel::ClearAndSelect | QItemSelectionModel::Current );
}
void
SourceTreeView::loadPlaylist()
@ -292,7 +302,9 @@ SourceTreeView::onCustomContextMenu( const QPoint& pos )
if ( model()->data( m_contextMenuIndex, SourcesModel::SourceTreeItemTypeRole ) == SourcesModel::StaticPlaylist )
{
m_playlistMenu.exec( mapToGlobal( pos ) );
PlaylistItem* item = itemFromIndex< PlaylistItem >( m_contextMenuIndex );
if( item->playlist()->author()->isLocal() )
m_playlistMenu.exec( mapToGlobal( pos ) );
}
}

View File

@ -55,8 +55,8 @@ private slots:
void onNewPlaylistPageActivated();
void onItemExpanded( const QModelIndex& idx );
void onItemActivated( const QModelIndex& index );
void selectRequest( const QModelIndex& idx );
void loadPlaylist();
void deletePlaylist();

View File

@ -39,7 +39,7 @@
#include "database/database.h"
#include "database/databasecommand_collectionstats.h"
#include "network/controlconnection.h"
#include "playlist/playlistmanager.h"
#include "viewmanager.h"
#include "sip/SipHandler.h"
#include "sourcetree/sourcetreeview.h"
#include "utils/animatedsplitter.h"
@ -77,7 +77,7 @@ TomahawkWindow::TomahawkWindow( QWidget* parent )
setUnifiedTitleAndToolBarOnMac( true );
#endif
PlaylistManager* pm = new PlaylistManager( this );
ViewManager* pm = new ViewManager( this );
connect( pm, SIGNAL( historyBackAvailable( bool ) ), SLOT( onHistoryBackAvailable( bool ) ) );
connect( pm, SIGNAL( historyForwardAvailable( bool ) ), SLOT( onHistoryForwardAvailable( bool ) ) );
@ -131,7 +131,7 @@ TomahawkWindow::TomahawkWindow( QWidget* parent )
buttonWidget->layout()->setSpacing( 0 );*/
ui->splitter->addWidget( sidebarWidget );
ui->splitter->addWidget( PlaylistManager::instance()->widget() );
ui->splitter->addWidget( ViewManager::instance()->widget() );
ui->splitter->setStretchFactor( 0, 1 );
ui->splitter->setStretchFactor( 1, 3 );
@ -167,8 +167,8 @@ TomahawkWindow::TomahawkWindow( QWidget* parent )
connect( checkForUpdates, SIGNAL( triggered() ), updater, SLOT( CheckNow() ) );
#endif
m_backAvailable = toolbar->addAction( QIcon( RESPATH "images/back.png" ), tr( "Back" ), PlaylistManager::instance(), SLOT( historyBack() ) );
m_forwardAvailable = toolbar->addAction( QIcon( RESPATH "images/forward.png" ), tr( "Forward" ), PlaylistManager::instance(), SLOT( historyForward() ) );
m_backAvailable = toolbar->addAction( QIcon( RESPATH "images/back.png" ), tr( "Back" ), ViewManager::instance(), SLOT( historyBack() ) );
m_forwardAvailable = toolbar->addAction( QIcon( RESPATH "images/forward.png" ), tr( "Forward" ), ViewManager::instance(), SLOT( historyForward() ) );
statusBar()->addPermanentWidget( m_audioControls, 1 );
@ -181,7 +181,7 @@ TomahawkWindow::TomahawkWindow( QWidget* parent )
loadSettings();
setupSignals();
PlaylistManager::instance()->showWelcomePage();
ViewManager::instance()->showWelcomePage();
}
@ -241,10 +241,10 @@ void
TomahawkWindow::setupSignals()
{
// <From PlaylistManager>
connect( PlaylistManager::instance(), SIGNAL( repeatModeChanged( PlaylistInterface::RepeatMode ) ),
connect( ViewManager::instance(), SIGNAL( repeatModeChanged( PlaylistInterface::RepeatMode ) ),
m_audioControls, SLOT( onRepeatModeChanged( PlaylistInterface::RepeatMode ) ) );
connect( PlaylistManager::instance(), SIGNAL( shuffleModeChanged( bool ) ),
connect( ViewManager::instance(), SIGNAL( shuffleModeChanged( bool ) ),
m_audioControls, SLOT( onShuffleModeChanged( bool ) ) );
// <From AudioEngine>
@ -403,7 +403,7 @@ TomahawkWindow::createAutomaticPlaylist()
dynplaylist_ptr playlist = DynamicPlaylist::create( author, id, name, info, creator, false );
playlist->setMode( Static );
playlist->createNewRevision( uuid(), playlist->currentrevision(), playlist->type(), playlist->generator()->controls(), playlist->entries() );
PlaylistManager::instance()->show( playlist );
ViewManager::instance()->show( playlist );
}
@ -422,14 +422,14 @@ TomahawkWindow::createStation()
dynplaylist_ptr playlist = DynamicPlaylist::create( author, id, name, info, creator, false );
playlist->setMode( OnDemand );
playlist->createNewRevision( uuid(), playlist->currentrevision(), playlist->type(), playlist->generator()->controls() );
PlaylistManager::instance()->show( playlist );
ViewManager::instance()->show( playlist );
}
void
TomahawkWindow::createPlaylist()
{
PlaylistManager::instance()->show( new NewPlaylistWidget() );
ViewManager::instance()->show( new NewPlaylistWidget() );
}