aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTheJackiMonster <thejackimonster@gmail.com>2022-01-19 13:41:10 +0100
committerTheJackiMonster <thejackimonster@gmail.com>2022-01-19 13:41:10 +0100
commitd739a0214d83b1fd366c167a610b8dbf1205f483 (patch)
tree537b01c784d920d3726a691a01bd750869c7f0e2
parent03badafe00a8bf4a019dca2ccac8e8937ff59899 (diff)
downloadmessenger-gtk-d739a0214d83b1fd366c167a610b8dbf1205f483.tar.gz
messenger-gtk-d739a0214d83b1fd366c167a610b8dbf1205f483.zip
Added files listbox and replaced idle task to shutdown gnunet with a select
Signed-off-by: TheJackiMonster <thejackimonster@gmail.com>
-rw-r--r--resources/ui/chat.ui46
-rw-r--r--src/application.c12
-rw-r--r--src/application.h4
-rw-r--r--src/chat/messenger.c36
-rw-r--r--src/chat/messenger.h4
-rw-r--r--src/ui/chat.c4
-rw-r--r--src/ui/chat.h1
7 files changed, 82 insertions, 25 deletions
diff --git a/resources/ui/chat.ui b/resources/ui/chat.ui
index b99c28e..383645d 100644
--- a/resources/ui/chat.ui
+++ b/resources/ui/chat.ui
@@ -611,6 +611,52 @@ Author: Tobias Frisch
611 <property name="position">1</property> 611 <property name="position">1</property>
612 </packing> 612 </packing>
613 </child> 613 </child>
614 <child>
615 <object class="GtkBox">
616 <property name="visible">True</property>
617 <property name="can-focus">False</property>
618 <property name="orientation">vertical</property>
619 <child>
620 <object class="GtkLabel">
621 <property name="visible">True</property>
622 <property name="can-focus">False</property>
623 <property name="label" translatable="yes">Files</property>
624 <property name="xalign">0</property>
625 <attributes>
626 <attribute name="weight" value="semibold"/>
627 </attributes>
628 <style>
629 <class name="details-group-title"/>
630 </style>
631 </object>
632 <packing>
633 <property name="expand">False</property>
634 <property name="fill">True</property>
635 <property name="position">0</property>
636 </packing>
637 </child>
638 <child>
639 <object class="GtkListBox" id="chat_files_listbox">
640 <property name="visible">True</property>
641 <property name="can-focus">False</property>
642 <property name="selection-mode">none</property>
643 </object>
644 <packing>
645 <property name="expand">False</property>
646 <property name="fill">True</property>
647 <property name="position">1</property>
648 </packing>
649 </child>
650 <style>
651 <class name="details-group"/>
652 </style>
653 </object>
654 <packing>
655 <property name="expand">False</property>
656 <property name="fill">True</property>
657 <property name="position">2</property>
658 </packing>
659 </child>
614 </object> 660 </object>
615 </child> 661 </child>
616 </object> 662 </object>
diff --git a/src/application.c b/src/application.c
index b2425c0..4f7b024 100644
--- a/src/application.c
+++ b/src/application.c
@@ -1,6 +1,6 @@
1/* 1/*
2 This file is part of GNUnet. 2 This file is part of GNUnet.
3 Copyright (C) 2021 GNUnet e.V. 3 Copyright (C) 2021--2022 GNUnet e.V.
4 4
5 GNUnet is free software: you can redistribute it and/or modify it 5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published 6 under the terms of the GNU Affero General Public License as published
@@ -79,7 +79,7 @@ application_init(MESSENGER_Application *app,
79 79
80 app->chat.status = EXIT_FAILURE; 80 app->chat.status = EXIT_FAILURE;
81 app->chat.tid = 0; 81 app->chat.tid = 0;
82 app->chat.signal = MESSENGER_NONE; 82 pipe(app->chat.pipe);
83 83
84 pthread_mutex_init(&(app->chat.mutex), NULL); 84 pthread_mutex_init(&(app->chat.mutex), NULL);
85 85
@@ -175,10 +175,16 @@ application_run(MESSENGER_Application *app)
175 app->argv 175 app->argv
176 ); 176 );
177 177
178 if (app->ui.status != 0)
179 application_exit(app, MESSENGER_FAIL);
180
178 pthread_join(app->chat.tid, NULL); 181 pthread_join(app->chat.tid, NULL);
179 182
180 g_hash_table_destroy(app->ui.bindings); 183 g_hash_table_destroy(app->ui.bindings);
181 184
185 close(app->chat.pipe[0]);
186 close(app->chat.pipe[1]);
187
182 pthread_mutex_destroy(&(app->chat.mutex)); 188 pthread_mutex_destroy(&(app->chat.mutex));
183 189
184 GList *list = app->notifications; 190 GList *list = app->notifications;
@@ -286,7 +292,7 @@ void
286application_exit(MESSENGER_Application *app, 292application_exit(MESSENGER_Application *app,
287 MESSENGER_ApplicationSignal signal) 293 MESSENGER_ApplicationSignal signal)
288{ 294{
289 app->chat.signal = signal; 295 write(app->chat.pipe[1], &signal, sizeof(signal));
290} 296}
291 297
292int 298int
diff --git a/src/application.h b/src/application.h
index d66a0cd..291bc1b 100644
--- a/src/application.h
+++ b/src/application.h
@@ -1,6 +1,6 @@
1/* 1/*
2 This file is part of GNUnet. 2 This file is part of GNUnet.
3 Copyright (C) 2021 GNUnet e.V. 3 Copyright (C) 2021--2022 GNUnet e.V.
4 4
5 GNUnet is free software: you can redistribute it and/or modify it 5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published 6 under the terms of the GNU Affero General Public License as published
@@ -62,7 +62,7 @@ typedef struct MESSENGER_Application
62 pthread_t tid; 62 pthread_t tid;
63 char *identity; 63 char *identity;
64 64
65 MESSENGER_ApplicationSignal signal; 65 int pipe [2];
66 pthread_mutex_t mutex; 66 pthread_mutex_t mutex;
67 67
68 CHAT_MESSENGER_Handle messenger; 68 CHAT_MESSENGER_Handle messenger;
diff --git a/src/chat/messenger.c b/src/chat/messenger.c
index bea3299..eb8523b 100644
--- a/src/chat/messenger.c
+++ b/src/chat/messenger.c
@@ -38,21 +38,15 @@ _chat_messenger_destroy_contacts(UNUSED void *cls,
38} 38}
39 39
40static void 40static void
41_chat_messenger_idle(void *cls) 41_chat_messenger_quit(void *cls)
42{ 42{
43 MESSENGER_Application *app = (MESSENGER_Application*) cls; 43 MESSENGER_Application *app = (MESSENGER_Application*) cls;
44 44
45 if (MESSENGER_NONE == app->chat.signal) 45 MESSENGER_ApplicationSignal signal;
46 { 46 int received = read(app->chat.pipe[0], &signal, sizeof(signal));
47 app->chat.messenger.idle = GNUNET_SCHEDULER_add_delayed_with_priority( 47
48 GNUNET_TIME_relative_get_second_(), 48 if (received < 0)
49 GNUNET_SCHEDULER_PRIORITY_IDLE, 49 signal = MESSENGER_FAIL;
50 &_chat_messenger_idle,
51 app
52 );
53
54 return;
55 }
56 50
57 GNUNET_CHAT_iterate_contacts( 51 GNUNET_CHAT_iterate_contacts(
58 app->chat.messenger.handle, 52 app->chat.messenger.handle,
@@ -63,8 +57,7 @@ _chat_messenger_idle(void *cls)
63 GNUNET_CHAT_stop(app->chat.messenger.handle); 57 GNUNET_CHAT_stop(app->chat.messenger.handle);
64 app->chat.messenger.handle = NULL; 58 app->chat.messenger.handle = NULL;
65 59
66 if (MESSENGER_QUIT != app->chat.signal) 60 GNUNET_SCHEDULER_shutdown();
67 GNUNET_SCHEDULER_shutdown();
68} 61}
69 62
70static int 63static int
@@ -181,10 +174,17 @@ chat_messenger_run(void *cls,
181 app 174 app
182 ); 175 );
183 176
184 app->chat.messenger.idle = GNUNET_SCHEDULER_add_delayed_with_priority( 177 struct GNUNET_NETWORK_FDSet *fd = GNUNET_NETWORK_fdset_create ();
185 GNUNET_TIME_relative_get_zero_(), 178 GNUNET_NETWORK_fdset_set_native(fd, app->chat.pipe[0]);
186 GNUNET_SCHEDULER_PRIORITY_IDLE, 179
187 &_chat_messenger_idle, 180 app->chat.messenger.quit = GNUNET_SCHEDULER_add_select(
181 GNUNET_SCHEDULER_PRIORITY_URGENT,
182 GNUNET_TIME_relative_get_forever_(),
183 fd,
184 NULL,
185 &_chat_messenger_quit,
188 app 186 app
189 ); 187 );
188
189 GNUNET_NETWORK_fdset_destroy(fd);
190} 190}
diff --git a/src/chat/messenger.h b/src/chat/messenger.h
index 4e3f80a..888e4cd 100644
--- a/src/chat/messenger.h
+++ b/src/chat/messenger.h
@@ -1,6 +1,6 @@
1/* 1/*
2 This file is part of GNUnet. 2 This file is part of GNUnet.
3 Copyright (C) 2021 GNUnet e.V. 3 Copyright (C) 2021--2022 GNUnet e.V.
4 4
5 GNUnet is free software: you can redistribute it and/or modify it 5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published 6 under the terms of the GNU Affero General Public License as published
@@ -35,7 +35,7 @@ typedef struct MESSENGER_Application MESSENGER_Application;
35typedef struct CHAT_MESSENGER_Handle 35typedef struct CHAT_MESSENGER_Handle
36{ 36{
37 struct GNUNET_CHAT_Handle *handle; 37 struct GNUNET_CHAT_Handle *handle;
38 struct GNUNET_SCHEDULER_Task *idle; 38 struct GNUNET_SCHEDULER_Task *quit;
39} CHAT_MESSENGER_Handle; 39} CHAT_MESSENGER_Handle;
40 40
41void 41void
diff --git a/src/ui/chat.c b/src/ui/chat.c
index e0b284d..03af9d0 100644
--- a/src/ui/chat.c
+++ b/src/ui/chat.c
@@ -486,6 +486,10 @@ ui_chat_new(MESSENGER_Application *app)
486 app 486 app
487 ); 487 );
488 488
489 handle->chat_files_listbox = GTK_LIST_BOX(
490 gtk_builder_get_object(handle->builder, "chat_files_listbox")
491 );
492
489 handle->messages_listbox = GTK_LIST_BOX( 493 handle->messages_listbox = GTK_LIST_BOX(
490 gtk_builder_get_object(handle->builder, "messages_listbox") 494 gtk_builder_get_object(handle->builder, "messages_listbox")
491 ); 495 );
diff --git a/src/ui/chat.h b/src/ui/chat.h
index 8b38db8..300a9be 100644
--- a/src/ui/chat.h
+++ b/src/ui/chat.h
@@ -73,6 +73,7 @@ typedef struct UI_CHAT_Handle
73 GtkScrolledWindow *chat_scrolled_window; 73 GtkScrolledWindow *chat_scrolled_window;
74 74
75 GtkListBox *chat_contacts_listbox; 75 GtkListBox *chat_contacts_listbox;
76 GtkListBox *chat_files_listbox;
76 GtkListBox *messages_listbox; 77 GtkListBox *messages_listbox;
77 78
78 GtkButton *attach_file_button; 79 GtkButton *attach_file_button;