comparison cagou/core/share_widget.py @ 383:a90f26e89a4a

share widget: fixed crash when a text content is shared without `text` in data: sometimes, text content is shared via a path and not directly the `text` key. This is the case with vCards. This patch fixes share widget to handle this case.
author Goffi <goffi@goffi.org>
date Tue, 04 Feb 2020 20:47:17 +0100
parents 4d660b252487
children 415de998b91d
comparison
equal deleted inserted replaced
382:c7f1176cd2a9 383:a90f26e89a4a
100 data = DictProperty() 100 data = DictProperty()
101 preview_box = ObjectProperty() 101 preview_box = ObjectProperty()
102 102
103 def on_kv_post(self, wid): 103 def on_kv_post(self, wid):
104 self.type, self.subtype = self.media_type.split('/') 104 self.type, self.subtype = self.media_type.split('/')
105 if self.type == 'text': 105 if self.type == 'text' and 'text' in self.data:
106 self.preview_box.add_widget(TextPreview(text=self.data['text'])) 106 self.preview_box.add_widget(TextPreview(text=self.data['text']))
107 elif self.type == 'image': 107 elif self.type == 'image':
108 self.preview_box.add_widget(ImagePreview(path=self.data['path'])) 108 self.preview_box.add_widget(ImagePreview(path=self.data['path']))
109 else: 109 else:
110 self.preview_box.add_widget(GenericPreview(path=self.data['path'])) 110 self.preview_box.add_widget(GenericPreview(path=self.data['path']))
124 124
125 def filterDataCb(self, data, contact_jid, profile): 125 def filterDataCb(self, data, contact_jid, profile):
126 G.host.doAction('chat', contact_jid, [profile]) 126 G.host.doAction('chat', contact_jid, [profile])
127 chat_wid = G.host.selected_widget 127 chat_wid = G.host.selected_widget
128 128
129 if self.type == 'text': 129 if self.type == 'text' and 'text' in self.data:
130 text = self.data['text'] 130 text = self.data['text']
131 chat_wid.message_input.text += text 131 chat_wid.message_input.text += text
132 else: 132 else:
133 path = self.data['path'] 133 path = self.data['path']
134 chat_wid.transferFile(path, cleaning_cb=data.get('cleaning_cb')) 134 chat_wid.transferFile(path, cleaning_cb=data.get('cleaning_cb'))