--- /dev/null
+# Authors: Amaury Medeiros and Paulo Ouriques
+# Software License: GPL
+import os
+from functools import partial
+
+from PyQt4.QtCore import *
+from PyQt4.QtGui import *
+from ui.pcsdevicewidget import PcsDeviceWidget
+from ui.pcsuiutils import *
+from pcsbackupmanagerui import *
+from pcsrestorebackupui import *
+from style.styleTabletSuite import *
+
+
+class PcsOpenFileWizard(QWizardPage):
+
+ _home_dir = os.path.expanduser("~")
+ _default_dir = _home_dir + "/.pcsuite/Backup"
+
+ def __init__(self, deviceInfo, windowManager, parent = None):
+ QWizardPage.__init__(self, parent)
+
+ self.path = self._default_dir
+ self.file_name = "Backup"
+ self.deviceInfo = deviceInfo
+ self.windowManager = windowManager
+
+ self.layout = QVBoxLayout()
+ self.layout.setMargin(0)
+ self.hLayout = QHBoxLayout()
+ self.hLayout.setMargin(0)
+ self.vLayout = QVBoxLayout()
+ self.vLayout.setMargin(0)
+
+ wayLayout = self._wayLayout()
+
+ buttonLayout = self._menuButtons()
+ spc = QSpacerItem(0, 3)
+ self.vLayout.addLayout(buttonLayout, Qt.AlignTop)
+ self.vLayout.addItem(spc)
+ spc = QSpacerItem(0, 12)
+ self.vLayout.addLayout(wayLayout, Qt.AlignTop)
+ self.vLayout.addItem(spc)
+ self.vLayout.addLayout(self._createCenterLayout(), Qt.AlignVCenter)
+ self.vLayout.addItem(spc)
+ spc2 = QSpacerItem(350, 0)
+ self.finishButton = QPushButton("Finish")
+ self.finishButton.setStyleSheet(DEFAULT_BUTTON_STYLE)
+ self.finishButton.setShortcut(Qt.Key_Return)
+ self.hLayout.addItem(spc2)
+ self.hLayout.addWidget(self.finishButton)
+ self.vLayout.addLayout(self.hLayout)
+ self.vLayout.addItem(spc)
+ self.vLayout.addLayout(self._createInformationsLabel(), Qt.AlignVCenter)
+
+ self.setLayout(self.vLayout)
+
+ def _menuButtons(self):
+ infList = [("New Backup", SMALL_ICON_NEW_BACKUP_STYLE_SELECTED),
+ ("Manage Backup", SMALL_ICON_MANAGER_BACKUP_STYLE, self._manageDialog),
+ ("Restore Backup", SMALL_ICON_RESTORE_BACKUP_STYLE, self._restoreDialog)]
+ buttonsLayout = QHBoxLayout()
+ buttonsLayout.setMargin(0)
+ for i in range(3):
+ but = QPushButton(infList[i][0])
+ but.setStyleSheet(infList[i][1])
+ if i <> 0:
+ buttonsLayout.addWidget(but, Qt.AlignLeft)
+ self.connect(but, SIGNAL("clicked()"), infList[i][2])
+ else:
+ buttonsLayout.addWidget(but)
+ return buttonsLayout
+
+ def _wayLayout(self):
+ barLayout = QHBoxLayout()
+ barLayout.setMargin(0)
+ main = QLabel("<font style='color: #333333'; size=2>Main</font>")
+ arrow = self._arrow()
+ arrow2 = self._arrow()
+ arrow3 = self._arrow()
+ spc = QSpacerItem(2, 0)
+ newBackup = QLabel("<font style='color: #333333'; size=2> New Backup</font>")
+ files = QLabel("<font style='color: #333333'; size=2>Files</font>")
+ folder = QLabel("<font style='color: #FFFFFF'; size=2>Folder</font>")
+ widgetList = [main, arrow, newBackup, arrow2, files, arrow3, folder]
+ for widget in widgetList:
+ barLayout.addWidget(widget, Qt.AlignLeft)
+ barLayout.addItem(spc)
+ barLayout.addItem(QSpacerItem(300, 0))
+ return barLayout
+
+ def _manageDialog(self):
+ if(self.deviceInfo and self.deviceInfo.ip != None):
+ backupManager = self.windowManager.getBackupManager()
+ centralize(backupManager)
+ backupManager.setGeometry(self.wizard().geometry())
+ backupManager.show()
+ self.wizard().close()
+ self.close()
+ else:
+ self._showNoDeviceFoundMessage()
+
+ def _restoreDialog(self):
+ if(self.deviceInfo and self.deviceInfo.ip != None):
+ restoreBackup = self.windowManager.getRestoreBackup()
+ centralize(restoreBackup)
+ restoreBackup.setGeometry(self.wizard().geometry())
+ restoreBackup.show()
+ self.wizard().close()
+ self.close()
+ else:
+ self._showNoDeviceFoundMessage()
+
+ def _showNoDeviceFoundMessage(self):
+ inf = QMessageBox(self)
+ inf.setWindowTitle("Connect a device.")
+ inf.setText("No devices were found.")
+ inf.show()
+
+ def _arrow(self):
+ label = QLabel()
+ label.setPixmap(QPixmap(BLACK_ARROW))
+ return label
+
+ def _createDeviceWidget(self):
+ deviceWidget = PcsDeviceWidget(3)
+ deviceWidget.addBorder()
+ deviceWidget.addDeviceName()
+ deviceWidget.setDeviceInfo(self.deviceInfo)
+
+ return deviceWidget
+
+ def _createInformationsLabel(self):
+ hLay = QHBoxLayout()
+ spc = QSpacerItem(10, 0)
+ infLabel = QLabel("<font style='color:"\
+ "#333333'; size=2>"\
+ "Do backup from Device to your PC.</font>")
+ iconAlert = QLabel()
+ iconAlert.setPixmap(QPixmap(ICON_ALERT))
+ hLay.addItem(spc)
+ hLay.addWidget(iconAlert)
+ hLay.addWidget(infLabel, Qt.AlignLeft)
+
+
+ return hLay
+
+ def _createCenterLayout(self):
+ hLay = QHBoxLayout()
+ hLay.setMargin(0)
+ vLay = QVBoxLayout()
+ vLay.setMargin(0)
+ hLayWithSpacer = QHBoxLayout()
+ hLayWithSpacer.setMargin(0)
+ spc = QSpacerItem(62, 0)
+
+ deviceWidget = self._createDeviceWidget()
+ arrowLabel = self._createArrowLabel()
+ pcLabel = self._createPcLabel()
+ pathField = self._createPathField()
+ nameField = self._createBackupNameField()
+
+ hLay.addWidget(deviceWidget, Qt.AlignVCenter)
+ hLay.addLayout(arrowLabel, Qt.AlignVCenter)
+ hLay.addLayout(pcLabel, Qt.AlignVCenter)
+
+ vLay.addLayout(nameField)
+ vLay.addLayout(hLay)
+ vLay.addLayout(pathField)
+
+ hLayWithSpacer.addItem(spc)
+ hLayWithSpacer.addLayout(vLay)
+ hLayWithSpacer.addItem(spc)
+
+ return hLayWithSpacer
+
+ def _createArrowLabel(self):
+ arrowLayout = QGridLayout()
+ arrowLabel = QLabel()
+ arrowLabel.setPixmap(QPixmap(LARGE_ARROW_IMAGE))
+ borderArrowLabel = QLabel()
+ borderArrowLabel.setFixedSize(42, 65)
+ borderArrowLabel.setPixmap(QPixmap(LARGE_ARROW_BORDER))
+ arrowLayout.addWidget(arrowLabel, 0, 0, Qt.AlignCenter)
+ arrowLayout.addWidget(borderArrowLabel, 0, 0, Qt.AlignCenter)
+ return arrowLayout
+
+ def _createPcLabel(self):
+ gridLay = QGridLayout()
+ pcLabelLayout = QGridLayout()
+ pcLabel = QLabel()
+ pcLabel.setPixmap(QPixmap(PC_IMAGE))
+ pcBorder = QLabel()
+ pcBorder.setFixedSize(112, 127)
+ pcBorder.setPixmap(QPixmap(PC_BORDER_FILE))
+ nameLabel = QLabel("PC")
+ nameBorder = QLabel()
+ nameBorder.setPixmap(QPixmap(PC_NAME_BORDER_FILE))
+ nameBorder.setFixedSize(92, 26)
+ gridLay.addWidget(pcLabel, 0, 0, Qt.AlignCenter)
+ gridLay.addWidget(nameLabel, 1, 0, Qt.AlignCenter)
+ gridLay.addWidget(nameBorder, 1, 0, Qt.AlignCenter)
+ pcLabelLayout.addLayout(gridLay, 0, 0, Qt.AlignCenter)
+ pcLabelLayout.addWidget(pcBorder, 0, 0, Qt.AlignCenter)
+ return pcLabelLayout
+
+ def _createPathField(self):
+ pathLayout = QHBoxLayout()
+ self.pathField = QLineEdit()
+ self.pathField.setReadOnly(True)
+ self.pathField.setText(self._default_dir)
+ self.pathField.setObjectName("pathField")
+ buttonBrowse = QPushButton()
+ buttonBrowse.setObjectName("buttonBrowse")
+ self.connect(buttonBrowse, SIGNAL("clicked()"), self._openFileDialog)
+ pathLayout.addWidget(self.pathField)
+ pathLayout.addWidget(buttonBrowse)
+
+ borderLabel = QLabel()
+ borderLabel.setPixmap(QPixmap(PATH_BG))
+ borderLabel.setFixedSize(304, 40)
+ gridLay = QGridLayout()
+ gridLay.addWidget(borderLabel, 0, 0, Qt.AlignCenter)
+ gridLay.addLayout(pathLayout, 0, 0, Qt.AlignCenter)
+
+ return gridLay
+
+ def _createBackupNameField(self):
+ label = QLabel("Backup Name:")
+ backupNameLayout = QHBoxLayout()
+ backupNameLayout.addWidget(label)
+ self.backupNameField = QLineEdit()
+ self.backupNameField.setObjectName("backupNameField")
+ self.backupNameField.setText("Backup")
+ backupNameLayout.addWidget(self.backupNameField,
+ Qt.AlignHCenter)
+ borderLabel = QLabel()
+ borderLabel.setPixmap(QPixmap(BACKUP_NAME_BG))
+ borderLabel.setFixedSize(304, 40)
+ gridLay = QGridLayout()
+ gridLay.addWidget(borderLabel, 0, 0, Qt.AlignCenter)
+ gridLay.addLayout(backupNameLayout, 0, 0, Qt.AlignCenter)
+
+ return gridLay
+
+ def _openFileDialog(self):
+ pathDialog = QFileDialog()
+ prompt = "Select the folder you wish to save your backup"
+ self.path = pathDialog.getExistingDirectory(self, prompt,
+ self._default_dir)
+ if self.path != "":
+ self.pathField.setText(self.path)
+
+ def _resetPage(self):
+ self.path = self._default_dir
+ self.pathField.setText(self._default_dir)
+ self.backupNameField.setText("Backup")
+
+ def getBackupName(self):
+ return str(self.backupNameField.text())
+
+ def getPath(self):
+ return str(self.pathField.text())
+