mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-08-12 00:54:20 +02:00
Merge pull request #195 from tomahawk-player/viewmanagerrefactor
Allow external plugins to add view pages to the sidebar
This commit is contained in:
@@ -672,8 +672,14 @@ ViewManager::setPage( ViewPage* page, bool trackHistory )
|
||||
connect( obj, SIGNAL( destroyed( QWidget* ) ), SLOT( onWidgetDestroyed( QWidget* ) ), Qt::UniqueConnection );
|
||||
}
|
||||
|
||||
QWidget *previousPage = m_stack->currentWidget();
|
||||
|
||||
m_stack->setCurrentWidget( page->widget() );
|
||||
|
||||
//This should save the CPU cycles, especially with pages like the visualizer
|
||||
if(previousPage && previousPage != page->widget())
|
||||
previousPage->hide();
|
||||
|
||||
updateView();
|
||||
}
|
||||
|
||||
@@ -907,6 +913,53 @@ ViewPage *ViewManager::networkActivityWidget() const
|
||||
}
|
||||
|
||||
|
||||
ViewPage*
|
||||
ViewManager::dynamicPageWidget( const QString& pageName ) const
|
||||
{
|
||||
if( m_dynamicPages.contains( pageName ) )
|
||||
return m_dynamicPages.value( pageName );
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
ViewManager::addDynamicPage( const QString& pageName, const QString& text, const QIcon& icon, boost::function<Tomahawk::ViewPage*()> instanceLoader )
|
||||
{
|
||||
tLog() << Q_FUNC_INFO << "Trying to add " << pageName;
|
||||
|
||||
if( m_dynamicPages.contains( pageName ) )
|
||||
{
|
||||
tLog() << "Not adding a second ViewPage with name " << pageName;
|
||||
Q_ASSERT( false );
|
||||
}
|
||||
|
||||
m_dynamicPagesInstanceLoaders.insert( pageName, instanceLoader );
|
||||
emit viewPageAdded( pageName, text, icon );
|
||||
}
|
||||
|
||||
|
||||
ViewPage*
|
||||
ViewManager::showDynamicPage( const QString& pageName )
|
||||
{
|
||||
tLog() << Q_FUNC_INFO << "pageName: " << pageName;
|
||||
|
||||
if( !m_dynamicPages.contains( pageName ) )
|
||||
{
|
||||
if( !m_dynamicPagesInstanceLoaders.contains( pageName ) )
|
||||
{
|
||||
tLog() << "Trying to show a page that does not exist and does not have a registered loader";
|
||||
Q_ASSERT(false);
|
||||
return 0;
|
||||
}
|
||||
m_dynamicPages.insert( pageName, m_dynamicPagesInstanceLoaders.value( pageName )() );
|
||||
m_dynamicPagesInstanceLoaders.remove( pageName );
|
||||
}
|
||||
|
||||
return show( dynamicPageWidget( pageName ) );
|
||||
}
|
||||
|
||||
|
||||
Tomahawk::ViewPage*
|
||||
ViewManager::superCollectionView() const
|
||||
{
|
||||
|
@@ -20,16 +20,19 @@
|
||||
#ifndef VIEWMANAGER_H
|
||||
#define VIEWMANAGER_H
|
||||
|
||||
#include <QObject>
|
||||
#include <QHash>
|
||||
#include <QStackedWidget>
|
||||
|
||||
#include "Artist.h"
|
||||
#include "collection/Collection.h"
|
||||
#include "PlaylistInterface.h"
|
||||
#include "playlist/QueueView.h"
|
||||
#include "ViewPage.h"
|
||||
|
||||
#include <QObject>
|
||||
#include <QHash>
|
||||
#include <QStackedWidget>
|
||||
|
||||
// best regards to you, mr. pimple aka xhochy :)
|
||||
#include <boost/function.hpp>
|
||||
|
||||
#include "DllMacro.h"
|
||||
|
||||
class AnimatedSplitter;
|
||||
@@ -98,6 +101,8 @@ public:
|
||||
Tomahawk::ViewPage* inboxWidget() const;
|
||||
Tomahawk::ViewPage* networkActivityWidget() const;
|
||||
|
||||
Tomahawk::ViewPage* dynamicPageWidget( const QString& pageName ) const;
|
||||
|
||||
InboxModel* inboxModel();
|
||||
|
||||
/// Get the view page for the given item. Not pretty...
|
||||
@@ -135,6 +140,8 @@ signals:
|
||||
void historyBackAvailable( bool avail );
|
||||
void historyForwardAvailable( bool avail );
|
||||
|
||||
void viewPageAdded( const QString& pageName, const QString& text, const QIcon& icon );
|
||||
|
||||
public slots:
|
||||
Tomahawk::ViewPage* showSuperCollection();
|
||||
Tomahawk::ViewPage* showDashboard();
|
||||
@@ -143,6 +150,10 @@ public slots:
|
||||
Tomahawk::ViewPage* showRecentPlaysPage();
|
||||
Tomahawk::ViewPage* showInboxPage();
|
||||
Tomahawk::ViewPage* showNetworkActivityPage();
|
||||
|
||||
void addDynamicPage( const QString& pageName, const QString& text, const QIcon& icon, boost::function< Tomahawk::ViewPage*() > instanceLoader );
|
||||
Tomahawk::ViewPage* showDynamicPage( const QString& pageName );
|
||||
|
||||
void showCurrentTrack();
|
||||
|
||||
// Returns the shown viewpage
|
||||
@@ -198,6 +209,9 @@ private:
|
||||
InboxModel* m_inboxModel;
|
||||
NetworkActivityWidget* m_networkActivityWidget;
|
||||
|
||||
QHash< QString, Tomahawk::ViewPage* > m_dynamicPages;
|
||||
QHash< QString, boost::function< Tomahawk::ViewPage*() > > m_dynamicPagesInstanceLoaders;
|
||||
|
||||
QList< Tomahawk::collection_ptr > m_superCollections;
|
||||
|
||||
QHash< Tomahawk::dynplaylist_ptr, QPointer<Tomahawk::DynamicWidget> > m_dynamicWidgets;
|
||||
|
@@ -37,6 +37,10 @@
|
||||
#ifdef WITH_BREAKPAD
|
||||
#include "breakpad/BreakPad.h"
|
||||
#endif
|
||||
|
||||
#ifdef Q_WS_X11 // This is probably a very bad idea with Qt5 anyway... because (if at all) X lives in a QPA plugin
|
||||
#include <X11/Xlib.h>
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
@@ -138,6 +142,10 @@ main( int argc, char *argv[] )
|
||||
#endif // Q_WS_MAC
|
||||
#endif //Q_OS_WIN
|
||||
|
||||
#ifdef Q_WS_X11
|
||||
XInitThreads();
|
||||
#endif
|
||||
|
||||
TomahawkApp a( argc, argv );
|
||||
|
||||
// MUST register StateHash ****before*** initing TomahawkSettingsGui as constructor of settings does upgrade before Gui subclass registers type
|
||||
|
@@ -58,6 +58,7 @@ SourcesModel::SourcesModel( QObject* parent )
|
||||
m_rootItem = new SourceTreeItem( this, 0, Invalid );
|
||||
|
||||
appendGroups();
|
||||
|
||||
onSourcesAdded( SourceList::instance()->sources() );
|
||||
|
||||
connect( SourceList::instance(), SIGNAL( sourceAdded( Tomahawk::source_ptr ) ),
|
||||
@@ -76,6 +77,9 @@ SourcesModel::SourcesModel( QObject* parent )
|
||||
this, SLOT( onScriptCollectionAdded( Tomahawk::collection_ptr ) ) );
|
||||
connect( SourceList::instance(), SIGNAL( scriptCollectionRemoved( Tomahawk::collection_ptr ) ),
|
||||
this, SLOT( onScriptCollectionRemoved( Tomahawk::collection_ptr ) ) );
|
||||
|
||||
|
||||
connect( ViewManager::instance(), SIGNAL( viewPageAdded( QString, QString, QIcon ) ), SLOT( appendPageItem( QString, QString, QIcon ) ) );
|
||||
}
|
||||
|
||||
|
||||
@@ -292,47 +296,48 @@ SourcesModel::appendGroups()
|
||||
{
|
||||
beginInsertRows( QModelIndex(), rowCount(), rowCount() + 4 );
|
||||
|
||||
GroupItem* browse = new GroupItem( this, m_rootItem, tr( "Browse" ), 0 );
|
||||
m_browse = new GroupItem( this, m_rootItem, tr( "Browse" ), 0 );
|
||||
new HistoryItem( this, m_rootItem, tr( "Search History" ), 1 );
|
||||
// new SourceTreeItem( this, m_rootItem, SourcesModel::Divider, 2 );
|
||||
m_myMusicGroup = new GroupItem( this, m_rootItem, tr( "My Music" ), 3 );
|
||||
|
||||
GenericPageItem* dashboard = new GenericPageItem( this, browse, tr( "Dashboard" ), ImageRegistry::instance()->icon( RESPATH "images/dashboard.svg" ),
|
||||
GenericPageItem* dashboard = new GenericPageItem( this, m_browse, tr( "Dashboard" ), ImageRegistry::instance()->icon( RESPATH "images/dashboard.svg" ),
|
||||
boost::bind( &ViewManager::showDashboard, ViewManager::instance() ),
|
||||
boost::bind( &ViewManager::dashboard, ViewManager::instance() ) );
|
||||
dashboard->setSortValue( 0 );
|
||||
|
||||
// super collection
|
||||
GenericPageItem* sc = new GenericPageItem( this, browse, tr( "SuperCollection" ), ImageRegistry::instance()->icon( RESPATH "images/supercollection.svg" ),
|
||||
GenericPageItem* sc = new GenericPageItem( this, m_browse, tr( "SuperCollection" ), ImageRegistry::instance()->icon( RESPATH "images/supercollection.svg" ),
|
||||
boost::bind( &ViewManager::showSuperCollection, ViewManager::instance() ),
|
||||
boost::bind( &ViewManager::superCollectionView, ViewManager::instance() ) );
|
||||
sc->setSortValue( 1 );
|
||||
|
||||
// browse section
|
||||
LovedTracksItem* loved = new LovedTracksItem( this, browse );
|
||||
LovedTracksItem* loved = new LovedTracksItem( this, m_browse );
|
||||
loved->setSortValue( 2 );
|
||||
|
||||
GenericPageItem* networkActivity = new GenericPageItem( this, browse, tr( "Network Activity" ), TomahawkUtils::defaultPixmap( TomahawkUtils::NetworkActivity, TomahawkUtils::Original ),
|
||||
GenericPageItem* networkActivity = new GenericPageItem( this, m_browse, tr( "Network Activity" ), TomahawkUtils::defaultPixmap( TomahawkUtils::NetworkActivity, TomahawkUtils::Original ),
|
||||
boost::bind( &ViewManager::showNetworkActivityPage, ViewManager::instance() ),
|
||||
boost::bind( &ViewManager::networkActivityWidget, ViewManager::instance() ) );
|
||||
networkActivity->setSortValue( 3 );
|
||||
|
||||
GenericPageItem* recent = new GenericPageItem( this, browse, tr( "Recently Played" ), ImageRegistry::instance()->icon( RESPATH "images/recently-played.svg" ),
|
||||
GenericPageItem* recent = new GenericPageItem( this, m_browse, tr( "Recently Played" ), ImageRegistry::instance()->icon( RESPATH "images/recently-played.svg" ),
|
||||
boost::bind( &ViewManager::showRecentPlaysPage, ViewManager::instance() ),
|
||||
boost::bind( &ViewManager::recentPlaysWidget, ViewManager::instance() ) );
|
||||
recent->setSortValue( 4 );
|
||||
|
||||
GenericPageItem* hot = new GenericPageItem( this, browse, tr( "Charts" ), ImageRegistry::instance()->icon( RESPATH "images/charts.svg" ),
|
||||
GenericPageItem* hot = new GenericPageItem( this, m_browse, tr( "Charts" ), ImageRegistry::instance()->icon( RESPATH "images/charts.svg" ),
|
||||
boost::bind( &ViewManager::showWhatsHotPage, ViewManager::instance() ),
|
||||
boost::bind( &ViewManager::whatsHotWidget, ViewManager::instance() ) );
|
||||
hot->setSortValue( 5 );
|
||||
|
||||
GenericPageItem* newReleases = new GenericPageItem( this, browse, tr( "New Releases" ), ImageRegistry::instance()->icon( RESPATH "images/new-releases.svg" ),
|
||||
GenericPageItem* newReleases = new GenericPageItem( this, m_browse, tr( "New Releases" ), ImageRegistry::instance()->icon( RESPATH "images/new-releases.svg" ),
|
||||
boost::bind( &ViewManager::showNewReleasesPage, ViewManager::instance() ),
|
||||
boost::bind( &ViewManager::newReleasesWidget, ViewManager::instance() ) );
|
||||
newReleases->setSortValue( 6 );
|
||||
|
||||
InboxItem* inbox = new InboxItem( this, browse );
|
||||
|
||||
InboxItem* inbox = new InboxItem( this, m_browse );
|
||||
inbox->setSortValue( 7 );
|
||||
|
||||
m_collectionsGroup = new GroupItem( this, m_rootItem, tr( "Friends" ), 4 );
|
||||
@@ -342,6 +347,19 @@ SourcesModel::appendGroups()
|
||||
endInsertRows();
|
||||
}
|
||||
|
||||
void
|
||||
SourcesModel::appendPageItem( const QString& name, const QString& text, const QIcon& icon )
|
||||
{
|
||||
QModelIndex parentIndex = indexFromItem( m_browse );
|
||||
beginInsertRows( parentIndex, rowCount( parentIndex ), rowCount( parentIndex ) );
|
||||
GenericPageItem* pageItem = new GenericPageItem( this, m_browse, text, icon,
|
||||
boost::bind( &ViewManager::showDynamicPage, ViewManager::instance(), name ),
|
||||
boost::bind( &ViewManager::dynamicPageWidget, ViewManager::instance(), name ) );
|
||||
pageItem->setSortValue( rowCount( parentIndex ) );
|
||||
|
||||
endInsertRows();
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
SourcesModel::appendItem( const Tomahawk::source_ptr& source )
|
||||
|
@@ -146,12 +146,18 @@ private slots:
|
||||
|
||||
void onWidgetDestroyed( QWidget* w );
|
||||
|
||||
/*
|
||||
* pageIcon and pageTitle are visible in the source tree, pageName is the internal name in the ViewManager
|
||||
*/
|
||||
void appendPageItem( const QString& name, const QString& text, const QIcon& icon );
|
||||
|
||||
private:
|
||||
SourceTreeItem* itemFromIndex( const QModelIndex& idx ) const;
|
||||
int rowForItem( SourceTreeItem* item ) const;
|
||||
SourceTreeItem* activatePlaylistPage( Tomahawk::ViewPage* p, SourceTreeItem* i );
|
||||
|
||||
SourceTreeItem* m_rootItem;
|
||||
GroupItem* m_browse;
|
||||
GroupItem* m_collectionsGroup;
|
||||
GroupItem* m_myMusicGroup;
|
||||
GroupItem* m_cloudGroup;
|
||||
|
Reference in New Issue
Block a user