obsolete TODO items
[harmattan/cameraplus] / src / quillitem.cpp
index c6e02ac..be9667f 100644 (file)
@@ -1,3 +1,23 @@
+/*!
+ * This file is part of CameraPlus.
+ *
+ * Copyright (C) 2012 Mohammed Sameer <msameer@foolab.org>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+ */
+
 #include "quillitem.h"
 #include <QuillFile>
 #include <QUrl>
 #include <QDir>
 
 QuillItem::QuillItem(QDeclarativeItem *parent) :
-  QDeclarativeItem(parent), m_file(0) {
+  QDeclarativeItem(parent), m_file(0), m_error(false) {
 
   setFlag(QGraphicsItem::ItemHasNoContents, false);
-
-  static bool init = false;
-  if (!init) {
-    Quill::setPreviewLevelCount(1);
-    Quill::setPreviewSize(0, QSize(864, 480)); // TODO:
-    Quill::setMinimumPreviewSize(0, QSize(864, 480)); // TODO:
-    Quill::setThumbnailExtension("jpeg"); // TODO:
-    Quill::setThumbnailFlavorName(0, "screen");
-    Quill::setBackgroundRenderingColor(Qt::black);
-    QString tempPath(QDir::homePath() +  QDir::separator() + ".config" +
-                     QDir::separator() + "quill" + QDir::separator() + "tmp");
-    QDir().mkpath(tempPath);
-    Quill::setTemporaryFilePath(tempPath);
-    init = true;
-  }
 }
 
 QuillItem::~QuillItem() {
   delete m_file; m_file = 0;
 }
 
-QUrl QuillItem::source() const {
-  if (m_file) {
-    return QUrl::fromLocalFile(m_file->fileName());
-  }
+void QuillItem::componentComplete() {
+  QDeclarativeItem::componentComplete();
+
+  recreate();
+}
 
-  return QUrl();
+QUrl QuillItem::source() const {
+  return m_url;
 }
 
 void QuillItem::setSource(const QUrl& src) {
@@ -43,11 +50,48 @@ void QuillItem::setSource(const QUrl& src) {
     return;
   }
 
+  m_url = src;
+
+  if (isComponentComplete()) {
+    recreate();
+  }
+
+  emit sourceChanged();
+}
+
+QString QuillItem::mimeType() const {
+  return m_type;
+}
+
+void QuillItem::setMimeType(const QString& mime) {
+  if (mimeType() == mime) {
+    return;
+  }
+
+  m_type = mime;
+
+  if (isComponentComplete()) {
+    recreate();
+  }
+
+  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();
   }
 
-  m_file = new QuillFile(src.toLocalFile());
+  m_file = new QuillFile(m_url.toLocalFile(), m_type);
 
   QObject::connect(m_file, SIGNAL(error(QuillError)),
          this, SLOT(fileError()), Qt::QueuedConnection);
@@ -65,8 +109,6 @@ void QuillItem::setSource(const QUrl& src) {
   if (fileError()) {
     return;
   }
-
-  emit sourceChanged();
 }
 
 void QuillItem::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget) {
@@ -93,12 +135,21 @@ bool QuillItem::fileError() {
   }
 
   QuillError err = m_file->error();
+
   if (err.errorCode() != QuillError::NoError) {
-    qWarning() << "Error loading file" << m_file->fileName() << err.errorData();
+    qWarning() << "Error loading file" << m_file->fileName()
+              << "Code" << err.errorCode() << "Source" << err.errorSource();
 
     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;
   }