Skip to content

Commit 12dc3da

Browse files
deepin-ci-robotmhduiy
authored andcommitted
sync: from linuxdeepin/dtkcore
Synchronize source files from linuxdeepin/dtkcore. Source-pull-request: linuxdeepin/dtkcore#451
1 parent 66f1448 commit 12dc3da

File tree

4 files changed

+33
-1
lines changed

4 files changed

+33
-1
lines changed

src/dconfigfile.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1288,12 +1288,22 @@ class Q_DECL_HIDDEN DConfigFilePrivate : public DObjectPrivate {
12881288
return cache->setValue(key, value, configMeta->serial(key), cache->uid(), appid);
12891289

12901290
// convert copy to meta's type, it promises `setValue` don't change meta's type.
1291+
// canConvert isn't explicit, e.g: QString is also can convert to double.
12911292
auto copy = value;
12921293
if (!copy.convert(metaValue.metaType())) {
12931294
qCWarning(cfLog) << "check type error, meta type is " << metaValue.metaType().name()
12941295
<< ", and now type is " << value.metaType().name();
12951296
return false;
12961297
}
1298+
1299+
// TODO it's a bug of qt, MetaType of 1.0 is qlonglong instead of double in json file.
1300+
static const QVector<QMetaType> filterConvertType {
1301+
QMetaType{QMetaType::Double}
1302+
};
1303+
// reset to origin value.
1304+
if (filterConvertType.contains(value.metaType())) {
1305+
copy = value;
1306+
}
12971307
#else
12981308
if (metaValue.type() == value.type())
12991309
return cache->setValue(key, value, configMeta->serial(key), cache->uid(), appid);
@@ -1304,6 +1314,13 @@ class Q_DECL_HIDDEN DConfigFilePrivate : public DObjectPrivate {
13041314
<< ", and now type is " << value.type();
13051315
return false;
13061316
}
1317+
1318+
static const QVector<QVariant::Type> filterConvertType {
1319+
QVariant::Double
1320+
};
1321+
if (filterConvertType.contains(value.type())) {
1322+
copy = value;
1323+
}
13071324
#endif
13081325

13091326
return cache->setValue(key, copy, configMeta->serial(key), cache->uid(), appid);

src/dsgapplication.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ QByteArray DSGApplication::getId(qint64 pid)
100100

101101
int pidfd = syscall(SYS_pidfd_open, pid, 0);
102102
if (pidfd < 0) {
103-
qCWarning(dsgApp) << "pidfd open failed:" << strerror(errno);
103+
qCWarning(dsgApp) << "pidfd open failed:" << strerror(errno) << ", the pid:" << pid;
104104
return QByteArray();
105105
}
106106

@@ -109,6 +109,8 @@ QByteArray DSGApplication::getId(qint64 pid)
109109
"org.desktopspec.ApplicationManager1");
110110

111111
QDBusReply<QString> reply = infc.call("Identify", QVariant::fromValue(QDBusUnixFileDescriptor(pidfd)));
112+
// see QDBusUnixFileDescriptor: The original file descriptor is not touched and must be closed by the user.
113+
close(pidfd);
112114

113115
if (!reply.isValid()) {
114116
qCWarning(dsgApp) << "Identify from AM failed." << reply.error().message();

tests/data/dconf-example.meta.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,14 @@
4040
"permissions": "readwrite",
4141
"visibility": "public"
4242
},
43+
"numberDouble": {
44+
"value": 1.0,
45+
"serial": 0,
46+
"flags": ["global"],
47+
"name": "double value type",
48+
"permissions": "readwrite",
49+
"visibility": "public"
50+
},
4351
"array": {
4452
"value": ["value1", "value2"],
4553
"serial": 0,

tests/ut_dconfigfile.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,11 @@ TEST_F(ut_DConfigFile, setValueTypeCheck) {
124124
ASSERT_FALSE(config.setValue("number", "1ab", "test", userCache.get()));
125125
ASSERT_EQ(config.value("number", userCache.get()).type(), type);
126126
}
127+
{
128+
const auto type = config.value("numberDouble", userCache.get()).type();
129+
ASSERT_TRUE(config.setValue("numberDouble", 1.2, "test", userCache.get()));
130+
ASSERT_EQ(config.value("numberDouble", userCache.get()), 1.2);
131+
}
127132
{
128133
const auto type = config.value("array", userCache.get()).type();
129134
const QStringList array{"value1", "value2"};

0 commit comments

Comments
 (0)