def __init__(self, clock=reactor): """Initialize this instance.""" self.aggregator = StatusAggregator(clock=clock) self.notification = self.aggregator.get_notification() self.messaging = Messaging() self.quota_timer = None
class StatusFrontend(object): """Frontend for the status aggregator, used by the StatusListener.""" def __init__(self, clock=reactor): """Initialize this instance.""" self.aggregator = StatusAggregator(clock=clock) self.notification = self.aggregator.get_notification() self.messaging = Messaging() self.quota_timer = None def file_published(self, public_url): """A file was published.""" status_event = FilePublishingStatus(new_public_url=public_url) self.notification.send_notification( UBUNTUONE_TITLE, status_event.one()) def file_unpublished(self, public_url): # pylint: disable=W0613 """A file was unpublished.""" self.notification.send_notification( UBUNTUONE_TITLE, FileUnpublishingStatus().one()) def download_started(self, command): """A file was queued for download.""" self.aggregator.download_started(command) def download_finished(self, command): """A file download was unqueued.""" self.aggregator.download_finished(command) def upload_started(self, command): """A file was queued for upload.""" self.aggregator.upload_started(command) def upload_finished(self, command): """A file upload was unqueued.""" self.aggregator.upload_finished(command) def progress_made(self, share_id, node_id, n_bytes, deflated_size): """Progress made on up- or download.""" self.aggregator.progress_made( share_id, node_id, n_bytes, deflated_size) def queue_done(self): """The queue is empty.""" self.aggregator.queue_done() def new_share_available(self, share): """A new share is available for subscription.""" self.messaging.show_message(share.other_visible_name) self.notification.send_notification( UBUNTUONE_TITLE, ShareAvailableStatus(share=share).one()) def new_udf_available(self, udf): """A new udf is available for subscription.""" if udf.subscribed: return self.notification.send_notification( UBUNTUONE_TITLE, UDFAvailableStatus(udf=udf).one()) def server_connection_lost(self): """The client lost the connection to the server.""" logger.debug("server connection lost") self.aggregator.connection_lost() def server_connection_made(self): """The client made the connection to the server.""" logger.debug("server connection made") self.aggregator.connection_made() def udf_quota_exceeded(self, volume_dict): """Quota exceeded in UDF.""" logger.debug("UDF quota exceeded for volume %r." % volume_dict) alert_user() def share_quota_exceeded(self, volume_dict): """Sharing user's quota exceeded in share.""" logger.debug("Share quota exceeded for volume %r." % volume_dict) if self.quota_timer is not None: if self.quota_timer.active: return else: self.quota_timer = Timer(ONE_DAY, clock=self.aggregator.clock) self.notification.send_notification( UBUNTUONE_TITLE, SHARE_QUOTA_EXCEEDED % ( volume_dict['path'], volume_dict['other_visible_name'])) alert_user() def root_quota_exceeded(self, volume_dict): """Quota exceeded in root.""" logger.debug("Root quota exceeded for volume %r." % volume_dict) alert_user() def set_show_all_notifications(self, value): """Set the flag to show all notifications.""" if value: self.aggregator.notification_switch.enable_notifications() else: self.aggregator.notification_switch.disable_notifications()