diff --git a/ChangeLog b/ChangeLog index 42978cfd55c94e962e8639ac92c52c29ddfdbc44..605df45bef8ab9a28fe9b3d91219a3ca4302121f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2008-10-24 Enrico Tröger <enrico(dot)troeger(at)uvena(dot)de> + + * Add mnemonics to the search method radio labels in the main window. + * Add a link to easily start a Web search if there are no Dict results. + + 2008-10-23 Enrico Tröger <enrico(dot)troeger(at)uvena(dot)de> * Bring the 'Search Term' string back, this time in the search diff --git a/lib/common.c b/lib/common.c index 9e26e903604b7e093798263f59361efa7ceca295..e7d401ad28cade340b3e6443894f976b8920b86b 100644 --- a/lib/common.c +++ b/lib/common.c @@ -155,7 +155,7 @@ static gboolean open_browser(DictData *dd, const gchar *uri) } -static gboolean start_web_query(DictData *dd, const gchar *word) +gboolean dict_start_web_query(DictData *dd, const gchar *word) { gboolean success = TRUE; gchar *uri; @@ -228,7 +228,7 @@ void dict_search_word(DictData *dd, const gchar *word) { case DICTMODE_WEB: { - browser_started = start_web_query(dd, dd->searched_word); + browser_started = dict_start_web_query(dd, dd->searched_word); break; } case DICTMODE_SPELL: diff --git a/lib/common.h b/lib/common.h index 94f308285f07a66b5d755afc6739fd4a7a5f9651..abf897868f952c655e26b4ce5555fdffc3a11111 100644 --- a/lib/common.h +++ b/lib/common.h @@ -55,6 +55,13 @@ enum SERVER_NOT_READY }; +enum +{ + COLOR_LINK, + COLOR_PHONECTIC +}; + + typedef struct { /* settings */ @@ -108,5 +115,6 @@ void dict_drag_data_received(GtkWidget *widget, GdkDragContext *drag_context, gi GtkSelectionData *data, guint info, guint ltime, DictData *dd); DictData *dict_create_dictdata(); +gboolean dict_start_web_query(DictData *dd, const gchar *word); #endif diff --git a/lib/dictd.c b/lib/dictd.c index 0a94feddd5d758d0ca5487e89e2e9f54a11204e1..91a29c3b587681150f844019a26459b0dbd958b3 100644 --- a/lib/dictd.c +++ b/lib/dictd.c @@ -49,6 +49,7 @@ #include "dictd.h" #include "gui.h" #include "aspell.h" +#include "prefs.h" #define BUF_SIZE 256 @@ -163,20 +164,11 @@ static void parse_header(DictData *dd, GString *buffer, GString *target) static GtkTextTag *create_tag(DictData *dd, const gchar *link_str) { - static GdkColor *link_color = NULL; - static GdkColor default_link_color = { 0, 0, 0, 0xeeee }; GtkTextTag *tag; - if (link_color == NULL) - { - gtk_widget_style_get(GTK_WIDGET(dd->main_textview), "link-color", &link_color, NULL); - if (link_color == NULL) - link_color = &default_link_color; - } - tag = gtk_text_buffer_create_tag(dd->main_textbuffer, NULL, "underline", PANGO_UNDERLINE_SINGLE, - "foreground-gdk", link_color, NULL); + "foreground-gdk", dict_gui_get_color(dd, COLOR_LINK), NULL); g_object_set_data_full(G_OBJECT(tag), "link", g_strdup(link_str), g_free); @@ -374,7 +366,8 @@ static gboolean process_server_response(DictData *dd) answer = dd->query_buffer; /* go to next line */ - while (*answer != '\n') answer++; + while (*answer != '\n') + answer++; answer++; if (dd->query_status == NOTHING_FOUND) @@ -388,7 +381,19 @@ static gboolean process_server_response(DictData *dd) g_free(dd->query_buffer); /* if we had no luck searching a word, maybe we have a typo so try searching with - * aspell */ + * aspell and offer a Web search*/ + if (NZV(dd->web_url)) + { + gchar *text = g_strdup_printf( + _("Do you want to search \"%s\" on the Web using "), dd->searched_word); + gtk_text_buffer_insert(dd->main_textbuffer, &dd->textiter, "\n\n", 2); + gtk_text_buffer_insert(dd->main_textbuffer, &dd->textiter, text, -1); + gtk_text_buffer_insert(dd->main_textbuffer, &dd->textiter, "\"", 1); + gtk_text_buffer_insert_with_tags_by_name(dd->main_textbuffer, &dd->textiter, + dict_prefs_get_web_url_label(dd), -1, "link", NULL); + gtk_text_buffer_insert(dd->main_textbuffer, &dd->textiter, "\"?", 2); + g_free(text); + } if (NZV(dd->spell_bin)) { gtk_text_buffer_insert(dd->main_textbuffer, &dd->textiter, "\n", 1); diff --git a/lib/gui.c b/lib/gui.c index 72abc27f4c1b58bfc2a948df8d044adce0cbfa78..0fd44b95dc7a2a968e3c4b304d916faa63c7b2c9 100644 --- a/lib/gui.c +++ b/lib/gui.c @@ -41,8 +41,6 @@ static gboolean hovering_over_link = FALSE; static GdkCursor *hand_cursor = NULL; static GdkCursor *regular_cursor = NULL; static gboolean entry_is_dirty = FALSE; -/** TODO make colours (phonecitc, link colour) configurable */ -static const GdkColor phon_color = { 0, 0, 0x6363, 0 }; /* all textview_* functions are from the gtk-demo app to get links in the textview working */ @@ -64,6 +62,13 @@ static void textview_follow_if_link(GtkWidget *text_view, GtkTextIter *iter, Dic break; } + g_object_get(G_OBJECT(tag), "name", &found_link, NULL); + if (found_link != NULL && strcmp("link", found_link) == 0) + { + dict_start_web_query(dd, dd->searched_word); + g_free(found_link); + break; + } } if (tags) g_slist_free(tags); @@ -138,12 +143,20 @@ static void textview_set_cursor_if_appropriate(GtkTextView *text_view, gint x, g for (tagp = tags; tagp != NULL; tagp = tagp->next) { GtkTextTag *tag = tagp->data; + gchar *name; if (g_object_get_data(G_OBJECT(tag), "link") != NULL) { hovering = TRUE; break; } + g_object_get(G_OBJECT(tag), "name", &name, NULL); + if (name != NULL && strcmp("link", name) == 0) + { + hovering = TRUE; + g_free(name); + break; + } } if (hovering != hovering_over_link) @@ -378,7 +391,7 @@ const guint8 *dict_gui_get_icon_data(void) } -static GtkWidget *create_file_menu(DictData *dd) + static GtkWidget *create_file_menu(DictData *dd) { GtkWidget *menubar, *file, *file_menu, *help, *help_menu, *menu_item; GtkAccelGroup *accel_group; @@ -432,6 +445,23 @@ void dict_gui_finalize(DictData *dd) } +const GdkColor *dict_gui_get_color(DictData *dd, gint color) +{ + /** TODO make colours (phonetic, link colour) configurable */ + static const GdkColor link_color = { 0, 0, 0, 0xeeee }; + static const GdkColor phon_color = { 0, 0, 0x6363, 0 }; + + switch (color) + { + case COLOR_PHONECTIC: + return &phon_color; + case COLOR_LINK: + return &link_color; + } + return NULL; +} + + void dict_gui_create_main_window(DictData *dd) { GtkWidget *main_box, *entry_box, *label_box; @@ -500,20 +530,19 @@ void dict_gui_create_main_window(DictData *dd) gtk_widget_show(label); gtk_box_pack_start(GTK_BOX(method_chooser), label, FALSE, FALSE, 6); - /* TODO: add mnemonics, add 'Search $web_dictionary link when nothing found */ - radio = gtk_radio_button_new_with_label(NULL, _("Dict")); + radio = gtk_radio_button_new_with_mnemonic(NULL, _("_Dict")); gtk_widget_show(radio); gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(radio), (dd->mode_in_use == DICTMODE_DICT)); g_signal_connect(radio, "toggled", G_CALLBACK(search_mode_dict_toggled), dd); gtk_box_pack_start(GTK_BOX(method_chooser), radio, FALSE, FALSE, 6); - radio = gtk_radio_button_new_with_label_from_widget(GTK_RADIO_BUTTON(radio), _("Web")); + radio = gtk_radio_button_new_with_mnemonic_from_widget(GTK_RADIO_BUTTON(radio), _("_Web")); gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(radio), (dd->mode_in_use == DICTMODE_WEB)); g_signal_connect(radio, "toggled", G_CALLBACK(search_mode_web_toggled), dd); gtk_widget_show(radio); gtk_box_pack_start(GTK_BOX(method_chooser), radio, FALSE, FALSE, 6); - radio = gtk_radio_button_new_with_label_from_widget(GTK_RADIO_BUTTON(radio), _("Spell Check")); + radio = gtk_radio_button_new_with_mnemonic_from_widget(GTK_RADIO_BUTTON(radio), _("_Spell Check")); gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(radio), (dd->mode_in_use == DICTMODE_SPELL)); g_signal_connect(radio, "toggled", G_CALLBACK(search_mode_spell_toggled), dd); gtk_widget_show(radio); @@ -544,9 +573,13 @@ void dict_gui_create_main_window(DictData *dd) "indent", 10, "pixels-below-lines", 5, NULL); gtk_text_buffer_create_tag(dd->main_textbuffer, - "phonetic", - "style", PANGO_STYLE_ITALIC, - "foreground-gdk", &phon_color, NULL); + "phonetic", + "style", PANGO_STYLE_ITALIC, + "foreground-gdk", dict_gui_get_color(dd, COLOR_PHONECTIC), NULL); + gtk_text_buffer_create_tag(dd->main_textbuffer, + "link", + "underline", PANGO_UNDERLINE_SINGLE, + "foreground-gdk", dict_gui_get_color(dd, COLOR_LINK), NULL); /* support for links (cross-references) for dictd responses */ { diff --git a/lib/gui.h b/lib/gui.h index 88d58d27748bab5892d3982518cbdaeda04079c5..7bef0a786975c837a15a1e08a725ab622229261e 100644 --- a/lib/gui.h +++ b/lib/gui.h @@ -30,6 +30,7 @@ void dict_gui_set_panel_entry_text(DictData *dd, const gchar *text); void dict_gui_show_main_window(DictData *dd); void dict_gui_query_geometry(DictData *dd); void dict_gui_finalize(DictData *dd); +const GdkColor *dict_gui_get_color(DictData *dd, gint color); const guint8 *dict_gui_get_icon_data(void); diff --git a/lib/prefs.c b/lib/prefs.c index b496c8cf8b5fbbd572d7a0355186f088445f59bd..e05b4906f3c02bc18783f92c10faf214c76bae25 100644 --- a/lib/prefs.c +++ b/lib/prefs.c @@ -49,6 +49,23 @@ enum NOTEBOOK_PAGE_ASPELL }; +static const web_dict_t web_dicts[] = +{ + { N_("dict.leo.org - German <-> English"), "http://dict.leo.org/ende?search={word}" }, + { N_("dict.leo.org - German <-> French"), "http://dict.leo.org/frde?search={word}" }, + { N_("dict.leo.org - German <-> Spanish"), "http://dict.leo.org/esde?search={word}" }, + { N_("dict.leo.org - German <-> Italian"), "http://dict.leo.org/itde?search={word}" }, + { N_("dict.leo.org - German <-> Chinese"), "http://dict.leo.org/chde?search={word}" }, + { N_("dist.cc - Dictionary"), "http://www.dict.cc/?s={word}" }, + { N_("Dictionary.com"), "http://dictionary.reference.com/search?db=dictionary&q={word}" }, + { N_("TheFreeDictionary.com"), "http://www.thefreedictionary.com/_/partner.aspx?Word={word}&Set=www&mode=w" }, + { N_("Wikipedia, the free encyclopedia (EN)"), "http://en.wikipedia.org/wiki/{word}" }, + { N_("Wiktionary, the free dictionary (EN)"), "http://en.wiktionary.org/wiki/{word}" }, + { N_("Merriam-Webster Online Dictionary"), "http://www.merriam-webster.com/dictionary/{word}" }, + { N_("Clear"), "" }, + { NULL, NULL } +}; + static void show_panel_entry_toggled(GtkToggleButton *tb, DictData *dd) { if (dd->is_plugin) @@ -190,22 +207,6 @@ static GtkWidget *create_web_dicts_table(GtkWidget *entry) gint i; gint offset; GtkWidget *table, *button; - static web_dict_t web_dicts[] = - { - { N_("dict.leo.org - German <-> English"), "http://dict.leo.org/ende?search={word}" }, - { N_("dict.leo.org - German <-> French"), "http://dict.leo.org/frde?search={word}" }, - { N_("dict.leo.org - German <-> Spanish"), "http://dict.leo.org/esde?search={word}" }, - { N_("dict.leo.org - German <-> Italian"), "http://dict.leo.org/itde?search={word}" }, - { N_("dict.leo.org - German <-> Chinese"), "http://dict.leo.org/chde?search={word}" }, - { N_("dist.cc - Dictionary"), "http://www.dict.cc/?s={word}" }, - { N_("Dictionary.com"), "http://dictionary.reference.com/search?db=dictionary&q={word}" }, - { N_("TheFreeDictionary.com"), "http://www.thefreedictionary.com/_/partner.aspx?Word={word}&Set=www&mode=w" }, - { N_("Wikipedia, the free encyclopedia (EN)"), "http://en.wikipedia.org/wiki/{word}" }, - { N_("Wiktionary, the free dictionary (EN)"), "http://en.wiktionary.org/wiki/{word}" }, - { N_("Merriam-Webster Online Dictionary"), "http://www.merriam-webster.com/dictionary/{word}" }, - { N_("Clear"), "" }, - { NULL, NULL } - }; table = gtk_table_new(4, 2, FALSE); gtk_table_set_row_spacings(GTK_TABLE(table), 2); @@ -229,6 +230,19 @@ static GtkWidget *create_web_dicts_table(GtkWidget *entry) } +const gchar *dict_prefs_get_web_url_label(DictData *dd) +{ + gint i; + + for (i = 0; web_dicts[i].label != NULL; i++) + { + if (strcmp(web_dicts[i].url, dd->web_url) == 0) + return web_dicts[i].label; + } + return dd->web_url; +} + + GtkWidget *dict_prefs_dialog_show(GtkWidget *parent, DictData *dd) { GtkWidget *dialog, *inner_vbox, *notebook, *notebook_vbox; diff --git a/lib/prefs.h b/lib/prefs.h index 5b02a20f61f5be021608d5adc548af3ec10403cf..096ecd7f8d145bc82b7ed8b728f3c3ef2b20d83a 100644 --- a/lib/prefs.h +++ b/lib/prefs.h @@ -23,6 +23,6 @@ GtkWidget *dict_prefs_dialog_show(GtkWidget *parent, DictData *dd); void dict_prefs_dialog_response(GtkWidget *dlg, gint response, DictData *dd); - +const gchar *dict_prefs_get_web_url_label(DictData *dd); #endif