Commit 4bed8ace authored by Philipp Hörist's avatar Philipp Hörist

Refactor Notifications

- Use icon names instead of path
- Move PopupNotificationWindow into notify.py
- Make popup class method instead of module method
- Dont use sessions to get control on notification action Fixes #9140
- Add has_focus() method to ChatControlBase
parent 2abbb1e2
......@@ -1268,6 +1268,13 @@ class ChatControlBase(MessageControl, ChatCommandProcessor, CommandTools):
app.log('autoscroll').info('Autoscroll disabled')
self.conv_textview.autoscroll = False
def has_focus(self):
if self.parent_win:
if self.parent_win.window.get_property('has-toplevel-focus'):
if self == self.parent_win.get_active_control():
return True
return False
def _on_scroll(self, widget, event):
if not self.conv_textview.autoscroll:
# autoscroll is already disabled
......
This diff is collapsed.
......@@ -3060,131 +3060,6 @@ class ChangePasswordDialog:
dialog.destroy()
self.on_response(password1)
class PopupNotificationWindow:
def __init__(self, event_type, jid, account, msg_type='',
path_to_image=None, title=None, text=None, timeout=-1):
self.account = account
self.jid = jid
self.msg_type = msg_type
self.index = len(app.interface.roster.popup_notification_windows)
xml = gtkgui_helpers.get_gtk_builder('popup_notification_window.ui')
self.window = xml.get_object('popup_notification_window')
self.window.set_type_hint(Gdk.WindowTypeHint.TOOLTIP)
self.window.set_name('NotificationPopup')
close_button = xml.get_object('close_button')
event_type_label = xml.get_object('event_type_label')
event_description_label = xml.get_object('event_description_label')
eventbox = xml.get_object('eventbox')
image = xml.get_object('notification_image')
if not text:
text = app.get_name_from_jid(account, jid) # default value of text
if not title:
title = ''
event_type_label.set_markup(
'<span foreground="black" weight="bold">%s</span>' %
GLib.markup_escape_text(title))
css = '#NotificationPopup {background-color: black }'
gtkgui_helpers.add_css_to_widget(self.window, css)
# default image
if not path_to_image:
path_to_image = gtkgui_helpers.get_icon_path('gajim-chat_msg_recv', 48)
if event_type == _('Contact Signed In'):
bg_color = app.config.get('notif_signin_color')
elif event_type == _('Contact Signed Out'):
bg_color = app.config.get('notif_signout_color')
elif event_type in (_('New Message'), _('New Single Message'),
_('New Private Message'), _('New E-mail')):
bg_color = app.config.get('notif_message_color')
elif event_type == _('File Transfer Request'):
bg_color = app.config.get('notif_ftrequest_color')
elif event_type == _('File Transfer Error'):
bg_color = app.config.get('notif_fterror_color')
elif event_type in (_('File Transfer Completed'),
_('File Transfer Stopped')):
bg_color = app.config.get('notif_ftcomplete_color')
elif event_type == _('Groupchat Invitation'):
bg_color = app.config.get('notif_invite_color')
elif event_type == _('Contact Changed Status'):
bg_color = app.config.get('notif_status_color')
else: # Unknown event! Shouldn't happen but deal with it
bg_color = app.config.get('notif_other_color')
background_class = '''
.popup-style {
border-image: none;
background-image: none;
background-color: %s }''' % bg_color
gtkgui_helpers.add_css_to_widget(eventbox, background_class)
eventbox.get_style_context().add_class('popup-style')
gtkgui_helpers.add_css_to_widget(close_button, background_class)
eventbox.get_style_context().add_class('popup-style')
event_description_label.set_markup('<span foreground="black">%s</span>' %
GLib.markup_escape_text(text))
# set the image
image.set_from_file(path_to_image)
# position the window to bottom-right of screen
window_width, self.window_height = self.window.get_size()
app.interface.roster.popups_notification_height += self.window_height
pos_x = app.config.get('notification_position_x')
screen_w, screen_h = gtkgui_helpers.get_total_screen_geometry()
if pos_x < 0:
pos_x = screen_w - window_width + pos_x + 1
pos_y = app.config.get('notification_position_y')
if pos_y < 0:
pos_y = screen_h - \
app.interface.roster.popups_notification_height + pos_y + 1
self.window.move(pos_x, pos_y)
xml.connect_signals(self)
self.window.show_all()
if timeout > 0:
GLib.timeout_add_seconds(timeout, self.on_timeout)
def on_close_button_clicked(self, widget):
self.adjust_height_and_move_popup_notification_windows()
def on_timeout(self):
self.adjust_height_and_move_popup_notification_windows()
def adjust_height_and_move_popup_notification_windows(self):
#remove
app.interface.roster.popups_notification_height -= self.window_height
self.window.destroy()
if len(app.interface.roster.popup_notification_windows) > self.index:
# we want to remove the destroyed window from the list
app.interface.roster.popup_notification_windows.pop(self.index)
# move the rest of popup windows
app.interface.roster.popups_notification_height = 0
current_index = 0
for window_instance in app.interface.roster.popup_notification_windows:
window_instance.index = current_index
current_index += 1
window_width, window_height = window_instance.window.get_size()
app.interface.roster.popups_notification_height += window_height
screen_w, screen_h = gtkgui_helpers.get_total_screen_geometry()
window_instance.window.move(screen_w - window_width,
screen_h - \
app.interface.roster.popups_notification_height)
def on_popup_notification_window_button_press_event(self, widget, event):
if event.button != 1:
self.window.destroy()
return
app.interface.handle_event(self.account, self.jid, self.msg_type)
self.adjust_height_and_move_popup_notification_windows()
class SingleMessageWindow:
"""
SingleMessageWindow can send or show a received singled message depending on
......
......@@ -920,3 +920,11 @@ def pango_to_css_weight(number):
if number > 900:
return 900
return int(math.ceil(number / 100.0)) * 100
def get_monitor_scale_factor():
display = Gdk.Display.get_default()
monitor = display.get_primary_monitor()
if monitor is None:
log.warning('Could not determine scale factor')
return 1
return monitor.get_scale_factor()
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment