Exemplo n.º 1
0
GVariant *
ostree_zlib_file_header_new (GFileInfo         *file_info,
                             GVariant          *xattrs)
{
  guint64 size;
  guint32 uid;
  guint32 gid;
  guint32 mode;
  guint32 rdev;
  const char *symlink_target;
  GVariant *ret;
  ot_lvariant GVariant *tmp_xattrs = NULL;

  size = g_file_info_get_size (file_info);
  uid = g_file_info_get_attribute_uint32 (file_info, "unix::uid");
  gid = g_file_info_get_attribute_uint32 (file_info, "unix::gid");
  mode = g_file_info_get_attribute_uint32 (file_info, "unix::mode");
  rdev = g_file_info_get_attribute_uint32 (file_info, "unix::rdev");

  if (g_file_info_get_file_type (file_info) == G_FILE_TYPE_SYMBOLIC_LINK)
    symlink_target = g_file_info_get_symlink_target (file_info);
  else
    symlink_target = "";

  if (xattrs == NULL)
    tmp_xattrs = g_variant_ref_sink (g_variant_new_array (G_VARIANT_TYPE ("(ayay)"), NULL, 0));

  ret = g_variant_new ("([email protected](ayay))",
                       GUINT64_TO_BE (size), GUINT32_TO_BE (uid),
                       GUINT32_TO_BE (gid), GUINT32_TO_BE (mode), GUINT32_TO_BE (rdev),
                       symlink_target, xattrs ? xattrs : tmp_xattrs);
  g_variant_ref_sink (ret);
  return ret;
}
static void
_answer_clicked(void *_data, Evas_Object * obj,
				 void *event_info)
{
	(void) obj;
	(void) event_info;
	GHashTable *options;
	struct MessageShowViewData *view = (struct MessageShowViewData *) _data;

	g_debug("message_show_view_answer_clicked()");

	options = g_hash_table_new_full(g_str_hash, g_str_equal,
					NULL, common_utils_variant_unref);
        if (!view->number) {
		g_warning("Trying to answer a message without number?!");
		return;
	}
	g_hash_table_insert(options, "Phone",
			      g_variant_ref_sink(g_variant_new_string(view->number)));
	if (view->name) {
		g_hash_table_insert(options, "Name",
			    g_variant_ref_sink(g_variant_new_string(view->name)));
	}
	if (view->photopath) {
		g_hash_table_insert(options, "Photo",
			g_variant_ref_sink(g_variant_new_string(view->photopath)));
	}

	phoneui_messages_message_new(options);
	//g_hash_table_destroy(options);
}
Exemplo n.º 3
0
static gboolean
ol_config_proxy_set_default (OlConfigProxy *config,
                             const gchar *key,
                             GVariant *value)
{
  ol_assert_ret (key != NULL && key[0] != '\0', FALSE);
  OlConfigProxyPrivate *priv = OL_CONFIG_PROXY_GET_PRIVATE (config);
  if (key[0] == '.' && !g_hash_table_lookup (priv->temp_values, key))
  {
    g_variant_ref_sink (value);
    g_hash_table_insert (priv->temp_values,
                         g_strdup (key),
                         g_variant_new ("(*)", g_variant_ref_sink (value)));
    g_signal_emit (config,
                   _signals[SIGNAL_CHANGED],
                   g_quark_from_string (key),
                   key);
    g_variant_unref (value);
  }
  else
  {
    if (priv->default_builder == NULL)
    {
      priv->default_builder = g_variant_builder_new (G_VARIANT_TYPE ("a{sv}"));
      priv->default_sync_handler = g_timeout_add (DEFAULT_SYNC_TIMEOUT,
                                                  (GSourceFunc) _sync_default_cb,
                                                  config);
    }
    g_variant_builder_add (priv->default_builder, "{sv}", key, value);
  }
  return TRUE;
}
Exemplo n.º 4
0
static GVariant *prv_get_prop(dleyna_settings_t *settings, const gchar *prop)
{
	GVariant *retval = NULL;
#if DLEYNA_LOG_LEVEL & DLEYNA_LOG_LEVEL_DEBUG
	gchar *prop_str;
#endif

	if (!strcmp(prop, DLR_INTERFACE_PROP_NEVER_QUIT))
		retval = g_variant_ref_sink(g_variant_new_boolean(
					dleyna_settings_is_never_quit(
								settings)));
	else if (!strcmp(prop, DLR_INTERFACE_PROP_WHITE_LIST_ENABLED))
		retval = g_variant_ref_sink(g_variant_new_boolean(
					dleyna_settings_is_white_list_enabled(
								settings)));
	else if (!strcmp(prop, DLR_INTERFACE_PROP_WHITE_LIST_ENTRIES))
		retval = g_variant_ref_sink(prv_build_wl_entries(settings));

#if DLEYNA_LOG_LEVEL & DLEYNA_LOG_LEVEL_DEBUG
	if (retval) {
		prop_str = g_variant_print(retval, FALSE);
		DLEYNA_LOG_DEBUG("Prop %s = %s", prop, prop_str);
		g_free(prop_str);
	}
#endif

	return retval;
}
static void
_number_button_add_clicked(void *data, Evas_Object *obj, void *event_info)
{
	(void) obj;
	(void) event_info;
	struct MessageNewViewData *view = (struct MessageNewViewData *)data;

	if (phone_utils_sms_is_valid_number(view->number)) {
		GHashTable *properties =
			g_hash_table_new_full(g_str_hash, g_str_equal,
					 NULL, common_utils_variant_unref);
		g_hash_table_insert(properties, "Name",
				g_variant_ref_sink(g_variant_new_string("Number")));
		g_hash_table_insert(properties, "Phone",
				g_variant_ref_sink(g_variant_new_string(view->number)));
		g_hash_table_insert(properties, "Photo",
				g_variant_ref_sink(g_variant_new_string(CONTACT_NUMBER_PHOTO)));
		g_ptr_array_add(view->recipients, properties);
		_process_recipient(properties, view);
		view->number[0] = '\0';
		view->number_length = 0;
		_number_update_number(view);
		elm_naviframe_item_simple_promote(view->pager, view->layout_recipients);
	}
	else {
		if (!view->notify) {
			view->notify = ui_utils_notify(ui_utils_view_window_get(VIEW_PTR(*view)), D_("You have entered<br>an invalid number."), 5);
		}
		evas_object_show(view->notify);
	}
}
Exemplo n.º 6
0
static struct sr_option *get_options(void)
{
	if (!options[0].def) {
		options[0].def = g_variant_ref_sink(g_variant_new_int32(DEFAULT_NUM_CHANNELS));
		options[1].def = g_variant_ref_sink(g_variant_new_uint64(DEFAULT_SAMPLERATE));
	}

