2 * Copyright (C) 2003 Marco Pesenti Gritti
3 * Copyright (C) 2003, 2004, 2005 Christian Persch
4 * Copyright (C) 2003, 2004 Lee Willis
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2, or (at your option)
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 * $Id: ephy-beagle-extension.c,v 1.5 2005/12/02 17:01:36 joeshaw Exp $
24 This is all copied from Dashboard's Epiphany Extension.
31 #include "ephy-beagle-extension.h"
33 #include <epiphany/ephy-extension.h>
34 #include <epiphany/ephy-embed-factory.h>
35 #include <epiphany/ephy-embed-persist.h>
36 #include <epiphany/ephy-shell.h>
37 #include <epiphany/ephy-node.h>
38 #include <epiphany/ephy-bookmarks.h>
39 #include <epiphany/ephy-window.h>
40 #include <epiphany/ephy-embed.h>
41 #include <epiphany/ephy-tab.h>
45 #define EPHY_BEAGLE_EXTENSION_GET_PRIVATE(object) (G_TYPE_INSTANCE_GET_PRIVATE ((object), EPHY_TYPE_BEAGLE_EXTENSION, EphyBeagleExtensionPrivate))
47 struct EphyBeagleExtensionPrivate
52 static GObjectClass
*parent_class
= NULL
;
53 static GType type
= 0;
56 load_status_cb (EphyTab
*tab
,
58 EphyBeagleExtension
*extension
)
62 /* Don't index web pages if this environment variable is set. */
63 if (getenv ("BEAGLE_NO_WEB_INDEXING") != NULL
)
66 load_status
= ephy_tab_get_load_status(tab
);
68 /* FALSE means load is finished */
69 if (load_status
== FALSE
)
72 EphyEmbedPersist
*persist
;
74 const char *page_title
;
79 embed
= ephy_tab_get_embed (tab
);
80 g_return_if_fail (EPHY_IS_EMBED (embed
));
82 /* Get the URL from the embed, since tab may contain modified url */
83 location
= ephy_embed_get_location (embed
, TRUE
);
86 page_title
= ephy_tab_get_title(tab
);
88 /* Get the page content. */
89 persist
= EPHY_EMBED_PERSIST (ephy_embed_factory_new_object (EPHY_TYPE_EMBED_PERSIST
));
90 ephy_embed_persist_set_embed (persist
, embed
);
91 ephy_embed_persist_set_flags (persist
, EPHY_EMBED_PERSIST_NO_VIEW
);
92 content
= ephy_embed_persist_to_string (persist
);
93 g_object_unref (persist
);
95 argv
[0] = "beagle-index-url";
99 argv
[4] = (char *) page_title
;
102 if (g_spawn_async_with_pipes (NULL
, /* inherit parent's working directory */
104 NULL
, /* inherit parent's environment */
106 NULL
, NULL
, /* no special child setup needed */
107 NULL
, /* don't need the child pid */
109 NULL
, NULL
, /* don't need access to child stdout/stderr */
112 FILE *to_child
= fdopen (child_stdin
, "w");
113 if (to_child
!= NULL
)
115 fprintf (to_child
, "%s\n", content
);
125 impl_attach_tab (EphyExtension
*extension
,
129 g_signal_connect_after (tab
, "notify::load-status",
130 G_CALLBACK (load_status_cb
), extension
);
134 impl_detach_tab (EphyExtension
*extension
,
138 g_signal_handlers_disconnect_by_func
139 (tab
, G_CALLBACK (load_status_cb
), extension
);
143 impl_attach_window (EphyExtension
*ext
,
149 impl_detach_window (EphyExtension
*ext
,
155 ephy_beagle_extension_init (EphyBeagleExtension
*extension
)
157 extension
->priv
= EPHY_BEAGLE_EXTENSION_GET_PRIVATE (extension
);
161 ephy_beagle_extension_iface_init (EphyExtensionIface
*iface
)
163 iface
->attach_window
= impl_attach_window
;
164 iface
->detach_window
= impl_detach_window
;
165 iface
->attach_tab
= impl_attach_tab
;
166 iface
->detach_tab
= impl_detach_tab
;
170 ephy_beagle_extension_class_init (EphyBeagleExtensionClass
*klass
)
172 GObjectClass
*object_class
= G_OBJECT_CLASS (klass
);
174 parent_class
= (GObjectClass
*) g_type_class_peek_parent (klass
);
176 g_type_class_add_private (object_class
, sizeof (EphyBeagleExtensionPrivate
));
180 ephy_beagle_extension_get_type (void)
186 ephy_beagle_extension_register_type (GTypeModule
*module
)
188 static const GTypeInfo our_info
=
190 sizeof (EphyBeagleExtensionClass
),
191 NULL
, /* base_init */
192 NULL
, /* base_finalize */
193 (GClassInitFunc
) ephy_beagle_extension_class_init
,
195 NULL
, /* class_data */
196 sizeof (EphyBeagleExtension
),
198 (GInstanceInitFunc
) ephy_beagle_extension_init
201 static const GInterfaceInfo extension_info
=
203 (GInterfaceInitFunc
) ephy_beagle_extension_iface_init
,
208 type
= g_type_module_register_type (module
,
213 g_type_module_add_interface (module
,