gladish: Confirm studio delete dialog

This commit is contained in:
Nedko Arnaudov 2009-08-30 15:35:32 +03:00
parent 6d260826cc
commit 6e5f677942
5 changed files with 151 additions and 2 deletions

73
gui/ask_dialog.c Normal file
View File

@ -0,0 +1,73 @@
/* -*- Mode: C ; c-basic-offset: 2 -*- */
/*
* LADI Session Handler (ladish)
*
* Copyright (C) 2009 Nedko Arnaudov <nedko@arnaudov.name>
*
**************************************************************************
* 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 <http://www.gnu.org/licenses/>
* or write to the Free Software Foundation, Inc.,
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#include <stdarg.h>
#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;
}

39
gui/ask_dialog.h Normal file
View File

@ -0,0 +1,39 @@
/* -*- Mode: C ; c-basic-offset: 2 -*- */
/*
* LADI Session Handler (ladish)
*
* Copyright (C) 2009 Nedko Arnaudov <nedko@arnaudov.name>
*
**************************************************************************
* 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 <http://www.gnu.org/licenses/>
* 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 */

View File

@ -888,4 +888,34 @@ along with LADI Session Handler; if not, write to the Free Software Foundation,
<property name="visible">True</property>
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
</widget>
<widget class="GtkMessageDialog" id="ask_dialog">
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
<property name="border_width">5</property>
<property name="resizable">False</property>
<property name="window_position">GTK_WIN_POS_CENTER_ON_PARENT</property>
<property name="type_hint">GDK_WINDOW_TYPE_HINT_DIALOG</property>
<property name="skip_taskbar_hint">True</property>
<property name="transient_for">main_win</property>
<property name="has_separator">False</property>
<property name="message_type">GTK_MESSAGE_QUESTION</property>
<property name="buttons">GTK_BUTTONS_YES_NO</property>
<child internal-child="vbox">
<widget class="GtkVBox" id="dialog-vbox8">
<property name="visible">True</property>
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
<property name="spacing">2</property>
<child internal-child="action_area">
<widget class="GtkHButtonBox" id="dialog-action_area8">
<property name="visible">True</property>
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
<property name="layout_style">GTK_BUTTONBOX_END</property>
</widget>
<packing>
<property name="expand">False</property>
<property name="pack_type">GTK_PACK_END</property>
</packing>
</child>
</widget>
</child>
</widget>
</glade-interface>

View File

@ -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, "<b><big>Confirm studio delete</big></b>", "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))
{

View File

@ -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))