[gnome-builder] plugins/sysprof: use gsettings schemas auto-loading



commit 9c390b474d590e07539abff73f769e00533d7303
Author: Christian Hergert <chergert redhat com>
Date:   Tue Jul 26 23:15:16 2022 -0700

    plugins/sysprof: use gsettings schemas auto-loading
    
    This can denote that it uses settings in the .plugin file and have them
    auto-loaded into the context app vs project overrides.

 src/plugins/sysprof/gbp-sysprof-tool.c             | 31 +++++++++++-----------
 src/plugins/sysprof/gbp-sysprof-workspace-addin.c  | 13 ---------
 src/plugins/sysprof/gtk/menus.ui                   | 24 ++++++++---------
 .../sysprof/org.gnome.builder.sysprof.gschema.xml  |  4 +--
 src/plugins/sysprof/sysprof.plugin                 |  1 +
 5 files changed, 31 insertions(+), 42 deletions(-)
---
diff --git a/src/plugins/sysprof/gbp-sysprof-tool.c b/src/plugins/sysprof/gbp-sysprof-tool.c
index a40d99713..3566e8713 100644
--- a/src/plugins/sysprof/gbp-sysprof-tool.c
+++ b/src/plugins/sysprof/gbp-sysprof-tool.c
@@ -82,9 +82,10 @@ gbp_sysprof_tool_handler (IdeRunContext       *run_context,
                           gpointer             user_data,
                           GError             **error)
 {
-  static GSettings *settings;
   GbpSysprofTool *self = user_data;
+  g_autoptr(IdeSettings) settings = NULL;
   g_autoptr(GIOStream) io_stream = NULL;
+  IdeContext *context;
   const char *capture_file;
   guint n_fds;
   int read_fd;
@@ -96,8 +97,8 @@ gbp_sysprof_tool_handler (IdeRunContext       *run_context,
   g_assert (IDE_IS_UNIX_FD_MAP (unix_fd_map));
   g_assert (GBP_IS_SYSPROF_TOOL (self));
 
-  if (settings == NULL)
-    settings = g_settings_new ("org.gnome.builder.sysprof");
+  context = ide_object_get_context (IDE_OBJECT (self));
+  settings = ide_context_ref_settings (context, "org.gnome.builder.sysprof");
 
   /* Run sysprof-agent/gnome-builder-sysprof */
   ide_run_context_append_argv (run_context, "sysprof-agent");
@@ -129,40 +130,40 @@ gbp_sysprof_tool_handler (IdeRunContext       *run_context,
   capture_file = gbp_sysprof_tool_get_capture_file (self);
   ide_run_context_append_formatted (run_context, "--capture=%s", capture_file);
 
-  if (g_settings_get_boolean (settings, "cpu-aid"))
+  if (ide_settings_get_boolean (settings, "cpu-aid"))
     ide_run_context_append_argv (run_context, "--cpu");
 
-  if (g_settings_get_boolean (settings, "perf-aid"))
+  if (ide_settings_get_boolean (settings, "perf-aid"))
     ide_run_context_append_argv (run_context, "--perf");
 
-  if (g_settings_get_boolean (settings, "memory-aid"))
+  if (ide_settings_get_boolean (settings, "memory-aid"))
     ide_run_context_append_argv (run_context, "--memory");
 
-  if (g_settings_get_boolean (settings, "memprof-aid"))
+  if (ide_settings_get_boolean (settings, "memprof-aid"))
     ide_run_context_append_argv (run_context, "--memprof");
 
-  if (g_settings_get_boolean (settings, "diskstat-aid"))
+  if (ide_settings_get_boolean (settings, "diskstat-aid"))
     ide_run_context_append_argv (run_context, "--disk");
 
-  if (g_settings_get_boolean (settings, "netstat-aid"))
+  if (ide_settings_get_boolean (settings, "netdev-aid"))
     ide_run_context_append_argv (run_context, "--net");
 
-  if (g_settings_get_boolean (settings, "energy-aid"))
+  if (ide_settings_get_boolean (settings, "energy-aid"))
     ide_run_context_append_argv (run_context, "--energy");
 
-  if (g_settings_get_boolean (settings, "battery-aid"))
+  if (ide_settings_get_boolean (settings, "battery-aid"))
     ide_run_context_append_argv (run_context, "--battery");
 
-  if (g_settings_get_boolean (settings, "compositor-aid"))
+  if (ide_settings_get_boolean (settings, "compositor-aid"))
     ide_run_context_append_argv (run_context, "--compositor");
 
-  if (g_settings_get_boolean (settings, "gjs-aid"))
+  if (ide_settings_get_boolean (settings, "gjs-aid"))
     ide_run_context_append_argv (run_context, "--gjs");
 
-  if (!g_settings_get_boolean (settings, "allow-throttle"))
+  if (!ide_settings_get_boolean (settings, "allow-throttle"))
     ide_run_context_append_argv (run_context, "--no-throttle");
 
-  if (g_settings_get_boolean (settings, "allow-tracefd"))
+  if (ide_settings_get_boolean (settings, "allow-tracefd"))
     ide_run_context_append_argv (run_context, "--tracefd");
 
   for (guint i = 0; env[i]; i++)
diff --git a/src/plugins/sysprof/gbp-sysprof-workspace-addin.c 
b/src/plugins/sysprof/gbp-sysprof-workspace-addin.c
index 5e88639ed..06630eecd 100644
--- a/src/plugins/sysprof/gbp-sysprof-workspace-addin.c
+++ b/src/plugins/sysprof/gbp-sysprof-workspace-addin.c
@@ -196,9 +196,6 @@ gbp_sysprof_workspace_addin_load (IdeWorkspaceAddin *addin,
                                   IdeWorkspace      *workspace)
 {
   GbpSysprofWorkspaceAddin *self = (GbpSysprofWorkspaceAddin *)addin;
-  g_autoptr(GSettingsSchema) schema = NULL;
-  g_autoptr(GSettings) settings = NULL;
-  g_auto(GStrv) keys = NULL;
   IdeRunManager *run_manager;
   IdeContext *context;
 
@@ -221,16 +218,6 @@ gbp_sysprof_workspace_addin_load (IdeWorkspaceAddin *addin,
                                    G_N_ELEMENTS (entries),
                                    self);
 
-  settings = g_settings_new ("org.gnome.builder.sysprof");
-  g_object_get (settings, "settings-schema", &schema, NULL);
-  keys = g_settings_schema_list_keys (schema);
-
-  for (guint i = 0; keys[i]; i++)
-    {
-      g_autoptr(GAction) action = g_settings_create_action (settings, keys[i]);
-      g_action_map_add_action (G_ACTION_MAP (self->actions), action);
-    }
-
   g_object_bind_property (self->run_manager,
                           "busy",
                           g_action_map_lookup_action (G_ACTION_MAP (self->actions), "run"),
diff --git a/src/plugins/sysprof/gtk/menus.ui b/src/plugins/sysprof/gtk/menus.ui
index 191581371..5149d46d2 100644
--- a/src/plugins/sysprof/gtk/menus.ui
+++ b/src/plugins/sysprof/gtk/menus.ui
@@ -32,17 +32,17 @@
           <attribute name="label" translatable="yes">Thread Sampling</attribute>
           <item>
             <attribute name="label" translatable="yes">CPU Performance</attribute>
-            <attribute name="action">sysprof.perf-aid</attribute>
+            <attribute name="action">context.settings.project:org.gnome.builder.sysprof.perf-aid</attribute>
             <attribute name="role">check</attribute>
           </item>
           <item>
             <attribute name="label" translatable="yes">Memory Allocations</attribute>
-            <attribute name="action">sysprof.memprof-aid</attribute>
+            <attribute 
name="action">context.settings.project:org.gnome.builder.sysprof.memprof-aid</attribute>
             <attribute name="role">check</attribute>
           </item>
           <item>
             <attribute name="label" translatable="yes">Sample JavaScript Stacks</attribute>
-            <attribute name="action">sysprof.gjs-aid</attribute>
+            <attribute name="action">context.settings.project:org.gnome.builder.sysprof.gjs-aid</attribute>
             <attribute name="role">check</attribute>
           </item>
         </section>
@@ -50,7 +50,7 @@
           <attribute name="label" translatable="yes">Graphics</attribute>
           <item>
             <attribute name="label" translatable="yes">Display Timings</attribute>
-            <attribute name="action">sysprof.compositor-aid</attribute>
+            <attribute 
name="action">context.settings.project:org.gnome.builder.sysprof.compositor-aid</attribute>
             <attribute name="role">check</attribute>
           </item>
         </section>
@@ -58,22 +58,22 @@
           <attribute name="label" translatable="yes">Counters</attribute>
           <item>
             <attribute name="label" translatable="yes">CPU Usage</attribute>
-            <attribute name="action">sysprof.cpu-aid</attribute>
+            <attribute name="action">context.settings.project:org.gnome.builder.sysprof.cpu-aid</attribute>
             <attribute name="role">check</attribute>
           </item>
           <item>
             <attribute name="label" translatable="yes">Memory Usage</attribute>
-            <attribute name="action">sysprof.memory-aid</attribute>
+            <attribute 
name="action">context.settings.project:org.gnome.builder.sysprof.memory-aid</attribute>
             <attribute name="role">check</attribute>
           </item>
           <item>
             <attribute name="label" translatable="yes">Storage I/O</attribute>
-            <attribute name="action">sysprof.diskstat-aid</attribute>
+            <attribute 
name="action">context.settings.project:org.gnome.builder.sysprof.diskstat-aid</attribute>
             <attribute name="role">check</attribute>
           </item>
           <item>
             <attribute name="label" translatable="yes">Network I/O</attribute>
-            <attribute name="action">sysprof.netstat-aid</attribute>
+            <attribute 
name="action">context.settings.project:org.gnome.builder.sysprof.netdev-aid</attribute>
             <attribute name="role">check</attribute>
           </item>
         </section>
@@ -81,24 +81,24 @@
           <attribute name="label" translatable="yes">Energy</attribute>
           <item>
             <attribute name="label" translatable="yes">Consumption</attribute>
-            <attribute name="action">sysprof.energy-aid</attribute>
+            <attribute 
name="action">context.settings.project:org.gnome.builder.sysprof.energy-aid</attribute>
             <attribute name="role">check</attribute>
           </item>
           <item>
             <attribute name="label" translatable="yes">Battery Charge</attribute>
-            <attribute name="action">sysprof.battery-aid</attribute>
+            <attribute 
name="action">context.settings.project:org.gnome.builder.sysprof.battery-aid</attribute>
             <attribute name="role">check</attribute>
           </item>
         </section>
         <section id="run-menu-sysprof-misc-section">
           <item>
             <attribute name="label" translatable="yes">Allow Application Integration</attribute>
-            <attribute name="action">sysprof.allow-tracefd</attribute>
+            <attribute 
name="action">context.settings.project:org.gnome.builder.sysprof.allow-tracefd</attribute>
             <attribute name="role">check</attribute>
           </item>
           <item>
             <attribute name="label" translatable="yes">Allow CPU Throttling</attribute>
-            <attribute name="action">sysprof.allow-throttle</attribute>
+            <attribute 
name="action">context.settings.project:org.gnome.builder.sysprof.allow-throttle</attribute>
             <attribute name="role">check</attribute>
           </item>
         </section>
diff --git a/src/plugins/sysprof/org.gnome.builder.sysprof.gschema.xml 
b/src/plugins/sysprof/org.gnome.builder.sysprof.gschema.xml
index b0d09db47..d60fe22e1 100644
--- a/src/plugins/sysprof/org.gnome.builder.sysprof.gschema.xml
+++ b/src/plugins/sysprof/org.gnome.builder.sysprof.gschema.xml
@@ -1,12 +1,12 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <schemalist>
-  <schema id="org.gnome.builder.sysprof" path="/org/gnome/builder/sysprof/" gettext-domain="gnome-builder">
+  <schema id="org.gnome.builder.sysprof" gettext-domain="gnome-builder">
     <key type="b" name="cpu-aid"><default>true</default></key>
     <key type="b" name="perf-aid"><default>true</default></key>
     <key type="b" name="memory-aid"><default>true</default></key>
     <key type="b" name="memprof-aid"><default>false</default></key>
     <key type="b" name="diskstat-aid"><default>true</default></key>
-    <key type="b" name="netstat-aid"><default>true</default></key>
+    <key type="b" name="netdev-aid"><default>true</default></key>
     <key type="b" name="energy-aid"><default>false</default></key>
     <key type="b" name="battery-aid"><default>false</default></key>
     <key type="b" name="compositor-aid"><default>false</default></key>
diff --git a/src/plugins/sysprof/sysprof.plugin b/src/plugins/sysprof/sysprof.plugin
index 276d5b51b..ffd66a3c4 100644
--- a/src/plugins/sysprof/sysprof.plugin
+++ b/src/plugins/sysprof/sysprof.plugin
@@ -9,3 +9,4 @@ Module=sysprof
 Name=Sysprof
 X-Category=debuggers
 X-Workspace-Kind=primary;
+X-Settings-Schemas=org.gnome.builder.sysprof;


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