Ticket #3819: 0001-Bring-back-dragging-of-elements-from-the-activities-.2.patch

File 0001-Bring-back-dragging-of-elements-from-the-activities-.2.patch, 10.1 KB (added by manuq, 11 years ago)

Update: use get_uris() instead of splitting get_data()

  • src/jarabe/frame/clipboardmenu.py

    From 463ea7d4a69c27bc44d270226e3649fd64b54a24 Mon Sep 17 00:00:00 2001
    From: =?UTF-8?q?Manuel=20Qui=C3=B1ones?= <manuq@laptop.org>
    Date: Tue, 2 Apr 2013 22:56:05 -0300
    Subject: [PATCH] Bring back dragging of elements from the activities to the
     frame clipboard - SL #3819
    MIME-Version: 1.0
    Content-Type: text/plain; charset=UTF-8
    Content-Transfer-Encoding: 8bit
    Mail-Followup-To: <sugar-devel@lists.sugarlabs.org>
    
    TestCase:
    
    - open an activity like Browse, Read, Log (not Write, is a special case)
    - bring up the frame
    - drag things to the left side panel of the frame (images, links, or selected text)
    
    The elements should be added to the clipboard which is inside the
    panel.  They should have the proper icon and they should popup a
    palette to act on them.
    
    Note: if the dragged object is a link from Browse, Sugar tries to copy
    the html to the disk.  But the current implementation looks wrong.  I
    have opened #4477 to track it: http://bugs.sugarlabs.org/ticket/4477
    
    Note: this doesn't solve the inverse operation: drag from the
    clipboard to the activity.  This will be done in another patch.
    
    API fixes:
    
    - gtk.SelectionData.type  ->  Gtk.SelectionData.get_data_type() [1]
    - gtk.SelectionData.data  ->  Gtk.SelectionData.get_data() [2]
    - gtk.SelectionData.target  ->  Gtk.SelectionData.get_target() [3]
    - context.targets  ->  context.list_targets() [4]
    - context.drop_finish(...)  ->  Gdk.drop_finish(context, ...) [5]
    - context.drag_status(...)  ->  Gdk.drag_status(context, ...) [6]
    - context.get_source_widget()  ->  Gdk.drag_get_source_widget(context) [7]
    
    [1] https://developer.gnome.org/gtk3/3.5/gtk3-Selections.html#gtk-selection-data-get-data-type
    [2] https://developer.gnome.org/gtk3/3.5/gtk3-Selections.html#gtk-selection-data-get-data
    [3] https://developer.gnome.org/gtk3/3.5/gtk3-Selections.html#gtk-selection-data-get-target
    [4] https://developer.gnome.org/gdk/stable/gdk-Drag-and-Drop.html#gdk-drag-context-list-targets
    [5] https://developer.gnome.org/gdk/stable/gdk-Drag-and-Drop.html#gdk-drop-finish
    [6] https://developer.gnome.org/gdk/stable/gdk-Drag-and-Drop.html#gdk-drag-status
    [7] https://developer.gnome.org/gtk3/stable/gtk3-Drag-and-Drop.html#gtk-drag-get-source-widget
    
    Cast the type of the Gtk.SelectionData from Gdk.Atom to str.  Our code
    treats it as str in sugar3.mime and asks methods like startswith which
    fails if it is not a str-like object.
    
    The data for the type 'text/uri-list' comes with a character '\x00' at
    the end now.  But using SelectionData.get_uris() returns a proper list
    (thanks to Flavio Danesse for the recommendation).  So we can use that
    list instead of doing selection.get_data().split('\n') or
    sugar3.mime.split_uri_list (which could be obsolete now).  In fact,
    this change was made a while ago in clipboardpanelwindow.py, but not
    in clipboardtray.py.  See commit f0d194f3 .
    
    Signed-off-by: Manuel Quiñones <manuq@laptop.org>
    ---
     src/jarabe/frame/clipboardmenu.py        |  4 ++--
     src/jarabe/frame/clipboardobject.py      |  4 ++--
     src/jarabe/frame/clipboardpanelwindow.py |  2 +-
     src/jarabe/frame/clipboardtray.py        | 41 +++++++++++++++++++-------------
     4 files changed, 30 insertions(+), 21 deletions(-)
    
    diff --git a/src/jarabe/frame/clipboardmenu.py b/src/jarabe/frame/clipboardmenu.py
    index e6766fb..eef3861 100644
    a b class ClipboardMenu(Palette): 
    195195
    196196        transfer_ownership = False
    197197        if most_significant_mime_type == 'text/uri-list':
    198             uris = mime.split_uri_list(format_.get_data())
     198            uris = format_.get_uris()
    199199            if len(uris) == 1 and uris[0].startswith('file://'):
    200200                parsed_url = urlparse.urlparse(uris[0])
    201201                file_path = parsed_url.path  # pylint: disable=E1101
    class ClipboardMenu(Palette): 
    207207                mime_type = 'text/uri-list'
    208208        else:
    209209            if format_.is_on_disk():
    210                 parsed_url = urlparse.urlparse(format_.get_data())
     210                parsed_url = urlparse.urlparse(format_.get_uris()[0])
    211211                file_path = parsed_url.path  # pylint: disable=E1101
    212212                transfer_ownership = False
    213213                mime_type = mime.get_for_file(file_path)
  • src/jarabe/frame/clipboardobject.py

    diff --git a/src/jarabe/frame/clipboardobject.py b/src/jarabe/frame/clipboardobject.py
    index e79fa46..5a3c9fe 100644
    a b class ClipboardObject(object): 
    103103
    104104        format_ = mime.choose_most_significant(self._formats.keys())
    105105        if format_ == 'text/uri-list':
    106             data = self._formats['text/uri-list'].get_data()
    107             uri = urlparse.urlparse(mime.split_uri_list(data)[0], 'file')
     106            uris = self._formats[format_].get_uris()
     107            uri = urlparse.urlparse(uris[0], 'file')
    108108            scheme = uri.scheme  # pylint: disable=E1101
    109109            if scheme == 'file':
    110110                path = uri.path  # pylint: disable=E1101
  • src/jarabe/frame/clipboardpanelwindow.py

    diff --git a/src/jarabe/frame/clipboardpanelwindow.py b/src/jarabe/frame/clipboardpanelwindow.py
    index ba86775..14b5f5d 100644
    a b class ClipboardPanelWindow(FrameWindow): 
    7979                cb_selections.append(selection)
    8080
    8181        if target_is_uri:
    82             uri = selection.get_data()
     82            uri = selection.get_uris()[0]
    8383            filename = uri[len('file://'):].strip()
    8484            md5 = self._md5_for_file(filename)
    8585            data_hash = hash(md5)
  • src/jarabe/frame/clipboardtray.py

    diff --git a/src/jarabe/frame/clipboardtray.py b/src/jarabe/frame/clipboardtray.py
    index abc885e..280747d 100644
    a b class ClipboardTray(tray.VTray): 
    7676        return False
    7777
    7878    def _add_selection(self, object_id, selection):
    79         if not selection.data:
     79        if not selection.get_data():
    8080            return
    8181
    82         logging.debug('ClipboardTray: adding type %r', selection.type)
     82        selection_data = selection.get_data()
     83        selection_type = selection.get_data_type()
     84
     85        # The type comes as a Gdk.Atom but we need it as str to
     86        # compare it.
     87        assert isinstance(selection_type, Gdk.Atom)
     88        selection_type = str(selection_type)
     89
     90        logging.debug('ClipboardTray: adding type %r', selection_type)
    8391
    8492        cb_service = clipboard.get_instance()
    85         if selection.type == 'text/uri-list':
    86             uris = selection.data.split('\n')
     93        if selection_type == 'text/uri-list':
     94            uris = selection.get_uris()
    8795            if len(uris) > 1:
    8896                raise NotImplementedError('Multiple uris in text/uri-list' \
    8997                                          ' still not supported.')
    9098
    9199            cb_service.add_object_format(object_id,
    92                                          selection.type,
     100                                         selection_type,
    93101                                         uris[0],
    94102                                         on_disk=True)
    95103        else:
    96104            cb_service.add_object_format(object_id,
    97                                          selection.type,
    98                                          selection.data,
     105                                         selection_type,
     106                                         selection_data,
    99107                                         on_disk=False)
    100108
    101109    def _object_added_cb(self, cb_service, cb_object):
    class ClipboardTray(tray.VTray): 
    132140        logging.debug('ClipboardTray._drag_motion_cb')
    133141
    134142        if self._internal_drag(context):
    135             context.drag_status(Gdk.DragAction.MOVE, time)
     143            Gdk.drag_status(context, Gdk.DragAction.MOVE, time)
    136144        else:
    137             context.drag_status(Gdk.DragAction.COPY, time)
     145            Gdk.drag_status(context, Gdk.DragAction.COPY, time)
    138146            self.props.drag_active = True
    139147
    140148        return True
    class ClipboardTray(tray.VTray): 
    148156        if self._internal_drag(context):
    149157            # TODO: We should move the object within the clipboard here
    150158            if not self._context_map.has_context(context):
    151                 context.drop_finish(False, Gtk.get_current_event_time())
     159                Gdk.drop_finish(context, False, Gtk.get_current_event_time())
    152160            return False
    153161
    154162        cb_service = clipboard.get_instance()
    155163        object_id = cb_service.add_object(name="")
    156164
    157         self._context_map.add_context(context, object_id, len(context.targets))
     165        context_targets = context.list_targets()
     166        self._context_map.add_context(context, object_id, len(context_targets))
    158167
    159         for target in context.targets:
     168        for target in context_targets:
    160169            if str(target) not in ('TIMESTAMP', 'TARGETS', 'MULTIPLE'):
    161170                widget.drag_get_data(context, target, time)
    162171
    class ClipboardTray(tray.VTray): 
    167176    def drag_data_received_cb(self, widget, context, x, y, selection,
    168177                              targetType, time):
    169178        logging.debug('ClipboardTray: got data for target %r',
    170             selection.target)
     179            selection.get_target())
    171180
    172181        object_id = self._context_map.get_object_id(context)
    173182        try:
    174183            if selection is None:
    175184                logging.warn('ClipboardTray: empty selection for target %s',
    176                     selection.target)
     185                    selection.get_target())
    177186            else:
    178187                self._add_selection(object_id, selection)
    179188
    class ClipboardTray(tray.VTray): 
    181190            # If it's the last target to be processed, finish
    182191            # the dnd transaction
    183192            if not self._context_map.has_context(context):
    184                 context.drop_finish(True, Gtk.get_current_event_time())
     193                Gdk.drop_finish(context, True, Gtk.get_current_event_time())
    185194
    186195    def _internal_drag(self, context):
    187         source_widget = context.get_source_widget()
     196        source_widget = Gtk.drag_get_source_widget(context)
    188197        if source_widget is None:
    189198            return False
    190199        view_ancestor = source_widget.get_ancestor(Gtk.Viewport)