From 6e5f67794221d216b6929b210d5c65ea7672d5be Mon Sep 17 00:00:00 2001 From: Nedko Arnaudov Date: Sun, 30 Aug 2009 15:35:32 +0300 Subject: [PATCH] gladish: Confirm studio delete dialog --- gui/ask_dialog.c | 73 ++++++++++++++++++++++++++++++++++++++++++++++++ gui/ask_dialog.h | 39 ++++++++++++++++++++++++++ gui/gui.glade | 30 ++++++++++++++++++++ gui/main.c | 10 +++++-- wscript | 1 + 5 files changed, 151 insertions(+), 2 deletions(-) create mode 100644 gui/ask_dialog.c create mode 100644 gui/ask_dialog.h diff --git a/gui/ask_dialog.c b/gui/ask_dialog.c new file mode 100644 index 00000000..5e62ad39 --- /dev/null +++ b/gui/ask_dialog.c @@ -0,0 +1,73 @@ +/* -*- Mode: C ; c-basic-offset: 2 -*- */ +/* + * LADI Session Handler (ladish) + * + * Copyright (C) 2009 Nedko Arnaudov + * + ************************************************************************** + * This file contains the code that implements ask dialog + ************************************************************************** + * + * LADI Session Handler is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * LADI Session Handler is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with LADI Session Handler. If not, see + * or write to the Free Software Foundation, Inc., + * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#include +#include "ask_dialog.h" +#include "glade.h" + +bool +ask_dialog( + bool * result_ptr, /* true - yes, false - no */ + const char * text, + const char * secondary_text_format, + ...) +{ + GtkResponseType response; + GtkWidget * dialog; + gchar * msg; + va_list ap; + + dialog = get_glade_widget("ask_dialog"); + + va_start(ap, secondary_text_format); + msg = g_markup_vprintf_escaped(secondary_text_format, ap); + va_end(ap); + if (msg == NULL) + { + lash_error("g_markup_vprintf_escaped() failed."); + return false; + } + gtk_message_dialog_format_secondary_markup(GTK_MESSAGE_DIALOG(dialog), "%s", msg); + g_free(msg); + + gtk_message_dialog_set_markup(GTK_MESSAGE_DIALOG(dialog), text); + gtk_widget_show(dialog); + response = gtk_dialog_run(GTK_DIALOG(dialog)); + gtk_widget_hide(dialog); + switch (response) + { + case GTK_RESPONSE_YES: + *result_ptr = true; + return true; + case GTK_RESPONSE_NO: + *result_ptr = false; + return true; + default: /* ignore warning */ + break; + } + + return false; +} diff --git a/gui/ask_dialog.h b/gui/ask_dialog.h new file mode 100644 index 00000000..9a4ecb4a --- /dev/null +++ b/gui/ask_dialog.h @@ -0,0 +1,39 @@ +/* -*- Mode: C ; c-basic-offset: 2 -*- */ +/* + * LADI Session Handler (ladish) + * + * Copyright (C) 2009 Nedko Arnaudov + * + ************************************************************************** + * This file contains the interface of ask dialog + ************************************************************************** + * + * LADI Session Handler is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * LADI Session Handler is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with LADI Session Handler. If not, see + * or write to the Free Software Foundation, Inc., + * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#ifndef ASK_DIALOG_H__67D26AF3_8FEA_44E4_B7CA_744898EF85D2__INCLUDED +#define ASK_DIALOG_H__67D26AF3_8FEA_44E4_B7CA_744898EF85D2__INCLUDED + +#include "common.h" + +bool +ask_dialog( + bool * result_ptr, /* true - yes, false - no */ + const char * text, + const char * secondary_text_format, + ...); + +#endif /* #ifndef ASK_DIALOG_H__67D26AF3_8FEA_44E4_B7CA_744898EF85D2__INCLUDED */ diff --git a/gui/gui.glade b/gui/gui.glade index 1320bea5..23173d22 100644 --- a/gui/gui.glade +++ b/gui/gui.glade @@ -888,4 +888,34 @@ along with LADI Session Handler; if not, write to the Free Software Foundation, True GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK + + GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK + 5 + False + GTK_WIN_POS_CENTER_ON_PARENT + GDK_WINDOW_TYPE_HINT_DIALOG + True + main_win + False + GTK_MESSAGE_QUESTION + GTK_BUTTONS_YES_NO + + + True + GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK + 2 + + + True + GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK + GTK_BUTTONBOX_END + + + False + GTK_PACK_END + + + + + diff --git a/gui/main.c b/gui/main.c index 15676d0c..b9b547c9 100644 --- a/gui/main.c +++ b/gui/main.c @@ -40,6 +40,7 @@ #include "graph_view.h" #include "../catdup.h" #include "../studio_proxy.h" +#include "ask_dialog.h" GtkWidget * g_main_win; @@ -234,11 +235,16 @@ static void on_load_studio(GtkWidget * item) static void on_delete_studio(GtkWidget * item) { const char * studio_name; + bool result; studio_name = gtk_label_get_text(GTK_LABEL(gtk_bin_get_child(GTK_BIN(item)))); - lash_info("Delete studio \"%s\"", studio_name); - /* TODO: ask user for confirmation */ + if (!ask_dialog(&result, "Confirm studio delete", "Studio \"%s\" will be deleted. Are you sure?", studio_name) || !result) + { + return; + } + + lash_info("Delete studio \"%s\"", studio_name); if (!control_proxy_delete_studio(studio_name)) { diff --git a/wscript b/wscript index cbbd0ce7..81a71717 100644 --- a/wscript +++ b/wscript @@ -283,6 +283,7 @@ def build(bld): 'graph_canvas.c', 'glade.c', 'control_proxy.c', + 'ask_dialog.c', ]: gladish.source.append(os.path.join("gui", source))