|
@@ -0,0 +1,356 @@
|
|
|
|
+# HG changeset patch
|
|
|
|
+# User Ian Neal <iann_cvs@blueyonder.co.uk>
|
|
|
|
+# Date 1728942119 -3600
|
|
|
|
+# Parent e092798953aaafdd481ed325a663bf28e2995a4d
|
|
|
|
+Bug 1924592 - Tidy message manager code in cZ. r=frg a=frg
|
|
|
|
+
|
|
|
|
+diff --git a/suite/extensions/irc/js/lib/message-manager.js b/suite/extensions/irc/js/lib/message-manager.js
|
|
|
|
+--- a/suite/extensions/irc/js/lib/message-manager.js
|
|
|
|
++++ b/suite/extensions/irc/js/lib/message-manager.js
|
|
|
|
+@@ -2,81 +2,38 @@
|
|
|
|
+ *
|
|
|
|
+ * This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
+
|
|
|
|
+ //
|
|
|
|
+ function MessageManager(entities)
|
|
|
|
+ {
|
|
|
|
+- const UC_CTRID = "@mozilla.org/intl/scriptableunicodeconverter";
|
|
|
|
+- const nsIUnicodeConverter =
|
|
|
|
+- Components.interfaces.nsIScriptableUnicodeConverter;
|
|
|
|
+-
|
|
|
|
+- this.ucConverter =
|
|
|
|
+- Components.classes[UC_CTRID].getService(nsIUnicodeConverter);
|
|
|
|
++ this.ucConverter = Cc["@mozilla.org/intl/scriptableunicodeconverter"]
|
|
|
|
++ .getService(Ci.nsIScriptableUnicodeConverter);
|
|
|
|
+ this.defaultBundle = null;
|
|
|
|
+ this.bundleList = new Array();
|
|
|
|
+ // Provide a fallback so we don't break getMsg and related constants later.
|
|
|
|
+ this.entities = entities || {};
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+-// ISO-2022-JP (often used for Japanese on IRC) doesn't contain any support
|
|
|
|
+-// for hankaku kana (half-width katakana), so we support the option to convert
|
|
|
|
+-// it to zenkaku kana (full-width katakana). This does not affect any other
|
|
|
|
+-// encoding at this time.
|
|
|
|
+-MessageManager.prototype.enableHankakuToZenkaku = false;
|
|
|
|
+-
|
|
|
|
+ MessageManager.prototype.loadBrands =
|
|
|
|
+ function mm_loadbrands()
|
|
|
|
+ {
|
|
|
|
+- var entities = this.entities;
|
|
|
|
+- var app = getService("@mozilla.org/xre/app-info;1", "nsIXULAppInfo");
|
|
|
|
+- if (app)
|
|
|
|
+- {
|
|
|
|
+- // Use App info if possible
|
|
|
|
+- entities.brandShortName = app.name;
|
|
|
|
+- entities.brandFullName = app.name + " " + app.version;
|
|
|
|
+- entities.brandVendorName = app.vendor;
|
|
|
|
+- return;
|
|
|
|
+- }
|
|
|
|
+-
|
|
|
|
+- var brandBundle;
|
|
|
|
+- var path = "chrome://branding/locale/brand.properties";
|
|
|
|
+- try
|
|
|
|
+- {
|
|
|
|
+- brandBundle = this.addBundle(path);
|
|
|
|
+- }
|
|
|
|
+- catch (exception)
|
|
|
|
+- {
|
|
|
|
+- // May be an older mozilla version, try another location.
|
|
|
|
+- path = "chrome://global/locale/brand.properties";
|
|
|
|
+- brandBundle = this.addBundle(path);
|
|
|
|
+- }
|
|
|
|
+-
|
|
|
|
+- entities.brandShortName = brandBundle.GetStringFromName("brandShortName");
|
|
|
|
+- entities.brandVendorName = brandBundle.GetStringFromName("vendorShortName");
|
|
|
|
+- // Not all versions of Suite / Fx have this defined; Cope:
|
|
|
|
+- try
|
|
|
|
+- {
|
|
|
|
+- entities.brandFullName = brandBundle.GetStringFromName("brandFullName");
|
|
|
|
+- }
|
|
|
|
+- catch(exception)
|
|
|
|
+- {
|
|
|
|
+- entities.brandFullName = entities.brandShortName;
|
|
|
|
+- }
|
|
|
|
+-
|
|
|
|
+- // Remove all of this junk, or it will be the default bundle for getMsg...
|
|
|
|
+- this.bundleList.pop();
|
|
|
|
++ let brandPath = "chrome://branding/locale/brand.properties";
|
|
|
|
++ let bundle = Services.strings.createBundle(brandPath);
|
|
|
|
++ this.entities.brandShortName = bundle.GetStringFromName("brandShortName");
|
|
|
|
++ this.entities.brandFullName = bundle.GetStringFromName("brandFullName");
|
|
|
|
++ this.entities.vendorShortName = bundle.GetStringFromName("vendorShortName");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ MessageManager.prototype.addBundle =
|
|
|
|
+ function mm_addbundle(bundlePath, targetWindow)
|
|
|
|
+ {
|
|
|
|
+- var bundle = srGetStrBundle(bundlePath);
|
|
|
|
++ let bundle = Services.strings.createBundle(bundlePath);
|
|
|
|
+ this.bundleList.push(bundle);
|
|
|
|
+
|
|
|
|
+ // The bundle will load if the file doesn't exist. This will fail though.
|
|
|
|
+ // We want to be clean and remove the bundle again.
|
|
|
|
+ try
|
|
|
|
+ {
|
|
|
|
+ this.importBundle(bundle, targetWindow, this.bundleList.length - 1);
|
|
|
|
+ }
|
|
|
|
+@@ -95,17 +52,16 @@ function mm_importbundle(bundle, targetW
|
|
|
|
+ var me = this;
|
|
|
|
+ function replaceEntities(matched, entity)
|
|
|
|
+ {
|
|
|
|
+ if (entity in me.entities)
|
|
|
|
+ return me.entities[entity];
|
|
|
|
+
|
|
|
|
+ return matched;
|
|
|
|
+ };
|
|
|
|
+- const nsIPropertyElement = Components.interfaces.nsIPropertyElement;
|
|
|
|
+
|
|
|
|
+ if (!targetWindow)
|
|
|
|
+ targetWindow = window;
|
|
|
|
+
|
|
|
|
+ if (typeof index == "undefined")
|
|
|
|
+ index = this.bundleList.indexOf(bundle);
|
|
|
|
+
|
|
|
|
+ var pfx;
|
|
|
|
+@@ -113,17 +69,17 @@ function mm_importbundle(bundle, targetW
|
|
|
|
+ pfx = "";
|
|
|
|
+ else
|
|
|
|
+ pfx = index + ":";
|
|
|
|
+
|
|
|
|
+ var enumer = bundle.getSimpleEnumeration();
|
|
|
|
+
|
|
|
|
+ while (enumer.hasMoreElements())
|
|
|
|
+ {
|
|
|
|
+- var prop = enumer.getNext().QueryInterface(nsIPropertyElement);
|
|
|
|
++ var prop = enumer.getNext().QueryInterface(Ci.nsIPropertyElement);
|
|
|
|
+ var ary = prop.key.match (/^(msg|msn)/);
|
|
|
|
+ if (ary)
|
|
|
|
+ {
|
|
|
|
+ var constValue;
|
|
|
|
+ var constName = prop.key.toUpperCase().replace (/\./g, "_");
|
|
|
|
+ if (ary[1] == "msn" || prop.value.search(/%(\d+\$)?s/i) != -1)
|
|
|
|
+ constValue = pfx + prop.key;
|
|
|
|
+ else
|
|
|
|
+@@ -133,94 +89,16 @@ function mm_importbundle(bundle, targetW
|
|
|
|
+ targetWindow[constName] = constValue;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (this.bundleList.length == 1)
|
|
|
|
+ this.defaultBundle = bundle;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+-MessageManager.prototype.convertHankakuToZenkaku =
|
|
|
|
+-function mm_converthankakutozenkaku(msg)
|
|
|
|
+-{
|
|
|
|
+- const basicMapping = [
|
|
|
|
+- /* 0xFF60 */ 0xFF60,0x3002,0x300C,0x300D,0x3001,0x30FB,0x30F2,0x30A1,
|
|
|
|
+- /* 0xFF68 */ 0x30A3,0x30A5,0x30A7,0x30A9,0x30E3,0x30E5,0x30E7,0x30C3,
|
|
|
|
+- /* 0xFF70 */ 0x30FC,0x30A2,0x30A4,0x30A6,0x30A8,0x30AA,0x30AB,0x30AD,
|
|
|
|
+- /* 0xFF78 */ 0x30AF,0x30B1,0x30B3,0x30B5,0x30B7,0x30B9,0x30BB,0x30BD,
|
|
|
|
+- /* 0xFF80 */ 0x30BF,0x30C1,0x30C4,0x30C6,0x30C8,0x30CA,0x30CB,0x30CC,
|
|
|
|
+- /* 0xFF88 */ 0x30CD,0x30CE,0x30CF,0x30D2,0x30D5,0x30D8,0x30DB,0x30DE,
|
|
|
|
+- /* 0xFF90 */ 0x30DF,0x30E0,0x30E1,0x30E2,0x30E4,0x30E6,0x30E8,0x30E9,
|
|
|
|
+- /* 0xFF98 */ 0x30EA,0x30EB,0x30EC,0x30ED,0x30EF,0x30F3,0x309B,0x309C
|
|
|
|
+- ];
|
|
|
|
+-
|
|
|
|
+- const HANKAKU_BASE1 = 0xFF60;
|
|
|
|
+- const HANKAKU_BASE2 = 0xFF80;
|
|
|
|
+- const HANKAKU_MASK = 0xFFE0;
|
|
|
|
+-
|
|
|
|
+- const MOD_NIGORI = 0xFF9E;
|
|
|
|
+- const NIGORI_MIN1 = 0xFF76;
|
|
|
|
+- const NIGORI_MAX1 = 0xFF84;
|
|
|
|
+- const NIGORI_MIN2 = 0xFF8A;
|
|
|
|
+- const NIGORI_MAX2 = 0xFF8E;
|
|
|
|
+- const NIGORI_MODIFIER = 1;
|
|
|
|
+-
|
|
|
|
+- const MOD_MARU = 0xFF9F;
|
|
|
|
+- const MARU_MIN = 0xFF8A;
|
|
|
|
+- const MARU_MAX = 0xFF8E;
|
|
|
|
+- const MARU_MODIFIER = 2;
|
|
|
|
+-
|
|
|
|
+- var i, src, srcMod, dest;
|
|
|
|
+- var rv = "";
|
|
|
|
+-
|
|
|
|
+- for (i = 0; i < msg.length; i++)
|
|
|
|
+- {
|
|
|
|
+- // Get both this character and the next one, which could be a modifier.
|
|
|
|
+- src = msg.charCodeAt(i);
|
|
|
|
+- if (i < msg.length - 1)
|
|
|
|
+- srcMod = msg.charCodeAt(i + 1);
|
|
|
|
+-
|
|
|
|
+- // Is the source characher hankaku?
|
|
|
|
+- if ((HANKAKU_BASE1 == (src & HANKAKU_MASK)) ||
|
|
|
|
+- (HANKAKU_BASE2 == (src & HANKAKU_MASK)))
|
|
|
|
+- {
|
|
|
|
+- // Do the basic character mapping first.
|
|
|
|
+- dest = basicMapping[src - HANKAKU_BASE1];
|
|
|
|
+-
|
|
|
|
+- // If the source character is in the nigori or maru ranges and
|
|
|
|
+- // the following character is the associated modifier, we apply
|
|
|
|
+- // the modification and skip over the modifier.
|
|
|
|
+- if (i < msg.length - 1)
|
|
|
|
+- {
|
|
|
|
+- if ((MOD_NIGORI == srcMod) &&
|
|
|
|
+- (((src >= NIGORI_MIN1) && (src <= NIGORI_MAX1)) ||
|
|
|
|
+- ((src >= NIGORI_MIN2) && (src <= NIGORI_MAX2))))
|
|
|
|
+- {
|
|
|
|
+- dest += NIGORI_MODIFIER;
|
|
|
|
+- i++;
|
|
|
|
+- }
|
|
|
|
+- else if ((MOD_MARU == srcMod) &&
|
|
|
|
+- (src >= MARU_MIN) && (src <= MARU_MAX))
|
|
|
|
+- {
|
|
|
|
+- dest += MARU_MODIFIER;
|
|
|
|
+- i++;
|
|
|
|
+- }
|
|
|
|
+- }
|
|
|
|
+-
|
|
|
|
+- rv += String.fromCharCode(dest);
|
|
|
|
+- }
|
|
|
|
+- else
|
|
|
|
+- {
|
|
|
|
+- rv += msg[i];
|
|
|
|
+- }
|
|
|
|
+- }
|
|
|
|
+-
|
|
|
|
+- return rv;
|
|
|
|
+-}
|
|
|
|
+-
|
|
|
|
+ MessageManager.prototype.checkCharset =
|
|
|
|
+ function mm_checkset(charset)
|
|
|
|
+ {
|
|
|
|
+ try
|
|
|
|
+ {
|
|
|
|
+ this.ucConverter.charset = charset;
|
|
|
|
+ }
|
|
|
|
+ catch (ex)
|
|
|
|
+@@ -252,35 +130,24 @@ function mm_tounicode(msg, charset)
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ MessageManager.prototype.fromUnicode =
|
|
|
|
+ function mm_fromunicode(msg, charset)
|
|
|
|
+ {
|
|
|
|
+ if (!charset)
|
|
|
|
+ return msg;
|
|
|
|
+
|
|
|
|
+- if (this.enableHankakuToZenkaku && (charset.toLowerCase() == "iso-2022-jp"))
|
|
|
|
+- msg = this.convertHankakuToZenkaku(msg);
|
|
|
|
+-
|
|
|
|
+ try
|
|
|
|
+ {
|
|
|
|
+ // This can actually fail in bizare cases. Cope.
|
|
|
|
+ if (charset != this.ucConverter.charset)
|
|
|
|
+ this.ucConverter.charset = charset;
|
|
|
|
+
|
|
|
|
+- if ("Finish" in this.ucConverter)
|
|
|
|
+- {
|
|
|
|
+- msg = this.ucConverter.ConvertFromUnicode(msg) +
|
|
|
|
+- this.ucConverter.Finish();
|
|
|
|
+- }
|
|
|
|
+- else
|
|
|
|
+- {
|
|
|
|
+- msg = this.ucConverter.ConvertFromUnicode(msg + " ");
|
|
|
|
+- msg = msg.substr(0, msg.length - 1);
|
|
|
|
+- }
|
|
|
|
++ msg = this.ucConverter.ConvertFromUnicode(msg) +
|
|
|
|
++ this.ucConverter.Finish();
|
|
|
|
+ }
|
|
|
|
+ catch (ex)
|
|
|
|
+ {
|
|
|
|
+ //dd ("caught exception " + ex + " converting " + msg + " to charset " +
|
|
|
|
+ // charset);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return msg;
|
|
|
|
+diff --git a/suite/extensions/irc/js/lib/utils.js b/suite/extensions/irc/js/lib/utils.js
|
|
|
|
+--- a/suite/extensions/irc/js/lib/utils.js
|
|
|
|
++++ b/suite/extensions/irc/js/lib/utils.js
|
|
|
|
+@@ -1132,38 +1132,11 @@ function strftime(format, time)
|
|
|
|
+ }
|
|
|
|
+ if (!rpl)
|
|
|
|
+ rpl = "%%" + ary[2];
|
|
|
|
+ format = format.substr(0, start) + rpl + format.substr(start + 2);
|
|
|
|
+ }
|
|
|
|
+ return format.replace(/%%/, "%");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+-// This used to be strres.js, copied here to help remove that...
|
|
|
|
+-var strBundleService = null;
|
|
|
|
+-function srGetStrBundle(path)
|
|
|
|
+-{
|
|
|
|
+- const STRBSCID = "@mozilla.org/intl/stringbundle;1";
|
|
|
|
+- const STRBSIF = "nsIStringBundleService";
|
|
|
|
+- var strBundle = null;
|
|
|
|
+- if (!strBundleService)
|
|
|
|
+- {
|
|
|
|
+- try
|
|
|
|
+- {
|
|
|
|
+- strBundleService = getService(STRBSCID, STRBSIF);
|
|
|
|
+- }
|
|
|
|
+- catch (ex)
|
|
|
|
+- {
|
|
|
|
+- dump("\n--** strBundleService failed: " + ex + "\n");
|
|
|
|
+- return null;
|
|
|
|
+- }
|
|
|
|
+- }
|
|
|
|
+-
|
|
|
|
+- strBundle = strBundleService.createBundle(path);
|
|
|
|
+- if (!strBundle)
|
|
|
|
+- dump("\n--** strBundle createInstance failed **--\n");
|
|
|
|
+-
|
|
|
|
+- return strBundle;
|
|
|
|
+-}
|
|
|
|
+-
|
|
|
|
+ // No-op window.getAttention if it's not found, this is for in-a-tab mode.
|
|
|
|
+ if (typeof getAttention == "undefined")
|
|
|
|
+ getAttention = function() {};
|
|
|
|
+diff --git a/suite/extensions/irc/locales/en-US/chrome/chatzilla.properties b/suite/extensions/irc/locales/en-US/chrome/chatzilla.properties
|
|
|
|
+--- a/suite/extensions/irc/locales/en-US/chrome/chatzilla.properties
|
|
|
|
++++ b/suite/extensions/irc/locales/en-US/chrome/chatzilla.properties
|
|
|
|
+@@ -31,18 +31,18 @@ msg.confirm = Confirm
|
|
|
|
+ # The following are therefore equivalent:
|
|
|
|
+ # cmd.foo.label = &Foo
|
|
|
|
+ # and
|
|
|
|
+ # cmd.foo.label = Foo
|
|
|
|
+ # cmd.foo.accesskey = F
|
|
|
|
+ #
|
|
|
|
+ #
|
|
|
|
+ # All localised strings may contain certain entities for branding purposes.
|
|
|
|
+-# The three standard brand entities (brandShortName, brandFullName, vendorName)
|
|
|
|
+-# can all be used like this:
|
|
|
|
++# The three standard brand entities (brandShortName, brandFullName,
|
|
|
|
++# vendorShortName) can all be used like this:
|
|
|
|
+ # foo.bar = Some text used in &brandFullName;!
|
|
|
|
+ #
|
|
|
|
+ ### End of notes ###
|
|
|
|
+
|
|
|
|
+ cmd.about.label = About ChatZilla
|
|
|
|
+ cmd.about.help = Display information about this version of ChatZilla.
|
|
|
|
+
|
|
|
|
+ cmd.alias.helpUsage = [<alias-name> [<command-list>]]
|
|
|
|
+diff --git a/suite/extensions/irc/xul/content/messages.js b/suite/extensions/irc/xul/content/messages.js
|
|
|
|
+--- a/suite/extensions/irc/xul/content/messages.js
|
|
|
|
++++ b/suite/extensions/irc/xul/content/messages.js
|
|
|
|
+@@ -4,17 +4,16 @@
|
|
|
|
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
+
|
|
|
|
+ function initMessages()
|
|
|
|
+ {
|
|
|
|
+ var path = "chrome://chatzilla/locale/chatzilla.properties";
|
|
|
|
+
|
|
|
|
+ client.messageManager = new MessageManager(client.entities);
|
|
|
|
+- client.messageManager.enableHankakuToZenkaku = true;
|
|
|
|
+ client.messageManager.loadBrands();
|
|
|
|
+ client.defaultBundle = client.messageManager.addBundle(path);
|
|
|
|
+
|
|
|
|
+ client.viewName = client.unicodeName = MSG_CLIENT_NAME;
|
|
|
|
+ client.responseCodeMap =
|
|
|
|
+ {
|
|
|
|
+ "HELLO": MSG_RSP_HELLO,
|
|
|
|
+ "HELP" : MSG_RSP_HELP,
|