Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/src/jarabe/web/account.py
blob: 2e55f254c3cdef35fc49455b72928d764291214a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
# Copyright (c) 2013 Walter Bender, Raul Gutierrez Segales
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2 of the License, or (at your option) any later version.
#
# This library 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
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the
# 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
    '''

    def get_description(self):
        ''' get_description returns a brief description of the online
        service. The description is used in palette menuitems and on
        the webservices control panel.

        :returns: online-account name
        :rtype: string
        '''
        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
        '''
        raise NotImplementedError

    def is_active(self):
        ''' is_active returns True if the service is currently
        available, e.g., the access token has not expired.

        :returns: active status
        :rtype: bool
        '''
        raise NotImplementedError

    def get_share_menu(self):
        ''' get_share_menu returns a menu item used on the Copy To
        palette in the Journal and on the Journal detail-view toolbar.

        :param: journal_entry_metadata
        :type: dict
        :returns: MenuItem
        :rtype: MenuItem
        '''
        raise NotImplementedError

    def get_refresh_menu(self):
        ''' 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,
        e.g., enabling the refresh menu after a successful transfer.

        :param: journal_entry_metadata
        :type: dict
        '''
        raise NotImplementedError