gboolean rb_ipod_helpers_is_ipod (GMount *mount, MPIDDevice *device_info) { GFile *root; gboolean result = FALSE; char **protocols; /* if we have specific information about the device, use it. * otherwise, check if the device has an ipod device directory on it. */ g_object_get (device_info, "access-protocols", &protocols, NULL); if (protocols != NULL && g_strv_length (protocols) > 0) { int i; for (i = 0; protocols[i] != NULL; i++) { if (g_str_equal (protocols[i], "ipod")) { result = TRUE; break; } } } else { root = g_mount_get_root (mount); if (root != NULL) { gchar *device_dir; if (g_file_has_uri_scheme (root, "afc") != FALSE) { gchar *uri; uri = g_file_get_uri (root); /* afc://<40 chars>:stuff */ g_assert (strlen (uri) >= 46); if (uri[6 + 40] == ':' && uri[6 + 40 + 1] != '1') { result = FALSE; } else { result = TRUE; } g_free (uri); } else { gchar *mount_point; mount_point = g_file_get_path (root); if (mount_point != NULL) { device_dir = itdb_get_device_dir (mount_point); if (device_dir != NULL) { result = g_file_test (device_dir, G_FILE_TEST_IS_DIR); g_free (device_dir); } } g_free (mount_point); } g_object_unref (root); } } g_strfreev (protocols); return result; }
/** * Returns true if file @param relFilename is found, readable and nonempty. * Searches in @param mountPoint /iPod_Control/Device/ */ static bool fileFound( const QString &mountPoint, const QString &relFilename ) { gchar *controlDir = itdb_get_device_dir( QFile::encodeName( mountPoint ) ); if( !controlDir ) return false; QString absFilename = QString( "%1/%2" ).arg( QFile::decodeName( controlDir ) ) .arg( relFilename ); g_free( controlDir ); QFileInfo fileInfo( absFilename ); return fileInfo.isReadable() && fileInfo.size() > 0; }