1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-03-19 15:29:42 +01:00

Finish refactoring playlistinterface...it's its own QObject, and it doesn't multiple inherit with any other classes for any implementations.

Dragons ahead, beware. Brave testers needed.
This commit is contained in:
Jeff Mitchell 2011-12-30 18:24:07 -05:00
parent 9fe40f0682
commit 2ea2b57d92
53 changed files with 1168 additions and 445 deletions

View File

@ -43,26 +43,32 @@ set( libGuiSources
playlist/treemodel.cpp
playlist/treeproxymodel.cpp
playlist/treeproxymodelplaylistinterface.cpp
playlist/treeheader.cpp
playlist/treeitemdelegate.cpp
playlist/collectionproxymodel.cpp
playlist/collectionproxymodelplaylistinterface.cpp
playlist/collectionflatmodel.cpp
playlist/collectionview.cpp
playlist/playlistmodel.cpp
playlist/playlistproxymodel.cpp
playlist/playlistproxymodelplaylistinterface.cpp
playlist/playlistview.cpp
playlist/playlistitemdelegate.cpp
playlist/queueproxymodel.cpp
playlist/queueproxymodelplaylistinterface.cpp
playlist/queueview.cpp
playlist/trackmodel.cpp
playlist/trackmodelitem.cpp
playlist/trackproxymodel.cpp
playlist/trackproxymodelplaylistinterface.cpp
playlist/trackview.cpp
playlist/trackheader.cpp
playlist/treemodelitem.cpp
playlist/albumitem.cpp
playlist/albummodel.cpp
playlist/albumproxymodel.cpp
playlist/albumproxymodelplaylistinterface.cpp
playlist/albumitemdelegate.cpp
playlist/albumview.cpp
playlist/artistview.cpp
@ -170,26 +176,32 @@ set( libGuiHeaders
playlist/treemodel.h
playlist/treeproxymodel.h
playlist/treeproxymodelplaylistinterface.h
playlist/treeheader.h
playlist/treeitemdelegate.h
playlist/collectionproxymodel.h
playlist/collectionproxymodelplaylistinterface.h
playlist/collectionflatmodel.h
playlist/collectionview.h
playlist/playlistmodel.h
playlist/playlistproxymodel.h
playlist/playlistproxymodelplaylistinterface.h
playlist/playlistview.h
playlist/playlistitemdelegate.h
playlist/queueproxymodel.h
playlist/queueproxymodelplaylistinterface.h
playlist/queueview.h
playlist/trackmodel.h
playlist/trackmodelitem.h
playlist/trackproxymodel.h
playlist/trackproxymodelplaylistinterface.h
playlist/trackview.h
playlist/trackheader.h
playlist/treemodelitem.h
playlist/albumitem.h
playlist/albummodel.h
playlist/albumproxymodel.h
playlist/albumproxymodelplaylistinterface.h
playlist/albumitemdelegate.h
playlist/albumview.h
playlist/artistview.h
@ -406,6 +418,8 @@ set( libHeaders
pipeline.h
functimeout.h
playlistinterface.h
aclsystem.h
collection.h
query.h

View File

@ -64,6 +64,6 @@ private:
Tomahawk::playlistinterface_ptr m_playlistInterface;
};
}; // ns
} // ns
#endif

View File

@ -31,7 +31,7 @@ using namespace Tomahawk;
AlbumPlaylistInterface::AlbumPlaylistInterface() {}
AlbumPlaylistInterface::AlbumPlaylistInterface( Tomahawk::Album *album )
: Tomahawk::PlaylistInterface( this )
: Tomahawk::PlaylistInterface()
, m_currentItem( 0 )
, m_currentTrack( 0 )
, m_album( QWeakPointer< Tomahawk::Album >( album ) )

View File

