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 |
22 | 22 | |
23 | 23 | from gi.repository import GObject |
24 | 24 | from gi.repository import Gtk |
| 25 | from gi.repository import Gdk |
25 | 26 | |
26 | 27 | from sugar3 import mime |
27 | 28 | |
… |
… |
class Clipboard(GObject.GObject): |
99 | 100 | cb_object = self._objects.pop(object_id) |
100 | 101 | cb_object.destroy() |
101 | 102 | if not self._objects: |
102 | | gtk_clipboard = Gtk.Clipboard() |
| 103 | gtk_clipboard = Gtk.Clipboard.get(Gdk.SELECTION_CLIPBOARD) |
103 | 104 | gtk_clipboard.clear() |
104 | 105 | self.emit('object-deleted', object_id) |
105 | 106 | logging.debug('Deleted object with object_id %r', object_id) |
diff --git a/src/jarabe/frame/clipboardicon.py b/src/jarabe/frame/clipboardicon.py
index 81b3131..b3fdccc 100644
a
|
b
|
class ClipboardIcon(RadioToolButton): |
89 | 89 | |
90 | 90 | targets = self._get_targets() |
91 | 91 | if targets: |
92 | | x_clipboard = Gtk.Clipboard() |
| 92 | x_clipboard = Gtk.Clipboard.get(Gdk.SELECTION_CLIPBOARD) |
93 | 93 | if not x_clipboard.set_with_data(targets, |
94 | 94 | self._clipboard_data_get_cb, |
95 | 95 | self._clipboard_clear_cb, |
… |
… |
class ClipboardIcon(RadioToolButton): |
170 | 170 | def _get_targets(self): |
171 | 171 | targets = [] |
172 | 172 | 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)) |
174 | 175 | return targets |
diff --git a/src/jarabe/frame/clipboardobject.py b/src/jarabe/frame/clipboardobject.py
index a91c672..e79fa46 100644
a
|
b
|
class ClipboardObject(object): |
83 | 83 | if not self._formats: |
84 | 84 | return False |
85 | 85 | 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 |
88 | 87 | |
89 | 88 | def get_percent(self): |
90 | 89 | return self._percent |
diff --git a/src/jarabe/frame/clipboardpanelwindow.py b/src/jarabe/frame/clipboardpanelwindow.py
index fed6ba1..80264c9 100644
a
|
b
|
from urlparse import urlparse |
19 | 19 | import hashlib |
20 | 20 | |
21 | 21 | from gi.repository import Gtk |
| 22 | from gi.repository import Gdk |
22 | 23 | |
23 | 24 | from jarabe.frame.framewindow import FrameWindow |
24 | 25 | from jarabe.frame.clipboardtray import ClipboardTray |
… |
… |
class ClipboardPanelWindow(FrameWindow): |
35 | 36 | # Listening for new clipboard objects |
36 | 37 | # NOTE: we need to keep a reference to Gtk.Clipboard in order to keep |
37 | 38 | # listening to it. |
38 | | self._clipboard = Gtk.Clipboard() |
| 39 | self._clipboard = Gtk.Clipboard.get(Gdk.SELECTION_CLIPBOARD) |
39 | 40 | self._clipboard.connect('owner-change', self._owner_change_cb) |
40 | 41 | |
41 | 42 | self._clipboard_tray = ClipboardTray() |
… |
… |
class ClipboardPanelWindow(FrameWindow): |
58 | 59 | |
59 | 60 | cb_service = clipboard.get_instance() |
60 | 61 | |
61 | | targets = x_clipboard.wait_for_targets() |
| 62 | targets_names = x_clipboard.wait_for_targets_names() |
| 63 | logging.error('targets %s ', targets_names) |
| 64 | |
62 | 65 | cb_selections = [] |
63 | | if targets is None: |
| 66 | if not targets_names: |
64 | 67 | return |
65 | 68 | |
66 | 69 | 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', |
69 | 72 | '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': |
72 | 75 | 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) |
75 | 78 | 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) |
77 | 81 | continue |
78 | 82 | cb_selections.append(selection) |
79 | 83 | |
80 | 84 | if target_is_uri: |
81 | | uri = selection.data |
| 85 | uri = selection.get_data() |
82 | 86 | filename = uri[len('file://'):].strip() |
83 | 87 | md5 = self._md5_for_file(filename) |
84 | 88 | data_hash = hash(md5) |
85 | 89 | else: |
86 | | data_hash = hash(selection.data) |
| 90 | data_hash = hash(selection.get_data()) |
87 | 91 | |
88 | 92 | if len(cb_selections) > 0: |
89 | 93 | key = cb_service.add_object(name="", data_hash=data_hash) |
… |
… |
class ClipboardPanelWindow(FrameWindow): |
111 | 115 | return md5.digest() |
112 | 116 | |
113 | 117 | 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()) |
116 | 121 | return |
117 | 122 | |
118 | | logging.debug('adding type ' + selection.type + '.') |
| 123 | selection_type = selection.get_data_type().name() |
| 124 | logging.debug('adding type ' + selection_type + '.') |
119 | 125 | |
120 | 126 | cb_service = clipboard.get_instance() |
121 | | if selection.type == 'text/uri-list': |
| 127 | if selection_type == 'text/uri-list': |
122 | 128 | uris = selection.get_uris() |
123 | 129 | |
124 | 130 | if len(uris) > 1: |
… |
… |
class ClipboardPanelWindow(FrameWindow): |
130 | 136 | on_disk = (scheme == 'file') |
131 | 137 | |
132 | 138 | cb_service.add_object_format(key, |
133 | | selection.type, |
| 139 | selection_type, |
134 | 140 | uri, |
135 | 141 | on_disk) |
136 | 142 | else: |
137 | 143 | cb_service.add_object_format(key, |
138 | | selection.type, |
139 | | selection.data, |
| 144 | selection_type, |
| 145 | selection.get_data(), |
140 | 146 | on_disk=False) |
diff --git a/src/jarabe/frame/notification.py b/src/jarabe/frame/notification.py
index 184a779..f63964f 100644
a
|
b
|
class NotificationWindow(Gtk.Window): |
97 | 97 | |
98 | 98 | def _realize_cb(self, widget): |
99 | 99 | self.set_type_hint(Gdk.WindowTypeHint.DIALOG) |
100 | | self.window.set_accept_focus(False) |
| 100 | self.get_window().set_accept_focus(False) |
101 | 101 | |
102 | 102 | color = Gdk.color_parse(style.COLOR_TOOLBAR_GREY.get_html()) |
103 | 103 | self.modify_bg(Gtk.StateType.NORMAL, color) |
diff --git a/src/jarabe/journal/palettes.py b/src/jarabe/journal/palettes.py
index 43f9905..f624c78 100644
a
|
b
|
import os |
20 | 20 | |
21 | 21 | from gi.repository import GObject |
22 | 22 | from gi.repository import Gtk |
| 23 | from gi.repository import Gdk |
23 | 24 | from gi.repository import GConf |
24 | 25 | from gi.repository import Gio |
25 | 26 | import glib |
… |
… |
class ClipboardMenu(MenuItem): |
299 | 300 | _('Warning')) |
300 | 301 | return |
301 | 302 | |
302 | | clipboard = Gtk.Clipboard() |
| 303 | clipboard = Gtk.Clipboard.get(Gdk.SELECTION_CLIPBOARD) |
303 | 304 | clipboard.set_with_data([('text/uri-list', 0, 0)], |
304 | 305 | self.__clipboard_get_func_cb, |
305 | 306 | self.__clipboard_clear_func_cb) |