[gnome-shell] Add a simple preference dialog for the clock



commit 266a0fb7d64b8d082407c6966cbb9dd03def1233
Author: Florian Müllner <fmuellner src gnome org>
Date:   Fri Feb 26 01:03:06 2010 +0100

    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 ++++++++++++++++++++++
 data/gnome-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(-)
---
diff --git a/.gitignore b/.gitignore
index 527a736..ed0ebf3 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 0df8df2..b1c9613 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 43ec39d..d3f57b0 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 0000000..ba71360
--- /dev/null
+++ b/data/clock-preferences.ui
@@ -0,0 +1,184 @@
+<?xml version="1.0"?>
+<interface>
+  <requires lib="gtk+" version="2.16"/>
+  <!-- interface-naming-policy project-wide -->
+  <object class="GtkDialog" id="prefs-dialog">
+    <property name="border_width">5</property>
+    <property name="title" translatable="yes">Clock Preferences</property>
+    <property name="window_position">center</property>
+    <property name="type_hint">normal</property>
+    <property name="has_separator">False</property>
+    <child internal-child="vbox">
+      <object class="GtkVBox" id="dialog-vbox1">
+        <property name="visible">True</property>
+        <property name="orientation">vertical</property>
+        <property name="spacing">2</property>
+        <child>
+          <object class="GtkVBox" id="vbox1">
+            <property name="visible">True</property>
+            <property name="orientation">vertical</property>
+            <property name="spacing">18</property>
+            <child>
+              <object class="GtkFrame" id="frame1">
+                <property name="visible">True</property>
+                <property name="label_xalign">0</property>
+                <property name="shadow_type">none</property>
+                <child>
+                  <object class="GtkAlignment" id="alignment1">
+                    <property name="visible">True</property>
+                    <property name="top_padding">6</property>
+                    <property name="left_padding">12</property>
+                    <property name="right_padding">6</property>
+                    <child>
+                      <object class="GtkHBox" id="hbox1">
+                        <property name="visible">True</property>
+                        <property name="spacing">12</property>
+                        <child>
+                          <object class="GtkRadioButton" id="12hr_radio">
+                            <property name="label" translatable="yes">_12 hour format</property>
+                            <property name="visible">True</property>
+                            <property name="can_focus">True</property>
+                            <property name="receives_default">False</property>
+                            <property name="use_underline">True</property>
+                            <property name="draw_indicator">True</property>
+                          </object>
+                          <packing>
+                            <property name="expand">False</property>
+                            <property name="fill">False</property>
+                            <property name="position">0</property>
+                          </packing>
+                        </child>
+                        <child>
+                          <object class="GtkRadioButton" id="24hr_radio">
+                            <property name="label" translatable="yes">_24 hour format</property>
+                            <property name="visible">True</property>
+                            <property name="can_focus">True</property>
+                            <property name="receives_default">False</property>
+                            <property name="use_underline">True</property>
+                            <property name="draw_indicator">True</property>
+                            <property name="group">12hr_radio</property>
+                          </object>
+                          <packing>
+                            <property name="expand">False</property>
+                            <property name="fill">False</property>
+                            <property name="position">1</property>
+                          </packing>
+                        </child>
+                      </object>
+                    </child>
+                  </object>
+                </child>
+                <child type="label">
+                  <object class="GtkLabel" id="label_format">
+                    <property name="visible">True</property>
+                    <property name="label" translatable="yes">&lt;b&gt;Clock Format&lt;/b&gt;</property>
+                    <property name="use_markup">True</property>
+                  </object>
+                </child>
+              </object>
+              <packing>
+                <property name="expand">False</property>
+                <property name="fill">False</property>
+                <property name="position">0</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkFrame" id="frame2">
+                <property name="visible">True</property>
+                <property name="label_xalign">0</property>
+                <property name="shadow_type">none</property>
+                <child>
+                  <object class="GtkAlignment" id="alignment2">
+                    <property name="visible">True</property>
+                    <property name="top_padding">6</property>
+                    <property name="left_padding">12</property>
+                    <child>
+                      <object class="GtkVBox" id="vbox2">
+                        <property name="visible">True</property>
+                        <property name="orientation">vertical</property>
+                        <property name="spacing">6</property>
+                        <child>
+                          <object class="GtkCheckButton" id="date_check">
+                            <property name="label" translatable="yes">Show the _date</property>
+                            <property name="visible">True</property>
+                            <property name="can_focus">True</property>
+                            <property name="receives_default">False</property>
+                            <property name="use_underline">True</property>
+                            <property name="draw_indicator">True</property>
+                          </object>
+                          <packing>
+                            <property name="position">0</property>
+                          </packing>
+                        </child>
+                        <child>
+                          <object class="GtkCheckButton" id="seconds_check">
+                            <property name="label" translatable="yes">Show seco_nds</property>
+                            <property name="visible">True</property>
+                            <property name="can_focus">True</property>
+                            <property name="receives_default">False</property>
+                            <property name="use_underline">True</property>
+                            <property name="draw_indicator">True</property>
+                          </object>
+                          <packing>
+                            <property name="position">1</property>
+                          </packing>
+                        </child>
+                      </object>
+                    </child>
+                  </object>
+                </child>
+                <child type="label">
+                  <object class="GtkLabel" id="label_display">
+                    <property name="visible">True</property>
+                    <property name="label" translatable="yes">&lt;b&gt;Panel Display&lt;/b&gt;</property>
+                    <property name="use_markup">True</property>
+                  </object>
+                </child>
+              </object>
+              <packing>
+                <property name="expand">False</property>
+                <property name="fill">False</property>
+                <property name="position">1</property>
+              </packing>
+            </child>
+          </object>
+          <packing>
+            <property name="padding">6</property>
+            <property name="position">1</property>
+          </packing>
+        </child>
+        <child internal-child="action_area">
+          <object class="GtkHButtonBox" id="dialog-action_area1">
+            <property name="visible">True</property>
+            <property name="layout_style">end</property>
+            <child>
+              <placeholder/>
+            </child>
+            <child>
+              <object class="GtkButton" id="prefs_close_button">
+                <property name="label">gtk-close</property>
+                <property name="visible">True</property>
+                <property name="can_focus">True</property>
+                <property name="receives_default">True</property>
+                <property name="use_stock">True</property>
+              </object>
+              <packing>
+                <property name="expand">False</property>
+                <property name="fill">False</property>
+                <property name="position">1</property>
+              </packing>
+            </child>
+          </object>
+          <packing>
+            <property name="expand">False</property>
+            <property name="pack_type">end</property>
+            <property name="position">0</property>
+          </packing>
+        </child>
+      </object>
+    </child>
+    <action-widgets>
+      <action-widget response="0">prefs_close_button</action-widget>
+    </action-widgets>
+  </object>
+</interface>
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 0000000..5886dd5
--- /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 43d6f51..ab54b60 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 0000000..a1e0c47
--- /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 0000000..44bffea
--- /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 31808c8..a78d10e 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 0000000..419d008
--- /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' });"



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]