From 5cce0a8ca9ae1fcca74feee322bc4de966a797e8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Bili=C5=84ski?= Date: Sat, 2 Aug 2008 17:29:32 +0000 Subject: [PATCH] Banner Tweaks plugin has all (four) options implemented. --- plugins/banner_tweaks/plugin.py | 89 ++++++++++++++++++++++---- plugins/length_notifier.py | 108 -------------------------------- 2 files changed, 76 insertions(+), 121 deletions(-) delete mode 100644 plugins/length_notifier.py diff --git a/plugins/banner_tweaks/plugin.py b/plugins/banner_tweaks/plugin.py index cecbbb38b..ee5cf2500 100644 --- a/plugins/banner_tweaks/plugin.py +++ b/plugins/banner_tweaks/plugin.py @@ -32,8 +32,11 @@ http://trac.gajim.org/attachment/ticket/4133/gajim-chatbanneroptions-svn10008.pa import sys import gtk +import gobject +import message_control from common import i18n from common import gajim +from common import helpers from plugins import GajimPlugin from plugins.helpers import log, log_calls @@ -83,23 +86,83 @@ http://trac.gajim.org/attachment/ticket/4133''' if not self.config['show_banner_image']: banner_status_img = chat_control.xml.get_widget('banner_status_image') banner_status_img.clear() + + # TODO: part below repeats a lot of code from ChatControl.draw_banner_text() + # This could be rewritten using re module: getting markup text from + # banner_name_label and replacing some elements based on plugin config. + # Would it be faster? + if self.config['show_banner_resource'] or self.config['banner_small_fonts']: + banner_name_label = chat_control.xml.get_widget('banner_name_label') + label_text = banner_name_label.get_label() + log.debug('label_text = "%s"'%(label_text)) + + contact = chat_control.contact + jid = contact.jid + + name = contact.get_shown_name() + if chat_control.resource: + name += '/' + chat_control.resource + elif contact.resource and self.config['show_banner_resource']: + name += '/' + contact.resource + + if chat_control.TYPE_ID == message_control.TYPE_PM: + name = _('%(nickname)s from group chat %(room_name)s') %\ + {'nickname': name, 'room_name': chat_control.room_name} + name = gobject.markup_escape_text(name) + + # We know our contacts nick, but if another contact has the same nick + # in another account we need to also display the account. + # except if we are talking to two different resources of the same contact + acct_info = '' + for account in gajim.contacts.get_accounts(): + if account == chat_control.account: + continue + if acct_info: # We already found a contact with same nick + break + for jid in gajim.contacts.get_jid_list(account): + other_contact_ = \ + gajim.contacts.get_first_contact_from_jid(account, jid) + if other_contact_.get_shown_name() == chat_control.contact.get_shown_name(): + acct_info = ' (%s)' % \ + gobject.markup_escape_text(chat_control.account) + break + + font_attrs, font_attrs_small = chat_control.get_font_attrs() + if self.config['banner_small_fonts']: + font_attrs = font_attrs_small + + st = gajim.config.get('displayed_chat_state_notifications') + cs = contact.chatstate + if cs and st in ('composing_only', 'all'): + if contact.show == 'offline': + chatstate = '' + elif contact.composing_xep == 'XEP-0085': + if st == 'all' or cs == 'composing': + chatstate = helpers.get_uf_chatstate(cs) + else: + chatstate = '' + elif contact.composing_xep == 'XEP-0022': + if cs in ('composing', 'paused'): + # only print composing, paused + chatstate = helpers.get_uf_chatstate(cs) + else: + chatstate = '' + else: + # When does that happen ? See [7797] and [7804] + chatstate = helpers.get_uf_chatstate(cs) + + label_text = '%s%s %s' % \ + (font_attrs, name, font_attrs_small, acct_info, chatstate) + else: + # weight="heavy" size="x-large" + label_text = '%s%s' % \ + (font_attrs, name, font_attrs_small, acct_info) + + banner_name_label.set_markup(label_text) def chat_control_base_draw_banner_deactivation(self, chat_control): pass #chat_control.draw_banner() - - #@log_calls('BannerTweaksPlugin') - #def connect_with_chat_control(self, chat_control): - #d = {} - #banner_status_img = chat_control.xml.get_widget('banner_status_image') - #h_id = banner_status_img.connect('state-changed', self.on_banner_status_img_state_changed, chat_control) - #d['banner_img_h_id'] = h_id - - #chat_control.banner_tweaks_plugin_data = d - - #@log_calls('BannerTweaksPlugin') - #def disconnect_from_chat_control(self, chat_control): - #pass class BannerTweaksPluginConfigDialog(GajimPluginConfigDialog): def init(self): diff --git a/plugins/length_notifier.py b/plugins/length_notifier.py deleted file mode 100644 index 7c14812e5..000000000 --- a/plugins/length_notifier.py +++ /dev/null @@ -1,108 +0,0 @@ -# -*- coding: utf-8 -*- - -## This file is part of Gajim. -## -## Gajim is free software; you can redistribute it and/or modify -## it under the terms of the GNU General Public License as published -## by the Free Software Foundation; version 3 only. -## -## Gajim is distributed in the hope that it will be useful, -## but WITHOUT ANY WARRANTY; without even the implied warranty of -## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -## GNU General Public License for more details. -## -## You should have received a copy of the GNU General Public License -## along with Gajim. If not, see . -## - -''' -Message length notifier plugin. - -:author: Mateusz Biliński -:since: 1st June 2008 -:copyright: Copyright (2008) Mateusz Biliński -:license: GPL -''' - -import sys - -import gtk - -from plugins import GajimPlugin -from plugins.helpers import log, log_calls - -class LengthNotifierPlugin(GajimPlugin): - name = u'Message Length Notifier' - short_name = u'length_notifier' - version = u'0.1' - description = u'''Highlights message entry field in chat window when given length of message is exceeded.''' - authors = [u'Mateusz Biliński '] - homepage = u'http://blog.bilinski.it' - - #@log_calls('LengthNotifierPlugin') - #def __init__(self): - #super(LengthNotifierPlugin, self).__init__() - - @log_calls('LengthNotifierPlugin') - def init(self): - #self.config_dialog = None - - self.gui_extension_points = { - 'chat_control' : (self.connect_with_chat_control, - self.disconnect_from_chat_control) - } - - self.MESSAGE_WARNING_LENGTH = 140 - self.WARNING_COLOR = gtk.gdk.color_parse('#F0DB3E') - self.JIDS = [] - - @log_calls('LengthNotifierPlugin') - def textview_length_warning(self, tb, chat_control): - tv = chat_control.msg_textview - d = chat_control.length_notifier_plugin_data - t = tb.get_text(tb.get_start_iter(), tb.get_end_iter()) - if t: - len_t = len(t) - #print("len_t: %d"%(len_t)) - if len_t>self.MESSAGE_WARNING_LENGTH: - if not d['prev_color']: - d['prev_color'] = tv.style.copy().base[gtk.STATE_NORMAL] - tv.modify_base(gtk.STATE_NORMAL, self.WARNING_COLOR) - elif d['prev_color']: - tv.modify_base(gtk.STATE_NORMAL, d['prev_color']) - d['prev_color'] = None - - @log_calls('LengthNotifierPlugin') - def connect_with_chat_control(self, chat_control): - jid = chat_control.contact.jid - if self.jid_is_ok(jid): - d = {'prev_color' : None} - tv = chat_control.msg_textview - tb = tv.get_buffer() - h_id = tb.connect('changed', self.textview_length_warning, chat_control) - d['h_id'] = h_id - - t = tb.get_text(tb.get_start_iter(), tb.get_end_iter()) - if t: - len_t = len(t) - if len_t>self.MESSAGE_WARNING_LENGTH: - d['prev_color'] = tv.style.copy().base[gtk.STATE_NORMAL] - tv.modify_base(gtk.STATE_NORMAL, self.WARNING_COLOR) - - chat_control.length_notifier_plugin_data = d - - return True - - return False - - @log_calls('LengthNotifierPlugin') - def disconnect_from_chat_control(self, chat_control): - d = chat_control.length_notifier_plugin_data - tv = chat_control.msg_textview - tv.get_buffer().disconnect(d['h_id']) - if d['prev_color']: - tv.modify_base(gtk.STATE_NORMAL, d['prev_color']) - - @log_calls('LengthNotifierPlugin') - def jid_is_ok(self, jid): - return True \ No newline at end of file