~ubuntu-branches/ubuntu/edgy/gnome-system-tools/edgy-proposed

« back to all changes in this revision

Viewing changes to src/disks/callbacks.c

  • Committer: Bazaar Package Importer
  • Author(s): Martin Pitt
  • Date: 2004-10-14 18:49:22 UTC
  • Revision ID: james.westby@ubuntu.com-20041014184922-efvh7u8kpyy67a3z
Tags: upstream-1.0.0
ImportĀ upstreamĀ versionĀ 1.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* callbacks.c: this file is part of disks-admin, a gnome-system-tool frontend 
 
2
 * for disks administration.
 
3
 * 
 
4
 * Copyright (C) 2001 Ximian, Inc.
 
5
 *
 
6
 * This program is free software; you can redistribute it and/or modify
 
7
 * it under the terms of the GNU General Public License as
 
8
 * published by the Free Software Foundation; either version 2 of the
 
9
 * License, or (at your option) any later version.
 
10
 *
 
11
 * This program is distributed in the hope that it will be useful,
 
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
14
 * GNU General Public License for more details.
 
15
 *
 
16
 * You should have received a copy of the GNU General Public License
 
17
 * along with this program; if not, write to the Free Software
 
18
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
 
19
 *
 
20
 * Authors: Alvaro Peļæ½a Gonzalez <apg@esware.com>
 
21
 *          Carlos Garcia Campos <elkalmail@yahoo.es>
 
22
 */
 
23
 
 
24
#ifdef HAVE_CONFIG_H
 
25
#  include <config.h>
 
26
#endif
 
27
 
 
28
#include <gnome.h>
 
29
#include "gst.h"
 
30
 
 
31
#include "disks-storage.h"
 
32
#include "disks-storage-disk.h"
 
33
#include "disks-storage-cdrom.h"
 
34
#include "disks-cdrom-disc.h"
 
35
#include "disks-cdrom-disc-data.h"
 
36
#include "disks-cdrom-disc-audio.h"
 
37
#include "disks-mountable.h"
 
38
#include "disks-partition.h"
 
39
#include "disks-gui.h"
 
40
#include "callbacks.h"
 
41
 
 
42
extern GstTool *tool;
 
43
 
 
44
enum {
 
45
        TAB_PROPERTIES,
 
46
        TAB_PARTITIONS,
 
47
        TAB_CDROM_DISC
 
48
};
 
49
 
 
50
enum {
 
51
        TAB_PROP_DISK,
 
52
        TAB_PROP_CDROM
 
53
};
 
54
 
 
55
void
 
56
gst_on_storage_list_selection_change (GtkTreeSelection *selection, gpointer gdata)
 
