gsettings-mapping.c 18 KB
Newer Older
Allison Karlitskaya's avatar
Allison Karlitskaya committed
1 2 3 4 5 6
/*
 * Copyright © 2010 Novell, Inc.
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
7
 * version 2.1 of the License, or (at your option) any later version.
Allison Karlitskaya's avatar
Allison Karlitskaya committed
8 9 10 11 12 13 14
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
15
 * License along with this library; if not, see <http://www.gnu.org/licenses/>.
Allison Karlitskaya's avatar
Allison Karlitskaya committed
16 17 18 19 20 21 22 23 24
 *
 * Author: Vincent Untz <vuntz@gnome.org>
 */

#include "config.h"

#include "gsettings-mapping.h"

static GVariant *
25 26
g_settings_set_mapping_int (const GValue       *value,
                            const GVariantType *expected_type)
Allison Karlitskaya's avatar
Allison Karlitskaya committed
27 28
{
  GVariant *variant = NULL;
29
  gint64 l;
Allison Karlitskaya's avatar
Allison Karlitskaya committed
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73

  if (G_VALUE_HOLDS_INT (value))
    l = g_value_get_int (value);
  else if (G_VALUE_HOLDS_INT64 (value))
    l = g_value_get_int64 (value);
  else
    return NULL;

  if (g_variant_type_equal (expected_type, G_VARIANT_TYPE_INT16))
    {
      if (G_MININT16 <= l && l <= G_MAXINT16)
        variant = g_variant_new_int16 ((gint16) l);
    }
  else if (g_variant_type_equal (expected_type, G_VARIANT_TYPE_UINT16))
    {
      if (0 <= l && l <= G_MAXUINT16)
        variant = g_variant_new_uint16 ((guint16) l);
    }
  else if (g_variant_type_equal (expected_type, G_VARIANT_TYPE_INT32))
    {
      if (G_MININT32 <= l && l <= G_MAXINT32)
        variant = g_variant_new_int32 ((gint) l);
    }
  else if (g_variant_type_equal (expected_type, G_VARIANT_TYPE_UINT32))
    {
      if (0 <= l && l <= G_MAXUINT32)
        variant = g_variant_new_uint32 ((guint) l);
    }
  else if (g_variant_type_equal (expected_type, G_VARIANT_TYPE_INT64))
    {
      if (G_MININT64 <= l && l <= G_MAXINT64)
        variant = g_variant_new_int64 ((gint64) l);
    }
  else if (g_variant_type_equal (expected_type, G_VARIANT_TYPE_UINT64))
    {
      if (0 <= l && l <= G_MAXUINT64)
        variant = g_variant_new_uint64 ((guint64) l);
    }
  else if (g_variant_type_equal (expected_type, G_VARIANT_TYPE_HANDLE))
    {
      if (0 <= l && l <= G_MAXUINT32)
        variant = g_variant_new_handle ((guint) l);
    }
  else if (g_variant_type_equal (expected_type, G_VARIANT_TYPE_DOUBLE))
74
    variant = g_variant_new_double ((gdouble) l);
Allison Karlitskaya's avatar
Allison Karlitskaya committed
75 76 77 78 79

  return variant;
}

static GVariant *
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135
g_settings_set_mapping_float (const GValue       *value,
                              const GVariantType *expected_type)
{
  GVariant *variant = NULL;
  gdouble d;
  gint64 l;

  if (G_VALUE_HOLDS_DOUBLE (value))
    d = g_value_get_double (value);
  else
    return NULL;

  l = (gint64) d;
  if (g_variant_type_equal (expected_type, G_VARIANT_TYPE_INT16))
    {
      if (G_MININT16 <= l && l <= G_MAXINT16)
        variant = g_variant_new_int16 ((gint16) l);
    }
  else if (g_variant_type_equal (expected_type, G_VARIANT_TYPE_UINT16))
    {
      if (0 <= l && l <= G_MAXUINT16)
        variant = g_variant_new_uint16 ((guint16) l);
    }
  else if (g_variant_type_equal (expected_type, G_VARIANT_TYPE_INT32))
    {
      if (G_MININT32 <= l && l <= G_MAXINT32)
        variant = g_variant_new_int32 ((gint) l);
    }
  else if (g_variant_type_equal (expected_type, G_VARIANT_TYPE_UINT32))
    {
      if (0 <= l && l <= G_MAXUINT32)
        variant = g_variant_new_uint32 ((guint) l);
    }
  else if (g_variant_type_equal (expected_type, G_VARIANT_TYPE_INT64))
    {
      if (G_MININT64 <= l && l <= G_MAXINT64)
        variant = g_variant_new_int64 ((gint64) l);
    }
  else if (g_variant_type_equal (expected_type, G_VARIANT_TYPE_UINT64))
    {
      if (0 <= l && l <= G_MAXUINT64)
        variant = g_variant_new_uint64 ((guint64) l);
    }
  else if (g_variant_type_equal (expected_type, G_VARIANT_TYPE_HANDLE))
    {
      if (0 <= l && l <= G_MAXUINT32)
        variant = g_variant_new_handle ((guint) l);
    }
  else if (g_variant_type_equal (expected_type, G_VARIANT_TYPE_DOUBLE))
    variant = g_variant_new_double ((gdouble) d);

  return variant;
}
static GVariant *
g_settings_set_mapping_unsigned_int (const GValue       *value,
                                     const GVariantType *expected_type)
