Skip to content

Commit

Permalink
Disable automatic conversions from 8-bit strings
Browse files Browse the repository at this point in the history
  • Loading branch information
jonaski committed Apr 11, 2024
1 parent 5894499 commit 49e0594
Show file tree
Hide file tree
Showing 281 changed files with 2,321 additions and 2,121 deletions.
7 changes: 7 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -508,8 +508,15 @@ add_definitions(
-DQT_NO_CAST_TO_ASCII
-DQT_NO_NARROWING_CONVERSIONS_IN_CONNECT
-DQT_NO_FOREACH
-DQT_ASCII_CAST_WARNINGS
)

if(BUILD_WITH_QT6)
add_definitions("-DQT_NO_CAST_FROM_ASCII")
else()
add_definitions("-DQT_RESTRICTED_CAST_FROM_ASCII")
endif()

if(WIN32)
add_definitions(-DUNICODE)
if(MSVC)
Expand Down
34 changes: 17 additions & 17 deletions ext/libstrawberry-common/core/logging.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ static QIODevice *sNullDevice = nullptr;

const char *kDefaultLogLevels = "*:3";

static const char *kMessageHandlerMagic = "__logging_message__";
static const size_t kMessageHandlerMagicLength = strlen(kMessageHandlerMagic);
static constexpr char kMessageHandlerMagic[] = "__logging_message__";
static const size_t kMessageHandlerMagicLen = strlen(kMessageHandlerMagic);
static QtMessageHandler sOriginalMessageHandler = nullptr;

