mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-08-09 23:57:34 +02:00
Add ResultProvider baseclass for Collections and Resolvers
This commit is contained in:
@@ -197,6 +197,7 @@ list(APPEND libSources
|
|||||||
MetaPlaylistInterface.cpp
|
MetaPlaylistInterface.cpp
|
||||||
Query.cpp
|
Query.cpp
|
||||||
Result.cpp
|
Result.cpp
|
||||||
|
ResultProvider.cpp
|
||||||
Source.cpp
|
Source.cpp
|
||||||
Track.cpp
|
Track.cpp
|
||||||
TrackData.cpp
|
TrackData.cpp
|
||||||
|
@@ -421,9 +421,7 @@ Result::sourceIcon( TomahawkUtils::ImageMode style, const QSize& desiredSize ) c
|
|||||||
const QString key = sourceCacheKey( m_resolvedBy.data(), desiredSize, style );
|
const QString key = sourceCacheKey( m_resolvedBy.data(), desiredSize, style );
|
||||||
if ( !sourceIconCache()->contains( key ) )
|
if ( !sourceIconCache()->contains( key ) )
|
||||||
{
|
{
|
||||||
QPixmap pixmap = resolver->icon();
|
QPixmap pixmap = resolver->icon( desiredSize );
|
||||||
if ( !desiredSize.isEmpty() )
|
|
||||||
pixmap = pixmap.scaled( desiredSize, Qt::KeepAspectRatio, Qt::SmoothTransformation );
|
|
||||||
|
|
||||||
switch ( style )
|
switch ( style )
|
||||||
{
|
{
|
||||||
|
24
src/libtomahawk/ResultProvider.cpp
Normal file
24
src/libtomahawk/ResultProvider.cpp
Normal 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()
|
||||||
|
{
|
||||||
|
}
|
42
src/libtomahawk/ResultProvider.h
Normal file
42
src/libtomahawk/ResultProvider.h
Normal 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
|
@@ -472,7 +472,7 @@ ResolverAccount::icon() const
|
|||||||
if ( m_resolver.isNull() )
|
if ( m_resolver.isNull() )
|
||||||
return QPixmap();
|
return QPixmap();
|
||||||
|
|
||||||
return m_resolver->icon();
|
return m_resolver->icon( QSize( 0, 0 ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@@ -67,7 +67,7 @@ Collection::weakRef() const
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
QString
|
const QString
|
||||||
Collection::name() const
|
Collection::name() const
|
||||||
{
|
{
|
||||||
return m_name;
|
return m_name;
|
||||||
@@ -95,10 +95,10 @@ Collection::itemName() const
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
QIcon
|
const QPixmap
|
||||||
Collection::icon() const
|
Collection::icon( const QSize& size ) const
|
||||||
{
|
{
|
||||||
return ImageRegistry::instance()->icon( RESPATH "images/collection.svg" );
|
return ImageRegistry::instance()->pixmap( RESPATH "images/collection.svg", size );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@@ -37,15 +37,14 @@
|
|||||||
#include "collection/ArtistsRequest.h"
|
#include "collection/ArtistsRequest.h"
|
||||||
#include "collection/AlbumsRequest.h"
|
#include "collection/AlbumsRequest.h"
|
||||||
#include "collection/TracksRequest.h"
|
#include "collection/TracksRequest.h"
|
||||||
|
#include "../ResultProvider.h"
|
||||||
|
|
||||||
#include "DllMacro.h"
|
#include "DllMacro.h"
|
||||||
|
|
||||||
class QIcon;
|
|
||||||
|
|
||||||
namespace Tomahawk
|
namespace Tomahawk
|
||||||
{
|
{
|
||||||
|
|
||||||
class DLLEXPORT Collection : public QObject
|
class DLLEXPORT Collection : public QObject, public ResultProvider
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
@@ -63,12 +62,12 @@ public:
|
|||||||
ScriptCollectionType //performs operations through a resolver
|
ScriptCollectionType //performs operations through a resolver
|
||||||
};
|
};
|
||||||
|
|
||||||
virtual QString name() const;
|
virtual const QString name() const override;
|
||||||
virtual QString prettyName() const;
|
virtual QString prettyName() const;
|
||||||
virtual QString description() const;
|
virtual QString description() const;
|
||||||
virtual QString itemName() const;
|
virtual QString itemName() const;
|
||||||
virtual BackendType backendType() const { return NullCollectionType; }
|
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 QPixmap bigIcon() const; //for the ViewPage header
|
||||||
|
|
||||||
virtual void loadPlaylists();
|
virtual void loadPlaylists();
|
||||||
|
@@ -77,7 +77,7 @@ DatabaseResolver::gotArtists( const Tomahawk::QID qid, QList< Tomahawk::artist_p
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
QString
|
const QString
|
||||||
DatabaseResolver::name() const
|
DatabaseResolver::name() const
|
||||||
{
|
{
|
||||||
return QString( "DatabaseResolver" );
|
return QString( "DatabaseResolver" );
|
||||||
|
@@ -33,7 +33,7 @@ Q_OBJECT
|
|||||||
public:
|
public:
|
||||||
explicit DatabaseResolver( int weight );
|
explicit DatabaseResolver( int weight );
|
||||||
|
|
||||||
virtual QString name() const;
|
const QString name() const override;
|
||||||
virtual unsigned int weight() const { return m_weight; }
|
virtual unsigned int weight() const { return m_weight; }
|
||||||
virtual unsigned int timeout() const { return 0; }
|
virtual unsigned int timeout() const { return 0; }
|
||||||
|
|
||||||
|
@@ -88,7 +88,6 @@ public:
|
|||||||
{ m_filePath = filePath; }
|
{ m_filePath = filePath; }
|
||||||
|
|
||||||
QString filePath() const { return m_filePath; }
|
QString filePath() const { return m_filePath; }
|
||||||
virtual QPixmap icon() const { return QPixmap(); }
|
|
||||||
virtual void setIcon( const QPixmap& ) {}
|
virtual void setIcon( const QPixmap& ) {}
|
||||||
|
|
||||||
virtual void saveConfig() = 0;
|
virtual void saveConfig() = 0;
|
||||||
|
@@ -116,7 +116,7 @@ JSResolver::capabilities() const
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
QString
|
const QString
|
||||||
JSResolver::name() const
|
JSResolver::name() const
|
||||||
{
|
{
|
||||||
Q_D( const JSResolver );
|
Q_D( const JSResolver );
|
||||||
@@ -125,11 +125,14 @@ JSResolver::name() const
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
QPixmap
|
const QPixmap
|
||||||
JSResolver::icon() const
|
JSResolver::icon( const QSize& size ) const
|
||||||
{
|
{
|
||||||
Q_D( const JSResolver );
|
Q_D( const JSResolver );
|
||||||
|
|
||||||
|
if ( !size.isEmpty() )
|
||||||
|
return d->icon.scaled( size, Qt::KeepAspectRatio, Qt::SmoothTransformation );
|
||||||
|
|
||||||
return d->icon;
|
return d->icon;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -805,7 +808,7 @@ JSResolver::loadCollections()
|
|||||||
QPixmap iconPixmap;
|
QPixmap iconPixmap;
|
||||||
bool ok = iconPixmap.load( iconPath );
|
bool ok = iconPixmap.load( iconPath );
|
||||||
if ( ok && !iconPixmap.isNull() )
|
if ( ok && !iconPixmap.isNull() )
|
||||||
sc->setIcon( QIcon( iconPixmap ) );
|
sc->setIcon( iconPixmap );
|
||||||
}
|
}
|
||||||
|
|
||||||
m_collections.insert( collection->name(), collection );
|
m_collections.insert( collection->name(), collection );
|
||||||
|
@@ -55,8 +55,8 @@ public:
|
|||||||
|
|
||||||
Capabilities capabilities() const override;
|
Capabilities capabilities() const override;
|
||||||
|
|
||||||
QString name() const override;
|
const QString name() const override;
|
||||||
QPixmap icon() const override;
|
const QPixmap icon( const QSize& size ) const override;
|
||||||
unsigned int weight() const override;
|
unsigned int weight() const override;
|
||||||
unsigned int timeout() const override;
|
unsigned int timeout() const override;
|
||||||
|
|
||||||
|
@@ -15,5 +15,12 @@
|
|||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with Tomahawk. If not, see <http://www.gnu.org/licenses/>.
|
* along with Tomahawk. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "Resolver.h"
|
#include "Resolver.h"
|
||||||
|
|
||||||
|
#include <QPixmap>
|
||||||
|
|
||||||
|
const QPixmap
|
||||||
|
Tomahawk::Resolver::icon( const QSize& ) const
|
||||||
|
{
|
||||||
|
return QPixmap();
|
||||||
|
}
|
||||||
|
@@ -19,11 +19,11 @@
|
|||||||
#ifndef RESOLVER_H
|
#ifndef RESOLVER_H
|
||||||
#define RESOLVER_H
|
#define RESOLVER_H
|
||||||
|
|
||||||
#include <QObject>
|
#include "../ResultProvider.h"
|
||||||
|
|
||||||
#include "DllMacro.h"
|
|
||||||
#include "Typedefs.h"
|
#include "Typedefs.h"
|
||||||
|
#include "DllMacro.h"
|
||||||
|
|
||||||
|
#include <QObject>
|
||||||
|
|
||||||
// implement this if you can resolve queries to content
|
// implement this if you can resolve queries to content
|
||||||
|
|
||||||
@@ -37,17 +37,18 @@
|
|||||||
namespace Tomahawk
|
namespace Tomahawk
|
||||||
{
|
{
|
||||||
|
|
||||||
class DLLEXPORT Resolver : public QObject
|
class DLLEXPORT Resolver : public QObject, public ResultProvider
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Resolver() {}
|
Resolver() {}
|
||||||
|
|
||||||
virtual QString name() const = 0;
|
|
||||||
virtual unsigned int weight() const = 0;
|
virtual unsigned int weight() const = 0;
|
||||||
virtual unsigned int timeout() const = 0;
|
virtual unsigned int timeout() const = 0;
|
||||||
|
|
||||||
|
virtual const QPixmap icon( const QSize& size ) const override;
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
virtual void resolve( const Tomahawk::query_ptr& query ) = 0;
|
virtual void resolve( const Tomahawk::query_ptr& query ) = 0;
|
||||||
};
|
};
|
||||||
|
@@ -86,20 +86,20 @@ ScriptCollection::itemName() const
|
|||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
ScriptCollection::setIcon( const QIcon& icon )
|
ScriptCollection::setIcon( const QPixmap& icon )
|
||||||
{
|
{
|
||||||
m_icon = icon;
|
m_icon = icon;
|
||||||
emit changed();
|
emit changed();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
QIcon
|
const QPixmap
|
||||||
ScriptCollection::icon() const
|
ScriptCollection::icon( const QSize& size ) const
|
||||||
{
|
{
|
||||||
if( !m_icon.isNull() )
|
if ( !size.isEmpty() && !m_icon.isNull() )
|
||||||
return m_icon;
|
return m_icon.scaled( size, Qt::KeepAspectRatio, Qt::SmoothTransformation );
|
||||||
|
|
||||||
return m_resolver->icon();
|
return m_icon;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -107,7 +107,7 @@ QPixmap
|
|||||||
ScriptCollection::bigIcon() const
|
ScriptCollection::bigIcon() const
|
||||||
{
|
{
|
||||||
QPixmap big = Collection::bigIcon();
|
QPixmap big = Collection::bigIcon();
|
||||||
QPixmap base = icon().pixmap( big.size() );
|
QPixmap base = icon( big.size() );
|
||||||
|
|
||||||
if ( !source()->isLocal() )
|
if ( !source()->isLocal() )
|
||||||
{
|
{
|
||||||
|
@@ -29,7 +29,7 @@
|
|||||||
#include "Typedefs.h"
|
#include "Typedefs.h"
|
||||||
#include "DllMacro.h"
|
#include "DllMacro.h"
|
||||||
|
|
||||||
#include <QIcon>
|
#include <QPixmap>
|
||||||
|
|
||||||
|
|
||||||
namespace Tomahawk
|
namespace Tomahawk
|
||||||
@@ -62,8 +62,8 @@ public:
|
|||||||
QString itemName() const override;
|
QString itemName() const override;
|
||||||
BackendType backendType() const override { return ScriptCollectionType; }
|
BackendType backendType() const override { return ScriptCollectionType; }
|
||||||
|
|
||||||
void setIcon( const QIcon& icon );
|
void setIcon( const QPixmap& icon );
|
||||||
QIcon icon() const override;
|
const QPixmap icon( const QSize& size ) const override;
|
||||||
QPixmap bigIcon() const override;
|
QPixmap bigIcon() const override;
|
||||||
|
|
||||||
void setDescription( const QString& text );
|
void setDescription( const QString& text );
|
||||||
@@ -84,7 +84,7 @@ private:
|
|||||||
QString m_servicePrettyName;
|
QString m_servicePrettyName;
|
||||||
QString m_description;
|
QString m_description;
|
||||||
int m_trackCount;
|
int m_trackCount;
|
||||||
QIcon m_icon;
|
QPixmap m_icon;
|
||||||
};
|
};
|
||||||
|
|
||||||
} //ns
|
} //ns
|
||||||
|
@@ -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*
|
AccountConfigWidget*
|
||||||
ScriptResolver::configUI() const
|
ScriptResolver::configUI() const
|
||||||
{
|
{
|
||||||
|
@@ -44,8 +44,8 @@ public:
|
|||||||
virtual ~ScriptResolver();
|
virtual ~ScriptResolver();
|
||||||
static ExternalResolver* factory( const QString& accountId, const QString& exe, const QStringList& );
|
static ExternalResolver* factory( const QString& accountId, const QString& exe, const QStringList& );
|
||||||
|
|
||||||
QString name() const Q_DECL_OVERRIDE { return m_name; }
|
const QString name() const Q_DECL_OVERRIDE { return m_name; }
|
||||||
QPixmap icon() const Q_DECL_OVERRIDE { return m_icon; }
|
const QPixmap icon( const QSize& size ) const Q_DECL_OVERRIDE;
|
||||||
unsigned int weight() const Q_DECL_OVERRIDE { return m_weight; }
|
unsigned int weight() const Q_DECL_OVERRIDE { return m_weight; }
|
||||||
virtual unsigned int preference() const { return m_preference; }
|
virtual unsigned int preference() const { return m_preference; }
|
||||||
unsigned int timeout() const Q_DECL_OVERRIDE { return m_timeout; }
|
unsigned int timeout() const Q_DECL_OVERRIDE { return m_timeout; }
|
||||||
|
@@ -62,7 +62,7 @@ ScriptCollectionItem::tooltip() const
|
|||||||
QIcon
|
QIcon
|
||||||
ScriptCollectionItem::icon() const
|
ScriptCollectionItem::icon() const
|
||||||
{
|
{
|
||||||
return m_collection->icon();
|
return m_collection->icon( QSize( 0, 0 ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@@ -378,7 +378,7 @@ SourceItem::performAddCollectionItem( const collection_ptr& collection )
|
|||||||
GenericPageItem* i = new GenericPageItem( model(),
|
GenericPageItem* i = new GenericPageItem( model(),
|
||||||
this,
|
this,
|
||||||
collection->itemName(),
|
collection->itemName(),
|
||||||
collection->icon(),
|
collection->icon( QSize( 0, 0 ) ),
|
||||||
std::bind( &SourceItem::collectionClicked, this, collection ),
|
std::bind( &SourceItem::collectionClicked, this, collection ),
|
||||||
std::bind( &SourceItem::getCollectionPage, this, collection ) );
|
std::bind( &SourceItem::getCollectionPage, this, collection ) );
|
||||||
i->setSortValue( -340 );
|
i->setSortValue( -340 );
|
||||||
|
Reference in New Issue
Block a user