Add an "Add Podcast" menu item to the main Music menu, and always display new podcasts in the list when adding them

This commit is contained in:
David Sansome 2012-03-12 14:11:24 +00:00
parent c5f5b8b597
commit 40858d26c5
6 changed files with 49 additions and 25 deletions

View File

@ -199,8 +199,11 @@ void AddPodcastDialog::PodcastDoubleClicked(const QModelIndex& index) {
return;
}
Podcast podcast = podcast_variant.value<Podcast>();
app_->podcast_backend()->Subscribe(&podcast);
current_podcast_ = podcast_variant.value<Podcast>();
app_->podcast_backend()->Subscribe(&current_podcast_);
add_button_->setEnabled(false);
remove_button_->setEnabled(true);
}
void AddPodcastDialog::RemovePodcast() {

View File

@ -380,17 +380,18 @@ void PodcastService::AddPodcast() {
}
void PodcastService::SubscriptionAdded(const Podcast& podcast) {
// If the user hasn't expanded the root node yet we don't need to do anything
if (root_->data(InternetModel::Role_CanLazyLoad).toBool()) {
return;
// Ensure the root item is lazy loaded already
LazyLoadRoot();
// The podcast might already be in the list - maybe the LazyLoadRoot() above
// added it.
QStandardItem* item = podcasts_by_database_id_[podcast.database_id()];
if (!item) {
item = CreatePodcastItem(podcast);
model_->appendRow(item);
}
QStandardItem* item = CreatePodcastItem(podcast);
model_->appendRow(item);
if (scroll_to_database_id_.remove(podcast.database_id())) {
emit ScrollToIndex(MapToMergedModel(item->index()));
}
emit ScrollToIndex(MapToMergedModel(item->index()));
}
void PodcastService::SubscriptionRemoved(const Podcast& podcast) {
@ -531,25 +532,26 @@ QModelIndex PodcastService::MapToMergedModel(const QModelIndex& index) const {
return model()->merged_model()->mapFromSource(proxy_->mapFromSource(index));
}
void PodcastService::LazyLoadRoot() {
if (root_->data(InternetModel::Role_CanLazyLoad).toBool()) {
root_->setData(false, InternetModel::Role_CanLazyLoad);
LazyPopulate(root_);
}
}
void PodcastService::SubscribeAndShow(const QVariant& podcast_or_opml) {
if (podcast_or_opml.canConvert<Podcast>()) {
Podcast podcast(podcast_or_opml.value<Podcast>());
backend_->Subscribe(&podcast);
// Lazy load the root item if it hasn't been already
if (root_->data(InternetModel::Role_CanLazyLoad).toBool()) {
root_->setData(false, InternetModel::Role_CanLazyLoad);
LazyPopulate(root_);
}
LazyLoadRoot();
QStandardItem* item = podcasts_by_database_id_[podcast.database_id()];
if (item) {
// There will be an item already if this podcast was already there.
// There will be an item already if this podcast was already there,
// otherwise it'll be scrolled to when the item is created.
emit ScrollToIndex(MapToMergedModel(item->index()));
} else {
// Otherwise we can remember the podcast ID and scroll to it when the
// item is created.
scroll_to_database_id_.insert(podcast.database_id());
}
} else if (podcast_or_opml.canConvert<OpmlContainer>()) {
EnsureAddPodcastDialogCreated();

View File

@ -52,7 +52,7 @@ public:
Role_Podcast = InternetModel::RoleCount,
Role_Episode
};
QStandardItem* CreateRootItem();
void LazyPopulate(QStandardItem* parent);
@ -63,9 +63,11 @@ public:
// subscription to the podcast and displays it in the UI. If the QVariant
// contains an OPML file then this displays it in the Add Podcast dialog.
void SubscribeAndShow(const QVariant& podcast_or_opml);
public slots:
void AddPodcast();
private slots:
void AddPodcast();
void UpdateSelectedPodcast();
void RemoveSelectedPodcast();
void DownloadSelectedEpisode();
@ -100,6 +102,8 @@ private:
QModelIndex MapToMergedModel(const QModelIndex& index) const;
void SetListened(const QModelIndexList& indexes, bool listened);
void LazyLoadRoot();
private:
bool use_pretty_covers_;
@ -132,8 +136,6 @@ private:
QMap<int, QStandardItem*> podcasts_by_database_id_;
QMap<int, QStandardItem*> episodes_by_database_id_;
QSet<int> scroll_to_database_id_;
QScopedPointer<AddPodcastDialog> add_podcast_dialog_;
};

View File

@ -65,6 +65,7 @@
#include "playlist/queuemanager.h"
#include "playlist/songplaylistitem.h"
#include "playlistparsers/playlistparser.h"
#include "podcasts/podcastservice.h"
#include "smartplaylists/generator.h"
#include "smartplaylists/generatormimedata.h"
#include "songinfo/artistinfoview.h"
@ -330,6 +331,7 @@ MainWindow::MainWindow(Application* app,
connect(ui_->action_add_file, SIGNAL(triggered()), SLOT(AddFile()));
connect(ui_->action_add_folder, SIGNAL(triggered()), SLOT(AddFolder()));
connect(ui_->action_add_stream, SIGNAL(triggered()), SLOT(AddStream()));
connect(ui_->action_add_podcast, SIGNAL(triggered()), SLOT(AddPodcast()));
connect(ui_->action_cover_manager, SIGNAL(triggered()), SLOT(ShowCoverManager()));
connect(ui_->action_equalizer, SIGNAL(triggered()), equalizer_.get(), SLOT(show()));
connect(ui_->action_transcode, SIGNAL(triggered()), SLOT(ShowTranscodeDialog()));
@ -2235,3 +2237,7 @@ void MainWindow::ScrollToInternetIndex(const QModelIndex& index) {
internet_view_->ScrollToIndex(index);
ui_->tabs->SetCurrentWidget(internet_view_);
}
void MainWindow::AddPodcast() {
app_->internet_model()->Service<PodcastService>()->AddPodcast();
}

View File

@ -208,6 +208,7 @@ class MainWindow : public QMainWindow, public PlatformInterface {
void AddStream();
void AddStreamAccepted();
void AddCDTracks();
void AddPodcast();
void CommandlineOptionsReceived(const QByteArray& serialized_options);

View File

@ -418,7 +418,7 @@
<x>0</x>
<y>0</y>
<width>1131</width>
<height>22</height>
<height>23</height>
</rect>
</property>
<widget class="QMenu" name="menu_music">
@ -427,6 +427,7 @@
</property>
<addaction name="action_open_media"/>
<addaction name="action_open_cd"/>
<addaction name="action_add_podcast"/>
<addaction name="separator"/>
<addaction name="action_previous_track"/>
<addaction name="action_play_pause"/>
@ -841,6 +842,15 @@
<string>Toggle scrobbling</string>
</property>
</action>
<action name="action_add_podcast">
<property name="icon">
<iconset resource="../../data/data.qrc">
<normaloff>:/providers/podcast16.png</normaloff>:/providers/podcast16.png</iconset>
</property>
<property name="text">
<string>Add podcast...</string>
</property>
</action>
</widget>
<layoutdefault spacing="6" margin="11"/>
<customwidgets>