[niepce] importer: reformat with 4-spaces. ImportedFile::Ptr now ImportedFilePtr



commit d61deaa8566a722bad851344d59dab90a4325dea
Author: Hubert Figuière <hub figuiere net>
Date:   Sun May 21 21:55:04 2017 -0400

    importer: reformat with 4-spaces. ImportedFile::Ptr now ImportedFilePtr

 doc/style-guide                                    |   15 ++-
 src/engine/importer/cameraimporter.cpp             |   24 ++++-
 src/engine/importer/cameraimporter.hpp             |   30 +++---
 src/engine/importer/directoryimporter.cpp          |   67 ++++++------
 src/engine/importer/directoryimporter.hpp          |   29 +++---
 src/engine/importer/iimporter.hpp                  |   40 ++++----
 src/engine/importer/importedfile.hpp               |   23 ++---
 src/fwk/toolkit/thumbnail.cpp                      |   88 ++++++++--------
 src/fwk/toolkit/thumbnail.hpp                      |   36 +++---
 src/fwk/toolkit/uiresult.cpp                       |    9 +-
 src/fwk/toolkit/uiresult.hpp                       |   82 +++++++-------
 src/niepce/ui/dialogs/importdialog.cpp             |  114 ++++++++++----------
 src/niepce/ui/dialogs/importdialog.hpp             |    4 +-
 .../ui/dialogs/importers/directoryimporterui.cpp   |   83 +++++++-------
 .../ui/dialogs/importers/directoryimporterui.hpp   |   11 +-
 src/niepce/ui/dialogs/importers/iimporterui.hpp    |   36 +++++--
 16 files changed, 363 insertions(+), 328 deletions(-)
---
diff --git a/doc/style-guide b/doc/style-guide
index 42e684d..cfba88c 100644
--- a/doc/style-guide
+++ b/doc/style-guide
@@ -38,13 +38,14 @@ Classes:
 -Camel case, starting with an uppercase
 
 Methods:
--Camel case, starting with a lowercase
+-snake lowercase
 
 Variables
--Lower case
+-lowercase
+Member variables are prefix with m_ to alleviate shadowing
 
 Constants
--Upper case
+-uppercase
 
 
 HEADERS
@@ -56,6 +57,10 @@ Use #pragma once for header guards.
 C++
 ---
 
-C++11
+The standard is C++11.
 
