summaryrefslogtreecommitdiffstats
path: root/iw/partition_gui.py
blob: 871d4f600d229ebf33a369dff235ad38fd1464e5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
#
# partition_gui.py: allows the user to choose how to partition their disks
#
# Matt Wilson <msw@redhat.com>
# Michael Fulbright <msf@redhat.com>
#
# Copyright 2001 Red Hat, Inc.
#
# This software may be freely redistributed under the terms of the GNU
# library public license.
#
# You should have received a copy of the GNU Library Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#

import gobject
import gtk
import gnome.canvas
import pango
import autopart
import gui
import parted
import string
import copy
import types
import checklist
import raid
from iw_gui import *
from translate import _, N_
from partitioning import *
from partedUtils import *
from fsset import *

STRIPE_HEIGHT = 32.0
LOGICAL_INSET = 3.0
CANVAS_WIDTH_800 = 500
CANVAS_WIDTH_640 = 400
CANVAS_HEIGHT = 200
TREE_SPACING = 2

MODE_ADD = 1
MODE_EDIT = 2

# XXX this is made up and used by the size spinner; should just be set with
# a callback
MAX_PART_SIZE = 1024*1024*1024

class DiskStripeSlice:
    def eventHandler(self, widget, event):
        if event.type == gtk.gdk.BUTTON_PRESS:
            if event.button == 1:
                self.parent.selectSlice(self.partition, 1)
        elif event.type == gtk.gdk._2BUTTON_PRESS:
            self.editCb()
                
        return gtk.TRUE

    def shutDown(self):
        self.parent = None
        if self.group:
            self.group.destroy()
            self.group = None
        del self.partition

    def select(self):
        if self.partition.type != parted.PARTITION_EXTENDED:
            self.group.raise_to_top()
        self.box.set(outline_color="red")
        self.box.set(fill_color=self.selectColor())

    def deselect(self):
        self.box.set(outline_color="black", fill_color=self.fillColor())

    def getPartition(self):
        return self.partition

    def fillColor(self):
        if self.partition.type & parted.PARTITION_FREESPACE:
            return "grey88"
        return "white"

    def selectColor(self):
        if self.partition.type & parted.PARTITION_FREESPACE:
            return "cornsilk2"
        return "cornsilk1"

    def hideOrShowText(self):
        return
        if self.box.get_bounds()[2] < self.text.get_bounds()[2]:
            self.text.hide()
        else:
            self.text.show()

    def sliceText(self):
        if self.partition.type & parted.PARTITION_EXTENDED:
            return ""
        if self.partition.type & parted.PARTITION_FREESPACE:
            rc = "Free\n"
        else:
            rc = "%s\n" % (get_partition_name(self.partition),)
        rc = rc + "%d MB" % (getPartSizeMB(self.partition),)
        return rc

    def getDeviceName(self):
        return get_partition_name(self.partition)

    def update(self):
        disk = self.parent.getDisk()
        totalSectors = float(disk.dev.heads
                             * disk.dev.sectors
                             * disk.dev.cylinders)

        # XXX hack but will work for now
        if gtk.gdk.screen_width() > 640:
            width = CANVAS_WIDTH_800
        else:
            width = CANVAS_WIDTH_640

        xoffset = self.partition.geom.start / totalSectors * width
        xlength = self.partition.geom.length / totalSectors * width
        if self.partition.type & parted.PARTITION_LOGICAL:
            yoffset = 0.0 + LOGICAL_INSET
            yheight = STRIPE_HEIGHT - (LOGICAL_INSET * 2)
            texty = 0.0
        else:
            yoffset = 0.0
            yheight = STRIPE_HEIGHT
            texty = LOGICAL_INSET
        self.group.set(x=xoffset, y=yoffset)
        self.box.set(x1=0.0, y1=0.0, x2=xlength,
                     y2=yheight, fill_color=self.fillColor(),
                     outline_color='black', width_units=1.0)
        self.text.set(x=2.0, y=texty + 2.0, text=self.sliceText(),
                      fill_color='black',
                      anchor=gtk.ANCHOR_NW, clip=gtk.TRUE,
                      clip_width=xlength-1, clip_height=yheight-1)
        self.hideOrShowText()
       
    def __init__(self, parent, partition, treeView, editCb):
        self.text = None
        self.partition = partition
        self.parent = parent
        self.treeView = treeView
        self.editCb = editCb
        pgroup = parent.getGroup()

        self.group = pgroup.add(gnome.canvas.CanvasGroup)
        self.box = self.group.add(gnome.canvas.CanvasRect)
        self.group.connect("event", self.eventHandler)
        self.text = self.group.add(gnome.canvas.CanvasText,
                                    font="helvetica", size_points=8)
        self.update()

class DiskStripe:
    def __init__(self, drive, disk, group, tree, editCb):
        self.disk = disk
        self.group = group
        self.tree = tree
        self.drive = drive
        self.slices = []
        self.hash = {}
        self.editCb = editCb
        self.selected = None

        # XXX hack but will work for now
        if gtk.gdk.screen_width() > 640:
            width = CANVAS_WIDTH_800
        else:
            width = CANVAS_WIDTH_640
        
        group.add(gnome.canvas.CanvasRect, x1=0.0, y1=10.0, x2=width,
                  y2=STRIPE_HEIGHT, fill_color='green',
                  outline_color='grey71', width_units=1.0)
        group.lower_to_bottom()

    def shutDown(self):
        while self.slices:
            slice = self.slices.pop()
            slice.shutDown()
        if self.group:
            self.group.destroy()
            self.group = None
        del self.disk

    def holds(self, partition):
        return self.hash.has_key(partition)

    def getSlice(self, partition):
        return self.hash[partition]
   
    def getDisk(self):
        return self.disk

    def getDrive(self):
        return self.drive

    def getGroup(self):
        return self.group

    def selectSlice(self, partition, updateTree=0):
        self.deselect()
        slice = self.hash[partition]
        slice.select()

        # update selection of the tree
        if updateTree:
            self.tree.selectPartition(partition)
        self.selected = slice

    def deselect(self):
        if self.selected:
            self.selected.deselect()
        self.selected = None
    
    def add(self, partition):
        stripe = DiskStripeSlice(self, partition, self.tree, self.editCb)
        self.slices.append(stripe)
        self.hash[partition] = stripe

class DiskStripeGraph:
    def __init__(self, tree, editCb):
        self.canvas = gnome.canvas.Canvas()
        self.diskStripes = []
        self.textlabels = []
        self.tree = tree
        self.editCb = editCb
        self.next_ypos = 0.0

    def __del__(self):
        self.shutDown()
        
    def shutDown(self):
        # remove any circular references so we can clean up
        while self.diskStripes:
            stripe = self.diskStripes.pop()
            stripe.shutDown()

        while self.textlabels:
            lab = self.textlabels.pop()
            lab.destroy()

        self.next_ypos = 0.0

    def getCanvas(self):
        return self.canvas

    def selectSlice(self, partition):
        for stripe in self.diskStripes:
            stripe.deselect()
            if stripe.holds(partition):
                stripe.selectSlice(partition)

    def getSlice(self, partition):
        for stripe in self.diskStripes:
            if stripe.holds(partition):
                return stripe.getSlice(partition)

    def getDisk(self, partition):
        for stripe in self.diskStripes:
            if stripe.holds(partition):
                return stripe.getDisk()

    def add(self, drive, disk):
#        yoff = len(self.diskStripes) * (STRIPE_HEIGHT + 5)
        yoff = self.next_ypos
        text = self.canvas.root().add(gnome.canvas.CanvasText,
                                      x=0.0, y=yoff,
                                      font="sans",
                                      size_points=9)
        drivetext = ("Drive %s (Geom: %s/%s/%s) "
                     "(Model: %s)") % ('/dev/' + drive,
                                       disk.dev.cylinders,
                                       disk.dev.heads,
                                       disk.dev.sectors,
                                       disk.dev.model)
        text.set(text=drivetext, fill_color='black', anchor=gtk.ANCHOR_NW,
                 weight=pango.WEIGHT_BOLD)
        (xxx1, yyy1, xxx2, yyy2) =  text.get_bounds()
        textheight = yyy2 - yyy1
        self.textlabels.append(text)
        group = self.canvas.root().add(gnome.canvas.CanvasGroup,
                                       x=0, y=yoff+textheight)
        stripe = DiskStripe(drive, disk, group, self.tree, self.editCb)
        self.diskStripes.append(stripe)
        self.next_ypos = self.next_ypos + STRIPE_HEIGHT+textheight+10
        return stripe

class DiskTreeModelHelper:
    def __init__(self, model, columns, iter):
        self.model = model
        self.iter = iter
        self.columns = columns

    def __getitem__(self, key):
        if type(key) == types.StringType:
            key = self.columns[key]
        try:
            return self.model.get_value(self.iter, key)
        except:
            return None

    def __setitem__(self, key, value):
        if type(key) == types.StringType:
            key = self.columns[key]
        self.model.set_value(self.iter, key, value)

