Exemplo n.º 1
0
static void
gimp_image_prop_view_label_set_filesize (GtkWidget *label,
                                         GimpImage *image)
{
  const gchar *uri      = gimp_image_get_any_uri (image);
  gchar       *filename = NULL;

  if (uri)
    filename = g_filename_from_uri (uri, NULL, NULL);

  if (filename)
    {
      struct stat  buf;

      if (g_stat (filename, &buf) == 0)
        {
          gchar *str = g_format_size (buf.st_size);

          gtk_label_set_text (GTK_LABEL (label), str);
          g_free (str);
        }
      else
        {
          gtk_label_set_text (GTK_LABEL (label), NULL);
        }

      g_free (filename);
    }
  else
    {
      gtk_label_set_text (GTK_LABEL (label), NULL);
    }
}
Exemplo n.º 2
0
static void
gimp_image_prop_view_label_set_filename (GtkWidget *label,
                                         GimpImage *image)
{
  const gchar *uri = gimp_image_get_any_uri (image);

  if (uri)
    {
      gchar *name = file_utils_uri_display_name (uri);

      gtk_label_set_text (GTK_LABEL (label), name);
      g_free (name);
    }
  else
    {
      gtk_label_set_text (GTK_LABEL (label), NULL);
      gimp_help_set_help_data (gtk_widget_get_parent (label), NULL, NULL);
    }
}
Exemplo n.º 3
0
static void
gimp_image_prop_view_label_set_filesize (GtkWidget *label,
                                         GimpImage *image)
{
  const gchar *uri  = gimp_image_get_any_uri (image);
  GFile       *file = NULL;

  if (uri)
    file = g_file_new_for_uri (uri);

  if (file)
    {
      GFileInfo *info = g_file_query_info (file,
                                           G_FILE_ATTRIBUTE_STANDARD_SIZE,
                                           G_FILE_QUERY_INFO_NONE,
                                           NULL, NULL);

      if (info)
        {
          goffset  size = g_file_info_get_size (info);
          gchar   *str  = g_format_size (size);

          gtk_label_set_text (GTK_LABEL (label), str);
          g_free (str);

          g_object_unref (info);
        }
      else
        {
          gtk_label_set_text (GTK_LABEL (label), NULL);
        }

      g_object_unref (file);
    }
  else
    {
      gtk_label_set_text (GTK_LABEL (label), NULL);
    }
}
Exemplo n.º 4
0
GimpImage *
file_open_with_proc_and_display (Gimp                *gimp,
                                 GimpContext         *context,
                                 GimpProgress        *progress,
                                 const gchar         *uri,
                                 const gchar         *entered_filename,
                                 gboolean             as_new,
                                 GimpPlugInProcedure *file_proc,
                                 GimpPDBStatusType   *status,
                                 GError             **error)
{
  GimpImage   *image;
  const gchar *mime_type = NULL;

  g_return_val_if_fail (GIMP_IS_GIMP (gimp), NULL);
  g_return_val_if_fail (GIMP_IS_CONTEXT (context), NULL);
  g_return_val_if_fail (progress == NULL || GIMP_IS_PROGRESS (progress), NULL);
  g_return_val_if_fail (status != NULL, NULL);

  image = file_open_image (gimp, context, progress,
                           uri,
                           entered_filename,
                           as_new,
                           file_proc,
                           GIMP_RUN_INTERACTIVE,
                           status,
                           &mime_type,
                           error);

  if (image)
    {
      /* If the file was imported we want to set the layer name to the
       * file name. For now, assume that multi-layered imported images
       * have named the layers already, so only rename the layer of
       * single-layered imported files. Note that this will also
       * rename already named layers from e.g. single-layered PSD
       * files. To solve this properly, we would need new file plug-in
       * API.
       */
      if (! file_proc)
        file_proc = gimp_image_get_load_proc (image);

      if (file_open_file_proc_is_import (file_proc) &&
          gimp_image_get_n_layers (image) == 1)
        {
          GimpObject *layer    = gimp_image_get_layer_iter (image)->data;
          gchar      *basename = file_utils_uri_display_basename (uri);

          gimp_item_rename (GIMP_ITEM (layer), basename, NULL);
          gimp_image_undo_free (image);
          gimp_image_clean_all (image);

          g_free (basename);
        }

      if (gimp_create_display (image->gimp, image, GIMP_UNIT_PIXEL, 1.0))
        {
          /*  the display owns the image now  */
          g_object_unref (image);
        }

      if (! as_new)
        {
          GimpDocumentList *documents = GIMP_DOCUMENT_LIST (gimp->documents);
          GimpImagefile    *imagefile;
          const gchar      *any_uri;

          imagefile = gimp_document_list_add_uri (documents, uri, mime_type);

          /*  can only create a thumbnail if the passed uri and the
           *  resulting image's uri match. Use any_uri() here so we
           *  create thumbnails for both XCF and imported images.
           */
          any_uri = gimp_image_get_any_uri (image);

          if (any_uri && ! strcmp (uri, any_uri))
            {
              /*  no need to save a thumbnail if there's a good one already  */
              if (! gimp_imagefile_check_thumbnail (imagefile))
                {
                  gimp_imagefile_save_thumbnail (imagefile, mime_type, image,
                                                 NULL);
                }
            }
        }

      /*  announce that we opened this image  */
      gimp_image_opened (image->gimp, uri);
    }

  return image;
}