Bug 352935 - Port over some FeedWriter improvements from bug 350615 to trunk. r=gavin.

git-svn-id: svn://10.0.0.236/trunk@211948 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
mozilla.mano%sent.com 2006-09-18 19:40:55 +00:00
parent 91309c0742
commit 7fac0cfaa4
2 changed files with 41 additions and 43 deletions

View File

@ -17,11 +17,14 @@
<html id="feedHandler"
xmlns="http://www.w3.org/1999/xhtml"
xmlns:xul="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
xmlns:xul="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
xmlns:aaa="http://www.w3.org/2005/07/aaa">
<head>
<title>&feedPage.title;</title>
<link rel="stylesheet" href="chrome://browser/skin/feeds/subscribe.css"
type="text/css" media="all"/>
<link rel="stylesheet"
href="chrome://browser/skin/feeds/subscribe.css"
type="text/css"
media="all"/>
<script type="application/x-javascript"
src="chrome://browser/content/feeds/subscribe.js"/>
</head>
@ -37,7 +40,7 @@
<!-- XXXmano this has to be in one line. Otherwise you would see
how much XUL-in-XHTML sucks, see bug 348830 -->
<div id="feedSubscribeLine"><xul:vbox><xul:hbox align="center"><xul:description>&subscribeUsing;</xul:description><xul:menulist id="handlersMenuList"><xul:menupopup menugenerated="true" id="handlersMenuPopup"><xul:menuitem id="liveBookmarksMenuItem" label="&feedLiveBookmarks;" class="menuitem-iconic" src="chrome://browser/skin/page-livemarks.png" selected="true"/><xul:menuseparator/></xul:menupopup></xul:menulist></xul:hbox><xul:hbox><xul:checkbox id="alwaysUse" checked="false"/></xul:hbox><xul:hbox align="center"><xul:spacer flex="1"/><span><xul:button label="&feedSubscribeNow;" id="subscribeButton"/></span></xul:hbox></xul:vbox></div></div>
<div id="feedSubscribeLine"><xul:vbox><xul:hbox align="center"><xul:description id="subscribeUsingDescription">&subscribeUsing;</xul:description><xul:menulist id="handlersMenuList" aaa:labelledby="subscribeUsingDescription"><xul:menupopup menugenerated="true" id="handlersMenuPopup"><xul:menuitem id="liveBookmarksMenuItem" label="&feedLiveBookmarks;" class="menuitem-iconic" src="chrome://browser/skin/page-livemarks.png" selected="true"/><xul:menuseparator/></xul:menupopup></xul:menulist></xul:hbox><xul:hbox><xul:checkbox id="alwaysUse" checked="false"/></xul:hbox><xul:hbox align="center"><xul:spacer flex="1"/><span><xul:button label="&feedSubscribeNow;" id="subscribeButton"/></span></xul:hbox></xul:vbox></div></div>
</div>

View File

