Thumbnail file hits. Based on a patch from D Bera
[beagle.git] / epiphany-extension / ephy-beagle-extension.c
blob23a7f89e315251c124b6e02057e6badee0a3b67d
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.4 2005/05/28 14:10:55 chpe 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-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>
42 #include <gmodule.h>
44 #define EPHY_BEAGLE_EXTENSION_GET_PRIVATE(object) (G_TYPE_INSTANCE_GET_PRIVATE ((object), EPHY_TYPE_BEAGLE_EXTENSION, EphyBeagleExtensionPrivate))
46 struct EphyBeagleExtensionPrivate
48 gpointer dummy;
51 static GObjectClass *parent_class = NULL;
52 static GType type = 0;
54 static void
55 load_status_cb (EphyTab *tab,
56 GParamSpec *pspec,
57 EphyBeagleExtension *extension)
59 gboolean load_status;
61 /* Don't index web pages if this environment variable is set. */
62 if (getenv ("BEAGLE_NO_WEB_INDEXING") != NULL)
63 return;
65 load_status = ephy_tab_get_load_status(tab);
67 /* FALSE means load is finished */
68 if (load_status == FALSE)
70 EphyEmbed *embed;
71 EphyEmbedPersist *persist;
72 char *location;
73 const char *page_title;
74 char *content;
75 int child_stdin;
76 char *argv[6];
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);
84 /* Get page title */
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";
95 argv[1] = "--url";
96 argv[2] = location;
97 argv[3] = "--title";
98 argv[4] = (char *) page_title;
99 argv[5] = NULL;
101 if (g_spawn_async_with_pipes (NULL, /* inherit parent's working directory */
102 argv,
103 NULL, /* inherit parent's environment */
104 G_SPAWN_SEARCH_PATH,
105 NULL, NULL, /* no special child setup needed */
106 NULL, /* don't need the child pid */
107 &child_stdin,
108 NULL, NULL, /* don't need access to child stdout/stderr */
109 NULL))
111 FILE *to_child = fdopen (child_stdin, "w");
112 if (to_child != NULL)
114 fprintf (to_child, "%s\n", content);
115 fclose (to_child);
119 g_free (location);
123 static void
124 impl_attach_tab (EphyExtension *extension,
125 EphyWindow *window,
126 EphyTab *tab)
128 g_signal_connect_after (tab, "notify::load-status",
129 G_CALLBACK (load_status_cb), extension);
132 static void
133 impl_detach_tab (EphyExtension *extension,
134 EphyWindow *window,
135 EphyTab *tab)
137 g_signal_handlers_disconnect_by_func
138 (tab, G_CALLBACK (load_status_cb), extension);
141 static void
142 impl_attach_window (EphyExtension *ext,
143 EphyWindow *window)
147 static void
148 impl_detach_window (EphyExtension *ext,
149 EphyWindow *window)
153 static void
154 ephy_beagle_extension_init (EphyBeagleExtension *extension)
156 extension->priv = EPHY_BEAGLE_EXTENSION_GET_PRIVATE (extension);
159 static void
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;
168 static void
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));
178 GType
179 ephy_beagle_extension_get_type (void)
181 return type;
184 GType
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,
193 NULL,
194 NULL, /* class_data */
195 sizeof (EphyBeagleExtension),
196 0, /* n_preallocs */
197 (GInstanceInitFunc) ephy_beagle_extension_init
200 static const GInterfaceInfo extension_info =
202 (GInterfaceInitFunc) ephy_beagle_extension_iface_init,
203 NULL,
204 NULL
207 type = g_type_module_register_type (module,
208 G_TYPE_OBJECT,
209 "BeagleExtension",
210 &our_info, 0);
212 g_type_module_add_interface (module,
213 type,
214 EPHY_TYPE_EXTENSION,
215 &extension_info);
217 return type;