Add an error property to QuillItem and show a label when we cannot load it
authorMohammed Sameer <msameer@foolab.org>
Wed, 12 Sep 2012 17:43:55 +0000 (20:43 +0300)
committerMohammed Sameer <msameer@foolab.org>
Wed, 12 Sep 2012 17:43:55 +0000 (20:43 +0300)
qml/PostCapturePage.qml
src/quillitem.cpp
src/quillitem.h

index 327a15e..8e560a8 100644 (file)
@@ -55,15 +55,26 @@ Page {
                         width: view.width
                         height: view.height
 
+                        Label {
+                                width: view.width - 10
+                                height: view.height
+                                anchors.centerIn: parent
+                                visible: item.error
+                                text: qsTr("Failed to load preview");
+                                verticalAlignment: Text.AlignVCenter
+                                horizontalAlignment: Text.AlignHCenter
+                                font.pixelSize: 32
+                        }
+
                         QuillItem {
+                                id: item
                                 source: url
                                 mimeType: mime
                                 width: view.width - 10
                                 height: view.height
                                 anchors.centerIn: parent
-                                // TODO: does not work because of preloading
-                                //                        onError: showError(qsTr("Failed to load image"));
-                                }
+                                visible: !item.error
+                        }
                 }
         }
 
index 79f6912..6f17525 100644 (file)
@@ -6,7 +6,7 @@
 #include <QDir>
 
 QuillItem::QuillItem(QDeclarativeItem *parent) :
-  QDeclarativeItem(parent), m_file(0) {
+  QDeclarativeItem(parent), m_file(0), m_error(false) {
 
   setFlag(QGraphicsItem::ItemHasNoContents, false);
 
@@ -72,7 +72,16 @@ void QuillItem::setMimeType(const QString& mime) {
   emit mimeTypeChanged();
 }
 
+bool QuillItem::error() const {
+  return m_error;
+}
+
 void QuillItem::recreate() {
+  if (m_error) {
+    m_error = false;
+    emit errorChanged();
+  }
+
   if (m_file) {
     m_file->deleteLater();
   }
@@ -128,6 +137,13 @@ bool QuillItem::fileError() {
     QMetaObject::invokeMethod(this, "error", Qt::QueuedConnection,
                              Q_ARG(QString, err.errorData()));
     m_file->deleteLater(); m_file = 0;
+
+    if (!m_error) {
+      m_error = true;
+
+      emit errorChanged();
+    }
+
     return true;
   }
 
index ac197f5..fd6d521 100644 (file)
@@ -12,6 +12,7 @@ class QuillItem : public QDeclarativeItem {
 
   Q_PROPERTY(QUrl source READ source WRITE setSource NOTIFY sourceChanged);
   Q_PROPERTY(QString mimeType READ mimeType WRITE setMimeType NOTIFY mimeTypeChanged);
+  Q_PROPERTY(bool error READ error NOTIFY errorChanged);
 
 public:
   QuillItem(QDeclarativeItem *parent = 0);
@@ -27,10 +28,13 @@ public:
 
   virtual void componentComplete();
 
+  bool error() const;
+
 signals:
   void sourceChanged();
   void error(const QString& err);
   void mimeTypeChanged();
+  void errorChanged();
 
 private slots:
   void fileLoaded();
@@ -42,6 +46,7 @@ private:
   QuillFile *m_file;
   QUrl m_url;
   QString m_type;
+  bool m_error;
 };
 
 #endif /* QUILL_ITEM_H */