commit d739a0214d83b1fd366c167a610b8dbf1205f483
parent 03badafe00a8bf4a019dca2ccac8e8937ff59899
Author: TheJackiMonster <thejackimonster@gmail.com>
Date: Wed, 19 Jan 2022 13:41:10 +0100
Added files listbox and replaced idle task to shutdown gnunet with a select
Signed-off-by: TheJackiMonster <thejackimonster@gmail.com>
Diffstat:
7 files changed, 82 insertions(+), 25 deletions(-)
diff --git a/resources/ui/chat.ui b/resources/ui/chat.ui
@@ -611,6 +611,52 @@ Author: Tobias Frisch
<property name="position">1</property>
</packing>
</child>
+ <child>
+ <object class="GtkBox">
+ <property name="visible">True</property>
+ <property name="can-focus">False</property>
+ <property name="orientation">vertical</property>
+ <child>
+ <object class="GtkLabel">
+ <property name="visible">True</property>
+ <property name="can-focus">False</property>
+ <property name="label" translatable="yes">Files</property>
+ <property name="xalign">0</property>
+ <attributes>
+ <attribute name="weight" value="semibold"/>
+ </attributes>
+ <style>
+ <class name="details-group-title"/>
+ </style>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">True</property>
+ <property name="position">0</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkListBox" id="chat_files_listbox">
+ <property name="visible">True</property>
+ <property name="can-focus">False</property>
+ <property name="selection-mode">none</property>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">True</property>
+ <property name="position">1</property>
+ </packing>
+ </child>
+ <style>
+ <class name="details-group"/>
+ </style>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">True</property>
+ <property name="position">2</property>
+ </packing>
+ </child>
</object>
</child>
</object>
diff --git a/src/application.c b/src/application.c
@@ -1,6 +1,6 @@
/*
This file is part of GNUnet.
- Copyright (C) 2021 GNUnet e.V.
+ Copyright (C) 2021--2022 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
@@ -79,7 +79,7 @@ application_init(MESSENGER_Application *app,
app->chat.status = EXIT_FAILURE;
app->chat.tid = 0;
- app->chat.signal = MESSENGER_NONE;
+ pipe(app->chat.pipe);
pthread_mutex_init(&(app->chat.mutex), NULL);
@@ -175,10 +175,16 @@ application_run(MESSENGER_Application *app)
app->argv
);
+ if (app->ui.status != 0)
+ application_exit(app, MESSENGER_FAIL);
+
pthread_join(app->chat.tid, NULL);
g_hash_table_destroy(app->ui.bindings);
+ close(app->chat.pipe[0]);
+ close(app->chat.pipe[1]);
+
pthread_mutex_destroy(&(app->chat.mutex));
GList *list = app->notifications;
@@ -286,7 +292,7 @@ void
application_exit(MESSENGER_Application *app,
MESSENGER_ApplicationSignal signal)
{
- app->chat.signal = signal;
+ write(app->chat.pipe[1], &signal, sizeof(signal));
}
int
diff --git a/src/application.h b/src/application.h
@@ -1,6 +1,6 @@
/*
This file is part of GNUnet.
- Copyright (C) 2021 GNUnet e.V.
+ Copyright (C) 2021--2022 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
@@ -62,7 +62,7 @@ typedef struct MESSENGER_Application
pthread_t tid;
char *identity;
- MESSENGER_ApplicationSignal signal;
+ int pipe [2];
pthread_mutex_t mutex;
CHAT_MESSENGER_Handle messenger;
diff --git a/src/chat/messenger.c b/src/chat/messenger.c
@@ -38,21 +38,15 @@ _chat_messenger_destroy_contacts(UNUSED void *cls,
}
static void
-_chat_messenger_idle(void *cls)
+_chat_messenger_quit(void *cls)
{
MESSENGER_Application *app = (MESSENGER_Application*) cls;
- if (MESSENGER_NONE == app->chat.signal)
- {
- app->chat.messenger.idle = GNUNET_SCHEDULER_add_delayed_with_priority(
- GNUNET_TIME_relative_get_second_(),
- GNUNET_SCHEDULER_PRIORITY_IDLE,
- &_chat_messenger_idle,
- app
- );
-
- return;
- }
+ MESSENGER_ApplicationSignal signal;
+ int received = read(app->chat.pipe[0], &signal, sizeof(signal));
+
+ if (received < 0)
+ signal = MESSENGER_FAIL;
GNUNET_CHAT_iterate_contacts(
app->chat.messenger.handle,
@@ -63,8 +57,7 @@ _chat_messenger_idle(void *cls)
GNUNET_CHAT_stop(app->chat.messenger.handle);
app->chat.messenger.handle = NULL;
- if (MESSENGER_QUIT != app->chat.signal)
- GNUNET_SCHEDULER_shutdown();
+ GNUNET_SCHEDULER_shutdown();
}
static int
@@ -181,10 +174,17 @@ chat_messenger_run(void *cls,
app
);
- app->chat.messenger.idle = GNUNET_SCHEDULER_add_delayed_with_priority(
- GNUNET_TIME_relative_get_zero_(),
- GNUNET_SCHEDULER_PRIORITY_IDLE,
- &_chat_messenger_idle,
+ struct GNUNET_NETWORK_FDSet *fd = GNUNET_NETWORK_fdset_create ();
+ GNUNET_NETWORK_fdset_set_native(fd, app->chat.pipe[0]);
+
+ app->chat.messenger.quit = GNUNET_SCHEDULER_add_select(
+ GNUNET_SCHEDULER_PRIORITY_URGENT,
+ GNUNET_TIME_relative_get_forever_(),
+ fd,
+ NULL,
+ &_chat_messenger_quit,
app
);
+
+ GNUNET_NETWORK_fdset_destroy(fd);
}
diff --git a/src/chat/messenger.h b/src/chat/messenger.h
@@ -1,6 +1,6 @@
/*
This file is part of GNUnet.
- Copyright (C) 2021 GNUnet e.V.
+ Copyright (C) 2021--2022 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
@@ -35,7 +35,7 @@ typedef struct MESSENGER_Application MESSENGER_Application;
typedef struct CHAT_MESSENGER_Handle
{
struct GNUNET_CHAT_Handle *handle;
- struct GNUNET_SCHEDULER_Task *idle;
+ struct GNUNET_SCHEDULER_Task *quit;
} CHAT_MESSENGER_Handle;
void
diff --git a/src/ui/chat.c b/src/ui/chat.c
@@ -486,6 +486,10 @@ ui_chat_new(MESSENGER_Application *app)
app
);
+ handle->chat_files_listbox = GTK_LIST_BOX(
+ gtk_builder_get_object(handle->builder, "chat_files_listbox")
+ );
+
handle->messages_listbox = GTK_LIST_BOX(
gtk_builder_get_object(handle->builder, "messages_listbox")
);
diff --git a/src/ui/chat.h b/src/ui/chat.h
@@ -73,6 +73,7 @@ typedef struct UI_CHAT_Handle
GtkScrolledWindow *chat_scrolled_window;
GtkListBox *chat_contacts_listbox;
+ GtkListBox *chat_files_listbox;
GtkListBox *messages_listbox;
GtkButton *attach_file_button;