clan_vm_manager: Fix incorrect signal behaviour in GKVStore setitem
This commit is contained in:
parent
ce3fc6973b
commit
483e2c05ea
@ -95,6 +95,10 @@ class GKVStore(GObject.GObject, Gio.ListModel, Generic[K, V]):
|
||||
# #
|
||||
#########################
|
||||
def insert(self, position: int, item: V) -> None:
|
||||
log.warning("Inserting is O(n) in GKVStore. Better use append")
|
||||
log.warning(
|
||||
"This functions may have incorrect items_changed signal behavior. Please test it"
|
||||
)
|
||||
key = self.key_gen(item)
|
||||
if key in self._items:
|
||||
raise ValueError("Key already exists in the dictionary")
|
||||
@ -141,12 +145,12 @@ class GKVStore(GObject.GObject, Gio.ListModel, Generic[K, V]):
|
||||
log.warning("Updating an existing key in GKVStore is O(n)")
|
||||
position = self.keys().index(key)
|
||||
self._items[key] = value
|
||||
self.items_changed(position, 0, 1)
|
||||
self.items_changed(position, 1, 1)
|
||||
else:
|
||||
# Add the new key-value pair
|
||||
position = max(len(self._items) - 1, 0)
|
||||
self._items[key] = value
|
||||
self._items.move_to_end(key)
|
||||
position = max(len(self._items) - 1, 0)
|
||||
self.items_changed(position, 0, 1)
|
||||
|
||||
# O(n) operation
|
||||
|
@ -1,5 +1,6 @@
|
||||
import logging
|
||||
import threading
|
||||
from collections.abc import Callable
|
||||
from typing import Any, ClassVar
|
||||
|
||||
import gi
|
||||
@ -67,17 +68,20 @@ class JoinList:
|
||||
def is_empty(self) -> bool:
|
||||
return self.list_store.get_n_items() == 0
|
||||
|
||||
def push(self, value: JoinValue) -> None:
|
||||
def push(
|
||||
self, value: JoinValue, after_join: Callable[[JoinValue, JoinValue], None]
|
||||
) -> None:
|
||||
"""
|
||||
Add a join request.
|
||||
This method can add multiple join requests if called subsequently for each request.
|
||||
"""
|
||||
|
||||
if value.url.get_id() in [item.url.get_id() for item in self.list_store]:
|
||||
log.info(f"Join request already exists: {value.url}")
|
||||
log.info(f"Join request already exists: {value.url}. Ignoring.")
|
||||
return
|
||||
|
||||
value.connect("join_finished", self._on_join_finished)
|
||||
value.connect("join_finished", after_join)
|
||||
|
||||
self.list_store.append(value)
|
||||
|
||||
|
@ -223,8 +223,7 @@ class ClanList(Gtk.Box):
|
||||
log.debug("Join request: %s", url)
|
||||
clan_uri = ClanURI.from_str(url)
|
||||
value = JoinValue(url=clan_uri)
|
||||
JoinList.use().push(value)
|
||||
value.connect("join_finished", self.on_after_join)
|
||||
JoinList.use().push(value, self.on_after_join)
|
||||
|
||||
def on_after_join(self, source: JoinValue, item: JoinValue) -> None:
|
||||
# If the join request list is empty disable the shadow artefact
|
||||
|
Loading…
Reference in New Issue
Block a user