@ -32,7 +32,7 @@ namespace Tomahawk
class Album;
class DLLEXPORT AlbumPlaylistInterface : public QObject, public Tomahawk::PlaylistInterface
class DLLEXPORT AlbumPlaylistInterface : public Tomahawk::PlaylistInterface
{
Q_OBJECT
@ -60,8 +60,6 @@ public:
virtual void addQueries( const QList<Tomahawk::query_ptr>& tracks );
virtual void findMoreIfaces() {}
signals:
void repeatModeChanged( PlaylistInterface::RepeatMode mode );
void shuffleModeChanged( bool enabled );

View File

@ -31,7 +31,7 @@ namespace Tomahawk
class Artist;
class DLLEXPORT ArtistPlaylistInterface : public QObject, public Tomahawk::PlaylistInterface
class DLLEXPORT ArtistPlaylistInterface : public Tomahawk::PlaylistInterface
{
Q_OBJECT
@ -59,8 +59,6 @@ public:
virtual void addQueries( const QList<Tomahawk::query_ptr>& tracks );
virtual void findMoreIfaces() {}
signals:
void repeatModeChanged( PlaylistInterface::RepeatMode mode );
void shuffleModeChanged( bool enabled );

View File

@ -562,7 +562,7 @@ AudioEngine::playItem( Tomahawk::playlistinterface_ptr playlist, const Tomahawk:
m_playlist.data()->reset();
setPlaylist( playlist );
m_currentTrackPlaylist = playlist->getSharedPointer();
m_currentTrackPlaylist = playlist;
if ( !result.isNull() )
loadTrack( result );
@ -682,8 +682,8 @@ AudioEngine::setPlaylist( Tomahawk::playlistinterface_ptr playlist )
{
if ( !m_playlist.isNull() )
{
if ( m_playlist.data()->object() && m_playlist.data()->retryMode() == PlaylistInterface::Retry )
disconnect( m_playlist.data()->object(), SIGNAL( nextTrackReady() ) );
if ( m_playlist.data() && m_playlist.data()->retryMode() == PlaylistInterface::Retry )
disconnect( m_playlist.data(), SIGNAL( nextTrackReady() ) );
m_playlist.data()->reset();
}
@ -694,10 +694,10 @@ AudioEngine::setPlaylist( Tomahawk::playlistinterface_ptr playlist )
return;
}
m_playlist = playlist.data()->getSharedPointer();
m_playlist = playlist;
if ( m_playlist.data()->object() && m_playlist.data()->retryMode() == PlaylistInterface::Retry )
connect( m_playlist.data()->object(), SIGNAL( nextTrackReady() ), SLOT( playlistNextTrackReady() ) );
if ( !m_playlist.isNull() && m_playlist.data() && m_playlist.data()->retryMode() == PlaylistInterface::Retry )
connect( m_playlist.data(), SIGNAL( nextTrackReady() ), SLOT( playlistNextTrackReady() ) );
emit playlistChanged( playlist );
}

View File

@ -92,7 +92,7 @@ public slots:
void playItem( Tomahawk::playlistinterface_ptr playlist, const Tomahawk::result_ptr& result );
void setPlaylist( Tomahawk::playlistinterface_ptr playlist );
void setQueue( Tomahawk::playlistinterface_ptr queue ) { m_queue = queue.data()->getSharedPointer(); }
void setQueue( Tomahawk::playlistinterface_ptr queue ) { m_queue = queue; }
void playlistNextTrackReady();

View File

@ -20,6 +20,7 @@
#include <QListView>
#include "albumproxymodelplaylistinterface.h"
#include "artist.h"
#include "albumitem.h"
#include "query.h"
@ -28,10 +29,7 @@
AlbumProxyModel::AlbumProxyModel( QObject* parent )
: QSortFilterProxyModel( parent )
, PlaylistInterface( this )
, m_model( 0 )
, m_repeatMode( PlaylistInterface::NoRepeat )
, m_shuffled( false )
{
setFilterCaseSensitivity( Qt::CaseInsensitive );
setSortCaseSensitivity( Qt::CaseInsensitive );
@ -61,29 +59,6 @@ AlbumProxyModel::setSourceAlbumModel( AlbumModel* sourceModel )
QSortFilterProxyModel::setSourceModel( sourceModel );
}
QList< Tomahawk::query_ptr >
AlbumProxyModel::tracks()
{
Q_ASSERT( FALSE );
QList<Tomahawk::query_ptr> queries;
return queries;
}
Tomahawk::result_ptr
AlbumProxyModel::currentItem() const
{
return Tomahawk::result_ptr();
}
void
AlbumProxyModel::setFilter( const QString& pattern )
{
qDebug() << Q_FUNC_INFO;
setFilterRegExp( pattern );
emit filterChanged( pattern );
}
bool
AlbumProxyModel::filterAcceptsRow( int sourceRow, const QModelIndex& sourceParent ) const
@ -165,10 +140,13 @@ AlbumProxyModel::removeIndexes( const QList<QModelIndex>& indexes )
}
Tomahawk::result_ptr
AlbumProxyModel::siblingItem( int itemsAway )
Tomahawk::playlistinterface_ptr
AlbumProxyModel::getPlaylistInterface()
{
Q_UNUSED( itemsAway );
qDebug() << Q_FUNC_INFO;
return Tomahawk::result_ptr( 0 );
if ( m_playlistInterface.isNull() )
{
m_playlistInterface = Tomahawk::playlistinterface_ptr( new Tomahawk::AlbumProxyModelPlaylistInterface( this ) );
}
return m_playlistInterface;
}

View File

@ -26,7 +26,7 @@
#include "dllmacro.h"
class DLLEXPORT AlbumProxyModel : public QSortFilterProxyModel, public Tomahawk::PlaylistInterface
class DLLEXPORT AlbumProxyModel : public QSortFilterProxyModel
{
Q_OBJECT
@ -38,48 +38,26 @@ public:
virtual void setSourceAlbumModel( AlbumModel* sourceModel );
virtual void setSourceModel( QAbstractItemModel* sourceModel );
virtual QList<Tomahawk::query_ptr> tracks();
virtual int unfilteredTrackCount() const { return sourceModel()->rowCount( QModelIndex() ); }
virtual int trackCount() const { return rowCount( QModelIndex() ); }
virtual int albumCount() const { return rowCount( QModelIndex() ); }
virtual void removeIndex( const QModelIndex& index );
virtual void removeIndexes( const QList<QModelIndex>& indexes );
virtual bool hasNextItem() { return true; }
virtual Tomahawk::result_ptr currentItem() const;
virtual Tomahawk::result_ptr siblingItem( int direction );
virtual void emitFilterChanged( const QString &pattern ) { emit filterChanged( pattern ); }
virtual void setFilter( const QString& pattern );
virtual Tomahawk::PlaylistInterface::RepeatMode repeatMode() const { return m_repeatMode; }
virtual bool shuffled() const { return m_shuffled; }
virtual Tomahawk::PlaylistInterface::ViewMode viewMode() const { return Tomahawk::PlaylistInterface::Album; }
virtual Tomahawk::playlistinterface_ptr getPlaylistInterface();
signals:
void repeatModeChanged( Tomahawk::PlaylistInterface::RepeatMode mode );
void shuffleModeChanged( bool enabled );
void trackCountChanged( unsigned int tracks );
void sourceTrackCountChanged( unsigned int tracks );
void filterChanged( const QString& filter );
void nextTrackReady();
public slots:
virtual void setRepeatMode( RepeatMode mode ) { m_repeatMode = mode; emit repeatModeChanged( mode ); }
virtual void setShuffled( bool enabled ) { m_shuffled = enabled; emit shuffleModeChanged( enabled ); }
protected:
bool filterAcceptsRow( int sourceRow, const QModelIndex& sourceParent ) const;
bool lessThan( const QModelIndex& left, const QModelIndex& right ) const;
private:
AlbumModel* m_model;
RepeatMode m_repeatMode;
bool m_shuffled;
Tomahawk::playlistinterface_ptr m_playlistInterface;
};
#endif // ALBUMPROXYMODEL_H

View File

@ -0,0 +1,100 @@
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
*
* Copyright 2010-2011, 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
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Tomahawk is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Tomahawk. If not, see <http://www.gnu.org/licenses/>.
*/
#include "albumproxymodelplaylistinterface.h"
#include "albumproxymodel.h"
#include "artist.h"
#include "albumitem.h"
#include "query.h"
#include "utils/logger.h"
using namespace Tomahawk;
AlbumProxyModelPlaylistInterface::AlbumProxyModelPlaylistInterface( AlbumProxyModel *proxyModel )
: Tomahawk::PlaylistInterface()
, m_proxyModel( proxyModel )
, m_repeatMode( PlaylistInterface::NoRepeat )
, m_shuffled( false )
{
}
AlbumProxyModelPlaylistInterface::~AlbumProxyModelPlaylistInterface()
{
m_proxyModel.clear();
}
QList< Tomahawk::query_ptr >
AlbumProxyModelPlaylistInterface::tracks()
{
Q_ASSERT( FALSE );
QList<Tomahawk::query_ptr> queries;
return queries;
}
int
AlbumProxyModelPlaylistInterface::unfilteredTrackCount() const
{
return ( m_proxyModel.isNull() ? 0 : m_proxyModel.data()->sourceModel()->rowCount( QModelIndex() ) );
}
int
AlbumProxyModelPlaylistInterface::trackCount() const
{
return ( m_proxyModel.isNull() ? 0 : m_proxyModel.data()->rowCount( QModelIndex() ) );
}
Tomahawk::result_ptr
AlbumProxyModelPlaylistInterface::currentItem() const
{
return Tomahawk::result_ptr();
}
QString
AlbumProxyModelPlaylistInterface::filter() const
{
return ( m_proxyModel.isNull() ? QString() : m_proxyModel.data()->filterRegExp().pattern() );
}
void
AlbumProxyModelPlaylistInterface::setFilter( const QString& pattern )
{
qDebug() << Q_FUNC_INFO;
if ( m_proxyModel.isNull() )
return;
m_proxyModel.data()->setFilterRegExp( pattern );
m_proxyModel.data()->emitFilterChanged( pattern );
}
Tomahawk::result_ptr
AlbumProxyModelPlaylistInterface::siblingItem( int itemsAway )
{
Q_UNUSED( itemsAway );
qDebug() << Q_FUNC_INFO;
return Tomahawk::result_ptr( 0 );
}

View File

@ -0,0 +1,77 @@
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
*
* Copyright 2010-2011, 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
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Tomahawk is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Tomahawk. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef ALBUMPROXYMODELPLAYLISTINTERFACE_H
#define ALBUMPROXYMODELPLAYLISTINTERFACE_H
#include "playlistinterface.h"
#include "playlist/albummodel.h"
#include "dllmacro.h"
class AlbumProxyModel;
namespace Tomahawk
{
class DLLEXPORT AlbumProxyModelPlaylistInterface : public Tomahawk::PlaylistInterface
{
Q_OBJECT
public:
explicit AlbumProxyModelPlaylistInterface( AlbumProxyModel *proxyModel );
virtual ~AlbumProxyModelPlaylistInterface();
virtual QList<Tomahawk::query_ptr> tracks();
virtual int unfilteredTrackCount() const;
virtual int trackCount() const;
virtual bool hasNextItem() { return true; }
virtual Tomahawk::result_ptr currentItem() const;
virtual Tomahawk::result_ptr siblingItem( int direction );
virtual QString filter() const;
virtual void setFilter( const QString& pattern );
virtual Tomahawk::PlaylistInterface::RepeatMode repeatMode() const { return m_repeatMode; }
virtual bool shuffled() const { return m_shuffled; }
virtual Tomahawk::PlaylistInterface::ViewMode viewMode() const { return Tomahawk::PlaylistInterface::Album; }
signals:
void repeatModeChanged( Tomahawk::PlaylistInterface::RepeatMode mode );
void shuffleModeChanged( bool enabled );
void trackCountChanged( unsigned int tracks );
void sourceTrackCountChanged( unsigned int tracks );
void nextTrackReady();
public slots:
virtual void setRepeatMode( RepeatMode mode ) { m_repeatMode = mode; emit repeatModeChanged( mode ); }
virtual void setShuffled( bool enabled ) { m_shuffled = enabled; emit shuffleModeChanged( enabled ); }
private:
QWeakPointer< AlbumProxyModel > m_proxyModel;
RepeatMode m_repeatMode;
bool m_shuffled;
};
} //ns
#endif // ALBUMPROXYMODELPLAYLISTINTERFACE_H

View File

@ -53,7 +53,7 @@ public:
void setModel( QAbstractItemModel* model );
virtual QWidget* widget() { return this; }
virtual Tomahawk::playlistinterface_ptr playlistInterface() const { return proxyModel()->getSharedPointer(); }
virtual Tomahawk::playlistinterface_ptr playlistInterface() const { return proxyModel()->getPlaylistInterface(); }
virtual QString title() const { return m_model->title(); }
virtual QString description() const { return m_model->description(); }

View File

@ -188,7 +188,7 @@ ArtistView::onItemActivated( const QModelIndex& index )
else if ( !item->result().isNull() && item->result()->isOnline() )
{
m_model->setCurrentItem( item->index );
AudioEngine::instance()->playItem( m_proxyModel->getSharedPointer(), item->result() );
AudioEngine::instance()->playItem( m_proxyModel->getPlaylistInterface(), item->result() );
}
}
}
@ -248,9 +248,9 @@ ArtistView::onFilterChanged( const QString& )
if ( selectedIndexes().count() )
scrollTo( selectedIndexes().at( 0 ), QAbstractItemView::PositionAtCenter );
if ( !proxyModel()->filter().isEmpty() && !proxyModel()->trackCount() && model()->trackCount() )
if ( !proxyModel()->getPlaylistInterface()->filter().isEmpty() && !proxyModel()->getPlaylistInterface()->trackCount() && model()->trackCount() )
{
m_overlay->setText( tr( "Sorry, your filter '%1' did not match any results." ).arg( proxyModel()->filter() ) );
m_overlay->setText( tr( "Sorry, your filter '%1' did not match any results." ).arg( proxyModel()->getPlaylistInterface()->filter() ) );
m_overlay->show();
}
else
@ -332,7 +332,7 @@ ArtistView::onScrollTimeout()
while ( right.isValid() && right.parent().isValid() )
right = right.parent();
int max = m_proxyModel->trackCount();
int max = m_proxyModel->getPlaylistInterface()->trackCount();
if ( right.isValid() )
max = right.row() + 1;

View File

@ -62,7 +62,7 @@ public:
void setTreeModel( TreeModel* model );
virtual QWidget* widget() { return this; }
virtual Tomahawk::playlistinterface_ptr playlistInterface() const { return proxyModel()->getSharedPointer(); }
virtual Tomahawk::playlistinterface_ptr playlistInterface() const { return proxyModel()->getPlaylistInterface(); }
virtual QString title() const { return m_model->title(); }
virtual QString description() const { return m_model->description(); }

View File

@ -18,6 +18,8 @@
#include "collectionproxymodel.h"
#include "collectionproxymodelplaylistinterface.h"
#include <QTreeView>
#include "album.h"
@ -29,3 +31,14 @@ CollectionProxyModel::CollectionProxyModel( QObject* parent )
: TrackProxyModel( parent )
{
}
Tomahawk::playlistinterface_ptr
CollectionProxyModel::getPlaylistInterface()
{
if ( m_playlistInterface.isNull() )
{
m_playlistInterface = Tomahawk::playlistinterface_ptr( new Tomahawk::CollectionProxyModelPlaylistInterface( this ) );
}
return m_playlistInterface;
}

