diff --git a/browser/components/migration/content/migration.js b/browser/components/migration/content/migration.js index 7894e1ac1db..1d5372e9790 100644 --- a/browser/components/migration/content/migration.js +++ b/browser/components/migration/content/migration.js @@ -54,14 +54,14 @@ var MigrationWizard = { os.addObserver(this, "Migration:ItemBeforeMigrate", false); os.addObserver(this, "Migration:ItemAfterMigrate", false); os.addObserver(this, "Migration:Ended", false); - + this._wiz = document.documentElement; if ("arguments" in window && window.arguments.length > 1) { this._source = window.arguments[0]; this._migrator = window.arguments[1].QueryInterface(kIMig); this._autoMigrate = window.arguments[2].QueryInterface(kIPStartup); - + if (this._autoMigrate) { // Show the "nothing" option in the automigrate case to provide an // easily identifiable way to avoid migration and create a new profile. @@ -69,10 +69,10 @@ var MigrationWizard = { nothing.hidden = false; } } - + this.onImportSourcePageShow(); }, - + uninit: function () { var os = Components.classes["@mozilla.org/observer-service;1"].getService(Components.interfaces.nsIObserverService); @@ -81,7 +81,7 @@ var MigrationWizard = { os.removeObserver(this, "Migration:ItemAfterMigrate"); os.removeObserver(this, "Migration:Ended"); }, - + // 1 - Import Source onImportSourcePageShow: function () { @@ -167,7 +167,13 @@ var MigrationWizard = { if (this._migrator.sourceHasMultipleProfiles) this._wiz.currentPage.next = "selectProfile"; else { - this._wiz.currentPage.next = (this._autoMigrate || this._bookmarks) ? "migrating" : "importItems"; + if (this._autoMigrate) + this._wiz.currentPage.next = "homePageImport"; + else if (this._bookmarks) + this._wiz.currentPage.next = "migrating" + else + this._wiz.currentPage.next = "importItems"; + var sourceProfiles = this._migrator.sourceProfiles; if (sourceProfiles && sourceProfiles.Count() == 1) { var profileName = sourceProfiles.QueryElementAt(0, Components.interfaces.nsISupportsString); @@ -215,8 +221,10 @@ var MigrationWizard = { this._selectedProfile = profiles.selectedItem.id; // If we're automigrating or just doing bookmarks don't show the item selection page - if (this._autoMigrate || this._bookmarks) - this._wiz.currentPage.next = "migrating"; + if (this._autoMigrate) + this._wiz.currentPage.next = "homePageImport"; + else if (this._bookmarks) + this._wiz.currentPage.next = "migrating" }, // 3 - ImportItems @@ -274,8 +282,117 @@ var MigrationWizard = { this._wiz.canAdvance = oneChecked; }, - - // 4 - Migrating + + // 4 - Home Page Selection + onHomePageMigrationPageShow: function () + { + // only want this on the first run + if (!this._autoMigrate) + this._wiz.advance(); + + var numberOfChoices = 0; + try { + var bundle = document.getElementById("browserconfigBundle"); + var pageTitle = bundle.getString("homePageMigrationPageTitle"); + var pageDesc = bundle.getString("homePageMigrationDescription"); + var startPages = bundle.getString("homePageOptionCount"); + } catch(ex) {} + + if (!pageTitle || !pageDesc || !startPages || startPages < 1) + this._wiz.advance(); + + document.getElementById("homePageImport").setAttribute("label", pageTitle); + document.getElementById("homePageImportDesc").setAttribute("value", pageDesc); + + this._wiz._adjustWizardHeader(); + + var singleStart = document.getElementById("homePageSingleStart"); + var i, mainStr, radioItem, radioItemId, radioItemLabel, radioItemValue; + if (startPages > 1) { + numberOfChoices += startPages; + + this._multipleStartOptions = true; + mainStr = bundle.getString("homePageMultipleStartMain"); + var multipleStart = document.getElementById("homePageMultipleStartMain"); + multipleStart.setAttribute("label", mainStr); + multipleStart.hidden = false; + multipleStart.setAttribute("selected", true); + singleStart.hidden = true; + + for (i = 1; i <= startPages; i++) { + radioItemId = "homePageMultipleStart" + i; + radioItemLabel = bundle.getString(radioItemId + "Label"); + radioItemValue = bundle.getString(radioItemId + "URL"); + radioItem = document.getElementById(radioItemId); + radioItem.hidden = false; + radioItem.setAttribute("label", radioItemLabel); + radioItem.setAttribute("value", radioItemValue); + } + } + else { + numberOfChoices++; + mainStr = bundle.getString("homePageSingleStartMain"); + radioItemValue = bundle.getString("homePageSingleStartMainURL"); + singleStart.setAttribute("label", mainStr); + singleStart.setAttribute("value", radioItemValue); + singleStart.setAttribute("selected", true); + } + + var source = null; + switch (this._source) { + case "ie": + case "macie": + source = "sourceNameIE"; + break; + case "opera": + source = "sourceNameOpera"; + break; + case "dogbert": + source = "sourceNameDogbert"; + break; + case "safari": + source = "sourceNameSafari"; + break; + case "seamonkey": + source = "sourceNameSeamonkey"; + break; + } + + // semi-wallpaper for crash when multiple profiles exist, since we haven't initialized mSourceProfile in places + this._migrator.getMigrateData(this._selectedProfile, this._autoMigrate); + + var oldHomePageURL = this._migrator.sourceHomePageURL; + + if (oldHomePageURL && source) { + numberOfChoices++; + var bundle2 = document.getElementById("bundle"); + var appName = bundle2.getString(source); + var oldHomePageLabel = bundle.getFormattedString("homePageImport", + [appName]); + var oldHomePage = document.getElementById("oldHomePage"); + oldHomePage.setAttribute("label", oldHomePageLabel); + oldHomePage.setAttribute("value", oldHomePageURL); + oldHomePage.removeAttribute("hidden"); + } + + // if we don't have at least two options, just advance + if (numberOfChoices < 2) + this._wiz.advance(); + }, + + onHomePageMigrationPageAdvanced: function () + { + // we might not have a selectedItem if we're in fallback mode + try { + var radioGroup = document.getElementById("homePageRadiogroup"); + if (radioGroup.selectedItem.id == "homePageMultipleStartMain") + radioGroup = document.getElementById("multipleStartRadiogroup"); + + this._newHomePage = radioGroup.selectedItem.value; + } catch(ex) {} + }, + + // 5 - Migrating onMigratingPageShow: function () { this._wiz.getButton("cancel").disabled = true; @@ -298,7 +415,7 @@ var MigrationWizard = { { aOuter._migrator.migrate(aOuter._itemsFlags, aOuter._autoMigrate, aOuter._selectedProfile); }, - + _listItems: function (aID) { var items = document.getElementById(aID); @@ -343,9 +460,40 @@ var MigrationWizard = { break; case "Migration:Ended": if (this._autoMigrate) { + if (this._newHomePage) { + try { + var prefSvc2 = Components.classes["@mozilla.org/preferences-service;1"] + .getService(Components.interfaces.nsIPrefService); + + const nsIDirectoryServiceContractID = "@mozilla.org/file/directory_service;1"; + const nsIProperties = Components.interfaces.nsIProperties; + var directoryService = Components.classes[nsIDirectoryServiceContractID] + .getService(nsIProperties); + var prefFile = directoryService.get("ProfDS", Components.interfaces.nsIFile); + prefFile.append("prefs.js"); + + prefSvc2.resetPrefs(); + prefSvc2.readUserPrefs(prefFile); + + // set homepage properly + var prefSvc = Components.classes["@mozilla.org/preferences-service;1"] + .getService(Components.interfaces.nsIPrefBranch); + var str = Components.classes["@mozilla.org/supports-string;1"] + .createInstance(Components.interfaces.nsISupportsString); + str.data = this._newHomePage; + prefSvc.setComplexValue("browser.startup.homepage", + Components.interfaces.nsISupportsString, str); + prefSvc2.savePrefFile(prefFile); + + } catch(ex) { + dump(ex); + } + } + // We're done now. this._wiz.canAdvance = true; this._wiz.advance(); + setTimeout(close, 5000); } else { @@ -356,7 +504,7 @@ var MigrationWizard = { break; } }, - + onDonePageShow: function () { this._wiz.getButton("cancel").disabled = true; diff --git a/browser/components/migration/content/migration.xul b/browser/components/migration/content/migration.xul index 6959a74d56d..0f84a12688c 100644 --- a/browser/components/migration/content/migration.xul +++ b/browser/components/migration/content/migration.xul @@ -1,4 +1,4 @@ - + # ***** BEGIN LICENSE BLOCK ***** # Version: MPL 1.1/GPL 2.0/LGPL 2.1 # @@ -38,7 +38,7 @@ - +