diff options
Diffstat (limited to 'src/fs/gnunet-fs-gtk-main_window_search.c')
-rw-r--r-- | src/fs/gnunet-fs-gtk-main_window_search.c | 137 |
1 files changed, 137 insertions, 0 deletions
diff --git a/src/fs/gnunet-fs-gtk-main_window_search.c b/src/fs/gnunet-fs-gtk-main_window_search.c new file mode 100644 index 00000000..870b5f18 --- /dev/null +++ b/src/fs/gnunet-fs-gtk-main_window_search.c | |||
@@ -0,0 +1,137 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet | ||
3 | (C) 2011, 2012 Christian Grothoff (and other contributing authors) | ||
4 | |||
5 | GNUnet is free software; you can redistribute it and/or modify | ||
6 | it under the terms of the GNU General Public License as published | ||
7 | by the Free Software Foundation; either version 2, or (at your | ||
8 | option) any later version. | ||
9 | |||
10 | GNUnet is distributed in the hope that it will be useful, but | ||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
13 | General Public License for more details. | ||
14 | |||
15 | You should have received a copy of the GNU General Public License | ||
16 | along with GNUnet; see the file COPYING. If not, write to the | ||
17 | Free Software Foundation, Inc., 59 Temple Place - Suite 330, | ||
18 | Boston, MA 02111-1307, USA. | ||
19 | */ | ||
20 | |||
21 | /** | ||
22 | * @file src/fs/gnunet-fs-gtk-main_window_search.c | ||
23 | * @author Christian Grothoff | ||
24 | * @brief event handlers for the search function in the main window | ||
25 | */ | ||
26 | #include "gnunet-fs-gtk-common.h" | ||
27 | #include <gdk/gdk.h> | ||
28 | |||
29 | |||
30 | |||
31 | void | ||
32 | main_window_search_button_clicked_cb (GtkButton * button, gpointer user_data) | ||
33 | { | ||
34 | GtkBuilder *builder; | ||
35 | GtkTreePath *namespace_treepath = NULL; | ||
36 | GtkTreeModel *namespace_model = NULL; | ||
37 | GtkComboBox *mime_combo; | ||
38 | GtkTreeModel *mime_model; | ||
39 | GtkEntry *query_entry; | ||
40 | guint anonymity_level; | ||
41 | GtkTreeRowReference *ref = NULL; | ||
42 | GtkTreeIter iter; | ||
43 | GtkToggleButton *toggle_button; | ||
44 | const char *entry_keywords; | ||
45 | gchar *keywords; | ||
46 | gchar *mime_keyword; | ||
47 | |||
48 | GNUNET_HashCode *nsid = NULL; | ||
49 | struct GNUNET_FS_Uri *uri; | ||
50 | char *emsg; | ||
51 | |||
52 | builder = GTK_BUILDER (user_data); | ||
53 | |||
54 | toggle_button = | ||
55 | GTK_TOGGLE_BUTTON (gtk_builder_get_object | ||
56 | (builder, | ||
57 | "main_window_search_namespace_dropdown_button")); | ||
58 | |||
59 | if (!GNUNET_GTK_get_selected_anonymity_level | ||
60 | (builder, "main_window_search_anonymity_combobox", &anonymity_level)) | ||
61 | return; | ||
62 | |||
63 | mime_combo = | ||
64 | GTK_COMBO_BOX (GNUNET_FS_GTK_get_main_window_object | ||
65 | ("main_window_search_mime_combobox")); | ||
66 | mime_model = gtk_combo_box_get_model (mime_combo); | ||
67 | mime_keyword = NULL; | ||
68 | if (mime_model && gtk_combo_box_get_active_iter (mime_combo, &iter)) | ||
69 | gtk_tree_model_get (mime_model, &iter, 0, &mime_keyword, -1); | ||
70 | if (strcmp (mime_keyword, " ") == 0) | ||
71 | { | ||
72 | g_free (mime_keyword); | ||
73 | mime_keyword = NULL; | ||
74 | } | ||
75 | |||
76 | ref = g_object_get_data (G_OBJECT (toggle_button), "selected-row-reference"); | ||
77 | if (ref) | ||
78 | { | ||
79 | namespace_model = gtk_tree_row_reference_get_model (ref); | ||
80 | namespace_treepath = gtk_tree_row_reference_get_path (ref); | ||
81 | if ((NULL != namespace_treepath) && | ||
82 | (TRUE == | ||
83 | gtk_tree_model_get_iter (namespace_model, &iter, namespace_treepath))) | ||
84 | gtk_tree_model_get (namespace_model, &iter, 1, &nsid, -1); | ||
85 | } | ||
86 | query_entry = | ||
87 | GTK_ENTRY (gtk_builder_get_object (builder, "main_window_search_entry")); | ||
88 | entry_keywords = gtk_entry_get_text (query_entry); | ||
89 | keywords = | ||
90 | g_strdup_printf ("%s %s%s", entry_keywords, mime_keyword ? "+" : "", | ||
91 | mime_keyword ? mime_keyword : ""); | ||
92 | g_free (mime_keyword); | ||
93 | if (nsid != NULL) | ||
94 | { | ||
95 | uri = GNUNET_FS_uri_sks_create_from_nsid (nsid, keywords); | ||
96 | GNUNET_assert (uri != NULL); | ||
97 | } | ||
98 | else | ||
99 | { | ||
100 | emsg = NULL; | ||
101 | uri = GNUNET_FS_uri_ksk_create (keywords, &emsg); | ||
102 | if (uri == NULL) | ||
103 | { | ||
104 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Invalid keyword string `%s': %s"), | ||
105 | keywords, emsg); | ||
106 | GNUNET_free_non_null (emsg); | ||
107 | return; | ||
108 | } | ||
109 | } | ||
110 | GNUNET_FS_search_start (GNUNET_FS_GTK_get_fs_handle (), uri, anonymity_level, | ||
111 | GNUNET_FS_SEARCH_OPTION_NONE, NULL); | ||
112 | |||
113 | g_free (keywords); | ||
114 | GNUNET_FS_uri_destroy (uri); | ||
115 | } | ||
116 | |||
117 | |||
118 | gboolean | ||
119 | main_window_search_entry_key_press_event_cb (GtkWidget * widget, | ||
120 | GdkEventKey * event, | ||
121 | gpointer user_data) | ||
122 | { | ||
123 | GtkBuilder *builder; | ||
124 | |||
125 | builder = GTK_BUILDER (user_data); | ||
126 | |||
127 | if (event->keyval == GDK_KEY_Return) | ||
128 | { | ||
129 | GtkWidget *find = GTK_WIDGET (gtk_builder_get_object (builder, | ||
130 | "main_window_search_button")); | ||
131 | |||
132 | main_window_search_button_clicked_cb (GTK_BUTTON (find), user_data); | ||
133 | return TRUE; | ||
134 | } | ||
135 | return FALSE; | ||
136 | } | ||
137 | |||