Initial commit (Vesion 0.1)
[tablet-suite] / src / backup / pcsbackup.py
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.pcsapp import PcsApp
8 from ui.pcsdevicewidget import PcsDeviceWidget
9 from ui.pcsuiutils import *
10 from ui.pcsbutton import *
11 from ui.tsuigeneralmethods import *
12
13 from ui.pcscustombuttons import PcsCustomButton as customButton
14
15 from pcswindowmanager import *
16
17 class PcsBackup(PcsApp):
18     
19     def __init__(self, deviceInfo, parent=None):
20         PcsApp.__init__(self, parent)
21         self.deviceInfo = deviceInfo
22         
23         if (self.deviceInfo != None):
24             self.windowManager = PcsWindowManager(self.deviceInfo, self)
25         
26         self.setWindowIcon(QIcon(BACKUP_IMAGE))
27         self.setWindowTitle("%s Backup" % APPLICATION_NAME)
28
29         self.hLayout = QHBoxLayout()
30         self.hLayout.setMargin(8)
31         self.vLayout = QVBoxLayout()
32         
33         spc = QSpacerItem(0,50)
34         self.optionsLayout = QVBoxLayout()
35         self.optionsLayout.addItem(spc)
36         self._addButtons()
37         self.optionsLayout.addItem(spc)
38         
39         self.deviceWidget = PcsDeviceWidget(1)
40         self.deviceWidget.addBorder()
41         self.deviceWidget.addDeviceName()
42         self.deviceWidget.setDeviceInfo(self.deviceInfo)
43         
44         self.optionsBorderLayout = QGridLayout()
45         self.optionsBorderLabel = QLabel()
46         self.optionsBorderLabel.setFixedSize(208, 205)
47         self.optionsBorderLabel.setPixmap(QPixmap(DEVICE_BACKUP_BORDER))
48         self.optionsBorderLayout.addWidget(self.optionsBorderLabel, 0, 0, Qt.AlignCenter)
49         self.optionsBorderLayout.addLayout(self.optionsLayout, 0, 0, Qt.AlignCenter)
50         self.hLayout.addLayout(self.optionsBorderLayout)
51         self.hLayout.addWidget(self.deviceWidget)
52         
53         #FIXE ME
54         l1 = QLabel("<font style='color: #333333'; size=2>Main</font>")
55         self.vLayout.addItem(TOP_SPACER)
56         self.vLayout.addWidget(l1)
57         self.vLayout.addLayout(self.hLayout)
58         informationLayout = QHBoxLayout()
59         spc = QSpacerItem(10, 0)
60         iconAlert = QLabel()
61         iconAlert.setPixmap(QPixmap(ICON_ALERT))
62         information = QLabel("<font style='color:"\
63                              "#333333'; size=2>"\
64                              "Select an action.</font>")
65         informationLayout.addItem(spc)
66         informationLayout.addWidget(iconAlert)
67         informationLayout.addWidget(information, Qt.AlignLeft)
68         self.vLayout.addLayout(informationLayout)
69         self.vLayout.setMargin(8)
70         self.setLayout(self.vLayout)
71         
72     def openBackupWizard(self):
73
74         if(self.deviceInfo and self.deviceInfo.ip != None):
75             backup_wizard = self.windowManager.getNewBackup()
76             centralize(backup_wizard)
77             backup_wizard.setGeometry(self.geometry())
78             backup_wizard.exec_()
79             self.setVisible(False)
80             self.setGeometry(backup_wizard.geometry())
81         else:
82             showMessageBox("No devices were found.", "")
83
84     def openBackupManagerDialog(self):
85         if(self.deviceInfo and self.deviceInfo.ip != None):
86             backupManager = self.windowManager.getBackupManager()
87             centralize(backupManager)
88             backupManager.show()
89             self.setVisible(False)
90         else:
91             showMessageBox("No devices were found.", "")
92             
93     def openRestoreBackupDialog(self):
94         if(self.deviceInfo and self.deviceInfo.ip != None):
95             restoreBackup = self.windowManager.getRestoreBackup()
96             centralize(restoreBackup)
97             restoreBackup.show()
98             self.setVisible(False)
99         else:
100             showMessageBox("No devices were found.", "")
101         
102     def _addButtons(self):
103         infList = [("New Backup       ", ICON_NEW_BACKUP), 
104                    ("Manage Backups", ICON_MANAGER_BACKUP),
105                    ("Restore Backups  ", ICON_RESTORE_BACKUP)]
106         buttonsList = []
107         for inf in infList:
108             buttonOptions = PcsButton(inf[0])
109             buttonOptions.setStyleSheet("background-image\
110             :url("+ BUTTON_WITH_ICON_BG +");\
111              qproperty-icon:url("+inf[1]+");\
112              min-height:50px; min-width:188px;\
113              max-height:50px; max-width:188px;\
114              qproperty-iconSize: 43px 36px")
115             self.optionsLayout.addWidget(buttonOptions)
116             buttonsList.append(buttonOptions)
117             
118         self.connect(buttonsList[0], SIGNAL("clicked()"),
119                      self.openBackupWizard)
120         self.connect(buttonsList[1], SIGNAL("clicked()"),
121                     self.openBackupManagerDialog)
122         self.connect(buttonsList[2], SIGNAL("clicked()"),
123                       self.openRestoreBackupDialog) 
124