View File

@ -20,6 +20,7 @@
#define COLLECTIONPROXYMODEL_H
#include "trackproxymodel.h"
#include "trackproxymodelplaylistinterface.h"
#include "dllmacro.h"
@ -29,8 +30,10 @@ Q_OBJECT
public:
explicit CollectionProxyModel( QObject* parent = 0 );
virtual ~CollectionProxyModel() {}
virtual Tomahawk::playlistinterface_ptr getPlaylistInterface();
virtual PlaylistInterface::ViewMode viewMode() const { return PlaylistInterface::Flat; }
};
#endif // COLLECTIONPROXYMODEL_H

View File

@ -0,0 +1,36 @@
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
*
* Copyright 2010-2011, 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
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Tomahawk is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Tomahawk. If not, see <http://www.gnu.org/licenses/>.
*/
#include "collectionproxymodelplaylistinterface.h"
#include "collectionproxymodel.h"
#include "album.h"
#include "query.h"
#include "utils/logger.h"
using namespace Tomahawk;
CollectionProxyModelPlaylistInterface::CollectionProxyModelPlaylistInterface( CollectionProxyModel *proxyModel )
: TrackProxyModelPlaylistInterface( proxyModel )
{
}
CollectionProxyModelPlaylistInterface::~CollectionProxyModelPlaylistInterface()
{
m_proxyModel.clear();
}

View File

@ -0,0 +1,45 @@
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
*
* Copyright 2010-2011, 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
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Tomahawk is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Tomahawk. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef COLLECTIONPROXYMODELPLAYLISTINTERFACE_H
#define COLLECTIONPROXYMODELPLAYLISTINTERFACE_H
#include "trackproxymodel.h"
#include "trackproxymodelplaylistinterface.h"
#include "dllmacro.h"
class CollectionProxyModel;
namespace Tomahawk
{
class DLLEXPORT CollectionProxyModelPlaylistInterface : public TrackProxyModelPlaylistInterface
{
Q_OBJECT
public:
explicit CollectionProxyModelPlaylistInterface( CollectionProxyModel* proxyModel );
virtual ~CollectionProxyModelPlaylistInterface();
virtual PlaylistInterface::ViewMode viewMode() const { return PlaylistInterface::Flat; }
};
} //ns
#endif // COLLECTIONPROXYMODELPLAYLISTINTERFACE_H

View File

@ -39,7 +39,7 @@ public:
virtual void setModel( QAbstractItemModel* model );
virtual QWidget* widget() { return this; }
virtual Tomahawk::playlistinterface_ptr playlistInterface() const { return proxyModel()->getSharedPointer(); }
virtual Tomahawk::playlistinterface_ptr playlistInterface() const { return proxyModel()->getPlaylistInterface(); }
virtual QString title() const { return model()->title(); }
virtual QString description() const { return model()->description(); }

View File

