[niepce] importer: split out importer UI from importdialog (part 1)



commit 2b522b057b829c23de1e9053efabfbd5e4acbeb0
Author: Hubert Figuière <hub figuiere net>
Date:   Wed May 17 00:21:22 2017 -0400

    importer: split out importer UI from importdialog (part 1)

 src/fwk/toolkit/frame.hpp                          |    4 +-
 src/niepce/ui/Makefile.am                          |    6 +-
 src/niepce/ui/dialogs/importdialog.cpp             |   53 +++------------
 src/niepce/ui/dialogs/importdialog.hpp             |    9 ++-
 .../ui/dialogs/importers/directoryimporterui.cpp   |   70 ++++++++++++++++++++
 .../ui/dialogs/importers/directoryimporterui.hpp   |   39 +++++++++++
 src/niepce/ui/dialogs/importers/iimporterui.hpp    |   23 +++++++
 src/niepce/ui/niepcewindow.cpp                     |    2 +-
 8 files changed, 155 insertions(+), 51 deletions(-)
---
diff --git a/src/fwk/toolkit/frame.hpp b/src/fwk/toolkit/frame.hpp
index 8eb3f0b..a2b33eb 100644
--- a/src/fwk/toolkit/frame.hpp
+++ b/src/fwk/toolkit/frame.hpp
@@ -59,9 +59,9 @@ public:
             return std::static_pointer_cast<Frame>(shared_from_this());
         }
 
-    Gtk::Window & gtkWindow()
+    Gtk::Window & gtkWindow() const
         {
-            return *m_window; 
+            return *m_window;
         }
     Glib::RefPtr<Gtk::Builder> & builder()
         { return m_builder; }
diff --git a/src/niepce/ui/Makefile.am b/src/niepce/ui/Makefile.am
index 5a2e2ae..fd22a80 100644
--- a/src/niepce/ui/Makefile.am
+++ b/src/niepce/ui/Makefile.am
@@ -18,7 +18,7 @@ EXTRA_DIST = $(gladefiles)
 
 noinst_LIBRARIES = libniepceui.a
 
-PUBLICHEADERS = ilibrarymodule.hpp imoduleshell.hpp
+PUBLICHEADERS = ilibrarymodule.hpp imoduleshell.hpp dialogs/importers/iimporterui.hpp
 
 libniepceui_a_SOURCES = \
        niepcewindow.hpp niepcewindow.cpp \
@@ -33,9 +33,11 @@ libniepceui_a_SOURCES = \
        dialogs/editlabels.hpp dialogs/editlabels.cpp \
        dialogs/importdialog.hpp dialogs/importdialog.cpp \
        dialogs/preferencesdialog.hpp dialogs/preferencesdialog.cpp \
+       dialogs/importdialog.hpp dialogs/importdialog.cpp \
+       dialogs/importers/directoryimporterui.hpp \
+       dialogs/importers/directoryimporterui.cpp \
        selectioncontroller.hpp selectioncontroller.cpp \
        filmstripcontroller.hpp filmstripcontroller.cpp \
-       dialogs/importdialog.hpp dialogs/importdialog.cpp \
        thumb-view/eog-thumb-nav.cpp thumb-view/eog-thumb-nav.hpp \
        thumbstripview.cpp thumbstripview.hpp \
        $(PUBLICHEADERS) \
diff --git a/src/niepce/ui/dialogs/importdialog.cpp b/src/niepce/ui/dialogs/importdialog.cpp
index d7c8fda..1221180 100644
--- a/src/niepce/ui/dialogs/importdialog.cpp
+++ b/src/niepce/ui/dialogs/importdialog.cpp
@@ -20,11 +20,9 @@
 
 #include <future>
 
-#include <glibmm/i18n.h>
 #include <gtkmm/button.h>
 #include <gtkmm/checkbutton.h>
 #include <gtkmm/combobox.h>
-#include <gtkmm/filechooserdialog.h>
 #include <gtkmm/iconview.h>
 #include <gtkmm/label.h>
 #include <gtkmm/liststore.h>
@@ -32,15 +30,11 @@
 
 #include "fwk/base/debug.hpp"
 #include "fwk/utils/pathutils.hpp"
