~ubuntu-branches/ubuntu/precise/rhythmbox/precise-201203091205

« back to all changes in this revision

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

Tags: upstream-0.9.5
ImportĀ upstreamĀ versionĀ 0.9.5

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
 
1
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
 
2
 *
2
3
 *  arch-tag: Implementation of removable media source object (based of the ipod source)
3
4
 *
4
5
 *  Copyright (C) 2004 Christophe Fergeau  <teuf@gnome.org>
16
17
 *
17
18
 *  You should have received a copy of the GNU General Public License
18
19
 *  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
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA.
20
21
 *
21
22
 */
22
23
 
23
24
#include <config.h>
24
25
 
 
26
#include <string.h>
 
27
 
 
28
#include <glib/gi18n.h>
25
29
#include <gtk/gtktreeview.h>
26
30
#include <gtk/gtkicontheme.h>
27
31
#include <gtk/gtkiconfactory.h>
28
 
#include <string.h>
29
 
#include "rhythmdb.h"
30
 
#include <libgnome/gnome-i18n.h>
31
32
#include <libgnomevfs/gnome-vfs-volume.h>
32
33
#include <libgnomevfs/gnome-vfs-volume-monitor.h>
 
34
 
 
35
#include "rhythmdb.h"
33
36
#include "eel-gconf-extensions.h"
34
37
#include "rb-removable-media-source.h"
35
38
#include "rb-stock-icons.h"
51
54
                                          GValue *value,
52
55
                                          GParamSpec *pspec);
53
56
 
54
 
static GdkPixbuf *impl_get_pixbuf (RBSource *source);
55
57
static void impl_delete_thyself (RBSource *source);
56
58
 
57
59
 
60
62
        GnomeVFSVolume *volume;
61
63
} RBRemovableMediaSourcePrivate;
62
64
 
63
 
G_DEFINE_TYPE (RBRemovableMediaSource, rb_removable_media_source, RB_TYPE_LIBRARY_SOURCE)
 
65
G_DEFINE_TYPE (RBRemovableMediaSource, rb_removable_media_source, RB_TYPE_BROWSER_SOURCE)
64
66
#define REMOVABLE_MEDIA_SOURCE_GET_PRIVATE(o)   (G_TYPE_INSTANCE_GET_PRIVATE ((o), RB_TYPE_REMOVABLE_MEDIA_SOURCE, RBRemovableMediaSourcePrivate))
65
67
 
