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.4 2005/05/28 14:10:55 chpe 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-persist.h>
35 #include <epiphany/ephy-shell.h>
36 #include <epiphany/ephy-node.h>
37 #include <epiphany/ephy-bookmarks.h>
38 #include <epiphany/ephy-window.h>
39 #include <epiphany/ephy-embed.h>
40 #include <epiphany/ephy-tab.h>
44 #define EPHY_BEAGLE_EXTENSION_GET_PRIVATE(object) (G_TYPE_INSTANCE_GET_PRIVATE ((object), EPHY_TYPE_BEAGLE_EXTENSION, EphyBeagleExtensionPrivate))
46 struct EphyBeagleExtensionPrivate
51 static GObjectClass
*parent_class
= NULL
;
52 static GType type
= 0;
55 load_status_cb (EphyTab
*tab
,
57 EphyBeagleExtension
*extension
)
61 /* Don't index web pages if this environment variable is set. */
62 if (getenv ("BEAGLE_NO_WEB_INDEXING") != NULL
)
65 load_status
= ephy_tab_get_load_status(tab
);
67 /* FALSE means load is finished */
68 if (load_status
== FALSE
)
71 EphyEmbedPersist
*persist
;
73 const char *page_title
;
78 embed
= ephy_tab_get_embed (tab
);
79 g_return_if_fail (EPHY_IS_EMBED (embed
));
81 /* Get the URL from the embed, since tab may contain modified url */
82 location
= ephy_embed_get_location (embed
, TRUE
);
85 page_title
= ephy_tab_get_title(tab
);
87 /* Get the page content. */
88 persist
= EPHY_EMBED_PERSIST (ephy_embed_factory_new_object (EPHY_TYPE_EMBED_PERSIST
));
89 ephy_embed_persist_set_embed (persist
, embed
);
90 ephy_embed_persist_set_flags (persist
, EPHY_EMBED_PERSIST_NO_VIEW
);
91 content
= ephy_embed_persist_to_string (persist
);
92 g_object_unref (persist
);
94 argv
[0] = "beagle-index-url";
98 argv
[4] = (char *) page_title
;
101 if (g_spawn_async_with_pipes (NULL
, /* inherit parent's working directory */
103 NULL
, /* inherit parent's environment */
105 NULL
, NULL
, /* no special child setup needed */
106 NULL
, /* don't need the child pid */
108 NULL
, NULL
, /* don't need access to child stdout/stderr */
111 FILE *to_child
= fdopen (child_stdin
, "w");
112 if (to_child
!= NULL
)
114 fprintf (to_child
, "%s\n", content
);
124 impl_attach_tab (EphyExtension
*extension
,
128 g_signal_connect_after (tab
, "notify::load-status",
129 G_CALLBACK (load_status_cb
), extension
);
133 impl_detach_tab (EphyExtension
*extension
,
137 g_signal_handlers_disconnect_by_func
138 (tab
, G_CALLBACK (load_status_cb
), extension
);
142 impl_attach_window (EphyExtension
*ext
,
148 impl_detach_window (EphyExtension
*ext
,
154 ephy_beagle_extension_init (EphyBeagleExtension
*extension
)
156 extension
->priv
= EPHY_BEAGLE_EXTENSION_GET_PRIVATE (extension
);
160 ephy_beagle_extension_iface_init (EphyExtensionIface
*iface
)
162 iface
->attach_window
= impl_attach_window
;
163 iface
->detach_window
= impl_detach_window
;
164 iface
->attach_tab
= impl_attach_tab
;
165 iface
->detach_tab
= impl_detach_tab
;
169 ephy_beagle_extension_class_init (EphyBeagleExtensionClass
*klass
)
171 GObjectClass
*object_class
= G_OBJECT_CLASS (klass
);
173 parent_class
= (GObjectClass
*) g_type_class_peek_parent (klass
);
175 g_type_class_add_private (object_class
, sizeof (EphyBeagleExtensionPrivate
));
179 ephy_beagle_extension_get_type (void)
185 ephy_beagle_extension_register_type (GTypeModule
*module
)
187 static const GTypeInfo our_info
=
189 sizeof (EphyBeagleExtensionClass
),
190 NULL
, /* base_init */
191 NULL
, /* base_finalize */
192 (GClassInitFunc
) ephy_beagle_extension_class_init
,
194 NULL
, /* class_data */
195 sizeof (EphyBeagleExtension
),
197 (GInstanceInitFunc
) ephy_beagle_extension_init
200 static const GInterfaceInfo extension_info
=
202 (GInterfaceInitFunc
) ephy_beagle_extension_iface_init
,
207 type
= g_type_module_register_type (module
,
212 g_type_module_add_interface (module
,