2008-06-02 01:33:51 +02:00
|
|
|
# -*- 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 <http://www.gnu.org/licenses/>.
|
|
|
|
##
|
|
|
|
|
|
|
|
'''
|
|
|
|
Message length notifier plugin.
|
|
|
|
|
|
|
|
:author: Mateusz Biliński <mateusz@bilinski.it>
|
2008-06-18 22:45:22 +02:00
|
|
|
:since: 1st June 2008
|
2008-06-02 01:33:51 +02:00
|
|
|
:copyright: Copyright (2008) Mateusz Biliński <mateusz@bilinski.it>
|
|
|
|
:license: GPL
|
|
|
|
'''
|
|
|
|
|
|
|
|
import sys
|
|
|
|
|
|
|
|
import gtk
|
|
|
|
|
|
|
|
from plugins import GajimPlugin
|
|
|
|
from plugins.helpers import log, log_calls
|
|
|
|
|
|
|
|
class LengthNotifierPlugin(GajimPlugin):
|
2008-06-07 19:28:34 +02:00
|
|
|
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 <mateusz@bilinski.it>']
|
|
|
|
homepage = u'http://blog.bilinski.it'
|
2008-06-02 01:33:51 +02:00
|
|
|
|
2008-06-18 22:45:22 +02:00
|
|
|
#@log_calls('LengthNotifierPlugin')
|
|
|
|
#def __init__(self):
|
|
|
|
#super(LengthNotifierPlugin, self).__init__()
|
|
|
|
|
2008-06-02 01:33:51 +02:00
|
|
|
@log_calls('LengthNotifierPlugin')
|
2008-06-18 22:45:22 +02:00
|
|
|
def init(self):
|
2008-06-19 14:56:45 +02:00
|
|
|
#self.config_dialog = None
|
|
|
|
|
2008-06-12 20:26:08 +02:00
|
|
|
self.gui_extension_points = {
|
2008-06-02 01:33:51 +02:00
|
|
|
'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
|
2008-06-03 15:40:27 +02:00
|
|
|
tb = tv.get_buffer()
|
|
|
|
h_id = tb.connect('changed', self.textview_length_warning, chat_control)
|
2008-06-02 01:33:51 +02:00
|
|
|
d['h_id'] = h_id
|
2008-06-03 15:40:27 +02:00
|
|
|
|
|
|
|
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)
|
|
|
|
|
2008-06-02 01:33:51 +02:00
|
|
|
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
|
2008-06-03 15:40:27 +02:00
|
|
|
tv = chat_control.msg_textview
|
|
|
|
tv.get_buffer().disconnect(d['h_id'])
|
2008-06-02 01:33:51 +02:00
|
|
|
if d['prev_color']:
|
2008-06-03 15:40:27 +02:00
|
|
|
tv.modify_base(gtk.STATE_NORMAL, d['prev_color'])
|
2008-06-02 01:33:51 +02:00
|
|
|
|
|
|
|
@log_calls('LengthNotifierPlugin')
|
|
|
|
def jid_is_ok(self, jid):
|
|
|
|
return True
|