@ -203,7 +203,7 @@ DynamicWidget::onRevisionLoaded( const Tomahawk::DynamicPlaylistRevision& rev )
Tomahawk::playlistinterface_ptr
DynamicWidget::playlistInterface() const
{
return m_view->proxyModel()->getSharedPointer();
return m_view->proxyModel()->getPlaylistInterface();
}
@ -243,7 +243,7 @@ DynamicWidget::layoutFloatingWidgets()
void
DynamicWidget::playlistChanged( Tomahawk::playlistinterface_ptr pl )
{
if( pl == m_view->proxyModel()->getSharedPointer() ) { // same playlist
if( pl == m_view->proxyModel()->getPlaylistInterface() ) { // same playlist
m_activePlaylist = true;
} else {
m_activePlaylist = false;

View File

@ -18,6 +18,7 @@
#include "playlistproxymodel.h"
#include "playlistproxymodelplaylistinterface.h"
#include "utils/logger.h"
@ -25,3 +26,14 @@ PlaylistProxyModel::PlaylistProxyModel( QObject* parent )
: TrackProxyModel( parent )
{
}
Tomahawk::playlistinterface_ptr
PlaylistProxyModel::getPlaylistInterface()
{
if ( m_playlistInterface.isNull() )
{
m_playlistInterface = Tomahawk::playlistinterface_ptr( new Tomahawk::PlaylistProxyModelPlaylistInterface( this ) );
}
return m_playlistInterface;
}

View File

@ -1,5 +1,5 @@
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
*
*
* Copyright 2010-2011, Christian Muehlhaeuser <muesli@tomahawk-player.org>
*
* Tomahawk is free software: you can redistribute it and/or modify
@ -30,6 +30,8 @@ Q_OBJECT
public:
explicit PlaylistProxyModel( QObject* parent = 0 );
virtual ~PlaylistProxyModel() {}
virtual Tomahawk::playlistinterface_ptr getPlaylistInterface();
};
#endif // PLAYLISTPROXYMODEL_H

View File

@ -0,0 +1,34 @@
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
*
* Copyright 2010-2011, 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
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Tomahawk is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Tomahawk. If not, see <http://www.gnu.org/licenses/>.
*/
#include "playlistproxymodelplaylistinterface.h"
#include "playlistproxymodel.h"
#include "utils/logger.h"
using namespace Tomahawk;
PlaylistProxyModelPlaylistInterface::PlaylistProxyModelPlaylistInterface( PlaylistProxyModel *proxyModel )
: TrackProxyModelPlaylistInterface( proxyModel )
{
}
PlaylistProxyModelPlaylistInterface::~PlaylistProxyModelPlaylistInterface()
{
m_proxyModel.clear();
}

View File

@ -0,0 +1,42 @@
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
*
* Copyright 2010-2011, 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
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Tomahawk is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Tomahawk. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef PLAYLISTPROXYMODELPLAYLISTINTERFACE_H
#define PLAYLISTPROXYMODELPLAYLISTINTERFACE_H
#include "trackproxymodelplaylistinterface.h"
#include "dllmacro.h"
class PlaylistProxyModel;
namespace Tomahawk
{
class DLLEXPORT PlaylistProxyModelPlaylistInterface : public TrackProxyModelPlaylistInterface
{
Q_OBJECT
public:
explicit PlaylistProxyModelPlaylistInterface( PlaylistProxyModel *proxyModel );
virtual ~PlaylistProxyModelPlaylistInterface();
};
} //ns
#endif // PLAYLISTPROXYMODELPLAYLISTINTERFACE_H

View File

@ -38,7 +38,7 @@ public:
virtual void setModel( QAbstractItemModel* model );
virtual QWidget* widget() { return this; }
virtual Tomahawk::playlistinterface_ptr playlistInterface() const { return proxyModel()->getSharedPointer(); }
virtual Tomahawk::playlistinterface_ptr playlistInterface() const { return proxyModel()->getPlaylistInterface(); }
virtual bool showFilter() const { return true; }

View File

@ -18,6 +18,7 @@
#include "queueproxymodel.h"
#include "queueproxymodelplaylistinterface.h"
#include "playlist/trackview.h"
#include "viewmanager.h"
#include "utils/logger.h"
@ -48,21 +49,21 @@ QueueProxyModel::onIndexActivated( const QModelIndex& index )
}
Tomahawk::result_ptr
QueueProxyModel::siblingItem( int itemsAway )
{
setCurrentIndex( QModelIndex() );
Tomahawk::result_ptr res = PlaylistProxyModel::siblingItem( itemsAway );
remove( currentIndex() );
return res;
}
void
QueueProxyModel::onTrackCountChanged( unsigned int count )
{
if ( count == 0 )
ViewManager::instance()->hideQueue();
}
Tomahawk::playlistinterface_ptr
QueueProxyModel::getPlaylistInterface()
{
if ( m_playlistInterface.isNull() )
{
m_playlistInterface = Tomahawk::playlistinterface_ptr( new Tomahawk::QueueProxyModelPlaylistInterface( this ) );
}
return m_playlistInterface;
}

View File

@ -32,11 +32,9 @@ Q_OBJECT
public:
explicit QueueProxyModel( TrackView* parent = 0 );
~QueueProxyModel();
virtual ~QueueProxyModel();
virtual Tomahawk::result_ptr siblingItem( int itemsAway );
using PlaylistProxyModel::siblingItem;
virtual Tomahawk::playlistinterface_ptr getPlaylistInterface();
private slots:
void onIndexActivated( const QModelIndex& index );

View File

@ -0,0 +1,50 @@
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
*
* Copyright 2010-2011, 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
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Tomahawk is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Tomahawk. If not, see <http://www.gnu.org/licenses/>.
*/
#include "queueproxymodelplaylistinterface.h"
#include "queueproxymodel.h"
#include "utils/logger.h"
using namespace Tomahawk;
QueueProxyModelPlaylistInterface::QueueProxyModelPlaylistInterface( QueueProxyModel *proxyModel )
: PlaylistProxyModelPlaylistInterface( proxyModel )
{
}
QueueProxyModelPlaylistInterface::~QueueProxyModelPlaylistInterface()
{
m_proxyModel.clear();
}
Tomahawk::result_ptr
QueueProxyModelPlaylistInterface::siblingItem( int itemsAway )
{
if ( m_proxyModel.isNull() )
return Tomahawk::result_ptr();
m_proxyModel.data()->setCurrentIndex( QModelIndex() );
Tomahawk::result_ptr res = PlaylistProxyModelPlaylistInterface::siblingItem( itemsAway );
m_proxyModel.data()->remove( m_proxyModel.data()->currentIndex() );
return res;
}

View File

@ -0,0 +1,44 @@
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
*
* Copyright 2010-2011, 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
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Tomahawk is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Tomahawk. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef QUEUEPROXYMODELPLAYLISTINTERFACE_H
#define QUEUEPROXYMODELPLAYLISTINTERFACE_H
#include "playlistproxymodelplaylistinterface.h"
#include "dllmacro.h"
class QueueProxyModel;
namespace Tomahawk
{
class DLLEXPORT QueueProxyModelPlaylistInterface : public PlaylistProxyModelPlaylistInterface
{
Q_OBJECT
public:
explicit QueueProxyModelPlaylistInterface( QueueProxyModel *proxyModel );
virtual ~QueueProxyModelPlaylistInterface();
virtual Tomahawk::result_ptr siblingItem( int itemsAway );
};
} //ns
#endif // QUEUEPROXYMODELPLAYLISTINTERFACE_H

View File

@ -20,6 +20,7 @@
#include <QTreeView>
#include "trackproxymodelplaylistinterface.h"
#include "artist.h"
#include "album.h"
#include "query.h"
@ -28,10 +29,7 @@
TrackProxyModel::TrackProxyModel( QObject* parent )
: QSortFilterProxyModel( parent )
, PlaylistInterface( this )
, m_model( 0 )
, m_repeatMode( PlaylistInterface::NoRepeat )
, m_shuffled( false )
, m_showOfflineResults( true )
{
setFilterCaseSensitivity( Qt::CaseInsensitive );
@ -63,120 +61,6 @@ TrackProxyModel::setSourceTrackModel( TrackModel* sourceModel )
}
void
TrackProxyModel::setFilter( const QString& pattern )
{
PlaylistInterface::setFilter( pattern );
setFilterRegExp( pattern );
emit filterChanged( pattern );
emit trackCountChanged( trackCount() );
}
QList< Tomahawk::query_ptr >
TrackProxyModel::tracks()
{
QList<Tomahawk::query_ptr> queries;
for ( int i = 0; i < rowCount( QModelIndex() ); i++ )
{
TrackModelItem* item = itemFromIndex( mapToSource( index( i, 0 ) ) );
if ( item )
queries << item->query();
}
return queries;
}
Tomahawk::result_ptr
TrackProxyModel::siblingItem( int itemsAway )
{
return siblingItem( itemsAway, false );
}
bool
TrackProxyModel::hasNextItem()
{
return !( siblingItem( 1, true ).isNull() );
}
Tomahawk::result_ptr
TrackProxyModel::siblingItem( int itemsAway, bool readOnly )
{
qDebug() << Q_FUNC_INFO;
QModelIndex idx = index( 0, 0 );
if ( rowCount() )
{
if ( m_shuffled )
{
// random mode is enabled
// TODO come up with a clever random logic, that keeps track of previously played items
idx = index( qrand() % rowCount(), 0 );
}
else if ( currentIndex().isValid() )
{
idx = currentIndex();
// random mode is disabled
if ( m_repeatMode != PlaylistInterface::RepeatOne )
{
// keep progressing through the playlist normally
idx = index( idx.row() + itemsAway, 0 );
}
}
}
if ( !idx.isValid() && m_repeatMode == PlaylistInterface::RepeatAll )
{
// repeat all tracks
if ( itemsAway > 0 )
{
// reset to first item
idx = index( 0, 0 );
}
else
{
// reset to last item
idx = index( rowCount() - 1, 0 );
}
}
// Try to find the next available PlaylistItem (with results)
while ( idx.isValid() )
{
TrackModelItem* item = itemFromIndex( mapToSource( idx ) );
if ( item && item->query()->playable() )
{
qDebug() << "Next PlaylistItem found:" << item->query()->toString() << item->query()->results().at( 0 )->url();
if ( !readOnly )
setCurrentIndex( idx );
return item->query()->results().at( 0 );
}
idx = index( idx.row() + ( itemsAway > 0 ? 1 : -1 ), 0 );
}
if ( !readOnly )
setCurrentIndex( QModelIndex() );
return Tomahawk::result_ptr();
}
Tomahawk::result_ptr
TrackProxyModel::currentItem() const
{
TrackModelItem* item = itemFromIndex( mapToSource( currentIndex() ) );
if ( item && !item->query().isNull() && item->query()->playable() )
return item->query()->results().at( 0 );
return Tomahawk::result_ptr();
}
bool
TrackProxyModel::filterAcceptsRow( int sourceRow, const QModelIndex& sourceParent ) const
{
@ -388,3 +272,15 @@ TrackProxyModel::lessThan( const QModelIndex& left, const QModelIndex& right ) c
return QString::localeAwareCompare( lefts, rights ) < 0;
}
Tomahawk::playlistinterface_ptr
TrackProxyModel::getPlaylistInterface()
{
if ( m_playlistInterface.isNull() )
{
m_playlistInterface = Tomahawk::playlistinterface_ptr( new Tomahawk::TrackProxyModelPlaylistInterface( this ) );
}
return m_playlistInterface;
}

View File

@ -26,14 +26,14 @@
#include "dllmacro.h"
class DLLEXPORT TrackProxyModel : public QSortFilterProxyModel, public Tomahawk::PlaylistInterface
class DLLEXPORT TrackProxyModel : public QSortFilterProxyModel
{
Q_OBJECT
public:
explicit TrackProxyModel ( QObject* parent = 0 );
virtual ~TrackProxyModel() {}
virtual TrackModel* sourceModel() const { return m_model; }
virtual void setSourceTrackModel( TrackModel* sourceModel );
virtual void setSourceModel( QAbstractItemModel* model );
@ -41,55 +41,29 @@ public:
virtual QPersistentModelIndex currentIndex() const { return mapFromSource( m_model->currentItem() ); }
virtual void setCurrentIndex( const QModelIndex& index ) { m_model->setCurrentItem( mapToSource( index ) ); }
virtual QList<Tomahawk::query_ptr> tracks();
virtual int unfilteredTrackCount() const { return sourceModel()->trackCount(); }
virtual int trackCount() const { return rowCount( QModelIndex() ); }
virtual void remove( const QModelIndex& index );
virtual void remove( const QModelIndexList& indexes );
virtual void remove( const QList< QPersistentModelIndex >& indexes );
virtual Tomahawk::result_ptr currentItem() const;
virtual Tomahawk::result_ptr siblingItem( int itemsAway );
virtual Tomahawk::result_ptr siblingItem( int itemsAway, bool readOnly );
virtual bool hasNextItem();
virtual bool showOfflineResults() const { return m_showOfflineResults; }
virtual void setShowOfflineResults( bool b ) { m_showOfflineResults = b; }
virtual QString filter() const { return filterRegExp().pattern(); }
virtual void setFilter( const QString& pattern );
virtual void emitFilterChanged( const QString &pattern ) { emit filterChanged( pattern ); }
virtual PlaylistInterface::RepeatMode repeatMode() const { return m_repeatMode; }
virtual bool shuffled() const { return m_shuffled; }
virtual TrackModelItem* itemFromIndex( const QModelIndex& index ) const { return sourceModel()->itemFromIndex( index ); }
bool showOfflineResults() const { return m_showOfflineResults; }
void setShowOfflineResults( bool b ) { m_showOfflineResults = b; }
TrackModelItem* itemFromIndex( const QModelIndex& index ) const { return sourceModel()->itemFromIndex( index ); }
virtual Tomahawk::playlistinterface_ptr getPlaylistInterface();
signals:
void repeatModeChanged( Tomahawk::PlaylistInterface::RepeatMode mode );
void shuffleModeChanged( bool enabled );
void trackCountChanged( unsigned int tracks );
void sourceTrackCountChanged( unsigned int tracks );
void filterChanged( const QString& filter );
void nextTrackReady();
public slots:
virtual void setRepeatMode( RepeatMode mode ) { m_repeatMode = mode; emit repeatModeChanged( mode ); }
virtual void setShuffled( bool enabled ) { m_shuffled = enabled; emit shuffleModeChanged( enabled ); }
protected:
bool filterAcceptsRow( int sourceRow, const QModelIndex& sourceParent ) const;
bool lessThan( const QModelIndex& left, const QModelIndex& right ) const;
virtual bool filterAcceptsRow( int sourceRow, const QModelIndex& sourceParent ) const;
virtual bool lessThan( const QModelIndex& left, const QModelIndex& right ) const;
private:
TrackModel* m_model;
RepeatMode m_repeatMode;
bool m_shuffled;
bool m_showOfflineResults;
Tomahawk::playlistinterface_ptr m_playlistInterface;
};
#endif // TRACKPROXYMODEL_H

View File

@ -0,0 +1,193 @@
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
*
* Copyright 2010-2011, 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
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Tomahawk is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Tomahawk. If not, see <http://www.gnu.org/licenses/>.
*/
#include "trackproxymodelplaylistinterface.h"
#include "trackproxymodel.h"
#include "artist.h"
#include "album.h"
#include "query.h"
#include "utils/logger.h"
using namespace Tomahawk;
TrackProxyModelPlaylistInterface::TrackProxyModelPlaylistInterface( TrackProxyModel* proxyModel )
: PlaylistInterface()
, m_proxyModel( proxyModel )
, m_repeatMode( PlaylistInterface::NoRepeat )
, m_shuffled( false )
{
}
TrackProxyModelPlaylistInterface::~TrackProxyModelPlaylistInterface()
{
m_proxyModel.clear();
}
int
TrackProxyModelPlaylistInterface::unfilteredTrackCount() const
{
return ( m_proxyModel.isNull() ? 0 : m_proxyModel.data()->sourceModel()->trackCount() );
}
int
TrackProxyModelPlaylistInterface::trackCount() const
{
return ( m_proxyModel.isNull() ? 0 : m_proxyModel.data()->rowCount( QModelIndex() ) );
}
QString
TrackProxyModelPlaylistInterface::filter() const
{
return ( m_proxyModel.isNull() ? QString() : m_proxyModel.data()->filterRegExp().pattern() );
}
void
TrackProxyModelPlaylistInterface::setFilter( const QString& pattern )
{
if ( m_proxyModel.isNull() )
return;
m_proxyModel.data()->setFilterRegExp( pattern );
m_proxyModel.data()->emitFilterChanged( pattern );
emit trackCountChanged( trackCount() );
}
QList< Tomahawk::query_ptr >
TrackProxyModelPlaylistInterface::tracks()
{
if ( m_proxyModel.isNull() )
return QList< Tomahawk::query_ptr >();
TrackProxyModel* proxyModel = m_proxyModel.data();
QList<Tomahawk::query_ptr> queries;
for ( int i = 0; i < proxyModel->rowCount( QModelIndex() ); i++ )
{
TrackModelItem* item = proxyModel->itemFromIndex( proxyModel->mapToSource( proxyModel->index( i, 0 ) ) );
if ( item )
queries << item->query();
}
return queries;
}
Tomahawk::result_ptr
TrackProxyModelPlaylistInterface::siblingItem( int itemsAway )
{
return siblingItem( itemsAway, false );
}
bool
TrackProxyModelPlaylistInterface::hasNextItem()
{
return !( siblingItem( 1, true ).isNull() );
}
Tomahawk::result_ptr
TrackProxyModelPlaylistInterface::siblingItem( int itemsAway, bool readOnly )
{
qDebug() << Q_FUNC_INFO;
if ( m_proxyModel.isNull() )
return Tomahawk::result_ptr();
TrackProxyModel* proxyModel = m_proxyModel.data();
QModelIndex idx = proxyModel->index( 0, 0 );
if ( proxyModel->rowCount() )
{
if ( m_shuffled )
{
// random mode is enabled
// TODO come up with a clever random logic, that keeps track of previously played items
idx = proxyModel->index( qrand() % proxyModel->rowCount(), 0 );
}
else if ( proxyModel->currentIndex().isValid() )
{
idx = proxyModel->currentIndex();
// random mode is disabled
if ( m_repeatMode != PlaylistInterface::RepeatOne )
{
// keep progressing through the playlist normally
idx = proxyModel->index( idx.row() + itemsAway, 0 );
}
}
}
if ( !idx.isValid() && m_repeatMode == PlaylistInterface::RepeatAll )
{
// repeat all tracks
if ( itemsAway > 0 )
{
// reset to first item
idx = proxyModel->index( 0, 0 );
}
else
{
// reset to last item
idx = proxyModel->index( proxyModel->rowCount() - 1, 0 );
}
}
// Try to find the next available PlaylistItem (with results)
while ( idx.isValid() )
{
TrackModelItem* item = proxyModel->itemFromIndex( proxyModel->mapToSource( idx ) );
if ( item && item->query()->playable() )
{
qDebug() << "Next PlaylistItem found:" << item->query()->toString() << item->query()->results().at( 0 )->url();
if ( !readOnly )
proxyModel->setCurrentIndex( idx );
return item->query()->results().at( 0 );
}
idx = proxyModel->index( idx.row() + ( itemsAway > 0 ? 1 : -1 ), 0 );
}
if ( !readOnly )
proxyModel->setCurrentIndex( QModelIndex() );
return Tomahawk::result_ptr();
}
Tomahawk::result_ptr
TrackProxyModelPlaylistInterface::currentItem() const
{
if ( m_proxyModel.isNull() )
return Tomahawk::result_ptr();
TrackProxyModel* proxyModel = m_proxyModel.data();
TrackModelItem* item = proxyModel->itemFromIndex( proxyModel->mapToSource( proxyModel->currentIndex() ) );
if ( item && !item->query().isNull() && item->query()->playable() )
return item->query()->results().at( 0 );
return Tomahawk::result_ptr();
}

View File

@ -0,0 +1,78 @@
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
*
* Copyright 2010-2011, 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
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Tomahawk is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Tomahawk. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef TRACKPROXYMODELPLAYLISTINTERFACE_H
#define TRACKPROXYMODELPLAYLISTINTERFACE_H
#include <QtGui/QSortFilterProxyModel>
#include "playlistinterface.h"
#include "playlist/trackmodel.h"
#include "dllmacro.h"
class TrackProxyModel;
namespace Tomahawk {
class DLLEXPORT TrackProxyModelPlaylistInterface : public Tomahawk::PlaylistInterface
{
Q_OBJECT
public:
explicit TrackProxyModelPlaylistInterface( TrackProxyModel* proxyModel );
virtual ~TrackProxyModelPlaylistInterface();
virtual QList<Tomahawk::query_ptr> tracks();
virtual int unfilteredTrackCount() const;
virtual int trackCount() const;
virtual Tomahawk::result_ptr currentItem() const;
virtual Tomahawk::result_ptr siblingItem( int itemsAway );
virtual Tomahawk::result_ptr siblingItem( int itemsAway, bool readOnly );
virtual bool hasNextItem();
virtual QString filter() const;
virtual void setFilter( const QString& pattern );
virtual PlaylistInterface::RepeatMode repeatMode() const { return m_repeatMode; }
virtual bool shuffled() const { return m_shuffled; }
signals:
void repeatModeChanged( Tomahawk::PlaylistInterface::RepeatMode mode );
void shuffleModeChanged( bool enabled );
void trackCountChanged( unsigned int tracks );
void sourceTrackCountChanged( unsigned int tracks );
void nextTrackReady();
public slots:
virtual void setRepeatMode( RepeatMode mode ) { m_repeatMode = mode; emit repeatModeChanged( mode ); }
virtual void setShuffled( bool enabled ) { m_shuffled = enabled; emit shuffleModeChanged( enabled ); }
protected:
QWeakPointer< TrackProxyModel > m_proxyModel;
RepeatMode m_repeatMode;
bool m_shuffled;
};
} //ns
#endif // TRACKPROXYMODELPLAYLISTINTERFACE_H

View File

@ -182,7 +182,7 @@ TrackView::onItemActivated( const QModelIndex& index )
{
tDebug() << "Result activated:" << item->query()->toString() << item->query()->results().first()->url();
m_proxyModel->setCurrentIndex( index );
AudioEngine::instance()->playItem( m_proxyModel->getSharedPointer(), item->query()->results().first() );
AudioEngine::instance()->playItem( m_proxyModel->getPlaylistInterface(), item->query()->results().first() );
}
emit itemActivated( index );
@ -369,9 +369,9 @@ TrackView::onFilterChanged( const QString& )
if ( selectedIndexes().count() )
scrollTo( selectedIndexes().at( 0 ), QAbstractItemView::PositionAtCenter );
if ( !proxyModel()->filter().isEmpty() && !proxyModel()->trackCount() && model()->trackCount() )
if ( !proxyModel()->getPlaylistInterface()->filter().isEmpty() && !proxyModel()->getPlaylistInterface()->trackCount() && model()->trackCount() )
{
m_overlay->setText( tr( "Sorry, your filter '%1' did not match any results." ).arg( proxyModel()->filter() ) );
m_overlay->setText( tr( "Sorry, your filter '%1' did not match any results." ).arg( proxyModel()->getPlaylistInterface()->filter() ) );
m_overlay->show();
}
else

View File

@ -18,8 +18,9 @@
#include "treeproxymodel.h"
#include <QListView>
#include <QtGui/QListView>
#include "treeproxymodelplaylistinterface.h"
#include "source.h"
#include "query.h"
#include "database/database.h"
@ -30,11 +31,8 @@
TreeProxyModel::TreeProxyModel( QObject* parent )
: QSortFilterProxyModel( parent )
, PlaylistInterface( this )
, m_artistsFilterCmd( 0 )
, m_model( 0 )
, m_repeatMode( PlaylistInterface::NoRepeat )
, m_shuffled( false )
{
setFilterCaseSensitivity( Qt::CaseInsensitive );
setSortCaseSensitivity( Qt::CaseInsensitive );
@ -111,9 +109,8 @@ TreeProxyModel::onModelReset()
m_albumsFilter.clear();
}
void
TreeProxyModel::setFilter( const QString& pattern )
TreeProxyModel::newFilterFromPlaylistInterface( const QString &pattern )
{
emit filteringStarted();
@ -145,7 +142,6 @@ TreeProxyModel::setFilter( const QString& pattern )
}
}
void
TreeProxyModel::onFilterArtists( const QList<Tomahawk::artist_ptr>& artists )
{
@ -191,15 +187,16 @@ TreeProxyModel::filterFinished()
{
m_artistsFilterCmd = 0;
if ( PlaylistInterface::filter() != m_filter )
if ( qobject_cast< Tomahawk::TreeProxyModelPlaylistInterface* >( m_playlistInterface.data() )->vanillaFilter() != m_filter )
{
emit filterChanged( m_filter );
}
PlaylistInterface::setFilter( m_filter );
qobject_cast< Tomahawk::TreeProxyModelPlaylistInterface* >( m_playlistInterface )->setVanillaFilter( m_filter );
setFilterRegExp( m_filter );
emit trackCountChanged( trackCount() );
qobject_cast< Tomahawk::TreeProxyModelPlaylistInterface* >( m_playlistInterface )->sendTrackCount();
emit filteringFinished();
}
@ -338,82 +335,6 @@ TreeProxyModel::removeIndexes( const QList<QModelIndex>& indexes )
}
bool
TreeProxyModel::hasNextItem()
{
return !( siblingItem( 1, true ).isNull() );
}
Tomahawk::result_ptr
TreeProxyModel::siblingItem( int itemsAway )
{
return siblingItem( itemsAway, false );
}
Tomahawk::result_ptr
TreeProxyModel::siblingItem( int itemsAway, bool readOnly )
{
QModelIndex idx = currentIndex();
if ( !idx.isValid() )
return Tomahawk::result_ptr();
if ( m_shuffled )
{
idx = index( qrand() % rowCount( idx.parent() ), 0, idx.parent() );
}
else
{
if ( m_repeatMode != PlaylistInterface::RepeatOne )
idx = index( idx.row() + ( itemsAway > 0 ? 1 : -1 ), 0, idx.parent() );
}
if ( !idx.isValid() && m_repeatMode == PlaylistInterface::RepeatAll )
{
if ( itemsAway > 0 )
{
// reset to first item
idx = index( 0, 0, currentIndex().parent() );
}
else
{
// reset to last item
idx = index( rowCount( currentIndex().parent() ) - 1, 0, currentIndex().parent() );
}
}
// Try to find the next available PlaylistItem (with results)
while ( idx.isValid() )
{
TreeModelItem* item = itemFromIndex( mapToSource( idx ) );
if ( item && !item->result().isNull() && item->result()->isOnline() )
{
qDebug() << "Next PlaylistItem found:" << item->result()->url();
if ( !readOnly )
setCurrentIndex( idx );
return item->result();
}
idx = index( idx.row() + ( itemsAway > 0 ? 1 : -1 ), 0, idx.parent() );
}
if ( !readOnly )
setCurrentIndex( QModelIndex() );
return Tomahawk::result_ptr();
}
Tomahawk::result_ptr
TreeProxyModel::currentItem() const
{
TreeModelItem* item = itemFromIndex( mapToSource( currentIndex() ) );
if ( item && !item->result().isNull() && item->result()->isOnline() )
return item->result();
return Tomahawk::result_ptr();
}
QString
TreeProxyModel::textForItem( TreeModelItem* item ) const
{
@ -439,3 +360,15 @@ TreeProxyModel::textForItem( TreeModelItem* item ) const
return QString();
}
Tomahawk::playlistinterface_ptr
TreeProxyModel::getPlaylistInterface()
{
if ( m_playlistInterface.isNull() )
{
m_playlistInterface = Tomahawk::playlistinterface_ptr( new Tomahawk::TreeProxyModelPlaylistInterface( this ) );
}
return m_playlistInterface;
}

