Example #1
0
void
ibus_rime_load_settings(IBusConfig* config)
{
  //g_debug("ibus_rime_load_settings");
  GVariant* value;

  value = ibus_config_get_value(config, "engine/Rime", "embed_preedit_text");
  if (!value) {
    value = ibus_config_get_value(config, "general", "embed_preedit_text");
  }
  if (value && g_variant_classify(value) == G_VARIANT_CLASS_BOOLEAN) {
    g_ibus_rime_settings.embed_preedit_text = g_variant_get_boolean(value);
  }

  value = ibus_config_get_value(config, "engine/Rime", "lookup_table_orientation");
  if (!value) {
    value = ibus_config_get_value(config, "panel", "lookup_table_orientation");
  }
  if (value && g_variant_classify(value) == G_VARIANT_CLASS_INT32) {
    g_ibus_rime_settings.lookup_table_orientation = g_variant_get_int32(value);
  }

  value = ibus_config_get_value(config, "engine/Rime", "color_scheme");
  if (value && g_variant_classify(value) == G_VARIANT_CLASS_STRING) {
    ibus_rime_select_color_scheme(g_variant_get_string(value, NULL));
  }
}
Example #2
0
static gint64
_tp_variant_convert_int64 (GVariant *variant,
    gboolean *valid)
{
  guint64 u;

  *valid = TRUE;

  switch (g_variant_classify (variant))
    {
      case G_VARIANT_CLASS_BYTE:
        return g_variant_get_byte (variant);

      case G_VARIANT_CLASS_UINT32:
        return g_variant_get_uint32 (variant);

      case G_VARIANT_CLASS_INT32:
        return g_variant_get_int32 (variant);

      case G_VARIANT_CLASS_INT64:
        return g_variant_get_int64 (variant);

      case G_VARIANT_CLASS_UINT64:
        u = g_variant_get_uint64 (variant);
        if (G_LIKELY (u <= G_MAXINT64))
          return u;
        break;

      default:
        break;
    }

  *valid = FALSE;
  return 0;
}
Example #3
0
static gdouble
_tp_variant_convert_double (GVariant *variant,
    gboolean *valid)
{
  *valid = TRUE;

  switch (g_variant_classify (variant))
    {
      case G_VARIANT_CLASS_DOUBLE:
        return g_variant_get_double (variant);

      case G_VARIANT_CLASS_BYTE:
        return g_variant_get_byte (variant);

      case G_VARIANT_CLASS_UINT32:
        return g_variant_get_uint32 (variant);

      case G_VARIANT_CLASS_INT32:
        return g_variant_get_int32 (variant);

      case G_VARIANT_CLASS_INT64:
        return g_variant_get_int64 (variant);

      case G_VARIANT_CLASS_UINT64:
        return g_variant_get_uint64 (variant);

      default:
        break;
    }

  *valid = FALSE;
  return 0.0;
}
Example #4
0
void
ibus_rime_config_value_changed_cb(IBusConfig* config,
                                  const gchar* section,
                                  const gchar* name,
                                  GVariant* value,
                                  gpointer unused)
{
  //g_debug("ibus_rime_config_value_changed_cb [%s/%s]", section, name);
  if (!strcmp("general", section)) {
    if (!strcmp("embed_preedit_text", name) &&
        value && g_variant_classify(value) == G_VARIANT_CLASS_BOOLEAN) {
      g_ibus_rime_settings.embed_preedit_text = g_variant_get_boolean(value);
      return;
    }
  }
  else if (!strcmp("panel", section)) {
    if (!strcmp("lookup_table_orientation", name) &&
        value && g_variant_classify(value) == G_VARIANT_CLASS_INT32) {
      g_ibus_rime_settings.lookup_table_orientation = g_variant_get_int32(value);
      return;
    }
  }
  else if (!strcmp("engine/Rime", section)) {
    if (!strcmp("embed_preedit_text", name) &&
        value && g_variant_classify(value) == G_VARIANT_CLASS_BOOLEAN) {
      GVariant* overridden = ibus_config_get_value(config, "engine/Rime", "embed_preedit_text");
      if (!overridden) {
        g_ibus_rime_settings.embed_preedit_text = g_variant_get_boolean(value);
      }
      return;
    }
    if (!strcmp("lookup_table_orientation", name) &&
        value && g_variant_classify(value) == G_VARIANT_CLASS_INT32) {
      GVariant* overridden = ibus_config_get_value(config, "engine/Rime", "lookup_table_orientation");
      if (!overridden) {
        g_ibus_rime_settings.lookup_table_orientation = g_variant_get_int32(value);
      }
      return;
    }
    if (!strcmp("color_scheme", name) &&
        value && g_variant_classify(value) == G_VARIANT_CLASS_STRING) {
      ibus_rime_select_color_scheme(g_variant_get_string(value, NULL));
      return;
    }
  }
}
QVariant gvariantToQVariant(GVariant *value)
{
	GVariantClass c = g_variant_classify(value);
	if(c == G_VARIANT_CLASS_BOOLEAN)
		return QVariant((bool) g_variant_get_boolean(value));

	else if(c == G_VARIANT_CLASS_BYTE)
		return QVariant((char) g_variant_get_byte(value));

	else if(c == G_VARIANT_CLASS_INT16)
		return QVariant((int) g_variant_get_int16(value));

	else if(c == G_VARIANT_CLASS_UINT16)
		return QVariant((unsigned int) g_variant_get_uint16(value));

	else if(c == G_VARIANT_CLASS_INT32)
		return QVariant((int) g_variant_get_int32(value));

	else if(c ==  G_VARIANT_CLASS_UINT32)
		return QVariant((unsigned int) g_variant_get_uint32(value));

	else if(c == G_VARIANT_CLASS_INT64)
		return QVariant((long long) g_variant_get_int64(value));

	else if(c == G_VARIANT_CLASS_UINT64)
		return QVariant((unsigned long long) g_variant_get_uint64(value));

	else if(c == G_VARIANT_CLASS_DOUBLE)
		return QVariant(g_variant_get_double(value));

	else if(c == G_VARIANT_CLASS_STRING)
		return QVariant(g_variant_get_string(value, NULL));

	else if(c == G_VARIANT_CLASS_ARRAY)
	{
		gsize dictsize = g_variant_n_children(value);
		QVariantList list;
		for (int i=0;i<dictsize;i++)
		{
			GVariant *childvariant = g_variant_get_child_value(value,i);
			GVariant *innervariant = g_variant_get_variant(childvariant);
			list.append(gvariantToQVariant(innervariant));
		}
		return list;
	}

	else
		return QVariant::Invalid;

}
Example #6
0
static int find_in_array(GVariant *data, const GVariantType *type,
			 const void *arr, int n)
{
	const char * const *sarr;
	const char *s;
	const uint64_t *u64arr;
	const uint8_t *u8arr;
	uint64_t u64;
	uint8_t u8;
	int i;

	if (!g_variant_is_of_type(data, type))
		return -1;

	switch (g_variant_classify(data)) {
	case G_VARIANT_CLASS_STRING:
		s = g_variant_get_string(data, NULL);
		sarr = arr;

		for (i = 0; i < n; i++)
			if (!strcmp(s, sarr[i]))
				return i;
		break;
	case G_VARIANT_CLASS_UINT64:
		u64 = g_variant_get_uint64(data);
		u64arr = arr;

		for (i = 0; i < n; i++)
			if (u64 == u64arr[i])
				return i;
		break;
	case G_VARIANT_CLASS_BYTE:
		u8 = g_variant_get_byte(data);
		u8arr = arr;

		for (i = 0; i < n; i++)
			if (u8 == u8arr[i])
				return i;
	default:
		break;
	}

	return -1;
}
Example #7
0
static gboolean
is_valid_choices (GVariant    *variant,
                  const gchar *choices)
{
  switch (g_variant_classify (variant))
    {
      case G_VARIANT_CLASS_MAYBE:
      case G_VARIANT_CLASS_ARRAY:
        {
          gsize i, n;
          GVariant *child;
          gboolean is_valid;

          n = g_variant_n_children (variant);
          for (i = 0; i < n; ++i)
            {
              child = g_variant_get_child_value (variant, i);
              is_valid = is_valid_choices (child, choices);
              g_variant_unref (child);

              if (!is_valid)
                return FALSE;
            }

          return TRUE;
        }

      case G_VARIANT_CLASS_STRING:
        {
          const gchar *string;

          g_variant_get (variant, "&s", &string);

          while ((choices = strstr (choices, string)) && choices[-1] != 0xff);

          return choices != NULL;
        }

      default:
        g_assert_not_reached ();
    }
}
Example #8
0
gchar *
go_conf_get_value_as_str (GOConfNode *node, gchar const *key)
{
	gchar *value_string;
	GVariant *value = NULL;

	if (node) {
		if (key && !strchr (key, '/') &&  !strchr (key, '.'))
			value = g_settings_get_value (node->settings, key);
		else if (node->key)
			value = g_settings_get_value (node->settings, node->key);
	}
	if (value == NULL) {
		GOConfNode *real_node = go_conf_get_node (node, key);
		value = real_node? g_settings_get_value (real_node->settings, real_node->key): NULL;
		go_conf_free_node (real_node);
	}
	switch (g_variant_classify (value)) {
	case 's':
		value_string = g_strdup (g_variant_get_string (value, NULL));
		break;
	case 'i':
		value_string = g_strdup_printf ("%i", g_variant_get_int32 (value));
		break;
	case 'd':
		value_string = g_strdup_printf ("%f", g_variant_get_double (value));
		break;
	case 'b':
		value_string = g_strdup (go_locale_boolean_name (g_variant_get_boolean (value)));
		break;
	default:
		value_string = g_strdup ("ERROR FIXME");
		break;
	}

	return value_string;
}
Example #9
0
JSValueRef dbus_to_js(JSContextRef ctx, GVariant *dbus)
{
    JSValueRef jsvalue = NULL;
    GVariantClass type = g_variant_classify(dbus);
    switch (type) {
        case G_VARIANT_CLASS_STRING:
        case G_VARIANT_CLASS_OBJECT_PATH:
        case G_VARIANT_CLASS_SIGNATURE:
            {
                JSStringRef js_string = JSStringCreateWithUTF8CString(g_variant_get_string(dbus, NULL));
                jsvalue = JSValueMakeString(ctx, js_string);
                JSStringRelease(js_string);
                return jsvalue;
            }
        case G_VARIANT_CLASS_BYTE:
            return JSValueMakeNumber(ctx, g_variant_get_byte(dbus));
        case G_VARIANT_CLASS_DOUBLE:
            return JSValueMakeNumber(ctx, g_variant_get_double(dbus));
        case G_VARIANT_CLASS_INT16:
            return JSValueMakeNumber(ctx, g_variant_get_int16(dbus));
        case G_VARIANT_CLASS_UINT16:
            return JSValueMakeNumber(ctx, g_variant_get_uint16(dbus));
        case G_VARIANT_CLASS_INT32:
            return JSValueMakeNumber(ctx, g_variant_get_int32(dbus));
        case G_VARIANT_CLASS_UINT32:
            return JSValueMakeNumber(ctx, g_variant_get_uint32(dbus));
        case G_VARIANT_CLASS_INT64:
            return JSValueMakeNumber(ctx, g_variant_get_int64(dbus));
        case G_VARIANT_CLASS_UINT64:
            return JSValueMakeNumber(ctx, g_variant_get_uint64(dbus));
        case G_VARIANT_CLASS_BOOLEAN:
            return JSValueMakeBoolean(ctx, g_variant_get_boolean(dbus));
        case G_VARIANT_CLASS_HANDLE:
            g_warning("didn't support FD type");
            return JSValueMakeNumber(ctx, g_variant_get_uint32(dbus));
        case G_VARIANT_CLASS_VARIANT:
            {
                GVariant* v = g_variant_get_variant(dbus);
                jsvalue = dbus_to_js(ctx, v);
                g_variant_unref(v);
                return jsvalue;
            }

        case G_VARIANT_CLASS_DICT_ENTRY:
            /*g_assert_not_reached();*/
            break;

        case G_VARIANT_CLASS_ARRAY:
            {
                if (g_variant_type_is_dict_entry(g_variant_type_element(g_variant_get_type(dbus)))) {
                    jsvalue = JSObjectMake(ctx, NULL, NULL);
                    for (size_t i=0; i<g_variant_n_children(dbus); i++) {
                        GVariant *dic = g_variant_get_child_value(dbus, i);
                        GVariant *key= g_variant_get_child_value (dic, 0);
                        GVariant *value = g_variant_get_child_value (dic, 1);

                        JSValueRef js_key = dbus_to_js(ctx, key);
                        JSValueRef js_value = dbus_to_js(ctx, value);

                        JSStringRef key_str = JSValueToStringCopy(ctx, js_key, NULL);
                        JSObjectSetProperty(ctx, (JSObjectRef)jsvalue, key_str, js_value, 0, NULL);
                        JSStringRelease(key_str);

                        g_variant_unref(key);
                        g_variant_unref(value);
                        g_variant_unref(dic);
                    }
                    return jsvalue;
                } else {
                    int n = g_variant_n_children(dbus);
                    JSValueRef *args = g_new(JSValueRef, n);
                    for (int i=0; i < n; i++) {
                        GVariant* v = g_variant_get_child_value(dbus, i);
                        args[i] = dbus_to_js(ctx, v);
                        g_variant_unref(v);
                    }
                    jsvalue = JSObjectMakeArray(ctx, n, args, NULL);
                    g_free(args);
                    return jsvalue;
                }
            }
        case G_VARIANT_CLASS_TUPLE:
            {
                int n = g_variant_n_children(dbus);
                jsvalue = JSObjectMakeArray(ctx, 0, NULL, NULL);
                for (int i=0; i < n; i++) {
                    GVariant* v = g_variant_get_child_value(dbus, i);
                    JSObjectSetPropertyAtIndex(ctx, (JSObjectRef)jsvalue, i, dbus_to_js(ctx, v), NULL);
                    g_variant_unref(v);
                }
                return jsvalue;
            }
        case G_VARIANT_CLASS_MAYBE:
            g_assert_not_reached();
    }
    g_warning("didn't support signature type:%c", type);
    return JSValueMakeUndefined(ctx);
}
Example #10
0
static JsonBuilder *
_json_builder_add_gvariant (JsonBuilder *builder,
                            GVariant *value)
{
  g_return_val_if_fail (JSON_IS_BUILDER (builder), builder);

  g_variant_ref_sink (value);

  switch (g_variant_classify (value))
    {
    case G_VARIANT_CLASS_BOOLEAN:
      json_builder_add_boolean_value (builder, g_variant_get_boolean (value));
      break;

    case G_VARIANT_CLASS_BYTE:
      json_builder_add_int_value (builder, g_variant_get_byte (value));
      break;

    case G_VARIANT_CLASS_INT16:
      json_builder_add_int_value (builder, g_variant_get_int16 (value));
      break;

    case G_VARIANT_CLASS_UINT16:
      json_builder_add_int_value (builder, g_variant_get_uint16 (value));
      break;

    case G_VARIANT_CLASS_INT32:
      json_builder_add_int_value (builder, g_variant_get_int32 (value));
      break;

    case G_VARIANT_CLASS_UINT32:
      json_builder_add_int_value (builder, g_variant_get_uint32 (value));
      break;

    case G_VARIANT_CLASS_INT64:
      json_builder_add_int_value (builder, g_variant_get_int64 (value));
      break;

    case G_VARIANT_CLASS_UINT64:
      json_builder_add_int_value (builder, g_variant_get_uint64 (value));
      break;

    case G_VARIANT_CLASS_HANDLE:
      json_builder_add_int_value (builder, g_variant_get_handle (value));
      break;

    case G_VARIANT_CLASS_DOUBLE:
      json_builder_add_double_value (builder, g_variant_get_double (value));
      break;

    case G_VARIANT_CLASS_STRING:      /* explicit fall-through */
    case G_VARIANT_CLASS_OBJECT_PATH: /* explicit fall-through */
    case G_VARIANT_CLASS_SIGNATURE:
      json_builder_add_string_value (builder, g_variant_get_string (value, NULL));
      break;

     /* TODO: */
    case G_VARIANT_CLASS_VARIANT:
      {
        GVariant *child;
        child = g_variant_get_variant (value);
        _json_builder_add_gvariant (builder, child);
        g_variant_unref (child);
      }
      break;

    case G_VARIANT_CLASS_MAYBE:
      g_assert_not_reached ();
      break;

    case G_VARIANT_CLASS_ARRAY:
      {
        const GVariantType *type;
        const GVariantType *element_type;

        type = g_variant_get_type (value);
        element_type = g_variant_type_element (type);
        if (g_variant_type_is_dict_entry (element_type))
          {
            GVariantIter iter;
            GVariant *child;

            json_builder_begin_object (builder);

            g_variant_iter_init (&iter, value);
            while ((child = g_variant_iter_next_value (&iter)) != NULL)
              {
                _json_builder_add_gvariant (builder, child);
                g_variant_unref (child);
              }

            json_builder_end_object (builder);
          }
        else
          {
            GVariantIter iter;
            GVariant *child;

            json_builder_begin_array (builder);

            g_variant_iter_init (&iter, value);
            while ((child = g_variant_iter_next_value (&iter)) != NULL)
              {
                _json_builder_add_gvariant (builder, child);
                g_variant_unref (child);
              }

            json_builder_end_array (builder);
          }
      }
      break;

    case G_VARIANT_CLASS_TUPLE:
      {
        GVariantIter iter;
        GVariant *child;

        json_builder_begin_array (builder);

        g_variant_iter_init (&iter, value);
        while ((child = g_variant_iter_next_value (&iter)) != NULL)
          {
            _json_builder_add_gvariant (builder, child);
            g_variant_unref (child);
          }

        json_builder_end_array (builder);
      }
      break;

    case G_VARIANT_CLASS_DICT_ENTRY:
      {
        GVariant *dict_key;
        GVariant *dict_value;
        gchar *dict_key_string;

        dict_key = g_variant_get_child_value (value, 0);
        dict_value = g_variant_get_child_value (value, 1);

        if (g_variant_is_of_type (dict_key, G_VARIANT_TYPE("s")))
          dict_key_string = g_variant_dup_string (dict_key, NULL);
        else
          dict_key_string = g_variant_print (dict_key, FALSE);

        json_builder_set_member_name (builder, dict_key_string);
        _json_builder_add_gvariant (builder, dict_value);
        g_free (dict_key_string);

        g_variant_unref (dict_key);
        g_variant_unref (dict_value);
      }
      break;
    }

  g_variant_unref (value);

  return builder;
}
Example #11
0
/* Generic qsort style comparison of variants
   For variants of the same class the "natural" order is used.
   If the types differ, we compare by value of GVariantClass
   except for:
    All numeric types (ints, double) compare by value
    All textish string types compare by utf8 collation
*/   
int
dtools_compare_variant (GVariant *a,
			GVariant *b)
{
  gint64 a64, b64;
  guint64 au64, bu64;
  double ad, bd;
  GVariantClass a_class, b_class;
  GVariant *ma, *mb;

  if (a == NULL && b == NULL)
    return 0;
  if (a == NULL)
    return 1;
  if (b == NULL)
    return -1;
  
  a_class = g_variant_classify (a);
  b_class = g_variant_classify (b);

  if (a_class == G_VARIANT_CLASS_MAYBE)
    {
      ma = g_variant_get_maybe (a);
      if (ma == NULL)
	{
	  if (b_class == G_VARIANT_CLASS_MAYBE &&
	      g_variant_get_maybe (b) == NULL)
	    return 0;
	  else
	    return 1; /* NULL sorts at end */
	}
      return dtools_compare_variant (ma, b);
    }

  if (b_class == G_VARIANT_CLASS_MAYBE)
    {
      mb = g_variant_get_maybe (b);
      if (mb == NULL)
	return -1; /* NULL sorts at end */
      return dtools_compare_variant (a, mb);
    }
  
  if (a_class == G_VARIANT_CLASS_VARIANT)
    return dtools_compare_variant (g_variant_get_child_value (a, 0),
				   b);
  
  if (b_class == G_VARIANT_CLASS_VARIANT)
    return dtools_compare_variant (a,
				   g_variant_get_child_value (b, 0));

  if (a_class == G_VARIANT_CLASS_DOUBLE &&
      b_class == G_VARIANT_CLASS_DOUBLE)
    {
      ad = g_variant_get_double (a);
      bd = g_variant_get_double (b);

      if (ad < bd)
	return -1;
      if (ad == bd)
	return 0;
      else
	return 1;
    }
  
  if (variant_class_is_int (a_class) &&
      variant_class_is_int (b_class))
    {
      if (variant_as_int64 (a, a_class, &a64) &&
	  variant_as_int64 (b, b_class, &b64))
	{
	  if (a64 < b64)
	    return -1;
	  else if (a64 == b64)
	    return 0;
	  else
	    return 1;
	}

      /* For integers the only leftover cases are:
	 a) Both a & b are uint64 (> maxint64)
	 b) One of a/b is uint64 (> maxint64)
	 b1) The other fits in uint64
	 b2) The other is < 0

	 This handles everything but case b2:
      */
      if (variant_as_uint64 (a, a_class, &au64) &&
	  variant_as_uint64 (b, b_class, &bu64))
	{
	  if (au64 < bu64)
	    return -1;
	  else if (au64 == bu64)
	    return 0;
	  else
	    return 1;
	}

      /* Handle case b2, one uint64, other is < 0  */
      if (variant_class_is_signed_int (a_class))
	/* signed but doesn't fit in uint64 => negative */
	return -1;
      else if (variant_class_is_signed_int (b_class))
	/* signed but doesn't fit in uint64 => negative */
	return 1;

      /* Can't be equal and yet not fit in either uint64 or int64 */
      g_assert_not_reached ();
    }

  if (a_class == G_VARIANT_CLASS_DOUBLE &&
      variant_class_is_int (b_class))
    {
      ad = g_variant_get_double (a);

      if (variant_as_int64 (b, b_class, &b64))
	return compare_double_int64 (ad, b64);
      else
	{
	  variant_as_uint64 (b, b_class, &bu64);
	  return compare_double_uint64 (ad, bu64);
	}
    }

  if (variant_class_is_int (a_class) &&
      b_class == G_VARIANT_CLASS_DOUBLE)
    {
      bd = g_variant_get_double (b);

      if (variant_as_int64 (a, a_class, &a64))
	return -compare_double_int64 (bd, a64);
      else
	{
	  variant_as_uint64 (a, a_class, &au64);
	  return -compare_double_uint64 (bd, au64);
	}

    }

  g_warning ("Unhandled variant type in compare\n");

  /* TODO: We just sort by ptr for now */
  if ((gsize)a < (gsize)b)
    return -1;
  else if (a == b)
    return 0;
  else
    return 1;
}
Example #12
0
static void
method_call_cb (GDBusConnection       *connection,
                const gchar           *sender,
                const gchar           *object_path,
                const gchar           *interface_name,
                const gchar           *method_name,
                GVariant              *parameters,
                GDBusMethodInvocation *invocation,
                gpointer               user_data)
{
        EvApplication   *application = EV_APPLICATION (user_data);
	GList           *windows, *l;
        guint            timestamp;
        GVariantIter    *iter;
        const gchar     *key;
        GVariant        *value;
        GdkDisplay      *display = NULL;
        int              screen_number = 0;
	EvLinkDest      *dest = NULL;
	EvWindowRunMode  mode = EV_WINDOW_MODE_NORMAL;
	const gchar     *search_string = NULL;
	GdkScreen       *screen = NULL;

	if (g_strcmp0 (method_name, "Reload") == 0) {
		g_variant_get (parameters, "(a{sv}u)", &iter, &timestamp);

		while (g_variant_iter_loop (iter, "{&sv}", &key, &value)) {
			if (strcmp (key, "display") == 0 && g_variant_classify (value) == G_VARIANT_CLASS_STRING) {
				display = ev_display_open_if_needed (g_variant_get_string (value, NULL));
			} else if (strcmp (key, "screen") == 0 && g_variant_classify (value) == G_VARIANT_CLASS_STRING) {
				screen_number = g_variant_get_int32 (value);
			} else if (strcmp (key, "mode") == 0 && g_variant_classify (value) == G_VARIANT_CLASS_UINT32) {
			mode = g_variant_get_uint32 (value);
			} else if (strcmp (key, "page-label") == 0 && g_variant_classify (value) == G_VARIANT_CLASS_STRING) {
				dest = ev_link_dest_new_page_label (g_variant_get_string (value, NULL));
			} else if (strcmp (key, "find-string") == 0 && g_variant_classify (value) == G_VARIANT_CLASS_STRING) {
				search_string = g_variant_get_string (value, NULL);
			}
		}
		g_variant_iter_free (iter);

		if (display != NULL &&
		    screen_number >= 0 &&
		    screen_number < gdk_display_get_n_screens (display))
			screen = gdk_display_get_screen (display, screen_number);
		else
			screen = gdk_screen_get_default ();

		windows = ev_application_get_windows (application);
		for (l = windows; l != NULL; l = g_list_next (l)) {
			EvWindow *ev_window = EV_WINDOW (l->data);

			ev_application_open_uri_in_window (application, application->uri,
							   ev_window,
							   screen, dest, mode,
							   search_string,
							   timestamp);
		}
		g_list_free (windows);

		if (dest)
			g_object_unref (dest);

		g_dbus_method_invocation_return_value (invocation, g_variant_new ("()"));
	} else if (g_strcmp0 (method_name, "GetWindowList") == 0) {
		GList          *windows = ev_application_get_windows (application);
		GVariantBuilder builder;
		GList	       *l;

		g_variant_builder_init (&builder, G_VARIANT_TYPE ("(ao)"));
		g_variant_builder_open (&builder, G_VARIANT_TYPE ("ao"));

		for (l = windows; l; l = g_list_next (l)) {
			EvWindow *window = (EvWindow *)l->data;

			g_variant_builder_add (&builder, "o", ev_window_get_dbus_object_path (window));
		}

		g_variant_builder_close (&builder);
		g_list_free (windows);

		g_dbus_method_invocation_return_value (invocation, g_variant_builder_end (&builder));
	}
}
QT_BEGIN_NAMESPACE

