4 from functools import partial
6 from PyQt4.QtCore import *
7 from PyQt4.QtGui import *
9 from ui.pcsuiutils import *
10 from style.styleTabletSuite import *
12 from pcsprogresswizard import *
13 from pcscheckboxwizard import *
14 from pcsopenfilewizard import *
15 from pcspcbackupmanager import *
16 from pcsdevicemanager import *
18 class PcsBackupWizard(QWizard):
20 ''' Class that creates a wizard responsible for doing backup '''
22 def __init__(self, deviceInfo, windowManager, parent = None):
23 QWizard.__init__(self, parent)
24 self.windowManager = windowManager
25 self.deviceInfo = deviceInfo
26 stylesheet = '''QWizard{background-image:url('''+ BACKUP_BG + ''')};'''
27 self.setStyleSheet(stylesheet)
28 self.setWindowIcon(QIcon(BACKUP_IMAGE))
29 self.setWindowTitle("%s Backup" % APPLICATION_NAME)
30 self.setFixedSize(WINDOW_WIDTH,WINDOW_HEIGHT)
32 self.setButtonLayout([])
33 self.setWizardStyle(4)
35 self.checkboxPage = PcsCheckboxWizard(self.deviceInfo, windowManager, self)
36 self.addPage(self.checkboxPage)
38 self.chooseFilePage = PcsOpenFileWizard(self.deviceInfo, windowManager, self)
39 self.connect(self.chooseFilePage.finishButton, SIGNAL("clicked()"),
41 self.addPage(self.chooseFilePage)
43 self.progressWizard = PcsProgressWizard(self.deviceInfo,self, windowManager, self)
44 self.connect(self.progressWizard.cancelButton, SIGNAL("clicked()"),
46 self.connect(self.progressWizard.doneButton, SIGNAL("clicked()"), self._done)
47 self.connect(self.progressWizard, SIGNAL("destroyed()"), self.test)
48 self.addPage(self.progressWizard)
51 print "entrou caraiiiiii"
54 if(str(self.chooseFilePage.getBackupName()).strip() == ""):
55 message = "Your backup name can't be blank."
56 showMessageBox(message, "Backup name blank")
63 self.progressWizard._resetPage()
64 self.chooseFilePage._resetPage()
66 def doNewBackup(self):
68 hostIp = self.deviceInfo.ip
69 backupName = self.chooseFilePage.getBackupName()
70 backupPath = self.chooseFilePage.getPath()
71 categories = self.checkboxPage.getCategories()
72 self.backupManager = PcsPcBackupManager()
73 self.backupManager.loadBackups()
76 self._updateThread = UpdateBackupProgress(backupName, backupPath,
77 hostIp,categories, comments,
80 self.connect(self._updateThread, SIGNAL("backupFinished"),
82 self.connect(self._updateThread, SIGNAL("backupCanceled"),
84 self.connect(self._updateThread, SIGNAL("backupNameChanged"),
85 self._onBackupNameChanged)
86 self.connect(self._updateThread, SIGNAL("backupProgress"),
87 self._updateCategoriesAndProgress)
89 self._updateThread.start()
91 def _updateCategoriesAndProgress(self, information):
92 progress, category = information
93 self.progressWizard.setProgress(progress)
94 self.progressWizard.setCategory(category)
97 def _onBackupDone(self, info):
98 self.progressWizard.updateInfo(info[0], info[1])
99 self.progressWizard.progressDone()
100 self.windowManager.getBackupManager().pcListView.updateBackupList()
102 def _onBackupNameChanged(self, correct_name):
104 Check if backup name was changed and show message case positive.
106 nameChangeMessage = "Backup with same name was found in" + \
107 " backup list, Backup name changed to %s" \
109 showMessageBox(nameChangeMessage, "Backup name changed")
111 def _confirmsCancel(self):
113 Confirms the backup canceling.
115 dialog = QMessageBox()
116 dialog.setText("Do you really want cancel this backup?")
117 dialog.setStandardButtons(QMessageBox.Yes | QMessageBox.No)
118 dialog.setWindowFlags(Qt.FramelessWindowHint)
119 dialog.setStyleSheet(MESSAGE_BOX_DEFAULT)
121 if ret == QMessageBox.Yes:
122 self._onBackupCancel()
124 def _onBackupCancel(self):
126 Stops current backup process in backup manager.
127 Also, shows a message box informing about canceling.
130 self.progressWizard.progressCanceled()
131 self.backupManager.setBackupInProgress(False)
133 def setVisible (self, visible):
134 if(visible == False):
138 class UpdateBackupProgress(QThread):
140 def __init__(self, backupName, path, hostIp, categories, comment,
141 backupManager, progressWizard):
142 QThread.__init__(self)
144 self.backupName = backupName
147 self.categories = categories
148 self.comment = comment
149 self.backupManager = backupManager
153 self._backupFlag = True
155 self.correctName = self.backupManager._verify_backup_name(self.backupName)
156 self.nameChanged = self.correctName != self.backupName
158 self.connect(self.backupManager, SIGNAL("backupProgress"), self._reEmitSignal)
159 self.connect(self.backupManager, SIGNAL("backupDone"), self._onBackupDone)
160 res = self.backupManager.createBackup(self.correctName, self.path,
161 self.hostIp, self.categories,
164 while (self._backupFlag):
167 def _reEmitSignal(self, informations):
168 self.emit(SIGNAL("backupProgress"), informations)
170 def _onBackupDone(self, res, info):
171 self._backupFlag = False
172 # If backup was not canceled, emit done signal
175 self.emit(SIGNAL("backupNameChanged"), self.correctName)
176 self.emit(SIGNAL("backupFinished"), info)
178 self.emit(SIGNAL("backupCanceled"))