mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-03-04 15:51:37 +00:00
Beginnings of supporting downloading of items, deleting download entries from the datasource.
NOT PART OF BUILD
This commit is contained in:
parent
25276e6b94
commit
b1e0c757a6
@ -133,7 +133,6 @@ var downloadViewController = {
|
||||
var selectionCount = gDownloadView.selectedItems.length;
|
||||
switch (aCommand) {
|
||||
case "cmd_downloadFile":
|
||||
downloadFile();
|
||||
return true;
|
||||
case "cmd_openfile":
|
||||
case "cmd_showinshell":
|
||||
@ -158,7 +157,7 @@ var downloadViewController = {
|
||||
var selection = gDownloadView.selectedItems;
|
||||
switch (aCommand) {
|
||||
case "cmd_downloadFile":
|
||||
dump("*** show a dialog that lets a user specify a URL to download\n");
|
||||
downloadFile();
|
||||
break;
|
||||
case "cmd_properties":
|
||||
dump("*** show properties for selected item\n");
|
||||
@ -181,6 +180,7 @@ var downloadViewController = {
|
||||
// a) Prompt user to confirm end of transfers in progress
|
||||
// b) End transfers
|
||||
// c) Delete entries from datasource
|
||||
deleteItem(selection);
|
||||
break;
|
||||
case "cmd_selectAll":
|
||||
gDownloadView.selectAll();
|
||||
@ -246,6 +246,52 @@ function downloadFile()
|
||||
}
|
||||
}
|
||||
|
||||
function deleteItem(aElements)
|
||||
{
|
||||
var selection = [];
|
||||
for (var i = 0; i < aElements.length; ++i)
|
||||
selection[i] = aElements[i];
|
||||
|
||||
var itemToSelect;
|
||||
for (i = 0; i < selection.length; ++i) {
|
||||
var itemResource = gRDFService.GetResource(NODE_ID(selection[i]));
|
||||
itemToSelect = getItemToSelect(selection[i]);
|
||||
|
||||
// Alert the user that transfers will be halted
|
||||
// End transfers
|
||||
|
||||
// Remove the download from the database
|
||||
var downloads = getDownloadsContainer();
|
||||
downloads.RemoveElement(itemResource, true);
|
||||
}
|
||||
gDownloadView.selectItem(itemToSelect);
|
||||
|
||||
var ds = gRDFService.GetDataSource("rdf:downloads");
|
||||
var remote = ds.QueryInterface(Components.interfaces.nsIRDFRemoteDataSource);
|
||||
ds.Flush();
|
||||
}
|
||||
|
||||
function getItemToSelect(aElement)
|
||||
{
|
||||
if (aElement.nextSibling)
|
||||
return aElement.nextSibling;
|
||||
else if (aElement.previousSibling)
|
||||
return aElement.previousSibling;
|
||||
return aElement.parentNode.parentNode;
|
||||
}
|
||||
|
||||
function getDownloadsContainer()
|
||||
{
|
||||
var downloads = gRDFService.GetResource("NC:DownloadsRoot", true);
|
||||
|
||||
const ctrContractID = "@mozilla.org/rdf/container;1";
|
||||
const ctrIID = Components.interfaces.nsIRDFContainer;
|
||||
var ctr = Components.classes[ctrContractID].getService(ctrIID);
|
||||
|
||||
ctr.Init(gDownloadView.database, downloads);
|
||||
return ctr;
|
||||
}
|
||||
|
||||
function getFileForItem(aElement)
|
||||
{
|
||||
var itemResource = gRDFService.GetResource(NODE_ID(aElement));
|
||||
|
@ -176,7 +176,7 @@
|
||||
src="moz-icon:rdf:http://home.netscape.com/NC-rdf#File"
|
||||
rdf:type="rdf:http://www.w3.org/1999/02/22-rdf-syntax-ns#type"/>
|
||||
<treecell>
|
||||
<progressmeter class="tree-progressmeter" value="rdf:http://home.netscape.com/NC-rdf#Progress"/>
|
||||
<progressmeter class="tree-progressmeter" value="rdf:http://home.netscape.com/NC-rdf#ProgressPercent"/>
|
||||
</treecell>
|
||||
<treecell label="rdf:http://home.netscape.com/NC-rdf#TimeRemaining"/>
|
||||
<treecell label="rdf:http://home.netscape.com/NC-rdf#Transferred"/>
|
||||
|
@ -65,12 +65,13 @@ nsIRDFResource* gNC_File;
|
||||
nsIRDFResource* gNC_URL;
|
||||
nsIRDFResource* gNC_Name;
|
||||
nsIRDFResource* gNC_Progress;
|
||||
nsIRDFResource* gNC_ProgressPercent;
|
||||
|
||||
nsIRDFService* gRDFService;
|
||||
|
||||
NS_IMPL_ISUPPORTS2(nsDownloadManager, nsIDownloadManager, nsIRDFDataSource)
|
||||
NS_IMPL_ISUPPORTS3(nsDownloadManager, nsIDownloadManager, nsIRDFDataSource, nsIRDFRemoteDataSource)
|
||||
|
||||
nsDownloadManager::nsDownloadManager()
|
||||
nsDownloadManager::nsDownloadManager() : mDownloadItems(nsnull)
|
||||
{
|
||||
NS_INIT_ISUPPORTS();
|
||||
}
|
||||
@ -83,9 +84,14 @@ nsDownloadManager::~nsDownloadManager()
|
||||
NS_IF_RELEASE(gNC_File);
|
||||
NS_IF_RELEASE(gNC_URL);
|
||||
NS_IF_RELEASE(gNC_Name);
|
||||
NS_IF_RELEASE(gNC_Progress);
|
||||
NS_IF_RELEASE(gNC_ProgressPercent);
|
||||
|
||||
nsServiceManager::ReleaseService(kRDFServiceCID, gRDFService);
|
||||
gRDFService = nsnull;
|
||||
|
||||
delete mDownloadItems;
|
||||
mDownloadItems = nsnull;
|
||||
}
|
||||
|
||||
nsresult
|
||||
@ -105,6 +111,7 @@ nsDownloadManager::Init()
|
||||
gRDFService->GetResource(NC_NAMESPACE_URI "URL", &gNC_URL);
|
||||
gRDFService->GetResource(NC_NAMESPACE_URI "Name", &gNC_Name);
|
||||
gRDFService->GetResource(NC_NAMESPACE_URI "Progress", &gNC_Progress);
|
||||
gRDFService->GetResource(NC_NAMESPACE_URI "ProgressPercent", &gNC_ProgressPercent);
|
||||
|
||||
#if 0
|
||||
mInner = do_GetService(NS_RDF_DATASOURCE_CONTRACTID_PREFIX "in-memory-datasource", &rv);
|
||||
@ -145,6 +152,8 @@ NS_IMETHODIMP
|
||||
nsDownloadManager::AddItem(const PRUnichar* aDisplayName, nsIURI* aSourceURI,
|
||||
nsILocalFile* aLocalFile, const char* aParentID, nsIWebProgress* aProgress)
|
||||
{
|
||||
nsresult rv;
|
||||
|
||||
nsCOMPtr<nsIRDFContainer> downloads;
|
||||
GetDownloadsContainer(getter_AddRefs(downloads));
|
||||
|
||||
@ -189,7 +198,28 @@ nsDownloadManager::AddItem(const PRUnichar* aDisplayName, nsIURI* aSourceURI,
|
||||
Assert(downloadItem, gNC_File, fileResource, PR_TRUE);
|
||||
|
||||
nsCOMPtr<nsIRDFRemoteDataSource> remote(do_QueryInterface(mInner));
|
||||
return remote->Flush();
|
||||
rv = remote->Flush();
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
DownloadItem* item = new DownloadItem();
|
||||
if (!item) return NS_ERROR_OUT_OF_MEMORY;
|
||||
NS_ADDREF(item);
|
||||
|
||||
if (!mDownloadItems)
|
||||
mDownloadItems = new nsHashtable();
|
||||
|
||||
nsCStringKey key(filePath);
|
||||
if (mDownloadItems->Exists(&key)) {
|
||||
DownloadItem* download = (DownloadItem*)mDownloadItems->Get(&key);
|
||||
if (download)
|
||||
delete download;
|
||||
}
|
||||
mDownloadItems->Put(&key, item);
|
||||
|
||||
rv = item->Init(downloadItem, this, aSourceURI, nsnull, aLocalFile);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
nsresult
|
||||
@ -391,6 +421,35 @@ nsDownloadManager::GetProfileDownloadsFileURL(char** aDownloadsFileURL)
|
||||
return profileDir->GetURL(aDownloadsFileURL);
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// nsIRDFRemoteDataSource
|
||||
NS_IMETHODIMP
|
||||
nsDownloadManager::GetLoaded(PRBool* aResult)
|
||||
{
|
||||
nsCOMPtr<nsIRDFRemoteDataSource> remote(do_QueryInterface(mInner));
|
||||
return remote->GetLoaded(aResult);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDownloadManager::Init(const char* aURI)
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDownloadManager::Refresh(PRBool aBlocking)
|
||||
{
|
||||
nsCOMPtr<nsIRDFRemoteDataSource> remote(do_QueryInterface(mInner));
|
||||
return remote->Refresh(aBlocking);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDownloadManager::Flush()
|
||||
{
|
||||
nsCOMPtr<nsIRDFRemoteDataSource> remote(do_QueryInterface(mInner));
|
||||
return remote->Flush();
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
DownloadItem::DownloadItem()
|
||||
@ -452,7 +511,8 @@ DownloadItem::Init(nsIRDFResource* aDownloadItem,
|
||||
// XXX using RDF here could really kill perf. Need to investigate timing.
|
||||
// RDF is probably not worthwhile if we're only looking at a single
|
||||
// view
|
||||
rv = mWebBrowserPersist->SetProgressListener(this);
|
||||
nsCOMPtr<nsIWebProgressListener> listener(do_QueryInterface(this));
|
||||
rv = mWebBrowserPersist->SetProgressListener(listener);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
rv = mWebBrowserPersist->SaveURI(aURI, aPostData, aFile);
|
||||
@ -465,6 +525,8 @@ DownloadItem::Init(nsIRDFResource* aDownloadItem,
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// nsIWebProgressListener
|
||||
NS_IMPL_ISUPPORTS1(DownloadItem, nsIWebProgressListener)
|
||||
|
||||
NS_IMETHODIMP
|
||||
DownloadItem::OnProgressChange(nsIWebProgress *aWebProgress,
|
||||
nsIRequest *aRequest,
|
||||
@ -473,9 +535,15 @@ DownloadItem::OnProgressChange(nsIWebProgress *aWebProgress,
|
||||
PRInt32 aCurTotalProgress,
|
||||
PRInt32 aMaxTotalProgress)
|
||||
{
|
||||
mCurTotalProgress = aCurTotalProgress;
|
||||
mMaxTotalProgress = aMaxTotalProgress;
|
||||
|
||||
if (mCurTotalProgress != aCurTotalProgress) {
|
||||
mCurTotalProgress = aCurTotalProgress;
|
||||
mMaxTotalProgress = aMaxTotalProgress;
|
||||
|
||||
PRInt32 percent = (PRInt32)(mCurTotalProgress / mMaxTotalProgress) * 100;
|
||||
nsCOMPtr<nsIRDFInt> percentInt;
|
||||
gRDFService->GetIntLiteral(percent, getter_AddRefs(percentInt));
|
||||
mDataSource->Assert(mDownloadItem, gNC_ProgressPercent, percentInt, PR_TRUE);
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
@ -51,12 +51,15 @@
|
||||
#include "nsIRequestObserver.h"
|
||||
#include "nsIURI.h"
|
||||
#include "nsILocalFile.h"
|
||||
#include "nsHashtable.h"
|
||||
|
||||
class nsDownloadManager : public nsIDownloadManager,
|
||||
public nsIRDFDataSource
|
||||
public nsIRDFDataSource,
|
||||
public nsIRDFRemoteDataSource
|
||||
{
|
||||
public:
|
||||
NS_DECL_NSIRDFDATASOURCE
|
||||
NS_DECL_NSIRDFREMOTEDATASOURCE
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSIDOWNLOADMANAGER
|
||||
|
||||
@ -76,6 +79,7 @@ protected:
|
||||
nsCOMPtr<nsIRDFService> mRDFService;
|
||||
nsCOMPtr<nsIRDFContainerUtils> mRDFContainerUtils;
|
||||
|
||||
nsHashtable* mDownloadItems;
|
||||
};
|
||||
|
||||
|
||||
@ -84,6 +88,7 @@ class DownloadItem : public nsIWebProgressListener
|
||||
{
|
||||
public:
|
||||
NS_DECL_NSIWEBPROGRESSLISTENER
|
||||
NS_DECL_ISUPPORTS
|
||||
DownloadItem();
|
||||
virtual ~DownloadItem();
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user