Open "requested" popups in a new activity

This commit is contained in:
Marco Pesenti Gritti 2006-09-27 14:45:55 +02:00
parent 7443ee4c8b
commit df6dd4618b
8 changed files with 128 additions and 7 deletions

View File

@ -2,6 +2,7 @@ import os
import gtk import gtk
import gtkmozembed import gtkmozembed
import gobject
from sugar.activity.Activity import Activity from sugar.activity.Activity import Activity
from sugar.presence.PresenceService import PresenceService from sugar.presence.PresenceService import PresenceService
@ -13,6 +14,16 @@ from NotificationBar import NotificationBar
from NavigationToolbar import NavigationToolbar from NavigationToolbar import NavigationToolbar
from sugar import env from sugar import env
class Browser(gecko.Browser):
__gtype_name__ = "SugarBrowser"
def __init__(self):
gecko.Browser.__init__(self)
def do_create_window(self):
activity = BrowserActivity()
activity.set_type('com.redhat.Sugar.BrowserActivity')
return activity.get_embed()
class BrowserActivity(Activity): class BrowserActivity(Activity):
def __init__(self): def __init__(self):
Activity.__init__(self) Activity.__init__(self)
@ -35,7 +46,7 @@ class BrowserActivity(Activity):
vbox.pack_start(self._notif_bar, False) vbox.pack_start(self._notif_bar, False)
self._notif_bar.connect('action', self.__notif_bar_action_cb) self._notif_bar.connect('action', self.__notif_bar_action_cb)
self._embed = gtkmozembed.MozEmbed() self._embed = Browser()
self._embed.connect("title", self.__title_cb) self._embed.connect("title", self.__title_cb)
vbox.pack_start(self._embed) vbox.pack_start(self._embed)
self._embed.show() self._embed.show()

View File

@ -26,6 +26,7 @@ EXTRA_DIST = gecko.override gecko.defs
.defs.c: .defs.c:
(cd $(srcdir)\ (cd $(srcdir)\
&& $(PYGTK_CODEGEN) \ && $(PYGTK_CODEGEN) \
--register $(GNOMEPYTHONEXTRAS_DEFSDIR)/gtkmozembed.defs \
--override $*.override \ --override $*.override \
--prefix py$* $*.defs) > gen-$*.c \ --prefix py$* $*.defs) > gen-$*.c \
&& cp gen-$*.c $*.c \ && cp gen-$*.c $*.c \

View File

@ -23,7 +23,7 @@
#include <nsServiceManagerUtils.h> #include <nsServiceManagerUtils.h>
void void
gecko_startup(void) gecko_browser_startup(void)
{ {
nsCOMPtr<nsIPrefService> prefService; nsCOMPtr<nsIPrefService> prefService;
@ -36,3 +36,43 @@ gecko_startup(void)
pref->SetBoolPref ("dom.disable_open_during_load", TRUE); pref->SetBoolPref ("dom.disable_open_during_load", TRUE);
} }
G_DEFINE_TYPE(GeckoBrowser, gecko_browser, GTK_TYPE_MOZ_EMBED)
//static guint signals[N_SIGNALS];
GeckoBrowser *
gecko_browser_new(void)
{
return GECKO_BROWSER(g_object_new(GECKO_TYPE_BROWSER, NULL));
}
static void
gecko_browser_class_init(GeckoBrowserClass *browser_class)
{
}
GeckoBrowser *
gecko_browser_create_window(GeckoBrowser *browser)
{
return GECKO_BROWSER_GET_CLASS(browser)->create_window(browser);
}
static void
gecko_browser_new_window_cb(GtkMozEmbed *embed,
GtkMozEmbed **newEmbed,
guint chromemask)
{
GeckoBrowser *browser;
browser = gecko_browser_create_window(GECKO_BROWSER(embed));
*newEmbed = GTK_MOZ_EMBED(browser);
}
static void
gecko_browser_init(GeckoBrowser *browser)
{
g_signal_connect(G_OBJECT(browser), "new-window",
G_CALLBACK(gecko_browser_new_window_cb), NULL);
}

View File

@ -19,11 +19,35 @@
#ifndef __GECKO_BROWSER_H__ #ifndef __GECKO_BROWSER_H__
#define __GECKO_BROWSER_H__ #define __GECKO_BROWSER_H__
#include <glib.h> #include <gtkmozembed.h>
G_BEGIN_DECLS G_BEGIN_DECLS
void gecko_startup (void); typedef struct _GeckoBrowser GeckoBrowser;
typedef struct _GeckoBrowserClass GeckoBrowserClass;
typedef struct _GeckoBrowserPrivate GeckoBrowserPrivate;
#define GECKO_TYPE_BROWSER (gecko_browser_get_type())
#define GECKO_BROWSER(object) (G_TYPE_CHECK_INSTANCE_CAST((object), GECKO_TYPE_BROWSER, GeckoBrowser))
#define GECKO_BROWSER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), GECKO_TYPE_BROWSER, GeckoBrowserClass))
#define GECKO_IS_BROWSER(object) (G_TYPE_CHECK_INSTANCE_TYPE((object), GECKO_TYPE_BROWSER))
#define GECKO_IS_BROWSER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), GECKO_TYPE_BROWSER))
#define GECKO_BROWSER_GET_CLASS(object) (G_TYPE_INSTANCE_GET_CLASS((object), GECKO_TYPE_BROWSER, GeckoBrowserClass))
struct _GeckoBrowser {
GtkMozEmbed base_instance;
};
struct _GeckoBrowserClass {
GtkMozEmbedClass base_class;
GeckoBrowser * (* create_window) (GeckoBrowser *browser);
};
GType gecko_browser_get_type (void);
void gecko_browser_startup (void);
GeckoBrowser *gecko_browser_new (void);
GeckoBrowser *gecko_browser_create_window (GeckoBrowser *browser);
G_END_DECLS G_END_DECLS

View File

@ -1,13 +1,40 @@
;; -*- scheme -*- ;; -*- scheme -*-
; object definitions ... ; object definitions ...
(define-object Browser
(in-module "Gecko")
(parent "GtkMozEmbed")
(c-name "GeckoBrowser")
(gtype-id "GECKO_TYPE_BROWSER")
)
;; Enumerations and flags ... ;; Enumerations and flags ...
;; From sugar-browser.h ;; From gecko-browser.h
(define-function get_type
(c-name "gecko_browser_get_type")
(return-type "GType")
)
(define-function startup (define-function startup
(c-name "gecko_startup") (c-name "gecko_browser_startup")
(return-type "none") (return-type "none")
) )
(define-function new
(c-name "gecko_browser_new")
(is-constructor-of "GeckoBrowser")
(return-type "GeckoBrowser*")
)
(define-method create_window
(of-object "GeckoBrowser")
(c-name "gecko_browser_create_window")
(return-type "GeckoBrowser*")
)
(define-virtual create_window
(of-object "GeckoBrowser")
(return-type "GeckoBrowser*")
)

View File

@ -3,5 +3,16 @@
headers headers
#include <Python.h> #include <Python.h>
#include "pygobject.h"
#include "gecko-browser.h" #include "gecko-browser.h"
%%
modulename gecko
%%
import gobject.GObject as PyGObject_Type
import gtkmozembed.MozEmbed as PyGtkMozEmbed_Type
%%
ignore-glob
*_get_type
_*
%% %%

View File

@ -5,6 +5,8 @@
/* include this first, before NO_IMPORT_PYGOBJECT is defined */ /* include this first, before NO_IMPORT_PYGOBJECT is defined */
#include <pygobject.h> #include <pygobject.h>
void pygecko_register_classes (PyObject *d);
extern PyMethodDef pygecko_functions[]; extern PyMethodDef pygecko_functions[];
DL_EXPORT(void) DL_EXPORT(void)
@ -17,6 +19,8 @@ initgecko(void)
m = Py_InitModule ("gecko", pygecko_functions); m = Py_InitModule ("gecko", pygecko_functions);
d = PyModule_GetDict (m); d = PyModule_GetDict (m);
pygecko_register_classes (d);
if (PyErr_Occurred ()) { if (PyErr_Occurred ()) {
Py_FatalError ("can't initialise module globalkeys"); Py_FatalError ("can't initialise module globalkeys");
} }

View File

@ -23,7 +23,10 @@ AC_PATH_PROG(PYGTK_CODEGEN, pygtk-codegen-2.0, no)
PKG_CHECK_MODULES(PYGTK, pygtk-2.0) PKG_CHECK_MODULES(PYGTK, pygtk-2.0)
PKG_CHECK_MODULES(GLOBALKEYS, gdk-2.0) PKG_CHECK_MODULES(GLOBALKEYS, gdk-2.0)
PKG_CHECK_MODULES(GECKO, xulrunner-gtkmozembed) PKG_CHECK_MODULES(GECKO, gtk+-2.0 xulrunner-gtkmozembed)
GNOMEPYTHONEXTRAS_DEFSDIR=`$PKG_CONFIG --variable=defsdir pygtk-2.0`
AC_SUBST(GNOMEPYTHONEXTRAS_DEFSDIR)
# #
# Setup GETTEXT # Setup GETTEXT