Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Basic saving of selected timezone

  • Loading branch information...
commit 314442f1d8cf97ad5eb6d0f4b66a255fdf374d85 1 parent b95b182
@mibus authored
View
93 convenience.js
@@ -0,0 +1,93 @@
+/* -*- mode: js; js-basic-offset: 4; indent-tabs-mode: nil -*- */
+/*
+ Copyright (c) 2011-2012, Giovanni Campagna <scampa.giovanni@gmail.com>
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+ * Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+ * Neither the name of the GNOME nor the
+ names of its contributors may be used to endorse or promote products
+ derived from this software without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY
+ DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+const Gettext = imports.gettext;
+const Gio = imports.gi.Gio;
+
+const Config = imports.misc.config;
+const ExtensionUtils = imports.misc.extensionUtils;
+
+/**
+ * initTranslations:
+ * @domain: (optional): the gettext domain to use
+ *
+ * Initialize Gettext to load translations from extensionsdir/locale.
+ * If @domain is not provided, it will be taken from metadata['gettext-domain']
+ */
+function initTranslations(domain) {
+ let extension = ExtensionUtils.getCurrentExtension();
+
+ domain = domain || extension.metadata['gettext-domain'];
+
+ // check if this extension was built with "make zip-file", and thus
+ // has the locale files in a subfolder
+ // otherwise assume that extension has been installed in the
+ // same prefix as gnome-shell
+ let localeDir = extension.dir.get_child('locale');
+ if (localeDir.query_exists(null))
+ Gettext.bindtextdomain(domain, localeDir.get_path());
+ else
+ Gettext.bindtextdomain(domain, Config.LOCALEDIR);
+}
+
+/**
+ * getSettings:
+ * @schema: (optional): the GSettings schema id
+ *
+ * Builds and return a GSettings schema for @schema, using schema files
+ * in extensionsdir/schemas. If @schema is not provided, it is taken from
+ * metadata['settings-schema'].
+ */
+function getSettings(schema) {
+ let extension = ExtensionUtils.getCurrentExtension();
+
+ schema = schema || extension.metadata['settings-schema'];
+
+ const GioSSS = Gio.SettingsSchemaSource;
+
+ // check if this extension was built with "make zip-file", and thus
+ // has the schema files in a subfolder
+ // otherwise assume that extension has been installed in the
+ // same prefix as gnome-shell (and therefore schemas are available
+ // in the standard folders)
+ let schemaDir = extension.dir.get_child('schemas');
+ let schemaSource;
+ if (schemaDir.query_exists(null))
+ schemaSource = GioSSS.new_from_directory(schemaDir.get_path(),
+ GioSSS.get_default(),
+ false);
+ else
+ schemaSource = GioSSS.get_default();
+
+ let schemaObj = schemaSource.lookup(schema, true);
+ if (!schemaObj)
+ throw new Error('Schema ' + schema + ' could not be found for extension '
+ + extension.metadata.uuid + '. Please check your installation.');
+
+ return new Gio.Settings({ settings_schema: schemaObj });
+}
+
View
30 extension.js
@@ -9,12 +9,24 @@ const Lang = imports.lang;
const PanelMenu = imports.ui.panelMenu;
const GnomeDesktop = imports.gi.GnomeDesktop;
+const ExtensionUtils = imports.misc.extensionUtils;
+const Me = ExtensionUtils.getCurrentExtension();
+const Convenience = Me.imports.convenience;
+
const UPDATE_INTERVAL = 5000;
+const Timezones = {
+ 'UTC': { hr: 0, min: 0, tzname: 'UTC' },
+ 'Australia/Adelaide': { hr: 10, min: 30, tzname: 'ACDT' },
+ 'Australia/Perth': { hr: 8, min: 0, tzname: 'WST' },
+};
+
const AltTimeMenuButton = new Lang.Class({
Name: 'AltTimeMenuButton',
Extends: PanelMenu.Button,
+ _schema: null,
+
_init: function() {
let item;
@@ -28,18 +40,26 @@ const AltTimeMenuButton = new Lang.Class({
this.minute_offset = 0;
this.tzname = 'WST';
- item = this.menu.addAction('UTC', Lang.bind(this, function() { this.set_tz (0, 0, 'UTC'); }));
- item = this.menu.addAction('Adelaide', Lang.bind(this, function() { this.set_tz (10, 30, 'CDT'); }));
- item = this.menu.addAction('Perth', Lang.bind(this, function() { this.set_tz (8, 0, 'WST'); }));
+ item = this.menu.addAction('UTC', Lang.bind(this, function() { this.set_tz (0, 0, 'UTC', 'UTC'); }));
+ item = this.menu.addAction('Adelaide', Lang.bind(this, function() { this.set_tz (10, 30, 'CDT', 'Australia/Adelaide'); }));
+ item = this.menu.addAction('Perth', Lang.bind(this, function() { this.set_tz (8, 0, 'WST', 'Australia/Perth'); }));
this._clock = new GnomeDesktop.WallClock();
+
+ this._schema = Convenience.getSettings();
+ global.log (this._schema.get_string('tz'));
+
+ let tzid = this._schema.get_string('tz');
+ let tz = Timezones[tzid];
+ this.set_tz (tz.hr, tz.min, tz.tzname, tzid);
},
- set_tz: function (hour_offset, minute_offset, tzname) {
+ set_tz: function (hour_offset, minute_offset, tzname, fulltzname) {
this.hour_offset = hour_offset;
this.minute_offset = minute_offset;
this.tzname = tzname;
- this.update_time();
+ this.update_time();
+ this._schema.set_string('tz', fulltzname);
},
get_alternate_time_string: function() {
View
1  metadata.json
@@ -8,5 +8,6 @@
],
"url": "https://github.com/mibus/MultiClock",
"uuid": "MultiClock@mibus.org",
+ "settings-schema": "org.gnome.shell.extensions.mibusMultiClock",
"version": 2
}
View
BIN  schemas/gschemas.compiled
Binary file not shown
View
13 schemas/org.gnome.shell.extensions.mibusMultiClock.gschema.xml
@@ -0,0 +1,13 @@
+<schemalist>
+ <enum id="org.gnome.shell.extensions.mibusMultiClock.tzs">
+ <value value="1" nick="UTC" />
+ <value value="2" nick="Australia/Adelaide" />
+ <value value="3" nick="Australia/Perth" />
+ </enum>
+ <schema id="org.gnome.shell.extensions.mibusMultiClock" path="/org/gnome/shell/extensions/mibusMultiClock/">
+ <key name="tz" enum="org.gnome.shell.extensions.mibusMultiClock.tzs">
+ <default>'UTC'</default>
+ <summary>Select a secondary timezone</summary>
+ </key>
+ </schema>
+</schemalist>
Please sign in to comment.
Something went wrong with that request. Please try again.