aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2013-08-08 21:40:39 +0000
committerChristian Grothoff <christian@grothoff.org>2013-08-08 21:40:39 +0000
commitac493b4f502987343bae691996a89635d4a5a58e (patch)
treee63d392cda55b7fcbdbd8ddb4bb134297f8f3993
parent2546dce5d056e496e004d6d615d6757435e95353 (diff)
downloadgnunet-gtk-ac493b4f502987343bae691996a89635d4a5a58e.tar.gz
gnunet-gtk-ac493b4f502987343bae691996a89635d4a5a58e.zip
-working on identity service create/rename/delete
-rw-r--r--src/identity/gnunet-identity-gtk.c111
-rw-r--r--src/identity/gnunet-identity-gtk_create_ego.c123
2 files changed, 111 insertions, 123 deletions
diff --git a/src/identity/gnunet-identity-gtk.c b/src/identity/gnunet-identity-gtk.c
index 7c9f24bd..6b87e812 100644
--- a/src/identity/gnunet-identity-gtk.c
+++ b/src/identity/gnunet-identity-gtk.c
@@ -72,6 +72,111 @@ static GtkListStore *ls;
72 72
73 73
74/** 74/**
75 * We need to track active operations with the identity service.
76 */
77struct OperationContext
78{
79
80 /**
81 * Kept in a DLL.
82 */
83 struct OperationContext *next;
84
85 /**
86 * Kept in a DLL.
87 */
88 struct OperationContext *prev;
89
90 /**
91 * Operation handle with the identity service.
92 */
93 struct GNUNET_IDENTITY_Operation *op;
94
95};
96
97
98/**
99 * Identity operation was finished, clean up.
100 *
101 * @param cls the 'struct OperationContext'
102 * @param emsg error message (NULL on success)
103 */
104static void
105operation_finished (void *cls,
106 const char *emsg)
107{
108 struct OperationContext *oc = cls;
109
110 GNUNET_free (oc);
111}
112
113
114/**
115 * The user edited one of the names of the egos. Change it
116 * in the IDENTITY service.
117 *
118 * @param renderer renderer where the change happened
119 * @param path location in the model where the change happened
120 * @param new_text updated text
121 * @param user_data internal context (not used)
122 */
123void
124GNUNET_GTK_namespace_organizer_namespaces_treeview_column_name_text_edited_cb
125(GtkCellRendererText *renderer,
126 gchar *path,
127 gchar *new_text,
128 gpointer user_data)
129{
130 GtkTreePath *treepath;
131 GtkTreeIter iter;
132 struct GNUNET_IDENTITY_Ego *ego;
133 gchar *old;
134 struct OperationContext *oc;
135
136 treepath = gtk_tree_path_new_from_string (path);
137 if (! gtk_tree_model_get_iter (GTK_TREE_MODEL (ls),
138 &iter,
139 treepath))
140 {
141 GNUNET_break (0);
142 gtk_tree_path_free (treepath);
143 return;
144 }
145 gtk_tree_path_free (treepath);
146 gtk_tree_model_get (GTK_TREE_MODEL (ls),
147 &iter,
148 IDENTITY_MC_NAME, &old,
149 IDENTITY_MC_EGO, &ego,
150 -1);
151 oc = GNUNET_new (struct OperationContext);
152 if (NULL == ego)
153 {
154 /* create operation */
155 oc->op = GNUNET_IDENTITY_create (identity,
156 new_text,
157 &operation_finished,
158 oc);
159 }
160 else if (0 != strlen (new_text))
161 {
162 /* rename operation */
163 oc->op = GNUNET_IDENTITY_rename (identity,
164 old, new_text,
165 &operation_finished,
166 oc);
167 }
168 else
169 {
170 /* delete operation */
171 oc->op = GNUNET_IDENTITY_delete (identity,
172 old,
173 &operation_finished,
174 oc);
175 }
176}
177
178
179/**
75 * Get cfg. 180 * Get cfg.
76 */ 181 */
77static const struct GNUNET_CONFIGURATION_Handle * 182static const struct GNUNET_CONFIGURATION_Handle *
@@ -208,6 +313,7 @@ static void
208run (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 313run (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
209{ 314{
210 GtkWidget *main_window; 315 GtkWidget *main_window;
316 GtkTreeIter iter;
211 317
212 ml = cls; 318 ml = cls;
213 if (GNUNET_OK != GNUNET_GTK_main_loop_build_window (ml, NULL)) 319 if (GNUNET_OK != GNUNET_GTK_main_loop_build_window (ml, NULL))
@@ -218,6 +324,11 @@ run (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
218 main_window = GTK_WIDGET (get_object ("GNUNET_GTK_identity_window")); 324 main_window = GTK_WIDGET (get_object ("GNUNET_GTK_identity_window"));
219 ls = GTK_LIST_STORE (get_object ("GNUNET_GTK_identity_liststore")); 325 ls = GTK_LIST_STORE (get_object ("GNUNET_GTK_identity_liststore"));
220 GNUNET_assert (NULL != ls); 326 GNUNET_assert (NULL != ls);
327 gtk_list_store_insert_with_values (ls,
328 &iter, G_MAXINT,
329 IDENTITY_MC_NAME, "<create>",
330 -1);
331
221 gtk_window_maximize (GTK_WINDOW (main_window)); 332 gtk_window_maximize (GTK_WINDOW (main_window));
222 GNUNET_GTK_tray_icon_create (ml, 333 GNUNET_GTK_tray_icon_create (ml,
223 GTK_WINDOW (main_window), 334 GTK_WINDOW (main_window),
diff --git a/src/identity/gnunet-identity-gtk_create_ego.c b/src/identity/gnunet-identity-gtk_create_ego.c
deleted file mode 100644
index e88c617c..00000000
--- a/src/identity/gnunet-identity-gtk_create_ego.c
+++ /dev/null
@@ -1,123 +0,0 @@
1/*
2 This file is part of GNUnet
3 (C) 2005, 2006, 2010, 2012 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/fs/gnunet-fs-gtk_create-pseudonym.c
23 * @author Christian Grothoff
24 * @brief code to handle the main menu action to create a pseudonym
25 */
26#include "gnunet-fs-gtk_common.h"
27#include "gnunet-fs-gtk.h"
28
29
30/**
31 * Function called whenever text is added to the GtkEntry
32 * with the name of the namespace. Here, we check that only
33 * "valid" characters are used (as the result must be a valid
34 * filename on most OSes).
35 *
36 * @param entry GtkEntry being edited
37 * @param text the text
38 * @param length length of the text
39 * @param position where the text is being inserted
40 * @param data the builder of the dialog (unused)
41 */
42void
43GNUNET_FS_GTK_create_namespace_insert_text_cb (GtkEntry *entry,
44 const gchar *text,
45 gint length,
46 gint *position,
47 gpointer data)
48{
49 GtkEditable *editable = GTK_EDITABLE(entry);
50 gint i;
51
52 for (i=0; i < length; i++)
53 if ( (! isalnum((int) text[i])) && (text[i] != '_') && (text[i] != '-') )
54 g_signal_stop_emission_by_name (G_OBJECT (editable), "insert_text");
55}
56
57
58/**
59 * User completed the 'create pseudonym' dialog. Run the desired action.
60 *
61 * @param dialog the dialog
62 * @param response_id GTK_RESPONSE_OK on "OK"
63 * @param user_data the builder of the dialog
64 */
65void
66GNUNET_GTK_create_namespace_dialog_response_cb (GtkDialog * dialog,
67 gint response_id,
68 gpointer user_data)
69{
70 GtkBuilder *builder = GTK_BUILDER (user_data);
71 const char *name;
72 struct GNUNET_FS_Namespace *ns;
73
74 if (GTK_RESPONSE_OK != response_id)
75 {
76 gtk_widget_destroy (GTK_WIDGET (dialog));
77 g_object_unref (G_OBJECT (builder));
78 return;
79 }
80 name = gtk_entry_get_text (GTK_ENTRY (gtk_builder_get_object (builder,
81 "GNUNET_GTK_create_namespace_name_entry")));
82 if (NULL != name)
83 {
84 ns = GNUNET_FS_namespace_create (GNUNET_FS_GTK_get_fs_handle (), name);
85 GNUNET_break (NULL != ns);
86 if (NULL != ns)
87 GNUNET_FS_namespace_delete (ns, GNUNET_NO);
88 }
89 gtk_widget_destroy (GTK_WIDGET (dialog));
90 g_object_unref (G_OBJECT (builder));
91}
92
93
94/**
95 * User selected "create pseudonym" in the menu of the main window.
96 *
97 * @param dummy the menu entry
98 * @param user_data the main dialog builder, unused
99 */
100void
101GNUNET_GTK_main_menu_create_pseudonym_activate_cb (GtkWidget * dummy,
102 gpointer user_data)
103{
104 GtkWidget *ad;
105 GtkWidget *toplevel;
106 GtkBuilder *builder;
107
108 builder = GNUNET_GTK_get_new_builder ("gnunet_fs_gtk_create_namespace_dialog.glade", NULL);
109 if (NULL == builder)
110 {
111 GNUNET_break (0);
112 return;
113 }
114 ad = GTK_WIDGET (gtk_builder_get_object
115 (builder, "GNUNET_GTK_create_namespace_dialog"));
116 toplevel = gtk_widget_get_toplevel (dummy);
117 if (GTK_IS_WINDOW (toplevel))
118 gtk_window_set_transient_for (GTK_WINDOW (ad), GTK_WINDOW (toplevel));
119 gtk_window_present (GTK_WINDOW (ad));
120}
121
122
123/* end of gnunet-fs-gtk_create-pseudonym.c */