aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2006-10-24 23:12:03 +0000
committerChristian Grothoff <christian@grothoff.org>2006-10-24 23:12:03 +0000
commit80863de749268d6f5c54812708aa7a602ecdf042 (patch)
tree7d6eadf6fb072375012e5a80d60b5dc98b194112
parent6af3cb961a2e9ad2117170521b6b1ea5f42ece29 (diff)
downloadgnunet-gtk-80863de749268d6f5c54812708aa7a602ecdf042.tar.gz
gnunet-gtk-80863de749268d6f5c54812708aa7a602ecdf042.zip
ref
-rw-r--r--src/plugins/fs/Makefile.am1
-rw-r--r--src/plugins/fs/download.c6
-rw-r--r--src/plugins/fs/download.h17
-rw-r--r--src/plugins/fs/fs.h2
-rw-r--r--src/plugins/fs/helper.c113
-rw-r--r--src/plugins/fs/helper.h13
-rw-r--r--src/plugins/fs/namespace.c142
-rw-r--r--src/plugins/fs/search.c300
-rw-r--r--src/plugins/fs/search.h75
9 files changed, 321 insertions, 348 deletions
diff --git a/src/plugins/fs/Makefile.am b/src/plugins/fs/Makefile.am
index ee8a6b49..b70c3284 100644
--- a/src/plugins/fs/Makefile.am
+++ b/src/plugins/fs/Makefile.am
@@ -11,7 +11,6 @@ plugin_LTLIBRARIES = \
11 11
12libgnunetgtkmodule_fs_la_SOURCES = \ 12libgnunetgtkmodule_fs_la_SOURCES = \
13 collection.c collection.h \ 13 collection.c collection.h \
14 download.c download.h \
15 fs.c fs.h \ 14 fs.c fs.h \
16 helper.c helper.h \ 15 helper.c helper.h \
17 meta.c meta.h \ 16 meta.c meta.h \
diff --git a/src/plugins/fs/download.c b/src/plugins/fs/download.c
index dc7e2ae4..f1ba0589 100644
--- a/src/plugins/fs/download.c
+++ b/src/plugins/fs/download.c
@@ -195,12 +195,6 @@ static void initiateDownload(GtkTreeModel * model,
195 we'll just add it as a new tab for now */ 195 we'll just add it as a new tab for now */
196 run_with_save_calls(&startSearch, 196 run_with_save_calls(&startSearch,
197 &idc); 197 &idc);
198 if (idc.ret != NULL)
199 openTabForSearch(idc.ret,
200 idc.uri,
201 idc.anon,
202 0,
203 NULL);
204 return; 198 return;
205 } else { 199 } else {
206 GE_BREAK(ectx, 0); /* unsupported URI type (i.e. ksk or loc) */ 200 GE_BREAK(ectx, 0); /* unsupported URI type (i.e. ksk or loc) */
diff --git a/src/plugins/fs/download.h b/src/plugins/fs/download.h
index 3f194c57..d6f42386 100644
--- a/src/plugins/fs/download.h
+++ b/src/plugins/fs/download.h
@@ -29,21 +29,4 @@
29 29
30#include <GNUnet/gnunet_ecrs_lib.h> 30#include <GNUnet/gnunet_ecrs_lib.h>
31 31
32/**
33 */
34void displayDownloadUpdate(const struct ECRS_URI * uri,
35 unsigned long long completed,
36 const char * data,
37 unsigned int size);
38
39/**
40 */
41void displayDownloadComplete(const struct ECRS_URI * uri,
42 const char * filename);
43
44void fs_download_start(struct GE_Context * e,
45 struct GC_Configuration * c);
46
47void fs_download_stop(void);
48
49#endif 32#endif
diff --git a/src/plugins/fs/fs.h b/src/plugins/fs/fs.h
index 0494a17c..6ff4b5b3 100644
--- a/src/plugins/fs/fs.h
+++ b/src/plugins/fs/fs.h
@@ -47,6 +47,7 @@ enum {
47 NS_SEARCH_DESCRIPTION = 0, 47 NS_SEARCH_DESCRIPTION = 0,
48 NS_SEARCH_ENCNAME, 48 NS_SEARCH_ENCNAME,
49 NS_SEARCH_METADATA, 49 NS_SEARCH_METADATA,
50 NS_SEARCH_FSUI,
50 NS_SEARCH_RATING, 51 NS_SEARCH_RATING,
51 NS_SEARCH_NUM, 52 NS_SEARCH_NUM,
52}; 53};
@@ -55,6 +56,7 @@ enum {
55 SER_SUM_NAME = 0, 56 SER_SUM_NAME = 0,
56 SER_SUM_COUNT, 57 SER_SUM_COUNT,
57 SER_SUM_URI, 58 SER_SUM_URI,
59 SER_SUM_FSUI,
58 SER_SUM_NUM 60 SER_SUM_NUM
59}; 61};
60 62
diff --git a/src/plugins/fs/helper.c b/src/plugins/fs/helper.c
index 60f4af9c..9f6eaed9 100644
--- a/src/plugins/fs/helper.c
+++ b/src/plugins/fs/helper.c
@@ -92,3 +92,116 @@ int parseTime(const char * t,
92 return OK; 92 return OK;
93} 93}
94 94
95/**
96 * FIXME: convert this into a glade widget!
97 */
98GtkWidget *
99buildSearchTabLabel(GtkWidget *searchPage,
100 const char *title) {
101 GtkWidget *hbox;
102 GtkWidget *label_hbox;
103 GtkWidget *label_ebox;
104 GtkWidget *label;
105 GtkWidget *dummy_label;
106 GtkWidget *close_button;
107 GtkRcStyle *rcstyle;
108 GtkRequisition size;
109 GtkWidget *image;
110 char *short_title;
111 char *orig_title;
112 char *final_title;
113 char *short_title_end;
114 char *tip_title;
115 int short_title_len;
116 static GtkTooltips *searchTabLabelTooltip = NULL;
117 unsigned int *file_count;
118
119 if(!searchTabLabelTooltip)
120 searchTabLabelTooltip = gtk_tooltips_new();
121
122 hbox = gtk_hbox_new (FALSE, 2);
123
124 label_ebox = gtk_event_box_new ();
125 gtk_event_box_set_visible_window (GTK_EVENT_BOX (label_ebox), FALSE);
126 gtk_box_pack_start (GTK_BOX (hbox), label_ebox, TRUE, TRUE, 0);
127
128 label_hbox = gtk_hbox_new (FALSE, 2);
129 gtk_container_add (GTK_CONTAINER (label_ebox), label_hbox);
130
131 /* setup close button */
132 close_button = gtk_button_new ();
133 gtk_button_set_relief (GTK_BUTTON (close_button),
134 GTK_RELIEF_NONE);
135 /* don't allow focus on the close button */
136 gtk_button_set_focus_on_click (GTK_BUTTON (close_button), FALSE);
137
138 /* make it as small as possible */
139 rcstyle = gtk_rc_style_new ();
140 rcstyle->xthickness = 0;
141 rcstyle->ythickness = 0;
142 gtk_widget_modify_style (close_button, rcstyle);
143 gtk_rc_style_unref (rcstyle),
144
145 image = gtk_image_new_from_stock (GTK_STOCK_CLOSE,
146 GTK_ICON_SIZE_MENU);
147 gtk_widget_size_request (image, &size);
148 gtk_widget_set_size_request (close_button, size.width, size.height);
149 gtk_container_add (GTK_CONTAINER (close_button), image);
150 gtk_box_pack_start (GTK_BOX (hbox), close_button, FALSE, FALSE, 0);
151
152 g_signal_connect_swapped(close_button,
153 "clicked",
154 G_CALLBACK (on_closeSearchButton_clicked_fs),
155 searchPage);
156
157 /* truncate the description if needed */
158 if(g_utf8_strlen(title, 16) > 15) {
159 short_title_end = g_utf8_offset_to_pointer (title, 15);
160 short_title_len = short_title_end - title;
161 short_title = g_strndup(title, short_title_len);
162 orig_title = g_strconcat(short_title, "...", NULL);
163 FREE(short_title);
164 } else {
165 orig_title = STRDUP(title);
166 }
167
168 /* setup label */
169 final_title = g_strconcat(orig_title, " (0)", NULL);
170 label = gtk_label_new (final_title);
171 FREE(final_title);
172
173 gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
174 gtk_misc_set_padding (GTK_MISC (label), 0, 0);
175 gtk_box_pack_start (GTK_BOX (label_hbox), label, FALSE, FALSE, 0);
176
177 /* add a forced space before the button */
178 dummy_label = gtk_label_new ("");
179 gtk_box_pack_start (GTK_BOX (label_hbox), dummy_label, TRUE, TRUE, 0);
180
181 /* tooltips */
182 gtk_tooltips_set_tip(searchTabLabelTooltip, close_button,
183 _("Close this search"), NULL);
184 tip_title = g_strconcat (_("Search: "), title, NULL);
185 gtk_tooltips_set_tip(searchTabLabelTooltip, label_ebox,
186 tip_title, NULL);
187
188 /* store some references to access count & title later */
189 file_count = malloc(sizeof(unsigned int));
190 *file_count = 0;
191 g_object_set_data(G_OBJECT(searchPage),
192 "file_count", (gpointer) file_count);
193 g_object_set_data(G_OBJECT(searchPage),
194 "label", (gpointer) label);
195 g_object_set_data(G_OBJECT(searchPage),
196 "title", (gpointer) orig_title);
197
198 gtk_widget_show (hbox);
199 gtk_widget_show (label_ebox);
200 gtk_widget_show (label_hbox);
201 gtk_widget_show (label);
202 gtk_widget_show (dummy_label);
203 gtk_widget_show (image);
204 gtk_widget_show (close_button);
205
206 return hbox;
207}
diff --git a/src/plugins/fs/helper.h b/src/plugins/fs/helper.h
index 72938fc3..73e40485 100644
--- a/src/plugins/fs/helper.h
+++ b/src/plugins/fs/helper.h
@@ -27,6 +27,19 @@
27 * @author Christian Grothoff 27 * @author Christian Grothoff
28 */ 28 */
29 29
30/* Create the tab label and icon,
31 * adding a little button to close the search
32 * This function is a modified version of an Epiphany/Gedit code,
33 * part of this work is copyrighted (GPL license) by its authors.
34 *
35 * @param the title of the new label
36 * @returns the created widget to pack into the page header
37 */
38GtkWidget *
39buildSearchTabLabel (GtkWidget *searchPage,
40 const char *title);
41
42
30/** 43/**
31 * Parse a time given in the form 44 * Parse a time given in the form
32 * "XX seconds yy days zz months". 45 * "XX seconds yy days zz months".
diff --git a/src/plugins/fs/namespace.c b/src/plugins/fs/namespace.c
index 3cbdd65d..f812488e 100644
--- a/src/plugins/fs/namespace.c
+++ b/src/plugins/fs/namespace.c
@@ -1208,6 +1208,148 @@ void on_trackingCheckButton_toggled_fs(GtkWidget * dummy1,
1208 YES : NO); 1208 YES : NO);
1209} 1209}
1210 1210
1211/**
1212 * The spin button giving the rating for a particular namespace
1213 * has been changed. Store the new rating for the namespace.
1214 */
1215void on_namespaceRatingSpinButton_changed_fs(GtkWidget * dummy,
1216 GtkWidget * dummy2) {
1217 GtkWidget * spin;
1218 GtkWidget * ncbe;
1219 GtkTreeModel * model;
1220 GtkTreeIter iter;
1221 char * encStr;
1222 char * description;
1223 int rating;
1224 int newrating;
1225
1226 DEBUG_BEGIN();
1227 spin
1228 = glade_xml_get_widget(getMainXML(),
1229 "namespaceRatingSpinButton");
1230 ncbe
1231 = glade_xml_get_widget(getMainXML(),
1232 "searchNamespaceComboBoxEntry");
1233 model = gtk_combo_box_get_model(GTK_COMBO_BOX(ncbe));
1234 if (TRUE == gtk_combo_box_get_active_iter(GTK_COMBO_BOX(ncbe),
1235 &iter)) {
1236 gtk_tree_model_get(model,
1237 &iter,
1238 NS_SEARCH_DESCRIPTION, &description,
1239 NS_SEARCH_ENCNAME, &encStr,
1240 NS_SEARCH_RATING, &rating,
1241 -1);
1242 if ( (description != NULL) &&
1243 (0 == strcmp(description,
1244 _("globally"))) ) {
1245 /* just to be sure */
1246 gtk_widget_set_sensitive(spin,
1247 FALSE);
1248 } else {
1249 if (encStr != NULL) {
1250 newrating = gtk_spin_button_get_value(GTK_SPIN_BUTTON(spin));
1251 rating = NS_rankNamespace(ectx,
1252 cfg,
1253 encStr,
1254 newrating - rating);
1255 if (rating != newrating) {
1256 /* concurrent modification? */
1257 gtk_spin_button_set_value(GTK_SPIN_BUTTON(spin),
1258 rating);
1259 GE_BREAK(ectx, 0);
1260 }
1261 gtk_list_store_set(GTK_LIST_STORE(model),
1262 &iter,
1263 NS_SEARCH_RATING, rating,
1264 -1);
1265 }
1266 }
1267 } else {
1268 /* FIXME: if enc2hash succeeds, we may want to keep this
1269 active */
1270 gtk_spin_button_set_value(GTK_SPIN_BUTTON(spin),
1271 0);
1272 gtk_widget_set_sensitive(spin,
1273 FALSE);
1274 }
1275 DEBUG_END();
1276}
1277
1278
1279/**
1280 * The namespace in the search window has changed.
1281 * Update the trust level (possibly changing sensitivity)
1282 * and set the search string to the root (if available).
1283 */
1284void on_searchNamespaceComboBoxEntry_changed_fs(GtkWidget * dummy,
1285 GtkWidget * dummy2) {
1286 GtkWidget * keyword;
1287 GtkWidget * spin;
1288 GtkWidget * ncbe;
1289 GtkTreeModel * model;
1290 GtkTreeIter iter;
1291 int rating;
1292 char * encStr;
1293 char * descStr;
1294 HashCode512 ns;
1295 HashCode512 root;
1296 EncName enc;
1297
1298 DEBUG_BEGIN();
1299 spin
1300 = glade_xml_get_widget(getMainXML(),
1301 "namespaceRatingSpinButton");
1302 ncbe
1303 = glade_xml_get_widget(getMainXML(),
1304 "searchNamespaceComboBoxEntry");
1305 model = gtk_combo_box_get_model(GTK_COMBO_BOX(ncbe));
1306 if (TRUE == gtk_combo_box_get_active_iter(GTK_COMBO_BOX(ncbe),
1307 &iter)) {
1308 encStr = NULL;
1309 descStr = NULL;
1310 gtk_tree_model_get(model,
1311 &iter,
1312 NS_SEARCH_DESCRIPTION, &descStr,
1313 NS_SEARCH_ENCNAME, &encStr,
1314 NS_SEARCH_RATING, &rating,
1315 -1);
1316 if ( (descStr != NULL) &&
1317 (0 == strcmp(descStr,
1318 _("globally"))) ) {
1319 gtk_spin_button_set_value(GTK_SPIN_BUTTON(spin),
1320 0);
1321 gtk_widget_set_sensitive(spin,
1322 FALSE);
1323 } else if (encStr != NULL) {
1324 enc2hash(encStr,
1325 &ns);
1326 gtk_spin_button_set_value(GTK_SPIN_BUTTON(spin),
1327 rating);
1328 gtk_widget_set_sensitive(spin,
1329 TRUE);
1330 if (OK == NS_getNamespaceRoot(ectx,
1331 cfg,
1332 encStr,
1333 &root)) {
1334 hash2enc(&root,
1335 &enc);
1336 keyword
1337 = glade_xml_get_widget(getMainXML(),
1338 "fssearchKeywordComboBoxEntry");
1339 gtk_entry_set_text(GTK_ENTRY(gtk_bin_get_child(GTK_BIN(keyword))),
1340 (const gchar*) &enc);
1341 }
1342 }
1343 } else {
1344 gtk_spin_button_set_value(GTK_SPIN_BUTTON(spin),
1345 0);
1346 gtk_widget_set_sensitive(spin,
1347 FALSE);
1348 }
1349 DEBUG_END();
1350}
1351
1352
1211 1353
1212void fs_namespace_start(struct GE_Context * e, 1354void fs_namespace_start(struct GE_Context * e,
1213 struct GC_Configuration * c) { 1355 struct GC_Configuration * c) {
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 */
diff --git a/src/plugins/fs/search.h b/src/plugins/fs/search.h
index 089074c3..ac0df7ee 100644
--- a/src/plugins/fs/search.h
+++ b/src/plugins/fs/search.h
@@ -30,18 +30,25 @@
30#include <GNUnet/gnunet_ecrs_lib.h> 30#include <GNUnet/gnunet_ecrs_lib.h>
31#include <GNUnet/gnunet_fsui_lib.h> 31#include <GNUnet/gnunet_fsui_lib.h>
32 32
33/** 33void * fs_download_started(void * downloadContext,
34 * Add an entry to the search tree. 34 unsigned long long total,
35 * 35 unsigned int anonymityLevel,
36 * @param model the search model 36 const struct ECRS_URI * uri,
37 * @param pos the position to add the entry 37 const char * filename,
38 * @param uri the URI to add 38 unsigned long long completed,
39 * @param meta metadata describing the URI 39 cron_t eta);
40 */ 40
41void addEntryToSearchTree(GtkTreeStore * model, 41void fs_download_update(void * downloadContext,
42 GtkTreeIter * pos, 42 unsigned long long completed,
43 const struct ECRS_URI * uri, 43 const char * data,
44 const struct ECRS_MetaData * meta); 44 unsigned int size);
45
46void fs_download_completed(void * downloadContext);
47
48void fs_download_aborted(void * downloadContext);
49
50void fs_download_stopped(void * downloadContext);
51
45 52
46/** 53/**
47 * Add the given result to the model (search result 54 * Add the given result to the model (search result
@@ -51,34 +58,42 @@ void addEntryToSearchTree(GtkTreeStore * model,
51 * @param path the tree path that selects where to add 58 * @param path the tree path that selects where to add
52 * the information, NULL for top-level 59 * the information, NULL for top-level
53 */ 60 */
54void displaySearchResult(const ECRS_FileInfo * info, 61void fs_search_result_received(void * searchContext,
62 const ECRS_FileInfo * info,
63 const struct ECRS_URI * uri);
64
65/**
66 * A search has been started. Open tab.
67 *
68 * @return internal search context
69 */
70void * fs_search_started(struct FSUI_SearchList * list,
55 const struct ECRS_URI * uri, 71 const struct ECRS_URI * uri,
56 GtkTreeRowReference * row); 72 unsigned int anonymityLevel,
73 unsigned int resultCount,
74 const ECRS_FileInfo * results);
57 75
58/** 76/**
59 * Helper for download. 77 * A search process has been aborted. Update display.
60 */ 78 */
61GtkWidget * getAnonymityButtonFromTM(GtkTreeModel * model); 79void fs_search_aborted(void * searchContext);
62 80
63int openTabForSearch(struct FSUI_SearchList * list, 81/**
64 const struct ECRS_URI * uri, 82 * A search process has stopped. Clean up.
65 unsigned int anonymityLevel, 83 */
66 unsigned int resultCount, 84void fs_search_stopped(void * searchContext);
67 const ECRS_FileInfo * results);
68 85
86
87/**
88 * Initialize the search module.
89 */
69void fs_search_start(struct GE_Context * e, 90void fs_search_start(struct GE_Context * e,
70 struct GC_Configuration * c); 91 struct GC_Configuration * c);
71 92
93/**
94 * Shutdown the search module.
95 */
72void fs_search_stop(void); 96void fs_search_stop(void);
73 97
74/* Create the tab label and icon,
75 * adding a little button to close the search
76 * This function is a modified version of an Epiphany/Gedit code,
77 * part of this work is copyrighted (GPL license) by its authors.
78 *
79 * @param the title of the new label
80 * @returns the created widget to pack into the page header
81 */
82GtkWidget *buildSearchTabLabel (GtkWidget *searchPage, const char *title);
83 98
84#endif 99#endif