QVariant convertValue(GVariant *value)
{
    if (!value)
        return QVariant(QVariant::Invalid);

    switch (g_variant_classify(value)) {
    case G_VARIANT_CLASS_BOOLEAN:
        return QVariant((bool)g_variant_get_boolean(value));
    case G_VARIANT_CLASS_BYTE:
        return QVariant(QLatin1Char(g_variant_get_byte(value)));
    case G_VARIANT_CLASS_INT16:
        return QVariant((int)g_variant_get_int16(value));
    case G_VARIANT_CLASS_UINT16:
        return QVariant((uint)g_variant_get_uint16(value));
    case G_VARIANT_CLASS_INT32:
        return QVariant((int)g_variant_get_int32(value));
    case G_VARIANT_CLASS_UINT32:
        return QVariant((uint)g_variant_get_uint32(value));
    case G_VARIANT_CLASS_INT64:
        return QVariant((qlonglong)g_variant_get_int64(value));
    case G_VARIANT_CLASS_UINT64:
        return QVariant((qulonglong)g_variant_get_uint64(value));
    case G_VARIANT_CLASS_DOUBLE:
        return QVariant(g_variant_get_double(value));
    case G_VARIANT_CLASS_STRING:
        return QVariant(QString::fromUtf8(g_variant_get_string(value, NULL)));
    case G_VARIANT_CLASS_ARRAY:
        if (g_variant_is_of_type(value, G_VARIANT_TYPE_STRING_ARRAY)) {
            GVariantIter iter;
            QStringList list;
            const gchar *str;

            g_variant_iter_init(&iter, value);

            while (g_variant_iter_next(&iter, "&s", &str))
                list.append(QString::fromUtf8(str));

            return QVariant(list);
        } else if (g_variant_is_of_type(value, G_VARIANT_TYPE_BYTESTRING_ARRAY)) {
            GVariantIter iter;
            QVariantList list;
            const gchar *item;

            g_variant_iter_init(&iter, value);

            while (g_variant_iter_next(&iter, "&y", &item))
                list.append(QByteArray(item));

            return list;
#ifndef QT_NO_DATASTREAM
        } else if (g_variant_is_of_type(value, G_VARIANT_TYPE_BYTESTRING)) {
            QByteArray a(g_variant_get_bytestring(value));
            QDataStream s(&a, QIODevice::ReadOnly);
            s.setVersion(QDataStream::Qt_4_0);
            QVariant result;
            s >> result;
            return result;
#else
        Q_ASSERT(!"QConfiguration: Cannot load custom types without QDataStream support");
#endif
        }
    default:
        break;
    }

    return QVariant(QVariant::Invalid);
}
Example #14
0
/**
 * g_dbus_gvariant_to_gvalue:
 * @value: A #GVariant.
 * @out_gvalue: (out): Return location pointing to a zero-filled (uninitialized) #GValue.
 *
 * Converts a #GVariant to a #GValue. If @value is floating, it is consumed.
 *
 * The rules specified in the g_dbus_gvalue_to_gvariant() function are
 * used - this function is essentially its reverse form.
 *
 * The conversion never fails - a valid #GValue is always returned in
 * @out_gvalue.
 *
 * Since: 2.30
 */
