diff options
Diffstat (limited to 'src/main_window_file_publish.c')
-rw-r--r-- | src/main_window_file_publish.c | 194 |
1 files changed, 183 insertions, 11 deletions
diff --git a/src/main_window_file_publish.c b/src/main_window_file_publish.c index 58352b77..96fcec38 100644 --- a/src/main_window_file_publish.c +++ b/src/main_window_file_publish.c | |||
@@ -66,6 +66,7 @@ update_selectivity () | |||
66 | { | 66 | { |
67 | GtkTreeView *tv; | 67 | GtkTreeView *tv; |
68 | GtkTreeModel *tm; | 68 | GtkTreeModel *tm; |
69 | GtkTreeModel *ptm; | ||
69 | GtkTreeSelection *sel; | 70 | GtkTreeSelection *sel; |
70 | GtkTreeIter iter; | 71 | GtkTreeIter iter; |
71 | GtkTreeIter parent; | 72 | GtkTreeIter parent; |
@@ -79,7 +80,27 @@ update_selectivity () | |||
79 | GtkWidget *execute_button; | 80 | GtkWidget *execute_button; |
80 | int is_dir; | 81 | int is_dir; |
81 | struct GNUNET_FS_FileInformation *fip; | 82 | struct GNUNET_FS_FileInformation *fip; |
82 | 83 | int ns_ok; | |
84 | char *namespace_id; | ||
85 | |||
86 | tm = GTK_TREE_MODEL (gtk_builder_get_object (master_builder, | ||
87 | "GNUNET_GTK_file_sharing_publishing_tree_store")); | ||
88 | tv = GTK_TREE_VIEW (gtk_builder_get_object (master_builder, | ||
89 | "GNUNET_GTK_master_publish_dialog_pseudonym_tree_view")); | ||
90 | sel = gtk_tree_view_get_selection (tv); | ||
91 | ns_ok = GNUNET_YES; | ||
92 | if (TRUE == gtk_tree_selection_get_selected (sel, &ptm, &iter)) | ||
93 | { | ||
94 | gtk_tree_model_get (ptm, | ||
95 | &iter, | ||
96 | 2, &namespace_id, | ||
97 | -1); | ||
98 | if (namespace_id == NULL) | ||
99 | { | ||
100 | ns_ok = GNUNET_NO; | ||
101 | GNUNET_free (namespace_id); | ||
102 | } | ||
103 | } | ||
83 | up_button = GTK_WIDGET (gtk_builder_get_object (master_builder, | 104 | up_button = GTK_WIDGET (gtk_builder_get_object (master_builder, |
84 | "GNUNET_GTK_master_publish_dialog_up_button")); | 105 | "GNUNET_GTK_master_publish_dialog_up_button")); |
85 | down_button = GTK_WIDGET (gtk_builder_get_object (master_builder, | 106 | down_button = GTK_WIDGET (gtk_builder_get_object (master_builder, |
@@ -98,7 +119,8 @@ update_selectivity () | |||
98 | "GNUNET_GTK_master_publish_dialog_file_information_tree_view")); | 119 | "GNUNET_GTK_master_publish_dialog_file_information_tree_view")); |
99 | sel = gtk_tree_view_get_selection (tv); | 120 | sel = gtk_tree_view_get_selection (tv); |
100 | tm = gtk_tree_view_get_model (tv); | 121 | tm = gtk_tree_view_get_model (tv); |
101 | if (gtk_tree_model_get_iter_first (tm, &iter)) | 122 | if ( (gtk_tree_model_get_iter_first (tm, &iter)) && |
123 | (ns_ok == GNUNET_YES) ) | ||
102 | gtk_widget_set_sensitive (execute_button, TRUE); | 124 | gtk_widget_set_sensitive (execute_button, TRUE); |
103 | else | 125 | else |
104 | gtk_widget_set_sensitive (execute_button, FALSE); | 126 | gtk_widget_set_sensitive (execute_button, FALSE); |
@@ -526,6 +548,59 @@ move_entry (GtkTreeModel *tm, | |||
526 | update_selectivity (); | 548 | update_selectivity (); |
527 | } | 549 | } |
528 | 550 | ||
551 | /** | ||
552 | * User has changed the "current" identifier for the content in | ||
553 | * the GtkTreeView. Update the model. | ||
554 | */ | ||
555 | void | ||
556 | GNUNET_GTK_master_publish_dialog_pseudonym_updates_renderer_edited_cb (GtkCellRendererText *renderer, | ||
557 | gchar *cpath, | ||
558 | gchar *new_text, | ||
559 | gpointer user_data) | ||
560 | { | ||
561 | GtkTreeIter iter; | ||
562 | GtkTreeStore *ts; | ||
563 | |||
564 | ts = GTK_TREE_STORE (gtk_builder_get_object (master_builder, | ||
565 | "GNUNET_GTK_pseudonym_tree_store")); | ||
566 | |||
567 | if (TRUE != | ||
568 | gtk_tree_model_get_iter_from_string (GTK_TREE_MODEL (ts), &iter, cpath)) | ||
569 | { | ||
570 | GNUNET_break (0); | ||
571 | return; | ||
572 | } | ||
573 | gtk_tree_store_set (ts, &iter, 5, new_text, -1); | ||
574 | update_selectivity (); | ||
575 | } | ||
576 | |||
577 | |||
578 | /** | ||
579 | * User has changed the "current" identifier for the content in | ||
580 | * the GtkTreeView. Update the model. | ||
581 | */ | ||
582 | void | ||
583 | GNUNET_GTK_master_publish_dialog_pseudonym_identifier_renderer_edited_cb (GtkCellRendererText *renderer, | ||
584 | gchar *cpath, | ||
585 | gchar *new_text, | ||
586 | gpointer user_data) | ||
587 | { | ||
588 | GtkTreeIter iter; | ||
589 | GtkTreeStore *ts; | ||
590 | |||
591 | ts = GTK_TREE_STORE (gtk_builder_get_object (master_builder, | ||
592 | "GNUNET_GTK_pseudonym_tree_store")); | ||
593 | |||
594 | if (TRUE != | ||
595 | gtk_tree_model_get_iter_from_string (GTK_TREE_MODEL (ts), &iter, cpath)) | ||
596 | { | ||
597 | GNUNET_break (0); | ||
598 | return; | ||
599 | } | ||
600 | gtk_tree_store_set (ts, &iter, 2, new_text, -1); | ||
601 | update_selectivity (); | ||
602 | } | ||
603 | |||
529 | 604 | ||
530 | void | 605 | void |
531 | GNUNET_GTK_master_publish_dialog_right_button_clicked_cb (GtkWidget * dummy, | 606 | GNUNET_GTK_master_publish_dialog_right_button_clicked_cb (GtkWidget * dummy, |
@@ -640,7 +715,7 @@ GNUNET_GTK_master_publish_dialog_up_button_clicked_cb (GtkWidget * dummy, | |||
640 | if (TRUE != gtk_tree_selection_get_selected (sel, | 715 | if (TRUE != gtk_tree_selection_get_selected (sel, |
641 | &tm, | 716 | &tm, |
642 | &iter)) | 717 | &iter)) |
643 | { | 718 | { |
644 | GNUNET_break (0); | 719 | GNUNET_break (0); |
645 | return; | 720 | return; |
646 | } | 721 | } |
@@ -1055,6 +1130,77 @@ get_file_information (GtkTreeModel *tm, | |||
1055 | } | 1130 | } |
1056 | 1131 | ||
1057 | 1132 | ||
1133 | struct UpdateableContext | ||
1134 | { | ||
1135 | GtkTreeIter parent; | ||
1136 | GtkTreeStore *ts; | ||
1137 | const char *namespace_name; | ||
1138 | struct GNUNET_FS_Namespace *ns; | ||
1139 | }; | ||
1140 | |||
1141 | |||
1142 | static void | ||
1143 | add_updateable_to_ts (void *cls, | ||
1144 | const char *last_id, | ||
1145 | const struct GNUNET_FS_Uri *last_uri, | ||
1146 | const struct GNUNET_CONTAINER_MetaData *last_meta, | ||
1147 | const char *next_id) | ||
1148 | { | ||
1149 | struct UpdateableContext *uc = cls; | ||
1150 | GtkTreeIter iter; | ||
1151 | char *desc; | ||
1152 | |||
1153 | desc = GNUNET_CONTAINER_meta_data_get_by_type (last_meta, | ||
1154 | EXTRACTOR_METATYPE_DESCRIPTION); | ||
1155 | gtk_tree_store_insert_with_values (uc->ts, | ||
1156 | &iter, | ||
1157 | &uc->parent, | ||
1158 | G_MAXINT, | ||
1159 | 0, uc->namespace_name, | ||
1160 | 1, uc->ns, | ||
1161 | 2, last_id, | ||
1162 | 3, GNUNET_FS_uri_dup (last_uri), | ||
1163 | 4, GNUNET_CONTAINER_meta_data_duplicate (last_meta), | ||
1164 | 5, next_id, | ||
1165 | 6, desc, | ||
1166 | 7, FALSE /* current not editable (only for top-level) */, | ||
1167 | 8, TRUE /* update editable (always) */, | ||
1168 | -1); | ||
1169 | GNUNET_free_non_null (desc); | ||
1170 | } | ||
1171 | |||
1172 | |||
1173 | static void | ||
1174 | add_namespace_to_ts (void *cls, | ||
1175 | const char *name, | ||
1176 | const GNUNET_HashCode *id) | ||
1177 | { | ||
1178 | GtkTreeStore *ts = cls; | ||
1179 | struct UpdateableContext uc; | ||
1180 | |||
1181 | uc.namespace_name = name; | ||
1182 | uc.ts = ts; | ||
1183 | uc.ns = GNUNET_FS_namespace_create (GNUNET_GTK_get_fs_handle (), | ||
1184 | name); | ||
1185 | gtk_tree_store_insert_with_values (ts, &uc.parent, | ||
1186 | NULL, | ||
1187 | G_MAXINT, | ||
1188 | 0, name, | ||
1189 | 1, uc.ns, | ||
1190 | 2, NULL /* last-id */, | ||
1191 | 3, NULL /* last-uri */, | ||
1192 | 4, NULL /* meta */, | ||
1193 | 5, NULL /* next-ID */, | ||
1194 | 6, NULL /* last-description */, | ||
1195 | 7, TRUE /* current editable */, | ||
1196 | 8, TRUE /* update editable */, | ||
1197 | -1); | ||
1198 | /* FIXME: maybe we want to build the real tree here? | ||
1199 | => FS API should be different... */ | ||
1200 | GNUNET_FS_namespace_list_updateable (uc.ns, &add_updateable_to_ts, &uc); | ||
1201 | } | ||
1202 | |||
1203 | |||
1058 | /** | 1204 | /** |
1059 | */ | 1205 | */ |
1060 | void | 1206 | void |
@@ -1062,13 +1208,17 @@ GNUNET_GTK_main_menu_file_publish_activate_cb (GtkWidget * dummy, | |||
1062 | gpointer data) | 1208 | gpointer data) |
1063 | { | 1209 | { |
1064 | GtkWidget *ad; | 1210 | GtkWidget *ad; |
1065 | GtkTreeStore *ls; | 1211 | GtkTreeStore *ts; |
1066 | gint ret; | 1212 | gint ret; |
1067 | GtkTreeView *tv; | 1213 | GtkTreeView *tv; |
1068 | GtkTreeSelection *sel; | 1214 | GtkTreeSelection *sel; |
1069 | GtkTreeIter iter; | 1215 | GtkTreeIter iter; |
1070 | struct GNUNET_FS_FileInformation *fi; | 1216 | struct GNUNET_FS_FileInformation *fi; |
1071 | GtkTreeModel *tm; | 1217 | GtkTreeModel *tm; |
1218 | GtkTreeModel *ptm; | ||
1219 | struct GNUNET_FS_Namespace *namespace; | ||
1220 | char *namespace_id; | ||
1221 | char *namespace_uid; | ||
1072 | 1222 | ||
1073 | GNUNET_assert (master_builder == NULL); | 1223 | GNUNET_assert (master_builder == NULL); |
1074 | master_builder = GNUNET_GTK_get_new_builder ("publish_dialog.glade"); | 1224 | master_builder = GNUNET_GTK_get_new_builder ("publish_dialog.glade"); |
@@ -1081,29 +1231,51 @@ GNUNET_GTK_main_menu_file_publish_activate_cb (GtkWidget * dummy, | |||
1081 | G_CALLBACK(selection_changed_cb), NULL); | 1231 | G_CALLBACK(selection_changed_cb), NULL); |
1082 | ad = GTK_WIDGET (gtk_builder_get_object (master_builder, | 1232 | ad = GTK_WIDGET (gtk_builder_get_object (master_builder, |
1083 | "GNUNET_GTK_master_publish_dialog")); | 1233 | "GNUNET_GTK_master_publish_dialog")); |
1084 | ls = GTK_TREE_STORE (gtk_builder_get_object (master_builder, | 1234 | ts = GTK_TREE_STORE (gtk_builder_get_object (master_builder, |
1085 | "GNUNET_GTK_pseudonym_tree_store")); | 1235 | "GNUNET_GTK_pseudonym_tree_store")); |
1086 | /* FIXME: populate 'ls' */ | 1236 | GNUNET_FS_namespace_list (GNUNET_GTK_get_fs_handle (), |
1237 | &add_namespace_to_ts, | ||
1238 | ts); | ||
1087 | ret = gtk_dialog_run (GTK_DIALOG (ad)); | 1239 | ret = gtk_dialog_run (GTK_DIALOG (ad)); |
1088 | if (ret == GTK_RESPONSE_OK) | 1240 | if (ret == GTK_RESPONSE_OK) |
1089 | { | 1241 | { |
1090 | /* FIXME: grab namespace from ls! */ | ||
1091 | tm = GTK_TREE_MODEL (gtk_builder_get_object (master_builder, | 1242 | tm = GTK_TREE_MODEL (gtk_builder_get_object (master_builder, |
1092 | "GNUNET_GTK_file_sharing_publishing_tree_store")); | 1243 | "GNUNET_GTK_file_sharing_publishing_tree_store")); |
1244 | tv = GTK_TREE_VIEW (gtk_builder_get_object (master_builder, | ||
1245 | "GNUNET_GTK_master_publish_dialog_pseudonym_tree_view")); | ||
1246 | sel = gtk_tree_view_get_selection (tv); | ||
1247 | if (TRUE == gtk_tree_selection_get_selected (sel, &ptm, &iter)) | ||
1248 | { | ||
1249 | gtk_tree_model_get (ptm, | ||
1250 | &iter, | ||
1251 | 1, &namespace, | ||
1252 | 2, &namespace_id, | ||
1253 | 5, &namespace_uid, | ||
1254 | -1); | ||
1255 | } | ||
1256 | else | ||
1257 | { | ||
1258 | namespace = NULL; | ||
1259 | namespace_id = NULL; | ||
1260 | namespace_uid = NULL; | ||
1261 | } | ||
1093 | if (gtk_tree_model_get_iter_first (tm, &iter)) | 1262 | if (gtk_tree_model_get_iter_first (tm, &iter)) |
1094 | do | 1263 | do |
1095 | { | 1264 | { |
1096 | fi = get_file_information (tm, &iter); | 1265 | fi = get_file_information (tm, &iter); |
1097 | GNUNET_FS_publish_start (GNUNET_GTK_get_fs_handle (), | 1266 | GNUNET_FS_publish_start (GNUNET_GTK_get_fs_handle (), |
1098 | fi, | 1267 | fi, |
1099 | NULL /* FIXME: namespace */, | 1268 | namespace, |
1100 | NULL /* FIXME: namespace id */, | 1269 | namespace_id, |
1101 | NULL /* FIXME: namespace uid */, | 1270 | namespace_uid, |
1102 | GNUNET_FS_PUBLISH_OPTION_NONE); | 1271 | GNUNET_FS_PUBLISH_OPTION_NONE); |
1103 | } | 1272 | } |
1104 | while (gtk_tree_model_iter_next (tm, &iter)); | 1273 | while (gtk_tree_model_iter_next (tm, &iter)); |
1105 | } | 1274 | GNUNET_free_non_null (namespace_uid); |
1275 | GNUNET_free_non_null (namespace_id); | ||
1276 | } | ||
1106 | /* FIXME: free state from 'ls' */ | 1277 | /* FIXME: free state from 'ls' */ |
1278 | /* FIXME: free state from 'tm' */ | ||
1107 | gtk_widget_destroy (ad); | 1279 | gtk_widget_destroy (ad); |
1108 | g_object_unref (G_OBJECT (master_builder)); | 1280 | g_object_unref (G_OBJECT (master_builder)); |
1109 | master_builder = NULL; | 1281 | master_builder = NULL; |