1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
|
/* -*- Mode: JS2; indent-tabs-mode: nil; js2-basic-offset: 4 -*- */
/* vim: set et ts=4 sw=4: */
/*
* Copyright (c) 2014 Damián Nohales
*
* 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, see <http://www.gnu.org/licenses/>.
*
* Author: Damián Nohales <damiannohales@gmail.com>
*/
const Gio = imports.gi.Gio;
const GLib = imports.gi.GLib;
const GObject = imports.gi.GObject;
const Gtk = imports.gi.Gtk;
const Lang = imports.lang;
const Mainloop = imports.mainloop;
const Application = imports.application;
const Place = imports.place;
const PlaceStore = imports.placeStore;
const SendToDialog = imports.sendToDialog;
const Utils = imports.utils;
const Button = {
NONE: 0,
ROUTE: 2,
SEND_TO: 4,
FAVORITE: 8,
CHECK_IN: 16
};
const MapBubble = new Lang.Class({
Name: "MapBubble",
Extends: Gtk.Popover,
Abstract: true,
_init: function(params) {
this._place = params.place;
delete params.place;
this._mapView = params.mapView;
params.relative_to = params.mapView;
params.transitions_enabled = false;
delete params.mapView;
let buttonFlags = params.buttons || Button.NONE;
delete params.buttons;
let routeFrom = params.routeFrom;
delete params.routeFrom;
let checkInMatchPlace = params.checkInMatchPlace;
if (checkInMatchPlace !== false)
checkInMatchPlace = true;
delete params.checkInMatchPlace;
params.modal = false;
this.parent(params);
let ui = Utils.getUIObject('map-bubble', [ 'bubble-main-grid',
'bubble-image',
'bubble-content-area',
'bubble-button-area',
'bubble-route-button',
'bubble-send-to-button',
'bubble-favorite-button',
'bubble-check-in-button',
'bubble-favorite-button-image']);
this._image = ui.bubbleImage;
this._content = ui.bubbleContentArea;
if (!buttonFlags)
ui.bubbleButtonArea.visible = false;
else {
if (buttonFlags & Button.ROUTE)
this._initRouteButton(ui.bubbleRouteButton, routeFrom);
if (buttonFlags & Button.SEND_TO)
this._initSendToButton(ui.bubbleSendToButton);
if (buttonFlags & Button.FAVORITE)
this._initFavoriteButton(ui.bubbleFavoriteButton, ui.bubbleFavoriteButtonImage);
if (buttonFlags & Button.CHECK_IN)
this._initCheckInButton(ui.bubbleCheckInButton, checkInMatchPlace);
}
this.add(ui.bubbleMainGrid);
},
get image() {
return this._image;
},
get place() {
return this._place;
},
get content() {
return this._content;
},
_initFavoriteButton: function(button, image) {
let placeStore = Application.placeStore;
button.visible = true;
if (placeStore.exists(this._place,
PlaceStore.PlaceType.FAVORITE)) {
image.icon_name = 'starred-symbolic';
} else {
image.icon_name = 'non-starred-symbolic';
}
button.connect('clicked', (function() {
if (placeStore.exists(this._place,
PlaceStore.PlaceType.FAVORITE)) {
image.icon_name = 'non-starred-symbolic';
placeStore.removePlace(this._place,
PlaceStore.PlaceType.FAVORITE);
} else {
image.icon_name = 'starred-symbolic';
placeStore.addPlace(this._place,
PlaceStore.PlaceType.FAVORITE);
}
}).bind(this));
},
_initSendToButton: function(button) {
let dialog = new SendToDialog.SendToDialog({ transient_for: this.get_toplevel(),
mapView: this._mapView,
place: this._place });
if (!dialog.ensureApplications())
return;
button.visible = true;
button.connect('clicked', function() {
dialog.connect('response', function() {
dialog.hide();
});
dialog.show_all();
});
},
_initRouteButton: function(button, routeFrom) {
let query = Application.routeService.query;
let route = Application.routeService.route;
let from = query.points[0];
let to = query.points[query.points.length - 1];
button.visible = true;
button.connect('clicked', (function() {
query.freeze_notify();
query.reset();
route.reset();
if (routeFrom) {
from.place = this._place;
} else {
if (Application.geoclue.place)
from.place = Application.geoclue.place;
to.place = this._place;
}
this.destroy();
query.thaw_notify();
}).bind(this));
},
_initCheckInButton: function(button, matchPlace) {
Application.checkInManager.bind_property('hasCheckIn',
button, 'visible',
GObject.BindingFlags.DEFAULT |
GObject.BindingFlags.SYNC_CREATE);
button.connect('clicked', (function() {
Application.checkInManager.showCheckInDialog(this.get_toplevel(),
this.place,
matchPlace);
}).bind(this));
}
});
|