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


Commits:
c154b03d by wurstsalat at 2024-07-31T20:48:04+02:00
refactor: Use constants for drag and drop target mime types

- - - - -


4 changed files:

- gajim/gtk/avatar_selector.py
- gajim/gtk/chat_stack.py
- gajim/gtk/const.py
- gajim/gtk/file_transfer_selector.py


Changes:

=====================================
gajim/gtk/avatar_selector.py
=====================================
@@ -27,6 +27,8 @@
 from gajim.common.image_helpers import scale_with_ratio
 
 from gajim.gtk import types
+from gajim.gtk.const import DND_TARGET_FLATPAK
+from gajim.gtk.const import DND_TARGET_URI_LIST
 from gajim.gtk.const import TARGET_TYPE_URI_LIST
 from gajim.gtk.dialogs import ErrorDialog
 from gajim.gtk.filechoosers import AvatarChooserDialog
@@ -64,9 +66,9 @@ def __init__(self) -> None:
         self.get_style_context().add_class('avatar-selector')
 
         if app.is_flatpak():
-            target = 'application/vnd.portal.files'
+            target = DND_TARGET_FLATPAK
         else:
-            target = 'text/uri-list'
+            target = DND_TARGET_URI_LIST
 
         uri_entry = Gtk.TargetEntry.new(
             target, Gtk.TargetFlags.OTHER_APP, TARGET_TYPE_URI_LIST)


=====================================
gajim/gtk/chat_stack.py
=====================================
@@ -39,6 +39,8 @@
 from gajim.gtk.chat_banner import ChatBanner
 from gajim.gtk.chat_function_page import ChatFunctionPage
 from gajim.gtk.chat_function_page import FunctionMode
+from gajim.gtk.const import DND_TARGET_FLATPAK
+from gajim.gtk.const import DND_TARGET_URI_LIST
 from gajim.gtk.const import TARGET_TYPE_URI_LIST
 from gajim.gtk.control import ChatControl
 from gajim.gtk.dialogs import ErrorDialog
@@ -117,9 +119,9 @@ def __init__(self):
         overlay.connect('drag-leave', self._on_drag_leave)
 
         if app.is_flatpak():
-            target = 'application/vnd.portal.files'
+            target = DND_TARGET_FLATPAK
         else:
-            target = 'text/uri-list'
+            target = DND_TARGET_URI_LIST
 
         uri_entry = Gtk.TargetEntry.new(
             target,
@@ -772,7 +774,7 @@ def _on_drag_motion(self,
             return False
 
         for targ in context.list_targets():
-            if targ.name() in {'text/uri-list', 
'application/vnd.portal.files'}:
+            if targ.name() in {DND_TARGET_URI_LIST, DND_TARGET_FLATPAK}:
                 self._drop_area.set_no_show_all(False)
                 self._drop_area.show_all()
                 return True


=====================================
gajim/gtk/const.py
=====================================
@@ -45,6 +45,9 @@ class Setting(NamedTuple):
 # Drag and drop target type URI list (for dropped files)
 TARGET_TYPE_URI_LIST = 80
 
+DND_TARGET_URI_LIST = 'text/uri-list'
+DND_TARGET_FLATPAK = 'application/vnd.portal.filetransfer'
+
 MAX_MESSAGE_LENGTH = 5000
 
 


=====================================
gajim/gtk/file_transfer_selector.py
=====================================
@@ -30,6 +30,8 @@
 from gajim.common.preview_helpers import guess_mime_type
 
 from gajim.gtk.builder import get_builder
+from gajim.gtk.const import DND_TARGET_FLATPAK
+from gajim.gtk.const import DND_TARGET_URI_LIST
 from gajim.gtk.const import TARGET_TYPE_URI_LIST
 from gajim.gtk.filechoosers import FileChooserDialog
 from gajim.gtk.resource_selector import ResourceSelector
@@ -81,9 +83,9 @@ def __init__(self,
                   'files to.') % self._contact.name)
 
         if app.is_flatpak():
-            target = 'application/vnd.portal.filetransfer'
+            target = DND_TARGET_FLATPAK
         else:
-            target = 'text/uri-list'
+            target = DND_TARGET_URI_LIST
 
         uri_entry = Gtk.TargetEntry.new(
             target, Gtk.TargetFlags.OTHER_APP, TARGET_TYPE_URI_LIST)



View it on GitLab: 
https://dev.gajim.org/gajim/gajim/-/commit/c154b03d8e752013611851d97292ff61b38f1995

-- 
View it on GitLab: 
https://dev.gajim.org/gajim/gajim/-/commit/c154b03d8e752013611851d97292ff61b38f1995
You're receiving this email because of your account on dev.gajim.org.


_______________________________________________
Commits mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to