15#include <forward_list>
19#include <dconf/dconf.h>
21#include <com/sun/star/uno/Sequence.hxx>
23#include <rtl/ustrbuf.hxx>
114template<
typename T>
class GObjectHolder {
116 explicit GObjectHolder(T *
object):
object_(
object) {}
127 GObjectHolder(GObjectHolder
const &) =
delete;
128 GObjectHolder& operator =(GObjectHolder
const &) =
delete;
133class GVariantHolder {
135 explicit GVariantHolder(GVariant * variant =
nullptr):
variant_(variant) {}
137 ~GVariantHolder() { unref(); }
139 void reset(GVariant * variant) {
144 void release() {
variant_ =
nullptr; }
149 GVariantHolder(GVariantHolder
const &) =
delete;
150 GVariantHolder& operator =(GVariantHolder
const &) =
delete;
161class GVariantTypeHolder {
163 explicit GVariantTypeHolder(GVariantType *
type):
type_(
type) {}
165 ~GVariantTypeHolder() {
166 if (
type_ !=
nullptr) {
167 g_variant_type_free(
type_);
171 GVariantType *
get()
const {
return type_; }
174 GVariantTypeHolder(GVariantTypeHolder
const &) =
delete;
175 GVariantTypeHolder& operator =(GVariantTypeHolder
const &) =
delete;
180class StringArrayHolder {
182 explicit StringArrayHolder(gchar ** array):
array_(array) {}
184 ~StringArrayHolder() { g_strfreev(
array_); }
189 StringArrayHolder(StringArrayHolder
const &) =
delete;
190 StringArrayHolder& operator =(StringArrayHolder
const &) =
delete;
195class ChangesetHolder {
197 explicit ChangesetHolder(DConfChangeset * changeset):
210 ChangesetHolder(ChangesetHolder
const &) =
delete;
211 ChangesetHolder& operator =(ChangesetHolder
const &) =
delete;
217 return "/org/libreoffice/registry";
220bool decode(OUString *
string,
bool slash) {
221 for (sal_Int32 i = 0;; ++
i) {
222 i =
string->indexOf(
'\\', i);
226 if (string->match(
"00", i + 1)) {
227 *
string =
string->replaceAt(i, 3, OUStringChar(u
'\0'));
228 }
else if (slash && string->match(
"2F", i + 1)) {
229 *
string =
string->replaceAt(i, 3, u
"/");
230 }
else if (string->match(
"5C", i + 1)) {
231 *
string =
string->replaceAt(i + 1, 2, u
"");
233 SAL_WARN(
"configmgr.dconf",
"bad escape in " << *
string);
240 OString
const & key, GVariantHolder
const & variant, css::uno::Any * value)
242 assert(value !=
nullptr);
243 if (!g_variant_is_of_type(variant.get(), G_VARIANT_TYPE_BOOLEAN)) {
246 "bad key " << key <<
" does not match boolean property");
249 *
value <<= bool(g_variant_get_boolean(variant.get()));
254 OString
const & key, GVariantHolder
const & variant, css::uno::Any * value)
256 assert(value !=
nullptr);
257 if (!g_variant_is_of_type(variant.get(), G_VARIANT_TYPE_INT16)) {
260 "bad key " << key <<
" does not match short property");
263 *
value <<= sal_Int16(g_variant_get_int16(variant.get()));
268 OString
const & key, GVariantHolder
const & variant, css::uno::Any * value)
270 assert(value !=
nullptr);
271 if (!g_variant_is_of_type(variant.get(), G_VARIANT_TYPE_INT32)) {
274 "bad key " << key <<
" does not match int property");
277 *
value <<= sal_Int32(g_variant_get_int32(variant.get()));
282 OString
const & key, GVariantHolder
const & variant, css::uno::Any * value)
284 assert(value !=
nullptr);
285 if (!g_variant_is_of_type(variant.get(), G_VARIANT_TYPE_INT64)) {
288 "bad key " << key <<
" does not match long property");
291 *
value <<= sal_Int64(g_variant_get_int64(variant.get()));
296 OString
const & key, GVariantHolder
const & variant, css::uno::Any * value)
298 assert(value !=
nullptr);
299 if (!g_variant_is_of_type(variant.get(), G_VARIANT_TYPE_DOUBLE)) {
302 "bad key " << key <<
" does not match double property");
305 *
value <<= double(g_variant_get_double(variant.get()));
310 OString
const & key, GVariantHolder
const & variant, OUString * value)
312 assert(value !=
nullptr);
313 if (!g_variant_is_of_type(variant.get(), G_VARIANT_TYPE_STRING)) {
316 "bad key " << key <<
" does not match string property");
320 char const *
p = g_variant_get_string(variant.get(), &n);
322 std::numeric_limits<sal_Int32>::max()))
324 SAL_WARN(
"configmgr.dconf",
"too long string value for key " << key);
327 if (!rtl_convertStringToUString(
328 &
value->pData, p,
static_cast<sal_Int32
>(n), RTL_TEXTENCODING_UTF8,
329 (RTL_TEXTTOUNICODE_FLAGS_UNDEFINED_ERROR
330 | RTL_TEXTTOUNICODE_FLAGS_MBUNDEFINED_ERROR
331 | RTL_TEXTTOUNICODE_FLAGS_INVALID_ERROR)))
333 SAL_WARN(
"configmgr.dconf",
"non--UTF-8 string value for key " << key);
336 return decode(value,
false);
340 OString
const & key, GVariantHolder
const & variant, css::uno::Any * value)
342 assert(value !=
nullptr);
344 if (!getStringValue(key, variant, &v)) {
351bool getHexbinaryValue(
352 OString
const & key, GVariantHolder
const & variant,
353 css::uno::Sequence<sal_Int8> * value)
355 assert(value !=
nullptr);
356 if (std::strcmp(g_variant_get_type_string(variant.get()),
"ay") != 0) {
359 "bad key " << key <<
" does not match hexbinary property");
363 gconstpointer
p = g_variant_get_fixed_array(
364 variant.get(), &n, sizeof (guchar));
366 std::numeric_limits<sal_Int32>::max()))
368 SAL_WARN(
"configmgr.dconf",
"too long hexbinary value for key " << key);
371 value->realloc(
static_cast<sal_Int32
>(n));
372 static_assert(
sizeof (
sal_Int8) ==
sizeof (guchar),
"size mismatch");
373 std::memcpy(
value->getArray(), p, n * sizeof (guchar));
379 OString
const & key, GVariantHolder
const & variant, css::uno::Any * value)
381 assert(value !=
nullptr);
382 css::uno::Sequence<sal_Int8>
v;
383 if (!getHexbinaryValue(key, variant, &v)) {
391 OString
const & key, GVariantHolder
const & variant, css::uno::Any * value)
393 assert(value !=
nullptr);
394 if (std::strcmp(g_variant_get_type_string(variant.get()),
"ab") != 0) {
397 "bad key " << key <<
" does not match boolean list property");
401 gconstpointer
p = g_variant_get_fixed_array(
402 variant.get(), &n, sizeof (guchar));
404 std::numeric_limits<sal_Int32>::max()))
406 SAL_WARN(
"configmgr.dconf",
"too long boolean list for key " << key);
409 css::uno::Sequence<sal_Bool>
v(
static_cast<sal_Int32
>(n));
410 static_assert(
sizeof (
sal_Bool) ==
sizeof (guchar),
"size mismatch");
411 std::memcpy(
v.getArray(), p, n * sizeof (guchar));
418 OString
const & key, GVariantHolder
const & variant, css::uno::Any * value)
420 assert(value !=
nullptr);
421 if (std::strcmp(g_variant_get_type_string(variant.get()),
"an") != 0) {
424 "bad key " << key <<
" does not match short list property");
428 gconstpointer
p = g_variant_get_fixed_array(
429 variant.get(), &n, sizeof (gint16));
431 std::numeric_limits<sal_Int32>::max()))
433 SAL_WARN(
"configmgr.dconf",
"too long short list for key " << key);
436 css::uno::Sequence<sal_Int16>
v(
static_cast<sal_Int32
>(n));
437 static_assert(
sizeof (sal_Int16) ==
sizeof (gint16),
"size mismatch");
438 std::memcpy(
v.getArray(), p, n * sizeof (gint16));
445 OString
const & key, GVariantHolder
const & variant, css::uno::Any * value)
447 assert(value !=
nullptr);
448 if (std::strcmp(g_variant_get_type_string(variant.get()),
"ai") != 0) {
451 "bad key " << key <<
" does not match int list property");
455 gconstpointer
p = g_variant_get_fixed_array(
456 variant.get(), &n, sizeof (gint32));
458 std::numeric_limits<sal_Int32>::max()))
460 SAL_WARN(
"configmgr.dconf",
"too long int list for key " << key);
463 css::uno::Sequence<sal_Int32>
v(
static_cast<sal_Int32
>(n));
464 static_assert(
sizeof (sal_Int32) ==
sizeof (gint32),
"size mismatch");
465 std::memcpy(
v.getArray(), p, n * sizeof (gint32));
472 OString
const & key, GVariantHolder
const & variant, css::uno::Any * value)
474 assert(value !=
nullptr);
475 if (std::strcmp(g_variant_get_type_string(variant.get()),
"ax") != 0) {
478 "bad key " << key <<
" does not match long list property");
482 gconstpointer
p = g_variant_get_fixed_array(
483 variant.get(), &n, sizeof (gint64));
485 std::numeric_limits<sal_Int32>::max()))
487 SAL_WARN(
"configmgr.dconf",
"too long long list for key " << key);
490 css::uno::Sequence<sal_Int64>
v(
static_cast<sal_Int32
>(n));
491 static_assert(
sizeof (sal_Int64) ==
sizeof (gint64),
"size mismatch");
492 std::memcpy(
v.getArray(), p, n * sizeof (gint64));
499 OString
const & key, GVariantHolder
const & variant, css::uno::Any * value)
501 assert(value !=
nullptr);
502 if (std::strcmp(g_variant_get_type_string(variant.get()),
"ad") != 0) {
505 "bad key " << key <<
" does not match double list property");
509 gconstpointer
p = g_variant_get_fixed_array(
510 variant.get(), &n, sizeof (gdouble));
512 std::numeric_limits<sal_Int32>::max()))
514 SAL_WARN(
"configmgr.dconf",
"too long double list for key " << key);
517 css::uno::Sequence<double>
v(
static_cast<sal_Int32
>(n));
518 static_assert(std::is_same<double, gdouble>::value,
"type mismatch");
519 std::memcpy(
v.getArray(), p, n * sizeof (gdouble));
526 OString
const & key, GVariantHolder
const & variant, css::uno::Any * value)
528 assert(value !=
nullptr);
529 if (std::strcmp(g_variant_get_type_string(variant.get()),
"as") != 0) {
532 "bad key " << key <<
" does not match string list property");
535 gsize
n = g_variant_n_children(variant.get());
537 std::numeric_limits<sal_Int32>::max()))
539 SAL_WARN(
"configmgr.dconf",
"too long string list for key " << key);
542 css::uno::Sequence<OUString>
v(
static_cast<sal_Int32
>(n));
543 for (gsize i = 0;
i !=
n; ++
i) {
544 GVariantHolder c(g_variant_get_child_value(variant.get(), i));
545 if (!getStringValue(key, c,
v.getArray() + i)) {
553bool getHexbinaryList(
554 OString
const & key, GVariantHolder
const & variant, css::uno::Any * value)
556 assert(value !=
nullptr);
557 if (std::strcmp(g_variant_get_type_string(variant.get()),
"aay") != 0) {
560 "bad key " << key <<
" does not match hexbinary list property");
563 gsize
n = g_variant_n_children(variant.get());
565 std::numeric_limits<sal_Int32>::max()))
567 SAL_WARN(
"configmgr.dconf",
"too long hexbinary list for key " << key);
570 css::uno::Sequence<css::uno::Sequence<sal_Int8>>
v(
571 static_cast<sal_Int32
>(n));
572 for (gsize i = 0;
i !=
n; ++
i) {
573 GVariantHolder c(g_variant_get_child_value(variant.get(), i));
574 if (!getHexbinaryValue(key, c,
v.getArray() + i)) {
583 OString
const & key, GVariantHolder
const & variant, css::uno::Any * value)
585 char const *
t = g_variant_get_type_string(variant.get());
586 if (std::strcmp(t,
"b") == 0) {
587 return getBoolean(key, variant, value);
589 if (std::strcmp(t,
"n") == 0) {
590 return getShort(key, variant, value);
592 if (std::strcmp(t,
"i") == 0) {
593 return getInt(key, variant, value);
595 if (std::strcmp(t,
"x") == 0) {
596 return getLong(key, variant, value);
598 if (std::strcmp(t,
"d") == 0) {
601 if (std::strcmp(t,
"s") == 0) {
604 if (std::strcmp(t,
"ay") == 0) {
605 return getHexbinary(key, variant, value);
607 if (std::strcmp(t,
"ab") == 0) {
608 return getBooleanList(key, variant, value);
610 if (std::strcmp(t,
"an") == 0) {
611 return getShortList(key, variant, value);
613 if (std::strcmp(t,
"ai") == 0) {
614 return getIntList(key, variant, value);
616 if (std::strcmp(t,
"ax") == 0) {
617 return getLongList(key, variant, value);
619 if (std::strcmp(t,
"ad") == 0) {
620 return getDoubleList(key, variant, value);
622 if (std::strcmp(t,
"as") == 0) {
623 return getStringList(key, variant, value);
625 if (std::strcmp(t,
"aay") == 0) {
626 return getHexbinaryList(key, variant, value);
629 "configmgr.dconf",
"bad key " << key <<
" does not match any property");
636 GObjectHolder<DConfClient>
const & client, OString
const & path, Type type,
637 bool nillable,
bool removable, css::uno::Any * value)
639 assert(value !=
nullptr);
640 assert(!
value->hasValue());
641 assert(!path.endsWith(
"/"));
642 GVariantHolder
v(dconf_client_read(client.get(), path.getStr()));
643 if (
v.get() ==
nullptr) {
644 SAL_WARN(
"configmgr.dconf",
"cannot read key " << path);
645 return ReadValue::Error;
647 if (removable && std::strcmp(g_variant_get_type_string(
v.get()),
"()") == 0)
649 return ReadValue::Remove;
653 if (g_variant_classify(
v.get()) != G_VARIANT_CLASS_MAYBE) {
656 "bad key " << path <<
" does not match nillable property");
658 v.reset(g_variant_get_maybe(
v.get()));
659 nil =
v.get() ==
nullptr;
666 if (!getAny(path, v, value)) {
667 return ReadValue::Error;
671 if (!getBoolean(path, v, value)) {
672 return ReadValue::Error;
676 if (!getShort(path, v, value)) {
677 return ReadValue::Error;
681 if (!getInt(path, v, value)) {
682 return ReadValue::Error;
686 if (!getLong(path, v, value)) {
687 return ReadValue::Error;
692 return ReadValue::Error;
697 return ReadValue::Error;
701 if (!getHexbinary(path, v, value)) {
702 return ReadValue::Error;
706 if (!getBooleanList(path, v, value)) {
707 return ReadValue::Error;
711 if (!getShortList(path, v, value)) {
712 return ReadValue::Error;
716 if (!getIntList(path, v, value)) {
717 return ReadValue::Error;
721 if (!getLongList(path, v, value)) {
722 return ReadValue::Error;
726 if (!getDoubleList(path, v, value)) {
727 return ReadValue::Error;
731 if (!getStringList(path, v, value)) {
732 return ReadValue::Error;
736 if (!getHexbinaryList(path, v, value)) {
737 return ReadValue::Error;
744 return ReadValue::Value;
748 GObjectHolder<DConfClient>
const & client, OString
const & path,
751 if (!dconf_client_is_writable(client.get(), path.getStr())) {
752 node->setFinalized(layer);
758 NodeMap & members, GObjectHolder<DConfClient>
const & client,
761 StringArrayHolder
a(dconf_client_list(client.get(), dir.getStr(),
nullptr));
762 for (
char const *
const * p =
a.get(); *p !=
nullptr; ++p) {
763 std::size_t
n = std::strlen(*p);
765 std::numeric_limits<sal_Int32>::max()))
767 SAL_WARN(
"configmgr.dconf",
"too long dir/key in dir " << dir);
770 OString s(*p,
static_cast<sal_Int32
>(n));
771 OString path(dir + s);
773 if (!rtl_convertStringToUString(
774 &
name.pData, s.getStr(), s.getLength(), RTL_TEXTENCODING_UTF8,
775 (RTL_TEXTTOUNICODE_FLAGS_UNDEFINED_ERROR
776 | RTL_TEXTTOUNICODE_FLAGS_MBUNDEFINED_ERROR
777 | RTL_TEXTTOUNICODE_FLAGS_INVALID_ERROR)))
779 SAL_WARN(
"configmgr.dconf",
"non--UTF-8 dir/key in dir " << dir);
782 bool isDir =
name.endsWith(
"/", &
name);
790 "bad key " << path <<
" does not match set element");
793 if (!decode(&
name,
true)) {
798 bool content =
false;
800 StringArrayHolder a2(
801 dconf_client_list(client.get(), path.getStr(),
nullptr));
802 for (
char const *
const * p2 = a2.get(); *p2 !=
nullptr; ++p2) {
803 if (std::strcmp(*p2,
"op") == 0) {
804 OString path2(path +
"op");
806 dconf_client_read(client.get(), path2.getStr()));
807 if (
v.get() ==
nullptr) {
809 "configmgr.dconf",
"cannot read key " << path2);
814 if (!getStringValue(path2, v, &ops)) {
820 }
else if (ops ==
"replace") {
822 }
else if (ops ==
"remove") {
827 "bad key " << path2 <<
" value " << ops);
831 }
else if (std::strcmp(*p2,
"template") == 0) {
832 OString path2(path +
"template");
834 dconf_client_read(client.get(), path2.getStr()));
835 if (
v.get() ==
nullptr) {
837 "configmgr.dconf",
"cannot read key " << path2);
841 if (!getStringValue(path2, v, &templ)) {
845 if (!
static_cast<SetNode *
>(node.get())->
846 isValidTemplate(templ))
850 "bad key " << path2 <<
" value " << templ
851 <<
" denotes unsupported set element template");
855 }
else if (std::strcmp(*p2,
"content/") == 0) {
861 <<
" in set element indirection dir " << path);
873 "bad set element indirection dir " << path
874 <<
" missing \"op\" key");
878 if (templ.isEmpty() || !content) {
881 "missing \"content\" and/or \"template\" dir/key in "
882 "\"op\" = \"fuse\"/\"remove\" set element"
883 " indirection dir " << path);
888 replace = op == Op::Replace;
891 if (!templ.isEmpty() || content) {
894 "bad \"content\" and/or \"template\" dir/key in \"op\" "
895 "= \"remove\" set element indirection dir "
908 bool insert = !member.is();
910 if (replace || insert) {
912 SAL_WARN(
"configmgr.dconf",
"bad unmatched " << path);
915 switch (node->kind()) {
917 member.set(
new LocalizedValueNode(layer));
920 if (!
static_cast<GroupNode *
>(node.get())->isExtensible()) {
921 SAL_WARN(
"configmgr.dconf",
"bad unmatched " << path);
926 layer,
TYPE_ANY,
true, css::uno::Any(),
true));
929 assert(!templ.isEmpty());
930 member = data.getTemplate(layer, templ);
934 "bad " << path <<
" denoting undefined template "
938 member = member->clone(
true);
943 }
else if (!templ.isEmpty() && templ != member->getTemplateName()) {
947 <<
" denoting set element of non-matching template "
948 << member->getTemplateName());
953 if (member->getFinalized() < layer) {
956 switch (member->kind()) {
962 "bad dir " << path <<
" does not match property");
966 static_cast<PropertyNode *
>(member.get()));
969 client, path, prop->getStaticType(),
970 prop->isNillable(), prop->isExtension(),
973 case ReadValue::Error:
975 case ReadValue::Value:
976 prop->setValue(layer, value);
977 finalize(client, path, member, layer);
979 case ReadValue::Remove:
991 <<
" does not match localized value");
998 static_cast<LocalizedPropertyNode *
>(node.get()));
1001 client, path, locProp->getStaticType(),
1002 locProp->isNillable(),
false, &value)
1003 == ReadValue::Error)
1007 static_cast<LocalizedValueNode *
>(member.get())->
setValue(
1009 finalize(client, path, member, layer);
1019 <<
" does not match localized property, group, or"
1020 " set, respectively");
1023 assert(path.endsWith(
"/"));
1025 data, layer, member, member->getMembers(), client, path);
1032 if (!(member.is() && member->getMandatory())) {
1035 }
else if (replace) {
1038 }
else if (insert) {
1046 return name.toUtf8();
1049 for (sal_Int32 i = 0;
i !=
name.getLength(); ++
i) {
1065 return buf.makeStringAndClear().toUtf8();
1068OString encodeString(OUString
const & value) {
1070 for (sal_Int32 i = 0;
i !=
value.getLength(); ++
i) {
1083 return buf.makeStringAndClear().toUtf8();
1087 ChangesetHolder
const & changeset, OString
const & pathRepresentation,
1088 Type type,
bool nillable, css::uno::Any
const & value)
1096 std::forward_list<GVariantHolder> children;
1100 v.reset(g_variant_new_maybe(G_VARIANT_TYPE_BOOLEAN,
nullptr));
1103 v.reset(g_variant_new_maybe(G_VARIANT_TYPE_INT16,
nullptr));
1106 v.reset(g_variant_new_maybe(G_VARIANT_TYPE_INT32,
nullptr));
1109 v.reset(g_variant_new_maybe(G_VARIANT_TYPE_INT64,
nullptr));
1112 v.reset(g_variant_new_maybe(G_VARIANT_TYPE_DOUBLE,
nullptr));
1115 v.reset(g_variant_new_maybe(G_VARIANT_TYPE_STRING,
nullptr));
1126 static char const *
const typeString[
1128 = {
"ay",
"ab",
"an",
"ai",
"ax",
"ad",
"as",
"aay" };
1129 GVariantTypeHolder ty(
1131 if (ty.get() ==
nullptr) {
1132 SAL_WARN(
"configmgr.dconf",
"g_variant_type_new failed");
1135 v.reset(g_variant_new_maybe(ty.get(),
nullptr));
1142 if (
v.get() ==
nullptr) {
1143 SAL_WARN(
"configmgr.dconf",
"g_variant_new_maybe failed");
1149 v.reset(g_variant_new_boolean(
value.get<
bool>()));
1152 v.reset(g_variant_new_int16(
value.get<sal_Int16>()));
1155 v.reset(g_variant_new_int32(
value.get<sal_Int32>()));
1158 v.reset(g_variant_new_int64(
value.get<sal_Int64>()));
1161 v.reset(g_variant_new_double(
value.get<
double>()));
1165 g_variant_new_string(
1166 encodeString(
value.get<OUString>()).getStr()));
1170 css::uno::Sequence<sal_Int8> seq(
1171 value.get<css::uno::Sequence<sal_Int8>>());
1173 sizeof(sal_Int32) <=
sizeof(gsize),
1174 "G_MAXSIZE too small");
1176 sizeof (
sal_Int8) ==
sizeof (guchar),
"size mismatch");
1178 g_variant_new_fixed_array(
1179 G_VARIANT_TYPE_BYTE, seq.getConstArray(),
1180 seq.getLength(),
sizeof (
sal_Int8)));
1185 css::uno::Sequence<sal_Bool> seq(
1186 value.get<css::uno::Sequence<sal_Bool>>());
1188 sizeof(sal_Int32) <=
sizeof(gsize),
1189 "G_MAXSIZE too small");
1190 static_assert(
sizeof (
sal_Bool) == 1,
"size mismatch");
1192 g_variant_new_fixed_array(
1193 G_VARIANT_TYPE_BOOLEAN, seq.getConstArray(),
1194 seq.getLength(),
sizeof (
sal_Bool)));
1199 css::uno::Sequence<sal_Int16> seq(
1200 value.get<css::uno::Sequence<sal_Int16>>());
1202 sizeof(sal_Int32) <=
sizeof(gsize),
1203 "G_MAXSIZE too small");
1205 sizeof (sal_Int16) ==
sizeof (gint16),
"size mismatch");
1207 g_variant_new_fixed_array(
1208 G_VARIANT_TYPE_INT16, seq.getConstArray(),
1209 seq.getLength(),
sizeof (sal_Int16)));
1215 css::uno::Sequence<sal_Int32> seq(
1216 value.get<css::uno::Sequence<sal_Int32>>());
1218 sizeof(sal_Int32) <=
sizeof(gsize),
1219 "G_MAXSIZE too small");
1221 sizeof (sal_Int32) ==
sizeof (gint32),
"size mismatch");
1223 g_variant_new_fixed_array(
1224 G_VARIANT_TYPE_INT32, seq.getConstArray(),
1225 seq.getLength(),
sizeof (sal_Int32)));
1231 css::uno::Sequence<sal_Int64> seq(
1232 value.get<css::uno::Sequence<sal_Int64>>());
1234 sizeof(sal_Int32) <=
sizeof(gsize),
1235 "G_MAXSIZE too small");
1237 sizeof (sal_Int64) ==
sizeof (gint64),
"size mismatch");
1239 g_variant_new_fixed_array(
1240 G_VARIANT_TYPE_INT64, seq.getConstArray(),
1241 seq.getLength(),
sizeof (sal_Int64)));
1247 css::uno::Sequence<double> seq(
1248 value.get<css::uno::Sequence<double>>());
1250 sizeof(sal_Int32) <=
sizeof(gsize),
1251 "G_MAXSIZE too small");
1253 sizeof (double) ==
sizeof (gdouble),
"size mismatch");
1255 g_variant_new_fixed_array(
1256 G_VARIANT_TYPE_DOUBLE, seq.getConstArray(),
1257 seq.getLength(),
sizeof (double)));
1263 const css::uno::Sequence<OUString> seq(
1264 value.get<css::uno::Sequence<OUString>>());
1265 std::vector<GVariant *> vs;
1266 for (OUString
const & s : seq) {
1267 children.emplace_front(
1268 g_variant_new_string(encodeString(s).getStr()));
1269 if (children.front().get() ==
nullptr) {
1271 "configmgr.dconf",
"g_variant_new_string failed");
1274 vs.push_back(children.front().get());
1277 sizeof(sal_Int32) <=
sizeof(gsize),
1278 "G_MAXSIZE too small");
1280 g_variant_new_array(
1281 G_VARIANT_TYPE_STRING, vs.data(), seq.getLength()));
1286 const css::uno::Sequence<css::uno::Sequence<sal_Int8>> seqSeq(
1288 css::uno::Sequence<css::uno::Sequence<sal_Int8>>>());
1289 std::vector<GVariant *> vs;
1290 for (css::uno::Sequence<sal_Int8>
const & seq : seqSeq) {
1292 sizeof(sal_Int32) <=
sizeof(gsize),
1293 "G_MAXSIZE too small");
1295 sizeof (
sal_Int8) ==
sizeof (guchar),
"size mismatch");
1296 children.emplace_front(
1297 g_variant_new_fixed_array(
1298 G_VARIANT_TYPE_BYTE, seq.getConstArray(),
1299 seq.getLength(),
sizeof (
sal_Int8)));
1300 if (children.front().get() ==
nullptr) {
1303 "g_variant_new_fixed_array failed");
1306 vs.push_back(children.front().get());
1308 GVariantTypeHolder ty(g_variant_type_new(
"aay"));
1309 if (ty.get() ==
nullptr) {
1310 SAL_WARN(
"configmgr.dconf",
"g_variant_type_new failed");
1314 sizeof(sal_Int32) <=
sizeof(gsize),
1315 "G_MAXSIZE too small");
1317 g_variant_new_array(ty.get(), vs.data(), seqSeq.getLength()));
1324 if (
v.get() ==
nullptr) {
1325 SAL_WARN(
"configmgr.dconf",
"GVariant creation failed");
1329 GVariantHolder v1(g_variant_new_maybe(
nullptr,
v.get()));
1330 if (v1.get() ==
nullptr) {
1331 SAL_WARN(
"configmgr.dconf",
"g_variant_new_maybe failed");
1339 dconf_changeset_set(
1340 changeset.get(), pathRepresentation.getStr(),
v.get());
1341 for (
auto & i: children) {
1349 Components & components, ChangesetHolder
const & changeset,
1353 switch (node->kind()) {
1356 PropertyNode * prop =
static_cast<PropertyNode *
>(node.get());
1358 changeset, pathRepresentation, prop->getStaticType(),
1359 prop->isNillable(), prop->getValue(components)))
1368 LocalizedPropertyNode * locprop
1369 =
static_cast<LocalizedPropertyNode *
>(parent.get());
1371 changeset, pathRepresentation,
1372 locprop->getStaticType(), locprop->isNillable(),
1373 static_cast<LocalizedValueNode *
>(node.get())->
getValue()))
1382 for (
auto const & i: node->getMembers()) {
1383 OUString templ(
i.second->getTemplateName());
1385 pathRepresentation +
"/"
1387 if (!templ.isEmpty()) {
1389 GVariantHolder
v(g_variant_new_string(
"replace"));
1390 if (
v.get() ==
nullptr) {
1391 SAL_WARN(
"configmgr.dconf",
"g_variant_new_string failed");
1394 dconf_changeset_set(
1395 changeset.get(), OString(path +
"op").getStr(),
v.get());
1397 v.reset(g_variant_new_string(encodeString(templ).getStr()));
1398 if (
v.get() ==
nullptr) {
1399 SAL_WARN(
"configmgr.dconf",
"g_variant_new_string failed");
1402 dconf_changeset_set(
1403 changeset.get(), OString(path +
"template").getStr(),
1408 if (!addNode(components, changeset, parent, path,
i.second)) {
1420bool addModifications(
1421 Components & components, ChangesetHolder
const & changeset,
1422 OString
const & parentPathRepresentation,
1425 Modifications::Node
const & modifications)
1429 if (modifications.children.empty()) {
1430 assert(parent.is());
1433 OUString templ(node->getTemplateName());
1435 parentPathRepresentation +
"/"
1437 if (!templ.isEmpty()) {
1439 GVariantHolder
v(g_variant_new_string(
"replace"));
1440 if (
v.get() ==
nullptr) {
1441 SAL_WARN(
"configmgr.dconf",
"g_variant_new_string failed");
1444 dconf_changeset_set(
1445 changeset.get(), OString(path +
"op").getStr(),
v.get());
1447 v.reset(g_variant_new_string(encodeString(templ).getStr()));
1448 if (
v.get() ==
nullptr) {
1449 SAL_WARN(
"configmgr.dconf",
"g_variant_new_string failed");
1452 dconf_changeset_set(
1453 changeset.get(), OString(path +
"template").getStr(),
1458 if (!addNode(components, changeset, parent, path, node)) {
1462 switch (parent->kind()) {
1466 GVariantHolder
v(g_variant_new_tuple(
nullptr, 0));
1467 if (
v.get() ==
nullptr) {
1469 "configmgr.dconf",
"g_variant_new_tuple failed");
1472 OString path(parentPathRepresentation);
1473 if (!nodeName.isEmpty()) {
1476 dconf_changeset_set(
1477 changeset.get(), path.getStr(),
v.get());
1484 parentPathRepresentation +
"/"
1486 GVariantHolder
v(g_variant_new_string(
"remove"));
1487 if (
v.get() ==
nullptr) {
1489 "configmgr.dconf",
"g_variant_new_string failed");
1492 dconf_changeset_set(
1493 changeset.get(), OString(path +
"op").getStr(),
1496 dconf_changeset_set(
1497 changeset.get(), OString(path +
"template").getStr(),
1499 dconf_changeset_set(
1500 changeset.get(), OString(path +
"content/").getStr(),
1511 OUString templ(node->getTemplateName());
1513 parentPathRepresentation +
"/"
1515 if (!templ.isEmpty()) {
1517 GVariantHolder
v(g_variant_new_string(
"fuse"));
1518 if (
v.get() ==
nullptr) {
1519 SAL_WARN(
"configmgr.dconf",
"g_variant_new_string failed");
1522 dconf_changeset_set(
1523 changeset.get(), OString(path +
"op").getStr(),
v.get());
1525 v.reset(g_variant_new_string(encodeString(templ).getStr()));
1526 if (
v.get() ==
nullptr) {
1527 SAL_WARN(
"configmgr.dconf",
"g_variant_new_string failed");
1530 dconf_changeset_set(
1531 changeset.get(), OString(path +
"template").getStr(),
v.get());
1535 for (
auto const & i: modifications.children) {
1536 if (!addModifications(
1537 components, changeset, path, node,
i.first,
1538 node->getMember(
i.first),
i.second))
1550 GObjectHolder<DConfClient> client(dconf_client_new());
1551 if (client.get() ==
nullptr) {
1552 SAL_WARN(
"configmgr.dconf",
"dconf_client_new failed");
1561 GObjectHolder<DConfClient> client(dconf_client_new());
1562 if (client.get() ==
nullptr) {
1563 SAL_WARN(
"configmgr.dconf",
"dconf_client_new failed");
1565 ChangesetHolder cs(dconf_changeset_new());
1566 if (cs.get() ==
nullptr) {
1567 SAL_WARN(
"configmgr.dconf",
"dconf_changeset_new failed");
1571 if (!addModifications(
1579 if (!dconf_client_change_sync(
1580 client.get(), cs.get(),
nullptr,
nullptr,
nullptr))
1583 SAL_WARN(
"configmgr.dconf",
"dconf_client_change_sync failed");
Node const & getRoot() const
rtl::Reference< Node > findNode(int layer, OUString const &name) const
NodeMapImpl::value_type value_type
@ KIND_LOCALIZED_PROPERTY
DConfChangeset * changeset_
#define SAL_WARN(area, stream)
std::map< const SwTextNode *, const sal_uInt32 > NodeMap
OUStringBuffer & remove(OUStringBuffer &rIn, sal_Unicode c)
double getDouble(const Any &_rAny)
OUString getString(const Any &_rAny)
void readLayer(Data &data, int layer)
void writeModifications(Components &components, Data &data)
Type getDynamicType(css::uno::Any const &value)
css::beans::Optional< css::uno::Any > getValue(std::u16string_view id)
constexpr std::enable_if_t< std::is_signed_v< T >, std::make_unsigned_t< T > > make_unsigned(T value)
Op_< std::function< void(double &, double)>, double > Op
css::uno::Reference< css::linguistic2::XProofreadingIterator > get(css::uno::Reference< css::uno::XComponentContext > const &context)
OUString encodeSegment(const OUString &rSegment)
PyObject_HEAD PyUNO_callable_Internals * members
RegError REGISTRY_CALLTYPE setValue(RegKeyHandle hKey, rtl_uString *keyName, RegValueType valueType, RegValue pData, sal_uInt32 valueSize)
Modifications modifications
NodeMap & getComponents() const
std::vector< uno::Reference< sheet::XSpreadsheetDocument > > Components