[niepce] Issue #29 - Rework import to allow bundles from camera
- From: Hubert Figuière <hub src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [niepce] Issue #29 - Rework import to allow bundles from camera
- Date: Sat, 13 Oct 2018 17:46:01 +0000 (UTC)
commit 00096c4bbebcdec79e0e1b11725a28aed6ac9f9a
Author: Hubert Figuière <hub figuiere net>
Date: Sat Oct 13 06:58:19 2018 -0400
Issue #29 - Rework import to allow bundles from camera
https://gitlab.gnome.org/GNOME/niepce/issues/29
src/engine/importer/cameraimporter.cpp | 13 ++++++++-----
src/engine/importer/directoryimporter.cpp | 7 +++----
src/engine/importer/iimporter.hpp | 10 ++++------
src/engine/library/commands.rs | 29 -----------------------------
src/libraryclient/clientimpl.rs | 8 --------
src/libraryclient/clientinterface.rs | 4 ----
src/libraryclient/libraryclient.cpp | 11 +----------
src/libraryclient/libraryclient.hpp | 8 +-------
src/libraryclient/libraryclient.rs | 14 --------------
src/niepce/ui/workspacecontroller.cpp | 12 +++++-------
10 files changed, 22 insertions(+), 94 deletions(-)
---
diff --git a/src/engine/importer/cameraimporter.cpp b/src/engine/importer/cameraimporter.cpp
index 81eb893..2dfefe4 100644
--- a/src/engine/importer/cameraimporter.cpp
+++ b/src/engine/importer/cameraimporter.cpp
@@ -104,10 +104,12 @@ bool CameraImporter::get_previews_for(const std::string& source,
}
bool CameraImporter::do_import(const std::string& source, const std::string& dest_dir,
- const FileImporter & importer)
+ const FileImporter& importer)
{
// XXX we shouldn't have to do that.
- list_source_content(source, [this, dest_dir, importer] (std::list<ImportedFilePtr>&& file_list) {
+ list_source_content(
+ source,
+ [this, dest_dir, importer] (std::list<ImportedFilePtr>&& file_list) {
auto tmp_dir_path = dest_dir.empty() ?
fwk::make_tmp_dir("niepce-camera-import-XXXXXX") :
dest_dir;
@@ -119,6 +121,7 @@ bool CameraImporter::do_import(const std::string& source, const std::string& des
DBG_ASSERT(!tmp_dir_path.empty(), "Dest dir is empty");
// XXX check we don't return an empty string.
+ fwk::FileListPtr files = std::make_shared<fwk::FileList>();
for (auto file: file_list) {
auto imported_camera_file =
std::dynamic_pointer_cast<CameraImportedFile>(file);
@@ -132,11 +135,11 @@ bool CameraImporter::do_import(const std::string& source, const std::string& des
if (this->m_camera->download_file(imported_camera_file->folder(),
imported_camera_file->name(),
output_path)) {
- // XXX else report error.
- importer(output_path, IImporter::Import::SINGLE, Managed::NO);
+ files->push_back(output_path);
}
}
- return true;
+
+ return importer(tmp_dir_path, files, Managed::NO);
});
return true;
}
diff --git a/src/engine/importer/directoryimporter.cpp b/src/engine/importer/directoryimporter.cpp
index 3eed11a..6eb50f4 100644
--- a/src/engine/importer/directoryimporter.cpp
+++ b/src/engine/importer/directoryimporter.cpp
@@ -93,11 +93,10 @@ bool DirectoryImporter::get_previews_for(const std::string& /*source*/,
bool DirectoryImporter::do_import(const std::string& source, const std::string& /*dest_dir*/,
const FileImporter& callback)
{
- // pretty trivial, we have the source path.
- callback(source, IImporter::Import::DIRECTORY, Managed::NO);
+ fwk::FileListPtr files;
+ files = fwk::FileList::getFilesFromDirectory(source, &fwk::filter_none);
- // XXX return a real error
- return true;
+ return callback(source, files, Managed::NO);
}
}
diff --git a/src/engine/importer/iimporter.hpp b/src/engine/importer/iimporter.hpp
index a8de7c2..5db673f 100644
--- a/src/engine/importer/iimporter.hpp
+++ b/src/engine/importer/iimporter.hpp
@@ -25,6 +25,7 @@
#include <functional>
#include "fwk/toolkit/thumbnail.hpp"
+#include "fwk/utils/files.hpp"
#include "engine/importer/importedfile.hpp"
#include "rust_bindings.hpp"
@@ -53,12 +54,9 @@ public:
const std::list<std::string>& paths,
const PreviewReady& callback) = 0;
- enum class Import {
- SINGLE,
- DIRECTORY
- };
- /** file importer callback */
- typedef std::function<void (const std::string&, Import, Managed)> FileImporter;
+ /** file importer callback
+ */
+ typedef std::function<bool (const std::string& path, const fwk::FileListPtr&, Managed)> FileImporter;
/** perform import from source
* @param source the source identified by a string.
* @param dest_dir the suggested destination directory is the importer needs to copy
diff --git a/src/engine/library/commands.rs b/src/engine/library/commands.rs
index ae53601..62c803b 100644
--- a/src/engine/library/commands.rs
+++ b/src/engine/library/commands.rs
@@ -18,7 +18,6 @@
*/
use std::os::raw::c_void;
-use std::path::Path;
use fwk::PropertyValue;
use engine::db::LibraryId;
@@ -104,34 +103,6 @@ fn get_folder_for_import(lib: &Library, folder: &str) -> library::Result<LibFold
}
}
-pub fn cmd_import_file(lib: &Library, path: &str, manage: Managed) -> bool {
- dbg_assert!(manage == Managed::NO, "managing file is currently unsupported");
-
- let mut bundle = FileBundle::new();
- bundle.add(path);
-
- let folder = Path::new(path).parent().unwrap_or(Path::new(""));
-
- match get_folder_for_import(lib, &*folder.to_string_lossy()) {
- Ok(libfolder) => {
- match lib.add_bundle(libfolder.id(), &bundle, manage) {
- Ok(_) => {
- lib.notify(Box::new(LibNotification::AddedFile));
- true
- },
- Err(err) => {
- err_out_line!("Failed to add bundle {:?}", err);
- false
- }
- }
- },
- Err(err) => {
- err_out_line!("Can't get folder name for import: {:?}.", err);
- false
- }
- }
-}
-
pub fn cmd_import_files(lib: &Library, folder: &str, files: &Vec<String>,
manage: Managed) -> bool {
dbg_assert!(manage == Managed::NO, "managing file is currently unsupported");
diff --git a/src/libraryclient/clientimpl.rs b/src/libraryclient/clientimpl.rs
index 7e6a680..c2c4039 100644
--- a/src/libraryclient/clientimpl.rs
+++ b/src/libraryclient/clientimpl.rs
@@ -217,14 +217,6 @@ impl ClientInterface for ClientImpl {
});
}
- /// Import file
- /// @param path the file path
- /// @param manage true if imported file have to be managed
- fn import_file(&mut self, path: String, manage: Managed) {
- self.schedule_op(move |lib| {
- commands::cmd_import_file(&lib, &path, manage)
- });
- }
/// Import files from a directory
/// @param dir the directory
/// @param manage true if imports have to be managed
diff --git a/src/libraryclient/clientinterface.rs b/src/libraryclient/clientinterface.rs
index 7e3e8e4..e92b2fb 100644
--- a/src/libraryclient/clientinterface.rs
+++ b/src/libraryclient/clientinterface.rs
@@ -54,10 +54,6 @@ pub trait ClientInterface {
/// tell to process the Xmp update Queue
fn process_xmp_update_queue(&mut self, write_xmp: bool);
- /// Import file
- /// @param path the file path
- /// @param manage true if imported file have to be managed
- fn import_file(&mut self, path: String, manage: Managed);
/// Import files from a directory
/// @param dir the directory
/// @param files the files to import
diff --git a/src/libraryclient/libraryclient.cpp b/src/libraryclient/libraryclient.cpp
index b5134dd..161b4c7 100644
--- a/src/libraryclient/libraryclient.cpp
+++ b/src/libraryclient/libraryclient.cpp
@@ -1,7 +1,7 @@
/*
* niepce - libraryclient/libraryclient.cpp
*
- * Copyright (C) 2007-2017 Hubert Figuière
+ * Copyright (C) 2007-2018 Hubert Figuière
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -19,7 +19,6 @@
#include "fwk/base/moniker.hpp"
-#include "fwk/utils/files.hpp"
#include "libraryclient.hpp"
#include "uidataprovider.hpp"
@@ -46,14 +45,6 @@ LibraryClient::~LibraryClient()
{
}
-void LibraryClient::importFromDirectory(const std::string& dir, eng::Managed manage)
-{
- fwk::FileListPtr files;
- files = fwk::FileList::getFilesFromDirectory(dir, &fwk::filter_none);
-
- ffi::libraryclient_import_files(m_client.get(), dir.c_str(), files.get(), manage);
-}
-
}
/*
Local Variables:
diff --git a/src/libraryclient/libraryclient.hpp b/src/libraryclient/libraryclient.hpp
index de7c948..61a60d8 100644
--- a/src/libraryclient/libraryclient.hpp
+++ b/src/libraryclient/libraryclient.hpp
@@ -1,7 +1,7 @@
/*
* niepce - libraryclient/libraryclient.hpp
*
- * Copyright (C) 2007-2015 Hubert Figuière
+ * Copyright (C) 2007-2018 Hubert Figuière
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -44,12 +44,6 @@ public:
LibraryClient(const fwk::Moniker & moniker, uint64_t notif_id);
virtual ~LibraryClient();
- /** Import files from a directory
- * @param dir the directory
- * @param manage true if imports have to be managed
- */
- void importFromDirectory(const std::string & dir, eng::Managed manage);
-
eng::ThumbnailCache & thumbnailCache()
{ return m_thumbnailCache; }
diff --git a/src/libraryclient/libraryclient.rs b/src/libraryclient/libraryclient.rs
index 36c98e4..e752732 100644
--- a/src/libraryclient/libraryclient.rs
+++ b/src/libraryclient/libraryclient.rs
@@ -140,12 +140,6 @@ impl ClientInterface for LibraryClient {
self.pimpl.process_xmp_update_queue(write_xmp);
}
- /// Import file
- /// @param path the file path
- /// @param manage true if imported file have to be managed
- fn import_file(&mut self, path: String, manage: Managed) {
- self.pimpl.import_file(path, manage);
- }
/// Import files from a directory
/// @param dir the directory
/// @param manage true if imports have to be managed
@@ -312,14 +306,6 @@ pub extern "C" fn libraryclient_process_xmp_update_queue(client: &mut LibraryCli
client.unwrap_mut().process_xmp_update_queue(write_xmp);
}
-#[no_mangle]
-pub extern "C" fn libraryclient_import_file(client: &mut LibraryClientWrapper,
- file_path: *const c_char,
- manage: Managed) {
- let path = String::from(unsafe { CStr::from_ptr(file_path) }.to_string_lossy());
- client.unwrap_mut().import_file(path, manage);
-}
-
#[no_mangle]
pub extern "C" fn libraryclient_import_files(client: &mut LibraryClientWrapper,
dir: *const c_char, cfiles: &mut FileList,
diff --git a/src/niepce/ui/workspacecontroller.cpp b/src/niepce/ui/workspacecontroller.cpp
index 8b9ec0c..5b28b77 100644
--- a/src/niepce/ui/workspacecontroller.cpp
+++ b/src/niepce/ui/workspacecontroller.cpp
@@ -135,13 +135,11 @@ void WorkspaceController::action_file_import()
auto dest_dir = import_dialog->get_dest_dir();
importer->do_import(
source, dest_dir,
- [this] (const std::string & path, IImporter::Import type, Managed manage) {
- if (type == IImporter::Import::SINGLE) {
- ffi::libraryclient_import_file(getLibraryClient()->client(),
- path.c_str(), manage);
- } else {
- getLibraryClient()->importFromDirectory(path, manage);
- }
+ [this] (const std::string& path, const fwk::FileListPtr& files, Managed manage) -> bool {
+ ffi::libraryclient_import_files(
+ getLibraryClient()->client(), path.c_str(), files.get(), manage);
+ // XXX the libraryclient function returns void
+ return true;
});
}
break;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]