Fixed podcast copy to device

This commit is contained in:
Krzysztof A. Sobiecki 2014-01-01 18:23:52 +01:00
parent f60327b1d1
commit 01635397d4
4 changed files with 42 additions and 9 deletions

View File

@ -313,3 +313,26 @@ PodcastEpisodeList PodcastBackend::GetOldDownloadedEpisodes(const QDateTime& max
return ret; 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;
}

View File

@ -59,7 +59,7 @@ public:
// last listened to before the given QDateTime. This query is NOT indexed so // last listened to before the given QDateTime. This query is NOT indexed so
// it involves a full search of the table. // it involves a full search of the table.
PodcastEpisodeList GetOldDownloadedEpisodes(const QDateTime& max_listened_date); PodcastEpisodeList GetOldDownloadedEpisodes(const QDateTime& max_listened_date);
PodcastEpisodeList GetNewDownloadedEpisodes();
// 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.
void AddEpisodes(PodcastEpisodeList* episodes); void AddEpisodes(PodcastEpisodeList* episodes);

View File

@ -174,7 +174,9 @@ Song PodcastEpisode::ToSong(const Podcast& podcast) const {
if (podcast.is_valid()) { if (podcast.is_valid()) {
ret.set_album(podcast.title().simplified()); ret.set_album(podcast.title().simplified());
ret.set_art_automatic(podcast.ImageUrlLarge().toString()); ret.set_art_automatic(podcast.ImageUrlLarge().toString());
if (author().isNull() || author().isEmpty())
ret.set_artist(podcast.title().simplified());
} }
return ret; return ret;
} }

View File

@ -119,27 +119,35 @@ QStandardItem* PodcastService::CreateRootItem() {
} }
void PodcastService::CopyToDeviceSlot() { void PodcastService::CopyToDeviceSlot() {
QList<QUrl> url_list;
QList<PodcastEpisode> episodes; QList<PodcastEpisode> episodes;
QList<Song> songs;
PodcastEpisode episode_tmp;
Podcast podcast;
foreach (const QModelIndex& index, selected_episodes_) { foreach (const QModelIndex& index, selected_episodes_) {
episodes << index.data(Role_Episode).value<PodcastEpisode>(); episode_tmp = index.data(Role_Episode).value<PodcastEpisode>();
if (episode_tmp.downloaded())
episodes << episode_tmp;
} }
foreach (const QModelIndex& podcast, explicitly_selected_podcasts_) { foreach (const QModelIndex& podcast, explicitly_selected_podcasts_) {
for (int i=0 ; i<podcast.model()->rowCount(podcast) ; ++i) { for (int i=0 ; i<podcast.model()->rowCount(podcast) ; ++i) {
const QModelIndex& index = podcast.child(i, 0); const QModelIndex& index = podcast.child(i, 0);
episodes << index.data(Role_Episode).value<PodcastEpisode>(); episode_tmp = index.data(Role_Episode).value<PodcastEpisode>();
if (episode_tmp.downloaded())
episodes << episode_tmp;
} }
} }
if(selected_episodes_.isEmpty() && explicitly_selected_podcasts_.isEmpty()) {
episodes << backend_->GetNewDownloadedEpisodes();
}
foreach (const PodcastEpisode& episode, episodes) { foreach (const PodcastEpisode& episode, episodes) {
if(!episode.local_url().isEmpty()) podcast = backend_->GetSubscriptionById(episode.podcast_database_id());
url_list.append(episode.local_url()); songs.append(episode.ToSong(podcast));
} }
organise_dialog_->SetDestinationModel(app_->device_manager()->connected_devices_model(), true); organise_dialog_->SetDestinationModel(app_->device_manager()->connected_devices_model(), true);
organise_dialog_->SetCopy(true); organise_dialog_->SetCopy(true);
if (organise_dialog_->SetUrls(url_list)) if (organise_dialog_->SetSongs(songs))
organise_dialog_->show(); organise_dialog_->show();
} }