commit 56e9186a90de84ea3108f95a1040c968b6f5d8aa
parent a435a928f6f6280761ee8a76225333d98f96a2b2
Author: TheJackiMonster <thejackimonster@gmail.com>
Date: Sat, 30 Oct 2021 15:28:12 +0200
Rearranged pieces of code to setup ui
Signed-off-by: TheJackiMonster <thejackimonster@gmail.com>
Diffstat:
7 files changed, 360 insertions(+), 197 deletions(-)
diff --git a/Makefile b/Makefile
@@ -3,7 +3,10 @@ SOURCE_DIR = src/
INSTALL_DIR ?= /usr/local/
BINARY = messenger-gtk
-SOURCES = messenger_gtk.c
+SOURCES = messenger_gtk.c\
+ chat/messenger.c\
+ ui/messenger.c
+
HEADERS =
LIBRARIES = gnunetutil gnunetchat
@@ -14,7 +17,7 @@ LD ?= gcc
RM ?= rm
CFLAGS += -pedantic -Wall -Wextra -march=native -ggdb3
-LDFLAGS += -pthread
+LDFLAGS +=
DEBUGFLAGS = -O0 -D _DEBUG
RELEASEFLAGS = -O2 -D NDEBUG -fwhole-program
diff --git a/resources/ui/messenger.ui b/resources/ui/messenger.ui
@@ -78,7 +78,7 @@ Author: Tobias Frisch
</packing>
</child>
<child>
- <object class="GtkSearchEntry">
+ <object class="GtkSearchEntry" id="chats_search">
<property name="width-request">250</property>
<property name="visible">True</property>
<property name="can-focus">True</property>
@@ -318,7 +318,7 @@ Author: Tobias Frisch
</packing>
</child>
<child>
- <object class="GtkButton">
+ <object class="GtkButton" id="favourites_button">
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="receives-default">True</property>
@@ -471,7 +471,7 @@ Author: Tobias Frisch
<property name="can-focus">False</property>
<property name="orientation">vertical</property>
<child>
- <object class="GtkButton">
+ <object class="GtkButton" id="new_group_button">
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="receives-default">True</property>
@@ -522,7 +522,7 @@ Author: Tobias Frisch
</packing>
</child>
<child>
- <object class="GtkButton">
+ <object class="GtkButton" id="new_platform_button">
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="receives-default">True</property>
@@ -573,7 +573,7 @@ Author: Tobias Frisch
</packing>
</child>
<child>
- <object class="GtkButton">
+ <object class="GtkButton" id="contacts_button">
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="receives-default">True</property>
@@ -624,7 +624,7 @@ Author: Tobias Frisch
</packing>
</child>
<child>
- <object class="GtkButton">
+ <object class="GtkButton" id="calls_button">
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="receives-default">True</property>
@@ -675,7 +675,7 @@ Author: Tobias Frisch
</packing>
</child>
<child>
- <object class="GtkButton">
+ <object class="GtkButton" id="settings_button">
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="receives-default">True</property>
@@ -726,7 +726,7 @@ Author: Tobias Frisch
</packing>
</child>
<child>
- <object class="GtkButton">
+ <object class="GtkButton" id="night_mode_button">
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="receives-default">True</property>
@@ -891,7 +891,7 @@ Author: Tobias Frisch
<property name="margin-end">4</property>
<property name="orientation">vertical</property>
<child>
- <object class="GtkLabel">
+ <object class="GtkLabel" id="chat_title">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="label" translatable="yes">Chat title</property>
@@ -907,7 +907,7 @@ Author: Tobias Frisch
</packing>
</child>
<child>
- <object class="GtkLabel">
+ <object class="GtkLabel" id="chat_subtitle">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="label" translatable="yes">Chat subtitle</property>
diff --git a/src/chat/messenger.c b/src/chat/messenger.c
@@ -0,0 +1,27 @@
+/*
+ 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 chat/messenger.c
+ */
+
+#include "messenger.h"
+
+
diff --git a/src/chat/messenger.h b/src/chat/messenger.h
@@ -0,0 +1,39 @@
+/*
+ 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 chat/messenger.h
+ */
+
+#ifndef CHAT_MESSENGER_H_
+#define CHAT_MESSENGER_H_
+
+#include <gnunet/platform.h>
+#include <gnunet/gnunet_chat_lib.h>
+#include <gnunet/gnunet_common.h>
+#include <gnunet/gnunet_program_lib.h>
+
+struct CHAT_MESSENGER_Handle
+{
+ struct GNUNET_CHAT_Handle *handle;
+ struct GNUNET_SCHEDULER_Task *idle;
+};
+
+#endif /* CHAT_MESSENGER_H_ */
diff --git a/src/messenger_gtk.c b/src/messenger_gtk.c
@@ -22,65 +22,12 @@
* @file messenger_gtk.c
*/
-#include <stdbool.h>
-#include <stdio.h>
+#include "chat/messenger.h"
+#include "ui/messenger.h"
#include <pthread.h>
-#include <gtk-3.0/gtk/gtk.h>
-#include <libhandy-1/handy.h>
-
-#include <gnunet/gnunet_program_lib.h>
-#include <gnunet/gnunet_chat_lib.h>
-
-void handle_user_details_button_click(GtkButton* button,
- gpointer user_data)
-{
- HdyFlap* flap = HDY_FLAP(user_data);
-
- if (TRUE == hdy_flap_get_reveal_flap(flap)) {
- hdy_flap_set_reveal_flap(flap, FALSE);
- } else {
- hdy_flap_set_reveal_flap(flap, TRUE);
- }
-}
-
-void handle_account_details_button_click(GtkButton* button,
- gpointer user_data)
-{
- GtkRevealer* revealer = GTK_REVEALER(user_data);
-
- if (TRUE == gtk_revealer_get_reveal_child(revealer)) {
- gtk_revealer_set_reveal_child(revealer, FALSE);
- } else {
- gtk_revealer_set_reveal_child(revealer, TRUE);
- }
-}
-
-void handle_chats_listbox_row_activated(GtkListBox* listbox,
- GtkListBoxRow* row,
- gpointer user_data)
-{
- HdyLeaflet* leaflet = HDY_LEAFLET(user_data);
-
- GList* children = gtk_container_get_children(GTK_CONTAINER(leaflet));
-
- if ((children) && (children->next)) {
- hdy_leaflet_set_visible_child(leaflet, GTK_WIDGET(children->next->data));
- }
-}
-
-void handle_back_button_click(GtkButton* button,
- gpointer user_data)
-{
- HdyLeaflet* leaflet = HDY_LEAFLET(user_data);
-
- GList* children = gtk_container_get_children(GTK_CONTAINER(leaflet));
-
- if (children) {
- hdy_leaflet_set_visible_child(leaflet, GTK_WIDGET(children->data));
- }
-}
+#define UNUSED __attribute__((unused))
struct main_program
{
@@ -89,31 +36,27 @@ struct main_program
bool exit;
- struct GNUNET_CHAT_Handle *chat;
-
- HdyAvatar *profile_avatar;
- GtkLabel *profile_label;
-
- struct GNUNET_SCHEDULER_Task *idle;
+ struct CHAT_MESSENGER_Handle chat;
+ struct UI_MESSENGER_Handle ui;
};
gboolean gtk_set_profile_name(gpointer user_data)
{
struct main_program *program = (struct main_program*) user_data;
- const char *name = GNUNET_CHAT_get_name(program->chat);
+ const char *name = GNUNET_CHAT_get_name(program->chat.handle);
if (name)
{
- hdy_avatar_set_text(program->profile_avatar, name);
- gtk_label_set_text(program->profile_label, name);
+ hdy_avatar_set_text(program->ui.profile_avatar, name);
+ gtk_label_set_text(program->ui.profile_label, name);
}
return FALSE;
}
int gnunet_chat_message(void *cls,
- struct GNUNET_CHAT_Context *context,
+ UNUSED struct GNUNET_CHAT_Context *context,
const struct GNUNET_CHAT_Message *message)
{
struct main_program *program = (struct main_program*) cls;
@@ -132,14 +75,14 @@ void gnunet_idle(void *cls)
if (program->exit)
{
- GNUNET_CHAT_stop(program->chat);
- program->chat = NULL;
+ GNUNET_CHAT_stop(program->chat.handle);
+ program->chat.handle = NULL;
GNUNET_SCHEDULER_shutdown();
return;
}
- program->idle = GNUNET_SCHEDULER_add_delayed_with_priority(
+ program->chat.idle = GNUNET_SCHEDULER_add_delayed_with_priority(
GNUNET_TIME_relative_get_second_(),
GNUNET_SCHEDULER_PRIORITY_IDLE,
gnunet_idle,
@@ -148,13 +91,13 @@ void gnunet_idle(void *cls)
}
void gnunet_task(void *cls,
- char *const *args,
- const char *cfgfile,
+ UNUSED char *const *args,
+ UNUSED const char *cfgfile,
const struct GNUNET_CONFIGURATION_Handle *cfg)
{
struct main_program *program = (struct main_program*) cls;
- program->chat = GNUNET_CHAT_start(
+ program->chat.handle = GNUNET_CHAT_start(
cfg,
"messenger-gtk",
"test",
@@ -162,7 +105,7 @@ void gnunet_task(void *cls,
program
);
- program->idle = GNUNET_SCHEDULER_add_delayed_with_priority(
+ program->chat.idle = GNUNET_SCHEDULER_add_delayed_with_priority(
GNUNET_TIME_relative_get_zero_(),
GNUNET_SCHEDULER_PRIORITY_IDLE,
gnunet_idle,
@@ -201,27 +144,7 @@ int main(int argc, char **argv) {
pthread_t gnunet_tid;
gtk_init(&argc, &argv);
- GtkBuilder* builder = gtk_builder_new();
- gtk_builder_add_from_file(
- builder,
- "resources/ui/messenger.ui",
- NULL
- );
-
- GtkApplicationWindow* window = GTK_APPLICATION_WINDOW(
- gtk_builder_get_object(builder, "main_window")
- );
-
- program.profile_avatar = HDY_AVATAR(
- gtk_builder_get_object(builder, "profile_avatar")
- );
-
- program.profile_label = GTK_LABEL(
- gtk_builder_get_object(builder, "profile_label")
- );
-
GdkScreen* screen = gdk_screen_get_default();
-
GtkCssProvider* provider = gtk_css_provider_new();
gtk_css_provider_load_from_path(
provider,
@@ -235,98 +158,7 @@ int main(int argc, char **argv) {
GTK_STYLE_PROVIDER_PRIORITY_APPLICATION
);
- HdyHeaderBar* title_bar = HDY_HEADER_BAR(
- gtk_builder_get_object(builder, "title_bar")
- );
-
- HdyLeaflet* leaflet_chat = HDY_LEAFLET(
- gtk_builder_get_object(builder, "leaflet_chat")
- );
-
- hdy_leaflet_set_homogeneous(leaflet_chat, FALSE, GTK_ORIENTATION_HORIZONTAL, FALSE);
-
- GtkListBox* chats_listbox = GTK_LIST_BOX(
- gtk_builder_get_object(builder, "chats_listbox")
- );
-
- g_signal_connect(
- chats_listbox,
- "row-activated",
- G_CALLBACK(handle_chats_listbox_row_activated),
- leaflet_chat
- );
-
- GtkButton* user_details_button = GTK_BUTTON(
- gtk_builder_get_object(builder, "user_details_button")
- );
-
- GtkButton* hide_user_details_button = GTK_BUTTON(
- gtk_builder_get_object(builder, "hide_user_details_button")
- );
-
- HdyFlap* flap_user_details = HDY_FLAP(
- gtk_builder_get_object(builder, "flap_user_details")
- );
-
- g_signal_connect(
- user_details_button,
- "clicked",
- G_CALLBACK(handle_user_details_button_click),
- flap_user_details
- );
-
- g_signal_connect(
- hide_user_details_button,
- "clicked",
- G_CALLBACK(handle_user_details_button_click),
- flap_user_details
- );
-
- GtkButton* account_details_button = GTK_BUTTON(
- gtk_builder_get_object(builder, "account_details_button")
- );
-
- GtkRevealer* account_details_revealer = GTK_REVEALER(
- gtk_builder_get_object(builder, "account_details_revealer")
- );
-
- g_signal_connect(
- account_details_button,
- "clicked",
- G_CALLBACK(handle_account_details_button_click),
- account_details_revealer
- );
-
- GtkButton* back_button = GTK_BUTTON(
- gtk_builder_get_object(builder, "back_button")
- );
-
- g_signal_connect(
- back_button,
- "clicked",
- G_CALLBACK(handle_back_button_click),
- leaflet_chat
- );
-
- g_object_bind_property(
- leaflet_chat,
- "folded",
- back_button,
- "visible",
- G_BINDING_SYNC_CREATE
- );
-
- g_object_bind_property(
- leaflet_chat,
- "folded",
- title_bar,
- "show-close-button",
- G_BINDING_INVERT_BOOLEAN
- );
-
- gtk_widget_show(GTK_WIDGET(window));
-
- g_signal_connect(window, "destroy", G_CALLBACK(gtk_main_quit), NULL);
+ ui_messenger_init(&(program.ui));
pthread_create(&gnunet_tid, NULL, gnunet_thread, &program);
diff --git a/src/ui/messenger.c b/src/ui/messenger.c
@@ -0,0 +1,190 @@
+/*
+ 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/messenger.c
+ */
+
+#include "messenger.h"
+
+void handle_user_details_button_click(UI_UNUSED GtkButton* button,
+ gpointer user_data)
+{
+ HdyFlap* flap = HDY_FLAP(user_data);
+
+ if (TRUE == hdy_flap_get_reveal_flap(flap)) {
+ hdy_flap_set_reveal_flap(flap, FALSE);
+ } else {
+ hdy_flap_set_reveal_flap(flap, TRUE);
+ }
+}
+
+void handle_account_details_button_click(UI_UNUSED GtkButton* button,
+ gpointer user_data)
+{
+ GtkRevealer* revealer = GTK_REVEALER(user_data);
+
+ if (TRUE == gtk_revealer_get_reveal_child(revealer)) {
+ gtk_revealer_set_reveal_child(revealer, FALSE);
+ } else {
+ gtk_revealer_set_reveal_child(revealer, TRUE);
+ }
+}
+
+void handle_chats_listbox_row_activated(UI_UNUSED GtkListBox* listbox,
+ UI_UNUSED GtkListBoxRow* row,
+ gpointer user_data)
+{
+ HdyLeaflet* leaflet = HDY_LEAFLET(user_data);
+
+ GList* children = gtk_container_get_children(GTK_CONTAINER(leaflet));
+
+ if ((children) && (children->next)) {
+ hdy_leaflet_set_visible_child(leaflet, GTK_WIDGET(children->next->data));
+ }
+}
+
+void handle_back_button_click(UI_UNUSED GtkButton* button,
+ gpointer user_data)
+{
+ HdyLeaflet* leaflet = HDY_LEAFLET(user_data);
+
+ GList* children = gtk_container_get_children(GTK_CONTAINER(leaflet));
+
+ if (children) {
+ hdy_leaflet_set_visible_child(leaflet, GTK_WIDGET(children->data));
+ }
+}
+
+void
+ui_messenger_init(struct UI_MESSENGER_Handle *handle)
+{
+ GtkBuilder* builder = gtk_builder_new();
+ gtk_builder_add_from_file(
+ builder,
+ "resources/ui/messenger.ui",
+ NULL
+ );
+
+ handle->main_window = GTK_APPLICATION_WINDOW(
+ gtk_builder_get_object(builder, "main_window")
+ );
+
+ handle->profile_avatar = HDY_AVATAR(
+ gtk_builder_get_object(builder, "profile_avatar")
+ );
+
+ handle->profile_label = GTK_LABEL(
+ gtk_builder_get_object(builder, "profile_label")
+ );
+
+ handle->title_bar = HDY_HEADER_BAR(
+ gtk_builder_get_object(builder, "title_bar")
+ );
+
+ handle->leaflet_chat = HDY_LEAFLET(
+ gtk_builder_get_object(builder, "leaflet_chat")
+ );
+
+ hdy_leaflet_set_homogeneous(handle->leaflet_chat, FALSE, GTK_ORIENTATION_HORIZONTAL, FALSE);
+
+ handle->chats_listbox = GTK_LIST_BOX(
+ gtk_builder_get_object(builder, "chats_listbox")
+ );
+
+ g_signal_connect(
+ handle->chats_listbox,
+ "row-activated",
+ G_CALLBACK(handle_chats_listbox_row_activated),
+ handle->leaflet_chat
+ );
+
+ handle->user_details_button = GTK_BUTTON(
+ gtk_builder_get_object(builder, "user_details_button")
+ );
+
+ handle->hide_user_details_button = GTK_BUTTON(
+ gtk_builder_get_object(builder, "hide_user_details_button")
+ );
+
+ handle->flap_user_details = HDY_FLAP(
+ gtk_builder_get_object(builder, "flap_user_details")
+ );
+
+ g_signal_connect(
+ handle->user_details_button,
+ "clicked",
+ G_CALLBACK(handle_user_details_button_click),
+ handle->flap_user_details
+ );
+
+ g_signal_connect(
+ handle->hide_user_details_button,
+ "clicked",
+ G_CALLBACK(handle_user_details_button_click),
+ handle->flap_user_details
+ );
+
+ handle->account_details_button = GTK_BUTTON(
+ gtk_builder_get_object(builder, "account_details_button")
+ );
+
+ handle->account_details_revealer = GTK_REVEALER(
+ gtk_builder_get_object(builder, "account_details_revealer")
+ );
+
+ g_signal_connect(
+ handle->account_details_button,
+ "clicked",
+ G_CALLBACK(handle_account_details_button_click),
+ handle->account_details_revealer
+ );
+
+ handle->back_button = GTK_BUTTON(
+ gtk_builder_get_object(builder, "back_button")
+ );
+
+ g_signal_connect(
+ handle->back_button,
+ "clicked",
+ G_CALLBACK(handle_back_button_click),
+ handle->leaflet_chat
+ );
+
+ g_object_bind_property(
+ handle->leaflet_chat,
+ "folded",
+ handle->back_button,
+ "visible",
+ G_BINDING_SYNC_CREATE
+ );
+
+ g_object_bind_property(
+ handle->leaflet_chat,
+ "folded",
+ handle->title_bar,
+ "show-close-button",
+ G_BINDING_INVERT_BOOLEAN
+ );
+
+ gtk_widget_show(GTK_WIDGET(handle->main_window));
+
+ g_signal_connect(handle->main_window, "destroy", G_CALLBACK(gtk_main_quit), NULL);
+}
diff --git a/src/ui/messenger.h b/src/ui/messenger.h
@@ -0,0 +1,72 @@
+/*
+ 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/messenger.h
+ */
+
+#ifndef UI_MESSENGER_H_
+#define UI_MESSENGER_H_
+
+#include <gtk-3.0/gtk/gtk.h>
+#include <libhandy-1/handy.h>
+
+#define UI_UNUSED __attribute__((unused))
+
+struct UI_MESSENGER_Handle
+{
+ GtkApplicationWindow *main_window;
+
+ HdyLeaflet *leaflet_chat;
+ HdyFlap *flap_user_details;
+ HdyFlap *flap_chat_details;
+
+ HdyHeaderBar *title_bar;
+ GtkButton *back_button;
+
+ HdyAvatar *profile_avatar;
+ GtkLabel *profile_label;
+
+ GtkButton *hide_user_details_button;
+ GtkButton *favourites_button;
+ GtkButton *account_details_button;
+
+ GtkRevealer *account_details_revealer;
+ GtkListBox *accounts_listbox;
+
+ GtkButton *new_group_button;
+ GtkButton *new_platform_button;
+ GtkButton *contacts_button;
+ GtkButton *calls_button;
+ GtkButton *settings_button;
+ GtkButton *night_mode_button;
+
+ GtkButton *user_details_button;
+ GtkSearchEntry *chats_search;
+ GtkListBox *chats_listbox;
+
+ GtkLabel *chat_title;
+ GtkLabel *chat_subtitle;
+};
+
+void
+ui_messenger_init(struct UI_MESSENGER_Handle *handle);
+
+#endif /* UI_MESSENGER_H_ */