Skip to content

Commit

Permalink
Fix StarToggleButton hover leave
Browse files Browse the repository at this point in the history
The icon was being reset to always-on even if the source weren't
starred. This adds a check for that, and also corrects the misleading
naming of the attribute determining whether the star API calls should
be made when the widget state changes. (If it only takes a weekend for
your naming to start tripping you up, it was clearly not thought
through.)
  • Loading branch information
rmol authored and sssoleileraaa committed Mar 16, 2020
1 parent 4f86a61 commit 8ab6101
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions securedrop_client/gui/widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -1203,7 +1203,6 @@ def __init__(self, controller: Controller, source: Source):
self.source = source

self.installEventFilter(self)
self.toggle_event_enabled = True

self.setObjectName('star_button')
self.setStyleSheet(self.css)
Expand All @@ -1222,6 +1221,7 @@ def disable(self):
to save on state we update the icon's off state image to
display on (hack).
"""
self.disable_api_call()
self.setCheckable(False)
if self.source.is_starred:
self.set_icon(on='star_on.svg', off='star_on.svg')
Expand All @@ -1244,6 +1244,7 @@ def enable(self):
"""
Enable the widget.
"""
self.enable_api_call()
self.setCheckable(True)
self.set_icon(on='star_on.svg', off='star_off.svg')
self.setChecked(self.source.is_starred)
Expand Down Expand Up @@ -1271,7 +1272,8 @@ def eventFilter(self, obj, event):
if checkable:
self.set_icon(on='star_on.svg', off='star_off.svg')
else:
self.set_icon(on='star_on.svg', off='star_on.svg')
if self.source.is_starred:
self.set_icon(on='star_on.svg', off='star_on.svg')
return QObject.event(obj, event)

def on_authentication_changed(self, authenticated: bool):
Expand All @@ -1288,7 +1290,7 @@ def on_toggle(self):
"""
Tell the controller to make an API call to update the source's starred field.
"""
if self.toggle_event_enabled:
if self.is_api_call_enabled:
self.controller.update_star(self.source, self.on_update)

def on_toggle_offline(self):
Expand All @@ -1313,15 +1315,15 @@ def update(self):
Update the star to reflect its source's current state.
"""
self.controller.session.refresh(self.source)
self.disable_toggle_event()
self.disable_api_call()
self.setChecked(self.source.is_starred)
self.enable_toggle_event()
self.enable_api_call()

def disable_toggle_event(self):
self.toggle_event_enabled = False
def disable_api_call(self):
self.is_api_call_enabled = False

def enable_toggle_event(self):
self.toggle_event_enabled = True
def enable_api_call(self):
self.is_api_call_enabled = True


class DeleteSourceMessageBox:
Expand Down

0 comments on commit 8ab6101

Please sign in to comment.