View File

@ -28,7 +28,12 @@
class DatabaseCommand_AllArtists;
class DLLEXPORT TreeProxyModel : public QSortFilterProxyModel, public Tomahawk::PlaylistInterface
namespace Tomahawk
{
class TreeProxyModelPlaylistInterface;
}
class DLLEXPORT TreeProxyModel : public QSortFilterProxyModel
{
Q_OBJECT
@ -43,46 +48,22 @@ public:
virtual QPersistentModelIndex currentIndex() const;
virtual void setCurrentIndex( const QModelIndex& index ) { m_model->setCurrentItem( mapToSource( index ) ); }
virtual QList<Tomahawk::query_ptr> tracks() { Q_ASSERT( FALSE ); QList<Tomahawk::query_ptr> queries; return queries; }
virtual int unfilteredTrackCount() const { return sourceModel()->rowCount( QModelIndex() ); }
virtual int trackCount() const { return rowCount( QModelIndex() ); }
virtual int albumCount() const { return rowCount( QModelIndex() ); }
virtual void newFilterFromPlaylistInterface( const QString &pattern );
virtual void removeIndex( const QModelIndex& index );
virtual void removeIndexes( const QList<QModelIndex>& indexes );
virtual bool hasNextItem();
virtual Tomahawk::result_ptr currentItem() const;
virtual Tomahawk::result_ptr siblingItem( int direction );
virtual Tomahawk::result_ptr siblingItem( int direction, bool readOnly );
virtual int albumCount() const { return rowCount( QModelIndex() ); }
virtual QString filter() const { return filterRegExp().pattern(); }
virtual void setFilter( const QString& pattern );
virtual TreeModelItem* itemFromIndex( const QModelIndex& index ) const { return sourceModel()->itemFromIndex( index ); }
virtual PlaylistInterface::RepeatMode repeatMode() const { return m_repeatMode; }
virtual bool shuffled() const { return m_shuffled; }
virtual PlaylistInterface::ViewMode viewMode() const { return PlaylistInterface::Tree; }
TreeModelItem* itemFromIndex( const QModelIndex& index ) const { return sourceModel()->itemFromIndex( index ); }
virtual Tomahawk::playlistinterface_ptr getPlaylistInterface();
signals:
void repeatModeChanged( Tomahawk::PlaylistInterface::RepeatMode mode );
void shuffleModeChanged( bool enabled );
void trackCountChanged( unsigned int tracks );
void sourceTrackCountChanged( unsigned int tracks );
void filterChanged( const QString& filter );
void filteringStarted();
void filteringFinished();
void nextTrackReady();
public slots:
virtual void setRepeatMode( RepeatMode mode ) { m_repeatMode = mode; emit repeatModeChanged( mode ); }
virtual void setShuffled( bool enabled ) { m_shuffled = enabled; emit shuffleModeChanged( enabled ); }
protected:
bool filterAcceptsRow( int sourceRow, const QModelIndex& sourceParent ) const;
bool lessThan( const QModelIndex& left, const QModelIndex& right ) const;
@ -105,11 +86,11 @@ private:
QList<int> m_albumsFilter;
DatabaseCommand_AllArtists* m_artistsFilterCmd;
QString m_filter;
QString m_filter;
TreeModel* m_model;
RepeatMode m_repeatMode;
bool m_shuffled;
Tomahawk::playlistinterface_ptr m_playlistInterface;
};
#endif // TREEPROXYMODEL_H

