summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPatrick McDermott <pj@pehjota.net>2017-10-07 18:49:05 (EDT)
committer Patrick McDermott <pj@pehjota.net>2017-10-07 18:49:05 (EDT)
commit7c5cfad314441b669b825e2ceb3b31b221b9ae65 (patch)
tree234e9f9e8f3d4cc3cd5afaac28a3f235a40a2056
parent851d4f5b36c2ea42d4480842d270e2fbbb024a24 (diff)
downloadmarquee-7c5cfad314441b669b825e2ceb3b31b221b9ae65.zip
marquee-7c5cfad314441b669b825e2ceb3b31b221b9ae65.tar.gz
marquee-7c5cfad314441b669b825e2ceb3b31b221b9ae65.tar.bz2
mq_application_quit(): New function
-rw-r--r--src/application.c95
-rw-r--r--src/application.h3
2 files changed, 98 insertions, 0 deletions
diff --git a/src/application.c b/src/application.c
index c553bc1..f5edc7f 100644
--- a/src/application.c
+++ b/src/application.c
@@ -73,6 +73,101 @@ mq_application_main(MqApplication G_GNUC_UNUSED *application)
return EXIT_SUCCESS;
}
+static void
+quit_confirm_warn_check_button_toggled_cb(GtkToggleButton *toggle_button,
+ MqApplication *application)
+{
+ mq_config_set_boolean(application->config, "tabs.warn-on-close",
+ gtk_toggle_button_get_active(toggle_button));
+ mq_config_save(application->config);
+}
+
+static void
+quit_confirm_response_cb(GtkWidget *dialog, gint response_id)
+{
+ gtk_widget_destroy(dialog);
+ if (response_id == GTK_RESPONSE_OK) {
+ gtk_main_quit();
+ }
+}
+
+void
+mq_application_quit(MqApplication *application, GtkWindow *parent)
+{
+ guint num_windows;
+ guint num_tabs;
+ GList *item;
+ gchar *message;
+ GtkWidget *message_label;
+ GtkWidget *check_button;
+ GtkWidget *vbox;
+ GtkWidget *hbox;
+ GtkWidget *dialog;
+
+ num_windows = 0;
+ num_tabs = 0;
+ for (item = application->windows; item; item = item->next) {
+ ++num_windows;
+ num_tabs += mq_window_get_num_tabs(item->data);
+ }
+
+ if (num_tabs == 1) { /* Also implies num_windows == 1 */
+ gtk_main_quit();
+ return; /* Making sure... */
+ }
+
+ if (!mq_config_get_boolean(application->config, "tabs.warn-on-close")) {
+ gtk_main_quit();
+ return; /* Making sure... */
+ }
+
+ /* Message */
+ message = g_strdup_printf("You are about to close %d tabs "
+ "in %d windows. Are you sure you want to continue?",
+ num_tabs, num_windows);
+ message_label = gtk_label_new(message);
+ g_free(message);
+
+ /* Check button */
+ check_button = gtk_check_button_new_with_mnemonic(
+ "_Warn When Closing Multiple Tabs or Windows");
+ gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(check_button),
+ mq_config_get_boolean(application->config,
+ "tabs.warn-on-close"));
+ /* Connect signal after setting initial toggle status, to avoid a
+ * spurious signal. */
+ g_signal_connect(check_button, "toggled",
+ G_CALLBACK(quit_confirm_warn_check_button_toggled_cb),
+ application);
+
+ /* Right vertical box (message and check button) */
+ vbox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0);
+ gtk_box_pack_start(GTK_BOX(vbox), message_label, FALSE, FALSE, 0);
+ gtk_box_pack_start(GTK_BOX(vbox), check_button, FALSE, FALSE, 0);
+
+ /* Horizontal box (icon and right vertical box) */
+ hbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0);
+ gtk_box_pack_start(GTK_BOX(hbox), gtk_image_new_from_icon_name(
+ "dialog-question", GTK_ICON_SIZE_DIALOG), FALSE, FALSE,
+ 0);
+ gtk_box_pack_start(GTK_BOX(hbox), vbox, FALSE, FALSE, 0);
+
+ /* Dialog */
+ dialog = gtk_dialog_new_with_buttons("Confirm Close", parent,
+ GTK_DIALOG_DESTROY_WITH_PARENT,
+ "_Cancel", GTK_RESPONSE_CANCEL,
+ "Cl_ose Tabs", GTK_RESPONSE_OK,
+ NULL);
+ gtk_container_add(
+ GTK_CONTAINER(gtk_dialog_get_content_area(GTK_DIALOG(dialog))),
+ hbox);
+ g_signal_connect(dialog, "response",
+ G_CALLBACK(quit_confirm_response_cb), NULL);
+ gtk_widget_show_all(dialog);
+
+ return;
+}
+
MqConfig *
mq_application_get_config(MqApplication *application)
{
diff --git a/src/application.h b/src/application.h
index 8fa6f1c..4b5d08f 100644
--- a/src/application.h
+++ b/src/application.h
@@ -43,6 +43,9 @@ mq_application_new(gchar *profile, gboolean private);
int
mq_application_main(MqApplication *application);
+void
+mq_application_quit(MqApplication *application, GtkWindow *parent);
+
MqConfig *
mq_application_get_config(MqApplication *application);