[libadwaita/wip/exalm/value-objects: 6/9] enum-value-object: Move to AdwEnumListModel file




commit e9ff4e175d3c86e80a58d89202c3b51933bf5d60
Author: Alexander Mikhaylenko <alexm gnome org>
Date:   Tue Jun 1 14:27:17 2021 +0500

    enum-value-object: Move to AdwEnumListModel file
    
    It's an object used only for AdwEnumListModel, might as well keep them
    together.
    
    Fixes https://gitlab.gnome.org/GNOME/libadwaita/-/issues/164

 src/adw-combo-row.h                 |   1 -
 src/adw-enum-list-model.c           | 171 +++++++++++++++++++++++++++++++++-
 src/adw-enum-list-model.h           |  15 ++-
 src/adw-enum-value-object-private.h |  19 ----
 src/adw-enum-value-object.c         | 177 ------------------------------------
 src/adw-enum-value-object.h         |  34 -------
 src/adwaita.h                       |   1 -
 src/meson.build                     |   2 -
 8 files changed, 183 insertions(+), 237 deletions(-)
---
diff --git a/src/adw-combo-row.h b/src/adw-combo-row.h
index fed5c447..685d433b 100644
--- a/src/adw-combo-row.h
+++ b/src/adw-combo-row.h
@@ -13,7 +13,6 @@
 #include "adw-version.h"
 
 #include <gtk/gtk.h>
-#include "adw-enum-value-object.h"
 #include "adw-action-row.h"
 
 G_BEGIN_DECLS
diff --git a/src/adw-enum-list-model.c b/src/adw-enum-list-model.c
index 895351de..21403603 100644
--- a/src/adw-enum-list-model.c
+++ b/src/adw-enum-list-model.c
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2020 Purism SPC
+ * Copyright (C) 2018-2020 Purism SPC
  *
  * SPDX-License-Identifier: LGPL-2.1-or-later
  */
@@ -7,7 +7,6 @@
 #include "config.h"
 
 #include "adw-enum-list-model.h"
-#include "adw-enum-value-object-private.h"
 
 #include <gio/gio.h>
 
@@ -44,6 +43,174 @@ static void adw_enum_list_model_list_model_init (GListModelInterface *iface);
 G_DEFINE_TYPE_WITH_CODE (AdwEnumListModel, adw_enum_list_model, G_TYPE_OBJECT,
                          G_IMPLEMENT_INTERFACE (G_TYPE_LIST_MODEL, adw_enum_list_model_list_model_init))
 
