Index: plasma/scriptengines/javascript/declarative/qfilenetworkreply.cpp =================================================================== --- a/plasma/scriptengines/javascript/declarative/qfilenetworkreply.cpp (revision 0) +++ b/plasma/scriptengines/javascript/declarative/qfilenetworkreply.cpp (revision 0) @@ -0,0 +1,222 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtNetwork module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qfilenetworkreply_p.h" + +#include "QtCore/qdatetime.h" +#include +#include +#include + +QT_BEGIN_NAMESPACE + +QNetworkReplyPrivate::QNetworkReplyPrivate() + : readBufferMaxSize(0), + operation(QNetworkAccessManager::UnknownOperation), + errorCode(QNetworkReply::NoError) +{ + // set the default attribute values + attributes.insert(QNetworkRequest::ConnectionEncryptedAttribute, false); +} + + +QFileNetworkReplyPrivate::QFileNetworkReplyPrivate() + : QNetworkReplyPrivate(), fileEngine(0), fileSize(0), filePos(0) +{ +} + +QFileNetworkReplyPrivate::~QFileNetworkReplyPrivate() +{ + delete fileEngine; +} + +QFileNetworkReply::~QFileNetworkReply() +{ +} + +QFileNetworkReply::QFileNetworkReply(QObject *parent, const QNetworkRequest &req, const QNetworkAccessManager::Operation op) + : QNetworkReply(*new QFileNetworkReplyPrivate(), parent) +{ + setRequest(req); + setUrl(req.url()); + setOperation(op); + QNetworkReply::open(QIODevice::ReadOnly); + + qRegisterMetaType("QNetworkReply::NetworkError"); + + QFileNetworkReplyPrivate *d = (QFileNetworkReplyPrivate*) d_func(); + + QUrl url = req.url(); + if (url.host() == QLatin1String("localhost")) + url.setHost(QString()); + +#if !defined(Q_OS_WIN) + // do not allow UNC paths on Unix + if (!url.host().isEmpty()) { + // we handle only local files + QString msg = QCoreApplication::translate("QNetworkAccessFileBackend", "Request for opening non-local file %1").arg(url.toString()); + setError(QNetworkReply::ProtocolInvalidOperationError, msg); + QMetaObject::invokeMethod(this, "error", Qt::QueuedConnection, + Q_ARG(QNetworkReply::NetworkError, QNetworkReply::ProtocolInvalidOperationError)); + QMetaObject::invokeMethod(this, "finished", Qt::QueuedConnection); + return; + } +#endif + if (url.path().isEmpty()) + url.setPath(QLatin1String("/")); + setUrl(url); + + + QString fileName = url.toLocalFile(); + if (fileName.isEmpty()) { + if (url.scheme() == QLatin1String("qrc")) + fileName = QLatin1Char(':') + url.path(); + else + fileName = url.toString(QUrl::RemoveAuthority | QUrl::RemoveFragment | QUrl::RemoveQuery); + } + + QFileInfo fi(fileName); + if (fi.isDir()) { + QString msg = QCoreApplication::translate("QNetworkAccessFileBackend", "Cannot open %1: Path is a directory").arg(url.toString()); + setError(QNetworkReply::ContentOperationNotPermittedError, msg); + QMetaObject::invokeMethod(this, "error", Qt::QueuedConnection, + Q_ARG(QNetworkReply::NetworkError, QNetworkReply::ContentOperationNotPermittedError)); + QMetaObject::invokeMethod(this, "finished", Qt::QueuedConnection); + return; + } + + d->fileEngine = QAbstractFileEngine::create(fileName); + bool opened = d->fileEngine->open(QIODevice::ReadOnly | QIODevice::Unbuffered); + + // could we open the file? + if (!opened) { + QString msg = QCoreApplication::translate("QNetworkAccessFileBackend", "Error opening %1: %2") + .arg(fileName, d->fileEngine->errorString()); + + if (fi.exists()) { + setError(QNetworkReply::ContentAccessDenied, msg); + QMetaObject::invokeMethod(this, "error", Qt::QueuedConnection, + Q_ARG(QNetworkReply::NetworkError, QNetworkReply::ContentAccessDenied)); + } else { + setError(QNetworkReply::ContentNotFoundError, msg); + QMetaObject::invokeMethod(this, "error", Qt::QueuedConnection, + Q_ARG(QNetworkReply::NetworkError, QNetworkReply::ContentNotFoundError)); + } + QMetaObject::invokeMethod(this, "finished", Qt::QueuedConnection); + return; + } + + d->fileSize = fi.size(); + setHeader(QNetworkRequest::LastModifiedHeader, fi.lastModified()); + setHeader(QNetworkRequest::ContentLengthHeader, d->fileSize); + + QMetaObject::invokeMethod(this, "metaDataChanged", Qt::QueuedConnection); + QMetaObject::invokeMethod(this, "downloadProgress", Qt::QueuedConnection, + Q_ARG(qint64, d->fileSize), Q_ARG(qint64, d->fileSize)); + QMetaObject::invokeMethod(this, "readyRead", Qt::QueuedConnection); + QMetaObject::invokeMethod(this, "finished", Qt::QueuedConnection); +} + +bool QFileNetworkReplyPrivate::isFinished() const +{ + return true; +} + +void QFileNetworkReply::close() +{ + Q_D(QFileNetworkReply); + QNetworkReply::close(); + if (d->fileEngine) + d->fileEngine->close(); +} + +void QFileNetworkReply::abort() +{ + Q_D(QFileNetworkReply); + QNetworkReply::close(); + if (d->fileEngine) + d->fileEngine->close(); +} + +qint64 QFileNetworkReply::bytesAvailable() const +{ + Q_D(const QFileNetworkReply); + if (!d->fileEngine) + return 0; + + return QNetworkReply::bytesAvailable() + d->fileSize - d->filePos; +} + +bool QFileNetworkReply::isSequential () const +{ + return true; +} + +qint64 QFileNetworkReply::size() const +{ + Q_D(const QFileNetworkReply); + return d->fileSize; +} + +/*! + \internal +*/ +qint64 QFileNetworkReply::readData(char *data, qint64 maxlen) +{ + Q_D(QFileNetworkReply); + if (!d->fileEngine) + return -1; + + qint64 ret = d->fileEngine->read(data, maxlen); + if (ret == 0 && bytesAvailable() == 0) { + return -1; // everything had been read + } else if (ret > 0) { + d->filePos += ret; + } + + return ret; +} + + +QT_END_NAMESPACE + +#include "moc_qfilenetworkreply_p.cpp" + Index: plasma/scriptengines/javascript/declarative/qnetworkrequest_p.h =================================================================== --- a/plasma/scriptengines/javascript/declarative/qnetworkrequest_p.h (revision 0) +++ b/plasma/scriptengines/javascript/declarative/qnetworkrequest_p.h (revision 0) @@ -0,0 +1,98 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtNetwork module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QNETWORKREQUEST_P_H +#define QNETWORKREQUEST_P_H + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists for the convenience +// of the Network Access API. This header file may change from +// version to version without notice, or even be removed. +// +// We mean it. +// + +#include "qnetworkrequest.h" +#include "QtCore/qbytearray.h" +#include "QtCore/qlist.h" +#include "QtCore/qhash.h" +#include "QtCore/qshareddata.h" +#include "QtCore/qsharedpointer.h" + +QT_BEGIN_NAMESPACE + +// this is the common part between QNetworkRequestPrivate and QNetworkReplyPrivate +class QNetworkHeadersPrivate +{ +public: + typedef QPair RawHeaderPair; + typedef QList RawHeadersList; + typedef QHash CookedHeadersMap; + typedef QHash AttributesMap; + + RawHeadersList rawHeaders; + CookedHeadersMap cookedHeaders; + AttributesMap attributes; + QWeakPointer originatingObject; + + RawHeadersList::ConstIterator findRawHeader(const QByteArray &key) const; + QList rawHeadersKeys() const; + void setRawHeader(const QByteArray &key, const QByteArray &value); + void setAllRawHeaders(const RawHeadersList &list); + void setCookedHeader(QNetworkRequest::KnownHeaders header, const QVariant &value); + + static QDateTime fromHttpDate(const QByteArray &value); + static QByteArray toHttpDate(const QDateTime &dt); + +private: + void setRawHeaderInternal(const QByteArray &key, const QByteArray &value); + void parseAndSetHeader(const QByteArray &key, const QByteArray &value); +}; + +Q_DECLARE_TYPEINFO(QNetworkHeadersPrivate::RawHeaderPair, Q_MOVABLE_TYPE); + +QT_END_NAMESPACE + + +#endif Index: plasma/scriptengines/javascript/declarative/packageaccessmanager.cpp =================================================================== --- a/plasma/scriptengines/javascript/declarative/packageaccessmanager.cpp (revision 1216700) +++ b/plasma/scriptengines/javascript/declarative/packageaccessmanager.cpp (working copy) @@ -18,6 +18,7 @@ */ #include "packageaccessmanager.h" +#include "qfilenetworkreply_p.h" #include @@ -68,7 +69,10 @@ reqUrl.setScheme("file"); reqUrl.setPath(m_package->filePath(0, reqUrl.path())); request.setUrl(reqUrl); - return QNetworkAccessManager::createRequest(op, request, outgoingData); + + QFileNetworkReply *reply = new QFileNetworkReply(this, request, op); + reply->setUrl(req.url()); + return reply; } else if ((reqUrl.scheme() == "http" && !m_auth->authorizeRequiredExtension("http")) || ((reqUrl.scheme() == "file" || reqUrl.scheme() == "desktop") && !m_auth->authorizeRequiredExtension("localio")) || (!m_auth->authorizeRequiredExtension("networkio"))) { Index: plasma/scriptengines/javascript/declarative/private/qringbuffer_p.h =================================================================== --- a/plasma/scriptengines/javascript/declarative/private/qringbuffer_p.h (revision 0) +++ b/plasma/scriptengines/javascript/declarative/private/qringbuffer_p.h (revision 0) @@ -0,0 +1,451 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtCore module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QRINGBUFFER_P_H +#define QRINGBUFFER_P_H + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists for the convenience +// of a number of Qt sources files. This header file may change from +// version to version without notice, or even be removed. +// +// We mean it. +// + +#include +#include + +QT_BEGIN_NAMESPACE + +class QRingBuffer +{ +public: + inline QRingBuffer(int growth = 4096) : basicBlockSize(growth) { + buffers << QByteArray(); + clear(); + } + + inline int nextDataBlockSize() const { + return (tailBuffer == 0 ? tail : buffers.first().size()) - head; + } + + inline const char *readPointer() const { + return buffers.isEmpty() ? 0 : (buffers.first().constData() + head); + } + + // access the bytes at a specified position + // the out-variable length will contain the amount of bytes readable + // from there, e.g. the amount still the same QByteArray + inline const char *readPointerAtPosition(qint64 pos, qint64 &length) const { + if (buffers.isEmpty()) { + length = 0; + return 0; + } + + if (pos >= bufferSize) { + length = 0; + return 0; + } + + // special case: it is in the first buffer + int nextDataBlockSizeValue = nextDataBlockSize(); + if (pos - head < nextDataBlockSizeValue) { + length = nextDataBlockSizeValue - pos; + return buffers.at(0).constData() + head + pos; + } + + // special case: we only had one buffer and tried to read over it + if (buffers.length() == 1) { + length = 0; + return 0; + } + + // skip the first + pos -= nextDataBlockSizeValue; + + // normal case: it is somewhere in the second to the-one-before-the-tailBuffer + for (int i = 1; i < tailBuffer; i++) { + if (pos >= buffers[i].size()) { + pos -= buffers[i].size(); + continue; + } + + length = buffers[i].length() - pos; + return buffers[i].constData() + pos; + } + + // it is in the tail buffer + length = tail - pos; + return buffers[tailBuffer].constData() + pos; + } + + inline void free(int bytes) { + bufferSize -= bytes; + if (bufferSize < 0) + bufferSize = 0; + + for (;;) { + int nextBlockSize = nextDataBlockSize(); + if (bytes < nextBlockSize) { + head += bytes; + if (head == tail && tailBuffer == 0) + head = tail = 0; + break; + } + + bytes -= nextBlockSize; + if (buffers.count() == 1) { + if (buffers.at(0).size() != basicBlockSize) + buffers[0].resize(basicBlockSize); + head = tail = 0; + tailBuffer = 0; + break; + } + + buffers.removeAt(0); + --tailBuffer; + head = 0; + } + + if (isEmpty()) + clear(); // try to minify/squeeze us + } + + inline char *reserve(int bytes) { + // if this is a fresh empty QRingBuffer + if (bufferSize == 0) { + buffers[0].resize(qMax(basicBlockSize, bytes)); + bufferSize += bytes; + tail = bytes; + return buffers[tailBuffer].data(); + } + + bufferSize += bytes; + + // if there is already enough space, simply return. + if (tail + bytes <= buffers.at(tailBuffer).size()) { + char *writePtr = buffers[tailBuffer].data() + tail; + tail += bytes; + return writePtr; + } + + // if our buffer isn't half full yet, simply resize it. + if (tail < buffers.at(tailBuffer).size() / 2) { + buffers[tailBuffer].resize(tail + bytes); + char *writePtr = buffers[tailBuffer].data() + tail; + tail += bytes; + return writePtr; + } + + // shrink this buffer to its current size + buffers[tailBuffer].resize(tail); + + // create a new QByteArray with the right size + buffers << QByteArray(); + ++tailBuffer; + buffers[tailBuffer].resize(qMax(basicBlockSize, bytes)); + tail = bytes; + return buffers[tailBuffer].data(); + } + + inline void truncate(int pos) { + if (pos < size()) + chop(size() - pos); + } + + inline void chop(int bytes) { + bufferSize -= bytes; + if (bufferSize < 0) + bufferSize = 0; + + for (;;) { + // special case: head and tail are in the same buffer + if (tailBuffer == 0) { + tail -= bytes; + if (tail <= head) + tail = head = 0; + return; + } + + if (bytes <= tail) { + tail -= bytes; + return; + } + + bytes -= tail; + buffers.removeAt(tailBuffer); + + --tailBuffer; + tail = buffers.at(tailBuffer).size(); + } + + if (isEmpty()) + clear(); // try to minify/squeeze us + } + + inline bool isEmpty() const { + return tailBuffer == 0 && tail == 0; + } + + inline int getChar() { + if (isEmpty()) + return -1; + char c = *readPointer(); + free(1); + return int(uchar(c)); + } + + inline void putChar(char c) { + char *ptr = reserve(1); + *ptr = c; + } + + inline void ungetChar(char c) { + --head; + if (head < 0) { + buffers.prepend(QByteArray()); + buffers[0].resize(basicBlockSize); + head = basicBlockSize - 1; + ++tailBuffer; + } + buffers[0][head] = c; + ++bufferSize; + } + + inline int size() const { + return bufferSize; + } + + inline void clear() { + buffers.erase(buffers.begin() + 1, buffers.end()); + buffers[0].resize(0); + buffers[0].squeeze(); + + head = tail = 0; + tailBuffer = 0; + bufferSize = 0; + } + + inline int indexOf(char c) const { + int index = 0; + for (int i = 0; i < buffers.size(); ++i) { + int start = 0; + int end = buffers.at(i).size(); + + if (i == 0) + start = head; + if (i == tailBuffer) + end = tail; + const char *ptr = buffers.at(i).data() + start; + for (int j = start; j < end; ++j) { + if (*ptr++ == c) + return index; + ++index; + } + } + return -1; + } + + inline int indexOf(char c, int maxLength) const { + int index = 0; + int remain = qMin(size(), maxLength); + for (int i = 0; remain && i < buffers.size(); ++i) { + int start = 0; + int end = buffers.at(i).size(); + + if (i == 0) + start = head; + if (i == tailBuffer) + end = tail; + if (remain < end - start) { + end = start + remain; + remain = 0; + } else { + remain -= end - start; + } + const char *ptr = buffers.at(i).data() + start; + for (int j = start; j < end; ++j) { + if (*ptr++ == c) + return index; + ++index; + } + } + return -1; + } + + inline int read(char *data, int maxLength) { + int bytesToRead = qMin(size(), maxLength); + int readSoFar = 0; + while (readSoFar < bytesToRead) { + const char *ptr = readPointer(); + int bytesToReadFromThisBlock = qMin(bytesToRead - readSoFar, nextDataBlockSize()); + if (data) + memcpy(data + readSoFar, ptr, bytesToReadFromThisBlock); + readSoFar += bytesToReadFromThisBlock; + free(bytesToReadFromThisBlock); + } + return readSoFar; + } + + inline QByteArray read(int maxLength) { + QByteArray tmp; + tmp.resize(qMin(maxLength, size())); + read(tmp.data(), tmp.size()); + return tmp; + } + + inline QByteArray readAll() { + return read(size()); + } + + // read an unspecified amount (will read the first buffer) + inline QByteArray read() { + if (bufferSize == 0) + return QByteArray(); + + // multiple buffers, just take the first one + if (head == 0 && tailBuffer != 0) { + QByteArray qba = buffers.takeFirst(); + --tailBuffer; + bufferSize -= qba.length(); + return qba; + } + + // one buffer with good value for head. Just take it. + if (head == 0 && tailBuffer == 0) { + QByteArray qba = buffers.takeFirst(); + qba.resize(tail); + buffers << QByteArray(); + bufferSize = 0; + tail = 0; + return qba; + } + + // Bad case: We have to memcpy. + // We can avoid by initializing the QRingBuffer with basicBlockSize of 0 + // and only using this read() function. + QByteArray qba(readPointer(), nextDataBlockSize()); + buffers.removeFirst(); + head = 0; + if (tailBuffer == 0) { + buffers << QByteArray(); + tail = 0; + } else { + --tailBuffer; + } + bufferSize -= qba.length(); + return qba; + } + + // append a new buffer to the end + inline void append(const QByteArray &qba) { + buffers[tailBuffer].resize(tail); + buffers << qba; + ++tailBuffer; + tail = qba.length(); + bufferSize += qba.length(); + } + + inline QByteArray peek(int maxLength) const { + int bytesToRead = qMin(size(), maxLength); + if(maxLength <= 0) + return QByteArray(); + QByteArray ret; + ret.resize(bytesToRead); + int readSoFar = 0; + for (int i = 0; readSoFar < bytesToRead && i < buffers.size(); ++i) { + int start = 0; + int end = buffers.at(i).size(); + if (i == 0) + start = head; + if (i == tailBuffer) + end = tail; + const int len = qMin(ret.size()-readSoFar, end-start); + memcpy(ret.data()+readSoFar, buffers.at(i).constData()+start, len); + readSoFar += len; + } + Q_ASSERT(readSoFar == ret.size()); + return ret; + } + + inline int skip(int length) { + return read(0, length); + } + + inline int readLine(char *data, int maxLength) { + int index = indexOf('\n'); + if (index == -1) + return read(data, maxLength); + if (maxLength <= 0) + return -1; + + int readSoFar = 0; + while (readSoFar < index + 1 && readSoFar < maxLength - 1) { + int bytesToRead = qMin((index + 1) - readSoFar, nextDataBlockSize()); + bytesToRead = qMin(bytesToRead, (maxLength - 1) - readSoFar); + memcpy(data + readSoFar, readPointer(), bytesToRead); + readSoFar += bytesToRead; + free(bytesToRead); + } + + // Terminate it. + data[readSoFar] = '\0'; + return readSoFar; + } + + inline bool canReadLine() const { + return indexOf('\n') != -1; + } + +private: + QList buffers; + int head, tail; + int tailBuffer; // always buffers.size() - 1 + int basicBlockSize; + int bufferSize; +}; + +QT_END_NAMESPACE + +#endif // QRINGBUFFER_P_H Index: plasma/scriptengines/javascript/declarative/private/qobject_p.h =================================================================== --- a/plasma/scriptengines/javascript/declarative/private/qobject_p.h (revision 0) +++ b/plasma/scriptengines/javascript/declarative/private/qobject_p.h (revision 0) @@ -0,0 +1,295 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtCore module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QOBJECT_P_H +#define QOBJECT_P_H + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists for the convenience +// of qapplication_*.cpp, qwidget*.cpp and qfiledialog.cpp. This header +// file may change from version to version without notice, or even be removed. +// +// We mean it. +// + +#include "QtCore/qobject.h" +#include "QtCore/qpointer.h" +#include "QtCore/qcoreevent.h" +#include "QtCore/qlist.h" +#include "QtCore/qvector.h" +#include "QtCore/qreadwritelock.h" +#include "QtCore/qvariant.h" + +QT_BEGIN_NAMESPACE + +class QVariant; +class QThreadData; +class QObjectConnectionListVector; +namespace QtSharedPointer { struct ExternalRefCountData; } + +/* mirrored in QtTestLib, DON'T CHANGE without prior warning */ +struct QSignalSpyCallbackSet +{ + typedef void (*BeginCallback)(QObject *caller, int method_index, void **argv); + typedef void (*EndCallback)(QObject *caller, int method_index); + BeginCallback signal_begin_callback, + slot_begin_callback; + EndCallback signal_end_callback, + slot_end_callback; +}; +void Q_CORE_EXPORT qt_register_signal_spy_callbacks(const QSignalSpyCallbackSet &callback_set); + +extern QSignalSpyCallbackSet Q_CORE_EXPORT qt_signal_spy_callback_set; + +enum { QObjectPrivateVersion = QT_VERSION }; + +class Q_CORE_EXPORT QAbstractDeclarativeData +{ +public: + static void (*destroyed)(QAbstractDeclarativeData *, QObject *); + static void (*parentChanged)(QAbstractDeclarativeData *, QObject *, QObject *); + static void (*objectNameChanged)(QAbstractDeclarativeData *, QObject *); +}; + +class Q_CORE_EXPORT QObjectPrivate : public QObjectData +{ + Q_DECLARE_PUBLIC(QObject) + +public: + struct ExtraData + { + ExtraData() {} +#ifndef QT_NO_USERDATA + QVector userData; +#endif + QList propertyNames; + QList propertyValues; + }; + + struct Connection + { + QObject *sender; + QObject *receiver; + int method; + uint connectionType : 3; // 0 == auto, 1 == direct, 2 == queued, 4 == blocking + QBasicAtomicPointer argumentTypes; + // The next pointer for the singly-linked ConnectionList + Connection *nextConnectionList; + //senders linked list + Connection *next; + Connection **prev; + ~Connection(); + }; + // ConnectionList is a singly-linked list + struct ConnectionList { + ConnectionList() : first(0), last(0) {} + Connection *first; + Connection *last; + }; + + struct Sender + { + QObject *sender; + int signal; + int ref; + }; + + + QObjectPrivate(int version = QObjectPrivateVersion); + virtual ~QObjectPrivate(); + void deleteChildren(); + + void setParent_helper(QObject *); + void moveToThread_helper(); + void setThreadData_helper(QThreadData *currentData, QThreadData *targetData); + void _q_reregisterTimers(void *pointer); + + bool isSender(const QObject *receiver, const char *signal) const; + QObjectList receiverList(const char *signal) const; + QObjectList senderList() const; + + void addConnection(int signal, Connection *c); + void cleanConnectionLists(); + +#ifdef QT3_SUPPORT + void sendPendingChildInsertedEvents(); + void removePendingChildInsertedEvents(QObject *child); +#endif + + static inline Sender *setCurrentSender(QObject *receiver, + Sender *sender); + static inline void resetCurrentSender(QObject *receiver, + Sender *currentSender, + Sender *previousSender); + static int *setDeleteWatch(QObjectPrivate *d, int *newWatch); + static void resetDeleteWatch(QObjectPrivate *d, int *oldWatch, int deleteWatch); + static void clearGuards(QObject *); + + static QObjectPrivate *get(QObject *o) { + return o->d_func(); + } + + int signalIndex(const char *signalName) const; + inline bool isSignalConnected(uint signalIdx) const; + +public: + QString objectName; + ExtraData *extraData; // extra data set by the user + QThreadData *threadData; // id of the thread that owns the object + + QObjectConnectionListVector *connectionLists; + + Connection *senders; // linked list of connections connected to this object + Sender *currentSender; // object currently activating the object + mutable quint32 connectedSignals[2]; + +#ifdef QT3_SUPPORT + QList pendingChildInsertedEvents; +#else + // preserve binary compatibility with code compiled without Qt 3 support + // keeping the binary layout stable helps the Qt Creator debugger + void *unused; +#endif + + QList > eventFilters; + union { + QObject *currentChildBeingDeleted; + QAbstractDeclarativeData *declarativeData; //extra data used by the declarative module + }; + + // these objects are all used to indicate that a QObject was deleted + // plus QPointer, which keeps a separate list + QAtomicPointer sharedRefcount; + int *deleteWatch; +}; + + +/*! \internal + + Returns true if the signal with index \a signal_index from object \a sender is connected. + Signals with indices above a certain range are always considered connected (see connectedSignals + in QObjectPrivate). If a signal spy is installed, all signals are considered connected. + + \a signal_index must be the index returned by QObjectPrivate::signalIndex; +*/ +inline bool QObjectPrivate::isSignalConnected(uint signal_index) const +{ + return signal_index >= sizeof(connectedSignals) * 8 + || (connectedSignals[signal_index >> 5] & (1 << (signal_index & 0x1f)) + || qt_signal_spy_callback_set.signal_begin_callback + || qt_signal_spy_callback_set.signal_end_callback); +} + +inline QObjectPrivate::Sender *QObjectPrivate::setCurrentSender(QObject *receiver, + Sender *sender) +{ + Sender *previousSender = receiver->d_func()->currentSender; + receiver->d_func()->currentSender = sender; + return previousSender; +} + +inline void QObjectPrivate::resetCurrentSender(QObject *receiver, + Sender *currentSender, + Sender *previousSender) +{ + // ref is set to zero when this object is deleted during the metacall + if (currentSender->ref == 1) + receiver->d_func()->currentSender = previousSender; + // if we've recursed, we need to tell the caller about the objects deletion + if (previousSender) + previousSender->ref = currentSender->ref; +} + + +Q_DECLARE_TYPEINFO(QObjectPrivate::Connection, Q_MOVABLE_TYPE); +Q_DECLARE_TYPEINFO(QObjectPrivate::Sender, Q_MOVABLE_TYPE); + +class QSemaphore; +class Q_CORE_EXPORT QMetaCallEvent : public QEvent +{ +public: + QMetaCallEvent(int id, const QObject *sender, int signalId, + int nargs = 0, int *types = 0, void **args = 0, QSemaphore *semaphore = 0); + ~QMetaCallEvent(); + + inline int id() const { return id_; } + inline const QObject *sender() const { return sender_; } + inline int signalId() const { return signalId_; } + inline void **args() const { return args_; } + + virtual int placeMetaCall(QObject *object); + +private: + int id_; + const QObject *sender_; + int signalId_; + int nargs_; + int *types_; + void **args_; + QSemaphore *semaphore_; +}; + +class QBoolBlocker +{ +public: + inline QBoolBlocker(bool &b, bool value=true):block(b), reset(b){block = value;} + inline ~QBoolBlocker(){block = reset; } +private: + bool █ + bool reset; +}; + +void Q_CORE_EXPORT qDeleteInEventHandler(QObject *o); + + +struct Q_CORE_EXPORT QAbstractDynamicMetaObject : public QMetaObject +{ + virtual ~QAbstractDynamicMetaObject() {} + virtual int metaCall(QMetaObject::Call, int _id, void **) { return _id; } + virtual int createProperty(const char *, const char *) { return -1; } +}; + +QT_END_NAMESPACE + +#endif // QOBJECT_P_H Index: plasma/scriptengines/javascript/declarative/private/qiodevice_p.h =================================================================== --- a/plasma/scriptengines/javascript/declarative/private/qiodevice_p.h (revision 0) +++ b/plasma/scriptengines/javascript/declarative/private/qiodevice_p.h (revision 0) @@ -0,0 +1,245 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtCore module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QIODEVICE_P_H +#define QIODEVICE_P_H + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists for the convenience +// of QIODevice. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. +// + +#include "QtCore/qiodevice.h" +#include "QtCore/qbytearray.h" +#include "QtCore/qobjectdefs.h" +#include "QtCore/qstring.h" +#include "qringbuffer_p.h" +#ifndef QT_NO_QOBJECT +#include "qobject_p.h" +#endif + +QT_BEGIN_NAMESPACE + +#ifndef QIODEVICE_BUFFERSIZE +#define QIODEVICE_BUFFERSIZE Q_INT64_C(16384) +#endif + +// This is QIODevice's read buffer, optimized for read(), isEmpty() and getChar() +class QIODevicePrivateLinearBuffer +{ +public: + QIODevicePrivateLinearBuffer(int) : len(0), first(0), buf(0), capacity(0) { + } + ~QIODevicePrivateLinearBuffer() { + delete [] buf; + } + void clear() { + first = buf; + len = 0; + } + int size() const { + return len; + } + bool isEmpty() const { + return len == 0; + } + void skip(int n) { + if (n >= len) { + clear(); + } else { + len -= n; + first += n; + } + } + int getChar() { + if (len == 0) + return -1; + int ch = uchar(*first); + len--; + first++; + return ch; + } + int read(char* target, int size) { + int r = qMin(size, len); + memcpy(target, first, r); + len -= r; + first += r; + return r; + } + char* reserve(int size) { + makeSpace(size + len, freeSpaceAtEnd); + char* writePtr = first + len; + len += size; + return writePtr; + } + void chop(int size) { + if (size >= len) { + clear(); + } else { + len -= size; + } + } + QByteArray readAll() { + char* f = first; + int l = len; + clear(); + return QByteArray(f, l); + } + int readLine(char* target, int size) { + int r = qMin(size, len); + char* eol = static_cast(memchr(first, '\n', r)); + if (eol) + r = 1+(eol-first); + memcpy(target, first, r); + len -= r; + first += r; + return int(r); + } + bool canReadLine() const { + return memchr(first, '\n', len); + } + void ungetChar(char c) { + if (first == buf) { + // underflow, the existing valid data needs to move to the end of the (potentially bigger) buffer + makeSpace(len+1, freeSpaceAtStart); + } + first--; + len++; + *first = c; + } + void ungetBlock(const char* block, int size) { + if ((first - buf) < size) { + // underflow, the existing valid data needs to move to the end of the (potentially bigger) buffer + makeSpace(len + size, freeSpaceAtStart); + } + first -= size; + len += size; + memcpy(first, block, size); + } + +private: + enum FreeSpacePos {freeSpaceAtStart, freeSpaceAtEnd}; + void makeSpace(size_t required, FreeSpacePos where) { + size_t newCapacity = qMax(capacity, size_t(QIODEVICE_BUFFERSIZE)); + while (newCapacity < required) + newCapacity *= 2; + int moveOffset = (where == freeSpaceAtEnd) ? 0 : newCapacity - len; + if (newCapacity > capacity) { + // allocate more space + char* newBuf = new char[newCapacity]; + memmove(newBuf + moveOffset, first, len); + delete [] buf; + buf = newBuf; + capacity = newCapacity; + } else { + // shift any existing data to make space + memmove(buf + moveOffset, first, len); + } + first = buf + moveOffset; + } + +private: + // length of the unread data + int len; + // start of the unread data + char* first; + // the allocated buffer + char* buf; + // allocated buffer size + size_t capacity; +}; + +class Q_CORE_EXPORT QIODevicePrivate +#ifndef QT_NO_QOBJECT + : public QObjectPrivate +#endif +{ + Q_DECLARE_PUBLIC(QIODevice) + +public: + QIODevicePrivate(); + virtual ~QIODevicePrivate(); + + QIODevice::OpenMode openMode; + QString errorString; + + QIODevicePrivateLinearBuffer buffer; + qint64 pos; + qint64 devicePos; + // these three are for fast position updates during read, avoiding isSequential test + qint64 seqDumpPos; + qint64 *pPos; + qint64 *pDevicePos; + bool baseReadLineDataCalled; + bool firstRead; + + virtual bool putCharHelper(char c); + + enum AccessMode { + Unset, + Sequential, + RandomAccess + }; + mutable AccessMode accessMode; + inline bool isSequential() const + { + if (accessMode == Unset) + accessMode = q_func()->isSequential() ? Sequential : RandomAccess; + return accessMode == Sequential; + } + + virtual qint64 peek(char *data, qint64 maxSize); + virtual QByteArray peek(qint64 maxSize); + +#ifdef QT_NO_QOBJECT + QIODevice *q_ptr; +#endif +}; + +QT_END_NAMESPACE + +#endif // QIODEVICE_P_H Index: plasma/scriptengines/javascript/declarative/qfilenetworkreply_p.h =================================================================== --- a/plasma/scriptengines/javascript/declarative/qfilenetworkreply_p.h (revision 0) +++ b/plasma/scriptengines/javascript/declarative/qfilenetworkreply_p.h (revision 0) @@ -0,0 +1,104 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtNetwork module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QFILENETWORKREPLY_P_H +#define QFILENETWORKREPLY_P_H + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists for the convenience +// of the Network Access API. This header file may change from +// version to version without notice, or even be removed. +// +// We mean it. +// + +#include "qnetworkreply.h" +#include "qnetworkreply_p.h" +#include "qnetworkaccessmanager.h" +#include +#include + +QT_BEGIN_NAMESPACE + + +class QFileNetworkReplyPrivate; +class QFileNetworkReply: public QNetworkReply +{ + Q_OBJECT +public: + QFileNetworkReply(QObject *parent, const QNetworkRequest &req, const QNetworkAccessManager::Operation op); + ~QFileNetworkReply(); + virtual void abort(); + + // reimplemented from QNetworkReply + virtual void close(); + virtual qint64 bytesAvailable() const; + virtual bool isSequential () const; + qint64 size() const; + + virtual qint64 readData(char *data, qint64 maxlen); + + void setUrl(const QUrl &url){QNetworkReply::setUrl(url);} + + Q_DECLARE_PRIVATE(QFileNetworkReply) +}; + +class QFileNetworkReplyPrivate: public QNetworkReplyPrivate +{ +public: + QFileNetworkReplyPrivate(); + ~QFileNetworkReplyPrivate(); + + QAbstractFileEngine *fileEngine; + qint64 fileSize; + qint64 filePos; + + virtual bool isFinished() const; + + Q_DECLARE_PUBLIC(QFileNetworkReply) +}; + +QT_END_NAMESPACE + +#endif // QFILENETWORKREPLY_P_H Index: plasma/scriptengines/javascript/declarative/qnetworkreply_p.h =================================================================== --- a/plasma/scriptengines/javascript/declarative/qnetworkreply_p.h (revision 0) +++ b/plasma/scriptengines/javascript/declarative/qnetworkreply_p.h (revision 0) @@ -0,0 +1,85 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtNetwork module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QNETWORKREPLY_P_H +#define QNETWORKREPLY_P_H + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists for the convenience +// of the Network Access API. This header file may change from +// version to version without notice, or even be removed. +// +// We mean it. +// + +#include "qnetworkrequest.h" +#include "qnetworkrequest_p.h" +#include "qnetworkreply.h" +#include "QtCore/qpointer.h" +#include "private/qiodevice_p.h" + +QT_BEGIN_NAMESPACE + +class QNetworkReplyPrivate: public QIODevicePrivate, public QNetworkHeadersPrivate +{ +public: + QNetworkReplyPrivate(); + QNetworkRequest request; + QUrl url; + QPointer manager; + qint64 readBufferMaxSize; + QNetworkAccessManager::Operation operation; + QNetworkReply::NetworkError errorCode; + + static inline void setManager(QNetworkReply *reply, QNetworkAccessManager *manager) + { reply->d_func()->manager = manager; } + + virtual bool isFinished() const { return false; } + + Q_DECLARE_PUBLIC(QNetworkReply) +}; + +QT_END_NAMESPACE + +#endif Index: plasma/scriptengines/javascript/CMakeLists.txt =================================================================== --- a/plasma/scriptengines/javascript/CMakeLists.txt (revision 1216700) +++ b/plasma/scriptengines/javascript/CMakeLists.txt (working copy) @@ -122,6 +122,7 @@ common/javascriptaddonpackagestructure.cpp common/declarativescriptenv.cpp declarative/packageaccessmanager.cpp + declarative/qfilenetworkreply.cpp declarative/packageaccessmanagerfactory.cpp plasmoid/abstractjsappletscript.cpp plasmoid/appletauthorization.cpp Index: plasma/CMakeLists.txt =================================================================== --- a/plasma/CMakeLists.txt (revision 1216700) +++ b/plasma/CMakeLists.txt (working copy) @@ -1,3 +1,25 @@ +find_package(KDE4 4.6.40 REQUIRED) + +# where to look first for cmake modules, before ${CMAKE_ROOT}/Modules/ is +# checked +set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules +${CMAKE_MODULE_PATH}) + +include_directories(/usr/include/qt4 + /usr/include/qt4/QtCore + /usr/include/qt4/QtGui + /usr/include/qt4/QtScript + /usr/include/qt4/QtDeclarative + /usr/include/qt4/QtNetwork + /usr/include/qt4/QtUiTools + /usr/include/KDE) + +set(KDE_MIN_VERSION "4.6.40") # for the < 4.2 macro +include(KDE4Defaults) +include(MacroLibrary) +include(CheckFunctionExists) +include(CheckIncludeFiles) + add_subdirectory(containments) add_subdirectory(declarativeimports) add_subdirectory(kpart)