messenger-gtk

Gtk+3 graphical user interfaces for GNUnet Messenger
Log | Files | Refs | Submodules | README | LICENSE

contact_entry.c (2519B)


      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/contact_entry.c
     23  */
     24 
     25 #include "contact_entry.h"
     26 
     27 #include "../application.h"
     28 #include "../contact.h"
     29 #include "../ui.h"
     30 
     31 UI_CONTACT_ENTRY_Handle*
     32 ui_contact_entry_new(MESSENGER_Application *app)
     33 {
     34   g_assert(app);
     35 
     36   UI_CONTACT_ENTRY_Handle* handle = g_malloc(sizeof(UI_CONTACT_ENTRY_Handle));
     37 
     38   handle->contact = NULL;
     39 
     40   handle->builder = ui_builder_from_resource(
     41     application_get_resource_path(app, "ui/contact_entry.ui")
     42   );
     43 
     44   handle->entry_box = GTK_WIDGET(
     45     gtk_builder_get_object(handle->builder, "entry_box")
     46   );
     47 
     48   handle->entry_avatar = HDY_AVATAR(
     49     gtk_builder_get_object(handle->builder, "entry_avatar")
     50   );
     51 
     52   handle->title_label = GTK_LABEL(
     53     gtk_builder_get_object(handle->builder, "title_label")
     54   );
     55 
     56   handle->subtitle_label = GTK_LABEL(
     57     gtk_builder_get_object(handle->builder, "subtitle_label")
     58   );
     59 
     60   return handle;
     61 }
     62 
     63 void
     64 ui_contact_entry_set_contact(UI_CONTACT_ENTRY_Handle* handle,
     65                              struct GNUNET_CHAT_Contact *contact)
     66 {
     67   g_assert(handle);
     68 
     69   if (handle->contact)
     70   {
     71     contact_remove_name_avatar_from_info(handle->contact, handle->entry_avatar);
     72     contact_remove_name_label_from_info(handle->contact, handle->title_label);
     73   }
     74 
     75   if (contact)
     76   {
     77     const char *key = GNUNET_CHAT_contact_get_key(contact);
     78 
     79     contact_add_name_avatar_to_info(contact, handle->entry_avatar);
     80     contact_add_name_label_to_info(contact, handle->title_label);
     81 
     82     ui_label_set_text(handle->subtitle_label, key);
     83   }
     84 
     85   handle->contact = contact;
     86 }
     87 
     88 void
     89 ui_contact_entry_delete(UI_CONTACT_ENTRY_Handle *handle)
     90 {
     91   g_assert(handle);
     92 
     93   ui_contact_entry_set_contact(handle, NULL);
     94 
     95   g_object_unref(handle->builder);
     96 
     97   g_free(handle);
     98 }