File: thing.c

package info (click to toggle)
evms 1.0.0-3
  • links: PTS
  • area: main
  • in suites: woody
  • size: 9,168 kB
  • ctags: 5,853
  • sloc: ansic: 87,317; makefile: 691; sh: 238
file content (395 lines) | stat: -rw-r--r-- 13,148 bytes parent folder | download
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
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
/*
 *
 *   Copyright (c) International Business Machines  Corp., 2001
 *
 *   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: thing.c
 */
 
#include <frontend.h>
#include <gtk/gtk.h>

#include "support.h"
#include "pixmap.h"
#include "widget.h"
#include "readable.h"
#include "thing.h"
#include "logging.h"

/*
 *
 *   void add_thing_to_selection_list (GtkCList *, object_handle_t, gboolean)
 *   
 *   Description:
 *      This routine appends a row to the standard selection window
 *      GtkCList with the information from the given object handle.
 *      It optionally can mark the appended entry as selected.
 * 
 *   Entry:
 *      widget        - address of the selection window GtkCList widget
 *      handle        - handle of object to place in selection window
 *      mark_selected - TRUE if row added should be selected
 *
 *   Exit:
 *      A new row is appended to the standard selection window list and the
 *      row index is returned. Otherwise, -1 is returned for any error.
 *
 */
gint add_thing_to_selection_list (GtkCList *clist, object_handle_t handle, gboolean mark_selected)
{
    gint                  rc;
    gint                  row=-1;
    gchar                *text[]={"","","",""};  
    handle_object_info_t *object;

    rc = evms_get_info (handle, &object);
            
    if (rc != SUCCESS)
    {
        log_error ("%s: evms_get_info() returned error %d.\n", __FUNCTION__, rc);
    }
    else
    {
        switch (object->type)
        {
            case VOLUME:
                text[SL_SIZE_COLUMN] = make_sectors_readable_string (object->info.volume.vol_size);
                text[SL_DESC_COLUMN] = object->info.volume.name;
                break;

            case EVMS_OBJECT:
            case REGION:
            case SEGMENT:
            case DISK:
                text[SL_SIZE_COLUMN] = make_sectors_readable_string (object->info.object.size);
                text[SL_DESC_COLUMN] = object->info.object.name;
                break;

            case CONTAINER:
                text[SL_SIZE_COLUMN] = make_sectors_readable_string (object->info.container.size);
                text[SL_DESC_COLUMN] = object->info.container.name;
                break;

            case PLUGIN:
                text[SL_SIZE_COLUMN] = g_strdup (object->info.plugin.long_name);
                break;

            default:
                log_debug ("%s: Unknown type %d.\n", __FUNCTION__, object->type);
                break;
        }
        
        row = gtk_clist_append (clist, text);

        if (mark_selected)
            gtk_clist_select_row (clist, row, 0);

        g_free (text[SL_SIZE_COLUMN]);

        /*
         * Associate things's handle with row data so that we can
         * use it when we invoke an operation based on the currently 
         * selected row.
         */

        if (row != -1) 
        {
            set_clist_row_pixmap (clist, row, object->type);   
            gtk_clist_set_row_data (clist, row, GUINT_TO_POINTER (handle));
        }

        evms_free (object);
    }
    
    return row;
}

/*
 * The following two routines are basically getter/setter functions
 * to allow binding and retrieving an object handle from a toplevel
 * widget.
 */

inline void bind_object_handle_to_toplevel_widget (GtkWidget *widget, object_handle_t object)
{
    GtkWidget *toplevel = gtk_widget_get_toplevel (widget);

    gtk_object_set_data (GTK_OBJECT (toplevel), "object_handle", GUINT_TO_POINTER (object));
}

inline object_handle_t retrieve_object_handle_from_toplevel_widget (GtkWidget *widget)
{
    GtkWidget *toplevel = gtk_widget_get_toplevel (widget);

    return GPOINTER_TO_UINT (gtk_object_get_data (GTK_OBJECT (toplevel), "object_handle"));
}

/*
 *
 *   void add_thing_as_selected_list_item (GtkCList *, gpointer)
 *   
 *   Description:
 *      This routine populates the standard selection window GtkCList
 *      with the information from one object handle. It also selects
 *      this single entry in the list so that the "Next" button is
 *      made active to complete an operation on the row.
 * 
 *   Entry:
 *      widget    - address of the selection window GtkCList widget
 *      user_data - contains handle of object to place in selection window
 *
 *   Exit:
 *      Returns nothing.
 *
 */
