Implemented file deletion
authorMohammed Sameer <msameer@foolab.org>
Fri, 28 Dec 2012 02:58:30 +0000 (04:58 +0200)
committerMohammed Sameer <msameer@foolab.org>
Fri, 28 Dec 2012 02:58:30 +0000 (04:58 +0200)
qml/PostCapturePage.qml
src/deletehelper.cpp [new file with mode: 0644]
src/deletehelper.h [new file with mode: 0644]
src/main.cpp
src/src.pro

index 29a3470..d5e4516 100644 (file)
@@ -63,7 +63,14 @@ CameraPage {
                 acceptButtonText: qsTr("Yes");
                 rejectButtonText: qsTr("No");
                 onAccepted: {
-                        // TODO: delete file, remove from model and move to next item
+                        // TODO: Remove from model and move to next item
+                        if (!remove.remove(currentItem.itemUrl)) {
+                                showError(qsTr("Failed to delete item"));
+                        }
+                }
+
+                DeleteHelper {
+                        id: remove
                 }
         }
 
diff --git a/src/deletehelper.cpp b/src/deletehelper.cpp
new file mode 100644 (file)
index 0000000..9b2a632
--- /dev/null
@@ -0,0 +1,48 @@
+/*!
+ * 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 "deletehelper.h"
+#include <QUrl>
+#include <QFile>
+#include <QDeclarativeInfo>
+
+DeleteHelper::DeleteHelper(QObject *parent) :
+  QObject(parent) {
+
+}
+
+DeleteHelper::~DeleteHelper() {
+
+}
+
+bool  DeleteHelper::remove(const QUrl& path) {
+  QFile file(path.toLocalFile());
+
+  if (!file.exists()) {
+    return true;
+  }
+
+  if (!file.remove()) {
+    qmlInfo(this) << "Failed to remove file" << file.fileName() << file.errorString();
+    return false;
+  }
+
+  return true;
+}
diff --git a/src/deletehelper.h b/src/deletehelper.h
new file mode 100644 (file)
index 0000000..4287174
--- /dev/null
@@ -0,0 +1,40 @@
+// -*- c++ -*-
+
+/*!
+ * 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
+ */
+
+#ifndef DELETE_HELPER_H
+#define DELETE_HELPER_H
+
+#include <QObject>
+
+class QUrl;
+
+class DeleteHelper : public QObject {
+  Q_OBJECT
+
+public:
+  DeleteHelper(QObject *parent = 0);
+  ~DeleteHelper();
+
+  Q_INVOKABLE bool remove(const QUrl& path);
+};
+
+#endif /* DELETE_HELPER_H */
index 179e980..88b910f 100644 (file)
@@ -41,6 +41,7 @@
 #include "trackerstore.h"
 #include "focusrectangle.h"
 #include "sharehelper.h"
+#include "deletehelper.h"
 
 static void initQuill() {
   // TODO: All these are hardcoded.
@@ -84,6 +85,7 @@ Q_DECL_EXPORT int main(int argc, char *argv[]) {
   qmlRegisterType<TrackerStore>("CameraPlus", 1, 0, "TrackerStore");
   qmlRegisterType<FocusRectangle>("CameraPlus", 1, 0, "FocusRectangle");
   qmlRegisterType<ShareHelper>("CameraPlus", 1, 0, "ShareHelper");
+  qmlRegisterType<DeleteHelper>("CameraPlus", 1, 0, "DeleteHelper");
 
   QUrl sourceUrl = QUrl::fromLocalFile(QDir::currentPath() + "/main.qml");
   view.setSource(sourceUrl);
index 8f466a8..01ca649 100644 (file)
@@ -16,8 +16,8 @@ LIBS +=  -L../imports/ -limports -L../lib/ -lqtcamera
 
 SOURCES += main.cpp settings.cpp filenaming.cpp quillitem.cpp displaystate.cpp fsmonitor.cpp \
            cameraresources.cpp compass.cpp orientation.cpp geocode.cpp mountprotector.cpp \
-           trackerstore.cpp focusrectangle.cpp sharehelper.cpp
+           trackerstore.cpp focusrectangle.cpp sharehelper.cpp deletehelper.cpp
 
 HEADERS += settings.h filenaming.h quillitem.h displaystate.h fsmonitor.h \
            cameraresources.h compass.h orientation.h geocode.h mountprotector.h \
-           trackerstore.h focusrectangle.h sharehelper.h
+           trackerstore.h focusrectangle.h sharehelper.h deletehelper.h