class DiskTreeModel(gtk.TreeStore):
    isLeaf = -3
    isFormattable = -2
    
    # format: column header, type, x alignment, hide?, visibleKey
    titles = ((N_("Device"), gobject.TYPE_STRING, 0.0, 0, 0),
              (N_("Start"), gobject.TYPE_STRING, 1.0, 0, 1),
              (N_("End"), gobject.TYPE_STRING, 1.0, 0, 1),
              (N_("Size (MB)"), gobject.TYPE_STRING, 1.0, 0, isLeaf),
              (N_("Type"), gobject.TYPE_STRING, 0.0, 0, 0),
              (N_("Mount Point"), gobject.TYPE_STRING, 0.0, 0, isLeaf),
              (N_("Format"), gobject.TYPE_BOOLEAN, 0.0, 0, isFormattable),
              # the following must be the last two
              ("IsLeaf", gobject.TYPE_BOOLEAN, 0.0, 1, 0),
              ("IsFormattable", gobject.TYPE_BOOLEAN, 0.0, 1, 0),
              ("PyObject", gobject.TYPE_PYOBJECT, 0.0, 1, 0))
    
    def __init__(self):
        self.titleSlot = {}
        i = 0
        types = [self]
        self.columns = []
        for title, kind, alignment, hide, key in self.titles:
            self.titleSlot[title] = i
            types.append(kind)
            if hide:
                i += 1
                continue
            elif kind == gobject.TYPE_BOOLEAN:
                renderer = gtk.CellRendererToggle()
                propertyMapping = {'active': i}
            elif (kind == gobject.TYPE_STRING or
                  kind == gobject.TYPE_INT):
                renderer = gtk.CellRendererText()
                propertyMapping = {'text': i}

            # wire in the cells that we want only visible on leaf nodes to
            # the special leaf node column.
            if key < 0:
                propertyMapping['visible'] = len(self.titles) + key
                
            renderer.set_property('xalign', alignment)
            col = apply(gtk.TreeViewColumn, (_(title), renderer),
                        propertyMapping)
            self.columns.append(col)
            i += 1

        apply(gtk.TreeStore.__init__, types)

        self.view = gtk.TreeView(self)
        # append all of the columns
        map(self.view.append_column, self.columns)

    def getTreeView(self):
        return self.view

    def selectPartition(self, partition):
        pyobject = self.titleSlot['PyObject']
        iter = self.get_iter_root()
        next = 1
	parentstack = []
	parent = None
        # iterate over the list, looking for the current mouse selection
        while next:
            # if this is a parent node, get the first child and iter over them
            if self.iter_has_child(iter):
		parent = iter
                parentstack.append(parent)
                iter = self.iter_children(parent)
                continue
            # if it's not a parent node and the mouse matches, select it.
            elif self.get_value(iter, pyobject) == partition:
                path = self.get_path(parent)
                self.view.expand_row(path, gtk.TRUE)
                selection = self.view.get_selection()
                selection.unselect_all()
                selection.select_iter(iter)
                path = self.get_path(iter)
                col = self.view.get_column(0)
                self.view.set_cursor(path, col, gtk.FALSE)
                self.view.scroll_to_cell(path, col, gtk.TRUE, 0.5, 0.5)
                return
            # get the next row.
            next = self.iter_next(iter)
            # if there isn't a next row and we had a parent, go to the node
            # after the parent we've just gotten the children of.
            if not next and parent:
		while not next and parent:
		    next = self.iter_next(parent)
		    iter = parent
		    if len(parentstack) > 0:
			parent = parentstack.pop()

    def getCurrentPartition(self):
        selection = self.view.get_selection()
        rc = selection.get_selected()
        if rc:
            model, iter = rc
        else:
            return None

        pyobject = self.titleSlot['PyObject']
	try:
	    return self.get_value(iter, pyobject)
        except:
            return None

    def resetSelection(self):
        pass
##         selection = self.view.get_selection()
##         selection.set_mode(gtk.SELECTION_SINGLE)
##         selection.set_mode(gtk.SELECTION_BROWSE)

    def clear(self):
        selection = self.view.get_selection()
        selection.unselect_all()
        gtk.TreeStore.clear(self)
        
    def __getitem__(self, iter):
        if type(iter) == gtk.TreeIter:
            return DiskTreeModelHelper(self, self.titleSlot, iter)
        raise KeyError, iter


# this should probably go into a class
# some helper functions for build UI components
def createAlignedLabel(text):
    label = gtk.Label(text)
    label.set_alignment(0.0, 0.0)

    return label

def createMountPointCombo(request):
    mountCombo = gtk.Combo()
    mountCombo.set_popdown_strings(defaultMountPoints)

    mountpoint = request.mountpoint

    if request.fstype and request.fstype.isMountable():
        mountCombo.set_sensitive(1)
        if mountpoint:
            mountCombo.entry.set_text(mountpoint)
        else:
            mountCombo.entry.set_text("")
    else:
        mountCombo.entry.set_text(_("<Not Applicable>"))
        mountCombo.set_sensitive(0)

    mountCombo.set_data("saved_mntpt", None)

    return mountCombo

def setMntPtComboStateFromType(fstype, mountCombo):
    prevmountable = mountCombo.get_data("prevmountable")
    mountpoint = mountCombo.get_data("saved_mntpt")

    if prevmountable and fstype.isMountable():
        return

    if fstype.isMountable():
        mountCombo.set_sensitive(1)
        if mountpoint != None:
            mountCombo.entry.set_text(mountpoint)
        else:
            mountCombo.entry.set_text("")
    else:
        if mountCombo.entry.get_text() != _("<Not Applicable>"):
            mountCombo.set_data("saved_mntpt", mountCombo.entry.get_text())
        mountCombo.entry.set_text(_("<Not Applicable>"))
        mountCombo.set_sensitive(0)

    mountCombo.set_data("prevmountable", fstype.isMountable())
    
def fstypechangeCB(widget, mountCombo):
    fstype = widget.get_data("type")
    setMntPtComboStateFromType(fstype, mountCombo)

class DriveCheckList(checklist.CheckList):
    def __init__(self, columns, store):
	checklist.CheckList.__init__(self, columns=columns,
				     custom_store = store)

	selection = self.get_selection()
	selection.set_mode(gtk.SELECTION_NONE)

	# make checkbox column wider
	column = self.get_column(0)
	column.set_fixed_width(75)
	column.set_alignment(0.0)

class RaidCheckList(checklist.CheckList):
    def __init__(self, columns, store):
	checklist.CheckList.__init__(self, columns=columns,
				     custom_store = store)

	selection = self.get_selection()
	selection.set_mode(gtk.SELECTION_NONE)

	# make checkbox column wider
	column = self.get_column(0)
	column.set_fixed_width(75)
	column.set_alignment(0.0)

def createAllowedDrivesList(disks, reqdrives):
    store = gtk.TreeStore(gobject.TYPE_BOOLEAN,
			  gobject.TYPE_STRING,
			  gobject.TYPE_STRING,
			  gobject.TYPE_STRING)
    drivelist = DriveCheckList(3, store)

    driverow = 0
    drives = disks.keys()
    drives.sort()
    for drive in drives:
        size = getDeviceSizeMB(disks[drive].dev)
	selected = 0
        if reqdrives:
            if drive in reqdrives:
		selected = 1
        else:
	    selected = 1

	sizestr = "%8.0f MB" % size
	drivelist.append_row((drive, sizestr, disks[drive].dev.model),selected)

    return drivelist

def createAllowedRaidPartitionsList(allraidparts, reqraidpart):

    store = gtk.TreeStore(gobject.TYPE_BOOLEAN,
			  gobject.TYPE_STRING,
			  gobject.TYPE_STRING)
    partlist = RaidCheckList(2, store)

    sw = gtk.ScrolledWindow()
    sw.add(partlist)
    sw.set_policy(gtk.POLICY_NEVER, gtk.POLICY_AUTOMATIC)
    sw.set_shadow_type(gtk.SHADOW_IN)

    partrow = 0
    for part, size, used in allraidparts:
        partname = "%s" % part
	partsize = "%8.0f MB" % size
        if used or not reqraidpart:
            selected = 1
	else:
	    selected = 0

	partlist.append_row((partname, partsize), selected)

    return (partlist, sw)

def createAllowedLvmPartitionsList(alllvmparts, reqlvmpart):

    store = gtk.TreeStore(gobject.TYPE_BOOLEAN,
			  gobject.TYPE_STRING,
			  gobject.TYPE_STRING)
    partlist = RaidCheckList(2, store)

    sw = gtk.ScrolledWindow()
    sw.add(partlist)
    sw.set_policy(gtk.POLICY_NEVER, gtk.POLICY_AUTOMATIC)
    sw.set_shadow_type(gtk.SHADOW_IN)

    for part, size, used in alllvmparts:
        partname = "%s" % part
	partsize = "%8.0f MB" % size
        if used or not reqlvmpart:
            selected = 1
	else:
	    selected = 0

	partlist.append_row((partname, partsize), selected)

    return (partlist, sw)

def createRaidLevelMenu(levels, reqlevel, raidlevelchangeCB, sparesb):
    leveloption = gtk.OptionMenu()
    leveloptionmenu = gtk.Menu()
    defindex = None
    i = 0
    for lev in levels:
        item = gtk.MenuItem(lev)
        item.set_data("level", lev)
        # XXX gtk bug, if you don't show then the menu will be larger
        # than the largest menu item
        item.show()        
        leveloptionmenu.add(item)
        if reqlevel and lev == reqlevel:
            defindex = i
        if raidlevelchangeCB and sparesb:
            item.connect("activate", raidlevelchangeCB, sparesb)
        i = i + 1

    leveloption.set_menu(leveloptionmenu)
    
    if defindex:
        leveloption.set_history(defindex)

    if reqlevel and reqlevel == "RAID0":
        sparesb.set_sensitive(0)
        
    return (leveloption, leveloptionmenu)

# pass in callback for when fs changes because of python scope issues
def createFSTypeMenu(fstype, fstypechangeCB, mountCombo,
                     availablefstypes = None, ignorefs = None):
    fstypeoption = gtk.OptionMenu()
    fstypeoptionMenu = gtk.Menu()
    types = fileSystemTypeGetTypes()
    if availablefstypes:
        names = availablefstypes
    else:
        names = types.keys()
    if fstype and fstype.isSupported() and fstype.isFormattable():
        default = fstype
    else:
        default = fileSystemTypeGetDefault()
        
    names.sort()
    defindex = None
    i = 0
    for name in names:
        if not fileSystemTypeGet(name).isSupported():
            continue

        if ignorefs and name in ignorefs:
            continue
        
        if fileSystemTypeGet(name).isFormattable():
            item = gtk.MenuItem(name)
            item.set_data("type", types[name])
            # XXX gtk bug, if you don't show then the menu will be larger
            # than the largest menu item
            item.show()
            fstypeoptionMenu.add(item)
            if default and default.getName() == name:
                defindex = i
                defismountable = types[name].isMountable()
            if fstypechangeCB and mountCombo:
                item.connect("activate", fstypechangeCB, mountCombo)
            i = i + 1

    fstypeoption.set_menu(fstypeoptionMenu)

    if defindex:
        fstypeoption.set_history(defindex)

    if mountCombo:
        mountCombo.set_data("prevmountable",
                            fstypeoptionMenu.get_active().get_data("type").isMountable())

    return (fstypeoption, fstypeoptionMenu)

