From 689184792390d539b7024ce800c6442c6a3dc213 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dani=C3=ABl?= Date: Fri, 15 May 2009 05:29:29 +0000 Subject: Memory of fixedKernel is never returned, found by cppcheck. Cherry-picked from d8a2e52e Merge-request: 419 Reviewed-by: Olivier --- src/gui/image/qpixmapfilter.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/gui/image/qpixmapfilter.cpp b/src/gui/image/qpixmapfilter.cpp index 4d143d2..1372189 100644 --- a/src/gui/image/qpixmapfilter.cpp +++ b/src/gui/image/qpixmapfilter.cpp @@ -401,6 +401,7 @@ static void convolute( } yk++; } + delete[] fixedKernel; } /*! -- cgit v0.12 From 30099d68599d23b7e9c39e3f2e23a1bb5c6dd7dc Mon Sep 17 00:00:00 2001 From: Kent Hansen Date: Wed, 28 Oct 2009 17:24:05 +0100 Subject: QStateMachine::event() should call QState::event() Since QStateMachine inherits QState now. Reviewed-by: Eskil Abrahamsen Blomfeldt --- src/corelib/statemachine/qstatemachine.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/corelib/statemachine/qstatemachine.cpp b/src/corelib/statemachine/qstatemachine.cpp index e182c88..154445f 100644 --- a/src/corelib/statemachine/qstatemachine.cpp +++ b/src/corelib/statemachine/qstatemachine.cpp @@ -1974,7 +1974,7 @@ bool QStateMachine::event(QEvent *e) return true; } } - return QObject::event(e); + return QState::event(e); } #ifndef QT_NO_STATEMACHINE_EVENTFILTER -- cgit v0.12 From 093ededb85c73f30ce3abf43bc6da0fff55323c2 Mon Sep 17 00:00:00 2001 From: Kent Hansen Date: Wed, 28 Oct 2009 16:45:46 +0100 Subject: Cache QState's child states This is the same type of optimization as that done for transitions in commit 5d8dcd57cd13fdd9c8643fa3bdda9f197a4351ff. The idea is to avoid calling qobject_cast() because it's very expensive. Obtaining child states needs to be as fast as possible because it's in the critical path of the state machine algorithm; it's called by a ton of internal functions, like isCompound(), isAtomic(), isInFinalState(). It's also called heavily for parallel state groups. Reviewed-by: Eskil Abrahamsen Blomfeldt --- src/corelib/statemachine/qstate.cpp | 25 +++++++++++++++---------- src/corelib/statemachine/qstate_p.h | 2 ++ 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/src/corelib/statemachine/qstate.cpp b/src/corelib/statemachine/qstate.cpp index 9abf20b..bcd8364 100644 --- a/src/corelib/statemachine/qstate.cpp +++ b/src/corelib/statemachine/qstate.cpp @@ -125,7 +125,7 @@ QT_BEGIN_NAMESPACE QStatePrivate::QStatePrivate() : errorState(0), initialState(0), childMode(QState::ExclusiveStates), - transitionsListNeedsRefresh(true) + childStatesListNeedsRefresh(true), transitionsListNeedsRefresh(true) { } @@ -181,15 +181,18 @@ QState::~QState() QList QStatePrivate::childStates() const { - QList result; - QList::const_iterator it; - for (it = children.constBegin(); it != children.constEnd(); ++it) { - QAbstractState *s = qobject_cast(*it); - if (!s || qobject_cast(s)) - continue; - result.append(s); + if (childStatesListNeedsRefresh) { + childStatesList.clear(); + QList::const_iterator it; + for (it = children.constBegin(); it != children.constEnd(); ++it) { + QAbstractState *s = qobject_cast(*it); + if (!s || qobject_cast(s)) + continue; + childStatesList.append(s); + } + childStatesListNeedsRefresh = false; } - return result; + return childStatesList; } QList QStatePrivate::historyStates() const @@ -473,8 +476,10 @@ void QState::setChildMode(ChildMode mode) bool QState::event(QEvent *e) { Q_D(QState); - if ((e->type() == QEvent::ChildAdded) || (e->type() == QEvent::ChildRemoved)) + if ((e->type() == QEvent::ChildAdded) || (e->type() == QEvent::ChildRemoved)) { + d->childStatesListNeedsRefresh = true; d->transitionsListNeedsRefresh = true; + } return QAbstractState::event(e); } diff --git a/src/corelib/statemachine/qstate_p.h b/src/corelib/statemachine/qstate_p.h index 3b5f416..34c8838 100644 --- a/src/corelib/statemachine/qstate_p.h +++ b/src/corelib/statemachine/qstate_p.h @@ -99,6 +99,8 @@ public: QAbstractState *errorState; QAbstractState *initialState; QState::ChildMode childMode; + mutable bool childStatesListNeedsRefresh; + mutable QList childStatesList; mutable bool transitionsListNeedsRefresh; mutable QList transitionsList; -- cgit v0.12 From 414d5550f9ffe46faf1ee81b1a364683f2b2f066 Mon Sep 17 00:00:00 2001 From: Kent Hansen Date: Wed, 28 Oct 2009 18:21:05 +0100 Subject: Test that we gracefully handle event posting after the state machine is stopped The internal slot _q_process() should never be called if the machine is not in the Running state. --- tests/auto/qstatemachine/tst_qstatemachine.cpp | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/tests/auto/qstatemachine/tst_qstatemachine.cpp b/tests/auto/qstatemachine/tst_qstatemachine.cpp index 1516346..346afc9 100644 --- a/tests/auto/qstatemachine/tst_qstatemachine.cpp +++ b/tests/auto/qstatemachine/tst_qstatemachine.cpp @@ -124,6 +124,7 @@ private slots: void postEvent(); void cancelDelayedEvent(); void postDelayedEventAndStop(); + void stopAndPostEvent(); void stateFinished(); void parallelStates(); void parallelRootState(); @@ -1681,6 +1682,22 @@ void tst_QStateMachine::postDelayedEventAndStop() QVERIFY(machine.configuration().contains(s1)); } +void tst_QStateMachine::stopAndPostEvent() +{ + QStateMachine machine; + QState *s1 = new QState(&machine); + machine.setInitialState(s1); + QSignalSpy startedSpy(&machine, SIGNAL(started())); + machine.start(); + QTRY_COMPARE(startedSpy.count(), 1); + QSignalSpy stoppedSpy(&machine, SIGNAL(stopped())); + machine.stop(); + QCOMPARE(stoppedSpy.count(), 0); + machine.postEvent(new QEvent(QEvent::User)); + QTRY_COMPARE(stoppedSpy.count(), 1); + QCoreApplication::processEvents(); +} + void tst_QStateMachine::stateFinished() { QStateMachine machine; -- cgit v0.12 From c3968d0981fd29764e3c665903f4c8db53cc1af3 Mon Sep 17 00:00:00 2001 From: Kent Hansen Date: Wed, 28 Oct 2009 18:05:50 +0100 Subject: Make QStateMachine event posting functions thread-safe By popular demand on the Qt Labs blog. This makes it possible to readily use QStateMachine with e.g. worker threads that post events to the machine. Reviewed-by: Eskil Abrahamsen Blomfeldt --- src/corelib/statemachine/qstatemachine.cpp | 89 +++++++++++++++++++++----- src/corelib/statemachine/qstatemachine_p.h | 11 ++++ tests/auto/qstatemachine/tst_qstatemachine.cpp | 48 ++++++++++++++ 3 files changed, 131 insertions(+), 17 deletions(-) diff --git a/src/corelib/statemachine/qstatemachine.cpp b/src/corelib/statemachine/qstatemachine.cpp index 154445f..45b0286 100644 --- a/src/corelib/statemachine/qstatemachine.cpp +++ b/src/corelib/statemachine/qstatemachine.cpp @@ -1216,8 +1216,7 @@ void QStateMachinePrivate::_q_process() delete e; e = 0; } - if (enabledTransitions.isEmpty() && !internalEventQueue.isEmpty()) { - e = internalEventQueue.takeFirst(); + if (enabledTransitions.isEmpty() && ((e = dequeueInternalEvent()) != 0)) { #ifdef QSTATEMACHINE_DEBUG qDebug() << q << ": dequeued internal event" << e << "of type" << e->type(); #endif @@ -1228,13 +1227,7 @@ void QStateMachinePrivate::_q_process() } } if (enabledTransitions.isEmpty()) { - if (externalEventQueue.isEmpty()) { - if (internalEventQueue.isEmpty()) { - processing = false; - stopProcessingReason = EventQueueEmpty; - } - } else { - e = externalEventQueue.takeFirst(); + if ((e = dequeueExternalEvent()) != 0) { #ifdef QSTATEMACHINE_DEBUG qDebug() << q << ": dequeued external event" << e << "of type" << e->type(); #endif @@ -1243,6 +1236,11 @@ void QStateMachinePrivate::_q_process() delete e; e = 0; } + } else { + if (isInternalEventQueueEmpty()) { + processing = false; + stopProcessingReason = EventQueueEmpty; + } } } if (!enabledTransitions.isEmpty()) { @@ -1278,17 +1276,60 @@ void QStateMachinePrivate::_q_process() } } +void QStateMachinePrivate::postInternalEvent(QEvent *e) +{ + QMutexLocker locker(&internalEventMutex); + internalEventQueue.append(e); +} + +void QStateMachinePrivate::postExternalEvent(QEvent *e) +{ + QMutexLocker locker(&externalEventMutex); + externalEventQueue.append(e); +} + +QEvent *QStateMachinePrivate::dequeueInternalEvent() +{ + QMutexLocker locker(&internalEventMutex); + if (internalEventQueue.isEmpty()) + return 0; + return internalEventQueue.takeFirst(); +} + +QEvent *QStateMachinePrivate::dequeueExternalEvent() +{ + QMutexLocker locker(&externalEventMutex); + if (externalEventQueue.isEmpty()) + return 0; + return externalEventQueue.takeFirst(); +} + +bool QStateMachinePrivate::isInternalEventQueueEmpty() +{ + QMutexLocker locker(&internalEventMutex); + return internalEventQueue.isEmpty(); +} + +bool QStateMachinePrivate::isExternalEventQueueEmpty() +{ + QMutexLocker locker(&externalEventMutex); + return externalEventQueue.isEmpty(); +} + void QStateMachinePrivate::processEvents(EventProcessingMode processingMode) { + Q_Q(QStateMachine); if ((state != Running) || processing || processingScheduled) return; switch (processingMode) { case DirectProcessing: - _q_process(); - break; + if (QThread::currentThread() == q->thread()) { + _q_process(); + break; + } // fallthrough -- processing must be done in the machine thread case QueuedProcessing: processingScheduled = true; - QMetaObject::invokeMethod(q_func(), "_q_process", Qt::QueuedConnection); + QMetaObject::invokeMethod(q, "_q_process", Qt::QueuedConnection); break; } } @@ -1296,6 +1337,7 @@ void QStateMachinePrivate::processEvents(EventProcessingMode processingMode) void QStateMachinePrivate::cancelAllDelayedEvents() { Q_Q(QStateMachine); + QMutexLocker locker(&delayedEventsMutex); QHash::const_iterator it; for (it = delayedEvents.constBegin(); it != delayedEvents.constEnd(); ++it) { int id = it.key(); @@ -1547,7 +1589,7 @@ void QStateMachinePrivate::handleFilteredEvent(QObject *watched, QEvent *event) { Q_ASSERT(qobjectEvents.contains(watched)); if (qobjectEvents[watched].contains(event->type())) { - internalEventQueue.append(new QStateMachine::WrappedEvent(watched, handler->cloneEvent(event))); + postInternalEvent(new QStateMachine::WrappedEvent(watched, handler->cloneEvent(event))); processEvents(DirectProcessing); } } @@ -1571,7 +1613,7 @@ void QStateMachinePrivate::handleTransitionSignal(QObject *sender, int signalInd qDebug() << q_func() << ": sending signal event ( sender =" << sender << ", signal =" << sender->metaObject()->method(signalIndex).signature() << ')'; #endif - internalEventQueue.append(new QStateMachine::SignalEvent(sender, signalIndex, vargs)); + postInternalEvent(new QStateMachine::SignalEvent(sender, signalIndex, vargs)); processEvents(DirectProcessing); } @@ -1825,6 +1867,8 @@ void QStateMachine::stop() } /*! + \threadsafe + Posts the given \a event of the given \a priority for processing by this state machine. @@ -1852,16 +1896,18 @@ void QStateMachine::postEvent(QEvent *event, EventPriority priority) #endif switch (priority) { case NormalPriority: - d->externalEventQueue.append(event); + d->postExternalEvent(event); break; case HighPriority: - d->internalEventQueue.append(event); + d->postInternalEvent(event); break; } d->processEvents(QStateMachinePrivate::QueuedProcessing); } /*! + \threadsafe + Posts the given \a event for processing by this state machine, with the given \a delay in milliseconds. Returns an identifier associated with the delayed event, or -1 if the event could not be posted. @@ -1893,12 +1939,15 @@ int QStateMachine::postDelayedEvent(QEvent *event, int delay) #ifdef QSTATEMACHINE_DEBUG qDebug() << this << ": posting event" << event << "with delay" << delay; #endif + QMutexLocker locker(&d->delayedEventsMutex); int tid = startTimer(delay); d->delayedEvents[tid] = event; return tid; } /*! + \threadsafe + Cancels the delayed event identified by the given \a id. The id should be a value returned by a call to postDelayedEvent(). Returns true if the event was successfully cancelled, otherwise returns false. @@ -1912,6 +1961,7 @@ bool QStateMachine::cancelDelayedEvent(int id) qWarning("QStateMachine::cancelDelayedEvent: the machine is not running"); return false; } + QMutexLocker locker(&d->delayedEventsMutex); QEvent *e = d->delayedEvents.take(id); if (!e) return false; @@ -1963,15 +2013,20 @@ bool QStateMachine::event(QEvent *e) int tid = te->timerId(); if (d->state != QStateMachinePrivate::Running) { // This event has been cancelled already + QMutexLocker locker(&d->delayedEventsMutex); Q_ASSERT(!d->delayedEvents.contains(tid)); return true; } + d->delayedEventsMutex.lock(); QEvent *ee = d->delayedEvents.take(tid); if (ee != 0) { killTimer(tid); - d->externalEventQueue.append(ee); + d->delayedEventsMutex.unlock(); + d->postExternalEvent(ee); d->processEvents(QStateMachinePrivate::DirectProcessing); return true; + } else { + d->delayedEventsMutex.unlock(); } } return QState::event(e); diff --git a/src/corelib/statemachine/qstatemachine_p.h b/src/corelib/statemachine/qstatemachine_p.h index cf7a073..69b727d 100644 --- a/src/corelib/statemachine/qstatemachine_p.h +++ b/src/corelib/statemachine/qstatemachine_p.h @@ -58,6 +58,7 @@ #include #include #include +#include #include #include #include @@ -159,6 +160,13 @@ public: void unregisterAllTransitions(); void handleTransitionSignal(QObject *sender, int signalIndex, void **args); + + void postInternalEvent(QEvent *e); + void postExternalEvent(QEvent *e); + QEvent *dequeueInternalEvent(); + QEvent *dequeueExternalEvent(); + bool isInternalEventQueueEmpty(); + bool isExternalEventQueueEmpty(); void processEvents(EventProcessingMode processingMode); void cancelAllDelayedEvents(); @@ -181,6 +189,8 @@ public: QSet configuration; QList internalEventQueue; QList externalEventQueue; + QMutex internalEventMutex; + QMutex externalEventMutex; QStateMachine::Error error; QStateMachine::RestorePolicy globalRestorePolicy; @@ -214,6 +224,7 @@ public: QHash > qobjectEvents; #endif QHash delayedEvents; + QMutex delayedEventsMutex; typedef QEvent* (*f_cloneEvent)(QEvent*); struct Handler { diff --git a/tests/auto/qstatemachine/tst_qstatemachine.cpp b/tests/auto/qstatemachine/tst_qstatemachine.cpp index 346afc9..97057c6 100644 --- a/tests/auto/qstatemachine/tst_qstatemachine.cpp +++ b/tests/auto/qstatemachine/tst_qstatemachine.cpp @@ -206,6 +206,7 @@ private slots: void goToState(); void task260403_clonedSignals(); + void postEventFromOtherThread(); }; tst_QStateMachine::tst_QStateMachine() @@ -4205,5 +4206,52 @@ void tst_QStateMachine::task260403_clonedSignals() QCOMPARE(t1->eventSignalIndex, emitter.metaObject()->indexOfSignal("signalWithDefaultArg()")); } +class EventPosterThread : public QThread +{ + Q_OBJECT +public: + EventPosterThread(QStateMachine *machine, QObject *parent = 0) + : QThread(parent), m_machine(machine), m_count(0) + { + moveToThread(this); + QObject::connect(m_machine, SIGNAL(started()), + this, SLOT(postEvent())); + } +protected: + virtual void run() + { + exec(); + } +private Q_SLOTS: + void postEvent() + { + m_machine->postEvent(new QEvent(QEvent::User)); + if (++m_count < 10000) + QTimer::singleShot(0, this, SLOT(postEvent())); + else + quit(); + } +private: + QStateMachine *m_machine; + int m_count; +}; + +void tst_QStateMachine::postEventFromOtherThread() +{ + QStateMachine machine; + EventPosterThread poster(&machine); + StringEventPoster *s1 = new StringEventPoster("foo", &machine); + s1->addTransition(new EventTransition(QEvent::User, s1)); + QFinalState *f = new QFinalState(&machine); + s1->addTransition(&poster, SIGNAL(finished()), f); + machine.setInitialState(s1); + + poster.start(); + + QSignalSpy finishedSpy(&machine, SIGNAL(finished())); + machine.start(); + QTRY_COMPARE(finishedSpy.count(), 1); +} + QTEST_MAIN(tst_QStateMachine) #include "tst_qstatemachine.moc" -- cgit v0.12 From c3b4522259bbbe216b31cd66ec6ce26d68847823 Mon Sep 17 00:00:00 2001 From: Kent Hansen Date: Thu, 29 Oct 2009 10:49:52 +0100 Subject: doc: Remove \internal tag from QStateMachine::configuration() This function is useful for debugging, if nothing else, and has been requested by users. We also refer to it in one of our blog posts, so there's little point in trying to hide it any longer. Reviewed-by: Eskil Abrahamsen Blomfeldt --- src/corelib/statemachine/qstatemachine.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/corelib/statemachine/qstatemachine.cpp b/src/corelib/statemachine/qstatemachine.cpp index 45b0286..689967a 100644 --- a/src/corelib/statemachine/qstatemachine.cpp +++ b/src/corelib/statemachine/qstatemachine.cpp @@ -1971,8 +1971,6 @@ bool QStateMachine::cancelDelayedEvent(int id) } /*! - \internal - Returns the maximal consistent set of states (including parallel and final states) that this state machine is currently in. If a state \c s is in the configuration, it is always the case that the parent of \c s is also in -- cgit v0.12 From 84c250448f8b1a3adee4dcaf2fc8edb282dda225 Mon Sep 17 00:00:00 2001 From: Kent Hansen Date: Thu, 29 Oct 2009 13:32:50 +0100 Subject: Cache a state's parent state QAbstractState::parentState() is called heavily by the state machine algorithm. The parent state is obtained by qobject_cast'ing QObject::parent(). qobject_cast() is expensive. This commit introduces caching of the result in order to improve performance. We expect that the cache won't be invalidated much since the parent-child relationship of states usually doesn't change after the state machine is started. Reviewed-by: Eskil Abrahamsen Blomfeldt --- src/corelib/statemachine/qabstractstate.cpp | 8 ++++++-- src/corelib/statemachine/qabstractstate_p.h | 2 ++ tests/auto/qstatemachine/tst_qstatemachine.cpp | 9 +++++++++ 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/src/corelib/statemachine/qabstractstate.cpp b/src/corelib/statemachine/qabstractstate.cpp index 72d640b..cf67cdd 100644 --- a/src/corelib/statemachine/qabstractstate.cpp +++ b/src/corelib/statemachine/qabstractstate.cpp @@ -78,7 +78,8 @@ QT_BEGIN_NAMESPACE function to perform custom processing when the state is exited. */ -QAbstractStatePrivate::QAbstractStatePrivate() +QAbstractStatePrivate::QAbstractStatePrivate() + : parentState(0) { } @@ -150,7 +151,10 @@ QAbstractState::~QAbstractState() */ QState *QAbstractState::parentState() const { - return qobject_cast(parent()); + Q_D(const QAbstractState); + if (d->parentState != parent()) + d->parentState = qobject_cast(parent()); + return d->parentState; } /*! diff --git a/src/corelib/statemachine/qabstractstate_p.h b/src/corelib/statemachine/qabstractstate_p.h index 4b1306d..cd57815 100644 --- a/src/corelib/statemachine/qabstractstate_p.h +++ b/src/corelib/statemachine/qabstractstate_p.h @@ -76,6 +76,8 @@ public: void emitEntered(); void emitExited(); + + mutable QState *parentState; }; QT_END_NAMESPACE diff --git a/tests/auto/qstatemachine/tst_qstatemachine.cpp b/tests/auto/qstatemachine/tst_qstatemachine.cpp index 97057c6..975b301 100644 --- a/tests/auto/qstatemachine/tst_qstatemachine.cpp +++ b/tests/auto/qstatemachine/tst_qstatemachine.cpp @@ -117,6 +117,7 @@ private slots: void cleanup(); void rootState(); + void machineWithParent(); void addAndRemoveState(); void stateEntryAndExit(); void assignProperty(); @@ -1045,6 +1046,14 @@ void tst_QStateMachine::rootState() QCOMPARE(s2->parentState(), static_cast(&machine)); } +void tst_QStateMachine::machineWithParent() +{ + QObject object; + QStateMachine *machine = new QStateMachine(&object); + QCOMPARE(machine->parent(), &object); + QCOMPARE(machine->parentState(), (QObject*)0); +} + void tst_QStateMachine::addAndRemoveState() { #ifdef QT_BUILD_INTERNAL -- cgit v0.12 From 4df10827546faafc3558bbe3c255e5cdab1984e5 Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Fri, 25 Sep 2009 16:49:50 +0200 Subject: Readd the Qt Evaluation timebomb, step 1. This is the QtCore part of the timebomb. Reviewed-by: Daniel Molkentin --- src/corelib/corelib.pro | 2 +- src/corelib/eval.pri | 2 + src/corelib/global/qlibraryinfo.cpp | 11 + src/corelib/global/qlibraryinfo.h | 2 + src/corelib/kernel/qtcore_eval.cpp | 569 ++++++++++++++++++++++++++++++++++++ 5 files changed, 585 insertions(+), 1 deletion(-) create mode 100644 src/corelib/eval.pri create mode 100644 src/corelib/kernel/qtcore_eval.cpp diff --git a/src/corelib/corelib.pro b/src/corelib/corelib.pro index f835bee..9a15bf1 100644 --- a/src/corelib/corelib.pro +++ b/src/corelib/corelib.pro @@ -35,4 +35,4 @@ symbian: { # Workaroud for problems with paging this dll MMP_RULES -= PAGED MMP_RULES *= UNPAGED -} \ No newline at end of file +} diff --git a/src/corelib/eval.pri b/src/corelib/eval.pri new file mode 100644 index 0000000..d50580b --- /dev/null +++ b/src/corelib/eval.pri @@ -0,0 +1,2 @@ +SOURCES += \ + $$QT_SOURCE_TREE/src/corelib/kernel/qtcore_eval.cpp \ diff --git a/src/corelib/global/qlibraryinfo.cpp b/src/corelib/global/qlibraryinfo.cpp index e227403..17273e9 100644 --- a/src/corelib/global/qlibraryinfo.cpp +++ b/src/corelib/global/qlibraryinfo.cpp @@ -208,6 +208,17 @@ QLibraryInfo::buildKey() } /*! + \since 4.6 + Returns the installation date for this build of Qt. The install date will + usually be the last time that Qt sources were configured. +*/ +QDate +QLibraryInfo::buildDate() +{ + return QDate::fromString(QString::fromLatin1(qt_configure_installation + 12), Qt::ISODate); +} + +/*! Returns the location specified by \a loc. */ diff --git a/src/corelib/global/qlibraryinfo.h b/src/corelib/global/qlibraryinfo.h index 3195777..88e8566 100644 --- a/src/corelib/global/qlibraryinfo.h +++ b/src/corelib/global/qlibraryinfo.h @@ -43,6 +43,7 @@ #define QLIBRARYINFO_H #include +#include QT_BEGIN_HEADER @@ -59,6 +60,7 @@ public: static QString licensedProducts(); static QString buildKey(); + static QDate buildDate(); enum LibraryLocation { diff --git a/src/corelib/kernel/qtcore_eval.cpp b/src/corelib/kernel/qtcore_eval.cpp new file mode 100644 index 0000000..0e18691 --- /dev/null +++ b/src/corelib/kernel/qtcore_eval.cpp @@ -0,0 +1,569 @@ +/**************************************************************************** +** +** Copyright (C) 2009 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$ +** +****************************************************************************/ + +#include +#include +#include +#include +#include + +#include "stdio.h" +#include "stdlib.h" + +QT_BEGIN_NAMESPACE + +static const char boilerplate_unsuported[] = + "\nQt %1 Evaluation License\n" + "Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).\n" + "All rights reserved.\n\n" + "This trial version may only be used for evaluation purposes\n" + "and will shut down after 120 minutes.\n" + "Registered to:\n" + " Licensee: %2\n\n" + "The evaluation expires in %4 days\n\n" + "Contact http://qt.nokia.com/about/contact-us for pricing and purchasing information.\n"; + +static const char boilerplate_supported[] = + "\nQt %1 Evaluation License\n" + "Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).\n" + "All rights reserved.\n\n" + "This trial version may only be used for evaluation purposes\n" + "Registered to:\n" + " Licensee: %2\n\n" + "The evaluation expires in %4 days\n\n" + "Contact http://qt.nokia.com/about/contact-us for pricing and purchasing information.\n"; + +static const char boilerplate_expired[] = + "This software is using the trial version of the Qt GUI toolkit.\n" + "The trial period has expired. If you need more time to\n" + "evaluate Qt, or if you have any questions about Qt, contact us\n" + "at: http://qt.nokia.com/about/contact-us.\n\n"; + +static const char will_shutdown_1min[] = + "\nThe evaluation of Qt will SHUT DOWN in 1 minute.\n" + "Contact http://qt.nokia.com/about/contact-us for pricing and purchasing information.\n"; + +static const char will_shutdown_now[] = + "\nThe evaluation of Qt has now reached its automatic\n" + "timeout and will shut down.\n" + "Contact http://qt.nokia.com/about/contact-us for pricing and purchasing information.\n"; + +extern const char qt_eval_key_data[]; + +static int qt_eval_days_left() +{ + const char *const license_key = qt_eval_key_data + 12; + + // fast fail + if (!qt_eval_key_data[0] || !*license_key) + return -2; + + QDate today = QDate::currentDate(); + QDate build = QLibraryInfo::buildDate(); + return qMax(-1, today.daysTo(build) + 30); +} + +static int qt_eval_is_supported() +{ + const char *const license_key = qt_eval_key_data + 12; + if (!qt_eval_key_data[0] || !*license_key) + return -1; + + // is this an unsupported evaluation? + const char* typecode = license_key; + int field = 2; + for ( ; field && *typecode; ++typecode) + if (*typecode == '-') + --field; + + if (!field && typecode[1] == '4' && typecode[2] == 'M') { + if (typecode[0] == 'Q') + return 0; + else if (typecode[0] == 'R' || typecode[0] == 'Z') + return 1; + } + return -1; +} + +static QString qt_eval_string() +{ + const char *msg; + switch (qt_eval_is_supported()) { + case 0: + msg = boilerplate_unsuported; + break; + case 1: + msg = boilerplate_supported; + break; + default: + return QString(); + msg = 0; + } + + return QString::fromLatin1(msg) + .arg(QLatin1String(QT_VERSION_STR)) + .arg(QLibraryInfo::licensee()) + .arg(qt_eval_days_left()); +} + +#define WARN_TIMEOUT 60 * 1000 * 119 +#define KILL_DELAY 60 * 1000 * 1 + +class QCoreFuriCuri : public QObject +{ +public: + + int warn; + int kill; + + QCoreFuriCuri() : QObject(), warn(-1), kill(-1) + { + if (!qt_eval_is_supported()) { + warn = startTimer(WARN_TIMEOUT); + kill = 0; + } + } + + void timerEvent(QTimerEvent *e) { + if (e->timerId() == warn) { + killTimer(warn); + fprintf(stderr, "%s\n", will_shutdown_1min); + kill = startTimer(KILL_DELAY); + } else if (e->timerId() == kill) { + fprintf(stderr, "%s\n", will_shutdown_now); + QCoreApplication::instance()->quit(); + } + } +}; + +#if defined(QT_BUILD_CORE_LIB) || defined (QT_BOOTSTRAPPED) + +void qt_core_eval_init(uint type) +{ + switch (qt_eval_days_left()) { + case -2: + return; + + case -1: + fprintf(stderr, "%s\n", boilerplate_expired); + if (type == 0) { + // if we're a console app only. + exit(0); + } + + default: + fprintf(stderr, "%s\n", qPrintable(qt_eval_string())); + if (type == 0) { + Q_UNUSED(new QCoreFuriCuri()); + } + } +} +#endif + +#ifdef QT_BUILD_GUI_LIB + +QT_BEGIN_INCLUDE_NAMESPACE +#include +#include +#include +#include +#include +#include +#include +QT_END_INCLUDE_NAMESPACE + + +static const char * const qtlogo_eval_xpm[] = { +/* columns rows colors chars-per-pixel */ +"46 55 174 2", +" c #002E02", +". c #00370D", +"X c #003A0E", +"o c #003710", +"O c #013C13", +"+ c #043E1A", +"@ c #084F0A", +"# c #0B520C", +"$ c #054413", +"% c #0C4C17", +"& c #07421D", +"* c #09451D", +"= c #0D491E", +"- c #125515", +"; c #13541A", +": c #17591B", +"> c #1B5C1D", +", c #1F611F", +"< c #20621E", +"1 c #337B1E", +"2 c #0B4521", +"3 c #0F4923", +"4 c #114B24", +"5 c #154D2A", +"6 c #175323", +"7 c #1C5924", +"8 c #1C532F", +"9 c #1E5432", +"0 c #245936", +"q c #265938", +"w c #295C3B", +"e c #246324", +"r c #266823", +"t c #2A6C24", +"y c #276628", +"u c #2D7026", +"i c #327427", +"p c #367927", +"a c #37782A", +"s c #397C2A", +"d c #2E613E", +"f c #336C37", +"g c #2F6040", +"h c #356545", +"j c #3C6B4E", +"k c #3F6C51", +"l c #406E4F", +"z c #406D52", +"x c #477457", +"c c #497557", +"v c #4B7857", +"b c #517B5E", +"n c #3C8423", +"m c #3E812C", +"M c #53A61D", +"N c #41862C", +"B c #458A2D", +"V c #498F2D", +"C c #479324", +"Z c #489226", +"A c #4D952C", +"S c #478B30", +"D c #488C30", +"F c #4D9232", +"G c #509632", +"H c #549A33", +"J c #589F35", +"K c #56A526", +"L c #57A821", +"P c #5BAA27", +"I c #57A32A", +"U c #5CA72E", +"Y c #5DAB2A", +"T c #5CA336", +"R c #60AD2E", +"E c #63B12D", +"W c #65AF35", +"Q c #62A53F", +"! c #65AE39", +"~ c #66B036", +"^ c #6AB437", +"/ c #67B138", +"( c #6AB339", +") c #6DB838", +"_ c #70BA3C", +"` c #4D8545", +"' c #4E8942", +"] c #548851", +"[ c #6FAF4A", +"{ c #6DB243", +"} c #71B546", +"| c #70B840", +" . c #73B648", +".. c #79BA4E", +"X. c #7CBB53", +"o. c #598266", +"O. c #62886D", +"+. c #6A8F75", +"@. c #6B9173", +"#. c #70937A", +"$. c #799F79", +"%. c #7BAF66", +"&. c #81BD5B", +"*. c #85BF60", +"=. c #85AC7F", +"-. c #8DBA7B", +";. c #87C061", +":. c #8AC364", +">. c #8DC46A", +",. c #90C56E", +"<. c #93C771", +"1. c #96CA73", +"2. c #9ACB7C", +"3. c #9FD07D", +"4. c #779981", +"5. c #7F9F89", +"6. c #809F88", +"7. c #82A18B", +"8. c #86A192", +"9. c #8DA994", +"0. c #8FA998", +"q. c #94AF9B", +"w. c #97B991", +"e. c #97B19E", +"r. c #9DB6A3", +"t. c #A3BCA7", +"y. c #A6BCAB", +"u. c #A9BEB1", +"i. c #9ECD81", +"p. c #A2CF85", +"a. c #A5D284", +"s. c #A6D189", +"d. c #A9D28E", +"f. c #ABD491", +"g. c #B1D797", +"h. c #B1D699", +"j. c #B5D89E", +"k. c #ADC5AC", +"l. c #B1CAAE", +"z. c #B9DAA3", +"x. c #BDDDA8", +"c. c #ADC1B4", +"v. c #B2C6B6", +"b. c #B5C6BC", +"n. c #B6C9BA", +"m. c #BCD1BA", +"M. c #C6E1B4", +"N. c #CDE5BD", +"B. c #C2D2C6", +"V. c #CADEC2", +"C. c #C6D3CC", +"Z. c #C8D7CB", +"A. c #CEDAD2", +"S. c #D2DDD4", +"D. c #D3E9C6", +"F. c #D7EBC9", +"G. c #D9EBCD", +"H. c #DEEED4", +"J. c #D6E0D9", +"K. c #DAE4DC", +"L. c #E0EFD7", +"P. c #E5F2DD", +"I. c #DFE8E0", +"U. c #E4EBE5", +"Y. c #E9EFEA", +"T. c #EDF4EB", +"R. c #F0FAE6", +"E. c #F1F8EC", +"W. c #EDF0F0", +"Q. c #F4F7F3", +"!. c #F6F9F4", +"~. c #F8FAF7", +"^. c #FEFEFE", +"/. c None", +/* pixels */ +"/././././.c h ' Q / W _ &.p././././././././././././././././././././././././././././././././.", +"/././.4 O % Z ~ ~ W ~ W R U R R ( X.>.p././././././././././././././././././././././././././.", +"/./.. * = J _ ~ ~ ~ ~ ~ / / / / W W U P P U W .;.2././././././././././././././././././././.", +"/.= = & a ) W ~ ~ ~ ~ ~ / W / ~ ~ ~ ^ ( ( ^ ~ R R U P Y ~ .;.2././././././././././././././.", +"O.O = = T ^ W ~ ~ ~ ~ ~ ~ W W / W ~ ~ ~ ~ ~ ~ ~ ( ( ( ( ~ W Y Y Y Y W { &.1././././././././.", +"0 = * 7 ~ ~ ~ ~ ~ ~ ~ ~ ~ / / W ~ ~ ~ ~ ~ ~ ~ ~ W W W ~ ~ ~ ~ ( ( ( W W R U P U W { X.1.f./.", +"= = & e ^ W ~ ~ ~ ~ ~ ~ ~ ~ / / ~ ~ ~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~ ~ ~ ~ ~ ~ ~ ~ ~ ~ W / ) ^ R Y W W ~ ~ ( / ( / W R Y Y U R ( X.,././././.", +"= = * e ( / ~ / ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ W W W ! ( ( ( W W E U P Y W ( X.,.d./././././././././.", +"= = * e ( W ~ ~ ~ ~ W ! ~ W ~ W ~ ( ( / ^ W W U Y P W ( X.,.d./././././././././././././././.", +"8 $ * e ( W ~ ~ ~ ! ( ( ( / ( W R Y Y Y R ( X.>.d./././././././././././././././././././././.", +"/.d . y ^ / / / ( W Y Y P P W ( X.>.d./././././././././././././././././././././././././././.", +"/./.h : ^ R R R W ( X.<.f./././././././././././././././././././././././././././././././././.", +"/././.] _ *.3./././././././././././././././././././././././././././././././././././././././." +}; + +class EvalMessageBox : public QDialog +{ +public: + EvalMessageBox(bool expired) + { + setWindowTitle(" "); + + QString str = qt_eval_string(); + if (expired) { + str = QLatin1String(boilerplate_expired); + } else { + str = qt_eval_string(); + } + str = str.trimmed(); + + QFrame *border = new QFrame(this); + + QLabel *pixmap_label = new QLabel(border); + pixmap_label->setPixmap(qtlogo_eval_xpm); + pixmap_label->setAlignment(Qt::AlignTop); + + QLabel *text_label = new QLabel(str, border); + + QHBoxLayout *pm_and_text_layout = new QHBoxLayout(); + pm_and_text_layout->addWidget(pixmap_label); + pm_and_text_layout->addWidget(text_label); + + QVBoxLayout *master_layout = new QVBoxLayout(border); + master_layout->addLayout(pm_and_text_layout); + + QVBoxLayout *border_layout = new QVBoxLayout(this); + border_layout->setMargin(0); + border_layout->addWidget(border); + + if (expired) { + QPushButton *cmd = new QPushButton("OK", border); + cmd->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); + cmd->setDefault(true); + + QHBoxLayout *button_layout = new QHBoxLayout(); + master_layout->addLayout(button_layout); + button_layout->addWidget(cmd); + + connect(cmd, SIGNAL(clicked()), this, SLOT(close())); + } else { + border->setFrameShape(QFrame::WinPanel); + border->setFrameShadow(QFrame::Raised); + setParent(parentWidget(), Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint); + QTimer::singleShot(7000, this, SLOT(close())); + setAttribute(Qt::WA_DeleteOnClose); + } + + setFixedSize(sizeHint()); + } +}; + +class QGuiFuriCuri : public QCoreFuriCuri +{ +public: + void timerEvent(QTimerEvent *e) { + if (e->timerId() == warn) { + killTimer(warn); + QMessageBox::information(0, "Automatic Timeout", will_shutdown_1min); + kill = startTimer(KILL_DELAY); + } else if (e->timerId() == kill) { + killTimer(kill); + QMessageBox::information(0, "Automatic Timeout", will_shutdown_now); + qApp->quit(); + } + } +}; + + +void qt_gui_eval_init(uint) +{ + switch (qt_eval_days_left()) { + case -2: + return; + + case -1: { + EvalMessageBox box(true); + box.exec(); + ::exit(0); + } + + default: { + EvalMessageBox *box = new EvalMessageBox(false); + box->show(); + Q_UNUSED(new QGuiFuriCuri()); + } + } +} + +static QString qt_eval_title_prefix() +{ + return QLatin1String("[Qt Evaluation] "); +} + +QString qt_eval_adapt_window_title(const QString &title) +{ + if (qt_eval_days_left() == -2) + return title; + return qt_eval_title_prefix() + title; +} + +void qt_eval_init_widget(QWidget *w) +{ + if (qt_eval_days_left() == -2) + return; + if (w->isTopLevel()) { + QString windowTitle = w->windowTitle(); + if (windowTitle.isEmpty()) { + w->setWindowTitle(" "); + } else if (!windowTitle.startsWith(qt_eval_title_prefix())) { + qt_eval_adapt_window_title(windowTitle); + } + } +} +#endif + +QT_END_NAMESPACE -- cgit v0.12 From ab7b164f60b0819d24d5b57d70988c4f5751329f Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Thu, 29 Oct 2009 13:01:28 +0100 Subject: Part 2 of the Evaluation notice feature, now for QtGui. Reviewed-by: Daniel Molkentin --- configure | 22 ++++++++++++++++++++++ src/corelib/eval.pri | 4 +++- src/corelib/kernel/qtcore_eval.cpp | 14 +++++++------- 3 files changed, 32 insertions(+), 8 deletions(-) diff --git a/configure b/configure index 08ec524..e3022b7 100755 --- a/configure +++ b/configure @@ -431,6 +431,7 @@ elif [ $COMMERCIAL_USER = "yes" ]; then ;; Z4M|R4M|Q4M) LicenseType="Evaluation" + QMakeVar add DEFINES QT_EVAL case $ProductCode in B) Edition="Evaluation" @@ -4068,12 +4069,17 @@ SETTINGS_PATH_STR=`"$relpath/config.tests/unix/padstring" 268 "qt_stngpath=$QT_I EXAMPLES_PATH_STR=`"$relpath/config.tests/unix/padstring" 268 "qt_xmplpath=$QT_INSTALL_EXAMPLES"` DEMOS_PATH_STR=`"$relpath/config.tests/unix/padstring" 268 "qt_demopath=$QT_INSTALL_DEMOS"` +TODAY=`date +%Y-%m-%d` cat > "$outpath/src/corelib/global/qconfig.cpp.new" </dev/null 2>&1; then + EVALKEY=`"$relpath/config.tests/unix/padstring" 524 "qt_qevalkey="` +fi + +if [ -n "$EVALKEY" ]; then + cat > "$outpath/src/corelib/global/qconfig_eval.cpp" <addWidget(border); if (expired) { - QPushButton *cmd = new QPushButton("OK", border); + QPushButton *cmd = new QPushButton(QLatin1String("OK"), border); cmd->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); cmd->setDefault(true); @@ -508,11 +508,11 @@ public: void timerEvent(QTimerEvent *e) { if (e->timerId() == warn) { killTimer(warn); - QMessageBox::information(0, "Automatic Timeout", will_shutdown_1min); + QMessageBox::information(0, QLatin1String("Automatic Timeout"), QLatin1String(will_shutdown_1min)); kill = startTimer(KILL_DELAY); } else if (e->timerId() == kill) { killTimer(kill); - QMessageBox::information(0, "Automatic Timeout", will_shutdown_now); + QMessageBox::information(0, QLatin1String("Automatic Timeout"), QLatin1String(will_shutdown_now)); qApp->quit(); } } @@ -558,7 +558,7 @@ void qt_eval_init_widget(QWidget *w) if (w->isTopLevel()) { QString windowTitle = w->windowTitle(); if (windowTitle.isEmpty()) { - w->setWindowTitle(" "); + w->setWindowTitle(QLatin1String(" ")); } else if (!windowTitle.startsWith(qt_eval_title_prefix())) { qt_eval_adapt_window_title(windowTitle); } -- cgit v0.12 From 2e9be4eec0778ceea2e32b4826cba08d85b177d9 Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Fri, 25 Sep 2009 17:18:28 +0200 Subject: Add the Qt Evaluation message to the hidden libQtCore.so boilerplate. Reviewed-By: Trust Me --- src/corelib/global/qlibraryinfo.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/corelib/global/qlibraryinfo.cpp b/src/corelib/global/qlibraryinfo.cpp index 17273e9..15a06d7 100644 --- a/src/corelib/global/qlibraryinfo.cpp +++ b/src/corelib/global/qlibraryinfo.cpp @@ -492,12 +492,20 @@ void qt_core_boilerplate() "Contact: Nokia Corporation (qt-info@nokia.com)\n" "\n" "Build key: " QT_BUILD_KEY "\n" + "Build date: %s\n" "Installation prefix: %s\n" "Library path: %s\n" "Include path: %s\n", + qt_configure_installation + 12, qt_configure_prefix_path_str + 12, qt_configure_libraries_path_str + 12, qt_configure_headers_path_str + 12); + +#ifdef QT_EVAL + extern void qt_core_eval_init(uint); + qt_core_eval_init(1); +#endif + exit(0); } -- cgit v0.12 From 7e0c0d684a42371c3597441a2488e05ce520f91e Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Mon, 28 Sep 2009 12:27:26 +0200 Subject: Also change the configure.exe to ensure that the necessary new configs are generated Reviewed-By: Daniel Molkentin --- tools/configure/configureapp.cpp | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/tools/configure/configureapp.cpp b/tools/configure/configureapp.cpp index f57f3a8..f75b51b 100644 --- a/tools/configure/configureapp.cpp +++ b/tools/configure/configureapp.cpp @@ -3033,7 +3033,11 @@ void Configure::generateConfigfiles() tmpStream.setDevice(&tmpFile2); tmpStream << "/* Licensed */" << endl << "static const char qt_configure_licensee_str [512 + 12] = \"qt_lcnsuser=" << licenseInfo["LICENSEE"] << "\";" << endl - << "static const char qt_configure_licensed_products_str [512 + 12] = \"qt_lcnsprod=" << dictionary["EDITION"] << "\";" << endl; + << "static const char qt_configure_licensed_products_str [512 + 12] = \"qt_lcnsprod=" << dictionary["EDITION"] << "\";" << endl + << endl + << "/* Build date */" << endl + << "static const char qt_configure_installation [11 + 12] = \"" << QDate::currentDate().toString(Qt::ISODate) << "\";" << endl + << endl; if(!dictionary[ "QT_HOST_PREFIX" ].isNull()) tmpStream << "#if !defined(QT_BOOTSTRAPPED) && !defined(QT_BUILD_QMAKE)" << endl; tmpStream << "static const char qt_configure_prefix_path_str [512 + 12] = \"qt_prfxpath=" << QString(dictionary["QT_INSTALL_PREFIX"]).replace( "\\", "\\\\" ) << "\";" << endl @@ -3087,6 +3091,24 @@ void Configure::generateConfigfiles() tmpFile2.copy(outName); tmpFile2.close(); } + + QTemporaryFile tmpFile3; + if (tmpFile3.open()) { + tmpStream.setDevice(&tmpFile3); + tmpStream << "/* Evaluation license key */" << endl + << "static const char qt_eval_key_data [512 + 12] = \"" << licenseInfo["LICENSEKEYEXT"] << "\";" << endl; + + tmpStream.flush(); + tmpFile3.flush(); + + outName = buildPath + "/src/corelib/global/qconfig_eval.cpp"; + ::SetFileAttributes((wchar_t*)outName.utf16(), FILE_ATTRIBUTE_NORMAL ); + QFile::remove( outName ); + + if (dictionary["EDITION"] == "Evaluation" || qmakeDefines.contains("QT_EVAL")) + tmpFile3.copy(outName); + tmpFile3.close(); + } } #endif -- cgit v0.12 From 263c81d923a1ed90335a3fb05c87330630456073 Mon Sep 17 00:00:00 2001 From: Norwegian Rock Cat Date: Thu, 29 Oct 2009 14:20:46 +0100 Subject: Plug some autorelease pool leaks. Calling QWidget::setCursor() outside of the event loop causes a memory leak in Cocoa. Adding an autorelease pool plugs it. Merge-request: 1791 Reviewed-by: Richard Moe Gustavsen --- src/gui/kernel/qwidget_mac.mm | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/gui/kernel/qwidget_mac.mm b/src/gui/kernel/qwidget_mac.mm index ef71194..db11815 100644 --- a/src/gui/kernel/qwidget_mac.mm +++ b/src/gui/kernel/qwidget_mac.mm @@ -2872,6 +2872,7 @@ void QWidgetPrivate::setCursor_sys(const QCursor &) #else Q_Q(QWidget); if (q->testAttribute(Qt::WA_WState_Created)) { + QMacCocoaAutoReleasePool pool; [qt_mac_window_for(q) invalidateCursorRectsForView:qt_mac_nativeview_for(q)]; } #endif @@ -2884,6 +2885,7 @@ void QWidgetPrivate::unsetCursor_sys() #else Q_Q(QWidget); if (q->testAttribute(Qt::WA_WState_Created)) { + QMacCocoaAutoReleasePool pool; [qt_mac_window_for(q) invalidateCursorRectsForView:qt_mac_nativeview_for(q)]; } #endif -- cgit v0.12 From ef4276442f8421771c827ad4e29bc69baf24de2d Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Thu, 29 Oct 2009 14:28:42 +0100 Subject: Remove the fromUserInput implementation and tests. Reviewed-by: Trust Me --- src/corelib/io/qurl.cpp | 119 +++++++++++++++++-------------------------- tests/auto/qurl/tst_qurl.cpp | 55 -------------------- 2 files changed, 46 insertions(+), 128 deletions(-) diff --git a/src/corelib/io/qurl.cpp b/src/corelib/io/qurl.cpp index 6001d9d..a865d8d 100644 --- a/src/corelib/io/qurl.cpp +++ b/src/corelib/io/qurl.cpp @@ -5556,79 +5556,6 @@ QUrl QUrl::fromEncoded(const QByteArray &input, ParsingMode parsingMode) } /*! - Returns a valid URL from a user supplied \a userInput string if one can be - deducted. In the case that is not possible, an invalid QUrl() is returned. - - \since 4.6 - - Most applications that can browse the web, allow the user to input a URL - in the form of a plain string. This string can be manually typed into - a location bar, obtained from the clipboard, or passed in via command - line arguments. - - When the string is not already a valid URL, a best guess is performed, - making various web related assumptions. - - In the case the string corresponds to a valid file path on the system, - a file:// URL is constructed, using QUrl::fromLocalFile(). - - If that is not the case, an attempt is made to turn the string into a - http:// or ftp:// URL. The latter in the case the string starts with - 'ftp'. The result is then passed through QUrl's tolerant parser, and - in the case or success, a valid QUrl is returned, or else a QUrl(). - - \section1 Examples: - - \list - \o qt.nokia.com becomes http://qt.nokia.com - \o ftp.qt.nokia.com becomes ftp://ftp.qt.nokia.com - \o localhost becomes http://localhost - \o /home/user/test.html becomes file:///home/user/test.html (if exists) - \endlist - - \section2 Tips to avoid erroneous character conversion when dealing with - URLs and strings: - - \list - \o When creating an URL QString from a QByteArray or a char*, always use - QString::fromUtf8(). - \o Favor the use of QUrl::fromEncoded() and QUrl::toEncoded() instead of - QUrl(string) and QUrl::toString() when converting QUrl to/from string. - \endlist -*/ -QUrl QUrl::fromUserInput(const QString &userInput) -{ - QString trimmedString = userInput.trimmed(); - - // Absolute files - if (QDir::isAbsolutePath(trimmedString)) - return QUrl::fromLocalFile(trimmedString); - - // Check the most common case of a valid url with scheme and host first - QUrl url = QUrl::fromEncoded(trimmedString.toUtf8(), QUrl::TolerantMode); - if (url.isValid() && !url.scheme().isEmpty() && !url.host().isEmpty()) - return url; - - // If the string is missing the scheme or the scheme is not valid, prepend a scheme - QString scheme = url.scheme(); - if (scheme.isEmpty() || scheme.contains(QLatin1Char('.')) || scheme == QLatin1String("localhost")) { - // Do not do anything for strings such as "foo", only "foo.com" - int dotIndex = trimmedString.indexOf(QLatin1Char('.')); - if (dotIndex != -1 || trimmedString.startsWith(QLatin1String("localhost"))) { - const QString hostscheme = trimmedString.left(dotIndex).toLower(); - QByteArray scheme = (hostscheme == QLatin1String("ftp")) ? "ftp" : "http"; - trimmedString = QLatin1String(scheme) + QLatin1String("://") + trimmedString; - } - url = QUrl::fromEncoded(trimmedString.toUtf8(), QUrl::TolerantMode); - } - - if (url.isValid()) - return url; - - return QUrl(); -} - -/*! Returns a decoded copy of \a input. \a input is first decoded from percent encoding, then converted from UTF-8 to unicode. */ @@ -6227,4 +6154,50 @@ QString QUrl::errorString() const \internal */ + +/*! + Returns a valid URL from a user supplied \a userInput string if one can be + deducted. In the case that is not possible, an invalid QUrl() is returned. + + \since 4.6 + + Most applications that can browse the web, allow the user to input a URL + in the form of a plain string. This string can be manually typed into + a location bar, obtained from the clipboard, or passed in via command + line arguments. + + When the string is not already a valid URL, a best guess is performed, + making various web related assumptions. + + In the case the string corresponds to a valid file path on the system, + a file:// URL is constructed, using QUrl::fromLocalFile(). + + If that is not the case, an attempt is made to turn the string into a + http:// or ftp:// URL. The latter in the case the string starts with + 'ftp'. The result is then passed through QUrl's tolerant parser, and + in the case or success, a valid QUrl is returned, or else a QUrl(). + + \section1 Examples: + + \list + \o qt.nokia.com becomes http://qt.nokia.com + \o ftp.qt.nokia.com becomes ftp://ftp.qt.nokia.com + \o localhost becomes http://localhost + \o /home/user/test.html becomes file:///home/user/test.html (if exists) + \endlist + + \section2 Tips to avoid erroneous character conversion when dealing with + URLs and strings: + + \list + \o When creating an URL QString from a QByteArray or a char*, always use + QString::fromUtf8(). + \o Favor the use of QUrl::fromEncoded() and QUrl::toEncoded() instead of + QUrl(string) and QUrl::toString() when converting QUrl to/from string. + \endlist +*/ +QUrl QUrl::fromUserInput(const QString &userInput) +{ +} + QT_END_NAMESPACE diff --git a/tests/auto/qurl/tst_qurl.cpp b/tests/auto/qurl/tst_qurl.cpp index 72c13bf..178e5e5 100644 --- a/tests/auto/qurl/tst_qurl.cpp +++ b/tests/auto/qurl/tst_qurl.cpp @@ -3679,65 +3679,10 @@ void tst_QUrl::binaryData() void tst_QUrl::fromUserInput_data() { - QTest::addColumn("string"); - QTest::addColumn("url"); - - // Null - QTest::newRow("null") << QString() << QUrl(); - - // File - QDirIterator it(QDir::homePath()); - QString fileString; - int c = 0; - while (it.hasNext()) { - it.next(); - QTest::newRow(QString("file-%1").arg(c++).toLatin1()) << it.filePath() << QUrl::fromLocalFile(it.filePath()); - } - - // basic latin1 - QTest::newRow("unicode-0") << QString::fromUtf8("\xC3\xA5.com/") << QUrl::fromEncoded(QString::fromUtf8("http://\xC3\xA5.com/").toUtf8(), QUrl::TolerantMode); - // unicode - QTest::newRow("unicode-1") << QString::fromUtf8("\xCE\xBB.com/") << QUrl::fromEncoded(QString::fromUtf8("http://\xCE\xBB.com/").toUtf8(), QUrl::TolerantMode); - - // no scheme - QTest::newRow("add scheme-0") << "webkit.org" << QUrl("http://webkit.org"); - QTest::newRow("add scheme-1") << "www.webkit.org" << QUrl("http://www.webkit.org"); - QTest::newRow("add scheme-2") << "ftp.webkit.org" << QUrl("ftp://ftp.webkit.org"); - QTest::newRow("add scheme-3") << "webkit" << QUrl("webkit"); - - // QUrl's tolerant parser should already handle this - QTest::newRow("not-encoded-0") << "http://webkit.org/test page.html" << QUrl("http://webkit.org/test%20page.html"); - - // Make sure the :80, i.e. port doesn't screw anything up - QUrl portUrl("http://webkit.org"); - portUrl.setPort(80); - QTest::newRow("port-0") << "webkit.org:80" << portUrl; - QTest::newRow("port-1") << "http://webkit.org:80" << portUrl; - - // mailto doesn't have a ://, but is valid - QUrl mailto("somebody@somewhere.net"); - mailto.setScheme("mailto"); - QTest::newRow("mailto") << "mailto:somebody@somewhere.net" << mailto; - - // misc - QTest::newRow("localhost-0") << "localhost" << QUrl("http://localhost"); - QTest::newRow("localhost-1") << "localhost:80" << QUrl("http://localhost:80"); - QTest::newRow("spaces-0") << " http://webkit.org/test page.html " << QUrl("http://webkit.org/test%20page.html"); - QTest::newRow("trash-0") << "webkit.org/test?someData=42%&someOtherData=abcde#anchor" << QUrl::fromEncoded("http://webkit.org/test?someData=42%25&someOtherData=abcde#anchor"); - - // FYI: The scheme in the resulting url user - QUrl authUrl("user:pass@domain.com"); - QTest::newRow("misc-1") << "user:pass@domain.com" << authUrl; } -// public static QUrl guessUrlFromString(QString const& string) void tst_QUrl::fromUserInput() { - QFETCH(QString, string); - QFETCH(QUrl, url); - - QUrl guessedUrl = QUrl::fromUserInput(string); - QCOMPARE(guessedUrl, url); } void tst_QUrl::task_199967() -- cgit v0.12 From 244c27d22cb7c0e686210ceb2973862ae514f95b Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Thu, 29 Oct 2009 14:41:12 +0100 Subject: Import a new implementation of fromUserInput. Imported from http://github.com/icefox/guessurlfromstring Licensed under the 3-clause BSD license by the copyright holder. --- src/corelib/io/qurl.cpp | 57 +++++++++++++++++++++++++++++++++++++++++ tests/auto/qurl/tst_qurl.cpp | 60 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 117 insertions(+) diff --git a/src/corelib/io/qurl.cpp b/src/corelib/io/qurl.cpp index a865d8d..86680a5 100644 --- a/src/corelib/io/qurl.cpp +++ b/src/corelib/io/qurl.cpp @@ -6154,6 +6154,34 @@ QString QUrl::errorString() const \internal */ +// The following code has the following copyright: +/* + Copyright (C) Research In Motion Limited 2009. All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + * Neither the name of Research In Motion Limited nor the + names of its contributors may be used to endorse or promote products + derived from this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY Research In Motion Limited ''AS IS'' AND ANY +EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL Research In Motion Limited BE LIABLE FOR ANY +DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND +ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +*/ + /*! Returns a valid URL from a user supplied \a userInput string if one can be @@ -6198,6 +6226,35 @@ QString QUrl::errorString() const */ QUrl QUrl::fromUserInput(const QString &userInput) { + QString trimmedString = userInput.trimmed(); + + // Check the most common case of a valid url with scheme and host first + QUrl url = QUrl::fromEncoded(trimmedString.toUtf8(), QUrl::TolerantMode); + if (url.isValid() && !url.scheme().isEmpty() && !url.host().isEmpty()) + return url; + + // Absolute files that exists + if (QDir::isAbsolutePath(trimmedString) && QFile::exists(trimmedString)) + return QUrl::fromLocalFile(trimmedString); + + // If the string is missing the scheme or the scheme is not valid prepend a scheme + QString scheme = url.scheme(); + if (scheme.isEmpty() || scheme.contains(QLatin1Char('.')) || scheme == QLatin1String("localhost")) { + // Do not do anything for strings such as "foo", only "foo.com" + int dotIndex = trimmedString.indexOf(QLatin1Char('.')); + if (dotIndex != -1 || trimmedString.startsWith(QLatin1String("localhost"))) { + const QString hostscheme = trimmedString.left(dotIndex).toLower(); + QByteArray scheme = (hostscheme == QLatin1String("ftp")) ? "ftp" : "http"; + trimmedString = QLatin1String(scheme) + QLatin1String("://") + trimmedString; + } + url = QUrl::fromEncoded(trimmedString.toUtf8(), QUrl::TolerantMode); + } + + if (url.isValid()) + return url; + + return QUrl(); } +// end of BSD code QT_END_NAMESPACE diff --git a/tests/auto/qurl/tst_qurl.cpp b/tests/auto/qurl/tst_qurl.cpp index 178e5e5..6424dcc 100644 --- a/tests/auto/qurl/tst_qurl.cpp +++ b/tests/auto/qurl/tst_qurl.cpp @@ -3679,10 +3679,70 @@ void tst_QUrl::binaryData() void tst_QUrl::fromUserInput_data() { + // + // most of this test is: + // Copyright (C) Research In Motion Limited 2009. All rights reserved. + // Distributed under the BSD license. + // See qurl.cpp + // + + QTest::addColumn("string"); + QTest::addColumn("guessUrlFromString"); + + // Null + QTest::newRow("null") << QString() << QUrl(); + + // File + QDirIterator it(QDir::homePath()); + QString fileString; + int c = 0; + while (it.hasNext()) { + it.next(); + QTest::newRow(QString("file-%1").arg(c++).toLatin1()) << it.filePath() << QUrl::fromLocalFile(it.filePath()); + } + + // basic latin1 + QTest::newRow("unicode-0") << QString::fromUtf8("å.com/") << QUrl::fromEncoded(QString::fromUtf8("http://å.com/").toUtf8(), QUrl::TolerantMode); + // unicode + QTest::newRow("unicode-1") << QString::fromUtf8("?.com/") << QUrl::fromEncoded(QString::fromUtf8("http://?.com/").toUtf8(), QUrl::TolerantMode); + + // no scheme + QTest::newRow("add scheme-0") << "webkit.org" << QUrl("http://webkit.org"); + QTest::newRow("add scheme-1") << "www.webkit.org" << QUrl("http://www.webkit.org"); + QTest::newRow("add scheme-2") << "ftp.webkit.org" << QUrl("ftp://ftp.webkit.org"); + QTest::newRow("add scheme-3") << "webkit" << QUrl("webkit"); + + // QUrl's tolerant parser should already handle this + QTest::newRow("not-encoded-0") << "http://webkit.org/test page.html" << QUrl("http://webkit.org/test%20page.html"); + + // Make sure the :80, i.e. port doesn't screw anything up + QUrl portUrl("http://webkit.org"); + portUrl.setPort(80); + QTest::newRow("port-0") << "webkit.org:80" << portUrl; + QTest::newRow("port-1") << "http://webkit.org:80" << portUrl; + + // mailto doesn't have a ://, but is valid + QUrl mailto("ben@meyerhome.net"); + mailto.setScheme("mailto"); + QTest::newRow("mailto") << "mailto:ben@meyerhome.net" << mailto; + + // misc + QTest::newRow("localhost-0") << "localhost" << QUrl("http://localhost"); + QTest::newRow("localhost-1") << "localhost:80" << QUrl("http://localhost:80"); + QTest::newRow("spaces-0") << " http://webkit.org/test page.html " << QUrl("http://webkit.org/test%20page.html"); + + // FYI: The scheme in the resulting url user + QUrl authUrl("user:pass@domain.com"); + QTest::newRow("misc-1") << "user:pass@domain.com" << authUrl; } void tst_QUrl::fromUserInput() { + QFETCH(QString, string); + QFETCH(QUrl, guessUrlFromString); + + QUrl url = QUrl::fromUserInput(string); + QCOMPARE(url, guessUrlFromString); } void tst_QUrl::task_199967() -- cgit v0.12 From 6cede417422d8ff421a513d2d031e21fa6080c8c Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Thu, 29 Oct 2009 14:44:45 +0100 Subject: Autotest: use example.org and example.net No need to publicise real sites and email addresses. Also, don't use 8-bit data. C escape sequences are ok. --- tests/auto/qurl/tst_qurl.cpp | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/tests/auto/qurl/tst_qurl.cpp b/tests/auto/qurl/tst_qurl.cpp index 6424dcc..65ca878 100644 --- a/tests/auto/qurl/tst_qurl.cpp +++ b/tests/auto/qurl/tst_qurl.cpp @@ -3702,34 +3702,34 @@ void tst_QUrl::fromUserInput_data() } // basic latin1 - QTest::newRow("unicode-0") << QString::fromUtf8("å.com/") << QUrl::fromEncoded(QString::fromUtf8("http://å.com/").toUtf8(), QUrl::TolerantMode); + QTest::newRow("unicode-0") << QString::fromUtf8("\xc3\xa5.com/") << QUrl::fromEncoded(QString::fromUtf8("http://\xc3\xa5.com/").toUtf8(), QUrl::TolerantMode); // unicode - QTest::newRow("unicode-1") << QString::fromUtf8("?.com/") << QUrl::fromEncoded(QString::fromUtf8("http://?.com/").toUtf8(), QUrl::TolerantMode); + QTest::newRow("unicode-1") << QString::fromUtf8("\xce\xbb.com/") << QUrl::fromEncoded(QString::fromUtf8("http://\xce\xbb.com/").toUtf8(), QUrl::TolerantMode); // no scheme - QTest::newRow("add scheme-0") << "webkit.org" << QUrl("http://webkit.org"); - QTest::newRow("add scheme-1") << "www.webkit.org" << QUrl("http://www.webkit.org"); - QTest::newRow("add scheme-2") << "ftp.webkit.org" << QUrl("ftp://ftp.webkit.org"); + QTest::newRow("add scheme-0") << "example.org" << QUrl("http://example.org"); + QTest::newRow("add scheme-1") << "www.example.org" << QUrl("http://www.example.org"); + QTest::newRow("add scheme-2") << "ftp.example.org" << QUrl("ftp://ftp.example.org"); QTest::newRow("add scheme-3") << "webkit" << QUrl("webkit"); // QUrl's tolerant parser should already handle this - QTest::newRow("not-encoded-0") << "http://webkit.org/test page.html" << QUrl("http://webkit.org/test%20page.html"); + QTest::newRow("not-encoded-0") << "http://example.org/test page.html" << QUrl("http://example.org/test%20page.html"); // Make sure the :80, i.e. port doesn't screw anything up - QUrl portUrl("http://webkit.org"); + QUrl portUrl("http://example.org"); portUrl.setPort(80); - QTest::newRow("port-0") << "webkit.org:80" << portUrl; - QTest::newRow("port-1") << "http://webkit.org:80" << portUrl; + QTest::newRow("port-0") << "example.org:80" << portUrl; + QTest::newRow("port-1") << "http://example.org:80" << portUrl; // mailto doesn't have a ://, but is valid - QUrl mailto("ben@meyerhome.net"); + QUrl mailto("ben@example.net"); mailto.setScheme("mailto"); - QTest::newRow("mailto") << "mailto:ben@meyerhome.net" << mailto; + QTest::newRow("mailto") << "mailto:ben@example.net" << mailto; // misc QTest::newRow("localhost-0") << "localhost" << QUrl("http://localhost"); QTest::newRow("localhost-1") << "localhost:80" << QUrl("http://localhost:80"); - QTest::newRow("spaces-0") << " http://webkit.org/test page.html " << QUrl("http://webkit.org/test%20page.html"); + QTest::newRow("spaces-0") << " http://example.org/test page.html " << QUrl("http://example.org/test%20page.html"); // FYI: The scheme in the resulting url user QUrl authUrl("user:pass@domain.com"); -- cgit v0.12 From 22e4b3dfa9f8ee6a596ac6e0d02cb39f364ef27d Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Thu, 29 Oct 2009 14:48:10 +0100 Subject: Autotest: add one test that was in the previous implementation but missing here --- tests/auto/qurl/tst_qurl.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/auto/qurl/tst_qurl.cpp b/tests/auto/qurl/tst_qurl.cpp index 65ca878..87018d3 100644 --- a/tests/auto/qurl/tst_qurl.cpp +++ b/tests/auto/qurl/tst_qurl.cpp @@ -3730,6 +3730,7 @@ void tst_QUrl::fromUserInput_data() QTest::newRow("localhost-0") << "localhost" << QUrl("http://localhost"); QTest::newRow("localhost-1") << "localhost:80" << QUrl("http://localhost:80"); QTest::newRow("spaces-0") << " http://example.org/test page.html " << QUrl("http://example.org/test%20page.html"); + QTest::newRow("trash-0") << "example.org/test?someData=42%&someOtherData=abcde#anchor" << QUrl::fromEncoded("http://example.org/test?someData=42%25&someOtherData=abcde#anchor"); // FYI: The scheme in the resulting url user QUrl authUrl("user:pass@domain.com"); -- cgit v0.12 From cfd4156e0dd3f42e23596bba40a30f93f7cdd64b Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Thu, 29 Oct 2009 14:55:59 +0100 Subject: Autotest: add a few more tests for Unicode (IDN) support --- tests/auto/qurl/tst_qurl.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/tests/auto/qurl/tst_qurl.cpp b/tests/auto/qurl/tst_qurl.cpp index 87018d3..c8fe4e5 100644 --- a/tests/auto/qurl/tst_qurl.cpp +++ b/tests/auto/qurl/tst_qurl.cpp @@ -3694,7 +3694,6 @@ void tst_QUrl::fromUserInput_data() // File QDirIterator it(QDir::homePath()); - QString fileString; int c = 0; while (it.hasNext()) { it.next(); @@ -3703,8 +3702,12 @@ void tst_QUrl::fromUserInput_data() // basic latin1 QTest::newRow("unicode-0") << QString::fromUtf8("\xc3\xa5.com/") << QUrl::fromEncoded(QString::fromUtf8("http://\xc3\xa5.com/").toUtf8(), QUrl::TolerantMode); + QTest::newRow("unicode-0b") << QString::fromUtf8("\xc3\xa5.com/") << QUrl::fromEncoded("http://%C3%A5.com/", QUrl::TolerantMode); + QTest::newRow("unicode-0c") << QString::fromUtf8("\xc3\xa5.com/") << QUrl::fromEncoded("http://xn--5ca.com/", QUrl::TolerantMode); // unicode QTest::newRow("unicode-1") << QString::fromUtf8("\xce\xbb.com/") << QUrl::fromEncoded(QString::fromUtf8("http://\xce\xbb.com/").toUtf8(), QUrl::TolerantMode); + QTest::newRow("unicode-1b") << QString::fromUtf8("\xce\xbb.com/") << QUrl::fromEncoded("http://%CE%BB.com/", QUrl::TolerantMode); + QTest::newRow("unicode-1c") << QString::fromUtf8("\xce\xbb.com/") << QUrl::fromEncoded("http://xn--wxa.com/", QUrl::TolerantMode); // no scheme QTest::newRow("add scheme-0") << "example.org" << QUrl("http://example.org"); @@ -3713,7 +3716,7 @@ void tst_QUrl::fromUserInput_data() QTest::newRow("add scheme-3") << "webkit" << QUrl("webkit"); // QUrl's tolerant parser should already handle this - QTest::newRow("not-encoded-0") << "http://example.org/test page.html" << QUrl("http://example.org/test%20page.html"); + QTest::newRow("not-encoded-0") << "http://example.org/test page.html" << QUrl::fromEncoded("http://example.org/test%20page.html"); // Make sure the :80, i.e. port doesn't screw anything up QUrl portUrl("http://example.org"); -- cgit v0.12 From 94be7bf47fe93ca4fa6ae90f5906f6ef711f558e Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Thu, 29 Oct 2009 15:23:03 +0100 Subject: Compile fix until configure.exe is rebuilt for Windows --- src/corelib/global/qlibraryinfo.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/corelib/global/qlibraryinfo.cpp b/src/corelib/global/qlibraryinfo.cpp index 15a06d7..32693e0 100644 --- a/src/corelib/global/qlibraryinfo.cpp +++ b/src/corelib/global/qlibraryinfo.cpp @@ -215,7 +215,8 @@ QLibraryInfo::buildKey() QDate QLibraryInfo::buildDate() { - return QDate::fromString(QString::fromLatin1(qt_configure_installation + 12), Qt::ISODate); + return QDate(); + //return QDate::fromString(QString::fromLatin1(qt_configure_installation + 12), Qt::ISODate); } /*! -- cgit v0.12 From 89ccbd14fe8c0e6b0fefcca2151da28d98088bf5 Mon Sep 17 00:00:00 2001 From: Oswald Buddenhagen Date: Thu, 29 Oct 2009 16:48:38 +0100 Subject: do not crash --- .../linguist/lupdate/testdata/good/parsecpp/main.cpp | 19 +++++++++++++++++++ .../lupdate/testdata/good/parsecpp/project.ts.result | 8 ++++++++ tools/linguist/lupdate/cpp.cpp | 12 +++++++----- 3 files changed, 34 insertions(+), 5 deletions(-) diff --git a/tests/auto/linguist/lupdate/testdata/good/parsecpp/main.cpp b/tests/auto/linguist/lupdate/testdata/good/parsecpp/main.cpp index 8201add..e243e66 100644 --- a/tests/auto/linguist/lupdate/testdata/good/parsecpp/main.cpp +++ b/tests/auto/linguist/lupdate/testdata/good/parsecpp/main.cpp @@ -228,3 +228,22 @@ QT_TRID_NOOP("this_a_id") //~ some thing //% "This needs to be here. Really." QString test = qtTrId("this_another_id", n); + + + +class YetAnotherTest : QObject { + Q_OBJECT + + int function(void) + { + // + //: + //= + //~ + //# + //============= + //~~~~~~~~~~~~~ + //::::::::::::: + tr("nothing"); + } +}; diff --git a/tests/auto/linguist/lupdate/testdata/good/parsecpp/project.ts.result b/tests/auto/linguist/lupdate/testdata/good/parsecpp/project.ts.result index d63c7c3..26e5a65 100644 --- a/tests/auto/linguist/lupdate/testdata/good/parsecpp/project.ts.result +++ b/tests/auto/linguist/lupdate/testdata/good/parsecpp/project.ts.result @@ -278,6 +278,14 @@ backslashed \ stuff. + YetAnotherTest + + + nothing + + + + scope diff --git a/tools/linguist/lupdate/cpp.cpp b/tools/linguist/lupdate/cpp.cpp index 6374912..4d89156 100644 --- a/tools/linguist/lupdate/cpp.cpp +++ b/tools/linguist/lupdate/cpp.cpp @@ -1896,25 +1896,26 @@ void CppParser::parseInternal(ConversionData &cd, QSet &inclusions) prospectiveContext.clear(); } break; - case Tok_Comment: + case Tok_Comment: { if (!tor) goto case_default; - if (yyWord.at(0) == QLatin1Char(':') && yyWord.at(1).isSpace()) { + const QChar *ptr = yyWord.unicode(); + if (*ptr == QLatin1Char(':') && ptr[1].isSpace()) { yyWord.remove(0, 2); extracomment += yyWord; extracomment.detach(); - } else if (yyWord.at(0) == QLatin1Char('=') && yyWord.at(1).isSpace()) { + } else if (*ptr == QLatin1Char('=') && ptr[1].isSpace()) { yyWord.remove(0, 2); msgid = yyWord.simplified(); msgid.detach(); - } else if (yyWord.at(0) == QLatin1Char('~') && yyWord.at(1).isSpace()) { + } else if (*ptr == QLatin1Char('~') && ptr[1].isSpace()) { yyWord.remove(0, 2); text = yyWord.trimmed(); int k = text.indexOf(QLatin1Char(' ')); if (k > -1) extra.insert(text.left(k), text.mid(k + 1).trimmed()); text.clear(); - } else if (yyWord.at(0) == QLatin1Char('%') && yyWord.at(1).isSpace()) { + } else if (*ptr == QLatin1Char('%') && ptr[1].isSpace()) { sourcetext.reserve(sourcetext.length() + yyWord.length() - 2); ushort *ptr = (ushort *)sourcetext.data() + sourcetext.length(); int p = 2, c; @@ -1977,6 +1978,7 @@ void CppParser::parseInternal(ConversionData &cd, QSet &inclusions) } yyTok = getToken(); break; + } case Tok_Arrow: yyTok = getToken(); if (yyTok == Tok_tr || yyTok == Tok_trUtf8) -- cgit v0.12 From 5641bd0cdd9c90427d7d976473b894c530cdb715 Mon Sep 17 00:00:00 2001 From: kh1 Date: Thu, 29 Oct 2009 17:51:24 +0100 Subject: Fix wrong version number in Assistant internal help. Task-number: QT-1522 Reviewed-by: kh --- tools/assistant/tools/assistant/assistant.qch | Bin 368640 -> 364544 bytes 1 file changed, 0 insertions(+), 0 deletions(-) diff --git a/tools/assistant/tools/assistant/assistant.qch b/tools/assistant/tools/assistant/assistant.qch index 3e66bd9..78fe9f3 100644 Binary files a/tools/assistant/tools/assistant/assistant.qch and b/tools/assistant/tools/assistant/assistant.qch differ -- cgit v0.12