Juick. use new extension point
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
[info]
|
[info]
|
||||||
name: Juick
|
name: Juick
|
||||||
short_name: Juick
|
short_name: Juick
|
||||||
version: 0.4
|
version: 0.5
|
||||||
description: Clickable juick links , juick nics, preview juick picturs.
|
description: Clickable juick links , juick nics, preview juick picturs.
|
||||||
The key combination alt + up in the textbox allow insert the number of last message (comment or topic).
|
The key combination alt + up in the textbox allow insert the number of last message (comment or topic).
|
||||||
authors: Denis Fomin <fominde@gmail.com>, evgen <drujebober@gmail.com>
|
authors: Denis Fomin <fominde@gmail.com>, evgen <drujebober@gmail.com>
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ from string import upper
|
|||||||
from string import rstrip
|
from string import rstrip
|
||||||
import locale
|
import locale
|
||||||
import sqlite3
|
import sqlite3
|
||||||
|
import gobject
|
||||||
|
|
||||||
from common import helpers
|
from common import helpers
|
||||||
from common import gajim
|
from common import gajim
|
||||||
@@ -31,7 +32,9 @@ class JuickPlugin(GajimPlugin):
|
|||||||
self.config_dialog = JuickPluginConfigDialog(self)
|
self.config_dialog = JuickPluginConfigDialog(self)
|
||||||
self.gui_extension_points = {
|
self.gui_extension_points = {
|
||||||
'chat_control_base': (self.connect_with_chat_control,
|
'chat_control_base': (self.connect_with_chat_control,
|
||||||
self.disconnect_from_chat_control)}
|
self.disconnect_from_chat_control),
|
||||||
|
'print_special_text': (self.print_special_text,
|
||||||
|
self.print_special_text1),}
|
||||||
self.config_default_values = {'SHOW_AVATARS': (False, ''),
|
self.config_default_values = {'SHOW_AVATARS': (False, ''),
|
||||||
'AVATAR_SIZE': (20, 'Avatar size(10-32)'),
|
'AVATAR_SIZE': (20, 'Avatar size(10-32)'),
|
||||||
'avatars_old': (2419200, 'Update avatars '
|
'avatars_old': (2419200, 'Update avatars '
|
||||||
@@ -78,6 +81,18 @@ class JuickPlugin(GajimPlugin):
|
|||||||
self.controls = []
|
self.controls = []
|
||||||
self.conn.close()
|
self.conn.close()
|
||||||
|
|
||||||
|
def print_special_text(self, tv, special_text, other_tags, graphics=True):
|
||||||
|
for control in self.controls:
|
||||||
|
if control.chat_control.conv_textview != tv:
|
||||||
|
continue
|
||||||
|
control.print_special_text(special_text, other_tags, graphics=True)
|
||||||
|
|
||||||
|
def print_special_text1(self, chat_control, special_text, other_tags=None,
|
||||||
|
graphics=True):
|
||||||
|
for control in self.controls:
|
||||||
|
if control.chat_control == chat_control:
|
||||||
|
control.disconnect_from_chat_control()
|
||||||
|
self.controls.remove(control)
|
||||||
|
|
||||||
class Base(object):
|
class Base(object):
|
||||||
def __init__(self, plugin, chat_control):
|
def __init__(self, plugin, chat_control):
|
||||||
@@ -124,9 +139,6 @@ class Base(object):
|
|||||||
self.create_tag_menu()
|
self.create_tag_menu()
|
||||||
self.create_buttons()
|
self.create_buttons()
|
||||||
|
|
||||||
self.old_print_special_text = self.textview.print_special_text
|
|
||||||
self.textview.print_special_text = self.print_special_text
|
|
||||||
|
|
||||||
def create_patterns(self):
|
def create_patterns(self):
|
||||||
self.juick_post_uid = self.juick_nick = ''
|
self.juick_post_uid = self.juick_nick = ''
|
||||||
self.juick_post_re = re.compile(r'#(\d+)')
|
self.juick_post_re = re.compile(r'#(\d+)')
|
||||||
@@ -308,19 +320,21 @@ class Base(object):
|
|||||||
buffer_, iter_, tag = self.get_iter_and_tag('sharp_slash')
|
buffer_, iter_, tag = self.get_iter_and_tag('sharp_slash')
|
||||||
buffer_.insert_with_tags(iter_, special_text, tag)
|
buffer_.insert_with_tags(iter_, special_text, tag)
|
||||||
self.last_juick_num = special_text
|
self.last_juick_num = special_text
|
||||||
|
self.textview.plugin_modified = True
|
||||||
return
|
return
|
||||||
if gajim.interface.juick_nick_re.match(special_text):
|
if gajim.interface.juick_nick_re.match(special_text):
|
||||||
# insert juick nick @nickname////
|
# insert juick nick @nickname////
|
||||||
if not self.plugin.config['SHOW_AVATARS']:
|
if not self.plugin.config['SHOW_AVATARS']:
|
||||||
|
self.textview.plugin_modified = True
|
||||||
return
|
return
|
||||||
buffer_, iter_, tag = self.get_iter_and_tag('juick_nick')
|
buffer_, iter_, tag = self.get_iter_and_tag('juick_nick')
|
||||||
mark = buffer_.create_mark(None, iter_, True)
|
mark = buffer_.create_mark(None, iter_, True)
|
||||||
nick = special_text[1:].rstrip(':')
|
nick = special_text[1:].rstrip(':')
|
||||||
# insert juick nick
|
|
||||||
buffer_.insert_with_tags(iter_, special_text, tag)
|
buffer_.insert_with_tags(iter_, special_text, tag)
|
||||||
# insert avatars
|
# insert avatars
|
||||||
conn = gajim.connections[self.chat_control.account]
|
conn = gajim.connections[self.chat_control.account]
|
||||||
if not conn.connected:
|
if not conn.connected:
|
||||||
|
self.textview.plugin_modified = True
|
||||||
return
|
return
|
||||||
# search id in the db
|
# search id in the db
|
||||||
query = "select nick, id from person where nick = :nick"
|
query = "select nick, id from person where nick = :nick"
|
||||||
@@ -330,6 +344,7 @@ class Base(object):
|
|||||||
# nick in the db
|
# nick in the db
|
||||||
pixbuf = self.get_avatar(db_item[1], nick, True)
|
pixbuf = self.get_avatar(db_item[1], nick, True)
|
||||||
if not pixbuf:
|
if not pixbuf:
|
||||||
|
self.textview.plugin_modified = True
|
||||||
return
|
return
|
||||||
end_iter = buffer_.get_iter_at_mark(mark)
|
end_iter = buffer_.get_iter_at_mark(mark)
|
||||||
anchor = buffer_.create_child_anchor(end_iter)
|
anchor = buffer_.create_child_anchor(end_iter)
|
||||||
@@ -337,6 +352,7 @@ class Base(object):
|
|||||||
img.set_from_pixbuf(pixbuf)
|
img.set_from_pixbuf(pixbuf)
|
||||||
img.show()
|
img.show()
|
||||||
self.textview.tv.add_child_at_anchor(img, anchor)
|
self.textview.tv.add_child_at_anchor(img, anchor)
|
||||||
|
self.textview.plugin_modified = True
|
||||||
return
|
return
|
||||||
else:
|
else:
|
||||||
# nick not in the db
|
# nick not in the db
|
||||||
@@ -350,6 +366,7 @@ class Base(object):
|
|||||||
iq.setID(id_)
|
iq.setID(id_)
|
||||||
conn.connection.SendAndCallForResponse(iq, self._on_response,
|
conn.connection.SendAndCallForResponse(iq, self._on_response,
|
||||||
{'mark': mark, 'special_text': special_text})
|
{'mark': mark, 'special_text': special_text})
|
||||||
|
self.textview.plugin_modified = True
|
||||||
return
|
return
|
||||||
if gajim.interface.juick_pic_re.match(special_text) and \
|
if gajim.interface.juick_pic_re.match(special_text) and \
|
||||||
self.plugin.config['SHOW_PREVIEW']:
|
self.plugin.config['SHOW_PREVIEW']:
|
||||||
@@ -359,19 +376,20 @@ class Base(object):
|
|||||||
buffer_.insert_with_tags(iter_, special_text, tag)
|
buffer_.insert_with_tags(iter_, special_text, tag)
|
||||||
uid = special_text.split('/')[-1]
|
uid = special_text.split('/')[-1]
|
||||||
url = "http://i.juick.com/photos-512/%s" % uid
|
url = "http://i.juick.com/photos-512/%s" % uid
|
||||||
pixbuf = self.get_pixbuf_from_url( url, self.plugin.config[
|
gobject.idle_add(self.insert_pic_preview, mark, special_text, url)
|
||||||
'PREVIEW_SIZE'])
|
|
||||||
if pixbuf:
|
def insert_pic_preview(self, mark, special_text, url):
|
||||||
# insert image
|
pixbuf = self.get_pixbuf_from_url( url, self.plugin.config[
|
||||||
buffer_ = mark.get_buffer()
|
'PREVIEW_SIZE'])
|
||||||
end_iter = buffer_.get_iter_at_mark(mark)
|
if pixbuf:
|
||||||
anchor = buffer_.create_child_anchor(end_iter)
|
# insert image
|
||||||
img = TextViewImage(anchor, special_text)
|
buffer_ = mark.get_buffer()
|
||||||
img.set_from_pixbuf(pixbuf)
|
end_iter = buffer_.get_iter_at_mark(mark)
|
||||||
img.show()
|
anchor = buffer_.create_child_anchor(end_iter)
|
||||||
self.textview.tv.add_child_at_anchor(img, anchor)
|
img = TextViewImage(anchor, special_text)
|
||||||
else:
|
img.set_from_pixbuf(pixbuf)
|
||||||
self.old_print_special_text(special_text, other_tags, graphics)
|
img.show()
|
||||||
|
self.textview.tv.add_child_at_anchor(img, anchor)
|
||||||
|
|
||||||
def get_iter_and_tag(self, tag_name):
|
def get_iter_and_tag(self, tag_name):
|
||||||
buffer_ = self.textview.tv.get_buffer()
|
buffer_ = self.textview.tv.get_buffer()
|
||||||
@@ -565,7 +583,6 @@ class Base(object):
|
|||||||
helpers.launch_browser_mailer('url', url)
|
helpers.launch_browser_mailer('url', url)
|
||||||
|
|
||||||
def disconnect_from_chat_control(self):
|
def disconnect_from_chat_control(self):
|
||||||
self.textview.print_special_text = self.old_print_special_text
|
|
||||||
buffer_ = self.textview.tv.get_buffer()
|
buffer_ = self.textview.tv.get_buffer()
|
||||||
tag_table = buffer_.get_tag_table()
|
tag_table = buffer_.get_tag_table()
|
||||||
if tag_table.lookup('sharp_slash'):
|
if tag_table.lookup('sharp_slash'):
|
||||||
|
|||||||
Reference in New Issue
Block a user