[niepce: 1/12] Some cleanup. ASync scanning the directory



commit bc84860d9a3a8828bd187825a4525ba3a4ffd703
Author: Hubert Figuière <hub figuiere net>
Date:   Sun Oct 5 00:21:10 2014 -0400

    Some cleanup.
    ASync scanning the directory

 src/niepce/ui/dialogs/importdialog.cpp |   63 ++++++++++++++++++--------------
 src/niepce/ui/dialogs/importdialog.hpp |   10 +++---
 src/niepce/ui/niepcewindow.cpp         |    5 ++-
 3 files changed, 44 insertions(+), 34 deletions(-)
---
diff --git a/src/niepce/ui/dialogs/importdialog.cpp b/src/niepce/ui/dialogs/importdialog.cpp
index 1c255a4..ad3bdb6 100644
--- a/src/niepce/ui/dialogs/importdialog.cpp
+++ b/src/niepce/ui/dialogs/importdialog.cpp
@@ -1,7 +1,7 @@
 /*
  * niepce - niepce/ui/importdialog.cpp
  *
- * Copyright (C) 2008-2013 Hubert Figuiere
+ * Copyright (C) 2008-2014 Hubert Figuiere
  *
  * 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
@@ -18,6 +18,7 @@
  */
 
 
+#include <future>
 #include <functional>
 
 #include <glibmm/i18n.h>
@@ -42,12 +43,12 @@ using fwk::Application;
 namespace ui {
 
 ImportDialog::ImportDialog()
-    : fwk::Dialog(GLADEDIR"importdialog.ui", "importDialog"),
-      m_date_tz_combo(nullptr),
-         m_ufraw_import_check(nullptr),
-         m_rawstudio_import_check(nullptr),
-         m_directory_name(nullptr),
-      m_imagesList(nullptr)
+    : fwk::Dialog(GLADEDIR"importdialog.ui", "importDialog")
+    , m_date_tz_combo(nullptr)
+    , m_ufraw_import_check(nullptr)
+    , m_rawstudio_import_check(nullptr)
+    , m_directory_name(nullptr)
+    , m_imagesList(nullptr)
 {
 }
 
@@ -60,60 +61,68 @@ void ImportDialog::setup_widget()
 
     add_header(_("Import"));
 
-    Glib::RefPtr<Gtk::Builder> _builder = builder();
+    Glib::RefPtr<Gtk::Builder> a_builder = builder();
     Gtk::Button *select_directories = nullptr;
 
-    _builder->get_widget("select_directories", select_directories);
+    a_builder->get_widget("select_directories", select_directories);
     select_directories->signal_clicked().connect(
-        sigc::mem_fun(*this, &ImportDialog::do_select_directories));
-    _builder->get_widget("date_tz_combo", m_date_tz_combo);
-    _builder->get_widget("ufraw_import_check", m_ufraw_import_check);
-    _builder->get_widget("rawstudio_import_check", m_rawstudio_import_check);
-    _builder->get_widget("directory_name", m_directory_name);
-    _builder->get_widget("imagesList", m_imagesList);
-    _builder->get_widget("destinationFolder", m_destinationFolder);
+        sigc::mem_fun(*this, &ImportDialog::doSelectDirectories));
+    a_builder->get_widget("date_tz_combo", m_date_tz_combo);
+    a_builder->get_widget("ufraw_import_check", m_ufraw_import_check);
+    a_builder->get_widget("rawstudio_import_check", m_rawstudio_import_check);
+    a_builder->get_widget("directory_name", m_directory_name);
+    a_builder->get_widget("imagesList", m_imagesList);
+    a_builder->get_widget("destinationFolder", m_destinationFolder);
+
     m_imagesListModel = m_imagesListModelRecord.inject(*m_imagesList);
     m_imagesList->set_model(m_imagesListModel);
     m_is_setup = true;
 }
 
 
