Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Port qt6 #1

Open
wants to merge 21 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
c6d09d4
[Port to Qt6] CMakeLists upgrade for qt6 + remove warnings
ochurlaud Feb 29, 2024
84bedd7
[Port to Qt6] Add -fPIC compilation flag
ochurlaud Feb 29, 2024
9f9fef4
[Port to Qt6] Remove cmake warnings
ochurlaud Feb 29, 2024
1887306
[Port to Qt6] Update solid-lite parts to what currently exists in KDE.
ochurlaud Feb 29, 2024
c614adf
[Port to Qt6] QRegExp -> QRegularExpression
ochurlaud Feb 29, 2024
dfa9f5c
[Port to Qt6] QVariant::type() => QVariant::typeId()
ochurlaud Feb 29, 2024
493784a
[Port to Qt6] Change in QVariant::setValue templating
ochurlaud Feb 29, 2024
90296ef
[Port to Qt6] QLayout::setMargin(int) -> QLayout::setContentsMargins(…
ochurlaud Feb 29, 2024
1c01e22
[Port to Qt6] QApplication::fontMetrics() -> QFontMetricsF(QApplicati…
ochurlaud Feb 29, 2024
ca77dfa
[Port to Qt6] QMatrix -> QTransform
ochurlaud Feb 29, 2024
2cd4bd0
[Port to Qt6] QKeySequence are now added with | instead of +
ochurlaud Feb 29, 2024
4c29c96
[Port to Qt6] QDesktopWidget -> QScreen
ochurlaud Feb 29, 2024
a510473
[Port to Qt6] DateTime::toTime_t() -> DateTime.toSecsSinceEpoch()
ochurlaud Feb 29, 2024
a8b3f0b
[Port to Qt6] QStringRef -> QStringView and other string manipulations
ochurlaud Feb 29, 2024
c2d88cd
[Port to Qt6] std::random_shuffle -> std::shuffle
ochurlaud Feb 29, 2024
aefaaa2
[Port to Qt6] QStandardPath changes
ochurlaud Feb 29, 2024
0058df4
[Port to Qt6] event->pos() -> event->position().toPoint()
ochurlaud Feb 29, 2024
d026f21
[Port to Qt6] QMenu::addAction signature change
ochurlaud Feb 29, 2024
7b0e0b7
[Port to Qt6] Port away from QTextCodec
ochurlaud Feb 29, 2024
f28e459
[Port to Qt6] AudioOutput is split from MediaPlayer
ochurlaud Feb 29, 2024
3c66687
[Port to Qt6] Various corrections
ochurlaud Feb 29, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion 3rdparty/qtiocompressor/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 2.6)
cmake_minimum_required(VERSION 3.5)

include_directories(${QTINCLUDES} ${ZLIB_INCLUDE_DIRS} ${CMAKE_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR})
ADD_LIBRARY(qtiocompressor STATIC qtiocompressor.cpp)
1 change: 1 addition & 0 deletions 3rdparty/solid-lite/backends/hal/haldevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include <QDBusArgument>
#include <QDBusMetaType>
#include <QDBusVariant>
#include <QLocale>

#include <solid-lite/genericinterface.h>

Expand Down
3 changes: 2 additions & 1 deletion 3rdparty/solid-lite/backends/hal/halfstabhandling.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include <QMultiHash>
#include <QObject>
#include <QProcess>
#include <QRegularExpression>
#include <QTextStream>
#include <QElapsedTimer>

Expand Down Expand Up @@ -167,7 +168,7 @@ QProcess *Solid::Backends::Hal::FstabHandling::callSystemCommand(const QString &
QObject *obj, const char *slot)
{
QStringList env = QProcess::systemEnvironment();
env.replaceInStrings(QRegExp("^PATH=(.*)", Qt::CaseInsensitive), "PATH=/sbin:/bin:/usr/sbin/:/usr/bin");
env.replaceInStrings(QRegularExpression("^PATH=(.*)", QRegularExpression::CaseInsensitiveOption), "PATH=/sbin:/bin:/usr/sbin/:/usr/bin");

QProcess *process = new QProcess(obj);

Expand Down
2 changes: 1 addition & 1 deletion 3rdparty/solid-lite/backends/iokit/cfhelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ static QVariant q_toVariant(const CFTypeRef &obj)
bool metNonString = false;
for (CFIndex i = 0; i < size; ++i) {
QVariant value = q_toVariant(CFArrayGetValueAtIndex(cfarray, i));
if (value.type() != QVariant::String)
if (value.typeId() != QMetaType::QString)
metNonString = true;
list << value;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ static QString readMpiValue(QIODevice &file, const QString &group, const QString
else if (line.startsWith(QChar('[')) && line.endsWith(QChar(']'))) {
currGroup = line.mid(1, line.length() - 2); // strip [ and ]
}
else if (line.indexOf(QChar('=') != -1)) {
else if (line.indexOf(QChar('=')) != -1) {
int index = line.indexOf(QChar('='));
if (currGroup == group && line.left(index) == key) {
line = line.right(line.length() - index - 1);
Expand Down
6 changes: 3 additions & 3 deletions 3rdparty/solid-lite/backends/udisks/udisksopticaldisc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@
#include <sys/stat.h>
#include <fcntl.h>

#include <QtCore/QFile>
#include <QtCore/QMap>
#include <QtCore/QMutexLocker>
#include <QFile>
#include <QMap>
#include <QMutexLocker>

#include "udisksopticaldisc.h"
#include "soliddefs_p.h"
Expand Down
22 changes: 21 additions & 1 deletion 3rdparty/solid-lite/backends/udisks2/udisksdevicebackend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,11 @@ QVariantMap DeviceBackend::allProperties() const
QDBusPendingReply<QVariantMap> reply = QDBusConnection::systemBus().call(call);

if (reply.isValid()) {
m_propertyCache.unite(reply.value());
auto props = reply.value();
// Can not use QMap<>::unite(), as it allows multiple values per key
for (auto it = props.cbegin(); it != props.cend(); ++it) {
cacheProperty(it.key(), it.value());
}
} else {
qWarning() << "Error getting props:" << reply.error().name() << reply.error().message();
}
Expand Down Expand Up @@ -242,3 +246,19 @@ void DeviceBackend::slotInterfacesRemoved(const QDBusObjectPath& object_path, co
m_interfaces.removeAll(iface);
}
}

// UDisks2 sends us null terminated strings, make sure to strip the extranous \0 in favor of the implicit \0.
// Otherwise comparision becomes unnecessarily complicated because 'foo\0' != 'foo'. QByteArrays are implicitly
// terminated already.
void DeviceBackend::cacheProperty(const QString &key, const QVariant &value) const
{
if (value.metaType() == QMetaType::fromType<QByteArray>()) {
auto blob = value.toByteArray();
while (blob.endsWith('\0')) {
blob.chop(1);
}
m_propertyCache.insert(key, blob);
} else {
m_propertyCache.insert(key, value);
}
}
3 changes: 2 additions & 1 deletion 3rdparty/solid-lite/backends/udisks2/udisksdevicebackend.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,11 @@ class DeviceBackend: public QObject {
void initInterfaces();
QString introspect() const;
void checkCache(const QString &key) const;
void cacheProperty(const QString &key, const QVariant &value) const;

QDBusInterface *m_device;

mutable QMultiMap<QString, QVariant> m_propertyCache;
mutable QVariantMap m_propertyCache;
QStringList m_interfaces;
QString m_udi;

Expand Down
246 changes: 201 additions & 45 deletions 3rdparty/solid-lite/backends/udisks2/udisksopticaldisc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,21 +24,18 @@
#include <sys/stat.h>
#include <fcntl.h>

#include <QFile>
#include <QMap>
#include <QMutexLocker>
#include <QDBusConnection>
#include <QSharedMemory>
#include <QSystemSemaphore>
#include <QThreadStorage>

#include "../shared/udevqt.h"

#include "udisks2.h"
#include "udisksdevice.h"
#include "udisksopticaldisc.h"
#include "soliddefs_p.h"

typedef QMap<QByteArray, Solid::OpticalDisc::ContentTypes> ContentTypesCache;
SOLID_GLOBAL_STATIC(ContentTypesCache, cache)
SOLID_GLOBAL_STATIC(QMutex, cacheLock)
#include "udisks2.h"

// inspired by http://cgit.freedesktop.org/hal/tree/hald/linux/probing/probe-volume.c
static Solid::OpticalDisc::ContentType advancedDiscDetect(const QByteArray & device_file)
Expand Down Expand Up @@ -173,17 +170,195 @@ static Solid::OpticalDisc::ContentType advancedDiscDetect(const QByteArray & dev

using namespace Solid::Backends::UDisks2;

class ContentTypesCache
{
public:
ContentTypesCache()
: m_n(0)
{
}

void add(const OpticalDisc::Identity &key, Solid::OpticalDisc::ContentTypes content)
{
if (!find(key)) {
m_n = qMin(m_n + 1, sizeof(m_info) / sizeof(*m_info));
moveToFront(m_n - 1);
front().first = key;
}
front().second = content;
}

bool find(const OpticalDisc::Identity &key)
{
for (size_t i = 0; i < m_n; i++) {
if (m_info[i].first == key) {
moveToFront(i);
return true;
}
}
return false;
}

QPair<OpticalDisc::Identity, Solid::OpticalDisc::ContentTypes> &front()
{
return *m_info;
}

private:
void moveToFront(size_t i)
{
while (i) {
qSwap(m_info[i - 1], m_info[i]);
--i;
}
}

size_t m_n;
QPair<OpticalDisc::Identity, Solid::OpticalDisc::ContentTypes> m_info[100];
};

class SharedContentTypesCache
{
private:
ContentTypesCache *m_pointer;
QSystemSemaphore m_semaphore;
QSharedMemory m_shmem;

struct Unlocker {
public:
Unlocker(QSharedMemory *mem)
: m_mem(mem)
{
}
~Unlocker()
{
m_mem->unlock();
}
Unlocker(const Unlocker &) = delete;
Unlocker &operator=(const Unlocker &) = delete;

private:
QSharedMemory *m_mem;
};

struct Releaser {
public:
Releaser(QSystemSemaphore *sem)
: m_sem(sem)
{
}
~Releaser()
{
m_sem->release();
}
Releaser(const Releaser &) = delete;
Releaser &operator=(const Releaser &) = delete;

private:
QSystemSemaphore *m_sem;
};

static QString getKey()
{
static const QString keyTemplate("solid-disk-info-1-%1-%2");
static const QString tableSize(QString::number(sizeof(ContentTypesCache)));

return keyTemplate.arg(tableSize, QString::number(geteuid()));
}

public:
SharedContentTypesCache()
: m_pointer(nullptr)
, m_semaphore(getKey() + "sem", 1)
, m_shmem(getKey() + "mem")
{
if (!m_semaphore.acquire()) {
return;
}
Releaser releaser(&m_semaphore);

if (m_shmem.attach()) {
m_pointer = reinterpret_cast<ContentTypesCache *>(m_shmem.data());
return;
}

if (!m_shmem.create(sizeof(ContentTypesCache))) {
return;
}

if (!m_shmem.lock()) {
m_shmem.detach();
return;
}
Unlocker unlocker(&m_shmem);

m_pointer = new (m_shmem.data()) ContentTypesCache;
}

Solid::OpticalDisc::ContentTypes getContent(const OpticalDisc::Identity &info, const QByteArray &file)
{
if (!m_pointer) {
return advancedDiscDetect(file);
}

if (!m_semaphore.acquire()) {
return advancedDiscDetect(file);
}
Releaser releaser(&m_semaphore);

if (!m_shmem.lock()) {
return advancedDiscDetect(file);
}
Unlocker unlocker(&m_shmem);

if (!m_pointer->find(info)) {
m_pointer->add(info, advancedDiscDetect(file));
}

Solid::OpticalDisc::ContentTypes content = m_pointer->front().second;
return content;
}

~SharedContentTypesCache()
{
m_semaphore.acquire();
Releaser releaser(&m_semaphore);
m_shmem.detach();
}
};

Q_GLOBAL_STATIC(QThreadStorage<SharedContentTypesCache>, sharedContentTypesCache)

OpticalDisc::Identity::Identity()
: m_detectTime(0)
, m_size(0)
, m_labelHash(0)
{
}

OpticalDisc::Identity::Identity(const Device &device, const Device &drive)
: m_detectTime(drive.prop("TimeMediaDetected").toLongLong())
, m_size(device.prop("Size").toLongLong())
, m_labelHash(qHash(device.prop("IdLabel").toString()))
{
}

bool OpticalDisc::Identity::operator==(const OpticalDisc::Identity &b) const
{
return m_detectTime == b.m_detectTime
&& m_size == b.m_size
&& m_labelHash == b.m_labelHash;
}

OpticalDisc::OpticalDisc(Device *dev)
: StorageVolume(dev), m_needsReprobe(true), m_cachedContent(Solid::OpticalDisc::NoContent)
: StorageVolume(dev)
{
UdevQt::Client client(this);
m_udevDevice = client.deviceByDeviceFile(device());
//qDebug() << "udev device:" << m_udevDevice.name() << "valid:" << m_udevDevice.isValid();
// qDebug() << "udev device:" << m_udevDevice.name() << "valid:" << m_udevDevice.isValid();
/*qDebug() << "\tProperties:" << */ m_udevDevice.deviceProperties(); // initialize the properties DB so that it doesn't crash further down, #298416

m_drive = new Device(m_device->drivePath());
QDBusConnection::systemBus().connect(UD2_DBUS_SERVICE, m_drive->udi(), DBUS_INTERFACE_PROPS, "PropertiesChanged", this,
SLOT(slotDrivePropertiesChanged(QString,QVariantMap,QStringList)));
}

OpticalDisc::~OpticalDisc()
Expand Down Expand Up @@ -247,49 +422,30 @@ Solid::OpticalDisc::DiscType OpticalDisc::discType() const
Solid::OpticalDisc::ContentTypes OpticalDisc::availableContent() const
{
if (isBlank()) {
m_needsReprobe = false;
return Solid::OpticalDisc::NoContent;
}

if (m_needsReprobe) {
QMutexLocker lock(cacheLock);
Solid::OpticalDisc::ContentTypes content = Solid::OpticalDisc::NoContent;
const bool hasData = m_drive->prop("OpticalNumDataTracks").toUInt() > 0;
const bool hasAudio = m_drive->prop("OpticalNumAudioTracks").toUInt() > 0;

const QByteArray deviceFile = m_device->prop("Device").toByteArray();
if (hasData) {
content |= Solid::OpticalDisc::Data;

if (cache->contains(deviceFile)) {
m_cachedContent = cache->value(deviceFile);
m_needsReprobe = false;
return m_cachedContent;
Identity newIdentity(*m_device, *m_drive);
if (!(m_identity == newIdentity)) {
QByteArray deviceFile(m_device->prop("Device").toByteArray());
m_cachedContent = sharedContentTypesCache->localData().getContent(newIdentity, deviceFile);
m_identity = newIdentity;
}

m_cachedContent = Solid::OpticalDisc::NoContent;
const bool hasData = m_drive->prop("OpticalNumDataTracks").toUInt() > 0;
const bool hasAudio = m_drive->prop("OpticalNumAudioTracks").toUInt() > 0;

if ( hasData ) {
m_cachedContent |= Solid::OpticalDisc::Data;
m_cachedContent |= advancedDiscDetect(deviceFile);
}
if ( hasAudio )
m_cachedContent |= Solid::OpticalDisc::Audio;

m_needsReprobe = false;
cache->insert(deviceFile, m_cachedContent);
content |= m_cachedContent;
}

return m_cachedContent;
}

void OpticalDisc::slotDrivePropertiesChanged(const QString &ifaceName, const QVariantMap &changedProps, const QStringList &invalidatedProps)
{
Q_UNUSED(ifaceName);

if (changedProps.keys().contains("Media") || invalidatedProps.contains("Media")) {
QMutexLocker lock(cacheLock);
m_needsReprobe = true;
m_cachedContent = Solid::OpticalDisc::NoContent;
cache->remove(m_device->prop("Device").toByteArray());
if (hasAudio) {
content |= Solid::OpticalDisc::Audio;
}

return content;
}

QString OpticalDisc::media() const
Expand Down
Loading