void ScreenPackages::MenuBack( PlayerNumber pn ) { if ( m_bIsDownloading ) { SCREENMAN->SystemMessage( "Download Cancelled." ); CancelDownload( ); return; } TweenOffScreen(); Cancel( SM_GoToPrevScreen ); ScreenWithMenuElements::MenuBack( pn ); }
int showprogress(void *bar, double total, /* dltotal */ double done, /* dlnow */ double ultotal, double ulnow) { char msg[20]; sprintf(msg, "Loading...%2.2f%%", done*100.0/total); SetMessage(msg); if(CancelDownload()) return 1; return 0; }
void FileTransfer::FileTransferDownload() { rfbFileDownloadDataMsg fdd; m_clientconn->ReadExact((char *)&fdd, sz_rfbFileDownloadDataMsg); fdd.realSize = Swap16IfLE(fdd.realSize); fdd.compressedSize = Swap16IfLE(fdd.compressedSize); char path[rfbMAX_PATH + rfbMAX_PATH + 3]; if (m_bFirstFileDownloadMsg) { m_dwDownloadBlockSize = fdd.compressedSize; sprintf(path, "%s\\%s", m_ClientPath, m_ServerFilename); strcpy(m_DownloadFilename, path); m_hFiletoWrite = CreateFile(path, GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, CREATE_ALWAYS, FILE_FLAG_SEQUENTIAL_SCAN, NULL); int amount = m_sizeDownloadFile / ((m_dwDownloadBlockSize + 1) * 10); InitProgressBar(0, 0, amount, 1); m_bFirstFileDownloadMsg = FALSE; m_bDownloadStarted = TRUE; } if ((fdd.realSize == 0) && (fdd.compressedSize == 0)) { unsigned int mTime; m_clientconn->ReadExact((char *) &mTime, sizeof(unsigned int)); if (m_hFiletoWrite == INVALID_HANDLE_VALUE) { CancelDownload("Could not create file"); MessageBox(m_hwndFileTransfer, "Download failed: could not create local file", "Download Failed", MB_ICONEXCLAMATION | MB_OK); SendMessage(m_hwndFTProgress, PBM_SETPOS, 0, 0); // Send message to start download for next selected file. PostMessage(m_hwndFileTransfer, WM_COMMAND, IDC_FTCOPY, 0); return; } FILETIME Filetime; Time70ToFiletime(mTime, &Filetime); SetFileTime(m_hFiletoWrite, &Filetime, &Filetime, &Filetime); SendMessage(m_hwndFTProgress, PBM_SETPOS, 0, 0); SetWindowText(m_hwndFTStatus, ""); CloseHandle(m_hFiletoWrite); ShowClientItems(m_ClientPath); m_bFirstFileDownloadMsg = TRUE; m_bDownloadStarted = FALSE; // Send message to start download for next selected file. PostMessage(m_hwndFileTransfer, WM_COMMAND, IDC_FTCOPY, 0); return; } char * pBuff = new char [fdd.compressedSize]; DWORD dwNumberOfBytesWritten; m_clientconn->ReadExact(pBuff, fdd.compressedSize); ProcessDlgMessage(m_hwndFileTransfer); if (!m_bTransferEnable) { CancelDownload("Download cancelled by user"); delete [] pBuff; return; } if (m_hFiletoWrite == INVALID_HANDLE_VALUE) { CancelDownload("Could not create file"); MessageBox(m_hwndFileTransfer, "Download failed: could not create local file", "Download Failed", MB_ICONEXCLAMATION | MB_OK); delete [] pBuff; return; } WriteFile(m_hFiletoWrite, pBuff, fdd.compressedSize, &dwNumberOfBytesWritten, NULL); m_dwDownloadRead += dwNumberOfBytesWritten; if (m_dwDownloadRead >= (10 * m_dwDownloadBlockSize)) { m_dwDownloadRead = 0; SendMessage(m_hwndFTProgress, PBM_STEPIT, 0, 0); } delete [] pBuff; }
void DownloadProgressView::MessageReceived(BMessage* message) { switch (message->what) { case B_DOWNLOAD_STARTED: { BString path; if (message->FindString("path", &path) != B_OK) break; fPath.SetTo(path); BEntry entry(fPath.Path()); fIconView->SetTo(entry); fStatusBar->Reset(fPath.Leaf()); _StartNodeMonitor(entry); // Immediately switch to speed display whenever a new download // starts. sShowSpeed = true; sLastEstimatedFinishSpeedToggleTime = fProcessStartTime = fLastSpeedReferenceTime = fEstimatedFinishReferenceTime = system_time(); break; } case B_DOWNLOAD_PROGRESS: { int64 currentSize; int64 expectedSize; if (message->FindInt64("current size", ¤tSize) == B_OK && message->FindInt64("expected size", &expectedSize) == B_OK) { _UpdateStatus(currentSize, expectedSize); } break; } case B_DOWNLOAD_REMOVED: // TODO: This is a bit asymetric. The removed notification // arrives here, but it would be nicer if it arrived // at the window... Window()->PostMessage(message); break; case OPEN_DOWNLOAD: { // TODO: In case of executable files, ask the user first! entry_ref ref; status_t status = get_ref_for_path(fPath.Path(), &ref); if (status == B_OK) status = be_roster->Launch(&ref); if (status != B_OK && status != B_ALREADY_RUNNING) { BAlert* alert = new BAlert(B_TRANSLATE("Open download error"), B_TRANSLATE("The download could not be opened."), B_TRANSLATE("OK")); alert->SetFlags(alert->Flags() | B_CLOSE_ON_ESCAPE); alert->Go(NULL); } break; } case RESTART_DOWNLOAD: { // We can't create a download without a full web context (mainly // because it needs to access the cookie jar), and when we get here // the original context is long gone (possibly the browser was // restarted). So we create a new window to restart the download // in a fresh context. // FIXME this has of course the huge downside of leaving the new // window open with a blank page. I can't think of a better // solution right now... BMessage* request = new BMessage(NEW_WINDOW); request->AddString("url", fURL); be_app->PostMessage(request); break; } case CANCEL_DOWNLOAD: CancelDownload(); break; case REMOVE_DOWNLOAD: { Window()->PostMessage(SAVE_SETTINGS); RemoveSelf(); delete this; // TOAST! return; } case B_NODE_MONITOR: { int32 opCode; if (message->FindInt32("opcode", &opCode) != B_OK) break; switch (opCode) { case B_ENTRY_REMOVED: fIconView->SetIconDimmed(true); CancelDownload(); break; case B_ENTRY_MOVED: { // Follow the entry to the new location dev_t device; ino_t directory; const char* name; if (message->FindInt32("device", reinterpret_cast<int32*>(&device)) != B_OK || message->FindInt64("to directory", reinterpret_cast<int64*>(&directory)) != B_OK || message->FindString("name", &name) != B_OK || strlen(name) == 0) { break; } // Construct the BEntry and update fPath entry_ref ref(device, directory, name); BEntry entry(&ref); if (entry.GetPath(&fPath) != B_OK) break; // Find out if the directory is the Trash for this // volume char trashPath[B_PATH_NAME_LENGTH]; if (find_directory(B_TRASH_DIRECTORY, device, false, trashPath, B_PATH_NAME_LENGTH) == B_OK) { BPath trashDirectory(trashPath); BPath parentDirectory; fPath.GetParent(&parentDirectory); if (parentDirectory == trashDirectory) { // The entry was moved into the Trash. // If the download is still in progress, // cancel it. fIconView->SetIconDimmed(true); CancelDownload(); break; } else if (fIconView->IsIconDimmed()) { // Maybe it was moved out of the trash. fIconView->SetIconDimmed(false); } } // Inform download of the new path if (fDownload) fDownload->HasMovedTo(fPath); float value = fStatusBar->CurrentValue(); fStatusBar->Reset(name); fStatusBar->SetTo(value); Window()->PostMessage(SAVE_SETTINGS); break; } case B_ATTR_CHANGED: { BEntry entry(fPath.Path()); fIconView->SetIconDimmed(false); fIconView->SetTo(entry); break; } } break; } // Context menu messages case COPY_URL_TO_CLIPBOARD: if (be_clipboard->Lock()) { BMessage* data = be_clipboard->Data(); if (data != NULL) { be_clipboard->Clear(); data->AddData("text/plain", B_MIME_TYPE, fURL.String(), fURL.Length()); } be_clipboard->Commit(); be_clipboard->Unlock(); } break; case OPEN_CONTAINING_FOLDER: if (fPath.InitCheck() == B_OK) { BEntry selected(fPath.Path()); if (!selected.Exists()) break; BPath containingFolder; if (fPath.GetParent(&containingFolder) != B_OK) break; entry_ref ref; if (get_ref_for_path(containingFolder.Path(), &ref) != B_OK) break; // Ask Tracker to open the containing folder and select the // file inside it. BMessenger trackerMessenger("application/x-vnd.Be-TRAK"); if (trackerMessenger.IsValid()) { BMessage selectionCommand(B_REFS_RECEIVED); selectionCommand.AddRef("refs", &ref); node_ref selectedRef; if (selected.GetNodeRef(&selectedRef) == B_OK) { selectionCommand.AddData("nodeRefToSelect", B_RAW_TYPE, (void*)&selectedRef, sizeof(node_ref)); } trackerMessenger.SendMessage(&selectionCommand); } } break; default: BGroupView::MessageReceived(message); } }
void PodcastService::CancelDownload() { CancelDownload(selected_episodes_, explicitly_selected_podcasts_); }
NS_IMETHODIMP nsDownloadManager::Observe(nsISupports* aSubject, const char* aTopic, const PRUnichar* aData) { nsresult rv; if (nsCRT::strcmp(aTopic, "profile-approve-change") == 0) { // Only run this on profile switch if (!NS_LITERAL_STRING("switch").Equals(aData)) return NS_OK; // If count == 0, nothing to do if (mCurrDownloads.Count() == 0) return NS_OK; nsCOMPtr<nsIProfileChangeStatus> changeStatus(do_QueryInterface(aSubject)); if (!changeStatus) return NS_ERROR_UNEXPECTED; nsXPIDLString title, text, proceed, cancel; nsresult rv = mBundle->GetStringFromName(NS_LITERAL_STRING("profileSwitchTitle").get(), getter_Copies(title)); NS_ENSURE_SUCCESS(rv, rv); rv = mBundle->GetStringFromName(NS_LITERAL_STRING("profileSwitchText").get(), getter_Copies(text)); NS_ENSURE_SUCCESS(rv, rv); rv = mBundle->GetStringFromName(NS_LITERAL_STRING("profileSwitchContinue").get(), getter_Copies(proceed)); NS_ENSURE_SUCCESS(rv, rv); nsCOMPtr<nsIPromptService> promptService(do_GetService(NS_PROMPTSERVICE_CONTRACTID, &rv)); if (NS_FAILED(rv)) return rv; PRInt32 button; rv = promptService->ConfirmEx(nsnull, title.get(), text.get(), nsIPromptService::BUTTON_TITLE_CANCEL * nsIPromptService::BUTTON_POS_0 | nsIPromptService::BUTTON_TITLE_IS_STRING * nsIPromptService::BUTTON_POS_1, nsnull, proceed.get(), nsnull, nsnull, nsnull, &button); if (NS_FAILED(rv)) return rv; if (button == 0) changeStatus->VetoChange(); } else if (nsCRT::strcmp(aTopic, "profile-before-change") == 0) { nsCOMPtr<nsISupports> supports; nsCOMPtr<nsIRDFResource> res; nsCOMPtr<nsIRDFInt> intLiteral; gRDFService->GetIntLiteral(DOWNLOADING, getter_AddRefs(intLiteral)); nsCOMPtr<nsISimpleEnumerator> downloads; rv = mDataSource->GetSources(gNC_DownloadState, intLiteral, PR_TRUE, getter_AddRefs(downloads)); if (NS_FAILED(rv)) return rv; PRBool hasMoreElements; downloads->HasMoreElements(&hasMoreElements); while (hasMoreElements) { const char* uri; downloads->GetNext(getter_AddRefs(supports)); res = do_QueryInterface(supports); res->GetValueConst(&uri); CancelDownload(nsDependentCString(uri)); downloads->HasMoreElements(&hasMoreElements); } } return NS_OK; }