Philipp Hörist pushed to branch master at gajim / gajim
Commits:
2cf121e4 by lovetox at 2022-06-12T23:19:48+02:00
fix: Make drag & drop more reliable
Use pickle to pass data as a tuple instead of depending on string.split()
Fixes #10978
- - - - -
2 changed files:
- gajim/gtk/chat_list.py
- gajim/gtk/workspace_side_bar.py
Changes:
=====================================
gajim/gtk/chat_list.py
=====================================
@@ -21,6 +21,7 @@
import logging
import time
+import pickle
from gi.repository import Gio
from gi.repository import Gdk
@@ -737,8 +738,8 @@ def _on_drag_data_get(self,
_time: int
) -> None:
drop_type = Gdk.Atom.intern_static_string('CHAT_LIST_ITEM')
- data = f'{self.account} {self.jid}'.encode('utf-8')
- selection_data.set(drop_type, 32, data)
+ byte_data = pickle.dumps((self.account, self.jid))
+ selection_data.set(drop_type, 8, byte_data)
def toggle_pinned(self) -> None:
self._pinned = not self._pinned
=====================================
gajim/gtk/workspace_side_bar.py
=====================================
@@ -20,12 +20,12 @@
from typing import cast
import logging
+import pickle
from gi.repository import Gdk
from gi.repository import Gio
from gi.repository import GLib
from gi.repository import Gtk
-
from nbxmpp.protocol import JID
from gajim.common import app
@@ -117,12 +117,13 @@ def _on_drag_data_received(self,
_info: int,
_time: int
) -> None:
- data = selection_data.get_data().decode('utf-8')
+ data = selection_data.get_data()
item_type = selection_data.get_data_type().name()
if item_type == 'WORKSPACE_SIDEBAR_ITEM':
- self._process_workspace_drop(data)
+ self._process_workspace_drop(data.decode('utf-8'))
elif item_type == 'CHAT_LIST_ITEM':
- self._process_chat_list_drop(data, y_coord)
+ account, jid = pickle.loads(data)
+ self._process_chat_list_drop(account, jid, y_coord)
else:
log.debug('Unknown item type dropped')
@@ -147,9 +148,11 @@ def _process_workspace_drop(self, workspace_id: str) ->
None:
self.store_workspace_order()
app.window.activate_workspace(workspace_id)
- def _process_chat_list_drop(self, identifier: str, y_coord: int) -> None:
- account, jid = identifier.split()
- jid = JID.from_string(jid)
+ def _process_chat_list_drop(self,
+ account: str,
+ jid: JID,
+ y_coord: int) -> None:
+
workspace_row = cast(Workspace, self.get_row_at_y(y_coord))
if workspace_row.workspace_id == 'add':
app.window.move_chat_to_new_workspace(
@@ -377,7 +380,7 @@ def _on_drag_data_get(self,
) -> None:
drop_type = Gdk.Atom.intern_static_string('WORKSPACE_SIDEBAR_ITEM')
data = self.workspace_id.encode('utf-8')
- selection_data.set(drop_type, 32, data)
+ selection_data.set(drop_type, 8, data)
class AddWorkspace(CommonWorkspace):
View it on GitLab:
https://dev.gajim.org/gajim/gajim/-/commit/2cf121e4e3f84171f294d217bd8b6f8ba20706c9
--
View it on GitLab:
https://dev.gajim.org/gajim/gajim/-/commit/2cf121e4e3f84171f294d217bd8b6f8ba20706c9
You're receiving this email because of your account on dev.gajim.org.
_______________________________________________
Commits mailing list
[email protected]
https://lists.gajim.org/cgi-bin/listinfo/commits