[gnome-keyring] gcr: Use glib-mkenums to generate types for enums and flags



commit 551843b52009417d2a46739fc275d0ab329ea0de
Author: Stef Walter <stefw collabora co uk>
Date:   Mon Jul 18 11:54:04 2011 +0200

    gcr: Use glib-mkenums to generate types for enums and flags
    
     * And remove manually coded type registration in GcrCertificateChain

 .gitignore                          |    2 +-
 configure.ac                        |    1 +
 docs/reference/gcr/gcr-sections.txt |    9 +++++++
 gcr/Makefile.am                     |   17 +++++++++++---
 gcr/gcr-certificate-chain.c         |   41 -----------------------------------
 gcr/gcr-certificate-chain.h         |   20 +---------------
 gcr/gcr-enum-types.c.template       |   35 +++++++++++++++++++++++++++++
 gcr/gcr-enum-types.h.template       |   28 +++++++++++++++++++++++
 gcr/gcr.h                           |    2 +
 9 files changed, 91 insertions(+), 64 deletions(-)
---
diff --git a/.gitignore b/.gitignore
index 1721d51..32e5ba0 100644
--- a/.gitignore
+++ b/.gitignore
@@ -110,7 +110,7 @@ run-tests
 /gck/tests/test-gck-slot
 /gck/tests/test-gck-uri
 
-<<<<<<< HEAD
+/gcr/gcr-enum-types.[ch]
 /gcr/tests/frob-certificate
 /gcr/tests/frob-key
 /gcr/tests/frob-gnupg-selector
diff --git a/configure.ac b/configure.ac
index f7aa7f9..8de1457 100644
--- a/configure.ac
+++ b/configure.ac
@@ -95,6 +95,7 @@ AC_SUBST(GETTEXT_PACKAGE)
 AM_GLIB_GNU_GETTEXT
 
 AC_PATH_PROG(GLIB_GENMARSHAL, glib-genmarshal)
+AC_PATH_PROG(GLIB_MKENUMS, glib-mkenums)
 
 GLIB_GSETTINGS
 
diff --git a/docs/reference/gcr/gcr-sections.txt b/docs/reference/gcr/gcr-sections.txt
index 61e7a7c..babaccf 100644
--- a/docs/reference/gcr/gcr-sections.txt
+++ b/docs/reference/gcr/gcr-sections.txt
@@ -28,6 +28,10 @@ GCR_IS_PARSER_CLASS
 GCR_PARSER_GET_CLASS
 GCK_API_SUBJECT_TO_CHANGE
 gcr_data_error_get_domain
+GCR_TYPE_DATA_ERROR
+GCR_TYPE_DATA_FORMAT
+gcr_data_error_get_type
+gcr_data_format_get_type
 </SECTION>
 
 <SECTION>
@@ -96,6 +100,8 @@ gcr_importer_get_type
 GCR_IMPORTER_CLASS
 GCR_IS_IMPORTER_CLASS
 GCR_IMPORTER_GET_CLASS
+GCR_TYPE_IMPORTER_PROMPT_BEHAVIOR
+gcr_importer_prompt_behavior_get_type
 </SECTION>
 
 <SECTION>
@@ -281,6 +287,9 @@ GcrCollectionModelPrivate
 <FILE>gcr-column</FILE>
 GcrColumn
 GcrColumnFlags
+<SUBSECTION Standard>
+GCR_TYPE_COLUMN_FLAGS
+gcr_column_flags_get_type
 </SECTION>
 
 <SECTION>
diff --git a/gcr/Makefile.am b/gcr/Makefile.am
index 45489be..e25fbcc 100644
--- a/gcr/Makefile.am
+++ b/gcr/Makefile.am
@@ -68,7 +68,8 @@ INCLUDES = \
 	$(P11_KIT_CFLAGS)
 
 BUILT_SOURCES = \
-	gcr-marshal.c gcr-marshal.h
+	gcr-marshal.c gcr-marshal.h \
+	gcr-enum-types.c gcr-enum-types.h
 
 lib_LTLIBRARIES = libgcr- GCR_MAJOR@.la
 
@@ -147,11 +148,19 @@ libgcr_testable_la_LIBADD = $(libgcr_ GCR_MAJOR@_la_OBJECTS) \
 libgcr_testable_la_DEPENDENCIES = $(libgcr_ GCR_MAJOR@_la_OBJECTS)
 
 gcr-marshal.h: gcr-marshal.list $(GLIB_GENMARSHAL)
-	$(GLIB_GENMARSHAL) $< --header --prefix=_gcr_marshal > $@
+	$(AM_V_GEN) $(GLIB_GENMARSHAL) $< --header --prefix=_gcr_marshal > $@
 
 gcr-marshal.c: gcr-marshal.list $(GLIB_GENMARSHAL)
