diff options
Diffstat (limited to 'src/plugins/fs/namespace_create.c')
-rw-r--r-- | src/plugins/fs/namespace_create.c | 260 |
1 files changed, 260 insertions, 0 deletions
diff --git a/src/plugins/fs/namespace_create.c b/src/plugins/fs/namespace_create.c new file mode 100644 index 00000000..6b6e3f86 --- /dev/null +++ b/src/plugins/fs/namespace_create.c | |||
@@ -0,0 +1,260 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | (C) 2005, 2006, 2007 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/plugins/fs/namespace.c | ||
23 | * @brief operations creating namespaces | ||
24 | * @author Christian Grothoff | ||
25 | */ | ||
26 | |||
27 | #include "platform.h" | ||
28 | #include "gnunetgtk_common.h" | ||
29 | #include "fs.h" | ||
30 | #include "helper.h" | ||
31 | #include "meta.h" | ||
32 | #include "namespace.h" | ||
33 | #include "content_tracking.h" | ||
34 | #include <GNUnet/gnunet_util_crypto.h> | ||
35 | #include <GNUnet/gnunet_uritrack_lib.h> | ||
36 | #include <GNUnet/gnunet_namespace_lib.h> | ||
37 | #include <extractor.h> | ||
38 | |||
39 | |||
40 | static GladeXML * metaXML; | ||
41 | |||
42 | |||
43 | void on_namespacemetaDataDialogKeywordRemoveButton_clicked_fs(gpointer dummy, | ||
44 | GtkWidget * uploadButton) { | ||
45 | handleListRemove(metaXML, | ||
46 | "namespaceMetaDataDialogKeywordList"); | ||
47 | } | ||
48 | |||
49 | void on_namespacemetaDataDialogMetaDataRemoveButton_clicked_fs(gpointer dummy, | ||
50 | GtkWidget * uploadButton) { | ||
51 | handleListRemove(metaXML, | ||
52 | "namespaceMetaDataDialogMetaDataList"); | ||
53 | } | ||
54 | |||
55 | void on_namespacemetaDataDialogKeywordAddButton_clicked_fs(gpointer dummy, | ||
56 | GtkWidget * uploadButton) { | ||
57 | handleKeywordListUpdate(metaXML, | ||
58 | "namespaceKeywordEntry", | ||
59 | "namespaceMetaDataDialogKeywordList"); | ||
60 | } | ||
61 | |||
62 | void on_namespacemetaDataDialogMetaDataAddButton_clicked_fs(gpointer dummy, | ||
63 | GtkWidget * uploadButton) { | ||
64 | handleMetaDataListUpdate(metaXML, | ||
65 | "namespaceMetaDataDialogMetaTypeComboBox", | ||
66 | "namespaceMetaDataValueEntry", | ||
67 | "namespaceMetaDataDialogMetaDataList"); | ||
68 | } | ||
69 | |||
70 | /** | ||
71 | * The selection of the keyword list changed. | ||
72 | * Update button status. | ||
73 | */ | ||
74 | static void on_keyword_list_selection_changed(gpointer signal, | ||
75 | gpointer cls) { | ||
76 | GtkTreeSelection * selection; | ||
77 | GtkWidget * button; | ||
78 | |||
79 | selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(glade_xml_get_widget(metaXML, | ||
80 | "namespaceMetaDataDialogKeywordList"))); | ||
81 | button | ||
82 | = glade_xml_get_widget(metaXML, | ||
83 | "nsMetaDataDialogKeywordRemoveButton"); | ||
84 | gtk_widget_set_sensitive(button, | ||
85 | gtk_tree_selection_count_selected_rows(selection) > 0); | ||
86 | } | ||
87 | |||
88 | /** | ||
89 | * The selection of the metadata list changed. | ||
90 | * Update button status. | ||
91 | */ | ||
92 | static void on_metadata_list_selection_changed(gpointer signal, | ||
93 | gpointer cls) { | ||
94 | GtkTreeSelection * selection; | ||
95 | GtkWidget * button; | ||
96 | |||
97 | selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(glade_xml_get_widget(metaXML, | ||
98 | "namespaceMetaDataDialogMetaDataList"))); | ||
99 | button | ||
100 | = glade_xml_get_widget(metaXML, | ||
101 | "nsMetaDataDialogMetaDataRemoveButton"); | ||
102 | gtk_widget_set_sensitive(button, | ||
103 | gtk_tree_selection_count_selected_rows(selection) > 0); | ||
104 | } | ||
105 | |||
106 | /** | ||
107 | * The user has edited the metadata entry. | ||
108 | * Update add button status. | ||
109 | */ | ||
110 | void on_namespaceMetaDataValueEntry_changed_fs(gpointer dummy2, | ||
111 | GtkWidget * searchEntry) { | ||
112 | const char * input; | ||
113 | GtkWidget * button; | ||
114 | |||
115 | input = gtk_entry_get_text(GTK_ENTRY(glade_xml_get_widget(metaXML, | ||
116 | "namespaceMetaDataValueEntry"))); | ||
117 | if (input == NULL) | ||
118 | return; | ||
119 | button | ||
120 | = glade_xml_get_widget(metaXML, | ||
121 | "nsMetaDataDialogMetaDataAddButton"); | ||
122 | gtk_widget_set_sensitive(button, | ||
123 | strlen(input) > 0); | ||
124 | } | ||
125 | |||
126 | /** | ||
127 | * The user has edited the keyword entry. | ||
128 | * Update add button status. | ||
129 | */ | ||
130 | void on_namespaceKeywordEntry_changed_fs(gpointer dummy2, | ||
131 | GtkWidget * searchEntry) { | ||
132 | const char * input; | ||
133 | GtkWidget * button; | ||
134 | |||
135 | input = gtk_entry_get_text(GTK_ENTRY(glade_xml_get_widget(metaXML, | ||
136 | "namespaceKeywordEntry"))); | ||
137 | if (input == NULL) | ||
138 | return; | ||
139 | button | ||
140 | = glade_xml_get_widget(metaXML, | ||
141 | "nsMetaDataDialogKeywordAddButton"); | ||
142 | gtk_widget_set_sensitive(button, | ||
143 | strlen(input) > 0); | ||
144 | } | ||
145 | |||
146 | |||
147 | void create_namespace_clicked_fs(GtkWidget * dummy1, | ||
148 | GtkWidget * dummy2) { | ||
149 | const char * namespaceName; | ||
150 | GtkWidget * nameLine; | ||
151 | GtkWidget * dialog; | ||
152 | GtkWidget * spin; | ||
153 | struct ECRS_MetaData * meta; | ||
154 | struct ECRS_URI * keywordURI; | ||
155 | struct ECRS_URI * root; | ||
156 | HashCode512 namespaceId; | ||
157 | HashCode512 rootEntry; | ||
158 | |||
159 | DEBUG_BEGIN(); | ||
160 | metaXML | ||
161 | = glade_xml_new(getGladeFileName(), | ||
162 | "namespaceMetaDataDialog", | ||
163 | PACKAGE_NAME); | ||
164 | connectGladeWithPlugins(metaXML); | ||
165 | dialog = glade_xml_get_widget(metaXML, | ||
166 | "namespaceMetaDataDialog"); | ||
167 | createMetaDataListTreeView(metaXML, | ||
168 | "namespaceMetaDataDialogMetaDataList", | ||
169 | NULL, | ||
170 | NULL); | ||
171 | g_signal_connect_data(gtk_tree_view_get_selection(GTK_TREE_VIEW(glade_xml_get_widget(metaXML, | ||
172 | "namespaceMetaDataDialogMetaDataList"))), | ||
173 | "changed", | ||
174 | G_CALLBACK(&on_metadata_list_selection_changed), | ||
175 | NULL, | ||
176 | NULL, | ||
177 | 0); | ||
178 | createKeywordListTreeView(metaXML, | ||
179 | "namespaceMetaDataDialogKeywordList", | ||
180 | NULL); | ||
181 | g_signal_connect_data(gtk_tree_view_get_selection(GTK_TREE_VIEW(glade_xml_get_widget(metaXML, | ||
182 | "namespaceMetaDataDialogKeywordList"))), | ||
183 | "changed", | ||
184 | G_CALLBACK(&on_keyword_list_selection_changed), | ||
185 | NULL, | ||
186 | NULL, | ||
187 | 0); | ||
188 | |||
189 | createMetaTypeComboBox(metaXML, | ||
190 | "namespaceMetaDataDialogMetaTypeComboBox"); | ||
191 | gtk_dialog_set_default_response(GTK_DIALOG(dialog), | ||
192 | GTK_RESPONSE_OK); | ||
193 | if (gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_OK) { | ||
194 | meta | ||
195 | = getMetaDataFromList(metaXML, | ||
196 | "namespaceMetaDataDialogMetaDataList", | ||
197 | NULL); | ||
198 | keywordURI | ||
199 | = getKeywordURIFromList(metaXML, | ||
200 | "namespaceMetaDataDialogKeywordList"); | ||
201 | spin = glade_xml_get_widget(metaXML, | ||
202 | "namespaceAnonymityspinbutton"); | ||
203 | nameLine = glade_xml_get_widget(metaXML, | ||
204 | "namespaceRootEntry"); | ||
205 | namespaceName = gtk_entry_get_text(GTK_ENTRY(nameLine)); | ||
206 | if (namespaceName == NULL) | ||
207 | namespaceName = "root"; /* do NOT translate "root"! */ | ||
208 | hash(namespaceName, | ||
209 | strlen(namespaceName), | ||
210 | &rootEntry); | ||
211 | nameLine = glade_xml_get_widget(metaXML, | ||
212 | "namespaceNameEntry"); | ||
213 | namespaceName = gtk_entry_get_text(GTK_ENTRY(nameLine)); | ||
214 | root = NS_createNamespace(ectx, | ||
215 | cfg, | ||
216 | gtk_spin_button_get_value_as_int | ||
217 | (GTK_SPIN_BUTTON(spin)), | ||
218 | 1000, /* FIXME: priority */ | ||
219 | 999999, /* FIXME: expiration */ | ||
220 | namespaceName, | ||
221 | meta, | ||
222 | keywordURI, | ||
223 | &rootEntry); | ||
224 | if (root != NULL) { | ||
225 | ECRS_getNamespaceId(root, | ||
226 | &namespaceId); | ||
227 | addTabForNamespace(NULL, | ||
228 | namespaceName, | ||
229 | &namespaceId, | ||
230 | meta, | ||
231 | 0); | ||
232 | ECRS_freeUri(root); | ||
233 | } else { | ||
234 | GtkWidget * dialog; | ||
235 | |||
236 | /* IMPROVE-ME: we could check if the | ||
237 | namespace exists as the user | ||
238 | enters its name and disable the | ||
239 | "Ok" button unless the name is unique */ | ||
240 | dialog = gtk_message_dialog_new | ||
241 | (NULL, | ||
242 | GTK_DIALOG_MODAL, | ||
243 | GTK_MESSAGE_ERROR, | ||
244 | GTK_BUTTONS_CLOSE, | ||
245 | _("Failed to create namespace `%s'." | ||
246 | "Consult logs, most likely error is" | ||
247 | " that a namespace with that name " | ||
248 | "already exists."), | ||
249 | namespaceName); | ||
250 | gtk_dialog_run(GTK_DIALOG(dialog)); | ||
251 | gtk_widget_destroy(dialog); | ||
252 | } | ||
253 | ECRS_freeMetaData(meta); | ||
254 | ECRS_freeUri(keywordURI); | ||
255 | } | ||
256 | gtk_widget_destroy(dialog); | ||
257 | UNREF(metaXML); | ||
258 | metaXML = NULL; | ||
259 | DEBUG_END(); | ||
260 | } | ||