~ralsina/ubuntuone-windows-installer/fix_803929

« back to all changes in this revision

Viewing changes to ubuntuone_installer/gui/qt/local_folders.py

  • Committer: ralsina
  • Date: 2011-07-07 20:32:17 UTC
  • Revision ID: roberto.alsina@canonical.com-20110707203217-vpjjqg35s3etu493
style fixes

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
"""Widget to create UDFs in the Windows Install Wizard."""
20
20
 
21
21
import ctypes
22
 
import gettext
23
22
import os
24
23
import threading
25
24
import Queue
29
28
from ubuntuone.controlpanel.gui import humanize
30
29
 
31
30
from ubuntuone_installer.gui.qt.ui import local_folders_ui
32
 
 
33
 
_ = gettext.gettext
 
31
from ubuntuone_installer.gui import (
 
32
    LOCAL_FOLDERS_TITLE,
 
33
    LOCAL_FOLDERS_SPACE_HEADER,
 
34
    LOCAL_FOLDERS_OFFER_LABEL,
 
35
    LOCAL_FOLDERS_CALCULATING,
 
36
)
34
37
 
35
38
 
36
39
class FolderItem(QtGui.QTreeWidgetItem):
54
57
 
55
58
    def run(self):
56
59
        total_size = 0
57
 
        for dirpath, dirnames, filenames in os.walk(self.path_name):
 
60
        for dirpath, _, filenames in os.walk(self.path_name):
58
61
            for f in filenames:
59
62
                fp = os.path.join(dirpath, f)
60
63
                total_size += os.path.getsize(fp)
65
68
    """Wizard page to create UDFs in the Windows Installer."""
66
69
    def __init__(self, parent=None):
67
70
        super(LocalFoldersPage, self).__init__(parent)
68
 
        self.setTitle(_("Syncing your computer with the cloud"))
 
71
        self.setTitle(LOCAL_FOLDERS_TITLE)
69
72
        self.ui = local_folders_ui.Ui_Form()
70
73
        self.ui.setupUi(self)
71
74
 
81
84
        self.timer.start(2000)
82
85
        self.timer.timeout.connect(self.update_sizes)
83
86
 
 
87
    # initializePage is inherited
 
88
    # pylint: disable=C0103
84
89
    def initializePage(self):
 
90
        """UI details."""
85
91
        self.wizard()._next_id = None
86
92
 
87
93
    def quota(self):
102
108
        if path in self.items:
103
109
            return None
104
110
        # FIXME: the path should actually be sent to u1cp to verify as valid
105
 
        item = FolderItem([path, "", _("Remove")], path=path, queue=self.queue)
 
111
        item = FolderItem([path, "", "remove"], path=path, queue=self.queue)
106
112
        self.ui.folder_list.addTopLevelItem(item)
107
113
        self.items[path] = item
108
114
        return item
120
126
        total = 0
121
127
        for path, item in self.items.items():
122
128
            if item.size is None:
123
 
                total = _("Calculating")
 
129
                total = LOCAL_FOLDERS_CALCULATING
124
130
                break
125
131
            total += item.size
126
132
 
129
135
            total = humanize(total)
130
136
        else:
131
137
            self.show_hide_offer(0)
132
 
        self.ui.folder_list.headerItem().setText(1, _("Space (%s)" % total))
 
138
        self.ui.folder_list.headerItem().setText(
 
139
            1, LOCAL_FOLDERS_SPACE_HEADER % total)
133
140
 
134
141
    def show_hide_offer(self, cur_size):
135
142
        """Show or hide the offer to buy space according to the total size."""
140
147
        else:
141
148
            self.ui.offer_frame.setVisible(False)
142
149
 
143
 
        self.ui.offer_label.setText(_("The folders you have selected to sync "
144
 
            "take over your %s space. You can remove some folders or add "
145
 
            "some extra space" % humanize(quota)))
 
150
        self.ui.offer_label.setText(LOCAL_FOLDERS_OFFER_LABEL %
 
151
            {"quota": humanize(quota)})
146
152
 
147
153
    def stop_threads(self):
148
154
        """Stop all pending threads."""
149
 
        for path, item in self.items:
 
155
        for _, item in self.items:
150
156
            item.thread._stop = True
151
157
 
 
158
    # itemClicked is a Qt signal name.
 
159
    # pylint: disable=C0103
152
160
    def on_folder_list_itemClicked(self, item, column):
153
161
        """Delete folder from the list."""
154
162
        if column == 2: