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

import sys
import os
import os.path
from PyTQt.qt import *
from tdecore import *
from tdeui import *
from tdefile import *
from tdeio import *
#import string
#import math
import shutil
#import select
#import struct
#import csv
#import time
import signal
#import shutil
import wineread
import winewrite
import drivedetect
import wineconfig

programname = "Wine Configuration"
version = "0.7.1"

default_winepath = os.environ['HOME'] + "/.wine"

# Are we running as a separate standalone application or in KControl?
standalone = __name__=='__main__'

# Editing application specific settings?  For which application?
application = None

# Running as the root user or not? Doesn't matter for wine
isroot = os.getuid()==0

############################################################################
if standalone:
    programbase = KDialogBase
else:
    programbase = TDECModule

############################################################################
class WineConfigApp(programbase):
    ########################################################################
    def __init__(self,parent=None,name=None):
        global standalone,kapp,default_winepath,application
        TDEGlobal.locale().insertCatalogue("guidance")

        if standalone:
            KDialogBase.__init__(self,KJanusWidget.Tabbed,"Wine Configuration",\
                KDialogBase.Apply|KDialogBase.User1|KDialogBase.User2|KDialogBase.Close, KDialogBase.Close)
            self.setButtonText(KDialogBase.User1,i18n("Reset"))
            self.setButtonText(KDialogBase.User2,i18n("About"))
            args = TDECmdLineArgs.parsedArgs()
            if args.count() > 0:
                application = args.arg(0)
        else:
            TDECModule.__init__(self,parent,name)
            self.setButtons(TDECModule.Apply|TDECModule.Reset)
            self.aboutdata = MakeAboutData()

        # Create a configuration object.
        self.config = TDEConfig("wineconfigrc")

        # Compact mode means that we have to make the GUI 
        # much smaller to fit on low resolution screens.
        self.compact_mode = kapp.desktop().height()<=600

        TDEGlobal.iconLoader().addAppDir("guidance")

        self.wineconfigchanged = False

        self.updatingGUI = True

        if not wineread.GetWineBuildPath():
            install = KMessageBox.questionYesNo(self, \
                i18n("It appears that you do not have Wine installed. Wine " + \
                    "can be used to run some programs designed for Windows.  " + \
                    "Would you " + \
                    "like to install it?\n" + \
                    "You will need administrative privileges, and the " + \
                    "community-maintained (universe) repository will be enabled."), \
                i18n("Windows Applications"))
            if install == KMessageBox.Yes:
                self.InstallWine()
                
        wineread.SetWineBuildPath(wineread.GetWineBuildPath())
        
        if wineread.GetWineBuildPath():
            # wine doesn't set the WINEPREFIX globally, but just in case...
            wineprefix = os.environ.get('WINEPREFIX',default_winepath)
            newrc = not self.config.hasKey("ColorScheme")
            firstrun = not wineread.VerifyWineDrive(wineprefix)
            if firstrun:
                KMessageBox.information(self, \
                    i18n("It appears that you do not yet have a Windows drive set up.  " + \
                        "A fake Windows installation will be created for you in " + \
                        wineprefix + "\nThis may take up to a minute."), \
                    i18n("Setting up your Windows drive"))
                self.CreateWindowsInstall()
                        
            self._buildGUI()
    
            if firstrun and newrc:
                self.appearancepage.slotColorSchemeActivated(1)
        else:
            self._buildGUI_noWine()
                    
        self.aboutus = TDEAboutApplication(self)

        if standalone:
            self.enableButton(KDialogBase.User1,False) # Reset button
            self.enableButtonApply(False) # Apply button

        self.updatingGUI = False
        
        
    def _buildGUI(self):
        global standalone,application
        if not standalone:
            toplayout = TQVBoxLayout( self, 0, KDialog.spacingHint() )
            tabcontrol = TQTabWidget(self)
            toplayout.addWidget(tabcontrol)
            toplayout.setStretchFactor(tabcontrol,1)

        #--- General tab ---
        tabname = i18n("General")
        if standalone:
            general1page = self.addGridPage(1,TQGrid.Horizontal,tabname)
            general1page.setSpacing(0)
            self.generalpage = GeneralPage(general1page,self.compact_mode)
        else:
            self.generalpage = GeneralPage(tabcontrol,self.compact_mode)
            self.generalpage.setMargin(KDialog.marginHint())

        # Connect all PYSIGNALs from GeneralPage Widget to appropriate actions.
        self.connect(self.generalpage,PYSIGNAL("changedSignal()"),self._sendChangedSignal)

        if not standalone:
            tabcontrol.addTab(self.generalpage,tabname)

        #--- Drives tab ---
        if not application:
            tabname = i18n("Drives && Directories")
            if standalone:
                drives1page = self.addGridPage(1,TQGrid.Horizontal,tabname)
                drives1page.setSpacing(0)
                self.drivespage = DrivesPage(drives1page,self.compact_mode)
            else:
                self.drivespage = DrivesPage(tabcontrol,self.compact_mode)
                self.drivespage.setMargin(KDialog.marginHint())

            # Connect all PYSIGNALs from DrivesPage Widget to appropriate actions.
            self.connect(self.drivespage,PYSIGNAL("changedSignal()"),self._sendChangedSignal)

            if not standalone:
                tabcontrol.addTab(self.drivespage,tabname)

        #--- Audio tab ---
        tabname = i18n("Audio")
        if standalone:
            audio1page = self.addGridPage(1,TQGrid.Horizontal,tabname)
            self.audiopage = AudioPage(audio1page)
        else:
            self.audiopage = AudioPage(tabcontrol)
            self.audiopage.setMargin(KDialog.marginHint())

        # Connect all PYSIGNALs from AudioPage Widget to appropriate actions.
        self.connect(self.audiopage,PYSIGNAL("changedSignal()"),self._sendChangedSignal)

        if not standalone:
            tabcontrol.addTab(self.audiopage,tabname)

        #--- Graphics tab ---
        tabname = i18n("Graphics")
        if standalone:
            graphics1page = self.addGridPage(1,TQGrid.Horizontal,tabname)
            self.graphicspage = GraphicsPage(graphics1page)
        else:
            self.graphicspage = GraphicsPage(tabcontrol)
            self.graphicspage.setMargin(KDialog.marginHint())


        # Connect all PYSIGNALs from GraphicsPage Widget to appropriate actions.
        self.connect(self.graphicspage,PYSIGNAL("changedSignal()"),self._sendChangedSignal)

        if not standalone:
            tabcontrol.addTab(self.graphicspage,tabname)

        #--- Appearance tab ---
        if not application:
            tabname = i18n("Appearance")
            if standalone:
                appearance1page = self.addGridPage(1,TQGrid.Horizontal,tabname)
                self.appearancepage = AppearancePage(appearance1page)
            else:
                self.appearancepage = AppearancePage(tabcontrol)
                self.appearancepage.setMargin(KDialog.marginHint())

            # Connect all PYSIGNALs from DesktopPage Widget to appropriate actions.
            self.connect(self.appearancepage,PYSIGNAL("changedSignal()"),self._sendChangedSignal)
            self.graphicspage.connect(self.graphicspage.allowwmcheckbox,
                SIGNAL("toggled(bool)"),
                self.appearancepage.slotFillItemCombo)
            self.connect(self.graphicspage.emudesktopcheckbox,
                SIGNAL("toggled(bool)"),
                self.appearancepage.slotFillItemComboDesktop)

            self.appearancepage.slotFillItemComboDesktop(\
                self.graphicspage.currentemudesktop)

            if not standalone:
                tabcontrol.addTab(self.appearancepage,tabname)

        #--- Applications tab ---
        if not application:
            tabname = i18n("Applications")
            if standalone:
                apps1page = self.addGridPage(1,TQGrid.Horizontal,tabname)
                self.appspage = ApplicationsPage(apps1page)
            else:
                self.appspage = ApplicationsPage(tabcontrol)
                self.appspage.setMargin(KDialog.marginHint())

            # Connect all PYSIGNALs from ApplicationsPage Widget to appropriate actions.
            self.connect(self.appspage,PYSIGNAL("changedSignal()"),self._sendChangedSignal)

            if not standalone:
                tabcontrol.addTab(self.appspage,tabname)

        #--- Libraries tab ---
        tabname = i18n("Libraries")
        if standalone:
            libs1page = self.addGridPage(1,TQGrid.Horizontal,tabname)
            self.libspage = LibrariesPage(libs1page)
        else:
            self.libspage = LibrariesPage(tabcontrol)
            self.libspage.setMargin(KDialog.marginHint())

        # Connect all PYSIGNALs from LibrariesPage Widget to appropriate actions.
        self.connect(self.libspage,PYSIGNAL("changedSignal()"),self._sendChangedSignal)

        if not standalone:
            tabcontrol.addTab(self.libspage,tabname)


    def _buildGUI_noWine(self):
        """ Displays an error that wine is not installed """
        global standalone
        if not standalone:
            toplayout = TQVBoxLayout( self, 0, KDialog.spacingHint() )
            
        if not standalone:
            nowinewarning = TQLabel(self,"nowinewarning")
            toplayout.addWidget(nowinewarning)
        else:
            vbox = self.addVBoxPage ("Wine Not Installed")
            nowinewarning = TQLabel(vbox,"nowinewarning")
        nowinewarning.setText(i18n("It appears that you do not have wine " +\
                    "installed.\nwine " + \
                    "can be used to run some programs designed for " + \
                    "Windows.\nPlease " +\
                    "install the wine package to get this functionality."))
        nowinewarning.setFrameStyle( TQFrame.Box | TQFrame.Raised )
            
    def InstallWine(self):
        """ Allows the user to enable the proper repositories and
        install wine.
        Currently Kubuntu specific, requires tdesudo, adept_batch
        and software-properties-kde """
        if not isroot:
            if os.system("tdesudo \"software-properties-kde --enable-component universe\""):
                KMessageBox.error(self, i18n("There was a problem running " + \
                    "software-properties-kde.  Make sure " + \
                    "software-properties-kde is installed."))
            elif os.system("tdesudo \"adept_batch install wine\""):
                KMessageBox.error(self, i18n("There was a problem running " + \
                    "adept_batch.  Make sure " + \
                    "Adept is installed."))
        else:
            if os.system("software-properties-kde --enable-component=universe" + \
                " && adept_batch install wine"):
                KMessageBox.error(self, i18n("There was a problem running " + \
                    "software-properties-kde and adept_batch.  Make sure " + \
                    "Adept and software-properties-kde are installed."))
                    
    def CreateWindowsInstall(self,winepath = None):
        if not winepath:
            winepath = default_winepath
        winewrite.CreateWineDrive(winepath)
        wineread.SetWinePath(winepath)

        drives = wineread.LoadDrives()
        autodrives = drivedetect.autodetect(drives)
        autoshelllinks = drivedetect.autodetectshelllinks()

        if autodrives[0] == 1:
            KMessageBox.sorry(self, \
                i18n("There were not enough letters to add all the autodetected drives."))
        drives = autodrives[1]
        drives[26:] = autoshelllinks

        winewrite.SetDriveMappings(drives)

        winewrite.SetAudioDriver('alsa')

        dsoundsettings = {"HardwareAcceleration":"Full",
            "DefaultSampleRate":"44100",
            "DefaultBitsPerSample":"8",
            "EmulDriver":"N"}

        winewrite.SetDSoundSettings(dsoundsettings)

        windowsettings = {"DXGrab":"N",
            "DesktopDoubleBuffered":"Y",
            "Managed":"Y",
            "Desktop":""}

        winewrite.SetWindowSettings(windowsettings)

        d3dsettings = {"VertexShaderMode":"hardware",
            "PixelShaderMode":"Y",
            "UseGLSL":"enabled"}

        winewrite.SetD3DSettings(d3dsettings)

        winewrite.SetWinVersion(wineread.winversions[1])

        # Removed pending a patch to winebrowser
        #winewrite.SetFirstBrowser("kfmclient exec")
        #winewrite.SetFirstMailer("kfmclient exec")

    def exec_loop(self,appname):
        global application, programbase
        if appname:
            application = appname
            KDialogBase.exec_loop(self)
        else:
            programbase.exec_loop(self)

    def save(self): # TDECModule
        # Find out what's changed
        generalchanged = self.generalpage.isChanged()
        driveschanged = not application and self.drivespage.isChanged()
        audiochanged = self.audiopage.isChanged()
        graphicschanged = self.graphicspage.isChanged()
        appearancechanged = not application and self.appearancepage.isChanged()
        applicationschanged = not application and self.appspage.isChanged()
        libschanged = self.libspage.isChanged()

        # Apply changes for each tab
        if generalchanged:
            self.generalpage.applyChanges()
        if driveschanged:
            self.drivespage.applyChanges()
        if audiochanged:
            self.audiopage.applyChanges()
        if graphicschanged:
            self.graphicspage.applyChanges()
        if appearancechanged:
            self.appearancepage.applyChanges()
        if applicationschanged:
            self.appspage.applyChanges()
        if libschanged:
            self.libspage.applyChanges()

        self._sendChangedSignal()

    def slotApply(self): # KDialogBase
        self.save()

    def slotClose(self): # KDialogBase
        KDialogBase.slotClose(self)

    def load(self): # TDECModule
        self.__reset()
        self._sendChangedSignal()

    def slotUser1(self): # Reset button, KDialogBase
        self.load()

    def slotUser2(self): # About button, KDialogBase
        self.aboutus.show()

    def __reset(self):
        # Reset each configuration page
        if not application:
            self.drivespage.reset()
        self.audiopage.reset()
        self.graphicspage.reset()
        self.appearancepage.reset()
        if not application:
            self.appspage.reset()
        self.libspage.reset()

    # Kcontrol expects updates about whether the contents have changed.
    # Also we fake the Apply and Reset buttons here when running outside kcontrol.
    def _sendChangedSignal(self):
        global standalone

        changed = False
        changed = changed or (not application and self.drivespage.isChanged()) or \
            self.audiopage.isChanged() \
            or self.generalpage.isChanged() or \
            (not application and self.appspage.isChanged()) or \
            self.libspage.isChanged() or \
            (not application and self.appearancepage.isChanged())
        graphicschanged = self.graphicspage.isChanged()
        changed = changed or graphicschanged

        if standalone:
            self.enableButton(KDialogBase.User1,changed) # Reset button
            self.enableButtonApply(changed) # Apply button
        else:
            self.emit(SIGNAL("changed(bool)"), (changed,) )

############################################################################
''' Not used.
class ErrorPage(TQWidget):
    """
    Displayed when there is no fake Windows drive
    """

    def __init__(self,parent = None, name = None, parentapp = None, modal = 0,fl=0):
        TQWidget.__init__(self,parent)

        if not name:
            self.setName("ErrorPage")

        self.parent = parentapp

        self.top_layout = TQVBoxLayout(self,0,0,"ErrorPageLayout")

        vbox = TQVBox(self)
        vbox.setSpacing(KDialog.spacingHint())

        self.top_layout.addWidget(vbox)

        errortext = TQLabel(vbox,"errortext")
        errortext.setText(i18n("You need to set up a " +\
            "fake Windows drive\n before you can edit settings or run " +\
            "Windows applications."))

        self.createbutton = KPushButton(i18n("Create Fake Windows Drive"),vbox)
        self.connect(self.createbutton,SIGNAL("clicked()"),self.slotCreateClicked)

        bottomspacer = TQSpacerItem(51,160,TQSizePolicy.Minimum,TQSizePolicy.Expanding)
        self.top_layout.addItem(bottomspacer)

        self.clearWState(TQt.WState_Polished)

    def slotCreateClicked(self):
        self.parent.CreateWindowsInstall()
        self.parent._buildGUI()

    def setMargin(self,margin):
        self.top_layout.setMargin(margin)

    def setSpacing(self,spacing):
        self.top_layout.setSpacing(spacing)

'''

##############################################################################

