Welcome to mirror list, hosted at ThFree Co, Russian Federation.

dev.gajim.org/gajim/gajim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMateusz Biliński <mateusz.bilinski@gmail.com>2008-07-29 23:09:28 +0400
committerMateusz Biliński <mateusz.bilinski@gmail.com>2008-07-29 23:09:28 +0400
commit8aa9cad2e098bb55e805bbb59ab129e16857eb07 (patch)
treed9412dc65c61e21ce9011964c3d7356c448e83fd /plugins
parentd8075a23e61ed802cd4d9a0b0335c5eb1ddfdf49 (diff)
Plugin's configuration is now saved to disk (currently: using UserDict and shelve modules).
Length Notifier Plugin has configuration dialog (added entry with JIDs to be included when plugin is working) - fully usable. Default values of configuration key has been added to GajimPlugin. Some other minor changes/fixes.
Diffstat (limited to 'plugins')
-rw-r--r--plugins/acronyms_expander.py36
-rw-r--r--plugins/length_notifier/__init__.py2
-rw-r--r--plugins/length_notifier/config_dialog.glade152
-rw-r--r--plugins/length_notifier/length_notifier.py157
4 files changed, 330 insertions, 17 deletions
diff --git a/plugins/acronyms_expander.py b/plugins/acronyms_expander.py
index dda47cf17..a575fe555 100644
--- a/plugins/acronyms_expander.py
+++ b/plugins/acronyms_expander.py
@@ -51,32 +51,35 @@ class AcronymsExpanderPlugin(GajimPlugin):
self.disconnect_from_chat_control_base)
}
- self.INVOKER = ' '
- self.ACRONYMS = {'RTFM' : 'Read The Friendly Manual',
- '/slap' : '/me slaps',
- 'PS-' : 'plug-in system',
- 'G-' : 'Gajim',
- 'GNT-' : 'http://trac.gajim.org/newticket',
- 'GW-' : 'http://trac.gajim.org/',
- 'GTS-' : 'http://trac.gajim.org/report'
- }
+ self.config_default_values = {'INVOKER' : (' ', _('')),
+ 'ACRONYMS' : ({'RTFM' : 'Read The Friendly Manual',
+ '/slap' : '/me slaps',
+ 'PS-' : 'plug-in system',
+ 'G-' : 'Gajim',
+ 'GNT-' : 'http://trac.gajim.org/newticket',
+ 'GW-' : 'http://trac.gajim.org/',
+ 'GTS-' : 'http://trac.gajim.org/report'
+ }, _('')),
+ }
@log_calls('AcronymsExpanderPlugin')
def textbuffer_live_acronym_expander(self, tb):
"""
@param tb gtk.TextBuffer
"""
- assert isinstance(tb,gtk.TextBuffer)
+ #assert isinstance(tb,gtk.TextBuffer)
+ ACRONYMS = self.config['ACRONYMS']
+ INVOKER = self.config['INVOKER']
t = tb.get_text(tb.get_start_iter(), tb.get_end_iter())
log.debug('%s %d'%(t, len(t)))
- if t and t[-1] == self.INVOKER:
+ if t and t[-1] == INVOKER:
log.debug("changing msg text")
- base,sep,head=t[:-1].rpartition(self.INVOKER)
+ base,sep,head=t[:-1].rpartition(INVOKER)
log.debug('%s | %s | %s'%(base, sep, head))
- if head in self.ACRONYMS:
- head = self.ACRONYMS[head]
+ if head in ACRONYMS:
+ head = ACRONYMS[head]
log.debug("head: %s"%(head))
- t = "".join((base, sep, head, self.INVOKER))
+ t = "".join((base, sep, head, INVOKER))
log.debug("turning off notify")
tb.freeze_notify()
log.debug("setting text: '%s'"%(t))
@@ -101,5 +104,4 @@ class AcronymsExpanderPlugin(GajimPlugin):
d = chat_control.acronyms_expander_plugin_data
tv = chat_control.msg_textview
tv.get_buffer().disconnect(d['h_id'])
-
- \ No newline at end of file
+ \ No newline at end of file
diff --git a/plugins/length_notifier/__init__.py b/plugins/length_notifier/__init__.py
new file mode 100644
index 000000000..fc433a0af
--- /dev/null
+++ b/plugins/length_notifier/__init__.py
@@ -0,0 +1,2 @@
+
+from length_notifier import LengthNotifierPlugin \ No newline at end of file
diff --git a/plugins/length_notifier/config_dialog.glade b/plugins/length_notifier/config_dialog.glade
new file mode 100644
index 000000000..0267bb184
--- /dev/null
+++ b/plugins/length_notifier/config_dialog.glade
@@ -0,0 +1,152 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<!DOCTYPE glade-interface SYSTEM "glade-2.0.dtd">
+<!--Generated with glade3 3.4.5 on Tue Jul 29 19:58:18 2008 -->
+<glade-interface>
+ <widget class="GtkWindow" id="window1">
+ <child>
+ <widget class="GtkTable" id="length_notifier_config_table">
+ <property name="visible">True</property>
+ <property name="border_width">9</property>
+ <property name="n_rows">3</property>
+ <property name="n_columns">2</property>
+ <property name="column_spacing">7</property>
+ <property name="row_spacing">5</property>
+ <child>
+ <widget class="GtkHBox" id="hbox2">
+ <property name="visible">True</property>
+ <child>
+ <widget class="GtkSpinButton" id="message_length_spinbutton">
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="tooltip" translatable="yes">Message length at which notification is invoked.</property>
+ <property name="width_chars">6</property>
+ <property name="adjustment">0 0 999999 1 10 10</property>
+ <property name="snap_to_ticks">True</property>
+ <property name="numeric">True</property>
+ <signal name="value_changed" handler="on_message_length_spinbutton_value_changed"/>
+ </widget>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">False</property>
+ </packing>
+ </child>
+ <child>
+ <widget class="GtkAlignment" id="alignment2">
+ <property name="visible">True</property>
+ <child>
+ <placeholder/>
+ </child>
+ </widget>
+ <packing>
+ <property name="position">1</property>
+ </packing>
+ </child>
+ </widget>
+ <packing>
+ <property name="left_attach">1</property>
+ <property name="right_attach">2</property>
+ <property name="x_options">GTK_FILL</property>
+ <property name="y_options">GTK_FILL</property>
+ </packing>
+ </child>
+ <child>
+ <widget class="GtkHBox" id="hbox1">
+ <property name="visible">True</property>
+ <child>
+ <widget class="GtkColorButton" id="notification_colorbutton">
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="receives_default">True</property>
+ <property name="tooltip" translatable="yes">Background color of text entry field in chat window when notification is invoked.</property>
+ <property name="xalign">0</property>
+ <property name="response_id">0</property>
+ <property name="title" translatable="yes">Pick a color for notification</property>
+ <property name="color">#000000000000</property>
+ <signal name="color_set" handler="on_notification_colorbutton_color_set"/>
+ </widget>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">False</property>
+ </packing>
+ </child>
+ <child>
+ <widget class="GtkAlignment" id="alignment1">
+ <property name="visible">True</property>
+ <child>
+ <placeholder/>
+ </child>
+ </widget>
+ <packing>
+ <property name="position">1</property>
+ </packing>
+ </child>
+ </widget>
+ <packing>
+ <property name="left_attach">1</property>
+ <property name="right_attach">2</property>
+ <property name="top_attach">1</property>
+ <property name="bottom_attach">2</property>
+ <property name="x_options">GTK_FILL</property>
+ <property name="y_options"></property>
+ </packing>
+ </child>
+ <child>
+ <widget class="GtkEntry" id="jids_entry">
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="tooltip" translatable="yes">JabberIDs that plugin should be used with (eg. restrict only to one microblogging bot). If empty plugin is used with every JID. [not implemented]</property>
+ <signal name="changed" handler="on_jids_entry_changed"/>
+ <signal name="editing_done" handler="on_jids_entry_editing_done"/>
+ </widget>
+ <packing>
+ <property name="left_attach">1</property>
+ <property name="right_attach">2</property>
+ <property name="top_attach">2</property>
+ <property name="bottom_attach">3</property>
+ <property name="y_options">GTK_FILL</property>
+ </packing>
+ </child>
+ <child>
+ <widget class="GtkLabel" id="label3">
+ <property name="visible">True</property>
+ <property name="tooltip" translatable="yes">JabberIDs that plugin should be used with (eg. restrict only to one microblogging bot). If empty plugin is used with every JID. [not implemented]</property>
+ <property name="xalign">0</property>
+ <property name="label" translatable="yes">JabberIDs to include:</property>
+ </widget>
+ <packing>
+ <property name="top_attach">2</property>
+ <property name="bottom_attach">3</property>
+ <property name="x_options">GTK_FILL</property>
+ <property name="y_options">GTK_FILL</property>
+ </packing>
+ </child>
+ <child>
+ <widget class="GtkLabel" id="label2">
+ <property name="visible">True</property>
+ <property name="tooltip" translatable="yes">Background color of text entry field in chat window when notification is invoked.</property>
+ <property name="xalign">0</property>
+ <property name="label" translatable="yes">Notification color:</property>
+ </widget>
+ <packing>
+ <property name="top_attach">1</property>
+ <property name="bottom_attach">2</property>
+ <property name="x_options">GTK_FILL</property>
+ <property name="y_options">GTK_FILL</property>
+ </packing>
+ </child>
+ <child>
+ <widget class="GtkLabel" id="label1">
+ <property name="visible">True</property>
+ <property name="tooltip" translatable="yes">Message length at which notification is invoked.</property>
+ <property name="xalign">0</property>
+ <property name="label" translatable="yes">Message length:</property>
+ </widget>
+ <packing>
+ <property name="x_options">GTK_FILL</property>
+ <property name="y_options">GTK_FILL</property>
+ </packing>
+ </child>
+ </widget>
+ </child>
+ </widget>
+</glade-interface>
diff --git a/plugins/length_notifier/length_notifier.py b/plugins/length_notifier/length_notifier.py
new file mode 100644
index 000000000..e9e5fbcd5
--- /dev/null
+++ b/plugins/length_notifier/length_notifier.py
@@ -0,0 +1,157 @@
+# -*- 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>
+:since: 1st June 2008
+:copyright: Copyright (2008) Mateusz Biliński <mateusz@bilinski.it>
+:license: GPL
+'''
+
+import sys
+
+import gtk
+from common import i18n
+
+from plugins import GajimPlugin
+from plugins.helpers import log, log_calls
+from plugins.gui import GajimPluginConfigDialog
+
+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 <mateusz@bilinski.it>']
+ 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 = LengthNotifierPluginConfigDialog(self)
+
+ self.gui_extension_points = {
+ 'chat_control' : (self.connect_with_chat_control,
+ self.disconnect_from_chat_control)
+ }
+
+ self.config_default_values = {'MESSAGE_WARNING_LENGTH' : (140, _('Message length at which 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]'))
+ }
+
+ @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.config['MESSAGE_WARNING_LENGTH']:
+ if not d['prev_color']:
+ d['prev_color'] = tv.style.copy().base[gtk.STATE_NORMAL]
+ tv.modify_base(gtk.STATE_NORMAL, gtk.gdk.color_parse(self.config['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.config['MESSAGE_WARNING_LENGTH']:
+ d['prev_color'] = tv.style.copy().base[gtk.STATE_NORMAL]
+ tv.modify_base(gtk.STATE_NORMAL, gtk.gdk.color_parse(self.config['WARNING_COLOR']))
+
+ chat_control.length_notifier_plugin_data = d
+
+ return True
+
+ return False
+
+ @log_calls('LengthNotifierPlugin')
+ def disconnect_from_chat_control(self, chat_control):
+ try:
+ 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'])
+ except AttributeError, error:
+ log.debug('Length Notifier Plugin was (probably) never connected with this chat window.\n Error: %s' % (error))
+
+ @log_calls('LengthNotifierPlugin')
+ def jid_is_ok(self, jid):
+ if jid in self.config['JIDS'] or not self.config['JIDS']:
+ return True
+
+ return False
+
+class LengthNotifierPluginConfigDialog(GajimPluginConfigDialog):
+ def init(self):
+ self.GLADE_FILE_PATH = self.plugin.local_file_path('config_dialog.glade')
+ self.xml = gtk.glade.XML(self.GLADE_FILE_PATH, root='length_notifier_config_table', domain=i18n.APP)
+ self.config_table = self.xml.get_widget('length_notifier_config_table')
+ self.child.pack_start(self.config_table)
+
+ self.message_length_spinbutton = self.xml.get_widget('message_length_spinbutton')
+ self.notification_colorbutton = self.xml.get_widget('notification_colorbutton')
+ self.jids_entry = self.xml.get_widget('jids_entry')
+
+ self.xml.signal_autoconnect(self)
+
+ def on_run(self):
+ self.message_length_spinbutton.set_value(self.plugin.config['MESSAGE_WARNING_LENGTH'])
+ self.notification_colorbutton.set_color(gtk.gdk.color_parse(self.plugin.config['WARNING_COLOR']))
+ #self.jids_entry.set_text(self.plugin.config['JIDS'])
+ self.jids_entry.set_text(','.join(self.plugin.config['JIDS']))
+
+ @log_calls('LengthNotifierPluginConfigDialog')
+ def on_message_length_spinbutton_value_changed(self, spinbutton):
+ self.plugin.config['MESSAGE_WARNING_LENGTH'] = spinbutton.get_value()
+
+ @log_calls('LengthNotifierPluginConfigDialog')
+ def on_notification_colorbutton_color_set(self, colorbutton):
+ self.plugin.config['WARNING_COLOR'] = colorbutton.get_color().to_string()
+
+ @log_calls('LengthNotifierPluginConfigDialog')
+ def on_jids_entry_changed(self, entry):
+ text = entry.get_text()
+ if len(text)>0:
+ self.plugin.config['JIDS'] = entry.get_text().split(',')
+ else:
+ self.plugin.config['JIDS'] = []
+
+ @log_calls('LengthNotifierPluginConfigDialog')
+ def on_jids_entry_editing_done(self, entry):
+ pass
+ \ No newline at end of file