diff --git a/data/data.qrc b/data/data.qrc
index d7345da99..24032bb7e 100644
--- a/data/data.qrc
+++ b/data/data.qrc
@@ -50,5 +50,8 @@
list-remove.png
clear-list.png
edit-track.png
+ somafm.png
+ refresh.png
+ web.png
diff --git a/data/refresh.png b/data/refresh.png
new file mode 100644
index 000000000..86b6f82c1
Binary files /dev/null and b/data/refresh.png differ
diff --git a/data/somafm.png b/data/somafm.png
new file mode 100644
index 000000000..1d06677df
Binary files /dev/null and b/data/somafm.png differ
diff --git a/data/web.png b/data/web.png
new file mode 100644
index 000000000..670c0716f
Binary files /dev/null and b/data/web.png differ
diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp
index 43c91e372..4fe1a5f93 100644
--- a/src/mainwindow.cpp
+++ b/src/mainwindow.cpp
@@ -408,6 +408,13 @@ void MainWindow::UpdateTrackPosition() {
const int position = std::floor(float(player_->GetEngine()->position()) / 1000.0 + 0.5);
const int length = playlist_->current_item()->Metadata().length();
+ if (length <= 0) {
+ // Probably a stream that we don't know the length of
+ track_slider_->SetStopped();
+ tray_icon_->SetProgress(0);
+ return;
+ }
+
// Time to scrobble?
LastFMService* lastfm = radio_model_->GetLastFMService();
diff --git a/src/somafmservice.cpp b/src/somafmservice.cpp
index 68f39cc23..6bce13a4a 100644
--- a/src/somafmservice.cpp
+++ b/src/somafmservice.cpp
@@ -6,6 +6,8 @@
#include
#include
#include
+#include
+#include
#include
#include
@@ -13,16 +15,27 @@ const char* SomaFMService::kServiceName = "SomaFM";
const char* SomaFMService::kLoadingChannelsText = "Getting channels";
const char* SomaFMService::kLoadingStreamText = "Loading stream";
const char* SomaFMService::kChannelListUrl = "http://somafm.com/channels.xml";
+const char* SomaFMService::kHomepage = "http://somafm.com";
SomaFMService::SomaFMService(QObject* parent)
: RadioService(kServiceName, parent),
root_(NULL),
+ context_menu_(new QMenu),
network_(new QNetworkAccessManager(this))
{
+ context_menu_->addAction(QIcon(":media-playback-start.png"), "Add to playlist", this, SLOT(AddToPlaylist()));
+ context_menu_->addSeparator();
+ context_menu_->addAction(QIcon(":web.png"), "Open somafm.com in browser", this, SLOT(Homepage()));
+ context_menu_->addAction(QIcon(":refresh.png"), "Refresh channels", this, SLOT(RefreshChannels()));
+}
+
+SomaFMService::~SomaFMService() {
+ delete context_menu_;
}
RadioItem* SomaFMService::CreateRootItem(RadioItem* parent) {
root_ = new RadioItem(this, RadioItem::Type_Service, kServiceName, parent);
+ root_->icon = QIcon(":somafm.png");
return root_;
}
@@ -40,7 +53,8 @@ void SomaFMService::LazyPopulate(RadioItem* item) {
}
void SomaFMService::ShowContextMenu(RadioItem* item, const QPoint& global_pos) {
-
+ context_item_ = item;
+ context_menu_->popup(global_pos);
}
void SomaFMService::StartLoading(const QUrl& url) {
@@ -98,6 +112,8 @@ void SomaFMService::RefreshChannelsFinished() {
return;
}
+ root_->ClearNotify();
+
QXmlStreamReader reader(reply);
while (!reader.atEnd()) {
reader.readNext();
@@ -107,12 +123,15 @@ void SomaFMService::RefreshChannelsFinished() {
ReadChannel(reader);
}
}
+
+ root_->lazy_loaded = true;
}
void SomaFMService::ReadChannel(QXmlStreamReader& reader) {
RadioItem* item = new RadioItem(this, Type_Stream, QString::null);
item->lazy_loaded = true;
item->playable = true;
+ item->icon = QIcon(":last.fm/icon_radio.png");
while (!reader.atEnd()) {
switch (reader.readNext()) {
@@ -162,3 +181,11 @@ void SomaFMService::ConsumeElement(QXmlStreamReader& reader) {
QString SomaFMService::TitleForItem(const RadioItem* item) const {
return "SomaFM " + item->display_text;
}
+
+void SomaFMService::Homepage() {
+ QDesktopServices::openUrl(QUrl(kHomepage));
+}
+
+void SomaFMService::AddToPlaylist() {
+ emit AddItemToPlaylist(context_item_);
+}
diff --git a/src/somafmservice.h b/src/somafmservice.h
index 2ffa425d0..7b3e264ed 100644
--- a/src/somafmservice.h
+++ b/src/somafmservice.h
@@ -5,12 +5,14 @@
class QNetworkAccessManager;
class QXmlStreamReader;
+class QMenu;
class SomaFMService : public RadioService {
Q_OBJECT
public:
SomaFMService(QObject* parent = 0);
+ ~SomaFMService();
enum ItemType {
Type_Stream = 2000,
@@ -20,6 +22,7 @@ class SomaFMService : public RadioService {
static const char* kLoadingChannelsText;
static const char* kLoadingStreamText;
static const char* kChannelListUrl;
+ static const char* kHomepage;
RadioItem* CreateRootItem(RadioItem* parent);
void LazyPopulate(RadioItem* item);
@@ -31,16 +34,21 @@ class SomaFMService : public RadioService {
void StartLoading(const QUrl& url);
private slots:
+ void RefreshChannels();
void RefreshChannelsFinished();
void LoadPlaylistFinished();
+ void AddToPlaylist();
+ void Homepage();
+
private:
- void RefreshChannels();
void ReadChannel(QXmlStreamReader& reader);
void ConsumeElement(QXmlStreamReader& reader);
private:
RadioItem* root_;
+ QMenu* context_menu_;
+ RadioItem* context_item_;
QNetworkAccessManager* network_;
};