	return options;
}
Exemplo n.º 7
0
static void
_add_entry(GHashTable *entry)
{
	Elm_Object_Item *glit;
	GVariant *val;
	int received = 0, answered = 0;

	val = g_hash_table_lookup(entry, "Direction");
	if (val) {
		const char *dir = g_variant_get_string(val, NULL);
		if (!strcmp(dir, "in")) {
			received = 1;
		}
	}
	else {
		g_warning("ignoring call without Direction field!!");
		return;
	}

	val = g_hash_table_lookup(entry, "Answered");
	if (val) {
		if (g_variant_get_boolean(val)) {
			answered = 1;
		}
	}

	glit = elm_genlist_item_append(view.list_all, &itc,
			g_hash_table_ref(entry),
			NULL, ELM_GENLIST_ITEM_NONE, NULL, NULL);
	val = g_variant_new_int32(GPOINTER_TO_INT(glit));
	g_hash_table_insert(entry, "_item_all", g_variant_ref_sink(val));
	if (received) {
		if (answered) {
			glit = elm_genlist_item_append(view.list_in, &itc,
					g_hash_table_ref(entry),
					NULL, ELM_GENLIST_ITEM_NONE, NULL, NULL);
			val = g_variant_new_int32(GPOINTER_TO_INT(glit));
			g_hash_table_insert(entry, "_item_in", g_variant_ref_sink(val));
		}
		else {
			glit = elm_genlist_item_append(view.list_missed, &itc,
					g_hash_table_ref(entry),
					NULL, ELM_GENLIST_ITEM_NONE, NULL, NULL);
			val = g_variant_new_int32(GPOINTER_TO_INT(glit));
			g_hash_table_insert(entry, "_item_missed",
					g_variant_ref_sink(val));
		}
	}
	else {
		glit = elm_genlist_item_append(view.list_out, &itc,
				g_hash_table_ref(entry),
				NULL, ELM_GENLIST_ITEM_NONE, NULL, NULL);
		val = g_variant_new_int32(GPOINTER_TO_INT(glit));
		g_hash_table_insert(entry, "_item_out",
				g_variant_ref_sink(val));
	}
}
Exemplo n.º 8
0
static void
init_gsettings (void)
{
#ifdef HAVE_GSETTINGS
  GVariant *val;
  const gchar *const *schemas;
  int schema_found = 0;

#if ! GLIB_CHECK_VERSION (2, 36, 0)
  g_type_init ();
#endif

  schemas = g_settings_list_schemas ();
  if (schemas == NULL) return;
  while (! schema_found && *schemas != NULL)
    schema_found = strcmp (*schemas++, GSETTINGS_SCHEMA) == 0;
  if (!schema_found) return;

  gsettings_client = g_settings_new (GSETTINGS_SCHEMA);
  if (!gsettings_client) return;
  g_object_ref_sink (G_OBJECT (gsettings_client));
  g_signal_connect (G_OBJECT (gsettings_client), "changed",
                    G_CALLBACK (something_changed_gsettingsCB), NULL);

  val = g_settings_get_value (gsettings_client, GSETTINGS_TOOL_BAR_STYLE);
  if (val)
    {
      g_variant_ref_sink (val);
      if (g_variant_is_of_type (val, G_VARIANT_TYPE_STRING))
        current_tool_bar_style
          = map_tool_bar_style (g_variant_get_string (val, NULL));
      g_variant_unref (val);
    }

#ifdef HAVE_XFT
  val = g_settings_get_value (gsettings_client, GSETTINGS_MONO_FONT);
  if (val)
    {
      g_variant_ref_sink (val);
      if (g_variant_is_of_type (val, G_VARIANT_TYPE_STRING))
        current_mono_font = xstrdup (g_variant_get_string (val, NULL));
      g_variant_unref (val);
    }

  val = g_settings_get_value (gsettings_client, GSETTINGS_FONT_NAME);
  if (val)
    {
      g_variant_ref_sink (val);
      if (g_variant_is_of_type (val, G_VARIANT_TYPE_STRING))
        current_font = xstrdup (g_variant_get_string (val, NULL));
      g_variant_unref (val);
    }
#endif /* HAVE_XFT */

#endif /* HAVE_GSETTINGS */
}
Exemplo n.º 9
0
/*****************************************************************************
 * neardal_set_adapter_property: Set a property on a specific NEARDAL adapter
 ****************************************************************************/
