Daniel Brötzmann pushed to branch master at gajim / gajim

Commits:

3 changed files:

Changes:

  • gajim/common/preview.py
    ... ... @@ -61,11 +61,14 @@ def __init__(self,
    61 61
                      orig_path: Optional[Path],
    
    62 62
                      thumb_path: Optional[Path],
    
    63 63
                      size: int,
    
    64
    -                 widget: Any) -> None:
    
    64
    +                 widget: Any,
    
    65
    +                 context: Optional[str] = None
    
    66
    +                 ) -> None:
    
    65 67
             self._uri = uri
    
    66 68
             self._urlparts = urlparts
    
    67 69
             self._filename = filename_from_uri(uri)
    
    68 70
             self._widget = widget
    
    71
    +        self._context = context
    
    69 72
     
    
    70 73
             self.account = widget.account
    
    71 74
             self.orig_path = orig_path
    
    ... ... @@ -102,6 +105,10 @@ def is_audio(self) -> bool:
    102 105
         def uri(self) -> str:
    
    103 106
             return self._uri
    
    104 107
     
    
    108
    +    @property
    
    109
    +    def context(self) -> Optional[str]:
    
    110
    +        return self._context
    
    111
    +
    
    105 112
         @property
    
    106 113
         def filename(self) -> str:
    
    107 114
             return self._filename
    
    ... ... @@ -240,13 +247,17 @@ def is_previewable(self,
    240 247
     
    
    241 248
             return True
    
    242 249
     
    
    243
    -    def create_preview(self, uri: str, widget: Any, context: str) -> None:
    
    250
    +    def create_preview(self,
    
    251
    +                       uri: str,
    
    252
    +                       widget: Any,
    
    253
    +                       context: Optional[str] = None
    
    254
    +                       ) -> None:
    
    244 255
             if uri.startswith('geo:'):
    
    245 256
                 preview = Preview(uri, None, None, None, 96, widget)
    
    246 257
                 preview.update_widget()
    
    247 258
                 return
    
    248 259
     
    
    249
    -        preview = self._process_web_uri(uri, widget)
    
    260
    +        preview = self._process_web_uri(uri, widget, context)
    
    250 261
     
    
    251 262
             if not preview.orig_exists():
    
    252 263
                 if context is not None:
    
    ... ... @@ -267,7 +278,11 @@ def create_preview(self, uri: str, widget: Any, context: str) -> None:
    267 278
                                 self._on_thumb_load_finished,
    
    268 279
                                 preview)
    
    269 280
     
    
    270
    -    def _process_web_uri(self, uri: str, widget: Any) -> Preview:
    
    281
    +    def _process_web_uri(self,
    
    282
    +                         uri: str,
    
    283
    +                         widget: Any,
    
    284
    +                         context: Optional[str] = None
    
    285
    +                         ) -> Preview:
    
    271 286
             urlparts = urlparse(uri)
    
    272 287
             size = app.settings.get('preview_size')
    
    273 288
             orig_path, thumb_path = get_image_paths(uri,
    
    ... ... @@ -280,7 +295,8 @@ def _process_web_uri(self, uri: str, widget: Any) -> Preview:
    280 295
                            orig_path,
    
    281 296
                            thumb_path,
    
    282 297
                            size,
    
    283
    -                       widget)
    
    298
    +                       widget,
    
    299
    +                       context=context)
    
    284 300
     
    
    285 301
         def _on_orig_load_finished(self,
    
    286 302
                                    data: Optional[bytes],
    

  • gajim/data/gui/preview.ui
    ... ... @@ -55,7 +55,6 @@
    55 55
                     <signal name="realize" handler="_on_realize" swapped="no"/>
    
    56 56
                     <child>
    
    57 57
                       <object class="GtkButton" id="download_button">
    
    58
    -                    <property name="visible">True</property>
    
    59 58
                         <property name="can-focus">True</property>
    
    60 59
                         <property name="receives-default">False</property>
    
    61 60
                         <property name="no-show-all">True</property>
    
    ... ... @@ -91,7 +90,6 @@
    91 90
                     <signal name="realize" handler="_on_realize" swapped="no"/>
    
    92 91
                     <child>
    
    93 92
                       <object class="GtkButton" id="save_as_button">
    
    94
    -                    <property name="visible">True</property>
    
    95 93
                         <property name="can-focus">True</property>
    
    96 94
                         <property name="receives-default">False</property>
    
    97 95
                         <property name="no-show-all">True</property>
    
    ... ... @@ -126,7 +124,6 @@
    126 124
                     <signal name="realize" handler="_on_realize" swapped="no"/>
    
    127 125
                     <child>
    
    128 126
                       <object class="GtkButton" id="open_folder_button">
    
    129
    -                    <property name="visible">True</property>
    
    130 127
                         <property name="can-focus">True</property>
    
    131 128
                         <property name="receives-default">False</property>
    
    132 129
                         <property name="no-show-all">True</property>
    

  • gajim/gtk/preview.py
    ... ... @@ -114,6 +114,11 @@ def update(self, preview: Preview, data: Optional[GdkPixbufType]) -> None:
    114 114
                 self._ui.icon_event_box.show()
    
    115 115
                 image.set_property('pixel-size', 64)
    
    116 116
     
    
    117
    +        file_size_string = _('File size unknown')
    
    118
    +        if preview.file_size != 0:
    
    119
    +            file_size_string = GLib.format_size_full(
    
    120
    +                preview.file_size, self._units)
    
    121
    +
    
    117 122
             if preview.orig_exists():
    
    118 123
                 self._ui.download_button.hide()
    
    119 124
                 self._ui.open_folder_button.show()
    
    ... ... @@ -126,19 +131,21 @@ def update(self, preview: Preview, data: Optional[GdkPixbufType]) -> None:
    126 131
                     self._ui.right_box.pack_end(audio_widget, False, True, 0)
    
    127 132
                     self._ui.right_box.reorder_child(audio_widget, 1)
    
    128 133
             else:
    
    134
    +            self._ui.download_button.show()
    
    129 135
                 self._ui.save_as_button.hide()
    
    130 136
                 self._ui.open_folder_button.hide()
    
    137
    +            allow_in_public = app.settings.get('preview_anonymous_muc')
    
    138
    +            if preview.context == 'public' and not allow_in_public:
    
    139
    +                image = Gtk.Image.new_from_icon_name(
    
    140
    +                    'dialog-question', Gtk.IconSize.DIALOG)
    
    141
    +                self._ui.icon_button.set_image(image)
    
    142
    +                file_size_string = _('Automatic preview disabled')
    
    131 143
     
    
    132
    -        file_size_string = _('File size unknown')
    
    133
    -        if preview.file_size != 0:
    
    134
    -            file_size_string = GLib.format_size_full(
    
    135
    -                preview.file_size, self._units)
    
    136 144
             self._ui.file_size.set_text(file_size_string)
    
    137
    -
    
    138 145
             self._ui.file_name.set_text(preview.filename)
    
    139 146
             self._ui.file_name.set_tooltip_text(preview.filename)
    
    140 147
     
    
    141
    -    def _get_context_menu(self):
    
    148
    +    def _get_context_menu(self) -> Gtk.Menu:
    
    142 149
             def _destroy(menu, _pspec):
    
    143 150
                 visible = menu.get_property('visible')
    
    144 151
                 if not visible:
    
    ... ... @@ -167,12 +174,17 @@ def _destroy(menu, _pspec):
    167 174
     
    
    168 175
             return menu.context_menu
    
    169 176
     
    
    170
    -    def _on_download(self, _menu):
    
    177
    +    def _on_download(self, _menu: Gtk.Menu) -> None:
    
    178
    +        if self._preview is None:
    
    179
    +            return
    
    171 180
             if not self._preview.orig_exists():
    
    172 181
                 app.interface.preview_manager.download_content(
    
    173 182
                     self._preview, force=True)
    
    174 183
     
    
    175
    -    def _on_open(self, _menu):
    
    184
    +    def _on_open(self, _menu: Gtk.Menu) -> None:
    
    185
    +        if self._preview is None:
    
    186
    +            return
    
    187
    +
    
    176 188
             if self._preview.is_geo_uri:
    
    177 189
                 open_uri(self._preview.uri)
    
    178 190
                 return
    
    ... ... @@ -184,7 +196,7 @@ def _on_open(self, _menu):
    184 196
     
    
    185 197
             open_file(self._preview.orig_path)
    
    186 198
     
    
    187
    -    def _on_save_as(self, _menu):
    
    199
    +    def _on_save_as(self, _menu: Gtk.Menu) -> None:
    
    188 200
             def _on_ok(target_path):
    
    189 201
                 dirname = Path(target_path).parent
    
    190 202
                 if not os.access(dirname, os.W_OK):
    
    ... ... @@ -206,18 +218,18 @@ def _on_ok(target_path):
    206 218
                            file_name=self._preview.filename,
    
    207 219
                            transient_for=app.app.get_active_window())
    
    208 220
     
    
    209
    -    def _on_open_folder(self, _menu):
    
    221
    +    def _on_open_folder(self, _menu: Gtk.Menu) -> None:
    
    210 222
             if not self._preview.orig_exists():
    
    211 223
                 app.interface.preview_manager.download_content(
    
    212 224
                     self._preview, force=True)
    
    213 225
                 return
    
    214 226
             open_file(self._preview.orig_path.parent)
    
    215 227
     
    
    216
    -    def _on_copy_link_location(self, _menu):
    
    228
    +    def _on_copy_link_location(self, _menu: Gtk.Menu) -> None:
    
    217 229
             clipboard = Gtk.Clipboard.get_default(Gdk.Display.get_default())
    
    218 230
             clipboard.set_text(self._preview.uri, -1)
    
    219 231
     
    
    220
    -    def _on_open_link_in_browser(self, _menu):
    
    232
    +    def _on_open_link_in_browser(self, _menu: Gtk.Menu) -> None:
    
    221 233
             if self._preview.is_aes_encrypted:
    
    222 234
                 if self._preview.is_geo_uri:
    
    223 235
                     open_uri(self._preview.uri)
    
    ... ... @@ -226,17 +238,20 @@ def _on_open_link_in_browser(self, _menu):
    226 238
             else:
    
    227 239
                 open_uri(self._preview.uri)
    
    228 240
     
    
    229
    -    def _on_content_button_clicked(self, _button):
    
    241
    +    def _on_content_button_clicked(self, _button: Gtk.Button) -> None:
    
    230 242
             action = app.settings.get('preview_leftclick_action')
    
    231 243
             method = getattr(self, f'_on_{action}')
    
    232 244
             method(None)
    
    233 245
     
    
    234
    -    def _on_button_press_event(self, _button, event):
    
    246
    +    def _on_button_press_event(self,
    
    247
    +                               _button: Gtk.Button,
    
    248
    +                               event: Gdk.EventButton
    
    249
    +                               ) -> None:
    
    235 250
             if event.type == Gdk.EventType.BUTTON_PRESS and event.button == 3:
    
    236 251
                 # Right click
    
    237 252
                 menu = self._get_context_menu()
    
    238 253
                 menu.popup_at_pointer(event)
    
    239 254
     
    
    240 255
         @staticmethod
    
    241
    -    def _on_realize(event_box):
    
    256
    +    def _on_realize(event_box: Gtk.EventBox) -> None:
    
    242 257
             event_box.get_window().set_cursor(get_cursor('pointer'))