Sexy "Downloading..." box

kmeleon10_branch
binaryc 21 years ago
parent 2f99afb1f0
commit c9ffa2efa5
  1. 3
      k-meleon/About.h
  2. 7
      k-meleon/BrowserFrameGlue.cpp
  3. 11
      k-meleon/BrowserView.cpp
  4. 4
      k-meleon/KMeleon.dsp
  5. 43
      k-meleon/MfcEmbed.rc
  6. 328
      k-meleon/UnknownContentTypeHandler.cpp
  7. 13
      k-meleon/resource.h
  8. 3
      k-meleon/version.h

@ -32,9 +32,8 @@ protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
protected:
//{{AFX_MSG(CMfcEmbedApp)
afx_msg void OnHome();
afx_msg void OnForum();
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};

@ -224,18 +224,17 @@ void CBrowserFrame::BrowserFrameGlueObj::SetBrowserFramePositionAndSize(PRInt32
SWP_NOACTIVATE | SWP_NOZORDER);
}
void CBrowserFrame::BrowserFrameGlueObj::SetFocus()
{
void CBrowserFrame::BrowserFrameGlueObj::SetFocus(){
METHOD_PROLOGUE(CBrowserFrame, BrowserFrameGlueObj)
pThis->SetFocus();
pThis->SetFocus();
}
void CBrowserFrame::BrowserFrameGlueObj::FocusAvailable(PRBool *aFocusAvail)
{
METHOD_PROLOGUE(CBrowserFrame, BrowserFrameGlueObj)
HWND focusWnd = GetFocus()->m_hWnd;
HWND focusWnd = GetFocus()->m_hWnd;
if ((focusWnd == pThis->m_hWnd) || ::IsChild(pThis->m_hWnd, focusWnd))
*aFocusAvail = PR_TRUE;

@ -699,11 +699,20 @@ void CBrowserView::OnFileOpen()
"HTML Files Only (*.htm;*.html)|*.htm;*.html|"
"All Files (*.*)|*.*||";
CFileDialog cf(TRUE, NULL, NULL, OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,
CFileDialog cf(TRUE, NULL, NULL, OFN_NOVALIDATE | OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,
lpszFilter, this);
cf.m_ofn.lpstrTitle = "Select a file or type in a URL";
if(cf.DoModal() == IDOK)
{
CString strFullPath = cf.GetPathName(); // Will be like: c:\tmp\junk.htm
FILE *test = fopen(strFullPath, "r");
if (!test){
// if the file doesn't exist, they probably typed a url...
// so chop off the path (for some reason GetFileName doesn't work for us...
strFullPath = strFullPath.Mid(strFullPath.ReverseFind('\\')+1);
}else{
fclose(test);
}
OpenURL(strFullPath);
}
}

@ -53,7 +53,7 @@ BSC32=bscmake.exe
# ADD BSC32 /nologo
LINK32=link.exe
# ADD BASE LINK32 /nologo /subsystem:windows /machine:I386
# ADD LINK32 xpcom.lib baseembed_s.lib plc4.lib /nologo /subsystem:windows /machine:I386 /out:"..\mozilla\mozilla\dist\WIN32_o.OBJ\Embed\k-meleon.exe" /libpath:"c:\projects\mozilla\mozilla\dist\win32_o.obj\lib" /libpath:"..\mozilla\mozilla\dist\WIN32_o.OBJ\lib"
# ADD LINK32 xpcom.lib baseembed_s.lib plc4.lib nspr4.lib /nologo /subsystem:windows /machine:I386 /out:"..\mozilla\mozilla\dist\WIN32_o.OBJ\Embed\k-meleon.exe" /libpath:"c:\projects\mozilla\mozilla\dist\win32_o.obj\lib" /libpath:"..\mozilla\mozilla\dist\WIN32_o.OBJ\lib"
# SUBTRACT LINK32 /pdb:none
# Begin Special Build Tool
SOURCE="$(InputPath)"
@ -85,7 +85,7 @@ BSC32=bscmake.exe
# ADD BSC32 /nologo
LINK32=link.exe
# ADD BASE LINK32 /nologo /subsystem:windows /debug /machine:I386 /pdbtype:sept
# ADD LINK32 xpcom.lib baseembed_s.lib /nologo /subsystem:windows /map /debug /machine:I386 /out:"..\mozilla\mozilla\dist\WIN32_o.OBJ\Embed\k-meleon.exe" /pdbtype:sept /libpath:"..\mozilla\mozilla\dist\WIN32_o.OBJ\lib"
# ADD LINK32 xpcom.lib baseembed_s.lib nspr4.lib /nologo /subsystem:windows /map /debug /machine:I386 /out:"..\mozilla\mozilla\dist\WIN32_o.OBJ\Embed\k-meleon.exe" /pdbtype:sept /libpath:"..\mozilla\mozilla\dist\WIN32_o.OBJ\lib"
# SUBTRACT LINK32 /profile /pdb:none /nodefaultlib
# Begin Special Build Tool
SOURCE="$(InputPath)"

@ -342,6 +342,33 @@ BEGIN
IDC_STATIC,7,7,160,8
END
IDD_PROGRESS DIALOG DISCARDABLE 0, 0, 291, 100
STYLE DS_MODALFRAME | WS_MINIMIZEBOX | WS_POPUP | WS_VISIBLE | WS_CAPTION |
WS_SYSMENU
CAPTION "Downloading..."
FONT 8, "MS Sans Serif"
BEGIN
PUSHBUTTON "Cancel",IDCANCEL,234,79,50,14
CONTROL "Progress1",IDC_DOWNLOAD_PROGRESS,"msctls_progress32",
PBS_SMOOTH | WS_BORDER,7,61,277,8
EDITTEXT IDC_SOURCE,40,7,244,14,ES_AUTOHSCROLL | ES_READONLY
EDITTEXT IDC_DESTINATION,40,22,244,14,ES_AUTOHSCROLL |
ES_READONLY
LTEXT "From:",IDC_STATIC,7,10,18,8
LTEXT "To:",IDC_STATIC,7,25,12,8
LTEXT "Status:",IDC_STATIC,7,39,23,8
CONTROL "",IDC_STATUS,"Static",SS_LEFTNOWORDWRAP | WS_GROUP,40,
39,244,8
CONTROL "Time Left:",IDC_TIME_LEFT,"Static",SS_LEFTNOWORDWRAP |
WS_GROUP,7,50,202,8
CONTROL "Speed:",IDC_SPEED,"Static",SS_LEFTNOWORDWRAP | WS_GROUP,
209,50,75,8
CONTROL "Close Dialog When Download Completes",
IDC_CLOSE_WHEN_DONE,"Button",BS_AUTOCHECKBOX |
WS_TABSTOP,40,83,145,10
PUSHBUTTON "Open File",IDC_OPEN,40,79,50,14,NOT WS_VISIBLE
END
#ifndef _MAC
/////////////////////////////////////////////////////////////////////////////
@ -490,6 +517,22 @@ BEGIN
BOTTOMMARGIN, 55
HORZGUIDE, 27
END
IDD_PROGRESS, DIALOG
BEGIN
LEFTMARGIN, 7
RIGHTMARGIN, 284
VERTGUIDE, 40
VERTGUIDE, 129
VERTGUIDE, 209
TOPMARGIN, 7
BOTTOMMARGIN, 93
HORZGUIDE, 14
HORZGUIDE, 29
HORZGUIDE, 43
HORZGUIDE, 54
HORZGUIDE, 65
END
END
#endif // APSTUDIO_INVOKED

@ -29,6 +29,43 @@
#include "MfcEmbed.h"
extern CMfcEmbedApp theApp;
class CProgressDialog : public CDialog,
public nsIWebProgressListener,
public nsSupportsWeakReference {
public:
enum { IDD = IDD_PROGRESS };
NS_DECL_ISUPPORTS
NS_DECL_NSIWEBPROGRESSLISTENER
CProgressDialog();
virtual ~CProgressDialog();
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
void SetLauncher(nsIHelperAppLauncher *aLauncher);
protected:
nsCOMPtr<nsIHelperAppLauncher> mLauncher;
// this is used to calculate speed
PRInt64 mStartTime;
PRInt32 mTotalBytes;
int mDone;
char *mFileName;
char *mFilePath;
virtual void OnCancel( );
afx_msg void OnOpen();
DECLARE_MESSAGE_MAP()
};
// HandleUnknownContentType (from nsIUnknownContentTypeHandler) implementation.
// XXX We can get the content type from the channel now so that arg could be dropped.
@ -45,88 +82,6 @@ CUnknownContentTypeHandler::HandleUnknownContentType( nsIRequest *request,
// this function never seems to get called...
MessageBox(NULL, "CHandleUnknownContentType()", NULL, MB_OK);
/*
if ( request ) {
aChannel = do_QueryInterface(request);
// Need root nsISupports for later JS_PushArguments call.
channel = do_QueryInterface( aChannel );
// Try to get HTTP channel.
nsCOMPtr<nsIHTTPChannel> httpChannel = do_QueryInterface( aChannel );
if ( httpChannel ) {
// Get content-disposition response header.
nsCOMPtr<nsIAtom> atom = dont_AddRef(NS_NewAtom( "content-disposition" ));
if ( atom ) {
nsXPIDLCString disp;
rv = httpChannel->GetResponseHeader( atom, getter_Copies( disp ) );
if ( NS_SUCCEEDED( rv ) && disp ) {
contentDisp = disp; // Save the response header to pass to dialog.
}
}
}
// Cancel input channel now.
rv = request->Cancel(NS_BINDING_ABORTED);
if ( NS_FAILED( rv ) ) {
NS_WARNING("Cancel failed");
}
}
if ( NS_SUCCEEDED( rv ) && channel && aContentType && aWindow ) {
// Open "Unknown content type" dialog.
// We pass in the channel, the content type, and the content disposition.
// Note that the "parent" browser window will be window.opener within the
// new dialog.
// Get JS context from parent window.
nsCOMPtr<nsIScriptGlobalObject> sgo = do_QueryInterface( aWindow, &rv );
if ( NS_SUCCEEDED( rv ) && sgo ) {
nsCOMPtr<nsIScriptContext> context;
sgo->GetContext( getter_AddRefs( context ) );
if ( context ) {
JSContext *jsContext = (JSContext*)context->GetNativeContext();
if ( jsContext ) {
void *stackPtr;
jsval *argv = JS_PushArguments( jsContext,
&stackPtr,
"sss%ipss",
"chrome://global/content/unknownContent.xul",
"_blank",
"chrome,titlebar",
(const nsIID*)(&NS_GET_IID(nsIChannel)),
(nsISupports*)channel.get(),
aContentType,
contentDisp.get() );
if ( argv ) {
nsCOMPtr<nsIDOMWindowInternal> newWindow;
rv = aWindow->OpenDialog( jsContext, argv, 6, getter_AddRefs( newWindow ) );
NS_ASSERTION(NS_SUCCEEDED(rv), "OpenDialog failed");
JS_PopArguments( jsContext, stackPtr );
} else {
NS_ASSERTION(0, "JS_PushArguments failed");
rv = NS_ERROR_FAILURE;
}
} else {
NS_ASSERTION(0, "GetNativeContext failed");
rv = NS_ERROR_FAILURE;
}
} else {
NS_ASSERTION(0, "GetContext failed");
rv = NS_ERROR_FAILURE;
}
} else {
NS_ASSERTION(0, "QueryInterface (for nsIScriptGlobalObject) failed");
}
} else {
// If no error recorded so far, set one now.
if ( NS_SUCCEEDED( rv ) ) {
rv = NS_ERROR_NULL_POINTER;
}
}
*/
return rv;
}
@ -134,11 +89,16 @@ CUnknownContentTypeHandler::HandleUnknownContentType( nsIRequest *request,
NS_IMETHODIMP
CUnknownContentTypeHandler::ShowProgressDialog(nsIHelperAppLauncher *aLauncher, nsISupports *aContext ) {
// this is here because mozilla won't do anything untill we call this function
// eventually we should probably pop up a "file saving" box or something
aLauncher->SetWebProgressListener (NULL);
CProgressDialog *progressDialog = new CProgressDialog ();
progressDialog->Create(IDD_PROGRESS, CWnd::FromHandle(GetDesktopWindow()));
return NS_OK;
progressDialog->SetLauncher(aLauncher);
NS_ADDREF (progressDialog);
aLauncher->SetWebProgressListener (progressDialog);
NS_RELEASE (progressDialog);
return NS_OK;
}
// Show the helper app launch confirmation dialog as instructed.
@ -331,4 +291,200 @@ nsresult NewUnknownContentHandlerFactory(nsIFactory** aFactory) {
}
/********************************************************************************************************
file save progress dialog box
********************************************************************************************************/
NS_IMPL_ISUPPORTS2(CProgressDialog, nsIWebProgressListener, nsISupportsWeakReference)
CProgressDialog::CProgressDialog() {
NS_INIT_ISUPPORTS();
mFileName = NULL;
mFilePath = NULL;
mStartTime = 0;
// assume we're done until we get data
// for small files, we'll be done before the box even pops up
mDone = true;
}
CProgressDialog::~CProgressDialog(){
if (mFileName)
delete mFileName;
if (mFilePath)
delete mFilePath;
}
/* void onStateChange (in nsIWebProgress aWebProgress, in nsIRequest aRequest, in long aStateFlags, in unsigned long aStatus); */
NS_IMETHODIMP CProgressDialog::OnStateChange(nsIWebProgress *aWebProgress, nsIRequest *aRequest, PRInt32 aStateFlags, PRUint32 aStatus){
if (aStateFlags & nsIWebProgressListener::STATE_STOP){
if (IsDlgButtonChecked(IDC_CLOSE_WHEN_DONE)){
mLauncher->CloseProgressWindow ();
}else{
char statusText[50];
PRInt64 now = PR_Now ();
PRInt64 timeSpent = now - mStartTime;
sprintf(statusText, "Done! Downloaded %.2f KBytes in %d seconds", mTotalBytes/1024 +.5, (int)(timeSpent/1000000.0l));
SetDlgItemText(IDC_STATUS, statusText);
SetDlgItemText(IDCANCEL, "Close");
GetDlgItem(IDC_OPEN)->ShowWindow(SW_SHOW);
GetDlgItem(IDC_CLOSE_WHEN_DONE)->ShowWindow(SW_HIDE);
mDone = true;
}
}else if (aStateFlags & nsIWebProgressListener::STATE_REDIRECTING){
SetDlgItemText(IDC_STATUS, "Redirecting...");
}else if (aStateFlags & nsIWebProgressListener::STATE_TRANSFERRING){
SetDlgItemText(IDC_STATUS, "Downloading...");
}else if (aStateFlags & nsIWebProgressListener::STATE_NEGOTIATING){
SetDlgItemText(IDC_STATUS, "Negotiating...");
}else if (aStateFlags & nsIWebProgressListener::STATE_START){
SetDlgItemText(IDC_STATUS, "Contacting...");
}
return NS_OK;
}
/* void onProgressChange (in nsIWebProgress aWebProgress, in nsIRequest aRequest, in long aCurSelfProgress, in long aMaxSelfProgress, in long aCurTotalProgress, in long aMaxTotalProgress); */
NS_IMETHODIMP CProgressDialog::OnProgressChange(nsIWebProgress *aWebProgress, nsIRequest *aRequest, PRInt32 aCurSelfProgress, PRInt32 aMaxSelfProgress, PRInt32 aCurTotalProgress, PRInt32 aMaxTotalProgress){
if (aMaxTotalProgress){
mDone = false;
int percent = (int)(((float)aCurTotalProgress / (float)aMaxTotalProgress) * 100.0f);
char progressString[50];
sprintf(progressString, "Downloaded %d%% (%.2f of %.2f KBytes)", percent, aCurTotalProgress/1024 +.5, aMaxTotalProgress/1024 +.5);
SetDlgItemText(IDC_STATUS, progressString);
PRInt64 now = PR_Now ();
PRInt64 timeSpent = now - mStartTime;
PRInt64 delta = aCurTotalProgress;
// given in bytes per second!
double speed = 0.0;
if (mStartTime > 0){
double timeSpent_seconds = ((double)timeSpent/1000000.0l);
if (timeSpent_seconds > 0)
speed = delta / timeSpent_seconds;
else
speed = 0;
double speed_kbs = speed/1024;
char speedString[50];
sprintf(speedString, "Speed: %.2f KBps ", speed_kbs);
SetDlgItemText(IDC_SPEED, speedString);
}else{
// mStartTime is 0, we should try to get a new start time
nsCOMPtr<nsIURI> pUri;
nsCOMPtr<nsIFile> pFile;
PRInt64 timestarted;
mLauncher->GetDownloadInfo(getter_AddRefs(pUri),
&timestarted,
getter_AddRefs(pFile));
mStartTime = timestarted;
// while we're at it, save the file size
mTotalBytes = aMaxTotalProgress;
}
if (speed){
PRInt32 remaining = (PRInt32)((aMaxTotalProgress - aCurTotalProgress)/speed +.5);
char timeString[50];
sprintf(timeString, "Time Left: %u Seconds", remaining );
SetDlgItemText(IDC_TIME_LEFT, timeString);
}
char titleString[255];
sprintf(titleString, "%d%% of %s", percent, mFileName);
SetWindowText(titleString);
HWND progressBar;
GetDlgItem(IDC_DOWNLOAD_PROGRESS, &progressBar);
::SendMessage(progressBar, PBM_SETRANGE, 0, MAKELPARAM(0, 100));
::SendMessage(progressBar, PBM_SETPOS, (WPARAM) percent, 0);
}
return NS_OK;
}
/* void onLocationChange (in nsIWebProgress aWebProgress, in nsIRequest aRequest, in nsIURI location); */
NS_IMETHODIMP CProgressDialog::OnLocationChange(nsIWebProgress *aWebProgress, nsIRequest *aRequest, nsIURI *location){
return NS_OK;
}
/* void onStatusChange (in nsIWebProgress aWebProgress, in nsIRequest aRequest, in nsresult aStatus, in wstring aMessage); */
NS_IMETHODIMP CProgressDialog::OnStatusChange(nsIWebProgress *aWebProgress, nsIRequest *aRequest, nsresult aStatus, const PRUnichar *aMessage){
return NS_OK;
}
/* void onSecurityChange (in nsIWebProgress aWebProgress, in nsIRequest aRequest, in long state); */
NS_IMETHODIMP CProgressDialog::OnSecurityChange(nsIWebProgress *aWebProgress, nsIRequest *aRequest, PRInt32 state){
return NS_OK;
}
void CProgressDialog::DoDataExchange(CDataExchange* pDX){
CDialog::DoDataExchange(pDX);
}
void CProgressDialog::SetLauncher(nsIHelperAppLauncher *aLauncher){
mLauncher = aLauncher;
nsCOMPtr<nsIURI> pUri;
nsCOMPtr<nsIFile> pFile;
PRInt64 timestarted;
aLauncher->GetDownloadInfo(getter_AddRefs(pUri),
&timestarted,
getter_AddRefs(pFile));
// we don't set start time here, because it's rarely set by now.
// we'll set it later in OnProgressChange
// mStartTime = timestarted; //PR_Now();
char *uri;
char *filepath;
pUri->GetSpec (&uri);
pFile->GetPath (&filepath);
SetDlgItemText(IDC_SOURCE, uri);
SetDlgItemText(IDC_DESTINATION, filepath);
char *file = strrchr(filepath, '\\')+1;
mFileName = strdup(file);
mFilePath = strdup(filepath);
}
BEGIN_MESSAGE_MAP(CProgressDialog, CDialog)
ON_COMMAND(IDC_OPEN, OnOpen)
END_MESSAGE_MAP()
void CProgressDialog::OnCancel() {
if (mDone){
DestroyWindow();
}else{
mLauncher->Cancel();
mLauncher->CloseProgressWindow ();
}
}
void CProgressDialog::OnOpen(){
char *directory = strdup(mFilePath);
char *last_slash = strrchr(directory, '\\');
*last_slash = 0;
ShellExecute(NULL, "open", mFilePath, "", directory, SW_SHOW);
delete directory;
}

@ -46,6 +46,7 @@
#define IDI_OFFCHECK 179
#define IDI_ONCHECK 180
#define IDD_DIALOG_OPEN 181
#define IDD_PROGRESS 184
#define ID_URL_BAR 1001
#define ID_PROG_BAR 1002
#define IDC_PROMPT_ANSWER 1003
@ -97,11 +98,19 @@
#define IDC_RADIO_URL 1041
#define IDC_WRAP_AROUND 1042
#define IDC_SEARCH_BACKWARDS 1043
#define IDC_DOWNLOAD_PROGRESS 1043
#define IDC_DESTINATION 1044
#define IDC_STATUS 1045
#define IDC_SOURCE 1046
#define IDC_TIME_LEFT 1047
#define IDC_CHECK_SOURCE_ENABLED 1050
#define IDC_RADIO_ONCE 1050
#define IDC_SPEED 1050
#define IDC_EDIT_SOURCE_COMMAND 1051
#define IDC_RADIO_ALWAYS 1051
#define IDC_CLOSE_WHEN_DONE 1051
#define IDC_RADIO_NEVER 1052
#define IDC_OPEN 1052
#define IDC_BUTTON2 1054
#define IDC_EDIT_ADDRESS 1055
#define IDC_BUTTON3 1055
@ -159,9 +168,9 @@
#ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_3D_CONTROLS 1
#define _APS_NEXT_RESOURCE_VALUE 184
#define _APS_NEXT_RESOURCE_VALUE 185
#define _APS_NEXT_COMMAND_VALUE 32801
#define _APS_NEXT_CONTROL_VALUE 1043
#define _APS_NEXT_CONTROL_VALUE 1053
#define _APS_NEXT_SYMED_VALUE 101
#endif
#endif

@ -3,5 +3,6 @@
#else
#define VERSION "0.4.5"
#endif
#define BUILD_TIME __TIMESTAMP__
#define BUILD_NUMBER 363
#define BUILD_NUMBER 462

Loading…
Cancel
Save