diff options
Diffstat (limited to 'src/conversation/gnunet-conversation-gtk_zones.c')
-rw-r--r-- | src/conversation/gnunet-conversation-gtk_zones.c | 148 |
1 files changed, 148 insertions, 0 deletions
diff --git a/src/conversation/gnunet-conversation-gtk_zones.c b/src/conversation/gnunet-conversation-gtk_zones.c new file mode 100644 index 00000000..459c9492 --- /dev/null +++ b/src/conversation/gnunet-conversation-gtk_zones.c | |||
@@ -0,0 +1,148 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | (C) 2013-2014 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 3, 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/conversation/gnunet-conversation-gtk_zones.c | ||
23 | * @brief manages the widget which shows the zones (to select | ||
24 | * which one will be used to populate the address book) | ||
25 | * @author yids | ||
26 | * @author hark | ||
27 | * @author Christian Grothoff | ||
28 | */ | ||
29 | #include "gnunet-conversation-gtk.h" | ||
30 | #include "gnunet-conversation-gtk_zones.h" | ||
31 | |||
32 | |||
33 | /** | ||
34 | * Columns in the #zone_liststore. | ||
35 | */ | ||
36 | enum ZoneListstoreValues | ||
37 | { | ||
38 | /** | ||
39 | * Human-readable name of the ego. | ||
40 | */ | ||
41 | ZONE_LS_NAME = 0, | ||
42 | |||
43 | /** | ||
44 | * Handel to the ego (of type `struct GNUNET_IDENTITY_Ego *ego`). | ||
45 | */ | ||
46 | ZONE_LS_EGO = 1 | ||
47 | }; | ||
48 | |||
49 | |||
50 | /** | ||
51 | * Handle to identity service. | ||
52 | */ | ||
53 | static struct GNUNET_IDENTITY_Handle *id; | ||
54 | |||
55 | /** | ||
56 | * list of zones | ||
57 | */ | ||
58 | static GtkListStore *zone_liststore; | ||
59 | |||
60 | |||
61 | /** | ||
62 | * Function called by identity service with information about zones. | ||
63 | * | ||
64 | * @param cls NULL | ||
65 | * @param ego ego handle for the zone | ||
66 | * @param ctx unused | ||
67 | * @param name name of the zone | ||
68 | */ | ||
69 | static void | ||
70 | identity_cb (void *cls, | ||
71 | struct GNUNET_IDENTITY_Ego *ego, | ||
72 | void **ctx, | ||
73 | const char *name) | ||
74 | { | ||
75 | GtkTreeIter iter; | ||
76 | GtkTreeRowReference *rr; | ||
77 | GtkTreePath *path; | ||
78 | |||
79 | rr = *ctx; | ||
80 | if (NULL == rr) | ||
81 | { | ||
82 | /* new identity */ | ||
83 | GNUNET_assert (NULL != name); | ||
84 | gtk_list_store_insert_with_values (zone_liststore, | ||
85 | &iter, -1, | ||
86 | ZONE_LS_NAME, name, | ||
87 | ZONE_LS_EGO, ego, | ||
88 | -1); | ||
89 | path = gtk_tree_model_get_path (GTK_TREE_MODEL (zone_liststore), | ||
90 | &iter); | ||
91 | rr = gtk_tree_row_reference_new (GTK_TREE_MODEL (zone_liststore), | ||
92 | path); | ||
93 | gtk_tree_path_free (path); | ||
94 | *ctx = rr; | ||
95 | return; | ||
96 | } | ||
97 | /* existing ego, locate and execute rename/delete */ | ||
98 | path = gtk_tree_row_reference_get_path (rr); | ||
99 | gtk_tree_model_get_iter (GTK_TREE_MODEL (zone_liststore), | ||
100 | &iter, | ||
101 | path); | ||
102 | gtk_tree_path_free (path); | ||
103 | if (NULL == name) | ||
104 | { | ||
105 | /* deletion operation */ | ||
106 | gtk_tree_row_reference_free (rr); | ||
107 | *ctx = NULL; | ||
108 | gtk_list_store_remove (zone_liststore, | ||
109 | &iter); | ||
110 | return; | ||
111 | } | ||
112 | /* rename operation */ | ||
113 | gtk_list_store_set (zone_liststore, | ||
114 | &iter, | ||
115 | ZONE_LS_NAME, &name, | ||
116 | -1); | ||
117 | } | ||
118 | |||
119 | |||
120 | /** | ||
121 | * Initialize the zones list | ||
122 | */ | ||
123 | void | ||
124 | GCG_ZONES_init () | ||
125 | { | ||
126 | zone_liststore | ||
127 | = GTK_LIST_STORE (GCG_get_main_window_object | ||
128 | ("gnunet_conversation_gtk_contacts_zone_liststore")); | ||
129 | id = GNUNET_IDENTITY_connect (GCG_get_configuration (), | ||
130 | &identity_cb, | ||
131 | NULL); | ||
132 | } | ||
133 | |||
134 | |||
135 | /** | ||
136 | * Shutdown the zone list | ||
137 | */ | ||
138 | void | ||
139 | GCG_ZONES_shutdown () | ||
140 | { | ||
141 | if (NULL != id) | ||
142 | { | ||
143 | GNUNET_IDENTITY_disconnect (id); | ||
144 | id = NULL; | ||
145 | } | ||
146 | } | ||
147 | |||
148 | /* end of gnunet-conversation-gtk_zones.c */ | ||