[niepce] Map module will now center the map on the selected picture location.



commit ab7b79e39312279c942ea09e95b2090a09186d8b
Author: Hubert Figuière <hub figuiere net>
Date:   Thu Jul 10 20:58:48 2014 -0400

    Map module will now center the map on the selected picture location.

 doc/code-organization.txt            |    3 +-
 src/fwk/toolkit/mapcontroller.cpp    |   33 ++++++++++++++++++++++
 src/fwk/toolkit/mapcontroller.hpp    |   12 ++++++--
 src/niepce/modules/map/mapmodule.cpp |   50 ++++++++++++++++++++++++++++++++++
 src/niepce/modules/map/mapmodule.hpp |    2 +
 src/niepce/ui/moduleshell.hpp        |    4 +++
 src/niepce/ui/niepcewindow.cpp       |    4 +++
 7 files changed, 104 insertions(+), 4 deletions(-)
---
diff --git a/doc/code-organization.txt b/doc/code-organization.txt
index 52855f0..bc0b188 100644
--- a/doc/code-organization.txt
+++ b/doc/code-organization.txt
@@ -6,7 +6,7 @@ Here are the different directories for the source code:
 * src
     * ext - external code
         * libgdl - "stolen" from Inkscape, a fork of libgdl
-                  from Anjuta. Has matching C++ code in 
+                  from Anjuta. Has matching C++ code in
                    the framework.
     * fwk - the framework
         * utils - utilities
@@ -24,3 +24,4 @@ Here are the different directories for the source code:
         * ui - the UI code
         * modules - The different application modules
             * darkroom - The darkroom module
+            * map - The map module
diff --git a/src/fwk/toolkit/mapcontroller.cpp b/src/fwk/toolkit/mapcontroller.cpp
index ecd80d7..b658060 100644
--- a/src/fwk/toolkit/mapcontroller.cpp
+++ b/src/fwk/toolkit/mapcontroller.cpp
@@ -37,8 +37,41 @@ MapController::buildWidget(const Glib::RefPtr<Gtk::UIManager> &)
     gtk_champlain_embed_get_view(GTK_CHAMPLAIN_EMBED(embed));
   m_clutter_map = Glib::wrap(CLUTTER_ACTOR(clutter_map), true);
 
+  // Default position. Somewhere over Montréal, QC
+  setZoomLevel(10);
+  centerOn(45.5030854,-73.5698944);
+
   return m_widget;
 }
 
+void MapController::centerOn(double lat, double longitude)
+{
+  champlain_view_center_on(CHAMPLAIN_VIEW(m_clutter_map->gobj()),
+                           lat, longitude);
+}
 
+void MapController::zoomIn()
+{
+  champlain_view_zoom_in(CHAMPLAIN_VIEW(m_clutter_map->gobj()));
+}
+
+void MapController::zoomOut()
+{
+  champlain_view_zoom_out(CHAMPLAIN_VIEW(m_clutter_map->gobj()));
 }
+
+void MapController::setZoomLevel(uint8_t level)
+{
+  champlain_view_set_zoom_level(CHAMPLAIN_VIEW(m_clutter_map->gobj()), level);
+}
+
+}
+/*
+  Local Variables:
+  mode:c++
+  c-file-style:"stroustrup"
+  c-file-offsets:((innamespace . 0))
+  indent-tabs-mode:nil
+  fill-column:99
+  End:
+*/
diff --git a/src/fwk/toolkit/mapcontroller.hpp b/src/fwk/toolkit/mapcontroller.hpp
index 6bd5839..79c2a58 100644
--- a/src/fwk/toolkit/mapcontroller.hpp
+++ b/src/fwk/toolkit/mapcontroller.hpp
@@ -29,12 +29,18 @@ class MapController
   : public UiController
 {
 public:
-  typedef std::shared_ptr<MapController> Ptr;
+    typedef std::shared_ptr<MapController> Ptr;
 
-  virtual Gtk::Widget * buildWidget(const Glib::RefPtr<Gtk::UIManager> &);
+    virtual Gtk::Widget * buildWidget(const Glib::RefPtr<Gtk::UIManager> &);
+
+    void centerOn(double lat, double longitude);
+
+    void zoomIn();
+    void zoomOut();
+    void setZoomLevel(uint8_t level); // 1 to 20
 
 private:
-  Glib::RefPtr<Clutter::Actor> m_clutter_map;
+    Glib::RefPtr<Clutter::Actor> m_clutter_map;
 };
 
 
