Move notify to gtk folder

- Rename notify to notification
- Move get_show_in_roster() to gtk.util
- Move get_show_in_systray() to gtk.util
This commit is contained in:
Philipp Hörist 2018-11-18 19:08:45 +01:00
parent 2ece342de2
commit fedc00eb83
7 changed files with 46 additions and 55 deletions

View file

@ -43,7 +43,6 @@ from gajim.common.connection_handlers_events import MessageOutgoingEvent
from gajim.common.const import StyleAttr
from gajim.common.const import Chatstate
from gajim import notify
from gajim import gtkgui_helpers
from gajim import message_control
@ -55,6 +54,8 @@ from gajim.gtk.dialogs import NonModalConfirmationDialog
from gajim.gtk import util
from gajim.gtk.util import convert_rgb_to_hex
from gajim.gtk.util import at_the_end
from gajim.gtk.util import get_show_in_roster
from gajim.gtk.util import get_show_in_systray
from gajim.gtk.emoji_chooser import emoji_chooser
from gajim.command_system.implementation.middleware import ChatCommandProcessor
@ -940,10 +941,9 @@ class ChatControlBase(MessageControl, ChatCommandProcessor, CommandTools):
else:
event_type = events.PrintedPmEvent
event = 'message_received'
show_in_roster = notify.get_show_in_roster(event,
self.account, self.contact.jid, self.session)
show_in_systray = notify.get_show_in_systray(event,
self.account, self.contact.jid, event_type.type_)
show_in_roster = get_show_in_roster(event, self.session)
show_in_systray = get_show_in_systray(
event_type.type_, self.contact.jid)
event = event_type(text, subject, self, msg_log_id,
show_in_roster=show_in_roster,
@ -1221,7 +1221,7 @@ class ChatControlBase(MessageControl, ChatCommandProcessor, CommandTools):
"""
self.parent_win.redraw_tab(self)
self.parent_win.show_title()
# TODO : get the contact and check notify.get_show_in_roster()
# TODO : get the contact and check get_show_in_roster()
if self.type_id == message_control.TYPE_PM:
room_jid, nick = app.get_room_and_nick_from_fjid(jid)
groupchat_control = app.interface.msg_win_mgr.get_gc_control(

View file

@ -46,35 +46,6 @@ from gajim.gtk.util import load_icon
log = logging.getLogger('gajim.notify')
def get_show_in_roster(event, account, jid, session=None):
"""
Return True if this event must be shown in roster, else False
"""
if event == 'gc_message_received':
return True
if event == 'message_received':
if app.config.get('autopopup_chat_opened'):
return True
if session and session.control:
return False
return True
def get_show_in_systray(event, account, jid, type_=None):
"""
Return True if this event must be shown in systray, else False
"""
notify = app.config.get('notify_on_all_muc_messages')
notify_for_jid = app.config.get_per(
'rooms', jid, 'notify_on_all_messages')
if type_ == 'printed_gc_msg' and not notify and not notify_for_jid:
# it's not an highlighted message, don't show in systray
return False
return app.config.get('trayicon_notification_on_events')
class Notification:
"""
Handle notifications

View file

@ -356,3 +356,31 @@ def get_affiliation_surface(icon_name, affiliation, scale):
ctx.set_source_rgb(0, 255/255, 0)
ctx.fill()
return surface
def get_show_in_roster(event, session=None):
"""
Return True if this event must be shown in roster, else False
"""
if event == 'gc_message_received':
return True
if event == 'message_received':
if app.config.get('autopopup_chat_opened'):
return True
if session and session.control:
return False
return True
def get_show_in_systray(type_, jid):
"""
Return True if this event must be shown in systray, else False
"""
notify = app.config.get('notify_on_all_muc_messages')
notify_for_jid = app.config.get_per(
'rooms', jid, 'notify_on_all_messages')
if type_ == 'printed_gc_msg' and not notify and not notify_for_jid:
# it's not an highlighted message, don't show in systray
return False
return app.config.get('trayicon_notification_on_events')

View file

@ -64,7 +64,6 @@ from gajim.common.dbus import logind
from gajim import gtkgui_helpers
from gajim import gui_menu_builder
from gajim import dialogs
from gajim import notify
from gajim import message_control
from gajim.dialog_messages import get_dialog
from gajim.dialogs import ProgressWindow
@ -102,6 +101,7 @@ from gajim.common.caps_cache import muc_caps_cache
from gajim.common import configpaths
from gajim.common import optparser
from gajim.gtk.notification import Notification
from gajim.gtk.dialogs import ErrorDialog
from gajim.gtk.dialogs import WarningDialog
from gajim.gtk.dialogs import InformationDialog
@ -120,6 +120,8 @@ from gajim.gtk.emoji_data import emoji_ascii_data
from gajim.gtk.groupchat_config import GroupchatConfig
from gajim.gtk.atom import AtomWindow
from gajim.gtk.filetransfer import FileTransfersWindow
from gajim.gtk.util import get_show_in_roster
from gajim.gtk.util import get_show_in_systray
parser = optparser.OptionsParser(configpaths.get('CONFIG_FILE'))
@ -1581,8 +1583,8 @@ class Interface:
event_types = {'file-request': 'ft_request',
'file-completed': 'ft_finished'}
event_type = event_types.get(event.type_)
show_in_roster = notify.get_show_in_roster(event_type, account, jid)
show_in_systray = notify.get_show_in_systray(event_type, account, jid)
show_in_roster = get_show_in_roster(event_type, jid)
show_in_systray = get_show_in_systray(event_type, jid)
event.show_in_roster = show_in_roster
event.show_in_systray = show_in_systray
app.events.add_event(account, jid, event)
@ -2636,7 +2638,7 @@ class Interface:
# Creating Network Events Controller
from gajim.common import nec
app.nec = nec.NetworkEventsController()
app.notification = notify.Notification()
app.notification = Notification()
self.create_core_handlers_list()
self.register_core_handlers()

View file

@ -21,7 +21,6 @@ import string
import random
import itertools
from gajim import notify
from gajim.common import helpers
from gajim.common import events
from gajim.common import app
@ -29,6 +28,8 @@ from gajim.common import contacts
from gajim.common import ged
from gajim.common.const import KindConstant
from gajim.gtk.single_message import SingleMessageWindow
from gajim.gtk.util import get_show_in_roster
from gajim.gtk.util import get_show_in_systray
class ChatControlSession:
@ -246,10 +247,8 @@ class ChatControlSession:
do_event = False
else:
# Everything else
obj.show_in_roster = notify.get_show_in_roster(event_type,
self.conn.name, contact.jid, self)
obj.show_in_systray = notify.get_show_in_systray(event_type,
self.conn.name, contact.jid)
obj.show_in_roster = get_show_in_roster(event_type, self)
obj.show_in_systray = get_show_in_systray(event_type, contact.jid)
if obj.mtype == 'normal' and obj.popup:
do_event = False
else:
@ -354,10 +353,8 @@ class ChatControlSession:
event_t = events.NormalEvent
event_type = 'single_message_received'
show_in_roster = notify.get_show_in_roster(event_type, self.conn.name,
contact.jid, self)
show_in_systray = notify.get_show_in_systray(event_type, self.conn.name,
contact.jid)
show_in_roster = get_show_in_roster(event_type, self)
show_in_systray = get_show_in_systray(event_type, contact.jid)
event = event_t(msg, subject, msg_type, tim, encrypted, resource,
msg_log_id, xhtml=xhtml, session=self, form_node=form_node,

View file

@ -23,7 +23,6 @@ from data import *
from gajim import roster_window
from gajim import plugins
from gajim import notify
class TestStatusChange(unittest.TestCase):
'''tests gajim.py's incredibly complex presence handling'''

View file

@ -26,9 +26,3 @@ def notify(event, jid, account, parameters, advanced_notif_num = None):
def get_advanced_notification(event, account, contact):
return None
def get_show_in_roster(event, account, jid, session=None):
return True
def get_show_in_systray(event, account, jid, type_=None):
return True