Initial commit (Vesion 0.1)
[tablet-suite] / src / backup / .svn / text-base / pcsprogresswizard.py.svn-base
1 # Authors: Amaury Medeiros and Paulo Ouriques
2 # Software License: GPL
3
4 from PyQt4.QtCore import *
5 from PyQt4.QtGui import *
6
7 from ui.pcsuiutils import *
8 from pcsbackupmanagerui import *
9 from pcsrestorebackupui import *
10 from style.styleTabletSuite import *
11
12
13 class PcsProgressWizard(QWizardPage):
14     
15     def __init__(self, deviceInfo, wizard, windowManager, parent = None):
16         QWizardPage.__init__(self, parent)
17         self.windowManager = windowManager
18         self.deviceInfo = deviceInfo
19         self.wizard = wizard
20         self.layout = QVBoxLayout()
21         self.layout.setMargin(0)
22         self.cancelButton = QPushButton("Cancel")
23         self.doneButton = QPushButton("Done")
24         self.completeReportButton = QPushButton("View Complete Report")
25         self.lockMenuButtons = True        
26         self._insertLayout()
27         
28     def _insertLayout(self, name = ""):
29         self.vLayout = QVBoxLayout()
30         self.vLayout.setMargin(0)
31         self.wayLayout = self._wayLayout(name)
32         buttonLayout = self._menuButtons()
33         spc = QSpacerItem(0, 3)
34         self.vLayout.addLayout(buttonLayout, Qt.AlignTop)
35         self.vLayout.addItem(spc)
36         self.vLayout.addLayout(self.wayLayout, Qt.AlignLeft)
37         spc = QSpacerItem(0, 68)
38         self.vLayout.addItem(spc)
39         self.vLayout.addLayout(self._createCenterLayout(), Qt.AlignVCenter)
40         self.vLayout.addItem(spc)
41         self.vLayout.addLayout(self._createInformationsLabel(), Qt.AlignVCenter)
42         self.setLayout(self.vLayout)
43
44     def _menuButtons(self):
45         infList = [("New Backup", SMALL_ICON_NEW_BACKUP_STYLE_SELECTED), 
46                    ("Manager Backup", SMALL_ICON_MANAGER_BACKUP_STYLE, self._manageDialog),
47                    ("Restore Backup", SMALL_ICON_RESTORE_BACKUP_STYLE, self._restoreDialog)]
48         buttonsLayout = QHBoxLayout()
49         buttonsLayout.setMargin(0)
50         for i in range(3):
51             but = QPushButton(infList[i][0])
52             but.setStyleSheet(infList[i][1])
53             if i <> 0:
54                 buttonsLayout.addWidget(but, Qt.AlignLeft)
55                 self.connect(but, SIGNAL("clicked()"), infList[i][2])
56             else:
57                 buttonsLayout.addWidget(but)
58         return buttonsLayout    
59     
60     def _wayLayout(self, name = ""):
61         self.barLayout = QHBoxLayout()
62         self.barLayout.setMargin(0)
63         main = QLabel("<font style='color: #333333'; size=2>Main</font>")
64         arrow1 = self._arrow()
65         arrow2 = self._arrow()
66         arrow3 = self._arrow()
67         arrow4 = self._arrow()
68         spc = QSpacerItem(2, 0)
69         newBackup = QLabel("<font style='color: #333333'; size=2> New Backup</font>")
70         files = QLabel("<font style='color: #333333'; size=2>Files</font>")
71         folder = QLabel("<font style='color: #333333'; size=2>Folder</font>")
72         if name != "":
73             loading = QLabel("<font style='color: #333333'; size=2>loading</font>")
74         else:
75             loading = QLabel("<font style='color: #FFFFFF'; size=2>loading</font>")   
76         widgetList = [main, self._arrow(), newBackup, self._arrow(), files,
77                       self._arrow(), folder, self._arrow(), loading]
78         for widget in widgetList:
79             self.barLayout.addWidget(widget, Qt.AlignLeft)
80             self.barLayout.addItem(spc)
81         if name != "":
82             newLabel = QLabel("<font style='color: #FFFFFF'; size=2>"+ name +"</font>")
83             self.barLayout.addWidget(self._arrow(), Qt.AlignLeft)
84             self.barLayout.addItem(spc)
85             self.barLayout.addWidget(newLabel, Qt.AlignLeft)
86             self.barLayout.addItem(spc)
87             
88         self.barLayout.addItem(QSpacerItem(300, 0))
89         return self.barLayout
90     
91     def _manageDialog(self):
92         if self.lockMenuButtons == False:
93             if(self.deviceInfo and self.deviceInfo.ip != None):
94                 backupManager = self.windowManager.getBackupManager()
95                 centralize(backupManager)
96                 backupManager.setGeometry(self.wizard.geometry())
97                 backupManager.show()
98                 self.close()
99                 self.wizard.close()
100                 self.lockMenuButtons = True
101                 self._resetPage()
102             else:
103                 self._showNoDeviceFoundMessage()
104         
105     def _restoreDialog(self):
106         if self.lockMenuButtons == False:
107             if(self.deviceInfo and self.deviceInfo.ip != None):
108                 restoreBackup = self.windowManager.getRestoreBackup()
109                 centralize(restoreBackup)
110                 restoreBackup.setGeometry(self.wizard.geometry())
111                 restoreBackup.show()
112                 self.wizard.close()
113                 self.close()
114                 self.lockMenuButtons = True
115                 self._resetPage()
116             else:
117                 self._showNoDeviceFoundMessage()
118         
119     def _showNoDeviceFoundMessage(self):
120         inf = QMessageBox(self)
121         inf.setWindowTitle("Connect a device.")
122         inf.setText("No devices were found.")
123         inf.show()
124     
125     def _arrow(self):
126         label = QLabel()
127         label.setPixmap(QPixmap(BLACK_ARROW))
128         return label
129         
130     def _createInformationsLabel(self):
131         hLay = QHBoxLayout()
132         spc = QSpacerItem(10, 0)
133         self.infLabel = QLabel("<font style='color:"\
134                              "#333333'; size=2>"\
135                              "Do backup from Device to your PC.</font>")
136         iconAlert = QLabel()
137         iconAlert.setPixmap(QPixmap(ICON_ALERT))
138         hLay.addItem(spc)
139         hLay.addWidget(iconAlert)
140         hLay.addWidget(self.infLabel, Qt.AlignLeft)
141         
142         return hLay
143     
144     def _resetPage(self):
145         self.lockMenuButtons = True
146         self.cancelButton.setVisible(True)
147         self.doneButton.setVisible(False)
148         self.progressBar.setValue(0)
149         self.progressReport.setText("")
150         self.categoryLabel.setText("<font style='color:"\
151                                     "#333333'; size=2>"\
152                                     "Backup starting...</font>")
153     
154     def _createCenterLayout(self):
155         gridLayout = QGridLayout()
156         gridLayout.setMargin(27)
157         
158         self.categoryLabel = QLabel("<font style='color:"\
159                                     "#333333'; size=2>"\
160                                     "Backup starting...</font>")  
161         
162         bgLabel = QLabel()
163         bgLabel.setPixmap(QPixmap(PROGRESS_BAR_BG))
164         grid = QGridLayout()
165         
166         self.progressBar = QProgressBar()
167         self.progressBar.setObjectName("progressBarWizard")
168         self.progressBar.setValue(0)
169         self.progressBar.setTextVisible(False)
170         
171         grid.addWidget(bgLabel, 0, 0, Qt.AlignCenter)
172         grid.addWidget(self.progressBar, 0, 0, Qt.AlignCenter)
173         
174         self.progressReport = QLabel("")  
175         
176         self.cancelButton.setStyleSheet(DEFAULT_BUTTON_STYLE)
177         self.cancelButton.setShortcut(Qt.Key_Return)
178         self.doneButton.setVisible(False)
179         self.doneButton.setStyleSheet(DEFAULT_BUTTON_STYLE)
180 #        self.completeReportButton.setStyleSheet()
181         
182         gridLayout.setSpacing(3)
183         gridLayout.addWidget(self.categoryLabel, 0, 0, Qt.AlignRight)
184         gridLayout.addLayout(grid, 1, 0)
185         gridLayout.addWidget(self.progressReport, 2, 0, Qt.AlignRight)
186         gridLayout.addWidget(self.cancelButton, 3, 0, Qt.AlignRight)
187         gridLayout.addWidget(self.doneButton, 3, 0, Qt.AlignRight)
188         
189         return gridLayout
190     
191     def progressCanceled(self):
192         self.progressDone(True)
193     
194     def progressDone(self, cancel=False):
195         self.lockMenuButtons = False
196         self.cancelButton.setVisible(False)
197         self.doneButton.setVisible(True)
198         
199         self.categoryLabel.setText("<font style='color:"\
200                                    "#333333'; size=2>"\
201                                    "Backup finished.</font>")
202         if not cancel:
203             totalSize =  "%.2f" % (self.totalSize/(1024.0**2))
204         
205             self.progressReport.setText("<font style='color:"\
206                                         "#333333'; size=2>"\
207                                         + str(self.backedUpNumber) +\
208                                         " Files - " + totalSize + " MB</font>")
209         else:
210             self.progressReport.setText("<font style='color:"\
211                                         "#333333'; size=2> Canceled")
212             self.categoryLabel.setText("")
213             self.progressBar.setValue(100)
214             
215             
216         self.infLabel.setText("<font style='color:"\
217                               "#333333'; size=2>"\
218                               "Select an action</font>")
219         
220     def updateInfo(self, totalSize, backedUpNumber):
221         self.totalSize = totalSize
222         self.backedUpNumber = backedUpNumber
223     
224     def setProgress(self, progress):
225         self.progressBar.setValue(progress)
226         
227         self.progressReport.setText("<font style='color:"\
228                                     "#333333'; size=2>"\
229                                     + str(int(progress))+\
230                                     "% Complete</font>")  
231         
232     def setCategory(self, category):
233         self.categoryLabel.setText("<font style='color:"\
234                                    "#333333'; size=2> Category name: "\
235                                    + category +"</font>")
236         
237