errorCode_t neardal_set_adapter_property(const char *adpName,
					   int adpPropId, void *value)
{
	errorCode_t	err		= NEARDAL_SUCCESS;
	AdpProp		*adpProp	= NULL;
	const gchar	*propKey	= NULL;
	GVariant	*propValue	= NULL;
	GVariant	*variantTmp	= NULL;

	if (neardalMgr.proxy == NULL)
		neardal_prv_construct(&err);

	if (err != NEARDAL_SUCCESS || adpName == NULL)
		goto exit;

	err = neardal_mgr_prv_get_adapter((gchar *) adpName, &adpProp);
	if (err != NEARDAL_SUCCESS)
		goto exit;

	switch (adpPropId) {
	case NEARD_ADP_PROP_POWERED:
		propKey = "Powered";
		variantTmp = g_variant_new_boolean(GPOINTER_TO_UINT(value));
		g_variant_ref_sink(variantTmp);
		break;
	default:
		break;
	}

	propValue = g_variant_new_variant(variantTmp);
	g_variant_ref_sink(propValue);
	NEARDAL_TRACE_LOG("Sending:\n%s=%s\n", propKey,
			  g_variant_print(propValue, TRUE));

	properties_call_set_sync(adpProp->props, "org.neard.Adapter",
				propKey, propValue, 0, &neardalMgr.gerror);

	if (neardalMgr.gerror == NULL)
		err = NEARDAL_SUCCESS;
	else {
		NEARDAL_TRACE_ERR(
			"DBUS Error (%d): %s\n",
				 neardalMgr.gerror->code,
				neardalMgr.gerror->message);
		err = NEARDAL_ERROR_DBUS_INVOKE_METHOD_ERROR;
	}

exit:
	neardal_tools_prv_free_gerror(&neardalMgr.gerror);
	neardalMgr.gerror = NULL;
	g_variant_unref(propValue);
	g_variant_unref(variantTmp);
	return err;
}
Exemplo n.º 10
0
static const struct sr_option *get_options(void)
{
	if (!options[0].def) {
		options[0].def = g_variant_ref_sink(g_variant_new_string("all"));
		options[0].values = g_slist_append(options[0].values,
				g_variant_ref_sink(g_variant_new_string("all")));
		options[0].values = g_slist_append(options[0].values,
				g_variant_ref_sink(g_variant_new_string("spec")));
	}

	return options;
}
Exemplo n.º 11
0
/**
 * tp_variant_convert:
 * @variant: (transfer full): a #GVariant to convert
 * @type: a #GVariantType @variant must be converted to
 *
 * Convert the type of @variant to @type if possible. This takes ownership of
 * @variant. If no conversion is needed, simply return @variant. If conversion
 * is not possible, %NULL is returned.
 *
 * Returns: (transfer full): a new #GVariant owned by the caller.
 * Since: 0.19.10
 **/
