Ticket #3903: 0001-Port-visual-representation-of-clipboard-to-Gtk3-SL-3.patch

File 0001-Port-visual-representation-of-clipboard-to-Gtk3-SL-3.patch, 8.7 KB (added by godiard, 11 years ago)
  • src/jarabe/frame/clipboard.py

    From f5565f396405219246d1fa62f8ce6a3ae78a9b12 Mon Sep 17 00:00:00 2001
    From: Gonzalo Odiard <godiard@gmail.com>
    Date: Fri, 9 Nov 2012 15:31:50 -0300
    Subject: [PATCH] Port visual representation of clipboard to Gtk3 - SL #3903
    
    There are several changes in the gtk+ clipboard api,
    this patch solve the problems related with the visual representation,
    and depends on [1] solved in gtk+.
    
    Signed-off-by: Gonzalo Odiard <gonzalo@laptop.org>
    
    [1] https://bugzilla.gnome.org/show_bug.cgi?id=687942
    ---
     src/jarabe/frame/clipboard.py            |  3 ++-
     src/jarabe/frame/clipboardicon.py        |  5 ++--
     src/jarabe/frame/clipboardobject.py      |  3 +--
     src/jarabe/frame/clipboardpanelwindow.py | 44 ++++++++++++++++++--------------
     src/jarabe/frame/notification.py         |  2 +-
     src/jarabe/journal/palettes.py           |  3 ++-
     6 files changed, 34 insertions(+), 26 deletions(-)
    
    diff --git a/src/jarabe/frame/clipboard.py b/src/jarabe/frame/clipboard.py
    index 493a9ce..7305360 100644
    a b import tempfile 
    2222
    2323from gi.repository import GObject
    2424from gi.repository import Gtk
     25from gi.repository import Gdk
    2526
    2627from sugar3 import mime
    2728
    class Clipboard(GObject.GObject): 
    99100        cb_object = self._objects.pop(object_id)
    100101        cb_object.destroy()
    101102        if not self._objects:
    102             gtk_clipboard = Gtk.Clipboard()
     103            gtk_clipboard = Gtk.Clipboard.get(Gdk.SELECTION_CLIPBOARD)
    103104            gtk_clipboard.clear()
    104105        self.emit('object-deleted', object_id)
    105106        logging.debug('Deleted object with object_id %r', object_id)
  • src/jarabe/frame/clipboardicon.py

    diff --git a/src/jarabe/frame/clipboardicon.py b/src/jarabe/frame/clipboardicon.py
    index 81b3131..b3fdccc 100644
    a b class ClipboardIcon(RadioToolButton): 
    8989
    9090        targets = self._get_targets()
    9191        if targets:
    92             x_clipboard = Gtk.Clipboard()
     92            x_clipboard = Gtk.Clipboard.get(Gdk.SELECTION_CLIPBOARD)
    9393            if not x_clipboard.set_with_data(targets,
    9494                                           self._clipboard_data_get_cb,
    9595                                           self._clipboard_clear_cb,
    class ClipboardIcon(RadioToolButton): 
    170170    def _get_targets(self):
    171171        targets = []
    172172        for format_type in self._cb_object.get_formats().keys():
    173             targets.append((format_type, 0, 0))
     173            targets.append(Gtk.TargetEntry.new(format_type,
     174                    Gtk.TargetFlags.SAME_APP, 0))
    174175        return targets
  • src/jarabe/frame/clipboardobject.py

    diff --git a/src/jarabe/frame/clipboardobject.py b/src/jarabe/frame/clipboardobject.py
    index a91c672..e79fa46 100644
    a b class ClipboardObject(object): 
    8383        if not self._formats:
    8484            return False
    8585        else:
    86             return self._formats.keys()[0] in [ActivityBundle.MIME_TYPE,
    87                     ActivityBundle.DEPRECATED_MIME_TYPE]
     86            return self._formats.keys()[0] == ActivityBundle.MIME_TYPE
    8887
    8988    def get_percent(self):
    9089        return self._percent
  • src/jarabe/frame/clipboardpanelwindow.py

    diff --git a/src/jarabe/frame/clipboardpanelwindow.py b/src/jarabe/frame/clipboardpanelwindow.py
    index fed6ba1..80264c9 100644
    a b from urlparse import urlparse 
    1919import hashlib
    2020
    2121from gi.repository import Gtk
     22from gi.repository import Gdk
    2223
    2324from jarabe.frame.framewindow import FrameWindow
    2425from jarabe.frame.clipboardtray import ClipboardTray
    class ClipboardPanelWindow(FrameWindow): 
    3536        # Listening for new clipboard objects
    3637        # NOTE: we need to keep a reference to Gtk.Clipboard in order to keep
    3738        # listening to it.
    38         self._clipboard = Gtk.Clipboard()
     39        self._clipboard = Gtk.Clipboard.get(Gdk.SELECTION_CLIPBOARD)
    3940        self._clipboard.connect('owner-change', self._owner_change_cb)
    4041
    4142        self._clipboard_tray = ClipboardTray()
    class ClipboardPanelWindow(FrameWindow): 
    5859
    5960        cb_service = clipboard.get_instance()
    6061
    61         targets = x_clipboard.wait_for_targets()
     62        targets_names = x_clipboard.wait_for_targets_names()
     63        logging.error('targets %s ', targets_names)
     64
    6265        cb_selections = []
    63         if targets is None:
     66        if not targets_names:
    6467            return
    6568
    6669        target_is_uri = False
    67         for target in targets:
    68             if target not in ('TIMESTAMP', 'TARGETS',
     70        for target_name in targets_names:
     71            if target_name not in ('TIMESTAMP', 'TARGETS',
    6972                              'MULTIPLE', 'SAVE_TARGETS'):
    70                 logging.debug('Asking for target %s.', target)
    71                 if target == 'text/uri-list':
     73                logging.debug('Asking for target %s.', target_name)
     74                if target_name == 'text/uri-list':
    7275                    target_is_uri = True
    73 
    74                 selection = x_clipboard.wait_for_contents(target)
     76                target_atom = Gdk.Atom.intern(target_name, False)
     77                selection = x_clipboard.wait_for_contents(target_atom)
    7578                if not selection:
    76                     logging.warning('no data for selection target %s.', target)
     79                    logging.warning('no data for selection target %s.',
     80                            target_name)
    7781                    continue
    7882                cb_selections.append(selection)
    7983
    8084        if target_is_uri:
    81             uri = selection.data
     85            uri = selection.get_data()
    8286            filename = uri[len('file://'):].strip()
    8387            md5 = self._md5_for_file(filename)
    8488            data_hash = hash(md5)
    8589        else:
    86             data_hash = hash(selection.data)
     90            data_hash = hash(selection.get_data())
    8791
    8892        if len(cb_selections) > 0:
    8993            key = cb_service.add_object(name="", data_hash=data_hash)
    class ClipboardPanelWindow(FrameWindow): 
    111115        return md5.digest()
    112116
    113117    def _add_selection(self, key, selection):
    114         if not selection.data:
    115             logging.warning('no data for selection target %s.', selection.type)
     118        if not selection.get_data():
     119            logging.warning('no data for selection target %s.',
     120                    selection.get_data_type())
    116121            return
    117122
    118         logging.debug('adding type ' + selection.type + '.')
     123        selection_type = selection.get_data_type().name()
     124        logging.debug('adding type ' + selection_type + '.')
    119125
    120126        cb_service = clipboard.get_instance()
    121         if selection.type == 'text/uri-list':
     127        if selection_type == 'text/uri-list':
    122128            uris = selection.get_uris()
    123129
    124130            if len(uris) > 1:
    class ClipboardPanelWindow(FrameWindow): 
    130136            on_disk = (scheme == 'file')
    131137
    132138            cb_service.add_object_format(key,
    133                                          selection.type,
     139                                         selection_type,
    134140                                         uri,
    135141                                         on_disk)
    136142        else:
    137143            cb_service.add_object_format(key,
    138                                          selection.type,
    139                                          selection.data,
     144                                         selection_type,
     145                                         selection.get_data(),
    140146                                         on_disk=False)
  • src/jarabe/frame/notification.py

    diff --git a/src/jarabe/frame/notification.py b/src/jarabe/frame/notification.py
    index 184a779..f63964f 100644
    a b class NotificationWindow(Gtk.Window): 
    9797
    9898    def _realize_cb(self, widget):
    9999        self.set_type_hint(Gdk.WindowTypeHint.DIALOG)
    100         self.window.set_accept_focus(False)
     100        self.get_window().set_accept_focus(False)
    101101
    102102        color = Gdk.color_parse(style.COLOR_TOOLBAR_GREY.get_html())
    103103        self.modify_bg(Gtk.StateType.NORMAL, color)
  • src/jarabe/journal/palettes.py

    diff --git a/src/jarabe/journal/palettes.py b/src/jarabe/journal/palettes.py
    index 43f9905..f624c78 100644
    a b import os 
    2020
    2121from gi.repository import GObject
    2222from gi.repository import Gtk
     23from gi.repository import Gdk
    2324from gi.repository import GConf
    2425from gi.repository import Gio
    2526import glib
    class ClipboardMenu(MenuItem): 
    299300                      _('Warning'))
    300301            return
    301302
    302         clipboard = Gtk.Clipboard()
     303        clipboard = Gtk.Clipboard.get(Gdk.SELECTION_CLIPBOARD)
    303304        clipboard.set_with_data([('text/uri-list', 0, 0)],
    304305                                self.__clipboard_get_func_cb,
    305306                                self.__clipboard_clear_func_cb)