View File

@ -0,0 +1,167 @@
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
*
* Copyright 2010-2011, 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
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Tomahawk is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Tomahawk. If not, see <http://www.gnu.org/licenses/>.
*/
#include "treeproxymodelplaylistinterface.h"
#include "treeproxymodel.h"
#include "source.h"
#include "query.h"
#include "database/database.h"
#include "database/databaseimpl.h"
#include "database/databasecommand_allalbums.h"
#include "utils/logger.h"
using namespace Tomahawk;
TreeProxyModelPlaylistInterface::TreeProxyModelPlaylistInterface( TreeProxyModel *proxyModel )
: PlaylistInterface()
, m_proxyModel( proxyModel )
, m_repeatMode( PlaylistInterface::NoRepeat )
, m_shuffled( false )
{
}
TreeProxyModelPlaylistInterface::~TreeProxyModelPlaylistInterface()
{
m_proxyModel.clear();
}
QString
TreeProxyModelPlaylistInterface::filter() const
{
if ( m_proxyModel.isNull() )
return 0;
TreeProxyModel* proxyModel = m_proxyModel.data();
return proxyModel->filterRegExp().pattern();
}
void
TreeProxyModelPlaylistInterface::setFilter( const QString& pattern )
{
if ( m_proxyModel.isNull() )
return;
m_proxyModel.data()->newFilterFromPlaylistInterface( pattern );
}
int
TreeProxyModelPlaylistInterface::unfilteredTrackCount() const
{
if ( m_proxyModel.isNull() )
return 0;
TreeProxyModel* proxyModel = m_proxyModel.data();
return proxyModel->sourceModel()->rowCount( QModelIndex() );
}
int
TreeProxyModelPlaylistInterface::trackCount() const
{
if ( m_proxyModel.isNull() )
return 0;
TreeProxyModel* proxyModel = m_proxyModel.data();
return proxyModel->rowCount( QModelIndex() );
}
bool
TreeProxyModelPlaylistInterface::hasNextItem()
{
return !( siblingItem( 1, true ).isNull() );
}
Tomahawk::result_ptr
TreeProxyModelPlaylistInterface::siblingItem( int itemsAway )
{
return siblingItem( itemsAway, false );
}
Tomahawk::result_ptr
TreeProxyModelPlaylistInterface::siblingItem( int itemsAway, bool readOnly )
{
if ( m_proxyModel.isNull() )
return Tomahawk::result_ptr();
TreeProxyModel* proxyModel = m_proxyModel.data();
QModelIndex idx = proxyModel->currentIndex();
if ( !idx.isValid() )
return Tomahawk::result_ptr();
if ( m_shuffled )
{
idx = proxyModel->index( qrand() % proxyModel->rowCount( idx.parent() ), 0, idx.parent() );
}
else
{
if ( m_repeatMode != PlaylistInterface::RepeatOne )
idx = proxyModel->index( idx.row() + ( itemsAway > 0 ? 1 : -1 ), 0, idx.parent() );
}
if ( !idx.isValid() && m_repeatMode == PlaylistInterface::RepeatAll )
{
if ( itemsAway > 0 )
{
// reset to first item
idx = proxyModel->index( 0, 0, proxyModel->currentIndex().parent() );
}
else
{
// reset to last item
idx = proxyModel->index( proxyModel->rowCount( proxyModel->currentIndex().parent() ) - 1, 0, proxyModel->currentIndex().parent() );
}
}
// Try to find the next available PlaylistItem (with results)
while ( idx.isValid() )
{
TreeModelItem* item = proxyModel->itemFromIndex( proxyModel->mapToSource( idx ) );
if ( item && !item->result().isNull() && item->result()->isOnline() )
{
qDebug() << "Next PlaylistItem found:" << item->result()->url();
if ( !readOnly )
proxyModel->setCurrentIndex( idx );
return item->result();
}
idx = proxyModel->index( idx.row() + ( itemsAway > 0 ? 1 : -1 ), 0, idx.parent() );
}
if ( !readOnly )
proxyModel->setCurrentIndex( QModelIndex() );
return Tomahawk::result_ptr();
}
Tomahawk::result_ptr
TreeProxyModelPlaylistInterface::currentItem() const
{
if ( m_proxyModel.isNull() )
return Tomahawk::result_ptr();
TreeProxyModel* proxyModel = m_proxyModel.data();
TreeModelItem* item = proxyModel->itemFromIndex( proxyModel->mapToSource( proxyModel->currentIndex() ) );
if ( item && !item->result().isNull() && item->result()->isOnline() )
return item->result();
return Tomahawk::result_ptr();
}

