Commit e76b0ace authored by Philipp Hörist's avatar Philipp Hörist

Merge branch 'regex-filter-config-ui' into 'master'

Add UI view to edit replacement patterns for regex_filter

See merge request !28
parents fe9819c6 fb32816f
<?xml version="1.0"?>
<interface>
<requires lib="gtk+" version="2.16"/>
<object class="GtkListStore" id="rules_store">
<columns>
<!-- column-name index -->
<column type="gint"/>
<!-- column-name search -->
<column type="gchararray"/>
<!-- column-name replace -->
<column type="gchararray"/>
</columns>
</object>
<object class="GtkVBox" id="vbox1">
<property name="visible">True</property>
<property name="border_width">12</property>
<property name="orientation">vertical</property>
<child>
<object class="GtkScrolledWindow" id="scrolledwindow1">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="hscrollbar_policy">automatic</property>
<property name="vscrollbar_policy">automatic</property>
<child>
<object class="GtkTreeView" id="rules_view">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="model">rules_store</property>
<property name="search_column">1</property>
<child>
<object class="GtkTreeViewColumn" id="index_column">
<property name="visible">False</property>
<child>
<object class="GtkCellRendererText" id="cellrenderertext1"/>
<attributes>
<attribute name="text">0</attribute>
</attributes>
</child>
</object>
</child>
<child>
<object class="GtkTreeViewColumn" id="search_column">
<property name="resizable">True</property>
<property name="title">Search Pattern</property>
<child>
<object class="GtkCellRendererText" id="cellrenderertext2"/>
<attributes>
<attribute name="text">1</attribute>
</attributes>
</child>
</object>
</child>
<child>
<object class="GtkTreeViewColumn" id="replace_column">
<property name="resizable">True</property>
<property name="title">Replace String</property>
<child>
<object class="GtkCellRendererText" id="cellrenderertext3"/>
<attributes>
<attribute name="text">2</attribute>
</attributes>
</child>
</object>
</child>
</object>
</child>
</object>
<packing>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkHBox" id="hbox1">
<property name="visible">True</property>
<property name="spacing">5</property>
<property name="homogeneous">True</property>
<child>
<object class="GtkButton" id="add_button">
<property name="label" translatable="yes" comments="button">Add</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<signal name="clicked" handler="add_button_clicked_cb"/>
</object>
<packing>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkButton" id="remove_button">
<property name="label" translatable="yes" comments="button">Remove</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<signal name="clicked" handler="remove_button_clicked_cb"/>
</object>
<packing>
<property name="position">1</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="position">1</property>
</packing>
</child>
</object>
</interface>
[info]
name: Regex Filter
short_name: regex_filter
version: 0.2.3
version: 0.2.4
description: Filter incoming messages using regex.
authors: Yann Leboulanger <asterix@lagaule.org>
homepage: http://trac-plugins.gajim.org/wiki/RegexFilterPlugin
homepage: https://dev.gajim.org/gajim/gajim-plugins/wikis/RegexFilterPlugin
max_gajim_version: 0.16.9
......@@ -34,11 +34,13 @@ from common import ged
from command_system.framework import CommandContainer, command, doc
from command_system.implementation.hosts import *
import ui
class RegexFilterPlugin(GajimPlugin):
@log_calls('RegexFilterPlugin')
def init(self):
self.config_dialog = None
self.config_dialog = ui.RegexFilterPluginConfigDialog(self)
self.events_handlers = {
'decrypted-message-received': (ged.PREGUI1,
......@@ -61,6 +63,7 @@ class RegexFilterPlugin(GajimPlugin):
self.rules = {}
for num, c in self.config.items():
self.rules[int(num)] = [re.compile(c[0], re.MULTILINE), c[1]]
self.update_context_list()
@log_calls('RegexFilterPlugin')
def add_rule(self, search, replace):
......@@ -101,6 +104,15 @@ class RegexFilterPlugin(GajimPlugin):
def _nec_gc_message_received(self, obj):
self._nec_all(obj)
@log_calls('RegexFilterPlugin')
def update_context_list(self):
self.config_dialog.rules_model.clear()
rules_num = self.rules.keys()
rules_num.sort()
for num in rules_num:
rule = self.rules[num]
self.config_dialog.rules_model.append((num, rule[0].pattern, rule[1]))
class FilterCommands(CommandContainer):
AUTOMATIC = False
HOSTS = ChatCommands, PrivateChatCommands, GroupChatCommands
......
# -*- coding: utf-8 -*-
import gtk
import gobject
from common import gajim
from plugins.gui import GajimPluginConfigDialog
class RegexFilterPluginConfigDialog(GajimPluginConfigDialog):
def init(self):
self.GTK_BUILDER_FILE_PATH = self.plugin.local_file_path(
'config_dialog.ui')
self.xml = gtk.Builder()
self.xml.set_translation_domain('gajim_plugins')
self.xml.add_from_file(self.GTK_BUILDER_FILE_PATH)
self.rules_model = gtk.ListStore(gobject.TYPE_INT,
gobject.TYPE_STRING,
gobject.TYPE_STRING)
self.rules_view = self.xml.get_object('rules_view')
self.rules_view.set_model(self.rules_model)
self.rules_view.get_selection().set_mode(gtk.SELECTION_MULTIPLE)
self.child.pack_start(self.xml.get_object('vbox1'))
self.child.parent.set_geometry_hints(None,
min_width=512, min_height=400,
max_width=1024, max_height=800)
self.xml.connect_signals(self)
def add_button_clicked_cb(self, button, *args):
message = "Add a new filter for incoming messages"
dialog = gtk.MessageDialog(self.parent,
gtk.DIALOG_MODAL|gtk.DIALOG_DESTROY_WITH_PARENT,
gtk.MESSAGE_OTHER,
gtk.BUTTONS_OK_CANCEL,
message)
hbox = gtk.HBox(False, 4)
hbox.show()
label1 = gtk.Label("Search:")
label1.show()
hbox.pack_start(label1, False, False, 0)
searchEntry = gtk.Entry()
searchEntry.show()
hbox.pack_start(searchEntry, True, False, 1)
label2 = gtk.Label("Replace:")
label2.show()
hbox.pack_start(label2, False, False, 2)
replaceEntry = gtk.Entry()
replaceEntry.show()
hbox.pack_start(replaceEntry, True, False, 3)
dialog.vbox.add(hbox)
searchEntry.connect('activate',
lambda _: dialog.response(gtk.RESPONSE_OK))
replaceEntry.connect('activate',
lambda _: dialog.response(gtk.RESPONSE_OK))
dialog.set_default_response(gtk.RESPONSE_OK)
response = dialog.run()
search = searchEntry.get_text().decode('utf8')
replace = replaceEntry.get_text().decode('utf8')
dialog.destroy()
if response == gtk.RESPONSE_OK:
if search.strip():
self.plugin.add_rule(search, replace)
def remove_button_clicked_cb(self, button, *args):
model, rules = self.rules_view.get_selection().get_selected_rows()
for rule in reversed(rules):
it = model.get_iter(rule)
ruleNum = model.get(it, 0)
self.plugin.remove_rule("%d" % ruleNum)
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