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