From dde8661e935b05b3d790e561813437ba46a36ed5 Mon Sep 17 00:00:00 2001 From: Jonas Kvinge Date: Sat, 24 Aug 2024 17:28:29 +0200 Subject: [PATCH] Use QDateTime::currentSecsSinceEpoch() --- src/collection/collectionquery.cpp | 2 +- src/covermanager/opentidalcoverprovider.cpp | 10 +++++----- src/globalshortcuts/globalshortcutsbackend-gnome.cpp | 2 +- src/globalshortcuts/globalshortcutsbackend-mate.cpp | 2 +- src/qobuz/qobuzstreamurlrequest.cpp | 2 +- src/scrobbler/listenbrainzscrobbler.cpp | 8 ++++---- src/scrobbler/scrobblingapi20.cpp | 4 ++-- src/spotify/spotifyservice.cpp | 4 ++-- src/tidal/tidalservice.cpp | 6 +++--- 9 files changed, 20 insertions(+), 20 deletions(-) diff --git a/src/collection/collectionquery.cpp b/src/collection/collectionquery.cpp index ef59d2843..1eb81acb0 100644 --- a/src/collection/collectionquery.cpp +++ b/src/collection/collectionquery.cpp @@ -46,7 +46,7 @@ CollectionQuery::CollectionQuery(const QSqlDatabase &db, const QString &songs_ta limit_(-1) { if (filter_options.max_age() != -1) { - qint64 cutoff = QDateTime::currentDateTime().toSecsSinceEpoch() - filter_options.max_age(); + qint64 cutoff = QDateTime::currentSecsSinceEpoch() - filter_options.max_age(); where_clauses_ << QStringLiteral("ctime > ?"); bound_values_ << cutoff; diff --git a/src/covermanager/opentidalcoverprovider.cpp b/src/covermanager/opentidalcoverprovider.cpp index 6025eaebb..881774ec6 100644 --- a/src/covermanager/opentidalcoverprovider.cpp +++ b/src/covermanager/opentidalcoverprovider.cpp @@ -94,7 +94,7 @@ bool OpenTidalCoverProvider::StartSearch(const QString &artist, const QString &a if (artist.isEmpty() || album.isEmpty()) return false; - if (!have_login_ && !login_in_progress_ && QDateTime::currentDateTime().toSecsSinceEpoch() - last_login_attempt_.toSecsSinceEpoch() < 120) { + if (!have_login_ && !login_in_progress_ && QDateTime::currentSecsSinceEpoch() - last_login_attempt_.toSecsSinceEpoch() < 120) { return false; } @@ -123,7 +123,7 @@ void OpenTidalCoverProvider::LoadSession() { login_time_ = s.value("login_time", 0).toLongLong(); s.endGroup(); - if (!token_type_.isEmpty() && !access_token_.isEmpty() && (login_time_ + expires_in_) > (QDateTime::currentDateTime().toSecsSinceEpoch() + 30)) { + if (!token_type_.isEmpty() && !access_token_.isEmpty() && (login_time_ + expires_in_) > (QDateTime::currentSecsSinceEpoch() + 30)) { have_login_ = true; } @@ -131,7 +131,7 @@ void OpenTidalCoverProvider::LoadSession() { void OpenTidalCoverProvider::FlushRequests() { - if (have_login_ && (login_time_ + expires_in_) < QDateTime::currentDateTime().toSecsSinceEpoch()) { + if (have_login_ && (login_time_ + expires_in_) < QDateTime::currentSecsSinceEpoch()) { have_login_ = false; } @@ -153,7 +153,7 @@ void OpenTidalCoverProvider::FlushRequests() { void OpenTidalCoverProvider::LoginCheck() { - if (!login_in_progress_ && (!last_login_attempt_.isValid() || QDateTime::currentDateTime().toSecsSinceEpoch() - last_login_attempt_.toSecsSinceEpoch() > 120)) { + if (!login_in_progress_ && (!last_login_attempt_.isValid() || QDateTime::currentSecsSinceEpoch() - last_login_attempt_.toSecsSinceEpoch() > 120)) { Login(); } @@ -221,7 +221,7 @@ void OpenTidalCoverProvider::LoginFinished(QNetworkReply *reply) { have_login_ = true; token_type_ = json_obj[QLatin1String("token_type")].toString(); access_token_ = json_obj[QLatin1String("access_token")].toString(); - login_time_ = QDateTime::currentDateTime().toSecsSinceEpoch(); + login_time_ = QDateTime::currentSecsSinceEpoch(); expires_in_ = json_obj[QLatin1String("expires_in")].toInt(); Settings s; diff --git a/src/globalshortcuts/globalshortcutsbackend-gnome.cpp b/src/globalshortcuts/globalshortcutsbackend-gnome.cpp index 95cfa7d40..15a24144f 100644 --- a/src/globalshortcuts/globalshortcutsbackend-gnome.cpp +++ b/src/globalshortcuts/globalshortcutsbackend-gnome.cpp @@ -76,7 +76,7 @@ bool GlobalShortcutsBackendGnome::DoRegister() { return false; } - QDBusPendingReply<> reply = interface_->GrabMediaPlayerKeys(QCoreApplication::applicationName(), QDateTime::currentDateTime().toSecsSinceEpoch()); + QDBusPendingReply<> reply = interface_->GrabMediaPlayerKeys(QCoreApplication::applicationName(), QDateTime::currentSecsSinceEpoch()); QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(reply, this); QObject::connect(watcher, &QDBusPendingCallWatcher::finished, this, &GlobalShortcutsBackendGnome::RegisterFinished); diff --git a/src/globalshortcuts/globalshortcutsbackend-mate.cpp b/src/globalshortcuts/globalshortcutsbackend-mate.cpp index 52a3fc264..612f018d0 100644 --- a/src/globalshortcuts/globalshortcutsbackend-mate.cpp +++ b/src/globalshortcuts/globalshortcutsbackend-mate.cpp @@ -76,7 +76,7 @@ bool GlobalShortcutsBackendMate::DoRegister() { return false; } - QDBusPendingReply<> reply = interface_->GrabMediaPlayerKeys(QCoreApplication::applicationName(), QDateTime::currentDateTime().toSecsSinceEpoch()); + QDBusPendingReply<> reply = interface_->GrabMediaPlayerKeys(QCoreApplication::applicationName(), QDateTime::currentSecsSinceEpoch()); QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(reply, this); QObject::connect(watcher, &QDBusPendingCallWatcher::finished, this, &GlobalShortcutsBackendMate::RegisterFinished); diff --git a/src/qobuz/qobuzstreamurlrequest.cpp b/src/qobuz/qobuzstreamurlrequest.cpp index 324672f5c..d617e0386 100644 --- a/src/qobuz/qobuzstreamurlrequest.cpp +++ b/src/qobuz/qobuzstreamurlrequest.cpp @@ -114,7 +114,7 @@ void QobuzStreamURLRequest::GetStreamURL() { reply_->deleteLater(); } - quint64 timestamp = QDateTime::currentDateTime().toSecsSinceEpoch(); + quint64 timestamp = QDateTime::currentSecsSinceEpoch(); ParamList params_to_sign = ParamList() << Param(QStringLiteral("format_id"), QString::number(format())) << Param(QStringLiteral("track_id"), QString::number(song_id_)); diff --git a/src/scrobbler/listenbrainzscrobbler.cpp b/src/scrobbler/listenbrainzscrobbler.cpp index d909a522d..8451bbb13 100644 --- a/src/scrobbler/listenbrainzscrobbler.cpp +++ b/src/scrobbler/listenbrainzscrobbler.cpp @@ -139,7 +139,7 @@ void ListenBrainzScrobbler::LoadSession() { s.endGroup(); if (!refresh_token_.isEmpty()) { - qint64 time = expires_in_ - (QDateTime::currentDateTime().toSecsSinceEpoch() - static_cast(login_time_)); + qint64 time = expires_in_ - (QDateTime::currentSecsSinceEpoch() - static_cast(login_time_)); if (time < 6) time = 6; refresh_login_timer_.setInterval(static_cast(time * kMsecPerSec)); refresh_login_timer_.start(); @@ -331,7 +331,7 @@ void ListenBrainzScrobbler::AuthenticateReplyFinished(QNetworkReply *reply) { if (json_obj.contains(QLatin1String("refresh_token"))) { refresh_token_ = json_obj[QLatin1String("refresh_token")].toString(); } - login_time_ = QDateTime::currentDateTime().toSecsSinceEpoch(); + login_time_ = QDateTime::currentSecsSinceEpoch(); Settings s; s.beginGroup(kSettingsGroup); @@ -452,7 +452,7 @@ void ListenBrainzScrobbler::UpdateNowPlaying(const Song &song) { song_playing_ = song; scrobbled_ = false; - timestamp_ = QDateTime::currentDateTime().toSecsSinceEpoch(); + timestamp_ = QDateTime::currentSecsSinceEpoch(); if (!song.is_metadata_good() || !authenticated() || settings_->offline()) return; @@ -684,7 +684,7 @@ void ListenBrainzScrobbler::Error(const QString &error, const QVariant &debug) { void ListenBrainzScrobbler::CheckScrobblePrevSong() { - qint64 duration = QDateTime::currentDateTime().toSecsSinceEpoch() - static_cast(timestamp_); + qint64 duration = QDateTime::currentSecsSinceEpoch() - static_cast(timestamp_); if (duration < 0) duration = 0; if (!scrobbled_ && song_playing_.is_metadata_good() && song_playing_.is_radio() && duration > 30) { diff --git a/src/scrobbler/scrobblingapi20.cpp b/src/scrobbler/scrobblingapi20.cpp index 9e46e8b5d..36a7c0749 100644 --- a/src/scrobbler/scrobblingapi20.cpp +++ b/src/scrobbler/scrobblingapi20.cpp @@ -394,7 +394,7 @@ void ScrobblingAPI20::UpdateNowPlaying(const Song &song) { CheckScrobblePrevSong(); song_playing_ = song; - timestamp_ = QDateTime::currentDateTime().toSecsSinceEpoch(); + timestamp_ = QDateTime::currentSecsSinceEpoch(); scrobbled_ = false; if (!authenticated() || !song.is_metadata_good() || settings_->offline()) return; @@ -980,7 +980,7 @@ QString ScrobblingAPI20::ErrorString(const ScrobbleErrorCode error) { void ScrobblingAPI20::CheckScrobblePrevSong() { - qint64 duration = QDateTime::currentDateTime().toSecsSinceEpoch() - static_cast(timestamp_); + qint64 duration = QDateTime::currentSecsSinceEpoch() - static_cast(timestamp_); if (duration < 0) duration = 0; if (!scrobbled_ && song_playing_.is_metadata_good() && song_playing_.is_radio() && duration > 30) { diff --git a/src/spotify/spotifyservice.cpp b/src/spotify/spotifyservice.cpp index 0e0758b1f..b10f8a969 100644 --- a/src/spotify/spotifyservice.cpp +++ b/src/spotify/spotifyservice.cpp @@ -216,7 +216,7 @@ void SpotifyService::LoadSession() { s.endGroup(); if (!refresh_token_.isEmpty()) { - qint64 time = static_cast(expires_in_) - (QDateTime::currentDateTime().toSecsSinceEpoch() - static_cast(login_time_)); + qint64 time = static_cast(expires_in_) - (QDateTime::currentSecsSinceEpoch() - static_cast(login_time_)); if (time < 1) time = 1; refresh_login_timer_.setInterval(static_cast(time * kMsecPerSec)); refresh_login_timer_.start(); @@ -479,7 +479,7 @@ void SpotifyService::AccessTokenRequestFinished(QNetworkReply *reply) { refresh_token_ = json_obj[QLatin1String("refresh_token")].toString(); } expires_in_ = json_obj[QLatin1String("expires_in")].toInt(); - login_time_ = QDateTime::currentDateTime().toSecsSinceEpoch(); + login_time_ = QDateTime::currentSecsSinceEpoch(); Settings s; s.beginGroup(SpotifySettingsPage::kSettingsGroup); diff --git a/src/tidal/tidalservice.cpp b/src/tidal/tidalservice.cpp index 798b3b38b..fb5270f5f 100644 --- a/src/tidal/tidalservice.cpp +++ b/src/tidal/tidalservice.cpp @@ -242,7 +242,7 @@ void TidalService::LoadSession() { s.endGroup(); if (!refresh_token_.isEmpty()) { - qint64 time = static_cast(expires_in_) - (QDateTime::currentDateTime().toSecsSinceEpoch() - static_cast(login_time_)); + qint64 time = static_cast(expires_in_) - (QDateTime::currentSecsSinceEpoch() - static_cast(login_time_)); if (time <= 0) { timer_refresh_login_->setInterval(200ms); } @@ -327,7 +327,7 @@ void TidalService::AuthorizationUrlReceived(const QUrl &url) { refresh_token_ = url_query.queryItemValue(QStringLiteral("refresh_token")); } expires_in_ = url_query.queryItemValue(QStringLiteral("expires_in")).toInt(); - login_time_ = QDateTime::currentDateTime().toSecsSinceEpoch(); + login_time_ = QDateTime::currentSecsSinceEpoch(); session_id_.clear(); Settings s; @@ -480,7 +480,7 @@ void TidalService::AccessTokenRequestFinished(QNetworkReply *reply) { if (json_obj.contains(QLatin1String("refresh_token"))) { refresh_token_ = json_obj[QLatin1String("refresh_token")].toString(); } - login_time_ = QDateTime::currentDateTime().toSecsSinceEpoch(); + login_time_ = QDateTime::currentSecsSinceEpoch(); if (json_obj.contains(QLatin1String("user")) && json_obj[QLatin1String("user")].isObject()) { QJsonObject obj_user = json_obj[QLatin1String("user")].toObject();