rbutil: Eliminate more pre-QT6 workarounds

Change-Id: I7b5cf428ef626543aa8e932622f4658e789e9236
This commit is contained in:
Solomon Peachy 2026-06-26 21:29:33 -04:00
parent 202243a1ab
commit 3c41d6a1c1
14 changed files with 9 additions and 118 deletions

View file

@ -49,9 +49,15 @@ find_package(QT NAMES Qt6 REQUIRED)
find_package(Qt6 REQUIRED COMPONENTS
Core Core5Compat Widgets Svg Network LinguistTools SvgWidgets
OPTIONAL_COMPONENTS Multimedia Test)
## note Core5Compat is only used for QuaZip
get_target_property(_moc_executable Qt${QT_VERSION_MAJOR}::moc IMPORTED_LOCATION)
get_filename_component(QT_BINDIR "${_moc_executable}" DIRECTORY)
message("-- Found Qt${QT_VERSION_MAJOR}: ${Qt${QT_VERSION_MAJOR}_DIR}")
if (TARGET Qt${QT_VERSION_MAJOR}::Multimedia)
message("-- Found Qt::Multimedia")
else()
message("-- QT::Multimedia not found, TTS preview not available")
endif()
# Added in QT 6.10
add_compile_options(-DQT_NO_USE_NODISCARD_FILE_OPEN)
@ -107,9 +113,7 @@ else()
${CMAKE_CURRENT_LIST_DIR}/rbutilqt/quazip/zip.h)
target_include_directories(quazip PUBLIC ${CMAKE_CURRENT_LIST_DIR}/rbutilqt/quazip)
target_link_libraries(quazip z Qt${QT_VERSION_MAJOR}::Core)
if(QT_VERSION_MAJOR EQUAL 6)
target_link_libraries(quazip Qt${QT_VERSION_MAJOR}::Core5Compat)
endif()
target_link_libraries(quazip Qt${QT_VERSION_MAJOR}::Core5Compat)
target_compile_definitions(quazip PUBLIC QUAZIP_STATIC)
set_property(TARGET quazip PROPERTY AUTOMOC ON)
set(QUAZIP_LIBRARY quazip)

View file

@ -32,11 +32,7 @@ set(RBUTIL_TS_FILES
${CMAKE_CURRENT_LIST_DIR}/lang/rbutil_zh_CN.ts
${CMAKE_CURRENT_LIST_DIR}/lang/rbutil_zh_TW.ts
)
if(QT_VERSION_MAJOR EQUAL 5)
qt5_add_translation(RBUTIL_QM_FILES ${RBUTIL_TS_FILES})
else()
qt6_add_translation(RBUTIL_QM_FILES ${RBUTIL_TS_FILES})
endif()
# The qrc file searches input files based on its location, and the qm files are
# generated in the build dir. Copy the qrc file to the build dir, make it
@ -112,10 +108,6 @@ if(WIN32)
target_sources(RockboxUtility PRIVATE
${CMAKE_CURRENT_LIST_DIR}/rbutilqt-win.qrc
${CMAKE_CURRENT_LIST_DIR}/rbutilqt.rc)
if(QT_VERSION_MAJOR EQUAL 5)
# needed on Windows, otherwise svg icons won't show.
target_link_libraries(RockboxUtility Qt${QT_VERSION_MAJOR}::QSvgIconPlugin)
endif()
endif()
if(APPLE)
# MacOS Application Bundle specifics.
@ -136,9 +128,7 @@ if (TARGET Qt${QT_VERSION_MAJOR}::Multimedia) # optional
Qt${QT_VERSION_MAJOR}::Multimedia)
endif()
if(QT_VERSION_MAJOR EQUAL 6)
target_link_libraries(RockboxUtility Qt${QT_VERSION_MAJOR}::SvgWidgets)
endif()
target_link_libraries(RockboxUtility Qt${QT_VERSION_MAJOR}::SvgWidgets)
target_include_directories(RockboxUtility PRIVATE
${CMAKE_CURRENT_LIST_DIR}/gui

View file

@ -160,13 +160,7 @@ void HttpGet::requestFinished(QNetworkReply* reply)
QUrl url = QUrl(org).resolved(
reply->attribute(QNetworkRequest::RedirectionTargetAttribute).toUrl());
// reconstruct query
#if QT_VERSION < 0x050000
QList<QPair<QByteArray, QByteArray> > qitms = org.encodedQueryItems();
for(int i = 0; i < qitms.size(); ++i)
url.addEncodedQueryItem(qitms.at(i).first, qitms.at(i).second);
#else
url.setQuery(org.query());
#endif
LOG_INFO() << "Redirected to" << url;
startRequest(url);
return;
@ -205,13 +199,7 @@ void HttpGet::startRequest(QUrl url)
req.setRawHeader("User-Agent", m_globalUserAgent.toLatin1());
m_reply = m_mgr.get(req);
#if QT_VERSION < 0x050f00
connect(m_reply,
static_cast<void (QNetworkReply::*)(QNetworkReply::NetworkError)>(&QNetworkReply::error),
this, &HttpGet::networkError);
#else
connect(m_reply, &QNetworkReply::errorOccurred, this, &HttpGet::networkError);
#endif
connect(m_reply, &QNetworkReply::downloadProgress, this, &HttpGet::downloadProgress);
connect(m_reply, &QNetworkReply::sslErrors, this, &HttpGet::gotSslError);
}
@ -276,4 +264,3 @@ int HttpGet::httpResponse(void)
{
return m_lastStatusCode;
}

