fixes bug 329634 "No apparent way to Reload Live Bookmark (or update livemarks)" patch by pamg, r=annie, sr=beng

This commit is contained in:
darin%meer.net 2006-04-04 00:32:33 +00:00
Родитель fecbcf26d6
Коммит 859d5467e5
8 изменённых файлов: 132 добавлений и 54 удалений

Просмотреть файл

@ -68,6 +68,7 @@
<commandset type="container|feed" readonly="true">
<command id="placesCmd_reload"
label="&cmd.reload.label;" accesskey="&cmd.reload.accesskey;"
oncommand="PlacesController.reloadSelectedLivemarks();"
disabled="true"/>
</commandset>
</commandset>

Просмотреть файл

@ -1,4 +1,4 @@
//* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* -*- 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
*
@ -619,7 +619,18 @@ var PlacesController = {
return asContainer(node).remoteContainerType != "";
return false;
},
/**
* Determines whether a ResultNode is a remote container registered by the livemark service.
* @param node
* A NavHistory Result Node
* @returns true if the node is a livemark container item
*/
nodeIsLivemarkContainer: function PC_nodeIsLivemarkContainer(node) {
return (this.nodeIsRemoteContainer(node) &&
asContainer(node).remoteContainerType == "@mozilla.org/browser/livemark-service;1");
},
/**
* Updates undo/redo commands.
*/
@ -952,23 +963,25 @@ var PlacesController = {
if (selectedNode.uri.indexOf("livemark%2F") != -1) {
isLivemarkItem = true;
command.setAttribute("label", strings.getString("livemarkReloadAll"));
}
else if (this.nodeIsURI(selectedNode)) {
var uri = this._uri(selectedNode.uri);
isLivemarkItem =
this.annotations.hasAnnotation(uri, "livemark/bookmarkFeedURI");
if (isLivemarkItem && selectedNode.parent)
var name = selectedNode.parent.title;
if (!isLivemarkItem && this.nodeIsFolder(selectedNode)) {
var folderId = asFolder(selectedNode).folderId;
uri = this.bookmarks.getFolderURI(folderId);
isLivemarkItem = this.annotations.hasAnnotation(uri, "livemark/feedURI");
name = selectedNode.title;
}
command.setAttribute("label",
strings.getFormattedString("livemarkReloadOne", [name]));
}
else {
var name;
if (this.nodeIsLivemarkContainer(selectedNode)) {
isLivemarkItem = true;
name = selectedNode.title;
}
else if (this.nodeIsURI(selectedNode)) {
var uri = this._uri(selectedNode.uri);
isLivemarkItem = this.annotations.hasAnnotation(uri, "livemark/bookmarkFeedURI");
if (isLivemarkItem)
name = selectedNode.parent.title;
}
if (isLivemarkItem)
command.setAttribute("label", strings.getFormattedString("livemarkReloadOne", [name]));
}
}
if (!isLivemarkItem)
command.setAttribute("label", strings.getString("livemarkReload"));
@ -1243,6 +1256,35 @@ var PlacesController = {
changeBookmarkURI: function PC_changeBookmarkProperties(oldURI, newURI) {
this.bookmarks.changeBookmarkURI(oldURI, newURI);
},
/**
*
* Reloads the livemarks associated with the selection. For the "Subscriptions"
* folder, reloads all livemarks; for a livemark folder, reloads its children;
* for a single livemark, reloads its siblings (the children of its parent).
*/
reloadSelectedLivemarks: function PC_reloadSelectedLivemarks() {
var selectedNode = this._activeView.selectedNode;
if (this._activeView.hasSingleSelection) {
if (selectedNode.uri.indexOf("livemark%2F") != -1) {
this.livemarks.reloadAllLivemarks();
}
else {
var folder = null;
if (this.nodeIsLivemarkContainer(selectedNode)) {
folder = asFolder(selectedNode);
}
else if (this.nodeIsURI(selectedNode)) {
var uri = this._uri(selectedNode.uri);
var isLivemarkItem = this.annotations.hasAnnotation(uri, "livemark/bookmarkFeedURI");
if (isLivemarkItem)
folder = asFolder(selectedNode.parent);
}
if (folder)
this.livemarks.reloadLivemarkFolder(folder.folderId);
}
}
},
/**
* Gets the current active browser window.

Просмотреть файл

@ -187,20 +187,18 @@
element.setAttribute("container", "true");
element.setAttribute("label", child.title);
if (PlacesController.nodeIsRemoteContainer(child)) {
if (asContainer(child).remoteContainerType == "@mozilla.org/browser/livemark-service;1") {
element.setAttribute("livemark", "true");
var folder = asFolder(child).folderId;
var bms =
Cc["@mozilla.org/browser/nav-bookmarks-service;1"].
getService(Ci.nsINavBookmarksService);
var folderURI = bms.getFolderURI(folder);
var anno =
Cc["@mozilla.org/browser/annotation-service;1"].
getService(Ci.nsIAnnotationService);
var siteURI = anno.getAnnotationString(folderURI, "livemark/siteURI");
element.setAttribute("siteURI", siteURI);
}
if (PlacesController.nodeIsLivemarkContainer(child)) {
element.setAttribute("livemark", "true");
var folder = asFolder(child).folderId;
var bms =
Cc["@mozilla.org/browser/nav-bookmarks-service;1"].
getService(Ci.nsINavBookmarksService);
var folderURI = bms.getFolderURI(folder);
var anno =
Cc["@mozilla.org/browser/annotation-service;1"].
getService(Ci.nsIAnnotationService);
var siteURI = anno.getAnnotationString(folderURI, "livemark/siteURI");
element.setAttribute("siteURI", siteURI);
}
var popup = document.createElementNS(XULNS, "menupopup");

Просмотреть файл

@ -125,17 +125,15 @@
button = document.createElementNS(XULNS, "toolbarbutton");
button.setAttribute("type", "menu");
button.setAttribute("container", "true");
if (PlacesController.nodeIsRemoteContainer(child)) {
if (asContainer(child).remoteContainerType == "@mozilla.org/browser/livemark-service;1") {
button.setAttribute("livemark", "true");
var folder = asFolder(child).folderId;
var folderURI = this._bms.getFolderURI(folder);
var anno =
Cc["@mozilla.org/browser/annotation-service;1"].
getService(Ci.nsIAnnotationService);
var siteURI = anno.getAnnotationString(folderURI, "livemark/siteURI");
button.setAttribute("siteURI", siteURI);
}
if (PlacesController.nodeIsLivemarkContainer(child)) {
button.setAttribute("livemark", "true");
var folder = asFolder(child).folderId;
var folderURI = this._bms.getFolderURI(folder);
var anno =
Cc["@mozilla.org/browser/annotation-service;1"].
getService(Ci.nsIAnnotationService);
var siteURI = anno.getAnnotationString(folderURI, "livemark/siteURI");
button.setAttribute("siteURI", siteURI);
}
var popup = document.createElementNS(XULNS, "menupopup");
popup.setAttribute("type", "places");

Просмотреть файл

@ -41,7 +41,7 @@
interface nsIURI;
[scriptable, uuid(b1257934-86cf-4143-8386-734ac352b6ba)]
[scriptable, uuid(5dd95266-3ddd-460d-8f80-092664d88a36)]
interface nsILivemarkService : nsIRemoteContainer
{
/**
@ -58,4 +58,15 @@ interface nsILivemarkService : nsIRemoteContainer
in nsIURI siteURI,
in nsIURI feedURI,
in PRInt32 index);
/**
* Reloads all livemark subscriptions, whether or not they've expired.
*/
void reloadAllLivemarks();
/**
* Reloads the livemark with this folder ID, whether or not it's expired.
* @param folderID The ID of the folder to be reloaded
*/
void reloadLivemarkFolder(in PRInt32 folderID);
};