class DrivesPage(TQWidget):
    """
    A TabPage with configuration for drive mappings
    """

    types = (
        (0,i18n("Autodetect"),"auto"),
        (1,i18n("Local Hard Disk"),"hd"),
        (2,i18n("Network Share"),"network"),
        (3,i18n("Floppy Disk"),"floppy"),
        (4,i18n("CD-ROM"),"cdrom"))

    typesdic = {
        'auto':0,
        'hd':1,
        'network':2,
        'floppy':3,
        'cdrom':4}

    def __init__(self,parent = None,name = None,modal = 0,fl = 0):
        TQWidget.__init__(self,parent)

        self.updatingGUI = True

        self.selecteddriveid = None

        if not name:
            self.setName("DrivesTab")

        self.drives = wineread.LoadDrives()
        self.drives[26:] = wineread.GetShellLinks()

        drives_tab_layout = TQVBoxLayout(self,0,0,"DrivesTabLayout")
        self.top_layout = drives_tab_layout

        vbox = TQVBox(self)
        vbox.setSpacing(KDialog.spacingHint())

        drives_tab_layout.addWidget(vbox)

        # -- Drive mappings group
        self.mappings_group_box = TQHGroupBox(vbox)
        self.mappings_group_box.setTitle(i18n("Drive and Directory Mappings"))
        self.mappings_group_box.setInsideSpacing(KDialog.spacingHint())
        self.mappings_group_box.setInsideMargin(KDialog.marginHint())

        vbox2 = TQVBox(self.mappings_group_box)
        vbox2.setSpacing(KDialog.spacingHint())

        spacer = TQWidget(vbox2)
        vbox2.setStretchFactor(spacer,1)

        self.driveslist = TDEListView(vbox2)
        self.driveslist.addColumn(i18n("Directory"))
        self.driveslist.addColumn(i18n("Links to"))
        self.driveslist.setAllColumnsShowFocus(True)
        self.driveslist.setSelectionMode(TQListView.Single)
        self.driveslist.setSorting(-1,True)

        self.connect(self.driveslist, SIGNAL("selectionChanged(TQListViewItem *)"), self.slotListClicked)

        hbox = TQHBox(vbox2)
        hbox.setSpacing(KDialog.spacingHint())

        self.addbutton = KPushButton(i18n("Add Drive..."),hbox)
        self.connect(self.addbutton,SIGNAL("clicked()"),self.slotAddClicked)

        self.removebutton = KPushButton(i18n("Remove Drive"),hbox)
        self.connect(self.removebutton,SIGNAL("clicked()"),self.slotRemoveClicked)

        spacer = TQWidget(hbox)
        hbox.setStretchFactor(spacer,1)

        self.autobutton = KPushButton(i18n("Autodetect"),hbox)
        self.connect(self.autobutton,SIGNAL("clicked()"),self.slotAutoClicked)

        hbox2 = TQHBox(vbox2)
        hbox2.setSpacing(KDialog.spacingHint())

        pathtext = TQLabel(hbox2,"pathtext")
        pathtext.setText(i18n("Path:"))

        self.fsfolderedit = KLineEdit("/",hbox2)
        self.urlcompletion = KURLCompletion(KURLCompletion.DirCompletion)
        self.fsfolderedit.setCompletionObject(self.urlcompletion)
        self.fsfolderedit.setCompletionMode(TDEGlobalSettings.CompletionPopup)
        self.connect(self.fsfolderedit,SIGNAL("textChanged(const TQString &)"),self.slotFolderEdited)

        self.browsebutton = KPushButton(i18n("Browse"),hbox2)
        self.connect(self.browsebutton,SIGNAL("clicked()"),self.slotBrowseClicked)

        hbox2 = TQHBox(vbox2)
        hbox2.setSpacing(KDialog.spacingHint())

        self.typetext = TQLabel(hbox2,"typetext")
        self.typetext.setText(i18n("Type:"))

        self.typecombo = KComboBox(0,hbox2,"typecombo")
        self.fillTypeCombo(self.typecombo)
        self.connect(self.typecombo,SIGNAL("activated(int)"),self.slotTypeActivated)

        spacer = TQWidget(hbox2)
        hbox2.setStretchFactor(spacer,1)

        hbox2 = TQHBox(vbox2)
        hbox2.setSpacing(KDialog.spacingHint())

        self.infotext1 = TQLabel(hbox2,"infotext1")

        hbox2 = TQHBox(vbox2)
        hbox2.setSpacing(KDialog.spacingHint())

        self.infotext2 = TQLabel(hbox2,"infotext2")

        bottomspacer = TQSpacerItem(51,160,TQSizePolicy.Minimum,TQSizePolicy.Expanding)
        drives_tab_layout.addItem(bottomspacer)

        self.changed = False

        self.clearWState(TQt.WState_Polished)

        self.updatingGUI=False

        self.updateDrivesList()

    def reset(self):
        self.drives = wineread.LoadDrives()
        self.drives[26:] = wineread.GetShellLinks()
        self.updatingGUI=True
        self.updateDrivesList()
        self.updatingGUI=False
        self.changed = False

    def isChanged(self):
        """ Check if something has changed since startup or last apply(). """
        return self.changed

    def applyChanges(self):
        """ Apply the changes """
        winewrite.SetDriveMappings(self.drives)
        self.reset()

    def updateChanges(self):
        """ Update the GUI and send the signal that changes were made """
        self.updatingGUI=True
        self.updateDrivesList()
        self.updatingGUI=False
        self.changed = True
        self.emit(PYSIGNAL("changedSignal()"), ())

    def slotListClicked(self,item):
        """ Show the drive information and settings for the newly selected drive """
        if self.updatingGUI==False:
            for driveid in self.drivesToListItems:
                if self.drivesToListItems[driveid]==item:
                    self.updatingGUI = True
                    self.__selectDrive(driveid)
                    self.updatingGUI = False
                    return

    def slotFolderChanged(self,folder):
        """ Change the directory mapping when a new one is entered in the URL box """
        self.drives[self.selecteddriveid][2] = str(folder)
        self.updateChanges()

    def slotFolderEdited(self,folder):
        """ Change the directory mapping when a new one is entered manually in the URL box """
        if not self.updatingGUI:
            self.urlcompletion.makeCompletion("")   # Doesn't seem like this should be required.
            self.slotFolderChanged(folder)

    def slotBrowseClicked(self):
        """ Bring up a browse window to choose a ndew mapping directory """
        mapping = KFileDialog.getExistingDirectory(wineread.winepath,self,i18n("Drive Mapping"))
        if mapping:
            mapping = str(mapping)
            self.drives[self.selecteddriveid][2] = mapping
            self.updateChanges()

    def slotAddClicked(self):
        """
        Let the user choose a directory to map a new drive to.
        Uses the next available drive letter. """
        # TODO: Maybe the user should choose the drive letter?
        for drive in self.drives[2:26]:
            if drive[2]:
                continue
            else:
                mapping = KFileDialog.getExistingDirectory(wineread.winepath,self,i18n("Drive Mapping"))
                if mapping:
                    mapping = str(mapping)
                    drive[2] = mapping
                else:
                    return
                self.selecteddriveid = drive[0]
                break
        else:
            KMessageBox.sorry(self, \
                i18n("Can't add another drive.  There can only be 26, for letters A-Z"))
            return

        self.updateChanges()

    def slotRemoveClicked(self):
        """ Removes the currently selected drive """
        if self.selecteddriveid == 2:   # Drive C:
            if KMessageBox.warningContinueCancel(self, \
                i18n("Are you sure you want to delete drive C:?\n\n"\
                    "Most Windows applications expect drive C: to exist, "\
                    "and will die messily if it doesn't.  If you proceed "\
                    "remember to recreate it!"),\
                i18n("Warning")) != KMessageBox.Continue:
                return
        self.drives[self.selecteddriveid][2:4] = ("","")
        self.selecteddriveid -= 1     # Not quite correct, should select previous drive.
        self.updateChanges()

    def slotAutoClicked(self):
        """ 
        Autodetects a default set of drives from /etc/fstab
        Allows the user to start with a fresh list of drives or append to the current one
        """
        automethod = KMessageBox.questionYesNoCancel(self, \
            i18n("Would you like to remove the current set of drives?"),\
            i18n("Drive Autodetection"))
        if automethod == KMessageBox.Yes:
            autodrives = drivedetect.autodetect()
            autoshelllinks = drivedetect.autodetectshelllinks()
        elif automethod == KMessageBox.No:
            autodrives = drivedetect.autodetect(self.drives[:26])
            autoshelllinks = drivedetect.autodetectshelllinks(self.drives[26:])
        else:
            return

        if autodrives[0] == 1:
            KMessageBox.sorry(self, \
                i18n("There were not enough letters to add all the autodetected drives."))
        self.drives[0:26] = autodrives[1]
        self.drives[26:] = autoshelllinks

        self.updateChanges()

    def slotTypeActivated(self,index):
        self.__selectType(self.types[index][2])
        self.updateChanges()

    def fillTypeCombo(self,combo):
        """ Fill the combobox with the values from our list """
        for drivetype in self.types:
            combo.insertItem(drivetype[1])

    def __selectType(self,typename):
        if typename:
            typeid = self.typesdic[typename]
        else:
            typeid = self.typesdic['auto']
        self.drives[self.selecteddriveid][3] = typename
        self.typecombo.setCurrentItem(typeid)

    def updateDrivesList(self):
        """ Updates the displayed list of drives """
        self.driveslist.clear()
        self.drivesToListItems = {}
        firstselecteddriveid = None
        lastdriveid = None

        for driveid, driveletter, mapping, drivetype, drivelabel, serial in reversed(self.drives):
            if mapping or drivelabel:
                lvi = TQListViewItem(self.driveslist,driveletter,mapping)
                self.drivesToListItems[driveid] = lvi
                if self.selecteddriveid==driveid:
                    firstselecteddriveid = driveid
                lastdriveid = driveid
            else:
                continue

        if firstselecteddriveid==None:
            firstselecteddriveid = lastdriveid

        self.selecteddriveid = firstselecteddriveid
        self.__selectDrive(self.selecteddriveid)
        self.driveslist.ensureItemVisible(self.driveslist.currentItem())

    def __selectDrive(self,driveid):
        """ Updates the GUI for a newly selected drive """
        self.selecteddriveid = driveid
        lvi = self.drivesToListItems[driveid]
        self.driveslist.setSelected(lvi,True)
        self.driveslist.setCurrentItem(lvi)

        self.fsfolderedit.setText(self.drives[driveid][2])
        if self.drives[driveid][3] == 'shellfolder':
            self.typecombo.insertItem(i18n("Shell Folder"))
            self.typecombo.setCurrentItem(5)
            self.typecombo.setEnabled(False)

            self.removebutton.setEnabled(False)

            self.infotext1.setText(str(i18n("Windows path: ")) + self.drives[driveid][4])

            # It seems some old versions of wine didn't store the shell folders in the same place
            if self.drives[driveid][5] != self.drives[driveid][4]:
                changeregistryshell = KMessageBox.warningYesNo(self, \
                    i18n("The " + self.drives[driveid][1] + " folder is currently located in\n" + \
                    self.drives[driveid][5] + "\nIt is recommended that it is put in the default " + \
                    "location in\n" + wineread.defaultwinfolderspath + "\nWould you like to move it there?"),\
                    i18n("Shell Folder Mapping"))
                changeregistryshell = changeregistryshell == KMessageBox.Yes

                if changeregistryshell:
                    self.drives[driveid][5] = self.drives[driveid][4]
                    self.changed = True
                    self.emit(PYSIGNAL("changedSignal()"), ())

            if self.drives[driveid][2] == wineread.profilesdirectory + self.drives[driveid][1]:
                realfolderwarning = KMessageBox.information(self, \
                    i18n(self.drives[driveid][1] + " is an actual folder and is not linked elsewhere." + \
                    "  Remapping it will create a backup of the directory in " + \
                    wineread.profilesdirectory),\
                    i18n("Shell Folder Mapping"))
        else:
            if self.typecombo.count() > 5:
                self.typecombo.removeItem(5)
                self.typecombo.setEnabled(True)
            self.__selectType(self.drives[driveid][3])

            self.removebutton.setEnabled(True)

            if self.drives[driveid][4]:
                self.infotext1.setText(str(i18n("Label: ")) + self.drives[driveid][4])
            else:
                self.infotext1.setText("")
            if self.drives[driveid][5]:
                self.infotext2.setText(str(i18n("Serial: ")) + self.drives[driveid][5])
            else:
                self.infotext2.setText("")

    def setMargin(self,margin):
        self.top_layout.setMargin(margin)

    def setSpacing(self,spacing):
        self.top_layout.setSpacing(spacing)

############################################################################
class AudioPage(TQWidget):
    driversdic = {
        "":i18n("None - Disable Sound"),
        "alsa":"ALSA",
        "arts":"aRts",
        "esd":"EsounD",
        "oss":"OSS",
        "jack":"JACK",
        "nas":"NAS",
        "coreaudio":"CoreAudio"}

    drivers = ("","alsa","arts","esd","oss","jack","nas","coreaudio")

    accel = (
        (0,i18n("Full")),
        (1,i18n("Standard")),
        (2,i18n("Basic")),
        (3,i18n("Emulation")))

    samplerates = (
        (0,"48000",48000),
        (1,"44100",44100),
        (2,"22050",22050),
        (3,"16000",16000),
        (4,"11025",11025),
        (5,"8000",8000))

    bitspersample = (
        (0,"8",8),
        (1,"16",16))

    def __init__(self,parent = None,name = None,modal = 0,fl = 0):
        global application
        TQWidget.__init__(self,parent)

        if not name:
            self.setName("AudioTab")

        audio_tab_layout = TQVBoxLayout(self,0,0,"AudioTabLayout")
        self.top_layout = audio_tab_layout

        vbox = TQVBox(self)
        vbox.setSpacing(KDialog.spacingHint())

        audio_tab_layout.addWidget(vbox)

        if application:
            appwarning = TQLabel(vbox,"appwarning")
            appwarning.setText(i18n("Application specific settings for <b>" +\
                application + "</b><p>Changing a setting here will permanently " +\
                "make that setting independent of settings for all other " +\
                "applications.</p>"))
            appwarning.setFrameStyle( TQFrame.Box | TQFrame.Raised )

        # -- Drivers group
        self.driver_group_box = TQHGroupBox(vbox)
        self.driver_group_box.setTitle(i18n("Driver Selection"))
        self.driver_group_box.setInsideSpacing(KDialog.spacingHint())
        self.driver_group_box.setInsideMargin(KDialog.marginHint())

        vbox2 = TQVBox(self.driver_group_box)
        vbox2.setSpacing(KDialog.spacingHint())

        hbox = TQHBox(vbox2)
        hbox.setSpacing(KDialog.spacingHint())

        drivertext = TQLabel(hbox,"drivertext")
        drivertext.setText(i18n("Audio Driver:"))

        self.drivercombo = KComboBox(0,hbox,"drivercombo")
        self.fillDriverCombo(self.drivercombo)
        self.connect(self.drivercombo,SIGNAL("activated(int)"),self.slotDriverActivated)

        TQToolTip.add(hbox, i18n("Choose an audio driver.  Not all audio " +\
            "drivers are available."))
        spacer = TQWidget(hbox)
        hbox.setStretchFactor(spacer,1)

        if application:
            self.driver_group_box.hide()

        # -- DirectSound Settings group
        self.dsound_group_box = TQHGroupBox(vbox)
        self.dsound_group_box.setTitle(i18n("DirectSound"))
        self.dsound_group_box.setInsideSpacing(KDialog.spacingHint())
        self.dsound_group_box.setInsideMargin(KDialog.marginHint())

        vbox2 = TQVBox(self.dsound_group_box)
        vbox2.setSpacing(KDialog.spacingHint())

        hbox = TQHBox(vbox2)
        hbox.setSpacing(KDialog.spacingHint())

        acceltext = TQLabel(hbox,"acceltext")
        acceltext.setText(i18n("Hardware Acceleration:"))

        self.accelcombo = KComboBox(0,hbox,"accelcombo")
        self.fillAccelCombo(self.accelcombo)
        self.connect(self.accelcombo,SIGNAL("activated(int)"),self.slotAccelActivated)

        spacer = TQWidget(hbox)
        hbox.setStretchFactor(spacer,1)

        hbox = TQHBox(vbox2)
        hbox.setSpacing(KDialog.spacingHint())

        self.overridecheckbox = TQCheckBox(i18n("Override KDE Sample Rate"),hbox)
        hbox.setStretchFactor(self.overridecheckbox,0)
        self.connect(self.overridecheckbox,SIGNAL("toggled(bool)"),self.slotOverrideKDESoundToggled)
        self.overridecheckbox.hide()

        self.sampleratehbox = TQHBox(vbox2)
        self.sampleratehbox.setSpacing(KDialog.spacingHint())

        sampletext = TQLabel(self.sampleratehbox,"sampletext")
        sampletext.setText(i18n("Default Sample Rate:"))

        self.samplecombo = KComboBox(0,self.sampleratehbox,"samplecombo")
        self.fillSampleCombo(self.samplecombo)
        self.connect(self.samplecombo,SIGNAL("activated(int)"),self.slotSampleActivated)

        bitstext = TQLabel(self.sampleratehbox,"bitstext")
        bitstext.setText(i18n("Default Bits Per Sample:"))

        self.bitscombo = KComboBox(0,self.sampleratehbox,"bitscombo")
        self.fillBitsCombo(self.bitscombo)
        self.connect(self.bitscombo,SIGNAL("activated(int)"),self.slotBitsActivated)

        spacer = TQWidget(self.sampleratehbox)
        self.sampleratehbox.setStretchFactor(spacer,1)

        hbox = TQHBox(vbox2)
        hbox.setSpacing(KDialog.spacingHint())

        self.drvemucheckbox = TQCheckBox(i18n("Driver Emulation"),hbox)
        hbox.setStretchFactor(self.drvemucheckbox,0)
        self.connect(self.drvemucheckbox,SIGNAL("toggled(bool)"), self.slotDriverEmulToggled)

        bottomspacer = TQSpacerItem(51,160,TQSizePolicy.Minimum,TQSizePolicy.Expanding)
        audio_tab_layout.addItem(bottomspacer)

        self.reset()

        self.clearWState(TQt.WState_Polished)

    def fillDriverCombo(self,combo):
        """ Fill the combobox with the values from our list """
        for driver in self.drivers:
            combo.insertItem(self.driversdic[driver])

    def fillAccelCombo(self,combo):
        """ Fill the combobox with the values from our list """
        for accel in self.accel:
            combo.insertItem(accel[1])

    def fillSampleCombo(self,combo):
        """ Fill the combobox with the values from our list """
        for rate in self.samplerates:
            combo.insertItem(rate[1])

    def fillBitsCombo(self,combo):
        """ Fill the combobox with the values from our list """
        for bits in self.bitspersample:
            combo.insertItem(bits[1])

    def isChanged(self):
        changed = False
        changed = changed or (not application and self.currentdriver != self.originaldriver)
        changed = changed or self.currentaccel != self.originalaccel
        changed = changed or self.currentsamplerate != self.originalsamplerate
        changed = changed or self.currentbitspersample != self.originalbitspersample
        changed = changed or self.currentemuldriver != self.originalemuldriver
        return changed

    def reset(self):
        if not application:
            self.currentdriver = wineread.GetAudioDriver()
            self.originaldriver = self.currentdriver
            self.__selectDriver(self.currentdriver)

        dsoundsettings = wineread.GetDSoundSettings(application)
        globaldsoundsettings = wineread.GetDSoundSettings()

        self.currentaccel = dsoundsettings.get("HardwareAcceleration",\
            globaldsoundsettings.get("HardwareAcceleration", "Full"))
        self.originalaccel = self.currentaccel
        self.__selectAccel(self.currentaccel)

        self.currentsamplerate = dsoundsettings.get("DefaultSampleRate",\
            globaldsoundsettings.get("DefaultSampleRate", "44100"))
        self.originalsamplerate = self.currentsamplerate
        self.__selectSampleRate(self.currentsamplerate)

        self.currentbitspersample = dsoundsettings.get("DefaultBitsPerSample",\
             globaldsoundsettings.get("DefaultBitsPerSample","16"))
        self.originalbitspersample = self.currentbitspersample
        self.__selectBitsPerSample(self.currentbitspersample)

        self.currentemuldriver = dsoundsettings.get("EmulDriver",\
            globaldsoundsettings.get("EmulDriver", "N"))
        self.originalemuldriver = self.currentemuldriver
        self.__setDriverEmul(self.currentemuldriver)

        self.currentkdeoverride = True
        self.originalkdeoverride = self.currentkdeoverride
        self.__setOverrideKDESound(self.currentkdeoverride)

    def applyChanges(self):
        if not application:
            winewrite.SetAudioDriver(self.currentdriver)

        dsoundsettings = {"HardwareAcceleration":self.currentaccel,
            "DefaultSampleRate":self.currentsamplerate,
            "DefaultBitsPerSample":self.currentbitspersample,
            "EmulDriver":self.currentemuldriver}

        winewrite.SetDSoundSettings(dsoundsettings, application)

        self.reset()

    def slotDriverActivated(self,driverid):
        self.currentdriver = self.drivers[driverid]
        self.emit(PYSIGNAL("changedSignal()"), ())

    def slotAccelActivated(self,accelid):
        self.currentaccel = self.accel[accelid][1]
        self.emit(PYSIGNAL("changedSignal()"), ())

    def slotSampleActivated(self,sampleid):
        self.currentsamplerate = self.samplerates[sampleid][1]
        self.emit(PYSIGNAL("changedSignal()"), ())

    def slotBitsActivated(self,bitsid):
        self.currentbitspersample = self.bitspersample[bitsid][1]
        self.emit(PYSIGNAL("changedSignal()"), ())

    def slotDriverEmulToggled(self,driveremul):
        if driveremul:
            self.currentemuldriver = 'Y'
        else:
            self.currentemuldriver = 'N'
        self.emit(PYSIGNAL("changedSignal()"), ())

    def slotOverrideKDESoundToggled(self,override):
        self.__setOverrideKDESound(override)
        self.emit(PYSIGNAL("changedSignal()"), ())

    def __selectDriver(self,drivername):
        """
        Sets the current driver and selects it in the combo box
        Assumes drivername is a valid driver
        """
        driverid = 0
        for driver in self.drivers:
            if driver == drivername:
                break
            else:
                driverid += 1

        self.currentdriver = drivername
        self.drivercombo.setCurrentItem(driverid)

    def __selectAccel(self,accelmode):
        """
        Sets the current acceleration mode and selects it in the combo box
        Assumes accelmode i sa valid acceleration mode
        """
        accelid = 0
        for accelmode1 in self.accel:
            if accelmode1[1] == accelmode:
                break
            else:
                accelid += 1

        self.currentaccel = accelmode
        self.accelcombo.setCurrentItem(accelid)

    def __selectSampleRate(self,samplerate):
        """
        Sets the current acceleration mode and selects it in the combo box
        Assumes samplerate is a valid sample rate
        """
        sampleid = 0
        for samplerate1 in self.samplerates:
            if samplerate1[1] == samplerate:
                break
            else:
                sampleid += 1

        self.currentsamplerate = samplerate
        self.samplecombo.setCurrentItem(sampleid)

    def __selectBitsPerSample(self,bits):
        """
        Sets the current acceleration mode and selects it in the combo box
        Assumes bits is a valid value for bits per sample
        """
        bitsid = 0
        for bits1 in self.bitspersample:
            if bits1[1] == bits:
                break
            else:
                bitsid += 1

        self.currentbitspersample = bits
        self.bitscombo.setCurrentItem(bitsid)

    def __setDriverEmul(self,driveremul):
        """ Enables/disables the driver emulation mode """
        self.currentdriveremul = driveremul
        driveremul = driveremul != 'N'
        self.drvemucheckbox.setChecked(driveremul)

    def __setOverrideKDESound(self,override):
        """ Enables/disables use of KDE's (aRts) sample rate settings """
        self.currentkdeoverride = override
        self.sampleratehbox.setEnabled(override)
        self.overridecheckbox.setChecked(override)

    def setMargin(self,margin):
        self.top_layout.setMargin(margin)

    def setSpacing(self,spacing):
        self.top_layout.setSpacing(spacing)


