Use static_cast

This commit is contained in:
Jonas Kvinge
2021-03-21 18:53:02 +01:00
parent f91a679cdf
commit 59bffed47f
80 changed files with 241 additions and 242 deletions

View File

@@ -1599,11 +1599,11 @@ void MainWindow::FilePathChanged(const QString &path) {
settings_.setValue("file_path", path);
}
void MainWindow::Seeked(const qlonglong microseconds) {
void MainWindow::Seeked(const qint64 microseconds) {
const int position = microseconds / kUsecPerSec;
const int length = app_->player()->GetCurrentItem()->Metadata().length_nanosec() / kNsecPerSec;
if (tray_icon_) tray_icon_->SetProgress(double(position) / length * 100);
const qint64 position = microseconds / kUsecPerSec;
const qint64 length = app_->player()->GetCurrentItem()->Metadata().length_nanosec() / kNsecPerSec;
if (tray_icon_) tray_icon_->SetProgress(static_cast<int>(double(position) / length * 100));
}
@@ -1612,18 +1612,18 @@ void MainWindow::UpdateTrackPosition() {
PlaylistItemPtr item(app_->player()->GetCurrentItem());
if (!item) return;
const int length = (item->Metadata().length_nanosec() / kNsecPerSec);
const qint64 length = (item->Metadata().length_nanosec() / kNsecPerSec);
if (length <= 0) return;
const int position = std::floor(float(app_->player()->engine()->position_nanosec()) / kNsecPerSec + 0.5);
// Update the tray icon every 10 seconds
if (tray_icon_ && position % 10 == 0) tray_icon_->SetProgress(double(position) / length * 100);
if (tray_icon_ && position % 10 == 0) tray_icon_->SetProgress(static_cast<int>(double(position) / length * 100));
// Send Scrobble
if (app_->scrobbler()->IsEnabled() && item->Metadata().is_metadata_good()) {
Playlist *playlist = app_->playlist_manager()->active();
if (playlist && !playlist->scrobbled()) {
const int scrobble_point = (playlist->scrobble_point_nanosec() / kNsecPerSec);
const qint64 scrobble_point = (playlist->scrobble_point_nanosec() / kNsecPerSec);
if (position >= scrobble_point) {
app_->scrobbler()->Scrobble(item->Metadata(), scrobble_point);
playlist->set_scrobbled(true);
@@ -1637,8 +1637,8 @@ void MainWindow::UpdateTrackSliderPosition() {
PlaylistItemPtr item(app_->player()->GetCurrentItem());
const int slider_position = std::floor(float(app_->player()->engine()->position_nanosec()) / kNsecPerMsec);
const int slider_length = app_->player()->engine()->length_nanosec() / kNsecPerMsec;
const qint64 slider_position = std::floor(float(app_->player()->engine()->position_nanosec()) / kNsecPerMsec);
const qint64 slider_length = app_->player()->engine()->length_nanosec() / kNsecPerMsec;
// Update the slider
ui_->track_slider->SetValue(slider_position, slider_length);

View File

@@ -200,7 +200,7 @@ class MainWindow : public QMainWindow, public PlatformInterface {
void ToggleShowHide();
void ToggleHide();
void Seeked(const qlonglong microseconds);
void Seeked(const qint64 microseconds);
void UpdateTrackPosition();
void UpdateTrackSliderPosition();

View File

@@ -412,9 +412,9 @@ void Mpris2::AlbumCoverLoaded(const Song &song, const AlbumCoverLoaderResult &re
double Mpris2::Volume() const { return app_->player()->GetVolume() / 100.0; }
void Mpris2::SetVolume(double value) { app_->player()->SetVolume(value * 100); }
void Mpris2::SetVolume(double value) { app_->player()->SetVolume(static_cast<int>(value * 100)); }
qlonglong Mpris2::Position() const {
qint64 Mpris2::Position() const {
return app_->player()->engine()->position_nanosec() / kNsecPerUsec;
}
@@ -479,13 +479,16 @@ void Mpris2::Play() {
}
}
void Mpris2::Seek(qlonglong offset) {
void Mpris2::Seek(qint64 offset) {
if (CanSeek()) {
app_->player()->SeekTo(app_->player()->engine()->position_nanosec() / kNsecPerSec + offset / kUsecPerSec);
}
}
void Mpris2::SetPosition(const QDBusObjectPath &trackId, qlonglong offset) {
void Mpris2::SetPosition(const QDBusObjectPath &trackId, qint64 offset) {
if (CanSeek() && trackId.path() == current_track_id() && offset >= 0) {
offset *= kNsecPerUsec;
@@ -493,6 +496,7 @@ void Mpris2::SetPosition(const QDBusObjectPath &trackId, qlonglong offset) {
app_->player()->SeekTo(offset / kNsecPerSec);
}
}
}
void Mpris2::OpenUri(const QString &uri) {

View File

@@ -98,7 +98,7 @@ class Mpris2 : public QObject {
Q_PROPERTY(bool Shuffle READ Shuffle WRITE SetShuffle)
Q_PROPERTY(QVariantMap Metadata READ Metadata)
Q_PROPERTY(double Volume READ Volume WRITE SetVolume)
Q_PROPERTY(qlonglong Position READ Position)
Q_PROPERTY(qint64 Position READ Position)
Q_PROPERTY(double MinimumRate READ MinimumRate)
Q_PROPERTY(double MaximumRate READ MaximumRate)
Q_PROPERTY(bool CanGoNext READ CanGoNext)
@@ -146,7 +146,7 @@ class Mpris2 : public QObject {
QVariantMap Metadata() const;
double Volume() const;
void SetVolume(double value);
qlonglong Position() const;
qint64 Position() const;
double MaximumRate() const;
double MinimumRate() const;
bool CanGoNext() const;
@@ -163,8 +163,8 @@ class Mpris2 : public QObject {
void PlayPause();
void Stop();
void Play();
void Seek(qlonglong offset);
void SetPosition(const QDBusObjectPath &trackId, qlonglong offset);
void Seek(qint64 offset);
void SetPosition(const QDBusObjectPath &trackId, qint64 offset);
void OpenUri(const QString &uri);
// TrackList Properties
@@ -188,7 +188,7 @@ class Mpris2 : public QObject {
signals:
// Player
void Seeked(qlonglong position);
void Seeked(qint64 position);
// TrackList
void TrackListReplaced(Track_Ids Tracks, QDBusObjectPath CurrentTrack);

View File

@@ -633,7 +633,7 @@ void Player::CurrentMetadataChanged(const Song &metadata) {
}
void Player::SeekTo(const int seconds) {
void Player::SeekTo(const qint64 seconds) {
const qint64 length_nanosec = engine_->length_nanosec();

View File

@@ -87,7 +87,7 @@ class PlayerInterface : public QObject {
virtual void SetVolume(const int value) = 0;
virtual void VolumeUp() = 0;
virtual void VolumeDown() = 0;
virtual void SeekTo(const int seconds) = 0;
virtual void SeekTo(const qint64 seconds) = 0;
// Moves the position of the currently playing song five seconds forward.
virtual void SeekForward() = 0;
// Moves the position of the currently playing song five seconds backwards.
@@ -113,7 +113,7 @@ class PlayerInterface : public QObject {
void VolumeChanged(int volume);
void TrackSkipped(PlaylistItemPtr old_track);
// Emitted when there's a manual change to the current's track position.
void Seeked(qlonglong microseconds);
void Seeked(qint64 microseconds);
// Emitted when Player has processed a request to play another song.
// This contains the URL of the song and a flag saying whether it was able to play the song.
@@ -168,7 +168,7 @@ class Player : public PlayerInterface {
void SetVolume(const int value) override;
void VolumeUp() override { SetVolume(GetVolume() + 5); }
void VolumeDown() override { SetVolume(GetVolume() - 5); }
void SeekTo(const int seconds) override;
void SeekTo(const qint64 seconds) override;
void SeekForward() override;
void SeekBackward() override;

View File

@@ -41,7 +41,7 @@ gulong CheckedGConnect(gpointer source, const char *signal, GCallback callback,
GSignalQuery query;
g_signal_query(signal_id, &query);
// The signature for a signal callback is always: return_type callback(gpointer data1, params..., gpointer data2);
int signal_params = query.n_params + 2;
int signal_params = static_cast<int>(query.n_params) + 2;
if (signal_params != callback_param_count) {
qFatal("Connecting callback to signal with different parameters counts");
return 0;

View File

@@ -214,7 +214,7 @@ struct Song::Private : public QSharedData {
QString cue_path_; // If the song has a CUE, this contains it's path.
float rating_; // Database rating, not read from tags.
double rating_; // Database rating, not read from tags.
QUrl stream_url_; // Temporary stream url set by url handler.
QImage image_; // Album Cover image set by album cover loader.
@@ -360,7 +360,7 @@ const QImage &Song::image() const { return d->image_; }
const QString &Song::cue_path() const { return d->cue_path_; }
bool Song::has_cue() const { return !d->cue_path_.isEmpty(); }
float Song::rating() const { return d->rating_; }
double Song::rating() const { return d->rating_; }
bool Song::is_collection_song() const { return d->source_ == Source_Collection; }
bool Song::is_metadata_good() const { return !d->url_.isEmpty() && !d->artist_.isEmpty() && !d->title_.isEmpty(); }
@@ -461,7 +461,7 @@ void Song::set_art_automatic(const QUrl &v) { d->art_automatic_ = v; }
void Song::set_art_manual(const QUrl &v) { d->art_manual_ = v; }
void Song::set_cue_path(const QString &v) { d->cue_path_ = v; }
void Song::set_rating(float v) { d->rating_ = v; }
void Song::set_rating(double v) { d->rating_ = v; }
void Song::set_stream_url(const QUrl &v) { d->stream_url_ = v; }
void Song::set_image(const QImage &i) { d->image_ = i; }
@@ -844,7 +844,7 @@ void Song::ToProtobuf(spb::tagreader::SongMetadata *pb) const {
#define tostr(n) (q.value(n).isNull() ? QString() : q.value(n).toString())
#define toint(n) (q.value(n).isNull() ? -1 : q.value(n).toInt())
#define tolonglong(n) (q.value(n).isNull() ? -1 : q.value(n).toLongLong())
#define tofloat(n) (q.value(n).isNull() ? -1 : q.value(n).toDouble())
#define todouble(n) (q.value(n).isNull() ? -1 : q.value(n).toDouble())
void Song::InitFromQuery(const SqlRow &q, bool reliable_metadata, int col) {
@@ -1013,7 +1013,7 @@ void Song::InitFromQuery(const SqlRow &q, bool reliable_metadata, int col) {
}
else if (Song::kColumns.value(i) == "rating") {
d->rating_ = tofloat(x);
d->rating_ = todouble(x);
}
else {
@@ -1029,7 +1029,7 @@ void Song::InitFromQuery(const SqlRow &q, bool reliable_metadata, int col) {
#undef tostr
#undef toint
#undef tolonglong
#undef tofloat
#undef todouble
}
@@ -1474,7 +1474,7 @@ QString Song::SampleRateBitDepthToText() const {
QString Song::PrettyRating() const {
float rating = d->rating_;
double rating = d->rating_;
if (rating == -1.0f) return "0";

View File

@@ -243,7 +243,7 @@ class Song {
const QString &cue_path() const;
bool has_cue() const;
float rating() const;
double rating() const;
const QString &effective_album() const;
int effective_originalyear() const;
@@ -356,7 +356,7 @@ class Song {
void set_cue_path(const QString &v);
void set_rating(const float v);
void set_rating(const double v);
void set_stream_url(const QUrl &v);
void set_image(const QImage &i);

View File

@@ -61,7 +61,7 @@ QPixmap SystemTrayIcon::CreateIcon(const QPixmap &icon, const QPixmap &grey_icon
QPolygon mask;
mask << rect.topLeft();
mask << rect.topLeft() + QPoint(length * sin(angle), length * cos(angle));
mask << rect.topLeft() + QPoint(static_cast<int>(length * sin(angle)), static_cast<int>(length * cos(angle)));
if (song_progress() > 50) mask << rect.bottomRight();

View File

@@ -128,7 +128,7 @@ QString PrettyTime(int seconds) {
}
QString PrettyTimeNanosec(qint64 nanoseconds) {
return PrettyTime(nanoseconds / kNsecPerSec);
return PrettyTime(static_cast<int>(nanoseconds / kNsecPerSec));
}
QString WordyTime(quint64 seconds) {
@@ -139,7 +139,7 @@ QString WordyTime(quint64 seconds) {
QStringList parts;
if (days) parts << (days == 1 ? tr("1 day") : tr("%1 days").arg(days));
parts << PrettyTime(seconds - days * 60 * 60 * 24);
parts << PrettyTime(static_cast<int>(seconds - days * 60 * 60 * 24));
return parts.join(" ");