From 49f4612c6e38c5ebbe56a37c1619c112ff73e3af Mon Sep 17 00:00:00 2001 From: fedir Date: Thu, 22 May 2025 19:01:16 +0200 Subject: [PATCH] Changed exit codes of dialogue to change the semantics of closing dialogue window with (x) button. --- src/gui/icfs_dialogue.c | 9 +++++---- src/ui-socket.c | 7 ++++--- test/mock/icfs_dialogue | 9 +++++---- 3 files changed, 14 insertions(+), 11 deletions(-) diff --git a/src/gui/icfs_dialogue.c b/src/gui/icfs_dialogue.c index 490af8b..f709409 100644 --- a/src/gui/icfs_dialogue.c +++ b/src/gui/icfs_dialogue.c @@ -7,9 +7,10 @@ #include #include -#define YES 0 -#define NO 1 +#define YES 1 +#define NO 0 #define PERM 2 +#define TEMP 0 int exit_code = 0; gboolean is_permanent = false; @@ -20,7 +21,7 @@ static void positive_response(GtkWindow *window) { fprintf(stdout, "%s", gtk_entry_buffer_get_text(entry_buffer)); exit_code = (gtk_check_button_get_active(GTK_CHECK_BUTTON(checkbox))) ? YES | PERM - : YES; + : YES | TEMP; gtk_window_close(window); } @@ -28,7 +29,7 @@ static void negative_response(GtkWindow *window) { fprintf(stdout, "%s", gtk_entry_buffer_get_text(entry_buffer)); exit_code = (gtk_check_button_get_active(GTK_CHECK_BUTTON(checkbox))) ? NO | PERM - : NO; + : NO | TEMP; gtk_window_close(window); } diff --git a/src/ui-socket.c b/src/ui-socket.c index 33f56c3..dfcff20 100644 --- a/src/ui-socket.c +++ b/src/ui-socket.c @@ -26,9 +26,10 @@ #include #include -#define DIALOGUE_YES 0 -#define DIALOGUE_NO 1 +#define DIALOGUE_YES 1 +#define DIALOGUE_NO 0 #define DIALOGUE_PERM 2 +#define DIALOGUE_TEMP 0 pthread_mutex_t access_check_mutex = PTHREAD_MUTEX_INITIALIZER; @@ -146,7 +147,7 @@ struct dialogue_response ask_access(const char *filename, if (dialogue_exit_code == (DIALOGUE_YES | DIALOGUE_PERM)) { response.decision = ALLOW; - } else if (dialogue_exit_code == DIALOGUE_YES) { + } else if (dialogue_exit_code == DIALOGUE_YES | DIALOGUE_TEMP) { response.decision = ALLOW_TEMP; } else if (dialogue_exit_code == (DIALOGUE_NO | DIALOGUE_PERM)) { response.decision = DENY; diff --git a/test/mock/icfs_dialogue b/test/mock/icfs_dialogue index 99ef036..ea987d9 100755 --- a/test/mock/icfs_dialogue +++ b/test/mock/icfs_dialogue @@ -2,9 +2,10 @@ # fake-icfs_dialogue: script that mocks the behavior of icfs_dialogue based on the ./.fake-icfs_dialogue-response file -ICFS_DIALOGUE_YES=0 -ICFS_DIALOGUE_NO=1 +ICFS_DIALOGUE_YES=1 +ICFS_DIALOGUE_NO=0 ICFS_DIALOGUE_PERM=2 +ICFS_DIALOGUE_TEMP=0 if [[ $1 == "--set-fake-response" ]]; then #someone knows we are fake :) @@ -27,9 +28,9 @@ else fi if [[ $FAKE_ICFS_DIALOGUE_RESPONSE == "yes" ]]; then - exit "$ICFS_DIALOGUE_YES" + exit "$((ICFS_DIALOGUE_YES | ICFS_DIALOGUE_TEMP))" elif [[ $FAKE_ICFS_DIALOGUE_RESPONSE == "no" ]]; then - exit "$ICFS_DIALOGUE_NO" + exit "$((ICFS_DIALOGUE_NO | ICFS_DIALOGUE_TEMP))" elif [[ $FAKE_ICFS_DIALOGUE_RESPONSE == "yes_perm" ]]; then exit "$((ICFS_DIALOGUE_YES | ICFS_DIALOGUE_PERM))" elif [[ $FAKE_ICFS_DIALOGUE_RESPONSE == "no_perm" ]]; then