49 Components.utils.import(
"resource://app/jsmodules/DOMUtils.jsm");
50 Components.utils.import(
"resource://app/jsmodules/StringUtils.jsm");
60 if (typeof(
Cc) ==
"undefined")
61 var
Cc = Components.classes;
62 if (typeof(
Ci) ==
"undefined")
63 var
Ci = Components.interfaces;
64 if (typeof(
Cr) ==
"undefined")
65 var
Cr = Components.results;
66 if (typeof(
Cu) ==
"undefined")
67 var
Cu = Components.utils;
70 if (typeof(
XUL_NS) ==
"undefined")
71 var
XUL_NS =
"http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul";
86 languageNamesBundleURL:
"chrome://global/locale/languageNames.properties",
87 regionNamesBundleURL:
"chrome://global/locale/regionNames.properties",
88 localeBundleDataLoadTimeout: 15000
107 this._widget = aWidget;
149 _domEventListenerSet:
null,
151 _wizardPageElem:
null,
154 _languageNamesBundle:
null,
155 _regionNamesBundle:
null,
156 _localeInfoTable:
null,
157 _localeInfoList:
null,
158 _localeIgnoreSelectEvents:
false,
159 _currentLocale:
null,
161 _userSelectedLocale:
null,
162 _appRestartRequired:
false,
164 _localeBundleRunning:
false,
166 _localeBundleDataLoadComplete:
false,
167 _localeBundleDataLoadSucceeded:
false,
180 initialize:
function firstRunEULASvc_initialize() {
188 this._wizardPageElem = this._widget;
189 this._wizardElem = this._wizardPageElem.ownerDocument.documentElement;
192 this._localeInitialize();
195 func =
function() { _this._doPageShow(); };
196 this._domEventListenerSet.add(this._wizardPageElem,
200 func =
function(aEvent) { _this._doPageAdvanced(aEvent); };
201 this._domEventListenerSet.add(this._wizardPageElem,
207 func =
function(aEvent) { firstRunWizard.doQuit(aEvent); };
208 this._domEventListenerSet.add(this._wizardPageElem,
214 func =
function(aEvent) { _this._onContentClick(aEvent); };
215 this._domEventListenerSet.add(this._widget.eulaBrowser,
221 this._perfInitialize();
229 finalize:
function firstRunEULASvc_finalize() {
231 this._localeFinalize();
234 if (this._domEventListenerSet) {
235 this._domEventListenerSet.removeAll();
237 this._domEventListenerSet =
null;
241 this._wizardElem =
null;
242 this._wizardPageElem =
null;
256 doAcceptChanged:
function firstRunEULASvc_doAcceptChanged() {
266 _doPageShow:
function firstRunEULASvc__doPageShow() {
269 var eulaAccepted =
Application.prefs.getValue(
"songbird.eulacheck",
false);
270 if (eulaAccepted || this._perfTest) {
276 this._localeDoPageShow();
279 this._wizardElem.getButton(
"extra1").label =
293 _doPageAdvanced:
function firstRunEULASvc__doPageAdvanced(aEvent) {
295 var eulaAccepted =
Application.prefs.getValue(
"songbird.eulacheck",
false);
296 var acceptCheckboxElem = this._getElement(
"accept_checkbox");
297 if (!eulaAccepted && !acceptCheckboxElem.checked) {
298 aEvent.preventDefault();
303 Application.prefs.setValue(
"songbird.eulacheck",
true);
304 var prefService = Cc[
"@mozilla.org/preferences-service;1"]
305 .getService(Ci.nsIPrefService);
306 prefService.savePrefFile(
null);
309 this._localeDoPageAdvanced(aEvent);
317 _doConnectionReset:
function firstRunLocaleSvc__doConnectionReset() {
319 this._localeBundleFinalize();
320 this._localeBundleInitialize();
324 this._localeBundleLoad();
331 _onContentClick:
function(aEvent) {
336 var targetURI = Cc[
"@mozilla.org/network/io-service;1"]
337 .getService(Ci.nsIIOService)
340 var extLoader = Cc[
"@mozilla.org/uriloader/external-protocol-service;1"]
341 .getService(Ci.nsIExternalProtocolService);
342 extLoader.loadURI(targetURI,
null);
343 aEvent.preventDefault();
360 _localeInitialize:
function firstRunEULASvc__localeInitialize() {
362 var stringBundleService = Cc[
"@mozilla.org/intl/stringbundle;1"]
363 .getService(Ci.nsIStringBundleService);
364 this._languageNamesBundle =
365 stringBundleService.createBundle(this._cfg.languageNamesBundleURL);
366 this._regionNamesBundle =
367 stringBundleService.createBundle(this._cfg.regionNamesBundleURL);
370 this._getLocaleInfo();
373 var chromeRegistry = Cc[
"@mozilla.org/chrome/chrome-registry;1"]
374 .getService(Ci.nsIXULChromeRegistry);
375 this._currentLocale = chromeRegistry.getSelectedLocale(
"songbird");
378 var localeService = Cc[
"@mozilla.org/intl/nslocaleservice;1"]
379 .getService(Ci.nsILocaleService);
380 this._systemLocale = localeService.getApplicationLocale()
381 .getCategory(
"NSILOCALE_CTYPE");
384 this._localeBundleInitialize();
388 var func =
function() {
return _this._doConnectionReset(); };
389 this._domEventListenerSet.add(firstRunWizard.wizardElem,
390 "firstRunConnectionReset",
400 _localeFinalize:
function firstRunEULASvc__localeFinalize() {
402 this._localeBundleFinalize();
405 this._languageNamesBundle =
null;
406 this._regionNamesBundle =
null;
407 this._localeInfoTable =
null;
408 this._localeInfoList =
null;
409 this._currentLocale =
null;
410 this._systemLocale =
null;
411 this._userSelectedLocale =
null;
419 _localeDoPageShow:
function firstRunEULASvc__localeDoPageShow() {
421 this._localeBundleStart();
431 _localeDoPageAdvanced:
432 function firstRunEULASvc__localeDoPageAdvanced(aEvent) {
434 var localeMenuListElem = this._getElement(
"locale_menulist");
435 var selectedLocaleTag = localeMenuListElem.value;
438 if (selectedLocaleTag != this._currentLocale) {
440 if (this._installLocale(selectedLocaleTag)) {
442 switchLocale(selectedLocaleTag);
445 if (this._appRestartRequired)
446 firstRunWizard.restartApp =
true;
448 firstRunWizard.restartWizard =
true;
451 aEvent.preventDefault();
454 document.defaultView.close();
464 localeDoSelect:
function firstRunEULASvc_localeDoSelect() {
466 if (this._ignoreLocaleSelectEvents)
470 var localeMenuListElem = this._getElement(
"locale_menulist");
471 this._userSelectedLocale = localeMenuListElem.value;
484 _installLocale:
function firstRunEULASvc__installLocale(aLocaleTag) {
486 var chromeRegistry = Cc[
"@mozilla.org/chrome/chrome-registry;1"]
487 .getService(Ci.nsIToolkitChromeRegistry);
488 var installedLocaleEnum = chromeRegistry.getLocalesForPackage(
"songbird");
489 while (installedLocaleEnum.hasMore()) {
491 var installedLocaleTag = installedLocaleEnum.getNext();
494 if (aLocaleTag == installedLocaleTag) {
500 if (!this._localeBundle)
505 if (!(aLocaleTag in this._localeInfoTable))
507 var localeInfo = this._localeInfoTable[aLocaleTag];
508 if (!(
"bundleIndex" in localeInfo))
510 var bundleIndex = localeInfo.bundleIndex;
513 var bundleExtensionCount = this._localeBundle.bundleExtensionCount;
514 for (var
i = 0;
i < bundleExtensionCount;
i++) {
515 this._localeBundle.setExtensionInstallFlag(
i,
false);
517 this._localeBundle.setExtensionInstallFlag(bundleIndex,
true);
520 var result = this._localeBundle.installFlaggedExtensions(
window);
521 if (result == Ci.sbIBundle.BUNDLE_INSTALL_ERROR)
525 if (this._localeBundle.restartRequired)
526 this._appRestartRequired =
true;
536 _localeUpdate:
function firstRunEULASvc__localeUpdate() {
540 if (this._localeBundleDataLoadComplete &&
541 !this._localeBundleDataLoadSucceeded) {
542 firstRunWizard.handleConnectionError();
546 var localeMenuPopupElem = this._getElement(
"locale_menupopup");
547 while (localeMenuPopupElem.hasChildNodes()) {
548 localeMenuPopupElem.removeChild(localeMenuPopupElem.firstChild);
552 for (var
i = 0;
i < this._localeInfoList.length;
i++) {
554 var localeInfo = this._localeInfoList[
i];
557 var menuItemElem = document.createElementNS(XUL_NS,
"menuitem");
558 menuItemElem.setAttribute(
"label", localeInfo.displayName);
559 menuItemElem.setAttribute(
"value", localeInfo.tag);
562 localeMenuPopupElem.appendChild(menuItemElem);
566 var selectedLocale = this._findMatchingLocaleTag(this._userSelectedLocale);
568 selectedLocale = this._findMatchingLocaleTag(this._systemLocale);
570 selectedLocale = this._findMatchingLocaleTag(this._currentLocale);
573 var localeMenuListElem = this._getElement(
"locale_menulist");
574 this._ignoreLocaleSelectEvents =
true;
576 localeMenuListElem.value = selectedLocale;
578 localeMenuListElem.selectedIndex = 0;
579 this._ignoreLocaleSelectEvents =
false;
587 _getLocaleInfo:
function firstRunEULASvc__getLocaleInfo() {
589 this._localeInfoTable = {};
592 var chromeRegistry = Cc[
"@mozilla.org/chrome/chrome-registry;1"]
593 .getService(Ci.nsIToolkitChromeRegistry);
594 var localeEnum = chromeRegistry.getLocalesForPackage(
"songbird");
595 while (localeEnum.hasMore())
598 var
tag = localeEnum.getNext();
599 var displayName = this._getLocaleDisplayName(tag);
602 var localeInfo = { tag:
tag, displayName: displayName };
603 this._localeInfoTable[
tag] = localeInfo;
607 if (this._localeBundle) {
608 var bundleExtensionCount = this._localeBundle.bundleExtensionCount;
609 for (var
i = 0;
i < bundleExtensionCount;
i++) {
611 var
tag = this._localeBundle.getExtensionAttribute(
i,
"languageTag");
612 var displayName = this._localeBundle.getExtensionAttribute(
i,
"name");
615 var localeInfo = { tag:
tag, displayName: displayName, bundleIndex:
i };
616 this._localeInfoTable[
tag] = localeInfo;
621 this._localeInfoList = [];
622 for (var localeTag in this._localeInfoTable) {
623 this._localeInfoList.push(this._localeInfoTable[localeTag]);
627 var sortFunc =
function(a, b) {
628 if (a.displayName > b.displayName)
630 if (a.displayName < b.displayName)
634 this._localeInfoList.sort(sortFunc);
650 _findMatchingLocaleTag:
651 function firstRunEULASvc__findMatchingLocaleTag(aLocaleTag) {
657 if (aLocaleTag in this._localeInfoTable)
661 var languageTag = aLocaleTag.split(
"-")[0];
662 if (languageTag in this._localeInfoTable)
677 _getLocaleDisplayName:
678 function firstRunEULASvc__getLocaleDisplayName(aLocaleTag) {
680 var localeTagPartList = aLocaleTag.split(
"-");
681 var languageTag = localeTagPartList[0];
683 if (localeTagPartList.length > 1)
684 regionTag = localeTagPartList[1];
687 var languageDisplayName =
SBString(languageTag,
689 this._languageNamesBundle);
690 var regionDisplayName =
"";
692 regionDisplayName =
SBString(regionTag,
"", this._regionNamesBundle);
695 var localeDisplayName =
"";
696 if (languageDisplayName && regionDisplayName) {
698 (
"locale.language_region.display_name",
699 [ languageDisplayName, regionDisplayName ],
701 }
else if (languageDisplayName) {
703 (
"locale.language.display_name",
704 [ languageDisplayName ],
707 if (!localeDisplayName)
708 localeDisplayName = aLocaleTag;
710 return localeDisplayName;
727 onDownloadComplete:
function firstRunEULASvc__onDownloadComplete(aBundle) {
728 this._localeBundleDataLoadComplete =
true;
729 this._localeBundleDataLoadSucceeded =
true;
730 this._getLocaleInfo();
742 onError:
function firstRunEULASvc__onError(aBundle) {
743 this._localeBundleDataLoadComplete =
true;
744 this._localeBundleDataLoadSucceeded =
false;
759 _localeBundleInitialize:
760 function firstRunEULASvc__localeBundleInitialize() {
762 this._localeBundle =
null;
763 this._localeBundleDataLoadComplete =
false;
764 this._localeBundleDataLoadSucceeded =
false;
772 _localeBundleFinalize:
773 function firstRunEULASvc__localeBundleFinalize() {
776 if (this._localeBundle)
777 this._localeBundle.removeBundleDataListener(
this);
780 this._localeBundleDataLoadComplete =
false;
781 this._localeBundleDataLoadSucceeded =
false;
784 this._localeBundle =
null;
792 _localeBundleStart:
function firstRunEULASvc__localeBundleStart() {
794 this._localeBundleRunning =
true;
795 this._localeBundleLoad();
803 _localeBundleLoad:
function firstRunEULASvc__localeBundleLoad() {
805 if (!this._localeBundleRunning)
809 if (!this._localeBundle) {
811 this._localeBundle = Cc[
"@songbirdnest.com/Songbird/Bundle;1"]
812 .createInstance(Ci.sbIBundle);
813 this._localeBundle.bundleId =
"locales";
814 this._localeBundle.bundleURL =
815 Application.prefs.getValue(
"songbird.url.locales",
"default");
816 this._localeBundle.addBundleDataListener(
this);
820 this._localeBundle.retrieveBundleData
821 (this._cfg.localeBundleDataLoadTimeout);
824 Components.utils.reportError(ex);
827 this._localeBundleDataLoadComplete =
true;
828 this._localeBundleDataLoadSucceeded =
false;
838 _localeBundleLoadCancel:
839 function firstRunEULASvc__localeBundleLoadCancel() {
842 if (this._localeBundle)
843 this._localeBundle.removeBundleDataListener(
this);
857 _perfInitialize:
function firstRunEULASvc__perfInitialize() {
859 this._perfTest =
window.arguments[0].perfTest;
868 var timingService = Cc[
"@songbirdnest.com/Songbird/TimingService;1"]
869 .getService(Ci.sbITimingService);
870 timingService.startPerfTimer(
"CSPerfEULA");
871 timingService.stopPerfTimer(
"CSPerfEULA");
877 if (this._perfTest) {
878 var acceptCheckboxElem = this._getElement(
"accept_checkbox");
879 acceptCheckboxElem.checked =
true;
895 _update:
function firstRunEULASvc__update() {
897 if (this._wizardElem.currentPage !=
this._wizardPageElem)
902 var eulaAccepted =
Application.prefs.getValue(
"songbird.eulacheck",
false);
903 if (eulaAccepted || this._perfTest) {
909 this._localeUpdate();
913 var acceptCheckboxElem = this._getElement(
"accept_checkbox");
914 this._wizardElem.canAdvance = acceptCheckboxElem.checked;
923 _advance:
function firstRunEULASvc__advance() {
925 if (this._wizardElem.currentPage ==
this._wizardPageElem) {
926 this._wizardElem.canAdvance =
true;
927 this._wizardElem.advance();
941 _getElement:
function firstRunEULASvc__getElement(aElementID) {
942 return document.getAnonymousElementByAttribute(this._widget,
function SBFormattedString(aKey, aParams, aDefault, aStringBundle)
function DOMEventListenerSet()
function SBString(aKey, aDefault, aStringBundle)
DataRemote prototype constructor
function firstRunEULASvc(aWidget)
dataSBGenres SBProperties tag
_getSelectedPageStyle s i