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 <alessandro.portale@qt.io>
This commit is contained in:
Andrii Semkiv
2024-09-02 17:16:12 +02:00
committed by andrii.semkiv
parent 88f8d5c5e0
commit f7a230a5b6
19 changed files with 176 additions and 149 deletions

View File

@@ -413,10 +413,10 @@ bool AndroidBuildApkWidget::isOpenSslLibsIncluded()
QString AndroidBuildApkWidget::openSslIncludeFileContent(const FilePath &projectPath) QString AndroidBuildApkWidget::openSslIncludeFileContent(const FilePath &projectPath)
{ {
QString openSslPath = AndroidConfig::openSslLocation().toString(); QString openSslPath = AndroidConfig::openSslLocation().path();
if (projectPath.endsWith(".pro")) if (projectPath.suffixView() == u"pro")
return "android: include(" + openSslPath + "/openssl.pri)"; 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 "if (ANDROID)\n include(" + openSslPath + "/CMakeLists.txt)\nendif()";
return {}; return {};
} }
@@ -747,7 +747,7 @@ Tasking::GroupItem AndroidBuildApkStep::runRecipe()
QString applicationBinary; QString applicationBinary;
if (!version->supportsMultipleQtAbis()) { if (!version->supportsMultipleQtAbis()) {
QTC_ASSERT(androidAbis.size() == 1, return false); 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(); FilePath androidLibsDir = androidBuildDir / "libs" / androidAbis.first();
for (const FilePath &target : targets) { for (const FilePath &target : targets) {
if (!copyFileIfNewer(target, androidLibsDir.pathAppended(target.fileName()))) { if (!copyFileIfNewer(target, androidLibsDir.pathAppended(target.fileName()))) {
@@ -804,16 +804,20 @@ Tasking::GroupItem AndroidBuildApkStep::runRecipe()
QString qmlRootPath = bs->extraData(buildKey, "QML_ROOT_PATH").toString(); QString qmlRootPath = bs->extraData(buildKey, "QML_ROOT_PATH").toString();
if (qmlRootPath.isEmpty()) if (qmlRootPath.isEmpty())
qmlRootPath = target()->project()->rootProjectDirectory().toString(); qmlRootPath = target()->project()->rootProjectDirectory().path();
deploySettings["qml-root-path"] = qmlRootPath; deploySettings["qml-root-path"] = qmlRootPath;
QFile f{m_inputFile.toString()}; const expected_str<qint64> result = m_inputFile.writeFileContents(QJsonDocument{deploySettings}.toJson());
if (!f.open(QIODevice::WriteOnly)) { if (!result) {
reportWarningOrError(Tr::tr("Cannot open androiddeployqt input file \"%1\" for writing.") reportWarningOrError(
.arg(m_inputFile.toUserOutput()), Task::Error); Tr::tr("Cannot open androiddeployqt input file \"%1\" for writing.")
.arg(m_inputFile.toUserOutput())
.append(' ')
.append(result.error()),
Task::Error);
return false; return false;
} }
f.write(QJsonDocument{deploySettings}.toJson());
return true; return true;
}; };

View File

@@ -64,6 +64,23 @@ using namespace Utils;
namespace { namespace {
static Q_LOGGING_CATEGORY(avdConfigLog, "qtc.android.androidconfig", QtWarningMsg) 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 { namespace Android {
@@ -120,9 +137,9 @@ const Key changeTimeStamp("ChangeTimeStamp");
const char sdkToolsVersionKey[] = "Pkg.Revision"; const char sdkToolsVersionKey[] = "Pkg.Revision";
const char ndkRevisionKey[] = "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() static QString ndkPackageMarker()
@@ -316,14 +333,18 @@ void AndroidConfigData::load(const QtcSettings &settings)
m_sdkFullyConfigured = settings.value(SdkFullyConfiguredKey, false).toBool(); m_sdkFullyConfigured = settings.value(SdkFullyConfiguredKey, false).toBool();
PersistentSettingsReader reader; PersistentSettingsReader reader;
if (reader.load(FilePath::fromString(sdkSettingsFileName())) if (reader.load(sdkSettingsFileName())
&& settings.value(changeTimeStamp).toInt() != QFileInfo(sdkSettingsFileName()).lastModified().toMSecsSinceEpoch() / 1000) { && settings.value(changeTimeStamp).toInt() != sdkSettingsFileName().lastModified().toMSecsSinceEpoch() / 1000) {
// persisten settings // 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_customNdkList = reader.restoreValue(CustomNdkLocationsKey).toStringList();
m_sdkManagerToolArgs = reader.restoreValue(SDKManagerToolArgsKey, m_sdkManagerToolArgs).toStringList(); m_sdkManagerToolArgs = reader.restoreValue(SDKManagerToolArgsKey, m_sdkManagerToolArgs).toStringList();
m_openJDKLocation = FilePath::fromString(reader.restoreValue(OpenJDKLocationKey, m_openJDKLocation.toString()).toString()); m_openJDKLocation = FilePath::fromSettings(
m_openSslLocation = FilePath::fromString(reader.restoreValue(OpenSslPriLocationKey, m_openSslLocation.toString()).toString()); 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_automaticKitCreation = reader.restoreValue(AutomaticKitCreationKey, m_automaticKitCreation).toBool();
m_sdkFullyConfigured = reader.restoreValue(SdkFullyConfiguredKey, m_sdkFullyConfigured).toBool(); m_sdkFullyConfigured = reader.restoreValue(SdkFullyConfiguredKey, m_sdkFullyConfigured).toBool();
// persistent settings // persistent settings
@@ -340,17 +361,17 @@ void AndroidConfigData::load(const QtcSettings &settings)
void AndroidConfigData::save(QtcSettings &settings) const void AndroidConfigData::save(QtcSettings &settings) const
{ {
QFileInfo fileInfo(sdkSettingsFileName()); const FilePath sdkSettingsFile = sdkSettingsFileName();
if (fileInfo.exists()) if (sdkSettingsFile.exists())
settings.setValue(changeTimeStamp, fileInfo.lastModified().toMSecsSinceEpoch() / 1000); settings.setValue(changeTimeStamp, sdkSettingsFile.lastModified().toMSecsSinceEpoch() / 1000);
// user settings // user settings
settings.setValue(SDKLocationKey, m_sdkLocation.toString()); settings.setValue(SDKLocationKey, m_sdkLocation.toSettings());
settings.setValue(CustomNdkLocationsKey, m_customNdkList); settings.setValue(CustomNdkLocationsKey, m_customNdkList);
settings.setValue(DefaultNdkLocationKey, m_defaultNdk.toString()); settings.setValue(DefaultNdkLocationKey, m_defaultNdk.toSettings());
settings.setValue(SDKManagerToolArgsKey, m_sdkManagerToolArgs); settings.setValue(SDKManagerToolArgsKey, m_sdkManagerToolArgs);
settings.setValue(OpenJDKLocationKey, m_openJDKLocation.toString()); settings.setValue(OpenJDKLocationKey, m_openJDKLocation.toSettings());
settings.setValue(OpenSslPriLocationKey, m_openSslLocation.toString()); settings.setValue(OpenSslPriLocationKey, m_openSslLocation.toSettings());
settings.setValue(EmulatorArgsKey, m_emulatorArgs); settings.setValue(EmulatorArgsKey, m_emulatorArgs);
settings.setValue(AutomaticKitCreationKey, m_automaticKitCreation); settings.setValue(AutomaticKitCreationKey, m_automaticKitCreation);
settings.setValue(SdkFullyConfiguredKey, m_sdkFullyConfigured); settings.setValue(SdkFullyConfiguredKey, m_sdkFullyConfigured);
@@ -373,13 +394,17 @@ void AndroidConfigData::parseDependenciesJson()
sdkConfigFile.copyFile(sdkConfigUserFile); sdkConfigFile.copyFile(sdkConfigUserFile);
} }
QFile jsonFile(sdkConfigUserFile.toString()); const expected_str<QByteArray> result = sdkConfigUserFile.fileContents();
if (!jsonFile.open(QIODevice::ReadOnly)) { if (!result) {
qCDebug(avdConfigLog, "Couldn't open JSON config file %s.", qPrintable(jsonFile.fileName())); qCDebug(
avdConfigLog,
"Couldn't open JSON config file %s. %s",
qPrintable(sdkConfigUserFile.fileName()),
qPrintable(result.error()));
return; return;
} }
QJsonObject jsonObject = QJsonDocument::fromJson(jsonFile.readAll()).object(); QJsonObject jsonObject = QJsonDocument::fromJson(*result).object();
if (jsonObject.contains(CommonKey) && jsonObject[CommonKey].isObject()) { if (jsonObject.contains(CommonKey) && jsonObject[CommonKey].isObject()) {
QJsonObject commonObject = jsonObject[CommonKey].toObject(); QJsonObject commonObject = jsonObject[CommonKey].toObject();
@@ -449,14 +474,11 @@ static QList<int> availableNdkPlatformsLegacy(const FilePath &ndkLocation)
{ {
QList<int> availableNdkPlatforms; QList<int> availableNdkPlatforms;
ndkLocation ndkLocation.pathAppended("platforms")
.pathAppended("platforms")
.iterateDirectory( .iterateDirectory(
[&availableNdkPlatforms](const FilePath &filePath) { [&availableNdkPlatforms](const FilePath &filePath) {
availableNdkPlatforms.push_back( const QString fileName = filePath.fileName();
filePath.toString() availableNdkPlatforms.push_back(fileName.mid(fileName.lastIndexOf('-') + 1).toInt());
.mid(filePath.path().lastIndexOf('-') + 1)
.toInt());
return IterationPolicy::Continue; return IterationPolicy::Continue;
}, },
{{"android-*"}, QDir::Dirs}); {{"android-*"}, QDir::Dirs});
@@ -576,17 +598,14 @@ void setTemporarySdkToolsPath(const FilePath &path)
FilePath toolchainPathFromNdk(const FilePath &ndkLocation, OsType hostOs) FilePath toolchainPathFromNdk(const FilePath &ndkLocation, OsType hostOs)
{ {
const FilePath tcPath = ndkLocation / "toolchains/"; const FilePath tcPath = ndkLocation / "toolchains";
FilePath toolchainPath;
QDirIterator llvmIter(tcPath.toString(), {"llvm*"}, QDir::Dirs);
if (llvmIter.hasNext()) {
llvmIter.next();
toolchainPath = tcPath / llvmIter.fileName() / "prebuilt/";
}
if (toolchainPath.isEmpty()) const std::optional<FilePath> llvmDir = tryGetFirstDirectory(tcPath, {"llvm*"});
if (!llvmDir)
return {}; return {};
const FilePath prebuiltDir = *llvmDir / "prebuilt";
// detect toolchain host // detect toolchain host
QStringList hostPatterns; QStringList hostPatterns;
switch (hostOs) { switch (hostOs) {
@@ -602,13 +621,11 @@ FilePath toolchainPathFromNdk(const FilePath &ndkLocation, OsType hostOs)
default: /* unknown host */ return {}; default: /* unknown host */ return {};
} }
QDirIterator iter(toolchainPath.toString(), hostPatterns, QDir::Dirs); const std::optional<FilePath> toolchainDir = tryGetFirstDirectory(prebuiltDir, hostPatterns);
if (iter.hasNext()) { if (!toolchainDir)
iter.next(); return {};
return toolchainPath / iter.fileName();
}
return {}; return *toolchainDir;
} }
FilePath toolchainPath(const QtVersion *qtVersion) FilePath toolchainPath(const QtVersion *qtVersion)
@@ -751,7 +768,7 @@ bool isValidNdk(const QString &ndkLocation)
const FilePath ndkPlatformsDir = ndkPath.pathAppended("platforms"); const FilePath ndkPlatformsDir = ndkPath.pathAppended("platforms");
if (version.majorVersion() <= 22 if (version.majorVersion() <= 22
&& (!ndkPlatformsDir.exists() || ndkPlatformsDir.toString().contains(' '))) && (!ndkPlatformsDir.exists() || ndkPlatformsDir.pathView().contains(' ')))
return false; return false;
return true; return true;
} }
@@ -799,7 +816,7 @@ QVersionNumber sdkToolsVersion()
return {}; return {};
const FilePath sdkToolsPropertiesPath = sdkToolsVersionPath(); 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()); return QVersionNumber::fromString(settings.value(sdkToolsVersionKey).toString());
} }
@@ -807,9 +824,8 @@ QVersionNumber buildToolsVersion()
{ {
//TODO: return version according to qt version //TODO: return version according to qt version
QVersionNumber maxVersion; QVersionNumber maxVersion;
QDir buildToolsDir(config().m_sdkLocation.pathAppended("build-tools").toString()); const FilePath buildToolsPath = config().m_sdkLocation.pathAppended("build-tools");
const auto files = buildToolsDir.entryInfoList(QDir::Dirs|QDir::NoDotAndDotDot); for (const FilePath &file : buildToolsPath.dirEntries(QDir::Dirs | QDir::NoDotAndDotDot))
for (const QFileInfo &file: files)
maxVersion = qMax(maxVersion, QVersionNumber::fromString(file.fileName())); maxVersion = qMax(maxVersion, QVersionNumber::fromString(file.fileName()));
return maxVersion; return maxVersion;
} }
@@ -842,7 +858,7 @@ QVersionNumber ndkVersion(const FilePath &ndkPath)
const FilePath ndkPropertiesPath = ndkPath.pathAppended("source.properties"); const FilePath ndkPropertiesPath = ndkPath.pathAppended("source.properties");
if (ndkPropertiesPath.exists()) { if (ndkPropertiesPath.exists()) {
// source.properties files exists in NDK version > 11 // 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(); auto versionStr = settings.value(ndkRevisionKey).toString();
version = QVersionNumber::fromString(versionStr); version = QVersionNumber::fromString(versionStr);
} else { } else {
@@ -1000,7 +1016,6 @@ QString toolchainHost(const QtVersion *qtVersion)
QString toolchainHostFromNdk(const FilePath &ndkPath) QString toolchainHostFromNdk(const FilePath &ndkPath)
{ {
// detect toolchain host // detect toolchain host
QString toolchainHost;
QStringList hostPatterns; QStringList hostPatterns;
switch (HostOsInfo::hostOs()) { switch (HostOsInfo::hostOs()) {
case OsTypeLinux: case OsTypeLinux:
@@ -1013,18 +1028,15 @@ QString toolchainHostFromNdk(const FilePath &ndkPath)
hostPatterns << QLatin1String("darwin*"); hostPatterns << QLatin1String("darwin*");
break; break;
default: /* unknown host */ default: /* unknown host */
return toolchainHost; return {};
} }
QDirIterator jt(ndkPath.pathAppended("prebuilt").toString(), const std::optional<FilePath> toolchainDir
hostPatterns, = tryGetFirstDirectory(ndkPath.pathAppended("prebuilt"), hostPatterns);
QDir::Dirs); if (!toolchainDir)
if (jt.hasNext()) { return {};
jt.next();
toolchainHost = jt.fileName();
}
return toolchainHost; return toolchainDir->fileName();
} }
QString emulatorArgs() { return config().m_emulatorArgs; } QString emulatorArgs() { return config().m_emulatorArgs; }
@@ -1366,8 +1378,9 @@ void AndroidConfigurations::updateAutomaticKitList()
if (DeviceTypeKitAspect::deviceTypeId(k) == Constants::ANDROID_DEVICE_TYPE) { if (DeviceTypeKitAspect::deviceTypeId(k) == Constants::ANDROID_DEVICE_TYPE) {
if (k->value(Constants::ANDROID_KIT_NDK).isNull() || k->value(Constants::ANDROID_KIT_SDK).isNull()) { if (k->value(Constants::ANDROID_KIT_NDK).isNull() || k->value(Constants::ANDROID_KIT_SDK).isNull()) {
if (QtVersion *qt = QtKitAspect::qtVersion(k)) { if (QtVersion *qt = QtKitAspect::qtVersion(k)) {
k->setValueSilently(Constants::ANDROID_KIT_NDK, AndroidConfig::ndkLocation(qt).toString()); k->setValueSilently(
k->setValue(Constants::ANDROID_KIT_SDK, AndroidConfig::sdkLocation().toString()); 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") k->setUnexpandedDisplayName(Tr::tr("Android %1 Clang %2")
.arg(versionStr) .arg(versionStr)
.arg(getMultiOrSingleAbiString(abis))); .arg(getMultiOrSingleAbiString(abis)));
k->setValueSilently(Constants::ANDROID_KIT_NDK, AndroidConfig::ndkLocation(qt).toString()); k->setValueSilently(
k->setValueSilently(Constants::ANDROID_KIT_SDK, AndroidConfig::sdkLocation().toString()); Constants::ANDROID_KIT_NDK, AndroidConfig::ndkLocation(qt).toSettings());
k->setValueSilently(
Constants::ANDROID_KIT_SDK, AndroidConfig::sdkLocation().toSettings());
}; };
if (existingKit) { if (existingKit) {

View File

@@ -263,15 +263,17 @@ void AndroidCreateKeystoreCertificate::buttonBoxAccepted()
if (!m_stateNameLineEdit->text().isEmpty()) if (!m_stateNameLineEdit->text().isEmpty())
distinguishedNames += QLatin1String(", S=") + m_stateNameLineEdit->text().replace(',', QLatin1String("\\,")); distinguishedNames += QLatin1String(", S=") + m_stateNameLineEdit->text().replace(',', QLatin1String("\\,"));
// clang-format off
const CommandLine command(AndroidConfig::keytoolPath(), const CommandLine command(AndroidConfig::keytoolPath(),
{"-genkey", "-keyalg", "RSA", {"-genkey", "-keyalg", "RSA",
"-keystore", m_keystoreFilePath.toString(), "-keystore", m_keystoreFilePath.path(),
"-storepass", keystorePassword(), "-storepass", keystorePassword(),
"-alias", certificateAlias(), "-alias", certificateAlias(),
"-keysize", m_keySizeSpinBox->text(), "-keysize", m_keySizeSpinBox->text(),
"-validity", m_validitySpinBox->text(), "-validity", m_validitySpinBox->text(),
"-keypass", certificatePassword(), "-keypass", certificatePassword(),
"-dname", distinguishedNames}); "-dname", distinguishedNames});
// clang-format off
Process genKeyCertProc; Process genKeyCertProc;
genKeyCertProc.setCommand(command); genKeyCertProc.setCommand(command);

View File

@@ -308,7 +308,7 @@ bool AndroidDeployQtStep::init()
AndroidManager::setManifestPath(target(), AndroidManager::setManifestPath(target(),
FilePath::fromString(node->data(Constants::AndroidManifest).toString())); FilePath::fromString(node->data(Constants::AndroidManifest).toString()));
} else { } else {
QString jsonFile = AndroidQtVersion::androidDeploymentSettings(target()).toString(); FilePath jsonFile = AndroidQtVersion::androidDeploymentSettings(target());
if (jsonFile.isEmpty()) { if (jsonFile.isEmpty()) {
reportWarningOrError(Tr::tr("Cannot find the androiddeployqt input JSON file."), reportWarningOrError(Tr::tr("Cannot find the androiddeployqt input JSON file."),
Task::Error); Task::Error);
@@ -323,10 +323,12 @@ bool AndroidDeployQtStep::init()
m_workingDirectory = AndroidManager::androidBuildDirectory(target()); m_workingDirectory = AndroidManager::androidBuildDirectory(target());
// clang-format off
m_androiddeployqtArgs.addArgs({"--verbose", m_androiddeployqtArgs.addArgs({"--verbose",
"--output", m_workingDirectory.toString(), "--output", m_workingDirectory.path(),
"--no-build", "--no-build",
"--input", jsonFile}); "--input", jsonFile.path()});
// clang-format on
m_androiddeployqtArgs.addArg("--gradle"); m_androiddeployqtArgs.addArg("--gradle");
@@ -476,7 +478,7 @@ Group AndroidDeployQtStep::deployRecipe()
} else { } else {
QTC_ASSERT(target()->activeRunConfiguration(), return SetupResult::StopWithError); QTC_ASSERT(target()->activeRunConfiguration(), return SetupResult::StopWithError);
cmd.addArgs(AndroidDeviceInfo::adbSelector(m_serialNumber)); cmd.addArgs(AndroidDeviceInfo::adbSelector(m_serialNumber));
cmd.addArgs({"install", "-r", m_apkPath.toString()}); cmd.addArgs({"install", "-r", m_apkPath.nativePath()});
} }
process.setCommand(cmd); process.setCommand(cmd);

View File

@@ -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. // 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 // 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. // 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()); devMgr->removeDevice(dev->id());
} else { } else {
// Find the state of the AVD retrieved from the AVD watcher // 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, // Setup AVD filesystem watcher to listen for changes when an avd is created/deleted,
// or started/stopped // or started/stopped
m_avdFileSystemWatcher.addPath(avdFilePath().toString()); m_avdFileSystemWatcher.addPath(avdFilePath().toFSPathString());
connect(&m_avdFileSystemWatcher, &QFileSystemWatcher::directoryChanged, this, [this] { connect(&m_avdFileSystemWatcher, &QFileSystemWatcher::directoryChanged, this, [this] {
if (!m_avdPathGuard.isLocked()) if (!m_avdPathGuard.isLocked())
AndroidDeviceManager::updateAvdList(); AndroidDeviceManager::updateAvdList();

View File

@@ -53,13 +53,16 @@ static Q_LOGGING_CATEGORY(androidManagerLog, "qtc.android.androidManager", QtWar
static std::optional<QDomElement> documentElement(const FilePath &fileName) static std::optional<QDomElement> documentElement(const FilePath &fileName)
{ {
QFile file(fileName.toString()); const expected_str<QByteArray> result = fileName.fileContents();
if (!file.open(QIODevice::ReadOnly)) { if (!result) {
MessageManager::writeDisrupting(Tr::tr("Cannot open \"%1\".").arg(fileName.toUserOutput())); MessageManager::writeDisrupting(Tr::tr("Cannot open \"%1\".")
.arg(fileName.toUserOutput())
.append(' ')
.append(result.error()));
return {}; return {};
} }
QDomDocument doc; QDomDocument doc;
if (!doc.setContent(file.readAll())) { if (!doc.setContent(*result)) {
MessageManager::writeDisrupting(Tr::tr("Cannot parse \"%1\".").arg(fileName.toUserOutput())); MessageManager::writeDisrupting(Tr::tr("Cannot parse \"%1\".").arg(fileName.toUserOutput()));
return {}; return {};
} }
@@ -183,8 +186,8 @@ int minimumSDK(const Kit *kit)
int minSdkVersion = -1; int minSdkVersion = -1;
QtSupport::QtVersion *version = QtSupport::QtKitAspect::qtVersion(kit); QtSupport::QtVersion *version = QtSupport::QtKitAspect::qtVersion(kit);
if (version && version->targetDeviceTypes().contains(Constants::ANDROID_DEVICE_TYPE)) { if (version && version->targetDeviceTypes().contains(Constants::ANDROID_DEVICE_TYPE)) {
const FilePath stockManifestFilePath = FilePath::fromUserInput( const FilePath stockManifestFilePath = version->prefix().pathAppended(
version->prefix().toString() + "/src/android/templates/AndroidManifest.xml"); "src/android/templates/AndroidManifest.xml");
const auto element = documentElement(stockManifestFilePath); const auto element = documentElement(stockManifestFilePath);
if (element) if (element)
@@ -236,19 +239,18 @@ QJsonObject deploymentSettings(const Target *target)
return {}; return {};
QJsonObject settings; QJsonObject settings;
settings["_description"] = qtcSignature; settings["_description"] = qtcSignature;
settings["qt"] = qt->prefix().toString(); settings["qt"] = qt->prefix().toFSPathString();
settings["ndk"] = AndroidConfig::ndkLocation(qt).toString(); settings["ndk"] = AndroidConfig::ndkLocation(qt).toFSPathString();
settings["sdk"] = AndroidConfig::sdkLocation().toString(); settings["sdk"] = AndroidConfig::sdkLocation().toFSPathString();
if (!qt->supportsMultipleQtAbis()) { if (!qt->supportsMultipleQtAbis()) {
const QStringList abis = applicationAbis(target); const QStringList abis = applicationAbis(target);
QTC_ASSERT(abis.size() == 1, return {}); QTC_ASSERT(abis.size() == 1, return {});
settings["stdcpp-path"] = (AndroidConfig::toolchainPath(qt) settings["stdcpp-path"] = (AndroidConfig::toolchainPath(qt) / "sysroot/usr/lib"
/ "sysroot/usr/lib" / archTriplet(abis.first()) / "libc++_shared.so")
/ archTriplet(abis.first()) .toFSPathString();
/ "libc++_shared.so").toString();
} else { } else {
settings["stdcpp-path"] settings["stdcpp-path"]
= AndroidConfig::toolchainPath(qt).pathAppended("sysroot/usr/lib").toString(); = AndroidConfig::toolchainPath(qt).pathAppended("sysroot/usr/lib").toFSPathString();
} }
settings["toolchain-prefix"] = "llvm"; settings["toolchain-prefix"] = "llvm";
settings["tool-prefix"] = "llvm"; settings["tool-prefix"] = "llvm";
@@ -259,10 +261,10 @@ QJsonObject deploymentSettings(const Target *target)
bool isQtCreatorGenerated(const FilePath &deploymentFile) bool isQtCreatorGenerated(const FilePath &deploymentFile)
{ {
QFile f{deploymentFile.toString()}; const expected_str<QByteArray> result = deploymentFile.fileContents();
if (!f.open(QIODevice::ReadOnly)) if (!result)
return false; return false;
return QJsonDocument::fromJson(f.readAll()).object()["_description"].toString() == qtcSignature; return QJsonDocument::fromJson(*result).object()["_description"].toString() == qtcSignature;
} }
FilePath androidBuildDirectory(const Target *target) FilePath androidBuildDirectory(const Target *target)

View File

@@ -121,7 +121,7 @@ void AndroidManifestEditorIconWidget::setIconFromPath(const FilePath &iconPath)
return; return;
m_iconPath = iconPath; m_iconPath = iconPath;
FilePath baseDir = manifestDir(m_textEditorWidget); FilePath baseDir = manifestDir(m_textEditorWidget);
QImage original(iconPath.toString()); QImage original(iconPath.toFSPathString());
if (!original.isNull() && m_scaledToOriginalAspectRatio) { if (!original.isNull() && m_scaledToOriginalAspectRatio) {
if ((original.width() > original.height() && m_buttonSize.height() > m_buttonSize.width()) if ((original.width() > original.height() && m_buttonSize.height() > m_buttonSize.width())
|| (original.height() > original.width() && m_buttonSize.width() > m_buttonSize.height())) { || (original.height() > original.width() && m_buttonSize.width() > m_buttonSize.height())) {
@@ -138,7 +138,7 @@ void AndroidManifestEditorIconWidget::setIconFromPath(const FilePath &iconPath)
} }
copyIcon(); copyIcon();
FilePath iconFile = baseDir / m_targetIconPath / m_targetIconFileName; FilePath iconFile = baseDir / m_targetIconPath / m_targetIconFileName;
m_button->setIcon(QIcon(iconFile.toString())); m_button->setIcon(QIcon(iconFile.toFSPathString()));
} }
void AndroidManifestEditorIconWidget::selectIcon() void AndroidManifestEditorIconWidget::selectIcon()
@@ -254,7 +254,7 @@ void AndroidManifestEditorIconWidget::copyIcon()
qCDebug(androidManifestEditorLog) << "Icon target path empty, cannot copy icon."; qCDebug(androidManifestEditorLog) << "Icon target path empty, cannot copy icon.";
return; return;
} }
QImage original(m_iconPath.toString()); QImage original(m_iconPath.toFSPathString());
if (m_iconPath != targetPath) if (m_iconPath != targetPath)
removeIcon(); removeIcon();
if (original.isNull()) { if (original.isNull()) {
@@ -277,7 +277,7 @@ void AndroidManifestEditorIconWidget::copyIcon()
else else
scaled = scaleWithoutStretching(original, m_iconSize); scaled = scaleWithoutStretching(original, m_iconSize);
setScaleWarningLabelVisible(scaled.width() > original.width() || scaled.height() > original.height()); setScaleWarningLabelVisible(scaled.width() > original.width() || scaled.height() > original.height());
scaled.save(targetPath.toString()); scaled.save(targetPath.toFSPathString());
m_iconPath = targetPath; m_iconPath = targetPath;
} else { } else {
m_iconPath.clear(); m_iconPath.clear();

View File

@@ -103,7 +103,7 @@ bool AndroidPackageInstallationStep::init()
QString AndroidPackageInstallationStep::nativeAndroidBuildPath() const QString AndroidPackageInstallationStep::nativeAndroidBuildPath() const
{ {
QString buildPath = AndroidManager::androidBuildDirectory(target()).toString(); QString buildPath = AndroidManager::androidBuildDirectory(target()).toFSPathString();
if (HostOsInfo::isWindowsHost()) if (HostOsInfo::isWindowsHost())
if (buildEnvironment().searchInPath("sh.exe").isEmpty()) if (buildEnvironment().searchInPath("sh.exe").isEmpty())
buildPath = QDir::toNativeSeparators(buildPath); buildPath = QDir::toNativeSeparators(buildPath);

View File

@@ -659,8 +659,8 @@ static ExecutableItem uploadDebugServerRecipe(RunnerStorage *storage, const QStr
}; };
const auto onServerUploadSetup = [storage, tempDebugServerPathStorage](Process &process) { const auto onServerUploadSetup = [storage, tempDebugServerPathStorage](Process &process) {
process.setCommand( process.setCommand(storage->adbCommand(
storage->adbCommand({"push", storage->m_debugServerPath.toString(), *tempDebugServerPathStorage})); {"push", storage->m_debugServerPath.path(), *tempDebugServerPathStorage}));
}; };
const auto onServerCopySetup = [storage, tempDebugServerPathStorage, debugServerFileName](Process &process) { const auto onServerCopySetup = [storage, tempDebugServerPathStorage, debugServerFileName](Process &process) {

View File

@@ -65,22 +65,23 @@ static FilePath sdkFromUrl(const QUrl &url)
// TODO: Make it a separate async task in a chain? // TODO: Make it a separate async task in a chain?
static std::optional<QString> saveToDisk(const FilePath &filename, QIODevice *data) static std::optional<QString> saveToDisk(const FilePath &filename, QIODevice *data)
{ {
QFile file(filename.toString()); const expected_str<qint64> result = filename.writeFileContents(data->readAll());
if (!file.open(QIODevice::WriteOnly)) { if (!result) {
return Tr::tr("Could not open \"%1\" for writing: %2.") 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 {}; return {};
} }
static void validateFileIntegrity(QPromise<void> &promise, const FilePath &fileName, static void validateFileIntegrity(QPromise<void> &promise, const FilePath &fileName,
const QByteArray &sha256) const QByteArray &sha256)
{ {
QFile file(fileName.toString()); const expected_str<QByteArray> result = fileName.fileContents();
if (file.open(QFile::ReadOnly)) { if (result) {
QCryptographicHash hash(QCryptographicHash::Sha256); QCryptographicHash hash(QCryptographicHash::Sha256);
if (hash.addData(&file) && hash.result() == sha256) hash.addData(*result);
if (hash.result() == sha256)
return; return;
} }
promise.future().cancel(); promise.future().cancel();

View File

@@ -115,7 +115,7 @@ private:
static QString sdkRootArg() static QString sdkRootArg()
{ {
return "--sdk_root=" + AndroidConfig::sdkLocation().toString(); return "--sdk_root=" + AndroidConfig::sdkLocation().path();
} }
const QRegularExpression &assertionRegExp() const QRegularExpression &assertionRegExp()

View File

@@ -41,8 +41,9 @@ public:
m_argumentDetailsEdit->setReadOnly(true); m_argumentDetailsEdit->setReadOnly(true);
m_process.setEnvironment(AndroidConfig::toolsEnvironment()); m_process.setEnvironment(AndroidConfig::toolsEnvironment());
m_process.setCommand({AndroidConfig::sdkManagerToolPath(), m_process.setCommand(
{"--help", "--sdk_root=" + AndroidConfig::sdkLocation().toString()}}); {AndroidConfig::sdkManagerToolPath(),
{"--help", "--sdk_root=" + AndroidConfig::sdkLocation().path()}});
connect(&m_process, &Process::done, this, [this] { connect(&m_process, &Process::done, this, [this] {
const QString output = m_process.allOutput(); const QString output = m_process.allOutput();
QString argumentDetails; QString argumentDetails;

View File

@@ -711,16 +711,14 @@ void AndroidSettingsWidget::downloadOpenSslRepo(const bool silent)
return; return;
} }
QDir openSslDir(openSslPath.toString()); if (openSslPath.exists() && !openSslPath.isEmpty()) {
const bool isEmptyDir = openSslDir.isEmpty(QDir::AllEntries | QDir::NoDotAndDotDot
| QDir::Hidden | QDir::System);
if (openSslDir.exists() && !isEmptyDir) {
QMessageBox::information( QMessageBox::information(
this, this,
openSslCloneTitle, openSslCloneTitle,
Tr::tr("The selected download path (%1) for OpenSSL already exists and the directory is " Tr::tr(
"not empty. Select a different path or make sure it is an empty directory.") "The selected download path (%1) for OpenSSL already exists and the directory is "
.arg(QDir::toNativeSeparators(openSslPath.toString()))); "not empty. Select a different path or make sure it is an empty directory.")
.arg(openSslPath.toUserOutput()));
return; return;
} }
@@ -733,8 +731,8 @@ void AndroidSettingsWidget::downloadOpenSslRepo(const bool silent)
const QString openSslRepo("https://github.com/KDAB/android_openssl.git"); const QString openSslRepo("https://github.com/KDAB/android_openssl.git");
Process *gitCloner = new Process(this); Process *gitCloner = new Process(this);
const CommandLine gitCloneCommand("git", {"clone", "--depth=1", openSslRepo, const CommandLine
openSslPath.toString()}); gitCloneCommand("git", {"clone", "--depth=1", openSslRepo, openSslPath.path()});
gitCloner->setCommand(gitCloneCommand); gitCloner->setCommand(gitCloneCommand);
qCDebug(androidsettingswidget) << "Cloning OpenSSL repo: " << gitCloneCommand.toUserOutput(); qCDebug(androidsettingswidget) << "Cloning OpenSSL repo: " << gitCloneCommand.toUserOutput();

View File

@@ -68,7 +68,7 @@ AndroidToolchain::~AndroidToolchain() = default;
bool AndroidToolchain::isValid() const bool AndroidToolchain::isValid() const
{ {
if (m_ndkLocation.isEmpty()) { if (m_ndkLocation.isEmpty()) {
QStringList ndkParts(compilerCommand().toString().split("toolchains/llvm/prebuilt/")); QStringList ndkParts(compilerCommand().toFSPathString().split("toolchains/llvm/prebuilt/"));
if (ndkParts.size() > 1) { if (ndkParts.size() > 1) {
QString ndkLocation(ndkParts.first()); QString ndkLocation(ndkParts.first());
if (ndkLocation.endsWith('/')) if (ndkLocation.endsWith('/'))

View File

@@ -60,7 +60,7 @@ static std::optional<AndroidDeviceInfo> parseAvd(const QStringList &deviceInfo)
if (avdPath.exists()) { if (avdPath.exists()) {
// Get ABI. // Get ABI.
const Utils::FilePath configFile = avdPath.pathAppended("config.ini"); 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(); value = config.value(avdInfoAbiKey).toString();
if (!value.isEmpty()) if (!value.isEmpty())
avd.cpuAbi << value; avd.cpuAbi << value;
@@ -71,13 +71,13 @@ static std::optional<AndroidDeviceInfo> parseAvd(const QStringList &deviceInfo)
const QString avdInfoFileName = avd.avdName + ".ini"; const QString avdInfoFileName = avd.avdName + ".ini";
const Utils::FilePath avdInfoFile = avdPath.parentDir().pathAppended( const Utils::FilePath avdInfoFile = avdPath.parentDir().pathAppended(
avdInfoFileName); avdInfoFileName);
QSettings avdInfo(avdInfoFile.toString(), QSettings::IniFormat); QSettings avdInfo(avdInfoFile.toFSPathString(), QSettings::IniFormat);
value = avdInfo.value(avdInfoTargetKey).toString(); value = avdInfo.value(avdInfoTargetKey).toString();
if (!value.isEmpty()) if (!value.isEmpty())
avd.sdk = platformNameToApiLevel(value); avd.sdk = platformNameToApiLevel(value);
else else
qCDebug(avdOutputParserLog) qCDebug(avdOutputParserLog)
<< "Avd Parsing: Cannot find sdk API:" << avdInfoFile.toString(); << "Avd Parsing: Cannot find sdk API:" << avdInfoFile.toUserOutput();
} }
} }
} }

View File

@@ -306,9 +306,9 @@ void CreateAndroidManifestWizard::createAndroidTemplateFiles()
if (androidPackageDir.isEmpty()) { if (androidPackageDir.isEmpty()) {
// and now time for some magic // and now time for some magic
const BuildTargetInfo bti = target->buildTarget(m_buildKey); const BuildTargetInfo bti = target->buildTarget(m_buildKey);
const QString value = "$$PWD/" const QString value
+ bti.projectFilePath.toFileInfo().absoluteDir().relativeFilePath( = "$$PWD/"
m_directory.toString()); + bti.projectFilePath.absoluteFilePath().relativePathFrom(m_directory).path();
bool result = node->setData(Android::Constants::AndroidPackageSourceDir, value); bool result = node->setData(Android::Constants::AndroidPackageSourceDir, value);
if (!result) { if (!result) {

View File

@@ -120,7 +120,7 @@ bool JLSSettings::applyFromSettingsWidget(QWidget *widget)
configDir.cd("config_mac"); configDir.cd("config_mac");
} }
if (configDir.exists()) { if (configDir.exists()) {
arguments = arguments.arg(m_languageServer.toString(), configDir.absolutePath()); arguments = arguments.arg(m_languageServer.path(), configDir.absolutePath());
changed |= m_arguments != arguments; changed |= m_arguments != arguments;
m_arguments = arguments; m_arguments = arguments;
} }
@@ -219,7 +219,7 @@ static void generateProjectFile(const FilePath &projectDir,
const QString &projectName) const QString &projectName)
{ {
const FilePath projectFilePath = projectDir.pathAppended(".project"); const FilePath projectFilePath = projectDir.pathAppended(".project");
QFile projectFile(projectFilePath.toString()); QFile projectFile(projectFilePath.toFSPathString());
if (projectFile.open(QFile::Truncate | QFile::WriteOnly)) { if (projectFile.open(QFile::Truncate | QFile::WriteOnly)) {
QXmlStreamWriter writer(&projectFile); QXmlStreamWriter writer(&projectFile);
writer.setAutoFormatting(true); writer.setAutoFormatting(true);
@@ -249,7 +249,7 @@ static void generateClassPathFile(const FilePath &projectDir,
const FilePaths &libs) const FilePaths &libs)
{ {
const FilePath classPathFilePath = projectDir.pathAppended(".classpath"); const FilePath classPathFilePath = projectDir.pathAppended(".classpath");
QFile classPathFile(classPathFilePath.toString()); QFile classPathFile(classPathFilePath.toFSPathString());
if (classPathFile.open(QFile::Truncate | QFile::WriteOnly)) { if (classPathFile.open(QFile::Truncate | QFile::WriteOnly)) {
QXmlStreamWriter writer(&classPathFile); QXmlStreamWriter writer(&classPathFile);
writer.setAutoFormatting(true); writer.setAutoFormatting(true);
@@ -259,14 +259,14 @@ static void generateClassPathFile(const FilePath &projectDir,
writer.writeStartElement("classpath"); writer.writeStartElement("classpath");
writer.writeEmptyElement("classpathentry"); writer.writeEmptyElement("classpathentry");
writer.writeAttribute("kind", "src"); writer.writeAttribute("kind", "src");
writer.writeAttribute("path", sourceDir.toString()); writer.writeAttribute("path", sourceDir.toUserOutput());
writer.writeEmptyElement("classpathentry"); writer.writeEmptyElement("classpathentry");
writer.writeAttribute("kind", "src"); writer.writeAttribute("kind", "src");
writer.writeAttribute("path", "qtSrc"); writer.writeAttribute("path", "qtSrc");
for (const FilePath &lib : libs) { for (const FilePath &lib : libs) {
writer.writeEmptyElement("classpathentry"); writer.writeEmptyElement("classpathentry");
writer.writeAttribute("kind", "lib"); writer.writeAttribute("kind", "lib");
writer.writeAttribute("path", lib.toString()); writer.writeAttribute("path", lib.toUserOutput());
} }
writer.writeEndElement(); // classpath writer.writeEndElement(); // classpath
writer.writeEndDocument(); writer.writeEndDocument();
@@ -286,7 +286,7 @@ void JLSClient::updateProjectFiles()
QtSupport::QtVersion *version = QtSupport::QtKitAspect::qtVersion(kit); QtSupport::QtVersion *version = QtSupport::QtKitAspect::qtVersion(kit);
if (!version) if (!version)
return; 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(); const FilePath &projectDir = project()->rootProjectDirectory();
if (!projectDir.exists()) if (!projectDir.exists())
return; return;
@@ -315,7 +315,7 @@ void JLSClient::updateProjectFiles()
for (const QString &path : classPaths) for (const QString &path : classPaths)
libs << FilePath::fromString(path); libs << FilePath::fromString(path);
generateProjectFile(projectDir, qtSrc, project()->displayName()); generateProjectFile(projectDir, qtSrc.path(), project()->displayName());
generateClassPathFile(projectDir, sourceDir, libs); generateClassPathFile(projectDir, sourceDir, libs);
} }
} }

View File

@@ -47,11 +47,11 @@ OutputLineParser::Result JavaParser::handleLine(const QString &line, OutputForma
FilePath file = FilePath::fromUserInput(match.captured(2)); FilePath file = FilePath::fromUserInput(match.captured(2));
if (file.isChildOf(m_buildDirectory)) { if (file.isChildOf(m_buildDirectory)) {
FilePath relativePath = file.relativeChildPath(m_buildDirectory); FilePath relativePath = file.relativeChildPath(m_buildDirectory);
file = m_sourceDirectory.pathAppended(relativePath.toString()); file = m_sourceDirectory.resolvePath(relativePath);
} }
if (file.toFileInfo().isRelative()) { if (file.toFileInfo().isRelative()) {
for (int i = 0; i < m_fileList.size(); i++) 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]; file = m_fileList[i];
break; break;
} }

View File

@@ -225,7 +225,7 @@ void SplashScreenWidget::setImageFromPath(const FilePath &imagePath, bool resize
qCDebug(androidManifestEditorLog) << "Image target path is empty, cannot set image."; qCDebug(androidManifestEditorLog) << "Image target path is empty, cannot set image.";
return; return;
} }
QImage image = QImage(imagePath.toString()); QImage image = QImage(imagePath.toFSPathString());
if (image.isNull()) { if (image.isNull()) {
qCDebug(androidManifestEditorLog) << "Image '" << imagePath << "' not found or invalid format."; qCDebug(androidManifestEditorLog) << "Image '" << imagePath << "' not found or invalid format.";
return; return;
@@ -239,7 +239,7 @@ void SplashScreenWidget::setImageFromPath(const FilePath &imagePath, bool resize
(float(image.height()) / float(m_maxScalingRatio)) * float(m_scalingRatio)); (float(image.height()) / float(m_maxScalingRatio)) * float(m_scalingRatio));
image = image.scaled(size); image = image.scaled(size);
} }
QFile file(targetPath.toString()); QFile file(targetPath.toFSPathString());
if (file.open(QIODevice::WriteOnly | QIODevice::Truncate)) { if (file.open(QIODevice::WriteOnly | QIODevice::Truncate)) {
image.save(&file, "PNG"); image.save(&file, "PNG");
file.close(); file.close();
@@ -296,7 +296,7 @@ void SplashScreenWidget::loadImage()
qCDebug(androidManifestEditorLog) << "Image target path empty, cannot load image."; qCDebug(androidManifestEditorLog) << "Image target path empty, cannot load image.";
return; return;
} }
QImage image = QImage(targetPath.toString()); QImage image = QImage(targetPath.toFSPathString());
if (image.isNull()) { if (image.isNull()) {
qCDebug(androidManifestEditorLog).noquote() qCDebug(androidManifestEditorLog).noquote()
<< "Cannot load image." << targetPath.toUserOutput(); << "Cannot load image." << targetPath.toUserOutput();
@@ -655,7 +655,7 @@ void SplashScreenContainerWidget::loadImages()
void SplashScreenContainerWidget::loadSplashscreenDrawParams(const QString &name) void SplashScreenContainerWidget::loadSplashscreenDrawParams(const QString &name)
{ {
const FilePath filePath = manifestDir(m_textEditorWidget).pathAppended("res/drawable/" + name + ".xml"); 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)) { if (file.open(QIODevice::ReadOnly | QIODevice::Text)) {
QXmlStreamReader reader(&file); QXmlStreamReader reader(&file);
reader.setNamespaceProcessing(false); reader.setNamespaceProcessing(false);
@@ -773,13 +773,13 @@ void SplashScreenContainerWidget::setImageShowMode(const QString &mode)
void SplashScreenContainerWidget::createSplashscreenThemes() void SplashScreenContainerWidget::createSplashscreenThemes()
{ {
const QString baseDir = manifestDir(m_textEditorWidget).toString(); const FilePath baseDir = manifestDir(m_textEditorWidget);
const QStringList splashscreenThemeFiles = {"/res/values/splashscreentheme.xml", const QStringList splashscreenThemeFiles = {"res/values/splashscreentheme.xml",
"/res/values-port/splashscreentheme.xml", "res/values-port/splashscreentheme.xml",
"/res/values-land/splashscreentheme.xml"}; "res/values-land/splashscreentheme.xml"};
const QStringList splashscreenDrawableFiles = {QString("/res/drawable/%1.xml").arg(splashscreenName), const QStringList splashscreenDrawableFiles = {QString("res/drawable/%1.xml").arg(splashscreenName),
QString("/res/drawable/%1.xml").arg(splashscreenPortraitName), QString("res/drawable/%1.xml").arg(splashscreenPortraitName),
QString("/res/drawable/%1.xml").arg(splashscreenLandscapeName)}; QString("res/drawable/%1.xml").arg(splashscreenLandscapeName)};
QStringList splashscreens[3]; QStringList splashscreens[3];
if (hasImages()) if (hasImages())
@@ -790,9 +790,11 @@ void SplashScreenContainerWidget::createSplashscreenThemes()
splashscreens[2] << splashscreenLandscapeName << splashscreenLandscapeFileName; splashscreens[2] << splashscreenLandscapeName << splashscreenLandscapeFileName;
for (int i = 0; i < 3; i++) { 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()) { if (!splashscreens[i].isEmpty()) {
QDir dir; QDir dir;
QFile themeFile(baseDir + splashscreenThemeFiles[i]); QFile themeFile(splashscreenThemeFile.toFSPathString());
dir.mkpath(QFileInfo(themeFile).absolutePath()); dir.mkpath(QFileInfo(themeFile).absolutePath());
if (themeFile.open(QFile::WriteOnly | QFile::Truncate)) { if (themeFile.open(QFile::WriteOnly | QFile::Truncate)) {
QXmlStreamWriter stream(&themeFile); QXmlStreamWriter stream(&themeFile);
@@ -810,7 +812,7 @@ void SplashScreenContainerWidget::createSplashscreenThemes()
stream.writeEndDocument(); stream.writeEndDocument();
themeFile.close(); themeFile.close();
} }
QFile drawableFile(baseDir + splashscreenDrawableFiles[i]); QFile drawableFile(splashscreenDrawableFile.toFSPathString());
dir.mkpath(QFileInfo(drawableFile).absolutePath()); dir.mkpath(QFileInfo(drawableFile).absolutePath());
if (drawableFile.open(QFile::WriteOnly | QFile::Truncate)) { if (drawableFile.open(QFile::WriteOnly | QFile::Truncate)) {
QXmlStreamWriter stream(&drawableFile); QXmlStreamWriter stream(&drawableFile);
@@ -836,8 +838,8 @@ void SplashScreenContainerWidget::createSplashscreenThemes()
} }
} }
else { else {
QFile::remove(baseDir + splashscreenThemeFiles[i]); QFile::remove(splashscreenThemeFile.toFSPathString());
QFile::remove(baseDir + splashscreenDrawableFiles[i]); QFile::remove(splashscreenDrawableFile.toFSPathString());
} }
} }
} }