Beispiel #1
0
static PyObject *
_wrap_gimp_thumb_find_thumb(PyGObject *self, PyObject *args, PyObject *kwargs)
{
    gchar *uri, *ret;
    PyObject *py_size, *py_ret;
    GimpThumbSize size;

    static char *kwlist[] = { "uri", NULL };

    if (!PyArg_ParseTupleAndKeywords(args, kwargs, "sO:find_thumb", kwlist,
                                     &uri, &py_size))
        return NULL;

    if (pyg_enum_get_value(GIMP_TYPE_THUMB_SIZE, py_size, (gint *)&size))
        return NULL;

    ret = gimp_thumb_find_thumb(uri, &size);

    if (ret == NULL) {
        Py_INCREF(Py_None);
        return Py_None;
    }

    py_ret = Py_BuildValue("sN", ret,
                           pyg_enum_from_gtype(GIMP_TYPE_THUMB_SIZE, size));
    g_free(ret);
    return py_ret;
}
Beispiel #2
0
static void
gimp_thumbnail_update_thumb (GimpThumbnail *thumbnail,
                             GimpThumbSize  size)
{
  gchar          *filename;
  GimpThumbState  state;
  gint64          filesize = 0;
  gint64          mtime    = 0;

  if (! thumbnail->image_uri)
    return;

  state = thumbnail->thumb_state;

  filename = gimp_thumb_find_thumb (thumbnail->image_uri, &size);

  /* We don't want to clear the GIMP_THUMB_STATE_FAILED state, because
   * it is normal to have no filename if thumbnail creation failed. */
  if (state != GIMP_THUMB_STATE_FAILED && ! filename)
    state = GIMP_THUMB_STATE_NOT_FOUND;

  switch (state)
    {
    case GIMP_THUMB_STATE_EXISTS:
    case GIMP_THUMB_STATE_OLD:
    case GIMP_THUMB_STATE_OK:
      g_return_if_fail (thumbnail->thumb_filename != NULL);

      if (thumbnail->thumb_size     == size     &&
          thumbnail->thumb_filesize == filesize &&
          thumbnail->thumb_mtime    == mtime)
        {
          g_free (filename);
          return;
        }
      break;
    default:
      break;
    }

  if (thumbnail->thumb_filename)
    g_free (thumbnail->thumb_filename);

  thumbnail->thumb_filename = filename;

  if (filename)
    state = (size > GIMP_THUMB_SIZE_FAIL ?
             GIMP_THUMB_STATE_EXISTS : GIMP_THUMB_STATE_FAILED);

  thumbnail->thumb_size     = size;
  thumbnail->thumb_filesize = filesize;
  thumbnail->thumb_mtime    = mtime;

  if (state != thumbnail->thumb_state)
    {
      g_object_freeze_notify (G_OBJECT (thumbnail));

      g_object_set (thumbnail, "thumb-state", state, NULL);
      gimp_thumbnail_reset_info (thumbnail);

      g_object_thaw_notify (G_OBJECT (thumbnail));
    }
}