diff options
Diffstat (limited to 'src/plugins/fs/namespace_search.c')
-rw-r--r-- | src/plugins/fs/namespace_search.c | 396 |
1 files changed, 187 insertions, 209 deletions
diff --git a/src/plugins/fs/namespace_search.c b/src/plugins/fs/namespace_search.c index 5a15194b..d89297f6 100644 --- a/src/plugins/fs/namespace_search.c +++ b/src/plugins/fs/namespace_search.c | |||
@@ -39,73 +39,67 @@ | |||
39 | * The spin button giving the rating for a particular namespace | 39 | * The spin button giving the rating for a particular namespace |
40 | * has been changed. Store the new rating for the namespace. | 40 | * has been changed. Store the new rating for the namespace. |
41 | */ | 41 | */ |
42 | void on_namespaceRatingSpinButton_changed_fs(GtkWidget * dummy, | 42 | void |
43 | GtkWidget * dummy2) { | 43 | on_namespaceRatingSpinButton_changed_fs (GtkWidget * dummy, |
44 | GtkWidget * spin; | 44 | GtkWidget * dummy2) |
45 | GtkWidget * ncbe; | 45 | { |
46 | GtkTreeModel * model; | 46 | GtkWidget *spin; |
47 | GtkWidget *ncbe; | ||
48 | GtkTreeModel *model; | ||
47 | GtkTreeIter iter; | 49 | GtkTreeIter iter; |
48 | char * encStr; | 50 | char *encStr; |
49 | char * description; | 51 | char *description; |
50 | int rating; | 52 | int rating; |
51 | int newrating; | 53 | int newrating; |
52 | 54 | ||
53 | DEBUG_BEGIN(); | 55 | DEBUG_BEGIN (); |
54 | spin | 56 | spin = glade_xml_get_widget (getMainXML (), "namespaceRatingSpinButton"); |
55 | = glade_xml_get_widget(getMainXML(), | 57 | ncbe = glade_xml_get_widget (getMainXML (), "searchNamespaceComboBoxEntry"); |
56 | "namespaceRatingSpinButton"); | 58 | model = gtk_combo_box_get_model (GTK_COMBO_BOX (ncbe)); |
57 | ncbe | ||
58 | = glade_xml_get_widget(getMainXML(), | ||
59 | "searchNamespaceComboBoxEntry"); | ||
60 | model = gtk_combo_box_get_model(GTK_COMBO_BOX(ncbe)); | ||
61 | description = NULL; | 59 | description = NULL; |
62 | encStr = NULL; | 60 | encStr = NULL; |
63 | if (TRUE == gtk_combo_box_get_active_iter(GTK_COMBO_BOX(ncbe), | 61 | if (TRUE == gtk_combo_box_get_active_iter (GTK_COMBO_BOX (ncbe), &iter)) |
64 | &iter)) { | 62 | { |
65 | gtk_tree_model_get(model, | 63 | gtk_tree_model_get (model, |
66 | &iter, | 64 | &iter, |
67 | NS_SEARCH_DESCRIPTION, &description, | 65 | NS_SEARCH_DESCRIPTION, &description, |
68 | NS_SEARCH_ENCNAME, &encStr, | 66 | NS_SEARCH_ENCNAME, &encStr, |
69 | NS_SEARCH_RATING, &rating, | 67 | NS_SEARCH_RATING, &rating, -1); |
70 | -1); | 68 | if ((description != NULL) && (0 == strcmp (description, _("globally")))) |
71 | if ( (description != NULL) && | 69 | { |
72 | (0 == strcmp(description, | 70 | /* just to be sure */ |
73 | _("globally"))) ) { | 71 | gtk_widget_set_sensitive (spin, FALSE); |
74 | /* just to be sure */ | 72 | } |
75 | gtk_widget_set_sensitive(spin, | 73 | else |
76 | FALSE); | 74 | { |
77 | } else { | 75 | if (encStr != NULL) |
78 | if (encStr != NULL) { | 76 | { |
79 | newrating = gtk_spin_button_get_value(GTK_SPIN_BUTTON(spin)); | 77 | newrating = gtk_spin_button_get_value (GTK_SPIN_BUTTON (spin)); |
80 | rating = NS_rankNamespace(ectx, | 78 | rating = NS_rankNamespace (ectx, |
81 | cfg, | 79 | cfg, encStr, newrating - rating); |
82 | encStr, | 80 | if (rating != newrating) |
83 | newrating - rating); | 81 | { |
84 | if (rating != newrating) { | 82 | /* concurrent modification? */ |
85 | /* concurrent modification? */ | 83 | gtk_spin_button_set_value (GTK_SPIN_BUTTON (spin), rating); |
86 | gtk_spin_button_set_value(GTK_SPIN_BUTTON(spin), | 84 | GE_BREAK (ectx, 0); |
87 | rating); | 85 | } |
88 | GE_BREAK(ectx, 0); | 86 | gtk_list_store_set (GTK_LIST_STORE (model), |
89 | } | 87 | &iter, NS_SEARCH_RATING, rating, -1); |
90 | gtk_list_store_set(GTK_LIST_STORE(model), | 88 | } |
91 | &iter, | 89 | } |
92 | NS_SEARCH_RATING, rating, | 90 | } |
93 | -1); | 91 | else |
94 | } | 92 | { |
93 | /* FIXME: if enc2hash succeeds, we may want to keep this | ||
94 | active */ | ||
95 | gtk_spin_button_set_value (GTK_SPIN_BUTTON (spin), 0); | ||
96 | gtk_widget_set_sensitive (spin, FALSE); | ||
95 | } | 97 | } |
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) | 98 | if (description != NULL) |
105 | free(description); | 99 | free (description); |
106 | if (encStr != NULL) | 100 | if (encStr != NULL) |
107 | free(encStr); | 101 | free (encStr); |
108 | DEBUG_END(); | 102 | DEBUG_END (); |
109 | } | 103 | } |
110 | 104 | ||
111 | 105 | ||
@@ -114,175 +108,159 @@ void on_namespaceRatingSpinButton_changed_fs(GtkWidget * dummy, | |||
114 | * Update the trust level (possibly changing sensitivity) | 108 | * Update the trust level (possibly changing sensitivity) |
115 | * and set the search string to the root (if available). | 109 | * and set the search string to the root (if available). |
116 | */ | 110 | */ |
117 | void on_searchNamespaceComboBoxEntry_changed_fs(GtkWidget * dummy, | 111 | void |
118 | GtkWidget * dummy2) { | 112 | on_searchNamespaceComboBoxEntry_changed_fs (GtkWidget * dummy, |
119 | GtkWidget * keyword; | 113 | GtkWidget * dummy2) |
120 | GtkWidget * spin; | 114 | { |
121 | GtkWidget * ncbe; | 115 | GtkWidget *keyword; |
122 | GtkTreeModel * model; | 116 | GtkWidget *spin; |
117 | GtkWidget *ncbe; | ||
118 | GtkTreeModel *model; | ||
123 | GtkTreeIter iter; | 119 | GtkTreeIter iter; |
124 | int rating; | 120 | int rating; |
125 | char * encStr; | 121 | char *encStr; |
126 | char * descStr; | 122 | char *descStr; |
127 | HashCode512 ns; | 123 | HashCode512 ns; |
128 | HashCode512 root; | 124 | HashCode512 root; |
129 | EncName enc; | 125 | EncName enc; |
130 | 126 | ||
131 | DEBUG_BEGIN(); | 127 | DEBUG_BEGIN (); |
132 | spin | 128 | spin = glade_xml_get_widget (getMainXML (), "namespaceRatingSpinButton"); |
133 | = glade_xml_get_widget(getMainXML(), | 129 | ncbe = glade_xml_get_widget (getMainXML (), "searchNamespaceComboBoxEntry"); |
134 | "namespaceRatingSpinButton"); | 130 | model = gtk_combo_box_get_model (GTK_COMBO_BOX (ncbe)); |
135 | ncbe | ||
136 | = glade_xml_get_widget(getMainXML(), | ||
137 | "searchNamespaceComboBoxEntry"); | ||
138 | model = gtk_combo_box_get_model(GTK_COMBO_BOX(ncbe)); | ||
139 | descStr = NULL; | 131 | descStr = NULL; |
140 | encStr = NULL; | 132 | encStr = NULL; |
141 | if (TRUE == gtk_combo_box_get_active_iter(GTK_COMBO_BOX(ncbe), | 133 | if (TRUE == gtk_combo_box_get_active_iter (GTK_COMBO_BOX (ncbe), &iter)) |
142 | &iter)) { | 134 | { |
143 | gtk_tree_model_get(model, | 135 | gtk_tree_model_get (model, |
144 | &iter, | 136 | &iter, |
145 | NS_SEARCH_DESCRIPTION, &descStr, | 137 | NS_SEARCH_DESCRIPTION, &descStr, |
146 | NS_SEARCH_ENCNAME, &encStr, | 138 | NS_SEARCH_ENCNAME, &encStr, |
147 | NS_SEARCH_RATING, &rating, | 139 | NS_SEARCH_RATING, &rating, -1); |
148 | -1); | 140 | if ((descStr != NULL) && (0 == strcmp (descStr, _("globally")))) |
149 | if ( (descStr != NULL) && | 141 | { |
150 | (0 == strcmp(descStr, | 142 | gtk_spin_button_set_value (GTK_SPIN_BUTTON (spin), 0); |
151 | _("globally"))) ) { | 143 | gtk_widget_set_sensitive (spin, FALSE); |
152 | gtk_spin_button_set_value(GTK_SPIN_BUTTON(spin), | 144 | } |
153 | 0); | 145 | else if (encStr != NULL) |
154 | gtk_widget_set_sensitive(spin, | 146 | { |
155 | FALSE); | 147 | enc2hash (encStr, &ns); |
156 | } else if (encStr != NULL) { | 148 | gtk_spin_button_set_value (GTK_SPIN_BUTTON (spin), rating); |
157 | enc2hash(encStr, | 149 | gtk_widget_set_sensitive (spin, TRUE); |
158 | &ns); | 150 | keyword |
159 | gtk_spin_button_set_value(GTK_SPIN_BUTTON(spin), | 151 | = glade_xml_get_widget (getMainXML (), |
160 | rating); | 152 | "fssearchKeywordComboBoxEntry"); |
161 | gtk_widget_set_sensitive(spin, | 153 | if (OK == NS_getNamespaceRoot (ectx, cfg, encStr, &root)) |
162 | TRUE); | 154 | { |
163 | keyword | 155 | hash2enc (&root, &enc); |
164 | = glade_xml_get_widget(getMainXML(), | 156 | gtk_entry_set_text (GTK_ENTRY |
165 | "fssearchKeywordComboBoxEntry"); | 157 | (gtk_bin_get_child (GTK_BIN (keyword))), |
166 | if (OK == NS_getNamespaceRoot(ectx, | 158 | (const gchar *) &enc); |
167 | cfg, | 159 | } |
168 | encStr, | 160 | else |
169 | &root)) { | 161 | { |
170 | hash2enc(&root, | 162 | gtk_entry_set_text (GTK_ENTRY |
171 | &enc); | 163 | (gtk_bin_get_child (GTK_BIN (keyword))), |
172 | gtk_entry_set_text(GTK_ENTRY(gtk_bin_get_child(GTK_BIN(keyword))), | 164 | ""); |
173 | (const gchar*) &enc); | 165 | } |
174 | } else { | 166 | } |
175 | gtk_entry_set_text(GTK_ENTRY(gtk_bin_get_child(GTK_BIN(keyword))), | 167 | } |
176 | ""); | 168 | else |
177 | } | 169 | { |
170 | gtk_spin_button_set_value (GTK_SPIN_BUTTON (spin), 0); | ||
171 | gtk_widget_set_sensitive (spin, FALSE); | ||
178 | } | 172 | } |
179 | } else { | ||
180 | gtk_spin_button_set_value(GTK_SPIN_BUTTON(spin), | ||
181 | 0); | ||
182 | gtk_widget_set_sensitive(spin, | ||
183 | FALSE); | ||
184 | } | ||
185 | if (descStr != NULL) | 173 | if (descStr != NULL) |
186 | free(descStr); | 174 | free (descStr); |
187 | if (encStr != NULL) | 175 | if (encStr != NULL) |
188 | free(encStr); | 176 | free (encStr); |
189 | DEBUG_END(); | 177 | DEBUG_END (); |
190 | } | 178 | } |
191 | 179 | ||
192 | struct NewNamespaceInfo { | 180 | struct NewNamespaceInfo |
193 | const char * namespaceName; | 181 | { |
194 | const HashCode512 * namespaceId; | 182 | const char *namespaceName; |
195 | const struct ECRS_MetaData * md; | 183 | const HashCode512 *namespaceId; |
184 | const struct ECRS_MetaData *md; | ||
196 | int rating; | 185 | int rating; |
197 | }; | 186 | }; |
198 | 187 | ||
199 | static void * saveDiscovery(void * cls) { | 188 | static void * |
200 | struct NewNamespaceInfo * nni = cls; | 189 | saveDiscovery (void *cls) |
190 | { | ||
191 | struct NewNamespaceInfo *nni = cls; | ||
201 | 192 | ||
202 | GtkListStore * model; | 193 | GtkListStore *model; |
203 | GtkTreeIter iter; | 194 | GtkTreeIter iter; |
204 | EncName enc; | 195 | EncName enc; |
205 | char * name; | 196 | char *name; |
206 | struct ECRS_MetaData * dmd; | 197 | struct ECRS_MetaData *dmd; |
207 | GtkWidget * ncbe; | 198 | GtkWidget *ncbe; |
208 | char * desc; | 199 | char *desc; |
209 | size_t n; | 200 | size_t n; |
210 | int found; | 201 | int found; |
211 | char * encName; | 202 | char *encName; |
212 | 203 | ||
213 | DEBUG_BEGIN(); | 204 | DEBUG_BEGIN (); |
214 | ncbe | 205 | ncbe = glade_xml_get_widget (getMainXML (), "searchNamespaceComboBoxEntry"); |
215 | = glade_xml_get_widget(getMainXML(), | 206 | model = GTK_LIST_STORE (gtk_combo_box_get_model (GTK_COMBO_BOX (ncbe))); |
216 | "searchNamespaceComboBoxEntry"); | 207 | hash2enc (nni->namespaceId, &enc); |
217 | model = GTK_LIST_STORE(gtk_combo_box_get_model(GTK_COMBO_BOX(ncbe))); | 208 | if (nni->md == NULL) |
218 | hash2enc(nni->namespaceId, | 209 | { |
219 | &enc); | 210 | dmd = NULL; |
220 | if (nni->md == NULL) { | 211 | desc = STRDUP (""); |
221 | dmd = NULL; | 212 | } |
222 | desc = STRDUP(""); | 213 | else |
223 | } else { | 214 | { |
224 | dmd = ECRS_dupMetaData(nni->md); | 215 | dmd = ECRS_dupMetaData (nni->md); |
225 | desc = ECRS_getFirstFromMetaData(dmd, | 216 | desc = ECRS_getFirstFromMetaData (dmd, |
226 | EXTRACTOR_DESCRIPTION, | 217 | EXTRACTOR_DESCRIPTION, |
227 | EXTRACTOR_TITLE, | 218 | EXTRACTOR_TITLE, |
228 | EXTRACTOR_AUTHOR, | 219 | EXTRACTOR_AUTHOR, |
229 | EXTRACTOR_GENRE, | 220 | EXTRACTOR_GENRE, |
230 | EXTRACTOR_SUBJECT, | 221 | EXTRACTOR_SUBJECT, |
231 | EXTRACTOR_CREATOR, | 222 | EXTRACTOR_CREATOR, |
232 | EXTRACTOR_PRODUCER, | 223 | EXTRACTOR_PRODUCER, |
233 | EXTRACTOR_GROUP, | 224 | EXTRACTOR_GROUP, |
234 | EXTRACTOR_CREATED_FOR, | 225 | EXTRACTOR_CREATED_FOR, |
235 | EXTRACTOR_SUMMARY, | 226 | EXTRACTOR_SUMMARY, |
236 | EXTRACTOR_OWNER, | 227 | EXTRACTOR_OWNER, -1); |
237 | -1); | 228 | if (desc == NULL) |
238 | if (desc == NULL) | 229 | desc = STRDUP (""); |
239 | desc = STRDUP(""); | 230 | } |
240 | } | ||
241 | 231 | ||
242 | n = strlen(desc) + 64; | 232 | n = strlen (desc) + 64; |
243 | name = MALLOC(n); | 233 | name = MALLOC (n); |
244 | SNPRINTF(name, | 234 | SNPRINTF (name, n, "%s: %.*s", desc, 20, &enc); |
245 | n, | ||
246 | "%s: %.*s", | ||
247 | desc, | ||
248 | 20, | ||
249 | &enc); | ||
250 | /* check if present! */ | 235 | /* check if present! */ |
251 | found = NO; | 236 | found = NO; |
252 | if (gtk_tree_model_get_iter_first(GTK_TREE_MODEL(model), | 237 | if (gtk_tree_model_get_iter_first (GTK_TREE_MODEL (model), &iter)) |
253 | &iter)) { | 238 | { |
254 | do { | 239 | do |
255 | gtk_tree_model_get(GTK_TREE_MODEL(model), | 240 | { |
256 | &iter, | 241 | gtk_tree_model_get (GTK_TREE_MODEL (model), |
257 | NS_SEARCH_ENCNAME, &encName, | 242 | &iter, NS_SEARCH_ENCNAME, &encName, -1); |
258 | -1); | 243 | if ((encName != NULL) && |
259 | if ( (encName != NULL) && | 244 | (0 == strcmp (encName, (const char *) &enc))) |
260 | (0 == strcmp(encName, | 245 | found = YES; |
261 | (const char*) &enc)) ) | 246 | FREENONNULL (encName); |
262 | found =YES; | 247 | } |
263 | FREENONNULL(encName); | 248 | while ((found == NO) && |
264 | } while ( (found == NO) && | 249 | (gtk_tree_model_iter_next (GTK_TREE_MODEL (model), &iter))); |
265 | (gtk_tree_model_iter_next(GTK_TREE_MODEL(model), | 250 | } |
266 | &iter)) ); | 251 | if (found == NO) |
267 | } | 252 | { |
268 | if (found == NO) { | 253 | infoMessage (YES, _("Namespace found: %s - %.*s\n"), desc, 20, &enc); |
269 | infoMessage(YES, | 254 | gtk_list_store_append (model, &iter); |
270 | _("Namespace found: %s - %.*s\n"), | 255 | gtk_list_store_set (model, |
271 | desc, | 256 | &iter, |
272 | 20, | 257 | NS_SEARCH_DESCRIPTION, name, |
273 | &enc); | 258 | NS_SEARCH_ENCNAME, &enc, |
274 | gtk_list_store_append(model, | 259 | NS_SEARCH_METADATA, dmd, |
275 | &iter); | 260 | NS_SEARCH_RATING, nni->rating, -1); |
276 | gtk_list_store_set(model, | 261 | } |
277 | &iter, | 262 | FREE (name); |
278 | NS_SEARCH_DESCRIPTION, name, | 263 | DEBUG_END (); |
279 | NS_SEARCH_ENCNAME, &enc, | ||
280 | NS_SEARCH_METADATA, dmd, | ||
281 | NS_SEARCH_RATING, nni->rating, | ||
282 | -1); | ||
283 | } | ||
284 | FREE(name); | ||
285 | DEBUG_END(); | ||
286 | 264 | ||
287 | return NULL; | 265 | return NULL; |
288 | } | 266 | } |
@@ -299,17 +277,17 @@ static void * saveDiscovery(void * cls) { | |||
299 | * @param rating the local rating of the namespace | 277 | * @param rating the local rating of the namespace |
300 | * @return OK (always) | 278 | * @return OK (always) |
301 | */ | 279 | */ |
302 | int namespace_discovered_cb(void * cls, | 280 | int |
303 | const char * namespaceName, | 281 | namespace_discovered_cb (void *cls, |
304 | const HashCode512 * namespaceId, | 282 | const char *namespaceName, |
305 | const struct ECRS_MetaData * md, | 283 | const HashCode512 * namespaceId, |
306 | int rating) { | 284 | const struct ECRS_MetaData *md, int rating) |
285 | { | ||
307 | struct NewNamespaceInfo nni; | 286 | struct NewNamespaceInfo nni; |
308 | nni.namespaceName = namespaceName; | 287 | nni.namespaceName = namespaceName; |
309 | nni.namespaceId = namespaceId; | 288 | nni.namespaceId = namespaceId; |
310 | nni.md = md; | 289 | nni.md = md; |
311 | nni.rating = rating; | 290 | nni.rating = rating; |
312 | gtkSaveCall(&saveDiscovery, | 291 | gtkSaveCall (&saveDiscovery, &nni); |
313 | &nni); | ||
314 | return OK; | 292 | return OK; |
315 | } | 293 | } |