Replace use of C style casts

This commit is contained in:
Jonas Kvinge
2020-06-15 17:59:02 +02:00
parent a68c249d4e
commit 72ede666d4
35 changed files with 105 additions and 111 deletions

View File

@@ -72,7 +72,7 @@ void Analyzer::Base::showEvent(QShowEvent*) { timer_.start(timeout(), this); }
void Analyzer::Base::transform(Scope& scope) {
QVector<float> aux(fht_->size());
if ((long unsigned int)aux.size() >= scope.size()) {
if (static_cast<long unsigned int>(aux.size()) >= scope.size()) {
std::copy(scope.begin(), scope.end(), aux.begin());
}
else {
@@ -97,7 +97,7 @@ void Analyzer::Base::paintEvent(QPaintEvent *e) {
int i = 0;
// convert to mono here - our built in analyzers need mono, but the engines provide interleaved pcm
for (uint x = 0; (int)x < fht_->size(); ++x) {
for (uint x = 0; static_cast<int>(x) < fht_->size(); ++x) {
lastscope_[x] = double(thescope[i] + thescope[i + 1]) / (2 * (1 << 15));
i += 2;
}
@@ -188,11 +188,11 @@ void Analyzer::Base::polishEvent() {
void Analyzer::interpolate(const Scope& inVec, Scope& outVec) {
double pos = 0.0;
const double step = (double)inVec.size() / outVec.size();
const double step = static_cast<double>(inVec.size()) / outVec.size();
for (uint i = 0; i < outVec.size(); ++i, pos += step) {
const double error = pos - std::floor(pos);
const uint64_t offset = (uint64_t)pos;
const uint64_t offset = static_cast<uint64_t>(pos);
uint64_t indexLeft = offset + 0;

View File

@@ -388,8 +388,8 @@ void BlockAnalyzer::drawBackground() {
if (!p.paintEngine()) return;
for (int x = 0; (uint)x < columns_; ++x)
for (int y = 0; (uint)y < rows_; ++y)
for (int x = 0; static_cast<uint>(x) < columns_; ++x)
for (int y = 0; static_cast<uint>(y) < rows_; ++y)
p.fillRect(x * (kWidth + 1), y * (kHeight + 1) + y_, kWidth, kHeight, bgdark);
}

View File

@@ -711,7 +711,7 @@ void ContextView::ResetSong() {
void ContextView::UpdateLyrics(const quint64 id, const QString &provider, const QString &lyrics) {
if ((qint64) id != lyrics_id_) return;
if (static_cast<qint64>(id) != lyrics_id_) return;
lyrics_ = lyrics + "\n\n(Lyrics from " + provider + ")\n";
lyrics_id_ = -1;
if (action_show_lyrics_->isChecked()) {

View File

@@ -1682,7 +1682,7 @@ void MainWindow::PlaylistRightClick(const QPoint &global_pos, const QModelIndex
}
else {
Playlist::Column column = (Playlist::Column)index.column();
Playlist::Column column = static_cast<Playlist::Column>(index.column());
bool column_is_editable = Playlist::column_is_editable(column) && editable;
ui_->action_selection_set_value->setVisible(ui_->action_selection_set_value->isVisible() && column_is_editable);
@@ -1867,7 +1867,7 @@ void MainWindow::SongSaveComplete(TagReaderReply *reply, const QPersistentModelI
void MainWindow::SelectionSetValue() {
Playlist::Column column = (Playlist::Column)playlist_menu_index_.column();
Playlist::Column column = static_cast<Playlist::Column>(playlist_menu_index_.column());
QVariant column_value = app_->playlist_manager()->current()->data(playlist_menu_index_);
for (const QModelIndex &proxy_index : ui_->playlist->view()->selectionModel()->selectedRows()) {

View File

@@ -875,7 +875,7 @@ QString UnicodeToAscii(const QString &unicode) {
#endif
iconv_t conv = iconv_open("ASCII//TRANSLIT", "UTF-8");
if (conv == (iconv_t) -1) return unicode;
if (conv == reinterpret_cast<iconv_t>(-1)) return unicode;
QByteArray utf8 = unicode.toUtf8();

View File

@@ -294,13 +294,13 @@ void AlbumCoverChoiceController::ShowCover(const Song &song, const QPixmap &pixm
// Resize differently if monitor is in portrait mode
if (desktop_width < desktop_height) {
const int new_width = (double)desktop_width * 0.95;
const int new_width = static_cast<double>(desktop_width) * 0.95;
if (new_width < pixmap.width()) {
label->setPixmap(pixmap.scaledToWidth(new_width, Qt::SmoothTransformation));
}
}
else {
const int new_height = (double)desktop_height * 0.85;
const int new_height = static_cast<double>(desktop_height) * 0.85;
if (new_height < pixmap.height()) {
label->setPixmap(pixmap.scaledToHeight(new_height, Qt::SmoothTransformation));
}

View File

@@ -152,7 +152,7 @@ void CddaSongLoader::LoadSongs() {
GstMessage *msg = nullptr;
GstMessage *msg_toc = nullptr;
GstMessage *msg_tag = nullptr;
while ((msg = gst_bus_timed_pop_filtered(GST_ELEMENT_BUS(pipeline), GST_SECOND, (GstMessageType)(GST_MESSAGE_TOC | GST_MESSAGE_TAG)))) {
while ((msg = gst_bus_timed_pop_filtered(GST_ELEMENT_BUS(pipeline), GST_SECOND, static_cast<GstMessageType>(GST_MESSAGE_TOC | GST_MESSAGE_TAG)))) {
if (GST_MESSAGE_TYPE(msg) == GST_MESSAGE_TOC) {
if (msg_toc) gst_message_unref(msg_toc); // Shouldn't happen, but just in case
msg_toc = msg;
@@ -169,7 +169,7 @@ void CddaSongLoader::LoadSongs() {
gst_message_parse_toc (msg_toc, &toc, nullptr);
if (toc) {
GList *entries = gst_toc_get_entries(toc);
if (entries && (guint)songs.size() <= g_list_length(entries)) {
if (entries && static_cast<guint>(songs.size()) <= g_list_length(entries)) {
int i = 0;
for (GList *node = entries; node != nullptr; node = node->next) {
GstTocEntry *entry = static_cast<GstTocEntry*>(node->data);

View File

@@ -52,7 +52,7 @@ QString GioLister::DeviceInfo::unique_id() const {
if (mount_ptr)
return QString("Gio/%1/%2/%3").arg(mount_uuid, filesystem_type).arg(filesystem_size);
else
return QString("Gio/unmounted/%1").arg((qulonglong)volume_ptr.get());
return QString("Gio/unmounted/%1").arg(reinterpret_cast<qulonglong>(volume_ptr.get()));
}
@@ -609,7 +609,7 @@ void GioLister::UnmountDevice(const QString &id) {
if (info.volume_ptr) {
if (g_volume_can_eject(info.volume_ptr)) {
g_volume_eject_with_operation(info.volume_ptr, G_MOUNT_UNMOUNT_NONE, nullptr, nullptr, (GAsyncReadyCallback)VolumeEjectFinished, nullptr);
g_volume_eject_with_operation(info.volume_ptr, G_MOUNT_UNMOUNT_NONE, nullptr, nullptr, reinterpret_cast<GAsyncReadyCallback>(VolumeEjectFinished), nullptr);
g_object_unref(info.volume_ptr);
return;
}
@@ -617,10 +617,10 @@ void GioLister::UnmountDevice(const QString &id) {
else return;
if (g_mount_can_eject(info.mount_ptr)) {
g_mount_eject_with_operation(info.mount_ptr, G_MOUNT_UNMOUNT_NONE, nullptr, nullptr, (GAsyncReadyCallback)MountEjectFinished, nullptr);
g_mount_eject_with_operation(info.mount_ptr, G_MOUNT_UNMOUNT_NONE, nullptr, nullptr, reinterpret_cast<GAsyncReadyCallback>(MountEjectFinished), nullptr);
}
else if (g_mount_can_unmount(info.mount_ptr)) {
g_mount_unmount_with_operation(info.mount_ptr, G_MOUNT_UNMOUNT_NONE, nullptr, nullptr, (GAsyncReadyCallback)MountUnmountFinished, nullptr);
g_mount_unmount_with_operation(info.mount_ptr, G_MOUNT_UNMOUNT_NONE, nullptr, nullptr, reinterpret_cast<GAsyncReadyCallback>(MountUnmountFinished), nullptr);
}
}

View File

@@ -60,7 +60,7 @@ MtpConnection::MtpConnection(const QUrl &url) : device_(nullptr) {
}
if (url_query.hasQueryItem("vendor")) {
LIBMTP_raw_device_t *raw_device = (LIBMTP_raw_device_t*)malloc(sizeof(LIBMTP_raw_device_t));
LIBMTP_raw_device_t *raw_device = static_cast<LIBMTP_raw_device_t*>(malloc(sizeof(LIBMTP_raw_device_t)));
raw_device->device_entry.vendor = url_query.queryItemValue("vendor").toLatin1().data();
raw_device->device_entry.product = url_query.queryItemValue("product").toLatin1().data();
raw_device->device_entry.vendor_id = url_query.queryItemValue("vendor_id").toUShort();

View File

@@ -321,7 +321,7 @@ const Engine::Scope &GstEngine::scope(const int chunk_length) {
// The new buffer could have a different size
if (have_new_buffer_) {
if (latest_buffer_) {
scope_chunks_ = ceil(((double)GST_BUFFER_DURATION(latest_buffer_) / (double)(chunk_length * kNsecPerMsec)));
scope_chunks_ = ceil((static_cast<double>(GST_BUFFER_DURATION(latest_buffer_) / static_cast<double>(chunk_length * kNsecPerMsec))));
}
// if the buffer is shorter than the chunk length
@@ -514,7 +514,7 @@ void GstEngine::HandlePipelineError(const int pipeline_id, const QString &messag
BufferingFinished();
emit StateChanged(Engine::Error);
if (domain == (int)GST_RESOURCE_ERROR && (error_code == (int)GST_RESOURCE_ERROR_NOT_FOUND || error_code == (int)GST_RESOURCE_ERROR_NOT_AUTHORIZED)) {
if (domain == static_cast<int>(GST_RESOURCE_ERROR) && (error_code == static_cast<int>(GST_RESOURCE_ERROR_NOT_FOUND) || error_code == static_cast<int>(GST_RESOURCE_ERROR_NOT_AUTHORIZED))) {
emit InvalidSongRequested(stream_url_);
}
else {

View File

@@ -581,13 +581,13 @@ GstPadProbeReturn GstEnginePipeline::HandoffCallback(GstPad *pad, GstPadProbeInf
GstMapInfo map_info;
gst_buffer_map(buf, &map_info, GST_MAP_READ);
int32_t *s = (int32_t*) map_info.data;
int32_t *s = reinterpret_cast<int32_t*>(map_info.data);
int samples = (map_info.size / sizeof(int32_t)) / channels;
int buf16_size = samples * sizeof(int16_t) * channels;
int16_t *d = (int16_t*) g_malloc(buf16_size);
int16_t *d = static_cast<int16_t*>(g_malloc(buf16_size));
memset(d, 0, buf16_size);
for (int i = 0 ; i < (samples * channels) ; ++i) {
d[i] = (int16_t) (s[i] >> 16);
d[i] = static_cast<int16_t>((s[i] >> 16));
}
gst_buffer_unmap(buf, &map_info);
buf16 = gst_buffer_new_wrapped(d, buf16_size);
@@ -801,7 +801,7 @@ void GstEnginePipeline::ErrorMessageReceived(GstMessage *msg) {
g_error_free(error);
g_free(debugs);
if (state() == GST_STATE_PLAYING && pipeline_is_initialised_ && next_uri_set_ && (domain == (int)GST_RESOURCE_ERROR || domain == (int)GST_STREAM_ERROR)) {
if (state() == GST_STATE_PLAYING && pipeline_is_initialised_ && next_uri_set_ && (domain == static_cast<int>(GST_RESOURCE_ERROR) || domain == static_cast<int>(GST_STREAM_ERROR))) {
// A track is still playing and the next uri is not playable. We ignore the error here so it can play until the end.
// But there is no message send to the bus when the current track finishes, we have to add an EOS ourself.
qLog(Debug) << "Ignoring error when loading next track";
@@ -1187,7 +1187,7 @@ void GstEnginePipeline::StreamDiscovered(GstDiscoverer*, GstDiscovererInfo *info
GList *audio_streams = gst_discoverer_info_get_audio_streams(info);
if (audio_streams) {
GstDiscovererStreamInfo *stream_info = (GstDiscovererStreamInfo*) g_list_first(audio_streams)->data;
GstDiscovererStreamInfo *stream_info = reinterpret_cast<GstDiscovererStreamInfo*>(g_list_first(audio_streams)->data);
Engine::SimpleMetaBundle bundle;
if (discovered_url == instance->stream_url_) {

View File

@@ -212,7 +212,7 @@ bool XineEngine::CreateStream() {
if (eventqueue_) xine_event_dispose_queue(eventqueue_);
eventqueue_ = xine_event_new_queue(stream_);
xine_event_create_listener_thread(eventqueue_, &XineEngine::XineEventListener, (void*)this);
xine_event_create_listener_thread(eventqueue_, &XineEngine::XineEventListener, reinterpret_cast<void*>(this));
#ifndef XINE_SAFE_MODE
xine_set_param(stream_, XINE_PARAM_METRONOM_PREBUFFER, 6000);
@@ -644,7 +644,7 @@ void XineEngine::XineEventListener(void *p, const xine_event_t *event) {
case XINE_EVENT_PROGRESS:
{
xine_progress_data_t *pd = (xine_progress_data_t*)event->data;
xine_progress_data_t *pd = reinterpret_cast<xine_progress_data_t*>(event->data);
QString msg = QString("%1 %2%").arg(QString::fromUtf8(pd->description)).arg(QString::number(pd->percent) + QLocale::system().percent());
//qLog(Debug) << "Xine:" << msg;
}
@@ -664,7 +664,7 @@ void XineEngine::XineEventListener(void *p, const xine_event_t *event) {
{
qLog(Debug) << "XINE_EVENT_UI_MESSAGE";
xine_ui_message_data_t *data = (xine_ui_message_data_t *)event->data;
xine_ui_message_data_t *data = reinterpret_cast<xine_ui_message_data_t*>(event->data);
QString message;
switch (data->type) {
@@ -685,7 +685,7 @@ void XineEngine::XineEventListener(void *p, const xine_event_t *event) {
message = "Source is encrypted.";
if (data->explanation) {
message += " : ";
message += QString::fromUtf8((char*)data + data->parameters);
message += QString::fromUtf8(reinterpret_cast<char*>(data) + data->parameters);
}
emit engine->StateChanged(Engine::Error);
emit engine->InvalidSongRequested(engine->stream_url_);
@@ -694,7 +694,7 @@ void XineEngine::XineEventListener(void *p, const xine_event_t *event) {
message = "The host is unknown.";
if (data->explanation) {
message += " : ";
message += QString::fromUtf8((char*)data + data->parameters);
message += QString::fromUtf8(reinterpret_cast<char*>(data) + data->parameters);
}
emit engine->StateChanged(Engine::Error);
emit engine->InvalidSongRequested(engine->stream_url_);
@@ -703,7 +703,7 @@ void XineEngine::XineEventListener(void *p, const xine_event_t *event) {
message = "The device name you specified seems invalid.";
if (data->explanation) {
message += " : ";
message += QString::fromUtf8((char*)data + data->parameters);
message += QString::fromUtf8(reinterpret_cast<char*>(data) + data->parameters);
}
emit engine->StateChanged(Engine::Error);
emit engine->InvalidSongRequested(engine->stream_url_);
@@ -712,7 +712,7 @@ void XineEngine::XineEventListener(void *p, const xine_event_t *event) {
message = "The network appears unreachable.";
if (data->explanation) {
message += " : ";
message += QString::fromUtf8((char*)data + data->parameters);
message += QString::fromUtf8(reinterpret_cast<char*>(data) + data->parameters);
}
emit engine->StateChanged(Engine::Error);
emit engine->InvalidSongRequested(engine->stream_url_);
@@ -721,7 +721,7 @@ void XineEngine::XineEventListener(void *p, const xine_event_t *event) {
message = "Audio output unavailable; the device is busy.";
if (data->explanation) {
message += " : ";
message += QString::fromUtf8((char*)data + data->parameters);
message += QString::fromUtf8(reinterpret_cast<char*>(data) + data->parameters);
}
emit engine->StateChanged(Engine::Error);
emit engine->FatalError();
@@ -730,7 +730,7 @@ void XineEngine::XineEventListener(void *p, const xine_event_t *event) {
message = "Connection refused.";
if (data->explanation) {
message += " : ";
message += QString::fromUtf8((char*)data + data->parameters);
message += QString::fromUtf8(reinterpret_cast<char*>(data) + data->parameters);
}
emit engine->StateChanged(Engine::Error);
emit engine->InvalidSongRequested(engine->stream_url_);
@@ -739,7 +739,7 @@ void XineEngine::XineEventListener(void *p, const xine_event_t *event) {
message = "File not found.";
if (data->explanation) {
message += " : ";
message += QString::fromUtf8((char*)data + data->parameters);
message += QString::fromUtf8(reinterpret_cast<char*>(data) + data->parameters);
}
emit engine->StateChanged(Engine::Error);
emit engine->InvalidSongRequested(engine->stream_url_);
@@ -748,7 +748,7 @@ void XineEngine::XineEventListener(void *p, const xine_event_t *event) {
message = "Access denied.";
if (data->explanation) {
message += " : ";
message += QString::fromUtf8((char*)data + data->parameters);
message += QString::fromUtf8(reinterpret_cast<char*>(data) + data->parameters);
}
emit engine->StateChanged(Engine::Error);
emit engine->InvalidSongRequested(engine->stream_url_);
@@ -757,7 +757,7 @@ void XineEngine::XineEventListener(void *p, const xine_event_t *event) {
message = "Read error.";
if (data->explanation) {
message += " : ";
message += QString::fromUtf8((char*)data + data->parameters);
message += QString::fromUtf8(reinterpret_cast<char*>(data) + data->parameters);
}
emit engine->StateChanged(Engine::Error);
emit engine->InvalidSongRequested(engine->stream_url_);
@@ -766,7 +766,7 @@ void XineEngine::XineEventListener(void *p, const xine_event_t *event) {
message = "A problem occurred while loading a library or decoder.";
if (data->explanation) {
message += " : ";
message += QString::fromUtf8((char*)data + data->parameters);
message += QString::fromUtf8(reinterpret_cast<char*>(data) + data->parameters);
}
emit engine->StateChanged(Engine::Error);
emit engine->FatalError();
@@ -775,7 +775,7 @@ void XineEngine::XineEventListener(void *p, const xine_event_t *event) {
message = "General Warning";
if (data->explanation) {
message += ": ";
message += QString::fromUtf8((char*)data + data->explanation);
message += QString::fromUtf8(reinterpret_cast<char*>(data) + data->explanation);
}
else message += ".";
break;
@@ -783,7 +783,7 @@ void XineEngine::XineEventListener(void *p, const xine_event_t *event) {
message = "Security Warning";
if (data->explanation) {
message += ": ";
message += QString::fromUtf8((char*)data + data->explanation);
message += QString::fromUtf8(reinterpret_cast<char*>(data) + data->explanation);
}
else message += ".";
break;
@@ -791,7 +791,7 @@ void XineEngine::XineEventListener(void *p, const xine_event_t *event) {
message = "Unknown Error";
if (data->explanation) {
message += ": ";
message += QString::fromUtf8((char*)data + data->explanation);
message += QString::fromUtf8(reinterpret_cast<char*>(data) + data->explanation);
}
else message += ".";
break;

View File

@@ -177,7 +177,7 @@ QVariant Playlist::headerData(int section, Qt::Orientation, int role) const {
if (role != Qt::DisplayRole && role != Qt::ToolTipRole) return QVariant();
const QString name = column_name((Playlist::Column)section);
const QString name = column_name(static_cast<Playlist::Column>(section));
if (!name.isEmpty()) return name;
return QVariant();
@@ -375,7 +375,7 @@ bool Playlist::setData(const QModelIndex &index, const QVariant &value, int role
if (index.data() == value) return false;
if (!set_column_value(song, (Column)index.column(), value)) return false;
if (!set_column_value(song, static_cast<Column>(index.column()), value)) return false;
TagReaderReply *reply = TagReaderClient::Instance()->SaveFile(song.url().toLocalFile(), song);
NewClosure(reply, SIGNAL(Finished(bool)), this, SLOT(SongSaveComplete(TagReaderReply*, QPersistentModelIndex)), reply, QPersistentModelIndex(index));
@@ -655,7 +655,7 @@ Qt::ItemFlags Playlist::flags(const QModelIndex &index) const {
Qt::ItemFlags flags = Qt::ItemIsEnabled | Qt::ItemIsSelectable;
if (column_is_editable((Column)index.column())) flags |= Qt::ItemIsEditable;
if (column_is_editable(static_cast<Column>(index.column()))) flags |= Qt::ItemIsEditable;
if (index.isValid()) return flags | Qt::ItemIsDragEnabled;
@@ -718,7 +718,7 @@ bool Playlist::dropMimeData(const QMimeData *data, Qt::DropAction action, int ro
stream.readRawData(reinterpret_cast<char*>(&source_playlist), sizeof(source_playlist));
stream >> source_rows;
if (!stream.atEnd()) {
stream.readRawData((char*)&pid, sizeof(pid));
stream.readRawData(reinterpret_cast<char*>(&pid), sizeof(pid));
}
else {
pid = !own_pid;
@@ -1097,7 +1097,7 @@ QMimeData *Playlist::mimeData(const QModelIndexList &indexes) const {
stream.writeRawData(reinterpret_cast<char*>(&self), sizeof(self));
stream << rows;
stream.writeRawData((char*)&pid, sizeof(pid));
stream.writeRawData(reinterpret_cast<const char*>(&pid), sizeof(pid));
buf.close();
mimedata->setUrls(urls);

View File

@@ -173,10 +173,10 @@ void CollectionSettingsPage::Load() {
ui_->checkbox_cover_replace_spaces->setChecked(s.value("cover_replace_spaces", true).toBool());
ui_->spinbox_cache_size->setValue(s.value(kSettingsCacheSize, kSettingsCacheSizeDefault).toInt());
ui_->combobox_cache_size->setCurrentIndex(s.value(kSettingsCacheSizeUnit, (int) CacheSizeUnit_MB).toInt());
ui_->combobox_cache_size->setCurrentIndex(s.value(kSettingsCacheSizeUnit, static_cast<int>(CacheSizeUnit_MB)).toInt());
ui_->checkbox_disk_cache->setChecked(s.value(kSettingsDiskCacheEnable, false).toBool());
ui_->spinbox_disk_cache_size->setValue(s.value(kSettingsDiskCacheSize, kSettingsDiskCacheSizeDefault).toInt());
ui_->combobox_disk_cache_size->setCurrentIndex(s.value(kSettingsDiskCacheSizeUnit, (int) CacheSizeUnit_MB).toInt());
ui_->combobox_disk_cache_size->setCurrentIndex(s.value(kSettingsDiskCacheSizeUnit, static_cast<int>(CacheSizeUnit_MB)).toInt());
s.endGroup();

View File

@@ -76,7 +76,7 @@ class FancyTabBar: public QTabBar {
QSize size(QTabBar::sizeHint());
FancyTabWidget *tabWidget = (FancyTabWidget*) parentWidget();
FancyTabWidget *tabWidget = qobject_cast<FancyTabWidget*>(parentWidget());
if (tabWidget->mode() == FancyTabWidget::Mode_Tabs || tabWidget->mode() == FancyTabWidget::Mode_IconOnlyTabs) return size;
QSize tabSize(tabSizeHint(0));
@@ -95,7 +95,7 @@ class FancyTabBar: public QTabBar {
protected:
QSize tabSizeHint(int index) const {
FancyTabWidget *tabWidget = (FancyTabWidget*) parentWidget();
FancyTabWidget *tabWidget = qobject_cast<FancyTabWidget*>(parentWidget());
QSize size = FancyTabWidget::TabSize_LargeSidebar;
if (tabWidget->mode() != FancyTabWidget::Mode_LargeSidebar) {
@@ -126,7 +126,7 @@ class FancyTabBar: public QTabBar {
void paintEvent(QPaintEvent *pe) {
FancyTabWidget *tabWidget = (FancyTabWidget*) parentWidget();
FancyTabWidget *tabWidget = qobject_cast<FancyTabWidget*>(parentWidget());
bool verticalTextTabs = false;