-#include "fwk/toolkit/configuration.hpp"
-#include "fwk/toolkit/application.hpp"
 #include "fwk/toolkit/widgets/imagegridview.hpp"
 #include "engine/importer/directoryimporter.hpp"
 #include "engine/importer/importedfile.hpp"
 #include "importdialog.hpp"
-
-using fwk::Configuration;
-using fwk::Application;
+#include "importers/directoryimporterui.hpp"
 
 namespace ui {
 
@@ -111,50 +105,23 @@ void ImportDialog::setup_widget()
 // XXX doesn't belong here
 void ImportDialog::do_select_directories()
 {
-  Configuration & cfg = Application::app()->config();
-
-  Glib::ustring filename;
-  {
-    Gtk::FileChooserDialog dialog(gtkWindow(), _("Import picture folder"),
-                                  Gtk::FILE_CHOOSER_ACTION_SELECT_FOLDER);
-
-    dialog.add_button(_("Cancel"), Gtk::RESPONSE_CANCEL);
-    dialog.add_button(_("Select"), Gtk::RESPONSE_OK);
-    dialog.set_select_multiple(false);
-
-    std::string last_import_location = cfg.getValue("last_import_location", "");
-    if (!last_import_location.empty()) {
-      dialog.set_filename(last_import_location);
+    if (!m_importer) {
+        // FIXME this should be the right kind
+        m_importer = std::make_shared<DirectoryImporterUI>();
     }
-
-    int result = dialog.run();
-    switch(result)
-    {
-    case Gtk::RESPONSE_OK:
-      filename = dialog.get_filename();
-      break;
-    default:
-      break;
+    auto source = m_importer->select_source(*this);
+    if (!source.empty()) {
+      set_to_import(source);
     }
-  }
-  if (!filename.empty()) {
-    set_to_import(filename);
-  }
 }
 
-// XXX doesn't belong here. Or must be deeply modified to deal with the Importer
-void ImportDialog::set_to_import(const Glib::ustring & f)
+void ImportDialog::set_to_import(const std::string& f)
 {
-    if (!m_importer) {
-        // FIXME this should be the right kind
-        m_importer = std::make_shared<eng::DirectoryImporter>();
-    }
-
     m_images_list_model->clear();
     m_images_list_map.clear();
     m_files_to_import.clear();
 
-    auto importer = m_importer;
+    auto importer = get_importer();
     m_files_to_import.run(
       [this, f, importer] () {
         return importer->list_source_content(
@@ -188,7 +155,7 @@ void ImportDialog::append_files_to_import()
     iter->set_value(m_grid_columns.file, std::move(f));
   }
 
-  auto importer = m_importer;
+  auto importer = get_importer();
   auto source = m_folder_path_source.raw();
   m_previews_to_import.run(
     [this, importer, source, paths] () {
diff --git a/src/niepce/ui/dialogs/importdialog.hpp b/src/niepce/ui/dialogs/importdialog.hpp
index 387d0ff..e942961 100644
--- a/src/niepce/ui/dialogs/importdialog.hpp
+++ b/src/niepce/ui/dialogs/importdialog.hpp
@@ -34,6 +34,7 @@
 #include "fwk/toolkit/uiresult.hpp"
 #include "imageliststore.hpp"
 #include "metadatapanecontroller.hpp"
+#include "importers/iimporterui.hpp"
 
 namespace Gtk {
 class Dialog;
@@ -79,9 +80,11 @@ public:
 //      { return m_list_to_import; }
     const Glib::ustring & source_path() const
         { return m_folder_path_source; }
-    void set_to_import(const Glib::ustring & f);
-    const std::shared_ptr<eng::IImporter>& importer() const
+    void set_to_import(const std::string& f);
+    const std::shared_ptr<IImporterUI>& importer_ui() const
         { return m_importer; }
+    std::shared_ptr<eng::IImporter> get_importer() const
+        { return m_importer->get_importer(); }
 private:
     class ImportParam;
 
@@ -89,7 +92,7 @@ private:
     void append_files_to_import();
     void preview_received();
 
-    std::shared_ptr<eng::IImporter> m_importer; // as shared_ptr<> for lambda capture
+    std::shared_ptr<ui::IImporterUI> m_importer; // as shared_ptr<> for lambda capture
     Glib::ustring m_folder_path_source;
 
     Gtk::ComboBox *m_date_tz_combo;
diff --git a/src/niepce/ui/dialogs/importers/directoryimporterui.cpp 
b/src/niepce/ui/dialogs/importers/directoryimporterui.cpp
new file mode 100644
index 0000000..5333785
--- /dev/null
+++ b/src/niepce/ui/dialogs/importers/directoryimporterui.cpp
@@ -0,0 +1,70 @@
+/*
+ * niepce - ui/dialogs/importer/directoryimporterui.cpp
+ *
+ * Copyright (C) 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
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <glibmm/i18n.h>
+#include <gtkmm/filechooserdialog.h>
+
+#include "fwk/toolkit/application.hpp"
+#include "fwk/toolkit/configuration.hpp"
+#include "engine/importer/directoryimporter.hpp"
+#include "directoryimporterui.hpp"
+
+namespace ui {
+
+  DirectoryImporterUI::DirectoryImporterUI()
+    : m_importer(std::make_shared<eng::DirectoryImporter>())
+  {
+  }
+
+  std::shared_ptr<eng::IImporter> DirectoryImporterUI::get_importer()
+  {
+    return m_importer;
+  }
+
+  std::string DirectoryImporterUI::select_source(const fwk::Frame& frame)
+  {
+    fwk::Configuration & cfg = fwk::Application::app()->config();
+
+    Glib::ustring filename;
+    {
+      Gtk::FileChooserDialog dialog(frame.gtkWindow(), _("Import picture folder"),
+                                    Gtk::FILE_CHOOSER_ACTION_SELECT_FOLDER);
+
+      dialog.add_button(_("Cancel"), Gtk::RESPONSE_CANCEL);
+      dialog.add_button(_("Select"), Gtk::RESPONSE_OK);
+      dialog.set_select_multiple(false);
+
+      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:
+        filename = dialog.get_filename();
+        break;
+      default:
+        break;
+      }
+    }
+    return filename.raw();
+  }
+}
diff --git a/src/niepce/ui/dialogs/importers/directoryimporterui.hpp 
b/src/niepce/ui/dialogs/importers/directoryimporterui.hpp
new file mode 100644
index 0000000..54da34a
--- /dev/null
+++ b/src/niepce/ui/dialogs/importers/directoryimporterui.hpp
@@ -0,0 +1,39 @@
+/*
+ * niepce - ui/dialogs/importer/directoryimporterui.hpp
+ *
+ * Copyright (C) 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
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#pragma once
+
+#include "iimporterui.hpp"
+
+namespace ui {
+
+class DirectoryImporterUI
+  : public IImporterUI
+{
+public:
+  DirectoryImporterUI();
+
+  std::shared_ptr<eng::IImporter> get_importer() override;
+  std::string select_source(const fwk::Frame&) override;
+
+private:
+  std::shared_ptr<eng::DirectoryImporter> m_importer;
+};
+
+}
diff --git a/src/niepce/ui/dialogs/importers/iimporterui.hpp b/src/niepce/ui/dialogs/importers/iimporterui.hpp
new file mode 100644
index 0000000..da203d1
--- /dev/null
+++ b/src/niepce/ui/dialogs/importers/iimporterui.hpp
@@ -0,0 +1,23 @@
+
+
+#pragma once
+
+#include <memory>
+
+#include "engine/importer/iimporter.hpp"
+
+namespace fwk {
+class Frame;
+}
+
+namespace ui {
+
+class IImporterUI {
+public:
+
+  virtual std::shared_ptr<eng::IImporter> get_importer() = 0;
+  virtual std::string select_source(const fwk::Frame&) = 0;
+
+};
+
+}
diff --git a/src/niepce/ui/niepcewindow.cpp b/src/niepce/ui/niepcewindow.cpp
index 1613aca..83947ff 100644
--- a/src/niepce/ui/niepcewindow.cpp
+++ b/src/niepce/ui/niepcewindow.cpp
@@ -265,7 +265,7 @@ void NiepceWindow::on_action_file_import()
         }
         cfg.setValue("last_import_location", source);
 
-        auto importer = import_dialog->importer();
+        auto importer = import_dialog->get_importer();
         DBG_ASSERT(!!importer, "Import can't be null if we clicked import");
         if (importer) {
             importer->do_import(


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