Disable automatic conversions from 8-bit strings

This commit is contained in:
Jonas Kvinge
2024-04-11 02:56:01 +02:00
parent 58944993b8
commit 0c6872b352
310 changed files with 2501 additions and 2332 deletions

View File

@@ -51,7 +51,7 @@ QString CddaLister::DeviceManufacturer(const QString &id) {
cdio_hwinfo_t cd_info;
if (cdio_get_hwinfo(cdio, &cd_info)) {
cdio_destroy(cdio);
return QString(cd_info.psz_vendor);
return QString::fromUtf8(cd_info.psz_vendor);
}
cdio_destroy(cdio);
return QString();
@@ -64,7 +64,7 @@ QString CddaLister::DeviceModel(const QString &id) {
cdio_hwinfo_t cd_info;
if (cdio_get_hwinfo(cdio, &cd_info)) {
cdio_destroy(cdio);
return QString(cd_info.psz_model);
return QString::fromUtf8(cd_info.psz_model);
}
cdio_destroy(cdio);
return QString();
@@ -85,15 +85,15 @@ QString CddaLister::MakeFriendlyName(const QString &id) {
cdio_hwinfo_t cd_info;
if (cdio_get_hwinfo(cdio, &cd_info)) {
cdio_destroy(cdio);
return QString(cd_info.psz_model);
return QString::fromUtf8(cd_info.psz_model);
}
cdio_destroy(cdio);
return QStringLiteral("CD (") + id + ")";
return QStringLiteral("CD (") + id + QLatin1Char(')');
}
QList<QUrl> CddaLister::MakeDeviceUrls(const QString &id) {
return QList<QUrl>() << QUrl("cdda://" + id);
return QList<QUrl>() << QUrl(QStringLiteral("cdda://") + id);
}
void CddaLister::UnmountDevice(const QString &id) {
@@ -116,14 +116,14 @@ bool CddaLister::Init() {
return false;
}
for (; *devices != nullptr; ++devices) {
QString device(*devices);
QString device = QString::fromUtf8(*devices);
QFileInfo device_info(device);
if (device_info.isSymLink()) {
device = device_info.symLinkTarget();
}
#ifdef Q_OS_MACOS
// Every track is detected as a separate device on Darwin. The raw disk looks like /dev/rdisk1
if (!device.contains(QRegularExpression("^/dev/rdisk[0-9]$"))) {
if (!device.contains(QRegularExpression(QStringLiteral("^/dev/rdisk[0-9]$")))) {
continue;
}
#endif

View File

@@ -82,7 +82,7 @@ void CddaSongLoader::LoadSongs() {
GError *error = nullptr;
cdda_ = gst_element_make_from_uri(GST_URI_SRC, "cdda://", nullptr, &error);
if (error) {
Error(QStringLiteral("%1: %2").arg(error->code).arg(error->message));
Error(QStringLiteral("%1: %2").arg(error->code).arg(QString::fromUtf8(error->message)));
}
if (!cdda_) return;
@@ -199,7 +199,7 @@ void CddaSongLoader::LoadSongs() {
gst_message_parse_tag(msg_tag, &tags);
char *string_mb = nullptr;
if (gst_tag_list_get_string(tags, GST_TAG_CDDA_MUSICBRAINZ_DISCID, &string_mb)) {
QString musicbrainz_discid(string_mb);
QString musicbrainz_discid = QString::fromUtf8(string_mb);
qLog(Info) << "MusicBrainz discid: " << musicbrainz_discid;
MusicBrainzClient *musicbrainz_client = new MusicBrainzClient(network_);

View File

@@ -60,7 +60,7 @@ ConnectedDevice::ConnectedDevice(const QUrl &url, DeviceLister *lister, const QS
backend_->moveToThread(app_->database()->thread());
qLog(Debug) << &*backend_ << "for device" << unique_id_ << "moved to thread" << app_->database()->thread();
if (url_.scheme() != "cdda") {
if (url_.scheme() != QStringLiteral("cdda")) {
QObject::connect(&*backend_, &CollectionBackend::TotalSongCountUpdated, this, &ConnectedDevice::BackendTotalSongCountUpdated);
}

View File

@@ -219,13 +219,13 @@ void DeviceDatabaseBackend::SetDeviceOptions(const int id, const QString &friend
QSqlDatabase db(db_->Connect());
SqlQuery q(db);
q.prepare(
q.prepare(QStringLiteral(
"UPDATE devices"
" SET friendly_name=:friendly_name,"
" icon=:icon_name,"
" transcode_mode=:transcode_mode,"
" transcode_format=:transcode_format"
" WHERE ROWID=:id");
" WHERE ROWID=:id"));
q.BindValue(QStringLiteral(":friendly_name"), friendly_name);
q.BindValue(QStringLiteral(":icon_name"), icon_name);
q.BindValue(QStringLiteral(":transcode_mode"), static_cast<int>(mode));

View File

@@ -64,7 +64,7 @@ void DeviceInfo::InitFromDb(const DeviceDatabaseBackend::Device &dev) {
transcode_format_ = dev.transcode_format_;
icon_name_ = dev.icon_name_;
QStringList unique_ids = dev.unique_id_.split(',');
QStringList unique_ids = dev.unique_id_.split(QLatin1Char(','));
for (const QString &id : unique_ids) {
backends_ << Backend(nullptr, id);
}

View File

@@ -223,9 +223,9 @@ QUrl DeviceLister::MakeUrlFromLocalPath(const QString &path) const {
}
bool DeviceLister::IsIpod(const QString &path) const {
return QFile::exists(path + "/iTunes_Control") ||
QFile::exists(path + "/iPod_Control") ||
QFile::exists(path + "/iTunes/iTunes_Control");
return QFile::exists(path + QStringLiteral("/iTunes_Control")) ||
QFile::exists(path + QStringLiteral("/iPod_Control")) ||
QFile::exists(path + QStringLiteral("/iTunes/iTunes_Control"));
}
QVariantList DeviceLister::GuessIconForPath(const QString &path) {
@@ -239,7 +239,7 @@ QVariantList DeviceLister::GuessIconForPath(const QString &path) {
const Itdb_IpodInfo *info = itdb_device_get_ipod_info(device);
if (info->ipod_model == ITDB_IPOD_MODEL_INVALID) {
ret << "device-ipod";
ret << QStringLiteral("device-ipod");
}
else {
QString model = GetIpodModel(info->ipod_model);
@@ -255,7 +255,7 @@ QVariantList DeviceLister::GuessIconForPath(const QString &path) {
}
if (ret.isEmpty()) {
ret << "device-ipod";
ret << QStringLiteral("device-ipod");
}
}
@@ -275,7 +275,7 @@ QVariantList DeviceLister::GuessIconForModel(const QString &vendor, const QStrin
QVariantList ret;
if (vendor.startsWith(QLatin1String("Google")) && model.contains(QLatin1String("Nexus"))) {
ret << "phone-google-nexus-one";
ret << QStringLiteral("phone-google-nexus-one");
}
return ret;

View File

@@ -245,7 +245,7 @@ void DeviceManager::LoadAllDevices() {
void DeviceManager::AddDeviceFromDB(DeviceInfo *info) {
QStringList icon_names = info->icon_name_.split(',');
QStringList icon_names = info->icon_name_.split(QLatin1Char(','));
QVariantList icons;
icons.reserve(icon_names.count());
for (const QString &icon_name : icon_names) {
@@ -279,7 +279,7 @@ QVariant DeviceManager::data(const QModelIndex &idx, int role) const {
if (!info) return QVariant();
switch (role) {
case Qt::DisplayRole: {
case Qt::DisplayRole:{
QString text;
if (!info->friendly_name_.isEmpty()) {
text = info->friendly_name_;
@@ -295,7 +295,7 @@ QVariant DeviceManager::data(const QModelIndex &idx, int role) const {
return text;
}
case Qt::DecorationRole: {
case Qt::DecorationRole:{
QPixmap pixmap = info->icon_.pixmap(kDeviceIconSize);
if (info->backends_.isEmpty() || !info->BestBackend() || !info->BestBackend()->lister_) {
@@ -360,7 +360,7 @@ QVariant DeviceManager::data(const QModelIndex &idx, int role) const {
if (!info->device_) return QVariant();
return QVariant::fromValue<SharedPtr<MusicStorage>>(info->device_);
case Role_MountPath: {
case Role_MountPath:{
if (!info->device_) return QVariant();
QString ret = info->device_->url().path();
@@ -604,17 +604,17 @@ SharedPtr<ConnectedDevice> DeviceManager::Connect(DeviceInfo *info) {
// If we get here it means that this URL scheme wasn't supported.
// If it was "ipod" or "mtp" then the user compiled out support and the device won't work properly.
if (url.scheme() == "mtp" || url.scheme() == "gphoto2") {
if (url.scheme() == QStringLiteral("mtp") || url.scheme() == QStringLiteral("gphoto2")) {
if (QMessageBox::critical(nullptr, tr("This device will not work properly"),
tr("This is an MTP device, but you compiled Strawberry without libmtp support.") + " " +
tr("This is an MTP device, but you compiled Strawberry without libmtp support.") + QStringLiteral(" ") +
tr("If you continue, this device will work slowly and songs copied to it may not work."),
QMessageBox::Abort, QMessageBox::Ignore) == QMessageBox::Abort)
return ret;
}
if (url.scheme() == "ipod") {
if (url.scheme() == QStringLiteral("ipod")) {
if (QMessageBox::critical(nullptr, tr("This device will not work properly"),
tr("This is an iPod, but you compiled Strawberry without libgpod support.") + " " +
tr("This is an iPod, but you compiled Strawberry without libgpod support.") + QStringLiteral(" ") +
tr("If you continue, this device will work slowly and songs copied to it may not work."),
QMessageBox::Abort, QMessageBox::Ignore) == QMessageBox::Abort)
return ret;

View File

@@ -139,7 +139,7 @@ void DeviceItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem &op
status_text = tr("Double click to open");
break;
case DeviceManager::State_Connected: {
case DeviceManager::State_Connected:{
QVariant song_count = idx.data(DeviceManager::Role_SongCount);
if (song_count.isValid()) {
int count = song_count.toInt();

View File

@@ -69,7 +69,7 @@ bool GioLister::DeviceInfo::is_suitable() const {
if (filesystem_type.isEmpty()) return true;
return filesystem_type != "udf" && filesystem_type != "smb" && filesystem_type != "cifs" && filesystem_type != "ssh" && filesystem_type != "isofs";
return filesystem_type != QStringLiteral("udf") && filesystem_type != QStringLiteral("smb") && filesystem_type != QStringLiteral("cifs") && filesystem_type != QStringLiteral("ssh") && filesystem_type != QStringLiteral("isofs");
}
@@ -189,9 +189,9 @@ QVariantMap GioLister::DeviceHardwareInfo(const QString &id) {
if (!devices_.contains(id)) return ret;
const DeviceInfo &info = devices_[id];
ret[QT_TR_NOOP("Mount point")] = info.mount_path;
ret[QT_TR_NOOP("Device")] = info.volume_unix_device;
ret[QT_TR_NOOP("URI")] = info.mount_uri;
ret[QStringLiteral(QT_TR_NOOP("Mount point"))] = info.mount_path;
ret[QStringLiteral(QT_TR_NOOP("Device"))] = info.volume_unix_device;
ret[QStringLiteral(QT_TR_NOOP("URI"))] = info.mount_uri;
return ret;
}
@@ -503,7 +503,7 @@ void GioLister::DeviceInfo::ReadMountInfo(GMount *mount) {
// Query the file's info for a filesystem ID
// Only afc devices (that I know of) give reliably unique IDs
if (filesystem_type == "afc") {
if (filesystem_type == QStringLiteral("afc")) {
error = nullptr;
info = g_file_query_info(root, G_FILE_ATTRIBUTE_ID_FILESYSTEM, G_FILE_QUERY_INFO_NONE, nullptr, &error);
if (error) {
@@ -528,7 +528,7 @@ void GioLister::DeviceInfo::ReadVolumeInfo(GVolume *volume) {
GFile *root = g_volume_get_activation_root(volume);
if (root) {
volume_root_uri = g_file_get_uri(root);
volume_root_uri = QString::fromUtf8(g_file_get_uri(root));
g_object_unref(root);
}

View File

@@ -195,12 +195,12 @@ bool GPodDevice::CopyToStorage(const CopyJob &job, QString &error_text) {
bool result = false;
if (!job.cover_image_.isNull()) {
#ifdef Q_OS_LINUX
QString temp_path = QStandardPaths::writableLocation(QStandardPaths::CacheLocation) + "/organize";
QString temp_path = QStandardPaths::writableLocation(QStandardPaths::CacheLocation) + QStringLiteral("/organize");
#else
QString temp_path = QStandardPaths::writableLocation(QStandardPaths::TempLocation);
#endif
if (!QDir(temp_path).exists()) QDir().mkpath(temp_path);
SharedPtr<QTemporaryFile> cover_file = make_shared<QTemporaryFile>(temp_path + "/track-albumcover-XXXXXX.jpg");
SharedPtr<QTemporaryFile> cover_file = make_shared<QTemporaryFile>(temp_path + QStringLiteral("/track-albumcover-XXXXXX.jpg"));
cover_file->setAutoRemove(true);
if (cover_file->open()) {
cover_file->close();
@@ -281,7 +281,7 @@ bool GPodDevice::WriteDatabase(QString &error_text) {
cover_files_.clear();
if (!success) {
if (error) {
error_text = tr("Writing database failed: %1").arg(error->message);
error_text = tr("Writing database failed: %1").arg(QString::fromUtf8(error->message));
g_error_free(error);
}
else {
@@ -327,17 +327,17 @@ bool GPodDevice::RemoveTrackFromITunesDb(const QString &path, const QString &rel
QString ipod_filename = path;
if (!relative_to.isEmpty() && path.startsWith(relative_to)) {
ipod_filename.remove(0, relative_to.length() + (relative_to.endsWith('/') ? -1 : 0));
ipod_filename.remove(0, relative_to.length() + (relative_to.endsWith(QLatin1Char('/')) ? -1 : 0));
}
ipod_filename.replace('/', ':');
ipod_filename.replace(QLatin1Char('/'), QLatin1Char(':'));
// Find the track in the itdb, identify it by its filename
Itdb_Track *track = nullptr;
for (GList *tracks = db_->tracks; tracks != nullptr; tracks = tracks->next) {
Itdb_Track *t = static_cast<Itdb_Track*>(tracks->data);
if (t->ipod_path == ipod_filename) {
if (QString::fromUtf8(t->ipod_path) == ipod_filename) {
track = t;
break;
}

View File

@@ -138,9 +138,9 @@ bool MacOsDeviceLister::Init() {
}
MTPDevice d;
d.vendor = "SanDisk";
d.vendor = QStringLiteral("SanDisk");
d.vendor_id = 0x781;
d.product = "Sansa Clip+";
d.product = QStringLiteral("Sansa Clip+");
d.product_id = 0x74d0;
d.quirks = 0x2 | 0x4 | 0x40 | 0x4000;
@@ -303,7 +303,7 @@ QString GetIconForDevice(io_object_t device) {
scoped_nsobject<NSURL> bundle_url(reinterpret_cast<NSURL*>(KextManagerCreateURLForBundleIdentifier(kCFAllocatorDefault, reinterpret_cast<CFStringRef>(bundle))));
QString path = QString::fromUtf8([[bundle_url path] UTF8String]);
path += "/Contents/Resources/";
path += QStringLiteral("/Contents/Resources/");
path += QString::fromUtf8([file UTF8String]);
return path;
}
@@ -314,10 +314,11 @@ QString GetIconForDevice(io_object_t device) {
QString GetSerialForDevice(io_object_t device) {
QString serial = GetUSBRegistryEntryString(device, CFSTR(kUSBSerialNumberString));
const QString serial = GetUSBRegistryEntryString(device, CFSTR(kUSBSerialNumberString));
if (!serial.isEmpty()) {
return "USB/" + serial;
return QStringLiteral("USB/") + serial;
}
return QString();
}
@@ -325,7 +326,7 @@ QString GetSerialForDevice(io_object_t device) {
QString GetSerialForMTPDevice(io_object_t device) {
scoped_nsobject<NSString> serial(reinterpret_cast<NSString*>(GetPropertyForDevice(device, CFSTR(kUSBSerialNumberString))));
return QString(QString("MTP/") + QString::fromUtf8([serial UTF8String]));
return QString(QStringLiteral("MTP/") + QString::fromUtf8([serial UTF8String]));
}
@@ -336,6 +337,7 @@ QString FindDeviceProperty(const QString &bsd_name, CFStringRef property) {
ScopedIOObject device(DADiskCopyIOMedia(disk.get()));
QString ret = GetUSBRegistryEntryString(device.get(), property);
return ret;
}
@@ -356,6 +358,7 @@ quint64 MacOsDeviceLister::GetFreeSpace(const QUrl &url) {
free_bytes += storage->FreeSpaceInBytes;
storage = storage->next;
}
return free_bytes;
}
@@ -412,7 +415,7 @@ void MacOsDeviceLister::DiskAddedCallback(DADiskRef disk, void *context) {
if ([[dict objectForKey:@"Removable"] intValue] == 1) {
QString serial = GetSerialForDevice(device.get());
if (!serial.isEmpty()) {
me->current_devices_[serial] = QString(DADiskGetBSDName(disk));
me->current_devices_[serial] = QString::fromLatin1(DADiskGetBSDName(disk));
emit me->DeviceAdded(serial);
}
}
@@ -467,6 +470,7 @@ bool DeviceRequest(IOUSBDeviceInterface **dev,
return false;
}
data->resize(req.wLenDone);
return true;
}
@@ -596,14 +600,14 @@ void MacOsDeviceLister::USBDeviceAddedCallback(void *refcon, io_iterator_t it) {
// Because this was designed by MS, the characters are in UTF-16 (LE?).
QString str = QString::fromUtf16(reinterpret_cast<char16_t*>(data.data() + 2), (data.size() / 2) - 2);
if (str.startsWith("MSFT100")) {
if (str.startsWith(QStringLiteral("MSFT100"))) {
// We got the OS descriptor!
char vendor_code = data[16];
ret = DeviceRequest(dev, kUSBIn, kUSBVendor, kUSBDevice, vendor_code, 0, 4, 256, &data);
if (!ret || data.at(0) != 0x28)
continue;
if (QString::fromLatin1(data.data() + 0x12, 3) != "MTP") {
if (QString::fromLatin1(data.data() + 0x12, 3) != QStringLiteral("MTP")) {
// Not quite.
continue;
}
@@ -613,7 +617,7 @@ void MacOsDeviceLister::USBDeviceAddedCallback(void *refcon, io_iterator_t it) {
continue;
}
if (QString::fromLatin1(data.data() + 0x12, 3) != "MTP") {
if (QString::fromLatin1(data.data() + 0x12, 3) != QStringLiteral("MTP")) {
// Not quite.
continue;
}
@@ -674,7 +678,7 @@ void MacOsDeviceLister::FoundMTPDevice(const MTPDevice &device, const QString &s
}
bool IsMTPSerial(const QString &serial) { return serial.startsWith("MTP"); }
bool IsMTPSerial(const QString &serial) { return serial.startsWith(QStringLiteral("MTP")); }
bool MacOsDeviceLister::IsCDDevice(const QString &serial) const {
return cd_devices_.contains(serial);
@@ -688,7 +692,7 @@ QString MacOsDeviceLister::MakeFriendlyName(const QString &serial) {
return device.product;
}
else {
return device.vendor + " " + device.product;
return device.vendor + QLatin1Char(' ') + device.product;
}
}
@@ -711,7 +715,7 @@ QString MacOsDeviceLister::MakeFriendlyName(const QString &serial) {
if (vendor.isEmpty()) {
return product;
}
return vendor + " " + product;
return vendor + QLatin1Char(' ') + product;
}
@@ -721,18 +725,18 @@ QList<QUrl> MacOsDeviceLister::MakeDeviceUrls(const QString &serial) {
const MTPDevice &device = mtp_devices_[serial];
QString str = QString::asprintf("gphoto2://usb-%d-%d/", device.bus, device.address);
QUrlQuery url_query;
url_query.addQueryItem("vendor", device.vendor);
url_query.addQueryItem("vendor_id", QString::number(device.vendor_id));
url_query.addQueryItem("product", device.product);
url_query.addQueryItem("product_id", QString::number(device.product_id));
url_query.addQueryItem("quirks", QString::number(device.quirks));
url_query.addQueryItem(QStringLiteral("vendor"), device.vendor);
url_query.addQueryItem(QStringLiteral("vendor_id"), QString::number(device.vendor_id));
url_query.addQueryItem(QStringLiteral("product"), device.product);
url_query.addQueryItem(QStringLiteral("product_id"), QString::number(device.product_id));
url_query.addQueryItem(QStringLiteral("quirks"), QString::number(device.quirks));
QUrl url(str);
url.setQuery(url_query);
return QList<QUrl>() << url;
}
if (IsCDDevice(serial)) {
return QList<QUrl>() << QUrl(QString("cdda:///dev/r" + serial));
return QList<QUrl>() << QUrl(QStringLiteral("cdda:///dev/r") + serial);
}
QString bsd_name = current_devices_[serial];
@@ -760,7 +764,7 @@ QVariantList MacOsDeviceLister::DeviceIcons(const QString &serial) {
}
if (IsCDDevice(serial)) {
return QVariantList() << "media-optical";
return QVariantList() << QStringLiteral("media-optical");
}
QString bsd_name = current_devices_[serial];

View File

@@ -226,7 +226,7 @@ bool MtpDevice::DeleteFromStorage(const DeleteJob &job) {
// Extract the ID from the song's URL
QString filename = job.metadata_.url().path();
filename.remove('/');
filename.remove(QLatin1Char('/'));
bool ok = false;
uint32_t id = filename.toUInt(&ok);

View File

@@ -57,6 +57,10 @@
using std::make_unique;
using std::make_shared;
namespace {
constexpr char kUDisks2Service[] = "org.freedesktop.UDisks2";
}
Udisks2Lister::Udisks2Lister(QObject *parent) : DeviceLister(parent) {}
Udisks2Lister::~Udisks2Lister() = default;
@@ -116,11 +120,11 @@ QVariantMap Udisks2Lister::DeviceHardwareInfo(const QString &id) {
QVariantMap result;
const PartitionData &data = device_data_[id];
result[QT_TR_NOOP("D-Bus path")] = data.dbus_path;
result[QT_TR_NOOP("Serial number")] = data.serial;
result[QT_TR_NOOP("Mount points")] = data.mount_paths.join(QStringLiteral(", "));
result[QT_TR_NOOP("Partition label")] = data.label;
result[QT_TR_NOOP("UUID")] = data.uuid;
result[QStringLiteral(QT_TR_NOOP("D-Bus path"))] = data.dbus_path;
result[QStringLiteral(QT_TR_NOOP("Serial number"))] = data.serial;
result[QStringLiteral(QT_TR_NOOP("Mount points"))] = data.mount_paths.join(QStringLiteral(", "));
result[QStringLiteral(QT_TR_NOOP("Partition label"))] = data.label;
result[QStringLiteral(QT_TR_NOOP("UUID"))] = data.uuid;
return result;
@@ -149,7 +153,7 @@ void Udisks2Lister::UnmountDevice(const QString &id) {
QReadLocker locker(&device_data_lock_);
if (!device_data_.contains(id)) return;
OrgFreedesktopUDisks2FilesystemInterface filesystem(udisks2_service_, device_data_[id].dbus_path, QDBusConnection::systemBus());
OrgFreedesktopUDisks2FilesystemInterface filesystem(QLatin1String(kUDisks2Service), device_data_[id].dbus_path, QDBusConnection::systemBus());
if (filesystem.isValid()) {
auto unmount_result = filesystem.Unmount(QVariantMap());
@@ -160,7 +164,7 @@ void Udisks2Lister::UnmountDevice(const QString &id) {
return;
}
OrgFreedesktopUDisks2DriveInterface drive(udisks2_service_, device_data_[id].dbus_drive_path, QDBusConnection::systemBus());
OrgFreedesktopUDisks2DriveInterface drive(QLatin1String(kUDisks2Service), device_data_[id].dbus_drive_path, QDBusConnection::systemBus());
if (drive.isValid()) {
auto eject_result = drive.Eject(QVariantMap());
@@ -185,7 +189,7 @@ void Udisks2Lister::UpdateDeviceFreeSpace(const QString &id) {
bool Udisks2Lister::Init() {
udisks2_interface_ = make_unique<OrgFreedesktopDBusObjectManagerInterface>(udisks2_service_, "/org/freedesktop/UDisks2", QDBusConnection::systemBus());
udisks2_interface_ = make_unique<OrgFreedesktopDBusObjectManagerInterface>(QLatin1String(kUDisks2Service), QStringLiteral("/org/freedesktop/UDisks2"), QDBusConnection::systemBus());
QDBusPendingReply<ManagedObjectList> reply = udisks2_interface_->GetManagedObjects();
reply.waitForFinished();
@@ -222,17 +226,17 @@ void Udisks2Lister::DBusInterfaceAdded(const QDBusObjectPath &path, const Interf
for (auto interface = interfaces.constBegin(); interface != interfaces.constEnd(); ++interface) {
if (interface.key() != "org.freedesktop.UDisks2.Job") continue;
if (interface.key() != QStringLiteral("org.freedesktop.UDisks2.Job")) continue;
SharedPtr<OrgFreedesktopUDisks2JobInterface> job = make_shared<OrgFreedesktopUDisks2JobInterface>(udisks2_service_, path.path(), QDBusConnection::systemBus());
SharedPtr<OrgFreedesktopUDisks2JobInterface> job = make_shared<OrgFreedesktopUDisks2JobInterface>(QLatin1String(kUDisks2Service), path.path(), QDBusConnection::systemBus());
if (!job->isValid()) continue;
bool is_mount_job = false;
if (job->operation() == "filesystem-mount") {
if (job->operation() == QStringLiteral("filesystem-mount")) {
is_mount_job = true;
}
else if (job->operation() == "filesystem-unmount") {
else if (job->operation() == QStringLiteral("filesystem-unmount")) {
is_mount_job = false;
}
else {
@@ -365,11 +369,11 @@ void Udisks2Lister::HandleFinishedUnmountJob(const PartitionData &partition_data
Udisks2Lister::PartitionData Udisks2Lister::ReadPartitionData(const QDBusObjectPath &path) {
PartitionData result;
OrgFreedesktopUDisks2FilesystemInterface filesystem(udisks2_service_, path.path(), QDBusConnection::systemBus());
OrgFreedesktopUDisks2BlockInterface block(udisks2_service_, path.path(), QDBusConnection::systemBus());
OrgFreedesktopUDisks2FilesystemInterface filesystem(QLatin1String(kUDisks2Service), path.path(), QDBusConnection::systemBus());
OrgFreedesktopUDisks2BlockInterface block(QLatin1String(kUDisks2Service), path.path(), QDBusConnection::systemBus());
if (filesystem.isValid() && block.isValid() && !filesystem.mountPoints().empty()) {
OrgFreedesktopUDisks2DriveInterface drive(udisks2_service_, block.drive().path(), QDBusConnection::systemBus());
OrgFreedesktopUDisks2DriveInterface drive(QLatin1String(kUDisks2Service), block.drive().path(), QDBusConnection::systemBus());
if (drive.isValid() && drive.mediaRemovable()) {
result.dbus_path = path.path();
@@ -384,18 +388,14 @@ Udisks2Lister::PartitionData Udisks2Lister::ReadPartitionData(const QDBusObjectP
result.capacity = drive.size();
if (result.label.isEmpty()) {
result.friendly_name = result.model + " " + result.uuid;
result.friendly_name = result.model + QLatin1Char(' ') + result.uuid;
}
else {
result.friendly_name = result.label;
}
for (const QByteArray &p : filesystem.mountPoints()) {
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) // Workaround a bytearray to string conversion issue with Qt 6
QString mountpoint = QByteArray(p.data(), static_cast<qint64>(strlen(p.data())));
#else
QString mountpoint = p;
#endif
const QString mountpoint = QString::fromUtf8(p.data(), p.size());
result.mount_paths.push_back(mountpoint);
}

View File

@@ -124,8 +124,6 @@ class Udisks2Lister : public DeviceLister {
private:
ScopedPtr<OrgFreedesktopDBusObjectManagerInterface> udisks2_interface_;
static constexpr char udisks2_service_[] = "org.freedesktop.UDisks2";
};
#endif // UDISKS2LISTER_H