~ubuntu-branches/ubuntu/oneiric/ubuntuone-control-panel/oneiric

« back to all changes in this revision

Viewing changes to ubuntuone/controlpanel/gui/qt/controlpanel.py

* New upstream release:
  [ Alejandro J. Cura <alecu@canonical.com>]
    - Do not throw a webclient error when closing
      (LP: #845105).
  [ Natalia B. Bidart <natalia.bidart@canonical.com> ]
    - Removed all code related to Bookmarks (LP: #850142).
    - Replaces references to "Evolution" by "Thunderbird" (LP: #849494).
  [ Rodney Dawes <rodney.dawes@canonical.com> ]
    - Don't install a .desktop file for control panel
      (part of LP: #838778).
    - Point the indicator/Unity API at the installer .desktop file
      (part of LP: #838778).
    - Set the WMCLASS so Unity will fall back properly
      (part of LP: #838778).
    - Fix a few grammar mistakes (LP: #835093).
    - Don't show the "Get NGB free!" label on "Join now" button at all
      (LP: #819955).
* debian/control:
  - ubuntuone-control-panel-gtk depends now on ubuntuone-installer >= 2.0.0.
  - require ubuntuone-client >= 2.0.0.
  - require ubuntu-sso-client >= 1.4.0.
  - no longer install a .desktop file (will be installed by ubuntuone-installer).

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
 
22
22
from __future__ import division
23
23
 
24
 
from PyQt4 import QtGui, QtCore
 
24
from PyQt4 import QtCore
25
25
from twisted.internet import defer
26
26
 
27
 
from ubuntuone.controlpanel import backend
 
27
from ubuntuone.controlpanel.backend import AUTOCONNECT_KEY
28
28
from ubuntuone.controlpanel.logger import setup_logging, log_call
29
29
from ubuntuone.controlpanel.gui import (
30
30
    humanize,
31
 
    EDIT_ACCOUNT_LINK,
 
31
    EDIT_SERVICES_LINK,
32
32
    FACEBOOK_LINK,
33
33
    GET_SUPPORT_LINK,
34
34
    GREETING,
35
35
    PERCENTAGE_LABEL,
 
36
    QUOTA_THRESHOLD,
36
37
    TWITTER_LINK,
37
38
    USAGE_LABEL,
38
39
)
39
 
from ubuntuone.controlpanel.gui.qt import uri_hook
 
40
from ubuntuone.controlpanel.gui import qt
 
41
from ubuntuone.controlpanel.gui.qt.ubuntuonebin import UbuntuOneBin
40
42
from ubuntuone.controlpanel.gui.qt.ui import controlpanel_ui
41
43
 
42
44
 
43
45
logger = setup_logging('qt.controlpanel')
44
46
 
45
 
NAME_STYLE = '<br><span style=" font-size:24pt;">%s!</span>'
 
47
NAME_STYLE = '<br><span style=" font-size:16pt;">%s!</span>'
46
48
PERCENTAGE_STYLE = '<span style=" font-size:16pt;">%.0f%%</span>'
47
49
 
48
50
 
49
 
class ControlPanel(QtGui.QWidget):
 
51
class ControlPanel(UbuntuOneBin):
50
52
    """The Control Panel widget"""
51
53
 
52
 
    def __init__(self, parent=None):
53
 
        """Initialize the UI of the widget."""
54
 
        QtGui.QWidget.__init__(self, parent)
55
 
        self.ui = controlpanel_ui.Ui_Form()
56
 
        self.ui.setupUi(self)
57
 
 
58
 
        self.backend = backend.ControlBackend()
59
 
        self._setup()
60
 
        logger.debug('%s: started.', self.__class__.__name__)
 
54
    ui_class = controlpanel_ui
 
55
    logger = logger
61
56
 
62
57
    def _setup(self):
63
58
        """Do some extra setupping for the UI."""
64
 
        self.ui.get_more_space_button.uri = EDIT_ACCOUNT_LINK
 
59
        self.ui.get_more_space_button.uri = EDIT_SERVICES_LINK
65
60
        self.ui.help_button.uri = GET_SUPPORT_LINK
66
 
 
67
 
    # Invalid name "showEvent"
68
 
    # pylint: disable=C0103
69
 
 
70
 
    def showEvent(self, event):
71
 
        """Load info."""
72
 
        self.load()
73
 
        event.accept()
74
 
 
 
61
        self.ui.devices_tab.localDeviceRemoved.connect(
 
62
            self.on_credentials_not_found)
 
63
        self.ui.signin.credentialsFound.connect(lambda creds: self.load())
 
64
 
 
65
    @defer.inlineCallbacks
 
66
    def connect_file_sync(self):
 
67
        """Connect file sync service if the setting autoconnect is enabled."""
 
68
        settings = yield self.backend.file_sync_settings_info()
 
69
        if AUTOCONNECT_KEY in settings and settings[AUTOCONNECT_KEY]:
 
70
            yield self.backend.connect_files()
 
71
 
 
72
    @log_call(logger.debug)
 
73
    def on_credentials_not_found(self):
 
74
        """Credentials are not found or were removed."""
 
75
        self.ui.switcher.setCurrentWidget(self.ui.signin)
 
76
        self.is_processing = False
 
77
 
 
78
    @log_call(logger.debug)
 
79
    def on_credentials_found(self):
 
80
        """Credentials are not found or were removed."""
 
81
        self.ui.switcher.setCurrentWidget(self.ui.management)
 
82
        self.connect_file_sync()
 
83
        self.is_processing = False
 
84
 
 
85
    # pylint: disable=E0202
75
86
    @defer.inlineCallbacks
76
87
    def load(self):
77
88
        """Load info."""
78
 
        info = yield self.backend.account_info()
79
 
        self.process_info(info)
 
89
        self.is_processing = True
 
90
        credentials = yield self.backend.get_credentials()
 
91
        if not credentials:
 
92
            self.on_credentials_not_found()
 
93
        else:
 
94
            self.on_credentials_found()
 
95
            info = yield self.backend.account_info()
 
96
            self.process_info(info)
80
97
 
81
98
    @log_call(logger.debug)
82
99
    def process_info(self, info):
86
103
 
87
104
        used = int(info['quota_used'])
88
105
        total = int(info['quota_total'])
89
 
        percentage = {'percentage': PERCENTAGE_STYLE % ((used / total) * 100)}
 
106
        percentage_value = ((used / total) * 100)
 
107
        percentage = {'percentage': PERCENTAGE_STYLE % percentage_value}
90
108
        data = {'used': humanize(used), 'total': humanize(total)}
91
109
        self.ui.percentage_usage_label.setText(PERCENTAGE_LABEL % percentage)
92
110
        self.ui.quota_usage_label.setText(USAGE_LABEL % data)
 
111
        self._update_quota({'percentage': percentage_value})
 
112
 
 
113
    @log_call(logger.debug)
 
114
    def _update_quota(self, data=None):
 
115
        """Update the quota info."""
 
116
        fraction = 0.0
 
117
        if data is not None:
 
118
            fraction = data.get('percentage', 0.0) / 100
 
119
            if fraction > 0 and fraction < 0.05:
 
120
                fraction = 0.05
 
121
            else:
 
122
                fraction = round(fraction, 2)
 
123
 
 
124
        logger.debug('ManagementPanel: updating quota to %r.', fraction)
 
125
        self.ui.percentage_usage_label.setProperty("OverQuota",
 
126
            fraction >= QUOTA_THRESHOLD)
 
127
        self.ui.quota_usage_label.setProperty("OverQuota",
 
128
            fraction >= QUOTA_THRESHOLD)
 
129
        self.ui.percentage_usage_label.style().unpolish(
 
130
            self.ui.percentage_usage_label)
 
131
        self.ui.percentage_usage_label.style().polish(
 
132
            self.ui.percentage_usage_label)
 
133
        self.ui.quota_usage_label.style().unpolish(
 
134
            self.ui.quota_usage_label)
 
135
        self.ui.quota_usage_label.style().polish(self.ui.quota_usage_label)
93
136
 
94
137
    @QtCore.pyqtSlot()
95
138
    def on_twitter_button_clicked(self):
96
139
        """The twitter button was clicked."""
97
 
        uri_hook(TWITTER_LINK)
 
140
        qt.uri_hook(TWITTER_LINK)
98
141
 
99
142
    @QtCore.pyqtSlot()
100
143
    def on_facebook_button_clicked(self):
101
144
        """The facebook button was clicked."""
102
 
        uri_hook(FACEBOOK_LINK)
 
145
        qt.uri_hook(FACEBOOK_LINK)