+/**
+ * AdwEnumValueObject:
+ *
+ * `AdwEnumValueObject` is the type of items in a [class@Adw.EnumListModel].
+ *
+ * Since: 1.0
+ */
+
+struct _AdwEnumValueObject
+{
+  GObject parent_instance;
+
+  GEnumValue enum_value;
+};
+
+enum {
+  VALUE_PROP_0,
+  VALUE_PROP_VALUE,
+  VALUE_PROP_NAME,
+  VALUE_PROP_NICK,
+  LAST_VALUE_PROP,
+};
+
+static GParamSpec *value_props[LAST_VALUE_PROP];
+
+G_DEFINE_TYPE (AdwEnumValueObject, adw_enum_value_object, G_TYPE_OBJECT)
+
+static void
+adw_enum_value_object_get_property (GObject    *object,
+                                    guint       prop_id,
+                                    GValue     *value,
+                                    GParamSpec *pspec)
+{
+  AdwEnumValueObject *self = ADW_ENUM_VALUE_OBJECT (object);
+
+  switch (prop_id) {
+  case VALUE_PROP_VALUE:
+    g_value_set_int (value, adw_enum_value_object_get_value (self));
+    break;
+  case VALUE_PROP_NAME:
+    g_value_set_string (value, adw_enum_value_object_get_name (self));
+    break;
+  case VALUE_PROP_NICK:
+    g_value_set_string (value, adw_enum_value_object_get_nick (self));
+    break;
+  default:
+    G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+  }
+}
+
+static void
+adw_enum_value_object_class_init (AdwEnumValueObjectClass *klass)
+{
+  GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+  object_class->get_property = adw_enum_value_object_get_property;
+
+  /**
+   * AdwEnumValueObject:value: (attributes org.gtk.Property.get=adw_enum_value_object_get_value)
+   *
+   * The enum value.
+   *
+   * Since: 1.0
+   */
+  value_props[VALUE_PROP_VALUE] =
+    g_param_spec_int ("value",
+                      "Value",
+                      "The enum value",
+                      G_MININT, G_MAXINT, 0,
+                      G_PARAM_READABLE);
+
+  /**
+   * AdwEnumValueObject:name: (attributes org.gtk.Property.get=adw_enum_value_object_get_name)
+   *
+   * The enum value name.
+   *
+   * Since: 1.0
+   */
+  value_props[VALUE_PROP_NAME] =
+    g_param_spec_string ("name",
+                         "Name",
+                         "The enum value name",
+                         NULL,
+                         G_PARAM_READABLE);
+
+  /**
+   * AdwEnumValueObject:nick: (attributes org.gtk.Property.get=adw_enum_value_object_get_nick)
+   *
+   * The enum value nick.
+   *
+   * Since: 1.0
+   */
+  value_props[VALUE_PROP_NICK] =
+    g_param_spec_string ("nick",
+                         "Nick",
+                         "The enum value nick",
+                         NULL,
+                         G_PARAM_READABLE);
+
+  g_object_class_install_properties (object_class, LAST_VALUE_PROP, value_props);
+}
+
+static void
+adw_enum_value_object_init (AdwEnumValueObject *self)
+{
+}
+
+static AdwEnumValueObject *
+adw_enum_value_object_new (GEnumValue *enum_value)
+{
+  AdwEnumValueObject *self = g_object_new (ADW_TYPE_ENUM_VALUE_OBJECT, NULL);
+
+  self->enum_value = *enum_value;
+
+  return self;
+}
+
+/**
+ * adw_enum_value_object_get_value: (attributes org.gtk.Method.get_property=value)
+ *
+ * Gets the enum value.
+ *
+ * Returns: the enum value
+ *
+ * Since: 1.0
+ */
+int
+adw_enum_value_object_get_value (AdwEnumValueObject *self)
+{
+  g_return_val_if_fail (ADW_IS_ENUM_VALUE_OBJECT (self), 0);
+
+  return self->enum_value.value;
+}
+
+/**
+ * adw_enum_value_object_get_name: (attributes org.gtk.Method.get_property=name)
+ *
+ * Gets the enum value name.
+ *
+ * Returns: the enum value name
+ *
+ * Since: 1.0
+ */
+const char *
+adw_enum_value_object_get_name (AdwEnumValueObject *self)
+{
+  g_return_val_if_fail (ADW_IS_ENUM_VALUE_OBJECT (self), NULL);
+
+  return self->enum_value.value_name;
+}
+
+/**
+ * adw_enum_value_object_get_nick: (attributes org.gtk.Method.get_property=nick)
+ *
+ * Gets the enum value nick.
+ *
+ * Returns: the enum value nick
+ *
+ * Since: 1.0
+ */
+const char *
+adw_enum_value_object_get_nick (AdwEnumValueObject *self)
+{
+  g_return_val_if_fail (ADW_IS_ENUM_VALUE_OBJECT (self), NULL);
+
+  return self->enum_value.value_nick;
+}
+
 static void
 adw_enum_list_model_constructed (GObject *object)
 {
diff --git a/src/adw-enum-list-model.h b/src/adw-enum-list-model.h
index 120b32ea..c32828b8 100644
--- a/src/adw-enum-list-model.h
+++ b/src/adw-enum-list-model.h
@@ -13,10 +13,23 @@
 #include "adw-version.h"
 
 #include <glib-object.h>
-#include "adw-enum-value-object.h"
 
 G_BEGIN_DECLS
 
+#define ADW_TYPE_ENUM_VALUE_OBJECT (adw_enum_value_object_get_type())
+
+ADW_AVAILABLE_IN_ALL
+G_DECLARE_FINAL_TYPE (AdwEnumValueObject, adw_enum_value_object, ADW, ENUM_VALUE_OBJECT, GObject)
+
+ADW_AVAILABLE_IN_ALL
+int adw_enum_value_object_get_value (AdwEnumValueObject *self);
+
+ADW_AVAILABLE_IN_ALL
+const char *adw_enum_value_object_get_name (AdwEnumValueObject *self);
+
+ADW_AVAILABLE_IN_ALL
+const char *adw_enum_value_object_get_nick (AdwEnumValueObject *self);
+
 #define ADW_TYPE_ENUM_LIST_MODEL (adw_enum_list_model_get_type())
 
 ADW_AVAILABLE_IN_ALL
diff --git a/src/adwaita.h b/src/adwaita.h
index 583e9fc9..916b83b1 100644
--- a/src/adwaita.h
+++ b/src/adwaita.h
@@ -36,7 +36,6 @@ G_BEGIN_DECLS
 #include "adw-combo-row.h"
 #include "adw-deprecation-macros.h"
 #include "adw-enum-list-model.h"
-#include "adw-enum-value-object.h"
 #include "adw-expander-row.h"
 #include "adw-flap.h"
 #include "adw-fold-threshold-policy.h"
diff --git a/src/meson.build b/src/meson.build
index ebef0015..e12cfd83 100644
--- a/src/meson.build
+++ b/src/meson.build
@@ -82,7 +82,6 @@ src_headers = [
   'adw-combo-row.h',
   'adw-deprecation-macros.h',
   'adw-enum-list-model.h',
-  'adw-enum-value-object.h',
   'adw-expander-row.h',
   'adw-flap.h',
   'adw-fold-threshold-policy.h',
@@ -136,7 +135,6 @@ src_sources = [
   'adw-clamp-scrollable.c',
   'adw-combo-row.c',
   'adw-enum-list-model.c',
-  'adw-enum-value-object.c',
   'adw-expander-row.c',
   'adw-fading-label.c',
   'adw-flap.c',


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