From 8696f9852d5dca0e40497574158e39fde32bd530 Mon Sep 17 00:00:00 2001 From: TheJackiMonster Date: Wed, 17 Nov 2021 12:10:03 +0100 Subject: Added contacts dialog to select and open a chat Signed-off-by: TheJackiMonster --- Makefile | 1 + resources/ui/contacts.ui | 102 ++++++++++++++++++++++++++++++++++++++++++++++ resources/ui/messenger.ui | 1 - src/application.h | 2 + src/ui/contacts.c | 91 +++++++++++++++++++++++++++++++++++++++++ src/ui/contacts.h | 49 ++++++++++++++++++++++ src/ui/messenger.c | 21 ++++++++++ 7 files changed, 266 insertions(+), 1 deletion(-) create mode 100644 resources/ui/contacts.ui create mode 100644 src/ui/contacts.c create mode 100644 src/ui/contacts.h diff --git a/Makefile b/Makefile index 23bd6bf..894973f 100644 --- a/Makefile +++ b/Makefile @@ -9,6 +9,7 @@ SOURCES = messenger_gtk.c\ chat/messenger.c\ ui/chat.c\ ui/chat_entry.c\ + ui/contacts.c\ ui/message.c\ ui/messenger.c\ 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 @@ + + + + + + False + True + center-on-parent + dialog + + + False + vertical + 2 + + + False + end + + + Close + True + True + True + + + True + True + 0 + + + + + False + False + 2 + + + + + 250 + True + True + edit-find-symbolic + False + False + + + False + True + 0 + + + + + 200 + True + True + in + + + True + False + + + True + False + + + + + + + True + True + 1 + + + + + + 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 True False - none 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 @@ #include "chat/messenger.h" +#include "ui/contacts.h" #include "ui/messenger.h" #include "ui/new_contact.h" #include "ui/new_platform.h" @@ -68,6 +69,7 @@ typedef struct MESSENGER_Application UI_NEW_CONTACT_Handle new_contact; UI_NEW_PLATFORM_Handle new_platform; + UI_CONTACTS_Handle contacts; } ui; } MESSENGER_Application; 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 @@ +/* + This file is part of GNUnet. + Copyright (C) 2021 GNUnet e.V. + + GNUnet is free software: you can redistribute it and/or modify it + under the terms of the GNU Affero General Public License as published + by the Free Software Foundation, either version 3 of the License, + or (at your option) any later version. + + GNUnet is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see . + + SPDX-License-Identifier: AGPL3.0-or-later + */ +/* + * @author Tobias Frisch + * @file ui/contacts.c + */ + +#include "contacts.h" + +#include "../application.h" + +static void +handle_close_button_click(UNUSED GtkButton *button, + gpointer user_data) +{ + GtkDialog *dialog = GTK_DIALOG(user_data); + gtk_window_close(GTK_WINDOW(dialog)); +} + +static void +handle_dialog_destroy(UNUSED GtkWidget *window, + gpointer user_data) +{ + ui_contacts_dialog_cleanup((UI_CONTACTS_Handle*) user_data); +} + +void +ui_contacts_dialog_init(MESSENGER_Application *app, + UI_CONTACTS_Handle *handle) +{ + handle->builder = gtk_builder_new_from_file("resources/ui/contacts.ui"); + + handle->dialog = GTK_DIALOG( + gtk_builder_get_object(handle->builder, "contacts_dialog") + ); + + gtk_window_set_title( + GTK_WINDOW(handle->dialog), + "Contacts" + ); + + gtk_window_set_transient_for( + GTK_WINDOW(handle->dialog), + GTK_WINDOW(app->ui.messenger.main_window) + ); + + handle->contact_search_entry = GTK_SEARCH_ENTRY( + gtk_builder_get_object(handle->builder, "contact_search_entry") + ); + + handle->close_button = GTK_BUTTON( + gtk_builder_get_object(handle->builder, "close_button") + ); + + g_signal_connect( + handle->close_button, + "clicked", + G_CALLBACK(handle_close_button_click), + handle->dialog + ); + + g_signal_connect( + handle->dialog, + "destroy", + G_CALLBACK(handle_dialog_destroy), + handle + ); +} + +void +ui_contacts_dialog_cleanup(UI_CONTACTS_Handle *handle) +{ + g_object_unref(handle->builder); +} 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 @@ +/* + This file is part of GNUnet. + Copyright (C) 2021 GNUnet e.V. + + GNUnet is free software: you can redistribute it and/or modify it + under the terms of the GNU Affero General Public License as published + by the Free Software Foundation, either version 3 of the License, + or (at your option) any later version. + + GNUnet is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see . + + SPDX-License-Identifier: AGPL3.0-or-later + */ +/* + * @author Tobias Frisch + * @file ui/contacts.h + */ + +#ifndef UI_CONTACTS_H_ +#define UI_CONTACTS_H_ + +#include "messenger.h" + +typedef struct UI_CONTACTS_Handle +{ + GtkBuilder *builder; + GtkDialog *dialog; + + GtkSearchEntry *contact_search_entry; + + GtkListBox *contacts_listbox; + + GtkButton *close_button; +} UI_CONTACTS_Handle; + +void +ui_contacts_dialog_init(MESSENGER_Application *app, + UI_CONTACTS_Handle *handle); + +void +ui_contacts_dialog_cleanup(UI_CONTACTS_Handle *handle); + +#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 @@ #include #include "chat_entry.h" +#include "contacts.h" #include "message.h" #include "new_contact.h" #include "new_platform.h" @@ -93,6 +94,19 @@ handle_new_platform_button_click(UNUSED GtkButton* button, gtk_widget_show(GTK_WIDGET(app->ui.new_platform.dialog)); } +static void +handle_contacts_button_click(UNUSED GtkButton* button, + gpointer user_data) +{ + MESSENGER_Application *app = (MESSENGER_Application*) user_data; + + hdy_flap_set_reveal_flap(HDY_FLAP(app->ui.messenger.flap_user_details), FALSE); + + ui_contacts_dialog_init(app, &(app->ui.contacts)); + + gtk_widget_show(GTK_WIDGET(app->ui.contacts.dialog)); +} + static void handle_chats_listbox_row_activated(UNUSED GtkListBox* listbox, GtkListBoxRow* row, @@ -261,6 +275,13 @@ ui_messenger_init(MESSENGER_Application *app, gtk_builder_get_object(handle->builder, "settings_button") ); + g_signal_connect( + handle->contacts_button, + "clicked", + G_CALLBACK(handle_contacts_button_click), + app + ); + handle->user_details_button = GTK_BUTTON( gtk_builder_get_object(handle->builder, "user_details_button") ); -- cgit v1.2.3