Created SugarBrowserChandler, for signaling when the browser has downloaded a file that cannot handle himself.
This commit is contained in:
parent
60fd7fb810
commit
dade0fbabc
@ -103,5 +103,12 @@ def start():
|
||||
|
||||
style.load_stylesheet(web.stylesheet)
|
||||
|
||||
chandler = _sugar.get_browser_chandler()
|
||||
chandler.connect('handle-content', handle_content_cb)
|
||||
logging.debug('handle-content connected.')
|
||||
|
||||
def stop():
|
||||
gtkmozembed.pop_startup()
|
||||
|
||||
def handle_content_cb(chandler, url, suggestedFileName, mimeType, tmpFileName):
|
||||
logging.debug('File ' + tmpFileName + ' with MIMEType ' + mimeType + ' downloaded from ' + url)
|
||||
|
@ -35,6 +35,13 @@
|
||||
(gtype-id "SUGAR_TYPE_PUSH_SCROLLER")
|
||||
)
|
||||
|
||||
(define-object BrowserChandler
|
||||
(in-module "Sugar")
|
||||
(parent "GObject")
|
||||
(c-name "SugarBrowserChandler")
|
||||
(gtype-id "SUGAR_TYPE_BROWSER_CHANDLER")
|
||||
)
|
||||
|
||||
;; Enumerations and flags ...
|
||||
|
||||
|
||||
@ -173,3 +180,15 @@
|
||||
'("guint32" "timestamp")
|
||||
)
|
||||
)
|
||||
|
||||
;; From sugar-browser-chandler.h
|
||||
|
||||
(define-function sugar_browser_chandler_get_type
|
||||
(c-name "sugar_browser_chandler_get_type")
|
||||
(return-type "GType")
|
||||
)
|
||||
|
||||
(define-function get_browser_chandler
|
||||
(c-name "sugar_get_browser_chandler")
|
||||
(return-type "SugarBrowserChandler*")
|
||||
)
|
||||
|
@ -9,6 +9,7 @@ headers
|
||||
#include "sugar-address-entry.h"
|
||||
#include "sugar-tray-manager.h"
|
||||
#include "sugar-push-scroller.h"
|
||||
#include "sugar-browser-chandler.h"
|
||||
|
||||
%%
|
||||
modulename gecko
|
||||
|
@ -1,3 +1,10 @@
|
||||
INCLUDES = \
|
||||
$(WARN_CFLAGS) \
|
||||
$(LIB_CFLAGS) \
|
||||
-I$(MOZILLA_INCLUDE_DIR)/exthandler \
|
||||
-I$(MOZILLA_INCLUDE_DIR)/mimetype \
|
||||
-I$(MOZILLA_INCLUDE_DIR)/necko
|
||||
|
||||
noinst_LTLIBRARIES = libsugarprivate.la
|
||||
|
||||
libsugarprivate_la_LIBADD = $(GECKO_LIBS)
|
||||
@ -6,12 +13,14 @@ libsugarprivate_la_SOURCES = \
|
||||
$(BUILT_SOURCES) \
|
||||
eggaccelerators.h \
|
||||
eggaccelerators.c \
|
||||
sugar-browser.h \
|
||||
sugar-browser.cpp \
|
||||
sugar-content-handler.h \
|
||||
sugar-content-handler.cpp \
|
||||
sugar-address-entry.h \
|
||||
sugar-address-entry.c \
|
||||
sugar-browser.h \
|
||||
sugar-browser.cpp \
|
||||
sugar-browser-chandler.h \
|
||||
sugar-browser-chandler.c \
|
||||
sugar-content-handler.h \
|
||||
sugar-content-handler.cpp \
|
||||
sugar-key-grabber.h \
|
||||
sugar-key-grabber.c \
|
||||
sugar-push-scroller.c \
|
||||
@ -19,12 +28,6 @@ libsugarprivate_la_SOURCES = \
|
||||
sugar-tray-manager.c \
|
||||
sugar-tray-manager.h
|
||||
|
||||
libsugarprivate_la_CPPFLAGS = \
|
||||
$(WARN_CFLAGS) \
|
||||
$(LIB_CFLAGS) \
|
||||
-I$(MOZILLA_INCLUDE_DIR)/exthandler \
|
||||
-DSHARE_DIR=\"$(pkgdatadir)\"
|
||||
|
||||
BUILT_SOURCES = \
|
||||
sugar-marshal.c \
|
||||
sugar-marshal.h
|
||||
|
57
lib/src/sugar-browser-chandler.c
Normal file
57
lib/src/sugar-browser-chandler.c
Normal file
@ -0,0 +1,57 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "sugar-marshal.h"
|
||||
#include "sugar-browser-chandler.h"
|
||||
|
||||
G_DEFINE_TYPE(SugarBrowserChandler, sugar_browser_chandler, G_TYPE_OBJECT)
|
||||
|
||||
SugarBrowserChandler *browserChandler = NULL;
|
||||
|
||||
static void
|
||||
sugar_browser_chandler_init(SugarBrowserChandler *browserChandler)
|
||||
{
|
||||
}
|
||||
|
||||
static void
|
||||
sugar_browser_chandler_class_init(SugarBrowserChandlerClass *browser_chandler_class)
|
||||
{
|
||||
browser_chandler_class->handle_content_signal_id =
|
||||
g_signal_new ("handle-content",
|
||||
G_OBJECT_CLASS_TYPE (browser_chandler_class),
|
||||
G_SIGNAL_RUN_LAST,
|
||||
G_STRUCT_OFFSET (SugarBrowserChandlerClass, handle_content),
|
||||
NULL, NULL,
|
||||
sugar_marshal_VOID__STRING_STRING_STRING_STRING,
|
||||
G_TYPE_NONE, 4,
|
||||
G_TYPE_STRING,
|
||||
G_TYPE_STRING,
|
||||
G_TYPE_STRING,
|
||||
G_TYPE_STRING);
|
||||
}
|
||||
|
||||
SugarBrowserChandler *
|
||||
sugar_get_browser_chandler()
|
||||
{
|
||||
if(browserChandler == NULL)
|
||||
browserChandler = g_object_new(SUGAR_TYPE_BROWSER_CHANDLER, NULL);
|
||||
|
||||
return browserChandler;
|
||||
}
|
||||
|
||||
void
|
||||
sugar_browser_chandler_handle_content (SugarBrowserChandler *browser_chandler,
|
||||
const char *url,
|
||||
const char *suggested_file_name,
|
||||
const char *mime_type,
|
||||
const char *tmp_file_name)
|
||||
{
|
||||
g_signal_emit(browser_chandler,
|
||||
SUGAR_BROWSER_CHANDLER_GET_CLASS(
|
||||
browser_chandler)->handle_content_signal_id,
|
||||
0 /* details */,
|
||||
url,
|
||||
suggested_file_name,
|
||||
mime_type,
|
||||
tmp_file_name);
|
||||
}
|
56
lib/src/sugar-browser-chandler.h
Normal file
56
lib/src/sugar-browser-chandler.h
Normal file
@ -0,0 +1,56 @@
|
||||
#ifndef __SUGAR_BROWSER_CHANDLER_H__
|
||||
#define __SUGAR_BROWSER_CHANDLER_H__
|
||||
|
||||
#include <glib-object.h>
|
||||
#include <glib.h>
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
typedef struct _SugarBrowserChandler SugarBrowserChandler;
|
||||
typedef struct _SugarBrowserChandlerClass SugarBrowserChandlerClass;
|
||||
|
||||
#define SUGAR_TYPE_BROWSER_CHANDLER ( \
|
||||
sugar_browser_chandler_get_type())
|
||||
#define SUGAR_BROWSER_CHANDLER(object) ( \
|
||||
G_TYPE_CHECK_INSTANCE_CAST((object), \
|
||||
SUGAR_TYPE_BROWSER_CHANDLER, SugarBrowserChandler))
|
||||
#define SUGAR_BROWSER_CHANDLER_CLASS(klass) ( \
|
||||
G_TYPE_CHECK_CLASS_CAST((klass), \
|
||||
SUGAR_TYPE_BROWSER_CHANDLER, \
|
||||
SugarBrowserChandlerClass))
|
||||
#define SUGAR_IS_BROWSER_CHANDLER(object) ( \
|
||||
G_TYPE_CHECK_INSTANCE_TYPE((object), \
|
||||
SUGAR_TYPE_BROWSER_CHANDLER))
|
||||
#define SUGAR_IS_BROWSER_CHANDLER_CLASS(klass) ( \
|
||||
G_TYPE_CHECK_CLASS_TYPE((klass), \
|
||||
SUGAR_TYPE_BROWSER_CHANDLER))
|
||||
#define SUGAR_BROWSER_CHANDLER_GET_CLASS(object) ( \
|
||||
G_TYPE_INSTANCE_GET_CLASS((object), \
|
||||
SUGAR_TYPE_BROWSER_CHANDLER, \
|
||||
SugarBrowserChandlerClass))
|
||||
|
||||
struct _SugarBrowserChandler {
|
||||
GObject base_instance;
|
||||
};
|
||||
|
||||
struct _SugarBrowserChandlerClass {
|
||||
GObjectClass base_class;
|
||||
|
||||
guint handle_content_signal_id;
|
||||
|
||||
void (* handle_content) (char *url, char *tmp_file_name);
|
||||
|
||||
};
|
||||
|
||||
GType sugar_browser_chandler_get_type (void);
|
||||
SugarBrowserChandler *sugar_get_browser_chandler ();
|
||||
void sugar_browser_chandler_handle_content (
|
||||
SugarBrowserChandler *browser_chandler,
|
||||
const char *url,
|
||||
const char *suggested_file_name,
|
||||
const char *mime_type,
|
||||
const char *tmp_file_name);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif
|
@ -1,5 +1,13 @@
|
||||
#include <stdio.h>
|
||||
|
||||
#include <nsStringAPI.h>
|
||||
#include <nsCExternalHandlerService.h>
|
||||
#include <nsIMIMEInfo.h>
|
||||
#include <nsIURL.h>
|
||||
#include <nsIFile.h>
|
||||
|
||||
#include "sugar-browser-chandler.h"
|
||||
|
||||
#include "sugar-content-handler.h"
|
||||
|
||||
GSugarContentHandler::GSugarContentHandler()
|
||||
@ -19,6 +27,42 @@ GSugarContentHandler::Show (nsIHelperAppLauncher *aLauncher,
|
||||
nsISupports *aContext,
|
||||
PRUint32 aReason)
|
||||
{
|
||||
SugarBrowserChandler *browser_chandler;
|
||||
nsresult rv;
|
||||
nsCString url;
|
||||
nsCString mimeType;
|
||||
nsString suggested_file_name_utf16;
|
||||
nsCString suggested_file_name;
|
||||
nsCString tmp_file_name;
|
||||
|
||||
NS_ENSURE_TRUE (aLauncher, NS_ERROR_FAILURE);
|
||||
|
||||
nsCOMPtr<nsIMIMEInfo> MIMEInfo;
|
||||
aLauncher->GetMIMEInfo (getter_AddRefs(MIMEInfo));
|
||||
NS_ENSURE_TRUE (MIMEInfo, NS_ERROR_FAILURE);
|
||||
|
||||
rv = MIMEInfo->GetMIMEType (mimeType);
|
||||
|
||||
nsCOMPtr<nsIURI> uri;
|
||||
aLauncher->GetSource (getter_AddRefs(uri));
|
||||
NS_ENSURE_TRUE (uri, NS_ERROR_FAILURE);
|
||||
|
||||
uri->GetSpec (url);
|
||||
|
||||
aLauncher->GetSuggestedFileName (suggested_file_name_utf16);
|
||||
NS_UTF16ToCString (suggested_file_name_utf16,
|
||||
NS_CSTRING_ENCODING_UTF8, suggested_file_name);
|
||||
|
||||
nsCOMPtr<nsIFile> tmp_file;
|
||||
aLauncher->GetTargetFile(getter_AddRefs(tmp_file));
|
||||
tmp_file->GetNativeLeafName (tmp_file_name);
|
||||
|
||||
browser_chandler = sugar_get_browser_chandler();
|
||||
sugar_browser_chandler_handle_content(browser_chandler,
|
||||
url.get(),
|
||||
suggested_file_name.get(),
|
||||
mimeType.get(),
|
||||
tmp_file_name.get());
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
@ -1,2 +1,3 @@
|
||||
VOID:OBJECT,STRING,LONG,LONG
|
||||
VOID:OBJECT,LONG
|
||||
VOID:STRING,STRING,STRING,STRING
|
||||
|
Loading…
Reference in New Issue
Block a user