def raidlevelchangeCB(widget, sparesb):
    raidlevel = widget.get_data("level")
    numparts = sparesb.get_data("numparts")
    maxspares = raid.get_raid_max_spares(raidlevel, numparts)
    if maxspares > 0 and raidlevel != "RAID0":
        sparesb.set_sensitive(1)
        adj = sparesb.get_adjustment()
        value = adj.value
        if adj.value > maxspares:
            value = maxspares
        adj.set_value(value)
        adj.clamp_page(0, maxspares)
        sparesb.set_adjustment(adj)
        sparesb.set_value(value)
        
    else:
        sparesb.set_value(0)
        sparesb.set_sensitive(0)

class PartitionWindow(InstallWindow):
    def __init__(self, ics):
	InstallWindow.__init__(self, ics)
        ics.setTitle(_("Disk Setup"))
        ics.setNextEnabled(gtk.TRUE)
        ics.readHTML("partition")
        self.parent = ics.getICW().window

    def quit(self):
        pass

    def presentPartitioningComments(self, type,
                                    title, labelstr1, labelstr2, comments):
        win = gtk.Dialog(title)
        gui.addFrame(win)
        
        if type == "ok":
            win.add_button('gtk-ok', 1)
        elif type == "yesno":
            win.add_button('gtk-yes', 1)
            win.add_button('gtk-no', 2)

        image = gtk.Image()
        image.set_from_stock('gtk-dialog-warning', gtk.ICON_SIZE_DIALOG)
        hbox = gtk.HBox(gtk.FALSE)
        hbox.pack_start(image, gtk.FALSE)

        buffer = gtk.TextBuffer(None)
        buffer.set_text(comments)
        text = gtk.TextView()
        text.set_buffer(buffer)
        text.set_property("editable", gtk.FALSE)
        text.set_property("cursor_visible", gtk.FALSE)
        text.set_wrap_mode(gtk.WRAP_WORD)
        
        sw = gtk.ScrolledWindow()
        sw.add(text)
        sw.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
        sw.set_shadow_type(gtk.SHADOW_IN)
        
        info1 = gtk.Label(labelstr1)
        info1.set_line_wrap(gtk.TRUE)
#        info1.set_size_request(300, -1)

        info2 = gtk.Label(labelstr2)
        info2.set_line_wrap(gtk.TRUE)
#        info2.set_size_request(300, -1)
        
        vbox = gtk.VBox(gtk.FALSE)
        vbox.pack_start(info1, gtk.FALSE)
        vbox.pack_start(sw, gtk.TRUE)
        vbox.pack_start(info2, gtk.FALSE)
        hbox.pack_start(vbox, gtk.FALSE)

        win.vbox.pack_start(hbox)
#        win.set_size_request(400,300)
        win.set_position(gtk.WIN_POS_CENTER)
        win.show_all()
        rc = win.run()
        win.destroy()
        return rc
        
    def getNext(self):
        (errors, warnings) = sanityCheckAllRequests(self.partitions,
                                                    self.diskset)

        if errors:
            labelstr1 =  _("The following critical errors exist "
                           "with your requested partitioning "
                           "scheme.")
            labelstr2 = _("These errors must be corrected prior "
                          "to continuing with your install of "
                          "Red Hat Linux.")

            commentstr = string.join(errors, "\n\n")
            
            self.presentPartitioningComments("ok",
                                             _("Partitioning Errors"),
                                             labelstr1, labelstr2,
                                             commentstr)
            raise gui.StayOnScreen
        
        if warnings:
            labelstr1 = _("The following warnings exist with "
                         "your requested partition scheme.")
            labelstr2 = _("Would you like to continue with "
                         "your requested partitioning "
                         "scheme?")
            
            commentstr = string.join(warnings, "\n\n")
            rc = self.presentPartitioningComments("yesno",
                                                  _("Partitioning Warnings"),
                                                  labelstr1, labelstr2,
                                                  commentstr)
            if rc != 1:
                raise gui.StayOnScreen

        formatWarnings = getPreExistFormatWarnings(self.partitions,
                                                   self.diskset)
        if formatWarnings:
            labelstr1 = _("The following pre-existing partitions have been "
                          "selected to be formatted, destroying all data.")

            labelstr2 = _("Select 'Yes' to continue and format these "
                          "partitions, or 'No' to go back and change these "
                          "settings.")

            commentstr = ""
            for (dev, type, mntpt) in formatWarnings:
                commentstr = commentstr + \
                        "/dev/%s         %s         %s\n" % (dev,type,mntpt)

            rc = self.presentPartitioningComments("yesno",
                                                  _("Format Warnings"),
                                                  labelstr1, labelstr2,
                                                  commentstr)
            if rc != 1:
                raise gui.StayOnScreen

        
        self.diskStripeGraph.shutDown()
        self.tree.clear()
        del self.parent
        return None

    def getPrev(self):
        self.diskStripeGraph.shutDown()
        self.tree.clear()
        del self.parent
        return None
    
    def populate(self, initial = 0):
        drives = self.diskset.disks.keys()
        drives.sort()

        self.tree.resetSelection()
        
	# first do LVM
        lvmrequests = self.partitions.getLVMRequests()
        if lvmrequests:
#
# XXX this breaks when we try to refresh tree after a refresh
#
# XXX - this breaks self.refresh calls!!!	
#	    lvmparent = self.tree.append(None)
#	    self.tree[lvmparent]['Device'] = _("LVM Physical Volumes")
            lvmparent = None
            for vgname in lvmrequests.keys():
                vgparent = self.tree.append(lvmparent)
		self.tree[vgparent]['Device'] = _("LVM: %s") % (vgname,)
		vgrequest = self.partitions.getRequestByVolumeGroupName(vgname)
		rsize = requestSize(vgrequest, self.diskset)
		print "volume group %s size is %g" % (vgname, rsize)
		self.tree[vgparent]['Start'] = ""
		self.tree[vgparent]['End'] = ""
		self.tree[vgparent]['Size (MB)'] = "%g" % (rsize,)
		self.tree[vgparent]['Type'] = _("LVM Volume Group")
		self.tree[vgparent]['Mount Point'] = ""
                self.tree[vgparent]['PyObject'] = str(vgrequest.uniqueID)
		for lvrequest in lvmrequests[vgname]:
		    iter = self.tree.append(vgparent)
		    self.tree[iter]['Device'] = lvrequest.logicalVolumeName
		    self.tree[iter]['Mount Point'] = lvrequest.mountpoint
		    self.tree[iter]['Size (MB)'] = "%g" % (lvrequest.size,)
		    self.tree[iter]['PyObject'] = str(lvrequest.uniqueID)
		
                    ptype = lvrequest.fstype.getName()
                    self.tree[iter]['Format'] = gtk.TRUE
                    self.tree[iter]['IsFormattable'] = lvrequest.fstype.isFormattable()
		    self.tree[iter]['IsLeaf'] = gtk.TRUE
		    self.tree[iter]['Type'] = ptype
		    self.tree[iter]['Start'] = ""
		    self.tree[iter]['End'] = ""
#		    self.tree[iter]['Start'] = _("N/A")
#		    self.tree[iter]['End'] = _("N/A")

        # handle RAID next
        raidcounter = 0
        raidrequests = self.partitions.getRaidRequests()
        if raidrequests:
# XXX - this breaks self.refresh calls!!!	
#	    raidparent = self.tree.append(None)
#	    self.tree[raidparent]['Device'] = _("RAID Devices")
            raidparent = None
            for request in raidrequests:
                iter = self.tree.append(raidparent)

                if request and request.mountpoint:
                    self.tree[iter]["Mount Point"] = request.mountpoint
                if request.fstype:
                    ptype = request.fstype.getName()
                    
                    self.tree[iter]['Format'] = request.format
                    self.tree[iter]['IsFormattable'] = request.fstype.isFormattable()
                else:
                    ptype = _("None")
                    self.tree[iter]['IsFormattable'] = gtk.FALSE

                device = _("RAID Device %s"  % (str(raidcounter)))
                self.tree[iter]['IsLeaf'] = gtk.TRUE
                self.tree[iter]['Device'] = device
                self.tree[iter]['Type'] = ptype
#		self.tree[iter]['Start'] = _("N/A")
#		self.tree[iter]['End'] = _("N/A")
                self.tree[iter]['Start'] = ""
                self.tree[iter]['End'] = ""
                self.tree[iter]['Size (MB)'] = "%g" % (request.size,)
                self.tree[iter]['PyObject'] = str(request.uniqueID)

                raidcounter = raidcounter + 1
                
	# now normal partitions
