Show total number of results for google driver too. Helps to know if my query resulte...
[beagle.git] / epiphany-extension / ephy-beagle-extension.c
blobbb72e6a957a9d16c03373c45d462db52f5e8d0b8
1 /*
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)
9 * any later version.
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.
27 #ifdef HAVE_CONFIG_H
28 #include "config.h"
29 #endif
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>
43 #include <gmodule.h>
45 #define EPHY_BEAGLE_EXTENSION_GET_PRIVATE(object) (G_TYPE_INSTANCE_GET_PRIVATE ((object), EPHY_TYPE_BEAGLE_EXTENSION, EphyBeagleExtensionPrivate))
47 struct EphyBeagleExtensionPrivate
49 gpointer dummy;
52 static GObjectClass *parent_class = NULL;
53 static GType type = 0;
55 static void
56 load_status_cb (EphyTab *tab,
57 GParamSpec *pspec,
58 EphyBeagleExtension *extension)
60 gboolean load_status;
62 /* Don't index web pages if this environment variable is set. */
63 if (getenv ("BEAGLE_NO_WEB_INDEXING") != NULL)
64 return;
66 load_status = ephy_tab_get_load_status(tab);
68 /* FALSE means load is finished */
69 if (load_status == FALSE)
71 EphyEmbed *embed;
72 EphyEmbedPersist *persist;
73 char *location;
74 const char *page_title;
75 char *content;
76 int child_stdin;
77 char *argv[6];
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);
85 /* Get page title */
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";
96 argv[1] = "--url";
97 argv[2] = location;
98 argv[3] = "--title";
99 argv[4] = (char *) page_title;
100 argv[5] = NULL;
102 if (g_spawn_async_with_pipes (NULL, /* inherit parent's working directory */
103 argv,
104 NULL, /* inherit parent's environment */
105 G_SPAWN_SEARCH_PATH,
106 NULL, NULL, /* no special child setup needed */
107 NULL, /* don't need the child pid */
108 &child_stdin,
109 NULL, NULL, /* don't need access to child stdout/stderr */
110 NULL))
112 FILE *to_child = fdopen (child_stdin, "w");
113 if (to_child != NULL)
115 fprintf (to_child, "%s\n", content);
116 fclose (to_child);
120 g_free (location);
124 static void
125 impl_attach_tab (EphyExtension *extension,
126 EphyWindow *window,
127 EphyTab *tab)
129 g_signal_connect_after (tab, "notify::load-status",
130 G_CALLBACK (load_status_cb), extension);
133 static void
134 impl_detach_tab (EphyExtension *extension,
135 EphyWindow *window,
136 EphyTab *tab)
138 g_signal_handlers_disconnect_by_func
139 (tab, G_CALLBACK (load_status_cb), extension);
142 static void
143 impl_attach_window (EphyExtension *ext,
144 EphyWindow *window)
148 static void
149 impl_detach_window (EphyExtension *ext,
150 EphyWindow *window)
154 static void
155 ephy_beagle_extension_init (EphyBeagleExtension *extension)
157 extension->priv = EPHY_BEAGLE_EXTENSION_GET_PRIVATE (extension);
160 static void
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;
169 static void
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));
179 GType
180 ephy_beagle_extension_get_type (void)
182 return type;
185 GType
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,
194 NULL,
195 NULL, /* class_data */
196 sizeof (EphyBeagleExtension),
197 0, /* n_preallocs */
198 (GInstanceInitFunc) ephy_beagle_extension_init
201 static const GInterfaceInfo extension_info =
203 (GInterfaceInitFunc) ephy_beagle_extension_iface_init,
204 NULL,
205 NULL
208 type = g_type_module_register_type (module,
209 G_TYPE_OBJECT,
210 "BeagleExtension",
211 &our_info, 0);
213 g_type_module_add_interface (module,
214 type,
215 EPHY_TYPE_EXTENSION,
216 &extension_info);
218 return type;