diff options
author | TheJackiMonster <thejackimonster@gmail.com> | 2021-11-17 12:10:03 +0100 |
---|---|---|
committer | TheJackiMonster <thejackimonster@gmail.com> | 2021-11-17 12:10:03 +0100 |
commit | 8696f9852d5dca0e40497574158e39fde32bd530 (patch) | |
tree | 50af336d021f53076160a2961ba53cfb44b7e65a | |
parent | 6b39e0b9d3c3e27110a6f3b5986e3a58b221c38b (diff) | |
download | messenger-gtk-8696f9852d5dca0e40497574158e39fde32bd530.tar.gz messenger-gtk-8696f9852d5dca0e40497574158e39fde32bd530.zip |
Added contacts dialog to select and open a chat
Signed-off-by: TheJackiMonster <thejackimonster@gmail.com>
-rw-r--r-- | Makefile | 1 | ||||
-rw-r--r-- | resources/ui/contacts.ui | 102 | ||||
-rw-r--r-- | resources/ui/messenger.ui | 1 | ||||
-rw-r--r-- | src/application.h | 2 | ||||
-rw-r--r-- | src/ui/contacts.c | 91 | ||||
-rw-r--r-- | src/ui/contacts.h | 49 | ||||
-rw-r--r-- | src/ui/messenger.c | 21 |
7 files changed, 266 insertions, 1 deletions
@@ -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/contacts.c\ | ||
12 | ui/message.c\ | 13 | ui/message.c\ |
13 | ui/messenger.c\ | 14 | ui/messenger.c\ |
14 | ui/new_contact.c\ | 15 | ui/new_contact.c\ |
diff --git a/resources/ui/contacts.ui b/resources/ui/contacts.ui new file mode 100644 index 0000000..a679cfc --- /dev/null +++ b/resources/ui/contacts.ui | |||
@@ -0,0 +1,102 @@ | |||
1 | <?xml version="1.0" encoding="UTF-8"?> | ||
2 | <!-- Generated with glade 3.38.2 | ||
3 | |||
4 | Copyright (C) 2021 GNUnet e.V. | ||
5 | |||
6 | GNUnet is free software: you can redistribute it and/or modify it | ||
7 | under the terms of the GNU Affero General Public License as published | ||
8 | by the Free Software Foundation, either version 3 of the License, | ||
9 | or (at your option) any later version. | ||
10 | |||
11 | GNUnet is distributed in the hope that it will be useful, but | ||
12 | WITHOUT ANY WARRANTY; without even the implied warranty of | ||
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
14 | Affero General Public License for more details. | ||
15 | |||
16 | You should have received a copy of the GNU Affero General Public License | ||
17 | along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
18 | |||
19 | SPDX-License-Identifier: AGPL3.0-or-later | ||
20 | Author: Tobias Frisch | ||
21 | |||
22 | --> | ||
23 | <interface> | ||
24 | <requires lib="gtk+" version="3.24"/> | ||
25 | <object class="GtkDialog" id="contacts_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/resources/ui/messenger.ui b/resources/ui/messenger.ui index 1c9b2cd..3c60f2e 100644 --- a/resources/ui/messenger.ui +++ b/resources/ui/messenger.ui | |||
@@ -113,7 +113,6 @@ Author: Tobias Frisch | |||
113 | <object class="GtkListBox" id="chats_listbox"> | 113 | <object class="GtkListBox" id="chats_listbox"> |
114 | <property name="visible">True</property> | 114 | <property name="visible">True</property> |
115 | <property name="can-focus">False</property> | 115 | <property name="can-focus">False</property> |
116 | <property name="selection-mode">none</property> | ||
117 | </object> | 116 | </object> |
118 | </child> | 117 | </child> |
119 | </object> | 118 | </object> |
diff --git a/src/application.h b/src/application.h index 9601ac5..4a56ffd 100644 --- a/src/application.h +++ b/src/application.h | |||
@@ -29,6 +29,7 @@ | |||
29 | 29 | ||
30 | #include "chat/messenger.h" | 30 | #include "chat/messenger.h" |
31 | 31 | ||
32 | #include "ui/contacts.h" | ||
32 | #include "ui/messenger.h" | 33 | #include "ui/messenger.h" |
33 | #include "ui/new_contact.h" | 34 | #include "ui/new_contact.h" |
34 | #include "ui/new_platform.h" | 35 | #include "ui/new_platform.h" |
@@ -68,6 +69,7 @@ typedef struct MESSENGER_Application | |||
68 | 69 | ||
69 | UI_NEW_CONTACT_Handle new_contact; | 70 | UI_NEW_CONTACT_Handle new_contact; |
70 | UI_NEW_PLATFORM_Handle new_platform; | 71 | UI_NEW_PLATFORM_Handle new_platform; |
72 | UI_CONTACTS_Handle contacts; | ||
71 | } ui; | 73 | } ui; |
72 | } MESSENGER_Application; | 74 | } MESSENGER_Application; |
73 | 75 | ||
diff --git a/src/ui/contacts.c b/src/ui/contacts.c new file mode 100644 index 0000000..3750f8f --- /dev/null +++ b/src/ui/contacts.c | |||
@@ -0,0 +1,91 @@ | |||
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/contacts.c | ||
23 | */ | ||
24 | |||
25 | #include "contacts.h" | ||
26 | |||
27 | #include "../application.h" | ||
28 | |||
29 | static void | ||
30 | handle_close_button_click(UNUSED GtkButton *button, | ||
31 | gpointer user_data) | ||
32 | { | ||
33 | GtkDialog *dialog = GTK_DIALOG(user_data); | ||
34 | gtk_window_close(GTK_WINDOW(dialog)); | ||
35 | } | ||
36 | |||
37 | static void | ||
38 | handle_dialog_destroy(UNUSED GtkWidget *window, | ||
39 | gpointer user_data) | ||
40 | { | ||
41 | ui_contacts_dialog_cleanup((UI_CONTACTS_Handle*) user_data); | ||
42 | } | ||
43 | |||
44 | void | ||
45 | ui_contacts_dialog_init(MESSENGER_Application *app, | ||
46 | UI_CONTACTS_Handle *handle) | ||
47 | { | ||
48 | handle->builder = gtk_builder_new_from_file("resources/ui/contacts.ui"); | ||
49 | |||
50 | handle->dialog = GTK_DIALOG( | ||
51 | gtk_builder_get_object(handle->builder, "contacts_dialog") | ||
52 | ); | ||
53 | |||
54 | gtk_window_set_title( | ||
55 | GTK_WINDOW(handle->dialog), | ||
56 | "Contacts" | ||
57 | ); | ||
58 | |||
59 | gtk_window_set_transient_for( | ||
60 | GTK_WINDOW(handle->dialog), | ||
61 | GTK_WINDOW(app->ui.messenger.main_window) | ||
62 | ); | ||
63 | |||
64 | handle->contact_search_entry = GTK_SEARCH_ENTRY( | ||
65 | gtk_builder_get_object(handle->builder, "contact_search_entry") | ||
66 | ); | ||
67 | |||
68 | handle->close_button = GTK_BUTTON( | ||
69 | gtk_builder_get_object(handle->builder, "close_button") | ||
70 | ); | ||
71 | |||
72 | g_signal_connect( | ||
73 | handle->close_button, | ||
74 | "clicked", | ||
75 | G_CALLBACK(handle_close_button_click), | ||
76 | handle->dialog | ||
77 | ); | ||
78 | |||
79 | g_signal_connect( | ||
80 | handle->dialog, | ||
81 | "destroy", | ||
82 | G_CALLBACK(handle_dialog_destroy), | ||
83 | handle | ||
84 | ); | ||
85 | } | ||
86 | |||
87 | void | ||
88 | ui_contacts_dialog_cleanup(UI_CONTACTS_Handle *handle) | ||
89 | { | ||
90 | g_object_unref(handle->builder); | ||
91 | } | ||
diff --git a/src/ui/contacts.h b/src/ui/contacts.h new file mode 100644 index 0000000..dbd952b --- /dev/null +++ b/src/ui/contacts.h | |||
@@ -0,0 +1,49 @@ | |||
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/contacts.h | ||
23 | */ | ||
24 | |||
25 | #ifndef UI_CONTACTS_H_ | ||
26 | #define UI_CONTACTS_H_ | ||
27 | |||
28 | #include "messenger.h" | ||
29 | |||
30 | typedef struct UI_CONTACTS_Handle | ||
31 | { | ||
32 | GtkBuilder *builder; | ||
33 | GtkDialog *dialog; | ||
34 | |||
35 | GtkSearchEntry *contact_search_entry; | ||
36 | |||
37 | GtkListBox *contacts_listbox; | ||
38 | |||
39 | GtkButton *close_button; | ||
40 | } UI_CONTACTS_Handle; | ||
41 | |||
42 | void | ||
43 | ui_contacts_dialog_init(MESSENGER_Application *app, | ||
44 | UI_CONTACTS_Handle *handle); | ||
45 | |||
46 | void | ||
47 | ui_contacts_dialog_cleanup(UI_CONTACTS_Handle *handle); | ||
48 | |||
49 | #endif /* UI_CONTACTS_H_ */ | ||
diff --git a/src/ui/messenger.c b/src/ui/messenger.c index bc3a8dd..8842385 100644 --- a/src/ui/messenger.c +++ b/src/ui/messenger.c | |||
@@ -27,6 +27,7 @@ | |||
27 | #include <gtk-3.0/gdk/gdkkeys.h> | 27 | #include <gtk-3.0/gdk/gdkkeys.h> |
28 | 28 | ||
29 | #include "chat_entry.h" | 29 | #include "chat_entry.h" |
30 | #include "contacts.h" | ||
30 | #include "message.h" | 31 | #include "message.h" |
31 | #include "new_contact.h" | 32 | #include "new_contact.h" |
32 | #include "new_platform.h" | 33 | #include "new_platform.h" |
@@ -94,6 +95,19 @@ handle_new_platform_button_click(UNUSED GtkButton* button, | |||
94 | } | 95 | } |
95 | 96 | ||
96 | static void | 97 | static void |
98 | handle_contacts_button_click(UNUSED GtkButton* button, | ||
99 | gpointer user_data) | ||
100 | { | ||
101 | MESSENGER_Application *app = (MESSENGER_Application*) user_data; | ||
102 | |||
103 | hdy_flap_set_reveal_flap(HDY_FLAP(app->ui.messenger.flap_user_details), FALSE); | ||
104 | |||
105 | ui_contacts_dialog_init(app, &(app->ui.contacts)); | ||
106 | |||
107 | gtk_widget_show(GTK_WIDGET(app->ui.contacts.dialog)); | ||
108 | } | ||
109 | |||
110 | static void | ||
97 | handle_chats_listbox_row_activated(UNUSED GtkListBox* listbox, | 111 | handle_chats_listbox_row_activated(UNUSED GtkListBox* listbox, |
98 | GtkListBoxRow* row, | 112 | GtkListBoxRow* row, |
99 | gpointer user_data) | 113 | gpointer user_data) |
@@ -261,6 +275,13 @@ ui_messenger_init(MESSENGER_Application *app, | |||
261 | gtk_builder_get_object(handle->builder, "settings_button") | 275 | gtk_builder_get_object(handle->builder, "settings_button") |
262 | ); | 276 | ); |
263 | 277 | ||
278 | g_signal_connect( | ||
279 | handle->contacts_button, | ||
280 | "clicked", | ||
281 | G_CALLBACK(handle_contacts_button_click), | ||
282 | app | ||
283 | ); | ||
284 | |||
264 | handle->user_details_button = GTK_BUTTON( | 285 | handle->user_details_button = GTK_BUTTON( |
265 | gtk_builder_get_object(handle->builder, "user_details_button") | 286 | gtk_builder_get_object(handle->builder, "user_details_button") |
266 | ); | 287 | ); |