GSettings constructor

GSettings(
  1. String schemaName, {
  2. String? path,
  3. DBusClient? systemBus,
  4. DBusClient? sessionBus,
  5. GSettingsBackend? backend,
  6. List<String>? schemaDirs,
})

Creates an object to access settings from the shema with name schemaName. If this schema is relocatable path is required to be set. If the schema is not relocatable an exception will be thrown if path is set.

Implementation

GSettings(this.schemaName,
    {this.path,
    DBusClient? systemBus,
    DBusClient? sessionBus,
    GSettingsBackend? backend,
    List<String>? schemaDirs}) {
  if (backend == null) {
    var backendName = Platform.environment['GSETTINGS_BACKEND'];
    switch (backendName) {
      case 'memory':
        backend = GSettingsMemoryBackend();
        break;
      case 'keyfile':
        backend = GSettingsKeyfileBackend();
        break;
      case 'dconf':
      case null:
        // Handled below
        break;
      default:
        stderr.write("Unsupported gsettings backend '$backendName'\n");
        break;
    }
  }
  // Default to DConf
  _backend = backend ??
      GSettingsDConfBackend(systemBus: systemBus, sessionBus: sessionBus);

  if (path != null) {
    if (path!.isEmpty) {
      throw ArgumentError.value(path, 'path', 'Empty path given');
    }
    if (!path!.startsWith('/')) {
      throw ArgumentError.value(
          path, 'path', 'Path must begin with a slash (/)');
    }
    if (!path!.endsWith('/')) {
      throw ArgumentError.value(
          path, 'path', 'Path must end with a slash (/)');
    }
    if (path!.contains('//')) {
      throw ArgumentError.value(
          path, 'path', 'Path must not contain two adjacent slashes (//)');
    }
  }

  _schemaDirs = _getSchemaDirs(schemaDirsPath: schemaDirs);

  _keysChangedController.onListen = () {
    _load().then((table) {
      var path = _getPath(table);
      _keysChangedController.addStream(_backend.valuesChanged
          .where((keys) => keys.any((key) => key.startsWith(path)))
          .map((keys) =>
              keys.map((key) => key.substring(path.length)).toList()));
    });
  };
}