66
68
enum
76
78
{
77
79
        GObjectClass *object_class = G_OBJECT_CLASS (klass);
78
80
        RBSourceClass *source_class = RB_SOURCE_CLASS (klass);
79
 
        RBLibrarySourceClass *library_source_class = RB_LIBRARY_SOURCE_CLASS (klass);
 
81
        RBBrowserSourceClass *browser_source_class = RB_BROWSER_SOURCE_CLASS (klass);
80
82
 
81
83
        object_class->constructor = rb_removable_media_source_constructor;
82
84
        object_class->dispose = rb_removable_media_source_dispose;
83
85
        object_class->set_property = rb_removable_media_source_set_property;
84
86
        object_class->get_property = rb_removable_media_source_get_property;
85
87
 
86
 
        source_class->impl_get_pixbuf = impl_get_pixbuf;
87
88
        source_class->impl_delete_thyself = impl_delete_thyself;
88
89
        source_class->impl_can_cut = (RBSourceFeatureFunc) rb_false_function;
89
 
        source_class->impl_can_copy = (RBSourceFeatureFunc) rb_false_function;
 
90
        source_class->impl_can_copy = (RBSourceFeatureFunc) rb_true_function;
 
91
        source_class->impl_can_paste = (RBSourceFeatureFunc) rb_false_function;
90
92
        source_class->impl_can_delete = (RBSourceFeatureFunc) rb_false_function;
91
93
        source_class->impl_receive_drag = NULL;
92
94
        source_class->impl_can_move_to_trash = (RBSourceFeatureFunc) rb_false_function;
95
97
        source_class->impl_get_config_widget = NULL;
96
98
        source_class->impl_show_popup = (RBSourceFeatureFunc) rb_false_function;
97
99
 
98
 
        library_source_class->impl_get_paned_key = NULL;
99
 
        library_source_class->impl_has_first_added_column = (RBLibrarySourceFeatureFunc) rb_false_function;
100
 
        library_source_class->impl_has_drop_support = (RBLibrarySourceFeatureFunc) rb_false_function;
 
100
        browser_source_class->impl_get_paned_key = NULL;
 
101
        browser_source_class->impl_has_drop_support = (RBBrowserSourceFeatureFunc) rb_false_function;
101
102
 
102
103
        g_object_class_install_property (object_class,
103
104
                                         PROP_VOLUME,
113
114
static void
114
115
rb_removable_media_source_init (RBRemovableMediaSource *self)
115
116
{
116
 
 
117
117
}
118
118
 
119
119
static GObject *
122
122
{
123
123
        GObject *source; 
124
124
        GnomeVFSVolume *volume;
 
125
        GnomeVFSDrive *drive;
125
126
        char *display_name;
 
127
        gint size;
 
128
        char *icon_name;
 
129
        GtkIconTheme *theme;
 
130
        GdkPixbuf *pixbuf;
126
131
 
127
132
        source = G_OBJECT_CLASS(rb_removable_media_source_parent_class)
128
133
                        ->constructor (type, n_construct_properties, construct_properties);
129
134
 
130
135
        g_object_get (source, "volume", &volume, NULL);
131
 
        
132
 
        display_name = gnome_vfs_volume_get_display_name (volume);
 
136
        drive = gnome_vfs_volume_get_drive (volume);
 
137
        if (drive != NULL) {
 
138
                display_name = gnome_vfs_drive_get_display_name (drive);
 
139
                gnome_vfs_drive_unref (drive);
 
140
        } else {
 
141
                display_name = gnome_vfs_volume_get_display_name (volume);
 
142
        }
133
143
        g_object_set (source, "name", display_name, NULL);
134
144
        g_free (display_name);
135
145
 
 
146
        icon_name = gnome_vfs_volume_get_icon (volume);
 
147
        theme = gtk_icon_theme_get_default ();
 
148
        gtk_icon_size_lookup (GTK_ICON_SIZE_LARGE_TOOLBAR, &size, NULL);
 
149
        pixbuf = gtk_icon_theme_load_icon (theme, icon_name, size, 0, NULL);
 
150
        g_free (icon_name);
 
151
 
 
152
        rb_source_set_pixbuf (RB_SOURCE (source), pixbuf);
 
153
        if (pixbuf != NULL) {
 
154
                g_object_unref (pixbuf);
 
155
        }
 
156
 
136
157
        g_object_unref (volume);
137
158
 
138
159
        return source;
160
181
{
161
182
        RBRemovableMediaSourcePrivate *priv = REMOVABLE_MEDIA_SOURCE_GET_PRIVATE (object);
162
183
 
163
 
        switch (prop_id)
164
 
        {
 
184
        switch (prop_id) {
165
185
        case PROP_VOLUME:
166
186
                if (priv->volume) {
167
187
                        gnome_vfs_volume_unref (priv->volume);
183
203
{
184
204
        RBRemovableMediaSourcePrivate *priv = REMOVABLE_MEDIA_SOURCE_GET_PRIVATE (object);
185
205
 
186
 
        switch (prop_id)
187
 
        {
 
206
        switch (prop_id) {
188
207
        case PROP_VOLUME:
189
208
                gnome_vfs_volume_ref (priv->volume);
190
209
                g_value_take_object (value, priv->volume);
195
214
        }
196
215
}
197
216
 
198
 
static GdkPixbuf *
199
 
impl_get_pixbuf (RBSource *source)
200
 
{
201
 
        RBRemovableMediaSourcePrivate *priv = REMOVABLE_MEDIA_SOURCE_GET_PRIVATE (source);
202
 
        gint size;
203
 
 
204
 
        char *icon_name = gnome_vfs_volume_get_icon (priv->volume);
205
 
        GtkIconTheme *theme = gtk_icon_theme_get_default ();
206
 
        gtk_icon_size_lookup (GTK_ICON_SIZE_LARGE_TOOLBAR, &size, NULL);
207
 
        GdkPixbuf *icon = gtk_icon_theme_load_icon (theme, icon_name, size, 0, NULL);
208
 
        g_free (icon_name);
209
 
 
210
 
        return icon;
211
 
}
212
 
 
213
217
static void
214
218
impl_delete_thyself (RBSource *source)
215
219
{