Allison Karlitskaya's avatar
Allison Karlitskaya committed
136 137
{
  GVariant *variant = NULL;
138
  guint64 u;
Allison Karlitskaya's avatar
Allison Karlitskaya committed
139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182

  if (G_VALUE_HOLDS_UINT (value))
    u = g_value_get_uint (value);
  else if (G_VALUE_HOLDS_UINT64 (value))
    u = g_value_get_uint64 (value);
  else
    return NULL;

  if (g_variant_type_equal (expected_type, G_VARIANT_TYPE_INT16))
    {
      if (u <= G_MAXINT16)
        variant = g_variant_new_int16 ((gint16) u);
    }
  else if (g_variant_type_equal (expected_type, G_VARIANT_TYPE_UINT16))
    {
      if (u <= G_MAXUINT16)
        variant = g_variant_new_uint16 ((guint16) u);
    }
  else if (g_variant_type_equal (expected_type, G_VARIANT_TYPE_INT32))
    {
      if (u <= G_MAXINT32)
        variant = g_variant_new_int32 ((gint) u);
    }
  else if (g_variant_type_equal (expected_type, G_VARIANT_TYPE_UINT32))
    {
      if (u <= G_MAXUINT32)
        variant = g_variant_new_uint32 ((guint) u);
    }
  else if (g_variant_type_equal (expected_type, G_VARIANT_TYPE_INT64))
    {
      if (u <= G_MAXINT64)
        variant = g_variant_new_int64 ((gint64) u);
    }
  else if (g_variant_type_equal (expected_type, G_VARIANT_TYPE_UINT64))
    {
      if (u <= G_MAXUINT64)
        variant = g_variant_new_uint64 ((guint64) u);
    }
  else if (g_variant_type_equal (expected_type, G_VARIANT_TYPE_HANDLE))
    {
      if (u <= G_MAXUINT32)
        variant = g_variant_new_handle ((guint) u);
    }
  else if (g_variant_type_equal (expected_type, G_VARIANT_TYPE_DOUBLE))
183
    variant = g_variant_new_double ((gdouble) u);
Allison Karlitskaya's avatar
Allison Karlitskaya committed
184 185 186 187 188

  return variant;
}

static gboolean
189 190
g_settings_get_mapping_int (GValue   *value,
                            GVariant *variant)
Allison Karlitskaya's avatar
Allison Karlitskaya committed
191 192
{
  const GVariantType *type;
193
  gint64 l;
Allison Karlitskaya's avatar
Allison Karlitskaya committed
194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235

  type = g_variant_get_type (variant);

  if (g_variant_type_equal (type, G_VARIANT_TYPE_INT16))
    l = g_variant_get_int16 (variant);
  else if (g_variant_type_equal (type, G_VARIANT_TYPE_INT32))
    l = g_variant_get_int32 (variant);
  else if (g_variant_type_equal (type, G_VARIANT_TYPE_INT64))
    l = g_variant_get_int64 (variant);
  else
    return FALSE;

  if (G_VALUE_HOLDS_INT (value))
    {
      g_value_set_int (value, l);
      return (G_MININT32 <= l && l <= G_MAXINT32);
    }
  else if (G_VALUE_HOLDS_UINT (value))
    {
      g_value_set_uint (value, l);
      return (0 <= l && l <= G_MAXUINT32);
    }
  else if (G_VALUE_HOLDS_INT64 (value))
    {
      g_value_set_int64 (value, l);
      return (G_MININT64 <= l && l <= G_MAXINT64);
    }
  else if (G_VALUE_HOLDS_UINT64 (value))
    {
      g_value_set_uint64 (value, l);
      return (0 <= l && l <= G_MAXUINT64);
    }
  else if (G_VALUE_HOLDS_DOUBLE (value))
    {
      g_value_set_double (value, l);
      return TRUE;
    }

  return FALSE;
}

