mirror of https://github.com/GNOME/gimp.git
libgimp: simplify GimpFileProcedure public API with G_DECLARE_DERIVABLE_TYPE().
While we definitely should not use this inside app/, because having the private structure easily accessible as a member is very convenient, it is clear that it makes for a much nicer public signature. Also the priv member is of no help to third-party developers using this API to make plug-ins and is better hidden in such a case.
This commit is contained in:
parent
e79de5db86
commit
f37c3c42c7
|
@ -24,7 +24,7 @@
|
|||
#include "gimpfileprocedure.h"
|
||||
|
||||
|
||||
struct _GimpFileProcedurePrivate
|
||||
typedef struct _GimpFileProcedurePrivate
|
||||
{
|
||||
gchar *format_name;
|
||||
gchar *mime_types;
|
||||
|
@ -33,7 +33,7 @@ struct _GimpFileProcedurePrivate
|
|||
gchar *magics;
|
||||
gint priority;
|
||||
gboolean handles_remote;
|
||||
};
|
||||
} GimpFileProcedurePrivate;
|
||||
|
||||
|
||||
static void gimp_file_procedure_constructed (GObject *object);
|
||||
|
@ -58,7 +58,6 @@ gimp_file_procedure_class_init (GimpFileProcedureClass *klass)
|
|||
static void
|
||||
gimp_file_procedure_init (GimpFileProcedure *procedure)
|
||||
{
|
||||
procedure->priv = gimp_file_procedure_get_instance_private (procedure);
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -79,13 +78,17 @@ gimp_file_procedure_constructed (GObject *object)
|
|||
static void
|
||||
gimp_file_procedure_finalize (GObject *object)
|
||||
{
|
||||
GimpFileProcedure *procedure = GIMP_FILE_PROCEDURE (object);
|
||||
GimpFileProcedure *procedure;
|
||||
GimpFileProcedurePrivate *priv;
|
||||
|
||||
g_clear_pointer (&procedure->priv->format_name, g_free);
|
||||
g_clear_pointer (&procedure->priv->mime_types, g_free);
|
||||
g_clear_pointer (&procedure->priv->extensions, g_free);
|
||||
g_clear_pointer (&procedure->priv->prefixes, g_free);
|
||||
g_clear_pointer (&procedure->priv->magics, g_free);
|
||||
procedure = GIMP_FILE_PROCEDURE (object);
|
||||
priv = gimp_file_procedure_get_instance_private (procedure);
|
||||
|
||||
g_clear_pointer (&priv->format_name, g_free);
|
||||
g_clear_pointer (&priv->mime_types, g_free);
|
||||
g_clear_pointer (&priv->extensions, g_free);
|
||||
g_clear_pointer (&priv->prefixes, g_free);
|
||||
g_clear_pointer (&priv->magics, g_free);
|
||||
|
||||
G_OBJECT_CLASS (parent_class)->finalize (object);
|
||||
}
|
||||
|
@ -121,10 +124,13 @@ void
|
|||
gimp_file_procedure_set_format_name (GimpFileProcedure *procedure,
|
||||
const gchar *format_name)
|
||||
{
|
||||
GimpFileProcedurePrivate *priv;
|
||||
|
||||
g_return_if_fail (GIMP_IS_FILE_PROCEDURE (procedure));
|
||||
|
||||
g_free (procedure->priv->format_name);
|
||||
procedure->priv->format_name = g_strdup (format_name);
|
||||
priv = gimp_file_procedure_get_instance_private (procedure);
|
||||
g_free (priv->format_name);
|
||||
priv->format_name = g_strdup (format_name);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -141,9 +147,13 @@ gimp_file_procedure_set_format_name (GimpFileProcedure *procedure,
|
|||
const gchar *
|
||||
gimp_file_procedure_get_format_name (GimpFileProcedure *procedure)
|
||||
{
|
||||
GimpFileProcedurePrivate *priv;
|
||||
|
||||
g_return_val_if_fail (GIMP_IS_FILE_PROCEDURE (procedure), NULL);
|
||||
|
||||
return procedure->priv->format_name;
|
||||
priv = gimp_file_procedure_get_instance_private (procedure);
|
||||
|
||||
return priv->format_name;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -166,10 +176,13 @@ void
|
|||
gimp_file_procedure_set_mime_types (GimpFileProcedure *procedure,
|
||||
const gchar *mime_types)
|
||||
{
|
||||
GimpFileProcedurePrivate *priv;
|
||||
|
||||
g_return_if_fail (GIMP_IS_FILE_PROCEDURE (procedure));
|
||||
|
||||
g_free (procedure->priv->mime_types);
|
||||
procedure->priv->mime_types = g_strdup (mime_types);
|
||||
priv = gimp_file_procedure_get_instance_private (procedure);
|
||||
g_free (priv->mime_types);
|
||||
priv->mime_types = g_strdup (mime_types);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -186,9 +199,13 @@ gimp_file_procedure_set_mime_types (GimpFileProcedure *procedure,
|
|||
const gchar *
|
||||
gimp_file_procedure_get_mime_types (GimpFileProcedure *procedure)
|
||||
{
|
||||
GimpFileProcedurePrivate *priv;
|
||||
|
||||
g_return_val_if_fail (GIMP_IS_FILE_PROCEDURE (procedure), NULL);
|
||||
|
||||
return procedure->priv->mime_types;
|
||||
priv = gimp_file_procedure_get_instance_private (procedure);
|
||||
|
||||
return priv->mime_types;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -206,10 +223,13 @@ void
|
|||
gimp_file_procedure_set_extensions (GimpFileProcedure *procedure,
|
||||
const gchar *extensions)
|
||||
{
|
||||
GimpFileProcedurePrivate *priv;
|
||||
|
||||
g_return_if_fail (GIMP_IS_FILE_PROCEDURE (procedure));
|
||||
|
||||
g_free (procedure->priv->extensions);
|
||||
procedure->priv->extensions = g_strdup (extensions);
|
||||
priv = gimp_file_procedure_get_instance_private (procedure);
|
||||
g_free (priv->extensions);
|
||||
priv->extensions = g_strdup (extensions);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -226,9 +246,13 @@ gimp_file_procedure_set_extensions (GimpFileProcedure *procedure,
|
|||
const gchar *
|
||||
gimp_file_procedure_get_extensions (GimpFileProcedure *procedure)
|
||||
{
|
||||
GimpFileProcedurePrivate *priv;
|
||||
|
||||
g_return_val_if_fail (GIMP_IS_FILE_PROCEDURE (procedure), NULL);
|
||||
|
||||
return procedure->priv->extensions;
|
||||
priv = gimp_file_procedure_get_instance_private (procedure);
|
||||
|
||||
return priv->extensions;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -246,10 +270,13 @@ void
|
|||
gimp_file_procedure_set_prefixes (GimpFileProcedure *procedure,
|
||||
const gchar *prefixes)
|
||||
{
|
||||
GimpFileProcedurePrivate *priv;
|
||||
|
||||
g_return_if_fail (GIMP_IS_FILE_PROCEDURE (procedure));
|
||||
|
||||
g_free (procedure->priv->prefixes);
|
||||
procedure->priv->prefixes = g_strdup (prefixes);
|
||||
priv = gimp_file_procedure_get_instance_private (procedure);
|
||||
g_free (priv->prefixes);
|
||||
priv->prefixes = g_strdup (prefixes);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -266,9 +293,13 @@ gimp_file_procedure_set_prefixes (GimpFileProcedure *procedure,
|
|||
const gchar *
|
||||
gimp_file_procedure_get_prefixes (GimpFileProcedure *procedure)
|
||||
{
|
||||
GimpFileProcedurePrivate *priv;
|
||||
|
||||
g_return_val_if_fail (GIMP_IS_FILE_PROCEDURE (procedure), NULL);
|
||||
|
||||
return procedure->priv->prefixes;
|
||||
priv = gimp_file_procedure_get_instance_private (procedure);
|
||||
|
||||
return priv->prefixes;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -284,10 +315,13 @@ void
|
|||
gimp_file_procedure_set_magics (GimpFileProcedure *procedure,
|
||||
const gchar *magics)
|
||||
{
|
||||
GimpFileProcedurePrivate *priv;
|
||||
|
||||
g_return_if_fail (GIMP_IS_FILE_PROCEDURE (procedure));
|
||||
|
||||
g_free (procedure->priv->magics);
|
||||
procedure->priv->magics = g_strdup (magics);
|
||||
priv = gimp_file_procedure_get_instance_private (procedure);
|
||||
g_free (priv->magics);
|
||||
priv->magics = g_strdup (magics);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -303,9 +337,13 @@ gimp_file_procedure_set_magics (GimpFileProcedure *procedure,
|
|||
const gchar *
|
||||
gimp_file_procedure_get_magics (GimpFileProcedure *procedure)
|
||||
{
|
||||
GimpFileProcedurePrivate *priv;
|
||||
|
||||
g_return_val_if_fail (GIMP_IS_FILE_PROCEDURE (procedure), NULL);
|
||||
|
||||
return procedure->priv->magics;
|
||||
priv = gimp_file_procedure_get_instance_private (procedure);
|
||||
|
||||
return priv->magics;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -326,9 +364,12 @@ void
|
|||
gimp_file_procedure_set_priority (GimpFileProcedure *procedure,
|
||||
gint priority)
|
||||
{
|
||||
GimpFileProcedurePrivate *priv;
|
||||
|
||||
g_return_if_fail (GIMP_IS_FILE_PROCEDURE (procedure));
|
||||
|
||||
procedure->priv->priority = priority;
|
||||
priv = gimp_file_procedure_get_instance_private (procedure);
|
||||
priv->priority = priority;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -345,9 +386,13 @@ gimp_file_procedure_set_priority (GimpFileProcedure *procedure,
|
|||
gint
|
||||
gimp_file_procedure_get_priority (GimpFileProcedure *procedure)
|
||||
{
|
||||
GimpFileProcedurePrivate *priv;
|
||||
|
||||
g_return_val_if_fail (GIMP_IS_FILE_PROCEDURE (procedure), 0);
|
||||
|
||||
return procedure->priv->priority;
|
||||
priv = gimp_file_procedure_get_instance_private (procedure);
|
||||
|
||||
return priv->priority;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -372,9 +417,12 @@ void
|
|||
gimp_file_procedure_set_handles_remote (GimpFileProcedure *procedure,
|
||||
gint handles_remote)
|
||||
{
|
||||
GimpFileProcedurePrivate *priv;
|
||||
|
||||
g_return_if_fail (GIMP_IS_FILE_PROCEDURE (procedure));
|
||||
|
||||
procedure->priv->handles_remote = handles_remote;
|
||||
priv = gimp_file_procedure_get_instance_private (procedure);
|
||||
priv->handles_remote = handles_remote;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -391,7 +439,10 @@ gimp_file_procedure_set_handles_remote (GimpFileProcedure *procedure,
|
|||
gint
|
||||
gimp_file_procedure_get_handles_remote (GimpFileProcedure *procedure)
|
||||
{
|
||||
GimpFileProcedurePrivate *priv;
|
||||
|
||||
g_return_val_if_fail (GIMP_IS_FILE_PROCEDURE (procedure), 0);
|
||||
|
||||
return procedure->priv->handles_remote;
|
||||
priv = gimp_file_procedure_get_instance_private (procedure);
|
||||
return priv->handles_remote;
|
||||
}
|
||||
|
|
|
@ -29,33 +29,26 @@ G_BEGIN_DECLS
|
|||
/* For information look into the C source or the html documentation */
|
||||
|
||||
|
||||
#define GIMP_TYPE_FILE_PROCEDURE (gimp_file_procedure_get_type ())
|
||||
#define GIMP_FILE_PROCEDURE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GIMP_TYPE_FILE_PROCEDURE, GimpFileProcedure))
|
||||
#define GIMP_FILE_PROCEDURE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GIMP_TYPE_FILE_PROCEDURE, GimpFileProcedureClass))
|
||||
#define GIMP_IS_FILE_PROCEDURE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GIMP_TYPE_FILE_PROCEDURE))
|
||||
#define GIMP_IS_FILE_PROCEDURE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GIMP_TYPE_FILE_PROCEDURE))
|
||||
#define GIMP_FILE_PROCEDURE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GIMP_TYPE_FILE_PROCEDURE, GimpFileProcedureClass))
|
||||
|
||||
|
||||
typedef struct _GimpFileProcedure GimpFileProcedure;
|
||||
typedef struct _GimpFileProcedureClass GimpFileProcedureClass;
|
||||
typedef struct _GimpFileProcedurePrivate GimpFileProcedurePrivate;
|
||||
|
||||
struct _GimpFileProcedure
|
||||
{
|
||||
GimpProcedure parent_instance;
|
||||
|
||||
GimpFileProcedurePrivate *priv;
|
||||
};
|
||||
#define GIMP_TYPE_FILE_PROCEDURE (gimp_file_procedure_get_type ())
|
||||
G_DECLARE_DERIVABLE_TYPE (GimpFileProcedure, gimp_file_procedure, GIMP, FILE_PROCEDURE, GimpProcedure)
|
||||
|
||||
struct _GimpFileProcedureClass
|
||||
{
|
||||
GimpProcedureClass parent_class;
|
||||
|
||||
/* Padding for future expansion */
|
||||
void (*_gimp_reserved1) (void);
|
||||
void (*_gimp_reserved2) (void);
|
||||
void (*_gimp_reserved3) (void);
|
||||
void (*_gimp_reserved4) (void);
|
||||
void (*_gimp_reserved5) (void);
|
||||
void (*_gimp_reserved6) (void);
|
||||
void (*_gimp_reserved7) (void);
|
||||
void (*_gimp_reserved8) (void);
|
||||
void (*_gimp_reserved9) (void);
|
||||
};
|
||||
|
||||
|
||||
GType gimp_file_procedure_get_type (void) G_GNUC_CONST;
|
||||
|
||||
void gimp_file_procedure_set_format_name (GimpFileProcedure *procedure,
|
||||
const gchar *format_name);
|
||||
const gchar * gimp_file_procedure_get_format_name (GimpFileProcedure *procedure);
|
||||
|
|
|
@ -72,6 +72,7 @@ typedef enum
|
|||
#define GIMP_IS_PROCEDURE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GIMP_TYPE_PROCEDURE))
|
||||
#define GIMP_PROCEDURE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GIMP_TYPE_PROCEDURE, GimpProcedureClass))
|
||||
|
||||
G_DEFINE_AUTOPTR_CLEANUP_FUNC (GimpProcedure, g_object_unref);
|
||||
|
||||
typedef struct _GimpProcedureClass GimpProcedureClass;
|
||||
typedef struct _GimpProcedurePrivate GimpProcedurePrivate;
|
||||
|
|
Loading…
Reference in New Issue