2006-04-25 Hendrik Brandt <heb@gnome-de.org>
[beagle.git] / searchomatic / searchomatic.c
blob639553ea5388504abaa72ad82261bd67cf593182
1 /* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
4 /*
5 * searchomatic.c
7 * Copyright (C) 2004 Novell, Inc.
9 */
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License as
14 * published by the Free Software Foundation; either version 2 of the
15 * License, or (at your option) any later version.
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
25 * USA.
29 Federico rules.
32 #ifdef CONFIG_H
33 #include <config.h>
34 #endif
35 #include <gtk/gtk.h>
36 #include <string.h>
38 static void
39 text_received_cb (GtkClipboard *clipboard, const char *text, gpointer data)
41 char *cpy;
42 int i;
44 if (text != NULL && strlen (text) > 2) {
46 cpy = g_strdup (text);
48 /* Remove trailing gunk */
49 i = strlen (cpy) - 1;
50 while (i > 0 && cpy [i] == 10) {
51 cpy [i] = '\0';
52 --i;
55 /* Remove excess whitespace. */
56 g_strstrip (cpy);
58 /* Searchs for best in the PATH. */
59 execlp ("best", "best", "--no-tray", cpy, NULL);
62 gtk_exit (0);
66 static gboolean
67 request_text (gpointer data)
69 GtkWidget *my_widget;
70 GtkClipboard *clipboard;
72 my_widget = GTK_WIDGET (data);
73 clipboard = gtk_widget_get_clipboard (my_widget, GDK_SELECTION_PRIMARY);
74 gtk_clipboard_request_text (clipboard, text_received_cb, my_widget);
76 return FALSE;
79 int
80 main (int argc, char *argv[])
82 GtkWidget *window;
84 gtk_init (&argc, &argv);
86 /* We need a widget, so we create (but don't show) a window. */
87 window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
89 g_idle_add (request_text, window);
91 gtk_main ();
93 return 0;