############################################################################
class GraphicsPage(TQWidget):

    # Mapping values in seconds to human-readable labels.
    vertexshadersupport = (
        (0,i18n("Hardware")),
        (1,i18n("None")),
        (2,i18n("Emulation")))

    vertexshadersupportdic = {
        "hardware":0,
        "none":1,
        "emulation":2}

    def __init__(self,parent = None,name = None,modal = 0,fl = 0):
        global currentallowwm
        TQWidget.__init__(self,parent)

        if not name:
            self.setName("GraphicsTab")

        graphics_tab_layout = TQVBoxLayout(self,0,0,"GraphicsTabLayout")
        self.top_layout = graphics_tab_layout

        vbox = TQVBox(self)
        vbox.setSpacing(KDialog.spacingHint())

        graphics_tab_layout.addWidget(vbox)

        if application:
            appwarning = TQLabel(vbox,"appwarning")
            appwarning.setText(i18n("Application specific settings for <b>" +\
                application + "</b><p>Changing a setting here will permanently " +\
                "make that setting independent of settings for all other " +\
                "applications.</p>"))
            appwarning.setFrameStyle( TQFrame.Box | TQFrame.Raised )

        # -- Window settings group
        self.windows_group_box = TQHGroupBox(vbox)
        self.windows_group_box.setTitle(i18n("Window Settings"))
        self.windows_group_box.setInsideSpacing(KDialog.spacingHint())
        self.windows_group_box.setInsideMargin(KDialog.marginHint())

        vbox2 = TQVBox(self.windows_group_box)
        vbox2.setSpacing(KDialog.spacingHint())

        self.allowcursorcheckbox = TQCheckBox(i18n("Allow DirectX applications to stop the mouse leaving their window"),vbox2)
        self.connect(self.allowcursorcheckbox,SIGNAL("toggled(bool)"), self.slotAllowCursorToggled)

        self.dubbuffercheckbox = TQCheckBox(i18n("Enable desktop double buffering"),vbox2)
        self.connect(self.dubbuffercheckbox,SIGNAL("toggled(bool)"), self.slotDubBufferToggled)

        self.allowwmcheckbox = TQCheckBox(i18n("Allow the window manager to control the windows"),vbox2)
        self.connect(self.allowwmcheckbox,SIGNAL("toggled(bool)"), self.slotAllowWMToggled)

        TQToolTip.add(self.allowwmcheckbox, \
            i18n("<p>If windows are managed by your window manager, then they" +\
            " will have the standard borders, they will respect your virtual" +\
            " desktop and appear in your window list.\n</p><p>" +\
            "If the windows are unmanaged, they will be disconnected from your" +\
            " window manager.  This will mean the windows do not integrate as" +\
            " closely with your desktop, but the emulation will be more" +\
            " accurate so it can help some programs work better.</p>"))

        self.showdragcheckbox = TQCheckBox(i18n("Display window contents while dragging"),vbox2)
        self.connect(self.showdragcheckbox,SIGNAL("toggled(bool)"), self.slotShowDragToggled)

        self.emudesktopcheckbox = TQCheckBox(i18n("Emulate a virtual desktop"),vbox2)
        self.connect(self.emudesktopcheckbox,SIGNAL("toggled(bool)"), self.slotEmuDesktopToggled)

        self.desksizehbox = TQHBox(vbox2)
        self.desksizehbox.setSpacing(KDialog.spacingHint())

        desksizetext = TQLabel(self.desksizehbox,"desksizetext")
        desksizetext.setText(i18n("Desktop size:"))

        self.xsizeedit = KLineEdit("640",self.desksizehbox)
        self.xsizeedit.setValidator(TQIntValidator(self.xsizeedit))
        self.connect(self.xsizeedit,SIGNAL("textChanged(const TQString &)"),self.slotDesktopSizeChanged)
        bytext = TQLabel(self.desksizehbox,"bytext")
        bytext.setText(i18n("x"))
        self.ysizeedit = KLineEdit("480",self.desksizehbox)
        self.ysizeedit.setValidator(TQIntValidator(self.ysizeedit))
        self.connect(self.ysizeedit,SIGNAL("textChanged(const TQString &)"),self.slotDesktopSizeChanged)

        spacer = TQWidget(self.desksizehbox)
        self.desksizehbox.setStretchFactor(spacer,1)

        TQToolTip.add(self.emudesktopcheckbox,
            i18n("<p>You can choose to emulate a Windows desktop, where all" +\
            " the windows are confined to one 'virtual screen', or you" +\
            " can have the windows placed on your standard desktop.</p>"))
        TQToolTip.add(self.desksizehbox, TQToolTip.textFor(self.emudesktopcheckbox))

        if application:
            self.emudesktopcheckbox.hide()
            self.desksizehbox.hide()
            self.showdragcheckbox.hide()

        # -- Direct3D settings group
        self.d3d_group_box = TQHGroupBox(vbox)
        self.d3d_group_box.setTitle(i18n("Direct3D"))
        self.d3d_group_box.setInsideSpacing(KDialog.spacingHint())
        self.d3d_group_box.setInsideMargin(KDialog.marginHint())

        vbox2 = TQVBox(self.d3d_group_box)
        vbox2.setSpacing(KDialog.spacingHint())

        hbox = TQHBox(vbox2)
        hbox.setSpacing(KDialog.spacingHint())

        vertexshadertext = TQLabel(hbox,"vertexshadertext")
        vertexshadertext.setText(i18n("Vertex Shader Support:"))

        self.accelcombo = KComboBox(0,hbox,"accelcombo")
        self.fillCombo(self.accelcombo)
        self.connect(self.accelcombo,SIGNAL("activated(int)"),self.slotVertexShaderModeActivated)

        spacer = TQWidget(hbox)
        hbox.setStretchFactor(spacer,1)

        hbox = TQHBox(vbox2)
        hbox.setSpacing(KDialog.spacingHint())

        self.pixelshadercheckbox = TQCheckBox(i18n("Allow Pixel Shader (if supported by hardware)"),hbox)
        self.connect(self.pixelshadercheckbox,SIGNAL("toggled(bool)"), self.slotPixelShaderModeToggled)

        hbox = TQHBox(vbox2)
        hbox.setSpacing(KDialog.spacingHint())

        self.glslcheckbox = TQCheckBox(i18n("Use GL Shader Language"),hbox)
        self.connect(self.glslcheckbox,SIGNAL("toggled(bool)"), self.slotGLSLToggled)

        TQToolTip.add(hbox,
            i18n("<p>This enables the use of GL Shading Language for vertex" +\
                " and pixel shaders, as long as the hardware supports it." +\
                "  This is experimental.</p>"))

        bottomspacer = TQSpacerItem(51,160,TQSizePolicy.Minimum,TQSizePolicy.Expanding)
        graphics_tab_layout.addItem(bottomspacer)

        self.reset()

        self.clearWState(TQt.WState_Polished)

    def fillCombo(self,combo):
        """ Fill the combobox with the values from our list """
        for accel in self.vertexshadersupport:
            combo.insertItem(accel[1])

    def isChanged(self):
        changed = False
        changed = changed or self.originalallowcursor != self.currentallowcursor
        changed = changed or self.originaldubbuffer != self.currentdubbuffer
        changed = changed or self.originalallowwm != currentallowwm
        changed = changed or (not application and \
            self.originalemudesktop != self.currentemudesktop)
        changed = changed or self.originalvertexshadermode != self.currentvertexshadermode
        changed = changed or self.originalpixelshadermode != self.currentpixelshadermode
        changed = changed or self.originalglsl != self.currentglsl
        changed = changed or (not application and \
            self.originalshowdrag != self.currentshowdrag)
        return changed

    def reset(self):
        """ Resets the settings to ones read from the registry """
        global currentallowwm
        settings = wineread.GetWindowSettings(application)
        globalsettings = wineread.GetWindowSettings()

        self.currentallowcursor = settings.get("DXGrab",\
            globalsettings.get("DXGrab",'N'))
        self.originalallowcursor = self.currentallowcursor
        self.__setAllowCursor(self.currentallowcursor)

        self.currentdubbuffer = settings.get("DesktopDoubleBuffered",\
            globalsettings.get("DesktopDoubleBuffered",'Y'))
        self.originaldubbuffer = self.currentdubbuffer
        self.__setDubBuffer(self.currentdubbuffer)

        currentallowwm = settings.get("Managed",\
            globalsettings.get("Managed",'Y'))
        self.originalallowwm = currentallowwm

        if not application:
            self.currentemudesktop = settings.get("Desktop","")
            self.originalemudesktop = self.currentemudesktop
            self.__setEmuDesktop(self.currentemudesktop)
        self.__setAllowWM(currentallowwm)

        d3dsettings = wineread.GetD3DSettings(application)
        globald3dsettings = wineread.GetD3DSettings()

        self.currentvertexshadermode = d3dsettings.get("VertexShaderMode",\
            globald3dsettings.get("VertexShaderMode","hardware"))
        self.originalvertexshadermode = self.currentvertexshadermode
        self.__selectVertexShaderMode(self.currentvertexshadermode)

        self.currentpixelshadermode = d3dsettings.get("PixelShaderMode",\
            globald3dsettings.get("PixelShaderMode","enabled"))
        self.originalpixelshadermode = self.currentpixelshadermode
        self.__setPixelShaderMode(self.currentpixelshadermode)

        self.currentglsl = d3dsettings.get("UseGLSL",\
            globald3dsettings.get("UseGLSL","disabled"))
        self.originalglsl = self.currentglsl
        self.__setGLSL(self.currentglsl)

        if not application:
            cpdesktopsettings = wineread.GetDesktopSettings()

            self.currentshowdrag = cpdesktopsettings.get("DragFullWindows","0")
            self.originalshowdrag = self.currentshowdrag
            self.__setShowDrag(self.currentshowdrag)

    def applyChanges(self):
        """ Applies the changes to wine's configuration """
        settings = {"DXGrab":self.currentallowcursor,
            "DesktopDoubleBuffered":self.currentdubbuffer,
            "Managed":currentallowwm}

        if not application:
            settings["Desktop"] = self.currentemudesktop

        winewrite.SetWindowSettings(settings, application)

        d3dsettings = {"VertexShaderMode":self.currentvertexshadermode,
            "PixelShaderMode":self.currentpixelshadermode,
            "UseGLSL":self.currentglsl}

        winewrite.SetD3DSettings(d3dsettings, application)

        if not application:
            cpdesktopsettings = {"DragFullWindows":self.currentshowdrag}

            winewrite.SetDesktopSettings(cpdesktopsettings)

        self.reset()

    def slotAllowCursorToggled(self,allow):
        if allow:
            self.currentallowcursor = 'Y'
        else:
            self.currentallowcursor = 'N'
        self.emit(PYSIGNAL("changedSignal()"), ())

    def slotDubBufferToggled(self,dub):
        if dub:
            self.currentdubbuffer = 'Y'
        else:
            self.currentdubbuffer = 'N'
        self.emit(PYSIGNAL("changedSignal()"), ())

    def slotAllowWMToggled(self,allow):
        global currentallowwm
        if allow:
            currentallowwm = 'Y'
        else:
            currentallowwm = 'N'
        if not application:
            if allow and self.currentemudesktop == "":
                self.showdragcheckbox.setEnabled(False)
            else:
                self.showdragcheckbox.setEnabled(True)
        self.emit(PYSIGNAL("changedSignal()"), ())

    def slotShowDragToggled(self,show):
        if show:
            self.currentshowdrag = '2'
        else:
            self.currentshowdrag = '0'
        self.emit(PYSIGNAL("changedSignal()"), ())

    def slotEmuDesktopToggled(self,emudesktop):
        if emudesktop:
            self.currentemudesktop = str(self.xsizeedit.text()) + 'x' + str(self.ysizeedit.text())
        else:
            self.currentemudesktop = ""
        self.__setEmuDesktop(self.currentemudesktop)
        self.emit(PYSIGNAL("changedSignal()"), ())

    def slotDesktopSizeChanged(self,size):
        self.slotEmuDesktopToggled(True)

    def slotVertexShaderModeActivated(self,modeid):
        mode = self.vertexshadersupport[modeid][1][0].lower() + self.vertexshadersupport[modeid][1][1:]
        self.currentvertexshadermode = mode
        self.emit(PYSIGNAL("changedSignal()"), ())

    def slotPixelShaderModeToggled(self,mode):
        if mode:
            self.currentpixelshadermode = 'enabled'
        else:
            self.currentpixelshadermode = 'disabled'

        self.emit(PYSIGNAL("changedSignal()"), ())

    def slotGLSLToggled(self,mode):
        if mode:
            self.currentglsl = 'enabled'
        else:
            self.currentglsl = 'disabled'

        self.emit(PYSIGNAL("changedSignal()"), ())

    def __setAllowCursor(self, allow):
        self.currentallowcursor = allow
        allow = allow != 'N'
        self.allowcursorcheckbox.setChecked(allow)

    def __setDubBuffer(self, dub):
        self.currentdubbuffer = dub
        dub = dub != 'N'
        self.dubbuffercheckbox.setChecked(dub)

    def __setAllowWM(self, allow):
        global currentallowwm
        currentallowwm = allow
        allow = allow != 'N'
        self.allowwmcheckbox.setChecked(allow)
        if not application:
            if allow and self.currentemudesktop == "":
                self.showdragcheckbox.setEnabled(False)
            else:
                self.showdragcheckbox.setEnabled(True)

    def __setEmuDesktop(self, emudesktop):
        self.currentemudesktop = emudesktop
        emudesktopbool = emudesktop != ""
        self.emudesktopcheckbox.setChecked(emudesktopbool)
        self.desksizehbox.setEnabled(emudesktopbool)
        if emudesktopbool:
            desktopsize = emudesktop.split('x')
            self.xsizeedit.setText(desktopsize[0])
            self.ysizeedit.setText(desktopsize[1])
            self.showdragcheckbox.setEnabled(True)
        elif currentallowwm:
            self.showdragcheckbox.setEnabled(False)

    def __selectVertexShaderMode(self,mode):
        self.currentvertexshadermode = mode
        self.accelcombo.setCurrentItem(self.vertexshadersupportdic[mode])

    def __setPixelShaderMode(self,mode):
        self.currentpixelshadermode = mode
        mode = mode == 'enabled'
        self.pixelshadercheckbox.setChecked(mode)

    def __setGLSL(self,mode):
        self.currentglsl = mode
        mode = mode == 'enabled'
        self.glslcheckbox.setChecked(mode)

    def __setShowDrag(self,show):
        self.currentshowdrag = show
        show = show != '0'
        self.showdragcheckbox.setChecked(show)

    def setMargin(self,margin):
        self.top_layout.setMargin(margin)

    def setSpacing(self,spacing):
        self.top_layout.setSpacing(spacing)


