diff --git a/src/podcasts/addpodcastdialog.cpp b/src/podcasts/addpodcastdialog.cpp index 6d2f1fde7..b843c808f 100644 --- a/src/podcasts/addpodcastdialog.cpp +++ b/src/podcasts/addpodcastdialog.cpp @@ -199,8 +199,11 @@ void AddPodcastDialog::PodcastDoubleClicked(const QModelIndex& index) { return; } - Podcast podcast = podcast_variant.value(); - app_->podcast_backend()->Subscribe(&podcast); + current_podcast_ = podcast_variant.value(); + app_->podcast_backend()->Subscribe(¤t_podcast_); + + add_button_->setEnabled(false); + remove_button_->setEnabled(true); } void AddPodcastDialog::RemovePodcast() { diff --git a/src/podcasts/podcastservice.cpp b/src/podcasts/podcastservice.cpp index b7f00b1b9..839c1d77e 100644 --- a/src/podcasts/podcastservice.cpp +++ b/src/podcasts/podcastservice.cpp @@ -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_or_opml.value()); 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()) { EnsureAddPodcastDialogCreated(); diff --git a/src/podcasts/podcastservice.h b/src/podcasts/podcastservice.h index c34fe43a3..6242c138a 100644 --- a/src/podcasts/podcastservice.h +++ b/src/podcasts/podcastservice.h @@ -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 podcasts_by_database_id_; QMap episodes_by_database_id_; - QSet scroll_to_database_id_; - QScopedPointer add_podcast_dialog_; }; diff --git a/src/ui/mainwindow.cpp b/src/ui/mainwindow.cpp index e499d6dac..be769870e 100644 --- a/src/ui/mainwindow.cpp +++ b/src/ui/mainwindow.cpp @@ -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()->AddPodcast(); +} diff --git a/src/ui/mainwindow.h b/src/ui/mainwindow.h index f81be8b81..3cd26227e 100644 --- a/src/ui/mainwindow.h +++ b/src/ui/mainwindow.h @@ -208,6 +208,7 @@ class MainWindow : public QMainWindow, public PlatformInterface { void AddStream(); void AddStreamAccepted(); void AddCDTracks(); + void AddPodcast(); void CommandlineOptionsReceived(const QByteArray& serialized_options); diff --git a/src/ui/mainwindow.ui b/src/ui/mainwindow.ui index 87f9418bf..bd7bb03a1 100644 --- a/src/ui/mainwindow.ui +++ b/src/ui/mainwindow.ui @@ -418,7 +418,7 @@ 0 0 1131 - 22 + 23 @@ -427,6 +427,7 @@ + @@ -841,6 +842,15 @@ Toggle scrobbling + + + + :/providers/podcast16.png:/providers/podcast16.png + + + Add podcast... + +