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