57
{
 
58
        GtkWidget        *notebook;
 
59
        GtkTreeModel     *model;
 
60
        GtkTreeIter       iter;
 
61
        GtkTreeSelection *selec;
 
62
        GstDisksStorage  *storage;
 
63
        GtkWidget        *treeview;
 
64
        GtkWidget        *storage_list;
 
65
        GtkWidget        *main_window;
 
66
        GList            *partitions;
 
67
        gboolean          cd_empty;
 
68
        GstCdromDisc     *disc;
 
69
        GtkWidget        *properties_notebook;
 
70
        GdkCursor *cursor;
 
71
 
 
72
        /* Avoid cycle */
 
73
        g_signal_handlers_block_by_func (G_OBJECT (selection),
 
74
                                         G_CALLBACK (gst_on_storage_list_selection_change),
 
75
                                         NULL);
 
76
        
 
77
        notebook = gst_dialog_get_widget (tool->main_dialog, "main_notebook");
 
78
        storage_list = gst_dialog_get_widget (tool->main_dialog, "storage_list");
 
79
        main_window = gst_dialog_get_widget (tool->main_dialog, "disks_admin");
 
80
        
 
81
        if (gtk_tree_selection_get_selected (GTK_TREE_SELECTION (selection), &model, &iter)) {
 
82
                gtk_tree_model_get (model, &iter, STORAGE_LIST_POINTER, &storage, -1);
 
83
 
 
84
                if (GST_IS_DISKS_STORAGE (storage)) {
 
85
                        /* Properties Notebook */
 
86
                        properties_notebook = gst_dialog_get_widget (tool->main_dialog,
 
87
                                                                                                "properties_notebook");
 
88
                        if (GST_IS_DISKS_STORAGE_DISK (storage)) {
 
89
                                gtk_widget_show (properties_notebook);
 
90
                                gtk_notebook_set_current_page (GTK_NOTEBOOK (properties_notebook),
 
91
                                                                                 TAB_PROP_DISK);
 
92
 
 
93
                                cursor = gdk_cursor_new (GDK_WATCH);
 
94
                                if (!GTK_WIDGET_REALIZED (main_window))
 
95
                                           gtk_widget_realize (GTK_WIDGET (main_window));
 
96
                                gdk_window_set_cursor (main_window->window, cursor);
 
97
                                gtk_widget_set_sensitive (storage_list, FALSE);
 
98
                                
 
99
                                gst_disks_storage_setup_properties_widget (storage);
 
100
 
 
101
                                gtk_widget_set_sensitive (storage_list, TRUE);
 
102
                                gdk_cursor_destroy (cursor);
 
103
                                gdk_window_set_cursor (main_window->window, NULL);
 
104
                                
 
105
 
 
106
                                g_object_get (G_OBJECT (storage), "partitions", &partitions, NULL);
 
107
 
 
108
                                treeview = gst_dialog_get_widget (tool->main_dialog, "partition_list");
 
109
                                model = gtk_tree_view_get_model (GTK_TREE_VIEW (treeview));
 
110
                                
 
111
                                if (partitions) {
 
112
                                        gst_disks_gui_setup_partition_list (treeview, partitions);
 
113
 
 
114
                                        selec = gtk_tree_view_get_selection (GTK_TREE_VIEW (treeview));
 
115
                                        gtk_tree_model_get_iter_first (model, &iter);
 
116
                                        gtk_tree_selection_select_iter (selec, &iter);
 
117
                                } else {
 
118
                                        gtk_tree_store_clear (GTK_TREE_STORE (model));
 
119
                                        gst_on_partition_list_selection_change (
 
120
                                                gtk_tree_view_get_selection (
 
121
                                                        GTK_TREE_VIEW (treeview)),
 
122
                                                NULL);
 
123
                                }
 
124
 
 
125
                                gtk_widget_hide (gtk_notebook_get_nth_page (
 
126
                                                         GTK_NOTEBOOK (notebook), TAB_CDROM_DISC));
 
127
                                gtk_widget_show_all (gtk_notebook_get_nth_page (
 
128
                                                             GTK_NOTEBOOK (notebook), TAB_PARTITIONS));
 
129
                                
 
130
                        } else if (GST_IS_DISKS_STORAGE_CDROM (storage)) {
 
131
                                gtk_widget_show (properties_notebook);
 
132
                                gtk_notebook_set_current_page (GTK_NOTEBOOK (properties_notebook),
 
133
                                                               TAB_PROP_CDROM);
 
134
 
 
135
                                cursor = gdk_cursor_new (GDK_WATCH);
 
136
                                if (!GTK_WIDGET_REALIZED (main_window))
 
137
                                           gtk_widget_realize (GTK_WIDGET (main_window));
 
138
                                gdk_window_set_cursor (main_window->window, cursor);
 
139
                                gtk_widget_set_sensitive (storage_list, FALSE);
 
140
 
 
141
                                gst_disks_storage_setup_properties_widget (storage);
 
142
 
 
143
                                gtk_widget_set_sensitive (storage_list, TRUE);
 
144
                                gdk_cursor_destroy (cursor);
 
145
                                gdk_window_set_cursor (main_window->window, NULL);
 
146
 
 
147
                                g_object_get (G_OBJECT (storage), "empty", &cd_empty,
 
148
                                                    "disc", &disc, NULL);
 
149
 
 
150
                                if (!cd_empty) {
 
151
                                        gtk_widget_show (gtk_notebook_get_nth_page (
 
152
                                                                 GTK_NOTEBOOK (notebook),
 
153
                                                                 TAB_CDROM_DISC));
 
154
                                } else {
 
155
                                        gtk_widget_hide (gtk_notebook_get_nth_page (
 
156
                                                                 GTK_NOTEBOOK (notebook),
 
157
                                                                 TAB_CDROM_DISC));
 
158
                                }
 
159
                                
 
160
                                gtk_widget_hide (gtk_notebook_get_nth_page (
 
161
                                                         GTK_NOTEBOOK (notebook), TAB_PARTITIONS));
 
162
                        } else {
 
163
                                gtk_widget_hide (gtk_notebook_get_nth_page (
 
164
                                                         GTK_NOTEBOOK (notebook), TAB_PARTITIONS));
 
165
                                gtk_widget_hide (gtk_notebook_get_nth_page (
 
166
                                                         GTK_NOTEBOOK (notebook), TAB_CDROM_DISC));
 
167
                                gtk_widget_hide (properties_notebook);
 
168
                        }
 
169
                }
 
170
        }
 
171
 
 
172
        /* Avoid cycle */
 
173
        g_signal_handlers_unblock_by_func (G_OBJECT (selection),
 
174
                                           G_CALLBACK (gst_on_storage_list_selection_change),
 
175
                                           NULL);
 
176
}
 
177
 
 
178
gboolean
 
179
gst_on_storage_list_button_press (GtkTreeView *treeview, GdkEventButton *event, gpointer gdata)
 
180
{
 
181
           GtkTreeSelection *selection;
 
182
 
 
183
           if (event->type == GDK_2BUTTON_PRESS || event->type == GDK_3BUTTON_PRESS) {
 
184
                         selection = gtk_tree_view_get_selection (treeview);
 
185
                         gst_on_storage_list_selection_change (selection, NULL);
 
186
           }
 
187
 
 
188
           return FALSE;
 
189
}
 
190
 
 
191
void 
 
192
gst_on_partition_list_selection_change (GtkTreeSelection *selection, gpointer gdata)
 
193
{
 
194
        GtkTreeModel    *model;
 
195
        GtkTreeIter      iter;
 
196
        GstDisksPartition *part = NULL;
 
197
 
 
198
        if (gtk_tree_selection_get_selected (selection, &model, &iter)) {
 
199
                gtk_tree_model_get (model, &iter, PARTITION_LIST_POINTER, &part, -1);
 
200
                if (GST_IS_DISKS_PARTITION (part)) {
 
201
                        gst_disks_partition_setup_properties_widget (part);
 
202
                }
 
203
        } else {
 
204
                gst_disks_partition_setup_properties_widget (part); /* part == NULL */
 
205
        }
 
206
}
 
207
 
 
208
void
 
209
gst_on_point_entry_changed (GtkWidget *entry, gpointer gdata)
 
210
{
 
211
        GtkWidget            *treeview;
 
212
        GtkTreeModel         *model;
 
213
        GtkTreeIter           iter;
 
214
        GtkTreeSelection     *selection;
 
215
        GstDisksPartition    *part;
 
216
        GstDisksStorageCdrom *cdrom;
 
217
        GstCdromDisc         *disc;
 
218
        GstCdromDiscData     *disc_data;
 
219
        const gchar *point;
 
220
 
 
221
        treeview = (GtkWidget *) gdata;
 
222
 
 
223
        point = gtk_entry_get_text (GTK_ENTRY (entry));
 
224
 
 
225
        if (point == NULL || strlen (point) <= 0)
 
226
                return;
 
227
 
 
228
        selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (treeview));
 
