commit 8696f9852d5dca0e40497574158e39fde32bd530
parent 6b39e0b9d3c3e27110a6f3b5986e3a58b221c38b
Author: TheJackiMonster <thejackimonster@gmail.com>
Date: Wed, 17 Nov 2021 12:10:03 +0100
Added contacts dialog to select and open a chat
Signed-off-by: TheJackiMonster <thejackimonster@gmail.com>
Diffstat:
7 files changed, 266 insertions(+), 1 deletion(-)
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/contacts.c\
ui/message.c\
ui/messenger.c\
ui/new_contact.c\
diff --git a/resources/ui/contacts.ui b/resources/ui/contacts.ui
@@ -0,0 +1,102 @@
+<?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"/>
+ <object class="GtkDialog" id="contacts_dialog">
+ <property name="can-focus">False</property>
+ <property name="modal">True</property>
+ <property name="window-position">center-on-parent</property>
+ <property name="type-hint">dialog</property>
+ <child internal-child="vbox">
+ <object class="GtkBox">
+ <property name="can-focus">False</property>
+ <property name="orientation">vertical</property>
+ <property name="spacing">2</property>
+ <child internal-child="action_area">
+ <object class="GtkButtonBox">
+ <property name="can-focus">False</property>
+ <property name="layout-style">end</property>
+ <child>
+ <object class="GtkButton" id="close_button">
+ <property name="label" translatable="yes">Close</property>
+ <property name="visible">True</property>
+ <property name="can-focus">True</property>
+ <property name="receives-default">True</property>
+ </object>
+ <packing>
+ <property name="expand">True</property>
+ <property name="fill">True</property>
+ <property name="position">0</property>
+ </packing>
+ </child>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">False</property>
+ <property name="position">2</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkSearchEntry" id="contact_search_entry">
+ <property name="width-request">250</property>
+ <property name="visible">True</property>
+ <property name="can-focus">True</property>
+ <property name="primary-icon-name">edit-find-symbolic</property>
+ <property name="primary-icon-activatable">False</property>
+ <property name="primary-icon-sensitive">False</property>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">True</property>
+ <property name="position">0</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkScrolledWindow">
+ <property name="height-request">200</property>
+ <property name="visible">True</property>
+ <property name="can-focus">True</property>
+ <property name="shadow-type">in</property>
+ <child>
+ <object class="GtkViewport">
+ <property name="visible">True</property>
+ <property name="can-focus">False</property>
+ <child>
+ <object class="GtkListBox" id="contacts_listbox">
+ <property name="visible">True</property>
+ <property name="can-focus">False</property>
+ </object>
+ </child>
+ </object>
+ </child>
+ </object>
+ <packing>
+ <property name="expand">True</property>
+ <property name="fill">True</property>
+ <property name="position">1</property>
+ </packing>
+ </child>
+ </object>
+ </child>
+ </object>
+</interface>
diff --git a/resources/ui/messenger.ui b/resources/ui/messenger.ui
@@ -113,7 +113,6 @@ Author: Tobias Frisch
<object class="GtkListBox" id="chats_listbox">
<property name="visible">True</property>
<property name="can-focus">False</property>
- <property name="selection-mode">none</property>
</object>
</child>
</object>
diff --git a/src/application.h b/src/application.h
@@ -29,6 +29,7 @@
#include "chat/messenger.h"
+#include "ui/contacts.h"
#include "ui/messenger.h"
#include "ui/new_contact.h"
#include "ui/new_platform.h"
@@ -68,6 +69,7 @@ typedef struct MESSENGER_Application
UI_NEW_CONTACT_Handle new_contact;
UI_NEW_PLATFORM_Handle new_platform;
+ UI_CONTACTS_Handle contacts;
} ui;
} MESSENGER_Application;
diff --git a/src/ui/contacts.c b/src/ui/contacts.c
@@ -0,0 +1,91 @@
+/*
+ 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/contacts.c
+ */
+
+#include "contacts.h"
+
+#include "../application.h"
+
+static void
+handle_close_button_click(UNUSED GtkButton *button,
+ gpointer user_data)
+{
+ GtkDialog *dialog = GTK_DIALOG(user_data);
+ gtk_window_close(GTK_WINDOW(dialog));
+}
+
+static void
+handle_dialog_destroy(UNUSED GtkWidget *window,
+ gpointer user_data)
+{
+ ui_contacts_dialog_cleanup((UI_CONTACTS_Handle*) user_data);
+}
+
+void
+ui_contacts_dialog_init(MESSENGER_Application *app,
+ UI_CONTACTS_Handle *handle)
+{
+ handle->builder = gtk_builder_new_from_file("resources/ui/contacts.ui");
+
+ handle->dialog = GTK_DIALOG(
+ gtk_builder_get_object(handle->builder, "contacts_dialog")
+ );
+
+ gtk_window_set_title(
+ GTK_WINDOW(handle->dialog),
+ "Contacts"
+ );
+
+ gtk_window_set_transient_for(
+ GTK_WINDOW(handle->dialog),
+ GTK_WINDOW(app->ui.messenger.main_window)
+ );
+
+ handle->contact_search_entry = GTK_SEARCH_ENTRY(
+ gtk_builder_get_object(handle->builder, "contact_search_entry")
+ );
+
+ handle->close_button = GTK_BUTTON(
+ gtk_builder_get_object(handle->builder, "close_button")
+ );
+
+ g_signal_connect(
+ handle->close_button,
+ "clicked",
+ G_CALLBACK(handle_close_button_click),
+ handle->dialog
+ );
+
+ g_signal_connect(
+ handle->dialog,
+ "destroy",
+ G_CALLBACK(handle_dialog_destroy),
+ handle
+ );
+}
+
+void
+ui_contacts_dialog_cleanup(UI_CONTACTS_Handle *handle)
+{
+ g_object_unref(handle->builder);
+}
diff --git a/src/ui/contacts.h b/src/ui/contacts.h
@@ -0,0 +1,49 @@
+/*
+ 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/contacts.h
+ */
+
+#ifndef UI_CONTACTS_H_
+#define UI_CONTACTS_H_
+
+#include "messenger.h"
+
+typedef struct UI_CONTACTS_Handle
+{
+ GtkBuilder *builder;
+ GtkDialog *dialog;
+
+ GtkSearchEntry *contact_search_entry;
+
+ GtkListBox *contacts_listbox;
+
+ GtkButton *close_button;
+} UI_CONTACTS_Handle;
+
+void
+ui_contacts_dialog_init(MESSENGER_Application *app,
+ UI_CONTACTS_Handle *handle);
+
+void
+ui_contacts_dialog_cleanup(UI_CONTACTS_Handle *handle);
+
+#endif /* UI_CONTACTS_H_ */
diff --git a/src/ui/messenger.c b/src/ui/messenger.c
@@ -27,6 +27,7 @@
#include <gtk-3.0/gdk/gdkkeys.h>
#include "chat_entry.h"
+#include "contacts.h"
#include "message.h"
#include "new_contact.h"
#include "new_platform.h"
@@ -94,6 +95,19 @@ handle_new_platform_button_click(UNUSED GtkButton* button,
}
static void
+handle_contacts_button_click(UNUSED GtkButton* button,
+ gpointer user_data)
+{
+ MESSENGER_Application *app = (MESSENGER_Application*) user_data;
+
+ hdy_flap_set_reveal_flap(HDY_FLAP(app->ui.messenger.flap_user_details), FALSE);
+
+ ui_contacts_dialog_init(app, &(app->ui.contacts));
+
+ gtk_widget_show(GTK_WIDGET(app->ui.contacts.dialog));
+}
+
+static void
handle_chats_listbox_row_activated(UNUSED GtkListBox* listbox,
GtkListBoxRow* row,
gpointer user_data)
@@ -261,6 +275,13 @@ ui_messenger_init(MESSENGER_Application *app,
gtk_builder_get_object(handle->builder, "settings_button")
);
+ g_signal_connect(
+ handle->contacts_button,
+ "clicked",
+ G_CALLBACK(handle_contacts_button_click),
+ app
+ );
+
handle->user_details_button = GTK_BUTTON(
gtk_builder_get_object(handle->builder, "user_details_button")
);