~didrocks/ubuntuone-client/use_result_var

« back to all changes in this revision

Viewing changes to ubuntuone/syncdaemon/status_listener.py

  • Committer: Bazaar Package Importer
  • Author(s): Rodney Dawes
  • Date: 2011-02-11 16:18:11 UTC
  • mto: This revision was merged to the branch mainline in revision 67.
  • Revision ID: james.westby@ubuntu.com-20110211161811-n18dj9lde7dxqjzr
Tags: upstream-1.5.4
ImportĀ upstreamĀ versionĀ 1.5.4

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
# with this program.  If not, see <http://www.gnu.org/licenses/>.
18
18
"""Listener for event queue that updates the UI to show syncdaemon status."""
19
19
 
20
 
from ubuntuone.status.aggregator import StatusAggregator
 
20
from ubuntuone.status.aggregator import StatusFrontend
 
21
from ubuntuone.syncdaemon import action_queue
21
22
 
22
23
def should_start_listener():
23
24
    """Check if the status listener should be started."""
27
28
def get_listener(fsm, vm):
28
29
    """Return an instance of the status listener, or None if turned off."""
29
30
    if should_start_listener():
30
 
        aggregator = StatusAggregator()
31
 
        return StatusListener(fsm, vm, aggregator)
 
31
        status_frontend = StatusFrontend()
 
32
        return StatusListener(fsm, vm, status_frontend)
32
33
    else:
33
34
        return None
34
35
 
 
36
#TODO: hookup the shutdown of the listener to the cleanup in the aggregator
35
37
class StatusListener(object):
36
38
    """SD listener for EQ events that turns them into status updates."""
37
39
 
38
 
    def __init__(self, fsm, vm, aggregator):
 
40
    def __init__(self, fsm, vm, status_frontend):
39
41
        """Initialize this instance with the FSM and VM."""
40
42
        self.fsm = fsm
41
43
        self.vm = vm
42
 
        self.aggregator = aggregator
 
44
        self.status_frontend = status_frontend
43
45
 
44
46
    def handle_AQ_CHANGE_PUBLIC_ACCESS_OK(self, share_id, node_id, is_public,
45
47
                                                  public_url):
46
48
        """The status of a published resource changed."""
47
49
        if is_public:
48
 
            self.aggregator.file_published(public_url)
49
 
        else:
50
 
            self.aggregator.file_unpublished(public_url)
 
50
            self.status_frontend.file_published(public_url)
 
51
        else:
 
52
            self.status_frontend.file_unpublished(public_url)
 
53
 
 
54
    def handle_SYS_QUEUE_ADDED(self, command):
 
55
        """A command has been added to the queue."""
 
56
        if isinstance(command, action_queue.Download):
 
57
            self.status_frontend.download_started(command)
 
58
        elif isinstance(command, action_queue.Upload):
 
59
            self.status_frontend.upload_started(command)
 
60
        else:
 
61
            self.status_frontend.queue_added(command)
 
62
 
 
63
    def handle_SYS_QUEUE_REMOVED(self, command):
 
64
        """A command has been removed from the queue."""
 
65
        if isinstance(command, action_queue.Download):
 
66
            self.status_frontend.download_finished(command)
 
67
        elif isinstance(command, action_queue.Upload):
 
68
            self.status_frontend.upload_finished(command)
 
69
        else:
 
70
            self.status_frontend.queue_removed(command)
 
71
 
 
72
    def handle_SYS_QUEUE_DONE(self):
 
73
        """The queue has finished processing everything."""
 
74
        self.status_frontend.queue_done()
 
75
 
 
76
    def handle_VM_SHARE_CREATED(self, share_id):
 
77
        """A new share is available for subscription."""
 
78
        share = self.vm.get_volume(share_id)
 
79
        self.status_frontend.new_share_available(share)
 
80
 
 
81
    def handle_VM_UDF_CREATED(self, udf):
 
82
        """A new udf is available for subscription."""
 
83
        self.status_frontend.new_udf_available(udf)
 
84
 
 
85
    def handle_SYS_CONNECTION_LOST(self):
 
86
        """The client lost the connection to the server."""
 
87
        self.status_frontend.server_connection_lost()
 
88
 
 
89
    def handle_SYS_CONNECTION_MADE(self):
 
90
        """The client connected to the server."""
 
91
        self.status_frontend.server_connection_made()