[gnome-desktop/gobject-gnomerr: 2/3] Add support for GObjectIntrospection



commit d135dd1e76268887460e2f7adcff2c49178ac489
Author: Giovanni Campagna <gcampagna src gnome org>
Date:   Mon Oct 25 18:49:15 2010 +0200

    Add support for GObjectIntrospection
    
    Turned all GnomeRR structures into boxed types, then added the needed
    annotations and the Makefile.am bits.
    Does not yet include API changes, but should bind (awfully) all of
    libgnome-desktop.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=630913

 configure.ac                                    |    1 +
 libgnome-desktop/Makefile.am                    |   58 ++++++++---
 libgnome-desktop/gnome-bg.c                     |   18 +++-
 libgnome-desktop/gnome-desktop-thumbnail.c      |    5 +-
 libgnome-desktop/gnome-rr-config.c              |   14 ++-
 libgnome-desktop/gnome-rr-config.h              |    5 +
 libgnome-desktop/gnome-rr.c                     |  127 ++++++++++++++++++++---
 libgnome-desktop/gnome-rr.h                     |    3 +
 libgnome-desktop/gnome-thumbnail-pixbuf-utils.c |    4 +-
 9 files changed, 194 insertions(+), 41 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index ca978d0..2e72274 100644
--- a/configure.ac
+++ b/configure.ac
@@ -165,6 +165,7 @@ AC_SUBST(GETTEXT_PACKAGE)
 
 AM_GLIB_GNU_GETTEXT
 
+GOBJECT_INTROSPECTION_CHECK([0.9.7])
 
 dnl Don't use AC_PROG_AWK since we need the full pathname.
 AC_PATH_PROGS(AWK, mawk gawk nawk awk, )
diff --git a/libgnome-desktop/Makefile.am b/libgnome-desktop/Makefile.am
index 8736b05..358ae3f 100644
--- a/libgnome-desktop/Makefile.am
+++ b/libgnome-desktop/Makefile.am
@@ -1,3 +1,5 @@
+CLEANFILES =
+
 lib_LTLIBRARIES = libgnome-desktop-3.la
 
 AM_CPPFLAGS =							\
@@ -11,20 +13,23 @@ AM_CPPFLAGS =							\
 
 AM_CFLAGS = $(WARN_CFLAGS)
 
-libgnome_desktop_3_la_SOURCES = \
-	gnome-desktop-utils.c	\
-	gnome-desktop-thumbnail.c \
-	gnome-thumbnail-pixbuf-utils.c \
-	gnome-bg.c		\
-	gnome-bg-crossfade.c	\
-	display-name.c		\
-	gnome-rr.c		\
-	gnome-rr-config.c	\
-	gnome-rr-labeler.c	\
-	gnome-rr-private.h	\
-	gnome-tz-monitor.c	\
-	edid-parse.c		\
-	edid.h			\
+introspection_sources = 		\
+	gnome-desktop-utils.c		\
+	gnome-desktop-thumbnail.c 	\
+	gnome-thumbnail-pixbuf-utils.c 	\
+	gnome-bg.c			\
+	gnome-bg-crossfade.c		\
+	display-name.c			\
+	gnome-rr.c			\
+	gnome-rr-config.c		\
+	gnome-rr-labeler.c		\
+	gnome-tz-monitor.c		\
+	edid-parse.c
+
+libgnome_desktop_3_la_SOURCES = 	\
+	$(introspection_sources)	\
+	gnome-rr-private.h		\
+	edid.h				\
 	private.h
 
 libgnome_desktop_3_la_LIBADD =	\
@@ -58,6 +63,31 @@ pnpdata_DATA_dist = pnp.ids
 check:
 	test -s $(top_srcdir)/libgnome-desktop/pnp.ids
 
