[niepce] importer: Rewrote the async listSourceContent
- From: Hubert Figuière <hub src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [niepce] importer: Rewrote the async listSourceContent
- Date: Tue, 16 May 2017 04:48:49 +0000 (UTC)
commit 9184fe86a6d866b2c5c623848d0cdaeb290baaba
Author: Hubert Figuière <hub figuiere net>
Date: Mon May 15 00:46:27 2017 -0400
importer: Rewrote the async listSourceContent
src/engine/importer/directoryimporter.cpp | 31 +++++++-----------
src/engine/importer/directoryimporter.hpp | 12 +++----
src/engine/importer/iimporter.hpp | 15 +++++----
src/niepce/ui/dialogs/importdialog.cpp | 47 ++++++++++++++++++----------
src/niepce/ui/dialogs/importdialog.hpp | 8 ++++-
5 files changed, 62 insertions(+), 51 deletions(-)
---
diff --git a/src/engine/importer/directoryimporter.cpp b/src/engine/importer/directoryimporter.cpp
index dfeb25b..6bb5aaa 100644
--- a/src/engine/importer/directoryimporter.cpp
+++ b/src/engine/importer/directoryimporter.cpp
@@ -1,7 +1,7 @@
/*
* niepce - engine/importer/directoryimporter.cpp
*
- * Copyright (C) 2014-2015 Hubert Figuière
+ * Copyright (C) 2014-2017 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
@@ -58,35 +58,28 @@ std::string DirectoryImporter::name() const
return _("Directory");
}
-bool DirectoryImporter::listSourceContent(const std::string & source)
+bool DirectoryImporter::listSourceContent(const std::string & source,
+ const SourceContentReady& callback)
{
- auto content =
+ auto files =
fwk::FileList::getFilesFromDirectory(source,
&fwk::filter_xmp_out);
- for(const auto & entry : *content)
- {
- std::lock_guard<std::mutex> lock(m_content_lock);
- m_content.push_back(ImportedFile::Ptr(new DirectoryImportedFile(entry)));
- }
- return true;
-}
-std::list<ImportedFile::Ptr> DirectoryImporter::getSourceContent()
-{
std::list<ImportedFile::Ptr> content;
+ for(const auto & entry : *files)
{
- std::lock_guard<std::mutex> lock(m_content_lock);
- content = std::move(m_content);
- m_content.clear();
+ content.push_back(ImportedFile::Ptr(new DirectoryImportedFile(entry)));
}
- return content;
+ callback(std::move(content));
+
+ return true;
}
-bool DirectoryImporter::doImport(const std::string & source,
- const file_importer & importer)
+bool DirectoryImporter::doImport(const std::string& source,
+ const FileImporter& callback)
{
// pretty trivial, we have the source path.
- importer(source, false);
+ callback(source, false);
// XXX return a real error
return true;
diff --git a/src/engine/importer/directoryimporter.hpp b/src/engine/importer/directoryimporter.hpp
index 0a31226..b778868 100644
--- a/src/engine/importer/directoryimporter.hpp
+++ b/src/engine/importer/directoryimporter.hpp
@@ -1,7 +1,7 @@
/*
* niepce - engine/importer/directoryimporter.hpp
*
- * Copyright (C) 2014-2015 Hubert Figuière
+ * Copyright (C) 2014-2017 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
@@ -36,13 +36,11 @@ public:
std::string name() const override;
- bool listSourceContent(const std::string & source) override;
- std::list<ImportedFile::Ptr> getSourceContent() override;
+ bool listSourceContent(const std::string & source,
+ const SourceContentReady& callback) override;
+
bool doImport(const std::string & source,
- const file_importer & importer) override;
-private:
- std::mutex m_content_lock;
- std::list<ImportedFile::Ptr> m_content;
+ const FileImporter & importer) override;
};
}
diff --git a/src/engine/importer/iimporter.hpp b/src/engine/importer/iimporter.hpp
index f75bd12..e5f16ff 100644
--- a/src/engine/importer/iimporter.hpp
+++ b/src/engine/importer/iimporter.hpp
@@ -1,7 +1,7 @@
/*
* niepce - engine/importer/iimporter.hpp
*
- * Copyright (C) 2014-2015 Hubert Figuière
+ * Copyright (C) 2014-2017 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
@@ -31,21 +31,22 @@ class IImporter {
public:
virtual ~IImporter() {}
- /** file importer callback */
- typedef std::function<void (const std::string&, bool)> file_importer;
/** User visible importer name. */
virtual std::string name() const = 0;
+ /** Source content is ready */
+ typedef std::function<void (std::list<ImportedFile::Ptr>&&)> SourceContentReady;
/** list the source content and store it. */
- virtual bool listSourceContent(const std::string & source) = 0;
+ virtual bool listSourceContent(const std::string & source,
+ const SourceContentReady& callback) = 0;
- /** get the source content. */
- virtual std::list<ImportedFile::Ptr> getSourceContent() = 0;
+ /** file importer callback */
+ typedef std::function<void (const std::string&, bool)> FileImporter;
/** perform import from source */
virtual bool doImport(const std::string & source,
- const file_importer & importer) = 0;
+ const FileImporter & importer) = 0;
};
diff --git a/src/niepce/ui/dialogs/importdialog.cpp b/src/niepce/ui/dialogs/importdialog.cpp
index e271065..ea4085b 100644
--- a/src/niepce/ui/dialogs/importdialog.cpp
+++ b/src/niepce/ui/dialogs/importdialog.cpp
@@ -1,7 +1,7 @@
/*
- * niepce - niepce/ui/importdialog.cpp
+ * niepce - niepce/ui/dialogs/importdialog.cpp
*
- * Copyright (C) 2008-2015 Hubert Figuière
+ * Copyright (C) 2008-2017 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
@@ -55,6 +55,8 @@ ImportDialog::ImportDialog()
, m_attributesScrolled(nullptr)
, m_images_list_scrolled(nullptr)
{
+ m_received_files_to_import.connect(
+ sigc::mem_fun(this, &ImportDialog::append_files_to_import));
}
ImportDialog::~ImportDialog()
@@ -135,30 +137,41 @@ void ImportDialog::setToImport(const Glib::ustring & f)
// FIXME this should be the right kind
m_importer = std::make_shared<eng::DirectoryImporter>();
}
+
+ eng::IImporter::SourceContentReady source_content_ready =
+ [this] (std::list<eng::ImportedFile::Ptr>&& list_to_import) {
+ {
+ std::lock_guard<std::mutex> lock(this->m_files_to_import_lock);
+ this->m_files_to_import = list_to_import;
+ }
+ this->m_received_files_to_import.emit();
+ };
+
+
+ m_images_list_model->clear();
+ m_files_to_import.clear();
+
auto importer = m_importer;
auto source_content =
std::async(std::launch::async,
- [f, importer] () {
- return importer->listSourceContent(f);
+ [f, importer, source_content_ready] () {
+ return importer->listSourceContent(f, source_content_ready);
});
m_folder_path_source = f;
m_destinationFolder->set_text(fwk::path_basename(f));
m_directory_name->set_text(f);
+}
- m_images_list_model->clear();
-
- // XXX this should be an event from the async result instead
- if (source_content.get()) {
- auto list_to_import = m_importer->getSourceContent();
-
- for(const auto & _f : list_to_import) {
- DBG_OUT("selected %s", _f->name().c_str());
- Gtk::TreeIter iter = m_images_list_model->append();
- iter->set_value(m_grid_columns.filename, Glib::ustring(_f->name()));
- iter->set_value(m_grid_columns.file, std::move(_f));
- }
- }
+void ImportDialog::append_files_to_import()
+{
+ std::lock_guard<std::mutex> lock(this->m_files_to_import_lock);
+ for(const auto & f : m_files_to_import) {
+ DBG_OUT("selected %s", f->name().c_str());
+ Gtk::TreeIter iter = m_images_list_model->append();
+ iter->set_value(m_grid_columns.filename, Glib::ustring(f->name()));
+ iter->set_value(m_grid_columns.file, std::move(f));
+ }
}
}
diff --git a/src/niepce/ui/dialogs/importdialog.hpp b/src/niepce/ui/dialogs/importdialog.hpp
index f399c9e..c02ef0c 100644
--- a/src/niepce/ui/dialogs/importdialog.hpp
+++ b/src/niepce/ui/dialogs/importdialog.hpp
@@ -1,7 +1,7 @@
/*
* niepce - niepce/ui/dialogs/importdialog.h
*
- * Copyright (C) 2008-2015 Hubert Figuière
+ * Copyright (C) 2008-2017 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
@@ -26,6 +26,7 @@
#include <string>
#include <glibmm/refptr.h>
+#include <glibmm/dispatcher.h>
#include "engine/importer/importedfile.hpp"
#include "fwk/toolkit/gtkutils.hpp"
@@ -83,6 +84,7 @@ private:
class ImportParam;
void doSelectDirectories();
+ void append_files_to_import();
std::shared_ptr<eng::IImporter> m_importer; // as shared_ptr<> for lambda capture
Glib::ustring m_folder_path_source;
@@ -100,6 +102,10 @@ private:
Gtk::IconView *m_gridview;
MetaDataPaneController::Ptr m_metadata_pane;
+
+ Glib::Dispatcher m_received_files_to_import;
+ std::mutex m_files_to_import_lock;
+ std::list<eng::ImportedFile::Ptr> m_files_to_import;
};
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]