View File

@ -0,0 +1,89 @@
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
*
* Copyright 2010-2011, 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
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Tomahawk is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Tomahawk. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef TREEPROXYMODELPLAYLISTINTERFACE_H
#define TREEPROXYMODELPLAYLISTINTERFACE_H
#include "playlistinterface.h"
#include "treemodel.h"
#include "dllmacro.h"
class DatabaseCommand_AllArtists;
class TreeProxyModel;
namespace Tomahawk
{
class DLLEXPORT TreeProxyModelPlaylistInterface : public Tomahawk::PlaylistInterface
{
Q_OBJECT
public:
explicit TreeProxyModelPlaylistInterface( TreeProxyModel *proxyModel );
virtual ~TreeProxyModelPlaylistInterface();
virtual QList< Tomahawk::query_ptr > tracks() { Q_ASSERT( FALSE ); QList< Tomahawk::query_ptr > queries; return queries; }
virtual int unfilteredTrackCount() const;
virtual int trackCount() const;
virtual bool hasNextItem();
virtual Tomahawk::result_ptr currentItem() const;
virtual Tomahawk::result_ptr siblingItem( int direction );
virtual Tomahawk::result_ptr siblingItem( int direction, bool readOnly );
virtual QString filter() const;
virtual void setFilter( const QString& pattern );
virtual QString vanillaFilter() const { return PlaylistInterface::filter(); }
virtual void setVanillaFilter( const QString &filter ) { PlaylistInterface::setFilter( filter ); }
virtual void sendTrackCount() { emit trackCountChanged( trackCount() ); }
virtual PlaylistInterface::RepeatMode repeatMode() const { return m_repeatMode; }
virtual bool shuffled() const { return m_shuffled; }
virtual PlaylistInterface::ViewMode viewMode() const { return PlaylistInterface::Tree; }
signals:
void repeatModeChanged( Tomahawk::PlaylistInterface::RepeatMode mode );
void shuffleModeChanged( bool enabled );
void trackCountChanged( unsigned int tracks );
void sourceTrackCountChanged( unsigned int tracks );
void filterChanged( const QString& filter );
void filteringStarted();
void filteringFinished();
void nextTrackReady();
public slots:
virtual void setRepeatMode( RepeatMode mode ) { m_repeatMode = mode; emit repeatModeChanged( mode ); }
virtual void setShuffled( bool enabled ) { m_shuffled = enabled; emit shuffleModeChanged( enabled ); }
private:
QWeakPointer< TreeProxyModel > m_proxyModel;
RepeatMode m_repeatMode;
bool m_shuffled;
};
} //ns
#endif // TREEPROXYMODELPLAYLISTINTERFACE_H

View File

@ -22,8 +22,7 @@
using namespace Tomahawk;
PlaylistInterface::PlaylistInterface ( QObject *parent )
: m_object( parent )
PlaylistInterface::PlaylistInterface ()
{
qRegisterMetaType<Tomahawk::PlaylistInterface::RepeatMode>( "Tomahawk::PlaylistInterface::RepeatMode" );
}

View File

