LINUX.ORG.RU

История изменений

Исправление annerleen, (текущая версия) :

--- chat_control.py.orig	2019-01-15 22:18:31.000000000 +0200
+++ chat_control.py	2019-06-18 19:12:09.880182560 +0300
@@ -28,8 +28,11 @@
 
 import os
 import time
+import tempfile
+import random
 
 from gi.repository import Gtk
+from gi.repository import Gdk
 from gi.repository import Gio
 from gi.repository import Pango
 from gi.repository import GLib
@@ -1247,6 +1250,22 @@
 
             dialogs.TransformChatToMUC(self.account, [c.jid], [dropped_jid])
 
+    def _on_paste_data_received(self, widget):
+        clipboard = Gtk.Clipboard.get(Gdk.SELECTION_CLIPBOARD)
+        image = clipboard.wait_for_image()
+        if not image: 
+            return
+        path = os.path.join(tempfile.mkdtemp(), ''.join(random.sample('abcdefghijklmnopqrstuvwxyz0123456789'*6, 12)) + '.png' )
+        image.savev(path, 'png', [], [])
+
+        # get contact info (check for PM = private chat)
+        if self.TYPE_ID == message_control.TYPE_PM:
+            c = self.gc_contact.as_contact()
+        else:
+            c = self.contact
+
+        self.clipboard_file_transfer(c, path, self)
+
     def restore_conversation(self):
         jid = self.contact.jid
         # don't restore lines if it's a transport



--- chat_control_base.py.orig	2019-01-15 22:18:31.000000000 +0200
+++ chat_control_base.py	2019-06-18 19:11:34.580240567 +0300
@@ -310,6 +310,10 @@
         id_ = self.msg_textview.connect('drag_data_received',
             self._on_drag_data_received)
         self.handlers[id_] = self.msg_textview
+        # setup paste 
+        id_ = self.msg_textview.connect('paste-clipboard',
+            self._on_paste_data_received)
+        self.handlers[id_] = self.msg_textview
         self.msg_textview.drag_dest_set(Gtk.DestDefaults.MOTION |
             Gtk.DestDefaults.HIGHLIGHT, self.dnd_list, Gdk.DragAction.COPY)
 
