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

« back to all changes in this revision

Viewing changes to src/disks/disks-storage-disk.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
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
 
2
/*  
 
3
 * Copyright (C) 2001 Ximian, Inc.
 
4
 *
 
5
 * This program is free software; you can redistribute it and/or modify
 
6
 * it under the terms of the GNU General Public License as
 
7
 * published by the Free Software Foundation; either version 2 of the
 
8
 * License, or (at your option) any later version.
 
9
 *
 
10
 * This program is distributed in the hope that it will be useful,
 
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
13
 * GNU General Public License for more details.
 
14
 *
 
15
 * You should have received a copy of the GNU General Public License
 
16
 * along with this program; if not, write to the Free Software
 
17
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
 
18
 *
 
19
 * Authors: Alvaro Pe�a Gonzalez <apg@esware.com>
 
20
 *          Carlos Garcia Campos <elkalmail@yahoo.es>
 
21
 */
 
22
 
 
23
#ifdef HAVE_CONFIG_H
 
24
#  include <config.h>
 
25
#endif
 
26
 
 
27
#include <glib/gi18n.h>
 
28
 
 
29
#include "disks-storage.h"
 
30
#include "disks-storage-disk.h"
 
31
#include "disks-gui.h"
 
32
 
 
33
#define PARENT_TYPE GST_TYPE_DISKS_STORAGE
 
34
 
 
35
enum {
 
36
        PROP_0,
 
37
        PROP_PARTITIONS
 
38
};
 
39
 
 
40
struct _GstDisksStorageDiskPriv
 
41
{
 
42
        GList *partitions;
 
43
        /*gboolean use_dma;*/
 
44
};
 
45
 
 
46
static void storage_disk_init       (GstDisksStorageDisk      *storage);
 
47
static void storage_disk_class_init (GstDisksStorageDiskClass *klass);
 
48
static void storage_disk_finalize   (GObject                  *object);
 
49
 
 
50
static void storage_set_property (GObject  *object, guint prop_id,
 
51
                                  const GValue *value, GParamSpec *spec);
 
52
static void storage_get_property (GObject  *object, guint prop_id,
 
53
                                  GValue *value, GParamSpec *spec);
 
54
 
 
55
static void storage_disk_setup_properties_widget (GstDisksStorage *storage);
 
56
 
 
57
static GObjectClass *parent_class = NULL;
 
58
 
 
59
GType
 
60
gst_disks_storage_disk_get_type (void)
 
61
{
 
62
        static GType type = 0;
 
63
        
 
64
        if (!type) {
 
65
                static const GTypeInfo info = {
 
66
                        sizeof (GstDisksStorageDiskClass),
 
67
                        (GBaseInitFunc) NULL,
 
68
                        (GBaseFinalizeFunc) NULL,
 
69
                        (GClassInitFunc) storage_disk_class_init,
 
70
                        NULL,
 
71
                        NULL,
 
72
                        sizeof (GstDisksStorageDisk),
 
73
                        0,
 
74
                        (GInstanceInitFunc) storage_disk_init
 
75
                };
 
76
                type = g_type_register_static (PARENT_TYPE, "GstDisksStorageDisk",
 
77
                                               &info, 0);
 
78
           }
 
79
           return type;
 
80
}
 
81
 
 
82
static void
 
83
storage_disk_init (GstDisksStorageDisk *storage)
 
84
{
 
85
        g_return_if_fail (GST_IS_DISKS_STORAGE_DISK (storage));
 
86
        
 
87
        storage->priv = g_new0 (GstDisksStorageDiskPriv, 1);
 
88
        /*storage->priv->use_dma = FALSE;*/
 
89
        storage->priv->partitions = NULL;
 
90
 
 
91
        g_object_set (G_OBJECT (storage),
 
92
                      "name", _("Hard Disk"),
 
93
                      "icon_name", "gnome-dev-harddisk",
 
94
                      NULL);
 
95
}
 
96
 
 
97
static void
 
98
storage_disk_class_init (GstDisksStorageDiskClass *klass)
 
99
{
 
100
        GObjectClass         *object_class  = G_OBJECT_CLASS (klass);
 
101
        GstDisksStorageClass *storage_class = GST_DISKS_STORAGE_CLASS (klass);
 
102
 
 
103
        parent_class = g_type_class_peek_parent (klass);
 
104
 
 
105
        object_class->set_property = storage_set_property;
 
106
        object_class->get_property = storage_get_property;
 
107
        
 
108
        storage_class->setup_properties_widget = storage_disk_setup_properties_widget;
 
109
 
 
110
        g_object_class_install_property (object_class, PROP_PARTITIONS,
 
111
                                         g_param_spec_pointer ("partitions", NULL, NULL,
 
112
                                                               G_PARAM_READWRITE));
 
113
        
 
114
        object_class->finalize = storage_disk_finalize;
 
115
}
 
