aboutsummaryrefslogtreecommitdiff
path: root/src/ui/messenger.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/ui/messenger.c')
-rw-r--r--src/ui/messenger.c190
1 files changed, 190 insertions, 0 deletions
diff --git a/src/ui/messenger.c b/src/ui/messenger.c
new file mode 100644
index 0000000..829d31a
--- /dev/null
+++ b/src/ui/messenger.c
@@ -0,0 +1,190 @@
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/messenger.c
23 */
24
25#include "messenger.h"
26
27void handle_user_details_button_click(UI_UNUSED GtkButton* button,
28 gpointer user_data)
29{
30 HdyFlap* flap = HDY_FLAP(user_data);
31
32 if (TRUE == hdy_flap_get_reveal_flap(flap)) {
33 hdy_flap_set_reveal_flap(flap, FALSE);
34 } else {
35 hdy_flap_set_reveal_flap(flap, TRUE);
36 }
37}
38
39void handle_account_details_button_click(UI_UNUSED GtkButton* button,
40 gpointer user_data)
41{
42 GtkRevealer* revealer = GTK_REVEALER(user_data);
43
44 if (TRUE == gtk_revealer_get_reveal_child(revealer)) {
45 gtk_revealer_set_reveal_child(revealer, FALSE);
46 } else {
47 gtk_revealer_set_reveal_child(revealer, TRUE);
48 }
49}
50
51void handle_chats_listbox_row_activated(UI_UNUSED GtkListBox* listbox,
52 UI_UNUSED GtkListBoxRow* row,
53 gpointer user_data)
54{
55 HdyLeaflet* leaflet = HDY_LEAFLET(user_data);
56
57 GList* children = gtk_container_get_children(GTK_CONTAINER(leaflet));
58
59 if ((children) && (children->next)) {
60 hdy_leaflet_set_visible_child(leaflet, GTK_WIDGET(children->next->data));
61 }
62}
63
64void handle_back_button_click(UI_UNUSED GtkButton* button,
65 gpointer user_data)
66{
67 HdyLeaflet* leaflet = HDY_LEAFLET(user_data);
68
69 GList* children = gtk_container_get_children(GTK_CONTAINER(leaflet));
70
71 if (children) {
72 hdy_leaflet_set_visible_child(leaflet, GTK_WIDGET(children->data));
73 }
74}
75
76void
77ui_messenger_init(struct UI_MESSENGER_Handle *handle)
78{
79 GtkBuilder* builder = gtk_builder_new();
80 gtk_builder_add_from_file(
81 builder,
82 "resources/ui/messenger.ui",
83 NULL
84 );
85
86 handle->main_window = GTK_APPLICATION_WINDOW(
87 gtk_builder_get_object(builder, "main_window")
88 );
89
90 handle->profile_avatar = HDY_AVATAR(
91 gtk_builder_get_object(builder, "profile_avatar")
92 );
93
94 handle->profile_label = GTK_LABEL(
95 gtk_builder_get_object(builder, "profile_label")
96 );
97
98 handle->title_bar = HDY_HEADER_BAR(
99 gtk_builder_get_object(builder, "title_bar")
100 );
101
102 handle->leaflet_chat = HDY_LEAFLET(
103 gtk_builder_get_object(builder, "leaflet_chat")
104 );
105
106 hdy_leaflet_set_homogeneous(handle->leaflet_chat, FALSE, GTK_ORIENTATION_HORIZONTAL, FALSE);
107
108 handle->chats_listbox = GTK_LIST_BOX(
109 gtk_builder_get_object(builder, "chats_listbox")
110 );
111
112 g_signal_connect(
113 handle->chats_listbox,
114 "row-activated",
115 G_CALLBACK(handle_chats_listbox_row_activated),
116 handle->leaflet_chat
117 );
118
119 handle->user_details_button = GTK_BUTTON(
120 gtk_builder_get_object(builder, "user_details_button")
121 );
122
123 handle->hide_user_details_button = GTK_BUTTON(
124 gtk_builder_get_object(builder, "hide_user_details_button")
125 );
126
127 handle->flap_user_details = HDY_FLAP(
128 gtk_builder_get_object(builder, "flap_user_details")
129 );
130
131 g_signal_connect(
132 handle->user_details_button,
133 "clicked",
134 G_CALLBACK(handle_user_details_button_click),
135 handle->flap_user_details
136 );
137
138 g_signal_connect(
139 handle->hide_user_details_button,
140 "clicked",
141 G_CALLBACK(handle_user_details_button_click),
142 handle->flap_user_details
143 );
144
145 handle->account_details_button = GTK_BUTTON(
146 gtk_builder_get_object(builder, "account_details_button")
147 );
148
149 handle->account_details_revealer = GTK_REVEALER(
150 gtk_builder_get_object(builder, "account_details_revealer")
151 );
152
153 g_signal_connect(
154 handle->account_details_button,
155 "clicked",
156 G_CALLBACK(handle_account_details_button_click),
157 handle->account_details_revealer
158 );
159
160 handle->back_button = GTK_BUTTON(
161 gtk_builder_get_object(builder, "back_button")
162 );
163
164 g_signal_connect(
165 handle->back_button,
166 "clicked",
167 G_CALLBACK(handle_back_button_click),
168 handle->leaflet_chat
169 );
170
171 g_object_bind_property(
172 handle->leaflet_chat,
173 "folded",
174 handle->back_button,
175 "visible",
176 G_BINDING_SYNC_CREATE
177 );
178
179 g_object_bind_property(
180 handle->leaflet_chat,
181 "folded",
182 handle->title_bar,
183 "show-close-button",
184 G_BINDING_INVERT_BOOLEAN
185 );
186
187 gtk_widget_show(GTK_WIDGET(handle->main_window));
188
189 g_signal_connect(handle->main_window, "destroy", G_CALLBACK(gtk_main_quit), NULL);
190}