Improve error message for invalid image provider name.
authorMartin Jones <martin.jones@nokia.com>
Thu, 12 May 2011 04:34:48 +0000 (14:34 +1000)
committerMartin Jones <martin.jones@nokia.com>
Thu, 12 May 2011 04:34:48 +0000 (14:34 +1000)
Also fix broken qdeclarativeimageprovider test.

src/declarative/qml/qdeclarativeengine.cpp
src/declarative/qml/qdeclarativeimageprovider.h
src/declarative/util/qdeclarativepixmapcache.cpp
tests/auto/declarative/qdeclarativeimageprovider/tst_qdeclarativeimageprovider.cpp

index 2ed1080..eb2974f 100644 (file)
@@ -837,7 +837,7 @@ QDeclarativeImageProvider::ImageType QDeclarativeEnginePrivate::getImageProvider
     locker.unlock();
     if (provider)
         return provider->imageType();
-    return static_cast<QDeclarativeImageProvider::ImageType>(-1);
+    return QDeclarativeImageProvider::Invalid;
 }
 
 QSGTexture *QDeclarativeEnginePrivate::getTextureFromProvider(const QUrl &url, QSize *size, const QSize& req_size)
index e5e80f2..512724b 100644 (file)
@@ -60,7 +60,8 @@ public:
     enum ImageType {
         Image,
         Pixmap,
-        Texture
+        Texture,
+        Invalid
     };
 
     QDeclarativeImageProvider(ImageType type);
index f0e999b..ef0c422 100644 (file)
@@ -507,8 +507,19 @@ void QDeclarativePixmapReader::processJob(QDeclarativePixmapReply *runningJob, c
         QSize readSize;
         QDeclarativeEnginePrivate *ep = QDeclarativeEnginePrivate::get(engine);
         QDeclarativeImageProvider::ImageType imageType = ep->getImageProviderType(url);
-
-        if (imageType == QDeclarativeImageProvider::Image) {
+        if (imageType == QDeclarativeImageProvider::Invalid) {
+            QDeclarativePixmapReply::ReadError errorCode = QDeclarativePixmapReply::Loading;
+            QString errorStr = QDeclarativePixmap::tr("Invalid image provider: %1").arg(url.toString());
+            QImage image;
+            mutex.lock();
+            if (!cancelled.contains(runningJob)) {
+                if (sgContext)
+                    runningJob->postReply(errorCode, errorStr, readSize, sgContext->createTexture(image), sgContext);
+                else
+                    runningJob->postReply(errorCode, errorStr, readSize, image);
+            }
+            mutex.unlock();
+        } else if (imageType == QDeclarativeImageProvider::Image) {
             QImage image = ep->getImageFromProvider(url, &readSize, requestSize);
             QDeclarativePixmapReply::ReadError errorCode = QDeclarativePixmapReply::NoError;
             QString errorStr;
@@ -877,6 +888,9 @@ static QDeclarativePixmapData* createPixmapDataSync(QDeclarativeEngine *engine,
         QDeclarativeImageProvider::ImageType imageType = ep->getImageProviderType(url);
 
         switch (imageType) {
+            case QDeclarativeImageProvider::Invalid:
+                return new QDeclarativePixmapData(url, requestSize,
+                    QDeclarativePixmap::tr("Invalid image provider: %1").arg(url.toString()));
             case QDeclarativeImageProvider::Texture:
             {
                 QSGTexture *texture = ep->getTextureFromProvider(url, &readSize, requestSize);
@@ -912,7 +926,7 @@ static QDeclarativePixmapData* createPixmapDataSync(QDeclarativeEngine *engine,
             }
         }
 
-        // no matching provider, or provider has bad image type, or provider returned null image
+        // provider has bad image type, or provider returned null image
         return new QDeclarativePixmapData(url, requestSize,
             QDeclarativePixmap::tr("Failed to get image from provider: %1").arg(url.toString()));
     }
index 6d35332..b7d826f 100644 (file)
@@ -210,7 +210,7 @@ void tst_qdeclarativeimageprovider::fillRequestTestsData(const QString &id)
 
     QTest::newRow(QTest::toString(id + " unknown provider"))
         << "image://bogus/exists.png" << "" << "" << QSize()
-        << "file::2:1: QML Image: Failed to get image from provider: image://bogus/exists.png";
+        << "file::2:1: QML Image: Invalid image provider: image://bogus/exists.png";
 }
 
 void tst_qdeclarativeimageprovider::runTest(bool async, QDeclarativeImageProvider *provider)
@@ -350,7 +350,7 @@ void tst_qdeclarativeimageprovider::removeProvider()
 
     // remove the provider and confirm
     QString fileName = newImageFileName();
-    QString error("file::2:1: QML Image: Failed to get image from provider: " + fileName);
+    QString error("file::2:1: QML Image: Invalid image provider: " + fileName);
     QTest::ignoreMessage(QtWarningMsg, error.toUtf8());
 
     engine.removeImageProvider("test");