[dconf-editor] Reorder functions.
- From: Arnaud Bonatti <arnaudb src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [dconf-editor] Reorder functions.
- Date: Fri, 19 Jan 2018 04:10:33 +0000 (UTC)
commit f20316e82b5a6fcc740e8de6b2c0c1d04b383a9a
Author: Arnaud Bonatti <arnaud bonatti gmail com>
Date: Fri Jan 19 05:09:38 2018 +0100
Reorder functions.
editor/dconf-model.vala | 229 ++++++++++++++++++++-----------------------
editor/source-manager.vala | 30 +++++-
2 files changed, 132 insertions(+), 127 deletions(-)
---
diff --git a/editor/dconf-model.vala b/editor/dconf-model.vala
index 53f60ba..4dee17f 100644
--- a/editor/dconf-model.vala
+++ b/editor/dconf-model.vala
@@ -84,7 +84,101 @@ public class SettingsModel : Object
}
/*\
- * * GSettings content creation
+ * * Objects requests
+ \*/
+
+ public Directory? get_directory (string path)
+ {
+ Directory? dir = null;
+ uint schemas_count = 0;
+ uint subpaths_count = 0;
+ source_manager.cached_schemas.get_content_count (path, out schemas_count, out subpaths_count);
+ if (schemas_count + subpaths_count > 0 || client.list (path).length > 0)
+ {
+ dir = new Directory (path, get_name (path));
+ if (schemas_count > 1)
+ ((!) dir).warning_multiple_schemas = true;
+ }
+ return dir;
+ }
+
+ public GLib.ListStore? get_children (string folder_path)
+ {
+ Directory? dir = get_directory (folder_path);
+ if (dir == null)
+ return null;
+
+ GLib.ListStore key_model = new GLib.ListStore (typeof (SettingObject));
+ bool multiple_schemas;
+
+ lookup_gsettings (folder_path, key_model, out multiple_schemas);
+ create_dconf_keys (folder_path, key_model);
+
+ if (key_model.get_n_items () > 0)
+ return key_model;
+ else
+ return null;
+ }
+
+ public SettingObject? get_object (string path, bool strict = true)
+ {
+ if (!is_key_path (path))
+ return (SettingObject?) get_directory (path);
+
+ if (strict)
+ return (SettingObject?) get_key (path);
+
+ GLib.ListStore? key_model = get_children (get_parent_path (path));
+ string name = get_name (path);
+ SettingObject? key = get_key_from_path_and_name (key_model, name);
+ if (key != null)
+ return key;
+
+ return get_folder_from_path_and_name (key_model, name);
+ }
+
+ public Key? get_key (string path)
+ {
+ GLib.ListStore? key_model = get_children (get_parent_path (path));
+ return get_key_from_path_and_name (key_model, get_name (path));
+ }
+
+ private static Key? get_key_from_path_and_name (GLib.ListStore? key_model, string key_name)
+ {
+ if (key_model == null)
+ return null;
+ uint position = 0;
+ while (position < ((!) key_model).get_n_items ())
+ {
+ SettingObject? object = (SettingObject?) ((!) key_model).get_object (position);
+ if (object == null)
+ assert_not_reached ();
+ if ((!) object is Key && ((!) object).name == key_name)
+ return (Key) (!) object;
+ position++;
+ }
+ return null;
+ }
+
+ private static Directory? get_folder_from_path_and_name (GLib.ListStore? key_model, string folder_name)
+ {
+ if (key_model == null)
+ return null;
+ uint position = 0;
+ while (position < ((!) key_model).get_n_items ())
+ {
+ SettingObject? object = (SettingObject?) ((!) key_model).get_object (position);
+ if (object == null)
+ assert_not_reached ();
+ if ((!) object is Directory && ((!) object).name == folder_name)
+ return (Directory) (!) object;
+ position++;
+ }
+ return null;
+ }
+
+ /*\
+ * * GSettings keys creation
\*/
private void lookup_gsettings (string path, GLib.ListStore key_model, out bool multiple_schemas)
@@ -115,6 +209,7 @@ public class SettingsModel : Object
content_found = true;
}
}
+
foreach (string folder in folders.get_values ())
{
if (get_folder_from_path_and_name (key_model, folder) == null)
@@ -125,58 +220,9 @@ public class SettingsModel : Object
}
}
- /*\
- * * Path requests
- \*/
-
- public static string get_base_path (string path)
- {
- if (!is_key_path (path))
- return path;
- else
- return stripped_path (path);
- }
-
- public Directory? get_directory (string path)
- {
- Directory? dir = null;
- uint schemas_count = 0;
- uint subpaths_count = 0;
- source_manager.cached_schemas.get_content_count (path, out schemas_count, out subpaths_count);
- if (schemas_count + subpaths_count > 0 || client.list (path).length > 0)
- {
- dir = new Directory (path, get_name (path));
- if (schemas_count > 1)
- ((!) dir).warning_multiple_schemas = true;
- }
- return dir;
- }
-
- public GLib.ListStore? get_children (string folder_path)
- {
- Directory? dir = get_directory (folder_path);
- if (dir == null)
- return null;
-
- GLib.ListStore key_model = new GLib.ListStore (typeof (SettingObject));
- bool multiple_schemas;
-
- lookup_gsettings (folder_path, key_model, out multiple_schemas);
- create_dconf_keys (folder_path, key_model);
-
- if (key_model.get_n_items () > 0)
- return key_model;
- else
- return null;
- }
-
- /*\
- * * GSettings keys creation
- \*/
-
private void create_gsettings_keys (string parent_path, GLib.SettingsSchema settings_schema,
GLib.ListStore key_model)
{
- string[] gsettings_key_map = settings_schema.list_keys ();
+ string [] gsettings_key_map = settings_schema.list_keys ();
string? path = settings_schema.get_path ();
GLib.Settings settings;
if (path == null) // relocatable
@@ -250,48 +296,21 @@ public class SettingsModel : Object
key_model.append (new_key);
}
- public SettingObject? get_object (string path, bool strict = true)
- {
- if (!is_key_path (path))
- return (SettingObject?) get_directory (path);
-
- if (strict)
- return (SettingObject?) get_key (path);
-
- GLib.ListStore? key_model = get_children (get_parent_path (path));
- string name = get_name (path);
- SettingObject? key = get_key_from_path_and_name (key_model, name);
- if (key != null)
- return key;
-
- return get_folder_from_path_and_name (key_model, name);
- }
-
- public Key? get_key (string path)
- {
- GLib.ListStore? key_model = get_children (get_parent_path (path));
- return get_key_from_path_and_name (key_model, get_name (path));
- }
-
- public static string[] to_segments (string path)
- {
- if (path == "/")
- return new string [0];
- int from = path.has_prefix ("/") ? 1 : 0;
- int to = path.has_suffix ("/") ? -1 : path.length;
- return path [from:to].split ("/");
- }
+ /*\
+ * * Path utilities
+ \*/
- public static string to_path (string[] segments)
+ public static bool is_key_path (string path)
{
- if (segments.length == 0)
- return "/";
- return "/" + string.joinv ("/", (string?[]?) segments) + "/";
+ return !path.has_suffix ("/");
}
- public static bool is_key_path (string path)
+ public static string get_base_path (string path)
{
- return !path.has_suffix ("/");
+ if (!is_key_path (path))
+ return path;
+ else
+ return stripped_path (path);
}
private static string get_name (string path)
@@ -318,40 +337,6 @@ public class SettingsModel : Object
return path.slice (0, path.last_index_of_char ('/') + 1);
}
- private static Key? get_key_from_path_and_name (GLib.ListStore? key_model, string key_name)
- {
- if (key_model == null)
- return null;
- uint position = 0;
- while (position < ((!) key_model).get_n_items ())
- {
- SettingObject? object = (SettingObject?) ((!) key_model).get_object (position);
- if (object == null)
- assert_not_reached ();
- if ((!) object is Key && ((!) object).name == key_name)
- return (Key) (!) object;
- position++;
- }
- return null;
- }
-
- private static Directory? get_folder_from_path_and_name (GLib.ListStore? key_model, string folder_name)
- {
- if (key_model == null)
- return null;
- uint position = 0;
- while (position < ((!) key_model).get_n_items ())
- {
- SettingObject? object = (SettingObject?) ((!) key_model).get_object (position);
- if (object == null)
- assert_not_reached ();
- if ((!) object is Directory && ((!) object).name == folder_name)
- return (Directory) (!) object;
- position++;
- }
- return null;
- }
-
/*\
* * Key value methods
\*/
diff --git a/editor/source-manager.vala b/editor/source-manager.vala
index 64dec9f..fe38558 100644
--- a/editor/source-manager.vala
+++ b/editor/source-manager.vala
@@ -207,7 +207,7 @@ public class SchemaPathTree
path_schemas = new GenericSet<SettingsSchema> ((schema) => { return str_hash (schema.get_id ()); },
(schema1, schema2) => { return str_equal
(schema1.get_id (), schema2.get_id ()); });
subpaths = new GenericSet<string> (str_hash, str_equal);
- return lookup_segments (SettingsModel.to_segments (path), 0, ref path_schemas, ref subpaths);
+ return lookup_segments (to_segments (path), 0, ref path_schemas, ref subpaths);
}
private bool lookup_segments (string[] path_segments, int matched_prefix_length, ref
GenericSet<SettingsSchema> path_schemas, ref GenericSet<string> subpaths)
@@ -237,14 +237,14 @@ public class SchemaPathTree
string? schema_path = schema.get_path ();
if (schema_path == null)
return;
- add_schema_to_path_spec (new CachedSchemaInfo (schema), SettingsModel.to_segments ((!) schema_path),
0, modified_path_specs);
+ add_schema_to_path_spec (new CachedSchemaInfo (schema), to_segments ((!) schema_path), 0,
modified_path_specs);
}
public void add_schema_with_path_specs (SettingsSchema schema, GenericSet<string> path_specs,
GenericSet<string> modified_path_specs)
{
ulong fingerprint = CachedSchemaInfo.compute_schema_fingerprint (schema);
path_specs.foreach ((path_spec) => {
- add_schema_to_path_spec (new CachedSchemaInfo (schema, fingerprint),
SettingsModel.to_segments (path_spec), 0, modified_path_specs);
+ add_schema_to_path_spec (new CachedSchemaInfo (schema, fingerprint), to_segments
(path_spec), 0, modified_path_specs);
});
}
@@ -260,7 +260,7 @@ public class SchemaPathTree
return false;
}
schemas.insert (schema_info.schema.get_id (), schema_info);
- modified_path_specs.add (SettingsModel.to_path (path_spec));
+ modified_path_specs.add (to_path (path_spec));
return true;
}
string segment = path_spec [matched_prefix_length];
@@ -278,7 +278,7 @@ public class SchemaPathTree
SchemaPathTree new_subtree = new SchemaPathTree (segment);
subtrees.insert (segment, new_subtree);
existing_subtree = new_subtree;
- modified_path_specs.add (SettingsModel.to_path (path_spec [0:matched_prefix_length]));
+ modified_path_specs.add (to_path (path_spec [0:matched_prefix_length]));
}
return ((!) existing_subtree).add_schema_to_path_spec (schema_info, path_spec,
matched_prefix_length + 1, modified_path_specs);
}
@@ -338,6 +338,26 @@ public class SchemaPathTree
{
return schemas.size () == 0 && wildcard_subtree == null && subtrees.size () == 0;
}
+
+ /*\
+ * * Path utilities
+ \*/
+
+ private static string [] to_segments (string path)
+ {
+ if (path == "/")
+ return new string [0];
+ int from = path.has_prefix ("/") ? 1 : 0;
+ int to = path.has_suffix ("/") ? -1 : path.length;
+ return path [from:to].split ("/");
+ }
+
+ private static string to_path (string [] segments)
+ {
+ if (segments.length == 0)
+ return "/";
+ return "/" + string.joinv ("/", (string? []?) segments) + "/";
+ }
}
class CachedSchemaInfo
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]