diff --git a/cli/mainfeatures.cpp b/cli/mainfeatures.cpp index 1cc6447..aebf50d 100644 --- a/cli/mainfeatures.cpp +++ b/cli/mainfeatures.cpp @@ -506,15 +506,15 @@ void setTagInfo(const SetTagInfoArgs &args) static string context("setting tags"); for (const char *file : args.filesArg.values()) { Diagnostics diag; - AbortableProgressFeedback progress; // FIXME: actually use the progress object + AbortableProgressFeedback parsingProgress; // FIXME: actually use the progress object try { // parse tags and tracks (tracks are relevent because track meta-data such as language can be changed as well) cout << TextAttribute::Bold << "Setting tag information for \"" << file << "\" ..." << Phrases::EndFlush; fileInfo.setPath(file); - fileInfo.parseContainerFormat(diag, progress); - fileInfo.parseTags(diag, progress); - fileInfo.parseTracks(diag, progress); - fileInfo.parseAttachments(diag, progress); + fileInfo.parseContainerFormat(diag, parsingProgress); + fileInfo.parseTags(diag, parsingProgress); + fileInfo.parseTracks(diag, parsingProgress); + fileInfo.parseAttachments(diag, parsingProgress); vector tags; // remove tags with the specified targets @@ -618,16 +618,16 @@ void setTagInfo(const SetTagInfoArgs &args) // add value from file try { // assume the file refers to a picture - MediaFileInfo fileInfo(relevantDenotedValue->value); - Diagnostics diag; - AbortableProgressFeedback progress; // FIXME: actually use the progress object - fileInfo.open(true); - fileInfo.parseContainerFormat(diag, progress); - auto buff = make_unique(fileInfo.size()); - fileInfo.stream().seekg(static_cast(fileInfo.containerOffset())); - fileInfo.stream().read(buff.get(), static_cast(fileInfo.size())); - TagValue value(move(buff), fileInfo.size(), TagDataType::Picture); - value.setMimeType(fileInfo.mimeType()); + MediaFileInfo coverFileInfo(relevantDenotedValue->value); + Diagnostics coverDiag; + AbortableProgressFeedback coverProgress; // FIXME: actually use the progress object + coverFileInfo.open(true); + coverFileInfo.parseContainerFormat(coverDiag, coverProgress); + auto buff = make_unique(coverFileInfo.size()); + coverFileInfo.stream().seekg(static_cast(coverFileInfo.containerOffset())); + coverFileInfo.stream().read(buff.get(), static_cast(coverFileInfo.size())); + TagValue value(move(buff), coverFileInfo.size(), TagDataType::Picture); + value.setMimeType(coverFileInfo.mimeType()); convertedValues.emplace_back(move(value)); } catch (const TagParser::Failure &) { diag.emplace_back(DiagLevel::Critical, "Unable to parse specified cover file.", context); @@ -703,8 +703,8 @@ void setTagInfo(const SetTagInfoArgs &args) bool attachmentsModified = false; if (args.addAttachmentArg.isPresent() || args.updateAttachmentArg.isPresent() || args.removeAttachmentArg.isPresent() || args.removeExistingAttachmentsArg.isPresent()) { - static const string context("setting attachments"); - fileInfo.parseAttachments(diag, progress); + static const string attachmentsContext("setting attachments"); + fileInfo.parseAttachments(diag, parsingProgress); if (fileInfo.attachmentsParsingStatus() == ParsingStatus::Ok && container) { // ignore all existing attachments if argument is specified if (args.removeExistingAttachmentsArg.isPresent()) { @@ -737,8 +737,8 @@ void setTagInfo(const SetTagInfoArgs &args) attachmentsModified |= currentInfo.next(container, diag); } } else { - diag.emplace_back( - DiagLevel::Critical, "Unable to assign attachments because the container object has not been initialized.", context); + diag.emplace_back(DiagLevel::Critical, "Unable to assign attachments because the container object has not been initialized.", + attachmentsContext); } } @@ -746,11 +746,11 @@ void setTagInfo(const SetTagInfoArgs &args) fileInfo.setSaveFilePath(currentOutputFile != noMoreOutputFiles ? string(*currentOutputFile) : string()); try { // create handler for progress updates and aborting - AbortableProgressFeedback progress(logNextStep, logStepPercentage); - const InterruptHandler handler(bind(&AbortableProgressFeedback::tryToAbort, ref(progress))); + AbortableProgressFeedback applyProgress(logNextStep, logStepPercentage); + const InterruptHandler handler(bind(&AbortableProgressFeedback::tryToAbort, ref(applyProgress))); // apply changes - fileInfo.applyChanges(diag, progress); + fileInfo.applyChanges(diag, applyProgress); // notify about completion finalizeLog(); @@ -855,7 +855,7 @@ void extractField( : outputFileArg.values().front(); try { outputFileStream.open(path, ios_base::out | ios_base::binary); - outputFileStream.write(value.first->dataPointer(), value.first->dataSize()); + outputFileStream.write(value.first->dataPointer(), static_cast(value.first->dataSize())); outputFileStream.flush(); cout << " - Value has been saved to \"" << path << "\"." << endl; } catch (const std::ios_base::failure &) { @@ -865,7 +865,7 @@ void extractField( } else { // write data to stdout if no output file has been specified for (const auto &value : values) { - cout.write(value.first->dataPointer(), value.first->dataSize()); + cout.write(value.first->dataPointer(), static_cast(value.first->dataSize())); } } } else { diff --git a/dbquery/dbquery.cpp b/dbquery/dbquery.cpp index 776e9f2..4011bd9 100644 --- a/dbquery/dbquery.cpp +++ b/dbquery/dbquery.cpp @@ -86,7 +86,7 @@ TagValue QueryResultsModel::fieldValue(int row, KnownField knownField) const case KnownField::Cover: if (!res.cover.isEmpty()) { TagValue tagValue(res.cover.data(), static_cast(res.cover.size()), TagDataType::Picture); - tagValue.setMimeType(containerMimeType(parseSignature(res.cover.data(), res.cover.size()))); + tagValue.setMimeType(containerMimeType(parseSignature(res.cover.data(), static_cast(res.cover.size())))); return tagValue; } break; diff --git a/dbquery/musicbrainz.cpp b/dbquery/musicbrainz.cpp index 2032219..87da270 100644 --- a/dbquery/musicbrainz.cpp +++ b/dbquery/musicbrainz.cpp @@ -251,14 +251,14 @@ void MusicBrainzResultsModel::parseInitialResults(const QByteArray &data) } // -> sort recordings within each release by track number and add recordings to results for (auto &releaseAndRecordings : recordingsByRelease) { - auto &recordings = releaseAndRecordings.second; - std::sort(recordings.begin(), recordings.end(), [](const auto &recording1, const auto &recording2) { + auto &recordingsOfRelease = releaseAndRecordings.second; + std::sort(recordingsOfRelease.begin(), recordingsOfRelease.end(), [](const auto &recording1, const auto &recording2) { if (recording1.disk != recording2.disk) { return recording1.disk < recording2.disk; } return recording1.track < recording2.track; }); - for (auto &recording : recordings) { + for (auto &recording : recordingsOfRelease) { m_results << move(recording); } } diff --git a/gui/attachmentsedit.cpp b/gui/attachmentsedit.cpp index 48f3b80..774ea6f 100644 --- a/gui/attachmentsedit.cpp +++ b/gui/attachmentsedit.cpp @@ -56,7 +56,7 @@ void AttachmentsEdit::setFileInfo(TagParser::MediaFileInfo *fileInfo, bool updat if (fileInfo && fileInfo->areAttachmentsSupported()) { if (AbstractContainer *container = fileInfo->container()) { auto count = container->attachmentCount(); - m_currentAttachments.reserve(count); + m_currentAttachments.reserve(static_cast(count)); for (size_t i = 0; i < count; ++i) { m_currentAttachments << container->attachment(i); } @@ -136,7 +136,7 @@ void AttachmentsEdit::extractSelected() NativeFileStream file; file.exceptions(ios_base::badbit | ios_base::failbit); try { - input.seekg(data->startOffset()); + input.seekg(static_cast(data->startOffset()), std::ios_base::beg); file.open(toNativeFileName(fileName).data(), ios_base::out | ios_base::binary); CopyHelper<0x1000> helper; helper.copy(input, file, data->size()); diff --git a/gui/attachmentsmodel.cpp b/gui/attachmentsmodel.cpp index e511293..3e8d466 100644 --- a/gui/attachmentsmodel.cpp +++ b/gui/attachmentsmodel.cpp @@ -189,6 +189,7 @@ Qt::ItemFlags AttachmentsModel::flags(const QModelIndex &index) const switch (index.column()) { case 0: flags |= Qt::ItemIsUserCheckable; + break; case 1: case 2: flags |= Qt::ItemIsEditable; diff --git a/gui/dbquerywidget.cpp b/gui/dbquerywidget.cpp index 2314105..96638c4 100644 --- a/gui/dbquerywidget.cpp +++ b/gui/dbquerywidget.cpp @@ -508,8 +508,8 @@ void DbQueryWidget::applyResults(TagEdit *tagEdit, const QModelIndex &resultInde if (row != index.row()) { return; } - if (auto *const tagEdit = m_tagEditorWidget->activeTagEdit()) { - tagEdit->setValue(KnownField::Cover, m_model->fieldValue(row, KnownField::Cover), previousValueHandling); + if (auto *const activeTagEdit = m_tagEditorWidget->activeTagEdit()) { + activeTagEdit->setValue(KnownField::Cover, m_model->fieldValue(row, KnownField::Cover), previousValueHandling); } }); break; @@ -531,8 +531,8 @@ void DbQueryWidget::applyResults(TagEdit *tagEdit, const QModelIndex &resultInde if (row != index.row()) { return; } - if (auto *const tagEdit = m_tagEditorWidget->activeTagEdit()) { - tagEdit->setValue(KnownField::Lyrics, m_model->fieldValue(row, KnownField::Lyrics), previousValueHandling); + if (auto *const activeTagEdit = m_tagEditorWidget->activeTagEdit()) { + activeTagEdit->setValue(KnownField::Lyrics, m_model->fieldValue(row, KnownField::Lyrics), previousValueHandling); } }); break; diff --git a/gui/entertargetdialog.cpp b/gui/entertargetdialog.cpp index 0f8ddf8..4ee6725 100644 --- a/gui/entertargetdialog.cpp +++ b/gui/entertargetdialog.cpp @@ -9,6 +9,7 @@ #include #include +#include #include #include @@ -89,9 +90,8 @@ EnterTargetDialog::~EnterTargetDialog() void EnterTargetDialog::updateLevelNamePlaceholderText(int i) { - const auto levelName - = i >= 0 ? tagTargetLevelName(containerTargetLevel(m_currentContainerFormat, static_cast(i))) : std::string_view(); - m_ui->levelNameLineEdit->setPlaceholderText(QString::fromUtf8(levelName.data(), levelName.size())); + m_ui->levelNameLineEdit->setPlaceholderText(qstringFromStdStringView( + i >= 0 ? tagTargetLevelName(containerTargetLevel(m_currentContainerFormat, static_cast(i))) : std::string_view())); } TagParser::TagTarget EnterTargetDialog::target() const diff --git a/gui/fileinfomodel.cpp b/gui/fileinfomodel.cpp index b2aa864..2c1423c 100644 --- a/gui/fileinfomodel.cpp +++ b/gui/fileinfomodel.cpp @@ -51,7 +51,7 @@ QStandardItem *defaultItem(const QString &text) QStandardItem *defaultItem(std::string_view text) { - return defaultItem(QString::fromUtf8(text.data(), text.size())); + return defaultItem(qstringFromStdStringView(text)); } class ItemHelper { @@ -72,7 +72,7 @@ public: void appendRow(const QString &label, std::string_view text) { if (!text.empty()) { - appendRow(label, QString::fromUtf8(text.data(), text.size())); + appendRow(label, qstringFromStdStringView(text)); } } @@ -313,10 +313,9 @@ void FileInfoModel::updateCache() QString containerName; const auto containerFormatName = m_file->containerFormatName(); if (const auto subversion = m_file->containerFormatSubversion(); !subversion.empty()) { - containerName = QString::fromUtf8(containerFormatName.data(), containerFormatName.size()) % QChar(' ') - % QString::fromUtf8(subversion.data(), subversion.size()); + containerName = qstringFromStdStringView(containerFormatName) % QChar(' ') % qstringFromStdStringView(subversion); } else { - containerName = QString::fromUtf8(containerFormatName.data(), containerFormatName.size()); + containerName = qstringFromStdStringView(containerFormatName); } setItem(currentRow, 1, defaultItem(containerName)); @@ -465,8 +464,8 @@ void FileInfoModel::updateCache() if (const auto cc = track->channelConfigString(); !cc.empty()) { const auto ecc = track->extensionChannelConfigString(); trackHelper.appendRow(tr("Channel config"), - !ecc.empty() ? QString::fromUtf8(ecc.data(), ecc.size()) % QStringLiteral(" / ") % QString::fromUtf8(cc.data(), cc.size()) - : QString::fromUtf8(cc.data(), cc.size())); + !ecc.empty() ? qstringFromStdStringView(ecc) % QStringLiteral(" / ") % qstringFromStdStringView(cc) + : qstringFromStdStringView(cc)); } else { trackHelper.appendRow(tr("Channel count"), track->channelCount()); } diff --git a/gui/mainwindow.cpp b/gui/mainwindow.cpp index 71c5e5c..32de070 100644 --- a/gui/mainwindow.cpp +++ b/gui/mainwindow.cpp @@ -452,14 +452,14 @@ void MainWindow::selectNextFile(QItemSelectionModel *selectionModel, const QMode [this, selectionModel, currentIndex, conn](const QModelIndex &parent, int, int) { disconnect(*conn); if (parent == currentIndex) { - const QModelIndex next = m_fileFilterModel->index(0, 0, parent); - if (next.isValid()) { - if (m_ui->filesTreeView->model()->hasChildren(next)) { + const QModelIndex nextFetched = m_fileFilterModel->index(0, 0, parent); + if (nextFetched.isValid()) { + if (m_ui->filesTreeView->model()->hasChildren(nextFetched)) { // next item is a directory -> keep on searching - selectNextFile(selectionModel, next, false); + selectNextFile(selectionModel, nextFetched, false); } else { m_ui->filesTreeView->selectionModel()->setCurrentIndex( - next, QItemSelectionModel::ClearAndSelect | QItemSelectionModel::Rows); + nextFetched, QItemSelectionModel::ClearAndSelect | QItemSelectionModel::Rows); } } else { selectNextFile(selectionModel, currentIndex, true); diff --git a/gui/picturepreviewselection.cpp b/gui/picturepreviewselection.cpp index 400aa7e..87d09be 100644 --- a/gui/picturepreviewselection.cpp +++ b/gui/picturepreviewselection.cpp @@ -347,11 +347,11 @@ template void pushId3v2CoverValues(TagType *tag, KnownField fiel using FieldType = typename TagType::FieldType; using TypeInfoType = typename FieldType::TypeInfoType; using IndexCompareType = typename Traits::Conditional, make_unsigned::type, TypeInfoType>; - FieldType field(id, values[index]); + auto newField = FieldType(id, values[index]); if (static_cast(index) < numeric_limits::max()) { - field.setTypeInfo(static_cast(index)); + newField.setTypeInfo(static_cast(index)); } - fields.insert(std::make_pair(id, field)); + fields.insert(std::make_pair(id, newField)); } } } @@ -422,8 +422,7 @@ void PicturePreviewSelection::addOfSelectedType(const QString &path) fileInfo.open(true); fileInfo.parseContainerFormat(diag, progress); - const auto detectedMimeType = fileInfo.mimeType(); - auto mimeType = QString::fromUtf8(detectedMimeType.data(), detectedMimeType.size()); + auto mimeType = qstringFromStdStringView(fileInfo.mimeType()); bool ok; mimeType = QInputDialog::getText( this, tr("Enter/confirm MIME type"), tr("Confirm or enter the MIME type of the selected file."), QLineEdit::Normal, mimeType, &ok); diff --git a/gui/tagedit.cpp b/gui/tagedit.cpp index c71fd90..67f0d56 100644 --- a/gui/tagedit.cpp +++ b/gui/tagedit.cpp @@ -6,6 +6,8 @@ #include +#include + #include #include @@ -199,8 +201,7 @@ QString TagEdit::generateLabel() const QStringList tagNames; tagNames.reserve(m_tags.size()); for (const Tag *const tag : m_tags) { - const auto typeName = tag->typeName(); - tagNames << QString::fromUtf8(typeName.data(), typeName.size()); + tagNames << QtUtilities::qstringFromStdStringView(tag->typeName()); if (!differentTargets && !(target == tag->target())) { differentTargets = true; } @@ -212,7 +213,7 @@ QString TagEdit::generateLabel() const if (differentTargets) { res.append(tr(" with different targets")); } else if (haveMatroskaTags || !target.isEmpty()) { - res.append(tr(" targeting %1").arg(QString::fromUtf8(m_tags.front()->targetString().c_str()))); + res.append(tr(" targeting %1").arg(QString::fromStdString(m_tags.front()->targetString()))); } return res; } diff --git a/gui/tageditorwidget.cpp b/gui/tageditorwidget.cpp index b3d642b..8a8911f 100644 --- a/gui/tageditorwidget.cpp +++ b/gui/tageditorwidget.cpp @@ -411,17 +411,18 @@ void TagEditorWidget::updateTagEditsAndAttachmentEdits(bool updateUi, PreviousVa // add/update AttachmentsEdit widget if (m_fileInfo.areAttachmentsSupported()) { - AttachmentsEdit *edit; + AttachmentsEdit *attachmentsEdit; // reuse existing edit (assigned in if-condition!) or ... - if ((widgetIndex < m_ui->stackedWidget->count()) && (edit = qobject_cast(m_ui->stackedWidget->widget(widgetIndex)))) { - edit->setFileInfo(&m_fileInfo, true); + if ((widgetIndex < m_ui->stackedWidget->count()) + && (attachmentsEdit = qobject_cast(m_ui->stackedWidget->widget(widgetIndex)))) { + attachmentsEdit->setFileInfo(&m_fileInfo, true); } else { // ... create and add a new edit - edit = new AttachmentsEdit(&m_fileInfo, this); - connect(m_ui->clearEntriesPushButton, &QPushButton::clicked, edit, &AttachmentsEdit::clear); - connect(m_ui->restoreEntriesPushButton, &QPushButton::clicked, edit, &AttachmentsEdit::restore); + attachmentsEdit = new AttachmentsEdit(&m_fileInfo, this); + connect(m_ui->clearEntriesPushButton, &QPushButton::clicked, attachmentsEdit, &AttachmentsEdit::clear); + connect(m_ui->restoreEntriesPushButton, &QPushButton::clicked, attachmentsEdit, &AttachmentsEdit::restore); //connect(edit, &AttachmentsEdit::returnPressed, this, &TagEditorWidget::handleReturnPressed); - m_ui->stackedWidget->insertWidget(widgetIndex, edit); + m_ui->stackedWidget->insertWidget(widgetIndex, attachmentsEdit); } ++widgetIndex; } diff --git a/gui/tagfieldedit.cpp b/gui/tagfieldedit.cpp index 3bc06f1..b955609 100644 --- a/gui/tagfieldedit.cpp +++ b/gui/tagfieldedit.cpp @@ -11,6 +11,7 @@ #include #include +#include #include #include #include @@ -572,9 +573,9 @@ bool TagFieldEdit::updateValue(const TagValue &value, PreviousValueHandling prev if (m_lineEdit || m_comboBox || m_plainTextEdit) { const auto text([&] { try { - const auto text(Utility::tagValueToQString(value)); - const auto correctedText = applyAutoCorrection(text); - if (correctedText != text) { + const auto textValue = Utility::tagValueToQString(value); + const auto correctedText = applyAutoCorrection(textValue); + if (correctedText != textValue) { autoCorrectionApplied = true; } return correctedText; @@ -699,17 +700,17 @@ bool TagFieldEdit::updateValue(const TagValue &value, PreviousValueHandling prev } const auto pixmap(QIcon::fromTheme(QStringLiteral("emblem-error")).pixmap(16)); const auto text([&] { - QString text; + QString textValue; if (conversionError) { - text = tr("The value of this field could not be read from the file because it couldn't be converted properly."); + textValue = tr("The value of this field could not be read from the file because it couldn't be converted properly."); if (!canApplyField) { - text += QChar('\n'); + textValue += QChar('\n'); } } if (!canApplyField) { - text += tr("The field can not be applied when saving the file and will be lost."); + textValue += tr("The field can not be applied when saving the file and will be lost."); } - return text; + return textValue; }()); for (auto *const overlay : widgets) { if (overlay) { @@ -919,9 +920,7 @@ void TagFieldEdit::handleRestoreButtonClicked() QMenu menu; int i = 0; for (auto *const tag : tags()) { - const auto typeName = tag->typeName(); - const auto *const action - = menu.addAction(tr("restore to value from %1 (%2)").arg(QString::fromUtf8(typeName.data(), typeName.size())).arg(++i)); + const auto *const action = menu.addAction(tr("restore to value from %1 (%2)").arg(qstringFromStdStringView(tag->typeName())).arg(++i)); connect(action, &QAction::triggered, [this, tag] { setLocked(false); updateValue(tag, PreviousValueHandling::Clear); diff --git a/misc/htmlinfo.cpp b/misc/htmlinfo.cpp index 8f4beba..bba5dd2 100644 --- a/misc/htmlinfo.cpp +++ b/misc/htmlinfo.cpp @@ -13,6 +13,7 @@ #include #include +#include #include #include @@ -276,7 +277,7 @@ template <> void mkElementContent(QXmlStreamWriter &writer, EbmlElement *element const auto seekIdName = matroskaIdName(static_cast(seekId)); if (!seekIdName.empty()) { writer.writeCharacters(QStringLiteral(" \"")); - writer.writeCharacters(QString::fromLatin1(seekIdName.data(), seekIdName.size())); + writer.writeCharacters(qstringFromStdStringView(seekIdName)); writer.writeCharacters(QStringLiteral("\"")); } } @@ -962,7 +963,7 @@ public: rowMaker.mkRow(QCoreApplication::translate("HtmlInfo", "Padding size"), QStringLiteral("%1 (%2 %)") .arg(qstr(dataSizeToString(m_file.paddingSize(), true))) - .arg(static_cast(m_file.paddingSize()) / m_file.size() * 100.0, 0, 'g', 2)); + .arg(static_cast(m_file.paddingSize()) / static_cast(m_file.size()) * 100.0, 0, 'g', 2)); } m_writer.writeEndElement(); diff --git a/misc/utility.cpp b/misc/utility.cpp index 05c0c53..15d587e 100644 --- a/misc/utility.cpp +++ b/misc/utility.cpp @@ -124,8 +124,8 @@ string qstringToString(const QString &value, TagTextEncoding textEncoding) #else case TagTextEncoding::Utf16BigEndian: #endif - encodedString = QByteArray( - reinterpret_cast(value.utf16()), static_cast(value.size() * static_cast(sizeof(ushort) / sizeof(char)))); + encodedString = QByteArray(reinterpret_cast(value.utf16()), + static_cast(value.size()) * static_cast(sizeof(ushort) / sizeof(char))); break; #if defined(CONVERSION_UTILITIES_BYTE_ORDER_LITTLE_ENDIAN) case TagTextEncoding::Utf16BigEndian: { @@ -139,7 +139,7 @@ string qstringToString(const QString &value, TagTextEncoding textEncoding) "UTF-16BE", #endif textEncodingToCodecName(textEncoding), reinterpret_cast(value.utf16()), - static_cast(value.size() * static_cast(sizeof(ushort) / sizeof(char))), 2.0f); + static_cast(value.size()) * (sizeof(ushort) / sizeof(char)), 2.0f); return string(utf16Data.first.get(), utf16Data.second); } } @@ -243,9 +243,9 @@ void parseFileName(const QString &fileName, QString &title, int &trackNumber) trackNumber = QtUtilities::midRef(title, lastDelimIndex, delimIndex - lastDelimIndex).toInt(&ok); if (ok) { int titleStart = delimIndex + delim.size(); - for (const auto &delim : delims) { - if (QtUtilities::midRef(title, titleStart).startsWith(delim)) { - titleStart += delim.size(); + for (const auto &delim2 : delims) { + if (QtUtilities::midRef(title, titleStart).startsWith(delim2)) { + titleStart += delim2.size(); break; } }