summaryrefslogtreecommitdiffstats
path: root/src/declarative/util/qdeclarativepixmapcache.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/declarative/util/qdeclarativepixmapcache.cpp')
-rw-r--r--src/declarative/util/qdeclarativepixmapcache.cpp34
1 files changed, 23 insertions, 11 deletions
diff --git a/src/declarative/util/qdeclarativepixmapcache.cpp b/src/declarative/util/qdeclarativepixmapcache.cpp
index 5e60819..4a96a2a 100644
--- a/src/declarative/util/qdeclarativepixmapcache.cpp
+++ b/src/declarative/util/qdeclarativepixmapcache.cpp
@@ -194,8 +194,8 @@ static bool readImage(const QUrl& url, QIODevice *dev, QImage *image, QString *e
return true;
} else {
if (errorString)
- *errorString = QLatin1String("Error decoding: ") + url.toString()
- + QLatin1String(" \"") + imgio.errorString() + QLatin1String("\"");
+ *errorString = QDeclarativeImageRequestHandler::tr("Error decoding: %1: %2").arg(url.toString())
+ .arg(imgio.errorString());
return false;
}
}
@@ -264,7 +264,7 @@ bool QDeclarativeImageRequestHandler::event(QEvent *event)
QString errorStr;
if (image.isNull()) {
errorCode = QDeclarativeImageReaderEvent::Loading;
- errorStr = QLatin1String("Failed to get image from provider: ") + url.toString();
+ errorStr = QDeclarativeImageRequestHandler::tr("Failed to get image from provider: %1").arg(url.toString());
}
QCoreApplication::postEvent(runningJob, new QDeclarativeImageReaderEvent(errorCode, errorStr, image));
} else {
@@ -283,7 +283,7 @@ bool QDeclarativeImageRequestHandler::event(QEvent *event)
errorCode = QDeclarativeImageReaderEvent::Loading;
}
} else {
- errorStr = QLatin1String("Cannot open: ") + url.toString();
+ errorStr = QDeclarativeImageRequestHandler::tr("Cannot open: %1").arg(url.toString());
errorCode = QDeclarativeImageReaderEvent::Loading;
}
QCoreApplication::postEvent(runningJob, new QDeclarativeImageReaderEvent(errorCode, errorStr, image));
@@ -460,6 +460,7 @@ public:
bool loading;
QDeclarativeImageReader *reader;
int forced_width, forced_height;
+ QString errorString;
};
@@ -511,7 +512,7 @@ bool QDeclarativePixmapReply::event(QEvent *event)
if (d->status == Ready)
d->pixmap = QPixmap::fromImage(de->image);
else
- qWarning() << de->errorString;
+ d->errorString = de->errorString;
QByteArray key = d->url.toEncoded(QUrl::FormattingOption(0x100));
QString strKey = QString::fromLatin1(key.constData(), key.count());
QPixmapCache::insert(strKey, d->pixmap); // note: may fail (returns false)
@@ -523,6 +524,12 @@ bool QDeclarativePixmapReply::event(QEvent *event)
return QObject::event(event);
}
+QString QDeclarativePixmapReply::errorString() const
+{
+ Q_D(const QDeclarativePixmapReply);
+ return d->errorString;
+}
+
QDeclarativePixmapReply::Status QDeclarativePixmapReply::status() const
{
Q_D(const QDeclarativePixmapReply);
@@ -586,7 +593,7 @@ bool QDeclarativePixmapReply::release(bool defer)
Note that images sourced from the network will always be loaded and
decoded asynchonously.
*/
-QDeclarativePixmapReply::Status QDeclarativePixmapCache::get(const QUrl& url, QPixmap *pixmap, QSize *impsize, bool async, int req_width, int req_height)
+QDeclarativePixmapReply::Status QDeclarativePixmapCache::get(const QUrl& url, QPixmap *pixmap, QString *errorString, QSize *impsize, bool async, int req_width, int req_height)
{
QDeclarativePixmapReply::Status status = QDeclarativePixmapReply::Unrequested;
QByteArray key = url.toEncoded(QUrl::FormattingOption(0x100));
@@ -609,17 +616,16 @@ QDeclarativePixmapReply::Status QDeclarativePixmapCache::get(const QUrl& url, QP
QFile f(lf);
QSize read_impsize;
if (f.open(QIODevice::ReadOnly)) {
- QString errorString;
QImage image;
- if (readImage(url, &f, &image, &errorString, &read_impsize, req_width, req_height)) {
+ if (readImage(url, &f, &image, errorString, &read_impsize, req_width, req_height)) {
*pixmap = QPixmap::fromImage(image);
} else {
- qWarning() << errorString;
*pixmap = QPixmap();
status = QDeclarativePixmapReply::Error;
}
} else {
- qWarning() << "Cannot open" << url;
+ if (errorString)
+ *errorString = QDeclarativeImageRequestHandler::tr("Cannot open: %1").arg(url.toString());
*pixmap = QPixmap();
status = QDeclarativePixmapReply::Error;
}
@@ -650,9 +656,15 @@ QDeclarativePixmapReply::Status QDeclarativePixmapCache::get(const QUrl& url, QP
} else if (QPixmapCache::find(strKey, pixmap)) {
if (iter != qmlActivePixmapReplies()->end()) {
status = (*iter)->status();
+ if (errorString)
+ *errorString = (*iter)->errorString();
(*iter)->release();
+ } else if (pixmap->isNull()) {
+ status = QDeclarativePixmapReply::Error;
+ if (errorString)
+ *errorString = QDeclarativeImageRequestHandler::tr("Unknown Error loading %1").arg(url);
} else {
- status = pixmap->isNull() ? QDeclarativePixmapReply::Error : QDeclarativePixmapReply::Ready;
+ status = QDeclarativePixmapReply::Ready;
}
} else if (iter != qmlActivePixmapReplies()->end()) {
status = QDeclarativePixmapReply::Loading;