diff options
Diffstat (limited to 'src/plugins')
30 files changed, 508 insertions, 607 deletions
diff --git a/src/plugins/bearer/networkmanager/qnetworkmanagerengine.cpp b/src/plugins/bearer/networkmanager/qnetworkmanagerengine.cpp index f0977b4735..f52b9d4b4d 100644 --- a/src/plugins/bearer/networkmanager/qnetworkmanagerengine.cpp +++ b/src/plugins/bearer/networkmanager/qnetworkmanagerengine.cpp @@ -125,7 +125,6 @@ void QNetworkManagerEngine::setupConfigurations() activeConnectionsList.insert(acPath.path(), activeConnection); connect(activeConnection, SIGNAL(propertiesChanged(QMap<QString,QVariant>)), this, SLOT(activeConnectionPropertiesChanged(QMap<QString,QVariant>))); - activeConnection->setConnections(); QStringList devices = activeConnection->devices(); if (!devices.isEmpty()) { @@ -180,7 +179,7 @@ void QNetworkManagerEngine::connectToId(const QString &id) NMDeviceType connectionType = connection->getType(); QString dbusDevicePath; - const QString settingsPath = connection->connectionInterface()->path(); + const QString settingsPath = connection->path(); QString specificPath = configuredAccessPoints.key(settingsPath); if (isConnectionActive(settingsPath)) @@ -277,7 +276,6 @@ void QNetworkManagerEngine::interfacePropertiesChanged(const QMap<QString, QVari connect(activeConnection, SIGNAL(propertiesChanged(QMap<QString,QVariant>)), this, SLOT(activeConnectionPropertiesChanged(QMap<QString,QVariant>))); - activeConnection->setConnections(); } const QString id = activeConnection->connection().path(); @@ -373,10 +371,10 @@ void QNetworkManagerEngine::deviceConnectionsChanged(const QStringList &connecti { QMutexLocker locker(&mutex); for (int i = 0; i < connections.count(); ++i) { - if (connectionsList.contains(connections.at(i)->connectionInterface()->path())) + if (connectionsList.contains(connections.at(i)->path())) continue; - const QString settingsPath = connections.at(i)->connectionInterface()->path(); + const QString settingsPath = connections.at(i)->path(); QNetworkConfigurationPrivatePointer ptr = accessPointConfigurations.value(settingsPath); @@ -399,11 +397,10 @@ void QNetworkManagerEngine::deviceAdded(const QDBusObjectPath &path) connect(iDevice,SIGNAL(connectionsChanged(QStringList)), this,SLOT(deviceConnectionsChanged(QStringList))); - iDevice->setConnections(); interfaceDevices.insert(path.path(),iDevice); if (iDevice->deviceType() == DEVICE_TYPE_WIFI) { QNetworkManagerInterfaceDeviceWireless *wirelessDevice = - new QNetworkManagerInterfaceDeviceWireless(iDevice->connectionInterface()->path(),this); + new QNetworkManagerInterfaceDeviceWireless(iDevice->path(),this); connect(wirelessDevice, SIGNAL(accessPointAdded(QString)), this, SLOT(newAccessPoint(QString))); @@ -417,9 +414,9 @@ void QNetworkManagerEngine::deviceAdded(const QDBusObjectPath &path) if (iDevice->deviceType() == DEVICE_TYPE_ETHERNET) { QNetworkManagerInterfaceDeviceWired *wiredDevice = - new QNetworkManagerInterfaceDeviceWired(iDevice->connectionInterface()->path(),this); + new QNetworkManagerInterfaceDeviceWired(iDevice->path(),this); connect(wiredDevice,SIGNAL(carrierChanged(bool)),this,SLOT(wiredCarrierChanged(bool))); - wiredDevices.insert(iDevice->connectionInterface()->path(), wiredDevice); + wiredDevices.insert(iDevice->path(), wiredDevice); } } @@ -454,7 +451,7 @@ void QNetworkManagerEngine::wiredCarrierChanged(bool carrier) for (int i = 0; i < connections.count(); ++i) { QNetworkManagerSettingsConnection *connection = connections.at(i); if (connection->getType() == DEVICE_TYPE_ETHERNET - && settingsPath.path() == connection->connectionInterface()->path()) { + && settingsPath.path() == connection->path()) { QNetworkConfigurationPrivatePointer ptr = accessPointConfigurations.value(settingsPath.path()); @@ -486,9 +483,9 @@ void QNetworkManagerEngine::newConnection(const QDBusObjectPath &path, } QNetworkManagerSettingsConnection *connection = - new QNetworkManagerSettingsConnection(settings->connectionInterface()->service(), + new QNetworkManagerSettingsConnection(settings->service(), path.path(),this); - const QString settingsPath = connection->connectionInterface()->path(); + const QString settingsPath = connection->path(); if (accessPointConfigurations.contains(settingsPath)) { return; } @@ -506,7 +503,7 @@ void QNetworkManagerEngine::newConnection(const QDBusObjectPath &path, for (int i = 0; i < accessPoints.count(); ++i) { if (connection->getSsid() == accessPoints.at(i)->ssid()) { // remove the corresponding accesspoint from configurations - apPath = accessPoints.at(i)->connectionInterface()->path(); + apPath = accessPoints.at(i)->path(); QNetworkConfigurationPrivatePointer ptr = accessPointConfigurations.take(apPath); if (ptr) { @@ -533,7 +530,7 @@ void QNetworkManagerEngine::newConnection(const QDBusObjectPath &path, i.next(); if (i.value()->deviceType() == deviceType) { QNetworkManagerInterfaceDeviceWired *wiredDevice - = wiredDevices.value(i.value()->connectionInterface()->path()); + = wiredDevices.value(i.value()->path()); if (wiredDevice->carrier()) { cpPriv->state |= QNetworkConfiguration::Discovered; } @@ -564,7 +561,7 @@ bool QNetworkManagerEngine::isConnectionActive(const QString &settingsPath) QNetworkManagerSettingsConnection *settingsConnection = connectionFromId(settingsPath); if (settingsConnection->getType() == DEVICE_TYPE_MODEM) { - return isActiveContext(settingsConnection->connectionInterface()->path()); + return isActiveContext(settingsConnection->path()); } return false; @@ -611,7 +608,7 @@ void QNetworkManagerEngine::updateConnection() qobject_cast<QNetworkManagerSettingsConnection *>(sender()); if (!connection) return; - const QString settingsPath = connection->connectionInterface()->path(); + const QString settingsPath = connection->path(); QNetworkConfigurationPrivate *cpPriv = parseConnection(settingsPath, connection->getSettings()); @@ -682,20 +679,19 @@ void QNetworkManagerEngine::newAccessPoint(const QString &path) bool okToAdd = true; for (int i = 0; i < accessPoints.count(); ++i) { - if (accessPoints.at(i)->connectionInterface()->path() == path) { + if (accessPoints.at(i)->path() == path) { okToAdd = false; } } if (okToAdd) { accessPoints.append(accessPoint); - accessPoint->setConnections(); } // Check if configuration exists for connection. if (!accessPoint->ssid().isEmpty()) { for (int i = 0; i < connections.count(); ++i) { QNetworkManagerSettingsConnection *connection = connections.at(i); - const QString settingsPath = connection->connectionInterface()->path(); + const QString settingsPath = connection->path(); if (accessPoint->ssid() == connection->getSsid()) { if (!configuredAccessPoints.contains(path)) { @@ -741,18 +737,18 @@ void QNetworkManagerEngine::removeAccessPoint(const QString &path) QMutexLocker locker(&mutex); for (int i = 0; i < accessPoints.count(); ++i) { QNetworkManagerInterfaceAccessPoint *accessPoint = accessPoints.at(i); - if (accessPoint->connectionInterface()->path() == path) { + if (accessPoint->path() == path) { accessPoints.removeOne(accessPoint); - if (configuredAccessPoints.contains(accessPoint->connectionInterface()->path())) { + if (configuredAccessPoints.contains(accessPoint->path())) { // find connection and change state to Defined - configuredAccessPoints.remove(accessPoint->connectionInterface()->path()); + configuredAccessPoints.remove(accessPoint->path()); for (int i = 0; i < connections.count(); ++i) { QNetworkManagerSettingsConnection *connection = connections.at(i); if (accessPoint->ssid() == connection->getSsid()) {//might not have bssid yet - const QString settingsPath = connection->connectionInterface()->path(); + const QString settingsPath = connection->path(); const QString connectionId = settingsPath; QNetworkConfigurationPrivatePointer ptr = @@ -804,7 +800,7 @@ QNetworkConfigurationPrivate *QNetworkManagerEngine::parseConnection(const QStri foreach (const QDBusObjectPath &devicePath, managerInterface->getDevices()) { QNetworkManagerInterfaceDevice device(devicePath.path(),this); if (device.deviceType() == DEVICE_TYPE_ETHERNET) { - QNetworkManagerInterfaceDeviceWired *wiredDevice = wiredDevices.value(device.connectionInterface()->path()); + QNetworkManagerInterfaceDeviceWired *wiredDevice = wiredDevices.value(device.path()); if (wiredDevice->carrier()) { cpPriv->state |= QNetworkConfiguration::Discovered; break; @@ -819,10 +815,10 @@ QNetworkConfigurationPrivate *QNetworkManagerEngine::parseConnection(const QStri if (connectionSsid == accessPoints.at(i)->ssid() && map.value("802-11-wireless").value("seen-bssids").toStringList().contains(accessPoints.at(i)->hwAddress())) { cpPriv->state |= QNetworkConfiguration::Discovered; - if (!configuredAccessPoints.contains(accessPoints.at(i)->connectionInterface()->path())) { - configuredAccessPoints.insert(accessPoints.at(i)->connectionInterface()->path(),settingsPath); + if (!configuredAccessPoints.contains(accessPoints.at(i)->path())) { + configuredAccessPoints.insert(accessPoints.at(i)->path(),settingsPath); - const QString accessPointId = accessPoints.at(i)->connectionInterface()->path(); + const QString accessPointId = accessPoints.at(i)->path(); QNetworkConfigurationPrivatePointer ptr = accessPointConfigurations.take(accessPointId); @@ -881,7 +877,7 @@ QNetworkManagerSettingsConnection *QNetworkManagerEngine::connectionFromId(const { for (int i = 0; i < connections.count(); ++i) { QNetworkManagerSettingsConnection *connection = connections.at(i); - if (id == connection->connectionInterface()->path()) + if (id == connection->path()) return connection; } diff --git a/src/plugins/bearer/networkmanager/qnetworkmanagerservice.cpp b/src/plugins/bearer/networkmanager/qnetworkmanagerservice.cpp index 9f4ae55e78..16a7e475e0 100644 --- a/src/plugins/bearer/networkmanager/qnetworkmanagerservice.cpp +++ b/src/plugins/bearer/networkmanager/qnetworkmanagerservice.cpp @@ -47,32 +47,24 @@ #ifndef QT_NO_DBUS +#define DBUS_PROPERTIES_INTERFACE "org.freedesktop.DBus.Properties" + QT_BEGIN_NAMESPACE -class QNetworkManagerInterfacePrivate -{ -public: - QDBusInterface *connectionInterface; - bool valid; -}; QNetworkManagerInterface::QNetworkManagerInterface(QObject *parent) - : QObject(parent) -{ - d = new QNetworkManagerInterfacePrivate(); - d->connectionInterface = new QDBusInterface(QLatin1String(NM_DBUS_SERVICE), - QLatin1String(NM_DBUS_PATH), - QLatin1String(NM_DBUS_INTERFACE), - QDBusConnection::systemBus(),parent); - if (!d->connectionInterface->isValid()) { - d->valid = false; + : QDBusAbstractInterface(QLatin1String(NM_DBUS_SERVICE), + QLatin1String(NM_DBUS_PATH), + NM_DBUS_INTERFACE, + QDBusConnection::systemBus(),parent) +{ + if (!isValid()) { return; } - d->valid = true; - QDBusInterface managerPropertiesInterface(QLatin1String(NM_DBUS_SERVICE), + PropertiesDBusInterface managerPropertiesInterface(QLatin1String(NM_DBUS_SERVICE), QLatin1String(NM_DBUS_PATH), - QLatin1String("org.freedesktop.DBus.Properties"), + DBUS_PROPERTIES_INTERFACE, QDBusConnection::systemBus()); QList<QVariant> argumentList; argumentList << QLatin1String(NM_DBUS_INTERFACE); @@ -81,13 +73,17 @@ QNetworkManagerInterface::QNetworkManagerInterface(QObject *parent) argumentList); if (!propsReply.isError()) { propertyMap = propsReply.value(); + } else { + qWarning() << Q_FUNC_INFO << "propsReply"<<propsReply.error().message(); } QDBusPendingReply<QList <QDBusObjectPath> > nmReply - = d->connectionInterface->call(QLatin1String("GetDevices")); + = call(QLatin1String("GetDevices")); nmReply.waitForFinished(); if (!nmReply.isError()) { devicesPathList = nmReply.value(); + } else { + qWarning() << Q_FUNC_INFO <<"nmReply"<<nmReply.error().message(); } QDBusConnection::systemBus().connect(QLatin1String(NM_DBUS_SERVICE), @@ -99,13 +95,6 @@ QNetworkManagerInterface::QNetworkManagerInterface(QObject *parent) QNetworkManagerInterface::~QNetworkManagerInterface() { - delete d->connectionInterface; - delete d; -} - -bool QNetworkManagerInterface::isValid() -{ - return d->valid; } bool QNetworkManagerInterface::setConnections() @@ -138,16 +127,11 @@ bool QNetworkManagerInterface::setConnections() return allOk; } -QDBusInterface *QNetworkManagerInterface::connectionInterface() const -{ - return d->connectionInterface; -} - QList <QDBusObjectPath> QNetworkManagerInterface::getDevices() { if (devicesPathList.isEmpty()) { //qWarning() << "using blocking call!"; - QDBusReply<QList<QDBusObjectPath> > reply = d->connectionInterface->call(QLatin1String("GetDevices")); + QDBusReply<QList<QDBusObjectPath> > reply = call(QLatin1String("GetDevices")); devicesPathList = reply.value(); } return devicesPathList; @@ -157,7 +141,7 @@ void QNetworkManagerInterface::activateConnection(QDBusObjectPath connectionPath QDBusObjectPath devicePath, QDBusObjectPath specificObject) { - QDBusPendingCall pendingCall = d->connectionInterface->asyncCall(QLatin1String("ActivateConnection"), + QDBusPendingCall pendingCall = asyncCall(QLatin1String("ActivateConnection"), QVariant::fromValue(connectionPath), QVariant::fromValue(devicePath), QVariant::fromValue(specificObject)); @@ -167,9 +151,9 @@ void QNetworkManagerInterface::activateConnection(QDBusObjectPath connectionPath this, SIGNAL(activationFinished(QDBusPendingCallWatcher*))); } -void QNetworkManagerInterface::deactivateConnection(QDBusObjectPath connectionPath) const +void QNetworkManagerInterface::deactivateConnection(QDBusObjectPath connectionPath) { - d->connectionInterface->asyncCall(QLatin1String("DeactivateConnection"), QVariant::fromValue(connectionPath)); + asyncCall(QLatin1String("DeactivateConnection"), QVariant::fromValue(connectionPath)); } bool QNetworkManagerInterface::wirelessEnabled() const @@ -245,73 +229,38 @@ void QNetworkManagerInterface::propertiesSwap(QMap<QString,QVariant> map) } } -class QNetworkManagerInterfaceAccessPointPrivate -{ -public: - QDBusInterface *connectionInterface; - QString path; - bool valid; -}; - QNetworkManagerInterfaceAccessPoint::QNetworkManagerInterfaceAccessPoint(const QString &dbusPathName, QObject *parent) - : QObject(parent) -{ - d = new QNetworkManagerInterfaceAccessPointPrivate(); - d->path = dbusPathName; - d->connectionInterface = new QDBusInterface(QLatin1String(NM_DBUS_SERVICE), - d->path, - QLatin1String(NM_DBUS_INTERFACE_ACCESS_POINT), - QDBusConnection::systemBus(),parent); - if (!d->connectionInterface->isValid()) { - d->valid = false; + : QDBusAbstractInterface(QLatin1String(NM_DBUS_SERVICE), + dbusPathName, + NM_DBUS_INTERFACE_ACCESS_POINT, + QDBusConnection::systemBus(),parent) +{ + if (!isValid()) { return; } - QDBusInterface accessPointPropertiesInterface(QLatin1String(NM_DBUS_SERVICE), - d->path, - QLatin1String("org.freedesktop.DBus.Properties"), + PropertiesDBusInterface *accessPointPropertiesInterface = new PropertiesDBusInterface(QLatin1String(NM_DBUS_SERVICE), + dbusPathName, + DBUS_PROPERTIES_INTERFACE, QDBusConnection::systemBus()); QList<QVariant> argumentList; argumentList << QLatin1String(NM_DBUS_INTERFACE_ACCESS_POINT); QDBusPendingReply<QVariantMap> propsReply - = accessPointPropertiesInterface.callWithArgumentList(QDBus::Block,QLatin1String("GetAll"), + = accessPointPropertiesInterface->callWithArgumentList(QDBus::Block,QLatin1String("GetAll"), argumentList); if (!propsReply.isError()) { propertyMap = propsReply.value(); } QDBusConnection::systemBus().connect(QLatin1String(NM_DBUS_SERVICE), - d->path, + dbusPathName, QLatin1String(NM_DBUS_INTERFACE_ACCESS_POINT), QLatin1String("PropertiesChanged"), this,SLOT(propertiesSwap(QMap<QString,QVariant>))); - - d->valid = true; - } QNetworkManagerInterfaceAccessPoint::~QNetworkManagerInterfaceAccessPoint() { - delete d->connectionInterface; - delete d; -} - -bool QNetworkManagerInterfaceAccessPoint::isValid() -{ - return d->valid; -} - -bool QNetworkManagerInterfaceAccessPoint::setConnections() -{ - if (!isValid()) - return false; - - return true; -} - -QDBusInterface *QNetworkManagerInterfaceAccessPoint::connectionInterface() const -{ - return d->connectionInterface; } quint32 QNetworkManagerInterfaceAccessPoint::flags() const @@ -386,31 +335,19 @@ void QNetworkManagerInterfaceAccessPoint::propertiesSwap(QMap<QString,QVariant> } } -class QNetworkManagerInterfaceDevicePrivate -{ -public: - QDBusInterface *connectionInterface; - QString path; - bool valid; -}; - QNetworkManagerInterfaceDevice::QNetworkManagerInterfaceDevice(const QString &deviceObjectPath, QObject *parent) - : QObject(parent) + : QDBusAbstractInterface(QLatin1String(NM_DBUS_SERVICE), + deviceObjectPath, + NM_DBUS_INTERFACE_DEVICE, + QDBusConnection::systemBus(),parent) { - d = new QNetworkManagerInterfaceDevicePrivate(); - d->path = deviceObjectPath; - d->connectionInterface = new QDBusInterface(QLatin1String(NM_DBUS_SERVICE), - d->path, - QLatin1String(NM_DBUS_INTERFACE_DEVICE), - QDBusConnection::systemBus(),parent); - if (!d->connectionInterface->isValid()) { - d->valid = false; + if (!isValid()) { return; } - QDBusInterface devicePropertiesInterface(QLatin1String(NM_DBUS_SERVICE), - d->path, - QLatin1String("org.freedesktop.DBus.Properties"), + PropertiesDBusInterface devicePropertiesInterface(QLatin1String(NM_DBUS_SERVICE), + deviceObjectPath, + DBUS_PROPERTIES_INTERFACE, QDBusConnection::systemBus(),parent); QList<QVariant> argumentList; @@ -424,35 +361,14 @@ QNetworkManagerInterfaceDevice::QNetworkManagerInterfaceDevice(const QString &de } QDBusConnection::systemBus().connect(QLatin1String(NM_DBUS_SERVICE), - d->path, + deviceObjectPath, QLatin1String(NM_DBUS_INTERFACE_DEVICE), QLatin1String("PropertiesChanged"), this,SLOT(propertiesSwap(QMap<QString,QVariant>))); - d->valid = true; } QNetworkManagerInterfaceDevice::~QNetworkManagerInterfaceDevice() { - delete d->connectionInterface; - delete d; -} - -bool QNetworkManagerInterfaceDevice::isValid() -{ - return d->valid; -} - -bool QNetworkManagerInterfaceDevice::setConnections() -{ - if (!isValid()) - return false; - - return true; -} - -QDBusInterface *QNetworkManagerInterfaceDevice::connectionInterface() const -{ - return d->connectionInterface; } QString QNetworkManagerInterfaceDevice::udi() const @@ -519,31 +435,19 @@ void QNetworkManagerInterfaceDevice::propertiesSwap(QMap<QString,QVariant> map) Q_EMIT propertiesChanged(map); } -class QNetworkManagerInterfaceDeviceWiredPrivate -{ -public: - QDBusInterface *connectionInterface; - QString path; - bool valid; -}; - QNetworkManagerInterfaceDeviceWired::QNetworkManagerInterfaceDeviceWired(const QString &ifaceDevicePath, QObject *parent) - : QObject(parent) -{ - d = new QNetworkManagerInterfaceDeviceWiredPrivate(); - d->path = ifaceDevicePath; - d->connectionInterface = new QDBusInterface(QLatin1String(NM_DBUS_SERVICE), - d->path, - QLatin1String(NM_DBUS_INTERFACE_DEVICE_WIRED), - QDBusConnection::systemBus(), parent); - if (!d->connectionInterface->isValid()) { - d->valid = false; + : QDBusAbstractInterface(QLatin1String(NM_DBUS_SERVICE), + ifaceDevicePath, + NM_DBUS_INTERFACE_DEVICE_WIRED, + QDBusConnection::systemBus(), parent) +{ + if (!isValid()) { return; } - QDBusInterface deviceWiredPropertiesInterface(QLatin1String(NM_DBUS_SERVICE), - d->path, - QLatin1String("org.freedesktop.DBus.Properties"), - QDBusConnection::systemBus(),parent); + PropertiesDBusInterface deviceWiredPropertiesInterface(QLatin1String(NM_DBUS_SERVICE), + ifaceDevicePath, + DBUS_PROPERTIES_INTERFACE, + QDBusConnection::systemBus(),parent); QList<QVariant> argumentList; argumentList << QLatin1String(NM_DBUS_INTERFACE_DEVICE_WIRED); @@ -556,36 +460,14 @@ QNetworkManagerInterfaceDeviceWired::QNetworkManagerInterfaceDeviceWired(const Q } QDBusConnection::systemBus().connect(QLatin1String(NM_DBUS_SERVICE), - d->path, + ifaceDevicePath, QLatin1String(NM_DBUS_INTERFACE_DEVICE_WIRED), QLatin1String("PropertiesChanged"), this,SLOT(propertiesSwap(QMap<QString,QVariant>))); - - d->valid = true; } QNetworkManagerInterfaceDeviceWired::~QNetworkManagerInterfaceDeviceWired() { - delete d->connectionInterface; - delete d; -} - -bool QNetworkManagerInterfaceDeviceWired::isValid() -{ - - return d->valid; -} - -bool QNetworkManagerInterfaceDeviceWired::setConnections() -{ - if (!isValid()) - return false; - return true; -} - -QDBusInterface *QNetworkManagerInterfaceDeviceWired::connectionInterface() const -{ - return d->connectionInterface; } QString QNetworkManagerInterfaceDeviceWired::hwAddress() const @@ -639,39 +521,27 @@ void QNetworkManagerInterfaceDeviceWired::propertiesSwap(QMap<QString,QVariant> Q_EMIT propertiesChanged(map); } -class QNetworkManagerInterfaceDeviceWirelessPrivate -{ -public: - QDBusInterface *connectionInterface; - QString path; - bool valid; -}; - QNetworkManagerInterfaceDeviceWireless::QNetworkManagerInterfaceDeviceWireless(const QString &ifaceDevicePath, QObject *parent) - : QObject(parent) -{ - d = new QNetworkManagerInterfaceDeviceWirelessPrivate(); - d->path = ifaceDevicePath; - d->connectionInterface = new QDBusInterface(QLatin1String(NM_DBUS_SERVICE), - d->path, - QLatin1String(NM_DBUS_INTERFACE_DEVICE_WIRELESS), - QDBusConnection::systemBus(), parent); - if (!d->connectionInterface->isValid()) { - d->valid = false; + : QDBusAbstractInterface(QLatin1String(NM_DBUS_SERVICE), + ifaceDevicePath, + NM_DBUS_INTERFACE_DEVICE_WIRELESS, + QDBusConnection::systemBus(), parent) +{ + if (!isValid()) { return; } - + interfacePath = ifaceDevicePath; QDBusPendingReply<QList <QDBusObjectPath> > nmReply - = d->connectionInterface->call(QLatin1String("GetAccessPoints")); + = call(QLatin1String("GetAccessPoints")); if (!nmReply.isError()) { accessPointsList = nmReply.value(); } - QDBusInterface deviceWirelessPropertiesInterface(QLatin1String(NM_DBUS_SERVICE), - d->path, - QLatin1String("org.freedesktop.DBus.Properties"), + PropertiesDBusInterface deviceWirelessPropertiesInterface(QLatin1String(NM_DBUS_SERVICE), + interfacePath, + DBUS_PROPERTIES_INTERFACE, QDBusConnection::systemBus(),parent); QList<QVariant> argumentList; @@ -684,31 +554,21 @@ QNetworkManagerInterfaceDeviceWireless::QNetworkManagerInterfaceDeviceWireless(c } QDBusConnection::systemBus().connect(QLatin1String(NM_DBUS_SERVICE), - d->path, + interfacePath, QLatin1String(NM_DBUS_INTERFACE_DEVICE_WIRELESS), QLatin1String("PropertiesChanged"), this,SLOT(propertiesSwap(QMap<QString,QVariant>))); QDBusPendingReply<QList<QDBusObjectPath> > reply - = d->connectionInterface->asyncCall(QLatin1String("GetAccessPoints")); + = asyncCall(QLatin1String("GetAccessPoints")); QDBusPendingCallWatcher *callWatcher = new QDBusPendingCallWatcher(reply); connect(callWatcher, SIGNAL(finished(QDBusPendingCallWatcher*)), this, SLOT(accessPointsFinished(QDBusPendingCallWatcher*))); - - - d->valid = true; } QNetworkManagerInterfaceDeviceWireless::~QNetworkManagerInterfaceDeviceWireless() { - delete d->connectionInterface; - delete d; -} - -bool QNetworkManagerInterfaceDeviceWireless::isValid() -{ - return d->valid; } void QNetworkManagerInterfaceDeviceWireless::slotAccessPointAdded(QDBusObjectPath path) @@ -732,16 +592,16 @@ bool QNetworkManagerInterfaceDeviceWireless::setConnections() bool allOk = true; if (!dbusConnection.connect(QLatin1String(NM_DBUS_SERVICE), - d->path, - QLatin1String(NM_DBUS_INTERFACE_DEVICE_WIRELESS), - QLatin1String("AccessPointAdded"), - this, SLOT(slotAccessPointAdded(QDBusObjectPath)))) { + interfacePath, + QLatin1String(NM_DBUS_INTERFACE_DEVICE_WIRELESS), + QLatin1String("AccessPointAdded"), + this, SLOT(slotAccessPointAdded(QDBusObjectPath)))) { allOk = false; } if (!dbusConnection.connect(QLatin1String(NM_DBUS_SERVICE), - d->path, + interfacePath, QLatin1String(NM_DBUS_INTERFACE_DEVICE_WIRELESS), QLatin1String("AccessPointRemoved"), this, SLOT(slotAccessPointRemoved(QDBusObjectPath)))) { @@ -749,7 +609,7 @@ bool QNetworkManagerInterfaceDeviceWireless::setConnections() } if (!dbusConnection.connect(QLatin1String(NM_DBUS_SERVICE), - d->path, + interfacePath, QLatin1String(NM_DBUS_INTERFACE_DEVICE_WIRELESS), QLatin1String("ScanDone"), this, SLOT(scanIsDone()))) { @@ -771,17 +631,12 @@ void QNetworkManagerInterfaceDeviceWireless::accessPointsFinished(QDBusPendingCa } } -QDBusInterface *QNetworkManagerInterfaceDeviceWireless::connectionInterface() const -{ - return d->connectionInterface; -} - QList <QDBusObjectPath> QNetworkManagerInterfaceDeviceWireless::getAccessPoints() { if (accessPointsList.isEmpty()) { //qWarning() << "Using blocking call!"; QDBusReply<QList<QDBusObjectPath> > reply - = d->connectionInterface->call(QLatin1String("GetAccessPoints")); + = call(QLatin1String("GetAccessPoints")); accessPointsList = reply.value(); } return accessPointsList; @@ -829,7 +684,7 @@ void QNetworkManagerInterfaceDeviceWireless::scanIsDone() void QNetworkManagerInterfaceDeviceWireless::requestScan() { - d->connectionInterface->asyncCall(QLatin1String("RequestScan")); + asyncCall(QLatin1String("RequestScan")); } void QNetworkManagerInterfaceDeviceWireless::propertiesSwap(QMap<QString,QVariant> map) @@ -844,29 +699,17 @@ void QNetworkManagerInterfaceDeviceWireless::propertiesSwap(QMap<QString,QVarian } } -class QNetworkManagerInterfaceDeviceModemPrivate -{ -public: - QDBusInterface *connectionInterface; - QString path; - bool valid; -}; - QNetworkManagerInterfaceDeviceModem::QNetworkManagerInterfaceDeviceModem(const QString &ifaceDevicePath, QObject *parent) - : QObject(parent) -{ - d = new QNetworkManagerInterfaceDeviceModemPrivate(); - d->path = ifaceDevicePath; - d->connectionInterface = new QDBusInterface(QLatin1String(NM_DBUS_SERVICE), - d->path, - QLatin1String(NM_DBUS_INTERFACE_DEVICE_MODEM), - QDBusConnection::systemBus(), parent); - if (!d->connectionInterface->isValid()) { - d->valid = false; + : QDBusAbstractInterface(QLatin1String(NM_DBUS_SERVICE), + ifaceDevicePath, + NM_DBUS_INTERFACE_DEVICE_MODEM, + QDBusConnection::systemBus(), parent) +{ + if (!isValid()) { return; } - QDBusInterface deviceModemPropertiesInterface(QLatin1String(NM_DBUS_SERVICE), - d->path, + PropertiesDBusInterface deviceModemPropertiesInterface(QLatin1String(NM_DBUS_SERVICE), + ifaceDevicePath, QLatin1String("org.freedesktop.DBus.Properties"), QDBusConnection::systemBus(),parent); @@ -880,36 +723,14 @@ QNetworkManagerInterfaceDeviceModem::QNetworkManagerInterfaceDeviceModem(const Q } QDBusConnection::systemBus().connect(QLatin1String(NM_DBUS_SERVICE), - d->path, + ifaceDevicePath, QLatin1String(NM_DBUS_INTERFACE_DEVICE_MODEM), QLatin1String("PropertiesChanged"), this,SLOT(propertiesSwap(QMap<QString,QVariant>))); - d->valid = true; } QNetworkManagerInterfaceDeviceModem::~QNetworkManagerInterfaceDeviceModem() { - delete d->connectionInterface; - delete d; -} - -bool QNetworkManagerInterfaceDeviceModem::isValid() -{ - - return d->valid; -} - -bool QNetworkManagerInterfaceDeviceModem::setConnections() -{ - if (!isValid() ) - return false; - - return true; -} - -QDBusInterface *QNetworkManagerInterfaceDeviceModem::connectionInterface() const -{ - return d->connectionInterface; } QNetworkManagerInterfaceDeviceModem::ModemCapabilities QNetworkManagerInterfaceDeviceModem::modemCapabilities() const @@ -936,59 +757,39 @@ void QNetworkManagerInterfaceDeviceModem::propertiesSwap(QMap<QString,QVariant> Q_EMIT propertiesChanged(map); } -class QNetworkManagerSettingsPrivate -{ -public: - QDBusInterface *connectionInterface; - QString path; - bool valid; -}; QNetworkManagerSettings::QNetworkManagerSettings(const QString &settingsService, QObject *parent) - : QObject(parent) -{ - d = new QNetworkManagerSettingsPrivate(); - d->path = settingsService; - d->connectionInterface = new QDBusInterface(settingsService, - QLatin1String(NM_DBUS_PATH_SETTINGS), - QLatin1String(NM_DBUS_IFACE_SETTINGS), - QDBusConnection::systemBus()); - if (!d->connectionInterface->isValid()) { - d->valid = false; + : QDBusAbstractInterface(settingsService, + NM_DBUS_PATH_SETTINGS, + NM_DBUS_IFACE_SETTINGS, + QDBusConnection::systemBus(), parent) +{ + if (!isValid()) { return; } - + interfacePath = settingsService; QDBusPendingReply<QList <QDBusObjectPath> > nmReply - = d->connectionInterface->call(QLatin1String("ListConnections")); + = call(QLatin1String("ListConnections")); if (!nmReply.isError()) { connectionsList = nmReply.value(); } - - d->valid = true; } QNetworkManagerSettings::~QNetworkManagerSettings() { - delete d->connectionInterface; - delete d; -} - -bool QNetworkManagerSettings::isValid() -{ - return d->valid; } bool QNetworkManagerSettings::setConnections() { bool allOk = true; - - if (!QDBusConnection::systemBus().connect(d->path, + if (!QDBusConnection::systemBus().connect(interfacePath, QLatin1String(NM_DBUS_PATH_SETTINGS), QLatin1String(NM_DBUS_IFACE_SETTINGS), QLatin1String("NewConnection"), this, SIGNAL(newConnection(QDBusObjectPath)))) { allOk = false; + qWarning() << Q_FUNC_INFO << "NewConnection could not be connected"; } return allOk; @@ -999,7 +800,7 @@ QList <QDBusObjectPath> QNetworkManagerSettings::listConnections() if (connectionsList.isEmpty()) { //qWarning() << "Using blocking call!"; QDBusReply<QList<QDBusObjectPath> > reply - = d->connectionInterface->call(QLatin1String("ListConnections")); + = call(QLatin1String("ListConnections")); connectionsList = reply.value(); } return connectionsList; @@ -1010,59 +811,30 @@ QString QNetworkManagerSettings::getConnectionByUuid(const QString &uuid) { QList<QVariant> argumentList; argumentList << QVariant::fromValue(uuid); - QDBusReply<QDBusObjectPath > reply = d->connectionInterface->callWithArgumentList(QDBus::Block,QLatin1String("GetConnectionByUuid"), argumentList); + QDBusReply<QDBusObjectPath > reply = callWithArgumentList(QDBus::Block,QLatin1String("GetConnectionByUuid"), argumentList); return reply.value().path(); } -QDBusInterface *QNetworkManagerSettings::connectionInterface() const -{ - return d->connectionInterface; -} - - -class QNetworkManagerSettingsConnectionPrivate -{ -public: - QDBusInterface *connectionInterface; - QString path; - QString service; - QNmSettingsMap settingsMap; - bool valid; -}; - QNetworkManagerSettingsConnection::QNetworkManagerSettingsConnection(const QString &settingsService, const QString &connectionObjectPath, QObject *parent) - : QObject(parent) + : QDBusAbstractInterface(settingsService, + connectionObjectPath, + NM_DBUS_IFACE_SETTINGS_CONNECTION, + QDBusConnection::systemBus(), parent) { qDBusRegisterMetaType<QNmSettingsMap>(); - d = new QNetworkManagerSettingsConnectionPrivate(); - d->path = connectionObjectPath; - d->service = settingsService; - d->connectionInterface = new QDBusInterface(settingsService, - d->path, - QLatin1String(NM_DBUS_IFACE_SETTINGS_CONNECTION), - QDBusConnection::systemBus(), parent); - if (!d->connectionInterface->isValid()) { - d->valid = false; + if (!isValid()) { return; } - d->valid = true; - + interfacepath = connectionObjectPath; QDBusPendingReply<QNmSettingsMap> nmReply - = d->connectionInterface->call(QLatin1String("GetSettings")); + = call(QLatin1String("GetSettings")); if (!nmReply.isError()) { - d->settingsMap = nmReply.value(); + settingsMap = nmReply.value(); } } QNetworkManagerSettingsConnection::~QNetworkManagerSettingsConnection() { - delete d->connectionInterface; - delete d; -} - -bool QNetworkManagerSettingsConnection::isValid() -{ - return d->valid; } bool QNetworkManagerSettingsConnection::setConnections() @@ -1072,16 +844,16 @@ bool QNetworkManagerSettingsConnection::setConnections() QDBusConnection dbusConnection = QDBusConnection::systemBus(); bool allOk = true; - if (!dbusConnection.connect(d->service, - d->path, + if (!dbusConnection.connect(service(), + interfacepath, QLatin1String(NM_DBUS_IFACE_SETTINGS_CONNECTION), QLatin1String("Updated"), this, SIGNAL(updated()))) { allOk = false; } - if (!dbusConnection.connect(d->service, - d->path, + if (!dbusConnection.connect(service(), + interfacepath, QLatin1String(NM_DBUS_IFACE_SETTINGS_CONNECTION), QLatin1String("Removed"), this, SIGNAL(slotSettingsRemoved()))) { @@ -1092,28 +864,23 @@ bool QNetworkManagerSettingsConnection::setConnections() void QNetworkManagerSettingsConnection::slotSettingsRemoved() { - Q_EMIT removed(d->path); -} - -QDBusInterface *QNetworkManagerSettingsConnection::connectionInterface() const -{ - return d->connectionInterface; + Q_EMIT removed(interfacepath); } QNmSettingsMap QNetworkManagerSettingsConnection::getSettings() { - if (d->settingsMap.isEmpty()) { + if (settingsMap.isEmpty()) { //qWarning() << "Using blocking call!"; - QDBusReply<QNmSettingsMap> reply = d->connectionInterface->call(QLatin1String("GetSettings")); - d->settingsMap = reply.value(); + QDBusReply<QNmSettingsMap> reply = call(QLatin1String("GetSettings")); + settingsMap = reply.value(); } - return d->settingsMap; + return settingsMap; } NMDeviceType QNetworkManagerSettingsConnection::getType() { const QString devType = - d->settingsMap.value(QLatin1String("connection")).value(QLatin1String("type")).toString(); + settingsMap.value(QLatin1String("connection")).value(QLatin1String("type")).toString(); if (devType == QLatin1String("802-3-ethernet")) return DEVICE_TYPE_ETHERNET; @@ -1128,7 +895,7 @@ NMDeviceType QNetworkManagerSettingsConnection::getType() bool QNetworkManagerSettingsConnection::isAutoConnect() { const QVariant autoConnect = - d->settingsMap.value(QLatin1String("connection")).value(QLatin1String("autoconnect")); + settingsMap.value(QLatin1String("connection")).value(QLatin1String("autoconnect")); // NetworkManager default is to auto connect if (!autoConnect.isValid()) @@ -1139,27 +906,27 @@ bool QNetworkManagerSettingsConnection::isAutoConnect() quint64 QNetworkManagerSettingsConnection::getTimestamp() { - return d->settingsMap.value(QLatin1String("connection")) + return settingsMap.value(QLatin1String("connection")) .value(QLatin1String("timestamp")).toUInt(); } QString QNetworkManagerSettingsConnection::getId() { - return d->settingsMap.value(QLatin1String("connection")).value(QLatin1String("id")).toString(); + return settingsMap.value(QLatin1String("connection")).value(QLatin1String("id")).toString(); } QString QNetworkManagerSettingsConnection::getUuid() { - const QString id = d->settingsMap.value(QLatin1String("connection")) + const QString id = settingsMap.value(QLatin1String("connection")) .value(QLatin1String("uuid")).toString(); // is no uuid, return the connection path - return id.isEmpty() ? d->connectionInterface->path() : id; + return id.isEmpty() ? path() : id; } QString QNetworkManagerSettingsConnection::getSsid() { - return d->settingsMap.value(QLatin1String("802-11-wireless")) + return settingsMap.value(QLatin1String("802-11-wireless")) .value(QLatin1String("ssid")).toString(); } @@ -1168,10 +935,10 @@ QString QNetworkManagerSettingsConnection::getMacAddress() NMDeviceType type = getType(); if (type == DEVICE_TYPE_ETHERNET) { - return d->settingsMap.value(QLatin1String("802-3-ethernet")) + return settingsMap.value(QLatin1String("802-3-ethernet")) .value(QLatin1String("mac-address")).toString(); } else if (type == DEVICE_TYPE_WIFI) { - return d->settingsMap.value(QLatin1String("802-11-wireless")) + return settingsMap.value(QLatin1String("802-11-wireless")) .value(QLatin1String("mac-address")).toString(); } else { return QString(); @@ -1181,36 +948,24 @@ QString QNetworkManagerSettingsConnection::getMacAddress() QStringList QNetworkManagerSettingsConnection::getSeenBssids() { if (getType() == DEVICE_TYPE_WIFI) { - return d->settingsMap.value(QLatin1String("802-11-wireless")) + return settingsMap.value(QLatin1String("802-11-wireless")) .value(QLatin1String("seen-bssids")).toStringList(); } else { return QStringList(); } } -class QNetworkManagerConnectionActivePrivate -{ -public: - QDBusInterface *connectionInterface; - QString path; - bool valid; -}; - QNetworkManagerConnectionActive::QNetworkManagerConnectionActive(const QString &activeConnectionObjectPath, QObject *parent) - : QObject(parent) -{ - d = new QNetworkManagerConnectionActivePrivate(); - d->path = activeConnectionObjectPath; - d->connectionInterface = new QDBusInterface(QLatin1String(NM_DBUS_SERVICE), - d->path, - QLatin1String(NM_DBUS_INTERFACE_ACTIVE_CONNECTION), - QDBusConnection::systemBus(), parent); - if (!d->connectionInterface->isValid()) { - d->valid = false; + : QDBusAbstractInterface(QLatin1String(NM_DBUS_SERVICE), + activeConnectionObjectPath, + NM_DBUS_INTERFACE_ACTIVE_CONNECTION, + QDBusConnection::systemBus(), parent) +{ + if (!isValid()) { return; } - QDBusInterface connectionActivePropertiesInterface(QLatin1String(NM_DBUS_SERVICE), - d->path, + PropertiesDBusInterface connectionActivePropertiesInterface(QLatin1String(NM_DBUS_SERVICE), + activeConnectionObjectPath, QLatin1String("org.freedesktop.DBus.Properties"), QDBusConnection::systemBus()); @@ -1228,35 +983,14 @@ QNetworkManagerConnectionActive::QNetworkManagerConnectionActive(const QString & } QDBusConnection::systemBus().connect(QLatin1String(NM_DBUS_SERVICE), - d->path, + activeConnectionObjectPath, QLatin1String(NM_DBUS_INTERFACE_ACTIVE_CONNECTION), QLatin1String("PropertiesChanged"), this,SLOT(propertiesSwap(QMap<QString,QVariant>))); - d->valid = true; } QNetworkManagerConnectionActive::~QNetworkManagerConnectionActive() { - delete d->connectionInterface; - delete d; -} - -bool QNetworkManagerConnectionActive::isValid() -{ - return d->valid; -} - -bool QNetworkManagerConnectionActive::setConnections() -{ - if (!isValid()) - return false; - - return true; -} - -QDBusInterface *QNetworkManagerConnectionActive::connectionInterface() const -{ - return d->connectionInterface; } QDBusObjectPath QNetworkManagerConnectionActive::connection() const @@ -1327,44 +1061,24 @@ void QNetworkManagerConnectionActive::propertiesSwap(QMap<QString,QVariant> map) } } -class QNetworkManagerIp4ConfigPrivate -{ -public: - QDBusInterface *connectionInterface; - QString path; - bool valid; -}; - QNetworkManagerIp4Config::QNetworkManagerIp4Config( const QString &deviceObjectPath, QObject *parent) - : QObject(parent) -{ - d = new QNetworkManagerIp4ConfigPrivate(); - d->path = deviceObjectPath; - d->connectionInterface = new QDBusInterface(QLatin1String(NM_DBUS_SERVICE), - d->path, - QLatin1String(NM_DBUS_INTERFACE_IP4_CONFIG), - QDBusConnection::systemBus(), parent); - if (!d->connectionInterface->isValid()) { - d->valid = false; + : QDBusAbstractInterface(QLatin1String(NM_DBUS_SERVICE), + deviceObjectPath, + NM_DBUS_INTERFACE_IP4_CONFIG, + QDBusConnection::systemBus(), parent) +{ + if (!isValid()) { return; } - d->valid = true; } QNetworkManagerIp4Config::~QNetworkManagerIp4Config() { - delete d->connectionInterface; - delete d; -} - -bool QNetworkManagerIp4Config::isValid() -{ - return d->valid; } QStringList QNetworkManagerIp4Config::domains() const { - return d->connectionInterface->property("Domains").toStringList(); + return property("Domains").toStringList(); } QT_END_NAMESPACE diff --git a/src/plugins/bearer/networkmanager/qnetworkmanagerservice.h b/src/plugins/bearer/networkmanager/qnetworkmanagerservice.h index e645159d71..f945532603 100644 --- a/src/plugins/bearer/networkmanager/qnetworkmanagerservice.h +++ b/src/plugins/bearer/networkmanager/qnetworkmanagerservice.h @@ -55,6 +55,7 @@ #include <QtDBus/QDBusPendingCallWatcher> #include <QtDBus/QDBusObjectPath> #include <QtDBus/QDBusContext> +#include <QtDBus/QDBusAbstractInterface> #include <QMap> #ifndef QT_NO_DBUS @@ -128,8 +129,7 @@ Q_DECLARE_METATYPE(QT_PREPEND_NAMESPACE(ServerThing)) QT_BEGIN_NAMESPACE -class QNetworkManagerInterfacePrivate; -class QNetworkManagerInterface : public QObject +class QNetworkManagerInterface : public QDBusAbstractInterface { Q_OBJECT @@ -151,10 +151,9 @@ public: QList <QDBusObjectPath> getDevices(); void activateConnection(QDBusObjectPath connection,QDBusObjectPath device, QDBusObjectPath specificObject); - void deactivateConnection(QDBusObjectPath connectionPath) const; + void deactivateConnection(QDBusObjectPath connectionPath); QDBusObjectPath path() const; - QDBusInterface *connectionInterface() const; bool wirelessEnabled() const; bool wirelessHardwareEnabled() const; @@ -162,7 +161,6 @@ public: NMState state(); QString version() const; bool setConnections(); - bool isValid(); Q_SIGNALS: void deviceAdded(QDBusObjectPath); @@ -177,14 +175,12 @@ private Q_SLOTS: void propertiesSwap(QMap<QString,QVariant>); private: - QNetworkManagerInterfacePrivate *d; QVariantMap propertyMap; QList<QDBusObjectPath> devicesPathList; }; -class QNetworkManagerInterfaceAccessPointPrivate; -class QNetworkManagerInterfaceAccessPoint : public QObject +class QNetworkManagerInterfaceAccessPoint : public QDBusAbstractInterface { Q_OBJECT @@ -229,8 +225,6 @@ public: explicit QNetworkManagerInterfaceAccessPoint(const QString &dbusPathName, QObject *parent = 0); ~QNetworkManagerInterfaceAccessPoint(); - QDBusInterface *connectionInterface() const; - quint32 flags() const; quint32 wpaFlags() const; quint32 rsnFlags() const; @@ -240,8 +234,7 @@ public: quint32 mode() const; quint32 maxBitrate() const; quint32 strength() const; - bool setConnections(); - bool isValid(); + // bool setConnections(); Q_SIGNALS: void propertiesChanged(QMap <QString,QVariant>); @@ -251,12 +244,10 @@ private Q_SLOTS: void propertiesSwap(QMap<QString,QVariant>); private: - QNetworkManagerInterfaceAccessPointPrivate *d; QVariantMap propertyMap; }; -class QNetworkManagerInterfaceDevicePrivate; -class QNetworkManagerInterfaceDevice : public QObject +class QNetworkManagerInterfaceDevice : public QDBusAbstractInterface { Q_OBJECT @@ -267,14 +258,11 @@ public: QString udi() const; QString networkInterface() const; - QDBusInterface *connectionInterface() const; quint32 ip4Address() const; quint32 state() const; quint32 deviceType() const; QDBusObjectPath ip4config() const; - bool setConnections(); - bool isValid(); Q_SIGNALS: void stateChanged(const QString &, quint32); @@ -284,12 +272,10 @@ Q_SIGNALS: private Q_SLOTS: void propertiesSwap(QMap<QString,QVariant>); private: - QNetworkManagerInterfaceDevicePrivate *d; QVariantMap propertyMap; }; -class QNetworkManagerInterfaceDeviceWiredPrivate; -class QNetworkManagerInterfaceDeviceWired : public QObject +class QNetworkManagerInterfaceDeviceWired : public QDBusAbstractInterface { Q_OBJECT @@ -299,12 +285,9 @@ public: QObject *parent = 0); ~QNetworkManagerInterfaceDeviceWired(); - QDBusInterface *connectionInterface() const; QString hwAddress() const; quint32 speed() const; bool carrier() const; - bool setConnections(); - bool isValid(); QStringList availableConnections(); Q_SIGNALS: @@ -316,12 +299,10 @@ private Q_SLOTS: void propertiesSwap(QMap<QString,QVariant>); private: - QNetworkManagerInterfaceDeviceWiredPrivate *d; QVariantMap propertyMap; }; -class QNetworkManagerInterfaceDeviceWirelessPrivate; -class QNetworkManagerInterfaceDeviceWireless : public QObject +class QNetworkManagerInterfaceDeviceWireless : public QDBusAbstractInterface { Q_OBJECT @@ -343,7 +324,6 @@ public: QDBusObjectPath path() const; QList <QDBusObjectPath> getAccessPoints(); - QDBusInterface *connectionInterface() const; QString hwAddress() const; quint32 mode() const; @@ -351,7 +331,6 @@ public: QDBusObjectPath activeAccessPoint() const; quint32 wirelessCapabilities() const; bool setConnections(); - bool isValid(); void requestScan(); Q_SIGNALS: @@ -372,13 +351,12 @@ private Q_SLOTS: void accessPointsFinished(QDBusPendingCallWatcher *watcher); private: - QNetworkManagerInterfaceDeviceWirelessPrivate *d; QVariantMap propertyMap; QList <QDBusObjectPath> accessPointsList; + QString interfacePath; }; -class QNetworkManagerInterfaceDeviceModemPrivate; -class QNetworkManagerInterfaceDeviceModem : public QObject +class QNetworkManagerInterfaceDeviceModem : public QDBusAbstractInterface { Q_OBJECT @@ -397,12 +375,6 @@ public: QObject *parent = 0); ~QNetworkManagerInterfaceDeviceModem(); - QDBusObjectPath path() const; - QDBusInterface *connectionInterface() const; - - bool setConnections(); - bool isValid(); - ModemCapabilities modemCapabilities() const; ModemCapabilities currentCapabilities() const; @@ -414,14 +386,12 @@ private Q_SLOTS: void propertiesSwap(QMap<QString,QVariant>); private: - QNetworkManagerInterfaceDeviceModemPrivate *d; QVariantMap propertyMap; }; Q_DECLARE_OPERATORS_FOR_FLAGS(QNetworkManagerInterfaceDeviceModem::ModemCapabilities) -class QNetworkManagerSettingsPrivate; -class QNetworkManagerSettings : public QObject +class QNetworkManagerSettings : public QDBusAbstractInterface { Q_OBJECT @@ -430,22 +400,19 @@ public: explicit QNetworkManagerSettings(const QString &settingsService, QObject *parent = 0); ~QNetworkManagerSettings(); - QDBusInterface *connectionInterface() const; QList <QDBusObjectPath> listConnections(); QString getConnectionByUuid(const QString &uuid); bool setConnections(); - bool isValid(); Q_SIGNALS: void newConnection(QDBusObjectPath); void connectionsListReady(); private: - QNetworkManagerSettingsPrivate *d; QList <QDBusObjectPath> connectionsList; + QString interfacePath; }; -class QNetworkManagerSettingsConnectionPrivate; -class QNetworkManagerSettingsConnection : public QObject +class QNetworkManagerSettingsConnection : public QDBusAbstractInterface { Q_OBJECT @@ -454,7 +421,6 @@ public: QNetworkManagerSettingsConnection(const QString &settingsService, const QString &connectionObjectPath, QObject *parent = 0); ~QNetworkManagerSettingsConnection(); - QDBusInterface *connectionInterface() const; QNmSettingsMap getSettings(); bool setConnections(); NMDeviceType getType(); @@ -465,7 +431,6 @@ public: QString getSsid(); QString getMacAddress(); QStringList getSeenBssids(); - bool isValid(); Q_SIGNALS: void updated(); @@ -474,13 +439,12 @@ Q_SIGNALS: private Q_SLOTS: void slotSettingsRemoved(); - private: - QNetworkManagerSettingsConnectionPrivate *d; + QNmSettingsMap settingsMap; + QString interfacepath; }; -class QNetworkManagerConnectionActivePrivate; -class QNetworkManagerConnectionActive : public QObject +class QNetworkManagerConnectionActive : public QDBusAbstractInterface { Q_OBJECT @@ -495,15 +459,12 @@ public: explicit QNetworkManagerConnectionActive(const QString &dbusPathName, QObject *parent = 0); ~ QNetworkManagerConnectionActive(); - QDBusInterface *connectionInterface() const; QDBusObjectPath connection() const; QDBusObjectPath specificObject() const; QStringList devices() const; quint32 state() const; bool defaultRoute() const; bool default6Route() const; - bool setConnections(); - bool isValid(); Q_SIGNALS: @@ -514,12 +475,10 @@ private Q_SLOTS: void propertiesSwap(QMap<QString,QVariant>); private: - QNetworkManagerConnectionActivePrivate *d; QVariantMap propertyMap; }; -class QNetworkManagerIp4ConfigPrivate; -class QNetworkManagerIp4Config : public QObject +class QNetworkManagerIp4Config : public QDBusAbstractInterface { Q_OBJECT @@ -528,10 +487,17 @@ public: ~QNetworkManagerIp4Config(); QStringList domains() const; - bool isValid(); +}; - private: - QNetworkManagerIp4ConfigPrivate *d; +class PropertiesDBusInterface : public QDBusAbstractInterface +{ +public: + PropertiesDBusInterface(const QString &service, const QString &path, + const QString &interface, const QDBusConnection &connection, + QObject *parent = 0) + : QDBusAbstractInterface(service, path, interface.toLatin1().data(), connection, parent) + {} + ~PropertiesDBusInterface() = default; }; QT_END_NAMESPACE diff --git a/src/plugins/platforms/android/androidjnimain.cpp b/src/plugins/platforms/android/androidjnimain.cpp index df0a8c56cb..ab653860f3 100644 --- a/src/plugins/platforms/android/androidjnimain.cpp +++ b/src/plugins/platforms/android/androidjnimain.cpp @@ -376,8 +376,6 @@ namespace QtAndroid const auto &it = m_surfaces.find(surfaceId); if (it != m_surfaces.end()) m_surfaces.remove(surfaceId); - if (m_surfaces.isEmpty()) - m_surfaceId = 1; QJNIEnvironmentPrivate env; if (!env) diff --git a/src/plugins/platforms/android/qandroidplatformopenglcontext.cpp b/src/plugins/platforms/android/qandroidplatformopenglcontext.cpp index 5781f0d7c6..4c38178343 100644 --- a/src/plugins/platforms/android/qandroidplatformopenglcontext.cpp +++ b/src/plugins/platforms/android/qandroidplatformopenglcontext.cpp @@ -50,8 +50,10 @@ QAndroidPlatformOpenGLContext::QAndroidPlatformOpenGLContext(const QSurfaceForma void QAndroidPlatformOpenGLContext::swapBuffers(QPlatformSurface *surface) { - if (surface->surface()->surfaceClass() == QSurface::Window) - static_cast<QAndroidPlatformOpenGLWindow *>(surface)->checkNativeSurface(eglConfig()); + if (surface->surface()->surfaceClass() == QSurface::Window && + static_cast<QAndroidPlatformOpenGLWindow *>(surface)->checkNativeSurface(eglConfig())) { + QEGLPlatformContext::makeCurrent(surface); + } QEGLPlatformContext::swapBuffers(surface); } diff --git a/src/plugins/platforms/android/qandroidplatformopenglwindow.cpp b/src/plugins/platforms/android/qandroidplatformopenglwindow.cpp index 8dc8e84f0a..de7f1f6990 100644 --- a/src/plugins/platforms/android/qandroidplatformopenglwindow.cpp +++ b/src/plugins/platforms/android/qandroidplatformopenglwindow.cpp @@ -138,19 +138,19 @@ EGLSurface QAndroidPlatformOpenGLWindow::eglSurface(EGLConfig config) return m_eglSurface; } -void QAndroidPlatformOpenGLWindow::checkNativeSurface(EGLConfig config) +bool QAndroidPlatformOpenGLWindow::checkNativeSurface(EGLConfig config) { QMutexLocker lock(&m_surfaceMutex); if (m_nativeSurfaceId == -1 || !m_androidSurfaceObject.isValid()) - return; + return false; // makeCurrent is NOT needed. createEgl(config); - // we've create another surface, the window should be repainted QRect availableGeometry = screen()->availableGeometry(); if (geometry().width() > 0 && geometry().height() > 0 && availableGeometry.width() > 0 && availableGeometry.height() > 0) QWindowSystemInterface::handleExposeEvent(window(), QRegion(QRect(QPoint(), geometry().size()))); + return true; // makeCurrent is needed! } void QAndroidPlatformOpenGLWindow::applicationStateChanged(Qt::ApplicationState state) @@ -209,15 +209,19 @@ void QAndroidPlatformOpenGLWindow::surfaceChanged(JNIEnv *jniEnv, jobject surfac Q_UNUSED(jniEnv); Q_UNUSED(w); Q_UNUSED(h); + lockSurface(); m_androidSurfaceObject = surface; - m_surfaceWaitCondition.wakeOne(); + if (surface) // wait until we have a valid surface to draw into + m_surfaceWaitCondition.wakeOne(); unlockSurface(); - // repaint the window - QRect availableGeometry = screen()->availableGeometry(); - if (geometry().width() > 0 && geometry().height() > 0 && availableGeometry.width() > 0 && availableGeometry.height() > 0) - QWindowSystemInterface::handleExposeEvent(window(), QRegion(QRect(QPoint(), geometry().size()))); + if (surface) { + // repaint the window, when we have a valid surface + QRect availableGeometry = screen()->availableGeometry(); + if (geometry().width() > 0 && geometry().height() > 0 && availableGeometry.width() > 0 && availableGeometry.height() > 0) + QWindowSystemInterface::handleExposeEvent(window(), QRegion(QRect(QPoint(), geometry().size()))); + } } QT_END_NAMESPACE diff --git a/src/plugins/platforms/android/qandroidplatformopenglwindow.h b/src/plugins/platforms/android/qandroidplatformopenglwindow.h index 71787edee1..6d6548fc6a 100644 --- a/src/plugins/platforms/android/qandroidplatformopenglwindow.h +++ b/src/plugins/platforms/android/qandroidplatformopenglwindow.h @@ -54,7 +54,7 @@ public: EGLSurface eglSurface(EGLConfig config); QSurfaceFormat format() const; - void checkNativeSurface(EGLConfig config); + bool checkNativeSurface(EGLConfig config); void applicationStateChanged(Qt::ApplicationState); @@ -66,7 +66,7 @@ protected: void clearEgl(); private: - EGLDisplay m_eglDisplay; + EGLDisplay m_eglDisplay = EGL_NO_DISPLAY; EGLSurface m_eglSurface = EGL_NO_SURFACE; EGLNativeWindowType m_nativeWindow = nullptr; diff --git a/src/plugins/platforms/android/qandroidplatformscreen.cpp b/src/plugins/platforms/android/qandroidplatformscreen.cpp index 940add3a38..a4e82a29ef 100644 --- a/src/plugins/platforms/android/qandroidplatformscreen.cpp +++ b/src/plugins/platforms/android/qandroidplatformscreen.cpp @@ -391,7 +391,7 @@ Qt::ScreenOrientation QAndroidPlatformScreen::nativeOrientation() const void QAndroidPlatformScreen::surfaceChanged(JNIEnv *env, jobject surface, int w, int h) { lockSurface(); - if (surface && w && h) { + if (surface && w > 0 && h > 0) { releaseSurface(); m_nativeSurface = ANativeWindow_fromSurface(env, surface); QMetaObject::invokeMethod(this, "setDirty", Qt::QueuedConnection, Q_ARG(QRect, QRect(0, 0, w, h))); diff --git a/src/plugins/platforms/cocoa/qnsview.h b/src/plugins/platforms/cocoa/qnsview.h index ffa616f968..c36634db74 100644 --- a/src/plugins/platforms/cocoa/qnsview.h +++ b/src/plugins/platforms/cocoa/qnsview.h @@ -48,7 +48,7 @@ class QCocoaBackingStore; class QCocoaGLContext; QT_END_NAMESPACE -Q_FORWARD_DECLARE_OBJC_CLASS(QNSViewMouseMoveHelper); +Q_FORWARD_DECLARE_OBJC_CLASS(QT_MANGLE_NAMESPACE(QNSViewMouseMoveHelper)); @interface QT_MANGLE_NAMESPACE(QNSView) : NSView <NSTextInputClient> { QImage m_backingStore; @@ -72,7 +72,7 @@ Q_FORWARD_DECLARE_OBJC_CLASS(QNSViewMouseMoveHelper); bool m_shouldSetGLContextinDrawRect; #endif NSString *m_inputSource; - QNSViewMouseMoveHelper *m_mouseMoveHelper; + QT_MANGLE_NAMESPACE(QNSViewMouseMoveHelper) *m_mouseMoveHelper; bool m_resendKeyEvent; bool m_scrolling; } diff --git a/src/plugins/platforms/cocoa/qnsview.mm b/src/plugins/platforms/cocoa/qnsview.mm index 2f4dcd2a8c..9c24851115 100644 --- a/src/plugins/platforms/cocoa/qnsview.mm +++ b/src/plugins/platforms/cocoa/qnsview.mm @@ -83,7 +83,7 @@ static NSString *_q_NSWindowDidChangeOcclusionStateNotification = nil; - (CGFloat)deviceDeltaZ; @end -@interface QNSViewMouseMoveHelper : NSObject +@interface QT_MANGLE_NAMESPACE(QNSViewMouseMoveHelper) : NSObject { QNSView *view; } @@ -97,7 +97,7 @@ static NSString *_q_NSWindowDidChangeOcclusionStateNotification = nil; @end -@implementation QNSViewMouseMoveHelper +@implementation QT_MANGLE_NAMESPACE(QNSViewMouseMoveHelper) - (id)initWithView:(QNSView *)theView { @@ -158,7 +158,7 @@ static NSString *_q_NSWindowDidChangeOcclusionStateNotification = nil; currentCustomDragTypes = 0; m_sendUpAsRightButton = false; m_inputSource = 0; - m_mouseMoveHelper = [[QNSViewMouseMoveHelper alloc] initWithView:self]; + m_mouseMoveHelper = [[QT_MANGLE_NAMESPACE(QNSViewMouseMoveHelper) alloc] initWithView:self]; m_resendKeyEvent = false; m_scrolling = false; diff --git a/src/plugins/platforms/ios/qiosinputcontext.mm b/src/plugins/platforms/ios/qiosinputcontext.mm index 76c02d939f..6e56f47954 100644 --- a/src/plugins/platforms/ios/qiosinputcontext.mm +++ b/src/plugins/platforms/ios/qiosinputcontext.mm @@ -75,9 +75,7 @@ static QUIView *focusView() - (id)initWithQIOSInputContext:(QIOSInputContext *)context { - id originalSelf = self; if (self = [super initWithTarget:self action:@selector(gestureStateChanged:)]) { - Q_ASSERT(self == originalSelf); m_context = context; @@ -505,7 +503,22 @@ void QIOSInputContext::scroll(int y) [rootView.layer addAnimation:animation forKey:@"AnimateSubLayerTransform"]; rootView.layer.sublayerTransform = translationTransform; - [rootView.qtViewController updateProperties]; + bool keyboardScrollIsActive = y != 0; + + // Raise all known windows to above the status-bar if we're scrolling the screen, + // while keeping the relative window level between the windows the same. + NSArray *applicationWindows = [[UIApplication sharedApplication] windows]; + static QHash<UIWindow *, UIWindowLevel> originalWindowLevels; + for (UIWindow *window in applicationWindows) { + if (keyboardScrollIsActive && !originalWindowLevels.contains(window)) + originalWindowLevels.insert(window, window.windowLevel); + + UIWindowLevel windowLevelAdjustment = keyboardScrollIsActive ? UIWindowLevelStatusBar : 0; + window.windowLevel = originalWindowLevels.value(window) + windowLevelAdjustment; + + if (!keyboardScrollIsActive) + originalWindowLevels.remove(window); + } } completion:^(BOOL){ if (self) { diff --git a/src/plugins/platforms/ios/qiosscreen.mm b/src/plugins/platforms/ios/qiosscreen.mm index 4af2a4965f..712bf0098b 100644 --- a/src/plugins/platforms/ios/qiosscreen.mm +++ b/src/plugins/platforms/ios/qiosscreen.mm @@ -46,6 +46,7 @@ #include <qpa/qwindowsysteminterface.h> #include "qiosapplicationdelegate.h" #include "qiosviewcontroller.h" +#include "quiview.h" #include <sys/sysctl.h> @@ -244,6 +245,22 @@ void QIOSScreen::updateProperties() m_geometry = fromCGRect([rootView convertRect:m_uiScreen.bounds fromView:m_uiWindow]).toRect(); m_availableGeometry = fromCGRect([rootView convertRect:m_uiScreen.applicationFrame fromView:m_uiWindow]).toRect(); + if (QSysInfo::MacintoshVersion >= QSysInfo::MV_IOS_8_0 && ![m_uiWindow.rootViewController shouldAutorotate]) { + // Setting the statusbar orientation (content orientation) on iOS8+ will result in the UIScreen + // updating its geometry and available geometry, which in the case of content orientation is not + // what we want. We want to reflect the screen geometry based on the locked orientation, and + // adjust the available geometry based on the repositioned status bar for the current status + // bar orientation. + + Qt::ScreenOrientation lockedOrientation = toQtScreenOrientation(UIDeviceOrientation(rootView.qtViewController.lockedOrientation)); + Qt::ScreenOrientation contenOrientation = toQtScreenOrientation(UIDeviceOrientation([UIApplication sharedApplication].statusBarOrientation)); + + QTransform transform = screen()->transformBetween(lockedOrientation, contenOrientation, m_geometry).inverted(); + + m_geometry = transform.mapRect(m_geometry); + m_availableGeometry = transform.mapRect(m_availableGeometry); + } + if (m_geometry != previousGeometry || m_availableGeometry != previousAvailableGeometry) { const qreal millimetersPerInch = 25.4; m_physicalSize = QSizeF(m_geometry.size()) / m_unscaledDpi * millimetersPerInch; diff --git a/src/plugins/platforms/ios/qiostextresponder.h b/src/plugins/platforms/ios/qiostextresponder.h index 118ab8958a..21b61bf8da 100644 --- a/src/plugins/platforms/ios/qiostextresponder.h +++ b/src/plugins/platforms/ios/qiostextresponder.h @@ -51,6 +51,7 @@ class QIOSInputContext; QIOSInputContext *m_inputContext; QString m_markedText; BOOL m_inSendEventToFocusObject; + BOOL m_inSelectionChange; } - (id)initWithInputContext:(QIOSInputContext *)context; diff --git a/src/plugins/platforms/ios/qiostextresponder.mm b/src/plugins/platforms/ios/qiostextresponder.mm index bebc7577f8..15fade0838 100644 --- a/src/plugins/platforms/ios/qiostextresponder.mm +++ b/src/plugins/platforms/ios/qiostextresponder.mm @@ -171,6 +171,7 @@ return self; m_inSendEventToFocusObject = NO; + m_inSelectionChange = NO; m_inputContext = inputContext; QVariantMap platformData = [self imValue:Qt::ImPlatformData].toMap(); @@ -302,6 +303,7 @@ return; if (updatedProperties & (Qt::ImCursorPosition | Qt::ImAnchorPosition)) { + QScopedValueRollback<BOOL> rollback(m_inSelectionChange, true); [self.inputDelegate selectionWillChange:self]; [self.inputDelegate selectionDidChange:self]; } @@ -349,6 +351,15 @@ - (void)setSelectedTextRange:(UITextRange *)range { + if (m_inSelectionChange) { + // After [UITextInputDelegate selectionWillChange], UIKit will cancel + // any ongoing auto correction (if enabled) and ask us to set an empty selection. + // This is contradictory to our current attempt to set a selection, so we ignore + // the callback. UIKit will be re-notified of the new selection after + // [UITextInputDelegate selectionDidChange]. + return; + } + QUITextRange *r = static_cast<QUITextRange *>(range); QList<QInputMethodEvent::Attribute> attrs; attrs << QInputMethodEvent::Attribute(QInputMethodEvent::Selection, r.range.location, r.range.length, 0); diff --git a/src/plugins/platforms/ios/qiosviewcontroller.h b/src/plugins/platforms/ios/qiosviewcontroller.h index 586edd589d..df7ce0ff4a 100644 --- a/src/plugins/platforms/ios/qiosviewcontroller.h +++ b/src/plugins/platforms/ios/qiosviewcontroller.h @@ -35,15 +35,17 @@ class QIOSScreen; -@interface QIOSViewController : UIViewController { - QIOSScreen *m_screen; -} +@interface QIOSViewController : UIViewController -@property (nonatomic, assign) BOOL changingOrientation; +- (id)initWithQIOSScreen:(QIOSScreen *)screen; +- (void)updateProperties; + +@property (nonatomic, assign) UIInterfaceOrientation lockedOrientation; + +// UIViewController +@property (nonatomic, assign) BOOL shouldAutorotate; @property (nonatomic, assign) BOOL prefersStatusBarHidden; @property (nonatomic, assign) UIStatusBarAnimation preferredStatusBarUpdateAnimation; -- (id)initWithQIOSScreen:(QIOSScreen *)screen; -- (void)updateProperties; @end diff --git a/src/plugins/platforms/ios/qiosviewcontroller.mm b/src/plugins/platforms/ios/qiosviewcontroller.mm index a2d81e3b6c..01bc84ae68 100644 --- a/src/plugins/platforms/ios/qiosviewcontroller.mm +++ b/src/plugins/platforms/ios/qiosviewcontroller.mm @@ -41,6 +41,8 @@ #import "qiosviewcontroller.h" +#include <QtCore/qscopedvaluerollback.h> + #include <QtGui/QGuiApplication> #include <QtGui/QWindow> #include <QtGui/QScreen> @@ -119,6 +121,13 @@ // ------------------------------------------------------------------------- +@interface QIOSViewController () { + QIOSScreen *m_screen; + BOOL m_updatingProperties; +} +@property (nonatomic, assign) BOOL changingOrientation; +@end + @implementation QIOSViewController - (id)initWithQIOSScreen:(QIOSScreen *)screen @@ -147,6 +156,7 @@ #endif self.changingOrientation = NO; + self.shouldAutorotate = [super shouldAutorotate]; // Status bar may be initially hidden at startup through Info.plist self.prefersStatusBarHidden = infoPlistValue(@"UIStatusBarHidden", false); @@ -173,6 +183,10 @@ [center addObserver:self selector:@selector(willChangeStatusBarFrame:) name:UIApplicationWillChangeStatusBarFrameNotification object:[UIApplication sharedApplication]]; + + [center addObserver:self selector:@selector(didChangeStatusBarOrientation:) + name:UIApplicationDidChangeStatusBarOrientationNotification + object:[UIApplication sharedApplication]]; } - (void)viewDidUnload @@ -183,19 +197,16 @@ // ------------------------------------------------------------------------- --(BOOL)shouldAutorotate -{ - // Until a proper orientation and rotation API is in place, we always auto rotate. - // If auto rotation is not wanted, you would need to switch it off manually from Info.plist. - return YES; -} - #if QT_IOS_PLATFORM_SDK_EQUAL_OR_ABOVE(__IPHONE_6_0) -(NSUInteger)supportedInterfaceOrientations { - // We need to tell iOS that we support all orientations in order to set - // status bar orientation when application content orientation changes. - return UIInterfaceOrientationMaskAll; + // As documented by Apple in the iOS 6.0 release notes, setStatusBarOrientation:animated: + // only works if the supportedInterfaceOrientations of the view controller is 0, making + // us responsible for ensuring that the status bar orientation is consistent. We enter + // this mode when auto-rotation is disabled due to an explicit content orientation being + // set on the focus window. Note that this is counter to what the documentation for + // supportedInterfaceOrientations says, which states that the method should not return 0. + return [self shouldAutorotate] ? UIInterfaceOrientationMaskAll : 0; } #endif @@ -203,7 +214,7 @@ -(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { Q_UNUSED(interfaceOrientation); - return YES; + return [self shouldAutorotate]; } #endif @@ -250,6 +261,22 @@ }]; } +- (void)didChangeStatusBarOrientation:(NSNotification *)notification +{ + Q_UNUSED(notification); + + if (self.view.window.screen != [UIScreen mainScreen]) + return; + + // If the statusbar changes orientation due to auto-rotation we don't care, + // there will be re-layout anyways. Only if the statusbar changes due to + // reportContentOrientation, we need to update the window layout. + if (self.changingOrientation) + return; + + [self.view setNeedsLayout]; +} + - (void)viewWillLayoutSubviews { if (!QCoreApplication::instance()) @@ -265,6 +292,15 @@ if (!isQtApplication()) return; + // Prevent recursion caused by updating the status bar appearance (position + // or visibility), which in turn may cause a layout of our subviews, and + // a reset of window-states, which themselves affect the view controller + // properties such as the statusbar visibilty. + if (m_updatingProperties) + return; + + QScopedValueRollback<BOOL> updateRollback(m_updatingProperties, YES); + QWindow *focusWindow = QGuiApplication::focusWindow(); // If we don't have a focus window we leave the statusbar @@ -281,14 +317,10 @@ // All decisions are based on the the top level window focusWindow = qt_window_private(focusWindow)->topLevelWindow(); - bool hasScrolledRootViewDueToVirtualKeyboard = - !CATransform3DIsIdentity(self.view.layer.sublayerTransform); + UIApplication *uiApplication = [UIApplication sharedApplication]; bool currentStatusBarVisibility = self.prefersStatusBarHidden; - self.prefersStatusBarHidden = focusWindow->windowState() == Qt::WindowFullScreen - || hasScrolledRootViewDueToVirtualKeyboard; - self.preferredStatusBarUpdateAnimation = hasScrolledRootViewDueToVirtualKeyboard ? - UIStatusBarAnimationFade : UIStatusBarAnimationNone; + self.prefersStatusBarHidden = focusWindow->windowState() == Qt::WindowFullScreen; if (self.prefersStatusBarHidden != currentStatusBarVisibility) { #if QT_IOS_PLATFORM_SDK_EQUAL_OR_ABOVE(__IPHONE_7_0) @@ -297,13 +329,60 @@ } else #endif { - [[UIApplication sharedApplication] - setStatusBarHidden:self.prefersStatusBarHidden + [uiApplication setStatusBarHidden:self.prefersStatusBarHidden withAnimation:self.preferredStatusBarUpdateAnimation]; } [self.view setNeedsLayout]; } + + + // -------------- Content orientation --------------- + + static BOOL kAnimateContentOrientationChanges = YES; + + Qt::ScreenOrientation contentOrientation = focusWindow->contentOrientation(); + if (contentOrientation != Qt::PrimaryOrientation) { + // An explicit content orientation has been reported for the focus window, + // so we keep the status bar in sync with content orientation. This will ensure + // that the task bar (and associated gestures) are also rotated accordingly. + + if (self.shouldAutorotate) { + // We are moving from Qt::PrimaryOrientation to an explicit orientation, + // so we need to store the current statusbar orientation, as we need it + // later when mapping screen coordinates for QScreen and for returning + // to Qt::PrimaryOrientation. + self.lockedOrientation = uiApplication.statusBarOrientation; + + // Calling setStatusBarOrientation only has an effect when auto-rotation is + // disabled, which makes sense when there's an explicit content orientation. + self.shouldAutorotate = NO; + } + + [uiApplication setStatusBarOrientation: + UIInterfaceOrientation(fromQtScreenOrientation(contentOrientation)) + animated:kAnimateContentOrientationChanges]; + + } else { + // The content orientation is set to Qt::PrimaryOrientation, meaning + // that auto-rotation should be enabled. But we may be coming out of + // a state of locked orientation, which needs some cleanup before we + // can enable auto-rotation again. + if (!self.shouldAutorotate) { + // First we need to restore the statusbar to what it was at the + // time of locking the orientation, otherwise iOS will be very + // confused when it starts doing auto-rotation again. + [uiApplication setStatusBarOrientation: + UIInterfaceOrientation(self.lockedOrientation) + animated:kAnimateContentOrientationChanges]; + + // Then we can re-enable auto-rotation + self.shouldAutorotate = YES; + + // And finally let iOS rotate the root view to match the device orientation + [UIViewController attemptRotationToDeviceOrientation]; + } + } } #if QT_IOS_PLATFORM_SDK_EQUAL_OR_ABOVE(__IPHONE_7_0) diff --git a/src/plugins/platforms/ios/qioswindow.mm b/src/plugins/platforms/ios/qioswindow.mm index 480062e4de..6c4614408d 100644 --- a/src/plugins/platforms/ios/qioswindow.mm +++ b/src/plugins/platforms/ios/qioswindow.mm @@ -75,6 +75,15 @@ QIOSWindow::QIOSWindow(QWindow *window) setWindowState(window->windowState()); setOpacity(window->opacity()); + + Qt::ScreenOrientation initialOrientation = window->contentOrientation(); + if (initialOrientation != Qt::PrimaryOrientation) { + // Start up in portrait, then apply possible content orientation, + // as per Apple's documentation. + dispatch_async(dispatch_get_main_queue(), ^{ + handleContentOrientationChange(initialOrientation); + }); + } } QIOSWindow::~QIOSWindow() @@ -322,10 +331,12 @@ void QIOSWindow::updateWindowLevel() void QIOSWindow::handleContentOrientationChange(Qt::ScreenOrientation orientation) { - // Keep the status bar in sync with content orientation. This will ensure - // that the task bar (and associated gestures) are aligned correctly: - UIInterfaceOrientation uiOrientation = UIInterfaceOrientation(fromQtScreenOrientation(orientation)); - [[UIApplication sharedApplication] setStatusBarOrientation:uiOrientation animated:NO]; + // Update the QWindow representation straight away, so that + // we can update the statusbar orientation based on the new + // content orientation. + qt_window_private(window())->contentOrientation = orientation; + + [m_view.qtViewController updateProperties]; } void QIOSWindow::applicationStateChanged(Qt::ApplicationState) diff --git a/src/plugins/platforms/windows/qwindowscursor.cpp b/src/plugins/platforms/windows/qwindowscursor.cpp index d10c7fdb20..9a42b7712d 100644 --- a/src/plugins/platforms/windows/qwindowscursor.cpp +++ b/src/plugins/platforms/windows/qwindowscursor.cpp @@ -126,13 +126,15 @@ HCURSOR QWindowsCursor::createPixmapCursor(const QPixmap &pixmap, const QPoint & // Create a cursor from image and mask of the format QImage::Format_Mono. static HCURSOR createBitmapCursor(const QImage &bbits, const QImage &mbits, - QPoint hotSpot = QPoint(), + QPoint hotSpot = QPoint(-1, -1), bool invb = false, bool invm = false) { const int width = bbits.width(); const int height = bbits.height(); - if (hotSpot.isNull()) - hotSpot = QPoint(width / 2, height / 2); + if (hotSpot.x() < 0) + hotSpot.setX(width / 2); + if (hotSpot.y() < 0) + hotSpot.setY(height / 2); const int n = qMax(1, width / 8); #if !defined(Q_OS_WINCE) QScopedArrayPointer<uchar> xBits(new uchar[height * n]); diff --git a/src/plugins/platforms/windows/qwindowsdrag.cpp b/src/plugins/platforms/windows/qwindowsdrag.cpp index fce60c3169..d3eb049269 100644 --- a/src/plugins/platforms/windows/qwindowsdrag.cpp +++ b/src/plugins/platforms/windows/qwindowsdrag.cpp @@ -626,7 +626,7 @@ QWindowsOleDropTarget::Drop(LPDATAOBJECT pDataObj, DWORD grfKeyState, const QPlatformDropQtResponse response = QWindowSystemInterface::handleDrop(m_window, windowsDrag->dropData(), m_lastPoint / QWindowsScaling::factor(), - translateToQDragDropActions(*pdwEffect)); + translateToQDragDropActions(m_chosenEffect)); if (response.isAccepted()) { const Qt::DropAction action = response.acceptedAction(); diff --git a/src/plugins/platforms/windows/qwindowsfontenginedirectwrite.cpp b/src/plugins/platforms/windows/qwindowsfontenginedirectwrite.cpp index f8747a741e..5c241b1fc8 100644 --- a/src/plugins/platforms/windows/qwindowsfontenginedirectwrite.cpp +++ b/src/plugins/platforms/windows/qwindowsfontenginedirectwrite.cpp @@ -511,8 +511,9 @@ QImage QWindowsFontEngineDirectWrite::imageForGlyph(glyph_t t, const QTransform &xform) { glyph_metrics_t metrics = QFontEngine::boundingBox(t, xform); - int width = (metrics.width + margin * 2 + 4).ceil().toInt() ; - int height = (metrics.height + margin * 2 + 4).ceil().toInt(); + // This needs to be kept in sync with alphaMapBoundingBox + int width = (metrics.width + margin * 2).ceil().toInt() ; + int height = (metrics.height + margin * 2).ceil().toInt(); UINT16 glyphIndex = t; FLOAT glyphAdvance = metrics.xoff.toReal(); @@ -695,6 +696,18 @@ QString QWindowsFontEngineDirectWrite::fontNameSubstitute(const QString &familyN return QSettings(QLatin1String(keyC), QSettings::NativeFormat).value(familyName, familyName).toString(); } +glyph_metrics_t QWindowsFontEngineDirectWrite::alphaMapBoundingBox(glyph_t glyph, QFixed pos, const QTransform &matrix, GlyphFormat format) +{ + Q_UNUSED(pos); + int margin = 0; + if (format == QFontEngine::Format_A32 || format == QFontEngine::Format_ARGB) + margin = glyphMargin(QFontEngine::Format_A32); + glyph_metrics_t gm = QFontEngine::boundingBox(glyph, matrix); + gm.width += margin * 2; + gm.height += margin * 2; + return gm; +} + QT_END_NAMESPACE #endif // QT_NO_DIRECTWRITE diff --git a/src/plugins/platforms/windows/qwindowsfontenginedirectwrite.h b/src/plugins/platforms/windows/qwindowsfontenginedirectwrite.h index 2addb90de3..e0466c138d 100644 --- a/src/plugins/platforms/windows/qwindowsfontenginedirectwrite.h +++ b/src/plugins/platforms/windows/qwindowsfontenginedirectwrite.h @@ -75,6 +75,7 @@ public: glyph_metrics_t boundingBox(const QGlyphLayout &glyphs); glyph_metrics_t boundingBox(glyph_t g); + glyph_metrics_t alphaMapBoundingBox(glyph_t glyph, QFixed, const QTransform &matrix, GlyphFormat); QFixed ascent() const; QFixed descent() const; diff --git a/src/plugins/platforms/windows/qwindowswindow.cpp b/src/plugins/platforms/windows/qwindowswindow.cpp index b7de580c44..5d94ec3c38 100644 --- a/src/plugins/platforms/windows/qwindowswindow.cpp +++ b/src/plugins/platforms/windows/qwindowswindow.cpp @@ -1298,21 +1298,7 @@ void QWindowsWindow::setGeometryDp(const QRect &rectIn) const QMargins margins = frameMarginsDp(); rect.moveTopLeft(rect.topLeft() + QPoint(margins.left(), margins.top())); } - const QSize oldSize = m_data.geometry.size(); m_data.geometry = rect; - const QSize newSize = rect.size(); - // Check on hint. - if (newSize != oldSize) { - const QWindowsGeometryHint hint(window(), m_data.customMargins); - if (!hint.validSize(newSize)) { - qWarning("%s: Attempt to set a size (%dx%d) violating the constraints" - "(%dx%d - %dx%d) on window %s/'%s'.", __FUNCTION__, - newSize.width(), newSize.height(), - hint.minimumSize.width(), hint.minimumSize.height(), - hint.maximumSize.width(), hint.maximumSize.height(), - window()->metaObject()->className(), qPrintable(window()->objectName())); - } - } if (m_data.hwnd) { // A ResizeEvent with resulting geometry will be sent. If we cannot // achieve that size (for example, window title minimal constraint), @@ -1625,17 +1611,6 @@ void QWindowsWindow::setWindowState_sys(Qt::WindowState newState) setFlag(FrameDirty); - if ((oldState == Qt::WindowMaximized) != (newState == Qt::WindowMaximized)) { - if (visible && !(newState == Qt::WindowMinimized)) { - setFlag(WithinMaximize); - if (newState == Qt::WindowFullScreen) - setFlag(MaximizeToFullScreen); - ShowWindow(m_data.hwnd, (newState == Qt::WindowMaximized) ? SW_MAXIMIZE : SW_SHOWNOACTIVATE); - clearFlag(WithinMaximize); - clearFlag(MaximizeToFullScreen); - } - } - if ((oldState == Qt::WindowFullScreen) != (newState == Qt::WindowFullScreen)) { #ifdef Q_OS_WINCE HWND handle = FindWindow(L"HHTaskBar", L""); @@ -1715,6 +1690,15 @@ void QWindowsWindow::setWindowState_sys(Qt::WindowState newState) m_savedStyle = 0; m_savedFrameGeometry = QRect(); } + } else if ((oldState == Qt::WindowMaximized) != (newState == Qt::WindowMaximized)) { + if (visible && !(newState == Qt::WindowMinimized)) { + setFlag(WithinMaximize); + if (newState == Qt::WindowFullScreen) + setFlag(MaximizeToFullScreen); + ShowWindow(m_data.hwnd, (newState == Qt::WindowMaximized) ? SW_MAXIMIZE : SW_SHOWNOACTIVATE); + clearFlag(WithinMaximize); + clearFlag(MaximizeToFullScreen); + } } if ((oldState == Qt::WindowMinimized) != (newState == Qt::WindowMinimized)) { @@ -1761,6 +1745,8 @@ void QWindowsWindow::windowEvent(QEvent *event) case QEvent::WindowBlocked: // Blocked by another modal window. setEnabled(false); setFlag(BlockedByModal); + if (hasMouseCapture()) + ReleaseCapture(); break; case QEvent::WindowUnblocked: setEnabled(true); diff --git a/src/plugins/platforms/xcb/qxcbbackingstore.cpp b/src/plugins/platforms/xcb/qxcbbackingstore.cpp index 74d73d7cdf..bbde948090 100644 --- a/src/plugins/platforms/xcb/qxcbbackingstore.cpp +++ b/src/plugins/platforms/xcb/qxcbbackingstore.cpp @@ -181,8 +181,6 @@ void QXcbShmImage::destroy() if (segmentSize && m_shm_info.shmaddr) Q_XCB_CALL(xcb_shm_detach(xcb_connection(), m_shm_info.shmseg)); - xcb_image_destroy(m_xcb_image); - if (segmentSize) { if (m_shm_info.shmaddr) { shmdt(m_shm_info.shmaddr); @@ -192,6 +190,8 @@ void QXcbShmImage::destroy() } } + xcb_image_destroy(m_xcb_image); + if (m_gc) Q_XCB_CALL(xcb_free_gc(xcb_connection(), m_gc)); delete m_graphics_buffer; diff --git a/src/plugins/platforms/xcb/qxcbnativeinterface.cpp b/src/plugins/platforms/xcb/qxcbnativeinterface.cpp index 956b0f83d2..05035a5b1e 100644 --- a/src/plugins/platforms/xcb/qxcbnativeinterface.cpp +++ b/src/plugins/platforms/xcb/qxcbnativeinterface.cpp @@ -71,7 +71,8 @@ static int resourceType(const QByteArray &key) QByteArrayLiteral("startupid"), QByteArrayLiteral("traywindow"), QByteArrayLiteral("gettimestamp"), QByteArrayLiteral("x11screen"), QByteArrayLiteral("rootwindow"), - QByteArrayLiteral("subpixeltype"), QByteArrayLiteral("antialiasingEnabled") + QByteArrayLiteral("subpixeltype"), QByteArrayLiteral("antialiasingEnabled"), + QByteArrayLiteral("nofonthinting") }; const QByteArray *end = names + sizeof(names) / sizeof(names[0]); const QByteArray *result = std::find(names, end, key); @@ -281,6 +282,9 @@ void *QXcbNativeInterface::nativeResourceForScreen(const QByteArray &resourceStr case GetTimestamp: result = getTimestamp(xcbScreen); break; + case NoFontHinting: + result = xcbScreen->noFontHinting() ? this : 0; //qboolptr... + break; default: break; } diff --git a/src/plugins/platforms/xcb/qxcbnativeinterface.h b/src/plugins/platforms/xcb/qxcbnativeinterface.h index b2044e6ee9..1db2d1cf83 100644 --- a/src/plugins/platforms/xcb/qxcbnativeinterface.h +++ b/src/plugins/platforms/xcb/qxcbnativeinterface.h @@ -65,7 +65,8 @@ public: X11Screen, RootWindow, ScreenSubpixelType, - ScreenAntialiasingEnabled + ScreenAntialiasingEnabled, + NoFontHinting }; QXcbNativeInterface(); diff --git a/src/plugins/platforms/xcb/qxcbscreen.cpp b/src/plugins/platforms/xcb/qxcbscreen.cpp index def6e2ce9a..0f25d10aac 100644 --- a/src/plugins/platforms/xcb/qxcbscreen.cpp +++ b/src/plugins/platforms/xcb/qxcbscreen.cpp @@ -53,7 +53,7 @@ QXcbScreen::QXcbScreen(QXcbConnection *connection, xcb_screen_t *scr, , m_screen(scr) , m_crtc(output ? output->crtc : 0) , m_outputName(outputName) - , m_sizeMillimeters(output ? QSize(output->mm_width, output->mm_height) : QSize()) + , m_outputSizeMillimeters(output ? QSize(output->mm_width, output->mm_height) : QSize()) , m_virtualSize(scr->width_in_pixels, scr->height_in_pixels) , m_virtualSizeMillimeters(scr->width_in_millimeters, scr->height_in_millimeters) , m_orientation(Qt::PrimaryOrientation) @@ -62,6 +62,7 @@ QXcbScreen::QXcbScreen(QXcbConnection *connection, xcb_screen_t *scr, , m_forcedDpi(-1) , m_devicePixelRatio(1) , m_hintStyle(QFontEngine::HintStyle(-1)) + , m_noFontHinting(false) , m_subpixelType(QFontEngine::SubpixelAntialiasingType(-1)) , m_antialiasingEnabled(-1) , m_xSettings(0) @@ -71,18 +72,27 @@ QXcbScreen::QXcbScreen(QXcbConnection *connection, xcb_screen_t *scr, updateGeometry(output ? output->timestamp : 0); updateRefreshRate(); + const int dpr = int(devicePixelRatio()); // On VNC, it can be that physical size is unknown while // virtual size is known (probably back-calculated from DPI and resolution) if (m_sizeMillimeters.isEmpty()) m_sizeMillimeters = m_virtualSizeMillimeters; - if (m_geometry.isEmpty()) + if (m_geometry.isEmpty()) { m_geometry = QRect(QPoint(), m_virtualSize/dpr); + m_nativeGeometry = QRect(QPoint(), m_virtualSize); + } if (m_availableGeometry.isEmpty()) m_availableGeometry = m_geometry; readXResources(); + // disable font hinting when we do UI scaling + static bool dpr_scaling_enabled = (qgetenv("QT_DEVICE_PIXEL_RATIO").toInt() > 1 + || qgetenv("QT_DEVICE_PIXEL_RATIO").toLower() == "auto"); + if (dpr_scaling_enabled) + m_noFontHinting = true; + #ifdef Q_XCB_DEBUG qDebug(); qDebug("Screen output %s of xcb screen %d:", m_outputName.toUtf8().constData(), m_number); @@ -93,6 +103,7 @@ QXcbScreen::QXcbScreen(QXcbConnection *connection, xcb_screen_t *scr, qDebug(" virtual height.: %lf", m_virtualSizeMillimeters.height()); qDebug(" virtual geom...: %d x %d", m_virtualSize.width(), m_virtualSize.height()); qDebug(" avail virt geom: %d x %d +%d +%d", m_availableGeometry.width(), m_availableGeometry.height(), m_availableGeometry.x(), m_availableGeometry.y()); + qDebug(" orientation....: %d", m_orientation); qDebug(" pixel ratio....: %d", m_devicePixelRatio); qDebug(" depth..........: %d", screen()->root_depth); qDebug(" white pixel....: %x", screen()->white_pixel); @@ -313,8 +324,14 @@ QDpi QXcbScreen::logicalDpi() const if (m_forcedDpi > 0) return QDpi(m_forcedDpi/dpr, m_forcedDpi/dpr); - return QDpi(Q_MM_PER_INCH * m_virtualSize.width() / m_virtualSizeMillimeters.width() / dpr, - Q_MM_PER_INCH * m_virtualSize.height() / m_virtualSizeMillimeters.height() / dpr); + static const bool auto_dpr = qgetenv("QT_DEVICE_PIXEL_RATIO").toLower() == "auto"; + if (auto_dpr) { + return QDpi(Q_MM_PER_INCH * m_geometry.width() / m_sizeMillimeters.width(), + Q_MM_PER_INCH * m_geometry.height() / m_sizeMillimeters.height()); + } else { + return QDpi(Q_MM_PER_INCH * m_virtualSize.width() / m_virtualSizeMillimeters.width() / dpr, + Q_MM_PER_INCH * m_virtualSize.height() / m_virtualSizeMillimeters.height() / dpr); + } } @@ -413,6 +430,24 @@ void QXcbScreen::updateGeometry(xcb_timestamp_t timestamp) if (crtc) { xGeometry = QRect(crtc->x, crtc->y, crtc->width, crtc->height); xAvailableGeometry = xGeometry; + switch (crtc->rotation) { + case XCB_RANDR_ROTATION_ROTATE_0: // xrandr --rotate normal + m_orientation = Qt::LandscapeOrientation; + m_sizeMillimeters = m_outputSizeMillimeters; + break; + case XCB_RANDR_ROTATION_ROTATE_90: // xrandr --rotate left + m_orientation = Qt::PortraitOrientation; + m_sizeMillimeters = m_outputSizeMillimeters.transposed(); + break; + case XCB_RANDR_ROTATION_ROTATE_180: // xrandr --rotate inverted + m_orientation = Qt::InvertedLandscapeOrientation; + m_sizeMillimeters = m_outputSizeMillimeters; + break; + case XCB_RANDR_ROTATION_ROTATE_270: // xrandr --rotate right + m_orientation = Qt::InvertedPortraitOrientation; + m_sizeMillimeters = m_outputSizeMillimeters.transposed(); + break; + } free(crtc); } } @@ -441,6 +476,7 @@ void QXcbScreen::updateGeometry(xcb_timestamp_t timestamp) m_devicePixelRatio = qRound(dpi/96); const int dpr = int(devicePixelRatio()); // we may override m_devicePixelRatio m_geometry = QRect(xGeometry.topLeft()/dpr, xGeometry.size()/dpr); + m_nativeGeometry = QRect(xGeometry.topLeft(), xGeometry.size()); m_availableGeometry = QRect(xAvailableGeometry.topLeft()/dpr, xAvailableGeometry.size()/dpr); QWindowSystemInterface::handleScreenGeometryChange(QPlatformScreen::screen(), m_geometry, m_availableGeometry); diff --git a/src/plugins/platforms/xcb/qxcbscreen.h b/src/plugins/platforms/xcb/qxcbscreen.h index 4d0ae9847a..652d64c105 100644 --- a/src/plugins/platforms/xcb/qxcbscreen.h +++ b/src/plugins/platforms/xcb/qxcbscreen.h @@ -63,6 +63,7 @@ public: QWindow *topLevelAt(const QPoint &point) const Q_DECL_OVERRIDE; QRect geometry() const Q_DECL_OVERRIDE { return m_geometry; } + QRect nativeGeometry() const { return m_nativeGeometry; } QRect availableGeometry() const Q_DECL_OVERRIDE {return m_availableGeometry;} int depth() const Q_DECL_OVERRIDE { return m_screen->root_depth; } QImage::Format format() const Q_DECL_OVERRIDE; @@ -98,6 +99,7 @@ public: void readXResources(); QFontEngine::HintStyle hintStyle() const { return m_hintStyle; } + bool noFontHinting() const { return m_noFontHinting; } QFontEngine::SubpixelAntialiasingType subpixelType() const { return m_subpixelType; } int antialiasingEnabled() const { return m_antialiasingEnabled; } @@ -112,8 +114,10 @@ private: xcb_screen_t *m_screen; xcb_randr_crtc_t m_crtc; QString m_outputName; + QSizeF m_outputSizeMillimeters; QSizeF m_sizeMillimeters; QRect m_geometry; + QRect m_nativeGeometry; QRect m_availableGeometry; QSize m_virtualSize; QSizeF m_virtualSizeMillimeters; @@ -130,6 +134,7 @@ private: int m_forcedDpi; int m_devicePixelRatio; QFontEngine::HintStyle m_hintStyle; + bool m_noFontHinting; QFontEngine::SubpixelAntialiasingType m_subpixelType; int m_antialiasingEnabled; QXcbXSettings *m_xSettings; diff --git a/src/plugins/platforms/xcb/qxcbwindow.cpp b/src/plugins/platforms/xcb/qxcbwindow.cpp index 4d14dd14a3..4676133777 100644 --- a/src/plugins/platforms/xcb/qxcbwindow.cpp +++ b/src/plugins/platforms/xcb/qxcbwindow.cpp @@ -142,7 +142,7 @@ static inline QRect mapToNative(const QRect &qtRect, int dpr) return QRect(qtRect.x() * dpr, qtRect.y() * dpr, qtRect.width() * dpr, qtRect.height() * dpr); } -// When converting native rects to Qt rects: round top/left towards the origin and +// When mapping expose events to Qt rects: round top/left towards the origin and // bottom/right away from the origin, making sure that we cover the whole widget static inline QPoint dpr_floor(const QPoint &p, int dpr) @@ -155,11 +155,15 @@ static inline QPoint dpr_ceil(const QPoint &p, int dpr) return QPoint((p.x() + dpr - 1) / dpr, (p.y() + dpr - 1) / dpr); } -static inline QRect mapFromNative(const QRect &xRect, int dpr) +static inline QRect mapExposeFromNative(const QRect &xRect, int dpr) { return QRect(dpr_floor(xRect.topLeft(), dpr), dpr_ceil(xRect.bottomRight(), dpr)); } +static inline QRect mapGeometryFromNative(const QRect &xRect, int dpr) +{ + return QRect(xRect.topLeft() / dpr, xRect.bottomRight() / dpr); +} // Returns \c true if we should set WM_TRANSIENT_FOR on \a w static inline bool isTransient(const QWindow *w) @@ -1670,7 +1674,7 @@ public: return false; if (expose->count == 0) m_pending = false; - *m_region |= mapFromNative(QRect(expose->x, expose->y, expose->width, expose->height), m_dpr); + *m_region |= mapExposeFromNative(QRect(expose->x, expose->y, expose->width, expose->height), m_dpr); return true; } @@ -1698,7 +1702,7 @@ void QXcbWindow::handleExposeEvent(const xcb_expose_event_t *event) { const int dpr = int(devicePixelRatio()); QRect x_rect(event->x, event->y, event->width, event->height); - QRect rect = mapFromNative(x_rect, dpr); + QRect rect = mapExposeFromNative(x_rect, dpr); if (m_exposeRegion.isEmpty()) m_exposeRegion = rect; @@ -1783,6 +1787,23 @@ void QXcbWindow::handleClientMessageEvent(const xcb_client_message_event_t *even } } +// Temporary workaround for bug in QPlatformScreen::screenForNativeGeometry +// we need the native geometries to detect our screen, but that's not +// available in cross-platform code. Will be fixed properly when highDPI +// support is refactored to expose the native coordinate system. + +QPlatformScreen *QXcbWindow::screenForNativeGeometry(const QRect &newGeometry) const +{ + QXcbScreen *currentScreen = static_cast<QXcbScreen*>(screen()); + if (!parent() && !currentScreen->nativeGeometry().intersects(newGeometry)) { + Q_FOREACH (QPlatformScreen* screen, currentScreen->virtualSiblings()) { + if (static_cast<QXcbScreen*>(screen)->nativeGeometry().intersects(newGeometry)) + return screen; + } + } + return currentScreen; +} + void QXcbWindow::handleConfigureNotifyEvent(const xcb_configure_notify_event_t *event) { bool fromSendEvent = (event->response_type & 0x80); @@ -1799,15 +1820,23 @@ void QXcbWindow::handleConfigureNotifyEvent(const xcb_configure_notify_event_t * } } - QRect rect = mapFromNative(QRect(pos, QSize(event->width, event->height)), int(devicePixelRatio())); + const int dpr = devicePixelRatio(); + const QRect nativeRect = QRect(pos, QSize(event->width, event->height)); + const QRect rect = mapGeometryFromNative(nativeRect, dpr); QPlatformWindow::setGeometry(rect); QWindowSystemInterface::handleGeometryChange(window(), rect); - QPlatformScreen *newScreen = screenForGeometry(rect); + QPlatformScreen *newScreen = screenForNativeGeometry(nativeRect); if (newScreen != m_screen) { m_screen = static_cast<QXcbScreen*>(newScreen); QWindowSystemInterface::handleWindowScreenChanged(window(), newScreen->screen()); + int newDpr = devicePixelRatio(); + if (newDpr != dpr) { + QRect newRect = mapGeometryFromNative(nativeRect, newDpr); + QPlatformWindow::setGeometry(newRect); + QWindowSystemInterface::handleGeometryChange(window(), newRect); + } } m_configureNotifyPending = false; diff --git a/src/plugins/platforms/xcb/qxcbwindow.h b/src/plugins/platforms/xcb/qxcbwindow.h index 340070e882..b78bf779d0 100644 --- a/src/plugins/platforms/xcb/qxcbwindow.h +++ b/src/plugins/platforms/xcb/qxcbwindow.h @@ -151,6 +151,8 @@ public: virtual void create(); virtual void destroy(); + QPlatformScreen *screenForNativeGeometry(const QRect &newGeometry) const; + public Q_SLOTS: void updateSyncRequestCounter(); diff --git a/src/plugins/platforms/xcb/qxcbxsettings.cpp b/src/plugins/platforms/xcb/qxcbxsettings.cpp index 13d42832db..a1dadb0e54 100644 --- a/src/plugins/platforms/xcb/qxcbxsettings.cpp +++ b/src/plugins/platforms/xcb/qxcbxsettings.cpp @@ -36,7 +36,9 @@ #include <QtCore/QByteArray> #include <QtCore/QtEndian> +#ifdef XCB_USE_XLIB #include <X11/extensions/XIproto.h> +#endif //XCB_USE_XLIB QT_BEGIN_NAMESPACE /* Implementation of http://standards.freedesktop.org/xsettings-spec/xsettings-0.5.html */ @@ -138,6 +140,7 @@ public: return value + 4 - remainder; } +#ifdef XCB_USE_XLIB void populateSettings(const QByteArray &xSettings) { if (xSettings.length() < 12) @@ -212,6 +215,7 @@ public: } } +#endif //XCB_USE_XLIB QXcbScreen *screen; xcb_window_t x_settings_window; @@ -258,8 +262,10 @@ QXcbXSettings::QXcbXSettings(QXcbScreen *screen) const uint32_t event_mask[] = { XCB_EVENT_MASK_STRUCTURE_NOTIFY|XCB_EVENT_MASK_PROPERTY_CHANGE }; xcb_change_window_attributes(screen->xcb_connection(),d_ptr->x_settings_window,event,event_mask); +#ifdef XCB_USE_XLIB d_ptr->populateSettings(d_ptr->getSettings()); d_ptr->initialized = true; +#endif //XCB_USE_XLIB } QXcbXSettings::~QXcbXSettings() @@ -279,7 +285,9 @@ void QXcbXSettings::handlePropertyNotifyEvent(const xcb_property_notify_event_t Q_D(QXcbXSettings); if (event->window != d->x_settings_window) return; +#ifdef XCB_USE_XLIB d->populateSettings(d->getSettings()); +#endif //XCB_USE_XLIB } void QXcbXSettings::registerCallbackForProperty(const QByteArray &property, QXcbXSettings::PropertyChangeFunc func, void *handle) |