From 376ad1fbc60bd9354d51d1a71efc449e018cc97b Mon Sep 17 00:00:00 2001 From: Jens Lody Date: Fri, 7 Mar 2014 19:25:42 +0100 Subject: [PATCH] Add option to always show notifications expandend;add possibility to show a test notification; remove unneeded imports. --- ....shell.extensions.panel-osd.gschema.xml.in | 16 +- data/panel-osd-settings.ui | 143 +++++++++++++++++- po/de.po | 32 +++- po/gnome-shell-extension-panel-osd.pot | 32 +++- src/extension.js | 82 ++++++++-- src/prefs.js | 69 +++++++++ 6 files changed, 347 insertions(+), 27 deletions(-) diff --git a/data/org.gnome.shell.extensions.panel-osd.gschema.xml.in b/data/org.gnome.shell.extensions.panel-osd.gschema.xml.in index d0061d2..82a3079 100644 --- a/data/org.gnome.shell.extensions.panel-osd.gschema.xml.in +++ b/data/org.gnome.shell.extensions.panel-osd.gschema.xml.in @@ -10,11 +10,23 @@ false - <_summary>Horizontal position of notification. + <_summary>Allow resetting horizontal position of notification. false - <_summary>Vertical position of notification. + <_summary>Allow resetting vertical position of notification. + + + false + <_summary>Always expand notifications. + + + 1.0 + <_summary>Delay before test notification is shown. + + + false + <_summary>If the value is true a test-notification is send and then set back to false. diff --git a/data/panel-osd-settings.ui b/data/panel-osd-settings.ui index 0d51403..b371d92 100644 --- a/data/panel-osd-settings.ui +++ b/data/panel-osd-settings.ui @@ -2,6 +2,13 @@ + + 0.5 + 20 + 1 + 0.10000000000000001 + 1 + 100 0.10000000000000001 @@ -223,11 +230,145 @@ True False + 10 + 10 + + + True + False + 7 + + + + + True + False + + + True + True + 10 + 10 + + + False + True + 0 + + + + + True + False + start + True + Force showing details for all notifications + + + False + True + 1 + + False True - 7 + 8 + + + + + True + False + 5 + 5 + 10 + 10 + + + True + False + 9 + + + + + True + False + vertical + + + True + False + True + 0 + 0 + Delay [s] before test-notification is shown. If it is too short, the notification might close immediately after it is shown. + True + False + + + False + True + 0 + + + + + 400 + True + True + True + delay-adjustment + True + False + 100 + + + True + False + 1 + + + + + Show test notification + True + True + True + end + center + 20 + True + True + + + False + True + 2 + + + + + False + True + 10 + + + + + True + False + 5 + 5 + 10 + 10 + + + True + False + 11 diff --git a/po/de.po b/po/de.po index 5cb9b51..ed01f7a 100644 --- a/po/de.po +++ b/po/de.po @@ -1,19 +1,41 @@ -#: ../data/panel-osd-settings.ui:26 +#: ../src/extension.js:85 +msgid "" +"This is just a multiline test-message to show where the notification will be " +"placed and to test expansion (showing details)." +msgstr "Dies ist nur eine einfache mehrzeilige Meldung um zu Zeigen, wo die" +"Meldung angezeigt wird, und um das Erweitern (Details) zu zeigen. " + +#: ../data/panel-osd-settings.ui:39 msgid "Horizontal position [%] from 0% (left) to 100% (right)" msgstr "Horizontale Position [%] von links (0%) bis rechts (100%)" -#: ../data/panel-osd-settings.ui:73 +#: ../data/panel-osd-settings.ui:86 msgid "Vertical position [%] from 0% (bottom) to 100% (top)" msgstr "Vertikale Position [%] von unten (0%) bis oben (100%)" -#: ../data/panel-osd-settings.ui:158 +#: ../data/panel-osd-settings.ui:174 msgid "Reset horizontal position to defaults" msgstr "Horizontale Position auf Standardwert zurücksetzen" -#: ../data/panel-osd-settings.ui:173 +#: ../data/panel-osd-settings.ui:189 msgid "Reset vertical position to defaults" msgstr "Vertikale Position auf Standardwert zurücksetzen" -#: ../data/panel-osd-settings.ui:191 +#: ../data/panel-osd-settings.ui:207 msgid "Reset" msgstr "Zurücksetzen" + +#: ../data/panel-osd-settings.ui:265 +msgid "Force showing details for all notifications" +msgstr "Zeige alle Meldungen erweitert" + +#: ../data/panel-osd-settings.ui:307 +msgid "" +"Delay [s] before test-notification is shown. If it is too short, the " +"notification might close immediately after it is shown." +msgstr "Verzögerung [s] before die Test-Meldung gezeigt wird. Ist die " +"Zeit zu kurz wird die Meldung sofort wieder geschlossen." + +#: ../data/panel-osd-settings.ui:336 +msgid "Show test notification" +msgstr "Zeige Test-Meldung" diff --git a/po/gnome-shell-extension-panel-osd.pot b/po/gnome-shell-extension-panel-osd.pot index dc0b351..39be9a9 100644 --- a/po/gnome-shell-extension-panel-osd.pot +++ b/po/gnome-shell-extension-panel-osd.pot @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2014-02-23 13:47+0100\n" +"POT-Creation-Date: 2014-03-07 18:36+0100\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -17,22 +17,42 @@ msgstr "" "Content-Type: text/plain; charset=CHARSET\n" "Content-Transfer-Encoding: 8bit\n" -#: ../data/panel-osd-settings.ui:26 +#: ../src/extension.js:85 +msgid "" +"This is just a multiline test-message to show where the notification will be " +"placed and to test expansion (showing details)." +msgstr "" + +#: ../data/panel-osd-settings.ui:39 msgid "Horizontal position [%] from 0% (left) to 100% (right)" msgstr "" -#: ../data/panel-osd-settings.ui:73 +#: ../data/panel-osd-settings.ui:86 msgid "Vertical position [%] from 0% (bottom) to 100% (top)" msgstr "" -#: ../data/panel-osd-settings.ui:158 +#: ../data/panel-osd-settings.ui:174 msgid "Reset horizontal position to defaults" msgstr "" -#: ../data/panel-osd-settings.ui:173 +#: ../data/panel-osd-settings.ui:189 msgid "Reset vertical position to defaults" msgstr "" -#: ../data/panel-osd-settings.ui:191 +#: ../data/panel-osd-settings.ui:207 msgid "Reset" msgstr "" + +#: ../data/panel-osd-settings.ui:265 +msgid "Force showing details for all notifications" +msgstr "" + +#: ../data/panel-osd-settings.ui:307 +msgid "" +"Delay [s] before test-notification is shown. If it is too short, the " +"notification might close immediately after it is shown." +msgstr "" + +#: ../data/panel-osd-settings.ui:336 +msgid "Show test notification" +msgstr "" diff --git a/src/extension.js b/src/extension.js index 9607b3e..9afb971 100644 --- a/src/extension.js +++ b/src/extension.js @@ -17,18 +17,20 @@ const ExtensionUtils = imports.misc.extensionUtils; const Config = imports.misc.config; const Main = imports.ui.main; const Tweener = imports.ui.tweener; -const LayoutManager = Main.layoutManager; const Lang = imports.lang; +const Mainloop = imports.mainloop; const Me = ExtensionUtils.getCurrentExtension(); const Convenience = Me.imports.convenience; -const EXTENSIONDIR = Me.dir.get_path(); +const Gettext = imports.gettext.domain('gnome-shell-extension-panel-osd'); +const _ = Gettext.gettext; const PANEL_OSD_SETTINGS_SCHEMA = 'org.gnome.shell.extensions.panel-osd'; const PANEL_OSD_X_POS_KEY = 'x-pos'; const PANEL_OSD_Y_POS_KEY = 'y-pos'; - - +const PANEL_OSD_FORCE_EXPAND = 'force-expand'; +const PANEL_OSD_TEST_DELAY = 'test-delay'; +const PANEL_OSD_TEST_NOTIFICATION = 'test-notification'; /* * Save MessageTray's original methods. We're going to change these @@ -66,12 +68,28 @@ const State = { HIDING: 3 }; -function init() {} +function init() { + Convenience.initTranslations('gnome-shell-extension-panel-osd'); +} let Settings; +let SettingsC; + +let showTestNotificationTimeout; let loadConfig = function() { Settings = Convenience.getSettings(PANEL_OSD_SETTINGS_SCHEMA); + SettingsC = Settings.connect("changed", function() { + if (getTestNotification()) { + if (showTestNotificationTimeout !== undefined) + Mainloop.source_remove(showTestNotificationTimeout); + showTestNotificationTimeout = Mainloop.timeout_add(getTestDelay(), Lang.bind(this, function() { + Main.notify("Panel OSD", _("This is just a multiline test-message to show where the notification will be placed and to test expansion (showing details).")); + return false; + })); + setTestNotification(false); + } + }); }; let getX_position = function() { @@ -80,13 +98,35 @@ let getX_position = function() { return Settings.get_double(PANEL_OSD_X_POS_KEY); }; -let gety_position = function() { +let getY_position = function() { if (!Settings) loadConfig(); return Settings.get_double(PANEL_OSD_Y_POS_KEY); }; +let getForce_expand = function() { + if (!Settings) + loadConfig(); + return Settings.get_boolean(PANEL_OSD_FORCE_EXPAND); +}; + +let getTestDelay = function() { + if (!Settings) + loadConfig(); + return Math.floor(1000 * Settings.get_double(PANEL_OSD_TEST_DELAY)); +}; +let getTestNotification = function() { + if (!Settings) + loadConfig(); + return Settings.get_boolean(PANEL_OSD_TEST_NOTIFICATION); +}; + +let setTestNotification = function(v) { + if (!Settings) + loadConfig(); + Settings.set_boolean(PANEL_OSD_TEST_NOTIFICATION, v); +}; /* * Copied from MessageTray._showNotification() * @@ -124,7 +164,7 @@ let extensionShowNotification = function() { let yTop = -global.screen_height; let yBottom = 0; - this._notificationWidget.y = (yTop - yBottom) * gety_position() / 100 + yBottom; + this._notificationWidget.y = (yTop - yBottom) * getY_position() / 100 + yBottom; // JRL changes end @@ -182,7 +222,7 @@ let extensionHideNotification = function(animate) { } // JRL changes begin let yPos; - if (gety_position() < 50) + if (getY_position() < 50) yPos = this.actor.height; else yPos = -global.screen_height; @@ -306,9 +346,9 @@ let extensionUpdateShowingNotification = function() { this._notification._table.remove_style_class_name('jrlnotification'); this._notification._table.remove_style_class_name('jrlnotification_top'); this._notification._table.remove_style_class_name('jrlnotification_bottom'); - if (gety_position() <= 0.1) + if (getY_position() <= 0.1) this._notification._table.add_style_class_name('jrlnotification_bottom'); - else if (gety_position() >= 99.9) + else if (getY_position() >= 99.9) this._notification._table.add_style_class_name('jrlnotification_top'); else this._notification._table.add_style_class_name('jrlnotification'); @@ -317,7 +357,11 @@ let extensionUpdateShowingNotification = function() { this._notification.acknowledged = true; if (ExtensionUtils.versionCheck(['3.6'], Config.PACKAGE_VERSION)) { // We auto-expand notifications with CRITICAL urgency. - if (this._notification.urgency == Urgency.CRITICAL) + // JRL changes begin + // if (this._notification.urgency == Urgency.CRITICAL) + if (this._notification.urgency == Urgency.CRITICAL || + getForce_expand()) + // JRL changes end this._expandNotification(true); } else @@ -326,6 +370,9 @@ let extensionUpdateShowingNotification = function() { // We auto-expand notifications with CRITICAL urgency, or for which the relevant setting // is on in the control center. if (this._notification.urgency == Urgency.CRITICAL || + // JRL changes begin + getForce_expand() || + // JRL changes end this._notification.source.policy.forceExpanded) this._expandNotification(true); } @@ -341,7 +388,7 @@ let extensionUpdateShowingNotification = function() { yTop = -global.screen_height; let yBottom = -this._notificationWidget.height; - let yPos = (yTop - yBottom) * gety_position() / 100 + yBottom; + let yPos = (yTop - yBottom) * getY_position() / 100 + yBottom; // this._notificationWidget.x = (global.screen_width - this._notificationWidget.width) * (getX_position() - 50) / 50; // JRL changes end @@ -386,7 +433,7 @@ let extensiononNotificationExpanded = function() { yTop = -global.screen_height; let yBottom = -this._notificationWidget.height; - let expandedY = (yTop - yBottom) * gety_position() / 100 + yBottom; + let expandedY = (yTop - yBottom) * getY_position() / 100 + yBottom; // JRL changes end this._closeButton.show(); @@ -414,6 +461,7 @@ function enable() { Main.messageTray._hideNotification = extensionHideNotification; Main.messageTray._updateShowingNotification = extensionUpdateShowingNotification; Main.messageTray._onNotificationExpanded = extensiononNotificationExpanded; + loadConfig(); } @@ -421,6 +469,14 @@ function enable() { * Put everything back. */ function disable() { + if (SettingsC) { + Settings.disconnect(SettingsC); + SettingsC = undefined; + } + + if (showTestNotificationTimeout !== undefined) + Mainloop.source_remove(showTestNotificationTimeout); + // 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'); diff --git a/src/prefs.js b/src/prefs.js index 8be8c7e..14d5faf 100644 --- a/src/prefs.js +++ b/src/prefs.js @@ -19,6 +19,9 @@ const PANEL_OSD_X_POS_KEY = 'x-pos'; const PANEL_OSD_Y_POS_KEY = 'y-pos'; const PANEL_OSD_ALLOW_X_RESET = 'x-res'; const PANEL_OSD_ALLOW_Y_RESET = 'y-res'; +const PANEL_OSD_FORCE_EXPAND = 'force-expand'; +const PANEL_OSD_TEST_DELAY = 'test-delay'; +const PANEL_OSD_TEST_NOTIFICATION = 'test-notification'; const PanelOsdPrefsWidget = new GObject.Class({ Name: 'PanelOsdExtension.Prefs.Widget', @@ -36,6 +39,9 @@ const PanelOsdPrefsWidget = new GObject.Class({ Window: new Gtk.Builder(), initWindow: function() { + if (this.test_notification) + this.test_notification = false; + this.Window.set_translation_domain('gnome-shell-extension-panel-osd'); this.Window.add_from_file(EXTENSIONDIR + "/panel-osd-settings.ui"); @@ -95,6 +101,33 @@ const PanelOsdPrefsWidget = new GObject.Class({ if (this.y_reset) this.y_scale.set_value(100); })); + this.switch_force_expand = this.Window.get_object("switch-force-expand"); + + this.switch_force_expand.set_active(this.force_expand); + + this.switch_force_expand.connect("notify::active", Lang.bind(this, function() { + this.force_expand = arguments[0].active; + })); + + this.delay_scale = this.Window.get_object("scale-test-delay"); + this.delay_scale.set_value(this.test_delay); + // prevent from continously updating the value + this.delayScaleTimeout = undefined; + this.delay_scale.connect("value-changed", Lang.bind(this, function(slider) { + + if (this.delayScaleTimeout !== undefined) + Mainloop.source_remove(this.delayScaleTimeout); + this.delayScaleTimeout = Mainloop.timeout_add(250, Lang.bind(this, function() { + this.test_delay = slider.get_value(); + return false; + })); + + })); + + this.Window.get_object("button-test").connect("clicked", Lang.bind(this, function() { + this.test_notification = true; + })); + }, @@ -148,6 +181,42 @@ const PanelOsdPrefsWidget = new GObject.Class({ if (!this.Settings) this.loadConfig(); this.Settings.set_boolean(PANEL_OSD_ALLOW_Y_RESET, v); + }, + + get force_expand() { + if (!this.Settings) + this.loadConfig(); + return this.Settings.get_boolean(PANEL_OSD_FORCE_EXPAND); + }, + + set force_expand(v) { + if (!this.Settings) + this.loadConfig(); + this.Settings.set_boolean(PANEL_OSD_FORCE_EXPAND, v); + }, + + get test_delay() { + if (!this.Settings) + this.loadConfig(); + return this.Settings.get_double(PANEL_OSD_TEST_DELAY); + }, + + set test_delay(v) { + if (!this.Settings) + this.loadConfig(); + this.Settings.set_double(PANEL_OSD_TEST_DELAY, v); + }, + + get test_notification() { + if (!this.Settings) + this.loadConfig(); + return this.Settings.get_boolean(PANEL_OSD_TEST_NOTIFICATION); + }, + + set test_notification(v) { + if (!this.Settings) + this.loadConfig(); + this.Settings.set_boolean(PANEL_OSD_TEST_NOTIFICATION, v); } });