GVariant *
tp_variant_convert (GVariant *variant,
    const GVariantType *type)
{
  GVariant *ret = NULL;
  gboolean valid;

  if (variant == NULL)
    return NULL;

  g_variant_ref_sink (variant);

  if (g_variant_is_of_type (variant, type))
    return variant;

  switch (tp_variant_type_classify (type))
    {
      #define CASE(type) \
        { \
          g##type tmp = _tp_variant_convert_##type (variant, &valid); \
          if (valid) \
            ret = g_variant_new_##type (tmp); \
        }
      case G_VARIANT_CLASS_DOUBLE:
        CASE (double);
        break;

      case G_VARIANT_CLASS_INT32:
        CASE (int32);
        break;

      case G_VARIANT_CLASS_INT64:
        CASE (int64);
        break;

      case G_VARIANT_CLASS_UINT32:
        CASE (uint32);
        break;

      case G_VARIANT_CLASS_UINT64:
        CASE (uint64);
        break;

      default:
        break;
      #undef CASE
    }

  g_variant_unref (variant);

  return (ret != NULL) ? g_variant_ref_sink (ret) : NULL;
}
Exemplo n.º 12
0
static void
something_changed_gsettingsCB (GSettings *settings,
                               gchar *key,
                               gpointer user_data)
{
  GVariant *val;

  if (strcmp (key, GSETTINGS_TOOL_BAR_STYLE) == 0)
    {
      val = g_settings_get_value (settings, GSETTINGS_TOOL_BAR_STYLE);
      if (val)
        {
          g_variant_ref_sink (val);
          if (g_variant_is_of_type (val, G_VARIANT_TYPE_STRING))
            {
              const gchar *newstyle = g_variant_get_string (val, NULL);
              store_tool_bar_style_changed (newstyle, first_dpyinfo);
            }
          g_variant_unref (val);
        }
    }
#ifdef HAVE_XFT
  else if (strcmp (key, GSETTINGS_MONO_FONT) == 0)
    {
      val = g_settings_get_value (settings, GSETTINGS_MONO_FONT);
      if (val)
        {
          g_variant_ref_sink (val);
          if (g_variant_is_of_type (val, G_VARIANT_TYPE_STRING))
            {
              const gchar *newfont = g_variant_get_string (val, NULL);
              store_monospaced_changed (newfont);
            }
          g_variant_unref (val);
        }
    }
  else if (strcmp (key, GSETTINGS_FONT_NAME) == 0)
    {
      val = g_settings_get_value (settings, GSETTINGS_FONT_NAME);
      if (val)
        {
          g_variant_ref_sink (val);
          if (g_variant_is_of_type (val, G_VARIANT_TYPE_STRING))
            {
              const gchar *newfont = g_variant_get_string (val, NULL);
              store_font_name_changed (newfont);
            }
          g_variant_unref (val);
        }
    }
#endif /* HAVE_XFT */
}
Exemplo n.º 13
0
static const struct sr_option *get_options(void)
{
	if (!options[0].def) {
		options[0].def = g_variant_ref_sink(g_variant_new_int32(DEFAULT_NUM_CHANNELS));
		options[1].def = g_variant_ref_sink(g_variant_new_uint64(DEFAULT_SAMPLERATE));
		options[2].def = g_variant_ref_sink(g_variant_new_string(sample_formats[0].fmt_name));
		for (unsigned int i = 0; i < ARRAY_SIZE(sample_formats); i++) {
			options[2].values = g_slist_append(options[2].values,
				g_variant_ref_sink(g_variant_new_string(sample_formats[i].fmt_name)));
		}
	}

	return options;
}
Exemplo n.º 14
0
GVariant *
mm_location_cdma_bs_get_dictionary (MMLocationCdmaBs *self)
{
    GVariantBuilder builder;

    /* We do allow NULL */
    if (!self)
        return NULL;

    g_return_val_if_fail (MM_IS_LOCATION_CDMA_BS (self), NULL);

    /* If mandatory parameters are not found, return NULL */
    if (self->priv->longitude == MM_LOCATION_LONGITUDE_UNKNOWN ||
        self->priv->latitude == MM_LOCATION_LATITUDE_UNKNOWN)
        return NULL;

    g_variant_builder_init (&builder, G_VARIANT_TYPE ("a{sv}"));
    g_variant_builder_add (&builder,
                           "{sv}",
                           PROPERTY_LONGITUDE,
                           g_variant_new_double (self->priv->longitude));
    g_variant_builder_add (&builder,
                           "{sv}",
                           PROPERTY_LATITUDE,
                           g_variant_new_double (self->priv->latitude));

    return g_variant_ref_sink (g_variant_builder_end (&builder));
}
Exemplo n.º 15
0
static void prv_process_sync_task(dld_task_t *task)
{
	GError *error;

	switch (task->type) {
	case DLD_TASK_GET_VERSION:
		task->result = g_variant_ref_sink(g_variant_new_string(
								VERSION));
		dld_task_complete(task);
		break;
	case DLD_TASK_GET_DEVICES:
		task->result = dld_upnp_get_device_ids(g_context.upnp);
		dld_task_complete(task);
		break;
	case DLD_TASK_RESCAN:
		dld_upnp_rescan(g_context.upnp);
		dld_task_complete(task);
		break;
	default:
		goto finished;
		break;
	}

	dleyna_task_queue_task_completed(task->atom.queue_id);

finished:
	return;
}
Exemplo n.º 16
0
/**
 * List all possible values for a configuration key.
 *
 * @param[in] driver The sr_dev_driver struct to query. Must not be NULL.
 * @param[in] sdi (optional) If the key is specific to a device, this must
 *            contain a pointer to the struct sr_dev_inst to be checked.
 *            Otherwise it must be NULL. If sdi is != NULL, sdi->priv must
 *            also be != NULL.
 * @param[in] cg The channel group on the device for which to list the
 *                    values, or NULL.
 * @param[in] key The configuration key (SR_CONF_*).
 * @param[in,out] data A pointer to a GVariant where the list will be stored.
 *             The caller is given ownership of the GVariant and must thus
 *             unref the GVariant after use. However if this function
 *             returns an error code, the field should be considered
 *             unused, and should not be unreferenced.
 *
 * @retval SR_OK Success.
 * @retval SR_ERR Error.
 * @retval SR_ERR_ARG The driver doesn't know that key, but this is not to be
 *          interpreted as an error by the caller; merely as an indication
 *          that it's not applicable.
 *
 * @since 0.3.0
 */
