LCOV - code coverage report
Current view: top level - malcontent-control - user-image.c (source / functions) Hit Total Coverage
Test: unnamed Lines: 0 40 0.0 %
Date: 2022-07-24 19:50:38 Functions: 0 10 0.0 %
Branches: 0 18 0.0 %

           Branch data     Line data    Source code
       1                 :            : /* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*-
       2                 :            :  *
       3                 :            :  * Copyright © 2022 Endless Mobile, Inc.
       4                 :            :  * Copyright © 2015 Red Hat, Inc.
       5                 :            :  *
       6                 :            :  * This program is free software; you can redistribute it and/or modify
       7                 :            :  * it under the terms of the GNU General Public License as published by
       8                 :            :  * the Free Software Foundation; either version 2 of the License, or
       9                 :            :  * (at your option) any later version.
      10                 :            :  *
      11                 :            :  * This program is distributed in the hope that it will be useful,
      12                 :            :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      13                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      14                 :            :  * GNU General Public License for more details.
      15                 :            :  *
      16                 :            :  * You should have received a copy of the GNU General Public License
      17                 :            :  * along with this program; if not, see <http://www.gnu.org/licenses/>.
      18                 :            :  *
      19                 :            :  * Authors:
      20                 :            :  *  - Georges Basile Stavracas Neto <georges@endlessos.org>
      21                 :            :  *  - Ondrej Holy <oholy@redhat.com>
      22                 :            :  */
      23                 :            : 
      24                 :            : #include <adwaita.h>
      25                 :            : #include <act/act.h>
      26                 :            : #include <sys/stat.h>
      27                 :            : 
      28                 :            : #include "user-image.h"
      29                 :            : 
      30                 :            : 
      31                 :            : struct _MctUserImage
      32                 :            : {
      33                 :            :   AdwBin parent_instance;
      34                 :            : 
      35                 :            :   AdwAvatar *avatar;
      36                 :            : 
      37                 :            :   ActUser *user;
      38                 :            : };
      39                 :            : 
      40   [ #  #  #  #  :          0 : G_DEFINE_TYPE (MctUserImage, mct_user_image, ADW_TYPE_BIN)
                   #  # ]
      41                 :            : 
      42                 :            : static GdkTexture *
      43                 :          0 : render_user_icon_texture (ActUser *user)
      44                 :            : {
      45                 :          0 :   g_autoptr(GdkTexture) texture = NULL;
      46                 :          0 :   g_autoptr(GError) error = NULL;
      47                 :            :   const gchar *icon_file;
      48                 :            : 
      49                 :          0 :   g_return_val_if_fail (ACT_IS_USER (user), NULL);
      50                 :            : 
      51                 :          0 :   icon_file = act_user_get_icon_file (user);
      52         [ #  # ]:          0 :   if (icon_file == NULL)
      53                 :          0 :     return NULL;
      54                 :            : 
      55                 :          0 :   texture = gdk_texture_new_from_filename (icon_file, &error);
      56         [ #  # ]:          0 :   if (error != NULL)
      57                 :            :     {
      58                 :          0 :       g_warning ("Error loading user icon: %s", error->message);
      59                 :          0 :       return NULL;
      60                 :            :     }
      61                 :            : 
      62                 :          0 :   return g_steal_pointer (&texture);
      63                 :            : }
      64                 :            : 
      65                 :            : static void
      66                 :          0 : render_image (MctUserImage *image)
      67                 :            : {
      68         [ #  # ]:          0 :   g_autoptr(GdkTexture) texture = NULL;
      69                 :            : 
      70         [ #  # ]:          0 :   if (image->user == NULL)
      71                 :          0 :     return;
      72                 :            : 
      73                 :          0 :   texture = render_user_icon_texture (image->user);
      74                 :          0 :   adw_avatar_set_custom_image (image->avatar, GDK_PAINTABLE (texture));
      75                 :          0 :   adw_avatar_set_text (image->avatar, act_user_get_real_name (image->user));
      76                 :            : }
      77                 :            : 
      78                 :            : void
      79                 :          0 : mct_user_image_set_user (MctUserImage *image,
      80                 :            :                          ActUser      *user)
      81                 :            : {
      82         [ #  # ]:          0 :   g_clear_object (&image->user);
      83                 :          0 :   image->user = g_object_ref (user);
      84                 :            : 
      85                 :          0 :   render_image (image);
      86                 :          0 : }
      87                 :            : 
      88                 :            : static void
      89                 :          0 : mct_user_image_finalize (GObject *object)
      90                 :            : {
      91                 :          0 :   MctUserImage *image = MCT_USER_IMAGE (object);
      92                 :            : 
      93         [ #  # ]:          0 :   g_clear_object (&image->user);
      94                 :            : 
      95                 :          0 :   G_OBJECT_CLASS (mct_user_image_parent_class)->finalize (object);
      96                 :          0 : }
      97                 :            : 
      98                 :            : static void
      99                 :          0 : mct_user_image_class_init (MctUserImageClass *class)
     100                 :            : {
     101                 :          0 :   GObjectClass *object_class = G_OBJECT_CLASS (class);
     102                 :            : 
     103                 :          0 :   object_class->finalize = mct_user_image_finalize;
     104                 :          0 : }
     105                 :            : 
     106                 :            : static void
     107                 :          0 : mct_user_image_init (MctUserImage *image)
     108                 :            : {
     109                 :          0 :   image->avatar = ADW_AVATAR (adw_avatar_new (48, NULL, TRUE));
     110                 :          0 :   adw_bin_set_child (ADW_BIN (image), GTK_WIDGET (image->avatar));
     111                 :          0 : }
     112                 :            : 
     113                 :            : GtkWidget *
     114                 :          0 : mct_user_image_new (void)
     115                 :            : {
     116                 :          0 :   return g_object_new (MCT_TYPE_USER_IMAGE, NULL);
     117                 :            : }

Generated by: LCOV version 1.16