aboutsummaryrefslogtreecommitdiff
path: root/src/plugins/fs/search.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/plugins/fs/search.c')
-rw-r--r--src/plugins/fs/search.c300
1 files changed, 6 insertions, 294 deletions
diff --git a/src/plugins/fs/search.c b/src/plugins/fs/search.c
index 750e7432..2b235c05 100644
--- a/src/plugins/fs/search.c
+++ b/src/plugins/fs/search.c
@@ -209,146 +209,6 @@ static void freeIterSubtree(GtkTreeModel * tree,
209 iter)); 209 iter));
210} 210}
211 211
212/**
213 * The spin button giving the rating for a particular namespace
214 * has been changed. Store the new rating for the namespace.
215 */
216void on_namespaceRatingSpinButton_changed_fs(GtkWidget * dummy,
217 GtkWidget * dummy2) {
218 GtkWidget * spin;
219 GtkWidget * ncbe;
220 GtkTreeModel * model;
221 GtkTreeIter iter;
222 char * encStr;
223 char * description;
224 int rating;
225 int newrating;
226
227 DEBUG_BEGIN();
228 spin
229 = glade_xml_get_widget(getMainXML(),
230 "namespaceRatingSpinButton");
231 ncbe
232 = glade_xml_get_widget(getMainXML(),
233 "searchNamespaceComboBoxEntry");
234 model = gtk_combo_box_get_model(GTK_COMBO_BOX(ncbe));
235 if (TRUE == gtk_combo_box_get_active_iter(GTK_COMBO_BOX(ncbe),
236 &iter)) {
237 gtk_tree_model_get(model,
238 &iter,
239 NS_SEARCH_DESCRIPTION, &description,
240 NS_SEARCH_ENCNAME, &encStr,
241 NS_SEARCH_RATING, &rating,
242 -1);
243 if ( (description != NULL) &&
244 (0 == strcmp(description,
245 _("globally"))) ) {
246 /* just to be sure */
247 gtk_widget_set_sensitive(spin,
248 FALSE);
249 } else {
250 if (encStr != NULL) {
251 newrating = gtk_spin_button_get_value(GTK_SPIN_BUTTON(spin));
252 rating = NS_rankNamespace(ectx,
253 cfg,
254 encStr,
255 newrating - rating);
256 if (rating != newrating) {
257 /* concurrent modification? */
258 gtk_spin_button_set_value(GTK_SPIN_BUTTON(spin),
259 rating);
260 GE_BREAK(ectx, 0);
261 }
262 gtk_list_store_set(GTK_LIST_STORE(model),
263 &iter,
264 NS_SEARCH_RATING, rating,
265 -1);
266 }
267 }
268 } else {
269 /* FIXME: if enc2hash succeeds, we may want to keep this
270 active */
271 gtk_spin_button_set_value(GTK_SPIN_BUTTON(spin),
272 0);
273 gtk_widget_set_sensitive(spin,
274 FALSE);
275 }
276 DEBUG_END();
277}
278
279/**
280 * The namespace in the search window has changed.
281 * Update the trust level (possibly changing sensitivity)
282 * and set the search string to the root (if available).
283 */
284void on_searchNamespaceComboBoxEntry_changed_fs(GtkWidget * dummy,
285 GtkWidget * dummy2) {
286 GtkWidget * keyword;
287 GtkWidget * spin;
288 GtkWidget * ncbe;
289 GtkTreeModel * model;
290 GtkTreeIter iter;
291 int rating;
292 char * encStr;
293 char * descStr;
294 HashCode512 ns;
295 HashCode512 root;
296 EncName enc;
297
298 DEBUG_BEGIN();
299 spin
300 = glade_xml_get_widget(getMainXML(),
301 "namespaceRatingSpinButton");
302 ncbe
303 = glade_xml_get_widget(getMainXML(),
304 "searchNamespaceComboBoxEntry");
305 model = gtk_combo_box_get_model(GTK_COMBO_BOX(ncbe));
306 if (TRUE == gtk_combo_box_get_active_iter(GTK_COMBO_BOX(ncbe),
307 &iter)) {
308 encStr = NULL;
309 descStr = NULL;
310 gtk_tree_model_get(model,
311 &iter,
312 NS_SEARCH_DESCRIPTION, &descStr,
313 NS_SEARCH_ENCNAME, &encStr,
314 NS_SEARCH_RATING, &rating,
315 -1);
316 if ( (descStr != NULL) &&
317 (0 == strcmp(descStr,
318 _("globally"))) ) {
319 gtk_spin_button_set_value(GTK_SPIN_BUTTON(spin),
320 0);
321 gtk_widget_set_sensitive(spin,
322 FALSE);
323 } else if (encStr != NULL) {
324 enc2hash(encStr,
325 &ns);
326 gtk_spin_button_set_value(GTK_SPIN_BUTTON(spin),
327 rating);
328 gtk_widget_set_sensitive(spin,
329 TRUE);
330 if (OK == NS_getNamespaceRoot(ectx,
331 cfg,
332 encStr,
333 &root)) {
334 hash2enc(&root,
335 &enc);
336 keyword
337 = glade_xml_get_widget(getMainXML(),
338 "fssearchKeywordComboBoxEntry");
339 gtk_entry_set_text(GTK_ENTRY(gtk_bin_get_child(GTK_BIN(keyword))),
340 (const gchar*) &enc);
341 }
342 }
343 } else {
344 gtk_spin_button_set_value(GTK_SPIN_BUTTON(spin),
345 0);
346 gtk_widget_set_sensitive(spin,
347 FALSE);
348 }
349 DEBUG_END();
350}
351
352void on_searchResults_destroy_fs(GtkWidget * dummy, 212void on_searchResults_destroy_fs(GtkWidget * dummy,
353 GtkWidget * treeview) { 213 GtkWidget * treeview) {
354 GtkTreeStore * tree; 214 GtkTreeStore * tree;
@@ -1044,7 +904,8 @@ int openTabForSearch(struct FSUI_SearchList * slist,
1044 int i; 904 int i;
1045 unsigned int *file_count; 905 unsigned int *file_count;
1046 GtkWidget *tab_label; 906 GtkWidget *tab_label;
1047 char *tab_title, *new_title; 907 char * tab_title;
908 char * new_title;
1048 909
1049 DEBUG_BEGIN(); 910 DEBUG_BEGIN();
1050 description = ECRS_uriToString(uri); 911 description = ECRS_uriToString(uri);
@@ -1122,8 +983,8 @@ int openTabForSearch(struct FSUI_SearchList * slist,
1122void fs_search_start(struct GE_Context * e, 983void fs_search_start(struct GE_Context * e,
1123 struct GC_Configuration * c) { 984 struct GC_Configuration * c) {
1124 GtkWidget * searchCB; 985 GtkWidget * searchCB;
1125 GtkListStore * model;
1126 GtkWidget * searchList; 986 GtkWidget * searchList;
987 GtkListStore * model;
1127 GtkCellRenderer * renderer; 988 GtkCellRenderer * renderer;
1128 GtkTreeViewColumn * column; 989 GtkTreeViewColumn * column;
1129 int col; 990 int col;
@@ -1138,26 +999,20 @@ void fs_search_start(struct GE_Context * e,
1138 model = gtk_list_store_new(NS_SEARCH_NUM, 999 model = gtk_list_store_new(NS_SEARCH_NUM,
1139 G_TYPE_STRING, /* what we show */ 1000 G_TYPE_STRING, /* what we show */
1140 G_TYPE_STRING, /* EncName of namespace */ 1001 G_TYPE_STRING, /* EncName of namespace */
1141 G_TYPE_POINTER, 1002 G_TYPE_POINTER, /* ECRS MetaData */
1003 G_TYPE_POINTER, /* FSUI search list */
1142 G_TYPE_INT); /* Meta-data about namespace */ 1004 G_TYPE_INT); /* Meta-data about namespace */
1143 gtk_combo_box_set_model(GTK_COMBO_BOX(searchCB), 1005 gtk_combo_box_set_model(GTK_COMBO_BOX(searchCB),
1144 GTK_TREE_MODEL(model)); 1006 GTK_TREE_MODEL(model));
1145 gtk_combo_box_entry_set_text_column(GTK_COMBO_BOX_ENTRY(searchCB), 1007 gtk_combo_box_entry_set_text_column(GTK_COMBO_BOX_ENTRY(searchCB),
1146 NS_SEARCH_DESCRIPTION); 1008 NS_SEARCH_DESCRIPTION);
1147#if 0
1148 /* FIXME: replace with event callback! */
1149 cron_job_add(cron,
1150 &updateNCBModel,
1151 0,
1152 5 * cronMINUTES,
1153 NULL);
1154#endif
1155 searchList = glade_xml_get_widget(getMainXML(), 1009 searchList = glade_xml_get_widget(getMainXML(),
1156 "activeSearchesSummary"); 1010 "activeSearchesSummary");
1157 summary = 1011 summary =
1158 gtk_list_store_new(SER_SUM_NUM, 1012 gtk_list_store_new(SER_SUM_NUM,
1159 G_TYPE_STRING, /* name */ 1013 G_TYPE_STRING, /* name */
1160 G_TYPE_INT, /* # results */ 1014 G_TYPE_INT, /* # results */
1015 G_TYPE_POINTER, /* internal: FSUI search list */
1161 G_TYPE_POINTER); /* internal: uri */ 1016 G_TYPE_POINTER); /* internal: uri */
1162 gtk_tree_view_set_model(GTK_TREE_VIEW(searchList), 1017 gtk_tree_view_set_model(GTK_TREE_VIEW(searchList),
1163 GTK_TREE_MODEL(summary)); 1018 GTK_TREE_MODEL(summary));
@@ -1174,8 +1029,6 @@ void fs_search_start(struct GE_Context * e,
1174 gtk_tree_view_column_set_clickable(column, TRUE); 1029 gtk_tree_view_column_set_clickable(column, TRUE);
1175 gtk_tree_view_column_set_reorderable(column, TRUE); 1030 gtk_tree_view_column_set_reorderable(column, TRUE);
1176 gtk_tree_view_column_set_sort_column_id(column, SER_SUM_NAME); 1031 gtk_tree_view_column_set_sort_column_id(column, SER_SUM_NAME);
1177 /*gtk_tree_view_column_set_sort_indicator(column, TRUE);*/
1178
1179 gtk_tree_view_column_set_resizable(gtk_tree_view_get_column(GTK_TREE_VIEW(searchList), 1032 gtk_tree_view_column_set_resizable(gtk_tree_view_get_column(GTK_TREE_VIEW(searchList),
1180 col - 1), 1033 col - 1),
1181 TRUE); 1034 TRUE);
@@ -1199,149 +1052,8 @@ void fs_search_start(struct GE_Context * e,
1199} 1052}
1200 1053
1201void fs_search_stop() { 1054void fs_search_stop() {
1202 SearchList * list;
1203 GtkTreeIter iter;
1204 struct ECRS_URI * u;
1205
1206#if 0
1207 cron_job_del(cron,
1208 &updateNCBModel,
1209 5 * cronMINUTES,
1210 NULL);
1211#endif
1212 while (head != NULL) {
1213 list = head;
1214 head = head->next;
1215 freeSearchModel(list->model, NULL);
1216 gtkSaveCall((SimpleCallback)&closeSearchPage,
1217 list);
1218 FREE(list);
1219 }
1220
1221 /* free URIs in summary */
1222 if (gtk_tree_model_get_iter_first(GTK_TREE_MODEL(summary),
1223 &iter)) {
1224 do {
1225 gtk_tree_model_get(GTK_TREE_MODEL(summary),
1226 &iter,
1227 SER_SUM_URI, &u,
1228 -1);
1229 if (u != NULL)
1230 ECRS_freeUri(u);
1231 gtk_list_store_set(summary,
1232 &iter,
1233 SER_SUM_URI, NULL,
1234 -1);
1235 } while (gtk_tree_model_iter_next(GTK_TREE_MODEL(summary),
1236 &iter));
1237 }
1238} 1055}
1239 1056
1240/* Create the tab label and icon,
1241 * adding a little button to close the search
1242 * This function is a modified version of an Epiphany/Gedit code,
1243 * part of this work is copyrighted (GPL license) by its authors.
1244 */
1245GtkWidget *buildSearchTabLabel(GtkWidget *searchPage,
1246 const char *title) {
1247 GtkWidget *hbox, *label_hbox, *label_ebox;
1248 GtkWidget *label, *dummy_label;
1249 GtkWidget *close_button;
1250 GtkRcStyle *rcstyle;
1251 GtkRequisition size;
1252 GtkWidget *image;
1253 char *short_title, *orig_title, *final_title;
1254 char *short_title_end, *tip_title;
1255 int short_title_len;
1256 static GtkTooltips *searchTabLabelTooltip = NULL;
1257 unsigned int *file_count;
1258 1057
1259 if(!searchTabLabelTooltip)
1260 searchTabLabelTooltip = gtk_tooltips_new();
1261
1262 hbox = gtk_hbox_new (FALSE, 2);
1263
1264 label_ebox = gtk_event_box_new ();
1265 gtk_event_box_set_visible_window (GTK_EVENT_BOX (label_ebox), FALSE);
1266 gtk_box_pack_start (GTK_BOX (hbox), label_ebox, TRUE, TRUE, 0);
1267
1268 label_hbox = gtk_hbox_new (FALSE, 2);
1269 gtk_container_add (GTK_CONTAINER (label_ebox), label_hbox);
1270
1271 /* setup close button */
1272 close_button = gtk_button_new ();
1273 gtk_button_set_relief (GTK_BUTTON (close_button),
1274 GTK_RELIEF_NONE);
1275 /* don't allow focus on the close button */
1276 gtk_button_set_focus_on_click (GTK_BUTTON (close_button), FALSE);
1277
1278 /* make it as small as possible */
1279 rcstyle = gtk_rc_style_new ();
1280 rcstyle->xthickness = rcstyle->ythickness = 0;
1281 gtk_widget_modify_style (close_button, rcstyle);
1282 gtk_rc_style_unref (rcstyle),
1283
1284 image = gtk_image_new_from_stock (GTK_STOCK_CLOSE,
1285 GTK_ICON_SIZE_MENU);
1286 gtk_widget_size_request (image, &size);
1287 gtk_widget_set_size_request (close_button, size.width, size.height);
1288 gtk_container_add (GTK_CONTAINER (close_button), image);
1289 gtk_box_pack_start (GTK_BOX (hbox), close_button, FALSE, FALSE, 0);
1290
1291 g_signal_connect_swapped(close_button,
1292 "clicked",
1293 G_CALLBACK (on_closeSearchButton_clicked_fs),
1294 searchPage);
1295
1296 /* truncate the description if needed */
1297 if(g_utf8_strlen(title, 16) > 15) {
1298 short_title_end = g_utf8_offset_to_pointer (title, 15);
1299 short_title_len = short_title_end - title;
1300 short_title = g_strndup(title, short_title_len);
1301 orig_title = g_strconcat(short_title, "...", NULL);
1302 FREE(short_title); }
1303 else {
1304 orig_title = STRDUP(title); }
1305
1306 /* setup label */
1307 final_title = g_strconcat(orig_title, " (0)", NULL);
1308 label = gtk_label_new (final_title);
1309 FREE(final_title);
1310
1311 gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
1312 gtk_misc_set_padding (GTK_MISC (label), 0, 0);
1313 gtk_box_pack_start (GTK_BOX (label_hbox), label, FALSE, FALSE, 0);
1314
1315 /* add a forced space before the button */
1316 dummy_label = gtk_label_new ("");
1317 gtk_box_pack_start (GTK_BOX (label_hbox), dummy_label, TRUE, TRUE, 0);
1318
1319 /* tooltips */
1320 gtk_tooltips_set_tip(searchTabLabelTooltip, close_button,
1321 _("Close this search"), NULL);
1322 tip_title = g_strconcat (_("Search: "), title, NULL);
1323 gtk_tooltips_set_tip(searchTabLabelTooltip, label_ebox,
1324 tip_title, NULL);
1325
1326 /* store some references to access count & title later */
1327 file_count = malloc(sizeof(unsigned int));
1328 *file_count = 0;
1329 g_object_set_data(G_OBJECT(searchPage),
1330 "file_count", (gpointer) file_count);
1331 g_object_set_data(G_OBJECT(searchPage),
1332 "label", (gpointer) label);
1333 g_object_set_data(G_OBJECT(searchPage),
1334 "title", (gpointer) orig_title);
1335
1336 gtk_widget_show (hbox);
1337 gtk_widget_show (label_ebox);
1338 gtk_widget_show (label_hbox);
1339 gtk_widget_show (label);
1340 gtk_widget_show (dummy_label);
1341 gtk_widget_show (image);
1342 gtk_widget_show (close_button);
1343
1344 return hbox;
1345}
1346 1058
1347/* end of search.c */ 1059/* end of search.c */