diff --git a/src/libtomahawk/CMakeLists.txt b/src/libtomahawk/CMakeLists.txt index 42bd6865a..4e6ecde8a 100644 --- a/src/libtomahawk/CMakeLists.txt +++ b/src/libtomahawk/CMakeLists.txt @@ -18,6 +18,7 @@ set( libGuiSources DropJob.cpp GlobalActionManager.cpp ViewPage.cpp + ViewPagePlugin.cpp ViewManager.cpp LatchManager.cpp TomahawkSettingsGui.cpp diff --git a/src/libtomahawk/ViewManager.cpp b/src/libtomahawk/ViewManager.cpp index 29c1d90b7..17de60b69 100644 --- a/src/libtomahawk/ViewManager.cpp +++ b/src/libtomahawk/ViewManager.cpp @@ -873,16 +873,39 @@ ViewManager::dynamicPageWidget( const QString& pageName ) const if( m_dynamicPages.contains( pageName ) ) return m_dynamicPages.value( pageName ); + if( m_dynamicPagePlugins.contains( pageName ) ) + return m_dynamicPagePlugins.value( pageName ).data(); + return 0; } +void +ViewManager::addDynamicPage( Tomahawk::ViewPagePlugin* viewPage, const QString& pageName ) +{ + const QString pageId = !pageName.isEmpty() ? pageName : viewPage->defaultName(); + + tLog() << Q_FUNC_INFO << "Trying to add " << pageId; + + if( m_dynamicPages.contains( pageId ) || m_dynamicPagePlugins.contains( pageId ) ) + { + tLog() << "Not adding a second ViewPage with name " << pageName; + Q_ASSERT( false ); + } + + m_dynamicPagePlugins.insert( pageId, viewPage ); + + // HACK: rather emit the viewpage itself ... + emit viewPageAdded( pageId, viewPage->title(), viewPage->pixmap(), viewPage->sortValue() ); +} + + void ViewManager::addDynamicPage( const QString& pageName, const QString& text, const QIcon& icon, boost::function instanceLoader, int sortValue ) { tLog() << Q_FUNC_INFO << "Trying to add " << pageName; - if( m_dynamicPages.contains( pageName ) ) + if( m_dynamicPages.contains( pageName ) || m_dynamicPagePlugins.contains( pageName ) ) { tLog() << "Not adding a second ViewPage with name " << pageName; Q_ASSERT( false ); @@ -898,7 +921,7 @@ ViewManager::showDynamicPage( const QString& pageName ) { tLog() << Q_FUNC_INFO << "pageName: " << pageName; - if( !m_dynamicPages.contains( pageName ) ) + if( !m_dynamicPages.contains( pageName ) && !m_dynamicPagePlugins.contains( pageName ) ) { if( !m_dynamicPagesInstanceLoaders.contains( pageName ) ) { diff --git a/src/libtomahawk/ViewManager.h b/src/libtomahawk/ViewManager.h index 49ea2251c..b6a301778 100644 --- a/src/libtomahawk/ViewManager.h +++ b/src/libtomahawk/ViewManager.h @@ -25,6 +25,7 @@ #include "PlaylistInterface.h" #include "playlist/QueueView.h" #include "ViewPage.h" +#include "ViewPagePlugin.h" #include #include @@ -115,6 +116,8 @@ public: FlexibleView* createPageForList( const QString& title, const QList< Tomahawk::query_ptr >& queries ); + void addDynamicPage( Tomahawk::ViewPagePlugin* viewPage, const QString& pageName = QString() ); + signals: void filterAvailable( bool b ); @@ -196,6 +199,7 @@ private: InboxModel* m_inboxModel; QHash< QString, Tomahawk::ViewPage* > m_dynamicPages; + QHash< QString, QPointer< Tomahawk::ViewPagePlugin > > m_dynamicPagePlugins; QHash< QString, boost::function< Tomahawk::ViewPage*() > > m_dynamicPagesInstanceLoaders; QList< Tomahawk::collection_ptr > m_superCollections; diff --git a/src/libtomahawk/ViewPagePlugin.cpp b/src/libtomahawk/ViewPagePlugin.cpp new file mode 100644 index 000000000..f31e4f76a --- /dev/null +++ b/src/libtomahawk/ViewPagePlugin.cpp @@ -0,0 +1,56 @@ +/* === This file is part of Tomahawk Player - === + * + * Copyright 2013, Dominik Schmidt + * + * 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 . + */ + +#include "ViewPagePlugin.h" + +#include "utils/TomahawkUtilsGui.h" +#include "utils/DpiScaler.h" +#include "utils/ImageRegistry.h" + +Tomahawk::ViewPagePlugin::ViewPagePlugin(QObject* parent) + : QObject( parent ) +{ + +} + +Tomahawk::ViewPagePlugin::~ViewPagePlugin() +{ + +} + + +int +Tomahawk::ViewPagePlugin::sortValue() +{ + return 0; +} + + +QPixmap +Tomahawk::ViewPagePlugin::pixmap() const +{ + // TODO: use DpiScaler here + return ImageRegistry::instance()->pixmap( pixmapPath(), QSize( 256, 256 ) ); +} + + +const QString +Tomahawk::ViewPagePlugin::pixmapPath() const +{ + return ( RESPATH "icons/tomahawk-icon-128x128.png" ); +} diff --git a/src/libtomahawk/ViewPagePlugin.h b/src/libtomahawk/ViewPagePlugin.h new file mode 100644 index 000000000..2d471624e --- /dev/null +++ b/src/libtomahawk/ViewPagePlugin.h @@ -0,0 +1,60 @@ +/* === This file is part of Tomahawk Player - === + * + * Copyright 2013, Dominik Schmidt + * + * 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 . + */ + +#ifndef VIEWPAGEPLUGIN_H +#define VIEWPAGEPLUGIN_H + +#include "ViewPage.h" + +#include "DllMacro.h" + +namespace Tomahawk +{ + + +class DLLEXPORT ViewPagePlugin : public QObject, public ViewPage +{ +Q_OBJECT + +public: + ViewPagePlugin( QObject* parent = 0 ); + virtual ~ViewPagePlugin(); + + virtual const QString defaultName() = 0; + virtual int sortValue(); + + // pixmap() by default returns a scaled instance of pixmapPath + virtual QPixmap pixmap() const; + virtual const QString pixmapPath() const; + +signals: + void nameChanged( const QString& ); + void descriptionChanged( const QString& ); + void descriptionChanged( const Tomahawk::artist_ptr& artist ); + void descriptionChanged( const Tomahawk::album_ptr& album ); + void longDescriptionChanged( const QString& ); + void pixmapChanged( const QPixmap& ); + void destroyed( QWidget* widget ); +}; + + +} // ns + +Q_DECLARE_INTERFACE( Tomahawk::ViewPagePlugin, "tomahawk.ViewPage/1.0" ) + +#endif //VIEWPAGEPLUGIN_H