void
g_dbus_gvariant_to_gvalue (GVariant  *value,
                           GValue    *out_gvalue)
{
  const GVariantType *type;
  gchar **array;

  g_return_if_fail (value != NULL);
  g_return_if_fail (out_gvalue != NULL);

  memset (out_gvalue, '\0', sizeof (GValue));

  switch (g_variant_classify (value))
    {
    case G_VARIANT_CLASS_BOOLEAN:
      g_value_init (out_gvalue, G_TYPE_BOOLEAN);
      g_value_set_boolean (out_gvalue, g_variant_get_boolean (value));
      break;

    case G_VARIANT_CLASS_BYTE:
      g_value_init (out_gvalue, G_TYPE_UCHAR);
      g_value_set_uchar (out_gvalue, g_variant_get_byte (value));
      break;

    case G_VARIANT_CLASS_INT16:
      g_value_init (out_gvalue, G_TYPE_INT);
      g_value_set_int (out_gvalue, g_variant_get_int16 (value));
      break;

    case G_VARIANT_CLASS_UINT16:
      g_value_init (out_gvalue, G_TYPE_UINT);
      g_value_set_uint (out_gvalue, g_variant_get_uint16 (value));
      break;

    case G_VARIANT_CLASS_INT32:
      g_value_init (out_gvalue, G_TYPE_INT);
      g_value_set_int (out_gvalue, g_variant_get_int32 (value));
      break;

    case G_VARIANT_CLASS_UINT32:
      g_value_init (out_gvalue, G_TYPE_UINT);
      g_value_set_uint (out_gvalue, g_variant_get_uint32 (value));
      break;

    case G_VARIANT_CLASS_INT64:
      g_value_init (out_gvalue, G_TYPE_INT64);
      g_value_set_int64 (out_gvalue, g_variant_get_int64 (value));
      break;

    case G_VARIANT_CLASS_UINT64:
      g_value_init (out_gvalue, G_TYPE_UINT64);
      g_value_set_uint64 (out_gvalue, g_variant_get_uint64 (value));
      break;

    case G_VARIANT_CLASS_DOUBLE:
      g_value_init (out_gvalue, G_TYPE_DOUBLE);
      g_value_set_double (out_gvalue, g_variant_get_double (value));
      break;

    case G_VARIANT_CLASS_STRING:
      g_value_init (out_gvalue, G_TYPE_STRING);
      g_value_set_string (out_gvalue, g_variant_get_string (value, NULL));
      break;

    case G_VARIANT_CLASS_OBJECT_PATH:
      g_value_init (out_gvalue, G_TYPE_STRING);
      g_value_set_string (out_gvalue, g_variant_get_string (value, NULL));
      break;

    case G_VARIANT_CLASS_SIGNATURE:
      g_value_init (out_gvalue, G_TYPE_STRING);
      g_value_set_string (out_gvalue, g_variant_get_string (value, NULL));
      break;

    case G_VARIANT_CLASS_ARRAY:
      type = g_variant_get_type (value);
      switch (g_variant_type_peek_string (type)[1])
        {
        case G_VARIANT_CLASS_BYTE:
          g_value_init (out_gvalue, G_TYPE_STRING);
          g_value_set_string (out_gvalue, g_variant_get_bytestring (value));
          break;

        case G_VARIANT_CLASS_STRING:
          g_value_init (out_gvalue, G_TYPE_STRV);
          array = g_variant_dup_strv (value, NULL);
          g_value_take_boxed (out_gvalue, array);
          break;

        case G_VARIANT_CLASS_OBJECT_PATH:
          g_value_init (out_gvalue, G_TYPE_STRV);
          array = g_variant_dup_objv (value, NULL);
          g_value_take_boxed (out_gvalue, array);
          break;

        case G_VARIANT_CLASS_ARRAY:
          switch (g_variant_type_peek_string (type)[2])
            {
            case G_VARIANT_CLASS_BYTE:
              g_value_init (out_gvalue, G_TYPE_STRV);
              array = g_variant_dup_bytestring_array (value, NULL);
              g_value_take_boxed (out_gvalue, array);
              break;

            default:
              g_value_init (out_gvalue, G_TYPE_VARIANT);
              g_value_set_variant (out_gvalue, value);
              break;
            }
          break;

        default:
          g_value_init (out_gvalue, G_TYPE_VARIANT);
          g_value_set_variant (out_gvalue, value);
          break;
        }
      break;

    case G_VARIANT_CLASS_HANDLE:
    case G_VARIANT_CLASS_VARIANT:
    case G_VARIANT_CLASS_MAYBE:
    case G_VARIANT_CLASS_TUPLE:
    case G_VARIANT_CLASS_DICT_ENTRY:
      g_value_init (out_gvalue, G_TYPE_VARIANT);
      g_value_set_variant (out_gvalue, value);
      break;
    }
}
Example #15
0
static void
build_json (JsonBuilder *builder,
            GVariant *value)
{
  const GVariantType *type;
  const GVariantType *element_type;

  g_variant_ref_sink (value);

  switch (g_variant_classify (value))
    {
    case G_VARIANT_CLASS_BOOLEAN:
      json_builder_add_boolean_value (builder, g_variant_get_boolean (value));
      break;

    case G_VARIANT_CLASS_BYTE:
      json_builder_add_int_value (builder, g_variant_get_byte (value));
      break;

    case G_VARIANT_CLASS_INT16:
      json_builder_add_int_value (builder, g_variant_get_int16 (value));
      break;

    case G_VARIANT_CLASS_UINT16:
      json_builder_add_int_value (builder, g_variant_get_uint16 (value));
      break;

    case G_VARIANT_CLASS_INT32:
      json_builder_add_int_value (builder, g_variant_get_int32 (value));
      break;

    case G_VARIANT_CLASS_UINT32:
      json_builder_add_int_value (builder, g_variant_get_uint32 (value));
      break;

    case G_VARIANT_CLASS_INT64:
      json_builder_add_int_value (builder, g_variant_get_int64 (value));
      break;

    case G_VARIANT_CLASS_UINT64:
      json_builder_add_int_value (builder, g_variant_get_uint64 (value));
      break;

    case G_VARIANT_CLASS_HANDLE:
      json_builder_add_int_value (builder, g_variant_get_handle (value));
      break;

    case G_VARIANT_CLASS_DOUBLE:
      json_builder_add_double_value (builder, g_variant_get_double (value));
      break;

    case G_VARIANT_CLASS_STRING:      /* explicit fall-through */
    case G_VARIANT_CLASS_OBJECT_PATH: /* explicit fall-through */
    case G_VARIANT_CLASS_SIGNATURE:
      {
        /* HACK: We can't use json_builder_add_string_value here since
           it turns empty strings into 'null' values inside arrays.

           https://bugzilla.gnome.org/show_bug.cgi?id=730803
        */
        JsonNode *string_element = json_node_alloc ();
        json_node_init_string (string_element, g_variant_get_string (value, NULL));
        json_builder_add_value (builder, string_element);
      }
      break;

    case G_VARIANT_CLASS_VARIANT:
      build_json_variant (builder, value);
      break;

    case G_VARIANT_CLASS_ARRAY:
      type = g_variant_get_type (value);
      element_type = g_variant_type_element (type);
      if (g_variant_type_is_dict_entry (element_type))
        build_json_dictionary (builder, element_type, value);
      else
        build_json_array_or_tuple (builder, value);
      break;

    case G_VARIANT_CLASS_TUPLE:
      build_json_array_or_tuple (builder, value);
      break;

    case G_VARIANT_CLASS_DICT_ENTRY:
    case G_VARIANT_CLASS_MAYBE:
    default:
      g_return_if_reached ();
      break;
    }

  g_variant_unref (value);
}