This file is indexed.

/usr/share/heartbeat-gui/haclient.py is in pacemaker-mgmt-client 2.1.2-0ubuntu2.

This file is owned by root:root, with mode 0o755.

The actual contents of the file can be viewed below.

    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
 2438
 2439
 2440
 2441
 2442
 2443
 2444
 2445
 2446
 2447
 2448
 2449
 2450
 2451
 2452
 2453
 2454
 2455
 2456
 2457
 2458
 2459
 2460
 2461
 2462
 2463
 2464
 2465
 2466
 2467
 2468
 2469
 2470
 2471
 2472
 2473
 2474
 2475
 2476
 2477
 2478
 2479
 2480
 2481
 2482
 2483
 2484
 2485
 2486
 2487
 2488
 2489
 2490
 2491
 2492
 2493
 2494
 2495
 2496
 2497
 2498
 2499
 2500
 2501
 2502
 2503
 2504
 2505
 2506
 2507
 2508
 2509
 2510
 2511
 2512
 2513
 2514
 2515
 2516
 2517
 2518
 2519
 2520
 2521
 2522
 2523
 2524
 2525
 2526
 2527
 2528
 2529
 2530
 2531
 2532
 2533
 2534
 2535
 2536
 2537
 2538
 2539
 2540
 2541
 2542
 2543
 2544
 2545
 2546
 2547
 2548
 2549
 2550
 2551
 2552
 2553
 2554
 2555
 2556
 2557
 2558
 2559
 2560
 2561
 2562
 2563
 2564
 2565
 2566
 2567
 2568
 2569
 2570
 2571
 2572
 2573
 2574
 2575
 2576
 2577
 2578
 2579
 2580
 2581
 2582
 2583
 2584
 2585
 2586
 2587
 2588
 2589
 2590
 2591
 2592
 2593
 2594
 2595
 2596
 2597
 2598
 2599
 2600
 2601
 2602
 2603
 2604
 2605
 2606
 2607
 2608
 2609
 2610
 2611
 2612
 2613
 2614
 2615
 2616
 2617
 2618
 2619
 2620
 2621
 2622
 2623
 2624
 2625
 2626
 2627
 2628
 2629
 2630
 2631
 2632
 2633
 2634
 2635
 2636
 2637
 2638
 2639
 2640
 2641
 2642
 2643
 2644
 2645
 2646
 2647
 2648
 2649
 2650
 2651
 2652
 2653
 2654
 2655
 2656
 2657
 2658
 2659
 2660
 2661
 2662
 2663
 2664
 2665
 2666
 2667
 2668
 2669
 2670
 2671
 2672
 2673
 2674
 2675
 2676
 2677
 2678
 2679
 2680
 2681
 2682
 2683
 2684
 2685
 2686
 2687
 2688
 2689
 2690
 2691
 2692
 2693
 2694
 2695
 2696
 2697
 2698
 2699
 2700
 2701
 2702
 2703
 2704
 2705
 2706
 2707
 2708
 2709
 2710
 2711
 2712
 2713
 2714
 2715
 2716
 2717
 2718
 2719
 2720
 2721
 2722
 2723
 2724
 2725
 2726
 2727
 2728
 2729
 2730
 2731
 2732
 2733
 2734
 2735
 2736
 2737
 2738
 2739
 2740
 2741
 2742
 2743
 2744
 2745
 2746
 2747
 2748
 2749
 2750
 2751
 2752
 2753
 2754
 2755
 2756
 2757
 2758
 2759
 2760
 2761
 2762
 2763
 2764
 2765
 2766
 2767
 2768
 2769
 2770
 2771
 2772
 2773
 2774
 2775
 2776
 2777
 2778
 2779
 2780
 2781
 2782
 2783
 2784
 2785
 2786
 2787
 2788
 2789
 2790
 2791
 2792
 2793
 2794
 2795
 2796
 2797
 2798
 2799
 2800
 2801
 2802
 2803
 2804
 2805
 2806
 2807
 2808
 2809
 2810
 2811
 2812
 2813
 2814
 2815
 2816
 2817
 2818
 2819
 2820
 2821
 2822
 2823
 2824
 2825
 2826
 2827
 2828
 2829
 2830
 2831
 2832
 2833
 2834
 2835
 2836
 2837
 2838
 2839
 2840
 2841
 2842
 2843
 2844
 2845
 2846
 2847
 2848
 2849
 2850
 2851
 2852
 2853
 2854
 2855
 2856
 2857
 2858
 2859
 2860
 2861
 2862
 2863
 2864
 2865
 2866
 2867
 2868
 2869
 2870
 2871
 2872
 2873
 2874
 2875
 2876
 2877
 2878
 2879
 2880
 2881
 2882
 2883
 2884
 2885
 2886
 2887
 2888
 2889
 2890
 2891
 2892
 2893
 2894
 2895
 2896
 2897
 2898
 2899
 2900
 2901
 2902
 2903
 2904
 2905
 2906
 2907
 2908
 2909
 2910
 2911
 2912
 2913
 2914
 2915
 2916
 2917
 2918
 2919
 2920
 2921
 2922
 2923
 2924
 2925
 2926
 2927
 2928
 2929
 2930
 2931
 2932
 2933
 2934
 2935
 2936
 2937
 2938
 2939
 2940
 2941
 2942
 2943
 2944
 2945
 2946
 2947
 2948
 2949
 2950
 2951
 2952
 2953
 2954
 2955
 2956
 2957
 2958
 2959
 2960
 2961
 2962
 2963
 2964
 2965
 2966
 2967
 2968
 2969
 2970
 2971
 2972
 2973
 2974
 2975
 2976
 2977
 2978
 2979
 2980
 2981
 2982
 2983
 2984
 2985
 2986
 2987
 2988
 2989
 2990
 2991
 2992
 2993
 2994
 2995
 2996
 2997
 2998
 2999
 3000
 3001
 3002
 3003
 3004
 3005
 3006
 3007
 3008
 3009
 3010
 3011
 3012
 3013
 3014
 3015
 3016
 3017
 3018
 3019
 3020
 3021
 3022
 3023
 3024
 3025
 3026
 3027
 3028
 3029
 3030
 3031
 3032
 3033
 3034
 3035
 3036
 3037
 3038
 3039
 3040
 3041
 3042
 3043
 3044
 3045
 3046
 3047
 3048
 3049
 3050
 3051
 3052
 3053
 3054
 3055
 3056
 3057
 3058
 3059
 3060
 3061
 3062
 3063
 3064
 3065
 3066
 3067
 3068
 3069
 3070
 3071
 3072
 3073
 3074
 3075
 3076
 3077
 3078
 3079
 3080
 3081
 3082
 3083
 3084
 3085
 3086
 3087
 3088
 3089
 3090
 3091
 3092
 3093
 3094
 3095
 3096
 3097
 3098
 3099
 3100
 3101
 3102
 3103
 3104
 3105
 3106
 3107
 3108
 3109
 3110
 3111
 3112
 3113
 3114
 3115
 3116
 3117
 3118
 3119
 3120
 3121
 3122
 3123
 3124
 3125
 3126
 3127
 3128
 3129
 3130
 3131
 3132
 3133
 3134
 3135
 3136
 3137
 3138
 3139
 3140
 3141
 3142
 3143
 3144
 3145
 3146
 3147
 3148
 3149
 3150
 3151
 3152
 3153
 3154
 3155
 3156
 3157
 3158
 3159
 3160
 3161
 3162
 3163
 3164
 3165
 3166
 3167
 3168
 3169
 3170
 3171
 3172
 3173
 3174
 3175
 3176
 3177
 3178
 3179
 3180
 3181
 3182
 3183
 3184
 3185
 3186
 3187
 3188
 3189
 3190
 3191
 3192
 3193
 3194
 3195
 3196
 3197
 3198
 3199
 3200
 3201
 3202
 3203
 3204
 3205
 3206
 3207
 3208
 3209
 3210
 3211
 3212
 3213
 3214
 3215
 3216
 3217
 3218
 3219
 3220
 3221
 3222
 3223
 3224
 3225
 3226
 3227
 3228
 3229
 3230
 3231
 3232
 3233
 3234
 3235
 3236
 3237
 3238
 3239
 3240
 3241
 3242
 3243
 3244
 3245
 3246
 3247
 3248
 3249
 3250
 3251
 3252
 3253
 3254
 3255
 3256
 3257
 3258
 3259
 3260
 3261
 3262
 3263
 3264
 3265
 3266
 3267
 3268
 3269
 3270
 3271
 3272
 3273
 3274
 3275
 3276
 3277
 3278
 3279
 3280
 3281
 3282
 3283
 3284
 3285
 3286
 3287
 3288
 3289
 3290
 3291
 3292
 3293
 3294
 3295
 3296
 3297
 3298
 3299
 3300
 3301
 3302
 3303
 3304
 3305
 3306
 3307
 3308
 3309
 3310
 3311
 3312
 3313
 3314
 3315
 3316
 3317
 3318
 3319
 3320
 3321
 3322
 3323
 3324
 3325
 3326
 3327
 3328
 3329
 3330
 3331
 3332
 3333
 3334
 3335
 3336
 3337
 3338
 3339
 3340
 3341
 3342
 3343
 3344
 3345
 3346
 3347
 3348
 3349
 3350
 3351
 3352
 3353
 3354
 3355
 3356
 3357
 3358
 3359
 3360
 3361
 3362
 3363
 3364
 3365
 3366
 3367
 3368
 3369
 3370
 3371
 3372
 3373
 3374
 3375
 3376
 3377
 3378
 3379
 3380
 3381
 3382
 3383
 3384
 3385
 3386
 3387
 3388
 3389
 3390
 3391
 3392
 3393
 3394
 3395
 3396
 3397
 3398
 3399
 3400
 3401
 3402
 3403
 3404
 3405
 3406
 3407
 3408
 3409
 3410
 3411
 3412
 3413
 3414
 3415
 3416
 3417
 3418
 3419
 3420
 3421
 3422
 3423
 3424
 3425
 3426
 3427
 3428
 3429
 3430
 3431
 3432
 3433
 3434
 3435
 3436
 3437
 3438
 3439
 3440
 3441
 3442
 3443
 3444
 3445
 3446
 3447
 3448
 3449
 3450
 3451
 3452
 3453
 3454
 3455
 3456
 3457
 3458
 3459
 3460
 3461
 3462
 3463
 3464
 3465
 3466
 3467
 3468
 3469
 3470
 3471
 3472
 3473
 3474
 3475
 3476
 3477
 3478
 3479
 3480
 3481
 3482
 3483
 3484
 3485
 3486
 3487
 3488
 3489
 3490
 3491
 3492
 3493
 3494
 3495
 3496
 3497
 3498
 3499
 3500
 3501
 3502
 3503
 3504
 3505
 3506
 3507
 3508
 3509
 3510
 3511
 3512
 3513
 3514
 3515
 3516
 3517
 3518
 3519
 3520
 3521
 3522
 3523
 3524
 3525
 3526
 3527
 3528
 3529
 3530
 3531
 3532
 3533
 3534
 3535
 3536
 3537
 3538
 3539
 3540
 3541
 3542
 3543
 3544
 3545
 3546
 3547
 3548
 3549
 3550
 3551
 3552
 3553
 3554
 3555
 3556
 3557
 3558
 3559
 3560
 3561
 3562
 3563
 3564
 3565
 3566
 3567
 3568
 3569
 3570
 3571
 3572
 3573
 3574
 3575
 3576
 3577
 3578
 3579
 3580
 3581
 3582
 3583
 3584
 3585
 3586
 3587
 3588
 3589
 3590
 3591
 3592
 3593
 3594
 3595
 3596
 3597
 3598
 3599
 3600
 3601
 3602
 3603
 3604
 3605
 3606
 3607
 3608
 3609
 3610
 3611
 3612
 3613
 3614
 3615
 3616
 3617
 3618
 3619
 3620
 3621
 3622
 3623
 3624
 3625
 3626
 3627
 3628
 3629
 3630
 3631
 3632
 3633
 3634
 3635
 3636
 3637
 3638
 3639
 3640
 3641
 3642
 3643
 3644
 3645
 3646
 3647
 3648
 3649
 3650
 3651
 3652
 3653
 3654
 3655
 3656
 3657
 3658
 3659
 3660
 3661
 3662
 3663
 3664
 3665
 3666
 3667
 3668
 3669
 3670
 3671
 3672
 3673
 3674
 3675
 3676
 3677
 3678
 3679
 3680
 3681
 3682
 3683
 3684
 3685
 3686
 3687
 3688
 3689
 3690
 3691
 3692
 3693
 3694
 3695
 3696
 3697
 3698
 3699
 3700
 3701
 3702
 3703
 3704
 3705
 3706
 3707
 3708
 3709
 3710
 3711
 3712
 3713
 3714
 3715
 3716
 3717
 3718
 3719
 3720
 3721
 3722
 3723
 3724
 3725
 3726
 3727
 3728
 3729
 3730
 3731
 3732
 3733
 3734
 3735
 3736
 3737
 3738
 3739
 3740
 3741
 3742
 3743
 3744
 3745
 3746
 3747
 3748
 3749
 3750
 3751
 3752
 3753
 3754
 3755
 3756
 3757
 3758
 3759
 3760
 3761
 3762
 3763
 3764
 3765
 3766
 3767
 3768
 3769
 3770
 3771
 3772
 3773
 3774
 3775
 3776
 3777
 3778
 3779
 3780
 3781
 3782
 3783
 3784
 3785
 3786
 3787
 3788
 3789
 3790
 3791
 3792
 3793
 3794
 3795
 3796
 3797
 3798
 3799
 3800
 3801
 3802
 3803
 3804
 3805
 3806
 3807
 3808
 3809
 3810
 3811
 3812
 3813
 3814
 3815
 3816
 3817
 3818
 3819
 3820
 3821
 3822
 3823
 3824
 3825
 3826
 3827
 3828
 3829
 3830
 3831
 3832
 3833
 3834
 3835
 3836
 3837
 3838
 3839
 3840
 3841
 3842
 3843
 3844
 3845
 3846
 3847
 3848
 3849
 3850
 3851
 3852
 3853
 3854
 3855
 3856
 3857
 3858
 3859
 3860
 3861
 3862
 3863
 3864
 3865
 3866
 3867
 3868
 3869
 3870
 3871
 3872
 3873
 3874
 3875
 3876
 3877
 3878
 3879
 3880
 3881
 3882
 3883
 3884
 3885
 3886
 3887
 3888
 3889
 3890
 3891
 3892
 3893
 3894
 3895
 3896
 3897
 3898
 3899
 3900
 3901
 3902
 3903
 3904
 3905
 3906
 3907
 3908
 3909
 3910
 3911
 3912
 3913
 3914
 3915
 3916
 3917
 3918
 3919
 3920
 3921
 3922
 3923
 3924
 3925
 3926
 3927
 3928
 3929
 3930
 3931
 3932
 3933
 3934
 3935
 3936
 3937
 3938
 3939
 3940
 3941
 3942
 3943
 3944
 3945
 3946
 3947
 3948
 3949
 3950
 3951
 3952
 3953
 3954
 3955
 3956
 3957
 3958
 3959
 3960
 3961
 3962
 3963
 3964
 3965
 3966
 3967
 3968
 3969
 3970
 3971
 3972
 3973
 3974
 3975
 3976
 3977
 3978
 3979
 3980
 3981
 3982
 3983
 3984
 3985
 3986
 3987
 3988
 3989
 3990
 3991
 3992
 3993
 3994
 3995
 3996
 3997
 3998
 3999
 4000
 4001
 4002
 4003
 4004
 4005
 4006
 4007
 4008
 4009
 4010
 4011
 4012
 4013
 4014
 4015
 4016
 4017
 4018
 4019
 4020
 4021
 4022
 4023
 4024
 4025
 4026
 4027
 4028
 4029
 4030
 4031
 4032
 4033
 4034
 4035
 4036
 4037
 4038
 4039
 4040
 4041
 4042
 4043
 4044
 4045
 4046
 4047
 4048
 4049
 4050
 4051
 4052
 4053
 4054
 4055
 4056
 4057
 4058
 4059
 4060
 4061
 4062
 4063
 4064
 4065
 4066
 4067
 4068
 4069
 4070
 4071
 4072
 4073
 4074
 4075
 4076
 4077
 4078
 4079
 4080
 4081
 4082
 4083
 4084
 4085
 4086
 4087
 4088
 4089
 4090
 4091
 4092
 4093
 4094
 4095
 4096
 4097
 4098
 4099
 4100
 4101
 4102
 4103
 4104
 4105
 4106
 4107
 4108
 4109
 4110
 4111
 4112
 4113
 4114
 4115
 4116
 4117
 4118
 4119
 4120
 4121
 4122
 4123
 4124
 4125
 4126
 4127
 4128
 4129
 4130
 4131
 4132
 4133
 4134
 4135
 4136
 4137
 4138
 4139
 4140
 4141
 4142
 4143
 4144
 4145
 4146
 4147
 4148
 4149
 4150
 4151
 4152
 4153
 4154
 4155
 4156
 4157
 4158
 4159
 4160
 4161
 4162
 4163
 4164
 4165
 4166
 4167
 4168
 4169
 4170
 4171
 4172
 4173
 4174
 4175
 4176
 4177
 4178
 4179
 4180
 4181
 4182
 4183
 4184
 4185
 4186
 4187
 4188
 4189
 4190
 4191
 4192
 4193
 4194
 4195
 4196
 4197
 4198
 4199
 4200
 4201
 4202
 4203
 4204
 4205
 4206
 4207
 4208
 4209
 4210
 4211
 4212
 4213
 4214
 4215
 4216
 4217
 4218
 4219
 4220
 4221
 4222
 4223
 4224
 4225
 4226
 4227
 4228
 4229
 4230
 4231
 4232
 4233
 4234
 4235
 4236
 4237
 4238
 4239
 4240
 4241
 4242
 4243
 4244
 4245
 4246
 4247
 4248
 4249
 4250
 4251
 4252
 4253
 4254
 4255
 4256
 4257
 4258
 4259
 4260
 4261
 4262
 4263
 4264
 4265
 4266
 4267
 4268
 4269
 4270
 4271
 4272
 4273
 4274
 4275
 4276
 4277
 4278
 4279
 4280
 4281
 4282
 4283
 4284
 4285
 4286
 4287
 4288
 4289
 4290
 4291
 4292
 4293
 4294
 4295
 4296
 4297
 4298
 4299
 4300
 4301
 4302
 4303
 4304
 4305
 4306
 4307
 4308
 4309
 4310
 4311
 4312
 4313
 4314
 4315
 4316
 4317
 4318
 4319
 4320
 4321
 4322
 4323
 4324
 4325
 4326
 4327
 4328
 4329
 4330
 4331
 4332
 4333
 4334
 4335
 4336
 4337
 4338
 4339
 4340
 4341
 4342
 4343
 4344
 4345
 4346
 4347
 4348
 4349
 4350
 4351
 4352
 4353
 4354
 4355
 4356
 4357
 4358
 4359
 4360
 4361
 4362
 4363
 4364
 4365
 4366
 4367
 4368
 4369
 4370
 4371
 4372
 4373
 4374
 4375
 4376
 4377
 4378
 4379
 4380
 4381
 4382
 4383
 4384
 4385
 4386
 4387
 4388
 4389
 4390
 4391
 4392
 4393
 4394
 4395
 4396
 4397
 4398
 4399
 4400
 4401
 4402
 4403
 4404
 4405
 4406
 4407
 4408
 4409
 4410
 4411
 4412
 4413
 4414
 4415
 4416
 4417
 4418
 4419
 4420
 4421
 4422
 4423
 4424
 4425
 4426
 4427
 4428
 4429
 4430
 4431
 4432
 4433
 4434
 4435
 4436
 4437
 4438
 4439
 4440
 4441
 4442
 4443
 4444
 4445
 4446
 4447
 4448
 4449
 4450
 4451
 4452
 4453
 4454
 4455
 4456
 4457
 4458
 4459
 4460
 4461
 4462
 4463
 4464
 4465
 4466
 4467
 4468
 4469
 4470
 4471
 4472
 4473
 4474
 4475
 4476
 4477
 4478
 4479
 4480
 4481
 4482
 4483
 4484
 4485
 4486
 4487
 4488
 4489
 4490
 4491
 4492
 4493
 4494
 4495
 4496
 4497
 4498
 4499
 4500
 4501
 4502
 4503
 4504
 4505
 4506
 4507
 4508
 4509
 4510
 4511
 4512
 4513
 4514
 4515
 4516
 4517
 4518
 4519
 4520
 4521
 4522
 4523
 4524
 4525
 4526
 4527
 4528
 4529
 4530
 4531
 4532
 4533
 4534
 4535
 4536
 4537
 4538
 4539
 4540
 4541
 4542
 4543
 4544
 4545
 4546
 4547
 4548
 4549
 4550
 4551
 4552
 4553
 4554
 4555
 4556
 4557
 4558
 4559
 4560
 4561
 4562
 4563
 4564
 4565
 4566
 4567
 4568
 4569
 4570
 4571
 4572
 4573
 4574
 4575
 4576
 4577
 4578
 4579
 4580
 4581
 4582
 4583
 4584
 4585
 4586
 4587
 4588
 4589
 4590
 4591
 4592
 4593
 4594
 4595
 4596
 4597
 4598
 4599
 4600
 4601
 4602
 4603
 4604
 4605
 4606
 4607
 4608
 4609
 4610
 4611
 4612
 4613
 4614
 4615
 4616
 4617
 4618
 4619
 4620
 4621
 4622
 4623
 4624
 4625
 4626
 4627
 4628
 4629
 4630
 4631
 4632
 4633
 4634
 4635
 4636
 4637
 4638
 4639
 4640
 4641
 4642
 4643
 4644
 4645
 4646
 4647
 4648
 4649
 4650
 4651
 4652
 4653
 4654
 4655
 4656
 4657
 4658
 4659
 4660
 4661
 4662
 4663
 4664
 4665
 4666
 4667
 4668
 4669
 4670
 4671
 4672
 4673
 4674
 4675
 4676
 4677
 4678
 4679
 4680
 4681
 4682
 4683
 4684
 4685
 4686
 4687
 4688
 4689
 4690
 4691
 4692
 4693
 4694
 4695
 4696
 4697
 4698
 4699
 4700
 4701
 4702
 4703
 4704
 4705
 4706
 4707
 4708
 4709
 4710
 4711
 4712
 4713
 4714
 4715
 4716
 4717
 4718
 4719
 4720
 4721
 4722
 4723
 4724
 4725
 4726
 4727
 4728
 4729
 4730
 4731
 4732
 4733
 4734
 4735
 4736
 4737
 4738
 4739
 4740
 4741
 4742
 4743
 4744
 4745
 4746
 4747
 4748
 4749
 4750
 4751
 4752
 4753
 4754
 4755
 4756
 4757
 4758
 4759
 4760
 4761
 4762
 4763
 4764
 4765
 4766
 4767
 4768
 4769
 4770
 4771
 4772
 4773
 4774
 4775
 4776
 4777
 4778
 4779
 4780
 4781
 4782
 4783
 4784
 4785
 4786
 4787
 4788
 4789
 4790
 4791
 4792
 4793
 4794
 4795
 4796
 4797
 4798
 4799
 4800
 4801
 4802
 4803
 4804
 4805
 4806
 4807
 4808
 4809
 4810
 4811
 4812
 4813
 4814
 4815
 4816
 4817
 4818
 4819
 4820
 4821
 4822
 4823
 4824
 4825
 4826
 4827
 4828
 4829
 4830
 4831
 4832
 4833
 4834
 4835
 4836
 4837
 4838
 4839
 4840
 4841
 4842
 4843
 4844
 4845
 4846
 4847
 4848
 4849
 4850
 4851
 4852
 4853
 4854
 4855
 4856
 4857
 4858
 4859
 4860
 4861
 4862
 4863
 4864
 4865
 4866
 4867
 4868
 4869
 4870
 4871
 4872
 4873
 4874
 4875
 4876
 4877
 4878
 4879
 4880
 4881
 4882
 4883
 4884
 4885
 4886
 4887
 4888
 4889
 4890
 4891
 4892
 4893
 4894
 4895
 4896
 4897
 4898
 4899
 4900
 4901
 4902
 4903
 4904
 4905
 4906
 4907
 4908
 4909
 4910
 4911
 4912
 4913
 4914
 4915
 4916
 4917
 4918
 4919
 4920
 4921
 4922
 4923
 4924
 4925
 4926
 4927
 4928
 4929
 4930
 4931
 4932
 4933
 4934
 4935
 4936
 4937
 4938
 4939
 4940
 4941
 4942
 4943
 4944
 4945
 4946
 4947
 4948
 4949
 4950
 4951
 4952
 4953
 4954
 4955
 4956
 4957
 4958
 4959
 4960
 4961
 4962
 4963
 4964
 4965
 4966
 4967
 4968
 4969
 4970
 4971
 4972
 4973
 4974
 4975
 4976
 4977
 4978
 4979
 4980
 4981
 4982
 4983
 4984
 4985
 4986
 4987
 4988
 4989
 4990
 4991
 4992
 4993
 4994
 4995
 4996
 4997
 4998
 4999
 5000
 5001
 5002
 5003
 5004
 5005
 5006
 5007
 5008
 5009
 5010
 5011
 5012
 5013
 5014
 5015
 5016
 5017
 5018
 5019
 5020
 5021
 5022
 5023
 5024
 5025
 5026
 5027
 5028
 5029
 5030
 5031
 5032
 5033
 5034
 5035
 5036
 5037
 5038
 5039
 5040
 5041
 5042
 5043
 5044
 5045
 5046
 5047
 5048
 5049
 5050
 5051
 5052
 5053
 5054
 5055
 5056
 5057
 5058
 5059
 5060
 5061
 5062
 5063
 5064
 5065
 5066
 5067
 5068
 5069
 5070
 5071
 5072
 5073
 5074
 5075
 5076
 5077
 5078
 5079
 5080
 5081
 5082
 5083
 5084
 5085
 5086
 5087
 5088
 5089
 5090
 5091
 5092
 5093
 5094
 5095
 5096
 5097
 5098
 5099
 5100
 5101
 5102
 5103
 5104
 5105
 5106
 5107
 5108
 5109
 5110
 5111
 5112
 5113
 5114
 5115
 5116
 5117
 5118
 5119
 5120
 5121
 5122
 5123
 5124
 5125
 5126
 5127
 5128
 5129
 5130
 5131
 5132
 5133
 5134
 5135
 5136
 5137
 5138
 5139
 5140
 5141
 5142
 5143
 5144
 5145
 5146
 5147
 5148
 5149
 5150
 5151
 5152
 5153
 5154
 5155
 5156
 5157
 5158
 5159
 5160
 5161
 5162
 5163
 5164
 5165
 5166
 5167
 5168
 5169
 5170
 5171
 5172
 5173
 5174
 5175
 5176
 5177
 5178
 5179
 5180
 5181
 5182
 5183
 5184
 5185
 5186
 5187
 5188
 5189
 5190
 5191
 5192
 5193
 5194
 5195
 5196
 5197
 5198
 5199
 5200
 5201
 5202
 5203
 5204
 5205
 5206
 5207
 5208
 5209
 5210
 5211
 5212
 5213
 5214
 5215
 5216
 5217
 5218
 5219
 5220
 5221
 5222
 5223
 5224
 5225
 5226
 5227
 5228
 5229
 5230
 5231
 5232
 5233
 5234
 5235
 5236
 5237
 5238
 5239
 5240
 5241
 5242
 5243
 5244
 5245
 5246
 5247
 5248
 5249
 5250
 5251
 5252
 5253
 5254
 5255
 5256
 5257
 5258
 5259
 5260
 5261
 5262
 5263
 5264
 5265
 5266
 5267
 5268
 5269
 5270
 5271
 5272
 5273
 5274
 5275
 5276
 5277
 5278
 5279
 5280
 5281
 5282
 5283
 5284
 5285
 5286
 5287
 5288
 5289
 5290
 5291
 5292
 5293
 5294
 5295
 5296
 5297
 5298
 5299
 5300
 5301
 5302
 5303
 5304
 5305
 5306
 5307
 5308
 5309
 5310
 5311
 5312
 5313
 5314
 5315
 5316
 5317
 5318
 5319
 5320
 5321
 5322
 5323
 5324
 5325
 5326
 5327
 5328
 5329
 5330
 5331
 5332
 5333
 5334
 5335
 5336
 5337
 5338
 5339
 5340
 5341
 5342
 5343
 5344
 5345
 5346
 5347
 5348
 5349
 5350
 5351
 5352
 5353
 5354
 5355
 5356
 5357
 5358
 5359
 5360
 5361
 5362
 5363
 5364
 5365
 5366
 5367
 5368
 5369
 5370
 5371
 5372
 5373
 5374
 5375
 5376
 5377
 5378
 5379
 5380
 5381
 5382
 5383
 5384
 5385
 5386
 5387
 5388
 5389
 5390
 5391
 5392
 5393
 5394
 5395
 5396
 5397
 5398
 5399
 5400
 5401
 5402
 5403
 5404
 5405
 5406
 5407
 5408
 5409
 5410
 5411
 5412
 5413
 5414
 5415
 5416
 5417
 5418
 5419
 5420
 5421
 5422
 5423
 5424
 5425
 5426
 5427
 5428
 5429
 5430
 5431
 5432
 5433
 5434
 5435
 5436
 5437
 5438
 5439
 5440
 5441
 5442
 5443
 5444
 5445
 5446
 5447
 5448
 5449
 5450
 5451
 5452
 5453
 5454
 5455
 5456
 5457
 5458
 5459
 5460
 5461
 5462
 5463
 5464
 5465
 5466
 5467
 5468
 5469
 5470
 5471
 5472
 5473
 5474
 5475
 5476
 5477
 5478
 5479
 5480
 5481
 5482
 5483
 5484
 5485
 5486
 5487
 5488
 5489
 5490
 5491
 5492
 5493
 5494
 5495
 5496
 5497
 5498
 5499
 5500
 5501
 5502
 5503
 5504
 5505
 5506
 5507
 5508
 5509
 5510
 5511
 5512
 5513
 5514
 5515
 5516
 5517
 5518
 5519
 5520
 5521
 5522
 5523
 5524
 5525
 5526
 5527
 5528
 5529
 5530
 5531
 5532
 5533
 5534
 5535
 5536
 5537
 5538
 5539
 5540
 5541
 5542
 5543
 5544
 5545
 5546
 5547
 5548
 5549
 5550
 5551
 5552
 5553
 5554
 5555
 5556
 5557
 5558
 5559
 5560
 5561
 5562
 5563
 5564
 5565
 5566
 5567
 5568
 5569
 5570
 5571
 5572
 5573
 5574
 5575
 5576
 5577
 5578
 5579
 5580
 5581
 5582
 5583
 5584
 5585
 5586
 5587
 5588
 5589
 5590
 5591
 5592
 5593
 5594
 5595
 5596
 5597
 5598
 5599
 5600
 5601
 5602
 5603
 5604
 5605
 5606
 5607
 5608
 5609
 5610
 5611
 5612
 5613
 5614
 5615
 5616
 5617
 5618
 5619
 5620
 5621
 5622
 5623
 5624
 5625
 5626
 5627
 5628
 5629
 5630
 5631
 5632
 5633
 5634
 5635
 5636
 5637
 5638
 5639
 5640
 5641
 5642
 5643
 5644
 5645
 5646
 5647
 5648
 5649
 5650
 5651
 5652
 5653
 5654
 5655
 5656
 5657
 5658
 5659
 5660
 5661
 5662
 5663
 5664
 5665
 5666
 5667
 5668
 5669
 5670
 5671
 5672
 5673
 5674
 5675
 5676
 5677
 5678
 5679
 5680
 5681
 5682
 5683
 5684
 5685
 5686
 5687
 5688
 5689
 5690
 5691
 5692
 5693
 5694
 5695
 5696
 5697
 5698
 5699
 5700
 5701
 5702
 5703
 5704
 5705
 5706
 5707
 5708
 5709
 5710
 5711
 5712
 5713
 5714
 5715
 5716
 5717
 5718
 5719
 5720
 5721
 5722
 5723
 5724
 5725
 5726
 5727
 5728
 5729
 5730
 5731
 5732
 5733
 5734
 5735
 5736
 5737
 5738
 5739
 5740
 5741
 5742
 5743
 5744
 5745
 5746
 5747
 5748
 5749
 5750
 5751
 5752
 5753
 5754
 5755
 5756
 5757
 5758
 5759
 5760
 5761
 5762
 5763
 5764
 5765
 5766
 5767
 5768
 5769
 5770
 5771
 5772
 5773
 5774
 5775
 5776
 5777
 5778
 5779
 5780
 5781
 5782
 5783
 5784
 5785
 5786
 5787
 5788
 5789
 5790
 5791
 5792
 5793
 5794
 5795
 5796
 5797
 5798
 5799
 5800
 5801
 5802
 5803
 5804
 5805
 5806
 5807
 5808
 5809
 5810
 5811
 5812
 5813
 5814
 5815
 5816
 5817
 5818
 5819
 5820
 5821
 5822
 5823
 5824
 5825
 5826
 5827
 5828
 5829
 5830
 5831
 5832
 5833
 5834
 5835
 5836
 5837
 5838
 5839
 5840
 5841
 5842
 5843
 5844
 5845
 5846
 5847
 5848
 5849
 5850
 5851
 5852
 5853
 5854
 5855
 5856
 5857
 5858
 5859
 5860
 5861
 5862
 5863
 5864
 5865
 5866
 5867
 5868
 5869
 5870
 5871
 5872
 5873
 5874
 5875
 5876
 5877
 5878
 5879
 5880
 5881
 5882
 5883
 5884
 5885
 5886
 5887
 5888
 5889
 5890
 5891
 5892
 5893
 5894
 5895
 5896
 5897
 5898
 5899
 5900
 5901
 5902
 5903
 5904
 5905
 5906
 5907
 5908
 5909
 5910
 5911
 5912
 5913
 5914
 5915
 5916
 5917
 5918
 5919
 5920
 5921
 5922
 5923
 5924
 5925
 5926
 5927
 5928
 5929
 5930
 5931
 5932
 5933
 5934
 5935
 5936
 5937
 5938
 5939
 5940
 5941
 5942
 5943
 5944
 5945
 5946
 5947
 5948
 5949
 5950
 5951
 5952
 5953
 5954
 5955
 5956
 5957
 5958
 5959
 5960
 5961
 5962
 5963
 5964
 5965
 5966
 5967
 5968
 5969
 5970
 5971
 5972
 5973
 5974
 5975
 5976
 5977
 5978
 5979
 5980
 5981
 5982
 5983
 5984
 5985
 5986
 5987
 5988
 5989
 5990
 5991
 5992
 5993
 5994
 5995
 5996
 5997
 5998
 5999
 6000
 6001
 6002
 6003
 6004
 6005
 6006
 6007
 6008
 6009
 6010
 6011
 6012
 6013
 6014
 6015
 6016
 6017
 6018
 6019
 6020
 6021
 6022
 6023
 6024
 6025
 6026
 6027
 6028
 6029
 6030
 6031
 6032
 6033
 6034
 6035
 6036
 6037
 6038
 6039
 6040
 6041
 6042
 6043
 6044
 6045
 6046
 6047
 6048
 6049
 6050
 6051
 6052
 6053
 6054
 6055
 6056
 6057
 6058
 6059
 6060
 6061
 6062
 6063
 6064
 6065
 6066
 6067
 6068
 6069
 6070
 6071
 6072
 6073
 6074
 6075
 6076
 6077
 6078
 6079
 6080
 6081
 6082
 6083
 6084
 6085
 6086
 6087
 6088
 6089
 6090
 6091
 6092
 6093
 6094
 6095
 6096
 6097
 6098
 6099
 6100
 6101
 6102
 6103
 6104
 6105
 6106
 6107
 6108
 6109
 6110
 6111
 6112
 6113
 6114
 6115
 6116
 6117
 6118
 6119
 6120
 6121
 6122
 6123
 6124
 6125
 6126
 6127
 6128
 6129
 6130
 6131
 6132
 6133
 6134
 6135
 6136
 6137
 6138
 6139
 6140
 6141
 6142
 6143
 6144
 6145
 6146
 6147
 6148
 6149
 6150
 6151
 6152
 6153
 6154
 6155
 6156
 6157
 6158
 6159
 6160
 6161
 6162
 6163
 6164
 6165
 6166
 6167
 6168
 6169
 6170
 6171
 6172
 6173
 6174
 6175
 6176
 6177
 6178
 6179
 6180
 6181
 6182
 6183
 6184
 6185
 6186
 6187
 6188
 6189
 6190
 6191
 6192
 6193
 6194
 6195
 6196
 6197
 6198
 6199
 6200
 6201
 6202
 6203
 6204
 6205
 6206
 6207
 6208
 6209
 6210
 6211
 6212
 6213
 6214
 6215
 6216
 6217
 6218
 6219
 6220
 6221
 6222
 6223
 6224
 6225
 6226
 6227
 6228
 6229
 6230
 6231
 6232
 6233
 6234
 6235
 6236
 6237
 6238
 6239
 6240
 6241
 6242
 6243
 6244
 6245
 6246
 6247
 6248
 6249
 6250
 6251
 6252
 6253
 6254
 6255
 6256
 6257
 6258
 6259
 6260
 6261
 6262
 6263
 6264
 6265
 6266
 6267
 6268
 6269
 6270
 6271
 6272
 6273
 6274
 6275
 6276
 6277
 6278
 6279
 6280
 6281
 6282
 6283
 6284
 6285
 6286
 6287
 6288
 6289
 6290
 6291
 6292
 6293
 6294
 6295
 6296
 6297
 6298
 6299
 6300
 6301
 6302
 6303
 6304
 6305
 6306
 6307
 6308
 6309
 6310
 6311
 6312
 6313
 6314
 6315
 6316
 6317
 6318
 6319
 6320
 6321
 6322
 6323
 6324
 6325
 6326
 6327
 6328
 6329
 6330
 6331
 6332
 6333
 6334
 6335
 6336
 6337
 6338
 6339
 6340
 6341
 6342
 6343
 6344
 6345
 6346
 6347
 6348
 6349
 6350
 6351
 6352
 6353
 6354
 6355
 6356
 6357
 6358
 6359
 6360
 6361
 6362
 6363
 6364
 6365
 6366
 6367
 6368
 6369
 6370
 6371
 6372
 6373
 6374
 6375
 6376
 6377
 6378
 6379
 6380
 6381
 6382
 6383
 6384
 6385
 6386
 6387
 6388
 6389
 6390
 6391
 6392
 6393
 6394
 6395
 6396
 6397
 6398
 6399
 6400
 6401
 6402
 6403
 6404
 6405
 6406
 6407
 6408
 6409
 6410
 6411
 6412
 6413
 6414
 6415
 6416
 6417
 6418
 6419
 6420
 6421
 6422
 6423
 6424
 6425
 6426
 6427
 6428
 6429
 6430
 6431
 6432
 6433
 6434
 6435
 6436
 6437
 6438
 6439
 6440
 6441
 6442
 6443
 6444
 6445
 6446
 6447
 6448
 6449
 6450
 6451
 6452
 6453
 6454
 6455
 6456
 6457
 6458
 6459
 6460
 6461
 6462
 6463
 6464
 6465
 6466
 6467
 6468
 6469
 6470
 6471
 6472
 6473
 6474
 6475
 6476
 6477
 6478
 6479
 6480
 6481
 6482
 6483
 6484
 6485
 6486
 6487
 6488
 6489
 6490
 6491
 6492
 6493
 6494
 6495
 6496
 6497
 6498
 6499
 6500
 6501
 6502
 6503
 6504
 6505
 6506
 6507
 6508
 6509
 6510
 6511
 6512
 6513
 6514
 6515
 6516
 6517
 6518
 6519
 6520
 6521
 6522
 6523
 6524
 6525
 6526
 6527
 6528
 6529
 6530
 6531
 6532
 6533
 6534
 6535
 6536
 6537
 6538
 6539
 6540
 6541
 6542
 6543
 6544
 6545
 6546
 6547
 6548
 6549
 6550
 6551
 6552
 6553
 6554
 6555
 6556
 6557
 6558
 6559
 6560
 6561
 6562
 6563
 6564
 6565
 6566
 6567
 6568
 6569
 6570
 6571
 6572
 6573
 6574
 6575
 6576
 6577
 6578
 6579
 6580
 6581
 6582
 6583
 6584
 6585
 6586
 6587
 6588
 6589
 6590
 6591
 6592
 6593
 6594
 6595
 6596
 6597
 6598
 6599
 6600
 6601
 6602
 6603
 6604
 6605
 6606
 6607
 6608
 6609
 6610
 6611
 6612
 6613
 6614
 6615
 6616
 6617
 6618
 6619
 6620
 6621
 6622
 6623
 6624
 6625
 6626
 6627
 6628
 6629
 6630
 6631
 6632
 6633
 6634
 6635
 6636
 6637
 6638
 6639
 6640
 6641
 6642
 6643
 6644
 6645
 6646
 6647
 6648
 6649
 6650
 6651
 6652
 6653
 6654
 6655
 6656
 6657
 6658
 6659
 6660
 6661
 6662
 6663
 6664
 6665
 6666
 6667
 6668
 6669
 6670
 6671
 6672
 6673
 6674
 6675
 6676
 6677
 6678
 6679
 6680
 6681
 6682
 6683
 6684
 6685
 6686
 6687
 6688
 6689
 6690
 6691
 6692
 6693
 6694
 6695
 6696
 6697
 6698
 6699
 6700
 6701
 6702
 6703
 6704
 6705
 6706
 6707
 6708
 6709
 6710
 6711
 6712
 6713
 6714
 6715
 6716
 6717
 6718
 6719
 6720
 6721
 6722
 6723
 6724
 6725
 6726
 6727
 6728
 6729
 6730
 6731
 6732
 6733
 6734
 6735
 6736
 6737
 6738
 6739
 6740
 6741
 6742
 6743
 6744
 6745
 6746
 6747
 6748
 6749
 6750
 6751
 6752
 6753
 6754
 6755
 6756
 6757
 6758
 6759
 6760
 6761
 6762
 6763
 6764
 6765
 6766
 6767
 6768
 6769
 6770
 6771
 6772
 6773
 6774
 6775
 6776
 6777
 6778
 6779
 6780
 6781
 6782
 6783
 6784
 6785
 6786
 6787
 6788
 6789
 6790
 6791
 6792
 6793
 6794
 6795
 6796
 6797
 6798
 6799
 6800
 6801
 6802
 6803
 6804
 6805
 6806
 6807
 6808
 6809
 6810
 6811
 6812
 6813
 6814
 6815
 6816
 6817
 6818
 6819
 6820
 6821
 6822
 6823
 6824
 6825
 6826
 6827
 6828
 6829
 6830
 6831
 6832
 6833
 6834
 6835
 6836
 6837
 6838
 6839
 6840
 6841
 6842
 6843
 6844
 6845
 6846
 6847
 6848
 6849
 6850
 6851
 6852
 6853
 6854
 6855
 6856
 6857
 6858
 6859
 6860
 6861
 6862
 6863
 6864
 6865
 6866
 6867
 6868
 6869
 6870
 6871
 6872
 6873
 6874
 6875
 6876
 6877
 6878
 6879
 6880
 6881
 6882
 6883
 6884
 6885
 6886
 6887
 6888
 6889
 6890
 6891
 6892
 6893
 6894
 6895
 6896
 6897
 6898
 6899
 6900
 6901
 6902
 6903
 6904
 6905
 6906
 6907
 6908
 6909
 6910
 6911
 6912
 6913
 6914
 6915
 6916
 6917
 6918
 6919
 6920
 6921
 6922
 6923
 6924
 6925
 6926
 6927
 6928
 6929
 6930
 6931
 6932
 6933
 6934
 6935
 6936
 6937
 6938
 6939
 6940
 6941
 6942
 6943
 6944
 6945
 6946
 6947
 6948
 6949
 6950
 6951
 6952
 6953
 6954
 6955
 6956
 6957
 6958
 6959
 6960
 6961
 6962
 6963
 6964
 6965
 6966
 6967
 6968
 6969
 6970
 6971
 6972
 6973
 6974
 6975
 6976
 6977
 6978
 6979
 6980
 6981
 6982
 6983
 6984
 6985
 6986
 6987
 6988
 6989
 6990
 6991
 6992
 6993
 6994
 6995
 6996
 6997
 6998
 6999
 7000
 7001
 7002
 7003
 7004
 7005
 7006
 7007
 7008
 7009
 7010
 7011
 7012
 7013
 7014
 7015
 7016
 7017
 7018
 7019
 7020
 7021
 7022
 7023
 7024
 7025
 7026
 7027
 7028
 7029
 7030
 7031
 7032
 7033
 7034
 7035
 7036
 7037
 7038
 7039
 7040
 7041
 7042
 7043
 7044
 7045
 7046
 7047
 7048
 7049
 7050
 7051
 7052
 7053
 7054
 7055
 7056
 7057
 7058
 7059
 7060
 7061
 7062
 7063
 7064
 7065
 7066
 7067
 7068
 7069
 7070
 7071
 7072
 7073
 7074
 7075
 7076
 7077
 7078
 7079
 7080
 7081
 7082
 7083
 7084
 7085
 7086
 7087
 7088
 7089
 7090
 7091
 7092
 7093
 7094
 7095
 7096
 7097
 7098
 7099
 7100
 7101
 7102
 7103
 7104
 7105
 7106
 7107
 7108
 7109
 7110
 7111
 7112
 7113
 7114
 7115
 7116
 7117
 7118
 7119
 7120
 7121
 7122
 7123
 7124
 7125
 7126
 7127
 7128
 7129
 7130
 7131
 7132
 7133
 7134
 7135
 7136
 7137
 7138
 7139
 7140
 7141
 7142
 7143
 7144
 7145
 7146
 7147
 7148
 7149
 7150
 7151
 7152
 7153
 7154
 7155
 7156
 7157
 7158
 7159
 7160
 7161
 7162
 7163
 7164
 7165
 7166
 7167
 7168
 7169
 7170
 7171
 7172
 7173
 7174
 7175
 7176
 7177
 7178
 7179
 7180
 7181
 7182
 7183
 7184
 7185
 7186
 7187
 7188
 7189
 7190
 7191
 7192
 7193
 7194
 7195
 7196
 7197
 7198
 7199
 7200
 7201
 7202
 7203
 7204
 7205
 7206
 7207
 7208
 7209
 7210
 7211
 7212
 7213
 7214
 7215
 7216
 7217
 7218
 7219
 7220
 7221
 7222
 7223
 7224
 7225
 7226
 7227
 7228
 7229
 7230
 7231
 7232
 7233
 7234
 7235
 7236
 7237
 7238
 7239
 7240
 7241
 7242
 7243
 7244
 7245
 7246
 7247
 7248
 7249
 7250
 7251
 7252
 7253
 7254
 7255
 7256
 7257
 7258
 7259
 7260
 7261
 7262
 7263
 7264
 7265
 7266
 7267
 7268
 7269
 7270
 7271
 7272
 7273
 7274
 7275
 7276
 7277
 7278
 7279
 7280
 7281
 7282
 7283
 7284
 7285
 7286
 7287
 7288
 7289
 7290
 7291
 7292
 7293
 7294
 7295
 7296
 7297
 7298
 7299
 7300
 7301
 7302
 7303
 7304
 7305
 7306
 7307
 7308
 7309
 7310
 7311
 7312
 7313
 7314
 7315
 7316
 7317
 7318
 7319
 7320
 7321
 7322
 7323
 7324
 7325
 7326
 7327
 7328
 7329
 7330
 7331
 7332
 7333
 7334
 7335
 7336
 7337
 7338
 7339
 7340
 7341
 7342
 7343
 7344
 7345
 7346
 7347
 7348
 7349
 7350
 7351
 7352
 7353
 7354
 7355
 7356
 7357
 7358
 7359
 7360
 7361
 7362
 7363
 7364
 7365
 7366
 7367
 7368
 7369
 7370
 7371
 7372
 7373
 7374
 7375
 7376
 7377
 7378
 7379
 7380
 7381
 7382
 7383
 7384
 7385
 7386
 7387
 7388
 7389
 7390
 7391
 7392
 7393
 7394
 7395
 7396
 7397
 7398
 7399
 7400
 7401
 7402
 7403
 7404
 7405
 7406
 7407
 7408
 7409
 7410
 7411
 7412
 7413
 7414
 7415
 7416
 7417
 7418
 7419
 7420
 7421
 7422
 7423
 7424
 7425
 7426
 7427
 7428
 7429
 7430
 7431
 7432
 7433
 7434
 7435
 7436
 7437
 7438
 7439
 7440
 7441
 7442
 7443
 7444
 7445
 7446
 7447
 7448
 7449
 7450
 7451
 7452
 7453
 7454
 7455
 7456
 7457
 7458
 7459
 7460
 7461
 7462
 7463
 7464
 7465
 7466
 7467
 7468
 7469
 7470
 7471
 7472
 7473
 7474
 7475
 7476
 7477
 7478
 7479
 7480
 7481
 7482
 7483
 7484
 7485
 7486
 7487
 7488
 7489
 7490
 7491
 7492
 7493
 7494
 7495
 7496
 7497
 7498
 7499
 7500
 7501
 7502
 7503
 7504
 7505
 7506
 7507
 7508
 7509
 7510
 7511
 7512
 7513
 7514
 7515
 7516
 7517
 7518
 7519
 7520
 7521
 7522
 7523
 7524
 7525
 7526
 7527
 7528
 7529
 7530
 7531
 7532
 7533
 7534
 7535
 7536
 7537
 7538
 7539
 7540
 7541
 7542
 7543
 7544
 7545
 7546
 7547
 7548
 7549
 7550
 7551
 7552
 7553
 7554
 7555
 7556
 7557
 7558
 7559
 7560
 7561
 7562
 7563
 7564
 7565
 7566
 7567
 7568
 7569
 7570
 7571
 7572
 7573
 7574
 7575
 7576
 7577
 7578
 7579
 7580
 7581
 7582
 7583
 7584
 7585
 7586
 7587
 7588
 7589
 7590
 7591
 7592
 7593
 7594
 7595
 7596
 7597
 7598
 7599
 7600
 7601
 7602
 7603
 7604
 7605
 7606
 7607
 7608
 7609
 7610
 7611
 7612
 7613
 7614
 7615
 7616
 7617
 7618
 7619
 7620
 7621
 7622
 7623
 7624
 7625
 7626
 7627
 7628
 7629
 7630
 7631
 7632
 7633
 7634
 7635
 7636
 7637
 7638
 7639
 7640
 7641
 7642
 7643
 7644
 7645
 7646
 7647
 7648
 7649
 7650
 7651
 7652
 7653
 7654
 7655
 7656
 7657
 7658
 7659
 7660
 7661
 7662
 7663
 7664
 7665
 7666
 7667
 7668
 7669
 7670
 7671
 7672
 7673
 7674
 7675
 7676
 7677
 7678
 7679
 7680
 7681
 7682
 7683
 7684
 7685
 7686
 7687
 7688
 7689
 7690
 7691
 7692
 7693
 7694
 7695
 7696
 7697
 7698
 7699
 7700
 7701
 7702
 7703
 7704
 7705
 7706
 7707
 7708
 7709
 7710
 7711
 7712
 7713
 7714
 7715
 7716
 7717
 7718
 7719
 7720
 7721
 7722
 7723
 7724
 7725
 7726
 7727
 7728
 7729
 7730
 7731
 7732
 7733
 7734
 7735
 7736
 7737
 7738
 7739
 7740
 7741
 7742
 7743
 7744
 7745
 7746
 7747
 7748
 7749
 7750
 7751
 7752
 7753
 7754
 7755
 7756
 7757
 7758
 7759
 7760
 7761
 7762
 7763
 7764
 7765
 7766
 7767
 7768
 7769
 7770
 7771
 7772
 7773
 7774
 7775
 7776
 7777
 7778
 7779
 7780
 7781
 7782
 7783
 7784
 7785
 7786
 7787
 7788
 7789
 7790
 7791
 7792
 7793
 7794
 7795
 7796
 7797
 7798
 7799
 7800
 7801
 7802
 7803
 7804
 7805
 7806
 7807
 7808
 7809
 7810
 7811
 7812
 7813
 7814
 7815
 7816
 7817
 7818
 7819
 7820
 7821
 7822
 7823
 7824
 7825
 7826
 7827
 7828
 7829
 7830
 7831
 7832
 7833
 7834
 7835
 7836
 7837
 7838
 7839
 7840
 7841
 7842
 7843
 7844
 7845
 7846
 7847
 7848
 7849
 7850
 7851
 7852
 7853
 7854
 7855
 7856
 7857
 7858
 7859
 7860
 7861
 7862
 7863
 7864
 7865
 7866
 7867
 7868
 7869
 7870
 7871
 7872
 7873
 7874
 7875
 7876
 7877
 7878
 7879
 7880
 7881
 7882
 7883
 7884
 7885
 7886
 7887
 7888
 7889
 7890
 7891
 7892
 7893
 7894
 7895
 7896
 7897
 7898
 7899
 7900
 7901
 7902
 7903
 7904
 7905
 7906
 7907
 7908
 7909
 7910
 7911
 7912
 7913
 7914
 7915
 7916
 7917
 7918
 7919
 7920
 7921
 7922
 7923
 7924
 7925
 7926
 7927
 7928
 7929
 7930
 7931
 7932
 7933
 7934
 7935
 7936
 7937
 7938
 7939
 7940
 7941
 7942
 7943
 7944
 7945
 7946
 7947
 7948
 7949
 7950
 7951
 7952
 7953
 7954
 7955
 7956
 7957
 7958
 7959
 7960
 7961
 7962
 7963
 7964
 7965
 7966
 7967
 7968
 7969
 7970
 7971
 7972
 7973
 7974
 7975
 7976
 7977
 7978
 7979
 7980
 7981
 7982
 7983
 7984
 7985
 7986
 7987
 7988
 7989
 7990
 7991
 7992
 7993
 7994
 7995
 7996
 7997
 7998
 7999
 8000
 8001
 8002
 8003
 8004
 8005
 8006
 8007
 8008
 8009
 8010
 8011
 8012
 8013
 8014
 8015
 8016
 8017
 8018
 8019
 8020
 8021
 8022
 8023
 8024
 8025
 8026
 8027
 8028
 8029
 8030
 8031
 8032
 8033
 8034
 8035
 8036
 8037
 8038
 8039
 8040
 8041
 8042
 8043
 8044
 8045
 8046
 8047
 8048
 8049
 8050
 8051
 8052
 8053
 8054
 8055
 8056
 8057
 8058
 8059
 8060
 8061
 8062
 8063
 8064
 8065
 8066
 8067
 8068
 8069
 8070
 8071
 8072
 8073
 8074
 8075
 8076
 8077
 8078
 8079
 8080
 8081
 8082
 8083
 8084
 8085
 8086
 8087
 8088
 8089
 8090
 8091
 8092
 8093
 8094
 8095
 8096
 8097
 8098
 8099
 8100
 8101
 8102
 8103
 8104
 8105
 8106
 8107
 8108
 8109
 8110
 8111
 8112
 8113
 8114
 8115
 8116
 8117
 8118
 8119
 8120
 8121
 8122
 8123
 8124
 8125
 8126
 8127
 8128
 8129
 8130
 8131
 8132
 8133
 8134
 8135
 8136
 8137
 8138
 8139
 8140
 8141
 8142
 8143
 8144
 8145
 8146
 8147
 8148
 8149
 8150
 8151
 8152
 8153
 8154
 8155
 8156
 8157
 8158
 8159
 8160
 8161
 8162
 8163
 8164
 8165
 8166
 8167
 8168
 8169
 8170
 8171
 8172
 8173
 8174
 8175
 8176
 8177
 8178
 8179
 8180
 8181
 8182
 8183
 8184
 8185
 8186
 8187
 8188
 8189
 8190
 8191
 8192
 8193
 8194
 8195
 8196
 8197
 8198
 8199
 8200
 8201
 8202
 8203
 8204
 8205
 8206
 8207
 8208
 8209
 8210
 8211
 8212
 8213
 8214
 8215
 8216
 8217
 8218
 8219
 8220
 8221
 8222
 8223
 8224
 8225
 8226
 8227
 8228
 8229
 8230
 8231
 8232
 8233
 8234
 8235
 8236
 8237
 8238
 8239
 8240
 8241
 8242
 8243
 8244
 8245
 8246
 8247
 8248
 8249
 8250
 8251
 8252
 8253
 8254
 8255
 8256
 8257
 8258
 8259
 8260
 8261
 8262
 8263
 8264
 8265
 8266
 8267
 8268
 8269
 8270
 8271
 8272
 8273
 8274
 8275
 8276
 8277
 8278
 8279
 8280
 8281
 8282
 8283
 8284
 8285
 8286
 8287
 8288
 8289
 8290
 8291
 8292
 8293
 8294
 8295
 8296
 8297
 8298
 8299
 8300
 8301
 8302
 8303
 8304
 8305
 8306
 8307
 8308
 8309
 8310
 8311
 8312
 8313
 8314
 8315
 8316
 8317
 8318
 8319
 8320
 8321
 8322
 8323
 8324
 8325
 8326
 8327
 8328
 8329
 8330
 8331
 8332
 8333
 8334
 8335
 8336
 8337
 8338
 8339
 8340
 8341
 8342
 8343
 8344
 8345
 8346
 8347
 8348
 8349
 8350
 8351
 8352
 8353
 8354
 8355
 8356
 8357
 8358
 8359
 8360
 8361
 8362
 8363
 8364
 8365
 8366
 8367
 8368
 8369
 8370
 8371
 8372
 8373
 8374
 8375
 8376
 8377
 8378
 8379
 8380
 8381
 8382
 8383
 8384
 8385
 8386
 8387
 8388
 8389
 8390
 8391
 8392
 8393
 8394
 8395
 8396
 8397
 8398
 8399
 8400
 8401
 8402
 8403
 8404
 8405
 8406
 8407
 8408
 8409
 8410
 8411
 8412
 8413
 8414
 8415
 8416
 8417
 8418
 8419
 8420
 8421
 8422
 8423
 8424
 8425
 8426
 8427
 8428
 8429
 8430
 8431
 8432
 8433
 8434
 8435
 8436
 8437
 8438
 8439
 8440
 8441
 8442
 8443
 8444
 8445
 8446
 8447
 8448
 8449
 8450
 8451
 8452
 8453
 8454
 8455
 8456
 8457
 8458
 8459
 8460
 8461
 8462
 8463
 8464
 8465
 8466
 8467
 8468
 8469
 8470
 8471
 8472
 8473
 8474
 8475
 8476
 8477
 8478
 8479
 8480
 8481
 8482
 8483
 8484
 8485
 8486
 8487
 8488
 8489
 8490
 8491
 8492
 8493
 8494
 8495
 8496
 8497
 8498
 8499
 8500
 8501
 8502
 8503
 8504
 8505
 8506
 8507
 8508
 8509
 8510
 8511
 8512
 8513
 8514
 8515
 8516
 8517
 8518
 8519
 8520
 8521
 8522
 8523
 8524
 8525
 8526
 8527
 8528
 8529
 8530
 8531
 8532
 8533
 8534
 8535
 8536
 8537
 8538
 8539
 8540
 8541
 8542
 8543
 8544
 8545
 8546
 8547
 8548
 8549
 8550
 8551
 8552
 8553
 8554
 8555
 8556
 8557
 8558
 8559
 8560
 8561
 8562
 8563
 8564
 8565
 8566
 8567
 8568
 8569
 8570
 8571
 8572
 8573
 8574
 8575
 8576
 8577
 8578
 8579
 8580
 8581
 8582
 8583
 8584
 8585
 8586
 8587
 8588
 8589
 8590
 8591
 8592
 8593
 8594
 8595
 8596
 8597
 8598
 8599
 8600
 8601
 8602
 8603
 8604
 8605
 8606
 8607
 8608
 8609
 8610
 8611
 8612
 8613
 8614
 8615
 8616
 8617
 8618
 8619
 8620
 8621
 8622
 8623
 8624
 8625
 8626
 8627
 8628
 8629
 8630
 8631
 8632
 8633
 8634
 8635
 8636
 8637
 8638
 8639
 8640
 8641
 8642
 8643
 8644
 8645
 8646
 8647
 8648
 8649
 8650
 8651
 8652
 8653
 8654
 8655
 8656
 8657
 8658
 8659
 8660
 8661
 8662
 8663
 8664
 8665
 8666
 8667
 8668
 8669
 8670
 8671
 8672
 8673
 8674
 8675
 8676
 8677
 8678
 8679
 8680
 8681
 8682
 8683
 8684
 8685
 8686
 8687
 8688
 8689
 8690
 8691
 8692
 8693
 8694
 8695
 8696
 8697
 8698
 8699
 8700
 8701
 8702
 8703
 8704
 8705
 8706
 8707
 8708
 8709
 8710
 8711
 8712
 8713
 8714
 8715
 8716
 8717
 8718
 8719
 8720
 8721
 8722
 8723
 8724
 8725
 8726
 8727
 8728
 8729
 8730
 8731
 8732
 8733
 8734
 8735
 8736
 8737
 8738
 8739
 8740
 8741
 8742
 8743
 8744
 8745
 8746
 8747
 8748
 8749
 8750
 8751
 8752
 8753
 8754
 8755
 8756
 8757
 8758
 8759
 8760
 8761
 8762
 8763
 8764
 8765
 8766
 8767
 8768
 8769
 8770
 8771
 8772
 8773
 8774
 8775
 8776
 8777
 8778
 8779
 8780
 8781
 8782
 8783
 8784
 8785
 8786
 8787
 8788
 8789
 8790
 8791
 8792
 8793
 8794
 8795
 8796
 8797
 8798
 8799
 8800
 8801
 8802
 8803
 8804
 8805
 8806
 8807
 8808
 8809
 8810
 8811
 8812
 8813
 8814
 8815
 8816
 8817
 8818
 8819
 8820
 8821
 8822
 8823
 8824
 8825
 8826
 8827
 8828
 8829
 8830
 8831
 8832
 8833
 8834
 8835
 8836
 8837
 8838
 8839
 8840
 8841
 8842
 8843
 8844
 8845
 8846
 8847
 8848
 8849
 8850
 8851
 8852
 8853
 8854
 8855
 8856
 8857
 8858
 8859
 8860
 8861
 8862
 8863
 8864
 8865
 8866
 8867
 8868
 8869
 8870
 8871
 8872
 8873
 8874
 8875
 8876
 8877
 8878
 8879
 8880
 8881
 8882
 8883
 8884
 8885
 8886
 8887
 8888
 8889
 8890
 8891
 8892
 8893
 8894
 8895
 8896
 8897
 8898
 8899
 8900
 8901
 8902
 8903
 8904
 8905
 8906
 8907
 8908
 8909
 8910
 8911
 8912
 8913
 8914
 8915
 8916
 8917
 8918
 8919
 8920
 8921
 8922
 8923
 8924
 8925
 8926
 8927
 8928
 8929
 8930
 8931
 8932
 8933
 8934
 8935
 8936
 8937
 8938
 8939
 8940
 8941
 8942
 8943
 8944
 8945
 8946
 8947
 8948
 8949
 8950
 8951
 8952
 8953
 8954
 8955
 8956
 8957
 8958
 8959
 8960
 8961
 8962
 8963
 8964
 8965
 8966
 8967
 8968
 8969
 8970
 8971
 8972
 8973
 8974
 8975
 8976
 8977
 8978
 8979
 8980
 8981
 8982
 8983
 8984
 8985
 8986
 8987
 8988
 8989
 8990
 8991
 8992
 8993
 8994
 8995
 8996
 8997
 8998
 8999
 9000
 9001
 9002
 9003
 9004
 9005
 9006
 9007
 9008
 9009
 9010
 9011
 9012
 9013
 9014
 9015
 9016
 9017
 9018
 9019
 9020
 9021
 9022
 9023
 9024
 9025
 9026
 9027
 9028
 9029
 9030
 9031
 9032
 9033
 9034
 9035
 9036
 9037
 9038
 9039
 9040
 9041
 9042
 9043
 9044
 9045
 9046
 9047
 9048
 9049
 9050
 9051
 9052
 9053
 9054
 9055
 9056
 9057
 9058
 9059
 9060
 9061
 9062
 9063
 9064
 9065
 9066
 9067
 9068
 9069
 9070
 9071
 9072
 9073
 9074
 9075
 9076
 9077
 9078
 9079
 9080
 9081
 9082
 9083
 9084
 9085
 9086
 9087
 9088
 9089
 9090
 9091
 9092
 9093
 9094
 9095
 9096
 9097
 9098
 9099
 9100
 9101
 9102
 9103
 9104
 9105
 9106
 9107
 9108
 9109
 9110
 9111
 9112
 9113
 9114
 9115
 9116
 9117
 9118
 9119
 9120
 9121
 9122
 9123
 9124
 9125
 9126
 9127
 9128
 9129
 9130
 9131
 9132
 9133
 9134
 9135
 9136
 9137
 9138
 9139
 9140
 9141
 9142
 9143
 9144
 9145
 9146
 9147
 9148
 9149
 9150
 9151
 9152
 9153
 9154
 9155
 9156
 9157
 9158
 9159
 9160
 9161
 9162
 9163
 9164
 9165
 9166
 9167
 9168
 9169
 9170
 9171
 9172
 9173
 9174
 9175
 9176
 9177
 9178
 9179
 9180
 9181
 9182
 9183
 9184
 9185
 9186
 9187
 9188
 9189
 9190
 9191
 9192
 9193
 9194
 9195
 9196
 9197
 9198
 9199
 9200
 9201
 9202
 9203
 9204
 9205
 9206
 9207
 9208
 9209
 9210
 9211
 9212
 9213
 9214
 9215
 9216
 9217
 9218
 9219
 9220
 9221
 9222
 9223
 9224
 9225
 9226
 9227
 9228
 9229
 9230
 9231
 9232
 9233
 9234
 9235
 9236
 9237
 9238
 9239
 9240
 9241
 9242
 9243
 9244
 9245
 9246
 9247
 9248
 9249
 9250
 9251
 9252
 9253
 9254
 9255
 9256
 9257
 9258
 9259
 9260
 9261
 9262
 9263
 9264
 9265
 9266
 9267
 9268
 9269
 9270
 9271
 9272
 9273
 9274
 9275
 9276
 9277
 9278
 9279
 9280
 9281
 9282
 9283
 9284
 9285
 9286
 9287
 9288
 9289
 9290
 9291
 9292
 9293
 9294
 9295
 9296
 9297
 9298
 9299
 9300
 9301
 9302
 9303
 9304
 9305
 9306
 9307
 9308
 9309
 9310
 9311
 9312
 9313
 9314
 9315
 9316
 9317
 9318
 9319
 9320
 9321
 9322
 9323
 9324
 9325
 9326
 9327
 9328
 9329
 9330
 9331
 9332
 9333
 9334
 9335
 9336
 9337
 9338
 9339
 9340
 9341
 9342
 9343
 9344
 9345
 9346
 9347
 9348
 9349
 9350
 9351
 9352
 9353
 9354
 9355
 9356
 9357
 9358
 9359
 9360
 9361
 9362
 9363
 9364
 9365
 9366
 9367
 9368
 9369
 9370
 9371
 9372
 9373
 9374
 9375
 9376
 9377
 9378
 9379
 9380
 9381
 9382
 9383
 9384
 9385
 9386
 9387
 9388
 9389
 9390
 9391
 9392
 9393
 9394
 9395
 9396
 9397
 9398
 9399
 9400
 9401
 9402
 9403
 9404
 9405
 9406
 9407
 9408
 9409
 9410
 9411
 9412
 9413
 9414
 9415
 9416
 9417
 9418
 9419
 9420
 9421
 9422
 9423
 9424
 9425
 9426
 9427
 9428
 9429
 9430
 9431
 9432
 9433
 9434
 9435
 9436
 9437
 9438
 9439
 9440
 9441
 9442
 9443
 9444
 9445
 9446
 9447
 9448
 9449
 9450
 9451
 9452
 9453
 9454
 9455
 9456
 9457
 9458
 9459
 9460
 9461
 9462
 9463
 9464
 9465
 9466
 9467
 9468
 9469
 9470
 9471
 9472
 9473
 9474
 9475
 9476
 9477
 9478
 9479
 9480
 9481
 9482
 9483
 9484
 9485
 9486
 9487
 9488
 9489
 9490
 9491
 9492
 9493
 9494
 9495
 9496
 9497
 9498
 9499
 9500
 9501
 9502
 9503
 9504
 9505
 9506
 9507
 9508
 9509
 9510
 9511
 9512
 9513
 9514
 9515
 9516
 9517
 9518
 9519
 9520
 9521
 9522
 9523
 9524
 9525
 9526
 9527
 9528
 9529
 9530
 9531
 9532
 9533
 9534
 9535
 9536
 9537
 9538
 9539
 9540
 9541
 9542
 9543
 9544
 9545
 9546
 9547
 9548
 9549
 9550
 9551
 9552
 9553
 9554
 9555
 9556
 9557
 9558
 9559
 9560
 9561
 9562
 9563
 9564
 9565
 9566
 9567
 9568
 9569
 9570
 9571
 9572
 9573
 9574
 9575
 9576
 9577
 9578
 9579
 9580
 9581
 9582
 9583
 9584
 9585
 9586
 9587
 9588
 9589
 9590
 9591
 9592
 9593
 9594
 9595
 9596
 9597
 9598
 9599
 9600
 9601
 9602
 9603
 9604
 9605
 9606
 9607
 9608
 9609
 9610
 9611
 9612
 9613
 9614
 9615
 9616
 9617
 9618
 9619
 9620
 9621
 9622
 9623
 9624
 9625
 9626
 9627
 9628
 9629
 9630
 9631
 9632
 9633
 9634
 9635
 9636
 9637
 9638
 9639
 9640
 9641
 9642
 9643
 9644
 9645
 9646
 9647
 9648
 9649
 9650
 9651
 9652
 9653
 9654
 9655
 9656
 9657
 9658
 9659
 9660
 9661
 9662
 9663
 9664
 9665
 9666
 9667
 9668
 9669
 9670
 9671
 9672
 9673
 9674
 9675
 9676
 9677
 9678
 9679
 9680
 9681
 9682
 9683
 9684
 9685
 9686
 9687
 9688
 9689
 9690
 9691
 9692
 9693
 9694
 9695
 9696
 9697
 9698
 9699
 9700
 9701
 9702
 9703
 9704
 9705
 9706
 9707
 9708
 9709
 9710
 9711
 9712
 9713
 9714
 9715
 9716
 9717
 9718
 9719
 9720
 9721
 9722
 9723
 9724
 9725
 9726
 9727
 9728
 9729
 9730
 9731
 9732
 9733
 9734
 9735
 9736
 9737
 9738
 9739
 9740
 9741
 9742
 9743
 9744
 9745
 9746
 9747
 9748
 9749
 9750
 9751
 9752
 9753
 9754
 9755
 9756
 9757
 9758
 9759
 9760
 9761
 9762
 9763
 9764
 9765
 9766
 9767
 9768
 9769
 9770
 9771
 9772
 9773
 9774
 9775
 9776
 9777
 9778
 9779
 9780
 9781
 9782
 9783
 9784
 9785
 9786
 9787
 9788
 9789
 9790
 9791
 9792
 9793
 9794
 9795
 9796
 9797
 9798
 9799
 9800
 9801
 9802
 9803
 9804
 9805
 9806
 9807
 9808
 9809
 9810
 9811
 9812
 9813
 9814
 9815
 9816
 9817
 9818
 9819
 9820
 9821
 9822
 9823
 9824
 9825
 9826
 9827
 9828
 9829
 9830
 9831
 9832
 9833
 9834
 9835
 9836
 9837
 9838
 9839
 9840
 9841
 9842
 9843
 9844
 9845
 9846
 9847
 9848
 9849
 9850
 9851
 9852
 9853
 9854
 9855
 9856
 9857
 9858
 9859
 9860
 9861
 9862
 9863
 9864
 9865
 9866
 9867
 9868
 9869
 9870
 9871
 9872
 9873
 9874
 9875
 9876
 9877
 9878
 9879
 9880
 9881
 9882
 9883
 9884
 9885
 9886
 9887
 9888
 9889
 9890
 9891
 9892
 9893
 9894
 9895
 9896
 9897
 9898
 9899
 9900
 9901
 9902
 9903
 9904
 9905
 9906
 9907
 9908
 9909
 9910
 9911
 9912
 9913
 9914
 9915
 9916
 9917
 9918
 9919
 9920
 9921
 9922
 9923
 9924
 9925
 9926
 9927
 9928
 9929
 9930
 9931
 9932
 9933
 9934
 9935
 9936
 9937
 9938
 9939
 9940
 9941
 9942
 9943
 9944
 9945
 9946
 9947
 9948
 9949
 9950
 9951
 9952
 9953
 9954
 9955
 9956
 9957
 9958
 9959
 9960
 9961
 9962
 9963
 9964
 9965
 9966
 9967
 9968
 9969
 9970
 9971
 9972
 9973
 9974
 9975
 9976
 9977
 9978
 9979
 9980
 9981
 9982
 9983
 9984
 9985
 9986
 9987
 9988
 9989
 9990
 9991
 9992
 9993
 9994
 9995
 9996
 9997
 9998
 9999
10000
10001
10002
10003
10004
10005
10006
10007
10008
10009
10010
10011
10012
10013
10014
10015
10016
10017
10018
10019
10020
10021
10022
10023
10024
10025
10026
10027
10028
10029
10030
10031
10032
10033
10034
10035
10036
10037
10038
10039
10040
10041
10042
10043
10044
10045
10046
10047
10048
10049
10050
10051
10052
10053
10054
10055
10056
10057
10058
10059
10060
10061
10062
10063
10064
10065
10066
10067
10068
10069
10070
10071
10072
10073
10074
10075
10076
10077
10078
10079
10080
10081
10082
10083
10084
10085
10086
10087
10088
10089
10090
10091
10092
10093
10094
10095
10096
10097
10098
10099
10100
10101
10102
10103
10104
10105
10106
10107
10108
10109
10110
10111
10112
10113
10114
10115
10116
10117
10118
10119
10120
10121
10122
10123
10124
10125
10126
10127
10128
10129
10130
10131
10132
10133
10134
10135
10136
10137
10138
10139
10140
10141
10142
10143
10144
10145
10146
10147
10148
10149
10150
10151
10152
10153
10154
10155
10156
10157
10158
10159
10160
10161
10162
10163
10164
10165
10166
10167
10168
10169
10170
10171
10172
10173
10174
10175
10176
10177
10178
10179
10180
10181
10182
10183
10184
10185
10186
10187
10188
10189
10190
10191
10192
10193
10194
10195
10196
10197
10198
10199
10200
10201
10202
10203
10204
10205
10206
10207
10208
10209
10210
10211
10212
10213
10214
10215
10216
10217
10218
10219
10220
10221
10222
10223
10224
10225
10226
10227
10228
10229
10230
10231
10232
10233
10234
10235
10236
10237
10238
10239
10240
10241
10242
10243
10244
10245
10246
10247
10248
10249
10250
10251
10252
10253
10254
10255
10256
10257
10258
10259
10260
10261
10262
10263
10264
10265
10266
10267
10268
10269
10270
10271
10272
10273
10274
10275
10276
10277
10278
10279
10280
10281
10282
10283
10284
10285
10286
10287
10288
10289
10290
10291
10292
10293
10294
10295
10296
10297
10298
10299
10300
10301
10302
10303
10304
10305
10306
10307
10308
10309
10310
10311
10312
10313
10314
10315
10316
10317
10318
10319
10320
10321
10322
10323
10324
10325
10326
10327
10328
10329
10330
10331
10332
10333
10334
10335
10336
10337
10338
10339
10340
10341
10342
10343
10344
10345
10346
10347
10348
10349
10350
10351
10352
10353
10354
10355
10356
10357
10358
10359
10360
10361
10362
10363
10364
10365
10366
10367
10368
10369
10370
10371
10372
10373
10374
10375
10376
10377
10378
10379
10380
10381
10382
10383
10384
10385
10386
10387
10388
10389
10390
10391
10392
10393
10394
10395
10396
10397
10398
10399
10400
10401
10402
10403
10404
10405
10406
10407
10408
10409
10410
10411
10412
10413
10414
10415
10416
10417
10418
10419
10420
10421
10422
10423
10424
10425
10426
10427
10428
10429
10430
10431
10432
10433
10434
10435
10436
10437
10438
10439
10440
10441
10442
10443
10444
10445
10446
10447
10448
10449
10450
10451
10452
10453
10454
10455
10456
10457
10458
10459
10460
10461
10462
10463
10464
10465
10466
10467
10468
10469
10470
10471
10472
10473
10474
10475
10476
10477
10478
10479
10480
10481
10482
10483
10484
10485
10486
10487
10488
10489
10490
10491
10492
10493
10494
10495
10496
10497
10498
10499
10500
10501
10502
10503
10504
10505
10506
10507
10508
10509
10510
10511
10512
10513
10514
10515
10516
10517
10518
10519
10520
10521
10522
10523
10524
10525
10526
10527
10528
10529
10530
10531
10532
10533
10534
10535
10536
10537
10538
10539
10540
10541
10542
10543
10544
10545
10546
10547
10548
#! /usr/bin/python

'''haclient.py, the GUI manamgement tool for Linux-HA
'''

__authors__ ='''
Gao,Yan <ygao@suse.com>
Huang Zhen <zhenhltc@cn.ibm.com>, 2005-2006
'''

__copyright__='''
Copyright (C) 2007-2012 Gao,Yan <ygao@suse.com>
Copyright (C) 2005-2006 International Business Machines
'''

__license__ = '''
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
'''

import sys, os, string, socket, syslog, webbrowser, pickle, xml, gc, time, binascii, thread, tarfile, tempfile
from stat import *
from xml.dom.minidom import parseString
from xml.dom.minidom import getDOMImplementation
import re

import locale, gettext
app_name = "haclient"

sys.path.append("/usr/share/heartbeat-gui")
sys.path.append("/usr/lib/heartbeat-gui")
from pymgmt import *

import pygtk
pygtk.require('2.0')
import gtk, gobject

support_pyxml = False
try:
	from xml.parsers.xmlproc.xmldtd import load_dtd_string
	support_pyxml = True
except ImportError :
	pass

support_lxml = False
try :
	from lxml import etree
	support_lxml = True
except ImportError :
	pass

support_gv = False
try :
	import gv
	support_gv = True
except ImportError :
	pass

validate_type = "dtd"
mode_level = 0
name_cap = lambda name: name.replace("-"," ").replace("_"," ").title().replace("Crmd","CRMD").\
				replace("Crm","CRM").replace("Pe ", "PE ").replace("Dc ","DC ").\
				replace("Cib", "CIB").replace("Ccm", "CCM").replace("Ha", "HA").\
				replace("Id", "ID").replace("Dtd", "DTD").replace("Uuid", "UUID").\
				replace("HAve", "Have").replace("Op ", "Operation ").replace("Rsc", "Resource").\
				replace("Lrm", "LRM").replace("Acl", "ACL")

window = None
manager = None
debug_level = 0
top_window = None
last_rsc_view_page_num = 0	
last_compound_view_page_num = 0
last_cluster_view_page_num = 0

def log(string) :
	syslog.syslog(string)
	if debug_level > 0 :
		print string
		
def debug(string) :
	if debug_level == 0 :
		return
	syslog.syslog(string)
	print string
	
# If the built-in uuid module is available, don't use the external command uuidgen
try :
	import uuid
	def gen_uuid() :
		return str(uuid.uuid4())
except ImportError :
	def gen_uuid() :
		return os.popen("uuidgen").readline()[:-1]

def cond(condition, vtrue, vfalse) :
	if condition :
		return vtrue
	return vfalse
	
def edited_cb(cell, path, new_text, user_data):
      liststore, column, call_back = user_data
      liststore[path][column] = new_text
      if call_back != None :
	      call_back(None)
      return

def pygtk_newer(major, minor) :
	if gtk.pygtk_version[0] > major :
		return True
	if gtk.pygtk_version[0] == major and gtk.pygtk_version[1] >= minor :
		return True
	return False

def pygobject_newer(major, minor, rel) :
	if gobject.pygobject_version[0] > major :
		return True
	if gobject.pygobject_version[0] == major :
		if gobject.pygobject_version[1] > minor :
			return True
		if gobject.pygobject_version[1] == minor and gobject.pygobject_version[2] >= rel :
			return True
	return False
		
def delete_dir(dir_path) :
	real_path = os.path.realpath(dir_path)
	if real_path.count(os.sep) == len(real_path) :
		msgbox(_("Do not delete the root directory"))
		return

	for root, dirs, files in os.walk(dir_path, False) :
    		for name in files :
			try :
				os.unlink(os.path.join(root, name))
			except OSError, msg :
				msgbox(_("System error") + _(": ") + str(msg))
				continue
		for name in dirs :
			try :
				os.rmdir(os.path.join(root, name))
			except OSError, msg :
				msgbox(_("System error") + _(": ") + str(msg))
				continue
	try :
		os.rmdir(dir_path)
	except OSError, msg :
		msgbox(_("System error") + _(": ") + str(msg))

def add_column(widget, label, value, icon_cell_func = None, editable = False
		, options=None, call_back=None, visible = True, is_enum = False) :
	tvcolumn = gtk.TreeViewColumn(label)
	widget.append_column(tvcolumn)
	if options == None or options == [] or not pygtk_newer(2, 6):
		cell = gtk.CellRendererText()
	else :
		cell = gtk.CellRendererCombo()
		store = gtk.ListStore(str)
		cell.set_property("model",store)
		for option in options :
			store.append([option])
		cell.set_property("text-column",0)
		if is_enum :
			cell.set_property('has-entry', False)
	
	if editable :
		cell.set_property('editable', True)
		cell.connect('edited', edited_cb, (widget.get_model(), value, call_back))

	if icon_cell_func != None :
		icon_cell = gtk.CellRendererPixbuf()
		tvcolumn.pack_start(icon_cell, False)
	        tvcolumn.set_cell_data_func(icon_cell, icon_cell_func)
	tvcolumn.set_resizable(True)        
	tvcolumn.pack_start(cell, True)
	tvcolumn.add_attribute(cell, 'text', value)
	tvcolumn.set_visible(visible)
	
def msgbox(msg) :
	global top_window
	dialog = gtk.Dialog(_("Message"), top_window, gtk.DIALOG_MODAL, (gtk.STOCK_OK, True))
	dialog.set_border_width(5)
	im=gtk.Image()
	im.set_from_stock(gtk.STOCK_DIALOG_INFO, gtk.ICON_SIZE_DIALOG)
	hb=gtk.HBox()
	hb.pack_start(im)
	label = gtk.Label(msg)
	label.set_selectable(True)
	label.set_line_wrap(True)
	hb.pack_start(label)
	dialog.vbox.pack_start(hb)
	dialog.show_all()
	save_top_window = top_window
	top_window = dialog
	dialog.run()
	top_window = save_top_window
	dialog.destroy()

def confirmbox(msg, button=(gtk.STOCK_NO, gtk.RESPONSE_NO, gtk.STOCK_YES, gtk.RESPONSE_YES), title ="") :
	global top_window
	dialog = gtk.Dialog(_("Confirm"),  top_window, gtk.DIALOG_MODAL,button)
	dialog.set_border_width(5)
	im=gtk.Image()
	im.set_from_stock(gtk.STOCK_DIALOG_QUESTION, gtk.ICON_SIZE_DIALOG)
	frame = gtk.Frame()
	confirm_title = gtk.Label()
	confirm_title.set_markup('<b>'+title+'</b>')
	frame.set_label_widget(confirm_title)
	confirm_msg =  gtk.Label()
	confirm_msg.set_text(msg)
	confirm_msg.set_selectable(True)
	confirm_msg.set_line_wrap(True)
	dialog.vbox.pack_start(frame)
	hb=gtk.HBox()
	hb.pack_start(im)
	hb.pack_start(confirm_msg)
	frame.add(hb)
	dialog.vbox.resize_children()
	dialog.set_default_response(gtk.RESPONSE_YES)
	dialog.show_all()
	save_top_window = top_window
	top_window = dialog
	ret = dialog.run()
	top_window = save_top_window
	dialog.destroy()
	return ret 
	
def on_label_active(event, widget, url) :
	if not url[0] == '/' and not url.startswith("http") :
		url = "http://"+url
	webbrowser.open(url)

def make_label_active(label, text, url) :
	label.set_markup('<span foreground="blue"><u>'+text+'</u></span>')
	label.get_parent().connect("button_press_event", on_label_active, url)
	#label.get_parent().window.set_cursor(gtk.gdk.Cursor(gtk.gdk.HAND1))

def is_valid_time(time_input) :
	num_chars = "0123456789."
	valid_units = ["", "ms", "msec", "us", "usec", "s", "sec", "m", "min", "h", "hr"]
	time_str = time_input.strip()
	if time_str[0] not in num_chars :
		return (False, _("The specified time should be numeric prefixed."))

	unit_str = ""
	for i in range(len(time_str)) :
		if time_str[i] not in num_chars :
			unit_str = time_str[i:].strip()
			break

	unit_list = valid_units[:]
	unit_list.remove("")
	if unit_str not in valid_units :
		return (False, _("The specified time should default with second unit, ") +
				_("or should be suffixed with one of the following units:\n %s")%(", ".join(unit_list)))
	return (True, None)

def is_valid_id(id) :
	if id == None :
		return False
	id_regex = "^[A-Za-z_][\w.-]*$"
	return re.match(id_regex, id)

def extract_int(int_str) :
	for i in range(len(int_str)) :
		if int_str[i].isdigit() :
			num_start = i
			break
	else :
		return None

	for i in range(num_start, len(int_str)) :
		if not int_str[i].isdigit() :
			return int_str[num_start:i]
	else :
			return int_str[num_start:]

def kvbox(title, description, fields, auto_fill = None) :
	global top_window
	dialog = gtk.Dialog(title, top_window, gtk.DIALOG_MODAL,
		(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL))
	dialog.set_border_width(5)
	ok_btn = dialog.add_button(gtk.STOCK_OK, gtk.RESPONSE_OK)
	ok_btn.grab_default()
	ok_btn.grab_focus()

	if description != None :
		label = gtk.Label()
		#label.set_markup('<span size="medium" weight="bold">' + action_des + '</span>')
		label.set_markup('<b>' + description + '</b>')
		label.set_alignment(0, 0)
		#label.show()

		dialog.vbox.pack_start(label, False, padding = 2)

		separator = gtk.HSeparator()
		#separator.show()
		dialog.vbox.pack_start(separator, False, padding = 2)

	table = gtk.Table(2, 1, False)
	widgets = []
	combos = {}
	for row in range(len(fields)):
		if fields[row].auto_gen :
			widgets.append(None)
			continue
		label = gtk.Label(fields[row].label+":")
		label.set_alignment(0, 0.5)
		table.attach(label, 0, 1, row, row+1, xoptions=gtk.FILL, yoptions=gtk.FILL, xpadding=5, ypadding=2)
		if fields[row].options != None and fields[row].options!=[]:
			if fields[row].entry_editable :
				combo = gtk.combo_box_entry_new_text()
			else :
				combo = gtk.combo_box_new_text()
			for option in fields[row].options:
				combo.append_text(option)
			if fields[row].default != None :
				if fields[row].entry_editable :
					combo.child.set_text(fields[row].default)
					combo.child.set_activates_default(True)
				
				else :
					model = combo.get_model()
					iter = model.get_iter_first()
					while iter != None :
						if model.get_value(iter,0) == fields[row].default :
							combo.set_active_iter(iter)
							break
						iter = model.iter_next(iter)
			else :
				if fields[row].entry_editable :
					combo.child.set_text(fields[row].options[0])
					combo.child.set_activates_default(True)
				else :
					combo.set_active(0)
			widgets.append(combo)
			table.attach(combo, 1,2, row, row+1, yoptions=gtk.FILL, xpadding=5, ypadding=2)
			combos[fields[row].key] = combo
		else :
			entry = gtk.Entry()
			if fields[row].default != None :
				entry.set_text(fields[row].default)
			entry.set_activates_default(True)
			widgets.append(entry)
			table.attach(entry, 1,2, row, row+1, xpadding=5, ypadding=2)

	if auto_fill != None :
		if title == _("Add Parameter") and combos.has_key("name"):
			combos["name"].connect("changed", auto_fill, widgets)
		elif title == _("Add Operation") :
			if combos.has_key("name"):
				combos["name"].connect("changed", auto_fill, widgets, "name")
			if combos.has_key("role"):
				combos["role"].connect("changed", auto_fill, widgets, "role")
	
	dialog.vbox.pack_start(table, padding=2)
	dialog.vbox.show_all()
	save_top_window = top_window
	top_window = dialog

	while True :
		ret = dialog.run()
		if ret in [gtk.RESPONSE_CANCEL, gtk.RESPONSE_DELETE_EVENT] :
			top_window = save_top_window
			dialog.destroy()
			return None
		else :
			kv = {}
			passed = True
			for row in range(len(fields)):
				if fields[row].auto_gen :
					kv[fields[row].key] = gen_uuid()
					continue
				if fields[row].options != None and fields[row].options != []:
					combo = widgets[row]
					if fields[row].entry_editable :
						kv[fields[row].key] = combo.child.get_text()
					else :
						if pygtk_newer(2, 6) :
							kv[fields[row].key] = combo.get_active_text()
						else :
							iter = combo.get_active_iter()
							if iter != None :
								kv[fields[row].key] = combo.get_model().get_value(iter, 0)
							else :
								kv[fields[row].key] = ""
				else :
					entry = widgets[row]
					kv[fields[row].key] = entry.get_text()
				if not fields[row].can_be_empty and kv[fields[row].key] == "" :
					msgbox(fields[row].label+_(" can't be empty"))
					passed = False
			if passed :
				top_window = save_top_window
				dialog.destroy()
				return kv

class Field :
	key = None
	label = None
	default = None
	options = None
	can_be_empty = True
	editable = True
	auto_gen = False
	entry_editable = True
	def __init__(self, key, label=None, default=None, options=None,
			can_be_empty=True, editable=True, auto_gen=False, entry_editable = True) :
		self.key = key
		self.label = cond(label==None, key, label)
		self.default = default
		self.options = options
		self.can_be_empty = can_be_empty
		self.editable = editable
		self.auto_gen = auto_gen
		self.entry_editable = entry_editable

class RAMeta :
	name = ""
	version = None
	desc = ""
	parameters = []
	actions = []

class ElementList:
	store = None
	widget = None
	id_index = None
	idref_index = None

	def __init__(self, obj_types, elem_node_list) :
		treeiter = {}
		attr_is_any_name = False
		elem_is_any_name = False
		id_is_idref = False

		attr_list = []
		sub_obj_list = []
		for obj_type in obj_types :
		    if validate_type == "dtd" :
			self.dtd_elem = manager.get_dtd_elem(obj_type)
			for attr in self.dtd_elem.get_attr_list() :
				if attr_list.count(attr) == 0 :
					attr_list.append(attr)
			for sub_obj in self.dtd_elem.get_content_model()[1] :
				if sub_obj_list.count(sub_obj) == 0 :
					sub_obj_list.append(sub_obj)
		    else :
			sorted_rng_nodes = manager.sorted_sub_rng_nodes_by_name(obj_type)

			if sorted_rng_nodes != None :
				attr_rng_nodes = sorted_rng_nodes.get("attribute", [])
				elem_rng_nodes = sorted_rng_nodes.get("element", [])
				for rng_node in attr_rng_nodes :
					name = rng_node[0][1].getAttribute("name")
					if name == "" :
						attr_is_any_name = True
					elif attr_list.count(name) == 0 :
						attr_list.append(name)
						if name != "id" :
							continue
						sub_rng_nodes = manager.sorted_sub_rng_nodes_by_node(*rng_node[0])
						for sub_rng_node in sub_rng_nodes.get("data", []) :
							if sub_rng_nodes["data"][0][0][1].getAttribute("type") == "IDREF" :
								id_is_idref = True
								break
				for rng_node in elem_rng_nodes :
					name = rng_node[0][1].getAttribute("name")
					if name == "" :
						elem_is_any_name = True
					elif sub_obj_list.count(name) == 0 :
						sub_obj_list.append(name)
			else :
				attr_is_any_name = True
				elem_is_any_name = True

			if attr_is_any_name :
				for elem_node in elem_node_list :
					for attr_name in elem_node.attributes.keys() :
						if attr_list.count(attr_name) == 0 :
							if attr_name == "id" :
								attr_list.insert(0, attr_name)
							else :
								attr_list.append(attr_name)

		if len(sub_obj_list) > 0 or elem_is_any_name :
			has_elem = True
		else :
			has_elem = False

		self.store = gtk.ListStore(*(tuple(str for i in range(len(attr_list)+1))))
		tree = gtk.TreeView(self.store)

		if len(obj_types) > 1 :
			visible = True
		else :
			visible = False
		add_column(tree, _("Type"), 0, self.render_icon, visible=visible)

		for i in range(len(attr_list)) :
			if i == 0 :
				icon_func = self.render_icon
			else :
				icon_func = None

			if attr_list[i] == "id" :
				self.id_index = i + 1
			elif attr_list[i] == "id-ref" :
				self.idref_index = i + 1

			if attr_list[i] == "id" and not id_is_idref and not has_elem :
				visible = False
			else :
				visible = True
			add_column(tree, _(name_cap(attr_list[i])), i+1, icon_func, visible=visible)

		sw = gtk.ScrolledWindow()
		sw.set_shadow_type(gtk.SHADOW_IN)
		sw.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
		sw.add(tree)
		self.widget = sw
		self.tree = tree
		self.attr_list = attr_list

		self.update(elem_node_list)

	def render_icon(self, tvcolumn, cell, model, iter):
		icons = {
				"cluster_property_set": gtk.STOCK_PREFERENCES,
				"node": "node",
				"primitive": gtk.STOCK_DND,
				"template": gtk.STOCK_DND,
				"group": gtk.STOCK_DND_MULTIPLE,
				"clone": gtk.STOCK_COPY,
				"master": gtk.STOCK_COPY,
				"master_slave": gtk.STOCK_COPY,
				"rsc_order": gtk.STOCK_PROPERTIES,
				"rsc_location": gtk.STOCK_PROPERTIES,
				"rsc_colocation": gtk.STOCK_PROPERTIES,
				"rsc_ticket": gtk.STOCK_PROPERTIES,
				"operations": gtk.STOCK_DIALOG_AUTHENTICATION,
				"op": gtk.STOCK_DIALOG_AUTHENTICATION,
				"instance_attributes": gtk.STOCK_PREFERENCES,
				"meta_attributes": gtk.STOCK_PREFERENCES,
				"attributes": gtk.STOCK_PREFERENCES,
				"utilization": gtk.STOCK_PREFERENCES,
				"life_time": gtk.STOCK_INDENT,
				"rule" : gtk.STOCK_JUSTIFY_FILL,
				"expression": gtk.STOCK_MEDIA_STOP,
				"nvpair": gtk.STOCK_MEDIA_STOP,
				"date_expression": gtk.STOCK_JUSTIFY_FILL,
				"transient_attributes": gtk.STOCK_PREFERENCES,
				"date_spec": gtk.STOCK_MEDIA_STOP,
				"duration": gtk.STOCK_MEDIA_STOP,
				"node_state": gtk.STOCK_FIND,
				"lrm": gtk.STOCK_FIND,
				"lrm_resources": gtk.STOCK_DND_MULTIPLE,
				"lrm_resource": gtk.STOCK_DND,
				"lrm_rsc_op": gtk.STOCK_DIALOG_AUTHENTICATION,
				"acl_user": gtk.STOCK_ORIENTATION_LANDSCAPE,
				"acl_role": gtk.STOCK_ORIENTATION_LANDSCAPE,
				"read": gtk.STOCK_FIND,
				"write": gtk.STOCK_FIND_AND_REPLACE,
				"deny": gtk.STOCK_DIALOG_ERROR,
			
			}
		pb = self.tree.render_icon(icons.get(model.get_value(iter, 0), gtk.STOCK_MEDIA_STOP),
			gtk.ICON_SIZE_BUTTON, None)
       		cell.set_property('pixbuf', pb)
		return

	def update(self, elem_node_list) :
		self.elem_node_list = elem_node_list
		self.store.clear()
		self.nodes = {}
		model = self.tree.get_model()
		for elem_node in elem_node_list :
			values = [elem_node.tagName]
			values.extend([elem_node.getAttribute(attr_name) for attr_name in self.attr_list])
			iter = self.store.append(values)
			#elem_type = elem_node.tagName
			#elem_id = elem_node.getAttribute("id")
			#if elem_id == "" :
			#	elem_id = elem_node.getAttribute("id-ref")
			#if elem_id == "" :
			#	elem_id = values[1]
			#if elem_id == "" :
			#	elem_id = elem_node.parentNode.getAttribute("id") 
			#self.nodes[(elem_type, elem_id)] = elem_node

			(node_type, node_id) = self.get_node_key(model, iter)
			self.nodes[(node_type, node_id)] = elem_node

	def get_selected_node(self) :
		(model, iter) = self.tree.get_selection().get_selected()
		if iter != None :
			(node_type, node_id) = self.get_node_key(model, iter)
			return self.nodes.get((node_type, node_id))
		else :
			return None

	def save_iter_status(self, model, path, iter, expand_status):
		(type, id) = self.get_node_key(model, iter)
		expand_status[(type, id)] = self.tree.row_expanded(path)
	
	def restore_iter_status(self, model, path, iter, user_data):
		(select_type, select_id, select_path, expand_status) = user_data
		(type, id) = self.get_node_key(model, iter)
		path = model.get_path(iter)
		if type == select_type and id == select_id :
			self.tree.get_selection().select_iter(iter)
		if expand_status.has_key((type, id)) :
			if expand_status[type, id] :
				self.tree.expand_row(path, False)
			else :
				self.tree.collapse_row(path)
		else :
			self.tree.collapse_row(path)
			
	def save_tree_status(self) :
		(model, iter) = self.tree.get_selection().get_selected()
		if iter != None :
			(select_type, select_id) = self.get_node_key(model, iter)
			select_path = model.get_path(iter)
		else :
			select_type = None
			select_id = None
			select_path = None
		expand_status = {}
		self.store.foreach(self.save_iter_status, expand_status)
		return (select_type, select_id, select_path, expand_status)

	def restore_tree_status(self, tree_status) :
		self.store.foreach(self.restore_iter_status, tree_status)

	def get_node_key(self, model, iter) :
		type = model.get_value(iter, 0)
		id = ""
		if self.id_index != None :
			id = model.get_value(iter, self.id_index)

		if id == "" and self.idref_index != None :
			id = model.get_value(iter, self.idref_index)

		if id == "" :
			id = model.get_value(iter, 1)

		if id == "" and model.iter_parent(iter) != None :
			id = model.get_value(model.iter_parent(iter), 1)

		return (type, id)

class ElementTree(ElementList):
	def __init__(self, obj_types, elem_node_list) :
		self.store = gtk.TreeStore(*(tuple(str for i in range(2))))
		tree = gtk.TreeView(self.store)
		add_column(tree, _("Type"), 0, self.render_icon)
		add_column(tree, _("ID"), 1)

		sw = gtk.ScrolledWindow()
		sw.set_shadow_type(gtk.SHADOW_IN)
		sw.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
		sw.add(tree)
		self.widget = sw
		self.tree = tree

		self.update(elem_node_list)

	def update(self, elem_node_list) :
		self.elem_node_list = elem_node_list
		self.store.clear()
		self.nodes = {}
		for elem_node in elem_node_list :
			iter = self.append_node(None, elem_node)
			self.append_child_nodes(iter, elem_node)

	def append_node(self, iter, node) :
		model = self.tree.get_model()
		node_type = node.tagName
		node_id = node.getAttribute("id")
		values = [node_type, node_id]
		child_iter = self.store.append(iter, values)
		#if node_id == "" :
		#	node_id = node.parentNode.getAttribute("id")
		#self.nodes[(node_type, node_id)] = node
		
		(type, id) = self.get_node_key(model, child_iter)
		self.nodes[(type, id)] = node
		return child_iter

	def append_child_nodes(self, iter, node) :
		for child_node in node.childNodes :
			if child_node.nodeType != xml.dom.Node.ELEMENT_NODE :
				continue
			child_iter = self.append_node(iter, child_node)
			self.append_child_nodes(child_iter, child_node)

class ManageView :
	def __init__(self) :
		vpaned = gtk.VPaned()
		self.widget = vpaned

		top_vbox = gtk.VBox()
		vpaned.add1(top_vbox)

		ui_xml = '''
		<ui>
			<popup name="resource_popup">
				<menuitem action="startrsc"/>
				<menuitem action="stoprsc"/>
				<menuitem action="defaultrsc"/>
				<menuitem action="cleanuprsc"/>
				<menuitem action="migratersc"/>
				<menuitem action="unmigratersc"/>
				<menuitem action="unmanagersc"/>
				<menuitem action="managersc"/>
			</popup>
			<popup action="node_popup">
				<menuitem action="standby"/>
				<menuitem action="active"/>
			</popup>
			<popup action="tools_popup">
				<menuitem action="group-by-node"/>
				<menuitem action="record-pending"/>
				<separator/>
				<menuitem action="refresh"/>
				<menuitem action="reprobe"/>
				<menuitem action="maintenance-mode"/>
			</popup>
			<toolbar name="toolbar">
				<toolitem action="startrsc"/>
				<toolitem action="stoprsc"/>
				<toolitem action="defaultrsc"/>
				<toolitem action="cleanuprsc"/>
				<toolitem action="migratersc"/>
				<toolitem action="unmigratersc"/>
				<toolitem action="unmanagersc"/>
				<toolitem action="managersc"/>
				<separator/>
				<toolitem action="standby"/>
				<toolitem action="active"/>
				<separator/>
				<toolitem action="refresh"/>
				<toolitem action="reprobe"/>
				<toolitem action="maintenance-mode"/>
				<separator/>
				<toolitem action="record-pending"/>
				<toolitem action="group-by-node"/>
			</toolbar>
		</ui>'''

		uimanager = gtk.UIManager()
		actiongroup = gtk.ActionGroup('management')

		if pygtk_newer(2, 6) :
			startrsc_icon = gtk.STOCK_MEDIA_PLAY
			stoprsc_icon = gtk.STOCK_MEDIA_STOP
		else :
			startrsc_icon = "ha-start-resource"
			stoprsc_icon = "ha-stop-resource"

		rsc_actions = [
			('startrsc', startrsc_icon, _('St_art'), None,_('Start resource'), self.on_rsc_action),
			('stoprsc', stoprsc_icon, _('_Stop'), None,_('Stop resource'), self.on_rsc_action),
			('defaultrsc', gtk.STOCK_EXECUTE, _('_Default'), None,_('Work as default'), self.on_rsc_action),
			('cleanuprsc', gtk.STOCK_CLEAR, _('_Cleanup Resource'), None,_('Cleanup resource'), self.on_rsc_cleanup),
			('migratersc', gtk.STOCK_GO_FORWARD, _('Migra_te Resource'), None, _('Migrate a resource to specified node'), 
				self.on_migrate_rsc),
			('unmigratersc', gtk.STOCK_GO_BACK, _('Clea_r Migrate Constraints'),
				None, _('Clear constraints created by migrate'),
				self.on_unmigrate_rsc),
			('unmanagersc', "ha-unmanage-resource", _('_Unmanage Resource'), None, _('Put a resource into unmanaged mode'), 
				self.on_manage_rsc),
			('managersc', "ha-manage-resource", _('_Manage Resource'), None, _('Put a resource into managed mode'), 
				self.on_manage_rsc),
			('refresh', gtk.STOCK_REFRESH, _('Re_fresh Resources'), None, _('Refresh CIB from the LRM status'), 
				self.on_crm_rsc_cmd),
			('reprobe', gtk.STOCK_FIND, _('Re_probe Resources'), None, _('Reprobe for resources started outside of the CRM'), 
				self.on_crm_rsc_cmd),
			]
		node_actions = [
			('standby', "ha-standby-node", _('_Standby'), None,_('Make the node standby'), self.on_standby),
			('active', "ha-active-node", _('_Active'), None,_('Make the node active'), self.on_active)
			]

		toggle_tool_actions = [
			('group-by-node', gtk.STOCK_SORT_DESCENDING, _('_Group By Node'), None, _('Group resources by node'), self.change_group_mode),
			('maintenance-mode', "administration", _('_Maintenance Mode'), None,
				_('Switch to maintenance mode'), self.change_maintenance_mode),
			('record-pending', "record-pending", _('_Indicate Pending Operations'), None,
				_('Indicate pending(starting/stopping) operations'), self.change_record_pending),
			]

		#toolbar = gtk.Toolbar()
		#toolbar.set_orientation(gtk.ORIENTATION_HORIZONTAL)
		#toolbar.set_style(gtk.TOOLBAR_ICONS)
		#self.vbox.pack_start(toolbar, False)

		rsc_action_group = gtk.ActionGroup("rsc_mgmt")
		rsc_action_group.add_actions(rsc_actions)
		self.rsc_action_group = rsc_action_group

		uimanager.insert_action_group(rsc_action_group, 0)

		#for action_entry in rsc_actions :
		#	action_name = action_entry[0]
		#	action = rsc_action_group.get_action(action_name)
		#	tool_item = action.create_tool_item()
		#	toolbar.insert(tool_item, -1)
		#	action.set_accel_group(window.accelgroup)

		#separator = gtk.SeparatorToolItem()
		#toolbar.insert(separator, -1)

		node_action_group = gtk.ActionGroup("node_mgmt")
		node_action_group.add_actions(node_actions)
		self.node_action_group = node_action_group

		uimanager.insert_action_group(node_action_group, 1)

		#for action_entry in node_actions :
		#	action_name = action_entry[0]
		#	action = node_action_group.get_action(action_name)
		#	tool_item = action.create_tool_item()
		#	toolbar.insert(tool_item, -1)
		#	action.set_accel_group(window.accelgroup)

		#separator = gtk.SeparatorToolItem()
		#toolbar.insert(separator, -1)

		self.toggle_tool_action_group = gtk.ActionGroup("toggle_tools")
		self.toggle_tool_action_group.add_toggle_actions(toggle_tool_actions)

		uimanager.insert_action_group(self.toggle_tool_action_group, 2)

		#for action_entry in toggle_tool_actions :
		#	action_name = action_entry[0]
		#	action = self.toggle_tool_action_group.get_action(action_name)
		#	tool_item = action.create_tool_item()
		#	toolbar.insert(tool_item, -1)
		#	action.set_accel_group(window.accelgroup)

		uimanager.add_ui_from_string(ui_xml)
		self.uimanager = uimanager

		toolbar = uimanager.get_widget('/toolbar')
		toolbar.set_style(gtk.TOOLBAR_ICONS)
		top_vbox.pack_start(toolbar, False)

		self.manage_tree = ManageTree()
		top_vbox.pack_start(self.manage_tree.widget)
		self.manage_tree.tree.connect("cursor-changed", self.on_after_show)
		self.manage_tree.tree.connect("event-after", self.on_right_click)

		self.sub_vbox = gtk.VBox()
		vpaned.add2(self.sub_vbox)

		"""notebook =  gtk.Notebook()
		self.notebook = notebook
		vbox.pack_start(notebook, padding=2)

		check_vbox = gtk.VBox()
		check_vbox.set_border_width(5)
		tab_label = gtk.Label(_("Check"))
		notebook.append_page(check_vbox, tab_label)
		self.check_vbox = check_vbox

		scores_vbox = gtk.VBox()
		scores_vbox.set_border_width(5)
		tab_label = gtk.Label(_("Scores"))
		notebook.append_page(scores_vbox, tab_label)
		self.scores_vbox = scores_vbox"""

		self.update()

	def on_right_click(self, widget, event) :
		if event.type == gtk.gdk.BUTTON_PRESS and event.button == 3 :
			menu = None
			(model, iter) = self.manage_tree.tree.get_selection().get_selected()
			cur_type = model.get_value(iter, 0)
			if cur_type in ["node"] :
				menu = self.uimanager.get_widget("/node_popup")
			elif cur_type in ["primitive", "group", "clone", "master"] :
				menu = self.uimanager.get_widget("/resource_popup")
			else :
				menu = self.uimanager.get_widget("/tools_popup")
			menu.popup(None, None, None, event.button, event.time)

	def change_group_mode(self, action) :
		self.update()

	def change_maintenance_mode(self, action) :
		if action.get_active() :
			value = "true"
		else :
			value = "false"

		manager.set_crm_attribute("crm_config", "maintenance-mode", value)
		if manager.failed_reason != "" :
			msgbox(manager.failed_reason)

	def change_record_pending(self, action) :
		if action.get_active() :
			value = "true"
		else :
			value = "false"

		manager.set_crm_attribute("op_defaults", "record-pending", value)
		if manager.failed_reason != "" :
			msgbox(manager.failed_reason)

	def on_after_show(self, treeview = None) :
		for child in self.sub_vbox.get_children() :
			self.sub_vbox.remove(child)

		(model, iter) = self.manage_tree.tree.get_selection().get_selected()
		if iter == None :
			self.update_ui(None, None)
			return

		cur_type = model.get_value(iter, 0)
		cur_status = model.get_value(iter, 2)
		self.update_ui(cur_type, cur_status)

		id = model.get_value(iter, 1)
		if cur_type == "primitive" :
			self.show_rsc_summary(id)
			self.show_operations(id)
		elif cur_type == "cluster" : 
			self.show_sub_attrs(manager.xml_nodes["cib"])
		elif cur_type == "node" :
			for node_state in manager.xml_nodes["cib"].getElementsByTagName("node_state") :
				if node_state.getAttribute("id") == id :
					self.show_sub_attrs(node_state)
					break

	def show_sub_attrs(self, selected_node) :
		if selected_node == None :
			return

		if validate_type == "dtd" :
			dtd_elem = manager.get_dtd_elem(selected_node.tagName)
			attr_list = dtd_elem.get_attr_list()
		else :
			attr_list = []
			is_any_name = False
			sorted_rng_nodes = manager.sorted_sub_rng_nodes_by_name(selected_node.tagName)
			if sorted_rng_nodes != None :
				attr_rng_nodes = sorted_rng_nodes.get("attribute", [])
				for rng_node in attr_rng_nodes :
					name = rng_node[0][1].getAttribute("name")
					if name == "" :
						is_any_name = True
					elif attr_list.count(name) == 0 :
						attr_list.append(name)
			else :
				is_any_name = True

			if is_any_name :
				for attr_name in  selected_node.attributes.keys() :
					if attr_list.count(attr_name) == 0 :
						if attr_name == "id" :
							attr_list.insert(0, attr_name)
						else :
							attr_list.append(attr_name)

		name_labels = {}
		name_label_max_len = 0
		for attr_name in attr_list :
			if attr_name in ["admin_epoch", "num_peers", "cib_feature_revision", "remote_access_port",
						"ccm_transition", "ignore_dtd", "generated", "crm-debug-origin",
						"remote-tls-port", "remote-clear-port", "no-quorum-panic",
						"shutdown", "clear_shutdown"] :
				continue
			attr_value = selected_node.getAttribute(attr_name)
			if attr_value == "" or name_labels.get(attr_name) != None :
				continue
			hbox = gtk.HBox()
			name_label = gtk.Label(_(name_cap(attr_name)+":"))
			name_label.set_alignment(0, 0.5)
			name_label.set_selectable(True)

			name_labels[attr_name] = name_label
			name_label_len = name_label.size_request()[0]
			if name_label_len > name_label_max_len :
				name_label_max_len = name_label_len

			value_label = gtk.Label(attr_value)
			value_label.set_alignment(0, 0.5)
			value_label.set_selectable(True)

			hbox.pack_start(name_label, False, padding=5)
			hbox.pack_start(value_label, False, padding=5)
			self.sub_vbox.pack_start(hbox, False, padding=2)

		for name_label in name_labels.values() :
			name_label.set_size_request(name_label_max_len + 20, -1)

		self.sub_vbox.show_all()

	def show_rsc_summary(self, rsc_id) :
		rsc_summary = {}

		(status, mig_threshold) = manager.get_rsc_status(rsc_id)
		if mig_threshold != "0" :
			rsc_summary["migration-threshold"] = [mig_threshold]

		rsc_summary["fail-count"] = self.get_rsc_failcount(rsc_id)

		name_labels = []
		name_label_max_len = 0
		for attr_name in rsc_summary :
			for i in range(len(rsc_summary[attr_name])) :
				hbox = gtk.HBox()
				if i == 0 :
					name_label = gtk.Label(_(name_cap(attr_name)) + _(":"))
				else :
					name_label = gtk.Label("")
				name_label.set_alignment(0, 0.5)
				name_label.set_selectable(True)

				name_labels.append(name_label)
				name_label_len = name_label.size_request()[0]
				if name_label_len > name_label_max_len :
					name_label_max_len = name_label_len

				value_label = gtk.Label(rsc_summary[attr_name][i])
				value_label.set_alignment(0, 0.5)
				value_label.set_selectable(True)

				hbox.pack_start(name_label, False, padding=5)
				hbox.pack_start(value_label, False, padding=5)
				self.sub_vbox.pack_start(hbox, False, padding=2)

		for name_label in name_labels :
			name_label.set_size_request(name_label_max_len, -1)

		self.sub_vbox.show_all()

	def get_rsc_failcount(self, rsc_id) :
		rsc_summary = []
		for trans_attr_node in manager.xml_nodes["cib"].getElementsByTagName("transient_attributes") :
			node_id = trans_attr_node.getAttribute("id")
			fail_count = ""
			last_failure = ""
			for nv_node in trans_attr_node.getElementsByTagName("nvpair") :
				nv_name = nv_node.getAttribute("name")
				if nv_name.count("fail-count") and nv_name.count(rsc_id) :
					fail_count = nv_node.getAttribute("value")
				elif nv_name.count("last-failure") and nv_name.count(rsc_id) :
					last_failure = nv_node.getAttribute("value")

			if fail_count == "" :
				continue

			summary_str = fail_count
			node_name = manager.node_name(node_id)
			if node_name != "" :
				summary_str += "  (%s, "%node_name
			else :
				summary_str += "  (%s, "%node_id

			if last_failure != "" :
				last_failure_time = time.ctime(float(last_failure))
				if len(summary_str) > 0 :
					summary_str += "  "
				summary_str += _("last failure at \"%s\"")%last_failure_time

			summary_str += ")"

			rsc_summary.append(summary_str)
		return rsc_summary

	def show_operations(self, rsc_id) :
		op_fields = ["Call ID", "Operation", "Interval", "Return Code", "Status", 
				"Last Run", "Exec Time", "Queue Time", "Last Return Code Change"]
			
		store = gtk.TreeStore(*(tuple(str for i in range(len(op_fields)))))
		tree = gtk.TreeView(store)
		for i in range(len(op_fields)) :
			add_column(tree, _(op_fields[i]), i)

		ops = self.get_operations(rsc_id)
		for node_id in ops :
			if len(ops[node_id]) == 0 :
				continue

			node_name = manager.node_name(node_id)
			if node_name == "" :
				node_name = node_id

			node_root = store.append(None, [node_name, "", "", "", "", "", "", "", ""])
			call_ids = [call_id for call_id in ops[node_id]]
			call_ids.sort()
			for call_id in call_ids :
				store.append(node_root, ops[node_id][call_id])
	
		tree.expand_all()

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

		self.sub_vbox.pack_start(sw)
		self.sub_vbox.show_all()

	def get_operations(self, rsc_id) :
		if validate_type == "dtd" :
			call_id_key = "call_id"
			rc_code_key = "rc_code"
			op_status_key = "op_status"
			last_run_key = "last_run"
			exec_time_key = "exec_time"
			queue_time_key = "queue_time"
			last_rc_change_key = "last_rc_change"
		else :
			call_id_key = "call-id"
			rc_code_key = "rc-code"
			op_status_key = "op-status"
			last_run_key = "last-run"
			exec_time_key = "exec-time"
			queue_time_key = "queue-time"
			last_rc_change_key = "last-rc-change"

		operations = {}
		for lrm_node in manager.xml_nodes["cib"].getElementsByTagName("lrm") :
			node_id = lrm_node.getAttribute("id")
			operations[node_id] = {}
			for lrm_resource_node in lrm_node.getElementsByTagName("lrm_resource") :
				if lrm_resource_node.getAttribute("id") == rsc_id :
					for lrm_rsc_op in lrm_resource_node.getElementsByTagName("lrm_rsc_op") :
						operation = lrm_rsc_op.getAttribute("operation")
						interval = lrm_rsc_op.getAttribute("interval")
						if interval == "0" :
							interval_time = ""
							if operation == "monitor" :
								operation = "probe"
						elif interval == "" :
							interval_time = ""
						else :
							interval_time = interval+"ms"

						rc_code = lrm_rsc_op.getAttribute(rc_code_key)

						if rc_code == "7" and operation == "probe" :
							continue
						elif operation == "notify" :
							continue

						rc_str = manager.lrm_op_rc2str(rc_code)
						if rc_code == "" :
							result_str = rc_str
						else :
							result_str = "%s (rc=%s)"%(rc_str, rc_code)

						call_id = lrm_rsc_op.getAttribute(call_id_key)

						op_status = lrm_rsc_op.getAttribute(op_status_key)
						op_status_str = manager.op_status2str(op_status)

						last_run = lrm_rsc_op.getAttribute(last_run_key)
						if last_run != "" :
							last_run_time = time.ctime(float(last_run))
						else :
							last_run_time = ""

						exec_time = lrm_rsc_op.getAttribute(exec_time_key)
						if exec_time == "" :
							exec_time_str = ""
						else :
							exec_time_str = exec_time + "ms"

						queue_time = lrm_rsc_op.getAttribute(queue_time_key)
						if queue_time == "" :
							queue_time_str = ""
						else :
							queue_time_str = queue_time + "ms"

						last_rc_change = lrm_rsc_op.getAttribute(last_rc_change_key)
						if last_rc_change != "" :
							last_rc_change_time = time.ctime(float(last_rc_change))
						else :
							last_rc_change_time = ""

						operations[node_id][int(call_id)] = [
										call_id,
										operation,
										interval_time,
										result_str,
										op_status_str,
										last_run_time, 
										exec_time_str, 
										queue_time_str,
										last_rc_change_time 
										]
					break
		return operations

	def set_action_sensitive(self, action, sensitive) :
		if self.rsc_action_group.get_action(action) != None :
			self.rsc_action_group.get_action(action).set_property("sensitive", sensitive)
		elif self.node_action_group.get_action(action) != None :
			self.node_action_group.get_action(action).set_property("sensitive", sensitive)

	def update_ui(self, cur_type = None, cur_status = None) :
		all_rsc_type = ["primitive", "group", "clone", "master"]

		self.set_action_sensitive('standby',
			cur_type in ["node"]
			and string.find(cur_status, _("standby")) == -1
			and string.find(cur_status, _("never started")) == -1)

		self.set_action_sensitive('active',
			cur_type in ["node"]
			and string.find(cur_status, _("standby")) != -1
			and string.find(cur_status, _("never started")) == -1)

		self.set_action_sensitive('cleanuprsc',
			cur_type in all_rsc_type)

		self.set_action_sensitive('startrsc',
			cur_type in all_rsc_type)
		
		self.set_action_sensitive('stoprsc',
			cur_type in all_rsc_type)

		self.set_action_sensitive('defaultrsc',
			cur_type in all_rsc_type)

		self.set_action_sensitive('migratersc',
			cur_type in all_rsc_type)

		self.set_action_sensitive('managersc',
			cur_type in all_rsc_type)

		self.set_action_sensitive('unmanagersc',
			cur_type in all_rsc_type)

	def update(self, xml_node = None) :
		view_status = self.save_status()
		self.manage_tree.update(view_status[0])
		self.widget.show_all()
		self.restore_status(view_status)

	def on_rsc_action(self, action) :
		(cur_type, cur_name) = self.manage_tree.get_selected_node()
		if action.get_name() == "startrsc" :
			target_role = "Started"
		elif action.get_name() == "stoprsc" :
			target_role = "Stopped"
		else :
			target_role = "#default"

		if validate_type == "dtd" :
			metaattr_name = "target_role"
		else :
			metaattr_name = "target-role"

		real_rsc_id = cur_name.split(":")[0]
		
		rsc_xml = None
		for resources_node in manager.xml_nodes["cib"].cloneNode(True).getElementsByTagName("resources") :
			for rsc_node in resources_node.getElementsByTagName(cur_type) :
				if rsc_node.getAttribute("id") == real_rsc_id :
					rsc_xml = rsc_node
					break

		if rsc_xml == None : 
			msgbox(_("Cannot find the %s: %s")%(cur_type, real_rsc_id))
			return

		supported_rsc_types = manager.get_supported_rsc_types()

		found_nv = False
		clear_all = False
		for nv_xml_node in rsc_xml.getElementsByTagName("nvpair") :
			if nv_xml_node.getAttribute("name") != metaattr_name :
				continue

			target_rsc = nv_xml_node
			while target_rsc.tagName not in supported_rsc_types :
				target_rsc = target_rsc.parentNode

			target_rsc_id = target_rsc.getAttribute("id")
			current_value = nv_xml_node.getAttribute("value")
			
			if target_rsc_id == real_rsc_id :
				found_nv = True
				if target_role == "#default" :
					nv_xml_node.parentNode.removeChild(nv_xml_node)
				else :
					nv_xml_node.setAttribute("value", target_role)
			else :
				if not clear_all :
					retval = confirmbox(_("Caused by your previous action, this attribute has been set to \"")
						+current_value
						+_("\".")+"\n\n"
						+_("Recommended") + _(":")+"\n"
						+_("Select \"Clear All\" to remove the attributes for all of the sub-resources.")+"\n"
						+_("All of the sub-resources will inherit the attributes from their parent."),
						(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL,
						gtk.STOCK_NO, gtk.RESPONSE_NO,
						gtk.STOCK_CLEAR, gtk.RESPONSE_OK,
						"Clear All", gtk.RESPONSE_YES),
						_("Clear the %s=\"%s\" attribute for sub-resource \"")%(metaattr_name, current_value)
						+target_rsc_id+_("\"?"))
					if retval in [gtk.RESPONSE_CANCEL, gtk.RESPONSE_DELETE_EVENT] :
						return	

					if retval in [gtk.RESPONSE_OK, gtk.RESPONSE_YES] :
						nv_xml_node.parentNode.removeChild(nv_xml_node)

					if retval == gtk.RESPONSE_YES :
						clear_all = True
				else :
					nv_xml_node.parentNode.removeChild(nv_xml_node)

		if not found_nv and target_role != "#default" :
			(parent_xml_node, add_obj_type, new_mid_elem) = manager.real_add_obj_type(rsc_xml, "meta_attributes", True)
			if parent_xml_node == None :
				msgbox(_("Cannot %s %s: XML processing error")%(target_role, real_rsc_id))
				return

			impl = getDOMImplementation()
			newdoc = impl.createDocument(None, "nvpair", None)
			nv = newdoc.documentElement
			parent_xml_node.appendChild(nv)
			attr_id = manager.auto_unique_id(nv, metaattr_name)
			nv.setAttribute("id", attr_id)
			nv.setAttribute("name", metaattr_name)
			nv.setAttribute("value", target_role)

		xml_str = rsc_xml.toxml().replace("\n", "")
		manager.cib_do_cmd("cib_replace\n%s\n%s"%(str(rsc_xml.tagName), str(xml_str)))
		if manager.failed_reason != "" :
			msgbox(manager.failed_reason)

	def on_rsc_cleanup(self, action) :
		(cur_type, cur_name) = self.manage_tree.get_selected_node()
		rsc_list = manager.get_all_rsc()
		if rsc_list == None :
			return
		rsc_options = rsc_list[:]
		rsc_options.insert(0, _("all resources"))

		node_list = manager.get_normal_nodes()
		if node_list == None :
			return
		node_options = node_list[:]
		node_options.insert(0, _("all nodes"))

		cleanup = kvbox(_("Cleanup Resource"), None,
				[Field("rsc", _("Resource"), cur_name, rsc_options, False, entry_editable = False),
				Field("node", _("Node"), _("all nodes"), node_options, False, entry_editable = False)])

		if cleanup != None :
			cleanup_rscs = []
			if cleanup["rsc"] == _("all resources") :
				for rsc in rsc_list :
					if manager.get_rsc_type(rsc) == "primitive" :
						cleanup_rscs.append(rsc)
			elif manager.get_rsc_type(cleanup["rsc"]) != "primitive" :
				all_subrscs = manager.get_all_subrsc(cleanup["rsc"])
				if all_subrscs == None :
					return
				for rsc in all_subrscs :
					if manager.get_rsc_type(rsc) == "primitive" :
						cleanup_rscs.append(rsc)
			else :
				cleanup_rscs.append(cleanup["rsc"])
			
			if cleanup["node"] == _("all nodes") :
				cleanup_nodes = node_list
			else :
				cleanup_nodes = [cleanup["node"]]
					
			for rsc in cleanup_rscs :
				for node in cleanup_nodes :
					#manager.do_cmd("cleanup_rsc\n" + node + "\n" + rsc)
					manager.do_cmd("crm_rsc_cmd\n%s\ncleanup\n%s"%(rsc, node))

	def on_migrate_rsc(self, action) :
		global top_window
		(cur_type, cur_name) = self.manage_tree.get_selected_node()

		dialog = gtk.Dialog(_("Migrate Resource"), top_window, gtk.DIALOG_MODAL,
			(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL, gtk.STOCK_OK, gtk.RESPONSE_OK))
		dialog.set_border_width(5)
		dialog.set_default_response(gtk.RESPONSE_OK)

		duration_elems = ["yrs", "mths", "wks", "days", "hrs", "mins", "secs"]

		combos = {}
		checkbuttons = {}
		spinbuttons = {}
		name_labels = []
		name_label_max_len = 0	
		for key in ["rsc", "to_node", "force", "duration", "period", "time"] :
			hbox = gtk.HBox()
			if key in ["rsc", "to_node"] :
				name_label = gtk.Label(_(name_cap(key))+_(":"))
				name_label.set_alignment(0, 0.5)
				name_labels.append(name_label)

				name_label_len = name_label.size_request()[0]
				if name_label_len >  name_label_max_len :
					name_label_max_len = name_label_len

				hbox.pack_start(name_label, False, padding=2)

			if key == "rsc" :
				widget = gtk.combo_box_new_text()
				for rsc in manager.get_all_real_rsc() :
					widget.append_text(rsc)

				model = widget.get_model()
				iter = model.get_iter_first()
				while iter != None :
					if model.get_value(iter,0) == manager.obj_real_id(cur_name) :
						widget.set_active_iter(iter)
						break
					iter = model.iter_next(iter)

				combos[key] = widget
				hbox.pack_start(widget, True, padding=2)
			elif key == "to_node" :
				widget = gtk.combo_box_new_text()
				node_list = manager.get_normal_nodes()
				node_options = node_list[:]
				node_options.insert(0, "")
				for node in node_options :
					widget.append_text(node)

				combos[key] = widget
				hbox.pack_start(widget, True, padding=2)
			elif key == "force" :
				widget = gtk.CheckButton(_(name_cap(key)))

				checkbuttons[key] = widget
				hbox.pack_start(widget, True, padding=2)
			elif key == "duration" :
				widget = gtk.CheckButton(_(name_cap(key)))
				checkbuttons[key] = widget
				hbox.pack_start(widget, True, padding=2)
				widget.connect("toggled", self.on_duration_toggled)

			elif key == "period" :
				for key in duration_elems[:4] :
					adj = gtk.Adjustment(0, 00, 99, 1, 3)
					widget = gtk.SpinButton(adj, 0, 0)
					widget.set_width_chars(2)
					widget.set_wrap(True)
					hbox.pack_start(widget, False)
					spinbuttons[key] = widget

					label = gtk.Label(_(name_cap(key)) + " ")
					hbox.pack_start(label, False, padding=2)
					hbox.set_sensitive(False)
					self.period_hbox = hbox

			else :
				for key in duration_elems[4:] :
					adj = gtk.Adjustment(0, 00, 99, 1, 5)
					widget = gtk.SpinButton(adj, 0, 0)
					widget.set_width_chars(2)
					widget.set_wrap(True)
					hbox.pack_start(widget, False)
					spinbuttons[key] = widget

					label = gtk.Label(_(name_cap(key)) + " ")
					hbox.pack_start(label, False, padding=2)
					hbox.set_sensitive(False)
					self.time_hbox = hbox

			dialog.vbox.pack_start(hbox, False, padding=2)
		
		for name_label in name_labels :
			name_label.set_size_request(name_label_max_len, -1)

		widgets = {}
		widgets["combos"] = combos
		widgets["checkbuttons"] = checkbuttons
		widgets["spinbuttons"] = spinbuttons

		widget_group = WidgetGroup(widgets)

		save_top_window = top_window
		top_window = dialog
		dialog.show_all()

		ret = dialog.run()
		if ret in [gtk.RESPONSE_CANCEL, gtk.RESPONSE_DELETE_EVENT] :
			top_window = save_top_window
			dialog.destroy()
			return

		migrate = widget_group.get_values()
		
		top_window = save_top_window
		dialog.destroy()

		period = ""
		if self.period_hbox.get_property("sensitive") :
			for key in duration_elems[:4] :
				if migrate.get(key, "0.0") != "0.0" :
					period += migrate[key].split(".")[0] + key[0].upper()
		time = ""
		if self.time_hbox.get_property("sensitive") :
			for key in duration_elems[4:] :
				if migrate.get(key, "0.0") != "0.0" :
					time += migrate[key].split(".")[0] + key[0].upper()

		if period == "" and time == "" :
			duration = ""
		else :
			duration = "P" + period
			if time != "" :
				duration += "T" + time

		manager.do_cmd("migrate\n%s\n%s\n%s\n%s"
				%(migrate.get("rsc", ""), migrate.get("to_node", ""), migrate.get("force", ""), duration))
		if manager.failed_reason != "" :
			msgbox(manager.failed_reason.replace("This message can be disabled with -Q", "").replace
				("using the 'crm_resource -U' command or manually with cibadmin", "by \"Clear Migrate Constraints\""))

	def on_duration_toggled(self, widget) :
		 self.period_hbox.set_sensitive(widget.get_active())
		 self.time_hbox.set_sensitive(widget.get_active())

	def on_unmigrate_rsc(self, action) :
		rsc_locations = {}
		for rsc_location in manager.xml_nodes["cib"].getElementsByTagName("rsc_location") :
			id = str(rsc_location.getAttribute("id"))
			rsc_locations[id] = rsc_location
		migrate_ids = {}
		rsc_ids = []
		for id in rsc_locations :
			for prefix in ["cli-prefer-", "cli-standby-"] :
				if id.startswith(prefix) :
					split_id = id.split(prefix)
					if len(split_id) > 1 :
						rsc_id = split_id[1]
						if not migrate_ids.has_key(rsc_id) :
							migrate_ids[rsc_id] = []
						migrate_ids[rsc_id].append(id)

		all_str = _("all migrated resources")
		rsc_list = migrate_ids.keys()[:]
		rsc_list.insert(0, all_str)

		(cur_type, cur_name) = self.manage_tree.get_selected_node()
		if cur_name in migrate_ids :
			default_option = cur_name
		else :
			default_option = all_str
		unmigrate = kvbox(_("Clear Migrate Constraints"), None,
				[Field("rsc", _("Resource"), default_option, rsc_list, False, entry_editable = False)])

		if unmigrate != None :
			if unmigrate["rsc"] == all_str :
				for rsc_id in migrate_ids.keys() :
					for id in migrate_ids[rsc_id] :
						xml_str = rsc_locations[id].toxml().replace("\n", "")
						manager.cib_do_cmd("cib_delete\nconstraints\n%s"%(str(xml_str)))
			else :
				for id in migrate_ids[unmigrate["rsc"]] :
					xml_str = rsc_locations[id].toxml().replace("\n", "")
					manager.cib_do_cmd("cib_delete\nconstraints\n%s"%(str(xml_str)))

	def on_manage_rsc(self, action) :
		(cur_type, cur_name) = self.manage_tree.get_selected_node()

		if action.get_name() == "managersc" :
			is_managed = "true"
		elif action.get_name() == "unmanagersc" :
			is_managed = "false"
		else :
			is_managed = "#default"

		if validate_type == "dtd" :
			metaattr_name = "is_managed"
		else :
			metaattr_name = "is-managed"

		if is_managed == "#default" :
			manager.do_cmd("del_rsc_attr\n%s\nmeta\n%s"%(manager.obj_real_id(cur_name), metaattr_name))
		else :
			manager.do_cmd("set_rsc_attr\n%s\nmeta\n%s\n%s"%(manager.obj_real_id(cur_name), metaattr_name, is_managed))
			if manager.failed_reason != "" :
				msgbox(manager.failed_reason)

	def on_crm_rsc_cmd(self, action) :
		global top_window
		cmd = action.get_name()
		node_list = manager.get_normal_nodes()
		if node_list == None :
			node_list = []
		#node_options = node_list[:]
		#node_options.insert(0, "")

		title = _("%s Resources")%_(name_cap(cmd))
		dialog = gtk.Dialog(title, top_window, gtk.DIALOG_MODAL,
			(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL, gtk.STOCK_OK, gtk.RESPONSE_OK))
		dialog.set_border_width(5)
		dialog.set_default_response(gtk.RESPONSE_OK)

		combos ={}
		for key in ["node"] :
			hbox = gtk.HBox()
			name_label = gtk.Label(_(name_cap(key)) + _(":"))
			name_label.set_alignment(0, 0.5)

			checkbutton = gtk.CheckButton()
			checkbutton.add(name_label)
			hbox.pack_start(checkbutton, False, padding=2)

			value_widget = gtk.combo_box_new_text()
			for node in node_list :
				value_widget.append_text(node)
			value_widget.set_sensitive(False)
			hbox.pack_start(value_widget, True, padding=2)
			combos[key] = value_widget

			checkbutton.connect("toggled", self.on_checkbutton_toggled, value_widget)
			dialog.vbox.pack_start(hbox, False, padding=2)

		widgets = {}
		widgets["combos"] = combos
		widget_group = WidgetGroup(widgets)

		dialog.show_all()

		save_top_window = top_window
		top_window = dialog

		ret = dialog.run()
		if ret in [gtk.RESPONSE_CANCEL, gtk.RESPONSE_DELETE_EVENT] :
			top_window = save_top_window
			dialog.destroy()
			return

		cmd_args = widget_group.get_values()
		top_window = save_top_window
		dialog.destroy()

		#cmd_args = kvbox(_("%s Resources")%_(name_cap(cmd)), None,
		#		[Field("node", _("Node"), "", node_options, True, entry_editable = False)])

		#if cmd_args == None :
		#	return

		manager.do_cmd("crm_rsc_cmd\n\n%s\n%s"%(cmd, cmd_args.get("node", "")))
		if manager.failed_reason != "" :
			msgbox(manager.failed_reason)

	def on_checkbutton_toggled(self, checkbutton, widget) :
		widget.set_sensitive(checkbutton.get_active())

	def on_standby(self, action) :
		(cur_type, cur_name) = self.manage_tree.get_selected_node()
		if confirmbox(_("Make") +" " +cur_name + " " +_("standby")+"?") == gtk.RESPONSE_YES:
			#manager.do_cmd("standby\n"+cur_name + "\n" + "on")
			manager.do_cmd("crm_attribute\nnodes\nset\nstandby\non\n%s\n\n"%cur_name)
			if manager.failed_reason != "" :
				msgbox(manager.failed_reason)

	def on_active(self, action) :
		(cur_type, cur_name) = self.manage_tree.get_selected_node()
		if confirmbox(_("Make") +" " +cur_name + " " + _("active")+"?") == gtk.RESPONSE_YES :
			#manager.do_cmd("standby\n"+cur_name + "\n" + "off")
			manager.do_cmd("crm_attribute\nnodes\nset\nstandby\noff\n%s\n\n"%cur_name)
			if manager.failed_reason != "" :
				msgbox(manager.failed_reason)

	def save_status(self) :
		group_by_node = self.toggle_tool_action_group.get_action("group-by-node").get_active()
		tree_status = self.manage_tree.save_tree_status()
		paned_position = self.widget.get_position()
		return (group_by_node, tree_status, paned_position)

	def restore_status(self, view_status) :
		#if view_status == None :
		#	return
		(group_by_node, tree_status, paned_position) = view_status
		if group_by_node :
			self.toggle_tool_action_group.get_action("group-by-node").set_active(group_by_node)

		self.update_tool_button()
		self.manage_tree.restore_tree_status(tree_status)
		self.on_after_show()

		if paned_position :
			(paned_width, paned_height) = self.widget.size_request()
			self.manage_tree.widget.set_size_request(paned_width, paned_position)
			self.widget.set_position(paned_position)

	def update_tool_button(self) :
		#value = manager.do_cmd("crm_attribute\ncrm_config\nget\nmaintenance-mode\n\n\n\n")
		#if value != None and len(value) > 0 and value[0].count("true") :
		value = manager.find_attribute("crm_config", "maintenance-mode")
		action = self.toggle_tool_action_group.get_action("maintenance-mode")
		if pygtk_newer(2, 10) and pygobject_newer(2, 12, 3) :
			action.disconnect_by_func(self.change_maintenance_mode)

		if value == "true" :
			if not action.get_active() :
				action.set_active(True)
		else :
			if action.get_active() :
				action.set_active(False)

		if pygtk_newer(2, 10) and pygobject_newer(2, 12, 3) :
			action.connect("toggled", self.change_maintenance_mode)

		#value = manager.do_cmd("crm_attribute\nop_defaults\nget\nrecord-pending\n\n\n\n")
		#if value != None and len(value) > 0 and value[0].count("true") :
		value = manager.find_attribute("op_defaults", "record-pending")
		action = self.toggle_tool_action_group.get_action("record-pending")
		if pygtk_newer(2, 10) and pygobject_newer(2, 12, 3) :
			action.disconnect_by_func(self.change_record_pending)

		if value == "true" :
			if not action.get_active() :
				action.set_active(True)
		else :
			if action.get_active() :
				action.set_active(False)

		if pygtk_newer(2, 10) and pygobject_newer(2, 12, 3) :
			action.connect("toggled", self.change_record_pending)

class ManageTree :
	store = None
	tree = None
	last_iter = None
	def __init__(self) :
		global top_window
		treeiter = {}
		self.store = gtk.TreeStore(str, str, str, str)

		tree = gtk.TreeView(self.store)
		add_column(tree, _("Type"), 0, self.render_type_icon, visible=False)
		add_column(tree, _("Name"), 1, self.render_type_icon)
		add_column(tree, _("Status"), 2, self.render_status_icon)
		add_column(tree, _("Details"), 3)
		(window_width, window_height) = top_window.get_size()
		tree.set_size_request(500, window_height / 2)
		#tree.connect("cursor-changed", self.on_cursor_changed, tree.get_selection())
		#tree.connect("event-after", self.on_right_click)

		sw = gtk.ScrolledWindow()
		sw.set_shadow_type(gtk.SHADOW_IN)
		sw.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
		sw.add(tree)
		self.widget = sw
		self.tree = tree

	def get_selected_node(self):
		(model, iter) = self.tree.get_selection().get_selected()
		type = model.get_value(iter, 0)
		name = model.get_value(iter, 1)
		return (type, name)

	def render_type_icon(self, tvcolumn, cell, model, iter) :
		icons = {
			"cluster": "nodes",
			"node": "node", 
			"resources": gtk.STOCK_DIRECTORY,
			"inactive resources": gtk.STOCK_DIRECTORY,
			"primitive": gtk.STOCK_DND,
			"group": gtk.STOCK_DND_MULTIPLE,
			"clone": gtk.STOCK_COPY,
			"master": gtk.STOCK_COPY,
			"master_slave": gtk.STOCK_COPY,
			}
		pb = self.tree.render_icon(icons.get(model.get_value(iter, 0), gtk.STOCK_MEDIA_STOP),
			gtk.ICON_SIZE_BUTTON, None)
		cell.set_property('pixbuf', pb)
		return
	
	def render_status_icon(self, tvcolumn, cell, model, iter):
 		icons = {-2:"stopped",
			 -1:gtk.STOCK_PREFERENCES,
			  0:"running",
			  1:"stopped",
			  2:"dirty-stopped",
			  3:"failed",
			  4:"starting",
			  5:"stopping"}
		status = self.iter_status(model,iter)
		pb = self.tree.render_icon(icons[status],
			gtk.ICON_SIZE_SMALL_TOOLBAR, None)
       		cell.set_property('pixbuf', pb)
		return

	def iter_status(self, model, iter) :
		# -1:config 0: ok, 1: stopped, 2: umanaged, 3:failed, 4:stop failed
		type = model.get_value(iter, 0)
		status = model.get_value(iter, 2)
		iter_status = 0
		if type == "primitive" :
			if string.find(status, _("unmanaged")) != -1 \
					or string.find(status, _("unclean")) != -1 \
					or string.find(status, _("failure ignored")) != -1 :
				iter_status = 2
			elif string.find(status, _("failed")) != -1 :
				iter_status = 3
			elif string.find(status, _("starting")) != -1 :
				iter_status = 4
			elif string.find(status, _("stopping")) != -1 :
				iter_status = 5
			elif string.find(status, _("not running")) != -1 :
				iter_status = 1
			elif string.find(status, _("running")) != -1 :
				iter_status = 0
			else :
				iter_status = 2
		
		elif type == "node" :
			if status == _("ping node") :
				iter_status = -1				
			elif string.find(status, _("online")) != -1 :
				iter_status = 0
			else :
				iter_status = 1
		elif type in ["group","resources","clone","master"]:
			iter_status = 0
		else :
			iter_status = -2
		if model.iter_has_child(iter) :
			for i in range(0, model.iter_n_children(iter)) :
				child = model.iter_nth_child(iter,i)
				child_status = self.iter_status(model, child)
				if child_status > iter_status :
					iter_status = child_status
		
		return iter_status

	def save_iter_status(self, model, path, iter, expand_status):
		type = model.get_value(iter, 0)
		name = model.get_value(iter, 1)
		expand_status[(type, name)] = self.tree.row_expanded(path)
	
	def restore_iter_status(self, model, path, iter, user_data):
		(select_name, select_type, select_path, expand_status) = user_data
		type = model.get_value(iter, 0)
		name = model.get_value(iter, 1)
		path = model.get_path(iter)
		if name == select_name and type == select_type :
			self.tree.get_selection().select_iter(iter)
		if expand_status.has_key((name,type)) :
			if expand_status[name, type] :
				self.tree.expand_row(path, False)
			else :
				self.tree.collapse_row(path)
		else :
			self.tree.expand_row(path, False)
			
	def save_tree_status(self) :
		(model, iter) = self.tree.get_selection().get_selected()
		if iter != None :
			select_type = model.get_value(iter, 0)
			select_name = model.get_value(iter, 1)
			select_path = model.get_path(iter)
		else :
			select_name = None
			select_type = None
			select_path = None
		expand_status = {}
		self.store.foreach(self.save_iter_status, expand_status)
		return (select_name, select_type, select_path, expand_status)

	def restore_tree_status(self, tree_status) :
		self.store.foreach(self.restore_iter_status, tree_status)
		(name, type, path, expand_status) = tree_status
		if  name == None :
			self.tree.get_selection().select_path((0,))
			self.tree.expand_all()
		
	def update(self, group_by_node = False) :
		self.store.clear()
		if not manager.connected :
			return
		
		nodes = manager.get_all_nodes()
		if nodes == None :
			return

		active_nodes = manager.get_active_nodes()
		if active_nodes == None :
			return

		crm_nodes = manager.get_crm_nodes()
		if crm_nodes == None :
			return
		
		have_quorum = False
		for attr_name in ["have-quorum", "have_quorum"] :
			attr_value = manager.xml_nodes["cib"].getAttribute(attr_name)
			if attr_value != "" :
				if attr_value in ["true", "yes", "1"] :
					have_quorum = True
				break
		if have_quorum :
			status = _("have quorum")
		else :
			status = _("no quorum")
		
		cluster_type = manager.get_cluster_type().capitalize()
		if len(cluster_type) > 0 :
			cluster_type += " & Pacemaker"
		else :
			cluster_type += "Pacemaker"

		#root = self.store.append(None, ["cluster", cluster_type, status, ""])
		
		if group_by_node :
			nodes_root = self.store.append(None, ["cluster", _("Cluster"), status, cluster_type])
			for node in nodes :
				self.add_node(nodes_root, node, node in active_nodes, node in crm_nodes)
			inactive_root = self.store.append(None, ["inactive resources", _("Inactive resources"), "", ""])
			rscs = manager.get_all_rsc()
			for rsc in rscs :
				rsc_type = manager.get_rsc_type(rsc)
				if rsc_type != "primitive" :
					continue
				nodes = manager.get_rsc_running_on(rsc)
				if nodes != None and len(nodes) > 0 :
					continue 
				else :
					(status, mig_threshold) = manager.get_rsc_status(rsc)
					info = self.get_rsc_info(rsc)
					self.store.append(inactive_root,[rsc_type, rsc, _(status), info])
		else :
			nodes_root = self.store.append(None, ["cluster", _("Cluster"), status, cluster_type])
			for node in nodes :
				self.add_node(nodes_root, node, node in active_nodes, node in crm_nodes, False)
			rscs_root = self.store.append(None, ["resources", _("Resources"), "", ""])
			rscs = manager.get_top_rsc()
			for rsc in rscs :
				self.add_rsc(rscs_root, rsc)
		
	def add_rsc(self, parent, rsc) :
		type = manager.get_rsc_type(rsc)
		status = ""
		label = ""
		if type == "primitive" :
			(status, mig_threshold) = manager.get_rsc_status(rsc)
			nodes = manager.get_rsc_running_on(rsc)
			info = self.get_rsc_info(rsc)
			if nodes != None and len(nodes)>0:
				self.store.append(parent,[type, rsc, _(status) + _(" on ")+str(nodes), info])
			else :
				self.store.append(parent,[type, rsc, _(status), info])
				
		elif type in ["group","clone","master"] :
			status = type
			iter = self.store.append(parent,[type, rsc, _(status), ""])
			for subrsc in manager.get_sub_rsc(rsc) :
				self.add_rsc(iter, subrsc)

	def get_rsc_info(self, rsc_id) :
		for lrm_rsc_node in manager.xml_nodes["cib"].getElementsByTagName("lrm_resource") :
			if lrm_rsc_node.getAttribute("id") == rsc_id :
				rsc_class = lrm_rsc_node.getAttribute("class")
				if rsc_class != "" :
					rsc_info = rsc_class + "::"
				else :
					rsc_info = ""

				rsc_provider = lrm_rsc_node.getAttribute("provider")
				if rsc_provider != "" :
					rsc_info += rsc_provider + ":"

				rsc_type = lrm_rsc_node.getAttribute("type")
				rsc_info += rsc_type
				return rsc_info
		return ""
					
	def add_node(self, nodes_root, node, active, started, add_rscs = True):
		status = _("unknown")
		if not started :
			node_type = manager.get_nodetype(node)
			if  node_type == "normal" :
				status = _("never started")
			elif node_type == "ping" :
				status = _("ping node")
			else :
				status = _("unknown type")
		else :
			node_status = manager.get_node_config(node)
			if node_status.get("online") == "True" :
				status = _("online")
			elif node_status.get("pending") == "True" :
				status = _("pending")
			else :
				status = _("offline")

			if node_status.get("unclean") == "True" :
				status += " (" + _("unclean") + ")"

			if node_status.get("is_dc") == "True" :
				status += " (" + _("dc") + ")"

			if node_status.get("standby_onfail") == "True" \
					and node_status.get("online") == "True" :
				status += " - " + _("standby") + " (" + _("on-fail") + ")"
			elif node_status.get("standby") == "True" :
				status += " - " + _("standby")

		node_iter = self.store.append(nodes_root,["node", node, status, ""])

		if add_rscs :
	 		running_rsc = manager.get_running_rsc(node)
 			for rsc in running_rsc :
 				self.add_rsc(node_iter, rsc)

class MainTree(ElementList) :
	def __init__(self) :
		obj_type = "cib"
		self.store = gtk.TreeStore(str, str)

		widget = gtk.TreeView(self.store)
		#widget.set_headers_visible(False)
		add_column(widget, None, 0, self.render_icon)
		title_label = gtk.Label()
		title_label.show()
		widget.get_column(0).set_widget(title_label)
		widget.set_size_request(180, 200)
		widget.connect("cursor-changed", self.on_cursor_changed, widget.get_selection())
		#widget.connect("event-after", self.on_right_click)
		self.tree = widget
		self.widget = widget
		self.title_label = title_label

	def on_cursor_changed(self, treeview, selection) :
		try :
			if not window.can_change_view() :
				if self.last_iter != None :
					selection.select_iter(self.last_iter)
					return
		except :
			pass

		(model, iter) = selection.get_selected()

		if window.cur_type != None and window.cur_view != None :
			window.view_status[window.cur_type] = window.cur_view.save_status()

		if iter == None :
			window.select_view(None, None, None)
			return
		#type = model.get_value(iter, 2)
		name = model.get_value(iter, 0)
		type = model.get_value(iter, 1)
		#status = model.get_value(iter, 1)
		window.select_view(type, name)
		self.last_iter = iter

	def render_icon(self, tvcolumn, cell, model, iter):
		name = model.get_value(iter, 1)
		stocks = {
				"cib":  gtk.STOCK_HARDDISK,
				"configuration": gtk.STOCK_HARDDISK,
				"status": gtk.STOCK_FIND,
				"crm_config": gtk.STOCK_PREFERENCES,
				"op_defaults": gtk.STOCK_PREFERENCES,
				"rsc_defaults": gtk.STOCK_PREFERENCES,
				"nodes": "nodes",
				"resources": gtk.STOCK_DIRECTORY,
				"constraints": gtk.STOCK_PROPERTIES,
				"acls": gtk.STOCK_DIALOG_AUTHENTICATION,
				"management" : gtk.STOCK_EXECUTE
			}
 		icons = {-2:gtk.STOCK_DIALOG_INFO,
			 -1:gtk.STOCK_PREFERENCES,
			  0:gtk.STOCK_YES,
			  1:gtk.STOCK_DIALOG_INFO,
			  2:gtk.STOCK_DIALOG_WARNING,
			  3:gtk.STOCK_DIALOG_ERROR}
		status = self.iter_status(model,iter)
		pb = self.widget.render_icon(stocks.get(name, gtk.STOCK_DIALOG_INFO),
			gtk.ICON_SIZE_BUTTON, None)
       		cell.set_property('pixbuf', pb)
		return

	def iter_status(self, model, iter) :
		return 0
		# -1:config 0: ok, 1: stopped, 2: umanaged, 3:failed, 4:stop failed
		type = model.get_value(iter, 2)
		status = model.get_value(iter, 1)
		iter_status = 0
		if type == _("primitive") :
			if string.find(status, _("not running")) != -1 :
				iter_status = 1
			elif string.find(status, _("running")) != -1 :
				iter_status = 0
			elif string.find(status, _("fail")) != -1 :
				iter_status = 3
			else :
				iter_status = 2
		
		elif type == "node" :
			if status == _("ping node") :
				iter_status = -1				
			elif string.find(status, _("running")) != -1 :
				iter_status = 0
			else :
				iter_status = 1
		elif type in [_("group"),_("resources"),_("clone"),_("master")]:
			iter_status = 0
		elif type in [_("orders"),_("locations"), _("colocations")] :
			iter_status = -1
		else :
			iter_status = -2
		if model.iter_has_child(iter) :
			for i in range(0, model.iter_n_children(iter)) :
				child = model.iter_nth_child(iter,i)
				child_status = self.iter_status(model, child)
				if child_status > iter_status :
					iter_status = child_status
		
		return iter_status
		
	def update(self) :
		tree_status = self.save_tree_status()

		self.title_label.set_text("")
		self.store.clear()
		if not manager.connected :
			window.select_view(None, None, None)
			return

		if manager.active_cib == "" :
			title_str = _("Live")
		else :
			title_str = _("Shadow: ") + manager.active_cib

		self.title_label.set_markup('<b>'+title_str+'</b>')

		treeiter = {}
		if validate_type == "dtd" :
			self.dtd_elem = manager.get_dtd_elem("cib")
			for (name, mod) in self.dtd_elem.get_content_model()[1] :
				if mod == '' :
					if mode_level != 2 and name == "status" :
						continue
					treeiter[name] = self.store.append(None, [_(name_cap(name)), name])
					sub_dtd_elem = manager.get_dtd_elem(name)
					for (sub_name, sub_mod) in sub_dtd_elem.get_content_model()[1] :
						if sub_mod == '' :
							treeiter[sub_name] =  \
								self.store.append(treeiter[name], [_(name_cap(sub_name)), sub_name])
		else :
			sorted_rng_nodes = manager.sorted_sub_rng_nodes_by_name("cib")
			for rng_node in sorted_rng_nodes.get("element", []) :
					name = rng_node[0][1].getAttribute("name")
					if mode_level != 2 and name == "status" :
						continue
					treeiter[name] = self.store.append(None, [_(name_cap(name)), name])
					sub_rng_nodes = manager.sorted_sub_rng_nodes_by_node(*rng_node[0])
					for sub_rng_node in sub_rng_nodes.get("element", []) :
						if manager.find_decl(sub_rng_node, "zeroOrMore") != 0 :
							continue
						sub_name = sub_rng_node[0][1].getAttribute("name")
						treeiter[sub_name] =  \
							self.store.append(treeiter[name], [_(name_cap(sub_name)), sub_name])
					

			#(u',', [(u'configuration', ''), (u'status', '')], '')
		if manager.active_cib == "" :
			treeiter["management"] = self.store.append(None, [_("Management"), "management"])

		self.treeiter = treeiter

		self.restore_tree_status(tree_status)
		(type, id, path, expand_status) = tree_status
		if expand_status == {} :
			self.widget.expand_all()

		selection = self.widget.get_selection()
		(model, iter) = selection.get_selected()
		if iter != None and window.cur_view != None and window.cur_type.count("crm_config") == 0 :
			cur_xml_nodes = manager.xml_nodes["cib"].getElementsByTagName(window.cur_type)
			if len(cur_xml_nodes) > 0 :
				cur_xml_node = cur_xml_nodes[0] 
			else :
				cur_xml_node = window.cur_type
			window.cur_view.update(cur_xml_node)
		else :
			if iter == None :
				if manager.active_cib == "" :
					selection.select_iter(self.treeiter["management"])
				else :
					selection.select_path("0")
			self.on_cursor_changed(self.widget, self.widget.get_selection())
	
class ClusterView :
	def update(self, xml_node = None) :
		self.cluster_info_labels = None
		self.cib_attrs_labels = None
		for line in self.cluster_info_vbox.get_children() :
			self.cluster_info_vbox.remove(line)
		for line in self.cib_attrs_vbox.get_children() :
			self.cib_attrs_vbox.remove(line)

		self.widget.show_all()

		config = manager.get_cluster_config()
		if config == None or len(config) == 0 :
			self.widget.get_nth_page(0).hide_all()
		else :	
			cluster_info_labels= {}
			for key in config.keys():
				if config.get(key, "") == "" :
					continue
				cluster_info_labels[key] = self.add_line(self.cluster_info_vbox, config.get(key,""))
			self.cluster_info_labels = cluster_info_labels
			self.widget.get_nth_page(0).show_all()

		xml_node = manager.xml_nodes.get("cib")
		if xml_node == None :
			self.widget.get_nth_page(1).hide_all()
		else :
			obj_type = xml_node.tagName
			if validate_type == "dtd" :
				dtd_elem = manager.get_dtd_elem(obj_type)
				attr_names = dtd_elem.get_attr_list()
			else :
				sorted_rng_nodes = manager.sorted_sub_rng_nodes_by_name("cib")
				attr_node_list = sorted_rng_nodes.get("attribute", [])
				attr_names = [attr_node[0][1].getAttribute("name") for attr_node in attr_node_list]

			cib_attrs_labels = {}
			for attr_name in attr_names :
				attr_value = xml_node.getAttribute(attr_name)
				if attr_value == "" :
					continue
				cib_attrs_labels[attr_name] = self.add_line(self.cib_attrs_vbox, attr_value)
			self.cib_attrs_labels = cib_attrs_labels
			self.widget.get_nth_page(1).show_all()

		self.on_after_show()

	def add_line(self, vbox, value) :
		hbox = gtk.HBox()
		name_label = gtk.Label()
		name_label.set_alignment(0, 0.5)
		name_label.set_selectable(True)
		eventbox = gtk.EventBox()
		eventbox.add(name_label)

		value_label = gtk.Label(value)
		value_label.set_alignment(0, 0.5)
		value_label.set_selectable(True)

		hbox.pack_start(eventbox, False, padding=5)
		hbox.pack_start(value_label, False, padding=5)
		vbox.pack_start(hbox, False, padding=2)

		return name_label

	def on_after_show(self) :
		info_dict =	{
				"quorum_server":	"Quorum Server",
				"use_logd":		"Use Logd",
				"autojoin":		"Auto Join",
				"apiauth":		"API Authentication",
				"auto_failback":	"Auto Failback",
				"baud":			"Baud Rate",
				"debug":		"Debug Level",
				"debugfile":		"Debug File",
				"deadping":		"Dead Ping",
				"deadtime":		"Dead Time",
				"hbversion":		"Heartbeat Version",
				"hopfudge":		"Hop Fudge",
				"initdead":		"Initial Dead Time",
				"keepalive":		"Keep Alive",
				"logfacility":		"Log Facility",
				"logfile":		"Log File",
				"msgfmt":		"Message Format",
				"nice_failback":	"Nice Failback",
				"node":			"Node",
				"normalpoll":		"Normal Poll",
				"stonith":		"Stonith",
				"udpport":		"UDP Port",
				"warntime":		"Warning Time",
				"watchdog":		"Watchdog",
				"cluster":		"Cluster"
				}


		if self.cluster_info_labels != None :
			cluster_type = manager.get_cluster_type()
			if cluster_type == "openais" :
				target_site = "www.openais.org"
			elif cluster_type == "heartbeat" :
				target_site = "www.linux-ha.org"
			else :
				target_site = "www.clusterlabs.org"

			name_label_max_len = 0
			for key in self.cluster_info_labels.keys() :
				make_label_active(self.cluster_info_labels[key], _(info_dict.get(key, key))+_(":"), target_site)
				name_label_len = self.cluster_info_labels[key].size_request()[0]
				if name_label_len >  name_label_max_len :
					name_label_max_len = name_label_len

			for name_label in self.cluster_info_labels.values() :
				name_label.set_size_request(name_label_max_len, -1)

		if self.cib_attrs_labels != None :
			target_site = "www.clusterlabs.org"
			name_label_max_len = 0
			for key in self.cib_attrs_labels.keys() :
				make_label_active(self.cib_attrs_labels[key], _(name_cap(key)+":"), target_site)
				name_label_len = self.cib_attrs_labels[key].size_request()[0]
				if name_label_len >  name_label_max_len :
					name_label_max_len = name_label_len

			for name_label in self.cib_attrs_labels.values() :
				name_label.set_size_request(name_label_max_len, -1)
			
	def __init__(self) :
		notebook =  gtk.Notebook()
		self.notebook = notebook
		self.widget = notebook

		cluster_info_vbox = gtk.VBox()
		cluster_info_vbox.set_border_width(5)
		tab_label = gtk.Label(_("Cluster"))
		notebook.append_page(cluster_info_vbox, tab_label)
		self.cluster_info_vbox = cluster_info_vbox

		cib_vbox = gtk.VBox()
		cib_vbox.set_border_width(5)
		tab_label = gtk.Label(_("CIB"))
		notebook.append_page(cib_vbox, tab_label)

		cib_attrs_vbox = gtk.VBox()
		cib_vbox.pack_start(cib_attrs_vbox)
		self.cib_attrs_vbox = cib_attrs_vbox

		bbox = gtk.HButtonBox()
		bbox.set_layout(gtk.BUTTONBOX_END)
		bbox.set_spacing(5)
		xml_btn = gtk.Button(_("View XML"))
		bbox.add(xml_btn)
		cib_vbox.pack_start(bbox, False)

		xml_menu = gtk.Menu()
		for obj_type in ["cib", "configuration"] :
			if obj_type == "cib" :
				label_text = _("The Whole CIB")
			elif obj_type == "configuration" :
				label_text = _("The Configuration Section")
			xml_menu_item = gtk.MenuItem(label_text)
			xml_menu.append(xml_menu_item)
			xml_menu_item.connect("activate", self.edit_xml, obj_type)

		xml_menu.show_all()
		xml_btn.connect_object("event", self.popup_menu, xml_menu)

		self.update()

	def popup_menu(self, menu, event) :
		if event.type == gtk.gdk.BUTTON_PRESS :
			menu.popup(None, None, None, event.button, event.time)
			return True
		elif event.type == gtk.gdk.KEY_PRESS and event.keyval == gtk.keysyms.Return :
			menu.popup(None, None, None, event.keyval, event.time)
			return True
		return False

	def edit_xml(self, widget, obj_type) :
		init_cib_xml_node = manager.xml_nodes["cib"]

		if obj_type == "cib" :
			xml_node = init_cib_xml_node
		else :
			xml_nodes = init_cib_xml_node.getElementsByTagName(obj_type)
			if len(xml_nodes) < 1 :
				msgbox(_("The object \"%s\" doesn't exist")%obj_type)
				return
			xml_node = xml_nodes[0]

		orig_xml_node = xml_node.cloneNode(True)
		replace_xml_node = xml_node
		xml_dlg = EditXMLDlg(xml_node)
		while True :
			new_xml_node = xml_dlg.run()
			if new_xml_node == None :
				if obj_type != "cib" :
					replace_xml_node.parentNode.replaceChild(orig_xml_node, replace_xml_node)
				self.update()
				break

			if obj_type == "cib" :
				init_cib_xml_node = new_xml_node
			else :
				replace_xml_node.parentNode.replaceChild(new_xml_node, replace_xml_node)
				replace_xml_node = new_xml_node

			xml_str = new_xml_node.toxml().replace("\n", "")
			if not manager.validate_cib(init_cib_xml_node) :
				continue
			manager.cib_do_cmd("cib_replace\n%s\n%s"%(str(xml_node.tagName), str(xml_str)))
			if manager.failed_reason != "" :
				msgbox(manager.failed_reason)
			else :
				if obj_type == "cib" :
					manager.set_update()
				else :
					self.update()
				xml_dlg.destroy()
				break

	def save_status(self) :
		page_num = self.notebook.get_current_page()
		if page_num < 0 :
			return None
		else :
			return (page_num,)

	def restore_status(self, view_status) :
		if view_status == None :
			return
		(page_num,) = view_status
		self.notebook.set_current_page(page_num)

class View :
	changed = False
	
	def __init__(self, param=None) :

		bbox = gtk.HButtonBox()
		bbox.set_layout(gtk.BUTTONBOX_END)
		bbox.set_spacing(5)
		default_btn = gtk.Button(_("Default"))
		bbox.add(default_btn)
		reset_btn = gtk.Button(_("Reset"))
		bbox.add(reset_btn)
		apply_btn = gtk.Button(stock=gtk.STOCK_APPLY)
		bbox.add(apply_btn)
		self.bbox = bbox

		self.default_btn_handler = default_btn.connect("clicked", self.on_default)
		self.reset_btn_handler = reset_btn.connect("clicked", self.on_reset)
		self.apply_btn_handler = apply_btn.connect("clicked", self.on_apply)

		self.default_btn = default_btn
		self.reset_btn = reset_btn
		self.apply_btn = apply_btn

		self.widget.pack_start(self.bbox, False, padding = 2)

	def update(self) :
		self.apply_btn.set_property("sensitive", False)
		self.reset_btn.set_property("sensitive", False)
		self.changed = False
	
	def on_changed(self, widget) :
		self.apply_btn.set_property("sensitive", True)
		self.reset_btn.set_property("sensitive", True)
		self.changed = True
	
	def on_reset(self, widget):
		self.update()
		
	def on_apply(self, widget):
		self.apply_btn.set_property("sensitive", False)
		self.reset_btn.set_property("sensitive", False)
		self.changed = False

	def on_default(self, widget):
		self.on_changed(widget)
		
	def on_after_show(self) :
		pass	

class CRMConfigView(View) :
	pengine_metadata = None
	crmd_metadata = None
	pengine_widgetgroup = None
	crmd_widgetgroup = None
	
	def on_apply(self, widget):
		current_page = self.notebook.get_current_page()
		if current_page == 0 :
			(widgetgroup, metadata) = (self.pengine_widgetgroup, self.pengine_metadata)
		else :
			(widgetgroup, metadata) = (self.crmd_widgetgroup, self.crmd_metadata)

		new_crm_config = widgetgroup.get_values()
		self.update_crm_config(metadata, new_crm_config)

		self.update()
		View.on_apply(self, widget)

	def on_default(self, widget):
		current_page = self.notebook.get_current_page()
		if current_page == 0 :
			(widgetgroup, metadata) = (self.pengine_widgetgroup, self.pengine_metadata)
		else :
			(widgetgroup, metadata) = (self.crmd_widgetgroup, self.crmd_metadata)

		default_crm_config = {}
		for parameter in metadata.parameters:
			default_crm_config[parameter["name"]] = str(parameter["content"]["default"])

		if default_crm_config != {}:
			widgetgroup.show_values(default_crm_config)

		View.on_default(self, widget)
	
	def update(self, xml_node = None) :
		for (widgetgroup, metadata) in ((self.pengine_widgetgroup, self.pengine_metadata),
						(self.crmd_widgetgroup, self.crmd_metadata)):
			if metadata != None and widgetgroup != None:
				crm_config = self.get_crm_config(metadata)
				if crm_config != None :
					widgetgroup.show_values(crm_config)
				else :
					return False

		View.update(self)
		self.on_after_show()
		return True

	def get_crm_config(self, metadata) :
		global mode_level
		config = {}
		for parameter in metadata.parameters :
			config[parameter["name"]] = str(parameter["content"]["default"])

		cluster_property_sets = manager.xml_nodes["cib"].getElementsByTagName("cluster_property_set")
		if len(cluster_property_sets) == 0 :
			return config
		elif len(cluster_property_sets) == 1 :
			for nvpair in cluster_property_sets[0].getElementsByTagName("nvpair") :
				name = nvpair.getAttribute("name")
				value = nvpair.getAttribute("value")
				if value != "" :
					config[nvpair.getAttribute("name")] = nvpair.getAttribute("value")
			return config
		else :
			mode_level = 2
			window.radio_tool_action_group.get_action("hack-mode").set_active(True)
			msgbox(_("Multiple \"Cluster Property Set\" in \"CRM Config\".") + "\n"
					+ _("We are switching to \"Hack Mode\" to view them properly."))
			return None

	def update_crm_config(self, metadata, new_crm_config) :
		crm_config_xml_nodes = manager.xml_nodes["cib"].getElementsByTagName("crm_config")
		if len(crm_config_xml_nodes) < 1 :
			msgbox(_("Cannot update the crm configuration: No \"crm_config\" in CIB"))
			return

		(parent_xml_node, add_obj_type, new_mid_elem) = \
				manager.real_add_obj_type(crm_config_xml_nodes[0], "cluster_property_set")

		if parent_xml_node == None :
			msgbox(_("Cannot update the crm configuration"))
			return

		nv_xml_nodes = {}
		for nv_xml_node in parent_xml_node.getElementsByTagName("nvpair") :
			nv_name = nv_xml_node.getAttribute("name")
			nv_xml_nodes[nv_name] = nv_xml_node

		default_crm_config = {}
		for parameter in metadata.parameters :
			default_crm_config[parameter["name"]] = str(parameter["content"]["default"])
			if parameter["content"]["type"] == "integer" :
				try :
					default_value = float(parameter["content"]["default"])
					if default_value == float("inf") :
						default_crm_config[parameter["name"]] = "1000000"
					elif default_value == float("-inf") :
						default_crm_config[parameter["name"]] = "-1000000"
				except :
					pass

		impl = getDOMImplementation()
		for attr_name, value in new_crm_config.iteritems() :
			nv_xml_node = nv_xml_nodes.get(attr_name)

			if nv_xml_node != None :
				if value != default_crm_config.get(attr_name) :
					nv_xml_node.setAttribute("value", value)
				else :
					nv_xml_node.parentNode.removeChild(nv_xml_node)
			else :
				if value != default_crm_config.get(attr_name) :
					newdoc = impl.createDocument(None, "nvpair", None)
					nv = newdoc.documentElement
					parent_xml_node.appendChild(nv)

					attr_id = manager.auto_unique_id(nv, attr_name)
					nv.setAttribute("id", attr_id)
					nv.setAttribute("name", attr_name)
					nv.setAttribute("value", value)

		xml_str = parent_xml_node.toxml().replace("\n", "")
		if new_mid_elem == None :
			manager.cib_do_cmd("cib_replace\ncrm_config\n%s"%(str(xml_str)))
		else :
			manager.cib_do_cmd("cib_create\ncrm_config\n%s"%(str(xml_str)))
			
		if manager.failed_reason != "" :
			msgbox(manager.failed_reason)

	def on_after_show(self) :
		target_site = "www.clusterlabs.org"
		for widgets in (self.pengine_widgetgroup.widgets, self.crmd_widgetgroup.widgets):
			if widgets != None:
				name_label_max_len = 0
				for key in widgets["name_labels"].keys():
					make_label_active(widgets["name_labels"][key], name_cap(key)+":", target_site)
					name_label_len = widgets["name_labels"][key].size_request()[0]
					if name_label_len >  name_label_max_len :
						name_label_max_len = name_label_len

				for name_label in widgets["name_labels"].values() :
					name_label.set_size_request(name_label_max_len, -1)
							
	def on_notebook_event(self, widget, page, page_num) :
		global last_cluster_view_page_num

		if self.changed == True:
			ret = confirmbox(_("There are unsaved changes in current page.")+"\n"+_("Apply the changes?"),
					(gtk.STOCK_NO, gtk.RESPONSE_NO, 
					gtk.STOCK_YES, gtk.RESPONSE_YES))
			if ret == gtk.RESPONSE_YES :
				self.on_apply(widget)
			else :
				self.update()

	def __init__(self) :
		vbox = gtk.VBox()
		self.widget = vbox

		notebook = gtk.Notebook()
		self.notebook = notebook
		vbox.pack_start(notebook)

		pe_vbox = gtk.VBox()
		pe_vbox.set_border_width(5)
		tab_label = gtk.Label(_("Policy Engine"))

		sw = gtk.ScrolledWindow()
		sw.set_shadow_type(gtk.SHADOW_NONE)
		sw.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
		sw.add_with_viewport(pe_vbox)
		sw.child.set_shadow_type(gtk.SHADOW_NONE)
		notebook.append_page(sw, tab_label)
		self.pe_vbox = pe_vbox

		crmd_vbox = gtk.VBox()
		crmd_vbox.set_border_width(5)
		tab_label = gtk.Label(_("CRM Daemon"))

		sw = gtk.ScrolledWindow()
		sw.set_shadow_type(gtk.SHADOW_NONE)
		sw.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
		sw.add_with_viewport(crmd_vbox)
		sw.child.set_shadow_type(gtk.SHADOW_NONE)
		notebook.append_page(sw, tab_label)
		self.crmd_vbox = crmd_vbox

		self.pengine_metadata = manager.get_crm_metadata("pengine")
		self.crmd_metadata = manager.get_crm_metadata("crmd")

		if self.pengine_metadata != None:
			pengine_widgets = self.render_crmconf_widgets(self.pengine_metadata)
			self.pengine_widgetgroup = WidgetGroup(pengine_widgets)
		if self.crmd_metadata != None:
			crmd_widgets = self.render_crmconf_widgets(self.crmd_metadata)
			self.crmd_widgetgroup = WidgetGroup(crmd_widgets)

		notebook.connect("switch-page", self.on_notebook_event)

		View.__init__(self)

		self.widget.show_all()
		#self.update()

	def render_crmconf_widgets(self, metadata):
		if metadata.name == "Policy Engine":
			vbox = self.pe_vbox
		elif metadata.name == "CRM Daemon":
			vbox = self.crmd_vbox

		widgets = {}
		name_labels = {}
		combos = {}
		combo_entries = {}
		checkbuttons = {}
		spinbuttons = {}
		entries = {}
		parameters = metadata.parameters

		for row in range(len(parameters)):
			param_name = parameters[row]["name"]
			param_type =  parameters[row]["content"]["type"]
			param_default =  parameters[row]["content"]["default"]

			hbox = gtk.HBox()
			label = gtk.Label(param_name + ":")
			label.set_alignment(0, 0.5)
			eventbox = gtk.EventBox()
			eventbox.add(label)
			hbox.pack_start(eventbox, False, padding=5)
			name_labels[param_name] = label

			longdesc = parameters[row].get("longdesc")
			shortdesc = parameters[row].get("shortdesc")
			if len(longdesc) == 0 :
				tip = shortdesc
			elif longdesc.find(shortdesc) > -1 :
				tip = longdesc
			else :
				if shortdesc.endswith(_(".")) :
					tip = shortdesc + "\n" + longdesc
				else :
					tip = shortdesc + _(".") + "\n" + longdesc

			if param_default != "" :
				default_str =  _("Default") + _(": ") + param_default
				if len(tip) > 0 :
					tip += "\n\n" + default_str
				else :
					tip = default_str 
				

			if pygtk_newer(2, 12) :
				label.set_tooltip_text(tip)
			else :
				tooltips = gtk.Tooltips()
				tooltips.set_tip(label, tip)

			if param_type == "enum" and parameters[row]["content"].has_key("values"):
				store = gtk.ListStore(str, str)
				for option in parameters[row]["content"]["values"]:
					if param_default != None and option == param_default :
						store.insert(0, [option, "[ "+ _("default") + " ]"])
					else :
						store.append([option, ""])
					
				combo = gtk.ComboBox(store)
				cell0 = gtk.CellRendererText()
				cell1 = gtk.CellRendererText()
				combo.pack_start(cell0, True)
				combo.pack_start(cell1, True)
				combo.add_attribute(cell0, 'text', 0)
				combo.add_attribute(cell1, 'text', 1)

				combo.connect("changed", self.on_changed)
				hbox.pack_start(combo, False, padding=3)
				combos[param_name] = combo
			elif param_type == "boolean":
				checkbutton = gtk.CheckButton()
				checkbutton.connect("toggled", self.on_changed)
				hbox.pack_start(checkbutton, False)
				checkbuttons[param_name] = checkbutton
			elif param_type == "integer" and param_name.count("time") == 0 :
				try :
					default_value = float(param_default)
				except :
					default_value = float(extract_int(param_default))
					if default_value == None :
						default_value = 0

				if default_value == float("inf") :
					default_value = 1000000
				elif default_value == float("-inf") :
					default_value = -1000000

				if param_name.count("node-health") or param_name.count("stickiness") :
					min_value = -1000000
					page_incr = 100
				elif default_value < 0 :
					min_value = default_value
					page_incr = 100
				else :
					min_value = 0
					page_incr = 10
				
				adj = gtk.Adjustment(default_value, min_value, 1000000, 1, page_incr)
				spinbutton = gtk.SpinButton(adj, 0, 0)
				#spinbutton.set_width_chars(7)
				spinbutton.set_wrap(True)

				spinbutton.connect("changed", self.on_changed)
				hbox.pack_start(spinbutton, False, padding=3)
				spinbuttons[param_name] = spinbutton
			elif param_default != "" or  parameters[row]["content"].has_key("values") :
				store = gtk.ListStore(str, str)

				if parameters[row]["content"].has_key("values") :
					for option in parameters[row]["content"]["values"] :
						if param_default != None and option == param_default :
							store.insert(0, [option, "[ "+ _("default") + " ]"])
						else :
							store.append([option, ""])
				else :
					store.insert(0, [param_default, "[ "+ _("default") + " ]"])
					
				combo_entry = gtk.ComboBoxEntry(store)
				cell = gtk.CellRendererText()
				combo_entry.pack_start(cell, True)
				combo_entry.add_attribute(cell, 'text', 1)

				combo_entry.connect("changed", self.on_changed)
				combo_entry.child.connect("activate", self.on_apply)
				hbox.pack_start(combo_entry, False, padding=3)
				combo_entries[param_name] = combo_entry

			else:
				entry = gtk.Entry()
				entry.connect("changed", self.on_changed)
				entry.connect("activate", self.on_apply)
				hbox.pack_start(entry, False, padding=3)
				entries[param_name] = entry 

			vbox.pack_start(hbox, False, padding=1)
	
		vbox.show_all()

		widgets["name_labels"] = name_labels
		widgets["combos"] = combos
		widgets["combo_entries"] = combo_entries
		widgets["checkbuttons"] = checkbuttons
		widgets["spinbuttons"] = spinbuttons
		widgets["entries"] = entries
	
		return widgets

	def save_status(self) :
		page_num = self.notebook.get_current_page()
		if page_num < 0 :
			return None
		else :
			return (page_num,)

	def restore_status(self, view_status) :
		if view_status == None :
			return
		(page_num,) = view_status
		self.notebook.set_current_page(page_num)

class ObjectView :
	obj_attrs = None
	elem_notebook = None
	
	def __init__(self, xml_node, is_newobj = False, change_call_back = None, is_topview = False,
			missing_opt_obj_parent_type = None, show_mode = 0) :
		self.is_newobj = is_newobj
		self.change_call_back = change_call_back
		self.is_topview = is_topview
		self.missing_opt_obj_parent_type = missing_opt_obj_parent_type
		self.show_mode = show_mode
		vbox = gtk.VBox()
		self.vbox = vbox
		self.widget = vbox

		self.mode_combobox = gtk.combo_box_new_text()
		self.mode_combobox.append_text(_("List Mode"))
		self.mode_combobox.append_text(_("Tree Mode"))
		self.mode_combobox.append_text(_("XML Mode"))
		self.mode_combobox.set_active(self.show_mode)
		self.mode_combobox.connect("changed", self.on_changed)

		self.hbox = gtk.HBox()
		self.hbox.pack_end(self.mode_combobox, False)

		self.label = gtk.Label(_("Show") + _(": "))
		self.hbox.pack_end(self.label, False)

		self.vbox.pack_start(self.hbox, False, padding=2)

		self.update(xml_node)

	def update(self, xml_node = None) :
		is_newobj = self.is_newobj
		if type(xml_node) == str:
			impl = getDOMImplementation()
			newdoc = impl.createDocument(None, xml_node, None)
			self.xml_node = newdoc.documentElement
			self.init_xml_node = self.xml_node.cloneNode(True)
			self.is_fake_xml_node = True
		elif xml_node != None :
			self.xml_node = xml_node
			self.init_xml_node = self.xml_node.cloneNode(True)
			self.is_fake_xml_node = False

		objview_status = self.save_status()

		for child in self.vbox.get_children() :
			if child != self.hbox :
				self.vbox.remove(child)

		obj_type = self.xml_node.tagName
		attr_is_any_name = False
		elem_is_any_name = False
		if validate_type == "dtd" :
			self.dtd_elem = manager.get_dtd_elem(obj_type)
			attr_list = self.dtd_elem.get_attr_list()
			sub_obj_list = self.dtd_elem.get_content_model()[1]
		else :
			sorted_rng_nodes = manager.sorted_sub_rng_nodes_by_name(obj_type)
			attr_list = []
			sub_obj_list = []
			if sorted_rng_nodes != None :
				attr_rng_nodes = sorted_rng_nodes.get("attribute", [])
				elem_rng_nodes = sorted_rng_nodes.get("element", [])
				for rng_node in attr_rng_nodes :
					name = rng_node[0][1].getAttribute("name")
					if name == "" :
						attr_is_any_name = True
					elif attr_list.count(name) == 0 :
						attr_list.append(name)

				for rng_node in elem_rng_nodes :
					name = rng_node[0][1].getAttribute("name")
					if name == "" :
						elem_is_any_name = True
					else :
						sub_obj_list.append(name)
			else :
				attr_is_any_name = True
				elem_is_any_name = True

		if attr_is_any_name :
			for attr_name in  self.xml_node.attributes.keys() :
				if attr_list.count(attr_name) == 0 :
					attr_list.append(attr_name)

		if elem_is_any_name :
			for elem_node in self.xml_node.childNodes :
				if elem_node.nodeType != xml.dom.Node.ELEMENT_NODE :
					continue
				elem_name = elem_node.tagName
				if sub_obj_list.count(elem_name) == 0 :
					sub_obj_list.append(elem_name)

		if not self.is_topview and (len(attr_list) >0 or attr_is_any_name) :
			has_attr = True
		else :
			has_attr = False

		if len(sub_obj_list) or elem_is_any_name > 0 :
			has_elem = True
		else :
			has_elem = False

		if len(attr_list) > 4 :
			obj_box = gtk.HBox()
			self.vbox.pack_start(obj_box)
		else :
			obj_box = self.vbox

		if has_attr :
			if obj_type in ["primitive", "template"] :
				obj_attrs = Primitive(self.xml_node, is_newobj, self.change_call_back)
			elif obj_type == "rsc_order" :
				obj_attrs = RscOrder(self.xml_node, is_newobj, self.change_call_back)
			elif obj_type == "rsc_colocation" :
				obj_attrs = RscColocation(self.xml_node, is_newobj, self.change_call_back)
			elif obj_type == "nvpair" :
				if validate_type == "dtd" :
					if self.xml_node.parentNode.parentNode.tagName == "instance_attributes" and \
							self.xml_node.parentNode.parentNode.parentNode.tagName in ["primitive", "template"] :
						obj_attrs = PrimInstAttrsNV(self.xml_node, is_newobj, self.change_call_back)
					elif self.xml_node.parentNode.parentNode.tagName == "instance_attributes" and \
							self.xml_node.parentNode.parentNode.parentNode.tagName == "op" :
						obj_attrs = OPInstAttrsNV(self.xml_node, is_newobj, self.change_call_back)
					elif self.xml_node.parentNode.parentNode.tagName == "instance_attributes" and \
							self.xml_node.parentNode.parentNode.parentNode.tagName == "node" :
						obj_attrs = InstAttrsNV(self.xml_node, is_newobj, self.change_call_back)
					elif self.xml_node.parentNode.parentNode.tagName == "meta_attributes" :
						obj_attrs = MetaAttrsNV(self.xml_node, is_newobj, self.change_call_back)
					elif self.xml_node.parentNode.parentNode.tagName == "cluster_property_set" :
						obj_attrs = CRMConfNV(self.xml_node, is_newobj, self.change_call_back)
					elif self.xml_node.parentNode.parentNode.tagName == "utilization" :
						obj_attrs = UtilizationNV(self.xml_node, is_newobj, self.change_call_back)
					else :
						obj_attrs = ObjectAttrs(self.xml_node, is_newobj, self.change_call_back)
				else :
					if self.xml_node.parentNode.tagName == "instance_attributes" and \
							self.xml_node.parentNode.parentNode.tagName in ["primitive", "template"]:
						obj_attrs = PrimInstAttrsNV(self.xml_node, is_newobj, self.change_call_back)
					elif self.xml_node.parentNode.tagName == "instance_attributes" and \
							self.xml_node.parentNode.parentNode.tagName == "op" :
						obj_attrs = OPInstAttrsNV(self.xml_node, is_newobj, self.change_call_back)
					elif self.xml_node.parentNode.tagName == "instance_attributes" and \
							self.xml_node.parentNode.parentNode.tagName == "node" :
						obj_attrs = InstAttrsNV(self.xml_node, is_newobj, self.change_call_back)
					elif self.xml_node.parentNode.tagName == "meta_attributes" :
						if self.xml_node.parentNode.parentNode.tagName == "op_defaults" :
							obj_attrs = OPDefaultsNV(self.xml_node, is_newobj, self.change_call_back)
						else :
							obj_attrs = MetaAttrsNV(self.xml_node, is_newobj, self.change_call_back)
					elif self.xml_node.parentNode.tagName == "cluster_property_set" :
						obj_attrs = CRMConfNV(self.xml_node, is_newobj, self.change_call_back)
					elif self.xml_node.parentNode.tagName == "utilization" :
						obj_attrs = UtilizationNV(self.xml_node, is_newobj, self.change_call_back)
					else :
						obj_attrs = ObjectAttrs(self.xml_node, is_newobj, self.change_call_back)

			elif obj_type == "expression" :
				obj_attrs = Expression(self.xml_node, is_newobj, self.change_call_back)
			elif obj_type == "op" :
				obj_attrs = OP(self.xml_node, is_newobj, self.change_call_back)
			else :
				obj_attrs = ObjectAttrs(self.xml_node, is_newobj, self.change_call_back)

			obj_attrs.dynamic_choice_elem()
			obj_attrs.update()

			obj_box.pack_start(obj_attrs.attrs_vbox)
			self.obj_attrs = obj_attrs
			
		if has_elem :
			if obj_type in ["acl_user", "acl_role"] :
				single_page = True
			else :
				single_page = False

			self.elem_notebook = ElementNotebook(self.xml_node, self.is_topview, self.elem_change_call_back,
						self.show_mode, self.is_fake_xml_node, self.missing_opt_obj_parent_type, single_page)
			if self.elem_notebook.update(self.xml_node) :
				obj_box.pack_start(self.elem_notebook.widget, True, padding = 5)
				self.vbox.pack_start(self.elem_notebook.bbox, False, padding = 2)
			else :
				#if not self.is_topview :
				#	self.update()
				self.update()
				return

		self.restore_status(objview_status)

		self.vbox.show_all()
		self.on_after_show()

		if not has_elem :
			self.label.hide_all()
			self.mode_combobox.hide_all()

	def elem_change_call_back(self) :
		if self.obj_attrs != None :
			self.obj_attrs.dynamic_choice_elem()

		if self.change_call_back != None :
			self.change_call_back()

	def save_status(self) :
		attrs_status = None
		if self.obj_attrs != None :
			attrs_status = self.obj_attrs.save_status()

		notebook_status = None
		if self.elem_notebook != None :
			notebook_status = self.elem_notebook.save_status()
		return (self.show_mode, attrs_status, notebook_status)

	def restore_status(self, objview_status) :
		#if objview_status == None :
		#	return
		(show_mode, attrs_status, notebook_status) = objview_status
		if self.obj_attrs != None and attrs_status != None :
			self.obj_attrs.restore_status(attrs_status)
		if self.elem_notebook != None and notebook_status != None :
			self.elem_notebook.restore_status(notebook_status)

	def on_after_show(self) :
		if self.obj_attrs != None :
			self.obj_attrs.on_after_show()
		if self.elem_notebook != None :
			self.elem_notebook.on_after_show()

	def on_changed(self, widget) :
		show_mode = self.mode_combobox.get_active()
		if show_mode != 2 :
			self.show_mode = show_mode
			self.update()
			return

		self.edit_xml()
		self.mode_combobox.set_active(self.show_mode)

	def edit_xml(self) :
		init_cib_xml_node = manager.xml_nodes["cib"]
		orig_xml_node = self.xml_node.cloneNode(True)
		replace_xml_node = self.xml_node
		xml_dlg = EditXMLDlg(self.xml_node)
		while True :
			new_xml_node = xml_dlg.run()
			if new_xml_node == None :
				replace_xml_node.parentNode.replaceChild(orig_xml_node, replace_xml_node)
				self.xml_node = orig_xml_node
				self.update()
				break
			replace_xml_node.parentNode.replaceChild(new_xml_node, replace_xml_node)
			replace_xml_node = new_xml_node
			if not self.is_topview :
				xml_dlg.destroy()
				#self.xml_node.parentNode.replaceChild(new_xml_node, self.xml_node)
				self.xml_node = new_xml_node
				self.update()
				if self.change_call_back != None :
					self.change_call_back()
				break
			else :
				xml_str = new_xml_node.toxml().replace("\n", "")
				if self.is_fake_xml_node :
					manager.cib_do_cmd("cib_create\n%s\n%s"
							%(str(self.missing_opt_obj_parent_type), str(xml_str)))
					if manager.failed_reason != "" :
						msgbox(manager.failed_reason)
					else :
						if manager.active_cib != "" :
							manager.set_update()
						xml_dlg.destroy()
						break
				else :
					if not manager.validate_cib(init_cib_xml_node) :
						continue
					manager.cib_do_cmd("cib_replace\n%s\n%s"%(str(self.xml_node.tagName), str(xml_str)))
					if manager.failed_reason != "" :
						msgbox(manager.failed_reason)
					else :
						#self.xml_node.parentNode.replaceChild(new_xml_node, self.xml_node)
						self.xml_node = new_xml_node
						self.update()
						xml_dlg.destroy()
						break

	def validate(self) :
		passed = True
		if self.obj_attrs != None :
			passed = self.obj_attrs.verify_values()
		return passed

	def reset(self) :
		new_xml_node = self.init_xml_node.cloneNode(True)
		try :
			self.xml_node.parentNode.replaceChild(new_xml_node, self.xml_node)
		except xml.dom.NotFoundErr :
			msgbox(_("The object doesn't exist"))
			return
		self.xml_node = new_xml_node

class EditXMLDlg:
	def __init__(self, xml_node) :
		global top_window
		self.xml_node = xml_node

		dialog = gtk.Dialog(_("Edit XML"), top_window, gtk.DIALOG_MODAL,
			(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL, str(_("Reset")), gtk.RESPONSE_APPLY, gtk.STOCK_OK, gtk.RESPONSE_OK))
		dialog.set_type_hint(gtk.gdk.WINDOW_TYPE_HINT_NORMAL)
		dialog.set_default_size(750, 550)

		ui_xml = '''
		<ui>
			<toolbar name="toolbar">
				<toolitem action="import"/>
				<toolitem action="export"/>
			</toolbar>
			
		</ui>'''

		actions = [
			("import", gtk.STOCK_REVERT_TO_SAVED, _("Import"), "<Ctrl>o",
				_("Import XML"), self.import_xml),
			("export", gtk.STOCK_SAVE_AS, _("Export"), "<Ctrl>s",
				_("Export XML"), self.export_xml)
			 ]

		action_group = gtk.ActionGroup("rw_xml_file")
		action_group.add_actions(actions)

		uimanager = gtk.UIManager()
		uimanager.insert_action_group(action_group, 0)
		uimanager.add_ui_from_string(ui_xml)

		#toolbar = gtk.Toolbar()
		#toolbar.set_orientation(gtk.ORIENTATION_HORIZONTAL)
		#toolbar.set_style(gtk.TOOLBAR_BOTH)

		toolbar = uimanager.get_widget('/toolbar')
		toolbar.set_style(gtk.TOOLBAR_BOTH)
		dialog.vbox.pack_start(toolbar, False)

		#tool_item = action_group.get_action("import").create_tool_item()
		#toolbar.insert(tool_item, -1)

		#tool_item = action_group.get_action("export").create_tool_item()
		#toolbar.insert(tool_item, -1)

		sw = gtk.ScrolledWindow()
		sw.set_shadow_type(gtk.SHADOW_IN)
		sw.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
		self.xml_text = gtk.TextView()
		self.xml_text.set_wrap_mode(gtk.WRAP_WORD)
		self.xml_textbuffer = self.xml_text.get_buffer()
		sw.add(self.xml_text)
		dialog.vbox.pack_start(sw, padding=1)
		dialog.set_response_sensitive(gtk.RESPONSE_APPLY, False)

		self.statusbar = gtk.Statusbar()
		dialog.vbox.pack_end(self.statusbar, False)

		self.xml_str = xml_node.toxml()
		self.xml_textbuffer.set_text(self.xml_str)
		self.update_statusbar()
		self.xml_textbuffer.connect("changed", self.on_changed)

		self.xml_text.connect_after("move-cursor", self.update_statusbar)
		self.xml_text.connect("event-after", self.on_click_text)
		self.xml_text.connect_after("toggle-overwrite", self.update_statusbar)
		dialog.show_all()
		self.dialog = dialog
		self.save_top_window = top_window
		top_window = dialog

	def on_changed(self, widget) :
		self.dialog.set_response_sensitive(gtk.RESPONSE_APPLY, True)
		self.update_statusbar()

	def on_click_text(self, widget, event) :
		if event.type == gtk.gdk.BUTTON_PRESS and event.button == 1 :
			self.update_statusbar()

	def update_statusbar(self, textview = None , step_size = None, count = None, extend_selection = None) :
		iter = self.xml_textbuffer.get_iter_at_mark(self.xml_textbuffer.get_insert())
		line = iter.get_line()
		column = iter.get_line_offset()

		if self.xml_text.get_overwrite() :
			overwrite = _("OVR")
		else :
			overwrite = _("INS")

		self.statusbar.pop(0)
		self.statusbar.push(0, _("Ln %d, Col %d\t%s")%(line+1, column+1, overwrite))

	def run(self) :
		while True :
			ret = self.dialog.run()
			if ret in [gtk.RESPONSE_CANCEL, gtk.RESPONSE_DELETE_EVENT] :
				self.destroy()
				return None
			elif ret == gtk.RESPONSE_APPLY :
				self.xml_textbuffer.set_text(self.xml_str)
				self.dialog.set_response_sensitive(gtk.RESPONSE_APPLY, False)
			else :
				new_xml_str = self.xml_textbuffer.get_text(*self.xml_textbuffer.get_bounds())
				try :
					new_xml_node = parseString(new_xml_str).documentElement
				except xml.parsers.expat.ExpatError, msg :
					msgbox(_("Failed to parse the XML") + _(": ") + str(msg))
					continue

				return new_xml_node

	def destroy(self) :
		global top_window
		self.dialog.destroy()
		top_window = self.save_top_window

	def import_xml(self, widget) :
		global top_window
		file_dialog = gtk.FileChooserDialog(_("Open File"), None, 
				gtk.FILE_CHOOSER_ACTION_OPEN,
				(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL,
				gtk.STOCK_OPEN, gtk.RESPONSE_OK))

		save_top_window = top_window
		top_window = file_dialog

		filter = gtk.FileFilter()
		filter.set_name(_("All files"))
		filter.add_pattern("*")
		file_dialog.add_filter(filter)

		filter = gtk.FileFilter()
		filter.set_name(_("XML files"))
		filter.add_pattern("*.xml")
		file_dialog.add_filter(filter)

		ret = file_dialog.run()
		if ret in [gtk.RESPONSE_CANCEL, gtk.RESPONSE_DELETE_EVENT] :
			open_file = None
		else :
			open_file = file_dialog.get_filename()

		top_window = save_top_window
		file_dialog.destroy()

		if open_file == None :
			return

		try :
			file_obj = open(open_file)
		except IOError, msg :
			msgbox(_("I/O error") + _(": ") + str(msg))
			return
		
		try :
			new_xml_str = file_obj.read()
		except IOError, msg :
			msgbox(_("I/O error") + _(": ") + str(msg))
			file_obj.close()
			return
		file_obj.close()

		self.xml_textbuffer.set_text(new_xml_str)

	def export_xml(self, widget) :
		sfdlg = SelectFileDlg()
		node_id = self.xml_node.getAttribute("id")
		if node_id == "" :
			default_name = self.xml_node.tagName +  ".xml"
		else :
			default_name = self.xml_node.tagName + "-" + self.xml_node.getAttribute("id") + ".xml"
		(save_file, save_type) = sfdlg.select_file(default_name)
		if save_file == None :
			return

		try :
			fd = os.open(save_file, os.O_RDWR|os.O_CREAT|os.O_TRUNC, 0644)
		except OSError, msg :
			msgbox(_("System error") + _(": ") + str(msg))
			return

		new_xml_str = self.xml_textbuffer.get_text(*self.xml_textbuffer.get_bounds())

		try :
			os.write(fd, new_xml_str)
		except OSError, msg :
			msgbox(_("System error") + _(": ") + str(msg))
			os.close(fd)
			return
		os.close(fd)

class ElementNotebook :
	notebook = None
	new_page_type = None
	def __init__(self, xml_node, is_topview = False, change_call_back = None, show_mode = 0,
				is_fake_xml_node = False, missing_opt_obj_parent_type = None, single_page = False) :
		self.is_topview = is_topview
		self.change_call_back = change_call_back
		self.show_mode = show_mode
		self.is_fake_xml_node = is_fake_xml_node
		self.missing_opt_obj_parent_type = missing_opt_obj_parent_type
		self.single_page = single_page
		vbox = gtk.VBox()
		self.widget = vbox

		self.hbox = gtk.HBox()
		vbox.pack_start(self.hbox)

		self.sub_vbox = gtk.VBox()
		vbox.pack_start(self.sub_vbox, False)

		bbox = gtk.HButtonBox()
		bbox.set_layout(gtk.BUTTONBOX_END)
		bbox.set_spacing(5)
		add_btn = gtk.Button(stock=gtk.STOCK_ADD)
		bbox.add(add_btn)
		edit_btn = gtk.Button(stock=gtk.STOCK_EDIT)
		bbox.add(edit_btn)
		del_btn = gtk.Button(stock=gtk.STOCK_REMOVE)
		bbox.add(del_btn)
		self.bbox = bbox

		self.add_btn_handler = add_btn.connect("clicked", self.on_add)
		self.edit_btn_handler = edit_btn.connect("clicked", self.on_edit)
		self.del_btn_handler = del_btn.connect("clicked", self.on_del)

		self.add_btn = add_btn
		self.edit_btn = edit_btn
		self.del_btn = del_btn

	def update(self, xml_node = None) :
		global mode_level
		if xml_node != None :
			self.xml_node = xml_node
		self.elem_lists = []
		self.pages = []
		self.obj_type = self.xml_node.tagName
		for child in self.hbox.get_children() :
			self.hbox.remove(child)

		self.notebook = gtk.Notebook()
		self.hbox.pack_start(self.notebook, True, padding=2)

		if validate_type == "dtd" :
			self.dtd_elem = manager.get_dtd_elem(self.obj_type)
			names = [name for (name, mod) in self.dtd_elem.get_content_model()[1]]
			if self.single_page :
				elem_node_list = []
				for elem_node in self.xml_node.childNodes :
					if elem_node.nodeType != xml.dom.Node.ELEMENT_NODE :
						continue
					elem_node_list.append(elem_node)

				self.pages.append(None)

				if self.show_mode == 0 :
					elem_list = ElementList(names, elem_node_list)
				else :
					elem_list = ElementTree(names, elem_node_list)
				self.notebook.append_page(elem_list.widget)
				self.notebook.set_show_tabs(False)
				self.elem_lists.append(elem_list)
				elem_list.tree.connect("cursor-changed", self.on_cursor_changed)
				elem_list.tree.connect("event-after", self.on_click)
			else :
			    for name in names :
				elem_node_list = []
				for elem_node in self.xml_node.getElementsByTagName(name) :
					if elem_node in self.xml_node.childNodes :
						elem_node_list.append(elem_node)

				if len(elem_node_list) == 0 :
					if self.is_topview :
						continue
					elif mode_level != 0 :
						continue
					elif name in ["resource_set", "rule", "lifetime", "expression", "date_expression", "duration", "date_spec"] \
							or (self.obj_type in ["group"]
								and name in ["instance_attributes"]) \
							or (self.obj_type in ["clone", "master"]
								and name in ["primitive", "group", "instance_attributes"]) \
							or (self.obj_type in ["op"] 
								and name in ["meta_attributes", "instance_attributes"]) :
						continue

				#if len(elem_node_list) > 0 :
				if True :
					self.pages.append(name)
					tab_label = gtk.Label(_(name_cap(name)))
					sub_dtd_elem = manager.get_dtd_elem(name)
					if len(sub_dtd_elem.get_attr_list()) == 0 \
							or (mode_level != 2 and name in
							["meta_attributes", "instance_attributes", "operations",
							"cluster_property_set", "utilization"]) :
						if len(elem_node_list) > 1 and len(sub_dtd_elem.get_attr_list()) > 0 :
							mode_level = 2
							window.radio_tool_action_group.get_action("hack-mode").set_active(True)
							#if not self.is_topview :
							if True :
								msgbox(_("The \"%s\" has multiple \"%s\" sets.")
									%(_(name_cap(self.obj_type)), _(name_cap(name))) + "\n"
									+ _("We are switching to \"Hack Mode\" to view them properly."))
							return False

						if len(sub_dtd_elem.get_attr_list()) == 0 :
							(name, mod) = sub_dtd_elem.get_content_model()[1][0]
						else :
							(name, mod) = sub_dtd_elem.get_content_model()[1][1]
						sub_elem_node_list = []
						for elem_node in elem_node_list :
							for sub_elem_node in elem_node.childNodes :
								if sub_elem_node.nodeType != xml.dom.Node.ELEMENT_NODE :
									continue
								if sub_elem_node.tagName == name :
									sub_elem_node_list.append(sub_elem_node)
								else :
									mode_level = 2
									window.radio_tool_action_group.get_action("hack-mode").set_active(True)
									#if not self.is_topview :
									if True :
										msgbox(_("The \"%s\" has a \"%s\".")
											%(_(name_cap(elem_node.tagName)),
											name_cap(sub_elem_node.tagName)) + "\n"
											+ _("We are switching to \"Hack Mode\" to view them properly."))
									return False

						if len(sub_dtd_elem.get_attr_list()) == 0 :
							elem_node_list = sub_elem_node_list
						else :
							sub_sub_dtd_elem = manager.get_dtd_elem(name)
							(name, mod) = sub_sub_dtd_elem.get_content_model()[1][0]

							sub_sub_elem_node_list = []
							for sub_elem_node in sub_elem_node_list :
								for sub_sub_elem_node in sub_elem_node.getElementsByTagName(name) :
									if sub_sub_elem_node in sub_elem_node.childNodes :
										sub_sub_elem_node_list.append(sub_sub_elem_node)
							elem_node_list = sub_sub_elem_node_list

					if self.show_mode == 0 :
						elem_list = ElementList([name], elem_node_list)
					else :
						elem_list = ElementTree([name], elem_node_list)
					self.notebook.append_page(elem_list.widget, tab_label)
					self.elem_lists.append(elem_list)
					elem_list.tree.connect("cursor-changed", self.on_cursor_changed)
					elem_list.tree.connect("event-after", self.on_click)
		else :
			elem_node_dict = {}
			for elem_node in self.xml_node.childNodes :
				if elem_node.nodeType != xml.dom.Node.ELEMENT_NODE :
					continue
				name = elem_node.tagName
				if elem_node_dict.get(name) == None :
					elem_node_dict[name] = []
				elem_node_dict[name].append(elem_node)

			sorted_rng_nodes = manager.sorted_sub_rng_nodes_by_name(self.obj_type)
			self.elem_rng_node_dict = {}
			self.attr_rng_node_dict = {}
			is_any_name = False
			elem_type_list = []
			if sorted_rng_nodes != None :
				self.elem_rng_nodes = sorted_rng_nodes.get("element", [])
				attr_rng_nodes = sorted_rng_nodes.get("attribute", [])
				for rng_node in self.elem_rng_nodes :
					name = rng_node[0][1].getAttribute("name")
					if name == "" :
						is_any_name = True
					else :
						if elem_type_list.count(name) == 0 :
							elem_type_list.append(name)
							self.elem_rng_node_dict[name] = []
						self.elem_rng_node_dict[name].append(rng_node)

				for rng_node in attr_rng_nodes :
					name = rng_node[0][1].getAttribute("name")
					if not self.attr_rng_node_dict.has_key(name) :
						self.attr_rng_node_dict[name] = []
					self.attr_rng_node_dict[name].append(rng_node)
			else :
				self.elem_rng_nodes = []
				is_any_name = True

			self.is_any_name = is_any_name
			other_elem_types = []
			if is_any_name :
				for name in elem_node_dict.keys() :
					if elem_type_list.count(name) == 0 :
						other_elem_types.append(name)

			if self.single_page :
				names = []
			    	for rng_node in self.elem_rng_nodes :
					name = rng_node[0][1].getAttribute("name")
					if names.count(name) == 0 :
						names.append(name)

				elem_node_list = []
				for elem_node in self.xml_node.childNodes :
					if elem_node.nodeType != xml.dom.Node.ELEMENT_NODE :
						continue
					elem_node_list.append(elem_node)

				self.pages.append(None)

				if self.show_mode == 0 :
					elem_list = ElementList(names, elem_node_list)
				else :
					elem_list = ElementTree(names, elem_node_list)
				self.notebook.append_page(elem_list.widget)
				self.notebook.set_show_tabs(False)
				self.elem_lists.append(elem_list)
				elem_list.tree.connect("cursor-changed", self.on_cursor_changed)
				elem_list.tree.connect("event-after", self.on_click)
			else :
			    for rng_node in self.elem_rng_nodes :
				name = rng_node[0][1].getAttribute("name")
				elem_node_list = elem_node_dict.get(name, [])
				if len(elem_node_list) == 0 :
					if self.is_topview :
						continue
					elif mode_level != 0 :
						continue
					elif name in ["resource_set", "rule", "lifetime", "expression", "date_expression", "duration", "date_spec"] \
							or (self.obj_type in ["group"]
								and name in ["instance_attributes"]) \
							or (self.obj_type in ["clone", "master"] 
								and name in ["primitive", "group", "instance_attributes"]) \
							or (self.obj_type in ["op"] 
								and name in ["meta_attributes", "instance_attributes"]) :
						continue

				self.pages.append(name)
				tab_label = gtk.Label(_(name_cap(name)))
				sub_rng_nodes = manager.sorted_sub_rng_nodes_by_node(*rng_node[0])
				if sub_rng_nodes != None :
					sub_attr_rng_nodes = sub_rng_nodes.get("attribute", [])
					sub_elem_rng_nodes = sub_rng_nodes.get("element", [])

					if len(sub_attr_rng_nodes) == 0 \
							or (mode_level != 2 and name in 
							["meta_attributes", "instance_attributes", "operations",
							"cluster_property_set", "utilization"]) :
						if len(elem_node_list) > 1 and len(sub_attr_rng_nodes) > 0 :
							mode_level = 2
							window.radio_tool_action_group.get_action("hack-mode").set_active(True)
							#if not self.is_topview :
							if True :
								msgbox(_("The \"%s\" has multiple \"%s\" sets.")
									%(_(name_cap(self.obj_type)), _(name_cap(name))) + "\n"
									+ _("We are switching to \"Hack Mode\" to view them properly."))
							return False
						sub_elem_node_list = []
						for sub_elem_rng_node in sub_elem_rng_nodes :
							if manager.find_decl(sub_elem_rng_node, "optional") != 0 :
								continue
							name = sub_elem_rng_node[0][1].getAttribute("name")
							for elem_node in elem_node_list :
								for sub_elem_node in elem_node.childNodes :
									if sub_elem_node.nodeType != xml.dom.Node.ELEMENT_NODE :
										continue
									if sub_elem_node.tagName == name :
										sub_elem_node_list.append(sub_elem_node)
									else :
										mode_level = 2
										window.radio_tool_action_group.get_action("hack-mode").set_active(True)
										#if not self.is_topview :
										if True :
											msgbox(_("The \"%s\" has a \"%s\".")
												%(_(name_cap(elem_node.tagName)),
												name_cap(sub_elem_node.tagName)) + "\n"
												+ _("We are switching to \"Hack Mode\" to view them properly."))
										return False

							elem_node_list = sub_elem_node_list
							break
				if self.show_mode == 0 :
					elem_list = ElementList([name], elem_node_list)
				else :
					elem_list = ElementTree([name], elem_node_list)
				self.notebook.append_page(elem_list.widget, tab_label)
				self.elem_lists.append(elem_list)
				elem_list.tree.connect("cursor-changed", self.on_cursor_changed)
				elem_list.tree.connect("event-after", self.on_click)

			for name in other_elem_types :
				elem_node_list = elem_node_dict.get(name, [])
				if len(elem_node_list) == 0 :
					continue

				self.pages.append(name)
				tab_label = gtk.Label(_(name_cap(name)))
				
				sub_attr_list = []
				for elem_node in elem_node_list :
					for attr_name in elem_node.attributes.keys() :
						if sub_attr_list.count(attr_name) == 0 :
							sub_attr_list.append(attr_name)
				if len(sub_attr_list) == 0 :
					sub_elem_node_list = []
					for elem_node in elem_node_list :
						for sub_elem_node in elem_node.childNodes :
							if sub_elem_node.nodeType != xml.dom.Node.ELEMENT_NODE :
								continue
							name = sub_elem_node.tagName
							sub_elem_node_list.append(sub_elem_node)
					elem_node_list = sub_elem_node_list

				if self.show_mode == 0 :
					elem_list = ElementList([name], elem_node_list)
				else :
					elem_list = ElementTree([name], elem_node_list)
				self.notebook.append_page(elem_list.widget, tab_label)
				self.elem_lists.append(elem_list)
				elem_list.tree.connect("cursor-changed", self.on_cursor_changed)
				elem_list.tree.connect("event-after", self.on_click)

		if self.notebook.get_n_pages() > 0 :
			bbox = gtk.VButtonBox()
			bbox.set_layout(gtk.BUTTONBOX_SPREAD)
			bbox.set_spacing(5)
			up_btn = gtk.Button(stock=gtk.STOCK_GO_UP)
			bbox.add(up_btn)
			down_btn = gtk.Button(stock=gtk.STOCK_GO_DOWN)
			bbox.add(down_btn)
			self.hbox.pack_start(bbox, False, padding=2)

			self.up_btn = up_btn
			self.down_btn = down_btn

			up_btn.connect("clicked", self.on_up)
			down_btn.connect("clicked", self.on_down)

			self.hbox.show_all()
			self.notebook.set_size_request(350, 180)
			self.notebook.set_scrollable(True)
			self.notebook.popup_enable()
			self.notebook.connect("switch-page", self.on_switch_page)

		return True

	def on_after_show(self, page_num = None) :
		selected_node = self.get_selected_node(page_num)

		self.edit_btn.set_sensitive(selected_node != None)
		self.del_btn.set_sensitive(selected_node != None)

		elem_list = self.get_elem_list(page_num)
		if elem_list == None or selected_node == None :
			self.show_sub_attrs(None)
			return

		(model, iter) = elem_list.tree.get_selection().get_selected()

		self.up_btn.set_sensitive(iter != None and model.get_path(iter)[-1] != 0)
		self.down_btn.set_sensitive(iter != None and model.iter_next(iter) != None)
		self.show_sub_attrs(selected_node)

	def show_sub_attrs(self, selected_node) :
		for child in self.sub_vbox.get_children() :
			self.sub_vbox.remove(child)

		if selected_node == None :
			return

		if validate_type == "dtd" :
			dtd_elem = manager.get_dtd_elem(selected_node.tagName)
			attr_list = dtd_elem.get_attr_list()
		else :
			attr_list = []
			is_any_name = False
			sorted_rng_nodes = manager.sorted_sub_rng_nodes_by_name(selected_node.tagName)
			if sorted_rng_nodes != None :
				attr_rng_nodes = sorted_rng_nodes.get("attribute", [])
				for rng_node in attr_rng_nodes :
					name = rng_node[0][1].getAttribute("name")
					if name == "" :
						is_any_name = True
					elif attr_list.count(name) == 0 :
						attr_list.append(name)
			else :
				is_any_name = True

			if is_any_name :
				for attr_name in  selected_node.attributes.keys() :
					if attr_list.count(attr_name) == 0 :
						if attr_name == "id" :
							attr_list.insert(0, attr_name)
						else :
							attr_list.append(attr_name)

		name_labels = {}
		name_label_max_len = 0
		for attr_name in attr_list :
			attr_value = selected_node.getAttribute(attr_name)
			if attr_value == "" or name_labels.get(attr_name) != None :
				continue
			hbox = gtk.HBox()
			name_label = gtk.Label(_(name_cap(attr_name)+":"))
			name_label.set_alignment(0, 0.5)
			name_label.set_selectable(True)

			name_labels[attr_name] = name_label
			name_label_len = name_label.size_request()[0]
			if name_label_len > name_label_max_len :
				name_label_max_len = name_label_len

			value_label = gtk.Label(attr_value)
			value_label.set_alignment(0, 0.5)
			value_label.set_selectable(True)

			hbox.pack_start(name_label, False, padding=5)
			hbox.pack_start(value_label, False, padding=5)
			self.sub_vbox.pack_start(hbox, False, padding=2)

		for name_label in name_labels.values() :
			name_label.set_size_request(name_label_max_len + 20, -1)

		self.sub_vbox.show_all()

	def on_cursor_changed(self, treeview) : 
		self.on_after_show()

	def on_click(self, widget, event) :
		if (event.type == gtk.gdk._2BUTTON_PRESS and event.button == 1) \
			or ( event.type == gtk.gdk.KEY_PRESS and event.keyval == gtk.keysyms.Return) :
			self.on_edit(widget)

	def on_switch_page(self, notebook, page, page_num) :
		self.on_after_show(page_num)

	def get_selected_node(self, page_num = None) :
		if page_num == None :
			page_num = self.notebook.get_current_page()
		if page_num >= 0 :
			selected_node = self.elem_lists[page_num].get_selected_node()
		else :
			selected_node = None
		return selected_node

	def get_elem_list(self, page_num = None) :
		if page_num == None :
			page_num = self.notebook.get_current_page()
		if page_num >= 0 :
			elem_list = self.elem_lists[page_num]
		else :
			elem_list = None
		return elem_list

	def on_add(self, widget = None, invoked_by_wizard = False, append_title = "") :
		global top_window
		init_cib_xml_node = manager.xml_nodes["cib"]

		elem_rng_nodes = []
		if validate_type == "dtd" :
			option_list = self.get_elem_options_dtd()
		else :
			option_list = []
			elem_is_any_name = False
			elem_rng_nodes = self.get_elem_options_rng()
			if elem_rng_nodes == [] :
				elem_is_any_name = self.is_any_name
			for rng_node in elem_rng_nodes :
				name = rng_node[0][1].getAttribute("name")
				if name == "" :
					elem_is_any_name = True
				else :
					option_list.append(rng_node)

			if elem_is_any_name :
				for elem_node in self.xml_node.childNodes :
					if elem_node.nodeType != xml.dom.Node.ELEMENT_NODE :
						continue
					elem_name = elem_node.tagName
					if option_list.count(elem_name) == 0 :
						option_list.append(elem_name)

		page_num = self.notebook.get_current_page()
		if page_num >= 0 :
			current_type = self.pages[page_num]
		else :
			current_type = None

		if len(option_list) == 0 and not elem_is_any_name :
			return 0
		elif len(option_list) == 1 and not elem_is_any_name and not invoked_by_wizard \
				and ((validate_type == "dtd" and option_list[0] != "lifetime")
					or (validate_type != "dtd" and option_list[0][0][1].getAttribute("name") != "lifetime")) :
			obj_type = option_list[0]
		elif not invoked_by_wizard and mode_level == 0 and (
					self.obj_type in ["node", "primitive", "template", "group"]
					or (self.obj_type in ["clone", "master"]
						and (self.pages.count("primitive") > 0 
							or self.pages.count("group") > 0))
					) :
			if self.obj_type in ["clone", "master"] \
					and (self.pages.count("primitive") > 0 or self.pages.count("group") > 0) \
					and current_type in ["primitive", "group"] :
				return 0
			obj_type = current_type
		else :
			dialog = gtk.Dialog(_("Add"), top_window, gtk.DIALOG_MODAL,
				(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL, gtk.STOCK_OK, gtk.RESPONSE_OK))
			dialog.set_border_width(5)
			dialog.set_default_response(gtk.RESPONSE_OK)

			if append_title != "" :
				label = gtk.Label(append_title)
				label.set_markup('<big><b>' + append_title + '</b></big>')
				label.set_alignment(0, 0)
				dialog.vbox.pack_start(label, False, padding=2)

				separator = gtk.HSeparator()
				dialog.vbox.pack_start(separator, False, padding = 2)


			radio_btns = {}
			radio_btn = None
			for option in option_list :
				if type(option) == str or type(option) == unicode :
					opt_name = option
				else :
					opt_name = option[0][1].getAttribute("name")

				if opt_name == "" :
					continue

				if invoked_by_wizard and opt_name in ["meta_attributes", "instance_attributes", "operations"] :
					continue

				radio_btn = gtk.RadioButton(radio_btn, _(name_cap(opt_name)))
				if opt_name == current_type :
					radio_btn.set_active(True)
				dialog.vbox.pack_start(radio_btn, False, padding=2)
				radio_btns[radio_btn] = option

			if elem_is_any_name :
				radio_btn = gtk.RadioButton(radio_btn, _("Other") + _(":"))
				entry = gtk.Entry()
				entry.set_activates_default(True)

				hbox = gtk.HBox()
				hbox.pack_start(radio_btn, False, padding=2)
				hbox.pack_start(entry, True, padding=2)

				dialog.vbox.pack_start(hbox, False, padding=2)
				radio_btns[radio_btn] = entry

			if len(radio_btns) == 0 :
				return 0

			save_top_window = top_window
			top_window = dialog
			dialog.vbox.show_all()

			while True :
				ret = dialog.run()
				if ret == gtk.RESPONSE_OK :
					passed = True
					for radio_btn in radio_btns :
						if radio_btn.get_active() :
							obj_type = radio_btns[radio_btn]
							if type(obj_type) == gtk.Entry and obj_type.get_text() == "" :
								msgbox(_("Please specify the type of object you want to add"))
								passed = False
							break
					if passed :
						break
				else :
					obj_type = None
					break

			top_window = save_top_window
			dialog.destroy()

			if obj_type == None :
				return 0

		if validate_type == "dtd" :
			obj_type_name = obj_type
		else :
			if type(obj_type) == str or type(obj_type) == unicode :
				obj_type_name = obj_type
				#sorted_rng_nodes = manager.sorted_sub_rng_nodes_by_name(obj_type_name)
			elif type(obj_type) == gtk.Entry :
				obj_type_name = obj_type.get_text()
				#sorted_rng_nodes = manager.sorted_sub_rng_nodes_by_name(obj_type_name)
			else :
				obj_type_name = obj_type[0][1].getAttribute("name")
				#sorted_rng_nodes = manager.sorted_sub_rng_nodes_by_node(*obj_type[0])

		(parent_xml_node, add_obj_type, new_mid_elem) = manager.real_add_obj_type(self.xml_node, obj_type_name)
		if parent_xml_node == None :
			return 1
				
		if obj_type_name not in manager.get_supported_rsc_types() :
			add_mode = "dialog"
		elif invoked_by_wizard or mode_level == 0 :
			add_mode = "wizard"
		else :
			dialog = gtk.Dialog("Select Mode", top_window, gtk.DIALOG_MODAL,
				(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL, gtk.STOCK_OK, gtk.RESPONSE_OK))
			dialog.set_border_width(5)
			dialog.set_default_response(gtk.RESPONSE_OK)

			wizard_radio_btn = gtk.RadioButton(None, _("Wizard"))
			dialog.vbox.pack_start(wizard_radio_btn, False, padding=2)

			dialog_radio_btn = gtk.RadioButton(wizard_radio_btn, _("Dialog"))
			dialog.vbox.pack_start(dialog_radio_btn, False, padding=2)

			save_top_window = top_window
			top_window = dialog
			dialog.vbox.show_all()

			ret = dialog.run()

			if ret == gtk.RESPONSE_OK :
				if wizard_radio_btn.get_active() :
					add_mode = "wizard"
				else :
					add_mode = "dialog"
			else :
				add_mode = None

			top_window = save_top_window
			dialog.destroy()

			if add_mode == None :
				return 1

		impl = getDOMImplementation()
		newdoc = impl.createDocument(None, add_obj_type, None)
		new_elem = newdoc.documentElement
		parent_xml_node.appendChild(new_elem)

		if add_mode == "wizard" :
			objdlg = AddWizard(new_elem)
		else :
			objdlg = ObjectViewDlg(new_elem, True)

		while True :
			new_xml_node = objdlg.run()
			if new_xml_node == None :
				tmp_elem = objdlg.obj_view.xml_node
				tmp_elem.parentNode.removeChild(tmp_elem)
				if new_mid_elem != None :
					new_mid_elem.parentNode.removeChild(new_mid_elem)
				if self.is_topview and window.cur_view != None :
					window.cur_view.update()
				return 2
			if not self.is_topview :
				objdlg.destroy()
				self.new_page_type = obj_type_name
				self.on_changed()
				if self.change_call_back != None :
					self.change_call_back()
				return 3
			else :
				if self.is_fake_xml_node :
					parent_xml_node = self.xml_node.cloneNode(True)
					#parent_xml_node.appendChild(new_xml_node)
					xml_str = parent_xml_node.toxml().replace("\n", "")
					parent_type = self.missing_opt_obj_parent_type
					if parent_type == None :
						if parent_xml_node.tagName != "node_state" :
							parent_type = "configuration"
						else :
							parent_type = "status"
					manager.cib_do_cmd("cib_create\n%s\n%s"%(str(parent_type), str(xml_str)))
				else :
					if not manager.validate_cib(init_cib_xml_node) :
						continue
					#xml_str = new_xml_node.toxml().replace("\n", "")
					#parent_type = self.obj_type
					xml_str = self.xml_node.toxml().replace("\n", "")
					manager.cib_do_cmd("cib_replace\n%s\n%s"%(str(self.obj_type), str(xml_str)))

				if manager.failed_reason != "" :
					msgbox(manager.failed_reason)
				else :
					if manager.active_cib != "" :
						manager.set_update()
					objdlg.destroy()
					self.new_page_type = obj_type_name
					return 3

	def get_elem_options_dtd(self) :
		(sep,cont,mod) =  self.dtd_elem.get_content_model()
		option_list = []
		if mod == "*" :
			for sub in cont :
				if len(sub) == 2 :
					option_list.append(sub[0])
		else :
			if sep != "|" :
				for sub in cont :
					if len(sub) == 2 :
						if sub[1] == "*" or sub[1] == "+":
							option_list.append(sub[0])
						elif sub[1] == "" or sub[1] == "?" :
							elem_node_list = []
							for elem_node in self.xml_node.getElementsByTagName(sub[0]) :
								if elem_node in self.xml_node.childNodes :
									elem_node_list.append(elem_node)
							if len(elem_node_list) < 1 or \
									len(manager.get_dtd_elem(sub[0]).get_attr_list()) == 0 :
								option_list.append(sub[0])

		return option_list

	def get_elem_options_rng(self) :
		attr_rng_node_dict = self.attr_rng_node_dict
		elem_rng_node_dict = self.elem_rng_node_dict

		object_attrs = {}
		for (k, v) in self.xml_node.attributes.items() :
			object_attrs[k] = v

		ref_match_value_decl_nodes_list = []
		ref_decl_nodes_list = []
		for key in object_attrs :
			for attr_rng_node in attr_rng_node_dict.get(key, []) :
				decl_rng_nodes = manager.get_decl_rng_nodes(attr_rng_node)
				value_list = []
				sub_rng_nodes = manager.sorted_sub_rng_nodes_by_node(*attr_rng_node[0])
				for value_node in sub_rng_nodes.get("value", []) :
					value_list.append(value_node[0][1].childNodes[0].data)
				if object_attrs.get(key, "") in value_list :
					ref_match_value_decl_nodes_list.append(decl_rng_nodes)
				elif len(sub_rng_nodes.get("data", [])) > 0 or len(sub_rng_nodes.get("text", [])) > 0 :
					ref_decl_nodes_list.append(decl_rng_nodes)

		if len(ref_match_value_decl_nodes_list) > 0 :
			ref_decl_nodes_list = ref_match_value_decl_nodes_list

		ref_sorted_nodes = {}
		for decl_type in ["choice", "first_choice", "group", "first_group"] :
			ref_sorted_nodes[decl_type] = manager.get_sorted_decl_nodes(ref_decl_nodes_list, decl_type)

		elem_node_dict = {}
		for elem_node in self.xml_node.childNodes :
			if elem_node.nodeType != xml.dom.Node.ELEMENT_NODE :
				continue
			elem_type = elem_node.tagName
			if not elem_node_dict.has_key(elem_type) :
				elem_node_dict[elem_type] = []
			elem_node_dict[elem_type].append(elem_node)

		exist_elem_rng_nodes = []
		ref_elem_decl_nodes_list = []
		for key in elem_node_dict :
			for elem_rng_node in elem_rng_node_dict.get(key, []):
				if len(elem_node_dict[key]) > 1 and manager.find_decl(elem_rng_node, "oneOrMore") == 0 \
						and manager.find_decl(elem_rng_node, "zeroOrMore") == 0 :
					continue
				exist_elem_rng_nodes.append(elem_rng_node)
				decl_rng_nodes = manager.get_decl_rng_nodes(elem_rng_node)
				ref_elem_decl_nodes_list.append(decl_rng_nodes)

		ref_elem_sorted_nodes = {}
		for decl_type in ["choice", "first_choice", "group", "first_group"] :
			ref_elem_sorted_nodes[decl_type] = manager.get_sorted_decl_nodes(ref_elem_decl_nodes_list, decl_type)

		option_list = []
		for rng_node in self.elem_rng_nodes :
			name = rng_node[0][1].getAttribute("name")

			if option_list.count(name) > 0 :
				continue

			can_add = True 
			
			if rng_node not in exist_elem_rng_nodes :
				decl_rng_nodes = manager.get_decl_rng_nodes(rng_node)
				if decl_rng_nodes.get("choice") != None :
					for sorted_nodes in [ref_sorted_nodes, ref_elem_sorted_nodes] :
						if decl_rng_nodes["choice"] in sorted_nodes["choice"] :
							if manager.find_decl(rng_node, "zeroOrMore") != 0 and \
									manager.find_decl(rng_node, "zeroOrMore") > \
										manager.find_decl(rng_node, "choice") :
								continue
							if manager.find_decl(rng_node, "oneOrMore") != 0 and \
									manager.find_decl(rng_node, "oneOrMore") > \
										manager.find_decl(rng_node, "choice") :
								continue
							if len(sorted_nodes["group"]) == 0 :
									can_add = False
							else :
								if decl_rng_nodes.get("group") not in sorted_nodes["group"] :
									can_add = False
								elif decl_rng_nodes.get("first_choice") in sorted_nodes["first_choice"] and \
										decl_rng_nodes.get("first_group") not in sorted_nodes["first_group"] :
									can_add = False

			if not can_add :
				continue

			if manager.find_decl(rng_node, "zeroOrMore") != 0 or manager.find_decl(rng_node, "oneOrMore") != 0 :
				option_list.append(rng_node)
			else :
				sub_rng_nodes = manager.sorted_sub_rng_nodes_by_node(*rng_node[0])
				if len(elem_node_dict.get(name, [])) < 1 or len(sub_rng_nodes.get("attribute", [])) == 0 \
						or (mode_level != 2 and name in ["operations"]):
					option_list.append(rng_node)
		return option_list
							

	def on_edit(self, widget) :
		init_cib_xml_node = manager.xml_nodes["cib"]

		selected_node = self.get_selected_node()
		if selected_node == None :
			return
		objdlg = ObjectViewDlg(selected_node, False)
		while True :
			new_xml_node = objdlg.run()
			if new_xml_node == None :
				if not self.is_topview :
					self.on_changed()
				else :
					if window.cur_view != None :
						window.cur_view.update()
				return
			if not self.is_topview :
				objdlg.destroy()
				self.on_changed()
				if self.change_call_back != None :
					self.change_call_back()
				return
			else :
				if not manager.validate_cib(init_cib_xml_node) :
					continue
				#if new_xml_node.getAttribute("id") != "" :
				#	xml_str = new_xml_node.toxml().replace("\n", "")
				#else :
				#	xml_str = new_xml_node.parentNode.toxml().replace("\n", "")
				xml_str = self.xml_node.toxml().replace("\n", "")

				manager.cib_do_cmd("cib_replace\n%s\n%s"%(str(self.obj_type), str(xml_str)))
				if manager.failed_reason != "" :
					msgbox(manager.failed_reason)
				else :
					if window.cur_view != None :
						window.cur_view.update()
					objdlg.destroy()
					return

	def on_del(self, widget) :
		selected_node = self.get_selected_node()
		if selected_node == None :
			return
		ret = confirmbox(_("This will delete the %s \"%s\"")%(_(name_cap(selected_node.tagName)), selected_node.getAttribute("id")),
				(gtk.STOCK_NO, gtk.RESPONSE_NO, gtk.STOCK_YES, gtk.RESPONSE_YES),
				_("Delete the selected object?"))
		if ret == gtk.RESPONSE_YES :
			selected_node.parentNode.removeChild(selected_node)
			if not self.is_topview :
				self.on_changed()
				if self.change_call_back != None :
					 self.change_call_back()
			else :
				#manager.validate_cib()
				#xml_str = selected_node.toxml().replace("\n", "")
				#manager.cib_do_cmd("cib_delete\n%s\n%s"%(str(self.obj_type), str(xml_str)))
				#if manager.failed_reason != "" :
				#	msgbox(manager.failed_reason)

				if manager.validate_cib() :
					xml_str = selected_node.toxml().replace("\n", "")
					manager.cib_do_cmd("cib_delete\n%s\n%s"%(str(self.obj_type), str(xml_str)))
					if manager.failed_reason != "" :
						msgbox(manager.failed_reason)
						if manager.active_cib != "" :
							manager.set_update()
					elif manager.active_cib != "" :
						self.on_changed()
				else :
					manager.set_update()

	def on_up(self, widget) :
		elem_list = self.get_elem_list()
		if elem_list == None :
			return

		(model, iter) = elem_list.tree.get_selection().get_selected()
		if iter == None or model.get_path(iter)[-1] == 0 :
			return

		(type, id) =  elem_list.get_node_key(model, iter)

		path = model.get_path(iter)
		if path[-1] < 1 :
			return
		prev_path_list = list(path[:])
		prev_path_list[-1] = prev_path_list[-1] - 1
		prev_path = tuple(prev_path_list)

		prev_iter = model.get_iter(prev_path)
		(prev_type, prev_id) = elem_list.get_node_key(model, prev_iter)

		selected_node = elem_list.nodes[(type, id)]
		prev_node = elem_list.nodes[(prev_type, prev_id)]

		try :
			selected_node.parentNode.insertBefore(selected_node.cloneNode(True), prev_node)
		except :
			return

		selected_node.parentNode.removeChild(selected_node)

		if self.is_topview :
			if manager.validate_cib() :
				xml_str = self.xml_node.toxml().replace("\n", "")
				manager.cib_do_cmd("cib_replace\n%s\n%s"%(str(self.obj_type), str(xml_str)))
				if manager.failed_reason != "" :
					msgbox(manager.failed_reason)
					if manager.active_cib != "" :
						manager.set_update()
				else :
					self.on_changed()
			else :
				manager.set_update()
		else :
			self.on_changed()
			if self.change_call_back != None :
				self.change_call_back()

	def on_down(self, widget) :
		elem_list = self.get_elem_list()
		if elem_list == None :
			return

		(model, iter) = elem_list.tree.get_selection().get_selected()
		if iter == None or model.iter_next(iter) == None :
			return

		(type, id) =  elem_list.get_node_key(model, iter)
		selected_node = elem_list.nodes[(type, id)]

		n_iter = model.iter_next(iter)
		nn_iter = model.iter_next(n_iter)

		if nn_iter == None :
			try :
				selected_node.parentNode.appendChild(selected_node.cloneNode(True))
			except :
				return
		else :
			(nn_type, nn_id) = elem_list.get_node_key(model, nn_iter)
			nn_node = elem_list.nodes[(nn_type, nn_id)]
			try :
				selected_node.parentNode.insertBefore(selected_node.cloneNode(True), nn_node)
			except :
				return
		selected_node.parentNode.removeChild(selected_node)

		if self.is_topview :
			if manager.validate_cib() :
				xml_str = self.xml_node.toxml().replace("\n", "")
				manager.cib_do_cmd("cib_replace\n%s\n%s"%(str(self.obj_type), str(xml_str)))
				if manager.failed_reason != "" :
					msgbox(manager.failed_reason)
					if manager.active_cib != "" :
						manager.set_update()
				else :
					self.on_changed()
			else :
				manager.set_update()
		else :
			self.on_changed()
			if self.change_call_back != None :
				self.change_call_back()

	def on_changed(self) :
		notebook_status = self.save_status()
		self.update()
		if notebook_status != None :
			self.restore_status(notebook_status)
		else :
			self.on_after_show()

	def save_status(self) :
		page_num = self.notebook.get_current_page()
		if page_num < 0 :
			return None

		page_type = self.pages[page_num]

		new_page_type = self.new_page_type
		self.new_page_type = None

		tree_status = {}
		for i in range(len(self.elem_lists)) :
			tree_status[self.pages[i]] =  self.elem_lists[i].save_tree_status()
		return (page_type, new_page_type, tree_status)

	def restore_status(self, notebook_status) :
		(page_type, new_page_type, tree_status) = notebook_status

		if new_page_type != None :
			set_page_type = new_page_type
		else :
			set_page_type = page_type

		for i in range(len(self.elem_lists)) :
			page_name = self.pages[i]
			if page_name == set_page_type :
				self.notebook.set_current_page(i)
			if tree_status.get(page_name) != None :
				self.elem_lists[i].restore_tree_status(tree_status[page_name])
		self.on_after_show()
		
class AddWizard :
	current_page = None
	def __init__(self, xml_node) :
		self.xml_node = xml_node
		self.obj_type = xml_node.tagName

		common_options = [
		("target-role", [["", "Defaults to \"Started\" or inherit from its parent"], ["Started", ""], ["Stopped", ""]],
			_("Initial state of resource")),
		]

		clone_basic_options = [
		("clone-max", [],
		 _("Maximum number of copies (Defaults to the number of nodes in the cluster)")),
		("clone-node-max", [["1", _("[ default ]")]],
		 _("Maximum number of copies on a single node (Defaults to 1)")),
		]
		clone_other_options = [
		("notify", [["false", _("[ default ]")], ["true", ""]],
		 _("Notify all the other copies before stopping or starting a copy and when the action was successful (Defaults to false)")),
		("globally-unique", [["false", _("[ default ]")], ["true", ""]],
		 _("Globally Unique (Does each copy of the clone perform a different function? Defaults to false)")),
		("interleave", [["false", _("[ default ]")], ["true", ""]],
		 _("Interleave (Changes the behavior of ordering constraints (between clones/masters) so that instances can start/stop as soon as their peer instance has (rather than waiting for every instance of the other clone has). Defaults to false)")),
		]

		master_basic_options = [
		("master-max", [["1", _("[ default ]")]],
		 _("Maximum number of master copies (Defaults to 1)")),
		("master-node-max", [["1", _("[ default ]")]],
		 _("Maximum number of master copies on a single node (Defaults to 1)"))
		]

		meta_attributes_options = {
		"primitive": common_options,
		"template": common_options,
		"group": common_options,
		"clone": common_options + clone_basic_options + clone_other_options,
		"master": common_options + clone_basic_options + master_basic_options + clone_other_options,
		}
		self.meta_attributes_options = meta_attributes_options

		self.default_meta_attributes = {}
		for option in meta_attributes_options[self.obj_type] :
			if validate_type == "dtd" :
				key = option[0].replace("-", "_")
			else :
				key = option[0]
			for (value, decl) in option[1] :
				if decl.count(_("[ default ]")) > 0 :
					self.default_meta_attributes[key] = value

	def first_page_render(self) :
		title = _("Add") + " " + _(name_cap(self.xml_node.tagName))
		dialog = gtk.Dialog(title, top_window, gtk.DIALOG_MODAL,
			(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL, gtk.STOCK_GO_FORWARD, gtk.RESPONSE_OK))
		dialog.set_border_width(5)
		dialog.set_type_hint(gtk.gdk.WINDOW_TYPE_HINT_NORMAL)
		dialog.set_default_response(gtk.RESPONSE_OK)
		self.dialog = dialog
		self.current_page = 0

		label = gtk.Label()
		label_text = title + " - " + _("Basic Settings")
		label.set_markup('<big><b>' + label_text + '</b></big>')
		label.set_alignment(0, 0)
		label.show()
		dialog.vbox.pack_start(label, False, padding = 2)

		separator = gtk.HSeparator()
		separator.show()
		dialog.vbox.pack_start(separator, False, padding = 2)

		if self.obj_type in ["primitive", "template"] :
			obj_attrs = Primitive(self.xml_node, True, hide_optional = True)
		else :
			obj_attrs = obj_attrs = ObjectAttrs(self.xml_node, True, hide_optional = True)
		obj_attrs.update()
		obj_attrs.on_after_show()

		dialog.vbox.pack_start(obj_attrs.attrs_vbox)
		self.obj_attrs = obj_attrs
		self.obj_view = obj_attrs

		label = gtk.Label()
		label.set_markup('<b>' + _("Options") + '</b>')
		label.set_alignment(0, 1)
		label.show()
		dialog.vbox.pack_start(label, False, padding = 2)

		meta_attributes = self.get_meta_attributes()

		combos = {}
		checkbuttons = {}
		spinbuttons = {}

		self.num_buttons_map = {}

		for option in self.meta_attributes_options[self.obj_type] :
			if validate_type == "dtd" :
				key = option[0].replace("-", "_")
			else :
				key = option[0]

			is_boolean = False
			for value in option[1] :
				if value[0] in ["true", "false"] :
					is_boolean = True
					break

			hbox = gtk.HBox()
			if not is_boolean :
				name_label = gtk.Label(option[2] + _(":"))
				name_label.set_alignment(0, 0.5)

				if key.count("max") > 0 :
					num_checkbutton = gtk.CheckButton()
					num_checkbutton.add(name_label)

					num_checkbutton.connect("toggled", self.on_num_checkbutton_toggled)
					if meta_attributes.get(key, "") != "" :
						num_checkbutton.set_active(True)
					
					hbox.pack_start(num_checkbutton, False, padding=2)
				else :
					hbox.pack_start(name_label, False, padding=2)

			if is_boolean :
				label = gtk.Label(option[2])
				label.set_line_wrap(True)
				widget = gtk.CheckButton()
				widget.add(label)

				checkbuttons[key] = widget
				hbox.pack_start(widget, True, padding=2)
			elif key.count("max") > 0 :
				if key in ["clone-max", "clone_max"] :
					node_list = manager.get_normal_nodes()
					if node_list != None and len(node_list) > 0 :
						init_value = len(node_list)
					else :
						init_value = 1
				else :
					init_value = 1

				adj = gtk.Adjustment(init_value, 1, 999, 1, 3)
				widget = gtk.SpinButton(adj, 0, 0)
				widget.set_width_chars(3)
				widget.set_wrap(True)

				if meta_attributes.get(key, "") == "" :
					widget.set_sensitive(False)

				self.num_buttons_map[num_checkbutton] = widget

				hbox.pack_start(widget, False)
				spinbuttons[key] = widget
			else :
				store = gtk.ListStore(str, str)
				for value in option[1] :
					store.append(value)

				widget = gtk.ComboBox(store)
				cell0 = gtk.CellRendererText()
				cell1 = gtk.CellRendererText()
				widget.pack_start(cell0, True)
				widget.pack_start(cell1, True)
				widget.add_attribute(cell0, 'text', 0)
				widget.add_attribute(cell1, 'text', 1)

				combos[key] = widget
				hbox.pack_start(widget, True, padding=2)

			hbox.show_all()
			dialog.vbox.pack_start(hbox, False, padding=2)

		widgets = {}
		widgets["combos"] = combos
		widgets["checkbuttons"] = checkbuttons
		widgets["spinbuttons"] = spinbuttons
		widget_group = WidgetGroup(widgets)
		self.widget_group = widget_group

		if self.obj_type in ["primitive", "template"]:
			label = gtk.Label(_("Add monitor operation"))
			self.monitor_checkbutton = gtk.CheckButton()
			self.monitor_checkbutton.add(label)
			self.monitor_checkbutton.show_all()
			dialog.vbox.pack_start(self.monitor_checkbutton, False, padding=2)

	def on_num_checkbutton_toggled(self, widget) :
		spinbutton = self.num_buttons_map.get(widget)
		if spinbutton != None :
			spinbutton.set_sensitive(widget.get_active())

	def get_meta_attributes(self) :
		meta_attributes = {}
		for meta_attributes_node in self.xml_node.getElementsByTagName("meta_attributes") :
			for nv_xml_node in meta_attributes_node.getElementsByTagName("nvpair") :
				attribute_name = nv_xml_node.getAttribute("name")
				meta_attributes[attribute_name] = nv_xml_node.getAttribute("value")
			break
		return meta_attributes

	def first_page_update(self) :
		meta_attributes = self.get_meta_attributes()
		tmp_meta_attributes = self.default_meta_attributes.copy()
		tmp_meta_attributes.update(meta_attributes)
		self.widget_group.show_values(tmp_meta_attributes)

		if self.obj_type in ["primitive", "template"]:
			monitors = self.get_monitors()
			if len(monitors) > 0 :
				self.monitor_checkbutton.set_active(True)
			else :
				self.monitor_checkbutton.set_active(False)

	def first_page_run(self) :
		global top_window
		dialog = self.dialog
		dialog.vbox.show()
		save_top_window = top_window
		top_window = dialog

		while True :
			ret = dialog.run()

			if ret == gtk.RESPONSE_OK :
				passed = self.obj_attrs.verify_values()
				if not passed :
					continue
				dialog.destroy()
				top_window = save_top_window

				self.set_meta_attributes()
				if self.obj_type in ["primitive", "template"] :
					meta = self.get_rsc_meta()
					self.set_monitor(meta)
					self.set_inst_attributes(meta)
				return self.last_page(True)
			else :
				dialog.destroy()
				top_window = save_top_window
				return None

	def set_meta_attributes(self) :
		meta_attributes = self.widget_group.get_values()

		(parent_xml_node, add_obj_type, new_mid_elem) = manager.real_add_obj_type(self.xml_node, "meta_attributes", True)
		if parent_xml_node == None :
			return

		nv_xml_nodes = {}
		for nv_xml_node in parent_xml_node.getElementsByTagName("nvpair") :
			nv_name = nv_xml_node.getAttribute("name")
			nv_xml_nodes[nv_name] = nv_xml_node

		impl = getDOMImplementation()
		for attr_name in meta_attributes :
			nv_xml_node = nv_xml_nodes.get(attr_name)
			if attr_name.count("max") > 0 :
				value = meta_attributes[attr_name].split(".")[0]
			else :
				value = meta_attributes[attr_name]

			if nv_xml_node != None :
				#if value != self.default_meta_attributes.get(attr_name) :
					nv_xml_node.setAttribute("value", value)
				#else :
				#	nv_xml_node.parentNode.removeChild(nv_xml_node)
			else :
				if value != self.default_meta_attributes.get(attr_name) :
					newdoc = impl.createDocument(None, "nvpair", None)
					nv = newdoc.documentElement
					parent_xml_node.appendChild(nv)

					attr_id = manager.auto_unique_id(nv, attr_name)
					nv.setAttribute("id", attr_id)
					nv.setAttribute("name", attr_name)
					nv.setAttribute("value", value)

		for option in self.meta_attributes_options[self.obj_type] :
			if validate_type == "dtd" :
				attr_name = option[0].replace("-", "_")
			else :
				attr_name = option[0]

			nv_xml_node = nv_xml_nodes.get(attr_name)
			if nv_xml_node != None and meta_attributes.get(attr_name, "") == "" :
				nv_xml_node.parentNode.removeChild(nv_xml_node)


		if len(parent_xml_node.getElementsByTagName("nvpair")) == 0 :
			parent_xml_node.parentNode.removeChild(parent_xml_node)

	def get_monitors(self) :
		monitors = []
		for operations_node in self.xml_node.getElementsByTagName("operations") :
			for op_node in operations_node.getElementsByTagName("op") :
				op_name = op_node.getAttribute("name")
				if op_name == "monitor" :
					monitors.append(op_node)
		return monitors

	def get_rsc_meta(self) :
		primitive_attrs = manager.get_rsc_attrs(self.xml_node, ["class", "type", "provider"])
		primitive_class = str(primitive_attrs.get("class", ""))
		primitive_type = str(primitive_attrs.get("type", ""))
		primitive_provider = str(primitive_attrs.get("provider", ""))
		meta = manager.get_rsc_meta(primitive_class, primitive_type, primitive_provider)
		return meta

	def set_monitor(self, meta) :
		if self.obj_type not in ["primitive", "template"] or meta == None :
			return

		monitors = self.get_monitors()
		(parent_xml_node, add_obj_type, new_mid_elem) = manager.real_add_obj_type(self.xml_node, "operations", True)
		if parent_xml_node == None :
			return

		enable_monitor = self.monitor_checkbutton.get_active()
		if enable_monitor :
			if len(monitors) == 0 :
				impl = getDOMImplementation()

				if validate_type == "dtd" :
					dtd_elem = manager.get_dtd_elem(add_obj_type)
					attr_list = dtd_elem.get_attr_list()
				else :
					attr_list = []
					sorted_rng_nodes = manager.sorted_sub_rng_nodes_by_name(add_obj_type)
					if sorted_rng_nodes != None :
						attr_rng_nodes = sorted_rng_nodes.get("attribute", [])
						for rng_node in attr_rng_nodes :
							name = rng_node[0][1].getAttribute("name")
							if attr_list.count(name) == 0 :
								attr_list.append(name)

				default_interval = "10"
				for action in meta.actions :
					if action.get("name") == "monitor" :
						newdoc = impl.createDocument(None, add_obj_type, None)
						op = newdoc.documentElement
						parent_xml_node.appendChild(op)

						primitive_id = str(self.xml_node.getAttribute("id"))
						op_id = primitive_id + "-" + add_obj_type + "-" + action["name"]
						role = action.get("role", "")
						if role != "" : 
							op_id += "-" + role
						interval = action.get("interval", "")
						if interval == "" :
							interval = default_interval

						op_id += "-" + interval
						unique_id = manager.get_unique_id(op_id, op)
						op.setAttribute("id", unique_id)

						for attr_name in attr_list :
							key  = attr_name.replace("_", "-")
							value = action.get(key, "")
							if value != "" :
								op.setAttribute(key, action[key])
							else :
								if key == "interval" :
									op.setAttribute(key, default_interval)

			else :
				return
				
		else :
			for monitor in monitors :
				monitor.parentNode.removeChild(monitor)

		ops = []
		for operations_node in self.xml_node.getElementsByTagName("operations") :
			for op_node in operations_node.getElementsByTagName("op") :
				op_name = op_node.getAttribute("name")
				ops.append(op_node)
		if len(ops) == 0 :
			parent_xml_node.parentNode.removeChild(parent_xml_node)

	def set_inst_attributes(self, meta) :
		if self.obj_type != "primitive" or meta == None :
			return

		(parent_xml_node, add_obj_type, new_mid_elem) = manager.real_add_obj_type(self.xml_node, "instance_attributes", True)
		if parent_xml_node == None :
			return

		nv_xml_nodes = {}
		for nv_xml_node in parent_xml_node.getElementsByTagName("nvpair") :
			nv_name = nv_xml_node.getAttribute("name")
			nv_xml_nodes[nv_name] = nv_xml_node

		impl = getDOMImplementation()

		param_list = []
		for param in meta.parameters :
			attr_name = param.get("name", "")
			if attr_name == "" :
				continue

			param_list.append(attr_name)

			if nv_xml_nodes.get(attr_name) != None :
				continue

			if param.get("required") == "1" :
				newdoc = impl.createDocument(None, "nvpair", None)
				nv = newdoc.documentElement
				parent_xml_node.appendChild(nv)

				attr_id = manager.auto_unique_id(nv, attr_name)
				nv.setAttribute("id", attr_id)
				nv.setAttribute("name", attr_name)

		for nv_name in nv_xml_nodes :
			if nv_name not in param_list :
				nv_xml_nodes[nv_name].parentNode.removeChild(nv_xml_nodes[nv_name])

		if len(parent_xml_node.getElementsByTagName("nvpair")) == 0 :
			parent_xml_node.parentNode.removeChild(parent_xml_node)

	def first_page_init_run(self) :
		self.first_page_render()
		self.first_page_update()

		if validate_type == "dtd" :
			target_role_widget = self.widget_group.widgets["combos"].get("target_role")
		else :
			target_role_widget = self.widget_group.widgets["combos"].get("target-role")
		if target_role_widget != None :
			if self.xml_node.parentNode.tagName == "resources" and manager.active_cib == "" :
				default_value = "Stopped"
			else :
				default_value = ""
				
			model = target_role_widget.get_model()
			iter = model.get_iter_first()
			while iter != None :
				if model.get_value(iter,0) == default_value :
					target_role_widget.set_active_iter(iter)
					break
				iter = model.iter_next(iter)

		if self.obj_type in ["primitive", "template"] :
			self.monitor_checkbutton.set_active(True)

		return self.first_page_run()

	def first_page_update_run(self) :
		self.first_page_render()
		self.first_page_update()
		return self.first_page_run()

	def last_page(self, add_prompt = False) :
		global top_window
		title = _("Add") + " " + _(name_cap(self.obj_type))
		dialog = gtk.Dialog(title, top_window, gtk.DIALOG_MODAL,
			(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL, gtk.STOCK_GO_BACK, gtk.RESPONSE_REJECT, gtk.STOCK_APPLY, gtk.RESPONSE_APPLY))
		dialog.set_border_width(5)
		dialog.set_type_hint(gtk.gdk.WINDOW_TYPE_HINT_NORMAL)
		dialog.set_default_response(gtk.RESPONSE_APPLY)

		self.current_page = 1

		label_text = title + " - "
		rsc_id = self.xml_node.getAttribute("id")
		if rsc_id != "" :
			label_text += _("Summary Of \"%s\"")%rsc_id
		else :
			label_text += _("Summary")

		label = gtk.Label()
		label.set_markup('<big><b>' + label_text + '</b></big>')
		label.set_alignment(0, 0)
		dialog.vbox.pack_start(label, False, padding=2)

		separator = gtk.HSeparator()
		dialog.vbox.pack_start(separator, False, padding = 2)

		elem_notebook = ElementNotebook(self.xml_node, False)
		elem_notebook.update(self.xml_node)
		dialog.vbox.pack_start(elem_notebook.widget, True, padding = 5)
		dialog.vbox.pack_start(elem_notebook.bbox, False, padding = 2)

		dialog.vbox.show_all()

		if self.obj_type not in ["primitive", "template"] and add_prompt :
			if rsc_id != "" :
				title_suffix = _("Sub-resource For \"%s\"")%rsc_id
			else :
				title_suffix = _("Sub-resource")

			first_title = title + " - " + _("Add ") + title_suffix
			later_title = title + " - " + _("Continue Adding ") + title_suffix
			append_title = first_title

			while True :
				if elem_notebook.on_add(invoked_by_wizard = True, append_title = append_title) == 0 :
					break
				#if self.obj_type in ["clone", "master"] :
				#	break
				append_title = later_title

		if self.obj_type == "primitive" :
			set_page_type = "instance_attributes"
		elif self.obj_type == "group" :
			set_page_type = "primitive"
		else :
			if len(self.xml_node.getElementsByTagName("group")) > 0 :
				set_page_type = "group"
			else :
				set_page_type = "primitive"

		elem_notebook.restore_status((set_page_type, None, {}))
		#elem_notebook.on_after_show()

		save_top_window = top_window
		top_window = dialog

		while True :
			ret = dialog.run()

			if ret == gtk.RESPONSE_APPLY :
				dialog.destroy()
				top_window = save_top_window
				return self.xml_node
			elif ret == gtk.RESPONSE_REJECT :
				dialog.destroy()
				top_window = save_top_window
				return self.first_page_update_run()
			else :
				dialog.destroy()
				top_window = save_top_window
				return None

	def run(self) :
		if self.current_page == None :
			ret = self.first_page_init_run()
		elif self.current_page == 0 :
			ret = self.first_page_update_run()
		else :
			ret = self.last_page()

		return ret

	def destroy(self) :
		#global top_window
		#self.dialog.destroy()
		#top_window = self.save_top_window
		pass

class ObjectViewDlg :
	def __init__(self, xml_node, is_newobj = False) :
		self.xml_node = xml_node

		global top_window

		if is_newobj :
			title_prefix = _("Add")
		else :
			title_prefix = _("Edit")

		title = title_prefix + " " + _(name_cap(xml_node.tagName))
		dialog = gtk.Dialog(title, top_window, gtk.DIALOG_MODAL,
			(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL, str(_("Reset")), gtk.RESPONSE_APPLY, gtk.STOCK_OK, gtk.RESPONSE_OK))
		dialog.set_border_width(5)
		dialog.set_type_hint(gtk.gdk.WINDOW_TYPE_HINT_NORMAL)
		dialog.set_default_response(gtk.RESPONSE_OK)
		self.dialog = dialog

		obj_view = ObjectView(self.xml_node, is_newobj, self.on_changed)
		self.obj_view = obj_view
		dialog.vbox.pack_start(obj_view.widget)
		dialog.vbox.show()
		dialog.set_response_sensitive(gtk.RESPONSE_APPLY, False)

		self.save_top_window = top_window
		top_window = dialog

	def run(self) :
		while True :
			ret = self.dialog.run()
			if ret in [gtk.RESPONSE_CANCEL, gtk.RESPONSE_DELETE_EVENT] :
				self.obj_view.reset()
				self.destroy()
				return None
			elif ret == gtk.RESPONSE_APPLY :
				self.on_reset()
			else :
				passed = self.obj_view.validate()
				if passed :
					return self.obj_view.xml_node

	def destroy(self) :
		global top_window
		self.dialog.destroy()
		top_window = self.save_top_window

	def on_changed(self) :
		self.dialog.set_response_sensitive(gtk.RESPONSE_APPLY, True)

	def on_reset(self) :
		ret = confirmbox(_("This will reset the current object attributes and all sub-objects to the initial configurations."),
				(gtk.STOCK_NO, gtk.RESPONSE_NO, gtk.STOCK_YES, gtk.RESPONSE_YES),
				_("Reset the configurations?"))
		if ret == gtk.RESPONSE_YES :
			self.obj_view.reset()
			self.obj_view.update()
			self.dialog.set_response_sensitive(gtk.RESPONSE_APPLY, False)

class TransitionInfoDlg :
	def __init__(self) :
		global top_window
		self.G = None
		dialog = gtk.Dialog(_("Transition Information"), top_window, gtk.DIALOG_MODAL,
			(gtk.STOCK_HELP, gtk.RESPONSE_HELP, gtk.STOCK_CLOSE, gtk.RESPONSE_CLOSE, 
			gtk.STOCK_SAVE, gtk.RESPONSE_APPLY))
		dialog.set_type_hint(gtk.gdk.WINDOW_TYPE_HINT_NORMAL)
		dialog.set_default_size(750, 550)

		hbox = gtk.HBox()
		label = gtk.Label(_("Transition") + _(":"))
		label.set_alignment(0, 0.5)
		hbox.pack_start(label, False, padding=2)

		self.live_radio_btn = gtk.RadioButton(None, _("Live"))
		self.live_radio_btn.set_active(True)
		hbox.pack_start(self.live_radio_btn, False, padding=2)

		history_radio_btn = gtk.RadioButton(self.live_radio_btn, _("History") + _(":"))
		hbox.pack_start(history_radio_btn, False, padding=2)

		self.search_btn = gtk.Button(stock=gtk.STOCK_FIND)
		self.search_btn.set_sensitive(False)
		hbox.pack_start(self.search_btn, False, padding=2)

		store = gtk.ListStore(str, str)
		self.combo_entry = gtk.ComboBoxEntry(store)
		cell = gtk.CellRendererText()
		self.combo_entry.pack_start(cell, True)
		self.combo_entry.set_sensitive(False)
		self.combo_entry.add_attribute(cell, 'text', 1)
		hbox.pack_start(self.combo_entry, True, padding=2)

		self.refresh_btn = gtk.Button(stock=gtk.STOCK_REFRESH)
		hbox.pack_start(self.refresh_btn, False, padding=2)

		dialog.vbox.pack_start(hbox, False, padding=2)

		self.summary_label = gtk.Label()
		self.summary_label.set_alignment(0, 0.5)
		dialog.vbox.pack_start(self.summary_label, False, padding=5)

		notebook = gtk.Notebook()
		dialog.vbox.pack_start(notebook, True)
		self.notebook = notebook

		vbox = gtk.VBox()
		tab_label = gtk.Label(_("Graph"))
		notebook.append_page(vbox, tab_label)

		sw = gtk.ScrolledWindow()
		sw.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
		vbox.pack_start(sw, True)

		self.image = gtk.Image()
		sw.add_with_viewport(self.image)

		vbox = gtk.VBox()
		tab_label = gtk.Label(_("Detail"))
		notebook.append_page(vbox, tab_label)

		hbox = gtk.HBox()
		label = gtk.Label(_("Verbosity") + _(":"))
		hbox.pack_start(label, False, padding=2)

		default_verbosity = 0
		adj = gtk.Adjustment(default_verbosity, 0, 99, 1, 5)
		self.detail_spin_btn = gtk.SpinButton(adj, 0, 0)
		self.detail_spin_btn.set_width_chars(2)
		self.detail_spin_btn.set_wrap(True)
		hbox.pack_start(self.detail_spin_btn, False, padding=2)

		self.detail_refresh_btn = gtk.Button(stock=gtk.STOCK_REFRESH)
		hbox.pack_start(self.detail_refresh_btn, False, padding=2)

		vbox.pack_start(hbox, False, padding=2)

		sw = gtk.ScrolledWindow()
		sw.set_shadow_type(gtk.SHADOW_IN)
		sw.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
		vbox.pack_start(sw, True)

		self.pe_detail_text = gtk.TextView()
		#self.pe_detail_text.set_wrap_mode(gtk.WRAP_WORD)
		self.pe_detail_text.set_property("editable", False)
		self.pe_detail_textbuffer = self.pe_detail_text.get_buffer()
		sw.add(self.pe_detail_text)

		vbox = gtk.VBox()
		tab_label = gtk.Label(_("Scores"))
		notebook.append_page(vbox, tab_label)

		sw = gtk.ScrolledWindow()
		sw.set_shadow_type(gtk.SHADOW_IN)
		sw.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
		vbox.pack_start(sw, True)

		self.pe_scores_text = gtk.TextView()
		#self.pe_scores_text.set_wrap_mode(gtk.WRAP_WORD)
		self.pe_scores_text.set_property("editable", False)
		self.pe_scores_textbuffer = self.pe_scores_text.get_buffer()
		sw.add(self.pe_scores_text)

		self.live_radio_btn.connect("activate", self.on_refresh)
		history_radio_btn.connect("toggled", self.on_radio_changed)
		history_radio_btn.connect("activate", self.on_refresh)
		self.search_btn.connect("clicked", self.on_search)
		self.combo_entry.connect("changed", self.on_value_changed)
		self.combo_entry.child.connect("activate", self.on_refresh)
		self.refresh_btn.connect("clicked", self.on_refresh)
		self.detail_spin_btn.connect("value-changed", self.on_detail_value_changed)
		self.detail_refresh_btn.connect("clicked", self.on_detail_refresh)

		self.on_refresh()

		dialog.show_all()

		if not support_gv :
			notebook.get_nth_page(0).hide_all()

		save_top_window = top_window
		top_window = dialog

		while True :
			ret = dialog.run()
			if ret == gtk.RESPONSE_APPLY :
				self.save_transition_info()
			elif ret == gtk.RESPONSE_HELP :
				self.show_help()
			else :
				break

		if support_gv and self.G != None :
			gv.rm(self.G)

		dialog.destroy()
		top_window = save_top_window

	def on_radio_changed(self, radio_btn) :
		radio_active = radio_btn.get_active()
		self.search_btn.set_sensitive(radio_active)
		self.combo_entry.set_sensitive(radio_active)

		self.refresh_btn.set_sensitive(True)

	def on_value_changed(self, combo_entry) :
		self.refresh_btn.set_sensitive(True)

	def on_search(self, search_btn) :
		rpdlg = TimeFrameDlg()
		pe_params = rpdlg.set_params(_("Transitions"), (True, True, True, False))
		if pe_params == None :
			return

		if pe_params.get("ftime") != None :
			pe_params["ftime"] = int(time.mktime(pe_params["ftime"]))
		if pe_params.get("ttime") != None :
			pe_params["ttime"] = int(time.mktime(pe_params["ttime"]))

		input_info_list = self.get_pe_inputs(pe_params.get("ftime", ""), pe_params.get("ttime", ""))
		if input_info_list == None :
			return

		show_len = 30
		late_len = 27
		early_len = show_len - late_len

		store = gtk.ListStore(str, str)
		if len(input_info_list) > show_len :
			for input_info in input_info_list[:late_len] :
				store.append(input_info)
			omit_len = len(input_info_list) - show_len
			store.append(["", _("[Omitted %d transitions...]")%omit_len])
			for input_info in input_info_list[-early_len:] :
				store.append(input_info)
		else :
			for input_info in input_info_list :
				store.append(input_info)
		self.combo_entry.set_model(store)

	def get_pe_inputs(self, ftime, ttime) :
		cmd = "get_pe_inputs\n%s\n%s"%(ftime, ttime)

		input_info = window.do_cmd_with_pbar(cmd, _("Transitions"),
				_("Searching the transitions may take a while,") + "\n"
				+ _("depending on the number of transitions..."),
				_("Cannot find any transition record"))

		if input_info == None :
			return None

		input_dict = {}
		for i in range(len(input_info)) :
			input_list = input_info[i].split()
			j = 0
			while j < len(input_list) :
				time_stamp = float(input_list[j+1])
				if not input_dict.has_key(time_stamp) :
					input_dict[time_stamp] = []
				input_dict[time_stamp].append(input_list[j])
				j += 2

		input_time_list = input_dict.keys()
		input_time_list.sort(reverse = True)

		input_info_list = []
		for i in range(len(input_time_list)) :
			input_time = input_time_list[i]

			input_files = input_dict[input_time]
			input_files.sort()
			for input_file in input_files :
				input_id = os.path.splitext(input_file)[0]
				info_text = time.ctime(input_time)
				input_info_list.append([input_id, info_text])

		return input_info_list

	def on_detail_value_changed(self, spin_btn) :
		self.detail_refresh_btn.set_sensitive(True)

	def on_refresh(self, btn=None) :
		pe_input = self.get_pe_input_id()
		if pe_input == None :
			return

		pe_summary = manager.do_cmd("get_pe_summary\n%s\n%s"%(pe_input[0], pe_input[1]))
		if pe_summary == None or len(pe_summary) < 1 :
			msgbox(_("The specified transition doesn't exist"))
			return

		if pe_input[0] == "live" :
			label_text = "Live"
		else :
			label_text = "-".join(pe_input)

		time_str = time.ctime(float(pe_summary[0]))
		label_text +=  "  (" + time_str + ")"
		self.summary_label.set_markup('<b>' + label_text + '</b>')

		self.show_pe_graph(pe_input)
		self.show_pe_detail(pe_input)
		self.show_pe_scores(pe_input)
		self.refresh_btn.set_sensitive(False)
		self.detail_refresh_btn.set_sensitive(False)

	def on_detail_refresh(self, btn=None) :
		pe_input = self.get_pe_input_id_label()
		if pe_input == None :
			return

		self.show_pe_detail(pe_input)
		self.detail_refresh_btn.set_sensitive(False)

	def get_pe_input_id(self) :
		if self.live_radio_btn.get_active() :
			pe_input = ("live", "")
		else :
			pe_series = ["error", "warn", "input"]
			error_str = _("Please specify a proper identity of a transition") + _(".") + "\n" \
					+ _("Such as") + _(":")  \
					+ "\"pe-error-100\", \"warn-36\", \"input 62\", \"pe-error-45.bz2\"..." + "\n" \
					+ _("Transition type: \"error\", \"warn\" or \"input\"")
			pe_str = self.combo_entry.child.get_text()
			if len(pe_str) == 0 :
				msgbox(error_str)
				return None
				
			pe_str_lower = pe_str.lower()
			for pe_type in pe_series :
				if pe_str_lower.count(pe_type) :
					break
			else :
				msgbox(error_str)
				return None

			pe_num = extract_int(pe_str)
			if pe_num == None :
				msgbox(error_str)
				return None

			pe_input = ("pe-" + pe_type, pe_num)

		return pe_input

	def get_pe_input_id_label(self) :
		summary_text = self.summary_label.get_text()
		pe_input_id = summary_text.split("(")[0].rstrip()
		if pe_input_id == "Live" :
			pe_input = ("live", "")
		elif pe_input_id.startswith("pe-") :
			id_split = pe_input_id.split("-")
			if len(id_split) == 3 :
				pe_input = (id_split[0] + "-" + id_split[1], id_split[2])
			else :
				pe_input = None
		else :
			pe_input = None

		return pe_input

	def show_pe_graph(self, pe_input) :
		if not support_gv :
			return

		if self.G != None :
			gv.rm(self.G)
			self.G = None
		self.image.clear()
		graph_str = self.gen_pe_graph(pe_input)
		if graph_str != None :
			G = gv.readstring(graph_str)
			gv.layout(G, "dot")
			try :
				(fd, tmp_png) = tempfile.mkstemp(suffix=".png")
			except IOError, msg :
				msgbox(_("I/O error") + _(": ") + str(msg))
				return
			os.close(fd)
			gv.render(G, "png", tmp_png)
			self.G = G
			self.image.set_from_file(tmp_png)
			os.unlink(tmp_png)
		self.graph_str = graph_str

	def gen_pe_graph(self, pe_input) :
		cmd = "gen_pe_graph\n%s\n%s"%(pe_input[0], pe_input[1])
		graph_lines = window.do_cmd_with_pbar(cmd, _("Transition Graph"),
				_("Generating the transition graph may take a while..."),
				_("Failed to generate the transition graph"))
		if graph_lines == None :
			return None

		graph_str = "\n".join(graph_lines)
		return graph_str

	def show_pe_detail(self, pe_input) :
		verbosity = int(self.detail_spin_btn.get_value())

		self.pe_detail_textbuffer.set_text("")

		cmd = "gen_pe_info\n%s\n%s\n%s"%(pe_input[0], pe_input[1], verbosity)
		detail_lines = window.do_cmd_with_pbar(cmd, _("Transition Detail"),
				_("Generating the transition detail may take a while..."),
				_("Failed to generate the transition detail"))
		if detail_lines == None :
			return

		detail_str = "\n".join(detail_lines)

		self.pe_detail_textbuffer.set_text(detail_str)

	def show_pe_scores(self, pe_input) :
		self.pe_scores_textbuffer.set_text("")

		cmd = "gen_pe_info\n%s\n%s\nscores"%(pe_input[0], pe_input[1])
		scores_lines = window.do_cmd_with_pbar(cmd, _("Transition Scores"),
				_("Generating the transition scores may take a while..."),
				_("Failed to generate the transition scores"))
		if scores_lines == None :
			return
		scores_str = "\n".join(scores_lines)

		self.pe_scores_textbuffer.set_text(scores_str)

	def save_transition_info(self) :
		page_num = self.notebook.get_current_page()
		if page_num == 0 :
			if not support_gv :
				msgbox(_("Cannot save the graph for specified transition"))
				return
			default_name = "pe-graph.png"
			filter_list = ((_("PNG Image"), ("*.png",)),
					(_("JPEG Image"), ("*.jpg", "*.jpeg", "*.jpe")),
					(_("GIF Image"), ("*.gif",)),
					(_("TIFF Image"), ("*.tiff", "*.tif")),
					(_("Dot File"), ("*.dot",)),
					)
		elif page_num == 1 :
			default_name = "pe-detail"
			filter_list = None
		else:
			default_name = "pe-scores"
			filter_list = None

		sfdlg = SelectFileDlg()
		(save_file, save_type) = sfdlg.select_file(default_name, filter_list)
		if save_file == None :
			return

		save_str = None
		if page_num == 0 :
			for (filter_name, filter_pattern) in filter_list :
				if filter_name == save_type :
					format = filter_pattern[0][2:]
					if format != "dot" :
						gv.render(self.G, format, save_file)
						return
					else :
						save_str = self.graph_str
					break
		elif page_num == 1 :
			save_str = self.pe_detail_textbuffer.get_text(*self.pe_detail_textbuffer.get_bounds())
		else :
			save_str = self.pe_scores_textbuffer.get_text(*self.pe_scores_textbuffer.get_bounds())

		if save_str == None :
			msgbox(_("Cannot save the information for specified transition"))
			return

		try :
			fd = os.open(save_file, os.O_RDWR|os.O_CREAT|os.O_TRUNC, 0644)
		except OSError, msg :
			msgbox(_("System error") + _(": ") + str(msg))
			return

		try :
			os.write(fd, save_str)
		except OSError, msg :
			msgbox(_("System error") + _(": ") + str(msg))
			os.close(fd)
			return
		os.close(fd)

	def show_help(self) :
		global top_window

		help_str = _("""Interpreting the graph:
* Arrows indicate ordering dependancies
* Dashed-arrows indicate dependancies that are not present in the transition graph
* Actions with a dashed border of any color do not form part of the transition graph
* Actions with a green border form part of the transition graph
* Actions with a red border are ones the cluster would like to execute but are unrunnable
* Actions with a blue border are ones the cluster does not feel need to be executed
* Actions with orange text are pseudo/pretend actions that the cluster uses to simplify the graph
* Actions with black text are sent to the LRM
* Resource actions have text of the form {rsc}_{action}_{interval} {node}
* Any action depending on an action with a red border will not be able to execute.
* Loops are really bad. Please report them to the development team.""")

		dialog = gtk.Dialog("Help", top_window, gtk.DIALOG_MODAL,
				(gtk.STOCK_CLOSE, gtk.RESPONSE_CLOSE))
		dialog.set_type_hint(gtk.gdk.WINDOW_TYPE_HINT_NORMAL)
		dialog.set_size_request(590, 270)
		dialog.set_default_response(gtk.RESPONSE_CLOSE)

		sw = gtk.ScrolledWindow()
		sw.set_shadow_type(gtk.SHADOW_IN)
		sw.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
		dialog.vbox.pack_start(sw, True)

		help_text = gtk.TextView()
		#help_text.set_wrap_mode(gtk.WRAP_WORD)
		help_text.set_property("editable", False)
		help_textbuffer = help_text.get_buffer()
		help_textbuffer.set_text(help_str)
		sw.add(help_text)

		dialog.show_all()
		save_top_window = top_window
		top_window = dialog

		dialog.run()
		dialog.destroy()
		top_window = save_top_window

class TimeFrameDlg :
	def set_params(self, title, (from_chkbtn, from_sensitive, to_chkbtn, to_sensitive)) :
		global top_window
		dialog = gtk.Dialog(title, top_window, gtk.DIALOG_MODAL,
			(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL, gtk.STOCK_OK, gtk.RESPONSE_OK))
		dialog.set_border_width(5)
		dialog.set_default_response(gtk.RESPONSE_OK)
		self.dialog = dialog

		current_time = time.time()
		from_time = time.localtime(current_time - 1800)
		to_time = time.localtime(current_time)

		fdatetime = self.render_time_widgets("<b>"+_("From")+"</b>", from_time, from_chkbtn, from_sensitive)
		tdatetime = self.render_time_widgets("<b>"+_("To")+"</b>", to_time, to_chkbtn, to_sensitive)

		save_top_window = top_window
		top_window = dialog
		dialog.show_all()

		while True :
			ret = dialog.run()
			if ret in [gtk.RESPONSE_CANCEL, gtk.RESPONSE_DELETE_EVENT] :
				top_window = save_top_window
				dialog.destroy()
				return None
			else :
				if fdatetime.time_hbox.get_property("sensitive") :
					ftime = fdatetime.get_time() 
				else :
					ftime = None

				if tdatetime.time_hbox.get_property("sensitive") :
					ttime = tdatetime.get_time()
				else :
					ttime = None

				passed = True
				if ftime != None and ttime != None and time.mktime(ftime) > time.mktime(ttime) :
					msgbox(_("The \"From\" time should before the \"To\" one"))
					passed = False

				if passed :
					params = {}
					if ftime != None :
						params["ftime"] = ftime
					if ttime != None :
						params["ttime"] = ttime

					top_window = save_top_window
					dialog.destroy()
					return params

	def render_time_widgets(self, label, default_time, chkbtn, sensitive) :
		time_label = gtk.Label()
		time_label.set_markup(_(label))
		time_label.set_alignment(0, 0.5)
		
		datetime = DateTime(default_time)

		if chkbtn :
			time_checkbutton = gtk.CheckButton()
			time_checkbutton.add(time_label)
			if sensitive :
				time_checkbutton.set_active(True)
			time_checkbutton.connect("toggled", self.on_checkbutton_toggled, datetime.time_hbox)
			self.dialog.vbox.pack_start(time_checkbutton, False, padding=2)
		else :
			self.dialog.vbox.pack_start(time_label, False, padding=2)

		datetime.time_hbox.set_sensitive(sensitive)
		self.dialog.vbox.pack_start(datetime.time_hbox, False, padding=2)

		return datetime

	def on_checkbutton_toggled(self, widget, hbox) :
		hbox.set_sensitive(widget.get_active())

class SelectFileDlg :
	def select_file(self, orig_filename = None, filter_list = None) :
		global top_window
		file_dialog = gtk.FileChooserDialog(_("Save as ..."), None, 
				gtk.FILE_CHOOSER_ACTION_SAVE,
				(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL,
				gtk.STOCK_SAVE, gtk.RESPONSE_OK))
		if orig_filename != None :
			file_dialog.set_current_name(orig_filename)

		save_top_window = top_window
		top_window = file_dialog

		if filter_list != None :
			for (filter_name, filter_patterns) in filter_list :
				filter = gtk.FileFilter()
				filter.set_name(filter_name)
				for filter_pattern in filter_patterns :
					filter.add_pattern(filter_pattern)
				file_dialog.add_filter(filter)

		while True :
			ret = file_dialog.run()
			if ret in [gtk.RESPONSE_CANCEL, gtk.RESPONSE_DELETE_EVENT] :
				top_window = save_top_window
				file_dialog.destroy()
				return (None, None)
			else :
				save_folder = file_dialog.get_current_folder()
				save_file = file_dialog.get_filename()
				passed = True
				try :
					if not os.access(save_folder, os.R_OK | os.W_OK | os.X_OK) :
						msgbox(_("Permission denied") + (": ") + save_folder)
						passed = False
						continue
					if os.access(save_file, os.F_OK) :
						retval = confirmbox(_("A file with the same name already exists") +_(": ")
								+ os.path.basename(save_file) + "\n"
								+_("Do you want to overwrite it?"),
								(gtk.STOCK_NO, gtk.RESPONSE_NO,
								gtk.STOCK_YES, gtk.RESPONSE_YES),
								_("Replace it?"))
						if retval in [gtk.RESPONSE_NO, gtk.RESPONSE_DELETE_EVENT] :
							passed = False
							continue
							
				except OSError, msg :
					msgbox(_("System error") + _(": ") + str(msg))
					passed = False

				if passed :
					top_window = save_top_window
					if filter_list != None :
						save_type = file_dialog.get_filter().get_name()
					else :
						save_type = None
					file_dialog.destroy()
					return (save_file, save_type)

class DateTime:
	def __init__(self, default_time) :
		time_hbox = gtk.HBox()

		time_date = gtk.Entry()
		time_date.set_width_chars(10)
		time_date.set_editable(False)
		time_date.set_activates_default(True)
		time_hbox.pack_start(time_date, False)

		time_cal_window = gtk.Window(gtk.WINDOW_POPUP)
		time_cal = gtk.Calendar()
		time_cal_window.add(time_cal)
		
		time_cal_button = gtk.ToggleButton()
		arrow = gtk.Arrow(gtk.ARROW_DOWN, gtk.SHADOW_OUT)
		time_cal_button.add(arrow)
		time_cal_button.connect("toggled", self.on_toggled, time_cal_window)
		time_hbox.pack_start(time_cal_button, False)

		time_cal_window.connect("button-press-event", self.on_button_press, time_cal_button)
		time_cal_window.connect("key-press-event", self.on_key_press, time_cal_button)

		time_cal.connect("day-selected", self.on_day_selected, time_date)

		time_cal.select_month(default_time[1]-1, default_time[0])
		time_cal.select_day(default_time[2])

		space = gtk.Label(" ")
		time_hbox.pack_start(space, False)

		time_hr_adj = gtk.Adjustment(default_time[3], 00, 23, 1, 4)
		time_hr = gtk.SpinButton(time_hr_adj, 0, 0)
		time_hr.set_width_chars(2)
		time_hr.set_wrap(True)
		time_hbox.pack_start(time_hr, False)

		time_colon = gtk.Label(":")
		time_hbox.pack_start(time_colon, False)

		time_min_adj = gtk.Adjustment(default_time[4], 00, 59, 1, 5)
		time_min = gtk.SpinButton(time_min_adj, 0, 0)
		time_min.set_width_chars(2)
		time_min.set_wrap(True)
		time_hbox.pack_start(time_min, False)
		
		time_colon = gtk.Label(":")
		time_hbox.pack_start(time_colon, False)

		time_sec_adj = gtk.Adjustment(default_time[5], 00, 59, 1, 5)
		time_sec = gtk.SpinButton(time_sec_adj, 0, 0)
		time_sec.set_width_chars(2)
		time_sec.set_wrap(True)
		time_hbox.pack_start(time_sec, False)

		time_widgets = {}
		self.time_date = time_date
		self.time_hr = time_hr
		self.time_min = time_min
		self.time_sec = time_sec
		self.time_hbox = time_hbox

	def on_toggled(self, widget, cal_window) :
		if widget.get_active() :
			self.cal_popup(widget, cal_window)
		else :
			self.cal_hide(widget, cal_window)

	def cal_popup(self, widget, cal_window) :
		(x, y) = widget.get_parent_window().get_position()
		x += widget.allocation.x
		y += widget.allocation.y + widget.allocation.height
		cal_window.grab_add()
		cal_window.move(x, y)
		cal_window.grab_focus()
		cal_window.show_all()

		if gtk.gdk.pointer_grab(cal_window.window, True,
			gtk.gdk.BUTTON_PRESS_MASK | gtk.gdk.BUTTON_RELEASE_MASK | gtk.gdk.POINTER_MOTION_MASK,
			None, None, 0L) == gtk.gdk.GRAB_SUCCESS :
			if (gtk.gdk.keyboard_grab (cal_window.window, True, 0L) != 0):
				gtk.gdk.pointer_ungrab(0L)

	def cal_hide(self, widget, cal_window) :
		cal_window.hide()
		cal_window.grab_remove()
		gtk.gdk.pointer_ungrab(0L)
		gtk.gdk.keyboard_ungrab(0L)

	def on_button_press(self, cal_window, event, button) :
		button.set_active(False)
				
	def on_key_press(self, cal_window, event, button) :
		if event.keyval == gtk.keysyms.Escape :
			button.set_active(False)
		else :
			gtk.gdk.keyboard_grab (cal_window.window, True, 0L)

	def on_day_selected(self, cal_window, date_entry) :
		(year, month, day) = cal_window.get_date()
		mytime = time.mktime((year, month+1, day, 0, 0, 0, 0, 0, -1))
		localtime = time.strftime("%Y-%m-%d", time.localtime(mytime))
		date_entry.set_text(localtime)
		#date_entry.set_text("%d-%02d-%02d"%(year, month+1, day))

	def get_time(self) :
		datetime = time.strptime("%s %02d:%02d:%02d"%(self.time_date.get_text(),
							self.time_hr.get_value(),
							self.time_min.get_value(),
							self.time_sec.get_value()), "%Y-%m-%d %H:%M:%S")
		return datetime

class ProgressPulse :
	def __init__(self, title, msg, pulse_msg, button=(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL), destroy_condition = None) :
		global top_window
		self.destroy_condition = destroy_condition

		dialog = gtk.Dialog(title, top_window, gtk.DIALOG_MODAL, button)
		dialog.set_border_width(5)
		if msg != None :
			label = gtk.Label(msg)
			dialog.vbox.pack_start(label, False, padding=2)
		self.pbar = gtk.ProgressBar()
		if pulse_msg != None :
			self.pbar.set_text(pulse_msg)
		self.timer = gobject.timeout_add(100, self.pulse)
		dialog.vbox.pack_start(self.pbar, False, padding=2)
		dialog.show_all()

		self.save_top_window = top_window
		self.dialog = dialog

	def pulse(self) :
		if self.destroy_condition != None and self.destroy_condition() :
			self.destroy()
			return False
		else :
			self.pbar.pulse()
			return True

	def destroy(self) :
		global top_window
		top_window = self.save_top_window
		self.dialog.destroy()
		gobject.source_remove(self.timer)

	def run(self) :	
		ret = self.dialog.run()
		self.destroy()
		return ret

class DesReportDlg:
	def __init__(self, des_file_lines) :
		global top_window
		self.des_file_lines = des_file_lines

		dialog = gtk.Dialog(_("Description of Cluster Report"), top_window, gtk.DIALOG_MODAL,
				(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL, gtk.STOCK_OK, gtk.RESPONSE_OK))
		dialog.set_type_hint(gtk.gdk.WINDOW_TYPE_HINT_NORMAL)
		dialog.set_border_width(5)

		entries = {}
		combo_entries = {}
		name_labels = []

		for line in des_file_lines :
			if line.startswith("Severity: [choose one] ") :
				options =  line.replace("Severity: [choose one] ", "").split()
				hbox = gtk.HBox()
				label = gtk.Label(_("Severity") + _(":"))
				label.set_alignment(0, 0.5)
				hbox.pack_start(label, False)
				name_labels.append(label)
				
				combo_entry = gtk.combo_box_entry_new_text()
				combo_entry.append_text("")
				for option in options :
					combo_entry.append_text(option)
				hbox.pack_start(combo_entry)
				dialog.vbox.pack_start(hbox, False, padding=1)
				combo_entries["severity"] = combo_entry 
			elif line.startswith("Component: [choose one] ") :
				options = line.replace("Component: [choose one] ", "").split()
				hbox = gtk.HBox()
				label = gtk.Label(_("Component") + _(":"))
				label.set_alignment(0, 0.5)
				hbox.pack_start(label, False)
				name_labels.append(label)
				
				combo_entry = gtk.combo_box_entry_new_text()
				combo_entry.append_text("")
				for option in options :
					combo_entry.append_text(option)
				hbox.pack_start(combo_entry)
				dialog.vbox.pack_start(hbox, False, padding=1)
				combo_entries["component"] = combo_entry
			elif line.startswith("Subject:") :
				hbox = gtk.HBox()
				label = gtk.Label(_("Subject") + _(":"))
				label.set_alignment(0, 0.5)
				name_labels.append(label)
				hbox.pack_start(label, False)
				entry = gtk.Entry()
				hbox.pack_start(entry)
				dialog.vbox.pack_start(hbox, False, padding=1)
				entries["subject"] = entry
			elif line.startswith("Detailed description:") :
				label = gtk.Label(_("Detailed description") + _(":"))
				label.set_alignment(0, 0.5)
				dialog.vbox.pack_start(label, False, padding=1)

				sw = gtk.ScrolledWindow()
				sw.set_shadow_type(gtk.SHADOW_IN)
				sw.set_border_width(5)
				sw.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
				des_text = gtk.TextView()
				des_text.set_wrap_mode(gtk.WRAP_WORD)
				self.des_textbuffer = des_text.get_buffer()
				sw.add(des_text)
				dialog.vbox.pack_start(sw, padding=1)
			elif not line.startswith("[...]") and not line.startswith("---") :
				label = gtk.Label(line.replace("\n", ""))
				label.set_alignment(0, 0.5)
				label.set_selectable(True)
				dialog.vbox.pack_start(label, False, padding=1)

		name_label_max_len = 0
		for name_label in name_labels :
			name_label_len = name_label.size_request()[0]
			if name_label_len >  name_label_max_len :
				name_label_max_len = name_label_len
		for name_label in name_labels :
			name_label.set_size_request(name_label_max_len, -1)

		widgets = {}
		widgets["entries"] = entries
		widgets["combo_entries"] = combo_entries
		self.widget_group = WidgetGroup(widgets)

		dialog.show_all()
		self.dialog = dialog
		self.save_top_window = top_window

	def run(self) :
		global top_window
		des_file_lines  = self.des_file_lines
		ret = self.dialog.run()
		if ret in [gtk.RESPONSE_CANCEL, gtk.RESPONSE_DELETE_EVENT] :
			top_window = self.save_top_window
			self.dialog.destroy()
			return None
		else :
			fields = self.widget_group.get_values()
			detailed_des = self.des_textbuffer.get_text(*self.des_textbuffer.get_bounds())
			new_file_lines = []
			for i in range(len(des_file_lines)) :
				if des_file_lines[i].startswith("Severity: [choose one] ") :
					des_file_lines[i] = "Severity: %s\n"%fields.get("severity", "")
				elif des_file_lines[i].startswith("Component: [choose one] ") :
					des_file_lines[i] = "Component: %s\n"%fields.get("component", "")
				elif des_file_lines[i].startswith("Subject:") :
					des_file_lines[i] = "Subject: %s\n"%fields.get("subject", "")
				elif des_file_lines[i-2].startswith("Detailed description:") :
					des_file_lines[i] = detailed_des + "\n"
			top_window = self.save_top_window
			self.dialog.destroy()
			return des_file_lines 

class MainWindow :
	'''
	Main UI window to show information to user and get users input
	'''
	win_widget = None
	actiongroup = None
	uimanager = None
	cur_type = None
	cur_status = None
	cur_name = None
	cur_view = None
	statusbar = None
	view_status = {}
	
	# utility functions
	def set_action_sensitive(self, action, sensitive) :
		if self.actiongroup.get_action(action) != None :
			self.actiongroup.get_action(action).set_property("sensitive", sensitive)
		elif self.radio_tool_action_group.get_action(action) != None :
			self.radio_tool_action_group.get_action(action).set_property("sensitive", sensitive)

	# system event handler
	def on_delete_event(self, widget, event, data=None) :
		self.do_quit(None)
		return False
	
	def update_ui(self) :
		self.set_action_sensitive('logout',manager.connected)
		self.set_action_sensitive('login',not manager.connected)

		self.set_action_sensitive('transition-info', manager.connected)
		self.set_action_sensitive('report', manager.connected)

		for action in ["new", "reset", "delete", "commit", "switch"] :
			self.set_action_sensitive(action, manager.connected)
		self.set_action_sensitive("diff", manager.connected and manager.active_cib != None and manager.active_cib != "")

	# functions
	def update(self) :
		self.maintree.update()
		self.statusbar.pop(2)

		window.statusbar.pop(1)
		if manager.connected :
			status_str = _("Connected to ") + manager.username + "@" + manager.server
		else :
			status_str = _("Not connected")
		if mode_level == 0 :
			status_str += " " + _("(") + _("Simple Mode") +_(")")
		elif mode_level == 1 :
			status_str += " " + _("(") + _("Expert Mode") +_(")")
		else :
			status_str += " " + _("(") + _("Hack Mode") +_(")")
		window.statusbar.push(1, status_str)

		self.update_ui()

		return False

	def can_change_view(self) :
		if not self.cur_view.changed :
			return True
		ret = confirmbox(_("The data of current view have been changed.")+"\n"+_("Apply the changes?"),
			(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL,
			gtk.STOCK_NO, gtk.RESPONSE_NO,
			gtk.STOCK_YES, gtk.RESPONSE_YES)) 
		if ret == gtk.RESPONSE_YES :
			self.cur_view.on_apply(self.cur_view.widget)
			return True
		if ret == gtk.RESPONSE_NO :
			return True
		return False

	def select_view(self, type, name = None, status = None) :
		for child in self.mainview_sw.get_children() :
			self.mainview_sw.remove(child)

		if self.view_status.get(type) != None :
			last_show_mode = self.view_status[type][0]
		else :
			last_show_mode = 0

		self.cur_type, self.cur_name, self.cur_status = type, name, status
		self.update_ui()
		if type == "configuration" :
			self.cur_view = ClusterView()
		elif type == "crm_config" and mode_level == 0 :
			self.cur_type = "crm_config_simple"
			self.cur_view = CRMConfigView()
			if not self.cur_view.update() :
				return
		elif type in ["crm_config", "nodes", "resources", "constraints", "status", "rsc_defaults", "op_defaults", "acls", "fencing-topology"] \
				and manager.xml_nodes["cib"].getElementsByTagName(type) != [] :
			self.cur_view = ObjectView(manager.xml_nodes["cib"].getElementsByTagName(type)[0],
					is_topview = True, show_mode = last_show_mode)
		elif type in ["rsc_defaults", "op_defaults", "acls", "fencing-topology"] \
				and manager.xml_nodes["cib"].getElementsByTagName(type) == [] :
			self.cur_view = ObjectView(type, is_topview = True, missing_opt_obj_parent_type = "configuration",
					show_mode = last_show_mode)
		elif type == "management" :
			self.cur_view = ManageView()
		else :
			self.cur_view = None
			return

		self.mainview_sw.add_with_viewport(self.cur_view.widget)
		#self.cur_view.on_after_show()
		if self.view_status.get(self.cur_type) != None :
			self.cur_view.restore_status(self.view_status[self.cur_type])

	def do_cmd_with_pbar(self, cmd, title, msg, failed_msg, show_msgbox = True) :
		manager.async_do_cmd(cmd)
		pbar = ProgressPulse(title, msg, None, None,
				lambda : manager.async_ret_list.has_key(cmd))
		ret = pbar.run()
		if ret in [gtk.RESPONSE_CANCEL, gtk.RESPONSE_DELETE_EVENT] :
			return None

		manager.async_ret_lock.acquire()
		if manager.async_ret_list.has_key(cmd) :
			ret_list = manager.async_ret_list.pop(cmd)
		else :
			ret_list = None
		manager.async_ret_lock.release()

		if manager.failed_reason != "" :
			if show_msgbox :
				msgbox(manager.failed_reason)
			return None
		elif len(ret_list) < 1 :
			if show_msgbox :
				msgbox(failed_msg + _(": ") + _("Empty information returned"))
			return None
		elif ret_list == None :
			if show_msgbox :
				msgbox(failed_msg + _(": ") + _("Nothing returned"))
			return None

		return ret_list
			
	# ui event handler	
	def on_quit(self, action) :
		if confirmbox(_("Do you want to quit ?")) == gtk.RESPONSE_YES :
			self.do_quit(action)

	def do_quit(self, action) :
		manager.save_profile()

		if manager.connected :
			self.confirm_record_pending()
		gtk.main_quit()
	
	def on_login(self, action) :
		dialog = gtk.Dialog(_("Login"),self.win_widget, gtk.DIALOG_MODAL,
			(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL, gtk.STOCK_OK, gtk.RESPONSE_OK))
		dialog.set_default_response(gtk.RESPONSE_OK)
		dialog.set_border_width(5)
		
		server = manager.profile["server"]
		user = manager.profile["user"]

		widgets = {}
		name_labels = []
		name_label_max_len = 0
		for key in ["server(:port)", "user_name", "password"] :
			hbox = gtk.HBox()
			name_label = gtk.Label(_(name_cap(key))+_(":"))
			name_label.set_alignment(0, 0.5)
			hbox.pack_start(name_label, False, padding=5)


			name_labels.append(name_label)
			name_label_len = name_label.size_request()[0]
			if name_label_len > name_label_max_len :
				name_label_max_len = name_label_len

			if key == "server(:port)" :
				widget = gtk.combo_box_entry_new_text()
				widget.append_text(server)
				widget.child.set_text(server)
				widget.child.set_activates_default(True)
			elif key == "user_name" :
				widget = gtk.combo_box_entry_new_text()
				widget.append_text(user)
				widget.child.set_text(user)
				widget.child.set_activates_default(True)
			if key == "password" :
				widget = gtk.Entry()
				widget.set_visibility(False)
				widget.set_activates_default(True)
				
			widgets[key] = widget
			hbox.pack_start(widget, True, padding=2)
			dialog.vbox.pack_start(hbox, False, padding=2)

		for name_label in name_labels :
			name_label.set_size_request(name_label_max_len, -1)

		dialog.set_focus(widgets["password"])		
		dialog.show_all()
		ret =  dialog.run()

		server = widgets["server(:port)"].child.get_text()
		user = widgets["user_name"].child.get_text()
		password = widgets["password"].get_text()

		dialog.destroy()

		if ret == gtk.RESPONSE_OK:
			if not manager.login(server, user, password):
				msgbox(manager.failed_reason)
				return
			else:
				manager.profile["server"] = server
				manager.profile["user"] = user
				manager.save_profile()
	
		self.update_ui()

	def on_logout(self, action) :
		if confirmbox(_("Do you want to logout ?")) == gtk.RESPONSE_YES :
			self.confirm_record_pending()
			manager.logout()
			self.update_ui()

	def confirm_record_pending(self) :
		if manager.xml_nodes.has_key("cib") and manager.find_attribute("op_defaults", "record-pending") == "true" :
			retval = confirmbox((_("\"Indicate pending operations\" has been activated.") + "\n"
					+ _("It could affect the performance.") + "\n"
					+ _("Turn it off ?")))
			if retval ==  gtk.RESPONSE_YES :
				manager.set_crm_attribute("op_defaults", "record-pending", "false")

	def on_shadow_action(self, action) :
		global top_window

		shadows = manager.do_cmd("get_shadows")
		if shadows == None or len(shadows) == 0 :
			msgbox(_("Cannot get any shadow CIB"))
			return

		shadow_list = [shadow[len("shadow."):] for shadow in shadows]
		shadow_list.sort()

		action_name = action.get_name()

		default_shadow = None
		if manager.active_cib != "" :
			#if action_name == "delete" :
			#	if manager.active_cib in shadow_list :
			#		shadow_list.remove(manager.active_cib)
			#		if len(shadow_list) == 0 :
			#			msgbox(_("The only one shadow CIB \"%s\" is currently active.")%manager.active_cib)
			#			return
			#else :
				default_shadow = manager.active_cib

		title_str = _(name_cap(action_name)) + " " + _("Shadow CIB")
		if action_name == "reset" :
			action_des = _(name_cap(action_name)) + " - " + _("Recreate the specified shadow CIB from the live CIB")
		elif action_name == "delete" :
			action_des = _("Delete the specified shadow CIB")
		elif action_name == "commit" :
			action_des = _(name_cap(action_name)) + " - " + _("Upload the specified shadow CIB to the cluster")

		shadow_action = kvbox(title_str, action_des,
				[Field("shadow_name", _("Shadow Name"), default_shadow, shadow_list, False, entry_editable = False)])

		if shadow_action == None :
			return

		shadow_name = shadow_action.get("shadow_name", "")

		if shadow_name == manager.active_cib and action_name == "delete" :
			reinit_name = ""
		else :
			reinit_name = manager.active_cib

		if shadow_name == manager.active_cib :
			manager.do_cmd("shutdown_cib")

		cmd_ret = manager.do_cmd("crm_shadow\n%s\n%s\ntrue" %(action_name, shadow_name))

		if cmd_ret == None :
			if manager.failed_reason.count("Please remember to unset the CIB_shadow variable") == 0 :
				if manager.failed_reason != "" :
					msgbox(manager.failed_reason)
		#else :
			elif action_name == "commit" and manager.active_cib != "" :
				retval = confirmbox(_("The shadow CIB \"%s\"has been successfully commited.")%shadow_name + "\n"
							+_("Switch to the live CIB?"),
						(gtk.STOCK_NO, gtk.RESPONSE_NO, gtk.STOCK_YES, gtk.RESPONSE_YES),
						_("Switch to the live CIB?"))
				if retval == gtk.RESPONSE_YES :
					reinit_name = ""

		if shadow_name == manager.active_cib :
			manager.do_cmd("init_cib\n%s"%(reinit_name))
			if manager.failed_reason != "" :
				msgbox(manager.failed_reason)
			else :
				manager.set_update()
		elif manager.active_cib != reinit_name :
			manager.do_cmd("switch_cib\n%s"%(reinit_name))
			if manager.failed_reason != "" :
				msgbox(manager.failed_reason)
			else :
				manager.set_update()

	def on_shadow_diff(self, action) :
		global top_window

		dialog = gtk.Dialog(_("Shadow CIB Diff"), top_window, gtk.DIALOG_MODAL,
				(gtk.STOCK_CLOSE, gtk.RESPONSE_CLOSE, gtk.STOCK_SAVE, gtk.RESPONSE_APPLY))
		dialog.set_type_hint(gtk.gdk.WINDOW_TYPE_HINT_NORMAL)
		dialog.set_default_size(750, 550)
		dialog.set_default_response(gtk.RESPONSE_CLOSE)

		label = gtk.Label()
		label.set_markup('<b>' + _("Differences between the live CIB and the shadow CIB \"%s\"")%manager.active_cib + _(": ") + '</b>')
		label.set_alignment(0, 0)
		dialog.vbox.pack_start(label, False, padding = 5)

		sw = gtk.ScrolledWindow()
		sw.set_shadow_type(gtk.SHADOW_IN)
		sw.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
		dialog.vbox.pack_start(sw, True)

		shadow_diff_text = gtk.TextView()
		shadow_diff_text.set_property("editable", False)
		shadow_diff_textbuffer = shadow_diff_text.get_buffer()
		sw.add(shadow_diff_text)

		reinit_name = manager.active_cib
		manager.do_cmd("shutdown_cib")

		cmd = "crm_shadow\ndiff\n\n"
		shadow_diff = window.do_cmd_with_pbar(cmd, _("Shadow CIB Diff"),
				_("Generating the shadow CIB differences may take a while..."),
				_("Failed to generate the shadow CIB differences"), False)

		if shadow_diff == None :
		#else :
			shadow_diff_textbuffer.set_text(manager.failed_reason)

		dialog.show_all()
		save_top_window = top_window
		top_window = dialog

		while True :
			ret = dialog.run()
			if ret == gtk.RESPONSE_APPLY :
				self.save_shadow_diff(shadow_diff_textbuffer)
			else :
				break

		dialog.destroy()
		top_window = save_top_window

		manager.do_cmd("init_cib\n%s"%(reinit_name))
		if manager.failed_reason != "" :
			msgbox(manager.failed_reason)
		else :
			manager.set_update()

	def save_shadow_diff(self, textbuffer) :
		default_name = manager.active_cib + ".diff"
		filter_list = ((_("Diff Files"), ("*.diff",)),
				(_("All Files"), ("*")))
		sfdlg = SelectFileDlg()
		(save_file, save_type) = sfdlg.select_file(default_name, filter_list)
		if save_file == None :
			return

		save_str = textbuffer.get_text(*textbuffer.get_bounds())

		if save_str == None :
			msgbox(_("Cannot save the shadow diff"))
			return

		try :
			fd = os.open(save_file, os.O_RDWR|os.O_CREAT|os.O_TRUNC, 0644)
		except OSError, msg :
			msgbox(_("System error") + _(": ") + str(msg))
			return

		try :
			 os.write(fd, save_str)
		except OSError, msg :
			msgbox(_("System error") + _(": ") + str(msg))
			os.close(fd)
			return
		os.close(fd)

	def on_create_cib(self, action) :
		global top_window

		shadows = manager.do_cmd("get_shadows")
		if shadows == None or len(shadows) == 0 :
			shadow_list = []
		else :
			shadow_list = [shadow[len("shadow."):] for shadow in shadows]
			shadow_list.sort()

		dialog = gtk.Dialog(_("Create Shadow CIB"), top_window, gtk.DIALOG_MODAL,
			(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL, gtk.STOCK_OK, gtk.RESPONSE_OK))
		dialog.set_default_response(gtk.RESPONSE_OK)
		dialog.set_border_width(5)

		combo_entries = {}
		checkbuttons = {}
		radiobuttons = {}

		for key in ["shadow_name", "live", "empty","force"] :
			hbox = gtk.HBox()
			if key in ["shadow_name"] :
				name_label = gtk.Label(_(name_cap(key))+_(":"))
				name_label.set_alignment(0, 0.5)
				hbox.pack_start(name_label, False, padding=2)

			if key == "shadow_name" :
				widget = gtk.combo_box_entry_new_text()
				for shadow in shadow_list :
					widget.append_text(shadow)
				widget.child.set_activates_default(True)
				combo_entries[key] = widget
			elif key == "live" :
				widget = gtk.RadioButton(None, _("A copy of the live CIB"))
				radiobuttons[key] = widget
				live_radio_btn = widget
			elif key == "empty" :
				widget = gtk.RadioButton(live_radio_btn, _("A new CIB with empty cluster configuration"))
				radiobuttons[key] = widget
			elif key == "force" :
				widget = gtk.CheckButton(_(name_cap(key)))
				checkbuttons[key] = widget

			hbox.pack_start(widget, True, padding=2)
			dialog.vbox.pack_start(hbox, False, padding=2)

		widgets = {}
		widgets["combo_entries"] = combo_entries
		widgets["checkbuttons"] = checkbuttons
		widgets["radiobuttons"] = radiobuttons

		widget_group = WidgetGroup(widgets)

		save_top_window = top_window
		top_window = dialog
		dialog.show_all()

		while True:
			ret = dialog.run()
			if ret in [gtk.RESPONSE_CANCEL, gtk.RESPONSE_DELETE_EVENT] :
				break

			create_shadow = widget_group.get_values()

			shadow_name = create_shadow.get("shadow_name", "")
			if shadow_name == "" :
				msgbox(_("Please specify a name for the shadow CIB."))
				continue
			if shadow_name == "Live" or shadow_name == "live" :
				msgbox(_("Please specify another name for avoiding confusion."))
				continue
			elif shadow_name == manager.active_cib :
				msgbox(_("A shadow CIB \"%s\" already exists and it's currently active.")%(shadow_name))
				continue
			elif shadow_name in shadow_list and create_shadow.get("force", "") != "true" :
				msgbox(_("A shadow CIB \"%s\" already exists.")%(shadow_name) + "\n" + 
						_("Specify another name, or select \"Force\" if you want to override it."))
				continue

			if create_shadow.get("live") == "true" :
				create_cmd = "create"
			else :
				create_cmd = "create-empty"

			cmd_ret = manager.do_cmd("crm_shadow\n%s\n%s\n%s"
					%(create_cmd, shadow_name, create_shadow.get("force", "")))
			if cmd_ret == None :
				if manager.failed_reason == "" :
					#msgbox(_("Failed creating shadow CIB"))
					break

				if manager.failed_reason.count("A new shadow instance was created") == 0 :
					msgbox(manager.failed_reason)
					continue
			#else :
				retval = confirmbox(_("A new shadow CIB \"%s\" has been successfully created.")%shadow_name + "\n"
							+_("Switch to it now?"),
						(gtk.STOCK_NO, gtk.RESPONSE_NO, gtk.STOCK_YES, gtk.RESPONSE_YES),
						_("Switch to the new created shadow CIB \"%s\"?")%shadow_name)
				if retval == gtk.RESPONSE_YES :
					manager.do_cmd("switch_cib\n%s"%(create_shadow.get("shadow_name", "")))
					manager.set_update()
				break

		top_window = save_top_window
		dialog.destroy()


	def on_switch_cib(self, action, current, switch_list) :
		switch_name = switch_list[action.get_current_value()]
		if switch_name == "live" :
			manager.do_cmd("switch_cib\n")
		else :
			manager.do_cmd("switch_cib\n%s"%(switch_name[len("shadow."):]))
		if manager.failed_reason != "" :
			msgbox(manager.failed_reason + "\n"+ _("Or you don't have the permission."))

		manager.set_update()

	def render_switch_submenu(self, action) :
		for menuitem in self.switch_submenu.get_children() :
			self.switch_submenu.remove(menuitem)

		shadows = manager.do_cmd("get_shadows")
		if manager.failed_reason != "" :
			msgbox(manager.failed_reason)
			return
		if shadows == None or len(shadows) == 0 :
			return

		#shadow_list = [shadow[len("shadow."):] for shadow in shadows]
		shadow_list = shadows[:]
		shadow_list.sort()

		switch_list = shadow_list[:]
		switch_list.insert(0, "live")

		switch_radio_actions = [('live', None, _('Live'), None, None, 0)]
		for i in range(len(shadow_list)) :
			shadow = shadow_list[i]
			switch_radio_actions.append((shadow, None, shadow[len("shadow."):], None, None, i+1))

		default_active = 0
		if manager.active_cib != "" :
			active_shadow = "shadow." + manager.active_cib
			if active_shadow in switch_list :
				default_active = switch_list.index(active_shadow)

		switch_radio_actiongroup = gtk.ActionGroup("switch")
		switch_radio_actiongroup.add_radio_actions(switch_radio_actions, default_active, self.on_switch_cib, switch_list)

		for switch_name in switch_list :
			action = switch_radio_actiongroup.get_action(switch_name)
			action.set_accel_group(self.accelgroup)
			switch_menuitem = action.create_menu_item()
			self.switch_submenu.append(switch_menuitem)
			if switch_name == "live" :
				separator = gtk.SeparatorMenuItem()
				self.switch_submenu.append(separator)

		self.switch_submenu.show_all()

	def on_transition_info(self, action) :
		tidlg = TransitionInfoDlg()

	def on_cluster_report(self, action) :
		rpdlg = TimeFrameDlg()
		report_params = rpdlg.set_params(_("Cluster Report"), (False, True, True, False))
		if report_params == None :
			return

		report_params["ftime"] = time.strftime("%F %T", report_params["ftime"])
		if report_params.get("ttime") != None :
			report_params["ttime"] = time.strftime("%F %T", report_params["ttime"])

		report_cmd = "gen_cluster_report\n%s\n%s"%(report_params["ftime"], report_params.get("ttime", ""))

		str_list = window.do_cmd_with_pbar(report_cmd, _("Cluster Report"), 
					_("Generating the cluster report may take a while,")+"\n"
					+_("depending on the size of logs..."),
					_("Failed to generate the cluster report"))
		if str_list != None :
			self.save_cluster_report(str_list)

	def save_cluster_report(self, str_list) :
		if str_list == None or len(str_list) < 2 :
			msgbox(_("Failed to generate the cluster report"))
			return

		default_filename = os.path.basename(str_list[0])
		default_filetype = default_filename.split(".")[-1]

		base64_str = "\n".join(str_list[1:])
		try :
			bin_str = binascii.a2b_base64(base64_str)
		except binascii.Incomplete, msg :
			msgbox(_("Incomplete data") + (": ") + str(msg))
			return

		try :
			(fd, tmp_file) = tempfile.mkstemp(suffix = ".tar." + default_filetype, prefix = "cluster-report-")
		except IOError, msg :
			msgbox(_("I/O error") + _(": ") + str(msg))
			return

		#try :
		#	fd = os.open(save_file, os.O_RDWR|os.O_CREAT|os.O_TRUNC, 0644)
		#except OSError, msg :
		#	msgbox(_("System error") + _(": ") + str(msg))
		#	return

		try :
			os.write(fd, bin_str)
		except OSError, msg :
			msgbox(_("System error") + _(": ") + str(msg))
			os.close(fd)
			return
		os.close(fd)

		self.des_cluster_report(tmp_file)

	def des_cluster_report(self, tmp_file) :
		tmp_dir = os.path.dirname(tmp_file)

		default_filename = os.path.basename(tmp_file)
		default_filetype = default_filename.split(".")[-1]

		try :
			tmp_tarfile = tarfile.open(tmp_file, "r:"+default_filetype)
		except IOError, msg :
			msgbox(_("I/O error") + _(": ") + str(msg))
			return
		except tarfile.TarError, msg :
			msgbox(_("Tar error") + _(": ") + "%s: '%s'"%(str(msg), tmp_file))
			return
			
		try :
			file_list = tmp_tarfile.getnames()
			for filename in file_list :
				tmp_tarfile.extract(filename, tmp_dir)
		except tarfile.TarError, msg :
			msgbox(_("Tar error") + _(": ") + "%s: '%s'"%(str(msg), tmp_file))
			tmp_tarfile.close()
			return

		tmp_tarfile.close()
		os.unlink(tmp_file)	

		des_filename = None
		for filename in file_list :
			if filename.endswith("description.txt") :
				des_filename = filename
				break

		if des_filename != None :
			des_filepath = os.path.join(tmp_dir, des_filename)

			try :
				des_f = open(des_filepath, "r+")
			except IOError, msg :
				msgbox(_("I/O error") + _(": ") + str(msg))
				self.delete_files(tmp_dir, file_list)
				return

			try :
				file_lines = des_f.readlines()
			except IOError, msg :
				msgbox(_("I/O error") + _(": ") + str(msg))
				des_f.close()
				self.delete_files(tmp_dir, file_list)
				return

			des_report = DesReportDlg(file_lines)
			new_file_lines = des_report.run()

			if new_file_lines == None :
				new_file_lines = file_lines

			try :
				des_f.seek(0)
				des_f.truncate()
				des_f.writelines(new_file_lines)
			except IOError, msg :
				msgbox(_("I/O error") + _(": ") + str(msg))
				des_f.close()
				self.delete_files(tmp_dir, file_list)
				return

			des_f.close()

		sfdlg = SelectFileDlg()
		(save_file, save_type) = sfdlg.select_file(default_filename)
		if save_file == None :
			self.delete_files(tmp_dir, file_list)
			return

		try :
			new_tarfile = tarfile.open(save_file, "w:"+default_filetype)
		except IOError, msg :
			msgbox(_("I/O error") + _(": ") + str(msg))
			self.delete_files(tmp_dir, file_list)
			return
		except tarfile.TarError, msg :
			msgbox(_("Tar error") + _(": ") + "%s: '%s'"%(str(msg), save_file))
			self.delete_files(tmp_dir, file_list)
			return

		current_arcname = os.path.commonprefix(file_list).split(os.sep)[0]
		if current_arcname != '' :
			file_basename = os.path.basename(save_file)

			new_arcname = None
			for suffix in [".tar.gz", ".tgz", ".gz", ".tar.bz2", ".tbz", ".bz2"] :
				if save_file.endswith(suffix) :
					new_arcname = file_basename[:file_basename.rfind(suffix)]
					break
			if new_arcname == None :
				new_arcname = file_basename

			folder = os.path.join(tmp_dir, current_arcname)
			try :
				new_tarfile.add(folder, new_arcname)
			except IOError, msg :
				msgbox(_("I/O error") + _(": ") + str(msg))
				self.delete_files(tmp_dir, file_list)
				return
			except tarfile.TarError, msg :
				msgbox(_("Tar error") + _(": ") + "%s: '%s'"%(str(msg), save_file))
				new_tarfile.close()
				self.delete_files(tmp_dir, file_list)
				return
			new_tarfile.close()
			self.delete_files(tmp_dir, file_list)

		else :
			for filename in file_list :
				file_path = os.path.join(tmp_dir, filename)
				try :
					new_tarfile.add(file_path, recursive=False)
				except IOError, msg :
					msgbox(_("I/O error") + _(": ") + str(msg))
					new_tarfile.close()
					self.delete_files(tmp_dir, file_list)
					return
				except tarfile.TarError, msg :
					msgbox(_("Tar error") + _(": ") + "%s: '%s'"%(str(msg), save_file))
					new_tarfile.close()
					self.delete_files(tmp_dir, file_list)
					return
			new_tarfile.close()
			self.delete_files(tmp_dir, file_list)

	def delete_files(self, save_dir, file_list) :
		dir_list = []
		for filename in file_list :
			file_path = os.path.join(save_dir, filename)
			try :
				mode = os.lstat(file_path)[ST_MODE]
			except OSError, msg :
				msgbox(_("System error") + _(": ") + str(msg))
				continue

			if S_ISDIR(mode) :
				dir_list.append(file_path)
			else :
				try :
					os.unlink(file_path)
				except OSError, msg :
					msgbox(_("System error") + _(": ") + str(msg))
					continue

		for dir_path in dir_list :
			if os.access(dir_path, os.F_OK) :
				delete_dir(dir_path)

	def on_about(self, action) :
		global top_window
		name = "pacemaker-mgmt".capitalize()
		#version = "2.0"
		version = ""
		comments = "Pacemaker Management GUI"
		revision = "Revision: -2.1.2"
		website = "http://www.clusterlabs.org"
		website_label = "Pacemaker Website"
		authors = __authors__.strip().split('\n')
		license = __license__.strip()
		copyright = "Copyright \xc2\xa9 2007-2012 Gao,Yan <ygao@suse.com>" + "\n" \
				+ "Copyright \xc2\xa9 2005-2006 Huang Zhen <zhenhltc@cn.ibm.com>"
		copyright0 = "Copyright \xc2\xa9 2007-2012 Gao,Yan" + "\n" \
				+ "Copyright \xc2\xa9 2005-2006 Huang Zhen"
		translators = "Hideo Yamauchi <renayama19661014@ybb.ne.jp>\n" \
				+ "Gao,Yan <ygao@suse.com>"

		if not pygtk_newer(2, 6) :
			dialog = gtk.Dialog(_("About") + " " + name, top_window, gtk.DIALOG_MODAL)
			dialog.set_has_separator(False)
			dialog.set_border_width(5)
			dialog.set_resizable(False)
			dialog.vbox.set_spacing(5)
			im = gtk.Image()
			im.set_from_stock("ha", gtk.ICON_SIZE_DIALOG)
			dialog.vbox.pack_start(im, False)
			markup_text_list = ['<span size="xx-large"><b>' + name + ' ' + version  + '</b></span>',
						comments,
						revision,
						'<span size="small">' + copyright0 + '</span>',
						website]
			for markup_text in markup_text_list :
				markup_label = gtk.Label()
				markup_label.set_justify(gtk.JUSTIFY_CENTER)
				if markup_text == website :
					markup_text = '<span foreground="blue"><u>' + website_label + '</u></span>'
					linkbtn = gtk.Button()
					linkbtn.add(markup_label)
					linkbtn.set_relief(gtk.RELIEF_NONE)
					linkbtn.connect("clicked", self.open_url, website)
					hbox = gtk.HBox(True)
					hbox.pack_start(linkbtn, False, False)
					tooltips = gtk.Tooltips()
					tooltips.set_tip(linkbtn, website)
					widget = hbox
				else :
					markup_label.set_selectable(True)
					widget = markup_label
					
				markup_label.set_markup(markup_text)
				dialog.vbox.pack_start(widget, False)

			close_btn = dialog.add_button(gtk.STOCK_CLOSE, gtk.RESPONSE_CANCEL)
			close_btn.grab_default()
			close_btn.grab_focus()

			dialog.show_all()
		else :
			dialog = gtk.AboutDialog()
			dialog.set_transient_for(top_window)

			dialog.set_name(name)
			dialog.set_version(version)
			dialog.set_copyright(copyright)
			dialog.set_license(_(license))
			comments += "\n" + revision
			dialog.set_comments(comments)
			gtk.about_dialog_set_url_hook(self.open_url)
			dialog.set_website(website)
			dialog.set_website_label(website_label)
			dialog.set_authors(authors)
			dialog.set_translator_credits(translators)
			dialog.set_logo(gtk.gdk.pixbuf_new_from_file("/usr/share/heartbeat-gui/ha.png"))

		save_top_window = top_window
             	top_window = dialog
		dialog.run()
		
		top_window = save_top_window
		dialog.destroy()

	def open_url(self, widget, link) :
		webbrowser.open(link)

	def change_mode_level(self, action, current) :
		global mode_level
		mode_level = action.get_current_value()
			
		self.update()

	def load_icon(self, name, file) :
		icons = gtk.IconFactory()
		icons.add(name,gtk.IconSet(gtk.gdk.pixbuf_new_from_file(file)))
		icons.add_default()

	# constructor	
	def __init__(self) :
		# create window
		win_widget = gtk.Window()
		win_widget.connect("delete_event", self.on_delete_event)
		win_widget.set_title(_("Pacemaker GUI"))
		win_widget.set_default_size(manager.profile["width"], manager.profile["height"])
		win_widget.set_icon_from_file("/usr/share/heartbeat-gui/ha.png")

		# add the icons to gtk stock
		self.load_icon("ha", "/usr/share/heartbeat-gui/ha.png")
		if not pygtk_newer(2, 6) :
			self.load_icon("ha-login","/usr/share/heartbeat-gui/login.png")
			self.load_icon("ha-logout","/usr/share/heartbeat-gui/logout.png")
		self.load_icon("ha-standby-node","/usr/share/heartbeat-gui/standby-node.png")
		self.load_icon("ha-active-node","/usr/share/heartbeat-gui/active-node.png")
		self.load_icon("ha-start-resource","/usr/share/heartbeat-gui/start-resource.png")
		self.load_icon("ha-stop-resource","/usr/share/heartbeat-gui/stop-resource.png")
		#self.load_icon("ha-master-resource","/usr/share/heartbeat-gui/master-resource.png")
		#self.load_icon("ha-slave-resource","/usr/share/heartbeat-gui/slave-resource.png")
		self.load_icon("ha-manage-resource","/usr/share/heartbeat-gui/manage-resource.png")
		self.load_icon("ha-unmanage-resource","/usr/share/heartbeat-gui/unmanage-resource.png")

		self.load_icon("administration","/usr/share/heartbeat-gui/administration.png")
		self.load_icon("record-pending","/usr/share/heartbeat-gui/record-pending.png")

		self.load_icon("nodes","/usr/share/heartbeat-gui/nodes.png")
		self.load_icon("node","/usr/share/heartbeat-gui/node.png")

		self.load_icon("failed","/usr/share/heartbeat-gui/failed.png")
		self.load_icon("running","/usr/share/heartbeat-gui/running.png")
		self.load_icon("stopped","/usr/share/heartbeat-gui/stopped.png")
		self.load_icon("dirty-stopped","/usr/share/heartbeat-gui/dirty-stopped.png")
		self.load_icon("starting","/usr/share/heartbeat-gui/starting.png")
		self.load_icon("stopping","/usr/share/heartbeat-gui/stopping.png")

		#self.load_icon("expert-mode","/usr/share/heartbeat-gui/expert-mode.png")

		# create ui-manager
		ui_xml = '''
		<ui>
			<menubar name="menubar">
				<menu action="connection">
					<menuitem action="login"/>
					<menuitem action="logout"/>
					<separator/>
					<menuitem action="quit"/>
				</menu>
				<menu action="view">
					<menuitem action="simple-mode"/>
					<menuitem action="expert-mode"/>
					<menuitem action="hack-mode"/>
				</menu>
				<menu action="shadow">
					<menuitem action="new"/>
					<menuitem action="diff"/>
					<menuitem action="reset"/>
					<menuitem action="delete"/>
					<separator/>
					<menuitem action="commit"/>
					<separator/>
					<menuitem action="switch"/>
				</menu>
				<menu action="tools">
					<menuitem action="transition-info"/>
					<menuitem action="report"/>
				</menu>
				<menu action="help">
					<menuitem action="about"/>
				</menu>
			</menubar>
			<popup name="connection_popup">
				<menuitem action="login"/>
				<menuitem action="logout"/>
				<menuitem action="quit"/>
			</popup>
			<popup action="tools_popup">
				<menuitem action="transition-info"/>
				<menuitem action="report"/>
				<separator/>
				<menuitem action="simple-mode"/>
				<menuitem action="expert-mode"/>
				<menuitem action="hack-mode"/>
			</popup>
			<toolbar name="toolbar">
				<toolitem action="login"/>
				<toolitem action="logout"/>
				<separator/>
				<toolitem action="transition-info"/>
				<toolitem action="report"/>
				<separator/>
				<toolitem action="quit"/>
			</toolbar>
		</ui>'''
		uimanager = gtk.UIManager()

		self.accelgroup = uimanager.get_accel_group()
		win_widget.add_accel_group(self.accelgroup)

		actiongroup = gtk.ActionGroup('haclient')

		if pygtk_newer(2, 6) :
			login_icon = gtk.STOCK_CONNECT
			logout_icon = gtk.STOCK_DISCONNECT
		else :
			login_icon = "ha-login"
			logout_icon = "ha-logout"

		actiongroup.add_actions([
			('connection', None, _('_Connection')),
			('login', login_icon, _('Log_in'), '<Ctrl>i', _('login to cluster'), self.on_login),
			('logout', logout_icon, _('Log_out'), '<Ctrl>o', _('logout from cluster'), self.on_logout),
			('quit', gtk.STOCK_QUIT, _('_Quit'), None,_('Quit the Program'), self.on_quit),
			('view', None, _('_View')),
			('shadow', None, _('_Shadow')),
			('new', gtk.STOCK_NEW, _('_New'), None,_('Create a new shadow CIB'), self.on_create_cib),
			('diff', gtk.STOCK_COPY, _('Di_ff'), '<Ctrl>f', _('Differences between the live CIB and the shadow CIB'), self.on_shadow_diff),
			('reset', None, _('_Reset'), '<Ctrl>r', _('Recreate a shadow CIB from the live CIB'), self.on_shadow_action),
			('delete', gtk.STOCK_DELETE, _('_Delete'), '<Ctrl>d', _('Delete a shadow CIB'), self.on_shadow_action),
			('commit', gtk.STOCK_SAVE, _('_Commit'), '<Ctrl>c', _('Upload a shadow CIB to the cluster'), self.on_shadow_action),
			('switch', None, _('_Switch'), None, _('Switch working CIB'), self.render_switch_submenu),
			('tools', None, _('_Tools')),
			('transition-info', gtk.STOCK_CONVERT, _('_Transition Information'), '<Ctrl>t',
				_('Show Transition Information'), self.on_transition_info),
			('report', gtk.STOCK_FIND_AND_REPLACE, _('Cluster Re_port'), '<Ctrl>p', _('generate a cluster report'), self.on_cluster_report),
			('help', None, _('_Help')),
			('about', gtk.STOCK_ABOUT, _('_About'), '<Ctrl>a', _('About'), self.on_about)
			])

		uimanager.insert_action_group(actiongroup, 0)

		radio_tool_actions = [
			('simple-mode', None, _('_Simple Mode'), '<Shift><Ctrl>s', _('Switch to simple mode'), 0),
			('expert-mode', None, _('_Expert Mode'), '<Shift><Ctrl>e', _('Switch to expert mode'), 1),
			('hack-mode', None, _('_Hack Mode'), '<Shift><Ctrl>h', _('Switch to hack mode'), 2),
			]

		self.radio_tool_action_group = gtk.ActionGroup("radio_mode_level")
		self.radio_tool_action_group.add_radio_actions(radio_tool_actions, 0, self.change_mode_level)
		uimanager.insert_action_group(self.radio_tool_action_group, 1)

		uimanager.add_ui_from_string(ui_xml)

		# put componets to window
		vbox = gtk.VBox()
		win_widget.add(vbox)

		menubar = uimanager.get_widget('/menubar')
		vbox.pack_start(menubar, False)

		switch_menu = uimanager.get_widget("/menubar/shadow/switch")
		self.switch_submenu = gtk.Menu()
		switch_menu.set_submenu(self.switch_submenu)
		#switch_menu.connect("focus", self.render_switch_submenu)

		toolbar = uimanager.get_widget('/toolbar')
		toolbar.set_style(gtk.TOOLBAR_ICONS)
		vbox.pack_start(toolbar, False)

		hpaned = gtk.HPaned()
		vbox.pack_start(hpaned)

		#maintree = MainTree("cib")
		maintree_sw = gtk.ScrolledWindow()
		maintree_sw.set_shadow_type(gtk.SHADOW_IN)

		maintree_sw.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)

		self.maintree = MainTree()
		maintree_sw.add(self.maintree.widget)

		#maintree_sw.add(maintree)

		#maintree_frame = gtk.Frame()
		#maintree_frame.add(maintree_sw)
		hpaned.add1(maintree_sw)

		mainview_sw = gtk.ScrolledWindow()
		mainview_sw.set_shadow_type(gtk.SHADOW_IN)
		mainview_sw.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)

		#mainview_frame = gtk.Frame()
		#mainview_frame.add(mainview_sw)
		hpaned.add2(mainview_sw)

		self.statusbar = gtk.Statusbar()
		vbox.pack_end(self.statusbar, False)

		# show the window
		win_widget.show_all()
		# keep some widgets
		self.win_widget = win_widget
		self.actiongroup = actiongroup
		self.uimanager = uimanager
		self.maintree_sw = maintree_sw
		self.mainview_sw = mainview_sw
		self.update_ui()
		self.statusbar.push(0,_("Not Connected"))

class Manager :
	'''
	Manager will connect to mgmtd and control the main window
	'''
	connected = False
	window = None
	server = None
	username = None
	password = None
	cache = {}
	no_update_cache = {}
	parent = {}
	io_tag = None
	update_timer = -1
	active_nodes = []
	all_nodes = []
	try_nodes = []
	failed_reason = ""
	dtd_elems = {}
	session_lock = thread.allocate_lock()
	async_ret_lock = thread.allocate_lock()
	#async_ret_str = {}
	async_ret_list = {} 
	xml_nodes = {}
	active_cib = None
	validate_name = None
	profile = {}
		
	# cache functions

	def __init__(self) :
		self.load_profile()

	def cache_lookup(self, key) :
		if self.cache.has_key(key) :
			return self.cache[key]
		if self.no_update_cache.has_key(key) :
			return self.no_update_cache[key]
		return None
			
	def cache_update(self, key, data, keep_in_cache = False) :
		if not keep_in_cache :
			self.cache[key] = data
		else :
			self.no_update_cache[key] = data
			
	def cache_delkey(self, key) :
		if self.cache.has_key(key) : 
			del self.cache[key]
			
	def cache_clear(self) :
		self.cache.clear()
		
	# internal functions	
	def split_attr_list(self, attrs, keys) :
		attr_list = []
		if attrs != None :
			for i in range(0, len(attrs), len(keys)) :
				attr = {}
				for j in range (0, len(keys)) :
					attr[keys[j]] = attrs[i+j]
				attr_list.append(attr)
		return attr_list
		
	def run(self) :
		gtk.gdk.threads_init()
		gtk.main()
		if self.connected :
			mgmt_disconnect()
	
	# connection functions
	def load_profile(self) :
		keys = ["server", "user", "width", "height"]

		self.profile["server"] = "127.0.0.1"
		self.profile["user"] = "hacluster"
		self.profile["width"] = 790
		self.profile["height"] = 550

		save_path = os.environ["HOME"]+"/.haclient"
		if not os.path.exists(save_path) :
			return
		try:
			values = pickle.load(file(save_path,"r"))
			user_profile = dict(zip(keys, values))
			self.profile.update(user_profile)
			return
		except:
			return

	def save_profile(self) :
		global top_window

		server = self.profile["server"]
		user = self.profile["user"]
		
		(width, height) = top_window.get_size()
		self.profile["width"] = width
		self.profile["height"] = height

		save_path = os.environ["HOME"]+"/.haclient"
		try:
			pickle.dump((server, user, width, height), file(save_path,"w"))
		except:
			os.remove(save_path)
		return
		
	def login(self, server, username, password) :
		# connect to one of the cluster
		self.failed_reason = ""
		if string.find(server, ":") != -1 :
			server_host, port = string.split(server,":")
		else :
			server_host = server
			port = ""

		try :
			ip = socket.gethostbyname(server_host)
		except socket.error :
			self.failed_reason = _("Can't resolve address of server ")+server_host
			return False

		try :
			ret = mgmt_connect(ip, username, password, port)
		except :
			self.failed_reason = _("Can't connect to server ")+server
			mgmt_disconnect()
			return False

		if ret != 0 :
			if ret == -1 :
				self.failed_reason = _("Can't connect to server ")+server
			elif ret == -2 :
				self.failed_reason =\
			 	_("Failed in the authentication.\n User Name or Password may be wrong." \
				"\n or the user doesn't belong to haclient group")
			else :
				self.failed_reason = _("Can't login to server.\n The protocols may be mismatched.")
			mgmt_disconnect()
			return False

		window.statusbar.pop(1)	
		window.statusbar.push(1,_("Connected to ")+username+"@"+server_host)
		self.connected = True
		if server != None and server not in self.try_nodes :
			self.try_nodes.insert(0, server)
		self.server = server_host
		self.username = username
		self.password = password

		window.statusbar.push(2,_("Updating data from server..."))
		self.update_timer = gobject.timeout_add(500, self.update)
		
		self.do_cmd("regevt\nevt:cib_changed")
		self.do_cmd("regevt\nevt:disconnected")

		fd = mgmt_inputfd()
		self.io_tag = gobject.io_add_watch(fd, gobject.IO_IN, self.on_event, None)

		gobject.timeout_add(5000, self.update_crm_metadata, priority=gobject.PRIORITY_DEFAULT_IDLE)

		return True
	
	def query(self, query, keep_in_catch = False) :
		result = self.cache_lookup(query)
		if  result != None :
			return 	result
		result = self.do_cmd(query)
		self.cache_update(query, result, keep_in_catch)
		return result
		
	def do_cmd(self, command) :
		self.failed_reason = ""
		self.session_lock.acquire()
		ret_str = mgmt_sendmsg(command)
		self.session_lock.release()
		if ret_str == None :
			debug(str(string.split(command, "\n"))+":None")
			self.failed_reason = "return None"
			return None
 		while len(ret_str)>=4 and ret_str[:4] == "evt:" :
			gobject.idle_add(self.on_event, None, None, ret_str)
			self.session_lock.acquire()
 			ret_str = mgmt_recvmsg()
			self.session_lock.release()
			if ret_str == None :
				debug(str(string.split(command, "\n"))+":None")
				self.failed_reason = "return None"
				return None

		return self.ret_str2list(ret_str, command)

	def ret_str2list(self, ret_str, command) :
		self.failed_reason = ""
		ret_list = string.split(ret_str, "\n")
		if ret_list[0] != "o" :
			debug(str(string.split(command, "\n"))+":"+ str(ret_list))
			if len(ret_list) > 1 :
				self.failed_reason = string.join(ret_list[1:],"\n")
			return None
		debug(str(string.split(command, "\n"))+":"+ str(ret_list))
		return ret_list[1:]

	def process_ret(self, command, ret_str) :
		self.failed_reason = ""
		if ret_str == None :
			debug(str(string.split(command, "\n"))+":None")
			self.failed_reason == "return None"
			return None

		return self.ret_str2list(ret_str, command)

	def async_sendmsg(self, command) :
		self.session_lock.acquire()
		gobject.source_remove(self.io_tag)
		async_ret_str = mgmt_thread_sendmsg(command)
		fd = mgmt_inputfd()
		self.io_tag = gobject.io_add_watch(fd, gobject.IO_IN, self.on_event, None)
		self.session_lock.release()

		self.async_ret_lock.acquire()
		self.async_ret_list[command] = self.process_ret(command, async_ret_str)
		self.async_ret_lock.release()
		
	def async_do_cmd(self, command) :
		self.async_ret_lock.acquire()
		#self.async_ret_str = {}
		#self.async_ret_list = {}
		if self.async_ret_list.has_key(command) :
			self.async_ret_list.pop(command)
		self.async_ret_lock.release()
		thread.start_new(self.async_sendmsg, (command, ))
		
	def logout(self) :
		mgmt_disconnect()
		gobject.source_remove(self.io_tag)
		self.connected = False
		window.update()
		window.statusbar.pop(1)
		
	# event handler	
	def on_reconnect(self) :
		if self.all_nodes == [] :
			window.statusbar.pop(1)
			return False

		try_nodes = self.try_nodes[:]
		for node in self.all_nodes :
			if node not in try_nodes :
				try_nodes.append(node)

		for server in try_nodes :
			if self.login(server, self.username, self.password) :
				return False
		return True

	def process_event(self, event) :
		if event == "evt:cib_changed" :
			self.set_update()

		elif event == None or event == "evt:disconnected" :
			self.logout()

			try_nodes = self.try_nodes[:]
			for active_node in self.active_nodes :
				if active_node not in try_nodes :
					try_nodes.append(active_node)

			for server in try_nodes :
				if self.login(server, self.username, self.password) :
					break
			else :
				window.statusbar.push(1,_("Reconnecting..."))
				gobject.timeout_add(1000, self.on_reconnect)

	def set_update(self) :
		if self.update_timer != -1 :
			gobject.source_remove(self.update_timer)
		else :
			window.statusbar.push(2,_("Updating data from server..."))
		self.update_timer = gobject.timeout_add(500, self.update)
	
	def on_event(self, source, condition, event_str) :
		if event_str == None : 	# called by gtk
			self.session_lock.acquire()
			event = mgmt_recvmsg()
			self.session_lock.release()
			debug("on_event:"+str(event))
			self.process_event(event)
			return True
		else :					# called by do_cmd
			event = event_str 
			log("on_event: from message queue: "+str(event))
			self.process_event(event)
			return False

	def cib_do_cmd(self, command):
		self.failed_reason = ""
		ret_str = mgmt_sendmsg(command)
		if ret_str == None:
			debug(command + ":None")
			self.failed_reason = "return None"
			return None
		ret_list = string.split(ret_str, "\n")
		if ret_list[0] != "o":
			debug(str(string.split(command, "\n"))+":"+str(ret_list))
			if len(ret_list) > 1:
				self.failed_reason = string.join(ret_list[1:], "\n")
			return None
		return string.join(ret_list[1:], "\n")

	def update_cib_xml(self) :
		global validate_type
		xml_nodes = self.xml_nodes
		cib_xml = self.cib_do_cmd("cib_query\ncib")
		if self.failed_reason != "" :
			#msgbox(self.failed_reason)
			log(self.failed_reason)
			return False 

		if cib_xml == None or cib_xml == "" :
			#msgbox(_("Cannot get the CIB"))
			log("Cannot get the CIB")
			return False

		try :
			xml_nodes["cib"] = parseString(cib_xml).documentElement
		except xml.parsers.expat.ExpatError, msg :
			#msgbox(_("Failed to parse the CIB") + _(": ") + str(msg))
			log("Failed to parse the CIB: " + str(msg))
			return False 
			
		"""xml_status = self.cib_do_cmd("cib_query\nstatus")
		xml_rscs = self.cib_do_cmd("cib_query\nresources")
		xml_nodes = self.cib_do_cmd("cib_query\nnodes")
		xml_constraints = self.cib_do_cmd("cib_query\nconstraints")
		xml_crm_config = self.cib_do_cmd("cib_query\ncrm_config")"""

		if xml_nodes.get("cib") == None :
			#msgbox(_("Cannot parse the CIB"))
			log("Cannot parse the CIB")
			return False

		validate_type = self.get_validate_type()
		saved_validate_name = self.validate_name
		self.validate_name = self.get_validate_name()

		if validate_type == "dtd" :
			if not support_pyxml :
				log("Pacemaker GUI requires pyxml package to process DTD")
				msgbox(_("Pacemaker GUI requires pyxml package to process DTD"))
				sys.exit()
			dtd_elem = self.get_dtd_elem("cib")
			for (name, mod) in dtd_elem.get_content_model()[1] :
				if mod != '' :
					continue
				
				xml_nodes[name] = xml_nodes["cib"].getElementsByTagName(name)[0]
				if xml_nodes.get(name) == None :
					continue
				sub_dtd_elem = manager.get_dtd_elem(name)
				for (sub_name, sub_mod) in sub_dtd_elem.get_content_model()[1] :
					if sub_mod != '' :
						continue
					xml_nodes[sub_name] = xml_nodes[name].getElementsByTagName(sub_name)[0]
		else :
			if self.validate_name != saved_validate_name :
				self.rng_docs = {}
				self.rng_str_docs = {}
				self.update_rng_docs(self.validate_name, self.validate_name+".rng")
				self.supported_rsc_types = self.get_supported_rsc_types()

		return True

		"""config_xml = self.cib_xml.getElementsByTagName("configuration")
		self.crm_xml = config_xml.getElementsByTagName("crm_config")
		self.nodes_xml = config_xml.getElementsByTagName("nodes")
		self.rscs_xml = config_xml.getElementsByTagName("resources")
		self.cns_xml = config_xml.getElementsByTagName("constraints")
		self.status_xml =  self.cib_xml.getElementsByTagName("status")
	
		try:
			self.cib_xml = parseString(xml_cib).documentElement
			self.status_xml = parseString(xml_status)
			self.rscs_xml = parseString(xml_rscs)
			self.nodes_xml = parseString(xml_nodes)
			self.cns_xml = parseString(xml_constraints)
			self.crm_xml = parseString(xml_crm_config)
		except xml.parsers.expat.ExpatError:
			self.status_xml = None
			self.rscs_xml = None
			self.nodes_xml = None
			self.crm_xml = None
			self.cns_xml = None
			debug("fail to parse xml info")
			return None"""

	def get_active_cib(self) :
		active_cib = manager.do_cmd("active_cib")
		if active_cib == None or len(active_cib) == 0 :
			return

		if len(active_cib[0]) > 0 :
			self.active_cib = active_cib[0]
		else :
			self.active_cib = ""

	def get_supported_rsc_types(self) :
		rsc_types = []
		if validate_type == "dtd" :
			dtd_elem = manager.get_dtd_elem("resources")
			for (name, mod) in dtd_elem.get_content_model()[1] :
				rsc_types.append(name)
		else :
			sorted_rng_nodes = manager.sorted_sub_rng_nodes_by_name("resources")
			for rng_node in sorted_rng_nodes.get("element", []) :
				rsc_types.append(rng_node[0][1].getAttribute("name"))

		return rsc_types

	def find_xml_node(self, obj_type, obj_name) :
		for xml_node in self.xml_nodes["cib"].getElementsByTagName(obj_type) :
			if xml_node.getAttribute("id") == obj_name :
				return xml_node
		return None

	def find_attribute(self, obj_type, attribute_name) :
		for xml_node in self.xml_nodes["cib"].getElementsByTagName(obj_type) :
			for nv_xml_node in xml_node.getElementsByTagName("nvpair") :
				if nv_xml_node.getAttribute("name") == attribute_name :
					return nv_xml_node.getAttribute("value")
		return None

	def set_crm_attribute(self, type, name, value) :
		for xml_node in self.xml_nodes["cib"].getElementsByTagName(type) :
			for attr_node in xml_node.getElementsByTagName("nvpair") :
				if attr_node.getAttribute("name") == name :
					attr_id = str(attr_node.getAttribute("id"))
					self.do_cmd("crm_attribute\n%s\nset\n%s\n%s\n\n\n%s"
							%(type, name, value, attr_id))
					return

			for child_node in xml_node.childNodes :
	                        if child_node.nodeType != xml.dom.Node.ELEMENT_NODE :
	                                continue
				set_id = str(child_node.getAttribute("id"))
				self.do_cmd("crm_attribute\n%s\nset\n%s\n%s\n\n%s\n"
						%(type, name, value, set_id))
				return

		self.do_cmd("crm_attribute\n%s\nset\n%s\n%s\n\n\n"%(type, name, value))

	def node_name(self, node_id) :
		for node_xml_node in manager.xml_nodes["cib"].getElementsByTagName("node") :
			if node_xml_node.getAttribute("id") == node_id :
				node_name = node_xml_node.getAttribute("uname")
				return node_name
		return ""

	def validate_cib(self, cib_xml_node = None) :
		if cib_xml_node == None :
			 cib_xml_node = manager.xml_nodes["cib"]

		if validate_type == "dtd" :
			is_valid = True
		elif not support_lxml :
			is_valid = True
		else :
			is_valid = self.validate_with_rng(cib_xml_node)

		return is_valid

	def validate_with_rng(self, cib_xml_node) :
		rng_doc = self.tmp_rng_doc()
		if rng_doc == None :
			msgbox(_("Cannot expand the Relax-NG schema"))
			return False
		
		try :
			cib_doc = etree.fromstring(cib_xml_node.toxml())
		except etree.Error, msg :
			msgbox(_("Failed to parse the CIB XML") + _(": ") + str(msg))
			return False
			
		try :
			relaxng = etree.RelaxNG(file = rng_doc)
		except etree.Error, msg :
			msgbox(_("Failed to parse the Relax-NG schema") + _(": ") + str(msg))
			return False
		#try :
		#	relaxng.assertValid(cib_doc)
		#except etree.DocumentInvalid, err_msg :
		#	print err_msg
		#	print relaxng.error_log
		try :
			etree.clear_error_log()
		except :
			try :
				etree.clearErrorLog()
			except :
				pass

		is_valid = relaxng.validate(cib_doc)
		if not is_valid :
			error_msg = ""
			for error_entry in relaxng.error_log :
				error_msg += error_entry.level_name + ": " + error_entry.message + "\n"
			msgbox(_(error_msg))

		delete_dir(os.path.dirname(rng_doc))

		return is_valid

	def tmp_rng_doc(self) :
		try :
			tmp_dir = tempfile.mkdtemp()
		except IOError, msg :
			msgbox(_("I/O error") + _(": ") + str(msg))
			return None
		for rng_doc_name in self.rng_str_docs :
			rng_doc_filename = os.path.join(tmp_dir, rng_doc_name)
			try :
				fd = os.open(rng_doc_filename, os.O_RDWR|os.O_CREAT|os.O_TRUNC, 0644)
			except OSError, msg :
				msgbox(_("System error") + _(": ") + str(msg))
				return None

			rng_doc_str = self.rng_str_docs[rng_doc_name]

			try :
				os.write(fd, rng_doc_str)
			except OSError, msg :
				msgbox(_("System error") + _(": ") + str(msg))
				os.close(fd)
				return None
			os.close(fd)

		if self.validate_name + ".rng" in  self.rng_str_docs :
			return os.path.join(tmp_dir, self.validate_name + ".rng")
		else :
			return None

	def update_rng_docs(self, validate_name = "", file= "") :
		self.rng_docs[file] = self.get_start_rng_node(validate_name, file)
		if self.rng_docs[file] == None :
			return
		for extern_ref in self.rng_docs[file][0].getElementsByTagName("externalRef") :
			href_value = extern_ref.getAttribute("href")
			if self.rng_docs.get(href_value) == None :
				self.update_rng_docs(validate_name, href_value)	

	def get_start_rng_node(self, validate_name = "", file = "") :
		schema_info = validate_name + " " + file
		crm_schema = self.get_crm_schema(validate_name, file)
		if crm_schema == None :
			#msgbox(_("Cannot get the Relax-NG schema") + _(": ") + schema_info)
			log("Cannot get the Relax-NG schema: " + schema_info)
			return None

		self.rng_str_docs[file] = crm_schema

		try :
			rng_doc = parseString(crm_schema).documentElement
		except xml.parsers.expat.ExpatError, msg :
			#msgbox(_("Failed to parse the Relax-NG schema") + _(": ") + str(msg) + schema_info)
			log("Failed to parse the Relax-NG schema: " + str(msg) + schema_info)
			return None

		start_nodes = rng_doc.getElementsByTagName("start")
		if len(start_nodes) > 0 :
			start_node = start_nodes[0] 
			return (rng_doc, start_node)
		else :
			#msgbox(_("Cannot get started in Relax-NG schema") +_(": ") + schema_info)
			log("Cannot get started in Relax-NG schema: " + schema_info)
			return None

		#sub_start_node = None
		#for sub_start_node in start_node.childNodes :
		#	if sub_start_node.nodeType == xml.dom.Node.ELEMENT_NODE :
		#		break
			
		##sub_start_nodes = self.get_sub_rng_nodes(start_node)["req_elem_nodes"]
		##if sub_start_nodes == [] :
		#if sub_start_node == None :
		#	#msgbox(_("Cannot get the start element in Relax-NG schema: ") + schema_info)
		#	log("Cannot get the start element in Relax-NG schema: " + schema_info)
		#	return None
		#else :
		#	return (rng_doc, sub_start_node)

	def get_rng_elem(self, elem_name) :
		elem_node = None
		for (rng_doc, start_node) in self.rng_docs.values() :
			for elem_node in rng_doc.getElementsByTagName("element") :
				if elem_node.getAttribute("name") == elem_name :
					return (rng_doc, elem_node)
		return None

	def get_sub_rng_nodes(self, rng_doc, rng_node) :
		sub_rng_nodes = []
		#sub_rng_nodes = {}
		#req_elem_nodes = []
		#attr_nodes = []
		for child_node in rng_node.childNodes :
			if child_node.nodeType != xml.dom.Node.ELEMENT_NODE :
				continue
			if child_node.tagName == "ref" :
				for def_node in rng_doc.getElementsByTagName("define") :
					if def_node.getAttribute("name") == child_node.getAttribute("name") :
						break
				sub_rng_nodes.extend(self.get_sub_rng_nodes(rng_doc, def_node))
			elif child_node.tagName == "externalRef" :
				nodes = self.get_sub_rng_nodes(*self.rng_docs[child_node.getAttribute("href")])
				sub_rng_nodes.extend(nodes)
			elif child_node.tagName in ["element", "attribute", "value", "data", "text"] :
				sub_rng_nodes.append([(rng_doc, child_node)])
			elif child_node.tagName in ["interleave", "optional", "zeroOrMore", "choice", "group", "oneOrMore"] :
				nodes = self.get_sub_rng_nodes(rng_doc, child_node)
				for node in nodes :
					node.append(child_node)
				sub_rng_nodes.extend(nodes)
		#sub_rng_nodes["req_elem_nodes"] = req_elem_nodes
		return sub_rng_nodes

	def sorted_sub_rng_nodes_by_name(self, obj_type) :
		rng_node = self.get_rng_elem(obj_type)	
		if rng_node == None or rng_node[1] == None :
			# msgbox(_("Cannot get %s in Relax-NG schema")%obj_type)
			return None
		return self.sorted_sub_rng_nodes_by_node(*rng_node)

	def sorted_sub_rng_nodes_by_node(self, rng_doc, rng_node) :
		sub_rng_nodes = manager.get_sub_rng_nodes(rng_doc, rng_node)
		sorted_nodes = {}
		for sub_rng_node in sub_rng_nodes :
			name = sub_rng_node[0][1].tagName
			if sorted_nodes.get(name) == None :
				sorted_nodes[name] = []
			sorted_nodes[name].append(sub_rng_node)
		return sorted_nodes

	def find_decl(self, rng_node, name, first = True) :
		decl_node_index = 0
		for decl_node in rng_node[1:] :
			if decl_node.tagName == name :
				decl_node_index = rng_node.index(decl_node) - len(rng_node)
				if first :
					break
		return decl_node_index

	def get_decl_rng_nodes(self, rng_node) :
		decl_rng_nodes = {}
		choice_index = manager.find_decl(rng_node, "choice", False)
		if choice_index != 0 :
			decl_rng_nodes["choice"] = rng_node[choice_index]

		first_choice_index = manager.find_decl(rng_node, "choice")
		if first_choice_index != choice_index :
			decl_rng_nodes["first_choice"] = rng_node[first_choice_index]

		group_index = manager.find_decl(rng_node, "group", False)
		if group_index != 0 :
			decl_rng_nodes["group"] = rng_node[group_index]

		first_group_index = manager.find_decl(rng_node, "group")
		if first_group_index != group_index :
			decl_rng_nodes["first_group"] = rng_node[first_group_index]

		return decl_rng_nodes

	def get_sorted_decl_nodes(self, decl_nodes_list, decl_type) :
		sorted_nodes = []
		for rng_nodes in decl_nodes_list :
			rng_node = rng_nodes.get(decl_type)
			if rng_node != None and rng_node not in sorted_nodes :
				sorted_nodes.append(rng_node)
		return sorted_nodes

	def get_rng_attr_type(self, attr_rng_node) :
		sub_rng_nodes = self.sorted_sub_rng_nodes_by_node(*attr_rng_node[0])
		for sub_rng_node in sub_rng_nodes.get("data", []) :
			return sub_rng_nodes["data"][0][0][1].getAttribute("type")

		return None

	def real_add_obj_type(self, xml_node, obj_type_name, is_wizard = False) :
		sub_attr_is_any_name = False 
		if validate_type == "dtd" :
			dtd_elem = manager.get_dtd_elem(obj_type_name)
			sub_attr_list = dtd_elem.get_attr_list()
		else :
			sorted_rng_nodes = manager.sorted_sub_rng_nodes_by_name(obj_type_name)
			sub_attr_list = []
			sub_elem_type_list = []
			sub_elem_is_any_name = False
			if sorted_rng_nodes != None :
				sub_attr_rng_nodes = sorted_rng_nodes.get("attribute", [])
				sub_elem_rng_nodes = sorted_rng_nodes.get("element", [])
				for rng_node in sub_attr_rng_nodes :
					name = rng_node[0][1].getAttribute("name")
					if name == "" :
						sub_attr_is_any_name = True
					elif sub_attr_list.count(name) == 0 :
						sub_attr_list.append(name)
				for rng_node in sub_elem_rng_nodes :
					name = rng_node[0][1].getAttribute("name")
					if name == "" :
						sub_elem_is_any_name = True
					elif sub_elem_type_list.count(name) == 0 :
						sub_elem_type_list.append(name)
			else :
				sub_attr_is_any_name = True
				sub_elem_is_any_name = True
				sub_elem_rng_nodes = []
					
		if not sub_attr_is_any_name and (len(sub_attr_list) == 0 \
				or ((mode_level != 2 or is_wizard) and obj_type_name in
				["meta_attributes", "instance_attributes", "operations",
				"cluster_property_set", "utilization"])) :
			new_mid_elem = None
			impl = getDOMImplementation()
			elem_node_list = []
			for elem_node in xml_node.getElementsByTagName(obj_type_name) :
				if elem_node in xml_node.childNodes :
					elem_node_list.append(elem_node)
			if len(elem_node_list) == 0 :
				newdoc = impl.createDocument(None, obj_type_name, None)
				mid_elem = newdoc.documentElement
				xml_node.appendChild(mid_elem)
				new_mid_elem = mid_elem

				if sub_attr_list.count("id") > 0 :
					mid_id = manager.auto_unique_id(mid_elem, obj_type_name)
					mid_elem.setAttribute("id", mid_id)
			else :
				mid_elem = elem_node_list[0]

			if validate_type == "dtd" :
				(sep,cont,mod) = dtd_elem.get_content_model()
				if len(cont) > 0 :
					if len(sub_attr_list) == 0 :
						sub_obj_type = cont[0][0]
					else :
						sub_obj_type = cont[1][0]
						sub_elem_node_list = []
						for sub_elem_node in mid_elem.getElementsByTagName(sub_obj_type) :
							if sub_elem_node in mid_elem.childNodes :
								sub_elem_node_list.append(sub_elem_node)
						if len(sub_elem_node_list) == 0 :
							newdoc = impl.createDocument(None, sub_obj_type, None)
							sub_mid_elem = newdoc.documentElement
							mid_elem.appendChild(sub_mid_elem)
							mid_elem = sub_mid_elem
							if new_mid_elem == None :
								new_mid_elem = mid_elem
						else :
							mid_elem = sub_elem_node_list[0]
							
						sub_dtd_elem = manager.get_dtd_elem(sub_obj_type)
						(sub_obj_type, mod) = sub_dtd_elem.get_content_model()[1][0]
				else :
					return (None, None, None)
			else:
				sub_obj_type = None
				for sub_elem_rng_node in sub_elem_rng_nodes :
					if manager.find_decl(sub_elem_rng_node, "optional") != 0  :
						continue
					sub_obj_type = sub_elem_rng_node[0][1].getAttribute("name")
					break

				if sub_obj_type == None :
					return (None, None, None)

			return (mid_elem, sub_obj_type, new_mid_elem)
		else :
			return (xml_node, obj_type_name, None)

	def get_obj_ids(self, xml_node) :
		id_list = []
		node_id = xml_node.getAttribute("id")
		if node_id != "" and id_list.count(node_id) == 0 :
			id_list.append(node_id)
		for child_node in xml_node.childNodes :
			if child_node.nodeType != xml.dom.Node.ELEMENT_NODE :
				continue
			id_list.extend(self.get_obj_ids(child_node))
		return id_list

	def exist_ids(self, xml_node = None) :
		all_ids = manager.get_obj_ids(manager.xml_nodes["cib"])

		top_types = ["crm_config","rsc_defaults", "op_defaults", "nodes", "resources", "constraints", "acls", "fencing-topology", "status"]

		if xml_node == None :
			return all_ids

		top_parent = xml_node
		while top_parent.parentNode.tagName not in top_types :
			top_parent = top_parent.parentNode

		other_ids = manager.get_obj_ids(top_parent)

		for id in other_ids :
			if id not in all_ids :
				all_ids.append(id)

		current_id = xml_node.getAttribute("id")
		if current_id in all_ids :
			all_ids.remove(current_id)

		return all_ids

	def auto_id_prefix(self, xml_node, name) :
		parent_node = xml_node.parentNode
		parent_type = parent_node.tagName
		parent_id = parent_node.getAttribute("id")

		if parent_type == "crm_config" :
			return "cib-bootstrap-options"
		elif parent_type in ["rsc_defaults", "op_defaults"] :
			return parent_type + "-options"
		elif parent_type == "node" :
			if xml_node.tagName != "instance_attributes" :
				return "nodes-" + parent_id + "-" + xml_node.tagName
			else :
				return "nodes-" + parent_id
		elif name == "fencing-level" :
			return name

		if parent_id == "" :
			parent_parent_node = xml_node.parentNode.parentNode
			parent_parent_id = parent_parent_node.getAttribute("id")
			if parent_parent_id == "" :
				parent_parent_type = parent_parent_node.tagName
				id_prefix = parent_parent_type + "-" + parent_type + "-" + name
			else :
				id_prefix = parent_parent_id + "-" + parent_type + "-" + name
		else :
			id_prefix = parent_id + "-" + name

		return id_prefix

	def get_unique_id(self, id_prefix, xml_node = None) :
		all_exist_ids = self.exist_ids(xml_node)
		valid_id_prefix = self.sanify_id(id_prefix)

		id_suffix = ""
		new_id = valid_id_prefix 
		while new_id in all_exist_ids :
			if id_suffix == "" :
				id_suffix = 0
			else :
				id_suffix += 1

			new_id = valid_id_prefix + "-" + str(id_suffix)

		return new_id

	def sanify_id(self, id) :
		valid_prefix = "_"
		valid_chrs = "-_."
		for i in range(len(id)) :
			if id[i].isalpha() or id[i] in valid_prefix :
				break

		valid_id = ""
		for chr in id[i:] :
			if chr.isalnum() or chr in valid_chrs :
				valid_id += chr
			else :
				valid_id += '.'
		return valid_id

	def auto_unique_id(self, xml_node, name) :
		id_prefix = self.auto_id_prefix(xml_node, name)
		return self.get_unique_id(id_prefix, xml_node)

	def update(self) :
		self.cache_clear()
		if not manager.connected :
			retval = False
		elif self.update_cib_xml() :
			self.get_active_cib()
			self.parent = {}
			window.update()
			retval = False
		else :
			retval = True
		gc.collect()
		self.update_timer = -1
		return retval

	def get_validate_type(self) : 
		validate_list = {
			"": "dtd",
			"pacemaker-0.6": "dtd",
			"transitional-0.6": "dtd",
			"pacemaker-0.7": "rng",
			"pacemaker-1.0": "rng"
		}
		validate_name = self.get_validate_name()
		if validate_name == None :
			return None
		else :
			return validate_list.get(validate_name)

	def get_validate_name(self) :
		if self.xml_nodes.get("cib") != None :
			return self.xml_nodes["cib"].getAttribute("validate-with")
		else :
			return None

	def get_crm_schema(self, validate_name="", file="") :
		lines = self.query("crm_schema\n%s\n%s"%(str(validate_name), str(file)))
		if lines == None :
			return None
		schema = "\n".join(lines)
		return schema

	def get_crm_dtd(self):
		lines = self.query("crm_dtd", True)
		if lines == None:
			return None
		dtd = "\n".join(lines)

		return dtd
		
	def get_dtd_elem(self, elem_name) :
		if not self.dtd_elems.has_key(elem_name) :
			dtd = self.get_crm_schema(self.validate_name)
			if dtd == None :
				#msgbox(_("Cannot get the DTD") + _(": ") + self.validate_name)
				log("Cannot get the DTD:" + self.validate_name)
				return None
			complete_dtd = load_dtd_string(dtd)
			self.dtd_elems[elem_name] = complete_dtd.get_elem(elem_name)
		
		return self.dtd_elems[elem_name]

	# cluster functions		
	def update_crm_metadata(self) :
		for crm_cmd in ["pengine", "crmd"] :
			self.query("crm_metadata\n%s"%(crm_cmd),True)
		return False

	def get_crm_metadata(self, crm_cmd) :
		if crm_cmd == None :
			return None
		lines = self.query("crm_metadata\n%s"%(crm_cmd),True)

		if lines == None :
			return None
		meta_data = "\n".join(lines)

		try :
			doc_xml = parseString(meta_data).documentElement
		except xml.parsers.expat.ExpatError, msg :
			log("Failed to parse the metadata of %s: %s"%(crm_cmd, msg))
			return None
			
		meta = RAMeta()
		meta.name = doc_xml.getAttribute("name")

		meta.version = ""
		version_xml = doc_xml.getElementsByTagName("version")
		if version_xml != [] and version_xml[0] in doc_xml.childNodes :
			meta.version = version_xml[0].childNodes[0].data

		meta.longdesc = self.get_locale_desc(doc_xml, "longdesc");
		meta.shortdesc = self.get_locale_desc(doc_xml, "shortdesc");
		
		params = {}
		for param_xml in doc_xml.getElementsByTagName("parameter") :
			param = {}
			param["name"] = param_xml.getAttribute("name")
			param["unique"] = param_xml.getAttribute("unique")
			param["longdesc"] = self.get_locale_desc(param_xml, "longdesc");
			param["shortdesc"] = self.get_locale_desc(param_xml, "shortdesc");
			content_xml = param_xml.getElementsByTagName("content")[0]
			content = {}
			content["type"] = content_xml.getAttribute("type")
			content["default"] = content_xml.getAttribute("default")
			if content["type"] == "enum" :
				values_tag = "Allowed values:"
				index = param["longdesc"].rfind(values_tag)
				if index != -1:
					strings = param["longdesc"][index+len(values_tag):].split(",")
					content["values"] = []
					for string in strings:
						content["values"].append(string.strip())
				
			param["content"] = content

			params[param["name"]] = param

		param_names = params.keys()
		param_names.sort()

		meta.parameters = []
		for param_name in param_names :
			meta.parameters.append(params[param_name])

		return meta

	def get_cluster_type(self) :
		typelist = manager.query("cluster_type")
		if typelist != None and len(typelist) > 0 :
			cluster_type = typelist[0]
		else :
			cluster_type = ""

		return cluster_type

	def get_hb_config(self) :
		values = manager.query("hb_config")
		hb_config = {}
		if values != None:
			i = 0
			while i < len(values) :
				hb_config[values[i]] = values[i+1]
				i += 2
		return hb_config

	def get_cluster_config(self) :
		config = {}
		cluster_type = self.get_cluster_type()
		if cluster_type == "heartbeat" :
			config = self.get_hb_config()

		return config
				
	# node functions
	def get_dc(self):
		return self.query("dc")

	def get_all_nodes(self) :
		all_nodes = self.query("all_nodes")
		if all_nodes == None :
			all_nodes = self.query("crm_nodes")

		if all_nodes != None :
			self.all_nodes = all_nodes
		else :
			self.all_nodes = []

		return self.all_nodes

	def get_nodetype(self, node):
		node_type = self.query("node_type\n%s"%node)
		if node_type != None and len(node_type) > 0 :
			return node_type[0]
		else :
			return None
	
	def get_normal_nodes(self) :
		nodes = self.query("all_nodes")
		if nodes == None :
			return self.get_crm_nodes()

		normal_nodes = []
		for node in nodes :
			if self.get_nodetype(node) == "normal" :
				normal_nodes.append(node)
		return normal_nodes

	def get_active_nodes(self):
		active_nodes = self.query("active_nodes")
		if active_nodes != None :
			self.active_nodes = active_nodes
		else :
			self.active_nodes = []

		return self.active_nodes
	
	def get_crm_nodes(self):
		return self.query("crm_nodes")
				
	def get_node_config(self, node) :
		node_attr_names = ["uname", "online","standby", "unclean", "shutdown",
				   "expected_up","is_dc","type", "pending","standby_onfail"]
				  
		values = manager.query("node_config\n%s"%node)
		if values == None :
			values = ["" for i in range(8)]
		config = dict(zip(node_attr_names,values))
		
		return config

	def get_running_rsc(self, node) :
		return self.query("running_rsc\n%s"%node)	

	# resource functions
	def get_top_rsc(self) :
		return self.query("all_rsc")

	def get_rsc_type(self, rsc_id) :
		rsc_type_ret = self.query("rsc_type\n"+rsc_id)
		if rsc_type_ret != None and len(rsc_type_ret) > 0 :
			rsc_type = rsc_type_ret[0]
		else :
			rsc_type = None

		if rsc_type == "native" :
			return "primitive"
		else :
			return rsc_type
	
	def get_rsc_status(self, rsc_id) :
		status = self.query("rsc_status\n"+rsc_id)
		for lrm_node in manager.xml_nodes["cib"].getElementsByTagName("lrm") :
			node_id = lrm_node.getAttribute("id")
			for lrm_resource_node in lrm_node.getElementsByTagName("lrm_resource") :
				if lrm_resource_node.getAttribute("id") == rsc_id :
					for lrm_rsc_op in lrm_resource_node.getElementsByTagName("lrm_rsc_op") :
						operation = lrm_rsc_op.getAttribute("operation")
						if lrm_rsc_op.getAttribute("op-status") == "-1" :
							if operation == "start" :
								status[0] = "starting"
								break
							elif operation == "stop" :
								status[0] = "stopping"
								break
		return status

	def get_rsc_running_on(self, rsc_id) :
		return self.query("rsc_running_on\n"+rsc_id)

	def get_sub_rsc(self, rsc_id) :
		sub_rscs = self.query("sub_rsc\n"+rsc_id)
		if sub_rscs != None :
			for sub_rsc in sub_rscs :
				self.parent[sub_rsc] = rsc_id
		else :
			return []
		return sub_rscs

	def get_all_subrsc(self, rsc_id) :
		all_subrscs = []
		sub_rscs = self.get_sub_rsc(rsc_id)
		if sub_rscs != None :
			for sub_rsc in sub_rscs :
				all_subrscs.append(sub_rsc)
				all_sub_subrscs = self.get_all_subrsc(sub_rsc)
				if all_sub_subrscs != None :
					all_subrscs.extend(all_sub_subrscs)
		return all_subrscs

	def get_all_rsc(self) :
		all_rscs = []
		top_rscs = self.query("all_rsc")
		if top_rscs != None :
			for top_rsc in top_rscs :
				all_rscs.append(top_rsc)
				all_subrscs = self.get_all_subrsc(top_rsc)
				if all_subrscs != None :
					all_rscs.extend(all_subrscs)
		return all_rscs

	def get_all_real_rsc(self) :
		all_rscs = self.get_all_rsc()
		all_real_rsc = []
		for rsc in all_rscs :
			rsc_real_id = self.obj_real_id(rsc)
			if all_real_rsc.count(rsc_real_id) == 0 :
				all_real_rsc.append(rsc_real_id)
		return all_real_rsc

	def get_all_real_subrsc(self, rsc_id) :
		all_subrscs = self.get_all_subrsc(rsc_id)
		all_real_subrsc = []
		for rsc in all_subrscs :
			rsc_real_id = self.obj_real_id(rsc)
			if all_real_subrsc.count(rsc_real_id) == 0 :
				all_real_subrsc.append(rsc_real_id)
		return all_real_subrsc

	def obj_real_id(self, obj_id) :
		return obj_id.split(":")[0]

	def op_status2str(self, op_status) :
		str_list = self.query("op_status2str\n%s"%str(op_status), True)
		if str_list != None and len(str_list) > 0 :
			return str_list[0]
		else :
			return ""

	def get_rsc_info(self, rsc_id) :
		for resources_node in manager.xml_nodes["cib"].getElementsByTagName("resources") :
			for primitive_node in resources_node.getElementsByTagName("primitive") :
				if primitive_node.getAttribute("id") == rsc_id :
					primitive_attrs = self.get_rsc_attrs(primitive_node, ["class", "type", "provider"])
					rsc_class = str(primitive_attrs.get("class", ""))
					rsc_type = str(primitive_attrs.get("type", ""))
					rsc_provider = str(primitive_attrs.get("provider", ""))
					return (rsc_class, rsc_type, rsc_provider)
		return None

	def get_rsc_attrs(self, primitive_node, attr_names) :
		attrs ={}

		ref_node = primitive_node
		while ref_node and ref_node.nodeType == xml.dom.Node.ELEMENT_NODE :
			for attr_name in attr_names :
				if attrs.get(attr_name) :
					continue

				attr_value = ref_node.getAttribute(attr_name)
				if attr_value :
					attrs[attr_name] = str(attr_value)

			template_id = ref_node.getAttribute("template")
			if template_id :
				ref_node = self.get_template(template_id)
			else :
				break

		return attrs

	def get_template(self, template_id) :
		if not template_id :
			return None

		for resources_node in manager.xml_nodes["cib"].getElementsByTagName("resources") :
			for template_node in resources_node.getElementsByTagName("template") :
				if template_node.getAttribute("id") == template_id :
					return template_node
		return None

	def get_all_templates(self) :
		templates = []
		for resources_node in manager.xml_nodes["cib"].getElementsByTagName("resources") :
			for template_node in resources_node.getElementsByTagName("template") :
				template_id = template_node.getAttribute("id")
				if template_id and template_id not in templates:
					templates.append(template_id)
		return templates

	def get_locale_desc(self, node, tag) :
		desc_en = ""
		desc_match = ""
		
		(lang, encode) = locale.getlocale()
		if lang == None:
			lang = "en"
		else:
			lang = string.lower(lang)
		if encode == None:	
			encode = ""
		else:	
			encode = string.lower(encode)
		
		for child in node.childNodes :
			if child.nodeType != node.ELEMENT_NODE :
				continue
			if child.tagName != tag :
				continue
			if len(child.childNodes) == 0:
				break
			langtag = string.lower(child.getAttribute("lang"))
			if langtag == "" :
				desc_en = child.childNodes[0].data
			else :
				langtag = string.split(langtag, ".")
				if string.find(langtag[0], "en") != -1 :
					desc_en = child.childNodes[0].data
				if len(langtag) == 1 and lang == langtag[0] :
					desc_match = child.childNodes[0].data
				if len(langtag) == 2 :	
					if lang == langtag[0] and encode == langtag[1] :
						desc_match = child.childNodes[0].data	
		if desc_match != "" :
			return desc_match
		return desc_en				
		
			
	def get_rsc_meta(self, rsc_class, rsc_type, rsc_provider) :
		if rsc_class == None or rsc_class == "" \
				or rsc_type == None or rsc_type == "" :
			return None
		if rsc_provider == None or rsc_provider == "" :
			rsc_provider = "heartbeat"

		lines = self.query("rsc_metadata\n%s\n%s\n%s"% \
				(rsc_class, rsc_type, rsc_provider),True)
		if lines == None :
			return None
		meta_data = ""
		for line in lines :
			if len(line)!= 0 :
				meta_data = meta_data + line + "\n"
		try :
			doc_xml = parseString(meta_data).documentElement
		except xml.parsers.expat.ExpatError, msg :
			errmsg = "Failed to parse the metadata of %s: %s"
			log(errmsg%(rsc_type, msg))
			msgbox(_(errmsg)%(rsc_type, _(msg)))
			return None
			
		meta = RAMeta()
		meta.name = doc_xml.getAttribute("name")
		meta.version = ""
		version_xml = doc_xml.getElementsByTagName("version")
		if version_xml != [] and version_xml[0] in doc_xml.childNodes :
			meta.version = version_xml[0].childNodes[0].data

		meta.longdesc = self.get_locale_desc(doc_xml, "longdesc");
		meta.shortdesc = self.get_locale_desc(doc_xml, "shortdesc");
		
		meta.parameters = []
		for param_xml in doc_xml.getElementsByTagName("parameter") :
			param = {}
			param["name"] = param_xml.getAttribute("name")
			param["required"] = param_xml.getAttribute("required")
			param["unique"] = param_xml.getAttribute("unique")
			param["longdesc"] = self.get_locale_desc(param_xml, "longdesc");
			param["shortdesc"] = self.get_locale_desc(param_xml, "shortdesc");
			content_xml = param_xml.getElementsByTagName("content")[0]
			content = {}
			content["type"] = content_xml.getAttribute("type")
			content["default"] = content_xml.getAttribute("default")
			param["value"] = content["default"]
			param["content"] = content
			meta.parameters.append(param)
		meta.actions = []
		for action_xml in doc_xml.getElementsByTagName("action") :
			action = {}
			for key in action_xml.attributes.keys() :
				action[key] = action_xml.getAttribute(key)
			meta.actions.append(action)
		return meta
	
	def get_rsc_classes(self) :
		return self.query("rsc_classes",True);

	def get_rsc_types(self, rsc_class) :
		return self.query("rsc_types\n"+rsc_class,True)
	
	def get_rsc_providers(self, rsc_class, rsc_type) :
		return self.query("rsc_providers\n%s\n%s"%(rsc_class, rsc_type),True)

	def lrm_op_rc2str(self, rc) :
		str_list = self.query("lrm_op_rc2str\n%s"%str(rc), True)
		if str_list != None and len(str_list) > 0 :
			return str_list[0]
		else :
			return ""

	def rsc_exists(self, rsc_id) :
		return rsc_id in self.get_all_rsc()

class WidgetGroup :
	def __init__(self, widgets) :
		self.widgets = widgets

	def get_values(self) :
		object = {}
		widgets = self.widgets
		if widgets.has_key("value_labels") :
			for key in widgets["value_labels"].keys() :
				if widgets["value_labels"][key].get_property("sensitive") == False :
					continue
				object[key] = widgets["value_labels"][key].get_text()
				if object[key] == "" or object[key] == None :
					object.pop(key)
		if widgets.has_key("combos") :
			for key in widgets["combos"].keys() :
				if widgets["combos"][key].get_property("sensitive") == False :
					continue
				if pygtk_newer(2, 6) :
					object[key] = widgets["combos"][key].get_active_text()
				else :
					iter = widgets["combos"][key].get_active_iter()
					if iter != None :
						object[key] = widgets["combos"][key].get_model().get_value(iter, 0)
					else :
						object[key] = None
				if object[key] == "" or object[key] == None :
					object.pop(key)
		if widgets.has_key("bool_combos") :
			for key in widgets["bool_combos"].keys() :
				if widgets["bool_combos"][key].get_property("sensitive") == False :
					continue
				if pygtk_newer(2, 6) :
					object[key] = widgets["bool_combos"][key].get_active_text()
				else :
					iter = widgets["bool_combos"][key].get_active_iter()
					if iter != None :	
						object[key] = widgets["bool_combos"][key].get_model().get_value(iter, 0)
					else :
						object[key] = None
				if object[key] == "" or object[key] == None :
					object.pop(key)
		if widgets.has_key("combo_entries") :
			for key in widgets["combo_entries"].keys() :
				if widgets["combo_entries"][key].get_property("sensitive") == False :
					continue
				object[key] = widgets["combo_entries"][key].child.get_text()
				if object[key] == "" or object[key] == None :
					object.pop(key)
		if widgets.has_key("checkbuttons") :
			for key in widgets["checkbuttons"].keys() :
				if widgets["checkbuttons"][key].get_property("sensitive") == False :
					continue
				if widgets["checkbuttons"][key].get_active() :
					object[key] = "true"
				else:
					object[key] = "false"
		if widgets.has_key("entries") :
			for key in widgets["entries"].keys() :
				if widgets["entries"][key].get_property("sensitive") == False :
					continue
				object[key] = widgets["entries"][key].get_text()
				if object[key] == "" or object[key] == None :
					object.pop(key)
		if widgets.has_key("spinbuttons") :
			for key in widgets["spinbuttons"].keys() :
				if widgets["spinbuttons"][key].get_property("sensitive") == False :
					continue
				object[key] = str(int(widgets["spinbuttons"][key].get_value()))
				if object[key] == ""  or object[key] == None :
					object.pop(key)

		if widgets.has_key("anyname_combo_entries") :
			for key in widgets["anyname_combo_entries"].keys() :
				if widgets["anyname_combo_entries"][key].get_property("sensitive") == False :
					continue
				attr_name = key.get_text()
				object[attr_name] = widgets["anyname_combo_entries"][key].child.get_text()
				if attr_name == "" or object[attr_name] == "" or object[attr_name] == None :
					object.pop(attr_name)

		if widgets.has_key("radiobuttons") :
			for key in widgets["radiobuttons"].keys() :
				if widgets["radiobuttons"][key].get_property("sensitive") == False :
					continue
				if widgets["radiobuttons"][key].get_active() :
					object[key] = "true"
				else:
					object[key] = "false"

		return object

	def show_values(self, object) :
		widgets = self.widgets
		if widgets.has_key("value_labels") :
			for key in widgets["value_labels"].keys() :
				if object.has_key(key) :
					widgets["value_labels"][key].set_text(object[key])
		if widgets.has_key("combos") :
 			for key in widgets["combos"].keys() :
				if object.has_key(key) :
					iter = widgets["combos"][key].get_model().get_iter_first()
					while iter != None :
						if widgets["combos"][key].get_model().get_value(iter,0) == object[key] :
							widgets["combos"][key].set_active_iter(iter)
						iter = widgets["combos"][key].get_model().iter_next(iter)
				else :
					widgets["combos"][key].set_active(0)

		if widgets.has_key("bool_combos") :
 			for key in widgets["bool_combos"].keys() :
				if object.has_key(key) :
					if object[key] == "true" or object[key] == "yes" or object[key] == "1" :
						bool_value = "true"
					elif object[key] == "false" or object[key] == "no" or object[key] == "0" :
						bool_value = "false"
					else :
						bool_value = object[key]
					iter = widgets["bool_combos"][key].get_model().get_iter_first()
					while iter != None :
						if widgets["bool_combos"][key].get_model().get_value(iter,0) == bool_value :
							widgets["bool_combos"][key].set_active_iter(iter)
						iter = widgets["bool_combos"][key].get_model().iter_next(iter)
				else :
					widgets["bool_combos"][key].set_active(0)
			
		if widgets.has_key("combo_entries") :
 			for key in widgets["combo_entries"].keys():
				if object.has_key(key) :
					widgets["combo_entries"][key].child.set_text(object[key])
				else :
					widgets["combo_entries"][key].child.set_text("")

		if widgets.has_key("entries") :
			for key in widgets["entries"].keys() :
				if object.has_key(key) :
					widgets["entries"][key].set_text(object[key])
				else :
					widgets["entries"][key].set_text("")

		if widgets.has_key("checkbuttons") :
			for key in widgets["checkbuttons"].keys() :
				if object.has_key(key) :
					lower_value = object[key].lower()
					widgets["checkbuttons"][key].set_active("true" == lower_value
										or "yes" == lower_value
										or "1" == lower_value)
		if widgets.has_key("spinbuttons") :
			for key in widgets["spinbuttons"].keys() :
				if object.has_key(key) :
					try :
						widgets["spinbuttons"][key].set_value(float(object[key]))
					except :
						pass

		if widgets.has_key("anyname_combo_entries") :
			for key in widgets["anyname_combo_entries"].keys() :
				attr_name = key.get_text()
				if object.has_key(attr_name) :
					widgets["anyname_combo_entries"][key].child.set_text(object[attr_name])
				else :
					widgets["anyname_combo_entries"][key].child.set_text("")

class ObjectAttrs(WidgetGroup) :
	dynamic_layout = None
	dynamic_fill = None
	dynamic_desc = None
	static_desc = None
	dynamic_render = None
	dynamic_set_id = None
	save_id = None

	def __init__(self, xml_node, is_newobj = False, change_call_back = None, hide_optional = False) :
		self.xml_node = xml_node
		self.obj_type = xml_node.tagName
		self.is_newobj = is_newobj
		self.change_call_back = change_call_back
		self.hide_optional = hide_optional
		self.render_attrs_vbox()

		if validate_type == "dtd" :
			self.dtd_elem = manager.get_dtd_elem(self.obj_type)
			self.attr_list = dtd_elem.get_attr_list()
			if self.dtd_elem.get_content_model()[1] == [] :
				self.auto_id = True
				self.dynamic_set_id = self.dynamic_set_id_auto
			else :
				self.auto_id = False
			self.render_widgets_dtd()
		else :
			self.render_widgets_rng()

		for widget_type in ("combos", "bool_combos", "combo_entries") :
			if self.widgets.has_key(widget_type) :
				for widget in self.widgets[widget_type].values() :
					if pygtk_newer(2, 10) and pygobject_newer(2, 12, 3) :
						widget.connect("changed", self.on_changed)
					else :
						widget.connect("changed", self.on_changed_later)
						

		for widget in self.widgets.get("anyname_combo_entries", {}) :
			if pygtk_newer(2, 10) and pygobject_newer(2, 12, 3) :
				widget.connect("changed", self.on_changed)
				self.widgets["anyname_combo_entries"][widget].connect("changed", self.on_changed)
			else :
				widget.connect("changed", self.on_changed_later)
				self.widgets["anyname_combo_entries"][widget].connect("changed", self.on_changed_later)

	def verify_values(self) :
		if validate_type == "dtd" :
			return self.verify_values_dtd()
		else :
			return self.verify_values_rng()

	def on_after_show(self) :
		if self.auto_id or (mode_level == 0 and self.dynamic_set_id != None) :
			self.hide_id_widget()

		if self.auto_id == True :
			if self.is_newobj :
				if self.widgets.has_key("combo_entries") and self.widgets["combo_entries"].has_key("id") :
					if len(self.widgets["combo_entries"]["id"].child.get_text()) == 0 :
						#self.widgets["combo_entries"]["id"].child.set_text(self.obj_type + "-" + gen_uuid())
						obj_id = manager.auto_unique_id(self.xml_node, self.obj_type)
						self.widgets["combo_entries"]["id"].child.set_text(obj_id)
		#			self.widgets["name_labels"]["id"].hide_all()
		#			self.widgets["combo_entries"]["id"].hide_all()
		#	else :
		#		if self.widgets.has_key("name_labels") and self.widgets["name_labels"].has_key("id") :
		#			self.widgets["name_labels"]["id"].hide_all()
		#			self.widgets["value_labels"]["id"].hide_all()

		else :
			if self.is_newobj and not self.id_is_idref and self.obj_type not in \
					["node", "primitive", "template", "group", "clone", "master","master_slave", \
					"rsc_location", "rsc_colocation", "rsc_order", "rsc_ticket", "acl_user", "acl_role"] :
				if self.widgets.has_key("combo_entries") and self.widgets["combo_entries"].has_key("id") \
						and len(self.widgets["combo_entries"]["id"].child.get_text()) == 0 :
					obj_id = manager.auto_unique_id(self.xml_node, self.obj_type)
					self.widgets["combo_entries"]["id"].child.set_text(obj_id)
		#			parent_id = self.xml_node.parentNode.getAttribute("id")
		#			if parent_id == "" :
		#				id_prefix = self.obj_type
		#			else :
		#				id_prefix = parent_id + "-" + self.obj_type
		#			self.widgets["combo_entries"]["id"].child.set_text(id_prefix)

		if self.pref_expand and (mode_level != 0 or self.obj_type not in ["op", "rsc_order"] ) :
			self.optional_expander.set_expanded(True)

		self.auto_fill()

		if len(self.required_vbox.get_children()) < 2 :
			self.required_vbox.hide()

		if len(self.optional_vbox.get_children()) < 1 or self.hide_optional :
			self.optional_expander.hide()

		if self.dynamic_desc == None and self.static_desc == None :
			#self.vbox_labels["Description"].hide()
			self.desc_outer_vbox.hide()

		if self.static_desc != None :
			self.show_desc(self.static_desc)

		if not pygtk_newer(2, 10) or not pygobject_newer(2, 12, 3) :
			return

		for widget_type in ("combos", "bool_combos", "combo_entries") :
			if self.widgets.has_key(widget_type) :
				for widget in self.widgets[widget_type].values() :
					widget.disconnect_by_func(self.on_changed)
					widget.connect("changed", self.on_changed_later)

		for widget in self.widgets.get("anyname_combo_entries", {}) :
			widget.disconnect_by_func(self.on_changed)
			widget.connect("changed", self.on_changed_later)
			self.widgets["anyname_combo_entries"][widget].disconnect_by_func(self.on_changed)
			self.widgets["anyname_combo_entries"][widget].connect("changed", self.on_changed_later)

	def render_attrs_vbox(self) :
		required_vbox = gtk.VBox()
		optional_vbox = gtk.VBox()
		optional_expander = gtk.Expander()
		optional_expander.add(optional_vbox)

		desc_outer_vbox = gtk.VBox()
		widget_list = [(required_vbox, "Required"), 
				(optional_expander, "Optional"),
				(desc_outer_vbox, "Description")]
		self.vbox_labels = {}
		for (widget, label_text) in widget_list : 
			vbox_label = gtk.Label()
			vbox_label.set_markup('<b>' + _(label_text) + '</b>')
			vbox_label.set_alignment(0, 1)
			if label_text == "Optional" :
				widget.set_label_widget(vbox_label)
			else :
				widget.pack_start(vbox_label, False, padding=2)
			self.vbox_labels[label_text] = vbox_label

		desc_vbox = gtk.VBox()
		desc_sw = gtk.ScrolledWindow()
		desc_sw.set_shadow_type(gtk.SHADOW_NONE)
		desc_sw.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
		desc_sw.add_with_viewport(desc_vbox)
		desc_sw.child.set_shadow_type(gtk.SHADOW_NONE)
		desc_outer_vbox.pack_start(desc_sw)
		desc_outer_vbox.set_size_request(380, 100)

		attrs_vbox = gtk.VBox()
		for (widget, label_text) in widget_list :
			if label_text == "Description" :
				attrs_vbox.pack_start(widget, True, padding = 2)
			else :
				attrs_vbox.pack_start(widget, False, padding = 2)

		self.attrs_vbox = attrs_vbox
		self.required_vbox = required_vbox
		self.optional_vbox = optional_vbox
		self.optional_expander = optional_expander
		self.desc_outer_vbox = desc_outer_vbox
		self.desc_vbox = desc_vbox

	def render_widgets_dtd(self):
		obj_type = self.obj_type
		is_newobj = self.is_newobj
		required_vbox = self.required_vbox
		optional_vbox = self.optional_vbox
		attrs_vbox = self.attrs_vbox

		dtd_elem = self.dtd_elem

		widgets = {}
		name_labels = {}
		value_labels = {}
		combos = {}
		bool_combos = {}
		combo_entries = {}
		required_row = 0
		optional_row = 0
		name_label_max_len = 0

		self.hboxes = {}
		for attr_name in self.attr_list :
			attr = dtd_elem.get_attr(attr_name)
			label_text = _(name_cap(attr_name)) + _(":")
			label = gtk.Label(label_text)
			label.set_alignment(0, 0.5)
			label_len = label.size_request()[0]
			if label_len > name_label_max_len :
				name_label_max_len = label_len
			eventbox = gtk.EventBox()
			eventbox.add(label)
			name_labels[attr_name] = label

			attr_type = attr.get_type()
			attr_default = attr.get_default()
			attr_decl = attr.get_decl()
			
			if attr_name == "id" and is_newobj == False :
				widget = gtk.Label()
				widget.set_alignment(0, 0.5)
				value_labels[attr_name] = widget
			elif type(attr_type) == list:
				is_boolean = False
				store = gtk.ListStore(str, str)
				if attr_decl != "#REQUIRED" :
					store.append(["", ""])
				if attr_type.count("true") > 0 and attr_type.count("false") > 0 :
					options = ("true", "false")
					is_boolean = True
				else: 
					options = attr_type
					
				for option in options:
					if attr_default != None and option == attr_default :
						store.append([option, "["+_("default")+"]"])
					else :
						store.append([option, ""])
				widget = gtk.ComboBox(store)
				cell0 = gtk.CellRendererText()
				cell1 = gtk.CellRendererText()
				widget.pack_start(cell0, True)
				widget.pack_start(cell1, True)
				widget.add_attribute(cell0, 'text', 0)
				widget.add_attribute(cell1, 'text', 1)
				if is_boolean == False :
					combos[attr_name] = widget
				else :
					bool_combos[attr_name] = widget
			else :
				store = gtk.ListStore(str, str)
				if attr_decl != "#REQUIRED" :
					store.append(["", ""])
				if attr_default != None :
					store.append([attr_default, "["+_("default")+"]"])
				widget = gtk.ComboBoxEntry(store)
				cell = gtk.CellRendererText()
				widget.pack_start(cell, True)
				widget.add_attribute(cell, 'text', 1)
				widget.child.set_activates_default(True)
				combo_entries[attr_name] = widget

			
			hbox = gtk.HBox()
			hbox.pack_start(eventbox, False, padding=5)
			hbox.pack_start(widget, padding=5)

			if attr_decl == "#REQUIRED":
				required_vbox.pack_start(hbox, False, padding=2)
			else:
				optional_vbox.pack_start(hbox, False, padding=2)

			self.hboxes[attr_name] = hbox

		attrs_vbox.show_all()

		for name_label in name_labels.values() :
			name_label.set_size_request(name_label_max_len, -1)
		
		widgets["name_labels"] = name_labels
		widgets["value_labels"] = value_labels
		widgets["combos"] = combos
		widgets["bool_combos"] = bool_combos
		widgets["combo_entries"] = combo_entries

		self.widgets = widgets

	def verify_values_dtd(self) :
		widgets = self.widgets
		obj_type = self.obj_type
		passed = True
		dtd_elem = self.dtd_elem
		object = self.get_values()

		for attr_name in self.attr_list :
			attr = dtd_elem.get_attr(attr_name)
			attr_decl = attr.get_decl()
			
			if attr_decl == "#REQUIRED" and not object.has_key(attr_name) :
				msgbox(_(name_cap(attr_name)) + (":")+_(" can't be empty"))
				passed =False
		return passed

	def render_widgets_rng(self):
		obj_type = self.obj_type
		is_newobj = self.is_newobj
		required_vbox = self.required_vbox
		optional_vbox = self.optional_vbox
		attrs_vbox = self.attrs_vbox

		widgets = {}
		name_labels = {}
		value_labels = {}
		combos = {}
		bool_combos = {}
		combo_entries = {}
		required_row = 0
		optional_row = 0
		name_label_max_len = 0


		self.attr_rng_node_dict = {}
		self.elem_rng_node_dict = {}
		attr_is_any_name = False
		any_attr_decl = []
		elem_is_any_name = False
		attr_list = []
		elem_type_list = []
		id_is_idref = False
		sorted_rng_nodes = manager.sorted_sub_rng_nodes_by_name(self.obj_type)
		if sorted_rng_nodes != None :
			attr_rng_nodes = sorted_rng_nodes.get("attribute", [])
			elem_rng_nodes = sorted_rng_nodes.get("element", [])
			for rng_node in attr_rng_nodes :
				name = rng_node[0][1].getAttribute("name")
				if name == "" :
					attr_is_any_name = True
					for decl in ["optional", "zeroOrMore", "oneOrMore"] :
						if manager.find_decl(rng_node, decl) != 0 :
							any_attr_decl.append(decl)
				else:
					if attr_list.count(name) == 0 :
						attr_list.append(name)
						self.attr_rng_node_dict[name] = []
						if name == "id" :
							sub_rng_nodes = manager.sorted_sub_rng_nodes_by_node(*rng_node[0])
							for sub_rng_node in sub_rng_nodes.get("data", []) :
								if sub_rng_nodes["data"][0][0][1].getAttribute("type") == "IDREF" :
									id_is_idref = True
									break
					self.attr_rng_node_dict[name].append(rng_node)

			for rng_node in elem_rng_nodes :
				name = rng_node[0][1].getAttribute("name")
				if name == "" :
					elem_is_any_name = True
				else :
					if elem_type_list.count(name) == 0 :
						elem_type_list.append(name)
						self.elem_rng_node_dict[name] = []
					self.elem_rng_node_dict[name].append(rng_node)
		else :
			attr_is_any_name = True
			any_attr_decl.append("zeroOrMore")
			elem_is_any_name = True
			attr_rng_nodes = []
			elem_rng_nodes = None

		self.attr_list = attr_list
		self.any_attr_decl = any_attr_decl
		self.attr_rng_nodes = attr_rng_nodes
		self.id_is_idref = id_is_idref

		other_attrs = []
		if attr_is_any_name :
			for attr_name in self.xml_node.attributes.keys() :
				if attr_list.count(attr_name) == 0 :
					if attr_name == "id" :
						other_attrs.insert(0, attr_name)
					else :
						other_attrs.append(attr_name)
		attr_list.extend(other_attrs)

		if  any_attr_decl.count("zeroOrMore") or any_attr_decl.count("oneOrMore") :
			other_attrs.append("")

		if elem_rng_nodes == [] and not id_is_idref :
			self.auto_id = True
			self.dynamic_set_id = self.dynamic_set_id_auto
		else :
			self.auto_id = False
					
		sub_elem_node_list = []
		for child_node in self.xml_node.childNodes :
			if child_node.nodeType != xml.dom.Node.ELEMENT_NODE :
				continue
			sub_elem_node_list.append(child_node)
			
		if len(sub_elem_node_list) == 0 : 
			self.pref_expand = True
		else :
			self.pref_expand = False

		self.hboxes = {}
		store_list = {}
		for attr_node in attr_rng_nodes :
			attr_name = attr_node[0][1].getAttribute("name")
			if attr_name == "" :
				continue

			sub_rng_nodes = manager.sorted_sub_rng_nodes_by_node(*attr_node[0])
			if store_list.get(attr_name) != None :
				if len(sub_rng_nodes.get("value",[])) > 0 :
					for value_node in sub_rng_nodes["value"] :
						store_list[attr_name].append([value_node[0][1].childNodes[0].data, ""])
				for sub_rng_node in sub_rng_nodes.get("data", []) :
					if sub_rng_nodes["data"][0][0][1].getAttribute("type") == "boolean" :
						for option in ("true", "false") :
							store_list[attr_name].append([option, ""])
				continue

			label_text = _(name_cap(attr_name)) + _(":")
			label = gtk.Label(label_text)
			label.set_alignment(0, 0.5)
			label_len = label.size_request()[0]
			if label_len > name_label_max_len :
				name_label_max_len = label_len
			eventbox = gtk.EventBox()
			eventbox.add(label)
			name_labels[attr_name] = label

			if attr_name == "id" and not id_is_idref and is_newobj == False :
				widget = gtk.Label()
				widget.set_alignment(0, 0.5)
				value_labels[attr_name] = widget
			elif len(sub_rng_nodes.get("value",[])) > 0 \
					and len(sub_rng_nodes.get("data", [])) == 0 \
					and len(sub_rng_nodes.get("text", [])) == 0 :
				store = gtk.ListStore(str, str)
				store_list[attr_name] = store
				if manager.find_decl(attr_node, "optional") != 0 :
					store.append(["", ""])

				for value_node in sub_rng_nodes["value"] :
					store.append([value_node[0][1].childNodes[0].data, ""])

				#for option in options:
				#	if attr_default != None and option == attr_default :
				#		store.append([option, "["+_("default")+"]"])
				#	else :
				#		store.append([option, ""])

				widget = gtk.ComboBox(store)
				cell0 = gtk.CellRendererText()
				cell1 = gtk.CellRendererText()
				widget.pack_start(cell0, True)
				widget.pack_start(cell1, True)
				widget.add_attribute(cell0, 'text', 0)
				widget.add_attribute(cell1, 'text', 1)
				combos[attr_name] = widget

			elif len(sub_rng_nodes.get("data",[])) == 1 \
					and sub_rng_nodes["data"][0][0][1].getAttribute("type") == "boolean" \
					and len(sub_rng_nodes.get("text", [])) == 0 :
				store = gtk.ListStore(str, str)
				store_list[attr_name] = store
				if manager.find_decl(attr_node, "optional") != 0 :
					store.append(["", ""])

				for option in ("true", "false") :
					store.append([option, ""])

				if len(sub_rng_nodes.get("value",[])) > 0 :
					for value_node in sub_rng_nodes["value"] :
						store.append([value_node[0][1].childNodes[0].data, ""])

				widget = gtk.ComboBox(store)
				cell0 = gtk.CellRendererText()
				cell1 = gtk.CellRendererText()
				widget.pack_start(cell0, True)
				widget.pack_start(cell1, True)
				widget.add_attribute(cell0, 'text', 0)
				widget.add_attribute(cell1, 'text', 1)
				bool_combos[attr_name] = widget

			else :
				store = gtk.ListStore(str, str)
				store_list[attr_name] = store
				if manager.find_decl(attr_node, "optional") != 0 :
					store.append(["", ""])
				#if attr_default != None :
				#	store.append([attr_default, "["+_("default")+"]"])
				if len(sub_rng_nodes.get("value",[])) > 0 :
					for value_node in sub_rng_nodes["value"] :
						store.append([value_node[0][1].childNodes[0].data, ""])

				for sub_rng_node in sub_rng_nodes.get("data", []) :
					if sub_rng_nodes["data"][0][0][1].getAttribute("type") == "boolean"  :
						for option in ("true", "false") :
							store.append([option, ""])

				widget = gtk.ComboBoxEntry(store)
				cell = gtk.CellRendererText()
				widget.pack_start(cell, True)
				widget.add_attribute(cell, 'text', 1)
				widget.child.set_activates_default(True)
				combo_entries[attr_name] = widget
			
			hbox = gtk.HBox()
			hbox.pack_start(eventbox, False, padding=5)
			hbox.pack_start(widget, padding=5)

			if manager.find_decl(attr_node, "optional") == 0 :
				required_vbox.pack_start(hbox, False, padding=2)
			else:
				optional_vbox.pack_start(hbox, False, padding=2)

			self.hboxes[attr_name] = hbox

		anyname_combo_entries = {}
		for attr_name in other_attrs :
			(name_entry, widget) = self.render_anyname_widgets(attr_name)
			anyname_combo_entries[name_entry] = widget

		attrs_vbox.show_all()

		for name_label in name_labels.values() :
			name_label.set_size_request(name_label_max_len, -1)
		
		widgets["name_labels"] = name_labels
		widgets["value_labels"] = value_labels
		widgets["combos"] = combos
		widgets["bool_combos"] = bool_combos
		widgets["combo_entries"] = combo_entries
		widgets["anyname_combo_entries"] = anyname_combo_entries

		self.widgets = widgets

	def render_anyname_widgets(self, attr_name) :
		any_attr_decl = self.any_attr_decl
		name_entry = gtk.Entry()
		name_entry.set_text(attr_name)
		name_entry.set_activates_default(True)

		label = gtk.Label(_(":"))

		store = gtk.ListStore(str, str)
		widget = gtk.ComboBoxEntry(store)
		cell = gtk.CellRendererText()
		widget.pack_start(cell, True)
		widget.add_attribute(cell, 'text', 1)
		widget.child.set_activates_default(True)

		hbox = gtk.HBox()
		hbox.pack_start(name_entry, False, padding=5)
		hbox.pack_start(label, False)
		hbox.pack_start(widget, padding=5)

		if any_attr_decl.count("optional") or any_attr_decl.count("zeroOrMore") :
			self.optional_vbox.pack_start(hbox, False, padding=2)
		elif any_attr_decl.count("oneOrMore") and len(self.widgets.get("anyname_combo_entries", {})) > 0:
			self.optional_vbox.pack_start(hbox, False, padding=2)
		else :
			self.required_vbox.pack_start(hbox, False, padding=2)

		hbox.show_all()

		return (name_entry, widget)

	def verify_values_rng(self) :
		widgets = self.widgets
		obj_type = self.obj_type
		passed = True
		object = self.get_values()

		choice_attrs = []
		for attr_node in self.attr_rng_nodes :
			attr_name = attr_node[0][1].getAttribute("name")

			attr_value = object.get(attr_name)
			if attr_value !=  None and manager.get_rng_attr_type(attr_node) in ["ID", "IDREF"]:
				if not is_valid_id(attr_value) :
					msgbox(_(name_cap(attr_name))+ _(": ")+_("Invalid identifier \"%s\"")%attr_value)
					passed = False

			if object.has_key(attr_name) or manager.find_decl(attr_node, "optional") != 0 \
					or manager.find_decl(attr_node, "zeroOrMore") != 0 :
				continue

			if manager.find_decl(attr_node, "choice") == 0  :
				msgbox(_(name_cap(attr_name))+ _(":")+_(" can't be empty"))
				passed = False
			else :
				choice_attrs.append(attr_node)

		return passed

	def combobox_store_append(self, combo, append_options) :
		current_store = combo.get_model()
		retained_store = []
		for i in range(len(current_store)) :
			if current_store[i][0] == "" :
				retained_store.insert(0, current_store[i])
			elif current_store[i][1] == "["+_("default")+"]" :
				retained_store.append(current_store[i])
			
		new_store = gtk.ListStore(str, str)
		for retained in retained_store :
			new_store.append(retained)
		retained_list = [k[0] for k in retained_store]
		for append_option in append_options :
			if retained_list.count(append_option[0]) == 0 :
				new_store.append(append_option)
		combo.set_model(new_store)

	def auto_fill(self) :
		widgets = self.widgets
		rsc_store = gtk.ListStore(str, str)
		all_real_rsc = manager.get_all_real_rsc()
		for rsc in all_real_rsc :
			rsc_store.append([rsc, ""])

		node_list = manager.get_normal_nodes()
		if node_list == None :
			node_list = []
		node_store = [[node, ""] for node in node_list]

		all_templates = manager.get_all_templates()
		template_store = [[template, ""] for template in all_templates]

		rsc_refs = all_real_rsc[:]
		rsc_refs.extend(all_templates)
		rsc_refs_store = [[rsc, ""] for rsc in rsc_refs]

		if widgets.has_key("combo_entries") :
			for key in ["rsc", "with-rsc", "first", "then", "from", "to"] :
				if widgets["combo_entries"].has_key(key) :
					if self.obj_type == "rsc_location" :
						self.combobox_store_append(widgets["combo_entries"][key], rsc_store)
					else :
						self.combobox_store_append(widgets["combo_entries"][key], rsc_refs_store)
			if widgets["combo_entries"].has_key("id") and self.id_is_idref :
				self.combobox_store_append(widgets["combo_entries"]["id"], rsc_store)

			for key in ["template"] :
				if widgets["combo_entries"].has_key(key) :
					self.combobox_store_append(widgets["combo_entries"][key], template_store)

			for key in ["node"] :
				if widgets["combo_entries"].has_key(key) :
					self.combobox_store_append(widgets["combo_entries"][key], node_store)

			if widgets["combo_entries"].has_key("role-ref") :
				acl_roles = []
				for acls in manager.xml_nodes["cib"].getElementsByTagName("acls") :
					for acl_role in acls.getElementsByTagName("acl_role") :
						acl_role_id = acl_role.getAttribute("id")
						if acl_role_id != "" and acl_roles.count(acl_role_id) == 0 :
							acl_roles.append(acl_role_id)
				acl_role_store = [[acl_role, ""] for acl_role in acl_roles]
				self.combobox_store_append(widgets["combo_entries"]["role-ref"], acl_role_store)

		role_attr_type = None
		if validate_type == "dtd" :
			try :
				op_dtd_elem = manager.get_dtd_elem("op")
				role_attr = op_dtd_elem.get_attr("role")
				role_attr_type = role_attr.get_type()
			except KeyError :
				pass

		if role_attr_type != None and type(role_attr_type) == list :
			roles = role_attr_type
		else :
			roles = ["Master", "Slave", "Started", "Stopped"]

		role_store = [[role, ""] for role in roles]
		if widgets.has_key("combo_entries") :
			for key in ["role", "from_role", "to_role"] :
				if widgets["combo_entries"].has_key(key) :
					self.combobox_store_append(widgets["combo_entries"][key], role_store)

		if validate_type != "dtd" :
			return

		scores = ["INFINITY", "-INFINITY"]
		score_store = [[score, ""] for score in scores]
		if widgets.has_key("combo_entries") and widgets["combo_entries"].has_key("score") :
			self.combobox_store_append(widgets["combo_entries"]["score"], score_store)


	def on_changed(self, widget) :
		if self.dynamic_layout != None :
			self.dynamic_layout(widget)

		if self.dynamic_choice != None and validate_type != "dtd" :
			self.dynamic_choice(widget)

		if self.dynamic_fill != None :
			self.dynamic_fill(widget)
		if self.dynamic_desc != None :
			desc = self.dynamic_desc(widget)
			if desc != None :
				self.show_desc(desc)

		self.save()

	def on_changed_later(self, widget) :
		if self.dynamic_layout != None :
			self.dynamic_layout(widget)

		if self.dynamic_choice != None and validate_type != "dtd" :
			self.dynamic_choice(widget)

		if self.dynamic_fill != None :
			self.dynamic_fill(widget)
		if self.dynamic_desc != None :
			desc = self.dynamic_desc(widget)
			if desc != None :
				self.show_desc(desc)
		if self.change_call_back != None :
			self.change_call_back()

		if self.dynamic_render != None :
			self.dynamic_render(widget)

		if self.dynamic_set_id != None :
			self.dynamic_set_id(widget)

		save_id = self.xml_node.getAttribute("id")
		if save_id != "" :
			self.save_id = save_id

		self.save()

		new_id = self.xml_node.getAttribute("id")
		if self.save_id != None and new_id != "" and new_id != self.save_id :
			self.auto_change_child_ids(self.xml_node, new_id)

	def auto_change_child_ids(self, xml_node, new_id) :
		for child_node in xml_node.childNodes :
			if child_node.nodeType != xml.dom.Node.ELEMENT_NODE :
				continue
			id = child_node.getAttribute("id")
			if id.count(self.save_id + "-") > 0 :
				child_node.setAttribute("id", id.replace(self.save_id + "-", new_id + "-"))
			self.auto_change_child_ids(child_node, new_id)

	def dynamic_render(self, widget) :
		if widget in self.widgets.get("anyname_combo_entries", {}) :
			changed_attr_name = widget.get_text()
			if len(changed_attr_name) > 0 :
				need_add = True
				for name_widget in self.widgets["anyname_combo_entries"] :
					if name_widget.get_text() == "" :
						need_add = False
						break
				if need_add :
					(name_entry, widget) = self.render_anyname_widgets("")
					self.widgets["anyname_combo_entries"][name_entry] = widget
					name_entry.connect("changed", self.on_changed_later)
					widget.connect("changed", self.on_changed_later)

	def show_desc(self, desc) :
		widgets = self.widgets
		desc_vbox = self.desc_vbox

		if not widgets.has_key("desc_labels") :
			desc_labels = []
			for row in range(len(desc)) :
				desc_label = gtk.Label(desc[row])
				desc_label.set_alignment(0, 0.5)
				desc_label.set_padding(5, 0)
				desc_label.set_line_wrap(True)
				desc_label.set_selectable(True)
				desc_vbox.pack_start(desc_label, False, padding=2)
				desc_labels.append(desc_label)
			if desc_labels != [] :
				widgets["desc_labels"] = desc_labels
		else :
			for row in range(len(desc)) :
				widgets["desc_labels"][row].set_text(desc[row])
		desc_vbox.show_all()

	def update(self, xml_node = None) :
		if xml_node != None :
			self.xml_node = xml_node
		object_attrs = {}
		for attr_name in self.attr_list :
			attr_value = self.xml_node.getAttribute(attr_name)
			if attr_value != None :
				object_attrs[attr_name] = attr_value

		self.show_values(object_attrs)

	def save(self) :
		object_attrs = self.get_values()
		for attr_name in object_attrs :
			self.xml_node.setAttribute(attr_name, object_attrs.get(attr_name , ""))

		for attr_name in self.xml_node.attributes.keys() :
			if object_attrs.get(attr_name) == None :
				self.xml_node.removeAttribute(attr_name)

	def save_status(self) :
		return self.optional_expander.get_expanded()

	def restore_status(self, saved_status) :
		self.optional_expander.set_expanded(saved_status)

	def get_score(self, score_str) :
		try :
			score = int(score_str)
		except :
			if score_str in ["INFINITY", "infinity", "+INFINITY", "+infinity"] :
				score = 1000000
			elif score_str in ["-INFINITY", "-infinity"] :
				score = -1000000
			else :
				score = 0
		return score

	def dynamic_choice(self, widget) :
		widgets = self.widgets
		attr_rng_node_dict = self.attr_rng_node_dict
		attr_name = None
		for widget_type in widgets :
			if type(widgets[widget_type]) != dict :
				continue
			for key in widgets[widget_type] :
				if widgets[widget_type][key] == widget :
					attr_name = key
					break

		if attr_name == None :
			return

		attr_rng_nodes = attr_rng_node_dict.get(attr_name)
		if attr_rng_nodes == None :
			return

		object_attrs = self.get_values()

		ref_match_value_decl_nodes_list = []
		ref_decl_nodes_list = []
		for key in object_attrs :
			for attr_rng_node in attr_rng_node_dict.get(key, []) :
				decl_rng_nodes = manager.get_decl_rng_nodes(attr_rng_node)
				value_list = []
				sub_rng_nodes = manager.sorted_sub_rng_nodes_by_node(*attr_rng_node[0])
				for value_node in sub_rng_nodes.get("value", []) :
					value_list.append(value_node[0][1].childNodes[0].data)
				if object_attrs.get(key, "") in value_list :
					ref_match_value_decl_nodes_list.append(decl_rng_nodes)
				elif len(sub_rng_nodes.get("data", [])) > 0 or len(sub_rng_nodes.get("text", [])) > 0 :
					ref_decl_nodes_list.append(decl_rng_nodes)

		if len(ref_match_value_decl_nodes_list) > 0 :
			ref_decl_nodes_list = ref_match_value_decl_nodes_list

		ref_sorted_nodes = {}
		for decl_type in ["choice", "first_choice", "group", "first_group"] :
			ref_sorted_nodes[decl_type] = manager.get_sorted_decl_nodes(ref_decl_nodes_list, decl_type)
			
		match_value_decl_nodes_list = []
		decl_nodes_list = []
		for attr_rng_node in attr_rng_nodes :
			decl_rng_nodes = manager.get_decl_rng_nodes(attr_rng_node)
			if decl_rng_nodes.get("choice") == None :
				return

			if decl_rng_nodes.get("choice") in ref_sorted_nodes["choice"] and \
					decl_rng_nodes.get("group") != None and \
					len(ref_sorted_nodes["group"]) > 0 and \
					decl_rng_nodes.get("group") not in ref_sorted_nodes["group"] :
				continue

			value_list = []
			sub_rng_nodes = manager.sorted_sub_rng_nodes_by_node(*attr_rng_node[0])
			for value_node in sub_rng_nodes.get("value", []) :
				value_list.append(value_node[0][1].childNodes[0].data)
			if object_attrs.get(attr_name, "") in value_list :
				match_value_decl_nodes_list.append(decl_rng_nodes)
			else :
				if len(sub_rng_nodes.get("data", [])) > 0 or len(sub_rng_nodes.get("text", [])) > 0 :
					decl_nodes_list.append(decl_rng_nodes)

		if len(match_value_decl_nodes_list) > 0 :
			decl_nodes_list = match_value_decl_nodes_list

		sorted_nodes = {}
		for decl_type in ["choice", "first_choice", "group", "first_group"] :
			sorted_nodes[decl_type] = manager.get_sorted_decl_nodes(decl_nodes_list, decl_type)

		friend_attrs = []
		opposite_attrs = []
		sub_opposite_attrs = []
		for key in attr_rng_node_dict :
			if key == attr_name :
				continue

			match_value = False
			for attr_rng_node in attr_rng_node_dict[key] :
				decl_rng_nodes = manager.get_decl_rng_nodes(attr_rng_node)
				if decl_rng_nodes.get("choice") == None or \
						decl_rng_nodes.get("choice") not in sorted_nodes["choice"] :
					continue

				value_list = []
				sub_rng_nodes = manager.sorted_sub_rng_nodes_by_node(*attr_rng_node[0])
				for value_node in sub_rng_nodes.get("value", []) :
					value_list.append(value_node[0][1].childNodes[0].data)
				if object_attrs.get(key, "") in value_list :
					if key in friend_attrs :
						friend_attrs.remove(key)
					if key in opposite_attrs :
						opposite_attrs.remove(key)
					if key in sub_opposite_attrs :
						sub_opposite_attrs.remove(key)
					match_value = True

				if len(sorted_nodes["group"]) == 0 :
					opposite_attrs.append(key)
				else :
					if decl_rng_nodes.get("group") not in sorted_nodes["group"] :
						if key not in opposite_attrs :
							opposite_attrs.append(key)
					elif decl_rng_nodes.get("first_choice") in sorted_nodes["first_choice"] and \
							decl_rng_nodes.get("first_group") not in sorted_nodes["first_group"] :
						if key not in sub_opposite_attrs :
							sub_opposite_attrs.append(key)
					else :
						if key not in friend_attrs :
							friend_attrs.append(key)

				if match_value :
					break

		if len(opposite_attrs) == 0 and len(sub_opposite_attrs) == 0 and len(friend_attrs) == 0 :
			return

		if object_attrs.get(attr_name, "") == "" :
			friends_clean = True
			for key in friend_attrs :
				if object_attrs.get(key, "") != "" :
					friends_clean = False
					break
			if friends_clean :
				self.set_sensibility(opposite_attrs, True)

			self.set_sensibility(sub_opposite_attrs, True)
		else :
			self.set_sensibility(opposite_attrs, False)
			self.set_sensibility(sub_opposite_attrs, False)
			self.set_sensibility(friend_attrs, True)

	def dynamic_choice_elem(self) :
		elem_rng_node_dict = self.elem_rng_node_dict
		attr_rng_node_dict = self.attr_rng_node_dict

		object_attrs = self.get_values()

		ref_match_value_decl_nodes_list = []
		ref_decl_nodes_list = []
		for key in object_attrs :
			for attr_rng_node in attr_rng_node_dict.get(key, []) :
				decl_rng_nodes = manager.get_decl_rng_nodes(attr_rng_node)
				value_list = []
				sub_rng_nodes = manager.sorted_sub_rng_nodes_by_node(*attr_rng_node[0])
				for value_node in sub_rng_nodes.get("value", []) :
					value_list.append(value_node[0][1].childNodes[0].data)
				if object_attrs.get(key, "") in value_list :
					ref_match_value_decl_nodes_list.append(decl_rng_nodes)
				elif len(sub_rng_nodes.get("data", [])) > 0 or len(sub_rng_nodes.get("text", [])) > 0 :
					ref_decl_nodes_list.append(decl_rng_nodes)

		if len(ref_match_value_decl_nodes_list) > 0 :
			ref_decl_nodes_list = ref_match_value_decl_nodes_list

		ref_sorted_nodes = {}
		for decl_type in ["choice", "first_choice", "group", "first_group"] :
			ref_sorted_nodes[decl_type] = manager.get_sorted_decl_nodes(ref_decl_nodes_list, decl_type)
			
		elem_node_dict = {}
		for elem_node in self.xml_node.childNodes :
			if elem_node.nodeType != xml.dom.Node.ELEMENT_NODE :
				continue
			elem_type = elem_node.tagName
			if not elem_node_dict.has_key(elem_type) :
				elem_node_dict[elem_type] = []
			elem_node_dict[elem_type].append(elem_node)

		decl_nodes_list = []
		for key in elem_node_dict :
			for elem_rng_node in elem_rng_node_dict.get(key, []):
				if len(elem_node_dict[key]) > 1 and manager.find_decl(elem_rng_node, "oneOrMore") == 0 \
						and manager.find_decl(elem_rng_node, "zeroOrMore") == 0 :
					continue

				decl_rng_nodes = manager.get_decl_rng_nodes(elem_rng_node)
				if decl_rng_nodes.get("choice") == None :
					return

				if decl_rng_nodes.get("choice") in ref_sorted_nodes["choice"] and \
						decl_rng_nodes.get("group") != None and \
						len(ref_sorted_nodes["group"]) > 0 and \
						decl_rng_nodes.get("group") not in ref_sorted_nodes["group"] :
					continue

				decl_nodes_list.append(decl_rng_nodes)

		sorted_nodes = {}
		for decl_type in ["choice", "first_choice", "group", "first_group"] :
			sorted_nodes[decl_type] = manager.get_sorted_decl_nodes(decl_nodes_list, decl_type)

		friend_attrs = []
		opposite_attrs = []
		sub_opposite_attrs = []
		for key in attr_rng_node_dict :
			match_value = False
			for attr_rng_node in attr_rng_node_dict[key] :
				decl_rng_nodes = manager.get_decl_rng_nodes(attr_rng_node)
				if decl_rng_nodes.get("choice") == None or \
						decl_rng_nodes.get("choice") not in sorted_nodes["choice"] :
					friend_attrs.append(key)
					continue

				value_list = []
				sub_rng_nodes = manager.sorted_sub_rng_nodes_by_node(*attr_rng_node[0])
				for value_node in sub_rng_nodes.get("value", []) :
					value_list.append(value_node[0][1].childNodes[0].data)
				if object_attrs.get(key, "") in value_list :
					if key in friend_attrs :
						friend_attrs.remove(key)
					if key in opposite_attrs :
						opposite_attrs.remove(key)
					if key in sub_opposite_attrs :
						sub_opposite_attrs.remove(key)
					match_value = True

				if len(sorted_nodes["group"]) == 0 :
					opposite_attrs.append(key)
				else :
					if decl_rng_nodes.get("group") not in sorted_nodes["group"] :
						if key not in opposite_attrs :
							opposite_attrs.append(key)
					elif decl_rng_nodes.get("first_choice") in sorted_nodes["first_choice"] and \
							decl_rng_nodes.get("first_group") not in sorted_nodes["first_group"] :
						if key not in sub_opposite_attrs :
							sub_opposite_attrs.append(key)
					else :
						if key not in friend_attrs :
							friend_attrs.append(key)

				if match_value :
					break

		if len(opposite_attrs) == 0 and len(sub_opposite_attrs) == 0 and len(friend_attrs) == 0 :
			return

		self.set_sensibility(opposite_attrs, False)
		self.set_sensibility(sub_opposite_attrs, False)
		self.set_sensibility(friend_attrs, True)

	def set_sensibility(self, keys, sensibility) :
		widgets = self.widgets
		for widget_type in widgets :
			if type(widgets[widget_type]) != dict :
				continue
			for key in widgets[widget_type] :
				if key in keys :
					widgets[widget_type][key].set_sensitive(sensibility)

	def set_id_widget(self, id) :
		widgets = self.widgets
		if self.is_newobj :
			if widgets.get("combo_entries", {}).has_key("id") :
				widgets["combo_entries"]["id"].child.set_text(id)
		else :
			if widgets.get("value_labels", {}).has_key("id") :
				widgets["value_labels"]["id"].set_text(id)

	def hide_id_widget(self) :
		widgets = self.widgets
		if widgets.get("name_labels", {}).has_key("id") :
			widgets["name_labels"]["id"].hide_all()
		if self.is_newobj :
			if widgets.get("combo_entries", {}).has_key("id") :
				widgets["combo_entries"]["id"].hide_all()
		else :
			if widgets.get("value_labels", {}).has_key("id") :
				widgets["value_labels"]["id"].hide_all()

	def dynamic_set_id_auto(self, widget) :
		key_attrs = ["name", "attribute"]
		widgets = self.widgets
		if not widgets.has_key("combo_entries") :
			return
		if widget not in [widgets["combo_entries"].get(attr) for attr in key_attrs] :
			return
				
		object_attrs = self.get_values()
		for attr in key_attrs :
			name = object_attrs.get(attr, "")
			if name != "" :
				break

		if name == "" :
			name = self.obj_type
			
		new_id = manager.auto_unique_id(self.xml_node, name)
		self.set_id_widget(new_id)

class Primitive(ObjectAttrs) :
	def dynamic_fill(self, widget) :
		widgets = self.widgets

		primitive = self.get_values()
		primitive_class = primitive.get("class", "")
		if primitive_class == "" :
			return

		if widgets.has_key("combos") and widgets["combos"].has_key("class") \
				and widget == widgets["combos"]["class"] :
			ra_list = manager.get_rsc_types(primitive_class)
			self.fill_provider(primitive, ra_list)
			self.fill_type(primitive, ra_list)

		elif widgets.has_key("combo_entries") and widgets["combo_entries"].has_key("provider") \
				and widget == widgets["combo_entries"]["provider"] :
			ra_list = manager.get_rsc_types(primitive_class)
			self.fill_type(primitive, ra_list)

	def fill_provider(self, primitive, ra_list = None) :
		widgets = self.widgets
		primitive_class = primitive.get("class", "")

		provider_list = []
		if primitive_class == "ocf" and ra_list != None :
			for ra in ra_list :
				providers = manager.get_rsc_providers(primitive_class, ra)
				for provider in providers :
					if provider_list.count(provider) == 0 :
						provider_list.append(provider)

		providers_store = [[provider, ""] for provider in provider_list]
		if widgets.has_key("combo_entries") and widgets["combo_entries"].has_key("provider") :
			self.combobox_store_append(widgets["combo_entries"]["provider"], providers_store)
		#	if provider_list != None and len(provider_list) > 0 :
		#		widgets["combo_entries"]["provider"].child.set_text(provider_list[0])

	def fill_type(self, primitive, ra_list = None) :
		widgets = self.widgets
		primitive_class = primitive.get("class", "")
		primitive_provider = primitive.get("provider", "")
		if ra_list != None :
			ra_list.sort()
			if primitive_class != "ocf" or primitive_provider == "" :
				type_store = [[ra, ""] for ra in ra_list]
			else :
				type_store = []
				for ra in ra_list :
					provider_list = manager.get_rsc_providers(primitive_class, ra)
					if provider_list != None and primitive_provider in provider_list :
						type_store.append([ra, ""])

			if widgets.has_key("combo_entries") and widgets["combo_entries"].has_key("type") :
				self.combobox_store_append(widgets["combo_entries"]["type"], type_store)

	def dynamic_desc(self, widget) :
		widgets = self.widgets
		desc = None
		if widgets.has_key("combos") and widgets["combos"].has_key("class") \
				and widget == widgets["combos"]["class"] :
			desc = self.get_meta_desc()

		if widgets.has_key("combo_entries") and widgets["combo_entries"].has_key("type") \
				and widget == widgets["combo_entries"]["type"] :
			desc = self.get_meta_desc()

		if widgets.has_key("combo_entries") and widgets["combo_entries"].has_key("provider") \
				and widget == widgets["combo_entries"]["provider"] :
			desc = self.get_meta_desc()

		if widgets.has_key("combo_entries") and widgets["combo_entries"].has_key("template") \
				and widget == widgets["combo_entries"]["template"] :
			desc = self.get_meta_desc()

		return desc

	def get_meta_desc(self) :
		primitive = self.get_values()
		primitive_template = primitive.get("template")

		title = ""
		if not primitive_template :
			primitive_class = primitive.get("class", "")
			primitive_type = primitive.get("type", "")
			primitive_provider = primitive.get("provider", "heartbeat")
		else :
			template_node = manager.get_template(primitive_template)
			if template_node == None :
				return [""]

			primitive_attrs = manager.get_rsc_attrs(template_node, ["class", "type", "provider"])
			primitive_class = str(primitive_attrs.get("class", ""))
			primitive_type = str(primitive_attrs.get("type", ""))
			primitive_provider = str(primitive_attrs.get("provider", "heartbeat"))

			title = "%s:%s:%s\n\n"%(primitive_class, primitive_provider, primitive_type)

		meta = manager.get_rsc_meta(primitive_class, primitive_type, primitive_provider) 
		if meta == None :
			return [""]

		longdesc = meta.longdesc
		if longdesc == None :
			longdesc = ""
		else :
			longdesc = longdesc.replace(_(".  "), _(".\n"))

		shortdesc = meta.shortdesc
		if shortdesc == None :
			shortdesc = ""

		if len(longdesc) == 0 :
			desc = [title + shortdesc]
		elif longdesc.find(shortdesc) > -1 :
			desc = [title + longdesc]
		else :
			if shortdesc.endswith(_(".")) :
				desc = [title + shortdesc + "\n" + longdesc]
			else :
				desc = [title + shortdesc + _(".") + "\n" + longdesc]
		return desc

	def verify_values(self) :
		if not ObjectAttrs.verify_values(self) :
			return False

		primitive = self.get_values()
		if primitive.get("template", "") == "" and primitive.get("class", "") == "" :
			msgbox(_("\"%s\" or \"%s\" is required")%(_("Class"), _("Template")))
			return False

		if primitive.get("class", "") == "ocf" and primitive.get("provider", "") == "" :
			msgbox(_("\"%s\" is required")%_("Provider") + " " +
					_("for an OCF primitive"))
			return False

		return True

class MetaAttrsNV(ObjectAttrs) :
	def __init__(self, xml_node, is_newobj = False, change_call_back = None) :
		common_options = [
		("priority", [], 
		 _("If not all resources can be active, the cluster will stop lower priority resources in order to keep higher priority ones active.")), 
		("target-role", [["Started", _("[ default ]")], ["Stopped", ""]],
		 _("What state should the cluster attempt to keep this resource in?")),
		("is-managed", [["true", _("[ default ]")], ["false", ""]],
		 _("Is the cluster allowed to start and stop the resource?"))
		]

		primitive_options = [
		("resource-stickiness", [],
		 _("How much does the resource prefer to stay where it is? Defaults to the value of \"default-resource-stickiness\"")),
		("migration-threshold", [],
		 _("How many failures should occur for this resource on a node before making the node ineligible to host this resource. Default: \"none\"")),
		("multiple-active", [["stop_start", _("[ default ]")], ["stop_only", ""], ["block", _("(mark the resource as unmanaged)")]],
		 _("What should the cluster do if it ever finds the resource active on more than one node.")),
		("failure-timeout", [],
		 _("How many seconds to wait before acting as if the failure had not occurred (and potentially allowing the resource back to the node on which it failed. Default: \"never\"")),
		("allow-migrate", [["false", _("[ default ]")], ["true", ""]],
		 _("Allow resource migration for resources which support migrate_to/migrate_from actions"))
		]

		clone_basic_options = [
		("clone-max", [],
		 _("How many copies of the resource to start. Defaults to the number of nodes in the cluster.")),
		("clone-node-max", [["1", _("[ default ]")]],
		 _("How many copies of the resource can be started on a single node.")),
		]
		clone_other_options = [
		("notify", [["false", _("[ default ]")], ["true", ""]],
		 _("When stopping or starting a copy of the clone, tell all the other copies beforehand and when the action was successful.")),
		("globally-unique", [["false", _("[ default ]")], ["true", ""]],
		 _("Does each copy of the clone perform a different function?")),
		("ordered", [["false", _("[ default ]")], ["true", ""]],
		 _("Should the copies be started in series (instead of in parallel)")),
		("interleave", [["false", _("[ default ]")], ["true", ""]],
		 _("Changes the behavior of ordering constraints (between clones/masters) so that instances can start/stop as soon as their peer instance has (rather than waiting for every instance of the other clone has)."))
		]

		master_basic_options = [
		("master-max", [["1", _("[ default ]")]],
		 _("How many copies of the resource can be promoted to master status.")),
		("master-node-max", [["1", _("[ default ]")]],
		 _("How many copies of the resource can be promoted to master status on a single node."))
		]

		self.meta_attributes_options = {
		"primitive": common_options + primitive_options,
		"template": common_options + primitive_options,
		"group": common_options,
		"clone": common_options + clone_basic_options + clone_other_options,
		"master": common_options + clone_basic_options + master_basic_options + clone_other_options,
		"rsc_defaults": common_options + primitive_options,
		}

		if validate_type == "dtd" :
			self.target_node = xml_node.parentNode.parentNode.parentNode
			self.target_type = self.target_node.tagName
			self.target_dtd_elem = manager.get_dtd_elem(self.target_type)
			self.target_attrlist = self.target_dtd_elem.get_attr_list()
			self.auto_fill = self.auto_fill_dtd
			self.dynamic_fill = self.dynamic_fill_dtd
		else :
			self.target_node = xml_node.parentNode.parentNode
			self.target_type = self.target_node.tagName
			self.auto_fill = self.auto_fill_rng
			self.dynamic_fill = self.dynamic_fill_rng
			self.dynamic_desc = self.dynamic_desc_rng
			
		ObjectAttrs.__init__(self, xml_node, is_newobj, change_call_back)

	def auto_fill_rng(self) :
		widgets = self.widgets
		name_store = [[option[0], ""] for option in self.meta_attributes_options.get(self.target_type, [])]
		if widgets.get("combo_entries", {}).has_key("name") :
			self.combobox_store_append(widgets["combo_entries"]["name"], name_store)

	def dynamic_fill_rng(self, widget) :
		widgets = self.widgets
		if widgets.get("combo_entries", {}).has_key("name") \
				and widget == widgets["combo_entries"]["name"] :
			value_store = []
			nvpair = self.get_values()
			if nvpair.has_key("name") :
				options = self.meta_attributes_options.get(self.target_type, [])
				for i in range(len(options)) :
					if options[i][0] == nvpair["name"] :
						value_store = options[i][1]
						break

			if widgets.get("combo_entries", {}).has_key("value") :
				self.combobox_store_append(widgets["combo_entries"]["value"], value_store)

	def dynamic_desc_rng(self, widget) :
		widgets = self.widgets
		if widgets.get("combo_entries", {}).get("name") != widget :
			return None

		desc = [""]
		nvpair =  self.get_values()
		if nvpair.has_key("name") :
			options = self.meta_attributes_options.get(self.target_type, [])
			for i in range(len(options)) :
				if options[i][0] == nvpair["name"] :
					desc = [options[i][2]]
					break

		return desc

	def auto_fill_dtd(self) :
		widgets = self.widgets
		attr_store = []

		if self.target_type in ["primitive", "template", "group", "clone", "master_slave"] :
			attr_store.append(["target_role", ""])

		for attr_name in self.target_attrlist :
			attr = self.target_dtd_elem.get_attr(attr_name)
			if attr.get_decl() !=  "#REQUIRED" :
				attr_store.append([attr_name, ""])

		if self.target_type in ["clone", "master_slave"] :
			attr_store.extend([attr_name, ""] for attr_name in ["clone_max", "clone_node_max"])

		if self.target_type == "master_slave" :
			attr_store.extend([attr_name, ""] for attr_name in ["master_max", "master_node_max"])


		if widgets.has_key("combo_entries") and widgets["combo_entries"].has_key("name") :
			self.combobox_store_append(widgets["combo_entries"]["name"], attr_store)

	def dynamic_fill_dtd(self, widget) :
		widgets = self.widgets
		options_dict = {"target_role": ["started", "stopped", "default"]}

		if widgets.has_key("combo_entries") and widgets["combo_entries"].has_key("name") \
				and widget == widgets["combo_entries"]["name"] :
			metaattr = self.get_values()
			attr_name = metaattr.get("name", None)
			if attr_name == None :
				return
			value_store = []
			if attr_name in self.target_attrlist :
				attr = self.target_dtd_elem.get_attr(attr_name)
				attr_type = attr.get_type()
				attr_default = attr.get_default()
				if  type(attr_type) == list :
					if attr_type.count("true") > 0 and attr_type.count("false") > 0 :
						options = ("true", "false")
					else :
						options = attr_type
					for option in options :
						if attr_default != None and option == attr_default :
							value_store.append([attr_default, "[ " + _("default") + " ]"])
						else :
							value_store.append([option, ""])
				elif attr_default != None :
					value_store.append([attr_default, "["+_("default")+"]"])
			elif attr_name in options_dict.keys() :
				value_store.extend([attr_value, ""] for attr_value in options_dict[attr_name])
				if self.target_node.parentNode.tagName == "clone" :
					value_store.extend([attr_value, ""] for attr_value in ["master", "slave"])

			if widgets.has_key("combo_entries") and widgets["combo_entries"].has_key("value") :
				self.combobox_store_append(widgets["combo_entries"]["value"], value_store)

class MetaNV(ObjectAttrs) :
	meta = None
	def auto_fill(self) :
		widgets = self.widgets
		meta = self.meta
		if meta != None :
			instattr_store = []
			for param in meta.parameters :
				param_attr = ""
				if param.get("required", None) == "1" :
					param_attr =  param_attr + _("required")
				if param.get("unique", None) == "1" :
					if param_attr != "" :
						param_attr = param_attr + _(", ")
					param_attr = param_attr + _("unique")
				if param_attr != "" :
					param_attr = "[ "+ param_attr + " ]"
				instattr_store.append([param["name"], param_attr])
					
			if widgets.has_key("combo_entries") and widgets["combo_entries"].has_key("name") :
				self.combobox_store_append(widgets["combo_entries"]["name"], instattr_store)

	def dynamic_fill(self, widget) :
		widgets = self.widgets
		meta = self.meta
		if widgets.has_key("combo_entries") and widgets["combo_entries"].has_key("name") \
				and widget == widgets["combo_entries"]["name"] \
				and meta != None :
			instattr = self.get_values()
			value_store = []
			if instattr.has_key("name") :
				for param in meta.parameters :
					if instattr["name"] == param["name"] :
						param_type = param["content"].get("type")
						options = []
						default_value = param["content"]["default"]
						if param_type == "boolean" :
							boolean_values = [["true", "false"], ["yes", "no"], ["1", "0"]]
							if default_value :
								options = None
								for value_pair in boolean_values :
									if default_value in value_pair :
										options = value_pair
										break
								if options == None :
									options = [default_value]
							else :
								options = boolean_values[0]
						elif param_type == "enum" and param["content"].has_key("values"):
							options =  param["content"]["values"]
						elif default_value != None :
							options = [default_value]

						for option in options :
							if default_value != None and option == default_value :
								value_store.insert(0, [option, "[ "+ _("default") + " ]"])
							else :
								value_store.append([option, ""])
						break
			if widgets.has_key("combo_entries") and widgets["combo_entries"].has_key("value") :
				self.combobox_store_append(widgets["combo_entries"]["value"], value_store)

	def dynamic_desc(self, widget) :
		widgets = self.widgets
		meta = self.meta
		if meta == None or not widgets.has_key("combo_entries") \
				or widget != widgets["combo_entries"].get("name") :
			return None

		desc = [""]
		instattr = self.get_values()
		if instattr.has_key("name") :
			for param in meta.parameters :
				if instattr["name"] == param["name"] :		
					longdesc = param.get("longdesc", "").replace(_(".  "), _(".\n"))
					shortdesc = param.get("shortdesc", "")

					if len(longdesc) == 0 :
						desc = [shortdesc]
					elif longdesc.find(shortdesc) > -1 :
						desc = [longdesc]
					else :
						if shortdesc.endswith(_(".")) :
							desc = [shortdesc + "\n" + longdesc]
						else :
							desc = [shortdesc + _(".") + "\n" + longdesc]
					break
		return desc

class CRMConfNV(MetaNV) :
	meta = None
	def __init__(self, xml_node, is_newobj = False, change_call_back = None) :
		self.meta = manager.get_crm_metadata("pengine")
		crmd_meta = manager.get_crm_metadata("crmd")
		if self.meta != None :
			if crmd_meta != None:
				self.meta.parameters.extend(crmd_meta.parameters)
				params = {}
				for param in self.meta.parameters :
					params[param["name"]] = param

				param_names = params.keys()
				param_names.sort()
				self.meta.parameters = []
				for param_name in param_names :
					self.meta.parameters.append(params[param_name]) 
		else :
			self.meta = crmd_meta
		MetaNV.__init__(self, xml_node, is_newobj, change_call_back)

class PrimInstAttrsNV(MetaNV) :
	meta = None
	def __init__(self, xml_node, is_newobj = False, change_call_back = None) :
		if validate_type == "dtd" :
			primitive_node = xml_node.parentNode.parentNode.parentNode
		else :
			primitive_node = xml_node.parentNode.parentNode

		primitive_attrs = manager.get_rsc_attrs(primitive_node, ["class", "type", "provider"])
		primitive_class = str(primitive_attrs.get("class", ""))
		primitive_type = str(primitive_attrs.get("type", ""))
		primitive_provider = str(primitive_attrs.get("provider", ""))

		self.meta = manager.get_rsc_meta(primitive_class, primitive_type, primitive_provider)
		MetaNV.__init__(self, xml_node, is_newobj, change_call_back)

class OPInstAttrsNV(ObjectAttrs) :
	def auto_fill(self) :
		widgets = self.widgets
		name_store = [["OCF_CHECK_LEVEL", ""]]
		if widgets.get("combo_entries", {}).has_key("name") :
			self.combobox_store_append(widgets["combo_entries"]["name"], name_store)

class UtilizationNV(ObjectAttrs) :
	def auto_fill(self) :
		widgets = self.widgets
		utilization_names = ["cpu", "memory"]
		name_store = [[name, ""] for name in utilization_names]
		if widgets.get("combo_entries", {}).has_key("name") :
			self.combobox_store_append(widgets["combo_entries"]["name"], name_store)

class InstAttrsNV(ObjectAttrs) :
	def __init__(self, xml_node, is_newobj = False, change_call_back = None) :
		self.attributes_options = {
		"node": [
		("standby", [["false", "[ default ]"], ["true", ""]]),
		("cpu_mips", [])
		]
		}

		if validate_type == "dtd" :
			self.target_node = xml_node.parentNode.parentNode.parentNode
			self.target_type = self.target_node.tagName
		else :
			self.target_node = xml_node.parentNode.parentNode
			self.target_type = self.target_node.tagName

		ObjectAttrs.__init__(self, xml_node, is_newobj, change_call_back)

	def auto_fill(self) :
		widgets = self.widgets
		name_store = [[option[0], ""] for option in self.attributes_options.get(self.target_type, [])]
		if widgets.get("combo_entries", {}).has_key("name") :
			self.combobox_store_append(widgets["combo_entries"]["name"], name_store)

	def dynamic_fill(self, widget) :
		widgets = self.widgets
		if widgets.get("combo_entries", {}).has_key("name") \
				and widget == widgets["combo_entries"]["name"] :
			value_store = []
			nvpair = self.get_values()
			if nvpair.has_key("name") :
				options = self.attributes_options.get(self.target_type, [])
				for i in range(len(options)) :
					if options[i][0] == nvpair["name"] :
						value_store = options[i][1]
						break

			if widgets.get("combo_entries", {}).has_key("value") :
				self.combobox_store_append(widgets["combo_entries"]["value"], value_store)

class OPDefaultsNV(ObjectAttrs) :
	def __init__(self, xml_node, is_newobj = False, change_call_back = None) :
		self.op_attr_rng_nodes = {}
		self.op_attr_list = []
		sorted_rng_nodes = manager.sorted_sub_rng_nodes_by_name("op")
		if sorted_rng_nodes != None :
			attr_rng_nodes = sorted_rng_nodes.get("attribute", [])
			for rng_node in attr_rng_nodes :
				name = rng_node[0][1].getAttribute("name")
				if name in ["id", "name", "description"] :
					continue
				if not self.op_attr_rng_nodes.has_key(name) :
					self.op_attr_rng_nodes[name] = []
					self.op_attr_list.append(name)
				self.op_attr_rng_nodes[name].append(rng_node)

		ObjectAttrs.__init__(self, xml_node, is_newobj, change_call_back)

	def auto_fill(self) :
		widgets = self.widgets
		name_store = [[name, ""] for name in self.op_attr_list]
		if widgets.get("combo_entries", {}).has_key("name") :
			self.combobox_store_append(widgets["combo_entries"]["name"], name_store)

	def dynamic_fill(self, widget) :
		widgets = self.widgets
		if widgets.get("combo_entries", {}).has_key("name") \
				and widget == widgets["combo_entries"]["name"] :
			nvpair = self.get_values()
			if nvpair.has_key("name") :
				value_store = []
				for attr_rng_node in self.op_attr_rng_nodes.get(nvpair["name"], []):
					sub_rng_nodes = manager.sorted_sub_rng_nodes_by_node(*attr_rng_node[0])
					if len(sub_rng_nodes.get("value",[])) > 0 :
						for value_node in sub_rng_nodes["value"] :
							value_store.append([value_node[0][1].childNodes[0].data, ""])
					for sub_rng_node in sub_rng_nodes.get("data", []) :
						if sub_rng_nodes["data"][0][0][1].getAttribute("type") == "boolean" :
							for option in ("true", "false") :
								value_store.append([option, ""])

				if widgets.get("combo_entries", {}).has_key("value") :
					self.combobox_store_append(widgets["combo_entries"]["value"], value_store)

class Expression(ObjectAttrs) :
	def __init__(self, xml_node, is_newobj = False, change_call_back = None) :
		ObjectAttrs.__init__(self, xml_node, is_newobj, change_call_back)

	def auto_fill(self) :
		widgets = self.widgets
		attr_names = ["#uname","#id", "#is_dc"]
		attr_store = [[attr_name, ""] for attr_name in attr_names]
		
		if widgets.has_key("combo_entries") and widgets["combo_entries"].has_key("attribute") :
			self.combobox_store_append(widgets["combo_entries"]["attribute"], attr_store)

	def dynamic_fill(self, widget) :
		widgets = self.widgets
		if widgets.has_key("combo_entries") and widgets["combo_entries"].has_key("attribute") \
				and widget == widgets["combo_entries"]["attribute"] :
			expr = self.get_values()
			value_store = []
			if expr.has_key("attribute") :
				if expr["attribute"] == "#uname" :
					value_store = [[node, ""] for node in manager.get_normal_nodes()]
				elif expr["attribute"] == "#is_dc" :
					value_store = [[boolean_val, ""] for boolean_val in ["true", "false"]]

			if widgets.has_key("combo_entries") and widgets["combo_entries"].has_key("value") :
				self.combobox_store_append(widgets["combo_entries"]["value"], value_store)

class OP(ObjectAttrs) :
	def __init__(self, xml_node, is_newobj = False, change_call_back = None) :
		if mode_level == 0 :
			self.dynamic_layout = self.dynamic_layout_simple
		primitive_node = xml_node.parentNode.parentNode
		primitive_attrs = manager.get_rsc_attrs(primitive_node, ["class", "type", "provider"])
		primitive_class = str(primitive_attrs.get("class", ""))
		primitive_type = str(primitive_attrs.get("type", ""))
		primitive_provider = str(primitive_attrs.get("provider", ""))
		meta = manager.get_rsc_meta(primitive_class, primitive_type, primitive_provider)
		self.meta = meta
		ObjectAttrs.__init__(self, xml_node, is_newobj, change_call_back)
		self.dynamic_fill = self.dynamic_fill_later

	def auto_fill(self) :
		widgets = self.widgets
		meta = self.meta
		actions = ["start", "stop", "reload", "monitor", "status", "migrate_from", "migrate_to", "promote", "demote"]
		op_names = []
		if meta != None :
			for action in meta.actions :
				if action["name"] not in op_names :
					op_names.append(action["name"])
		else :
			op_names = actions
		op_name_store = [[op_name, ""] for op_name in op_names]

		if widgets.has_key("combo_entries") and widgets["combo_entries"].has_key("name") :
			self.combobox_store_append(widgets["combo_entries"]["name"], op_name_store)

	def dynamic_fill_later(self, widget) :
		widgets = self.widgets
		meta = self.meta
		if meta == None or not widgets.has_key("combo_entries") :
			return
		elif widget != widgets["combo_entries"].get("name") :
			if not widgets.has_key("combos") :
				return
			elif widget != widgets["combos"].get("role") :
				return

		op = self.get_values()
		if op.has_key("name") :
			if validate_type == "dtd" :
				default_role = manager.get_dtd_elem("op").get_attr("role").get_default()
			else :
				default_role = None

			for action in meta.actions :
				if action["name"] == op["name"] :
					if action.get("role") == op.get("role") \
							or ( action.get("role") == None and op.get("role") == default_role ) \
							or ( action.get("role") == default_role and op.get("role") == None) :
						for attr_name in widgets["combo_entries"].keys() :
							if attr_name != "id" and attr_name != "name" and attr_name != "role":
								attr_store = []
								if attr_name == "start_delay" and action.has_key("start-delay") :
									action["start_delay"] = action["start-delay"]
								if action.has_key(attr_name) :
									attr_store.append([action[attr_name], ""])
								self.combobox_store_append(widgets["combo_entries"][attr_name], attr_store)
								widgets["combo_entries"][attr_name].child.set_text(action.get(attr_name, ""))
						break

			if op["name"] != "monitor" and widgets["combo_entries"].has_key("interval") \
					and widgets["combo_entries"]["interval"].get_property("sensitive") \
					and widgets["combo_entries"]["interval"].child.get_text() == "" :
				is_required = False
				for child_widget in self.required_vbox.get_children() :
					if type(child_widget) == gtk.HBox \
							and widgets["combo_entries"]["interval"] in child_widget.get_children() :
						is_required = True
						break
				if is_required or mode_level == 0 :
					widgets["combo_entries"]["interval"].child.set_text("0")

		else :
			for attr_name in widgets["combo_entries"].keys() :
				if attr_name != "name" :
					self.combobox_store_append(widgets["combo_entries"][attr_name], [])
					widgets["combo_entries"][attr_name].child.set_text("")

	def dynamic_layout_simple(self, widget) :
		widgets = self.widgets
		required_vbox = self.required_vbox
		optional_vbox = self.optional_vbox

		if not widgets.has_key("combo_entries") :
			return
		elif widget != widgets["combo_entries"].get("name") :
			return

		op = self.get_values()
		if op.get("name", "") in ["", "monitor"] :
			required_attrs = ["id", "name", "interval", "timeout"]
		else :
			required_attrs = ["id", "name", "timeout"]

		for vbox in [required_vbox, optional_vbox] :
			for child in vbox.get_children() :
				vbox.remove(child)

		for attr_name in self.attr_list :
			if attr_name in required_attrs :
				required_vbox.pack_start(self.hboxes[attr_name], False, padding=2)
			else :
				optional_vbox.pack_start(self.hboxes[attr_name], False, padding=2)

		required_vbox.show_all()
		optional_vbox.show_all()
		if mode_level == 0 :
			self.hide_id_widget()
		top_window.set_focus(widgets["combo_entries"]["name"].child)

	def verify_values(self) :
		if not ObjectAttrs.verify_values(self) :
			return False

		time_attrs = ["interval", "timeout"]
		if validate_type == "dtd" :
			time_attrs.append("start_delay")
		else :
			time_attrs.append("start-delay")

		op = self.get_values()
		for time_attr in time_attrs :
			if op.get(time_attr, "") != "" :
				(is_valid, error_msg) = is_valid_time(op[time_attr])
				if not is_valid :
					msgbox(_("Invalid \"%s\"")%(_(name_cap(time_attr))) + _(":") + "\n" +
							error_msg)
					return False
		return True

	def dynamic_set_id(self, widget) :
		widgets = self.widgets
		if mode_level != 0 or not widgets.has_key("combo_entries") :
			return
		if widget not in [widgets["combo_entries"].get("name"), widgets["combo_entries"].get("interval")] :
			if not widgets.has_key("combos") :
				return
			if widget != widgets["combos"].get("role") :
				return
				
		op = self.get_values()
		primitive_id = self.xml_node.parentNode.parentNode.getAttribute("id")
		op_id = primitive_id + "-op"
		name = op.get("name", "")
		if name != "" :
			op_id += "-" + name
		role = op.get("role", "")
		if role != "" :
			op_id += "-" + role
		interval = op.get("interval", "")
		if interval != "" :
			op_id += "-" + interval
			
		new_id = manager.get_unique_id(op_id, self.xml_node)
		self.set_id_widget(new_id)

class RscOrder(ObjectAttrs) :
	def __init__(self, xml_node, is_newobj = False, change_call_back = None) :
		if validate_type == "dtd" :
			self.dynamic_fill = self.dynamic_fill_dtd
			self.dynamic_desc = self.dynamic_desc_dtd
		else :
			self.dynamic_desc = self.dynamic_desc_rng
		ObjectAttrs.__init__(self, xml_node, is_newobj, change_call_back)

	def dynamic_fill_dtd(self, widget) :
		widgets = self.widgets
		if widgets.has_key("combo_entries") and widgets["combo_entries"].has_key("from") \
				and widget == widgets["combo_entries"]["from"] :
			key_pair = ["from", "action"]
		elif widgets.has_key("combo_entries") and widgets["combo_entries"].has_key("to") \
				and widget == widgets["combo_entries"]["to"] :
			key_pair = ["to", "to_action"]
		else :
			return

		object = self.get_values()
		actions_list = ["start", "stop", "reload", "monitor", "status", "migrate_from", "migrate_to", "promote", "demote"]

		actions = actions_list
		if object.has_key(key_pair[0]) :
			rsc_info = manager.get_rsc_info(object[key_pair[0]])
			if rsc_info != None :
				meta = manager.get_rsc_meta(*rsc_info)
				if meta != None :
					actions = []
					for f in meta.actions :
						if not f["name"] in actions : 
							actions.append(f["name"])

		action_store = [[action, ""] for action in actions]

		if widgets.has_key("combo_entries") and widgets["combo_entries"].has_key(key_pair[1]) :
			self.combobox_store_append(widgets["combo_entries"][key_pair[1]], action_store)

	def dynamic_desc_dtd(self, widget) :
		dtd_elem = self.dtd_elem
		order = self.get_values()
		for attr_name in dtd_elem.get_attr_list() :
			attr = dtd_elem.get_attr(attr_name)
			if not order.has_key(attr_name) :
				if attr_name != "id" and attr.get_decl() == "#REQUIRED" :
					return [_("* Specify dependencies between the actions on two resources"), 
						_("* Please set the required attributes"), "", ""]
				order[attr_name] = attr.get_default()
			if order[attr_name] == None :
				order[attr_name] = ""
		desc = []
		desc.append(_("* %s %s %s %s %s")
				%(order["action"].capitalize(), order["from"], order["type"], order["to_action"], order["to"]))

		if order["score"] == "INFINITY" or order["score"] == "infinity":
			if order["type"] == "before" :
				desc.append(_("* If cannot %s %s, do not %s %s")
						%(order["action"], order["from"], order["to_action"], order["to"]))
			else :
				desc.append(_("* If cannot %s %s, do not %s %s")
						%(order["to_action"], order["to"], order["action"], order["from"]))
		else :
			desc.append("")

		action = self.invert_action(order["action"])
		to_action = self.invert_action(order["to_action"])
		if order["symmetrical"] == "true" and action != None and to_action != None :
			desc.append(_("* %s %s %s %s %s")
					%(to_action.capitalize(), order["to"], order["type"], action, order["from"]))
			if order["score"] == "INFINITY" or order["score"] == "infinity":
				if order["type"] == "before" :
					desc.append(_("* If cannot %s %s, do not %s %s")
							%(to_action, order["to"], action, order["from"]))
				else :
					desc.append(_("* If cannot %s %s, do not %s %s")
							%(action, order["from"], to_action, order["to"]))
			else:
				desc.append("")
		else :
			desc.append("")
			desc.append("")

		return desc

	def invert_action(self, action) :
		if action == "start" :
			return "stop"
		elif action == "stop" :
			return "start"
		elif action == "promote" :
			return "demote"
		elif action == "demote" :
			return "promote"
		elif action == "promoted" :
			return "demoted"
		elif action == "demoted" :
			return "promoted"
		if action == "started" :
			return "stopped"
		elif action == "stopped" :
			return "started"
		else :
			return None

	def dynamic_desc_rng(self, widget) :
		attr_list = self.attr_list
		order = self.get_values()
		for attr_name in self.attr_list :
			if attr_name in ["first", "then"] and not order.has_key(attr_name) :
				return [_("* Specify the order of actions on resources"), 
						_("* Please set the required attributes or add resource sets"), "", ""]
			if order.get(attr_name) == None :
				if attr_name in ["first-action", "then-action"] :
					order[attr_name] = "start"
				elif attr_name == "score" :
					order[attr_name] = "INFINITY"
				elif attr_name == "symmetrical" :
					order[attr_name] = "true"
				else :
					order[attr_name] = ""
		desc = []
		desc.append(_("* %s %s before %s %s")
				%(order["first-action"].capitalize(), order["first"], order["then-action"], order["then"]))

		score = self.get_score(order["score"])

		if score > 0 :
			desc.append(_("* If cannot %s %s, do not %s %s")
					%(order["first-action"], order["first"], order["then-action"], order["then"]))
		else :
			desc.append("")

		first_action = self.invert_action(order["first-action"])
		then_action = self.invert_action(order["then-action"])
		if order["symmetrical"] == "true" and first_action != None and then_action != None :
			desc.append(_("* %s %s before %s %s")
					%(then_action.capitalize(), order["then"], first_action, order["first"]))
			if score > 0 :
				desc.append(_("* If cannot %s %s, do not %s %s")
						%(then_action, order["then"], first_action, order["first"]))
			else:
				desc.append("")
		else :
			desc.append("")
			desc.append("")

		return desc

class RscColocation(ObjectAttrs) :
	def __init__(self, xml_node, is_newobj = False, change_call_back = None) :
		if validate_type == "dtd" :
			self.dynamic_desc = self.dynamic_desc_dtd
		else :
			self.dynamic_desc = self.dynamic_desc_rng
		ObjectAttrs.__init__(self, xml_node, is_newobj, change_call_back)

	def dynamic_desc_dtd(self, widget) :
		dtd_elem = self.dtd_elem
		colocation = self.get_values()
		for attr_name in dtd_elem.get_attr_list() :
			attr = dtd_elem.get_attr(attr_name)
			if not colocation.has_key(attr_name) :
				if attr_name != "id" and attr.get_decl() == "#REQUIRED" :
					return [_("* Specify where a resource should run relative to another resource"),
						_("* Please set the required attributes"), "", ""]
				colocation[attr_name] = attr.get_default()
			if colocation[attr_name] == None :
				colocation[attr_name] = ""
		desc = []

		if colocation["score"] == "INFINITY" or colocation["score"] == "infinity" :
			desc.append(_("* Make %s %s on the same node as %s %s  ( %s according to %s )")
					%(colocation["from"], colocation["from_role"], colocation["to"], colocation["to_role"],
					colocation["from"], colocation["to"]))
			desc.append(_("* If %s cannot be %s on any node, then %s won't be %s anywhere")
					%(colocation["to"], colocation["to_role"], colocation["from"], colocation["from_role"]))
			if colocation["symmetrical"] == "false" :
				desc.append(_("* If %s cannot be %s on any node, %s won't be affected")
						%(colocation["from"], colocation["from_role"], colocation["to"]))
				desc.append("")
			else : 
				desc.append(_("* Make %s %s on the same node as %s %s  ( %s according to %s )")
						%(colocation["to"], colocation["to_role"], colocation["from"], colocation["from_role"],
						colocation["to"], colocation["from"]))
				desc.append(_("* If %s cannot be %s on any node, then %s won't be %s anywhere")
						%(colocation["from"], colocation["from_role"], colocation["to"], colocation["to_role"]))
		elif colocation["score"] == "-INFINITY" or colocation["score"] == "-infinity" :
			desc.append(_("* Prevent %s from being %s on the same node as %s %s  ( %s according to %s )")
					%(colocation["from"], colocation["from_role"], colocation["to"], colocation["to_role"],
					colocation["from"], colocation["to"]))
			desc.append(_("* If %s is %s on the only (or every) available node, then %s won't be %s anywhere")
					%(colocation["to"], colocation["to_role"], colocation["from"], colocation["from_role"]))
			if colocation["symmetrical"] == "false" :
				desc.append(_("* If %s is %s on the only (or every) available node, %s won't be affected")
						%(colocation["from"], colocation["from_role"], colocation["to"]))
				desc.append("")
			else :
				desc.append(_("* Prevent %s from being %s on the same node as %s %s  ( %s according to %s )")
						%(colocation["to"], colocation["to_role"], colocation["from"], colocation["from_role"],
						colocation["to"], colocation["from"]))
				desc.append(_("* If %s is %s on the only (or every) available node, then %s won't be %s anywhere")
						%(colocation["from"], colocation["from_role"], colocation["to"], colocation["to_role"]))
		else :
			desc.append(_("* Combine this colocation score and the appropriate location scores to decide where to put the resources"))
			desc.append("")
			desc.append("")
			desc.append("")

		return desc

	def dynamic_desc_rng(self, widget) :
		attr_list = self.attr_list
		colocation = self.get_values()
		for attr_name in self.attr_list :
			if attr_name in ["rsc", "with-rsc"] and not colocation.has_key(attr_name) :
				return [_("* Specify where resources should run relative to other resources"),
					_("* Please set the required attributes or add resource sets"), ""]
			if colocation.get(attr_name) == None :
				colocation[attr_name] = ""
		desc = []

		score = self.get_score(colocation["score"])

		comb_tip = _("* Combine this \"Score\" and corresponding location scores to decide where to place %s") \
				%colocation["rsc"]

		if score > 0 :
			if colocation["score"] in ["INFINITY", "infinity", "+INFINITY", "+infinity"] :
				desc.append(_("* Make %s %s on the same node as %s %s  ( %s according to %s )")
						%(colocation["rsc"], colocation["rsc-role"], colocation["with-rsc"], colocation["with-rsc-role"],
						colocation["rsc"], colocation["with-rsc"]))
				desc.append(_("* If %s cannot be %s on any node, then %s won't be %s anywhere")
						%(colocation["with-rsc"], colocation["with-rsc-role"], colocation["rsc"], colocation["rsc-role"]))
				desc.append(_("* If %s cannot be %s on any node, %s won't be affected")
						%(colocation["rsc"], colocation["rsc-role"], colocation["with-rsc"]))
			else :
				desc.append(_("* Prefer to make %s %s on the same node as %s %s  ( %s according to %s )")
					%(colocation["rsc"], colocation["rsc-role"], colocation["with-rsc"], colocation["with-rsc-role"],
					colocation["rsc"], colocation["with-rsc"])) 
				desc.append(comb_tip)
				desc.append("")


		elif score < 0 :
			if colocation["score"] in ["-INFINITY", "-infinity"] :
				desc.append(_("* Prevent %s from being %s on the same node as %s %s  ( %s according to %s )")
						%(colocation["rsc"], colocation["rsc-role"], colocation["with-rsc"], colocation["with-rsc-role"],
						colocation["rsc"], colocation["with-rsc"]))
				desc.append(_("* If %s is %s on the only (or every) available node, then %s won't be %s anywhere")
						%(colocation["with-rsc"], colocation["with-rsc-role"], colocation["rsc"], colocation["rsc-role"]))
				desc.append(_("* If %s is %s on the only (or every) available node, %s won't be affected")
						%(colocation["rsc"], colocation["rsc-role"], colocation["with-rsc"]))
			else :
				desc.append(_("* Prefer to prevent %s from being %s on the same node as %s %s  ( %s according to %s )")
						%(colocation["rsc"], colocation["rsc-role"], colocation["with-rsc"], colocation["with-rsc-role"],
						colocation["rsc"], colocation["with-rsc"])) 
				desc.append(comb_tip)
				desc.append("")
		else :
			desc.append(_("* Please specify a valid \"Score\" to determine the location relationship between %s and %s")
					%(colocation["rsc"], colocation["with-rsc"]))
			desc.append("")
			desc.append("")

		return desc

if __name__ == '__main__' :
	try :
		gtk._gtk.init_check()
	except RuntimeError :
		print "Could not open display"
		sys.exit()
	except AttributeError :
		pass
	if not pygtk_newer(2, 4) :
		print "the pygtk 2.4 or newer is needed."
		sys.exit()
	gc.enable()
	syslog.openlog("haclient", 0, syslog.LOG_USER)
	locale.setlocale(locale.LC_ALL, '')
	gettext.bindtextdomain(app_name)
	gettext.textdomain(app_name)
	gettext.install(app_name,"/usr/share/locale",unicode=1)
	if "-v" in sys.argv :
		debug_level = 1
	manager = Manager()
	window = MainWindow()
	top_window = window.win_widget
	manager.run()
	syslog.closelog()