Lazyload the radio service context menus
This commit is contained in:
parent
75b70b4acb
commit
59e5de1468
@ -60,7 +60,7 @@ const char* MagnatuneService::kDownloadUrl = "http://download.magnatune.com/buy/
|
||||
MagnatuneService::MagnatuneService(RadioModel* parent)
|
||||
: RadioService(kServiceName, parent),
|
||||
root_(NULL),
|
||||
context_menu_(new QMenu),
|
||||
context_menu_(NULL),
|
||||
library_backend_(NULL),
|
||||
library_model_(NULL),
|
||||
library_filter_(NULL),
|
||||
@ -87,21 +87,11 @@ MagnatuneService::MagnatuneService(RadioModel* parent)
|
||||
library_sort_model_->setDynamicSortFilter(true);
|
||||
library_sort_model_->sort(0);
|
||||
|
||||
add_to_playlist_ = context_menu_->addAction(
|
||||
IconLoader::Load("media-playback-start"), tr("Add to playlist"), this, SLOT(AddToPlaylist()));
|
||||
download_ = context_menu_->addAction(
|
||||
IconLoader::Load("download"), tr("Download this album"), this, SLOT(Download()));
|
||||
context_menu_->addSeparator();
|
||||
context_menu_->addAction(IconLoader::Load("download"), tr("Open magnatune.com in browser"), this, SLOT(Homepage()));
|
||||
context_menu_->addAction(IconLoader::Load("view-refresh"), tr("Refresh catalogue"), this, SLOT(ReloadDatabase()));
|
||||
QAction* config_action = context_menu_->addAction(IconLoader::Load("configure"), tr("Configure Magnatune..."), this, SLOT(ShowConfig()));
|
||||
|
||||
library_filter_ = new LibraryFilterWidget(0);
|
||||
library_filter_->SetSettingsGroup(kSettingsGroup);
|
||||
library_filter_->SetLibraryModel(library_model_);
|
||||
library_filter_->SetFilterHint(tr("Search Magnatune"));
|
||||
library_filter_->SetAgeFilterEnabled(false);
|
||||
library_filter_->AddMenuAction(config_action);
|
||||
|
||||
library_model_->Init();
|
||||
}
|
||||
@ -262,8 +252,28 @@ QString MagnatuneService::ReadElementText(QXmlStreamReader& reader) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
void MagnatuneService::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()));
|
||||
download_ = context_menu_->addAction(
|
||||
IconLoader::Load("download"), tr("Download this album"), this, SLOT(Download()));
|
||||
context_menu_->addSeparator();
|
||||
context_menu_->addAction(IconLoader::Load("download"), tr("Open magnatune.com in browser"), this, SLOT(Homepage()));
|
||||
context_menu_->addAction(IconLoader::Load("view-refresh"), tr("Refresh catalogue"), this, SLOT(ReloadDatabase()));
|
||||
QAction* config_action = context_menu_->addAction(IconLoader::Load("configure"), tr("Configure Magnatune..."), this, SLOT(ShowConfig()));
|
||||
|
||||
library_filter_->AddMenuAction(config_action);
|
||||
}
|
||||
|
||||
void MagnatuneService::ShowContextMenu(RadioItem*, const QModelIndex& index,
|
||||
const QPoint& global_pos) {
|
||||
EnsureMenuCreated();
|
||||
|
||||
if (index.model() == library_sort_model_)
|
||||
context_item_ = index;
|
||||
else
|
||||
@ -335,5 +345,6 @@ void MagnatuneService::Download() {
|
||||
}
|
||||
|
||||
QWidget* MagnatuneService::HeaderWidget() const {
|
||||
const_cast<MagnatuneService*>(this)->EnsureMenuCreated();
|
||||
return library_filter_;
|
||||
}
|
||||
|
@ -98,6 +98,8 @@ class MagnatuneService : public RadioService {
|
||||
void ShowConfig();
|
||||
|
||||
private:
|
||||
void EnsureMenuCreated();
|
||||
|
||||
Song ReadTrack(QXmlStreamReader& reader);
|
||||
|
||||
private:
|
||||
|
@ -24,6 +24,7 @@
|
||||
#include "core/mergedproxymodel.h"
|
||||
|
||||
#include <QMimeData>
|
||||
#include <QTime>
|
||||
#include <QtDebug>
|
||||
|
||||
QMap<QString, RadioService*> RadioModel::sServices;
|
||||
@ -43,10 +44,17 @@ RadioModel::RadioModel(BackgroundThread<Database>* db_thread,
|
||||
root_->lazy_loaded = true;
|
||||
merged_model_->setSourceModel(this);
|
||||
|
||||
QTime t;
|
||||
t.start();
|
||||
|
||||
AddService(new LastFMService(this));
|
||||
qDebug() << t.restart() << "lastfm";
|
||||
AddService(new SomaFMService(this));
|
||||
qDebug() << t.restart() << "somafm";
|
||||
AddService(new MagnatuneService(this));
|
||||
qDebug() << t.restart() << "magnatune";
|
||||
AddService(new SavedRadio(this));
|
||||
qDebug() << t.restart() << "saved";
|
||||
}
|
||||
|
||||
void RadioModel::AddService(RadioService *service) {
|
||||
|
@ -27,17 +27,8 @@ const char* SavedRadio::kSettingsGroup = "SavedRadio";
|
||||
SavedRadio::SavedRadio(RadioModel* parent)
|
||||
: RadioService(kServiceName, parent),
|
||||
root_(NULL),
|
||||
context_menu_(new QMenu),
|
||||
edit_dialog_(new AddStreamDialog)
|
||||
context_menu_(NULL)
|
||||
{
|
||||
add_action_ = context_menu_->addAction(IconLoader::Load("media-playback-start"), tr("Add to playlist"), this, SLOT(AddToPlaylist()));
|
||||
remove_action_ = context_menu_->addAction(IconLoader::Load("list-remove"), tr("Remove"), this, SLOT(Remove()));
|
||||
edit_action_ = context_menu_->addAction(IconLoader::Load("edit-rename"), tr("Edit..."), this, SLOT(Edit()));
|
||||
context_menu_->addSeparator();
|
||||
context_menu_->addAction(IconLoader::Load("document-open-remote"), tr("Add another stream..."), this, SIGNAL(ShowAddStreamDialog()));
|
||||
|
||||
edit_dialog_->set_save_visible(false);
|
||||
|
||||
LoadStreams();
|
||||
}
|
||||
|
||||
@ -95,6 +86,15 @@ void SavedRadio::SaveStreams() {
|
||||
|
||||
void SavedRadio::ShowContextMenu(RadioItem* item, const QModelIndex&,
|
||||
const QPoint& global_pos) {
|
||||
if (!context_menu_) {
|
||||
context_menu_ = new QMenu;
|
||||
add_action_ = context_menu_->addAction(IconLoader::Load("media-playback-start"), tr("Add to playlist"), this, SLOT(AddToPlaylist()));
|
||||
remove_action_ = context_menu_->addAction(IconLoader::Load("list-remove"), tr("Remove"), this, SLOT(Remove()));
|
||||
edit_action_ = context_menu_->addAction(IconLoader::Load("edit-rename"), tr("Edit..."), this, SLOT(Edit()));
|
||||
context_menu_->addSeparator();
|
||||
context_menu_->addAction(IconLoader::Load("document-open-remote"), tr("Add another stream..."), this, SIGNAL(ShowAddStreamDialog()));
|
||||
}
|
||||
|
||||
context_item_ = item;
|
||||
|
||||
add_action_->setEnabled(item != root_);
|
||||
@ -111,6 +111,11 @@ void SavedRadio::Remove() {
|
||||
}
|
||||
|
||||
void SavedRadio::Edit() {
|
||||
if (!edit_dialog_) {
|
||||
edit_dialog_.reset(new AddStreamDialog);
|
||||
edit_dialog_->set_save_visible(false);
|
||||
}
|
||||
|
||||
edit_dialog_->set_name(context_item_->display_text);
|
||||
edit_dialog_->set_url(context_item_->key);
|
||||
if (edit_dialog_->exec() == QDialog::Rejected)
|
||||
|
@ -38,15 +38,11 @@ const char* SomaFMService::kHomepage = "http://somafm.com";
|
||||
SomaFMService::SomaFMService(RadioModel* parent)
|
||||
: RadioService(kServiceName, parent),
|
||||
root_(NULL),
|
||||
context_menu_(new QMenu),
|
||||
context_menu_(NULL),
|
||||
get_channels_task_id_(0),
|
||||
get_stream_task_id_(0),
|
||||
network_(parent->network()->network())
|
||||
{
|
||||
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 somafm.com in browser"), this, SLOT(Homepage()));
|
||||
context_menu_->addAction(IconLoader::Load("view-refresh"), tr("Refresh channels"), this, SLOT(RefreshChannels()));
|
||||
}
|
||||
|
||||
SomaFMService::~SomaFMService() {
|
||||
@ -74,6 +70,14 @@ void SomaFMService::LazyPopulate(RadioItem* item) {
|
||||
|
||||
void SomaFMService::ShowContextMenu(RadioItem* item, const QModelIndex&,
|
||||
const QPoint& global_pos) {
|
||||
if (!context_menu_) {
|
||||
context_menu_ = new QMenu;
|
||||
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 somafm.com in browser"), this, SLOT(Homepage()));
|
||||
context_menu_->addAction(IconLoader::Load("view-refresh"), tr("Refresh channels"), this, SLOT(RefreshChannels()));
|
||||
}
|
||||
|
||||
context_item_ = item;
|
||||
context_menu_->popup(global_pos);
|
||||
}
|
||||
|
@ -165,14 +165,19 @@ MainWindow::MainWindow(NetworkAccessManager* network, Engine::Type engine, QWidg
|
||||
|
||||
// Create stuff that needs the database
|
||||
radio_model_ = new RadioModel(database_, network, task_manager_, this);
|
||||
qDebug() << t.restart() << "dbdeps: radio model";
|
||||
player_ = new Player(playlists_, radio_model_->GetLastFMService(), engine, this);
|
||||
qDebug() << t.restart() << "dbdeps: player";
|
||||
library_ = new Library(database_, task_manager_, this);
|
||||
qDebug() << t.restart() << "dbdeps: library";
|
||||
cover_manager_.reset(new AlbumCoverManager(network, library_->backend()));
|
||||
qDebug() << t.restart() << "dbdeps: covermanager";
|
||||
settings_dialog_.reset(new SettingsDialog); // Needs RadioModel
|
||||
qDebug() << t.restart() << "dbdeps: settings dialog";
|
||||
radio_model_->SetSettingsDialog(settings_dialog_.get());
|
||||
qDebug() << t.restart() << "dbdeps: radiomodel";
|
||||
devices_ = new DeviceManager(database_, task_manager_, this),
|
||||
|
||||
qDebug() << t.restart() << "other shit";
|
||||
qDebug() << t.restart() << "dbdeps: devices";
|
||||
|
||||
// Initialise the UI
|
||||
ui_->setupUi(this);
|
||||
|
Loading…
x
Reference in New Issue
Block a user