示例#1
0
/**
 * cd_sensor_dbus_emit_property_changed:
 **/
static void
cd_sensor_dbus_emit_property_changed (CdSensor *sensor,
				      const gchar *property_name,
				      GVariant *property_value)
{
	CdSensorPrivate *priv = GET_PRIVATE (sensor);
	GVariantBuilder builder;
	GVariantBuilder invalidated_builder;

	/* not yet connected */
	if (priv->connection == NULL)
		return;

	/* build the dict */
	g_variant_builder_init (&invalidated_builder, G_VARIANT_TYPE ("as"));
	g_variant_builder_init (&builder, G_VARIANT_TYPE_ARRAY);
	g_variant_builder_add (&builder,
			       "{sv}",
			       property_name,
			       property_value);
	g_debug ("CdSensor: emit PropertiesChanged(%s)", property_name);
	g_dbus_connection_emit_signal (priv->connection,
				       NULL,
				       priv->object_path,
				       "org.freedesktop.DBus.Properties",
				       "PropertiesChanged",
				       g_variant_new ("(sa{sv}as)",
				       COLORD_DBUS_INTERFACE_SENSOR,
				       &builder,
				       &invalidated_builder),
				       NULL);
	g_variant_builder_clear (&builder);
	g_variant_builder_clear (&invalidated_builder);
}
示例#2
0
static int
app_action (gchar **args)
{
  GVariantBuilder params;
  const gchar *name;

  if (!app_check_name (args, "action"))
    return 1;

  if (args[1] == NULL)
    {
      g_printerr (_("action name must be given after application id\n"));
      return 1;
    }

  name = args[1];

  if (!g_action_name_is_valid (name))
    {
      g_printerr (_("invalid action name: '%s'\n"
                    "action names must consist of only alphanumerics, '-' and '.'\n"), name);
      return 1;
    }

  g_variant_builder_init (&params, G_VARIANT_TYPE ("av"));

  if (args[2])
    {
      GError *error = NULL;
      GVariant *parameter;

      parameter = g_variant_parse (NULL, args[2], NULL, NULL, &error);

      if (!parameter)
        {
          gchar *context;

          context = g_variant_parse_error_print_context (error, args[2]);
          g_printerr (_("error parsing action parameter: %s\n"), context);
          g_variant_builder_clear (&params);
          g_error_free (error);
          g_free (context);
          return 1;
        }

      g_variant_builder_add (&params, "v", parameter);
      g_variant_unref (parameter);

      if (args[3])
        {
          g_printerr (_("actions accept a maximum of one parameter\n"));
          g_variant_builder_clear (&params);
          return 1;
        }
    }

  return app_call (args[0], "ActivateAction", g_variant_new ("(sav@a{sv})", name, &params, app_get_platform_data ()));
}
static GVariant *
create_translation_dict (GHashTable * ht_strings, const gchar * en)
{
  GVariantBuilder array;
  guint count = 0;
  GList *l;

  g_variant_builder_init (&array, G_VARIANT_TYPE_ARRAY);

  for (l = langs; l != NULL; l = l->next) {
    const gchar *trans, *lang;

    lang = (const gchar *) l->data;
    trans = g_hash_table_lookup (ht_strings, (gpointer) lang);
    if (trans != NULL && *trans != '\0' && strcmp (en, trans) != 0 &&
        !skip_translation (ht_strings, lang, trans)) {
      /* g_print ("%s (%s) => %s\n", en, lang, trans); */
      g_variant_builder_add_value (&array,
          g_variant_new_dict_entry (g_variant_new_string (lang),
              g_variant_new_string (trans)));
      ++count;
    }
  }

  if (count == 0) {
    g_variant_builder_clear (&array);
    return NULL;
  }

  return g_variant_builder_end (&array);
}
示例#4
0
static void
nautilus_application_select (NautilusApplication *self,
			     GFile **files,
			     gint len)
{
	GDBusConnection *connection = g_application_get_dbus_connection (G_APPLICATION (self));
	GVariantBuilder builder;
	gint idx;
	gchar *uri;

	g_variant_builder_init (&builder, G_VARIANT_TYPE ("as"));
	for (idx = 0; idx < len; idx++) {
		uri = g_file_get_uri (files[idx]);
		g_variant_builder_add (&builder, "s", uri);
		g_free (uri);
	}

	g_dbus_connection_call (connection,
				NAUTILUS_FDO_DBUS_NAME,
				NAUTILUS_FDO_DBUS_PATH,
				NAUTILUS_FDO_DBUS_IFACE,
				"ShowItems",
				g_variant_new ("(ass)", &builder, ""), NULL,
				G_DBUS_CALL_FLAGS_NONE, G_MAXINT, NULL,
				select_items_ready_cb, self);

	g_variant_builder_clear (&builder);
}
示例#5
0
GVariant *
g_mount_spec_to_dbus_with_path (GMountSpec *spec,
				const char *path)
{
  GVariantBuilder builder;
  GVariant *v;
  int i;

  g_variant_builder_init (&builder, G_VARIANT_TYPE_VARDICT);
  for (i = 0; i < spec->items->len; i++)
    {
      GMountSpecItem *item = &g_array_index (spec->items, GMountSpecItem, i);

      g_variant_builder_add_value (&builder, g_variant_new ("{sv}",
                                                            item->key,
                                                            g_variant_new_bytestring (item->value)));
    }
  
  v = g_variant_new ("(^aya{sv})",
                      path ? path : "",
                      &builder);
  g_variant_builder_clear (&builder);
  
  return v;
}
示例#6
0
static GVariant *
read_xattrs_cb (OstreeRepo     *repo,
                const char     *relpath,
                GFileInfo      *file_info,
                gpointer        user_data)
{
    int rootfs_fd = GPOINTER_TO_INT (user_data);
    /* Hardcoded at the moment, we're only taking file caps */
    static const char *accepted_xattrs[] = { "security.capability" };
    guint i;
    gs_unref_variant GVariant *existing_xattrs = NULL;
    gs_free_variant_iter GVariantIter *viter = NULL;
    GError *local_error = NULL;
    GError **error = &local_error;
    GVariant *key, *value;
    GVariantBuilder builder;

    if (relpath[0] == '/')
        relpath++;

    g_variant_builder_init (&builder, G_VARIANT_TYPE ("a(ayay)"));

    if (!*relpath)
    {
        if (!gs_fd_get_all_xattrs (rootfs_fd, &existing_xattrs, NULL, error))
            goto out;
    }
    else
    {
        if (!gs_dfd_and_name_get_all_xattrs (rootfs_fd, relpath, &existing_xattrs,
                                             NULL, error))
            goto out;
    }

    viter = g_variant_iter_new (existing_xattrs);

    while (g_variant_iter_loop (viter, "(@ay@ay)", &key, &value))
    {
        for (i = 0; i < G_N_ELEMENTS (accepted_xattrs); i++)
        {
            const char *validkey = accepted_xattrs[i];
            const char *attrkey = g_variant_get_bytestring (key);
            if (g_str_equal (validkey, attrkey))
                g_variant_builder_add (&builder, "(@ay@ay)", key, value);
        }
    }

out:
    if (local_error)
    {
        g_variant_builder_clear (&builder);
        /* Unfortunately we have no way to throw from this callback */
        g_printerr ("Failed to read xattrs of '%s': %s\n",
                    relpath, local_error->message);
        exit (1);
    }
    return g_variant_ref_sink (g_variant_builder_end (&builder));
}
示例#7
0
文件: eog-util.c 项目: UIKit0/eog
void
eog_util_show_file_in_filemanager (GFile *file, GdkScreen *screen)
{
	GDBusProxy *proxy;
	gboolean done = FALSE;

	g_return_if_fail (file != NULL);

	proxy = g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SESSION,
				G_DBUS_PROXY_FLAGS_DO_NOT_CONNECT_SIGNALS |
				G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES,
				NULL, "org.freedesktop.FileManager1",
				"/org/freedesktop/FileManager1",
				"org.freedesktop.FileManager1",
				NULL, NULL);

	if (proxy) {
		gchar *uri = g_file_get_uri (file);
		gchar *startup_id;
		GVariant *params, *result;
		GVariantBuilder builder;

		g_variant_builder_init (&builder,
					G_VARIANT_TYPE ("as"));
		g_variant_builder_add (&builder, "s", uri);

		/* This seems to be the expected format, as other values
		   cause the filemanager window not to get focus. */
		startup_id = g_strdup_printf("_TIME%u",
					     gtk_get_current_event_time());

		/* params is floating! */
		params = g_variant_new ("(ass)", &builder, startup_id);

		g_free (startup_id);
		g_variant_builder_clear (&builder);

		/* Floating params-GVariant is consumed here */
		result = g_dbus_proxy_call_sync (proxy, "ShowItems",
						 params, G_DBUS_CALL_FLAGS_NONE,
						 -1, NULL, NULL);

		/* Receiving a non-NULL result counts as a successful call. */
		if (G_LIKELY (result != NULL)) {
			done = TRUE;
			g_variant_unref (result);
		}

		g_free (uri);
		g_object_unref (proxy);
	}

	/* Fallback to gtk_show_uri() if launch over DBus is not possible */
	if (!done)
		_eog_util_show_file_in_filemanager_fallback (file, screen);
}
示例#8
0
gboolean
ostree_get_xattrs_for_file (GFile         *f,
                            GVariant     **out_xattrs,
                            GCancellable  *cancellable,
                            GError       **error)
{
  gboolean ret = FALSE;
  const char *path;
  ssize_t bytes_read;
  ot_lvariant GVariant *ret_xattrs = NULL;
  ot_lfree char *xattr_names = NULL;
  ot_lfree char *xattr_names_canonical = NULL;
  GVariantBuilder builder;
  gboolean builder_initialized = FALSE;

  path = ot_gfile_get_path_cached (f);

  g_variant_builder_init (&builder, G_VARIANT_TYPE ("a(ayay)"));
  builder_initialized = TRUE;

  bytes_read = llistxattr (path, NULL, 0);

  if (bytes_read < 0)
    {
      if (errno != ENOTSUP)
        {
          ot_util_set_error_from_errno (error, errno);
          goto out;
        }
    }
  else if (bytes_read > 0)
    {
      xattr_names = g_malloc (bytes_read);
      if (llistxattr (path, xattr_names, bytes_read) < 0)
        {
          ot_util_set_error_from_errno (error, errno);
          goto out;
        }
      xattr_names_canonical = canonicalize_xattrs (xattr_names, bytes_read);
      
      if (!read_xattr_name_array (path, xattr_names_canonical, bytes_read, &builder, error))
        goto out;
    }

  ret_xattrs = g_variant_builder_end (&builder);
  g_variant_ref_sink (ret_xattrs);
  
  ret = TRUE;
  ot_transfer_out_value (out_xattrs, &ret_xattrs);
 out:
  if (!builder_initialized)
    g_variant_builder_clear (&builder);
  return ret;
}
示例#9
0
void
files_copy_via_dbus (GFile *file_list[], guint num, GFile *dest_dir)
{
    g_debug ("files copy start ...\n");
    guint i = 0;
    GVariantBuilder builder;

    g_variant_builder_init (&builder, G_VARIANT_TYPE("as"));
    for ( ; i < num; i++ ) {
        gchar *src_uri = g_file_get_uri (file_list[i]);
        g_variant_builder_add (&builder, "s", src_uri);
        g_free (src_uri);
    }
    gchar *dest_uri = g_file_get_uri (dest_dir);
    call_method_via_dbus (&builder, dest_uri);
    g_variant_builder_clear (&builder);
    g_free (dest_uri);
}
static int _worker_req_handler(void *context)
{
	GVariant *value;
	char *host_address;
	int ret, conn_type;
	GVariantBuilder payload_builder;
	struct icd_req_context *ctx = context;

	RETV_IF(NULL == ctx, IOTCON_ERROR_INVALID_PARAMETER);

	g_variant_builder_init(&payload_builder, G_VARIANT_TYPE("av"));
	if (ctx->payload) {
		g_variant_builder_add(&payload_builder, "v", ctx->payload);
		ctx->payload = NULL;
	}

	ret = icd_ioty_get_host_address(&ctx->dev_addr, &host_address, &conn_type);
	if (IOTCON_ERROR_NONE != ret) {
		ERR("icd_ioty_get_host_address() Fail(%d)", ret);
		g_variant_builder_clear(&payload_builder);
		return ret;
	}

	value = g_variant_new("(siia(qs)a(ss)iiavxx)",
			host_address,
			conn_type,
			ctx->request_type,
			ctx->options,
			ctx->query,
			ctx->observe_type,
			ctx->observe_id,
			&payload_builder,
			ICD_POINTER_TO_INT64(ctx->request_h),
			ICD_POINTER_TO_INT64(ctx->resource_h));

	free(host_address);

	ret = _ocprocess_response_signal(ctx->bus_name, IC_DBUS_SIGNAL_REQUEST_HANDLER,
			ctx->signal_number, value);
	if (IOTCON_ERROR_NONE != ret)
		ERR("_ocprocess_response_signal() Fail(%d)", ret);

	return ret;
}
示例#11
0
GVariant *
g_settings_set_mapping (const GValue       *value,
                        const GVariantType *expected_type,
                        gpointer            user_data)
{
  gchar *type_string;

  if (G_VALUE_HOLDS_BOOLEAN (value))
    {
      if (g_variant_type_equal (expected_type, G_VARIANT_TYPE_BOOLEAN))
        return g_variant_new_boolean (g_value_get_boolean (value));
    }

  else if (G_VALUE_HOLDS_CHAR (value)  ||
           G_VALUE_HOLDS_UCHAR (value))
    {
      if (g_variant_type_equal (expected_type, G_VARIANT_TYPE_BYTE))
        {
          if (G_VALUE_HOLDS_CHAR (value))
            return g_variant_new_byte (g_value_get_char (value));
          else
            return g_variant_new_byte (g_value_get_uchar (value));
        }
    }

  else if (G_VALUE_HOLDS_INT (value)   ||
           G_VALUE_HOLDS_INT64 (value))
    return g_settings_set_mapping_int (value, expected_type);

  else if (G_VALUE_HOLDS_DOUBLE (value))
    return g_settings_set_mapping_float (value, expected_type);

  else if (G_VALUE_HOLDS_UINT (value)  ||
           G_VALUE_HOLDS_UINT64 (value))
    return g_settings_set_mapping_unsigned_int (value, expected_type);

  else if (G_VALUE_HOLDS_STRING (value))
    {
      if (g_value_get_string (value) == NULL)
        return NULL;
      else if (g_variant_type_equal (expected_type, G_VARIANT_TYPE_STRING))
        return g_variant_new_string (g_value_get_string (value));
      else if (g_variant_type_equal (expected_type, G_VARIANT_TYPE_BYTESTRING))
        return g_variant_new_bytestring (g_value_get_string (value));
      else if (g_variant_type_equal (expected_type, G_VARIANT_TYPE_OBJECT_PATH))
        return g_variant_new_object_path (g_value_get_string (value));
      else if (g_variant_type_equal (expected_type, G_VARIANT_TYPE_SIGNATURE))
        return g_variant_new_signature (g_value_get_string (value));
    }

  else if (G_VALUE_HOLDS (value, G_TYPE_STRV))
    {
      if (g_value_get_boxed (value) == NULL)
        return NULL;
      return g_variant_new_strv ((const gchar **) g_value_get_boxed (value),
                                 -1);
    }

  else if (G_VALUE_HOLDS_ENUM (value))
    {
      GEnumValue *enumval;
      GEnumClass *eclass;

      /* GParamSpecEnum holds a ref on the class so we just peek... */
      eclass = g_type_class_peek (G_VALUE_TYPE (value));
      enumval = g_enum_get_value (eclass, g_value_get_enum (value));

      if (enumval)
        return g_variant_new_string (enumval->value_nick);
      else
        return NULL;
    }

  else if (G_VALUE_HOLDS_FLAGS (value))
    {
      GVariantBuilder builder;
      GFlagsValue *flagsval;
      GFlagsClass *fclass;
      guint flags;

      fclass = g_type_class_peek (G_VALUE_TYPE (value));
      flags = g_value_get_flags (value);

      g_variant_builder_init (&builder, G_VARIANT_TYPE ("as"));
      while (flags)
        {
          flagsval = g_flags_get_first_value (fclass, flags);

          if (flagsval == NULL)
            {
              g_variant_builder_clear (&builder);
              return NULL;
            }

          g_variant_builder_add (&builder, "s", flagsval->value_nick);
          flags &= ~flagsval->value;
        }

      return g_variant_builder_end (&builder);
    }

  type_string = g_variant_type_dup_string (expected_type);
  g_critical ("No GSettings bind handler for type \"%s\".", type_string);
  g_free (type_string);

  return NULL;
}