+-include $(INTROSPECTION_MAKEFILE)
+INTROSPECTION_GIRS =
+INTROSPECTION_SCANNER_ARGS = --add-include-path=$(srcdir) --warn-all
+INTROSPECTION_COMPILER_ARGS = --includedir=$(srcdir)
+
+if HAVE_INTROSPECTION
+
+GnomeDesktop-3.0.gir: libgnome-desktop-3.la
+GnomeDesktop_3_0_gir_INCLUDES = GObject-2.0 Gtk-3.0 GConf-2.0
+GnomeDesktop_3_0_gir_PACKAGES = gdk-pixbuf-2.0 glib-2.0 gobject-2.0 gio-2.0 gtk+-3.0 gconf-2.0 gsettings-desktop-schemas
+GnomeDesktop_3_0_gir_CFLAGS = -DGNOME_DESKTOP_USE_UNSTABLE_API -I$(top_srcdir)
+GnomeDesktop_3_0_gir_LIBS = libgnome-desktop-3.la
+GnomeDesktop_3_0_gir_FILES = $(introspection_sources) $(libgnome_desktop_HEADERS)
+GnomeDesktop_3_0_gir_SCANNERFLAGS = --identifier-prefix=Gnome --symbol-prefix=gnome_
+INTROSPECTION_GIRS += GnomeDesktop-3.0.gir
+
+girdir = $(datadir)/gir-1.0
+gir_DATA = $(INTROSPECTION_GIRS)
+
+typelibdir = $(libdir)/girepository-1.0
+typelib_DATA = $(INTROSPECTION_GIRS:.gir=.typelib)
+
+CLEANFILES += $(gir_DATA) $(typelib_DATA)
+endif
+
 EXTRA_DIST = \
 	gnome-desktop-3.0.pc.in			\
 	gnome-desktop-3.0-uninstalled.pc.in	\
diff --git a/libgnome-desktop/gnome-bg.c b/libgnome-desktop/gnome-bg.c
index 27aea30..23c2dac 100644
--- a/libgnome-desktop/gnome-bg.c
+++ b/libgnome-desktop/gnome-bg.c
@@ -1278,6 +1278,11 @@ fit_factor (int from_width, int from_height,
 	return MIN (to_width  / (double) from_width, to_height / (double) from_height);
 }
 
