Remove "All rights reserved" line from license headers.
[profile/ivi/qtdeclarative.git] / src / declarative / qml / qdeclarativecleanup.cpp
index db671a3..aa7a1e3 100644 (file)
@@ -1,8 +1,7 @@
 /****************************************************************************
 **
 /****************************************************************************
 **
-** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
-** All rights reserved.
-** Contact: Nokia Corporation (qt-info@nokia.com)
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
 **
 ** This file is part of the QtDeclarative module of the Qt Toolkit.
 **
 **
 ** This file is part of the QtDeclarative module of the Qt Toolkit.
 **
 **
 **
 **
 **
 **
 **
+**
 ** $QT_END_LICENSE$
 **
 ****************************************************************************/
 
 ** $QT_END_LICENSE$
 **
 ****************************************************************************/
 
-#include "private/qdeclarativecleanup_p.h"
+#include "qdeclarativecleanup_p.h"
 
 
-#include "private/qdeclarativeengine_p.h"
+#include "qdeclarativeengine_p.h"
 
 QT_BEGIN_NAMESPACE
 
 
 QT_BEGIN_NAMESPACE
 
@@ -50,22 +50,43 @@ QT_BEGIN_NAMESPACE
 \class QDeclarativeCleanup
 \brief The QDeclarativeCleanup provides a callback when a QDeclarativeEngine is deleted. 
 
 \class QDeclarativeCleanup
 \brief The QDeclarativeCleanup provides a callback when a QDeclarativeEngine is deleted. 
 
-Any object that needs cleanup to occur before the QDeclarativeEngine's QScriptEngine is
+Any object that needs cleanup to occur before the QDeclarativeEngine's V8 engine is
 destroyed should inherit from QDeclarativeCleanup.  The clear() virtual method will be
 destroyed should inherit from QDeclarativeCleanup.  The clear() virtual method will be
-called by QDeclarativeEngine just before it deletes the QScriptEngine.
+called by QDeclarativeEngine just before it destroys the context.
 */
 
 */
 
-/*!
-\internal
 
 
+/*
+Create a QDeclarativeCleanup that is not associated with any engine.
+*/
+QDeclarativeCleanup::QDeclarativeCleanup()
+: prev(0), next(0), engine(0)
+{
+}
+
+/*!
 Create a QDeclarativeCleanup for \a engine
 */
 QDeclarativeCleanup::QDeclarativeCleanup(QDeclarativeEngine *engine)
 Create a QDeclarativeCleanup for \a engine
 */
 QDeclarativeCleanup::QDeclarativeCleanup(QDeclarativeEngine *engine)
-: prev(0), next(0)
+: prev(0), next(0), engine(0)
 {
     if (!engine)
         return;
 
 {
     if (!engine)
         return;
 
+    addToEngine(engine);
+}
+
+/*!
+Adds this object to \a engine's cleanup list.  hasEngine() must be false
+before calling this method.
+*/
+void QDeclarativeCleanup::addToEngine(QDeclarativeEngine *engine)
+{
+    Q_ASSERT(engine);
+    Q_ASSERT(QDeclarativeEnginePrivate::isEngineThread(engine));
+
+    this->engine = engine;
+
     QDeclarativeEnginePrivate *p = QDeclarativeEnginePrivate::get(engine);
 
     if (p->cleanup) next = p->cleanup;
     QDeclarativeEnginePrivate *p = QDeclarativeEnginePrivate::get(engine);
 
     if (p->cleanup) next = p->cleanup;
@@ -75,13 +96,23 @@ QDeclarativeCleanup::QDeclarativeCleanup(QDeclarativeEngine *engine)
 }
 
 /*!
 }
 
 /*!
+\fn bool QDeclarativeCleanup::hasEngine() const
+
+Returns true if this QDeclarativeCleanup is associated with an engine, otherwise false.
+*/
+
+/*!
 \internal
 */
 QDeclarativeCleanup::~QDeclarativeCleanup()
 {
 \internal
 */
 QDeclarativeCleanup::~QDeclarativeCleanup()
 {
+    Q_ASSERT(!prev || engine);
+    Q_ASSERT(!prev || QDeclarativeEnginePrivate::isEngineThread(engine));
+
     if (prev) *prev = next;
     if (next) next->prev = prev;
     prev = 0; 
     next = 0;
 }
     if (prev) *prev = next;
     if (next) next->prev = prev;
     prev = 0; 
     next = 0;
 }
+
 QT_END_NAMESPACE
 QT_END_NAMESPACE