static gboolean
236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281
g_settings_get_mapping_float (GValue   *value,
                              GVariant *variant)
{
  const GVariantType *type;
  gdouble d;
  gint64 l;

  type = g_variant_get_type (variant);

  if (g_variant_type_equal (type, G_VARIANT_TYPE_DOUBLE))
    d = g_variant_get_double (variant);
  else
    return FALSE;

  l = (gint64)d;
  if (G_VALUE_HOLDS_INT (value))
    {
      g_value_set_int (value, l);
      return (G_MININT32 <= l && l <= G_MAXINT32);
    }
  else if (G_VALUE_HOLDS_UINT (value))
    {
      g_value_set_uint (value, l);
      return (0 <= l && l <= G_MAXUINT32);
    }
  else if (G_VALUE_HOLDS_INT64 (value))
    {
      g_value_set_int64 (value, l);
      return (G_MININT64 <= l && l <= G_MAXINT64);
    }
  else if (G_VALUE_HOLDS_UINT64 (value))
    {
      g_value_set_uint64 (value, l);
      return (0 <= l && l <= G_MAXUINT64);
    }
  else if (G_VALUE_HOLDS_DOUBLE (value))
    {
      g_value_set_double (value, d);
      return TRUE;
    }

  return FALSE;
}
static gboolean
g_settings_get_mapping_unsigned_int (GValue   *value,
                                     GVariant *variant)
Allison Karlitskaya's avatar
Allison Karlitskaya committed
282 283
{
  const GVariantType *type;
284
  guint64 u;
Allison Karlitskaya's avatar
Allison Karlitskaya committed
285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346

  type = g_variant_get_type (variant);

  if (g_variant_type_equal (type, G_VARIANT_TYPE_UINT16))
    u = g_variant_get_uint16 (variant);
  else if (g_variant_type_equal (type, G_VARIANT_TYPE_UINT32))
    u = g_variant_get_uint32 (variant);
  else if (g_variant_type_equal (type, G_VARIANT_TYPE_UINT64))
    u = g_variant_get_uint64 (variant);
  else if (g_variant_type_equal (type, G_VARIANT_TYPE_HANDLE))
    u = g_variant_get_handle (variant);
  else
    return FALSE;

  if (G_VALUE_HOLDS_INT (value))
    {
      g_value_set_int (value, u);
      return (u <= G_MAXINT32);
    }
  else if (G_VALUE_HOLDS_UINT (value))
    {
      g_value_set_uint (value, u);
      return (u <= G_MAXUINT32);
    }
  else if (G_VALUE_HOLDS_INT64 (value))
    {
      g_value_set_int64 (value, u);
      return (u <= G_MAXINT64);
    }
  else if (G_VALUE_HOLDS_UINT64 (value))
    {
      g_value_set_uint64 (value, u);
      return (u <= G_MAXUINT64);
    }
  else if (G_VALUE_HOLDS_DOUBLE (value))
    {
      g_value_set_double (value, u);
      return TRUE;
    }

  return FALSE;
}

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))
347
            return g_variant_new_byte (g_value_get_schar (value));
Allison Karlitskaya's avatar
Allison Karlitskaya committed
348 349 350 351 352 353
          else
            return g_variant_new_byte (g_value_get_uchar (value));
        }
    }

  else if (G_VALUE_HOLDS_INT (value)   ||
354 355 356 357 358
           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);
Allison Karlitskaya's avatar
Allison Karlitskaya committed
359 360 361

  else if (G_VALUE_HOLDS_UINT (value)  ||
           G_VALUE_HOLDS_UINT64 (value))
362
    return g_settings_set_mapping_unsigned_int (value, expected_type);
