2012-03-05 19:15:45 +01:00
|
|
|
/* This file is part of Clementine.
|
|
|
|
Copyright 2012, David Sansome <me@davidsansome.com>
|
2014-02-07 16:34:20 +01:00
|
|
|
|
2012-03-05 19:15:45 +01:00
|
|
|
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.
|
2014-02-07 16:34:20 +01:00
|
|
|
|
2012-03-05 19:15:45 +01:00
|
|
|
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.
|
2014-02-07 16:34:20 +01:00
|
|
|
|
2012-03-05 19:15:45 +01:00
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with Clementine. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "addpodcastdialog.h"
|
2012-03-11 18:57:15 +01:00
|
|
|
#include "opmlcontainer.h"
|
2012-03-06 19:37:46 +01:00
|
|
|
#include "podcastbackend.h"
|
2012-03-10 16:32:36 +01:00
|
|
|
#include "podcastdownloader.h"
|
2012-03-05 19:15:45 +01:00
|
|
|
#include "podcastservice.h"
|
2012-03-11 00:39:09 +01:00
|
|
|
#include "podcastservicemodel.h"
|
2012-03-09 13:15:24 +01:00
|
|
|
#include "podcastupdater.h"
|
2012-03-06 19:37:46 +01:00
|
|
|
#include "core/application.h"
|
2012-03-06 22:24:41 +01:00
|
|
|
#include "core/logging.h"
|
2012-03-07 12:04:47 +01:00
|
|
|
#include "core/mergedproxymodel.h"
|
2014-01-25 10:28:46 +01:00
|
|
|
#include "devices/devicemanager.h"
|
|
|
|
#include "devices/devicestatefiltermodel.h"
|
|
|
|
#include "devices/deviceview.h"
|
2012-03-05 19:15:45 +01:00
|
|
|
#include "internet/internetmodel.h"
|
2012-03-06 22:24:41 +01:00
|
|
|
#include "library/libraryview.h"
|
2012-03-05 19:15:45 +01:00
|
|
|
#include "ui/iconloader.h"
|
2013-12-30 16:01:02 +01:00
|
|
|
#include "ui/organisedialog.h"
|
|
|
|
#include "ui/organiseerrordialog.h"
|
2014-01-25 10:28:46 +01:00
|
|
|
#include "ui/standarditemiconloader.h"
|
2012-03-05 19:15:45 +01:00
|
|
|
|
|
|
|
#include <QMenu>
|
2012-03-07 12:04:47 +01:00
|
|
|
#include <QSortFilterProxyModel>
|
2012-03-05 19:15:45 +01:00
|
|
|
|
|
|
|
const char* PodcastService::kServiceName = "Podcasts";
|
|
|
|
const char* PodcastService::kSettingsGroup = "Podcasts";
|
|
|
|
|
2012-03-09 13:15:24 +01:00
|
|
|
class PodcastSortProxyModel : public QSortFilterProxyModel {
|
2014-02-07 16:34:20 +01:00
|
|
|
public:
|
2014-02-07 20:34:34 +01:00
|
|
|
explicit PodcastSortProxyModel(QObject* parent = nullptr);
|
2012-03-09 13:15:24 +01:00
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
protected:
|
2012-03-09 13:15:24 +01:00
|
|
|
bool lessThan(const QModelIndex& left, const QModelIndex& right) const;
|
|
|
|
};
|
|
|
|
|
2012-03-05 19:15:45 +01:00
|
|
|
PodcastService::PodcastService(Application* app, InternetModel* parent)
|
2014-02-07 16:34:20 +01:00
|
|
|
: InternetService(kServiceName, app, parent, parent),
|
|
|
|
use_pretty_covers_(true),
|
|
|
|
icon_loader_(new StandardItemIconLoader(app->album_cover_loader(), this)),
|
|
|
|
backend_(app->podcast_backend()),
|
|
|
|
model_(new PodcastServiceModel(this)),
|
|
|
|
proxy_(new PodcastSortProxyModel(this)),
|
|
|
|
context_menu_(nullptr),
|
|
|
|
root_(nullptr),
|
2014-10-30 17:52:21 +01:00
|
|
|
organise_dialog_(new OrganiseDialog(app_->task_manager(),
|
|
|
|
nullptr, this)) {
|
2012-03-07 12:04:47 +01:00
|
|
|
icon_loader_->SetModel(model_);
|
|
|
|
proxy_->setSourceModel(model_);
|
|
|
|
proxy_->setDynamicSortFilter(true);
|
|
|
|
proxy_->sort(0);
|
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
connect(backend_, SIGNAL(SubscriptionAdded(Podcast)),
|
|
|
|
SLOT(SubscriptionAdded(Podcast)));
|
|
|
|
connect(backend_, SIGNAL(SubscriptionRemoved(Podcast)),
|
|
|
|
SLOT(SubscriptionRemoved(Podcast)));
|
|
|
|
connect(backend_, SIGNAL(EpisodesAdded(PodcastEpisodeList)),
|
|
|
|
SLOT(EpisodesAdded(PodcastEpisodeList)));
|
|
|
|
connect(backend_, SIGNAL(EpisodesUpdated(PodcastEpisodeList)),
|
|
|
|
SLOT(EpisodesUpdated(PodcastEpisodeList)));
|
|
|
|
|
|
|
|
connect(app_->playlist_manager(), SIGNAL(CurrentSongChanged(Song)),
|
|
|
|
SLOT(CurrentSongChanged(Song)));
|
2012-03-05 19:15:45 +01:00
|
|
|
}
|
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
PodcastService::~PodcastService() {}
|
2012-03-05 19:15:45 +01:00
|
|
|
|
2012-03-09 13:15:24 +01:00
|
|
|
PodcastSortProxyModel::PodcastSortProxyModel(QObject* parent)
|
2014-02-07 16:34:20 +01:00
|
|
|
: QSortFilterProxyModel(parent) {}
|
2012-03-09 13:15:24 +01:00
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
bool PodcastSortProxyModel::lessThan(const QModelIndex& left,
|
|
|
|
const QModelIndex& right) const {
|
|
|
|
const int left_type = left.data(InternetModel::Role_Type).toInt();
|
2012-03-09 13:15:24 +01:00
|
|
|
const int right_type = right.data(InternetModel::Role_Type).toInt();
|
|
|
|
|
|
|
|
// The special Add Podcast item comes first
|
|
|
|
if (left_type == PodcastService::Type_AddPodcast)
|
|
|
|
return true;
|
|
|
|
else if (right_type == PodcastService::Type_AddPodcast)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// Otherwise we only compare identical typed items.
|
|
|
|
if (left_type != right_type)
|
|
|
|
return QSortFilterProxyModel::lessThan(left, right);
|
|
|
|
|
|
|
|
switch (left_type) {
|
2014-02-07 16:34:20 +01:00
|
|
|
case PodcastService::Type_Podcast:
|
|
|
|
return left.data().toString().localeAwareCompare(
|
|
|
|
right.data().toString()) < 0;
|
2012-03-09 13:15:24 +01:00
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
case PodcastService::Type_Episode: {
|
|
|
|
const PodcastEpisode left_episode =
|
|
|
|
left.data(PodcastService::Role_Episode).value<PodcastEpisode>();
|
|
|
|
const PodcastEpisode right_episode =
|
|
|
|
right.data(PodcastService::Role_Episode).value<PodcastEpisode>();
|
2012-03-09 13:15:24 +01:00
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
return left_episode.publication_date() > right_episode.publication_date();
|
|
|
|
}
|
2012-03-09 13:15:24 +01:00
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
default:
|
|
|
|
return QSortFilterProxyModel::lessThan(left, right);
|
2012-03-09 13:15:24 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-03-05 19:15:45 +01:00
|
|
|
QStandardItem* PodcastService::CreateRootItem() {
|
|
|
|
root_ = new QStandardItem(QIcon(":providers/podcast16.png"), tr("Podcasts"));
|
2012-03-06 19:37:46 +01:00
|
|
|
root_->setData(true, InternetModel::Role_CanLazyLoad);
|
2012-03-05 19:15:45 +01:00
|
|
|
return root_;
|
|
|
|
}
|
|
|
|
|
2014-01-27 13:46:43 +01:00
|
|
|
void PodcastService::CopyToDevice() {
|
2014-01-24 01:04:15 +01:00
|
|
|
if (selected_episodes_.isEmpty() && explicitly_selected_podcasts_.isEmpty()) {
|
2014-01-27 13:46:43 +01:00
|
|
|
CopyToDevice(backend_->GetNewDownloadedEpisodes());
|
2014-01-25 10:28:46 +01:00
|
|
|
} else {
|
2014-01-27 13:46:43 +01:00
|
|
|
CopyToDevice(selected_episodes_, explicitly_selected_podcasts_);
|
2014-01-07 23:17:59 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-01-27 13:46:43 +01:00
|
|
|
void PodcastService::CopyToDevice(const PodcastEpisodeList& episodes_list) {
|
2014-01-28 16:04:17 +01:00
|
|
|
SongList songs;
|
2014-01-07 23:17:59 +01:00
|
|
|
Podcast podcast;
|
2014-01-28 16:04:17 +01:00
|
|
|
for (const PodcastEpisode& episode : episodes_list) {
|
2014-01-07 23:17:59 +01:00
|
|
|
podcast = backend_->GetSubscriptionById(episode.podcast_database_id());
|
|
|
|
songs.append(episode.ToSong(podcast));
|
|
|
|
}
|
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
organise_dialog_->SetDestinationModel(
|
|
|
|
app_->device_manager()->connected_devices_model(), true);
|
2014-01-07 23:17:59 +01:00
|
|
|
organise_dialog_->SetCopy(true);
|
2014-02-07 16:34:20 +01:00
|
|
|
if (organise_dialog_->SetSongs(songs)) organise_dialog_->show();
|
2014-01-07 23:17:59 +01:00
|
|
|
}
|
|
|
|
|
2014-01-27 13:46:43 +01:00
|
|
|
void PodcastService::CopyToDevice(const QModelIndexList& episode_indexes,
|
2014-02-07 16:34:20 +01:00
|
|
|
const QModelIndexList& podcast_indexes) {
|
2014-01-01 18:23:52 +01:00
|
|
|
PodcastEpisode episode_tmp;
|
2014-02-07 16:34:20 +01:00
|
|
|
SongList songs;
|
2014-01-07 23:17:59 +01:00
|
|
|
PodcastEpisodeList episodes;
|
2014-01-01 18:23:52 +01:00
|
|
|
Podcast podcast;
|
2014-01-28 16:04:17 +01:00
|
|
|
for (const QModelIndex& index : episode_indexes) {
|
2014-01-01 18:23:52 +01:00
|
|
|
episode_tmp = index.data(Role_Episode).value<PodcastEpisode>();
|
2014-02-07 16:34:20 +01:00
|
|
|
if (episode_tmp.downloaded()) episodes << episode_tmp;
|
2013-12-30 16:01:02 +01:00
|
|
|
}
|
2014-01-02 07:52:03 +01:00
|
|
|
|
2014-01-28 16:04:17 +01:00
|
|
|
for (const QModelIndex& podcast : podcast_indexes) {
|
2014-01-25 10:28:46 +01:00
|
|
|
for (int i = 0; i < podcast.model()->rowCount(podcast); ++i) {
|
2014-01-24 00:47:24 +01:00
|
|
|
const QModelIndex& index = podcast.child(i, 0);
|
|
|
|
episode_tmp = index.data(Role_Episode).value<PodcastEpisode>();
|
|
|
|
if (episode_tmp.downloaded() && !episode_tmp.listened())
|
2014-01-25 10:28:46 +01:00
|
|
|
episodes << episode_tmp;
|
2014-01-24 00:47:24 +01:00
|
|
|
}
|
|
|
|
}
|
2014-01-28 16:04:17 +01:00
|
|
|
for (const PodcastEpisode& episode : episodes) {
|
2014-01-24 00:47:24 +01:00
|
|
|
podcast = backend_->GetSubscriptionById(episode.podcast_database_id());
|
|
|
|
songs.append(episode.ToSong(podcast));
|
|
|
|
}
|
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
organise_dialog_->SetDestinationModel(
|
|
|
|
app_->device_manager()->connected_devices_model(), true);
|
2014-01-25 10:28:46 +01:00
|
|
|
organise_dialog_->SetCopy(true);
|
2014-02-07 16:34:20 +01:00
|
|
|
if (organise_dialog_->SetSongs(songs)) organise_dialog_->show();
|
2014-01-24 00:47:24 +01:00
|
|
|
}
|
|
|
|
|
2012-03-05 19:15:45 +01:00
|
|
|
void PodcastService::LazyPopulate(QStandardItem* parent) {
|
2012-03-06 19:37:46 +01:00
|
|
|
switch (parent->data(InternetModel::Role_Type).toInt()) {
|
2014-02-07 16:34:20 +01:00
|
|
|
case InternetModel::Type_Service:
|
|
|
|
PopulatePodcastList(model_->invisibleRootItem());
|
|
|
|
model()->merged_model()->AddSubModel(parent->index(), proxy_);
|
|
|
|
break;
|
2012-03-06 19:37:46 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void PodcastService::PopulatePodcastList(QStandardItem* parent) {
|
2012-03-10 22:05:57 +01:00
|
|
|
// Do this here since the downloader won't be created yet in the ctor.
|
2014-02-07 16:34:20 +01:00
|
|
|
connect(
|
|
|
|
app_->podcast_downloader(),
|
|
|
|
SIGNAL(ProgressChanged(PodcastEpisode, PodcastDownloader::State, int)),
|
|
|
|
SLOT(DownloadProgressChanged(PodcastEpisode, PodcastDownloader::State,
|
|
|
|
int)));
|
2012-03-10 22:05:57 +01:00
|
|
|
|
2012-03-06 22:24:41 +01:00
|
|
|
if (default_icon_.isNull()) {
|
|
|
|
default_icon_ = QIcon(":providers/podcast16.png");
|
|
|
|
}
|
|
|
|
|
2014-01-28 16:04:17 +01:00
|
|
|
for (const Podcast& podcast : backend_->GetAllSubscriptions()) {
|
2012-03-07 12:04:47 +01:00
|
|
|
parent->appendRow(CreatePodcastItem(podcast));
|
|
|
|
}
|
|
|
|
}
|
2012-03-06 19:37:46 +01:00
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
void PodcastService::UpdatePodcastText(QStandardItem* item,
|
|
|
|
int unlistened_count) const {
|
2012-03-09 13:15:24 +01:00
|
|
|
const Podcast podcast = item->data(Role_Podcast).value<Podcast>();
|
2012-03-06 19:37:46 +01:00
|
|
|
|
2013-12-29 15:25:30 +01:00
|
|
|
QString title = podcast.title().simplified();
|
2012-03-09 13:15:24 +01:00
|
|
|
QFont font;
|
2012-03-06 19:37:46 +01:00
|
|
|
|
2012-03-07 12:04:47 +01:00
|
|
|
if (unlistened_count > 0) {
|
|
|
|
// Add the number of new episodes after the title.
|
|
|
|
title.append(QString(" (%1)").arg(unlistened_count));
|
2012-03-06 19:37:46 +01:00
|
|
|
|
2012-03-07 12:04:47 +01:00
|
|
|
// Set a bold font
|
2012-03-10 22:05:57 +01:00
|
|
|
font.setBold(true);
|
2012-03-09 13:15:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
item->setFont(font);
|
|
|
|
item->setText(title);
|
|
|
|
}
|
|
|
|
|
2012-03-10 22:05:57 +01:00
|
|
|
void PodcastService::UpdateEpisodeText(QStandardItem* item,
|
|
|
|
PodcastDownloader::State state,
|
|
|
|
int percent) {
|
2014-02-07 16:34:20 +01:00
|
|
|
const PodcastEpisode episode =
|
|
|
|
item->data(Role_Episode).value<PodcastEpisode>();
|
2012-03-10 22:05:57 +01:00
|
|
|
|
2013-12-29 15:25:30 +01:00
|
|
|
QString title = episode.title().simplified();
|
2012-03-10 22:05:57 +01:00
|
|
|
QString tooltip;
|
|
|
|
QFont font;
|
|
|
|
QIcon icon;
|
|
|
|
|
2012-03-11 00:39:09 +01:00
|
|
|
// Unlistened episodes are bold
|
2012-03-10 22:05:57 +01:00
|
|
|
if (!episode.listened()) {
|
|
|
|
font.setBold(true);
|
|
|
|
}
|
|
|
|
|
2012-03-11 00:39:09 +01:00
|
|
|
// Downloaded episodes get an icon
|
2012-03-10 22:05:57 +01:00
|
|
|
if (episode.downloaded()) {
|
|
|
|
if (downloaded_icon_.isNull()) {
|
|
|
|
downloaded_icon_ = IconLoader::Load("document-save");
|
|
|
|
}
|
|
|
|
icon = downloaded_icon_;
|
|
|
|
}
|
|
|
|
|
2012-03-11 00:39:09 +01:00
|
|
|
// Queued or downloading episodes get icons, tooltips, and maybe a title.
|
2012-03-10 22:05:57 +01:00
|
|
|
switch (state) {
|
2014-02-07 16:34:20 +01:00
|
|
|
case PodcastDownloader::Queued:
|
|
|
|
if (queued_icon_.isNull()) {
|
|
|
|
queued_icon_ = QIcon(":icons/22x22/user-away.png");
|
|
|
|
}
|
|
|
|
icon = queued_icon_;
|
|
|
|
tooltip = tr("Download queued");
|
|
|
|
break;
|
2012-03-10 22:05:57 +01:00
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
case PodcastDownloader::Downloading:
|
|
|
|
if (downloading_icon_.isNull()) {
|
|
|
|
downloading_icon_ = IconLoader::Load("go-down");
|
|
|
|
}
|
|
|
|
icon = downloading_icon_;
|
|
|
|
tooltip = tr("Downloading (%1%)...").arg(percent);
|
|
|
|
title =
|
|
|
|
QString("[ %1% ] %2").arg(QString::number(percent), episode.title());
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PodcastDownloader::Finished:
|
|
|
|
case PodcastDownloader::NotDownloading:
|
|
|
|
break;
|
2012-03-10 22:05:57 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
item->setFont(font);
|
|
|
|
item->setText(title);
|
|
|
|
item->setIcon(icon);
|
|
|
|
}
|
|
|
|
|
2012-03-09 13:15:24 +01:00
|
|
|
QStandardItem* PodcastService::CreatePodcastItem(const Podcast& podcast) {
|
|
|
|
QStandardItem* item = new QStandardItem;
|
|
|
|
|
|
|
|
// Add the episodes in this podcast and gather aggregate stats.
|
|
|
|
int unlistened_count = 0;
|
2014-02-07 16:34:20 +01:00
|
|
|
for (const PodcastEpisode& episode :
|
|
|
|
backend_->GetEpisodes(podcast.database_id())) {
|
2012-03-09 13:15:24 +01:00
|
|
|
if (!episode.listened()) {
|
2014-01-25 10:28:46 +01:00
|
|
|
unlistened_count++;
|
2012-03-09 13:15:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
item->appendRow(CreatePodcastEpisodeItem(episode));
|
2012-03-07 12:04:47 +01:00
|
|
|
}
|
2012-03-06 22:24:41 +01:00
|
|
|
|
2012-03-07 12:04:47 +01:00
|
|
|
item->setIcon(default_icon_);
|
2012-03-09 13:15:24 +01:00
|
|
|
item->setData(Type_Podcast, InternetModel::Role_Type);
|
2012-03-07 12:22:43 +01:00
|
|
|
item->setData(QVariant::fromValue(podcast), Role_Podcast);
|
2014-02-07 16:34:20 +01:00
|
|
|
item->setFlags(Qt::ItemIsEnabled | Qt::ItemIsDragEnabled |
|
|
|
|
Qt::ItemIsSelectable);
|
2012-03-09 13:15:24 +01:00
|
|
|
UpdatePodcastText(item, unlistened_count);
|
2012-03-06 19:37:46 +01:00
|
|
|
|
2012-03-07 12:04:47 +01:00
|
|
|
// Load the podcast's image if it has one
|
2012-03-07 13:27:31 +01:00
|
|
|
if (podcast.ImageUrlSmall().isValid()) {
|
|
|
|
icon_loader_->LoadIcon(podcast.ImageUrlSmall().toString(), QString(), item);
|
2012-03-06 19:37:46 +01:00
|
|
|
}
|
2012-03-07 12:04:47 +01:00
|
|
|
|
2012-03-09 13:15:24 +01:00
|
|
|
podcasts_by_database_id_[podcast.database_id()] = item;
|
|
|
|
|
|
|
|
return item;
|
|
|
|
}
|
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
QStandardItem* PodcastService::CreatePodcastEpisodeItem(
|
|
|
|
const PodcastEpisode& episode) {
|
2012-03-09 13:15:24 +01:00
|
|
|
QStandardItem* item = new QStandardItem;
|
2013-12-29 15:25:30 +01:00
|
|
|
item->setText(episode.title().simplified());
|
2012-03-09 13:15:24 +01:00
|
|
|
item->setData(Type_Episode, InternetModel::Role_Type);
|
|
|
|
item->setData(QVariant::fromValue(episode), Role_Episode);
|
2014-02-07 16:34:20 +01:00
|
|
|
item->setData(InternetModel::PlayBehaviour_UseSongLoader,
|
|
|
|
InternetModel::Role_PlayBehaviour);
|
|
|
|
item->setFlags(Qt::ItemIsEnabled | Qt::ItemIsDragEnabled |
|
|
|
|
Qt::ItemIsSelectable);
|
2012-03-09 13:15:24 +01:00
|
|
|
|
2012-03-10 22:05:57 +01:00
|
|
|
UpdateEpisodeText(item);
|
|
|
|
|
|
|
|
episodes_by_database_id_[episode.database_id()] = item;
|
2012-03-09 13:15:24 +01:00
|
|
|
|
2012-03-07 12:04:47 +01:00
|
|
|
return item;
|
2012-03-05 19:15:45 +01:00
|
|
|
}
|
|
|
|
|
2012-03-11 15:44:43 +01:00
|
|
|
void PodcastService::ShowContextMenu(const QPoint& global_pos) {
|
2012-03-05 19:15:45 +01:00
|
|
|
if (!context_menu_) {
|
|
|
|
context_menu_ = new QMenu;
|
2014-02-07 16:34:20 +01:00
|
|
|
context_menu_->addAction(IconLoader::Load("list-add"), tr("Add podcast..."),
|
|
|
|
this, SLOT(AddPodcast()));
|
|
|
|
context_menu_->addAction(IconLoader::Load("view-refresh"),
|
|
|
|
tr("Update all podcasts"), app_->podcast_updater(),
|
|
|
|
SLOT(UpdateAllPodcastsNow()));
|
2014-01-25 10:28:46 +01:00
|
|
|
|
2012-03-12 17:21:05 +01:00
|
|
|
context_menu_->addSeparator();
|
|
|
|
context_menu_->addActions(GetPlaylistActions());
|
2012-03-09 21:02:12 +01:00
|
|
|
|
|
|
|
context_menu_->addSeparator();
|
2012-03-10 23:39:24 +01:00
|
|
|
update_selected_action_ = context_menu_->addAction(
|
2014-02-07 16:34:20 +01:00
|
|
|
IconLoader::Load("view-refresh"), tr("Update this podcast"), this,
|
|
|
|
SLOT(UpdateSelectedPodcast()));
|
|
|
|
download_selected_action_ =
|
|
|
|
context_menu_->addAction(IconLoader::Load("download"), "", this,
|
|
|
|
SLOT(DownloadSelectedEpisode()));
|
2012-03-11 16:36:35 +01:00
|
|
|
delete_downloaded_action_ = context_menu_->addAction(
|
2014-02-07 16:34:20 +01:00
|
|
|
IconLoader::Load("edit-delete"), tr("Delete downloaded data"), this,
|
|
|
|
SLOT(DeleteDownloadedData()));
|
2013-12-30 16:01:02 +01:00
|
|
|
copy_to_device_ = context_menu_->addAction(
|
2014-02-07 16:34:20 +01:00
|
|
|
IconLoader::Load("multimedia-player-ipod-mini-blue"),
|
|
|
|
tr("Copy to device..."), this, SLOT(CopyToDevice()));
|
2012-03-10 23:39:24 +01:00
|
|
|
remove_selected_action_ = context_menu_->addAction(
|
2014-02-07 16:34:20 +01:00
|
|
|
IconLoader::Load("list-remove"), tr("Unsubscribe"), this,
|
|
|
|
SLOT(RemoveSelectedPodcast()));
|
2012-03-11 16:36:35 +01:00
|
|
|
|
|
|
|
context_menu_->addSeparator();
|
2014-02-07 16:34:20 +01:00
|
|
|
set_new_action_ =
|
|
|
|
context_menu_->addAction(tr("Mark as new"), this, SLOT(SetNew()));
|
|
|
|
set_listened_action_ = context_menu_->addAction(tr("Mark as listened"),
|
|
|
|
this, SLOT(SetListened()));
|
2012-03-10 23:39:24 +01:00
|
|
|
|
|
|
|
context_menu_->addSeparator();
|
2014-02-07 16:34:20 +01:00
|
|
|
context_menu_->addAction(IconLoader::Load("configure"),
|
|
|
|
tr("Configure podcasts..."), this,
|
|
|
|
SLOT(ShowConfig()));
|
|
|
|
|
|
|
|
copy_to_device_->setDisabled(
|
|
|
|
app_->device_manager()->connected_devices_model()->rowCount() == 0);
|
|
|
|
connect(app_->device_manager()->connected_devices_model(),
|
|
|
|
SIGNAL(IsEmptyChanged(bool)), copy_to_device_,
|
|
|
|
SLOT(setDisabled(bool)));
|
2012-03-05 19:15:45 +01:00
|
|
|
}
|
|
|
|
|
2012-03-11 16:36:35 +01:00
|
|
|
selected_episodes_.clear();
|
|
|
|
selected_podcasts_.clear();
|
2013-04-15 14:31:20 +02:00
|
|
|
explicitly_selected_podcasts_.clear();
|
2012-03-11 16:36:35 +01:00
|
|
|
QSet<int> podcast_ids;
|
|
|
|
|
2014-01-28 16:04:17 +01:00
|
|
|
for (const QModelIndex& index : model()->selected_indexes()) {
|
2012-03-11 16:36:35 +01:00
|
|
|
switch (index.data(InternetModel::Role_Type).toInt()) {
|
2014-02-07 16:34:20 +01:00
|
|
|
case Type_Podcast: {
|
|
|
|
const int id = index.data(Role_Podcast).value<Podcast>().database_id();
|
|
|
|
if (!podcast_ids.contains(id)) {
|
|
|
|
selected_podcasts_.append(index);
|
|
|
|
explicitly_selected_podcasts_.append(index);
|
|
|
|
podcast_ids.insert(id);
|
|
|
|
}
|
|
|
|
break;
|
2012-03-11 16:36:35 +01:00
|
|
|
}
|
2012-03-09 13:15:24 +01:00
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
case Type_Episode: {
|
|
|
|
selected_episodes_.append(index);
|
2012-03-09 13:15:24 +01:00
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
// Add the parent podcast as well.
|
|
|
|
const QModelIndex parent = index.parent();
|
|
|
|
const int id = parent.data(Role_Podcast).value<Podcast>().database_id();
|
|
|
|
if (!podcast_ids.contains(id)) {
|
|
|
|
selected_podcasts_.append(parent);
|
|
|
|
podcast_ids.insert(id);
|
|
|
|
}
|
|
|
|
break;
|
2012-03-11 16:36:35 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-03-09 13:15:24 +01:00
|
|
|
|
2012-03-11 16:36:35 +01:00
|
|
|
const bool episodes = !selected_episodes_.isEmpty();
|
|
|
|
const bool podcasts = !selected_podcasts_.isEmpty();
|
|
|
|
|
|
|
|
update_selected_action_->setEnabled(podcasts);
|
|
|
|
remove_selected_action_->setEnabled(podcasts);
|
2013-04-15 14:31:20 +02:00
|
|
|
set_new_action_->setEnabled(episodes || podcasts);
|
|
|
|
set_listened_action_->setEnabled(episodes || podcasts);
|
2012-03-11 16:36:35 +01:00
|
|
|
|
|
|
|
if (selected_episodes_.count() == 1) {
|
2014-02-07 16:34:20 +01:00
|
|
|
const PodcastEpisode episode =
|
|
|
|
selected_episodes_[0].data(Role_Episode).value<PodcastEpisode>();
|
2012-03-11 16:36:35 +01:00
|
|
|
const bool downloaded = episode.downloaded();
|
|
|
|
const bool listened = episode.listened();
|
|
|
|
|
|
|
|
download_selected_action_->setEnabled(!downloaded);
|
|
|
|
delete_downloaded_action_->setEnabled(downloaded);
|
2013-04-15 14:31:20 +02:00
|
|
|
|
|
|
|
if (explicitly_selected_podcasts_.isEmpty()) {
|
|
|
|
set_new_action_->setEnabled(listened);
|
|
|
|
set_listened_action_->setEnabled(!listened);
|
|
|
|
}
|
2012-03-11 16:36:35 +01:00
|
|
|
} else {
|
|
|
|
download_selected_action_->setEnabled(episodes);
|
|
|
|
delete_downloaded_action_->setEnabled(episodes);
|
|
|
|
}
|
|
|
|
|
2014-01-07 23:17:59 +01:00
|
|
|
if (explicitly_selected_podcasts_.isEmpty() && selected_episodes_.isEmpty()) {
|
|
|
|
PodcastEpisodeList epis = backend_->GetNewDownloadedEpisodes();
|
|
|
|
set_listened_action_->setEnabled(!epis.isEmpty());
|
|
|
|
}
|
|
|
|
|
2012-03-11 16:36:35 +01:00
|
|
|
if (selected_episodes_.count() > 1) {
|
2014-02-07 16:34:20 +01:00
|
|
|
download_selected_action_->setText(
|
|
|
|
tr("Download %n episodes", "", selected_episodes_.count()));
|
2012-03-11 16:36:35 +01:00
|
|
|
} else {
|
|
|
|
download_selected_action_->setText(tr("Download this episode"));
|
2012-03-09 13:15:24 +01:00
|
|
|
}
|
2014-01-25 10:28:46 +01:00
|
|
|
|
2012-03-12 17:21:05 +01:00
|
|
|
GetAppendToPlaylistAction()->setEnabled(episodes || podcasts);
|
|
|
|
GetReplacePlaylistAction()->setEnabled(episodes || podcasts);
|
|
|
|
GetOpenInNewPlaylistAction()->setEnabled(episodes || podcasts);
|
2012-03-09 13:15:24 +01:00
|
|
|
|
2012-03-05 19:15:45 +01:00
|
|
|
context_menu_->popup(global_pos);
|
|
|
|
}
|
|
|
|
|
2012-03-09 13:15:24 +01:00
|
|
|
void PodcastService::UpdateSelectedPodcast() {
|
2014-01-28 16:04:17 +01:00
|
|
|
for (const QModelIndex& index : selected_podcasts_) {
|
2012-03-11 16:36:35 +01:00
|
|
|
app_->podcast_updater()->UpdatePodcastNow(
|
2014-02-07 16:34:20 +01:00
|
|
|
index.data(Role_Podcast).value<Podcast>());
|
2012-03-11 16:36:35 +01:00
|
|
|
}
|
2012-03-09 13:15:24 +01:00
|
|
|
}
|
|
|
|
|
2012-03-09 21:02:12 +01:00
|
|
|
void PodcastService::RemoveSelectedPodcast() {
|
2014-01-28 16:04:17 +01:00
|
|
|
for (const QModelIndex& index : selected_podcasts_) {
|
2012-03-11 16:36:35 +01:00
|
|
|
backend_->Unsubscribe(index.data(Role_Podcast).value<Podcast>());
|
|
|
|
}
|
2012-03-09 21:02:12 +01:00
|
|
|
}
|
|
|
|
|
2012-03-06 22:24:41 +01:00
|
|
|
void PodcastService::ReloadSettings() {
|
|
|
|
QSettings s;
|
|
|
|
s.beginGroup(LibraryView::kSettingsGroup);
|
|
|
|
|
|
|
|
use_pretty_covers_ = s.value("pretty_covers", true).toBool();
|
2014-02-10 13:51:03 +01:00
|
|
|
// TODO(notme): reload the podcast icons that are already loaded?
|
2012-03-06 22:24:41 +01:00
|
|
|
}
|
|
|
|
|
2012-03-11 18:57:15 +01:00
|
|
|
void PodcastService::EnsureAddPodcastDialogCreated() {
|
2014-03-03 17:45:31 +01:00
|
|
|
add_podcast_dialog_.reset(new AddPodcastDialog(app_));
|
2012-03-11 18:57:15 +01:00
|
|
|
}
|
2012-03-05 19:15:45 +01:00
|
|
|
|
2012-03-11 18:57:15 +01:00
|
|
|
void PodcastService::AddPodcast() {
|
|
|
|
EnsureAddPodcastDialogCreated();
|
2012-03-05 19:15:45 +01:00
|
|
|
add_podcast_dialog_->show();
|
|
|
|
}
|
2012-03-07 12:04:47 +01:00
|
|
|
|
2014-10-30 17:52:21 +01:00
|
|
|
void PodcastService::FileCopied(int database_id) {
|
2014-10-30 03:41:15 +01:00
|
|
|
SetListened(PodcastEpisodeList() << backend_->GetEpisodeById(database_id),
|
|
|
|
true);
|
|
|
|
}
|
|
|
|
|
2012-03-07 12:04:47 +01:00
|
|
|
void PodcastService::SubscriptionAdded(const Podcast& podcast) {
|
2012-03-12 15:11:24 +01:00
|
|
|
// Ensure the root item is lazy loaded already
|
|
|
|
LazyLoadRoot();
|
2014-01-25 10:28:46 +01:00
|
|
|
|
2012-03-12 15:11:24 +01:00
|
|
|
// 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);
|
2012-03-07 12:04:47 +01:00
|
|
|
}
|
|
|
|
|
2012-03-12 15:11:24 +01:00
|
|
|
emit ScrollToIndex(MapToMergedModel(item->index()));
|
2012-03-07 12:04:47 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void PodcastService::SubscriptionRemoved(const Podcast& podcast) {
|
2012-03-09 13:15:24 +01:00
|
|
|
QStandardItem* item = podcasts_by_database_id_.take(podcast.database_id());
|
|
|
|
if (item) {
|
2012-03-10 22:05:57 +01:00
|
|
|
// Remove any episode ID -> item mappings for the episodes in this podcast.
|
2014-01-25 10:28:46 +01:00
|
|
|
for (int i = 0; i < item->rowCount(); ++i) {
|
2012-03-10 22:05:57 +01:00
|
|
|
QStandardItem* episode_item = item->child(i);
|
2014-02-07 16:34:20 +01:00
|
|
|
const int episode_id = episode_item->data(Role_Episode)
|
|
|
|
.value<PodcastEpisode>()
|
|
|
|
.database_id();
|
2012-03-10 22:05:57 +01:00
|
|
|
|
|
|
|
episodes_by_database_id_.remove(episode_id);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Remove this episode's row
|
2012-03-09 19:57:54 +01:00
|
|
|
model_->removeRow(item->row());
|
2012-03-09 13:15:24 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-01-28 16:04:17 +01:00
|
|
|
void PodcastService::EpisodesAdded(const PodcastEpisodeList& episodes) {
|
2012-03-09 13:15:24 +01:00
|
|
|
QSet<int> seen_podcast_ids;
|
|
|
|
|
2014-01-28 16:04:17 +01:00
|
|
|
for (const PodcastEpisode& episode : episodes) {
|
2012-03-09 13:15:24 +01:00
|
|
|
const int database_id = episode.podcast_database_id();
|
|
|
|
QStandardItem* parent = podcasts_by_database_id_[database_id];
|
2014-02-07 16:34:20 +01:00
|
|
|
if (!parent) continue;
|
2012-03-09 13:15:24 +01:00
|
|
|
|
|
|
|
parent->appendRow(CreatePodcastEpisodeItem(episode));
|
|
|
|
|
|
|
|
if (!seen_podcast_ids.contains(database_id)) {
|
|
|
|
// Update the unlistened count text once for each podcast
|
|
|
|
int unlistened_count = 0;
|
2014-01-28 16:04:17 +01:00
|
|
|
for (const PodcastEpisode& episode : backend_->GetEpisodes(database_id)) {
|
2012-03-09 13:15:24 +01:00
|
|
|
if (!episode.listened()) {
|
2014-01-25 10:28:46 +01:00
|
|
|
unlistened_count++;
|
2012-03-09 13:15:24 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
UpdatePodcastText(parent, unlistened_count);
|
|
|
|
seen_podcast_ids.insert(database_id);
|
2012-03-07 12:22:43 +01:00
|
|
|
}
|
|
|
|
}
|
2012-03-07 12:04:47 +01:00
|
|
|
}
|
2012-03-10 16:32:36 +01:00
|
|
|
|
2014-01-28 16:04:17 +01:00
|
|
|
void PodcastService::EpisodesUpdated(const PodcastEpisodeList& episodes) {
|
2012-03-10 22:05:57 +01:00
|
|
|
QSet<int> seen_podcast_ids;
|
|
|
|
|
2014-01-28 16:04:17 +01:00
|
|
|
for (const PodcastEpisode& episode : episodes) {
|
2012-03-10 22:05:57 +01:00
|
|
|
const int podcast_database_id = episode.podcast_database_id();
|
|
|
|
QStandardItem* item = episodes_by_database_id_[episode.database_id()];
|
|
|
|
QStandardItem* parent = podcasts_by_database_id_[podcast_database_id];
|
2014-02-07 16:34:20 +01:00
|
|
|
if (!item || !parent) continue;
|
2012-03-10 22:05:57 +01:00
|
|
|
|
|
|
|
// Update the episode data on the item, and update the item's text.
|
|
|
|
item->setData(QVariant::fromValue(episode), Role_Episode);
|
|
|
|
UpdateEpisodeText(item);
|
|
|
|
|
|
|
|
// Update the parent podcast's text too.
|
|
|
|
if (!seen_podcast_ids.contains(podcast_database_id)) {
|
|
|
|
// Update the unlistened count text once for each podcast
|
|
|
|
int unlistened_count = 0;
|
2014-02-07 16:34:20 +01:00
|
|
|
for (const PodcastEpisode& episode :
|
|
|
|
backend_->GetEpisodes(podcast_database_id)) {
|
2012-03-10 22:05:57 +01:00
|
|
|
if (!episode.listened()) {
|
2014-01-25 10:28:46 +01:00
|
|
|
unlistened_count++;
|
2012-03-10 22:05:57 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
UpdatePodcastText(parent, unlistened_count);
|
|
|
|
seen_podcast_ids.insert(podcast_database_id);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-03-10 16:32:36 +01:00
|
|
|
void PodcastService::DownloadSelectedEpisode() {
|
2014-01-28 16:04:17 +01:00
|
|
|
for (const QModelIndex& index : selected_episodes_) {
|
2012-03-11 16:36:35 +01:00
|
|
|
app_->podcast_downloader()->DownloadEpisode(
|
2014-02-07 16:34:20 +01:00
|
|
|
index.data(Role_Episode).value<PodcastEpisode>());
|
2012-03-11 16:36:35 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void PodcastService::DeleteDownloadedData() {
|
2014-01-28 16:04:17 +01:00
|
|
|
for (const QModelIndex& index : selected_episodes_) {
|
2012-03-11 16:36:35 +01:00
|
|
|
app_->podcast_downloader()->DeleteEpisode(
|
2014-02-07 16:34:20 +01:00
|
|
|
index.data(Role_Episode).value<PodcastEpisode>());
|
2012-03-11 16:36:35 +01:00
|
|
|
}
|
2012-03-10 16:32:36 +01:00
|
|
|
}
|
2012-03-10 22:05:57 +01:00
|
|
|
|
|
|
|
void PodcastService::DownloadProgressChanged(const PodcastEpisode& episode,
|
|
|
|
PodcastDownloader::State state,
|
|
|
|
int percent) {
|
|
|
|
QStandardItem* item = episodes_by_database_id_[episode.database_id()];
|
2014-02-07 16:34:20 +01:00
|
|
|
if (!item) return;
|
2012-03-10 22:05:57 +01:00
|
|
|
|
|
|
|
UpdateEpisodeText(item, state, percent);
|
|
|
|
}
|
2012-03-10 23:39:24 +01:00
|
|
|
|
|
|
|
void PodcastService::ShowConfig() {
|
2012-12-05 10:36:22 +01:00
|
|
|
app_->OpenSettingsDialogAtPage(SettingsDialog::Page_Podcasts);
|
2012-03-10 23:39:24 +01:00
|
|
|
}
|
2012-03-11 13:27:48 +01:00
|
|
|
|
|
|
|
void PodcastService::CurrentSongChanged(const Song& metadata) {
|
|
|
|
// Check whether this song is one of our podcast episodes.
|
|
|
|
PodcastEpisode episode = backend_->GetEpisodeByUrlOrLocalUrl(metadata.url());
|
2014-02-07 16:34:20 +01:00
|
|
|
if (!episode.is_valid()) return;
|
2012-03-11 13:27:48 +01:00
|
|
|
|
|
|
|
// Mark it as listened if it's not already
|
|
|
|
if (!episode.listened()) {
|
|
|
|
episode.set_listened(true);
|
2012-03-12 20:35:47 +01:00
|
|
|
episode.set_listened_date(QDateTime::currentDateTime());
|
2012-03-11 13:27:48 +01:00
|
|
|
backend_->UpdateEpisodes(PodcastEpisodeList() << episode);
|
|
|
|
}
|
|
|
|
}
|
2012-03-11 16:36:35 +01:00
|
|
|
|
|
|
|
void PodcastService::SetNew() {
|
2013-04-15 14:31:20 +02:00
|
|
|
SetListened(selected_episodes_, explicitly_selected_podcasts_, false);
|
2012-03-11 16:36:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void PodcastService::SetListened() {
|
2014-01-24 01:04:15 +01:00
|
|
|
if (selected_episodes_.isEmpty() && explicitly_selected_podcasts_.isEmpty())
|
2014-01-07 23:17:59 +01:00
|
|
|
SetListened(backend_->GetNewDownloadedEpisodes(), true);
|
|
|
|
else
|
|
|
|
SetListened(selected_episodes_, explicitly_selected_podcasts_, true);
|
|
|
|
}
|
|
|
|
|
2014-01-25 13:06:36 +01:00
|
|
|
void PodcastService::SetListened(const PodcastEpisodeList& episodes_list,
|
2014-01-25 10:28:46 +01:00
|
|
|
bool listened) {
|
2014-01-25 13:06:36 +01:00
|
|
|
PodcastEpisodeList episodes;
|
2014-01-07 23:17:59 +01:00
|
|
|
QDateTime current_date_time = QDateTime::currentDateTime();
|
2014-01-28 16:04:17 +01:00
|
|
|
for (PodcastEpisode episode : episodes_list) {
|
2014-01-25 13:06:36 +01:00
|
|
|
episode.set_listened(listened);
|
2014-01-07 23:17:59 +01:00
|
|
|
if (listened) {
|
2014-01-25 13:06:36 +01:00
|
|
|
episode.set_listened_date(current_date_time);
|
2014-01-07 23:17:59 +01:00
|
|
|
}
|
2014-01-25 13:06:36 +01:00
|
|
|
episodes << episode;
|
2014-01-07 23:17:59 +01:00
|
|
|
}
|
|
|
|
|
2014-01-25 13:06:36 +01:00
|
|
|
backend_->UpdateEpisodes(episodes);
|
2012-03-11 16:36:35 +01:00
|
|
|
}
|
|
|
|
|
2013-04-15 14:31:20 +02:00
|
|
|
void PodcastService::SetListened(const QModelIndexList& episode_indexes,
|
|
|
|
const QModelIndexList& podcast_indexes,
|
|
|
|
bool listened) {
|
2012-03-11 16:36:35 +01:00
|
|
|
PodcastEpisodeList episodes;
|
|
|
|
|
2013-04-15 14:31:20 +02:00
|
|
|
// Get all the episodes from the indexes.
|
2014-01-28 16:04:17 +01:00
|
|
|
for (const QModelIndex& index : episode_indexes) {
|
2013-04-15 14:31:20 +02:00
|
|
|
episodes << index.data(Role_Episode).value<PodcastEpisode>();
|
|
|
|
}
|
2012-03-12 20:35:47 +01:00
|
|
|
|
2014-01-25 10:28:46 +01:00
|
|
|
for (const QModelIndex& podcast : podcast_indexes) {
|
|
|
|
for (int i = 0; i < podcast.model()->rowCount(podcast); ++i) {
|
2013-04-15 14:31:20 +02:00
|
|
|
const QModelIndex& index = podcast.child(i, 0);
|
|
|
|
episodes << index.data(Role_Episode).value<PodcastEpisode>();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Update each one with the new state and maybe the listened time.
|
|
|
|
QDateTime current_date_time = QDateTime::currentDateTime();
|
2014-01-25 10:28:46 +01:00
|
|
|
for (int i = 0; i < episodes.count(); ++i) {
|
2013-04-15 14:31:20 +02:00
|
|
|
PodcastEpisode* episode = &episodes[i];
|
|
|
|
episode->set_listened(listened);
|
2012-03-12 20:35:47 +01:00
|
|
|
if (listened) {
|
2013-04-15 14:31:20 +02:00
|
|
|
episode->set_listened_date(current_date_time);
|
2012-03-12 20:35:47 +01:00
|
|
|
}
|
2012-03-11 16:36:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
backend_->UpdateEpisodes(episodes);
|
|
|
|
}
|
2012-03-11 18:57:15 +01:00
|
|
|
|
|
|
|
QModelIndex PodcastService::MapToMergedModel(const QModelIndex& index) const {
|
|
|
|
return model()->merged_model()->mapFromSource(proxy_->mapFromSource(index));
|
|
|
|
}
|
|
|
|
|
2012-03-12 15:11:24 +01:00
|
|
|
void PodcastService::LazyLoadRoot() {
|
|
|
|
if (root_->data(InternetModel::Role_CanLazyLoad).toBool()) {
|
|
|
|
root_->setData(false, InternetModel::Role_CanLazyLoad);
|
|
|
|
LazyPopulate(root_);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-03-11 18:57:15 +01:00
|
|
|
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
|
2012-03-12 15:11:24 +01:00
|
|
|
LazyLoadRoot();
|
2012-03-11 18:57:15 +01:00
|
|
|
|
|
|
|
QStandardItem* item = podcasts_by_database_id_[podcast.database_id()];
|
|
|
|
if (item) {
|
2012-03-12 15:11:24 +01:00
|
|
|
// There will be an item already if this podcast was already there,
|
|
|
|
// otherwise it'll be scrolled to when the item is created.
|
2012-03-11 18:57:15 +01:00
|
|
|
emit ScrollToIndex(MapToMergedModel(item->index()));
|
|
|
|
}
|
|
|
|
} else if (podcast_or_opml.canConvert<OpmlContainer>()) {
|
|
|
|
EnsureAddPodcastDialogCreated();
|
|
|
|
|
|
|
|
add_podcast_dialog_->ShowWithOpml(podcast_or_opml.value<OpmlContainer>());
|
|
|
|
}
|
|
|
|
}
|