Skip to content

Commit

Permalink
fix build with qt6
Browse files Browse the repository at this point in the history
  • Loading branch information
jmlich committed Jul 14, 2023
1 parent ade1b9a commit 641f556
Show file tree
Hide file tree
Showing 8 changed files with 81 additions and 5 deletions.
14 changes: 14 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
*.o
*.so*
moc_*
*.moc
*.a
*.la
Makefile
.qmake.stash
declarative/qmldir
src/libmpris-qt5.prl
src/mpris-qt5.prf
src/libmpris-qt6.prl
src/mpris-qt6.prf
src/pkgconfig/
2 changes: 1 addition & 1 deletion common.pri
Original file line number Diff line number Diff line change
@@ -1 +1 @@
MPRISQTLIB = mpris-qt5
MPRISQTLIB = mpris-qt$${QT_MAJOR_VERSION}
35 changes: 35 additions & 0 deletions qtdbusextended/dbusextendedabstractinterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,11 @@ QVariant DBusExtendedAbstractInterface::internalPropGet(const char *propname, vo
if (m_useCache) {
int propertyIndex = metaObject()->indexOfProperty(propname);
QMetaProperty metaProperty = metaObject()->property(propertyIndex);
#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0))
return QVariant(QMetaType(metaProperty.typeId()), propertyPtr);
#else
return QVariant(metaProperty.type(), propertyPtr);
#endif
}

if (m_sync) {
Expand Down Expand Up @@ -188,8 +192,14 @@ QVariant DBusExtendedAbstractInterface::internalPropGet(const char *propname, vo

// is this metatype registered?
const char *expectedSignature = "";
#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0))
if (metaProperty.metaType().id() != QMetaType::QVariant) {
expectedSignature = QDBusMetaType::typeToSignature(metaProperty.metaType());
#else
if (int(metaProperty.type()) != QMetaType::QVariant) {
expectedSignature = QDBusMetaType::typeToSignature(metaProperty.userType());
#endif

if (0 == expectedSignature) {
QString errorMessage =
QStringLiteral("Type %1 must be registered with Qt D-Bus "
Expand All @@ -205,7 +215,11 @@ QVariant DBusExtendedAbstractInterface::internalPropGet(const char *propname, vo
}

asyncProperty(propname);
#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0))
return QVariant(QMetaType(metaProperty.typeId()), propertyPtr);
#else
return QVariant(metaProperty.type(), propertyPtr);
#endif
}
}

Expand Down Expand Up @@ -243,7 +257,11 @@ void DBusExtendedAbstractInterface::internalPropSet(const char *propname, const
return;
}

#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0))
asyncSetProperty(propname, QVariant(QMetaType(metaProperty.typeId()), propertyPtr));
#else
asyncSetProperty(propname, QVariant(metaProperty.type(), propertyPtr));
#endif
}
}

Expand Down Expand Up @@ -385,16 +403,29 @@ QVariant DBusExtendedAbstractInterface::demarshall(const QString &interface, con
return value;
}

#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0))
QVariant result = QVariant(QMetaType(metaProperty.typeId()), nullptr);
#else
QVariant result = QVariant(metaProperty.userType(), (void*)0);
#endif
QString errorMessage;

#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0))
const char *expectedSignature = QDBusMetaType::typeToSignature(metaProperty.metaType());
#else
const char *expectedSignature = QDBusMetaType::typeToSignature(metaProperty.userType());
#endif

if (value.userType() == qMetaTypeId<QDBusArgument>()) {
// demarshalling a DBus argument ...
QDBusArgument dbusArg = value.value<QDBusArgument>();

if (expectedSignature == dbusArg.currentSignature().toLatin1()) {
#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0))
QDBusMetaType::demarshall(dbusArg, metaProperty.metaType(), result.data());
#else
QDBusMetaType::demarshall(dbusArg, metaProperty.userType(), result.data());
#endif
if (!result.isValid()) {
errorMessage = QStringLiteral("Unexpected failure demarshalling "
"upon PropertiesChanged signal arrival "
Expand All @@ -415,7 +446,11 @@ QVariant DBusExtendedAbstractInterface::demarshall(const QString &interface, con
QString::fromLatin1(expectedSignature));
}
} else {
#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0))
const char *actualSignature = QDBusMetaType::typeToSignature(value.metaType());
#else
const char *actualSignature = QDBusMetaType::typeToSignature(value.userType());
#endif

errorMessage = QStringLiteral("Unexpected `%1' (%2) "
"upon PropertiesChanged signal arrival "
Expand Down
2 changes: 1 addition & 1 deletion qtdbusextended/qtdbusextended.pro
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ CONFIG += qt staticlib

QT = core dbus

TARGET = dbusextended-qt5
TARGET = dbusextended-qt$${QT_MAJOR_VERSION}

DEFINES += QT_DBUS_EXTENDED_LIBRARY

Expand Down
19 changes: 18 additions & 1 deletion src/mprismanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@

#include <QDBusConnection>
#include <QDBusConnectionInterface>

#if (QT_VERSION >= QT_VERSION_CHECK(5, 12, 0))
#include <QRegularExpression>
#endif
#include <QtCore/QSignalMapper>
#include <QDebug>

Expand Down Expand Up @@ -68,9 +70,14 @@ MprisManager::MprisManager(QObject *parent)
QStringList serviceNames = connection.interface()->registeredServiceNames();
QStringList::const_iterator i = serviceNames.constBegin();
while (i != serviceNames.constEnd()) {
#if (QT_VERSION >= QT_VERSION_CHECK(5, 12, 0))
QRegularExpression rx(QRegularExpression::wildcardToRegularExpression(mprisNameSpace));
if (rx.match(*i).hasMatch()) {
#else
QRegExp rx(mprisNameSpace);
rx.setPatternSyntax(QRegExp::Wildcard);
if (rx.exactMatch(*i)) {
#endif
onServiceAppeared(*i);
}

Expand Down Expand Up @@ -173,9 +180,14 @@ void MprisManager::setCurrentService(const QString &service)
return;
}

#if (QT_VERSION >= QT_VERSION_CHECK(5, 12, 0))
QRegularExpression rx(QRegularExpression::wildcardToRegularExpression(mprisNameSpace));
if (!rx.match(service).hasMatch()) {
#else
QRegExp rx(mprisNameSpace);
rx.setPatternSyntax(QRegExp::Wildcard);
if (!rx.exactMatch(service)) {
#endif
qWarning() << "Mpris:" << service << "is not a proper Mpris2 service";
return;
}
Expand Down Expand Up @@ -380,9 +392,14 @@ void MprisManager::onNameOwnerChanged(const QString &service, const QString &old
// bus, not just the ones for our name space of interest, and we
// will have to filter on our own :(

#if (QT_VERSION >= QT_VERSION_CHECK(5, 12, 0))
QRegularExpression rx(QRegularExpression::wildcardToRegularExpression(mprisNameSpace));
if (!rx.match(service).hasMatch()) {
#else
QRegExp rx(mprisNameSpace);
rx.setPatternSyntax(QRegExp::Wildcard);
if (!rx.exactMatch(service)) {
#endif
return;
}

Expand Down
2 changes: 2 additions & 0 deletions src/mprisplayer_p.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ class QByteArray;
template<class T> class QList;
template<class Key, class Value> class QMap;
class QString;
#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
class QStringList;
#endif
class QVariant;
QT_END_NAMESPACE

Expand Down
8 changes: 8 additions & 0 deletions src/mprisplayerinterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,18 @@ MprisPlayerInterface::MprisPlayerInterface(const QString &service, const QString
, m_canPause(false)
, m_canPlay(false)
, m_canSeek(false)
#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0))
, m_loopStatus("None")
#else
, m_loopStatus(Mpris::None)
#endif
, m_maximumRate(1)
, m_minimumRate(1)
#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0))
, m_playbackStatus("Stopped")
#else
, m_playbackStatus(Mpris::Stopped)
#endif
, m_position(0)
, m_rate(1)
, m_shuffle(false)
Expand Down
4 changes: 2 additions & 2 deletions src/src.pro
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use_system_dbus {

DEPENDPATH += ../qtdbusextended
INCLUDEPATH += ../qtdbusextended
LIBS += -L../qtdbusextended -ldbusextended-qt5
LIBS += -L../qtdbusextended -ldbusextended-qt$${QT_MAJOR_VERSION}

# Generate pkg-config support by default
# Note that we HAVE TO also create prl config as QMake implementation
Expand Down Expand Up @@ -64,7 +64,7 @@ prf.files = $${TARGET}.prf
prf.path = $$[QMAKE_MKSPECS]/features
INSTALLS += target headers prf

QMAKE_PKGCONFIG_REQUIRES = Qt5Core Qt5DBus
QMAKE_PKGCONFIG_REQUIRES = Qt$${QT_MAJOR_VERSION}Core Qt$${QT_MAJOR_VERSION}DBus
QMAKE_PKGCONFIG_LIBDIR = $$target.path
QMAKE_PKGCONFIG_INCDIR = $$headers.path
QMAKE_PKGCONFIG_DESTDIR = pkgconfig
Expand Down

0 comments on commit 641f556

Please sign in to comment.