-Use of 'override' is mandatory. Anywhere it is missing is a bug.
\ No newline at end of file
+Use of 'override' is mandatory. Anywhere it is missing is a bug.
+Use auto when possible.
+
+Avoid raw pointers. Use unique_ptr<> or shared_ptr<>. You can typedef
+the pointer type by suffixing Ptr to the class name.
diff --git a/src/engine/importer/cameraimporter.cpp b/src/engine/importer/cameraimporter.cpp
index 9db00aa..b6b8727 100644
--- a/src/engine/importer/cameraimporter.cpp
+++ b/src/engine/importer/cameraimporter.cpp
@@ -1,4 +1,22 @@
-
+/* -*- mode: C++; tab-width: 4; c-basic-offset: 4; indent-tabs-mode:nil; -*- */
+/*
+ * niepce - engine/importer/cameraimporter.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 "cameraimporter.hpp"
 
@@ -14,8 +32,8 @@ CameraImporter::~CameraImporter()
 
 const std::string& CameraImporter::id() const
 {
-  static std::string _id = "CameraImporter";
-  return _id;
+    static std::string _id = "CameraImporter";
+    return _id;
 }
 
 bool CameraImporter::list_source_content(const std::string & source,
diff --git a/src/engine/importer/cameraimporter.hpp b/src/engine/importer/cameraimporter.hpp
index 52d4878..61bb59d 100644
--- a/src/engine/importer/cameraimporter.hpp
+++ b/src/engine/importer/cameraimporter.hpp
@@ -1,3 +1,4 @@
+/* -*- mode: C++; tab-width: 4; c-basic-offset: 4; indent-tabs-mode:nil; -*- */
 /*
  * niepce - engine/importer/cameraimporter.hpp
  *
@@ -17,7 +18,6 @@
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
-
 #pragma once
 
 #include <string>
@@ -28,23 +28,21 @@
 
 namespace eng {
 
-
 class CameraImporter
-  : public IImporter {
+    : public IImporter {
 public:
-  CameraImporter();
-  virtual ~CameraImporter();
-
-  const std::string& id() const override;
-  bool list_source_content(const std::string & source,
-                           const SourceContentReady& callback) override;
-  bool get_previews_for(const std::string& source,
-                        const std::list<std::string>& paths,
-                        const PreviewReady& callback) override;
-
-  bool do_import(const std::string & source,
-                 const FileImporter & importer) override;
-
+    CameraImporter();
+    virtual ~CameraImporter();
+
+    const std::string& id() const override;
+    bool list_source_content(const std::string & source,
+                             const SourceContentReady& callback) override;
+    bool get_previews_for(const std::string& source,
+                          const std::list<std::string>& paths,
+                          const PreviewReady& callback) override;
+
+    bool do_import(const std::string & source,
+                   const FileImporter & importer) override;
 };
 
 }
diff --git a/src/engine/importer/directoryimporter.cpp b/src/engine/importer/directoryimporter.cpp
index 07178d8..767f318 100644
--- a/src/engine/importer/directoryimporter.cpp
+++ b/src/engine/importer/directoryimporter.cpp
@@ -1,3 +1,4 @@
+/* -*- mode: C++; tab-width: 4; c-basic-offset: 4; indent-tabs-mode:nil; -*- */
 /*
  * niepce - engine/importer/directoryimporter.cpp
  *
@@ -31,18 +32,18 @@ class DirectoryImportedFile
   : public ImportedFile
 {
 public:
-  DirectoryImportedFile(const std::string & path)
-    : m_path(path)
-    {
-      m_name = fwk::path_basename(path);
-    }
-  const std::string & name() const override
-    {
-      return m_name;
-    }
+    DirectoryImportedFile(const std::string & path)
+        : m_path(path)
+        {
+            m_name = fwk::path_basename(path);
+        }
+    const std::string & name() const override
+        {
+            return m_name;
+        }
 private:
-  std::string m_name;
-  std::string m_path;
+    std::string m_name;
+    std::string m_path;
 };
 
 
@@ -56,47 +57,47 @@ DirectoryImporter::~DirectoryImporter()
 
 const std::string& DirectoryImporter::id() const
 {
-  static std::string _id = "DirectoryImporter";
-  return _id;
+    static std::string _id = "DirectoryImporter";
+    return _id;
 }
 
 bool DirectoryImporter::list_source_content(const std::string & source,
                                             const SourceContentReady& callback)
 {
-  auto files =
-    fwk::FileList::getFilesFromDirectory(source,
-                                         &fwk::filter_xmp_out);
+    auto files =
+        fwk::FileList::getFilesFromDirectory(source,
+                                             &fwk::filter_xmp_out);
 
-  std::list<ImportedFile::Ptr> content;
-  for(const auto & entry : *files)
-  {
-    content.push_back(ImportedFile::Ptr(new DirectoryImportedFile(entry)));
-  }
-  callback(std::move(content));
+    std::list<ImportedFilePtr> content;
+    for(const auto & entry : *files)
+    {
+        content.push_back(ImportedFilePtr(new DirectoryImportedFile(entry)));
+    }
+    callback(std::move(content));
 
-  return true;
+    return true;
 }
 
 bool DirectoryImporter::get_previews_for(const std::string& source,
                                          const std::list<std::string>& paths,
                                          const PreviewReady& callback)
 {
-  for (auto path : paths) {
-    auto full_path = Glib::build_filename(source, path);
-    auto thumbnail = fwk::Thumbnail::thumbnail_file(full_path, 160, 160, 0);
-    callback(path, thumbnail);
-  }
-  return true;
+    for (auto path : paths) {
+        auto full_path = Glib::build_filename(source, path);
+        auto thumbnail = fwk::Thumbnail::thumbnail_file(full_path, 160, 160, 0);
+        callback(path, thumbnail);
+    }
+    return true;
 }
 
 bool DirectoryImporter::do_import(const std::string& source,
                                   const FileImporter& callback)
 {
-  // pretty trivial, we have the source path.
-  callback(source, false);
+    // pretty trivial, we have the source path.
+    callback(source, false);
 
-  // XXX return a real error
-  return true;
+    // XXX return a real error
+    return true;
 }
 
 }
diff --git a/src/engine/importer/directoryimporter.hpp b/src/engine/importer/directoryimporter.hpp
index e9a17fa..c691b57 100644
--- a/src/engine/importer/directoryimporter.hpp
+++ b/src/engine/importer/directoryimporter.hpp
@@ -1,3 +1,4 @@
+/* -*- mode: C++; tab-width: 4; c-basic-offset: 4; indent-tabs-mode:nil; -*- */
 /*
  * niepce - engine/importer/directoryimporter.hpp
  *
@@ -17,7 +18,6 @@
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
-
 #pragma once
 
 #include <string>
@@ -28,22 +28,21 @@
 
 namespace eng {
 
-
 class DirectoryImporter
-  : public IImporter {
+    : public IImporter {
 public:
-  DirectoryImporter();
-  virtual ~DirectoryImporter();
-
-  const std::string& id() const override;
-  bool list_source_content(const std::string & source,
-                           const SourceContentReady& callback) override;
-  bool get_previews_for(const std::string& source,
-                        const std::list<std::string>& paths,
-                        const PreviewReady& callback) override;
-
-  bool do_import(const std::string & source,
-                 const FileImporter & importer) override;
+    DirectoryImporter();
+    virtual ~DirectoryImporter();
+
+    const std::string& id() const override;
+    bool list_source_content(const std::string & source,
+                             const SourceContentReady& callback) override;
+    bool get_previews_for(const std::string& source,
+                          const std::list<std::string>& paths,
+                          const PreviewReady& callback) override;
+
+    bool do_import(const std::string & source,
+                   const FileImporter & importer) override;
 
 };
 
diff --git a/src/engine/importer/iimporter.hpp b/src/engine/importer/iimporter.hpp
index 17772d7..1f860b2 100644
--- a/src/engine/importer/iimporter.hpp
+++ b/src/engine/importer/iimporter.hpp
@@ -34,28 +34,28 @@ namespace eng {
  */
 class IImporter {
 public:
-  virtual ~IImporter() {}
+    virtual ~IImporter() {}
 
-  /** Return the id string */
-  virtual const std::string& id() const = 0;
+    /** Return the id string */
+    virtual const std::string& id() const = 0;
 
-  /** Source content is ready */
-  typedef std::function<void (std::list<ImportedFile::Ptr>&&)> SourceContentReady;
-  /** list the source content and store it. */
-  virtual bool list_source_content(const std::string& source,
-                                   const SourceContentReady& callback) = 0;
+    /** Source content is ready */
+    typedef std::function<void (std::list<ImportedFilePtr>&&)> SourceContentReady;
+    /** list the source content and store it. */
+    virtual bool list_source_content(const std::string& source,
+                                     const SourceContentReady& callback) = 0;
 
-  typedef std::function<void (const std::string& path,
-                              const fwk::Thumbnail&)> PreviewReady;
-  virtual bool get_previews_for(const std::string& source,
-                                const std::list<std::string>& paths,
-                                const PreviewReady& callback) = 0;
+    typedef std::function<void (const std::string& path,
+                                const fwk::Thumbnail&)> PreviewReady;
+    virtual bool get_previews_for(const std::string& source,
+                                  const std::list<std::string>& paths,
+                                  const PreviewReady& callback) = 0;
 
-  /** file importer callback */
-  typedef std::function<void (const std::string&, bool)> FileImporter;
-  /** perform import from source */
-  virtual bool do_import(const std::string& source,
-                        const FileImporter& importer) = 0;
+    /** file importer callback */
+    typedef std::function<void (const std::string&, bool)> FileImporter;
+    /** perform import from source */
+    virtual bool do_import(const std::string& source,
+                           const FileImporter& importer) = 0;
 
 };
 
