Implement save_uri. Add boolean return arguments.

This commit is contained in:
Marco Pesenti Gritti 2007-03-13 14:07:03 +01:00
parent 070c77c67f
commit c9bdd4418c
4 changed files with 49 additions and 6 deletions

View File

@ -101,7 +101,7 @@
(define-method save_uri
(of-object "SugarBrowser")
(c-name "sugar_browser_save_uri")
(return-type "none")
(return-type "gboolean")
(parameters
'("const-char*" "uri")
'("const-char*" "filename")
@ -111,7 +111,7 @@
(define-method save_document
(of-object "SugarBrowser")
(c-name "sugar_browser_save_document")
(return-type "none")
(return-type "gboolean")
(parameters
'("const-char*" "filename")
)

View File

@ -11,6 +11,7 @@ libsugarprivate_la_CPPFLAGS = \
-I$(MOZILLA_INCLUDE_DIR)/pref \
-I$(MOZILLA_INCLUDE_DIR)/uriloader \
-I$(MOZILLA_INCLUDE_DIR)/webbrwsr \
-I$(MOZILLA_INCLUDE_DIR)/webbrowserpersist \
-DPLUGIN_DIR=\"$(libdir)/mozilla/plugins\" \
-DSHARE_DIR=\"$(pkgdatadir)\"

View File

@ -32,6 +32,7 @@
#include <nsILocalFile.h>
#include <nsIWebBrowser.h>
#include <nsIWebBrowserFocus.h>
#include <nsIWebBrowserPersist.h>
#include <nsIDOMWindow.h>
#include <nsIDOMMouseEvent.h>
#include <nsIGenericFactory.h>
@ -40,6 +41,8 @@
#include <nsIDOMNode.h>
#include <nsIDOMEventTarget.h>
#include <nsIDOMHTMLImageElement.h>
#include <nsIIOService.h>
#include <nsComponentManagerUtils.h>
enum {
PROP_0,
@ -484,14 +487,53 @@ sugar_browser_grab_focus(SugarBrowser *browser)
}
}
void
nsresult
NewURI(const char *uri, nsIURI **result)
{
nsresult rv;
nsCOMPtr<nsIServiceManager> mgr;
NS_GetServiceManager (getter_AddRefs (mgr));
NS_ENSURE_TRUE(mgr, FALSE);
nsCOMPtr<nsIIOService> ioService;
rv = mgr->GetServiceByContractID ("@mozilla.org/network/io-service;1",
NS_GET_IID (nsIIOService),
getter_AddRefs(ioService));
NS_ENSURE_SUCCESS(rv, FALSE);
nsCString cSpec(uri);
return ioService->NewURI (cSpec, nsnull, nsnull, result);
}
gboolean
sugar_browser_save_uri(SugarBrowser *browser,
const char *uri,
const char *filename)
{
nsresult rv;
nsCOMPtr<nsIURI> sourceURI;
rv = NewURI(uri, getter_AddRefs(sourceURI));
NS_ENSURE_SUCCESS(rv, FALSE);
nsCOMPtr<nsILocalFile> destFile = do_CreateInstance(NS_LOCAL_FILE_CONTRACTID);
NS_ENSURE_TRUE(destFile, FALSE);
destFile->InitWithNativePath(nsCString(filename));
nsCOMPtr<nsIWebBrowser> webBrowser;
gtk_moz_embed_get_nsIWebBrowser(GTK_MOZ_EMBED(browser),
getter_AddRefs(webBrowser));
NS_ENSURE_TRUE(webBrowser, FALSE);
nsCOMPtr<nsIWebBrowserPersist> webPersist = do_QueryInterface (webBrowser);
NS_ENSURE_TRUE(webPersist, FALSE);
rv = webPersist->SaveURI(sourceURI, nsnull, nsnull, nsnull, nsnull, destFile);
}
void
gboolean
sugar_browser_save_document(SugarBrowser *browser,
const char *filename)
{

View File

@ -63,10 +63,10 @@ void sugar_browser_scroll_pixels (SugarBrowser *browser,
int dx,
int dy);
void sugar_browser_grab_focus (SugarBrowser *browser);
void sugar_browser_save_uri (SugarBrowser *browser,
gboolean sugar_browser_save_uri (SugarBrowser *browser,
const char *uri,
const char *filename);
void sugar_browser_save_document (SugarBrowser *browser,
gboolean sugar_browser_save_document (SugarBrowser *browser,
const char *filename);
gboolean sugar_browser_startup (const char *profile_path,