mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-26 14:22:01 +00:00
102477 - post-landing download manager cleanup. r=timeless sr=hewitt a=dbaron
This commit is contained in:
parent
298d74cdb6
commit
eaea0b13e9
@ -105,7 +105,7 @@ function openPropertiesDialog()
|
||||
function onSelect(aEvent) {
|
||||
if (!gStatusBar)
|
||||
gStatusBar = document.getElementById("statusbar-text");
|
||||
if (gDownloadView.selectedItems.length)
|
||||
if (gDownloadView.getRowCount() && gDownloadView.selectedItems.length)
|
||||
gStatusBar.label = gDownloadView.selectedItems[0].id;
|
||||
else
|
||||
gStatusBar.label = "";
|
||||
@ -139,15 +139,13 @@ var downloadViewController = {
|
||||
var isDownloading = gDownloadManager.getDownload(gDownloadView.selectedItems[0].id);
|
||||
switch (aCommand) {
|
||||
case "cmd_openfile":
|
||||
if (getFileForItem(gDownloadView.selectedItems[0]).isExecutable())
|
||||
if (!isDownloading && getFileForItem(gDownloadView.selectedItems[0]).isExecutable())
|
||||
return false;
|
||||
|
||||
case "cmd_showinshell":
|
||||
if (selectionCount != 1)
|
||||
return false;
|
||||
// some apps like kazaa/morpheus let you "preview" in-progress downloads because
|
||||
// that's possible for movies and music. for now, just disable indiscriminately.
|
||||
return !isDownloading && getFileForItem(gDownloadView.selectedItems[0]).exists();
|
||||
return selectionCount == 1;
|
||||
case "cmd_properties":
|
||||
return selectionCount == 1 && isDownloading;
|
||||
case "cmd_pause":
|
||||
@ -163,24 +161,24 @@ var downloadViewController = {
|
||||
case "cmd_selectAll":
|
||||
return gDownloadViewChildren.childNodes.length != selectionCount;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
},
|
||||
|
||||
doCommand: function dVC_doCommand (aCommand)
|
||||
{
|
||||
var selection = gDownloadView.selectedItems;
|
||||
var i;
|
||||
var i, file;
|
||||
switch (aCommand) {
|
||||
case "cmd_properties":
|
||||
openPropertiesDialog();
|
||||
break;
|
||||
case "cmd_openfile":
|
||||
var file = getFileForItem(selection[0]);
|
||||
file = getFileForItem(selection[0]);
|
||||
file.launch();
|
||||
break;
|
||||
case "cmd_showinshell":
|
||||
var localFile = getFileForItem(selection[0]);
|
||||
var file = localFile.QueryInterface(Components.interfaces.nsIFile);
|
||||
file = getFileForItem(selection[0]).QueryInterface(Components.interfaces.nsIFile);
|
||||
|
||||
// on unix, open a browser window rooted at the parent
|
||||
if (navigator.platform.indexOf("Win") == -1 && navigator.platform.indexOf("Mac") == -1) {
|
||||
@ -200,6 +198,7 @@ var downloadViewController = {
|
||||
// XXX we should probably prompt the user
|
||||
for (i = 0; i < selection.length; ++i)
|
||||
gDownloadManager.cancelDownload(selection[i].id);
|
||||
window.updateCommands("tree-select");
|
||||
break;
|
||||
case "cmd_remove":
|
||||
for (i = 0; i < selection.length; ++i)
|
||||
|
@ -419,7 +419,11 @@ nsDownloadManager::AddDownload(nsIURI* aSource,
|
||||
|
||||
nsCOMPtr<nsIRDFResource> urlResource;
|
||||
gRDFService->GetResource(spec.get(), getter_AddRefs(urlResource));
|
||||
rv = mDataSource->Assert(downloadRes, gNC_URL, urlResource, PR_TRUE);
|
||||
mDataSource->GetTarget(downloadRes, gNC_URL, PR_TRUE, getter_AddRefs(node));
|
||||
if (node)
|
||||
rv = mDataSource->Change(downloadRes, gNC_URL, node, urlResource);
|
||||
else
|
||||
rv = mDataSource->Assert(downloadRes, gNC_URL, urlResource, PR_TRUE);
|
||||
if (NS_FAILED(rv)) {
|
||||
downloads->IndexOf(downloadRes, &itemIndex);
|
||||
downloads->RemoveElementAt(itemIndex, PR_TRUE, getter_AddRefs(node));
|
||||
@ -437,7 +441,11 @@ nsDownloadManager::AddDownload(nsIURI* aSource,
|
||||
|
||||
nsCOMPtr<nsIRDFLiteral> nameLiteral;
|
||||
gRDFService->GetLiteral(displayName.get(), getter_AddRefs(nameLiteral));
|
||||
rv = mDataSource->Assert(downloadRes, gNC_Name, nameLiteral, PR_TRUE);
|
||||
mDataSource->GetTarget(downloadRes, gNC_Name, PR_TRUE, getter_AddRefs(node));
|
||||
if (node)
|
||||
rv = mDataSource->Change(downloadRes, gNC_Name, node, nameLiteral);
|
||||
else
|
||||
rv = mDataSource->Assert(downloadRes, gNC_Name, nameLiteral, PR_TRUE);
|
||||
if (NS_FAILED(rv)) {
|
||||
downloads->IndexOf(downloadRes, &itemIndex);
|
||||
downloads->RemoveElementAt(itemIndex, PR_TRUE, getter_AddRefs(node));
|
||||
@ -460,7 +468,11 @@ nsDownloadManager::AddDownload(nsIURI* aSource,
|
||||
// Assert download state information (NOTSTARTED, since it's just now being added)
|
||||
nsCOMPtr<nsIRDFInt> intLiteral;
|
||||
gRDFService->GetIntLiteral(NOTSTARTED, getter_AddRefs(intLiteral));
|
||||
rv = mDataSource->Assert(downloadRes, gNC_DownloadState, intLiteral, PR_TRUE);
|
||||
mDataSource->GetTarget(downloadRes, gNC_ProgressPercent, PR_TRUE, getter_AddRefs(node));
|
||||
if (node)
|
||||
rv = mDataSource->Change(downloadRes, gNC_ProgressPercent, node, intLiteral);
|
||||
else
|
||||
rv = mDataSource->Assert(downloadRes, gNC_DownloadState, intLiteral, PR_TRUE);
|
||||
if (NS_FAILED(rv)) {
|
||||
downloads->IndexOf(downloadRes, &itemIndex);
|
||||
downloads->RemoveElementAt(itemIndex, PR_TRUE, getter_AddRefs(node));
|
||||
@ -550,6 +562,8 @@ nsDownloadManager::CancelDownload(const char* aPersistentDescriptor)
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
}
|
||||
|
||||
DownloadEnded(aPersistentDescriptor, nsnull);
|
||||
|
||||
// if there's a progress dialog open for the item,
|
||||
// we have to notify it that we're cancelling
|
||||
nsCOMPtr<nsIProgressDialog> dialog;
|
||||
@ -1005,12 +1019,15 @@ nsDownload::OnStateChange(nsIWebProgress* aWebProgress,
|
||||
mDialogListener->OnStateChange(aWebProgress, aRequest, aStateFlags, aStatus);
|
||||
|
||||
if (aStateFlags & STATE_STOP) {
|
||||
if ((mDownloadState == DOWNLOADING && mPercentComplete == 100) || mDownloadState == NOTSTARTED)
|
||||
if (mDownloadState == DOWNLOADING || mDownloadState == NOTSTARTED) {
|
||||
mDownloadState = FINISHED;
|
||||
mCurrBytes = mMaxBytes;
|
||||
mPercentComplete = 100;
|
||||
|
||||
char* persistentDescriptor;
|
||||
mTarget->GetPersistentDescriptor(&persistentDescriptor);
|
||||
mDownloadManager->DownloadEnded(persistentDescriptor, nsnull);
|
||||
char* persistentDescriptor;
|
||||
mTarget->GetPersistentDescriptor(&persistentDescriptor);
|
||||
mDownloadManager->DownloadEnded(persistentDescriptor, nsnull);
|
||||
}
|
||||
|
||||
// break the cycle we created in AddDownload
|
||||
if (mPersist)
|
||||
|
Loading…
Reference in New Issue
Block a user