Icons and right click menu for SomaFM
This commit is contained in:
parent
4777b3eab1
commit
491f1184b8
|
@ -50,5 +50,8 @@
|
||||||
<file>list-remove.png</file>
|
<file>list-remove.png</file>
|
||||||
<file>clear-list.png</file>
|
<file>clear-list.png</file>
|
||||||
<file>edit-track.png</file>
|
<file>edit-track.png</file>
|
||||||
|
<file>somafm.png</file>
|
||||||
|
<file>refresh.png</file>
|
||||||
|
<file>web.png</file>
|
||||||
</qresource>
|
</qresource>
|
||||||
</RCC>
|
</RCC>
|
||||||
|
|
Binary file not shown.
After Width: | Height: | Size: 931 B |
Binary file not shown.
After Width: | Height: | Size: 560 B |
Binary file not shown.
After Width: | Height: | Size: 953 B |
|
@ -408,6 +408,13 @@ void MainWindow::UpdateTrackPosition() {
|
||||||
const int position = std::floor(float(player_->GetEngine()->position()) / 1000.0 + 0.5);
|
const int position = std::floor(float(player_->GetEngine()->position()) / 1000.0 + 0.5);
|
||||||
const int length = playlist_->current_item()->Metadata().length();
|
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?
|
// Time to scrobble?
|
||||||
LastFMService* lastfm = radio_model_->GetLastFMService();
|
LastFMService* lastfm = radio_model_->GetLastFMService();
|
||||||
|
|
||||||
|
|
|
@ -6,6 +6,8 @@
|
||||||
#include <QXmlStreamReader>
|
#include <QXmlStreamReader>
|
||||||
#include <QSettings>
|
#include <QSettings>
|
||||||
#include <QTemporaryFile>
|
#include <QTemporaryFile>
|
||||||
|
#include <QMenu>
|
||||||
|
#include <QDesktopServices>
|
||||||
#include <QCoreApplication>
|
#include <QCoreApplication>
|
||||||
#include <QtDebug>
|
#include <QtDebug>
|
||||||
|
|
||||||
|
@ -13,16 +15,27 @@ const char* SomaFMService::kServiceName = "SomaFM";
|
||||||
const char* SomaFMService::kLoadingChannelsText = "Getting channels";
|
const char* SomaFMService::kLoadingChannelsText = "Getting channels";
|
||||||
const char* SomaFMService::kLoadingStreamText = "Loading stream";
|
const char* SomaFMService::kLoadingStreamText = "Loading stream";
|
||||||
const char* SomaFMService::kChannelListUrl = "http://somafm.com/channels.xml";
|
const char* SomaFMService::kChannelListUrl = "http://somafm.com/channels.xml";
|
||||||
|
const char* SomaFMService::kHomepage = "http://somafm.com";
|
||||||
|
|
||||||
SomaFMService::SomaFMService(QObject* parent)
|
SomaFMService::SomaFMService(QObject* parent)
|
||||||
: RadioService(kServiceName, parent),
|
: RadioService(kServiceName, parent),
|
||||||
root_(NULL),
|
root_(NULL),
|
||||||
|
context_menu_(new QMenu),
|
||||||
network_(new QNetworkAccessManager(this))
|
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) {
|
RadioItem* SomaFMService::CreateRootItem(RadioItem* parent) {
|
||||||
root_ = new RadioItem(this, RadioItem::Type_Service, kServiceName, parent);
|
root_ = new RadioItem(this, RadioItem::Type_Service, kServiceName, parent);
|
||||||
|
root_->icon = QIcon(":somafm.png");
|
||||||
return root_;
|
return root_;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -40,7 +53,8 @@ void SomaFMService::LazyPopulate(RadioItem* item) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void SomaFMService::ShowContextMenu(RadioItem* item, const QPoint& global_pos) {
|
void SomaFMService::ShowContextMenu(RadioItem* item, const QPoint& global_pos) {
|
||||||
|
context_item_ = item;
|
||||||
|
context_menu_->popup(global_pos);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SomaFMService::StartLoading(const QUrl& url) {
|
void SomaFMService::StartLoading(const QUrl& url) {
|
||||||
|
@ -98,6 +112,8 @@ void SomaFMService::RefreshChannelsFinished() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
root_->ClearNotify();
|
||||||
|
|
||||||
QXmlStreamReader reader(reply);
|
QXmlStreamReader reader(reply);
|
||||||
while (!reader.atEnd()) {
|
while (!reader.atEnd()) {
|
||||||
reader.readNext();
|
reader.readNext();
|
||||||
|
@ -107,12 +123,15 @@ void SomaFMService::RefreshChannelsFinished() {
|
||||||
ReadChannel(reader);
|
ReadChannel(reader);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
root_->lazy_loaded = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SomaFMService::ReadChannel(QXmlStreamReader& reader) {
|
void SomaFMService::ReadChannel(QXmlStreamReader& reader) {
|
||||||
RadioItem* item = new RadioItem(this, Type_Stream, QString::null);
|
RadioItem* item = new RadioItem(this, Type_Stream, QString::null);
|
||||||
item->lazy_loaded = true;
|
item->lazy_loaded = true;
|
||||||
item->playable = true;
|
item->playable = true;
|
||||||
|
item->icon = QIcon(":last.fm/icon_radio.png");
|
||||||
|
|
||||||
while (!reader.atEnd()) {
|
while (!reader.atEnd()) {
|
||||||
switch (reader.readNext()) {
|
switch (reader.readNext()) {
|
||||||
|
@ -162,3 +181,11 @@ void SomaFMService::ConsumeElement(QXmlStreamReader& reader) {
|
||||||
QString SomaFMService::TitleForItem(const RadioItem* item) const {
|
QString SomaFMService::TitleForItem(const RadioItem* item) const {
|
||||||
return "SomaFM " + item->display_text;
|
return "SomaFM " + item->display_text;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SomaFMService::Homepage() {
|
||||||
|
QDesktopServices::openUrl(QUrl(kHomepage));
|
||||||
|
}
|
||||||
|
|
||||||
|
void SomaFMService::AddToPlaylist() {
|
||||||
|
emit AddItemToPlaylist(context_item_);
|
||||||
|
}
|
||||||
|
|
|
@ -5,12 +5,14 @@
|
||||||
|
|
||||||
class QNetworkAccessManager;
|
class QNetworkAccessManager;
|
||||||
class QXmlStreamReader;
|
class QXmlStreamReader;
|
||||||
|
class QMenu;
|
||||||
|
|
||||||
class SomaFMService : public RadioService {
|
class SomaFMService : public RadioService {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
SomaFMService(QObject* parent = 0);
|
SomaFMService(QObject* parent = 0);
|
||||||
|
~SomaFMService();
|
||||||
|
|
||||||
enum ItemType {
|
enum ItemType {
|
||||||
Type_Stream = 2000,
|
Type_Stream = 2000,
|
||||||
|
@ -20,6 +22,7 @@ class SomaFMService : public RadioService {
|
||||||
static const char* kLoadingChannelsText;
|
static const char* kLoadingChannelsText;
|
||||||
static const char* kLoadingStreamText;
|
static const char* kLoadingStreamText;
|
||||||
static const char* kChannelListUrl;
|
static const char* kChannelListUrl;
|
||||||
|
static const char* kHomepage;
|
||||||
|
|
||||||
RadioItem* CreateRootItem(RadioItem* parent);
|
RadioItem* CreateRootItem(RadioItem* parent);
|
||||||
void LazyPopulate(RadioItem* item);
|
void LazyPopulate(RadioItem* item);
|
||||||
|
@ -31,16 +34,21 @@ class SomaFMService : public RadioService {
|
||||||
void StartLoading(const QUrl& url);
|
void StartLoading(const QUrl& url);
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
|
void RefreshChannels();
|
||||||
void RefreshChannelsFinished();
|
void RefreshChannelsFinished();
|
||||||
void LoadPlaylistFinished();
|
void LoadPlaylistFinished();
|
||||||
|
|
||||||
|
void AddToPlaylist();
|
||||||
|
void Homepage();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void RefreshChannels();
|
|
||||||
void ReadChannel(QXmlStreamReader& reader);
|
void ReadChannel(QXmlStreamReader& reader);
|
||||||
void ConsumeElement(QXmlStreamReader& reader);
|
void ConsumeElement(QXmlStreamReader& reader);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
RadioItem* root_;
|
RadioItem* root_;
|
||||||
|
QMenu* context_menu_;
|
||||||
|
RadioItem* context_item_;
|
||||||
|
|
||||||
QNetworkAccessManager* network_;
|
QNetworkAccessManager* network_;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue