JNIEXPORT jintLong JNICALL GNOME_NATIVE(_1gnome_1icon_1theme_1lookup_1icon) (JNIEnv *env, jclass that, jintLong arg0, jintLong arg1, jint arg2, jintLongArray arg3, jintArray arg4) { jintLong *lparg3=NULL; jint *lparg4=NULL; jintLong rc = 0; GNOME_NATIVE_ENTER(env, that, _1gnome_1icon_1theme_1lookup_1icon_FUNC); if (arg3) if ((lparg3 = (*env)->GetIntLongArrayElements(env, arg3, NULL)) == NULL) goto fail; if (arg4) if ((lparg4 = (*env)->GetIntArrayElements(env, arg4, NULL)) == NULL) goto fail; rc = (jintLong)gnome_icon_theme_lookup_icon((GnomeIconTheme *)arg0, (const char *)arg1, arg2, (const GnomeIconData **)lparg3, lparg4); fail: if (arg4 && lparg4) (*env)->ReleaseIntArrayElements(env, arg4, lparg4, 0); if (arg3 && lparg3) (*env)->ReleaseIntLongArrayElements(env, arg3, lparg3, 0); GNOME_NATIVE_EXIT(env, that, _1gnome_1icon_1theme_1lookup_1icon_FUNC); return rc; }
nsresult nsIconChannel::InitWithGnome(nsIMozIconURI *aIconURI) { nsresult rv; if (!gnome_program_get()) { // Get the brandShortName from the string bundle to pass to GNOME // as the application name. This may be used for things such as // the title of grouped windows in the panel. nsCOMPtr<nsIStringBundleService> bundleService = do_GetService(NS_STRINGBUNDLE_CONTRACTID); NS_ASSERTION(bundleService, "String bundle service must be present!"); nsCOMPtr<nsIStringBundle> bundle; bundleService->CreateBundle("chrome://branding/locale/brand.properties", getter_AddRefs(bundle)); nsXPIDLString appName; if (bundle) { bundle->GetStringFromName(NS_LITERAL_STRING("brandShortName").get(), getter_Copies(appName)); } else { NS_WARNING("brand.properties not present, using default application name"); appName.AssignLiteral("Gecko"); } char* empty[] = { "" }; gnome_init(NS_ConvertUTF16toUTF8(appName).get(), "1.0", 1, empty); } nsCAutoString iconSizeString; aIconURI->GetIconSize(iconSizeString); PRUint32 iconSize; if (iconSizeString.IsEmpty()) { rv = aIconURI->GetImageSize(&iconSize); NS_ASSERTION(NS_SUCCEEDED(rv), "GetImageSize failed"); } else { int size; GtkIconSize icon_size = moz_gtk_icon_size(iconSizeString.get()); gtk_icon_size_lookup(icon_size, &size, NULL); iconSize = size; } nsCAutoString type; aIconURI->GetContentType(type); GnomeVFSFileInfo fileInfo = {0}; fileInfo.refcount = 1; // In case some GnomeVFS function addrefs and releases it nsCAutoString spec; nsCOMPtr<nsIURI> fileURI; rv = aIconURI->GetIconFile(getter_AddRefs(fileURI)); if (fileURI) { fileURI->GetAsciiSpec(spec); // Only ask gnome-vfs for a GnomeVFSFileInfo for file: uris, to avoid a // network request PRBool isFile; if (NS_SUCCEEDED(fileURI->SchemeIs("file", &isFile)) && isFile) { gnome_vfs_get_file_info(spec.get(), &fileInfo, GNOME_VFS_FILE_INFO_DEFAULT); } else { // We have to get a leaf name from our uri... nsCOMPtr<nsIURL> url(do_QueryInterface(fileURI)); if (url) { nsCAutoString name; // The filename we get is UTF-8-compatible, which matches gnome expectations. // See also: http://lists.gnome.org/archives/gnome-vfs-list/2004-March/msg00049.html // "Whenever we can detect the charset used for the URI type we try to // convert it to/from utf8 automatically inside gnome-vfs." // I'll interpret that as "otherwise, this field is random junk". url->GetFileName(name); fileInfo.name = g_strdup(name.get()); } // If this is no nsIURL, nothing we can do really. if (!type.IsEmpty()) { fileInfo.valid_fields = GNOME_VFS_FILE_INFO_FIELDS_MIME_TYPE; fileInfo.mime_type = g_strdup(type.get()); } } } if (type.IsEmpty()) { nsCOMPtr<nsIMIMEService> ms(do_GetService("@mozilla.org/mime;1")); if (ms) { nsCAutoString fileExt; aIconURI->GetFileExtension(fileExt); ms->GetTypeFromExtension(fileExt, type); } } // Get the icon theme if (!gIconTheme) { gIconTheme = gnome_icon_theme_new(); if (!gIconTheme) { gnome_vfs_file_info_clear(&fileInfo); return NS_ERROR_NOT_AVAILABLE; } } char* name = gnome_icon_lookup(gIconTheme, NULL, spec.get(), NULL, &fileInfo, type.get(), GNOME_ICON_LOOKUP_FLAGS_NONE, NULL); gnome_vfs_file_info_clear(&fileInfo); if (!name) { return NS_ERROR_NOT_AVAILABLE; } char* file = gnome_icon_theme_lookup_icon(gIconTheme, name, iconSize, NULL, NULL); g_free(name); if (!file) return NS_ERROR_NOT_AVAILABLE; // Create a GdkPixbuf buffer and scale it GError *err = nsnull; GdkPixbuf* buf = gdk_pixbuf_new_from_file(file, &err); g_free(file); if (!buf) { if (err) g_error_free(err); return NS_ERROR_UNEXPECTED; } GdkPixbuf* scaled = buf; if (gdk_pixbuf_get_width(buf) != iconSize && gdk_pixbuf_get_height(buf) != iconSize) { // scale... scaled = gdk_pixbuf_scale_simple(buf, iconSize, iconSize, GDK_INTERP_BILINEAR); gdk_pixbuf_unref(buf); if (!scaled) return NS_ERROR_OUT_OF_MEMORY; } // XXX Respect icon state rv = moz_gdk_pixbuf_to_channel(scaled, aIconURI, getter_AddRefs(mRealChannel)); gdk_pixbuf_unref(scaled); return rv; }