1 # Authors: Amaury Medeiros and Paulo Ouriques
2 # Software License: GPL
4 from functools import partial
6 from PyQt4.QtCore import *
7 from PyQt4.QtGui import *
8 from ui.pcsdevicewidget import PcsDeviceWidget
9 from ui.pcsuiutils import *
10 from pcsbackupmanagerui import *
11 from pcsrestorebackupui import *
12 from style.styleTabletSuite import *
15 class PcsOpenFileWizard(QWizardPage):
17 _home_dir = os.path.expanduser("~")
18 _default_dir = _home_dir + "/.pcsuite/Backup"
20 def __init__(self, deviceInfo, windowManager, parent = None):
21 QWizardPage.__init__(self, parent)
23 self.path = self._default_dir
24 self.file_name = "Backup"
25 self.deviceInfo = deviceInfo
26 self.windowManager = windowManager
28 self.layout = QVBoxLayout()
29 self.layout.setMargin(0)
30 self.hLayout = QHBoxLayout()
31 self.hLayout.setMargin(0)
32 self.vLayout = QVBoxLayout()
33 self.vLayout.setMargin(0)
35 wayLayout = self._wayLayout()
37 buttonLayout = self._menuButtons()
38 spc = QSpacerItem(0, 3)
39 self.vLayout.addLayout(buttonLayout, Qt.AlignTop)
40 self.vLayout.addItem(spc)
41 spc = QSpacerItem(0, 12)
42 self.vLayout.addLayout(wayLayout, Qt.AlignTop)
43 self.vLayout.addItem(spc)
44 self.vLayout.addLayout(self._createCenterLayout(), Qt.AlignVCenter)
45 self.vLayout.addItem(spc)
46 spc2 = QSpacerItem(350, 0)
47 self.finishButton = QPushButton("Finish")
48 self.finishButton.setStyleSheet(DEFAULT_BUTTON_STYLE)
49 self.finishButton.setShortcut(Qt.Key_Return)
50 self.hLayout.addItem(spc2)
51 self.hLayout.addWidget(self.finishButton)
52 self.vLayout.addLayout(self.hLayout)
53 self.vLayout.addItem(spc)
54 self.vLayout.addLayout(self._createInformationsLabel(), Qt.AlignVCenter)
56 self.setLayout(self.vLayout)
58 def _menuButtons(self):
59 infList = [("New Backup", SMALL_ICON_NEW_BACKUP_STYLE_SELECTED),
60 ("Manage Backup", SMALL_ICON_MANAGER_BACKUP_STYLE, self._manageDialog),
61 ("Restore Backup", SMALL_ICON_RESTORE_BACKUP_STYLE, self._restoreDialog)]
62 buttonsLayout = QHBoxLayout()
63 buttonsLayout.setMargin(0)
65 but = QPushButton(infList[i][0])
66 but.setStyleSheet(infList[i][1])
68 buttonsLayout.addWidget(but, Qt.AlignLeft)
69 self.connect(but, SIGNAL("clicked()"), infList[i][2])
71 buttonsLayout.addWidget(but)
75 barLayout = QHBoxLayout()
76 barLayout.setMargin(0)
77 main = QLabel("<font style='color: #333333'; size=2>Main</font>")
79 arrow2 = self._arrow()
80 arrow3 = self._arrow()
81 spc = QSpacerItem(2, 0)
82 newBackup = QLabel("<font style='color: #333333'; size=2> New Backup</font>")
83 files = QLabel("<font style='color: #333333'; size=2>Files</font>")
84 folder = QLabel("<font style='color: #FFFFFF'; size=2>Folder</font>")
85 widgetList = [main, arrow, newBackup, arrow2, files, arrow3, folder]
86 for widget in widgetList:
87 barLayout.addWidget(widget, Qt.AlignLeft)
88 barLayout.addItem(spc)
89 barLayout.addItem(QSpacerItem(300, 0))
92 def _manageDialog(self):
93 if(self.deviceInfo and self.deviceInfo.ip != None):
94 backupManager = self.windowManager.getBackupManager()
95 centralize(backupManager)
96 backupManager.setGeometry(self.wizard().geometry())
101 self._showNoDeviceFoundMessage()
103 def _restoreDialog(self):
104 if(self.deviceInfo and self.deviceInfo.ip != None):
105 restoreBackup = self.windowManager.getRestoreBackup()
106 centralize(restoreBackup)
107 restoreBackup.setGeometry(self.wizard().geometry())
109 self.wizard().close()
112 self._showNoDeviceFoundMessage()
114 def _showNoDeviceFoundMessage(self):
115 inf = QMessageBox(self)
116 inf.setWindowTitle("Connect a device.")
117 inf.setText("No devices were found.")
122 label.setPixmap(QPixmap(BLACK_ARROW))
125 def _createDeviceWidget(self):
126 deviceWidget = PcsDeviceWidget(3)
127 deviceWidget.addBorder()
128 deviceWidget.addDeviceName()
129 deviceWidget.setDeviceInfo(self.deviceInfo)
133 def _createInformationsLabel(self):
135 spc = QSpacerItem(10, 0)
136 infLabel = QLabel("<font style='color:"\
138 "Do backup from Device to your PC.</font>")
140 iconAlert.setPixmap(QPixmap(ICON_ALERT))
142 hLay.addWidget(iconAlert)
143 hLay.addWidget(infLabel, Qt.AlignLeft)
148 def _createCenterLayout(self):
153 hLayWithSpacer = QHBoxLayout()
154 hLayWithSpacer.setMargin(0)
155 spc = QSpacerItem(62, 0)
157 deviceWidget = self._createDeviceWidget()
158 arrowLabel = self._createArrowLabel()
159 pcLabel = self._createPcLabel()
160 pathField = self._createPathField()
161 nameField = self._createBackupNameField()
163 hLay.addWidget(deviceWidget, Qt.AlignVCenter)
164 hLay.addLayout(arrowLabel, Qt.AlignVCenter)
165 hLay.addLayout(pcLabel, Qt.AlignVCenter)
167 vLay.addLayout(nameField)
169 vLay.addLayout(pathField)
171 hLayWithSpacer.addItem(spc)
172 hLayWithSpacer.addLayout(vLay)
173 hLayWithSpacer.addItem(spc)
175 return hLayWithSpacer
177 def _createArrowLabel(self):
178 arrowLayout = QGridLayout()
179 arrowLabel = QLabel()
180 arrowLabel.setPixmap(QPixmap(LARGE_ARROW_IMAGE))
181 borderArrowLabel = QLabel()
182 borderArrowLabel.setFixedSize(42, 65)
183 borderArrowLabel.setPixmap(QPixmap(LARGE_ARROW_BORDER))
184 arrowLayout.addWidget(arrowLabel, 0, 0, Qt.AlignCenter)
185 arrowLayout.addWidget(borderArrowLabel, 0, 0, Qt.AlignCenter)
188 def _createPcLabel(self):
189 gridLay = QGridLayout()
190 pcLabelLayout = QGridLayout()
192 pcLabel.setPixmap(QPixmap(PC_IMAGE))
194 pcBorder.setFixedSize(112, 127)
195 pcBorder.setPixmap(QPixmap(PC_BORDER_FILE))
196 nameLabel = QLabel("PC")
197 nameBorder = QLabel()
198 nameBorder.setPixmap(QPixmap(PC_NAME_BORDER_FILE))
199 nameBorder.setFixedSize(92, 26)
200 gridLay.addWidget(pcLabel, 0, 0, Qt.AlignCenter)
201 gridLay.addWidget(nameLabel, 1, 0, Qt.AlignCenter)
202 gridLay.addWidget(nameBorder, 1, 0, Qt.AlignCenter)
203 pcLabelLayout.addLayout(gridLay, 0, 0, Qt.AlignCenter)
204 pcLabelLayout.addWidget(pcBorder, 0, 0, Qt.AlignCenter)
207 def _createPathField(self):
208 pathLayout = QHBoxLayout()
209 self.pathField = QLineEdit()
210 self.pathField.setReadOnly(True)
211 self.pathField.setText(self._default_dir)
212 self.pathField.setObjectName("pathField")
213 buttonBrowse = QPushButton()
214 buttonBrowse.setObjectName("buttonBrowse")
215 self.connect(buttonBrowse, SIGNAL("clicked()"), self._openFileDialog)
216 pathLayout.addWidget(self.pathField)
217 pathLayout.addWidget(buttonBrowse)
219 borderLabel = QLabel()
220 borderLabel.setPixmap(QPixmap(PATH_BG))
221 borderLabel.setFixedSize(304, 40)
222 gridLay = QGridLayout()
223 gridLay.addWidget(borderLabel, 0, 0, Qt.AlignCenter)
224 gridLay.addLayout(pathLayout, 0, 0, Qt.AlignCenter)
228 def _createBackupNameField(self):
229 label = QLabel("Backup Name:")
230 backupNameLayout = QHBoxLayout()
231 backupNameLayout.addWidget(label)
232 self.backupNameField = QLineEdit()
233 self.backupNameField.setObjectName("backupNameField")
234 self.backupNameField.setText("Backup")
235 backupNameLayout.addWidget(self.backupNameField,
237 borderLabel = QLabel()
238 borderLabel.setPixmap(QPixmap(BACKUP_NAME_BG))
239 borderLabel.setFixedSize(304, 40)
240 gridLay = QGridLayout()
241 gridLay.addWidget(borderLabel, 0, 0, Qt.AlignCenter)
242 gridLay.addLayout(backupNameLayout, 0, 0, Qt.AlignCenter)
246 def _openFileDialog(self):
247 pathDialog = QFileDialog()
248 prompt = "Select the folder you wish to save your backup"
249 self.path = pathDialog.getExistingDirectory(self, prompt,
252 self.pathField.setText(self.path)
254 def _resetPage(self):
255 self.path = self._default_dir
256 self.pathField.setText(self._default_dir)
257 self.backupNameField.setText("Backup")
259 def getBackupName(self):
260 return str(self.backupNameField.text())
263 return str(self.pathField.text())