aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/application.c7
-rw-r--r--src/application.h9
-rw-r--r--src/chat/messenger.c32
-rw-r--r--src/event.c28
-rw-r--r--src/event.h7
-rw-r--r--src/ui/messenger.c21
-rw-r--r--src/ui/new_platform.c122
-rw-r--r--src/ui/new_platform.h47
8 files changed, 258 insertions, 15 deletions
diff --git a/src/application.c b/src/application.c
index 2f367a5..0db05bb 100644
--- a/src/application.c
+++ b/src/application.c
@@ -147,6 +147,7 @@ typedef struct MESSENGER_ApplicationEventCall
147{ 147{
148 MESSENGER_Application *app; 148 MESSENGER_Application *app;
149 MESSENGER_ApplicationEvent event; 149 MESSENGER_ApplicationEvent event;
150 void *cls;
150} MESSENGER_ApplicationEventCall; 151} MESSENGER_ApplicationEventCall;
151 152
152static gboolean 153static gboolean
@@ -155,7 +156,7 @@ _application_event_call(gpointer user_data)
155 MESSENGER_ApplicationEventCall *call; 156 MESSENGER_ApplicationEventCall *call;
156 157
157 call = (MESSENGER_ApplicationEventCall*) user_data; 158 call = (MESSENGER_ApplicationEventCall*) user_data;
158 call->event(call->app); 159 call->event(call->app, call->cls);
159 160
160 GNUNET_free(call); 161 GNUNET_free(call);
161 return FALSE; 162 return FALSE;
@@ -163,7 +164,8 @@ _application_event_call(gpointer user_data)
163 164
164void 165void
165application_call_event(MESSENGER_Application *app, 166application_call_event(MESSENGER_Application *app,
166 MESSENGER_ApplicationEvent event) 167 MESSENGER_ApplicationEvent event,
168 void *cls)
167{ 169{
168 MESSENGER_ApplicationEventCall *call; 170 MESSENGER_ApplicationEventCall *call;
169 171
@@ -173,6 +175,7 @@ application_call_event(MESSENGER_Application *app,
173 175
174 call->app = app; 176 call->app = app;
175 call->event = event; 177 call->event = event;
178 call->cls = cls;
176 179
177 g_idle_add(_application_event_call, call); 180 g_idle_add(_application_event_call, call);
178} 181}
diff --git a/src/application.h b/src/application.h
index 5801f6d..61aed2a 100644
--- a/src/application.h
+++ b/src/application.h
@@ -30,6 +30,7 @@
30#include "chat/messenger.h" 30#include "chat/messenger.h"
31 31
32#include "ui/messenger.h" 32#include "ui/messenger.h"
33#include "ui/new_platform.h"
33 34
34#include "util.h" 35#include "util.h"
35 36
@@ -61,6 +62,8 @@ typedef struct MESSENGER_Application
61 gboolean mobile; 62 gboolean mobile;
62 63
63 UI_MESSENGER_Handle messenger; 64 UI_MESSENGER_Handle messenger;
65
66 UI_NEW_PLATFORM_Handle new_platform;
64 } ui; 67 } ui;
65} MESSENGER_Application; 68} MESSENGER_Application;
66 69
@@ -72,11 +75,13 @@ application_init(MESSENGER_Application *app,
72void 75void
73application_run(MESSENGER_Application *app); 76application_run(MESSENGER_Application *app);
74 77
75typedef void (*MESSENGER_ApplicationEvent) (MESSENGER_Application *app); 78typedef void (*MESSENGER_ApplicationEvent) (MESSENGER_Application *app,
79 void *cls);
76 80
77void 81void
78application_call_event(MESSENGER_Application *app, 82application_call_event(MESSENGER_Application *app,
79 MESSENGER_ApplicationEvent event); 83 MESSENGER_ApplicationEvent event,
84 void *cls);
80 85
81void 86void
82application_exit(MESSENGER_Application *app, 87application_exit(MESSENGER_Application *app,
diff --git a/src/chat/messenger.c b/src/chat/messenger.c
index 62b93e8..72ba93a 100644
--- a/src/chat/messenger.c
+++ b/src/chat/messenger.c
@@ -57,10 +57,34 @@ _chat_messenger_message(void *cls,
57{ 57{
58 MESSENGER_Application *app = (MESSENGER_Application*) cls; 58 MESSENGER_Application *app = (MESSENGER_Application*) cls;
59 59
60 if (GNUNET_CHAT_KIND_LOGIN == GNUNET_CHAT_message_get_kind(message)) 60 const enum GNUNET_CHAT_MessageKind kind = GNUNET_CHAT_message_get_kind(message);
61 application_call_event(app, event_update_profile); 61 const struct GNUNET_CHAT_Contact* sender = GNUNET_CHAT_message_get_sender(message);
62 else if (GNUNET_CHAT_KIND_TEXT == GNUNET_CHAT_message_get_kind(message)) 62
63 printf("%s\n", GNUNET_CHAT_message_get_text(message)); 63 struct GNUNET_TIME_Absolute time = GNUNET_CHAT_message_get_timestamp(message);
64
65 printf("- %d, %lu", kind, time.abs_value_us);
66
67 if (sender)
68 printf(", %s\n", GNUNET_CHAT_contact_get_name(sender));
69 else
70 printf("\n");
71
72 switch (kind)
73 {
74 case GNUNET_CHAT_KIND_LOGIN:
75 application_call_event(app, event_update_profile, NULL);
76 break;
77 case GNUNET_CHAT_KIND_TEXT:
78 printf("text: %s\n", GNUNET_CHAT_message_get_text(message));
79 break;
80 case GNUNET_CHAT_KIND_JOIN:
81 if (GNUNET_YES == GNUNET_CHAT_message_is_sent(message))
82 application_call_event(app, event_update_chats, context);
83
84 break;
85 default:
86 break;
87 }
64 88
65 return GNUNET_YES; 89 return GNUNET_YES;
66} 90}
diff --git a/src/event.c b/src/event.c
index e023613..5ad3016 100644
--- a/src/event.c
+++ b/src/event.c
@@ -73,7 +73,8 @@ _clear_each_widget(GtkWidget *widget,
73} 73}
74 74
75void 75void
76event_update_profile(MESSENGER_Application *app) 76event_update_profile(MESSENGER_Application *app,
77 UNUSED void *cls)
77{ 78{
78 UI_MESSENGER_Handle *ui = &(app->ui.messenger); 79 UI_MESSENGER_Handle *ui = &(app->ui.messenger);
79 CHAT_MESSENGER_Handle *chat = &(app->chat.messenger); 80 CHAT_MESSENGER_Handle *chat = &(app->chat.messenger);
@@ -95,13 +96,28 @@ event_update_profile(MESSENGER_Application *app)
95 GNUNET_CHAT_iterate_contacts(chat->handle, _iterate_profile_contacts, app); 96 GNUNET_CHAT_iterate_contacts(chat->handle, _iterate_profile_contacts, app);
96 GNUNET_CHAT_iterate_groups(chat->handle, _iterate_profile_groups, app); 97 GNUNET_CHAT_iterate_groups(chat->handle, _iterate_profile_groups, app);
97 98
98 UI_CHAT_ENTRY_Handle *entry = ui_chat_entry_new();
99 gtk_container_add(GTK_CONTAINER(ui->chats_listbox), entry->entry_box);
100 g_free(entry);
101
102 for (int i = 0; i < 8; i++) { 99 for (int i = 0; i < 8; i++) {
103 UI_MESSAGE_Handle *message = ui_message_new(app, i % 2 == 0); 100 UI_MESSAGE_Handle *message = ui_message_new(app, i % 2 == 0);
104 gtk_container_add(GTK_CONTAINER(ui->messages_listbox), message->message_box); 101 gtk_container_add(GTK_CONTAINER(ui->messages_listbox), message->message_box);
105 g_free(message); 102 g_free(message); // TODO: this is just a test!
106 } 103 }
107} 104}
105
106void
107event_update_chats(MESSENGER_Application *app,
108 void *cls)
109{
110 struct GNUNET_CHAT_Context *context = (struct GNUNET_CHAT_Context*) cls;
111
112 if (GNUNET_CHAT_context_get_user_pointer(context))
113 return;
114
115 UI_MESSENGER_Handle *ui = &(app->ui.messenger);
116
117 UI_CHAT_ENTRY_Handle *entry = ui_chat_entry_new();
118 gtk_container_add(GTK_CONTAINER(ui->chats_listbox), entry->entry_box);
119 g_free(entry); // TODO: free already?
120
121 // TODO: put something better here to attach it!
122 GNUNET_CHAT_context_set_user_pointer(context, ui);
123}
diff --git a/src/event.h b/src/event.h
index 4beb589..6b5dce3 100644
--- a/src/event.h
+++ b/src/event.h
@@ -28,6 +28,11 @@
28#include "application.h" 28#include "application.h"
29 29
30void 30void
31event_update_profile(MESSENGER_Application *app); 31event_update_profile(MESSENGER_Application *app,
32 void *cls);
33
34void
35event_update_chats(MESSENGER_Application *app,
36 void *cls);
32 37
33#endif /* EVENT_H_ */ 38#endif /* EVENT_H_ */
diff --git a/src/ui/messenger.c b/src/ui/messenger.c
index 196b00a..4e31952 100644
--- a/src/ui/messenger.c
+++ b/src/ui/messenger.c
@@ -24,6 +24,7 @@
24 24
25#include "messenger.h" 25#include "messenger.h"
26 26
27#include "new_platform.h"
27#include "../application.h" 28#include "../application.h"
28 29
29static void 30static void
@@ -53,6 +54,19 @@ handle_account_details_button_click(UNUSED GtkButton* button,
53} 54}
54 55
55static void 56static void
57handle_new_platform_button_click(UNUSED GtkButton* button,
58 gpointer user_data)
59{
60 MESSENGER_Application *app = (MESSENGER_Application*) user_data;
61
62 hdy_flap_set_reveal_flap(HDY_FLAP(app->ui.messenger.flap_user_details), FALSE);
63
64 ui_new_platform_dialog_init(app, &(app->ui.new_platform));
65
66 gtk_widget_show(GTK_WIDGET(app->ui.new_platform.platform_dialog));
67}
68
69static void
56handle_chats_listbox_row_activated(UNUSED GtkListBox* listbox, 70handle_chats_listbox_row_activated(UNUSED GtkListBox* listbox,
57 UNUSED GtkListBoxRow* row, 71 UNUSED GtkListBoxRow* row,
58 gpointer user_data) 72 gpointer user_data)
@@ -215,6 +229,13 @@ ui_messenger_init(MESSENGER_Application *app,
215 gtk_builder_get_object(builder, "new_platform_button") 229 gtk_builder_get_object(builder, "new_platform_button")
216 ); 230 );
217 231
232 g_signal_connect(
233 handle->new_platform_button,
234 "clicked",
235 G_CALLBACK(handle_new_platform_button_click),
236 app
237 );
238
218 handle->contacts_button = GTK_BUTTON( 239 handle->contacts_button = GTK_BUTTON(
219 gtk_builder_get_object(builder, "contacts_button") 240 gtk_builder_get_object(builder, "contacts_button")
220 ); 241 );
diff --git a/src/ui/new_platform.c b/src/ui/new_platform.c
new file mode 100644
index 0000000..46384c0
--- /dev/null
+++ b/src/ui/new_platform.c
@@ -0,0 +1,122 @@
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/new_platform.h
23 */
24
25#include "new_platform.h"
26
27#include "../application.h"
28
29static void
30handle_platform_entry_changed(GtkEditable *editable,
31 gpointer user_data)
32{
33 HdyAvatar *avatar = HDY_AVATAR(user_data);
34 GtkEntry *entry = GTK_ENTRY(editable);
35
36 hdy_avatar_set_text(avatar, gtk_entry_get_text(entry));
37}
38
39static void
40handle_cancel_button_click(UNUSED GtkButton *button,
41 gpointer user_data)
42{
43 GtkDialog *dialog = GTK_DIALOG(user_data);
44 gtk_window_close(GTK_WINDOW(dialog));
45}
46
47static void
48handle_confirm_button_click(UNUSED GtkButton *button,
49 gpointer user_data)
50{
51 MESSENGER_Application *app = (MESSENGER_Application*) user_data;
52
53 const char *topic = gtk_entry_get_text(app->ui.new_platform.platform_entry);
54
55 GNUNET_CHAT_group_create(app->chat.messenger.handle, topic);
56
57 gtk_window_close(GTK_WINDOW(app->ui.new_platform.platform_dialog));
58}
59
60void
61ui_new_platform_dialog_init(MESSENGER_Application *app,
62 UI_NEW_PLATFORM_Handle *handle)
63{
64 GtkBuilder* builder = gtk_builder_new_from_file("resources/ui/new_platform.ui");
65
66 handle->platform_dialog = GTK_DIALOG(
67 gtk_builder_get_object(builder, "platform_dialog")
68 );
69
70 gtk_window_set_title(
71 GTK_WINDOW(handle->platform_dialog),
72 "New Platform"
73 );
74
75 gtk_window_set_transient_for(
76 GTK_WINDOW(handle->platform_dialog),
77 GTK_WINDOW(app->ui.messenger.main_window)
78 );
79
80 gtk_window_set_modal(GTK_WINDOW(handle->platform_dialog), TRUE);
81
82 handle->platform_avatar = HDY_AVATAR(
83 gtk_builder_get_object(builder, "platform_avatar")
84 );
85
86 handle->platform_avatar_file = GTK_FILE_CHOOSER_BUTTON(
87 gtk_builder_get_object(builder, "platform_avatar_file")
88 );
89
90 handle->platform_entry = GTK_ENTRY(
91 gtk_builder_get_object(builder, "platform_entry")
92 );
93
94 g_signal_connect(
95 handle->platform_entry,
96 "changed",
97 G_CALLBACK(handle_platform_entry_changed),
98 handle->platform_avatar
99 );
100
101 handle->cancel_button = GTK_BUTTON(
102 gtk_builder_get_object(builder, "cancel_button")
103 );
104
105 g_signal_connect(
106 handle->cancel_button,
107 "clicked",
108 G_CALLBACK(handle_cancel_button_click),
109 handle->platform_dialog
110 );
111
112 handle->confirm_button = GTK_BUTTON(
113 gtk_builder_get_object(builder, "confirm_button")
114 );
115
116 g_signal_connect(
117 handle->confirm_button,
118 "clicked",
119 G_CALLBACK(handle_confirm_button_click),
120 app
121 );
122}
diff --git a/src/ui/new_platform.h b/src/ui/new_platform.h
new file mode 100644
index 0000000..745c4de
--- /dev/null
+++ b/src/ui/new_platform.h
@@ -0,0 +1,47 @@
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/new_platform.h
23 */
24
25#ifndef UI_NEW_PLATFORM_H_
26#define UI_NEW_PLATFORM_H_
27
28#include "messenger.h"
29
30typedef struct UI_NEW_PLATFORM_Handle
31{
32 GtkDialog* platform_dialog;
33
34 HdyAvatar* platform_avatar;
35 GtkFileChooserButton* platform_avatar_file;
36
37 GtkEntry* platform_entry;
38
39 GtkButton* cancel_button;
40 GtkButton* confirm_button;
41} UI_NEW_PLATFORM_Handle;
42
43void
44ui_new_platform_dialog_init(MESSENGER_Application *app,
45 UI_NEW_PLATFORM_Handle *handle);
46
47#endif /* UI_NEW_PLATFORM_H_ */