[gnome-maps] Add ShareDialog
- From: Jonas Danielsson <jonasdn src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-maps] Add ShareDialog
- Date: Fri, 21 Nov 2014 21:39:38 +0000 (UTC)
commit b621c3aa3704d6ef4c146cc3cbab371c48e20d28
Author: Jonas Danielsson <jonas threetimestwo org>
Date: Wed Nov 19 02:02:32 2014 -0500
Add ShareDialog
Add the ShareDialog module, which includes sharing a place to
GNOME Weather and GNOME Clocks.
https://bugzilla.gnome.org/show_bug.cgi?id=728117
po/POTFILES.in | 1 +
src/gnome-maps.data.gresource.xml | 1 +
src/gnome-maps.js.gresource.xml | 1 +
src/share-dialog.ui | 139 +++++++++++++++++++++++++++++++++++++
src/shareDialog.js | 131 ++++++++++++++++++++++++++++++++++
5 files changed, 273 insertions(+), 0 deletions(-)
---
diff --git a/po/POTFILES.in b/po/POTFILES.in
index c9aeed6..9417e87 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -12,6 +12,7 @@ src/mapView.js
src/place.js
src/routeService.js
src/searchResultBubble.js
+[type: gettext/glade]src/share-dialog.ui
src/sidebar.js
[type: gettext/glade]src/sidebar.ui
[type: gettext/glade]src/user-location-bubble.ui
diff --git a/src/gnome-maps.data.gresource.xml b/src/gnome-maps.data.gresource.xml
index 5af82f8..82bdf11 100644
--- a/src/gnome-maps.data.gresource.xml
+++ b/src/gnome-maps.data.gresource.xml
@@ -14,6 +14,7 @@
<file preprocess="xml-stripblanks">route-via-row.ui</file>
<file preprocess="xml-stripblanks">map-bubble.ui</file>
<file preprocess="xml-stripblanks">search-result-bubble.ui</file>
+ <file preprocess="xml-stripblanks">share-dialog.ui</file>
<file preprocess="xml-stripblanks">user-location-bubble.ui</file>
<file alias="application.css">../data/gnome-maps.css</file>
<file alias="maptype-aerial.png">../data/media/maptype-aerial.png</file>
diff --git a/src/gnome-maps.js.gresource.xml b/src/gnome-maps.js.gresource.xml
index 1b3c13b..ff80c84 100644
--- a/src/gnome-maps.js.gresource.xml
+++ b/src/gnome-maps.js.gresource.xml
@@ -29,6 +29,7 @@
<file>searchPopup.js</file>
<file>searchResultBubble.js</file>
<file>searchResultMarker.js</file>
+ <file>shareDialog.js</file>
<file>turnPointBubble.js</file>
<file>turnPointMarker.js</file>
<file>settings.js</file>
diff --git a/src/share-dialog.ui b/src/share-dialog.ui
new file mode 100644
index 0000000..f3d8976
--- /dev/null
+++ b/src/share-dialog.ui
@@ -0,0 +1,139 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- Generated with glade 3.18.3 -->
+<interface>
+ <requires lib="gtk+" version="3.12"/>
+ <template class="Gjs_ShareDialog" parent="GtkDialog">
+ <property name="visible">False</property>
+ <property name="can_focus">False</property>
+ <property name="use_header_bar">1</property>
+ <child internal-child="headerbar">
+ <object class="GtkHeaderBar" id="headerBar">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="show_close_button">False</property>
+ <property name="title" translatable="yes">Share location</property>
+ <style>
+ <class name="titlebar"/>
+ </style>
+ <child>
+ <object class="GtkButton" id="cancelButton">
+ <property name="label" translatable="yes">_Cancel</property>
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="use_underline">True</property>
+ <style>
+ <class name="text-button"/>
+ </style>
+ </object>
+ <packing>
+ <property name="pack_type">start</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkButton" id="chooseButton">
+ <property name="label" translatable="yes">_Share</property>
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="can_default">True</property>
+ <property name="has_default">True</property>
+ <property name="receives_default">True</property>
+ <property name="valign">center</property>
+ <property name="use_underline">True</property>
+ <style>
+ <class name="suggested-action"/>
+ <class name="text-button"/>
+ </style>
+ </object>
+ <packing>
+ <property name="pack_type">end</property>
+ </packing>
+ </child>
+ </object>
+ </child>
+ <child internal-child="vbox">
+ <object class="GtkBox" id="contentArea">
+ <child>
+ <object class="GtkFrame" id="frame">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="shadow-type">in</property>
+ <property name="margin">10</property>
+ <child>
+ <object class="GtkScrolledWindow" id="scrolledWindow">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="hscrollbar_policy">never</property>
+ <child>
+ <object class="GtkListBox" id="list">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="activate_on_single_click">True</property>
+ <property name="selection_mode">single</property>
+ <child>
+ <object class="GtkListBoxRow" id="weatherRow">
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="height_request">40</property>
+ <child>
+ <object class="GtkGrid" id="weatherGrid">
+ <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="icon_name">org.gnome.Weather.Application</property>
+ <property name="pixel_size">32</property>
+ <property name="halign">start</property>
+ </object>
+ </child>
+ <child>
+ <object class="GtkLabel">
+ <property name="visible">True</property>
+ <property name="label" translatable="yes">Weather</property>
+ <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="GtkGrid" id="clocksGrid">
+ <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="icon_name">gnome-clocks</property>
+ <property name="pixel_size">32</property>
+ <property name="halign">start</property>
+ </object>
+ </child>
+ <child>
+ <object class="GtkLabel">
+ <property name="visible">True</property>
+ <property name="label" translatable="yes">Clocks</property>
+ <property name="margin-end">10</property>
+ </object>
+ </child>
+ </object>
+ </child>
+ </object>
+ </child>
+ </object>
+ </child>
+ </object>
+ </child>
+ </object>
+ </child>
+ </object>
+ </child>
+ </template>
+</interface>
diff --git a/src/shareDialog.js b/src/shareDialog.js
new file mode 100644
index 0000000..8c3ce88
--- /dev/null
+++ b/src/shareDialog.js
@@ -0,0 +1,131 @@
+/* -*- Mode: JS2; indent-tabs-mode: nil; js2-basic-offset: 4 -*- */
+/* vim: set et ts=4 sw=4: */
+/*
+ * 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: Jonas Danielson <jonas threetimestwo org>
+ */
+
+const Gio = imports.gi.Gio;
+const GLib = imports.gi.GLib;
+const Gtk = imports.gi.Gtk;
+const GWeather = imports.gi.GWeather;
+const Lang = imports.lang;
+
+const Application = imports.application;
+const Utils = imports.utils;
+
+const _WEATHER_APPID = 'org.gnome.Weather.Application';
+const _CLOCKS_APPID = 'org.gnome.clocks';
+
+const Response = {
+ SUCCESS: 0,
+ CANCEL: 1
+};
+
+const _NUM_VISIBLE = 6;
+
+const ShareDialog = new Lang.Class({
+ Name: 'ShareDialog',
+ Extends: Gtk.Dialog,
+ Template: 'resource:///org/gnome/maps/share-dialog.ui',
+ InternalChildren: [ 'list',
+ 'weatherRow',
+ 'clocksRow',
+ 'headerBar',
+ 'cancelButton',
+ 'chooseButton',
+ 'scrolledWindow' ],
+
+ _init: function(params) {
+ this._place = params.place;
+ delete params.place;
+
+ params.use_header_bar = true;
+ this.parent(params);
+
+ this._scrolledWindow.min_content_height = 40 * _NUM_VISIBLE;
+ this._headerBar.subtitle = this._place.name;
+
+ this._cancelButton.connect('clicked',
+ this.response.bind(this, Response.CANCEL));
+
+ this._chooseButton.connect('clicked',
+ this._onChooseButtonClicked.bind(this));
+
+ this._list.set_header_func(function(row, before) {
+ let horizontal = Gtk.Orientation.HORIZONTAL;
+
+ if (before)
+ row.set_header(new Gtk.Separator({ orientation: horizontal }));
+ else
+ row.set_header(null);
+ });
+ },
+
+ ensureShares: function() {
+ let shareWeather = this._checkWeather();
+ let shareClocks = this._checkClocks();
+
+ if (!shareWeather)
+ this._weatherRow.hide();
+
+ if (!shareClocks)
+ this._clocksRow.hide();
+
+ return shareWeather || shareClocks;
+ },
+
+ _onChooseButtonClicked: function() {
+ let rows = this._list.get_selected_rows();
+ if (rows.length === 0)
+ this.response(Response.CANCEL);
+
+ if (rows[0] === this._weatherRow || rows[0] === this._clocksRow) {
+ let world = GWeather.Location.get_world();
+ let city = world.find_nearest_city(this._place.location.latitude,
+ this._place.location.longitude);
+ let appId;
+ let action;
+ if (rows[0] === this._weatherRow) {
+ action = 'show-location';
+ appId = _WEATHER_APPID;
+ } else {
+ action = 'add-location';
+ appId = _CLOCKS_APPID;
+ }
+
+ Utils.activateAction(appId,
+ action,
+ new GLib.Variant('v', city.serialize()),
+ Gtk.get_current_event_time());
+
+ this.response(Response.SUCCESS);
+ }
+ },
+
+ _checkApp: function(appId) {
+ let info = Gio.DesktopAppInfo.new(appId + '.desktop');
+ return info !== null;
+ },
+
+ _checkWeather: function() {
+ return (GWeather !== null && this._checkApp(_WEATHER_APPID));
+ },
+
+ _checkClocks: function() {
+ return (GWeather !== null && this._checkApp(_CLOCKS_APPID));
+ }
+});
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]