static GIcon * photos_utils_get_thumbnail_icon (const gchar *uri) { GError *error; GFile *file = NULL; GFile *thumb_file = NULL; GFileInfo *info = NULL; GIcon *icon = NULL; const gchar *thumb_path; file = g_file_new_for_uri (uri); error = NULL; info = g_file_query_info (file, G_FILE_ATTRIBUTE_THUMBNAIL_PATH, G_FILE_QUERY_INFO_NONE, NULL, &error); if (error != NULL) { g_warning ("Unable to fetch thumbnail path for %s: %s", uri, error->message); g_error_free (error); goto out; } thumb_path = g_file_info_get_attribute_byte_string (info, G_FILE_ATTRIBUTE_THUMBNAIL_PATH); thumb_file = g_file_new_for_path (thumb_path); icon = g_file_icon_new (thumb_file); out: g_clear_object (&thumb_file); g_clear_object (&info); g_clear_object (&file); return icon; }
static VALUE fileicon_initialize(VALUE self, VALUE file) { G_INITIALIZE(self, g_file_icon_new(RVAL2GFILE(file))); return Qnil; }
static GIcon * _icon_new_from_name (const gchar *icon_name) { ol_assert_ret (icon_name != NULL, NULL); /* This is taken from gdesktopappinfo.c of GIO */ GIcon *icon = NULL; if (g_path_is_absolute (icon_name)) { GFile *file; file = g_file_new_for_path (icon_name); icon = g_file_icon_new (file); g_object_unref (file); } else { char *p; /* Work around a common mistake in desktop files */ if ((p = strrchr (icon_name, '.')) != NULL && (strcmp (p, ".png") == 0 || strcmp (p, ".xpm") == 0 || strcmp (p, ".svg") == 0)) { gchar *real_name = g_strndup (icon_name, p - icon_name); icon = g_themed_icon_new (real_name); g_free (real_name); } else { icon = g_themed_icon_new (icon_name); } } return icon; }
static GrlVimeoSource * grl_vimeo_source_new (void) { GIcon *icon; GFile *file; GrlVimeoSource *source; const char *tags[] = { "net:internet", NULL }; GRL_DEBUG ("grl_vimeo_source_new"); file = g_file_new_for_uri ("resource:///org/gnome/grilo/plugins/vimeo/channel-vimeo.svg"); icon = g_file_icon_new (file); g_object_unref (file); source = g_object_new (GRL_VIMEO_SOURCE_TYPE, "source-id", SOURCE_ID, "source-name", SOURCE_NAME, "source-desc", SOURCE_DESC, "supported-media", GRL_SUPPORTED_MEDIA_VIDEO, "source-icon", icon, "source-tags", tags, NULL); g_object_unref (icon); return source; }
static GtkWidget * menu_item_for_filename (UmPhotoDialog *um, const char *filename) { GtkWidget *image, *menuitem; GFile *file; GIcon *icon; file = g_file_new_for_path (filename); icon = g_file_icon_new (file); g_object_unref (file); image = gtk_image_new_from_gicon (icon, GTK_ICON_SIZE_DIALOG); g_object_unref (icon); menuitem = gtk_menu_item_new (); gtk_container_add (GTK_CONTAINER (menuitem), image); gtk_widget_show_all (menuitem); g_object_set_data_full (G_OBJECT (menuitem), "filename", g_strdup (filename), (GDestroyNotify) g_free); g_signal_connect (G_OBJECT (menuitem), "activate", G_CALLBACK (stock_icon_selected), um); return menuitem; }
static GrlRaitvSource * grl_raitv_source_new (void) { GIcon *icon; GFile *file; GrlRaitvSource *source; const char *tags[] = { "country:it", "tv", "net:internet", NULL }; file = g_file_new_for_uri ("resource:///org/gnome/grilo/plugins/raitv/channel-rai.svg"); icon = g_file_icon_new (file); g_object_unref (file); source = g_object_new (GRL_TYPE_RAITV_SOURCE, "source-id", SOURCE_ID, "source-name", SOURCE_NAME, "source-desc", SOURCE_DESC, "supported-media", GRL_MEDIA_TYPE_VIDEO, "source-icon", icon, "source-tags", tags, NULL); g_object_unref (icon); return source; }
static GIcon * key_file_get_icon (GKeyFile *key_file) { GIcon *icon = NULL; gchar *icon_name; icon_name = g_key_file_get_locale_string (key_file, DESKTOP_ENTRY_GROUP, "Icon", NULL, NULL); if (!icon_name) return NULL; if (g_path_is_absolute (icon_name)) { GFile *file; file = g_file_new_for_path (icon_name); icon = g_file_icon_new (file); g_object_unref (file); } else { char *p; /* Work around a common mistake in desktop files */ if ((p = strrchr (icon_name, '.')) != NULL && (strcmp (p, ".png") == 0 || strcmp (p, ".xpm") == 0 || strcmp (p, ".svg") == 0)) *p = 0; icon = g_themed_icon_new (icon_name); } g_free (icon_name); return icon; }
static void on_icon_file_located (GObject *source_object, GAsyncResult *res, gpointer user_data) { GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (user_data); GFile *icon_file; GError *error; error = NULL; icon_file = _g_find_file_insensitive_finish (G_FILE (source_object), res, &error); if (icon_file != NULL) { g_simple_async_result_set_op_res_gpointer (simple, g_file_icon_new (icon_file), NULL); g_object_unref (icon_file); } else { g_simple_async_result_set_from_error (simple, error); g_error_free (error); } g_simple_async_result_complete (simple); g_object_unref (simple); }
static GIcon * themed_icon_from_name (const char *iconname) { GIcon *icon; if (!iconname) return NULL; if (g_path_is_absolute (iconname)) { GFile *file; file = g_file_new_for_path (iconname); icon = G_ICON (g_file_icon_new (file)); g_object_unref (file); } else { char *tmp_name, *p; tmp_name = strdup (iconname); /* Work around a common mistake in desktop files */ if ((p = strrchr (tmp_name, '.')) != NULL && (strcmp (p, ".png") == 0 || strcmp (p, ".xpm") == 0 || strcmp (p, ".svg") == 0)) { *p = 0; } icon = g_themed_icon_new (tmp_name); g_free (tmp_name); } return icon; }
GIcon * panel_gicon_from_icon_name (const char *icon_name) { GIcon *icon = NULL; if (icon_name == NULL) { return NULL; } if (g_path_is_absolute(icon_name)) { if (!g_file_test (icon_name, G_FILE_TEST_EXISTS)) { gchar *name = g_path_get_basename (icon_name); icon = g_themed_icon_new (name); g_free (name); } else { GFile *gfile = g_file_new_for_path (icon_name); icon = g_file_icon_new (gfile); g_object_unref (gfile); } } else { gchar *name = panel_xdg_icon_remove_extension (icon_name); icon = g_themed_icon_new (name); g_free (name); } return icon; }
static void add_menu_items(GtkTreeIter* parent_it, MenuCacheDir* dir) { GtkTreeIter it; GSList * l; GIcon* gicon; /* Iterate over all menu items in this directory. */ for (l = menu_cache_dir_get_children(dir); l != NULL; l = l->next) { /* Get the menu item. */ MenuCacheItem* item = MENU_CACHE_ITEM(l->data); switch(menu_cache_item_get_type(item)) { case MENU_CACHE_TYPE_NONE: case MENU_CACHE_TYPE_SEP: break; case MENU_CACHE_TYPE_APP: case MENU_CACHE_TYPE_DIR: if(menu_cache_item_get_icon(item)) { if(g_path_is_absolute(menu_cache_item_get_icon(item))) { GFile* gf = g_file_new_for_path(menu_cache_item_get_icon(item)); gicon = g_file_icon_new(gf); g_object_unref(gf); } else { char* dot = strrchr((char*)menu_cache_item_get_icon(item), '.'); if(dot && (strcmp(dot+1, "png") == 0 || strcmp(dot+1, "svg") == 0 || strcmp(dot+1, "xpm") == 0)) { char* name = g_strndup(menu_cache_item_get_icon(item), dot - menu_cache_item_get_icon(item)); gicon = g_themed_icon_new(name); g_free(name); } else gicon = g_themed_icon_new(menu_cache_item_get_icon(item)); } } else gicon = NULL; gtk_tree_store_append(store, &it, parent_it); gtk_tree_store_set(store, &it, COL_ICON, gicon, COL_TITLE, menu_cache_item_get_name(item), COL_ITEM, item, -1); if(gicon) g_object_unref(gicon); if(menu_cache_item_get_type(item) == MENU_CACHE_TYPE_DIR) add_menu_items(&it, MENU_CACHE_DIR(item)); break; } } }
static void shoes_native_systray_gapp(char *title, char *message, char *path) { GNotification *note; note = g_notification_new (title); g_notification_set_body (note, message); GFile *iconf = g_file_new_for_path (path); GIcon *icon = g_file_icon_new (iconf); g_notification_set_icon(note, icon); //TODO: could get icon from settings shoes_settings *st; Data_Get_Struct(shoes_world->settings, shoes_settings, st); g_application_send_notification (G_APPLICATION(shoes_GtkApp), RSTRING_PTR(st->app_name), note); }
NautilusIconInfo * nautilus_icon_info_lookup_from_path (const char *path, int size) { GFile *icon_file; GIcon *icon; NautilusIconInfo *info; icon_file = g_file_new_for_path (path); icon = g_file_icon_new (icon_file); info = nautilus_icon_info_lookup (icon, size); g_object_unref (icon); g_object_unref (icon_file); return info; }
static GIcon * photos_utils_get_thumbnail_icon (PhotosBaseItem *item) { g_autoptr (GFile) thumb_file = NULL; g_autoptr (GFileInfo) info = NULL; GIcon *icon = NULL; const gchar *thumb_path; const gchar *uri; uri = photos_base_item_get_uri (item); if (uri == NULL || uri[0] == '\0') goto out; { g_autoptr (GError) error = NULL; info = photos_base_item_query_info (item, G_FILE_ATTRIBUTE_THUMBNAIL_PATH, G_FILE_QUERY_INFO_NONE, NULL, &error); if (error != NULL) { g_warning ("Unable to fetch thumbnail path for %s: %s", uri, error->message); goto out; } } thumb_path = g_file_info_get_attribute_byte_string (info, G_FILE_ATTRIBUTE_THUMBNAIL_PATH); if (thumb_path == NULL) goto out; thumb_file = g_file_new_for_path (thumb_path); icon = g_file_icon_new (thumb_file); out: return icon; }
/** * fm_icon_from_name * @name: a name for icon * * Retrives a #FmIcon corresponding to @name from cache inserting new * one if there was no such icon there yet. * * Returns: (transfer full): a #FmIcon object. * * Since: 0.1.0 */ FmIcon* fm_icon_from_name(const char* name) { if(G_LIKELY(name)) { FmIcon* icon; GIcon* gicon; if(g_path_is_absolute(name)) { GFile* gicon_file = g_file_new_for_path(name); gicon = g_file_icon_new(gicon_file); g_object_unref(gicon_file); } else gicon = g_themed_icon_new_with_default_fallbacks(name); if(G_LIKELY(gicon)) { icon = fm_icon_from_gicon(gicon); g_object_unref(gicon); return icon; } } return NULL; }
/** * fm_icon_from_name * @name: a name for icon * * Retrives a #FmIcon corresponding to @name from cache inserting new * one if there was no such icon there yet. * * Returns: (transfer full): a #FmIcon object. * * Since: 0.1.0 */ FmIcon* fm_icon_from_name(const char* name) { if(G_LIKELY(name)) { FmIcon* icon; GIcon* gicon; gchar *dot; if(g_path_is_absolute(name)) { GFile* gicon_file = g_file_new_for_path(name); gicon = g_file_icon_new(gicon_file); g_object_unref(gicon_file); } else if(G_UNLIKELY((dot = strrchr(name, '.')) != NULL && dot > name && (g_ascii_strcasecmp(&dot[1], "png") == 0 || g_ascii_strcasecmp(&dot[1], "svg") == 0 || g_ascii_strcasecmp(&dot[1], "xpm") == 0))) { /* some desktop entries have invalid icon name which contains suffix so let strip the suffix from such invalid name */ dot = g_strndup(name, dot - name); gicon = g_themed_icon_new_with_default_fallbacks(dot); g_free(dot); } else gicon = g_themed_icon_new_with_default_fallbacks(name); if(G_LIKELY(gicon)) { icon = fm_icon_from_gicon(gicon); g_object_unref(gicon); return icon; } } return NULL; }
static GIcon * xfdesktop_regular_file_icon_load_icon(XfdesktopIcon *icon) { XfdesktopRegularFileIcon *regular_icon = XFDESKTOP_REGULAR_FILE_ICON(icon); XfdesktopFileIcon *file_icon = XFDESKTOP_FILE_ICON(icon); GIcon *gicon = NULL; TRACE("entering"); /* Try to load the icon referenced in the .desktop file */ if(xfdesktop_file_utils_is_desktop_file(regular_icon->priv->file_info)) { gicon = xfdesktop_load_icon_from_desktop_file(regular_icon); } else if(g_file_info_get_file_type(regular_icon->priv->file_info) == G_FILE_TYPE_DIRECTORY) { /* Try to load a thumbnail from the standard folder image locations */ gchar *thumbnail_file = NULL; if(regular_icon->priv->show_thumbnails) thumbnail_file = xfdesktop_load_icon_location_from_folder(file_icon); if(thumbnail_file) { /* If there's a folder thumbnail, use it */ regular_icon->priv->thumbnail_file = g_file_new_for_path(thumbnail_file); gicon = g_file_icon_new(regular_icon->priv->thumbnail_file); g_free(thumbnail_file); } } else { /* If we have a thumbnail then they are enabled, use it. */ if(regular_icon->priv->thumbnail_file) { gchar *file = g_file_get_path(regular_icon->priv->file); gchar *mimetype = xfdesktop_get_file_mimetype(file); /* Don't use thumbnails for svg, use the file itself */ if(g_strcmp0(mimetype, "image/svg+xml") == 0) gicon = g_file_icon_new(regular_icon->priv->file); else gicon = g_file_icon_new(regular_icon->priv->thumbnail_file); g_free(mimetype); g_free(file); } } /* If we still don't have an icon, use the default */ if(!G_IS_ICON(gicon)) { gicon = g_file_info_get_icon(regular_icon->priv->file_info); if(G_IS_ICON(gicon)) g_object_ref(gicon); } g_object_set(file_icon, "gicon", gicon, NULL); /* Add any user set emblems */ gicon = xfdesktop_file_icon_add_emblems(file_icon); /* load the read only emblem if necessary */ if(!g_file_info_get_attribute_boolean(regular_icon->priv->file_info, G_FILE_ATTRIBUTE_ACCESS_CAN_WRITE)) { GIcon *themed_icon = g_themed_icon_new(EMBLEM_READONLY); GEmblem *emblem = g_emblem_new(themed_icon); g_emblemed_icon_add_emblem(G_EMBLEMED_ICON(gicon), emblem); g_object_unref(emblem); g_object_unref(themed_icon); } /* load the symlink emblem if necessary */ if(g_file_info_get_attribute_boolean(regular_icon->priv->file_info, G_FILE_ATTRIBUTE_STANDARD_IS_SYMLINK)) { GIcon *themed_icon = g_themed_icon_new(EMBLEM_SYMLINK); GEmblem *emblem = g_emblem_new(themed_icon); g_emblemed_icon_add_emblem(G_EMBLEMED_ICON(gicon), emblem); g_object_unref(emblem); g_object_unref(themed_icon); } return gicon; }
static GIcon * xfdesktop_load_icon_from_desktop_file(XfdesktopRegularFileIcon *regular_icon) { gchar *contents, *icon_name; gsize length; GIcon *gicon = NULL; gchar *p; GKeyFile *key_file; /* try to load the file into memory */ if(!g_file_load_contents(regular_icon->priv->file, NULL, &contents, &length, NULL, NULL)) return NULL; /* allocate a new key file */ key_file = g_key_file_new(); /* try to parse the key file from the contents of the file */ if(!g_key_file_load_from_data(key_file, contents, length, 0, NULL)) { g_free(contents); return NULL; } /* try to determine the custom icon name */ icon_name = g_key_file_get_string(key_file, G_KEY_FILE_DESKTOP_GROUP, G_KEY_FILE_DESKTOP_KEY_ICON, NULL); /* No icon name in the desktop file */ if(icon_name == NULL) { /* free key file and in-memory data */ g_key_file_free(key_file); g_free(contents); return NULL; } /* icon_name is an absolute path, create it as a file icon */ if(g_file_test(icon_name, G_FILE_TEST_IS_REGULAR)) { gicon = g_file_icon_new(g_file_new_for_path(icon_name)); } /* check if the icon theme includes the icon name as-is */ if(gicon == NULL) { if(gtk_icon_theme_has_icon(gtk_icon_theme_get_default(), icon_name)) { /* load it */ gicon = g_themed_icon_new(icon_name); } } /* drop any suffix (e.g. '.png') from themed icons and try to laod that */ if(gicon == NULL) { gchar *tmp_name = NULL; p = strrchr(icon_name, '.'); if(p != NULL) tmp_name = g_strndup(icon_name, p - icon_name); /* check if the icon theme includes the icon name */ if(tmp_name && gtk_icon_theme_has_icon(gtk_icon_theme_get_default(), tmp_name)) { /* load it */ gicon = g_themed_icon_new(tmp_name); } g_free(tmp_name); } /* maybe it points to a file in the pixmaps folder */ if(gicon == NULL) { gchar *filename = g_build_filename("pixmaps", icon_name, NULL); gchar *tmp_name = NULL; if(filename) tmp_name = xfce_resource_lookup(XFCE_RESOURCE_DATA, filename); if(tmp_name) gicon = g_file_icon_new(g_file_new_for_path(tmp_name)); g_free(filename); g_free(tmp_name); } /* free key file and in-memory data */ g_key_file_free(key_file); g_free(contents); g_free(icon_name); return gicon; }
int main (int argc, char **argv) { GtkWidget *window, *grid; GtkWidget *label, *image, *box; GtkIconTheme *theme; GdkPixbuf *pixbuf; GtkIconSet *iconset; GtkIconSource *iconsource; gchar *icon_name = "gnome-terminal"; gchar *anim_filename = NULL; GIcon *icon; GFile *file; gtk_init (&argc, &argv); if (argc > 1) icon_name = argv[1]; if (argc > 2) anim_filename = argv[2]; window = gtk_window_new (GTK_WINDOW_TOPLEVEL); grid = gtk_grid_new (); gtk_container_add (GTK_CONTAINER (window), grid); label = gtk_label_new ("symbolic size"); gtk_grid_attach (GTK_GRID (grid), label, 1, 0, 1, 1); label = gtk_label_new ("fixed size"); gtk_grid_attach (GTK_GRID (grid), label, 2, 0, 1, 1); label = gtk_label_new ("GTK_IMAGE_PIXBUF"); gtk_grid_attach (GTK_GRID (grid), label, 0, 1, 1, 1); theme = gtk_icon_theme_get_default (); pixbuf = gtk_icon_theme_load_icon (theme, icon_name, 48, 0, NULL); image = gtk_image_new_from_pixbuf (pixbuf); box = gtk_event_box_new (); gtk_container_add (GTK_CONTAINER (box), image); gtk_grid_attach (GTK_GRID (grid), box, 2, 1, 1, 1); gtk_drag_source_set (box, GDK_BUTTON1_MASK, NULL, 0, GDK_ACTION_COPY); gtk_drag_source_add_image_targets (box); g_signal_connect (box, "drag_begin", G_CALLBACK (drag_begin), image); g_signal_connect (box, "drag_data_get", G_CALLBACK (drag_data_get), image); gtk_drag_dest_set (box, GTK_DEST_DEFAULT_MOTION | GTK_DEST_DEFAULT_HIGHLIGHT | GTK_DEST_DEFAULT_DROP, NULL, 0, GDK_ACTION_COPY); gtk_drag_dest_add_image_targets (box); g_signal_connect (box, "drag_data_received", G_CALLBACK (drag_data_received), image); label = gtk_label_new ("GTK_IMAGE_STOCK"); gtk_grid_attach (GTK_GRID (grid), label, 0, 2, 1, 1); image = gtk_image_new_from_stock (GTK_STOCK_REDO, GTK_ICON_SIZE_DIALOG); gtk_grid_attach (GTK_GRID (grid), image, 1, 2, 1, 1); label = gtk_label_new ("GTK_IMAGE_ICON_SET"); gtk_grid_attach (GTK_GRID (grid), label, 0, 3, 1, 1); iconsource = gtk_icon_source_new (); gtk_icon_source_set_icon_name (iconsource, icon_name); iconset = gtk_icon_set_new (); gtk_icon_set_add_source (iconset, iconsource); image = gtk_image_new_from_icon_set (iconset, GTK_ICON_SIZE_DIALOG); gtk_grid_attach (GTK_GRID (grid), image, 1, 3, 1, 1); label = gtk_label_new ("GTK_IMAGE_ICON_NAME"); gtk_grid_attach (GTK_GRID (grid), label, 0, 4, 1, 1); image = gtk_image_new_from_icon_name (icon_name, GTK_ICON_SIZE_DIALOG); gtk_grid_attach (GTK_GRID (grid), image, 1, 4, 1, 1); image = gtk_image_new_from_icon_name (icon_name, GTK_ICON_SIZE_DIALOG); gtk_image_set_pixel_size (GTK_IMAGE (image), 30); gtk_grid_attach (GTK_GRID (grid), image, 2, 4, 1, 1); label = gtk_label_new ("GTK_IMAGE_GICON"); gtk_grid_attach (GTK_GRID (grid), label, 0, 5, 1, 1); icon = g_themed_icon_new_with_default_fallbacks ("folder-remote"); image = gtk_image_new_from_gicon (icon, GTK_ICON_SIZE_DIALOG); g_object_unref (icon); gtk_grid_attach (GTK_GRID (grid), image, 1, 5, 1, 1); file = g_file_new_for_path ("apple-red.png"); icon = g_file_icon_new (file); image = gtk_image_new_from_gicon (icon, GTK_ICON_SIZE_DIALOG); g_object_unref (icon); gtk_image_set_pixel_size (GTK_IMAGE (image), 30); gtk_grid_attach (GTK_GRID (grid), image, 2, 5, 1, 1); if (anim_filename) { label = gtk_label_new ("GTK_IMAGE_ANIMATION (from file)"); gtk_grid_attach (GTK_GRID (grid), label, 0, 6, 1, 1); image = gtk_image_new_from_file (anim_filename); gtk_image_set_pixel_size (GTK_IMAGE (image), 30); gtk_grid_attach (GTK_GRID (grid), image, 2, 6, 1, 1); /* produce high load */ g_signal_connect_after (image, "draw", G_CALLBACK (anim_image_draw), NULL); } gtk_widget_show_all (window); gtk_main (); return 0; }
static GIcon * nemo_link_get_link_icon_from_desktop (GKeyFile *key_file) { char *icon_str, *p, *type = NULL; GFile *file; GIcon *icon; /* Look at the Icon: key */ icon_str = g_key_file_get_string (key_file, MAIN_GROUP, "Icon", NULL); /* if it's an absolute path, return a GFileIcon for that path */ if (icon_str != NULL && g_path_is_absolute (icon_str)) { file = g_file_new_for_path (icon_str); icon = g_file_icon_new (file); g_object_unref (file); goto out; } type = g_key_file_get_string (key_file, MAIN_GROUP, "Type", NULL); if (icon_str == NULL) { if (g_strcmp0 (type, "Application") == 0) { icon_str = g_strdup ("application-x-executable"); } else if (g_strcmp0 (type, "FSDevice") == 0) { icon_str = g_strdup ("drive-harddisk"); } else if (g_strcmp0 (type, "Directory") == 0) { icon_str = g_strdup (NEMO_ICON_FOLDER); } else if (g_strcmp0 (type, "Service") == 0 || g_strcmp0 (type, "ServiceType") == 0) { icon_str = g_strdup ("folder-remote"); } else { icon_str = g_strdup ("text-x-preview"); } } else { /* Strip out any extension on non-filename icons. Old desktop files may have this */ p = strchr (icon_str, '.'); /* Only strip known icon extensions */ if ((p != NULL) && ((g_ascii_strcasecmp (p, ".png") == 0) || (g_ascii_strcasecmp (p, ".svn") == 0) || (g_ascii_strcasecmp (p, ".jpg") == 0) || (g_ascii_strcasecmp (p, ".xpm") == 0) || (g_ascii_strcasecmp (p, ".bmp") == 0) || (g_ascii_strcasecmp (p, ".jpeg") == 0))) { *p = 0; } } icon = g_themed_icon_new (icon_str); /* apply a link emblem if it's a link */ if (g_strcmp0 (type, "Link") == 0) { GIcon *emblemed, *emblem_icon; GEmblem *emblem; emblem_icon = g_themed_icon_new ("emblem-symbolic-link"); emblem = g_emblem_new (emblem_icon); emblemed = g_emblemed_icon_new (icon, emblem); g_object_unref (icon); g_object_unref (emblem_icon); g_object_unref (emblem); icon = emblemed; } out: g_free (icon_str); g_free (type); return icon; }
static void bdmv_metadata_thread (GSimpleAsyncResult *result, GObject *object, GCancellable *cancellable) { BLURAY *bd; META_DL *meta; GError *error; GFile *file; char *disc_root; char *icon; char *name; const char *lang; file = G_FILE (object); disc_root = g_file_get_path (file); bd = bd_open (disc_root, NULL); g_free (disc_root); if (bd == NULL) { error = g_error_new_literal (G_IO_ERROR, G_IO_ERROR_FAILED, "Device is not a Blu-Ray disc"); goto error; } lang = get_iso_639_3_for_locale (); if (lang != NULL) bd_set_player_setting_str (bd, BLURAY_PLAYER_SETTING_MENU_LANG, lang); meta = bd_get_meta (bd); if (meta == NULL) { error = g_error_new_literal (G_IO_ERROR, G_IO_ERROR_FAILED, "Device is not a Blu-Ray disc, or has no metadata"); bd_close (bd); goto error; } name = icon = NULL; if (meta != NULL) { if (meta->di_name && *meta->di_name) name = g_strdup (meta->di_name); icon = g_strdup (get_icon (meta)); } /* We're missing either an icon, or the name */ if (!name || !icon) { bd_set_player_setting_str (bd, BLURAY_PLAYER_SETTING_MENU_LANG, "eng"); meta = bd_get_meta (bd); if (meta != NULL && name == NULL && meta->di_name && *meta->di_name) name = meta->di_name; if (meta != NULL && icon == NULL) icon = g_strdup (get_icon (meta)); } /* Set the results */ if (icon != NULL) { char *icon_path; GFile *icon_file; icon_path = g_strdup_printf ("BDMV/META/DL/%s", icon); g_free (icon); icon_file = g_file_resolve_relative_path (file, icon_path); g_free (icon_path); g_simple_async_result_set_op_res_gpointer (result, g_file_icon_new (icon_file), NULL); } else { g_simple_async_result_set_op_res_gpointer (result, NULL, NULL); } if (name != NULL) g_object_set_data_full (G_OBJECT (result), "name", name, g_free); bd_close (bd); return; error: g_simple_async_result_set_from_error (result, error); g_simple_async_result_set_op_res_gpointer (result, NULL, NULL); g_error_free (error); }
static void bjb_empty_results_box_constructed (GObject *object) { BjbEmptyResultsBox *self; BjbEmptyResultsBoxPrivate *priv; GtkStyleContext *context; GtkWidget *labels_grid; gchar *label, *markup; GFile *note_icon_file; GIcon *icon; G_OBJECT_CLASS (bjb_empty_results_box_parent_class)->constructed (object); self = BJB_EMPTY_RESULTS_BOX (object); priv = self->priv; gtk_widget_set_halign (GTK_WIDGET (self), GTK_ALIGN_CENTER); gtk_widget_set_hexpand (GTK_WIDGET (self), TRUE); gtk_widget_set_valign (GTK_WIDGET (self), GTK_ALIGN_CENTER); gtk_widget_set_vexpand (GTK_WIDGET (self), TRUE); gtk_orientable_set_orientation (GTK_ORIENTABLE (self), GTK_ORIENTATION_HORIZONTAL); gtk_grid_set_column_spacing (GTK_GRID (self), 12); context = gtk_widget_get_style_context (GTK_WIDGET (self)); gtk_style_context_add_class (context, "dim-label"); note_icon_file = g_file_new_for_uri ("resource://org/gnome/bijiben/note-symbolic.svg"); icon = g_file_icon_new (note_icon_file); g_object_unref (note_icon_file); priv->image = gtk_image_new_from_gicon (icon, GTK_ICON_SIZE_DIALOG); g_object_unref (icon); gtk_container_add (GTK_CONTAINER (self), priv->image); labels_grid = gtk_grid_new (); gtk_orientable_set_orientation (GTK_ORIENTABLE (labels_grid), GTK_ORIENTATION_VERTICAL); gtk_grid_set_row_spacing (GTK_GRID (labels_grid), 0); gtk_widget_set_valign (labels_grid, GTK_ALIGN_START); gtk_container_add (GTK_CONTAINER (self), labels_grid); label = _("No notes"); markup = g_markup_printf_escaped ("<big><b>%s</b></big>", label); priv->primary_label = gtk_label_new (NULL); gtk_label_set_markup (GTK_LABEL (priv->primary_label), markup); g_free (markup); gtk_widget_set_halign (priv->primary_label, GTK_ALIGN_START); gtk_widget_set_vexpand (priv->primary_label, TRUE); gtk_label_set_use_markup (GTK_LABEL (priv->primary_label), TRUE); gtk_container_add (GTK_CONTAINER (labels_grid), priv->primary_label); self->priv->type = BJB_EMPTY_RESULTS_TYPE; label = ""; self->priv->details_label = GTK_LABEL (gtk_label_new (label)); gtk_label_set_use_markup (GTK_LABEL (self->priv->details_label), TRUE); gtk_widget_set_halign (priv->primary_label, GTK_ALIGN_START); // xalign: 0, // max_width_chars: 24, // wrap: true gtk_container_add (GTK_CONTAINER (labels_grid), GTK_WIDGET (self->priv->details_label)); gtk_widget_set_valign (priv->primary_label, GTK_ALIGN_CENTER); gtk_widget_show_all (GTK_WIDGET (self)); }
static void on_xdg_volume_info_loaded (GObject *source_object, GAsyncResult *res, gpointer user_data) { GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (user_data); GFile *xdg_volume_info_file; gchar *content; gsize content_length; GError *error; GKeyFile *key_file; gchar *name; gchar *icon_name; gchar *icon_file; GIcon *icon; content = NULL; key_file = NULL; name = NULL; icon_name = NULL; icon_file = NULL; xdg_volume_info_file = G_FILE (source_object); error = NULL; if (g_file_load_contents_finish (xdg_volume_info_file, res, &content, &content_length, NULL, &error)) { key_file = g_key_file_new (); if (!g_key_file_load_from_data (key_file, content, content_length, G_KEY_FILE_NONE, &error)) goto out; name = g_key_file_get_locale_string (key_file, VOLUME_INFO_GROUP, "Name", NULL, NULL); icon_name = g_key_file_get_string (key_file, VOLUME_INFO_GROUP, "Icon", NULL); icon_file = g_key_file_get_string (key_file, VOLUME_INFO_GROUP, "IconFile", NULL); icon = NULL; if (icon_file != NULL) { GFile *dir, *f; dir = g_file_get_parent (xdg_volume_info_file); if (dir) { f = g_file_resolve_relative_path (dir, icon_file); if (f) { icon = g_file_icon_new (f); g_object_unref (f); } g_object_unref (dir); } } if (icon == NULL && icon_name != NULL) { icon = g_themed_icon_new (icon_name); g_themed_icon_append_name (G_THEMED_ICON (icon), "drive-removable-media"); g_themed_icon_append_name (G_THEMED_ICON (icon), "drive-removable"); g_themed_icon_append_name (G_THEMED_ICON (icon), "drive"); } g_simple_async_result_set_op_res_gpointer (simple, icon, NULL); g_object_set_data_full (G_OBJECT (simple), "name", name, g_free); name = NULL; /* steals name */ g_simple_async_result_complete_in_idle (simple); g_object_unref (simple); } out: if (key_file != NULL) g_key_file_free (key_file); if (error != NULL) { g_simple_async_result_set_from_error (simple, error); g_simple_async_result_complete_in_idle (simple); g_object_unref (simple); g_error_free (error); } g_free (name); g_free (icon_name); g_free (icon_file); g_free (content); }
/** * cinnamon_util_get_icon_for_uri: * @text_uri: A URI * * Look up the icon that should be associated with a given URI. Handles * various special GNOME-internal cases like x-nautilus-search, etc. * * Return Value: (transfer full): A new #GIcon */ GIcon * cinnamon_util_get_icon_for_uri (const char *text_uri) { const char *name; GFile *file; GFileInfo *info; GIcon *retval; /* Here's what we do: * + check for known file: URI * + x-nautilus-search: URI * + override burn: URI icon * + check if the URI is a mount * + override trash: URI icon for subfolders * + check for application/x-gnome-saved-search mime type and override * icon of the GFile * + use icon of the GFile */ /* this only checks file: URI */ name = cinnamon_util_get_icon_for_uri_known_folders (text_uri); if (name) return g_themed_icon_new (name); if (g_str_has_prefix (text_uri, "x-nautilus-search:")) return g_themed_icon_new ("folder-saved-search"); /* gvfs doesn't give us a nice icon, so overriding */ if (g_str_has_prefix (text_uri, "burn:")) return g_themed_icon_new ("nautilus-cd-burner"); file = g_file_new_for_uri (text_uri); retval = cinnamon_util_get_file_icon_if_mount (file); if (retval) return retval; /* gvfs doesn't give us a nice icon for subfolders of the trash, so * overriding */ if (g_str_has_prefix (text_uri, "trash:")) { GFile *root; root = cinnamon_util_get_gfile_root (file); g_object_unref (file); file = root; } info = g_file_query_info (file, "standard::icon,metadata::custom-icon", G_FILE_QUERY_INFO_NONE, NULL, NULL); g_object_unref (file); if (!info) return g_themed_icon_new ("gtk-file"); const char *custom_icon = g_file_info_get_attribute_string (info, "metadata::custom-icon"); if (custom_icon) { GFile *icon_file = g_file_new_for_uri (custom_icon); retval = g_file_icon_new (icon_file); g_object_unref (icon_file); } if (!retval) { retval = g_file_info_get_icon (info); if (retval) g_object_ref (retval); } g_object_unref (info); if (retval) return retval; return g_themed_icon_new ("gtk-file"); }