From 208a68e451635883d0c6f58e56c8308bafe8b16c Mon Sep 17 00:00:00 2001 From: Walter Bender Date: Sun, 09 Jun 2013 22:06:54 +0000 Subject: refactoring based on lasted commits upstream --- (limited to 'src/jarabe/web/account.py') diff --git a/src/jarabe/web/account.py b/src/jarabe/web/account.py index 2e55f25..c089cbc 100644 --- a/src/jarabe/web/account.py +++ b/src/jarabe/web/account.py @@ -1,4 +1,5 @@ # Copyright (c) 2013 Walter Bender, Raul Gutierrez Segales +# Copyright (c) 2013 SugarLabs # # This library is free software; you can redistribute it and/or # modify it under the terms of the GNU Lesser General Public @@ -15,19 +16,18 @@ # Free Software Foundation, Inc., 59 Temple Place - Suite 330, # Boston, MA 02111-1307, USA. -import logging - from gi.repository import GObject -from sugar3.graphics.menuitem import MenuItem -from sugar3.graphics.toolbutton import ToolButton - class Account(): ''' Account is a prototype class for online accounts. It provides - stubs for five public methods that are used by online services + stubs for public methods that are used by online services. ''' + STATE_NONE = 0 + STATE_VALID = 1 + STATE_EXPIRED = 2 + def get_description(self): ''' get_description returns a brief description of the online service. The description is used in palette menuitems and on @@ -38,25 +38,49 @@ class Account(): ''' raise NotImplementedError - def is_configured(self): - ''' is_configured returns True if the service has been - configured for use, e.g., an access token has been acquired. - - :returns: configuration status - :rtype: bool + def get_token_state(self): + ''' get_token_state returns an enum to describe the state of + the online service: + State.NONE means there is no token, e.g., the service is not + configured. + State.VALID means there is a valid token, e.g., the service is + available for use. + State.EXPIRED means the token is no longer valid. + + :returns: token state + :rtype: enum ''' raise NotImplementedError - def is_active(self): - ''' is_active returns True if the service is currently - available, e.g., the access token has not expired. + def get_shared_journal_entry(self): + ''' get_shared_journal_entry returns a class used to + intermediate between the online service and the Sugar UI + elements. - :returns: active status - :rtype: bool + :returns: SharedJournalEntry() + :rtype: SharedJournalEntry ''' - raise NotImplementedError + return NotImplemented + - def get_share_menu(self): +class SharedJournalEntry(): + ''' SharedJournalEntry is a class used to intermediate between the + online service and the Sugar UI elements (MenuItems used in the + Journal UI) for online accounts. It provides stubs for public + methods that are used by online services. + + The comments-changed signal is emitted by the online service if + changes to the 'comments' metadata have been made. + + :emits: metadata['comments'] + :type: string + ''' + + __gsignals__ = { + 'comments-changed': (GObject.SignalFlags.RUN_FIRST, None, ([str])) + } + + def get_share_menu(self, metadata): ''' get_share_menu returns a menu item used on the Copy To palette in the Journal and on the Journal detail-view toolbar. @@ -71,67 +95,11 @@ class Account(): ''' get_refresh_menu returns a menu item used on the Journal detail-view toolbar. - :param: journal_entry_metadata - :type: dict :returns: MenuItem :rtype: MenuItem ''' raise NotImplementedError - -class MenuItem(MenuItem): - ''' This is a subclass of sugar3.graphics.menuitem.MenuItem - - The transfer signals are used to update progress of data transfer - between Sugar and the online service. Signal handlers in the - journaltoolbox manage a Notification Alert of this progress. - - 'transfer-started' is emitted at the beginning of a transfer. - - 'transfer-progress' is emitted periodically to indicate progress. - - :emits: total data to transfer - :type: float - :emits: quantity of data transfered - :type: float - :emits: message string - :type: string - - 'transfer-completed' is emitted at the successful completion of a - transfer. - - :emits: message string - :type: string - - 'transfer-failed' is emitted at if the transfer fails. - - :emits: message string - :type: string - - 'transfer-state-changed' is emitted when the account manager wants - to indicate a change in state. - - :emits: message string - :type: string - - The comments-changed signal is emitted by the online service if - changes to the 'comments' metadata have been made. The - expandedentry of the Journal detail view displays these comments. - - :emits: metadata['comments'] - :type: string - ''' - __gsignals__ = { - 'transfer-started': (GObject.SignalFlags.RUN_FIRST, None, ([])), - 'transfer-progress': (GObject.SignalFlags.RUN_FIRST, None, - ([int, int, str])), - 'transfer-completed': (GObject.SignalFlags.RUN_FIRST, None, ([str])), - 'transfer-failed': (GObject.SignalFlags.RUN_FIRST, None, ([str])), - 'transfer-state-changed': (GObject.SignalFlags.RUN_FIRST, None, - ([str])), - 'comments-changed': (GObject.SignalFlags.RUN_FIRST, None, ([str])) - } - def set_metadata(self, metadata): ''' The online account uses this method to set metadata in the Sugar journal and provide a means of updating menuitem status, -- cgit v0.9.1