View file

@ -97,10 +97,7 @@ PlayerBuildInfo::PlayerBuildInfo() :
serverInfo(nullptr),
playerInfo(":/ini/rbutil.ini", QSettings::IniFormat)
{
#if QT_VERSION < 0x060000
playerInfo.setIniCodec("UTF-8");
#endif
// Nothing to do here.
}
void PlayerBuildInfo::setBuildInfo(QString file)
@ -199,11 +196,7 @@ QVariant PlayerBuildInfo::value(BuildInfo item, BuildType type)
// if the value is a string we can replace some patterns.
// if we cannot convert it (f.e. for a QStringList) we leave as-is, since
// the conversion would return an empty type.
#if QT_VERSION < 0x060000
if (result.type() == QVariant::String)
#else
if (result.metaType().id() == QMetaType::QString)
#endif
result = result.toString()
.replace("%TARGET%", target)
.replace("%VERSION%", version.at(0));

View file

@ -295,11 +295,7 @@ QString TTSFestival::getVoiceInfo(QString voice)
QRegularExpression::CaseInsensitiveOption));
LOG_INFO() << "voiceInfo w/o descr:" << response;
response = response.remove(')');
#if QT_VERSION >= 0x050e00
QStringList responseLines = response.split('(', Qt::SkipEmptyParts);
#else
QStringList responseLines = response.split('(', QString::SkipEmptyParts);
#endif
responseLines.removeAt(0); // the voice name itself
QString description;
@ -417,4 +413,3 @@ QString TTSFestival::queryServer(QString query, int timeout)
return response.trimmed();
}

View file

@ -140,11 +140,7 @@ bool TTSSapi::start(QString *errStr)
}
voicestream = new QTextStream(voicescript);
#if QT_VERSION < 0x060000
voicestream->setCodec("UTF16-LE");
#else
voicestream->setEncoding(QStringConverter::Utf16LE);
#endif
m_started = true;
return true;
@ -201,11 +197,7 @@ QStringList TTSSapi::getVoiceList(QString language)
if(dataRaw.startsWith("Error")) {
LOG_INFO() << "Error:" << dataRaw;
}
#if QT_VERSION >= 0x050e00
result = dataRaw.split(";", Qt::SkipEmptyParts);
#else
result = dataRaw.split(";", QString::SkipEmptyParts);
#endif
if(result.size() > 0)
{
result.sort();
@ -271,4 +263,3 @@ bool TTSSapi::configOk()
return false;
return true;
}

