home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC World 2008 September
/
PCWorld_2008-09_cd.bin
/
komunikace
/
kmeleon
/
K-Meleon1.1.3en-US.exe
/
chrome
/
newsfox.jar
/
content
/
newsfox
/
livemarks.js
< prev
next >
Wrap
Text File
|
2007-08-07
|
9KB
|
317 lines
/* ***** 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 bookmarksHome.
*
* The Initial Developer of the Original Code is
* Jeroen Groenenboom <jagrboom@zonnet.nl>
* Portions created by the Initial Developer are Copyright (C) 2004-2007
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Andrey Gromyko <andrey@gromyko.name>
* Ron Pruitt <wa84it@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
* 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 ***** */
function lifemarkData(title, URL)
{
this.title = title;
this.URL = URL;
}
var liveBookmarks =
{
// RDF namespaces
NC_NS : "http://home.netscape.com/NC-rdf#",
RDF_NS : "http://www.w3.org/1999/02/22-rdf-syntax-ns#",
getRDF: function()
{
return Components.classes["@mozilla.org/rdf/rdf-service;1"]
.getService( Components.interfaces.nsIRDFService );
},
getRDFC: function()
{
return Components.classes["@mozilla.org/rdf/container;1"]
.createInstance( Components.interfaces.nsIRDFContainer );
},
getRDFCU: function()
{
return Components.classes["@mozilla.org/rdf/container-utils;1"]
.getService( Components.interfaces.nsIRDFContainerUtils );
},
getProperty: function ( aInput, aArc, DS )
{
var node;
node = DS.GetTarget( aInput, aArc, true );
if( node instanceof Components.interfaces.nsIRDFResource )
return node.Value;
else if( node instanceof Components.interfaces.nsIRDFLiteral )
return node.Value;
return "";
},
getAll : function()
{
if (gFF3)
return this.getAll3();
else
return this.getAll2();
},
getAll3 : function()
{
var lifemarks = new Array();
alert("New nor old livemarks code works in FF3a7");
return lifemarks;
var Ci = Components.interfaces;
var bmsvc = Components.classes["@mozilla.org/browser/nav-bookmarks-service;1"].getService(Ci.nsINavBookmarksService);
var bmroot = bmsvc.bookmarksRoot;
var histsvc = Components.classes["@mozilla.org/browser/nav-history-service;1"].getService(Ci.nsINavHistoryService);
var options = histsvc.getNewQueryOptions();
var query = histsvc.getNewQuery();
// won't want the following when bug#331487 fixed
options.setGroupingMode([options.GROUP_BY_FOLDER], 1);
query.setFolders([bmroot], 1);
var result = histsvc.executeQuery(query, options);
var rootNode = result.root;
//var b = bmsvc.getBookmarksIdsForURI(uri(""), {});
//alert(b.length);
rootNode.containerOpen = true;
lifemarks = this.findlivemarks(rootNode,lifemarks);
rootNode.containerOpen = false;
return lifemarks;
},
findlivemarks : function(rootNode,lifemarks)
{
var Ci = Components.interfaces;
var lmsvc = Components.classes["@mozilla.org/browser/livemark-service;2"].getService(Ci.nsILivemarkService);
alert(rootNode.title + " " + rootNode.childCount);
for (var i=0; i<rootNode.childCount; i++)
{
var node = rootNode.getChild(i);
alert("Child: " + node.title + "\n");
if (node.type == node.RESULT_TYPE_FOLDER)
{
var folder = node.QueryInterface(Ci.nsINavHistoryQueryResultNode);
alert(folder.title + " " + node.uri + " " + node.id);
if (lmsvc.isLivemark(node.id))
{
curFeedURL = lmsvc.getFeedURI(node.id);
curName = node.title;
lifemarks.push(new lifemarkData(curName, curFeedURL));
}
else
{}// lifemarks = this.findlivemarks(node,lifemarks);
}
}
return lifemarks;
},
getAll2 : function()
{
var lifemarks = new Array();
// RDF variables
var RDF = this.getRDF();
var RDFC = this.getRDFC();
var RDFCU = this.getRDFCU();
var BMDS = RDF.GetDataSource("rdf:bookmarks");
var root = RDF.GetResource( "NC:BookmarksRoot" );
var NameArc = RDF.GetResource( this.NC_NS + "Name" );
var feedURLArc = RDF.GetResource( this.NC_NS + "FeedURL" );
var URLArc = RDF.GetResource( this.NC_NS + "URL" );
var typeArc = RDF.GetResource( this.RDF_NS + "type" );
var nodesToProcess = new Array( root );
var curNode, curType, curFeedURL, curName, enumerator;
while( nodesToProcess.length > 0 )
{
curNode = nodesToProcess.pop();
RDFC.Init( BMDS, curNode );
enumerator = RDFC.GetElements();
while( enumerator.hasMoreElements() )
{
curNode = enumerator.getNext();
curType = this.getProperty( curNode, typeArc, BMDS ).split( "#" )[1];
if( curType == "Folder" )
nodesToProcess.push( curNode );
else if( curType == "Livemark" )
{
curFeedURL = this.getProperty( curNode, feedURLArc, BMDS );
curName = this.getProperty( curNode, NameArc, BMDS );
lifemarks.push(new lifemarkData(curName, curFeedURL));
}
}
}
return lifemarks;
},
getAllUnique : function()
{
var livemarks = this.getAll();
var uniqmarks = new Array();
var isNew;
if (livemarks.length > 0) uniqmarks.push(livemarks[0]);
for (var i=1; i<livemarks.length; i++)
{
isNew = true;
for (var j=0; j<uniqmarks.length; j++)
if (uniqmarks[j].URL == livemarks[i].URL)
{
isNew = false;
break;
}
if (isNew) uniqmarks.push(livemarks[i]);
}
return uniqmarks;
}
}
///////////////////////////////////////////////////////////
// AG: check model against livemarks. Returns an array, possibly empty.
function getNewLivemarks()
{
var allLivemarks = liveBookmarks.getAllUnique();
var allLivemarksLen = allLivemarks.length;
var newLivemarks = new Array();
var modelTotalSize = gFmodel.sizeTotal();
for( var k=0; k < allLivemarksLen; k++ )
{
var livemark = allLivemarks[k];
var isNew = true;
for( var i=0; i < modelTotalSize; i++ )
if( gFmodel.get(i).url == livemark.URL)
{
isNew = false;
break;
}
if( isNew )
newLivemarks.push(livemark);
}
return newLivemarks;
}
function manageLivemarks()
{
var allLivemarks = liveBookmarks.getAllUnique();
var selected = new Array();
for( var i=0; i < gFmodel.sizeTotal(); i++)
{
var feed = gFmodel.get(i);
if( !feed.exclude )
selected.push(feed.url);
}
var params = { ok:false, livemarks:allLivemarks, selected:selected };
var win = window.openDialog("chrome://newsfox/content/livemarksDlg.xul",
"newsfox-dialog","chrome,centerscreen,modal", params);
if (params.ok)
{
updateLivemarks(allLivemarks, selected, false);
refreshModel();
}
}
function updateLivemarks(livemarks, selected, bNew)
{
for( var i=0; i < livemarks.length; i++ )
{
var feed = gFmodel.getFeedByURL(livemarks[i].URL);
var isExcluded = true;
for( var k = 0; k < selected.length; k++ )
if( selected[k] == livemarks[i].URL )
{
isExcluded = false;
break;
}
if( bNew || !feed) // new feed
{
feed = createNewFeed(gFmodel,livemarks[i].URL,isExcluded,true);
feed.setDefaultName(livemarks[i].title);
}
else // current feed
{
if (feed.exclude != isExcluded)
{
if (feed.exclude) // make included
{
gFmodel.remove(feed);
var inclfeed = createNewFeed(gFmodel,feed.url,false,true);
inclfeed.setDefaultName(livemarks[i].title);
}
else // make excluded
{
var feedtree = document.getElementById("newsfox.feedTree");
if (!gFdGroup[0].expanded) feedtree.view.toggleOpenState(0);
var index = -1;
for (var j=1; j<=gFmodel.size(); j++)
if (feed.url == gFmodel.get(gIdx.feed[j]).url) index = j;
if (index == -1) return;
deleteFeed(index,false);
var exclfeed = createNewFeed(gFmodel,feed.url,true,true);
exclfeed.setDefaultName(livemarks[i].title);
}
}
}
saveModels();
}
}
function doLivemarks()
{
if( !gKMeleon )
{
var newLivemarks = getNewLivemarks();
if( newLivemarks.length )
{
var selected = new Array();
var params = { ok:false, livemarks:newLivemarks, selected:selected, onlyNew:true };
var win = window.openDialog("chrome://newsfox/content/livemarksDlg.xul",
"newsfox-dialog","chrome,centerscreen,modal", params);
if (params.ok)
{
updateLivemarks(newLivemarks, selected, true);
refreshModel(); // need? TODO
}
}
}
else
{
var mngLMbutton = document.getElementById("mngLMbutton");
mngLMbutton.setAttribute("hidden", true);
}
}