# XXX - this breaks self.refresh calls!!!	
#	drvparent = self.tree.append(None)
#	self.tree[drvparent]['Device'] = _("Hard Drives")
	drvparent=None
        for drive in drives:
            disk = self.diskset.disks[drive]

            # add a disk stripe to the graph
            stripe = self.diskStripeGraph.add(drive, disk)

            # add a parent node to the tree
            parent = self.tree.append(drvparent)
            self.tree[parent]['Device'] = '/dev/%s' % (drive,)
            sectorsPerCyl = disk.dev.heads * disk.dev.sectors

            extendedParent = None
            part = disk.next_partition()
            while part:
                if part.type & parted.PARTITION_METADATA:
                    part = disk.next_partition(part)
                    continue

                stripe.add(part)
                device = get_partition_name(part)
                request = self.partitions.getRequestByDeviceName(device)

                if part.type == parted.PARTITION_EXTENDED:
                    if extendedParent:
                        raise RuntimeError, ("can't handle more than "
                                             "one extended partition per disk")
                    extendedParent = self.tree.append(parent)
                    iter = extendedParent
                elif part.type & parted.PARTITION_LOGICAL:
                    if not extendedParent:
                        raise RuntimeError, ("crossed logical partition "
                                             "before extended")
                    iter = self.tree.append(extendedParent)
                    self.tree[iter]['IsLeaf'] = gtk.TRUE
                else:
                    iter = self.tree.append(parent)
                    self.tree[iter]['IsLeaf'] = gtk.TRUE
                    
                if request and request.mountpoint:
                    self.tree[iter]['Mount Point'] = request.mountpoint
                else:
                    self.tree[iter]['Mount Point'] = ""

                if request and request.fstype:
                    self.tree[iter]['IsFormattable'] = request.fstype.isFormattable()
                
                if part.type & parted.PARTITION_FREESPACE:
                    ptype = _("Free space")
                elif part.type == parted.PARTITION_EXTENDED:
                    ptype = _("Extended")
                elif part.get_flag(parted.PARTITION_RAID) == 1:
                    ptype = _("software RAID")
                elif part.fs_type:
                    if request and request.fstype != None:
                        ptype = request.fstype.getName()
                        if ptype == "foreign":
                            ptype = map_foreign_to_fsname(part.native_type)
                    else:
                        ptype = part.fs_type.name
                    self.tree[iter]['Format'] = request.format
                else:
                    if request and request.fstype != None:
                        ptype = request.fstype.getName()
                        
                        if ptype == "foreign":
                            ptype = map_foreign_to_fsname(part.native_type)
                    else:
                        ptype = _("None")
                if part.type & parted.PARTITION_FREESPACE:
                    devname = _("Free")
                else:
                    devname = '/dev/%s' % (device,)
                self.tree[iter]['Device'] = devname
                self.tree[iter]['Type'] = ptype
                self.tree[iter]['Start'] = str(start_sector_to_cyl(disk.dev,
                                                                   part.geom.start))
                self.tree[iter]['End'] = str(end_sector_to_cyl(disk.dev,
                                                               part.geom.end))
                size = getPartSizeMB(part)
                if size < 1.0:
                    sizestr = "< 1"
                else:
                    sizestr = "%8.0f" % (size)
                self.tree[iter]['Size (MB)'] = sizestr
                self.tree[iter]['PyObject'] = part
                
                part = disk.next_partition(part)

        canvas = self.diskStripeGraph.getCanvas()
        apply(canvas.set_scroll_region, canvas.root().get_bounds())
        self.treeView.expand_all()

    def treeActivateCb(self, view, path, col):
        if self.tree.getCurrentPartition():
            self.editCb()
        
    def treeSelectCb(self, selection, *args):
        rc = selection.get_selected()
        if rc:
            model, iter = rc
        else:
            return
        partition = model[iter]['PyObject']
        if partition:
            self.diskStripeGraph.selectSlice(partition)

    def newCB(self, widget):
        # create new request of size 1M
        request = PartitionSpec(fileSystemTypeGetDefault(), REQUEST_NEW, 1)

        self.editPartitionRequest(request, isNew = 1)

    # edit a partition request
    # isNew implies that this request has never been successfully used before
    def editPartitionRequest(self, origrequest, isNew = 0):

        def formatOptionCB(widget, data):
            (menuwidget, menu, mntptcombo, ofstype) = data
            menuwidget.set_sensitive(widget.get_active())

            # inject event for fstype menu
            if widget.get_active():
                fstype = menu.get_active().get_data("type")
                setMntPtComboStateFromType(fstype, mntptcombo)
            else:
                setMntPtComboStateFromType(ofstype, mntptcombo)

        def noformatCB(widget, badblocks):
            badblocks.set_sensitive(widget.get_active())

        def sizespinchangedCB(widget, fillmaxszsb):
            size = widget.get_value_as_int()
            maxsize = fillmaxszsb.get_value_as_int()
            if size > maxsize:
                fillmaxszsb.set_value(size)

            # ugly got to be better way
            adj = fillmaxszsb.get_adjustment()
            adj.clamp_page(size, adj.upper)
            fillmaxszsb.set_adjustment(adj)

        def cylspinchangedCB(widget, data):
            (dev, startcylspin, endcylspin, bycyl_sizelabel) = data
            startsec = start_cyl_to_sector(dev,
                                           startcylspin.get_value_as_int())
            endsec = end_cyl_to_sector(dev, endcylspin.get_value_as_int())
            cursize = (endsec - startsec)/2048
            bycyl_sizelabel.set_text("%s" % (int(cursize))) 

        def fillmaxszCB(widget, spin):
            spin.set_sensitive(widget.get_active())

        # pass in CB defined above because of two scope limitation of python!
        def createSizeOptionsFrame(request, fillmaxszCB):
            frame = gtk.Frame(_("Additional Size Options"))
            sizeoptiontable = gtk.Table()
            sizeoptiontable.set_row_spacings(5)
            sizeoptiontable.set_border_width(4)
            
            fixedrb     = gtk.RadioButton(label=_("Fixed size"))
            fillmaxszrb = gtk.RadioButton(group=fixedrb,
                                          label=_("Fill all space up "
                                                  "to (MB):"))
            maxsizeAdj = gtk.Adjustment(value = 1, lower = 1,
                                        upper = MAX_PART_SIZE, step_incr = 1)
            fillmaxszsb = gtk.SpinButton(maxsizeAdj, digits = 0)
            fillmaxszsb.set_property('numeric', gtk.TRUE)
            fillmaxszhbox = gtk.HBox()
            fillmaxszhbox.pack_start(fillmaxszrb)
            fillmaxszhbox.pack_start(fillmaxszsb)
            fillunlimrb = gtk.RadioButton(group=fixedrb,
                                         label=_("Fill to maximum allowable "
                                                 "size"))

            fillmaxszrb.connect("toggled", fillmaxszCB, fillmaxszsb)

            # default to fixed, turn off max size spinbutton
            fillmaxszsb.set_sensitive(0)
            if request.grow:
                if request.maxSizeMB != None:
                    fillmaxszrb.set_active(1)
                    fillmaxszsb.set_sensitive(1)
                    fillmaxszsb.set_value(request.maxSizeMB)
                else:
                    fillunlimrb.set_active(1)
            else:
                fixedrb.set_active(1)

            sizeoptiontable.attach(fixedrb, 0, 1, 0, 1)
            sizeoptiontable.attach(fillmaxszhbox, 0, 1, 1, 2)
            sizeoptiontable.attach(fillunlimrb, 0, 1, 2, 3)
            
            frame.add(sizeoptiontable)

            return (frame, fixedrb, fillmaxszrb, fillmaxszsb)

        #
        # start of editPartitionRequest
        #


        dialog = gtk.Dialog(_("Add Partition"), self.parent)
        gui.addFrame(dialog)
        dialog.add_button('gtk-ok', 1)
        dialog.add_button('gtk-cancel', 2)
        dialog.set_position(gtk.WIN_POS_CENTER)
        
        maintable = gtk.Table()
        maintable.set_row_spacings(5)
        maintable.set_col_spacings(5)
        row = 0

        # see if we are creating a floating request or by cylinder
        if origrequest.type == REQUEST_NEW:
            newbycyl = origrequest.start != None

        # Mount Point entry
        maintable.attach(createAlignedLabel(_("Mount Point:")),
                                            0, 1, row, row + 1)
        mountCombo = createMountPointCombo(origrequest)
        maintable.attach(mountCombo, 1, 2, row, row + 1)
        row = row + 1

        # Partition Type
        if origrequest.type == REQUEST_NEW:
            maintable.attach(createAlignedLabel(_("Filesystem Type:")),
                             0, 1, row, row + 1)

            (newfstype, newfstypeMenu) = createFSTypeMenu(origrequest.fstype,
                                                          fstypechangeCB,
                                                          mountCombo)
            maintable.attach(newfstype, 1, 2, row, row + 1)
        else:
            maintable.attach(createAlignedLabel(_("Original Filesystem "
                                                  "Type:")),
                             0, 1, row, row + 1)

            if origrequest.origfstype:
                typestr = origrequest.origfstype.getName()
                if origrequest.origfstype.getName() == "foreign":
                    part = get_partition_by_name(self.diskset.disks,
                                                 origrequest.device)
                    typestr = map_foreign_to_fsname(part.native_type)
            else:
                typestr = _("Unknown")

            fstypelabel = gtk.Label(typestr)
            maintable.attach(fstypelabel, 1, 2, row, row + 1)
            newfstype = None
            newfstypeMenu = None
            
        row = row + 1

        # allowable drives
        if origrequest.type == REQUEST_NEW:
            if not newbycyl:
                maintable.attach(createAlignedLabel(_("Allowable Drives:")),
                                 0, 1, row, row + 1)

                driveview = createAllowedDrivesList(self.diskset.disks,
                                                      origrequest.drive)

                sw = gtk.ScrolledWindow()
                sw.add(driveview)
                sw.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
		sw.set_shadow_type(gtk.SHADOW_IN)
                maintable.attach(sw, 1, 2, row, row + 1)
		driveview.set_size_request(375, 80)
            else:
                maintable.attach(createAlignedLabel(_("Drive:")),
                                 0, 1, row, row + 1)
                maintable.attach(createAlignedLabel(origrequest.drive[0]),
                                 1, 2, row, row + 1)

            row = row + 1

        # original fs label
        if origrequest.type != REQUEST_NEW and origrequest.fslabel:
            maintable.attach(createAlignedLabel(_("Original Filesystem "
                                                  "Label:")),
                             0, 1, row, row + 1)
            fslabel = gtk.Label(origrequest.fslabel)
            maintable.attach(fslabel, 1, 2, row, row + 1)

            row = row + 1

        # size
        if origrequest.type == REQUEST_NEW:
            if not newbycyl:
                # Size specification
                maintable.attach(createAlignedLabel(_("Size (MB):")),
                                 0, 1, row, row + 1)
                sizeAdj = gtk.Adjustment(value = 1, lower = 1,
                                         upper = MAX_PART_SIZE, step_incr = 1)
                sizespin = gtk.SpinButton(sizeAdj, digits = 0)
                sizespin.set_property('numeric', gtk.TRUE)

                if origrequest.size:
                    sizespin.set_value(origrequest.size)

                maintable.attach(sizespin, 1, 2, row, row + 1)
                bycyl_sizelabel = None
            else:
                # XXX need to add partition by size and
                #     wire in limits between start and end
                dev = self.diskset.disks[origrequest.drive[0]].dev
                maintable.attach(createAlignedLabel(_("Size (MB):")),
                                 0, 1, row, row + 1)
                bycyl_sizelabel = createAlignedLabel("")
                maintable.attach(bycyl_sizelabel, 1, 2, row, row + 1)
                row = row + 1
                maintable.attach(createAlignedLabel(_("Start Cylinder:")),
                                 0, 1, row, row + 1)

                maxcyl = self.diskset.disks[origrequest.drive[0]].dev.cylinders
                cylAdj = gtk.Adjustment(value=origrequest.start,
                                        lower=origrequest.start,
                                        upper=maxcyl,
                                        step_incr=1)
                startcylspin = gtk.SpinButton(cylAdj, digits=0)
                startcylspin.set_property('numeric', gtk.TRUE)
                maintable.attach(startcylspin, 1, 2, row, row + 1)
                row = row + 1
                
                endcylAdj = gtk.Adjustment(value=origrequest.end,
                                           lower=origrequest.start,
                                           upper=maxcyl,
                                           step_incr=1)
                maintable.attach(createAlignedLabel(_("End Cylinder:")),
                                 0, 1, row, row + 1)
                endcylspin = gtk.SpinButton(endcylAdj, digits = 0)
                endcylspin.set_property('numeric', gtk.TRUE)
                maintable.attach(endcylspin, 1, 2, row, row + 1)

                startcylspin.connect("changed", cylspinchangedCB,
                            (dev, startcylspin, endcylspin, bycyl_sizelabel))
                endcylspin.connect("changed", cylspinchangedCB,
                             (dev, startcylspin, endcylspin, bycyl_sizelabel))
                
                startsec = start_cyl_to_sector(dev, origrequest.start)
                endsec = end_cyl_to_sector(dev, origrequest.end)
                cursize = (endsec - startsec)/2048
                bycyl_sizelabel.set_text("%s" % (int(cursize)))
        else:
            maintable.attach(createAlignedLabel(_("Size (MB):")),
                             0, 1, row, row + 1)
            sizelabel = gtk.Label("%d" % (origrequest.size))
            maintable.attach(sizelabel, 1, 2, row, row + 1)
            sizespin = None
            
        row = row + 1

        # format/migrate options for pre-existing partitions
        if origrequest.type == REQUEST_PREEXIST and origrequest.fstype:

            ofstype = origrequest.fstype
            
            maintable.attach(gtk.HSeparator(), 0, 2, row, row + 1)
            row = row + 1

            label = gtk.Label(_("How would you like to prepare the filesystem "
                               "on this partition?"))
            label.set_line_wrap(1)
            label.set_alignment(0.0, 0.0)
