diff --git a/gajim/chat_control_base.py b/gajim/chat_control_base.py index b9c61385f..6816b3750 100644 --- a/gajim/chat_control_base.py +++ b/gajim/chat_control_base.py @@ -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( diff --git a/gajim/notify.py b/gajim/gtk/notification.py similarity index 93% rename from gajim/notify.py rename to gajim/gtk/notification.py index 78cf68be4..64bd6750e 100644 --- a/gajim/notify.py +++ b/gajim/gtk/notification.py @@ -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 diff --git a/gajim/gtk/util.py b/gajim/gtk/util.py index cc6cf599a..ef620a901 100644 --- a/gajim/gtk/util.py +++ b/gajim/gtk/util.py @@ -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') diff --git a/gajim/gui_interface.py b/gajim/gui_interface.py index 203467f5b..82398cfb3 100644 --- a/gajim/gui_interface.py +++ b/gajim/gui_interface.py @@ -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() diff --git a/gajim/session.py b/gajim/session.py index f52798f32..c83c7ed45 100644 --- a/gajim/session.py +++ b/gajim/session.py @@ -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, diff --git a/test/broken/integration/test_gui_event_integration.py b/test/broken/integration/test_gui_event_integration.py index 150f2102a..808e3fbf6 100644 --- a/test/broken/integration/test_gui_event_integration.py +++ b/test/broken/integration/test_gui_event_integration.py @@ -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''' diff --git a/test/lib/notify.py b/test/lib/notify.py index 2dd7e2628..a166a4737 100644 --- a/test/lib/notify.py +++ b/test/lib/notify.py @@ -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