-	echo "#include \"gcr-marshal.h\"" > $@ && \
-	$(GLIB_GENMARSHAL) $< --body --prefix=_gcr_marshal >> $@
+	$(AM_V_GEN) ( echo "#include \"gcr-marshal.h\"" > $@ && \
+		$(GLIB_GENMARSHAL) $< --body --prefix=_gcr_marshal >> $@ )
+
+gcr-enum-types.h: $(inc_HEADERS) gcr-enum-types.h.template
+	$(AM_V_GEN) $(GLIB_MKENUMS) --template $(srcdir)/gcr-enum-types.h.template \
+		$(inc_HEADERS) > $@
+
+gcr-enum-types.c: $(inc_HEADERS) gcr-enum-types.c.template
+	$(AM_V_GEN) $(GLIB_MKENUMS) --template $(srcdir)/gcr-enum-types.c.template \
+		$(inc_HEADERS) > $@
 
 pkgconfigdir = $(libdir)/pkgconfig
 pkgconfig_DATA = gcr-$(GCR_MAJOR).pc
diff --git a/gcr/gcr-certificate-chain.c b/gcr/gcr-certificate-chain.c
index 0c38582..f993c74 100644
--- a/gcr/gcr-certificate-chain.c
+++ b/gcr/gcr-certificate-chain.c
@@ -496,29 +496,6 @@ gcr_certificate_chain_class_init (GcrCertificateChainClass *klass)
  * The enum #GType for #GcrCertificateChainStatus.
  */
 
-GType
-gcr_certificate_chain_status_get_type (void)
-{
-	static volatile gsize initialized = 0;
-	static GType type = 0;
-	static const GEnumValue values[] = {
-		{ GCR_CERTIFICATE_CHAIN_UNKNOWN, "GCR_CERTIFICATE_CHAIN_UNKNOWN", "unknown" },
-		{ GCR_CERTIFICATE_CHAIN_INCOMPLETE, "GCR_CERTIFICATE_CHAIN_INCOMPLETE", "incomplete" },
-		{ GCR_CERTIFICATE_CHAIN_DISTRUSTED, "GCR_CERTIFICATE_CHAIN_DISTRUSTED", "distrusted" },
-		{ GCR_CERTIFICATE_CHAIN_SELFSIGNED, "GCR_CERTIFICATE_CHAIN_SELFSIGNED", "self-signed" },
-		{ GCR_CERTIFICATE_CHAIN_PINNED, "GCR_CERTIFICATE_CHAIN_PINNED", "pinned" },
-		{ GCR_CERTIFICATE_CHAIN_ANCHORED, "GCR_CERTIFICATE_CHAIN_ANCHORED", "anchored" },
-		{ 0, NULL, NULL }
-	};
-
-	if (g_once_init_enter (&initialized)) {
-		type = g_enum_register_static ("GcrCertificateChainStatus", values);
-		g_once_init_leave (&initialized, 1);
-	}
-
-	return type;
-}
-
 /**
  * GcrCertificateChainFlags:
  * @GCR_CERTIFICATE_CHAIN_FLAG_NO_LOOKUPS: If this flag is specified then no
@@ -535,24 +512,6 @@ gcr_certificate_chain_status_get_type (void)
  * The flags #GType for #GcrCertificateChainFlags.
  */
 
