1 /* Copyright (c) 2010, Christophe Fergeau  <teuf@gnome.org>
2  * Part of the libgpod project.
3  *
4  * URL: http://www.gtkpod.org/
5  * URL: http://gtkpod.sourceforge.net/
6  *
7  * The code contained in this file is free software; you can redistribute
8  * it and/or modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either version
10  * 2.1 of the License, or (at your option) any later version.
11  *
12  * This file 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 GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with this code; if not, write to the Free Software
19  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
20  *
21  * iTunes and iPod are trademarks of Apple
22  *
23  * This product is not supported/written/published by Apple!
24  *
25  */
26 #include "config.h"
27 #include "backends.h"
28 
29 #include <stdlib.h>
30 #include <itdb_device.h>
31 #include <glib-object.h>
32 
33 #define LIBGPOD_UDEV_NS "LIBGPOD_"
34 
35 struct _UdevBackend {
36 	ItdbBackend parent;
37 };
38 typedef struct _UdevBackend UdevBackend;
39 
40 
udev_backend_destroy(ItdbBackend * itdb_backend)41 static void udev_backend_destroy (ItdbBackend *itdb_backend)
42 {
43 	UdevBackend *backend = (UdevBackend *)itdb_backend;
44 	g_free (backend);
45 }
46 
47 static gboolean
udev_backend_set_version(ItdbBackend * itdb_backend,unsigned int version)48 udev_backend_set_version (ItdbBackend *itdb_backend, unsigned int version)
49 {
50 #ifdef UPODSLEUTH
51 	g_print (LIBGPOD_UDEV_NS"VERSION=%u\n", version);
52 #endif
53 	return TRUE;
54 }
55 
56 static gboolean
udev_backend_set_is_unknown(ItdbBackend * itdb_backend,gboolean unknown)57 udev_backend_set_is_unknown (ItdbBackend *itdb_backend, gboolean unknown)
58 {
59 #ifdef UPODSLEUTH
60 	g_print (LIBGPOD_UDEV_NS"IS_UNKNOWN=%u\n", !!unknown);
61 #endif
62 	return TRUE;
63 }
64 
65 static gboolean
udev_backend_set_icon_name(ItdbBackend * itdb_backend,const char * icon_name)66 udev_backend_set_icon_name (ItdbBackend *itdb_backend, const char *icon_name)
67 {
68 	g_print ("UDISKS_PRESENTATION_ICON_NAME=%s\n", icon_name);
69 	return TRUE;
70 }
71 
72 static gboolean
udev_backend_set_firewire_id(ItdbBackend * itdb_backend,const char * fwid)73 udev_backend_set_firewire_id (ItdbBackend *itdb_backend, const char *fwid)
74 {
75 #ifdef UPODSLEUTH
76 	g_print (LIBGPOD_UDEV_NS"FIREWIRE_ID=%s\n", fwid);
77 #endif
78 	return TRUE;
79 }
80 
81 static gboolean
udev_backend_set_serial_number(ItdbBackend * itdb_backend,const char * serial_number)82 udev_backend_set_serial_number (ItdbBackend *itdb_backend, const char *serial_number)
83 {
84 #ifdef UPODSLEUTH
85 	g_print (LIBGPOD_UDEV_NS"SERIAL_NUMBER=%s\n", serial_number);
86 #endif
87 	return TRUE;
88 }
89 
udev_backend_set_firmware_version(ItdbBackend * itdb_backend,const char * firmware_version)90 static gboolean udev_backend_set_firmware_version (ItdbBackend *itdb_backend,
91 						  const char *firmware_version)
92 {
93 #ifdef UPODSLEUTH
94 	g_print (LIBGPOD_UDEV_NS"FIRMWARE_VERSION=%s\n", firmware_version);
95 #endif
96 	return TRUE;
97 }
98 
99 static gboolean
udev_backend_set_model_name(ItdbBackend * itdb_backend,const char * model_name)100 udev_backend_set_model_name (ItdbBackend *itdb_backend, const char *model_name)
101 {
102 #ifdef UPODSLEUTH
103 	g_print (LIBGPOD_UDEV_NS"DEVICE_CLASS=%s\n", model_name);
104 #endif
105 	return TRUE;
106 }
107 
108 static gboolean
udev_backend_set_generation(ItdbBackend * itdb_backend,gdouble generation)109 udev_backend_set_generation (ItdbBackend *itdb_backend, gdouble generation)
110 {
111 #ifdef UPODSLEUTH
112 	g_print (LIBGPOD_UDEV_NS"MODEL_GENERATION=%f\n", generation);
113 #endif
114 	return TRUE;
115 }
116 
117 static gboolean
udev_backend_set_color(ItdbBackend * itdb_backend,const char * color_name)118 udev_backend_set_color (ItdbBackend *itdb_backend, const char *color_name)
119 {
120 #ifdef UPODSLEUTH
121 	g_print (LIBGPOD_UDEV_NS"MODEL_SHELL_COLOR=%s\n", color_name);
122 #endif
123 	return TRUE;
124 }
125 
126 static gboolean
udev_backend_set_factory_id(ItdbBackend * itdb_backend,const char * factory_id)127 udev_backend_set_factory_id (ItdbBackend *itdb_backend,
128 			    const char *factory_id)
129 {
130 #ifdef UPODSLEUTH
131 	g_print (LIBGPOD_UDEV_NS"PRODUCTION_FACTORY_ID=%s\n", factory_id);
132 #endif
133 	return TRUE;
134 }
135 
136 static gboolean
udev_backend_set_production_year(ItdbBackend * itdb_backend,guint year)137 udev_backend_set_production_year (ItdbBackend *itdb_backend, guint year)
138 {
139 #ifdef UPODSLEUTH
140 	g_print (LIBGPOD_UDEV_NS"PRODUCTION_YEAR=%u\n", year);
141 #endif
142 	return TRUE;
143 }
144 
145 static gboolean
udev_backend_set_production_week(ItdbBackend * itdb_backend,guint week)146 udev_backend_set_production_week (ItdbBackend *itdb_backend, guint week)
147 {
148 #ifdef UPODSLEUTH
149 	g_print (LIBGPOD_UDEV_NS"PRODUCTION_WEEK=%u\n", week);
150 #endif
151 	return TRUE;
152 }
153 
154 static gboolean
udev_backend_set_production_index(ItdbBackend * itdb_backend,guint index)155 udev_backend_set_production_index (ItdbBackend *itdb_backend, guint index)
156 {
157 #ifdef UPODSLEUTH
158 	g_print (LIBGPOD_UDEV_NS"PRODUCTION_INDEX=%u\n", index);
159 #endif
160 	return TRUE;
161 }
162 
163 static gboolean
udev_backend_set_control_path(ItdbBackend * itdb_backend,const char * control_path)164 udev_backend_set_control_path (ItdbBackend *itdb_backend, const char *control_path)
165 {
166 #ifdef UPODSLEUTH
167 	g_print (LIBGPOD_UDEV_NS"MODEL_CONTROL_PATH=%s\n", control_path);
168 #endif
169 	return TRUE;
170 }
171 
172 static gboolean
udev_backend_set_name(ItdbBackend * itdb_backend,const char * name)173 udev_backend_set_name (ItdbBackend *itdb_backend, const char *name)
174 {
175 	g_print ("UDISKS_PRESENTATION_NAME=%s\n", name);
176 	return TRUE;
177 }
178 
179 #ifdef UPODSLEUTH
udev_backend_set_artwork_type_supported(ItdbBackend * itdb_backend,enum ArtworkType type,gboolean supported)180 static gboolean udev_backend_set_artwork_type_supported (ItdbBackend *itdb_backend,
181 							enum ArtworkType type,
182 							gboolean supported)
183 {
184     	char *propname;
185 	switch (type) {
186 	    case ALBUM:
187 		propname = LIBGPOD_UDEV_NS"IMAGES_ALBUM_ART_SUPPORTED=%d\n";
188 		break;
189 	    case PHOTO:
190 		propname = LIBGPOD_UDEV_NS"IMAGES_PHOTOS_SUPPORTED=%d\n";
191 		break;
192 	    case CHAPTER:
193 		propname = LIBGPOD_UDEV_NS"IMAGES_CHAPTER_IMAGES_SUPPORTED=%d\n";
194 		break;
195 	    default:
196 		g_return_val_if_reached (FALSE);
197 	}
198 	g_print (propname, !!supported);
199 	return TRUE;
200 }
201 #endif
202 
udev_backend_set_artwork_formats(ItdbBackend * itdb_backend,enum ArtworkType type,const GList * formats)203 static gboolean udev_backend_set_artwork_formats (ItdbBackend *itdb_backend,
204 						 enum ArtworkType type,
205 						 const GList *formats)
206 {
207 #ifdef UPODSLEUTH
208 	udev_backend_set_artwork_type_supported (itdb_backend, type,
209 					       	(formats != NULL));
210 #endif
211 
212 	return TRUE;
213 }
214 
udev_backend_new(void)215 static ItdbBackend *udev_backend_new (void)
216 {
217 	UdevBackend *backend;
218 
219 	backend = g_new0 (UdevBackend, 1);
220 
221 	backend->parent.destroy = udev_backend_destroy;
222 	backend->parent.set_version = udev_backend_set_version;
223 	backend->parent.set_is_unknown = udev_backend_set_is_unknown;
224 	backend->parent.set_icon_name = udev_backend_set_icon_name;
225 	backend->parent.set_firewire_id = udev_backend_set_firewire_id;
226 	backend->parent.set_serial_number = udev_backend_set_serial_number;
227 	backend->parent.set_firmware_version = udev_backend_set_firmware_version;
228 	backend->parent.set_model_name = udev_backend_set_model_name;
229 	backend->parent.set_generation = udev_backend_set_generation;
230 	backend->parent.set_color = udev_backend_set_color;
231 	backend->parent.set_factory_id = udev_backend_set_factory_id;
232 	backend->parent.set_production_year = udev_backend_set_production_year;
233 	backend->parent.set_production_week = udev_backend_set_production_week;
234 	backend->parent.set_production_index = udev_backend_set_production_index;
235 	backend->parent.set_control_path = udev_backend_set_control_path;
236 	backend->parent.set_name = udev_backend_set_name;
237 	backend->parent.set_artwork_formats = udev_backend_set_artwork_formats;
238 
239 	return (ItdbBackend *)backend;
240 }
241 
main(int argc,char ** argv)242 int main (int argc, char **argv)
243 {
244 	ItdbBackend *backend;
245 	int result;
246 	const char *fstype;
247         gint usb_bus_number;
248         gint usb_dev_number;
249 
250 	if (argc != 4) {
251 		return -1;
252 	}
253 #if !GLIB_CHECK_VERSION(2, 36, 0)
254 	g_type_init ();
255 #endif
256 
257         fstype = g_getenv ("ID_FS_TYPE");
258         if (fstype == NULL) {
259                 return -1;
260         }
261 
262 	backend = udev_backend_new ();
263 	if (backend == NULL) {
264 		return -1;
265 	}
266 
267         usb_bus_number = atoi (argv[2]);
268         usb_dev_number = atoi (argv[3]);
269 
270 	result = itdb_callout_set_ipod_properties (backend, argv[1],
271                                                    usb_bus_number,
272                                                    usb_dev_number,
273                                                    fstype);
274 	backend->destroy (backend);
275 
276 	return result;
277 }
278