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.c151
1 files changed, 144 insertions, 7 deletions
diff --git a/src/plugins/fs/search.c b/src/plugins/fs/search.c
index 0c9ac717..7dba2ddc 100644
--- a/src/plugins/fs/search.c
+++ b/src/plugins/fs/search.c
@@ -410,8 +410,10 @@ void displaySearchResult(const ECRS_FileInfo * info,
410 GtkTreeRowReference * row) { 410 GtkTreeRowReference * row) {
411 SearchList * list; 411 SearchList * list;
412 struct ECRS_URI * euri; 412 struct ECRS_URI * euri;
413 unsigned int count; 413 unsigned int *file_count;
414 GtkTreeIter iter; 414 GtkTreeIter iter;
415 GtkWidget *tab_label;
416 char *tab_title, *new_title;
415 417
416 DEBUG_BEGIN(); 418 DEBUG_BEGIN();
417 list = head; 419 list = head;
@@ -427,6 +429,19 @@ void displaySearchResult(const ECRS_FileInfo * info,
427 list->treeview, 429 list->treeview,
428 row); 430 row);
429 431
432 /* update tab title with the number of results */
433 file_count = (unsigned int *)
434 g_object_get_data(G_OBJECT(list->searchpage), "file_count");
435 (*file_count)++;
436 tab_label = (GtkWidget *)
437 g_object_get_data(G_OBJECT(list->searchpage), "label");
438 tab_title = (char *)
439 g_object_get_data(G_OBJECT(list->searchpage), "title");
440 new_title =
441 g_strdup_printf("%s%s%u%s", tab_title, " (", *file_count, ")");
442 gtk_label_set(GTK_LABEL(tab_label), new_title);
443 FREE(new_title);
444
430 if (! gtk_tree_model_get_iter_first(GTK_TREE_MODEL(summary), 445 if (! gtk_tree_model_get_iter_first(GTK_TREE_MODEL(summary),
431 &iter)) { 446 &iter)) {
432 BREAK(); 447 BREAK();
@@ -436,15 +451,13 @@ void displaySearchResult(const ECRS_FileInfo * info,
436 do { 451 do {
437 gtk_tree_model_get(GTK_TREE_MODEL(summary), 452 gtk_tree_model_get(GTK_TREE_MODEL(summary),
438 &iter, 453 &iter,
439 SER_SUM_COUNT, &count,
440 SER_SUM_URI, &euri, 454 SER_SUM_URI, &euri,
441 -1); 455 -1);
442 if (ECRS_equalsUri(euri, 456 if (ECRS_equalsUri(euri,
443 uri)) { 457 uri)) {
444 count++;
445 gtk_list_store_set(GTK_LIST_STORE(summary), 458 gtk_list_store_set(GTK_LIST_STORE(summary),
446 &iter, 459 &iter,
447 SER_SUM_COUNT, count, 460 SER_SUM_COUNT, *file_count,
448 -1); 461 -1);
449 DEBUG_END(); 462 DEBUG_END();
450 return; 463 return;
@@ -885,7 +898,7 @@ void on_fssearchbutton_clicked(gpointer dummy2,
885 SER_SUM_URI, ECRS_dupUri(uri), 898 SER_SUM_URI, ECRS_dupUri(uri),
886 -1); 899 -1);
887 900
888 label = gtk_label_new(tabtxt); 901 label = buildSearchTabLabel(list->searchpage, tabtxt);
889 gtk_notebook_append_page(GTK_NOTEBOOK(notebook), 902 gtk_notebook_append_page(GTK_NOTEBOOK(notebook),
890 list->searchpage, 903 list->searchpage,
891 label); 904 label);
@@ -1023,6 +1036,9 @@ int openTabForSearch(void * unused,
1023 GtkTreeStore * model; 1036 GtkTreeStore * model;
1024 GtkTreeIter iter; 1037 GtkTreeIter iter;
1025 int i; 1038 int i;
1039 unsigned int *file_count;
1040 GtkWidget *tab_label;
1041 char *tab_title, *new_title;
1026 1042
1027 DEBUG_BEGIN(); 1043 DEBUG_BEGIN();
1028 description = ECRS_uriToString(uri); 1044 description = ECRS_uriToString(uri);
@@ -1040,7 +1056,6 @@ int openTabForSearch(void * unused,
1040 ECRS_SUBSPACE_INFIX, 1056 ECRS_SUBSPACE_INFIX,
1041 strlen(ECRS_SUBSPACE_INFIX))) 1057 strlen(ECRS_SUBSPACE_INFIX)))
1042 dhead = &dhead[strlen(ECRS_SUBSPACE_INFIX)]; 1058 dhead = &dhead[strlen(ECRS_SUBSPACE_INFIX)];
1043 label = gtk_label_new(dhead);
1044 1059
1045 gtk_list_store_append(summary, 1060 gtk_list_store_append(summary,
1046 &iter); 1061 &iter);
@@ -1051,7 +1066,6 @@ int openTabForSearch(void * unused,
1051 SER_SUM_URI, ECRS_dupUri(uri), 1066 SER_SUM_URI, ECRS_dupUri(uri),
1052 -1); 1067 -1);
1053 1068
1054 FREE(description);
1055 list = MALLOC(sizeof(SearchList)); 1069 list = MALLOC(sizeof(SearchList));
1056 list->uri = ECRS_dupUri(uri); 1070 list->uri = ECRS_dupUri(uri);
1057 list->next = head; 1071 list->next = head;
@@ -1068,6 +1082,8 @@ int openTabForSearch(void * unused,
1068 notebook 1082 notebook
1069 = glade_xml_get_widget(getMainXML(), 1083 = glade_xml_get_widget(getMainXML(),
1070 "downloadNotebook"); 1084 "downloadNotebook");
1085 label = buildSearchTabLabel(list->searchpage, dhead);
1086 FREE(description);
1071 gtk_notebook_append_page(GTK_NOTEBOOK(notebook), 1087 gtk_notebook_append_page(GTK_NOTEBOOK(notebook),
1072 list->searchpage, 1088 list->searchpage,
1073 label); 1089 label);
@@ -1078,6 +1094,20 @@ int openTabForSearch(void * unused,
1078 list->treeview, 1094 list->treeview,
1079 NULL); 1095 NULL);
1080 } 1096 }
1097
1098 /* update tab title with the number of results */
1099 file_count = (unsigned int *)
1100 g_object_get_data(G_OBJECT(list->searchpage), "file_count");
1101 (*file_count) = resultCount;
1102 tab_label = (GtkWidget *)
1103 g_object_get_data(G_OBJECT(list->searchpage), "label");
1104 tab_title = (char *)
1105 g_object_get_data(G_OBJECT(list->searchpage), "title");
1106 new_title =
1107 g_strdup_printf("%s%s%u%s", tab_title, " (", *file_count, ")");
1108 gtk_label_set(GTK_LABEL(tab_label), new_title);
1109 FREE(new_title);
1110
1081 DEBUG_END(); 1111 DEBUG_END();
1082 return OK; 1112 return OK;
1083} 1113}
@@ -1195,4 +1225,111 @@ void fs_search_stop() {
1195 } 1225 }
1196} 1226}
1197 1227
1228/* Create the tab label and icon,
1229 * adding a little button to close the search
1230 * This function is a modified version of an Epiphany/Gedit code,
1231 * part of this work is copyrighted (GPL license) by its authors.
1232 */
1233GtkWidget *buildSearchTabLabel (GtkWidget *searchPage, const char *title)
1234{
1235 GtkWidget *hbox, *label_hbox, *label_ebox;
1236 GtkWidget *label, *dummy_label;
1237 GtkWidget *close_button;
1238 GtkRcStyle *rcstyle;
1239 GtkRequisition size;
1240 GtkWidget *image;
1241 char *short_title, *orig_title, *final_title;
1242 char *short_title_end, *tip_title;
1243 int short_title_len;
1244 static GtkTooltips *searchTabLabelTooltip = NULL;
1245 unsigned int *file_count;
1246
1247 if(!searchTabLabelTooltip)
1248 searchTabLabelTooltip = gtk_tooltips_new();
1249
1250 hbox = gtk_hbox_new (FALSE, 2);
1251
1252 label_ebox = gtk_event_box_new ();
1253 gtk_event_box_set_visible_window (GTK_EVENT_BOX (label_ebox), FALSE);
1254 gtk_box_pack_start (GTK_BOX (hbox), label_ebox, TRUE, TRUE, 0);
1255
1256 label_hbox = gtk_hbox_new (FALSE, 2);
1257 gtk_container_add (GTK_CONTAINER (label_ebox), label_hbox);
1258
1259 /* setup close button */
1260 close_button = gtk_button_new ();
1261 gtk_button_set_relief (GTK_BUTTON (close_button),
1262 GTK_RELIEF_NONE);
1263 /* don't allow focus on the close button */
1264 gtk_button_set_focus_on_click (GTK_BUTTON (close_button), FALSE);
1265
1266 /* make it as small as possible */
1267 rcstyle = gtk_rc_style_new ();
1268 rcstyle->xthickness = rcstyle->ythickness = 0;
1269 gtk_widget_modify_style (close_button, rcstyle);
1270 gtk_rc_style_unref (rcstyle),
1271
1272 image = gtk_image_new_from_stock (GTK_STOCK_CLOSE,
1273 GTK_ICON_SIZE_MENU);
1274 gtk_widget_size_request (image, &size);
1275 gtk_widget_set_size_request (close_button, size.width, size.height);
1276 gtk_container_add (GTK_CONTAINER (close_button), image);
1277 gtk_box_pack_start (GTK_BOX (hbox), close_button, FALSE, FALSE, 0);
1278
1279 g_signal_connect_swapped(close_button,
1280 "clicked",
1281 G_CALLBACK (on_closeSearchButton_clicked),
1282 searchPage);
1283
1284 /* truncate the description if needed */
1285 if(g_utf8_strlen(title, 16) > 15) {
1286 short_title_end = g_utf8_offset_to_pointer (title, 15);
1287 short_title_len = short_title_end - title;
1288 short_title = g_strndup(title, short_title_len);
1289 orig_title = g_strconcat(short_title, "...", NULL);
1290 FREE(short_title); }
1291 else {
1292 orig_title = STRDUP(title); }
1293
1294 /* setup label */
1295 final_title = g_strconcat(orig_title, " (0)", NULL);
1296 label = gtk_label_new (final_title);
1297 FREE(final_title);
1298
1299 gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
1300 gtk_misc_set_padding (GTK_MISC (label), 0, 0);
1301 gtk_box_pack_start (GTK_BOX (label_hbox), label, FALSE, FALSE, 0);
1302
1303 /* add a forced space before the button */
1304 dummy_label = gtk_label_new ("");
1305 gtk_box_pack_start (GTK_BOX (label_hbox), dummy_label, TRUE, TRUE, 0);
1306
1307 /* tooltips */
1308 gtk_tooltips_set_tip(searchTabLabelTooltip, close_button,
1309 _("Close this search"), NULL);
1310 tip_title = g_strconcat (_("Search: "), title, NULL);
1311 gtk_tooltips_set_tip(searchTabLabelTooltip, label_ebox,
1312 tip_title, NULL);
1313
1314 /* store some references to access count & title later */
1315 file_count = malloc(sizeof(unsigned int));
1316 *file_count = 0;
1317 g_object_set_data(G_OBJECT(searchPage),
1318 "file_count", (gpointer) file_count);
1319 g_object_set_data(G_OBJECT(searchPage),
1320 "label", (gpointer) label);
1321 g_object_set_data(G_OBJECT(searchPage),
1322 "title", (gpointer) orig_title);
1323
1324 gtk_widget_show (hbox);
1325 gtk_widget_show (label_ebox);
1326 gtk_widget_show (label_hbox);
1327 gtk_widget_show (label);
1328 gtk_widget_show (dummy_label);
1329 gtk_widget_show (image);
1330 gtk_widget_show (close_button);
1331
1332 return hbox;
1333}
1334
1198/* end of search.c */ 1335/* end of search.c */