Re: Dictionary search extension
- From: Christian Persch <chpe stud uni-saarland de>
- To: jf rameau wanadoo fr
- Cc: "epiphany list at gnome.org" <epiphany-list gnome org>
- Subject: Re: Dictionary search extension
- Date: Fri, 11 Jun 2004 00:09:52 +0200
Hi,
On Wed, 2004-06-09 at 21:02, Jean-François RAMEAU wrote:
[snip]
>dictionary-search-extension.c:
> #define LOG(x) printf(x);printf("\n");
You can #include "ephy-debug.h", LOG() is defined there.
> static void
> clipboard_text_received_cb (GtkClipboard *clipboard,
> const char *text,
> gpointer *ptr)
> {
> GSList *dicos_url, *dicos_lbl, *du, *dl;
> gchar **cutter, *a_dico, *url;
> const gchar *action_lbl;
> GtkAction *action;
>
> action = (GtkAction *)ptr;
>
> dicos_url = eel_gconf_get_string_list (CONF_DICTIONARIES);
> dicos_lbl = eel_gconf_get_string_list (CONF_MENUS);
Guard against NULL values.
> /* Replace $ by the selected word */
> cutter = g_strsplit (a_dico, "$", 0);
> url = g_strconcat (cutter[0], text, cutter[1], NULL);
Why invent your own format here? Just use %s like smart bookmarks. Then
you can solve the url with
bookmarks = ephy_shell_get_bookmarks (ephy_shell);
ephy_bookmarks_solve_smart_url (bookmarks, a_dico, text);
That has also another advantage: probably not all servers are going to
expect UTF-8 in the url; for this solve_smart_url supports encodings,
using a smart url like this one:
{encoding="ISO-8859-1"}http://www.example.com/search?term=%s
> static void dico_cb (GtkAction *action,
> EphyWindow *window)
> {
> EphyEmbed *embed;
>
> embed = ephy_window_get_active_embed (window);
> g_return_if_fail (EPHY_IS_EMBED (embed));
>
> ephy_command_manager_do_command (EPHY_COMMAND_MANAGER (embed), "cmd_copy");
>
> gtk_clipboard_request_text (gtk_widget_get_clipboard (GTK_WIDGET (embed),
> GDK_SELECTION_CLIPBOARD),
> (GtkClipboardTextReceivedFunc) clipboard_text_received_cb,
> action);
> }
Here's a potential crasher. Retrieving the selection is async; if the
tab/window was closed between requesting the text and receiving it,
"action" has been destroyed. Look in ephy-tab.c's
clipboard_text_received_cb() and ephy_tab_dom_mouse_click_cb() for how
to solve this, for example.
> dictionary-search.c:
> G_MODULE_EXPORT GType
> register_module (GTypeModule *module)
> {
> LOG ("Registering Dictionary Search Extension")
>
> return dictionary_search_extension_register_type (module);
> }
You need to initialise the i18n support here; see any of the other
extensions how to do it (for example
extensions/popup-blocker/popup-blocker.c).
Do you want to sumbit this extension for inclusion in Epiphany
Extensions ?
Regards,
Christian
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]