############################################################################
class AppearancePage(TQWidget):

    themes = [str(i18n("No Theme"))]
    colorschemes = [str(i18n("Custom"))]
    sizes = [("NormalSize",str(i18n("Normal"))),
        ("LargeSize",str(i18n("Large Fonts"))),
        ("ExtraLargeSize",str(i18n("Extra Large Fonts")))]

    # Items for the combo box reference a tuple of dictionaries for color
    # and size values and translations for that item
    # For example, the value of BorderWidth is
    #  customizableitems[str(i18n("Window Border"))][1]["BorderWidth"][1]
    customizableitems = {"Window Border":
            ({"ActiveBorder":[str(i18n("Active Color:")),TQColor()],
              "InactiveBorder":[str(i18n("Inactive Color:")),TQColor()]},
             {"BorderWidth":[str(i18n("Width:")),1]}), #ActiveBorder, InactiveBorder, metrics: BorderWidth
        "Title Bar":
            ({"ActiveTitle":[str(i18n("Active Color:")),TQColor()],
              "GradientActiveTitle":[str(i18n("Gradient:")),TQColor()],
              "InactiveTitle":[str(i18n("Inactive Color:")),TQColor()],
              "GradientInactiveTitle":[str(i18n("Gradient:")),TQColor()],
              "TitleText":[str(i18n("Active Text:")),TQColor()],
              "InactiveTitleText":[str(i18n("Inactive Text:")),TQColor()]},
             {}), #ActiveTitle, GradientActiveTitle, InactiveTitle, GradientInactiveTitle, TitleText, InactiveTitleText
        "Application Workspace":
            ({"AppWorkSpace":[str(i18n("Background Color:")),TQColor()]},
             {}), #AppWorkSpace "Background"
        "Buttons":
            ({"ButtonFace":[str(i18n("Face:")),TQColor()],
              "ButtonHilight":[str(i18n("Hilight:")),TQColor()],
              "ButtonLight":[str(i18n("Light:")),TQColor()],
              "ButtonShadow":[str(i18n("Shadow:")),TQColor()],
              "ButtonText":[str(i18n("Text Color:")),TQColor()],
              "ButtonAlternateFace":[str(i18n("Alternate Face:")),TQColor()],
              "ButtonDkShadow":[str(i18n("Dark Shadow:")),TQColor()],
              "WindowFrame":[str(i18n("Frame:")),TQColor()]},
             {}), #ButtonFace, ButtonHilight, ButtonLight, ButtonShadow, ButtonText, ButtonAlternateFace, ButtonDkShadow, WindowFrame
        "Caption Buttons":
            ({},
             {"CaptionHeight":[str(i18n("Height:")),1],
              "CaptionWidth":[str(i18n("Width:")),1]}), #Metrics: CaptionHeight, CaptionWidth
        "Desktop":
            ({"Background":[str(i18n("Background:")),TQColor()]},
             {}), #Background
        "Menu":
            ({"Menu":[str(i18n("Menu Background:")),TQColor()],
              "MenuBar":[str(i18n("Menu Bar Color:")),TQColor()],
              "MenuHilight":[str(i18n("Menu Hilight:")),TQColor()],
              "MenuText":[str(i18n("Text Color:")),TQColor()]},
             {"MenuHeight":[str(i18n("Menu Bar Height:")),1]}), #Menu (Background), MenuBar, MenuHilight, MenuText, metrics: MenuHeight, MenuWidth (does nothing)
        "Scrollbar":
            ({"Scrollbar":[str(i18n("Color:")),TQColor()]},
             {"ScrollWidth":[str(i18n("Width:")),1]}), #Scrollbar, metrics: ScrollHeight (does nothing), ScrollWidth
        "Window":
            ({"Window":[str(i18n("Background:")),TQColor()],
              "WindowText":[str(i18n("Text Color:")),TQColor()]},
             {}), #Window "Background", WindowText
        "Selected Items":
            ({"Hilight":[str(i18n("Hilight Color:")),TQColor()],
              "HilightText":[str(i18n("Text Color:")),TQColor()]},
             {})} #Hilight, HilightText

    def __init__(self,parent = None,name = None,modal = 0,fl = 0):
        global imagedir
        TQWidget.__init__(self,parent)

        if not name:
            self.setName("AppearanceTab")

        appearance_tab_layout = TQVBoxLayout(self,0,0,"AppearanceTabLayout")
        self.top_layout = appearance_tab_layout

        vbox = TQVBox(self)
        vbox.setSpacing(KDialog.spacingHint())

        appearance_tab_layout.addWidget(vbox)

        # -- Appearance group
        self.appearance_group_box = TQVGroupBox(vbox)
        self.appearance_group_box.setTitle(i18n("Style and Colors"))
        self.appearance_group_box.setInsideSpacing(KDialog.spacingHint())
        self.appearance_group_box.setInsideMargin(KDialog.marginHint())

        themebox = TQWidget(self.appearance_group_box)

        theme_layout = TQGridLayout(themebox,3,3)
        theme_layout.setSpacing(KDialog.spacingHint())
        theme_layout.setColStretch(1,1)

        styletext = TQLabel(themebox,"styletext")
        styletext.setText(i18n("Widget Style:"))
        theme_layout.addWidget(styletext,0,0)

        self.themes = self.themes + wineread.GetThemesList()
        self.themecombo = KComboBox(0,themebox,"themecombo")
        self.fillThemeCombo(self.themecombo)
        self.connect(self.themecombo,SIGNAL("activated(int)"),self.slotThemeActivated)
        theme_layout.addWidget(self.themecombo,0,1)

        self.installbutton = KPushButton(i18n("Install style..."),themebox)
        self.connect(self.installbutton,SIGNAL("clicked()"),self.slotInstallThemeClicked)
        theme_layout.addWidget(self.installbutton,0,2)

        fontsizetext = TQLabel(themebox,"fontsizetext")
        fontsizetext.setText(i18n("Font Size:"))
        theme_layout.addWidget(fontsizetext,1,0)

        self.fontsizecombo = KComboBox(0,themebox,"fontsizecombo")
        self.fillFontSizeCombo(self.fontsizecombo)
        self.connect(self.fontsizecombo,SIGNAL("activated(int)"),self.slotFontSizeActivated)
        theme_layout.addWidget(self.fontsizecombo,1,1)

        colorschemetext = TQLabel(themebox,"colorschemetext")
        colorschemetext.setText(i18n("Color Scheme:"))
        theme_layout.addWidget(colorschemetext,2,0)

        self.colorschemecombo = KComboBox(0,themebox,"colorschemecombo")
        self.fillColorSchemeCombo(self.colorschemecombo)
        self.connect(self.colorschemecombo,SIGNAL("activated(int)"),self.slotColorSchemeActivated)
        theme_layout.addWidget(self.colorschemecombo,2,1)

        self.saveschemebutton = KPushButton(i18n("Save..."),themebox)
        self.connect(self.saveschemebutton,SIGNAL("clicked()"),self.slotSaveSchemeClicked)
        theme_layout.addWidget(self.saveschemebutton,2,2)

        # --- Custom Colors ---
        hbox = TQHBox(self.appearance_group_box)
        hbox.setSpacing(KDialog.spacingHint())

        self.sizehbox = hbox
        self.leftspacer = TQWidget(hbox)

        self.customcolorsvbox = TQVBox(hbox)
        self.customcolorsvbox.setSpacing(KDialog.spacingHint())

        hbox = TQHBox(self.customcolorsvbox)
        hbox.setSpacing(KDialog.spacingHint())

        itemtext = TQLabel(hbox,"itemtext")
        itemtext.setText(i18n("Item:"))

        self.itemcombo = KComboBox(0,hbox,"itemcombo")
        self.fillItemCombo(self.itemcombo)
        self.connect(self.itemcombo,SIGNAL("activated(int)"),self.slotItemActivated)
        hbox.setStretchFactor(self.itemcombo,1)

        self.customcolorsgrid = TQWidget(self.customcolorsvbox)
        self.customcolorsgrid_layout = TQGridLayout(self.customcolorsgrid,4,2)
        self.customcolorsgrid_layout.setSpacing(KDialog.spacingHint())

        # Box 1 of 8
        self.colorsizehbox1 = TQWidget(self.customcolorsgrid,"colorsizehbox1")
        self.customcolorsgrid_layout.addWidget(self.colorsizehbox1,0,0)
        self.colorsizehbox1_layout = TQGridLayout(self.colorsizehbox1,1,2)
        self.colorsizehbox1_layout.setSpacing(KDialog.spacingHint())

        self.colorsizetext1 = TQLabel(self.colorsizehbox1,"colorsizetext1")
        self.colorsizetext1.setText(i18n(":"))
        self.colorsizehbox1_layout.addWidget(self.colorsizetext1,0,0,TQt.AlignRight)

        self.sizespinbox1 = TQSpinBox(self.colorsizehbox1,"sizespinbox1")
        self.sizespinbox1.setMinValue(0)
        self.connect(self.sizespinbox1,SIGNAL("valueChanged(int)"),self.slotSizeActivated)

        self.colorcombo1 = KColorCombo(self.colorsizehbox1,"colorcombo1")
        self.connect(self.colorcombo1,SIGNAL("activated(const TQColor &)"),self.slotColorActivated)

        # Box 2 of 8
        self.colorsizehbox2 = TQWidget(self.customcolorsgrid,"colorsizehbox2")
        self.customcolorsgrid_layout.addWidget(self.colorsizehbox2,0,1)
        self.colorsizehbox2_layout = TQGridLayout(self.colorsizehbox2,1,2)
        self.colorsizehbox2_layout.setSpacing(KDialog.spacingHint())

        self.colorsizetext2 = TQLabel(self.colorsizehbox2,"colorsizetext2")
        self.colorsizetext2.setText(i18n(":"))
        self.colorsizehbox2_layout.addWidget(self.colorsizetext2,0,0,TQt.AlignRight)

        self.sizespinbox2 = TQSpinBox(self.colorsizehbox2,"sizespinbox2")
        self.sizespinbox2.setMinValue(0)
        self.connect(self.sizespinbox2,SIGNAL("valueChanged(int)"),self.slotSizeActivated)

        self.colorcombo2 = KColorCombo(self.colorsizehbox2,"colorcombo2")
        self.connect(self.colorcombo2,SIGNAL("activated(const TQColor &)"),self.slotColorActivated)

        # Box 3 of 8
        self.colorsizehbox3 = TQWidget(self.customcolorsgrid,"colorsizehbox3")
        self.customcolorsgrid_layout.addWidget(self.colorsizehbox3,1,0)
        self.colorsizehbox3_layout = TQGridLayout(self.colorsizehbox3,1,2)
        self.colorsizehbox3_layout.setSpacing(KDialog.spacingHint())

        self.colorsizetext3 = TQLabel(self.colorsizehbox3,"colorsizetext3")
        self.colorsizetext3.setText(i18n(":"))
        self.colorsizehbox3_layout.addWidget(self.colorsizetext3,0,0,TQt.AlignRight)

        self.sizespinbox3 = TQSpinBox(self.colorsizehbox3,"sizespinbox3")
        self.sizespinbox3.setMinValue(0)
        self.connect(self.sizespinbox3,SIGNAL("valueChanged(int)"),self.slotSizeActivated)

        self.colorcombo3 = KColorCombo(self.colorsizehbox3,"colorcombo3")
        self.connect(self.colorcombo3,SIGNAL("activated(const TQColor &)"),self.slotColorActivated)

        # Box 4 of 8
        self.colorsizehbox4 = TQWidget(self.customcolorsgrid,"colorsizehbox4")
        self.customcolorsgrid_layout.addWidget(self.colorsizehbox4,1,1)
        self.colorsizehbox4_layout = TQGridLayout(self.colorsizehbox4,1,2)
        self.colorsizehbox4_layout.setSpacing(KDialog.spacingHint())

        self.colorsizetext4 = TQLabel(self.colorsizehbox4,"colorsizetext4")
        self.colorsizetext4.setText(i18n(":"))
        self.colorsizehbox4_layout.addWidget(self.colorsizetext4,0,0,TQt.AlignRight)

        self.sizespinbox4 = TQSpinBox(self.colorsizehbox4,"sizespinbox4")
        self.sizespinbox4.setMinValue(0)
        self.connect(self.sizespinbox4,SIGNAL("valueChanged(int)"),self.slotSizeActivated)

        self.colorcombo4 = KColorCombo(self.colorsizehbox4,"colorcombo4")
        self.connect(self.colorcombo4,SIGNAL("activated(const TQColor &)"),self.slotColorActivated)

        # Box 5 of 8
        self.colorsizehbox5 = TQWidget(self.customcolorsgrid,"colorsizehbox5")
        self.customcolorsgrid_layout.addWidget(self.colorsizehbox5,2,0)
        self.colorsizehbox5_layout = TQGridLayout(self.colorsizehbox5,1,2)
        self.colorsizehbox5_layout.setSpacing(KDialog.spacingHint())

        self.colorsizetext5 = TQLabel(self.colorsizehbox5,"colorsizetext5")
        self.colorsizetext5.setText(i18n(":"))
        self.colorsizehbox5_layout.addWidget(self.colorsizetext5,0,0,TQt.AlignRight)

        self.sizespinbox5 = TQSpinBox(self.colorsizehbox5,"sizespinbox5")
        self.sizespinbox5.setMinValue(0)
        self.connect(self.sizespinbox5,SIGNAL("valueChanged(int)"),self.slotSizeActivated)

        self.colorcombo5 = KColorCombo(self.colorsizehbox5,"colorcombo5")
        self.connect(self.colorcombo5,SIGNAL("activated(const TQColor &)"),self.slotColorActivated)

        # Box 6 of 8
        self.colorsizehbox6 = TQWidget(self.customcolorsgrid,"colorsizehbox6")
        self.customcolorsgrid_layout.addWidget(self.colorsizehbox6,2,1)
        self.colorsizehbox6_layout = TQGridLayout(self.colorsizehbox6,1,2)
        self.colorsizehbox6_layout.setSpacing(KDialog.spacingHint())

        self.colorsizetext6 = TQLabel(self.colorsizehbox6,"colorsizetext6")
        self.colorsizetext6.setText(i18n(":"))
        self.colorsizehbox6_layout.addWidget(self.colorsizetext6,0,0,TQt.AlignRight)

        self.sizespinbox6 = TQSpinBox(self.colorsizehbox6,"sizespinbox6")
        self.sizespinbox6.setMinValue(0)
        self.connect(self.sizespinbox6,SIGNAL("valueChanged(int)"),self.slotSizeActivated)

        self.colorcombo6 = KColorCombo(self.colorsizehbox6,"colorcombo6")
        self.connect(self.colorcombo6,SIGNAL("activated(const TQColor &)"),self.slotColorActivated)

        # Box 7 of 8
        self.colorsizehbox7 = TQWidget(self.customcolorsgrid,"colorsizehbox7")
        self.customcolorsgrid_layout.addWidget(self.colorsizehbox7,3,0)
        self.colorsizehbox7_layout = TQGridLayout(self.colorsizehbox7,1,2)
        self.colorsizehbox7_layout.setSpacing(KDialog.spacingHint())

        self.colorsizetext7 = TQLabel(self.colorsizehbox7,"colorsizetext7")
        self.colorsizetext7.setText(i18n(":"))
        self.colorsizehbox7_layout.addWidget(self.colorsizetext7,0,0,TQt.AlignRight)

        self.sizespinbox7 = TQSpinBox(self.colorsizehbox7,"sizespinbox7")
        self.sizespinbox7.setMinValue(0)
        self.connect(self.sizespinbox7,SIGNAL("valueChanged(int)"),self.slotSizeActivated)

        self.colorcombo7 = KColorCombo(self.colorsizehbox7,"colorcombo7")
        self.connect(self.colorcombo7,SIGNAL("activated(const TQColor &)"),self.slotColorActivated)

        # Box 8 of 8
        self.colorsizehbox8 = TQWidget(self.customcolorsgrid,"colorsizehbox8")
        self.customcolorsgrid_layout.addWidget(self.colorsizehbox8,3,1)
        self.colorsizehbox8_layout = TQGridLayout(self.colorsizehbox8,1,2)
        self.colorsizehbox8_layout.setSpacing(KDialog.spacingHint())

        self.colorsizetext8 = TQLabel(self.colorsizehbox8,"colorsizetext8")
        self.colorsizetext8.setText(i18n(":"))
        self.colorsizehbox8_layout.addWidget(self.colorsizetext8,0,0,TQt.AlignRight)

        self.sizespinbox8 = TQSpinBox(self.colorsizehbox8,"sizespinbox8")
        self.sizespinbox8.setMinValue(0)
        self.connect(self.sizespinbox8,SIGNAL("valueChanged(int)"),self.slotSizeActivated)

        self.colorcombo8 = KColorCombo(self.colorsizehbox8,"colorcombo8")
        self.connect(self.colorcombo8,SIGNAL("activated(const TQColor &)"),self.slotColorActivated)

        spacer = TQWidget(self.customcolorsvbox)
        self.customcolorsvbox.setStretchFactor(spacer,1)
        self.customcolorsvbox.setMinimumHeight(itemtext.height()*4.5)
        #self.customcolorsvbox.setStretchFactor(self.customcolorsgrid,1)

        bottomspacer = TQSpacerItem(51,160,TQSizePolicy.Minimum,TQSizePolicy.Expanding)
        appearance_tab_layout.addItem(bottomspacer)

        self.selecteditem = None
        self.config = TDEConfig("wineconfigrc",False,False)
        self.reset()

        self.clearWState(TQt.WState_Polished)

    def isChanged(self):
        changed = False
        changed = changed or self.currenttheme != self.originaltheme\
            or self.currentthemecolorscheme != self.originalthemecolorscheme\
            or self.currentfontsize != self.originalfontsize\
            or self.customizableItemsChanged()
        return changed

    def customizableItemsChanged(self):
        """ Returns true if any custom setting was changed """
        colors = wineread.GetColorSettings()
        metrics = wineread.GetWindowMetrics()

        changed = False
        custom = False  # For a little efficiency
        for item in list(self.customizableitems.keys()):
            for key in list(self.customizableitems[item][0].keys()):
                color = colors.get(key,"0 0 0")
                color = color.split()
                color = TQColor(int(color[0]),int(color[1]),int(color[2]))
                if not custom and self.customizableitems[item][0][key][1] !=\
                    self.config.readColorEntry(key,TQColor(0,0,0)):
                    self.__selectColorScheme(0)
                    custom = True
                if self.customizableitems[item][0][key][1] != color:
                    if custom:
                        return True
                    else:
                        changed = True
            for key in list(self.customizableitems[item][1].keys()):
                size = int(metrics.get(key,1))
                if not custom and self.customizableitems[item][1][key][1] !=\
                    self.config.readNumEntry(key,1):
                    self.__selectColorScheme(0)
                    custom = True
                if self.customizableitems[item][1][key][1] != size:
                    if custom:
                        return True
                    else:
                        changed = True
        return changed

    def reset(self):
        self.fillItemCombo(self.itemcombo)
        self.config.setGroup("")
        self.currentcustomcolorscheme = str(self.config.readEntry("ColorScheme",i18n("Custom")))
        self.originalcustomcolorscheme = self.currentcustomcolorscheme
        schemeslist = self.config.readListEntry("ColorSchemes")
        self.colorschemes = [str(i18n("Custom")),
            str(i18n("Get KDE Colors"))] + list(schemeslist)
        self.config.setGroup(self.currentcustomcolorscheme)

        for preset in self.presets:
            if preset[0] not in schemeslist:
                self.saveColorScheme(preset[0],preset[1])
                self.colorschemes.append(preset[0])

        self.fillColorSchemeCombo(self.colorschemecombo)

        theme = wineread.GetCurrentTheme()
        if not theme:
            self.currenttheme = self.themes[0]
            self.originaltheme = self.currenttheme
            self.__selectTheme(0)

            self.currentthemecolorscheme = "NormalColor"
            self.originalthemecolorscheme = self.currentthemecolorscheme

            self.currentfontsize = self.sizes[0][0]
            self.originalfontsize = self.currentfontsize
            for i,sizename in enumerate(self.sizes):
                if sizename[0] == self.currentfontsize:
                    self.__selectFontSize(i)
                    break
        else:
            self.currenttheme = theme[0]
            self.originaltheme = self.currenttheme
            for i,themename in enumerate(self.themes):
                if themename == self.currenttheme:
                    self.__selectTheme(i)
                    break
            self.currentthemecolorscheme = theme[1]
            self.originalthemecolorscheme = self.currentthemecolorscheme

            self.currentfontsize = theme[2]
            self.originalfontsize = self.currentfontsize
            for i,sizename in enumerate(self.sizes):
                if sizename[0] == self.currentfontsize:
                    self.__selectFontSize(i)
                    break

        colors = wineread.GetColorSettings()
        metrics = wineread.GetWindowMetrics()

        for item in list(self.customizableitems.keys()):
            for key in list(self.customizableitems[item][0].keys()):
                color = colors.get(key,"0 0 0")
                color = color.split()
                color = TQColor(int(color[0]),int(color[1]),int(color[2]))
                if color != self.config.readColorEntry(key,TQColor(0,0,0)):
                    self.currentcustomcolorscheme = self.colorschemes[0]
                self.customizableitems[item][0][key][1] = color
            for key in list(self.customizableitems[item][1].keys()):
                size = int(metrics.get(key,1))
                if size != self.config.readNumEntry(key,1):
                    self.currentcustomcolorscheme = self.colorschemes[0]
                self.customizableitems[item][1][key][1] = size

        for i,colorname in enumerate(self.colorschemes):
            if colorname == self.currentcustomcolorscheme:
                self.__selectColorScheme(i)
                break

        self.desktopsettings = wineread.GetDesktopSettings()

    def applyChanges(self):
        """ Applies the changes to wine's configuration """
        if self.currenttheme == self.themes[0]:
            winewrite.SetCurrentTheme(None)
        else:
            winewrite.SetCurrentTheme((self.currenttheme,
                self.currentthemecolorscheme,
                self.currentfontsize))

        colorsettings = {}
        metricssettings = {}
        for item in list(self.customizableitems.keys()):
            for key in list(self.customizableitems[item][0].keys()):
                color = self.customizableitems[item][0][key][1]
                color = str(color.red()) + " " + str(color.green()) +\
                    " " + str(color.blue())
                colorsettings[key] = color
            for key in list(self.customizableitems[item][1].keys()):
                size = self.customizableitems[item][1][key][1]

                metricssettings[key] = str(size)

        winewrite.SetColorSettings(colorsettings)
        winewrite.SetWindowMetrics(metricssettings)

        self.config.setGroup("")
        if self.currentcustomcolorscheme == self.colorschemes[1]:
            self.currentcustomcolorscheme = self.colorschemes[0]
        self.config.writeEntry("ColorScheme",self.currentcustomcolorscheme)
        self.config.sync()

        if self.customizableitems["Title Bar"][0]["ActiveTitle"][1]\
            !=\
            self.customizableitems["Title Bar"][0]["GradientActiveTitle"][1]\
            or\
            self.customizableitems["Title Bar"][0]["InactiveTitle"][1]\
            !=\
            self.customizableitems["Title Bar"][0]["GradientInactiveTitle"][1]:
            prefmask = self.desktopsettings["UserPreferencemask"]
            prefmask = prefmask[:4] + "1" + prefmask[5:]
            self.desktopsettings["UserPreferencemask"] = prefmask
        else:
            prefmask = self.desktopsettings["UserPreferencemask"]
            prefmask = prefmask[:4] + "0" + prefmask[5:]
            self.desktopsettings["UserPreferencemask"] = prefmask

        winewrite.SetDesktopSettings(self.desktopsettings)

        self.reset()

    def fillThemeCombo(self,combo):
        """ Fill the combo box with the list of themes """
        for theme in self.themes:
            combo.insertItem(theme)

    def fillColorSchemeCombo(self,combo):
        """ Fill the combo box with the list of color schemes """
        combo.clear()
        for color in self.colorschemes:
            combo.insertItem(color)

    def fillFontSizeCombo(self,combo):
        """ Fill the combo box with the list of font sizes """
        for size in self.sizes:
            combo.insertItem(size[1])

    def slotFillItemCombo(self,allowwm):
        """
        Fill the combo box with the list of customizable items
        Called when window managing is changed
        """
        combo = self.itemcombo
        combo.clear()
        items = list(self.customizableitems.keys())
        items.sort()
        for item in items:
            if not (allowwm and (item == "Window Border" \
                or item == "Title Bar" or \
                item == "Caption Buttons")):
                combo.insertItem(str(i18n(item)))

    def slotFillItemComboDesktop(self,desktop):
        """
        Fill the combo box with the list of customizable items
        Called when virtual desktop is changed
        """
        self.slotFillItemCombo(not desktop)

    def fillItemCombo(self,combo = None):
        """ Fill the combo box with the list of customizable items """
        if not combo:
            combo = self.itemcombo
        combo.clear()
        items = list(self.customizableitems.keys())
        items.sort()
        self.currentitems = []
        for item in items:
            if not (currentallowwm == 'Y' and (item == "Window Border" \
                or item == "Title Bar" or \
                item == "Caption Buttons")):
                combo.insertItem(str(i18n(item)))
                self.currentitems.append(item)

    def slotThemeActivated(self,themeid):
        """ Picks an already installed theme """
        self.__selectTheme(themeid)
        self.emit(PYSIGNAL("changedSignal()"), ())

    def slotInstallThemeClicked(self):
        """ Opens up a dialog to install a new theme """
        themepath = str(KFileDialog.getOpenFileName(os.environ['HOME'],\
            "*.msstyles|" + str(i18n("Windows Styles (*.msstyles)")),self,i18n("Install Style")))
        if themepath:
            themename = themepath.split('/')
            themename = themename[-1]
            themename = themename.split('.')
            themename = themename[0]
            themedir = wineread.winepath +\
                "/dosdevices/c:/windows/Resources/Themes/" +\
                themename
            if not os.path.exists(themedir):
                os.mkdir(themedir)
            shutil.copy(themepath, themedir)
            self.themes.append(str(i18n(themename)))
            self.themecombo.insertItem(self.themes[-1])
            self.emit(PYSIGNAL("changedSignal()"), ())

    def slotSaveSchemeClicked(self):
        """ Lets the user save the current color scheme """
        schemename = KInputDialog.getText(i18n("Save Color Scheme"),\
            i18n("Name: "),\
            i18n("CustomScheme"),\
            self,"schemenameinput")

        while schemename[1] and schemename[0] == "" or \
            schemename[0] == self.colorschemes[0] or \
            schemename[0] == self.colorschemes[1]:
            KMessageBox.information(self, \
                i18n("Please enter a unique name for the color scheme."), \
                i18n("Save Color Scheme"))
            schemename = KInputDialog.getText(i18n("Save Color Scheme"),\
                i18n("Name: "),\
                i18n("CustomScheme"),\
                self,"schemenameinput")

        if schemename[1]:
            schemename = str(schemename[0])
            self.saveColorScheme(schemename)
            if schemename not in self.colorschemes:
                self.colorschemes.append(schemename)
                self.colorschemecombo.insertItem(schemename)
            for i,colorname in enumerate(self.colorschemes):
                if colorname == schemename:
                    self.__selectColorScheme(i)
                    break

    def saveColorScheme(self,name,schemesettings = None):
        """ Saves the colorscheme """
        if not schemesettings:
            schemesettings = self.customizableitems
        self.config.setGroup("")
        if name != self.colorschemes[1]:
            self.config.writeEntry("ColorScheme",name)
        schemeslist = self.config.readListEntry("ColorSchemes")
        if name not in schemeslist and name != self.colorschemes[0] and \
            name != self.colorschemes[1]:
            schemeslist.append(name)
        self.config.writeEntry("ColorSchemes",schemeslist)
        self.config.setGroup(name)
        for item in list(self.customizableitems.keys()):
            for key in list(schemesettings[item][0].keys()):
                self.config.writeEntry(key,schemesettings[item][0][key][1])
            for key in list(schemesettings[item][1].keys()):
                self.config.writeEntry(key,schemesettings[item][1][key][1])
        self.config.sync()

    def GetKdeColorScheme(self):
        """ Sets the current color scheme settings to those currently set in KDE """
        # Create a configuration object.
        config = TDEConfig("kdesktoprc")

        config.setGroup("General")
        self.customizableitems["Application Workspace"][0]["AppWorkSpace"][1] =\
            config.readColorEntry("background",TQColor(100,100,100))
        self.customizableitems["Buttons"][0]["ButtonFace"][1] =\
            config.readColorEntry("background",TQColor(230,230,230))
        self.customizableitems["Buttons"][0]["ButtonHilight"][1] =\
            config.readColorEntry("windowBackground",TQColor(240,240,240))
        self.customizableitems["Buttons"][0]["ButtonLight"][1] =\
            config.readColorEntry("selectBackground",TQColor(200,200,200)).light(135)
        self.customizableitems["Buttons"][0]["ButtonShadow"][1] =\
            config.readColorEntry("background",TQColor(100,100,100)).dark(180)
        self.customizableitems["Buttons"][0]["ButtonText"][1] =\
            config.readColorEntry("buttonForeground",TQColor(0,0,0))
        self.customizableitems["Buttons"][0]["ButtonAlternateFace"][1] =\
            config.readColorEntry("background",TQColor(230,230,230))
        self.customizableitems["Buttons"][0]["ButtonDkShadow"][1] =\
            config.readColorEntry("selectBackground",TQColor(0,0,0)).dark(146)
        self.customizableitems["Buttons"][0]["WindowFrame"][1] =\
            config.readColorEntry("selectBackground",TQColor(0,0,0))
        self.customizableitems["Menu"][0]["Menu"][1] =\
            config.readColorEntry("background",TQColor(230,230,230)).light(105)
        self.customizableitems["Menu"][0]["MenuBar"][1] =\
            config.readColorEntry("background",TQColor(230,230,230))
        self.customizableitems["Menu"][0]["MenuHilight"][1] =\
            config.readColorEntry("selectBackground",TQColor(0,0,0))
        self.customizableitems["Menu"][0]["MenuText"][1] =\
            config.readColorEntry("foreground",TQColor(0,0,0))
        self.customizableitems["Scrollbar"][0]["Scrollbar"][1] =\
            config.readColorEntry("background",TQColor(230,230,230))
        self.customizableitems["Window"][0]["Window"][1] =\
            config.readColorEntry("windowBackground",TQColor(255,255,255))
        self.customizableitems["Window"][0]["WindowText"][1] =\
            config.readColorEntry("foreground",TQColor(0,0,0))
        self.customizableitems["Selected Items"][0]["Hilight"][1] =\
            config.readColorEntry("selectBackground",TQColor(0,0,0))
        self.customizableitems["Selected Items"][0]["HilightText"][1] =\
            config.readColorEntry("selectForeground",TQColor(255,255,255))

        config.setGroup("WM")
        self.customizableitems["Title Bar"][0]["ActiveTitle"][1] =\
            config.readColorEntry("activeBackground",TQColor(10,10,100))
        self.customizableitems["Title Bar"][0]["GradientActiveTitle"][1] =\
            config.readColorEntry("activeBlend",TQColor(10,10,200)).light(110)
        self.customizableitems["Title Bar"][0]["InactiveTitle"][1] =\
            config.readColorEntry("inactiveBackground",TQColor(100,100,100))
        self.customizableitems["Title Bar"][0]["GradientInactiveTitle"][1] =\
            config.readColorEntry("inactiveBlend",TQColor(100,100,200))
        self.customizableitems["Title Bar"][0]["TitleText"][1] =\
            config.readColorEntry("activeForeground",TQColor(255,255,255))
        self.customizableitems["Title Bar"][0]["InactiveTitleText"][1] =\
            config.readColorEntry("inactiveForeground",TQColor(250,250,250))
        self.customizableitems["Window Border"][0]["ActiveBorder"][1] =\
            config.readColorEntry("frame",TQColor(10,10,100))
        self.customizableitems["Window Border"][0]["InactiveBorder"][1] =\
            config.readColorEntry("frame",TQColor(100,100,200))

        config.setGroup("Desktop0")
        self.customizableitems["Desktop"][0]["Background"][1] =\
            config.readColorEntry("Color1",TQColor(50,150,85))

        self.saveColorScheme(self.colorschemes[1])

    def slotColorSchemeActivated(self,colorid):
        """ Picks a color scheme """
        self.__selectColorScheme(colorid)
        self.emit(PYSIGNAL("changedSignal()"), ())

    def slotFontSizeActivated(self,fontid):
        """ Picks a font size """
        self.__selectFontSize(fontid)
        self.emit(PYSIGNAL("changedSignal()"), ())

    def slotItemActivated(self,itemid):
        """ Picks an item to customize """
        items = list(self.customizableitems.keys())
        items.sort()
        for i,item in enumerate(self.currentitems):
            if i == itemid:
                if item != self.selecteditem:
                    self.__selectItem(item)

    def slotColorActivated(self,color):
        """ Picks a color for the currently selected item """
        key = self.sender().name()
        self.customizableitems[self.selecteditem][0][key][1] = color
        self.emit(PYSIGNAL("changedSignal()"), ())

    def slotSizeActivated(self,sizevalue):
        """ Sets the size value from the spin box """
        key = self.sender().name()
        self.customizableitems[self.selecteditem][1][key][1] = sizevalue
        self.emit(PYSIGNAL("changedSignal()"), ())

    def __selectTheme(self,themeid):
        """ Selects the browser in the combobox """
        self.currenttheme = self.themes[themeid]

        self.themecombo.setCurrentItem(themeid)

        #if themeid == 0:
        #    self.colorfontbox.setEnabled(False)
        #else:
        #    self.colorfontbox.setEnabled(True)

    def __selectColorScheme(self,colorid):
        """ Selects a color scheme in the combo box """
        self.currentcustomcolorscheme = self.colorschemes[colorid]

        self.colorschemecombo.setCurrentItem(colorid)

        if colorid > 1:
            self.config.setGroup("")
            self.config.writeEntry("ColorScheme",self.colorschemes[colorid])
            self.config.setGroup(self.colorschemes[colorid])
            for item in list(self.customizableitems.keys()):
                for key in list(self.customizableitems[item][0].keys()):
                    color = self.config.readColorEntry(key,TQColor(0,0,0))
                    self.customizableitems[item][0][key][1] = color
                for key in list(self.customizableitems[item][1].keys()):
                    size = self.config.readNumEntry(key,1)
                    self.customizableitems[item][1][key][1] = size
        elif colorid == 1:
            self.GetKdeColorScheme()

        if not self.selecteditem:
            self.__selectItem("Desktop")
        else:
            self.__selectItem(self.selecteditem)

    def __selectColorSchemeByName(self,name):
        """ Finds the index of name in colorschemes and calls the above function """
        for i,colorname in enumerate(self.colorschemes):
            if colorname == name:
                self.__selectColorScheme(i)
                break

    def __selectFontSize(self,sizeid):
        """ Selects a font size in the combo box """
        self.currentfontsize = self.sizes[sizeid][0]

        self.fontsizecombo.setCurrentItem(sizeid)

    def __selectItem(self,item):
        """ Sets the color and size settings boxes to those for item """
        self.selecteditem = item

        for i,item1 in enumerate(self.currentitems):
            if item1 == item:
                self.itemcombo.setCurrentItem(i)

        if item == "Application Workspace":
            key = "AppWorkSpace"
            self.colorsizehbox1.show()
            self.colorsizetext1.setText(\
                self.customizableitems[item][0][key][0])
            self.sizespinbox1.hide()
            self.colorsizehbox1_layout.remove(self.sizespinbox1)
            self.colorsizehbox1_layout.addWidget(self.colorcombo1,0,1)
            self.colorcombo1.show()
            self.colorcombo1.setColor(\
                self.customizableitems[item][0][key][1])
            self.colorcombo1.setName(key)

            self.colorsizehbox2.hide()
            self.colorsizehbox3.hide()
            self.colorsizehbox4.hide()
            self.colorsizehbox5.hide()
            self.colorsizehbox6.hide()
            self.colorsizehbox7.hide()
            self.colorsizehbox8.hide()
        elif item == "Buttons":
            key = "ButtonFace"
            self.colorsizehbox1.show()
            self.colorsizetext1.setText(\
                self.customizableitems[item][0][key][0])
            self.sizespinbox1.hide()
            self.colorsizehbox1_layout.remove(self.sizespinbox1)
            self.colorsizehbox1_layout.addWidget(self.colorcombo1,0,1)
            self.colorcombo1.show()
            self.colorcombo1.setColor(\
                self.customizableitems[item][0][key][1])
            self.colorcombo1.setName(key)

            key = "WindowFrame"
            self.colorsizehbox2.show()
            self.colorsizetext2.setText(\
                self.customizableitems[item][0][key][0])
            self.sizespinbox2.hide()
            self.colorsizehbox2_layout.remove(self.sizespinbox2)
            self.colorsizehbox2_layout.addWidget(self.colorcombo2,0,1)
            self.colorcombo2.show()
            self.colorcombo2.setColor(\
                self.customizableitems[item][0][key][1])
            self.colorcombo2.setName(key)

            key = "ButtonShadow"
            self.colorsizehbox3.show()
            self.colorsizetext3.setText(\
                self.customizableitems[item][0][key][0])
            self.sizespinbox3.hide()
            self.colorsizehbox3_layout.remove(self.sizespinbox3)
            self.colorsizehbox3_layout.addWidget(self.colorcombo3,0,1)
            self.colorcombo3.show()
            self.colorcombo3.setColor(\
                self.customizableitems[item][0][key][1])
            self.colorcombo3.setName(key)

            key = "ButtonDkShadow"
            self.colorsizehbox4.show()
            self.colorsizetext4.setText(\
                self.customizableitems[item][0][key][0])
            self.sizespinbox4.hide()
            self.colorsizehbox4_layout.remove(self.sizespinbox4)
            self.colorsizehbox4_layout.addWidget(self.colorcombo4,0,1)
            self.colorcombo4.show()
            self.colorcombo4.setColor(\
                self.customizableitems[item][0][key][1])
            self.colorcombo4.setName(key)

            key = "ButtonLight"
            self.colorsizehbox5.show()
            self.colorsizetext5.setText(\
                self.customizableitems[item][0][key][0])
            self.sizespinbox5.hide()
            self.colorsizehbox5_layout.remove(self.sizespinbox5)
            self.colorsizehbox5_layout.addWidget(self.colorcombo5,0,1)
            self.colorcombo5.show()
            self.colorcombo5.setColor(\
                self.customizableitems[item][0][key][1])
            self.colorcombo5.setName(key)

            key = "ButtonHilight"
            self.colorsizehbox6.show()
            self.colorsizetext6.setText(\
                self.customizableitems[item][0][key][0])
            self.sizespinbox6.hide()
            self.colorsizehbox6_layout.remove(self.sizespinbox6)
            self.colorsizehbox6_layout.addWidget(self.colorcombo6,0,1)
            self.colorcombo6.show()
            self.colorcombo6.setColor(\
                self.customizableitems[item][0][key][1])
            self.colorcombo6.setName(key)

            key = "ButtonAlternateFace"
            self.colorsizehbox7.show()
            self.colorsizetext7.setText(\
                self.customizableitems[item][0][key][0])
            self.sizespinbox7.hide()
            self.colorsizehbox7_layout.remove(self.sizespinbox7)
            self.colorsizehbox7_layout.addWidget(self.colorcombo7,0,1)
            self.colorcombo7.show()
            self.colorcombo7.setColor(\
                self.customizableitems[item][0][key][1])
            self.colorcombo7.setName(key)

            key = "ButtonText"
            self.colorsizehbox8.show()
            self.colorsizetext8.setText(\
                self.customizableitems[item][0][key][0])
            self.sizespinbox8.hide()
            self.colorsizehbox8_layout.remove(self.sizespinbox8)
            self.colorsizehbox8_layout.addWidget(self.colorcombo8,0,1)
            self.colorcombo8.show()
            self.colorcombo8.setColor(\
                self.customizableitems[item][0][key][1])
            self.colorcombo8.setName(key)
        elif item == "Caption Buttons":
            key = "CaptionHeight"
            self.colorsizehbox1.show()
            self.colorsizetext1.setText(\
                self.customizableitems[item][1][key][0])
            self.colorcombo1.hide()
            self.colorsizehbox1_layout.remove(self.colorcombo1)
            self.colorsizehbox1_layout.addWidget(self.sizespinbox1,0,1)
            self.sizespinbox1.show()
            self.sizespinbox1.setName(key)
            self.sizespinbox1.setValue(\
                self.customizableitems[item][1][key][1])
            self.sizespinbox1.setMinValue(8)
            self.sizespinbox1.setMaxValue(100)

            key = "CaptionWidth"
            self.colorsizehbox2.show()
            self.colorsizetext2.setText(\
                self.customizableitems[item][1][key][0])
            self.colorcombo2.hide()
            self.colorsizehbox2_layout.remove(self.colorcombo2)
            self.colorsizehbox2_layout.addWidget(self.sizespinbox2,0,1)
            self.sizespinbox2.show()
            self.sizespinbox2.setName(key)
            self.sizespinbox2.setValue(\
                self.customizableitems[item][1][key][1])
            self.sizespinbox2.setMinValue(8)
            self.sizespinbox2.setMaxValue(100)

            self.colorsizehbox3.hide()
            self.colorsizehbox4.hide()
            self.colorsizehbox5.hide()
            self.colorsizehbox6.hide()
            self.colorsizehbox7.hide()
            self.colorsizehbox8.hide()
        elif item == "Desktop":
            key = "Background"
            self.colorsizehbox1.show()
            self.colorsizetext1.setText(\
                self.customizableitems[item][0][key][0])
            self.sizespinbox1.hide()
            self.colorsizehbox1_layout.remove(self.sizespinbox1)
            self.colorsizehbox1_layout.addWidget(self.colorcombo1,0,1)
            self.colorcombo1.show()
            self.colorcombo1.setColor(\
                self.customizableitems[item][0][key][1])
            self.colorcombo1.setName(key)

            self.colorsizehbox2.hide()
            self.colorsizehbox3.hide()
            self.colorsizehbox4.hide()
            self.colorsizehbox5.hide()
            self.colorsizehbox6.hide()
            self.colorsizehbox7.hide()
            self.colorsizehbox8.hide()
        elif item == "Menu":
            key = "Menu"
            self.colorsizehbox1.show()
            self.colorsizetext1.setText(\
                self.customizableitems[item][0][key][0])
            self.sizespinbox1.hide()
            self.colorsizehbox1_layout.remove(self.sizespinbox1)
            self.colorsizehbox1_layout.addWidget(self.colorcombo1,0,1)
            self.colorcombo1.show()
            self.colorcombo1.setColor(\
                self.customizableitems[item][0][key][1])
            self.colorcombo1.setName(key)

            key = "MenuBar"
            self.colorsizehbox2.show()
            self.colorsizetext2.setText(\
                self.customizableitems[item][0][key][0])
            self.sizespinbox2.hide()
            self.colorsizehbox2_layout.remove(self.sizespinbox2)
            self.colorsizehbox2_layout.addWidget(self.colorcombo2,0,1)
            self.colorcombo2.show()
            self.colorcombo2.setColor(\
                self.customizableitems[item][0][key][1])
            self.colorcombo2.setName(key)

            key = "MenuHilight"
            self.colorsizehbox3.show()
            self.colorsizetext3.setText(\
                self.customizableitems[item][0][key][0])
            self.sizespinbox3.hide()
            self.colorsizehbox3_layout.remove(self.sizespinbox3)
            self.colorsizehbox3_layout.addWidget(self.colorcombo3,0,1)
            self.colorcombo3.show()
            self.colorcombo3.setColor(\
                self.customizableitems[item][0][key][1])
            self.colorcombo3.setName(key)

            key = "MenuText"
            self.colorsizehbox4.show()
            self.colorsizetext4.setText(\
                self.customizableitems[item][0][key][0])
            self.sizespinbox4.hide()
            self.colorsizehbox4_layout.remove(self.sizespinbox4)
            self.colorsizehbox4_layout.addWidget(self.colorcombo4,0,1)
            self.colorcombo4.show()
            self.colorcombo4.setColor(\
                self.customizableitems[item][0][key][1])
            self.colorcombo4.setName(key)

            key = "MenuHeight"
            self.colorsizehbox5.show()
            self.colorsizetext5.setText(\
                self.customizableitems[item][1][key][0])
            self.colorcombo5.hide()
            self.colorsizehbox5_layout.remove(self.colorcombo5)
            self.colorsizehbox5_layout.addWidget(self.sizespinbox5,0,1)
            self.sizespinbox5.show()
            self.sizespinbox5.setName(key)
            self.sizespinbox5.setValue(\
                self.customizableitems[item][1][key][1])
            self.sizespinbox5.setMinValue(15)
            self.sizespinbox5.setMaxValue(100)

            self.colorsizehbox6.hide()
            self.colorsizehbox7.hide()
            self.colorsizehbox8.hide()
        elif item == "Scrollbar":
            key = "Scrollbar"
            self.colorsizehbox1.show()
            self.colorsizetext1.setText(\
                self.customizableitems[item][0][key][0])
            self.sizespinbox1.hide()
            self.colorsizehbox1_layout.remove(self.sizespinbox1)
            self.colorsizehbox1_layout.addWidget(self.colorcombo1,0,1)
            self.colorcombo1.show()
            self.colorcombo1.setColor(\
                self.customizableitems[item][0][key][1])
            self.colorcombo1.setName(key)

            key = "ScrollWidth"
            self.colorsizehbox2.show()
            self.colorsizetext2.setText(\
                self.customizableitems[item][1][key][0])
            self.colorcombo2.hide()
            self.colorsizehbox2_layout.remove(self.colorcombo2)
            self.colorsizehbox2_layout.addWidget(self.sizespinbox2,0,1)
            self.sizespinbox2.show()
            self.sizespinbox2.setName(key)
            self.sizespinbox2.setValue(\
                self.customizableitems[item][1][key][1])
            self.sizespinbox2.setMinValue(8)
            self.sizespinbox2.setMaxValue(100)

            self.colorsizehbox3.hide()
            self.colorsizehbox4.hide()
            self.colorsizehbox5.hide()
            self.colorsizehbox6.hide()
            self.colorsizehbox7.hide()
            self.colorsizehbox8.hide()
        elif item == "Selected Items":
            key = "Hilight"
            self.colorsizehbox1.show()
            self.colorsizetext1.setText(\
                self.customizableitems[item][0][key][0])
            self.sizespinbox1.hide()
            self.colorsizehbox1_layout.remove(self.sizespinbox1)
            self.colorsizehbox1_layout.addWidget(self.colorcombo1,0,1)
            self.colorcombo1.show()
            self.colorcombo1.setColor(\
                self.customizableitems[item][0][key][1])
            self.colorcombo1.setName(key)

            key = "HilightText"
            self.colorsizehbox2.show()
            self.colorsizetext2.setText(\
                self.customizableitems[item][0][key][0])
            self.sizespinbox2.hide()
            self.colorsizehbox2_layout.remove(self.sizespinbox2)
            self.colorsizehbox2_layout.addWidget(self.colorcombo2,0,1)
            self.colorcombo2.show()
            self.colorcombo2.setColor(\
                self.customizableitems[item][0][key][1])
            self.colorcombo2.setName(key)

            self.colorsizehbox3.hide()
            self.colorsizehbox4.hide()
            self.colorsizehbox5.hide()
            self.colorsizehbox6.hide()
            self.colorsizehbox7.hide()
            self.colorsizehbox8.hide()
        elif item == "Title Bar":
            key = "ActiveTitle"
            self.colorsizehbox1.show()
            self.colorsizetext1.setText(\
                self.customizableitems[item][0][key][0])
            self.sizespinbox1.hide()
            self.colorsizehbox1_layout.remove(self.sizespinbox1)
            self.colorsizehbox1_layout.addWidget(self.colorcombo1,0,1)
            self.colorcombo1.show()
            self.colorcombo1.setColor(\
                self.customizableitems[item][0][key][1])
            self.colorcombo1.setName(key)

            key = "GradientActiveTitle"
            self.colorsizehbox2.show()
            self.colorsizetext2.setText(\
                self.customizableitems[item][0][key][0])
            self.sizespinbox2.hide()
            self.colorsizehbox2_layout.remove(self.sizespinbox2)
            self.colorsizehbox2_layout.addWidget(self.colorcombo2,0,1)
            self.colorcombo2.show()
            self.colorcombo2.setColor(\
                self.customizableitems[item][0][key][1])
            self.colorcombo2.setName(key)

            key = "InactiveTitle"
            self.colorsizehbox3.show()
            self.colorsizetext3.setText(\
                self.customizableitems[item][0][key][0])
            self.sizespinbox3.hide()
            self.colorsizehbox3_layout.remove(self.sizespinbox3)
            self.colorsizehbox3_layout.addWidget(self.colorcombo3,0,1)
            self.colorcombo3.show()
            self.colorcombo3.setColor(\
                self.customizableitems[item][0][key][1])
            self.colorcombo3.setName(key)

            key = "GradientInactiveTitle"
            self.colorsizehbox4.show()
            self.colorsizetext4.setText(\
                self.customizableitems[item][0][key][0])
            self.sizespinbox4.hide()
            self.colorsizehbox4_layout.remove(self.sizespinbox4)
            self.colorsizehbox4_layout.addWidget(self.colorcombo4,0,1)
            self.colorcombo4.show()
            self.colorcombo4.setColor(\
                self.customizableitems[item][0][key][1])
            self.colorcombo4.setName(key)

            key = "TitleText"
            self.colorsizehbox5.show()
            self.colorsizetext5.setText(\
                self.customizableitems[item][0][key][0])
            self.sizespinbox5.hide()
            self.colorsizehbox5_layout.remove(self.sizespinbox5)
            self.colorsizehbox5_layout.addWidget(self.colorcombo5,0,1)
            self.colorcombo5.show()
            self.colorcombo5.setColor(\
                self.customizableitems[item][0][key][1])
            self.colorcombo5.setName(key)

            key = "InactiveTitleText"
            self.colorsizehbox6.show()
            self.colorsizetext6.setText(\
                self.customizableitems[item][0][key][0])
            self.sizespinbox6.hide()
            self.colorsizehbox6_layout.remove(self.sizespinbox6)
            self.colorsizehbox6_layout.addWidget(self.colorcombo6,0,1)
            self.colorcombo6.show()
            self.colorcombo6.setColor(\
                self.customizableitems[item][0][key][1])
            self.colorcombo6.setName(key)

            self.colorsizehbox7.hide()
            self.colorsizehbox8.hide()
        elif item == "Window":
            key = "Window"
            self.colorsizehbox1.show()
            self.colorsizetext1.setText(\
                self.customizableitems[item][0][key][0])
            self.sizespinbox1.hide()
            self.colorsizehbox1_layout.remove(self.sizespinbox1)
            self.colorsizehbox1_layout.addWidget(self.colorcombo1,0,1)
            self.colorcombo1.show()
            self.colorcombo1.setColor(\
                self.customizableitems[item][0][key][1])
            self.colorcombo1.setName(key)

            key = "WindowText"
            self.colorsizehbox2.show()
            self.colorsizetext2.setText(\
                self.customizableitems[item][0][key][0])
            self.sizespinbox2.hide()
            self.colorsizehbox2_layout.remove(self.sizespinbox2)
            self.colorsizehbox2_layout.addWidget(self.colorcombo2,0,1)
            self.colorcombo2.show()
            self.colorcombo2.setColor(\
                self.customizableitems[item][0][key][1])
            self.colorcombo2.setName(key)

            self.colorsizehbox3.hide()
            self.colorsizehbox4.hide()
            self.colorsizehbox5.hide()
            self.colorsizehbox6.hide()
            self.colorsizehbox7.hide()
            self.colorsizehbox8.hide()
        elif item == "Window Border":
            key = "ActiveBorder"
            self.colorsizehbox1.show()
            self.colorsizetext1.setText(\
                self.customizableitems[item][0][key][0])
            self.sizespinbox1.hide()
            self.colorsizehbox1_layout.remove(self.sizespinbox1)
            self.colorsizehbox1_layout.addWidget(self.colorcombo1,0,1)
            self.colorcombo1.show()
            self.colorcombo1.setColor(\
                self.customizableitems[item][0][key][1])
            self.colorcombo1.setName(key)

            key = "InactiveBorder"
            self.colorsizehbox2.show()
            self.colorsizetext2.setText(\
                self.customizableitems[item][0][key][0])
            self.sizespinbox2.hide()
            self.colorsizehbox2_layout.remove(self.sizespinbox2)
            self.colorsizehbox2_layout.addWidget(self.colorcombo2,0,1)
            self.colorcombo2.show()
            self.colorcombo2.setColor(\
                self.customizableitems[item][0][key][1])
            self.colorcombo2.setName(key)

            key = "BorderWidth"
            self.colorsizehbox3.show()
            self.colorsizetext3.setText(\
                self.customizableitems[item][1][key][0])
            self.colorcombo3.hide()
            self.colorsizehbox3_layout.remove(self.colorcombo3)
            self.colorsizehbox3_layout.addWidget(self.sizespinbox3,0,1)
            self.sizespinbox3.show()
            self.sizespinbox3.setName(key)
            self.sizespinbox3.setValue(\
                self.customizableitems[item][1][key][1])
            self.sizespinbox3.setMinValue(1)
            self.sizespinbox3.setMaxValue(50)

            self.colorsizehbox4.hide()
            self.colorsizehbox5.hide()
            self.colorsizehbox6.hide()
            self.colorsizehbox7.hide()
            self.colorsizehbox8.hide()
        else:
            # Shouldn't happen.
            self.colorsizehbox1.hide()
            self.colorsizehbox2.hide()
            self.colorsizehbox3.hide()
            self.colorsizehbox4.hide()
            self.colorsizehbox5.hide()
            self.colorsizehbox6.hide()
            self.colorsizehbox7.hide()
            self.colorsizehbox8.hide()

    def setMargin(self,margin):
        self.top_layout.setMargin(margin)

    def setSpacing(self,spacing):
        self.top_layout.setSpacing(spacing)

    # --- Some default color schemes, with names ---
    preset1 = (str(i18n("Purple")),
       {"Window Border":
            ({"ActiveBorder":[str(i18n("Active Color:")),TQColor(239,239,239)],
              "InactiveBorder":[str(i18n("Inactive Color:")),TQColor(239,239,239)]},
             {"BorderWidth":[str(i18n("Width:")),1]}), #ActiveBorder, InactiveBorder, metrics: BorderWidth
        "Title Bar":
            ({"ActiveTitle":[str(i18n("Active Color:")),TQColor(91,86,168)],
              "GradientActiveTitle":[str(i18n("Gradient:")),TQColor(136,118,202)],
              "InactiveTitle":[str(i18n("Inactive Color:")),TQColor(223,225,230)],
              "GradientInactiveTitle":[str(i18n("Gradient:")),TQColor(157,170,186)],
              "TitleText":[str(i18n("Active Text:")),TQColor(255,255,255)],
              "InactiveTitleText":[str(i18n("Inactive Text:")),TQColor(168,168,168)]},
             {}), #ActiveTitle, GradientActiveTitle, InactiveTitle, GradientInactiveTitle, TitleText, InactiveTitleText
        "Application Workspace":
            ({"AppWorkSpace":[str(i18n("Background Color:")),TQColor(90,90,90)]},
             {}), #AppWorkSpace "Background"
        "Buttons":
            ({"ButtonFace":[str(i18n("Face:")),TQColor(238,239,242)],
              "ButtonHilight":[str(i18n("Hilight:")),TQColor(255,255,255)],
              "ButtonLight":[str(i18n("Light:")),TQColor(201,199,255)],
              "ButtonShadow":[str(i18n("Shadow:")),TQColor(132,132,134)],
              "ButtonText":[str(i18n("Text Color:")),TQColor(0,0,0)],
              "ButtonAlternateFace":[str(i18n("Alternate Face:")),TQColor(238,239,242)],
              "ButtonDkShadow":[str(i18n("Dark Shadow:")),TQColor(98,96,143)],
              "WindowFrame":[str(i18n("Frame:")),TQColor(144,140,209)]},
             {}), #ButtonFace, ButtonHilight, ButtonLight, ButtonShadow, ButtonText, ButtonAlternateFace, ButtonDkShadow, WindowFrame
        "Caption Buttons":
            ({},
             {"CaptionHeight":[str(i18n("Height:")),22],
              "CaptionWidth":[str(i18n("Width:")),22]}), #Metrics: CaptionHeight, CaptionWidth
        "Desktop":
            ({"Background":[str(i18n("Background:")),TQColor(146,127,188)]},
             {}), #Background
        "Menu":
            ({"Menu":[str(i18n("Menu Background:")),TQColor(250,251,254)],
              "MenuBar":[str(i18n("Menu Bar Color:")),TQColor(238,239,242)],
              "MenuHilight":[str(i18n("Menu Hilight:")),TQColor(144,140,209)],
              "MenuText":[str(i18n("Text Color:")),TQColor(0,0,0)]},
             {"MenuHeight":[str(i18n("Menu Bar Height:")),22]}), #Menu (Background), MenuBar, MenuHilight, MenuText, metrics: MenuHeight, MenuWidth (does nothing)
        "Scrollbar":
            ({"Scrollbar":[str(i18n("Color:")),TQColor(238,239,242)]},
             {"ScrollWidth":[str(i18n("Width:")),16]}), #Scrollbar, metrics: ScrollHeight (does nothing), ScrollWidth
        "Window":
            ({"Window":[str(i18n("Background:")),TQColor(255,255,255)],
              "WindowText":[str(i18n("Text Color:")),TQColor(0,0,0)]},
             {}), #Window "Background", WindowText
        "Selected Items":
            ({"Hilight":[str(i18n("Hilight Color:")),TQColor(144,140,209)],
              "HilightText":[str(i18n("Text Color:")),TQColor(255,255,255)]},
             {})}) #Hilight, HilightText

    preset2 = (str(i18n("Blue")),
       {"Window Border":
            ({"ActiveBorder":[str(i18n("Active Color:")),TQColor(239,239,239)],
              "InactiveBorder":[str(i18n("Inactive Color:")),TQColor(239,239,239)]},
             {"BorderWidth":[str(i18n("Width:")),1]}), #ActiveBorder, InactiveBorder, metrics: BorderWidth
        "Title Bar":
            ({"ActiveTitle":[str(i18n("Active Color:")),TQColor(0,113,201)],
              "GradientActiveTitle":[str(i18n("Gradient:")),TQColor(87,161,219)],
              "InactiveTitle":[str(i18n("Inactive Color:")),TQColor(191,191,191)],
              "GradientInactiveTitle":[str(i18n("Gradient:")),TQColor(171,171,171)],
              "TitleText":[str(i18n("Active Text:")),TQColor(255,255,255)],
              "InactiveTitleText":[str(i18n("Inactive Text:")),TQColor(95,95,95)]},
             {}), #ActiveTitle, GradientActiveTitle, InactiveTitle, GradientInactiveTitle, TitleText, InactiveTitleText
        "Application Workspace":
            ({"AppWorkSpace":[str(i18n("Background Color:")),TQColor(90,90,90)]},
             {}), #AppWorkSpace "Background"
        "Buttons":
            ({"ButtonFace":[str(i18n("Face:")),TQColor(239,239,239)],
              "ButtonHilight":[str(i18n("Hilight:")),TQColor(246,246,246)],
              "ButtonLight":[str(i18n("Light:")),TQColor(191,207,251)],
              "ButtonShadow":[str(i18n("Shadow:")),TQColor(148,148,153)],
              "ButtonText":[str(i18n("Text Color:")),TQColor(0,0,0)],
              "ButtonAlternateFace":[str(i18n("Alternate Face:")),TQColor(238,239,242)],
              "ButtonDkShadow":[str(i18n("Dark Shadow:")),TQColor(50,101,146)],
              "WindowFrame":[str(i18n("Frame:")),TQColor(74,149,214)]},
             {}), #ButtonFace, ButtonHilight, ButtonLight, ButtonShadow, ButtonText, ButtonAlternateFace, ButtonDkShadow, WindowFrame
        "Caption Buttons":
            ({},
             {"CaptionHeight":[str(i18n("Height:")),22],
              "CaptionWidth":[str(i18n("Width:")),22]}), #Metrics: CaptionHeight, CaptionWidth
        "Desktop":
            ({"Background":[str(i18n("Background:")),TQColor(44,109,189)]},
             {}), #Background
        "Menu":
            ({"Menu":[str(i18n("Menu Background:")),TQColor(249,249,249)],
              "MenuBar":[str(i18n("Menu Bar Color:")),TQColor(239,239,239)],
              "MenuHilight":[str(i18n("Menu Hilight:")),TQColor(74,149,214)],
              "MenuText":[str(i18n("Text Color:")),TQColor(0,0,0)]},
             {"MenuHeight":[str(i18n("Menu Bar Height:")),22]}), #Menu (Background), MenuBar, MenuHilight, MenuText, metrics: MenuHeight, MenuWidth (does nothing)
        "Scrollbar":
            ({"Scrollbar":[str(i18n("Color:")),TQColor(230,230,230)]},
             {"ScrollWidth":[str(i18n("Width:")),16]}), #Scrollbar, metrics: ScrollHeight (does nothing), ScrollWidth
        "Window":
            ({"Window":[str(i18n("Background:")),TQColor(255,255,255)],
              "WindowText":[str(i18n("Text Color:")),TQColor(0,0,0)]},
             {}), #Window "Background", WindowText
        "Selected Items":
            ({"Hilight":[str(i18n("Hilight Color:")),TQColor(74,149,214)],
              "HilightText":[str(i18n("Text Color:")),TQColor(255,255,255)]},
             {})}) #Hilight, HilightText
    presets = [preset1,preset2]

