1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-07-31 03:10:12 +02:00

Add ResultProvider baseclass for Collections and Resolvers

This commit is contained in:
Dominik Schmidt
2015-01-06 03:23:32 +01:00
parent 55fa633dad
commit 5d322c12cb
20 changed files with 127 additions and 43 deletions

View File

@@ -197,6 +197,7 @@ list(APPEND libSources
MetaPlaylistInterface.cpp
Query.cpp
Result.cpp
ResultProvider.cpp
Source.cpp
Track.cpp
TrackData.cpp

View File

@@ -421,9 +421,7 @@ Result::sourceIcon( TomahawkUtils::ImageMode style, const QSize& desiredSize ) c
const QString key = sourceCacheKey( m_resolvedBy.data(), desiredSize, style );
if ( !sourceIconCache()->contains( key ) )
{
QPixmap pixmap = resolver->icon();
if ( !desiredSize.isEmpty() )
pixmap = pixmap.scaled( desiredSize, Qt::KeepAspectRatio, Qt::SmoothTransformation );
QPixmap pixmap = resolver->icon( desiredSize );
switch ( style )
{

View File

@@ -0,0 +1,24 @@
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
*
* Copyright (C) 2015 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 2 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 "ResultProvider.h"
using namespace Tomahawk;
ResultProvider::~ResultProvider()
{
}

View File

@@ -0,0 +1,42 @@
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
*
* Copyright (C) 2015 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 2 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/>.
*/
#pragma once
#ifndef TOMAHAWK_RESULTPROVIDER_H
#define TOMAHAWK_RESULTPROVIDER_H
#include "DllMacro.h"
class QPixmap;
class QString;
class QSize;
namespace Tomahawk
{
class DLLEXPORT ResultProvider
{
public:
virtual ~ResultProvider();
virtual const QString name() const = 0;
virtual const QPixmap icon( const QSize& size ) const = 0;
};
}
#endif // TOMAHAWK_RESULTPROVIDER_H

View File

@@ -472,7 +472,7 @@ ResolverAccount::icon() const
if ( m_resolver.isNull() )
return QPixmap();
return m_resolver->icon();
return m_resolver->icon( QSize( 0, 0 ) );
}

View File

@@ -67,7 +67,7 @@ Collection::weakRef() const
}
QString
const QString
Collection::name() const
{
return m_name;
@@ -95,10 +95,10 @@ Collection::itemName() const
}
QIcon
Collection::icon() const
const QPixmap
Collection::icon( const QSize& size ) const
{
return ImageRegistry::instance()->icon( RESPATH "images/collection.svg" );
return ImageRegistry::instance()->pixmap( RESPATH "images/collection.svg", size );
}

View File

@@ -37,15 +37,14 @@
#include "collection/ArtistsRequest.h"
#include "collection/AlbumsRequest.h"
#include "collection/TracksRequest.h"
#include "../ResultProvider.h"
#include "DllMacro.h"
class QIcon;
namespace Tomahawk
{
class DLLEXPORT Collection : public QObject
class DLLEXPORT Collection : public QObject, public ResultProvider
{
Q_OBJECT
@@ -63,12 +62,12 @@ public:
ScriptCollectionType //performs operations through a resolver
};
virtual QString name() const;
virtual const QString name() const override;
virtual QString prettyName() const;
virtual QString description() const;
virtual QString itemName() const;
virtual BackendType backendType() const { return NullCollectionType; }
virtual QIcon icon() const;
virtual const QPixmap icon( const QSize& size ) const override;
virtual QPixmap bigIcon() const; //for the ViewPage header
virtual void loadPlaylists();

View File

@@ -77,7 +77,7 @@ DatabaseResolver::gotArtists( const Tomahawk::QID qid, QList< Tomahawk::artist_p
}
QString
const QString
DatabaseResolver::name() const
{
return QString( "DatabaseResolver" );

View File

@@ -33,7 +33,7 @@ Q_OBJECT
public:
explicit DatabaseResolver( int weight );
virtual QString name() const;
const QString name() const override;
virtual unsigned int weight() const { return m_weight; }
virtual unsigned int timeout() const { return 0; }

View File

@@ -88,7 +88,6 @@ public:
{ m_filePath = filePath; }
QString filePath() const { return m_filePath; }
virtual QPixmap icon() const { return QPixmap(); }
virtual void setIcon( const QPixmap& ) {}
virtual void saveConfig() = 0;

View File

@@ -116,7 +116,7 @@ JSResolver::capabilities() const
}
QString
const QString
JSResolver::name() const
{
Q_D( const JSResolver );
@@ -125,11 +125,14 @@ JSResolver::name() const
}
QPixmap
JSResolver::icon() const
const QPixmap
JSResolver::icon( const QSize& size ) const
{
Q_D( const JSResolver );
if ( !size.isEmpty() )
return d->icon.scaled( size, Qt::KeepAspectRatio, Qt::SmoothTransformation );
return d->icon;
}
@@ -805,7 +808,7 @@ JSResolver::loadCollections()
QPixmap iconPixmap;
bool ok = iconPixmap.load( iconPath );
if ( ok && !iconPixmap.isNull() )
sc->setIcon( QIcon( iconPixmap ) );
sc->setIcon( iconPixmap );
}
m_collections.insert( collection->name(), collection );

View File

@@ -55,8 +55,8 @@ public:
Capabilities capabilities() const override;
QString name() const override;
QPixmap icon() const override;
const QString name() const override;
const QPixmap icon( const QSize& size ) const override;
unsigned int weight() const override;
unsigned int timeout() const override;

View File

@@ -15,5 +15,12 @@
* You should have received a copy of the GNU General Public License
* along with Tomahawk. If not, see <http://www.gnu.org/licenses/>.
*/
#include "Resolver.h"
#include <QPixmap>
const QPixmap
Tomahawk::Resolver::icon( const QSize& ) const
{
return QPixmap();
}

View File

@@ -19,11 +19,11 @@
#ifndef RESOLVER_H
#define RESOLVER_H
#include <QObject>
#include "DllMacro.h"
#include "../ResultProvider.h"
#include "Typedefs.h"
#include "DllMacro.h"
#include <QObject>
// implement this if you can resolve queries to content
@@ -37,17 +37,18 @@
namespace Tomahawk
{
class DLLEXPORT Resolver : public QObject
class DLLEXPORT Resolver : public QObject, public ResultProvider
{
Q_OBJECT
public:
Resolver() {}
virtual QString name() const = 0;
virtual unsigned int weight() const = 0;
virtual unsigned int timeout() const = 0;
virtual const QPixmap icon( const QSize& size ) const override;
public slots:
virtual void resolve( const Tomahawk::query_ptr& query ) = 0;
};

View File

@@ -86,20 +86,20 @@ ScriptCollection::itemName() const
void
ScriptCollection::setIcon( const QIcon& icon )
ScriptCollection::setIcon( const QPixmap& icon )
{
m_icon = icon;
emit changed();
}
QIcon
ScriptCollection::icon() const
const QPixmap
ScriptCollection::icon( const QSize& size ) const
{
if( !m_icon.isNull() )
return m_icon;
if ( !size.isEmpty() && !m_icon.isNull() )
return m_icon.scaled( size, Qt::KeepAspectRatio, Qt::SmoothTransformation );
return m_resolver->icon();
return m_icon;
}
@@ -107,7 +107,7 @@ QPixmap
ScriptCollection::bigIcon() const
{
QPixmap big = Collection::bigIcon();
QPixmap base = icon().pixmap( big.size() );
QPixmap base = icon( big.size() );
if ( !source()->isLocal() )
{

View File

@@ -29,7 +29,7 @@
#include "Typedefs.h"
#include "DllMacro.h"
#include <QIcon>
#include <QPixmap>
namespace Tomahawk
@@ -62,8 +62,8 @@ public:
QString itemName() const override;
BackendType backendType() const override { return ScriptCollectionType; }
void setIcon( const QIcon& icon );
QIcon icon() const override;
void setIcon( const QPixmap& icon );
const QPixmap icon( const QSize& size ) const override;
QPixmap bigIcon() const override;
void setDescription( const QString& text );
@@ -84,7 +84,7 @@ private:
QString m_servicePrettyName;
QString m_description;
int m_trackCount;
QIcon m_icon;
QPixmap m_icon;
};
} //ns

View File

@@ -555,6 +555,16 @@ ScriptResolver::setIcon( const QPixmap& icon )
}
const QPixmap
ScriptResolver::icon( const QSize& size ) const
{
if ( !size.isEmpty() )
return m_icon.scaled( size, Qt::KeepAspectRatio, Qt::SmoothTransformation );
return m_icon;
}
AccountConfigWidget*
ScriptResolver::configUI() const
{

View File

@@ -44,8 +44,8 @@ public:
virtual ~ScriptResolver();
static ExternalResolver* factory( const QString& accountId, const QString& exe, const QStringList& );
QString name() const Q_DECL_OVERRIDE { return m_name; }
QPixmap icon() const Q_DECL_OVERRIDE { return m_icon; }
const QString name() const Q_DECL_OVERRIDE { return m_name; }
const QPixmap icon( const QSize& size ) const Q_DECL_OVERRIDE;
unsigned int weight() const Q_DECL_OVERRIDE { return m_weight; }
virtual unsigned int preference() const { return m_preference; }
unsigned int timeout() const Q_DECL_OVERRIDE { return m_timeout; }

View File

@@ -62,7 +62,7 @@ ScriptCollectionItem::tooltip() const
QIcon
ScriptCollectionItem::icon() const
{
return m_collection->icon();
return m_collection->icon( QSize( 0, 0 ) );
}

View File

@@ -378,7 +378,7 @@ SourceItem::performAddCollectionItem( const collection_ptr& collection )
GenericPageItem* i = new GenericPageItem( model(),
this,
collection->itemName(),
collection->icon(),
collection->icon( QSize( 0, 0 ) ),
std::bind( &SourceItem::collectionClicked, this, collection ),
std::bind( &SourceItem::getCollectionPage, this, collection ) );
i->setSortValue( -340 );