diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 6d6d63c50..a97f037d9 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -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 diff --git a/src/globalsearch/digitallyimportedsearchprovider.cpp b/src/globalsearch/digitallyimportedsearchprovider.cpp new file mode 100644 index 000000000..27d4b8d45 --- /dev/null +++ b/src/globalsearch/digitallyimportedsearchprovider.cpp @@ -0,0 +1,56 @@ +/* This file is part of Clementine. + Copyright 2010, David Sansome + + 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 . +*/ + +#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 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); +} diff --git a/src/globalsearch/digitallyimportedsearchprovider.h b/src/globalsearch/digitallyimportedsearchprovider.h new file mode 100644 index 000000000..88356957d --- /dev/null +++ b/src/globalsearch/digitallyimportedsearchprovider.h @@ -0,0 +1,42 @@ +/* This file is part of Clementine. + Copyright 2010, David Sansome + + 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 . +*/ + +#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 diff --git a/src/globalsearch/lastfmsearchprovider.cpp b/src/globalsearch/lastfmsearchprovider.cpp index 32cdb20b4..69aad694c 100644 --- a/src/globalsearch/lastfmsearchprovider.cpp +++ b/src/globalsearch/lastfmsearchprovider.cpp @@ -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"); diff --git a/src/globalsearch/simplesearchprovider.cpp b/src/globalsearch/simplesearchprovider.cpp index dd5ea25c5..4757d9c80 100644 --- a/src/globalsearch/simplesearchprovider.cpp +++ b/src/globalsearch/simplesearchprovider.cpp @@ -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_; diff --git a/src/globalsearch/simplesearchprovider.h b/src/globalsearch/simplesearchprovider.h index ed744a3b4..54d704fff 100644 --- a/src/globalsearch/simplesearchprovider.h +++ b/src/globalsearch/simplesearchprovider.h @@ -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_; diff --git a/src/internet/digitallyimportedservice.cpp b/src/internet/digitallyimportedservice.cpp index 3f40f08ca..f2e0802c4 100644 --- a/src/internet/digitallyimportedservice.cpp +++ b/src/internet/digitallyimportedservice.cpp @@ -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(false, "http://listen.di.fm/public3/%1.pls") diff --git a/src/internet/digitallyimportedservicebase.cpp b/src/internet/digitallyimportedservicebase.cpp index 32d6de6b1..09f55fc25 100644 --- a/src/internet/digitallyimportedservicebase.cpp +++ b/src/internet/digitallyimportedservicebase.cpp @@ -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 @@ -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() { diff --git a/src/internet/digitallyimportedservicebase.h b/src/internet/digitallyimportedservicebase.h index c3f17b530..628813091 100644 --- a/src/internet/digitallyimportedservicebase.h +++ b/src/internet/digitallyimportedservicebase.h @@ -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_; diff --git a/src/internet/skyfmservice.cpp b/src/internet/skyfmservice.cpp index f7fdaae56..fb6bfa385 100644 --- a/src/internet/skyfmservice.cpp +++ b/src/internet/skyfmservice.cpp @@ -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()