229
        if (gtk_tree_selection_get_selected (selection, &model, &iter)) {
 
230
                if (gtk_tree_model_get_n_columns (model) == PARTITION_LIST_LAST) {
 
231
                        gtk_tree_model_get (model, &iter, PARTITION_LIST_POINTER, &part, -1);
 
232
                        if (GST_IS_DISKS_PARTITION (part)) {
 
233
                                g_object_set (G_OBJECT (part), "point", point, NULL);
 
234
                        }
 
235
                } else if (gtk_tree_model_get_n_columns (model) == STORAGE_LIST_LAST) {
 
236
                        gtk_tree_model_get (model, &iter, STORAGE_LIST_POINTER, &cdrom, -1);
 
237
                        if (GST_IS_DISKS_STORAGE_CDROM (cdrom)) {
 
238
                                g_object_get (G_OBJECT (cdrom), "disc", &disc, NULL);
 
239
                                if (GST_IS_CDROM_DISC_DATA (disc)) {
 
240
                                        g_object_set (G_OBJECT (disc), "mount-point",
 
241
                                                      point, NULL);
 
242
                                } else if (GST_IS_CDROM_DISC_MIXED (disc)) {
 
243
                                        g_object_get (G_OBJECT (disc), "data",
 
244
                                                      &disc_data, NULL);
 
245
                                        if (GST_IS_CDROM_DISC_DATA (disc_data))
 
246
                                                g_object_set (G_OBJECT (disc_data), "mount-point",
 
247
                                                              point, NULL);
 
248
                                }
 
249
                                        
 
250
                        }
 
251
                }
 
252
        }
 
253
}
 
254
 
 
255
void
 
256
gst_on_mount_button_clicked (GtkWidget *button, gpointer gdata)
 
257
{
 
258
        GtkWidget            *treeview;
 
259
        GtkTreeModel         *model;
 
260
        GtkTreeIter           iter;
 
261
        GtkTreeSelection     *selection;
 
262
        GstDisksPartition    *part;
 
263
        GstDisksStorageCdrom *cdrom;
 
264
        GstCdromDisc *disc;
 
265
 
 
266
        treeview = (GtkWidget *) gdata;
 
267
 
 
268
        selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (treeview));
 
269
        if (gtk_tree_selection_get_selected (selection, &model, &iter)) {
 
270
                if (gtk_tree_model_get_n_columns (model) == PARTITION_LIST_LAST) {
 
271
                        gtk_tree_model_get (model, &iter, PARTITION_LIST_POINTER, &part, -1);
 
272
 
 
273
                        if (GST_IS_DISKS_PARTITION (part)) {
 
274
                                /*gst_disks_partition_mount (part);*/
 
275
                                gst_disks_mountable_mount (GST_DISKS_MOUNTABLE (part));
 
276
                                
 
277
                                gst_disks_partition_setup_properties_widget (part);
 
278
                        }
 
279
                } else if (gtk_tree_model_get_n_columns (model) == STORAGE_LIST_LAST) {
 
280
                        gtk_tree_model_get (model, &iter, STORAGE_LIST_POINTER, &cdrom, -1);
 
281
                        if (GST_IS_DISKS_STORAGE_CDROM (cdrom)) {
 
282
                                /*gst_disks_cdrom_mount (cdrom);*/
 
283
                                g_object_get (G_OBJECT (cdrom), "disc", &disc, NULL);
 
284
                                if (GST_IS_CDROM_DISC_DATA (disc))
 
285
                                        gst_disks_mountable_mount (GST_DISKS_MOUNTABLE (disc));
 
286
                        
 
287
                                gst_disks_storage_setup_properties_widget (GST_DISKS_STORAGE (cdrom));
 
288
                        }
 
289
                        
 
290
                }
 
291
        }
 
292
}
 
293
 
 
294
void
 
295
gst_on_browse_button_clicked (GtkWidget *button, gpointer gdata)
 
296
{
 
297
        GtkWidget            *treeview;
 
298
        GtkTreeModel         *model;
 
299
        GtkTreeIter           iter;
 
300
        GtkTreeSelection     *selection;
 
301
        GstDisksPartition    *part;
 
302
        GstDisksStorageCdrom *cdrom;
 
303
        GstCdromDisc         *disc;
 
304
 
 
305
        treeview = (GtkWidget *) gdata;
 
306
 
 
307
        selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (treeview));
 