@ -28,8 +28,9 @@
namespace Tomahawk
{
class DLLEXPORT PlaylistInterface
class DLLEXPORT PlaylistInterface : public QObject
{
Q_OBJECT
public:
enum RepeatMode { NoRepeat, RepeatOne, RepeatAll };
@ -39,7 +40,7 @@ public:
enum SkipRestrictions { NoSkipRestrictions, NoSkipForwards, NoSkipBackwards, NoSkip };
enum RetryMode { NoRetry, Retry };
explicit PlaylistInterface( QObject* parent = 0 );
explicit PlaylistInterface();
virtual ~PlaylistInterface();
virtual QList< Tomahawk::query_ptr > tracks() = 0;
@ -67,39 +68,25 @@ public:
virtual void reset() {}
//TODO: Get rid of the next two functions once all playlsitinterfaces are factored out
// Some playlist interfaces can wrap other interfaces. When checking for top-level
// equality (say, to compare the currently playing interface) this might be needed
virtual bool hasChildInterface( Tomahawk::playlistinterface_ptr ) { return false; }
QObject* object() const { return m_object; }
virtual Tomahawk::playlistinterface_ptr getSharedPointer()
{
if ( m_sharedPtr.isNull() )
{
m_sharedPtr = Tomahawk::playlistinterface_ptr( this );
}
return m_sharedPtr;
}
//virtual void findMoreIfaces() = 0;
public slots:
virtual void setRepeatMode( RepeatMode mode ) = 0;
virtual void setShuffled( bool enabled ) = 0;
signals:
virtual void repeatModeChanged( PlaylistInterface::RepeatMode mode ) = 0;
virtual void shuffleModeChanged( bool enabled ) = 0;
virtual void trackCountChanged( unsigned int tracks ) = 0;
virtual void sourceTrackCountChanged( unsigned int tracks ) = 0;
virtual void nextTrackReady() = 0;
void repeatModeChanged( PlaylistInterface::RepeatMode mode );
void shuffleModeChanged( bool enabled );
void trackCountChanged( unsigned int tracks );
void sourceTrackCountChanged( unsigned int tracks );
void nextTrackReady();
private:
Q_DISABLE_COPY( PlaylistInterface )
QObject* m_object;
Tomahawk::playlistinterface_ptr m_sharedPtr;
QString m_filter;

View File

@ -27,7 +27,7 @@ using namespace Tomahawk;
PlaylistPlaylistInterface::PlaylistPlaylistInterface( Tomahawk::Playlist* playlist )
: QObject()
: Tomahawk::PlaylistInterface()
, m_playlist( playlist )
{
}

View File

@ -33,7 +33,7 @@
namespace Tomahawk
{
class DLLEXPORT PlaylistPlaylistInterface : public QObject, public Tomahawk::PlaylistInterface
class DLLEXPORT PlaylistPlaylistInterface : public Tomahawk::PlaylistInterface
{
Q_OBJECT
@ -56,8 +56,6 @@ public:
virtual void setFilter( const QString& /*pattern*/ ) {}
virtual void findMoreIfaces() {}
signals:
void repeatModeChanged( PlaylistInterface::RepeatMode mode );
void shuffleModeChanged( bool enabled );

View File

@ -307,7 +307,7 @@ Source::getPlaylistInterface()
if ( m_playlistInterface.isNull() )
{
Tomahawk::source_ptr source = SourceList::instance()->get( id() );
m_playlistInterface = Tomahawk::playlistinterface_ptr( new Tomahawk::SourcePlaylistInterface( source ) );
m_playlistInterface = Tomahawk::playlistinterface_ptr( new Tomahawk::SourcePlaylistInterface( source.data() ) );
}
return m_playlistInterface;

View File

@ -26,13 +26,14 @@
using namespace Tomahawk;
SourcePlaylistInterface::SourcePlaylistInterface( Tomahawk::source_ptr& source )
: PlaylistInterface( this )
, m_source( source.data() )
SourcePlaylistInterface::SourcePlaylistInterface( Tomahawk::Source *source )
: PlaylistInterface()
, m_source( source )
, m_currentItem( 0 )
, m_gotNextItem( false )
{
connect( source.data(), SIGNAL( playbackStarted( const Tomahawk::query_ptr& ) ), SLOT( onSourcePlaybackStarted( const Tomahawk::query_ptr& ) ) );
if ( !m_source.isNull() )
connect( m_source.data(), SIGNAL( playbackStarted( const Tomahawk::query_ptr& ) ), SLOT( onSourcePlaybackStarted( const Tomahawk::query_ptr& ) ) );
}

View File

@ -30,12 +30,12 @@
namespace Tomahawk
{
class DLLEXPORT SourcePlaylistInterface : public QObject, public Tomahawk::PlaylistInterface
class DLLEXPORT SourcePlaylistInterface : public Tomahawk::PlaylistInterface
{
Q_OBJECT
public:
SourcePlaylistInterface( Tomahawk::source_ptr& source );
SourcePlaylistInterface( Tomahawk::Source *source );
virtual ~SourcePlaylistInterface();
QList<Tomahawk::query_ptr> tracks();
@ -61,8 +61,6 @@ public:
virtual void reset();
virtual void findMoreIfaces() {}
public slots:
virtual void setRepeatMode( PlaylistInterface::RepeatMode ) {}
virtual void setShuffled( bool ) {}

View File

@ -605,16 +605,16 @@ ViewManager::unlinkPlaylist()
{
if ( currentPlaylistInterface() )
{
disconnect( currentPlaylistInterface()->object(), SIGNAL( sourceTrackCountChanged( unsigned int ) ),
disconnect( currentPlaylistInterface().data(), SIGNAL( sourceTrackCountChanged( unsigned int ) ),
this, SIGNAL( numTracksChanged( unsigned int ) ) );
disconnect( currentPlaylistInterface()->object(), SIGNAL( trackCountChanged( unsigned int ) ),
disconnect( currentPlaylistInterface().data(), SIGNAL( trackCountChanged( unsigned int ) ),
this, SIGNAL( numShownChanged( unsigned int ) ) );
disconnect( currentPlaylistInterface()->object(), SIGNAL( repeatModeChanged( Tomahawk::PlaylistInterface::RepeatMode ) ),
disconnect( currentPlaylistInterface().data(), SIGNAL( repeatModeChanged( Tomahawk::PlaylistInterface::RepeatMode ) ),
this, SIGNAL( repeatModeChanged( Tomahawk::PlaylistInterface::RepeatMode ) ) );
disconnect( currentPlaylistInterface()->object(), SIGNAL( shuffleModeChanged( bool ) ),
disconnect( currentPlaylistInterface().data(), SIGNAL( shuffleModeChanged( bool ) ),
this, SIGNAL( shuffleModeChanged( bool ) ) );
}
}
@ -644,16 +644,16 @@ ViewManager::updateView()
{
if ( currentPlaylistInterface() )
{
connect( currentPlaylistInterface()->object(), SIGNAL( sourceTrackCountChanged( unsigned int ) ),
connect( currentPlaylistInterface().data(), SIGNAL( sourceTrackCountChanged( unsigned int ) ),
SIGNAL( numTracksChanged( unsigned int ) ) );
connect( currentPlaylistInterface()->object(), SIGNAL( trackCountChanged( unsigned int ) ),
connect( currentPlaylistInterface().data(), SIGNAL( trackCountChanged( unsigned int ) ),
SIGNAL( numShownChanged( unsigned int ) ) );
connect( currentPlaylistInterface()->object(), SIGNAL( repeatModeChanged( Tomahawk::PlaylistInterface::RepeatMode ) ),
connect( currentPlaylistInterface().data(), SIGNAL( repeatModeChanged( Tomahawk::PlaylistInterface::RepeatMode ) ),
SIGNAL( repeatModeChanged( Tomahawk::PlaylistInterface::RepeatMode ) ) );
connect( currentPlaylistInterface()->object(), SIGNAL( shuffleModeChanged( bool ) ),
connect( currentPlaylistInterface().data(), SIGNAL( shuffleModeChanged( bool ) ),
SIGNAL( shuffleModeChanged( bool ) ) );
m_infobar->setFilter( currentPlaylistInterface()->filter() );

View File

@ -102,7 +102,7 @@ AlbumInfoWidget::~AlbumInfoWidget()
Tomahawk::playlistinterface_ptr
AlbumInfoWidget::playlistInterface() const
{
return ui->tracksView->playlistInterface()->getSharedPointer();
return ui->tracksView->playlistInterface();
}

View File

@ -27,12 +27,12 @@
#include <QObject>
class MetaPlaylistInterface : public QObject, public Tomahawk::PlaylistInterface
class MetaPlaylistInterface : public Tomahawk::PlaylistInterface
{
Q_OBJECT
public:
explicit MetaPlaylistInterface( ArtistInfoWidget* w )
: PlaylistInterface( this )
: PlaylistInterface()
, m_w( w )
{
connect( m_w->ui->albums->proxyModel(), SIGNAL( repeatModeChanged( Tomahawk::PlaylistInterface::RepeatMode ) ),
@ -53,9 +53,9 @@ public:
// Any one is fine, we keep them all synched
virtual RepeatMode repeatMode() const { return m_w->ui->albums->proxyModel()->repeatMode(); }
virtual RepeatMode repeatMode() const { return m_w->ui->albums->proxyModel()->getPlaylistInterface()->repeatMode(); }
virtual bool shuffled() const { return m_w->ui->albums->proxyModel()->shuffled(); }
virtual bool shuffled() const { return m_w->ui->albums->proxyModel()->getPlaylistInterface()->shuffled(); }
// Do nothing
virtual Tomahawk::result_ptr currentItem() const { return Tomahawk::result_ptr(); }
@ -70,19 +70,20 @@ public:
( m_w->ui->relatedArtists->playlistInterface() == other ) ||
( m_w->ui->topHits->playlistInterface() == other );
}
public slots:
virtual void setRepeatMode( RepeatMode mode )
{
m_w->ui->albums->proxyModel()->setRepeatMode( mode );
m_w->ui->relatedArtists->proxyModel()->setRepeatMode( mode );
m_w->ui->topHits->proxyModel()->setRepeatMode( mode );
m_w->ui->albums->proxyModel()->getPlaylistInterface()->setRepeatMode( mode );
m_w->ui->relatedArtists->proxyModel()->getPlaylistInterface()->setRepeatMode( mode );
m_w->ui->topHits->proxyModel()->getPlaylistInterface()->setRepeatMode( mode );
}
virtual void setShuffled( bool enabled )
{
m_w->ui->albums->proxyModel()->setShuffled( enabled );
m_w->ui->relatedArtists->proxyModel()->setShuffled( enabled );
m_w->ui->topHits->proxyModel()->setShuffled( enabled );
m_w->ui->albums->proxyModel()->getPlaylistInterface()->setShuffled( enabled );
m_w->ui->relatedArtists->proxyModel()->getPlaylistInterface()->setShuffled( enabled );
m_w->ui->topHits->proxyModel()->getPlaylistInterface()->setShuffled( enabled );
}
signals:

View File

@ -101,7 +101,7 @@ WelcomeWidget::~WelcomeWidget()
Tomahawk::playlistinterface_ptr
WelcomeWidget::playlistInterface() const
{
return ui->tracksView->playlistInterface()->getSharedPointer();
return ui->tracksView->playlistInterface();
}

View File

@ -93,7 +93,7 @@ WhatsHotWidget::WhatsHotWidget( QWidget* parent )
ui->artistsViewLeft->setHorizontalScrollBarPolicy( Qt::ScrollBarAlwaysOff );
ui->artistsViewLeft->header()->setVisible( false );
m_playlistInterface = ( new ChartsPlaylistInterface( this ) )->getSharedPointer();
m_playlistInterface = Tomahawk::playlistinterface_ptr( new ChartsPlaylistInterface( this ) );
m_workerThread = new QThread( this );
m_workerThread->start();

View File

@ -31,7 +31,6 @@
#include "dllmacro.h"
class ChartsPlaylistInterface;
class QSortFilterProxyModel;
class QStandardItemModel;
class QStandardItem;
@ -49,6 +48,7 @@ namespace Ui
namespace Tomahawk
{
class ChartDataLoader;
class ChartsPlaylistInterface;
}
/**
@ -119,7 +119,7 @@ private:
QSet< QString > m_queuedFetches;
QTimer* m_timer;
friend class ChartsPlaylistInterface;
friend class Tomahawk::ChartsPlaylistInterface;
};
#endif // WHATSHOTWIDGET_H

View File

@ -28,12 +28,15 @@
#include <QObject>
class ChartsPlaylistInterface : public QObject, public Tomahawk::PlaylistInterface
namespace Tomahawk
{
class ChartsPlaylistInterface : public Tomahawk::PlaylistInterface
{
Q_OBJECT
public:
explicit ChartsPlaylistInterface( WhatsHotWidget* w )
: PlaylistInterface( this )
: PlaylistInterface()
, m_w( w )
{
connect( m_w->ui->tracksViewLeft->proxyModel(), SIGNAL( repeatModeChanged( Tomahawk::PlaylistInterface::RepeatMode ) ),
@ -48,11 +51,10 @@ public:
}
virtual ~ChartsPlaylistInterface() {}
// Any one is fine, we keep them all synched
virtual RepeatMode repeatMode() const { return m_w->ui->tracksViewLeft->proxyModel()->repeatMode(); }
virtual RepeatMode repeatMode() const { return m_w->ui->tracksViewLeft->proxyModel()->getPlaylistInterface()->repeatMode(); }
virtual bool shuffled() const { return m_w->ui->tracksViewLeft->proxyModel()->shuffled(); }
virtual bool shuffled() const { return m_w->ui->tracksViewLeft->proxyModel()->getPlaylistInterface()->shuffled(); }
// Do nothing
virtual Tomahawk::result_ptr currentItem() const { return Tomahawk::result_ptr(); }
@ -67,17 +69,18 @@ public:
m_w->ui->artistsViewLeft->playlistInterface() == other;
}
public slots:
virtual void setRepeatMode( RepeatMode mode )
{
m_w->ui->tracksViewLeft->proxyModel()->setRepeatMode( mode );
m_w->ui->artistsViewLeft->proxyModel()->setRepeatMode( mode );
m_w->ui->tracksViewLeft->proxyModel()->getPlaylistInterface()->setRepeatMode( mode );
m_w->ui->artistsViewLeft->proxyModel()->getPlaylistInterface()->setRepeatMode( mode );
}
virtual void setShuffled( bool enabled )
{
m_w->ui->tracksViewLeft->proxyModel()->setShuffled( enabled );
m_w->ui->artistsViewLeft->proxyModel()->setShuffled( enabled );
m_w->ui->tracksViewLeft->proxyModel()->getPlaylistInterface()->setShuffled( enabled );
m_w->ui->artistsViewLeft->proxyModel()->getPlaylistInterface()->setShuffled( enabled );
}
signals:
@ -104,4 +107,6 @@ private:
};
} //ns
#endif

View File

@ -224,7 +224,7 @@ TomahawkWindow::setupSideBar()
m_queueModel->setStyle( PlaylistModel::Short );
m_queueView->queue()->setPlaylistModel( m_queueModel );
m_queueView->queue()->playlistModel()->setReadOnly( false );
AudioEngine::instance()->setQueue( m_queueView->queue()->proxyModel()->getSharedPointer() );
AudioEngine::instance()->setQueue( m_queueView->queue()->proxyModel()->getPlaylistInterface() );
m_sidebar->addWidget( m_searchWidget );
m_sidebar->addWidget( m_sourcetree );