Support for Qt5

This commit is contained in:
craig.p.drummond
2013-02-08 17:57:02 +00:00
committed by craig.p.drummond
parent 4e48b6b9ff
commit cb1d5b4b26
42 changed files with 594 additions and 128 deletions

View File

@@ -2,7 +2,7 @@ INCLUDE(MacroOptionalFindPackage)
INCLUDE(MacroLogFeature)
add_subdirectory( ifaces )
include_directories( ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR} ${QT_INCLUDES})
include_directories( ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR} ${QTINCLUDES})
file(MAKE_DIRECTORY
${CMAKE_CURRENT_BINARY_DIR}/backends/hal
@@ -233,7 +233,11 @@ if(APPLE)
set(solidlite_OPTIONAL_LIBS ${IOKIT_LIBRARY})
endif(APPLE)
QT4_WRAP_CPP(solidlite_LIB_MOC_SRCS ${solidlite_LIB_MOC_HDRS} )
if (ENABLE_QT5)
QT5_WRAP_CPP(solidlite_LIB_MOC_SRCS ${solidlite_LIB_MOC_HDRS} )
else (ENABLE_QT5)
QT4_WRAP_CPP(solidlite_LIB_MOC_SRCS ${solidlite_LIB_MOC_HDRS} )
endif (ENABLE_QT5)
add_library(solidlite ${solidlite_LIB_SRCS} ${solidlite_LIB_MOC_SRCS})
# set_target_properties(solidlite PROPERTIES AUTOMOC TRUE)

View File

@@ -90,7 +90,11 @@ bool UDevManager::Private::isOfInterest(const UdevQt::Device &device)
QString path = device.deviceProperty("DEVPATH").toString();
int lastSlash = path.length() - path.lastIndexOf(QLatin1String("/")) -1;
#if QT_VERSION < 0x050000
QByteArray lastElement = path.right(lastSlash).toAscii();
#else
QByteArray lastElement = path.right(lastSlash).toLatin1();
#endif
if (lastElement.startsWith("tty") && !path.startsWith("/devices/virtual")) {
return true;

View File

@@ -23,17 +23,24 @@
#include <QObject>
#include <QSharedData>
#if QT_VERSION < 0x050000
#include <QWeakPointer>
#else
#include <QPointer>
#include "ifaces/device.h"
#endif
#include <QMap>
#include "deviceinterface.h"
namespace Solid
{
#if QT_VERSION < 0x050000
namespace Ifaces
{
class Device;
}
#endif
class DevicePrivate : public QObject, public QSharedData
{
@@ -55,7 +62,11 @@ namespace Solid
private:
QString m_udi;
#if QT_VERSION < 0x050000
QWeakPointer<Ifaces::Device> m_backendObject;
#else
QPointer<Ifaces::Device> m_backendObject;
#endif
QMap<DeviceInterface::Type, DeviceInterface *> m_ifaces;
};
}

View File

@@ -22,7 +22,9 @@
#define SOLID_DEVICEINTERFACE_H
#include <QObject>
#if QT_VERSION < 0x050000
#include <QBool>
#endif
#include <solid-lite/solid_export.h>

View File

@@ -21,7 +21,11 @@
#ifndef SOLID_DEVICEINTERFACE_P_H
#define SOLID_DEVICEINTERFACE_P_H
#if QT_VERSION < 0x050000
#include <QWeakPointer>
#else
#include <QPointer>
#endif
namespace Solid
{
@@ -37,7 +41,11 @@ namespace Solid
void setDevicePrivate(DevicePrivate *devicePrivate);
private:
#if QT_VERSION < 0x050000
QWeakPointer<QObject> m_backendObject;
#else
QPointer<QObject> m_backendObject;
#endif
DevicePrivate* m_devicePrivate;
};
}

View File

@@ -32,6 +32,12 @@
SOLID_GLOBAL_STATIC(Solid::DeviceManagerStorage, globalDeviceStorage)
#if QT_VERSION < 0x050000
#define QtPointer QWeakPointer
#else
#define QtPointer QPointer
#endif
Solid::DeviceManagerPrivate::DeviceManagerPrivate()
: m_nullDevice(new DevicePrivate(QString()))
{
@@ -53,7 +59,7 @@ Solid::DeviceManagerPrivate::~DeviceManagerPrivate()
disconnect(backend, 0, this, 0);
}
foreach (QWeakPointer<DevicePrivate> dev, m_devicesMap) {
foreach (QtPointer<DevicePrivate> dev, m_devicesMap) {
if (!dev.data()->ref.deref()) {
delete dev.data();
}
@@ -228,7 +234,7 @@ Solid::DevicePrivate *Solid::DeviceManagerPrivate::findRegisteredDevice(const QS
DevicePrivate *devData = new DevicePrivate(udi);
devData->setBackendObject(iface);
QWeakPointer<DevicePrivate> ptr(devData);
QtPointer<DevicePrivate> ptr(devData);
m_devicesMap[udi] = ptr;
m_reverseMap[devData] = udi;

View File

@@ -26,7 +26,11 @@
#include "devicenotifier.h"
#include <QMap>
#if QT_VERSION < 0x050000
#include <QWeakPointer>
#else
#include <QPointer>
#endif
#include <QSharedData>
#include <QThreadStorage>
@@ -57,7 +61,11 @@ namespace Solid
Ifaces::Device *createBackendObject(const QString &udi);
QExplicitlySharedDataPointer<DevicePrivate> m_nullDevice;
#if QT_VERSION < 0x050000
QMap<QString, QWeakPointer<DevicePrivate> > m_devicesMap;
#else
QMap<QString, QPointer<DevicePrivate> > m_devicesMap;
#endif
QMap<QObject *, QString> m_reverseMap;
};

View File

@@ -22,7 +22,9 @@
#define SOLID_IFACES_DEVICEINTERFACE_H
#include <QObject>
#if QT_VERSION < 0x050000
#include <QBool>
#endif
namespace Solid
{

View File

@@ -22,7 +22,9 @@
#define SOLID_IFACES_GENERICINTERFACE_H
#include <QObject>
#if QT_VERSION < 0x050000
#include <QBool>
#endif
#include <QMap>
#include <QVariant>

View File

@@ -57,7 +57,11 @@ Solid::Predicate Solid::Predicate::fromString(const QString &predicate)
{
Solid::PredicateParse::ParsingData *data = new Solid::PredicateParse::ParsingData();
s_parsingData->setLocalData(data);
#if QT_VERSION < 0x050000
data->buffer = predicate.toAscii();
#else
data->buffer = predicate.toLatin1();
#endif
PredicateParse_mainParse(data->buffer.constData());
Predicate result;
if (data->result)

View File

@@ -76,6 +76,7 @@ namespace Solid
#define SOLID_GLOBAL_STATIC(TYPE, NAME) SOLID_GLOBAL_STATIC_WITH_ARGS(TYPE, NAME, ())
#if QT_VERSION < 0x050000
#define SOLID_GLOBAL_STATIC_WITH_ARGS(TYPE, NAME, ARGS) \
static QBasicAtomicPointer<TYPE > _solid_static_##NAME = Q_BASIC_ATOMIC_INITIALIZER(0);\
static bool _solid_static_##NAME##_destroyed; \
@@ -119,4 +120,49 @@ static struct SOLID_GLOBAL_STATIC_STRUCT_NAME(NAME) \
} \
} NAME;
#else
#define SOLID_GLOBAL_STATIC_WITH_ARGS(TYPE, NAME, ARGS) \
static QBasicAtomicPointer<TYPE > _solid_static_##NAME = Q_BASIC_ATOMIC_INITIALIZER(0);\
static bool _solid_static_##NAME##_destroyed; \
static struct SOLID_GLOBAL_STATIC_STRUCT_NAME(NAME) \
{ \
bool isDestroyed() \
{ \
return _solid_static_##NAME##_destroyed; \
} \
inline operator TYPE*() \
{ \
return operator->(); \
} \
inline TYPE *operator->() \
{ \
if (!_solid_static_##NAME.load()) { \
if (isDestroyed()) { \
qFatal("Fatal Error: Accessed global static '%s *%s()' after destruction. " \
"Defined at %s:%d", #TYPE, #NAME, __FILE__, __LINE__); \
} \
TYPE *x = new TYPE ARGS; \
if (!_solid_static_##NAME.testAndSetOrdered(0, x) \
&& _solid_static_##NAME.load() != x ) { \
delete x; \
} else { \
static Solid::CleanUpGlobalStatic cleanUpObject = { destroy }; \
} \
} \
return _solid_static_##NAME.load(); \
} \
inline TYPE &operator*() \
{ \
return *operator->(); \
} \
static void destroy() \
{ \
_solid_static_##NAME##_destroyed = true; \
TYPE *x = _solid_static_##NAME.load(); \
_solid_static_##NAME.store(0); \
delete x; \
} \
} NAME;
#endif
#endif