1
0
mirror of https://github.com/clementine-player/Clementine synced 2025-01-30 02:55:19 +01:00

Show a context menu for icecast stations

This commit is contained in:
David Sansome 2010-11-24 19:41:17 +00:00
parent c43a06c04e
commit ad191e0880
42 changed files with 306 additions and 2 deletions

View File

@ -156,13 +156,26 @@ QMimeData* IcecastModel::mimeData(const QModelIndexList& indexes) const {
foreach (const QModelIndex& index, indexes) {
IcecastItem* item = IndexToItem(index);
if (!item)
if (!item || item->type != IcecastItem::Type_Station)
continue;
data->songs << item->station.ToSong();
urls << item->station.url;
}
if (data->songs.isEmpty()) {
delete data;
return NULL;
}
data->setUrls(urls);
return data;
}
Song IcecastModel::GetSong(const QModelIndex& index) const {
IcecastItem* item = IndexToItem(index);
if (!item || item->type != IcecastItem::Type_Station)
return Song();
return item->station.ToSong();
}

View File

@ -41,6 +41,8 @@ public:
IcecastBackend* backend() const { return backend_; }
Song GetSong(const QModelIndex& index) const;
// QAbstractItemModel
QVariant data(const QModelIndex & index, int role = Qt::DisplayRole) const;
Qt::ItemFlags flags(const QModelIndex& index) const;

View File

@ -21,7 +21,9 @@
using std::sort;
using std::unique;
#include <QDesktopServices>
#include <QFutureWatcher>
#include <QMenu>
#include <QMultiHash>
#include <QNetworkReply>
#include <QRegExp>
@ -34,13 +36,17 @@ using std::unique;
#include "core/mergedproxymodel.h"
#include "core/network.h"
#include "core/taskmanager.h"
#include "playlist/songplaylistitem.h"
#include "ui/iconloader.h"
const char* IcecastService::kServiceName = "Icecast";
const char* IcecastService::kDirectoryUrl = "http://dir.xiph.org/yp.xml";
const char* IcecastService::kHomepage = "http://dir.xiph.org/";
IcecastService::IcecastService(RadioModel* parent)
: RadioService(kServiceName, parent),
network_(new NetworkAccessManager(this)),
context_menu_(NULL),
backend_(NULL),
model_(NULL),
filter_(new IcecastFilterWidget(0)),
@ -252,3 +258,43 @@ IcecastBackend::Station IcecastService::ReadStation(QXmlStreamReader* reader) co
QWidget* IcecastService::HeaderWidget() const {
return filter_;
}
void IcecastService::ShowContextMenu(RadioItem* item, const QModelIndex& index,
const QPoint& global_pos) {
EnsureMenuCreated();
if (index.model() == model_)
context_item_ = index;
else
context_item_ = QModelIndex();
add_to_playlist_->setEnabled(context_item_.isValid() &&
model_->GetSong(context_item_).is_valid());
context_menu_->popup(global_pos);
}
void IcecastService::EnsureMenuCreated() {
if (context_menu_)
return;
context_menu_ = new QMenu;
add_to_playlist_ = context_menu_->addAction(
IconLoader::Load("media-playback-start"), tr("Add to playlist"), this, SLOT(AddToPlaylist()));
context_menu_->addSeparator();
context_menu_->addAction(IconLoader::Load("download"), tr("Open dir.xiph.org in browser"), this, SLOT(Homepage()));
context_menu_->addAction(IconLoader::Load("view-refresh"), tr("Refresh station list"), this, SLOT(LoadDirectory()));
}
void IcecastService::Homepage() {
QDesktopServices::openUrl(QUrl(kHomepage));
}
void IcecastService::AddToPlaylist() {
Song song(model_->GetSong(context_item_));
if (!song.is_valid())
return;
emit AddItemsToPlaylist(PlaylistItemList() <<
PlaylistItemPtr(new SongPlaylistItem(song)));
}

View File