diff --git a/src/niepce/modules/map/mapmodule.cpp b/src/niepce/modules/map/mapmodule.cpp
index 860843c..db1d9bb 100644
--- a/src/niepce/modules/map/mapmodule.cpp
+++ b/src/niepce/modules/map/mapmodule.cpp
@@ -21,6 +21,7 @@
 
 #include "fwk/base/debug.hpp"
 #include "fwk/toolkit/application.hpp"
+#include "engine/db/properties.hpp"
 #include "mapmodule.hpp"
 
 namespace mapm {
@@ -64,6 +65,55 @@ Gtk::Widget * MapModule::buildWidget(const Glib::RefPtr<Gtk::UIManager> & manage
     return m_widget;
 }
 
+void
+MapModule::on_lib_notification(const eng::LibNotification &ln)
+{
+    if (!m_active) {
+        return;
+    }
+    switch(ln.type) {
+    case eng::Library::NOTIFY_METADATA_QUERIED:
+    {
+        DBG_ASSERT(ln.param.type() == typeid(eng::LibMetadata::Ptr),
+                   "incorrect data type for the notification");
+        eng::LibMetadata::Ptr lm
+            = boost::any_cast<eng::LibMetadata::Ptr>(ln.param);
+        DBG_OUT("received metadata in MapModule");
+
+        if (lm) {
+            fwk::PropertyBag properties;
+            const fwk::PropertySet propset = { eng::NpExifGpsLongProp,
+                                               eng::NpExifGpsLatProp };
+            lm->to_properties(propset, properties);
+            double latitude, longitude;
+            latitude = longitude = NAN;
+            fwk::PropertyValue val;
+            if(properties.get_value_for_property(eng::NpExifGpsLongProp, val)) {
+                // it is a string
+                if (is_string(val)) {
+                    longitude = fwk::XmpMeta::gpsCoordFromXmp(
+                        fwk::get_string(val));
+                }
+            }
+            if(properties.get_value_for_property(eng::NpExifGpsLatProp, val)) {
+                // it is a string
+                if (is_string(val)) {
+                    latitude = fwk::XmpMeta::gpsCoordFromXmp(
+                        fwk::get_string(val));
+                }
+            }
+
+            if (!isnan(latitude) && !isnan(longitude)) {
+                m_map->centerOn(latitude, longitude);
+            }
+        }
+        break;
+    }
+    default:
+        break;
+    }
+}
+
 }
 
 /*
diff --git a/src/niepce/modules/map/mapmodule.hpp b/src/niepce/modules/map/mapmodule.hpp
index f258c74..66cf4d8 100644
--- a/src/niepce/modules/map/mapmodule.hpp
+++ b/src/niepce/modules/map/mapmodule.hpp
@@ -47,6 +47,8 @@ public:
 
     virtual void set_active(bool active);
 
+    void on_lib_notification(const eng::LibNotification &ln);
+
 protected:
     virtual Gtk::Widget * buildWidget(const Glib::RefPtr<Gtk::UIManager> &);
 
diff --git a/src/niepce/ui/moduleshell.hpp b/src/niepce/ui/moduleshell.hpp
index 82388c6..3741029 100644
--- a/src/niepce/ui/moduleshell.hpp
+++ b/src/niepce/ui/moduleshell.hpp
@@ -58,6 +58,10 @@ public:
         {
             return m_gridview;
         }
+    const mapm::MapModule::Ptr & get_map_module() const
+        {
+            return m_mapm;
+        }
     const Glib::RefPtr<ImageListStore> & get_list_store() const
         { 
             return m_selection_controller->get_list_store(); 
diff --git a/src/niepce/ui/niepcewindow.cpp b/src/niepce/ui/niepcewindow.cpp
index 6a91be7..3573d3f 100644
--- a/src/niepce/ui/niepcewindow.cpp
+++ b/src/niepce/ui/niepcewindow.cpp
@@ -93,6 +93,10 @@ NiepceWindow::_createModuleShell()
         .connect(sigc::mem_fun(
                      *get_pointer(m_moduleshell->get_list_store()),
                      &ImageListStore::on_lib_notification));
+    m_notifcenter->signal_lib_notification
+        .connect(sigc::mem_fun(
+                     *m_moduleshell->get_map_module(),
+                     &mapm::MapModule::on_lib_notification));
     m_notifcenter->signal_thumbnail_notification
         .connect(sigc::mem_fun(
                      *get_pointer(m_moduleshell->get_list_store()), 


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