account_entry.c (2878B)
1 /* 2 This file is part of GNUnet. 3 Copyright (C) 2021--2024 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/account_entry.c 23 */ 24 25 #include "account_entry.h" 26 27 #include "../account.h" 28 #include "../application.h" 29 #include "../contact.h" 30 #include "../ui.h" 31 32 UI_ACCOUNT_ENTRY_Handle* 33 ui_account_entry_new(MESSENGER_Application *app) 34 { 35 g_assert(app); 36 37 UI_ACCOUNT_ENTRY_Handle* handle = g_malloc(sizeof(UI_ACCOUNT_ENTRY_Handle)); 38 39 handle->account = NULL; 40 handle->contact = NULL; 41 42 handle->builder = ui_builder_from_resource( 43 application_get_resource_path(app, "ui/account_entry.ui") 44 ); 45 46 handle->entry_box = GTK_WIDGET( 47 gtk_builder_get_object(handle->builder, "entry_box") 48 ); 49 50 handle->entry_avatar = HDY_AVATAR( 51 gtk_builder_get_object(handle->builder, "entry_avatar") 52 ); 53 54 handle->entry_label = GTK_LABEL( 55 gtk_builder_get_object(handle->builder, "entry_label") 56 ); 57 58 return handle; 59 } 60 61 void 62 ui_account_entry_set_account(UI_ACCOUNT_ENTRY_Handle* handle, 63 const struct GNUNET_CHAT_Account *account) 64 { 65 g_assert(handle); 66 67 if (handle->account) 68 account_remove_name_avatar_from_info(handle->account, handle->entry_avatar); 69 70 if (account) 71 { 72 account_add_name_avatar_to_info(account, handle->entry_avatar); 73 74 ui_label_set_text(handle->entry_label, GNUNET_CHAT_account_get_name(account)); 75 } 76 77 handle->account = account; 78 } 79 80 void 81 ui_account_entry_set_contact(UI_ACCOUNT_ENTRY_Handle* handle, 82 const struct GNUNET_CHAT_Contact *contact) 83 { 84 g_assert(handle); 85 86 if (handle->contact) 87 { 88 contact_remove_name_avatar_from_info(handle->contact, handle->entry_avatar); 89 contact_remove_name_label_from_info(handle->contact, handle->entry_label); 90 } 91 92 if (contact) 93 { 94 contact_add_name_avatar_to_info(contact, handle->entry_avatar); 95 contact_add_name_label_to_info(contact, handle->entry_label); 96 } 97 98 handle->contact = contact; 99 } 100 101 void 102 ui_account_entry_delete(UI_ACCOUNT_ENTRY_Handle *handle) 103 { 104 g_assert(handle); 105 106 ui_account_entry_set_account(handle, NULL); 107 ui_account_entry_set_contact(handle, NULL); 108 109 g_object_unref(handle->builder); 110 111 g_free(handle); 112 }