@ -22,6 +22,7 @@
# Ben Goodger <beng@google.com>
# Jeff Walden <jwalden+code@mit.edu>
# Asaf Romano <mozilla.mano@sent.com>
# Robert Sayre <sayrer@gmail.com>
#
# 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
@ -67,7 +68,6 @@ const PREF_SELECTED_APP = "browser.feeds.handlers.application";
const PREF_SELECTED_WEB = "browser.feeds.handlers.webservice";
const PREF_SELECTED_ACTION = "browser.feeds.handler";
const PREF_SELECTED_READER = "browser.feeds.handler.default";
const PREF_SKIP_PREVIEW_PAGE = "browser.feeds.skip_preview_page";
const PREF_SHOW_FIRST_RUN_UI = "browser.feeds.showFirstRunUI";
const FW_CLASSID = Components.ID("{49bb6593-3aff-4eb3-a068-2712c28bd58e}");
@ -335,7 +335,7 @@ FeedWriter.prototype = {
/**
* Get moz-icon url for a file
* @param file
* A nsIFile to look up the name of
* A nsIFile object for which the moz-icon:// is returned
* @returns moz-icon url of the given file as a string
*/
_getFileIconURL: function FW__getFileIconURL(file) {
@ -347,6 +347,20 @@ FeedWriter.prototype = {
return "moz-icon://" + urlSpec + "?size=16";
},
/**
* Helper method to set the selected application and system default
* reader menuitems details from a file object
* @param aMenuItem
* The menuitem on which the attributes should be set
* @param aFile
* The menuitem's associated file
*/
_initMenuItemWithFile: function(aMenuItem, aFile) {
aMenuItem.setAttribute("label", this._getFileDisplayName(aFile));
aMenuItem.setAttribute("src", this._getFileIconURL(aFile));
aMenuItem.wrappedJSObject.file = aFile;
},
/**
* Displays a prompt from which the user may choose a (client) feed reader.
* @return - true if a feed reader was selected, false otherwise.
@ -376,12 +390,7 @@ FeedWriter.prototype = {
#endif
var selectedAppMenuItem =
this._document.getElementById("selectedAppMenuItem");
selectedAppMenuItem.wrappedJSObject.file = selectedApp;
selectedAppMenuItem.setAttribute("label",
this._getFileDisplayName(selectedApp));
selectedAppMenuItem.setAttribute("src",
this._getFileIconURL(selectedApp));
this._initMenuItemWithFile(selectedAppMenuItem, selectedApp);
// Show and select the selected application menuitem
selectedAppMenuItem.wrappedJSObject.hidden = false;
@ -437,9 +446,9 @@ FeedWriter.prototype = {
return;
}
switch(event.type) {
switch (event.type) {
case "command" : {
switch(event.target.id) {
switch (event.target.id) {
case "subscribeButton":
this.subscribe();
break;
@ -456,7 +465,8 @@ FeedWriter.prototype = {
case "click": {
if (event.target.id == "chooseApplicationMenuItem") {
if (!this._chooseClientApp()) {
// Select the (per-prefs) selected handler if no application was selected
// Select the (per-prefs) selected handler if no application was
// selected
this._setSelectedHandler();
}
}
@ -501,12 +511,7 @@ FeedWriter.prototype = {
} catch(ex) { }
if (selectedApp) {
selectedAppMenuItem.file = selectedApp;
selectedAppMenuItem.setAttribute("label",
this._getFileDisplayName(selectedApp));
selectedAppMenuItem.setAttribute("src",
this._getFileIconURL(selectedApp));
this._initMenuItemWithFile(selectedAppMenuItem, selectedApp);
selectedAppMenuItem.wrappedJSObject.hidden = false;
selectedAppMenuItem.doCommand();
@ -550,13 +555,10 @@ FeedWriter.prototype = {
getService(Ci.nsIPrefBranch);
selectedApp = prefs.getComplexValue(PREF_SELECTED_APP,
Ci.nsILocalFile);
if (selectedApp.exists()) {
menuItem.setAttribute("label",
this._getFileDisplayName(selectedApp));
menuItem.setAttribute("src",
this._getFileIconURL(selectedApp));
menuItem.setAttribute("handlerType", "client");
menuItem.wrappedJSObject.file = selectedApp;
this._initMenuItemWithFile(menuItem, selectedApp);
}
else {
// Hide the menuitem if the last selected application doesn't exist
@ -596,13 +598,9 @@ FeedWriter.prototype = {
if (defaultReader.exists()) {
menuItem = this._document.createElementNS(XUL_NS, "menuitem");
menuItem.id = "defaultHandlerMenuItem";
menuItem.className = "menuitem-iconic";
menuItem.setAttribute("label",
this._getFileDisplayName(defaultReader));
menuItem.setAttribute("src",
this._getFileIconURL(defaultReader));
menuItem.className = "menuitem-iconic";
menuItem.setAttribute("handlerType", "client");
menuItem.wrappedJSObject.file = defaultReader;
this._initMenuItemWithFile(menuItem, defaultReader);
// Hide the default reader item if it points to the same application
// as the last-selected application
@ -766,16 +764,13 @@ FeedWriter.prototype = {
_removeFeedFromCache: function FW__removeFeedFromCache() {
if (this._feedURI) {
var feedService =
Cc["@mozilla.org/browser/feeds/result-service;1"].
getService(Ci.nsIFeedResultService);
Cc["@mozilla.org/browser/feeds/result-service;1"].
getService(Ci.nsIFeedResultService);
feedService.removeFeedResult(this._feedURI);
this._feedURI = null;
}
},
/**
* See nsIFeedWriter
*/
subscribe: function FW_subscribe() {
// Subscribe to the feed using the selected handler and save prefs
var prefs =
@ -850,7 +845,7 @@ FeedWriter.prototype = {
else
prefs.setCharPref(PREF_SELECTED_ACTION, "ask");
},
/**
* See nsIObserver
*/
@ -873,7 +868,7 @@ FeedWriter.prototype = {
}
}
},
/**
* See nsIClassInfo
*/
@ -910,14 +905,14 @@ var Module = {
return this;
throw Cr.NS_ERROR_NO_INTERFACE;
},
getClassObject: function M_getClassObject(cm, cid, iid) {
if (!iid.equals(Ci.nsIFactory))
throw Cr.NS_ERROR_NOT_IMPLEMENTED;
if (cid.equals(FW_CLASSID))
return new GenericComponentFactory(FeedWriter);
throw Cr.NS_ERROR_NO_INTERFACE;
},
@ -933,12 +928,12 @@ var Module = {
catman.addCategoryEntry("JavaScript global constructor",
"BrowserFeedWriter", FW_CONTRACTID, true, true);
},
unregisterSelf: function M_unregisterSelf(cm, location, type) {
var cr = cm.QueryInterface(Ci.nsIComponentRegistrar);
cr.unregisterFactoryLocation(FW_CLASSID, location);
},
canUnload: function M_canUnload(cm) {
return true;
}