[gnome-builder] libide/tweaks: add IdeTweaksVariable



commit 8ef4b8fa180103765b2fdf2413e181b7ebdecdbd
Author: Christian Hergert <chergert redhat com>
Date:   Fri Jul 29 19:57:58 2022 -0700

    libide/tweaks: add IdeTweaksVariable
    
    Defining these will allow specialized expansion of some state such as
    settings paths or schemas when those are introduced into the object
    hierarchy.

 src/libide/tweaks/ide-tweaks-init.c     |   1 +
 src/libide/tweaks/ide-tweaks-variable.c | 152 ++++++++++++++++++++++++++++++++
 src/libide/tweaks/ide-tweaks-variable.h |  40 +++++++++
 src/libide/tweaks/libide-tweaks.h       |   1 +
 src/libide/tweaks/meson.build           |   2 +
 5 files changed, 196 insertions(+)
---
diff --git a/src/libide/tweaks/ide-tweaks-init.c b/src/libide/tweaks/ide-tweaks-init.c
index 0b63d9a47..59a8125e7 100644
--- a/src/libide/tweaks/ide-tweaks-init.c
+++ b/src/libide/tweaks/ide-tweaks-init.c
@@ -31,4 +31,5 @@ _ide_tweaks_init (void)
 {
   g_type_ensure (IDE_TYPE_TWEAKS_ITEM);
   g_type_ensure (IDE_TYPE_TWEAKS_PAGE);
+  g_type_ensure (IDE_TYPE_TWEAKS_VARIABLE);
 }