############################################################################
class GeneralPage(TQWidget):

    winversions = wineread.winversions

    verdic = {
        "win2003":0,
        "winxp":1,
        "win2k":2,
        "winme":3,
        "win98":4,
        "win95":5,
        "nt40":6,
        "nt351":7,
        "win31":8,
        "win30":9,
        "win20":10}

    def __init__(self,parent = None,name = None,modal = 0,fl = 0):
        global application
        TQWidget.__init__(self,parent)

        if not name:
            self.setName("GeneralTab")

        general_tab_layout = TQVBoxLayout(self,0,0,"GeneralTabLayout")
        self.top_layout = general_tab_layout

        vbox = TQVBox(self)
        vbox.setSpacing(KDialog.spacingHint())

        general_tab_layout.addWidget(vbox)

        if application:
            appwarning = TQLabel(vbox,"appwarning")
            appwarning.setText(i18n("Application specific settings for <b>" +\
                application + "</b><p>Changing a setting here will permanently " +\
                "make that setting independent of settings for all other " +\
                "applications.</p>"))
            appwarning.setFrameStyle( TQFrame.Box | TQFrame.Raised )
            self.winversions = self.winversions + (( "global",\
                str(i18n("Use Global Setting")),   0,  0, 0, "", "", 0, 0, ""),)
            self.verdic["global"]=11

        hbox = TQHBox(vbox)
        hbox.setSpacing(KDialog.spacingHint())

        versiontext = TQLabel(hbox,"versiontext")
        versiontext.setText(i18n("Windows version:"))

        self.versioncombo = KComboBox(0,hbox,"versioncombo")
        self.fillVersionCombo(self.versioncombo)
        self.connect(self.versioncombo,SIGNAL("activated(int)"),self.slotVersionActivated)

        spacer = TQWidget(hbox)
        hbox.setStretchFactor(spacer,1)

        bottomspacer = TQSpacerItem(51,160,TQSizePolicy.Minimum,TQSizePolicy.Expanding)
        general_tab_layout.addItem(bottomspacer)

        self.reset()

        self.clearWState(TQt.WState_Polished)

    def isChanged(self):
        changed = False
        changed = changed or self.currentwinverid != self.originalwinverid
        return changed

    def reset(self):
        settings = wineread.GetGeneralWineSettings(application)

        if application:
            self.currentwinverid = self.verdic[settings.get("Version","global")]
        else:
            self.currentwinverid = self.verdic[settings.get("Version","winxp")]
        self.originalwinverid = self.currentwinverid
        self.__selectWinVer(self.currentwinverid)

    def applyChanges(self):
        """ Applies the changes to wine's configuration """
        winewrite.SetWinVersion(self.winversions[self.currentwinverid], application)

        self.reset()

    def fillVersionCombo(self,combo):
        """ Fill the combobox with the values from our list """
        for version in self.winversions:
            combo.insertItem(version[1])

    def slotVersionActivated(self,verid):
        self.currentwinverid = verid
        self.emit(PYSIGNAL("changedSignal()"), ())

    def __selectWinVer(self,verid):
        """
        Sets the current Windows version and selects it in the combo box
        """
        self.versioncombo.setCurrentItem(verid)

    def setMargin(self,margin):
        self.top_layout.setMargin(margin)

    def setSpacing(self,spacing):
        self.top_layout.setSpacing(spacing)