@@ -65,9 +65,9 @@ public:
   mode:c++
   c-file-style:"stroustrup"
   c-file-offsets:((innamespace . 0))
-  c-basic-offset:2
+  c-basic-offset:4
   indent-tabs-mode:nil
-  tab-width:2
+  tab-width:4
   fill-column:99
   End:
 */
diff --git a/src/engine/importer/importedfile.hpp b/src/engine/importer/importedfile.hpp
index c9e09cc..b79bf48 100644
--- a/src/engine/importer/importedfile.hpp
+++ b/src/engine/importer/importedfile.hpp
@@ -24,24 +24,21 @@
 
 namespace eng {
 
-// XXX make not copyable
 class ImportedFile {
 public:
-  typedef std::shared_ptr<ImportedFile> Ptr;
+    ImportedFile()
+        {}
 
-  ImportedFile()
-    {}
+    ImportedFile(const ImportedFile&) = delete;
+    ImportedFile& operator=(const ImportedFile&) = delete;
 
-  ImportedFile(const ImportedFile&) = delete;
-  ImportedFile& operator=(const ImportedFile&) = delete;
+    virtual ~ImportedFile()
+        {}
 
-  virtual ~ImportedFile()
-    {}
-
-  virtual const std::string & name() const = 0;
-private:
+    virtual const std::string & name() const = 0;
 };
 
+typedef std::shared_ptr<ImportedFile> ImportedFilePtr;
 
 }
 
@@ -50,9 +47,9 @@ private:
   mode:c++
   c-file-style:"stroustrup"
   c-file-offsets:((innamespace . 0))
-  c-basic-offset:2
+  c-basic-offset:4
   indent-tabs-mode:nil
-  tab-width:2
+  tab-width:4
   fill-column:99
   End:
 */
