From 1bccf4db4e6c983fd00538b3c1a0804b96dbe305 Mon Sep 17 00:00:00 2001 From: Jens Lody Date: Sat, 22 Feb 2014 00:34:43 +0100 Subject: [PATCH] Make x-position of notification configurable, add translation files , make po/update.js able to fetch translatable strings from xml(glade in this case) files. --- Makefile.am | 7 +- configure.ac | 13 + data/Makefile.am | 11 +- ....shell.extensions.panel-osd.gschema.xml.in | 8 + data/panel-osd-settings.ui | 77 ++++++ gnome-shell-extension-panel-osd.cbp | 9 + m4/.gitignore | 1 + po/LINGUAS | 1 + po/Makefile.in | 222 ++++++++++++++++++ po/POTFILES.in | 3 + po/de.po | 8 + po/gnome-shell-extension-panel-osd.pot | 22 ++ po/update.js | 54 +++++ src/Makefile.am | 2 +- src/convenience.js | 92 ++++++++ src/extension.js | 31 ++- src/prefs.js | 88 +++++++ 17 files changed, 643 insertions(+), 6 deletions(-) create mode 100644 data/org.gnome.shell.extensions.panel-osd.gschema.xml.in create mode 100644 data/panel-osd-settings.ui create mode 100644 m4/.gitignore create mode 100644 po/LINGUAS create mode 100644 po/Makefile.in create mode 100644 po/POTFILES.in create mode 100644 po/de.po create mode 100644 po/gnome-shell-extension-panel-osd.pot create mode 100644 po/update.js create mode 100644 src/convenience.js create mode 100644 src/prefs.js diff --git a/Makefile.am b/Makefile.am index 23d2aab..d12075b 100644 --- a/Makefile.am +++ b/Makefile.am @@ -1,6 +1,6 @@ ACLOCAL_AMFLAGS = -I m4 ${ACLOCAL_FLAGS} -SUBDIRS = src data +SUBDIRS = src data po uuid = panel-osd@berend.de.schouwer.gmail.com @@ -13,6 +13,11 @@ zip-file: all $(MKDIR_P) $(builddir)/zip-file; \ $(MAKE) install DESTDIR="$(abs_builddir)/_build"; \ cp -r "$(builddir)/_build$(datadir)/gnome-shell/extensions/$(uuid)" "$(builddir)/_build"; \ + if [ -f "$(builddir)/_build$(datadir)/glib-2.0/schemas/org.gnome.shell.extensions.panel-osd.gschema.xml" ]; then \ + $(MKDIR_P) "$(builddir)/_build/$(uuid)/schemas"; \ + mv "$(builddir)/_build$(datadir)/glib-2.0/schemas/org.gnome.shell.extensions.panel-osd.gschema.xml" "$(builddir)/_build/$(uuid)/schemas"; \ + glib-compile-schemas "$(builddir)/_build/$(uuid)/schemas"; \ + fi; \ cp -r "$(builddir)/_build$(datadir)/locale" "$(builddir)/_build/$(uuid)"; \ (cd "$(builddir)/_build/$(uuid)/"; \ zip -qr "$(abs_builddir)/zip-file/panel-osd.shell-extension.zip" .; \ diff --git a/configure.ac b/configure.ac index dc665ec..e20f0a9 100644 --- a/configure.ac +++ b/configure.ac @@ -2,6 +2,7 @@ AC_PREREQ(2.63) dnl be carefull, the version needs to be in sync with your gnome shell version AC_INIT([gnome-shell-extension-panel-osd],[1.1],[https://github.com/jenslody/gnome-shell-extension-panel-osd/issues]) +AC_CONFIG_MACRO_DIR([m4]) AC_CONFIG_AUX_DIR([config]) AM_INIT_AUTOMAKE([1.10 dist-xz foreign]) @@ -10,6 +11,11 @@ m4_ifdef([AM_SILENT_RULES],[AM_SILENT_RULES([yes])]) AC_PROG_SED +GETTEXT_PACKAGE=gnome-shell-extension-panel-osd +AC_SUBST(GETTEXT_PACKAGE) +AC_DEFINE_UNQUOTED(GETTEXT_PACKAGE, "$GETTEXT_PACKAGE", + [The prefix for our gettext translation domains.]) +IT_PROG_INTLTOOL(0.26) PKG_PROG_PKG_CONFIG([0.22]) GLIB_GSETTINGS @@ -38,6 +44,7 @@ extensiontopdir=${datadir}/gnome-shell/extensions/panel-osd-extension@jenslody.d dnl This is beyond ugly. Suggestions accepted. if test "x${use_local_install}" == "xyes"; then + AC_SUBST(gsettingsschemadir, [${extensiontopdir}/schemas]) AC_SUBST(LOCALEDIR, [${extensiontopdir}/locale]) else AC_SUBST(LOCALEDIR, [${datadir}/locale]) @@ -47,10 +54,16 @@ dnl Please keep this sorted alphabetically. AC_CONFIG_FILES([ Makefile data/Makefile + po/Makefile.in src/Makefile ]) AC_OUTPUT +dnl 'Fugly hack' doesn't get close to describe this. I don't know how else +dnl to change the directory for translations. +if test "x${use_local_install}" == "xyes"; then + ${SED} -i -e "s%itlocaledir = .*%itlocaledir = ${extensiontopdir}/locale%g" po/Makefile +fi if test "x$use_local_install" == "xyes"; then echo echo "The extension will be installed locally in the userdatadir." diff --git a/data/Makefile.am b/data/Makefile.am index d615f12..2676994 100644 --- a/data/Makefile.am +++ b/data/Makefile.am @@ -7,7 +7,7 @@ uuid = panel-osd@berend.de.schouwer.gmail.com extensiondir = $(topextensiondir)/$(uuid) -dist_extension_DATA = stylesheet.css +dist_extension_DATA = stylesheet.css panel-osd-settings.ui nodist_extension_DATA = metadata.json $(EXTRA_EXTENSION) @@ -19,3 +19,12 @@ metadata.json: metadata.json.in $(top_builddir)/config.status -e "s|[@]url@|$(extensionurl)|" $< > $@ CLEANFILES = metadata.json + +gschemas_in = org.gnome.shell.extensions.panel-osd.gschema.xml.in + +@INTLTOOL_XML_NOMERGE_RULE@ + +gsettings_SCHEMAS = $(gschemas_in:.xml.in=.xml) @GSETTINGS_RULES@ + +EXTRA_DIST += $(gschemas_in) +CLEANFILES += $(gschemas_in:.xml.in=.valid) $(gsettings_SCHEMAS) diff --git a/data/org.gnome.shell.extensions.panel-osd.gschema.xml.in b/data/org.gnome.shell.extensions.panel-osd.gschema.xml.in new file mode 100644 index 0000000..01e49e4 --- /dev/null +++ b/data/org.gnome.shell.extensions.panel-osd.gschema.xml.in @@ -0,0 +1,8 @@ + + + + 50.0 + <_summary>Horizontal position of notification. + + + diff --git a/data/panel-osd-settings.ui b/data/panel-osd-settings.ui new file mode 100644 index 0000000..3a21162 --- /dev/null +++ b/data/panel-osd-settings.ui @@ -0,0 +1,77 @@ + + + + + + 100 + 0.10000000000000001 + 2 + + + False + 5 + 14 + vertical + + + True + False + True + 0 + Horizontal position [%] from 0% (left) to 100% (right) + start + False + + + False + True + 0 + + + + + True + True + True + x-adjustment + True + False + 100 + + + True + False + 1 + + + + + True + False + 5 + 5 + 10 + 10 + + + False + True + 2 + + + + + Reset to defaults + True + True + True + end + + + False + True + 3 + + + + diff --git a/gnome-shell-extension-panel-osd.cbp b/gnome-shell-extension-panel-osd.cbp index 59994ae..b68503f 100644 --- a/gnome-shell-extension-panel-osd.cbp +++ b/gnome-shell-extension-panel-osd.cbp @@ -31,10 +31,19 @@ + + + + + + + + + diff --git a/m4/.gitignore b/m4/.gitignore new file mode 100644 index 0000000..9f841b0 --- /dev/null +++ b/m4/.gitignore @@ -0,0 +1 @@ +intltool.m4 diff --git a/po/LINGUAS b/po/LINGUAS new file mode 100644 index 0000000..c42e816 --- /dev/null +++ b/po/LINGUAS @@ -0,0 +1 @@ +de \ No newline at end of file diff --git a/po/Makefile.in b/po/Makefile.in new file mode 100644 index 0000000..996c26a --- /dev/null +++ b/po/Makefile.in @@ -0,0 +1,222 @@ +# Makefile for program source directory in GNU NLS utilities package. +# Copyright (C) 1995, 1996, 1997 by Ulrich Drepper +# Copyright (C) 2004-2008 Rodney Dawes +# +# This file may be copied and used freely without restrictions. It may +# be used in projects which are not available under a GNU Public License, +# but which still want to provide support for the GNU gettext functionality. +# +# - Modified by Owen Taylor to use GETTEXT_PACKAGE +# instead of PACKAGE and to look for po2tbl in ./ not in intl/ +# +# - Modified by jacob berkman to install +# Makefile.in.in and po2tbl.sed.in for use with glib-gettextize +# +# - Modified by Rodney Dawes for use with intltool +# +# We have the following line for use by intltoolize: +# INTLTOOL_MAKEFILE + +GETTEXT_PACKAGE = gnome-shell-extension-panel-osd +PACKAGE = gnome-shell-extension-panel-osd +VERSION = 1.1 + +SHELL = /bin/sh + +srcdir = . +top_srcdir = .. +top_builddir = .. + + +prefix = /usr/local +exec_prefix = ${prefix} +datadir = ${datarootdir} +datarootdir = ${prefix}/share +libdir = ${exec_prefix}/lib +DATADIRNAME = share +itlocaledir = $(prefix)/$(DATADIRNAME)/locale +subdir = po +install_sh = ${SHELL} /home/jens/sources/p/gnome-shell-extension-panel-osd/config/install-sh +# Automake >= 1.8 provides $(MKDIR_P). +# Until it can be supposed, use the safe fallback: +mkdir_p = $(install_sh) -d + +INSTALL = /usr/bin/install -c +INSTALL_DATA = ${INSTALL} -m 644 + +GMSGFMT = /usr/bin/msgfmt +MSGFMT = /usr/bin/msgfmt +XGETTEXT = /usr/bin/xgettext +INTLTOOL_UPDATE = /usr/bin/intltool-update +INTLTOOL_EXTRACT = /usr/bin/intltool-extract +MSGMERGE = INTLTOOL_EXTRACT="$(INTLTOOL_EXTRACT)" XGETTEXT="$(XGETTEXT)" srcdir=$(srcdir) $(INTLTOOL_UPDATE) --gettext-package $(GETTEXT_PACKAGE) --dist +GENPOT = INTLTOOL_EXTRACT="$(INTLTOOL_EXTRACT)" XGETTEXT="$(XGETTEXT)" srcdir=$(srcdir) $(INTLTOOL_UPDATE) --gettext-package $(GETTEXT_PACKAGE) --pot + +ALL_LINGUAS = + +PO_LINGUAS=$(shell if test -r $(srcdir)/LINGUAS; then grep -v "^\#" $(srcdir)/LINGUAS; else echo "$(ALL_LINGUAS)"; fi) + +USER_LINGUAS=$(shell if test -n "$(LINGUAS)"; then LLINGUAS="$(LINGUAS)"; ALINGUAS="$(ALL_LINGUAS)"; for lang in $$LLINGUAS; do if test -n "`grep \^$$lang$$ $(srcdir)/LINGUAS 2>/dev/null`" -o -n "`echo $$ALINGUAS|tr ' ' '\n'|grep \^$$lang$$`"; then printf "$$lang "; fi; done; fi) + +USE_LINGUAS=$(shell if test -n "$(USER_LINGUAS)" -o -n "$(LINGUAS)"; then LLINGUAS="$(USER_LINGUAS)"; else if test -n "$(PO_LINGUAS)"; then LLINGUAS="$(PO_LINGUAS)"; else LLINGUAS="$(ALL_LINGUAS)"; fi; fi; for lang in $$LLINGUAS; do printf "$$lang "; done) + +POFILES=$(shell LINGUAS="$(PO_LINGUAS)"; for lang in $$LINGUAS; do printf "$$lang.po "; done) + +DISTFILES = Makefile.in.in POTFILES.in $(POFILES) +EXTRA_DISTFILES = ChangeLog POTFILES.skip Makevars LINGUAS + +POTFILES = \ +# This comment gets stripped out + +CATALOGS=$(shell LINGUAS="$(USE_LINGUAS)"; for lang in $$LINGUAS; do printf "$$lang.gmo "; done) + +.SUFFIXES: +.SUFFIXES: .po .pox .gmo .mo .msg .cat + +AM_DEFAULT_VERBOSITY = 0 +INTLTOOL_V_MSGFMT = $(INTLTOOL__v_MSGFMT_$(V)) +INTLTOOL__v_MSGFMT_= $(INTLTOOL__v_MSGFMT_$(AM_DEFAULT_VERBOSITY)) +INTLTOOL__v_MSGFMT_0 = @echo " MSGFMT" $@; + +.po.pox: + $(MAKE) $(GETTEXT_PACKAGE).pot + $(MSGMERGE) $< $(GETTEXT_PACKAGE).pot -o $*.pox + +.po.mo: + $(INTLTOOL_V_MSGFMT)$(MSGFMT) -o $@ $< + +.po.gmo: + $(INTLTOOL_V_MSGFMT)file=`echo $* | sed 's,.*/,,'`.gmo \ + && rm -f $$file && $(GMSGFMT) -o $$file $< + +.po.cat: + sed -f ../intl/po2msg.sed < $< > $*.msg \ + && rm -f $@ && gencat $@ $*.msg + + +all: all-yes + +all-yes: $(CATALOGS) +all-no: + +$(GETTEXT_PACKAGE).pot: $(POTFILES) + $(GENPOT) + +install: install-data +install-data: install-data-yes +install-data-no: all +install-data-yes: all + linguas="$(USE_LINGUAS)"; \ + for lang in $$linguas; do \ + dir=$(DESTDIR)$(itlocaledir)/$$lang/LC_MESSAGES; \ + $(mkdir_p) $$dir; \ + if test -r $$lang.gmo; then \ + $(INSTALL_DATA) $$lang.gmo $$dir/$(GETTEXT_PACKAGE).mo; \ + echo "installing $$lang.gmo as $$dir/$(GETTEXT_PACKAGE).mo"; \ + else \ + $(INSTALL_DATA) $(srcdir)/$$lang.gmo $$dir/$(GETTEXT_PACKAGE).mo; \ + echo "installing $(srcdir)/$$lang.gmo as" \ + "$$dir/$(GETTEXT_PACKAGE).mo"; \ + fi; \ + if test -r $$lang.gmo.m; then \ + $(INSTALL_DATA) $$lang.gmo.m $$dir/$(GETTEXT_PACKAGE).mo.m; \ + echo "installing $$lang.gmo.m as $$dir/$(GETTEXT_PACKAGE).mo.m"; \ + else \ + if test -r $(srcdir)/$$lang.gmo.m ; then \ + $(INSTALL_DATA) $(srcdir)/$$lang.gmo.m \ + $$dir/$(GETTEXT_PACKAGE).mo.m; \ + echo "installing $(srcdir)/$$lang.gmo.m as" \ + "$$dir/$(GETTEXT_PACKAGE).mo.m"; \ + else \ + true; \ + fi; \ + fi; \ + done + +# Empty stubs to satisfy archaic automake needs +dvi info ctags tags CTAGS TAGS ID: + +# Define this as empty until I found a useful application. +install-exec installcheck: + +uninstall: + linguas="$(USE_LINGUAS)"; \ + for lang in $$linguas; do \ + rm -f $(DESTDIR)$(itlocaledir)/$$lang/LC_MESSAGES/$(GETTEXT_PACKAGE).mo; \ + rm -f $(DESTDIR)$(itlocaledir)/$$lang/LC_MESSAGES/$(GETTEXT_PACKAGE).mo.m; \ + done + +check: all $(GETTEXT_PACKAGE).pot + rm -f missing notexist + srcdir=$(srcdir) $(INTLTOOL_UPDATE) -m + if [ -r missing -o -r notexist ]; then \ + exit 1; \ + fi + +mostlyclean: + rm -f *.pox $(GETTEXT_PACKAGE).pot *.old.po cat-id-tbl.tmp + rm -f .intltool-merge-cache + +clean: mostlyclean + +distclean: clean + rm -f Makefile Makefile.in POTFILES stamp-it + rm -f *.mo *.msg *.cat *.cat.m *.gmo + +maintainer-clean: distclean + @echo "This command is intended for maintainers to use;" + @echo "it deletes files that may require special tools to rebuild." + rm -f Makefile.in.in + +distdir = ../$(PACKAGE)-$(VERSION)/$(subdir) +dist distdir: $(DISTFILES) + dists="$(DISTFILES)"; \ + extra_dists="$(EXTRA_DISTFILES)"; \ + for file in $$extra_dists; do \ + test -f $(srcdir)/$$file && dists="$$dists $(srcdir)/$$file"; \ + done; \ + for file in $$dists; do \ + test -f $$file || file="$(srcdir)/$$file"; \ + ln $$file $(distdir) 2> /dev/null \ + || cp -p $$file $(distdir); \ + done + +update-po: Makefile + $(MAKE) $(GETTEXT_PACKAGE).pot + tmpdir=`pwd`; \ + linguas="$(USE_LINGUAS)"; \ + for lang in $$linguas; do \ + echo "$$lang:"; \ + result="`$(MSGMERGE) -o $$tmpdir/$$lang.new.po $$lang`"; \ + if $$result; then \ + if cmp $(srcdir)/$$lang.po $$tmpdir/$$lang.new.po >/dev/null 2>&1; then \ + rm -f $$tmpdir/$$lang.new.po; \ + else \ + if mv -f $$tmpdir/$$lang.new.po $$lang.po; then \ + :; \ + else \ + echo "msgmerge for $$lang.po failed: cannot move $$tmpdir/$$lang.new.po to $$lang.po" 1>&2; \ + rm -f $$tmpdir/$$lang.new.po; \ + exit 1; \ + fi; \ + fi; \ + else \ + echo "msgmerge for $$lang.gmo failed!"; \ + rm -f $$tmpdir/$$lang.new.po; \ + fi; \ + done + +Makefile POTFILES: stamp-it + @if test ! -f $@; then \ + rm -f stamp-it; \ + $(MAKE) stamp-it; \ + fi + +stamp-it: Makefile.in.in $(top_builddir)/config.status POTFILES.in + cd $(top_builddir) \ + && CONFIG_FILES=$(subdir)/Makefile.in CONFIG_HEADERS= CONFIG_LINKS= \ + $(SHELL) ./config.status + +# Tell versions [3.59,3.63) of GNU make not to export all variables. +# Otherwise a system limit (for SysV at least) may be exceeded. +.NOEXPORT: diff --git a/po/POTFILES.in b/po/POTFILES.in new file mode 100644 index 0000000..90194d4 --- /dev/null +++ b/po/POTFILES.in @@ -0,0 +1,3 @@ +../src/extension.js +../src/prefs.js +../data/panel-osd-settings.ui diff --git a/po/de.po b/po/de.po new file mode 100644 index 0000000..fa3f03e --- /dev/null +++ b/po/de.po @@ -0,0 +1,8 @@ +#: ../data/panel-osd-settings.ui:21 +#, fuzzy +msgid "Horizontal position [%] from 0% (left) to 100% (right)" +msgstr "Horizontale Position [%] von links (0%) bis rechts (100%)" + +#: ../data/panel-osd-settings.ui:64 +msgid "Reset to defaults" +msgstr "Auf Standardwert zurücksetzen" diff --git a/po/gnome-shell-extension-panel-osd.pot b/po/gnome-shell-extension-panel-osd.pot new file mode 100644 index 0000000..7cdfefc --- /dev/null +++ b/po/gnome-shell-extension-panel-osd.pot @@ -0,0 +1,22 @@ +# SOME DESCRIPTIVE TITLE. +# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER +# This file is distributed under the same license as the PACKAGE package. +# FIRST AUTHOR , YEAR. +# +#, fuzzy +msgid "" +msgstr "" +"Project-Id-Version: PACKAGE VERSION\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2014-02-16 18:20+0100\n" +"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" +"Last-Translator: FULL NAME \n" +"Language-Team: LANGUAGE \n" +"Language: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=CHARSET\n" +"Content-Transfer-Encoding: 8bit\n" + +#: ../data/panel-osd-settings.ui:19 +msgid "Horizontal position [%] from left (0%) to right (100%)" +msgstr "" diff --git a/po/update.js b/po/update.js new file mode 100644 index 0000000..bcf02ae --- /dev/null +++ b/po/update.js @@ -0,0 +1,54 @@ +#!/usr/bin/env seed + +/* + * + * PO Updater for GNOME Shell Extension Panel OSD + * + * Copyright (C) 2012 + * Christian METZLER + * 2014 Jens Lody + * + * + * This file is part of gnome-shell-extension-panel-osd. + * + * gnome-shell-extension-panel-osd 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 3 of the License, or + * (at your option) any later version. + * + * gnome-shell-extension-panel-osd 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-shell-extension-panel-osd. If not, see . + * + */ + +Gio = imports.gi.Gio; + +print("Generate gnome-shell-extension-panel-osd.pot"); +var xgettext = Seed.spawn("xgettext -o gnome-shell-extension-panel-osd.pot --from-code=utf-8 --keyword=_ --keyword=translatable -f POTFILES.in"); + +if (xgettext.stderr) + print(xgettext.stderr); +else { + var file = Gio.file_new_for_path("."); + var enumerator = file.enumerate_children("standard::name,standard::size"); + var linguas = ""; + var n = ""; + var i = 0; + while (child = enumerator.next_file()) + if (child.get_name().search(/.po$/) != -1) { + print("Generate " + child.get_name()); + linguas += n + (child.get_name().split(".po")[0]); + Seed.spawn("msgmerge -U " + child.get_name() + " gnome-shell-extension-panel-osd.pot"); + n = "\n"; + i++; + } + + print("Write LINGUAS file"); + Gio.simple_write("LINGUAS", linguas); + print("Successfully generated " + i + " entry"); +} diff --git a/src/Makefile.am b/src/Makefile.am index ecdf629..507db76 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -5,6 +5,6 @@ uuid = panel-osd@berend.de.schouwer.gmail.com extensiondir = $(topextensiondir)/$(uuid) -dist_extension_DATA = extension.js +dist_extension_DATA = extension.js convenience.js prefs.js nodist_extension_DATA = $(EXTRA_EXTENSION) diff --git a/src/convenience.js b/src/convenience.js new file mode 100644 index 0000000..1fb9ede --- /dev/null +++ b/src/convenience.js @@ -0,0 +1,92 @@ +/* -*- mode: js -*- */ +/* + Copyright (c) 2011-2012, Giovanni Campagna + + 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 + }); +} diff --git a/src/extension.js b/src/extension.js index 0cca3f3..2293366 100644 --- a/src/extension.js +++ b/src/extension.js @@ -4,7 +4,7 @@ * We're grabbing "private" methods (start with _), so expect this to break * with different versions of Gnome Shell. * - * It was tested with 3.8.3, with various themes. + * It was tested with 3.6 to 3.11.90 with various themes. * * Most of this code is a direct copy from gnome-shell/js/ui/messageTray.js, * so (C)opyright Gnome-Team, I think :) @@ -18,6 +18,15 @@ const Main = imports.ui.main; const Tweener = imports.ui.tweener; const LayoutManager = Main.layoutManager; const Lang = imports.lang; +const Me = ExtensionUtils.getCurrentExtension(); +const Convenience = Me.imports.convenience; + +const EXTENSIONDIR = Me.dir.get_path(); + +const PANEL_OSD_SETTINGS_SCHEMA = 'org.gnome.shell.extensions.panel-osd'; +const PANEL_OSD_X_POS_KEY = 'x-pos'; + + /* * Save MessageTray's original methods. We're going to change these @@ -47,7 +56,7 @@ const Urgency = { NORMAL: 1, HIGH: 2, CRITICAL: 3 -} +}; const State = { HIDDEN: 0, SHOWING: 1, @@ -58,6 +67,18 @@ const State = { function init() { } +let Settings; + +let loadConfig = function() { + Settings = Convenience.getSettings(PANEL_OSD_SETTINGS_SCHEMA); +}; + +let getX_position = function() { + if (!Settings) + loadConfig(); + return Settings.get_double(PANEL_OSD_X_POS_KEY); +} + /* * Copied from MessageTray._showNotification() @@ -287,11 +308,13 @@ let extensionUpdateShowingNotification = function() { // use panel's y and height property to determine the bottom of the top-panel. // needed because the "hide top bar" and "hide top panel" use different approaches to hide the // top bar. - // "hide top panel" keeps the haeight and just moves the panel out of the visible area, so using + // "hide top panel" keeps the height and just moves the panel out of the visible area, so using // the panels-height is not enough. let yPos = panel.y + panel.height - global.screen_height; if (yPos < (-global.screen_height)) yPos = -global.screen_height; + // + this._notificationWidget.x = (global.screen_width - this._notificationWidget.width) * (getX_position() - 50) / 50 ; // JRL changes end // We tween all notifications to full opacity. This ensures that both new notifications and // notifications that might have been in the process of hiding get full opacity. @@ -369,6 +392,8 @@ function disable() { // remove our style, in case we just show a notification, otherwise the radius is drawn incorrect if(Main.messageTray._notification) Main.messageTray._notification._table.remove_style_class_name('jrlnotification'); + // reset x-position + notificationWidget.x = originalNotificationWidgetX; Main.messageTray._showNotification = originalShowNotification; Main.messageTray._hideNotification = originalHideNotification; Main.messageTray._updateShowingNotification = originalUpdateShowingNotification; diff --git a/src/prefs.js b/src/prefs.js new file mode 100644 index 0000000..6c0beb1 --- /dev/null +++ b/src/prefs.js @@ -0,0 +1,88 @@ +const Gtk = imports.gi.Gtk; +const GObject = imports.gi.GObject; +const GtkBuilder = Gtk.Builder; +const Lang = imports.lang; +const Mainloop = imports.mainloop; + +const Gettext = imports.gettext.domain('gnome-shell-extension-panel-osd'); +const _ = Gettext.gettext; + +const ExtensionUtils = imports.misc.extensionUtils; +const Me = ExtensionUtils.getCurrentExtension(); +const Convenience = Me.imports.convenience; + +const EXTENSIONDIR = Me.dir.get_path(); + +const PANEL_OSD_SETTINGS_SCHEMA = 'org.gnome.shell.extensions.panel-osd'; +const PANEL_OSD_X_POS_KEY = 'x-pos'; + +const PanelOsdPrefsWidget = new GObject.Class({ + Name: 'PanelOsdExtension.Prefs.Widget', + GTypeName: 'PanelOsdExtensionPrefsWidget', + Extends: Gtk.Box, + + _init: function(params) { + this.parent(params); + + this.initWindow(); + + this.add(this.MainWidget); + }, + + Window: new Gtk.Builder(), + + initWindow: function() { + this.Window.set_translation_domain('gnome-shell-extension-panel-osd'); + this.Window.add_from_file(EXTENSIONDIR + "/panel-osd-settings.ui"); + + this.MainWidget = this.Window.get_object("main-widget"); + + this.x_scale = this.Window.get_object("scale-x-pos"); + this.x_scale.set_value(this.x_position); + // prevent from continously updating the value + this.xScaleTimeout = undefined; + this.x_scale.connect("value-changed", Lang.bind(this, function(slider) { + + if (this.xScaleTimeout != undefined) + Mainloop.source_remove(this.xScaleTimeout); + this.xScaleTimeout = Mainloop.timeout_add(250, Lang.bind(this, function() { + this.x_position = slider.get_value(); + return false; + })); + + })); + + this.Window.get_object("button-reset").connect("clicked", Lang.bind(this, function() { + this.x_scale.set_value(50);; + })); + + + }, + + loadConfig: function() { + this.Settings = Convenience.getSettings(PANEL_OSD_SETTINGS_SCHEMA); + }, + + get x_position() { + if (!this.Settings) + this.loadConfig(); + return this.Settings.get_double(PANEL_OSD_X_POS_KEY); + }, + + set x_position(v) { + if (!this.Settings) + this.loadConfig(); + this.Settings.set_double(PANEL_OSD_X_POS_KEY, v); + } + +}); + +function init() { + Convenience.initTranslations('gnome-shell-extension-panel-osd'); +} + +function buildPrefsWidget() { + let widget = new PanelOsdPrefsWidget(); + widget.show_all(); + return widget; +}