/* This file is part of GNUnet (C) 2005, 2006, 2010 Christian Grothoff (and other contributing authors) GNUnet is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. GNUnet is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with GNUnet; see the file COPYING. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /** * @file src/fs/gnunet-fs-gtk-main_window_adv_pseudonym.c * @author Christian Grothoff */ #include "gnunet-fs-gtk-common.h" #include "gnunet-fs-gtk.h" #include "gnunet-fs-gtk-edit_publish_dialog.h" /** * Callback with information about local (!) namespaces. * Contains the names of the local namespace and the global * ID. Adds the to the list store. * * @param cls closure, the list store. * @param name human-readable identifier of the namespace * @param id hash identifier for the namespace */ static void add_to_list (void *cls, const char *name, const GNUNET_HashCode * id) { GtkListStore *ls = cls; GtkTreeIter iter; gtk_list_store_insert_with_values (ls, &iter, -1, 0, name, 1, GNUNET_FS_namespace_create (GNUNET_FS_GTK_get_fs_handle (), name), -1); } static void selection_changed_cb (GtkTreeSelection * ts, gpointer user_data) { GtkTreeIter iter; GtkWidget *ok_button; GtkBuilder *builder; builder = GTK_BUILDER (user_data); ok_button = GTK_WIDGET (gtk_builder_get_object (builder, "GNUNET_GTK_select_pseudonym_ok_button")); if (TRUE == gtk_tree_selection_get_selected (ts, NULL, &iter)) gtk_widget_set_sensitive (ok_button, TRUE); else gtk_widget_set_sensitive (ok_button, FALSE); } struct namespace_data_struct { struct GNUNET_FS_Namespace *ns; int do_index; char *short_fn; guint anonymity_level; guint priority; gchar *root; }; /** * Function called on entries in a GNUNET_FS_FileInformation publish-structure. * * @param cls closure * @param fi the entry in the publish-structure * @param length length of the file or directory * @param meta metadata for the file or directory (can be modified) * @param uri pointer to the keywords that will be used for this entry (can be modified) * @param bo block options (can be modified) * @param do_index should we index (can be modified) * @param client_info pointer to client context set upon creation (can be modified) * @return GNUNET_OK to continue, GNUNET_NO to remove * this entry from the directory, GNUNET_SYSERR * to abort the iteration */ int advertise_namespace (void *cls, struct GNUNET_FS_FileInformation *fi, uint64_t length, struct GNUNET_CONTAINER_MetaData *meta, struct GNUNET_FS_Uri **uri, struct GNUNET_FS_BlockOptions *bo, int *do_index, void **client_info) { struct namespace_data_struct *nds; nds = (struct namespace_data_struct *) cls; GNUNET_FS_namespace_advertise (GNUNET_FS_GTK_get_fs_handle (), *uri, nds->ns, meta, bo, nds->root, NULL, NULL); return GNUNET_SYSERR; } void adv_pseudonym_edit_publish_dialog_cb (gpointer cls, int *do_index, char **short_fn, guint * anonymity_level, guint * priority, gchar *root, struct GNUNET_FS_FileInformation *fip, gint ret) { struct namespace_data_struct *nds; nds = (struct namespace_data_struct *) cls; if (ret == GTK_RESPONSE_OK) { nds->do_index = *do_index; nds->short_fn = *short_fn; nds->anonymity_level = *anonymity_level; nds->priority = *priority; nds->root = root; GNUNET_FS_file_information_inspect (fip, advertise_namespace, nds); } g_free (nds->root); GNUNET_FS_namespace_delete (nds->ns, GNUNET_NO); g_free (nds); GNUNET_FS_file_information_destroy (fip, NULL, NULL); } void GNUNET_GTK_select_pseudonym_dialog_response_cb (GtkDialog *dialog, gint response_id, gpointer user_data) { GtkBuilder *builder; GtkWidget *ad; GtkTreeView *tv; GtkTreeSelection *sel; GtkTreeModel *tm; GtkTreeIter iter; struct GNUNET_FS_Namespace *ns; struct GNUNET_FS_Namespace *nso; GtkWindow *transient; struct namespace_data_struct *nds; struct GNUNET_FS_FileInformation *fip; struct GNUNET_CONTAINER_MetaData *meta; builder = GTK_BUILDER (user_data); struct GNUNET_FS_BlockOptions bo; ad = GTK_WIDGET (gtk_builder_get_object (builder, "GNUNET_GTK_select_pseudonym_dialog")); if (response_id != -5) { gtk_widget_hide (ad); return; } tv = GTK_TREE_VIEW (gtk_builder_get_object (builder, "GNUNET_GTK_select_pseudonym_tree_view")); sel = gtk_tree_view_get_selection (tv); GNUNET_assert (TRUE == gtk_tree_selection_get_selected (sel, &tm, &iter)); gtk_tree_model_get (tm, &iter, 1, &ns, -1); /* free all namespaces from list store except "ns" */ if (TRUE == gtk_tree_model_get_iter_first (tm, &iter)) { do { gtk_tree_model_get (tm, &iter, 1, &nso, -1); if (ns != nso) GNUNET_FS_namespace_delete (nso, GNUNET_NO); } while (TRUE == gtk_tree_model_iter_next (tm, &iter)); } transient = gtk_window_get_transient_for (GTK_WINDOW (ad)); gtk_widget_hide (ad); meta = GNUNET_CONTAINER_meta_data_create (); nds = g_new0 (struct namespace_data_struct, 1); nds->ns = ns; nds->do_index = FALSE; nds->short_fn = NULL; nds->anonymity_level = 1; nds->priority = 1000; nds->root = NULL; /* This is a bogus fileinfo. It's needed because edit_publish_dialog * was written to work with fileinfo, and return a fileinfo. */ memset (&bo, 0, sizeof (bo)); fip = GNUNET_FS_file_information_create_empty_directory (NULL, NULL, NULL, meta, &bo); GNUNET_CONTAINER_meta_data_destroy (meta); GNUNET_FS_GTK_edit_publish_dialog (builder, transient, &nds->do_index, &nds->short_fn, &nds->anonymity_level, &nds->priority, fip, FALSE, &adv_pseudonym_edit_publish_dialog_cb, nds); } void GNUNET_GTK_select_pseudonym_dialog_realize_cb (GtkWidget *widget, gpointer user_data) { GtkTreeView *tv; GtkTreeSelection *sel; GtkBuilder *builder; builder = GTK_BUILDER (user_data); tv = GTK_TREE_VIEW (gtk_builder_get_object (builder, "GNUNET_GTK_select_pseudonym_tree_view")); sel = gtk_tree_view_get_selection (tv); g_signal_connect (G_OBJECT (sel), "changed", G_CALLBACK (selection_changed_cb), user_data); } /** * Advertise pseudonym selected. */ void GNUNET_GTK_main_menu_file_advertise_pseudonym_activate_cb (GtkWidget * dummy, gpointer data) { GtkWidget *ad; GtkListStore *ls; GtkWidget *toplevel; GtkBuilder *builder; builder = GTK_BUILDER (data); ad = GTK_WIDGET (gtk_builder_get_object (builder, "GNUNET_GTK_select_pseudonym_dialog")); ls = GTK_LIST_STORE (gtk_builder_get_object (builder, "GNUNET_GTK_select_pseudonym_liststore")); gtk_list_store_clear (ls); GNUNET_FS_namespace_list (GNUNET_FS_GTK_get_fs_handle (), &add_to_list, ls); toplevel = gtk_widget_get_toplevel (dummy); if (GTK_IS_WINDOW (toplevel)) gtk_window_set_transient_for (GTK_WINDOW (ad), GTK_WINDOW (toplevel)); gtk_window_present (GTK_WINDOW (ad)); } /* end of gnunet-fs-gtk-main_window_adv_pseudonym.c */