diff --git a/src/fwk/toolkit/thumbnail.cpp b/src/fwk/toolkit/thumbnail.cpp
index 019e2f3..e208a3a 100644
--- a/src/fwk/toolkit/thumbnail.cpp
+++ b/src/fwk/toolkit/thumbnail.cpp
@@ -1,4 +1,4 @@
-/* -*- mode: C++; tab-width: 2; c-basic-offset: 2; indent-tabs-mode:nil; -*- */
+/* -*- mode: C++; tab-width: 4; c-basic-offset: 4; indent-tabs-mode:nil; -*- */
 /*
  * niepce - fwk/toolkit/thumbnail.cpp
  *
@@ -31,63 +31,63 @@
 namespace fwk {
 
 Thumbnail::Thumbnail(const Glib::RefPtr<Gdk::Pixbuf>& pixbuf)
-  : m_pixbuf(pixbuf)
+    : m_pixbuf(pixbuf)
 {
 }
 
 void Thumbnail::save(const std::string& path, const std::string& format)
 {
-  if (m_pixbuf) {
-    m_pixbuf->save(path, format);
-  }
+    if (m_pixbuf) {
+        m_pixbuf->save(path, format);
+    }
 }
 
 Thumbnail Thumbnail::thumbnail_file(const std::string& filename,
                                     int w, int h, int32_t orientation)
 {
-  fwk::MimeType mime_type(filename);
-  DBG_OUT("MIME type %s", mime_type.string().c_str());
+    fwk::MimeType mime_type(filename);
+    DBG_OUT("MIME type %s", mime_type.string().c_str());
 
-  Glib::RefPtr<Gdk::Pixbuf> pix;
+    Glib::RefPtr<Gdk::Pixbuf> pix;
 
-  if(mime_type.isUnknown()) {
-    DBG_OUT("unknown file type %s", filename.c_str());
-  } else if(mime_type.isMovie()) {
-    try {
-      // XXX FIXME
-      std::string cached = Glib::get_tmp_dir() + "/temp-1234";
-      if(fwk::thumbnail_movie(filename, w, h, cached)) {
-        pix = Gdk::Pixbuf::create_from_file(cached, w, h, true);
-      }
-    }
-    catch(const Glib::Error & e) {
-      ERR_OUT("exception thumbnailing video %s", e.what().c_str());
-    }
-  } else if(!mime_type.isImage()) {
-    DBG_OUT("not an image type");
-  } else if(!mime_type.isDigicamRaw()) {
-    DBG_OUT("not a raw type, trying GdkPixbuf loaders");
-    try {
-      pix = Gdk::Pixbuf::create_from_file(filename, w, h, true);
-      if(pix) {
-        pix = fwk::gdkpixbuf_exif_rotate(pix, orientation);
-      }
-    }
-    catch(const Glib::Error & e) {
-      ERR_OUT("exception thumbnailing image %s", e.what().c_str());
-    }
-  } else {
-    GdkPixbuf *pixbuf = or_gdkpixbuf_extract_rotated_thumbnail(filename.c_str(),
-                                                               std::min(w, h));
-    if(pixbuf) {
-      pix = Glib::wrap(pixbuf, true); // take ownership
-      if((w < pix->get_width()) || (h < pix->get_height())) {
-        pix = fwk::gdkpixbuf_scale_to_fit(pix, std::min(w,h));
-      }
+    if(mime_type.isUnknown()) {
+        DBG_OUT("unknown file type %s", filename.c_str());
+    } else if(mime_type.isMovie()) {
+        try {
+            // XXX FIXME
+            std::string cached = Glib::get_tmp_dir() + "/temp-1234";
+            if(fwk::thumbnail_movie(filename, w, h, cached)) {
+                pix = Gdk::Pixbuf::create_from_file(cached, w, h, true);
+            }
+        }
+        catch(const Glib::Error & e) {
+            ERR_OUT("exception thumbnailing video %s", e.what().c_str());
+        }
+    } else if(!mime_type.isImage()) {
+        DBG_OUT("not an image type");
+    } else if(!mime_type.isDigicamRaw()) {
+        DBG_OUT("not a raw type, trying GdkPixbuf loaders");
+        try {
+            pix = Gdk::Pixbuf::create_from_file(filename, w, h, true);
+            if(pix) {
+                pix = fwk::gdkpixbuf_exif_rotate(pix, orientation);
+            }
+        }
+        catch(const Glib::Error & e) {
+            ERR_OUT("exception thumbnailing image %s", e.what().c_str());
+        }
+    } else {
+        GdkPixbuf *pixbuf = or_gdkpixbuf_extract_rotated_thumbnail(filename.c_str(),
+                                                                   std::min(w, h));
+        if(pixbuf) {
+            pix = Glib::wrap(pixbuf, true); // take ownership
+            if((w < pix->get_width()) || (h < pix->get_height())) {
+                pix = fwk::gdkpixbuf_scale_to_fit(pix, std::min(w,h));
+            }
+        }
     }
-  }
 
-  return Thumbnail(pix);
+    return Thumbnail(pix);
 }
 
 }
diff --git a/src/fwk/toolkit/thumbnail.hpp b/src/fwk/toolkit/thumbnail.hpp
index c039015..dc6c384 100644
--- a/src/fwk/toolkit/thumbnail.hpp
+++ b/src/fwk/toolkit/thumbnail.hpp
@@ -1,4 +1,4 @@
-/* -*- mode: C++; tab-width: 2; c-basic-offset: 2; indent-tabs-mode:nil; -*- */
+/* -*- mode: C++; tab-width: 4; c-basic-offset: 4; indent-tabs-mode:nil; -*- */
 /*
  * niepce - fwk/toolkit/thumbnail.cpp
  *
@@ -30,29 +30,29 @@ namespace fwk {
 
 class Thumbnail {
 public:
-  Thumbnail() = default;
-  Thumbnail(const Glib::RefPtr<Gdk::Pixbuf>& pixbuf);
+    Thumbnail() = default;
+    Thumbnail(const Glib::RefPtr<Gdk::Pixbuf>& pixbuf);
 
-  bool ok() const {
-    return !!m_pixbuf;
-  }
+    bool ok() const {
+        return !!m_pixbuf;
+    }
 
-  int get_width() const {
-    return m_pixbuf->get_width();
-  }
-  int get_height() const {
-    return m_pixbuf->get_height();
-  }
-  const Glib::RefPtr<Gdk::Pixbuf>& pixbuf() const {
-    return m_pixbuf;
-  }
+    int get_width() const {
+        return m_pixbuf->get_width();
+    }
+    int get_height() const {
+        return m_pixbuf->get_height();
+    }
+    const Glib::RefPtr<Gdk::Pixbuf>& pixbuf() const {
+        return m_pixbuf;
+    }
 
-  void save(const std::string& path, const std::string& format);
+    void save(const std::string& path, const std::string& format);
 
-  static Thumbnail thumbnail_file(const std::string& path, int w, int h, int32_t orientation);
+    static Thumbnail thumbnail_file(const std::string& path, int w, int h, int32_t orientation);
 
 private:
-  Glib::RefPtr<Gdk::Pixbuf> m_pixbuf;
+    Glib::RefPtr<Gdk::Pixbuf> m_pixbuf;
 };
 
 }
diff --git a/src/fwk/toolkit/uiresult.cpp b/src/fwk/toolkit/uiresult.cpp
index d433d92..a8e73c5 100644
--- a/src/fwk/toolkit/uiresult.cpp
+++ b/src/fwk/toolkit/uiresult.cpp
@@ -1,4 +1,4 @@
-/* -*- mode: C++; tab-width: 2; c-basic-offset: 2; indent-tabs-mode:nil; -*- */
+/* -*- mode: C++; tab-width: 4; c-basic-offset: 4; indent-tabs-mode:nil; -*- */
 /*
  * niepce - fwk/toolkit/uiresult.hpp
  *
@@ -24,9 +24,10 @@
 
 namespace fwk {
 
-void UIResult::run(std::function<void ()>&& f) {
-  std::thread t(f);
-  t.detach();
+void UIResult::run(std::function<void ()>&& f)
+{
+    std::thread t(f);
+    t.detach();
 }
 
 }
diff --git a/src/fwk/toolkit/uiresult.hpp b/src/fwk/toolkit/uiresult.hpp
index 806eca6..5c10a21 100644
--- a/src/fwk/toolkit/uiresult.hpp
+++ b/src/fwk/toolkit/uiresult.hpp
@@ -1,4 +1,4 @@
-/* -*- mode: C++; tab-width: 2; c-basic-offset: 2; indent-tabs-mode:nil; -*- */
+/* -*- mode: C++; tab-width: 4; c-basic-offset: 4; indent-tabs-mode:nil; -*- */
 /*
  * niepce - fwk/toolkit/uiresult.hpp
  *
@@ -33,40 +33,38 @@ namespace fwk {
 class UIResult
 {
 public:
-  virtual void clear() = 0;
+    virtual void clear() = 0;
 
-  sigc::connection connect(sigc::slot<void>&& slot) {
-    return m_notifier.connect(std::move(slot));
-  }
+    sigc::connection connect(sigc::slot<void>&& slot) {
+        return m_notifier.connect(std::move(slot));
+    }
 
-  void run(std::function<void ()>&& f);
+    void run(std::function<void ()>&& f);
 protected:
-  Glib::Dispatcher m_notifier;
-  std::mutex m_data_mutex;
+    Glib::Dispatcher m_notifier;
+    std::mutex m_data_mutex;
 };
 
 template<class T>
 class UIResultSingle
-  : public UIResult
+    : public UIResult
 {
 public:
-  void clear() override {
-    m_data = T();
-  }
+    void clear() override {
+        m_data = T();
+    }
 
-  void send_data(T&& d) {
-    {
-      std::lock_guard<std::mutex> lock(m_data_mutex);
-      m_data = std::move(d);
+    void send_data(T&& d) {
+        {
+            std::lock_guard<std::mutex> lock(m_data_mutex);
+            m_data = std::move(d);
+        }
+        m_notifier.emit();
     }
-    m_notifier.emit();
-  }
-  T recv_data() {
-    {
-      std::lock_guard<std::mutex> lock(m_data_mutex);
-      return m_data;
+    T recv_data() {
+        std::lock_guard<std::mutex> lock(m_data_mutex);
+        return m_data;
     }
-  }
 private:
   T m_data;
 };
@@ -74,31 +72,31 @@ private:
 /** @brief Fetch many "results" asynchronously */
 template<class T>
 class UIResults
