messenger-gtk

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

discourse_panel.c (2595B)


      1 /*
      2    This file is part of GNUnet.
      3    Copyright (C) 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/discourse_panel.c
     23  */
     24 
     25 #include "discourse_panel.h"
     26 
     27 #include "../contact.h"
     28 #include "../ui.h"
     29 
     30 UI_DISCOURSE_PANEL_Handle*
     31 ui_discourse_panel_new(MESSENGER_Application *app)
     32 {
     33   g_assert(app);
     34 
     35   UI_DISCOURSE_PANEL_Handle* handle = g_malloc(sizeof(UI_DISCOURSE_PANEL_Handle));
     36 
     37   handle->contact = NULL;
     38 
     39   handle->builder = ui_builder_from_resource(
     40     application_get_resource_path(app, "ui/discourse_panel.ui")
     41   );
     42 
     43   handle->panel_box = GTK_WIDGET(
     44     gtk_builder_get_object(handle->builder, "panel_box")
     45   );
     46 
     47   handle->panel_stack = GTK_STACK(
     48     gtk_builder_get_object(handle->builder, "panel_stack")
     49   );
     50 
     51   handle->avatar_box = GTK_WIDGET(
     52     gtk_builder_get_object(handle->builder, "avatar_box")
     53   );
     54 
     55   handle->panel_avatar = HDY_AVATAR(
     56     gtk_builder_get_object(handle->builder, "panel_avatar")
     57   );
     58 
     59   handle->panel_label = GTK_LABEL(
     60     gtk_builder_get_object(handle->builder, "panel_label")
     61   );
     62 
     63   handle->video_box = GTK_WIDGET(
     64     gtk_builder_get_object(handle->builder, "video_box")
     65   );
     66 
     67   return handle;
     68 }
     69 
     70 void
     71 ui_discourse_panel_set_contact(UI_DISCOURSE_PANEL_Handle* handle,
     72                                const struct GNUNET_CHAT_Contact *contact)
     73 {
     74   g_assert(handle);
     75 
     76   if (handle->contact)
     77   {
     78     contact_remove_name_avatar_from_info(handle->contact, handle->panel_avatar);
     79     contact_remove_name_label_from_info(handle->contact, handle->panel_label);
     80   }
     81 
     82   if (contact)
     83   {
     84     contact_add_name_avatar_to_info(contact, handle->panel_avatar);
     85     contact_add_name_label_to_info(contact, handle->panel_label);
     86   }
     87 
     88   handle->contact = contact;
     89 }
     90 
     91 void
     92 ui_discourse_panel_delete(UI_DISCOURSE_PANEL_Handle *handle)
     93 {
     94   g_assert(handle);
     95 
     96   ui_discourse_panel_set_contact(handle, NULL);
     97   
     98   g_object_unref(handle->builder);
     99 
    100   g_free(handle);
    101 }