1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
3 * arch-tag: Implementation of Nokia 770 source object
5 * Copyright (C) 2006 James Livingston <jrl@ids.org.au>
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.
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.
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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
23 #define __EXTENSIONS__
29 #include <glib/gi18n.h>
31 #include <dbus/dbus.h>
33 #include <libgnomevfs/gnome-vfs-volume.h>
34 #include <libgnomevfs/gnome-vfs-volume-monitor.h>
36 #include "eel-gconf-extensions.h"
37 #include "rb-nokia770-source.h"
40 #include "rb-file-helpers.h"
42 #include "rb-plugin.h"
45 static char * impl_transform_playlist_uri (RBGenericPlayerSource
*source
, const char *uri
);
50 int x
; /* To build with Solaris forte compiler */
52 } RBNokia770SourcePrivate
;
54 RB_PLUGIN_DEFINE_TYPE (RBNokia770Source
, rb_nokia770_source
, RB_TYPE_GENERIC_PLAYER_SOURCE
)
55 #define NOKIA770_SOURCE_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), RB_TYPE_NOKIA770_SOURCE, RBNokia770SourcePrivate))
58 #define NOKIA_INTERNAL_MOUNTPOINT "file:///media/mmc1/"
61 rb_nokia770_source_class_init (RBNokia770SourceClass
*klass
)
63 RBGenericPlayerSourceClass
*generic_class
= RB_GENERIC_PLAYER_SOURCE_CLASS (klass
);
65 generic_class
->impl_transform_playlist_uri
= impl_transform_playlist_uri
;
67 g_type_class_add_private (klass
, sizeof (RBNokia770SourcePrivate
));
71 rb_nokia770_source_init (RBNokia770Source
*source
)
76 RBRemovableMediaSource
*
77 rb_nokia770_source_new (RBShell
*shell
, GnomeVFSVolume
*volume
)
79 RBNokia770Source
*source
;
80 RhythmDBEntryType entry_type
;
83 g_assert (rb_nokia770_is_volume_player (volume
));
85 g_object_get (shell
, "db", &db
, NULL
);
86 entry_type
= rhythmdb_entry_register_type (db
, NULL
);
89 source
= RB_NOKIA770_SOURCE (g_object_new (RB_TYPE_NOKIA770_SOURCE
,
90 "entry-type", entry_type
,
93 "sourcelist-group", RB_SOURCELIST_GROUP_REMOVABLE
,
96 rb_shell_register_entry_type_for_source (shell
, RB_SOURCE (source
), entry_type
);
98 return RB_REMOVABLE_MEDIA_SOURCE (source
);
102 impl_transform_playlist_uri (RBGenericPlayerSource
*source
, const char *uri
)
108 if (!g_str_has_prefix (uri
, NOKIA_INTERNAL_MOUNTPOINT
)) {
109 rb_debug ("found playlist uri with unexpected mountpoint");
113 path
= uri
+ strlen (NOKIA_INTERNAL_MOUNTPOINT
);
114 mount_uri
= rb_generic_player_source_get_mount_path (source
);
115 local_uri
= rb_uri_append_uri (mount_uri
, path
);
124 hal_udi_is_nokia770 (const char *udi
)
127 DBusConnection
*conn
;
132 gboolean inited
= FALSE
;
135 dbus_error_init (&error
);
141 ctx
= libhal_ctx_new ();
143 rb_debug ("cannot connect to HAL");
146 conn
= dbus_bus_get (DBUS_BUS_SYSTEM
, &error
);
147 if (conn
== NULL
|| dbus_error_is_set (&error
))
150 libhal_ctx_set_dbus_connection (ctx
, conn
);
151 if (!libhal_ctx_init (ctx
, &error
) || dbus_error_is_set (&error
))
155 parent_udi
= libhal_device_get_property_string (ctx
, udi
,
156 "info.parent", &error
);
157 if (parent_udi
== NULL
|| dbus_error_is_set (&error
))
161 rb_debug ("Nokia detection: info.parent=%s", parent_udi
);
162 parent_name
= libhal_device_get_property_string (ctx
, parent_udi
,
163 "info.vendor", &error
);
164 rb_debug ("Nokia detection: info.vendor=%s", parent_name
);
165 if (parent_name
== NULL
|| dbus_error_is_set (&error
))
168 if (strcmp (parent_name
, "Nokia") == 0) {
169 g_free (parent_name
);
171 parent_name
= libhal_device_get_property_string (ctx
, parent_udi
,
172 "info.product", &error
);
173 rb_debug ("Nokia detection: info.product=%s", parent_name
);
174 if (parent_name
== NULL
|| dbus_error_is_set (&error
))
177 if (strcmp (parent_name
, "770") == 0) {
183 g_free (parent_name
);
186 if (dbus_error_is_set (&error
)) {
187 rb_debug ("Error: %s\n", error
.message
);
188 dbus_error_free (&error
);
189 dbus_error_init (&error
);
194 libhal_ctx_shutdown (ctx
, &error
);
195 libhal_ctx_free(ctx
);
198 dbus_error_free (&error
);
206 hal_udi_is_nokia770 (const char *udi
)
214 ctx
= hal_initialize (NULL
, FALSE
);
218 parent_udi
= hal_device_get_property_string (ctx
, udi
,
221 parent_name
= hal_device_get_property_string (ctx
, parent_udi
,
223 if (parent_name
!= NULL
&& strcmp (parent_name
, "Nokia") == 0) {
225 parent_name
= hal_device_get_property_string (ctx
, parent_udi
,
227 if (parent_name
!= NULL
&& strcmp (parent_name
, "770") == 0) {
232 g_free (parent_name
);
243 rb_nokia770_is_volume_player (GnomeVFSVolume
*volume
)
245 gboolean result
= FALSE
;
248 if (gnome_vfs_volume_get_volume_type (volume
) != GNOME_VFS_VOLUME_TYPE_MOUNTPOINT
) {
252 str
= gnome_vfs_volume_get_hal_udi (volume
);
256 result
= hal_udi_is_nokia770 (str
);