2
* arch-tag: Implementation of generic audio player source object
4
* Copyright (C) 2004 James Livingston <jrl@ids.org.au>
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 published by
8
* the Free Software Foundation; either version 2 of the License, or
9
* (at your option) any later version.
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.
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.
24
#include <gtk/gtktreeview.h>
27
#include <libgnome/gnome-i18n.h>
30
#include <dbus/dbus.h>
32
#include <libgnomevfs/gnome-vfs-volume.h>
33
#include <libgnomevfs/gnome-vfs-volume-monitor.h>
34
#include "eel-gconf-extensions.h"
35
#include "rb-generic-player-source.h"
38
#include "rb-file-helpers.h"
41
static GObject *rb_generic_player_source_constructor (GType type, guint n_construct_properties,
42
GObjectConstructParam *construct_properties);
43
static void rb_generic_player_source_dispose (GObject *object);
45
static gboolean impl_show_popup (RBSource *source);
46
static void rb_generic_player_source_load_songs (RBGenericPlayerSource *source);
47
static gchar *default_get_mount_path (RBGenericPlayerSource *source);
52
} RBGenericPlayerSourcePrivate;
55
G_DEFINE_TYPE (RBGenericPlayerSource, rb_generic_player_source, RB_TYPE_REMOVABLE_MEDIA_SOURCE)
56
#define GENERIC_PLAYER_SOURCE_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), RB_TYPE_GENERIC_PLAYER_SOURCE, RBGenericPlayerSourcePrivate))
60
rb_generic_player_source_class_init (RBGenericPlayerSourceClass *klass)
62
GObjectClass *object_class = G_OBJECT_CLASS (klass);
63
RBSourceClass *source_class = RB_SOURCE_CLASS (klass);
65
object_class->constructor = rb_generic_player_source_constructor;
66
object_class->dispose = rb_generic_player_source_dispose;
68
source_class->impl_show_popup = impl_show_popup;
70
klass->impl_get_mount_path = default_get_mount_path;
72
g_type_class_add_private (klass, sizeof (RBGenericPlayerSourcePrivate));
76
rb_generic_player_source_init (RBGenericPlayerSource *source)
82
rb_generic_player_source_constructor (GType type, guint n_construct_properties,
83
GObjectConstructParam *construct_properties)
85
GObjectClass *klass, *parent_class;
86
RBGenericPlayerSource *source;
88
klass = G_OBJECT_CLASS (g_type_class_peek (type));
89
parent_class = G_OBJECT_CLASS (g_type_class_peek_parent (klass));
90
source = RB_GENERIC_PLAYER_SOURCE (parent_class->constructor (type, n_construct_properties, construct_properties));
92
rb_generic_player_source_load_songs (source);
94
return G_OBJECT (source);
98
rb_generic_player_source_dispose (GObject *object)
100
RBGenericPlayerSourcePrivate *priv = GENERIC_PLAYER_SOURCE_GET_PRIVATE (object);
102
if (priv->mount_path) {
103
g_free (priv->mount_path);
104
priv->mount_path = NULL;
107
G_OBJECT_CLASS (rb_generic_player_source_parent_class)->dispose (object);
110
RBRemovableMediaSource *
111
rb_generic_player_source_new (RBShell *shell, GnomeVFSVolume *volume)
113
RBGenericPlayerSource *source;
114
RhythmDBEntryType entry_type;
116
g_assert (rb_generic_player_is_volume_player (volume));
118
entry_type = rhythmdb_entry_register_type ();
120
source = RB_GENERIC_PLAYER_SOURCE (g_object_new (RB_TYPE_GENERIC_PLAYER_SOURCE,
121
"entry-type", entry_type,
126
rb_shell_register_entry_type_for_source (shell, RB_SOURCE (source), entry_type);
128
return RB_REMOVABLE_MEDIA_SOURCE (source);
132
rb_generic_player_source_load_songs (RBGenericPlayerSource *source)
134
RBGenericPlayerSourcePrivate *priv = GENERIC_PLAYER_SOURCE_GET_PRIVATE (source);
137
RhythmDBEntryType entry_type;
139
priv->mount_path = rb_generic_player_source_get_mount_path (source);
140
g_object_get (G_OBJECT (source), "entry-type", &entry_type, NULL);
141
g_object_get (G_OBJECT (source), "shell", &shell, NULL);
142
g_object_get (G_OBJECT (shell), "db", &db, NULL);
143
g_object_unref (G_OBJECT (shell));
145
rhythmdb_add_uri_with_type (db, priv->mount_path, entry_type);
149
rb_generic_player_source_get_mount_path (RBGenericPlayerSource *source)
151
RBGenericPlayerSourceClass *klass = RB_GENERIC_PLAYER_SOURCE_GET_CLASS (source);
153
return klass->impl_get_mount_path (source);
157
default_get_mount_path (RBGenericPlayerSource *source)
160
GnomeVFSVolume *volume;
162
g_object_get (G_OBJECT (source), "volume", &volume, NULL);
163
uri = gnome_vfs_volume_get_activation_uri (volume);
164
g_object_unref (G_OBJECT (volume));
171
rb_generic_player_is_volume_player (GnomeVFSVolume *volume)
173
gboolean result = FALSE;
175
gchar *udi = gnome_vfs_volume_get_hal_udi (volume);
178
LibHalContext *ctx = NULL;
179
DBusConnection *conn = NULL;
183
dbus_error_init (&error);
184
ctx = libhal_ctx_new ();
188
conn = dbus_bus_get (DBUS_BUS_SYSTEM, &error);
189
if (conn == NULL || dbus_error_is_set (&error))
191
libhal_ctx_set_dbus_connection (ctx, conn);
192
if (!libhal_ctx_init (ctx, &error) || dbus_error_is_set (&error))
195
/* find the udi of the player itself */
196
while (!libhal_device_query_capability (ctx, udi, "portable_audio_player", &error) &&
197
!dbus_error_is_set (&error)) {
198
char *new_udi = libhal_device_get_property_string (ctx, udi, "info.parent", &error);
199
if (dbus_error_is_set (&error))
202
if ((new_udi == NULL) || strcmp (new_udi, "/") == 0) {
203
rb_debug ("device is not audio player");
208
udi = g_strdup (new_udi);
209
libhal_free_string (new_udi);
211
if (dbus_error_is_set (&error))
214
/* check that it can be accessed as mass-storage */
215
prop = libhal_device_get_property_string (ctx, udi, "portable_audio_player.access_method", &error);
216
if (prop == NULL || strcmp (prop, "storage") != 0 || dbus_error_is_set (&error)) {
217
rb_debug ("device cannot be accessed via storage");
221
/* the device has passed all tests, so it should be a usable player */
224
if (dbus_error_is_set (&error)) {
225
rb_debug ("Error: %s\n", error.message);
226
dbus_error_free (&error);
227
dbus_error_init (&error);
231
libhal_free_string (prop);
234
libhal_ctx_shutdown (ctx, &error);
235
libhal_ctx_free (ctx);
237
dbus_error_free (&error);
241
#endif /* HAVE_HAL_0_5 */
243
/* treat as audio player if ".is_audio_player" exists in the root of the volume */
245
char *path = gnome_vfs_volume_get_activation_uri (volume);
246
char *file = g_build_filename (path, ".is_audio_player", NULL);
248
if (rb_uri_is_local (file) && rb_uri_exists (file))
259
impl_show_popup (RBSource *source)
261
_rb_source_show_popup (RB_SOURCE (source), "/GenericPlayerSourcePopup");