diff options
Diffstat (limited to 'src/fs/gnunet-fs-gtk-edit_publish_dialog.c')
-rw-r--r-- | src/fs/gnunet-fs-gtk-edit_publish_dialog.c | 319 |
1 files changed, 170 insertions, 149 deletions
diff --git a/src/fs/gnunet-fs-gtk-edit_publish_dialog.c b/src/fs/gnunet-fs-gtk-edit_publish_dialog.c index 61832925..a689b06d 100644 --- a/src/fs/gnunet-fs-gtk-edit_publish_dialog.c +++ b/src/fs/gnunet-fs-gtk-edit_publish_dialog.c | |||
@@ -73,11 +73,6 @@ struct EditPublicationDialogContext | |||
73 | GtkComboBox *anonymity_combo; | 73 | GtkComboBox *anonymity_combo; |
74 | 74 | ||
75 | /** | 75 | /** |
76 | * Liststore of the 'anonymity_combo' with the anonymity levels. | ||
77 | */ | ||
78 | GtkListStore *anonymity_liststore; | ||
79 | |||
80 | /** | ||
81 | * Liststore of possible publication types. | 76 | * Liststore of possible publication types. |
82 | */ | 77 | */ |
83 | GtkListStore *pubtypes_liststore; | 78 | GtkListStore *pubtypes_liststore; |
@@ -147,11 +142,6 @@ struct EditPublicationDialogContext | |||
147 | void *cb_cls; | 142 | void *cb_cls; |
148 | 143 | ||
149 | /** | 144 | /** |
150 | * Short name of the file being published (or NULL). | ||
151 | */ | ||
152 | char *short_fn; | ||
153 | |||
154 | /** | ||
155 | * Briefly used temporary meta data set. | 145 | * Briefly used temporary meta data set. |
156 | */ | 146 | */ |
157 | struct GNUNET_CONTAINER_MetaData *md; | 147 | struct GNUNET_CONTAINER_MetaData *md; |
@@ -175,9 +165,8 @@ struct EditPublicationDialogContext | |||
175 | 165 | ||
176 | /** | 166 | /** |
177 | * Is it allowed for the user to supply keywords in this dialog? | 167 | * Is it allowed for the user to supply keywords in this dialog? |
178 | * FIXME: why 'gboolean'? | ||
179 | */ | 168 | */ |
180 | gboolean allow_no_keywords; | 169 | int allow_no_keywords; |
181 | 170 | ||
182 | }; | 171 | }; |
183 | 172 | ||
@@ -191,7 +180,6 @@ static void | |||
191 | free_edit_dialog_context (struct EditPublicationDialogContext *ctx) | 180 | free_edit_dialog_context (struct EditPublicationDialogContext *ctx) |
192 | { | 181 | { |
193 | gtk_widget_destroy (GTK_WIDGET (ctx->edit_publication_window)); | 182 | gtk_widget_destroy (GTK_WIDGET (ctx->edit_publication_window)); |
194 | GNUNET_free_non_null (ctx->short_fn); | ||
195 | // FIXME-LEAK: destroy builder! | 183 | // FIXME-LEAK: destroy builder! |
196 | GNUNET_free (ctx); | 184 | GNUNET_free (ctx); |
197 | } | 185 | } |
@@ -652,7 +640,7 @@ GNUNET_GTK_edit_publication_cancel_button_clicked_cb (GtkButton * button, | |||
652 | { | 640 | { |
653 | struct EditPublicationDialogContext *ctx = user_data; | 641 | struct EditPublicationDialogContext *ctx = user_data; |
654 | 642 | ||
655 | ctx->cb (ctx->cb_cls, GNUNET_SYSERR, NULL, NULL, NULL, GTK_RESPONSE_CANCEL); | 643 | ctx->cb (ctx->cb_cls, GTK_RESPONSE_CANCEL, NULL); |
656 | free_edit_dialog_context (ctx); | 644 | free_edit_dialog_context (ctx); |
657 | } | 645 | } |
658 | 646 | ||
@@ -672,17 +660,25 @@ GNUNET_GTK_edit_publication_window_delete_event_cb (GtkWidget * widget, | |||
672 | { | 660 | { |
673 | struct EditPublicationDialogContext *ctx = user_data; | 661 | struct EditPublicationDialogContext *ctx = user_data; |
674 | 662 | ||
675 | ctx->cb (ctx->cb_cls, GNUNET_SYSERR, NULL, NULL, NULL, GTK_RESPONSE_CANCEL); | 663 | ctx->cb (ctx->cb_cls, GTK_RESPONSE_CANCEL, NULL); |
676 | free_edit_dialog_context (ctx); | 664 | free_edit_dialog_context (ctx); |
677 | return TRUE; | 665 | return TRUE; |
678 | } | 666 | } |
679 | 667 | ||
680 | 668 | ||
681 | /** | 669 | /** |
682 | * Copy binary meta data from to the new container and also | 670 | * Copy binary meta data from to the new container and also preserve |
683 | * preserve all entries that were not changed. | 671 | * all entries that were not changed. In particular, all binary meta |
672 | * data is removed if the preview was changed, otherwise it is all | ||
673 | * kept. Similarly, if values are still in the liststore, they are | ||
674 | * fully kept (including plugin name and original format). "Keeping" | ||
675 | * a value means that it is added to the 'md' meta data in the dialog | ||
676 | * context. | ||
684 | * | 677 | * |
685 | * @param cls closure, a 'struct FileInformationUpdateContext' | 678 | * @param cls closure, a 'struct FileInformationUpdateContext'; |
679 | * contains the 'new' meta data to construct in the 'md' | ||
680 | * field and the liststore to check the current value | ||
681 | * against in 'meta_liststore'. | ||
686 | * @param plugin_name name of the plugin that produced this value; | 682 | * @param plugin_name name of the plugin that produced this value; |
687 | * special values can be used (i.e. '<zlib>' for zlib being | 683 | * special values can be used (i.e. '<zlib>' for zlib being |
688 | * used in the main libextractor library and yielding | 684 | * used in the main libextractor library and yielding |
@@ -752,7 +748,8 @@ preserve_meta_items (void *cls, const char *plugin_name, | |||
752 | 748 | ||
753 | 749 | ||
754 | /** | 750 | /** |
755 | * Function called to update the information in FI. | 751 | * Function called to update the information in FI based on the changes made in |
752 | * the edit dialog. | ||
756 | * | 753 | * |
757 | * @param cls closure with a 'struct FileInformationUpdateContext *' | 754 | * @param cls closure with a 'struct FileInformationUpdateContext *' |
758 | * @param fi the entry in the publish-structure | 755 | * @param fi the entry in the publish-structure |
@@ -774,55 +771,58 @@ file_information_update (void *cls, struct GNUNET_FS_FileInformation *fi, | |||
774 | { | 771 | { |
775 | struct EditPublicationDialogContext *ctx = cls; | 772 | struct EditPublicationDialogContext *ctx = cls; |
776 | GtkTreeIter iter; | 773 | GtkTreeIter iter; |
777 | struct GNUNET_FS_Uri *nxt; | 774 | gint year; |
778 | struct GNUNET_FS_Uri *mrg; | ||
779 | gchar *value; | ||
780 | guint ntype; | ||
781 | guint nformat; | ||
782 | gchar *fn; | ||
783 | char *data; | ||
784 | gsize data_size; | ||
785 | const char *mime; | ||
786 | GFile *f; | ||
787 | GFileInfo *finfo; | ||
788 | char *sfn; | ||
789 | 775 | ||
776 | /* gather publishing options */ | ||
790 | *do_index = gtk_toggle_button_get_active (ctx->index_checkbutton); | 777 | *do_index = gtk_toggle_button_get_active (ctx->index_checkbutton); |
778 | GNUNET_break (GNUNET_GTK_get_selected_anonymity_combo_level (ctx->anonymity_combo, | ||
779 | &bo->anonymity_level)); | ||
780 | bo->content_priority = gtk_spin_button_get_value (ctx->priority_spin); | ||
781 | bo->replication_level = gtk_spin_button_get_value (ctx->replication_spin); | ||
782 | year = gtk_spin_button_get_value (ctx->expiration_year_spin); | ||
783 | bo->expiration_time = GNUNET_FS_year_to_time (year); | ||
791 | 784 | ||
792 | /* update URI */ | 785 | /* update keyword-URI */ |
793 | if (NULL != (*uri)) | 786 | if (NULL != (*uri)) |
794 | GNUNET_FS_uri_destroy (*uri); | 787 | GNUNET_FS_uri_destroy (*uri); |
795 | *uri = NULL; | 788 | *uri = NULL; |
796 | nxt = NULL; | 789 | if (gtk_tree_model_get_iter_first (GTK_TREE_MODEL (ctx->keywords_liststore), &iter)) |
797 | mrg = NULL; | ||
798 | |||
799 | if (TRUE == gtk_tree_model_get_iter_first (GTK_TREE_MODEL (ctx->keywords_liststore), &iter)) | ||
800 | { | 790 | { |
801 | do | 791 | do |
802 | { | 792 | { |
793 | gchar *value; | ||
794 | |||
803 | gtk_tree_model_get (GTK_TREE_MODEL (ctx->keywords_liststore), &iter, 0, &value, -1); | 795 | gtk_tree_model_get (GTK_TREE_MODEL (ctx->keywords_liststore), &iter, 0, &value, -1); |
804 | nxt = GNUNET_FS_uri_ksk_create_from_args (1, (const char **) &value); | 796 | if (NULL == *uri) |
805 | mrg = GNUNET_FS_uri_ksk_merge (nxt, *uri); | 797 | *uri = GNUNET_FS_uri_ksk_create_from_args (1, (const char **) &value); |
806 | GNUNET_FS_uri_destroy (nxt); | 798 | else |
807 | if (NULL != *uri) | 799 | GNUNET_FS_uri_ksk_add_keyword (*uri, value, GNUNET_NO); |
808 | GNUNET_FS_uri_destroy (*uri); | ||
809 | *uri = mrg; | ||
810 | g_free (value); | 800 | g_free (value); |
811 | } | 801 | } |
812 | while (TRUE == gtk_tree_model_iter_next (GTK_TREE_MODEL (ctx->keywords_liststore), &iter)); | 802 | while (gtk_tree_model_iter_next (GTK_TREE_MODEL (ctx->keywords_liststore), &iter)); |
813 | } | 803 | } |
814 | 804 | ||
815 | /* update meta */ | 805 | /* update meta data; first, we copy the unchanged values from the original meta data */ |
816 | ctx->md = GNUNET_CONTAINER_meta_data_create (); | 806 | ctx->md = GNUNET_CONTAINER_meta_data_create (); |
817 | GNUNET_CONTAINER_meta_data_iterate (meta, | 807 | GNUNET_CONTAINER_meta_data_iterate (meta, |
818 | &preserve_meta_items, | 808 | &preserve_meta_items, |
819 | ctx); | 809 | ctx); |
820 | 810 | /* clear original meta data */ | |
821 | GNUNET_CONTAINER_meta_data_clear (meta); | 811 | GNUNET_CONTAINER_meta_data_clear (meta); |
822 | if (TRUE == gtk_tree_model_get_iter_first (GTK_TREE_MODEL (ctx->meta_liststore), &iter)) | 812 | /* add all of the 'preserved' values */ |
813 | GNUNET_CONTAINER_meta_data_merge (meta, ctx->md); | ||
814 | GNUNET_CONTAINER_meta_data_destroy (ctx->md); | ||
815 | ctx->md = NULL; | ||
816 | /* now add all of the values from the model; adding will simply do | ||
817 | nothing for values that are already in the set because they were preserved */ | ||
818 | if (gtk_tree_model_get_iter_first (GTK_TREE_MODEL (ctx->meta_liststore), &iter)) | ||
823 | { | 819 | { |
824 | do | 820 | do |
825 | { | 821 | { |
822 | guint ntype; | ||
823 | guint nformat; | ||
824 | gchar *value; | ||
825 | |||
826 | gtk_tree_model_get (GTK_TREE_MODEL (ctx->meta_liststore), &iter, 0, &ntype, 1, &nformat, 3, &value, -1); | 826 | gtk_tree_model_get (GTK_TREE_MODEL (ctx->meta_liststore), &iter, 0, &ntype, 1, &nformat, 3, &value, -1); |
827 | if (ntype > 0) | 827 | if (ntype > 0) |
828 | GNUNET_CONTAINER_meta_data_insert (ctx->md, "<user>", ntype, nformat, | 828 | GNUNET_CONTAINER_meta_data_insert (ctx->md, "<user>", ntype, nformat, |
@@ -830,11 +830,19 @@ file_information_update (void *cls, struct GNUNET_FS_FileInformation *fi, | |||
830 | strlen (value) + 1); | 830 | strlen (value) + 1); |
831 | g_free (value); | 831 | g_free (value); |
832 | } | 832 | } |
833 | while (TRUE == gtk_tree_model_iter_next (GTK_TREE_MODEL (ctx->meta_liststore), &iter)); | 833 | while (gtk_tree_model_iter_next (GTK_TREE_MODEL (ctx->meta_liststore), &iter)); |
834 | } | 834 | } |
835 | GNUNET_CONTAINER_meta_data_merge (meta, ctx->md); | 835 | |
836 | /* finally, if we got a new preview, add it as well */ | ||
836 | if (ctx->preview_changed == GNUNET_YES) | 837 | if (ctx->preview_changed == GNUNET_YES) |
837 | { | 838 | { |
839 | gchar *fn; | ||
840 | char *data; | ||
841 | gsize data_size; | ||
842 | const char *mime; | ||
843 | GFile *f; | ||
844 | GFileInfo *finfo; | ||
845 | |||
838 | fn = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER | 846 | fn = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER |
839 | (gtk_builder_get_object | 847 | (gtk_builder_get_object |
840 | (ctx->builder, | 848 | (ctx->builder, |
@@ -843,7 +851,7 @@ file_information_update (void *cls, struct GNUNET_FS_FileInformation *fi, | |||
843 | finfo = | 851 | finfo = |
844 | g_file_query_info (f, G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE, 0, NULL, | 852 | g_file_query_info (f, G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE, 0, NULL, |
845 | NULL); | 853 | NULL); |
846 | if (FALSE == g_file_load_contents (f, NULL, &data, &data_size, NULL, NULL)) | 854 | if (! g_file_load_contents (f, NULL, &data, &data_size, NULL, NULL)) |
847 | { | 855 | { |
848 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 856 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
849 | _("Could not load preview `%s' into memory\n"), fn); | 857 | _("Could not load preview `%s' into memory\n"), fn); |
@@ -862,18 +870,6 @@ file_information_update (void *cls, struct GNUNET_FS_FileInformation *fi, | |||
862 | g_object_unref (f); | 870 | g_object_unref (f); |
863 | g_free (fn); | 871 | g_free (fn); |
864 | } | 872 | } |
865 | GNUNET_CONTAINER_meta_data_destroy (ctx->md); | ||
866 | ctx->md = NULL; | ||
867 | |||
868 | /* update short_fn */ | ||
869 | sfn = GNUNET_CONTAINER_meta_data_get_first_by_types (meta, | ||
870 | EXTRACTOR_METATYPE_FILENAME, | ||
871 | -1); | ||
872 | if (NULL != sfn) | ||
873 | { | ||
874 | GNUNET_free_non_null (ctx->short_fn); | ||
875 | ctx->short_fn = sfn; | ||
876 | } | ||
877 | return GNUNET_SYSERR; /* only visit top-level item */ | 873 | return GNUNET_SYSERR; /* only visit top-level item */ |
878 | } | 874 | } |
879 | 875 | ||
@@ -891,31 +887,25 @@ GNUNET_GTK_edit_publication_confirm_button_clicked_cb (GtkButton * button, | |||
891 | gpointer user_data) | 887 | gpointer user_data) |
892 | { | 888 | { |
893 | struct EditPublicationDialogContext *ctx = user_data; | 889 | struct EditPublicationDialogContext *ctx = user_data; |
894 | struct GNUNET_FS_BlockOptions bo; | ||
895 | gint year; | ||
896 | 890 | ||
891 | /* push back changes to file-information */ | ||
897 | GNUNET_FS_file_information_inspect (ctx->fip, | 892 | GNUNET_FS_file_information_inspect (ctx->fip, |
898 | &file_information_update, | 893 | &file_information_update, |
899 | ctx); | 894 | ctx); |
900 | GNUNET_break (GNUNET_GTK_get_selected_anonymity_combo_level (ctx->anonymity_combo, | 895 | /* call our continuation */ |
901 | &bo.anonymity_level)); | ||
902 | bo.content_priority = gtk_spin_button_get_value (ctx->priority_spin); | ||
903 | bo.replication_level = gtk_spin_button_get_value (ctx->replication_spin); | ||
904 | year = gtk_spin_button_get_value (ctx->expiration_year_spin); | ||
905 | bo.expiration_time = GNUNET_FS_year_to_time (year); | ||
906 | ctx->cb (ctx->cb_cls, | 896 | ctx->cb (ctx->cb_cls, |
907 | gtk_toggle_button_get_active (ctx->index_checkbutton), | 897 | GTK_RESPONSE_OK, |
908 | ctx->short_fn, | 898 | gtk_entry_get_text (ctx->root_entry)); |
909 | &bo, | 899 | /* free resources from the edit dialog */ |
910 | gtk_entry_get_text (ctx->root_entry), | ||
911 | GTK_RESPONSE_OK); | ||
912 | free_edit_dialog_context (ctx); | 900 | free_edit_dialog_context (ctx); |
913 | } | 901 | } |
914 | 902 | ||
915 | 903 | ||
904 | |||
916 | /* ****************** code for initialization of the dialog ******************** */ | 905 | /* ****************** code for initialization of the dialog ******************** */ |
917 | 906 | ||
918 | 907 | ||
908 | |||
919 | /** | 909 | /** |
920 | * Add each of the keywords to the keyword list store. | 910 | * Add each of the keywords to the keyword list store. |
921 | * | 911 | * |
@@ -931,18 +921,20 @@ add_keyword (void *cls, const char *keyword, int is_mandatory) | |||
931 | GtkTreeIter iter; | 921 | GtkTreeIter iter; |
932 | 922 | ||
933 | ls = GTK_LIST_STORE (cls); | 923 | ls = GTK_LIST_STORE (cls); |
934 | gtk_list_store_insert_with_values (ls, &iter, G_MAXINT, 0, keyword, 1, FALSE, | 924 | gtk_list_store_insert_with_values (ls, &iter, G_MAXINT, |
925 | 0, keyword, | ||
926 | 1, FALSE, | ||
935 | -1); | 927 | -1); |
936 | return GNUNET_OK; | 928 | return GNUNET_OK; |
937 | } | 929 | } |
938 | 930 | ||
939 | 931 | ||
940 | /** | 932 | /** |
941 | * Function called to extract the information from FI. | 933 | * Function called to extract the information from FI to populate the edit dialog. |
942 | * | 934 | * |
943 | * @param cls closure | 935 | * @param cls the 'struct EditPublicationDialogContext' |
944 | * @param fi the entry in the publish-structure | 936 | * @param fi the entry in the publish-structure (unused) |
945 | * @param length length of the file or directory | 937 | * @param length length of the file or directory (unused) |
946 | * @param meta metadata for the file or directory (can be modified) | 938 | * @param meta metadata for the file or directory (can be modified) |
947 | * @param uri pointer to the keywords that will be used for this entry (can be modified) | 939 | * @param uri pointer to the keywords that will be used for this entry (can be modified) |
948 | * @param bo block options | 940 | * @param bo block options |
@@ -951,19 +943,34 @@ add_keyword (void *cls, const char *keyword, int is_mandatory) | |||
951 | * @return GNUNET_SYSERR (aborts after first call) | 943 | * @return GNUNET_SYSERR (aborts after first call) |
952 | */ | 944 | */ |
953 | static int | 945 | static int |
954 | file_information_extract (void *cls, struct GNUNET_FS_FileInformation *fi, | 946 | file_information_import (void *cls, |
955 | uint64_t length, | 947 | struct GNUNET_FS_FileInformation *fi, |
956 | struct GNUNET_CONTAINER_MetaData *meta, | 948 | uint64_t length, |
957 | struct GNUNET_FS_Uri **uri, | 949 | struct GNUNET_CONTAINER_MetaData *meta, |
958 | struct GNUNET_FS_BlockOptions *bo, int *do_index, | 950 | struct GNUNET_FS_Uri **uri, |
959 | void **client_info) | 951 | struct GNUNET_FS_BlockOptions *bo, int *do_index, |
952 | void **client_info) | ||
960 | { | 953 | { |
961 | struct EditPublicationDialogContext *ctx = cls; | 954 | struct EditPublicationDialogContext *ctx = cls; |
962 | GdkPixbuf *pixbuf; | 955 | GdkPixbuf *pixbuf; |
956 | char *short_fn; | ||
963 | int year; | 957 | int year; |
964 | 958 | ||
959 | /* import options */ | ||
960 | year = (int) GNUNET_FS_time_to_year (bo->expiration_time); | ||
961 | gtk_spin_button_set_value (ctx->expiration_year_spin, year); | ||
962 | GNUNET_GTK_select_anonymity_combo_level (ctx->anonymity_combo, | ||
963 | bo->anonymity_level); | ||
964 | gtk_spin_button_set_value (ctx->priority_spin, bo->content_priority); | ||
965 | gtk_spin_button_set_value (ctx->replication_spin, bo->replication_level); | ||
966 | gtk_toggle_button_set_active (ctx->index_checkbutton, *do_index); | ||
967 | |||
968 | |||
969 | /* import keywords */ | ||
965 | if (NULL != *uri) | 970 | if (NULL != *uri) |
966 | GNUNET_FS_uri_ksk_get_keywords (*uri, &add_keyword, ctx->keywords_liststore); | 971 | GNUNET_FS_uri_ksk_get_keywords (*uri, &add_keyword, ctx->keywords_liststore); |
972 | |||
973 | /* import meta data */ | ||
967 | if (NULL != meta) | 974 | if (NULL != meta) |
968 | { | 975 | { |
969 | GNUNET_CONTAINER_meta_data_iterate (meta, | 976 | GNUNET_CONTAINER_meta_data_iterate (meta, |
@@ -975,43 +982,41 @@ file_information_extract (void *cls, struct GNUNET_FS_FileInformation *fi, | |||
975 | gtk_image_set_from_pixbuf (ctx->preview_image, pixbuf); | 982 | gtk_image_set_from_pixbuf (ctx->preview_image, pixbuf); |
976 | } | 983 | } |
977 | } | 984 | } |
978 | year = (int) GNUNET_FS_time_to_year (bo->expiration_time); | 985 | |
979 | gtk_spin_button_set_value (ctx->expiration_year_spin, year); | 986 | /* Also update window title based on filename */ |
980 | GNUNET_GTK_select_anonymity_combo_level (ctx->anonymity_combo, | 987 | short_fn = GNUNET_CONTAINER_meta_data_get_first_by_types (meta, |
981 | bo->anonymity_level); | 988 | EXTRACTOR_METATYPE_FILENAME, |
982 | gtk_spin_button_set_value (ctx->priority_spin, bo->content_priority); | 989 | -1); |
983 | gtk_spin_button_set_value (ctx->replication_spin, bo->replication_level); | 990 | if (NULL == short_fn) |
984 | gtk_toggle_button_set_active (ctx->index_checkbutton, *do_index); | 991 | { |
992 | gtk_window_set_title (ctx->edit_publication_window, _("<unnamed>")); | ||
993 | } | ||
994 | else | ||
995 | { | ||
996 | /* FIXME: ensure that short_fn is UTF-8 encoded */ | ||
997 | gtk_window_set_title (ctx->edit_publication_window, short_fn); | ||
998 | GNUNET_free (short_fn); | ||
999 | } | ||
985 | return GNUNET_SYSERR; /* only visit top-level item */ | 1000 | return GNUNET_SYSERR; /* only visit top-level item */ |
986 | } | 1001 | } |
987 | 1002 | ||
988 | 1003 | ||
989 | void | ||
990 | GNUNET_GTK_edit_publication_window_realize_cb (GtkWidget *widget, struct EditPublicationDialogContext *ctx) | ||
991 | { | ||
992 | GtkTreeSelection *meta_selection; | ||
993 | GtkTreeSelection *keywords_selection; | ||
994 | |||
995 | /* FIXME: these can be set by (modern) versions of Glade */ | ||
996 | keywords_selection = gtk_tree_view_get_selection (ctx->keywords_treeview); | ||
997 | meta_selection = gtk_tree_view_get_selection (ctx->meta_treeview); | ||
998 | |||
999 | g_signal_connect (G_OBJECT (keywords_selection), "changed", | ||
1000 | G_CALLBACK (keywords_selection_changed_cb), ctx); | ||
1001 | |||
1002 | g_signal_connect (G_OBJECT (meta_selection), "changed", | ||
1003 | G_CALLBACK (metadata_selection_changed_cb), ctx); | ||
1004 | } | ||
1005 | |||
1006 | /** | 1004 | /** |
1007 | * Open the dialog to edit file information data. | 1005 | * Open the dialog to edit file information data. |
1008 | * short_fn MUST be UTF-8-encoded | 1006 | * |
1007 | * @param parent parent window of the dialog | ||
1008 | * @param fip information about the file information that is to be edited | ||
1009 | * @param allow_no_keywords is it OK to close the dialog without any keywords? | ||
1010 | * also used to indicate that this is a namespace operation | ||
1011 | * (FIXME: overloaded/badly-named argument) | ||
1012 | * @param anon_liststore liststore with anonymity options (FIXME: bad sharing) | ||
1013 | * @param cb function to call when the dialog is closed | ||
1014 | * @param cb_cls closure for 'cb' | ||
1009 | */ | 1015 | */ |
1010 | void | 1016 | void |
1011 | GNUNET_FS_GTK_edit_publish_dialog (GtkWindow * parent, | 1017 | GNUNET_FS_GTK_edit_publish_dialog (GtkWindow * parent, |
1012 | const char *short_fn, | ||
1013 | struct GNUNET_FS_FileInformation *fip, | 1018 | struct GNUNET_FS_FileInformation *fip, |
1014 | gboolean allow_no_keywords, | 1019 | int allow_no_keywords, |
1015 | GtkListStore *anon_liststore, | 1020 | GtkListStore *anon_liststore, |
1016 | GNUNET_FS_GTK_EditPublishDialogCallback cb, | 1021 | GNUNET_FS_GTK_EditPublishDialogCallback cb, |
1017 | gpointer cb_cls) | 1022 | gpointer cb_cls) |
@@ -1022,8 +1027,17 @@ GNUNET_FS_GTK_edit_publish_dialog (GtkWindow * parent, | |||
1022 | GtkLabel *index_label; | 1027 | GtkLabel *index_label; |
1023 | GtkLabel *root_label; | 1028 | GtkLabel *root_label; |
1024 | struct EditPublicationDialogContext *ctx; | 1029 | struct EditPublicationDialogContext *ctx; |
1030 | GtkTreeSelection *meta_selection; | ||
1031 | GtkTreeSelection *keywords_selection; | ||
1025 | 1032 | ||
1026 | ctx = GNUNET_malloc (sizeof (struct EditPublicationDialogContext)); | 1033 | ctx = GNUNET_malloc (sizeof (struct EditPublicationDialogContext)); |
1034 | ctx->fip = fip; | ||
1035 | ctx->preview_changed = GNUNET_NO; | ||
1036 | ctx->allow_no_keywords = allow_no_keywords; | ||
1037 | ctx->is_directory = GNUNET_FS_file_information_is_directory (fip); | ||
1038 | ctx->cb = cb; | ||
1039 | ctx->cb_cls = cb_cls; | ||
1040 | ctx->meta_combo_selected_type_id = -1; | ||
1027 | ctx->builder = GNUNET_GTK_get_new_builder ("gnunet_fs_gtk_edit_publication.glade", ctx); | 1041 | ctx->builder = GNUNET_GTK_get_new_builder ("gnunet_fs_gtk_edit_publication.glade", ctx); |
1028 | 1042 | ||
1029 | if (ctx->builder == NULL) | 1043 | if (ctx->builder == NULL) |
@@ -1031,7 +1045,8 @@ GNUNET_FS_GTK_edit_publish_dialog (GtkWindow * parent, | |||
1031 | GNUNET_free (ctx); | 1045 | GNUNET_free (ctx); |
1032 | return; | 1046 | return; |
1033 | } | 1047 | } |
1034 | ctx->meta_combo_selected_type_id = -1; | 1048 | |
1049 | /* obtain various widgets for use later */ | ||
1035 | ctx->pubtypes_liststore = | 1050 | ctx->pubtypes_liststore = |
1036 | GTK_LIST_STORE (gtk_builder_get_object | 1051 | GTK_LIST_STORE (gtk_builder_get_object |
1037 | (ctx->builder, "GNUNET_GTK_publication_types_liststore")); | 1052 | (ctx->builder, "GNUNET_GTK_publication_types_liststore")); |
@@ -1046,7 +1061,8 @@ GNUNET_FS_GTK_edit_publish_dialog (GtkWindow * parent, | |||
1046 | (ctx->builder, | 1061 | (ctx->builder, |
1047 | "GNUNET_GTK_edit_publication_keyword_list_tree_view")); | 1062 | "GNUNET_GTK_edit_publication_keyword_list_tree_view")); |
1048 | ctx->edit_publication_window = | 1063 | ctx->edit_publication_window = |
1049 | GTK_WINDOW (gtk_builder_get_object (ctx->builder, "GNUNET_GTK_edit_publication_window")); | 1064 | GTK_WINDOW (gtk_builder_get_object (ctx->builder, |
1065 | "GNUNET_GTK_edit_publication_window")); | ||
1050 | ctx->keywords_liststore = GTK_LIST_STORE (gtk_builder_get_object | 1066 | ctx->keywords_liststore = GTK_LIST_STORE (gtk_builder_get_object |
1051 | (ctx->builder, "GNUNET_GTK_publication_keywords_liststore")); | 1067 | (ctx->builder, "GNUNET_GTK_publication_keywords_liststore")); |
1052 | ctx->keyword_entry = | 1068 | ctx->keyword_entry = |
@@ -1061,11 +1077,8 @@ GNUNET_FS_GTK_edit_publish_dialog (GtkWindow * parent, | |||
1061 | ctx->meta_liststore = GTK_LIST_STORE (gtk_builder_get_object | 1077 | ctx->meta_liststore = GTK_LIST_STORE (gtk_builder_get_object |
1062 | (ctx->builder, | 1078 | (ctx->builder, |
1063 | "GNUNET_GTK_publication_metadata_liststore")); | 1079 | "GNUNET_GTK_publication_metadata_liststore")); |
1064 | |||
1065 | ctx->root_entry = GTK_ENTRY (gtk_builder_get_object | 1080 | ctx->root_entry = GTK_ENTRY (gtk_builder_get_object |
1066 | (ctx->builder, "GNUNET_GTK_edit_publication_root_entry")); | 1081 | (ctx->builder, "GNUNET_GTK_edit_publication_root_entry")); |
1067 | |||
1068 | |||
1069 | ctx->expiration_year_spin = GTK_SPIN_BUTTON | 1082 | ctx->expiration_year_spin = GTK_SPIN_BUTTON |
1070 | (gtk_builder_get_object | 1083 | (gtk_builder_get_object |
1071 | (ctx->builder, | 1084 | (ctx->builder, |
@@ -1083,32 +1096,17 @@ GNUNET_FS_GTK_edit_publish_dialog (GtkWindow * parent, | |||
1083 | (ctx->builder, | 1096 | (ctx->builder, |
1084 | "GNUNET_GTK_edit_publication_index_checkbutton")); | 1097 | "GNUNET_GTK_edit_publication_index_checkbutton")); |
1085 | ctx->anonymity_combo = GTK_COMBO_BOX (gtk_builder_get_object (ctx->builder, | 1098 | ctx->anonymity_combo = GTK_COMBO_BOX (gtk_builder_get_object (ctx->builder, |
1086 | "GNUNET_GTK_edit_publication_anonymity_combobox")); | 1099 | "GNUNET_GTK_edit_publication_anonymity_combobox")); |
1087 | gtk_combo_box_set_model (ctx->anonymity_combo, GTK_TREE_MODEL (anon_liststore)); | ||
1088 | ctx->anonymity_liststore = anon_liststore; | ||
1089 | 1100 | ||
1101 | /* Basic initialization of widgets models and visibility */ | ||
1102 | gtk_combo_box_set_model (ctx->anonymity_combo, | ||
1103 | GTK_TREE_MODEL (anon_liststore)); | ||
1090 | GNUNET_FS_GTK_setup_expiration_year_adjustment (ctx->builder); | 1104 | GNUNET_FS_GTK_setup_expiration_year_adjustment (ctx->builder); |
1091 | /* indexing does not apply to directories */ | ||
1092 | gtk_widget_set_visible (GTK_WIDGET (ctx->index_checkbutton), | ||
1093 | !GNUNET_FS_file_information_is_directory (fip)); | ||
1094 | index_label = GTK_LABEL (gtk_builder_get_object | ||
1095 | (ctx->builder, "GNUNET_GTK_edit_publication_index_label")); | ||
1096 | gtk_widget_set_visible (GTK_WIDGET (index_label), | ||
1097 | !GNUNET_FS_file_information_is_directory (fip)); | ||
1098 | gtk_widget_set_visible (GTK_WIDGET (ctx->root_entry), | ||
1099 | !allow_no_keywords); | ||
1100 | root_label = GTK_LABEL (gtk_builder_get_object | ||
1101 | (ctx->builder, "GNUNET_GTK_edit_publication_root_label")); | ||
1102 | gtk_widget_set_visible (GTK_WIDGET (root_label), | ||
1103 | !allow_no_keywords); | ||
1104 | 1105 | ||
1106 | /* FIXME-UNCLEAN: are the following three even required anymore? */ | ||
1105 | gtk_list_store_clear (ctx->keywords_liststore); | 1107 | gtk_list_store_clear (ctx->keywords_liststore); |
1106 | gtk_list_store_clear (ctx->meta_liststore); | 1108 | gtk_list_store_clear (ctx->meta_liststore); |
1107 | 1109 | gtk_entry_set_text (ctx->keyword_entry, ""); | |
1108 | if (NULL != short_fn) | ||
1109 | gtk_window_set_title (ctx->edit_publication_window, short_fn); | ||
1110 | else | ||
1111 | gtk_window_set_title (ctx->edit_publication_window, _("<unnamed>")); | ||
1112 | 1110 | ||
1113 | pubtypes_combo = | 1111 | pubtypes_combo = |
1114 | GTK_COMBO_BOX (gtk_builder_get_object | 1112 | GTK_COMBO_BOX (gtk_builder_get_object |
@@ -1121,19 +1119,42 @@ GNUNET_FS_GTK_edit_publish_dialog (GtkWindow * parent, | |||
1121 | else | 1119 | else |
1122 | gtk_combo_box_set_active (pubtypes_combo, 0); | 1120 | gtk_combo_box_set_active (pubtypes_combo, 0); |
1123 | 1121 | ||
1124 | if (NULL != short_fn) | 1122 | /* indexing does not apply to directories */ |
1125 | ctx->short_fn = GNUNET_strdup (short_fn); | 1123 | gtk_widget_set_visible (GTK_WIDGET (ctx->index_checkbutton), |
1126 | ctx->fip = fip; | 1124 | ! ctx->is_directory); |
1127 | ctx->preview_changed = GNUNET_NO; | 1125 | index_label = GTK_LABEL (gtk_builder_get_object |
1128 | ctx->allow_no_keywords = allow_no_keywords; | 1126 | (ctx->builder, |
1129 | ctx->is_directory = GNUNET_FS_file_information_is_directory (fip); | 1127 | "GNUNET_GTK_edit_publication_index_label")); |
1130 | ctx->cb = cb; | 1128 | gtk_widget_set_visible (GTK_WIDGET (index_label), |
1131 | ctx->cb_cls = cb_cls; | 1129 | ! ctx->is_directory); |
1132 | |||
1133 | GNUNET_FS_file_information_inspect (fip, &file_information_extract, ctx); | ||
1134 | 1130 | ||
1135 | gtk_entry_set_text (ctx->keyword_entry, ""); | 1131 | /* show root label only if we must have keywords, which is also only the |
1132 | case for namespaces (FIXME-UNCLEAN: overloaded use of the argument) */ | ||
1133 | gtk_widget_set_visible (GTK_WIDGET (ctx->root_entry), | ||
1134 | !allow_no_keywords); | ||
1135 | root_label = GTK_LABEL (gtk_builder_get_object | ||
1136 | (ctx->builder, "GNUNET_GTK_edit_publication_root_label")); | ||
1137 | gtk_widget_set_visible (GTK_WIDGET (root_label), | ||
1138 | !allow_no_keywords); | ||
1139 | |||
1140 | /* FIXME-UNCLEAN: what if we already have keywords? Again, does not really | ||
1141 | apply to namespace-case, but this seems a bit ugly */ | ||
1136 | gtk_widget_set_sensitive (ctx->confirm_button, allow_no_keywords ? TRUE : FALSE); | 1142 | gtk_widget_set_sensitive (ctx->confirm_button, allow_no_keywords ? TRUE : FALSE); |
1143 | |||
1144 | |||
1145 | /* FIXME: these signal handlers can be set by (modern) versions of Glade */ | ||
1146 | keywords_selection = gtk_tree_view_get_selection (ctx->keywords_treeview); | ||
1147 | g_signal_connect (G_OBJECT (keywords_selection), "changed", | ||
1148 | G_CALLBACK (keywords_selection_changed_cb), ctx); | ||
1149 | meta_selection = gtk_tree_view_get_selection (ctx->meta_treeview); | ||
1150 | g_signal_connect (G_OBJECT (meta_selection), "changed", | ||
1151 | G_CALLBACK (metadata_selection_changed_cb), ctx); | ||
1152 | |||
1153 | /* import meta data and options */ | ||
1154 | GNUNET_FS_file_information_inspect (fip, &file_information_import, ctx); | ||
1155 | |||
1156 | |||
1157 | /* Finally, display window */ | ||
1137 | gtk_window_set_transient_for (ctx->edit_publication_window, parent); | 1158 | gtk_window_set_transient_for (ctx->edit_publication_window, parent); |
1138 | gtk_window_present (ctx->edit_publication_window); | 1159 | gtk_window_present (ctx->edit_publication_window); |
1139 | } | 1160 | } |