Back to index

lightning-sunbird  0.9+nobinonly
old.cpp
Go to the documentation of this file.
00001 
00010   void openProgressDialogFor(in wstring aPersistentDescriptor, in nsIDOMWindow aParent);
00011 
00012 NS_IMETHODIMP
00013 nsDownloadManager::OpenProgressDialogFor(const PRUnichar* aPath, nsIDOMWindow* aParent)
00014 {
00015   nsresult rv;
00016   nsStringKey key(aPath);
00017   if (!mCurrDownloads.Exists(&key))
00018     return NS_ERROR_FAILURE;
00019 
00020   nsCOMPtr<nsIDownload> download;
00021   nsDownload* internalDownload = NS_STATIC_CAST(nsDownload*, mCurrDownloads.Get(&key));
00022   internalDownload->QueryInterface(NS_GET_IID(nsIDownload), (void**) getter_AddRefs(download));
00023   if (!download)
00024     return NS_ERROR_FAILURE;
00025  
00026 
00027   nsCOMPtr<nsIProgressDialog> oldDialog;
00028   internalDownload->GetDialog(getter_AddRefs(oldDialog));
00029   
00030   if (oldDialog) {
00031     nsCOMPtr<nsIDOMWindow> window;
00032     oldDialog->GetDialog(getter_AddRefs(window));
00033     if (window) {
00034       nsCOMPtr<nsIDOMWindowInternal> internalWin = do_QueryInterface(window);
00035       internalWin->Focus();
00036       return NS_OK;
00037     }
00038   }
00039 
00040   nsCOMPtr<nsIProgressDialog> dialog(do_CreateInstance("@mozilla.org/progressdialog;1", &rv));
00041   if (NS_FAILED(rv)) return rv;
00042   
00043   nsCOMPtr<nsIDownload> dl = do_QueryInterface(dialog);
00044 
00045   // now give the dialog the necessary context
00046   
00047   // start time...
00048   PRInt64 startTime = 0;
00049   download->GetStartTime(&startTime);
00050   
00051   // source...
00052   nsCOMPtr<nsIURI> source;
00053   download->GetSource(getter_AddRefs(source));
00054 
00055   // target...
00056   nsCOMPtr<nsILocalFile> target;
00057   download->GetTarget(getter_AddRefs(target));
00058   
00059   // helper app...
00060   nsCOMPtr<nsIMIMEInfo> mimeInfo;
00061   download->GetMIMEInfo(getter_AddRefs(mimeInfo));
00062 
00063   dl->Init(source, target, nsnull, mimeInfo, startTime, nsnull); 
00064   dl->SetObserver(this);
00065 
00066   // now set the listener so we forward notifications to the dialog
00067   nsCOMPtr<nsIWebProgressListener> listener = do_QueryInterface(dialog);
00068   internalDownload->SetDialogListener(listener);
00069   
00070   internalDownload->SetDialog(dialog);
00071   
00072   return dialog->Open(aParent);
00073 }
00074