2012-03-05 19:15:45 +01:00
|
|
|
/* This file is part of Clementine.
|
2014-11-01 19:38:39 +01:00
|
|
|
Copyright 2012-2013, David Sansome <me@davidsansome.com>
|
2014-12-10 01:24:51 +01:00
|
|
|
Copyright 2013-2014, Krzysztof A. Sobiecki <sobkas@gmail.com>
|
2014-11-01 19:38:39 +01:00
|
|
|
Copyright 2014, John Maguire <john.maguire@gmail.com>
|
2014-12-10 01:24:51 +01:00
|
|
|
Copyright 2014, Simeon Bird <sbird@andrew.cmu.edu>
|
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/>.
|
|
|
|
*/
|
|
|
|
|
2014-02-07 20:34:34 +01:00
|
|
|
#ifndef PODCASTS_PODCASTSERVICE_H_
|
|
|
|
#define PODCASTS_PODCASTSERVICE_H_
|
2012-03-05 19:15:45 +01:00
|
|
|
|
2014-12-06 19:44:12 +01:00
|
|
|
#include "podcastdeleter.h"
|
2012-03-10 22:05:57 +01:00
|
|
|
#include "podcastdownloader.h"
|
2012-03-06 19:37:46 +01:00
|
|
|
#include "internet/internetmodel.h"
|
2012-03-05 19:15:45 +01:00
|
|
|
#include "internet/internetservice.h"
|
|
|
|
|
2014-01-28 16:04:17 +01:00
|
|
|
#include <memory>
|
2012-03-05 19:15:45 +01:00
|
|
|
#include <QScopedPointer>
|
|
|
|
|
|
|
|
class AddPodcastDialog;
|
2014-01-25 10:28:46 +01:00
|
|
|
class OrganiseDialog;
|
2012-03-07 12:04:47 +01:00
|
|
|
class Podcast;
|
2012-03-06 19:37:46 +01:00
|
|
|
class PodcastBackend;
|
2012-03-09 13:15:24 +01:00
|
|
|
class PodcastEpisode;
|
2012-03-06 22:24:41 +01:00
|
|
|
class StandardItemIconLoader;
|
2012-03-05 19:15:45 +01:00
|
|
|
|
2012-03-07 12:04:47 +01:00
|
|
|
class QSortFilterProxyModel;
|
|
|
|
|
2012-03-05 19:15:45 +01:00
|
|
|
class PodcastService : public InternetService {
|
|
|
|
Q_OBJECT
|
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
public:
|
2012-03-05 19:15:45 +01:00
|
|
|
PodcastService(Application* app, InternetModel* parent);
|
|
|
|
~PodcastService();
|
|
|
|
|
|
|
|
static const char* kServiceName;
|
|
|
|
static const char* kSettingsGroup;
|
|
|
|
|
2012-03-06 19:37:46 +01:00
|
|
|
enum Type {
|
|
|
|
Type_AddPodcast = InternetModel::TypeCount,
|
|
|
|
Type_Podcast,
|
|
|
|
Type_Episode
|
|
|
|
};
|
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
enum Role { Role_Podcast = InternetModel::RoleCount, Role_Episode };
|
|
|
|
|
2012-03-05 19:15:45 +01:00
|
|
|
QStandardItem* CreateRootItem();
|
|
|
|
void LazyPopulate(QStandardItem* parent);
|
2014-12-14 14:35:21 +01:00
|
|
|
bool has_initial_load_settings() const { return true; }
|
2012-03-11 15:44:43 +01:00
|
|
|
void ShowContextMenu(const QPoint& global_pos);
|
2012-03-06 22:24:41 +01:00
|
|
|
void ReloadSettings();
|
2014-12-14 14:35:21 +01:00
|
|
|
void InitialLoadSettings();
|
2012-03-11 18:57:15 +01:00
|
|
|
// Called by SongLoader when the user adds a Podcast URL directly. Adds a
|
|
|
|
// 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);
|
2014-02-07 16:34:20 +01:00
|
|
|
|
|
|
|
public slots:
|
2012-03-12 15:11:24 +01:00
|
|
|
void AddPodcast();
|
2014-10-30 03:41:15 +01:00
|
|
|
void FileCopied(int database_id);
|
2012-03-11 18:57:15 +01:00
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
private slots:
|
2012-03-09 13:15:24 +01:00
|
|
|
void UpdateSelectedPodcast();
|
2014-12-11 01:25:56 +01:00
|
|
|
void ReloadPodcast(const Podcast& podcast);
|
2012-03-09 21:02:12 +01:00
|
|
|
void RemoveSelectedPodcast();
|
2012-03-10 16:32:36 +01:00
|
|
|
void DownloadSelectedEpisode();
|
2012-03-11 16:36:35 +01:00
|
|
|
void DeleteDownloadedData();
|
|
|
|
void SetNew();
|
|
|
|
void SetListened();
|
2012-03-10 23:39:24 +01:00
|
|
|
void ShowConfig();
|
2012-03-10 16:32:36 +01:00
|
|
|
|
2012-03-07 12:04:47 +01:00
|
|
|
void SubscriptionAdded(const Podcast& podcast);
|
|
|
|
void SubscriptionRemoved(const Podcast& podcast);
|
2014-01-28 16:04:17 +01:00
|
|
|
void EpisodesAdded(const PodcastEpisodeList& episodes);
|
|
|
|
void EpisodesUpdated(const PodcastEpisodeList& episodes);
|
2012-03-10 22:05:57 +01:00
|
|
|
|
|
|
|
void DownloadProgressChanged(const PodcastEpisode& episode,
|
2014-12-06 19:44:12 +01:00
|
|
|
PodcastDownload::State state, int percent);
|
2012-03-05 19:15:45 +01:00
|
|
|
|
2012-03-11 13:27:48 +01:00
|
|
|
void CurrentSongChanged(const Song& metadata);
|
2014-01-02 07:52:03 +01:00
|
|
|
|
2014-01-27 13:46:43 +01:00
|
|
|
void CopyToDevice();
|
|
|
|
void CopyToDevice(const PodcastEpisodeList& episodes_list);
|
|
|
|
void CopyToDevice(const QModelIndexList& episode_indexes,
|
2014-02-07 16:34:20 +01:00
|
|
|
const QModelIndexList& podcast_indexes);
|
2014-12-12 15:38:34 +01:00
|
|
|
void CancelDownload();
|
|
|
|
void CancelDownload(const QModelIndexList& episode_indexes,
|
|
|
|
const QModelIndexList& podcast_indexes);
|
2012-03-11 13:27:48 +01:00
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
private:
|
2012-03-11 18:57:15 +01:00
|
|
|
void EnsureAddPodcastDialogCreated();
|
|
|
|
|
2014-12-08 02:51:29 +01:00
|
|
|
void UpdatePodcastListenedStateAsync(const Song& metadata);
|
2012-03-06 19:37:46 +01:00
|
|
|
void PopulatePodcastList(QStandardItem* parent);
|
2014-12-11 01:25:56 +01:00
|
|
|
void ClearPodcastList(QStandardItem* parent);
|
2012-03-09 13:15:24 +01:00
|
|
|
void UpdatePodcastText(QStandardItem* item, int unlistened_count) const;
|
2014-02-07 16:34:20 +01:00
|
|
|
void UpdateEpisodeText(
|
|
|
|
QStandardItem* item,
|
2014-12-06 19:44:12 +01:00
|
|
|
PodcastDownload::State state = PodcastDownload::NotDownloading,
|
|
|
|
int percent = 0);
|
|
|
|
void UpdatePodcastText(
|
|
|
|
QStandardItem* item,
|
|
|
|
PodcastDownload::State state = PodcastDownload::NotDownloading,
|
2014-02-07 16:34:20 +01:00
|
|
|
int percent = 0);
|
2012-03-09 13:15:24 +01:00
|
|
|
|
2012-03-07 12:04:47 +01:00
|
|
|
QStandardItem* CreatePodcastItem(const Podcast& podcast);
|
2012-03-09 13:15:24 +01:00
|
|
|
QStandardItem* CreatePodcastEpisodeItem(const PodcastEpisode& episode);
|
2012-03-06 19:37:46 +01:00
|
|
|
|
2012-03-11 18:57:15 +01:00
|
|
|
QModelIndex MapToMergedModel(const QModelIndex& index) const;
|
2012-03-11 16:36:35 +01:00
|
|
|
|
2013-04-15 14:31:20 +02:00
|
|
|
void SetListened(const QModelIndexList& episode_indexes,
|
2014-02-07 16:34:20 +01:00
|
|
|
const QModelIndexList& podcast_indexes, bool listened);
|
|
|
|
void SetListened(const PodcastEpisodeList& episodes_list, bool listened);
|
2014-01-07 23:17:59 +01:00
|
|
|
|
2012-03-12 15:11:24 +01:00
|
|
|
void LazyLoadRoot();
|
2012-03-11 16:36:35 +01:00
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
private:
|
2012-03-06 22:24:41 +01:00
|
|
|
bool use_pretty_covers_;
|
2014-12-11 01:25:56 +01:00
|
|
|
bool hide_listened_;
|
|
|
|
qint64 show_episodes_;
|
2012-03-06 22:24:41 +01:00
|
|
|
StandardItemIconLoader* icon_loader_;
|
|
|
|
|
2012-03-10 22:05:57 +01:00
|
|
|
// The podcast icon
|
|
|
|
QIcon default_icon_;
|
|
|
|
|
|
|
|
// Episodes get different icons depending on their state
|
|
|
|
QIcon queued_icon_;
|
|
|
|
QIcon downloading_icon_;
|
|
|
|
QIcon downloaded_icon_;
|
|
|
|
|
2012-03-07 12:04:47 +01:00
|
|
|
PodcastBackend* backend_;
|
|
|
|
QStandardItemModel* model_;
|
|
|
|
QSortFilterProxyModel* proxy_;
|
|
|
|
|
2012-03-05 19:15:45 +01:00
|
|
|
QMenu* context_menu_;
|
2012-03-09 13:15:24 +01:00
|
|
|
QAction* update_selected_action_;
|
2012-03-09 21:02:12 +01:00
|
|
|
QAction* remove_selected_action_;
|
2012-03-10 16:32:36 +01:00
|
|
|
QAction* download_selected_action_;
|
2012-03-11 16:36:35 +01:00
|
|
|
QAction* delete_downloaded_action_;
|
|
|
|
QAction* set_new_action_;
|
|
|
|
QAction* set_listened_action_;
|
2013-12-30 16:01:02 +01:00
|
|
|
QAction* copy_to_device_;
|
2014-12-12 15:38:34 +01:00
|
|
|
QAction* cancel_download_;
|
2012-03-05 19:15:45 +01:00
|
|
|
QStandardItem* root_;
|
2014-01-28 16:04:17 +01:00
|
|
|
std::unique_ptr<OrganiseDialog> organise_dialog_;
|
2012-03-05 19:15:45 +01:00
|
|
|
|
2013-04-15 14:31:20 +02:00
|
|
|
QModelIndexList explicitly_selected_podcasts_;
|
2012-03-11 16:36:35 +01:00
|
|
|
QModelIndexList selected_podcasts_;
|
|
|
|
QModelIndexList selected_episodes_;
|
2012-03-09 13:15:24 +01:00
|
|
|
|
|
|
|
QMap<int, QStandardItem*> podcasts_by_database_id_;
|
2012-03-10 22:05:57 +01:00
|
|
|
QMap<int, QStandardItem*> episodes_by_database_id_;
|
2012-03-09 13:15:24 +01:00
|
|
|
|
2014-03-03 17:45:31 +01:00
|
|
|
std::unique_ptr<AddPodcastDialog> add_podcast_dialog_;
|
2012-03-05 19:15:45 +01:00
|
|
|
};
|
|
|
|
|
2014-02-07 20:34:34 +01:00
|
|
|
#endif // PODCASTS_PODCASTSERVICE_H_
|