From f24b6a520cbfefe8966d5bf90297c6148cf07772 Mon Sep 17 00:00:00 2001 From: Jonas Kvinge Date: Sat, 18 Jul 2020 03:53:30 +0200 Subject: [PATCH] Replace QDateTime::toTime_t() with QDateTime::toSecsSinceEpoch() --- ext/libstrawberry-tagreader/tagreader.cpp | 6 +++--- src/collection/collectionwatcher.cpp | 18 +++++++++--------- src/collection/collectionwatcher.h | 2 +- src/core/mpris_common.h | 2 +- src/covermanager/spotifycoverprovider.cpp | 4 ++-- .../globalshortcutbackend-gsd.cpp | 2 +- src/playlist/playlistdelegates.cpp | 2 +- src/scrobbler/scrobblingapi20.cpp | 4 ++-- src/tidal/tidalservice.cpp | 6 +++--- 9 files changed, 23 insertions(+), 23 deletions(-) diff --git a/ext/libstrawberry-tagreader/tagreader.cpp b/ext/libstrawberry-tagreader/tagreader.cpp index 24855f4e4..01296aae8 100644 --- a/ext/libstrawberry-tagreader/tagreader.cpp +++ b/ext/libstrawberry-tagreader/tagreader.cpp @@ -177,11 +177,11 @@ void TagReader::ReadFile(const QString &filename, pb::tagreader::SongMetadata *s song->set_basefilename(DataCommaSizeFromQString(info.fileName())); song->set_url(url.constData(), url.size()); song->set_filesize(info.size()); - song->set_mtime(info.lastModified().toTime_t()); + song->set_mtime(info.lastModified().toSecsSinceEpoch()); #if (QT_VERSION >= QT_VERSION_CHECK(5, 10, 0)) - song->set_ctime(info.birthTime().isValid() ? info.birthTime().toTime_t() : info.lastModified().toTime_t()); + song->set_ctime(info.birthTime().isValid() ? info.birthTime().toSecsSinceEpoch() : info.lastModified().toSecsSinceEpoch()); #else - song->set_ctime(info.created().toTime_t()); + song->set_ctime(info.created().toSecsSinceEpoch()); #endif std::unique_ptr fileref(factory_->GetFileRef(filename)); diff --git a/src/collection/collectionwatcher.cpp b/src/collection/collectionwatcher.cpp index ee0098cfc..4bee75382 100644 --- a/src/collection/collectionwatcher.cpp +++ b/src/collection/collectionwatcher.cpp @@ -328,7 +328,7 @@ void CollectionWatcher::ScanSubdirectory(const QString &path, const Subdirectory return; } - if (!t->ignores_mtime() && !force_noincremental && t->is_incremental() && subdir.mtime == path_info.lastModified().toTime_t()) { + if (!t->ignores_mtime() && !force_noincremental && t->is_incremental() && subdir.mtime == path_info.lastModified().toSecsSinceEpoch()) { // The directory hasn't changed since last time t->AddToProgress(1); return; @@ -362,7 +362,7 @@ void CollectionWatcher::ScanSubdirectory(const QString &path, const Subdirectory Subdirectory new_subdir; new_subdir.directory_id = -1; new_subdir.path = child; - new_subdir.mtime = child_info.lastModified().toTime_t(); + new_subdir.mtime = child_info.lastModified().toSecsSinceEpoch(); my_new_subdirs << new_subdir; } } @@ -393,7 +393,7 @@ void CollectionWatcher::ScanSubdirectory(const QString &path, const Subdirectory Song matching_song(source_); if (FindSongByPath(songs_in_db, file, &matching_song)) { - uint matching_cue_mtime = GetMtimeForCue(matching_cue); + quint64 matching_cue_mtime = GetMtimeForCue(matching_cue); // The song is in the database and still on disk. // Check the mtime to see if it's been changed since it was added. @@ -407,13 +407,13 @@ void CollectionWatcher::ScanSubdirectory(const QString &path, const Subdirectory // cue sheet's path from collection (if any) QString song_cue = matching_song.cue_path(); - uint song_cue_mtime = GetMtimeForCue(song_cue); + qint64 song_cue_mtime = GetMtimeForCue(song_cue); bool cue_deleted = song_cue_mtime == 0 && matching_song.has_cue(); bool cue_added = matching_cue_mtime != 0 && !matching_song.has_cue(); // watch out for cue songs which have their mtime equal to qMax(media_file_mtime, cue_sheet_mtime) - bool changed = (matching_song.mtime() != qMax(file_info.lastModified().toTime_t(), song_cue_mtime)) || cue_deleted || cue_added; + bool changed = (matching_song.mtime() != static_cast(qMax(file_info.lastModified().toSecsSinceEpoch(), song_cue_mtime))) || cue_deleted || cue_added; // Also want to look to see whether the album art has changed QUrl image = ImageForSong(file, album_art); @@ -470,7 +470,7 @@ void CollectionWatcher::ScanSubdirectory(const QString &path, const Subdirectory // Add this subdir to the new or touched list Subdirectory updated_subdir; updated_subdir.directory_id = t->dir(); - updated_subdir.mtime = path_info.exists() ? path_info.lastModified().toTime_t() : 0; + updated_subdir.mtime = path_info.exists() ? path_info.lastModified().toSecsSinceEpoch() : 0; updated_subdir.path = path; if (subdir.directory_id == -1) @@ -560,7 +560,7 @@ SongList CollectionWatcher::ScanNewFile(const QString &file, const QString &path SongList song_list; - uint matching_cue_mtime = GetMtimeForCue(matching_cue); + quint64 matching_cue_mtime = GetMtimeForCue(matching_cue); // If it's a cue - create virtual tracks if (matching_cue_mtime) { // don't process the same cue many times @@ -629,7 +629,7 @@ void CollectionWatcher::PreserveUserSetData(const QString &file, const QUrl &ima } -uint CollectionWatcher::GetMtimeForCue(const QString &cue_path) { +quint64 CollectionWatcher::GetMtimeForCue(const QString &cue_path) { // Slight optimisation if (cue_path.isEmpty()) { @@ -643,7 +643,7 @@ uint CollectionWatcher::GetMtimeForCue(const QString &cue_path) { const QDateTime cue_last_modified = file_info.lastModified(); - return cue_last_modified.isValid() ? cue_last_modified.toTime_t() : 0; + return cue_last_modified.isValid() ? cue_last_modified.toSecsSinceEpoch() : 0; } void CollectionWatcher::AddWatch(const Directory &dir, const QString &path) { diff --git a/src/collection/collectionwatcher.h b/src/collection/collectionwatcher.h index 98df8aacd..a4de8519e 100644 --- a/src/collection/collectionwatcher.h +++ b/src/collection/collectionwatcher.h @@ -166,7 +166,7 @@ class CollectionWatcher : public QObject { QUrl ImageForSong(const QString &path, QMap &album_art); void AddWatch(const Directory &dir, const QString &path); void RemoveWatch(const Directory &dir, const Subdirectory &subdir); - uint GetMtimeForCue(const QString &cue_path); + quint64 GetMtimeForCue(const QString &cue_path); void PerformScan(bool incremental, bool ignore_mtimes); // Updates the sections of a cue associated and altered (according to mtime) media file during a scan. diff --git a/src/core/mpris_common.h b/src/core/mpris_common.h index 12d7b0756..68a7aa9d2 100644 --- a/src/core/mpris_common.h +++ b/src/core/mpris_common.h @@ -56,7 +56,7 @@ inline void AddMetadata(const QString &key, const QDateTime &metadata, QVariantM } inline QString AsMPRISDateTimeType(const int time) { - return time != -1 ? QDateTime::fromTime_t(time).toString(Qt::ISODate) : ""; + return time != -1 ? QDateTime::fromSecsSinceEpoch(time).toString(Qt::ISODate) : ""; } } // namespace mpris diff --git a/src/covermanager/spotifycoverprovider.cpp b/src/covermanager/spotifycoverprovider.cpp index 26d82035f..e3bb924c9 100644 --- a/src/covermanager/spotifycoverprovider.cpp +++ b/src/covermanager/spotifycoverprovider.cpp @@ -77,7 +77,7 @@ SpotifyCoverProvider::SpotifyCoverProvider(Application *app, QObject *parent) : s.endGroup(); if (!refresh_token_.isEmpty()) { - qint64 time = expires_in_ - (QDateTime::currentDateTime().toTime_t() - login_time_); + qint64 time = expires_in_ - (QDateTime::currentDateTime().toSecsSinceEpoch() - login_time_); if (time < 6) time = 6; refresh_login_timer_.setInterval(time * kMsecPerSec); refresh_login_timer_.start(); @@ -330,7 +330,7 @@ void SpotifyCoverProvider::AccessTokenRequestFinished(QNetworkReply *reply) { refresh_token_ = json_obj["refresh_token"].toString(); } expires_in_ = json_obj["expires_in"].toInt(); - login_time_ = QDateTime::currentDateTime().toTime_t(); + login_time_ = QDateTime::currentDateTime().toSecsSinceEpoch(); QSettings s; s.beginGroup(kSettingsGroup); diff --git a/src/globalshortcuts/globalshortcutbackend-gsd.cpp b/src/globalshortcuts/globalshortcutbackend-gsd.cpp index c73f77472..5b15717e3 100644 --- a/src/globalshortcuts/globalshortcutbackend-gsd.cpp +++ b/src/globalshortcuts/globalshortcutbackend-gsd.cpp @@ -66,7 +66,7 @@ bool GlobalShortcutBackendGSD::DoRegister() { return false; } - QDBusPendingReply<> reply = interface_->GrabMediaPlayerKeys(QCoreApplication::applicationName(), QDateTime::currentDateTime().toTime_t()); + QDBusPendingReply<> reply = interface_->GrabMediaPlayerKeys(QCoreApplication::applicationName(), QDateTime::currentDateTime().toSecsSinceEpoch()); QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(reply, this); NewClosure(watcher, SIGNAL(finished(QDBusPendingCallWatcher*)), this, SLOT(RegisterFinished(QDBusPendingCallWatcher*)), watcher); diff --git a/src/playlist/playlistdelegates.cpp b/src/playlist/playlistdelegates.cpp index 7a0c12f57..21e4910ae 100644 --- a/src/playlist/playlistdelegates.cpp +++ b/src/playlist/playlistdelegates.cpp @@ -328,7 +328,7 @@ QString DateItemDelegate::displayText(const QVariant &value, const QLocale &loca if (!ok || time == -1) return QString(); - return QDateTime::fromTime_t(time).toString(QLocale::system().dateTimeFormat(QLocale::ShortFormat)); + return QDateTime::fromSecsSinceEpoch(time).toString(QLocale::system().dateTimeFormat(QLocale::ShortFormat)); } diff --git a/src/scrobbler/scrobblingapi20.cpp b/src/scrobbler/scrobblingapi20.cpp index 37f4de07f..fd8aad05c 100644 --- a/src/scrobbler/scrobblingapi20.cpp +++ b/src/scrobbler/scrobblingapi20.cpp @@ -447,7 +447,7 @@ void ScrobblingAPI20::UpdateNowPlaying(const Song &song) { CheckScrobblePrevSong(); song_playing_ = song; - timestamp_ = QDateTime::currentDateTime().toTime_t(); + timestamp_ = QDateTime::currentDateTime().toSecsSinceEpoch(); scrobbled_ = false; if (!IsAuthenticated() || !song.is_metadata_good() || app_->scrobbler()->IsOffline()) return; @@ -1030,7 +1030,7 @@ QString ScrobblingAPI20::ErrorString(const ScrobbleErrorCode error) const { void ScrobblingAPI20::CheckScrobblePrevSong() { - quint64 duration = QDateTime::currentDateTime().toTime_t() - timestamp_; + quint64 duration = QDateTime::currentDateTime().toSecsSinceEpoch() - timestamp_; if (!scrobbled_ && song_playing_.is_metadata_good() && song_playing_.source() == Song::Source_Stream && duration > 30) { Song song(song_playing_); diff --git a/src/tidal/tidalservice.cpp b/src/tidal/tidalservice.cpp index 283a83a32..0da43d7c7 100644 --- a/src/tidal/tidalservice.cpp +++ b/src/tidal/tidalservice.cpp @@ -250,7 +250,7 @@ void TidalService::LoadSession() { s.endGroup(); if (!refresh_token_.isEmpty()) { - qint64 time = expires_in_ - (QDateTime::currentDateTime().toTime_t() - login_time_); + qint64 time = expires_in_ - (QDateTime::currentDateTime().toSecsSinceEpoch() - login_time_); if (time < 6) time = 6; timer_refresh_login_->setInterval(time * kMsecPerSec); timer_refresh_login_->start(); @@ -330,7 +330,7 @@ void TidalService::AuthorizationUrlReceived(const QUrl &url) { refresh_token_ = url_query.queryItemValue("refresh_token").toUtf8(); } expires_in_ = url_query.queryItemValue("expires_in").toInt(); - login_time_ = QDateTime::currentDateTime().toTime_t(); + login_time_ = QDateTime::currentDateTime().toSecsSinceEpoch(); session_id_.clear(); QSettings s; @@ -483,7 +483,7 @@ void TidalService::AccessTokenRequestFinished(QNetworkReply *reply) { if (json_obj.contains("refresh_token")) { refresh_token_ = json_obj["refresh_token"].toString(); } - login_time_ = QDateTime::currentDateTime().toTime_t(); + login_time_ = QDateTime::currentDateTime().toSecsSinceEpoch(); if (json_obj.contains("user") && json_obj["user"].isObject()) { QJsonObject obj_user = json_obj["user"].toObject();