diff options
Diffstat (limited to 'src/plugins/fs/upload.c')
-rw-r--r-- | src/plugins/fs/upload.c | 752 |
1 files changed, 0 insertions, 752 deletions
diff --git a/src/plugins/fs/upload.c b/src/plugins/fs/upload.c deleted file mode 100644 index 82a8ca0c..00000000 --- a/src/plugins/fs/upload.c +++ /dev/null | |||
@@ -1,752 +0,0 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | (C) 2005, 2006, 2008 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/upload.c | ||
23 | * @brief code for uploading with gnunet-gtk | ||
24 | * @author Christian Grothoff | ||
25 | */ | ||
26 | |||
27 | #include "platform.h" | ||
28 | #include "gnunetgtk_common.h" | ||
29 | #include "search.h" | ||
30 | #include "upload.h" | ||
31 | #include "fs.h" | ||
32 | #include "meta.h" | ||
33 | #include <extractor.h> | ||
34 | |||
35 | #ifdef MINGW | ||
36 | #include <shlobj.h> | ||
37 | #ifndef BIF_NONEWFOLDERBUTTON | ||
38 | #define BIF_NONEWFOLDERBUTTON 0x200 | ||
39 | #endif | ||
40 | #endif | ||
41 | |||
42 | /** | ||
43 | * XML tree for the meta-data dialog of upload. | ||
44 | * (there can only be one at a time; | ||
45 | * maybe NULL at times where there is no dialog) | ||
46 | */ | ||
47 | static GladeXML *metaXML; | ||
48 | |||
49 | /* ************ FSUI event handlers ************ */ | ||
50 | |||
51 | void | ||
52 | fs_upload_update (UploadList * list, unsigned long long completed, | ||
53 | unsigned long long total) | ||
54 | { | ||
55 | GtkTreeIter iter; | ||
56 | GtkTreePath *path; | ||
57 | int progress; | ||
58 | |||
59 | list->total = total; | ||
60 | if (list->total != 0) | ||
61 | progress = 100 * completed / list->total; | ||
62 | else | ||
63 | progress = 100; | ||
64 | path = gtk_tree_row_reference_get_path (list->summaryViewRowReference); | ||
65 | gtk_tree_model_get_iter (GTK_TREE_MODEL (upload_summary), &iter, path); | ||
66 | gtk_tree_path_free (path); | ||
67 | gtk_tree_store_set (upload_summary, &iter, UPLOAD_PROGRESS, progress, -1); | ||
68 | } | ||
69 | |||
70 | void | ||
71 | fs_upload_complete (UploadList * list, struct GNUNET_ECRS_URI *uri) | ||
72 | { | ||
73 | GtkTreeIter iter; | ||
74 | GtkTreePath *path; | ||
75 | char *us; | ||
76 | |||
77 | list->has_terminated = GNUNET_YES; | ||
78 | list->uri = GNUNET_ECRS_uri_duplicate (uri); | ||
79 | us = GNUNET_ECRS_uri_to_string (uri); | ||
80 | path = gtk_tree_row_reference_get_path (list->summaryViewRowReference); | ||
81 | gtk_tree_model_get_iter (GTK_TREE_MODEL (upload_summary), &iter, path); | ||
82 | gtk_tree_path_free (path); | ||
83 | gtk_tree_store_set (upload_summary, &iter, | ||
84 | UPLOAD_URISTRING, us, UPLOAD_PROGRESS, 100, -1); | ||
85 | GNUNET_free (us); | ||
86 | } | ||
87 | |||
88 | void | ||
89 | fs_upload_aborted (UploadList * list) | ||
90 | { | ||
91 | GtkTreeIter iter; | ||
92 | GtkTreePath *path; | ||
93 | |||
94 | list->has_terminated = GNUNET_YES; | ||
95 | list->uri = NULL; | ||
96 | path = gtk_tree_row_reference_get_path (list->summaryViewRowReference); | ||
97 | gtk_tree_model_get_iter (GTK_TREE_MODEL (upload_summary), &iter, path); | ||
98 | gtk_tree_path_free (path); | ||
99 | gtk_tree_store_set (upload_summary, &iter, | ||
100 | UPLOAD_URISTRING, _("Aborted."), | ||
101 | UPLOAD_PROGRESS, 0, -1); | ||
102 | } | ||
103 | |||
104 | void | ||
105 | fs_upload_error (UploadList * list, const char *emsg) | ||
106 | { | ||
107 | GtkTreeIter iter; | ||
108 | GtkTreePath *path; | ||
109 | char *us; | ||
110 | size_t len; | ||
111 | |||
112 | list->has_terminated = GNUNET_YES; | ||
113 | list->uri = NULL; | ||
114 | len = strlen (_("Error uploading file: `%s'")) + strlen (emsg) + 2; | ||
115 | us = GNUNET_malloc (len); | ||
116 | GNUNET_snprintf (us, len, _("Error uploading file: `%s'"), emsg); | ||
117 | path = gtk_tree_row_reference_get_path (list->summaryViewRowReference); | ||
118 | gtk_tree_model_get_iter (GTK_TREE_MODEL (upload_summary), &iter, path); | ||
119 | gtk_tree_path_free (path); | ||
120 | gtk_tree_store_set (upload_summary, &iter, | ||
121 | UPLOAD_URISTRING, us, UPLOAD_PROGRESS, 0, -1); | ||
122 | GNUNET_free (us); | ||
123 | } | ||
124 | |||
125 | void | ||
126 | fs_upload_stopped (UploadList * list) | ||
127 | { | ||
128 | GtkTreeIter iter; | ||
129 | GtkTreePath *path; | ||
130 | UploadList *prev; | ||
131 | |||
132 | path = gtk_tree_row_reference_get_path (list->summaryViewRowReference); | ||
133 | gtk_tree_model_get_iter (GTK_TREE_MODEL (upload_summary), &iter, path); | ||
134 | gtk_tree_path_free (path); | ||
135 | gtk_tree_row_reference_free (list->summaryViewRowReference); | ||
136 | list->summaryViewRowReference = NULL; | ||
137 | gtk_tree_store_remove (upload_summary, &iter); | ||
138 | GNUNET_free (list->filename); | ||
139 | if (list->uri != NULL) | ||
140 | { | ||
141 | GNUNET_ECRS_uri_destroy (list->uri); | ||
142 | list->uri = NULL; | ||
143 | } | ||
144 | if (upload_head == list) | ||
145 | upload_head = list->next; | ||
146 | else | ||
147 | { | ||
148 | prev = upload_head; | ||
149 | while ((prev != NULL) && (prev->next != list)) | ||
150 | prev = prev->next; | ||
151 | if (prev != NULL) | ||
152 | prev->next = list->next; | ||
153 | else | ||
154 | GNUNET_GE_BREAK (ectx, 0); | ||
155 | } | ||
156 | GNUNET_free (list); | ||
157 | } | ||
158 | |||
159 | UploadList * | ||
160 | fs_upload_started (struct GNUNET_FSUI_UploadList *fsui, | ||
161 | UploadList * parent, | ||
162 | const char *filename, | ||
163 | const struct GNUNET_ECRS_URI *uri, | ||
164 | unsigned long long total, | ||
165 | unsigned long long completed, GNUNET_FSUI_State state) | ||
166 | { | ||
167 | UploadList *ret; | ||
168 | GtkTreeIter iter; | ||
169 | GtkTreePath *path; | ||
170 | int progress; | ||
171 | GtkTreeIter par; | ||
172 | char *u; | ||
173 | |||
174 | ret = GNUNET_malloc (sizeof (UploadList)); | ||
175 | memset (ret, 0, sizeof (UploadList)); | ||
176 | ret->filename = GNUNET_strdup (filename); | ||
177 | ret->fsui_list = fsui; | ||
178 | ret->total = total; | ||
179 | ret->is_top = parent == NULL; | ||
180 | if ((parent != NULL) && | ||
181 | (NULL != | ||
182 | (path = | ||
183 | gtk_tree_row_reference_get_path (parent->summaryViewRowReference)))) | ||
184 | { | ||
185 | gtk_tree_model_get_iter (GTK_TREE_MODEL (upload_summary), &par, path); | ||
186 | gtk_tree_path_free (path); | ||
187 | gtk_tree_store_append (upload_summary, &iter, &par); | ||
188 | } | ||
189 | else | ||
190 | { | ||
191 | gtk_tree_store_append (upload_summary, &iter, NULL); | ||
192 | } | ||
193 | if ((total != 0) && (state != GNUNET_FSUI_COMPLETED_JOINED)) | ||
194 | progress = 100 * completed / total; | ||
195 | else | ||
196 | progress = 100; | ||
197 | if (uri != NULL) | ||
198 | u = GNUNET_ECRS_uri_to_string (uri); | ||
199 | else | ||
200 | u = GNUNET_strdup (""); | ||
201 | gtk_tree_store_set (upload_summary, &iter, UPLOAD_FILENAME, filename, | ||
202 | UPLOAD_PROGRESS, progress, UPLOAD_URISTRING, u, | ||
203 | UPLOAD_INTERNAL, ret, -1); | ||
204 | GNUNET_free (u); | ||
205 | path = gtk_tree_model_get_path (GTK_TREE_MODEL (upload_summary), &iter); | ||
206 | ret->summaryViewRowReference | ||
207 | = gtk_tree_row_reference_new (GTK_TREE_MODEL (upload_summary), path); | ||
208 | gtk_tree_path_free (path); | ||
209 | ret->has_terminated = ((state != GNUNET_FSUI_ACTIVE) | ||
210 | && (state != GNUNET_FSUI_PENDING)); | ||
211 | |||
212 | ret->next = upload_head; | ||
213 | upload_head = ret; | ||
214 | return ret; | ||
215 | } | ||
216 | |||
217 | /* *************** user upload event handling ************** */ | ||
218 | |||
219 | |||
220 | void | ||
221 | on_selectAlternativePreviewButton_selection_changed_fs (GtkWidget * preview, | ||
222 | GtkWidget * | ||
223 | fileChooser) | ||
224 | { | ||
225 | char *fn; | ||
226 | |||
227 | fn = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (fileChooser)); | ||
228 | if (fn == NULL) | ||
229 | { | ||
230 | gtk_image_set_from_pixbuf (GTK_IMAGE (preview), NULL); | ||
231 | } | ||
232 | else | ||
233 | { | ||
234 | GdkPixbuf *buf; | ||
235 | |||
236 | buf = gdk_pixbuf_new_from_file (fn, NULL); | ||
237 | gtk_image_set_from_pixbuf (GTK_IMAGE (preview), buf); | ||
238 | g_object_unref (buf); | ||
239 | free (fn); | ||
240 | } | ||
241 | } | ||
242 | |||
243 | void | ||
244 | on_metaDataDialogKeywordAddButton_clicked_fs (gpointer dummy, | ||
245 | GtkWidget * button) | ||
246 | { | ||
247 | handleKeywordListUpdate (metaXML, | ||
248 | "fileInformationKeywordEntry", | ||
249 | "metaDataDialogKeywordList"); | ||
250 | } | ||
251 | |||
252 | void | ||
253 | on_metaDataDialogMetaDataAddButton_clicked_fs (gpointer dummy, | ||
254 | GtkWidget * button) | ||
255 | { | ||
256 | handleMetaDataListUpdate (metaXML, | ||
257 | "metaDataDialogMetaTypeComboBox", | ||
258 | "metaDataDialogValueEntry", | ||
259 | "metaDataDialogMetaDataList"); | ||
260 | } | ||
261 | |||
262 | void | ||
263 | on_fileInformationKeywordEntry_activate_fs (GtkWidget * | ||
264 | fileInformationKeywordEntry, | ||
265 | gpointer dummy) | ||
266 | { | ||
267 | const char *input; | ||
268 | |||
269 | input = gtk_entry_get_text (GTK_ENTRY (fileInformationKeywordEntry)); | ||
270 | if ((input == NULL) || (strlen (input) == 0)) | ||
271 | return; | ||
272 | handleKeywordListUpdate (metaXML, | ||
273 | "fileInformationKeywordEntry", | ||
274 | "metaDataDialogKeywordList"); | ||
275 | } | ||
276 | |||
277 | void | ||
278 | on_metaDataDialogValueEntry_activate_fs (GtkWidget * metaDataDialogValueEntry, | ||
279 | gpointer dummy) | ||
280 | { | ||
281 | const char *input; | ||
282 | |||
283 | input = gtk_entry_get_text (GTK_ENTRY (metaDataDialogValueEntry)); | ||
284 | if ((input == NULL) || (strlen (input) == 0)) | ||
285 | return; | ||
286 | handleMetaDataListUpdate (metaXML, | ||
287 | "metaDataDialogMetaTypeComboBox", | ||
288 | "metaDataDialogValueEntry", | ||
289 | "metaDataDialogMetaDataList"); | ||
290 | } | ||
291 | |||
292 | |||
293 | void | ||
294 | on_metaDataDialogKeywordRemoveButton_clicked_fs (gpointer dummy, | ||
295 | GtkWidget * button) | ||
296 | { | ||
297 | handleListRemove (metaXML, "metaDataDialogKeywordList"); | ||
298 | } | ||
299 | |||
300 | void | ||
301 | on_metaDataDialogMetaDataRemoveButton_clicked_fs (gpointer dummy, | ||
302 | GtkWidget * button) | ||
303 | { | ||
304 | handleListRemove (metaXML, "metaDataDialogMetaDataList"); | ||
305 | } | ||
306 | |||
307 | /** | ||
308 | * The selection of the keyword list changed. | ||
309 | * Update button status. | ||
310 | */ | ||
311 | void | ||
312 | on_keyword_list_selection_changed (gpointer signal, gpointer cls) | ||
313 | { | ||
314 | GtkTreeSelection *selection; | ||
315 | GtkWidget *button; | ||
316 | |||
317 | selection = | ||
318 | gtk_tree_view_get_selection (GTK_TREE_VIEW | ||
319 | (glade_xml_get_widget | ||
320 | (metaXML, "metaDataDialogKeywordList"))); | ||
321 | button = | ||
322 | glade_xml_get_widget (metaXML, "metaDataDialogKeywordRemoveButton"); | ||
323 | gtk_widget_set_sensitive (button, | ||
324 | gtk_tree_selection_count_selected_rows (selection) | ||
325 | > 0); | ||
326 | } | ||
327 | |||
328 | /** | ||
329 | * The selection of the metadata list changed. | ||
330 | * Update button status. | ||
331 | */ | ||
332 | void | ||
333 | on_metadata_list_selection_changed (gpointer signal, gpointer cls) | ||
334 | { | ||
335 | GtkTreeSelection *selection; | ||
336 | GtkWidget *button; | ||
337 | |||
338 | selection = | ||
339 | gtk_tree_view_get_selection (GTK_TREE_VIEW | ||
340 | (glade_xml_get_widget | ||
341 | (metaXML, "metaDataDialogMetaDataList"))); | ||
342 | button = | ||
343 | glade_xml_get_widget (metaXML, "metaDataDialogMetaDataRemoveButton"); | ||
344 | gtk_widget_set_sensitive (button, | ||
345 | gtk_tree_selection_count_selected_rows (selection) | ||
346 | > 0); | ||
347 | } | ||
348 | |||
349 | /** | ||
350 | * The user has edited the metadata entry. | ||
351 | * Update add button status. | ||
352 | */ | ||
353 | void | ||
354 | on_metaDataDialogValueEntry_changed_fs (gpointer dummy2, | ||
355 | GtkWidget * searchEntry) | ||
356 | { | ||
357 | const char *input; | ||
358 | GtkWidget *button; | ||
359 | |||
360 | input = gtk_entry_get_text (GTK_ENTRY (glade_xml_get_widget (metaXML, | ||
361 | "metaDataDialogValueEntry"))); | ||
362 | if (input == NULL) | ||
363 | return; | ||
364 | button = glade_xml_get_widget (metaXML, "metaDataDialogMetaDataAddButton"); | ||
365 | gtk_widget_set_sensitive (button, strlen (input) > 0); | ||
366 | } | ||
367 | |||
368 | /** | ||
369 | * The user has edited the keyword entry. | ||
370 | * Update add button status. | ||
371 | */ | ||
372 | void | ||
373 | on_fileInformationKeywordEntry_changed_fs (gpointer dummy2, | ||
374 | GtkWidget * searchEntry) | ||
375 | { | ||
376 | const char *input; | ||
377 | GtkWidget *button; | ||
378 | |||
379 | input = gtk_entry_get_text (GTK_ENTRY (glade_xml_get_widget (metaXML, | ||
380 | "fileInformationKeywordEntry"))); | ||
381 | if (input == NULL) | ||
382 | return; | ||
383 | button = glade_xml_get_widget (metaXML, "metaDataDialogKeywordAddButton"); | ||
384 | gtk_widget_set_sensitive (button, strlen (input) > 0); | ||
385 | } | ||
386 | |||
387 | typedef struct | ||
388 | { | ||
389 | char *filename; | ||
390 | unsigned int anonymity; | ||
391 | unsigned int priority; | ||
392 | int index; | ||
393 | int extract; | ||
394 | int deep_index; | ||
395 | GNUNET_CronTime expire; | ||
396 | struct GNUNET_MetaData *meta; | ||
397 | struct GNUNET_ECRS_URI *gkeywordURI; | ||
398 | struct GNUNET_ECRS_URI *keywordURI; | ||
399 | } FSUC; | ||
400 | |||
401 | static void * | ||
402 | start_upload_helper (void *cls) | ||
403 | { | ||
404 | FSUC *fsuc = cls; | ||
405 | |||
406 | GNUNET_FSUI_upload_start (ctx, | ||
407 | fsuc->filename, | ||
408 | (GNUNET_FSUI_DirectoryScanCallback) & | ||
409 | GNUNET_disk_directory_scan, ectx, fsuc->anonymity, | ||
410 | fsuc->priority, fsuc->index, fsuc->extract, | ||
411 | fsuc->deep_index, fsuc->expire, fsuc->meta, | ||
412 | fsuc->gkeywordURI, fsuc->keywordURI); | ||
413 | return NULL; | ||
414 | } | ||
415 | |||
416 | void | ||
417 | on_fsinsertuploadbutton_clicked_fs (gpointer dummy, GtkWidget * uploadButton) | ||
418 | { | ||
419 | FSUC fsuc; | ||
420 | const char *filename; | ||
421 | const char *filenamerest; | ||
422 | GtkWidget *dialog; | ||
423 | EXTRACTOR_ExtractorList *extractors; | ||
424 | char *config; | ||
425 | struct GNUNET_MetaData *meta; | ||
426 | struct GNUNET_ECRS_URI *keywordURI; | ||
427 | |||
428 | extractors = EXTRACTOR_loadDefaultLibraries (); | ||
429 | config = NULL; | ||
430 | GNUNET_GC_get_configuration_value_string (cfg, "FS", "EXTRACTORS", "", | ||
431 | &config); | ||
432 | if (strlen (config) > 0) | ||
433 | extractors = EXTRACTOR_loadConfigLibraries (extractors, config); | ||
434 | GNUNET_free (config); | ||
435 | filename = | ||
436 | getEntryLineValue (GNUNET_GTK_get_main_glade_XML (), | ||
437 | "uploadFilenameComboBoxEntry"); | ||
438 | metaXML = | ||
439 | glade_xml_new (GNUNET_GTK_get_glade_filename (), "metaDataDialog", | ||
440 | PACKAGE_NAME); | ||
441 | GNUNET_GTK_connect_glade_with_plugins (metaXML); | ||
442 | dialog = glade_xml_get_widget (metaXML, "metaDataDialog"); | ||
443 | meta = GNUNET_meta_data_create (); | ||
444 | GNUNET_meta_data_extract_from_file (ectx, meta, filename, extractors); | ||
445 | EXTRACTOR_removeAll (extractors); | ||
446 | filenamerest = &filename[strlen (filename) - 1]; | ||
447 | while ((filenamerest > filename) && (filenamerest[-1] != DIR_SEPARATOR)) | ||
448 | filenamerest--; | ||
449 | GNUNET_meta_data_insert (meta, EXTRACTOR_FILENAME, filenamerest); | ||
450 | keywordURI = GNUNET_meta_data_to_uri (meta); | ||
451 | while (GNUNET_OK == GNUNET_meta_data_delete (meta, EXTRACTOR_SPLIT, NULL)); | ||
452 | while (GNUNET_OK == | ||
453 | GNUNET_meta_data_delete (meta, EXTRACTOR_LOWERCASE, NULL)); | ||
454 | createMetaDataListTreeView (metaXML, | ||
455 | "metaDataDialogMetaDataList", | ||
456 | "previewImage", meta); | ||
457 | GNUNET_meta_data_destroy (meta); | ||
458 | createKeywordListTreeView (metaXML, | ||
459 | "metaDataDialogKeywordList", keywordURI); | ||
460 | GNUNET_ECRS_uri_destroy (keywordURI); | ||
461 | createMetaTypeComboBox (metaXML, "metaDataDialogMetaTypeComboBox"); | ||
462 | g_signal_connect_data (gtk_tree_view_get_selection | ||
463 | (GTK_TREE_VIEW | ||
464 | (glade_xml_get_widget | ||
465 | (metaXML, "metaDataDialogKeywordList"))), | ||
466 | "changed", | ||
467 | G_CALLBACK (&on_keyword_list_selection_changed), | ||
468 | NULL, NULL, 0); | ||
469 | g_signal_connect_data (gtk_tree_view_get_selection | ||
470 | (GTK_TREE_VIEW | ||
471 | (glade_xml_get_widget | ||
472 | (metaXML, "metaDataDialogMetaDataList"))), | ||
473 | "changed", | ||
474 | G_CALLBACK (&on_metadata_list_selection_changed), | ||
475 | NULL, NULL, 0); | ||
476 | gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_OK); | ||
477 | if (gtk_dialog_run (GTK_DIALOG (dialog)) != GTK_RESPONSE_CANCEL) | ||
478 | { | ||
479 | fsuc.anonymity = getSpinButtonValue (GNUNET_GTK_get_main_glade_XML (), | ||
480 | "uploadAnonymityLevelSpinButton"); | ||
481 | fsuc.priority = getSpinButtonValue (GNUNET_GTK_get_main_glade_XML (), | ||
482 | "contentPrioritySpinButton"); | ||
483 | fsuc.index = | ||
484 | getToggleButtonValue (GNUNET_GTK_get_main_glade_XML (), | ||
485 | "indexbutton"); | ||
486 | fsuc.extract = | ||
487 | getToggleButtonValue (GNUNET_GTK_get_main_glade_XML (), | ||
488 | "doExtractCheckButton"); | ||
489 | fsuc.deep_index = | ||
490 | getToggleButtonValue (GNUNET_GTK_get_main_glade_XML (), | ||
491 | "deepIndexCheckButton"); | ||
492 | fsuc.expire = GNUNET_get_time () + 2 * GNUNET_CRON_YEARS; | ||
493 | fsuc.meta = getMetaDataFromList (metaXML, | ||
494 | "metaDataDialogMetaDataList", | ||
495 | "previewImage"); | ||
496 | fsuc.keywordURI = getKeywordURIFromList (metaXML, | ||
497 | "metaDataDialogKeywordList"); | ||
498 | fsuc.gkeywordURI = GNUNET_ECRS_string_to_uri (ectx, | ||
499 | GNUNET_ECRS_URI_PREFIX | ||
500 | GNUNET_ECRS_SEARCH_INFIX); | ||
501 | fsuc.filename = GNUNET_strdup (filename); | ||
502 | GNUNET_GTK_run_with_save_calls (&start_upload_helper, &fsuc); | ||
503 | GNUNET_free (fsuc.filename); | ||
504 | GNUNET_meta_data_destroy (fsuc.meta); | ||
505 | if (fsuc.gkeywordURI != NULL) | ||
506 | GNUNET_ECRS_uri_destroy (fsuc.gkeywordURI); | ||
507 | if (fsuc.keywordURI != NULL) | ||
508 | GNUNET_ECRS_uri_destroy (fsuc.keywordURI); | ||
509 | } | ||
510 | gtk_widget_destroy (dialog); | ||
511 | UNREF (metaXML); | ||
512 | metaXML = NULL; | ||
513 | } | ||
514 | |||
515 | #ifndef MINGW | ||
516 | static char * | ||
517 | selectFile (const char *oldfilename) | ||
518 | { | ||
519 | GladeXML *uploadXML; | ||
520 | GtkFileChooser *dialog; | ||
521 | char *ret; | ||
522 | |||
523 | uploadXML | ||
524 | = glade_xml_new (GNUNET_GTK_get_glade_filename (), | ||
525 | "uploadfilechooserdialog", PACKAGE_NAME); | ||
526 | GNUNET_GTK_connect_glade_with_plugins (uploadXML); | ||
527 | dialog = GTK_FILE_CHOOSER (glade_xml_get_widget (uploadXML, | ||
528 | "uploadfilechooserdialog")); | ||
529 | gtk_file_chooser_set_filename (dialog, oldfilename); | ||
530 | if (getToggleButtonValue | ||
531 | (GNUNET_GTK_get_main_glade_XML (), "scopeRecursiveButton")) | ||
532 | gtk_file_chooser_set_action (dialog, | ||
533 | GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER); | ||
534 | if (gtk_dialog_run (GTK_DIALOG (dialog)) != GTK_RESPONSE_CANCEL) | ||
535 | ret = gtk_file_chooser_get_filename (dialog); | ||
536 | else | ||
537 | ret = NULL; | ||
538 | gtk_widget_destroy (GTK_WIDGET (dialog)); | ||
539 | UNREF (uploadXML); | ||
540 | return ret; | ||
541 | } | ||
542 | |||
543 | #else /* MINGW */ | ||
544 | |||
545 | static char * | ||
546 | selectFile (const char *oldfilename) | ||
547 | { | ||
548 | if (getToggleButtonValue | ||
549 | (GNUNET_GTK_get_main_glade_XML (), "scopeFileOnlyButton")) | ||
550 | return plibc_ChooseFile (_("Choose the file you want to publish."), | ||
551 | OFN_FILEMUSTEXIST | OFN_SHAREAWARE); | ||
552 | return plibc_ChooseDir (_("Choose the directory you want to publish."), | ||
553 | BIF_USENEWUI | BIF_SHAREABLE | | ||
554 | BIF_NONEWFOLDERBUTTON); | ||
555 | } | ||
556 | #endif /* MINGW */ | ||
557 | |||
558 | void | ||
559 | on_mainFileSharingInsertBrowseButton_clicked_fs (GtkWidget * browseButton, | ||
560 | gpointer dummy) | ||
561 | { | ||
562 | char *filename; | ||
563 | char *ofn; | ||
564 | const char *oldfilename; | ||
565 | GtkWidget *uploadLine; | ||
566 | GtkEntry *entry; | ||
567 | GtkListStore *model; | ||
568 | GtkTreeIter iter; | ||
569 | |||
570 | uploadLine = glade_xml_get_widget (GNUNET_GTK_get_main_glade_XML (), | ||
571 | "uploadFilenameComboBoxEntry"); | ||
572 | entry = GTK_ENTRY (gtk_bin_get_child (GTK_BIN (uploadLine))); | ||
573 | oldfilename = gtk_entry_get_text (entry); | ||
574 | if (oldfilename == NULL) | ||
575 | oldfilename = getenv ("PWD"); | ||
576 | if (oldfilename == NULL) | ||
577 | oldfilename = getenv ("HOME"); | ||
578 | if (oldfilename == NULL) | ||
579 | oldfilename = "/"; | ||
580 | ofn = GNUNET_expand_file_name (ectx, oldfilename); | ||
581 | filename = selectFile (ofn); | ||
582 | GNUNET_free (ofn); | ||
583 | if (NULL == filename) | ||
584 | return; | ||
585 | gtk_entry_set_text (entry, filename); | ||
586 | model = | ||
587 | GTK_LIST_STORE (gtk_combo_box_get_model (GTK_COMBO_BOX (uploadLine))); | ||
588 | gtk_list_store_prepend (model, &iter); | ||
589 | gtk_list_store_set (model, &iter, 0, filename, -1); | ||
590 | free (filename); | ||
591 | } | ||
592 | |||
593 | struct FCBC | ||
594 | { | ||
595 | int (*method) (struct GNUNET_FSUI_UploadList * list); | ||
596 | struct GNUNET_FSUI_UploadList *argument; | ||
597 | }; | ||
598 | |||
599 | static void * | ||
600 | fsui_callback (void *cls) | ||
601 | { | ||
602 | struct FCBC *fcbc = cls; | ||
603 | fcbc->method (fcbc->argument); | ||
604 | return NULL; | ||
605 | } | ||
606 | |||
607 | static void | ||
608 | clearCompletedUploadCallback (GtkTreeModel * model, | ||
609 | GtkTreePath * path, | ||
610 | GtkTreeIter * iter, gpointer unused) | ||
611 | { | ||
612 | UploadList *ul; | ||
613 | struct FCBC fcbc; | ||
614 | |||
615 | GNUNET_GE_ASSERT (ectx, model == GTK_TREE_MODEL (upload_summary)); | ||
616 | gtk_tree_model_get (model, iter, UPLOAD_INTERNAL, &ul, -1); | ||
617 | if ((ul->has_terminated) && (ul->is_top)) | ||
618 | { | ||
619 | fcbc.method = &GNUNET_FSUI_upload_stop; | ||
620 | fcbc.argument = ul->fsui_list; | ||
621 | GNUNET_GTK_run_with_save_calls (&fsui_callback, &fcbc); | ||
622 | } | ||
623 | } | ||
624 | |||
625 | /** | ||
626 | * The user has edited the search entry. | ||
627 | * Update search button status. | ||
628 | */ | ||
629 | void | ||
630 | on_uploadFilenameComboBoxEntry_changed_fs (gpointer dummy2, | ||
631 | GtkWidget * searchEntry) | ||
632 | { | ||
633 | const char *filename; | ||
634 | GtkWidget *uploadButton; | ||
635 | struct stat buf; | ||
636 | int ok; | ||
637 | GtkWidget *toggle; | ||
638 | |||
639 | filename = | ||
640 | getEntryLineValue (GNUNET_GTK_get_main_glade_XML (), | ||
641 | "uploadFilenameComboBoxEntry"); | ||
642 | ok = (0 == stat (filename, &buf)); | ||
643 | if (ok) | ||
644 | ok = (0 == ACCESS (filename, R_OK)); | ||
645 | if (ok) | ||
646 | { | ||
647 | if (S_ISDIR (buf.st_mode)) | ||
648 | { | ||
649 | toggle = glade_xml_get_widget (GNUNET_GTK_get_main_glade_XML (), | ||
650 | "scopeRecursiveButton"); | ||
651 | gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (toggle), 1); | ||
652 | } | ||
653 | else | ||
654 | { | ||
655 | toggle = glade_xml_get_widget (GNUNET_GTK_get_main_glade_XML (), | ||
656 | "scopeFileOnlyButton"); | ||
657 | gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (toggle), 1); | ||
658 | } | ||
659 | } | ||
660 | uploadButton = | ||
661 | glade_xml_get_widget (GNUNET_GTK_get_main_glade_XML (), | ||
662 | "fsinsertuploadbutton"); | ||
663 | gtk_widget_set_sensitive (uploadButton, ok); | ||
664 | } | ||
665 | |||
666 | void | ||
667 | on_clearCompletedUploads_clicked_fs (void *unused, GtkWidget * clearButton) | ||
668 | { | ||
669 | GNUNET_GTK_tree_model_foreach (GTK_TREE_MODEL (upload_summary), | ||
670 | &clearCompletedUploadCallback, NULL); | ||
671 | } | ||
672 | |||
673 | static void | ||
674 | do_copy_uri (GtkTreeModel * model, | ||
675 | GtkTreePath * path, GtkTreeIter * iter, gpointer unused) | ||
676 | { | ||
677 | char *str; | ||
678 | GtkClipboard *clip; | ||
679 | |||
680 | gtk_tree_model_get (model, iter, UPLOAD_URISTRING, &str, -1); | ||
681 | clip = gtk_clipboard_get (GDK_SELECTION_CLIPBOARD); | ||
682 | gtk_clipboard_set_text (clip, str, strlen (str)); | ||
683 | GNUNET_free (str); | ||
684 | } | ||
685 | |||
686 | int | ||
687 | on_upload_copy_uri_activate_fs (void *dummy1, GtkWidget * dummy2) | ||
688 | { | ||
689 | GtkTreeSelection *selection; | ||
690 | GtkWidget *uploadList; | ||
691 | |||
692 | uploadList = | ||
693 | glade_xml_get_widget (GNUNET_GTK_get_main_glade_XML (), | ||
694 | "activeUploadsList"); | ||
695 | selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (uploadList)); | ||
696 | GNUNET_GTK_tree_selection_selected_foreach (selection, &do_copy_uri, NULL); | ||
697 | return FALSE; | ||
698 | } | ||
699 | |||
700 | static void | ||
701 | fsuiCallUploadCallback (GtkTreeModel * model, | ||
702 | GtkTreePath * path, | ||
703 | GtkTreeIter * iter, gpointer fsui_call) | ||
704 | { | ||
705 | UploadList *ul; | ||
706 | struct FCBC fcbc; | ||
707 | |||
708 | GNUNET_GE_ASSERT (ectx, model == GTK_TREE_MODEL (upload_summary)); | ||
709 | gtk_tree_model_get (model, iter, UPLOAD_INTERNAL, &ul, -1); | ||
710 | fcbc.method = fsui_call; | ||
711 | fcbc.argument = ul->fsui_list; | ||
712 | GNUNET_GTK_run_with_save_calls (&fsui_callback, &fcbc); | ||
713 | } | ||
714 | |||
715 | void | ||
716 | on_stopUpload_clicked_fs (void *unused, GtkWidget * clearButton) | ||
717 | { | ||
718 | GtkTreeSelection *selection; | ||
719 | GtkWidget *uploadList; | ||
720 | |||
721 | uploadList = | ||
722 | glade_xml_get_widget (GNUNET_GTK_get_main_glade_XML (), | ||
723 | "activeUploadsList"); | ||
724 | selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (uploadList)); | ||
725 | GNUNET_GTK_tree_selection_selected_foreach | ||
726 | (selection, &fsuiCallUploadCallback, &GNUNET_FSUI_upload_abort); | ||
727 | } | ||
728 | |||
729 | /** | ||
730 | * Right-click on the active uploads list | ||
731 | */ | ||
732 | gboolean | ||
733 | on_activeUploadsList_button_press_fs (GtkWidget * treeview, | ||
734 | GdkEventButton * event_button, | ||
735 | gpointer dummy) | ||
736 | { | ||
737 | GtkWidget *menu; | ||
738 | GladeXML *contextMenuXML; | ||
739 | |||
740 | contextMenuXML = | ||
741 | glade_xml_new (GNUNET_GTK_get_glade_filename (), | ||
742 | "uploadsContextMenu", PACKAGE_NAME); | ||
743 | GNUNET_GTK_connect_glade_with_plugins (contextMenuXML); | ||
744 | menu = glade_xml_get_widget (contextMenuXML, "uploadsContextMenu"); | ||
745 | if (event_button->button == 3) | ||
746 | gtk_menu_popup (GTK_MENU (menu), | ||
747 | NULL, NULL, NULL, NULL, | ||
748 | event_button->button, event_button->time); | ||
749 | return FALSE; | ||
750 | } | ||
751 | |||
752 | /* end of upload.c */ | ||