diff options
author | wolfbeast <mcwerewolf@gmail.com> | 2014-05-21 11:38:25 +0200 |
---|---|---|
committer | wolfbeast <mcwerewolf@gmail.com> | 2014-05-21 11:38:25 +0200 |
commit | d25ba7d760b017b038e5aa6c0a605b4a330eb68d (patch) | |
tree | 16ec27edc7d5f83986f16236d3a36a2682a0f37e /dom/phonenumberutils/PhoneNumberUtils.jsm | |
parent | a942906574671868daf122284a9c4689e6924f74 (diff) | |
download | palemoon-gre-d25ba7d760b017b038e5aa6c0a605b4a330eb68d.tar.gz |
Recommit working copy to repo with proper line endings.
Diffstat (limited to 'dom/phonenumberutils/PhoneNumberUtils.jsm')
-rw-r--r-- | dom/phonenumberutils/PhoneNumberUtils.jsm | 100 |
1 files changed, 100 insertions, 0 deletions
diff --git a/dom/phonenumberutils/PhoneNumberUtils.jsm b/dom/phonenumberutils/PhoneNumberUtils.jsm new file mode 100644 index 000000000..5db22f7a5 --- /dev/null +++ b/dom/phonenumberutils/PhoneNumberUtils.jsm @@ -0,0 +1,100 @@ +/* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set shiftwidth=2 tabstop=2 autoindent cindent expandtab: */ + +"use strict"; + +this.EXPORTED_SYMBOLS = ["PhoneNumberUtils"]; + +const DEBUG = false; +function debug(s) { if(DEBUG) dump("-*- PhoneNumberutils: " + s + "\n"); } + +const Cu = Components.utils; + +Cu.import("resource://gre/modules/Services.jsm"); +Cu.import('resource://gre/modules/XPCOMUtils.jsm'); +Cu.import("resource://gre/modules/PhoneNumber.jsm"); +Cu.import("resource://gre/modules/mcc_iso3166_table.jsm"); + +#ifdef MOZ_B2G_RIL +XPCOMUtils.defineLazyServiceGetter(this, "mobileConnection", + "@mozilla.org/ril/content-helper;1", + "nsIMobileConnectionProvider"); +#endif + +this.PhoneNumberUtils = { + // 1. See whether we have a network mcc + // 2. If we don't have that, look for the simcard mcc + // 3. TODO: If we don't have that or its 0 (not activated), pick up the last used mcc + // 4. If we don't have, default to some mcc + + // mcc for Brasil + _mcc: '724', + + getCountryName: function getCountryName() { + let mcc; + let countryName; + +#ifdef MOZ_B2G_RIL + // Get network mcc + if (mobileConnection.voiceConnectionInfo && + mobileConnection.voiceConnectionInfo.network) { + mcc = mobileConnection.voiceConnectionInfo.network.mcc; + } + + // Get SIM mcc + if (!mcc) { + mcc = mobileConnection.iccInfo.mcc; + } + + // Get previous mcc + if (!mcc && mobileConnection.voiceConnectionInfo) { + mcc = mobileConnection.voiceConnectionInfo.lastKnownMcc; + } + + // Set to default mcc + if (!mcc) { + mcc = this._mcc; + } +#else + mcc = this._mcc; +#endif + + countryName = MCC_ISO3166_TABLE[mcc]; + if (DEBUG) debug("MCC: " + mcc + "countryName: " + countryName); + return countryName; + }, + + parse: function(aNumber) { + if (DEBUG) debug("call parse: " + aNumber); + let result = PhoneNumber.Parse(aNumber, this.getCountryName()); + if (DEBUG) { + if (result) { + debug("InternationalFormat: " + result.internationalFormat); + debug("InternationalNumber: " + result.internationalNumber); + debug("NationalNumber: " + result.nationalNumber); + debug("NationalFormat: " + result.nationalFormat); + } else { + debug("No result!\n"); + } + } + return result; + }, + + parseWithMCC: function(aNumber, aMCC) { + let countryName = MCC_ISO3166_TABLE[aMCC]; + if (DEBUG) debug("found country name: " + countryName); + return PhoneNumber.Parse(aNumber, countryName); + }, + + isPlainPhoneNumber: function isPlainPhoneNumber(aNumber) { + var isPlain = PhoneNumber.IsPlain(aNumber); + if (DEBUG) debug("isPlain(" + aNumber + ") " + isPlain); + return isPlain; + }, + + normalize: function Normalize(aNumber, aNumbersOnly) { + var normalized = PhoneNumber.Normalize(aNumber, aNumbersOnly); + if (DEBUG) debug("normalize(" + aNumber + "): " + normalized + ", " + aNumbersOnly); + return normalized; + } +}; |