1
# ubuntuone.syncdaemon.status_listener
3
# Author: Alejandro J. Cura <alecu@canonical.com>
5
# Copyright 2011 Canonical Ltd.
7
# This program is free software: you can redistribute it and/or modify it
8
# under the terms of the GNU General Public License version 3, as published
9
# by the Free Software Foundation.
11
# This program is distributed in the hope that it will be useful, but
12
# WITHOUT ANY WARRANTY; without even the implied warranties of
13
# MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
14
# PURPOSE. See the GNU General Public License for more details.
16
# You should have received a copy of the GNU General Public License along
17
# with this program. If not, see <http://www.gnu.org/licenses/>.
18
"""Listener for event queue that updates the UI to show syncdaemon status."""
20
from ubuntuone.status.aggregator import StatusAggregator
22
def should_start_listener():
23
"""Check if the status listener should be started."""
24
# TODO: look this up in some configuration object
27
def get_listener(fsm, vm):
28
"""Return an instance of the status listener, or None if turned off."""
29
if should_start_listener():
30
aggregator = StatusAggregator()
31
return StatusListener(fsm, vm, aggregator)
35
class StatusListener(object):
36
"""SD listener for EQ events that turns them into status updates."""
38
def __init__(self, fsm, vm, aggregator):
39
"""Initialize this instance with the FSM and VM."""
42
self.aggregator = aggregator
44
def handle_AQ_CHANGE_PUBLIC_ACCESS_OK(self, share_id, node_id, is_public,
46
"""The status of a published resource changed."""
48
self.aggregator.file_published(public_url)
50
self.aggregator.file_unpublished(public_url)