char * panel_find_icon (GtkIconTheme *icon_theme, const char *icon_name, gint size) { GtkIconInfo *info; char *retval; char *icon_no_extension; if (icon_name == NULL || strcmp (icon_name, "") == 0) return NULL; if (g_path_is_absolute (icon_name)) { if (g_file_test (icon_name, G_FILE_TEST_EXISTS)) { return g_strdup (icon_name); } else { char *basename; basename = g_path_get_basename (icon_name); retval = panel_find_icon (icon_theme, basename, size); g_free (basename); return retval; } } /* This is needed because some .desktop files have an icon name *and* * an extension as icon */ icon_no_extension = panel_xdg_icon_remove_extension (icon_name); info = gtk_icon_theme_lookup_icon (icon_theme, icon_no_extension, size, 0); g_free (icon_no_extension); if (info) { retval = g_strdup (gtk_icon_info_get_filename (info)); #if GTK_CHECK_VERSION (3, 8, 0) g_object_unref (info); #else gtk_icon_info_free (info); #endif } else retval = NULL; return retval; }
static void select_icon (GtkTreeSelection * sel, IconBrowserData * data) { GtkTreeModel *model; GtkTreeIter iter; GtkIconInfo *info; gint *sz, i; gchar *icon, *file; GString *sizes; if (!gtk_tree_selection_get_selected (sel, &model, &iter)) return; gtk_tree_model_get (model, &iter, 1, &icon, -1); gtk_image_set_from_icon_name (GTK_IMAGE (data->image), icon, GTK_ICON_SIZE_DIALOG); sz = gtk_icon_theme_get_icon_sizes (data->theme, icon); info = gtk_icon_theme_lookup_icon (data->theme, icon, sz[0], 0); if (info) file = (gchar *) gtk_icon_info_get_filename (info); else file = NULL; /* create sizes string */ i = 0; sizes = g_string_new (""); while (sz[i]) { if (sz[i] == -1) g_string_append (sizes, _("scalable ")); else g_string_append_printf (sizes, "%dx%d ", sz[i], sz[i]); i++; } /* free memory */ g_free (sz); gtk_label_set_text (GTK_LABEL (data->lname), icon); gtk_label_set_text (GTK_LABEL (data->lsize), sizes->str); gtk_label_set_text (GTK_LABEL (data->lfile), file ? file : _("built-in")); g_string_free (sizes, TRUE); if (info) gtk_icon_info_free (info); }
static char *icon_path(char *to, const char *icon) { if (STR_IS_EMPTY(icon)) { to[0] = 0; return to; } GtkIconInfo* info = gtk_icon_theme_lookup_icon(gtk_icon_theme_get_default(), icon, GTK_ICON_SIZE_SMALL_TOOLBAR, 0); if (info != NULL) { const char *path = gtk_icon_info_get_filename(info); strcpy(to, path); gtk_icon_info_free(info); } else { strcpy(to, icon); } return to; }
static void update_icon (GtkWidget *p, volume_t *vol) { GdkPixbuf *icon; GtkWidget *image; GtkIconTheme* theme; GtkIconInfo* info; int icon_size; theme = panel_get_icon_theme(vol->panel); icon_size = panel_get_icon_size(vol->panel); if (curr_volume <= 0) { info = gtk_icon_theme_lookup_icon( theme, "stock_volume-mute", icon_size, 0 ); } else if (curr_volume > 0 && curr_volume <= 50) { info = gtk_icon_theme_lookup_icon( theme, "stock_volume-min", icon_size, 0 ); } else if (curr_volume > 50 && curr_volume <= 75) { info = gtk_icon_theme_lookup_icon( theme, "stock_volume-med", icon_size, 0 ); } else /* curr_volume > 75 */ { info = gtk_icon_theme_lookup_icon( theme, "stock_volume-max", icon_size, 0 ); } if (info ) { icon = gdk_pixbuf_new_from_file_at_size( gtk_icon_info_get_filename( info ), icon_size, icon_size, NULL ); gtk_icon_info_free( info ); } else { icon = gdk_pixbuf_new_from_xpm_data((const char **) volume_xpm); } if (icon) { if (curr_image) { gtk_widget_destroy(curr_image); curr_image = NULL; } image = gtk_image_new_from_pixbuf(icon); gtk_container_add(GTK_CONTAINER(p), image); curr_image = image; } gtk_widget_show_all(p); return; }
char * matekbd_indicator_config_get_images_file (MatekbdIndicatorConfig * ind_config, MatekbdKeyboardConfig * kbd_config, int group) { char *image_file = NULL; GtkIconInfo *icon_info = NULL; if (!ind_config->show_flags) return NULL; if ((kbd_config->layouts_variants != NULL) && (g_strv_length (kbd_config->layouts_variants) > group)) { char *full_layout_name = kbd_config->layouts_variants[group]; if (full_layout_name != NULL) { char *l, *v; matekbd_keyboard_config_split_items (full_layout_name, &l, &v); if (l != NULL) { /* probably there is something in theme? */ icon_info = gtk_icon_theme_lookup_icon (ind_config->icon_theme, l, 48, 0); } } } /* fallback to the default value */ if (icon_info == NULL) { icon_info = gtk_icon_theme_lookup_icon (ind_config->icon_theme, "stock_dialog-error", 48, 0); } if (icon_info != NULL) { image_file = g_strdup (gtk_icon_info_get_filename (icon_info)); #if GTK_CHECK_VERSION (3, 8, 0) g_object_unref (icon_info); #else gtk_icon_info_free (icon_info); #endif } return image_file; }
static CString getThemeIconFileName(const char* name, int size) { GtkIconInfo* iconInfo = gtk_icon_theme_lookup_icon(gtk_icon_theme_get_default(), name, size, GTK_ICON_LOOKUP_NO_SVG); // Try to fallback on MISSING_IMAGE. if (!iconInfo) iconInfo = gtk_icon_theme_lookup_icon(gtk_icon_theme_get_default(), GTK_STOCK_MISSING_IMAGE, size, GTK_ICON_LOOKUP_NO_SVG); if (iconInfo) { GOwnPtr<GtkIconInfo> info(iconInfo); return CString(gtk_icon_info_get_filename(info.get())); } // No icon was found, this can happen if not GTK theme is set. In // that case an empty Image will be created. return CString(); }
// iconName should be a icon name constraints to the freeedesktop standard. QString DockAppIcon::getThemeIconPath(QString iconName) { QByteArray bytes = iconName.toUtf8(); const char *name = bytes.constData(); GtkIconTheme* theme = gtk_icon_theme_get_default(); GtkIconInfo* info = gtk_icon_theme_lookup_icon(theme, name, 48, GTK_ICON_LOOKUP_GENERIC_FALLBACK); if (info) { char* path = g_strdup(gtk_icon_info_get_filename(info)); #if GTK_MAJOR_VERSION >= 3 g_object_unref(info); #elif GTK_MAJOR_VERSION == 2 gtk_icon_info_free(info); #endif return QString(path); } else { return ""; } }
static GtkWidget * _toolbar_new (OlScrollModule *module) { GtkWidget *toolbar = gtk_hbox_new (FALSE, 0); OlImageButton *button = OL_IMAGE_BUTTON (ol_image_button_new ()); GtkIconTheme *icontheme = gtk_icon_theme_get_default (); GtkIconInfo *info = gtk_icon_theme_lookup_icon (icontheme, OL_STOCK_SCROLL_CLOSE, 16, 0); GdkPixbuf *image = gdk_pixbuf_new_from_file (gtk_icon_info_get_filename (info), NULL); ol_image_button_set_pixbuf (button, image); g_signal_connect (button, "clicked", G_CALLBACK (_close_clicked_cb), module); gtk_container_add (GTK_CONTAINER (toolbar), GTK_WIDGET (button)); gtk_icon_info_free (info); gtk_widget_show_all (toolbar); return toolbar; }
// Get the base64 of the theme icon QString On::getThemeIcon(QString icon) { if (icon.contains("/") && !QFile::exists(icon)) { icon = defaultIcon; /*GtkIconInfo *iconInfo = gtk_icon_theme_lookup_icon(gtk_icon_theme_get_default(), "application-default-icon", 48, (GtkIconLookupFlags)0); icon = gtk_icon_info_get_filename(iconInfo); gtk_icon_info_free(iconInfo);*/ } else if (!icon.contains("/")) { GtkIconInfo *iconInfo = gtk_icon_theme_lookup_icon(gtk_icon_theme_get_default(), icon.toAscii(), iconSize, (GtkIconLookupFlags)0); if (iconInfo == NULL) { iconInfo = gtk_icon_theme_lookup_icon(gtk_icon_theme_get_default(), "application-default-icon", iconSize, (GtkIconLookupFlags)0); } icon = gtk_icon_info_get_filename(iconInfo); gtk_icon_info_free(iconInfo); } QPixmap pixmap = QIcon(icon).pixmap(iconSize, iconSize); QByteArray byteArray; QBuffer buffer(&byteArray); pixmap.save(&buffer, "PNG"); QString iconBase64 = QString::fromLatin1(byteArray.toBase64().data()); return iconBase64; }
wxString wxGTKMimeTypesManagerImpl::GetIconFromMimeType(const wxString& mime) { wxString icon; #if GTK_CHECK_VERSION(2,14,0) if (!wx_is_at_least_gtk2(14)) return icon; wxGtkString type(g_content_type_from_mime_type(mime.utf8_str())); wxGtkObject<GIcon> gicon(g_content_type_get_icon(type)); if ( !gicon ) return icon; GtkIconTheme *theme(gtk_icon_theme_get_default()); if ( !theme ) return icon; // Notice that we can't use wxGtkObject here because a special function // needs to be used for freeing this object prior to GTK+ 3.8. GtkIconInfo* const giconinfo = gtk_icon_theme_lookup_by_gicon ( theme, gicon, 256, GTK_ICON_LOOKUP_NO_SVG ); if ( giconinfo ) { icon = wxString::FromUTF8(gtk_icon_info_get_filename(giconinfo)); wxGCC_WARNING_SUPPRESS(deprecated-declarations) gtk_icon_info_free(giconinfo); wxGCC_WARNING_RESTORE() } #endif // GTK_CHECK_VERSION(2,14,0) return icon; }
static CajaIconInfo * caja_icon_info_new_for_icon_info (GtkIconInfo *icon_info) { CajaIconInfo *icon; GdkPoint *points; gint n_points; const char *filename; char *basename, *p; icon = g_object_new (CAJA_TYPE_ICON_INFO, NULL); icon->pixbuf = gtk_icon_info_load_icon (icon_info, NULL); icon->got_embedded_rect = gtk_icon_info_get_embedded_rect (icon_info, &icon->embedded_rect); if (gtk_icon_info_get_attach_points (icon_info, &points, &n_points)) { icon->n_attach_points = n_points; icon->attach_points = points; } icon->display_name = g_strdup (gtk_icon_info_get_display_name (icon_info)); filename = gtk_icon_info_get_filename (icon_info); if (filename != NULL) { basename = g_path_get_basename (filename); p = strrchr (basename, '.'); if (p) { *p = 0; } icon->icon_name = basename; } return icon; }
static GtkButton * _add_button (OlOsdToolbar *toolbar, const struct ButtonSpec *btn_spec) { OlImageButton *btn = OL_IMAGE_BUTTON (ol_image_button_new ()); GtkIconTheme *icontheme = gtk_icon_theme_get_default (); GtkIconInfo *info = gtk_icon_theme_lookup_icon (icontheme, btn_spec->stock, 16, 0); GdkPixbuf *image = gdk_pixbuf_new_from_file (gtk_icon_info_get_filename (info), NULL); gtk_icon_info_free (info); ol_image_button_set_pixbuf (btn, image); g_signal_connect (btn, "clicked", G_CALLBACK (btn_spec->handler), toolbar); gtk_box_pack_start (GTK_BOX (toolbar->center_box), GTK_WIDGET (btn), FALSE, TRUE, 0); gtk_widget_show (GTK_WIDGET (btn)); return GTK_BUTTON (btn); }
gchar * tpaw_filename_from_icon_name (const gchar *icon_name, GtkIconSize icon_size) { GtkIconTheme *icon_theme; GtkIconInfo *icon_info; gint w, h; gint size = 48; gchar *ret; icon_theme = gtk_icon_theme_get_default (); if (gtk_icon_size_lookup (icon_size, &w, &h)) size = (w + h) / 2; icon_info = gtk_icon_theme_lookup_icon (icon_theme, icon_name, size, 0); if (icon_info == NULL) return NULL; ret = g_strdup (gtk_icon_info_get_filename (icon_info)); gtk_icon_info_free (icon_info); return ret; }
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); } }
static void ntf_libnotify_update (NtfNotification *ntf, Notification *details) { ClutterActor *icon = NULL; g_return_if_fail (store && ntf && details); if (details->summary) ntf_notification_set_summary (ntf, details->summary); if (details->body) ntf_notification_set_body (ntf, details->body); if (details->icon_pixbuf) { GdkPixbuf *pixbuf = details->icon_pixbuf; icon = clutter_texture_new (); clutter_texture_set_from_rgb_data (CLUTTER_TEXTURE (icon), gdk_pixbuf_get_pixels (pixbuf), gdk_pixbuf_get_has_alpha (pixbuf), gdk_pixbuf_get_width (pixbuf), gdk_pixbuf_get_height (pixbuf), gdk_pixbuf_get_rowstride (pixbuf), gdk_pixbuf_get_has_alpha (pixbuf) ? 4 : 3, 0, NULL); } else if (details->icon_name) { GtkIconTheme *theme; GtkIconInfo *info; theme = gtk_icon_theme_get_default (); info = gtk_icon_theme_lookup_icon (theme, details->icon_name, 24, 0); if (info) { icon = clutter_texture_new (); clutter_texture_set_from_file (CLUTTER_TEXTURE(icon), gtk_icon_info_get_filename (info), NULL); gtk_icon_info_free (info); } } if (icon) clutter_actor_set_size (icon, 24.0, 24.0); ntf_notification_set_icon (ntf, icon); if (details->actions) { GList *action; gchar *key, *value; ntf_notification_remove_all_buttons (ntf); for (action = details->actions; action;) { /* * The action list length is * guaranteed to be % 2 and > 0 */ key = action->data; action = g_list_next (action); value = action->data; action = g_list_next (action); if (strcasecmp(key, "default") != 0) { ActionData *data; ClutterActor *button; KeySym keysym = 0; data = g_slice_new0 (ActionData); data->notification = ntf; data->action = g_strdup (key); data->id = details->id; data->store = store; button = mx_button_new (); mx_button_set_label (MX_BUTTON (button), value); g_signal_connect_data (button, "clicked", G_CALLBACK (ntf_libnotify_action_cb), data, (GClosureNotify) free_action_data, 0); /* * Handle the dawati key shortcut protocol */ if (!strncmp (key, DAWATI_KEY_PREFIX, strlen (DAWATI_KEY_PREFIX))) { const char *k = key + strlen (DAWATI_KEY_PREFIX); const char *pfx = strstr (k, "XK_"); char *name; if (pfx) { if (k == pfx) { name = g_strdup (k + 3); } else { name = g_strdup (k); name [pfx - k] = 0; strcat (name, pfx + 3); } keysym = XStringToKeysym (name); if (!keysym) g_warning (G_STRLOC ": no keysym found for %s (%s)", key, name); g_free (name); } else { g_warning (G_STRLOC ": invalid key %s", key); } } ntf_notification_add_button (ntf, button, key, keysym); mx_stylable_set_style_class (MX_STYLABLE (button), "Primary"); } } } ntf_notification_set_urgent (ntf, details->is_urgent); ntf_notification_set_timeout (ntf, details->timeout_ms); }
static EphySpinnerImages * ephy_spinner_images_load (GdkScreen *screen, GtkIconTheme *icon_theme, GtkIconSize icon_size) { EphySpinnerImages *images; GdkPixbuf *icon_pixbuf, *pixbuf; GtkIconInfo *icon_info = NULL; int grid_width, grid_height, x, y, requested_size, size, isw, ish, n; const char *icon; GSList *list = NULL, *l; LOG ("EphySpinnerCacheData loading for screen %p at size %d", screen, icon_size); START_PROFILER ("loading spinner animation") if (!gtk_icon_size_lookup_for_settings (gtk_settings_get_for_screen (screen), icon_size, &isw, &ish)) goto loser; requested_size = MAX (ish, isw); /* Load the animation. The 'rest icon' is the 0th frame */ icon_info = gtk_icon_theme_lookup_icon (icon_theme, SPINNER_ICON_NAME, requested_size, 0); if (icon_info == NULL) { g_warning ("Throbber animation not found"); /* If the icon naming spec compliant name wasn't found, try the old name */ icon_info = gtk_icon_theme_lookup_icon (icon_theme, SPINNER_FALLBACK_ICON_NAME, requested_size, 0); if (icon_info == NULL) { g_warning ("Throbber fallback animation not found either"); goto loser; } } g_assert (icon_info != NULL); size = gtk_icon_info_get_base_size (icon_info); icon = gtk_icon_info_get_filename (icon_info); if (icon == NULL) goto loser; icon_pixbuf = gdk_pixbuf_new_from_file (icon, NULL); gtk_icon_info_free (icon_info); icon_info = NULL; if (icon_pixbuf == NULL) { g_warning ("Could not load the spinner file"); goto loser; } grid_width = gdk_pixbuf_get_width (icon_pixbuf); grid_height = gdk_pixbuf_get_height (icon_pixbuf); n = 0; for (y = 0; y < grid_height; y += size) { for (x = 0; x < grid_width ; x += size) { pixbuf = extract_frame (icon_pixbuf, x, y, size); if (pixbuf) { list = g_slist_prepend (list, pixbuf); ++n; } else { g_warning ("Cannot extract frame (%d, %d) from the grid\n", x, y); } } } g_object_unref (icon_pixbuf); if (list == NULL) goto loser; g_assert (n > 0); if (size > requested_size) { for (l = list; l != NULL; l = l->next) { l->data = scale_to_size (l->data, isw, ish); } } /* Now we've successfully got all the data */ images = g_new (EphySpinnerImages, 1); images->ref_count = 1; images->size = icon_size; images->width = images->height = requested_size; images->n_animation_pixbufs = n; images->animation_pixbufs = g_new (GdkPixbuf *, n); for (l = list; l != NULL; l = l->next) { g_assert (l->data != NULL); images->animation_pixbufs[--n] = l->data; } g_assert (n == 0); g_slist_free (list); STOP_PROFILER ("loading spinner animation") return images; loser: if (icon_info) { gtk_icon_info_free (icon_info); } g_slist_foreach (list, (GFunc) g_object_unref, NULL); STOP_PROFILER ("loading spinner animation") return NULL; }
static VALUE rg_filename(VALUE self) { return CSTR2RVAL(gtk_icon_info_get_filename(_SELF(self))); }
static void ygtk_help_dialog_init (YGtkHelpDialog *dialog) { gtk_container_set_border_width (GTK_CONTAINER (dialog), 6); gtk_window_set_type_hint (GTK_WINDOW (dialog), GDK_WINDOW_TYPE_HINT_DIALOG); gtk_window_set_title (GTK_WINDOW (dialog), _("Help")); GdkPixbuf *icon = gtk_widget_render_icon ( GTK_WIDGET (dialog), GTK_STOCK_HELP, GTK_ICON_SIZE_MENU, NULL); gtk_window_set_icon (GTK_WINDOW (dialog), icon); g_object_unref (G_OBJECT (icon)); gtk_window_set_default_size (GTK_WINDOW (dialog), 500, 450); // help text dialog->help_box = gtk_scrolled_window_new (NULL, NULL); gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (dialog->help_box), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (dialog->help_box), GTK_SHADOW_IN); dialog->help_text = ygtk_html_wrap_new(); gtk_container_add (GTK_CONTAINER (dialog->help_box), dialog->help_text); #if 0 // show a nice background image GtkIconTheme *theme = gtk_icon_theme_get_default(); GtkIconInfo *info = gtk_icon_theme_lookup_icon (theme, HELP_IMG_BG, 192, 0); if (info) { GdkPixbuf *pixbuf = gtk_icon_info_load_icon (info, NULL); if (pixbuf) { const gchar *filename = gtk_icon_info_get_filename (info); GdkPixbuf *transparent = ygutils_setOpacity (pixbuf, 60, FALSE); ygtk_html_wrap_set_background (dialog->help_text, transparent, filename); g_object_unref (pixbuf); g_object_unref (transparent); } gtk_icon_info_free (info); } #endif // bottom part (search entry + close button) dialog->search_entry = gtk_entry_new(); gtk_widget_set_size_request (dialog->search_entry, 140, -1); gtk_entry_set_icon_from_stock (GTK_ENTRY (dialog->search_entry), GTK_ENTRY_ICON_PRIMARY, GTK_STOCK_FIND); gtk_entry_set_icon_activatable (GTK_ENTRY (dialog->search_entry), GTK_ENTRY_ICON_PRIMARY, TRUE); g_signal_connect (G_OBJECT (dialog->search_entry), "icon-press", G_CALLBACK (search_entry_icon_press_cb), dialog); g_signal_connect (G_OBJECT (dialog->search_entry), "changed", G_CALLBACK (search_entry_changed_cb), dialog); g_signal_connect (G_OBJECT (dialog->search_entry), "activate", G_CALLBACK (search_entry_activated_cb), dialog); dialog->close_button = gtk_button_new_from_stock (GTK_STOCK_CLOSE); gtk_widget_set_can_default(dialog->close_button, TRUE); GtkWidget *close_box = gtk_hbutton_box_new(); gtk_container_add (GTK_CONTAINER (close_box), dialog->close_button); char *label_str = ygutils_mapKBAccel (_("&Find:")); GtkWidget *bottom_box, *label = gtk_label_new_with_mnemonic (label_str); g_free (label_str); gtk_misc_set_alignment (GTK_MISC (label), 0, .5); gtk_label_set_mnemonic_widget (GTK_LABEL (label), dialog->search_entry); bottom_box = gtk_hbox_new (FALSE, 2); gtk_box_pack_start (GTK_BOX (bottom_box), label, FALSE, FALSE, 0); gtk_box_pack_start (GTK_BOX (bottom_box), dialog->search_entry, FALSE, FALSE, 0); gtk_box_pack_end (GTK_BOX (bottom_box), close_box, FALSE, FALSE, 0); #ifdef SET_HELP_HISTORY dialog->history_combo = gtk_combo_box_new_text(); GList *cells = gtk_cell_layout_get_cells (GTK_CELL_LAYOUT (dialog->history_combo)); g_object_set (G_OBJECT (cells->data), "ellipsize", PANGO_ELLIPSIZE_END, NULL); g_list_free (cells); #endif // glue it dialog->vbox = gtk_vbox_new (FALSE, 6); #ifdef SET_HELP_HISTORY GtkWidget *hbox = gtk_hbox_new (FALSE, 6); gtk_box_pack_start (GTK_BOX (hbox), gtk_image_new_from_stock (GTK_STOCK_HELP, GTK_ICON_SIZE_BUTTON), FALSE, TRUE, 0); gtk_box_pack_start (GTK_BOX (hbox), dialog->history_combo, TRUE, TRUE, 0); gtk_box_pack_start (GTK_BOX (dialog->vbox), hbox, FALSE, TRUE, 0); #endif gtk_box_pack_start (GTK_BOX (dialog->vbox), dialog->help_box, TRUE, TRUE, 0); gtk_box_pack_start (GTK_BOX (dialog->vbox), bottom_box, FALSE, TRUE, 0); gtk_container_add (GTK_CONTAINER (dialog), dialog->vbox); gtk_widget_show_all (dialog->vbox); g_signal_connect (G_OBJECT (dialog->close_button), "clicked", G_CALLBACK (close_button_clicked_cb), dialog); g_signal_connect (G_OBJECT (dialog), "delete-event", G_CALLBACK (gtk_widget_hide_on_delete), NULL); }
/*! \fn static gboolean on_file_apply(GtkButton *button, CDesktopAppChooser *thisObject) \brief The callback function to retrieve user wanting node-data from the selected node. \param[in] button. The button this callback connects to. \param[in] thisObject. The instance of class CDesktopAppChooser. \return TRUE or FALSE */ static gboolean on_file_apply(GtkButton *button, CDesktopAppChooser *thisObject) { GtkWidget *treeview = NULL; if(!button || !thisObject) return false; /* To get the data of the selected tree node. */ treeview = thisObject->m_GetWidget(APPCHOOSER_GtkTreeView); if(treeview) { GtkTreeIter iter; GtkTreeModel *model =NULL; gpointer value; if(gtk_tree_selection_get_selected( GTK_TREE_SELECTION(thisObject->m_GetWidget(APPCHOOSER_GtkTreeSelection)), &model, &iter)) { gtk_tree_model_get(model, &iter, COLUMN_NODEDATA, &value, -1); if(value) { APP_ITEM_INFO *appInfo = (APP_ITEM_INFO*)value; /* Try to get the context storing selected application item contents. */ if( thisObject->m_GetSelectedAppItem() ) { APP_ITEM_INFO *storeSelected = thisObject->m_GetSelectedAppItem(); /* Clear out old data. */ if(storeSelected->name) g_free(storeSelected->name); if(storeSelected->icon) g_free(storeSelected->icon); if(storeSelected->exec) g_free(storeSelected->exec); if(storeSelected->comment) g_free(storeSelected->comment); if(storeSelected->desktopfile) g_free(storeSelected->desktopfile); /* To set all members to be NULL. */ storeSelected->name = NULL; storeSelected->icon = NULL; storeSelected->exec = NULL; storeSelected->comment = NULL; storeSelected->desktopfile = NULL; /* Store the selected node's data. */ if(appInfo->name) storeSelected->name = (gchar*)g_strdup(appInfo->name); if(appInfo->icon) { gchar *dirName = g_path_get_dirname(appInfo->icon); /* To check if it has path name. */ if( !dirName || (*dirName == '.') ) { GtkIconTheme *theme = gtk_icon_theme_get_default(); GtkIconInfo *info = gtk_icon_theme_lookup_icon( theme, appInfo->icon, IMG_SIZE_SHOW, GTK_ICON_LOOKUP_USE_BUILTIN ); if(G_UNLIKELY(!info)) { /* To search the icon in alternative paths. */ storeSelected->icon = thisObject->m_GetIconFullName(appInfo->icon, IMG_SIZE_SHOW); if(storeSelected->icon == NULL) storeSelected->icon = (gchar*)g_strdup(DEFAULT_ICON); /* If it can not find the icon file name specified in the ".desktop" file. */ } else { if(dirName) g_free(dirName); /* To reset the icon name in full path form. */ g_free(storeSelected->icon); storeSelected->icon = NULL; storeSelected->icon = g_strdup( gtk_icon_info_get_filename(info) ); if(storeSelected->icon) ; else { /* To search the icon in alternative paths. */ storeSelected->icon = thisObject->m_GetIconFullName(appInfo->icon, IMG_SIZE_SHOW); } } } else storeSelected->icon = (gchar*)g_strdup(appInfo->icon); } else storeSelected->icon = (gchar*)g_strdup(DEFAULT_ICON); /* If the icon field in the ".desktop" is empty, set the default icon full name. */ if(appInfo->exec) storeSelected->exec = (gchar*)g_strdup(appInfo->exec); if(appInfo->comment) storeSelected->comment = (gchar*)g_strdup(appInfo->comment); if (appInfo->desktopfile) storeSelected->desktopfile = (gchar*)g_strdup(appInfo->desktopfile); /* To set the flag to be true for that there has one application item has been chosen. */ thisObject->m_SetIsChosen(true); } // end of "if" } // end of "if" else return true; } } /* To deinitialize all member variables and release allocated memory. */ thisObject->m_DeinitValue(); /* To destroy dialog window. */ gtk_widget_destroy( thisObject->m_GetWidget(APPCHOOSER_GtkWindow_Main) ); return true; }
/* Load image from file */ static void _xfdashboard_image_content_load_from_file(XfdashboardImageContent *self) { XfdashboardImageContentPrivate *priv; gchar *lookupFilename; gchar *filename; g_return_if_fail(XFDASHBOARD_IS_IMAGE_CONTENT(self)); priv=self->priv; filename=NULL; /* Check if type of image is valid and all needed parameters are set */ g_return_if_fail(priv->type==XFDASHBOARD_IMAGE_TYPE_FILE); g_return_if_fail(priv->iconName); g_return_if_fail(priv->iconSize>0); /* If path of icon filename is relative build absolute path by prefixing theme path ... */ if(!g_path_is_absolute(priv->iconName)) { XfdashboardTheme *theme; const gchar *themePath; /* Get theme path */ theme=xfdashboard_application_get_theme(); g_object_ref(theme); themePath=xfdashboard_theme_get_path(theme); /* Build absolute path from theme path and given relative path to icon */ lookupFilename=g_build_filename(themePath, priv->iconName, NULL); /* Release allocated resources */ g_object_unref(theme); } /* ... otherwise it is an absolute path already so just copy it */ else lookupFilename=g_strdup(priv->iconName); /* If file does not exists then load fallback icon */ if(!g_file_test(lookupFilename, G_FILE_TEST_EXISTS)) { GtkIconInfo *iconInfo; g_warning(_("Icon file '%s' does not exist - trying fallback icon '%s'"), priv->iconName, priv->missingIconName); iconInfo=gtk_icon_theme_lookup_icon(priv->iconTheme, priv->missingIconName, priv->iconSize, #ifdef USE_GTK_BUILTIN_ICONS GTK_ICON_LOOKUP_USE_BUILTIN); #else 0); #endif if(!iconInfo) { g_error(_("Could not load fallback icon for file '%s'"), priv->iconName); _xfdashboard_image_content_set_empty_image(self); g_free(lookupFilename); return; } /* Check if have to use built-in GdkPixbuf for icon ... */ filename=g_strdup(gtk_icon_info_get_filename(iconInfo)); #ifdef USE_GTK_BUILTIN_ICONS if(!filename) { GdkPixbuf *iconPixbuf; GError *error=NULL; iconPixbuf=gtk_icon_info_get_builtin_pixbuf(iconInfo); if(!clutter_image_set_data(CLUTTER_IMAGE(self), gdk_pixbuf_get_pixels(iconPixbuf), gdk_pixbuf_get_has_alpha(iconPixbuf) ? COGL_PIXEL_FORMAT_RGBA_8888 : COGL_PIXEL_FORMAT_RGB_888, gdk_pixbuf_get_width(iconPixbuf), gdk_pixbuf_get_height(iconPixbuf), gdk_pixbuf_get_rowstride(iconPixbuf), &error)) { g_warning(_("Failed to load image data into content for icon '%s': %s"), priv->iconName, error ? error->message : _("Unknown error")); if(error) { g_error_free(error); error=NULL; } } else g_debug("Loaded fallback icon for file '%s' from built-in pixbuf", priv->iconName); g_object_unref(iconPixbuf); } #endif /* Release allocated resources */ g_object_unref(iconInfo); }
static void add_tile_from_mount (MpdDevicesTile *self, GMount *mount) { MpdDevicesTilePrivate *priv = GET_PRIVATE (self); GFile *file; char *uri; GVolume *volume; char *name = NULL; char **mime_types; GIcon *icon; GtkIconInfo *icon_info; char const *icon_file; ClutterActor *tile; GError *error = NULL; volume = g_mount_get_volume (mount); if (volume) { name = g_volume_get_identifier (volume, G_VOLUME_IDENTIFIER_KIND_LABEL); g_object_unref (volume); } if (!name) { name = g_mount_get_name (mount); } /* Mount point */ file = g_mount_get_root (mount); uri = g_file_get_uri (file); mime_types = g_mount_guess_content_type_sync (mount, false, NULL, &error); for (int i = 0; mime_types && mime_types[i]; i++) { g_debug ("%s", mime_types[i]); } if (error) { g_warning ("%s : %s", G_STRLOC, error->message); g_clear_error (&error); } /* Icon */ icon = g_mount_get_icon (mount); icon_info = gtk_icon_theme_lookup_by_gicon (gtk_icon_theme_get_default (), icon, MPD_STORAGE_DEVICE_TILE_ICON_SIZE, GTK_ICON_LOOKUP_NO_SVG); icon_file = gtk_icon_info_get_filename (icon_info); g_debug ("%s() %s", __FUNCTION__, icon_file); tile = mpd_storage_device_tile_new (name, uri, mime_types ? mime_types[0] : NULL, icon_file); g_signal_connect (tile, "eject", G_CALLBACK (_tile_eject_cb), self); g_signal_connect (tile, "request-hide", G_CALLBACK (_device_tile_request_hide_cb), self); g_signal_connect (tile, "request-show", G_CALLBACK (_device_tile_request_show_cb), self); mx_box_layout_add_actor (MX_BOX_LAYOUT (priv->vbox), tile, 0); g_hash_table_insert (priv->tiles, mount, tile); gtk_icon_info_free (icon_info); g_object_unref (icon); g_strfreev (mime_types); g_free (uri); g_object_unref (file); }
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); }
static void exo_cell_renderer_icon_render (GtkCellRenderer *renderer, GdkWindow *window, GtkWidget *widget, GdkRectangle *background_area, GdkRectangle *cell_area, GdkRectangle *expose_area, GtkCellRendererState flags) { const ExoCellRendererIconPrivate *priv = EXO_CELL_RENDERER_ICON_GET_PRIVATE (renderer); GtkIconSource *icon_source; GtkIconTheme *icon_theme; GdkRectangle icon_area; GdkRectangle draw_area; GtkStateType state; const gchar *filename; GtkIconInfo *icon_info = NULL; GdkPixbuf *icon = NULL; GdkPixbuf *temp; GError *err = NULL; gchar *display_name = NULL; gint *icon_sizes; gint icon_size; gint n; /* verify that we have an icon */ if (G_UNLIKELY (priv->icon == NULL && priv->gicon == NULL)) return; /* icon may be either an image file or a named icon */ if (priv->icon != NULL && g_path_is_absolute (priv->icon)) { /* load the icon via the thumbnail database */ icon = _exo_thumbnail_get_for_file (priv->icon, (priv->size > 128) ? EXO_THUMBNAIL_SIZE_LARGE : EXO_THUMBNAIL_SIZE_NORMAL, &err); } else if (priv->icon != NULL || priv->gicon != NULL) { /* determine the best icon size (GtkIconTheme is somewhat messy scaling up small icons) */ icon_theme = gtk_icon_theme_get_for_screen (gtk_widget_get_screen (widget)); if (priv->icon != NULL) { icon_sizes = gtk_icon_theme_get_icon_sizes (icon_theme, priv->icon); for (icon_size = -1, n = 0; icon_sizes[n] != 0; ++n) { /* we can use any size if scalable, because we load the file directly */ if (icon_sizes[n] == -1) icon_size = priv->size; else if (icon_sizes[n] > icon_size && icon_sizes[n] <= priv->size) icon_size = icon_sizes[n]; } g_free (icon_sizes); /* if we don't know any icon sizes at all, the icon is probably not present */ if (G_UNLIKELY (icon_size < 0)) icon_size = priv->size; /* lookup the icon in the icon theme */ icon_info = gtk_icon_theme_lookup_icon (icon_theme, priv->icon, icon_size, 0); } else if (priv->gicon != NULL) { icon_info = gtk_icon_theme_lookup_by_gicon (icon_theme, priv->gicon, priv->size, GTK_ICON_LOOKUP_USE_BUILTIN); } if (G_UNLIKELY (icon_info == NULL)) return; /* check if we have an SVG icon here */ filename = gtk_icon_info_get_filename (icon_info); if (filename != NULL && g_str_has_suffix (filename, ".svg")) { /* loading SVG icons is terribly slow, so we try to use thumbnail instead, and we use the * real available cell area directly here, because loading thumbnails involves scaling anyway * and this way we need to the thumbnail pixbuf scale only once. */ icon = _exo_thumbnail_get_for_file (filename, (priv->size > 128) ? EXO_THUMBNAIL_SIZE_LARGE : EXO_THUMBNAIL_SIZE_NORMAL, &err); } else { /* regularly load the icon from the theme */ icon = gtk_icon_info_load_icon (icon_info, &err); } gtk_icon_info_free (icon_info); } /* check if we failed */ if (G_UNLIKELY (icon == NULL)) { /* better let the user know whats going on, might be surprising otherwise */ if (G_LIKELY (priv->icon != NULL)) { display_name = g_filename_display_name (priv->icon); } else if (G_UNLIKELY (priv->gicon != NULL && g_object_class_find_property (G_OBJECT_GET_CLASS (priv->gicon), "name"))) { g_object_get (priv->gicon, "name", &display_name, NULL); } if (display_name != NULL) { g_warning ("Failed to load \"%s\": %s", display_name, err->message); g_free (display_name); } g_error_free (err); return; } /* determine the real icon size */ icon_area.width = gdk_pixbuf_get_width (icon); icon_area.height = gdk_pixbuf_get_height (icon); /* scale down the icon on-demand */ if (G_UNLIKELY (icon_area.width > cell_area->width || icon_area.height > cell_area->height)) { /* scale down to fit */ temp = exo_gdk_pixbuf_scale_down (icon, TRUE, cell_area->width, cell_area->height); g_object_unref (G_OBJECT (icon)); icon = temp; /* determine the icon dimensions again */ icon_area.width = gdk_pixbuf_get_width (icon); icon_area.height = gdk_pixbuf_get_height (icon); } icon_area.x = cell_area->x + (cell_area->width - icon_area.width) / 2; icon_area.y = cell_area->y + (cell_area->height - icon_area.height) / 2; /* check whether the icon is affected by the expose event */ if (gdk_rectangle_intersect (expose_area, &icon_area, &draw_area)) { /* colorize the icon if we should follow the selection state */ if ((flags & (GTK_CELL_RENDERER_SELECTED | GTK_CELL_RENDERER_PRELIT)) != 0 && priv->follow_state) { if ((flags & GTK_CELL_RENDERER_SELECTED) != 0) { state = GTK_WIDGET_HAS_FOCUS (widget) ? GTK_STATE_SELECTED : GTK_STATE_ACTIVE; temp = exo_gdk_pixbuf_colorize (icon, &widget->style->base[state]); g_object_unref (G_OBJECT (icon)); icon = temp; } if ((flags & GTK_CELL_RENDERER_PRELIT) != 0) { temp = exo_gdk_pixbuf_spotlight (icon); g_object_unref (G_OBJECT (icon)); icon = temp; } } /* check if we should render an insensitive icon */ if (G_UNLIKELY (GTK_WIDGET_STATE (widget) == GTK_STATE_INSENSITIVE || !renderer->sensitive)) { /* allocate an icon source */ icon_source = gtk_icon_source_new (); gtk_icon_source_set_pixbuf (icon_source, icon); gtk_icon_source_set_size_wildcarded (icon_source, FALSE); gtk_icon_source_set_size (icon_source, GTK_ICON_SIZE_SMALL_TOOLBAR); /* render the insensitive icon */ temp = gtk_style_render_icon (widget->style, icon_source, gtk_widget_get_direction (widget), GTK_STATE_INSENSITIVE, -1, widget, "gtkcellrendererpixbuf"); g_object_unref (G_OBJECT (icon)); icon = temp; /* release the icon source */ gtk_icon_source_free (icon_source); } /* render the invalid parts of the icon */ gdk_draw_pixbuf (window, widget->style->black_gc, icon, draw_area.x - icon_area.x, draw_area.y - icon_area.y, draw_area.x, draw_area.y, draw_area.width, draw_area.height, GDK_RGB_DITHER_NORMAL, 0, 0); } /* release the file's icon */ g_object_unref (G_OBJECT (icon)); }