// Clear Download Manager Button for PrefBar
// Copyright (C) Manuel Reimer (Manuel _dot_ Reimer _at_ gmx _dot_ de)
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// version 2 as published by the Free Software Foundation
function main() {
var dlmgr = Components.classes["@mozilla.org/download-manager;1"]
.getService(Components.interfaces.nsIDownloadManager);
if ("cleanUp" in dlmgr) // SeaMonkey >= 2.0
dlmgr.cleanUp();
else { // SeaMonkey 1.x
dlmgr.startBatchUpdate();
var dlarray = SmGetDownloads();
for (var index = 0; index < dlarray.length; index++)
dlmgr.removeDownload(dlarray[index]);
dlmgr.endBatchUpdate();
}
}
function SmGetDownloads() {
var retarray = new Array();
var dirService = Components.classes["@mozilla.org/file/directory_service;1"]
.getService(Components.interfaces.nsIProperties);
var dlDir = dirService.get("DLoads", Components.interfaces.nsIFile);
var fileHandler = Components.classes["@mozilla.org/network/protocol;1?name=file"]
.getService(Components.interfaces.nsIFileProtocolHandler);
var dlfurl = fileHandler.getURLSpecFromFile(dlDir);
var RDF = goPrefBar.RDF.RDFService;
var ds = RDF.GetDataSourceBlocking(dlfurl);
var RDLSeq = RDF.GetResource("NC:DownloadsRoot");
var seq = RDFCU.MakeSeq(ds, RDLSeq);
var dls = seq.GetElements();
while(dls.hasMoreElements()) {
var Rcurdl = dls.getNext();
var curdl = Rcurdl.QueryInterface(Components.interfaces.nsIRDFResource).Value;
retarray.push(curdl);
}
return retarray;
}
main();