Fix conversion to/from QString/QByteArray

BUG: 384321
This commit is contained in:
Andrius Štikonas 2017-12-03 12:37:21 +00:00
parent f1a695bdac
commit 4bf5bb467f
9 changed files with 31 additions and 31 deletions

View File

@ -335,7 +335,7 @@ bool Partition::unmount(Report& report)
const QString canonicalDeviceNode = QFileInfo(deviceNode()).canonicalFilePath();
const QList<QStorageInfo> mountedVolumes = QStorageInfo::mountedVolumes();
for (const QStorageInfo &storage : mountedVolumes) {
if (QFileInfo(QString::fromUtf8(storage.device())).canonicalFilePath() == canonicalDeviceNode ) {
if (QFileInfo(QString::fromLocal8Bit(storage.device())).canonicalFilePath() == canonicalDeviceNode ) {
success = false;
break;
}

View File

@ -77,9 +77,9 @@ void SmartStatus::update()
if (sk_disk_identify_parse(skDisk, &skIdentify) < 0)
qDebug() << "getting identify data failed for " << devicePath() << ": " << strerror(errno);
else {
setModelName(QString::fromUtf8(skIdentify->model));
setFirmware(QString::fromUtf8(skIdentify->firmware));
setSerial(QString::fromUtf8(skIdentify->serial));
setModelName(QString::fromLocal8Bit(skIdentify->model));
setFirmware(QString::fromLocal8Bit(skIdentify->firmware));
setSerial(QString::fromLocal8Bit(skIdentify->serial));
}
const SkSmartParsedData* skParsed;

View File

@ -110,7 +110,7 @@ static QString readBlkIdValue(const QString& deviceNode, const QString& tag)
char* label = nullptr;
if ((dev = blkid_get_dev(cache, deviceNode.toLocal8Bit().constData(), BLKID_DEV_NORMAL)) != nullptr &&
(label = blkid_get_tag_value(cache, tag.toLocal8Bit().constData(), deviceNode.toLocal8Bit().constData()))) {
rval = QString::fromUtf8(label);
rval = QString::fromLocal8Bit(label);
free(label);
}
@ -138,7 +138,7 @@ QString FileSystem::detectMountPoint(FileSystem* fs, const QString& partitionPat
QString partitionCanonicalPath = partitionPathFileInfo.canonicalFilePath();
const QList<QStorageInfo> mountedVolumes = QStorageInfo::mountedVolumes();
for (const QStorageInfo &storage : mountedVolumes) {
if (partitionCanonicalPath == QFileInfo(QString::fromUtf8(storage.device())).canonicalFilePath() ) {
if (partitionCanonicalPath == QFileInfo(QString::fromLocal8Bit(storage.device())).canonicalFilePath() ) {
mountPoints.append(storage.rootPath());
}
}

View File

@ -128,7 +128,7 @@ bool luks::create(Report& report, const QString& deviceNode)
QStringLiteral("luksFormat"),
deviceNode });
if (!( createCmd.start(-1) &&
createCmd.write(m_passphrase.toUtf8() + '\n') == m_passphrase.toUtf8().length() + 1 &&
createCmd.write(m_passphrase.toLocal8Bit() + '\n') == m_passphrase.toLocal8Bit().length() + 1 &&
createCmd.waitFor() && createCmd.exitCode() == 0))
{
return false;
@ -139,7 +139,7 @@ bool luks::create(Report& report, const QString& deviceNode)
deviceNode,
suggestedMapperName(deviceNode) });
if (!( openCmd.start(-1) && openCmd.write(m_passphrase.toUtf8() + '\n') == m_passphrase.toUtf8().length() + 1 && openCmd.waitFor()))
if (!( openCmd.start(-1) && openCmd.write(m_passphrase.toLocal8Bit() + '\n') == m_passphrase.toLocal8Bit().length() + 1 && openCmd.waitFor()))
return false;
scan(deviceNode);
@ -262,7 +262,7 @@ bool luks::cryptOpen(QWidget* parent, const QString& deviceNode)
suggestedMapperName(deviceNode) });
if (!( openCmd.start(-1) &&
openCmd.write(passphrase.toUtf8() + '\n') == passphrase.toUtf8().length() + 1 &&
openCmd.write(passphrase.toLocal8Bit() + '\n') == passphrase.toLocal8Bit().length() + 1 &&
openCmd.waitFor() && openCmd.exitCode() == 0) )
return false;
@ -572,7 +572,7 @@ void luks::getMapperName(const QString& deviceNode)
m_MapperName = QString();
if (cmd.run(-1) && cmd.exitCode() == 0) {
const QJsonDocument jsonDocument = QJsonDocument::fromJson(cmd.output().toUtf8());
const QJsonDocument jsonDocument = QJsonDocument::fromJson(cmd.output().toLocal8Bit());
QJsonObject jsonObject = jsonDocument.object();
const QJsonArray jsonArray = jsonObject[QLatin1String("blockdevices")].toArray();
for (const auto &deviceLine : jsonArray) {

View File

@ -107,7 +107,7 @@ typedef struct _GPTDiskData GPTDiskData;
*/
static qint64 firstUsableSector(const Device& d)
{
PedDevice* pedDevice = ped_device_get(d.deviceNode().toLatin1().constData());
PedDevice* pedDevice = ped_device_get(d.deviceNode().toLocal8Bit().constData());
PedDisk* pedDisk = pedDevice ? ped_disk_new(pedDevice) : nullptr;
qint64 rval = 0;
@ -135,7 +135,7 @@ static qint64 firstUsableSector(const Device& d)
*/
static qint64 lastUsableSector(const Device& d)
{
PedDevice* pedDevice = ped_device_get(d.deviceNode().toLatin1().constData());
PedDevice* pedDevice = ped_device_get(d.deviceNode().toLocal8Bit().constData());
PedDisk* pedDisk = pedDevice ? ped_disk_new(pedDevice) : nullptr;
qint64 rval = 0;
@ -305,7 +305,7 @@ void LibPartedBackend::scanDevicePartitions(Device& d, PedDisk* pedDisk)
FileSystem::Type type = FileSystem::Unknown;
char* pedPath = ped_partition_get_path(pedPartition);
const QString partitionNode = pedPath ? QString::fromUtf8(pedPath) : QString();
const QString partitionNode = pedPath ? QString::fromLocal8Bit(pedPath) : QString();
free(pedPath);
type = detectFileSystem(partitionNode);
@ -393,14 +393,14 @@ DiskDevice* LibPartedBackend::scanDevice(const QString& deviceNode)
return nullptr;
}
Log(Log::information) << xi18nc("@info:status", "Device found: %1", QString::fromUtf8(pedDevice->model));
Log(Log::information) << xi18nc("@info:status", "Device found: %1", QString::fromLocal8Bit(pedDevice->model));
DiskDevice* d = new DiskDevice(QString::fromUtf8(pedDevice->model), QString::fromUtf8(pedDevice->path), pedDevice->bios_geom.heads, pedDevice->bios_geom.sectors, pedDevice->bios_geom.cylinders, pedDevice->sector_size);
DiskDevice* d = new DiskDevice(QString::fromLocal8Bit(pedDevice->model), QString::fromLocal8Bit(pedDevice->path), pedDevice->bios_geom.heads, pedDevice->bios_geom.sectors, pedDevice->bios_geom.cylinders, pedDevice->sector_size);
PedDisk* pedDisk = ped_disk_new(pedDevice);
if (pedDisk) {
const PartitionTable::TableType type = PartitionTable::nameToTableType(QString::fromUtf8(pedDisk->type->name));
const PartitionTable::TableType type = PartitionTable::nameToTableType(QString::fromLocal8Bit(pedDisk->type->name));
CoreBackend::setPartitionTableForDevice(*d, new PartitionTable(type, firstUsableSector(*d), lastUsableSector(*d)));
CoreBackend::setPartitionTableMaxPrimaries(*d->partitionTable(), ped_disk_get_max_primary_partition_count(pedDisk));
@ -426,7 +426,7 @@ QList<Device*> LibPartedBackend::scanDevices(bool excludeReadOnly)
QStringLiteral("type,name") });
if (cmd.run(-1) && cmd.exitCode() == 0) {
const QJsonDocument jsonDocument = QJsonDocument::fromJson(cmd.output().toUtf8());
const QJsonDocument jsonDocument = QJsonDocument::fromJson(cmd.output().toLocal8Bit());
QJsonObject jsonObject = jsonDocument.object();
const QJsonArray jsonArray = jsonObject[QLatin1String("blockdevices")].toArray();
for (const auto &deviceLine : jsonArray) {
@ -479,7 +479,7 @@ FileSystem::Type LibPartedBackend::detectFileSystem(const QString& partitionPath
partitionPath.toLocal8Bit().constData(),
BLKID_DEV_NORMAL)) != nullptr) {
char *string = blkid_get_tag_value(cache, "TYPE", partitionPath.toLocal8Bit().constData());
QString s = QString::fromUtf8(string);
QString s = QString::fromLocal8Bit(string);
free(string);
if (s == QStringLiteral("ext2")) rval = FileSystem::Ext2;
@ -497,7 +497,7 @@ FileSystem::Type LibPartedBackend::detectFileSystem(const QString& partitionPath
else if (s == QStringLiteral("vfat")) {
// libblkid uses SEC_TYPE to distinguish between FAT16 and FAT32
string = blkid_get_tag_value(cache, "SEC_TYPE", partitionPath.toLocal8Bit().constData());
QString st = QString::fromUtf8(string);
QString st = QString::fromLocal8Bit(string);
free(string);
if (st == QStringLiteral("msdos"))
rval = FileSystem::Fat16;

View File

@ -45,7 +45,7 @@ bool LibPartedDevice::open()
if (pedDevice())
return false;
m_PedDevice = ped_device_get(deviceNode().toLatin1().constData());
m_PedDevice = ped_device_get(deviceNode().toLocal8Bit().constData());
return m_PedDevice != nullptr;
}
@ -87,14 +87,14 @@ CoreBackendPartitionTable* LibPartedDevice::openPartitionTable()
bool LibPartedDevice::createPartitionTable(Report& report, const PartitionTable& ptable)
{
PedDiskType* pedDiskType = ped_disk_type_get(ptable.typeName().toLatin1().constData());
PedDiskType* pedDiskType = ped_disk_type_get(ptable.typeName().toLocal8Bit().constData());
if (pedDiskType == nullptr) {
report.line() << xi18nc("@info:progress", "Creating partition table failed: Could not retrieve partition table type \"%1\" for <filename>%2</filename>.", ptable.typeName(), deviceNode());
return false;
}
PedDevice* dev = ped_device_get(deviceNode().toLatin1().constData());
PedDevice* dev = ped_device_get(deviceNode().toLocal8Bit().constData());
if (dev == nullptr) {
report.line() << xi18nc("@info:progress", "Creating partition table failed: Could not open backend device <filename>%1</filename>.", deviceNode());

View File

@ -125,7 +125,7 @@ static PedFileSystemType* getPedFileSystemType(FileSystem::Type t)
{
for (quint32 i = 0; i < sizeof(mapFileSystemTypeToLibPartedName) / sizeof(mapFileSystemTypeToLibPartedName[0]); i++)
if (mapFileSystemTypeToLibPartedName[i].type == t)
return ped_file_system_type_get(mapFileSystemTypeToLibPartedName[i].name.toLatin1().constData());
return ped_file_system_type_get(mapFileSystemTypeToLibPartedName[i].name.toLocal8Bit().constData());
// if we didn't find anything, go with ext2 as a safe fallback
return ped_file_system_type_get("ext2");
@ -133,7 +133,7 @@ static PedFileSystemType* getPedFileSystemType(FileSystem::Type t)
QString LibPartedPartitionTable::createPartition(Report& report, const Partition& partition)
{
Q_ASSERT(partition.devicePath() == QString::fromUtf8(pedDevice()->path));
Q_ASSERT(partition.devicePath() == QString::fromLocal8Bit(pedDevice()->path));
QString rval = QString();
@ -177,11 +177,11 @@ QString LibPartedPartitionTable::createPartition(Report& report, const Partition
if (ped_disk_add_partition(pedDisk(), pedPartition, pedConstraint)) {
char *pedPath = ped_partition_get_path(pedPartition);
rval = QString::fromUtf8(pedPath);
rval = QString::fromLocal8Bit(pedPath);
free(pedPath);
}
else {
report.line() << xi18nc("@info:progress", "Failed to add partition <filename>%1</filename> to device <filename>%2</filename>.", partition.deviceNode(), QString::fromUtf8(pedDisk()->dev->path));
report.line() << xi18nc("@info:progress", "Failed to add partition <filename>%1</filename> to device <filename>%2</filename>.", partition.deviceNode(), QString::fromLocal8Bit(pedDisk()->dev->path));
report.line() << LibPartedBackend::lastPartedExceptionMessage();
}
@ -192,7 +192,7 @@ QString LibPartedPartitionTable::createPartition(Report& report, const Partition
bool LibPartedPartitionTable::deletePartition(Report& report, const Partition& partition)
{
Q_ASSERT(partition.devicePath() == QString::fromUtf8(pedDevice()->path));
Q_ASSERT(partition.devicePath() == QString::fromLocal8Bit(pedDevice()->path));
bool rval = false;
@ -213,7 +213,7 @@ bool LibPartedPartitionTable::deletePartition(Report& report, const Partition& p
bool LibPartedPartitionTable::updateGeometry(Report& report, const Partition& partition, qint64 sector_start, qint64 sector_end)
{
Q_ASSERT(partition.devicePath() == QString::fromUtf8(pedDevice()->path));
Q_ASSERT(partition.devicePath() == QString::fromLocal8Bit(pedDevice()->path));
bool rval = false;
@ -317,7 +317,7 @@ FileSystem::Type LibPartedPartitionTable::detectFileSystemBySector(Report& repor
char* pedPath = ped_partition_get_path(pedPartition);
FileSystem::Type type = FileSystem::Unknown;
if (pedPartition && pedPath)
type = CoreBackendManager::self()->backend()->detectFileSystem(QString::fromUtf8(pedPath));
type = CoreBackendManager::self()->backend()->detectFileSystem(QString::fromLocal8Bit(pedPath));
else
report.line() << xi18nc("@info:progress", "Could not determine file system of partition at sector %1 on device <filename>%2</filename>.", sector, device.deviceNode());
free(pedPath);

View File

@ -59,7 +59,7 @@ ExternalCommand::ExternalCommand(Report& report, const QString& cmd, const QStri
void ExternalCommand::setup(const QProcess::ProcessChannelMode processChannelMode)
{
setEnvironment(QStringList() << QStringLiteral("LC_ALL=C") << QStringLiteral("PATH=") + QString::fromUtf8(getenv("PATH")) << QStringLiteral("LVM_SUPPRESS_FD_WARNINGS=1"));
setEnvironment(QStringList() << QStringLiteral("LC_ALL=C") << QStringLiteral("PATH=") + QString::fromLocal8Bit(getenv("PATH")) << QStringLiteral("LVM_SUPPRESS_FD_WARNINGS=1"));
setProcessChannelMode(processChannelMode);
connect(this, qOverload<int, QProcess::ExitStatus>(&QProcess::finished), this, &ExternalCommand::onFinished);

View File

@ -71,7 +71,7 @@ QString HtmlReport::header()
struct utsname info;
uname(&info);
const QString unameString = QString::fromUtf8(info.sysname) + QStringLiteral(" ") + QString::fromUtf8(info.nodename) + QStringLiteral(" ") + QString::fromUtf8(info.release) + QStringLiteral(" ") + QString::fromUtf8(info.version) + QStringLiteral(" ") + QString::fromUtf8(info.machine);
const QString unameString = QString::fromLocal8Bit(info.sysname) + QStringLiteral(" ") + QString::fromLocal8Bit(info.nodename) + QStringLiteral(" ") + QString::fromLocal8Bit(info.release) + QStringLiteral(" ") + QString::fromLocal8Bit(info.version) + QStringLiteral(" ") + QString::fromLocal8Bit(info.machine);
s << "<table>\n"
<< tableLine(i18n("Date:"), QLocale().toString(QDateTime::currentDateTime(), QLocale::ShortFormat))