Merge branch 'master' of git+ssh://dev.laptop.org/git/sugar

This commit is contained in:
Marco Pesenti Gritti 2006-10-27 22:18:49 +02:00
commit 45287c880c
7 changed files with 17 additions and 38 deletions

View File

@ -21,8 +21,8 @@ libsugarprivate_la_SOURCES = \
sugar-browser.cpp \ sugar-browser.cpp \
sugar-browser-chandler.h \ sugar-browser-chandler.h \
sugar-browser-chandler.c \ sugar-browser-chandler.c \
sugar-content-handler.h \ SugarContentHandler.h \
sugar-content-handler.cpp \ SugarContentHandler.cpp \
SugarDownload.h \ SugarDownload.h \
SugarDownload.cpp \ SugarDownload.cpp \
sugar-key-grabber.h \ sugar-key-grabber.h \

View File

@ -1,15 +1,10 @@
#include <stdio.h>
#include <nsStringAPI.h>
#include <nsCExternalHandlerService.h> #include <nsCExternalHandlerService.h>
#include <nsIMIMEInfo.h>
#include <nsIURL.h>
#include <nsIFile.h> #include <nsIFile.h>
#include "sugar-browser-chandler.h" #include "sugar-browser-chandler.h"
#include "SugarDownload.h" #include "SugarDownload.h"
#include "sugar-content-handler.h" #include "SugarContentHandler.h"
GSugarContentHandler::GSugarContentHandler() GSugarContentHandler::GSugarContentHandler()
{ {
@ -28,10 +23,10 @@ GSugarContentHandler::Show (nsIHelperAppLauncher *aLauncher,
nsISupports *aContext, nsISupports *aContext,
PRUint32 aReason) PRUint32 aReason)
{ {
nsCOMPtr<nsIFile> tmp_file; nsCOMPtr<nsIFile> tmpFile;
aLauncher->GetTargetFile(getter_AddRefs(tmp_file)); aLauncher->GetTargetFile(getter_AddRefs(tmpFile));
aLauncher->SaveToDisk (tmp_file, PR_FALSE); aLauncher->SaveToDisk (tmpFile, PR_FALSE);
return NS_OK; return NS_OK;
} }

View File

@ -1,7 +1,3 @@
#include <stdio.h>
#include <stdlib.h>
#include <nsStringAPI.h>
#include "sugar-browser-chandler.h" #include "sugar-browser-chandler.h"
#include "SugarDownload.h" #include "SugarDownload.h"
@ -28,15 +24,11 @@ GSugarDownload::Init (nsIURI *aSource,
nsILocalFile *aTempFile, nsILocalFile *aTempFile,
nsICancelable *aCancelable) nsICancelable *aCancelable)
{ {
FILE *file = fopen("/home/tomeu/file.txt","a+");
fprintf(file,"%s\n","GSugarDownload::Init");
fclose(file);
mSource = aSource; mSource = aSource;
mTarget = aTarget; aTarget->GetPath(mTargetFileName);
mMIMEInfo = aMIMEInfo; mMIMEInfo = aMIMEInfo;
mTempFile = aTempFile; mTempFile = aTempFile;
return NS_OK; return NS_OK;
} }
@ -46,7 +38,7 @@ GSugarDownload::OnStateChange (nsIWebProgress *aWebProgress, nsIRequest *aReques
{ {
nsCString url; nsCString url;
nsCString mimeType; nsCString mimeType;
nsCString tmpFileName; nsCString targetURI;
if ((((aStateFlags & STATE_IS_REQUEST) && if ((((aStateFlags & STATE_IS_REQUEST) &&
(aStateFlags & STATE_IS_NETWORK) && (aStateFlags & STATE_IS_NETWORK) &&
@ -56,18 +48,12 @@ GSugarDownload::OnStateChange (nsIWebProgress *aWebProgress, nsIRequest *aReques
mMIMEInfo->GetMIMEType(mimeType); mMIMEInfo->GetMIMEType(mimeType);
mSource->GetSpec(url); mSource->GetSpec(url);
mTempFile->GetNativeLeafName(tmpFileName);
// FIXME: Hack. Mozilla adds a .part to the file name. Must exist a better/simpler way.
// FIXME: Also creates a nice memory leak.
char *tmpFileName_striped = (char*)malloc(strlen(tmpFileName.get()));
strncpy(tmpFileName_striped, tmpFileName.get(), strlen(tmpFileName.get()) - 5);
SugarBrowserChandler *browser_chandler = sugar_get_browser_chandler(); SugarBrowserChandler *browser_chandler = sugar_get_browser_chandler();
sugar_browser_chandler_handle_content(browser_chandler, sugar_browser_chandler_handle_content(browser_chandler,
url.get(), url.get(),
mimeType.get(), mimeType.get(),
tmpFileName_striped); mTargetFileName.get());
} }
return NS_OK; return NS_OK;

View File

@ -8,6 +8,7 @@
#include <nsIMIMEInfo.h> #include <nsIMIMEInfo.h>
#include <nsIURL.h> #include <nsIURL.h>
#include <nsILocalFile.h> #include <nsILocalFile.h>
#include <nsStringAPI.h>
#define G_SUGARDOWNLOAD_CID \ #define G_SUGARDOWNLOAD_CID \
{ /* b1813bbe-6518-11db-967e-00e08161165f */ \ { /* b1813bbe-6518-11db-967e-00e08161165f */ \
@ -29,10 +30,10 @@ public:
NS_DECL_NSITRANSFER NS_DECL_NSITRANSFER
protected: protected:
nsIURI *mSource; nsIURI *mSource;
nsIURI *mTarget; nsCString mTargetFileName;
nsIMIMEInfo *mMIMEInfo; nsIMIMEInfo *mMIMEInfo;
nsILocalFile *mTempFile; nsILocalFile *mTempFile;
}; };
#endif // SugarDownload_h__ #endif // SugarDownload_h__

View File

@ -1,6 +1,3 @@
#include <stdio.h>
#include <string.h>
#include "sugar-marshal.h" #include "sugar-marshal.h"
#include "sugar-browser-chandler.h" #include "sugar-browser-chandler.h"

View File

@ -18,7 +18,7 @@
*/ */
#include "sugar-browser.h" #include "sugar-browser.h"
#include "sugar-content-handler.h" #include "SugarContentHandler.h"
#include "SugarDownload.h" #include "SugarDownload.h"
#include <gtkmozembed_internal.h> #include <gtkmozembed_internal.h>