From f9af7ecbe0e976b17fa7c902d9811622d64974e3 Mon Sep 17 00:00:00 2001
From: Gonzalo Odiard <godiard@gmail.com>
Date: Wed, 14 Mar 2012 18:18:33 -0300
Subject: [PATCH] Only add one time every object in the clipboard
Signed-off-by: Gonzalo Odiard <gonzalo@laptop.org>
---
src/jarabe/frame/clipboard.py | 14 ++++++++++----
src/jarabe/frame/clipboardpanelwindow.py | 6 +++++-
2 files changed, 15 insertions(+), 5 deletions(-)
diff --git a/src/jarabe/frame/clipboard.py b/src/jarabe/frame/clipboard.py
index be2b902..3351146 100644
a
|
b
|
class Clipboard(gobject.GObject): |
36 | 36 | 'object-added': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE, |
37 | 37 | ([object])), |
38 | 38 | 'object-deleted': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE, |
39 | | ([int])), |
| 39 | ([long])), |
40 | 40 | 'object-state-changed': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE, |
41 | 41 | ([object])), |
42 | 42 | } |
… |
… |
class Clipboard(gobject.GObject): |
51 | 51 | self._next_id += 1 |
52 | 52 | return self._next_id |
53 | 53 | |
54 | | def add_object(self, name): |
55 | | logging.debug('Clipboard.add_object') |
56 | | object_id = self._get_next_object_id() |
| 54 | def add_object(self, name, data_hash=None): |
| 55 | logging.debug('Clipboard.add_object hash %s', data_hash) |
| 56 | if data_hash is None: |
| 57 | object_id = self._get_next_object_id() |
| 58 | else: |
| 59 | object_id = data_hash |
| 60 | if object_id in self._objects: |
| 61 | logging.debug('Object rejected, already exist') |
| 62 | return None |
57 | 63 | self._objects[object_id] = ClipboardObject(object_id, name) |
58 | 64 | self.emit('object-added', self._objects[object_id]) |
59 | 65 | return object_id |
diff --git a/src/jarabe/frame/clipboardpanelwindow.py b/src/jarabe/frame/clipboardpanelwindow.py
index b73572e..595e23f 100644
a
|
b
|
class ClipboardPanelWindow(FrameWindow): |
70 | 70 | cb_selections.append(selection) |
71 | 71 | |
72 | 72 | if len(cb_selections) > 0: |
73 | | key = cb_service.add_object(name="") |
| 73 | key = cb_service.add_object(name="", |
| 74 | data_hash=hash(selection.data)) |
| 75 | if key is None: |
| 76 | return |
| 77 | logging.error('key %s', key) |
74 | 78 | cb_service.set_object_percent(key, percent=0) |
75 | 79 | for selection in cb_selections: |
76 | 80 | self._add_selection(key, selection) |