Remove some redundant parameters from DigitallyImportedServiceBase and move the subclasses (which are now empty) into the same file.

This commit is contained in:
David Sansome 2011-11-04 22:54:27 +00:00
parent 2b6beb7417
commit a2327c4eb7
11 changed files with 80 additions and 190 deletions

View File

@ -133,7 +133,6 @@ set(SOURCES
globalsearch/tooltipresultwidget.cpp globalsearch/tooltipresultwidget.cpp
internet/digitallyimportedclient.cpp internet/digitallyimportedclient.cpp
internet/digitallyimportedservice.cpp
internet/digitallyimportedservicebase.cpp internet/digitallyimportedservicebase.cpp
internet/digitallyimportedsettingspage.cpp internet/digitallyimportedsettingspage.cpp
internet/digitallyimportedurlhandler.cpp internet/digitallyimportedurlhandler.cpp
@ -159,7 +158,6 @@ set(SOURCES
internet/magnatuneservice.cpp internet/magnatuneservice.cpp
internet/magnatuneurlhandler.cpp internet/magnatuneurlhandler.cpp
internet/savedradio.cpp internet/savedradio.cpp
internet/skyfmservice.cpp
internet/somafmservice.cpp internet/somafmservice.cpp
internet/somafmurlhandler.cpp internet/somafmurlhandler.cpp
@ -403,7 +401,6 @@ set(HEADERS
internet/magnatunesettingspage.h internet/magnatunesettingspage.h
internet/magnatuneservice.h internet/magnatuneservice.h
internet/savedradio.h internet/savedradio.h
internet/skyfmservice.h
internet/somafmservice.h internet/somafmservice.h
internet/somafmurlhandler.h internet/somafmurlhandler.h

View File

@ -24,7 +24,7 @@ DigitallyImportedSearchProvider::DigitallyImportedSearchProvider(
: SimpleSearchProvider(parent), : SimpleSearchProvider(parent),
service_(service) service_(service)
{ {
Init(service_->name(), service->url_scheme(), service_->icon(), Init(service_->name(), service->api_service_name(), service_->icon(),
ArtIsInSongMetadata); ArtIsInSongMetadata);
set_safe_words(QStringList() << "sky.fm" << "skyfm" << "di.fm" << "difm" set_safe_words(QStringList() << "sky.fm" << "skyfm" << "di.fm" << "difm"

View File

@ -1,32 +0,0 @@
/* 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 "digitallyimportedservice.h"
#include "core/logging.h"
#include <QNetworkAccessManager>
#include <QNetworkCookieJar>
#include <QNetworkReply>
DigitallyImportedService::DigitallyImportedService(InternetModel* model, QObject* parent)
: DigitallyImportedServiceBase("DigitallyImported", model, parent)
{
Init("Digitally Imported", QUrl("http://www.di.fm"),
"di.fm", QUrl("http://listen.di.fm"), "digitallyimported",
":/providers/digitallyimported.png", "di");
}

View File

@ -1,28 +0,0 @@
/* 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 DIGITALLYIMPORTEDSERVICE_H
#define DIGITALLYIMPORTEDSERVICE_H
#include "digitallyimportedservicebase.h"
class DigitallyImportedService : public DigitallyImportedServiceBase {
public:
DigitallyImportedService(InternetModel* model, QObject* parent = NULL);
};
#endif // DIGITALLYIMPORTEDSERVICE_H

View File

@ -39,47 +39,39 @@ const int DigitallyImportedServiceBase::kStreamsCacheDurationSecs =
DigitallyImportedServiceBase::DigitallyImportedServiceBase( DigitallyImportedServiceBase::DigitallyImportedServiceBase(
const QString& name, InternetModel* model, QObject* parent) const QString& name,
const QString& description,
const QUrl& homepage_url,
const QIcon& icon,
const QString& api_service_name,
InternetModel* model, QObject* parent)
: InternetService(name, model, parent), : InternetService(name, model, parent),
homepage_url_(homepage_url),
icon_(icon),
service_description_(description),
api_service_name_(api_service_name),
network_(new NetworkAccessManager(this)), network_(new NetworkAccessManager(this)),
url_handler_(new DigitallyImportedUrlHandler(this)), url_handler_(new DigitallyImportedUrlHandler(this)),
basic_audio_type_(1), basic_audio_type_(1),
premium_audio_type_(2), premium_audio_type_(2),
root_(NULL), root_(NULL),
context_item_(NULL), context_item_(NULL),
api_client_(NULL) api_client_(new DigitallyImportedClient(api_service_name, this))
{ {
model->player()->RegisterUrlHandler(url_handler_);
model->global_search()->AddProvider(new DigitallyImportedSearchProvider(this, this));
basic_playlists_ basic_playlists_
<< "http://listen.%1/public3/%2.pls" << "http://%1/public3/%2.pls"
<< "http://listen.%1/public1/%2.pls" << "http://%1/public1/%2.pls"
<< "http://listen.%1/public5/%2.asx"; << "http://%1/public5/%2.asx";
premium_playlists_ premium_playlists_
<< "http://listen.%1/premium_high/%2.pls?hash=%3" << "http://%1/premium_high/%2.pls?hash=%3"
<< "http://listen.%1/premium_medium/%2.pls?hash=%3" << "http://%1/premium_medium/%2.pls?hash=%3"
<< "http://listen.%1/premium/%2.pls?hash=%3" << "http://%1/premium/%2.pls?hash=%3"
<< "http://listen.%1/premium_wma_low/%2.asx?hash=%3" << "http://%1/premium_wma_low/%2.asx?hash=%3"
<< "http://listen.%1/premium_wma/%2.asx?hash=%3"; << "http://%1/premium_wma/%2.asx?hash=%3";
}
void DigitallyImportedServiceBase::Init(
const QString& description, const QUrl& homepage_url,
const QString& homepage_name, const QUrl& stream_list_url,
const QString& url_scheme, const QString& icon_path,
const QString& api_service_name) {
service_description_ = description;
homepage_url_ = homepage_url;
homepage_name_ = homepage_name;
stream_list_url_ = stream_list_url;
url_scheme_ = url_scheme;
icon_path_ = icon_path;
api_service_name_ = api_service_name;
icon_ = QIcon(icon_path_);
model()->player()->RegisterUrlHandler(url_handler_);
model()->global_search()->AddProvider(new DigitallyImportedSearchProvider(this, this));
api_client_ = new DigitallyImportedClient(api_service_name, this);
} }
DigitallyImportedServiceBase::~DigitallyImportedServiceBase() { DigitallyImportedServiceBase::~DigitallyImportedServiceBase() {
@ -153,7 +145,7 @@ void DigitallyImportedServiceBase::SongFromChannel(
const DigitallyImportedClient::Channel& channel, Song* song) const { const DigitallyImportedClient::Channel& channel, Song* song) const {
song->set_title(channel.name_); song->set_title(channel.name_);
song->set_artist(service_description_ + " - " + channel.director_); song->set_artist(service_description_ + " - " + channel.director_);
song->set_url(QUrl(url_scheme_ + "://" + channel.key_)); song->set_url(QUrl(api_service_name_ + "://" + channel.key_));
song->set_art_automatic(channel.art_url_.toString()); song->set_art_automatic(channel.art_url_.toString());
} }
@ -169,7 +161,7 @@ void DigitallyImportedServiceBase::ReloadSettings() {
premium_audio_type_ = s.value("premium_audio_type", 2).toInt(); premium_audio_type_ = s.value("premium_audio_type", 2).toInt();
username_ = s.value("username").toString(); username_ = s.value("username").toString();
listen_hash_ = s.value("listen_hash").toString(); listen_hash_ = s.value("listen_hash").toString();
last_refreshed_channels_ = s.value("last_refreshed_v2_" + url_scheme_).toDateTime(); last_refreshed_channels_ = s.value("last_refreshed_" + api_service_name_).toDateTime();
saved_channels_ = LoadChannels(); saved_channels_ = LoadChannels();
} }
@ -179,7 +171,7 @@ void DigitallyImportedServiceBase::ShowContextMenu(
context_menu_.reset(new QMenu); context_menu_.reset(new QMenu);
context_menu_->addActions(GetPlaylistActions()); context_menu_->addActions(GetPlaylistActions());
context_menu_->addAction(IconLoader::Load("download"), context_menu_->addAction(IconLoader::Load("download"),
tr("Open %1 in browser").arg(homepage_name_), tr("Open %1 in browser").arg(homepage_url_.host()),
this, SLOT(Homepage())); this, SLOT(Homepage()));
context_menu_->addAction(IconLoader::Load("view-refresh"), context_menu_->addAction(IconLoader::Load("view-refresh"),
tr("Refresh streams"), tr("Refresh streams"),
@ -224,7 +216,7 @@ DigitallyImportedClient::ChannelList DigitallyImportedServiceBase::LoadChannels(
QSettings s; QSettings s;
s.beginGroup(kSettingsGroup); s.beginGroup(kSettingsGroup);
int count = s.beginReadArray(url_scheme_); int count = s.beginReadArray(api_service_name_);
for (int i=0 ; i<count ; ++i) { for (int i=0 ; i<count ; ++i) {
s.setArrayIndex(i); s.setArrayIndex(i);
@ -243,7 +235,7 @@ void DigitallyImportedServiceBase::SaveChannels(
QSettings s; QSettings s;
s.beginGroup(kSettingsGroup); s.beginGroup(kSettingsGroup);
s.beginWriteArray(url_scheme_, channels.count()); s.beginWriteArray(api_service_name_, channels.count());
for (int i=0 ; i<channels.count() ; ++i) { for (int i=0 ; i<channels.count() ; ++i) {
s.setArrayIndex(i); s.setArrayIndex(i);
channels[i].Save(&s); channels[i].Save(&s);
@ -251,7 +243,7 @@ void DigitallyImportedServiceBase::SaveChannels(
s.endArray(); s.endArray();
last_refreshed_channels_ = QDateTime::currentDateTime(); last_refreshed_channels_ = QDateTime::currentDateTime();
s.setValue("last_refreshed_v2_" + url_scheme_, last_refreshed_channels_); s.setValue("last_refreshed_" + api_service_name_, last_refreshed_channels_);
} }
bool DigitallyImportedServiceBase::IsChannelListStale() const { bool DigitallyImportedServiceBase::IsChannelListStale() const {
@ -271,12 +263,15 @@ DigitallyImportedClient::ChannelList DigitallyImportedServiceBase::Channels() {
void DigitallyImportedServiceBase::LoadStation(const QString& key) { void DigitallyImportedServiceBase::LoadStation(const QString& key) {
QUrl playlist_url; QUrl playlist_url;
// Replace "www." with "listen." in the hostname.
const QString host = "listen." + homepage_url_.host().remove("www.");
if (is_premium_account()) { if (is_premium_account()) {
playlist_url = QUrl(premium_playlists_[premium_audio_type_].arg( playlist_url = QUrl(premium_playlists_[premium_audio_type_].arg(
homepage_name_, key, listen_hash_)); host, key, listen_hash_));
} else { } else {
playlist_url = QUrl(basic_playlists_[basic_audio_type_].arg( playlist_url = QUrl(basic_playlists_[basic_audio_type_].arg(
homepage_name_, key)); host, key));
} }
qLog(Debug) << "Getting playlist URL" << playlist_url; qLog(Debug) << "Getting playlist URL" << playlist_url;
@ -288,3 +283,24 @@ void DigitallyImportedServiceBase::LoadStation(const QString& key) {
QModelIndex DigitallyImportedServiceBase::GetCurrentIndex() { QModelIndex DigitallyImportedServiceBase::GetCurrentIndex() {
return context_item_->index(); return context_item_->index();
} }
DigitallyImportedService::DigitallyImportedService(InternetModel* model, QObject* parent)
: DigitallyImportedServiceBase("DigitallyImported",
"Digitally Imported",
QUrl("http://www.di.fm"),
QIcon(":/providers/digitallyimported.png"),
"di",
model, parent)
{
}
SkyFmService::SkyFmService(InternetModel* model, QObject* parent)
: DigitallyImportedServiceBase("SKY.fm",
"SKY.fm",
QUrl("http://www.sky.fm"),
QIcon(":/providers/skyfm.png"),
"sky",
model, parent)
{
}

View File

@ -34,7 +34,12 @@ class DigitallyImportedServiceBase : public InternetService {
friend class DigitallyImportedUrlHandler; friend class DigitallyImportedUrlHandler;
public: public:
DigitallyImportedServiceBase(const QString& name, InternetModel* model, DigitallyImportedServiceBase(const QString& name,
const QString& description,
const QUrl& homepage_url,
const QIcon& icon,
const QString& api_service_name,
InternetModel* model,
QObject* parent = NULL); QObject* parent = NULL);
~DigitallyImportedServiceBase(); ~DigitallyImportedServiceBase();
@ -50,12 +55,8 @@ public:
bool is_premium_account() const; bool is_premium_account() const;
const QUrl& homepage_url() const { return homepage_url_; } 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 QIcon& icon() const { return icon_; }
const QString& service_description() const { return service_description_; } const QString& service_description() const { return service_description_; }
const QString& url_scheme() const { return url_scheme_; }
const QString& api_service_name() const { return api_service_name_; } const QString& api_service_name() const { return api_service_name_; }
bool IsChannelListStale() const; bool IsChannelListStale() const;
@ -67,18 +68,10 @@ signals:
void StreamsChanged(); void StreamsChanged();
protected: protected:
// Subclasses must call this from their constructor
void Init(const QString& description, const QUrl& homepage_url,
const QString& homepage_name, const QUrl& stream_list_url,
const QString& url_scheme, const QString& icon_path,
const QString& api_service_name);
QModelIndex GetCurrentIndex(); QModelIndex GetCurrentIndex();
protected slots:
void LoadPlaylistFinished();
private slots: private slots:
void LoadPlaylistFinished();
void Homepage(); void Homepage();
void ForceRefreshStreams(); void ForceRefreshStreams();
void RefreshStreams(); void RefreshStreams();
@ -95,12 +88,8 @@ private:
private: private:
// Set by subclasses through the constructor // Set by subclasses through the constructor
QUrl homepage_url_; QUrl homepage_url_;
QString homepage_name_;
QUrl stream_list_url_;
QString icon_path_;
QIcon icon_; QIcon icon_;
QString service_description_; QString service_description_;
QString url_scheme_;
QString api_service_name_; QString api_service_name_;
QStringList basic_playlists_; QStringList basic_playlists_;
@ -125,4 +114,14 @@ private:
DigitallyImportedClient* api_client_; DigitallyImportedClient* api_client_;
}; };
class DigitallyImportedService : public DigitallyImportedServiceBase {
public:
DigitallyImportedService(InternetModel* model, QObject* parent = NULL);
};
class SkyFmService : public DigitallyImportedServiceBase {
public:
SkyFmService(InternetModel* model, QObject* parent = NULL);
};
#endif // DIGITALLYIMPORTEDSERVICEBASE_H #endif // DIGITALLYIMPORTEDSERVICEBASE_H

View File

@ -30,7 +30,7 @@ DigitallyImportedUrlHandler::DigitallyImportedUrlHandler(DigitallyImportedServic
} }
QString DigitallyImportedUrlHandler::scheme() const { QString DigitallyImportedUrlHandler::scheme() const {
return service_->url_scheme_; return service_->api_service_name();
} }
UrlHandler::LoadResult DigitallyImportedUrlHandler::StartLoading(const QUrl& url) { UrlHandler::LoadResult DigitallyImportedUrlHandler::StartLoading(const QUrl& url) {

View File

@ -15,7 +15,7 @@
along with Clementine. If not, see <http://www.gnu.org/licenses/>. along with Clementine. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include "digitallyimportedservice.h" #include "digitallyimportedservicebase.h"
#include "icecastservice.h" #include "icecastservice.h"
#include "jamendoservice.h" #include "jamendoservice.h"
#include "magnatuneservice.h" #include "magnatuneservice.h"
@ -23,7 +23,6 @@
#include "internetmodel.h" #include "internetmodel.h"
#include "internetservice.h" #include "internetservice.h"
#include "savedradio.h" #include "savedradio.h"
#include "skyfmservice.h"
#include "somafmservice.h" #include "somafmservice.h"
#include "groovesharkservice.h" #include "groovesharkservice.h"
#include "core/logging.h" #include "core/logging.h"
@ -66,6 +65,7 @@ InternetModel::InternetModel(BackgroundThread<Database>* db_thread,
#ifdef HAVE_LIBLASTFM #ifdef HAVE_LIBLASTFM
AddService(new LastFMService(this)); AddService(new LastFMService(this));
#endif #endif
AddService(new GroovesharkService(this));
AddService(new MagnatuneService(this)); AddService(new MagnatuneService(this));
AddService(new SavedRadio(this)); AddService(new SavedRadio(this));
AddService(new SkyFmService(this)); AddService(new SkyFmService(this));
@ -73,7 +73,6 @@ InternetModel::InternetModel(BackgroundThread<Database>* db_thread,
#ifdef HAVE_SPOTIFY #ifdef HAVE_SPOTIFY
AddService(new SpotifyService(this)); AddService(new SpotifyService(this));
#endif #endif
AddService(new GroovesharkService(this));
} }
void InternetModel::AddService(InternetService *service) { void InternetModel::AddService(InternetService *service) {

View File

@ -1,33 +0,0 @@
/* 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 "digitallyimportedurlhandler.h"
#include "internetmodel.h"
#include "skyfmservice.h"
#include "core/logging.h"
#include "core/taskmanager.h"
#include <QNetworkAccessManager>
#include <QNetworkReply>
SkyFmService::SkyFmService(InternetModel* model, QObject* parent)
: DigitallyImportedServiceBase(
"SKY.fm", model, parent)
{
Init("SKY.fm", QUrl("http://www.sky.fm"), "sky.fm",
QUrl("http://listen.sky.fm"), "skyfm", ":/providers/skyfm.png", "sky");
}

View File

@ -1,28 +0,0 @@
/* 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 SKYFMSERVICE_H
#define SKYFMSERVICE_H
#include "digitallyimportedservicebase.h"
class SkyFmService : public DigitallyImportedServiceBase {
public:
SkyFmService(InternetModel* model, QObject* parent = NULL);
};
#endif // SKYFMSERVICE_H

View File

@ -1003,7 +1003,7 @@ msgstr ""
msgid "Configure library..." msgid "Configure library..."
msgstr "" msgstr ""
#: internet/digitallyimportedservicebase.cpp:189 #: internet/digitallyimportedservicebase.cpp:181
#: ../bin/src/ui_globalsearchsettingspage.h:167 #: ../bin/src/ui_globalsearchsettingspage.h:167
msgid "Configure..." msgid "Configure..."
msgstr "" msgstr ""
@ -1593,7 +1593,7 @@ msgstr ""
msgid "Error loading %1" msgid "Error loading %1"
msgstr "" msgstr ""
#: internet/digitallyimportedservicebase.cpp:211 #: internet/digitallyimportedservicebase.cpp:203
#: internet/digitallyimportedurlhandler.cpp:73 #: internet/digitallyimportedurlhandler.cpp:73
msgid "Error loading di.fm playlist" msgid "Error loading di.fm playlist"
msgstr "" msgstr ""
@ -1854,7 +1854,7 @@ msgstr ""
msgid "Getting channels" msgid "Getting channels"
msgstr "" msgstr ""
#: internet/digitallyimportedservicebase.cpp:111 #: internet/digitallyimportedservicebase.cpp:103
msgid "Getting streams" msgid "Getting streams"
msgstr "" msgstr ""
@ -2736,7 +2736,7 @@ msgstr ""
msgid "Only show the first" msgid "Only show the first"
msgstr "" msgstr ""
#: internet/digitallyimportedservicebase.cpp:182 #: internet/digitallyimportedservicebase.cpp:174
#, qt-format #, qt-format
msgid "Open %1 in browser" msgid "Open %1 in browser"
msgstr "" msgstr ""
@ -3146,7 +3146,7 @@ msgstr ""
msgid "Refresh station list" msgid "Refresh station list"
msgstr "" msgstr ""
#: internet/digitallyimportedservicebase.cpp:185 #: internet/digitallyimportedservicebase.cpp:177
msgid "Refresh streams" msgid "Refresh streams"
msgstr "" msgstr ""