[gnome-weather] Add a GResource and an application menu
- From: Cosimo Cecchi <cosimoc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-weather] Add a GResource and an application menu
- Date: Wed, 6 Mar 2013 19:07:27 +0000 (UTC)
commit 11b223919a6aecbf1e5eaf4a34fb8f56a3b7b9bd
Author: Cosimo Cecchi <cosimoc gnome org>
Date: Wed Mar 6 13:05:00 2013 -0500
Add a GResource and an application menu
The application menu right now only contains "About Weather" and "Quit".
https://bugzilla.gnome.org/show_bug.cgi?id=695310
configure.ac | 3 +++
data/Makefile.am | 23 +++++++++++++++++++----
data/app-menu.ui | 15 +++++++++++++++
data/gnome-weather.gresource.xml | 7 +++++++
src/main.js | 30 +++++++++++++++++++++++++++++-
src/util.js | 17 ++++++++++++++---
src/window.js | 23 +++++++++++++++++++++++
7 files changed, 110 insertions(+), 8 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 857e8be..f451298 100644
--- a/configure.ac
+++ b/configure.ac
@@ -30,6 +30,9 @@ GOBJECT_INTROSPECTION_REQUIRE([1.30.0])
AC_PATH_PROG([GJS],[gjs])
+GLIB_COMPILE_RESOURCES=`$PKG_CONFIG --variable glib_compile_resources gio-2.0`
+AC_SUBST(GLIB_COMPILE_RESOURCES)
+
AC_CONFIG_FILES([
Makefile
data/Makefile
diff --git a/data/Makefile.am b/data/Makefile.am
index 84418d4..fc07d61 100644
--- a/data/Makefile.am
+++ b/data/Makefile.am
@@ -1,5 +1,9 @@
-cssdir = $(pkgdatadir)
-dist_css_DATA = application.css
+resource_files = $(shell $(GLIB_COMPILE_RESOURCES) --sourcedir=$(srcdir) --generate-dependencies
$(srcdir)/gnome-weather.gresource.xml)
+gnome-weather.gresource: gnome-weather.gresource.xml $(resource_files)
+ $(AM_V_GEN) $(GLIB_COMPILE_RESOURCES) --target=$@ --sourcedir=$(srcdir) $<
+
+resourcedir = $(pkgdatadir)
+resource_DATA = gnome-weather.gresource
appsdir = $(datadir)/applications
apps_DATA = gnome-weather.desktop
@@ -10,8 +14,19 @@ gsettings_SCHEMAS = org.gnome.Weather.Application.gschema.xml
@GSETTINGS_RULES@
-EXTRA_DIST = gnome-weather.desktop.in $(gsettings_SCHEMAS)
-CLEANFILES = $(apps_DATA) *.valid gschemas.compiled
+EXTRA_DIST = \
+ gnome-weather.desktop.in \
+ gnome-weather.gresource.xml \
+ $(gsettings_SCHEMAS) \
+ $(resource_files) \
+ $(NULL)
+
+CLEANFILES = \
+ gnome-weather.gresource \
+ $(apps_DATA) \
+ *.valid \
+ gschemas.compiled \
+ $(NULL)
# For uninstalled use
all-local:
diff --git a/data/app-menu.ui b/data/app-menu.ui
new file mode 100644
index 0000000..621b50a
--- /dev/null
+++ b/data/app-menu.ui
@@ -0,0 +1,15 @@
+<interface>
+ <menu id="app-menu">
+ <section>
+ <item>
+ <attribute name="action">app.about</attribute>
+ <attribute name="label" translatable="yes">About Weather</attribute>
+ </item>
+ <item>
+ <attribute name="action">app.quit</attribute>
+ <attribute name="label" translatable="yes">Quit</attribute>
+ <attribute name="accel"><Primary>q</attribute>
+ </item>
+ </section>
+ </menu>
+</interface>
diff --git a/data/gnome-weather.gresource.xml b/data/gnome-weather.gresource.xml
new file mode 100644
index 0000000..627cd69
--- /dev/null
+++ b/data/gnome-weather.gresource.xml
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<gresources>
+ <gresource prefix="/org/gnome/weather">
+ <file preprocess="xml-stripblanks">app-menu.ui</file>
+ <file>application.css</file>
+ </gresource>
+</gresources>
diff --git a/src/main.js b/src/main.js
index 99e9d05..c74e94b 100644
--- a/src/main.js
+++ b/src/main.js
@@ -44,15 +44,43 @@ const Application = new Lang.Class({
GLib.set_application_name(_("Weather"));
},
+ _onQuit: function() {
+ this.quit();
+ },
+
+ _onAbout: function() {
+ let win = this.get_active_window();
+ win.showAbout();
+ },
+
+ _initAppMenu: function() {
+ let builder = new Gtk.Builder();
+ builder.add_from_resource('/org/gnome/weather/app-menu.ui');
+
+ let menu = builder.get_object('app-menu');
+ this.set_app_menu(menu);
+ },
+
vfunc_startup: function() {
this.parent();
- Util.loadStyleSheet();
+ let resource = Gio.Resource.load(pkg.pkgdatadir + '/gnome-weather.gresource');
+ resource._register();
+
+ Util.loadStyleSheet(Gio.file_new_for_uri('resource:///org/gnome/weather/application.css'));
let settings = Gtk.Settings.get_for_screen(Gdk.Screen.get_default());
settings.gtk_application_prefer_dark_theme = true;
this.world = GWeather.Location.new_world(false);
+
+ Util.initActions(this,
+ [{ name: 'quit',
+ callback: this._onQuit },
+ { name: 'about',
+ callback: this._onAbout }]);
+
+ this._initAppMenu();
},
vfunc_activate: function() {
diff --git a/src/util.js b/src/util.js
index 6bc3c26..71ae7df 100644
--- a/src/util.js
+++ b/src/util.js
@@ -34,16 +34,27 @@ function loadUI(file) {
}
function loadStyleSheet(file) {
- file = file || 'application.css';
+ file = file || Gio.file_new_for_path(GLib.build_filenamev([pkg.pkgdatadir,
+ 'application.css']));
let provider = new Gtk.CssProvider();
- provider.load_from_path(GLib.build_filenamev([pkg.pkgdatadir,
- file]));
+ provider.load_from_file(file);
Gtk.StyleContext.add_provider_for_screen(Gdk.Screen.get_default(),
provider,
Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION);
}
+function initActions(app, simpleActionEntries) {
+ simpleActionEntries.forEach(function(entry) {
+ let action = new Gio.SimpleAction({ name: entry.name });
+
+ if (entry.callback)
+ action.connect('activate', Lang.bind(app, entry.callback));
+
+ app.add_action(action);
+ });
+}
+
function arrayEqual(one, two) {
if (one.length != two.length)
return false;
diff --git a/src/window.js b/src/window.js
index 8d0a7c8..01e20db 100644
--- a/src/window.js
+++ b/src/window.js
@@ -295,5 +295,28 @@ const MainWindow = new Lang.Class({
this._model.addLocation(entry.location);
}));
dialog.show_all();
+ },
+
+ showAbout: function() {
+ let aboutDialog = new Gtk.AboutDialog(
+ { artists: [ 'Jakub Steiner <jimmac gmail com>' ],
+ authors: [ 'Giovanni Campagna <gcampagna src gnome org>' ],
+ translator_credits: _("translator-credits"),
+ program_name: _("Weather"),
+ comments: _("A weather application"),
+ copyright: 'Copyright 2013 The Weather Developers',
+ license_type: Gtk.License.GPL_2_0,
+ logo_icon_name: 'weather-clear',
+ version: pkg.version,
+ website: 'https://live.gnome.org/Design/Apps/Weather',
+ wrap_license: true,
+ modal: true,
+ transient_for: this
+ });
+
+ aboutDialog.show();
+ aboutDialog.connect('response', function() {
+ aboutDialog.destroy();
+ });
}
});
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]