View file

@ -93,11 +93,7 @@ QString Utils::resolvePathCase(QString path)
{
int start;
QString realpath;
#if QT_VERSION >= 0x050e00
QStringList elems = path.split("/", Qt::SkipEmptyParts);
#else
QStringList elems = path.split("/", QString::SkipEmptyParts);
#endif
if(path.isEmpty())
return QString();
@ -321,17 +317,9 @@ QString Utils::findExecutable(QString name)
{
//try autodetect tts
#if defined(Q_OS_LINUX) || defined(Q_OS_MACX) || defined(Q_OS_OPENBSD)
#if QT_VERSION >= 0x050e00
QStringList path = QString(getenv("PATH")).split(":", Qt::SkipEmptyParts);
#else
QStringList path = QString(getenv("PATH")).split(":", QString::SkipEmptyParts);
#endif
#elif defined(Q_OS_WIN)
#if QT_VERSION >= 0x050e00
QStringList path = QString(getenv("PATH")).split(";", Qt::SkipEmptyParts);
#else
QStringList path = QString(getenv("PATH")).split(";", QString::SkipEmptyParts);
#endif
#endif
LOG_INFO() << "system path:" << path;
for(int i = 0; i < path.size(); i++)
@ -339,11 +327,7 @@ QString Utils::findExecutable(QString name)
QString executable = QDir::fromNativeSeparators(path.at(i)) + "/" + name;
#if defined(Q_OS_WIN)
executable += ".exe";
#if QT_VERSION >= 0x050e00
QStringList ex = executable.split("\"", Qt::SkipEmptyParts);
#else
QStringList ex = executable.split("\"", QString::SkipEmptyParts);
#endif
executable = ex.join("");
#endif
if(QFileInfo(executable).isExecutable())

View file

@ -267,11 +267,7 @@ void VoiceFileCreator::create(void)
//read in downloaded file
emit logItem(tr("Reading strings..."),LOGINFO);
QTextStream in(&genlang);
#if QT_VERSION < 0x060000
in.setCodec("UTF-8");
#else
in.setEncoding(QStringConverter::Utf8);
#endif
QString id, voice;
bool idfound = false;
bool voicefound=false;

View file

@ -45,11 +45,7 @@ QString Changelog::parseChangelogFile(QString filename)
QFile changelog(filename);
changelog.open(QIODevice::ReadOnly);
QTextStream c(&changelog);
#if QT_VERSION < 0x060000
c.setCodec(QTextCodec::codecForName("UTF-8"));
#else
c.setEncoding(QStringConverter::Utf8);
#endif
QString text;
while(!c.atEnd()) {
QString line = c.readLine();

View file

@ -110,11 +110,7 @@ void InstallTalkWindow::accept()
talkcreator->setStripExtensions(ui.StripExtensions->isChecked());
talkcreator->setTalkFolders(ui.talkFolders->isChecked());
talkcreator->setTalkFiles(ui.talkFiles->isChecked());
#if QT_VERSION >= 0x050e00
talkcreator->setIgnoreFiles(ui.ignoreFiles->text().split(",", Qt::SkipEmptyParts));
#else
talkcreator->setIgnoreFiles(ui.ignoreFiles->text().split(",", QString::SkipEmptyParts));
#endif
connect(talkcreator, &TalkFileCreator::done, logger, &ProgressLoggerGui::setFinished);
connect(talkcreator, &TalkFileCreator::logItem, logger, &ProgressLoggerGui::addItem);
@ -185,4 +181,3 @@ void InstallTalkWindow::changeEvent(QEvent *e)
QWidget::changeEvent(e);
}
}

View file

@ -26,23 +26,7 @@
#include "ConsoleAppender.h"
#include "FileAppender.h"
#ifdef STATIC
#if QT_VERSION < 0x050400
/*
* accessibility is no longer a plugin after 5.4.0:
* <https://bugreports.qt.io/browse/QTBUG-37957#comment-239189>
*/
#include <QtPlugin>
Q_IMPORT_PLUGIN(AccessibleFactory)
#endif
#endif
int main( int argc, char ** argv ) {
#if QT_VERSION >= 0x050600 && QT_VERSION < 0x060000
QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
QCoreApplication::setAttribute(Qt::AA_UseHighDpiPixmaps);
#endif
QApplication app( argc, argv );
#ifdef Q_OS_WIN
qApp->setStyle(QStyleFactory::create("Fusion"));
@ -83,11 +67,7 @@ int main( int argc, char ** argv ) {
if(!translator.load("rbutil_" + applang, absolutePath))
translator.load("rbutil_" + applang, ":/lang");
if(!qttrans.load("qt_" + applang,
#if QT_VERSION >= 0x060000
QLibraryInfo::path(QLibraryInfo::TranslationsPath)
#else
QLibraryInfo::location(QLibraryInfo::TranslationsPath)
#endif
))
qttrans.load("qt_" + applang, ":/lang");

View file

@ -334,11 +334,7 @@ void RbUtilQt::about()
QFile credits(":/docs/CREDITS");
credits.open(QIODevice::ReadOnly);
QTextStream r(&credits);
#if QT_VERSION < 0x060000
r.setCodec(QTextCodec::codecForName("UTF-8"));
#else
r.setEncoding(QStringConverter::Utf8);
#endif
while(!r.atEnd()) {
QString line = r.readLine();
// filter out header.

View file

@ -39,12 +39,8 @@
quint16 port(void) { return this->serverPort(); }
#if QT_VERSION < 0x050000
void incomingConnection(int socket)
#else
// Qt 5 uses a different prototype for this function!
void incomingConnection(qintptr socket)
#endif
{
// When a new client connects, the server constructs a QTcpSocket and all
// communication with the client is done over this QTcpSocket. QTcpSocket
@ -549,4 +545,3 @@ QTEST_MAIN(TestHttpGet)
// this include is needed because we don't use a separate header file for the
// test class. It also needs to be at the end.
#include "test-httpget.moc"

View file

@ -114,9 +114,6 @@ void ThemesInstallWindow::downloadDone(QNetworkReply::NetworkError error)
themesInfo.open();
QSettings iniDetails(themesInfo.fileName(), QSettings::IniFormat, this);
#if QT_VERSION < 0x060000
iniDetails.setIniCodec(QTextCodec::codecForName("UTF-8"));
#endif
QStringList tl = iniDetails.childGroups();
LOG_INFO() << "Theme site result:"
<< iniDetails.value("error/code").toString()
@ -190,9 +187,6 @@ void ThemesInstallWindow::updateSize(void)
long size = 0;
// sum up size for all selected themes
QSettings iniDetails(themesInfo.fileName(), QSettings::IniFormat, this);
#if QT_VERSION < 0x060000
iniDetails.setIniCodec(QTextCodec::codecForName("UTF-8"));
#endif
int items = ui.listThemes->selectedItems().size();
for(int i = 0; i < items; i++) {
iniDetails.beginGroup(ui.listThemes->selectedItems()
@ -211,10 +205,6 @@ void ThemesInstallWindow::updateDetails(QListWidgetItem* cur, QListWidgetItem* p
return;
QSettings iniDetails(themesInfo.fileName(), QSettings::IniFormat, this);
#if QT_VERSION < 0x060000
iniDetails.setIniCodec(QTextCodec::codecForName("UTF-8"));
#endif
QCoreApplication::processEvents();
ui.themeDescription->setText(tr("fetching details for %1")
.arg(cur->data(Qt::DisplayRole).toString()));
@ -393,4 +383,3 @@ void ThemesInstallWindow::changeEvent(QEvent *e)
QWidget::changeEvent(e);
}
}