Changeset View
Changeset View
Standalone View
Standalone View
rules.cpp
Show First 20 Lines • Show All 1074 Lines • ▼ Show 20 Line(s) | 1071 | for (int i = 1; | |||
---|---|---|---|---|---|
1075 | Rules* rule = new Rules(cg); | 1075 | Rules* rule = new Rules(cg); | ||
1076 | m_rules.append(rule); | 1076 | m_rules.append(rule); | ||
1077 | } | 1077 | } | ||
1078 | } | 1078 | } | ||
1079 | 1079 | | |||
1080 | void RuleBook::save() | 1080 | void RuleBook::save() | ||
1081 | { | 1081 | { | ||
1082 | m_updateTimer->stop(); | 1082 | m_updateTimer->stop(); | ||
1083 | KConfig cfg(QStringLiteral(KWIN_NAME "rulesrc"), KConfig::NoGlobals); | 1083 | if (!m_config) { | ||
1084 | QStringList groups = cfg.groupList(); | 1084 | qCWarning(KWIN_CORE) << "RuleBook::save invoked without prior invokation of RuleBook::load"; | ||
romangg: Shouldn't it call `openConfig` in this case in order to set `m_config` and not just return? | |||||
Save cannot be called without calling load before. Thus I decided to not add the load code as it would be dead code. M_config is a smart pointer, thus does not need to be explicitly initialized with null. graesslin: Save cannot be called without calling load before. Thus I decided to not add the load code as… | |||||
romangg: Assert then? | |||||
graesslin: I don't like asserts | |||||
romangg: Maybe then a warning message. Anyways, this is a non-blocking issue for me. | |||||
1085 | return; | ||||
1086 | } | ||||
1087 | QStringList groups = m_config->groupList(); | ||||
1085 | for (QStringList::ConstIterator it = groups.constBegin(); | 1088 | for (QStringList::ConstIterator it = groups.constBegin(); | ||
1086 | it != groups.constEnd(); | 1089 | it != groups.constEnd(); | ||
1087 | ++it) | 1090 | ++it) | ||
1088 | cfg.deleteGroup(*it); | 1091 | m_config->deleteGroup(*it); | ||
1089 | cfg.group("General").writeEntry("count", m_rules.count()); | 1092 | m_config->group("General").writeEntry("count", m_rules.count()); | ||
1090 | int i = 1; | 1093 | int i = 1; | ||
1091 | for (QList< Rules* >::ConstIterator it = m_rules.constBegin(); | 1094 | for (QList< Rules* >::ConstIterator it = m_rules.constBegin(); | ||
1092 | it != m_rules.constEnd(); | 1095 | it != m_rules.constEnd(); | ||
1093 | ++it) { | 1096 | ++it) { | ||
1094 | if ((*it)->isTemporary()) | 1097 | if ((*it)->isTemporary()) | ||
1095 | continue; | 1098 | continue; | ||
1096 | KConfigGroup cg(&cfg, QString::number(i)); | 1099 | KConfigGroup cg(m_config, QString::number(i)); | ||
1097 | (*it)->write(cg); | 1100 | (*it)->write(cg); | ||
1098 | ++i; | 1101 | ++i; | ||
1099 | } | 1102 | } | ||
1100 | } | 1103 | } | ||
1101 | 1104 | | |||
1102 | void RuleBook::temporaryRulesMessage(const QString& message) | 1105 | void RuleBook::temporaryRulesMessage(const QString& message) | ||
1103 | { | 1106 | { | ||
1104 | bool was_temporary = false; | 1107 | bool was_temporary = false; | ||
▲ Show 20 Lines • Show All 70 Lines • Show Last 20 Lines |
Shouldn't it call openConfig in this case in order to set m_config and not just return? Also note that m_config is not initialized as a nullptr in the header file or in the constructor. Might be a problem with the check on !m_config (but should be then in the load function as well).