[niepce] importer: unmount the camera if it is claimed



commit 84f50710947b49ea619e3ec47798bb56a22ad982
Author: Hubert Figuière <hub figuiere net>
Date:   Mon May 29 22:20:19 2017 -0400

    importer: unmount the camera if it is claimed

 src/fwk/toolkit/gphoto.cpp |   26 +++++++++++++++++++++++++-
 src/fwk/toolkit/gphoto.hpp |    1 +
 2 files changed, 26 insertions(+), 1 deletions(-)
---
diff --git a/src/fwk/toolkit/gphoto.cpp b/src/fwk/toolkit/gphoto.cpp
index 6bdf5f8..b8ae860 100644
--- a/src/fwk/toolkit/gphoto.cpp
+++ b/src/fwk/toolkit/gphoto.cpp
@@ -29,7 +29,7 @@
 #include <gphoto2-port-result.h>
 
 #include <glibmm/miscutils.h>
-
+#include <giomm/file.h>
 #include <gdkmm/pixbufloader.h>
 
 #include "fwk/base/debug.hpp"
@@ -220,6 +220,10 @@ bool GpCamera::open()
             DBG_OUT("camera open");
             success = true;
             break;
+        case GP_ERROR_IO_USB_CLAIM:
+            DBG_OUT("will try to unmount GVFS");
+            try_unmount_camera();
+            break;
         case GP_ERROR_CANCEL:
             break;
         default:
@@ -230,6 +234,26 @@ bool GpCamera::open()
     return success;
 }
 
+/** A hackish attempt to unmount the camera */
+bool GpCamera::try_unmount_camera()
+{
+    std::string camera_mount = "gphoto2://[" + m_device->get_path() + "]/";
+
+    try {
+        auto file = Gio::File::create_for_uri(camera_mount);
+        auto mount = file->find_enclosing_mount();
+        if (!mount) {
+            return false;
+        }
+        auto mount_op = Gio::MountOperation::create();
+        mount->unmount(mount_op, Gio::MOUNT_UNMOUNT_NONE);
+    } catch(const Gio::Error& e) {
+        ERR_OUT("Gio::Error unmounting camera %d", e.code());
+        return false;
+    }
+    return true;
+}
+
 bool GpCamera::close()
 {
     gp_camera_unref(m_priv->camera);
diff --git a/src/fwk/toolkit/gphoto.hpp b/src/fwk/toolkit/gphoto.hpp
index b50d70e..615cae0 100644
--- a/src/fwk/toolkit/gphoto.hpp
+++ b/src/fwk/toolkit/gphoto.hpp
@@ -109,6 +109,7 @@ public:
         { return m_device->get_path(); }
     bool open();
     bool close();
+    bool try_unmount_camera();
     std::list<std::pair<std::string, std::string>> list_content() const;
     fwk::Thumbnail get_preview(const std::string& path) const;
     bool download_file(const std::string& folder, const std::string& file,


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]