Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/src/jarabe/web
diff options
context:
space:
mode:
Diffstat (limited to 'src/jarabe/web')
-rw-r--r--src/jarabe/web/Makefile.am6
-rw-r--r--src/jarabe/web/__init__.py15
-rw-r--r--src/jarabe/web/account.py118
-rw-r--r--src/jarabe/web/accountsmanager.py18
4 files changed, 57 insertions, 100 deletions
diff --git a/src/jarabe/web/Makefile.am b/src/jarabe/web/Makefile.am
index a2caada..b51b5a9 100644
--- a/src/jarabe/web/Makefile.am
+++ b/src/jarabe/web/Makefile.am
@@ -1,5 +1,5 @@
sugardir = $(pythondir)/jarabe/web
-sugar_PYTHON = \
- __init__.py \
- account.py \
+sugar_PYTHON = \
+ __init__.py \
+ account.py \
accountsmanager.py
diff --git a/src/jarabe/web/__init__.py b/src/jarabe/web/__init__.py
index 85f6a24..e69de29 100644
--- a/src/jarabe/web/__init__.py
+++ b/src/jarabe/web/__init__.py
@@ -1,15 +0,0 @@
-# Copyright (C) 2006-2007, Red Hat, Inc.
-#
-# This program is free software; you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation; either version 2 of the License, or
-# (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the Free Software
-# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
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,
diff --git a/src/jarabe/web/accountsmanager.py b/src/jarabe/web/accountsmanager.py
index cd1da83..fb7b632 100644
--- a/src/jarabe/web/accountsmanager.py
+++ b/src/jarabe/web/accountsmanager.py
@@ -21,13 +21,14 @@ import logging
from gi.repository import Gtk
from jarabe import config
+from jarabe.web.account import Account
_accounts = []
def get_all_accounts():
''' Returns a list of all installed online account managers '''
- global _accounts # No need to do this every time.
+ global _accounts
if len(_accounts) > 0:
return _accounts
@@ -54,8 +55,8 @@ def _load_module(dir_path):
for f in os.listdir(dir_path):
if f == 'account.py':
module_name = f[:-3]
- logging.debug('OnlineAccountsManager loading %s' % (
- module_name))
+ logging.debug('OnlineAccountsManager loading %s' %
+ (module_name))
module_path = 'web.%s.%s' % (os.path.basename(dir_path),
module_name)
try:
@@ -65,8 +66,8 @@ def _load_module(dir_path):
module = mod.get_account()
except Exception as e:
- logging.exception('Exception while loading %s: %s' % (
- module_name, str(e)))
+ logging.exception('Exception while loading %s: %s' %
+ (module_name, str(e)))
return module
@@ -90,8 +91,11 @@ def _extend_icon_theme_search_path(dir_path):
def get_configured_accounts():
- return [a for a in get_all_accounts() if a.is_configured()]
+ return [a for a in get_all_accounts()
+ if a.get_token_state() in (Account.STATE_VALID,
+ Account.STATE_EXPIRED)]
def get_active_accounts():
- return [a for a in get_all_accounts() if a.is_active()]
+ return [a for a in get_all_accounts()
+ if a.get_token_state() == Account.STATE_VALID]