~ubuntu-branches/ubuntu/utopic/rhythmbox/utopic-proposed

« back to all changes in this revision

Viewing changes to sources/rb-removable-media-source.c

Tags: upstream-0.9.2
ImportĀ upstreamĀ versionĀ 0.9.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 *  arch-tag: Implementation of removable media source object (based of the ipod source)
 
3
 *
 
4
 *  Copyright (C) 2004 Christophe Fergeau  <teuf@gnome.org>
 
5
 *  Copyright (C) 2005 James Livingston  <jrl@ids.org.au>
 
6
 *
 
7
 *  This program is free software; you can redistribute it and/or modify
 
8
 *  it under the terms of the GNU General Public License as published by
 
9
 *  the Free Software Foundation; either version 2 of the License, or
 
10
 *  (at your option) any later version.
 
11
 *
 
12
 *  This program is distributed in the hope that it will be useful,
 
13
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
14
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
15
 *  GNU General Public License for more details.
 
16
 *
 
17
 *  You should have received a copy of the GNU General Public License
 
18
 *  along with this program; if not, write to the Free Software
 
19
 *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 
20
 *
 
21
 */
 
22
 
 
23
#include <config.h>
 
24
 
 
25
#include <gtk/gtktreeview.h>
 
26
#include <gtk/gtkicontheme.h>
 
27
#include <gtk/gtkiconfactory.h>
 
28
#include <string.h>
 
29
#include "rhythmdb.h"
 
30
#include <libgnome/gnome-i18n.h>
 
31
#include <libgnomevfs/gnome-vfs-volume.h>
 
32
#include <libgnomevfs/gnome-vfs-volume-monitor.h>
 
33
#include "eel-gconf-extensions.h"
 
34
#include "rb-removable-media-source.h"
 
35
#include "rb-stock-icons.h"
 
36
#include "rb-debug.h"
 
37
#include "rb-dialog.h"
 
38
#include "rb-util.h"
 
39
 
 
40
static void rb_removable_media_source_dispose (GObject *object);
 
41
 
 
42
static void rb_removable_media_source_set_property (GObject *object,
 
43
                                          guint prop_id,
 
44
                                          const GValue *value,
 
45
                                          GParamSpec *pspec);
 
46
static void rb_removable_media_source_get_property (GObject *object,
 
47
                                          guint prop_id,
 
48
                                          GValue *value,
 
49
                                          GParamSpec *pspec);
 
50
 
 
51
static GdkPixbuf *impl_get_pixbuf (RBSource *source);
 
52
static void impl_delete_thyself (RBSource *source);
 
53
 
 
54
 
 
55
typedef struct
 
56
{
 
57
        GnomeVFSVolume *volume;
 
58
} RBRemovableMediaSourcePrivate;
 
59
 
 
60
G_DEFINE_TYPE (RBRemovableMediaSource, rb_removable_media_source, RB_TYPE_LIBRARY_SOURCE)
 
61
#define REMOVABLE_MEDIA_SOURCE_GET_PRIVATE(o)   (G_TYPE_INSTANCE_GET_PRIVATE ((o), RB_TYPE_REMOVABLE_MEDIA_SOURCE, RBRemovableMediaSourcePrivate))
 
62
 
 
63
enum
 
64
{
 
65
        PROP_0,
 
66
        PROP_VOLUME,
 
67
};
 
68
 
 
69
 
 
70
 
 
71
static void
 
72
rb_removable_media_source_class_init (RBRemovableMediaSourceClass *klass)
 
