[gnome-maps] Add open with browser to send-to-dialog
- From: Jonas Danielsson <jonasdn src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-maps] Add open with browser to send-to-dialog
- Date: Thu, 5 Nov 2015 15:26:15 +0000 (UTC)
commit 687b3c1060754a18f14844544f53b00751e6d58f
Author: Jonas Danielsson <jonas threetimestwo org>
Date: Mon Nov 2 22:52:04 2015 +0800
Add open with browser to send-to-dialog
This will add your default launcher for the
'https' URI scheme as an option to send-to-dialog.
https://bugzilla.gnome.org/show_bug.cgi?id=756512
data/ui/send-to-dialog.ui | 27 +++++++++++++++++++++
src/mapBubble.js | 1 +
src/overpass.js | 12 +--------
src/sendToDialog.js | 56 +++++++++++++++++++++++++++++++++++++++++----
src/utils.js | 9 +++++++
5 files changed, 90 insertions(+), 15 deletions(-)
---
diff --git a/data/ui/send-to-dialog.ui b/data/ui/send-to-dialog.ui
index 7fb2077..15e0060 100644
--- a/data/ui/send-to-dialog.ui
+++ b/data/ui/send-to-dialog.ui
@@ -126,6 +126,33 @@
</child>
</object>
</child>
+ <child>
+ <object class="GtkListBoxRow" id="browserRow">
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="height_request">40</property>
+ <child>
+ <object class="GtkGrid" id="browserGrid">
+ <property name="visible">True</property>
+ <property name="orientation">horizontal</property>
+ <property name="column_spacing">10</property>
+ <child>
+ <object class="GtkImage" id="browserIcon">
+ <property name="visible">True</property>
+ <property name="pixel_size">32</property>
+ <property name="halign">start</property>
+ </object>
+ </child>
+ <child>
+ <object class="GtkLabel" id="browserLabel">
+ <property name="visible">True</property>
+ <property name="margin-end">10</property>
+ </object>
+ </child>
+ </object>
+ </child>
+ </object>
+ </child>
</object>
</child>
</object>
diff --git a/src/mapBubble.js b/src/mapBubble.js
index 28a6f37..3a8ebb7 100644
--- a/src/mapBubble.js
+++ b/src/mapBubble.js
@@ -135,6 +135,7 @@ const MapBubble = new Lang.Class({
_initSendToButton: function(button) {
let dialog = new SendToDialog.SendToDialog({ transient_for: this.get_toplevel(),
+ mapView: this._mapView,
place: this._place });
if (!dialog.ensureApplications())
return;
diff --git a/src/overpass.js b/src/overpass.js
index 372a0f1..e471fd4 100644
--- a/src/overpass.js
+++ b/src/overpass.js
@@ -23,6 +23,7 @@ const Lang = imports.lang;
const Soup = imports.gi.Soup;
const Place = imports.place;
+const Utils = imports.utils;
const _DEFAULT_TIMEOUT = 180;
const _DEFAULT_MAXSIZE = 536870912;
@@ -120,17 +121,8 @@ const Overpass = new Lang.Class({
value ]);
},
- _osmTypeString: function(osmType) {
- switch(osmType) {
- case Geocode.PlaceOsmType.NODE: return 'node';
- case Geocode.PlaceOsmType.RELATION: return 'relation';
- case Geocode.PlaceOsmType.WAY: return 'way';
- default: return 'node';
- }
- },
-
_getData: function(place) {
- return Format.vprintf('%s(%s)', [this._osmTypeString(place.osm_type),
+ return Format.vprintf('%s(%s)', [Utils.osmTypeToString(place.osm_type),
place.osm_id]);
},
diff --git a/src/sendToDialog.js b/src/sendToDialog.js
index 5c8b7d5..4940641 100644
--- a/src/sendToDialog.js
+++ b/src/sendToDialog.js
@@ -17,6 +17,7 @@
* Author: Jonas Danielson <jonas threetimestwo org>
*/
+const Gdk = imports.gi.Gdk;
const Gio = imports.gi.Gio;
const GLib = imports.gi.GLib;
const Gtk = imports.gi.Gtk;
@@ -45,6 +46,9 @@ const SendToDialog = new Lang.Class({
'weatherLabel',
'clocksRow',
'clocksLabel',
+ 'browserRow',
+ 'browserLabel',
+ 'browserIcon',
'headerBar',
'cancelButton',
'chooseButton',
@@ -54,6 +58,9 @@ const SendToDialog = new Lang.Class({
this._place = params.place;
delete params.place;
+ this._mapView = params.mapView;
+ delete params.mapView;
+
params.use_header_bar = true;
this.parent(params);
@@ -79,6 +86,7 @@ const SendToDialog = new Lang.Class({
ensureApplications: function() {
let weatherInfo = Gio.DesktopAppInfo.new(_WEATHER_APPID + '.desktop');
let clocksInfo = Gio.DesktopAppInfo.new(_CLOCKS_APPID + '.desktop');
+ let browserInfo = Gio.AppInfo.get_default_for_uri_scheme('https');
let appWeather = this._checkWeather(weatherInfo);
let appClocks = this._checkClocks(clocksInfo);
@@ -92,7 +100,31 @@ const SendToDialog = new Lang.Class({
else
this._clocksLabel.label = clocksInfo.get_name();
- return appWeather || appClocks;
+ if (!browserInfo) {
+ this._browserRow.hide();
+ } else {
+ this._browserLabel.label = browserInfo.get_name();
+ this._browserIcon.icon_name = browserInfo.get_icon().to_string();
+ }
+
+ return appWeather || appClocks || browserInfo;
+ },
+
+ _getOSMURI: function() {
+ let view = this._mapView.view;
+ let place = this._place;
+
+ let base = 'https://openstreetmap.org';
+ if (this._place.osm_id && this._place.osm_type) {
+ return '%s/%s/%s'.format(base,
+ Utils.osmTypeToString(place.osm_type),
+ place.osm_id);
+ } else {
+ return '%s?lat=%f&lon=%f&zoom=%d'.format(base,
+ place.location.latitude,
+ place.location.longitude,
+ view.zoom_level);
+ }
},
_onChooseButtonClicked: function() {
@@ -100,13 +132,14 @@ const SendToDialog = new Lang.Class({
if (rows.length === 0)
this.response(Response.CANCEL);
+ let timestamp = Gtk.get_current_event_time();
+
if (rows[0] === this._weatherRow || rows[0] === this._clocksRow) {
let location = this._place.location;
let city = GWeather.Location.new_detached(this._place.name,
null,
location.latitude,
location.longitude);
- let appId;
let action;
if (rows[0] === this._weatherRow) {
action = 'show-location';
@@ -119,10 +152,23 @@ const SendToDialog = new Lang.Class({
Utils.activateAction(appId,
action,
new GLib.Variant('v', city.serialize()),
- Gtk.get_current_event_time());
-
- this.response(Response.SUCCESS);
+ timestamp);
+ } else if (rows[0] === this._browserRow) {
+ try {
+ let display = Gdk.Display.get_default();
+ let ctx = Gdk.Display.get_default().get_app_launch_context();
+ let screen = display.get_default_screen();
+
+ ctx.set_timestamp(timestamp);
+ ctx.set_screen(screen);
+ Gio.app_info_launch_default_for_uri(this._getOSMURI(), ctx);
+ } catch(e) {
+ let msg = _("Failed to open URI");
+ Application.notificationManager.showMessage(msg);
+ Utils.debug('failed to open URI: %s'.format(e.message));
+ }
}
+ this.response(Response.SUCCESS);
},
_checkWeather: function(appInfo) {
diff --git a/src/utils.js b/src/utils.js
index e112e09..caa1b84 100644
--- a/src/utils.js
+++ b/src/utils.js
@@ -342,6 +342,15 @@ function _load_themed_icon(icon, size, loadCompleteCallback) {
}
}
+function osmTypeToString(osmType) {
+ switch(osmType) {
+ case Geocode.PlaceOsmType.NODE: return 'node';
+ case Geocode.PlaceOsmType.RELATION: return 'relation';
+ case Geocode.PlaceOsmType.WAY: return 'way';
+ default: return 'node';
+ }
+}
+
function prettyTime(time) {
let seconds = Math.floor(time / 1000);
let minutes = Math.floor(seconds / 60);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]