diff options
author | TheJackiMonster <thejackimonster@gmail.com> | 2021-11-24 03:18:23 +0100 |
---|---|---|
committer | TheJackiMonster <thejackimonster@gmail.com> | 2021-11-24 03:18:23 +0100 |
commit | 5df934d452aaedf319028740987de0e0dcac52d5 (patch) | |
tree | 19ea3b7469a7e55e227f6da42c13972e56f66f83 | |
parent | 724f7738ed6d60bccabb428c2ae87faba9033b0c (diff) | |
download | messenger-gtk-5df934d452aaedf319028740987de0e0dcac52d5.tar.gz messenger-gtk-5df934d452aaedf319028740987de0e0dcac52d5.zip |
Added invitations for private chats and cleaned up status messages
Signed-off-by: TheJackiMonster <thejackimonster@gmail.com>
-rw-r--r-- | resources/css/style.css | 2 | ||||
-rw-r--r-- | resources/ui/message-sent.ui | 3 | ||||
-rw-r--r-- | resources/ui/message-status.ui | 140 | ||||
-rw-r--r-- | resources/ui/message.ui | 3 | ||||
-rw-r--r-- | src/application.c | 62 | ||||
-rw-r--r-- | src/application.h | 23 | ||||
-rw-r--r-- | src/chat/messenger.c | 45 | ||||
-rw-r--r-- | src/event.c | 112 | ||||
-rw-r--r-- | src/event.h | 21 | ||||
-rw-r--r-- | src/ui/message.c | 42 | ||||
-rw-r--r-- | src/ui/message.h | 14 |
11 files changed, 369 insertions, 98 deletions
diff --git a/resources/css/style.css b/resources/css/style.css index 743e0c1..a75a5e2 100644 --- a/resources/css/style.css +++ b/resources/css/style.css | |||
@@ -58,7 +58,7 @@ | |||
58 | } | 58 | } |
59 | 59 | ||
60 | .message-box.status > .message-content { | 60 | .message-box.status > .message-content { |
61 | padding: 2px 12px; | 61 | padding: 2px 4px; |
62 | } | 62 | } |
63 | 63 | ||
64 | .settings-entry { | 64 | .settings-entry { |
diff --git a/resources/ui/message-sent.ui b/resources/ui/message-sent.ui index 6fd9e04..25ac52c 100644 --- a/resources/ui/message-sent.ui +++ b/resources/ui/message-sent.ui | |||
@@ -59,7 +59,6 @@ Author: Tobias Frisch | |||
59 | <object class="GtkLabel" id="text_label"> | 59 | <object class="GtkLabel" id="text_label"> |
60 | <property name="visible">True</property> | 60 | <property name="visible">True</property> |
61 | <property name="can-focus">False</property> | 61 | <property name="can-focus">False</property> |
62 | <property name="label" translatable="yes">My evil comment text is awesome! This is coming to the Pinephone which will be extremely awesome and this text may only cut some borders in certain areas!!!</property> | ||
63 | <property name="wrap">True</property> | 62 | <property name="wrap">True</property> |
64 | <property name="max-width-chars">64</property> | 63 | <property name="max-width-chars">64</property> |
65 | <property name="xalign">0</property> | 64 | <property name="xalign">0</property> |
@@ -92,7 +91,6 @@ Author: Tobias Frisch | |||
92 | <object class="GtkLabel" id="timestamp_label"> | 91 | <object class="GtkLabel" id="timestamp_label"> |
93 | <property name="visible">True</property> | 92 | <property name="visible">True</property> |
94 | <property name="can-focus">False</property> | 93 | <property name="can-focus">False</property> |
95 | <property name="label" translatable="yes">0min</property> | ||
96 | <attributes> | 94 | <attributes> |
97 | <attribute name="weight" value="light"/> | 95 | <attribute name="weight" value="light"/> |
98 | </attributes> | 96 | </attributes> |
@@ -120,7 +118,6 @@ Author: Tobias Frisch | |||
120 | <object class="GtkLabel" id="sender_label"> | 118 | <object class="GtkLabel" id="sender_label"> |
121 | <property name="visible">True</property> | 119 | <property name="visible">True</property> |
122 | <property name="can-focus">False</property> | 120 | <property name="can-focus">False</property> |
123 | <property name="label" translatable="yes">User</property> | ||
124 | <attributes> | 121 | <attributes> |
125 | <attribute name="weight" value="semibold"/> | 122 | <attribute name="weight" value="semibold"/> |
126 | </attributes> | 123 | </attributes> |
diff --git a/resources/ui/message-status.ui b/resources/ui/message-status.ui index 54d0d0b..7d5b233 100644 --- a/resources/ui/message-status.ui +++ b/resources/ui/message-status.ui | |||
@@ -22,7 +22,8 @@ Author: Tobias Frisch | |||
22 | --> | 22 | --> |
23 | <interface> | 23 | <interface> |
24 | <requires lib="gtk+" version="3.24"/> | 24 | <requires lib="gtk+" version="3.24"/> |
25 | <object class="GtkBox"> | 25 | <requires lib="libhandy" version="1.2"/> |
26 | <object class="GtkBox" id="message_box"> | ||
26 | <property name="visible">True</property> | 27 | <property name="visible">True</property> |
27 | <property name="can-focus">False</property> | 28 | <property name="can-focus">False</property> |
28 | <child> | 29 | <child> |
@@ -36,17 +37,113 @@ Author: Tobias Frisch | |||
36 | <object class="GtkBox"> | 37 | <object class="GtkBox"> |
37 | <property name="visible">True</property> | 38 | <property name="visible">True</property> |
38 | <property name="can-focus">False</property> | 39 | <property name="can-focus">False</property> |
39 | <property name="orientation">vertical</property> | 40 | <property name="spacing">8</property> |
40 | <child> | 41 | <child> |
41 | <object class="GtkLabel" id="status_label"> | 42 | <object class="GtkButton" id="deny_button"> |
43 | <property name="can-focus">True</property> | ||
44 | <property name="receives-default">True</property> | ||
45 | <property name="relief">none</property> | ||
46 | <child> | ||
47 | <object class="GtkImage"> | ||
48 | <property name="visible">True</property> | ||
49 | <property name="can-focus">False</property> | ||
50 | <property name="icon-name">edit-delete-symbolic</property> | ||
51 | </object> | ||
52 | </child> | ||
53 | </object> | ||
54 | <packing> | ||
55 | <property name="expand">False</property> | ||
56 | <property name="fill">True</property> | ||
57 | <property name="position">0</property> | ||
58 | </packing> | ||
59 | </child> | ||
60 | <child> | ||
61 | <object class="GtkBox"> | ||
42 | <property name="visible">True</property> | 62 | <property name="visible">True</property> |
43 | <property name="can-focus">False</property> | 63 | <property name="can-focus">False</property> |
44 | <property name="label" translatable="yes">status information</property> | 64 | <property name="orientation">vertical</property> |
65 | <child> | ||
66 | <object class="GtkLabel" id="text_label"> | ||
67 | <property name="visible">True</property> | ||
68 | <property name="can-focus">False</property> | ||
69 | <property name="label" translatable="yes">invited you to a chat</property> | ||
70 | <property name="justify">center</property> | ||
71 | <property name="wrap">True</property> | ||
72 | <property name="xalign">0.5</property> | ||
73 | </object> | ||
74 | <packing> | ||
75 | <property name="expand">True</property> | ||
76 | <property name="fill">True</property> | ||
77 | <property name="position">0</property> | ||
78 | </packing> | ||
79 | </child> | ||
80 | <child> | ||
81 | <object class="GtkBox"> | ||
82 | <property name="visible">True</property> | ||
83 | <property name="can-focus">False</property> | ||
84 | <property name="spacing">4</property> | ||
85 | <child> | ||
86 | <object class="GtkImage" id="read_receipt_image"> | ||
87 | <property name="can-focus">False</property> | ||
88 | <property name="xalign">1</property> | ||
89 | <property name="icon-name">emblem-default-symbolic</property> | ||
90 | </object> | ||
91 | <packing> | ||
92 | <property name="expand">False</property> | ||
93 | <property name="fill">True</property> | ||
94 | <property name="pack-type">end</property> | ||
95 | <property name="position">0</property> | ||
96 | </packing> | ||
97 | </child> | ||
98 | <child> | ||
99 | <object class="GtkLabel" id="timestamp_label"> | ||
100 | <property name="can-focus">False</property> | ||
101 | <property name="justify">right</property> | ||
102 | <property name="xalign">1</property> | ||
103 | <attributes> | ||
104 | <attribute name="weight" value="light"/> | ||
105 | </attributes> | ||
106 | </object> | ||
107 | <packing> | ||
108 | <property name="expand">False</property> | ||
109 | <property name="fill">True</property> | ||
110 | <property name="pack-type">end</property> | ||
111 | <property name="position">1</property> | ||
112 | </packing> | ||
113 | </child> | ||
114 | </object> | ||
115 | <packing> | ||
116 | <property name="expand">False</property> | ||
117 | <property name="fill">True</property> | ||
118 | <property name="pack-type">end</property> | ||
119 | <property name="position">1</property> | ||
120 | </packing> | ||
121 | </child> | ||
122 | </object> | ||
123 | <packing> | ||
124 | <property name="expand">True</property> | ||
125 | <property name="fill">True</property> | ||
126 | <property name="position">1</property> | ||
127 | </packing> | ||
128 | </child> | ||
129 | <child> | ||
130 | <object class="GtkButton" id="accept_button"> | ||
131 | <property name="can-focus">True</property> | ||
132 | <property name="receives-default">True</property> | ||
133 | <property name="relief">none</property> | ||
134 | <child> | ||
135 | <object class="GtkImage"> | ||
136 | <property name="visible">True</property> | ||
137 | <property name="can-focus">False</property> | ||
138 | <property name="icon-name">emblem-ok-symbolic</property> | ||
139 | </object> | ||
140 | </child> | ||
45 | </object> | 141 | </object> |
46 | <packing> | 142 | <packing> |
47 | <property name="expand">False</property> | 143 | <property name="expand">False</property> |
48 | <property name="fill">True</property> | 144 | <property name="fill">True</property> |
49 | <property name="position">0</property> | 145 | <property name="pack-type">end</property> |
146 | <property name="position">2</property> | ||
50 | </packing> | 147 | </packing> |
51 | </child> | 148 | </child> |
52 | <style> | 149 | <style> |
@@ -55,13 +152,36 @@ Author: Tobias Frisch | |||
55 | </object> | 152 | </object> |
56 | </child> | 153 | </child> |
57 | <child type="label"> | 154 | <child type="label"> |
58 | <object class="GtkLabel" id="sender_label"> | 155 | <object class="GtkBox"> |
59 | <property name="visible">True</property> | 156 | <property name="visible">True</property> |
60 | <property name="can-focus">False</property> | 157 | <property name="can-focus">False</property> |
61 | <property name="label" translatable="yes">User</property> | 158 | <property name="spacing">4</property> |
62 | <attributes> | 159 | <child> |
63 | <attribute name="weight" value="semibold"/> | 160 | <object class="HdyAvatar" id="sender_avatar"> |
64 | </attributes> | 161 | <property name="can-focus">False</property> |
162 | <property name="size">24</property> | ||
163 | </object> | ||
164 | <packing> | ||
165 | <property name="expand">False</property> | ||
166 | <property name="fill">True</property> | ||
167 | <property name="position">0</property> | ||
168 | </packing> | ||
169 | </child> | ||
170 | <child> | ||
171 | <object class="GtkLabel" id="sender_label"> | ||
172 | <property name="visible">True</property> | ||
173 | <property name="can-focus">False</property> | ||
174 | <property name="xalign">0</property> | ||
175 | <attributes> | ||
176 | <attribute name="weight" value="semibold"/> | ||
177 | </attributes> | ||
178 | </object> | ||
179 | <packing> | ||
180 | <property name="expand">True</property> | ||
181 | <property name="fill">True</property> | ||
182 | <property name="position">1</property> | ||
183 | </packing> | ||
184 | </child> | ||
65 | </object> | 185 | </object> |
66 | </child> | 186 | </child> |
67 | <style> | 187 | <style> |
diff --git a/resources/ui/message.ui b/resources/ui/message.ui index ceb84f4..42bde4d 100644 --- a/resources/ui/message.ui +++ b/resources/ui/message.ui | |||
@@ -58,7 +58,6 @@ Author: Tobias Frisch | |||
58 | <object class="GtkLabel" id="text_label"> | 58 | <object class="GtkLabel" id="text_label"> |
59 | <property name="visible">True</property> | 59 | <property name="visible">True</property> |
60 | <property name="can-focus">False</property> | 60 | <property name="can-focus">False</property> |
61 | <property name="label" translatable="yes">My evil comment text is awesome! This is coming to the Pinephone which will be extremely awesome and this text may only cut some borders in certain areas!!!</property> | ||
62 | <property name="wrap">True</property> | 61 | <property name="wrap">True</property> |
63 | <property name="max-width-chars">64</property> | 62 | <property name="max-width-chars">64</property> |
64 | <property name="xalign">0</property> | 63 | <property name="xalign">0</property> |
@@ -90,7 +89,6 @@ Author: Tobias Frisch | |||
90 | <object class="GtkLabel" id="timestamp_label"> | 89 | <object class="GtkLabel" id="timestamp_label"> |
91 | <property name="visible">True</property> | 90 | <property name="visible">True</property> |
92 | <property name="can-focus">False</property> | 91 | <property name="can-focus">False</property> |
93 | <property name="label" translatable="yes">0min</property> | ||
94 | <attributes> | 92 | <attributes> |
95 | <attribute name="weight" value="light"/> | 93 | <attribute name="weight" value="light"/> |
96 | </attributes> | 94 | </attributes> |
@@ -118,7 +116,6 @@ Author: Tobias Frisch | |||
118 | <object class="GtkLabel" id="sender_label"> | 116 | <object class="GtkLabel" id="sender_label"> |
119 | <property name="visible">True</property> | 117 | <property name="visible">True</property> |
120 | <property name="can-focus">False</property> | 118 | <property name="can-focus">False</property> |
121 | <property name="label" translatable="yes">User</property> | ||
122 | <attributes> | 119 | <attributes> |
123 | <attribute name="weight" value="semibold"/> | 120 | <attribute name="weight" value="semibold"/> |
124 | </attributes> | 121 | </attributes> |
diff --git a/src/application.c b/src/application.c index 7cb827b..dfb214a 100644 --- a/src/application.c +++ b/src/application.c | |||
@@ -170,8 +170,6 @@ typedef struct MESSENGER_ApplicationEventCall | |||
170 | { | 170 | { |
171 | MESSENGER_Application *app; | 171 | MESSENGER_Application *app; |
172 | MESSENGER_ApplicationEvent event; | 172 | MESSENGER_ApplicationEvent event; |
173 | int argc; | ||
174 | void **argv; | ||
175 | } MESSENGER_ApplicationEventCall; | 173 | } MESSENGER_ApplicationEventCall; |
176 | 174 | ||
177 | static gboolean | 175 | static gboolean |
@@ -180,10 +178,7 @@ _application_event_call(gpointer user_data) | |||
180 | MESSENGER_ApplicationEventCall *call; | 178 | MESSENGER_ApplicationEventCall *call; |
181 | 179 | ||
182 | call = (MESSENGER_ApplicationEventCall*) user_data; | 180 | call = (MESSENGER_ApplicationEventCall*) user_data; |
183 | call->event(call->app, call->argc, call->argv); | 181 | call->event(call->app); |
184 | |||
185 | if (call->argc > 0) | ||
186 | GNUNET_free(call->argv); | ||
187 | 182 | ||
188 | GNUNET_free(call); | 183 | GNUNET_free(call); |
189 | return FALSE; | 184 | return FALSE; |
@@ -191,9 +186,7 @@ _application_event_call(gpointer user_data) | |||
191 | 186 | ||
192 | void | 187 | void |
193 | application_call_event(MESSENGER_Application *app, | 188 | application_call_event(MESSENGER_Application *app, |
194 | MESSENGER_ApplicationEvent event, | 189 | MESSENGER_ApplicationEvent event) |
195 | int argc, | ||
196 | void **argv) | ||
197 | { | 190 | { |
198 | MESSENGER_ApplicationEventCall *call; | 191 | MESSENGER_ApplicationEventCall *call; |
199 | 192 | ||
@@ -203,19 +196,50 @@ application_call_event(MESSENGER_Application *app, | |||
203 | 196 | ||
204 | call->app = app; | 197 | call->app = app; |
205 | call->event = event; | 198 | call->event = event; |
206 | call->argc = argc; | ||
207 | call->argv = NULL; | ||
208 | 199 | ||
209 | if (call->argc > 0) | 200 | g_idle_add(G_SOURCE_FUNC(_application_event_call), call); |
210 | { | 201 | } |
211 | call->argv = GNUNET_new_array(call->argc, void*); | ||
212 | 202 | ||
213 | for (int i = 0; i < call->argc; i++) { | 203 | typedef struct MESSENGER_ApplicationMessageEventCall |
214 | call->argv[i] = argv[i]; | 204 | { |
215 | } | 205 | MESSENGER_Application *app; |
216 | } | 206 | MESSENGER_ApplicationMessageEvent event; |
217 | 207 | ||
218 | g_idle_add(G_SOURCE_FUNC(_application_event_call), call); | 208 | struct GNUNET_CHAT_Context *context; |
209 | const struct GNUNET_CHAT_Message *message; | ||
210 | } MESSENGER_ApplicationMessageEventCall; | ||
211 | |||
212 | static gboolean | ||
213 | _application_message_event_call(gpointer user_data) | ||
214 | { | ||
215 | MESSENGER_ApplicationMessageEventCall *call; | ||
216 | |||
217 | call = (MESSENGER_ApplicationMessageEventCall*) user_data; | ||
218 | call->event(call->app, call->context, call->message); | ||
219 | |||
220 | GNUNET_free(call); | ||
221 | return FALSE; | ||
222 | } | ||
223 | |||
224 | void | ||
225 | application_call_message_event(MESSENGER_Application *app, | ||
226 | MESSENGER_ApplicationMessageEvent event, | ||
227 | struct GNUNET_CHAT_Context *context, | ||
228 | const struct GNUNET_CHAT_Message *message) | ||
229 | { | ||
230 | MESSENGER_ApplicationMessageEventCall *call; | ||
231 | |||
232 | call = (MESSENGER_ApplicationMessageEventCall*) GNUNET_malloc( | ||
233 | sizeof(MESSENGER_ApplicationMessageEventCall) | ||
234 | ); | ||
235 | |||
236 | call->app = app; | ||
237 | call->event = event; | ||
238 | |||
239 | call->context = context; | ||
240 | call->message = message; | ||
241 | |||
242 | g_idle_add(G_SOURCE_FUNC(_application_message_event_call), call); | ||
219 | } | 243 | } |
220 | 244 | ||
221 | void | 245 | void |
diff --git a/src/application.h b/src/application.h index f30ebb8..4ffa2c8 100644 --- a/src/application.h +++ b/src/application.h | |||
@@ -26,6 +26,7 @@ | |||
26 | #define APPLICATION_H_ | 26 | #define APPLICATION_H_ |
27 | 27 | ||
28 | #include <pthread.h> | 28 | #include <pthread.h> |
29 | #include <gnunet/gnunet_chat_lib.h> | ||
29 | 30 | ||
30 | #include "chat/messenger.h" | 31 | #include "chat/messenger.h" |
31 | 32 | ||
@@ -84,15 +85,25 @@ application_init(MESSENGER_Application *app, | |||
84 | void | 85 | void |
85 | application_run(MESSENGER_Application *app); | 86 | application_run(MESSENGER_Application *app); |
86 | 87 | ||
87 | typedef void (*MESSENGER_ApplicationEvent) (MESSENGER_Application *app, | 88 | typedef void (*MESSENGER_ApplicationEvent) ( |
88 | int argc, | 89 | MESSENGER_Application *app |
89 | void **argv); | 90 | ); |
91 | |||
92 | typedef void (*MESSENGER_ApplicationMessageEvent) ( | ||
93 | MESSENGER_Application *app, | ||
94 | struct GNUNET_CHAT_Context *context, | ||
95 | const struct GNUNET_CHAT_Message *msg | ||
96 | ); | ||
90 | 97 | ||
91 | void | 98 | void |
92 | application_call_event(MESSENGER_Application *app, | 99 | application_call_event(MESSENGER_Application *app, |
93 | MESSENGER_ApplicationEvent event, | 100 | MESSENGER_ApplicationEvent event); |
94 | int argc, | 101 | |
95 | void **argv); | 102 | void |
103 | application_call_message_event(MESSENGER_Application *app, | ||
104 | MESSENGER_ApplicationMessageEvent event, | ||
105 | struct GNUNET_CHAT_Context *context, | ||
106 | const struct GNUNET_CHAT_Message *message); | ||
96 | 107 | ||
97 | void | 108 | void |
98 | application_exit(MESSENGER_Application *app, | 109 | application_exit(MESSENGER_Application *app, |
diff --git a/src/chat/messenger.c b/src/chat/messenger.c index 6df3664..9bfe11b 100644 --- a/src/chat/messenger.c +++ b/src/chat/messenger.c | |||
@@ -75,30 +75,51 @@ _chat_messenger_message(void *cls, | |||
75 | { | 75 | { |
76 | case GNUNET_CHAT_KIND_LOGIN: | 76 | case GNUNET_CHAT_KIND_LOGIN: |
77 | { | 77 | { |
78 | application_call_event(app, event_update_profile, 0, NULL); | 78 | application_call_event(app, event_update_profile); |
79 | break; | 79 | break; |
80 | } | 80 | } |
81 | case GNUNET_CHAT_KIND_JOIN: | 81 | case GNUNET_CHAT_KIND_JOIN: |
82 | { | 82 | { |
83 | if (GNUNET_YES == GNUNET_CHAT_message_is_sent(message)) | 83 | application_call_message_event( |
84 | application_call_event(app, event_update_chats, 1, (void**) &context); | 84 | app, |
85 | else | 85 | (GNUNET_YES == GNUNET_CHAT_message_is_sent(message)? |
86 | { | 86 | event_update_chats : |
87 | void* event_data [2] = { context, &message }; | 87 | event_joining_contact |
88 | application_call_event(app, event_joining_contact, 2, event_data); | 88 | ), |
89 | } | 89 | context, |
90 | 90 | message | |
91 | ); | ||
92 | break; | ||
93 | } | ||
94 | case GNUNET_CHAT_KIND_LEAVE: | ||
95 | { | ||
96 | // TODO: add status message | ||
91 | break; | 97 | break; |
92 | } | 98 | } |
93 | case GNUNET_CHAT_KIND_CONTACT: | 99 | case GNUNET_CHAT_KIND_CONTACT: |
94 | { | 100 | { |
95 | 101 | // TODO: update messages and content related to a contacts information | |
102 | // (name and key) | ||
103 | break; | ||
104 | } | ||
105 | case GNUNET_CHAT_KIND_INVITATION: | ||
106 | { | ||
107 | application_call_message_event( | ||
108 | app, | ||
109 | event_invitation, | ||
110 | context, | ||
111 | message | ||
112 | ); | ||
96 | break; | 113 | break; |
97 | } | 114 | } |
98 | case GNUNET_CHAT_KIND_TEXT: | 115 | case GNUNET_CHAT_KIND_TEXT: |
99 | { | 116 | { |
100 | void* event_data [2] = { context, &message }; | 117 | application_call_message_event( |
101 | application_call_event(app, event_receive_message, 2, event_data); | 118 | app, |
119 | event_receive_message, | ||
120 | context, | ||
121 | message | ||
122 | ); | ||
102 | break; | 123 | break; |
103 | } | 124 | } |
104 | default: | 125 | default: |
diff --git a/src/event.c b/src/event.c index 16b709e..dfc7b8e 100644 --- a/src/event.c +++ b/src/event.c | |||
@@ -117,9 +117,7 @@ _clear_each_widget(GtkWidget *widget, | |||
117 | } | 117 | } |
118 | 118 | ||
119 | void | 119 | void |
120 | event_update_profile(MESSENGER_Application *app, | 120 | event_update_profile(MESSENGER_Application *app) |
121 | UNUSED int argc, | ||
122 | UNUSED void **argv) | ||
123 | { | 121 | { |
124 | UI_MESSENGER_Handle *ui = &(app->ui.messenger); | 122 | UI_MESSENGER_Handle *ui = &(app->ui.messenger); |
125 | CHAT_MESSENGER_Handle *chat = &(app->chat.messenger); | 123 | CHAT_MESSENGER_Handle *chat = &(app->chat.messenger); |
@@ -164,14 +162,9 @@ event_update_profile(MESSENGER_Application *app, | |||
164 | 162 | ||
165 | void | 163 | void |
166 | event_update_chats(MESSENGER_Application *app, | 164 | event_update_chats(MESSENGER_Application *app, |
167 | int argc, | 165 | struct GNUNET_CHAT_Context *context, |
168 | void **argv) | 166 | UNUSED const struct GNUNET_CHAT_Message *msg) |
169 | { | 167 | { |
170 | if (argc < 1) | ||
171 | return; | ||
172 | |||
173 | struct GNUNET_CHAT_Context *context = (struct GNUNET_CHAT_Context*) argv[0]; | ||
174 | |||
175 | if (GNUNET_CHAT_context_get_user_pointer(context)) | 168 | if (GNUNET_CHAT_context_get_user_pointer(context)) |
176 | return; | 169 | return; |
177 | 170 | ||
@@ -180,46 +173,109 @@ event_update_chats(MESSENGER_Application *app, | |||
180 | 173 | ||
181 | void | 174 | void |
182 | event_joining_contact(MESSENGER_Application *app, | 175 | event_joining_contact(MESSENGER_Application *app, |
183 | int argc, | 176 | struct GNUNET_CHAT_Context *context, |
184 | void **argv) | 177 | const struct GNUNET_CHAT_Message *msg) |
185 | { | 178 | { |
186 | if (argc < 2) | 179 | UI_CHAT_ENTRY_Handle *handle = GNUNET_CHAT_context_get_user_pointer(context); |
180 | |||
181 | if (!handle) | ||
187 | return; | 182 | return; |
188 | 183 | ||
189 | struct GNUNET_CHAT_Context *context = (struct GNUNET_CHAT_Context*) argv[0]; | 184 | UI_MESSAGE_Handle *message = ui_message_new(app, UI_MESSAGE_STATUS); |
185 | |||
186 | const struct GNUNET_CHAT_Contact *contact = GNUNET_CHAT_message_get_sender( | ||
187 | msg | ||
188 | ); | ||
189 | |||
190 | const char *sender = GNUNET_CHAT_contact_get_name(contact); | ||
191 | |||
192 | hdy_avatar_set_text(message->sender_avatar, sender? sender : ""); | ||
193 | gtk_label_set_text(message->sender_label, sender? sender : ""); | ||
194 | |||
195 | gtk_label_set_text(message->text_label, "joined the chat"); | ||
196 | |||
197 | gtk_container_add( | ||
198 | GTK_CONTAINER(handle->chat->messages_listbox), | ||
199 | message->message_box | ||
200 | ); | ||
201 | |||
202 | ui_message_delete(message); | ||
203 | } | ||
204 | |||
205 | static void | ||
206 | _event_invitation_accept_click(UNUSED GtkButton *button, | ||
207 | gpointer user_data) | ||
208 | { | ||
209 | struct GNUNET_CHAT_Invitation *invitation = ( | ||
210 | (struct GNUNET_CHAT_Invitation*) user_data | ||
211 | ); | ||
212 | |||
213 | GNUNET_CHAT_invitation_accept(invitation); | ||
214 | } | ||
190 | 215 | ||
216 | void | ||
217 | event_invitation(MESSENGER_Application *app, | ||
218 | struct GNUNET_CHAT_Context *context, | ||
219 | const struct GNUNET_CHAT_Message *msg) | ||
220 | { | ||
191 | UI_CHAT_ENTRY_Handle *handle = GNUNET_CHAT_context_get_user_pointer(context); | 221 | UI_CHAT_ENTRY_Handle *handle = GNUNET_CHAT_context_get_user_pointer(context); |
192 | 222 | ||
193 | if (!handle) | 223 | if (!handle) |
194 | return; | 224 | return; |
195 | 225 | ||
196 | const struct GNUNET_CHAT_Message *msg; | 226 | struct GNUNET_CHAT_Invitation *invitation; |
197 | msg = *((const struct GNUNET_CHAT_Message**) argv[1]); | 227 | invitation = GNUNET_CHAT_message_get_invitation(msg); |
228 | |||
229 | if (!invitation) | ||
230 | return; | ||
231 | |||
232 | UI_MESSAGE_Handle *message = ui_message_new(app, UI_MESSAGE_STATUS); | ||
233 | |||
234 | const struct GNUNET_CHAT_Contact *contact = GNUNET_CHAT_message_get_sender( | ||
235 | msg | ||
236 | ); | ||
237 | |||
238 | const char *sender = GNUNET_CHAT_contact_get_name(contact); | ||
239 | |||
240 | hdy_avatar_set_text(message->sender_avatar, sender? sender : ""); | ||
241 | gtk_label_set_text(message->sender_label, sender? sender : ""); | ||
242 | |||
243 | gtk_label_set_text(message->text_label, "invited you to a chat"); | ||
244 | |||
245 | g_signal_connect( | ||
246 | message->accept_button, | ||
247 | "clicked", | ||
248 | G_CALLBACK(_event_invitation_accept_click), | ||
249 | invitation | ||
250 | ); | ||
251 | |||
252 | gtk_widget_show(GTK_WIDGET(message->deny_button)); | ||
253 | gtk_widget_show(GTK_WIDGET(message->accept_button)); | ||
254 | |||
255 | gtk_container_add( | ||
256 | GTK_CONTAINER(handle->chat->messages_listbox), | ||
257 | message->message_box | ||
258 | ); | ||
198 | 259 | ||
199 | // | 260 | ui_message_delete(message); |
200 | } | 261 | } |
201 | 262 | ||
202 | void | 263 | void |
203 | event_receive_message(MESSENGER_Application *app, | 264 | event_receive_message(MESSENGER_Application *app, |
204 | int argc, | 265 | struct GNUNET_CHAT_Context *context, |
205 | void **argv) | 266 | const struct GNUNET_CHAT_Message *msg) |
206 | { | 267 | { |
207 | if (argc < 2) | ||
208 | return; | ||
209 | |||
210 | struct GNUNET_CHAT_Context *context = (struct GNUNET_CHAT_Context*) argv[0]; | ||
211 | |||
212 | UI_CHAT_ENTRY_Handle *handle = GNUNET_CHAT_context_get_user_pointer(context); | 268 | UI_CHAT_ENTRY_Handle *handle = GNUNET_CHAT_context_get_user_pointer(context); |
213 | 269 | ||
214 | if (!handle) | 270 | if (!handle) |
215 | return; | 271 | return; |
216 | 272 | ||
217 | const struct GNUNET_CHAT_Message *msg; | ||
218 | msg = *((const struct GNUNET_CHAT_Message**) argv[1]); | ||
219 | |||
220 | const int sent = GNUNET_CHAT_message_is_sent(msg); | 273 | const int sent = GNUNET_CHAT_message_is_sent(msg); |
221 | 274 | ||
222 | UI_MESSAGE_Handle *message = ui_message_new(app, GNUNET_YES == sent); | 275 | UI_MESSAGE_Handle *message = ui_message_new( |
276 | app, | ||
277 | GNUNET_YES == sent? UI_MESSAGE_SENT : UI_MESSAGE_DEFAULT | ||
278 | ); | ||
223 | 279 | ||
224 | if (GNUNET_YES != sent) | 280 | if (GNUNET_YES != sent) |
225 | { | 281 | { |
diff --git a/src/event.h b/src/event.h index a4b7e7c..38890b2 100644 --- a/src/event.h +++ b/src/event.h | |||
@@ -28,23 +28,26 @@ | |||
28 | #include "application.h" | 28 | #include "application.h" |
29 | 29 | ||
30 | void | 30 | void |
31 | event_update_profile(MESSENGER_Application *app, | 31 | event_update_profile(MESSENGER_Application *app); |
32 | int argc, | ||
33 | void **argv); | ||
34 | 32 | ||
35 | void | 33 | void |
36 | event_update_chats(MESSENGER_Application *app, | 34 | event_update_chats(MESSENGER_Application *app, |
37 | int argc, | 35 | struct GNUNET_CHAT_Context *context, |
38 | void **argv); | 36 | const struct GNUNET_CHAT_Message *msg); |
39 | 37 | ||
40 | void | 38 | void |
41 | event_joining_contact(MESSENGER_Application *app, | 39 | event_joining_contact(MESSENGER_Application *app, |
42 | int argc, | 40 | struct GNUNET_CHAT_Context *context, |
43 | void **argv); | 41 | const struct GNUNET_CHAT_Message *msg); |
42 | |||
43 | void | ||
44 | event_invitation(MESSENGER_Application *app, | ||
45 | struct GNUNET_CHAT_Context *context, | ||
46 | const struct GNUNET_CHAT_Message *msg); | ||
44 | 47 | ||
45 | void | 48 | void |
46 | event_receive_message(MESSENGER_Application *app, | 49 | event_receive_message(MESSENGER_Application *app, |
47 | int argc, | 50 | struct GNUNET_CHAT_Context *context, |
48 | void **argv); | 51 | const struct GNUNET_CHAT_Message *msg); |
49 | 52 | ||
50 | #endif /* EVENT_H_ */ | 53 | #endif /* EVENT_H_ */ |
diff --git a/src/ui/message.c b/src/ui/message.c index f89f5ef..def4524 100644 --- a/src/ui/message.c +++ b/src/ui/message.c | |||
@@ -28,14 +28,28 @@ | |||
28 | 28 | ||
29 | UI_MESSAGE_Handle* | 29 | UI_MESSAGE_Handle* |
30 | ui_message_new(MESSENGER_Application *app, | 30 | ui_message_new(MESSENGER_Application *app, |
31 | bool sent) | 31 | UI_MESSAGE_Type type) |
32 | { | 32 | { |
33 | UI_MESSAGE_Handle* handle = g_malloc(sizeof(UI_MESSAGE_Handle)); | 33 | UI_MESSAGE_Handle* handle = g_malloc(sizeof(UI_MESSAGE_Handle)); |
34 | 34 | ||
35 | if (sent) | 35 | handle->type = type; |
36 | handle->builder = gtk_builder_new_from_file("resources/ui/message-sent.ui"); | 36 | |
37 | else | 37 | const char *ui_builder_file; |
38 | handle->builder = gtk_builder_new_from_file("resources/ui/message.ui"); | 38 | |
39 | switch (handle->type) | ||
40 | { | ||
41 | case UI_MESSAGE_SENT: | ||
42 | ui_builder_file = "resources/ui/message-sent.ui"; | ||
43 | break; | ||
44 | case UI_MESSAGE_STATUS: | ||
45 | ui_builder_file = "resources/ui/message-status.ui"; | ||
46 | break; | ||
47 | default: | ||
48 | ui_builder_file = "resources/ui/message.ui"; | ||
49 | break; | ||
50 | } | ||
51 | |||
52 | handle->builder = gtk_builder_new_from_file(ui_builder_file); | ||
39 | 53 | ||
40 | handle->message_box = GTK_WIDGET( | 54 | handle->message_box = GTK_WIDGET( |
41 | gtk_builder_get_object(handle->builder, "message_box") | 55 | gtk_builder_get_object(handle->builder, "message_box") |
@@ -49,7 +63,7 @@ ui_message_new(MESSENGER_Application *app, | |||
49 | gtk_builder_get_object(handle->builder, "sender_label") | 63 | gtk_builder_get_object(handle->builder, "sender_label") |
50 | ); | 64 | ); |
51 | 65 | ||
52 | if (sent) | 66 | if (UI_MESSAGE_SENT == handle->type) |
53 | { | 67 | { |
54 | const char *sender = GNUNET_CHAT_get_name(app->chat.messenger.handle); | 68 | const char *sender = GNUNET_CHAT_get_name(app->chat.messenger.handle); |
55 | 69 | ||
@@ -61,6 +75,22 @@ ui_message_new(MESSENGER_Application *app, | |||
61 | gtk_builder_get_object(handle->builder, "text_label") | 75 | gtk_builder_get_object(handle->builder, "text_label") |
62 | ); | 76 | ); |
63 | 77 | ||
78 | if (UI_MESSAGE_STATUS == handle->type) | ||
79 | { | ||
80 | handle->deny_button = GTK_BUTTON( | ||
81 | gtk_builder_get_object(handle->builder, "deny_button") | ||
82 | ); | ||
83 | |||
84 | handle->accept_button = GTK_BUTTON( | ||
85 | gtk_builder_get_object(handle->builder, "accept_button") | ||
86 | ); | ||
87 | } | ||
88 | else | ||
89 | { | ||
90 | handle->deny_button = NULL; | ||
91 | handle->accept_button = NULL; | ||
92 | } | ||
93 | |||
64 | handle->timestamp_label = GTK_LABEL( | 94 | handle->timestamp_label = GTK_LABEL( |
65 | gtk_builder_get_object(handle->builder, "timestamp_label") | 95 | gtk_builder_get_object(handle->builder, "timestamp_label") |
66 | ); | 96 | ); |
diff --git a/src/ui/message.h b/src/ui/message.h index 1b3a80c..333ef75 100644 --- a/src/ui/message.h +++ b/src/ui/message.h | |||
@@ -32,8 +32,17 @@ | |||
32 | 32 | ||
33 | typedef struct MESSENGER_Application MESSENGER_Application; | 33 | typedef struct MESSENGER_Application MESSENGER_Application; |
34 | 34 | ||
35 | typedef enum UI_MESSAGE_Type | ||
36 | { | ||
37 | UI_MESSAGE_DEFAULT = 0, | ||
38 | UI_MESSAGE_SENT = 1, | ||
39 | UI_MESSAGE_STATUS = 2 | ||
40 | } UI_MESSAGE_Type; | ||
41 | |||
35 | typedef struct UI_MESSAGE_Handle | 42 | typedef struct UI_MESSAGE_Handle |
36 | { | 43 | { |
44 | UI_MESSAGE_Type type; | ||
45 | |||
37 | GtkBuilder *builder; | 46 | GtkBuilder *builder; |
38 | GtkWidget *message_box; | 47 | GtkWidget *message_box; |
39 | 48 | ||
@@ -42,13 +51,16 @@ typedef struct UI_MESSAGE_Handle | |||
42 | 51 | ||
43 | GtkLabel *text_label; | 52 | GtkLabel *text_label; |
44 | 53 | ||
54 | GtkButton *deny_button; | ||
55 | GtkButton *accept_button; | ||
56 | |||
45 | GtkLabel *timestamp_label; | 57 | GtkLabel *timestamp_label; |
46 | GtkImage *read_receipt_image; | 58 | GtkImage *read_receipt_image; |
47 | } UI_MESSAGE_Handle; | 59 | } UI_MESSAGE_Handle; |
48 | 60 | ||
49 | UI_MESSAGE_Handle* | 61 | UI_MESSAGE_Handle* |
50 | ui_message_new(MESSENGER_Application *app, | 62 | ui_message_new(MESSENGER_Application *app, |
51 | bool sent); | 63 | UI_MESSAGE_Type type); |
52 | 64 | ||
53 | void | 65 | void |
54 | ui_message_delete(UI_MESSAGE_Handle *handle); | 66 | ui_message_delete(UI_MESSAGE_Handle *handle); |