Daniel Brötzmann pushed to branch master at gajim / gajim
Commits:
-
a1dacac5
by wurstsalat at 2022-06-16T14:43:59+02:00
-
61fae3de
by wurstsalat at 2022-06-16T15:13:17+02:00
4 changed files:
- gajim/common/preview.py
- gajim/common/preview_helpers.py
- gajim/gtk/notification_manager.py
- gajim/gtk/preview.py
Changes:
| ... | ... | @@ -150,6 +150,7 @@ def orig_exists(self) -> bool: |
| 150 | 150 | def create_thumbnail(self, data: bytes) -> bool:
|
| 151 | 151 | self.thumbnail = create_thumbnail(data, self.size)
|
| 152 | 152 | if self.thumbnail is None:
|
| 153 | + self.info_message = _('Creating thumbnail failed')
|
|
| 153 | 154 | log.warning('Creating thumbnail failed for: %s', self.orig_path)
|
| 154 | 155 | return False
|
| 155 | 156 | return True
|
| ... | ... | @@ -342,8 +343,7 @@ def _on_orig_load_finished(self, |
| 342 | 343 | preview.thumbnail,
|
| 343 | 344 | self._on_thumb_write_finished,
|
| 344 | 345 | preview)
|
| 345 | - else:
|
|
| 346 | - preview.update_widget()
|
|
| 346 | + preview.update_widget()
|
|
| 347 | 347 | |
| 348 | 348 | @staticmethod
|
| 349 | 349 | def _on_thumb_load_finished(data: Optional[bytes],
|
| ... | ... | @@ -426,7 +426,7 @@ def _on_content_sniffed(self, |
| 426 | 426 | return
|
| 427 | 427 | |
| 428 | 428 | if file_size == 0:
|
| 429 | - log.info('File size is unknown (zero) for URL: \'%s\'', uri)
|
|
| 429 | + log.info('File size is unknown (zero) for URL: \'%s\'', uri)
|
|
| 430 | 430 | session.cancel_message(message, Soup.Status.CANCELLED)
|
| 431 | 431 | return
|
| 432 | 432 | |
| ... | ... | @@ -434,7 +434,9 @@ def _on_content_sniffed(self, |
| 434 | 434 | log.info(
|
| 435 | 435 | 'File size (%s) too big for URL: \'%s\'',
|
| 436 | 436 | file_size, uri)
|
| 437 | - if not force:
|
|
| 437 | + if force:
|
|
| 438 | + preview.info_message = None
|
|
| 439 | + else:
|
|
| 438 | 440 | session.cancel_message(message, Soup.Status.CANCELLED)
|
| 439 | 441 | preview.info_message = _('Automatic preview disabled '
|
| 440 | 442 | '(file too big)')
|
| ... | ... | @@ -463,6 +465,8 @@ def _on_finished(self, |
| 463 | 465 | preview.update_widget()
|
| 464 | 466 | return
|
| 465 | 467 | |
| 468 | + preview.info_message = None
|
|
| 469 | + |
|
| 466 | 470 | data = message.props.response_body_data.get_data()
|
| 467 | 471 | if data is None:
|
| 468 | 472 | return
|
| ... | ... | @@ -486,6 +490,8 @@ def _on_finished(self, |
| 486 | 490 | preview.thumbnail,
|
| 487 | 491 | self._on_thumb_write_finished,
|
| 488 | 492 | preview)
|
| 493 | + else:
|
|
| 494 | + preview.update_widget()
|
|
| 489 | 495 | |
| 490 | 496 | @staticmethod
|
| 491 | 497 | def _on_orig_write_finished(_result: bool,
|
| ... | ... | @@ -146,7 +146,7 @@ def extract_and_resize_frames(image: Image.Image, |
| 146 | 146 | return frames, result
|
| 147 | 147 | |
| 148 | 148 | |
| 149 | -def create_thumbnail(data: bytes, size:int) -> Optional[bytes]:
|
|
| 149 | +def create_thumbnail(data: bytes, size: int) -> Optional[bytes]:
|
|
| 150 | 150 | thumbnail = create_thumbnail_with_pil(data, size)
|
| 151 | 151 | if thumbnail is not None:
|
| 152 | 152 | return thumbnail
|
| ... | ... | @@ -191,7 +191,7 @@ def create_thumbnail_with_pil(data: bytes, size: int) -> Optional[bytes]: |
| 191 | 191 | output_file = BytesIO()
|
| 192 | 192 | try:
|
| 193 | 193 | image = Image.open(input_file)
|
| 194 | - except OSError as error:
|
|
| 194 | + except Exception as error:
|
|
| 195 | 195 | log.warning('making pil thumbnail failed: %s', error)
|
| 196 | 196 | log.warning('fallback to pixbuf')
|
| 197 | 197 | input_file.close()
|
| ... | ... | @@ -236,21 +236,23 @@ def add_invitation_received(self, event: MucInvitation) -> None: |
| 236 | 236 | self.add(new_row)
|
| 237 | 237 | self.update_unread_count()
|
| 238 | 238 | |
| 239 | - if get_muc_context(event.muc) == 'public':
|
|
| 240 | - jid = event.from_
|
|
| 239 | + jid = event.from_.bare
|
|
| 240 | + muc_context = get_muc_context(event.muc)
|
|
| 241 | + if (muc_context == 'private' and
|
|
| 242 | + not event.muc.bare_match(event.from_)):
|
|
| 243 | + contact = self._client.get_module('Contacts').get_contact(jid)
|
|
| 244 | + text = _('%(contact)s invited you to %(chat)s') % {
|
|
| 245 | + 'contact': contact.name,
|
|
| 246 | + 'chat': event.info.muc_name}
|
|
| 241 | 247 | else:
|
| 242 | - jid = event.from_.bare
|
|
| 243 | - contact = self._client.get_module('Contacts').get_contact(jid)
|
|
| 244 | - text = _('%(contact)s invited you to %(chat)s') % {
|
|
| 245 | - 'contact': contact.name,
|
|
| 246 | - 'chat': event.info.muc_name}
|
|
| 248 | + text = _('You have been invited to %s') % event.info.muc_name
|
|
| 247 | 249 | |
| 248 | 250 | app.ged.raise_event(
|
| 249 | 251 | Notification(account=self._account,
|
| 250 | - jid=jid,
|
|
| 251 | - type='group-chat-invitation',
|
|
| 252 | - title=_('Group Chat Invitation'),
|
|
| 253 | - text=text))
|
|
| 252 | + jid=jid,
|
|
| 253 | + type='group-chat-invitation',
|
|
| 254 | + title=_('Group Chat Invitation'),
|
|
| 255 | + text=text))
|
|
| 254 | 256 | |
| 255 | 257 | def add_invitation_declined(self, event: MucDecline) -> None:
|
| 256 | 258 | row = self._get_notification_row(str(event.muc))
|
| ... | ... | @@ -394,10 +396,7 @@ def __init__(self, account: str, event: MucInvitation) -> None: |
| 394 | 396 | |
| 395 | 397 | self._event = event
|
| 396 | 398 | |
| 397 | - if get_muc_context(event.muc) == 'public':
|
|
| 398 | - jid = event.from_
|
|
| 399 | - else:
|
|
| 400 | - jid = event.from_.bare
|
|
| 399 | + jid = event.from_.bare
|
|
| 401 | 400 | image = self._generate_avatar_image(jid)
|
| 402 | 401 | self.grid.attach(image, 1, 1, 1, 2)
|
| 403 | 402 | |
| ... | ... | @@ -406,10 +405,16 @@ def __init__(self, account: str, event: MucInvitation) -> None: |
| 406 | 405 | title_label.get_style_context().add_class('bold')
|
| 407 | 406 | self.grid.attach(title_label, 2, 1, 1, 1)
|
| 408 | 407 | |
| 409 | - contact = self._client.get_module('Contacts').get_contact(jid)
|
|
| 410 | - invitation_text = _('%(contact)s invited you to %(chat)s') % {
|
|
| 411 | - 'contact': contact.name,
|
|
| 412 | - 'chat': event.info.muc_name}
|
|
| 408 | + muc_context = get_muc_context(event.muc)
|
|
| 409 | + if (muc_context == 'private' and
|
|
| 410 | + not event.muc.bare_match(event.from_)):
|
|
| 411 | + contact = self._client.get_module('Contacts').get_contact(jid)
|
|
| 412 | + invitation_text = _('%(contact)s invited you to %(chat)s') % {
|
|
| 413 | + 'contact': contact.name,
|
|
| 414 | + 'chat': event.info.muc_name}
|
|
| 415 | + else:
|
|
| 416 | + invitation_text = _('You have been invited '
|
|
| 417 | + 'to %s') % event.info.muc_name
|
|
| 413 | 418 | text_label = self._generate_label()
|
| 414 | 419 | text_label.set_text(invitation_text)
|
| 415 | 420 | text_label.set_tooltip_text(invitation_text)
|
| ... | ... | @@ -142,6 +142,11 @@ def update(self, preview: Preview, data: Optional[GdkPixbufType]) -> None: |
| 142 | 142 | label.set_ellipsize(Pango.EllipsizeMode.END)
|
| 143 | 143 | label.set_max_width_chars(32)
|
| 144 | 144 | |
| 145 | + if preview.info_message is not None:
|
|
| 146 | + self._ui.info_message.set_text(preview.info_message)
|
|
| 147 | + self._ui.info_message.set_tooltip_text(preview.info_message)
|
|
| 148 | + self._ui.info_message.show()
|
|
| 149 | + |
|
| 145 | 150 | if preview.orig_exists():
|
| 146 | 151 | self._ui.download_button.hide()
|
| 147 | 152 | self._ui.open_folder_button.show()
|
| ... | ... | @@ -155,11 +160,6 @@ def update(self, preview: Preview, data: Optional[GdkPixbufType]) -> None: |
| 155 | 160 | self._ui.right_box.pack_end(audio_widget, False, True, 0)
|
| 156 | 161 | self._ui.right_box.reorder_child(audio_widget, 1)
|
| 157 | 162 | else:
|
| 158 | - if preview.info_message is not None:
|
|
| 159 | - self._ui.info_message.set_text(preview.info_message)
|
|
| 160 | - self._ui.info_message.set_tooltip_text(preview.info_message)
|
|
| 161 | - self._ui.info_message.show()
|
|
| 162 | - |
|
| 163 | 163 | if preview.file_size == 0:
|
| 164 | 164 | self._ui.download_button.hide()
|
| 165 | 165 | self._ui.link_button.show()
|