Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/services/clipboard/ClipboardService.py
blob: 35ac3a24e01a3e031f8433b592cc484da4a64fb9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# 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

_CLIPBOARD_SERVICE = "org.laptop.Clipboard"
_CLIPBOARD_DBUS_INTERFACE = "org.laptop.Clipboard"
_CLIPBOARD_OBJECT_PATH = "/org/laptop/Clipboard"

class ClipboardDBusServiceHelper(dbus.service.Object):
	def __init__(self, parent):
		self._parent = parent

		bus = dbus.SessionBus()
		bus_name = dbus.service.BusName(_CLIPBOARD_DBUS_INTERFACE, bus=bus)
		dbus.service.Object.__init__(self, bus_name, _CLIPBOARD_OBJECT_PATH)
		
	@dbus.service.method(_CLIPBOARD_DBUS_INTERFACE,
						 in_signature="ss", out_signature="")
	def add_object(self, mimeType, fileName):
		logging.debug('Added object of type ' + mimeType + ' with path at ' + fileName)
		self.object_added(mimeType, fileName)

	@dbus.service.method(_CLIPBOARD_DBUS_INTERFACE,
						 in_signature="s", out_signature="")
	def delete_object(self, fileName):
		logging.debug('Deleted object with path at ' + fileName)
		self.object_deleted(fileName)

	@dbus.service.method(_CLIPBOARD_DBUS_INTERFACE,
						 in_signature="si", out_signature="")
	def update_object_state(self, fileName, percent):
		logging.debug('Updated object with path at ' + fileName + ' with percent ' + str(percent))
		self.object_state_updated(fileName, percent)

	@dbus.service.signal(_CLIPBOARD_DBUS_INTERFACE, signature="ss")
	def object_added(self, 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_updated(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...'