1
0
mirror of https://github.com/clementine-player/Clementine synced 2025-01-31 11:35:24 +01:00

[internet/podcasts]Fix modification date&time support

After setting QDateTime to invalid state, it's saved into database as uint,
with then is read from database as a valid date. To make behaviour consistent, this change is needed.
If date is 4294967295, then it's an invalid one.
This commit is contained in:
Krzysztof Sobiecki 2014-12-29 14:45:30 +01:00
parent 2613341761
commit 8cf127a19c
2 changed files with 13 additions and 3 deletions

View File

@ -146,7 +146,17 @@ void PodcastEpisode::InitFromQuery(const QSqlQuery& query) {
d->duration_secs_ = query.value(6).toInt();
d->url_ = QUrl::fromEncoded(query.value(7).toByteArray());
d->listened_ = query.value(8).toBool();
d->listened_date_ = QDateTime::fromTime_t(query.value(9).toUInt());
// After setting QDateTime to invalid state, it's saved into database as time_t,
// when this number std::numeric_limits<unsigned int>::max() (4294967295) is read back
// from database, it creates a valid QDateTime.
// So to make it behave consistently, this change is needed.
if (query.value(9).toUInt() == std::numeric_limits<unsigned int>::max()) {
d->listened_date_ = QDateTime();
} else {
d->listened_date_ = QDateTime::fromTime_t(query.value(9).toUInt());
}
d->downloaded_ = query.value(10).toBool();
d->local_url_ = QUrl::fromEncoded(query.value(11).toByteArray());

View File

@ -512,7 +512,7 @@ void PodcastService::ShowContextMenu(const QPoint& global_pos) {
if (explicitly_selected_podcasts_.isEmpty()) {
set_new_action_->setEnabled(listened);
set_listened_action_->setEnabled(!listened);
set_listened_action_->setEnabled(!listened || !episode.listened_date().isValid());
}
} else {
download_selected_action_->setEnabled(episodes);
@ -719,7 +719,7 @@ void PodcastService::UpdatePodcastListenedStateAsync(const Song& metadata) {
if (!episode.is_valid()) return;
// Mark it as listened if it's not already
if (!episode.listened()) {
if (!episode.listened() || !episode.listened_date().isValid()) {
episode.set_listened(true);
episode.set_listened_date(QDateTime::currentDateTime());
backend_->UpdateEpisodes(PodcastEpisodeList() << episode);