Add fallback implementation to new delete LVM2 PV warning dialog (#670171)

The new delete non-empty LVM2 Physical Volume warning dialog uses
Gtk::MessageDialog::get_message_area() in the display of Volume Group
members.  This function was new in gtkmm 2.22, released September 2010,
which is not available in a number of current distributions including:
Unbuntu 10.04 LTS, RHEL 6.3, SLES 11-SP2, Debian 6.0.

Implement fallback method to display the VG name and member PVs in the
warning dialog for when get_message_area() is not available.

Bug #670171 - Add LVM PV read-write support
This commit is contained in:
Mike Fleetwood 2012-07-24 13:49:44 +01:00 committed by Curtis Gedak
parent 69c8acce75
commit 590f1377f9
2 changed files with 48 additions and 11 deletions

View File

@ -258,6 +258,12 @@ PKG_CHECK_EXISTS([gtkmm-2.4 >= 2.16.0],
[]) [])
dnl Check for gtkmm >= 2.22 to determine availability of Gtk::MessageDialog::get_message_area().
PKG_CHECK_EXISTS([gtkmm-2.4 >= 2.22.0],
[AC_DEFINE([HAVE_GET_MESSAGE_AREA], 1, [Define if gtkmm provides Gtk::MessageDialog::get_message_area() function.])],
[])
dnl====================== dnl======================
dnl check whether to build documentation - Gnome-Doc-Utils dnl check whether to build documentation - Gnome-Doc-Utils
dnl====================== dnl======================

View File

@ -2708,10 +2708,46 @@ bool Win_GParted::remove_non_empty_lvm2_pv_dialog( const OperationType optype )
"LVM commands to free the Physical Volume before attempting this operation." ) ; "LVM commands to free the Physical Volume before attempting this operation." ) ;
tmp_msg += "\n\n" ; tmp_msg += "\n\n" ;
tmp_msg += _( "Do you want to continue to forcibly delete the Physical Volume?" ) ; tmp_msg += _( "Do you want to continue to forcibly delete the Physical Volume?" ) ;
dialog .set_secondary_text( tmp_msg ) ;
//WARNING: Uses Gtk::MessageDialog::get_message_area() which was new in LVM2_PV_Info lvm2_pv_info ;
// gtkmm-2.22 released September 2010. Not all distributions will have it. Glib::ustring vgname = lvm2_pv_info .get_vg_name( selected_partition .get_path() ) ;
std::vector<Glib::ustring> members ;
if ( ! vgname .empty() )
members = lvm2_pv_info .get_vg_members( vgname ) ;
//Single copy of each string for translation purposes
const Glib::ustring vgname_label = _( "Volume Group:" ) ;
const Glib::ustring members_label = _( "Members:" ) ;
#ifndef HAVE_GET_MESSAGE_AREA
//Basic method of displaying VG members by appending it to the secondary text in the dialog.
tmp_msg += "\n____________________\n\n" ;
tmp_msg += "<b>" ;
tmp_msg += vgname_label ;
tmp_msg += "</b> " ;
tmp_msg += vgname ;
tmp_msg += "\n" ;
tmp_msg += "<b>" ;
tmp_msg += members_label ;
tmp_msg += "</b>" ;
if ( ! members .empty() )
{
tmp_msg += " " ;
tmp_msg += members [0] ;
for ( unsigned int i = 1 ; i < members .size() ; i ++ )
{
tmp_msg += " " ;
tmp_msg += members [i] ;
}
}
#endif /* ! HAVE_GET_MESSAGE_AREA */
dialog .set_secondary_text( tmp_msg, true ) ;
#ifdef HAVE_GET_MESSAGE_AREA
//Nicely formatted method of displaying VG members by using a table below the secondary text
// in the dialog. Uses Gtk::MessageDialog::get_message_area() which was new in gtkmm-2.22
// released September 2010.
Gtk::Box * msg_area = dialog .get_message_area() ; Gtk::Box * msg_area = dialog .get_message_area() ;
Gtk::HSeparator * hsep( manage( new Gtk::HSeparator() ) ) ; Gtk::HSeparator * hsep( manage( new Gtk::HSeparator() ) ) ;
@ -2723,23 +2759,17 @@ bool Win_GParted::remove_non_empty_lvm2_pv_dialog( const OperationType optype )
msg_area ->pack_start( * table ) ; msg_area ->pack_start( * table ) ;
int top = 0, bottom = 1 ; int top = 0, bottom = 1 ;
LVM2_PV_Info lvm2_pv_info ;
Glib::ustring vgname = lvm2_pv_info .get_vg_name( selected_partition .get_path() ) ;
//Volume Group //Volume Group
table ->attach( * Utils::mk_label( "<b>" + Glib::ustring( _( "Volume Group:" ) ) + "</b>" ), table ->attach( * Utils::mk_label( "<b>" + Glib::ustring( vgname_label ) + "</b>" ),
0, 1, top, bottom, Gtk::FILL ) ; 0, 1, top, bottom, Gtk::FILL ) ;
table ->attach( * Utils::mk_label( vgname, true, Gtk::ALIGN_LEFT, Gtk::ALIGN_CENTER, false, true ), table ->attach( * Utils::mk_label( vgname, true, Gtk::ALIGN_LEFT, Gtk::ALIGN_CENTER, false, true ),
1, 2, top++, bottom++, Gtk::FILL ) ; 1, 2, top++, bottom++, Gtk::FILL ) ;
//Members //Members
table ->attach( * Utils::mk_label( "<b>" + Glib::ustring( _("Members:") ) + "</b>"), table ->attach( * Utils::mk_label( "<b>" + Glib::ustring( members_label ) + "</b>"),
0, 1, top, bottom, Gtk::FILL ) ; 0, 1, top, bottom, Gtk::FILL ) ;
std::vector<Glib::ustring> members ;
if ( ! vgname .empty() )
members = lvm2_pv_info .get_vg_members( vgname ) ;
if ( members .empty() ) if ( members .empty() )
table ->attach( * Utils::mk_label( "" ), 1, 2, top++, bottom++, Gtk::FILL ) ; table ->attach( * Utils::mk_label( "" ), 1, 2, top++, bottom++, Gtk::FILL ) ;
else else
@ -2754,6 +2784,7 @@ bool Win_GParted::remove_non_empty_lvm2_pv_dialog( const OperationType optype )
} }
} }
#endif /* HAVE_GET_MESSAGE_AREA */
dialog .add_button( Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL ); dialog .add_button( Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL );
dialog .add_button( Gtk::Stock::DELETE, Gtk::RESPONSE_OK ); dialog .add_button( Gtk::Stock::DELETE, Gtk::RESPONSE_OK );