#            label.set_size_request(400, -1)

            maintable.attach(label, 0, 2, row, row + 1)
            row = row + 1
            
            noformatrb = gtk.RadioButton(label=_("Leave unchanged "
                                                 "(preserve data)"))
            noformatrb.set_active(1)
            maintable.attach(noformatrb, 0, 2, row, row + 1)
            row = row + 1

            formatrb = gtk.RadioButton(label=_("Format partition as:"),
                                       group = noformatrb)
            formatrb.set_active(0)
            if origrequest.format:
                formatrb.set_active(1)

            maintable.attach(formatrb, 0, 1, row, row + 1)
            (fstype, fstypeMenu) = createFSTypeMenu(ofstype,fstypechangeCB,
                                                    mountCombo)
            fstype.set_sensitive(formatrb.get_active())
            maintable.attach(fstype, 1, 2, row, row + 1)
            row = row + 1

            if not formatrb.get_active() and not origrequest.migrate:
                mountCombo.set_data("prevmountable", ofstype.isMountable())

            formatrb.connect("toggled", formatOptionCB, (fstype, fstypeMenu,
                                                         mountCombo, ofstype))

            if origrequest.origfstype.isMigratable():
                migraterb = gtk.RadioButton(label=_("Migrate partition to:"),
                                            group=noformatrb)
                migraterb.set_active(0)
                if origrequest.migrate:
                    migraterb.set_active(1)

                migtypes = origrequest.origfstype.getMigratableFSTargets()

                maintable.attach(migraterb, 0, 1, row, row + 1)
                (migfstype, migfstypeMenu)=createFSTypeMenu(ofstype,
                                                            None, None,
                                                   availablefstypes = migtypes)
                migfstype.set_sensitive(migraterb.get_active())
                maintable.attach(migfstype, 1, 2, row, row + 1)
                row = row + 1

                migraterb.connect("toggled", formatOptionCB, (migfstype,
                                                              migfstypeMenu,
                                                              mountCombo,
                                                              ofstype))
                
            else:
                migraterb = None

            badblocks = gtk.CheckButton(_("Check for bad blocks?"))
            badblocks.set_active(0)
            maintable.attach(badblocks, 0, 1, row, row + 1)
            formatrb.connect("toggled", noformatCB, badblocks)
            if not origrequest.format:
                badblocks.set_sensitive(0)

            if origrequest.badblocks:
                badblocks.set_active(1)
            
            row = row + 1
            
        else:
            noformatrb = None
            formatrb = None
            migraterb = None

        # size options
        if origrequest.type == REQUEST_NEW:
            if not newbycyl:
                (sizeframe, fixedrb, fillmaxszrb,
                 fillmaxszsb) = createSizeOptionsFrame(origrequest,
                                                       fillmaxszCB)
                sizespin.connect("changed", sizespinchangedCB, fillmaxszsb)

                maintable.attach(sizeframe, 0, 2, row, row + 1)
            else:
                # XXX need new by cyl options (if any)
                pass
            row = row + 1
        else:
            sizeoptiontable = None

        # create only as primary
        if origrequest.type == REQUEST_NEW:
            primonlycheckbutton = gtk.CheckButton(_("Force to be a primary "
                                                    "partition"))
            primonlycheckbutton.set_active(0)
            if origrequest.primary:
                primonlycheckbutton.set_active(1)
            maintable.attach(primonlycheckbutton, 0, 2, row, row+1)
            row = row + 1

            badblocks = gtk.CheckButton(_("Check for bad blocks"))
            badblocks.set_active(0)
            maintable.attach(badblocks, 0, 1, row, row + 1)
            row = row + 1
            if origrequest.badblocks:
                badblocks.set_active(1)
            
        # put main table into dialog
        dialog.vbox.pack_start(maintable)
        dialog.show_all()

        while 1:
            rc = dialog.run()

            # user hit cancel, do nothing
            if rc == 2:
                dialog.destroy()
                return

            if origrequest.type == REQUEST_NEW:
                # read out UI into a partition specification
                filesystem = newfstypeMenu.get_active().get_data("type")

                request = copy.copy(origrequest)
                request.fstype = filesystem
                request.format = gtk.TRUE
                
                if request.fstype.isMountable():
                    request.mountpoint = mountCombo.entry.get_text()
                else:
                    request.mountpoint = None
                    
                if primonlycheckbutton.get_active():
                    primonly = gtk.TRUE
                else:
                    primonly = None

                if badblocks and badblocks.get_active():
                    request.badblocks = gtk.TRUE
                else:
                    request.badblocks = None

                if not newbycyl:
                    if fixedrb.get_active():
                        grow = None
                    else:
                        grow = gtk.TRUE

                    if fillmaxszrb.get_active():
                        maxsize = fillmaxszsb.get_value_as_int()
                    else:
                        maxsize = None

		    allowdrives = []
		    model = driveview.get_model()
		    iter = model.get_iter_root()
		    next = 1
		    while next:
			val   = model.get_value(iter, 0)
			drive = model.get_value(iter, 1)

			if val:
			    allowdrives.append(drive)

			next = model.iter_next(iter)

                    if len(allowdrives) == len(self.diskset.disks.keys()):
                        allowdrives = None
			
                    request.size = sizespin.get_value_as_int()
                    request.drive = allowdrives
                    request.grow = grow
                    request.primary = primonly
                    request.maxSizeMB = maxsize
                else:
                    request.start = startcylspin.get_value_as_int()
                    request.end = endcylspin.get_value_as_int()

                    if request.end <= request.start:
                        self.intf.messageWindow(_("Error With Request"),
                                                _("The end cylinder must be "
                                                "greater than the start "
                                                "cylinder."))

                        continue

                err = sanityCheckPartitionRequest(self.partitions, request)
                if err:
                    self.intf.messageWindow(_("Error With Request"),
                                            "%s" % (err))
                    continue

            else:
                # preexisting partition, just set mount point and format flag
                request = copy.copy(origrequest)
                if formatrb:
                    request.format = formatrb.get_active()
                    if request.format:
                        request.fstype = fstypeMenu.get_active().get_data("type")
                    if badblocks and badblocks.get_active():
                        request.badblocks = gtk.TRUE
                    else:
                        request.badblocks = None
                        
                else:
                    request.format = 0
                    request.badblocks = None

                if migraterb:
                    request.migrate = migraterb.get_active()
                    if request.migrate:
                        request.fstype =migfstypeMenu.get_active().get_data("type")
                else:
                    request.migrate = 0

                # set back if we are not formatting or migrating
                if not request.format and not request.migrate:
                    request.fstype = origrequest.origfstype

                if request.fstype.isMountable():
                    request.mountpoint =  mountCombo.entry.get_text()
                else:
                    request.mountpoint = None

                err = sanityCheckPartitionRequest(self.partitions, request)
                if err:
                    self.intf.messageWindow(_("Error With Request"),
                                            "%s" % (err))
                    continue

#                if not origrequest.format and request.format:
#                    if not queryFormatPreExisting(self.intf):
#                        continue

                if (not request.format and
                    request.mountpoint and isFormatOnByDefault(request)):
                    if not queryNoFormatPreExisting(self.intf):
                        continue
            
            if not isNew:
                self.partitions.removeRequest(origrequest)

            self.partitions.addRequest(request)
            if self.refresh():
                # the add failed; remove what we just added and put
                # back what was there if we removed it
                self.partitions.removeRequest(request)
                if not isNew:
                    self.partitions.addRequest(origrequest)
                if self.refresh():
                    # this worked before and doesn't now...
                    raise RuntimeError, ("Returning partitions to state "
                                         "prior to edit failed")
            else:
                break

        dialog.destroy()

    def deleteCb(self, widget):
        curselection = self.tree.getCurrentPartition()

        if doDeletePartitionByRequest(self.intf, self.partitions, curselection):
            self.refresh()
            
    def resetCb(self, *args):
        if not confirmResetPartitionState(self.intf):
            return
        
        self.diskStripeGraph.shutDown()
        self.newFsset = self.fsset.copy()
        self.diskset.refreshDevices()
        self.partitions.setFromDisk(self.diskset)
        self.tree.clear()
        self.populate()

    def refresh(self):
        self.diskStripeGraph.shutDown()
        self.tree.clear()
        try:
            autopart.doPartitioning(self.diskset, self.partitions)
            rc = 0
        except PartitioningError, msg:
            self.intf.messageWindow(_("Error Partitioning"),
                   _("Could not allocate requested partitions: %s.") % (msg))
            rc = -1
        except PartitioningWarning, msg:
            # XXX somebody other than me should make this look better
            # XXX this doesn't handle the 'delete /boot partition spec' case
            #     (it says 'add anyway')
            dialog = gtk.MessageDialog(self.parent, 0, gtk.MESSAGE_ERROR,
                                       gtk.BUTTONS_NONE,
                                       _("Warning: %s.") % (msg))
            gui.addFrame(dialog)
            button = gtk.Button(_("_Modify Partition"))
            dialog.add_action_widget(button, 1)
            button = gtk.Button(_("_Continue"))
            dialog.add_action_widget(button, 2)
            dialog.set_position(gtk.WIN_POS_CENTER)

            dialog.show_all()
            rc = dialog.run()
            dialog.destroy()
            
            if rc == 1:
                rc = -1
            else:
                rc = 0
                req = self.partitions.getBootableRequest()
                if req:
                    req.ignoreBootConstraints = 1

        self.populate()
        return rc

    def editCb(self, *args):
        part = self.tree.getCurrentPartition()

        (type, request) = doEditPartitionByRequest(self.intf, self.partitions,
                                                   part)
        if request:
            if type == "RAID":
                self.editRaidRequest(request)
	    elif type == "LVMVG":
		self.editLVMVolumeGroup(request)
	    elif type == "LVMLV":
		vgrequest = self.partitions.getRequestByID(request.volumeGroup)
		self.editLVMVolumeGroup(vgrequest)
            elif type == "NEW":
		self.editPartitionRequest(request, isNew = 1)
            else:
                self.editPartitionRequest(request)

    # isNew implies that this request has never been successfully used before
    def editRaidRequest(self, raidrequest, isNew = 0):
        #
        # start of editRaidRuquest
        #
        availraidparts = get_available_raid_partitions(self.diskset,
                                                       self.partitions,
                                                       raidrequest)
        # if no raid partitions exist, raise an error message and return
        if len(availraidparts) < 2:
            dlg = gtk.MessageDialog(self.parent, 0, gtk.MESSAGE_ERROR,
                                    gtk.BUTTONS_OK,
                                    _("At least two software RAID "
                                      "partitions are needed."))
            gui.addFrame(dlg)
            dlg.show_all()
            dlg.set_position(gtk.WIN_POS_CENTER)
            dlg.run()
            dlg.destroy()
            return

        dialog = gtk.Dialog(_("Make RAID Device"), self.parent)
        gui.addFrame(dialog)
        dialog.add_button('gtk-ok', 1)
        dialog.add_button('gtk-cancel', 2)
        dialog.set_position(gtk.WIN_POS_CENTER)
        
        maintable = gtk.Table()
        maintable.set_row_spacings(5)
        maintable.set_col_spacings(5)
        row = 0

        # Mount Point entry
        maintable.attach(createAlignedLabel(_("Mount Point:")),
                                            0, 1, row, row + 1)
        mountCombo = createMountPointCombo(raidrequest)
        maintable.attach(mountCombo, 1, 2, row, row + 1)
        row = row + 1

        # Filesystem Type
        maintable.attach(createAlignedLabel(_("Filesystem type:")),
                                            0, 1, row, row + 1)

        (fstypeoption, fstypeoptionMenu) = createFSTypeMenu(raidrequest.fstype,
                                                            fstypechangeCB,
                                                            mountCombo,
                                                            ignorefs = ["software RAID"])
        maintable.attach(fstypeoption, 1, 2, row, row + 1)
            
        row = row + 1

        # raid level
        maintable.attach(createAlignedLabel(_("RAID Level:")),
                                            0, 1, row, row + 1)

        # Create here, pack below
        numparts =  len(availraidparts)
        if raidrequest.raidspares:
            nspares = raidrequest.raidspares
        else:
            nspares = 0
            
        if raidrequest.raidlevel:
            maxspares = raid.get_raid_max_spares(raidrequest.raidlevel, numparts)
        else:
            maxspares = 0

        spareAdj = gtk.Adjustment(value = nspares, lower = 0,
                                  upper = maxspares, step_incr = 1)
        sparesb = gtk.SpinButton(spareAdj, digits = 0)
        sparesb.set_data("numparts", numparts)

        if maxspares > 0:
            sparesb.set_sensitive(1)
        else:
            sparesb.set_value(0)
            sparesb.set_sensitive(0)

        (leveloption, leveloptionmenu) = createRaidLevelMenu(availRaidLevels,
                                                       raidrequest.raidlevel,
                                                       raidlevelchangeCB,
                                                       sparesb)
        maintable.attach(leveloption, 1, 2, row, row + 1)
            
        row = row + 1

        # raid members
        maintable.attach(createAlignedLabel(_("RAID Members:")),
                         0, 1, row, row + 1)

        # XXX need to pass in currently used partitions for this device
        (raidlist, sw) = createAllowedRaidPartitionsList(availraidparts,
						       raidrequest.raidmembers)

        raidlist.set_size_request(275, 80)
        maintable.attach(sw, 1, 2, row, row + 1)
        row = row + 1

        # number of spares - created widget above
        maintable.attach(createAlignedLabel(_("Number of spares:")),
                         0, 1, row, row + 1)
        maintable.attach(sparesb, 1, 2, row, row + 1)
        row = row + 1

        # format or not?
        if raidrequest.fstype and raidrequest.fstype.isFormattable():
            formatButton = gtk.CheckButton(_("Format partition?"))
            # XXX this probably needs more logic once we detect existing raid
            if raidrequest.format == None or raidrequest.format != 0:
                formatButton.set_active(1)
            else:
                formatButton.set_active(0)
            maintable.attach(formatButton, 0, 2, row, row + 1)
            row = row + 1

        else:
            formatButton = None
            
        # put main table into dialog
        dialog.vbox.pack_start(maintable)

        dialog.show_all()

        while 1:
            rc = dialog.run()

            # user hit cancel, do nothing
            if rc == 2:
                dialog.destroy()
                return

            # read out UI into a partition specification
            request = copy.copy(raidrequest)

            filesystem = fstypeoptionMenu.get_active().get_data("type")
            request.fstype = filesystem

            if request.fstype.isMountable():
                request.mountpoint = mountCombo.entry.get_text()
            else:
                request.mountpoint = None

	    raidmembers = []
	    model = raidlist.get_model()
	    iter = model.get_iter_root()
	    next = 1
	    while next:
		val   = model.get_value(iter, 0)
		part = model.get_value(iter, 1)

		if val:
		    req = self.partitions.getRequestByDeviceName(part)
		    raidmembers.append(req.uniqueID)

		next = model.iter_next(iter)

            request.raidmembers = raidmembers
            request.raidlevel = leveloptionmenu.get_active().get_data("level")
            if request.raidlevel != "RAID0":
                request.raidspares = sparesb.get_value_as_int()
            else:
                request.raidspares = 0
            
            if formatButton:
                request.format = formatButton.get_active()
            else:
                request.format = 0

            err = sanityCheckRaidRequest(self.partitions, request)
            if err:
                self.intf.messageWindow(_("Error With Request"),
                                        "%s" % (err))
                continue
            
            if not isNew:
                self.partitions.removeRequest(raidrequest)

            self.partitions.addRequest(request)
            
            if self.refresh():
                # how can this fail?  well, if it does, do the remove new,
                # add old back in dance
                self.partitions.removeRequest(request)
                if not isNew:
                    self.partitions.addRequest(raidrequest)
                if self.refresh():
                    raise RuntimeError, ("Returning partitions to state "
                                         "prior to RAID edit failed")
            else:
                break

        dialog.destroy()

    def getCurrentLogicalVolume(self):
	selection = self.logvollist.get_selection()
	rc = selection.get_selected()
	if rc:
	    model, iter = rc
	else:
	    return None

	return iter


    def editLogicalVolume(self, logrequest, isNew = 0):
        dialog = gtk.Dialog(_("Make Logical Volume"), self.parent)
        gui.addFrame(dialog)
        dialog.add_button('gtk-ok', 1)
        dialog.add_button('gtk-cancel', 2)
        dialog.set_position(gtk.WIN_POS_CENTER)

        maintable = gtk.Table()
        maintable.set_row_spacings(5)
        maintable.set_col_spacings(5)
        row = 0

        maintable.attach(createAlignedLabel(_("Mount point:")), 0, 1, row,row+1)
        mountpointEntry = gtk.Entry(16)
        maintable.attach(mountpointEntry, 1, 2, row, row + 1)
	if logrequest:
	    mountpointEntry.set_text(logrequest.mountpoint)
        row = row + 1

	maintable.attach(createAlignedLabel(_("Filesystem:")), 0, 1, row, row+1)
	maintable.attach(createAlignedLabel(_("ext3")), 1, 2, row, row+1)
	row = row+1
			 
        maintable.attach(createAlignedLabel(_("Size (MB):")), 0, 1, row, row+1)
        sizeEntry = gtk.Entry(16)
        maintable.attach(sizeEntry, 1, 2, row, row + 1)
	if logrequest:
	    sizeEntry.set_text("%g" % (logrequest.size,))
        row = row + 1

        maintable.attach(createAlignedLabel(_("Logical Volume Name:")), 0, 1, row, row + 1)
        lvnameEntry = gtk.Entry(16)
        maintable.attach(lvnameEntry, 1, 2, row, row + 1)
	if logrequest:
	    lvnameEntry.set_text(logrequest.logicalVolumeName)
        row = row + 1

        dialog.vbox.pack_start(maintable)
        dialog.show_all()

	while 1:
	    rc = dialog.run()
	    if rc == 2:
		dialog.destroy()
		return

	    # I suck.  I assume the fs is ext3 because it doesn't matter
	    # for me and do no error checking :)
	    fsystem = fileSystemTypeGetDefault()
	    mntpt = string.strip(mountpointEntry.get_text())
	    badsize = 0
	    try:
		size = int(sizeEntry.get_text())
	    except:
		badsize = 1

	    if badsize or size <= 0:
		self.intf.messageWindow(_("Illegal size"),
					_("The requested size as entered is "
					  "not a valid number greater than 0."))
		continue
	    
	    lvname = string.strip(lvnameEntry.get_text())

	    err = sanityCheckMountPoint(mntpt, fsystem, REQUEST_LV)
	    if err:
		self.intf.messageWindow(_("Bad mount point"), err)
		continue

	    used = 0
	    if not logrequest or mntpt != logrequest.mountpoint:
		# check in existing requests
		curreq = self.partitions.getRequestByMountPoint(mntpt)
		if curreq:
		    used = 1

		# check in pending logical volume requests
		if not used:
		    for lv in self.logvolreqs:
			if logrequest and logrequest.mountpoint and lv.mountpoint == logrequest.mountpoint:
			    continue

			if lv.mountpoint == mntpt:
			    used = 1
			    break

	    if used:
		self.intf.messageWindow(_("Mount point in use"),
					_("The mount point %s is in use, "
					  "please pick another.") % (mntpt,))
		continue

	    err = sanityCheckLogicalVolumeName(lvname)
	    if err:
		self.intf.messageWindow(_("Illegal Logical Volume Name"),
					err)
		continue

	    # is it in use?
	    used = 0
	    if logrequest:
		origlvname = logrequest.logicalVolumeName
	    else:
		origlvname = None
		
	    if not used:
		for lv in self.logvolreqs:
		    if logrequest and logrequest.mountpoint and lv.mountpoint == logrequest.mountpoint:
			continue

		    if lv.logicalVolumeName == lvname:
			used = 1
			break

	    if used:
		self.intf.messageWindow(_("Illegal logical volume name"),
					_("The logical volume name %s is "
					  "already in use. Please pick "
					  "another.") % (lvname,))
		continue

	    # everything ok
	    break

	if not isNew:
	    self.logvolreqs.remove(logrequest)
	    iter = self.getCurrentLogicalVolume()
	    self.logvolstore.remove(iter)
	    
        request = PartitionSpec(fsystem, REQUEST_LV, mountpoint = mntpt,
                                volname = lvname, size = size)
        self.logvolreqs.append(request)

	iter = self.logvolstore.append()
	self.logvolstore.set_value(iter, 0, lvname)
	self.logvolstore.set_value(iter, 1, mntpt)
	self.logvolstore.set_value(iter, 2, "%g" % (size,))

        dialog.destroy()
	
    def editCurrentLogicalVolume(self):
	iter = self.getCurrentLogicalVolume()

	if iter is None:
	    return
	
	logvolname = self.logvolstore.get_value(iter, 0)
	logrequest = None
	for lv in self.logvolreqs:
	    if lv.logicalVolumeName == logvolname:
		logrequest = lv
		
	if logrequest is None:
	    return

	self.editLogicalVolume(logrequest)

    def addLogicalVolumeCB(self, widget):
	self.editLogicalVolume(None, isNew = 1)
	return

    def editLogicalVolumeCB(self, widget):
	self.editCurrentLogicalVolume()
	return

    def delLogicalVolumeCB(self, widget):
	iter = self.getCurrentLogicalVolume()
	if iter is None:
	    return
	
	logvolname = self.logvolstore.get_value(iter, 0)
	if logvolname is None:
	    return

	rc = self.intf.messageWindow(_("Confirm Delete"),
				_("Are you sure you want to remove the "
				"logical volume %s?") % (logvolname,),
				type = "yesno")
	if not rc:
	    return

	for lv in self.logvolreqs:
	    if lv.logicalVolumeName == logvolname:
		self.logvolreqs.remove(lv)

	self.logvolstore.remove(iter)
	return
    
    def logvolActivateCb(self, view, path, col):
	self.editCurrentLogicalVolume()

    def editLVMVolumeGroup(self, origvgrequest, isNew = 0):
        availlvmparts = get_available_lvm_partitions(self.diskset,
						     self.partitions,
						     origvgrequest)

        # if no raid partitions exist, raise an error message and return
        if len(availlvmparts) < 1:
	    self.intf.messageWindow(_("Not enough physical volumes"),
			       _("At least one LVM partition is needed."))
            return


        dialog = gtk.Dialog(_("Make LVM Device"), self.parent)
        gui.addFrame(dialog)
        dialog.add_button('gtk-ok', 1)
        dialog.add_button('gtk-cancel', 2)
        dialog.set_position(gtk.WIN_POS_CENTER)

        maintable = gtk.Table()
        maintable.set_row_spacings(5)
        maintable.set_col_spacings(5)
        row = 0

        # volume group name
	labelalign = gtk.Alignment()
	labelalign.set(0.0, 0.5, 0.0, 0.0)
	labelalign.add(createAlignedLabel(_("Volume Group Name:")))
        maintable.attach(labelalign, 0, 1, row, row + 1)
        volnameEntry = gtk.Entry(16)
	if not isNew:
	    volnameEntry.set_text(origvgrequest.volumeGroupName)
	    
        maintable.attach(volnameEntry, 1, 2, row, row + 1)
	row = row + 1

        (lvmlist, sw) = createAllowedLvmPartitionsList(availlvmparts, [])
        lvmlist.set_size_request(275, 80)

        maintable.attach(createAlignedLabel(_("Physical Volumes to Use:")), 0, 1,
			 row, row + 1)
        maintable.attach(sw, 1, 2, row, row + 1)
        row = row + 1

	# populate list of logical volumes
        lvtable = gtk.Table()
        lvtable.set_row_spacings(5)
        lvtable.set_col_spacings(5)
	self.logvolstore = gtk.ListStore(gobject.TYPE_STRING,
				      gobject.TYPE_STRING,
				      gobject.TYPE_STRING)
	
        self.logvolreqs = self.partitions.getLVMLVForVG(origvgrequest)
	self.origvolreqs = copy.copy(self.logvolreqs)

	if self.logvolreqs:
	    for lvrequest in self.logvolreqs:
		iter = self.logvolstore.append()
		self.logvolstore.set_value(iter, 0, lvrequest.logicalVolumeName)
		self.logvolstore.set_value(iter, 1, lvrequest.mountpoint)
		self.logvolstore.set_value(iter, 2, "%g" % (lvrequest.size,))

	self.logvollist = gtk.TreeView(self.logvolstore)
        col = gtk.TreeViewColumn(_("Logical Volume Name"),
				 gtk.CellRendererText(), text=0)
        self.logvollist.append_column(col)
        col = gtk.TreeViewColumn(_("Mount Point"),
				 gtk.CellRendererText(), text=1)
        self.logvollist.append_column(col)
        col = gtk.TreeViewColumn(_("Size (MB)"),
				 gtk.CellRendererText(), text=2)
        self.logvollist.append_column(col)
        self.logvollist.connect('row-activated', self.logvolActivateCb)

        sw = gtk.ScrolledWindow()
        sw.add(self.logvollist)
        sw.set_size_request(100, 100)
        sw.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
	sw.set_shadow_type(gtk.SHADOW_IN)
        lvtable.attach(sw, 0, 1, 0, 1)

	# button box of options
	lvbbox = gtk.VBox()
        add = gtk.Button(_("_Add"))
        add.connect("clicked", self.addLogicalVolumeCB)
	lvbbox.pack_start(add)
        edit = gtk.Button(_("_Edit"))
        edit.connect("clicked", self.editLogicalVolumeCB)
	lvbbox.pack_start(edit)
        delete = gtk.Button(_("_Delete"))
        delete.connect("clicked", self.delLogicalVolumeCB)
	lvbbox.pack_start(delete)

	lvalign = gtk.Alignment()
	lvalign.set(0.5, 0.0, 0.0, 0.0)
	lvalign.add(lvbbox)
        lvtable.attach(lvalign, 1, 2, 0, 1, gtk.SHRINK, gtk.SHRINK)

	# pack all logical volumne stuff in a frame
	frame = gtk.Frame(_("Logical Volumes"))
	frame.add(lvtable)
	maintable.attach(frame, 0, 2, row, row+1)
	row = row + 1
	
	dialog.set_size_request(500, 400)

        dialog.vbox.pack_start(maintable)
        dialog.show_all()

	while 1:
	    rc = dialog.run()

	    if rc == 2:
		dialog.destroy()
		return

	    pv = []
	    model = lvmlist.get_model()
	    iter = model.get_iter_root()
	    next = 1
	    availSpaceMB = 0
	    while next:
		val      = model.get_value(iter, 0)
		partname = model.get_value(iter, 1)

		if val:
		    pvreq = self.partitions.getRequestByDeviceName(partname)
		    id = pvreq.uniqueID
		    pv.append(id)

		    part = get_partition_by_name(self.diskset.disks, partname)
		    availSpaceMB = availSpaceMB + requestSize(pvreq,
							      self.diskset)
		next = model.iter_next(iter)

	    print "Total size of volume group is %g MB" % (availSpaceMB,)

	    neededSpaceMB = 0
	    for lv in self.logvolreqs:
		neededSpaceMB = neededSpaceMB + lv.requestSize

	    print "Required size for logical volumes is %g MB" % (neededSpaceMB,)

	    if neededSpaceMB > availSpaceMB:
		self.intf.messageWindow(_("Not enough space"),
					_("The logical volumes you have "
					  "configured require %g MB, but the "
					  "volume group only has %g MB.  Please "
					  "either make the volume group larger "
					  "or make the logical volume(s) smaller.") % (neededSpaceMB, availSpaceMB))
		continue

	    # check volume name
	    volname = string.strip(volnameEntry.get_text())
	    err = sanityCheckVolumeGroupName(volname)
	    if err:
		self.intf.messageWindow(_("Invalid Volume Group Name"), err)
		continue

	    if origvgrequest:
		origvname = origvgrequest.volumeGroupName
	    else:
		origname = None

	    if origvname != volname:
		tmpreq =  PartitionSpec(fileSystemTypeGet("volume group (LVM)"),
					REQUEST_VG, physvolumes = pv,
					vgname = volname)
		if isVolumeGroupNameInUse(self.partitions, tmpreq):
		    self.intf.messageWindow(_("Name in use"),
					    _("The volume group name %s is "
					      "already in use. Please pick "
					      "another." % (volname,)))
		    del tmpreq
		    continue

		del tmpreq

	    # everything ok
	    break

        # first add the volume group
	if not isNew:
	    for lv in self.origvolreqs:
		self.partitions.removeRequest(lv)

	    self.partitions.removeRequest(origvgrequest)


	request = PartitionSpec(fileSystemTypeGet("volume group (LVM)"),
				REQUEST_VG, physvolumes = pv,
				vgname = volname)

        self.partitions.addRequest(request)

        # this is an evil hack for now.  should addRequest return the id?
        vgID = self.partitions.nextUniqueID - 1

        # now add the logical volumes
        for lv in self.logvolreqs:
            lv.volumeGroup = vgID
            lv.format = 1
            self.partitions.addRequest(lv)

