hythmbox-2.98/plugins/generic-player/rb-nokia770-source.c

No issues found

  1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
  2  *
  3  *  Copyright (C) 2006 James Livingston  <doclivingston@gmail.com>
  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 published by
  7  *  the Free Software Foundation; either version 2 of the License, or
  8  *  (at your option) any later version.
  9  *
 10  *  The Rhythmbox authors hereby grant permission for non-GPL compatible
 11  *  GStreamer plugins to be used and distributed together with GStreamer
 12  *  and Rhythmbox. This permission is above and beyond the permissions granted
 13  *  by the GPL license by which Rhythmbox is covered. If you modify this code
 14  *  you may extend this exception to your version of the code, but you are not
 15  *  obligated to do so. If you do not wish to do so, delete this exception
 16  *  statement from your version.
 17  *
 18  *  This program is distributed in the hope that it will be useful,
 19  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 20  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 21  *  GNU General Public License for more details.
 22  *
 23  *  You should have received a copy of the GNU General Public License
 24  *  along with this program; if not, write to the Free Software
 25  *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA.
 26  *
 27  */
 28 
 29 #define __EXTENSIONS__
 30 
 31 #include "config.h"
 32 
 33 #include <string.h>
 34 
 35 #include <glib/gi18n.h>
 36 #include <gtk/gtk.h>
 37 
 38 #include "mediaplayerid.h"
 39 
 40 #include "rb-nokia770-source.h"
 41 #include "rb-debug.h"
 42 #include "rb-util.h"
 43 #include "rb-file-helpers.h"
 44 #include "rhythmdb.h"
 45 
 46 
 47 static char * impl_uri_from_playlist_uri (RBGenericPlayerSource *source, const char *uri);
 48 
 49 G_DEFINE_DYNAMIC_TYPE (RBNokia770Source, rb_nokia770_source, RB_TYPE_GENERIC_PLAYER_SOURCE)
 50 
 51 #define NOKIA_INTERNAL_MOUNTPOINT "file:///media/mmc1/"
 52 
 53 static void
 54 rb_nokia770_source_class_init (RBNokia770SourceClass *klass)
 55 {
 56 	RBGenericPlayerSourceClass *generic_class = RB_GENERIC_PLAYER_SOURCE_CLASS (klass);
 57 
 58 	generic_class->impl_uri_from_playlist_uri = impl_uri_from_playlist_uri;
 59 }
 60 
 61 static void
 62 rb_nokia770_source_class_finalize (RBNokia770SourceClass *klass)
 63 {
 64 }
 65 
 66 static void
 67 rb_nokia770_source_init (RBNokia770Source *source)
 68 {
 69 
 70 }
 71 
 72 RBSource *
 73 rb_nokia770_source_new (GObject *plugin, RBShell *shell, GMount *mount, MPIDDevice *device_info)
 74 {
 75 	RBNokia770Source *source;
 76 	RhythmDBEntryType *entry_type;
 77 	RhythmDB *db;
 78 	GVolume *volume;
 79 	char *name;
 80 	char *path;
 81 
 82 	g_assert (rb_nokia770_is_mount_player (mount, device_info));
 83 
 84 	volume = g_mount_get_volume (mount);
 85 
 86 	g_object_get (G_OBJECT (shell), "db", &db, NULL);
 87 	path = g_volume_get_identifier (volume, G_VOLUME_IDENTIFIER_KIND_UNIX_DEVICE);
 88 	name = g_strdup_printf ("nokia770: %s", path);
 89 
 90 	entry_type = g_object_new (RHYTHMDB_TYPE_ENTRY_TYPE,
 91 				   "db", db,
 92 				   "name", name,
 93 				   "category", RHYTHMDB_ENTRY_NORMAL,
 94 				   "save-to-disk", FALSE,
 95 				   NULL);
 96 	rhythmdb_register_entry_type (db, entry_type);
 97 	g_object_unref (db);
 98 	g_free (name);
 99 	g_free (path);
100 	g_object_unref (volume);
101 
102 	source = RB_NOKIA770_SOURCE (g_object_new (RB_TYPE_NOKIA770_SOURCE,
103 						   "plugin", plugin,
104 						   "entry-type", entry_type,
105 						   "mount", mount,
106 						   "shell", shell,
107 						   "device-info", device_info,
108 						   NULL));
109 
110 	rb_shell_register_entry_type_for_source (shell, RB_SOURCE (source), entry_type);
111 
112 	return RB_SOURCE (source);
113 }
114 
115 static char *
116 impl_uri_from_playlist_uri (RBGenericPlayerSource *source, const char *uri)
117 {
118 	const char *path;
119 	char *local_uri;
120 	char *mount_uri;
121 
122 	if (!g_str_has_prefix (uri, NOKIA_INTERNAL_MOUNTPOINT)) {
123 		rb_debug ("found playlist uri with unexpected mountpoint");
124 		return NULL;
125 	}
126 
127 	path = uri + strlen (NOKIA_INTERNAL_MOUNTPOINT);
128 	mount_uri = rb_generic_player_source_get_mount_path (source);
129 	local_uri = rb_uri_append_uri (mount_uri, path);
130 	g_free (mount_uri);
131 	return local_uri;
132 }
133 
134 gboolean
135 rb_nokia770_is_mount_player (GMount *mount, MPIDDevice *device_info)
136 {
137 	gboolean result;
138 	char *vendor;
139 	char *model;
140 
141 	g_object_get (device_info, "vendor", &vendor, "model", &model, NULL);
142 	result = FALSE;
143 	if (vendor != NULL && g_str_equal (vendor, "Nokia")) {
144 		if (model != NULL && (g_str_equal (model, "770") || g_str_equal (model, "N800") || g_str_equal (model, "N810"))) {
145 			result = TRUE;
146 		}
147 	}
148 
149 	g_free (vendor);
150 	g_free (model);
151 	return result;
152 }
153 
154 void
155 _rb_nokia770_source_register_type (GTypeModule *module)
156 {
157 	rb_nokia770_source_register_type (module);
158 }