Skip to content

Commit

Permalink
LinGUI: New dialogs for stopping encoding
Browse files Browse the repository at this point in the history
- Removes use of deprecated gtk_dialog_run()
- Better dialog messages
- Make dialogs appear modal on current window
  • Loading branch information
robxnano authored and galad87 committed Nov 29, 2023
1 parent cca2e01 commit c3ef553
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 55 deletions.
105 changes: 61 additions & 44 deletions gtk/src/callbacks.c
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ static GList* dvd_device_list(void);
static void prune_logs(signal_user_data_t *ud);
static gboolean can_suspend_logind(void);
static void suspend_logind(void);
static void quit_dialog_show(signal_user_data_t *ud);
static void quit_dialog_response(GtkDialog *dialog, int response, signal_user_data_t *ud);
static gboolean has_drive = FALSE;

Expand Down Expand Up @@ -514,8 +515,7 @@ quit_action_cb(GSimpleAction *action, GVariant *param, signal_user_data_t *ud)
gint state = ghb_get_queue_state();
if (state & (GHB_STATE_WORKING|GHB_STATE_SEARCHING))
{
ghb_stop_encode_dialog(FALSE, _("Closing HandBrake will terminate encoding.\n"),
G_CALLBACK(quit_dialog_response), ud);
quit_dialog_show(ud);
return;
}
else
Expand Down Expand Up @@ -1975,8 +1975,7 @@ window_delete_event_cb(
gint state = ghb_get_queue_state();
if (state & (GHB_STATE_WORKING|GHB_STATE_SEARCHING))
{
ghb_stop_encode_dialog(FALSE, _("Closing HandBrake will terminate encoding.\n"),
G_CALLBACK(quit_dialog_response), ud);
quit_dialog_show(ud);
}
else
{
Expand Down Expand Up @@ -3800,8 +3799,42 @@ ghb_error_dialog(GtkWindow *parent, GtkMessageType type, const gchar *message, c
ghb_message_dialog(parent, type, message, cancel, NULL);
}

GtkWidget *
ghb_cancel_dialog_new (GtkWindow *parent, const char *title, const char *message,
const char *cancel_all_button, const char *cancel_current_button,
const char *finish_button, const char *continue_button)
{
GtkWidget *dialog, *cancel;
GtkStyleContext *style;

dialog = gtk_message_dialog_new(parent, GTK_DIALOG_MODAL,
GTK_MESSAGE_WARNING, GTK_BUTTONS_NONE, "%s", title);
gtk_message_dialog_format_secondary_text(GTK_MESSAGE_DIALOG(dialog), message);
gtk_window_set_transient_for(GTK_WINDOW(dialog), parent);
gtk_window_set_modal(GTK_WINDOW(dialog), TRUE);
cancel = gtk_dialog_add_button(GTK_DIALOG(dialog), cancel_all_button, 1);
style = gtk_widget_get_style_context(cancel);
gtk_style_context_add_class(style, "destructive-action");
if (cancel_current_button != NULL)
{
cancel = gtk_dialog_add_button(GTK_DIALOG(dialog), cancel_current_button, 2);
style = gtk_widget_get_style_context(cancel);
gtk_style_context_add_class(style, "destructive-action");
}
if (finish_button != NULL)
{
gtk_dialog_add_button (GTK_DIALOG(dialog), finish_button, 3);
}
if (continue_button != NULL)
{
gtk_dialog_add_button(GTK_DIALOG(dialog), continue_button, 4);
}
return dialog;
}

static void
cancel_encode_response (GtkDialog *dialog, int response, signal_user_data_t *ud)
stop_encode_dialog_response (GtkDialog *dialog, int response,
signal_user_data_t *ud)
{
g_signal_handlers_disconnect_by_data(dialog, ud);
gtk_widget_destroy(GTK_WIDGET(dialog));
Expand All @@ -3826,6 +3859,20 @@ cancel_encode_response (GtkDialog *dialog, int response, signal_user_data_t *ud)
}
}

void
ghb_stop_encode_dialog_show (signal_user_data_t *ud)
{
GtkWindow *window = gtk_application_get_active_window(
GTK_APPLICATION(g_application_get_default()));
GtkWidget *dialog = ghb_cancel_dialog_new(window, _("Stop Encoding?"),
_("Your movie will be lost if you don't continue encoding."),
_("Cancel Current and Stop"), _("Cancel Current, Start Next"),
_("Finish Current, Start Next"), _("Continue Encoding"));
g_signal_connect(dialog, "response",
G_CALLBACK(stop_encode_dialog_response), ud);
gtk_widget_show(dialog);
}

static void
quit_dialog_response (GtkDialog *dialog, int response, signal_user_data_t *ud)
{
Expand All @@ -3835,46 +3882,16 @@ quit_dialog_response (GtkDialog *dialog, int response, signal_user_data_t *ud)
application_quit(ud);
}
}