#        for req in self.partitions.requests:
#            print req

	# XXX - probably shouldn't do this here - trying to force refresh of ui
#        self.diskStripeGraph.shutDown()
#        self.tree.clear()
#        self.populate()

        # XXX should probably check if this fails, cant see how it could
        self.refresh()
	
        dialog.destroy()
	return
    
    def makeLvmCB(self, widget):

        request = PartitionSpec(fileSystemTypeGet("volume group (LVM)"),
                                REQUEST_VG)
        self.editLVMVolumeGroup(request, isNew = 1)

	return

    def makeraidCB(self, widget):
        request = PartitionSpec(fileSystemTypeGetDefault(), REQUEST_RAID, 1)
        self.editRaidRequest(request, isNew = 1)

    def getScreen(self, fsset, diskset, partitions, intf):
        self.fsset = fsset
        self.diskset = diskset
        self.intf = intf
        
        self.diskset.openDevices()
        self.partitions = partitions

        checkForSwapNoMatch(self.intf, self.diskset, self.partitions)

        # XXX PartitionRequests() should already exist and
        # if upgrade or going back, have info filled in
#        self.newFsset = self.fsset.copy()

        # operational buttons
        buttonBox = gtk.HButtonBox()
        buttonBox.set_layout(gtk.BUTTONBOX_SPREAD)

        if iutil.getArch() == "s390":
            ops = ((_("_Edit"), self.editCb),
                   (_("_Delete"), self.deleteCb),
                   (_("_Reset"), self.resetCb),
                   (_("Make _RAID"), self.makeraidCB),)
        else:
            ops = ((_("_New"), self.newCB),
                   (_("_Edit"), self.editCb),
                   (_("_Delete"), self.deleteCb),
                   (_("_Reset"), self.resetCb),
                   (_("Make _RAID"), self.makeraidCB),
                   (_("_LVM"), self.makeLvmCB))
        
        for label, cb in ops:
            button = gtk.Button(label)
            buttonBox.add (button)
            button.connect ("clicked", cb)

        self.tree = DiskTreeModel()
        self.treeView = self.tree.getTreeView()
        self.treeView.connect('row-activated', self.treeActivateCb)
        self.treeViewSelection = self.treeView.get_selection()
        self.treeViewSelection.connect("changed", self.treeSelectCb)

        # set up the canvas
        self.diskStripeGraph = DiskStripeGraph(self.tree, self.editCb)
        
        # do the initial population of the tree and the graph
        self.populate(initial = 1)

	vpaned = gtk.VPaned()

        sw = gtk.ScrolledWindow()
        sw.add(self.diskStripeGraph.getCanvas())
        sw.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
	sw.set_shadow_type(gtk.SHADOW_IN)

        frame = gtk.Frame()
        frame.add(sw)
	vpaned.add1(frame)

        box = gtk.VBox(gtk.FALSE, 5)
        box.pack_start(frame, gtk.TRUE, gtk.TRUE)
        box.pack_start(buttonBox, gtk.FALSE)
        sw = gtk.ScrolledWindow()
        sw.add(self.treeView)
        sw.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
	sw.set_shadow_type(gtk.SHADOW_IN)
	
        box.pack_start(sw, gtk.TRUE)
	vpaned.add2(box)

	# XXX should probably be set according to height 
	vpaned.set_position(170)

	return vpaned

