Commit ec24f12bb78a5dd81c4b639595f36c490df4161b

Authored by Colomban Wendling
1 parent 4f85382a

gsettings: Add support for list default values

compizconfig/gsettings/gsettings_backend_shared/gsettings_util.c
... ... @@ -497,7 +497,7 @@ getVariantAtKey (CCSGSettingsWrapper *settings, const char *key, const char *pat
497 497 }
498 498  
499 499 CCSSettingValueList
500   -readBoolListValue (GVariantIter *iter, guint nItems, CCSSetting *setting, CCSObjectAllocationInterface *ai)
  500 +readBoolListValue (GVariantIter *iter, guint nItems, CCSSetting *parent, CCSObjectAllocationInterface *ai)
501 501 {
502 502 CCSSettingValueList list = NULL;
503 503 Bool *array = (*ai->calloc_) (ai->allocator, 1, nItems * sizeof (Bool));
... ... @@ -511,14 +511,14 @@ readBoolListValue (GVariantIter *iter, guint nItems, CCSSetting *setting, CCSObj
511 511 while (g_variant_iter_loop (iter, "b", &value))
512 512 *arrayCounter++ = value ? TRUE : FALSE;
513 513  
514   - list = ccsGetValueListFromBoolArray (array, nItems, setting);
  514 + list = ccsGetValueListFromBoolArray (array, nItems, parent);
515 515 free (array);
516 516  
517 517 return list;
518 518 }
519 519  
520 520 CCSSettingValueList
521   -readIntListValue (GVariantIter *iter, guint nItems, CCSSetting *setting, CCSObjectAllocationInterface *ai)
  521 +readIntListValue (GVariantIter *iter, guint nItems, CCSSetting *parent, CCSObjectAllocationInterface *ai)
522 522 {
523 523 CCSSettingValueList list = NULL;
524 524 int *array = (*ai->calloc_) (ai->allocator, 1, nItems * sizeof (int));
... ... @@ -532,14 +532,14 @@ readIntListValue (GVariantIter *iter, guint nItems, CCSSetting *setting, CCSObje
532 532 while (g_variant_iter_loop (iter, "i", &value))
533 533 *arrayCounter++ = value;
534 534  
535   - list = ccsGetValueListFromIntArray (array, nItems, setting);
  535 + list = ccsGetValueListFromIntArray (array, nItems, parent);
536 536 free (array);
537 537  
538 538 return list;
539 539 }
540 540  
541 541 CCSSettingValueList
542   -readFloatListValue (GVariantIter *iter, guint nItems, CCSSetting *setting, CCSObjectAllocationInterface *ai)
  542 +readFloatListValue (GVariantIter *iter, guint nItems, CCSSetting *parent, CCSObjectAllocationInterface *ai)
543 543 {
544 544 CCSSettingValueList list = NULL;
545 545 float *array = (*ai->calloc_) (ai->allocator, 1, nItems * sizeof (float));
... ... @@ -553,14 +553,14 @@ readFloatListValue (GVariantIter *iter, guint nItems, CCSSetting *setting, CCSOb
553 553 while (g_variant_iter_loop (iter, "d", &value))
554 554 *arrayCounter++ = value;
555 555  
556   - list = ccsGetValueListFromFloatArray (array, nItems, setting);
  556 + list = ccsGetValueListFromFloatArray (array, nItems, parent);
557 557 free (array);
558 558  
559 559 return list;
560 560 }
561 561  
562 562 CCSSettingValueList
563   -readStringListValue (GVariantIter *iter, guint nItems, CCSSetting *setting, CCSObjectAllocationInterface *ai)
  563 +readStringListValue (GVariantIter *iter, guint nItems, CCSSetting *parent, CCSObjectAllocationInterface *ai)
564 564 {
565 565 CCSSettingValueList list = NULL;
566 566 gchar **array = (*ai->calloc_) (ai->allocator, 1, (nItems + 1) * sizeof (gchar *));
... ... @@ -576,14 +576,14 @@ readStringListValue (GVariantIter *iter, guint nItems, CCSSetting *setting, CCSO
576 576 while (g_variant_iter_next (iter, "s", &value))
577 577 *arrayCounter++ = value;
578 578  
579   - list = ccsGetValueListFromStringArray ((const gchar **) array, nItems, setting);
  579 + list = ccsGetValueListFromStringArray ((const gchar **) array, nItems, parent);
580 580 g_strfreev (array);
581 581  
582 582 return list;
583 583 }
584 584  
585 585 CCSSettingValueList
586   -readColorListValue (GVariantIter *iter, guint nItems, CCSSetting *setting, CCSObjectAllocationInterface *ai)
  586 +readColorListValue (GVariantIter *iter, guint nItems, CCSSetting *parent, CCSObjectAllocationInterface *ai)
587 587 {
588 588 CCSSettingValueList list = NULL;
589 589 char *colorValue;
... ... @@ -600,16 +600,16 @@ readColorListValue (GVariantIter *iter, guint nItems, CCSSetting *setting, CCSOb
600 600 ++i;
601 601 }
602 602  
603   - list = ccsGetValueListFromColorArray (array, nItems, setting);
  603 + list = ccsGetValueListFromColorArray (array, nItems, parent);
604 604 free (array);
605 605  
606 606 return list;
607 607 }
608 608  
609 609 CCSSettingValueList
610   -readListValue (GVariant *gsettingsValue, CCSSetting *setting, CCSObjectAllocationInterface *ai)
  610 +readListValue (GVariant *gsettingsValue, CCSSettingInfo *info, CCSSetting *parent, CCSObjectAllocationInterface *ai)
611 611 {
612   - CCSSettingType listType = ccsSettingGetInfo (setting)->forList.listType;
  612 + CCSSettingType listType = info->forList.listType;
613 613 gboolean hasVariantType;
614 614 unsigned int nItems;
615 615 CCSSettingValueList list = NULL;
... ... @@ -626,20 +626,20 @@ readListValue (GVariant *gsettingsValue, CCSSetting *setting, CCSObjectAllocatio
626 626 switch (listType)
627 627 {
628 628 case TypeBool:
629   - list = readBoolListValue (&iter, nItems, setting, ai);
  629 + list = readBoolListValue (&iter, nItems, parent, ai);
630 630 break;
631 631 case TypeInt:
632   - list = readIntListValue (&iter, nItems, setting, ai);
  632 + list = readIntListValue (&iter, nItems, parent, ai);
633 633 break;
634 634 case TypeFloat:
635   - list = readFloatListValue (&iter, nItems, setting, ai);
  635 + list = readFloatListValue (&iter, nItems, parent, ai);
636 636 break;
637 637 case TypeString:
638 638 case TypeMatch:
639   - list = readStringListValue (&iter, nItems, setting, ai);
  639 + list = readStringListValue (&iter, nItems, parent, ai);
640 640 break;
641 641 case TypeColor:
642   - list = readColorListValue (&iter, nItems, setting, ai);
  642 + list = readColorListValue (&iter, nItems, parent, ai);
643 643 break;
644 644 default:
645 645 break;
... ...
compizconfig/gsettings/gsettings_backend_shared/gsettings_util.h
... ... @@ -131,7 +131,7 @@ CCSSettingButtonValue readButtonFromVariant (GVariant *gsettingsValue, Bool *suc
131 131 unsigned int readEdgeFromVariant (GVariant *gsettingsValue);
132 132  
133 133 CCSSettingValueList
134   -readListValue (GVariant *gsettingsValue, CCSSetting *setting, CCSObjectAllocationInterface *allocator);
  134 +readListValue (GVariant *gsettingsValue, CCSSettingInfo *info, CCSSetting *parent, CCSObjectAllocationInterface *allocator);
135 135  
136 136 Bool
137 137 writeListValue (CCSSettingValueList list,
... ... @@ -176,19 +176,19 @@ removeItemFromVariant (GVariant **variant,
176 176 const char *string);
177 177  
178 178 CCSSettingValueList
179   -readBoolListValue (GVariantIter *iter, guint nItems, CCSSetting *setting, CCSObjectAllocationInterface *allocator);
  179 +readBoolListValue (GVariantIter *iter, guint nItems, CCSSetting *parent, CCSObjectAllocationInterface *allocator);
180 180  
181 181 CCSSettingValueList
182   -readIntListValue (GVariantIter *iter, guint nItems, CCSSetting *setting, CCSObjectAllocationInterface *allocator);
  182 +readIntListValue (GVariantIter *iter, guint nItems, CCSSetting *parent, CCSObjectAllocationInterface *allocator);
183 183  
184 184 CCSSettingValueList
185   -readFloatListValue (GVariantIter *iter, guint nItems, CCSSetting *setting, CCSObjectAllocationInterface *allocator);
  185 +readFloatListValue (GVariantIter *iter, guint nItems, CCSSetting *parent, CCSObjectAllocationInterface *allocator);
186 186  
187 187 CCSSettingValueList
188   -readStringListValue (GVariantIter *iter, guint nItems, CCSSetting *setting, CCSObjectAllocationInterface *allocator);
  188 +readStringListValue (GVariantIter *iter, guint nItems, CCSSetting *parent, CCSObjectAllocationInterface *allocator);
189 189  
190 190 CCSSettingValueList
191   -readColorListValue (GVariantIter *iter, guint nItems, CCSSetting *setting, CCSObjectAllocationInterface *allocator);
  191 +readColorListValue (GVariantIter *iter, guint nItems, CCSSetting *parent, CCSObjectAllocationInterface *allocator);
192 192  
193 193 gchar *
194 194 makeSettingPath (const char *currentProfile, CCSPlugin *plugin);
... ...
compizconfig/gsettings/src/gsettings.c
... ... @@ -207,7 +207,7 @@ readOption (CCSBackend *backend, CCSSetting * setting)
207 207 break;
208 208 case TypeList:
209 209 {
210   - CCSSettingValueList list = readListValue (gsettingsValue, setting, &ccsDefaultObjectAllocator);
  210 + CCSSettingValueList list = readListValue (gsettingsValue, ccsSettingGetInfo (setting), setting, &ccsDefaultObjectAllocator);
211 211  
212 212 if (list)
213 213 {
... ... @@ -271,7 +271,7 @@ isTypeReadable (CCSSettingType type)
271 271 }
272 272  
273 273 Bool
274   -readOptionDefault (CCSBackend *backend, CCSPlugin *plugin, const char *name, CCSSettingType type, CCSSettingValue *defaultValue)
  274 +readOptionDefault (CCSBackend *backend, CCSPlugin *plugin, const char *name, CCSSettingType type, CCSSettingInfo *info, CCSSettingValue *defaultValue)
275 275 {
276 276 Bool ret = FALSE;
277 277 GVariant *gsettingsValue = NULL;
... ... @@ -384,8 +384,14 @@ readOptionDefault (CCSBackend *backend, CCSPlugin *plugin, const char *name, CCS
384 384 break;
385 385 case TypeList:
386 386 {
387   - ccsWarning ("GSettings backend: default values for lists are currently not supported");
388   - ret = FALSE;
  387 + CCSSettingValueList list = readListValue (gsettingsValue, info, defaultValue->parent, &ccsDefaultObjectAllocator);
  388 +
  389 + if (list)
  390 + {
  391 + ccsSettingValueListFree (defaultValue->value.asList, TRUE);
  392 + defaultValue->value.asList = list;
  393 + ret = TRUE;
  394 + }
389 395 }
390 396 break;
391 397 default:
... ... @@ -587,7 +593,7 @@ readSettingDefaultValue (CCSBackend *backend,
587 593 if (ccsGetIntegrationEnabled (ccsPluginGetContext (plugin)))
588 594 ccsWarning ("Integration is enabled, but getting the setting's default value is not implemented for integrated settings");
589 595  
590   - status = readOptionDefault (backend, plugin, name, type, defaultValue);
  596 + status = readOptionDefault (backend, plugin, name, type, info, defaultValue);
591 597  
592 598 return status;
593 599 }
... ...
compizconfig/gsettings/tests/compizconfig_ccs_gsettings_settings_env_test.cpp
... ... @@ -307,7 +307,7 @@ CCSGSettingsStorageEnv::ReadListAtKey (const std::string &plugin,
307 307 GVariantShared variant (ReadVariantAtKeyToShared (plugin,
308 308 key,
309 309 TypeList));
310   - return readListValue (variant.get (), setting, &ccsDefaultObjectAllocator);
  310 + return readListValue (variant.get (), ccsSettingGetInfo (setting), setting, &ccsDefaultObjectAllocator);
311 311 }
312 312  
313 313 GVariantShared
... ...
compizconfig/gsettings/tests/test_gsettings_tests.cpp
... ... @@ -1410,6 +1410,7 @@ TEST_P(CCSGSettingsTestReadListValueTypes, TestListValueThroughListValueDispatch
1410 1410 ON_CALL (*gmockSetting, getDefaultValue ()).WillByDefault (ReturnNull ());
1411 1411  
1412 1412 boost::shared_ptr <_CCSSettingValueList> readValueList (readListValue (variant.get (),
  1413 + ccsSettingGetInfo (mockSetting.get ()),
1413 1414 mockSetting.get (),
1414 1415 &ccsDefaultObjectAllocator),
1415 1416 boost::bind (ccsSettingValueListFree, _1, TRUE));
... ... @@ -1493,7 +1494,7 @@ TEST_P (CCSGSettingsBackendReadListValueBadTypesTest, TestGSettingsReadListValue
1493 1494  
1494 1495 ON_CALL (*gmockSetting, getInfo ()).WillByDefault (Return (&info));
1495 1496  
1496   - EXPECT_THAT (readListValue (variant, mockSetting.get (), &ccsDefaultObjectAllocator), IsNull ());
  1497 + EXPECT_THAT (readListValue (variant, ccsSettingGetInfo (mockSetting.get ()), mockSetting.get (), &ccsDefaultObjectAllocator), IsNull ());
1497 1498 }
1498 1499  
1499 1500 CCSSettingType readListValueNonVariantTypes[] =
... ...