template<class T>
Expand Down Expand Up @@ -135,9 +135,9 @@ class LoggedDebug : public DebugBase<LoggedDebug> {

static void MessageHandler(QtMsgType type, const QMessageLogContext&, const QString &message) {

if (message.startsWith(kMessageHandlerMagic)) {
if (message.startsWith(QLatin1String(kMessageHandlerMagic))) {
QByteArray message_data = message.toUtf8();
fprintf(type == QtCriticalMsg || type == QtFatalMsg ? stderr : stdout, "%s\n", message_data.constData() + kMessageHandlerMagicLength);
fprintf(type == QtCriticalMsg || type == QtFatalMsg ? stderr : stdout, "%s\n", message_data.constData() + kMessageHandlerMagicLen);
fflush(type == QtCriticalMsg || type == QtFatalMsg ? stderr : stdout);
return;
}
Expand All @@ -157,7 +157,7 @@ static void MessageHandler(QtMsgType type, const QMessageLogContext&, const QStr
break;
}

for (const QString &line : message.split('\n')) {
for (const QString &line : message.split(QLatin1Char('\n'))) {
BufferedDebug d = CreateLogger<BufferedDebug>(level, QStringLiteral("unknown"), -1, nullptr);
d << line.toLocal8Bit().constData();
if (d.buf_) {
Expand Down Expand Up @@ -193,8 +193,8 @@ void SetLevels(const QString &levels) {

if (!sClassLevels) return;

for (const QString &item : levels.split(',')) {
const QStringList class_level = item.split(':');
for (const QString &item : levels.split(QLatin1Char(','))) {
const QStringList class_level = item.split(QLatin1Char(':'));

QString class_name;
bool ok = false;
Expand All @@ -212,7 +212,7 @@ void SetLevels(const QString &levels) {
continue;
}

if (class_name.isEmpty() || class_name == "*") {
if (class_name.isEmpty() || class_name == QStringLiteral("*")) {
sDefaultLevel = static_cast<Level>(level);
}
else {
Expand All @@ -225,8 +225,8 @@ void SetLevels(const QString &levels) {
static QString ParsePrettyFunction(const char *pretty_function) {

// Get the class name out of the function name.
QString class_name = pretty_function;
const qint64 paren = class_name.indexOf('(');
QString class_name = QLatin1String(pretty_function);
const qint64 paren = class_name.indexOf(QLatin1Char('('));
if (paren != -1) {
const qint64 colons = class_name.lastIndexOf(QLatin1String("::"), paren);
if (colons != -1) {
Expand All @@ -237,7 +237,7 @@ static QString ParsePrettyFunction(const char *pretty_function) {
}
}

const qint64 space = class_name.lastIndexOf(' ');
const qint64 space = class_name.lastIndexOf(QLatin1Char(' '));
if (space != -1) {
class_name = class_name.mid(space + 1);
}
Expand All @@ -259,7 +259,7 @@ static T CreateLogger(Level level, const QString &class_name, int line, const ch
case Level_Fatal: level_name = " FATAL "; break;
}

QString filter_category = (category != nullptr) ? category : class_name;
QString filter_category = (category != nullptr) ? QLatin1String(category) : class_name;
// Check the settings to see if we're meant to show or hide this message.
Level threshold_level = sDefaultLevel;
if (sClassLevels && sClassLevels->contains(filter_category)) {
Expand All @@ -272,10 +272,10 @@ static T CreateLogger(Level level, const QString &class_name, int line, const ch

QString function_line = class_name;
if (line != -1) {
function_line += ":" + QString::number(line);
function_line += QStringLiteral(":") + QString::number(line);
}
if (category) {
function_line += "(" + QString(category) + ")";
function_line += QStringLiteral("(") + QLatin1String(category) + QStringLiteral(")");
}

QtMsgType type = QtDebugMsg;
Expand Down Expand Up @@ -326,9 +326,9 @@ QString DarwinDemangle(const QString &symbol);
QString DarwinDemangle(const QString &symbol) {

# if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)
QStringList split = symbol.split(' ', Qt::SkipEmptyParts);
QStringList split = symbol.split(QLatin1Char(' '), Qt::SkipEmptyParts);
# else
QStringList split = symbol.split(' ', QString::SkipEmptyParts);
QStringList split = symbol.split(QLatin1Char(' '), QString::SkipEmptyParts);
# endif
QString mangled_function = split[3];
return CXXDemangle(mangled_function);
Expand Down Expand Up @@ -392,7 +392,7 @@ namespace {

template<typename T>
QString print_duration(T duration, const std::string &unit) {
return QStringLiteral("%1%2").arg(duration.count()).arg(unit.c_str());
return QStringLiteral("%1%2").arg(duration.count()).arg(QString::fromStdString(unit));
}

} // namespace
Expand Down
4 changes: 2 additions & 2 deletions ext/libstrawberry-common/core/workerpool.h
Original file line number Diff line number Diff line change
Expand Up @@ -247,11 +247,11 @@ void WorkerPool<HandlerType>::DoStart() {
search_path << QStringLiteral("/usr/local/libexec");
#endif
#if defined(Q_OS_MACOS)
search_path << QDir::cleanPath(QCoreApplication::applicationDirPath() + "/../PlugIns");
search_path << QDir::cleanPath(QCoreApplication::applicationDirPath() + QStringLiteral("/../PlugIns"));
#endif

for (const QString &path_prefix : search_path) {
const QString executable_path = path_prefix + "/" + executable_name_;
const QString executable_path = path_prefix + QLatin1Char('/') + executable_name_;
if (QFile::exists(executable_path)) {
executable_path_ = executable_path;
qLog(Debug) << "Using worker" << executable_name_ << "from" << path_prefix;
Expand Down
14 changes: 9 additions & 5 deletions ext/libstrawberry-tagreader/tagreaderbase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ TagReaderBase::Cover TagReaderBase::LoadCoverFromRequest(const spb::tagreader::S
}
QString cover_mime_type;
if (request.has_cover_mime_type()) {
cover_mime_type = QByteArray(request.cover_mime_type().data(), static_cast<qint64>(request.cover_mime_type().size()));
cover_mime_type = QString::fromStdString(request.cover_mime_type());
}

return LoadCoverFromRequest(song_filename, cover_filename, cover_data, cover_mime_type);
Expand All @@ -94,7 +94,7 @@ TagReaderBase::Cover TagReaderBase::LoadCoverFromRequest(const spb::tagreader::S
}
QString cover_mime_type;
if (request.has_cover_mime_type()) {
cover_mime_type = QByteArray(request.cover_mime_type().data(), static_cast<qint64>(request.cover_mime_type().size()));
cover_mime_type = QString::fromStdString(request.cover_mime_type());
}

return LoadCoverFromRequest(song_filename, cover_filename, cover_data, cover_mime_type);
Expand All @@ -118,17 +118,21 @@ TagReaderBase::Cover TagReaderBase::LoadCoverFromRequest(const QString &song_fil
if (cover_mime_type.isEmpty()) {
cover_mime_type = QMimeDatabase().mimeTypeForData(cover_data).name();
}
if (cover_mime_type == "image/jpeg") {
if (cover_mime_type == QStringLiteral("image/jpeg")) {
qLog(Debug) << "Using cover from JPEG data for" << song_filename;
return Cover(cover_data, cover_mime_type);
}
if (cover_mime_type == "image/png") {
if (cover_mime_type == QStringLiteral("image/png")) {
qLog(Debug) << "Using cover from PNG data for" << song_filename;
return Cover(cover_data, cover_mime_type);
}
// Convert image to JPEG.
qLog(Debug) << "Converting cover to JPEG data for" << song_filename;
QImage cover_image(cover_data);
QImage cover_image;
if (!cover_image.loadFromData(cover_data)) {
qLog(Error) << "Failed to load image from cover data for" << song_filename;
return Cover();
}
cover_data.clear();
QBuffer buffer(&cover_data);
if (buffer.open(QIODevice::WriteOnly)) {
Expand Down
2 changes: 1 addition & 1 deletion ext/libstrawberry-tagreader/tagreadergme.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ void GME::VGM::Read(const QFileInfo &file_info, spb::tagreader::SongMetadata *so
#else
fileTagStream.setCodec("UTF-16");
#endif
QStringList strings = fileTagStream.readLine(0).split(QChar('\0'));
QStringList strings = fileTagStream.readLine(0).split(QLatin1Char('\0'));
if (strings.count() < 10) return;

// VGM standard dictates string tag data exist in specific order.
Expand Down
8 changes: 4 additions & 4 deletions ext/libstrawberry-tagreader/tagreadertaglib.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ bool TagReaderTagLib::ReadFile(const QString &filename, spb::tagreader::SongMeta
for (uint i = 0; i < map["COMM"].size(); ++i) {
const TagLib::ID3v2::CommentsFrame *frame = dynamic_cast<const TagLib::ID3v2::CommentsFrame*>(map["COMM"][i]);

if (frame && TStringToQString(frame->description()) != "iTunNORM") {
if (frame && TStringToQString(frame->description()) != QStringLiteral("iTunNORM")) {
TStringToStdString(frame->text(), song->mutable_comment());
break;
}
Expand Down Expand Up @@ -663,7 +663,7 @@ bool TagReaderTagLib::ReadFile(const QString &filename, spb::tagreader::SongMeta
}

if (!disc.isEmpty()) {
const qint64 i = disc.indexOf('/');
const qint64 i = disc.indexOf(QLatin1Char('/'));
if (i != -1) {
// disc.right( i ).toInt() is total number of discs, we don't use this at the moment
song->set_disc(disc.left(i).toInt());
Expand Down Expand Up @@ -1311,10 +1311,10 @@ void TagReaderTagLib::SetEmbeddedArt(TagLib::MP4::File *aac_file, TagLib::MP4::T
}
else {
TagLib::MP4::CoverArt::Format cover_format = TagLib::MP4::CoverArt::Format::JPEG;
if (mime_type == "image/jpeg") {
if (mime_type == QStringLiteral("image/jpeg")) {
cover_format = TagLib::MP4::CoverArt::Format::JPEG;
}
else if (mime_type == "image/png") {
else if (mime_type == QStringLiteral("image/png")) {
cover_format = TagLib::MP4::CoverArt::Format::PNG;
}
else {
Expand Down
2 changes: 2 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ set(SOURCES
core/networktimeouts.cpp
core/networkproxyfactory.cpp
core/qtfslistener.cpp
core/settings.cpp
core/settingsprovider.cpp
core/signalchecker.cpp
core/song.cpp
Expand Down Expand Up @@ -307,6 +308,7 @@ set(HEADERS
core/threadsafenetworkdiskcache.h
core/networktimeouts.h
core/qtfslistener.h
core/settings.h
core/songloader.h
core/tagreaderclient.h
core/taskmanager.h
Expand Down
13 changes: 7 additions & 6 deletions src/analyzer/analyzercontainer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@

#include "core/logging.h"
#include "core/shared_ptr.h"
#include "core/settings.h"
#include "engine/enginebase.h"

using namespace std::chrono_literals;
Expand Down Expand Up @@ -178,9 +179,9 @@ void AnalyzerContainer::ChangeFramerate(int new_framerate) {

void AnalyzerContainer::Load() {

QSettings s;
Settings s;
s.beginGroup(kSettingsGroup);
QString type = s.value("type", "BlockAnalyzer").toString();
QString type = s.value("type", QStringLiteral("BlockAnalyzer")).toString();
current_framerate_ = s.value(kSettingsFramerate, kMediumFramerate).toInt();
s.endGroup();

Expand All @@ -191,7 +192,7 @@ void AnalyzerContainer::Load() {
}
else {
for (int i = 0; i < analyzer_types_.count(); ++i) {
if (type == analyzer_types_[i]->className()) {
if (type == QString::fromUtf8(analyzer_types_[i]->className())) {
ChangeAnalyzer(i);
actions_[i]->setChecked(true);
break;
Expand All @@ -215,7 +216,7 @@ void AnalyzerContainer::SaveFramerate(const int framerate) {

// For now, framerate is common for all analyzers. Maybe each analyzer should have its own framerate?
current_framerate_ = framerate;
QSettings s;
Settings s;
s.beginGroup(kSettingsGroup);
s.setValue(kSettingsFramerate, current_framerate_);
s.endGroup();
Expand All @@ -224,9 +225,9 @@ void AnalyzerContainer::SaveFramerate(const int framerate) {

void AnalyzerContainer::Save() {

QSettings s;
Settings s;
s.beginGroup(kSettingsGroup);
s.setValue("type", current_analyzer_ ? current_analyzer_->metaObject()->className() : QVariant());
s.setValue("type", current_analyzer_ ? QString::fromUtf8(current_analyzer_->metaObject()->className()) : QVariant());
s.endGroup();

}
Expand Down
5 changes: 3 additions & 2 deletions src/collection/collection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
#include "core/thread.h"
#include "core/song.h"
#include "core/logging.h"
#include "core/settings.h"
#include "utilities/threadutils.h"
#include "collection.h"
#include "collectionwatcher.h"
Expand Down Expand Up @@ -69,7 +70,7 @@ SCollection::SCollection(Application *app, QObject *parent)
backend()->moveToThread(app->database()->thread());
qLog(Debug) << &*backend_ << "moved to thread" << app->database()->thread();

backend_->Init(app->database(), app->task_manager(), Song::Source::Collection, kSongsTable, kFtsTable, kDirsTable, kSubdirsTable);
backend_->Init(app->database(), app->task_manager(), Song::Source::Collection, QLatin1String(kSongsTable), QLatin1String(kFtsTable), QLatin1String(kDirsTable), QLatin1String(kSubdirsTable));

model_ = new CollectionModel(backend_, app_, this);

Expand Down Expand Up @@ -179,7 +180,7 @@ void SCollection::ReloadSettings() {
watcher_->ReloadSettingsAsync();
model_->ReloadSettings();

QSettings s;
Settings s;
s.beginGroup(CollectionSettingsPage::kSettingsGroup);
save_playcounts_to_files_ = s.value("save_playcounts", false).toBool();
save_ratings_to_files_ = s.value("save_ratings", false).toBool();
Expand Down
Loading

0 comments on commit 49e0594

Please sign in to comment.