class AutoPartitionWindow(InstallWindow):
    def __init__(self, ics):
    	InstallWindow.__init__(self, ics)
        ics.setTitle(_("Automatic Partitioning"))
        ics.setNextEnabled(gtk.TRUE)
        ics.readHTML("autopart")
        self.parent = ics.getICW().window

    def getNext(self):
        if self.clearLinuxRB.get_active():
            self.partitions.autoClearPartType = autopart.CLEARPART_TYPE_LINUX
        elif self.clearAllRB.get_active():
            self.partitions.autoClearPartType = autopart.CLEARPART_TYPE_ALL
        else:
            self.partitions.autoClearPartType = autopart.CLEARPART_TYPE_NONE

        allowdrives = []
	model = self.drivelist.get_model()
	iter = model.get_iter_root()
	next = 1
	while next:
	    val   = model.get_value(iter, 0)
	    drive = model.get_value(iter, 1)

	    if val:
		allowdrives.append(drive)

	    next = model.iter_next(iter)

        if len(allowdrives) < 1:
            dlg = gtk.MessageDialog(self.parent, 0, gtk.MESSAGE_ERROR,
                                    gtk.BUTTONS_OK,
                                    _("You need to select at least one "
                                      "drive to have Red Hat Linux installed "
                                      "onto."))
            gui.addFrame(dlg)
            dlg.show_all()
            rc = dlg.run()
            dlg.destroy()
            raise gui.StayOnScreen

        self.partitions.autoClearPartDrives = allowdrives

        if not autopart.queryAutoPartitionOK(self.intf, self.diskset,
                                             self.partitions):
            raise gui.StayOnScreen
        
        if self.inspect.get_active():
            self.dispatch.skipStep("partition", skip = 0)
        else:
            self.dispatch.skipStep("partition")

        return None


    def getScreen(self, diskset, partitions, intf, dispatch):
        
        self.diskset = diskset
        self.partitions = partitions
        self.intf = intf
        self.dispatch = dispatch
        
        type = partitions.autoClearPartType
        cleardrives = partitions.autoClearPartDrives
        
        box = gtk.VBox(gtk.FALSE)
        box.set_border_width(5)

        label = gui.WrappingLabel(_(autopart.AUTOPART_DISK_CHOICE_DESCR_TEXT))
        label.set_alignment(0.0, 0.0)
        box.pack_start(label, gtk.FALSE, gtk.FALSE)

        # what partition types to remove
        clearbox = gtk.VBox(gtk.FALSE)
        label = gui.WrappingLabel(_("I want to have automatic partitioning:"))
        label.set_alignment(0.0, 0.0)
        clearbox.pack_start(label, gtk.FALSE, gtk.FALSE, 10)
        
        radioBox = gtk.VBox(gtk.FALSE)
        self.clearLinuxRB = gtk.RadioButton(
            None, _(autopart.CLEARPART_TYPE_LINUX_DESCR_TEXT))
	radioBox.pack_start(self.clearLinuxRB, gtk.FALSE, gtk.FALSE)
        self.clearAllRB = gtk.RadioButton(
            self.clearLinuxRB, _(autopart.CLEARPART_TYPE_ALL_DESCR_TEXT))
	radioBox.pack_start(self.clearAllRB, gtk.FALSE, gtk.FALSE)
        self.clearNoneRB = gtk.RadioButton(
            self.clearLinuxRB, _(autopart.CLEARPART_TYPE_NONE_DESCR_TEXT))
	radioBox.pack_start(self.clearNoneRB, gtk.FALSE, gtk.FALSE)

        if type == autopart.CLEARPART_TYPE_LINUX:
            self.clearLinuxRB.set_active(1)
        elif type == autopart.CLEARPART_TYPE_ALL:
            self.clearAllRB.set_active(1)
        else:
            self.clearNoneRB.set_active(1)
           
	align = gtk.Alignment()
	align.add(radioBox)
	align.set(0.5, 0.5, 0.0, 0.0)
	clearbox.pack_start(align, gtk.FALSE, gtk.FALSE)

        box.pack_start(clearbox, gtk.FALSE, gtk.FALSE, 10)

        # which drives to use?
        drivesbox = gtk.VBox(gtk.FALSE)
        label = gui.WrappingLabel(_("Which drive(s) do you want to use for "
                                    "this installation?"))
        label.set_alignment(0.0, 0.0)
        drivesbox.pack_start(label, gtk.FALSE, gtk.FALSE, 10)
        self.drivelist = createAllowedDrivesList(diskset.disks, cleardrives)

        # XXX bad use of usize
        self.drivelist.set_size_request(375, 80)

        sw = gtk.ScrolledWindow()
        sw.add(self.drivelist)
        sw.set_policy(gtk.POLICY_NEVER, gtk.POLICY_AUTOMATIC)
	sw.set_shadow_type(gtk.SHADOW_IN)
        
	align = gtk.Alignment()
	align.add(sw)
	align.set(0.5, 0.5, 0.0, 0.0)
        
        drivesbox.pack_start(align, gtk.FALSE, gtk.FALSE)

        box.pack_start(drivesbox, gtk.FALSE, gtk.FALSE)

        self.inspect = gtk.CheckButton()
        gui.widgetExpander(self.inspect)
        label = gtk.Label(_("Review (allows you to see and change the "
                            "automatic partitioning results)"))
        label.set_line_wrap(gtk.TRUE)
        gui.widgetExpander(label, self.inspect)
        label.set_alignment(0.0, 1.0)
        self.inspect.add(label)

        self.inspect.set_active(not dispatch.stepInSkipList("partition"))

	box.pack_start(self.inspect, gtk.TRUE, gtk.TRUE, 10)

        self.ics.setNextEnabled(gtk.TRUE)

	align = gtk.Alignment()
	align.add(box)
	align.set(0.5, 0.5, 0.0, 0.0)

	return align