Icons and right click menu for SomaFM

This commit is contained in:
David Sansome 2010-01-18 02:49:07 +00:00
parent 4777b3eab1
commit 491f1184b8
7 changed files with 47 additions and 2 deletions

View File

@ -50,5 +50,8 @@
<file>list-remove.png</file>
<file>clear-list.png</file>
<file>edit-track.png</file>
<file>somafm.png</file>
<file>refresh.png</file>
<file>web.png</file>
</qresource>
</RCC>

BIN
data/refresh.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 931 B

BIN
data/somafm.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 560 B

BIN
data/web.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 953 B

View File

@ -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();

View File

@ -6,6 +6,8 @@
#include <QXmlStreamReader>
#include <QSettings>
#include <QTemporaryFile>
#include <QMenu>
#include <QDesktopServices>
#include <QCoreApplication>
#include <QtDebug>
@ -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_);
}

View File

@ -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_;
};