SR_API int sr_config_list(const struct sr_dev_driver *driver,
		const struct sr_dev_inst *sdi,
		const struct sr_channel_group *cg,
		uint32_t key, GVariant **data)
{
	int ret;

	if (!driver || !data)
		return SR_ERR;
	else if (!driver->config_list)
		return SR_ERR_ARG;
	else if (key != SR_CONF_SCAN_OPTIONS && key != SR_CONF_DEVICE_OPTIONS) {
		if (check_key(driver, sdi, cg, key, SR_CONF_LIST, NULL) != SR_OK)
			return SR_ERR_ARG;
	}
	if (sdi && !sdi->priv) {
		sr_err("Can't list config (sdi != NULL, sdi->priv == NULL).");
		return SR_ERR;
	}
	if ((ret = driver->config_list(key, data, sdi, cg)) == SR_OK) {
		log_key(sdi, cg, key, SR_CONF_LIST, *data);
		g_variant_ref_sink(*data);
	}

	return ret;
}
static void
ide_preferences_spin_button_value_changed (IdePreferencesSpinButton *self,
                                           GParamSpec               *pspec,
                                           GtkSpinButton            *spin_button)
{
  GVariant *variant = NULL;
  gdouble value;

  g_assert (IDE_IS_PREFERENCES_SPIN_BUTTON (self));
  g_assert (pspec != NULL);
  g_assert (GTK_IS_SPIN_BUTTON (spin_button));

  value = gtk_spin_button_get_value (spin_button);

  if (g_variant_type_equal (self->type, G_VARIANT_TYPE_DOUBLE))
    variant = g_variant_new_double (value);
  else if (g_variant_type_equal (self->type, G_VARIANT_TYPE_INT16))
    variant = g_variant_new_int16 (value);
  else if (g_variant_type_equal (self->type, G_VARIANT_TYPE_UINT16))
    variant = g_variant_new_uint16 (value);
  else if (g_variant_type_equal (self->type, G_VARIANT_TYPE_INT32))
    variant = g_variant_new_int32 (value);
  else if (g_variant_type_equal (self->type, G_VARIANT_TYPE_UINT32))
    variant = g_variant_new_uint32 (value);
  else if (g_variant_type_equal (self->type, G_VARIANT_TYPE_INT64))
    variant = g_variant_new_int64 (value);
  else if (g_variant_type_equal (self->type, G_VARIANT_TYPE_UINT64))
    variant = g_variant_new_uint64 (value);
  else
    g_return_if_reached ();

  g_variant_ref_sink (variant);
  g_settings_set_value (self->settings, self->key, variant);
  g_clear_pointer (&variant, g_variant_unref);
}
static void
g_simple_action_set_state (GAction  *action,
                           GVariant *value)
{
  GSimpleAction *simple = G_SIMPLE_ACTION (action);

  g_return_if_fail (value != NULL);

  {
    const GVariantType *state_type;

    state_type = simple->priv->state ?
                   g_variant_get_type (simple->priv->state) : NULL;
    g_return_if_fail (state_type != NULL);
    g_return_if_fail (g_variant_is_of_type (value, state_type));
  }

  g_variant_ref_sink (value);

  if (!g_variant_equal (simple->priv->state, value))
    {
      if (simple->priv->state)
        g_variant_unref (simple->priv->state);

      simple->priv->state = g_variant_ref (value);

      g_object_notify (G_OBJECT (simple), "state");
    }

  g_variant_unref (value);
}
Exemplo n.º 19
0
static void
impl_get_item_attributes (GMenuModel *menu_model, int item_index, GHashTable **attrs)
{
	RBDisplayPageMenu *menu = RB_DISPLAY_PAGE_MENU (menu_model);
	RBDisplayPage *page;
	GtkTreeIter iter;

	*attrs = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, (GDestroyNotify) g_variant_unref);

	page = get_page_at_index (menu, item_index, &iter);
	if (page != NULL) {
		char *name;
		char *ptr;
		GVariant *v;

		g_object_get (page, "name", &name, NULL);
		rb_debug ("page at %d is %s", item_index, name);
		g_hash_table_insert (*attrs, g_strdup ("label"), g_variant_new_string (name));
		g_free (name);

		g_hash_table_insert (*attrs, g_strdup ("action"), g_variant_new_string (menu->priv->action));

		ptr = g_strdup_printf ("%p", page);
		v = g_variant_new_string (ptr);
		g_hash_table_insert (*attrs, g_strdup ("target"), g_variant_ref_sink (v));
		g_free (ptr);

		g_object_unref (page);
	} else {
		rb_debug ("no page at %d", item_index);
	}
}
Exemplo n.º 20
0
/**
 * Read all input from @src, allocating a new #GVariant from it into
 * output variable @out_variant.  @src will be closed as a result.
 *
 * Note the returned @out_variant is not floating.
 */
