[Goodies-commits] r2108 - in xfce4-dict-plugin/trunk: . panel-plugin
Enrico Troeger
enrico at xfce.org
Sat Oct 14 17:08:46 CEST 2006
Author: enrico
Date: 2006-10-14 15:08:44 +0000 (Sat, 14 Oct 2006)
New Revision: 2108
Modified:
xfce4-dict-plugin/trunk/ChangeLog
xfce4-dict-plugin/trunk/configure.in.in
xfce4-dict-plugin/trunk/panel-plugin/Makefile.am
xfce4-dict-plugin/trunk/panel-plugin/dict.c
Log:
Implemented threading to not freeze the GUI while searching on a slow server.
Modified: xfce4-dict-plugin/trunk/ChangeLog
===================================================================
--- xfce4-dict-plugin/trunk/ChangeLog 2006-10-14 12:35:52 UTC (rev 2107)
+++ xfce4-dict-plugin/trunk/ChangeLog 2006-10-14 15:08:44 UTC (rev 2108)
@@ -1,3 +1,9 @@
+2006-10-14 enrico
+
+ * Implemented threading to not freeze the GUI while searching on a slow server
+ (needs testing).
+
+
2006-10-02 enrico
* Again fixed display of panel text field when panel has no horizontal orientation.
Modified: xfce4-dict-plugin/trunk/configure.in.in
===================================================================
--- xfce4-dict-plugin/trunk/configure.in.in 2006-10-14 12:35:52 UTC (rev 2107)
+++ xfce4-dict-plugin/trunk/configure.in.in 2006-10-14 15:08:44 UTC (rev 2108)
@@ -4,7 +4,7 @@
dnl
dnl version info
-m4_define([dict_version], [0.2.0])
+m4_define([dict_version], [0.2.1])
dnl init autoconf
AC_INIT([xfce4-dict-plugin], [dict_version], [goodies-dev at xfce.org])
Modified: xfce4-dict-plugin/trunk/panel-plugin/Makefile.am
===================================================================
--- xfce4-dict-plugin/trunk/panel-plugin/Makefile.am 2006-10-14 12:35:52 UTC (rev 2107)
+++ xfce4-dict-plugin/trunk/panel-plugin/Makefile.am 2006-10-14 15:08:44 UTC (rev 2108)
@@ -3,17 +3,19 @@
xfce4_dict_plugin_SOURCES = \
inline-icon.h \
- dict.c
+ dict.c
xfce4_dict_plugin_CFLAGS = \
-I$(top_srcdir) \
$(LIBXFCEGUI4_CFLAGS) \
$(LIBXFCE4PANEL_CFLAGS) \
- -DPACKAGE_LOCALE_DIR=\"$(localedir)\"
+ -DPACKAGE_LOCALE_DIR=\"$(localedir)\" \
+ @GTHREAD_CFLAGS@
xfce4_dict_plugin_LDADD = \
$(LIBXFCE4PANEL_LIBS) \
- $(LIBXFCEGUI4_LIBS)
+ $(LIBXFCEGUI4_LIBS) \
+ @GTHREAD_LIBS@
inline-icon.h: $(srcdir)/dict-icon.svg
gdk-pixbuf-csource --raw --name=dict_icon_data dict-icon.svg > inline-icon.h
Modified: xfce4-dict-plugin/trunk/panel-plugin/dict.c
===================================================================
--- xfce4-dict-plugin/trunk/panel-plugin/dict.c 2006-10-14 12:35:52 UTC (rev 2107)
+++ xfce4-dict-plugin/trunk/panel-plugin/dict.c 2006-10-14 15:08:44 UTC (rev 2108)
@@ -71,6 +71,9 @@
gchar *server;
gchar *dictionary;
+ gchar *searched_word; // word to query the server
+ gboolean query_is_running;
+
GdkPixbuf *icon;
}
DictData;
@@ -253,7 +256,7 @@
}
-static gboolean dict_ask_server(DictData *dd, const gchar *word)
+static gboolean dict_ask_server(DictData *dd)
{
gint fd, i, max_lines;
gint defs_found = 0;
@@ -263,7 +266,7 @@
gchar *answer, *tmp, *stripped;
GtkTextIter iter;
- if (word == NULL || strlen(word) == 0) return FALSE;
+ if (dd->searched_word == NULL || strlen(dd->searched_word) == 0) return FALSE;
clear_text_buffer(dd);
gtk_text_buffer_get_start_iter(dd->main_textbuffer, &iter);
@@ -274,18 +277,20 @@
return FALSE;
}
- if (strlen(word) > (BUF_SIZE - 11))
+ if (strlen(dd->searched_word) > (BUF_SIZE - 11))
{
dict_status_add(dd, _("Input is too long."));
return FALSE;
}
+ dd->query_is_running = TRUE;
+
// take only the first part of the dictionary string, so let the string end at the space
i = 0;
while (dd->dictionary[i] != ' ') i++;
dd->dictionary[i] = '\0';
- snprintf(cmd, BUF_SIZE, "define %s \"%s\"\n", dd->dictionary, word);
+ snprintf(cmd, BUF_SIZE, "define %s \"%s\"\n", dd->dictionary, dd->searched_word);
send_command(fd, cmd);
// and now, "append" again the rest of the dictionary string again
@@ -297,6 +302,7 @@
if (strncmp("220", answer, 3) != 0)
{
dict_status_add(dd, _("Server not ready."));
+ dd->query_is_running = FALSE;
return FALSE;
}
@@ -306,12 +312,14 @@
if (strncmp("552", answer, 3) == 0)
{
- dict_status_add(dd, _("No matches could be found for \"%s\"."), word);
+ dict_status_add(dd, _("No matches could be found for \"%s\"."), dd->searched_word);
+ dd->query_is_running = FALSE;
return TRUE;
}
else if (strncmp("150", answer, 3) != 0 && strncmp("552", answer, 3) != 0)
{
dict_status_add(dd, _("Unknown error while quering the server."));
+ dd->query_is_running = FALSE;
return FALSE;
}
defs_found = atoi(answer + 4);
@@ -326,6 +334,7 @@
max_lines = g_strv_length(lines);
if (lines == NULL || max_lines == 0) return FALSE;
+ gdk_threads_enter();
gtk_text_buffer_insert(dd->main_textbuffer, &iter, "\n", 1);
i = -1;
@@ -370,12 +379,33 @@
// clear the panel entry to not search again when you click on the panel button
gtk_entry_set_text(GTK_ENTRY(dd->panel_entry), "");
+ gdk_threads_leave();
+
+ dd->query_is_running = FALSE;
+
+ g_thread_exit(NULL);
return TRUE;
}
+static void dict_start_query(DictData *dd, const gchar *word)
+{
+ if (dd->query_is_running)
+ {
+ gdk_beep();
+ }
+ else
+ {
+ g_free(dd->searched_word);
+ dd->searched_word = g_strdup(word); // copy the string because it will be freed by the caller
+ g_thread_create((GThreadFunc)dict_ask_server, dd, FALSE, NULL);
+ }
+}
+
+
static void dict_free_data(XfcePanelPlugin *plugin, DictData *dd)
{
+ g_free(dd->searched_word);
g_free(dd->dictionary);
g_free(dd->server);
g_object_unref(dd->icon);
@@ -767,7 +797,7 @@
else
entered_text = gtk_entry_get_text(GTK_ENTRY(dd->main_entry));
- dict_ask_server(dd, entered_text);
+ dict_start_query(dd, entered_text);
}
@@ -952,7 +982,7 @@
drag_context->action = GDK_ACTION_COPY;
}
gtk_entry_set_text(GTK_ENTRY(dd->main_entry), data->data);
- dict_ask_server(dd, data->data);
+ dict_start_query(dd, data->data);
gtk_widget_show(dd->window);
gtk_window_deiconify(GTK_WINDOW(dd->window));
gtk_window_present(GTK_WINDOW(dd->window));
@@ -970,7 +1000,7 @@
const gchar *panel_text = gtk_entry_get_text(GTK_ENTRY(dd->panel_entry));
if (strcmp("", panel_text) != 0)
{
- dict_ask_server(dd, panel_text);
+ dict_start_query(dd, panel_text);
gtk_entry_set_text(GTK_ENTRY(dd->main_entry), panel_text);
}
gtk_widget_grab_focus(dd->main_entry);
@@ -1006,7 +1036,12 @@
xfce_textdomain(GETTEXT_PACKAGE, PACKAGE_LOCALE_DIR, "UTF-8");
+ g_thread_init(NULL);
+ gdk_threads_init();
+
dd->plugin = plugin;
+ dd->searched_word = NULL;
+ dd->query_is_running = FALSE;
//dd->icon = load_and_scale(dict_icon_data, 24, -1);
More information about the Goodies-commits
mailing list