aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTheJackiMonster <thejackimonster@gmail.com>2021-12-19 15:07:25 +0100
committerTheJackiMonster <thejackimonster@gmail.com>2021-12-19 15:07:25 +0100
commit35f830ec5f9ea6ff42d2c98e2a0efb40de3dd1f2 (patch)
tree9748fe12e3a2bd195652f11a2c207cfd8e190820
parentd71038500f255d3e5b491eea0677d179866044d2 (diff)
downloadmessenger-gtk-35f830ec5f9ea6ff42d2c98e2a0efb40de3dd1f2.tar.gz
messenger-gtk-35f830ec5f9ea6ff42d2c98e2a0efb40de3dd1f2.zip
Added dialog to invite contact to group
Signed-off-by: TheJackiMonster <thejackimonster@gmail.com>
-rw-r--r--Makefile1
-rw-r--r--resources/ui/invite_contact.ui102
-rw-r--r--src/application.h2
-rw-r--r--src/ui/chat.c25
-rw-r--r--src/ui/invite_contact.c206
-rw-r--r--src/ui/invite_contact.h51
6 files changed, 385 insertions, 2 deletions
diff --git a/Makefile b/Makefile
index 47e341a..6fc0fa6 100644
--- a/Makefile
+++ b/Makefile
@@ -12,6 +12,7 @@ SOURCES = messenger_gtk.c\
12 ui/chat_entry.c\ 12 ui/chat_entry.c\
13 ui/contact_entry.c\ 13 ui/contact_entry.c\
14 ui/contacts.c\ 14 ui/contacts.c\
15 ui/invite_contact.c\
15 ui/message.c\ 16 ui/message.c\
16 ui/messenger.c\ 17 ui/messenger.c\
17 ui/new_contact.c\ 18 ui/new_contact.c\
diff --git a/resources/ui/invite_contact.ui b/resources/ui/invite_contact.ui
new file mode 100644
index 0000000..03c3dca
--- /dev/null
+++ b/resources/ui/invite_contact.ui
@@ -0,0 +1,102 @@
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 <object class="GtkDialog" id="invite_contact_dialog">
26 <property name="can-focus">False</property>
27 <property name="modal">True</property>
28 <property name="window-position">center-on-parent</property>
29 <property name="type-hint">dialog</property>
30 <child internal-child="vbox">
31 <object class="GtkBox">
32 <property name="can-focus">False</property>
33 <property name="orientation">vertical</property>
34 <property name="spacing">2</property>
35 <child internal-child="action_area">
36 <object class="GtkButtonBox">
37 <property name="can-focus">False</property>
38 <property name="layout-style">end</property>
39 <child>
40 <object class="GtkButton" id="close_button">
41 <property name="label" translatable="yes">Close</property>
42 <property name="visible">True</property>
43 <property name="can-focus">True</property>
44 <property name="receives-default">True</property>
45 </object>
46 <packing>
47 <property name="expand">True</property>
48 <property name="fill">True</property>
49 <property name="position">0</property>
50 </packing>
51 </child>
52 </object>
53 <packing>
54 <property name="expand">False</property>
55 <property name="fill">False</property>
56 <property name="position">2</property>
57 </packing>
58 </child>
59 <child>
60 <object class="GtkSearchEntry" id="contact_search_entry">
61 <property name="width-request">250</property>
62 <property name="visible">True</property>
63 <property name="can-focus">True</property>
64 <property name="primary-icon-name">edit-find-symbolic</property>
65 <property name="primary-icon-activatable">False</property>
66 <property name="primary-icon-sensitive">False</property>
67 </object>
68 <packing>
69 <property name="expand">False</property>
70 <property name="fill">True</property>
71 <property name="position">0</property>
72 </packing>
73 </child>
74 <child>
75 <object class="GtkScrolledWindow">
76 <property name="height-request">200</property>
77 <property name="visible">True</property>
78 <property name="can-focus">True</property>
79 <property name="shadow-type">in</property>
80 <child>
81 <object class="GtkViewport">
82 <property name="visible">True</property>
83 <property name="can-focus">False</property>
84 <child>
85 <object class="GtkListBox" id="contacts_listbox">
86 <property name="visible">True</property>
87 <property name="can-focus">False</property>
88 </object>
89 </child>
90 </object>
91 </child>
92 </object>
93 <packing>
94 <property name="expand">True</property>
95 <property name="fill">True</property>
96 <property name="position">1</property>
97 </packing>
98 </child>
99 </object>
100 </child>
101 </object>
102</interface>
diff --git a/src/application.h b/src/application.h
index f8bfc6b..2e18f64 100644
--- a/src/application.h
+++ b/src/application.h
@@ -31,6 +31,7 @@
31#include "chat/messenger.h" 31#include "chat/messenger.h"
32 32
33#include "ui/contacts.h" 33#include "ui/contacts.h"
34#include "ui/invite_contact.h"
34#include "ui/messenger.h" 35#include "ui/messenger.h"
35#include "ui/new_contact.h" 36#include "ui/new_contact.h"
36#include "ui/new_group.h" 37#include "ui/new_group.h"
@@ -73,6 +74,7 @@ typedef struct MESSENGER_Application
73 74
74 UI_MESSENGER_Handle messenger; 75 UI_MESSENGER_Handle messenger;
75 76
77 UI_INVITE_CONTACT_Handle invite_contact;
76 UI_SEND_FILE_Handle send_file; 78 UI_SEND_FILE_Handle send_file;
77 79
78 UI_NEW_CONTACT_Handle new_contact; 80 UI_NEW_CONTACT_Handle new_contact;
diff --git a/src/ui/chat.c b/src/ui/chat.c
index c45b7b5..a8547ba 100644
--- a/src/ui/chat.c
+++ b/src/ui/chat.c
@@ -47,15 +47,30 @@ handle_flap_via_button_click(UNUSED GtkButton *button,
47} 47}
48 48
49static void 49static void
50handle_chat_contacts_listbox_row_activated(UNUSED GtkListBox *listbox, 50handle_chat_contacts_listbox_row_activated(GtkListBox *listbox,
51 GtkListBoxRow *row, 51 GtkListBoxRow *row,
52 gpointer user_data) 52 gpointer user_data)
53{ 53{
54 MESSENGER_Application *app = (MESSENGER_Application*) user_data; 54 MESSENGER_Application *app = (MESSENGER_Application*) user_data;
55 55
56 GtkTextView *text_view = GTK_TEXT_VIEW(
57 g_hash_table_lookup(app->ui.bindings, listbox)
58 );
59
60 if (!text_view)
61 return;
62
56 if (!gtk_list_box_row_get_selectable(row)) 63 if (!gtk_list_box_row_get_selectable(row))
57 { 64 {
58 //g_idle_add(G_SOURCE_FUNC(_open_new_contact_dialog), app); 65 ui_invite_contact_dialog_init(app, &(app->ui.invite_contact));
66
67 g_hash_table_insert(
68 app->ui.bindings,
69 app->ui.invite_contact.contacts_listbox,
70 text_view
71 );
72
73 gtk_widget_show(GTK_WIDGET(app->ui.invite_contact.dialog));
59 return; 74 return;
60 } 75 }
61 76
@@ -375,6 +390,12 @@ ui_chat_new(MESSENGER_Application *app)
375 390
376 g_hash_table_insert( 391 g_hash_table_insert(
377 app->ui.bindings, 392 app->ui.bindings,
393 handle->chat_contacts_listbox,
394 handle->send_text_view
395 );
396
397 g_hash_table_insert(
398 app->ui.bindings,
378 handle->attach_file_button, 399 handle->attach_file_button,
379 handle->send_text_view 400 handle->send_text_view
380 ); 401 );
diff --git a/src/ui/invite_contact.c b/src/ui/invite_contact.c
new file mode 100644
index 0000000..5b6a71c
--- /dev/null
+++ b/src/ui/invite_contact.c
@@ -0,0 +1,206 @@
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/invite_contact.c
23 */
24
25#include "invite_contact.h"
26
27#include "chat_entry.h"
28#include "contact_entry.h"
29#include "../application.h"
30
31static void
32handle_close_button_click(UNUSED GtkButton *button,
33 gpointer user_data)
34{
35 GtkDialog *dialog = GTK_DIALOG(user_data);
36 gtk_window_close(GTK_WINDOW(dialog));
37}
38
39static void
40handle_contacts_listbox_row_activated(GtkListBox* listbox,
41 GtkListBoxRow* row,
42 gpointer user_data)
43{
44 MESSENGER_Application *app = (MESSENGER_Application*) user_data;
45
46 GtkTextView *text_view = GTK_TEXT_VIEW(
47 g_hash_table_lookup(app->ui.bindings, listbox)
48 );
49
50 struct GNUNET_CHAT_Contact *contact = (struct GNUNET_CHAT_Contact*) (
51 g_hash_table_lookup(app->ui.bindings, row)
52 );
53
54 if ((!contact) || (!GNUNET_CHAT_contact_get_key(contact)) ||
55 (GNUNET_YES == GNUNET_CHAT_contact_is_owned(contact)) ||
56 (!text_view))
57 goto close_dialog;
58
59 struct GNUNET_CHAT_Context *context = g_hash_table_lookup(
60 app->ui.bindings, text_view
61 );
62
63 if (!context)
64 goto close_dialog;
65
66 const struct GNUNET_CHAT_Group *group = GNUNET_CHAT_context_get_group(
67 context
68 );
69
70 if (group)
71 GNUNET_CHAT_group_invite_contact(group, contact);
72
73close_dialog:
74 gtk_window_close(GTK_WINDOW(app->ui.invite_contact.dialog));
75}
76
77static void
78handle_dialog_destroy(UNUSED GtkWidget *window,
79 gpointer user_data)
80{
81 ui_contacts_dialog_cleanup((UI_CONTACTS_Handle*) user_data);
82}
83
84static int
85_iterate_contacts(void *cls,
86 UNUSED struct GNUNET_CHAT_Handle *handle,
87 struct GNUNET_CHAT_Contact *contact)
88{
89 if (GNUNET_YES == GNUNET_CHAT_contact_is_owned(contact))
90 return GNUNET_YES;
91
92 MESSENGER_Application *app = (MESSENGER_Application*) cls;
93
94 const char *title;
95 title = GNUNET_CHAT_contact_get_name(contact);
96
97 const char *key = GNUNET_CHAT_contact_get_key(contact);
98
99 UI_CONTACT_ENTRY_Handle *entry = ui_contact_entry_new();
100 gtk_list_box_prepend(
101 app->ui.invite_contact.contacts_listbox,
102 entry->entry_box
103 );
104
105 if (title)
106 {
107 gtk_label_set_text(entry->title_label, title);
108 hdy_avatar_set_text(entry->entry_avatar, title);
109 }
110
111 if (key)
112 gtk_label_set_text(entry->subtitle_label, key);
113
114 GtkListBoxRow *row = GTK_LIST_BOX_ROW(
115 gtk_widget_get_parent(entry->entry_box)
116 );
117
118 g_hash_table_insert(app->ui.bindings, row, contact);
119
120 app->ui.invite_contact.contact_entries = g_list_append(
121 app->ui.invite_contact.contact_entries,
122 entry
123 );
124
125 return GNUNET_YES;
126}
127
128void
129ui_invite_contact_dialog_init(MESSENGER_Application *app,
130 UI_INVITE_CONTACT_Handle *handle)
131{
132 handle->contact_entries = NULL;
133
134 handle->builder = gtk_builder_new_from_file("resources/ui/invite_contact.ui");
135
136 handle->dialog = GTK_DIALOG(
137 gtk_builder_get_object(handle->builder, "invite_contact_dialog")
138 );
139
140 gtk_window_set_title(
141 GTK_WINDOW(handle->dialog),
142 _("Invite Contact")
143 );
144
145 gtk_window_set_transient_for(
146 GTK_WINDOW(handle->dialog),
147 GTK_WINDOW(app->ui.messenger.main_window)
148 );
149
150 handle->contact_search_entry = GTK_SEARCH_ENTRY(
151 gtk_builder_get_object(handle->builder, "contact_search_entry")
152 );
153
154 handle->contacts_listbox = GTK_LIST_BOX(
155 gtk_builder_get_object(handle->builder, "contacts_listbox")
156 );
157
158 g_signal_connect(
159 handle->contacts_listbox,
160 "row-activated",
161 G_CALLBACK(handle_contacts_listbox_row_activated),
162 app
163 );
164
165 handle->close_button = GTK_BUTTON(
166 gtk_builder_get_object(handle->builder, "close_button")
167 );
168
169 g_signal_connect(
170 handle->close_button,
171 "clicked",
172 G_CALLBACK(handle_close_button_click),
173 handle->dialog
174 );
175
176 g_signal_connect(
177 handle->dialog,
178 "destroy",
179 G_CALLBACK(handle_dialog_destroy),
180 handle
181 );
182
183 GNUNET_CHAT_iterate_contacts(
184 app->chat.messenger.handle,
185 _iterate_contacts,
186 app
187 );
188}
189
190void
191ui_invite_contact_dialog_cleanup(UI_INVITE_CONTACT_Handle *handle)
192{
193 g_object_unref(handle->builder);
194
195 GList *list = handle->contact_entries;
196
197 while (list) {
198 if (list->data)
199 ui_contact_entry_delete((UI_CONTACT_ENTRY_Handle*) list->data);
200
201 list = list->next;
202 }
203
204 if (handle->contact_entries)
205 g_list_free(handle->contact_entries);
206}
diff --git a/src/ui/invite_contact.h b/src/ui/invite_contact.h
new file mode 100644
index 0000000..64d2f09
--- /dev/null
+++ b/src/ui/invite_contact.h
@@ -0,0 +1,51 @@
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/invite_contact.h
23 */
24
25#ifndef UI_INVITE_CONTACT_H_
26#define UI_INVITE_CONTACT_H_
27
28#include "messenger.h"
29
30typedef struct UI_INVITE_CONTACT_Handle
31{
32 GList *contact_entries;
33
34 GtkBuilder *builder;
35 GtkDialog *dialog;
36
37 GtkSearchEntry *contact_search_entry;
38
39 GtkListBox *contacts_listbox;
40
41 GtkButton *close_button;
42} UI_INVITE_CONTACT_Handle;
43
44void
45ui_invite_contact_dialog_init(MESSENGER_Application *app,
46 UI_INVITE_CONTACT_Handle *handle);
47
48void
49ui_invite_contact_dialog_cleanup(UI_INVITE_CONTACT_Handle *handle);
50
51#endif /* UI_INVITE_CONTACT_H_ */