308
        if (gtk_tree_selection_get_selected (selection, &model, &iter)) {
 
309
                if (gtk_tree_model_get_n_columns (model) == PARTITION_LIST_LAST) {
 
310
                        gtk_tree_model_get (model, &iter, PARTITION_LIST_POINTER, &part, -1);
 
311
                        if (GST_IS_DISKS_PARTITION (part)) {
 
312
                                gst_disks_partition_browse (part);
 
313
                        }
 
314
                } else if (gtk_tree_model_get_n_columns (model) == STORAGE_LIST_LAST) {
 
315
                        gtk_tree_model_get (model, &iter, STORAGE_LIST_POINTER, &cdrom, -1);
 
316
                        if (GST_IS_DISKS_STORAGE_CDROM (cdrom)) {
 
317
                                g_object_get (G_OBJECT (cdrom), "disc", &disc, NULL);
 
318
                                if (GST_IS_CDROM_DISC_DATA (disc)) {
 
319
                                        gst_disks_cdrom_disc_data_browse (GST_CDROM_DISC_DATA (disc));
 
320
                                } else if (GST_IS_CDROM_DISC_MIXED (disc)) {
 
321
                                        gst_disks_cdrom_disc_mixed_browse (GST_CDROM_DISC_MIXED (disc));
 
322
                                }
 
323
                        }
 
324
                }
 
325
        }
 
326
}
 
327
 
 
328
void
 
329
gst_on_play_button_clicked (GtkWidget *button, gpointer gdata)
 
330
{
 
331
        GtkWidget             *treeview;
 
332
        GtkTreeModel          *model;
 
333
        GtkTreeIter            iter;
 
334
        GtkTreeSelection      *selection;
 
335
        GstDisksStorageCdrom  *cdrom;
 
336
        GstCdromDisc          *disc;
 
337
        const gchar *device;
 
338
 
 
339
        treeview = (GtkWidget *) gdata;
 
340
 
 
341
        selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (treeview));
 
342
        if (gtk_tree_selection_get_selected (selection, &model, &iter)) {
 
343
                gtk_tree_model_get (model, &iter, STORAGE_LIST_POINTER, &cdrom, -1);
 
344
                if (GST_IS_DISKS_STORAGE_CDROM (cdrom)) {
 
345
                        g_object_get (G_OBJECT (cdrom), "device", &device, 
 
346
                                      "disc", &disc, NULL);
 
347
                        if (GST_IS_CDROM_DISC_AUDIO (disc)) {
 
348
                                gst_disks_cdrom_disc_audio_play (GST_CDROM_DISC_AUDIO (disc), device);
 
349
                        } else if (GST_IS_CDROM_DISC_MIXED (disc)) {
 
350
                                gst_disks_cdrom_disc_mixed_play (GST_CDROM_DISC_MIXED (disc), device);
 
351
                        }
 
352
                }
 
353
        }
 
354
}
 
355
 
 
356
gboolean
 
357
gst_on_partition_list_button_press (GtkTreeView *treeview, GdkEventButton *event, gpointer gdata)
 
358
{
 
359
        GtkTreePath *path;
 
360
        GtkItemFactory *factory;
 
361
 
 
362
        factory = (GtkItemFactory *) gdata;
 
363
 
 
364
        if (event->button == 3)
 
365
        {
 
366
                gtk_widget_grab_focus (GTK_WIDGET (treeview));
 
367
                if (gtk_tree_view_get_path_at_pos (treeview, event->x, event->y, &path, NULL, NULL, NULL))
 
368
                {
 
369
                        gtk_tree_selection_unselect_all (gtk_tree_view_get_selection (treeview));
 
370
                        gtk_tree_selection_select_path (gtk_tree_view_get_selection (treeview), path);
 
371
 
 
372
                        gtk_item_factory_popup (factory, event->x_root, event->y_root,
 
373
                                                event->button, event->time);
 
374
                }
 
375
                return TRUE;
 
376
        }
 
377
        return FALSE;
 
378
}
 
379
 
 
380
void
 
381
gst_disks_storage_get_device_speed_cb (GstDirectiveEntry *entry)
 
382
{
 
383
        GtkWidget *speed_label;
 
384
        xmlDoc *xml;
 
385
        xmlNodePtr root;
 
386
        gchar *device, *media;
 
387
        gchar *buf = NULL;
 
388
        gchar *speed;
 
389
        GstDisksStorage *storage;
 
390
 
 
391
        storage = (GstDisksStorage *) entry->data;
 
392
 
 
393
        if (GST_IS_DISKS_STORAGE_CDROM (storage)) {
 
394
                media = g_strdup ("cdrom");
 
395
        } else if (GST_IS_DISKS_STORAGE_DISK (storage)) {
 
396
                media = g_strdup ("disk");
 
397
        } else
 
398
                return;
 
399
 
 
400
        speed = g_strdup_printf ("%s_speed_label", media);
 
401
        speed_label = gst_dialog_get_widget (tool->main_dialog, speed);
 
402
        g_free (speed);
 
403
 
 
404
        g_object_set (G_OBJECT (storage), "speed", _("Getting ..."), NULL);
 
405
        gtk_label_set_text (GTK_LABEL (speed_label), _("Getting ..."));
 
406
 
 
407
        g_object_get (G_OBJECT (storage), "device", &device, NULL);
 
408
        xml = gst_tool_run_get_directive (entry->tool, entry->report_sign,
 
409
                                          entry->directive, device, NULL);
 
410
 
 
411
        if (!xml) {
 
412
                g_object_set (G_OBJECT (storage), "speed", _("Not Available"), NULL);
 
413
                gtk_label_set_text (GTK_LABEL (speed_label), _("Not Available"));
 
414
                return;
 
415
        }
 
416
 
 
417
        root = gst_xml_doc_get_root (xml);
 
418
        if (root) {
 
419
                buf = gst_xml_get_child_content (root, "speed");
 
420
        }
 
421
        gst_xml_doc_destroy (xml);
 
422
 
 
423
        if (buf) {
 
424
                g_object_set (G_OBJECT (storage), "speed", buf, NULL);
 
425
                gtk_label_set_text (GTK_LABEL (speed_label), buf);
 
426
                g_free (buf);
 
427
        } else {
 
428
                g_object_set (G_OBJECT (storage), "speed", _("Not Available"), NULL);
 
429
                gtk_label_set_text (GTK_LABEL (speed_label), _("Not Available"));
 
430
        }
 
431
 
 
432
        g_free (media);
 
433
}
 
434
 
 
435
void
 
436
gst_on_change_mp_button_clicked (GtkWidget *button, gpointer gdata)
 
437
{
 
438
        GtkWidget *filesel;
 
439
        GtkWidget *point_entry;
 
440
        gchar     *filename;
 
441
 
 
442
        filesel = gtk_file_chooser_dialog_new (_("Select New Mount Point Path"),
 
443
                                                                    NULL, GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER,
 
444
                                                                    GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
 
445
                                                                    GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT, NULL);
 
446
 
 
447
        if (g_ascii_strcasecmp (gtk_widget_get_name (button), "cd_change_mp_button") == 0) {
 
448
                   point_entry = gst_dialog_get_widget (tool->main_dialog, "cd_point_entry");
 
449
        } else {
 
450
                   point_entry = gst_dialog_get_widget (tool->main_dialog, "part_point_entry");
 
451
        }
 
452
 
 
453
        filename = g_strdup (gtk_entry_get_text (GTK_ENTRY (point_entry)));
 
454
        
 
455
        if (g_file_test (filename, G_FILE_TEST_IS_DIR)) {
 
456
                   gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (filesel),
 
457
                                                                                filename);
 
458
        }
 
459
 
 
460
        if (filename) {
 
461
                   g_free (filename);
 
462
                   filename = NULL;
 
463
        }
 
464
                                                                  
 
465
        if (gtk_dialog_run (GTK_DIALOG (filesel)) == GTK_RESPONSE_ACCEPT) {
 
466
                   filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (filesel));
 
467
                   gtk_entry_set_text (GTK_ENTRY (point_entry), filename);
 
468
                   g_free (filename);
 
469
        }
 
470
 
 
471
        gtk_widget_destroy (filesel);
 
472
}