diff --git a/browser/app/profile/firefox.js b/browser/app/profile/firefox.js index d68ebacb923..56337d7306c 100644 --- a/browser/app/profile/firefox.js +++ b/browser/app/profile/firefox.js @@ -455,18 +455,15 @@ pref("browser.send_pings", true); #ifdef MOZ_FEEDS // XXXben This is just here for demo purposes until web registration works! // XXXben Needs Localization! -pref("browser.contentHandlers.types.0.title", "Netvibes"); -pref("browser.contentHandlers.types.0.uri", "http://www.netvibes.com/subscribe.php?url=%s"); +pref("browser.contentHandlers.types.0.title", "Bloglines"); +pref("browser.contentHandlers.types.0.uri", "http://www.bloglines.com/login?r=/sub/%s"); pref("browser.contentHandlers.types.0.type", "application/vnd.mozilla.maybe.feed"); -pref("browser.contentHandlers.types.1.title", "My Yahoo"); -pref("browser.contentHandlers.types.1.uri", "http://add.my.yahoo.com/rss?url=%s"); +pref("browser.contentHandlers.types.1.title", "iGoogle/Google Reader"); +pref("browser.contentHandlers.types.1.uri", "http://fusion.google.com/add?feedurl=%s"); pref("browser.contentHandlers.types.1.type", "application/vnd.mozilla.maybe.feed"); -pref("browser.contentHandlers.types.2.title", "Bloglines"); -pref("browser.contentHandlers.types.2.uri", "http://www.bloglines.com/login?r=/sub/%s"); +pref("browser.contentHandlers.types.2.title", "My Yahoo"); +pref("browser.contentHandlers.types.2.uri", "http://add.my.yahoo.com/rss?url=%s"); pref("browser.contentHandlers.types.2.type", "application/vnd.mozilla.maybe.feed"); -pref("browser.contentHandlers.types.3.title", "iGoogle/Google Reader"); -pref("browser.contentHandlers.types.3.uri", "http://fusion.google.com/add?feedurl=%s"); -pref("browser.contentHandlers.types.3.type", "application/vnd.mozilla.maybe.feed"); #endif #ifdef MOZ_SAFE_BROWSING diff --git a/browser/components/feeds/content/addFeedReader.js b/browser/components/feeds/content/addFeedReader.js new file mode 100644 index 00000000000..b3d5e34fb7d --- /dev/null +++ b/browser/components/feeds/content/addFeedReader.js @@ -0,0 +1,150 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* ***** BEGIN LICENSE BLOCK ***** + * Version: MPL 1.1/GPL 2.0/LGPL 2.1 + * + * The contents of this file are subject to the Mozilla Public License Version + * 1.1 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * Software distributed under the License is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License + * for the specific language governing rights and limitations under the + * License. + * + * The Original Code is the Add Feed Reader Dialog. + * + * The Initial Developer of the Original Code is Google Inc. + * Portions created by the Initial Developer are Copyright (C) 2006 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * Ben Goodger + * + * Alternatively, the contents of this file may be used under the terms of + * either the GNU General Public License Version 2 or later (the "GPL"), or + * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), + * in which case the provisions of the GPL or the LGPL are applicable instead + * of those above. If you wish to allow use of your version of this file only + * under the terms of either the GPL or the LGPL, and not to allow others to + * use your version of this file under the terms of the MPL, indicate your + * decision by deleting the provisions above and replace them with the notice + * and other provisions required by the GPL or the LGPL. If you do not delete + * the provisions above, a recipient may use your version of this file under + * the terms of any one of the MPL, the GPL or the LGPL. + * + * ***** END LICENSE BLOCK ***** */ + +const Cc = Components.classes; +const Ci = Components.interfaces; +const Cr = Components.results; + +function LOG(str) { + dump("*** " + str + "\n"); +} + +const TYPE_MAYBE_FEED = "application/vnd.mozilla.maybe.feed"; +const PREF_SELECTED_WEB = "browser.feeds.handlers.webservice"; + +const TYPETYPE_MIME = 1; +const TYPETYPE_PROTOCOL = 2; + +// +// window.arguments: +// +// 0 nsIDialogParamBlock containing user decision result +// 1 string uri of the service being registered +// 2 string title of the service being registered +// 3 string type of service being registered for +// 4 integer 1 = content type 2 = protocol + + +var AddFeedReader = { + _result: null, + _uri: null, + _title: null, + _type: null, + _typeType: null, + + + init: function AFR_init() { + this._result = window.arguments[0].QueryInterface(Ci.nsIDialogParamBlock); + this._uri = window.arguments[1]; + this._title = window.arguments[2]; + this._type = window.arguments[3]; + this._typeType = window.arguments[4]; + + var strings = document.getElementById("strings"); + var dlg = document.documentElement; + var addQuestion = document.getElementById("addQuestion"); + + var wccr = + Cc["@mozilla.org/web-content-handler-registrar;1"]. + getService(Ci.nsIWebContentConverterService); + var handler = + wccr.getWebContentHandlerByURI(this._type, this._uri); + + var key = handler != null ? "handlerRegistered" : "addHandler"; + var message = strings.getFormattedString(key, [this._title]); + addQuestion.setAttribute("value", message); + + this._updateAddAsDefaultCheckbox(); + + if (this._type != TYPE_MAYBE_FEED && this._typeType == TYPETYPE_MIME) { + var mimeService = + Cc["@mozilla.org/uriloader/external-helper-app-service;1"]. + getService(Ci.nsIMIMEService); + var ext = mimeService.getPrimaryExtension(this._type, null); + var imageBox = document.getElementById("imageBox"); + imageBox.style.backgroundImage = "url('moz-icon://goat." + ext + "?size=32');"; + } + + var site = document.getElementById("site"); + site.value = this._uri; + + if (handler) + dlg.getButton("accept").focus(); + else { + dlg.getButton("accept").label = strings.getString("addHandlerYes"); + dlg.getButton("cancel").label = strings.getString("addHandlerNo"); + dlg.getButton("cancel").focus(); + } + }, + + _updateAddAsDefaultCheckbox: function AFR__updateAddAsDefaultCheckbox() { + var addAsDefaultCheckbox = + document.getElementById("addAsDefaultCheckbox"); + if (this._type != TYPE_MAYBE_FEED) { + addAsDefaultCheckbox.hidden = true; + return; + } + + try { + var ps = + Cc["@mozilla.org/preferences-service;1"]. + getService(Ci.nsIPrefBranch); + var webHandler = + ps.getComplexValue(PREF_SELECTED_WEB, Ci.nsIPrefLocalizedString); + if (webHandler.data == window.arguments[0]) { + addAsDefaultCheckbox.checked = true; + addAsDefaultCheckbox.disabled = true; + } + } + catch (e) { + } + }, + + add: function AFR_add() { + // Used to tell the WCCR that the user chose to add the handler (rather + // than canceling) and whether or not they made it their default handler. + const PARAM_SHOULD_ADD_HANDLER = 0; + const PARAM_SHOULD_MAKE_DEFAULT = 1; + + this._result.SetInt(PARAM_SHOULD_ADD_HANDLER, 1); + if (this._type == TYPE_MAYBE_FEED) { + var addAsDefaultCheckbox = document.getElementById("addAsDefaultCheckbox"); + this._result.SetInt(PARAM_SHOULD_MAKE_DEFAULT, + addAsDefaultCheckbox.checked ? 1 : 0); + } + } +}; \ No newline at end of file diff --git a/browser/components/feeds/content/addFeedReader.xul b/browser/components/feeds/content/addFeedReader.xul new file mode 100644 index 00000000000..e69de29bb2d diff --git a/browser/components/feeds/content/options.js b/browser/components/feeds/content/options.js index a129b948037..c058b6e0c8c 100644 --- a/browser/components/feeds/content/options.js +++ b/browser/components/feeds/content/options.js @@ -65,10 +65,55 @@ var SubscriptionOptions = { catch (e) { } + this._initClientApp(); + this.populateWebHandlers(); + + var handler = "bookmarks"; + try { + handler = prefs.getCharPref(PREF_SELECTED_HANDLER); + } + catch (e) { + } + + var reader = document.getElementById("reader"); + reader.value = handler != "bookmarks" ? "reader" : "bookmarks"; + + var readers = document.getElementById("readers"); + if (handler == "web") { + try { + readers.value = prefs.getCharPref(PREF_SELECTED_WEB); + } + catch (e) { + readers.selectedIndex = 1; + } + } + else if (handler == "client") + readers.selectedIndex = 0; + + if ("arguments" in window && window.arguments[0] == "subscribe") { + var strings = document.getElementById("bundle"); + var okButton = document.documentElement.getButton("accept"); + okButton.label = strings.getString("subscribeNow"); + document.title = strings.getString("subscribeTitle"); + + okButton.className += " feedSubscribeButton"; + } + + if (handler != "bookmarks") + readers.focus(); + }, + + _initClientApp: function SO__initClientApp() { var clientApp = document.getElementById("clientApp"); try { + var prefs = + Cc["@mozilla.org/preferences-service;1"]. + getService(Ci.nsIPrefBranch); clientApp.file = prefs.getComplexValue(PREF_SELECTED_APP, Ci.nsILocalFile); + var application = document.getElementById("applicationName"); + application.setAttribute("label", clientApp.label); + application.setAttribute("image", clientApp.image); } catch (e) { // No specified file, look on the system for one @@ -82,7 +127,8 @@ var SubscriptionOptions = { var path = regKey.readStringValue(""); if (path.charAt(0) == "\"") { // Everything inside the quotes - path = path.substr(1, path.lastIndexOf("\"") - 1); + path = path.substr(1); + path = path.substr(0, path.indexOf("\"")); } else { // Everything up to the first space @@ -92,82 +138,50 @@ var SubscriptionOptions = { Cc["@mozilla.org/file/local;1"].createInstance(Ci.nsILocalFile); file.initWithPath(path); clientApp.file = file; + var application = document.getElementById("applicationName"); + application.setAttribute("label", clientApp.label); + application.setAttribute("image", clientApp.image); } catch (e) { LOG("SubscriptionOptions.init: No feed: handler registered on system"); } #endif } - - var wsp = document.getElementById("webServicePopup"); - this.populateWebHandlers(wsp); - if (!document.getElementById("noneItem")) { - // If there are any web handlers installed, this option should - // be enabled for selection. - var readerWebOption = document.getElementById("readerWeb"); - readerWebOption.removeAttribute("disabled"); - } - - var webService = document.getElementById("webService"); - try { - webService.value = prefs.getCharPref(PREF_SELECTED_WEB); - } - catch (e) { - webService.selectedIndex = 0; - } - - var reader = document.getElementById("reader"); - try { - reader.value = prefs.getCharPref(PREF_SELECTED_HANDLER); - } - catch (e) { - reader.value = "bookmarks"; - } }, - populateWebHandlers: function SO_populateWebHandlers(popup) { + readerTypeChanged: function SO_readerTypeChanged() { + var reader = document.getElementById("reader"); + var chooseClientApp = document.getElementById("chooseClientApp"); + var readers = document.getElementById("readers"); + readers.disabled = chooseClientApp.disabled = + reader.value == "bookmarks"; + }, + + populateWebHandlers: function SO_populateWebHandlers() { var wccr = Cc["@mozilla.org/web-content-handler-registrar;1"]. - getService(Ci.nsIWebContentConverterRegistrar); + getService(Ci.nsIWebContentConverterService); var handlers = wccr.getContentHandlers(TYPE_MAYBE_FEED, {}); if (handlers.length == 0) return; - - while (popup.hasChildNodes()) - popup.removeChild(popup.firstChild); + + var appRow = document.getElementById("application"); + while (appRow.nextSibling) + appRow.parentNode.removeChild(appRow.parentNode.lastChild); + var ios = Cc["@mozilla.org/network/io-service;1"]. getService(Ci.nsIIOService); for (var i = 0; i < handlers.length; ++i) { - var menuitem = document.createElementNS(XUL_NS, "menuitem"); - menuitem.setAttribute("label", handlers[i].name); - menuitem.setAttribute("value", handlers[i].uri); + var row = document.createElementNS(XUL_NS, "listitem"); + row.className = "listitem-iconic"; + row.setAttribute("label", handlers[i].name); + row.setAttribute("value", handlers[i].uri); var uri = ios.newURI(handlers[i].uri, null, null); - menuitem.setAttribute("src", uri.prePath + "/favicon.ico"); + row.setAttribute("image", uri.prePath + "/favicon.ico"); - popup.appendChild(menuitem); - } - }, - - selectionChanged: function SO_selectionChanged() { - var reader = document.getElementById("reader"); - var clientApp = document.getElementById("clientApp"); - var chooseClientApp = document.getElementById("chooseClientApp"); - var webService = document.getElementById("webService"); - switch (reader.value) { - case "client": - webService.disabled = true; - clientApp.disabled = chooseClientApp.disabled = false; - break; - case "web": - webService.disabled = false; - clientApp.disabled = chooseClientApp.disabled = true; - break; - case "bookmarks": - webService.disabled = true; - clientApp.disabled = chooseClientApp.disabled = true; - break; + appRow.parentNode.appendChild(row); } }, @@ -177,8 +191,20 @@ var SubscriptionOptions = { fp.init(window, title, Ci.nsIFilePicker.modeOpen); fp.appendFilters(Ci.nsIFilePicker.filterApps); if (fp.show() == Ci.nsIFilePicker.returnOK && fp.file) { + // XXXben - we need to compare this with the running instance executable + // just don't know how to do that via script... + if (fp.file.leafName == "firefox.exe") + return false; + var clientApp = document.getElementById("clientApp"); clientApp.file = fp.file; + var application = document.getElementById("applicationName"); + application.setAttribute("label", clientApp.label); + application.setAttribute("image", clientApp.image); + + var okButton = document.documentElement.getButton("accept"); + okButton.disabled = !clientApp.file.exists(); + return true; } return false; @@ -190,23 +216,28 @@ var SubscriptionOptions = { getService(Ci.nsIPrefBranch); var reader = document.getElementById("reader"); - prefs.setCharPref(PREF_SELECTED_HANDLER, reader.value); + var readers = document.getElementById("readers"); + + var selectedHandler = "bookmarks"; + if (reader.value != "bookmarks") + selectedHandler = readers.selectedIndex == 0 ? "client" : "web"; + prefs.setCharPref(PREF_SELECTED_HANDLER, selectedHandler); var clientApp = document.getElementById("clientApp"); if (clientApp.file) prefs.setComplexValue(PREF_SELECTED_APP, Ci.nsILocalFile, clientApp.file); - var webService = document.getElementById("webService"); - prefs.setCharPref(PREF_SELECTED_WEB, webService.value); + if (selectedHandler == "web") + prefs.setCharPref(PREF_SELECTED_WEB, readers.selectedItem.value); var autoHandle = document.getElementById("autoHandle"); prefs.setBoolPref(PREF_SKIP_PREVIEW_PAGE, autoHandle.checked); - if (reader.value == "web") { + if (selectedHandler == "web") { var wccr = Cc["@mozilla.org/web-content-handler-registrar;1"]. - getService(Ci.nsIWebContentConverterRegistrar); + getService(Ci.nsIWebContentConverterService); if (autoHandle.checked) { var handler = wccr.getWebContentHandlerByURI(TYPE_MAYBE_FEED, webService.value); @@ -217,6 +248,16 @@ var SubscriptionOptions = { wccr.setAutoHandler(TYPE_MAYBE_FEED, null); } + try { + var params = window.arguments[1].QueryInterface(Ci.nsIDialogParamBlock); + // Used to tell the preview page that the user chose to subscribe with + // a particular reader, and so it should subscribe now. + const PARAM_USER_SUBSCRIBED = 0; + params.SetInt(PARAM_USER_SUBSCRIBED, 1); + } + catch (e) { + } + prefs.QueryInterface(Ci.nsIPrefService); prefs.savePrefFile(null); }, diff --git a/browser/components/feeds/content/options.xul b/browser/components/feeds/content/options.xul index 12cc629065b..3c645ada213 100644 --- a/browser/components/feeds/content/options.xul +++ b/browser/components/feeds/content/options.xul @@ -19,40 +19,40 @@