diff --git a/src/libide/tweaks/ide-tweaks-variable.c b/src/libide/tweaks/ide-tweaks-variable.c
new file mode 100644
index 000000000..aad0e8d12
--- /dev/null
+++ b/src/libide/tweaks/ide-tweaks-variable.c
@@ -0,0 +1,152 @@
+/* ide-tweaks-variable.c
+ *
+ * Copyright 2022 Christian Hergert <chergert redhat com>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ * SPDX-License-Identifier: GPL-3.0-or-later
+ */
+
+#define G_LOG_DOMAIN "ide-tweaks-variable"
+
+#include "config.h"
+
+#include "ide-tweaks-variable.h"
+
+struct _IdeTweaksVariable
+{
+  IdeTweaksItem parent_instance;
+
+  char *key;
+  char *value;
+};
+
+G_DEFINE_FINAL_TYPE (IdeTweaksVariable, ide_tweaks_variable, IDE_TYPE_TWEAKS_ITEM)
+
+enum {
+  PROP_0,
+  PROP_KEY,
+  PROP_VALUE,
+  N_PROPS
+};
+
+static GParamSpec *properties [N_PROPS];
+
+IdeTweaksVariable *
+ide_tweaks_variable_new (const char *key,
+                         const char *value)
+{
+  return g_object_new (IDE_TYPE_TWEAKS_VARIABLE,
+                       "key", key,
+                       "value", value,
+                       NULL);
+}
+
+static void
+ide_tweaks_variable_finalize (GObject *object)
+{
+  IdeTweaksVariable *self = (IdeTweaksVariable *)object;
+
+  g_clear_pointer (&self->key, g_free);
+  g_clear_pointer (&self->value, g_free);
+
+  G_OBJECT_CLASS (ide_tweaks_variable_parent_class)->finalize (object);
+}
+
+static void
+ide_tweaks_variable_get_property (GObject    *object,
+                                  guint       prop_id,
+                                  GValue     *value,
+                                  GParamSpec *pspec)
+{
+  IdeTweaksVariable *self = IDE_TWEAKS_VARIABLE (object);
+
+  switch (prop_id)
+    {
+    case PROP_KEY:
+      g_value_set_string (value, ide_tweaks_variable_get_key (self));
+      break;
+
+    case PROP_VALUE:
+      g_value_set_string (value, ide_tweaks_variable_get_value (self));
+      break;
+
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+    }
+}
+
+static void
+ide_tweaks_variable_set_property (GObject      *object,
+                                  guint         prop_id,
+                                  const GValue *value,
+                                  GParamSpec   *pspec)
+{
+  IdeTweaksVariable *self = IDE_TWEAKS_VARIABLE (object);
+
+  switch (prop_id)
+    {
+    case PROP_KEY:
+      self->key = g_value_dup_string (value);
+      break;
+
+    case PROP_VALUE:
+      self->value = g_value_dup_string (value);
+      break;
+
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+    }
+}
+
+static void
+ide_tweaks_variable_class_init (IdeTweaksVariableClass *klass)
+{
+  GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+  object_class->finalize = ide_tweaks_variable_finalize;
+  object_class->get_property = ide_tweaks_variable_get_property;
+  object_class->set_property = ide_tweaks_variable_set_property;
+
+  properties [PROP_KEY] =
+    g_param_spec_string ("key", NULL, NULL, NULL,
+                         (G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS));
+
+  properties [PROP_VALUE] =
+    g_param_spec_string ("value", NULL, NULL, NULL,
+                         (G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS));
+
+  g_object_class_install_properties (object_class, N_PROPS, properties);
+}
+
+static void
+ide_tweaks_variable_init (IdeTweaksVariable *self)
+{
+}
+
+const char *
+ide_tweaks_variable_get_key (IdeTweaksVariable *self)
+{
+  g_return_val_if_fail (IDE_IS_TWEAKS_VARIABLE (self), NULL);
+
+  return self->key;
+}
+
+const char *
+ide_tweaks_variable_get_value (IdeTweaksVariable *self)
+{
+  g_return_val_if_fail (IDE_IS_TWEAKS_VARIABLE (self), NULL);
+
+  return self->value;
+}
diff --git a/src/libide/tweaks/ide-tweaks-variable.h b/src/libide/tweaks/ide-tweaks-variable.h
new file mode 100644
index 000000000..c4762d4bf
--- /dev/null
+++ b/src/libide/tweaks/ide-tweaks-variable.h
@@ -0,0 +1,40 @@
+/* ide-tweaks-variable.h
+ *
+ * Copyright 2022 Christian Hergert <chergert redhat com>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ * SPDX-License-Identifier: GPL-3.0-or-later
+ */
+
+#pragma once
+
+#include "ide-tweaks-item.h"
+
+G_BEGIN_DECLS
+
+#define IDE_TYPE_TWEAKS_VARIABLE (ide_tweaks_variable_get_type())
+
+IDE_AVAILABLE_IN_ALL
+G_DECLARE_FINAL_TYPE (IdeTweaksVariable, ide_tweaks_variable, IDE, TWEAKS_VARIABLE, IdeTweaksItem)
+
+IDE_AVAILABLE_IN_ALL
+IdeTweaksVariable *ide_tweaks_variable_new       (const char        *key,
+                                                  const char        *value);
+IDE_AVAILABLE_IN_ALL
+const char        *ide_tweaks_variable_get_key   (IdeTweaksVariable *self);
+IDE_AVAILABLE_IN_ALL
+const char        *ide_tweaks_variable_get_value (IdeTweaksVariable *self);
+
+G_END_DECLS
diff --git a/src/libide/tweaks/libide-tweaks.h b/src/libide/tweaks/libide-tweaks.h
index 45d4ceef2..f2a4c3611 100644
--- a/src/libide/tweaks/libide-tweaks.h
+++ b/src/libide/tweaks/libide-tweaks.h
@@ -23,4 +23,5 @@
 #define IDE_TWEAKS_INSIDE
 # include "ide-tweaks-item.h"
 # include "ide-tweaks-page.h"
+# include "ide-tweaks-variable.h"
 #undef IDE_TWEAKS_INSIDE
diff --git a/src/libide/tweaks/meson.build b/src/libide/tweaks/meson.build
index 03c5b0e74..acdd5f9d4 100644
--- a/src/libide/tweaks/meson.build
+++ b/src/libide/tweaks/meson.build
@@ -10,6 +10,7 @@ libide_tweaks_public_headers = [
   'libide-tweaks.h',
   'ide-tweaks-item.h',
   'ide-tweaks-page.h',
+  'ide-tweaks-variable.h',
 ]
 
 install_headers(libide_tweaks_public_headers, subdir: libide_tweaks_header_subdir)
@@ -21,6 +22,7 @@ install_headers(libide_tweaks_public_headers, subdir: libide_tweaks_header_subdi
 libide_tweaks_public_sources = [
   'ide-tweaks-item.c',
   'ide-tweaks-page.c',
+  'ide-tweaks-variable.c',
 ]
 
 libide_tweaks_private_sources = [


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