313aac4143bd6f0bea16444dda360437dac36796
[tablet-suite] / src / backup / .svn / text-base / pcsopenfilewizard.py.svn-base
1 # Authors: Amaury Medeiros and Paulo Ouriques
2 # Software License: GPL
3 import os
4 from functools import partial
5
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 *
13
14
15 class PcsOpenFileWizard(QWizardPage):
16     
17     _home_dir = os.path.expanduser("~")
18     _default_dir = _home_dir + "/.pcsuite/Backup"
19     
20     def __init__(self, deviceInfo, windowManager, parent = None):
21         QWizardPage.__init__(self, parent)
22         
23         self.path = self._default_dir
24         self.file_name = "Backup"
25         self.deviceInfo = deviceInfo
26         self.windowManager = windowManager
27         
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)
34         
35         wayLayout = self._wayLayout()
36         
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)
55         
56         self.setLayout(self.vLayout)
57
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)
64         for i in range(3):
65             but = QPushButton(infList[i][0])
66             but.setStyleSheet(infList[i][1])
67             if i <> 0:
68                 buttonsLayout.addWidget(but, Qt.AlignLeft)
69                 self.connect(but, SIGNAL("clicked()"), infList[i][2])
70             else:
71                 buttonsLayout.addWidget(but)
72         return buttonsLayout    
73     
74     def _wayLayout(self):
75         barLayout = QHBoxLayout()
76         barLayout.setMargin(0)
77         main = QLabel("<font style='color: #333333'; size=2>Main</font>")
78         arrow = self._arrow()
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))
90         return barLayout
91     
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())
97             backupManager.show()
98             self.wizard().close()
99             self.close()
100         else:
101             self._showNoDeviceFoundMessage()
102     
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())
108             restoreBackup.show()
109             self.wizard().close()
110             self.close()
111         else:
112             self._showNoDeviceFoundMessage()
113     
114     def _showNoDeviceFoundMessage(self):
115         inf = QMessageBox(self)
116         inf.setWindowTitle("Connect a device.")
117         inf.setText("No devices were found.")
118         inf.show()
119     
120     def _arrow(self):
121         label = QLabel()
122         label.setPixmap(QPixmap(BLACK_ARROW))
123         return label   
124      
125     def _createDeviceWidget(self):
126         deviceWidget = PcsDeviceWidget(3)
127         deviceWidget.addBorder()
128         deviceWidget.addDeviceName()
129         deviceWidget.setDeviceInfo(self.deviceInfo)
130
131         return deviceWidget
132     
133     def _createInformationsLabel(self):
134         hLay = QHBoxLayout()
135         spc = QSpacerItem(10, 0)
136         infLabel = QLabel("<font style='color:"\
137                              "#333333'; size=2>"\
138                              "Do backup from Device to your PC.</font>")
139         iconAlert = QLabel()
140         iconAlert.setPixmap(QPixmap(ICON_ALERT))
141         hLay.addItem(spc)
142         hLay.addWidget(iconAlert)
143         hLay.addWidget(infLabel, Qt.AlignLeft)
144         
145         
146         return hLay
147
148     def _createCenterLayout(self):
149         hLay = QHBoxLayout()
150         hLay.setMargin(0)
151         vLay = QVBoxLayout()
152         vLay.setMargin(0)
153         hLayWithSpacer = QHBoxLayout()
154         hLayWithSpacer.setMargin(0)
155         spc = QSpacerItem(62, 0)
156         
157         deviceWidget = self._createDeviceWidget()
158         arrowLabel = self._createArrowLabel()
159         pcLabel = self._createPcLabel()
160         pathField = self._createPathField()
161         nameField = self._createBackupNameField()
162         
163         hLay.addWidget(deviceWidget, Qt.AlignVCenter)
164         hLay.addLayout(arrowLabel, Qt.AlignVCenter)
165         hLay.addLayout(pcLabel, Qt.AlignVCenter)
166         
167         vLay.addLayout(nameField)
168         vLay.addLayout(hLay)
169         vLay.addLayout(pathField)
170         
171         hLayWithSpacer.addItem(spc)
172         hLayWithSpacer.addLayout(vLay)
173         hLayWithSpacer.addItem(spc)
174         
175         return hLayWithSpacer
176
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)
186         return arrowLayout
187
188     def _createPcLabel(self):
189         gridLay = QGridLayout()
190         pcLabelLayout = QGridLayout()
191         pcLabel = QLabel()
192         pcLabel.setPixmap(QPixmap(PC_IMAGE))
193         pcBorder = QLabel()
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)
205         return pcLabelLayout
206
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)
218         
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)
225         
226         return gridLay
227         
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, 
236                                           Qt.AlignHCenter)
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)
243         
244         return gridLay
245       
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, 
250                                                      self._default_dir)
251         if self.path != "":
252             self.pathField.setText(self.path)
253         
254     def _resetPage(self):
255         self.path = self._default_dir
256         self.pathField.setText(self._default_dir)
257         self.backupNameField.setText("Backup")
258     
259     def getBackupName(self):
260         return str(self.backupNameField.text())
261     
262     def getPath(self):
263         return str(self.pathField.text())
264