@ -27,6 +27,9 @@ class IcecastFilterWidget;
class IcecastModel;
class NetworkAccessManager;
class QAction;
class QMenu;
class IcecastService : public RadioService {
Q_OBJECT
public:
@ -35,6 +38,7 @@ class IcecastService : public RadioService {
static const char* kServiceName;
static const char* kDirectoryUrl;
static const char* kHomepage;
enum ItemType {
Type_Stream = 3000,
@ -44,15 +48,26 @@ class IcecastService : public RadioService {
RadioItem* CreateRootItem(RadioItem* parent);
void LazyPopulate(RadioItem* item);
void ShowContextMenu(RadioItem* item, const QModelIndex& index,
const QPoint& global_pos);
QWidget* HeaderWidget() const;
private:
private slots:
void LoadDirectory();
void Homepage();
void AddToPlaylist();
private:
void EnsureMenuCreated();
IcecastBackend::StationList ParseDirectory(QIODevice* device) const;
IcecastBackend::Station ReadStation(QXmlStreamReader* reader) const;
RadioItem* root_;
NetworkAccessManager* network_;
QMenu* context_menu_;
QModelIndex context_item_;
QAction* add_to_playlist_;
IcecastBackend* backend_;
IcecastModel* model_;

View File

@ -1438,6 +1438,9 @@ msgstr ""
msgid "Open device"
msgstr ""
msgid "Open dir.xiph.org in browser"
msgstr ""
msgid "Open magnatune.com in browser"
msgstr ""
@ -1637,6 +1640,9 @@ msgstr ""
msgid "Refresh channels"
msgstr ""
msgid "Refresh station list"
msgstr ""
msgid "Reggae"
msgstr ""

View File

@ -1442,6 +1442,9 @@ msgstr ""
msgid "Open device"
msgstr ""
msgid "Open dir.xiph.org in browser"
msgstr ""
msgid "Open magnatune.com in browser"
msgstr "Отваряне на magnatune.com в уеб браузер"
@ -1641,6 +1644,9 @@ msgstr ""
msgid "Refresh channels"
msgstr ""
msgid "Refresh station list"
msgstr ""
msgid "Reggae"
msgstr "Реге"

View File

@ -1467,6 +1467,9 @@ msgstr ""
msgid "Open device"
msgstr "Obrir dispositiu"
msgid "Open dir.xiph.org in browser"
msgstr ""
msgid "Open magnatune.com in browser"
msgstr "Obre magnatune.com al navegador"
@ -1666,6 +1669,9 @@ msgstr "Actualitzar catàleg"
msgid "Refresh channels"
msgstr "Actualitzar canals"
msgid "Refresh station list"
msgstr ""
msgid "Reggae"
msgstr "Reggae"

View File

@ -1442,6 +1442,9 @@ msgstr ""
msgid "Open device"
msgstr ""
msgid "Open dir.xiph.org in browser"
msgstr ""
msgid "Open magnatune.com in browser"
msgstr ""
@ -1641,6 +1644,9 @@ msgstr ""
msgid "Refresh channels"
msgstr "Obnovit kanály"
msgid "Refresh station list"
msgstr ""
msgid "Reggae"
msgstr "Reggae"

View File

@ -1438,6 +1438,9 @@ msgstr ""
msgid "Open device"
msgstr ""
msgid "Open dir.xiph.org in browser"
msgstr ""
msgid "Open magnatune.com in browser"
msgstr ""
@ -1637,6 +1640,9 @@ msgstr ""
msgid "Refresh channels"
msgstr ""
msgid "Refresh station list"
msgstr ""
msgid "Reggae"
msgstr ""

View File

@ -1443,6 +1443,9 @@ msgstr ""
msgid "Open device"
msgstr ""
msgid "Open dir.xiph.org in browser"
msgstr ""
msgid "Open magnatune.com in browser"
msgstr ""
@ -1642,6 +1645,9 @@ msgstr ""
msgid "Refresh channels"
msgstr "Genopfrisk kanaler"
msgid "Refresh station list"
msgstr ""
msgid "Reggae"
msgstr "Reggae"

View File

@ -1470,6 +1470,9 @@ msgstr ""
msgid "Open device"
msgstr "Gerät öffnen"
msgid "Open dir.xiph.org in browser"
msgstr ""
msgid "Open magnatune.com in browser"
msgstr "magnatune.com im Browser öffnen"
@ -1669,6 +1672,9 @@ msgstr "Katalog neu laden"
msgid "Refresh channels"
msgstr "Channels neu laden"
msgid "Refresh station list"
msgstr ""
msgid "Reggae"
msgstr "Reggae"

View File

@ -1481,6 +1481,9 @@ msgstr "Εμφάνιση μόνο του πρώτου"
msgid "Open device"
msgstr "Άνοιγμα συσκευής"
msgid "Open dir.xiph.org in browser"
msgstr ""
msgid "Open magnatune.com in browser"
msgstr "Άνοιγμα του magnatune.com στον περιηγητή"
@ -1680,6 +1683,9 @@ msgstr "Ανανέωση καταλόγου"
msgid "Refresh channels"
msgstr "Ανανέωση καναλιών"
msgid "Refresh station list"
msgstr ""
msgid "Reggae"
msgstr "Reggae"

View File

@ -1443,6 +1443,9 @@ msgstr ""
msgid "Open device"
msgstr ""
msgid "Open dir.xiph.org in browser"
msgstr ""
msgid "Open magnatune.com in browser"
msgstr "Open magnatune.com in browser"
@ -1642,6 +1645,9 @@ msgstr "Refresh catalogue"
msgid "Refresh channels"
msgstr "Refresh channels"
msgid "Refresh station list"
msgstr ""
msgid "Reggae"
msgstr "Reggae"

View File

@ -1440,6 +1440,9 @@ msgstr ""
msgid "Open device"
msgstr ""
msgid "Open dir.xiph.org in browser"
msgstr ""
msgid "Open magnatune.com in browser"
msgstr ""
@ -1639,6 +1642,9 @@ msgstr ""
msgid "Refresh channels"
msgstr "Refresh channels"
msgid "Refresh station list"
msgstr ""
msgid "Reggae"
msgstr "Reggae"

View File

@ -1438,6 +1438,9 @@ msgstr ""
msgid "Open device"
msgstr ""
msgid "Open dir.xiph.org in browser"
msgstr ""
msgid "Open magnatune.com in browser"
msgstr ""
@ -1637,6 +1640,9 @@ msgstr ""
msgid "Refresh channels"
msgstr ""
msgid "Refresh station list"
msgstr ""
msgid "Reggae"
msgstr ""

View File

@ -1481,6 +1481,9 @@ msgstr ""
msgid "Open device"
msgstr "Abrir dispositivo"
msgid "Open dir.xiph.org in browser"
msgstr ""
msgid "Open magnatune.com in browser"
msgstr "Abrir magnatune.com en el navegador"
@ -1680,6 +1683,9 @@ msgstr "Actualizar catálogo"
msgid "Refresh channels"
msgstr "Actualizar canales"
msgid "Refresh station list"
msgstr ""
msgid "Reggae"
msgstr "Reggae"

View File

@ -1440,6 +1440,9 @@ msgstr ""
msgid "Open device"
msgstr ""
msgid "Open dir.xiph.org in browser"
msgstr ""
msgid "Open magnatune.com in browser"
msgstr ""
@ -1639,6 +1642,9 @@ msgstr ""
msgid "Refresh channels"
msgstr ""
msgid "Refresh station list"
msgstr ""
msgid "Reggae"
msgstr "Regemuusika"

View File

@ -1440,6 +1440,9 @@ msgstr ""
msgid "Open device"
msgstr ""
msgid "Open dir.xiph.org in browser"
msgstr ""
msgid "Open magnatune.com in browser"
msgstr ""
@ -1639,6 +1642,9 @@ msgstr ""
msgid "Refresh channels"
msgstr ""
msgid "Refresh station list"
msgstr ""
msgid "Reggae"
msgstr "Reggae"

View File

@ -1480,6 +1480,9 @@ msgstr ""
msgid "Open device"
msgstr "Ouvrir le périphérique"
msgid "Open dir.xiph.org in browser"
msgstr ""
msgid "Open magnatune.com in browser"
msgstr "Ouvrir magnatune.com dans le navigateur"
@ -1679,6 +1682,9 @@ msgstr "Actualiser le catalogue"
msgid "Refresh channels"
msgstr "Mettre à jour les canaux"
msgid "Refresh station list"
msgstr ""
msgid "Reggae"
msgstr "Reggae"

View File

@ -1444,6 +1444,9 @@ msgstr ""
msgid "Open device"
msgstr ""
msgid "Open dir.xiph.org in browser"
msgstr ""
msgid "Open magnatune.com in browser"
msgstr ""
@ -1643,6 +1646,9 @@ msgstr ""
msgid "Refresh channels"
msgstr "Actualizar os canais"
msgid "Refresh station list"
msgstr ""
msgid "Reggae"
msgstr "Reggae"

View File

@ -1472,6 +1472,9 @@ msgstr "Csak a legelsőt mutassa"
msgid "Open device"
msgstr "Eszköz megnyitása"
msgid "Open dir.xiph.org in browser"
msgstr ""
msgid "Open magnatune.com in browser"
msgstr "A magnatune.com megnyitása böngészőben"
@ -1671,6 +1674,9 @@ msgstr "Katalógus frissítése"
msgid "Refresh channels"
msgstr "Csatornák frissítése"
msgid "Refresh station list"
msgstr ""
msgid "Reggae"
msgstr "Reggae"

View File

@ -1481,6 +1481,9 @@ msgstr "Mostra solo la prima"
msgid "Open device"
msgstr "Apri dispositivo"
msgid "Open dir.xiph.org in browser"
msgstr ""
msgid "Open magnatune.com in browser"
msgstr "Apri magnatune.com nel browser"
@ -1680,6 +1683,9 @@ msgstr "Aggiorna catalogo"
msgid "Refresh channels"
msgstr "Aggiorna i canali"
msgid "Refresh station list"
msgstr ""
msgid "Reggae"
msgstr "Reggae"

View File

@ -1466,6 +1466,9 @@ msgstr "先頭の未表示する"
msgid "Open device"
msgstr "デバイスを開く"
msgid "Open dir.xiph.org in browser"
msgstr ""
msgid "Open magnatune.com in browser"
msgstr "ブラウザで magnatune.com を開きます"
@ -1665,6 +1668,9 @@ msgstr "カタログの更新"
msgid "Refresh channels"
msgstr "チャンネルの更新"
msgid "Refresh station list"
msgstr ""
msgid "Reggae"
msgstr "Reggae"

View File

@ -1440,6 +1440,9 @@ msgstr ""
msgid "Open device"
msgstr ""
msgid "Open dir.xiph.org in browser"
msgstr ""
msgid "Open magnatune.com in browser"
msgstr ""
@ -1639,6 +1642,9 @@ msgstr ""
msgid "Refresh channels"
msgstr ""
msgid "Refresh station list"
msgstr ""
msgid "Reggae"
msgstr "Регги"

View File

@ -1438,6 +1438,9 @@ msgstr ""
msgid "Open device"
msgstr ""
msgid "Open dir.xiph.org in browser"
msgstr ""
msgid "Open magnatune.com in browser"
msgstr ""
@ -1637,6 +1640,9 @@ msgstr ""
msgid "Refresh channels"
msgstr ""
msgid "Refresh station list"
msgstr ""
msgid "Reggae"
msgstr ""

View File

@ -1452,6 +1452,9 @@ msgstr ""
msgid "Open device"
msgstr ""
msgid "Open dir.xiph.org in browser"
msgstr ""
msgid "Open magnatune.com in browser"
msgstr ""
@ -1651,6 +1654,9 @@ msgstr ""
msgid "Refresh channels"
msgstr "Hent kanaler på ny"
msgid "Refresh station list"
msgstr ""
msgid "Reggae"
msgstr "Reggae"

View File

@ -1471,6 +1471,9 @@ msgstr ""
msgid "Open device"
msgstr "Apparaat openen"
msgid "Open dir.xiph.org in browser"
msgstr ""
msgid "Open magnatune.com in browser"
msgstr "Magnatune.com in webbrowser openen"
@ -1670,6 +1673,9 @@ msgstr "Catalogus verversen"
msgid "Refresh channels"
msgstr "Kanalen verversen"
msgid "Refresh station list"
msgstr ""
msgid "Reggae"
msgstr "Reggae"

View File

@ -1438,6 +1438,9 @@ msgstr ""
msgid "Open device"
msgstr ""
msgid "Open dir.xiph.org in browser"
msgstr ""
msgid "Open magnatune.com in browser"
msgstr ""
@ -1637,6 +1640,9 @@ msgstr ""
msgid "Refresh channels"
msgstr ""
msgid "Refresh station list"
msgstr ""
msgid "Reggae"
msgstr "Reggae"

View File

@ -1468,6 +1468,9 @@ msgstr ""
msgid "Open device"
msgstr "Otwórz urządzenie"
msgid "Open dir.xiph.org in browser"
msgstr ""
msgid "Open magnatune.com in browser"
msgstr "Otwórz magnatune.com w przeglądarce"
@ -1667,6 +1670,9 @@ msgstr "Odśwież katalog"
msgid "Refresh channels"
msgstr "Odśwież kanały"
msgid "Refresh station list"
msgstr ""
msgid "Reggae"
msgstr "Reggae"

View File

@ -1477,6 +1477,9 @@ msgstr "Mostrar apenas a primeira"
msgid "Open device"
msgstr "Abrir dispositivo"
msgid "Open dir.xiph.org in browser"
msgstr ""
msgid "Open magnatune.com in browser"
msgstr "Abrir magnatune.com no navegador"
@ -1676,6 +1679,9 @@ msgstr "Atualizar catálogo"
msgid "Refresh channels"
msgstr "Atualizar canais"
msgid "Refresh station list"
msgstr ""
msgid "Reggae"
msgstr "Reggae"

View File

@ -1456,6 +1456,9 @@ msgstr ""
msgid "Open device"
msgstr ""
msgid "Open dir.xiph.org in browser"
msgstr ""
msgid "Open magnatune.com in browser"
msgstr "Abrir magnatune.com no navegador"
@ -1655,6 +1658,9 @@ msgstr "Atualizar catálogo"
msgid "Refresh channels"
msgstr "Atualizar canais"
msgid "Refresh station list"
msgstr ""
msgid "Reggae"
msgstr "Reggae"

View File

@ -1439,6 +1439,9 @@ msgstr ""
msgid "Open device"
msgstr ""
msgid "Open dir.xiph.org in browser"
msgstr ""
msgid "Open magnatune.com in browser"
msgstr ""
@ -1638,6 +1641,9 @@ msgstr ""
msgid "Refresh channels"
msgstr "Reîncarcă canalele"
msgid "Refresh station list"
msgstr ""
msgid "Reggae"
msgstr "Reggae"

View File

@ -1462,6 +1462,9 @@ msgstr ""
msgid "Open device"
msgstr "Открыть устройство"
msgid "Open dir.xiph.org in browser"
msgstr ""
msgid "Open magnatune.com in browser"
msgstr "Открыть в браузере magnatune.com"
@ -1661,6 +1664,9 @@ msgstr "Обновить каталог"
msgid "Refresh channels"
msgstr "Обновить каналы"
msgid "Refresh station list"
msgstr ""
msgid "Reggae"
msgstr "Reggae"

View File

@ -1464,6 +1464,9 @@ msgstr "Iba prvé zobraziť"
msgid "Open device"
msgstr "Otvoriť zariadenie"
msgid "Open dir.xiph.org in browser"
msgstr ""
msgid "Open magnatune.com in browser"
msgstr "Otvoriť magnatune.com v prehliadači"
@ -1663,6 +1666,9 @@ msgstr "Obnoviť katalóg"
msgid "Refresh channels"
msgstr "Obnoviť kanály"
msgid "Refresh station list"
msgstr ""
msgid "Reggae"
msgstr "Reggae"

View File

@ -1467,6 +1467,9 @@ msgstr "Pokaži le prve"
msgid "Open device"
msgstr "Odpri napravo"
msgid "Open dir.xiph.org in browser"
msgstr ""
msgid "Open magnatune.com in browser"
msgstr "Odpri magnatune.com v brskalniku"
@ -1666,6 +1669,9 @@ msgstr "Osveži katalog"
msgid "Refresh channels"
msgstr "Osveži kanale"
msgid "Refresh station list"
msgstr ""
msgid "Reggae"
msgstr "Reggae"

View File

@ -1443,6 +1443,9 @@ msgstr ""
msgid "Open device"
msgstr ""
msgid "Open dir.xiph.org in browser"
msgstr ""
msgid "Open magnatune.com in browser"
msgstr "Отвори magnatune.com у прегледачу"
@ -1642,6 +1645,9 @@ msgstr "Освежи каталог"
msgid "Refresh channels"
msgstr "Освежи канале"
msgid "Refresh station list"
msgstr ""
msgid "Reggae"
msgstr "Реге"

View File

@ -1464,6 +1464,9 @@ msgstr "Visa endast de första"
msgid "Open device"
msgstr "Öppna enhet"
msgid "Open dir.xiph.org in browser"
msgstr ""
msgid "Open magnatune.com in browser"
msgstr "Öppna magnatune.com i en webbläsare"
@ -1663,6 +1666,9 @@ msgstr "Updatera katalog"
msgid "Refresh channels"
msgstr "Uppdatera kanaler"
msgid "Refresh station list"
msgstr ""
msgid "Reggae"
msgstr "Reggae"

View File

@ -1464,6 +1464,9 @@ msgstr ""
msgid "Open device"
msgstr "Aygıtı aç"
msgid "Open dir.xiph.org in browser"
msgstr ""
msgid "Open magnatune.com in browser"
msgstr "magnatune.com'u tarayıcıda aç"
@ -1663,6 +1666,9 @@ msgstr "Kataloğu yenile"
msgid "Refresh channels"
msgstr "Kanalları yenile"
msgid "Refresh station list"
msgstr ""
msgid "Reggae"
msgstr "Reggae"

View File

@ -1428,6 +1428,9 @@ msgstr ""
msgid "Open device"
msgstr ""
msgid "Open dir.xiph.org in browser"
msgstr ""
msgid "Open magnatune.com in browser"
msgstr ""
@ -1627,6 +1630,9 @@ msgstr ""
msgid "Refresh channels"
msgstr ""
msgid "Refresh station list"
msgstr ""
msgid "Reggae"
msgstr ""

View File

@ -1466,6 +1466,9 @@ msgstr "Показувати лише перший"
msgid "Open device"
msgstr "Відкрити пристрій"
msgid "Open dir.xiph.org in browser"
msgstr ""
msgid "Open magnatune.com in browser"
msgstr "Відкрити magnatune.com в браузері"
@ -1665,6 +1668,9 @@ msgstr "Оновити каталог"
msgid "Refresh channels"
msgstr "Оновити канали"
msgid "Refresh station list"
msgstr ""
msgid "Reggae"
msgstr "Реґґі"

View File

@ -1440,6 +1440,9 @@ msgstr ""
msgid "Open device"
msgstr ""
msgid "Open dir.xiph.org in browser"
msgstr ""
msgid "Open magnatune.com in browser"
msgstr ""
@ -1639,6 +1642,9 @@ msgstr ""
msgid "Refresh channels"
msgstr ""
msgid "Refresh station list"
msgstr ""
msgid "Reggae"
msgstr ""

View File

@ -1443,6 +1443,9 @@ msgstr ""
msgid "Open device"
msgstr ""
msgid "Open dir.xiph.org in browser"
msgstr ""
msgid "Open magnatune.com in browser"
msgstr "在瀏覽器中打開 magnatune.com"
@ -1642,6 +1645,9 @@ msgstr "刷新目錄"
msgid "Refresh channels"
msgstr "刷新頻道"
msgid "Refresh station list"
msgstr ""
msgid "Reggae"
msgstr "雷鬼"