aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/event.c3
-rw-r--r--src/ui/contact_entry.c61
-rw-r--r--src/ui/contact_entry.h48
-rw-r--r--src/ui/contacts.c86
-rw-r--r--src/ui/contacts.h2
5 files changed, 199 insertions, 1 deletions
diff --git a/src/event.c b/src/event.c
index 6e585b2..a9ae35d 100644
--- a/src/event.c
+++ b/src/event.c
@@ -25,6 +25,7 @@
25#include "event.h" 25#include "event.h"
26 26
27#include "ui/chat_entry.h" 27#include "ui/chat_entry.h"
28#include "ui/contact_entry.h"
28#include "ui/message.h" 29#include "ui/message.h"
29 30
30static void 31static void
@@ -81,7 +82,7 @@ _add_new_chat_entry(MESSENGER_Application *app,
81static int 82static int
82_iterate_profile_contacts(void *cls, 83_iterate_profile_contacts(void *cls,
83 UNUSED struct GNUNET_CHAT_Handle *handle, 84 UNUSED struct GNUNET_CHAT_Handle *handle,
84 UNUSED struct GNUNET_CHAT_Contact *contact) 85 struct GNUNET_CHAT_Contact *contact)
85{ 86{
86 MESSENGER_Application *app = (MESSENGER_Application*) cls; 87 MESSENGER_Application *app = (MESSENGER_Application*) cls;
87 _add_new_chat_entry(app, GNUNET_CHAT_contact_get_context(contact)); 88 _add_new_chat_entry(app, GNUNET_CHAT_contact_get_context(contact));
diff --git a/src/ui/contact_entry.c b/src/ui/contact_entry.c
new file mode 100644
index 0000000..cf830db
--- /dev/null
+++ b/src/ui/contact_entry.c
@@ -0,0 +1,61 @@
1/*
2 This file is part of GNUnet.
3 Copyright (C) 2021 GNUnet e.V.
4
5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation, either version 3 of the License,
8 or (at your 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 Affero General Public License for more details.
14
15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17
18 SPDX-License-Identifier: AGPL3.0-or-later
19 */
20/*
21 * @author Tobias Frisch
22 * @file ui/contact_entry.c
23 */
24
25#include "contact_entry.h"
26
27#include "../application.h"
28
29UI_CONTACT_ENTRY_Handle*
30ui_contact_entry_new(void)
31{
32 UI_CONTACT_ENTRY_Handle* handle = g_malloc(sizeof(UI_CONTACT_ENTRY_Handle));
33
34 handle->builder = gtk_builder_new_from_file("resources/ui/contact_entry.ui");
35
36 handle->entry_box = GTK_WIDGET(
37 gtk_builder_get_object(handle->builder, "entry_box")
38 );
39
40 handle->entry_avatar = HDY_AVATAR(
41 gtk_builder_get_object(handle->builder, "entry_avatar")
42 );
43
44 handle->title_label = GTK_LABEL(
45 gtk_builder_get_object(handle->builder, "title_label")
46 );
47
48 handle->subtitle_label = GTK_LABEL(
49 gtk_builder_get_object(handle->builder, "subtitle_label")
50 );
51
52 return handle;
53}
54
55void
56ui_contact_entry_delete(UI_CONTACT_ENTRY_Handle *handle)
57{
58 g_object_unref(handle->builder);
59
60 g_free(handle);
61}
diff --git a/src/ui/contact_entry.h b/src/ui/contact_entry.h
new file mode 100644
index 0000000..6b39077
--- /dev/null
+++ b/src/ui/contact_entry.h
@@ -0,0 +1,48 @@
1/*
2 This file is part of GNUnet.
3 Copyright (C) 2021 GNUnet e.V.
4
5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation, either version 3 of the License,
8 or (at your 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 Affero General Public License for more details.
14
15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17
18 SPDX-License-Identifier: AGPL3.0-or-later
19 */
20/*
21 * @author Tobias Frisch
22 * @file ui/contact_entry.h
23 */
24
25#ifndef UI_CONTACT_ENTRY_H_
26#define UI_CONTACT_ENTRY_H_
27
28#include "messenger.h"
29
30typedef struct UI_CONTACT_ENTRY_Handle
31{
32 GtkBuilder *builder;
33
34 GtkWidget *entry_box;
35
36 HdyAvatar *entry_avatar;
37
38 GtkLabel *title_label;
39 GtkLabel *subtitle_label;
40} UI_CONTACT_ENTRY_Handle;
41
42UI_CONTACT_ENTRY_Handle*
43ui_contact_entry_new(void);
44
45void
46ui_contact_entry_delete(UI_CONTACT_ENTRY_Handle *handle);
47
48#endif /* UI_CONTACT_ENTRY_H_ */
diff --git a/src/ui/contacts.c b/src/ui/contacts.c
index 3750f8f..34ceaed 100644
--- a/src/ui/contacts.c
+++ b/src/ui/contacts.c
@@ -24,8 +24,11 @@
24 24
25#include "contacts.h" 25#include "contacts.h"
26 26
27#include "contact_entry.h"
27#include "../application.h" 28#include "../application.h"
28 29
30#include <gnunet/gnunet_identity_service.h>
31
29static void 32static void
30handle_close_button_click(UNUSED GtkButton *button, 33handle_close_button_click(UNUSED GtkButton *button,
31 gpointer user_data) 34 gpointer user_data)
@@ -41,10 +44,66 @@ handle_dialog_destroy(UNUSED GtkWidget *window,
41 ui_contacts_dialog_cleanup((UI_CONTACTS_Handle*) user_data); 44 ui_contacts_dialog_cleanup((UI_CONTACTS_Handle*) user_data);
42} 45}
43 46
47static int
48_iterate_clear_contacts(UNUSED void *cls,
49 UNUSED struct GNUNET_CHAT_Handle *handle,
50 struct GNUNET_CHAT_Contact *contact)
51{
52 GNUNET_CHAT_contact_set_user_pointer(contact, NULL);
53 return GNUNET_YES;
54}
55
56static int
57_iterate_contacts(void *cls,
58 UNUSED struct GNUNET_CHAT_Handle *handle,
59 struct GNUNET_CHAT_Contact *contact)
60{
61 MESSENGER_Application *app = (MESSENGER_Application*) cls;
62
63 if (GNUNET_CHAT_contact_get_user_pointer(contact))
64 return GNUNET_YES;
65
66 const char *title;
67 title = GNUNET_CHAT_contact_get_name(contact);
68
69 const struct GNUNET_IDENTITY_PublicKey *key;
70 key = GNUNET_CHAT_contact_get_key(contact);
71
72 UI_CONTACT_ENTRY_Handle *entry = ui_contact_entry_new();
73 gtk_container_add(
74 GTK_CONTAINER(app->ui.contacts.contacts_listbox),
75 entry->entry_box
76 );
77
78 GNUNET_CHAT_contact_set_user_pointer(contact, entry);
79
80 if (title)
81 {
82 gtk_label_set_text(entry->title_label, title);
83 hdy_avatar_set_text(entry->entry_avatar, title);
84 }
85
86 if (key)
87 {
88 char *key_string = GNUNET_IDENTITY_public_key_to_string(key);
89 gtk_label_set_text(entry->subtitle_label, key_string);
90 GNUNET_free(key_string);
91 }
92
93 app->ui.contacts.contact_entries = g_list_append(
94 app->ui.contacts.contact_entries,
95 entry
96 );
97
98 return GNUNET_YES;
99}
100
44void 101void
45ui_contacts_dialog_init(MESSENGER_Application *app, 102ui_contacts_dialog_init(MESSENGER_Application *app,
46 UI_CONTACTS_Handle *handle) 103 UI_CONTACTS_Handle *handle)
47{ 104{
105 handle->contact_entries = g_list_alloc();
106
48 handle->builder = gtk_builder_new_from_file("resources/ui/contacts.ui"); 107 handle->builder = gtk_builder_new_from_file("resources/ui/contacts.ui");
49 108
50 handle->dialog = GTK_DIALOG( 109 handle->dialog = GTK_DIALOG(
@@ -65,6 +124,10 @@ ui_contacts_dialog_init(MESSENGER_Application *app,
65 gtk_builder_get_object(handle->builder, "contact_search_entry") 124 gtk_builder_get_object(handle->builder, "contact_search_entry")
66 ); 125 );
67 126
127 handle->contacts_listbox = GTK_LIST_BOX(
128 gtk_builder_get_object(handle->builder, "contacts_listbox")
129 );
130
68 handle->close_button = GTK_BUTTON( 131 handle->close_button = GTK_BUTTON(
69 gtk_builder_get_object(handle->builder, "close_button") 132 gtk_builder_get_object(handle->builder, "close_button")
70 ); 133 );
@@ -82,10 +145,33 @@ ui_contacts_dialog_init(MESSENGER_Application *app,
82 G_CALLBACK(handle_dialog_destroy), 145 G_CALLBACK(handle_dialog_destroy),
83 handle 146 handle
84 ); 147 );
148
149 GNUNET_CHAT_iterate_contacts(
150 app->chat.messenger.handle,
151 _iterate_clear_contacts,
152 NULL
153 );
154
155 GNUNET_CHAT_iterate_contacts(
156 app->chat.messenger.handle,
157 _iterate_contacts,
158 app
159 );
85} 160}
86 161
87void 162void
88ui_contacts_dialog_cleanup(UI_CONTACTS_Handle *handle) 163ui_contacts_dialog_cleanup(UI_CONTACTS_Handle *handle)
89{ 164{
90 g_object_unref(handle->builder); 165 g_object_unref(handle->builder);
166
167 GList *list = handle->contact_entries;
168
169 while (list) {
170 if (list->data)
171 ui_contact_entry_delete((UI_CONTACT_ENTRY_Handle*) list->data);
172
173 list = list->next;
174 }
175
176 g_list_free(handle->contact_entries);
91} 177}
diff --git a/src/ui/contacts.h b/src/ui/contacts.h
index dbd952b..90b4b4c 100644
--- a/src/ui/contacts.h
+++ b/src/ui/contacts.h
@@ -29,6 +29,8 @@
29 29
30typedef struct UI_CONTACTS_Handle 30typedef struct UI_CONTACTS_Handle
31{ 31{
32 GList *contact_entries;
33
32 GtkBuilder *builder; 34 GtkBuilder *builder;
33 GtkDialog *dialog; 35 GtkDialog *dialog;
34 36