12
12
# You should have received a copy of the GNU General Public License
13
13
# along with this program. If not, see <http://www.gnu.org/licenses/>.
15
16
import dbus.service
19
from . import constants
17
20
from libertine import utils
18
21
from time import time
20
DOWNLOAD_INTERFACE = "com.canonical.applications.Download"
21
PROGRESS_INTERFACE = "com.canonical.libertine.Service.Progress"
23
class Progress(dbus.service.Object):
24
def __init__(self, connection):
25
utils.get_logger().debug("creating a Progress object")
24
class Download(dbus.service.Object):
25
def __init__(self, connection, id):
26
26
self._finished = False
29
dbus.service.Object.__init__(self, conn=connection, object_path=("/Progress/%s" % hex(int(time()*10000000))[2:]))
31
# self.emit_processing() # Disabled until something requires the Download interface
35
return self._object_path
29
dbus.service.Object.__init__(self, conn=connection, object_path=(constants.DOWNLOAD_OBJECT % id))
31
# Disabled until something requires the Download interface
32
# self.emit_processing()
34
# This is currently how services using the Ubuntu SDK to show progress
35
# determine whether or not an operation is running.
37
36
def emit_processing(self):
39
38
self.processing(self.id)
40
39
threading.Timer(0.5, self.emit_processing).start()
43
return self._object_path
44
47
return self._finished
46
@dbus.service.signal(DOWNLOAD_INTERFACE)
51
return self._result.strip()
57
def data(self, message):
58
self._result += message + '\n'
60
# Signals to satisfy the download interface
62
@dbus.service.signal(constants.DOWNLOAD_INTERFACE, signature='o')
47
63
def processing(self, path):
48
64
utils.get_logger().debug("emit processing('%s')" % path)
50
@dbus.service.signal(DOWNLOAD_INTERFACE)
66
@dbus.service.signal(constants.DOWNLOAD_INTERFACE, signature='o')
51
67
def finished(self, path):
52
68
utils.get_logger().debug("emit finished('%s')" % path)
53
69
self._finished = True
55
@dbus.service.signal(DOWNLOAD_INTERFACE)
71
@dbus.service.signal(constants.DOWNLOAD_INTERFACE)
56
72
def progress(self, received, total):
57
73
utils.get_logger().debug("emit progress(%d, %d)" % (received, total))
59
@dbus.service.signal(DOWNLOAD_INTERFACE)
75
@dbus.service.signal(constants.DOWNLOAD_INTERFACE, signature='s')
60
76
def error(self, message):
61
77
utils.get_logger().error("emit error(%s)" % message)
62
78
self._error = message
63
79
self._finished = True
65
@dbus.service.signal(PROGRESS_INTERFACE)
66
def data(self, message):
67
utils.get_logger().debug("emit data(%s)" % message)
68
self._result.append(message)
70
@dbus.service.method(PROGRESS_INTERFACE, out_signature='b')
72
utils.get_logger().debug(not self.done)
75
@dbus.service.method(PROGRESS_INTERFACE, out_signature='s')
77
full_result = "\n".join(self._result)
78
utils.get_logger().debug(full_result)
81
@dbus.service.method(PROGRESS_INTERFACE, out_signature='s')
83
utils.get_logger().debug(self._error)