-void ImportDialog::do_select_directories()
+void ImportDialog::doSelectDirectories()
 {
     Configuration & cfg = Application::app()->config();
-       
+
     Gtk::FileChooserDialog dialog(gtkWindow(), _("Import picture folder"),
                                   Gtk::FILE_CHOOSER_ACTION_SELECT_FOLDER);
-       
+
     dialog.add_button(_("Cancel"), Gtk::RESPONSE_CANCEL);
     dialog.add_button(_("Import"), Gtk::RESPONSE_OK);
     dialog.set_select_multiple(false);
-    std::string last_import_location;
-    last_import_location = cfg.getValue("last_import_location", "");
+
+    std::string last_import_location = cfg.getValue("last_import_location", "");
     if(!last_import_location.empty()) {
         dialog.set_filename(last_import_location);
     }
-       
+
     int result = dialog.run();
     switch(result)
     {
     case Gtk::RESPONSE_OK:
-        set_to_import(dialog.get_filename());
+        setToImport(dialog.get_filename());
         break;
     default:
         break;
     }
 }
 
-void ImportDialog::set_to_import(const Glib::ustring & f)
+void ImportDialog::setToImport(const Glib::ustring & f)
 {
+
+    auto future1 = std::async(std::launch::async,
+                              [f] () {
+                                  return fwk::FileList::getFilesFromDirectory(
+                                      f, &fwk::filter_xmp_out);
+                              });
+
     m_folder_path_to_import = f;
     m_destinationFolder->set_text(fwk::path_basename(f));
     m_directory_name->set_text(f);
 
     m_imagesListModel->clear();
-    fwk::FileList::Ptr list_to_import
-        = fwk::FileList::getFilesFromDirectory(f, &fwk::filter_xmp_out);
+
+    auto list_to_import = future1.get();
 
     std::for_each(list_to_import->begin(), list_to_import->end(),
                   [this] (const std::string & s) {
@@ -132,7 +141,7 @@ void ImportDialog::set_to_import(const Glib::ustring & f)
   c-file-style:"stroustrup"
   c-file-offsets:((innamespace . 0))
   indent-tabs-mode:nil
-  tab-width:4
+  tab-width:2
   fill-column:99
   End:
 */
diff --git a/src/niepce/ui/dialogs/importdialog.hpp b/src/niepce/ui/dialogs/importdialog.hpp
index d3fad3d..45fcbab 100644
--- a/src/niepce/ui/dialogs/importdialog.hpp
+++ b/src/niepce/ui/dialogs/importdialog.hpp
@@ -42,7 +42,7 @@ namespace Gtk {
 
 namespace ui {
 
-class ImportDialog 
+class ImportDialog
        : public fwk::Dialog
 {
 public:
@@ -54,15 +54,15 @@ public:
 
 //     const std::list<std::string> & to_import() const
 //             { return m_list_to_import; }
-    const Glib::ustring & path_to_import() const
+    const Glib::ustring & pathToImport() const
         { return m_folder_path_to_import; }
-       void set_to_import(const Glib::ustring & f);
+       void setToImport(const Glib::ustring & f);
 
 private:
        class ImportParam;
 
-       void do_select_directories();
-       
+       void doSelectDirectories();
+
   Glib::ustring m_folder_path_to_import;
 //     std::list<std::string> m_list_to_import;
 
diff --git a/src/niepce/ui/niepcewindow.cpp b/src/niepce/ui/niepcewindow.cpp
index ec467aa..cffeb37 100644
--- a/src/niepce/ui/niepcewindow.cpp
+++ b/src/niepce/ui/niepcewindow.cpp
@@ -255,9 +255,10 @@ void NiepceWindow::on_action_file_import()
     case 0:
     {
         // import
-        Glib::ustring to_import = import_dialog->path_to_import();
+        // XXX change the API to provide more details.
+        Glib::ustring to_import = import_dialog->pathToImport();
         if(!to_import.empty()) {
-            cfg.setValue("last_import_location", import_dialog->path_to_import());
+            cfg.setValue("last_import_location", to_import);
 
             //DBG_OUT("%s", to_import.c_str());
             m_libClient->importFromDirectory(to_import, false);


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