mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-07-31 19:30:21 +02:00
Add ViewPagePlugin base class
This commit is contained in:
@@ -18,6 +18,7 @@ set( libGuiSources
|
||||
DropJob.cpp
|
||||
GlobalActionManager.cpp
|
||||
ViewPage.cpp
|
||||
ViewPagePlugin.cpp
|
||||
ViewManager.cpp
|
||||
LatchManager.cpp
|
||||
TomahawkSettingsGui.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<Tomahawk::ViewPage*()> 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 ) )
|
||||
{
|
||||
|
@@ -25,6 +25,7 @@
|
||||
#include "PlaylistInterface.h"
|
||||
#include "playlist/QueueView.h"
|
||||
#include "ViewPage.h"
|
||||
#include "ViewPagePlugin.h"
|
||||
|
||||
#include <QObject>
|
||||
#include <QHash>
|
||||
@@ -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;
|
||||
|
56
src/libtomahawk/ViewPagePlugin.cpp
Normal file
56
src/libtomahawk/ViewPagePlugin.cpp
Normal file
@@ -0,0 +1,56 @@
|
||||
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
|
||||
*
|
||||
* Copyright 2013, Dominik Schmidt <domme@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 "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" );
|
||||
}
|
60
src/libtomahawk/ViewPagePlugin.h
Normal file
60
src/libtomahawk/ViewPagePlugin.h
Normal file
@@ -0,0 +1,60 @@
|
||||
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
|
||||
*
|
||||
* Copyright 2013, Dominik Schmidt <domme@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 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
|
Reference in New Issue
Block a user