update sv, hy, lt, pl, fr language
[enigma2.git] / lib / python / Screens / HarddiskSetup.py
1 from Screen import Screen
2 from Components.ActionMap import ActionMap
3 from Components.Harddisk import harddiskmanager                 #global harddiskmanager
4 from Components.MenuList import MenuList
5 from Components.Label import Label
6 from Components.Pixmap import Pixmap
7 from Screens.MessageBox import MessageBox
8 from enigma import eTimer
9
10 class HarddiskWait(Screen):
11         def doInit(self):
12                 self.timer.stop()
13                 result = self.hdd.initialize()
14                 self.close(result)
15
16         def doCheck(self):
17                 self.timer.stop()
18                 result = self.hdd.check()
19                 self.close(result)
20
21         def __init__(self, session, hdd, type):
22                 Screen.__init__(self, session)
23                 self.hdd = hdd
24                 self.timer = eTimer()
25                 if type == HarddiskSetup.HARDDISK_INITIALIZE:
26                         text = _("Initializing Harddisk...")
27                         self.timer.callback.append(self.doInit)
28                 else:
29                         text = _("Checking Filesystem...")
30                         self.timer.callback.append(self.doCheck)
31                 self["wait"] = Label(text)
32                 self.timer.start(100)
33
34 class HarddiskSetup(Screen):
35         HARDDISK_INITIALIZE = 1
36         HARDDISK_CHECK = 2
37
38         def __init__(self, session, hdd, type = None):
39                 Screen.__init__(self, session)
40                 self.hdd = hdd
41
42                 if type not in [self.HARDDISK_INITIALIZE, self.HARDDISK_CHECK]:
43                         self.type = self.HARDDISK_INITIALIZE
44                 else:
45                         self.type = type
46
47                 self["model"] = Label(_("Model: ") + hdd.model())
48                 self["capacity"] = Label(_("Capacity: ") + hdd.capacity())
49                 self["bus"] = Label(_("Bus: ") + hdd.bus())
50                 self["initialize"] = Pixmap()
51
52                 if self.type == self.HARDDISK_INITIALIZE:
53                         text = _("Initialize")
54                 else:
55                         text = _("Check")
56                 self["initializetext"] = Label(text)
57
58                 self["actions"] = ActionMap(["OkCancelActions"],
59                 {
60                         "ok": self.close,
61                         "cancel": self.close
62                 })
63                 
64                 self["shortcuts"] = ActionMap(["ShortcutActions"],
65                 {
66                         "red": self.hddQuestion
67                 })
68
69         def hddReady(self, result):
70                 print "Result: " + str(result)
71                 if (result != 0):
72                         if self.type == self.HARDDISK_INITIALIZE:
73                                 message = _("Unable to initialize harddisk.\nError: ")
74                         else:
75                                 message = _("Unable to complete filesystem check.\nError: ")
76                         self.session.open(MessageBox, message + str(self.hdd.errorList[0 - result]), MessageBox.TYPE_ERROR)
77                 else:
78                         self.close()
79
80         def hddQuestion(self):
81                 if self.type == self.HARDDISK_INITIALIZE:
82                         message = _("Do you really want to initialize the harddisk?\nAll data on the disk will be lost!")
83                 else:
84                         message = _("Do you really want to check the filesystem?\nThis could take lots of time!")
85                 self.session.openWithCallback(self.hddConfirmed, MessageBox, message)
86
87         def hddConfirmed(self, confirmed):
88                 if not confirmed:
89                         return
90
91                 print "this will start either the initialize or the fsck now!"
92                 self.session.openWithCallback(self.hddReady, HarddiskWait, self.hdd, self.type)
93
94 class HarddiskSelection(Screen):
95         def __init__(self, session):
96                 Screen.__init__(self, session)
97                 
98                 if harddiskmanager.HDDCount() == 0:
99                         tlist = []
100                         tlist.append((_("no HDD found"), 0))
101                         self["hddlist"] = MenuList(tlist)
102                 else:                   
103                         self["hddlist"] = MenuList(harddiskmanager.HDDList())
104                 
105                 self["actions"] = ActionMap(["OkCancelActions"],
106                 {
107                         "ok": self.okbuttonClick ,
108                         "cancel": self.close
109                 })
110
111         def okbuttonClick(self):
112                 selection = self["hddlist"].getCurrent()
113                 if selection[1] != 0:
114                         self.session.open(HarddiskSetup, selection[1], HarddiskSetup.HARDDISK_INITIALIZE)
115
116 # This is actually just HarddiskSelection but with correct type
117 class HarddiskFsckSelection(HarddiskSelection):
118         def __init__(self, session):
119                 HarddiskSelection.__init__(self, session)
120                 self.skinName = "HarddiskSelection"
121
122         def okbuttonClick(self):
123                 selection = self["hddlist"].getCurrent()
124                 if selection[1] != 0:
125                         self.session.open(HarddiskSetup, selection[1], HarddiskSetup.HARDDISK_CHECK)