aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorAndrii Semkiv <[email protected]>2024-09-02 17:16:12 +0200
committerandrii.semkiv <[email protected]>2024-09-06 07:24:48 +0000
commitf7a230a5b69f45a16192060278f35f5605e8f480 (patch)
treefe9f00a0cd8a2252dd53f2d9ff19fb13ecacfee0 /src
parent88f8d5c5e090663c03f3cb7e7e6b9d28dc5d5c3e (diff)
Android: Replace occurrences of FilePath::toString
Use FilePath capabilities instead of QFile/QDir where applicable. More informative error messages. Add a helper function in androidconfigurations.cpp to reduce amount of repeated code. Change-Id: I02457461713caf8355601af34679fb6c2f4090a7 Reviewed-by: Alessandro Portale <[email protected]>
Diffstat (limited to 'src')
-rw-r--r--src/plugins/android/androidbuildapkstep.cpp24
-rw-r--r--src/plugins/android/androidconfigurations.cpp131
-rw-r--r--src/plugins/android/androidcreatekeystorecertificate.cpp4
-rw-r--r--src/plugins/android/androiddeployqtstep.cpp10
-rw-r--r--src/plugins/android/androiddevice.cpp4
-rw-r--r--src/plugins/android/androidmanager.cpp36
-rw-r--r--src/plugins/android/androidmanifesteditoriconwidget.cpp8
-rw-r--r--src/plugins/android/androidpackageinstallationstep.cpp2
-rw-r--r--src/plugins/android/androidrunnerworker.cpp4
-rw-r--r--src/plugins/android/androidsdkdownloader.cpp15
-rw-r--r--src/plugins/android/androidsdkmanager.cpp2
-rw-r--r--src/plugins/android/androidsdkmanagerdialog.cpp5
-rw-r--r--src/plugins/android/androidsettingswidget.cpp16
-rw-r--r--src/plugins/android/androidtoolchain.cpp2
-rw-r--r--src/plugins/android/avdmanageroutputparser.cpp6
-rw-r--r--src/plugins/android/createandroidmanifestwizard.cpp6
-rw-r--r--src/plugins/android/javalanguageserver.cpp14
-rw-r--r--src/plugins/android/javaparser.cpp4
-rw-r--r--src/plugins/android/splashscreencontainerwidget.cpp32
19 files changed, 176 insertions, 149 deletions
diff --git a/src/plugins/android/androidbuildapkstep.cpp b/src/plugins/android/androidbuildapkstep.cpp
index 8a21d17b84f..8ed611b19c4 100644
--- a/src/plugins/android/androidbuildapkstep.cpp
+++ b/src/plugins/android/androidbuildapkstep.cpp
@@ -413,10 +413,10 @@ bool AndroidBuildApkWidget::isOpenSslLibsIncluded()
QString AndroidBuildApkWidget::openSslIncludeFileContent(const FilePath &projectPath)
{
- QString openSslPath = AndroidConfig::openSslLocation().toString();
- if (projectPath.endsWith(".pro"))
+ QString openSslPath = AndroidConfig::openSslLocation().path();
+ if (projectPath.suffixView() == u"pro")
return "android: include(" + openSslPath + "/openssl.pri)";
- if (projectPath.endsWith("CMakeLists.txt"))
+ if (projectPath.fileNameView() == u"CMakeLists.txt")
return "if (ANDROID)\n include(" + openSslPath + "/CMakeLists.txt)\nendif()";
return {};
}
@@ -747,7 +747,7 @@ Tasking::GroupItem AndroidBuildApkStep::runRecipe()
QString applicationBinary;
if (!version->supportsMultipleQtAbis()) {
QTC_ASSERT(androidAbis.size() == 1, return false);
- applicationBinary = buildSystem()->buildTarget(buildKey).targetFilePath.toString();
+ applicationBinary = buildSystem()->buildTarget(buildKey).targetFilePath.path();
FilePath androidLibsDir = androidBuildDir / "libs" / androidAbis.first();
for (const FilePath &target : targets) {
if (!copyFileIfNewer(target, androidLibsDir.pathAppended(target.fileName()))) {
@@ -804,16 +804,20 @@ Tasking::GroupItem AndroidBuildApkStep::runRecipe()
QString qmlRootPath = bs->extraData(buildKey, "QML_ROOT_PATH").toString();
if (qmlRootPath.isEmpty())
- qmlRootPath = target()->project()->rootProjectDirectory().toString();
+ qmlRootPath = target()->project()->rootProjectDirectory().path();
deploySettings["qml-root-path"] = qmlRootPath;
- QFile f{m_inputFile.toString()};
- if (!f.open(QIODevice::WriteOnly)) {
- reportWarningOrError(Tr::tr("Cannot open androiddeployqt input file \"%1\" for writing.")
- .arg(m_inputFile.toUserOutput()), Task::Error);
+ const expected_str<qint64> result = m_inputFile.writeFileContents(QJsonDocument{deploySettings}.toJson());
+ if (!result) {
+ reportWarningOrError(
+ Tr::tr("Cannot open androiddeployqt input file \"%1\" for writing.")
+ .arg(m_inputFile.toUserOutput())
+ .append(' ')
+ .append(result.error()),
+ Task::Error);
return false;
}
- f.write(QJsonDocument{deploySettings}.toJson());
+
return true;
};
diff --git a/src/plugins/android/androidconfigurations.cpp b/src/plugins/android/androidconfigurations.cpp
index ccdee4190a3..6cb65e4eed6 100644
--- a/src/plugins/android/androidconfigurations.cpp
+++ b/src/plugins/android/androidconfigurations.cpp
@@ -64,6 +64,23 @@ using namespace Utils;
namespace {
static Q_LOGGING_CATEGORY(avdConfigLog, "qtc.android.androidconfig", QtWarningMsg)
+
+std::optional<FilePath> tryGetFirstDirectory(const FilePath &path, const QStringList &nameFilters)
+{
+ std::optional<FilePath> ret;
+ path.iterateDirectory(
+ [&ret](const FilePath &p) {
+ if (p.exists()) {
+ ret = p;
+ return IterationPolicy::Stop;
+ }
+
+ return IterationPolicy::Continue;
+ },
+ FileFilter{nameFilters, QDir::Dirs});
+
+ return ret;
+}
}
namespace Android {
@@ -120,9 +137,9 @@ const Key changeTimeStamp("ChangeTimeStamp");
const char sdkToolsVersionKey[] = "Pkg.Revision";
const char ndkRevisionKey[] = "Pkg.Revision";
-static QString sdkSettingsFileName()
+static FilePath sdkSettingsFileName()
{
- return Core::ICore::installerResourcePath("android.xml").toString();
+ return Core::ICore::installerResourcePath("android.xml");
}
static QString ndkPackageMarker()
@@ -316,14 +333,18 @@ void AndroidConfigData::load(const QtcSettings &settings)
m_sdkFullyConfigured = settings.value(SdkFullyConfiguredKey, false).toBool();
PersistentSettingsReader reader;
- if (reader.load(FilePath::fromString(sdkSettingsFileName()))
- && settings.value(changeTimeStamp).toInt() != QFileInfo(sdkSettingsFileName()).lastModified().toMSecsSinceEpoch() / 1000) {
+ if (reader.load(sdkSettingsFileName())
+ && settings.value(changeTimeStamp).toInt() != sdkSettingsFileName().lastModified().toMSecsSinceEpoch() / 1000) {
// persisten settings
- m_sdkLocation = FilePath::fromUserInput(reader.restoreValue(SDKLocationKey, m_sdkLocation.toString()).toString()).cleanPath();
+ m_sdkLocation = FilePath::fromSettings(
+ reader.restoreValue(SDKLocationKey, m_sdkLocation.toSettings()))
+ .cleanPath();
m_customNdkList = reader.restoreValue(CustomNdkLocationsKey).toStringList();
m_sdkManagerToolArgs = reader.restoreValue(SDKManagerToolArgsKey, m_sdkManagerToolArgs).toStringList();
- m_openJDKLocation = FilePath::fromString(reader.restoreValue(OpenJDKLocationKey, m_openJDKLocation.toString()).toString());
- m_openSslLocation = FilePath::fromString(reader.restoreValue(OpenSslPriLocationKey, m_openSslLocation.toString()).toString());
+ m_openJDKLocation = FilePath::fromSettings(
+ reader.restoreValue(OpenJDKLocationKey, m_openJDKLocation.toSettings()));
+ m_openSslLocation = FilePath::fromSettings(
+ reader.restoreValue(OpenSslPriLocationKey, m_openSslLocation.toSettings()));
m_automaticKitCreation = reader.restoreValue(AutomaticKitCreationKey, m_automaticKitCreation).toBool();
m_sdkFullyConfigured = reader.restoreValue(SdkFullyConfiguredKey, m_sdkFullyConfigured).toBool();
// persistent settings
@@ -340,17 +361,17 @@ void AndroidConfigData::load(const QtcSettings &settings)
void AndroidConfigData::save(QtcSettings &settings) const
{
- QFileInfo fileInfo(sdkSettingsFileName());
- if (fileInfo.exists())
- settings.setValue(changeTimeStamp, fileInfo.lastModified().toMSecsSinceEpoch() / 1000);
+ const FilePath sdkSettingsFile = sdkSettingsFileName();
+ if (sdkSettingsFile.exists())
+ settings.setValue(changeTimeStamp, sdkSettingsFile.lastModified().toMSecsSinceEpoch() / 1000);
// user settings
- settings.setValue(SDKLocationKey, m_sdkLocation.toString());
+ settings.setValue(SDKLocationKey, m_sdkLocation.toSettings());
settings.setValue(CustomNdkLocationsKey, m_customNdkList);
- settings.setValue(DefaultNdkLocationKey, m_defaultNdk.toString());
+ settings.setValue(DefaultNdkLocationKey, m_defaultNdk.toSettings());
settings.setValue(SDKManagerToolArgsKey, m_sdkManagerToolArgs);
- settings.setValue(OpenJDKLocationKey, m_openJDKLocation.toString());
- settings.setValue(OpenSslPriLocationKey, m_openSslLocation.toString());
+ settings.setValue(OpenJDKLocationKey, m_openJDKLocation.toSettings());
+ settings.setValue(OpenSslPriLocationKey, m_openSslLocation.toSettings());
settings.setValue(EmulatorArgsKey, m_emulatorArgs);
settings.setValue(AutomaticKitCreationKey, m_automaticKitCreation);
settings.setValue(SdkFullyConfiguredKey, m_sdkFullyConfigured);
@@ -373,13 +394,17 @@ void AndroidConfigData::parseDependenciesJson()
sdkConfigFile.copyFile(sdkConfigUserFile);
}
- QFile jsonFile(sdkConfigUserFile.toString());
- if (!jsonFile.open(QIODevice::ReadOnly)) {
- qCDebug(avdConfigLog, "Couldn't open JSON config file %s.", qPrintable(jsonFile.fileName()));
+ const expected_str<QByteArray> result = sdkConfigUserFile.fileContents();
+ if (!result) {
+ qCDebug(
+ avdConfigLog,
+ "Couldn't open JSON config file %s. %s",
+ qPrintable(sdkConfigUserFile.fileName()),
+ qPrintable(result.error()));
return;
}
- QJsonObject jsonObject = QJsonDocument::fromJson(jsonFile.readAll()).object();
+ QJsonObject jsonObject = QJsonDocument::fromJson(*result).object();
if (jsonObject.contains(CommonKey) && jsonObject[CommonKey].isObject()) {
QJsonObject commonObject = jsonObject[CommonKey].toObject();
@@ -449,14 +474,11 @@ static QList<int> availableNdkPlatformsLegacy(const FilePath &ndkLocation)
{
QList<int> availableNdkPlatforms;
- ndkLocation
- .pathAppended("platforms")
+ ndkLocation.pathAppended("platforms")
.iterateDirectory(
[&availableNdkPlatforms](const FilePath &filePath) {
- availableNdkPlatforms.push_back(
- filePath.toString()
- .mid(filePath.path().lastIndexOf('-') + 1)
- .toInt());
+ const QString fileName = filePath.fileName();
+ availableNdkPlatforms.push_back(fileName.mid(fileName.lastIndexOf('-') + 1).toInt());
return IterationPolicy::Continue;
},
{{"android-*"}, QDir::Dirs});
@@ -576,17 +598,14 @@ void setTemporarySdkToolsPath(const FilePath &path)
FilePath toolchainPathFromNdk(const FilePath &ndkLocation, OsType hostOs)
{
- const FilePath tcPath = ndkLocation / "toolchains/";
- FilePath toolchainPath;
- QDirIterator llvmIter(tcPath.toString(), {"llvm*"}, QDir::Dirs);
- if (llvmIter.hasNext()) {
- llvmIter.next();
- toolchainPath = tcPath / llvmIter.fileName() / "prebuilt/";
- }
+ const FilePath tcPath = ndkLocation / "toolchains";
- if (toolchainPath.isEmpty())
+ const std::optional<FilePath> llvmDir = tryGetFirstDirectory(tcPath, {"llvm*"});
+ if (!llvmDir)
return {};
+ const FilePath prebuiltDir = *llvmDir / "prebuilt";
+
// detect toolchain host
QStringList hostPatterns;
switch (hostOs) {
@@ -602,13 +621,11 @@ FilePath toolchainPathFromNdk(const FilePath &ndkLocation, OsType hostOs)
default: /* unknown host */ return {};
}
- QDirIterator iter(toolchainPath.toString(), hostPatterns, QDir::Dirs);
- if (iter.hasNext()) {
- iter.next();
- return toolchainPath / iter.fileName();
- }
+ const std::optional<FilePath> toolchainDir = tryGetFirstDirectory(prebuiltDir, hostPatterns);
+ if (!toolchainDir)
+ return {};
- return {};
+ return *toolchainDir;
}
FilePath toolchainPath(const QtVersion *qtVersion)
@@ -751,7 +768,7 @@ bool isValidNdk(const QString &ndkLocation)
const FilePath ndkPlatformsDir = ndkPath.pathAppended("platforms");
if (version.majorVersion() <= 22
- && (!ndkPlatformsDir.exists() || ndkPlatformsDir.toString().contains(' ')))
+ && (!ndkPlatformsDir.exists() || ndkPlatformsDir.pathView().contains(' ')))
return false;
return true;
}
@@ -799,7 +816,7 @@ QVersionNumber sdkToolsVersion()
return {};
const FilePath sdkToolsPropertiesPath = sdkToolsVersionPath();
- const QSettings settings(sdkToolsPropertiesPath.toString(), QSettings::IniFormat);
+ const QSettings settings(sdkToolsPropertiesPath.toFSPathString(), QSettings::IniFormat);
return QVersionNumber::fromString(settings.value(sdkToolsVersionKey).toString());
}
@@ -807,9 +824,8 @@ QVersionNumber buildToolsVersion()
{
//TODO: return version according to qt version
QVersionNumber maxVersion;
- QDir buildToolsDir(config().m_sdkLocation.pathAppended("build-tools").toString());
- const auto files = buildToolsDir.entryInfoList(QDir::Dirs|QDir::NoDotAndDotDot);
- for (const QFileInfo &file: files)
+ const FilePath buildToolsPath = config().m_sdkLocation.pathAppended("build-tools");
+ for (const FilePath &file : buildToolsPath.dirEntries(QDir::Dirs | QDir::NoDotAndDotDot))
maxVersion = qMax(maxVersion, QVersionNumber::fromString(file.fileName()));
return maxVersion;
}
@@ -842,7 +858,7 @@ QVersionNumber ndkVersion(const FilePath &ndkPath)
const FilePath ndkPropertiesPath = ndkPath.pathAppended("source.properties");
if (ndkPropertiesPath.exists()) {
// source.properties files exists in NDK version > 11
- QSettings settings(ndkPropertiesPath.toString(), QSettings::IniFormat);
+ QSettings settings(ndkPropertiesPath.toFSPathString(), QSettings::IniFormat);
auto versionStr = settings.value(ndkRevisionKey).toString();
version = QVersionNumber::fromString(versionStr);
} else {
@@ -1000,7 +1016,6 @@ QString toolchainHost(const QtVersion *qtVersion)
QString toolchainHostFromNdk(const FilePath &ndkPath)
{
// detect toolchain host
- QString toolchainHost;
QStringList hostPatterns;
switch (HostOsInfo::hostOs()) {
case OsTypeLinux:
@@ -1013,18 +1028,15 @@ QString toolchainHostFromNdk(const FilePath &ndkPath)
hostPatterns << QLatin1String("darwin*");
break;
default: /* unknown host */
- return toolchainHost;
+ return {};
}
- QDirIterator jt(ndkPath.pathAppended("prebuilt").toString(),
- hostPatterns,
- QDir::Dirs);
- if (jt.hasNext()) {
- jt.next();
- toolchainHost = jt.fileName();
- }
+ const std::optional<FilePath> toolchainDir
+ = tryGetFirstDirectory(ndkPath.pathAppended("prebuilt"), hostPatterns);
+ if (!toolchainDir)
+ return {};
- return toolchainHost;
+ return toolchainDir->fileName();
}
QString emulatorArgs() { return config().m_emulatorArgs; }
@@ -1366,8 +1378,9 @@ void AndroidConfigurations::updateAutomaticKitList()
if (DeviceTypeKitAspect::deviceTypeId(k) == Constants::ANDROID_DEVICE_TYPE) {
if (k->value(Constants::ANDROID_KIT_NDK).isNull() || k->value(Constants::ANDROID_KIT_SDK).isNull()) {
if (QtVersion *qt = QtKitAspect::qtVersion(k)) {
- k->setValueSilently(Constants::ANDROID_KIT_NDK, AndroidConfig::ndkLocation(qt).toString());
- k->setValue(Constants::ANDROID_KIT_SDK, AndroidConfig::sdkLocation().toString());
+ k->setValueSilently(
+ Constants::ANDROID_KIT_NDK, AndroidConfig::ndkLocation(qt).toSettings());
+ k->setValue(Constants::ANDROID_KIT_SDK, AndroidConfig::sdkLocation().toSettings());
}
}
}
@@ -1438,8 +1451,10 @@ void AndroidConfigurations::updateAutomaticKitList()
k->setUnexpandedDisplayName(Tr::tr("Android %1 Clang %2")
.arg(versionStr)
.arg(getMultiOrSingleAbiString(abis)));
- k->setValueSilently(Constants::ANDROID_KIT_NDK, AndroidConfig::ndkLocation(qt).toString());
- k->setValueSilently(Constants::ANDROID_KIT_SDK, AndroidConfig::sdkLocation().toString());
+ k->setValueSilently(
+ Constants::ANDROID_KIT_NDK, AndroidConfig::ndkLocation(qt).toSettings());
+ k->setValueSilently(
+ Constants::ANDROID_KIT_SDK, AndroidConfig::sdkLocation().toSettings());
};
if (existingKit) {
diff --git a/src/plugins/android/androidcreatekeystorecertificate.cpp b/src/plugins/android/androidcreatekeystorecertificate.cpp
index 8e1ff1ea2e2..555dd6de855 100644
--- a/src/plugins/android/androidcreatekeystorecertificate.cpp
+++ b/src/plugins/android/androidcreatekeystorecertificate.cpp
@@ -263,15 +263,17 @@ void AndroidCreateKeystoreCertificate::buttonBoxAccepted()
if (!m_stateNameLineEdit->text().isEmpty())
distinguishedNames += QLatin1String(", S=") + m_stateNameLineEdit->text().replace(',', QLatin1String("\\,"));
+ // clang-format off
const CommandLine command(AndroidConfig::keytoolPath(),
{"-genkey", "-keyalg", "RSA",
- "-keystore", m_keystoreFilePath.toString(),
+ "-keystore", m_keystoreFilePath.path(),
"-storepass", keystorePassword(),
"-alias", certificateAlias(),
"-keysize", m_keySizeSpinBox->text(),
"-validity", m_validitySpinBox->text(),
"-keypass", certificatePassword(),
"-dname", distinguishedNames});
+ // clang-format off
Process genKeyCertProc;
genKeyCertProc.setCommand(command);
diff --git a/src/plugins/android/androiddeployqtstep.cpp b/src/plugins/android/androiddeployqtstep.cpp
index 9882ece4dc6..f8551e7a971 100644
--- a/src/plugins/android/androiddeployqtstep.cpp
+++ b/src/plugins/android/androiddeployqtstep.cpp
@@ -308,7 +308,7 @@ bool AndroidDeployQtStep::init()
AndroidManager::setManifestPath(target(),
FilePath::fromString(node->data(Constants::AndroidManifest).toString()));
} else {
- QString jsonFile = AndroidQtVersion::androidDeploymentSettings(target()).toString();
+ FilePath jsonFile = AndroidQtVersion::androidDeploymentSettings(target());
if (jsonFile.isEmpty()) {
reportWarningOrError(Tr::tr("Cannot find the androiddeployqt input JSON file."),
Task::Error);
@@ -323,10 +323,12 @@ bool AndroidDeployQtStep::init()
m_workingDirectory = AndroidManager::androidBuildDirectory(target());
+ // clang-format off
m_androiddeployqtArgs.addArgs({"--verbose",
- "--output", m_workingDirectory.toString(),
+ "--output", m_workingDirectory.path(),
"--no-build",
- "--input", jsonFile});
+ "--input", jsonFile.path()});
+ // clang-format on
m_androiddeployqtArgs.addArg("--gradle");
@@ -476,7 +478,7 @@ Group AndroidDeployQtStep::deployRecipe()
} else {
QTC_ASSERT(target()->activeRunConfiguration(), return SetupResult::StopWithError);
cmd.addArgs(AndroidDeviceInfo::adbSelector(m_serialNumber));
- cmd.addArgs({"install", "-r", m_apkPath.toString()});
+ cmd.addArgs({"install", "-r", m_apkPath.nativePath()});
}
process.setCommand(cmd);
diff --git a/src/plugins/android/androiddevice.cpp b/src/plugins/android/androiddevice.cpp
index 3fc78006edd..de164f03c49 100644
--- a/src/plugins/android/androiddevice.cpp
+++ b/src/plugins/android/androiddevice.cpp
@@ -761,7 +761,7 @@ static void handleAvdListChange(const AndroidDeviceInfoList &avdList)
// of the device has changed, remove it and register it again with the new name.
// Also account for the case of an AVD registered through old QC which might have
// invalid data by checking if the avdPath is not empty.
- if (dev->displayName() != displayName || androidDev->avdPath().toString().isEmpty()) {
+ if (dev->displayName() != displayName || androidDev->avdPath().isEmpty()) {
devMgr->removeDevice(dev->id());
} else {
// Find the state of the AVD retrieved from the AVD watcher
@@ -907,7 +907,7 @@ void AndroidDeviceManagerInstance::setupDevicesWatcher()
// Setup AVD filesystem watcher to listen for changes when an avd is created/deleted,
// or started/stopped
- m_avdFileSystemWatcher.addPath(avdFilePath().toString());
+ m_avdFileSystemWatcher.addPath(avdFilePath().toFSPathString());
connect(&m_avdFileSystemWatcher, &QFileSystemWatcher::directoryChanged, this, [this] {
if (!m_avdPathGuard.isLocked())
AndroidDeviceManager::updateAvdList();
diff --git a/src/plugins/android/androidmanager.cpp b/src/plugins/android/androidmanager.cpp
index b50fd6887d3..d34dc453827 100644
--- a/src/plugins/android/androidmanager.cpp
+++ b/src/plugins/android/androidmanager.cpp
@@ -53,13 +53,16 @@ static Q_LOGGING_CATEGORY(androidManagerLog, "qtc.android.androidManager", QtWar
static std::optional<QDomElement> documentElement(const FilePath &fileName)
{
- QFile file(fileName.toString());
- if (!file.open(QIODevice::ReadOnly)) {
- MessageManager::writeDisrupting(Tr::tr("Cannot open \"%1\".").arg(fileName.toUserOutput()));
+ const expected_str<QByteArray> result = fileName.fileContents();
+ if (!result) {
+ MessageManager::writeDisrupting(Tr::tr("Cannot open \"%1\".")
+ .arg(fileName.toUserOutput())
+ .append(' ')
+ .append(result.error()));
return {};
}
QDomDocument doc;
- if (!doc.setContent(file.readAll())) {
+ if (!doc.setContent(*result)) {
MessageManager::writeDisrupting(Tr::tr("Cannot parse \"%1\".").arg(fileName.toUserOutput()));
return {};
}
@@ -183,8 +186,8 @@ int minimumSDK(const Kit *kit)
int minSdkVersion = -1;
QtSupport::QtVersion *version = QtSupport::QtKitAspect::qtVersion(kit);
if (version && version->targetDeviceTypes().contains(Constants::ANDROID_DEVICE_TYPE)) {
- const FilePath stockManifestFilePath = FilePath::fromUserInput(
- version->prefix().toString() + "/src/android/templates/AndroidManifest.xml");
+ const FilePath stockManifestFilePath = version->prefix().pathAppended(
+ "src/android/templates/AndroidManifest.xml");
const auto element = documentElement(stockManifestFilePath);
if (element)
@@ -236,19 +239,18 @@ QJsonObject deploymentSettings(const Target *target)
return {};
QJsonObject settings;
settings["_description"] = qtcSignature;
- settings["qt"] = qt->prefix().toString();
- settings["ndk"] = AndroidConfig::ndkLocation(qt).toString();
- settings["sdk"] = AndroidConfig::sdkLocation().toString();
+ settings["qt"] = qt->prefix().toFSPathString();
+ settings["ndk"] = AndroidConfig::ndkLocation(qt).toFSPathString();
+ settings["sdk"] = AndroidConfig::sdkLocation().toFSPathString();
if (!qt->supportsMultipleQtAbis()) {
const QStringList abis = applicationAbis(target);
QTC_ASSERT(abis.size() == 1, return {});
- settings["stdcpp-path"] = (AndroidConfig::toolchainPath(qt)
- / "sysroot/usr/lib"
- / archTriplet(abis.first())
- / "libc++_shared.so").toString();
+ settings["stdcpp-path"] = (AndroidConfig::toolchainPath(qt) / "sysroot/usr/lib"
+ / archTriplet(abis.first()) / "libc++_shared.so")
+ .toFSPathString();
} else {
settings["stdcpp-path"]
- = AndroidConfig::toolchainPath(qt).pathAppended("sysroot/usr/lib").toString();
+ = AndroidConfig::toolchainPath(qt).pathAppended("sysroot/usr/lib").toFSPathString();
}
settings["toolchain-prefix"] = "llvm";
settings["tool-prefix"] = "llvm";
@@ -259,10 +261,10 @@ QJsonObject deploymentSettings(const Target *target)
bool isQtCreatorGenerated(const FilePath &deploymentFile)
{
- QFile f{deploymentFile.toString()};
- if (!f.open(QIODevice::ReadOnly))
+ const expected_str<QByteArray> result = deploymentFile.fileContents();
+ if (!result)
return false;
- return QJsonDocument::fromJson(f.readAll()).object()["_description"].toString() == qtcSignature;
+ return QJsonDocument::fromJson(*result).object()["_description"].toString() == qtcSignature;
}
FilePath androidBuildDirectory(const Target *target)
diff --git a/src/plugins/android/androidmanifesteditoriconwidget.cpp b/src/plugins/android/androidmanifesteditoriconwidget.cpp
index fd0935a7b02..5e2b7ae095c 100644
--- a/src/plugins/android/androidmanifesteditoriconwidget.cpp
+++ b/src/plugins/android/androidmanifesteditoriconwidget.cpp
@@ -121,7 +121,7 @@ void AndroidManifestEditorIconWidget::setIconFromPath(const FilePath &iconPath)
return;
m_iconPath = iconPath;
FilePath baseDir = manifestDir(m_textEditorWidget);
- QImage original(iconPath.toString());
+ QImage original(iconPath.toFSPathString());
if (!original.isNull() && m_scaledToOriginalAspectRatio) {
if ((original.width() > original.height() && m_buttonSize.height() > m_buttonSize.width())
|| (original.height() > original.width() && m_buttonSize.width() > m_buttonSize.height())) {
@@ -138,7 +138,7 @@ void AndroidManifestEditorIconWidget::setIconFromPath(const FilePath &iconPath)
}
copyIcon();
FilePath iconFile = baseDir / m_targetIconPath / m_targetIconFileName;
- m_button->setIcon(QIcon(iconFile.toString()));
+ m_button->setIcon(QIcon(iconFile.toFSPathString()));
}
void AndroidManifestEditorIconWidget::selectIcon()
@@ -254,7 +254,7 @@ void AndroidManifestEditorIconWidget::copyIcon()
qCDebug(androidManifestEditorLog) << "Icon target path empty, cannot copy icon.";
return;
}
- QImage original(m_iconPath.toString());
+ QImage original(m_iconPath.toFSPathString());
if (m_iconPath != targetPath)
removeIcon();
if (original.isNull()) {
@@ -277,7 +277,7 @@ void AndroidManifestEditorIconWidget::copyIcon()
else
scaled = scaleWithoutStretching(original, m_iconSize);
setScaleWarningLabelVisible(scaled.width() > original.width() || scaled.height() > original.height());
- scaled.save(targetPath.toString());
+ scaled.save(targetPath.toFSPathString());
m_iconPath = targetPath;
} else {
m_iconPath.clear();
diff --git a/src/plugins/android/androidpackageinstallationstep.cpp b/src/plugins/android/androidpackageinstallationstep.cpp
index 8f1d4b01d57..3c8621d4d4a 100644
--- a/src/plugins/android/androidpackageinstallationstep.cpp
+++ b/src/plugins/android/androidpackageinstallationstep.cpp
@@ -103,7 +103,7 @@ bool AndroidPackageInstallationStep::init()
QString AndroidPackageInstallationStep::nativeAndroidBuildPath() const
{
- QString buildPath = AndroidManager::androidBuildDirectory(target()).toString();
+ QString buildPath = AndroidManager::androidBuildDirectory(target()).toFSPathString();
if (HostOsInfo::isWindowsHost())
if (buildEnvironment().searchInPath("sh.exe").isEmpty())
buildPath = QDir::toNativeSeparators(buildPath);
diff --git a/src/plugins/android/androidrunnerworker.cpp b/src/plugins/android/androidrunnerworker.cpp
index aefe2ba351d..0b1f9e4d518 100644
--- a/src/plugins/android/androidrunnerworker.cpp
+++ b/src/plugins/android/androidrunnerworker.cpp
@@ -659,8 +659,8 @@ static ExecutableItem uploadDebugServerRecipe(RunnerStorage *storage, const QStr
};
const auto onServerUploadSetup = [storage, tempDebugServerPathStorage](Process &process) {
- process.setCommand(
- storage->adbCommand({"push", storage->m_debugServerPath.toString(), *tempDebugServerPathStorage}));
+ process.setCommand(storage->adbCommand(
+ {"push", storage->m_debugServerPath.path(), *tempDebugServerPathStorage}));
};
const auto onServerCopySetup = [storage, tempDebugServerPathStorage, debugServerFileName](Process &process) {
diff --git a/src/plugins/android/androidsdkdownloader.cpp b/src/plugins/android/androidsdkdownloader.cpp
index 8f0993363e0..e8a51d1299f 100644
--- a/src/plugins/android/androidsdkdownloader.cpp
+++ b/src/plugins/android/androidsdkdownloader.cpp
@@ -65,22 +65,23 @@ static FilePath sdkFromUrl(const QUrl &url)
// TODO: Make it a separate async task in a chain?
static std::optional<QString> saveToDisk(const FilePath &filename, QIODevice *data)
{
- QFile file(filename.toString());
- if (!file.open(QIODevice::WriteOnly)) {
+ const expected_str<qint64> result = filename.writeFileContents(data->readAll());
+ if (!result) {
return Tr::tr("Could not open \"%1\" for writing: %2.")
- .arg(filename.toUserOutput(), file.errorString());
+ .arg(filename.toUserOutput(), result.error());
}
- file.write(data->readAll());
+
return {};
}
static void validateFileIntegrity(QPromise<void> &promise, const FilePath &fileName,
const QByteArray &sha256)
{
- QFile file(fileName.toString());
- if (file.open(QFile::ReadOnly)) {
+ const expected_str<QByteArray> result = fileName.fileContents();
+ if (result) {
QCryptographicHash hash(QCryptographicHash::Sha256);
- if (hash.addData(&file) && hash.result() == sha256)
+ hash.addData(*result);
+ if (hash.result() == sha256)
return;
}
promise.future().cancel();
diff --git a/src/plugins/android/androidsdkmanager.cpp b/src/plugins/android/androidsdkmanager.cpp
index be9bd06e763..1a7db4ea49f 100644
--- a/src/plugins/android/androidsdkmanager.cpp
+++ b/src/plugins/android/androidsdkmanager.cpp
@@ -115,7 +115,7 @@ private:
static QString sdkRootArg()
{
- return "--sdk_root=" + AndroidConfig::sdkLocation().toString();
+ return "--sdk_root=" + AndroidConfig::sdkLocation().path();
}
const QRegularExpression &assertionRegExp()
diff --git a/src/plugins/android/androidsdkmanagerdialog.cpp b/src/plugins/android/androidsdkmanagerdialog.cpp
index 8ae1cfd77b5..c4c7da5755b 100644
--- a/src/plugins/android/androidsdkmanagerdialog.cpp
+++ b/src/plugins/android/androidsdkmanagerdialog.cpp
@@ -41,8 +41,9 @@ public:
m_argumentDetailsEdit->setReadOnly(true);
m_process.setEnvironment(AndroidConfig::toolsEnvironment());
- m_process.setCommand({AndroidConfig::sdkManagerToolPath(),
- {"--help", "--sdk_root=" + AndroidConfig::sdkLocation().toString()}});
+ m_process.setCommand(
+ {AndroidConfig::sdkManagerToolPath(),
+ {"--help", "--sdk_root=" + AndroidConfig::sdkLocation().path()}});
connect(&m_process, &Process::done, this, [this] {
const QString output = m_process.allOutput();
QString argumentDetails;
diff --git a/src/plugins/android/androidsettingswidget.cpp b/src/plugins/android/androidsettingswidget.cpp
index cdfdd5c029a..cdc80f91e9d 100644
--- a/src/plugins/android/androidsettingswidget.cpp
+++ b/src/plugins/android/androidsettingswidget.cpp
@@ -711,16 +711,14 @@ void AndroidSettingsWidget::downloadOpenSslRepo(const bool silent)
return;
}
- QDir openSslDir(openSslPath.toString());
- const bool isEmptyDir = openSslDir.isEmpty(QDir::AllEntries | QDir::NoDotAndDotDot
- | QDir::Hidden | QDir::System);
- if (openSslDir.exists() && !isEmptyDir) {
+ if (openSslPath.exists() && !openSslPath.isEmpty()) {
QMessageBox::information(
this,
openSslCloneTitle,
- Tr::tr("The selected download path (%1) for OpenSSL already exists and the directory is "
- "not empty. Select a different path or make sure it is an empty directory.")
- .arg(QDir::toNativeSeparators(openSslPath.toString())));
+ Tr::tr(
+ "The selected download path (%1) for OpenSSL already exists and the directory is "
+ "not empty. Select a different path or make sure it is an empty directory.")
+ .arg(openSslPath.toUserOutput()));
return;
}
@@ -733,8 +731,8 @@ void AndroidSettingsWidget::downloadOpenSslRepo(const bool silent)
const QString openSslRepo("https://github.com/KDAB/android_openssl.git");
Process *gitCloner = new Process(this);
- const CommandLine gitCloneCommand("git", {"clone", "--depth=1", openSslRepo,
- openSslPath.toString()});
+ const CommandLine
+ gitCloneCommand("git", {"clone", "--depth=1", openSslRepo, openSslPath.path()});
gitCloner->setCommand(gitCloneCommand);
qCDebug(androidsettingswidget) << "Cloning OpenSSL repo: " << gitCloneCommand.toUserOutput();
diff --git a/src/plugins/android/androidtoolchain.cpp b/src/plugins/android/androidtoolchain.cpp
index 02da5692eff..ede99938e25 100644
--- a/src/plugins/android/androidtoolchain.cpp
+++ b/src/plugins/android/androidtoolchain.cpp
@@ -68,7 +68,7 @@ AndroidToolchain::~AndroidToolchain() = default;
bool AndroidToolchain::isValid() const
{
if (m_ndkLocation.isEmpty()) {
- QStringList ndkParts(compilerCommand().toString().split("toolchains/llvm/prebuilt/"));
+ QStringList ndkParts(compilerCommand().toFSPathString().split("toolchains/llvm/prebuilt/"));
if (ndkParts.size() > 1) {
QString ndkLocation(ndkParts.first());
if (ndkLocation.endsWith('/'))
diff --git a/src/plugins/android/avdmanageroutputparser.cpp b/src/plugins/android/avdmanageroutputparser.cpp
index 7a91b99f19d..8309fee7810 100644
--- a/src/plugins/android/avdmanageroutputparser.cpp
+++ b/src/plugins/android/avdmanageroutputparser.cpp
@@ -60,7 +60,7 @@ static std::optional<AndroidDeviceInfo> parseAvd(const QStringList &deviceInfo)
if (avdPath.exists()) {
// Get ABI.
const Utils::FilePath configFile = avdPath.pathAppended("config.ini");
- QSettings config(configFile.toString(), QSettings::IniFormat);
+ QSettings config(configFile.toFSPathString(), QSettings::IniFormat);
value = config.value(avdInfoAbiKey).toString();
if (!value.isEmpty())
avd.cpuAbi << value;
@@ -71,13 +71,13 @@ static std::optional<AndroidDeviceInfo> parseAvd(const QStringList &deviceInfo)
const QString avdInfoFileName = avd.avdName + ".ini";
const Utils::FilePath avdInfoFile = avdPath.parentDir().pathAppended(
avdInfoFileName);
- QSettings avdInfo(avdInfoFile.toString(), QSettings::IniFormat);
+ QSettings avdInfo(avdInfoFile.toFSPathString(), QSettings::IniFormat);
value = avdInfo.value(avdInfoTargetKey).toString();
if (!value.isEmpty())
avd.sdk = platformNameToApiLevel(value);
else
qCDebug(avdOutputParserLog)
- << "Avd Parsing: Cannot find sdk API:" << avdInfoFile.toString();
+ << "Avd Parsing: Cannot find sdk API:" << avdInfoFile.toUserOutput();
}
}
}
diff --git a/src/plugins/android/createandroidmanifestwizard.cpp b/src/plugins/android/createandroidmanifestwizard.cpp
index 8d2226f3790..60423c9d4a0 100644
--- a/src/plugins/android/createandroidmanifestwizard.cpp
+++ b/src/plugins/android/createandroidmanifestwizard.cpp
@@ -306,9 +306,9 @@ void CreateAndroidManifestWizard::createAndroidTemplateFiles()
if (androidPackageDir.isEmpty()) {
// and now time for some magic
const BuildTargetInfo bti = target->buildTarget(m_buildKey);
- const QString value = "$$PWD/"
- + bti.projectFilePath.toFileInfo().absoluteDir().relativeFilePath(
- m_directory.toString());
+ const QString value
+ = "$$PWD/"
+ + bti.projectFilePath.absoluteFilePath().relativePathFrom(m_directory).path();
bool result = node->setData(Android::Constants::AndroidPackageSourceDir, value);
if (!result) {
diff --git a/src/plugins/android/javalanguageserver.cpp b/src/plugins/android/javalanguageserver.cpp
index 90d536dcaef..c4bfd9bfd6d 100644
--- a/src/plugins/android/javalanguageserver.cpp
+++ b/src/plugins/android/javalanguageserver.cpp
@@ -120,7 +120,7 @@ bool JLSSettings::applyFromSettingsWidget(QWidget *widget)
configDir.cd("config_mac");
}
if (configDir.exists()) {
- arguments = arguments.arg(m_languageServer.toString(), configDir.absolutePath());
+ arguments = arguments.arg(m_languageServer.path(), configDir.absolutePath());
changed |= m_arguments != arguments;
m_arguments = arguments;
}
@@ -219,7 +219,7 @@ static void generateProjectFile(const FilePath &projectDir,
const QString &projectName)
{
const FilePath projectFilePath = projectDir.pathAppended(".project");
- QFile projectFile(projectFilePath.toString());
+ QFile projectFile(projectFilePath.toFSPathString());
if (projectFile.open(QFile::Truncate | QFile::WriteOnly)) {
QXmlStreamWriter writer(&projectFile);
writer.setAutoFormatting(true);
@@ -249,7 +249,7 @@ static void generateClassPathFile(const FilePath &projectDir,
const FilePaths &libs)
{
const FilePath classPathFilePath = projectDir.pathAppended(".classpath");
- QFile classPathFile(classPathFilePath.toString());
+ QFile classPathFile(classPathFilePath.toFSPathString());
if (classPathFile.open(QFile::Truncate | QFile::WriteOnly)) {
QXmlStreamWriter writer(&classPathFile);
writer.setAutoFormatting(true);
@@ -259,14 +259,14 @@ static void generateClassPathFile(const FilePath &projectDir,
writer.writeStartElement("classpath");
writer.writeEmptyElement("classpathentry");
writer.writeAttribute("kind", "src");
- writer.writeAttribute("path", sourceDir.toString());
+ writer.writeAttribute("path", sourceDir.toUserOutput());
writer.writeEmptyElement("classpathentry");
writer.writeAttribute("kind", "src");
writer.writeAttribute("path", "qtSrc");
for (const FilePath &lib : libs) {
writer.writeEmptyElement("classpathentry");
writer.writeAttribute("kind", "lib");
- writer.writeAttribute("path", lib.toString());
+ writer.writeAttribute("path", lib.toUserOutput());
}
writer.writeEndElement(); // classpath
writer.writeEndDocument();
@@ -286,7 +286,7 @@ void JLSClient::updateProjectFiles()
QtSupport::QtVersion *version = QtSupport::QtKitAspect::qtVersion(kit);
if (!version)
return;
- const QString qtSrc = version->prefix().toString() + "/src/android/java/src";
+ const FilePath qtSrc = version->prefix().pathAppended("src/android/java/src");
const FilePath &projectDir = project()->rootProjectDirectory();
if (!projectDir.exists())
return;
@@ -315,7 +315,7 @@ void JLSClient::updateProjectFiles()
for (const QString &path : classPaths)
libs << FilePath::fromString(path);
- generateProjectFile(projectDir, qtSrc, project()->displayName());
+ generateProjectFile(projectDir, qtSrc.path(), project()->displayName());
generateClassPathFile(projectDir, sourceDir, libs);
}
}
diff --git a/src/plugins/android/javaparser.cpp b/src/plugins/android/javaparser.cpp
index 65ddfba9ad6..a6b6146f1d2 100644
--- a/src/plugins/android/javaparser.cpp
+++ b/src/plugins/android/javaparser.cpp
@@ -47,11 +47,11 @@ OutputLineParser::Result JavaParser::handleLine(const QString &line, OutputForma
FilePath file = FilePath::fromUserInput(match.captured(2));
if (file.isChildOf(m_buildDirectory)) {
FilePath relativePath = file.relativeChildPath(m_buildDirectory);
- file = m_sourceDirectory.pathAppended(relativePath.toString());
+ file = m_sourceDirectory.resolvePath(relativePath);
}
if (file.toFileInfo().isRelative()) {
for (int i = 0; i < m_fileList.size(); i++)
- if (m_fileList[i].endsWith(file.toString())) {
+ if (m_fileList[i].endsWith(file.path())) {
file = m_fileList[i];
break;
}
diff --git a/src/plugins/android/splashscreencontainerwidget.cpp b/src/plugins/android/splashscreencontainerwidget.cpp
index 351fcd1a448..22ea3a1738d 100644
--- a/src/plugins/android/splashscreencontainerwidget.cpp
+++ b/src/plugins/android/splashscreencontainerwidget.cpp
@@ -225,7 +225,7 @@ void SplashScreenWidget::setImageFromPath(const FilePath &imagePath, bool resize
qCDebug(androidManifestEditorLog) << "Image target path is empty, cannot set image.";
return;
}
- QImage image = QImage(imagePath.toString());
+ QImage image = QImage(imagePath.toFSPathString());
if (image.isNull()) {
qCDebug(androidManifestEditorLog) << "Image '" << imagePath << "' not found or invalid format.";
return;
@@ -239,7 +239,7 @@ void SplashScreenWidget::setImageFromPath(const FilePath &imagePath, bool resize
(float(image.height()) / float(m_maxScalingRatio)) * float(m_scalingRatio));
image = image.scaled(size);
}
- QFile file(targetPath.toString());
+ QFile file(targetPath.toFSPathString());
if (file.open(QIODevice::WriteOnly | QIODevice::Truncate)) {
image.save(&file, "PNG");
file.close();
@@ -296,7 +296,7 @@ void SplashScreenWidget::loadImage()
qCDebug(androidManifestEditorLog) << "Image target path empty, cannot load image.";
return;
}
- QImage image = QImage(targetPath.toString());
+ QImage image = QImage(targetPath.toFSPathString());
if (image.isNull()) {
qCDebug(androidManifestEditorLog).noquote()
<< "Cannot load image." << targetPath.toUserOutput();
@@ -655,7 +655,7 @@ void SplashScreenContainerWidget::loadImages()
void SplashScreenContainerWidget::loadSplashscreenDrawParams(const QString &name)
{
const FilePath filePath = manifestDir(m_textEditorWidget).pathAppended("res/drawable/" + name + ".xml");
- QFile file(filePath.toString());
+ QFile file(filePath.toFSPathString());
if (file.open(QIODevice::ReadOnly | QIODevice::Text)) {
QXmlStreamReader reader(&file);
reader.setNamespaceProcessing(false);
@@ -773,13 +773,13 @@ void SplashScreenContainerWidget::setImageShowMode(const QString &mode)
void SplashScreenContainerWidget::createSplashscreenThemes()
{
- const QString baseDir = manifestDir(m_textEditorWidget).toString();
- const QStringList splashscreenThemeFiles = {"/res/values/splashscreentheme.xml",
- "/res/values-port/splashscreentheme.xml",
- "/res/values-land/splashscreentheme.xml"};
- const QStringList splashscreenDrawableFiles = {QString("/res/drawable/%1.xml").arg(splashscreenName),
- QString("/res/drawable/%1.xml").arg(splashscreenPortraitName),
- QString("/res/drawable/%1.xml").arg(splashscreenLandscapeName)};
+ const FilePath baseDir = manifestDir(m_textEditorWidget);
+ const QStringList splashscreenThemeFiles = {"res/values/splashscreentheme.xml",
+ "res/values-port/splashscreentheme.xml",
+ "res/values-land/splashscreentheme.xml"};
+ const QStringList splashscreenDrawableFiles = {QString("res/drawable/%1.xml").arg(splashscreenName),
+ QString("res/drawable/%1.xml").arg(splashscreenPortraitName),
+ QString("res/drawable/%1.xml").arg(splashscreenLandscapeName)};
QStringList splashscreens[3];
if (hasImages())
@@ -790,9 +790,11 @@ void SplashScreenContainerWidget::createSplashscreenThemes()
splashscreens[2] << splashscreenLandscapeName << splashscreenLandscapeFileName;
for (int i = 0; i < 3; i++) {
+ const FilePath splashscreenThemeFile = baseDir.pathAppended(splashscreenThemeFiles[i]);
+ const FilePath splashscreenDrawableFile = baseDir.pathAppended(splashscreenDrawableFiles[i]);
if (!splashscreens[i].isEmpty()) {
QDir dir;
- QFile themeFile(baseDir + splashscreenThemeFiles[i]);
+ QFile themeFile(splashscreenThemeFile.toFSPathString());
dir.mkpath(QFileInfo(themeFile).absolutePath());
if (themeFile.open(QFile::WriteOnly | QFile::Truncate)) {
QXmlStreamWriter stream(&themeFile);
@@ -810,7 +812,7 @@ void SplashScreenContainerWidget::createSplashscreenThemes()
stream.writeEndDocument();
themeFile.close();
}
- QFile drawableFile(baseDir + splashscreenDrawableFiles[i]);
+ QFile drawableFile(splashscreenDrawableFile.toFSPathString());
dir.mkpath(QFileInfo(drawableFile).absolutePath());
if (drawableFile.open(QFile::WriteOnly | QFile::Truncate)) {
QXmlStreamWriter stream(&drawableFile);
@@ -836,8 +838,8 @@ void SplashScreenContainerWidget::createSplashscreenThemes()
}
}
else {
- QFile::remove(baseDir + splashscreenThemeFiles[i]);
- QFile::remove(baseDir + splashscreenDrawableFiles[i]);
+ QFile::remove(splashscreenThemeFile.toFSPathString());
+ QFile::remove(splashscreenDrawableFile.toFSPathString());
}
}
}