[niepce] importer: camera importer now import (part 2)
- From: Hubert Figuière <hub src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [niepce] importer: camera importer now import (part 2)
- Date: Thu, 1 Jun 2017 03:40:19 +0000 (UTC)
commit 2ac9e28b5f7300b644a3070f43f914bd76b5a242
Author: Hubert Figuière <hub figuiere net>
Date: Thu May 25 21:26:46 2017 -0400
importer: camera importer now import (part 2)
- FileImporter callback now have a different signature
- Sadly temp file still imported in place
src/engine/importer/cameraimporter.cpp | 36 +++++++++++++++++++++++++---
src/engine/importer/directoryimporter.cpp | 4 +-
src/engine/importer/iimporter.hpp | 2 +-
src/fwk/utils/gphoto.cpp | 17 +++++++++++++
src/fwk/utils/gphoto.hpp | 3 +-
src/niepce/ui/niepcewindow.cpp | 8 +++++-
6 files changed, 60 insertions(+), 10 deletions(-)
---
diff --git a/src/engine/importer/cameraimporter.cpp b/src/engine/importer/cameraimporter.cpp
index 96466d2..4130325 100644
--- a/src/engine/importer/cameraimporter.cpp
+++ b/src/engine/importer/cameraimporter.cpp
@@ -18,6 +18,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
+#include <glibmm/miscutils.h>
#include "cameraimporter.hpp"
#include "fwk/base/debug.hpp"
@@ -42,6 +43,8 @@ public:
{ return m_filename; }
const std::string& path() const override
{ return m_path; }
+ const std::string& folder() const
+ { return m_folder; }
private:
std::string m_folder;
std::string m_filename;
@@ -101,10 +104,35 @@ bool CameraImporter::get_previews_for(const std::string& source,
bool CameraImporter::do_import(const std::string & source,
const FileImporter & importer)
{
- if (ensure_camera_open(source)) {
-
- }
- return false;
+ // XXX we shouldn't have to do that.
+ list_source_content(source, [this, importer] (auto file_list) {
+ char* tmp_dir = g_dir_make_tmp("niepce-camera-import-XXXXXX", nullptr);
+ if (!tmp_dir) {
+ return false;
+ }
+ std::string tmp_dir_path = tmp_dir;
+ g_free(tmp_dir);
+ tmp_dir = nullptr;
+
+ for (auto file: file_list) {
+ auto imported_camera_file =
+ std::dynamic_pointer_cast<CameraImportedFile>(file);
+ if (!imported_camera_file) {
+ continue;
+ }
+
+ std::string output_path =
+ Glib::build_filename(tmp_dir_path,
+ imported_camera_file->name());
+ if (this->m_camera->download_file(imported_camera_file->folder(),
+ imported_camera_file->name(),
+ output_path)) {
+ importer(output_path, true, true);
+ }
+ }
+ return true;
+ });
+ return true;
}
bool CameraImporter::ensure_camera_open(const std::string& source)
diff --git a/src/engine/importer/directoryimporter.cpp b/src/engine/importer/directoryimporter.cpp
index 76ce623..af94f62 100644
--- a/src/engine/importer/directoryimporter.cpp
+++ b/src/engine/importer/directoryimporter.cpp
@@ -78,7 +78,7 @@ bool DirectoryImporter::list_source_content(const std::string & source,
return true;
}
-bool DirectoryImporter::get_previews_for(const std::string& source,
+bool DirectoryImporter::get_previews_for(const std::string& /*source*/,
const std::list<std::string>& paths,
const PreviewReady& callback)
{
@@ -94,7 +94,7 @@ bool DirectoryImporter::do_import(const std::string& source,
const FileImporter& callback)
{
// pretty trivial, we have the source path.
- callback(source, false);
+ callback(source, false, false);
// XXX return a real error
return true;
diff --git a/src/engine/importer/iimporter.hpp b/src/engine/importer/iimporter.hpp
index 1f860b2..c30c4a8 100644
--- a/src/engine/importer/iimporter.hpp
+++ b/src/engine/importer/iimporter.hpp
@@ -52,7 +52,7 @@ public:
const PreviewReady& callback) = 0;
/** file importer callback */
- typedef std::function<void (const std::string&, bool)> FileImporter;
+ typedef std::function<void (const std::string&, bool, bool)> FileImporter;
/** perform import from source */
virtual bool do_import(const std::string& source,
const FileImporter& importer) = 0;
diff --git a/src/fwk/utils/gphoto.cpp b/src/fwk/utils/gphoto.cpp
index 3c2a24c..97dbe86 100644
--- a/src/fwk/utils/gphoto.cpp
+++ b/src/fwk/utils/gphoto.cpp
@@ -291,4 +291,21 @@ fwk::Thumbnail GpCamera::get_preview(const std::string& path) const
return thumbnail;
}
+bool GpCamera::download_file(const std::string& folder, const std::string& file,
+ const std::string& dest)
+{
+ CameraFile *camerafile;
+ DBG_OUT("importing into %s", dest.c_str());
+ gp_file_new(&camerafile);
+ int result = gp_camera_file_get(m_priv->camera, folder.c_str(), file.c_str(),
+ GP_FILE_TYPE_NORMAL, camerafile,
+ m_priv->context);
+ if (result == GP_OK) {
+ gp_file_save(camerafile, dest.c_str());
+ }
+ gp_file_unref(camerafile);
+
+ return (result == GP_OK);
+}
+
}
diff --git a/src/fwk/utils/gphoto.hpp b/src/fwk/utils/gphoto.hpp
index 95f694f..961b467 100644
--- a/src/fwk/utils/gphoto.hpp
+++ b/src/fwk/utils/gphoto.hpp
@@ -101,7 +101,8 @@ public:
bool close();
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,
+ const std::string& dest);
private:
void process_folders(const std::vector<std::string>& folders,
std::list<std::pair<std::string, std::string>>& files) const;
diff --git a/src/niepce/ui/niepcewindow.cpp b/src/niepce/ui/niepcewindow.cpp
index 83947ff..c01e098 100644
--- a/src/niepce/ui/niepcewindow.cpp
+++ b/src/niepce/ui/niepcewindow.cpp
@@ -270,8 +270,12 @@ void NiepceWindow::on_action_file_import()
if (importer) {
importer->do_import(
source,
- [this] (const std::string & path, bool manage) {
- m_libClient->importFromDirectory(path, manage);
+ [this] (const std::string & path, bool single, bool manage) {
+ if (single) {
+ m_libClient->importFile(path, manage);
+ } else {
+ m_libClient->importFromDirectory(path, manage);
+ }
});
}
break;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]