commit be913f75546422d3e8e1c3b84d0ee66ae3e26602
parent 2ed903525356c027d16fc3ae7cef16a7ee1775af
Author: TheJackiMonster <thejackimonster@gmail.com>
Date: Sat, 19 Mar 2022 18:22:12 +0100
Implemented switchable settings and added visible whispering
Signed-off-by: TheJackiMonster <thejackimonster@gmail.com>
Diffstat:
9 files changed, 287 insertions(+), 43 deletions(-)
diff --git a/resources/ui/message_content.ui b/resources/ui/message_content.ui
@@ -173,6 +173,46 @@ Author: Tobias Frisch
<property name="position">2</property>
</packing>
</child>
+ <child>
+ <object class="GtkBox" id="whisper_box">
+ <property name="visible">True</property>
+ <property name="can-focus">False</property>
+ <property name="spacing">4</property>
+ <child>
+ <object class="GtkImage">
+ <property name="visible">True</property>
+ <property name="can-focus">False</property>
+ <property name="icon-name">face-shutmouth-symbolic</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">whispering...</property>
+ <property name="xalign">0</property>
+ <attributes>
+ <attribute name="style" value="italic"/>
+ </attributes>
+ </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>
+ </object>
+ <packing>
+ <property name="name">whisper_page</property>
+ <property name="position">3</property>
+ </packing>
+ </child>
</object>
<packing>
<property name="expand">True</property>
diff --git a/resources/ui/settings.ui b/resources/ui/settings.ui
@@ -107,6 +107,7 @@ Author: Tobias Frisch
<child>
<object class="GtkSwitch">
<property name="visible">True</property>
+ <property name="sensitive">False</property>
<property name="can-focus">True</property>
</object>
<packing>
@@ -148,6 +149,7 @@ Author: Tobias Frisch
<child>
<object class="GtkSwitch">
<property name="visible">True</property>
+ <property name="sensitive">False</property>
<property name="can-focus">True</property>
</object>
<packing>
@@ -202,7 +204,7 @@ Author: Tobias Frisch
</packing>
</child>
<child>
- <object class="GtkSwitch">
+ <object class="GtkSwitch" id="enable_notifications_switch">
<property name="visible">True</property>
<property name="can-focus">True</property>
</object>
@@ -245,6 +247,7 @@ Author: Tobias Frisch
<child>
<object class="GtkSwitch">
<property name="visible">True</property>
+ <property name="sensitive">False</property>
<property name="can-focus">True</property>
</object>
<packing>
@@ -322,7 +325,7 @@ Author: Tobias Frisch
</packing>
</child>
<child>
- <object class="GtkSwitch">
+ <object class="GtkSwitch" id="read_receipts_switch">
<property name="visible">True</property>
<property name="can-focus">True</property>
</object>
@@ -363,7 +366,7 @@ Author: Tobias Frisch
</packing>
</child>
<child>
- <object class="GtkSwitch">
+ <object class="GtkSwitch" id="whispering_switch">
<property name="visible">True</property>
<property name="can-focus">True</property>
</object>
@@ -412,7 +415,7 @@ Author: Tobias Frisch
</packing>
</child>
<child>
- <object class="GtkComboBox">
+ <object class="GtkComboBox" id="auto_delete_combo_box">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="model">delay_store</property>
@@ -470,6 +473,7 @@ Author: Tobias Frisch
<child>
<object class="GtkComboBox">
<property name="visible">True</property>
+ <property name="sensitive">False</property>
<property name="can-focus">False</property>
<property name="model">delay_store</property>
<property name="active">0</property>
@@ -506,6 +510,7 @@ Author: Tobias Frisch
<object class="GtkButton">
<property name="label" translatable="yes">Clear all history</property>
<property name="visible">True</property>
+ <property name="sensitive">False</property>
<property name="can-focus">True</property>
<property name="receives-default">True</property>
<style>
@@ -564,7 +569,7 @@ Author: Tobias Frisch
</packing>
</child>
<child>
- <object class="GtkSwitch">
+ <object class="GtkSwitch" id="auto_accept_invitations_switch">
<property name="visible">True</property>
<property name="can-focus">True</property>
</object>
@@ -606,7 +611,7 @@ Author: Tobias Frisch
</packing>
</child>
<child>
- <object class="GtkComboBox">
+ <object class="GtkComboBox" id="delete_invitations_combo_box">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="model">delay_store</property>
@@ -641,7 +646,7 @@ Author: Tobias Frisch
<property name="visible">True</property>
<property name="can-focus">False</property>
<child>
- <object class="GtkButton">
+ <object class="GtkButton" id="delete_invitations_button">
<property name="label" translatable="yes">Delete all invitations</property>
<property name="visible">True</property>
<property name="can-focus">True</property>
@@ -694,7 +699,7 @@ Author: Tobias Frisch
</packing>
</child>
<child>
- <object class="GtkSwitch">
+ <object class="GtkSwitch" id="auto_accept_files_switch">
<property name="visible">True</property>
<property name="can-focus">True</property>
</object>
@@ -736,7 +741,7 @@ Author: Tobias Frisch
</packing>
</child>
<child>
- <object class="GtkFileChooserButton">
+ <object class="GtkFileChooserButton" id="download_folder_button">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="title" translatable="yes">Select download folder</property>
@@ -778,7 +783,7 @@ Author: Tobias Frisch
</packing>
</child>
<child>
- <object class="GtkComboBox">
+ <object class="GtkComboBox" id="delete_files_combo_box">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="model">delay_store</property>
@@ -813,7 +818,7 @@ Author: Tobias Frisch
<property name="visible">True</property>
<property name="can-focus">False</property>
<child>
- <object class="GtkButton">
+ <object class="GtkButton" id="delete_files_button">
<property name="label" translatable="yes">Delete all files</property>
<property name="visible">True</property>
<property name="can-focus">True</property>
@@ -867,7 +872,7 @@ Author: Tobias Frisch
</packing>
</child>
<child>
- <object class="GtkComboBox">
+ <object class="GtkComboBox" id="leave_chats_combo_box">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="model">delay_store</property>
@@ -902,7 +907,7 @@ Author: Tobias Frisch
<property name="visible">True</property>
<property name="can-focus">False</property>
<child>
- <object class="GtkButton">
+ <object class="GtkButton" id="leave_chats_button">
<property name="label" translatable="yes">Leave all chats</property>
<property name="visible">True</property>
<property name="can-focus">True</property>
diff --git a/src/application.h b/src/application.h
@@ -114,9 +114,16 @@ typedef struct MESSENGER_Application
struct {
gboolean mobile_design;
gboolean hide_delete_dialog;
+
gboolean disable_notifications;
+
+ gboolean send_read_receipts;
+ gboolean show_whispering;
+
+ gboolean accept_all_invitations;
gboolean accept_all_files;
- gboolean accept_all_invites;
+
+ gchar *download_folder_path;
} settings;
} MESSENGER_Application;
diff --git a/src/chat/messenger.c b/src/chat/messenger.c
@@ -150,6 +150,7 @@ _chat_messenger_message(void *cls,
}
case GNUNET_CHAT_KIND_TEXT:
case GNUNET_CHAT_KIND_FILE:
+ case GNUNET_CHAT_KIND_WHISPER:
{
application_call_message_event(
app,
diff --git a/src/event.c b/src/event.c
@@ -521,6 +521,9 @@ event_invitation(MESSENGER_Application *app,
ui_chat_add_message(handle->chat, app, message);
+ if (app->settings.accept_all_invitations)
+ gtk_button_clicked(message->accept_button);
+
enqueue_chat_entry_update(handle);
}
@@ -534,9 +537,19 @@ event_receive_message(MESSENGER_Application *app,
if (!handle)
return;
+ const gboolean whispering = (
+ GNUNET_CHAT_KIND_WHISPER == GNUNET_CHAT_message_get_kind(msg)
+ );
+
+ if ((whispering) && (!(app->settings.show_whispering)))
+ return;
+
const int sent = GNUNET_CHAT_message_is_sent(msg);
const gchar *text = GNUNET_CHAT_message_get_text(msg);
+ if (whispering)
+ text = _("whispers...");
+
if ((text) && (!(*text)))
goto skip_message;
diff --git a/src/ui/message.c b/src/ui/message.c
@@ -373,6 +373,10 @@ ui_message_new(MESSENGER_Application *app,
handle
);
+ handle->whisper_box = GTK_WIDGET(
+ gtk_builder_get_object(handle->builder[1], "whisper_box")
+ );
+
switch (handle->type)
{
case UI_MESSAGE_STATUS:
@@ -425,44 +429,28 @@ ui_message_refresh(UI_MESSAGE_Handle *handle)
gtk_widget_hide(GTK_WIDGET(handle->read_receipt_image));
}
-void
-ui_message_update(UI_MESSAGE_Handle *handle,
- MESSENGER_Application *app,
- const struct GNUNET_CHAT_Message *msg)
+static void
+_update_file_message(UI_MESSAGE_Handle *handle,
+ MESSENGER_Application *app,
+ struct GNUNET_CHAT_File *file)
{
- struct GNUNET_CHAT_File *file = NULL;
-
- handle->msg = msg;
-
- ui_message_refresh(handle);
-
- if (msg)
- {
- file = GNUNET_CHAT_message_get_file(msg);
-
- handle->timestamp = GNUNET_CHAT_message_get_timestamp(msg);
- }
- else
- file = (struct GNUNET_CHAT_File*) (
- g_object_get_qdata(G_OBJECT(handle->message_box), app->quarks.data)
- );
-
- if (!file)
- return;
-
- g_object_set_qdata(G_OBJECT(handle->message_box), app->quarks.data, file);
-
uint64_t size = GNUNET_CHAT_file_get_size(file);
uint64_t local_size = GNUNET_CHAT_file_get_local_size(file);
+ gboolean autostart_download = FALSE;
+
if ((size <= 0) || (size > local_size))
{
gtk_image_set_from_icon_name(
- handle->file_status_image,
- "folder-download-symbolic",
- GTK_ICON_SIZE_BUTTON
+ handle->file_status_image,
+ "folder-download-symbolic",
+ GTK_ICON_SIZE_BUTTON
);
+ if ((app->settings.accept_all_files) &&
+ (!GNUNET_CHAT_file_is_downloading(file)))
+ autostart_download = TRUE;
+
goto file_content;
}
@@ -524,6 +512,45 @@ file_content:
app->quarks.data,
file
);
+
+ if (autostart_download)
+ gtk_button_clicked(handle->file_button);
+}
+
+void
+ui_message_update(UI_MESSAGE_Handle *handle,
+ MESSENGER_Application *app,
+ const struct GNUNET_CHAT_Message *msg)
+{
+ struct GNUNET_CHAT_File *file = NULL;
+
+ handle->msg = msg;
+
+ ui_message_refresh(handle);
+
+ if (msg)
+ {
+ if (GNUNET_CHAT_KIND_WHISPER == GNUNET_CHAT_message_get_kind(msg))
+ gtk_stack_set_visible_child(
+ handle->content_stack,
+ GTK_WIDGET(handle->whisper_box)
+ );
+
+ file = GNUNET_CHAT_message_get_file(msg);
+
+ handle->timestamp = GNUNET_CHAT_message_get_timestamp(msg);
+
+ g_object_set_qdata(G_OBJECT(handle->message_box), app->quarks.data, file);
+ }
+ else
+ file = (struct GNUNET_CHAT_File*) (
+ g_object_get_qdata(G_OBJECT(handle->message_box), app->quarks.data)
+ );
+
+ if (!file)
+ return;
+
+ _update_file_message(handle, app, file);
}
void
diff --git a/src/ui/message.h b/src/ui/message.h
@@ -75,6 +75,8 @@ typedef struct UI_MESSAGE_Handle
GtkDrawingArea *preview_drawing_area;
+ GtkWidget *whisper_box;
+
GdkPixbuf *preview_image;
GdkPixbufAnimation *preview_animation;
GdkPixbufAnimationIter *preview_animation_iter;
diff --git a/src/ui/settings.c b/src/ui/settings.c
@@ -26,6 +26,24 @@
#include "../application.h"
+static gboolean
+handle_general_switch_state(UNUSED GtkSwitch *widget,
+ gboolean state,
+ gpointer user_data)
+{
+ gboolean *setting = (gboolean*) user_data;
+ *setting = state;
+ return FALSE;
+}
+
+static gboolean
+handle_inverted_switch_state(GtkSwitch *widget,
+ gboolean state,
+ gpointer user_data)
+{
+ return handle_general_switch_state(widget, !state, user_data);
+}
+
static void
handle_dialog_destroy(UNUSED GtkWidget *window,
gpointer user_data)
@@ -50,6 +68,118 @@ ui_settings_dialog_init(MESSENGER_Application *app,
GTK_WINDOW(app->ui.messenger.main_window)
);
+ handle->enable_notifications_switch = GTK_SWITCH(
+ gtk_builder_get_object(handle->builder, "enable_notifications_switch")
+ );
+
+ gtk_switch_set_active(
+ handle->enable_notifications_switch,
+ !(app->settings.disable_notifications)
+ );
+
+ g_signal_connect(
+ handle->enable_notifications_switch,
+ "state-set",
+ G_CALLBACK(handle_inverted_switch_state),
+ &(app->settings.disable_notifications)
+ );
+
+ handle->read_receipts_switch = GTK_SWITCH(
+ gtk_builder_get_object(handle->builder, "read_receipts_switch")
+ );
+
+ gtk_switch_set_active(
+ handle->read_receipts_switch,
+ app->settings.send_read_receipts
+ );
+
+ g_signal_connect(
+ handle->read_receipts_switch,
+ "state-set",
+ G_CALLBACK(handle_general_switch_state),
+ &(app->settings.send_read_receipts)
+ );
+
+ handle->whispering_switch = GTK_SWITCH(
+ gtk_builder_get_object(handle->builder, "whispering_switch")
+ );
+
+ gtk_switch_set_active(
+ handle->whispering_switch,
+ app->settings.show_whispering
+ );
+
+ g_signal_connect(
+ handle->whispering_switch,
+ "state-set",
+ G_CALLBACK(handle_general_switch_state),
+ &(app->settings.show_whispering)
+ );
+
+ handle->auto_delete_combo_box = GTK_COMBO_BOX(
+ gtk_builder_get_object(handle->builder, "auto_delete_combo_box")
+ );
+
+ handle->auto_accept_invitations_switch = GTK_SWITCH(
+ gtk_builder_get_object(handle->builder, "auto_accept_invitations_switch")
+ );
+
+ gtk_switch_set_active(
+ handle->auto_accept_invitations_switch,
+ app->settings.accept_all_invitations
+ );
+
+ g_signal_connect(
+ handle->auto_accept_invitations_switch,
+ "state-set",
+ G_CALLBACK(handle_general_switch_state),
+ &(app->settings.accept_all_invitations)
+ );
+
+ handle->delete_invitations_combo_box = GTK_COMBO_BOX(
+ gtk_builder_get_object(handle->builder, "delete_invitations_combo_box")
+ );
+
+ handle->delete_invitations_button = GTK_BUTTON(
+ gtk_builder_get_object(handle->builder, "delete_invitations_button")
+ );
+
+ handle->auto_accept_files_switch = GTK_SWITCH(
+ gtk_builder_get_object(handle->builder, "auto_accept_files_switch")
+ );
+
+ gtk_switch_set_active(
+ handle->auto_accept_files_switch,
+ app->settings.accept_all_files
+ );
+
+ g_signal_connect(
+ handle->auto_accept_files_switch,
+ "state-set",
+ G_CALLBACK(handle_general_switch_state),
+ &(app->settings.accept_all_files)
+ );
+
+ handle->download_folder_button = GTK_FILE_CHOOSER_BUTTON(
+ gtk_builder_get_object(handle->builder, "download_folder_button")
+ );
+
+ handle->delete_files_combo_box = GTK_COMBO_BOX(
+ gtk_builder_get_object(handle->builder, "delete_files_combo_box")
+ );
+
+ handle->delete_files_button = GTK_BUTTON(
+ gtk_builder_get_object(handle->builder, "delete_files_button")
+ );
+
+ handle->leave_chats_combo_box = GTK_COMBO_BOX(
+ gtk_builder_get_object(handle->builder, "leave_chats_combo_box")
+ );
+
+ handle->leave_chats_button = GTK_BUTTON(
+ gtk_builder_get_object(handle->builder, "leave_chats_button")
+ );
+
g_signal_connect(
handle->dialog,
"destroy",
diff --git a/src/ui/settings.h b/src/ui/settings.h
@@ -31,6 +31,25 @@ typedef struct UI_SETTINGS_Handle
{
GtkBuilder *builder;
HdyPreferencesWindow *dialog;
+
+ GtkSwitch *enable_notifications_switch;
+
+ GtkSwitch *read_receipts_switch;
+ GtkSwitch *whispering_switch;
+
+ GtkComboBox *auto_delete_combo_box;
+
+ GtkSwitch *auto_accept_invitations_switch;
+ GtkComboBox *delete_invitations_combo_box;
+ GtkButton *delete_invitations_button;
+
+ GtkSwitch *auto_accept_files_switch;
+ GtkFileChooserButton *download_folder_button;
+ GtkComboBox *delete_files_combo_box;
+ GtkButton *delete_files_button;
+
+ GtkComboBox *leave_chats_combo_box;
+ GtkButton *leave_chats_button;
} UI_SETTINGS_Handle;
void