aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/edit_publish_dialog.c10
-rw-r--r--src/gnunet-gtk.c3
-rw-r--r--src/main_window_file_publish.c195
3 files changed, 175 insertions, 33 deletions
diff --git a/src/edit_publish_dialog.c b/src/edit_publish_dialog.c
index 16cee5ac..abb6beb4 100644
--- a/src/edit_publish_dialog.c
+++ b/src/edit_publish_dialog.c
@@ -644,6 +644,16 @@ GNUNET_GTK_edit_publish_dialog (int *do_index,
644 GNUNET_break (0); 644 GNUNET_break (0);
645 return; 645 return;
646 } 646 }
647 if (GNUNET_FS_file_information_is_directory (fip))
648 {
649 /* indexing does not apply to directories */
650 gtk_widget_hide (GTK_WIDGET (gtk_builder_get_object (builder,
651 "GNUNET_GTK_edit_file_information_index_check_button")));
652 gtk_widget_hide (GTK_WIDGET (gtk_builder_get_object (builder,
653 "GNUNET_GTK_edit_file_information_index_label")));
654
655 }
656
647 ad = GTK_WIDGET (gtk_builder_get_object (builder, 657 ad = GTK_WIDGET (gtk_builder_get_object (builder,
648 "GNUNET_GTK_edit_file_information_dialog")); 658 "GNUNET_GTK_edit_file_information_dialog"));
649 ls = GTK_LIST_STORE (gtk_builder_get_object (builder, 659 ls = GTK_LIST_STORE (gtk_builder_get_object (builder,
diff --git a/src/gnunet-gtk.c b/src/gnunet-gtk.c
index f3f9a19f..215d4d8c 100644
--- a/src/gnunet-gtk.c
+++ b/src/gnunet-gtk.c
@@ -363,9 +363,8 @@ GNUNET_GTK_get_new_builder (const char *filename)
363 ret = gtk_builder_new (); 363 ret = gtk_builder_new ();
364 gtk_builder_set_translation_domain (ret, "gnunet-gtk"); 364 gtk_builder_set_translation_domain (ret, "gnunet-gtk");
365 GNUNET_asprintf (&glade_path, 365 GNUNET_asprintf (&glade_path,
366 "%s/%s/%s", 366 "%s%s",
367 GNUNET_GTK_get_data_dir (), 367 GNUNET_GTK_get_data_dir (),
368 PACKAGE_NAME,
369 filename); 368 filename);
370 error = NULL; 369 error = NULL;
371 if (0 == gtk_builder_add_from_file (ret, glade_path, &error)) 370 if (0 == gtk_builder_add_from_file (ret, glade_path, &error))
diff --git a/src/main_window_file_publish.c b/src/main_window_file_publish.c
index d44c3137..58352b77 100644
--- a/src/main_window_file_publish.c
+++ b/src/main_window_file_publish.c
@@ -179,7 +179,7 @@ static void
179add_file_at_iter (const char *filename, 179add_file_at_iter (const char *filename,
180 uint32_t anonymity_level, 180 uint32_t anonymity_level,
181 uint32_t priority, 181 uint32_t priority,
182 struct GNUNET_TIME_Relative expiration, 182 struct GNUNET_TIME_Absolute expiration,
183 int do_index, 183 int do_index,
184 GtkTreeIter *iter) 184 GtkTreeIter *iter)
185{ 185{
@@ -240,7 +240,7 @@ add_file_at_iter (const char *filename,
240 do_index, 240 do_index,
241 anonymity_level, 241 anonymity_level,
242 priority, 242 priority,
243 GNUNET_TIME_relative_to_absolute (expiration)); 243 expiration);
244 GNUNET_CONTAINER_meta_data_destroy (meta); 244 GNUNET_CONTAINER_meta_data_destroy (meta);
245 GNUNET_FS_uri_destroy (ksk_uri); 245 GNUNET_FS_uri_destroy (ksk_uri);
246 file_size_fancy = GNUNET_STRINGS_byte_size_fancy (file_size); 246 file_size_fancy = GNUNET_STRINGS_byte_size_fancy (file_size);
@@ -260,24 +260,24 @@ add_file_at_iter (const char *filename,
260 260
261/** 261/**
262 * Add an empty directory to the tree model. 262 * Add an empty directory to the tree model.
263 * FIXME: consider opening a dialog to get
264 * anonymity, priority and expiration prior
265 * to calling this function (currently we
266 * use default values for those).
267 * 263 *
268 * @param name name for the directory 264 * @param name name for the directory
269 * @param iter parent entry, or NULL for top-level addition 265 * @param iter parent entry, or NULL for top-level addition
266 * @param pos iterator to set to the location of the new element
270 */ 267 */
271static void 268static void
272create_dir_at_iter (const char *name, 269create_dir_at_iter (const char *name,
273 GtkTreeIter *iter) 270 uint32_t anonymity,
271 uint32_t priority,
272 struct GNUNET_TIME_Absolute expiration,
273 GtkTreeIter *iter,
274 GtkTreeIter *pos)
274{ 275{
275 struct GNUNET_FS_FileInformation *fi; 276 struct GNUNET_FS_FileInformation *fi;
276 GtkTreeRowReference *row_reference; 277 GtkTreeRowReference *row_reference;
277 GtkTreePath *path; 278 GtkTreePath *path;
278 struct GNUNET_CONTAINER_MetaData *meta; 279 struct GNUNET_CONTAINER_MetaData *meta;
279 GtkTreeStore *ts; 280 GtkTreeStore *ts;
280 GtkTreeIter pos;
281 281
282 ts = GTK_TREE_STORE (gtk_builder_get_object (master_builder, 282 ts = GTK_TREE_STORE (gtk_builder_get_object (master_builder,
283 "GNUNET_GTK_file_sharing_publishing_tree_store")); 283 "GNUNET_GTK_file_sharing_publishing_tree_store"));
@@ -291,11 +291,11 @@ create_dir_at_iter (const char *name,
291 name, 291 name,
292 strlen(name)+1); 292 strlen(name)+1);
293 gtk_tree_store_insert_before (ts, 293 gtk_tree_store_insert_before (ts,
294 &pos, 294 pos,
295 iter, 295 iter,
296 NULL); 296 NULL);
297 path = gtk_tree_model_get_path (GTK_TREE_MODEL (ts), 297 path = gtk_tree_model_get_path (GTK_TREE_MODEL (ts),
298 &pos); 298 pos);
299 row_reference = gtk_tree_row_reference_new (GTK_TREE_MODEL (ts), 299 row_reference = gtk_tree_row_reference_new (GTK_TREE_MODEL (ts),
300 path); 300 path);
301 gtk_tree_path_free (path); 301 gtk_tree_path_free (path);
@@ -303,21 +303,68 @@ create_dir_at_iter (const char *name,
303 row_reference, 303 row_reference,
304 NULL, 304 NULL,
305 meta, 305 meta,
306 1 /* anonymity */, 1000 /* priority */, 306 anonymity,
307 GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_YEARS)); 307 priority,
308 expiration);
308 GNUNET_CONTAINER_meta_data_destroy (meta); 309 GNUNET_CONTAINER_meta_data_destroy (meta);
309 gtk_tree_store_set (ts, &pos, 310 gtk_tree_store_set (ts, pos,
310 0, "0", 311 0, "0",
311 1, (gboolean) GNUNET_NO, 312 1, (gboolean) GNUNET_NO,
312 2, name, 313 2, name,
313 3, (guint) 1 /* anonymity */, 314 3, (guint) anonymity,
314 4, (guint) 1000 /* priority */, 315 4, (guint) priority,
315 5, fi, 316 5, fi,
316 -1); 317 -1);
317 update_selectivity (); 318 update_selectivity ();
318} 319}
319 320
320 321
322struct AddDirContext
323{
324 GtkTreeIter *parent;
325 uint32_t anonymity_level;
326 uint32_t priority;
327 struct GNUNET_TIME_Absolute expiration;
328 int do_index;
329};
330
331
332/**
333 * Add a directory to the tree model.
334 *
335 * @param filename directory name to add
336 * @param iter parent entry, or NULL for top-level addition
337 */
338static void
339add_dir_at_iter (const char *filename,
340 uint32_t anonymity_level,
341 uint32_t priority,
342 struct GNUNET_TIME_Absolute expiration,
343 int do_index,
344 GtkTreeIter *iter);
345
346
347/**
348 * Function called by the directory iterator to
349 * (recursively) add all of the files in the
350 * directory to the tree.
351 */
352static int
353scan_cb (void *cls,
354 const char *filename)
355{
356 struct AddDirContext *adc = cls;
357
358 add_dir_at_iter (filename,
359 adc->anonymity_level,
360 adc->priority,
361 adc->expiration,
362 adc->do_index,
363 adc->parent);
364 return GNUNET_OK;
365}
366
367
321/** 368/**
322 * Add a directory to the tree model. 369 * Add a directory to the tree model.
323 * 370 *
@@ -326,10 +373,44 @@ create_dir_at_iter (const char *name,
326 */ 373 */
327static void 374static void
328add_dir_at_iter (const char *filename, 375add_dir_at_iter (const char *filename,
376 uint32_t anonymity_level,
377 uint32_t priority,
378 struct GNUNET_TIME_Absolute expiration,
379 int do_index,
329 GtkTreeIter *iter) 380 GtkTreeIter *iter)
330{ 381{
331 GNUNET_break (0); 382 struct stat sbuf;
332 update_selectivity (); 383 struct AddDirContext scan_ctx;
384 GtkTreeIter pos;
385
386 fprintf (stderr, "Adding %s\n", filename);
387 if (0 != STAT (filename, &sbuf))
388 return;
389 if (S_ISDIR (sbuf.st_mode))
390 {
391 create_dir_at_iter (filename,
392 anonymity_level,
393 priority,
394 expiration,
395 iter, &pos);
396 scan_ctx.parent = &pos;
397 scan_ctx.anonymity_level = anonymity_level;
398 scan_ctx.priority = priority;
399 scan_ctx.expiration = expiration;
400 scan_ctx.do_index = do_index;
401 GNUNET_DISK_directory_scan (filename,
402 &scan_cb,
403 &scan_ctx);
404 }
405 else
406 {
407 add_file_at_iter (filename,
408 anonymity_level,
409 priority,
410 expiration,
411 do_index,
412 iter);
413 }
333} 414}
334 415
335 416
@@ -648,18 +729,32 @@ GNUNET_GTK_master_publish_dialog_new_button_clicked_cb (GtkWidget * dummy,
648 GtkTreeView *tv; 729 GtkTreeView *tv;
649 GtkTreeSelection *sel; 730 GtkTreeSelection *sel;
650 GtkTreeIter iter; 731 GtkTreeIter iter;
732 GtkTreeIter pos;
651 733
652 tv = GTK_TREE_VIEW (gtk_builder_get_object (master_builder, 734 tv = GTK_TREE_VIEW (gtk_builder_get_object (master_builder,
653 "GNUNET_GTK_master_publish_dialog_file_information_tree_view")); 735 "GNUNET_GTK_master_publish_dialog_file_information_tree_view"));
654 sel = gtk_tree_view_get_selection (tv); 736 sel = gtk_tree_view_get_selection (tv);
737 /* FIXME: consider opening a dialog to get
738 * anonymity, priority and expiration prior
739 * to calling this function (currently we
740 * use default values for those).
741 */
655 if (TRUE != gtk_tree_selection_get_selected (sel, 742 if (TRUE != gtk_tree_selection_get_selected (sel,
656 NULL, 743 NULL,
657 &iter)) 744 &iter))
658 { 745 {
659 create_dir_at_iter ("unnamed/", NULL); 746 create_dir_at_iter ("unnamed/",
747 1 /* anonymity */,
748 1000 /* priority */,
749 GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_YEARS) /* expiration */,
750 NULL, &pos);
660 return; 751 return;
661 } 752 }
662 create_dir_at_iter ("unnamed/", &iter); 753 create_dir_at_iter ("unnamed/",
754 1 /* anonymity */,
755 1000 /* priority */,
756 GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_YEARS) /* expiration */,
757 &iter, &pos);
663} 758}
664 759
665 760
@@ -670,19 +765,21 @@ struct ListValue
670}; 765};
671 766
672 767
768static struct ListValue list_values[] =
769 {
770 { gettext_noop ("1 year"), 1000LL * 60 * 60 * 24 * 365 },
771 { gettext_noop ("1 month"), 1000LL * 60 * 60 * 24 * 30 },
772 { gettext_noop ("1 day"), 1000LL * 60 * 60 * 24 },
773 { gettext_noop ("1 hour"), 1000LL * 60 * 60 },
774 { gettext_noop ("1 minute"), 1000LL * 60 },
775 { NULL, 0}
776 };
777
778
673void 779void
674GNUNET_GTK_master_publish_dialog_add_button_clicked_cb (GtkWidget * dummy, 780GNUNET_GTK_master_publish_dialog_add_button_clicked_cb (GtkWidget * dummy,
675 gpointer data) 781 gpointer data)
676{ 782{
677 static struct ListValue list_values[] =
678 {
679 { gettext_noop ("1 year"), 1000LL * 60 * 60 * 24 * 365 },
680 { gettext_noop ("1 month"), 1000LL * 60 * 60 * 24 * 30 },
681 { gettext_noop ("1 day"), 1000LL * 60 * 60 * 24 },
682 { gettext_noop ("1 hour"), 1000LL * 60 * 60 },
683 { gettext_noop ("1 minute"), 1000LL * 60 },
684 { NULL, 0}
685 };
686 GtkWidget *ad; 783 GtkWidget *ad;
687 GtkBuilder *builder; 784 GtkBuilder *builder;
688 char *filename; 785 char *filename;
@@ -734,7 +831,8 @@ GNUNET_GTK_master_publish_dialog_add_button_clicked_cb (GtkWidget * dummy,
734 gtk_combo_box_get_active_iter (cb, &iter); 831 gtk_combo_box_get_active_iter (cb, &iter);
735 gtk_tree_model_get (GTK_TREE_MODEL (ls), &iter, 1, &exp.value, -1); 832 gtk_tree_model_get (GTK_TREE_MODEL (ls), &iter, 1, &exp.value, -1);
736 add_file_at_iter (filename, anonymity, 833 add_file_at_iter (filename, anonymity,
737 priority, exp, do_index, 834 priority,
835 GNUNET_TIME_relative_to_absolute (exp), do_index,
738 NULL); 836 NULL);
739 gtk_widget_destroy (ad); 837 gtk_widget_destroy (ad);
740 g_object_unref (G_OBJECT (builder)); 838 g_object_unref (G_OBJECT (builder));
@@ -860,6 +958,14 @@ GNUNET_GTK_master_publish_dialog_open_button_clicked_cb (GtkWidget * dummy,
860 GtkWidget *ad; 958 GtkWidget *ad;
861 GtkBuilder *builder; 959 GtkBuilder *builder;
862 char *filename; 960 char *filename;
961 uint32_t anonymity;
962 uint32_t priority;
963 struct GNUNET_TIME_Relative exp;
964 int do_index;
965 GtkComboBox *cb;
966 GtkListStore *ls;
967 GtkTreeIter iter;
968 int i;
863 969
864 builder = GNUNET_GTK_get_new_builder ("publish-directory-dialog.glade"); 970 builder = GNUNET_GTK_get_new_builder ("publish-directory-dialog.glade");
865 if (builder == NULL) 971 if (builder == NULL)
@@ -869,6 +975,22 @@ GNUNET_GTK_master_publish_dialog_open_button_clicked_cb (GtkWidget * dummy,
869 } 975 }
870 ad = GTK_WIDGET (gtk_builder_get_object (builder, 976 ad = GTK_WIDGET (gtk_builder_get_object (builder,
871 "GNUNET_GTK_publish_directory_dialog")); 977 "GNUNET_GTK_publish_directory_dialog"));
978 cb = GTK_COMBO_BOX (gtk_builder_get_object (builder,
979 "GNUNET_GTK_publish_directory_dialog_expiration_combo_box"));
980
981 ls = GTK_LIST_STORE (gtk_builder_get_object (builder,
982 "GNUNET_GTK_publish_directory_dialog_expiration_list_store"));
983 i = 0;
984 while (list_values[i].text != NULL)
985 {
986 gtk_list_store_insert_before (ls, &iter, NULL);
987 gtk_list_store_set (ls, &iter,
988 0, gettext (list_values[i].text),
989 1, list_values[i].value,
990 -1);
991 i++;
992 }
993
872 if (GTK_RESPONSE_OK != gtk_dialog_run (GTK_DIALOG (ad))) 994 if (GTK_RESPONSE_OK != gtk_dialog_run (GTK_DIALOG (ad)))
873 { 995 {
874 gtk_widget_destroy (ad); 996 gtk_widget_destroy (ad);
@@ -876,10 +998,21 @@ GNUNET_GTK_master_publish_dialog_open_button_clicked_cb (GtkWidget * dummy,
876 return; 998 return;
877 } 999 }
878 filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER(ad)); 1000 filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER(ad));
879 add_dir_at_iter (filename, NULL); 1001 anonymity = gtk_spin_button_get_value (GTK_SPIN_BUTTON (gtk_builder_get_object (builder,
880 GNUNET_break (0); 1002 "GNUNET_GTK_publish_directory_dialog_anonymity_spin_button")));
1003 priority = gtk_spin_button_get_value (GTK_SPIN_BUTTON (gtk_builder_get_object (builder,
1004 "GNUNET_GTK_publish_directory_dialog_priority_spin_button")));
1005 do_index = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (gtk_builder_get_object (builder,
1006 "GNUNET_GTK_publish_directory_dialog_do_index_checkbutton")));
1007 gtk_combo_box_get_active_iter (cb, &iter);
1008 gtk_tree_model_get (GTK_TREE_MODEL (ls), &iter, 1, &exp.value, -1);
881 gtk_widget_destroy (ad); 1009 gtk_widget_destroy (ad);
882 g_object_unref (G_OBJECT (builder)); 1010 g_object_unref (G_OBJECT (builder));
1011 /* FIXME: open progress dialog here... */
1012 add_dir_at_iter (filename, anonymity, priority,
1013 GNUNET_TIME_relative_to_absolute (exp),
1014 do_index,
1015 NULL);
883 g_free (filename); 1016 g_free (filename);
884 update_selectivity (); 1017 update_selectivity ();
885} 1018}