From 7f82799a7273156e3f68beaf566ff43b65c861a8 Mon Sep 17 00:00:00 2001 From: Teo Mrnjavac Date: Mon, 4 Mar 2013 17:03:16 +0100 Subject: [PATCH] Allow resolvers to set a prettyName for their ScriptCollections. --- src/libtomahawk/resolvers/QtScriptResolver.cpp | 2 ++ src/libtomahawk/resolvers/ScriptCollection.cpp | 15 ++++++++++++--- src/libtomahawk/resolvers/ScriptCollection.h | 11 +++++++++++ 3 files changed, 25 insertions(+), 3 deletions(-) diff --git a/src/libtomahawk/resolvers/QtScriptResolver.cpp b/src/libtomahawk/resolvers/QtScriptResolver.cpp index 6a634f2e4..5d92e1cd3 100644 --- a/src/libtomahawk/resolvers/QtScriptResolver.cpp +++ b/src/libtomahawk/resolvers/QtScriptResolver.cpp @@ -908,11 +908,13 @@ QtScriptResolver::loadCollections() !collectionInfo.contains( "description" ) ) return; + QString prettyname = collectionInfo.value( "prettyname" ).toString(); QString desc = collectionInfo.value( "description" ).toString(); m_collections.clear(); // at this point we assume that all the tracks browsable through a resolver belong to the local source Tomahawk::ScriptCollection* sc = new Tomahawk::ScriptCollection( SourceList::instance()->getLocal(), this ); + sc->setServiceName( prettyname ); sc->setDescription( desc ); if ( collectionInfo.contains( "trackcount" ) ) //a resolver might not expose this diff --git a/src/libtomahawk/resolvers/ScriptCollection.cpp b/src/libtomahawk/resolvers/ScriptCollection.cpp index d76ce2f49..cced05a4e 100644 --- a/src/libtomahawk/resolvers/ScriptCollection.cpp +++ b/src/libtomahawk/resolvers/ScriptCollection.cpp @@ -43,6 +43,8 @@ ScriptCollection::ScriptCollection( const source_ptr& source, qDebug() << Q_FUNC_INFO << resolver->name() << name(); m_resolver = resolver; + + m_servicePrettyName = m_resolver->name(); } @@ -52,19 +54,26 @@ ScriptCollection::~ScriptCollection() } +void +ScriptCollection::setServiceName( const QString& name ) +{ + m_servicePrettyName = name; +} + + QString ScriptCollection::prettyName() const { return tr( "%1 Collection", - "Name of a collection based on a resolver, e.g. Subsonic Collection" ) - .arg( m_resolver->name() ); + "Name of a collection based on a resolver, e.g. Subsonic Collection" ) + .arg( m_servicePrettyName ); } QString ScriptCollection::itemName() const { - return m_resolver->name(); + return m_servicePrettyName; } diff --git a/src/libtomahawk/resolvers/ScriptCollection.h b/src/libtomahawk/resolvers/ScriptCollection.h index 8f17d2d9c..7bfb12b47 100644 --- a/src/libtomahawk/resolvers/ScriptCollection.h +++ b/src/libtomahawk/resolvers/ScriptCollection.h @@ -42,6 +42,16 @@ public: QObject* parent = 0 ); virtual ~ScriptCollection(); + /** + * @brief setServiceName sets the name of the service that provides the ScriptCollection. + * Please note that by default, the pretty name is the same as the resolver's name, e.g. + * "Ampache", thus prettyName and itemName yield "Ampache Collection" and "Ampache", + * respectively. + * However, a resolver might want to change this string to something more appropriate and + * different from the resolver's name, to identify the specific service rather than just the + * resolver. + */ + virtual void setServiceName( const QString& name ); virtual QString prettyName() const; virtual QString itemName() const; virtual BackendType backendType() const { return ScriptCollectionType; } @@ -62,6 +72,7 @@ public: private: ExternalResolver* m_resolver; + QString m_servicePrettyName; QString m_description; int m_trackCount; };