void add_thing_as_selected_list_item (GtkCList *clist, gpointer user_data)
{
    object_type_t   type;
    object_handle_t handle = GPOINTER_TO_UINT (user_data);
    
    if (evms_get_handle_object_type (handle, &type) == SUCCESS)
        set_selection_window_clist_column_titles (clist, _("Size"), 
                                                  make_object_type_readable_string (type),
                                                  NULL);
    
    add_thing_to_selection_list (clist, handle, TRUE);
}

/*
 *
 *   GtkWidget* create_thing_details_window (extended_info_array_t *)
 *   
 *   Description:
 *      This routine creates a window with a close button and a notebook
 *      widget that contains plugin specific information. Each extended
 *      info structure is convereted to a widget that represents the data
 *      and the widgets are placed in a widget notebook which is placed
 *      in the window.
 * 
 *   Entry:
 *      handle        - the handle for the thing so we can get additional info
 *      extended_info - address of structure containing array of extended_info_t
 *                      structures
 *      field_title    - title of field that was drilled into or NULL if toplevel
 *
 *   Exit:
 *      The address of the window containing the extended info widget notebook
 *      is returned.
 *
 */
GtkWidget* create_thing_details_window (object_handle_t handle, extended_info_array_t *extended_info, gchar *field_title)
{
    gint       i;
    gchar     *frame_title;
    gchar     *window_title;
    gchar     *thing_name;
    gchar     *plugin_name;
    gchar     *field_drilled=NULL;
    GSList    *widgets=NULL;
    GtkWidget *vbox;
    GtkWidget *hbox;
    GtkWidget *frame;
    GtkWidget *window;
    GtkWidget *widget;
    GtkWidget *button;
    GtkWidget *hbuttonbox;
    GtkWidget *hseparator;
    GtkWidget *widget_notebook;
    GtkWidget *pixmap;
    GdkBitmap *mask;
    GdkPixmap *gdk_pixmap;            
    
    get_dialog_pixmap (INFO_PIXMAP, &gdk_pixmap, &mask);

    get_object_and_plugin_names (handle, &thing_name, &plugin_name);

    if (field_title) field_drilled = g_strconcat ((" - "), field_title, NULL);

    frame_title  = g_strconcat (thing_name, " (", plugin_name, ")", field_drilled, NULL);
    window_title = g_strconcat (_("Detailed Information"), " - ", thing_name, NULL);

    window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
    gtk_window_set_default_size (GTK_WINDOW (window), 550, -1);

    vbox       = gtk_vbox_new (FALSE, 0);
    hbox       = gtk_hbox_new (FALSE, 5);        
    frame      = gtk_frame_new (frame_title);
    hbuttonbox = gtk_hbutton_box_new ();
    hseparator = gtk_hseparator_new ();
    button     = gtk_button_new_with_label (_("OK"));
    pixmap     = gtk_pixmap_new (gdk_pixmap, mask);

    for (i=0; i < extended_info->count; i++)
    {
        widget = create_widget_from_extended_info (&(extended_info->info[i]));

        if (widget != NULL)
            widgets = g_slist_append (widgets, widget);
    }

    widget_notebook = create_widget_notebook (widgets, NULL, 7, 0);
    
    gtk_box_pack_start (GTK_BOX (hbox), pixmap, FALSE, FALSE, 0);
    gtk_misc_set_alignment (GTK_MISC (pixmap), 0.05, 0.05);
        
    gtk_box_pack_start (GTK_BOX (hbox), frame, TRUE, TRUE, 0);
    gtk_container_set_border_width (GTK_CONTAINER (hbox), 2);
    
    gtk_box_pack_start (GTK_BOX (vbox), hbox, TRUE, TRUE, 0);
    gtk_box_pack_start (GTK_BOX (vbox), hseparator, FALSE, FALSE, 12);
    gtk_box_pack_start (GTK_BOX (vbox), hbuttonbox, FALSE, FALSE, 0);

    gtk_window_set_title (GTK_WINDOW (window), window_title);
    gtk_container_set_border_width (GTK_CONTAINER (vbox), 5);
    gtk_container_set_border_width (GTK_CONTAINER (hbuttonbox), 5);
    gtk_container_set_border_width (GTK_CONTAINER (frame), 6);
    gtk_container_set_border_width (GTK_CONTAINER (widget_notebook), 5);
    gtk_button_box_set_layout (GTK_BUTTON_BOX (hbuttonbox), GTK_BUTTONBOX_END);
    gtk_button_box_set_child_size (GTK_BUTTON_BOX (hbuttonbox), -1, 44);
    gtk_button_box_set_child_ipadding (GTK_BUTTON_BOX (hbuttonbox), 19, 0);

    gtk_container_add (GTK_CONTAINER (hbuttonbox), button);
    gtk_container_add (GTK_CONTAINER (frame), widget_notebook);
    gtk_container_add (GTK_CONTAINER (window), vbox);

    gtk_widget_show (widget_notebook);
    gtk_widget_show (button);
    gtk_widget_show (hbuttonbox);
    gtk_widget_show (hseparator);
    gtk_widget_show (vbox);
    gtk_widget_show (frame);
    gtk_widget_show (pixmap);
    gtk_widget_show (hbox);
    
    gtk_signal_connect_object (GTK_OBJECT (button), "clicked", gtk_widget_destroy, GTK_OBJECT (window));
    GTK_WIDGET_SET_FLAGS (button, GTK_CAN_DEFAULT);

    gtk_widget_grab_default (button);

    g_free (thing_name);
    g_free (plugin_name);
    g_free (frame_title);
    g_free (window_title);
    g_free (field_drilled);

    g_slist_free (widgets);

    return window;
}