gboolean
ot_util_variant_from_stream (GInputStream         *src,
                             const GVariantType   *type,
                             gboolean              trusted,
                             GVariant            **out_variant,
                             GCancellable         *cancellable,
                             GError              **error)
{
  gboolean ret = FALSE;
  gs_unref_object GMemoryOutputStream *data_stream = NULL;
  gs_unref_variant GVariant *ret_variant = NULL;

  data_stream = (GMemoryOutputStream*)g_memory_output_stream_new (NULL, 0, g_realloc, g_free);

  if (g_output_stream_splice ((GOutputStream*)data_stream, src,
                              G_OUTPUT_STREAM_SPLICE_CLOSE_SOURCE | G_OUTPUT_STREAM_SPLICE_CLOSE_TARGET,
                              cancellable, error) < 0)
    goto out;

  ret_variant = g_variant_new_from_data (type, g_memory_output_stream_get_data (data_stream),
                                         g_memory_output_stream_get_data_size (data_stream),
                                         trusted, (GDestroyNotify) g_object_unref, data_stream);
  data_stream = NULL; /* Transfer ownership */
  g_variant_ref_sink (ret_variant);

  ret = TRUE;
  ot_transfer_out_value (out_variant, &ret_variant);
 out:
  return ret;
}
Exemplo n.º 21
0
/**
 * ot_util_variant_map:
 * @src: a #GFile
 * @type: Use this for variant
 * @trusted: See documentation of g_variant_new_from_data()
 * @out_variant: (out): Return location for new variant
 * @error:
 *
 * Memory-map @src, and store a new #GVariant referring to this memory
 * in @out_variant.  Note the returned @out_variant is not floating.
 */
