コード例 #1
0
static void
clear_tip (GtkMenuItem  *item,
           gpointer      user_data)
{
        GList *children;
        GtkWidget *image;
        GIcon *icon, *icon2;
        const char *filename;

        /* Not a stock icon? */
        filename = g_object_get_data (G_OBJECT (item), "filename");
        if (filename == NULL)
                return;

        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))
                icon2 = g_emblemed_icon_get_icon (G_EMBLEMED_ICON (icon));
        else
                return;

        gtk_image_set_from_gicon (GTK_IMAGE (image), icon2, GTK_ICON_SIZE_DIALOG);
        g_object_unref (icon);
}
コード例 #2
0
static char *
gicon_to_string (GIcon *icon)
{
  GFile *file;
  const char *const *names;

  if (G_IS_FILE_ICON (icon))
    {
      file = g_file_icon_get_file (G_FILE_ICON (icon));
      if (file)
	return g_file_get_path (file);
    }
  else if (G_IS_THEMED_ICON (icon))
    {
      names = g_themed_icon_get_names (G_THEMED_ICON (icon));
      if (names)
	return g_strdup (names[0]);
    }
  else if (G_IS_EMBLEMED_ICON (icon))
    {
      GIcon *base;

      base = g_emblemed_icon_get_icon (G_EMBLEMED_ICON (icon));

      return gicon_to_string (base);
    }

  return NULL;
}
コード例 #3
0
static char *
get_uri_for_gicon (GIcon *icon)
{
  char *uri;

  uri = NULL;

  if (G_IS_EMBLEMED_ICON (icon) != FALSE) {
    GIcon *new_icon;
    new_icon = g_emblemed_icon_get_icon (G_EMBLEMED_ICON (icon));
    g_object_unref (icon);
    icon = g_object_ref (new_icon);
  }

  if (G_IS_FILE_ICON (icon) != FALSE) {
    GFile *file;

    file = g_file_icon_get_file (G_FILE_ICON (icon));
    uri = g_file_get_uri (file);
    g_object_unref (file);

    return uri;
  }

  /* We leave the themed icons up to the applications to set */

  return uri;
}
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;
}
コード例 #5
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;
}
コード例 #6
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);
}
コード例 #7
0
ファイル: gtknumerableicon.c プロジェクト: BoozzyAmdJin/gtk-
static void
gtk_numerable_icon_ensure_emblem (GtkNumerableIcon *self)
{
  cairo_t *cr;
  cairo_surface_t *surface;
  PangoLayout *layout;
  GEmblem *emblem;
  gint width, height;
  gdouble scale;
  PangoAttrList *attr_list;
  PangoAttribute *attr;
  GdkPixbuf *pixbuf;

  /* don't draw anything if the count is zero */
  if (self->priv->rendered_string == NULL)
    {
      g_emblemed_icon_clear_emblems (G_EMBLEMED_ICON (self));
      return;
    }

  surface = get_image_surface (self);
  cr = cairo_create (surface);

  layout = get_pango_layout (self);
  pango_layout_get_pixel_size (layout, &width, &height);

  /* scale the layout to be 0.75 of the size still available for drawing */
  scale = ((get_surface_size (surface) - 2 * get_border_size (self)) * 0.75) / (MAX (height, width));
  attr_list = pango_attr_list_new ();

  attr = pango_attr_scale_new (scale);
  pango_attr_list_insert (attr_list, attr);

  attr = pango_attr_weight_new (PANGO_WEIGHT_BOLD);
  pango_attr_list_insert (attr_list, attr);

  pango_layout_set_attributes (layout, attr_list);

  /* update these values */
  pango_layout_get_pixel_size (layout, &width, &height);

  /* move to the center */
  cairo_move_to (cr,
                 get_surface_size (surface) / 2. - (gdouble) width / 2.,
                 get_surface_size (surface) / 2. - (gdouble) height / 2.);

  gdk_cairo_set_source_rgba (cr, self->priv->foreground);
  pango_cairo_show_layout (cr, layout);

  cairo_destroy (cr);

  pixbuf =
    gdk_pixbuf_get_from_surface (surface, 0, 0,
                                 get_surface_size (surface), get_surface_size (surface));

  emblem = g_emblem_new (G_ICON (pixbuf));
  g_emblemed_icon_clear_emblems (G_EMBLEMED_ICON (self));
  g_emblemed_icon_add_emblem (G_EMBLEMED_ICON (self), emblem);

  g_object_unref (layout);
  g_object_unref (emblem);
  g_object_unref (pixbuf);

  cairo_surface_destroy (surface);
  pango_attr_list_unref (attr_list);
}
コード例 #8
0
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;
}
コード例 #9
0
ファイル: fm-list-model.c プロジェクト: fatman2021/caja
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 ();
        }
    }
}