mirror of
https://github.com/clementine-player/Clementine
synced 2024-12-19 21:04:08 +01:00
Mark podcast episodes as listened when they're listened to
This commit is contained in:
parent
19a971c7cd
commit
8cc971fa93
@ -37,4 +37,8 @@ CREATE INDEX podcast_idx_url ON podcasts(url);
|
|||||||
|
|
||||||
CREATE INDEX podcast_episodes_idx_podcast_id ON podcast_episodes(podcast_id);
|
CREATE INDEX podcast_episodes_idx_podcast_id ON podcast_episodes(podcast_id);
|
||||||
|
|
||||||
|
CREATE INDEX podcast_episodes_idx_url ON podcast_episodes(url);
|
||||||
|
|
||||||
|
CREATE INDEX podcast_episodes_idx_local_url ON podcast_episodes(local_url);
|
||||||
|
|
||||||
UPDATE schema_version SET version=37;
|
UPDATE schema_version SET version=37;
|
||||||
|
@ -143,7 +143,7 @@ void PodcastBackend::UpdateEpisodes(const PodcastEpisodeList& episodes) {
|
|||||||
foreach (const PodcastEpisode& episode, episodes) {
|
foreach (const PodcastEpisode& episode, episodes) {
|
||||||
q.bindValue(":listened", episode.listened());
|
q.bindValue(":listened", episode.listened());
|
||||||
q.bindValue(":downloaded", episode.downloaded());
|
q.bindValue(":downloaded", episode.downloaded());
|
||||||
q.bindValue(":local_url", episode.local_url());
|
q.bindValue(":local_url", episode.local_url().toEncoded());
|
||||||
q.bindValue(":id", episode.database_id());
|
q.bindValue(":id", episode.database_id());
|
||||||
q.exec();
|
q.exec();
|
||||||
db_->CheckErrors(q);
|
db_->CheckErrors(q);
|
||||||
@ -260,7 +260,26 @@ PodcastEpisode PodcastBackend::GetEpisodeByUrl(const QUrl& url) {
|
|||||||
QSqlQuery q("SELECT ROWID, " + PodcastEpisode::kColumnSpec +
|
QSqlQuery q("SELECT ROWID, " + PodcastEpisode::kColumnSpec +
|
||||||
" FROM podcast_episodes"
|
" FROM podcast_episodes"
|
||||||
" WHERE url = :url", db);
|
" WHERE url = :url", db);
|
||||||
q.bindValue(":url", url);
|
q.bindValue(":url", url.toEncoded());
|
||||||
|
q.exec();
|
||||||
|
if (!db_->CheckErrors(q) && q.next()) {
|
||||||
|
ret.InitFromQuery(q);
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
PodcastEpisode PodcastBackend::GetEpisodeByUrlOrLocalUrl(const QUrl& url) {
|
||||||
|
PodcastEpisode ret;
|
||||||
|
|
||||||
|
QMutexLocker l(db_->Mutex());
|
||||||
|
QSqlDatabase db(db_->Connect());
|
||||||
|
|
||||||
|
QSqlQuery q("SELECT ROWID, " + PodcastEpisode::kColumnSpec +
|
||||||
|
" FROM podcast_episodes"
|
||||||
|
" WHERE url = :url"
|
||||||
|
" OR local_url = :url", db);
|
||||||
|
q.bindValue(":url", url.toEncoded());
|
||||||
q.exec();
|
q.exec();
|
||||||
if (!db_->CheckErrors(q) && q.next()) {
|
if (!db_->CheckErrors(q) && q.next()) {
|
||||||
ret.InitFromQuery(q);
|
ret.InitFromQuery(q);
|
||||||
|
@ -52,6 +52,7 @@ public:
|
|||||||
PodcastEpisodeList GetEpisodes(int podcast_id);
|
PodcastEpisodeList GetEpisodes(int podcast_id);
|
||||||
PodcastEpisode GetEpisodeById(int id);
|
PodcastEpisode GetEpisodeById(int id);
|
||||||
PodcastEpisode GetEpisodeByUrl(const QUrl& url);
|
PodcastEpisode GetEpisodeByUrl(const QUrl& url);
|
||||||
|
PodcastEpisode GetEpisodeByUrlOrLocalUrl(const QUrl& url);
|
||||||
|
|
||||||
// Adds episodes to the database. Every episode must have a valid
|
// Adds episodes to the database. Every episode must have a valid
|
||||||
// podcast_database_id set already.
|
// podcast_database_id set already.
|
||||||
|
@ -44,6 +44,8 @@ public:
|
|||||||
|
|
||||||
Song ToSong(const Podcast& podcast) const;
|
Song ToSong(const Podcast& podcast) const;
|
||||||
|
|
||||||
|
bool is_valid() const { return database_id() != -1; }
|
||||||
|
|
||||||
int database_id() const;
|
int database_id() const;
|
||||||
int podcast_database_id() const;
|
int podcast_database_id() const;
|
||||||
const QString& title() const;
|
const QString& title() const;
|
||||||
|
@ -64,6 +64,8 @@ PodcastService::PodcastService(Application* app, InternetModel* parent)
|
|||||||
connect(backend_, SIGNAL(SubscriptionRemoved(Podcast)), SLOT(SubscriptionRemoved(Podcast)));
|
connect(backend_, SIGNAL(SubscriptionRemoved(Podcast)), SLOT(SubscriptionRemoved(Podcast)));
|
||||||
connect(backend_, SIGNAL(EpisodesAdded(QList<PodcastEpisode>)), SLOT(EpisodesAdded(QList<PodcastEpisode>)));
|
connect(backend_, SIGNAL(EpisodesAdded(QList<PodcastEpisode>)), SLOT(EpisodesAdded(QList<PodcastEpisode>)));
|
||||||
connect(backend_, SIGNAL(EpisodesUpdated(QList<PodcastEpisode>)), SLOT(EpisodesUpdated(QList<PodcastEpisode>)));
|
connect(backend_, SIGNAL(EpisodesUpdated(QList<PodcastEpisode>)), SLOT(EpisodesUpdated(QList<PodcastEpisode>)));
|
||||||
|
|
||||||
|
connect(app_->playlist_manager(), SIGNAL(CurrentSongChanged(Song)), SLOT(CurrentSongChanged(Song)));
|
||||||
}
|
}
|
||||||
|
|
||||||
PodcastService::~PodcastService() {
|
PodcastService::~PodcastService() {
|
||||||
@ -434,3 +436,16 @@ void PodcastService::DownloadProgressChanged(const PodcastEpisode& episode,
|
|||||||
void PodcastService::ShowConfig() {
|
void PodcastService::ShowConfig() {
|
||||||
app_->OpenSettingsDialogAtPage(SettingsDialog::Page_Podcasts);
|
app_->OpenSettingsDialogAtPage(SettingsDialog::Page_Podcasts);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void PodcastService::CurrentSongChanged(const Song& metadata) {
|
||||||
|
// Check whether this song is one of our podcast episodes.
|
||||||
|
PodcastEpisode episode = backend_->GetEpisodeByUrlOrLocalUrl(metadata.url());
|
||||||
|
if (!episode.is_valid())
|
||||||
|
return;
|
||||||
|
|
||||||
|
// Mark it as listened if it's not already
|
||||||
|
if (!episode.listened()) {
|
||||||
|
episode.set_listened(true);
|
||||||
|
backend_->UpdateEpisodes(PodcastEpisodeList() << episode);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -78,6 +78,8 @@ private slots:
|
|||||||
PodcastDownloader::State state,
|
PodcastDownloader::State state,
|
||||||
int percent);
|
int percent);
|
||||||
|
|
||||||
|
void CurrentSongChanged(const Song& metadata);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void PopulatePodcastList(QStandardItem* parent);
|
void PopulatePodcastList(QStandardItem* parent);
|
||||||
void UpdatePodcastText(QStandardItem* item, int unlistened_count) const;
|
void UpdatePodcastText(QStandardItem* item, int unlistened_count) const;
|
||||||
|
Loading…
Reference in New Issue
Block a user