diff options
author | Tomeu Vizoso <tomeu@tomeuvizoso.net> | 2006-12-13 21:36:05 (GMT) |
---|---|---|
committer | Tomeu Vizoso <tomeu@tomeuvizoso.net> | 2006-12-13 21:36:05 (GMT) |
commit | e68f0e00e95416c696ecc08895b1a29463c989f8 (patch) | |
tree | e6f9b82880efecf155c1281bb3bdf95502e388af /services | |
parent | 474313ffdebb066e8e6891cfc362aa2edf3cf5c3 (diff) |
Added c&v and dnd support to the clipboard.
Diffstat (limited to 'services')
-rw-r--r-- | services/clipboard/ClipboardService.py | 76 | ||||
-rw-r--r-- | services/clipboard/Makefile.am | 4 | ||||
-rw-r--r-- | services/clipboard/clipboardobject.py | 38 | ||||
-rw-r--r-- | services/clipboard/clipboardservice.py | 119 | ||||
-rwxr-xr-x | services/clipboard/sugar-clipboard | 2 |
5 files changed, 161 insertions, 78 deletions
diff --git a/services/clipboard/ClipboardService.py b/services/clipboard/ClipboardService.py deleted file mode 100644 index d8a151d..0000000 --- a/services/clipboard/ClipboardService.py +++ /dev/null @@ -1,76 +0,0 @@ -# vi: ts=4 ai noet -# -# Copyright (C) 2006, Red Hat, Inc. -# -# 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 - -import logging -import gobject -import dbus -import dbus.service -from sugar import env - -class ClipboardDBusServiceHelper(dbus.service.Object): - - _CLIPBOARD_DBUS_INTERFACE = "org.laptop.Clipboard" - _CLIPBOARD_OBJECT_PATH = "/org/laptop/Clipboard" - - def __init__(self, parent): - self._parent = parent - - bus = dbus.SessionBus() - bus_name = dbus.service.BusName(self._CLIPBOARD_DBUS_INTERFACE, bus=bus) - dbus.service.Object.__init__(self, bus_name, self._CLIPBOARD_OBJECT_PATH) - - @dbus.service.method(_CLIPBOARD_DBUS_INTERFACE, - in_signature="sss", out_signature="") - def add_object(self, name, mimeType, fileName): - self.object_added(name, mimeType, fileName) - logging.debug('Added object of type ' + mimeType + ' with path at ' + fileName) - - @dbus.service.method(_CLIPBOARD_DBUS_INTERFACE, - in_signature="s", out_signature="") - def delete_object(self, fileName): - self.object_deleted(fileName) - logging.debug('Deleted object with path at ' + fileName) - - @dbus.service.method(_CLIPBOARD_DBUS_INTERFACE, - in_signature="si", out_signature="") - def set_object_state(self, fileName, percent): - logging.debug('Changed object with path at ' + fileName + ' with percent ' + str(percent)) - self.object_state_changed(fileName, percent) - - @dbus.service.signal(_CLIPBOARD_DBUS_INTERFACE, signature="sss") - def object_added(self, name, mimeType, fileName): - pass - - @dbus.service.signal(_CLIPBOARD_DBUS_INTERFACE, signature="s") - def object_deleted(self, fileName): - pass - - @dbus.service.signal(_CLIPBOARD_DBUS_INTERFACE, signature="si") - def object_state_changed(self, fileName, percent): - pass - -class ClipboardService(object): - def __init__(self): - self._dbus_helper = ClipboardDBusServiceHelper(self) - - def run(self): - loop = gobject.MainLoop() - try: - loop.run() - except KeyboardInterrupt: - print 'Ctrl+C pressed, exiting...' diff --git a/services/clipboard/Makefile.am b/services/clipboard/Makefile.am index 4f4d8a3..130a33c 100644 --- a/services/clipboard/Makefile.am +++ b/services/clipboard/Makefile.am @@ -8,7 +8,9 @@ $(service_DATA): $(service_in_files) Makefile sugardir = $(pkgdatadir)/services/clipboard sugar_PYTHON = \ __init__.py \ - ClipboardService.py + clipboardobject.py \ + clipboardservice.py + bin_SCRIPTS = sugar-clipboard diff --git a/services/clipboard/clipboardobject.py b/services/clipboard/clipboardobject.py new file mode 100644 index 0000000..fd15363 --- /dev/null +++ b/services/clipboard/clipboardobject.py @@ -0,0 +1,38 @@ +class ClipboardObject: + + def __init__(self, id, name): + self._id = id + self._name = name + self._percent = 0 + self._formats = {} + + def get_id(self): + return self._id + + def get_name(self): + return self._name + + def get_percent(self): + return self._percent + + def set_percent(self, percent): + self._percent = percent + + def add_format(self, format): + self._formats[format.get_type()] = format + + def get_formats(self): + return self._formats + +class Format: + + def __init__(self, type, data, on_disk): + self._type = type + self._data = data + self._on_disk = on_disk + + def get_type(self): + return self._type + + def get_data(self): + return self._data diff --git a/services/clipboard/clipboardservice.py b/services/clipboard/clipboardservice.py new file mode 100644 index 0000000..02ee7ac --- /dev/null +++ b/services/clipboard/clipboardservice.py @@ -0,0 +1,119 @@ +# Copyright (C) 2006, Red Hat, Inc. +# +# 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 + +import logging +import gobject +import dbus +import dbus.service +from sugar import env +from clipboardobject import ClipboardObject, Format + +class ClipboardDBusServiceHelper(dbus.service.Object): + + _CLIPBOARD_DBUS_INTERFACE = "org.laptop.Clipboard" + _CLIPBOARD_OBJECT_PATH = "/org/laptop/Clipboard" + + def __init__(self, parent): + self._parent = parent + self._objects = {} + + bus = dbus.SessionBus() + bus_name = dbus.service.BusName(self._CLIPBOARD_DBUS_INTERFACE, bus=bus) + dbus.service.Object.__init__(self, bus_name, self._CLIPBOARD_OBJECT_PATH) + + # dbus methods + @dbus.service.method(_CLIPBOARD_DBUS_INTERFACE, + in_signature="ss", out_signature="") + def add_object(self, object_id, name): + self._objects[object_id] = ClipboardObject(object_id, name) + self.object_added(object_id, name) + logging.debug('Added object ' + object_id + ' with name ' + name) + + @dbus.service.method(_CLIPBOARD_DBUS_INTERFACE, + in_signature="ssayb", out_signature="") + def add_object_format(self, object_id, format_type, data, on_disk): + + # FIXME: Take it out when using the 0.80 dbus bindings + s = "" + for i in data: + s += chr(i) + + cb_object = self._objects[object_id] + cb_object.add_format(Format(format_type, s, on_disk)) + + if on_disk: + logging.debug('Added format of type ' + format_type + ' with path at ' + s) + else: + logging.debug('Added in-memory format of type ' + format_type + '.') + + @dbus.service.method(_CLIPBOARD_DBUS_INTERFACE, + in_signature="s", out_signature="") + def delete_object(self, object_id): + del self._objects[object_id] + self.object_deleted(object_id) + logging.debug('Deleted object with object_id ' + object_id) + + @dbus.service.method(_CLIPBOARD_DBUS_INTERFACE, + in_signature="si", out_signature="") + def set_object_state(self, object_id, percent): + cb_object = self._objects[object_id] + cb_object.set_percent(percent) + self.object_state_changed(object_id, percent) + logging.debug('Changed object with object_id ' + object_id + ' with percent ' + str(percent)) + + @dbus.service.method(_CLIPBOARD_DBUS_INTERFACE, + in_signature="s", out_signature="as") + def get_object_format_types(self, object_id): + cb_object = self._objects[object_id] + formats = cb_object.get_formats() + array = [] + + for type, format in formats.iteritems(): + array.append(type) + + return array + + @dbus.service.method(_CLIPBOARD_DBUS_INTERFACE, + in_signature="ss", out_signature="ay") + def get_object_data(self, object_id, format_type): + cb_object = self._objects[object_id] + formats = cb_object.get_formats() + + return formats[format_type].get_data() + + # dbus signals + @dbus.service.signal(_CLIPBOARD_DBUS_INTERFACE, signature="ss") + def object_added(self, object_id, name): + pass + + @dbus.service.signal(_CLIPBOARD_DBUS_INTERFACE, signature="s") + def object_deleted(self, object_id): + pass + + @dbus.service.signal(_CLIPBOARD_DBUS_INTERFACE, signature="si") + def object_state_changed(self, object_id, percent): + pass + +class ClipboardService(object): + def __init__(self): + self._dbus_helper = ClipboardDBusServiceHelper(self) + + def run(self): + loop = gobject.MainLoop() + try: + loop.run() + except idboardInterrupt: + print 'Ctrl+C pressed, exiting...' diff --git a/services/clipboard/sugar-clipboard b/services/clipboard/sugar-clipboard index bcbd280..3f7ef9f 100755 --- a/services/clipboard/sugar-clipboard +++ b/services/clipboard/sugar-clipboard @@ -33,7 +33,7 @@ from sugar import env sys.path.insert(0, env.get_services_dir()) -from clipboard.ClipboardService import ClipboardService +from clipboard.clipboardservice import ClipboardService logging.info('Starting clipboard service.') |