Source

Target

Showing with 537 additions and 371 deletions
......@@ -35,8 +35,12 @@
#define _POSIX_C_SOURCE 200809L
#include "qelapsedtimer.h"
#ifdef Q_OS_VXWORKS
#if defined(Q_OS_VXWORKS)
#include "qfunctions_vxworks.h"
#elif defined(Q_OS_QNX)
#include <sys/neutrino.h>
#include <sys/syspage.h>
#include <inttypes.h>
#else
#include <sys/time.h>
#include <time.h>
......@@ -84,7 +88,18 @@ QT_BEGIN_NAMESPACE
* see http://pubs.opengroup.org/onlinepubs/9699919799/functions/clock_getres.html
*/
#ifndef CLOCK_REALTIME
#if defined(Q_OS_QNX)
static inline void qt_clock_gettime(clockid_t clock, struct timespec *ts)
{
// The standard POSIX clock calls only have 1ms accuracy on QNX. To get
// higher accuracy, this platform-specific function must be used instead
quint64 cycles_per_sec = SYSPAGE_ENTRY(qtime)->cycles_per_sec;
quint64 cycles = ClockCycles();
ts->tv_sec = cycles / cycles_per_sec;
quint64 mod = cycles % cycles_per_sec;
ts->tv_nsec = mod * Q_INT64_C(1000000000) / cycles_per_sec;
}
#elif !defined(CLOCK_REALTIME)
# define CLOCK_REALTIME 0
static inline void qt_clock_gettime(int, struct timespec *ts)
{
......
......@@ -519,7 +519,7 @@ QBasicAtomicInt qt_cpu_features = Q_BASIC_ATOMIC_INITIALIZER(0);
void qDetectCpuFeatures()
{
#if defined(Q_CC_GNU) && !defined(Q_CC_CLANG) && !defined(Q_CC_INTEL)
# if (__GNUC__ * 100 + __GNUC_MINOR__) < 403
# if Q_CC_GNU < 403
// GCC 4.2 (at least the one that comes with Apple's XCode, on Mac) is
// known to be broken beyond repair in dealing with the inline assembly
// above. It will generate bad code that could corrupt important registers
......
......@@ -218,8 +218,8 @@
#endif
// other x86 intrinsics
#if defined(Q_PROCESSOR_X86) && ((defined(Q_CC_GNU) && (__GNUC__ * 100 + __GNUC_MINOR__ >= 404)) \
|| (defined(Q_CC_CLANG) && (__clang_major__ * 100 + __clang_minor__ >= 208)) \
#if defined(Q_PROCESSOR_X86) && ((defined(Q_CC_GNU) && (Q_CC_GNU >= 404)) \
|| (defined(Q_CC_CLANG) && (Q_CC_CLANG >= 208)) \
|| defined(Q_CC_INTEL))
# define QT_COMPILER_SUPPORTS_X86INTRIN
# ifdef Q_CC_INTEL
......@@ -332,7 +332,7 @@ static __forceinline unsigned long _bit_scan_forward(uint val)
_BitScanForward(&result, val);
return result;
}
# elif (defined(Q_CC_CLANG) || (defined(Q_CC_GNU) && __GNUC__ * 100 + __GNUC_MINOR__ < 405)) \
# elif (defined(Q_CC_CLANG) || (defined(Q_CC_GNU) && Q_CC_GNU < 405)) \
&& !defined(Q_CC_INTEL)
// Clang is missing the intrinsic for _bit_scan_reverse
// GCC only added it in version 4.5
......
......@@ -5705,21 +5705,18 @@ QString QString::toUpper() const
Safely builds a formatted string from the format string \a cformat
and an arbitrary list of arguments.
The %lc escape sequence expects a unicode character of type ushort
(as returned by QChar::unicode()). The %ls escape sequence expects
a pointer to a zero-terminated array of unicode characters of type
ushort (as returned by QString::utf16()).
\note This function expects a UTF-8 string for %s and Latin-1 for
the format string.
The format string supports most of the conversion specifiers
provided by printf() in the standard C++ library. It doesn't
honor the length modifiers (e.g. \c h for \c short, \c ll for
\c{long long}). If you need those, use the standard snprintf()
function instead:
\snippet qstring/main.cpp 63
The format string supports the conversion specifiers, length modifiers,
and flags provided by printf() in the standard C++ library. The \a cformat
string and \c{%s} arguments must be UTF-8 encoded.
\note The \c{%lc} escape sequence expects a unicode character of type
\c char16_t, or \c ushort (as returned by QChar::unicode()).
The \c{%ls} escape sequence expects a pointer to a zero-terminated array
of unicode characters of type \c char16_t, or ushort (as returned by
QString::utf16()). This is at odds with the printf() in the standard C++
library, which defines \c {%lc} to print a wchar_t and \c{%ls} to print
a \c{wchar_t*}, and might also produce compiler warnings on platforms
where the size of \c {wchar_t} is not 16 bits.
\warning We do not recommend using QString::sprintf() in new Qt
code. Instead, consider using QTextStream or arg(), both of
......@@ -6339,8 +6336,7 @@ ushort QString::toUShort(bool *ok, int base) const
\snippet qstring/main.cpp 66
Various string formats for floating point numbers can be converted
to double values:
\warning The QString content may only contain valid numerical characters which includes the plus/minus sign, the characters g and e used in scientific notation, and the decimal point. Including the unit or additional characters leads to a conversion error.
\snippet qstring/main.cpp 67
......@@ -6349,7 +6345,7 @@ ushort QString::toUShort(bool *ok, int base) const
\snippet qstring/main.cpp 68
For historic reasons, this function does not handle
For historical reasons, this function does not handle
thousands group separators. If you need to convert such numbers,
use QLocale::toDouble().
......
......@@ -282,24 +282,18 @@ public:
QStringList serverConnectionNames;
ConnectionMode mode;
QDBusConnectionInterface *busService;
// members accessed in unlocked mode (except for deletion)
// connection and server provide their own locking mechanisms
// busService doesn't have state to be changed
// the dispatch lock protects everything related to the DBusConnection or DBusServer
// including the timeouts and watches
QMutex dispatchLock;
DBusConnection *connection;
DBusServer *server;
QDBusConnectionInterface *busService;
// watchers and timeouts are accessed from any thread
// but the corresponding timer and QSocketNotifier must be handled
// only in the object's thread
QMutex watchAndTimeoutLock;
WatcherHash watchers;
TimeoutHash timeouts;
PendingTimeoutList timeoutsPendingAdd;
// members accessed through a lock
QMutex dispatchLock;
// the master lock protects our own internal state
QReadWriteLock lock;
QDBusError lastError;
......
......@@ -154,7 +154,7 @@ static dbus_bool_t qDBusAddTimeout(DBusTimeout *timeout, void *data)
if (!q_dbus_timeout_get_enabled(timeout))
return true;
QDBusWatchAndTimeoutLocker locker(AddTimeoutAction, d);
QDBusDispatchLocker locker(AddTimeoutAction, d);
if (QCoreApplication::instance() && QThread::currentThread() == d->thread()) {
// correct thread
return qDBusRealAddTimeout(d, timeout, q_dbus_timeout_get_interval(timeout));
......@@ -189,7 +189,7 @@ static void qDBusRemoveTimeout(DBusTimeout *timeout, void *data)
QDBusConnectionPrivate *d = static_cast<QDBusConnectionPrivate *>(data);
QDBusWatchAndTimeoutLocker locker(RemoveTimeoutAction, d);
QDBusDispatchLocker locker(RemoveTimeoutAction, d);
// is it pending addition?
QDBusConnectionPrivate::PendingTimeoutList::iterator pit = d->timeoutsPendingAdd.begin();
......@@ -262,7 +262,7 @@ static bool qDBusRealAddWatch(QDBusConnectionPrivate *d, DBusWatch *watch, int f
{
QDBusConnectionPrivate::Watcher watcher;
QDBusWatchAndTimeoutLocker locker(AddWatchAction, d);
QDBusDispatchLocker locker(AddWatchAction, d);
if (flags & DBUS_WATCH_READABLE) {
//qDebug("addReadWatch %d", fd);
watcher.watch = watch;
......@@ -296,7 +296,7 @@ static void qDBusRemoveWatch(DBusWatch *watch, void *data)
QDBusConnectionPrivate *d = static_cast<QDBusConnectionPrivate *>(data);
int fd = q_dbus_watch_get_unix_fd(watch);
QDBusWatchAndTimeoutLocker locker(RemoveWatchAction, d);
QDBusDispatchLocker locker(RemoveWatchAction, d);
QDBusConnectionPrivate::WatcherHash::iterator i = d->watchers.find(fd);
while (i != d->watchers.end() && i.key() == fd) {
if (i.value().watch == watch) {
......@@ -340,7 +340,7 @@ static void qDBusToggleWatch(DBusWatch *watch, void *data)
static void qDBusRealToggleWatch(QDBusConnectionPrivate *d, DBusWatch *watch, int fd)
{
QDBusWatchAndTimeoutLocker locker(ToggleWatchAction, d);
QDBusDispatchLocker locker(ToggleWatchAction, d);
QDBusConnectionPrivate::WatcherHash::iterator i = d->watchers.find(fd);
while (i != d->watchers.end() && i.key() == fd) {
......@@ -1015,8 +1015,8 @@ void QDBusConnectionPrivate::deliverCall(QObject *object, int /*flags*/, const Q
extern bool qDBusInitThreads();
QDBusConnectionPrivate::QDBusConnectionPrivate(QObject *p)
: QObject(p), ref(1), capabilities(0), mode(InvalidMode), connection(0), server(0), busService(0),
watchAndTimeoutLock(QMutex::Recursive),
: QObject(p), ref(1), capabilities(0), mode(InvalidMode), busService(0),
dispatchLock(QMutex::Recursive), connection(0), server(0),
rootNode(QString(QLatin1Char('/'))),
anonymousAuthenticationAllowed(false)
{
......@@ -1126,7 +1126,7 @@ bool QDBusConnectionPrivate::handleError(const QDBusErrorInternal &error)
void QDBusConnectionPrivate::timerEvent(QTimerEvent *e)
{
{
QDBusWatchAndTimeoutLocker locker(TimerEventAction, this);
QDBusDispatchLocker locker(TimerEventAction, this);
DBusTimeout *timeout = timeouts.value(e->timerId(), 0);
if (timeout)
q_dbus_timeout_handle(timeout);
......@@ -1145,7 +1145,7 @@ void QDBusConnectionPrivate::customEvent(QEvent *e)
switch (ev->subtype)
{
case QDBusConnectionCallbackEvent::AddTimeout: {
QDBusWatchAndTimeoutLocker locker(RealAddTimeoutAction, this);
QDBusDispatchLocker locker(RealAddTimeoutAction, this);
while (!timeoutsPendingAdd.isEmpty()) {
QPair<DBusTimeout *, int> entry = timeoutsPendingAdd.takeFirst();
qDBusRealAddTimeout(this, entry.first, entry.second);
......@@ -1178,41 +1178,29 @@ void QDBusConnectionPrivate::doDispatch()
void QDBusConnectionPrivate::socketRead(int fd)
{
QVarLengthArray<DBusWatch *, 2> pendingWatches;
{
QDBusWatchAndTimeoutLocker locker(SocketReadAction, this);
WatcherHash::ConstIterator it = watchers.constFind(fd);
while (it != watchers.constEnd() && it.key() == fd) {
if (it->watch && it->read && it->read->isEnabled())
pendingWatches.append(it.value().watch);
++it;
QDBusDispatchLocker locker(SocketReadAction, this);
WatcherHash::ConstIterator it = watchers.constFind(fd);
while (it != watchers.constEnd() && it.key() == fd) {
if (it->watch && it->read && it->read->isEnabled()) {
if (!q_dbus_watch_handle(it.value().watch, DBUS_WATCH_READABLE))
qDebug("OUT OF MEM");
}
++it;
}
for (int i = 0; i < pendingWatches.size(); ++i)
if (!q_dbus_watch_handle(pendingWatches[i], DBUS_WATCH_READABLE))
qDebug("OUT OF MEM");
doDispatch();
}
void QDBusConnectionPrivate::socketWrite(int fd)
{
QVarLengthArray<DBusWatch *, 2> pendingWatches;
{
QDBusWatchAndTimeoutLocker locker(SocketWriteAction, this);
WatcherHash::ConstIterator it = watchers.constFind(fd);
while (it != watchers.constEnd() && it.key() == fd) {
if (it->watch && it->write && it->write->isEnabled())
pendingWatches.append(it.value().watch);
++it;
QDBusDispatchLocker locker(SocketWriteAction, this);
WatcherHash::ConstIterator it = watchers.constFind(fd);
while (it != watchers.constEnd() && it.key() == fd) {
if (it->watch && it->write && it->write->isEnabled()) {
if (!q_dbus_watch_handle(it.value().watch, DBUS_WATCH_WRITABLE))
qDebug("OUT OF MEM");
}
++it;
}
for (int i = 0; i < pendingWatches.size(); ++i)
if (!q_dbus_watch_handle(pendingWatches[i], DBUS_WATCH_WRITABLE))
qDebug("OUT OF MEM");
}
void QDBusConnectionPrivate::objectDestroyed(QObject *obj)
......@@ -1265,7 +1253,10 @@ void QDBusConnectionPrivate::relaySignal(QObject *obj, const QMetaObject *mo, in
//qDBusDebug() << "Emitting signal" << message;
//qDBusDebug() << "for paths:";
q_dbus_message_set_no_reply(msg, true); // the reply would not be delivered to anything
huntAndEmit(connection, msg, obj, rootNode, isScriptable, isAdaptor);
{
QDBusDispatchLocker locker(HuntAndEmitAction, this);
huntAndEmit(connection, msg, obj, rootNode, isScriptable, isAdaptor);
}
q_dbus_message_unref(msg);
}
......@@ -1922,7 +1913,11 @@ int QDBusConnectionPrivate::send(const QDBusMessage& message)
qDBusDebug() << this << "sending message (no reply):" << message;
checkThread();
bool isOk = q_dbus_connection_send(connection, msg, 0);
bool isOk;
{
QDBusDispatchLocker locker(SendMessageAction, this);
isOk = q_dbus_connection_send(connection, msg, 0);
}
int serial = 0;
if (isOk)
serial = q_dbus_message_get_serial(msg);
......@@ -2040,7 +2035,11 @@ QDBusMessage QDBusConnectionPrivate::sendWithReply(const QDBusMessage &message,
qDBusDebug() << this << "sending message (blocking):" << message;
QDBusErrorInternal error;
DBusMessage *reply = q_dbus_connection_send_with_reply_and_block(connection, msg, timeout, error);
DBusMessage *reply;
{
QDBusDispatchLocker locker(SendWithReplyAndBlockAction, this);
reply = q_dbus_connection_send_with_reply_and_block(connection, msg, timeout, error);
}
q_dbus_message_unref(msg);
......
......@@ -86,6 +86,9 @@ enum ThreadAction {
MessageResultReceivedAction = 26,
ActivateSignalAction = 27,
PendingCallBlockAction = 28,
SendMessageAction = 29,
SendWithReplyAndBlockAction = 30,
HuntAndEmitAction = 31,
AddTimeoutAction = 50,
RealAddTimeoutAction = 51,
......@@ -196,13 +199,6 @@ struct QDBusDispatchLocker: QDBusMutexLocker
{ }
};
struct QDBusWatchAndTimeoutLocker: QDBusMutexLocker
{
inline QDBusWatchAndTimeoutLocker(ThreadAction a, QDBusConnectionPrivate *s)
: QDBusMutexLocker(a, s, &s->watchAndTimeoutLock)
{ }
};
#if QDBUS_THREAD_DEBUG
# define SEM_ACQUIRE(action, sem) \
do { \
......
......@@ -1122,6 +1122,10 @@ Qt::WindowState QWindow::windowState() const
This is a hint to the window manager that this window is a dialog or pop-up
on behalf of the given window.
In order to cause the window to be centered above its transient parent by
default, depending on the window manager, it may also be necessary to call
setFlags() with a suitable \l Qt::WindowType (such as \c Qt::Dialog).
\sa transientParent(), parent()
*/
void QWindow::setTransientParent(QWindow *parent)
......
......@@ -82,10 +82,12 @@ QOpenGLTextureGlyphCache::~QOpenGLTextureGlyphCache()
clear();
}
#if !defined(QT_OPENGL_ES_2)
static inline bool isCoreProfile()
{
return QOpenGLContext::currentContext()->format().profile() == QSurfaceFormat::CoreProfile;
}
#endif
void QOpenGLTextureGlyphCache::createTextureData(int width, int height)
{
......
......@@ -2524,10 +2524,6 @@ void QPdfEnginePrivate::drawTextItem(const QPointF &p, const QTextItemInt &ti)
qreal size = ti.fontEngine->fontDef.pixelSize;
#if defined(Q_OS_WIN)
size = (ti.fontEngine->ascent() + ti.fontEngine->descent()).toReal();
#endif
QVarLengthArray<glyph_t> glyphs;
QVarLengthArray<QFixedPoint> positions;
QTransform m = QTransform::fromTranslate(p.x(), p.y());
......
......@@ -44,31 +44,49 @@
QT_BEGIN_NAMESPACE
static QString resolve2xFile(const QString &fileName, qreal targetDevicePixelRatio)
static QString resolveFileName(QString fileName, QUrl *url, qreal targetDevicePixelRatio)
{
// We might use the fileName for loading if url loading fails
// try to make sure it is a valid file path.
// Also, QFile{Info}::exists works only on filepaths (not urls)
if (url->isValid()) {
if (url->scheme() == QLatin1Literal("qrc")) {
fileName = fileName.right(fileName.length() - 3);
}
else if (url->scheme() == QLatin1Literal("file")) {
fileName = url->toLocalFile();
}
}
if (targetDevicePixelRatio <= 1.0)
return fileName;
int dotIndex = fileName.lastIndexOf(QLatin1Char('.'));
// try to find a 2x version
const int dotIndex = fileName.lastIndexOf(QLatin1Char('.'));
if (dotIndex != -1) {
QString at2xfileName = fileName;
at2xfileName.insert(dotIndex, QStringLiteral("@2x"));
if (QFile::exists(at2xfileName))
return at2xfileName;
if (QFile::exists(at2xfileName)) {
fileName = at2xfileName;
*url = QUrl(fileName);
}
}
return fileName;
}
static QPixmap getPixmap(QTextDocument *doc, const QTextImageFormat &format)
static QPixmap getPixmap(QTextDocument *doc, const QTextImageFormat &format, const qreal devicePixelRatio = 1.0)
{
QPixmap pm;
QString name = format.name();
if (name.startsWith(QLatin1String(":/"))) // auto-detect resources
if (name.startsWith(QLatin1String(":/"))) // auto-detect resources and convert them to url
name.prepend(QLatin1String("qrc"));
QPaintDevice *pdev = doc->documentLayout()->paintDevice();
name = resolve2xFile(name, pdev ? pdev->devicePixelRatio() : qApp->devicePixelRatio());
QUrl url = QUrl(name);
name = resolveFileName(name, &url, devicePixelRatio);
const QVariant data = doc->resource(QTextDocument::ImageResource, url);
if (data.type() == QVariant::Pixmap || data.type() == QVariant::Image) {
pm = qvariant_cast<QPixmap>(data);
......@@ -77,19 +95,18 @@ static QPixmap getPixmap(QTextDocument *doc, const QTextImageFormat &format)
}
if (pm.isNull()) {
QString context;
#if 0
QString context;
// ### Qt5
QTextBrowser *browser = qobject_cast<QTextBrowser *>(doc->parent());
if (browser)
context = browser->source().toString();
#endif
// try direct loading
QImage img;
if (img.isNull()) { // try direct loading
name = format.name(); // remove qrc:/ prefix again
if (name.isEmpty() || !img.load(name))
return QPixmap(QLatin1String(":/qt-project.org/styles/commonstyle/images/file-16.png"));
}
if (name.isEmpty() || !img.load(name))
return QPixmap(QLatin1String(":/qt-project.org/styles/commonstyle/images/file-16.png"));
pm = QPixmap::fromImage(img);
doc->addResource(QTextDocument::ImageResource, url, pm);
}
......@@ -142,16 +159,15 @@ static QSize getPixmapSize(QTextDocument *doc, const QTextImageFormat &format)
return size;
}
static QImage getImage(QTextDocument *doc, const QTextImageFormat &format)
static QImage getImage(QTextDocument *doc, const QTextImageFormat &format, const qreal devicePixelRatio = 1.0)
{
QImage image;
QString name = format.name();
if (name.startsWith(QLatin1String(":/"))) // auto-detect resources
name.prepend(QLatin1String("qrc"));
QPaintDevice *pdev = doc->documentLayout()->paintDevice();
name = resolve2xFile(name, pdev ? pdev->devicePixelRatio() : qApp->devicePixelRatio());
QUrl url = QUrl(name);
name = resolveFileName(name, &url, devicePixelRatio);
const QVariant data = doc->resource(QTextDocument::ImageResource, url);
if (data.type() == QVariant::Image) {
image = qvariant_cast<QImage>(data);
......@@ -160,19 +176,18 @@ static QImage getImage(QTextDocument *doc, const QTextImageFormat &format)
}
if (image.isNull()) {
QString context;
#if 0
QString context;
// ### Qt5
QTextBrowser *browser = qobject_cast<QTextBrowser *>(doc->parent());
if (browser)
context = browser->source().toString();
#endif
if (image.isNull()) { // try direct loading
name = format.name(); // remove qrc:/ prefix again
if (name.isEmpty() || !image.load(name))
return QImage(QLatin1String(":/qt-project.org/styles/commonstyle/images/file-16.png"));
}
// try direct loading
if (name.isEmpty() || !image.load(name))
return QImage(QLatin1String(":/qt-project.org/styles/commonstyle/images/file-16.png"));
doc->addResource(QTextDocument::ImageResource, url, image);
}
......@@ -241,10 +256,10 @@ void QTextImageHandler::drawObject(QPainter *p, const QRectF &rect, QTextDocumen
const QTextImageFormat imageFormat = format.toImageFormat();
if (QCoreApplication::instance()->thread() != QThread::currentThread()) {
const QImage image = getImage(doc, imageFormat);
const QImage image = getImage(doc, imageFormat, p->device()->devicePixelRatio());
p->drawImage(rect, image, image.rect());
} else {
const QPixmap pixmap = getPixmap(doc, imageFormat);
const QPixmap pixmap = getPixmap(doc, imageFormat, p->device()->devicePixelRatio());
p->drawPixmap(rect, pixmap, pixmap.rect());
}
}
......
......@@ -1135,7 +1135,12 @@ QNetworkReply *QNetworkAccessManager::createRequest(QNetworkAccessManager::Opera
if (!d->networkSessionStrongRef && (d->initializeSession || !d->networkConfiguration.identifier().isEmpty())) {
QNetworkConfigurationManager manager;
if (!d->networkConfiguration.identifier().isEmpty()) {
d->createSession(d->networkConfiguration);
if ((d->networkConfiguration.state() & QNetworkConfiguration::Defined)
&& d->networkConfiguration != manager.defaultConfiguration())
d->createSession(manager.defaultConfiguration());
else
d->createSession(d->networkConfiguration);
} else {
if (manager.capabilities() & QNetworkConfigurationManager::NetworkSessionRequired)
d->createSession(manager.defaultConfiguration());
......@@ -1590,6 +1595,11 @@ void QNetworkAccessManagerPrivate::_q_onlineStateChanged(bool isOnline)
if (customNetworkConfiguration) {
online = (networkConfiguration.state() & QNetworkConfiguration::Active);
} else {
if (isOnline && online != isOnline) {
networkSessionStrongRef.clear();
networkSessionWeakRef.clear();
}
online = isOnline;
}
}
......
......@@ -1908,18 +1908,14 @@ qint64 QSslSocket::readData(char *data, qint64 maxlen)
if (d->mode == UnencryptedMode && !d->autoStartHandshake) {
readBytes = d->plainSocket->read(data, maxlen);
} else {
int bytesToRead = qMin<int>(maxlen, d->buffer.size());
readBytes = d->buffer.read(data, bytesToRead);
}
#ifdef QSSLSOCKET_DEBUG
qDebug() << "QSslSocket::readData(" << (void *)data << ',' << maxlen << ") ==" << readBytes;
qDebug() << "QSslSocket::readData(" << (void *)data << ',' << maxlen << ") =="
<< readBytes;
#endif
// possibly trigger another transmit() to decrypt more data from the socket
if (d->buffer.isEmpty() && d->plainSocket->bytesAvailable()) {
QMetaObject::invokeMethod(this, "_q_flushReadBuffer", Qt::QueuedConnection);
} else {
// possibly trigger another transmit() to decrypt more data from the socket
if (d->plainSocket->bytesAvailable())
QMetaObject::invokeMethod(this, "_q_flushReadBuffer", Qt::QueuedConnection);
}
return readBytes;
......
......@@ -8,14 +8,14 @@ QT = core network-private dbus
CONFIG += link_pkgconfig
HEADERS += qconnmanservice_linux_p.h \
qofonoservice_linux_p.h \
../linux_common/qofonoservice_linux_p.h \
qconnmanengine.h \
../qnetworksession_impl.h \
../qbearerengine_impl.h
SOURCES += main.cpp \
qconnmanservice_linux.cpp \
qofonoservice_linux.cpp \
../linux_common/qofonoservice_linux.cpp \
qconnmanengine.cpp \
../qnetworksession_impl.cpp
......
......@@ -48,7 +48,7 @@
#include "../qbearerengine_impl.h"
#include "qconnmanservice_linux_p.h"
#include "qofonoservice_linux_p.h"
#include "../linux_common/qofonoservice_linux_p.h"
#include <QMap>
#include <QVariant>
......
......@@ -95,14 +95,12 @@ QStringList QOfonoManagerInterface::getModems()
{
if (modemList.isEmpty()) {
QList<QVariant> argumentList;
QDBusPendingReply<PathPropertiesList> reply = asyncCallWithArgumentList(QLatin1String("GetModems"), argumentList);
QDBusPendingReply<PathPropertiesList> reply = callWithArgumentList(QDBus::Block, QLatin1String("GetModems"), argumentList);
reply.waitForFinished();
if (!reply.isError()) {
foreach (ObjectPathProperties modem, reply.value()) {
modemList << modem.path.path();
}
} else {
qDebug() << reply.error().message();
}
}
......@@ -114,7 +112,8 @@ QString QOfonoManagerInterface::currentModem()
QStringList modems = getModems();
foreach (const QString &modem, modems) {
QOfonoModemInterface device(modem);
if (device.isPowered() && device.isOnline())
if (device.isPowered() && device.isOnline()
&& device.interfaces().contains(QStringLiteral("org.ofono.NetworkRegistration")))
return modem;
}
return QString();
......@@ -171,11 +170,17 @@ bool QOfonoModemInterface::isOnline()
return qdbus_cast<bool>(var);
}
QStringList QOfonoModemInterface::interfaces()
{
const QVariant var = getProperty(QStringLiteral("Interfaces"));
return var.toStringList();
}
QVariantMap QOfonoModemInterface::getProperties()
{
if (propertiesMap.isEmpty()) {
QList<QVariant> argumentList;
QDBusPendingReply<QVariantMap> reply = asyncCallWithArgumentList(QLatin1String("GetProperties"), argumentList);
QDBusPendingReply<QVariantMap> reply = callWithArgumentList(QDBus::Block, QLatin1String("GetProperties"), argumentList);
if (!reply.isError()) {
propertiesMap = reply.value();
}
......@@ -187,7 +192,8 @@ QVariant QOfonoModemInterface::getProperty(const QString &property)
{
QVariant var;
QVariantMap map = getProperties();
var = map.value(property);
if (map.contains(property))
var = map.value(property);
return var;
}
......@@ -214,7 +220,8 @@ QVariant QOfonoNetworkRegistrationInterface::getProperty(const QString &property
{
QVariant var;
QVariantMap map = getProperties();
var = map.value(property);
if (map.contains(property))
var = map.value(property);
return var;
}
......@@ -222,12 +229,10 @@ QVariantMap QOfonoNetworkRegistrationInterface::getProperties()
{
if (propertiesMap.isEmpty()) {
QList<QVariant> argumentList;
QDBusPendingReply<QVariantMap> reply = asyncCallWithArgumentList(QLatin1String("GetProperties"), argumentList);
QDBusPendingReply<QVariantMap> reply = callWithArgumentList(QDBus::Block, QLatin1String("GetProperties"), argumentList);
reply.waitForFinished();
if (!reply.isError()) {
propertiesMap = reply.value();
} else {
qDebug() << reply.error().message();
}
}
return propertiesMap;
......@@ -270,11 +275,18 @@ bool QOfonoDataConnectionManagerInterface::roamingAllowed()
return qdbus_cast<bool>(var);
}
QString QOfonoDataConnectionManagerInterface::bearer()
{
QVariant var = getProperty(QStringLiteral("Bearer"));
return qdbus_cast<QString>(var);
}
QVariant QOfonoDataConnectionManagerInterface::getProperty(const QString &property)
{
QVariant var;
QVariantMap map = getProperties();
var = map.value(property);
if (map.contains(property))
var = map.value(property);
return var;
}
......@@ -282,7 +294,7 @@ QVariantMap QOfonoDataConnectionManagerInterface::getProperties()
{
if (propertiesMap.isEmpty()) {
QList<QVariant> argumentList;
QDBusPendingReply<QVariantMap> reply = asyncCallWithArgumentList(QLatin1String("GetProperties"), argumentList);
QDBusPendingReply<QVariantMap> reply = callWithArgumentList(QDBus::Block, QLatin1String("GetProperties"), argumentList);
if (!reply.isError()) {
propertiesMap = reply.value();
}
......@@ -297,6 +309,68 @@ void QOfonoDataConnectionManagerInterface::propertyChanged(const QString &name,
Q_EMIT roamingAllowedChanged(value.variant().toBool());
}
QOfonoConnectionContextInterface::QOfonoConnectionContextInterface(const QString &dbusPathName, QObject *parent)
: QDBusAbstractInterface(QLatin1String(OFONO_SERVICE),
dbusPathName,
OFONO_CONNECTION_CONTEXT_INTERFACE,
QDBusConnection::systemBus(), parent)
{
QDBusConnection::systemBus().connect(QLatin1String(OFONO_SERVICE),
path(),
QLatin1String(OFONO_MODEM_INTERFACE),
QLatin1String("PropertyChanged"),
this,SLOT(propertyChanged(QString,QDBusVariant)));
}
QOfonoConnectionContextInterface::~QOfonoConnectionContextInterface()
{
}
QVariantMap QOfonoConnectionContextInterface::getProperties()
{
if (propertiesMap.isEmpty()) {
QList<QVariant> argumentList;
QDBusPendingReply<QVariantMap> reply = callWithArgumentList(QDBus::Block, QLatin1String("GetProperties"), argumentList);
if (!reply.isError()) {
propertiesMap = reply.value();
}
}
return propertiesMap;
}
void QOfonoConnectionContextInterface::propertyChanged(const QString &name, const QDBusVariant &value)
{
propertiesMap[name] = value.variant();
}
QVariant QOfonoConnectionContextInterface::getProperty(const QString &property)
{
QVariant var;
QVariantMap map = getProperties();
if (map.contains(property))
var = map.value(property);
return var;
}
bool QOfonoConnectionContextInterface::active()
{
QVariant var = getProperty(QStringLiteral("Active"));
return qdbus_cast<bool>(var);
}
QString QOfonoConnectionContextInterface::accessPointName()
{
QVariant var = getProperty(QStringLiteral("AccessPointName"));
return qdbus_cast<QString>(var);
}
QString QOfonoConnectionContextInterface::name()
{
QVariant var = getProperty(QStringLiteral("Name"));
return qdbus_cast<QString>(var);
}
QT_END_NAMESPACE
#endif // QT_NO_DBUS
......
......@@ -67,6 +67,7 @@
#define OFONO_MODEM_INTERFACE "org.ofono.Modem"
#define OFONO_NETWORK_REGISTRATION_INTERFACE "org.ofono.NetworkRegistration"
#define OFONO_DATA_CONNECTION_MANAGER_INTERFACE "org.ofono.ConnectionManager"
#define OFONO_CONNECTION_CONTEXT_INTERFACE "org.ofono.ConnectionContext"
QT_BEGIN_NAMESPACE
......@@ -114,6 +115,7 @@ public:
bool isPowered();
bool isOnline();
QStringList interfaces();
private:
QVariantMap getProperties();
QVariantMap propertiesMap;
......@@ -152,17 +154,39 @@ public:
QStringList contexts();
bool roamingAllowed();
QVariant getProperty(const QString &);
QString bearer();
Q_SIGNALS:
void roamingAllowedChanged(bool);
private:
QVariantMap getProperties();
QVariantMap propertiesMap;
QVariant getProperty(const QString &);
QStringList contextList;
private slots:
void propertyChanged(const QString &, const QDBusVariant &value);
};
class QOfonoConnectionContextInterface : public QDBusAbstractInterface
{
Q_OBJECT
public:
explicit QOfonoConnectionContextInterface(const QString &dbusPathName, QObject *parent = 0);
~QOfonoConnectionContextInterface();
QVariant getProperty(const QString &);
bool active();
QString accessPointName();
QString name();
Q_SIGNALS:
private:
QVariantMap getProperties();
QVariantMap propertiesMap;
private slots:
void propertyChanged(const QString &, const QDBusVariant &value);
};
QT_END_NAMESPACE
......
......@@ -6,16 +6,16 @@ load(qt_plugin)
QT = core network-private dbus
HEADERS += qnmdbushelper.h \
qnetworkmanagerservice.h \
HEADERS += qnetworkmanagerservice.h \
qnetworkmanagerengine.h \
../linux_common/qofonoservice_linux_p.h \
../qnetworksession_impl.h \
../qbearerengine_impl.h
SOURCES += main.cpp \
qnmdbushelper.cpp \
qnetworkmanagerservice.cpp \
qnetworkmanagerengine.cpp \
../linux_common/qofonoservice_linux.cpp \
../qnetworksession_impl.cpp
OTHER_FILES += networkmanager.json
......@@ -49,6 +49,8 @@
#include "qnetworkmanagerservice.h"
#include "../linux_common/qofonoservice_linux_p.h"
#include <QMap>
#include <QVariant>
......@@ -89,11 +91,8 @@ public:
QNetworkConfigurationPrivatePointer defaultConfiguration();
private Q_SLOTS:
void interfacePropertiesChanged(const QString &path,
const QMap<QString, QVariant> &properties);
void activeConnectionPropertiesChanged(const QString &path,
const QMap<QString, QVariant> &properties);
void devicePropertiesChanged(const QString &path, quint32);
void interfacePropertiesChanged(const QMap<QString, QVariant> &properties);
void activeConnectionPropertiesChanged(const QMap<QString, QVariant> &properties);
void deviceAdded(const QDBusObjectPath &path);
void deviceRemoved(const QDBusObjectPath &path);
......@@ -106,9 +105,10 @@ private Q_SLOTS:
void newAccessPoint(const QString &path);
void removeAccessPoint(const QString &path);
void updateAccessPoint(const QMap<QString, QVariant> &map);
void scanFinished();
void wiredCarrierChanged(bool);
private:
QNetworkConfigurationPrivate *parseConnection(const QString &settingsPath,
const QNmSettingsMap &map);
......@@ -116,14 +116,22 @@ private:
QNetworkManagerInterface *managerInterface;
QNetworkManagerSettings *systemSettings;
QNetworkManagerSettings *userSettings;
QHash<QString, QNetworkManagerInterfaceDeviceWired *> wiredDevices;
QHash<QString, QNetworkManagerInterfaceDeviceWireless *> wirelessDevices;
QHash<QString, QNetworkManagerConnectionActive *> activeConnections;
QHash<QString, QNetworkManagerConnectionActive *> activeConnectionsList;
QList<QNetworkManagerSettingsConnection *> connections;
QList<QNetworkManagerInterfaceAccessPoint *> accessPoints;
QHash<QString, QNetworkManagerInterfaceDevice *> interfaceDevices;
QMap<QString,QString> configuredAccessPoints; //ap, settings path
QHash<QString,QString> connectionInterfaces; // ac, interface
QOfonoManagerInterface *ofonoManager;
QHash <QString, QOfonoDataConnectionManagerInterface *> ofonoContextManagers;
QNetworkConfiguration::BearerType currentBearerType(const QString &id);
QString contextName(const QString &path);
};
QT_END_NAMESPACE
......