-  : public UIResult
+    : public UIResult
 {
 public:
-  void clear() override {
-    m_data.clear();
-  }
+    void clear() override {
+        m_data.clear();
+    }
 
-  void send_data(T&& d) {
-    {
-      std::lock_guard<std::mutex> lock(m_data_mutex);
-      m_data.push_back(std::move(d));
+    void send_data(T&& d) {
+        {
+            std::lock_guard<std::mutex> lock(m_data_mutex);
+            m_data.push_back(std::move(d));
+        }
+        m_notifier.emit();
     }
-    m_notifier.emit();
-  }
-  Option<T> recv_data() {
-    std::lock_guard<std::mutex> lock(m_data_mutex);
-    if (m_data.empty()) {
-      return Option<T>();
+    Option<T> recv_data() {
+        std::lock_guard<std::mutex> lock(m_data_mutex);
+        if (m_data.empty()) {
+            return Option<T>();
+        }
+        auto result = Option<T>(m_data.front());
+        m_data.pop_front();
+        return result;
     }
-    auto result = Option<T>(m_data.front());
-    m_data.pop_front();
-    return result;
-  }
 private:
-  std::deque<T> m_data;
+    std::deque<T> m_data;
 };
 
 }
diff --git a/src/niepce/ui/dialogs/importdialog.cpp b/src/niepce/ui/dialogs/importdialog.cpp
index b9a2713..a238adb 100644
--- a/src/niepce/ui/dialogs/importdialog.cpp
+++ b/src/niepce/ui/dialogs/importdialog.cpp
@@ -18,8 +18,6 @@
  */
 
 
-#include <future>
-
 #include <gtkmm/button.h>
 #include <gtkmm/checkbutton.h>
 #include <gtkmm/combobox.h>
@@ -63,14 +61,14 @@ ImportDialog::~ImportDialog()
 
 void ImportDialog::add_importer_ui(IImporterUI& importer)
 {
-  m_import_source_combo->append(importer.id(), importer.name());
-  Gtk::Widget* importer_widget = importer.setup_widget(
-    std::static_pointer_cast<Frame>(shared_from_this()));
-  importer_widget->show_all();
-  m_importer_ui_stack->add(*importer_widget, importer.id());
-  importer.set_source_selected_callback([this] (const std::string& source) {
-      this->set_to_import(source);
-    });
+    m_import_source_combo->append(importer.id(), importer.name());
+    Gtk::Widget* importer_widget = importer.setup_widget(
+        std::static_pointer_cast<Frame>(shared_from_this()));
+    importer_widget->show_all();
+    m_importer_ui_stack->add(*importer_widget, importer.id());
+    importer.set_source_selected_callback([this] (const std::string& source) {
+            this->set_to_import(source);
+        });
 }
 
 void ImportDialog::setup_widget()
@@ -134,12 +132,12 @@ void ImportDialog::setup_widget()
 
 void ImportDialog::import_source_changed()
 {
-  auto id = m_import_source_combo->get_active_id();
-  m_current_importer = m_importers[id];
-  m_importer_ui_stack->set_visible_child(id);
+    auto id = m_import_source_combo->get_active_id();
+    m_current_importer = m_importers[id];
+    m_importer_ui_stack->set_visible_child(id);
 
-  fwk::Configuration & cfg = fwk::Application::app()->config();
-  cfg.setValue("last_importer", id);
+    fwk::Configuration & cfg = fwk::Application::app()->config();
+    cfg.setValue("last_importer", id);
 }
 
 void ImportDialog::set_to_import(const std::string& f)
@@ -150,13 +148,13 @@ void ImportDialog::set_to_import(const std::string& f)
 
     auto importer = get_importer();
     m_files_to_import.run(
-      [this, f, importer] () {
-        return importer->list_source_content(
-          f,
-          [this] (std::list<eng::ImportedFile::Ptr>&& list_to_import) {
-            this->m_files_to_import.send_data(std::move(list_to_import));
-          });
-      });
+        [this, f, importer] () {
+            return importer->list_source_content(
+                f,
+                [this] (std::list<eng::ImportedFilePtr>&& list_to_import) {
+                    this->m_files_to_import.send_data(std::move(list_to_import));
+                });
+        });
 
     m_folder_path_source = f;
     m_destination_folder->set_text(fwk::path_basename(f));