116
 
 
117
static void
 
118
delete_object (gpointer object, gpointer gdata)
 
119
{
 
120
        g_object_unref (G_OBJECT (object));
 
121
}
 
122
 
 
123
static void
 
124
storage_disk_finalize (GObject *object)
 
125
{
 
126
        GstDisksStorageDisk *storage = GST_DISKS_STORAGE_DISK (object);
 
127
        g_return_if_fail (GST_IS_DISKS_STORAGE_DISK (storage));
 
128
 
 
129
        if (storage->priv) {
 
130
                if (storage->priv->partitions) {
 
131
                        g_list_foreach (storage->priv->partitions,
 
132
                                        delete_object, NULL);
 
133
                        g_list_free (storage->priv->partitions);
 
134
                        storage->priv->partitions = NULL;
 
135
                }
 
136
                g_free (storage->priv);
 
137
                storage->priv = NULL;
 
138
        }
 
139
        
 
140
        if (G_OBJECT_CLASS (parent_class)->finalize)
 
141
                (* G_OBJECT_CLASS (parent_class)->finalize) (object);
 
142
}
 
143
 
 
144
static void
 
145
storage_set_property (GObject  *object, guint prop_id, const GValue *value,
 
146
                      GParamSpec *spec)
 
147
{
 
148
        GstDisksStorageDisk *storage;
 
149
 
 
150
        g_return_if_fail (GST_IS_DISKS_STORAGE_DISK (object));
 
151
 
 
152
        storage = GST_DISKS_STORAGE_DISK (object);
 
153
 
 
154
        switch (prop_id) {
 
155
        case PROP_PARTITIONS:
 
156
                storage->priv->partitions = g_value_get_pointer (value);
 
157
                
 
158
                break;
 
159
        default:
 
160
                break;
 
161
        }
 
162
}
 
163
 
 
164
static void
 
165
storage_get_property (GObject  *object, guint prop_id, GValue *value,
 
166
                      GParamSpec *spec)
 
167
{
 
168
        GstDisksStorageDisk *storage;
 
169
 
 
170
        g_return_if_fail (GST_IS_DISKS_STORAGE_DISK (object));
 
171
 
 
172
        storage = GST_DISKS_STORAGE_DISK (object);
 
173
 
 
174
        switch (prop_id) {
 
175
        case PROP_PARTITIONS:
 
176
                g_value_set_pointer (value, storage->priv->partitions);
 
177
                break;
 
178
        default:
 
179
                G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, spec);
 
180
        }
 
181
}
 
182
 
 
183
GstDisksStorage*
 
184
gst_disks_storage_disk_new (void)
 
185
{
 
186
        GstDisksStorageDisk *storage;
 
187
        
 
188
        storage = g_object_new (GST_TYPE_DISKS_STORAGE_DISK, NULL);
 
189
 
 
190
        return GST_DISKS_STORAGE (storage);
 
191
}
 
192
 
 
193
static void
 
194
storage_disk_setup_properties_widget (GstDisksStorage *storage)
 
195
{
 
196
        GstDisksStorageDisk *disk;
 
197
 
 
198
        disk = GST_DISKS_STORAGE_DISK (storage);
 
199
 
 
200
        gst_disks_gui_setup_disk_properties (disk);
 
201
        
 
202
        GST_DISKS_STORAGE_GET_CLASS (storage)->setup_common_properties (storage);
 
203
}
 
204
 
 
205
GstDisksPartition *
 
206
gst_disks_storage_disk_get_partition (GstDisksStorageDisk *disk, const gchar *device)
 
207
{
 
208
        GList *list = NULL;
 
209
        GList *partitions = NULL;
 
210
        GstDisksPartition *part;
 
211
        gchar *part_device;
 
212
 
 
213
        g_return_val_if_fail (GST_IS_DISKS_STORAGE_DISK (disk), NULL);
 
214
 
 
215
        g_object_get (G_OBJECT (disk), "partitions", &partitions, NULL);
 
216
 
 
217
        if (partitions)
 
218
                list = g_list_first (partitions);
 
219
        
 
220
        while (list) {
 
221
                part = GST_DISKS_PARTITION (list->data);
 
222
                g_object_get (G_OBJECT (part), "device", &part_device, NULL);
 
223
 
 
224
                if (g_ascii_strcasecmp (part_device, device) == 0)
 
225
                        return part;
 
226
 
 
227
                list = g_list_next (list);
 
228
        }
 
229
 
 
230
        return NULL;
 
231
}
 
232
 
 
233