@@ -716,6 +720,12 @@
         """
         pass
 
+    def _on_paste_data_received(self, widget):
+        """
+        Derived types SHOULD implement this
+        """
+        pass
+
     def _on_drag_leave(self, *args):
         # FIXME: DND on non editable TextView, find a better way
         self.drag_entered = False
@@ -766,6 +776,42 @@
                     ft = app.interface.instances['file_transfers']
                     ft.send_file(self.account, contact, path)
 
+    def clipboard_file_transfer(self, contact, path, widget):
+        # get file transfer preference
+        ft_pref = app.config.get_per('accounts', self.account,
+                                     'filetransfer_preference')
+        win = self.parent_win.window
+        con = app.connections[self.account]
+        httpupload = win.lookup_action(
+            'send-file-httpupload-%s' % self.control_id)
+        jingle = win.lookup_action('send-file-jingle-%s' % self.control_id)
+
+        if not os.path.isfile(path):  # is it a file?
+            return
+
+        if self.type_id == message_control.TYPE_GC:
+            # groupchat only supports httpupload on drag and drop
+            if httpupload.get_enabled():
+                # use httpupload
+                con.get_module('HTTPUpload').check_file_before_transfer(
+                    path, self.encryption, contact,
+                    self.session, groupchat=True)
+        else:
+            if httpupload.get_enabled() and jingle.get_enabled():
+                if ft_pref == 'httpupload':
+                    con.get_module('HTTPUpload').check_file_before_transfer(
+                        path, self.encryption, contact, self.session)
+                else:
+                    ft = app.interface.instances['file_transfers']
+                    ft.send_file(self.account, contact, path)
+            elif httpupload.get_enabled():
+                con.get_module('HTTPUpload').check_file_before_transfer(
+                    path, self.encryption, contact, self.session)
+            elif jingle.get_enabled():
+                ft = app.interface.instances['file_transfers']
+                ft.send_file(self.account, contact, path)
+
+
     def get_seclabel(self):
         idx = self.seclabel_combo.get_active()
         if idx == -1:

Исправление annerleen, :

Closed.

Исходная версия annerleen, :

--- chat_control.py	2019-01-15 22:18:31.000000000 +0200
+++ /home/ann/chat_control.py	2019-06-18 19:12:09.880182560 +0300
@@ -28,8 +28,11 @@
 
 import os
 import time
+import tempfile
+import random
 
 from gi.repository import Gtk
+from gi.repository import Gdk
 from gi.repository import Gio
 from gi.repository import Pango
 from gi.repository import GLib
@@ -1247,6 +1250,22 @@
 
             dialogs.TransformChatToMUC(self.account, [c.jid], [dropped_jid])
 
+    def _on_paste_data_received(self, widget):
+        clipboard = Gtk.Clipboard.get(Gdk.SELECTION_CLIPBOARD)
+        image = clipboard.wait_for_image()
+        if not image: 
+            return
+        path = os.path.join(tempfile.mkdtemp(), ''.join(random.sample('abcdefghijklmnopqrstuvwxyz0123456789'*6, 12)) + '.png' )
+        image.savev(path, 'png', [], [])
+
+        # get contact info (check for PM = private chat)
+        if self.TYPE_ID == message_control.TYPE_PM:
+            c = self.gc_contact.as_contact()
+        else:
+            c = self.contact
+
+        self.clipboard_file_transfer(c, path, self)
+
     def restore_conversation(self):
         jid = self.contact.jid
         # don't restore lines if it's a transport



--- chat_control_base.py	2019-01-15 22:18:31.000000000 +0200
+++ /home/ann/gajim/chat_control_base.py	2019-06-18 19:11:34.580240567 +0300
@@ -310,6 +310,10 @@
         id_ = self.msg_textview.connect('drag_data_received',
             self._on_drag_data_received)
         self.handlers[id_] = self.msg_textview
+        # setup paste 
+        id_ = self.msg_textview.connect('paste-clipboard',
+            self._on_paste_data_received)
+        self.handlers[id_] = self.msg_textview
         self.msg_textview.drag_dest_set(Gtk.DestDefaults.MOTION |
             Gtk.DestDefaults.HIGHLIGHT, self.dnd_list, Gdk.DragAction.COPY)
 
@@ -716,6 +720,12 @@
         """
         pass
 
+    def _on_paste_data_received(self, widget):
+        """
+        Derived types SHOULD implement this
+        """
+        pass
+
     def _on_drag_leave(self, *args):
         # FIXME: DND on non editable TextView, find a better way
         self.drag_entered = False
@@ -766,6 +776,42 @@
                     ft = app.interface.instances['file_transfers']
                     ft.send_file(self.account, contact, path)
 
+    def clipboard_file_transfer(self, contact, path, widget):
+        # get file transfer preference
+        ft_pref = app.config.get_per('accounts', self.account,
+                                     'filetransfer_preference')
+        win = self.parent_win.window
+        con = app.connections[self.account]
+        httpupload = win.lookup_action(
+            'send-file-httpupload-%s' % self.control_id)
+        jingle = win.lookup_action('send-file-jingle-%s' % self.control_id)
+
+        if not os.path.isfile(path):  # is it a file?
+            return
+
+        if self.type_id == message_control.TYPE_GC:
+            # groupchat only supports httpupload on drag and drop
+            if httpupload.get_enabled():
+                # use httpupload
+                con.get_module('HTTPUpload').check_file_before_transfer(
+                    path, self.encryption, contact,
+                    self.session, groupchat=True)
+        else:
+            if httpupload.get_enabled() and jingle.get_enabled():
+                if ft_pref == 'httpupload':
+                    con.get_module('HTTPUpload').check_file_before_transfer(
+                        path, self.encryption, contact, self.session)
+                else:
+                    ft = app.interface.instances['file_transfers']
+                    ft.send_file(self.account, contact, path)
+            elif httpupload.get_enabled():
+                con.get_module('HTTPUpload').check_file_before_transfer(
+                    path, self.encryption, contact, self.session)
+            elif jingle.get_enabled():
+                ft = app.interface.instances['file_transfers']
+                ft.send_file(self.account, contact, path)
+
+
     def get_seclabel(self):
         idx = self.seclabel_combo.get_active()
         if idx == -1: