[gnome-maps] Add a context menu



commit 91338dec0dfdbd96141fe65c798e4683389ab6e6
Author: Zeeshan Ali (Khattak) <zeeshanak gnome org>
Date:   Sun Aug 25 02:50:33 2013 +0300

    Add a context menu
    
    Currently this menu has only one item: "What's here?". If user activates
    this item, a reverse geocoding is performed for the coordinates where
    user right clicked and place information (currently only the name) is
    shown in bubble (just like for forward geocoding search results).
    
    Next would be to add a "I'm here" menu item to provide user the ability
    to correct (or improve the accuracy) of his/her location.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=706726

 src/Makefile-js.am           |    3 +-
 src/context-menu.ui          |   14 +++++++
 src/contextMenu.js           |   81 ++++++++++++++++++++++++++++++++++++++++++
 src/gnome-maps.gresource.xml |    1 +
 src/mainWindow.js            |    3 ++
 5 files changed, 101 insertions(+), 1 deletions(-)
---
diff --git a/src/Makefile-js.am b/src/Makefile-js.am
index 90365a3..233db98 100644
--- a/src/Makefile-js.am
+++ b/src/Makefile-js.am
@@ -11,7 +11,8 @@ dist_js_DATA = \
     userLocation.js \
     geoclue.js \
     zoomControl.js \
-    searchPopup.js
+    searchPopup.js \
+    contextMenu.js
 
 BUILT_SOURCES += \
     path.js \
diff --git a/src/context-menu.ui b/src/context-menu.ui
new file mode 100644
index 0000000..de9ea6a
--- /dev/null
+++ b/src/context-menu.ui
@@ -0,0 +1,14 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+  <!-- interface-requires gtk+ 3.0 -->
+  <object class= "GtkMenu" id="context-menu">
+    <property name="visible">False</property>
+    <child>
+      <object class="GtkMenuItem" id="whats-here-item">
+        <property name="name">whats-here-item</property>
+        <property name="label" translatable="yes">What's here?</property>
+        <property name="visible">True</property>
+      </object>
+    </child>
+  </object>
+</interface>
diff --git a/src/contextMenu.js b/src/contextMenu.js
new file mode 100644
index 0000000..617a676
--- /dev/null
+++ b/src/contextMenu.js
@@ -0,0 +1,81 @@
+/* -*- Mode: JS2; indent-tabs-mode: nil; js2-basic-offset: 4 -*- */
+/* vim: set et ts=4 sw=4: */
+/*
+ * Copyright (c) 2011, 2012, 2013 Red Hat, Inc.
+ *
+ * GNOME Maps 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 2 of the License, or (at your
+ * option) any later version.
+ *
+ * GNOME Maps 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 GNOME Maps; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ *
+ * Author: Zeeshan Ali (Khattak) <zeeshanak gnome org>
+ */
+
+const Gtk = imports.gi.Gtk;
+const Clutter = imports.gi.Clutter;
+const Geocode = imports.gi.GeocodeGlib;
+
+const Application = imports.application;
+const Lang = imports.lang;
+const Utils = imports.utils;
+
+const ContextMenu = new Lang.Class({
+    Name: 'ContextMenu',
+
+    _init: function(mapView) {
+        this._mapView = mapView;
+
+        let ui = Utils.getUIObject('context-menu', ['context-menu',
+                                                    'whats-here-item']);
+        this._menu = ui.contextMenu;
+
+        this._mapView.view.connect('button-release-event',
+                                   this._onButtonReleaseEvent.bind(this));
+
+        ui.whatsHereItem.connect('activate',
+                                 this._onWhatsHereActivated.bind(this));
+    },
+
+    _onButtonReleaseEvent: function(actor, event) {
+        let button = event.get_button();
+        let [x, y] = event.get_coords();
+        this._longitude = this._mapView.view.x_to_longitude(x);
+        this._latitude = this._mapView.view.y_to_latitude(y);
+
+        if (button === Clutter.BUTTON_SECONDARY) {
+            this._menu.popup(null, null, null, button, event.get_time());
+        }
+    },
+
+    _onWhatsHereActivated: function() {
+        let location = new Geocode.Location({ latitude: this._latitude,
+                                              longitude: this._longitude,
+                                              accuracy: 0 });
+        let reverse = Geocode.Reverse.new_for_location(location);
+
+        Application.application.mark_busy();
+        reverse.resolve_async (null, (function(reverse, res) {
+            Application.application.unmark_busy();
+            try {
+                let place = reverse.resolve_finish(res);
+
+                this._mapView.showLocation(place.location);
+            } catch (e) {
+                log ("Error finding place at " +
+                     this._latitude + ", " +
+                     this._longitude + ": " +
+                     e.message);
+            }
+        }).bind(this));
+    }
+});
+Utils.addSignalMethods(ContextMenu.prototype);
diff --git a/src/gnome-maps.gresource.xml b/src/gnome-maps.gresource.xml
index 0265ec2..6250d60 100644
--- a/src/gnome-maps.gresource.xml
+++ b/src/gnome-maps.gresource.xml
@@ -5,6 +5,7 @@
     <file preprocess="xml-stripblanks">main-window.ui</file>
     <file preprocess="xml-stripblanks">zoom-control.ui</file>
     <file preprocess="xml-stripblanks">search-popup.ui</file>
+    <file preprocess="xml-stripblanks">context-menu.ui</file>
     <file alias="application.css">../data/gnome-maps.css</file>
     <file alias="zoom-in.png">../data/media/zoom-in.png</file>
     <file alias="zoom-out.png">../data/media/zoom-out.png</file>
diff --git a/src/mainWindow.js b/src/mainWindow.js
index 5490524..94bd7ef 100644
--- a/src/mainWindow.js
+++ b/src/mainWindow.js
@@ -34,6 +34,7 @@ const Mainloop = imports.mainloop;
 const Application = imports.application;
 const MapView = imports.mapView;
 const SearchPopup = imports.searchPopup;
+const ContextMenu = imports.contextMenu;
 const Utils = imports.utils;
 const Config = imports.config;
 
@@ -72,6 +73,8 @@ const MainWindow = new Lang.Class({
 
         this.mapView.gotoUserLocation(false);
 
+        this._contextMenu = new ContextMenu.ContextMenu(this.mapView);
+
         this._initSearchWidgets();
         this._initActions();
         this._initSignals();


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