foreach_slist (elem, file_list) { GtkTreeIter iter; gchar **path_arr = elem->data; GIcon *icon = NULL; gchar *content_type = g_content_type_guess(path_arr[level], NULL, 0, NULL); if (content_type) { icon = g_content_type_get_icon(content_type); if (icon) { GtkIconInfo *icon_info; icon_info = gtk_icon_theme_lookup_by_gicon(gtk_icon_theme_get_default(), icon, 16, 0); if (!icon_info) { g_object_unref(icon); icon = NULL; } else gtk_icon_info_free(icon_info); } g_free(content_type); } if (patterns_match(header_patterns, path_arr[level])) { if (! icon) icon = g_icon_new_for_string("prjorg-header", NULL); gtk_tree_store_insert_with_values(s_file_store, &iter, parent, 0, FILEVIEW_COLUMN_ICON, icon, FILEVIEW_COLUMN_NAME, path_arr[level], FILEVIEW_COLUMN_COLOR, project ? NULL : &s_external_color, -1); } else if (patterns_match(source_patterns, path_arr[level])) { if (! icon) icon = g_icon_new_for_string("prjorg-source", NULL); gtk_tree_store_insert_with_values(s_file_store, &iter, parent, 0, FILEVIEW_COLUMN_ICON, icon, FILEVIEW_COLUMN_NAME, path_arr[level], FILEVIEW_COLUMN_COLOR, project ? NULL : &s_external_color, -1); } else { if (! icon) icon = g_icon_new_for_string("prjorg-file", NULL); gtk_tree_store_insert_with_values(s_file_store, &iter, parent, 0, FILEVIEW_COLUMN_ICON, icon, FILEVIEW_COLUMN_NAME, path_arr[level], FILEVIEW_COLUMN_COLOR, project ? NULL : &s_external_color, -1); } if (icon) g_object_unref(icon); }
QImage imageForIconString(const QString& name, int size, GtkIconTheme* theme) { if (!theme) { theme = gtk_icon_theme_get_default(); } QByteArray utf8Name = name.toUtf8(); /* Load the icon by creating a GIcon from the string icon_name. icon_name can contain more than a simple icon name but possibly a string as returned by g_icon_to_string(). */ GObjectScopedPointer<GIcon> icon(g_icon_new_for_string(utf8Name.data(), NULL)); GScopedPointer<GtkIconInfo, gtk_icon_info_free> iconInfo; iconInfo.reset(gtk_icon_theme_lookup_by_gicon( theme, icon.data(), size, (GtkIconLookupFlags)0) ); if (!iconInfo) { UQ_WARNING << "Failed to find icon:" << name; return QImage(); } GObjectScopedPointer<GdkPixbuf> pixbuf(gtk_icon_info_load_icon(iconInfo.data(), NULL)); if (!pixbuf) { UQ_WARNING << "Failed to load icon:" << name; return QImage(); } return imageForPixbuf(pixbuf.data(), name); }
static void set_icon(AnacondaDiskOverview *widget, const char *icon_name) { GError *err = NULL; GIcon *base_icon, *emblem_icon, *icon; GEmblem *emblem = NULL; gchar *file; if (!icon_name) return; if (widget->priv->kind_icon) gtk_widget_destroy(widget->priv->kind_icon); if (widget->priv->chosen) { base_icon = g_icon_new_for_string(icon_name, &err); if (!base_icon) { fprintf(stderr, "could not create icon: %s\n", err->message); g_error_free(err); return; } file = g_strdup_printf("%s/pixmaps/anaconda-selected-icon.svg", get_widgets_datadir()); emblem_icon = g_icon_new_for_string(file, &err); g_free(file); if (!emblem_icon) { fprintf(stderr, "could not create emblem: %s\n", err->message); g_error_free(err); } else { emblem = g_emblem_new(emblem_icon); } icon = g_emblemed_icon_new(base_icon, emblem); g_object_unref(base_icon); } else { icon = g_icon_new_for_string(icon_name, &err); if (!icon) { fprintf(stderr, "could not create icon: %s\n", err->message); g_error_free(err); return; } } widget->priv->kind_icon = gtk_image_new_from_gicon(icon, GTK_ICON_SIZE_DIALOG); gtk_image_set_pixel_size(GTK_IMAGE(widget->priv->kind_icon), ICON_SIZE); }
void QMessagingMenuSource::setIcon(const QString &icon) { auto gicon = !icon.isEmpty() ? g_icon_new_for_string(icon.toUtf8().data(), nullptr) : nullptr; messaging_menu_app_set_source_icon(m_menuApp->app(), m_id.toUtf8().data(), gicon); if (gicon) g_object_unref(gicon); }
static VALUE icon_new_for_string(UNUSED(VALUE self), VALUE string) { GError *error = NULL; GIcon *icon = g_icon_new_for_string(RVAL2CSTR(string), &error); if (icon == NULL) rbgio_raise_io_error(error); return GOBJ2RVAL(icon); }
/*! \param toolbar object add to it \param name name of the action and also display it in tooltip \param icon_path Address of the icon (It can be NULL) */ GtkAction* ijadi_gui_create_action (GtkWidget *toolbar,const gchar *name, const gchar *icon_path) { GIcon *icon = g_icon_new_for_string (icon_path,NULL); GtkAction *action = gtk_action_new(name, name,name,NULL); gtk_action_set_gicon (action,icon); GtkWidget *toolItem = gtk_action_create_tool_item(action); gtk_toolbar_insert (GTK_TOOLBAR(toolbar),GTK_TOOL_ITEM(toolItem),-1); return action; }
QMessagingMenuSource::QMessagingMenuSource(const QString &id, const QString &label, const QString &icon, int count, QMessagingMenuApp *menuApp) : QObject{menuApp}, m_menuApp{menuApp}, m_id{id} { Q_ASSERT(m_menuApp); Q_UNUSED(icon); auto gicon = !icon.isEmpty() ? g_icon_new_for_string(icon.toUtf8().data(), nullptr) : nullptr; messaging_menu_app_append_source_with_count(m_menuApp->app(), m_id.toUtf8().data(), gicon, label.toUtf8().data(), count); if (gicon) g_object_unref(gicon); }
static void thunar_uca_editor_set_icon_name (ThunarUcaEditor *uca_editor, const gchar *icon_name) { GIcon *icon = NULL; GtkWidget *image; GtkWidget *label; g_return_if_fail (THUNAR_UCA_IS_EDITOR (uca_editor)); /* drop the previous button child */ if (gtk_bin_get_child (GTK_BIN (uca_editor->icon_button)) != NULL) gtk_widget_destroy (gtk_bin_get_child (GTK_BIN (uca_editor->icon_button))); /* setup the icon button */ if (icon_name != NULL) icon = g_icon_new_for_string (icon_name, NULL); if (G_LIKELY (icon != NULL)) { /* setup an image for the icon */ image = gtk_image_new_from_gicon (icon, GTK_ICON_SIZE_DIALOG); g_object_set (image, "icon-size", GTK_ICON_SIZE_DND, NULL); gtk_container_add (GTK_CONTAINER (uca_editor->icon_button), image); gtk_widget_show (image); /* remember the name for the icon */ g_object_set_data_full (G_OBJECT (uca_editor->icon_button), "thunar-uca-icon-name", g_strdup (icon_name), g_free); /* release the icon */ g_object_unref (G_OBJECT (icon)); } else { /* reset the remembered icon name */ g_object_set_data (G_OBJECT (uca_editor->icon_button), "thunar-uca-icon-name", NULL); /* setup a label to tell that no icon was selected */ label = gtk_label_new (_("No icon")); gtk_container_add (GTK_CONTAINER (uca_editor->icon_button), label); gtk_widget_show (label); } }
GdkPixbuf * iconstore_get_pixbuf (GFileInfo * file_info) { // create new hash table if (pixbuf_hash_table == NULL) { pixbuf_hash_table = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_object_unref); } GIcon *icon = NULL; gboolean icon_needs_free = FALSE; if (file_info) { icon = g_file_info_get_icon (file_info); } else { icon = g_icon_new_for_string ("image-missing", NULL); icon_needs_free = TRUE; } gchar *icon_string = g_icon_to_string (icon); GdkPixbuf *pixbuf = (GdkPixbuf *) g_hash_table_lookup (pixbuf_hash_table, icon_string); if (pixbuf == NULL) { pixbuf = get_themed_icon_pixbuf (G_THEMED_ICON (icon), ICON_SIZE, gtk_icon_theme_get_default ()); g_hash_table_insert (pixbuf_hash_table, g_strdup (icon_string), pixbuf); } if (icon_needs_free) { g_object_unref (icon); } g_free (icon_string); return pixbuf; }
static void set_values (GoaPanelAccountsModel *model, GoaObject *object, GtkTreeIter *iter) { GoaAccount *account; GIcon *icon; gchar *markup; GError *error; account = goa_object_peek_account (object); error = NULL; icon = g_icon_new_for_string (goa_account_get_provider_icon (account), &error); if (icon == NULL) { goa_warning ("Error creating GIcon for account: %s (%s, %d)", error->message, g_quark_to_string (error->domain), error->code); g_error_free (error); } markup = g_strdup_printf ("<b>%s</b>\n<small>%s</small>", goa_account_get_provider_name (account), goa_account_get_presentation_identity (account)); gtk_list_store_set (GTK_LIST_STORE (model), iter, GOA_PANEL_ACCOUNTS_MODEL_COLUMN_SORT_KEY, goa_account_get_id (account), GOA_PANEL_ACCOUNTS_MODEL_COLUMN_OBJECT, object, GOA_PANEL_ACCOUNTS_MODEL_COLUMN_ATTENTION_NEEDED, goa_account_get_attention_needed (account), GOA_PANEL_ACCOUNTS_MODEL_COLUMN_MARKUP, markup, GOA_PANEL_ACCOUNTS_MODEL_COLUMN_ICON, icon, -1); g_free (markup); g_clear_object (&icon); }
GFileInfo * gvfs_file_info_demarshal (char *data, gsize size) { guint32 num_attrs, i; GInputStream *memstream; GDataInputStream *in; GFileInfo *info; char *attr, *str, **strv; GFileAttributeType type; GFileAttributeStatus status; GObject *obj; int objtype; memstream = g_memory_input_stream_new_from_data (data, size, NULL); in = g_data_input_stream_new (memstream); g_object_unref (memstream); info = g_file_info_new (); num_attrs = g_data_input_stream_read_uint32 (in, NULL, NULL); for (i = 0; i < num_attrs; i++) { attr = read_string (in); type = g_data_input_stream_read_byte (in, NULL, NULL); status = g_data_input_stream_read_byte (in, NULL, NULL); switch (type) { case G_FILE_ATTRIBUTE_TYPE_STRING: str = read_string (in); g_file_info_set_attribute_string (info, attr, str); g_free (str); break; case G_FILE_ATTRIBUTE_TYPE_BYTE_STRING: str = read_string (in); g_file_info_set_attribute_byte_string (info, attr, str); g_free (str); break; case G_FILE_ATTRIBUTE_TYPE_STRINGV: strv = read_stringv (in); g_file_info_set_attribute_stringv (info, attr, strv); g_strfreev (strv); break; case G_FILE_ATTRIBUTE_TYPE_BOOLEAN: g_file_info_set_attribute_boolean (info, attr, g_data_input_stream_read_byte (in, NULL, NULL)); break; case G_FILE_ATTRIBUTE_TYPE_UINT32: g_file_info_set_attribute_uint32 (info, attr, g_data_input_stream_read_uint32 (in, NULL, NULL)); break; case G_FILE_ATTRIBUTE_TYPE_INT32: g_file_info_set_attribute_int32 (info, attr, g_data_input_stream_read_int32 (in, NULL, NULL)); break; case G_FILE_ATTRIBUTE_TYPE_UINT64: g_file_info_set_attribute_uint64 (info, attr, g_data_input_stream_read_uint64 (in, NULL, NULL)); break; case G_FILE_ATTRIBUTE_TYPE_INT64: g_file_info_set_attribute_int64 (info, attr, g_data_input_stream_read_int64 (in, NULL, NULL)); break; case G_FILE_ATTRIBUTE_TYPE_OBJECT: objtype = g_data_input_stream_read_byte (in, NULL, NULL); obj = NULL; if (objtype == 1) { char *icon_str; icon_str = read_string (in); obj = (GObject *)g_icon_new_for_string (icon_str, NULL); g_free (icon_str); } else { g_warning ("Unsupported GFileInfo object type %d\n", objtype); g_free (attr); goto out; } g_file_info_set_attribute_object (info, attr, obj); if (obj) g_object_unref (obj); break; case G_FILE_ATTRIBUTE_TYPE_INVALID: break; default: g_warning ("Unsupported GFileInfo attribute type %d\n", type); g_free (attr); goto out; break; } g_file_info_set_attribute_status (info, attr, status); g_free (attr); } out: g_object_unref (in); return info; }