gboolean
ot_util_variant_map (GFile              *src,
                     const GVariantType *type,
                     gboolean            trusted,
                     GVariant          **out_variant,
                     GError            **error)
{
  gboolean ret = FALSE;
  gs_unref_variant GVariant *ret_variant = NULL;
  GMappedFile *mfile = NULL;

  mfile = gs_file_map_noatime (src, NULL, error);
  if (!mfile)
    goto out;

  ret_variant = g_variant_new_from_data (type,
                                         g_mapped_file_get_contents (mfile),
                                         g_mapped_file_get_length (mfile),
                                         trusted,
                                         (GDestroyNotify) g_mapped_file_unref,
                                         mfile);
  mfile = NULL;
  g_variant_ref_sink (ret_variant);
  
  ret = TRUE;
  ot_transfer_out_value(out_variant, &ret_variant);
 out:
  if (mfile)
    g_mapped_file_unref (mfile);
  return ret;
}
Exemplo n.º 22
0
/* swiss-army knife: takes an strv of pkgspecs destined for
 * install, and splits it into repo pkgs, and for local
 * pkgs, an fd list & idx variant. */
gboolean
rpmostree_sort_pkgs_strv (const char *const* pkgs,
                          GUnixFDList  *fd_list,
                          GPtrArray   **out_repo_pkgs,
                          GVariant    **out_fd_idxs,
                          GError      **error)
{
  g_autoptr(GPtrArray) repo_pkgs = g_ptr_array_new_with_free_func (g_free);
  g_auto(GVariantBuilder) builder;

  g_variant_builder_init (&builder, G_VARIANT_TYPE ("ah"));
  for (const char *const* pkg = pkgs; pkg && *pkg; pkg++)
    {
      if (!g_str_has_suffix (*pkg, ".rpm"))
        g_ptr_array_add (repo_pkgs, g_strdup (*pkg));
      else
        {
          glnx_fd_close int fd = -1;
          if (!glnx_openat_rdonly (AT_FDCWD, *pkg, TRUE, &fd, error))
            return FALSE;

          int idx = g_unix_fd_list_append (fd_list, fd, error);
          if (idx < 0)
            return FALSE;

          g_variant_builder_add (&builder, "h", idx);
        }
    }

  *out_fd_idxs = g_variant_ref_sink (g_variant_new ("ah", &builder));
  *out_repo_pkgs = g_steal_pointer (&repo_pkgs);
  return TRUE;
}
Exemplo n.º 23
0
/**
 * @brief Perform sending remote signals to connected clients.
 * @memberof GstSwitchController
 */
static void
gst_switch_controller_emit_signal (GstSwitchController * controller,
    const gchar * signame, GVariant * parameters)
{
  GError *error;
  gboolean res;
  GList *client;
  gint num;

  GST_SWITCH_CONTROLLER_LOCK_CLIENTS (controller);
  g_assert (parameters);
  g_variant_ref_sink (parameters);

  for (client = controller->clients, num = 0; client;
      client = g_list_next (client)) {
    error = NULL;
    res = g_dbus_connection_emit_signal (G_DBUS_CONNECTION (client->data),
        /*destination_bus_name */ NULL,
        SWITCH_CONTROLLER_OBJECT_PATH,
        SWITCH_CONTROLLER_OBJECT_NAME, signame, parameters, &error);

    if (!res) {
      g_assert (error != NULL);
      ERROR ("emit: (%d) %s", num, error->message);
    } else {
      ++num;
    }
  }
  /*
     INFO ("emit: %s (%d/%d)", signame, num, g_list_length (controller->uis));
   */
  g_variant_unref (parameters);

  GST_SWITCH_CONTROLLER_UNLOCK_CLIENTS (controller);
}
Exemplo n.º 24
0
/**
 * g_notification_add_button_with_target_value: (rename-to g_notification_add_button_with_target)
 * @notification: a #GNotification
 * @label: label of the button
 * @action: an action name
 * @target: (allow-none): a #GVariant to use as @action's parameter, or %NULL
 *
 * Adds a button to @notification that activates @action when clicked.
 * @action must be an application-wide action (it must start with "app.").
 *
 * If @target is non-%NULL, @action will be activated with @target as
 * its parameter.
 *
 * Since: 2.40
 */
