~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-01-25 16:42:52 UTC
  • mfrom: (1.1.43 upstream)
  • Revision ID: james.westby@ubuntu.com-20110125164252-gyx1hii7jk1b3hw7
Tags: 1.5.3-0ubuntu1
* New upstream release.
  - Metadata load is too slow (LP: #436612)
  - Out of space dialog is broken (LP: #650671)
  - Should not autoconnect when there are no credentials (LP: #701588)
  - gsd extension should not ask for sso credentials (LP: #702171) 

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# ubuntuone.syncdaemon.status_listener
 
2
#
 
3
# Author: Alejandro J. Cura <alecu@canonical.com>
 
4
#
 
5
# Copyright 2011 Canonical Ltd.
 
6
#
 
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.
 
10
#
 
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.
 
15
#
 
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."""
 
19
 
 
20
from ubuntuone.status.aggregator import StatusAggregator
 
21
 
 
22
def should_start_listener():
 
23
    """Check if the status listener should be started."""
 
24
    # TODO: look this up in some configuration object
 
25
    return True
 
26
 
 
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)
 
32
    else:
 
33
        return None
 
34
 
 
35
class StatusListener(object):
 
36
    """SD listener for EQ events that turns them into status updates."""
 
37
 
 
38
    def __init__(self, fsm, vm, aggregator):
 
39
        """Initialize this instance with the FSM and VM."""
 
40
        self.fsm = fsm
 
41
        self.vm = vm
 
42
        self.aggregator = aggregator
 
43
 
 
44
    def handle_AQ_CHANGE_PUBLIC_ACCESS_OK(self, share_id, node_id, is_public,
 
45
                                                  public_url):
 
46
        """The status of a published resource changed."""
 
47
        if is_public:
 
48
            self.aggregator.file_published(public_url)
 
49
        else:
 
50
            self.aggregator.file_unpublished(public_url)