commit 5e9ee3427898e799cebe06787b409ca770e6e1ee
parent 8696f9852d5dca0e40497574158e39fde32bd530
Author: TheJackiMonster <thejackimonster@gmail.com>
Date: Thu, 18 Nov 2021 01:37:30 +0100
Implemented querying contacts to visualize list of them
Signed-off-by: TheJackiMonster <thejackimonster@gmail.com>
Diffstat:
7 files changed, 299 insertions(+), 2 deletions(-)
diff --git a/Makefile b/Makefile
@@ -9,6 +9,7 @@ SOURCES = messenger_gtk.c\
chat/messenger.c\
ui/chat.c\
ui/chat_entry.c\
+ ui/contact_entry.c\
ui/contacts.c\
ui/message.c\
ui/messenger.c\
@@ -18,7 +19,7 @@ SOURCES = messenger_gtk.c\
HEADERS =
LIBRARIES = gnunetchat zbargtk
-PACKAGES = gnunetutil libhandy-1 gtk+-3.0 libnotify zbar libqrencode
+PACKAGES = gnunetutil libhandy-1 gtk+-3.0 libnotify zbar libqrencode gnunetidentity
GNU_CC ?= gcc
GNU_LD ?= gcc
diff --git a/resources/ui/contact_entry.ui b/resources/ui/contact_entry.ui
@@ -0,0 +1,98 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- Generated with glade 3.38.2
+
+Copyright (C) 2021 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
+by the Free Software Foundation, either version 3 of the License,
+or (at your option) any later version.
+
+GNUnet is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+Affero General Public License for more details.
+
+You should have received a copy of the GNU Affero General Public License
+along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+SPDX-License-Identifier: AGPL3.0-or-later
+Author: Tobias Frisch
+
+-->
+<interface>
+ <requires lib="gtk+" version="3.24"/>
+ <requires lib="libhandy" version="1.2"/>
+ <object class="GtkBox" id="entry_box">
+ <property name="visible">True</property>
+ <property name="can-focus">False</property>
+ <property name="spacing">8</property>
+ <child>
+ <object class="HdyAvatar" id="entry_avatar">
+ <property name="visible">True</property>
+ <property name="can-focus">False</property>
+ <property name="size">48</property>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">True</property>
+ <property name="position">0</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkBox">
+ <property name="visible">True</property>
+ <property name="can-focus">False</property>
+ <property name="border-width">2</property>
+ <property name="orientation">vertical</property>
+ <property name="spacing">2</property>
+ <child>
+ <object class="GtkLabel" id="title_label">
+ <property name="visible">True</property>
+ <property name="can-focus">False</property>
+ <property name="wrap">True</property>
+ <property name="wrap-mode">word-char</property>
+ <property name="ellipsize">end</property>
+ <property name="xalign">0</property>
+ <attributes>
+ <attribute name="weight" value="bold"/>
+ </attributes>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">True</property>
+ <property name="position">0</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkLabel" id="subtitle_label">
+ <property name="visible">True</property>
+ <property name="can-focus">False</property>
+ <property name="wrap">True</property>
+ <property name="wrap-mode">word-char</property>
+ <property name="ellipsize">end</property>
+ <property name="max-width-chars">48</property>
+ <property name="xalign">0</property>
+ <attributes>
+ <attribute name="weight" value="semilight"/>
+ </attributes>
+ </object>
+ <packing>
+ <property name="expand">True</property>
+ <property name="fill">True</property>
+ <property name="position">1</property>
+ </packing>
+ </child>
+ </object>
+ <packing>
+ <property name="expand">True</property>
+ <property name="fill">True</property>
+ <property name="pack-type">end</property>
+ <property name="position">1</property>
+ </packing>
+ </child>
+ <style>
+ <class name="chat-entry"/>
+ </style>
+ </object>
+</interface>
diff --git a/src/event.c b/src/event.c
@@ -25,6 +25,7 @@
#include "event.h"
#include "ui/chat_entry.h"
+#include "ui/contact_entry.h"
#include "ui/message.h"
static void
@@ -81,7 +82,7 @@ _add_new_chat_entry(MESSENGER_Application *app,
static int
_iterate_profile_contacts(void *cls,
UNUSED struct GNUNET_CHAT_Handle *handle,
- UNUSED struct GNUNET_CHAT_Contact *contact)
+ struct GNUNET_CHAT_Contact *contact)
{
MESSENGER_Application *app = (MESSENGER_Application*) cls;
_add_new_chat_entry(app, GNUNET_CHAT_contact_get_context(contact));
diff --git a/src/ui/contact_entry.c b/src/ui/contact_entry.c
@@ -0,0 +1,61 @@
+/*
+ This file is part of GNUnet.
+ Copyright (C) 2021 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
+ by the Free Software Foundation, either version 3 of the License,
+ or (at your option) any later version.
+
+ GNUnet is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Affero General Public License for more details.
+
+ You should have received a copy of the GNU Affero General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+ SPDX-License-Identifier: AGPL3.0-or-later
+ */
+/*
+ * @author Tobias Frisch
+ * @file ui/contact_entry.c
+ */
+
+#include "contact_entry.h"
+
+#include "../application.h"
+
+UI_CONTACT_ENTRY_Handle*
+ui_contact_entry_new(void)
+{
+ UI_CONTACT_ENTRY_Handle* handle = g_malloc(sizeof(UI_CONTACT_ENTRY_Handle));
+
+ handle->builder = gtk_builder_new_from_file("resources/ui/contact_entry.ui");
+
+ handle->entry_box = GTK_WIDGET(
+ gtk_builder_get_object(handle->builder, "entry_box")
+ );
+
+ handle->entry_avatar = HDY_AVATAR(
+ gtk_builder_get_object(handle->builder, "entry_avatar")
+ );
+
+ handle->title_label = GTK_LABEL(
+ gtk_builder_get_object(handle->builder, "title_label")
+ );
+
+ handle->subtitle_label = GTK_LABEL(
+ gtk_builder_get_object(handle->builder, "subtitle_label")
+ );
+
+ return handle;
+}
+
+void
+ui_contact_entry_delete(UI_CONTACT_ENTRY_Handle *handle)
+{
+ g_object_unref(handle->builder);
+
+ g_free(handle);
+}
diff --git a/src/ui/contact_entry.h b/src/ui/contact_entry.h
@@ -0,0 +1,48 @@
+/*
+ This file is part of GNUnet.
+ Copyright (C) 2021 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
+ by the Free Software Foundation, either version 3 of the License,
+ or (at your option) any later version.
+
+ GNUnet is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Affero General Public License for more details.
+
+ You should have received a copy of the GNU Affero General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+ SPDX-License-Identifier: AGPL3.0-or-later
+ */
+/*
+ * @author Tobias Frisch
+ * @file ui/contact_entry.h
+ */
+
+#ifndef UI_CONTACT_ENTRY_H_
+#define UI_CONTACT_ENTRY_H_
+
+#include "messenger.h"
+
+typedef struct UI_CONTACT_ENTRY_Handle
+{
+ GtkBuilder *builder;
+
+ GtkWidget *entry_box;
+
+ HdyAvatar *entry_avatar;
+
+ GtkLabel *title_label;
+ GtkLabel *subtitle_label;
+} UI_CONTACT_ENTRY_Handle;
+
+UI_CONTACT_ENTRY_Handle*
+ui_contact_entry_new(void);
+
+void
+ui_contact_entry_delete(UI_CONTACT_ENTRY_Handle *handle);
+
+#endif /* UI_CONTACT_ENTRY_H_ */
diff --git a/src/ui/contacts.c b/src/ui/contacts.c
@@ -24,8 +24,11 @@
#include "contacts.h"
+#include "contact_entry.h"
#include "../application.h"
+#include <gnunet/gnunet_identity_service.h>
+
static void
handle_close_button_click(UNUSED GtkButton *button,
gpointer user_data)
@@ -41,10 +44,66 @@ handle_dialog_destroy(UNUSED GtkWidget *window,
ui_contacts_dialog_cleanup((UI_CONTACTS_Handle*) user_data);
}
+static int
+_iterate_clear_contacts(UNUSED void *cls,
+ UNUSED struct GNUNET_CHAT_Handle *handle,
+ struct GNUNET_CHAT_Contact *contact)
+{
+ GNUNET_CHAT_contact_set_user_pointer(contact, NULL);
+ return GNUNET_YES;
+}
+
+static int
+_iterate_contacts(void *cls,
+ UNUSED struct GNUNET_CHAT_Handle *handle,
+ struct GNUNET_CHAT_Contact *contact)
+{
+ MESSENGER_Application *app = (MESSENGER_Application*) cls;
+
+ if (GNUNET_CHAT_contact_get_user_pointer(contact))
+ return GNUNET_YES;
+
+ const char *title;
+ title = GNUNET_CHAT_contact_get_name(contact);
+
+ const struct GNUNET_IDENTITY_PublicKey *key;
+ key = GNUNET_CHAT_contact_get_key(contact);
+
+ UI_CONTACT_ENTRY_Handle *entry = ui_contact_entry_new();
+ gtk_container_add(
+ GTK_CONTAINER(app->ui.contacts.contacts_listbox),
+ entry->entry_box
+ );
+
+ GNUNET_CHAT_contact_set_user_pointer(contact, entry);
+
+ if (title)
+ {
+ gtk_label_set_text(entry->title_label, title);
+ hdy_avatar_set_text(entry->entry_avatar, title);
+ }
+
+ if (key)
+ {
+ char *key_string = GNUNET_IDENTITY_public_key_to_string(key);
+ gtk_label_set_text(entry->subtitle_label, key_string);
+ GNUNET_free(key_string);
+ }
+
+ app->ui.contacts.contact_entries = g_list_append(
+ app->ui.contacts.contact_entries,
+ entry
+ );
+
+ return GNUNET_YES;
+}
+
void
ui_contacts_dialog_init(MESSENGER_Application *app,
UI_CONTACTS_Handle *handle)
{
+ handle->contact_entries = g_list_alloc();
+
handle->builder = gtk_builder_new_from_file("resources/ui/contacts.ui");
handle->dialog = GTK_DIALOG(
@@ -65,6 +124,10 @@ ui_contacts_dialog_init(MESSENGER_Application *app,
gtk_builder_get_object(handle->builder, "contact_search_entry")
);
+ handle->contacts_listbox = GTK_LIST_BOX(
+ gtk_builder_get_object(handle->builder, "contacts_listbox")
+ );
+
handle->close_button = GTK_BUTTON(
gtk_builder_get_object(handle->builder, "close_button")
);
@@ -82,10 +145,33 @@ ui_contacts_dialog_init(MESSENGER_Application *app,
G_CALLBACK(handle_dialog_destroy),
handle
);
+
+ GNUNET_CHAT_iterate_contacts(
+ app->chat.messenger.handle,
+ _iterate_clear_contacts,
+ NULL
+ );
+
+ GNUNET_CHAT_iterate_contacts(
+ app->chat.messenger.handle,
+ _iterate_contacts,
+ app
+ );
}
void
ui_contacts_dialog_cleanup(UI_CONTACTS_Handle *handle)
{
g_object_unref(handle->builder);
+
+ GList *list = handle->contact_entries;
+
+ while (list) {
+ if (list->data)
+ ui_contact_entry_delete((UI_CONTACT_ENTRY_Handle*) list->data);
+
+ list = list->next;
+ }
+
+ g_list_free(handle->contact_entries);
}
diff --git a/src/ui/contacts.h b/src/ui/contacts.h
@@ -29,6 +29,8 @@
typedef struct UI_CONTACTS_Handle
{
+ GList *contact_entries;
+
GtkBuilder *builder;
GtkDialog *dialog;