void
g_notification_add_button_with_target_value (GNotification *notification,
                                             const gchar   *label,
                                             const gchar   *action,
                                             GVariant      *target)
{
  Button *button;

  g_return_if_fail (G_IS_NOTIFICATION (notification));
  g_return_if_fail (label != NULL);
  g_return_if_fail (action != NULL && g_action_name_is_valid (action));

  if (!g_str_has_prefix (action, "app."))
    {
      g_warning ("%s: action '%s' does not start with 'app.'."
                 "This is unlikely to work properly.", G_STRFUNC, action);
    }

  button =  g_slice_new0 (Button);
  button->label = g_strdup (label);
  button->action_name = g_strdup (action);

  if (target)
    button->target = g_variant_ref_sink (target);

  g_ptr_array_add (notification->buttons, button);
}
static void
on_notify (GObject    *object,
           GParamSpec *pspec,
           gpointer    user_data)
{
  GDBusConnection *connection;
  const gchar *path;
  GVariant *value;
  const gchar *property_name;
  guint prop_id;

  path = g_object_get_data (object, "gdbus-codegen-path");
  connection = g_object_get_data (object, "gdbus-codegen-connection");
  if (connection == NULL || path == NULL)
    goto out;

  property_name = lookup_property_name_from_property_gname (pspec->name);
  if (property_name == NULL)
    goto out;
  prop_id = lookup_property_id_from_property_name (property_name);

  value = NULL;
  switch (prop_id)
    {
  }

  if (value != NULL && property_name != NULL)
    {
      queue_notification (object, property_name, g_variant_ref_sink (value));
    }
out:
  ;
}
Exemplo n.º 26
0
static const struct sr_option *get_options(void)
{
	if (!options[0].def)
        options[0].def = g_variant_ref_sink(g_variant_new_string(""));

	return options;
}
Exemplo n.º 27
0
GVariant *dls_upnp_get_server_ids(dls_upnp_t *upnp)
{
	GVariantBuilder vb;
	GHashTableIter iter;
	gpointer value;
	dls_device_t *device;
	GVariant *retval;

	DLEYNA_LOG_DEBUG("Enter");

	g_variant_builder_init(&vb, G_VARIANT_TYPE("ao"));

	g_hash_table_iter_init(&iter, upnp->server_udn_map);
	while (g_hash_table_iter_next(&iter, NULL, &value)) {
		device = value;
		DLEYNA_LOG_DEBUG("Have device %s", device->path);
		g_variant_builder_add(&vb, "o", device->path);
	}

	retval = g_variant_ref_sink(g_variant_builder_end(&vb));

	DLEYNA_LOG_DEBUG("Exit");

	return retval;
}
Exemplo n.º 28
0
static void
variant_table_sink (GHashTable *props,
                    const gchar *name,
                    GVariant *value)
{
  g_hash_table_insert (props, (gchar *)name, g_variant_ref_sink (value));
}
Exemplo n.º 29
0
GVariant *
mm_network_timezone_get_dictionary (MMNetworkTimezone *self)
{
    GVariantBuilder builder;

    /* Allow NULL */
    if (!self)
        return NULL;

    g_return_val_if_fail (MM_IS_NETWORK_TIMEZONE (self), NULL);

    g_variant_builder_init (&builder, G_VARIANT_TYPE ("a{sv}"));

    if (self->priv->offset != MM_NETWORK_TIMEZONE_OFFSET_UNKNOWN)
        g_variant_builder_add (&builder,
                               "{sv}",
                               "offset",
                               g_variant_new_int32 (self->priv->offset));

    if (self->priv->dst_offset != MM_NETWORK_TIMEZONE_OFFSET_UNKNOWN)
        g_variant_builder_add (&builder,
                               "{sv}",
                               "dst-offset",
                               g_variant_new_int32 (self->priv->dst_offset));

    if (self->priv->leap_seconds != MM_NETWORK_TIMEZONE_LEAP_SECONDS_UNKNOWN)
        g_variant_builder_add (&builder,
                               "{sv}",
                               "leap-seconds",
                               g_variant_new_int32 (self->priv->leap_seconds));

    return g_variant_ref_sink (g_variant_builder_end (&builder));
}
Exemplo n.º 30
0
static gboolean
gconf_settings_backend_write (GSettingsBackend *backend,
                              const gchar      *key,
                              GVariant         *value,
                              gpointer          origin_tag)
{
  GConfSettingsBackend *gconf = GCONF_SETTINGS_BACKEND (backend);
  GConfValue           *gconf_value;
  GError               *error;

  g_variant_ref_sink (value);
  gconf_value = gconf_settings_backend_gvariant_to_gconf_value (value);
  g_variant_unref (value);
  if (gconf_value == NULL)
    return FALSE;

  error = NULL;
  gconf_client_set (gconf->priv->client, key, gconf_value, &error);
  gconf_value_free (gconf_value);

  if (error != NULL)
    {
      g_error_free (error);
      return FALSE;
    }

  g_settings_backend_changed (backend, key, origin_tag);

  g_hash_table_replace (gconf->priv->ignore_notifications,
                        g_strdup (key), GINT_TO_POINTER (1));

  return TRUE;
}