1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318
|
/*
*
* Copyright (c) International Business Machines Corp., 2001, 2002
*
* This program 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.
*
* This program 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 this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* Module: transfer.c
*/
#include <frontend.h>
#include <gtk/gtk.h>
#include "support.h"
#include "transfer.h"
#include "thing.h"
#include "readable.h"
#include "logging.h"
#include "help.h"
/*
*
* gchar* get_container_name (object_handle_t)
*
* Description:
* This routine returns a dynamically allocated
* string containing the name of the container
* corresponding to the handle given.
*
* Entry:
* handle - object handle
*
* Exit:
* Container name string which should be freed
* with g_free or NULL if the name could not be
* obtained.
*
*/
gchar* get_container_name (object_handle_t handle)
{
gchar *name=NULL;
if (handle)
{
gint rc;
handle_object_info_t *info;
rc = evms_get_info (handle, &info);
if (rc != SUCCESS)
{
log_error ("%s: evms_get_info() returned error %d.\n", __FUNCTION__, rc);
}
else
{
name = g_strdup (info->info.container.name);
evms_free (info);
}
}
return name;
}
/*
*
* void on_remove_thing_from_container_button_clicked (GtkButton *, gpointer)
*
* Description:
* This routine initiates removing a storage object from its
* consuming container.
*
* Entry:
* button - address of the GtkButton widget
* user_data - object handle
*
* Exit:
* See description.
*
*/
void on_remove_thing_from_container_button_clicked (GtkButton *button, gpointer user_data)
{
GtkCList *clist;
object_handle_t handle;
clist = GTK_CLIST (lookup_widget (GTK_WIDGET (button), "selection_window_clist"));
handle = GPOINTER_TO_UINT (get_single_select_current_row_data (clist));
if (handle != 0)
{
gint rc;
gchar *error_msg = _("An error was encountered attempting to remove the storage object.");
gchar *success_msg = _("The storage object was successfully removed.");
rc = evms_transfer (handle, 0, 0, NULL);
display_selection_window_results (GTK_WIDGET (button), rc, error_msg, success_msg);
}
}
/*
*
* void on_remove_thing_from_container_menu_item_activate (GtkMenuItem *, gpointer)
*
* Description:
* This routine will display the thing we intend to remove from
* a certain container and allow the user to confirm the removal
* operation.
*
* Entry:
* menuitem - the menuitem that initiated the action
* user_data - object handle
*
* Exit:
* See description.
*
*/
void on_remove_thing_from_container_menu_item_activate (GtkMenuItem *menuitem, gpointer user_data)
{
gint rc;
object_handle_t handle = GPOINTER_TO_UINT (user_data);
handle_object_info_t *info;
rc = evms_get_info (handle, &info);
if (rc != SUCCESS)
{
log_error ("%s: evms_get_info() returned error %d.\n", __FUNCTION__, rc);
}
else
{
gchar *window_title;
gchar *help_text;
gchar *container_name;
GtkWidget *window;
object_type_t type;
container_name = get_container_name (info->info.object.consuming_container);
if (container_name)
{
window_title = g_strdup_printf (_("Remove %s from %s"),
info->info.object.name,
container_name);
g_free (container_name);
}
else
window_title = g_strdup_printf (_("Remove %s from unknown container"),
info->info.object.name);
if (evms_get_handle_object_type (handle, &type) == SUCCESS)
{
switch (type)
{
case REGION:
help_text = remove_region_from_container_help_text;
break;
case SEGMENT:
help_text = remove_segment_from_container_help_text;
break;
case DISK:
help_text = remove_disk_from_container_help_text;
break;
default:
help_text = NULL;
break;
}
}
else
{
help_text = NULL;
}
window = create_standard_selection_window (window_title,
_("Remove"),
help_text,
add_thing_as_selected_list_item,
on_remove_thing_from_container_button_clicked,
NULL, NULL, NULL, NULL, user_data);
gtk_widget_show (window);
evms_free (info);
g_free (window_title);
}
}
/*
*
* void add_consumed_object_to_selection_list (GtkCList *, object_handle_t, gboolean)
*
* Description:
* This routine appends a row to a GtkCList with information
* on the given object consumed by a container.
*
* Entry:
* clist - address of the selections GtkCList widget
* object - the handle to the consumed object
* is_selected - whether to mark this item as selected
*
* Exit:
* A new row corresponding to the consumed object is added to the
* clist.
*
*/
void add_consumed_object_to_selection_list (GtkCList *clist, object_handle_t object, gboolean is_selected)
{
gint row;
row = add_thing_to_selection_list (clist, object, is_selected);
if (row != -1)
{
gint rc;
handle_object_info_t *info;
rc = evms_get_info (object, &info);
if (rc != SUCCESS)
{
log_error ("%s: evms_get_info() returned error %d.\n", __FUNCTION__, rc);
}
else
{
gchar *container_name;
container_name = get_container_name (info->info.object.consuming_container);
gtk_clist_set_text (clist, row, SL_MINMAX_SIZE_COLUMN, container_name);
g_free (container_name);
evms_free (info);
}
}
}
/*
*
* void on_remove_thing_from_container_clist_realize (GtkWidget *, object_type_t)
*
* Description:
* This routine populates the given GtkCList with the list
* of storage objects that can be removed from their consuming
* container.
*
* Entry:
* widget - address of the selections GtkCList widget
* type - type of the container consumables to list
*
* Exit:
* Selection list populated with things in the handle array that can
* removed from their corresponding container
*
*/
void on_remove_thing_from_container_clist_realize (GtkWidget *widget, object_type_t type)
{
gint rc=0;
GtkCList *clist = GTK_CLIST (widget);
handle_array_t *things;
/*
* Use the normally hidden min/max size column for the name of the consuming
* container.
*/
gtk_clist_set_column_visibility (clist, SL_MINMAX_SIZE_COLUMN, TRUE);
gtk_clist_set_column_auto_resize (clist, SL_MINMAX_SIZE_COLUMN, TRUE);
set_selection_window_clist_column_titles (clist, _("Size"),
make_object_type_readable_string (type),
_("Consuming Container"));
switch (type)
{
case REGION:
case SEGMENT:
case DISK:
rc = evms_get_object_list (type, DATA_TYPE, 0, 0, &things);
break;
default:
log_error ("%s: Unsupported selection type %d.\n", __FUNCTION__, type);
rc = EINVAL;
break;
}
if (rc != SUCCESS)
{
log_error ("%s: evms_get_object_list() returned error code %d.\n", __FUNCTION__, rc);
}
else
{
guint i;
gboolean is_selected = (things->count == 1);
for (i=0; i < things->count; i++)
{
if (evms_can_remove_from_container (things->handle[i]) == 0)
add_consumed_object_to_selection_list (clist, things->handle[i], is_selected);
}
if (clist->rows == 1)
gtk_clist_select_row (clist, 0, 0);
evms_free (things);
}
}
|