From 266a0fb7d64b8d082407c6966cbb9dd03def1233 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20M=C3=BCllner?= Date: Fri, 26 Feb 2010 01:03:06 +0100 Subject: [PATCH] Add a simple preference dialog for the clock Port the 'General' preferences tab of the panel's clock applet to javascript and add it to the build system. https://bugzilla.gnome.org/show_bug.cgi?id=600276 --- .gitignore | 3 + configure.ac | 3 + data/Makefile.am | 18 +- data/clock-preferences.ui | 184 ++++++++++++++++++ ...nome-shell-clock-preferences.desktop.in.in | 15 ++ js/Makefile.am | 2 +- js/prefs/Makefile.am | 4 + js/prefs/clockPreferences.js | 91 +++++++++ src/Makefile.am | 9 +- src/gnome-shell-clock-preferences.in | 18 ++ 10 files changed, 338 insertions(+), 9 deletions(-) create mode 100644 data/clock-preferences.ui create mode 100644 data/gnome-shell-clock-preferences.desktop.in.in create mode 100644 js/prefs/Makefile.am create mode 100644 js/prefs/clockPreferences.js create mode 100644 src/gnome-shell-clock-preferences.in diff --git a/.gitignore b/.gitignore index 527a7361d..ed0ebf3a9 100644 --- a/.gitignore +++ b/.gitignore @@ -18,6 +18,8 @@ config configure data/gnome-shell.desktop data/gnome-shell.desktop.in +data/gnome-shell-clock-preferences.desktop +data/gnome-shell-clock-preferences.desktop.in intltool-extract.in intltool-merge.in intltool-update.in @@ -38,6 +40,7 @@ src/Makefile src/Makefile.in src/gnomeshell-taskpanel src/gnome-shell +src/gnome-shell-clock-preferences src/test-recorder src/test-recorder.ogg src/test-theme diff --git a/configure.ac b/configure.ac index 0df8df287..b1c9613d8 100644 --- a/configure.ac +++ b/configure.ac @@ -96,8 +96,10 @@ AC_SUBST(MUTTER_PLUGIN_DIR) GJS_JS_DIR=`$PKG_CONFIG --variable=jsdir gjs-1.0` GJS_JS_NATIVE_DIR=`$PKG_CONFIG --variable=jsnativedir gjs-1.0` +GJS_CONSOLE=`$PKG_CONFIG --variable=gjs_console gjs-1.0` AC_SUBST(GJS_JS_DIR) AC_SUBST(GJS_JS_NATIVE_DIR) +AC_SUBST(GJS_CONSOLE) AC_CHECK_FUNCS(fdwalk) AC_CHECK_HEADERS([sys/resource.h]) @@ -151,6 +153,7 @@ AC_CONFIG_FILES([ js/Makefile js/misc/Makefile js/ui/Makefile + js/prefs/Makefile src/Makefile tests/Makefile po/Makefile.in diff --git a/data/Makefile.am b/data/Makefile.am index 43ec39dc4..d3f57b05e 100644 --- a/data/Makefile.am +++ b/data/Makefile.am @@ -1,17 +1,19 @@ desktopdir=$(datadir)/applications -desktop_DATA = gnome-shell.desktop +desktop_DATA = gnome-shell.desktop gnome-shell-clock-preferences.desktop # We substitute in bindir so it works as an autostart # file when built in a non-system prefix -gnome-shell.desktop.in: gnome-shell.desktop.in.in +%.desktop.in:%.desktop.in.in $(AM_V_GEN) sed -e "s|@bindir[@]|$(bindir)|" \ -e "s|@VERSION[@]|$(VERSION)|" \ $< > $@ || rm $@ # Placeholder until we add intltool -gnome-shell.desktop: gnome-shell.desktop.in +%.desktop:%.desktop.in $(AM_V_GEN) sed s/^_// < $< > $@ || rm $@ +pkgdata_DATA = clock-preferences.ui + imagesdir = $(pkgdatadir)/images dist_images_DATA = \ close-black.svg \ @@ -50,11 +52,13 @@ schema_DATA = gnome-shell.schemas install-data-local: GCONF_CONFIG_SOURCE=$(GCONF_SCHEMA_CONFIG_SOURCE) $(GCONFTOOL) --makefile-install-rule $(srcdir)/$(schema_DATA) -EXTRA_DIST = \ - gnome-shell.desktop.in.in \ +EXTRA_DIST = \ + gnome-shell.desktop.in.in \ + gnome-shell-clock-preferences.desktop.in.in \ $(schema_DATA) -CLEANFILES = \ - gnome-shell.desktop.in \ +CLEANFILES = \ + gnome-shell.desktop.in \ + gnome-shell-clock-preferences.desktop.in \ $(desktop_DATA) diff --git a/data/clock-preferences.ui b/data/clock-preferences.ui new file mode 100644 index 000000000..ba713602f --- /dev/null +++ b/data/clock-preferences.ui @@ -0,0 +1,184 @@ + + + + + + 5 + Clock Preferences + center + normal + False + + + True + vertical + 2 + + + True + vertical + 18 + + + True + 0 + none + + + True + 6 + 12 + 6 + + + True + 12 + + + _12 hour format + True + True + False + True + True + + + False + False + 0 + + + + + _24 hour format + True + True + False + True + True + 12hr_radio + + + False + False + 1 + + + + + + + + + True + <b>Clock Format</b> + True + + + + + False + False + 0 + + + + + True + 0 + none + + + True + 6 + 12 + + + True + vertical + 6 + + + Show the _date + True + True + False + True + True + + + 0 + + + + + Show seco_nds + True + True + False + True + True + + + 1 + + + + + + + + + True + <b>Panel Display</b> + True + + + + + False + False + 1 + + + + + 6 + 1 + + + + + True + end + + + + + + gtk-close + True + True + True + True + + + False + False + 1 + + + + + False + end + 0 + + + + + + prefs_close_button + + + diff --git a/data/gnome-shell-clock-preferences.desktop.in.in b/data/gnome-shell-clock-preferences.desktop.in.in new file mode 100644 index 000000000..5886dd509 --- /dev/null +++ b/data/gnome-shell-clock-preferences.desktop.in.in @@ -0,0 +1,15 @@ +[Desktop Entry] +_Name=Clock +_Comment=Customize the panel clock +Exec=@bindir@/gnome-shell-clock-preferences +Icon=gnome-panel-clock +Terminal=false +Type=Application +StartupNotify=true +Categories=GNOME;GTK;Settings;DesktopSettings; +OnlyShowIn=GNOME; +X-GNOME-ShellOnly=true +X-GNOME-Bugzilla-Bugzilla=GNOME +X-GNOME-Bugzilla-Product=gnome-shell +X-GNOME-Bugzilla-Component=general +X-GNOME-Bugzilla-Version=@VERSION@ diff --git a/js/Makefile.am b/js/Makefile.am index 43d6f51cb..ab54b60ab 100644 --- a/js/Makefile.am +++ b/js/Makefile.am @@ -1 +1 @@ -SUBDIRS = misc ui +SUBDIRS = misc ui prefs diff --git a/js/prefs/Makefile.am b/js/prefs/Makefile.am new file mode 100644 index 000000000..a1e0c47ff --- /dev/null +++ b/js/prefs/Makefile.am @@ -0,0 +1,4 @@ +jsprefsdir = $(pkgdatadir)/js/prefs + +dist_jsprefs_DATA = \ + clockPreferences.js diff --git a/js/prefs/clockPreferences.js b/js/prefs/clockPreferences.js new file mode 100644 index 000000000..44bffea70 --- /dev/null +++ b/js/prefs/clockPreferences.js @@ -0,0 +1,91 @@ +const GLib = imports.gi.GLib; +const Gtk = imports.gi.Gtk; +const GConf = imports.gi.GConf; + +const Lang = imports.lang; +const Signals = imports.signals; + +const GCONF_DIR = '/desktop/gnome/shell/clock'; +const FORMAT_KEY = GCONF_DIR + '/format'; +const SHOW_DATE_KEY = GCONF_DIR + '/show_date'; +const SHOW_SECONDS_KEY = GCONF_DIR + '/show_seconds'; + + +function ClockPreferences(uiFile) { + this._init(uiFile); +}; + +ClockPreferences.prototype = { + _init: function(uiFile) { + let builder = new Gtk.Builder(); + builder.add_from_file(uiFile); + + this._dialog = builder.get_object('prefs-dialog'); + this._dialog.connect('response', Lang.bind(this, this._onResponse)); + + this._12hrRadio = builder.get_object('12hr_radio'); + this._24hrRadio = builder.get_object('24hr_radio'); + this._dateCheck = builder.get_object('date_check'); + this._secondsCheck = builder.get_object('seconds_check'); + + delete builder; + + this._gconf = GConf.Client.get_default(); + this._gconf.add_dir(GCONF_DIR, GConf.ClientPreloadType.PRELOAD_NONE); + this._notifyId = this._gconf.notify_add(GCONF_DIR, + Lang.bind(this, + this._updateDialog)); + + this._12hrRadio.connect('toggled', Lang.bind(this, + function() { + let format = this._12hrRadio.active ? '12-hour' : '24-hour'; + this._gconf.set_string(FORMAT_KEY, format); + })); + this._dateCheck.connect('toggled', Lang.bind(this, + function() { + this._gconf.set_bool(SHOW_DATE_KEY, this._dateCheck.active); + })); + this._secondsCheck.connect('toggled', Lang.bind(this, + function() { + this._gconf.set_bool(SHOW_SECONDS_KEY, + this._secondsCheck.active); + })); + + this._updateDialog(); + }, + + show: function() { + this._dialog.show_all(); + }, + + _updateDialog: function() { + let format = this._gconf.get_string(FORMAT_KEY); + this._12hrRadio.active = (format == "12-hour"); + this._24hrRadio.active = (format == "24-hour"); + + this._dateCheck.active = this._gconf.get_bool(SHOW_DATE_KEY); + this._secondsCheck.active = this._gconf.get_bool(SHOW_SECONDS_KEY); + }, + + _onResponse: function() { + this._dialog.destroy(); + this._gconf.notify_remove(this._notifyId); + this.emit('destroy'); + } +}; +Signals.addSignalMethods(ClockPreferences.prototype); + +function main(params) { + if ('progName' in params) + GLib.set_prgname(params['progName']); + Gtk.init(null, null); + + let clockPrefs = new ClockPreferences(params['uiFile']); + clockPrefs.connect('destroy', + function() { + Gtk.main_quit(); + }); + clockPrefs.show(); + + Gtk.main(); +} diff --git a/src/Makefile.am b/src/Makefile.am index 31808c8c7..a78d10ef7 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -8,7 +8,7 @@ noinst_PROGRAMS = .AUTOPARALLEL: -bin_SCRIPTS = gnome-shell +bin_SCRIPTS = gnome-shell gnome-shell-clock-preferences gnome-shell: gnome-shell.in $(AM_V_GEN) sed -e "s|@MUTTER_BIN_DIR[@]|$(MUTTER_BIN_DIR)|" \ @@ -24,6 +24,13 @@ gnome-shell: gnome-shell.in CLEANFILES += gnome-shell EXTRA_DIST += gnome-shell.in +gnome-shell-clock-preferences: gnome-shell-clock-preferences.in + $(AM_V_GEN) sed -e "s|@pkgdatadir[@]|$(pkgdatadir)|" \ + -e "s|@GJS_CONSOLE[@]|$(GJS_CONSOLE)|" \ + $< > $@ && chmod a+x $@ +CLEANFILES += gnome-shell-clock-preferences +EXTRA_DIST += gnome-shell-clock-preferences.in + include Makefile-gdmuser.am include Makefile-st.am include Makefile-tray.am diff --git a/src/gnome-shell-clock-preferences.in b/src/gnome-shell-clock-preferences.in new file mode 100644 index 000000000..419d0085d --- /dev/null +++ b/src/gnome-shell-clock-preferences.in @@ -0,0 +1,18 @@ +#!/bin/sh + +if [ -f "$0.in" ] +then + scriptDir="`dirname $0`" + uiDir="$scriptDir/../data" + jsDir="$scriptDir/../js" +else + uiDir="@pkgdatadir@" + jsDir="@pkgdatadir@/js" +fi + +progName="`basename $0`" +uiFile="$uiDir/clock-preferences.ui" +export GJS_PATH="$jsDir" + +@GJS_CONSOLE@ -c "const ClockPreferences = imports.prefs.clockPreferences; +ClockPreferences.main({ progName: '$progName', uiFile: '$uiFile' });"