Context menu to configure Last.fm

This commit is contained in:
David Sansome 2009-12-29 23:01:07 +00:00
parent b5be7d6cb9
commit 939e4b5264
11 changed files with 69 additions and 5 deletions

1
TODO
View File

@ -11,7 +11,6 @@
Last.fm:
- Artist/tag/etc. radio
- Double click from radio list
- Right click on radio list to configure Last.fm
- More types of radio
Long-term:

View File

@ -9,6 +9,7 @@
#include <lastfm/Audioscrobbler>
#include <QSettings>
#include <QMenu>
const char* LastFMService::kServiceName = "Last.fm";
const char* LastFMService::kSettingsGroup = "Last.fm";
@ -20,6 +21,7 @@ LastFMService::LastFMService(QObject* parent)
: RadioService(kServiceName, parent),
tuner_(NULL),
scrobbler_(NULL),
context_menu_(new QMenu),
initial_tune_(false),
scrobbling_enabled_(false)
{
@ -37,10 +39,14 @@ LastFMService::LastFMService(QObject* parent)
config_->ui_.username->setText(lastfm::ws::Username);
config_->ui_.scrobble->setEnabled(scrobbling_enabled_);
context_menu_->addAction(QIcon(":configure.png"), "Configure Last.fm...",
config_, SLOT(show()));
}
LastFMService::~LastFMService() {
delete config_;
delete context_menu_;
}
bool LastFMService::IsAuthenticated() const {
@ -312,3 +318,7 @@ void LastFMService::Ban() {
Scrobble();
LoadNext(last_url_);
}
void LastFMService::ShowContextMenu(RadioItem *, const QPoint &global_pos) {
context_menu_->popup(global_pos);
}

View File

@ -6,6 +6,8 @@
#include <lastfm/RadioTuner>
class QMenu;
class LastFMConfig;
class LastFMService : public RadioService {
@ -32,6 +34,7 @@ class LastFMService : public RadioService {
RadioItem* CreateRootItem(RadioItem* parent);
void LazyPopulate(RadioItem *item);
QList<RadioItem::PlaylistData> DataForItem(RadioItem* item);
void ShowContextMenu(RadioItem *item, const QPoint &global_pos);
void StartLoading(const QUrl& url);
void LoadNext(const QUrl& url);
bool IsPauseAllowed() const { return false; }
@ -72,6 +75,8 @@ class LastFMService : public RadioService {
lastfm::Track last_track_;
LastFMConfig* config_;
QMenu* context_menu_;
QUrl last_url_;
bool initial_tune_;

View File

@ -357,7 +357,7 @@
<number>0</number>
</property>
<item>
<widget class="QTreeView" name="radio_view">
<widget class="RadioView" name="radio_view">
<property name="dragEnabled">
<bool>true</bool>
</property>
@ -588,6 +588,11 @@
<header>fileview.h</header>
<container>1</container>
</customwidget>
<customwidget>
<class>RadioView</class>
<extends>QTreeView</extends>
<header>radioview.h</header>
</customwidget>
</customwidgets>
<resources>
<include location="../data/data.qrc"/>

View File

@ -117,3 +117,8 @@ LastFMService* RadioModel::GetLastFMService() const {
return static_cast<LastFMService*>(sServices[LastFMService::kServiceName]);
return NULL;
}
void RadioModel::ShowContextMenu(RadioItem* item, const QPoint& global_pos) {
if (item->service)
item->service->ShowContextMenu(item, global_pos);
}

View File

@ -32,6 +32,8 @@ class RadioModel : public SimpleTreeModel<RadioItem> {
QStringList mimeTypes() const;
QMimeData* mimeData(const QModelIndexList& indexes) const;
void ShowContextMenu(RadioItem* item, const QPoint& global_pos);
signals:
void LoadingStarted();
void LoadingFinished();

View File

@ -22,6 +22,8 @@ class RadioService : public QObject {
virtual void LazyPopulate(RadioItem* item) = 0;
virtual QList<RadioItem::PlaylistData> DataForItem(RadioItem* item) = 0;
virtual void ShowContextMenu(RadioItem* item, const QPoint& global_pos) {
Q_UNUSED(item); Q_UNUSED(global_pos); }
virtual void StartLoading(const QUrl& url) = 0;
virtual void LoadNext(const QUrl& url) = 0;

18
src/radioview.cpp Normal file
View File

@ -0,0 +1,18 @@
#include "radioview.h"
#include "radiomodel.h"
#include <QContextMenuEvent>
RadioView::RadioView(QWidget *parent)
: QTreeView(parent)
{
}
void RadioView::contextMenuEvent(QContextMenuEvent* e) {
QModelIndex index = indexAt(e->pos());
if (!index.isValid())
return;
RadioModel* radio_model = static_cast<RadioModel*>(model());
radio_model->ShowContextMenu(radio_model->IndexToItem(index), e->globalPos());
}

16
src/radioview.h Normal file
View File

@ -0,0 +1,16 @@
#ifndef RADIOVIEW_H
#define RADIOVIEW_H
#include <QTreeView>
class RadioView : public QTreeView {
Q_OBJECT
public:
RadioView(QWidget* parent = 0);
// QWidget
void contextMenuEvent(QContextMenuEvent* e);
};
#endif // RADIOVIEW_H

View File

@ -18,10 +18,10 @@ class SimpleTreeModel : public QAbstractItemModel {
int rowCount(const QModelIndex& parent) const;
bool hasChildren(const QModelIndex& parent) const;
protected:
T* IndexToItem(const QModelIndex& index) const;
QModelIndex ItemToIndex(T* item) const;
protected:
virtual void LazyPopulate(T* item) = 0;
protected:

View File

@ -41,7 +41,8 @@ SOURCES += main.cpp \
lastfmconfig.cpp \
busyindicator.cpp \
radioplaylistitem.cpp \
radioloadingindicator.cpp
radioloadingindicator.cpp \
radioview.cpp
HEADERS += mainwindow.h \
player.h \
library.h \
@ -82,7 +83,8 @@ HEADERS += mainwindow.h \
busyindicator.h \
radiomimedata.h \
radioplaylistitem.h \
radioloadingindicator.h
radioloadingindicator.h \
radioview.h
FORMS += mainwindow.ui \
libraryconfig.ui \
fileview.ui \