messenger-gtk

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

tag.c (2103B)


      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/tag.c
     23  */
     24 
     25 #include "tag.h"
     26 
     27 #include "../application.h"
     28 #include "../ui.h"
     29 
     30 UI_TAG_Handle*
     31 ui_tag_new(MESSENGER_Application *app)
     32 {
     33   g_assert(app);
     34 
     35   UI_TAG_Handle* handle = g_malloc(sizeof(UI_TAG_Handle));
     36 
     37   memset(handle, 0, sizeof(*handle));
     38 
     39   handle->builder = ui_builder_from_resource(
     40     application_get_resource_path(app, "ui/tag.ui")
     41   );
     42 
     43   handle->tag_label = GTK_LABEL(
     44     gtk_builder_get_object(handle->builder, "tag_label")
     45   );
     46 
     47   g_object_set_qdata(
     48     G_OBJECT(handle->tag_label),
     49     app->quarks.ui,
     50     handle
     51   );
     52 
     53   return handle;
     54 }
     55 
     56 void
     57 ui_tag_set_message(UI_TAG_Handle* handle,
     58                    MESSENGER_Application *app,
     59                    const struct GNUNET_CHAT_Message *message)
     60 {
     61   g_assert((handle) && (message));
     62 
     63   if (GNUNET_CHAT_KIND_TAG != GNUNET_CHAT_message_get_kind(message))
     64     return;
     65 
     66   const char *tag_value = GNUNET_CHAT_message_get_text(message);
     67 
     68   GString *label = g_string_new("#");
     69   g_string_append(label, tag_value);
     70 
     71   ui_label_set_text(handle->tag_label, label->str);
     72   g_string_free(label, TRUE);
     73 
     74   g_object_set_qdata(
     75     G_OBJECT(handle->tag_label),
     76     app->quarks.data,
     77     (gpointer) message
     78   );
     79 }
     80 
     81 void
     82 ui_tag_delete(UI_TAG_Handle *handle)
     83 {
     84   g_assert(handle);
     85 
     86   g_object_unref(handle->builder);
     87 
     88   g_free(handle);
     89 }