aboutsummaryrefslogtreecommitdiff
path: root/src/fs/gnunet-fs-gtk-main_window_file_search.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/fs/gnunet-fs-gtk-main_window_file_search.c')
-rw-r--r--src/fs/gnunet-fs-gtk-main_window_file_search.c243
1 files changed, 243 insertions, 0 deletions
diff --git a/src/fs/gnunet-fs-gtk-main_window_file_search.c b/src/fs/gnunet-fs-gtk-main_window_file_search.c
new file mode 100644
index 00000000..bef1d2b7
--- /dev/null
+++ b/src/fs/gnunet-fs-gtk-main_window_file_search.c
@@ -0,0 +1,243 @@
1/*
2 This file is part of GNUnet
3 (C) 2005, 2006, 2010 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/main_window_file_search.c
23 * @author Christian Grothoff
24 */
25#include "common.h"
26#include "gnunet-fs-gtk.h"
27
28/**
29 * Builder used for the search dialog.
30 */
31static GtkBuilder *builder;
32
33
34/**
35 * User double-clicked on namespace or pressed enter;
36 * move namespace root to the 'keywords' line.
37 */
38void
39GNUNET_GTK_search_dialog_namespace_tree_view_row_activated_cb (GtkTreeView *tree_view,
40 GtkTreePath *path,
41 GtkTreeViewColumn *column,
42 gpointer user_data)
43{
44 GtkTreeModel *ls;
45 GtkTreeSelection *sel;
46 GtkEntry *query;
47 GtkTreeIter iter;
48 char *root;
49
50 query = GTK_ENTRY (gtk_builder_get_object (builder,
51 "GNUNET_GTK_search_dialog_keyword_entry"));
52 sel = gtk_tree_view_get_selection (tree_view);
53 if (TRUE ==
54 gtk_tree_selection_get_selected (sel,
55 &ls,
56 &iter))
57 {
58 gtk_tree_model_get (ls, &iter,
59 1, &root,
60 -1);
61 gtk_entry_set_text (query,
62 root);
63 GNUNET_free (root);
64 }
65}
66
67
68void
69GNUNET_GTK_search_dialog_search_button_clicked_cb (GtkWidget * dummy,
70 gpointer data)
71{
72 GtkEntry *query;
73 GtkSpinButton *anonymity;
74 GtkTreeView *namespace;
75 const char *keywords;
76 char *emsg;
77 struct GNUNET_FS_Uri *uri;
78 GNUNET_HashCode *nsid;
79 GtkTreeModel *ls;
80 GtkTreeSelection *sel;
81 GtkTreeIter iter;
82
83 query = GTK_ENTRY (gtk_builder_get_object (builder,
84 "GNUNET_GTK_search_dialog_keyword_entry"));
85 anonymity = GTK_SPIN_BUTTON (gtk_builder_get_object (builder,
86 "GNUNET_GTK_search_dialog_anonymity_spin_button"));
87 namespace = GTK_TREE_VIEW (gtk_builder_get_object (builder,
88 "GNUNET_GTK_search_dialog_namespace_tree_view"));
89 keywords = gtk_entry_get_text (query);
90 nsid = NULL;
91 sel = gtk_tree_view_get_selection (namespace);
92 if (TRUE ==
93 gtk_tree_selection_get_selected (sel,
94 &ls,
95 &iter))
96 gtk_tree_model_get (ls, &iter,
97 2, &nsid,
98 -1);
99 if (nsid != NULL)
100 {
101 uri = GNUNET_FS_uri_sks_create_from_nsid (nsid,
102 keywords);
103 GNUNET_assert (uri != NULL);
104 }
105 else
106 {
107 emsg = NULL;
108 uri = GNUNET_FS_uri_ksk_create (keywords, &emsg);
109 if (uri == NULL)
110 {
111 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
112 _("Invalid keyword string `%s': %s"),
113 keywords,
114 emsg);
115 GNUNET_free_non_null (emsg);
116 return;
117 }
118 }
119 GNUNET_FS_search_start (GNUNET_FS_GTK_get_fs_handle (),
120 uri,
121 gtk_spin_button_get_value_as_int (anonymity),
122 GNUNET_FS_SEARCH_OPTION_NONE,
123 NULL);
124 GNUNET_FS_uri_destroy (uri);
125}
126
127
128
129/**
130 * Add pseudonym data to list store
131 *
132 * @param cls closure (the 'GtkListStore')
133 * @param pseudonym hash code of public key of pseudonym
134 * @param md meta data known about the pseudonym
135 * @param rating the local rating of the pseudonym
136 * @return GNUNET_OK to continue iteration, GNUNET_SYSERR to abort
137 */
138static int
139add_namespace_to_ls (void *cls,
140 const GNUNET_HashCode *
141 pseudonym,
142 const struct
143 GNUNET_CONTAINER_MetaData * md,
144 int rating)
145{
146 GtkListStore *ls = cls;
147 char *root;
148 char *ns_name;
149 GNUNET_HashCode *nsid;
150 char *description;
151 char *uris;
152 char *emsg;
153 struct GNUNET_FS_Uri *uri;
154 GtkTreeIter iter;
155
156 ns_name = GNUNET_PSEUDONYM_id_to_name (GNUNET_FS_GTK_get_configuration (),
157 pseudonym);
158 nsid = GNUNET_malloc (sizeof (GNUNET_HashCode));
159 *nsid = *pseudonym;
160 root = NULL;
161 uris = GNUNET_CONTAINER_meta_data_get_by_type (md,
162 EXTRACTOR_METATYPE_URI);
163 if (uris != NULL)
164 {
165 emsg = NULL;
166 uri = GNUNET_FS_uri_parse (uris, &emsg);
167 if (uri == NULL)
168 GNUNET_free (emsg);
169 root = GNUNET_FS_uri_sks_get_content_id (uri);
170 GNUNET_FS_uri_destroy (uri);
171 }
172 description = GNUNET_CONTAINER_meta_data_get_first_by_types (md,
173 EXTRACTOR_METATYPE_TITLE,
174 EXTRACTOR_METATYPE_BOOK_TITLE,
175 EXTRACTOR_METATYPE_DESCRIPTION,
176 EXTRACTOR_METATYPE_SUMMARY,
177 EXTRACTOR_METATYPE_ALBUM,
178 EXTRACTOR_METATYPE_COMMENT,
179 EXTRACTOR_METATYPE_SUBJECT,
180 EXTRACTOR_METATYPE_KEYWORDS,
181 -1);
182 gtk_list_store_insert_with_values (ls,
183 &iter,
184 G_MAXINT,
185 0, ns_name,
186 1, root,
187 2, nsid,
188 3, description,
189 -1);
190 GNUNET_free (ns_name);
191 GNUNET_free_non_null (root);
192 GNUNET_free_non_null (description);
193 return GNUNET_OK;
194}
195
196
197/**
198 * Search selected in 'file' menu.
199 */
200void
201GNUNET_GTK_main_menu_file_search_activate_cb (GtkWidget * dummy,
202 gpointer data)
203{
204 GtkWidget *ad;
205 GtkListStore *ls;
206 GtkTreeIter iter;
207 GNUNET_HashCode *nsid;
208
209 GNUNET_assert (builder == NULL);
210 builder = GNUNET_GTK_get_new_builder ("search_dialog.glade");
211 if (builder == NULL)
212 return;
213 ad = GTK_WIDGET (gtk_builder_get_object (builder,
214 "GNUNET_GTK_search_dialog"));
215 ls = GTK_LIST_STORE (gtk_builder_get_object (builder,
216 "GNUNET_GTK_namespace_list_store"));
217 GNUNET_PSEUDONYM_list_all (GNUNET_FS_GTK_get_configuration (),
218 &add_namespace_to_ls,
219 ls);
220 gtk_dialog_run (GTK_DIALOG (ad));
221
222 /* free nsids from 'ls' */
223 if (TRUE ==
224 gtk_tree_model_get_iter_first (GTK_TREE_MODEL (ls),
225 &iter))
226 {
227 do
228 {
229 gtk_tree_model_get (GTK_TREE_MODEL (ls),
230 &iter,
231 2, &nsid,
232 -1);
233 GNUNET_free (nsid);
234 }
235 while (TRUE == gtk_tree_model_iter_next (GTK_TREE_MODEL (ls),
236 &iter));
237 }
238 gtk_widget_destroy (ad);
239 g_object_unref (G_OBJECT (builder));
240 builder = NULL;
241}
242
243/* end of main_window_file_search.c */