Commit 780fcfa5 authored by Daniel Brötzmann's avatar Daniel Brötzmann Committed by Philipp Hörist

GroupChatControl: Fix drag and drop invites

This adds the correct TargetList to our drag destination. Dropping a
contact on the group chat's roster will send an invite.
parent 7c3d4740
Pipeline #3625 passed with stages
in 2 minutes and 37 seconds
......@@ -1241,17 +1241,17 @@ class ChatControl(ChatControlBase):
c = self.contact
if target_type == self.TARGET_TYPE_URI_LIST:
# file drag and drop (handled in chat_control_base)
# File drag and drop (handled in chat_control_base)
self.drag_data_file_transfer(c, selection, self)
else:
# chat2muc
# Convert single chat to MUC
treeview = app.interface.roster.tree
model = treeview.get_model()
data = selection.get_data()
data = selection.get_data().decode()
path = treeview.get_selection().get_selected_rows()[1][0]
iter_ = model.get_iter(path)
type_ = model[iter_][2]
if type_ != 'contact': # source is not a contact
if type_ != 'contact': # Source is not a contact
return
dropped_jid = data
......
......@@ -244,35 +244,48 @@ class ChatControlBase(MessageControl, ChatCommandProcessor, CommandTools):
# Init DND
self.TARGET_TYPE_URI_LIST = 80
self.dnd_list = [Gtk.TargetEntry.new('text/uri-list', 0,
self.TARGET_TYPE_URI_LIST), Gtk.TargetEntry.new('MY_TREE_MODEL_ROW',
Gtk.TargetFlags.SAME_APP, 0)]
uri_entry = Gtk.TargetEntry.new(
'text/uri-list',
Gtk.TargetFlags.OTHER_APP,
self.TARGET_TYPE_URI_LIST)
dst_targets = Gtk.TargetList.new([uri_entry])
dst_targets.add_text_targets(0)
self.dnd_list = [uri_entry,
Gtk.TargetEntry.new(
'MY_TREE_MODEL_ROW',
Gtk.TargetFlags.SAME_APP,
0)]
id_ = self.widget.connect('drag_data_received',
self._on_drag_data_received)
self._on_drag_data_received)
self.handlers[id_] = self.widget
self.widget.drag_dest_set(Gtk.DestDefaults.MOTION |
Gtk.DestDefaults.HIGHLIGHT | Gtk.DestDefaults.DROP,
self.dnd_list, Gdk.DragAction.COPY)
self.widget.drag_dest_set(
Gtk.DestDefaults.ALL,
self.dnd_list,
Gdk.DragAction.COPY)
self.widget.drag_dest_set_target_list(dst_targets)
# Create textviews and connect signals
self.conv_textview = ConversationTextview(self.account)
id_ = self.conv_textview.connect('quote', self.on_quote)
self.handlers[id_] = self.conv_textview.tv
id_ = self.conv_textview.tv.connect('key_press_event',
self._conv_textview_key_press_event)
id_ = self.conv_textview.tv.connect(
'key_press_event', self._conv_textview_key_press_event)
self.handlers[id_] = self.conv_textview.tv
# FIXME: DND on non editable TextView, find a better way
self.drag_entered = False
id_ = self.conv_textview.tv.connect('drag_data_received',
self._on_drag_data_received)
self._on_drag_data_received)
self.handlers[id_] = self.conv_textview.tv
id_ = self.conv_textview.tv.connect('drag_motion', self._on_drag_motion)
self.handlers[id_] = self.conv_textview.tv
id_ = self.conv_textview.tv.connect('drag_leave', self._on_drag_leave)
self.handlers[id_] = self.conv_textview.tv
self.conv_textview.tv.drag_dest_set(Gtk.DestDefaults.MOTION |
Gtk.DestDefaults.HIGHLIGHT | Gtk.DestDefaults.DROP,
self.dnd_list, Gdk.DragAction.COPY)
self.conv_textview.tv.drag_dest_set(
Gtk.DestDefaults.ALL,
self.dnd_list,
Gdk.DragAction.COPY)
self.conv_textview.tv.drag_dest_set_target_list(dst_targets)
self.conv_scrolledwindow = self.xml.get_object(
'conversation_scrolledwindow')
......@@ -307,12 +320,15 @@ class ChatControlBase(MessageControl, ChatCommandProcessor, CommandTools):
id_ = self.msg_textview.connect('populate_popup',
self.on_msg_textview_populate_popup)
self.handlers[id_] = self.msg_textview
# Setup DND
id_ = self.msg_textview.connect('drag_data_received',
self._on_drag_data_received)
self._on_drag_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)
self.msg_textview.drag_dest_set(
Gtk.DestDefaults.ALL,
self.dnd_list,
Gdk.DragAction.COPY)
self._overlay = self.xml.get_object('overlay')
......
......@@ -2420,27 +2420,26 @@ class GroupchatControl(ChatControlBase):
if not selection.get_data():
return
# get contact info
# Get contact info
contact = contacts.Contact(jid=self.room_jid, account=self.account)
if target_type == self.TARGET_TYPE_URI_LIST:
# file drag and drop (handled in chat_control_base)
# File drag and drop (handled in chat_control_base)
self.drag_data_file_transfer(contact, selection, self)
else:
# Invite contact to groupchat
treeview = app.interface.roster.tree
model = treeview.get_model()
data = selection.get_data()
data = selection.get_data().decode()
path = treeview.get_selection().get_selected_rows()[1][0]
iter_ = model.get_iter(path)
type_ = model[iter_][2]
if type_ != 'contact': # source is not a contact
if type_ != 'contact': # Source is not a contact
return
contact_jid = data
con = app.connections[self.account]
con.get_module('MUC').invite(self.room_jid, contact_jid)
self.add_info_message(_('%(jid)s has been invited in this room') %
self.add_info_message(_('%(jid)s has been invited to this group chat') %
{'jid': contact_jid})
def _jid_not_blocked(self, bare_jid: str) -> bool:
......
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