Refactor set_unset_urgency_hint()

This commit is contained in:
Philipp Hörist 2018-11-20 22:59:02 +01:00
parent c97fddf0f8
commit 6327679461
4 changed files with 12 additions and 18 deletions

View File

@ -180,6 +180,11 @@ def get_builder(file_name: str, widgets: List[str] = None) -> Builder:
return Builder(file_name, widgets)
def set_urgency_hint(window: Any, setting: bool):
if app.config.get('use_urgency_hint'):
window.set_urgency_hint(setting)
def icon_exists(name: str) -> bool:
return _icon_theme.has_icon(name)

View File

@ -66,14 +66,6 @@ class Color:
ORANGE = Gdk.RGBA(red=245/255, green=121/255, blue=0/255, alpha=1)
def set_unset_urgency_hint(window, unread_messages_no):
"""
Sets/unset urgency hint in window argument depending if we have unread
messages or not
"""
if app.config.get('use_urgency_hint'):
window.props.urgency_hint = unread_messages_no > 0
def get_pixbuf_from_data(file_data):
"""
Get image data and returns GdkPixbuf.Pixbuf

View File

@ -46,6 +46,7 @@ from gajim.gtk.util import resize_window
from gajim.gtk.util import move_window
from gajim.gtk.util import get_app_icon_list
from gajim.gtk.util import get_builder
from gajim.gtk.util import set_urgency_hint
####################
@ -203,7 +204,7 @@ class MessageWindow:
# window received focus, so if we had urgency REMOVE IT
# NOTE: we do not have to read the message (it maybe in a bg tab)
# to remove urgency hint so this functions does that
gtkgui_helpers.set_unset_urgency_hint(self.window, False)
set_urgency_hint(self.window, False)
ctrl = self.get_active_control()
if ctrl:
@ -541,11 +542,7 @@ class MessageWindow:
title = title + ": " + control.account
self.window.set_title(unread_str + title)
if urgent:
gtkgui_helpers.set_unset_urgency_hint(self.window, unread)
else:
gtkgui_helpers.set_unset_urgency_hint(self.window, False)
set_urgency_hint(self.window, urgent and unread > 0)
def set_active_tab(self, ctrl):
ctrl_page = self.notebook.page_num(ctrl.widget)

View File

@ -85,6 +85,7 @@ from gajim.gtk.util import resize_window
from gajim.gtk.util import move_window
from gajim.gtk.util import get_metacontact_surface
from gajim.gtk.util import get_builder
from gajim.gtk.util import set_urgency_hint
log = logging.getLogger('gajim.roster')
@ -3688,7 +3689,7 @@ class RosterWindow:
# roster received focus, so if we had urgency REMOVE IT
# NOTE: we do not have to read the message to remove urgency
# so this functions does that
gtkgui_helpers.set_unset_urgency_hint(widget, False)
set_urgency_hint(widget, False)
# if a contact row is selected, update colors (eg. for status msg)
# because gtk engines may differ in bg when window is selected
@ -4626,7 +4627,7 @@ class RosterWindow:
if not app.interface.msg_win_mgr.one_window_opened():
# No MessageWindow to defer to
self.window.set_title('Gajim')
gtkgui_helpers.set_unset_urgency_hint(self.window, nb_unread)
set_urgency_hint(self.window, nb_unread > 0)
return
start = ''
@ -4636,8 +4637,7 @@ class RosterWindow:
start = '* '
self.window.set_title(start + 'Gajim')
gtkgui_helpers.set_unset_urgency_hint(self.window, nb_unread)
set_urgency_hint(self.window, nb_unread > 0)
def _nec_chatstate_received(self, event):
if event.contact.is_gc_contact or event.contact.is_pm_contact: