aboutsummaryrefslogtreecommitdiff
path: root/src/fs/gnunet-fs-gtk_main-window-search.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/fs/gnunet-fs-gtk_main-window-search.c')
-rw-r--r--src/fs/gnunet-fs-gtk_main-window-search.c189
1 files changed, 189 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..fdab7b94
--- /dev/null
+++ b/src/fs/gnunet-fs-gtk_main-window-search.c
@@ -0,0 +1,189 @@
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 "gnunet-fs-gtk.h"
28#include "gnunet-fs-gtk_anonymity-widgets.h"
29
30
31/**
32 * Start a search.
33 *
34 * @param builder the main dialog builder
35 */
36static void
37start_search (GtkBuilder *builder)
38{
39 guint anonymity_level;
40 gchar *keywords;
41 gchar *mime_keyword;
42 GNUNET_HashCode *nsid;
43 struct GNUNET_FS_Uri *uri;
44
45 /* get anonymity level */
46 if (!GNUNET_GTK_get_selected_anonymity_level
47 (builder, "main_window_search_anonymity_combobox", &anonymity_level))
48 {
49 GNUNET_break (0);
50 return;
51 }
52
53 /* get selected mime type */
54 {
55 GtkComboBox *mime_combo;
56 GtkTreeModel *mime_model;
57 GtkTreeIter iter;
58
59 mime_combo = GTK_COMBO_BOX (GNUNET_FS_GTK_get_main_window_object
60 ("main_window_search_mime_combobox"));
61 mime_model = gtk_combo_box_get_model (mime_combo);
62 mime_keyword = NULL;
63 if ( (NULL != mime_model) &&
64 gtk_combo_box_get_active_iter (mime_combo, &iter))
65 gtk_tree_model_get (mime_model, &iter, 0, &mime_keyword, -1);
66 if (0 == strcmp (mime_keyword, " "))
67 {
68 g_free (mime_keyword);
69 mime_keyword = NULL;
70 }
71 }
72
73 /* get selected namespace */
74 {
75 GtkTreeRowReference *ref;
76 GtkToggleButton *toggle_button;
77 GtkTreeIter iter;
78
79 nsid = NULL;
80 toggle_button =
81 GTK_TOGGLE_BUTTON (gtk_builder_get_object
82 (builder,
83 "main_window_search_namespace_dropdown_button"));
84 ref = g_object_get_data (G_OBJECT (toggle_button), "selected-row-reference");
85 if (NULL != ref)
86 {
87 GtkTreePath *namespace_treepath;
88 GtkTreeModel *namespace_model;
89
90 namespace_model = gtk_tree_row_reference_get_model (ref);
91 namespace_treepath = gtk_tree_row_reference_get_path (ref);
92 if ( (NULL != namespace_treepath) &&
93 (gtk_tree_model_get_iter (namespace_model, &iter, namespace_treepath)))
94 gtk_tree_model_get (namespace_model, &iter, 1, &nsid, -1);
95 }
96 }
97
98 /* get keywords and compose keyword string */
99 {
100 GtkEntry *query_entry;
101 const char *entry_keywords;
102
103 query_entry = GTK_ENTRY (gtk_builder_get_object (builder,
104 "main_window_search_entry"));
105 entry_keywords = gtk_entry_get_text (query_entry);
106 if (NULL != mime_keyword)
107 {
108 keywords = g_strdup_printf ("%s +%s",
109 entry_keywords,
110 mime_keyword);
111 g_free (mime_keyword);
112 }
113 else
114 {
115 keywords = g_strdup (entry_keywords);
116 }
117 }
118
119 /* build KSK/SKS URI */
120 if (NULL != nsid)
121 {
122 uri = GNUNET_FS_uri_sks_create_from_nsid (nsid, keywords);
123 GNUNET_assert (uri != NULL);
124 }
125 else
126 {
127 char *emsg = NULL;
128
129 uri = GNUNET_FS_uri_ksk_create (keywords, &emsg);
130 if (NULL == uri)
131 {
132 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Invalid keyword string `%s': %s"),
133 keywords, emsg);
134 g_free (keywords);
135 GNUNET_free_non_null (emsg);
136 return;
137 }
138 }
139 g_free (keywords);
140
141 /* start search */
142 GNUNET_FS_search_start (GNUNET_FS_GTK_get_fs_handle (),
143 uri, anonymity_level,
144 GNUNET_FS_SEARCH_OPTION_NONE, NULL);
145 GNUNET_FS_uri_destroy (uri);
146}
147
148
149/**
150 * User clicked on the 'search' button in the main window.
151 *
152 * @param button the search button
153 * @param user_data the main dialog builder
154 */
155void
156main_window_search_button_clicked_cb (GtkButton * button,
157 gpointer user_data)
158{
159 GtkBuilder *builder = GTK_BUILDER (user_data);
160
161 start_search (builder);
162}
163
164
165/**
166 * User pushed a key (possibly ENTER) in the search entry widget.
167 * Start the search if it was ENTER.
168 *
169 * @param widget the entry widget
170 * @param event the key stroke
171 * @param user_data the builder of the main window
172 * @return FALSE if this was not ENTER, TRUE if it was
173 */
174gboolean
175main_window_search_entry_key_press_event_cb (GtkWidget * widget,
176 GdkEventKey * event,
177 gpointer user_data)
178{
179 GtkBuilder *builder = GTK_BUILDER (user_data);
180
181 if (event->keyval == GDK_KEY_Return)
182 {
183 start_search (builder);
184 return TRUE;
185 }
186 return FALSE;
187}
188
189/* end of gnunet-fs-gtk_main-window-search.c */