aboutsummaryrefslogtreecommitdiff
path: root/src/conversation/gnunet-conversation-gtk_egos.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/conversation/gnunet-conversation-gtk_egos.c')
-rw-r--r--src/conversation/gnunet-conversation-gtk_egos.c169
1 files changed, 169 insertions, 0 deletions
diff --git a/src/conversation/gnunet-conversation-gtk_egos.c b/src/conversation/gnunet-conversation-gtk_egos.c
new file mode 100644
index 00000000..29aa3501
--- /dev/null
+++ b/src/conversation/gnunet-conversation-gtk_egos.c
@@ -0,0 +1,169 @@
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_egos.c
23 * @brief
24 * @author yids
25 * @author hark
26 * @author Christian Grothoff
27 */
28#include "gnunet-conversation-gtk.h"
29#include "gnunet-conversation-gtk_egos.h"
30
31
32/**
33 * Columns in the #zone_liststore.
34 */
35enum ZoneListstoreValues
36{
37 /**
38 * Human-readable name of the ego.
39 */
40 ZONE_LS_NAME = 0,
41
42 /**
43 * Handel to the ego (of type `struct GNUNET_IDENTITY_Ego *ego`).
44 */
45 ZONE_LS_EGO = 1
46};
47
48
49/**
50 * Handle to identity service.
51 */
52static struct GNUNET_IDENTITY_Handle *id;
53
54/**
55 * list of zones
56 */
57static GtkListStore *zone_liststore;
58
59
60/**
61 * Obtain the currently selected ego.
62 *
63 * @return NULL if no ego is selected
64 */
65struct GNUNET_IDENTITY_Ego *
66GCG_EGOS_get_selected_ego (void)
67{
68 struct GNUNET_IDENTITY_Ego *ego;
69 GtkTreeIter iter;
70 GtkComboBox *cb;
71
72 cb = GTK_COMBO_BOX (GCG_get_main_window_object ("gnunet_conversation_gtk_contacts_zone_combobox"));
73 gtk_combo_box_get_active_iter (cb,
74 &iter);
75 gtk_tree_model_get (GTK_TREE_MODEL (zone_liststore),
76 &iter,
77 ZONE_LS_EGO, &ego,
78 -1);
79 return ego;
80}
81
82
83/**
84 * Function called by identity service with information about egos.
85 *
86 * @param cls NULL
87 * @param ego ego handle
88 * @param ctx unused
89 * @param name name of the ego
90 */
91static void
92identity_cb (void *cls,
93 struct GNUNET_IDENTITY_Ego *ego,
94 void **ctx,
95 const char *name)
96{
97 GtkTreeIter iter;
98 GtkTreeRowReference *rr;
99 GtkTreePath *path;
100
101 rr = *ctx;
102 if (NULL == rr)
103 {
104 /* new identity */
105 GNUNET_assert (NULL != name);
106 gtk_list_store_insert_with_values (zone_liststore,
107 &iter, -1,
108 ZONE_LS_NAME, name,
109 ZONE_LS_EGO, ego,
110 -1);
111 path = gtk_tree_model_get_path (GTK_TREE_MODEL (zone_liststore),
112 &iter);
113 rr = gtk_tree_row_reference_new (GTK_TREE_MODEL (zone_liststore),
114 path);
115 gtk_tree_path_free (path);
116 *ctx = rr;
117 return;
118 }
119 /* existing ego, locate and execute rename/delete */
120 path = gtk_tree_row_reference_get_path (rr);
121 gtk_tree_model_get_iter (GTK_TREE_MODEL (zone_liststore),
122 &iter,
123 path);
124 gtk_tree_path_free (path);
125 if (NULL == name)
126 {
127 /* deletion operation */
128 gtk_tree_row_reference_free (rr);
129 *ctx = NULL;
130 gtk_list_store_remove (zone_liststore,
131 &iter);
132 return;
133 }
134 /* rename operation */
135 gtk_list_store_set (zone_liststore,
136 &iter,
137 ZONE_LS_NAME, &name,
138 -1);
139}
140
141
142/**
143 * Initialize the ego list
144 */
145void
146GCG_EGOS_init ()
147{
148 zone_liststore
149 = GTK_LIST_STORE (GCG_get_main_window_object ("gnunet_conversation_gtk_contacts_zone_liststore"));
150 id = GNUNET_IDENTITY_connect (GCG_get_configuration (),
151 &identity_cb,
152 NULL);
153}
154
155
156/**
157 * Shutdown the ego list
158 */
159void
160GCG_EGOS_shutdown ()
161{
162 if (NULL != id)
163 {
164 GNUNET_IDENTITY_disconnect (id);
165 id = NULL;
166 }
167}
168
169/* end of gnunet-conversation-gtk_egos.c */