From 2e4814eb3651e9c2a210baca9eecd331afdecefb Mon Sep 17 00:00:00 2001 From: Jim Broadus Date: Sun, 11 Nov 2018 12:53:06 -0800 Subject: [PATCH] Create a PodcastInfoDialog that utilizes the existing PodcastInfoWidget. Add a Podcast Information menu item that is enabled when exactly one podcast is represented by the highlighted items. (#6190) --- src/CMakeLists.txt | 3 + src/internet/podcasts/podcastinfodialog.cpp | 39 +++++++ src/internet/podcasts/podcastinfodialog.h | 42 ++++++++ src/internet/podcasts/podcastinfodialog.ui | 107 ++++++++++++++++++++ src/internet/podcasts/podcastservice.cpp | 21 ++++ src/internet/podcasts/podcastservice.h | 4 + 6 files changed, 216 insertions(+) create mode 100644 src/internet/podcasts/podcastinfodialog.cpp create mode 100644 src/internet/podcasts/podcastinfodialog.h create mode 100644 src/internet/podcasts/podcastinfodialog.ui diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 8ed886174..185ac995c 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -275,6 +275,7 @@ set(SOURCES internet/podcasts/podcastdeleter.cpp internet/podcasts/podcastdownloader.cpp internet/podcasts/podcastepisode.cpp + internet/podcasts/podcastinfodialog.cpp internet/podcasts/podcastinfowidget.cpp internet/podcasts/podcastservice.cpp internet/podcasts/podcastservicemodel.cpp @@ -569,6 +570,7 @@ set(HEADERS internet/podcasts/podcastdiscoverymodel.h internet/podcasts/podcastdeleter.h internet/podcasts/podcastdownloader.h + internet/podcasts/podcastinfodialog.h internet/podcasts/podcastinfowidget.h internet/podcasts/podcastservice.h internet/podcasts/podcastservicemodel.h @@ -715,6 +717,7 @@ set(UI internet/podcasts/addpodcastdialog.ui internet/podcasts/gpoddersearchpage.ui internet/podcasts/itunessearchpage.ui + internet/podcasts/podcastinfodialog.ui internet/podcasts/podcastinfowidget.ui internet/podcasts/podcastsettingspage.ui diff --git a/src/internet/podcasts/podcastinfodialog.cpp b/src/internet/podcasts/podcastinfodialog.cpp new file mode 100644 index 000000000..33db8cde9 --- /dev/null +++ b/src/internet/podcasts/podcastinfodialog.cpp @@ -0,0 +1,39 @@ +/* This file is part of Clementine. + Copyright 2018, Jim Broadus + + Clementine is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + Clementine is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with Clementine. If not, see . +*/ + +#include "podcastinfodialog.h" + +#include "ui_podcastinfodialog.h" + +PodcastInfoDialog::PodcastInfoDialog(Application* app, QWidget* parent) + : QDialog(parent), + app_(app), + ui_(new Ui_PodcastInfoDialog) { + ui_->setupUi(this); + ui_->details->SetApplication(app); +} + +PodcastInfoDialog::~PodcastInfoDialog() { + delete ui_; +} + +void PodcastInfoDialog::ShowPodcast(const Podcast& podcast) { + show(); + ui_->podcast_url->setText(podcast.url().toString()); + ui_->podcast_url->setReadOnly(true); + ui_->details->SetPodcast(podcast); +} diff --git a/src/internet/podcasts/podcastinfodialog.h b/src/internet/podcasts/podcastinfodialog.h new file mode 100644 index 000000000..3643d8007 --- /dev/null +++ b/src/internet/podcasts/podcastinfodialog.h @@ -0,0 +1,42 @@ +/* This file is part of Clementine. + Copyright 2018, Jim Broadus + + Clementine is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + Clementine is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with Clementine. If not, see . +*/ + +#ifndef INTERNET_PODCASTS_PODCASTINFODIALOG_H_ +#define INTERNET_PODCASTS_PODCASTINFODIALOG_H_ + +#include + +class Application; +class Podcast; +class Ui_PodcastInfoDialog; + +class PodcastInfoDialog : public QDialog { + Q_OBJECT + + public: + explicit PodcastInfoDialog(Application* app, QWidget* parent = nullptr); + ~PodcastInfoDialog(); + + void ShowPodcast(const Podcast& podcast); + + private: + Application* app_; + + Ui_PodcastInfoDialog* ui_; +}; + +#endif // INTERNET_PODCASTS_PODCASTINFODIALOG_H_ diff --git a/src/internet/podcasts/podcastinfodialog.ui b/src/internet/podcasts/podcastinfodialog.ui new file mode 100644 index 000000000..e0cbb0970 --- /dev/null +++ b/src/internet/podcasts/podcastinfodialog.ui @@ -0,0 +1,107 @@ + + + PodcastInfoDialog + + + + 0 + 0 + 493 + 395 + + + + Podcast Information + + + + + + + + + + 250 + 100 + + + + + 16777215 + 16777215 + + + + Qt::ScrollBarAlwaysOff + + + true + + + + + 0 + 0 + 473 + 313 + + + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Close + + + + + + + + PodcastInfoWidget + QWidget +
internet/podcasts/podcastinfowidget.h
+ 1 +
+
+ + + + buttonBox + accepted() + PodcastInfoDialog + accept() + + + 248 + 254 + + + 157 + 274 + + + + + buttonBox + rejected() + PodcastInfoDialog + reject() + + + 316 + 260 + + + 286 + 274 + + + + +
diff --git a/src/internet/podcasts/podcastservice.cpp b/src/internet/podcasts/podcastservice.cpp index b38db6050..6b196aaab 100644 --- a/src/internet/podcasts/podcastservice.cpp +++ b/src/internet/podcasts/podcastservice.cpp @@ -26,6 +26,7 @@ #include #include "addpodcastdialog.h" +#include "podcastinfodialog.h" #include "core/application.h" #include "core/logging.h" #include "core/mergedproxymodel.h" @@ -430,6 +431,11 @@ void PodcastService::ShowContextMenu(const QPoint& global_pos) { download_selected_action_ = context_menu_->addAction(IconLoader::Load("download", IconLoader::Base), "", this, SLOT(DownloadSelectedEpisode())); + info_selected_action_ = + context_menu_->addAction(IconLoader::Load("about-info", + IconLoader::Base), + tr("Podcast information"), this, + SLOT(PodcastInfo())); delete_downloaded_action_ = context_menu_->addAction( IconLoader::Load("edit-delete", IconLoader::Base), tr("Delete downloaded data"), this, SLOT(DeleteDownloadedData())); @@ -521,6 +527,12 @@ void PodcastService::ShowContextMenu(const QPoint& global_pos) { delete_downloaded_action_->setEnabled(episodes); } + if (selected_podcasts_.count() == 1) { + info_selected_action_->setEnabled(true); + } else { + info_selected_action_->setEnabled(false); + } + if (explicitly_selected_podcasts_.isEmpty() && selected_episodes_.isEmpty()) { PodcastEpisodeList epis = backend_->GetNewDownloadedEpisodes(); set_listened_action_->setEnabled(!epis.isEmpty()); @@ -686,6 +698,15 @@ void PodcastService::DownloadSelectedEpisode() { } } +void PodcastService::PodcastInfo() { + if (selected_podcasts_.count() > 0) { + const Podcast podcast = + selected_podcasts_[0].data(Role_Podcast).value(); + podcast_info_dialog_.reset(new PodcastInfoDialog(app_)); + podcast_info_dialog_->ShowPodcast(podcast); + } +} + void PodcastService::DeleteDownloadedData() { for (const QModelIndex& index : selected_episodes_) { app_->podcast_deleter()->DeleteEpisode( diff --git a/src/internet/podcasts/podcastservice.h b/src/internet/podcasts/podcastservice.h index eb93de4f7..e6b3c6fbe 100644 --- a/src/internet/podcasts/podcastservice.h +++ b/src/internet/podcasts/podcastservice.h @@ -30,6 +30,7 @@ #include class AddPodcastDialog; +class PodcastInfoDialog; class OrganiseDialog; class Podcast; class PodcastBackend; @@ -76,6 +77,7 @@ class PodcastService : public InternetService { void ReloadPodcast(const Podcast& podcast); void RemoveSelectedPodcast(); void DownloadSelectedEpisode(); + void PodcastInfo(); void DeleteDownloadedData(); void SetNew(); void SetListened(); @@ -148,6 +150,7 @@ class PodcastService : public InternetService { QAction* update_selected_action_; QAction* remove_selected_action_; QAction* download_selected_action_; + QAction* info_selected_action_; QAction* delete_downloaded_action_; QAction* set_new_action_; QAction* set_listened_action_; @@ -164,6 +167,7 @@ class PodcastService : public InternetService { QMap episodes_by_database_id_; std::unique_ptr add_podcast_dialog_; + std::unique_ptr podcast_info_dialog_; }; #endif // INTERNET_PODCASTS_PODCASTSERVICE_H_