[Goodies-commits] r5795 - in xfce4-dict/trunk: . lib

Enrico Troeger enrico at xfce.org
Fri Oct 24 19:30:33 CEST 2008


Author: enrico
Date: 2008-10-24 17:30:33 +0000 (Fri, 24 Oct 2008)
New Revision: 5795

Modified:
   xfce4-dict/trunk/ChangeLog
   xfce4-dict/trunk/lib/common.c
   xfce4-dict/trunk/lib/common.h
   xfce4-dict/trunk/lib/dictd.c
   xfce4-dict/trunk/lib/gui.c
   xfce4-dict/trunk/lib/gui.h
   xfce4-dict/trunk/lib/prefs.c
   xfce4-dict/trunk/lib/prefs.h
Log:
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.

Modified: xfce4-dict/trunk/ChangeLog
===================================================================
--- xfce4-dict/trunk/ChangeLog	2008-10-24 17:30:29 UTC (rev 5794)
+++ xfce4-dict/trunk/ChangeLog	2008-10-24 17:30:33 UTC (rev 5795)
@@ -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

Modified: xfce4-dict/trunk/lib/common.c
===================================================================
--- xfce4-dict/trunk/lib/common.c	2008-10-24 17:30:29 UTC (rev 5794)
+++ xfce4-dict/trunk/lib/common.c	2008-10-24 17:30:33 UTC (rev 5795)
@@ -155,7 +155,7 @@
 }
 
 
-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 @@
 	{
 		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:

Modified: xfce4-dict/trunk/lib/common.h
===================================================================
--- xfce4-dict/trunk/lib/common.h	2008-10-24 17:30:29 UTC (rev 5794)
+++ xfce4-dict/trunk/lib/common.h	2008-10-24 17:30:33 UTC (rev 5795)
@@ -55,6 +55,13 @@
 	SERVER_NOT_READY
 };
 
+enum
+{
+	COLOR_LINK,
+	COLOR_PHONECTIC
+};
+
+
 typedef struct
 {
 	/* settings */
@@ -108,5 +115,6 @@
 							 GtkSelectionData *data, guint info, guint ltime, DictData *dd);
 
 DictData *dict_create_dictdata();
+gboolean dict_start_web_query(DictData *dd, const gchar *word);
 
 #endif

Modified: xfce4-dict/trunk/lib/dictd.c
===================================================================
--- xfce4-dict/trunk/lib/dictd.c	2008-10-24 17:30:29 UTC (rev 5794)
+++ xfce4-dict/trunk/lib/dictd.c	2008-10-24 17:30:33 UTC (rev 5795)
@@ -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 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 @@
 
 	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 @@
 		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);

Modified: xfce4-dict/trunk/lib/gui.c
===================================================================
--- xfce4-dict/trunk/lib/gui.c	2008-10-24 17:30:29 UTC (rev 5794)
+++ xfce4-dict/trunk/lib/gui.c	2008-10-24 17:30:33 UTC (rev 5795)
@@ -41,8 +41,6 @@
 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 @@
 
 			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 @@
 	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 @@
 }
 
 
-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 @@
 }
 
 
+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 @@
 	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 @@
 			"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 */
 	{

Modified: xfce4-dict/trunk/lib/gui.h
===================================================================
--- xfce4-dict/trunk/lib/gui.h	2008-10-24 17:30:29 UTC (rev 5794)
+++ xfce4-dict/trunk/lib/gui.h	2008-10-24 17:30:33 UTC (rev 5795)
@@ -30,6 +30,7 @@
 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);
 
 

Modified: xfce4-dict/trunk/lib/prefs.c
===================================================================
--- xfce4-dict/trunk/lib/prefs.c	2008-10-24 17:30:29 UTC (rev 5794)
+++ xfce4-dict/trunk/lib/prefs.c	2008-10-24 17:30:33 UTC (rev 5795)
@@ -49,6 +49,23 @@
 	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 @@
 	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 @@
 }
 
 
+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;

Modified: xfce4-dict/trunk/lib/prefs.h
===================================================================
--- xfce4-dict/trunk/lib/prefs.h	2008-10-24 17:30:29 UTC (rev 5794)
+++ xfce4-dict/trunk/lib/prefs.h	2008-10-24 17:30:33 UTC (rev 5795)
@@ -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




More information about the Goodies-commits mailing list