Philipp Hörist pushed to branch master at gajim / gajim
Commits: 4b3a5b77 by Philipp Hörist at 2019-03-12T17:44:20Z Use Consistent Color Generation for MUC nicknames
- - - - -
4 changed files:
- gajim/command_system/implementation/standard.py - gajim/common/config.py - gajim/conversation_textview.py - gajim/groupchat_control.py
Changes:
===================================== gajim/command_system/implementation/standard.py ===================================== @@ -250,8 +250,6 @@ class StandardGroupChatCommands(CommandContainer): @doc(_("Clear the text window")) def clear(self): self.conv_textview.clear() - self.gc_count_nicknames_colors = -1 - self.gc_custom_colors = {}
@command(raw=True) @doc(_("Change your nickname in a group chat"))
===================================== gajim/common/config.py ===================================== @@ -253,7 +253,6 @@ class Config: 'hide_groupchat_occupants_list': [opt_bool, False, _('Hides the group chat occupants list in group chat window.')], 'chat_merge_consecutive_nickname': [opt_bool, False, _('In a chat, show the nickname at the beginning of a line only when it's not the same person talking than in previous message.')], 'chat_merge_consecutive_nickname_indent': [opt_str, ' ', _('Indentation when using merge consecutive nickname.')], - 'gc_nicknames_colors': [opt_str, '#4e9a06:#f57900:#ce5c00:#3465a4:#204a87:#75507b:#5c3566:#c17d11:#8f5902:#ef2929:#cc0000:#a40000', _('List of colors, separated by ":", that will be used to color nicknames in group chats.'), True], 'ctrl_tab_go_to_next_composing': [opt_bool, True, _('Ctrl-Tab go to next composing tab when none is unread.')], 'confirm_metacontacts': [opt_str, '', _('Show the confirm metacontacts creation dialog or not? Empty string means never show the dialog.')], 'confirm_block': [opt_str, '', _('Show the confirm block contact dialog or not? Empty string means never show the dialog.')],
===================================== gajim/conversation_textview.py ===================================== @@ -34,6 +34,9 @@ from gi.repository import Gtk from gi.repository import Pango from gi.repository import GObject from gi.repository import GLib +from gi.repository import Gdk + +from nbxmpp.util import text_to_colour
from gajim.common import app from gajim.common import helpers @@ -43,14 +46,13 @@ from gajim.common.helpers import AdditionalDataDict from gajim.common.fuzzyclock import FuzzyClock from gajim.common.const import StyleAttr
-from gajim.gtk.htmltextview import HtmlTextView - from gajim.gtk import util from gajim.gtk.util import load_icon from gajim.gtk.util import get_cursor from gajim.gtk.emoji_data import emoji_pixbufs from gajim.gtk.emoji_data import is_emoji from gajim.gtk.emoji_data import get_emoji_pixbuf +from gajim.gtk.htmltextview import HtmlTextView
NOT_SHOWN = 0 ALREADY_RECEIVED = 1 @@ -247,13 +249,6 @@ class ConversationTextview(GObject.GObject): desc = app.css_config.get_font('.gajim-outgoing-message-text') self.tagOutText.set_property('font-desc', desc)
- colors = app.config.get('gc_nicknames_colors') - colors = colors.split(':') - for i, color in enumerate(colors): - tagname = 'gc_nickname_color_' + str(i) - tag = buffer_.create_tag(tagname) - tag.set_property('foreground', color) - self.tagMarked = buffer_.create_tag('marked') color = app.css_config.get_value( '.gajim-highlight-message', StyleAttr.COLOR) @@ -1223,6 +1218,11 @@ class ConversationTextview(GObject.GObject): if other_tags_for_name: name_tags = other_tags_for_name[:] # create a new list name_tags.append(kind) + + for tag in name_tags: + if tag.startswith('muc_nickname_color_'): + self._add_new_colour_tags(tag, name) + before_str = app.config.get('before_nickname') before_str = helpers.from_one_line(before_str) after_str = app.config.get('after_nickname') @@ -1230,6 +1230,12 @@ class ConversationTextview(GObject.GObject): format_ = before_str + name + direction_mark + after_str + ' ' buffer_.insert_with_tags_by_name(end_iter, format_, *name_tags)
+ def _add_new_colour_tags(self, tag, name): + if self._buffer.get_tag_table().lookup(tag) is not None: + return + gdk_color = Gdk.Color.from_floats(*text_to_colour(name)) + self._buffer.create_tag(tag, foreground_gdk=gdk_color) + def print_subject(self, subject, iter_=None): if subject: # if we have subject, show it too! subject = _('Subject: %s\n') % subject
===================================== gajim/groupchat_control.py ===================================== @@ -193,12 +193,6 @@ class GroupchatControl(ChatControlBase):
self.subject = ''
- # nickname coloring - self.gc_count_nicknames_colors = -1 - self.gc_custom_colors = {} - self.number_of_colors = len(app.config.get('gc_nicknames_colors').\ - split(':')) - self.name_label = self.xml.get_object('banner_name_label') self.event_box = self.xml.get_object('banner_eventbox')
@@ -1347,17 +1341,7 @@ class GroupchatControl(ChatControlBase): if kind == 'incoming': # it's a message NOT from us # highlighting and sounds highlight, _sound = self.highlighting_for_message(text, tim) - if contact in self.gc_custom_colors: - other_tags_for_name.append('gc_nickname_color_' + \ - str(self.gc_custom_colors[contact])) - else: - self.gc_count_nicknames_colors += 1 - if self.gc_count_nicknames_colors == self.number_of_colors: - self.gc_count_nicknames_colors = 0 - self.gc_custom_colors[contact] = \ - self.gc_count_nicknames_colors - other_tags_for_name.append('gc_nickname_color_' + \ - str(self.gc_count_nicknames_colors)) + other_tags_for_name.append('muc_nickname_color_%s' % contact) if highlight: # muc-specific chatstate if self.parent_win: @@ -1369,10 +1353,6 @@ class GroupchatControl(ChatControlBase):
self._nick_completion.record_message(contact, highlight)
- if text.startswith('/me ') or text.startswith('/me\n'): - other_tags_for_text.append('gc_nickname_color_' + \ - str(self.gc_custom_colors[contact])) - self.check_and_possibly_add_focus_out_line()
ChatControlBase.print_conversation_line(self, text, kind, contact, tim, @@ -1858,10 +1838,6 @@ class GroupchatControl(ChatControlBase): tv.last_received_message_id[nick] del tv.last_received_message_id[nick]
- # keep nickname color - if nick in self.gc_custom_colors: - self.gc_custom_colors[new_nick] = self.gc_custom_colors[nick] - self.remove_contact(nick) self.add_contact_to_roster(new_nick)
View it on GitLab: https://dev.gajim.org/gajim/gajim/commit/4b3a5b7704dbf51afa2d0d71b8c4a53e504...