diff --git a/docs/global/dconfigfile.zh_CN.dox b/docs/global/dconfigfile.zh_CN.dox index 8bedc0b..87ae4c7 100644 --- a/docs/global/dconfigfile.zh_CN.dox +++ b/docs/global/dconfigfile.zh_CN.dox @@ -108,6 +108,16 @@ dtk_add_config_meta_files( "name": "map", "permissions": "readwrite", "visibility": "public" + }, + "publicConfig": { + "value": true, + "serial": 0, + "flags": ["user-public"], + "name": "public configure", + "name[zh_CN]": "我是公开的配置", + "description": "I am public configure", + "permissions": "readwrite", + "visibility": "private" } } } @@ -188,6 +198,8 @@ sudo ./dconfigfile-example @brief 存在此标记时,将表明则此配置项不可被覆盖(详见下述 override 机制)。反之,不存在此标记时表明此配置项允许被覆盖,对于此类配置项,如若其有界面设置入口,则当此项不可写时,应当隐藏或禁用界面的设置入口. @var Dtk::Core::DConfigFile::Flag Dtk::Core::DConfigFile::Global @brief 当读写此类配置时,将忽略用户身份,无论程序使用哪个用户身份执行,读操作都将获取到同样的数据,写操作将对所有用户都生效。但是,如果对应的配置存储目录不存在或无权限写入,则忽略此标志 +@var Dtk::Core::DConfigFile::Flag Dtk::Core::DConfigFile::UserPublic +@brief 该类配置项允许被其他用户访问 @enum Dtk::Core::DConfigFile::Permissions diff --git a/include/global/dconfigfile.h b/include/global/dconfigfile.h index 0593f8c..5959fd9 100644 --- a/include/global/dconfigfile.h +++ b/include/global/dconfigfile.h @@ -28,7 +28,8 @@ class LIBDTKCORESHARED_EXPORT DConfigFile : public DObject{ public: enum Flag { NoOverride = 1 << 0, - Global = 1 << 1 + Global = 1 << 1, + UserPublic = 1 << 2 }; Q_DECLARE_FLAGS(Flags, Flag) diff --git a/src/dconfigfile.cpp b/src/dconfigfile.cpp index 1cc8a78..3120662 100644 --- a/src/dconfigfile.cpp +++ b/src/dconfigfile.cpp @@ -336,6 +336,8 @@ public: flags |= DConfigFile::NoOverride; } else if (flag == QLatin1String("global")) { flags |= DConfigFile::Global; + } else if (flag == QLatin1String("user-public")) { + flags |= DConfigFile::UserPublic; } } diff --git a/tests/data/dconf-example.meta.json b/tests/data/dconf-example.meta.json index d591a1c..abe786f 100755 --- a/tests/data/dconf-example.meta.json +++ b/tests/data/dconf-example.meta.json @@ -87,6 +87,16 @@ "name": "array value type", "permissions": "readwrite", "visibility": "public" + }, + "publicConfig": { + "value": true, + "serial": 0, + "flags": ["user-public"], + "name": "public configure", + "name[zh_CN]": "我是公开的配置", + "description": "I am public configure", + "permissions": "readwrite", + "visibility": "private" } } } diff --git a/tests/ut_dconfigfile.cpp b/tests/ut_dconfigfile.cpp index 8a0ab83..77d4b32 100644 --- a/tests/ut_dconfigfile.cpp +++ b/tests/ut_dconfigfile.cpp @@ -485,3 +485,14 @@ TEST_F(ut_DConfigFile, setSubpath) { ASSERT_FALSE(config.load(LocalPrefix)); } } + +TEST_F(ut_DConfigFile, userPublic) { + + FileCopyGuard guard(":/data/dconf-example.meta.json", QString("%1/%2.json").arg(metaPath, FILE_NAME)); + { + DConfigFile config(APP_ID, FILE_NAME); + ASSERT_TRUE(config.load(LocalPrefix)); + ASSERT_TRUE(config.meta()->flags("publicConfig").testFlag(DConfigFile::UserPublic)); + ASSERT_FALSE(config.meta()->flags("canExit").testFlag(DConfigFile::UserPublic)); + } +}