From eb06de34d167be240131cf1affc12a92a4384223 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Enrico=20Tr=C3=83=C2=B6ger?= <enrico@xfce.org> Date: Fri, 4 Jan 2008 16:53:38 +0000 Subject: [PATCH] * Add xfce4-popup-dict command to show the main window and/or grad the input focus to the text field in the panel. * Change year in copyright notes to 2008. (Old svn revision: 3777) --- ChangeLog | 7 ++ README | 25 +++++-- panel-plugin/Makefile.am | 16 +++++ panel-plugin/aspell.c | 2 +- panel-plugin/dict.c | 65 +++++++++++++++++- panel-plugin/dict.h | 2 +- panel-plugin/xfce4-popup-dict.c | 118 ++++++++++++++++++++++++++++++++ panel-plugin/xfce4-popup-dict.h | 45 ++++++++++++ po/POTFILES.in | 1 + 9 files changed, 271 insertions(+), 10 deletions(-) create mode 100644 panel-plugin/xfce4-popup-dict.c create mode 100644 panel-plugin/xfce4-popup-dict.h diff --git a/ChangeLog b/ChangeLog index 2abac3b..a0c401e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2008-01-04 Enrico Tröger <enrico(dot)troeger(at)uvena(dot)de> + + * Add xfce4-popup-dict command to show the main window and/or grad the input + focus to the text field in the panel. + * Change year in copyright notes to 2008. + + 2007-12-18 Enrico Tröger <enrico(dot)troeger(at)uvena(dot)de> * Remove wrong additional space before colons. diff --git a/README b/README index 924e597..b0e1272 100644 --- a/README +++ b/README @@ -1,4 +1,4 @@ -xfce4-dict-plugin - A plugin to query a Dict server +xfce4-dict-plugin - A plugin to query a Dict server and other dictionary sources With this plugin you can query a dictionary server(see RFC 2229) to search for the translation or explanation of a word. You can also choose a dictionary offered by the @@ -14,7 +14,22 @@ icon in your panel, then the plugin begins to search and shows you the results. This plugin was mainly tested with the server "dict.org" but should work with any other servers which implement the DICT protocol defined in RFC 2229. -ToDo: -- support user authentification -- keep dictionary list in memory -- support the MATCH command +Searching web-based dictionary services like dict.leo.org or other ones is also supported +by passing the search word as a URL argument and opening the URL in your webbrowser. The URL +can be configured in the preferences dialog. + +It is also possible to verify the spelling of word using aspell. To get this working you need +to have the aspell binary in your binary search path and at least one dictionary working. If you +have multiple aspell dictionaries installed, you can select the one to use in the preferences +dialog. + +Together with the plugin itself, a little tool named "xfce4-popup-dict" is installed which can +be used to open the plugin's main window from the command line or from any other program. +It can also be used to bind the dict plugin actions to a keyboard shortcut. You can add a new +keyboard command with the Keyboard settings plugin in Xfce's settings manager and assign +xfce4-popup-dict as the action command. +It accepts the arguments -t and --text-field to grab the focus to the text entry field in the +panel (if shown, it does nothing if not). If called without any arguments, it simply shows the +plugin's main window. +To get a list of available command line options you can also pass -h and --help as command line +options. diff --git a/panel-plugin/Makefile.am b/panel-plugin/Makefile.am index 89f88d6..c6597a9 100644 --- a/panel-plugin/Makefile.am +++ b/panel-plugin/Makefile.am @@ -1,6 +1,22 @@ plugindir = $(libexecdir)/xfce4/panel-plugins plugin_PROGRAMS = xfce4-dict-plugin +bin_PROGRAMS = \ + xfce4-popup-dict + +xfce4_popup_dict_SOURCES = \ + xfce4-popup-dict.c \ + xfce4-popup-dict.h + +xfce4_popup_dict_CFLAGS = \ + -DPACKAGE_LOCALE_DIR=\"$(localedir)\" \ + $(GTK_CFLAGS) \ + $(PLATFORM_CFLAGS) + +xfce4_popup_dict_LDADD = \ + $(GTK_LIBS) + + xfce4_dict_plugin_SOURCES = \ inline-icon.h \ aspell.c \ diff --git a/panel-plugin/aspell.c b/panel-plugin/aspell.c index 6b031e2..2048134 100644 --- a/panel-plugin/aspell.c +++ b/panel-plugin/aspell.c @@ -1,6 +1,6 @@ /* $Id$ * - * Copyright © 2007 Enrico Tröger <enrico(dot)troeger(at)uvena(dot)de> + * Copyright 2007-2008 Enrico Tröger <enrico(dot)troeger(at)uvena(dot)de> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/panel-plugin/dict.c b/panel-plugin/dict.c index c7a8b68..5e220a2 100644 --- a/panel-plugin/dict.c +++ b/panel-plugin/dict.c @@ -1,6 +1,6 @@ /* $Id$ * - * Copyright © 2006-2007 Enrico Tröger <enrico(dot)troeger(at)uvena(dot)de> + * Copyright 2006-2008 Enrico Tröger <enrico(dot)troeger(at)uvena(dot)de> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -40,6 +40,7 @@ #include <string.h> #include "dict.h" +#include "xfce4-popup-dict.h" #include "inline-icon.h" #define BUF_SIZE 256 @@ -50,6 +51,7 @@ static void dict_properties_dialog(XfcePanelPlugin *plugin, DictData *dd); static void dict_construct(XfcePanelPlugin *plugin); static void dict_write_rc_file(XfcePanelPlugin *plugin, DictData *dd); +static void dict_panel_button_clicked(GtkWidget *button, DictData *dd); /* internal functions */ @@ -133,6 +135,62 @@ static gchar *dict_str_replace(gchar *haystack, const gchar *needle, const gchar } +/* Handle user messages (xfce4-popup-dict) */ +static gboolean dict_message_received(GtkWidget *w, GdkEventClient *ev, gpointer user_data) +{ + DictData *dd = user_data; + + if (ev->data_format == 8 && *(ev->data.b) != '\0') + { + if (strcmp(XFCE_DICT_WINDOW_MESSAGE, ev->data.b) == 0) + { // open the main window + dict_panel_button_clicked(NULL, dd); + return TRUE; + } + + if (strcmp(XFCE_DICT_TEXTFIELD_MESSAGE, ev->data.b) == 0) + { // put the focus onto the panel entry + if (dd->show_panel_entry) + xfce_panel_plugin_focus_widget(dd->plugin, dd->panel_entry); + } + } + + return FALSE; +} + + +static gboolean dict_set_selection(DictData *dd) +{ + GdkScreen *gscreen; + gchar selection_name[32]; + Atom selection_atom; + GtkWidget *win; + Window xwin; + + win = gtk_invisible_new(); + gtk_widget_realize(win); + xwin = GDK_WINDOW_XID(GTK_WIDGET(win)->window); + + gscreen = gtk_widget_get_screen(win); + g_snprintf(selection_name, sizeof (selection_name), + XFCE_DICT_SELECTION"%d", gdk_screen_get_number(gscreen)); + selection_atom = XInternAtom(GDK_DISPLAY(), selection_name, False); + + if (XGetSelectionOwner(GDK_DISPLAY(), selection_atom)) + { + gtk_widget_destroy(win); + return FALSE; + } + + XSelectInput(GDK_DISPLAY(), xwin, PropertyChangeMask); + XSetSelectionOwner(GDK_DISPLAY(), selection_atom, xwin, GDK_CURRENT_TIME); + + g_signal_connect(G_OBJECT(win), "client-event", G_CALLBACK(dict_message_received), dd); + + return TRUE; +} + + static GdkPixbuf *dict_load_and_scale(const guint8 *data, int dstw, int dsth) { GdkPixbuf *pb, *pb_scaled; @@ -1444,7 +1502,7 @@ static void dict_about_dialog(GtkWidget *widget, DictData *dd) info = xfce_about_info_new("xfce4-dict-plugin", VERSION, _("A plugin to query a Dict server."), - XFCE_COPYRIGHT_TEXT("2006-2007", "Enrico Tröger"), + XFCE_COPYRIGHT_TEXT("2006-2008", "Enrico Tröger"), XFCE_LICENSE_GPL); xfce_about_info_add_credit(info, "Enrico Tröger", "enrico(dot)troeger(at)uvena(dot)de", _("Developer")); @@ -1485,7 +1543,7 @@ static void dict_panel_button_clicked(GtkWidget *button, DictData *dd) const gchar *panel_text = gtk_entry_get_text(GTK_ENTRY(dd->panel_entry)); dict_show_main_window(dd); - if (strcmp("", panel_text) != 0) + if (NZV(panel_text)) { dict_search_word(dd, panel_text); gtk_entry_set_text(GTK_ENTRY(dd->main_entry), panel_text); @@ -1574,6 +1632,7 @@ static void dict_construct(XfcePanelPlugin *plugin) gtk_container_add(GTK_CONTAINER(plugin), hbox); xfce_panel_plugin_add_action_widget(plugin, dd->panel_button); + dict_set_selection(dd); /* DnD stuff */ gtk_drag_dest_set(GTK_WIDGET(dd->panel_button), GTK_DEST_DEFAULT_ALL, diff --git a/panel-plugin/dict.h b/panel-plugin/dict.h index 78cf077..b6f1918 100644 --- a/panel-plugin/dict.h +++ b/panel-plugin/dict.h @@ -1,6 +1,6 @@ /* $Id$ * - * Copyright © 2007 Enrico Tröger <enrico(dot)troeger(at)uvena(dot)de> + * Copyright 2007-2008 Enrico Tröger <enrico(dot)troeger(at)uvena(dot)de> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/panel-plugin/xfce4-popup-dict.c b/panel-plugin/xfce4-popup-dict.c new file mode 100644 index 0000000..38279f5 --- /dev/null +++ b/panel-plugin/xfce4-popup-dict.c @@ -0,0 +1,118 @@ +/* $Id$ + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + + (c) 2008 Enrico Tröger + + (c) 2006 Darren Salt + + Derived from xfdesktop's xfce4-popup-menu + (c) 2002-2006 Olivier Fourdan + + */ + +#include <stdio.h> +#include <gtk/gtk.h> +#include <glib.h> +#include <glib/gi18n.h> +#include <gdk/gdkx.h> +#include <X11/Xlib.h> + +#ifdef HAVE_CONFIG_H +#include <config.h> +#endif + +#if HAVE_LOCALE_H +# include <locale.h> +#endif + +#include "xfce4-popup-dict.h" + +#ifdef HAVE_STRING_H +#include <string.h> +#endif + +#ifdef HAVE_STDLIB_H +#include <stdlib.h> +#endif + +static gboolean xfce4_check_is_running(GtkWidget *widget, Window *xid) +{ + GdkScreen *gscreen; + gchar selection_name[32]; + Atom selection_atom; + + gscreen = gtk_widget_get_screen(widget); + g_snprintf(selection_name, sizeof(selection_name), XFCE_DICT_SELECTION"%d", + gdk_screen_get_number(gscreen)); + selection_atom = XInternAtom(GDK_DISPLAY(), selection_name, False); + + if ((*xid = XGetSelectionOwner(GDK_DISPLAY(), selection_atom))) + return TRUE; + + return FALSE; +} + + +int main(int argc, char *argv[]) +{ + GdkEventClient gev; + GtkWidget *win; + Window id; + +#ifdef ENABLE_NLS + bindtextdomain(GETTEXT_PACKAGE, PACKAGE_LOCALE_DIR); + bind_textdomain_codeset(GETTEXT_PACKAGE, "UTF-8"); + textdomain(GETTEXT_PACKAGE); +#endif + + gtk_init(&argc, &argv); + + win = gtk_invisible_new(); + gtk_widget_realize(win); + + gev.type = GDK_CLIENT_EVENT; + gev.window = win->window; + gev.send_event = TRUE; + gev.message_type = gdk_atom_intern("STRING", FALSE); + gev.data_format = 8; + if (argc > 1 && (strcmp(argv[1], "--text-field") == 0 || strcmp(argv[1], "-t") == 0)) + { + strcpy(gev.data.b, XFCE_DICT_TEXTFIELD_MESSAGE); + } + else if (argc > 1 && (strcmp(argv[1], "--help") == 0 || strcmp(argv[1], "-h") == 0)) + { + g_print(_("Usage: %s [options]\n"), argv[0]); + g_print(_("Options:\n")); + g_print(_(" -t, --text-field grap the focus on the text field in the panel\n")); + g_print(_(" -h, --help show this help and exit\n")); + g_print(_("If called without any options, the xfce4-dict-plugin main window is shown.\n")); + return 0; + } + else + { + strcpy(gev.data.b, XFCE_DICT_WINDOW_MESSAGE); + } + + if (xfce4_check_is_running(win, &id)) + gdk_event_send_client_message((GdkEvent*) &gev, (GdkNativeWindow) id); + else + g_warning("Can't find the xfce4-dict-plugin to popup.\n"); + + gdk_flush(); + gtk_widget_destroy(win); + + return 0; +} diff --git a/panel-plugin/xfce4-popup-dict.h b/panel-plugin/xfce4-popup-dict.h new file mode 100644 index 0000000..1d23909 --- /dev/null +++ b/panel-plugin/xfce4-popup-dict.h @@ -0,0 +1,45 @@ +/* $Id$ + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + + (c) 2008 Enrico Tröger + + (c) 2006 Darren Salt + + Derived from xfdesktop panel-plugin/xfce4-popup-menu.h + (c) 2002-2006 Olivier Fourdan + + */ + +#ifdef HAVE_CONFIG_H +#include <config.h> +#endif + +#ifndef INC_XFCE4_DICT_POPUP_MENU_H +#define INC_XFCE4_DICT_POPUP_MENU_H + +#ifndef XFCE_DICT_WINDOW_MESSAGE +#define XFCE_DICT_WINDOW_MESSAGE "xfce4-dict-popup" +#endif /* XFCE_DICT_WINDOW_MESSAGE */ + +#ifndef XFCE_DICT_TEXTFIELD_MESSAGE +#define XFCE_DICT_TEXTFIELD_MESSAGE "xfce4-dict-atptr" +#endif /* XFCE_DICT_TEXTFIELD_MESSAGE */ + +#ifndef XFCE_DICT_SELECTION +#define XFCE_DICT_SELECTION "XFCE_DICT_SEL" +#endif /* XFCE_DICT_SELECTION */ + +#endif /* INC_XFCE4_DICT_POPUP_MENU_H */ diff --git a/po/POTFILES.in b/po/POTFILES.in index 125b84e..00ae54b 100644 --- a/po/POTFILES.in +++ b/po/POTFILES.in @@ -1,2 +1,3 @@ panel-plugin/dict.c +panel-plugin/xfce4-popup-dict.c panel-plugin/dict.desktop.in.in -- GitLab