aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile3
-rw-r--r--resources/ui/contact_entry.ui98
-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
7 files changed, 299 insertions, 2 deletions
diff --git a/Makefile b/Makefile
index 894973f..7dc9f52 100644
--- a/Makefile
+++ b/Makefile
@@ -9,6 +9,7 @@ SOURCES = messenger_gtk.c\
9 chat/messenger.c\ 9 chat/messenger.c\
10 ui/chat.c\ 10 ui/chat.c\
11 ui/chat_entry.c\ 11 ui/chat_entry.c\
12 ui/contact_entry.c\
12 ui/contacts.c\ 13 ui/contacts.c\
13 ui/message.c\ 14 ui/message.c\
14 ui/messenger.c\ 15 ui/messenger.c\
@@ -18,7 +19,7 @@ SOURCES = messenger_gtk.c\
18HEADERS = 19HEADERS =
19 20
20LIBRARIES = gnunetchat zbargtk 21LIBRARIES = gnunetchat zbargtk
21PACKAGES = gnunetutil libhandy-1 gtk+-3.0 libnotify zbar libqrencode 22PACKAGES = gnunetutil libhandy-1 gtk+-3.0 libnotify zbar libqrencode gnunetidentity
22 23
23GNU_CC ?= gcc 24GNU_CC ?= gcc
24GNU_LD ?= gcc 25GNU_LD ?= gcc
diff --git a/resources/ui/contact_entry.ui b/resources/ui/contact_entry.ui
new file mode 100644
index 0000000..c0376b3
--- /dev/null
+++ b/resources/ui/contact_entry.ui
@@ -0,0 +1,98 @@
1<?xml version="1.0" encoding="UTF-8"?>
2<!-- Generated with glade 3.38.2
3
4Copyright (C) 2021 GNUnet e.V.
5
6GNUnet is free software: you can redistribute it and/or modify it
7under the terms of the GNU Affero General Public License as published
8by the Free Software Foundation, either version 3 of the License,
9or (at your option) any later version.
10
11GNUnet is distributed in the hope that it will be useful, but
12WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14Affero General Public License for more details.
15
16You should have received a copy of the GNU Affero General Public License
17along with this program. If not, see <http://www.gnu.org/licenses/>.
18
19SPDX-License-Identifier: AGPL3.0-or-later
20Author: Tobias Frisch
21
22-->
23<interface>
24 <requires lib="gtk+" version="3.24"/>
25 <requires lib="libhandy" version="1.2"/>
26 <object class="GtkBox" id="entry_box">
27 <property name="visible">True</property>
28 <property name="can-focus">False</property>
29 <property name="spacing">8</property>
30 <child>
31 <object class="HdyAvatar" id="entry_avatar">
32 <property name="visible">True</property>
33 <property name="can-focus">False</property>
34 <property name="size">48</property>
35 </object>
36 <packing>
37 <property name="expand">False</property>
38 <property name="fill">True</property>
39 <property name="position">0</property>
40 </packing>
41 </child>
42 <child>
43 <object class="GtkBox">
44 <property name="visible">True</property>
45 <property name="can-focus">False</property>
46 <property name="border-width">2</property>
47 <property name="orientation">vertical</property>
48 <property name="spacing">2</property>
49 <child>
50 <object class="GtkLabel" id="title_label">
51 <property name="visible">True</property>
52 <property name="can-focus">False</property>
53 <property name="wrap">True</property>
54 <property name="wrap-mode">word-char</property>
55 <property name="ellipsize">end</property>
56 <property name="xalign">0</property>
57 <attributes>
58 <attribute name="weight" value="bold"/>
59 </attributes>
60 </object>
61 <packing>
62 <property name="expand">False</property>
63 <property name="fill">True</property>
64 <property name="position">0</property>
65 </packing>
66 </child>
67 <child>
68 <object class="GtkLabel" id="subtitle_label">
69 <property name="visible">True</property>
70 <property name="can-focus">False</property>
71 <property name="wrap">True</property>
72 <property name="wrap-mode">word-char</property>
73 <property name="ellipsize">end</property>
74 <property name="max-width-chars">48</property>
75 <property name="xalign">0</property>
76 <attributes>
77 <attribute name="weight" value="semilight"/>
78 </attributes>
79 </object>
80 <packing>
81 <property name="expand">True</property>
82 <property name="fill">True</property>
83 <property name="position">1</property>
84 </packing>
85 </child>
86 </object>
87 <packing>
88 <property name="expand">True</property>
89 <property name="fill">True</property>
90 <property name="pack-type">end</property>
91 <property name="position">1</property>
92 </packing>
93 </child>
94 <style>
95 <class name="chat-entry"/>
96 </style>
97 </object>
98</interface>
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