+/**
+ * gnome_bg_create_thumbnail:
+ *
+ * Returns: (transfer full): a #GdkPixbuf showing the background as a thumbnail
+ */
 GdkPixbuf *
 gnome_bg_create_thumbnail (GnomeBG               *bg,
 		           GnomeDesktopThumbnailFactory *factory,
@@ -1499,14 +1504,13 @@ gnome_bg_set_surface_as_root (GdkScreen *screen, cairo_surface_t *surface)
  * gnome_bg_set_surface_as_root_with_crossfade:
  * @screen: the #GdkScreen to change root background on
  * @surface: the cairo xlib surface to set root background from
- * @context: a #GMainContext or %NULL
  *
  * Set the root pixmap, and properties pointing to it.
  * This function differs from gnome_bg_set_surface_as_root()
  * in that it adds a subtle crossfade animation from the
  * current root pixmap to the new one.
  *
- * Return value: a #GnomeBGCrossfade object
+ * Return value: (transfer full): a #GnomeBGCrossfade object
  **/
 GnomeBGCrossfade *
 gnome_bg_set_surface_as_root_with_crossfade (GdkScreen       *screen,
@@ -2996,9 +3000,15 @@ gnome_bg_changes_with_time (GnomeBG *bg)
 	return FALSE;
 }
 
-/* Creates a thumbnail for a certain frame, where 'frame' is somewhat
+/**
+ * gnome_bg_create_frame_thumbnail:
+ *
+ * Creates a thumbnail for a certain frame, where 'frame' is somewhat
  * vaguely defined as 'suitable point to show while single-stepping
- * through the slideshow'. Returns NULL if frame_num is out of bounds.
+ * through the slideshow'.
+ *
+ * Returns: (transfer full): the newly created thumbnail or
+ * or NULL if frame_num is out of bounds.
  */
 GdkPixbuf *
 gnome_bg_create_frame_thumbnail (GnomeBG			*bg,
diff --git a/libgnome-desktop/gnome-desktop-thumbnail.c b/libgnome-desktop/gnome-desktop-thumbnail.c
index 71871df..82816ef 100644
--- a/libgnome-desktop/gnome-desktop-thumbnail.c
+++ b/libgnome-desktop/gnome-desktop-thumbnail.c
@@ -779,7 +779,7 @@ expand_thumbnailing_script (const char *script,
  *
  * Usage of this function is threadsafe.
  *
- * Return value: thumbnail pixbuf if thumbnailing succeeded, %NULL otherwise.
+ * Return value: (transfer full): thumbnail pixbuf if thumbnailing succeeded, %NULL otherwise.
  *
  * Since: 2.2
  **/
@@ -1187,8 +1187,7 @@ gnome_desktop_thumbnail_factory_create_failed_thumbnail (GnomeDesktopThumbnailFa
  * Return value: A string with the MD5 digest of the uri string.
  *
  * Since: 2.2
- *
- * @Deprecated: 2.22: Use #GChecksum instead
+ * Deprecated: 2.22: Use #GChecksum instead
  **/
 char *
 gnome_desktop_thumbnail_md5 (const char *uri)
diff --git a/libgnome-desktop/gnome-rr-config.c b/libgnome-desktop/gnome-rr-config.c
index f5d63c6..6ca4a34 100644
--- a/libgnome-desktop/gnome-rr-config.c
+++ b/libgnome-desktop/gnome-rr-config.c
@@ -84,7 +84,11 @@ static CrtcAssignment  *crtc_assignment_new   (GnomeRRScreen    *screen,
 					       GError          **error);
 static void             crtc_assignment_free  (CrtcAssignment   *assign);
 static void             output_free           (GnomeOutputInfo  *output);
-static GnomeOutputInfo *output_copy           (GnomeOutputInfo  *output);
+static GnomeOutputInfo *output_copy           (const GnomeOutputInfo  *output);
+static GnomeRRConfig *  gnome_rr_config_copy (const GnomeRRConfig *config);
+
+G_DEFINE_BOXED_TYPE (GnomeOutputInfo, gnome_rr_output_info, output_copy, output_free)
+G_DEFINE_BOXED_TYPE (GnomeRRConfig, gnome_rr_config, gnome_rr_config_copy, gnome_rr_config_free)
 
 typedef struct Parser Parser;
 
@@ -622,7 +626,7 @@ output_free (GnomeOutputInfo *output)
 }
 
 static GnomeOutputInfo *
-output_copy (GnomeOutputInfo *output)
+output_copy (const GnomeOutputInfo *output)
 {
     GnomeOutputInfo *copy = g_new0 (GnomeOutputInfo, 1);
 
@@ -1177,7 +1181,7 @@ gnome_rr_config_save (GnomeRRConfig *configuration, GError **error)
 }
 
 static GnomeRRConfig *
-gnome_rr_config_copy (GnomeRRConfig *config)
+gnome_rr_config_copy (const GnomeRRConfig *config)
 {
     GnomeRRConfig *copy = g_new0 (GnomeRRConfig, 1);
     int i;
@@ -1297,8 +1301,8 @@ gnome_rr_config_apply_with_time (GnomeRRConfig *config,
  * See the documentation for gnome_rr_config_apply_from_filename().  This
  * function simply calls that other function with a filename of
  * gnome_rr_config_get_intended_filename().
-
- * @Deprecated: 2.26: Use gnome_rr_config_apply_from_filename() instead and pass it
+ *
+ * Deprecated: 2.26: Use gnome_rr_config_apply_from_filename() instead and pass it
  * the filename from gnome_rr_config_get_intended_filename().
  */
 gboolean
diff --git a/libgnome-desktop/gnome-rr-config.h b/libgnome-desktop/gnome-rr-config.h
index f230337..4619ab2 100644
--- a/libgnome-desktop/gnome-rr-config.h
+++ b/libgnome-desktop/gnome-rr-config.h
@@ -66,6 +66,11 @@ struct GnomeOutputInfo
     gpointer		user_data;
 };
 
+#define GNOME_RR_TYPE_OUTPUT_INFO    (gnome_rr_output_info_get_type())
+#define GNOME_RR_TYPE_CONFIG         (gnome_rr_config_get_type())
+GType gnome_rr_output_info_get_type (void);
+GType gnome_rr_config_get_type (void);
+
 struct GnomeRRConfig
 {
     /* "clone" means that at least two outputs are at (0, 0) offset and they
diff --git a/libgnome-desktop/gnome-rr.c b/libgnome-desktop/gnome-rr.c
index 3d4784f..568acd3 100644
--- a/libgnome-desktop/gnome-rr.c
+++ b/libgnome-desktop/gnome-rr.c
@@ -87,6 +87,7 @@ struct GnomeRROutput
     GnomeRRMode **	modes;
     int			n_preferred;
     guint8 *		edid_data;
+    int         edid_size;
     char *              connector_type;
 };
 
@@ -124,6 +125,7 @@ struct GnomeRRMode
 /* GnomeRRCrtc */
 static GnomeRRCrtc *  crtc_new          (ScreenInfo         *info,
 					 RRCrtc              id);
+static GnomeRRCrtc *  crtc_copy         (const GnomeRRCrtc  *from);
 static void           crtc_free         (GnomeRRCrtc        *crtc);
 
 #ifdef HAVE_RANDR
@@ -142,6 +144,7 @@ static gboolean       output_initialize (GnomeRROutput      *output,
 					 GError            **error);
 #endif
 
+static GnomeRROutput *output_copy       (const GnomeRROutput *from);
 static void           output_free       (GnomeRROutput      *output);
 
 /* GnomeRRMode */
@@ -153,6 +156,7 @@ static void           mode_initialize   (GnomeRRMode        *mode,
 					 XRRModeInfo        *info);
 #endif
 
+static GnomeRRMode *  mode_copy         (const GnomeRRMode  *from);
 static void           mode_free         (GnomeRRMode        *mode);
 
 static void gnome_rr_screen_finalize (GObject*);
@@ -162,6 +166,10 @@ static void gnome_rr_screen_initable_iface_init (GInitableIface *iface);
 G_DEFINE_TYPE_WITH_CODE (GnomeRRScreen, gnome_rr_screen, G_TYPE_OBJECT,
         G_IMPLEMENT_INTERFACE (G_TYPE_INITABLE, gnome_rr_screen_initable_iface_init))
 
+G_DEFINE_BOXED_TYPE (GnomeRRCrtc, gnome_rr_crtc, crtc_copy, crtc_free)
+G_DEFINE_BOXED_TYPE (GnomeRROutput, gnome_rr_output, output_copy, output_free)
+G_DEFINE_BOXED_TYPE (GnomeRRMode, gnome_rr_mode, mode_copy, mode_free)
+
 /* Errors */
 
 /**
@@ -765,7 +773,7 @@ gnome_rr_screen_class_init (GnomeRRScreenClass *klass)
                     "GDK Screen",
                     "The GDK Screen represented by this GnomeRRScreen",
                     GDK_TYPE_SCREEN,
-                    G_PARAM_CONSTRUCT | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB
+                    G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB
                     )
             );
 
@@ -1102,7 +1110,7 @@ gnome_rr_screen_get_output_by_id (GnomeRRScreen *screen,
 static GnomeRROutput *
 output_new (ScreenInfo *info, RROutput id)
 {
-    GnomeRROutput *output = g_new0 (GnomeRROutput, 1);
+    GnomeRROutput *output = g_slice_new0 (GnomeRROutput);
     
     output->id = id;
     output->info = info;
@@ -1149,26 +1157,25 @@ get_property (Display *dpy,
 }
 
 static guint8 *
-read_edid_data (GnomeRROutput *output)
+read_edid_data (GnomeRROutput *output, int *len)
 {
     Atom edid_atom;
     guint8 *result;
-    int len;
 
     edid_atom = XInternAtom (DISPLAY (output), "EDID", FALSE);
     result = get_property (DISPLAY (output),
-			   output->id, edid_atom, &len);
+			   output->id, edid_atom, len);
 
     if (!result)
     {
 	edid_atom = XInternAtom (DISPLAY (output), "EDID_DATA", FALSE);
 	result = get_property (DISPLAY (output),
-			       output->id, edid_atom, &len);
+			       output->id, edid_atom, len);
     }
 
     if (result)
     {
-	if (len % 128 == 0)
+	if (*len % 128 == 0)
 	    return result;
 	else
 	    g_free (result);
@@ -1289,7 +1296,7 @@ output_initialize (GnomeRROutput *output, XRRScreenResources *res, GError **erro
     output->n_preferred = info->npreferred;
     
     /* Edid data */
-    output->edid_data = read_edid_data (output);
+    output->edid_data = read_edid_data (output, &output->edid_size);
     
     XRRFreeOutputInfo (info);
 
@@ -1297,6 +1304,52 @@ output_initialize (GnomeRROutput *output, XRRScreenResources *res, GError **erro
 }
 #endif /* HAVE_RANDR */
 
+static GnomeRROutput*
+output_copy (const GnomeRROutput *from)
+{
+    GPtrArray *array;
+    GnomeRRCrtc **p_crtc;
+    GnomeRROutput **p_output;
+    GnomeRRMode **p_mode;
+    GnomeRROutput *output = g_slice_new0 (GnomeRROutput);
+
+    output->id = from->id;
+    output->info = from->info;
+    output->name = g_strdup (from->name);
+    output->current_crtc = from->current_crtc;
+    output->width_mm = from->width_mm;
+    output->height_mm = from->height_mm;
+    output->connected = from->connected;
+    output->n_preferred = from->n_preferred;
+    output->connector_type = g_strdup (from->connector_type);
+
+    array = g_ptr_array_new ();
+    for (p_crtc = from->possible_crtcs; *p_crtc != NULL; p_crtc++)
+    {
+        g_ptr_array_add (array, *p_crtc);
+    }
+    output->possible_crtcs = (GnomeRRCrtc**) g_ptr_array_free (array, FALSE);
+
+    array = g_ptr_array_new ();
+    for (p_output = from->clones; *p_output != NULL; p_output++)
+    {
+        g_ptr_array_add (array, *p_output);
+    }
+    output->clones = (GnomeRROutput**) g_ptr_array_free (array, FALSE);
+
+    array = g_ptr_array_new ();
+    for (p_mode = from->modes; *p_mode != NULL; p_mode++)
+    {
+        g_ptr_array_add (array, *p_mode);
+    }
+    output->modes = (GnomeRRMode**) g_ptr_array_free (array, FALSE);
+
+    output->edid_size = from->edid_size;
+    output->edid_data = g_memdup (from->edid_data, from->edid_size);
+
+    return output;
+}
+
 static void
 output_free (GnomeRROutput *output)
 {
@@ -1306,7 +1359,7 @@ output_free (GnomeRROutput *output)
     g_free (output->edid_data);
     g_free (output->name);
     g_free (output->connector_type);
-    g_free (output);
+    g_slice_free (GnomeRROutput, output);
 }
 
 guint32
@@ -1750,7 +1803,7 @@ gnome_rr_crtc_supports_rotation (GnomeRRCrtc *   crtc,
 static GnomeRRCrtc *
 crtc_new (ScreenInfo *info, RROutput id)
 {
-    GnomeRRCrtc *crtc = g_new0 (GnomeRRCrtc, 1);
+    GnomeRRCrtc *crtc = g_slice_new0 (GnomeRRCrtc);
     
     crtc->id = id;
     crtc->info = info;
@@ -1758,6 +1811,39 @@ crtc_new (ScreenInfo *info, RROutput id)
     return crtc;
 }
 
+static GnomeRRCrtc *
+crtc_copy (const GnomeRRCrtc *from)
+{
+    GnomeRROutput **p_output;
+    GPtrArray *array;
+    GnomeRRCrtc *to = g_slice_new0 (GnomeRRCrtc);
+
+    to->info = from->info;
+    to->id = from->id;
+    to->current_mode = from->current_mode;
+    to->x = from->x;
+    to->y = from->y;
+    to->current_rotation = from->current_rotation;
+    to->rotations = from->rotations;
+    to->gamma_size = from->gamma_size;
+
+    array = g_ptr_array_new ();
+    for (p_output = from->current_outputs; *p_output != NULL; p_output++)
+    {
+        g_ptr_array_add (array, *p_output);
+    }
+    to->current_outputs = (GnomeRROutput**) g_ptr_array_free (array, FALSE);
+
+    array = g_ptr_array_new ();
+    for (p_output = from->possible_outputs; *p_output != NULL; p_output++)
+    {
+        g_ptr_array_add (array, *p_output);
+    }
+    to->possible_outputs = (GnomeRROutput**) g_ptr_array_free (array, FALSE);
+
+    return to;
+}
+
 #ifdef HAVE_RANDR
 static gboolean
 crtc_initialize (GnomeRRCrtc        *crtc,
@@ -1834,14 +1920,14 @@ crtc_free (GnomeRRCrtc *crtc)
 {
     g_free (crtc->current_outputs);
     g_free (crtc->possible_outputs);
-    g_free (crtc);
+    g_slice_free (GnomeRRCrtc, crtc);
 }
 
 /* GnomeRRMode */
 static GnomeRRMode *
 mode_new (ScreenInfo *info, RRMode id)
 {
-    GnomeRRMode *mode = g_new0 (GnomeRRMode, 1);
+    GnomeRRMode *mode = g_slice_new0 (GnomeRRMode);
     
     mode->id = id;
     mode->info = info;
@@ -1891,11 +1977,26 @@ mode_initialize (GnomeRRMode *mode, XRRModeInfo *info)
 }
 #endif /* HAVE_RANDR */
 
+static GnomeRRMode *
+mode_copy (const GnomeRRMode *from)
+{
+    GnomeRRMode *to = g_slice_new0 (GnomeRRMode);
+
+    to->id = from->id;
+    to->info = from->info;
+    to->name = g_strdup (from->name);
+    to->width = from->width;
+    to->height = from->height;
+    to->freq = from->freq;
+
+    return to;
+}
+
 static void
 mode_free (GnomeRRMode *mode)
 {
     g_free (mode->name);
-    g_free (mode);
+    g_slice_free (GnomeRRMode, mode);
 }
 
 void
diff --git a/libgnome-desktop/gnome-rr.h b/libgnome-desktop/gnome-rr.h
index 1b73617..e305921 100644
--- a/libgnome-desktop/gnome-rr.h
+++ b/libgnome-desktop/gnome-rr.h
@@ -88,6 +88,9 @@ typedef enum {
 #define GNOME_RR_TYPE_MODE   (gnome_rr_mode_get_type())
 
 GType gnome_rr_screen_get_type (void);
+GType gnome_rr_output_get_type (void);
+GType gnome_rr_crtc_get_type (void);
+GType gnome_rr_mode_get_type (void);
 
 /* GnomeRRScreen */
 GnomeRRScreen * gnome_rr_screen_new                (GdkScreen             *screen,
diff --git a/libgnome-desktop/gnome-thumbnail-pixbuf-utils.c b/libgnome-desktop/gnome-thumbnail-pixbuf-utils.c
index 833242a..e6b0a9c 100644
--- a/libgnome-desktop/gnome-thumbnail-pixbuf-utils.c
+++ b/libgnome-desktop/gnome-thumbnail-pixbuf-utils.c
@@ -35,7 +35,7 @@
 #define LOAD_BUFFER_SIZE 65536
 
 /**
- * gnome_thumbnail_scale_down_pixbuf:
+ * gnome_desktop_thumbnail_scale_down_pixbuf:
  * @pixbuf: a #GdkPixbuf
  * @dest_width: the desired new width
  * @dest_height: the desired new height
@@ -44,7 +44,7 @@
  * is a lot faster than gdk-pixbuf when scaling down by
  * large amounts.
  *
- * Return value: a scaled pixbuf
+ * Return value: (transfer full): a scaled pixbuf
  * 
  * Since: 2.2
  **/



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]