############################################################################
class ApplicationsPage(TQWidget):

    applications = []

    browsers = []
    mailers = []

    def __init__(self,parent = None,name = None,modal = 0,fl = 0):
        TQWidget.__init__(self,parent)

        if not name:
            self.setName("ApplicationsTab")

        applications_tab_layout = TQVBoxLayout(self,0,0,"ApplicationsTabLayout")
        self.top_layout = applications_tab_layout

        vbox = TQVBox(self)
        vbox.setSpacing(KDialog.spacingHint())

        applications_tab_layout.addWidget(vbox)

        # -- Application Specific Settings group --
        self.perapp_group_box = TQHGroupBox(vbox)
        self.perapp_group_box.setTitle(i18n("Application specific settings"))
        self.perapp_group_box.setInsideSpacing(KDialog.spacingHint())
        self.perapp_group_box.setInsideMargin(KDialog.marginHint())

        vbox2 = TQVBox(self.perapp_group_box)
        vbox2.setSpacing(KDialog.spacingHint())

        applicationstext = TQLabel(vbox2,"applicationstext")
        applicationstext.setText(i18n("Change application specific settings for:"))

        self.appslist = TDEListBox(vbox2)
        self.connect(self.appslist, SIGNAL("selectionChanged(TQListBoxItem *)"), self.slotListClicked)

        hbox = TQHBox(vbox2)
        hbox.setSpacing(KDialog.spacingHint())

        self.addbutton = KPushButton(i18n("Add Application..."),hbox)
        self.connect(self.addbutton,SIGNAL("clicked()"),self.slotAddClicked)

        self.removebutton = KPushButton(i18n("Remove..."),hbox)
        self.connect(self.removebutton,SIGNAL("clicked()"),self.slotRemoveClicked)

        spacer = TQWidget(hbox)
        hbox.setStretchFactor(spacer,1)

        self.settingsbutton = KPushButton(i18n("Settings"),hbox)
        self.connect(self.settingsbutton,SIGNAL("clicked()"),self.slotSettingsClicked)

        # -- Native Applications Settings group --
        # Removed pending a patch to winebrowser
        #self.nativeapp_group_box = TQVGroupBox(vbox)
        #self.nativeapp_group_box.setTitle(i18n("Native applications"))
        #self.nativeapp_group_box.setInsideSpacing(KDialog.spacingHint())
        #self.nativeapp_group_box.setInsideMargin(KDialog.marginHint())

        #vbox3 = TQWidget(self.nativeapp_group_box)

        #native_apps_layout = TQGridLayout(vbox3,2,3)
        #native_apps_layout.setSpacing(KDialog.spacingHint())

        #browsertext = TQLabel(vbox3,"browsertext")
        #browsertext.setText(i18n("Web Browser:"))
        #native_apps_layout.addWidget(browsertext,0,0)

        #self.browsercombo = KComboBox(0,vbox3,"browsercombo")
        #self.browsercombo.setEditable(False)
        #self.connect(self.browsercombo,SIGNAL("activated(int)"),self.slotBrowserActivated)
        #native_apps_layout.addWidget(self.browsercombo,0,1)
        #native_apps_layout.setColStretch(1,1)

        #QToolTip.add(self.browsercombo,
            #i18n("<p>Select the browser to be launched when clicking on a link" +\
            #" in a Windows application.</p>"))

        #self.browserbutton = KPushButton(i18n("..."),vbox3)
        #self.connect(self.browserbutton,SIGNAL("clicked()"),self.slotBrowserClicked)
        #native_apps_layout.addWidget(self.browserbutton,0,2)

        #mailertext = TQLabel(vbox3,"mailertext")
        #mailertext.setText(i18n("Mail Client:"))
        #native_apps_layout.addWidget(mailertext,1,0)

        #self.mailercombo = KComboBox(0,vbox3,"mailercombo")
        #self.connect(self.mailercombo,SIGNAL("activated(int)"),self.slotMailerActivated)
        #native_apps_layout.addWidget(self.mailercombo,1,1)

        #QToolTip.add(self.mailercombo,
            #i18n("<p>Select the mail client to be launched when clicking on" +\
            #" a mailto link in a Windows application.</p>"))

        #self.mailerbutton = KPushButton(i18n("..."),vbox3)
        #self.connect(self.mailerbutton,SIGNAL("clicked()"),self.slotMailerClicked)
        #native_apps_layout.addWidget(self.mailerbutton,1,2)

        bottomspacer = TQSpacerItem(51,160,TQSizePolicy.Minimum,TQSizePolicy.Expanding)
        applications_tab_layout.addItem(bottomspacer)

        self.changed = False

        # Removed pending a patch to winebrowser
        #browsers = wineread.GetNativeBrowserList()
        #if "kfmclient exec" not in browsers:
            #browsers.append("kfmclient exec")
        #self.currentbrowser = wineread.GetBrowser()
        #self.browsers = self.createBrowserList(browsers,[self.currentbrowser])
        #self.fillCombo(self.browsercombo,self.browsers)

        #mailers = wineread.GetNativeMailerList()
        #if "kfmclient exec" not in mailers:
            #mailers.append("kfmclient exec")
        #self.currentmailer = wineread.GetMailer()
        #self.mailers = self.createMailerList(mailers,[self.currentmailer])
        #self.fillCombo(self.mailercombo,self.mailers)

        self.reset()

        self.clearWState(TQt.WState_Polished)

    def isChanged(self):
        changed = False
        changed = changed or self.applications != self.originalapplications
        #changed = changed or self.currentbrowser != self.originalbrowser
        #changed = changed or self.currentmailer != self.originalmailer
        return changed

    def reset(self):
        self.applications = wineread.GetApps()
        self.originalapplications = self.applications[:]
        self.updateAppsList()

        # Removed pending a patch to winebrowser
        #self.currentbrowser = wineread.GetBrowser()
        #self.__selectBrowser(self.currentbrowser)
        #self.originalbrowser = self.currentbrowser

        #self.currentmailer = wineread.GetMailer()
        #self.__selectMailer(self.currentmailer)
        #self.originalmailer = self.currentmailer

    def applyChanges(self):
        """ Applies the changes to wine's configuration """
        if self.applications != self.originalapplications:
            winewrite.SetApps(self.applications)
        # Removed pending a patch to winebrowser
        #if self.currentbrowser != self.originalbrowser:
            #winewrite.SetDefaultBrowser(self.currentbrowser)
        #if self.currentmailer != self.originalmailer:
            #winewrite.SetDefaultMailer(self.currentmailer)
        self.reset()

    def createBrowserList(self,native,wine):
        """
        Takes a list of native browsers and a list wine browsers
        and creates a list of the commands with descriptions
        """

        browsers = []

        for browser in native:
            browserwords = browser.split()
            if browserwords and browserwords[0] == "kfmclient":
                browserkfmcmd = browser.split(' ')
                if len(browserkfmcmd) > 2 and \
                    browserkfmcmd[1] == 'openProfile':
                    browsertr = "Konqueror " + browserkfmcmd[2] +\
                        str(i18n(" profile (Native)"))
                elif len(browserkfmcmd) > 1 and \
                    browserkfmcmd[1] == 'exec':
                    browsertr = str(i18n("Use KDE Default"))
                else:
                    browsertr = str(i18n("Konqueror (Native)"))
            else:
                browsertr = browser.capitalize() + str(i18n(" (Native)"))
            browsers.append((browser,browsertr))
        for browser in wine:
            if browser and browser[1] == ':':
                browser = browser.lower()
                browsertr = browser[browser.rfind('\\\\')+2:browser.rfind('.exe')]
                browsertr = browsertr.capitalize() + str(i18n(" (Windows, set by application)"))
            else:   # winebrowser
                continue
            browsers.append((browser,browsertr))

        return browsers

    def createMailerList(self,native,wine):
        """
        Takes a list of native mailers and a list wine mailers
        and creates a list of the commands with descriptions
        """

        mailers = []

        for mailer in native:
            mailerwords = mailer.split()
            if mailerwords and mailerwords[0] == "kfmclient":
                mailerkfmcmd = mailer.split(' ')
                if len(mailerkfmcmd) > 1 and \
                    mailerkfmcmd[1] == 'exec':
                    mailertr = str(i18n("Use KDE Default"))
                else:
                    mailertr = str(i18n("KDE (Native)"))
            else:
                mailertr = mailer.capitalize() + str(i18n(" (Native)"))
            mailers.append((mailer,mailertr))
        for mailer in wine:
            if mailer and mailer[1] == ':':
                mailer = mailer.lower()
                mailertr = mailer[mailer.rfind('\\\\')+2:mailer.rfind('.exe')]
                mailertr = mailertr.capitalize() + str(i18n(" (Windows, set by application)"))
            else:   # winebrowser
                continue
            mailers.append((mailer,mailertr))

        return mailers

    def slotListClicked(self,item):
        """ Called when an application in the list is clicked """
        for appid,appname in enumerate(self.applications):
            if appname==item.text():
                self.__selectApp(appid)
                return

    def slotAddClicked(self):
        """
        Let the user choose a new application to change settings for
        """
        app = KFileDialog.getOpenFileName(wineread.winepath + \
            "/dosdevices/c:",\
            "*.exe|" + str(i18n("Windows Executables (*.exe)")),self,i18n("Application"))
        if app:
            app = str(app).split('/')
            app = app[-1]
            self.applications.append(app)
            self.updateAppsList()
            for appid,appname in enumerate(self.applications):
                if appname==app:
                    self.__selectApp(appid)
            self.emit(PYSIGNAL("changedSignal()"), ())

    def slotRemoveClicked(self):
        """ Removes settings for selected application """
        if KMessageBox.warningContinueCancel(self, \
                i18n("This will remove all application specific settings for \n" +\
                    self.applications[self.selectedappid] +"\n" +\
                    "Do you want to proceed?"),\
                i18n("Warning")) == KMessageBox.Continue:
            del self.applications[self.selectedappid]
            self.updateAppsList()
            self.emit(PYSIGNAL("changedSignal()"), ())

    def slotSettingsClicked(self):
        """ 
        Launches a new wineconfig window for the selected application
        """
        os.system("wineconfig " + self.applications[self.selectedappid])

    def slotBrowserEdited(self,browser):
        """ Sets the first browser to use to the one selected in the combo box """
        self.currentbrowser = str(browser).strip()
        self.emit(PYSIGNAL("changedSignal()"), ())

    def slotBrowserActivated(self,browserid):
        """ Sets the first browser to use to the one selected in the combo box """
        self.currentbrowser = self.browsers[browserid][0]
        self.emit(PYSIGNAL("changedSignal()"), ())

    def slotBrowserClicked(self):
        """ Sets the first browser to use to the one selected in the combo box """
        browserdlg = KOpenWithDlg(self)
        browserdlg.hideNoCloseOnExit()
        browserdlg.hideRunInTerminal()
        if browserdlg.exec_loop():#i18n("Choose a Web Browser"),self.currentbrowser)
            self.__selectBrowser(str(browserdlg.text()))
        self.emit(PYSIGNAL("changedSignal()"), ())

    def slotMailerEdited(self,mailer):
        """ Sets the first mailer to use to the one selected in the combo box """
        self.currentmailer = str(mailer).strip()
        self.emit(PYSIGNAL("changedSignal()"), ())

    def slotMailerActivated(self,mailerid):
        """ Sets the first browser to use to the one selected in the combo box """
        self.currentmailer = self.mailers[mailerid][0]
        self.emit(PYSIGNAL("changedSignal()"), ())

    def slotMailerClicked(self):
        """ Sets the first mailer to use to the one selected in the combo box """
        mailerdlg = KOpenWithDlg(self)
        mailerdlg.hideNoCloseOnExit()
        mailerdlg.hideRunInTerminal()
        if mailerdlg.exec_loop():#i18n("Choose a Web Browser"),self.currentbrowser)
            self.__selectMailer(str(mailerdlg.text()))
        self.emit(PYSIGNAL("changedSignal()"), ())

    def fillCombo(self,combo,_list):
        """ Fill the combobox with the values from our list
        Uses the second value from each tuple """
        for item in _list:
            combo.insertItem(item[1])

    def updateAppsList(self):
        """ Updates the displayed list of applications """
        self.appslist.clear()

        self.applications.sort()

        self.appslist.insertStringList(TQStringList.fromStrList(self.applications))

        self.__selectApp(None)

    def __selectBrowser(self,browsercommand):
        """ Selects the browser in the combobox """
        self.currentbrowser = browsercommand

        for i,browser in enumerate(self.browsers):
            if browser[0].lower() == browsercommand.lower():
                self.browsercombo.setCurrentItem(i)
                break
        else:
            browserwords = browsercommand.split()
            #if len(browserwords) > 1 and browserwords[0] != "kfmclient":
            #    browsercommand = browserwords[0]
            self.browsers = self.browsers +\
                self.createBrowserList([browsercommand],[])
            self.browsercombo.insertItem(self.browsers[-1][1])
            self.__selectBrowser(browsercommand)

    def __selectMailer(self,mailercommand):
        """ Selects the mailer in the combobox """
        self.currentmailer = mailercommand

        for i,mailer in enumerate(self.mailers):
            if mailer[0] == mailercommand:
                self.mailercombo.setCurrentItem(i)
                break
        else:
            mailerwords = mailercommand.split()
            #if len(mailerwords) > 1 and mailerwords[0] != "kfmclient":
            #    mailercommand = mailerwords[0]
            self.mailers = self.mailers +\
                self.createBrowserList([mailercommand],[])
            self.mailercombo.insertItem(self.mailers[-1][1])
            self.__selectMailer(mailercommand)

    def __selectApp(self,appid):
        """ Selects the application """
        if appid or appid == 0:
            self.selectedappid = appid
            self.appslist.setCurrentItem(appid)
            self.removebutton.setEnabled(True)
            self.settingsbutton.setEnabled(True)
        else:
            self.selectedappid = None
            self.removebutton.setEnabled(False)
            self.settingsbutton.setEnabled(False)

    def GetKdeDefaultBrowser(self):
        """ Returns the default browser set in KDE """
        # Create a configuration object.
        config = TDEConfig("wineconfigrc")
        return str(config.lookupData(KEntryKey("General","BrowserApplication")).mValue).strip('!')

    def setMargin(self,margin):
        self.top_layout.setMargin(margin)

    def setSpacing(self,spacing):
        self.top_layout.setSpacing(spacing)


