[gnome-maps/wip/favorites: 5/8] MapBubble: Add favorite button



commit c9a582214d96ca2629b36bee522c35000120cc0c
Author: Jonas Danielsson <jonas threetimestwo org>
Date:   Sat Nov 22 21:13:32 2014 +0100

    MapBubble: Add favorite button
    
    https://bugzilla.gnome.org/show_bug.cgi?id=722102

 src/map-bubble.ui |   17 +++++++++++++++++
 src/mapBubble.js  |   28 ++++++++++++++++++++++++++--
 2 files changed, 43 insertions(+), 2 deletions(-)
---
diff --git a/src/map-bubble.ui b/src/map-bubble.ui
index 1cbb149..b7143ab 100644
--- a/src/map-bubble.ui
+++ b/src/map-bubble.ui
@@ -78,6 +78,23 @@
                 </child>
               </object>
             </child>
+            <child>
+              <object class="GtkToggleButton" id="bubble-favorite-button">
+                <property name="name">bubble-favorite-button</property>
+                <property name="visible">False</property>
+                <property name="can_focus">True</property>
+                <property name="receives_default">False</property>
+                <child>
+                  <object class="GtkImage" id="bubble-favorite-button-image">
+                <property name="name">bubble-favorite-button-image</property>
+                    <property name="visible">True</property>
+                    <property name="can_focus">False</property>
+                    <property name="icon-name">emblem-favorite-symbolic</property>
+                    <property name="pixel_size">16</property>
+                  </object>
+                </child>
+              </object>
+            </child>
           </object>
           <packing>
             <property name="left_attach">0</property>
diff --git a/src/mapBubble.js b/src/mapBubble.js
index 4182a6d..e8d2f0a 100644
--- a/src/mapBubble.js
+++ b/src/mapBubble.js
@@ -27,13 +27,16 @@ const Lang = imports.lang;
 const Mainloop = imports.mainloop;
 
 const Application = imports.application;
+const Place = imports.place;
+const PlaceStore = imports.placeStore;
 const ShareDialog = imports.shareDialog;
 const Utils = imports.utils;
 
 const Button = {
     NONE: 0,
     ROUTE: 2,
-    SHARE: 4
+    SHARE: 4,
+    FAVORITE: 8
 };
 
 const MapBubble = new Lang.Class({
@@ -63,7 +66,8 @@ const MapBubble = new Lang.Class({
                                                    'bubble-content-area',
                                                    'bubble-button-area',
                                                    'bubble-route-button',
-                                                   'bubble-share-button' ]);
+                                                   'bubble-share-button',
+                                                   'bubble-favorite-button']);
         this._image = ui.bubbleImage;
         this._content = ui.bubbleContentArea;
 
@@ -74,6 +78,8 @@ const MapBubble = new Lang.Class({
                 this._initRouteButton(ui.bubbleRouteButton, routeFrom);
             if (buttonFlags & Button.SHARE)
                 this._initShareButton(ui.bubbleShareButton);
+            if (buttonFlags & Button.FAVORITE)
+                this._initFavoriteButton(ui.bubbleFavoriteButton);
         }
 
         this.add(ui.bubbleMainGrid);
@@ -91,6 +97,24 @@ const MapBubble = new Lang.Class({
         return this._content;
     },
 
+    _initFavoriteButton: function(button) {
+        let placeStore = Application.placeStore;
+        let isFavorite = placeStore.exists(this._place.osm_id,
+                                           PlaceStore.PlaceType.FAVORITE);
+        button.visible = true;
+        button.active = isFavorite;
+        button.connect('toggled', (function() {
+            let place = new Place.Place({ place: this._place });
+
+            if (button.active)
+                placeStore.addPlace(place,
+                                    PlaceStore.PlaceType.FAVORITE);
+            else
+                placeStore.removePlace(place,
+                                       PlaceStore.PlaceType.FAVORITE);
+        }).bind(this));
+    },
+
     _initShareButton: function(button) {
         let dialog = new ShareDialog.ShareDialog({ transient_for: this.get_toplevel(),
                                                    place: this._place });


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