[gnome-maps] sendToDialog: Add summary text
- From: Marcus Lundblad <mlundblad src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-maps] sendToDialog: Add summary text
- Date: Thu, 13 Jun 2019 19:06:41 +0000 (UTC)
commit 131e0a4eca7278bda4a459308f99b11fbe2a230f
Author: James Westman <flyingpimonster flyingpimonster net>
Date: Mon Jun 3 18:43:26 2019 -0500
sendToDialog: Add summary text
This is a label with the name, address, coordinates, and OSM url of a
place. There are buttons to copy the text or email it to someone. The
link in the summary text replaces the browser row.
Part of the share dialog overhaul, #167.
data/ui/send-to-dialog.ui | 156 +++++++++++++++++++++++++---------------------
src/sendToDialog.js | 100 ++++++++++++++++++++---------
2 files changed, 156 insertions(+), 100 deletions(-)
---
diff --git a/data/ui/send-to-dialog.ui b/data/ui/send-to-dialog.ui
index 7ba4836..3ca9ebb 100644
--- a/data/ui/send-to-dialog.ui
+++ b/data/ui/send-to-dialog.ui
@@ -53,100 +53,116 @@
</child>
<child internal-child="vbox">
<object class="GtkBox" id="contentArea">
+ <property name="orientation">vertical</property>
+ <property name="margin">18</property>
+ <property name="spacing">12</property>
<child>
- <object class="GtkFrame" id="frame">
+ <object class="GtkBox">
+ <property name="orientation">horizontal</property>
+ <property name="spacing">6</property>
+ <child>
+ <object class="GtkBox">
+ <property name="orientation">vertical</property>
+ <child>
+ <object class="GtkLabel" id="summaryLabel">
+ <property name="selectable">true</property>
+ <property name="label">…</property>
+ <property name="justify">left</property>
+ <property name="halign">start</property>
+ </object>
+ </child>
+ <child>
+ <object class="GtkLabel" id="summaryUrl">
+ <property name="selectable">true</property>
+ <property name="use-markup">true</property>
+ <property name="label">…</property>
+ <property name="xalign">0</property>
+ <property name="width-request">0</property>
+ <property name="ellipsize">end</property>
+ </object>
+ </child>
+ </object>
+ </child>
+ <child>
+ <object class="GtkBox">
+ <property name="orientation">vertical</property>
+ <property name="spacing">6</property>
+ <child>
+ <object class="GtkButton" id="copyButton">
+ <property name="label" translatable="yes">Copy</property>
+ </object>
+ </child>
+ <child>
+ <object class="GtkButton" id="emailButton">
+ <property name="label" translatable="yes">Send To…</property>
+ </object>
+ </child>
+ </object>
+ <packing>
+ <property name="pack_type">end</property>
+ </packing>
+ </child>
+ </object>
+ </child>
+ <child>
+ <object class="GtkScrolledWindow" id="scrolledWindow">
<property name="visible">True</property>
<property name="can_focus">False</property>
- <property name="shadow-type">in</property>
- <property name="margin">10</property>
+ <property name="hscrollbar_policy">never</property>
<child>
- <object class="GtkScrolledWindow" id="scrolledWindow">
+ <object class="GtkListBox" id="list">
<property name="visible">True</property>
<property name="can_focus">False</property>
- <property name="hscrollbar_policy">never</property>
+ <property name="activate_on_single_click">False</property>
+ <property name="selection_mode">single</property>
<child>
- <object class="GtkListBox" id="list">
+ <object class="GtkListBoxRow" id="weatherRow">
<property name="visible">True</property>
- <property name="can_focus">False</property>
- <property name="activate_on_single_click">False</property>
- <property name="selection_mode">single</property>
+ <property name="can_focus">True</property>
+ <property name="height_request">40</property>
<child>
- <object class="GtkListBoxRow" id="weatherRow">
+ <object class="GtkGrid" id="weatherGrid">
<property name="visible">True</property>
- <property name="can_focus">True</property>
- <property name="height_request">40</property>
+ <property name="orientation">horizontal</property>
+ <property name="column_spacing">10</property>
<child>
- <object class="GtkGrid" id="weatherGrid">
+ <object class="GtkImage" id="weatherIcon">
<property name="visible">True</property>
- <property name="orientation">horizontal</property>
- <property name="column_spacing">10</property>
- <child>
- <object class="GtkImage" id="weatherIcon">
- <property name="visible">True</property>
- <property name="pixel_size">32</property>
- <property name="halign">start</property>
- </object>
- </child>
- <child>
- <object class="GtkLabel" id='weatherLabel'>
- <property name="visible">True</property>
- <property name="margin-end">10</property>
- </object>
- </child>
+ <property name="pixel_size">32</property>
+ <property name="halign">start</property>
</object>
</child>
- </object>
- </child>
- <child>
- <object class="GtkListBoxRow" id="clocksRow">
- <property name="visible">True</property>
- <property name="can_focus">True</property>
- <property name="height_request">40</property>
<child>
- <object class="GtkGrid" id="clocksGrid">
+ <object class="GtkLabel" id='weatherLabel'>
<property name="visible">True</property>
- <property name="orientation">horizontal</property>
- <property name="column_spacing">10</property>
- <child>
- <object class="GtkImage" id="clocksIcon">
- <property name="visible">True</property>
- <property name="pixel_size">32</property>
- <property name="halign">start</property>
- </object>
- </child>
- <child>
- <object class="GtkLabel" id="clocksLabel">
- <property name="visible">True</property>
- <property name="margin-end">10</property>
- </object>
- </child>
+ <property name="margin-end">10</property>
</object>
</child>
</object>
</child>
+ </object>
+ </child>
+ <child>
+ <object class="GtkListBoxRow" id="clocksRow">
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="height_request">40</property>
<child>
- <object class="GtkListBoxRow" id="browserRow">
+ <object class="GtkGrid" id="clocksGrid">
<property name="visible">True</property>
- <property name="can_focus">True</property>
- <property name="height_request">40</property>
+ <property name="orientation">horizontal</property>
+ <property name="column_spacing">10</property>
+ <child>
+ <object class="GtkImage" id="clocksIcon">
+ <property name="visible">True</property>
+ <property name="pixel_size">32</property>
+ <property name="halign">start</property>
+ </object>
+ </child>
<child>
- <object class="GtkGrid" id="browserGrid">
+ <object class="GtkLabel" id="clocksLabel">
<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>
+ <property name="margin-end">10</property>
</object>
</child>
</object>
diff --git a/src/sendToDialog.js b/src/sendToDialog.js
index 0091dfd..d66f7d2 100644
--- a/src/sendToDialog.js
+++ b/src/sendToDialog.js
@@ -23,7 +23,9 @@ const GLib = imports.gi.GLib;
const GObject = imports.gi.GObject;
const Gtk = imports.gi.Gtk;
const GWeather = imports.gi.GWeather;
+const Soup = imports.gi.Soup;
+const PlaceFormatter = imports.placeFormatter;
const Utils = imports.utils;
const _WEATHER_APPID = 'org.gnome.Weather.Application';
@@ -45,12 +47,13 @@ var SendToDialog = GObject.registerClass({
'clocksRow',
'clocksLabel',
'clocksIcon',
- 'browserRow',
- 'browserLabel',
- 'browserIcon',
'headerBar',
'cancelButton',
'chooseButton',
+ 'summaryLabel',
+ 'summaryUrl',
+ 'copyButton',
+ 'emailButton',
'scrolledWindow' ]
}, class SendToDialog extends Gtk.Dialog {
@@ -85,12 +88,20 @@ var SendToDialog = GObject.registerClass({
else
row.set_header(null);
});
+
+ this.connect('show', () => {
+ this._summaryLabel.label = this._getSummary();
+ let osmuri = GLib.markup_escape_text(this._getOSMURI(), -1);
+ this._summaryUrl.label = "<a href='%s'>%s</a>".format(osmuri, osmuri);
+
+ this._copyButton.connect('clicked', () => this._copySummary());
+ this._emailButton.connect('clicked', () => this._emailSummary());
+ });
}
ensureApplications() {
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);
@@ -108,18 +119,29 @@ var SendToDialog = GObject.registerClass({
this._clocksIcon.icon_name = clocksInfo.get_icon().to_string();
}
- if (!browserInfo) {
- this._browserRow.hide();
- } else {
- this._browserLabel.label = browserInfo.get_name();
- try {
- this._browserIcon.icon_name = browserInfo.get_icon().to_string();
- } catch(e) {
- Utils.debug('failed to get browser icon: %s'.format(e.message));
- }
+ return appWeather || appClocks;
+ }
+
+ _getSummary(markup) {
+ /* Gets a summary of the place (usually name, address, and coordinates,
+ whichever are available). Does not include OSM URL. */
+
+ let place = this._place;
+ let lines = [];
+
+ let formatter = new PlaceFormatter.PlaceFormatter(place);
+
+ lines.push(formatter.title);
+
+ let details = formatter.getDetailsString();
+ if (details) {
+ lines.push(details);
}
- return appWeather || appClocks || browserInfo;
+ lines.push('%f, %f'.format(place.location.latitude,
+ place.location.longitude));
+
+ return lines.join("\n");
}
_getOSMURI() {
@@ -139,10 +161,42 @@ var SendToDialog = GObject.registerClass({
}
}
- _activateRow(row) {
- let timestamp = Gtk.get_current_event_time();
+ _copySummary() {
+ let summary = "%s\n%s".format(this._getSummary(), this._getOSMURI());
+
+ let display = Gdk.Display.get_default();
+ let clipboard = Gtk.Clipboard.get_default(display);
+ clipboard.set_text(summary, -1);
+ this.response(Response.SUCCESS);
+ }
+
+ _emailSummary() {
+ let title = new PlaceFormatter.PlaceFormatter(this._place).title;
+ let summary = "%s\n%s".format(this._getSummary(), this._getOSMURI());
+ let uri = "mailto:?subject=%s&body=%s".format(Soup.URI.encode(title, null),
+ Soup.URI.encode(summary, null));
+
+ try {
+ let timestamp = Gtk.get_current_event_time();
+ 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(uri, ctx);
+ } catch(e) {
+ Utils.showDialog(_("Failed to open URI"), Gtk.MessageType.ERROR,
+ this.get_toplevel());
+ Utils.debug('failed to open URI: %s'.format(e.message));
+ }
+
+ this.response(Response.SUCCESS);
+ }
+ _activateRow(row) {
if (row === this._weatherRow || row === this._clocksRow) {
+ let timestamp = Gtk.get_current_event_time();
let location = this._place.location;
let city = GWeather.Location.new_detached(this._place.name,
null,
@@ -162,20 +216,6 @@ var SendToDialog = GObject.registerClass({
action,
new GLib.Variant('v', city.serialize()),
timestamp);
- } else if (row === 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) {
- Utils.showDialog(_("Failed to open URI"), Gtk.MessageType.ERROR,
- this.get_toplevel());
- Utils.debug('failed to open URI: %s'.format(e.message));
- }
}
this.response(Response.SUCCESS);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]