Flutter Linux Embedder
fl_settings_portal.h File Reference

Go to the source code of this file.

Functions

G_BEGIN_DECLS G_DECLARE_FINAL_TYPE (FlSettingsPortal, fl_settings_portal, FL, SETTINGS_PORTAL, GObject)
 
FlSettingsPortal * fl_settings_portal_new ()
 
FlSettingsPortal * fl_settings_portal_new_with_values (GVariantDict *values)
 
gboolean fl_settings_portal_start (FlSettingsPortal *portal, GError **error)
 

Function Documentation

◆ fl_settings_portal_new()

FlSettingsPortal* fl_settings_portal_new ( )

FlSettingsPortal: #FlSettingsPortal reads settings from the XDG desktop portal. fl_settings_portal_new:

Creates a new settings portal instance.

Returns: a new #FlSettingsPortal.

Definition at line 263 of file fl_settings_portal.cc.

263  {
264  g_autoptr(GVariantDict) values = g_variant_dict_new(nullptr);
265  return fl_settings_portal_new_with_values(values);
266 }

References fl_settings_portal_new_with_values().

Referenced by fl_settings_new().

◆ fl_settings_portal_new_with_values()

FlSettingsPortal* fl_settings_portal_new_with_values ( GVariantDict *  values)

fl_settings_portal_new_with_values: @values: (nullable): a #GVariantDict.

Creates a new settings portal instance with initial values for testing.

Returns: a new #FlSettingsPortal.

Definition at line 268 of file fl_settings_portal.cc.

268  {
269  g_return_val_if_fail(values != nullptr, nullptr);
270  FlSettingsPortal* portal =
271  FL_SETTINGS_PORTAL(g_object_new(fl_settings_portal_get_type(), nullptr));
272  portal->values = g_variant_dict_ref(values);
273  return portal;
274 }

Referenced by fl_settings_portal_new(), and TEST().

◆ fl_settings_portal_start()

gboolean fl_settings_portal_start ( FlSettingsPortal *  portal,
GError **  error 
)

fl_settings_portal_start: @portal: an #FlSettingsPortal. @error: (allow-none): #GError location to store the error occurring, or NULL

Reads the current settings and starts monitoring for changes in the desktop portal settings.

Returns: TRUE on success, or FALSE if the portal is not available.

Definition at line 276 of file fl_settings_portal.cc.

276  {
277  g_return_val_if_fail(FL_IS_SETTINGS_PORTAL(self), false);
278  g_return_val_if_fail(self->dbus_proxy == nullptr, false);
279 
280  self->dbus_proxy = g_dbus_proxy_new_for_bus_sync(
281  G_BUS_TYPE_SESSION, G_DBUS_PROXY_FLAGS_NONE, nullptr, kPortalName,
282  kPortalPath, kPortalSettings, nullptr, error);
283 
284  if (self->dbus_proxy == nullptr) {
285  return FALSE;
286  }
287 
288  for (const FlSetting setting : kAllSettings) {
289  g_autoptr(GVariant) value = nullptr;
290  if (settings_portal_read(self->dbus_proxy, setting.ns, setting.key,
291  &value)) {
292  set_value(self, &setting, value);
293  }
294  }
295 
296  g_signal_connect_object(self->dbus_proxy, "g-signal",
297  G_CALLBACK(settings_portal_changed_cb), self,
298  static_cast<GConnectFlags>(0));
299 
300  return true;
301 }

References error, kAllSettings, kPortalName, kPortalPath, kPortalSettings, set_value(), settings_portal_changed_cb(), settings_portal_read(), and value.

Referenced by fl_settings_new().

◆ G_DECLARE_FINAL_TYPE()

G_BEGIN_DECLS G_DECLARE_FINAL_TYPE ( FlSettingsPortal  ,
fl_settings_portal  ,
FL  ,
SETTINGS_PORTAL  ,
GObject   
)
fl_settings_portal_new_with_values
FlSettingsPortal * fl_settings_portal_new_with_values(GVariantDict *values)
Definition: fl_settings_portal.cc:268
kPortalPath
static constexpr char kPortalPath[]
Definition: fl_settings_portal.cc:11
FlSetting
Definition: fl_settings_portal.cc:14
settings_portal_read
static gboolean settings_portal_read(GDBusProxy *proxy, const gchar *ns, const gchar *key, GVariant **out)
Definition: fl_settings_portal.cc:113
kPortalName
static constexpr char kPortalName[]
Definition: fl_settings_portal.cc:10
error
const uint8_t uint32_t uint32_t GError ** error
Definition: fl_pixel_buffer_texture_test.cc:40
kPortalSettings
static constexpr char kPortalSettings[]
Definition: fl_settings_portal.cc:12
set_value
static void set_value(FlSettingsPortal *portal, const FlSetting *setting, GVariant *value)
Definition: fl_settings_portal.cc:94
settings_portal_changed_cb
static void settings_portal_changed_cb(GDBusProxy *proxy, const char *sender_name, const char *signal_name, GVariant *parameters, gpointer user_data)
Definition: fl_settings_portal.cc:147
value
uint8_t value
Definition: fl_standard_message_codec.cc:36
kAllSettings
static const FlSetting kAllSettings[]
Definition: fl_settings_portal.cc:57