Просмотреть файл

@ -853,10 +853,12 @@ nsLivemarkLoadListener::IsLinkValid(const PRUnichar *aURI)
/*
* Update the child elements of a livemark; take care of cache checking,
* channel setup and firing off the async load and parse.
* channel setup and firing off the async load and parse. If aForceUpdate
* is true, the livemark will be updated whether or not it has expired; this
* is intended for user "Update Livemark" commands.
*/
nsresult
nsLivemarkService::UpdateLivemarkChildren(PRInt32 aLivemarkIndex)
nsLivemarkService::UpdateLivemarkChildren(PRInt32 aLivemarkIndex, PRBool aForceUpdate)
{
nsresult rv;
@ -870,17 +872,21 @@ nsLivemarkService::UpdateLivemarkChildren(PRInt32 aLivemarkIndex)
mLivemarks[aLivemarkIndex]->locked = PR_TRUE;
// Check the TTL/expiration on this. If there isn't one,
// then we assume it's never been loaded.
// then we assume it's never been loaded. We perform this
// check even when the update is being forced, in case the
// livemark has somehow never been loaded.
PRTime exprTime;
rv = mAnnotationService->GetAnnotationInt64(mLivemarks[aLivemarkIndex]->feedURI,
NS_LITERAL_CSTRING(LMANNO_EXPIRATION),
&exprTime);
if (rv == NS_OK) {
PRTime nowTime = PR_Now();
if (LL_CMP(exprTime, >, nowTime)) {
// No need to refresh yet.
mLivemarks[aLivemarkIndex]->locked = PR_FALSE;
return rv;
if (! aForceUpdate) {
PRTime nowTime = PR_Now();
if (LL_CMP(exprTime, >, nowTime)) {
// No need to refresh yet.
mLivemarks[aLivemarkIndex]->locked = PR_FALSE;
return rv;
}
}
} else {
// This livemark has never been loaded, since it has no expire time.

Просмотреть файл

@ -316,7 +316,7 @@ nsLivemarkService::CreateLivemark(PRInt64 aFolder,
NS_ENSURE_TRUE(info, NS_ERROR_OUT_OF_MEMORY);
NS_ENSURE_TRUE(mLivemarks.AppendElement(info), NS_ERROR_OUT_OF_MEMORY);
UpdateLivemarkChildren(mLivemarks.Length() - 1);
UpdateLivemarkChildren(mLivemarks.Length() - 1, PR_FALSE);
return NS_OK;
}
@ -481,7 +481,7 @@ nsLivemarkService::FireTimer(nsITimer* aTimer, void* aClosure)
// Go through all of the livemarks, and check if each needs to be updated.
for (PRUint32 i = 0; i < lmks->mLivemarks.Length(); i++) {
lmks->UpdateLivemarkChildren(i);
lmks->UpdateLivemarkChildren(i, PR_FALSE);
}
}
@ -584,3 +584,25 @@ nsLivemarkService::InsertLivemarkFailedItem(PRInt64 aFolder)
rv = bookmarks->SetItemTitle(failedURI, mLivemarkFailed);
return rv;
}
NS_IMETHODIMP
nsLivemarkService::ReloadAllLivemarks()
{
for (PRUint32 i = 0; i < mLivemarks.Length(); i++) {
UpdateLivemarkChildren(i, PR_TRUE);
}
return NS_OK;
}
NS_IMETHODIMP
nsLivemarkService::ReloadLivemarkFolder(PRInt32 aFolderId)
{
nsresult rv = NS_OK;
for (PRUint32 i = 0; i < mLivemarks.Length(); i++) {
if (mLivemarks[i]->folderId == aFolderId) {
rv = UpdateLivemarkChildren(i, PR_TRUE);
break;
}
}
return rv;
}

Просмотреть файл

@ -118,5 +118,5 @@ private:
// Livemarks are updated on a timer.
nsCOMPtr<nsITimer> mTimer;
static void FireTimer(nsITimer* aTimer, void* aClosure);
nsresult UpdateLivemarkChildren(PRInt32 aLivemarkIndex);
nsresult UpdateLivemarkChildren(PRInt32 aLivemarkIndex, PRBool aForceUpdate);
};