-GType
-gcr_certificate_chain_flags_get_type (void)
-{
-	static volatile gsize initialized = 0;
-	static GType type = 0;
-	static const GFlagsValue values[] = {
-		{ GCR_CERTIFICATE_CHAIN_FLAG_NO_LOOKUPS, "GCR_CERTIFICATE_CHAIN_FLAG_NO_LOOKUPS", "no-lookups" },
-		{ 0, NULL, NULL }
-	};
-
-	if (g_once_init_enter (&initialized)) {
-		type = g_flags_register_static ("GcrCertificateChainFlags", values);
-		g_once_init_leave (&initialized, 1);
-	}
-
-	return type;
-}
-
 /**
  * gcr_certificate_chain_new:
  *
diff --git a/gcr/gcr-certificate-chain.h b/gcr/gcr-certificate-chain.h
index 2f91542..fe3ab37 100644
--- a/gcr/gcr-certificate-chain.h
+++ b/gcr/gcr-certificate-chain.h
@@ -36,11 +36,7 @@
 
 G_BEGIN_DECLS
 
-/*
- * IMPORTANT: When adding a status, always update the
- * gcr_certificate_chain_status_get_type() function
- */
-typedef enum _GcrCertificateChainStatus {
+typedef enum {
 	GCR_CERTIFICATE_CHAIN_UNKNOWN,
 	GCR_CERTIFICATE_CHAIN_INCOMPLETE,
 	GCR_CERTIFICATE_CHAIN_DISTRUSTED,
@@ -49,22 +45,10 @@ typedef enum _GcrCertificateChainStatus {
 	GCR_CERTIFICATE_CHAIN_ANCHORED,
 } GcrCertificateChainStatus;
 
-#define GCR_TYPE_CERTIFICATE_CHAIN_STATUS        (gcr_certificate_chain_status_get_type())
-
-GType                     gcr_certificate_chain_status_get_type       (void) G_GNUC_CONST;
-
-/*
- * IMPORTANT: When adding a status, always update the
- * gcr_certificate_chain_flags_get_type() function
- */
-typedef enum _GcrCertificateChainFlags {
+typedef enum {
 	GCR_CERTIFICATE_CHAIN_FLAG_NO_LOOKUPS = 1 << 0,
 } GcrCertificateChainFlags;
 
-#define GCR_TYPE_CERTIFICATE_CHAIN_FLAGS         (gcr_certificate_chain_flags_get_type())
-
-GType                     gcr_certificate_chain_flags_get_type       (void) G_GNUC_CONST;
-
 #define GCR_TYPE_CERTIFICATE_CHAIN               (gcr_certificate_chain_get_type ())
 #define GCR_CERTIFICATE_CHAIN(obj)               (G_TYPE_CHECK_INSTANCE_CAST ((obj), GCR_TYPE_CERTIFICATE_CHAIN, GcrCertificateChain))
 #define GCR_CERTIFICATE_CHAIN_CLASS(klass)       (G_TYPE_CHECK_CLASS_CAST ((klass), GCR_TYPE_CERTIFICATE_CHAIN, GcrCertificateChainClass))
diff --git a/gcr/gcr-enum-types.c.template b/gcr/gcr-enum-types.c.template
new file mode 100644
index 0000000..685ceb7
--- /dev/null
+++ b/gcr/gcr-enum-types.c.template
@@ -0,0 +1,35 @@
+/*** BEGIN file-header ***/
+#include "gcr.h"
+
+/*** END file-header ***/
+
+/*** BEGIN file-production ***/
+/* enumerations from "@filename@" */
+/*** END file-production ***/
+
+/*** BEGIN value-header ***/
+GType
+ enum_name@_get_type (void)
+{
+    static GType etype = 0;
+    if (G_UNLIKELY(etype == 0)) {
+        static const G Type@Value values[] = {
+/*** END value-header ***/
+
+/*** BEGIN value-production ***/
+            { @VALUENAME@, "@VALUENAME@", "@valuenick@" },
+/*** END value-production ***/
+
+/*** BEGIN value-tail ***/
+            { 0, NULL, NULL }
+        };
+        etype = g_ type@_register_static (g_intern_static_string ("@EnumName@"), values);
+    }
+    return etype;
+}
+
+/*** END value-tail ***/
+
+/*** BEGIN file-tail ***/
+ /**/
+/*** END file-tail ***/
diff --git a/gcr/gcr-enum-types.h.template b/gcr/gcr-enum-types.h.template
new file mode 100644
index 0000000..c1b4f41
--- /dev/null
+++ b/gcr/gcr-enum-types.h.template
@@ -0,0 +1,28 @@
+/*** BEGIN file-header ***/
+#if !defined (__GCR_H_INSIDE__) && !defined (GCR_COMPILATION)
+#error "Only <gcr/gcr.h> can be included directly."
+#endif
+
+#ifndef __GCR_ENUM_TYPES_H__
+#define __GCR_ENUM_TYPES_H__
+
+#include <glib-object.h>
+
+G_BEGIN_DECLS
+/*** END file-header ***/
+
+/*** BEGIN file-production ***/
+
+/* enumerations from "@filename@" */
+/*** END file-production ***/
+
+/*** BEGIN value-header ***/
+GType @enum_name _get_type (void) G_GNUC_CONST;
+#define @ENUMPREFIX _TYPE_@ENUMSHORT@ (@enum_name _get_type ())
+/*** END value-header ***/
+
+/*** BEGIN file-tail ***/
+G_END_DECLS
+
+#endif /* __GCR_ENUM_TYPES_H__ */
+/*** END file-tail ***/
diff --git a/gcr/gcr.h b/gcr/gcr.h
index 332d8f1..a925e4e 100644
--- a/gcr/gcr.h
+++ b/gcr/gcr.h
@@ -39,7 +39,9 @@
 #include "gcr-certificate-renderer.h"
 #include "gcr-certificate-widget.h"
 #include "gcr-collection-model.h"
+#include "gcr-column.h"
 #include "gcr-combo-selector.h"
+#include "gcr-enum-types.h"
 #include "gcr-key-renderer.h"
 #include "gcr-key-widget.h"
 #include "gcr-importer.h"



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