/*
 *
 *   void display_thing_details (object_handle_t, gchar *, gchar *)
 *   
 *   Description:
 *      This routine displays the plugin specific information on a thing.
 * 
 *   Entry:
 *      handle      - the handle of the thing to get extended info for
 *      field_name  - an optional field name to gather specific info on
 *      field_title - the title/description of the optional field name     
 *
 *   Exit:
 *      Returns nothing.
 *
 */
void display_thing_details (object_handle_t handle, gchar *field_name, gchar *field_title)
{
    gint                   rc;
    extended_info_array_t *extended_info=NULL;
    
    rc = evms_get_extended_info (handle, field_name, &extended_info);

    if (rc != SUCCESS)
    {
        log_error ("%s: evms_get_extended_info() returned error code %d.\n", __FUNCTION__, rc);
    	display_popup_window (_("View Detailed Information"), _("No detailed information is available."));
    }
    else if (extended_info != NULL && extended_info->count > 0)
    {
        GtkWidget *window;
        
        window = create_thing_details_window (handle, extended_info, field_title);
        bind_object_handle_to_toplevel_widget (window, handle);
        gtk_widget_show (window);

        evms_free (extended_info);
    }
    else
    {
    	display_popup_window (_("View Detailed Information"), _("No detailed information is available."));
    	evms_free (extended_info);
    }
}

/*
 *
 *   void on_display_thing_details_menu_item_activate (GtkMenuItem *, gpointer)
 *   
 *   Description:
 *      This routine displays the plugin specific information on the thing
 *      selected in one of the browser views. The information is retrieved
 *      through the evms_get_extended_info() API.
 * 
 *   Entry:
 *      menuitem  - menu item selected
 *      user_data - contains handle of the object we want extended info on
 *
 *   Exit:
 *      Returns nothing.
 *
 */
void on_display_thing_details_menu_item_activate (GtkMenuItem *menuitem, gpointer user_data)
{
    display_thing_details (GPOINTER_TO_UINT (user_data), NULL, NULL);
}

/*
 *
 *   void on_display_more_thing_details_button_clicked (GtkButton *, field_details *)
 *   
 *   Description:
 *      This routine displays the plugin specific information on the field
 *      for a thing if the field had the EVMS_EINFO_FLAGS_MORE_INFO_AVAILABLE
 *      flag set.
 * 
 *   Entry:
 *      button - id of the button clicked
 *      field  - contains reference info of the specific field
 *
 *   Exit:
 *      Returns nothing.
 *
 */
void on_display_more_thing_details_button_clicked (GtkButton *button, field_details_t *field)
{
    gchar *name=NULL;
    
    object_handle_t handle=retrieve_object_handle_from_toplevel_widget (GTK_WIDGET (button));

    /*
     * Assign field->name to name if non-NULL and non-empty string.
     *
     * An empty field name equates to retrieving full info for the
     * object. This empty string trick is used by the 
     * create_volume_pseudo_extended_info() routine to allow getting
     * toplevel extended info from an FSIM for a volume.
     */
    if (field->name && *(field->name) != '\0')
        name = field->name;
    
    display_thing_details (handle, field->name, field->title);
}