diff --git a/image/__init__.py b/image/__init__.py deleted file mode 100644 index e003e38..0000000 --- a/image/__init__.py +++ /dev/null @@ -1 +0,0 @@ -from .image import ImagePlugin diff --git a/image/image.png b/image/image.png deleted file mode 100644 index 32dda52..0000000 Binary files a/image/image.png and /dev/null differ diff --git a/image/image.py b/image/image.py deleted file mode 100644 index 9b47f24..0000000 --- a/image/image.py +++ /dev/null @@ -1,153 +0,0 @@ -import os -import base64 -import urllib - -from gi.repository import Gtk -from gi.repository import Gdk - -from gajim import chat_control -from gajim.plugins import GajimPlugin -from gajim.plugins.helpers import log_calls -from gajim.plugins.plugins_i18n import _ -from gajim.gtk.dialogs import ErrorDialog -from gajim.gtk.filechoosers import FileChooserDialog - - -NS_XHTML_IM = 'http://jabber.org/protocol/xhtml-im' - - -class ImagePlugin(GajimPlugin): - @log_calls('ImagePlugin') - def init(self): - self.description = _('This plugin is designed to send ' - 'a small(0 - 40 kb) graphic image to your contact.\n' - 'Client on the other side must support XEP-0071: XHTML-IM' - ' and maintain the scheme data: URI.\n' - 'Psi+ and Jabbim supported this.') - self.config_dialog = None # ImagePluginConfigDialog(self) - self.controls = [] - self.gui_extension_points = { - 'chat_control_base': (self.connect_with_chat_control, - self.disconnect_from_chat_control), - 'chat_control_base_update_toolbar': (self.update_button_state, - None)} - self.first_run = True - - @log_calls('ImagePlugin') - def connect_with_chat_control(self, control): - if not isinstance(control, chat_control.ChatControl): - return - self.chat_control = control - base = Base(self, self.chat_control) - self.controls.append(base) - - @log_calls('ImagePlugin') - def disconnect_from_chat_control(self, chat_control): - for control in self.controls: - control.disconnect_from_chat_control() - self.controls = [] - - @log_calls('ImagePlugin') - def update_button_state(self, chat_control): - for base in self.controls: - if base.chat_control == chat_control: - is_support_xhtml = chat_control.contact.supports(NS_XHTML_IM) - base.button.set_sensitive(is_support_xhtml and not \ - chat_control.encryption) - if not is_support_xhtml: - text = _('This contact does not support XHTML_IM') - else: - text = _('Send image (Alt+L)') - base.button.set_tooltip_text(text) - - -class Base(object): - def __init__(self, plugin, chat_control): - self.plugin = plugin - self.chat_control = chat_control - actions_hbox = chat_control.xml.get_object('hbox') - - self.button = Gtk.Button(label=None, stock=None, use_underline=True) - self.button.get_style_context().add_class( - 'chatcontrol-actionbar-button') - self.button.set_property('relief', Gtk.ReliefStyle.NONE) - self.button.set_property('can-focus', False) - img = Gtk.Image() - img.set_from_icon_name('image-x-generic-symbolic.symbolic', - Gtk.IconSize.MENU) - self.button.set_image(img) - self.button.set_tooltip_text('Send image (Alt+L)') - ag = Gtk.accel_groups_from_object(self.chat_control.parent_win.window)[0] - self.button.add_accelerator('activate', ag, Gdk.KEY_L, - Gdk.ModifierType.MOD1_MASK, Gtk.AccelFlags.VISIBLE) - - actions_hbox.pack_start(self.button, False, False , 0) - actions_hbox.reorder_child(self.button, - len(actions_hbox.get_children()) - 2) - id_ = self.button.connect('clicked', self.on_image_button_clicked) - self.button.show() - - def _on_message_textview_key_press_event(self, widget, event): - if event.get_state() & Gdk.ModifierType.MOD1_MASK and \ - event.keyval == Gdk.KEY_l: - if not self.chat_control.contact.supports(NS_XHTML_IM): - from dialogs import WarningDialog - WarningDialog('Warning', - _('This contact does not support XHTML_IM'), - self.chat_control.parent_win.window) - return True - self.on_image_button_clicked(widget) - return True - - def on_image_button_clicked(self, *args): - def on_ok(filename): - image = self._check_file(filename) - if image is None: - return - - self._send(image, filename) - - FileChooserDialog(on_ok, - select_multiple=False, - transient_for=self.chat_control.parent_win.window) - - def _check_file(self, filename): - filesize = os.path.getsize(filename) # in bytes - invalid_file = False - msg = '' - if os.path.isfile(filename): - stat = os.stat(filename) - if stat[6] == 0: - invalid_file = True - msg = _('File is empty') - else: - invalid_file = True - msg = _('File does not exist') - if filesize < 60000: - file_ = open(filename, "rb") - img = urllib.parse.quote(base64.standard_b64encode( - file_.read()), '') - if len(img) > 60000: - invalid_file = True - msg = _('File too big') - file_.close() - else: - invalid_file = True - msg = _('File too big') - if invalid_file: - ErrorDialog(_('Could not load image'), msg) - return - return img - - def _send(self, image, filename): - msg = 'HTML image' - extension = os.path.splitext(os.path.split(filename)[1])[1] \ - .lower()[1:] - xhtml = '