diff --git a/src/podcasts/podcastbackend.cpp b/src/podcasts/podcastbackend.cpp index f87eb8de3..49c1bb2c0 100644 --- a/src/podcasts/podcastbackend.cpp +++ b/src/podcasts/podcastbackend.cpp @@ -313,3 +313,26 @@ PodcastEpisodeList PodcastBackend::GetOldDownloadedEpisodes(const QDateTime& max return ret; } + +PodcastEpisodeList PodcastBackend::GetNewDownloadedEpisodes() { + PodcastEpisodeList ret; + + QMutexLocker l(db_->Mutex()); + QSqlDatabase db(db_->Connect()); + + QSqlQuery q("SELECT ROWID, " + PodcastEpisode::kColumnSpec + + " FROM podcast_episodes" + " WHERE downloaded = 'true'" + " AND listened = 'false'", db); + q.exec(); + if (db_->CheckErrors(q)) + return ret; + + while (q.next()) { + PodcastEpisode episode; + episode.InitFromQuery(q); + ret << episode; + } + + return ret; +} diff --git a/src/podcasts/podcastbackend.h b/src/podcasts/podcastbackend.h index f09f4742b..ff3e1fbef 100644 --- a/src/podcasts/podcastbackend.h +++ b/src/podcasts/podcastbackend.h @@ -59,7 +59,7 @@ public: // last listened to before the given QDateTime. This query is NOT indexed so // it involves a full search of the table. PodcastEpisodeList GetOldDownloadedEpisodes(const QDateTime& max_listened_date); - + PodcastEpisodeList GetNewDownloadedEpisodes(); // Adds episodes to the database. Every episode must have a valid // podcast_database_id set already. void AddEpisodes(PodcastEpisodeList* episodes); diff --git a/src/podcasts/podcastepisode.cpp b/src/podcasts/podcastepisode.cpp index a049ec1df..42eda0c90 100644 --- a/src/podcasts/podcastepisode.cpp +++ b/src/podcasts/podcastepisode.cpp @@ -174,7 +174,9 @@ Song PodcastEpisode::ToSong(const Podcast& podcast) const { if (podcast.is_valid()) { ret.set_album(podcast.title().simplified()); ret.set_art_automatic(podcast.ImageUrlLarge().toString()); + + if (author().isNull() || author().isEmpty()) + ret.set_artist(podcast.title().simplified()); } - return ret; } diff --git a/src/podcasts/podcastservice.cpp b/src/podcasts/podcastservice.cpp index 3975e2d98..55abda99a 100644 --- a/src/podcasts/podcastservice.cpp +++ b/src/podcasts/podcastservice.cpp @@ -119,27 +119,35 @@ QStandardItem* PodcastService::CreateRootItem() { } void PodcastService::CopyToDeviceSlot() { - QList url_list; QList episodes; - + QList songs; + PodcastEpisode episode_tmp; + Podcast podcast; foreach (const QModelIndex& index, selected_episodes_) { - episodes << index.data(Role_Episode).value(); + episode_tmp = index.data(Role_Episode).value(); + if (episode_tmp.downloaded()) + episodes << episode_tmp; } foreach (const QModelIndex& podcast, explicitly_selected_podcasts_) { for (int i=0 ; irowCount(podcast) ; ++i) { const QModelIndex& index = podcast.child(i, 0); - episodes << index.data(Role_Episode).value(); + episode_tmp = index.data(Role_Episode).value(); + if (episode_tmp.downloaded()) + episodes << episode_tmp; } } + if(selected_episodes_.isEmpty() && explicitly_selected_podcasts_.isEmpty()) { + episodes << backend_->GetNewDownloadedEpisodes(); + } foreach (const PodcastEpisode& episode, episodes) { - if(!episode.local_url().isEmpty()) - url_list.append(episode.local_url()); + podcast = backend_->GetSubscriptionById(episode.podcast_database_id()); + songs.append(episode.ToSong(podcast)); } organise_dialog_->SetDestinationModel(app_->device_manager()->connected_devices_model(), true); organise_dialog_->SetCopy(true); - if (organise_dialog_->SetUrls(url_list)) + if (organise_dialog_->SetSongs(songs)) organise_dialog_->show(); }