GtkWidget *
ghb_stop_encode_dialog (gboolean show_all_options, const char *extra_msg,
GCallback response, signal_user_data_t *ud)
{
GtkWindow *hb_window;
GtkWidget *dialog, *cancel;
GtkStyleContext *style;

if (extra_msg == NULL) extra_msg = "";
// Toss up a warning dialog
hb_window = GTK_WINDOW(GHB_WIDGET(ud->builder, "hb_window"));
dialog = gtk_message_dialog_new(hb_window, GTK_DIALOG_MODAL,
GTK_MESSAGE_WARNING, GTK_BUTTONS_NONE,
_("%sYour movie will be lost if you don't continue encoding."),
extra_msg);
cancel = gtk_dialog_add_button(GTK_DIALOG(dialog),
_("Cancel Current and Stop"), 1);
style = gtk_widget_get_style_context(cancel);
gtk_style_context_add_class(style, "destructive-action");
if (show_all_options)
{
cancel = gtk_dialog_add_button(GTK_DIALOG(dialog),
_("Cancel Current, Start Next"), 2);
style = gtk_widget_get_style_context(cancel);
gtk_style_context_add_class(style, "destructive-action");
gtk_dialog_add_button (GTK_DIALOG(dialog),
_("Finish Current, then Stop"), 3);
}
gtk_dialog_add_button(GTK_DIALOG(dialog), _("Continue Encoding"), 4);

g_signal_connect(dialog, "response", response, ud);
static void
quit_dialog_show (signal_user_data_t *ud)
{
GtkWindow *window = gtk_application_get_active_window(
GTK_APPLICATION(g_application_get_default()));
GtkWidget *dialog = ghb_cancel_dialog_new(window, _("Quit HandBrake?"),
_("Your movie will be lost if you don't continue encoding."),
_("Cancel All and Quit"), NULL, NULL, _("Continue Encoding"));
g_signal_connect(dialog, "response", G_CALLBACK(quit_dialog_response), ud);
gtk_widget_show(dialog);
return dialog;
}

void
ghb_cancel_encode (signal_user_data_t *ud, const char *extra_msg)
{
ghb_stop_encode_dialog(TRUE, extra_msg, G_CALLBACK(cancel_encode_response), ud);
}

static void
Expand Down
8 changes: 5 additions & 3 deletions gtk/src/callbacks.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,11 @@ gboolean ghb_message_dialog(
void ghb_error_dialog(
GtkWindow *parent, GtkMessageType type,
const gchar *message, const gchar *cancel);
void ghb_cancel_encode(signal_user_data_t *ud, const gchar *extra_msg);
GtkWidget *ghb_stop_encode_dialog(gboolean show_all_options,
const char *extra_msg, GCallback response, signal_user_data_t *ud);
GtkWidget *ghb_cancel_dialog_new(GtkWindow *parent,
const char *title, const char *message, const char *cancel_all_button,
const char *cancel_current_button, const char *finish_button,
const char *continue_button);
void ghb_stop_encode_dialog_show(signal_user_data_t *ud);
void ghb_start_next_job(signal_user_data_t *ud);
void ghb_bind_dependencies (signal_user_data_t *ud);
void ghb_do_scan( signal_user_data_t *ud, const gchar *filename,
Expand Down
28 changes: 20 additions & 8 deletions gtk/src/queuehandler.c
Original file line number Diff line number Diff line change
Expand Up @@ -1869,17 +1869,15 @@ list_box_get_row(GtkWidget *widget)
return GTK_LIST_BOX_ROW(widget);
}

static GtkWidget *queue_remove_dialog = NULL;
static int queue_remove_index = -1;
static int queue_remove_unique_id = -1;

static void
queue_remove_row_cb (GtkWidget *dialog, int response, signal_user_data_t *ud)
queue_remove_response (GtkWidget *dialog, int response, signal_user_data_t *ud)
{
if (dialog != NULL)
{
gtk_widget_destroy(dialog);
queue_remove_dialog = NULL;
}

if (response != 1 || queue_remove_index < 0)
Expand All @@ -1903,12 +1901,27 @@ queue_remove_row_cb (GtkWidget *dialog, int response, signal_user_data_t *ud)
queue_remove_index = -1;
}

static void
queue_remove_dialog_show (signal_user_data_t *ud)
{
GtkWidget *dialog;
GtkWindow *queue_window;

queue_window = GTK_WINDOW(GHB_WIDGET(ud->builder, "queue_window"));
dialog = ghb_cancel_dialog_new(queue_window, _("Remove Item in Progress?"),
_("Your movie will be lost if you don't continue encoding."),
_("Cancel and Remove"), NULL, NULL, _("Continue Encoding"));

g_signal_connect(dialog, "response", G_CALLBACK(queue_remove_response), ud);
gtk_widget_show(dialog);
}

static void
ghb_queue_remove_row_internal (signal_user_data_t *ud, int index)
{
GhbValue *queueDict, *uiDict;

if (index < 0 || index >= ghb_array_len(ud->queue) || queue_remove_dialog != NULL)
if (index < 0 || index >= ghb_array_len(ud->queue))
{
return;
}
Expand All @@ -1922,11 +1935,11 @@ ghb_queue_remove_row_internal (signal_user_data_t *ud, int index)
{
// Ask if wants to stop encode.
queue_remove_unique_id = ghb_dict_get_int(uiDict, "job_unique_id");
ghb_stop_encode_dialog(FALSE, "", G_CALLBACK(queue_remove_row_cb), ud);
queue_remove_dialog_show(ud);
}
else
{
queue_remove_row_cb(NULL, 1, ud);
queue_remove_response(NULL, 1, ud);
}
}

Expand Down Expand Up @@ -2711,8 +2724,7 @@ queue_start_action_cb (GSimpleAction *action, GVariant *param,
if (state & (GHB_STATE_WORKING | GHB_STATE_SEARCHING |
GHB_STATE_SCANNING | GHB_STATE_MUXING))
{
ghb_cancel_encode(ud, _("You are currently encoding. "
"What would you like to do?\n\n"));
ghb_stop_encode_dialog_show(ud);
return;
}

Expand Down

0 comments on commit c3ef553

Please sign in to comment.