length_notifier/0000755000175500017550000000000013772360441013777 5ustar debacledebaclelength_notifier/config_dialog.py0000644000175500017550000000605713772360441017145 0ustar debacledebacle# -*- 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, either version 3 of the License, or # (at your option) any later version. # # 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 . from gi.repository import GObject from gi.repository import Gtk from gajim.gui.settings import SettingsDialog from gajim.gui.settings import SpinSetting from gajim.gui.const import Setting from gajim.gui.const import SettingKind from gajim.gui.const import SettingType from gajim.plugins.plugins_i18n import _ class LengthNotifierConfigDialog(SettingsDialog): def __init__(self, plugin, parent): self.plugin = plugin jids = self.plugin.config['JIDS'] or '' settings = [ Setting('MessageLengthSpinSetting', _('Message Length'), SettingType.VALUE, self.plugin.config['MESSAGE_WARNING_LENGTH'], callback=self._on_setting, data='MESSAGE_WARNING_LENGTH', desc=_('Message length at which the highlight is shown'), props={'range_': (1, 1000)}, ), Setting(SettingKind.COLOR, _('Color'), SettingType.VALUE, self.plugin.config['WARNING_COLOR'], callback=self._on_setting, data='WARNING_COLOR', desc=_('Highlight color for the message input'), ), Setting(SettingKind.ENTRY, _('Selected Addresses'), SettingType.VALUE, jids, callback=self._on_setting, data='JIDS', desc=_('Enable the plugin for selected XMPP addresses ' 'only (comma separated)'), ), ] SettingsDialog.__init__(self, parent, _('Length Notifier Configuration'), Gtk.DialogFlags.MODAL, settings, None, extend=[('MessageLengthSpinSetting', SizeSpinSetting)]) def _on_setting(self, value, data): if isinstance(value, str): value.strip() self.plugin.config[data] = value self.plugin.update() class SizeSpinSetting(SpinSetting): __gproperties__ = { "setting-value": (int, 'Size', '', 1, 1000, 140, GObject.ParamFlags.READWRITE), } def __init__(self, *args, **kwargs): SpinSetting.__init__(self, *args, **kwargs) length_notifier/length_notifier.py0000644000175500017550000001316413772360441017536 0ustar debacledebacle# -*- 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 logging from functools import partial from gi.repository import Gtk from nbxmpp.protocol import JID from gajim.common import app from gajim.plugins import GajimPlugin from gajim.plugins.plugins_i18n import _ from length_notifier.config_dialog import LengthNotifierConfigDialog log = logging.getLogger('gajim.p.length_notifier') class LengthNotifierPlugin(GajimPlugin): def init(self): self.description = _('Highlights the chat window’s message input if ' 'a specified message length is exceeded.') self.config_dialog = partial(LengthNotifierConfigDialog, self) self.gui_extension_points = { 'chat_control_base': ( self._connect_chat_control, self._disconnect_chat_control ) } self.config_default_values = { 'MESSAGE_WARNING_LENGTH': ( 140, 'Message length at which the highlight is shown'), 'WARNING_COLOR': ( 'rgb(240, 220, 60)', 'Highlight color for the message input'), 'JIDS': ( [], 'Enable the plugin for selected XMPP addresses ' 'only (comma separated)') } self._counters = {} def _connect_chat_control(self, chat_control): jid = chat_control.contact.jid if self._check_jid(jid): counter = Counter(chat_control, self.config) self._counters[chat_control.control_id] = counter actions_hbox = chat_control.xml.get_object('hbox') actions_hbox.pack_start(counter, False, False, 0) counter.show() def _disconnect_chat_control(self, chat_control): counter = self._counters.get(chat_control.control_id) if counter is not None: counter.reset() counter.destroy() self._counters.pop(chat_control.control_id, None) def _check_jid(self, jid): if not self.config['JIDS']: # Not restricted to any JIDs return True current_jid = JID(jid) allowed_jids = self.config['JIDS'].split(',') for allowed_jid in allowed_jids: try: address = JID(allowed_jid.strip()) except Exception as error: log.debug('Error parsing JID: %s (%s)' % (error, allowed_jid)) continue if address.isDomain: if current_jid.getDomain() == address: log.debug('Add counter for Domain %s' % address) return True if current_jid == address: log.debug('Add counter for JID %s' % address) return True def update(self): if not app.plugin_manager.get_active_plugin('length_notifier'): # Don’t update if the plugin is disabled return for control in app.interface.msg_win_mgr.get_controls(): self._disconnect_chat_control(control) self._connect_chat_control(control) class Counter(Gtk.Label): def __init__(self, chat_control, config): Gtk.Label.__init__(self) self._control = chat_control self._max_length = config['MESSAGE_WARNING_LENGTH'] self._color = config['WARNING_COLOR'] self.set_tooltip_text(_('Number of typed characters')) self.get_style_context().add_class('dim-label') self._textview = self._control.msg_textview self._textbuffer = self._textview.get_buffer() self._textbuffer.connect('changed', self._update) self._provider = None self._set_css() self._update() def _set_css(self): self._context = self._textview.get_style_context() if self._provider is not None: self._context.remove_provider(self._provider) css = ''' .length-warning > * { background-color: %s; } ''' % self._color self._provider = Gtk.CssProvider() self._provider.load_from_data(bytes(css.encode())) self._context.add_provider( self._provider, Gtk.STYLE_PROVIDER_PRIORITY_USER) def _set_count(self, count): self.set_label(str(count)) def _update(self, *args): if self._textview.has_text(): text = self._textbuffer.get_text( self._textbuffer.get_start_iter(), self._textbuffer.get_end_iter(), True) len_text = len(text) self._set_count(len_text) if len_text > self._max_length: self._context.add_class('length-warning') else: self._context.remove_class('length-warning') else: self._set_count('0') self._context.remove_class('length-warning') def reset(self): self._context.remove_class('length-warning') length_notifier/__init__.py0000644000175500017550000000006213772360441016106 0ustar debacledebaclefrom .length_notifier import LengthNotifierPlugin length_notifier/manifest.ini0000644000175500017550000000055013772360441016306 0ustar debacledebacle[info] name: Message Length Notifier short_name: length_notifier version: 1.3.2 description: Highlights the chat window’s message input if a specified message length is exceeded authors: Mateusz Biliński homepage: https://dev.gajim.org/gajim/gajim-plugins/wikis/LengthNotifierPlugin min_gajim_version: 1.2.91 max_gajim_version: 1.3.90 length_notifier/length_notifier.png0000644000175500017550000000066213772360441017671 0ustar debacledebaclePNG  IHDRatEXtSoftwareAdobe ImageReadyqe<TIDATxb,\(H8YIM^UK$ݷݳw&* ' \?!r N`_<%! if/Veb#÷?L _Bw02L7A}a] J KU}ŀ}tx]!!H"]?`d/# j1\p7=n>K_fcD2,&`x t0!ꅃ]!AQAG KL | /}5ӈ = , d,gff&%7(0$&IENDB`