diff --git a/xpfe/components/download-manager/resources/downloadmanager.js b/xpfe/components/download-manager/resources/downloadmanager.js index 1c84e8ca9bfd..8e4f303a0778 100644 --- a/xpfe/components/download-manager/resources/downloadmanager.js +++ b/xpfe/components/download-manager/resources/downloadmanager.js @@ -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) diff --git a/xpfe/components/download-manager/src/nsDownloadManager.cpp b/xpfe/components/download-manager/src/nsDownloadManager.cpp index ed054013e65b..04f47598fb81 100644 --- a/xpfe/components/download-manager/src/nsDownloadManager.cpp +++ b/xpfe/components/download-manager/src/nsDownloadManager.cpp @@ -419,7 +419,11 @@ nsDownloadManager::AddDownload(nsIURI* aSource, nsCOMPtr 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 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 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 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)