Allison Karlitskaya's avatar
Allison Karlitskaya committed
363 364 365

  else if (G_VALUE_HOLDS_STRING (value))
    {
366 367 368
      if (g_value_get_string (value) == NULL)
        return NULL;
      else if (g_variant_type_equal (expected_type, G_VARIANT_TYPE_STRING))
Allison Karlitskaya's avatar
Allison Karlitskaya committed
369
        return g_variant_new_string (g_value_get_string (value));
370 371
      else if (g_variant_type_equal (expected_type, G_VARIANT_TYPE_BYTESTRING))
        return g_variant_new_bytestring (g_value_get_string (value));
Allison Karlitskaya's avatar
Allison Karlitskaya committed
372 373 374 375 376 377
      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));
    }

378 379 380 381 382 383 384 385
  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);
    }

386 387 388 389 390
  else if (G_VALUE_HOLDS_ENUM (value))
    {
      GEnumValue *enumval;
      GEnumClass *eclass;

391 392
      /* GParamSpecEnum holds a ref on the class so we just peek... */
      eclass = g_type_class_peek (G_VALUE_TYPE (value));
393 394 395 396 397 398 399 400
      enumval = g_enum_get_value (eclass, g_value_get_enum (value));

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

401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428
  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);
    }

Allison Karlitskaya's avatar
Allison Karlitskaya committed
429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453
  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;
}

gboolean
g_settings_get_mapping (GValue   *value,
                        GVariant *variant,
                        gpointer  user_data)
{
  if (g_variant_is_of_type (variant, G_VARIANT_TYPE_BOOLEAN))
    {
      if (!G_VALUE_HOLDS_BOOLEAN (value))
        return FALSE;
      g_value_set_boolean (value, g_variant_get_boolean (variant));
      return TRUE;
    }

  else if (g_variant_is_of_type (variant, G_VARIANT_TYPE_BYTE))
    {
      if (G_VALUE_HOLDS_UCHAR (value))
        g_value_set_uchar (value, g_variant_get_byte (variant));
      else if (G_VALUE_HOLDS_CHAR (value))
454
        g_value_set_schar (value, (gint8)g_variant_get_byte (variant));
Allison Karlitskaya's avatar
Allison Karlitskaya committed
455 456 457 458 459 460 461
      else
        return FALSE;
      return TRUE;
    }

  else if (g_variant_is_of_type (variant, G_VARIANT_TYPE_INT16)  ||
           g_variant_is_of_type (variant, G_VARIANT_TYPE_INT32)  ||
462 463 464 465 466
           g_variant_is_of_type (variant, G_VARIANT_TYPE_INT64))
    return g_settings_get_mapping_int (value, variant);

  else if (g_variant_is_of_type (variant, G_VARIANT_TYPE_DOUBLE))
    return g_settings_get_mapping_float (value, variant);
Allison Karlitskaya's avatar
Allison Karlitskaya committed
467 468 469 470 471

  else if (g_variant_is_of_type (variant, G_VARIANT_TYPE_UINT16) ||
           g_variant_is_of_type (variant, G_VARIANT_TYPE_UINT32) ||
           g_variant_is_of_type (variant, G_VARIANT_TYPE_UINT64) ||
           g_variant_is_of_type (variant, G_VARIANT_TYPE_HANDLE))
472
    return g_settings_get_mapping_unsigned_int (value, variant);
Allison Karlitskaya's avatar
Allison Karlitskaya committed
473 474 475 476 477

  else if (g_variant_is_of_type (variant, G_VARIANT_TYPE_STRING)      ||
           g_variant_is_of_type (variant, G_VARIANT_TYPE_OBJECT_PATH) ||
           g_variant_is_of_type (variant, G_VARIANT_TYPE_SIGNATURE))
    {
478 479 480 481 482
      if (G_VALUE_HOLDS_STRING (value))
        {
          g_value_set_string (value, g_variant_get_string (variant, NULL));
          return TRUE;
        }
483

484
      else if (G_VALUE_HOLDS_ENUM (value))
485 486 487 488 489
        {
          GEnumClass *eclass;
          GEnumValue *evalue;
          const gchar *nick;

490 491
          /* GParamSpecEnum holds a ref on the class so we just peek... */
          eclass = g_type_class_peek (G_VALUE_TYPE (value));
492 493 494 495 496 497 498 499 500
          nick = g_variant_get_string (variant, NULL);
          evalue = g_enum_get_value_by_nick (eclass, nick);

          if (evalue)
            {
             g_value_set_enum (value, evalue->value);
             return TRUE;
            }

501
          g_warning ("Unable to lookup enum nick '%s' via GType", nick);
502 503
          return FALSE;
        }
Allison Karlitskaya's avatar
Allison Karlitskaya committed
504
    }
505 506
  else if (g_variant_is_of_type (variant, G_VARIANT_TYPE ("as")))
    {
507 508 509 510 511 512 513
      if (G_VALUE_HOLDS (value, G_TYPE_STRV))
        {
          g_value_take_boxed (value, g_variant_dup_strv (variant, NULL));
          return TRUE;
        }

      else if (G_VALUE_HOLDS_FLAGS (value))
514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532
        {
          GFlagsClass *fclass;
          GFlagsValue *fvalue;
          const gchar *nick;
          GVariantIter iter;
          guint flags = 0;

          fclass = g_type_class_peek (G_VALUE_TYPE (value));

          g_variant_iter_init (&iter, variant);
          while (g_variant_iter_next (&iter, "&s", &nick))
            {
              fvalue = g_flags_get_value_by_nick (fclass, nick);

              if (fvalue)
                flags |= fvalue->value;

              else
                {
533
                  g_warning ("Unable to lookup flags nick '%s' via GType",
534 535 536 537 538 539 540 541 542
                             nick);
                  return FALSE;
                }
            }

          g_value_set_flags (value, flags);
          return TRUE;
        }
    }
543
  else if (g_variant_is_of_type (variant, G_VARIANT_TYPE_BYTESTRING))
544
    {
545
      g_value_set_string (value, g_variant_get_bytestring (variant));
546 547
      return TRUE;
    }
Allison Karlitskaya's avatar
Allison Karlitskaya committed
548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580

  g_critical ("No GSettings bind handler for type \"%s\".",
              g_variant_get_type_string (variant));

  return FALSE;
}

gboolean
g_settings_mapping_is_compatible (GType               gvalue_type,
                                  const GVariantType *variant_type)
{
  gboolean ok = FALSE;

  if (gvalue_type == G_TYPE_BOOLEAN)
    ok = g_variant_type_equal (variant_type, G_VARIANT_TYPE_BOOLEAN);
  else if (gvalue_type == G_TYPE_CHAR  ||
           gvalue_type == G_TYPE_UCHAR)
    ok = g_variant_type_equal (variant_type, G_VARIANT_TYPE_BYTE);
  else if (gvalue_type == G_TYPE_INT    ||
           gvalue_type == G_TYPE_UINT   ||
           gvalue_type == G_TYPE_INT64  ||
           gvalue_type == G_TYPE_UINT64 ||
           gvalue_type == G_TYPE_DOUBLE)
    ok = (g_variant_type_equal (variant_type, G_VARIANT_TYPE_INT16)  ||
          g_variant_type_equal (variant_type, G_VARIANT_TYPE_UINT16) ||
          g_variant_type_equal (variant_type, G_VARIANT_TYPE_INT32)  ||
          g_variant_type_equal (variant_type, G_VARIANT_TYPE_UINT32) ||
          g_variant_type_equal (variant_type, G_VARIANT_TYPE_INT64)  ||
          g_variant_type_equal (variant_type, G_VARIANT_TYPE_UINT64) ||
          g_variant_type_equal (variant_type, G_VARIANT_TYPE_HANDLE) ||
          g_variant_type_equal (variant_type, G_VARIANT_TYPE_DOUBLE));
  else if (gvalue_type == G_TYPE_STRING)
    ok = (g_variant_type_equal (variant_type, G_VARIANT_TYPE_STRING)      ||
581
          g_variant_type_equal (variant_type, G_VARIANT_TYPE ("ay")) ||
Allison Karlitskaya's avatar
Allison Karlitskaya committed
582 583
          g_variant_type_equal (variant_type, G_VARIANT_TYPE_OBJECT_PATH) ||
          g_variant_type_equal (variant_type, G_VARIANT_TYPE_SIGNATURE));
584 585
  else if (gvalue_type == G_TYPE_STRV)
    ok = g_variant_type_equal (variant_type, G_VARIANT_TYPE ("as"));
586 587
  else if (G_TYPE_IS_ENUM (gvalue_type))
    ok = g_variant_type_equal (variant_type, G_VARIANT_TYPE_STRING);
588 589
  else if (G_TYPE_IS_FLAGS (gvalue_type))
    ok = g_variant_type_equal (variant_type, G_VARIANT_TYPE ("as"));
Allison Karlitskaya's avatar
Allison Karlitskaya committed
590 591 592

  return ok;
}