Пример #1
0
int
main (int argc,
      char **argv)
{
  GdkPixbuf *pixbuf, *otherpix;
  GtkWidget *image, *image2, *hbox, *vbox, *label, *toplevel;
  GIcon *emblemed;
  GEmblem *emblem;
  gchar *str;

  gtk_init (&argc, &argv);

  pixbuf = gdk_pixbuf_new_from_file ("apple-red.png", NULL);
  toplevel = gtk_window_new (GTK_WINDOW_TOPLEVEL);
  hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 12);
  gtk_container_add (GTK_CONTAINER (toplevel), hbox);

  vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 12);
  gtk_box_pack_start (GTK_BOX (hbox), vbox, FALSE, FALSE, 0);

  image = gtk_image_new_from_gicon (G_ICON (pixbuf), GTK_ICON_SIZE_DIALOG);
  gtk_box_pack_start (GTK_BOX (vbox), image, FALSE, FALSE, 0);

  label = gtk_label_new (NULL);
  str = g_strdup_printf ("Normal icon, hash %u", g_icon_hash (G_ICON (pixbuf)));
  gtk_label_set_label (GTK_LABEL (label), str);
  gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 0);

  otherpix = gdk_pixbuf_new_from_file ("gnome-textfile.png", NULL);
  emblem = g_emblem_new (G_ICON (otherpix));
  emblemed = g_emblemed_icon_new (G_ICON (pixbuf), emblem);

  vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 12);
  gtk_box_pack_start (GTK_BOX (hbox), vbox, FALSE, FALSE, 0);
  
  image2 = gtk_image_new_from_gicon (emblemed, GTK_ICON_SIZE_DIALOG);
  gtk_box_pack_start (GTK_BOX (vbox), image2, FALSE, FALSE, 0);

  label = gtk_label_new (NULL);
  str = g_strdup_printf ("Emblemed icon, hash %u", g_icon_hash (emblemed));
  gtk_label_set_label (GTK_LABEL (label), str);
  gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 0);

  gtk_widget_show_all (toplevel);

  g_signal_connect (toplevel, "delete-event",
		    G_CALLBACK (gtk_main_quit), NULL);

  gtk_main ();

  return 0;
}
Пример #2
0
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);
}
Пример #3
0
static void
nemo_bookmark_set_icon_to_default (NemoBookmark *bookmark)
{
	GIcon *icon, *emblemed_icon, *folder;
	GEmblem *emblem;
	char *uri;

	if (g_file_is_native (bookmark->details->location)) {
		folder = g_themed_icon_new (NEMO_ICON_FOLDER);
	} else {
		uri = nemo_bookmark_get_uri (bookmark);
		if (g_str_has_prefix (uri, EEL_SEARCH_URI)) {
			folder = g_themed_icon_new (NEMO_ICON_FOLDER_SAVED_SEARCH);
		} else {
			folder = g_themed_icon_new (NEMO_ICON_FOLDER_REMOTE);
		}
		g_free (uri);
	}

	if (nemo_bookmark_uri_known_not_to_exist (bookmark)) {
		DEBUG ("%s: file does not exist, add emblem", nemo_bookmark_get_name (bookmark));

		icon = g_themed_icon_new (GTK_STOCK_DIALOG_WARNING);
		emblem = g_emblem_new (icon);

		emblemed_icon = g_emblemed_icon_new (folder, emblem);

		g_object_unref (emblem);
		g_object_unref (icon);
		g_object_unref (folder);

		folder = emblemed_icon;
	}

	DEBUG ("%s: setting icon to default", nemo_bookmark_get_name (bookmark));

	g_object_set (bookmark,
		      "icon", folder,
		      NULL);

	g_object_unref (folder);
}
static GIcon *
source_view_new_remote_deletable_icon (void)
{
	GEmblem *emblem;
	GIcon *emblem_icon;
	GIcon *folder_icon;
	GIcon *icon;

	emblem_icon = g_themed_icon_new ("edit-delete");
	folder_icon = g_themed_icon_new ("folder-remote");

	emblem = g_emblem_new (emblem_icon);
	icon = g_emblemed_icon_new (folder_icon, emblem);
	g_object_unref (emblem);

	g_object_unref (folder_icon);
	g_object_unref (emblem_icon);

	return icon;
}
static void
apply_warning_emblem (GIcon **base,
		      gboolean symbolic)
{
	GIcon *warning, *emblemed_icon;
	GEmblem *emblem;

	if (symbolic) {
		warning = g_themed_icon_new ("dialog-warning-symbolic");
	} else {
		warning = g_themed_icon_new (GTK_STOCK_DIALOG_WARNING);
	}

	emblem = g_emblem_new (warning);
	emblemed_icon = g_emblemed_icon_new (*base, emblem);

	g_object_unref (emblem);
	g_object_unref (warning);
	g_object_unref (*base);

	*base = emblemed_icon;
}
static void
set_tip (GtkWidget  *item,
         const char *tip,
         GEmblem    *emblem)
{
        GList *children;
        GtkWidget *image;
        GIcon *icon, *icon2;

        children = gtk_container_get_children (GTK_CONTAINER (item));
        image = children->data;
        g_assert (image != NULL);
        g_list_free (children);

        gtk_image_get_gicon (GTK_IMAGE (image), &icon, NULL);
        if (G_IS_EMBLEMED_ICON (icon)) {
                return;
        }

        icon2 = g_emblemed_icon_new (icon, emblem);
        gtk_image_set_from_gicon (GTK_IMAGE (image), icon2, GTK_ICON_SIZE_DIALOG);

        gtk_widget_set_tooltip_text (GTK_WIDGET (item), tip);
}
Пример #7
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 NautilusIconInfo *
nautilus_canvas_view_container_get_icon_images (NautilusCanvasContainer *container,
					      NautilusCanvasIconData      *data,
					      int                    size,
					      char                 **embedded_text,
					      gboolean               for_drag_accept,
					      gboolean               need_large_embeddded_text,
					      gboolean              *embedded_text_needs_loading,
					      gboolean              *has_window_open)
{
	NautilusCanvasView *canvas_view;
	NautilusFile *file;
	gboolean use_embedding;
	NautilusFileIconFlags flags;
	NautilusIconInfo *icon_info;
	GdkPixbuf *pixbuf;
	GIcon *emblemed_icon;
	GEmblem *emblem;
	GList *emblem_icons, *l;

	file = (NautilusFile *) data;

	g_assert (NAUTILUS_IS_FILE (file));
	canvas_view = get_canvas_view (container);
	g_return_val_if_fail (canvas_view != NULL, NULL);

	use_embedding = FALSE;
	if (embedded_text) {
		*embedded_text = nautilus_file_peek_top_left_text (file, need_large_embeddded_text, embedded_text_needs_loading);
		use_embedding = *embedded_text != NULL;
	}
	
	*has_window_open = nautilus_file_has_open_window (file);

	flags = NAUTILUS_FILE_ICON_FLAGS_USE_MOUNT_ICON_AS_EMBLEM |
		NAUTILUS_FILE_ICON_FLAGS_USE_THUMBNAILS;

	if (use_embedding) {
		flags |= NAUTILUS_FILE_ICON_FLAGS_EMBEDDING_TEXT;
	}
	if (for_drag_accept) {
		flags |= NAUTILUS_FILE_ICON_FLAGS_FOR_DRAG_ACCEPT;
	}

	icon_info = nautilus_file_get_icon (file, size, flags);
	emblem_icons = nautilus_file_get_emblem_icons (file);

	/* apply emblems */
	if (emblem_icons != NULL) {
		l = emblem_icons;

		emblem = g_emblem_new (l->data);
		pixbuf = nautilus_icon_info_get_pixbuf (icon_info);
		emblemed_icon = g_emblemed_icon_new (G_ICON (pixbuf), emblem);
		g_object_unref (emblem);

		for (l = l->next; l != NULL; l = l->next) {
			emblem = g_emblem_new (l->data);
			g_emblemed_icon_add_emblem (G_EMBLEMED_ICON (emblemed_icon),
						    emblem);
			g_object_unref (emblem);
		}

		g_clear_object (&icon_info);
		icon_info = nautilus_icon_info_lookup (emblemed_icon, size);

		g_object_unref (pixbuf);
		g_object_unref (emblemed_icon);
	}

	if (emblem_icons != NULL) {
		g_list_free_full (emblem_icons, g_object_unref);
	}

	return icon_info;
}
Пример #9
0
static NemoIconInfo *
nemo_icon_view_container_get_icon_images (NemoIconContainer *container,
					      NemoIconData      *data,
					      int                    size,
					      char                 **embedded_text,
					      gboolean               for_drag_accept,
					      gboolean               need_large_embeddded_text,
					      gboolean              *embedded_text_needs_loading,
					      gboolean              *has_window_open)
{
	NemoIconView *icon_view;
	char **emblems_to_ignore;
	NemoFile *file;
	NemoFileIconFlags flags;
	NemoIconInfo *icon_info;
	GdkPixbuf *pixbuf;
	GIcon *emblemed_icon;
	GEmblem *emblem;
	GList *emblem_icons, *l;
    gint scale;

	file = (NemoFile *) data;

	g_assert (NEMO_IS_FILE (file));
	icon_view = get_icon_view (container);
	g_return_val_if_fail (icon_view != NULL, NULL);
	
	*has_window_open = nemo_file_has_open_window (file);

	flags = NEMO_FILE_ICON_FLAGS_USE_MOUNT_ICON_AS_EMBLEM |
			NEMO_FILE_ICON_FLAGS_USE_THUMBNAILS;

	if (for_drag_accept) {
		flags |= NEMO_FILE_ICON_FLAGS_FOR_DRAG_ACCEPT;
	}

	emblems_to_ignore = nemo_view_get_emblem_names_to_exclude 
		(NEMO_VIEW (icon_view));
	emblem_icons = nemo_file_get_emblem_icons (file,
						       emblems_to_ignore);
	g_strfreev (emblems_to_ignore);

    scale = gtk_widget_get_scale_factor (GTK_WIDGET (icon_view));
	icon_info = nemo_file_get_icon (file, size, scale, flags);

	/* apply emblems */
	if (emblem_icons != NULL) {
		l = emblem_icons;


		pixbuf = nemo_icon_info_get_pixbuf (icon_info);

        gint w, h, s;
        gboolean bad_ratio;

        w = gdk_pixbuf_get_width (pixbuf);
        h = gdk_pixbuf_get_height (pixbuf);

        s = MAX (w, h);
        if (s < size)
            size = s;

        bad_ratio = nemo_icon_get_emblem_size_for_icon_size (size) * scale > w ||
                    nemo_icon_get_emblem_size_for_icon_size (size) * scale > h;

        if (bad_ratio)
            goto skip_emblem; /* Would prefer to not use goto, but
                               * I don't want to do these checks on
                               * non-emblemed icons (the majority)
                               * as it would be too costly */

        emblem = g_emblem_new (l->data);

		emblemed_icon = g_emblemed_icon_new (G_ICON (pixbuf), emblem);
		g_object_unref (emblem);

		for (l = l->next; l != NULL; l = l->next) {
			emblem = g_emblem_new (l->data);
			g_emblemed_icon_add_emblem (G_EMBLEMED_ICON (emblemed_icon),
						    emblem);
			g_object_unref (emblem);
		}

		g_clear_object (&icon_info);
		icon_info = nemo_icon_info_lookup (emblemed_icon, size, scale);
        g_object_unref (emblemed_icon);

skip_emblem:
		g_object_unref (pixbuf);

	}

	if (emblem_icons != NULL) {
		g_list_free_full (emblem_icons, g_object_unref);
	}

	return icon_info;
}
Пример #10
0
void
e_composer_actions_init (EMsgComposer *composer)
{
	GtkActionGroup *action_group;
	GtkAccelGroup *accel_group;
	GtkUIManager *ui_manager;
	EHTMLEditor *editor;
	EContentEditor *cnt_editor;
	gboolean visible;
	GIcon *gcr_gnupg_icon;

	g_return_if_fail (E_IS_MSG_COMPOSER (composer));

	editor = e_msg_composer_get_editor (composer);
	cnt_editor = e_html_editor_get_content_editor (editor);
	ui_manager = e_html_editor_get_ui_manager (editor);

	/* Composer Actions */
	action_group = composer->priv->composer_actions;
	gtk_action_group_set_translation_domain (
		action_group, GETTEXT_PACKAGE);
	gtk_action_group_add_actions (
		action_group, entries,
		G_N_ELEMENTS (entries), composer);
	gtk_action_group_add_toggle_actions (
		action_group, toggle_entries,
		G_N_ELEMENTS (toggle_entries), composer);
	gtk_ui_manager_insert_action_group (ui_manager, action_group, 0);

	/* Asynchronous Actions */
	action_group = composer->priv->async_actions;
	gtk_action_group_set_translation_domain (
		action_group, GETTEXT_PACKAGE);
	gtk_action_group_add_actions (
		action_group, async_entries,
		G_N_ELEMENTS (async_entries), composer);
	gtk_ui_manager_insert_action_group (ui_manager, action_group, 0);

	/* Character Set Actions */
	action_group = composer->priv->charset_actions;
	gtk_action_group_set_translation_domain (
		action_group, GETTEXT_PACKAGE);
	e_charset_add_radio_actions (
		action_group, "charset-", composer->priv->charset,
		G_CALLBACK (action_charset_cb), composer);
	gtk_ui_manager_insert_action_group (ui_manager, action_group, 0);

	/* Fine Tuning */

	g_object_set (
		ACTION (ATTACH), "short-label", _("Attach"), NULL);

	g_object_set (
		ACTION (PICTURE_GALLERY), "is-important", TRUE, NULL);

	g_object_set (
		ACTION (SAVE_DRAFT), "short-label", _("Save Draft"), NULL);

	#define init_toolbar_option(x, always_visible)	\
		gtk_action_set_visible (ACTION (TOOLBAR_ ## x), always_visible); \
		e_binding_bind_property ( \
			ACTION (x), "active", \
			ACTION (TOOLBAR_ ## x), "active", \
			G_BINDING_SYNC_CREATE | G_BINDING_BIDIRECTIONAL); \
		e_binding_bind_property ( \
			ACTION (x), "label", \
			ACTION (TOOLBAR_ ## x), "label", \
			G_BINDING_SYNC_CREATE); \
		e_binding_bind_property ( \
			ACTION (x), "tooltip", \
			ACTION (TOOLBAR_ ## x), "tooltip", \
			G_BINDING_SYNC_CREATE); \
		e_binding_bind_property ( \
			ACTION (x), "sensitive", \
			ACTION (TOOLBAR_ ## x), "sensitive", \
			G_BINDING_SYNC_CREATE); \
		g_signal_connect (ACTION (TOOLBAR_ ## x), "toggled", \
			G_CALLBACK (composer_actions_toolbar_option_toggled_cb), composer);

	init_toolbar_option (PGP_SIGN, FALSE);
	init_toolbar_option (PGP_ENCRYPT, FALSE);
	init_toolbar_option (PRIORITIZE_MESSAGE, TRUE);
	init_toolbar_option (REQUEST_READ_RECEIPT, TRUE);
	init_toolbar_option (SMIME_SIGN, FALSE);
	init_toolbar_option (SMIME_ENCRYPT, FALSE);

	#undef init_toolbar_option

	/* Borrow a GnuPG icon from gcr to distinguish between GPG and S/MIME Sign/Encrypt actions */
	gcr_gnupg_icon = g_themed_icon_new ("gcr-gnupg");
	if (gcr_gnupg_icon) {
		GIcon *temp_icon;
		GIcon *action_icon;
		GEmblem *emblem;
		GtkAction *action;

		emblem = g_emblem_new (gcr_gnupg_icon);

		action = ACTION (TOOLBAR_PGP_SIGN);
		action_icon = g_themed_icon_new (gtk_action_get_icon_name (action));
		temp_icon = g_emblemed_icon_new (action_icon, emblem);
		g_object_unref (action_icon);

		gtk_action_set_gicon (action, temp_icon);
		g_object_unref (temp_icon);

		action = ACTION (TOOLBAR_PGP_ENCRYPT);
		action_icon = g_themed_icon_new (gtk_action_get_icon_name (action));
		temp_icon = g_emblemed_icon_new (action_icon, emblem);
		g_object_unref (action_icon);

		gtk_action_set_gicon (action, temp_icon);
		g_object_unref (temp_icon);

		g_object_unref (emblem);
		g_object_unref (gcr_gnupg_icon);
	}

	e_binding_bind_property (
		cnt_editor, "html-mode",
		ACTION (PICTURE_GALLERY), "sensitive",
		G_BINDING_SYNC_CREATE);

	e_binding_bind_property (
		cnt_editor, "editable",
		e_html_editor_get_action (editor, "edit-menu"), "sensitive",
		G_BINDING_SYNC_CREATE);

	e_binding_bind_property (
		cnt_editor, "editable",
		e_html_editor_get_action (editor, "format-menu"), "sensitive",
		G_BINDING_SYNC_CREATE);

	e_binding_bind_property (
		cnt_editor, "editable",
		e_html_editor_get_action (editor, "insert-menu"), "sensitive",
		G_BINDING_SYNC_CREATE);

	e_binding_bind_property (
		cnt_editor, "editable",
		e_html_editor_get_action (editor, "options-menu"), "sensitive",
		G_BINDING_SYNC_CREATE);

	e_binding_bind_property (
		cnt_editor, "editable",
		e_html_editor_get_action (editor, "picture-gallery"), "sensitive",
		G_BINDING_SYNC_CREATE);

#if defined (ENABLE_SMIME)
	visible = TRUE;
#else
	visible = FALSE;
#endif

	gtk_action_set_visible (ACTION (SMIME_ENCRYPT), visible);
	gtk_action_set_visible (ACTION (SMIME_SIGN), visible);

	accel_group = gtk_ui_manager_get_accel_group (ui_manager);
	g_signal_connect (accel_group, "accel-activate",
		G_CALLBACK (composer_actions_accel_activate_cb), composer);
}
Пример #11
0
static void
photos_base_item_check_effects_and_update_info (PhotosBaseItem *self)
{
  PhotosBaseItemPrivate *priv = self->priv;
  GApplication *app;
  GIcon *pix;
  GList *emblem_icons = NULL;
  GList *windows;
  GdkPixbuf *emblemed_pixbuf = NULL;
  GdkPixbuf *thumbnailed_pixbuf = NULL;
  GdkWindow *window;
  gint scale;

  if (priv->original_icon == NULL)
    goto out;

  emblemed_pixbuf = g_object_ref (priv->original_icon);

  if (priv->favorite)
    {
      pix = photos_base_item_create_symbolic_emblem (PHOTOS_ICON_FAVORITE);
      emblem_icons = g_list_prepend (emblem_icons, pix);
    }

  if (g_list_length (emblem_icons) > 0)
    {
      GIcon *emblemed_icon;
      GList *l;
      GtkIconInfo *icon_info;
      GtkIconTheme *theme;
      gint height;
      gint size;
      gint width;

      emblem_icons = g_list_reverse (emblem_icons);
      emblemed_icon = g_emblemed_icon_new (G_ICON (priv->original_icon), NULL);
      for (l = emblem_icons; l != NULL; l = g_list_next (l))
        {
          GEmblem *emblem;
          GIcon *emblem_icon = G_ICON (l->data);

          emblem = g_emblem_new (emblem_icon);
          g_emblemed_icon_add_emblem (G_EMBLEMED_ICON (emblemed_icon), emblem);
          g_object_unref (emblem);
        }

      theme = gtk_icon_theme_get_default ();

      width = gdk_pixbuf_get_width (priv->original_icon);
      height = gdk_pixbuf_get_height (priv->original_icon);
      size = (width > height) ? width : height;

      icon_info = gtk_icon_theme_lookup_by_gicon (theme, emblemed_icon, size, GTK_ICON_LOOKUP_FORCE_SIZE);

      if (icon_info != NULL)
        {
          GError *error = NULL;
          GdkPixbuf *tmp;

          tmp = gtk_icon_info_load_icon (icon_info, &error);
          if (error != NULL)
            {
              g_warning ("Unable to render the emblem: %s", error->message);
              g_error_free (error);
            }
          else
            {
              g_object_unref (emblemed_pixbuf);
              emblemed_pixbuf = tmp;
            }

          g_object_unref (icon_info);
        }

      g_object_unref (emblemed_icon);
    }

  g_clear_pointer (&priv->surface, (GDestroyNotify) cairo_surface_destroy);

  if (priv->thumb_path != NULL)
    {
      GtkBorder *slice;

      slice = photos_utils_get_thumbnail_frame_border ();
      thumbnailed_pixbuf = gd_embed_image_in_frame (emblemed_pixbuf,
                                                    "resource:///org/gnome/photos/thumbnail-frame.png",
                                                    slice,
                                                    slice);
      gtk_border_free (slice);
    }
  else
    thumbnailed_pixbuf = g_object_ref (emblemed_pixbuf);

  app = g_application_get_default ();
  scale = photos_application_get_scale_factor (PHOTOS_APPLICATION (app));
  windows = gtk_application_get_windows (GTK_APPLICATION (app));
  window = gtk_widget_get_window (GTK_WIDGET (windows->data));
  priv->surface = gdk_cairo_surface_create_from_pixbuf (thumbnailed_pixbuf, scale, window);

  g_signal_emit (self, signals[INFO_UPDATED], 0);

 out:
  g_clear_object (&thumbnailed_pixbuf);
  g_clear_object (&emblemed_pixbuf);
  g_list_free_full (emblem_icons, g_object_unref);
}
Пример #12
0
static GdkPixbuf *
get_menu_icon_for_file (TreeNode *node,
                        NemoFile *file,
			NemoFileIconFlags flags)
{
	NemoIconInfo *info;
	GIcon *gicon, *emblem_icon, *emblemed_icon;
	GEmblem *emblem;
	GdkPixbuf *pixbuf, *retval;
	gboolean highlight;
	int size;
	FMTreeModel *model;
	GList *emblem_icons, *l;
	char *emblems_to_ignore[3];
	int i;

	size = nemo_get_icon_size_for_stock_size (GTK_ICON_SIZE_MENU);
	gicon = G_ICON (nemo_file_get_icon_pixbuf (file, size, TRUE, flags));

	i = 0;
	emblems_to_ignore[i++] = NEMO_FILE_EMBLEM_NAME_TRASH;

	if (node->parent && node->parent->file) {
		if (!nemo_file_can_write (node->parent->file)) {
			emblems_to_ignore[i++] = NEMO_FILE_EMBLEM_NAME_CANT_WRITE;
		}
	}
	
	emblems_to_ignore[i++] = NULL;

	emblem = NULL;
	emblem_icons = nemo_file_get_emblem_icons (node->file,
						       emblems_to_ignore);

	/* pick only the first emblem we can render for the tree view */
	for (l = emblem_icons; l != NULL; l = l->next) {
		emblem_icon = l->data;
		if (nemo_icon_theme_can_render (G_THEMED_ICON (emblem_icon))) {
			emblem = g_emblem_new (emblem_icon);
			emblemed_icon = g_emblemed_icon_new (gicon, emblem);

			g_object_unref (gicon);
			g_object_unref (emblem);
			gicon = emblemed_icon;

			break;
		}
	}

	g_list_free_full (emblem_icons, g_object_unref);

	info = nemo_icon_info_lookup (gicon, size);
	retval = nemo_icon_info_get_pixbuf_nodefault_at_size (info, size);
	model = node->root->model;

	g_object_unref (gicon);

	highlight = (g_list_find_custom (model->details->highlighted_files,
	                                 file, (GCompareFunc) nemo_file_compare_location) != NULL);

	if (highlight) {
		pixbuf = eel_create_spotlight_pixbuf (retval);

		if (pixbuf != NULL) {
			g_object_unref (retval);
			retval = pixbuf;
		}
	}

	g_object_unref (info);

	return retval;
}
Пример #13
0
static void
fm_list_model_get_value (GtkTreeModel *tree_model, GtkTreeIter *iter, int column, GValue *value)
{
    FMListModel *model;
    FileEntry *file_entry;
    CajaFile *file;
    char *str;
    GdkPixbuf *icon, *rendered_icon;
    GIcon *gicon, *emblemed_icon, *emblem_icon;
    CajaIconInfo *icon_info;
    GEmblem *emblem;
    GList *emblem_icons, *l;
    int icon_size;
    CajaZoomLevel zoom_level;
    CajaFile *parent_file;
    char *emblems_to_ignore[3];
    int i;
    CajaFileIconFlags flags;

    model = (FMListModel *)tree_model;

    g_return_if_fail (model->details->stamp == iter->stamp);
    g_return_if_fail (!g_sequence_iter_is_end (iter->user_data));

    file_entry = g_sequence_get (iter->user_data);
    file = file_entry->file;

    switch (column)
    {
    case FM_LIST_MODEL_FILE_COLUMN:
        g_value_init (value, CAJA_TYPE_FILE);

        g_value_set_object (value, file);
        break;
    case FM_LIST_MODEL_SUBDIRECTORY_COLUMN:
        g_value_init (value, CAJA_TYPE_DIRECTORY);

        g_value_set_object (value, file_entry->subdirectory);
        break;
    case FM_LIST_MODEL_SMALLEST_ICON_COLUMN:
    case FM_LIST_MODEL_SMALLER_ICON_COLUMN:
    case FM_LIST_MODEL_SMALL_ICON_COLUMN:
    case FM_LIST_MODEL_STANDARD_ICON_COLUMN:
    case FM_LIST_MODEL_LARGE_ICON_COLUMN:
    case FM_LIST_MODEL_LARGER_ICON_COLUMN:
    case FM_LIST_MODEL_LARGEST_ICON_COLUMN:
        g_value_init (value, GDK_TYPE_PIXBUF);

        if (file != NULL)
        {
            zoom_level = fm_list_model_get_zoom_level_from_column_id (column);
            icon_size = caja_get_icon_size_for_zoom_level (zoom_level);

            flags = CAJA_FILE_ICON_FLAGS_USE_THUMBNAILS |
                    CAJA_FILE_ICON_FLAGS_FORCE_THUMBNAIL_SIZE |
                    CAJA_FILE_ICON_FLAGS_USE_MOUNT_ICON_AS_EMBLEM;
            if (model->details->drag_view != NULL)
            {
                GtkTreePath *path_a, *path_b;

                gtk_tree_view_get_drag_dest_row (model->details->drag_view,
                                                 &path_a,
                                                 NULL);
                if (path_a != NULL)
                {
                    path_b = gtk_tree_model_get_path (tree_model, iter);

                    if (gtk_tree_path_compare (path_a, path_b) == 0)
                    {
                        flags |= CAJA_FILE_ICON_FLAGS_FOR_DRAG_ACCEPT;
                    }

                    gtk_tree_path_free (path_a);
                    gtk_tree_path_free (path_b);
                }
            }

            gicon = caja_file_get_gicon (file, flags);

            /* render emblems with GEmblemedIcon */
            parent_file = caja_file_get_parent (file);
            i = 0;
            emblems_to_ignore[i++] = CAJA_FILE_EMBLEM_NAME_TRASH;
            if (parent_file) {
            	if (!caja_file_can_write (parent_file)) {
                    emblems_to_ignore[i++] = CAJA_FILE_EMBLEM_NAME_CANT_WRITE;
            	}
            	caja_file_unref (parent_file);
            }
            emblems_to_ignore[i++] = NULL;

            emblem = NULL;
            emblem_icons = caja_file_get_emblem_icons (file,
            					       emblems_to_ignore);

            if (emblem_icons != NULL) {
                emblem_icon = emblem_icons->data;
                emblem = g_emblem_new (emblem_icon);
                emblemed_icon = g_emblemed_icon_new (gicon, emblem);

                g_object_unref (emblem);

            	for (l = emblem_icons->next; l != NULL; l = l->next) {
            	    emblem_icon = l->data;
            	    emblem = g_emblem_new (emblem_icon);
            	    g_emblemed_icon_add_emblem
            	        (G_EMBLEMED_ICON (emblemed_icon), emblem);

                    g_object_unref (emblem);
            	}

                g_list_free_full (emblem_icons, g_object_unref);

            	g_object_unref (gicon);
            	gicon = emblemed_icon;
            }

            icon_info = caja_icon_info_lookup (gicon, icon_size);
            icon = caja_icon_info_get_pixbuf_at_size (icon_info, icon_size);

            g_object_unref (icon_info);
            g_object_unref (gicon);

            if (model->details->highlight_files != NULL &&
                    g_list_find_custom (model->details->highlight_files,
                                        file, (GCompareFunc) caja_file_compare_location))
            {
                rendered_icon = eel_gdk_pixbuf_render (icon, 1, 255, 255, 0, 0);

                if (rendered_icon != NULL)
                {
                    g_object_unref (icon);
                    icon = rendered_icon;
                }
            }

            g_value_set_object (value, icon);
            g_object_unref (icon);
        }
        break;
    case FM_LIST_MODEL_FILE_NAME_IS_EDITABLE_COLUMN:
        g_value_init (value, G_TYPE_BOOLEAN);

        g_value_set_boolean (value, file != NULL && caja_file_can_rename (file));
        break;
    default:
        if (column >= FM_LIST_MODEL_NUM_COLUMNS || column < FM_LIST_MODEL_NUM_COLUMNS + model->details->columns->len)
        {
            CajaColumn *caja_column;
            GQuark attribute;
            caja_column = model->details->columns->pdata[column - FM_LIST_MODEL_NUM_COLUMNS];

            g_value_init (value, G_TYPE_STRING);
            g_object_get (caja_column,
                          "attribute_q", &attribute,
                          NULL);
            if (file != NULL)
            {
                str = caja_file_get_string_attribute_with_default_q (file,
                        attribute);
                g_value_take_string (value, str);
            }
            else if (attribute == attribute_name_q)
            {
                if (file_entry->parent->loaded)
                {
                    g_value_set_string (value, _("(Empty)"));
                }
                else
                {
                    g_value_set_string (value, _("Loading..."));
                }
            }
        }
        else
        {
            g_assert_not_reached ();
        }
    }
}
Пример #14
0
static void
nautilus_list_model_get_value (GtkTreeModel *tree_model, GtkTreeIter *iter, int column, GValue *value)
{
	NautilusListModel *model;
	FileEntry *file_entry;
	NautilusFile *file;
	char *str;
	GdkPixbuf *icon, *rendered_icon;
	GIcon *gicon, *emblemed_icon, *emblem_icon;
	NautilusIconInfo *icon_info;
	GEmblem *emblem;
	GList *emblem_icons, *l;
	int icon_size, icon_scale;
	NautilusZoomLevel zoom_level;
	NautilusFileIconFlags flags;
	cairo_surface_t *surface;
	
	model = (NautilusListModel *)tree_model;

	g_return_if_fail (model->details->stamp == iter->stamp);
	g_return_if_fail (!g_sequence_iter_is_end (iter->user_data));

	file_entry = g_sequence_get (iter->user_data);
	file = file_entry->file;
	
	switch (column) {
	case NAUTILUS_LIST_MODEL_FILE_COLUMN:
		g_value_init (value, NAUTILUS_TYPE_FILE);

		g_value_set_object (value, file);
		break;
	case NAUTILUS_LIST_MODEL_SUBDIRECTORY_COLUMN:
		g_value_init (value, NAUTILUS_TYPE_DIRECTORY);

		g_value_set_object (value, file_entry->subdirectory);
		break;
	case NAUTILUS_LIST_MODEL_SMALLEST_ICON_COLUMN:
	case NAUTILUS_LIST_MODEL_SMALLER_ICON_COLUMN:
	case NAUTILUS_LIST_MODEL_SMALL_ICON_COLUMN:
	case NAUTILUS_LIST_MODEL_STANDARD_ICON_COLUMN:
	case NAUTILUS_LIST_MODEL_LARGE_ICON_COLUMN:
	case NAUTILUS_LIST_MODEL_LARGER_ICON_COLUMN:
	case NAUTILUS_LIST_MODEL_LARGEST_ICON_COLUMN:
		g_value_init (value, CAIRO_GOBJECT_TYPE_SURFACE);

		if (file != NULL) {
			zoom_level = nautilus_list_model_get_zoom_level_from_column_id (column);
			icon_size = nautilus_get_icon_size_for_zoom_level (zoom_level);
			icon_scale = nautilus_list_model_get_icon_scale (model);

			flags = NAUTILUS_FILE_ICON_FLAGS_USE_THUMBNAILS |
				NAUTILUS_FILE_ICON_FLAGS_FORCE_THUMBNAIL_SIZE |
				NAUTILUS_FILE_ICON_FLAGS_USE_MOUNT_ICON_AS_EMBLEM;
			if (model->details->drag_view != NULL) {
				GtkTreePath *path_a, *path_b;
				
				gtk_tree_view_get_drag_dest_row (model->details->drag_view,
								 &path_a,
								 NULL);
				if (path_a != NULL) {
					path_b = gtk_tree_model_get_path (tree_model, iter);

					if (gtk_tree_path_compare (path_a, path_b) == 0) {
						flags |= NAUTILUS_FILE_ICON_FLAGS_FOR_DRAG_ACCEPT;
					}
						
					gtk_tree_path_free (path_a);
					gtk_tree_path_free (path_b);
				}
			}

			gicon = G_ICON (nautilus_file_get_icon_pixbuf (file, icon_size, TRUE, icon_scale, flags));
			emblem_icons = nautilus_file_get_emblem_icons (file);

			/* pick only the first emblem we can render for the list view */
			for (l = emblem_icons; l != NULL; l = l->next) {
				emblem_icon = l->data;
				if (nautilus_icon_theme_can_render (G_THEMED_ICON (emblem_icon))) {
					emblem = g_emblem_new (emblem_icon);
					emblemed_icon = g_emblemed_icon_new (gicon, emblem);

					g_object_unref (gicon);
					g_object_unref (emblem);
					gicon = emblemed_icon;

					break;
				}
			}

			g_list_free_full (emblem_icons, g_object_unref);

			icon_info = nautilus_icon_info_lookup (gicon, icon_size, icon_scale);
			icon = nautilus_icon_info_get_pixbuf_at_size (icon_info, icon_size);

			g_object_unref (icon_info);
			g_object_unref (gicon);

			if (model->details->highlight_files != NULL &&
			    g_list_find_custom (model->details->highlight_files,
			                        file, (GCompareFunc) nautilus_file_compare_location))
			{
				rendered_icon = eel_create_spotlight_pixbuf (icon);

				if (rendered_icon != NULL) {
					g_object_unref (icon);
					icon = rendered_icon;
				}
			}

			surface = gdk_cairo_surface_create_from_pixbuf (icon, icon_scale, NULL);
			g_value_take_boxed (value, surface);
			g_object_unref (icon);
		}
		break;
	case NAUTILUS_LIST_MODEL_FILE_NAME_IS_EDITABLE_COLUMN:
		g_value_init (value, G_TYPE_BOOLEAN);
		
                g_value_set_boolean (value, file != NULL && nautilus_file_can_rename (file));
                break;
 	default:
 		if (column >= NAUTILUS_LIST_MODEL_NUM_COLUMNS || column < NAUTILUS_LIST_MODEL_NUM_COLUMNS + model->details->columns->len) {
			NautilusColumn *nautilus_column;
			GQuark attribute;
			nautilus_column = model->details->columns->pdata[column - NAUTILUS_LIST_MODEL_NUM_COLUMNS];
			
			g_value_init (value, G_TYPE_STRING);
			g_object_get (nautilus_column, 
				      "attribute_q", &attribute, 
				      NULL);
			if (file != NULL) {
				str = nautilus_file_get_string_attribute_with_default_q (file, 
											 attribute);
				g_value_take_string (value, str);
			} else if (attribute == attribute_name_q) {
				if (file_entry->parent->loaded) {
					g_value_set_string (value, _("(Empty)"));
				} else {
					g_value_set_string (value, _("Loading…"));
				}
			}
		} else {
			g_assert_not_reached ();
		}
	}
}