本文整理汇总了C++中KConfigGroup::isImmutable方法的典型用法代码示例。如果您正苦于以下问题:C++ KConfigGroup::isImmutable方法的具体用法?C++ KConfigGroup::isImmutable怎么用?C++ KConfigGroup::isImmutable使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类KConfigGroup
的用法示例。
在下文中一共展示了KConfigGroup::isImmutable方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: process
void process(Mode mode, KConfigGroup &grp, QString key, QString value)
{
switch (mode) {
case Read:
if (IS_A_TTY(1))
std::cout << CHAR(key) << ": " << CHAR(grp.readEntry(key, "does not exist")) << " (" << CHAR(path(grp)) << ")" << std::endl;
else
std::cout << CHAR(grp.readEntry(key, ""));
break;
case Write: {
if (grp.isImmutable()) {
std::cout << "The component/group " << CHAR(path(grp)) << " cannot be modified" << std::endl;
exit(1);
}
bool added = !grp.hasKey(key);
QString oldv;
if (!added) oldv = grp.readEntry(key);
grp.writeEntry(key, QString(value));
grp.sync();
if (added)
std::cout << "New " << CHAR(key) << ": " << CHAR(grp.readEntry(key)) << std::endl;
else
std::cout << CHAR(key) << ": " << CHAR(oldv) << " -> " << CHAR(grp.readEntry(key)) << std::endl;
break;
}
case Delete: {
if (grp.isImmutable()) {
std::cout << "The component/group " << CHAR(path(grp)) << " cannot be modified" << std::endl;
exit(1);
}
if (grp.hasKey(key)) {
std::cout << "Removed " << CHAR(key) << ": " << CHAR(grp.readEntry(key)) << std::endl;
grp.deleteEntry(key);
grp.sync();
} else if (grp.hasGroup(key)) {
std::cout << "There's a group, but no key: " << CHAR(key) << "\nPlease explicitly use deletegroup" << std::endl;
exit(1);
} else {
std::cout << "There's no key " << CHAR(key) << " in " << CHAR(path(grp)) << std::endl;
exit(1);
}
break;
}
case DeleteGroup: {
if (grp.hasGroup(key)) {
grp = grp.group(key);
if (grp.isImmutable()) {
std::cout << "The component/group " << CHAR(path(grp)) << " cannot be modified" << std::endl;
exit(1);
}
QMap<QString, QString> map = grp.entryMap();
std::cout << "Removed " << CHAR(key) << gs_separator << std::endl;
for (QMap<QString, QString>::const_iterator it = map.constBegin(), end = map.constEnd(); it != end; ++it) {
std::cout << CHAR(it.key()) << ": " << CHAR(it.value()) << std::endl;
}
grp.deleteGroup();
grp.sync();
} else {
std::cout << "There's no group " << CHAR(key) << " in " << CHAR(path(grp)) << std::endl;
exit(1);
}
break;
}
case List:
case ListKeys: {
if (!grp.exists()) { // could be parent group
if (mode == ListKeys)
exit(1);
QStringList groups = grp.parent().exists() ? grp.parent().groupList() : grp.config()->groupList();
if (groups.isEmpty()) {
std::cout << "The component/group " << CHAR(path(grp)) << " does not exist" << std::endl;
exit(1);
}
std::cout << "Groups in " << CHAR(path(grp)) << gs_separator << std::endl;
foreach (const QString &s, groups)
if (key.isEmpty() || s.contains(key, Qt::CaseInsensitive))
std::cout << CHAR(s) << std::endl;
exit(0);
}
QMap<QString, QString> map = grp.entryMap();
if (map.isEmpty()) {
std::cout << "The group " << CHAR(path(grp)) << " is empty" << std::endl;
break;
}
if (mode == List) {
bool matchFound = false;
for (QMap<QString, QString>::const_iterator it = map.constBegin(), end = map.constEnd(); it != end; ++it) {
if (key.isEmpty() || it.key().contains(key, Qt::CaseInsensitive)) {
if (!matchFound)
std::cout << std::endl << CHAR(path(grp)) << gs_separator << std::endl;
matchFound = true;
std::cout << CHAR(it.key()) << ": " << CHAR(it.value()) << std::endl;
}
}
if (!matchFound)
std::cout << "No present key matches \"" << CHAR(key) << "\" in " << CHAR(path(grp));
std::cout << std::endl;
//.........这里部分代码省略.........