############################################################################
class LibrariesPage(TQWidget):

    dlls = [""]
    overriddendlls = {}

    orderoptions = ("builtin","native","builtin,native","native,builtin","")
    orderoptionstr = [
        str(i18n("Built-in (Wine)")),
        str(i18n("Native (Windows)")),
        str(i18n("Built-in then Native")),
        str(i18n("Native then Built-in")),
        str(i18n("Disable"))]

    def __init__(self,parent = None,name = None,modal = 0,fl = 0):
        TQWidget.__init__(self,parent)

        if not name:
            self.setName("LibrariesTab")

        libraries_tab_layout = TQVBoxLayout(self,0,0,"LibrariesTabLayout")
        self.top_layout = libraries_tab_layout

        vbox = TQVBox(self)
        vbox.setSpacing(KDialog.spacingHint())

        libraries_tab_layout.addWidget(vbox)

        # -- DLL overrides group
        self.overrides_group_box = TQHGroupBox(vbox)
        self.overrides_group_box.setTitle(i18n("DLL Overrides"))
        self.overrides_group_box.setInsideSpacing(KDialog.spacingHint())
        self.overrides_group_box.setInsideMargin(KDialog.marginHint())

        vbox2 = TQVBox(self.overrides_group_box)
        vbox2.setSpacing(KDialog.spacingHint())

        spacer = TQWidget(vbox2)
        vbox2.setStretchFactor(spacer,1)

        newtext = TQLabel(vbox2,"newtext")
        newtext.setText(i18n("New override for library:"))

        hbox = TQHBox(vbox2)
        hbox.setSpacing(KDialog.spacingHint())

        self.dllcombo = KComboBox(0,hbox,"dllcombo")
        self.dllcombo.setEditable(True)
        hbox.setStretchFactor(self.dllcombo,3)
        self.connect(self.dllcombo,SIGNAL("activated(int)"),self.slotDllComboActivated)

        TQToolTip.add(self.dllcombo,
            i18n("<p>Dynamic Link Libraries can be specified individually to" +\
            " be either builtin (provided by Wine) or native (taken from" +\
            " Windows or provided by the application).</p>"))
        self.addbutton = KPushButton(i18n("Add"),hbox)
        hbox.setStretchFactor(self.addbutton,1)
        self.connect(self.addbutton,SIGNAL("clicked()"),self.slotAddClicked)

        existingtext = TQLabel(vbox2,"existingtext")
        existingtext.setText(i18n("Existing overrides:"))

        hbox = TQHBox(vbox2)
        hbox.setSpacing(KDialog.spacingHint())

        self.dllslist = TDEListView(hbox)
        self.dllslist.addColumn(i18n("Library"))
        self.dllslist.addColumn(i18n("Load Order"))
        self.dllslist.setAllColumnsShowFocus(True)
        self.dllslist.setSelectionMode(TQListView.Single)
        self.dllslist.setSorting(-1,True)
        hbox.setStretchFactor(self.dllslist,3)

        self.connect(self.dllslist, SIGNAL("selectionChanged(TQListViewItem *)"), self.slotListClicked)

        vbox3 = TQVBox(hbox)
        vbox3.setSpacing(KDialog.spacingHint())
        hbox.setStretchFactor(vbox3,1)

        self.editbutton = KPushButton(i18n("Edit"),vbox3)
        self.connect(self.editbutton,SIGNAL("clicked()"),self.slotEditClicked)
        self.editbutton.setEnabled(False)

        self.removebutton = KPushButton(i18n("Remove"),vbox3)
        self.connect(self.removebutton,SIGNAL("clicked()"),self.slotRemoveClicked)
        self.removebutton.setEnabled(False)

        spacer = TQWidget(vbox3)
        vbox3.setStretchFactor(spacer,1)

        bottomspacer = TQSpacerItem(51,160,TQSizePolicy.Minimum,TQSizePolicy.Expanding)
        libraries_tab_layout.addItem(bottomspacer)

        self.changed = False

        self.reset()

        self.clearWState(TQt.WState_Polished)

    def isChanged(self):
        changed = False
        changed = changed or self.overriddendlls != self.originaloverriddendlls
        return changed

    def reset(self):
        self.dlls = wineread.GetDllsList()
        self.fillCombo(self.dllcombo)

        self.overriddendlls = wineread.GetDllOverrides(application)
        self.originaloverriddendlls = self.overriddendlls.copy()
        self.selecteddll = None
        self.updateDllOverridesList()

    def applyChanges(self):
        """ Applies the changes to wine's configuration """
        winewrite.SetDllOverrides(self.overriddendlls,application)
        self.reset()

    def slotListClicked(self,item):
        """ Called when an application in the list is clicked """
        self.__selectOverriddenDll(item.text(0))

    def slotAddClicked(self):
        """
        Adds the selected library to the overrides list
        """
        dll = self.dllcombo.currentText()
        if dll:
            self.overriddendlls[str(dll)]="native,builtin"
            self.updateDllOverridesList()
            self.__selectOverriddenDll(dll)
            self.emit(PYSIGNAL("changedSignal()"), ())

    def slotRemoveClicked(self):
        """ Removes override for selected library """
        del self.overriddendlls[str(self.selecteddll)]
        self.updateDllOverridesList()
        self.__selectOverriddenDll(None)
        self.emit(PYSIGNAL("changedSignal()"), ())

    def slotEditClicked(self):
        """ 
        Gives a choice for the load order for the library
        """
        if self.selecteddll:
            order = KInputDialog.getItem(i18n("Edit Library Override"),\
                str(i18n("Load order for %s:")) % (str(self.selecteddll),),
                TQStringList.fromStrList(self.orderoptionstr),\
                False,0,self,"editdll")

            if order[1]:
                self.overriddendlls[str(self.selecteddll)] = \
                    self.orderoptions[self.orderoptionstr.index(str(order[0]))]
                self.updateDllOverridesList()
                self.emit(PYSIGNAL("changedSignal()"), ())

    def slotDllComboActivated(self,dllid):
        return

    def fillCombo(self,combo):
        """ Fill the combobox with the values from our list """
        for dll in self.dlls:
            combo.insertItem(dll)

    def updateDllOverridesList(self):
        """ Updates the displayed list of drives """
        self.dllslist.clear()
        self.dllsToListItems = {}
        firstselecteddll = None
        lastdll = None

        for dll,order in self.overriddendlls.items():
            lvi = TQListViewItem(self.dllslist,dll,order)
            self.dllsToListItems[dll] = lvi
            if self.selecteddll and self.selecteddll==dll:
                firstselecteddll = dll
            lastdll = dll

        self.dllslist.setSortColumn(0)
        self.selecteddll = firstselecteddll
        self.__selectOverriddenDll(self.selecteddll)
        self.dllslist.ensureItemVisible(self.dllslist.currentItem())

    def __selectOverriddenDll(self,dll):
        """ Select a dll from the overridden list """
        self.selecteddll = dll
        if dll:
            self.dllslist.setSelected(self.dllsToListItems[str(dll)],True)
            self.editbutton.setEnabled(True)
            self.removebutton.setEnabled(True)
        else:
            self.editbutton.setEnabled(False)
            self.removebutton.setEnabled(False)

    def setMargin(self,margin):
        self.top_layout.setMargin(margin)

    def setSpacing(self,spacing):
        self.top_layout.setSpacing(spacing)