@@ -164,46 +162,46 @@ void ImportDialog::set_to_import(const std::string& f)
 
 void ImportDialog::append_files_to_import()
 {
-  auto files_to_import = m_files_to_import.recv_data();
-
-  if (!m_images_list_model) {
-    ERR_OUT("No image list model");
-    return;
-  }
-  // request the previews to the importer.
-  std::list<std::string> paths;
-  for(const auto & f : files_to_import) {
-    DBG_OUT("selected %s", f->name().c_str());
-    paths.push_back(f->name());
-    Gtk::TreeIter iter = m_images_list_model->append();
-    m_images_list_map.insert(std::make_pair(f->name(), iter));
-    iter->set_value(m_grid_columns.filename, Glib::ustring(f->name()));
-    iter->set_value(m_grid_columns.file, std::move(f));
-  }
-
-  auto importer = get_importer();
-  auto source = m_folder_path_source.raw();
-  m_previews_to_import.run(
-    [this, importer, source, paths] () {
-      return importer->get_previews_for(
-        source, paths,
-        [this] (const std::string& path, const fwk::Thumbnail& thumbnail) {
-          this->m_previews_to_import.send_data(
-            std::make_pair(path, thumbnail));
+    auto files_to_import = m_files_to_import.recv_data();
+
+    if (!m_images_list_model) {
+        ERR_OUT("No image list model");
+        return;
+    }
+    // request the previews to the importer.
+    std::list<std::string> paths;
+    for(const auto & f : files_to_import) {
+        DBG_OUT("selected %s", f->name().c_str());
+        paths.push_back(f->name());
+        Gtk::TreeIter iter = m_images_list_model->append();
+        m_images_list_map.insert(std::make_pair(f->name(), iter));
+        iter->set_value(m_grid_columns.filename, Glib::ustring(f->name()));
+        iter->set_value(m_grid_columns.file, std::move(f));
+    }
+
+    auto importer = get_importer();
+    auto source = m_folder_path_source.raw();
+    m_previews_to_import.run(
+        [this, importer, source, paths] () {
+            return importer->get_previews_for(
+                source, paths,
+                [this] (const std::string& path, const fwk::Thumbnail& thumbnail) {
+                    this->m_previews_to_import.send_data(
+                        std::make_pair(path, thumbnail));
+                });
         });
-    });
 }
 
 void ImportDialog::preview_received()
 {
-  auto result = m_previews_to_import.recv_data();
-  if (!result.empty()) {
-    auto preview = result.unwrap();
-    auto iter = m_images_list_map.find(preview.first);
-    if (iter != m_images_list_map.end()) {
-      iter->second->set_value(m_grid_columns.pixbuf, preview.second.pixbuf());
+    auto result = m_previews_to_import.recv_data();
+    if (!result.empty()) {
+        auto preview = result.unwrap();
+        auto iter = m_images_list_map.find(preview.first);
+        if (iter != m_images_list_map.end()) {
+            iter->second->set_value(m_grid_columns.pixbuf, preview.second.pixbuf());
+        }
     }
-  }
 }
 
 
@@ -214,9 +212,9 @@ void ImportDialog::preview_received()
   mode:c++
   c-file-style:"stroustrup"
   c-file-offsets:((innamespace . 0))
-  c-basic-offset:2
+  c-basic-offset:4
   indent-tabs-mode:nil
-  tab-width:2
+  tab-width:4
   fill-column:99
   End:
 */
diff --git a/src/niepce/ui/dialogs/importdialog.hpp b/src/niepce/ui/dialogs/importdialog.hpp
index 53f7603..c2ef72d 100644
--- a/src/niepce/ui/dialogs/importdialog.hpp
+++ b/src/niepce/ui/dialogs/importdialog.hpp
@@ -68,7 +68,7 @@ public:
     public:
         Gtk::TreeModelColumn<Glib::ustring> filename;
         Gtk::TreeModelColumn<Glib::RefPtr<Gdk::Pixbuf>> pixbuf;
-        Gtk::TreeModelColumn<eng::ImportedFile::Ptr> file;
+        Gtk::TreeModelColumn<eng::ImportedFilePtr> file;
         PreviewGridModel()
             { add(filename); add(pixbuf); add(file); }
     };
@@ -116,7 +116,7 @@ private:
 
     MetaDataPaneController::Ptr m_metadata_pane;
 
-    fwk::UIResultSingle<std::list<eng::ImportedFile::Ptr>> m_files_to_import;
+    fwk::UIResultSingle<std::list<eng::ImportedFilePtr>> m_files_to_import;
     fwk::UIResults<std::pair<std::string, fwk::Thumbnail>> m_previews_to_import;
 };
 
diff --git a/src/niepce/ui/dialogs/importers/directoryimporterui.cpp 
b/src/niepce/ui/dialogs/importers/directoryimporterui.cpp
index d5774c7..da1efc2 100644
--- a/src/niepce/ui/dialogs/importers/directoryimporterui.cpp
+++ b/src/niepce/ui/dialogs/importers/directoryimporterui.cpp
@@ -1,3 +1,4 @@
+/* -*- mode: C++; tab-width: 4; c-basic-offset: 4; indent-tabs-mode:nil; -*- */
 /*
  * niepce - ui/dialogs/importer/directoryimporterui.cpp
  *
@@ -29,65 +30,65 @@
 namespace ui {
 
 DirectoryImporterUI::DirectoryImporterUI()
-  : ImporterUI(std::make_shared<eng::DirectoryImporter>(), _("Directory"))
-  , m_directory_name(nullptr)
+    : ImporterUI(std::make_shared<eng::DirectoryImporter>(), _("Directory"))
+    , m_directory_name(nullptr)
 {
 }
 
 Gtk::Widget* DirectoryImporterUI::setup_widget(const fwk::Frame::Ptr& frame)
 {
-  m_frame = frame;
-  Gtk::Button* select_directories = nullptr;
-  m_builder = Gtk::Builder::create_from_file(GLADEDIR"directoryimporterui.ui",
-                                             "main_widget");
-  Gtk::Box* main_widget = nullptr;
-  m_builder->get_widget("main_widget", main_widget);
-  m_builder->get_widget("select_directories", select_directories);
-  select_directories->signal_clicked().connect(
-    sigc::mem_fun(*this, &DirectoryImporterUI::do_select_directories));
-  m_builder->get_widget("directory_name", m_directory_name);
-  return main_widget;
+    m_frame = frame;
+    Gtk::Button* select_directories = nullptr;
+    m_builder = Gtk::Builder::create_from_file(GLADEDIR"directoryimporterui.ui",
+                                               "main_widget");
+    Gtk::Box* main_widget = nullptr;
+    m_builder->get_widget("main_widget", main_widget);
+    m_builder->get_widget("select_directories", select_directories);
+    select_directories->signal_clicked().connect(
+        sigc::mem_fun(*this, &DirectoryImporterUI::do_select_directories));
+    m_builder->get_widget("directory_name", m_directory_name);
+    return main_widget;
 }
 
 void DirectoryImporterUI::do_select_directories()
 {
-  auto source = select_source();
-  if (!source.empty() && m_source_selected_cb) {
-    m_source_selected_cb(source);
-  }
+    auto source = select_source();
+    if (!source.empty() && m_source_selected_cb) {
+        m_source_selected_cb(source);
+    }
 }
 
 std::string DirectoryImporterUI::select_source()
 {
-  fwk::Configuration & cfg = fwk::Application::app()->config();
+    fwk::Configuration & cfg = fwk::Application::app()->config();
 
-  Glib::ustring filename;
-  {
-    auto frame = m_frame.lock();
-    Gtk::FileChooserDialog dialog(frame->gtkWindow(), _("Import picture folder"),
-                                  Gtk::FILE_CHOOSER_ACTION_SELECT_FOLDER);
+    Glib::ustring filename;
+    {
+        auto frame = m_frame.lock();
+        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);
+        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);
-    }
+        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;
+        int result = dialog.run();
+        switch(result)
+        {
+        case Gtk::RESPONSE_OK:
+            filename = dialog.get_filename();
+            break;
+        default:
+            break;
+        }
     }
-  }
-  m_directory_name->set_text(filename);
-  return filename.raw();
+    m_directory_name->set_text(filename);
+    return filename.raw();
 }
 
 }
diff --git a/src/niepce/ui/dialogs/importers/directoryimporterui.hpp 
b/src/niepce/ui/dialogs/importers/directoryimporterui.hpp
index 563f341..c4a8a75 100644
--- a/src/niepce/ui/dialogs/importers/directoryimporterui.hpp
+++ b/src/niepce/ui/dialogs/importers/directoryimporterui.hpp
@@ -1,3 +1,4 @@
+/* -*- mode: C++; tab-width: 4; c-basic-offset: 4; indent-tabs-mode:nil; -*- */
 /*
  * niepce - ui/dialogs/importer/directoryimporterui.hpp
  *
@@ -35,15 +36,15 @@ class DirectoryImporterUI
   : public ImporterUI
 {
 public:
-  DirectoryImporterUI();
+    DirectoryImporterUI();
 
-  Gtk::Widget* setup_widget(const fwk::Frame::Ptr&) override;
+    Gtk::Widget* setup_widget(const fwk::Frame::Ptr&) override;
 
 private:
-  std::string select_source();
-  void do_select_directories();
+    std::string select_source();
+    void do_select_directories();
 
-  Gtk::Label *m_directory_name;
+    Gtk::Label *m_directory_name;
 };
 
 }
diff --git a/src/niepce/ui/dialogs/importers/iimporterui.hpp b/src/niepce/ui/dialogs/importers/iimporterui.hpp
index 0e5539c..66b3880 100644
--- a/src/niepce/ui/dialogs/importers/iimporterui.hpp
+++ b/src/niepce/ui/dialogs/importers/iimporterui.hpp
@@ -1,4 +1,22 @@
-
+/* -*- mode: C++; tab-width: 4; c-basic-offset: 4; indent-tabs-mode:nil; -*- */
+/*
+ * niepce - ui/dialogs/importers/iimporterui.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
 
@@ -21,17 +39,17 @@ namespace ui {
 class IImporterUI {
 public:
 
-  virtual ~IImporterUI() {}
+    virtual ~IImporterUI() {}
 
-  virtual std::shared_ptr<eng::IImporter> get_importer() = 0;
+    virtual std::shared_ptr<eng::IImporter> get_importer() = 0;
 
-  /** User visible importer name. */
-  virtual const std::string& name() const = 0;
-  virtual const std::string& id() const = 0;
-  virtual Gtk::Widget* setup_widget(const fwk::Frame::Ptr&) = 0;
+    /** User visible importer name. */
+    virtual const std::string& name() const = 0;
+    virtual const std::string& id() const = 0;
+    virtual Gtk::Widget* setup_widget(const fwk::Frame::Ptr&) = 0;
 
-  typedef std::function<void (const std::string&)> SourceSelected;
-  virtual void set_source_selected_callback(const SourceSelected&) = 0;
+    typedef std::function<void (const std::string&)> SourceSelected;
+    virtual void set_source_selected_callback(const SourceSelected&) = 0;
 };
 
 }


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