73
{
 
74
        GObjectClass *object_class = G_OBJECT_CLASS (klass);
 
75
        RBSourceClass *source_class = RB_SOURCE_CLASS (klass);
 
76
        RBLibrarySourceClass *library_source_class = RB_LIBRARY_SOURCE_CLASS (klass);
 
77
 
 
78
        object_class->dispose = rb_removable_media_source_dispose;
 
79
        object_class->set_property = rb_removable_media_source_set_property;
 
80
        object_class->get_property = rb_removable_media_source_get_property;
 
81
 
 
82
        source_class->impl_get_pixbuf = impl_get_pixbuf;
 
83
        source_class->impl_delete_thyself = impl_delete_thyself;
 
84
        source_class->impl_can_cut = (RBSourceFeatureFunc) rb_false_function;
 
85
        source_class->impl_can_copy = (RBSourceFeatureFunc) rb_false_function;
 
86
        source_class->impl_can_delete = (RBSourceFeatureFunc) rb_false_function;
 
87
        source_class->impl_receive_drag = NULL;
 
88
        source_class->impl_paste = NULL;
 
89
        source_class->impl_delete = NULL;
 
90
        source_class->impl_get_config_widget = NULL;
 
91
        source_class->impl_show_popup = (RBSourceFeatureFunc) rb_false_function;
 
92
 
 
93
        library_source_class->impl_get_paned_key = NULL;
 
94
        library_source_class->impl_has_first_added_column = (RBLibrarySourceFeatureFunc) rb_false_function;
 
95
        library_source_class->impl_has_drop_support = (RBLibrarySourceFeatureFunc) rb_false_function;
 
96
 
 
97
        g_object_class_install_property (object_class,
 
98
                                         PROP_VOLUME,
 
99
                                         g_param_spec_object ("volume",
 
100
                                                              "Volume",
 
101
                                                              "GnomeVfs Volume",
 
102
                                                              GNOME_VFS_TYPE_VOLUME,
 
103
                                                              G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
 
104
 
 
105
        g_type_class_add_private (klass, sizeof (RBRemovableMediaSourcePrivate));
 
106
}
 
107
 
 
108
static void
 
109
rb_removable_media_source_init (RBRemovableMediaSource *self)
 
110
{
 
111
 
 
112
}
 
113
 
 
114
static void 
 
115
rb_removable_media_source_dispose (GObject *object)
 
116
{
 
117
        RBRemovableMediaSourcePrivate *priv = REMOVABLE_MEDIA_SOURCE_GET_PRIVATE (object);
 
118
 
 
119
        if (priv->volume) {
 
120
                gnome_vfs_volume_unref (priv->volume);
 
121
                priv->volume = NULL;
 
122
        }
 
123
 
 
124
        G_OBJECT_CLASS (rb_removable_media_source_parent_class)->dispose (object);
 
125
}
 
126
 
 
127
static void
 
128
rb_removable_media_source_set_property (GObject *object,
 
129
                                        guint prop_id,
 
130
                                        const GValue *value,
 
131
                                        GParamSpec *pspec)
 
132
{
 
133
        RBRemovableMediaSourcePrivate *priv = REMOVABLE_MEDIA_SOURCE_GET_PRIVATE (object);
 
134
 
 
135
        switch (prop_id)
 
136
        {
 
137
        case PROP_VOLUME:
 
138
                if (priv->volume) {
 
139
                        gnome_vfs_volume_unref (priv->volume);
 
140
                }
 
141
                priv->volume = g_value_get_object (value);
 
142
                gnome_vfs_volume_ref (priv->volume);
 
143
                break;
 
144
        default:
 
145
                G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
 
146
                break;
 
147
        }
 
148
}
 
149
 
 
150
static void
 
151
rb_removable_media_source_get_property (GObject *object,
 
152
                                        guint prop_id,
 
153
                                        GValue *value,
 
154
                                        GParamSpec *pspec)
 
155
{
 
156
        RBRemovableMediaSourcePrivate *priv = REMOVABLE_MEDIA_SOURCE_GET_PRIVATE (object);
 
157
 
 
158
        switch (prop_id)
 
159
        {
 
160
        case PROP_VOLUME:
 
161
                gnome_vfs_volume_ref (priv->volume);
 
162
                g_value_take_object (value, priv->volume);
 
163
                break;
 
164
        default:
 
165
                G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
 
166
                break;
 
167
        }
 
168
}
 
169
 
 
170
static GdkPixbuf *
 
171
impl_get_pixbuf (RBSource *source)
 
172
{
 
173
        RBRemovableMediaSourcePrivate *priv = REMOVABLE_MEDIA_SOURCE_GET_PRIVATE (source);
 
174
        gint size;
 
175
 
 
176
        char *icon_name = gnome_vfs_volume_get_icon (priv->volume);
 
177
        GtkIconTheme *theme = gtk_icon_theme_get_default ();
 
178
        gtk_icon_size_lookup (GTK_ICON_SIZE_LARGE_TOOLBAR, &size, NULL);
 
179
        GdkPixbuf *icon = gtk_icon_theme_load_icon (theme, icon_name, size, 0, NULL);
 
180
        g_free (icon_name);
 
181
 
 
182
        return icon;
 
183
}
 
184
 
 
185
static void
 
186
impl_delete_thyself (RBSource *source)
 
187
{
 
188
        RhythmDB *db;
 
189
        RBShell *shell;
 
190
        RhythmDBEntryType entry_type;
 
191
 
 
192
        g_object_get (G_OBJECT (source), "shell", &shell, NULL);
 
193
        g_object_get (G_OBJECT (shell), "db", &db, NULL);
 
194
        g_object_unref (G_OBJECT (shell));
 
195
 
 
196
        g_object_get (G_OBJECT (source), "entry-type", &entry_type, NULL);
 
197
        rhythmdb_entry_delete_by_type (db, entry_type);
 
198
        rhythmdb_commit (db);
 
199
        g_object_unref (db);
 
200
}