############################################################################
def create_wineconfig(parent,name):
    """ Factory function for KControl """
    global kapp
    kapp = TDEApplication.kApplication()
    return WineConfigApp(parent, name)

############################################################################
def MakeAboutData():
    aboutdata = TDEAboutData("guidance",programname,version, \
        "Wine Configuration Tool", TDEAboutData.License_GPL, \
        "Copyright (C) 2006-2007 Yuriy Kozlov", \
        "Thanks go to  Simon Edwards, Sebastian Kügler")
    aboutdata.addAuthor("Yuriy Kozlov","Developer","yuriy.kozlov@gmail.com", \
            "http://www.yktech.us/")
    aboutdata.addAuthor("Simon Edwards","Developer","simon@simonzone.com", \
            "http://www.simonzone.com/software/")
    aboutdata.addAuthor("Sebastian Kügler","Developer","sebas@kde.org", \
            "http://vizZzion.org")
    return aboutdata

if standalone:
    aboutdata = MakeAboutData()
    TDECmdLineArgs.init(sys.argv,aboutdata)

    # Can't do i18n?
    options = [("+[appname]", str(i18n("Application to change settings for")))]
    TDECmdLineArgs.addCmdLineOptions( options )

    kapp = TDEApplication()

    wineconfigapp = WineConfigApp()
    wineconfigapp.exec_loop(None)