QIcon get_file_icon(const QString& content_type) { static QCache<QString, QIcon> cache; cache.setMaxCost(100); if (cache.contains(content_type)) return QIcon(*(cache.object(content_type))); QByteArray ba = content_type.toLocal8Bit(); GIcon* gicon = g_content_type_get_icon(ba.constData()); QStringList tried_names; if (G_IS_THEMED_ICON(gicon)) { const gchar * const * names = g_themed_icon_get_names(reinterpret_cast<GThemedIcon*>(gicon)); if (names != 0) { int i = 0; while(names[i] != 0) { QString name = QString::fromLocal8Bit(names[i]); QIcon r = QIcon::fromTheme(name); if (r.isNull()) { tried_names << name; } else { cache.insert(content_type, new QIcon(r)); g_object_unref(gicon); return r; } i++; } } else { qDebug() << "get_file_icon: empty or invalid result of g_themed_icon_get_names"; } } else { qDebug() << "get_file_icon: gicon is not themed icon"; } qDebug() << "get_file_icon(" << content_type << "): no valid names" << tried_names << "; returning null icon"; cache.insert(content_type, new QIcon()); g_object_unref(gicon); return QIcon(); }
GdkPixbuf* getPixBuf(char* name) { GFile* file=g_file_new_for_path(name); GFileInfo* file_info=g_file_query_info(file,"standard::*",G_FILE_QUERY_INFO_NONE,NULL,NULL); GIcon* icon=g_file_info_get_icon(file_info); GdkPixbuf* pix=NULL; gchar* path; gchar const* const* names; GFile* icon_file; char* newname; if(G_IS_THEMED_ICON(icon)) { names=g_themed_icon_get_names(G_THEMED_ICON(icon)); pix=gtk_icon_theme_load_icon(gtk_icon_theme_get_default(),*names,16,(GtkIconLookupFlags)(GTK_ICON_LOOKUP_USE_BUILTIN|GTK_ICON_LOOKUP_FORCE_SVG|GTK_ICON_LOOKUP_GENERIC_FALLBACK|GTK_ICON_LOOKUP_FORCE_SIZE),NULL); if(pix==NULL) { asprintf(&newname,"gnome-mime-%s",*names); pix=gtk_icon_theme_load_icon(gtk_icon_theme_get_default(),(const gchar*)newname,16,(GtkIconLookupFlags)(GTK_ICON_LOOKUP_USE_BUILTIN|GTK_ICON_LOOKUP_FORCE_SVG|GTK_ICON_LOOKUP_GENERIC_FALLBACK|GTK_ICON_LOOKUP_FORCE_SIZE),NULL); debugFree(&newname); } } else if(G_IS_FILE_ICON(icon)) { icon_file=g_file_icon_get_file(G_FILE_ICON(icon)); path=g_file_get_path(icon_file); pix=gdk_pixbuf_new_from_file_at_size(path,16,16,NULL); debugFree(&path); g_object_unref(G_OBJECT(icon_file)); } g_object_unref(G_OBJECT(file)); g_object_unref(G_OBJECT(file_info)); return(pix); }
static gboolean ignore_drive (GDrive *drive) { GIcon *icon; if (g_drive_can_eject (drive) == FALSE || g_drive_has_media (drive) == FALSE) { GRL_DEBUG ("%s: Not adding %s as cannot eject or has no media", __FUNCTION__, g_drive_get_name (drive)); return TRUE; } /* Hack to avoid USB devices showing up * https://bugzilla.gnome.org/show_bug.cgi?id=679624 */ icon = g_drive_get_icon (drive); if (icon && G_IS_THEMED_ICON (icon)) { const gchar * const * names; names = g_themed_icon_get_names (G_THEMED_ICON (icon)); if (names && names[0] && !g_str_has_prefix (names[0], "drive-optical")) { g_object_unref (icon); GRL_DEBUG ("%s: Not adding drive %s as is not optical drive", __FUNCTION__, g_drive_get_name (drive)); return TRUE; } } g_clear_object (&icon); return FALSE; }
GdkPixbuf * _g_icon_get_pixbuf (GIcon *icon, int size, GtkIconTheme *theme) { GdkPixbuf *pixbuf; int w, h; if (icon == NULL) return NULL; pixbuf = NULL; if (G_IS_THEMED_ICON (icon)) pixbuf = get_themed_icon_pixbuf (G_THEMED_ICON (icon), size, theme); if (G_IS_FILE_ICON (icon)) pixbuf = get_file_icon_pixbuf (G_FILE_ICON (icon), size); if (pixbuf == NULL) return NULL; w = gdk_pixbuf_get_width (pixbuf); h = gdk_pixbuf_get_height (pixbuf); if (scale_keeping_ratio (&w, &h, size, size, FALSE)) { GdkPixbuf *scaled; scaled = gdk_pixbuf_scale_simple (pixbuf, w, h, GDK_INTERP_BILINEAR); g_object_unref (pixbuf); pixbuf = scaled; } return pixbuf; }
static char * gicon_to_string (GIcon *icon) { GFile *file; const char *const *names; if (G_IS_FILE_ICON (icon)) { file = g_file_icon_get_file (G_FILE_ICON (icon)); if (file) return g_file_get_path (file); } else if (G_IS_THEMED_ICON (icon)) { names = g_themed_icon_get_names (G_THEMED_ICON (icon)); if (names) return g_strdup (names[0]); } else if (G_IS_EMBLEMED_ICON (icon)) { GIcon *base; base = g_emblemed_icon_get_icon (G_EMBLEMED_ICON (icon)); return gicon_to_string (base); } return NULL; }
static GdkPixbuf* get_icon_pixbuf_for_content_type (const char *ctype, size_t size) { GIcon *icon; GdkPixbuf *pixbuf; icon = g_content_type_get_icon (ctype); pixbuf = NULL; /* based on a snippet from http://www.gtkforums.com/about4721.html */ if (G_IS_THEMED_ICON(icon)) { gchar const * const *names; names = g_themed_icon_get_names (G_THEMED_ICON(icon)); pixbuf = gtk_icon_theme_load_icon (gtk_icon_theme_get_default(), *names, size, 0, NULL); } else if (G_IS_FILE_ICON(icon)) { GFile *icon_file; gchar *path; icon_file = g_file_icon_get_file (G_FILE_ICON(icon)); path = g_file_get_path (icon_file); pixbuf = gdk_pixbuf_new_from_file_at_size (path, size, size, NULL); g_free (path); g_object_unref(icon_file); } g_object_unref(icon); return pixbuf; }
static const char * _icon_cache_get_icon_key (GIcon * icon) { const char * key = NULL; if (G_IS_THEMED_ICON (icon)) { char ** icon_names; char * name; g_object_get (icon, "names", &icon_names, NULL); name = g_strjoinv (",", icon_names); key = get_static_string (name); g_free (name); g_strfreev (icon_names); } else if (G_IS_FILE_ICON (icon)) { GFile * file; char * filename; file = g_file_icon_get_file (G_FILE_ICON (icon)); filename = g_file_get_path (file); key = get_static_string (filename); g_free (filename); g_object_unref (file); } return key; }
/* libbalsa_icon_finder: * locate a suitable icon (pixmap graphic) based on 'mime-type' and/or * 'filename', either of which can be NULL. If both arguments are * non-NULL, 'mime-type' has priority. If both are NULL, the default * 'attachment.png' icon will be returned. This function *MUST* * return the complete path to the icon file. */ GdkPixbuf * libbalsa_icon_finder(GtkWidget * widget, const char * mime_type, const LibbalsaVfs * for_file, gchar ** used_type, GtkIconSize size) { const gchar *content_type; GdkPixbuf *pixbuf = NULL; gint width, height; GtkIconTheme *icon_theme; GIcon *icon; if (!gtk_icon_size_lookup(size, &width, &height)) width = 16; if (mime_type) content_type = mime_type; else if (for_file) { content_type = libbalsa_vfs_get_mime_type(for_file); } else content_type = "application/octet-stream"; /* ask GIO for the icon */ if ((icon_theme = gtk_icon_theme_get_default()) == NULL) return NULL; icon = g_content_type_get_icon(content_type); if (icon != NULL) { if (G_IS_THEMED_ICON(icon)) { gint i; GStrv icon_names; g_object_get(G_OBJECT(icon), "names", &icon_names, NULL); if (icon_names != NULL) { for (i = 0; pixbuf == NULL && icon_names[i] != NULL; i++) { pixbuf = gtk_icon_theme_load_icon(icon_theme, icon_names[i], width, GTK_ICON_LOOKUP_FORCE_SIZE, NULL); } g_strfreev(icon_names); } } g_object_unref(icon); } if (pixbuf == NULL) { /* load the default pixbuf */ pixbuf = libbalsa_default_attachment_pixbuf(width); } if (used_type) *used_type = g_strdup(content_type); return pixbuf; }
static void list_drives (GList *drives, int indent) { GList *volumes, *l; int c, i; GDrive *drive; char *name; char **ids; GIcon *icon; for (c = 0, l = drives; l != NULL; l = l->next, c++) { drive = (GDrive *) l->data; name = g_drive_get_name (drive); g_print ("%*sDrive(%d): %s\n", indent, "", c, name); g_free (name); if (mount_list_info) { ids = g_drive_enumerate_identifiers (drive); if (ids && ids[0] != NULL) { g_print ("%*sids:\n", indent+2, ""); for (i = 0; ids[i] != NULL; i++) { char *id = g_drive_get_identifier (drive, ids[i]); g_print ("%*s %s: '%s'\n", indent+2, "", ids[i], id); g_free (id); } } g_strfreev (ids); icon = g_drive_get_icon (drive); if (icon) { if (G_IS_THEMED_ICON (icon)) show_themed_icon_names (G_THEMED_ICON (icon), indent + 2); g_object_unref (icon); } g_print ("%*sis_media_removable=%d\n", indent + 2, "", g_drive_is_media_removable (drive)); g_print ("%*shas_media=%d\n", indent + 2, "", g_drive_has_media (drive)); g_print ("%*sis_media_check_automatic=%d\n", indent + 2, "", g_drive_is_media_check_automatic (drive)); g_print ("%*scan_poll_for_media=%d\n", indent + 2, "", g_drive_can_poll_for_media (drive)); g_print ("%*scan_eject=%d\n", indent + 2, "", g_drive_can_eject (drive)); } volumes = g_drive_get_volumes (drive); list_volumes (volumes, indent + 2, FALSE); g_list_foreach (volumes, (GFunc)g_object_unref, NULL); g_list_free (volumes); } }
static GdkPixbuf * _get_icon_pixbuf (GIcon * icon, int size, GtkIconTheme * theme) { if (icon == NULL) return NULL; if (G_IS_THEMED_ICON (icon)) return get_themed_icon_pixbuf (G_THEMED_ICON (icon), size, theme); if (G_IS_FILE_ICON (icon)) return get_file_icon_pixbuf (G_FILE_ICON (icon), size); return NULL; }
const gchar * st_icon_get_icon_name (StIcon *icon) { StIconPrivate *priv; g_return_val_if_fail (ST_IS_ICON (icon), NULL); priv = icon->priv; if (priv->gicon && G_IS_THEMED_ICON (priv->gicon)) return g_themed_icon_get_names (G_THEMED_ICON (priv->gicon)) [0]; else return NULL; }
static void set_icon(GtkWindow *window, const gchar *uri) { GFile *file; GIcon *icon; GFileInfo *info; GdkScreen *screen; GtkIconTheme *icon_theme; const gchar *icon_name = NULL, *content_type; screen = gtk_widget_get_screen (GTK_WIDGET (window)); icon_theme = gtk_icon_theme_get_for_screen (screen); file = g_file_new_for_uri (uri); info = g_file_query_info (file, G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE, G_FILE_QUERY_INFO_NONE, NULL, NULL); g_object_unref (file); if (! info) return; content_type = g_file_info_get_content_type (info); icon = g_content_type_get_icon (content_type); if (G_IS_THEMED_ICON (icon)) { const gchar * const *names = NULL; names = g_themed_icon_get_names (G_THEMED_ICON (icon)); if (names) { gint i; for (i = 0; names[i]; i++) { if (gtk_icon_theme_has_icon (icon_theme, names[i])) { icon_name = names[i]; break; } } } } if (icon_name) { gtk_window_set_icon_name (window, icon_name); } g_object_unref (icon); }
static GdkPixbuf * render_icon (GIcon *icon, gint icon_size) { GdkPixbuf *pixbuf; GtkIconInfo *info; pixbuf = NULL; if (G_IS_THEMED_ICON (icon)) { gchar const * const *names; info = gtk_icon_theme_lookup_by_gicon (gtk_icon_theme_get_default (), icon, icon_size, 0); if (info) { pixbuf = gtk_icon_info_load_icon (info, NULL); gtk_icon_info_free (info); } if (pixbuf == NULL) { names = g_themed_icon_get_names (G_THEMED_ICON (icon)); pixbuf = gtk_icon_theme_load_icon (gtk_icon_theme_get_default (), *names, icon_size, 0, NULL); } } else if (G_IS_FILE_ICON (icon)) { GFile *icon_file; gchar *path; icon_file = g_file_icon_get_file (G_FILE_ICON (icon)); path = g_file_get_path (icon_file); pixbuf = gdk_pixbuf_new_from_file_at_size (path, icon_size, icon_size, NULL); g_free (path); g_object_unref (G_OBJECT (icon_file)); } return pixbuf; }
/* consumes reference on icon */ static GtkWidget *_gtk_image_new_for_icon(FmIcon *icon, gint size) { GtkWidget * img = gtk_image_new(); ImgData * data = g_new0(ImgData, 1); data->icon = icon; data->size = size; if (img_data_id == 0) img_data_id = g_quark_from_static_string("ImgData"); g_object_set_qdata_full(G_OBJECT(img), img_data_id, data, (GDestroyNotify) img_data_free); _gtk_image_set_from_file_scaled(img, data); if (G_IS_THEMED_ICON(data->icon)) { /* This image is loaded from icon theme. Update the image if the icon theme is changed. */ data->theme_changed_handler = g_signal_connect(gtk_icon_theme_get_default(), "changed", G_CALLBACK(on_theme_changed), img); } return img; }
char * panel_util_get_icon_name_from_g_icon (GIcon *gicon) { const char * const *names; GtkIconTheme *icon_theme; int i; if (!G_IS_THEMED_ICON (gicon)) return NULL; names = g_themed_icon_get_names (G_THEMED_ICON (gicon)); icon_theme = gtk_icon_theme_get_default (); for (i = 0; names[i] != NULL; i++) { if (gtk_icon_theme_has_icon (icon_theme, names[i])) return g_strdup (names[i]); } return NULL; }
static GList * add_drive (GList *media_list, GDrive *drive, GrlOpticalMediaSource *source) { GList *volumes, *i; GIcon *icon; if (g_drive_can_eject (drive) == FALSE || g_drive_has_media (drive) == FALSE) { return media_list; } /* Hack to avoid USB devices showing up * https://bugzilla.gnome.org/show_bug.cgi?id=679624 */ icon = g_drive_get_icon (drive); if (icon && G_IS_THEMED_ICON (icon)) { const gchar * const * names; names = g_themed_icon_get_names (G_THEMED_ICON (icon)); if (names && names[0] && !g_str_has_prefix (names[0], "drive-optical")) { g_object_unref (icon); return media_list; } } g_clear_object (&icon); /* Repeat for all the drive's volumes */ volumes = g_drive_get_volumes (drive); for (i = volumes; i != NULL; i = i->next) { GVolume *volume = i->data; media_list = add_volume (media_list, volume, drive, source); g_object_unref (volume); } g_list_free (volumes); return media_list; }
static gchar *_cd_get_icon_path (GIcon *pIcon) { gchar *cIconPath = NULL; if (G_IS_THEMED_ICON (pIcon)) { const gchar * const *cFileNames = g_themed_icon_get_names (G_THEMED_ICON (pIcon)); //cd_message ("icones possibles : %s\n", g_strjoinv (":", (gchar **) cFileNames)); int i; for (i = 0; cFileNames[i] != NULL && cIconPath == NULL; i ++) { //cd_message (" une icone possible est : %s\n", cFileNames[i]); cIconPath = cairo_dock_search_icon_s_path (cFileNames[i]); //cd_message (" chemin trouve : %s\n", cIconPath); } } else if (G_IS_FILE_ICON (pIcon)) { GFile *pFile = g_file_icon_get_file (G_FILE_ICON (pIcon)); cIconPath = g_file_get_basename (pFile); //cd_message (" file_icon => %s\n", cIconPath); } return cIconPath; }
void ephy_web_application_setup_from_desktop_file (GDesktopAppInfo *desktop_info) { GAppInfo *app_info; const char *wm_class; GIcon *icon; g_assert (G_IS_DESKTOP_APP_INFO (desktop_info)); app_info = G_APP_INFO (desktop_info); g_set_prgname (g_app_info_get_name (app_info)); g_set_application_name (g_app_info_get_display_name (app_info)); icon = g_app_info_get_icon (app_info); if (G_IS_FILE_ICON (icon)) { GFile *file = g_file_icon_get_file (G_FILE_ICON (icon)); char *path = file ? g_file_get_path (file) : NULL; if (path) { gtk_window_set_default_icon_from_file (path, NULL); g_free (path); } g_clear_object (&file); } else if (G_IS_THEMED_ICON (icon)) { const char * const *names = g_themed_icon_get_names (G_THEMED_ICON (icon)); if (names) gtk_window_set_default_icon_name (names[0]); } g_clear_object (&icon); /* We need to re-set this because we have already parsed the * options, which inits GTK+ and sets this as a side effect. */ wm_class = g_desktop_app_info_get_startup_wm_class (desktop_info); if (wm_class) gdk_set_program_class (wm_class); }
static void _gtk_image_set_from_file_scaled(GtkWidget * img, ImgData * data) { if (data->pixbuf != NULL) { g_object_unref(data->pixbuf); data->pixbuf = NULL; } /* if there is a cached hilighted version of this pixbuf, free it */ if (data->hilight != NULL) { g_object_unref(data->hilight); data->hilight = NULL; } if (G_LIKELY(G_IS_THEMED_ICON(data->icon))) data->pixbuf = fm_pixbuf_from_icon_with_fallback(data->icon, data->size, "application-x-executable"); else { char *file = g_icon_to_string(fm_icon_get_gicon(data->icon)); data->pixbuf = gdk_pixbuf_new_from_file_at_scale(file, -1, data->size, TRUE, NULL); g_free(file); } if (data->pixbuf != NULL) { /* Set the pixbuf into the image widget. */ gtk_image_set_from_pixbuf((GtkImage *)img, data->pixbuf); } else { /* No pixbuf available. Set the "missing image" icon. */ gtk_image_set_from_stock(GTK_IMAGE(img), GTK_STOCK_MISSING_IMAGE, GTK_ICON_SIZE_BUTTON); } }
/* Function implementations */ static void fl_parser_start_node_cb (void *user_data, const char *node_name, const char **attr) { ParserData *data; GFileInfo *info; data = (ParserData *) user_data; data->depth++; d(g_print ("%d: %s\n", data->depth, node_name)); if (data->depth > 2) { g_set_error (data->error, G_MARKUP_ERROR, G_MARKUP_ERROR_INVALID_CONTENT, "Don't expect node '%s' as child of 'file', 'folder' or 'parent-folder'", node_name); return; } else if (data->depth == 1) { if (strcmp (node_name, "folder-listing") != 0) { g_set_error (data->error, G_MARKUP_ERROR, G_MARKUP_ERROR_INVALID_CONTENT, "Expected 'folder-listing', got '%s'", node_name); return; } return; } if (strcmp (node_name, "parent-folder") == 0) { /* Just ignore parent-folder items */ return; } info = g_file_info_new (); if (strcmp (node_name, "file") == 0) { g_file_info_set_file_type (info, G_FILE_TYPE_REGULAR); } else if (strcmp (node_name, "folder") == 0) { GIcon *icon; g_file_info_set_file_type (info, G_FILE_TYPE_DIRECTORY); g_file_info_set_content_type (info, "inode/directory"); icon = g_themed_icon_new ("folder"); g_file_info_set_icon (info, icon); g_object_unref (icon); icon = g_themed_icon_new ("folder-symbolic"); g_file_info_set_symbolic_icon (info, icon); g_object_unref (icon); } else { g_set_error (data->error, G_MARKUP_ERROR, G_MARKUP_ERROR_UNKNOWN_ELEMENT, "Unknown element '%s'", node_name); return; } if (!fl_parser_fill_file_info (info, attr)) { d(g_print ("Failed to fill GnomeVFSFileInfo from node '%s'\n", node_name)); g_object_unref (info); return; } if (g_file_info_get_content_type (info) == NULL) { char *mime_type; mime_type = g_content_type_guess (g_file_info_get_name (info), NULL, 0, NULL); g_file_info_set_content_type (info, mime_type); g_free (mime_type); } if (g_file_info_get_content_type (info) == NULL) { g_file_info_set_content_type (info, "application/octet-stream"); } if (g_file_info_get_file_type (info) == G_FILE_TYPE_REGULAR) { GIcon *icon; const char *content_type; content_type = g_file_info_get_content_type (info); icon = g_content_type_get_icon (content_type); if (icon != NULL) { if (G_IS_THEMED_ICON (icon)) g_themed_icon_append_name (G_THEMED_ICON (icon), "text-x-generic"); g_file_info_set_icon (info, icon); g_object_unref (icon); } icon = g_content_type_get_symbolic_icon (content_type); if (icon != NULL) { if (G_IS_THEMED_ICON (icon)) g_themed_icon_append_name (G_THEMED_ICON (icon), "text-x-generic-symbolic"); g_file_info_set_symbolic_icon (info, icon); g_object_unref (icon); } } /* Permissions on folders in OBEX has different semantics than POSIX. * In POSIX, if a folder is not writable, it means that it's content * can't be removed, whereas in OBEX, it just means that the folder * itself can't be removed. Therefore we must set all folders to RWD and * handle the error when it happens. */ if (g_file_info_get_file_type (info) == G_FILE_TYPE_DIRECTORY) { g_file_info_set_attribute_boolean (info, G_FILE_ATTRIBUTE_ACCESS_CAN_READ, TRUE); g_file_info_set_attribute_boolean (info, G_FILE_ATTRIBUTE_ACCESS_CAN_WRITE, TRUE); } data->elements = g_list_prepend (data->elements, info); }
void thunar_notify_unmount (GMount *mount) { const gchar * const *icon_names; NotifyNotification *notification = NULL; const gchar *summary; GFileInfo *info; gboolean read_only = FALSE; GFile *icon_file; GFile *mount_point; GIcon *icon; gchar *icon_name = NULL; gchar *message; gchar *name; g_return_if_fail (G_IS_MOUNT (mount)); if (!thunar_notify_init ()) return; mount_point = g_mount_get_root (mount); info = g_file_query_info (mount_point, G_FILE_ATTRIBUTE_ACCESS_CAN_WRITE, G_FILE_QUERY_INFO_NONE, NULL, NULL); if (info != NULL) { read_only = !g_file_info_get_attribute_boolean (info, G_FILE_ATTRIBUTE_ACCESS_CAN_WRITE); g_object_unref (info); } g_object_unref (mount_point); name = g_mount_get_name (mount); icon = g_mount_get_icon (mount); if (G_IS_THEMED_ICON (icon)) { icon_names = g_themed_icon_get_names (G_THEMED_ICON (icon)); if (icon_names != NULL) icon_name = g_strdup (icon_names[0]); } else if (G_IS_FILE_ICON (icon)) { icon_file = g_file_icon_get_file (G_FILE_ICON (icon)); if (icon_file != NULL) { icon_name = g_file_get_path (icon_file); g_object_unref (icon_file); } } g_object_unref (icon); if (icon_name == NULL) icon_name = g_strdup ("drive-removable-media"); if (read_only) { summary = _("Unmounting device"); message = g_strdup_printf (_("The device \"%s\" is being unmounted by the system. " "Please do not remove the media or disconnect the " "drive"), name); } else { summary = _("Writing data to device"); message = g_strdup_printf (_("There is data that needs to be written to the " "device \"%s\" before it can be removed. Please " "do not remove the media or disconnect the drive"), name); } #ifdef NOTIFY_CHECK_VERSION #if NOTIFY_CHECK_VERSION (0, 7, 0) notification = notify_notification_new (summary, message, icon_name); #else notification = notify_notification_new (summary, message, icon_name, NULL); #endif #else notification = notify_notification_new (summary, message, icon_name, NULL); #endif notify_notification_set_urgency (notification, NOTIFY_URGENCY_CRITICAL); notify_notification_set_timeout (notification, NOTIFY_EXPIRES_NEVER); notify_notification_show (notification, NULL); g_object_set_data_full (G_OBJECT (mount), "thunar-notification", notification, g_object_unref); g_free (message); g_free (icon_name); g_free (name); }
static void list_volumes (GList *volumes, int indent, gboolean only_with_no_drive) { GList *l, *mounts; int c, i; GMount *mount; GVolume *volume; GDrive *drive; char *name; char *uuid; GFile *activation_root; char **ids; GIcon *icon; char *type_name; const gchar *sort_key; for (c = 0, l = volumes; l != NULL; l = l->next, c++) { volume = (GVolume *) l->data; if (only_with_no_drive) { drive = g_volume_get_drive (volume); if (drive != NULL) { g_object_unref (drive); continue; } } name = g_volume_get_name (volume); g_print ("%*sVolume(%d): %s\n", indent, "", c, name); g_free (name); type_name = get_type_name (volume); g_print ("%*sType: %s\n", indent+2, "", type_name); g_free (type_name); if (extra_detail) { ids = g_volume_enumerate_identifiers (volume); if (ids && ids[0] != NULL) { g_print ("%*sids:\n", indent+2, ""); for (i = 0; ids[i] != NULL; i++) { char *id = g_volume_get_identifier (volume, ids[i]); g_print ("%*s %s: '%s'\n", indent+2, "", ids[i], id); g_free (id); } } g_strfreev (ids); uuid = g_volume_get_uuid (volume); if (uuid) g_print ("%*suuid=%s\n", indent + 2, "", uuid); activation_root = g_volume_get_activation_root (volume); if (activation_root) { char *uri; uri = g_file_get_uri (activation_root); g_print ("%*sactivation_root=%s\n", indent + 2, "", uri); g_free (uri); g_object_unref (activation_root); } icon = g_volume_get_icon (volume); if (icon) { if (G_IS_THEMED_ICON (icon)) show_themed_icon_names (G_THEMED_ICON (icon), indent + 2); g_object_unref (icon); } g_print ("%*scan_mount=%d\n", indent + 2, "", g_volume_can_mount (volume)); g_print ("%*scan_eject=%d\n", indent + 2, "", g_volume_can_eject (volume)); g_print ("%*sshould_automount=%d\n", indent + 2, "", g_volume_should_automount (volume)); sort_key = g_volume_get_sort_key (volume); if (sort_key != NULL) g_print ("%*ssort_key=%s\n", indent + 2, "", sort_key); g_free (uuid); } mount = g_volume_get_mount (volume); if (mount) { mounts = g_list_prepend (NULL, mount); list_mounts (mounts, indent + 2, FALSE); g_list_free (mounts); g_object_unref (mount); } } }
static void list_drives (GList *drives, int indent) { GList *volumes, *l; int c, i; GDrive *drive; char *name; char **ids; GIcon *icon; char *type_name; const gchar *sort_key; for (c = 0, l = drives; l != NULL; l = l->next, c++) { drive = (GDrive *) l->data; name = g_drive_get_name (drive); g_print ("%*sDrive(%d): %s\n", indent, "", c, name); g_free (name); type_name = get_type_name (drive); g_print ("%*sType: %s\n", indent+2, "", type_name); g_free (type_name); if (extra_detail) { GEnumValue *enum_value; gpointer klass; ids = g_drive_enumerate_identifiers (drive); if (ids && ids[0] != NULL) { g_print ("%*sids:\n", indent+2, ""); for (i = 0; ids[i] != NULL; i++) { char *id = g_drive_get_identifier (drive, ids[i]); g_print ("%*s %s: '%s'\n", indent+2, "", ids[i], id); g_free (id); } } g_strfreev (ids); icon = g_drive_get_icon (drive); if (icon) { if (G_IS_THEMED_ICON (icon)) show_themed_icon_names (G_THEMED_ICON (icon), indent + 2); g_object_unref (icon); } g_print ("%*sis_media_removable=%d\n", indent + 2, "", g_drive_is_media_removable (drive)); g_print ("%*shas_media=%d\n", indent + 2, "", g_drive_has_media (drive)); g_print ("%*sis_media_check_automatic=%d\n", indent + 2, "", g_drive_is_media_check_automatic (drive)); g_print ("%*scan_poll_for_media=%d\n", indent + 2, "", g_drive_can_poll_for_media (drive)); g_print ("%*scan_eject=%d\n", indent + 2, "", g_drive_can_eject (drive)); g_print ("%*scan_start=%d\n", indent + 2, "", g_drive_can_start (drive)); g_print ("%*scan_stop=%d\n", indent + 2, "", g_drive_can_stop (drive)); enum_value = NULL; klass = g_type_class_ref (G_TYPE_DRIVE_START_STOP_TYPE); if (klass != NULL) { enum_value = g_enum_get_value (klass, g_drive_get_start_stop_type (drive)); g_print ("%*sstart_stop_type=%s\n", indent + 2, "", enum_value != NULL ? enum_value->value_nick : "UNKNOWN"); g_type_class_unref (klass); } sort_key = g_drive_get_sort_key (drive); if (sort_key != NULL) g_print ("%*ssort_key=%s\n", indent + 2, "", sort_key); } volumes = g_drive_get_volumes (drive); list_volumes (volumes, indent + 2, FALSE); g_list_foreach (volumes, (GFunc)g_object_unref, NULL); g_list_free (volumes); } }
static void list_mounts (GList *mounts, int indent, gboolean only_with_no_volume) { GList *l; int c; GMount *mount; GVolume *volume; char *name, *uuid, *uri; GFile *root, *default_location; GIcon *icon; char **x_content_types; char *type_name; const gchar *sort_key; for (c = 0, l = mounts; l != NULL; l = l->next, c++) { mount = (GMount *) l->data; if (only_with_no_volume) { volume = g_mount_get_volume (mount); if (volume != NULL) { g_object_unref (volume); continue; } } name = g_mount_get_name (mount); root = g_mount_get_root (mount); uri = g_file_get_uri (root); g_print ("%*sMount(%d): %s -> %s\n", indent, "", c, name, uri); type_name = get_type_name (mount); g_print ("%*sType: %s\n", indent+2, "", type_name); g_free (type_name); if (extra_detail) { uuid = g_mount_get_uuid (mount); if (uuid) g_print ("%*suuid=%s\n", indent + 2, "", uuid); default_location = g_mount_get_default_location (mount); if (default_location) { char *loc_uri = g_file_get_uri (default_location); g_print ("%*sdefault_location=%s\n", indent + 2, "", loc_uri); g_free (loc_uri); g_object_unref (default_location); } icon = g_mount_get_icon (mount); if (icon) { if (G_IS_THEMED_ICON (icon)) show_themed_icon_names (G_THEMED_ICON (icon), indent + 2); g_object_unref (icon); } x_content_types = g_mount_guess_content_type_sync (mount, FALSE, NULL, NULL); if (x_content_types != NULL && g_strv_length (x_content_types) > 0) { int n; g_print ("%*sx_content_types:", indent + 2, ""); for (n = 0; x_content_types[n] != NULL; n++) g_print (" %s", x_content_types[n]); g_print ("\n"); } g_strfreev (x_content_types); g_print ("%*scan_unmount=%d\n", indent + 2, "", g_mount_can_unmount (mount)); g_print ("%*scan_eject=%d\n", indent + 2, "", g_mount_can_eject (mount)); g_print ("%*sis_shadowed=%d\n", indent + 2, "", g_mount_is_shadowed (mount)); sort_key = g_mount_get_sort_key (mount); if (sort_key != NULL) g_print ("%*ssort_key=%s\n", indent + 2, "", sort_key); g_free (uuid); } g_object_unref (root); g_free (name); g_free (uri); } }
/** * rb_device_source_set_display_details: * @source: a #RBDeviceSource * * Sets the icon and display name for a device-based source. * The details come from the mount and/or volume. This should * be called in the source's constructed method. */ void rb_device_source_set_display_details (RBDeviceSource *source) { GMount *mount = NULL; GVolume *volume = NULL; GIcon *icon = NULL; char *display_name; GdkPixbuf *pixbuf = NULL; if (g_object_class_find_property (G_OBJECT_GET_CLASS (source), "volume")) { g_object_get (source, "volume", &volume, NULL); } if (g_object_class_find_property (G_OBJECT_GET_CLASS (source), "mount")) { g_object_get (source, "mount", &mount, NULL); } /* prefer mount details to volume details, as the nautilus sidebar does */ if (mount != NULL) { mount = g_object_ref (mount); } else if (volume != NULL) { mount = g_volume_get_mount (volume); } else { mount = NULL; } if (mount != NULL) { display_name = g_mount_get_name (mount); icon = g_mount_get_icon (mount); rb_debug ("details from mount: display name = %s, icon = %p", display_name, icon); } else if (volume != NULL) { display_name = g_volume_get_name (volume); icon = g_volume_get_icon (volume); rb_debug ("details from volume: display name = %s, icon = %p", display_name, icon); } else { display_name = g_strdup ("Unknown Device"); icon = g_themed_icon_new ("multimedia-player"); } g_object_set (source, "name", display_name, NULL); g_free (display_name); if (icon == NULL) { rb_debug ("no icon set"); pixbuf = NULL; } else if (G_IS_THEMED_ICON (icon)) { GtkIconTheme *theme; const char * const *names; gint size; int i; theme = gtk_icon_theme_get_default (); gtk_icon_size_lookup (RB_SOURCE_ICON_SIZE, &size, NULL); i = 0; names = g_themed_icon_get_names (G_THEMED_ICON (icon)); while (names[i] != NULL && pixbuf == NULL) { rb_debug ("looking up themed icon: %s", names[i]); pixbuf = gtk_icon_theme_load_icon (theme, names[i], size, 0, NULL); i++; } } else if (G_IS_LOADABLE_ICON (icon)) { rb_debug ("loading of GLoadableIcons is not implemented yet"); pixbuf = NULL; } if (pixbuf != NULL) { g_object_set (source, "pixbuf", pixbuf, NULL); g_object_unref (pixbuf); } if (mount != NULL) { g_object_unref (mount); } if (volume != NULL) { g_object_unref (volume); } if (icon != NULL) { g_object_unref (icon); } }
void GioLister::DeviceInfo::ReadMountInfo(GMount* mount) { // Get basic information this->mount.reset_without_add(mount); if (!mount) return; mount_name = ConvertAndFree(g_mount_get_name(mount)); // Get the icon name(s) mount_icon_names.clear(); GIcon* icon = g_mount_get_icon(mount); if (G_IS_THEMED_ICON(icon)) { const char* const * icons = g_themed_icon_get_names(G_THEMED_ICON(icon)); for (const char* const * p = icons ; *p ; ++p) { mount_icon_names << QString::fromUtf8(*p); } } g_object_unref(icon); GFile* root = g_mount_get_root(mount); // Get the mount path mount_path = ConvertAndFree(g_file_get_path(root)); mount_uri = ConvertAndFree(g_file_get_uri(root)); // Do a sanity check to make sure the root is actually this mount - when a // device is unmounted GIO sends a changed signal before the removed signal, // and we end up reading information about the / filesystem by mistake. GError* error = NULL; GMount* actual_mount = g_file_find_enclosing_mount(root, NULL, &error); if (error || !actual_mount) { g_error_free(error); invalid_enclosing_mount = true; } else if (actual_mount) { g_object_unref(actual_mount); } // Query the filesystem info for size, free space, and type error = NULL; GFileInfo* info = g_file_query_filesystem_info(root, G_FILE_ATTRIBUTE_FILESYSTEM_SIZE "," G_FILE_ATTRIBUTE_FILESYSTEM_FREE "," G_FILE_ATTRIBUTE_FILESYSTEM_TYPE, NULL, &error); if (error) { qLog(Warning) << error->message; g_error_free(error); } else { filesystem_size = g_file_info_get_attribute_uint64( info, G_FILE_ATTRIBUTE_FILESYSTEM_SIZE); filesystem_free = g_file_info_get_attribute_uint64( info, G_FILE_ATTRIBUTE_FILESYSTEM_FREE); filesystem_type = QString::fromUtf8(g_file_info_get_attribute_string( info, G_FILE_ATTRIBUTE_FILESYSTEM_TYPE)); g_object_unref(info); } // Query the file's info for a filesystem ID // Only afc devices (that I know of) give reliably unique IDs if (filesystem_type == "afc") { error = NULL; info = g_file_query_info(root, G_FILE_ATTRIBUTE_ID_FILESYSTEM, G_FILE_QUERY_INFO_NONE, NULL, &error); if (error) { qLog(Warning) << error->message; g_error_free(error); } else { mount_uuid = QString::fromUtf8(g_file_info_get_attribute_string( info, G_FILE_ATTRIBUTE_ID_FILESYSTEM)); g_object_unref(info); } } g_object_unref(root); }
NautilusIconInfo * nautilus_icon_info_lookup (GIcon *icon, int size) { NautilusIconInfo *icon_info; GdkPixbuf *pixbuf; if (G_IS_LOADABLE_ICON (icon)) { LoadableIconKey lookup_key; LoadableIconKey *key; GInputStream *stream; if (loadable_icon_cache == NULL) { loadable_icon_cache = g_hash_table_new_full ((GHashFunc)loadable_icon_key_hash, (GEqualFunc)loadable_icon_key_equal, (GDestroyNotify) loadable_icon_key_free, (GDestroyNotify) g_object_unref); } lookup_key.icon = icon; lookup_key.size = size; icon_info = g_hash_table_lookup (loadable_icon_cache, &lookup_key); if (icon_info) { return g_object_ref (icon_info); } pixbuf = NULL; stream = g_loadable_icon_load (G_LOADABLE_ICON (icon), size, NULL, NULL, NULL); if (stream) { GdkPixbuf *scaled_pixbuf; int w, h, s; double scale; pixbuf = eel_gdk_pixbuf_load_from_stream (stream); g_object_unref (stream); w = gdk_pixbuf_get_width (pixbuf); h = gdk_pixbuf_get_height (pixbuf); s = MAX (w, h); if (size != s) { scale = (double)size / s; scaled_pixbuf = gdk_pixbuf_scale_simple (pixbuf, w * scale, h * scale, GDK_INTERP_BILINEAR); g_object_unref (pixbuf); pixbuf = scaled_pixbuf; } } icon_info = nautilus_icon_info_new_for_pixbuf (pixbuf); key = loadable_icon_key_new (icon, size); g_hash_table_insert (loadable_icon_cache, key, icon_info); return g_object_ref (icon_info); } else if (G_IS_THEMED_ICON (icon)) { const char * const *names; ThemedIconKey lookup_key; ThemedIconKey *key; GtkIconTheme *icon_theme; GtkIconInfo *gtkicon_info; const char *filename; if (themed_icon_cache == NULL) { themed_icon_cache = g_hash_table_new_full ((GHashFunc)themed_icon_key_hash, (GEqualFunc)themed_icon_key_equal, (GDestroyNotify) themed_icon_key_free, (GDestroyNotify) g_object_unref); } names = g_themed_icon_get_names (G_THEMED_ICON (icon)); icon_theme = gtk_icon_theme_get_default (); gtkicon_info = gtk_icon_theme_choose_icon (icon_theme, (const char **)names, size, 0); if (gtkicon_info == NULL) { return nautilus_icon_info_new_for_pixbuf (NULL); } filename = gtk_icon_info_get_filename (gtkicon_info); lookup_key.filename = (char *)filename; lookup_key.size = size; icon_info = g_hash_table_lookup (themed_icon_cache, &lookup_key); if (icon_info) { gtk_icon_info_free (gtkicon_info); return g_object_ref (icon_info); } icon_info = nautilus_icon_info_new_for_icon_info (gtkicon_info); key = themed_icon_key_new (filename, size); g_hash_table_insert (themed_icon_cache, key, icon_info); gtk_icon_info_free (gtkicon_info); return g_object_ref (icon_info); } return nautilus_icon_info_new_for_pixbuf (NULL); }
NautilusIconInfo * nautilus_icon_info_lookup (GIcon *icon, int size) { NautilusIconInfo *icon_info; GdkPixbuf *pixbuf; if (G_IS_LOADABLE_ICON (icon)) { LoadableIconKey lookup_key; LoadableIconKey *key; GInputStream *stream; if (loadable_icon_cache == NULL) { loadable_icon_cache = g_hash_table_new_full ((GHashFunc)loadable_icon_key_hash, (GEqualFunc)loadable_icon_key_equal, (GDestroyNotify) loadable_icon_key_free, (GDestroyNotify) g_object_unref); } lookup_key.icon = icon; lookup_key.size = size; icon_info = g_hash_table_lookup (loadable_icon_cache, &lookup_key); if (icon_info) { return g_object_ref (icon_info); } pixbuf = NULL; stream = g_loadable_icon_load (G_LOADABLE_ICON (icon), size, NULL, NULL, NULL); if (stream) { pixbuf = eel_gdk_pixbuf_load_from_stream_at_size (stream, size); g_object_unref (stream); } icon_info = nautilus_icon_info_new_for_pixbuf (pixbuf); key = loadable_icon_key_new (icon, size); g_hash_table_insert (loadable_icon_cache, key, icon_info); return g_object_ref (icon_info); } else if (G_IS_THEMED_ICON (icon)) { const char * const *names; ThemedIconKey lookup_key; ThemedIconKey *key; GtkIconTheme *icon_theme; GtkIconInfo *gtkicon_info; const char *filename; if (themed_icon_cache == NULL) { themed_icon_cache = g_hash_table_new_full ((GHashFunc)themed_icon_key_hash, (GEqualFunc)themed_icon_key_equal, (GDestroyNotify) themed_icon_key_free, (GDestroyNotify) g_object_unref); } names = g_themed_icon_get_names (G_THEMED_ICON (icon)); icon_theme = gtk_icon_theme_get_default (); gtkicon_info = gtk_icon_theme_choose_icon (icon_theme, (const char **)names, size, 0); if (gtkicon_info == NULL) { return nautilus_icon_info_new_for_pixbuf (NULL); } filename = gtk_icon_info_get_filename (gtkicon_info); lookup_key.filename = (char *)filename; lookup_key.size = size; icon_info = g_hash_table_lookup (themed_icon_cache, &lookup_key); if (icon_info) { gtk_icon_info_free (gtkicon_info); return g_object_ref (icon_info); } icon_info = nautilus_icon_info_new_for_icon_info (gtkicon_info); key = themed_icon_key_new (filename, size); g_hash_table_insert (themed_icon_cache, key, icon_info); gtk_icon_info_free (gtkicon_info); return g_object_ref (icon_info); } else { GdkPixbuf *pixbuf; GtkIconInfo *gtk_icon_info; gtk_icon_info = gtk_icon_theme_lookup_by_gicon (gtk_icon_theme_get_default (), icon, size, GTK_ICON_LOOKUP_GENERIC_FALLBACK); if (gtk_icon_info != NULL) { pixbuf = gtk_icon_info_load_icon (gtk_icon_info, NULL); gtk_icon_info_free (gtk_icon_info); } else { pixbuf = NULL; } return nautilus_icon_info_new_for_pixbuf (pixbuf); } }