messenger-gtk

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

commit 1b0b1f7ed77e7a6cec8874692437befcf663b883
parent bb7b62fdb665c574681847d954b7355686cafd65
Author: Jacki <jacki@thejackimonster.de>
Date:   Wed,  3 Jan 2024 02:47:54 +0100

Show amount of blocked contacts

Signed-off-by: Jacki <jacki@thejackimonster.de>

Diffstat:
Mresources/ui/settings.ui | 4++--
Msrc/ui/settings.c | 47+++++++++++++++++++++++++++++++++++++++++++++--
Msrc/ui/settings.h | 3++-
3 files changed, 49 insertions(+), 5 deletions(-)

diff --git a/resources/ui/settings.ui b/resources/ui/settings.ui @@ -1,5 +1,5 @@ <?xml version="1.0" encoding="UTF-8"?> -<!-- Generated with glade 3.38.2 +<!-- Generated with glade 3.40.0 Copyright (C) 2021 GNUnet e.V. @@ -284,7 +284,7 @@ Author: Tobias Frisch <property name="visible">True</property> <property name="can-focus">True</property> <child> - <object class="GtkLabel"> + <object class="GtkLabel" id="blocked_label"> <property name="visible">True</property> <property name="can-focus">False</property> <property name="label" translatable="yes">0 blocked contacts</property> diff --git a/src/ui/settings.c b/src/ui/settings.c @@ -1,6 +1,6 @@ /* This file is part of GNUnet. - Copyright (C) 2021--2022 GNUnet e.V. + Copyright (C) 2021--2024 GNUnet e.V. GNUnet is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published @@ -25,6 +25,8 @@ #include "settings.h" #include "../application.h" +#include <gnunet/gnunet_chat_lib.h> +#include <gnunet/gnunet_common.h> static gboolean handle_general_switch_state(UNUSED GtkSwitch *widget, @@ -125,9 +127,22 @@ set_active: gtk_combo_box_set_active_iter(widget, &iter); } +static enum GNUNET_GenericReturnValue +_count_blocked_contacts(void *cls, + struct GNUNET_CHAT_Handle *handle, + struct GNUNET_CHAT_Contact *contact) +{ + guint *count = (guint*) cls; + + if (GNUNET_YES == GNUNET_CHAT_contact_is_blocked(contact)) + *count = (*count) + 1; + + return GNUNET_YES; +} + void ui_settings_dialog_init(MESSENGER_Application *app, - UI_SETTINGS_Handle *handle) + UI_SETTINGS_Handle *handle) { handle->builder = gtk_builder_new_from_resource( application_get_resource_path(app, "ui/settings.ui") @@ -158,6 +173,34 @@ ui_settings_dialog_init(MESSENGER_Application *app, &(app->settings.disable_notifications) ); + handle->blocked_label = GTK_LABEL( + gtk_builder_get_object(handle->builder, "blocked_label") + ); + + guint blocked_count = 0; + GNUNET_CHAT_iterate_contacts( + app->chat.messenger.handle, + _count_blocked_contacts, + &blocked_count + ); + + GString *blocked_text = g_string_new(NULL); + if (blocked_text) + { + g_string_printf( + blocked_text, + "%u blocked contacts", + blocked_count + ); + + gtk_label_set_text( + handle->blocked_label, + blocked_text->str + ); + + g_string_free(blocked_text, TRUE); + } + handle->read_receipts_switch = GTK_SWITCH( gtk_builder_get_object(handle->builder, "read_receipts_switch") ); diff --git a/src/ui/settings.h b/src/ui/settings.h @@ -1,6 +1,6 @@ /* This file is part of GNUnet. - Copyright (C) 2021--2022 GNUnet e.V. + Copyright (C) 2021--2024 GNUnet e.V. GNUnet is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published @@ -34,6 +34,7 @@ typedef struct UI_SETTINGS_Handle GtkSwitch *enable_notifications_switch; + GtkLabel *blocked_label; GtkSwitch *read_receipts_switch; GtkSwitch *whispering_switch;