2007-06-17 20:55:16 +02:00
|
|
|
# Copyright (C) 2007, One Laptop Per Child
|
|
|
|
#
|
|
|
|
# This program is free software; you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation; either version 2 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program; if not, write to the Free Software
|
|
|
|
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
2007-07-02 10:21:58 +02:00
|
|
|
|
2006-12-13 22:36:05 +01:00
|
|
|
import logging
|
2007-07-02 10:21:58 +02:00
|
|
|
|
2006-12-13 22:36:05 +01:00
|
|
|
import gtk
|
|
|
|
import hippo
|
|
|
|
|
2007-05-01 18:26:26 +02:00
|
|
|
from view.frame.framewindow import FrameWindow
|
2006-12-13 22:36:05 +01:00
|
|
|
from view.frame.clipboardbox import ClipboardBox
|
|
|
|
from sugar.clipboard import clipboardservice
|
|
|
|
from sugar import util
|
|
|
|
|
2007-05-01 18:26:26 +02:00
|
|
|
class ClipboardPanelWindow(FrameWindow):
|
2007-02-20 16:35:07 +01:00
|
|
|
def __init__(self, frame, orientation):
|
2007-05-01 18:26:26 +02:00
|
|
|
FrameWindow.__init__(self, orientation)
|
2006-12-13 22:36:05 +01:00
|
|
|
|
2006-12-16 23:55:22 +01:00
|
|
|
self._frame = frame
|
|
|
|
|
2006-12-13 22:36:05 +01:00
|
|
|
# Listening for new clipboard objects
|
2007-03-14 13:32:05 +01:00
|
|
|
# NOTE: we need to keep a reference to gtk.Clipboard in order to keep
|
|
|
|
# listening to it.
|
|
|
|
self._clipboard = gtk.Clipboard()
|
|
|
|
self._clipboard.connect("owner-change", self._owner_change_cb)
|
2006-12-13 22:36:05 +01:00
|
|
|
|
2007-07-01 12:55:10 +02:00
|
|
|
self._clipboard_box = ClipboardBox()
|
2007-08-31 14:53:59 +02:00
|
|
|
self.append(self._clipboard_box, hippo.PACK_EXPAND)
|
2006-12-13 22:36:05 +01:00
|
|
|
|
|
|
|
# Receiving dnd drops
|
|
|
|
self.drag_dest_set(0, [], 0)
|
2007-03-14 13:32:05 +01:00
|
|
|
self.connect("drag_motion", self._clipboard_box.drag_motion_cb)
|
|
|
|
self.connect("drag_drop", self._clipboard_box.drag_drop_cb)
|
|
|
|
self.connect("drag_data_received",
|
|
|
|
self._clipboard_box.drag_data_received_cb)
|
2006-12-13 22:36:05 +01:00
|
|
|
|
|
|
|
def _owner_change_cb(self, clipboard, event):
|
2007-06-07 13:07:25 +02:00
|
|
|
logging.debug("owner_change_cb")
|
|
|
|
|
2007-03-14 13:32:05 +01:00
|
|
|
if self._clipboard_box.owns_clipboard():
|
|
|
|
return
|
|
|
|
|
2006-12-13 22:36:05 +01:00
|
|
|
cb_service = clipboardservice.get_instance()
|
2007-03-14 05:50:06 +01:00
|
|
|
key = cb_service.add_object(name="")
|
2007-06-07 20:49:17 +02:00
|
|
|
cb_service.set_object_percent(key, percent=0)
|
2006-12-13 22:36:05 +01:00
|
|
|
|
|
|
|
targets = clipboard.wait_for_targets()
|
|
|
|
for target in targets:
|
2007-06-07 20:49:17 +02:00
|
|
|
if target not in ('TIMESTAMP', 'TARGETS', 'MULTIPLE', 'SAVE_TARGETS'):
|
2007-11-23 18:38:55 +01:00
|
|
|
logging.debug('Asking for target %s.' % target)
|
2006-12-13 22:36:05 +01:00
|
|
|
selection = clipboard.wait_for_contents(target)
|
2007-11-23 18:38:55 +01:00
|
|
|
if not selection:
|
|
|
|
logging.warning('no data for selection target %s.' % target)
|
|
|
|
continue
|
|
|
|
self._add_selection(key, selection)
|
2007-03-14 13:32:05 +01:00
|
|
|
|
|
|
|
cb_service.set_object_percent(key, percent=100)
|
|
|
|
|
2006-12-13 22:36:05 +01:00
|
|
|
def _add_selection(self, key, selection):
|
2007-11-23 18:38:55 +01:00
|
|
|
if not selection.data:
|
|
|
|
logging.warning('no data for selection target %s.' % selection.type)
|
|
|
|
return
|
|
|
|
|
|
|
|
logging.debug('adding type ' + selection.type + '.')
|
|
|
|
|
|
|
|
cb_service = clipboardservice.get_instance()
|
|
|
|
if selection.type == 'text/uri-list':
|
|
|
|
uris = selection.data.split('\n')
|
|
|
|
if len(uris) > 1:
|
|
|
|
raise NotImplementedError('Multiple uris in text/uri-list still not supported.')
|
2007-07-29 11:03:09 +02:00
|
|
|
|
2007-11-23 18:38:55 +01:00
|
|
|
cb_service.add_object_format(key,
|
|
|
|
selection.type,
|
|
|
|
uris[0],
|
|
|
|
on_disk=True)
|
|
|
|
else:
|
|
|
|
cb_service.add_object_format(key,
|
|
|
|
selection.type,
|
|
|
|
selection.data,
|
|
|
|
on_disk=False)
|
2007-07-29 11:03:09 +02:00
|
|
|
|