Commit e6d9790d authored by Daniel Brötzmann's avatar Daniel Brötzmann
Browse files

[length_notifier] Fix character counter

Setting the character count to 0 will disable color notification.
Removes setting for counter toggle.
parent 25f4da6e
...@@ -4,6 +4,9 @@ ...@@ -4,6 +4,9 @@
<requires lib="gtk+" version="3.20"/> <requires lib="gtk+" version="3.20"/>
<object class="GtkWindow"> <object class="GtkWindow">
<property name="can_focus">False</property> <property name="can_focus">False</property>
<child>
<placeholder/>
</child>
<child> <child>
<object class="GtkGrid" id="length_notifier_config_table"> <object class="GtkGrid" id="length_notifier_config_table">
<property name="visible">True</property> <property name="visible">True</property>
...@@ -32,7 +35,7 @@ ...@@ -32,7 +35,7 @@
<object class="GtkSpinButton" id="message_length_spinbutton"> <object class="GtkSpinButton" id="message_length_spinbutton">
<property name="visible">True</property> <property name="visible">True</property>
<property name="can_focus">True</property> <property name="can_focus">True</property>
<property name="tooltip_text" translatable="yes">Message length for the notification to be shown</property> <property name="tooltip_text" translatable="yes">Message length for the notification to be shown (set to 0 to disable color notification)</property>
<property name="halign">start</property> <property name="halign">start</property>
<property name="width_chars">6</property> <property name="width_chars">6</property>
<property name="input_purpose">number</property> <property name="input_purpose">number</property>
...@@ -50,27 +53,28 @@ ...@@ -50,27 +53,28 @@
<property name="visible">True</property> <property name="visible">True</property>
<property name="can_focus">False</property> <property name="can_focus">False</property>
<property name="halign">end</property> <property name="halign">end</property>
<property name="label" translatable="yes">XMPP Addresses</property> <property name="label" translatable="yes">Notification Color</property>
<style> <style>
<class name="dim-label"/> <class name="dim-label"/>
</style> </style>
</object> </object>
<packing> <packing>
<property name="left_attach">0</property> <property name="left_attach">0</property>
<property name="top_attach">3</property> <property name="top_attach">1</property>
</packing> </packing>
</child> </child>
<child> <child>
<object class="GtkEntry" id="jids_entry"> <object class="GtkColorButton" id="notification_colorbutton">
<property name="visible">True</property> <property name="visible">True</property>
<property name="can_focus">True</property> <property name="can_focus">True</property>
<property name="tooltip_text" translatable="yes">Restrict this plugin to certain contacts, e.g. to one microblogging bot (use comma without space as separator)</property> <property name="receives_default">True</property>
<property name="tooltip_text" translatable="yes">Background color of the message input when the specified message length is reached</property>
<property name="halign">start</property> <property name="halign">start</property>
<property name="placeholder_text" translatable="yes">user@example.org</property> <property name="title" translatable="yes">Pick a color for notification</property>
</object> </object>
<packing> <packing>
<property name="left_attach">1</property> <property name="left_attach">1</property>
<property name="top_attach">3</property> <property name="top_attach">1</property>
</packing> </packing>
</child> </child>
<child> <child>
...@@ -78,7 +82,7 @@ ...@@ -78,7 +82,7 @@
<property name="visible">True</property> <property name="visible">True</property>
<property name="can_focus">False</property> <property name="can_focus">False</property>
<property name="halign">end</property> <property name="halign">end</property>
<property name="label" translatable="yes">Notification Color</property> <property name="label" translatable="yes">XMPP Addresses</property>
<style> <style>
<class name="dim-label"/> <class name="dim-label"/>
</style> </style>
...@@ -89,38 +93,18 @@ ...@@ -89,38 +93,18 @@
</packing> </packing>
</child> </child>
<child> <child>
<object class="GtkColorButton" id="notification_colorbutton"> <object class="GtkEntry" id="jids_entry">
<property name="visible">True</property> <property name="visible">True</property>
<property name="can_focus">True</property> <property name="can_focus">True</property>
<property name="receives_default">True</property> <property name="tooltip_text" translatable="yes">Restrict this plugin to certain contacts, e.g. to one microblogging bot (use comma without space as separator)</property>
<property name="tooltip_text" translatable="yes">Background color of the message input when the specified message length is reached</property>
<property name="halign">start</property> <property name="halign">start</property>
<property name="title" translatable="yes">Pick a color for notification</property> <property name="placeholder_text" translatable="yes">user@example.org</property>
</object> </object>
<packing> <packing>
<property name="left_attach">1</property> <property name="left_attach">1</property>
<property name="top_attach">2</property> <property name="top_attach">2</property>
</packing> </packing>
</child> </child>
<child>
<object class="GtkCheckButton" id="char_counter">
<property name="label" translatable="yes">Show Character Count</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">False</property>
<property name="tooltip_text" translatable="yes">Adds a character counter to the message input</property>
<property name="halign">start</property>
<property name="draw_indicator">True</property>
<signal name="toggled" handler="_on_char_counter_toggled" swapped="no"/>
</object>
<packing>
<property name="left_attach">1</property>
<property name="top_attach">1</property>
</packing>
</child>
<child>
<placeholder/>
</child>
</object> </object>
</child> </child>
</object> </object>
......
...@@ -48,7 +48,6 @@ class LengthNotifierPlugin(GajimPlugin): ...@@ -48,7 +48,6 @@ class LengthNotifierPlugin(GajimPlugin):
self.config_default_values = { self.config_default_values = {
'MESSAGE_WARNING_LENGTH' : (140, 'Message length at which notification is invoked.'), 'MESSAGE_WARNING_LENGTH' : (140, 'Message length at which notification is invoked.'),
'CHAR_COUNTER': (True, 'Show character count'),
'WARNING_COLOR' : ('#F0DB3E', 'Background color of text entry field in chat window when notification is invoked.'), 'WARNING_COLOR' : ('#F0DB3E', 'Background color of text entry field in chat window when notification is invoked.'),
'JIDS' : ([], 'JabberIDs that plugin should be used with (eg. restrict only to one microblogging bot). If empty plugin is used with every JID. [not implemented]') 'JIDS' : ([], 'JabberIDs that plugin should be used with (eg. restrict only to one microblogging bot). If empty plugin is used with every JID. [not implemented]')
} }
...@@ -57,13 +56,15 @@ class LengthNotifierPlugin(GajimPlugin): ...@@ -57,13 +56,15 @@ class LengthNotifierPlugin(GajimPlugin):
def textview_length_warning(self, tb, chat_control): def textview_length_warning(self, tb, chat_control):
tv = chat_control.msg_textview tv = chat_control.msg_textview
d = chat_control.length_notifier_plugin_data d = chat_control.length_notifier_plugin_data
counter = d['counter']
if not tv.has_text(): if not tv.has_text():
self.counter.set_text('0') counter.set_text('0')
if tv.has_text(): if tv.has_text():
t = tb.get_text(tb.get_start_iter(), tb.get_end_iter(), True) t = tb.get_text(tb.get_start_iter(), tb.get_end_iter(), True)
len_t = len(t) len_t = len(t)
self.counter.set_text(str(len_t)) counter.set_text(str(len_t))
if len_t > self.config['MESSAGE_WARNING_LENGTH']: warning_length = self.config['MESSAGE_WARNING_LENGTH']
if len_t > warning_length and warning_length != 0:
if not d['prev_color']: if not d['prev_color']:
#FIXME: That doesn't work #FIXME: That doesn't work
context = tv.get_style_context() context = tv.get_style_context()
...@@ -84,19 +85,27 @@ class LengthNotifierPlugin(GajimPlugin): ...@@ -84,19 +85,27 @@ class LengthNotifierPlugin(GajimPlugin):
def connect_with_chat_control(self, chat_control): def connect_with_chat_control(self, chat_control):
jid = chat_control.contact.jid jid = chat_control.contact.jid
if self.jid_is_ok(jid): if self.jid_is_ok(jid):
self._create_counter(chat_control) actions_hbox = chat_control.xml.get_object('hbox')
counter = Gtk.Label()
counter.set_tooltip_text(_('Number of typed characters'))
counter.get_style_context().add_class('dim-label')
counter.show()
actions_hbox.pack_start(counter, False, False, 0)
d = {'prev_color' : None} d = {'prev_color' : None}
tv = chat_control.msg_textview tv = chat_control.msg_textview
tb = tv.get_buffer() tb = tv.get_buffer()
h_id = tb.connect('changed', self.textview_length_warning, h_id = tb.connect('changed', self.textview_length_warning,
chat_control) chat_control)
d['h_id'] = h_id d['h_id'] = h_id
d['counter'] = counter
if tv.has_text(): if tv.has_text():
t = tb.get_text(tb.get_start_iter(), tb.get_end_iter(), True) t = tb.get_text(tb.get_start_iter(), tb.get_end_iter(), True)
len_t = len(t) len_t = len(t)
self.counter.set_text(str(len_t)) counter.set_text(str(len_t))
if len_t > self.config['MESSAGE_WARNING_LENGTH']: warning_length = self.config['MESSAGE_WARNING_LENGTH']
if len_t > warning_length and warning_length != 0:
context = tv.get_style_context() context = tv.get_style_context()
d['prev_color'] = context.get_background_color( d['prev_color'] = context.get_background_color(
Gtk.StateFlags.NORMAL) Gtk.StateFlags.NORMAL)
...@@ -104,7 +113,7 @@ class LengthNotifierPlugin(GajimPlugin): ...@@ -104,7 +113,7 @@ class LengthNotifierPlugin(GajimPlugin):
Gdk.RGBA.parse(color, self.config['WARNING_COLOR']) Gdk.RGBA.parse(color, self.config['WARNING_COLOR'])
tv.override_background_color(Gtk.StateType.NORMAL, color) tv.override_background_color(Gtk.StateType.NORMAL, color)
else: else:
self.counter.set_text('0') counter.set_text('0')
chat_control.length_notifier_plugin_data = d chat_control.length_notifier_plugin_data = d
return True return True
...@@ -114,17 +123,17 @@ class LengthNotifierPlugin(GajimPlugin): ...@@ -114,17 +123,17 @@ class LengthNotifierPlugin(GajimPlugin):
@log_calls('LengthNotifierPlugin') @log_calls('LengthNotifierPlugin')
def disconnect_from_chat_control(self, chat_control): def disconnect_from_chat_control(self, chat_control):
try: try:
actions_hbox = chat_control.xml.get_object('hbox')
actions_hbox.remove(self.counter)
d = chat_control.length_notifier_plugin_data d = chat_control.length_notifier_plugin_data
actions_hbox = chat_control.xml.get_object('hbox')
actions_hbox.remove(d['counter'])
tv = chat_control.msg_textview tv = chat_control.msg_textview
tv.get_buffer().disconnect(d['h_id']) tv.get_buffer().disconnect(d['h_id'])
if d['prev_color']: if d['prev_color']:
tv.override_background_color(Gtk.StateType.NORMAL, tv.override_background_color(Gtk.StateType.NORMAL,
d['prev_color']) d['prev_color'])
except AttributeError as error: except AttributeError:
pass pass
#log.debug('Length Notifier Plugin was (probably) never connected with this chat window.\n Error: %s' % (error))
@log_calls('LengthNotifierPlugin') @log_calls('LengthNotifierPlugin')
def jid_is_ok(self, jid): def jid_is_ok(self, jid):
...@@ -133,21 +142,6 @@ class LengthNotifierPlugin(GajimPlugin): ...@@ -133,21 +142,6 @@ class LengthNotifierPlugin(GajimPlugin):
return False return False
def _create_counter(self, chat_control):
actions_hbox = chat_control.xml.get_object('hbox')
self.counter = Gtk.Label()
self.counter.set_tooltip_text(_('Number of typed characters'))
self.counter.get_style_context().add_class('dim-label')
self.counter.set_no_show_all(True)
actions_hbox.pack_start(self.counter, False, False, 0)
self.toggle_counter()
def toggle_counter(self):
if self.config['CHAR_COUNTER']:
self.counter.show()
else:
self.counter.hide()
class LengthNotifierPluginConfigDialog(GajimPluginConfigDialog): class LengthNotifierPluginConfigDialog(GajimPluginConfigDialog):
def init(self): def init(self):
...@@ -164,7 +158,6 @@ class LengthNotifierPluginConfigDialog(GajimPluginConfigDialog): ...@@ -164,7 +158,6 @@ class LengthNotifierPluginConfigDialog(GajimPluginConfigDialog):
'message_length_spinbutton') 'message_length_spinbutton')
self.message_length_spinbutton.get_adjustment().configure(140, 0, 500, self.message_length_spinbutton.get_adjustment().configure(140, 0, 500,
1, 10, 0) 1, 10, 0)
self.char_counter = self.xml.get_object('char_counter')
self.notification_colorbutton = self.xml.get_object( self.notification_colorbutton = self.xml.get_object(
'notification_colorbutton') 'notification_colorbutton')
self.jids_entry = self.xml.get_object('jids_entry') self.jids_entry = self.xml.get_object('jids_entry')
...@@ -175,7 +168,6 @@ class LengthNotifierPluginConfigDialog(GajimPluginConfigDialog): ...@@ -175,7 +168,6 @@ class LengthNotifierPluginConfigDialog(GajimPluginConfigDialog):
self.message_length_spinbutton.set_value(self.plugin.config[ self.message_length_spinbutton.set_value(self.plugin.config[
'MESSAGE_WARNING_LENGTH']) 'MESSAGE_WARNING_LENGTH'])
color = Gdk.Color.parse(self.plugin.config['WARNING_COLOR'])[1] color = Gdk.Color.parse(self.plugin.config['WARNING_COLOR'])[1]
self.char_counter.set_active(self.plugin.config['CHAR_COUNTER'])
self.notification_colorbutton.set_color(color) self.notification_colorbutton.set_color(color)
#self.jids_entry.set_text(self.plugin.config['JIDS']) #self.jids_entry.set_text(self.plugin.config['JIDS'])
self.jids_entry.set_text(','.join(self.plugin.config['JIDS'])) self.jids_entry.set_text(','.join(self.plugin.config['JIDS']))
...@@ -184,10 +176,6 @@ class LengthNotifierPluginConfigDialog(GajimPluginConfigDialog): ...@@ -184,10 +176,6 @@ class LengthNotifierPluginConfigDialog(GajimPluginConfigDialog):
def on_message_length_spinbutton_value_changed(self, spinbutton): def on_message_length_spinbutton_value_changed(self, spinbutton):
self.plugin.config['MESSAGE_WARNING_LENGTH'] = spinbutton.get_value() self.plugin.config['MESSAGE_WARNING_LENGTH'] = spinbutton.get_value()
def _on_char_counter_toggled(self, checkbutton):
self.plugin.config['CHAR_COUNTER'] = checkbutton.get_active()
self.plugin.toggle_counter()
@log_calls('LengthNotifierPluginConfigDialog') @log_calls('LengthNotifierPluginConfigDialog')
def on_notification_colorbutton_color_set(self, colorbutton): def on_notification_colorbutton_color_set(self, colorbutton):
self.plugin.config['WARNING_COLOR'] = colorbutton.get_color().\ self.plugin.config['WARNING_COLOR'] = colorbutton.get_color().\
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment