Skip to content
Snippets Groups Projects
Verified Commit 4910b1df authored by Janne Mareike Koschinski's avatar Janne Mareike Koschinski
Browse files

Fixes #135

parent 7a26345c
No related branches found
No related tags found
No related merge requests found
...@@ -163,6 +163,18 @@ class HighlightListFragment : SettingsFragment(), SettingsFragment.Savable, ...@@ -163,6 +163,18 @@ class HighlightListFragment : SettingsFragment(), SettingsFragment.Savable,
private fun startIgnoreRuleDrag(holder: HighlightRuleAdapter.HighlightRuleViewHolder) = private fun startIgnoreRuleDrag(holder: HighlightRuleAdapter.HighlightRuleViewHolder) =
ignoreRulesHelper.startDrag(holder) ignoreRulesHelper.startDrag(holder)
private fun nextId(): Int {
val maxRuleId = rulesAdapter.list.maxBy { it.id }?.id
val maxIgnoreRuleId = ignoreRulesAdapter.list.maxBy { it.id }?.id
return when {
maxRuleId != null && maxIgnoreRuleId != null -> maxOf(maxRuleId, maxIgnoreRuleId) + 1
maxIgnoreRuleId != null -> maxIgnoreRuleId + 1
maxRuleId != null -> maxRuleId + 1
else -> 0
}
}
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
if (resultCode == Activity.RESULT_OK && data != null) { if (resultCode == Activity.RESULT_OK && data != null) {
when (requestCode) { when (requestCode) {
...@@ -178,7 +190,7 @@ class HighlightListFragment : SettingsFragment(), SettingsFragment.Savable, ...@@ -178,7 +190,7 @@ class HighlightListFragment : SettingsFragment(), SettingsFragment.Savable,
val newRule = data.getSerializableExtra("new") as? HighlightRuleManager.HighlightRule val newRule = data.getSerializableExtra("new") as? HighlightRuleManager.HighlightRule
if (newRule != null) { if (newRule != null) {
rulesAdapter.add(newRule) rulesAdapter.add(newRule.copy(id = nextId()))
} }
} }
REQUEST_UPDATE_IGNORE_RULE -> { REQUEST_UPDATE_IGNORE_RULE -> {
...@@ -193,7 +205,7 @@ class HighlightListFragment : SettingsFragment(), SettingsFragment.Savable, ...@@ -193,7 +205,7 @@ class HighlightListFragment : SettingsFragment(), SettingsFragment.Savable,
val newRule = data.getSerializableExtra("new") as? HighlightRuleManager.HighlightRule val newRule = data.getSerializableExtra("new") as? HighlightRuleManager.HighlightRule
if (newRule != null) { if (newRule != null) {
ignoreRulesAdapter.add(newRule) ignoreRulesAdapter.add(newRule.copy(id = nextId()))
} }
} }
} }
......
...@@ -81,6 +81,7 @@ class HighlightRuleFragment : SettingsFragment(), SettingsFragment.Savable, ...@@ -81,6 +81,7 @@ class HighlightRuleFragment : SettingsFragment(), SettingsFragment.Savable,
} }
private fun applyChanges() = HighlightRuleManager.HighlightRule( private fun applyChanges() = HighlightRuleManager.HighlightRule(
id = rule?.id ?: -1,
isInverse = rule?.isInverse ?: isInverse ?: false, isInverse = rule?.isInverse ?: isInverse ?: false,
isEnabled = enabled.isChecked, isEnabled = enabled.isChecked,
name = name.text.toString(), name = name.text.toString(),
......
...@@ -28,6 +28,7 @@ class HighlightRuleManager( ...@@ -28,6 +28,7 @@ class HighlightRuleManager(
proxy: SignalProxy proxy: SignalProxy
) : SyncableObject(proxy, "HighlightRuleManager"), IHighlightRuleManager { ) : SyncableObject(proxy, "HighlightRuleManager"), IHighlightRuleManager {
data class HighlightRule( data class HighlightRule(
val id: Int,
val name: String, val name: String,
val isRegEx: Boolean = false, val isRegEx: Boolean = false,
val isCaseSensitive: Boolean = false, val isCaseSensitive: Boolean = false,
...@@ -38,14 +39,24 @@ class HighlightRuleManager( ...@@ -38,14 +39,24 @@ class HighlightRuleManager(
) : Serializable ) : Serializable
override fun toVariantMap(): QVariantMap = mapOf( override fun toVariantMap(): QVariantMap = mapOf(
"HighlightRuleList" to QVariant.of(initHighlightRuleList(), Type.QVariantMap) "HighlightRuleList" to QVariant.of(initHighlightRuleList(), Type.QVariantMap),
"highlightNick" to QVariant.of(_highlightNick.value, Type.Int),
"nicksCaseSensitive" to QVariant.of(_nicksCaseSensitive, Type.Bool)
) )
override fun fromVariantMap(properties: QVariantMap) { override fun fromVariantMap(properties: QVariantMap) {
initSetHighlightRuleList(properties["HighlightRuleList"].valueOr(::emptyMap)) initSetHighlightRuleList(properties["HighlightRuleList"].valueOr(::emptyMap))
_highlightNick = properties["highlightNick"].value<Int>()?.let {
IHighlightRuleManager.HighlightNickType.of(it)
} ?: _highlightNick
_nicksCaseSensitive = properties["nicksCaseSensitive"].value(_nicksCaseSensitive)
} }
override fun initHighlightRuleList(): QVariantMap = mapOf( override fun initHighlightRuleList(): QVariantMap = mapOf(
"id" to QVariant.of(_highlightRuleList.map {
QVariant.of(it.id, Type.Int)
}, Type.QVariantList),
"name" to QVariant.of(_highlightRuleList.map { "name" to QVariant.of(_highlightRuleList.map {
it.name it.name
}, Type.QStringList), }, Type.QStringList),
...@@ -66,12 +77,11 @@ class HighlightRuleManager( ...@@ -66,12 +77,11 @@ class HighlightRuleManager(
}, Type.QStringList), }, Type.QStringList),
"channel" to QVariant.of(_highlightRuleList.map { "channel" to QVariant.of(_highlightRuleList.map {
it.channel it.channel
}, Type.QStringList), }, Type.QStringList)
"highlightNick" to QVariant.of(_highlightNick.value, Type.Int),
"nicksCaseSensitive" to QVariant.of(_nicksCaseSensitive, Type.Bool)
) )
override fun initSetHighlightRuleList(highlightRuleList: QVariantMap) { override fun initSetHighlightRuleList(highlightRuleList: QVariantMap) {
val idList = highlightRuleList["id"].valueOr<QVariantList>(::emptyList)
val nameList = highlightRuleList["name"].valueOr<QStringList>(::emptyList) val nameList = highlightRuleList["name"].valueOr<QStringList>(::emptyList)
val isRegExList = highlightRuleList["isRegEx"].valueOr<QVariantList>(::emptyList) val isRegExList = highlightRuleList["isRegEx"].valueOr<QVariantList>(::emptyList)
val isCaseSensitiveList = highlightRuleList["isCaseSensitive"].valueOr<QVariantList>(::emptyList) val isCaseSensitiveList = highlightRuleList["isCaseSensitive"].valueOr<QVariantList>(::emptyList)
...@@ -79,14 +89,15 @@ class HighlightRuleManager( ...@@ -79,14 +89,15 @@ class HighlightRuleManager(
val isInverseList = highlightRuleList["isInverse"].valueOr<QVariantList>(::emptyList) val isInverseList = highlightRuleList["isInverse"].valueOr<QVariantList>(::emptyList)
val senderList = highlightRuleList["sender"].valueOr<QStringList>(::emptyList) val senderList = highlightRuleList["sender"].valueOr<QStringList>(::emptyList)
val channelList = highlightRuleList["channel"].valueOr<QStringList>(::emptyList) val channelList = highlightRuleList["channel"].valueOr<QStringList>(::emptyList)
val size = nameList.size val size = idList.size
if (isRegExList.size != size || isCaseSensitiveList.size != size || if (nameList.size != size || isRegExList.size != size || isCaseSensitiveList.size != size ||
isEnabledList.size != size || isInverseList.size != size || senderList.size != size || isEnabledList.size != size || isInverseList.size != size || senderList.size != size ||
channelList.size != size) channelList.size != size)
return return
_highlightRuleList = List(size, { _highlightRuleList = List(size) {
HighlightRule( HighlightRule(
id = idList[it].value(0),
name = nameList[it] ?: "", name = nameList[it] ?: "",
isRegEx = isRegExList[it].value(false), isRegEx = isRegExList[it].value(false),
isCaseSensitive = isCaseSensitiveList[it].value(false), isCaseSensitive = isCaseSensitiveList[it].value(false),
...@@ -95,28 +106,24 @@ class HighlightRuleManager( ...@@ -95,28 +106,24 @@ class HighlightRuleManager(
sender = senderList[it] ?: "", sender = senderList[it] ?: "",
channel = channelList[it] ?: "" channel = channelList[it] ?: ""
) )
}) }
_highlightNick = highlightRuleList["highlightNick"].value<Int>()?.let {
IHighlightRuleManager.HighlightNickType.of(it)
} ?: _highlightNick
_nicksCaseSensitive = highlightRuleList["nicksCaseSensitive"].value(_nicksCaseSensitive)
} }
override fun removeHighlightRule(highlightRule: String) = removeAt(indexOf(highlightRule)) override fun removeHighlightRule(highlightRule: Int) = removeAt(indexOf(highlightRule))
override fun toggleHighlightRule(highlightRule: String) { override fun toggleHighlightRule(highlightRule: Int) {
_highlightRuleList = _highlightRuleList.map { _highlightRuleList = _highlightRuleList.map {
if (it.name == highlightRule) it.copy(isEnabled = !it.isEnabled) else it if (it.id == highlightRule) it.copy(isEnabled = !it.isEnabled) else it
} }
} }
override fun addHighlightRule(name: String, isRegEx: Boolean, isCaseSensitive: Boolean, override fun addHighlightRule(id: Int, name: String, isRegEx: Boolean, isCaseSensitive: Boolean,
isEnabled: Boolean, isInverse: Boolean, sender: String, isEnabled: Boolean, isInverse: Boolean, sender: String,
chanName: String) { chanName: String) {
if (contains(name)) return if (contains(id)) return
_highlightRuleList += HighlightRule( _highlightRuleList += HighlightRule(
name, isRegEx, isCaseSensitive, isEnabled, isInverse, sender, chanName id, name, isRegEx, isCaseSensitive, isEnabled, isInverse, sender, chanName
) )
} }
...@@ -131,8 +138,8 @@ class HighlightRuleManager( ...@@ -131,8 +138,8 @@ class HighlightRuleManager(
_nicksCaseSensitive = nicksCaseSensitive _nicksCaseSensitive = nicksCaseSensitive
} }
fun indexOf(name: String): Int = _highlightRuleList.indexOfFirst { it.name == name } fun indexOf(id: Int): Int = _highlightRuleList.indexOfFirst { it.id == id }
fun contains(name: String) = _highlightRuleList.any { it.name == name } fun contains(id: Int) = _highlightRuleList.any { it.id == id }
fun isEmpty() = _highlightRuleList.isEmpty() fun isEmpty() = _highlightRuleList.isEmpty()
fun count() = _highlightRuleList.count() fun count() = _highlightRuleList.count()
......
...@@ -48,12 +48,12 @@ interface IHighlightRuleManager : ISyncableObject { ...@@ -48,12 +48,12 @@ interface IHighlightRuleManager : ISyncableObject {
* @param highlightRule A valid ignore rule * @param highlightRule A valid ignore rule
*/ */
@Slot @Slot
fun requestRemoveHighlightRule(highlightRule: String) { fun requestRemoveHighlightRule(highlightRule: Int) {
REQUEST("requestRemoveHighlightRule", ARG(highlightRule, Type.QString)) REQUEST("requestRemoveHighlightRule", ARG(highlightRule, Type.Int))
} }
@Slot @Slot
fun removeHighlightRule(highlightRule: String) fun removeHighlightRule(highlightRule: Int)
/** /**
* Request toggling of "isEnabled" flag of a given ignore rule. * Request toggling of "isEnabled" flag of a given ignore rule.
...@@ -62,12 +62,12 @@ interface IHighlightRuleManager : ISyncableObject { ...@@ -62,12 +62,12 @@ interface IHighlightRuleManager : ISyncableObject {
* @param highlightRule A valid ignore rule * @param highlightRule A valid ignore rule
*/ */
@Slot @Slot
fun requestToggleHighlightRule(highlightRule: String) { fun requestToggleHighlightRule(highlightRule: Int) {
REQUEST("requestToggleHighlightRule", ARG(highlightRule, Type.QString)) REQUEST("requestToggleHighlightRule", ARG(highlightRule, Type.Int))
} }
@Slot @Slot
fun toggleHighlightRule(highlightRule: String) fun toggleHighlightRule(highlightRule: Int)
/** /**
* Request an HighlightRule to be added to the ignore list * Request an HighlightRule to be added to the ignore list
...@@ -79,17 +79,17 @@ interface IHighlightRuleManager : ISyncableObject { ...@@ -79,17 +79,17 @@ interface IHighlightRuleManager : ISyncableObject {
* @param chanName The channel in which the rule should apply * @param chanName The channel in which the rule should apply
*/ */
@Slot @Slot
fun requestAddHighlightRule(name: String, isRegEx: Boolean, isCaseSensitive: Boolean, fun requestAddHighlightRule(id: Int, name: String, isRegEx: Boolean, isCaseSensitive: Boolean,
isEnabled: Boolean, isEnabled: Boolean, isInverse: Boolean, sender: String,
isInverse: Boolean, sender: String, chanName: String) { chanName: String) {
REQUEST("requestAddHighlightRule", ARG(name, Type.QString), ARG(isRegEx, Type.Bool), REQUEST("requestAddHighlightRule", ARG(id, Type.Int), ARG(name, Type.QString),
ARG(isCaseSensitive, Type.Bool), ARG(isEnabled, Type.Bool), ARG(isInverse, Type.Bool), ARG(isRegEx, Type.Bool), ARG(isCaseSensitive, Type.Bool), ARG(isEnabled, Type.Bool),
ARG(sender, Type.QString), ARG(chanName, Type.QString)) ARG(isInverse, Type.Bool), ARG(sender, Type.QString), ARG(chanName, Type.QString))
} }
@Slot @Slot
fun addHighlightRule(name: String, isRegEx: Boolean, isCaseSensitive: Boolean, isEnabled: Boolean, fun addHighlightRule(id: Int, name: String, isRegEx: Boolean, isCaseSensitive: Boolean,
isInverse: Boolean, sender: String, chanName: String) isEnabled: Boolean, isInverse: Boolean, sender: String, chanName: String)
@Slot @Slot
fun requestSetHighlightNick(highlightNick: Int) { fun requestSetHighlightNick(highlightNick: Int) {
......
...@@ -22,10 +22,7 @@ package de.kuschku.libquassel.quassel.syncables ...@@ -22,10 +22,7 @@ package de.kuschku.libquassel.quassel.syncables
import de.kuschku.libquassel.protocol.primitive.serializer.VariantMapSerializer import de.kuschku.libquassel.protocol.primitive.serializer.VariantMapSerializer
import de.kuschku.libquassel.quassel.syncables.interfaces.IHighlightRuleManager import de.kuschku.libquassel.quassel.syncables.interfaces.IHighlightRuleManager
import de.kuschku.libquassel.session.SignalProxy import de.kuschku.libquassel.session.SignalProxy
import de.kuschku.libquassel.util.randomBoolean import de.kuschku.libquassel.util.*
import de.kuschku.libquassel.util.randomOf
import de.kuschku.libquassel.util.randomString
import de.kuschku.libquassel.util.roundTrip
import org.junit.Test import org.junit.Test
class HighlightRuleManagerTest { class HighlightRuleManagerTest {
...@@ -36,6 +33,7 @@ class HighlightRuleManagerTest { ...@@ -36,6 +33,7 @@ class HighlightRuleManagerTest {
original.setNicksCaseSensitive(randomBoolean()) original.setNicksCaseSensitive(randomBoolean())
original.setHighlightRuleList(listOf( original.setHighlightRuleList(listOf(
HighlightRuleManager.HighlightRule( HighlightRuleManager.HighlightRule(
randomInt(),
randomString(), randomString(),
randomBoolean(), randomBoolean(),
randomBoolean(), randomBoolean(),
...@@ -45,6 +43,7 @@ class HighlightRuleManagerTest { ...@@ -45,6 +43,7 @@ class HighlightRuleManagerTest {
randomString() randomString()
), ),
HighlightRuleManager.HighlightRule( HighlightRuleManager.HighlightRule(
randomInt(),
randomString(), randomString(),
randomBoolean(), randomBoolean(),
randomBoolean(), randomBoolean(),
...@@ -54,6 +53,7 @@ class HighlightRuleManagerTest { ...@@ -54,6 +53,7 @@ class HighlightRuleManagerTest {
randomString() randomString()
), ),
HighlightRuleManager.HighlightRule( HighlightRuleManager.HighlightRule(
randomInt(),
randomString(), randomString(),
randomBoolean(), randomBoolean(),
randomBoolean(), randomBoolean(),
...@@ -76,6 +76,7 @@ class HighlightRuleManagerTest { ...@@ -76,6 +76,7 @@ class HighlightRuleManagerTest {
original.setNicksCaseSensitive(randomBoolean()) original.setNicksCaseSensitive(randomBoolean())
original.setHighlightRuleList(listOf( original.setHighlightRuleList(listOf(
HighlightRuleManager.HighlightRule( HighlightRuleManager.HighlightRule(
randomInt(),
randomString(), randomString(),
randomBoolean(), randomBoolean(),
randomBoolean(), randomBoolean(),
...@@ -85,6 +86,7 @@ class HighlightRuleManagerTest { ...@@ -85,6 +86,7 @@ class HighlightRuleManagerTest {
randomString() randomString()
), ),
HighlightRuleManager.HighlightRule( HighlightRuleManager.HighlightRule(
randomInt(),
randomString(), randomString(),
randomBoolean(), randomBoolean(),
randomBoolean(), randomBoolean(),
...@@ -94,6 +96,7 @@ class HighlightRuleManagerTest { ...@@ -94,6 +96,7 @@ class HighlightRuleManagerTest {
randomString() randomString()
), ),
HighlightRuleManager.HighlightRule( HighlightRuleManager.HighlightRule(
randomInt(),
randomString(), randomString(),
randomBoolean(), randomBoolean(),
randomBoolean(), randomBoolean(),
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment