messenger-gtk

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

commit 847faf46a60160a8ffdce3d3ca0bcdef0f55c886
parent 2531da9bf962386ba0d7d1b824dd399dd0980f39
Author: TheJackiMonster <thejackimonster@gmail.com>
Date:   Sun, 31 Oct 2021 02:07:27 +0200

Added ui file to add chat/contact entries

Signed-off-by: TheJackiMonster <thejackimonster@gmail.com>

Diffstat:
MMakefile | 1+
Aresources/ui/chat_entry.ui | 119+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Msrc/chat/messenger.c | 2++
Msrc/event.c | 61+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--
Asrc/ui/chat_entry.c | 55+++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/ui/chat_entry.h | 48++++++++++++++++++++++++++++++++++++++++++++++++
Msrc/ui/messenger.c | 7+------
7 files changed, 285 insertions(+), 8 deletions(-)

diff --git a/Makefile b/Makefile @@ -7,6 +7,7 @@ SOURCES = messenger_gtk.c\ application.c\ event.c\ chat/messenger.c\ + ui/chat_entry.c\ ui/messenger.c HEADERS = diff --git a/resources/ui/chat_entry.ui b/resources/ui/chat_entry.ui @@ -0,0 +1,119 @@ +<?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"> + <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="orientation">vertical</property> + <property name="spacing">2</property> + <child> + <object class="GtkBox"> + <property name="visible">True</property> + <property name="can-focus">False</property> + <property name="spacing">8</property> + <child> + <object class="GtkLabel"> + <property name="visible">True</property> + <property name="can-focus">False</property> + <property name="label" translatable="yes">Chat title</property> + <property name="wrap">True</property> + <property name="wrap-mode">word-char</property> + <property name="ellipsize">end</property> + <property name="xalign">0</property> + </object> + <packing> + <property name="expand">False</property> + <property name="fill">True</property> + <property name="position">0</property> + </packing> + </child> + <child> + <object class="GtkLabel"> + <property name="visible">True</property> + <property name="can-focus">False</property> + <property name="label" translatable="yes">11.12.13</property> + <property name="justify">right</property> + </object> + <packing> + <property name="expand">False</property> + <property name="fill">True</property> + <property name="pack-type">end</property> + <property name="position">1</property> + </packing> + </child> + </object> + <packing> + <property name="expand">False</property> + <property name="fill">True</property> + <property name="position">0</property> + </packing> + </child> + <child> + <object class="GtkLabel"> + <property name="visible">True</property> + <property name="can-focus">False</property> + <property name="label" translatable="yes">My evil comment text is awesome! This is coming to the Pinephone which will be extremely awesome and this text may only cut some borders in certain areas!!!</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> + </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/chat/messenger.c b/src/chat/messenger.c @@ -59,6 +59,8 @@ _chat_messenger_message(void *cls, if (GNUNET_CHAT_KIND_LOGIN == GNUNET_CHAT_message_get_kind(message)) application_call_event(app, event_update_profile); + else if (GNUNET_CHAT_KIND_TEXT == GNUNET_CHAT_message_get_kind(message)) + printf("%s\n", GNUNET_CHAT_message_get_text(message)); return GNUNET_YES; } diff --git a/src/event.c b/src/event.c @@ -24,16 +24,73 @@ #include "event.h" +#include "ui/chat_entry.h" + +static int +_iterate_profile_contacts(void *cls, + UNUSED struct GNUNET_CHAT_Handle *handle, + UNUSED struct GNUNET_CHAT_Contact *contact) +{ + MESSENGER_Application *app = (MESSENGER_Application*) cls; + + UI_MESSENGER_Handle *ui = &(app->ui.messenger); + + UI_CHAT_ENTRY_Handle *entry = ui_chat_entry_new(); + + gtk_container_add(GTK_CONTAINER(ui->chats_listbox), entry->entry_box); + + g_free(entry); //TODO: add to a list or similar? + + return GNUNET_YES; +} + +static int +_iterate_profile_groups(void *cls, + UNUSED struct GNUNET_CHAT_Handle *handle, + UNUSED struct GNUNET_CHAT_Group *group) +{ + MESSENGER_Application *app = (MESSENGER_Application*) cls; + + UI_MESSENGER_Handle *ui = &(app->ui.messenger); + + UI_CHAT_ENTRY_Handle *entry = ui_chat_entry_new(); + + gtk_container_add(GTK_CONTAINER(ui->chats_listbox), entry->entry_box); + + g_free(entry); //TODO: add to a list or similar? + + return GNUNET_YES; +} + +static void +_clear_each_widget(GtkWidget *widget, + gpointer user_data) +{ + GtkContainer *container = GTK_CONTAINER(user_data); + + gtk_container_remove(container, widget); +} + void event_update_profile(MESSENGER_Application *app) { - UI_MESSENGER_Handle* ui = &(app->ui.messenger); + UI_MESSENGER_Handle *ui = &(app->ui.messenger); + CHAT_MESSENGER_Handle *chat = &(app->chat.messenger); - const char *name = GNUNET_CHAT_get_name(app->chat.messenger.handle); + const char *name = GNUNET_CHAT_get_name(chat->handle); if (name) { hdy_avatar_set_text(ui->profile_avatar, name); gtk_label_set_text(ui->profile_label, name); } + + gtk_container_foreach( + GTK_CONTAINER(ui->chats_listbox), + _clear_each_widget, + ui->chats_listbox + ); + + GNUNET_CHAT_iterate_contacts(chat->handle, _iterate_profile_contacts, app); + GNUNET_CHAT_iterate_groups(chat->handle, _iterate_profile_groups, app); } diff --git a/src/ui/chat_entry.c b/src/ui/chat_entry.c @@ -0,0 +1,55 @@ +/* + 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/chat_entry.c + */ + +#include "chat_entry.h" + +UI_CHAT_ENTRY_Handle* +ui_chat_entry_new(void) +{ + UI_CHAT_ENTRY_Handle* handle = g_malloc(sizeof(UI_CHAT_ENTRY_Handle)); + + GtkBuilder* builder = gtk_builder_new_from_file("resources/ui/chat_entry.ui"); + + handle->entry_box = GTK_WIDGET( + gtk_builder_get_object(builder, "entry_box") + ); + + handle->avatar = HDY_AVATAR( + gtk_builder_get_object(builder, "avatar") + ); + + handle->title = GTK_LABEL( + gtk_builder_get_object(builder, "title") + ); + + handle->timestamp = GTK_LABEL( + gtk_builder_get_object(builder, "timestamp") + ); + + handle->text = GTK_LABEL( + gtk_builder_get_object(builder, "text") + ); + + return handle; +} diff --git a/src/ui/chat_entry.h b/src/ui/chat_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/chat_entry.h + */ + +#ifndef UI_CHAT_ENTRY_H_ +#define UI_CHAT_ENTRY_H_ + +#include <gtk-3.0/gtk/gtk.h> +#include <libhandy-1/handy.h> + +typedef struct MESSENGER_Application MESSENGER_Application; + +typedef struct UI_CHAT_ENTRY_Handle +{ + GtkWidget* entry_box; + + HdyAvatar* avatar; + + GtkLabel* title; + GtkLabel* timestamp; + + GtkLabel* text; +} UI_CHAT_ENTRY_Handle; + +UI_CHAT_ENTRY_Handle* +ui_chat_entry_new(void); + +#endif /* UI_CHAT_ENTRY_H_ */ diff --git a/src/ui/messenger.c b/src/ui/messenger.c @@ -92,12 +92,7 @@ void ui_messenger_init(MESSENGER_Application *app, UI_MESSENGER_Handle *handle) { - GtkBuilder* builder = gtk_builder_new(); - gtk_builder_add_from_file( - builder, - "resources/ui/messenger.ui", - NULL - ); + GtkBuilder* builder = gtk_builder_new_from_file("resources/ui/messenger.ui"); handle->main_window = GTK_APPLICATION_WINDOW( gtk_builder_get_object(builder, "main_window")