aboutsummaryrefslogtreecommitdiff
path: root/src/plugins/fs/namespace_search.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/plugins/fs/namespace_search.c')
-rw-r--r--src/plugins/fs/namespace_search.c187
1 files changed, 187 insertions, 0 deletions
diff --git a/src/plugins/fs/namespace_search.c b/src/plugins/fs/namespace_search.c
new file mode 100644
index 00000000..f5f7b1d8
--- /dev/null
+++ b/src/plugins/fs/namespace_search.c
@@ -0,0 +1,187 @@
1/*
2 This file is part of GNUnet.
3 (C) 2005, 2006 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/plugins/fs/namespace_search.c
23 * @brief code for namespace-related operations on the search frame
24 * @author Christian Grothoff
25 */
26
27#include "platform.h"
28#include "gnunetgtk_common.h"
29#include "fs.h"
30#include "helper.h"
31#include "meta.h"
32#include <GNUnet/gnunet_util_crypto.h>
33#include <GNUnet/gnunet_uritrack_lib.h>
34#include <GNUnet/gnunet_namespace_lib.h>
35#include <extractor.h>
36
37
38/**
39 * The spin button giving the rating for a particular namespace
40 * has been changed. Store the new rating for the namespace.
41 */
42void on_namespaceRatingSpinButton_changed_fs(GtkWidget * dummy,
43 GtkWidget * dummy2) {
44 GtkWidget * spin;
45 GtkWidget * ncbe;
46 GtkTreeModel * model;
47 GtkTreeIter iter;
48 char * encStr;
49 char * description;
50 int rating;
51 int newrating;
52
53 DEBUG_BEGIN();
54 spin
55 = glade_xml_get_widget(getMainXML(),
56 "namespaceRatingSpinButton");
57 ncbe
58 = glade_xml_get_widget(getMainXML(),
59 "searchNamespaceComboBoxEntry");
60 model = gtk_combo_box_get_model(GTK_COMBO_BOX(ncbe));
61 description = NULL;
62 encStr = NULL;
63 if (TRUE == gtk_combo_box_get_active_iter(GTK_COMBO_BOX(ncbe),
64 &iter)) {
65 gtk_tree_model_get(model,
66 &iter,
67 NS_SEARCH_DESCRIPTION, &description,
68 NS_SEARCH_ENCNAME, &encStr,
69 NS_SEARCH_RATING, &rating,
70 -1);
71 if ( (description != NULL) &&
72 (0 == strcmp(description,
73 _("globally"))) ) {
74 /* just to be sure */
75 gtk_widget_set_sensitive(spin,
76 FALSE);
77 } else {
78 if (encStr != NULL) {
79 newrating = gtk_spin_button_get_value(GTK_SPIN_BUTTON(spin));
80 rating = NS_rankNamespace(ectx,
81 cfg,
82 encStr,
83 newrating - rating);
84 if (rating != newrating) {
85 /* concurrent modification? */
86 gtk_spin_button_set_value(GTK_SPIN_BUTTON(spin),
87 rating);
88 GE_BREAK(ectx, 0);
89 }
90 gtk_list_store_set(GTK_LIST_STORE(model),
91 &iter,
92 NS_SEARCH_RATING, rating,
93 -1);
94 }
95 }
96 } else {
97 /* FIXME: if enc2hash succeeds, we may want to keep this
98 active */
99 gtk_spin_button_set_value(GTK_SPIN_BUTTON(spin),
100 0);
101 gtk_widget_set_sensitive(spin,
102 FALSE);
103 }
104 if (description != NULL)
105 free(description);
106 if (encStr != NULL)
107 free(encStr);
108 DEBUG_END();
109}
110
111
112/**
113 * The namespace in the search window has changed.
114 * Update the trust level (possibly changing sensitivity)
115 * and set the search string to the root (if available).
116 */
117void on_searchNamespaceComboBoxEntry_changed_fs(GtkWidget * dummy,
118 GtkWidget * dummy2) {
119 GtkWidget * keyword;
120 GtkWidget * spin;
121 GtkWidget * ncbe;
122 GtkTreeModel * model;
123 GtkTreeIter iter;
124 int rating;
125 char * encStr;
126 char * descStr;
127 HashCode512 ns;
128 HashCode512 root;
129 EncName enc;
130
131 DEBUG_BEGIN();
132 spin
133 = glade_xml_get_widget(getMainXML(),
134 "namespaceRatingSpinButton");
135 ncbe
136 = glade_xml_get_widget(getMainXML(),
137 "searchNamespaceComboBoxEntry");
138 model = gtk_combo_box_get_model(GTK_COMBO_BOX(ncbe));
139 descStr = NULL;
140 encStr = NULL;
141 if (TRUE == gtk_combo_box_get_active_iter(GTK_COMBO_BOX(ncbe),
142 &iter)) {
143 gtk_tree_model_get(model,
144 &iter,
145 NS_SEARCH_DESCRIPTION, &descStr,
146 NS_SEARCH_ENCNAME, &encStr,
147 NS_SEARCH_RATING, &rating,
148 -1);
149 if ( (descStr != NULL) &&
150 (0 == strcmp(descStr,
151 _("globally"))) ) {
152 gtk_spin_button_set_value(GTK_SPIN_BUTTON(spin),
153 0);
154 gtk_widget_set_sensitive(spin,
155 FALSE);
156 } else if (encStr != NULL) {
157 enc2hash(encStr,
158 &ns);
159 gtk_spin_button_set_value(GTK_SPIN_BUTTON(spin),
160 rating);
161 gtk_widget_set_sensitive(spin,
162 TRUE);
163 if (OK == NS_getNamespaceRoot(ectx,
164 cfg,
165 encStr,
166 &root)) {
167 hash2enc(&root,
168 &enc);
169 keyword
170 = glade_xml_get_widget(getMainXML(),
171 "fssearchKeywordComboBoxEntry");
172 gtk_entry_set_text(GTK_ENTRY(gtk_bin_get_child(GTK_BIN(keyword))),
173 (const gchar*) &enc);
174 }
175 }
176 } else {
177 gtk_spin_button_set_value(GTK_SPIN_BUTTON(spin),
178 0);
179 gtk_widget_set_sensitive(spin,
180 FALSE);
181 }
182 if (descStr != NULL)
183 free(descStr);
184 if (encStr != NULL)
185 free(encStr);
186 DEBUG_END();
187}