Add search providers for di.fm and sky.fm
This commit is contained in:
parent
e7ab192361
commit
892f5f1df1
|
@ -115,6 +115,7 @@ set(SOURCES
|
|||
engines/gstenginepipeline.cpp
|
||||
engines/gstelementdeleter.cpp
|
||||
|
||||
globalsearch/digitallyimportedsearchprovider.cpp
|
||||
globalsearch/globalsearch.cpp
|
||||
globalsearch/globalsearchitemdelegate.cpp
|
||||
globalsearch/globalsearchpopup.cpp
|
||||
|
@ -363,6 +364,7 @@ set(HEADERS
|
|||
engines/gstenginepipeline.h
|
||||
engines/gstelementdeleter.h
|
||||
|
||||
globalsearch/digitallyimportedsearchprovider.h
|
||||
globalsearch/librarysearchprovider.h
|
||||
globalsearch/globalsearch.h
|
||||
globalsearch/globalsearchpopup.h
|
||||
|
|
|
@ -0,0 +1,56 @@
|
|||
/* This file is part of Clementine.
|
||||
Copyright 2010, David Sansome <me@davidsansome.com>
|
||||
|
||||
Clementine 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.
|
||||
|
||||
Clementine 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 Clementine. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "digitallyimportedsearchprovider.h"
|
||||
#include "core/logging.h"
|
||||
#include "internet/digitallyimportedservicebase.h"
|
||||
|
||||
DigitallyImportedSearchProvider::DigitallyImportedSearchProvider(
|
||||
DigitallyImportedServiceBase* service, QObject* parent)
|
||||
: SimpleSearchProvider(parent),
|
||||
service_(service)
|
||||
{
|
||||
Init(service_->name(), service->url_scheme(), service_->icon(), false, false);
|
||||
icon_ = ScaleAndPad(QImage(service_->icon_path()));
|
||||
|
||||
set_safe_words(QStringList() << "sky.fm" << "skyfm" << "di.fm" << "difm"
|
||||
<< "digitallyimported");
|
||||
|
||||
connect(service_, SIGNAL(StreamsChanged()), SLOT(RecreateItems()));
|
||||
RecreateItems();
|
||||
}
|
||||
|
||||
void DigitallyImportedSearchProvider::LoadArtAsync(int id, const Result& result) {
|
||||
emit ArtLoaded(id, icon_);
|
||||
}
|
||||
|
||||
void DigitallyImportedSearchProvider::RecreateItems() {
|
||||
QList<Item> items;
|
||||
|
||||
DigitallyImportedServiceBase::StreamList streams = service_->Streams();
|
||||
|
||||
foreach (const DigitallyImportedServiceBase::Stream& stream, streams) {
|
||||
Song song;
|
||||
song.set_title(stream.name_);
|
||||
song.set_artist(service_->service_description());
|
||||
song.set_url(QUrl(service_->url_scheme() + "://" + stream.key_));
|
||||
|
||||
items << Item(song);
|
||||
}
|
||||
|
||||
SetItems(items);
|
||||
}
|
|
@ -0,0 +1,42 @@
|
|||
/* This file is part of Clementine.
|
||||
Copyright 2010, David Sansome <me@davidsansome.com>
|
||||
|
||||
Clementine 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.
|
||||
|
||||
Clementine 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 Clementine. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef DIGITALLYIMPORTEDSEARCHPROVIDER_H
|
||||
#define DIGITALLYIMPORTEDSEARCHPROVIDER_H
|
||||
|
||||
#include "simplesearchprovider.h"
|
||||
|
||||
class DigitallyImportedServiceBase;
|
||||
|
||||
class DigitallyImportedSearchProvider : public SimpleSearchProvider {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
DigitallyImportedSearchProvider(DigitallyImportedServiceBase* service,
|
||||
QObject* parent);
|
||||
|
||||
void LoadArtAsync(int id, const Result& result);
|
||||
|
||||
private slots:
|
||||
void RecreateItems();
|
||||
|
||||
private:
|
||||
DigitallyImportedServiceBase* service_;
|
||||
QImage icon_;
|
||||
};
|
||||
|
||||
#endif // DIGITALLYIMPORTEDSEARCHPROVIDER_H
|
|
@ -23,7 +23,7 @@
|
|||
LastFMSearchProvider::LastFMSearchProvider(LastFMService* service, QObject* parent)
|
||||
: SimpleSearchProvider(parent),
|
||||
service_(service) {
|
||||
Init("Last.fm", "lastfm", QIcon(":last.fm/as.png"), false, true);
|
||||
Init("Last.fm", "lastfm", QIcon(":last.fm/as.png"), false, false);
|
||||
icon_ = ScaleAndPad(QImage(":last.fm/as.png"));
|
||||
|
||||
set_safe_words(QStringList() << "lastfm" << "last.fm");
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
*/
|
||||
|
||||
#include "simplesearchprovider.h"
|
||||
#include "core/logging.h"
|
||||
#include "playlist/songmimedata.h"
|
||||
|
||||
|
||||
|
@ -28,6 +29,12 @@ SimpleSearchProvider::Item::Item(const QString& title, const QUrl& url, const QS
|
|||
metadata_.set_url(url);
|
||||
}
|
||||
|
||||
SimpleSearchProvider::Item::Item(const Song& song, const QString& keyword)
|
||||
: keyword_(keyword),
|
||||
metadata_(song)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
SimpleSearchProvider::SimpleSearchProvider(QObject* parent)
|
||||
: BlockingSearchProvider(parent),
|
||||
|
@ -72,7 +79,7 @@ SearchProvider::ResultList SimpleSearchProvider::Search(int id, const QString& q
|
|||
}
|
||||
|
||||
if (result.match_quality_ == Result::Quality_Middle) {
|
||||
result.match_quality_ = MatchQuality(tokens, result.metadata_.title());
|
||||
result.match_quality_ = MatchQuality(tokens, item.metadata_.title());
|
||||
}
|
||||
if (result.match_quality_ != Result::Quality_None) {
|
||||
result.metadata_ = item.metadata_;
|
||||
|
|
|
@ -37,6 +37,7 @@ protected:
|
|||
Item() {}
|
||||
Item(const QString& title, const QUrl& url,
|
||||
const QString& keyword = QString());
|
||||
Item(const Song& song, const QString& keyword = QString());
|
||||
|
||||
QString keyword_;
|
||||
Song metadata_;
|
||||
|
|
|
@ -26,7 +26,7 @@ DigitallyImportedService::DigitallyImportedService(InternetModel* model, QObject
|
|||
: DigitallyImportedServiceBase(
|
||||
"DigitallyImported", "Digitally Imported", QUrl("http://www.di.fm"),
|
||||
"di.fm", QUrl("http://listen.di.fm"), "digitallyimported",
|
||||
QIcon(":/providers/digitallyimported.png"), model, parent)
|
||||
":/providers/digitallyimported.png", model, parent)
|
||||
{
|
||||
playlists_ = QList<Playlist>()
|
||||
<< Playlist(false, "http://listen.di.fm/public3/%1.pls")
|
||||
|
|
|
@ -22,6 +22,8 @@
|
|||
#include "core/network.h"
|
||||
#include "core/player.h"
|
||||
#include "core/taskmanager.h"
|
||||
#include "globalsearch/digitallyimportedsearchprovider.h"
|
||||
#include "globalsearch/globalsearch.h"
|
||||
#include "ui/iconloader.h"
|
||||
|
||||
#include <QDesktopServices>
|
||||
|
@ -37,7 +39,7 @@ const int DigitallyImportedServiceBase::kStreamsCacheDurationSecs =
|
|||
DigitallyImportedServiceBase::DigitallyImportedServiceBase(
|
||||
const QString& name, const QString& description, const QUrl& homepage_url,
|
||||
const QString& homepage_name, const QUrl& stream_list_url,
|
||||
const QString& url_scheme, const QIcon& icon,
|
||||
const QString& url_scheme, const QString& icon_path,
|
||||
InternetModel* model, QObject* parent)
|
||||
: InternetService(name, model, parent),
|
||||
network_(new NetworkAccessManager(this)),
|
||||
|
@ -47,7 +49,8 @@ DigitallyImportedServiceBase::DigitallyImportedServiceBase(
|
|||
homepage_url_(homepage_url),
|
||||
homepage_name_(homepage_name),
|
||||
stream_list_url_(stream_list_url),
|
||||
icon_(icon),
|
||||
icon_path_(icon_path),
|
||||
icon_(icon_path),
|
||||
service_description_(description),
|
||||
url_scheme_(url_scheme),
|
||||
root_(NULL),
|
||||
|
@ -55,6 +58,8 @@ DigitallyImportedServiceBase::DigitallyImportedServiceBase(
|
|||
context_item_(NULL)
|
||||
{
|
||||
model->player()->RegisterUrlHandler(url_handler_);
|
||||
|
||||
model->global_search()->AddProvider(new DigitallyImportedSearchProvider(this, this));
|
||||
}
|
||||
|
||||
DigitallyImportedServiceBase::~DigitallyImportedServiceBase() {
|
||||
|
@ -139,6 +144,8 @@ void DigitallyImportedServiceBase::RefreshStreamsFinished() {
|
|||
|
||||
SaveStreams(saved_streams_);
|
||||
PopulateStreams();
|
||||
|
||||
emit StreamsChanged();
|
||||
}
|
||||
|
||||
void DigitallyImportedServiceBase::PopulateStreams() {
|
||||
|
|
|
@ -33,7 +33,7 @@ public:
|
|||
DigitallyImportedServiceBase(
|
||||
const QString& name, const QString& description, const QUrl& homepage_url,
|
||||
const QString& homepage_name, const QUrl& stream_list_url,
|
||||
const QString& url_scheme, const QIcon& icon,
|
||||
const QString& url_scheme, const QString& icon_path,
|
||||
InternetModel* model, QObject* parent = NULL);
|
||||
~DigitallyImportedServiceBase();
|
||||
|
||||
|
@ -50,6 +50,14 @@ public:
|
|||
bool is_premium_stream_selected() const;
|
||||
bool is_premium_account() const;
|
||||
|
||||
const QUrl& homepage_url() const { return homepage_url_; }
|
||||
const QString& homepage_name() const { return homepage_name_; }
|
||||
const QUrl& stream_list_url() const { return stream_list_url_; }
|
||||
const QString& icon_path() const { return icon_path_; }
|
||||
const QIcon& icon() const { return icon_; }
|
||||
const QString& service_description() const { return service_description_; }
|
||||
const QString& url_scheme() const { return url_scheme_; }
|
||||
|
||||
// Public for the global search provider.
|
||||
struct Stream {
|
||||
int id_;
|
||||
|
@ -64,6 +72,9 @@ public:
|
|||
bool IsStreamListStale() const;
|
||||
StreamList Streams();
|
||||
|
||||
signals:
|
||||
void StreamsChanged();
|
||||
|
||||
protected:
|
||||
struct Playlist {
|
||||
Playlist(bool premium, const QString& url_template)
|
||||
|
@ -111,6 +122,7 @@ private:
|
|||
QUrl homepage_url_;
|
||||
QString homepage_name_;
|
||||
QUrl stream_list_url_;
|
||||
QString icon_path_;
|
||||
QIcon icon_;
|
||||
QString service_description_;
|
||||
QString url_scheme_;
|
||||
|
|
|
@ -26,7 +26,7 @@
|
|||
SkyFmService::SkyFmService(InternetModel* model, QObject* parent)
|
||||
: DigitallyImportedServiceBase(
|
||||
"SKY.fm", "SKY.fm", QUrl("http://www.sky.fm"), "sky.fm",
|
||||
QUrl("http://listen.sky.fm"), "skyfm", QIcon(":/providers/skyfm.png"),
|
||||
QUrl("http://listen.sky.fm"), "skyfm", ":/providers/skyfm.png",
|
||||
model, parent)
|
||||
{
|
||||
playlists_ = QList<Playlist>()
|
||||
|
|
Loading…
Reference in New Issue