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
|
# -*- coding:utf-8 -*-
## src/config.py
##
## Copyright (C) 2003-2005 Vincent Hanquez <tab AT snarc.org>
## Copyright (C) 2003-2008 Yann Leboulanger <asterix AT lagaule.org>
## Copyright (C) 2005 Alex Podaras <bigpod AT gmail.com>
## Stéphan Kochen <stephan AT kochen.nl>
## Copyright (C) 2005-2006 Dimitur Kirov <dkirov AT gmail.com>
## Nikos Kouremenos <kourem AT gmail.com>
## Copyright (C) 2006 Junglecow J <junglecow AT gmail.com>
## Copyright (C) 2006-2007 Travis Shirk <travis AT pobox.com>
## Stefan Bethge <stefan AT lanpartei.de>
## Copyright (C) 2006-2008 Jean-Marie Traissard <jim AT lapin.org>
## Copyright (C) 2007 James Newton <redshodan AT gmail.com>
## Julien Pivotto <roidelapluie AT gmail.com>
## Copyright (C) 2007-2008 Stephan Erb <steve-e AT h3c.de>
## Copyright (C) 2008 Jonathan Schleifer <js-gajim AT webkeks.org>
##
## This file is part of Gajim.
##
## Gajim 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; version 3 only.
##
## Gajim is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
## GNU General Public License for more details.
##
## You should have received a copy of the GNU General Public License
## along with Gajim. If not, see <http://www.gnu.org/licenses/>.
##
import gtk
import gobject
import os, sys
import common.config
import common.sleepy
from common.i18n import Q_
import gtkgui_helpers
import dialogs
import cell_renderer_image
import message_control
import chat_control
import dataforms_widget
try:
import gtkspell
HAS_GTK_SPELL = True
except Exception:
HAS_GTK_SPELL = False
from common import helpers
from common import gajim
from common import connection
from common import passwords
from common import zeroconf
from common import dataforms
from common.exceptions import GajimGeneralException
#---------- PreferencesWindow class -------------#
class PreferencesWindow:
'''Class for Preferences window'''
def on_preferences_window_destroy(self, widget):
'''close window'''
del gajim.interface.instances['preferences']
def on_close_button_clicked(self, widget):
self.window.destroy()
def __init__(self):
'''Initialize Preferences window'''
self.xml = gtkgui_helpers.get_glade('preferences_window.glade')
self.window = self.xml.get_widget('preferences_window')
self.window.set_transient_for(gajim.interface.roster.window)
self.notebook = self.xml.get_widget('preferences_notebook')
self.one_window_type_combobox =\
self.xml.get_widget('one_window_type_combobox')
self.iconset_combobox = self.xml.get_widget('iconset_combobox')
self.notify_on_signin_checkbutton = self.xml.get_widget(
'notify_on_signin_checkbutton')
self.notify_on_signout_checkbutton = self.xml.get_widget(
'notify_on_signout_checkbutton')
self.auto_popup_away_checkbutton = self.xml.get_widget(
'auto_popup_away_checkbutton')
self.auto_away_checkbutton = self.xml.get_widget('auto_away_checkbutton')
self.auto_away_time_spinbutton = self.xml.get_widget(
'auto_away_time_spinbutton')
self.auto_away_message_entry = self.xml.get_widget(
'auto_away_message_entry')
self.auto_xa_checkbutton = self.xml.get_widget('auto_xa_checkbutton')
self.auto_xa_time_spinbutton = self.xml.get_widget(
'auto_xa_time_spinbutton')
self.auto_xa_message_entry = self.xml.get_widget('auto_xa_message_entry')
### General tab ###
# Display avatars in roster
st = gajim.config.get('show_avatars_in_roster')
self.xml.get_widget('show_avatars_in_roster_checkbutton'). \
set_active(st)
# Display status msg under contact name in roster
st = gajim.config.get('show_status_msgs_in_roster')
self.xml.get_widget('show_status_msgs_in_roster_checkbutton'). \
set_active( st)
# Display mood in roster
st = gajim.config.get('show_mood_in_roster')
self.xml.get_widget('show_mood_in_roster_checkbutton'). \
set_active(st)
# Display activity in roster
st = gajim.config.get('show_activity_in_roster')
self.xml.get_widget('show_activity_in_roster_checkbutton'). \
set_active(st)
# Display tunes in roster
st = gajim.config.get('show_tunes_in_roster')
self.xml.get_widget('show_tunes_in_roster_checkbutton'). \
set_active(st)
# Sort contacts by show
st = gajim.config.get('sort_by_show_in_roster')
self.xml.get_widget('sort_by_show_in_roster_checkbutton').set_active(st)
st = gajim.config.get('sort_by_show_in_muc')
self.xml.get_widget('sort_by_show_in_muc_checkbutton').set_active(st)
# emoticons
emoticons_combobox = self.xml.get_widget('emoticons_combobox')
emoticons_list = os.listdir(os.path.join(gajim.DATA_DIR, 'emoticons'))
# user themes
if os.path.isdir(gajim.MY_EMOTS_PATH):
emoticons_list += os.listdir(gajim.MY_EMOTS_PATH)
renderer_text = gtk.CellRendererText()
emoticons_combobox.pack_start(renderer_text, True)
emoticons_combobox.add_attribute(renderer_text, 'text', 0)
model = gtk.ListStore(str)
emoticons_combobox.set_model(model)
l = []
for dir in emoticons_list:
if not os.path.isdir(os.path.join(gajim.DATA_DIR, 'emoticons', dir)) \
and not os.path.isdir(os.path.join(gajim.MY_EMOTS_PATH, dir)) :
continue
if dir != '.svn':
l.append(dir)
l.append(_('Disabled'))
for i in xrange(len(l)):
model.append([l[i]])
if gajim.config.get('emoticons_theme') == l[i]:
emoticons_combobox.set_active(i)
if not gajim.config.get('emoticons_theme'):
emoticons_combobox.set_active(len(l)-1)
# Set default for single window type
choices = common.config.opt_one_window_types
type = gajim.config.get('one_message_window')
if type in choices:
self.one_window_type_combobox.set_active(choices.index(type))
else:
self.one_window_type_combobox.set_active(0)
# Compact View
st = gajim.config.get('compact_view')
self.xml.get_widget('compact_view_checkbutton').set_active(st)
# Ignore XHTML
st = gajim.config.get('ignore_incoming_xhtml')
self.xml.get_widget('xhtml_checkbutton').set_active(st)
# use speller
if HAS_GTK_SPELL:
st = gajim.config.get('use_speller')
self.xml.get_widget('speller_checkbutton').set_active(st)
else:
self.xml.get_widget('speller_checkbutton').set_sensitive(False)
### Style tab ###
# Themes
theme_combobox = self.xml.get_widget('theme_combobox')
cell = gtk.CellRendererText()
theme_combobox.pack_start(cell, True)
theme_combobox.add_attribute(cell, 'text', 0)
self.update_theme_list()
# iconset
iconsets_list = os.listdir(os.path.join(gajim.DATA_DIR, 'iconsets'))
if os.path.isdir(gajim.MY_ICONSETS_PATH):
iconsets_list += os.listdir(gajim.MY_ICONSETS_PATH)
# new model, image in 0, string in 1
model = gtk.ListStore(gtk.Image, str)
renderer_image = cell_renderer_image.CellRendererImage(0, 0)
renderer_text = gtk.CellRendererText()
renderer_text.set_property('xpad', 5)
self.iconset_combobox.pack_start(renderer_image, expand = False)
self.iconset_combobox.pack_start(renderer_text, expand = True)
self.iconset_combobox.set_attributes(renderer_text, text = 1)
self.iconset_combobox.add_attribute(renderer_image, 'image', 0)
self.iconset_combobox.set_model(model)
l = []
for dir in iconsets_list:
if not os.path.isdir(os.path.join(gajim.DATA_DIR, 'iconsets', dir)) \
and not os.path.isdir(os.path.join(gajim.MY_ICONSETS_PATH, dir)):
continue
if dir != '.svn' and dir != 'transports':
l.append(dir)
if l.count == 0:
l.append(' ')
for i in xrange(len(l)):
preview = gtk.Image()
files = []
files.append(os.path.join(helpers.get_iconset_path(l[i]), '16x16',
'online.png'))
files.append(os.path.join(helpers.get_iconset_path(l[i]), '16x16',
'online.gif'))
for file in files:
if os.path.exists(file):
preview.set_from_file(file)
model.append([preview, l[i]])
if gajim.config.get('iconset') == l[i]:
self.iconset_combobox.set_active(i)
# Use transports iconsets
st = gajim.config.get('use_transports_iconsets')
self.xml.get_widget('transports_iconsets_checkbutton').set_active(st)
# Color for incoming messages
colSt = gajim.config.get('inmsgcolor')
self.xml.get_widget('incoming_msg_colorbutton').set_color(
gtk.gdk.color_parse(colSt))
# Color for outgoing messages
colSt = gajim.config.get('outmsgcolor')
self.xml.get_widget('outgoing_msg_colorbutton').set_color(
gtk.gdk.color_parse(colSt))
# Color for status messages
colSt = gajim.config.get('statusmsgcolor')
self.xml.get_widget('status_msg_colorbutton').set_color(
gtk.gdk.color_parse(colSt))
# Color for hyperlinks
colSt = gajim.config.get('urlmsgcolor')
self.xml.get_widget('url_msg_colorbutton').set_color(
gtk.gdk.color_parse(colSt))
# Font for messages
font = gajim.config.get('conversation_font')
# try to set default font for the current desktop env
fontbutton = self.xml.get_widget('conversation_fontbutton')
if font == '':
fontbutton.set_sensitive(False)
self.xml.get_widget('default_chat_font').set_active(True)
else:
fontbutton.set_font_name(font)
### Personal Events tab ###
# outgoing send chat state notifications
st = gajim.config.get('outgoing_chat_state_notifications')
combo = self.xml.get_widget('outgoing_chat_states_combobox')
if st == 'all':
combo.set_active(0)
elif st == 'composing_only':
combo.set_active(1)
else: # disabled
combo.set_active(2)
# displayed send chat state notifications
st = gajim.config.get('displayed_chat_state_notifications')
combo = self.xml.get_widget('displayed_chat_states_combobox')
if st == 'all':
combo.set_active(0)
elif st == 'composing_only':
combo.set_active(1)
else: # disabled
combo.set_active(2)
### Notifications tab ###
# On new event
on_event_combobox = self.xml.get_widget('on_event_combobox')
if gajim.config.get('autopopup'):
on_event_combobox.set_active(0)
elif gajim.config.get('notify_on_new_message'):
on_event_combobox.set_active(1)
else:
on_event_combobox.set_active(2)
# notify on online statuses
st = gajim.config.get('notify_on_signin')
self.notify_on_signin_checkbutton.set_active(st)
# notify on offline statuses
st = gajim.config.get('notify_on_signout')
self.notify_on_signout_checkbutton.set_active(st)
# autopopupaway
st = gajim.config.get('autopopupaway')
self.auto_popup_away_checkbutton.set_active(st)
# sounds
if gajim.config.get('sounds_on'):
self.xml.get_widget('play_sounds_checkbutton').set_active(True)
else:
self.xml.get_widget('sounds_scrolledwindow').set_sensitive(False)
self.xml.get_widget('browse_sounds_hbox').set_sensitive(False)
# sound player
player = gajim.config.get('soundplayer')
# sounds treeview
self.sound_tree = self.xml.get_widget('sounds_treeview')
# active, event ui name, path to sound file, event_config_name
model = gtk.ListStore(bool, str, str, str)
self.sound_tree.set_model(model)
col = gtk.TreeViewColumn(_('Active'))
self.sound_tree.append_column(col)
renderer = gtk.CellRendererToggle()
renderer.set_property('activatable', True)
renderer.connect('toggled', self.sound_toggled_cb)
col.pack_start(renderer)
col.set_attributes(renderer, active = 0)
col = gtk.TreeViewColumn(_('Event'))
self.sound_tree.append_column(col)
renderer = gtk.CellRendererText()
col.pack_start(renderer)
col.set_attributes(renderer, text = 1)
self.fill_sound_treeview()
# Notify user of new gmail e-mail messages,
# make checkbox sensitive if user has a gtalk account
frame_gmail = self.xml.get_widget('frame_gmail')
notify_gmail_checkbutton = self.xml.get_widget('notify_gmail_checkbutton')
notify_gmail_extra_checkbutton = self.xml.get_widget(
'notify_gmail_extra_checkbutton')
for account in gajim.config.get_per('accounts'):
jid = gajim.get_jid_from_account(account)
if gajim.get_server_from_jid(jid) in gajim.gmail_domains:
frame_gmail.set_sensitive(True)
st = gajim.config.get('notify_on_new_gmail_email')
notify_gmail_checkbutton.set_active(st)
st = gajim.config.get('notify_on_new_gmail_email_extra')
notify_gmail_extra_checkbutton.set_active(st)
break
#### Status tab ###
# Autoaway
st = gajim.config.get('autoaway')
self.auto_away_checkbutton.set_active(st)
# Autoawaytime
st = gajim.config.get('autoawaytime')
self.auto_away_time_spinbutton.set_value(st)
self.auto_away_time_spinbutton.set_sensitive(gajim.config.get('autoaway'))
# autoaway message
st = gajim.config.get('autoaway_message')
self.auto_away_message_entry.set_text(st)
self.auto_away_message_entry.set_sensitive(gajim.config.get('autoaway'))
# Autoxa
st = gajim.config.get('autoxa')
self.auto_xa_checkbutton.set_active(st)
# Autoxatime
st = gajim.config.get('autoxatime')
self.auto_xa_time_spinbutton.set_value(st)
self.auto_xa_time_spinbutton.set_sensitive(gajim.config.get('autoxa'))
# autoxa message
st = gajim.config.get('autoxa_message')
self.auto_xa_message_entry.set_text(st)
self.auto_xa_message_entry.set_sensitive(gajim.config.get('autoxa'))
from common import sleepy
if not sleepy.SUPPORTED:
self.xml.get_widget('autoaway_table').set_sensitive(False)
# ask_status when online / offline
st = gajim.config.get('ask_online_status')
self.xml.get_widget('prompt_online_status_message_checkbutton').\
set_active(st)
st = gajim.config.get('ask_offline_status')
self.xml.get_widget('prompt_offline_status_message_checkbutton').\
set_active(st)
# Default Status messages
self.default_msg_tree = self.xml.get_widget('default_msg_treeview')
# (status, translated_status, message, enabled)
model = gtk.ListStore(str, str, str, bool)
self.default_msg_tree.set_model(model)
col = gtk.TreeViewColumn(_('Status'))
self.default_msg_tree.append_column(col)
renderer = gtk.CellRendererText()
col.pack_start(renderer, False)
col.set_attributes(renderer, text = 1)
col = gtk.TreeViewColumn(_('Default Message'))
self.default_msg_tree.append_column(col)
renderer = gtk.CellRendererText()
col.pack_start(renderer, True)
col.set_attributes(renderer, text = 2)
renderer.connect('edited', self.on_default_msg_cell_edited)
renderer.set_property('editable', True)
col = gtk.TreeViewColumn(_('Enabled'))
self.default_msg_tree.append_column(col)
renderer = gtk.CellRendererToggle()
col.pack_start(renderer, False)
col.set_attributes(renderer, active = 3)
renderer.set_property('activatable', True)
renderer.connect('toggled', self.default_msg_toggled_cb)
self.fill_default_msg_treeview()
# Status messages
self.msg_tree = self.xml.get_widget('msg_treeview')
model = gtk.ListStore(str, str)
self.msg_tree.set_model(model)
col = gtk.TreeViewColumn('name')
self.msg_tree.append_column(col)
renderer = gtk.CellRendererText()
col.pack_start(renderer, True)
col.set_attributes(renderer, text = 0)
renderer.connect('edited', self.on_msg_cell_edited)
renderer.set_property('editable', True)
self.fill_msg_treeview()
buf = self.xml.get_widget('msg_textview').get_buffer()
buf.connect('changed', self.on_msg_textview_changed)
### Advanced tab ###
# open links with
if os.name == 'nt':
applications_frame = self.xml.get_widget('applications_frame')
applications_frame.set_no_show_all(True)
applications_frame.hide()
else:
self.applications_combobox = self.xml.get_widget(
'applications_combobox')
self.xml.get_widget('custom_apps_frame').hide()
self.xml.get_widget('custom_apps_frame').set_no_show_all(True)
if sys.platform == 'darwin':
self.applications_combobox.remove_text(4)
self.applications_combobox.remove_text(3)
self.applications_combobox.remove_text(2)
self.applications_combobox.remove_text(1)
self.applications_combobox.append_text(
_('Always use OS/X default applications'))
self.applications_combobox.append_text(_('Custom'))
if gajim.config.get('autodetect_browser_mailer'):
self.applications_combobox.set_active(0)
# else autodetect_browser_mailer is False.
# so user has 'Always Use GNOME/KDE/Xfce' or Custom
elif gajim.config.get('openwith') == 'gnome-open':
self.applications_combobox.set_active(1)
elif gajim.config.get('openwith') == 'kfmclient exec':
self.applications_combobox.set_active(2)
elif gajim.config.get('openwith') == 'exo-open':
self.applications_combobox.set_active(3)
elif ((sys.platform == 'darwin') and\
(gajim.config.get('openwith') == 'open')):
self.applications_combobox.set_active(1)
elif gajim.config.get('openwith') == 'custom':
if sys.platform == 'darwin':
self.applications_combobox.set_active(2)
else:
self.applications_combobox.set_active(4)
self.xml.get_widget('custom_apps_frame').show()
self.xml.get_widget('custom_browser_entry').set_text(
gajim.config.get('custombrowser'))
self.xml.get_widget('custom_mail_client_entry').set_text(
gajim.config.get('custommailapp'))
self.xml.get_widget('custom_file_manager_entry').set_text(
gajim.config.get('custom_file_manager'))
# log status changes of contacts
st = gajim.config.get('log_contact_status_changes')
self.xml.get_widget('log_show_changes_checkbutton').set_active(st)
# log encrypted chat sessions
st = gajim.config.get('log_encrypted_sessions')
self.xml.get_widget('log_encrypted_chats_checkbutton').set_active(st)
# send os info
st = gajim.config.get('send_os_info')
self.xml.get_widget('send_os_info_checkbutton').set_active(st)
# check if gajm is default
st = gajim.config.get('check_if_gajim_is_default')
self.xml.get_widget('check_default_client_checkbutton').set_active(st)
# Ignore messages from unknown contacts
self.xml.get_widget('ignore_events_from_unknown_contacts_checkbutton').\
set_active(gajim.config.get('ignore_unknown_contacts'))
self.xml.signal_autoconnect(self)
self.sound_tree.get_model().connect('row-changed',
self.on_sounds_treemodel_row_changed)
self.msg_tree.get_model().connect('row-changed',
self.on_msg_treemodel_row_changed)
self.msg_tree.get_model().connect('row-deleted',
self.on_msg_treemodel_row_deleted)
self.default_msg_tree.get_model().connect('row-changed',
self.on_default_msg_treemodel_row_changed)
self.theme_preferences = None
self.notebook.set_current_page(0)
self.window.show_all()
gtkgui_helpers.possibly_move_window_in_current_desktop(self.window)
def on_preferences_window_key_press_event(self, widget, event):
if event.keyval == gtk.keysyms.Escape:
self.window.hide()
def on_checkbutton_toggled(self, widget, config_name,
change_sensitivity_widgets = None):
gajim.config.set(config_name, widget.get_active())
if change_sensitivity_widgets:
for w in change_sensitivity_widgets:
w.set_sensitive(widget.get_active())
gajim.interface.save_config()
def on_sort_by_show_in_roster_checkbutton_toggled(self, widget):
self.on_checkbutton_toggled(widget, 'sort_by_show_in_roster')
gajim.interface.roster.setup_and_draw_roster()
def on_sort_by_show_in_muc_checkbutton_toggled(self, widget):
self.on_checkbutton_toggled(widget, 'sort_by_show_in_muc')
# Redraw connected groupchats
for account in gajim.connections:
if gajim.connections[account].connected:
for gc_control in gajim.interface.msg_win_mgr.get_controls(
message_control.TYPE_GC) + \
gajim.interface.minimized_controls[account].values():
gc_control.draw_roster()
def on_show_avatars_in_roster_checkbutton_toggled(self, widget):
self.on_checkbutton_toggled(widget, 'show_avatars_in_roster')
gajim.interface.roster.setup_and_draw_roster()
# Redraw connected groupchats (in an ugly way)
for account in gajim.connections:
if gajim.connections[account].connected:
for gc_control in gajim.interface.msg_win_mgr.get_controls(
message_control.TYPE_GC) + \
gajim.interface.minimized_controls[account].values():
gc_control.draw_roster()
def on_show_status_msgs_in_roster_checkbutton_toggled(self, widget):
self.on_checkbutton_toggled(widget, 'show_status_msgs_in_roster')
gajim.interface.roster.setup_and_draw_roster()
for ctl in gajim.interface.msg_win_mgr.controls():
if ctl.type_id == message_control.TYPE_GC:
ctl.update_ui()
def on_show_mood_in_roster_checkbutton_toggled(self, widget):
self.on_checkbutton_toggled(widget, 'show_mood_in_roster')
gajim.interface.roster.setup_and_draw_roster()
def on_show_activity_in_roster_checkbutton_toggled(self, widget):
self.on_checkbutton_toggled(widget, 'show_activity_in_roster')
gajim.interface.roster.setup_and_draw_roster()
def on_show_tunes_in_roster_checkbutton_toggled(self, widget):
self.on_checkbutton_toggled(widget, 'show_tunes_in_roster')
gajim.interface.roster.setup_and_draw_roster()
def on_emoticons_combobox_changed(self, widget):
active = widget.get_active()
model = widget.get_model()
emot_theme = model[active][0].decode('utf-8')
if emot_theme == _('Disabled'):
gajim.config.set('emoticons_theme', '')
else:
gajim.config.set('emoticons_theme', emot_theme)
gajim.interface.init_emoticons(need_reload = True)
gajim.interface.make_regexps()
self.toggle_emoticons()
def toggle_emoticons(self):
'''Update emoticons state in Opened Chat Windows'''
for win in gajim.interface.msg_win_mgr.windows():
win.toggle_emoticons()
def on_one_window_type_combo_changed(self, widget):
active = widget.get_active()
config_type = common.config.opt_one_window_types[active]
gajim.config.set('one_message_window', config_type)
gajim.interface.save_config()
gajim.interface.msg_win_mgr.reconfig()
def on_compact_view_checkbutton_toggled(self, widget):
active = widget.get_active()
for ctl in gajim.interface.msg_win_mgr.controls():
ctl.chat_buttons_set_visible(active)
gajim.config.set('compact_view', active)
gajim.interface.save_config()
gajim.interface.roster.setup_and_draw_roster()
def on_xhtml_checkbutton_toggled(self, widget):
self.on_checkbutton_toggled(widget, 'ignore_incoming_xhtml')
helpers.update_optional_features()
def apply_speller(self):
for acct in gajim.connections:
for ctrl in gajim.interface.msg_win_mgr.controls():
if isinstance(ctrl, chat_control.ChatControlBase):
try:
spell_obj = gtkspell.get_from_text_view(ctrl.msg_textview)
except Exception:
spell_obj = None
if not spell_obj:
gtkspell.Spell(ctrl.msg_textview)
def remove_speller(self):
for acct in gajim.connections:
for ctrl in gajim.interface.msg_win_mgr.controls():
if isinstance(ctrl, chat_control.ChatControlBase):
try:
spell_obj = gtkspell.get_from_text_view(ctrl.msg_textview)
except Exception:
spell_obj = None
if spell_obj:
spell_obj.detach()
def on_speller_checkbutton_toggled(self, widget):
active = widget.get_active()
gajim.config.set('use_speller', active)
gajim.interface.save_config()
if active:
lang = gajim.config.get('speller_language')
if not lang:
lang = gajim.LANG
tv = gtk.TextView()
try:
spell = gtkspell.Spell(tv, lang)
except:
dialogs.ErrorDialog(
_('Dictionary for lang %s not available') % lang,
_('You have to install %s dictionary to use spellchecking, or '
'choose another language by setting the speller_language option.'
) % lang)
gajim.config.set('use_speller', False)
widget.set_active(False)
else:
gajim.config.set('speller_language', lang)
self.apply_speller()
else:
self.remove_speller()
def on_theme_combobox_changed(self, widget):
model = widget.get_model()
active = widget.get_active()
config_theme = model[active][0].decode('utf-8').replace(' ', '_')
gajim.config.set('roster_theme', config_theme)
# begin repainting themed widgets throughout
gajim.interface.roster.repaint_themed_widgets()
gajim.interface.roster.change_roster_style(None)
gajim.interface.save_config()
def update_theme_list(self):
theme_combobox = self.xml.get_widget('theme_combobox')
model = gtk.ListStore(str)
theme_combobox.set_model(model)
i = 0
for config_theme in gajim.config.get_per('themes'):
theme = config_theme.replace('_', ' ')
model.append([theme])
if gajim.config.get('roster_theme') == config_theme:
theme_combobox.set_active(i)
i += 1
def on_manage_theme_button_clicked(self, widget):
if self.theme_preferences is None:
self.theme_preferences = dialogs.GajimThemesWindow()
else:
self.theme_preferences.window.present()
self.theme_preferences.select_active_theme()
def on_iconset_combobox_changed(self, widget):
model = widget.get_model()
active = widget.get_active()
icon_string = model[active][1].decode('utf-8')
gajim.config.set('iconset', icon_string)
gtkgui_helpers.reload_jabber_state_images()
gajim.interface.save_config()
def on_transports_iconsets_checkbutton_toggled(self, widget):
self.on_checkbutton_toggled(widget, 'use_transports_iconsets')
gtkgui_helpers.reload_jabber_state_images()
def on_outgoing_chat_states_combobox_changed(self, widget):
active = widget.get_active()
old_value = gajim.config.get('outgoing_chat_state_notifications')
if active == 0: # all
gajim.config.set('outgoing_chat_state_notifications', 'all')
elif active == 1: # only composing
gajim.config.set('outgoing_chat_state_notifications', 'composing_only')
else: # disabled
gajim.config.set('outgoing_chat_state_notifications', 'disabled')
new_value = gajim.config.get('outgoing_chat_state_notifications')
if 'disabled' in (old_value, new_value):
# we changed from disabled to sth else or vice versa
helpers.update_optional_features()
def on_displayed_chat_states_combobox_changed(self, widget):
active = widget.get_active()
if active == 0: # all
gajim.config.set('displayed_chat_state_notifications', 'all')
elif active == 1: # only composing
gajim.config.set('displayed_chat_state_notifications',
'composing_only')
else: # disabled
gajim.config.set('displayed_chat_state_notifications', 'disabled')
def on_ignore_events_from_unknown_contacts_checkbutton_toggled(self, widget):
self.on_checkbutton_toggled(widget, 'ignore_unknown_contacts')
def on_on_event_combobox_changed(self, widget):
active = widget.get_active()
if active == 0:
gajim.config.set('autopopup', True)
gajim.config.set('notify_on_new_message', False)
elif active == 1:
gajim.config.set('autopopup', False)
gajim.config.set('notify_on_new_message', True)
else:
gajim.config.set('autopopup', False)
gajim.config.set('notify_on_new_message', False)
def on_notify_on_signin_checkbutton_toggled(self, widget):
self.on_checkbutton_toggled(widget, 'notify_on_signin')
def on_notify_on_signout_checkbutton_toggled(self, widget):
self.on_checkbutton_toggled(widget, 'notify_on_signout')
def on_auto_popup_away_checkbutton_toggled(self, widget):
self.on_checkbutton_toggled(widget, 'autopopupaway')
def on_advanced_notifications_button_clicked(self, widget):
dialogs.AdvancedNotificationsWindow()
def on_play_sounds_checkbutton_toggled(self, widget):
self.on_checkbutton_toggled(widget, 'sounds_on',
[self.xml.get_widget('sounds_scrolledwindow'),
self.xml.get_widget('browse_sounds_hbox')])
def on_sounds_treemodel_row_changed(self, model, path, iter_):
sound_event = model[iter_][3].decode('utf-8')
gajim.config.set_per('soundevents', sound_event, 'enabled',
bool(model[path][0]))
gajim.config.set_per('soundevents', sound_event, 'path',
model[iter_][2].decode('utf-8'))
gajim.interface.save_config()
def update_text_tags(self):
'''Update color tags in Opened Chat Windows'''
for win in gajim.interface.msg_win_mgr.windows():
win.update_tags()
def on_preference_widget_color_set(self, widget, text):
color = widget.get_color()
color_string = gtkgui_helpers.make_color_string(color)
gajim.config.set(text, color_string)
self.update_text_tags()
gajim.interface.save_config()
def on_preference_widget_font_set(self, widget, text):
if widget:
font = widget.get_font_name()
else:
font = ''
gajim.config.set(text, font)
self.update_text_font()
gajim.interface.save_config()
def update_text_font(self):
'''Update text font in Opened Chat Windows'''
for win in gajim.interface.msg_win_mgr.windows():
win.update_font()
def on_incoming_msg_colorbutton_color_set(self, widget):
self.on_preference_widget_color_set(widget, 'inmsgcolor')
def on_outgoing_msg_colorbutton_color_set(self, widget):
self.on_preference_widget_color_set(widget, 'outmsgcolor')
def on_url_msg_colorbutton_color_set(self, widget):
self.on_preference_widget_color_set(widget, 'urlmsgcolor')
def on_status_msg_colorbutton_color_set(self, widget):
self.on_preference_widget_color_set(widget, 'statusmsgcolor')
def on_conversation_fontbutton_font_set(self, widget):
self.on_preference_widget_font_set(widget, 'conversation_font')
def on_default_chat_font_toggled(self, widget):
font_widget = self.xml.get_widget('conversation_fontbutton')
if widget.get_active():
font_widget.set_sensitive(False)
font_widget = None
else:
font_widget.set_sensitive(True)
self.on_preference_widget_font_set(font_widget, 'conversation_font')
def on_reset_colors_button_clicked(self, widget):
for i in ('inmsgcolor', 'outmsgcolor', 'statusmsgcolor', 'urlmsgcolor'):
gajim.config.set(i, gajim.interface.default_colors[i])
self.xml.get_widget('incoming_msg_colorbutton').set_color(\
gtk.gdk.color_parse(gajim.config.get('inmsgcolor')))
self.xml.get_widget('outgoing_msg_colorbutton').set_color(\
gtk.gdk.color_parse(gajim.config.get('outmsgcolor')))
self.xml.get_widget('status_msg_colorbutton').set_color(\
gtk.gdk.color_parse(gajim.config.get('statusmsgcolor')))
self.xml.get_widget('url_msg_colorbutton').set_color(\
gtk.gdk.color_parse(gajim.config.get('urlmsgcolor')))
self.update_text_tags()
gajim.interface.save_config()
def on_auto_away_checkbutton_toggled(self, widget):
self.on_checkbutton_toggled(widget, 'autoaway',
[self.auto_away_time_spinbutton, self.auto_away_message_entry])
def on_auto_away_time_spinbutton_value_changed(self, widget):
aat = widget.get_value_as_int()
gajim.config.set('autoawaytime', aat)
gajim.interface.sleeper = common.sleepy.Sleepy(
gajim.config.get('autoawaytime') * 60,
gajim.config.get('autoxatime') * 60)
gajim.interface.save_config()
def on_auto_away_message_entry_changed(self, widget):
gajim.config.set('autoaway_message', widget.get_text().decode('utf-8'))
def on_auto_xa_checkbutton_toggled(self, widget):
self.on_checkbutton_toggled(widget, 'autoxa',
[self.auto_xa_time_spinbutton, self.auto_xa_message_entry])
def on_auto_xa_time_spinbutton_value_changed(self, widget):
axt = widget.get_value_as_int()
gajim.config.set('autoxatime', axt)
gajim.interface.sleeper = common.sleepy.Sleepy(
gajim.config.get('autoawaytime') * 60,
gajim.config.get('autoxatime') * 60)
gajim.interface.save_config()
def on_auto_xa_message_entry_changed(self, widget):
gajim.config.set('autoxa_message', widget.get_text().decode('utf-8'))
def on_prompt_online_status_message_checkbutton_toggled(self, widget):
self.on_checkbutton_toggled(widget, 'ask_online_status')
def on_prompt_offline_status_message_checkbutton_toggled(self, widget):
self.on_checkbutton_toggled(widget, 'ask_offline_status')
def fill_default_msg_treeview(self):
model = self.default_msg_tree.get_model()
model.clear()
status = []
for status_ in gajim.config.get_per('defaultstatusmsg'):
status.append(status_)
status.sort()
for status_ in status:
msg = gajim.config.get_per('defaultstatusmsg', status_, 'message')
enabled = gajim.config.get_per('defaultstatusmsg', status_, 'enabled')
iter = model.append()
uf_show = helpers.get_uf_show(status_)
model.set(iter, 0, status_, 1, uf_show, 2, msg, 3, enabled)
def on_default_msg_cell_edited(self, cell, row, new_text):
model = self.default_msg_tree.get_model()
iter = model.get_iter_from_string(row)
model.set_value(iter, 2, new_text)
def default_msg_toggled_cb(self, cell, path):
model = self.default_msg_tree.get_model()
model[path][3] = not model[path][3]
def on_default_msg_treemodel_row_changed(self, model, path, iter_):
status = model[iter_][0]
message = model[iter_][2].decode('utf-8')
gajim.config.set_per('defaultstatusmsg', status, 'enabled',
model[iter_][3])
gajim.config.set_per('defaultstatusmsg', status, 'message', message)
def on_default_status_expander_activate(self, expander):
eventbox = self.xml.get_widget('default_status_eventbox')
vbox = self.xml.get_widget('status_vbox')
vbox.set_child_packing(eventbox, not expander.get_expanded(), True, 0,
gtk.PACK_START)
def save_status_messages(self, model):
for msg in gajim.config.get_per('statusmsg'):
gajim.config.del_per('statusmsg', msg)
iter = model.get_iter_first()
while iter:
val = model[iter][0].decode('utf-8')
if model[iter][1]: # we have a preset message
if not val: # no title, use message text for title
val = model[iter][1]
gajim.config.add_per('statusmsg', val)
msg = helpers.to_one_line(model[iter][1].decode('utf-8'))
gajim.config.set_per('statusmsg', val, 'message', msg)
iter = model.iter_next(iter)
gajim.interface.save_config()
def on_msg_treemodel_row_changed(self, model, path, iter_):
self.save_status_messages(model)
def on_msg_treemodel_row_deleted(self, model, path):
self.save_status_messages(model)
def on_applications_combobox_changed(self, widget):
gajim.config.set('autodetect_browser_mailer', False)
if sys.platform == 'darwin':
if widget.get_active() == 0:
gajim.config.set('autodetect_browser_mailer', True)
self.xml.get_widget('custom_apps_frame').hide()
elif widget.get_active() == 1:
self.xml.get_widget('custom_apps_frame').hide()
gajim.config.set('openwith', 'open')
elif widget.get_active() == 2:
self.xml.get_widget('custom_apps_frame').show()
gajim.config.set('openwith', 'custom')
else:
if widget.get_active() == 4:
self.xml.get_widget('custom_apps_frame').show()
gajim.config.set('openwith', 'custom')
else:
if widget.get_active() == 0:
gajim.config.set('autodetect_browser_mailer', True)
elif widget.get_active() == 1:
gajim.config.set('openwith', 'gnome-open')
elif widget.get_active() == 2:
gajim.config.set('openwith', 'kfmclient exec')
elif widget.get_active() == 3:
gajim.config.set('openwith', 'exo-open')
self.xml.get_widget('custom_apps_frame').hide()
gajim.interface.save_config()
def on_custom_browser_entry_changed(self, widget):
gajim.config.set('custombrowser', widget.get_text().decode('utf-8'))
gajim.interface.save_config()
def on_custom_mail_client_entry_changed(self, widget):
gajim.config.set('custommailapp', widget.get_text().decode('utf-8'))
gajim.interface.save_config()
def on_custom_file_manager_entry_changed(self, widget):
gajim.config.set('custom_file_manager', widget.get_text().decode('utf-8'))
gajim.interface.save_config()
def on_log_show_changes_checkbutton_toggled(self, widget):
self.on_checkbutton_toggled(widget, 'log_contact_status_changes')
def on_log_encrypted_chats_checkbutton_toggled(self, widget):
self.on_checkbutton_toggled(widget, 'log_encrypted_sessions')
def on_send_os_info_checkbutton_toggled(self, widget):
self.on_checkbutton_toggled(widget, 'send_os_info')
def on_check_default_client_checkbutton_toggled(self, widget):
self.on_checkbutton_toggled(widget, 'check_if_gajim_is_default')
def on_notify_gmail_checkbutton_toggled(self, widget):
self.on_checkbutton_toggled(widget, 'notify_on_new_gmail_email')
def on_notify_gmail_extra_checkbutton_toggled(self, widget):
self.on_checkbutton_toggled(widget, 'notify_on_new_gmail_email_extra')
def fill_msg_treeview(self):
self.xml.get_widget('delete_msg_button').set_sensitive(False)
model = self.msg_tree.get_model()
model.clear()
preset_status = []
for msg_name in gajim.config.get_per('statusmsg'):
preset_status.append(msg_name)
preset_status.sort()
for msg_name in preset_status:
msg_text = gajim.config.get_per('statusmsg', msg_name, 'message')
msg_text = helpers.from_one_line(msg_text)
iter = model.append()
model.set(iter, 0, msg_name, 1, msg_text)
def on_msg_cell_edited(self, cell, row, new_text):
model = self.msg_tree.get_model()
iter = model.get_iter_from_string(row)
model.set_value(iter, 0, new_text)
def on_msg_treeview_cursor_changed(self, widget, data = None):
(model, iter) = self.msg_tree.get_selection().get_selected()
if not iter:
return
self.xml.get_widget('delete_msg_button').set_sensitive(True)
buf = self.xml.get_widget('msg_textview').get_buffer()
msg = model[iter][1]
buf.set_text(msg)
def on_new_msg_button_clicked(self, widget, data = None):
model = self.msg_tree.get_model()
iter = model.append()
model.set(iter, 0, _('status message title'), 1, _('status message text'))
self.msg_tree.set_cursor(model.get_path(iter))
def on_delete_msg_button_clicked(self, widget, data = None):
(model, iter) = self.msg_tree.get_selection().get_selected()
if not iter:
return
buf = self.xml.get_widget('msg_textview').get_buffer()
model.remove(iter)
buf.set_text('')
self.xml.get_widget('delete_msg_button').set_sensitive(False)
def on_msg_textview_changed(self, widget, data = None):
(model, iter) = self.msg_tree.get_selection().get_selected()
if not iter:
return
buf = self.xml.get_widget('msg_textview').get_buffer()
first_iter, end_iter = buf.get_bounds()
name = model.get_value(iter, 0)
model.set_value(iter, 1, buf.get_text(first_iter, end_iter))
def on_msg_treeview_key_press_event(self, widget, event):
if event.keyval == gtk.keysyms.Delete:
self.on_delete_msg_button_clicked(widget)
def sound_toggled_cb(self, cell, path):
model = self.sound_tree.get_model()
model[path][0] = not model[path][0]
def fill_sound_treeview(self):
model = self.sound_tree.get_model()
model.clear()
model.set_sort_column_id(1, gtk.SORT_ASCENDING)
# NOTE: sounds_ui_names MUST have all items of
# sounds = gajim.config.get_per('soundevents') as keys
sounds_dict = {
'first_message_received': _('First Message Received'),
'next_message_received_focused': _('Next Message Received Focused'),
'next_message_received_unfocused':
_('Next Message Received Unfocused'),
'contact_connected': _('Contact Connected'),
'contact_disconnected': _('Contact Disconnected'),
'message_sent': _('Message Sent'),
'muc_message_highlight': _('Group Chat Message Highlight'),
'muc_message_received': _('Group Chat Message Received'),
'gmail_received': _('GMail Email Received')
}
for sound_event_config_name, sound_ui_name in sounds_dict.items():
enabled = gajim.config.get_per('soundevents',
sound_event_config_name, 'enabled')
path = gajim.config.get_per('soundevents',
sound_event_config_name, 'path')
model.append((enabled, sound_ui_name, path, sound_event_config_name))
def on_treeview_sounds_cursor_changed(self, widget, data = None):
(model, iter) = self.sound_tree.get_selection().get_selected()
sounds_entry = self.xml.get_widget('sounds_entry')
if not iter:
sounds_entry.set_text('')
return
path_to_snd_file = model[iter][2]
sounds_entry.set_text(path_to_snd_file)
def on_browse_for_sounds_button_clicked(self, widget, data = None):
(model, iter) = self.sound_tree.get_selection().get_selected()
if not iter:
return
def on_ok(widget, path_to_snd_file):
self.dialog.destroy()
model, iter = self.sound_tree.get_selection().get_selected()
if not path_to_snd_file:
model[iter][2] = ''
self.xml.get_widget('sounds_entry').set_text('')
model[iter][0] = False
return
directory = os.path.dirname(path_to_snd_file)
gajim.config.set('last_sounds_dir', directory)
self.xml.get_widget('sounds_entry').set_text(path_to_snd_file)
model[iter][2] = path_to_snd_file # set new path to sounds_model
model[iter][0] = True # set the sound to enabled
def on_cancel(widget):
self.dialog.destroy()
model, iter = self.sound_tree.get_selection().get_selected()
model[iter][2] = ''
model[iter][0] = False
path_to_snd_file = model[iter][2].decode('utf-8')
path_to_snd_file = os.path.join(os.getcwd(), path_to_snd_file)
self.dialog = dialogs.SoundChooserDialog(path_to_snd_file, on_ok,
on_cancel)
def on_sounds_entry_changed(self, widget):
path_to_snd_file = widget.get_text()
model, iter = self.sound_tree.get_selection().get_selected()
model[iter][2] = path_to_snd_file # set new path to sounds_model
def on_play_button_clicked(self, widget):
model, iter = self.sound_tree.get_selection().get_selected()
if not iter:
return
snd_event_config_name = model[iter][3]
helpers.play_sound(snd_event_config_name)
def on_open_advanced_editor_button_clicked(self, widget, data = None):
if 'advanced_config' in gajim.interface.instances:
gajim.interface.instances['advanced_config'].window.present()
else:
gajim.interface.instances['advanced_config'] = \
dialogs.AdvancedConfigurationWindow()
#---------- ManageProxiesWindow class -------------#
class ManageProxiesWindow:
def __init__(self):
self.xml = gtkgui_helpers.get_glade('manage_proxies_window.glade')
self.window = self.xml.get_widget('manage_proxies_window')
self.window.set_transient_for(gajim.interface.roster.window)
self.proxies_treeview = self.xml.get_widget('proxies_treeview')
self.proxyname_entry = self.xml.get_widget('proxyname_entry')
self.proxytype_combobox = self.xml.get_widget('proxytype_combobox')
self.init_list()
self.xml.signal_autoconnect(self)
self.window.show_all()
def fill_proxies_treeview(self):
model = self.proxies_treeview.get_model()
model.clear()
iter = model.append()
model.set(iter, 0, _('None'))
for p in gajim.config.get_per('proxies'):
iter = model.append()
model.set(iter, 0, p)
def init_list(self):
self.xml.get_widget('remove_proxy_button').set_sensitive(False)
self.proxytype_combobox.set_sensitive(False)
self.xml.get_widget('proxy_table').set_sensitive(False)
model = gtk.ListStore(str)
self.proxies_treeview.set_model(model)
col = gtk.TreeViewColumn('Proxies')
self.proxies_treeview.append_column(col)
renderer = gtk.CellRendererText()
col.pack_start(renderer, True)
col.set_attributes(renderer, text = 0)
self.fill_proxies_treeview()
self.xml.get_widget('proxytype_combobox').set_active(0)
def on_manage_proxies_window_destroy(self, widget):
if 'accounts' in gajim.interface.instances:
gajim.interface.instances['accounts'].\
update_proxy_list()
del gajim.interface.instances['manage_proxies']
def on_add_proxy_button_clicked(self, widget):
model = self.proxies_treeview.get_model()
proxies = gajim.config.get_per('proxies')
i = 1
while ('proxy' + unicode(i)) in proxies:
i += 1
iter = model.append()
model.set(iter, 0, 'proxy' + unicode(i))
gajim.config.add_per('proxies', 'proxy' + unicode(i))
def on_remove_proxy_button_clicked(self, widget):
(model, iter) = self.proxies_treeview.get_selection().get_selected()
if not iter:
return
proxy = model[iter][0].decode('utf-8')
model.remove(iter)
gajim.config.del_per('proxies', proxy)
self.xml.get_widget('remove_proxy_button').set_sensitive(False)
def on_close_button_clicked(self, widget):
self.window.destroy()
def on_useauth_checkbutton_toggled(self, widget):
act = widget.get_active()
self.xml.get_widget('proxyuser_entry').set_sensitive(act)
self.xml.get_widget('proxypass_entry').set_sensitive(act)
def on_proxies_treeview_cursor_changed(self, widget):
#FIXME: check if off proxy settings are correct (see
# http://trac.gajim.org/changeset/1921#file2 line 1221
(model, iter) = widget.get_selection().get_selected()
if not iter:
return
proxy = model[iter][0]
self.xml.get_widget('proxyname_entry').set_text(proxy)
proxyhost_entry = self.xml.get_widget('proxyhost_entry')
proxyport_entry = self.xml.get_widget('proxyport_entry')
proxyuser_entry = self.xml.get_widget('proxyuser_entry')
proxypass_entry = self.xml.get_widget('proxypass_entry')
useauth_checkbutton = self.xml.get_widget('useauth_checkbutton')
proxyhost_entry.set_text('')
proxyport_entry.set_text('')
proxyuser_entry.set_text('')
proxypass_entry.set_text('')
useauth_checkbutton.set_active(False)
self.on_useauth_checkbutton_toggled(useauth_checkbutton)
if proxy == _('None'): # special proxy None
self.proxyname_entry.set_editable(False)
self.xml.get_widget('remove_proxy_button').set_sensitive(False)
self.xml.get_widget('proxytype_combobox').set_sensitive(False)
self.xml.get_widget('proxy_table').set_sensitive(False)
else:
self.proxyname_entry.set_editable(True)
self.xml.get_widget('remove_proxy_button').set_sensitive(True)
self.xml.get_widget('proxytype_combobox').set_sensitive(True)
self.xml.get_widget('proxy_table').set_sensitive(True)
proxyhost_entry.set_text(gajim.config.get_per('proxies', proxy,
'host'))
proxyport_entry.set_text(unicode(gajim.config.get_per('proxies',
proxy, 'port')))
proxyuser_entry.set_text(gajim.config.get_per('proxies', proxy,
'user'))
proxypass_entry.set_text(gajim.config.get_per('proxies', proxy,
'pass'))
proxytype = gajim.config.get_per('proxies', proxy, 'type')
types = ['http', 'socks5']
self.proxytype_combobox.set_active(types.index(proxytype))
if gajim.config.get_per('proxies', proxy, 'user'):
useauth_checkbutton.set_active(True)
def on_proxies_treeview_key_press_event(self, widget, event):
if event.keyval == gtk.keysyms.Delete:
self.on_remove_proxy_button_clicked(widget)
def on_proxyname_entry_changed(self, widget):
(model, iter) = self.proxies_treeview.get_selection().get_selected()
if not iter:
return
old_name = model.get_value(iter, 0).decode('utf-8')
new_name = widget.get_text().decode('utf-8')
if new_name == '':
return
if new_name == old_name:
return
config = gajim.config.get_per('proxies', old_name)
gajim.config.del_per('proxies', old_name)
gajim.config.add_per('proxies', new_name)
for option in config:
gajim.config.set_per('proxies', new_name, option,
config[option][common.config.OPT_VAL])
model.set_value(iter, 0, new_name)
def on_proxytype_combobox_changed(self, widget):
types = ['http', 'socks5']
type_ = self.proxytype_combobox.get_active()
proxy = self.proxyname_entry.get_text().decode('utf-8')
gajim.config.set_per('proxies', proxy, 'type', types[type_])
def on_proxyhost_entry_changed(self, widget):
value = widget.get_text().decode('utf-8')
proxy = self.proxyname_entry.get_text().decode('utf-8')
gajim.config.set_per('proxies', proxy, 'host', value)
def on_proxyport_entry_changed(self, widget):
value = widget.get_text().decode('utf-8')
proxy = self.proxyname_entry.get_text().decode('utf-8')
gajim.config.set_per('proxies', proxy, 'port', value)
def on_proxyuser_entry_changed(self, widget):
value = widget.get_text().decode('utf-8')
proxy = self.proxyname_entry.get_text().decode('utf-8')
gajim.config.set_per('proxies', proxy, 'user', value)
def on_proxypass_entry_changed(self, widget):
value = widget.get_text().decode('utf-8')
proxy = self.proxyname_entry.get_text().decode('utf-8')
gajim.config.set_per('proxies', proxy, 'pass', value)
#---------- AccountsWindow class -------------#
class AccountsWindow:
'''Class for accounts window: list of accounts'''
def on_accounts_window_destroy(self, widget):
del gajim.interface.instances['accounts']
def on_close_button_clicked(self, widget):
self.check_resend_relog()
self.window.destroy()
def __init__(self):
self.xml = gtkgui_helpers.get_glade('accounts_window.glade')
self.window = self.xml.get_widget('accounts_window')
self.window.set_transient_for(gajim.interface.roster.window)
self.accounts_treeview = self.xml.get_widget('accounts_treeview')
self.remove_button = self.xml.get_widget('remove_button')
self.rename_button = self.xml.get_widget('rename_button')
path_to_kbd_input_img = os.path.join(gajim.DATA_DIR, 'pixmaps',
'kbd_input.png')
img = self.xml.get_widget('rename_image')
img.set_from_file(path_to_kbd_input_img)
self.notebook = self.xml.get_widget('notebook')
# Name
model = gtk.ListStore(str)
self.accounts_treeview.set_model(model)
# column
renderer = gtk.CellRendererText()
self.accounts_treeview.insert_column_with_attributes(-1,
_('Name'), renderer, text = 0)
self.current_account = None
# When we fill info, we don't want to handle the changed signals
self.ignore_events = False
self.need_relogin = False
self.resend_presence = False
self.update_proxy_list()
self.xml.signal_autoconnect(self)
self.init_accounts()
self.window.show_all()
# Merge accounts
st = gajim.config.get('mergeaccounts')
checkbutton = self.xml.get_widget('merge_checkbutton')
checkbutton.set_active(st)
# prevent roster redraws by connecting the signal after button state is set
checkbutton.connect('toggled', self.on_merge_checkbutton_toggled)
self.avahi_available = True
try:
import avahi
except ImportError:
self.avahi_available = False
def on_accounts_window_key_press_event(self, widget, event):
if event.keyval == gtk.keysyms.Escape:
self.check_resend_relog()
self.window.destroy()
def select_account(self, account):
model = self.accounts_treeview.get_model()
iter = model.get_iter_root()
while iter:
acct = model[iter][0].decode('utf-8')
if account == acct:
self.accounts_treeview.set_cursor(model.get_path(iter))
return
iter = model.iter_next(iter)
def init_accounts(self):
'''initialize listStore with existing accounts'''
self.remove_button.set_sensitive(False)
self.rename_button.set_sensitive(False)
self.current_account = None
model = self.accounts_treeview.get_model()
model.clear()
for account in gajim.config.get_per('accounts'):
iter = model.append()
model.set(iter, 0, account)
def resend(self, account):
show = gajim.SHOW_LIST[gajim.connections[account].connected]
status = gajim.connections[account].status
gajim.connections[account].change_status(show, status)
def check_resend_relog(self):
if self.need_relogin and self.current_account == gajim.ZEROCONF_ACC_NAME:
if gajim.ZEROCONF_ACC_NAME in gajim.connections:
gajim.connections[gajim.ZEROCONF_ACC_NAME].update_details()
return
elif self.need_relogin and self.current_account and \
gajim.connections[self.current_account].connected > 0:
def login(account, show_before, status_before):
''' login with previous status'''
# first make sure connection is really closed,
# 0.5 may not be enough
gajim.connections[account].disconnect(True)
gajim.interface.roster.send_status(account, show_before,
status_before)
def relog(account):
self.dialog.destroy()
show_before = gajim.SHOW_LIST[gajim.connections[account].connected]
status_before = gajim.connections[account].status
gajim.interface.roster.send_status(account, 'offline',
_('Be right back.'))
gobject.timeout_add(500, login, account, show_before, status_before)
def on_yes(checked, account):
relog(account)
def on_no(account):
if self.resend_presence:
self.resend(account)
self.dialog = dialogs.YesNoDialog(_('Relogin now?'),
_('If you want all the changes to apply instantly, '
'you must relogin.'), on_response_yes=(on_yes,
self.current_account), on_response_no=(on_no, self.current_account))
elif self.resend_presence:
self.resend(self.current_account)
self.need_relogin = False
self.resend_presence = False
def on_accounts_treeview_cursor_changed(self, widget):
'''Activate modify buttons when a row is selected, update accounts info'''
sel = self.accounts_treeview.get_selection()
(model, iter) = sel.get_selected()
if iter:
account = model[iter][0].decode('utf-8')
else:
account = None
if self.current_account and self.current_account == account:
# We're comming back to our current account, no need to update widgets
return
# Save config for previous account if needed cause focus_out event is
# called after the changed event
if self.current_account and self.window.get_focus():
focused_widget = self.window.get_focus()
focused_widget_name = focused_widget.get_name()
if focused_widget_name in ('jid_entry1', 'resource_entry1',
'custom_port_entry'):
if focused_widget_name == 'jid_entry1':
func = self.on_jid_entry1_focus_out_event
elif focused_widget_name == 'resource_entry1':
func = self.on_resource_entry1_focus_out_event
elif focused_widget_name == 'custom_port_entry':
func = self.on_custom_port_entry_focus_out_event
if func(focused_widget, None):
# Error detected in entry, don't change account, re-put cursor on
# previous row
self.select_account(self.current_account)
return True
self.window.set_focus(widget)
self.check_resend_relog()
self.remove_button.set_sensitive(True)
self.rename_button.set_sensitive(True)
if iter:
self.current_account = account
if account == gajim.ZEROCONF_ACC_NAME:
self.remove_button.set_sensitive(False)
self.init_account()
self.update_proxy_list()
def update_proxy_list(self):
if self.current_account:
our_proxy = gajim.config.get_per('accounts', self.current_account,
'proxy')
else:
our_proxy = ''
if not our_proxy:
our_proxy = _('None')
proxy_combobox = self.xml.get_widget('proxies_combobox1')
model = gtk.ListStore(str)
proxy_combobox.set_model(model)
l = gajim.config.get_per('proxies')
l.insert(0, _('None'))
for i in xrange(len(l)):
model.append([l[i]])
if our_proxy == l[i]:
proxy_combobox.set_active(i)
def init_account(self):
if not self.current_account:
self.notebook.set_current_page(0)
return
if gajim.config.get_per('accounts', self.current_account, 'is_zeroconf'):
self.ignore_events = True
self.init_zeroconf_account()
self.ignore_events = False
self.notebook.set_current_page(2)
return
self.ignore_events = True
self.init_normal_account()
self.ignore_events = False
self.notebook.set_current_page(1)
def init_zeroconf_account(self):
enable = gajim.config.get('enable_zeroconf')
self.xml.get_widget('enable_zeroconf_checkbutton2').set_active(enable)
self.xml.get_widget('zeroconf_notebook').set_sensitive(enable)
# General tab
st = gajim.config.get_per('accounts', gajim.ZEROCONF_ACC_NAME,
'autoconnect')
self.xml.get_widget('autoconnect_checkbutton2').set_active(st)
list_no_log_for = gajim.config.get_per('accounts',
gajim.ZEROCONF_ACC_NAME, 'no_log_for').split()
if gajim.ZEROCONF_ACC_NAME in list_no_log_for:
self.xml.get_widget('log_history_checkbutton2').set_active(0)
else:
self.xml.get_widget('log_history_checkbutton2').set_active(1)
st = gajim.config.get_per('accounts', gajim.ZEROCONF_ACC_NAME,
'sync_with_global_status')
self.xml.get_widget('sync_with_global_status_checkbutton2').set_active(st)
st = gajim.config.get_per('accounts', gajim.ZEROCONF_ACC_NAME,
'use_custom_host')
self.xml.get_widget('custom_port_checkbutton2').set_active(st)
self.xml.get_widget('custom_port_entry2').set_sensitive(st)
st = gajim.config.get_per('accounts', gajim.ZEROCONF_ACC_NAME,
'custom_port')
if not st:
gajim.config.set_per('accounts', gajim.ZEROCONF_ACC_NAME,
'custom_port', '5298')
st = '5298'
self.xml.get_widget('custom_port_entry2').set_text(str(st))
# Personal tab
gpg_key_label = self.xml.get_widget('gpg_key_label2')
if gajim.ZEROCONF_ACC_NAME in gajim.connections and \
gajim.connections[gajim.ZEROCONF_ACC_NAME].gpg:
self.xml.get_widget('gpg_choose_button2').set_sensitive(True)
self.init_account_gpg()
else:
gpg_key_label.set_text(_('OpenPGP is not usable in this computer'))
self.xml.get_widget('gpg_choose_button2').set_sensitive(False)
for opt in ('first_name', 'last_name', 'jabber_id', 'email'):
st = gajim.config.get_per('accounts', gajim.ZEROCONF_ACC_NAME,
'zeroconf_' + opt)
self.xml.get_widget(opt + '_entry2').set_text(st)
def init_account_gpg(self):
account = self.current_account
keyid = gajim.config.get_per('accounts', account, 'keyid')
keyname = gajim.config.get_per('accounts', account, 'keyname')
use_gpg_agent = gajim.config.get('use_gpg_agent')
if account == gajim.ZEROCONF_ACC_NAME:
widget_name_add = '2'
else:
widget_name_add = '1'
gpg_key_label = self.xml.get_widget('gpg_key_label' + widget_name_add)
gpg_name_label = self.xml.get_widget('gpg_name_label' + widget_name_add)
use_gpg_agent_checkbutton = self.xml.get_widget(
'use_gpg_agent_checkbutton' + widget_name_add)
if not keyid or not gajim.connections[account].gpg:
use_gpg_agent_checkbutton.set_sensitive(False)
gpg_key_label.set_text(_('No key selected'))
gpg_name_label.set_text('')
return
gpg_key_label.set_text(keyid)
gpg_name_label.set_text(keyname)
use_gpg_agent_checkbutton.set_sensitive(True)
use_gpg_agent_checkbutton.set_active(use_gpg_agent)
def init_normal_account(self):
account = self.current_account
# Account tab
jid = gajim.config.get_per('accounts', account, 'name') \
+ '@' + gajim.config.get_per('accounts', account, 'hostname')
self.xml.get_widget('jid_entry1').set_text(jid)
savepass = gajim.config.get_per('accounts', account, 'savepass')
self.xml.get_widget('save_password_checkbutton1').set_active(savepass)
password_entry = self.xml.get_widget('password_entry1')
if savepass:
passstr = passwords.get_password(account) or ''
password_entry.set_sensitive(True)
else:
passstr = ''
password_entry.set_sensitive(False)
password_entry.set_text(passstr)
self.xml.get_widget('resource_entry1').set_text(gajim.config.get_per(
'accounts', account, 'resource'))
self.xml.get_widget('adjust_priority_with_status_checkbutton1').\
set_active(gajim.config.get_per('accounts', account,
'adjust_priority_with_status'))
spinbutton = self.xml.get_widget('priority_spinbutton1')
if gajim.config.get('enable_negative_priority'):
spinbutton.set_range(-128, 127)
else:
spinbutton.set_range(0, 127)
spinbutton.set_value(gajim.config.get_per('accounts', account,
'priority'))
# Connection tab
use_env_http_proxy = gajim.config.get_per('accounts', account,
'use_env_http_proxy')
self.xml.get_widget('use_env_http_proxy_checkbutton1').set_active(
use_env_http_proxy)
self.xml.get_widget('proxy_hbox1').set_sensitive(not use_env_http_proxy)
warn_when_insecure_ssl = gajim.config.get_per('accounts', account,
'warn_when_insecure_ssl_connection')
self.xml.get_widget('warn_when_insecure_connection_checkbutton1').\
set_active(warn_when_insecure_ssl)
self.xml.get_widget('send_keepalive_checkbutton1').set_active(
gajim.config.get_per('accounts', account, 'keep_alives_enabled'))
use_custom_host = gajim.config.get_per('accounts', account,
'use_custom_host')
self.xml.get_widget('custom_host_port_checkbutton1').set_active(
use_custom_host)
custom_host = gajim.config.get_per('accounts', account, 'custom_host')
if not custom_host:
custom_host = gajim.config.get_per('accounts', account, 'hostname')
self.xml.get_widget('custom_host_entry1').set_text(custom_host)
custom_port = gajim.config.get_per('accounts', account, 'custom_port')
if not custom_port:
custom_port = 5222
self.xml.get_widget('custom_port_entry1').set_text(unicode(custom_port))
# Personal tab
gpg_key_label = self.xml.get_widget('gpg_key_label1')
if gajim.connections[account].gpg:
self.xml.get_widget('gpg_choose_button1').set_sensitive(True)
self.init_account_gpg()
else:
gpg_key_label.set_text(_('OpenPGP is not usable in this computer'))
self.xml.get_widget('gpg_choose_button1').set_sensitive(False)
# General tab
self.xml.get_widget('autoconnect_checkbutton1').set_active(gajim.config.\
get_per('accounts', account, 'autoconnect'))
self.xml.get_widget('autoreconnect_checkbutton1').set_active(gajim.
config.get_per('accounts', account, 'autoreconnect'))
list_no_log_for = gajim.config.get_per('accounts', account,
'no_log_for').split()
if account in list_no_log_for:
self.xml.get_widget('log_history_checkbutton1').set_active(False)
else:
self.xml.get_widget('log_history_checkbutton1').set_active(True)
self.xml.get_widget('sync_with_global_status_checkbutton1').set_active(
gajim.config.get_per('accounts', account, 'sync_with_global_status'))
self.xml.get_widget('use_ft_proxies_checkbutton1').set_active(
gajim.config.get_per('accounts', account, 'use_ft_proxies'))
def on_add_button_clicked(self, widget):
'''When add button is clicked: open an account information window'''
if 'account_creation_wizard' in gajim.interface.instances:
gajim.interface.instances['account_creation_wizard'].window.present()
else:
gajim.interface.instances['account_creation_wizard'] = \
AccountCreationWizardWindow()
def on_remove_button_clicked(self, widget):
'''When delete button is clicked:
Remove an account from the listStore and from the config file'''
if not self.current_account:
return
account = self.current_account
if len(gajim.events.get_events(account)):
dialogs.ErrorDialog(_('Unread events'),
_('Read all pending events before removing this account.'))
return
if gajim.config.get_per('accounts', account, 'is_zeroconf'):
# Should never happen as button is insensitive
return
win_opened = False
if gajim.interface.msg_win_mgr.get_controls(acct = account):
win_opened = True
else:
for key in gajim.interface.instances[account]:
if gajim.interface.instances[account][key] and key != \
'remove_account':
win_opened = True
break
# Detect if we have opened windows for this account
def remove(account):
if 'remove_account' in gajim.interface.instances[account]:
gajim.interface.instances[account]['remove_account'].window.\
present()
else:
gajim.interface.instances[account]['remove_account'] = \
RemoveAccountWindow(account)
if win_opened:
dialog = dialogs.ConfirmationDialog(
_('You have opened chat in account %s') % account,
_('All chat and groupchat windows will be closed. Do you want to '
'continue?'),
on_response_ok = (remove, account))
else:
remove(account)
def on_rename_button_clicked(self, widget):
enable = gajim.config.get('enable_zeroconf')
if (self.current_account != gajim.ZEROCONF_ACC_NAME or enable) and \
gajim.connections[self.current_account].connected != 0:
dialogs.ErrorDialog(
_('You are currently connected to the server'),
_('To change the account name, you must be disconnected.'))
return
if len(gajim.events.get_events(self.current_account)):
dialogs.ErrorDialog(_('Unread events'),
_('To change the account name, you must read all pending '
'events.'))
return
# Get the new name
def on_renamed(new_name, old_name):
if new_name in gajim.connections:
dialogs.ErrorDialog(_('Account Name Already Used'),
_('This name is already used by another of your accounts. '
'Please choose another name.'))
return
if (new_name == ''):
dialogs.ErrorDialog(_('Invalid account name'),
_('Account name cannot be empty.'))
return
if new_name.find(' ') != -1:
dialogs.ErrorDialog(_('Invalid account name'),
_('Account name cannot contain spaces.'))
return
if self.current_account != gajim.ZEROCONF_ACC_NAME or enable:
# update variables
gajim.interface.instances[new_name] = gajim.interface.instances[
old_name]
gajim.interface.minimized_controls[new_name] = \
gajim.interface.minimized_controls[old_name]
gajim.nicks[new_name] = gajim.nicks[old_name]
gajim.block_signed_in_notifications[new_name] = \
gajim.block_signed_in_notifications[old_name]
gajim.groups[new_name] = gajim.groups[old_name]
gajim.gc_connected[new_name] = gajim.gc_connected[old_name]
gajim.automatic_rooms[new_name] = gajim.automatic_rooms[old_name]
gajim.newly_added[new_name] = gajim.newly_added[old_name]
gajim.to_be_removed[new_name] = gajim.to_be_removed[old_name]
gajim.sleeper_state[new_name] = gajim.sleeper_state[old_name]
gajim.encrypted_chats[new_name] = gajim.encrypted_chats[old_name]
gajim.last_message_time[new_name] = \
gajim.last_message_time[old_name]
gajim.status_before_autoaway[new_name] = \
gajim.status_before_autoaway[old_name]
gajim.transport_avatar[new_name] = gajim.transport_avatar[old_name]
gajim.gajim_optional_features[new_name] = \
gajim.gajim_optional_features[old_name]
gajim.caps_hash[new_name] = gajim.caps_hash[old_name]
gajim.contacts.change_account_name(old_name, new_name)
gajim.events.change_account_name(old_name, new_name)
# change account variable for chat / gc controls
gajim.interface.msg_win_mgr.change_account_name(old_name, new_name)
# upgrade account variable in opened windows
for kind in ('infos', 'disco', 'gc_config', 'search'):
for j in gajim.interface.instances[new_name][kind]:
gajim.interface.instances[new_name][kind][j].account = \
new_name
# ServiceCache object keep old property account
if hasattr(gajim.connections[old_name], 'services_cache'):
gajim.connections[old_name].services_cache.account = new_name
del gajim.interface.instances[old_name]
del gajim.interface.minimized_controls[old_name]
del gajim.nicks[old_name]
del gajim.block_signed_in_notifications[old_name]
del gajim.groups[old_name]
del gajim.gc_connected[old_name]
del gajim.automatic_rooms[old_name]
del gajim.newly_added[old_name]
del gajim.to_be_removed[old_name]
del gajim.sleeper_state[old_name]
del gajim.encrypted_chats[old_name]
del gajim.last_message_time[old_name]
del gajim.status_before_autoaway[old_name]
del gajim.transport_avatar[old_name]
del gajim.gajim_optional_features[old_name]
del gajim.caps_hash[old_name]
gajim.connections[old_name].name = new_name
gajim.connections[new_name] = gajim.connections[old_name]
del gajim.connections[old_name]
gajim.config.add_per('accounts', new_name)
old_config = gajim.config.get_per('accounts', old_name)
for opt in old_config:
gajim.config.set_per('accounts', new_name, opt, old_config[opt][1])
gajim.config.del_per('accounts', old_name)
if self.current_account == old_name:
self.current_account = new_name
if old_name == gajim.ZEROCONF_ACC_NAME:
gajim.ZEROCONF_ACC_NAME = new_name
# refresh roster
gajim.interface.roster.setup_and_draw_roster()
self.init_accounts()
self.select_account(new_name)
title = _('Rename Account')
message = _('Enter a new name for account %s') % self.current_account
old_text = self.current_account
dialogs.InputDialog(title, message, old_text, is_modal=False,
ok_handler=(on_renamed, self.current_account))
def option_changed(self, option, value):
return gajim.config.get_per('accounts', self.current_account, option) != \
value
def on_jid_entry1_focus_out_event(self, widget, event):
if self.ignore_events:
return
jid = widget.get_text()
# check if jid is conform to RFC and stringprep it
try:
jid = helpers.parse_jid(jid)
except helpers.InvalidFormat, s:
if not widget.is_focus():
pritext = _('Invalid Jabber ID')
dialogs.ErrorDialog(pritext, str(s))
gobject.idle_add(lambda: widget.grab_focus())
return True
jid_splited = jid.split('@', 1)
if len(jid_splited) != 2:
if not widget.is_focus():
pritext = _('Invalid Jabber ID')
sectext = _('A Jabber ID must be in the form "user@servername".')
dialogs.ErrorDialog(pritext, sectext)
gobject.idle_add(lambda: widget.grab_focus())
return True
if self.option_changed('name', jid_splited[0]) or \
self.option_changed('hostname', jid_splited[1]):
self.need_relogin = True
gajim.config.set_per('accounts', self.current_account, 'name',
jid_splited[0])
gajim.config.set_per('accounts', self.current_account, 'hostname',
jid_splited[1])
def on_password_entry1_changed(self, widget):
if self.ignore_events:
return
passwords.save_password(self.current_account, widget.get_text().decode(
'utf-8'))
def on_save_password_checkbutton1_toggled(self, widget):
if self.ignore_events:
return
active = widget.get_active()
password_entry = self.xml.get_widget('password_entry1')
password_entry.set_sensitive(active)
gajim.config.set_per('accounts', self.current_account, 'savepass', active)
if active:
password = password_entry.get_text()
passwords.save_password(self.current_account, password)
else:
passwords.save_password(self.current_account, '')
def on_resource_entry1_focus_out_event(self, widget, event):
if self.ignore_events:
return
resource = self.xml.get_widget('resource_entry1').get_text().decode(
'utf-8')
try:
resource = helpers.parse_resource(resource)
except helpers.InvalidFormat, s:
if not widget.is_focus():
pritext = _('Invalid Jabber ID')
dialogs.ErrorDialog(pritext, str(s))
gobject.idle_add(lambda: widget.grab_focus())
return True
if self.option_changed('resource', resource):
self.need_relogin = True
gajim.config.set_per('accounts', self.current_account, 'resource',
resource)
def on_adjust_priority_with_status_checkbutton1_toggled(self, widget):
self.xml.get_widget('priority_spinbutton1').set_sensitive(
not widget.get_active())
self.on_checkbutton_toggled(widget, 'adjust_priority_with_status',
account = self.current_account)
def on_priority_spinbutton1_value_changed(self, widget):
prio = widget.get_value_as_int()
if self.option_changed('priority', prio):
self.resend_presence = True
gajim.config.set_per('accounts', self.current_account, 'priority', prio)
def on_synchronise_contacts_button1_clicked(self, widget):
try:
dialog = dialogs.SynchroniseSelectAccountDialog(self.current_account)
except GajimGeneralException:
# If we showed ErrorDialog, there will not be dialog instance
return
def on_change_password_button1_clicked(self, widget):
def on_changed(new_password):
if new_password is not None:
gajim.connections[self.current_account].change_password(
new_password)
if self.xml.get_widget('save_password_checkbutton1').get_active():
self.xml.get_widget('password_entry1').set_text(new_password)
try:
dialog = dialogs.ChangePasswordDialog(self.current_account, on_changed)
except GajimGeneralException:
# if we showed ErrorDialog, there will not be dialog instance
return
def on_autoconnect_checkbutton_toggled(self, widget):
if self.ignore_events:
return
self.on_checkbutton_toggled(widget, 'autoconnect',
account=self.current_account)
def on_autoreconnect_checkbutton_toggled(self, widget):
if self.ignore_events:
return
self.on_checkbutton_toggled(widget, 'autoreconnect',
account=self.current_account)
def on_log_history_checkbutton_toggled(self, widget):
if self.ignore_events:
return
list_no_log_for = gajim.config.get_per('accounts', self.current_account,
'no_log_for').split()
if self.current_account in list_no_log_for:
list_no_log_for.remove(self.current_account)
if not widget.get_active():
list_no_log_for.append(self.current_account)
gajim.config.set_per('accounts', self.current_account, 'no_log_for',
' '.join(list_no_log_for))
def on_sync_with_global_status_checkbutton_toggled(self, widget):
if self.ignore_events:
return
self.on_checkbutton_toggled(widget, 'sync_with_global_status',
account=self.current_account)
gajim.interface.roster.update_status_combobox()
def on_use_ft_proxies_checkbutton1_toggled(self, widget):
if self.ignore_events:
return
self.on_checkbutton_toggled(widget, 'use_ft_proxies',
account=self.current_account)
def on_use_env_http_proxy_checkbutton1_toggled(self, widget):
if self.ignore_events:
return
self.on_checkbutton_toggled(widget, 'use_env_http_proxy',
account=self.current_account)
hbox = self.xml.get_widget('proxy_hbox1')
hbox.set_sensitive(not widget.get_active())
def on_proxies_combobox1_changed(self, widget):
active = widget.get_active()
proxy = widget.get_model()[active][0].decode('utf-8')
if proxy == _('None'):
proxy = ''
if self.option_changed('proxy', proxy):
self.need_relogin = True
gajim.config.set_per('accounts', self.current_account, 'proxy', proxy)
def on_manage_proxies_button1_clicked(self, widget):
if 'manage_proxies' in gajim.interface.instances:
gajim.interface.instances['manage_proxies'].window.present()
else:
gajim.interface.instances['manage_proxies'] = ManageProxiesWindow()
def on_warn_when_insecure_connection_checkbutton1_toggled(self, widget):
if self.ignore_events:
return
self.on_checkbutton_toggled(widget, 'warn_when_insecure_ssl_connection',
account=self.current_account)
def on_send_keepalive_checkbutton1_toggled(self, widget):
if self.ignore_events:
return
self.on_checkbutton_toggled(widget, 'keep_alives_enabled',
account=self.current_account)
def on_custom_host_port_checkbutton1_toggled(self, widget):
if self.option_changed('use_custom_host', widget.get_active()):
self.need_relogin = True
self.on_checkbutton_toggled(widget, 'use_custom_host',
account=self.current_account)
active = widget.get_active()
self.xml.get_widget('custom_host_port_hbox1').set_sensitive(active)
def on_custom_host_entry1_changed(self, widget):
if self.ignore_events:
return
host = widget.get_text().decode('utf-8')
if self.option_changed('custom_host', host):
self.need_relogin = True
gajim.config.set_per('accounts', self.current_account, 'custom_host',
host)
def on_custom_port_entry_focus_out_event(self, widget, event):
if self.ignore_events:
return
custom_port = widget.get_text()
try:
custom_port = int(custom_port)
except Exception:
if not widget.is_focus():
dialogs.ErrorDialog(_('Invalid entry'),
_('Custom port must be a port number.'))
gobject.idle_add(lambda: widget.grab_focus())
return True
if self.option_changed('custom_port', custom_port):
self.need_relogin = True
gajim.config.set_per('accounts', self.current_account, 'custom_port',
custom_port)
def on_gpg_choose_button_clicked(self, widget, data = None):
if self.current_account in gajim.connections and \
gajim.connections[self.current_account].gpg:
secret_keys = gajim.connections[self.current_account].\
ask_gpg_secrete_keys()
# self.current_account is None and/or gajim.connections is {}
else:
if gajim.HAVE_GPG:
secret_keys = GnuPG.GnuPG().get_secret_keys()
else:
secret_keys = []
if not secret_keys:
dialogs.ErrorDialog(_('Failed to get secret keys'),
_('There was a problem retrieving your OpenPGP secret keys.'))
return
secret_keys[_('None')] = _('None')
def on_key_selected(keyID):
if keyID is None:
return
if self.current_account == gajim.ZEROCONF_ACC_NAME:
wiget_name_ext = '2'
else:
wiget_name_ext = '1'
gpg_key_label = self.xml.get_widget('gpg_key_label' + wiget_name_ext)
gpg_name_label = self.xml.get_widget('gpg_name_label' + wiget_name_ext)
use_gpg_agent_checkbutton = self.xml.get_widget(
'use_gpg_agent_checkbutton' + wiget_name_ext)
if keyID[0] == _('None'):
gpg_key_label.set_text(_('No key selected'))
gpg_name_label.set_text('')
use_gpg_agent_checkbutton.set_sensitive(False)
if self.option_changed('keyid', ''):
self.need_relogin = True
gajim.config.set_per('accounts', self.current_account, 'keyname',
'')
gajim.config.set_per('accounts', self.current_account, 'keyid', '')
else:
gpg_key_label.set_text(keyID[0])
gpg_name_label.set_text(keyID[1])
use_gpg_agent_checkbutton.set_sensitive(True)
if self.option_changed('keyid', keyID[0]):
self.need_relogin = True
gajim.config.set_per('accounts', self.current_account, 'keyname',
keyID[1])
gajim.config.set_per('accounts', self.current_account, 'keyid',
keyID[0])
instance = dialogs.ChooseGPGKeyDialog(_('OpenPGP Key Selection'),
_('Choose your OpenPGP key'), secret_keys, on_key_selected)
def on_use_gpg_agent_checkbutton_toggled(self, widget):
if self.current_account == gajim.ZEROCONF_ACC_NAME:
wiget_name_ext = '2'
else:
wiget_name_ext = '1'
self.on_checkbutton_toggled(widget, 'use_gpg_agent')
def on_edit_details_button1_clicked(self, widget):
if self.current_account not in gajim.interface.instances:
dialogs.ErrorDialog(_('No such account available'),
_('You must create your account before editing your personal '
'information.'))
return
# show error dialog if account is newly created (not in gajim.connections)
if self.current_account not in gajim.connections or \
gajim.connections[self.current_account].connected < 2:
dialogs.ErrorDialog(_('You are not connected to the server'),
_('Without a connection, you can not edit your personal information.'))
return
if not gajim.connections[self.current_account].vcard_supported:
dialogs.ErrorDialog(_("Your server doesn't support Vcard"),
_("Your server can't save your personal information."))
return
gajim.interface.edit_own_details(self.current_account)
def on_checkbutton_toggled(self, widget, config_name,
change_sensitivity_widgets = None, account = None):
if account:
gajim.config.set_per('accounts', account, config_name,
widget.get_active())
else:
gajim.config.set(config_name, widget.get_active())
if change_sensitivity_widgets:
for w in change_sensitivity_widgets:
w.set_sensitive(widget.get_active())
gajim.interface.save_config()
def on_merge_checkbutton_toggled(self, widget):
self.on_checkbutton_toggled(widget, 'mergeaccounts')
if len(gajim.connections) >= 2: # Do not merge accounts if only one exists
gajim.interface.roster.regroup = gajim.config.get('mergeaccounts')
else:
gajim.interface.roster.regroup = False
gajim.interface.roster.setup_and_draw_roster()
def on_enable_zeroconf_checkbutton2_toggled(self, widget):
# don't do anything if there is an account with the local name but is a
# normal account
if gajim.ZEROCONF_ACC_NAME in gajim.connections and not \
gajim.connections[gajim.ZEROCONF_ACC_NAME].is_zeroconf:
gajim.connections[gajim.ZEROCONF_ACC_NAME].dispatch('ERROR',
(_('Account Local already exists.'),
_('Please rename or remove it before enabling link-local messaging'
'.')))
return
if gajim.config.get('enable_zeroconf') and not widget.get_active():
self.xml.get_widget('zeroconf_notebook').set_sensitive(False)
# disable
gajim.interface.roster.close_all(gajim.ZEROCONF_ACC_NAME)
gajim.connections[gajim.ZEROCONF_ACC_NAME].disable_account()
del gajim.connections[gajim.ZEROCONF_ACC_NAME]
gajim.interface.save_config()
del gajim.interface.instances[gajim.ZEROCONF_ACC_NAME]
del gajim.interface.minimized_controls[gajim.ZEROCONF_ACC_NAME]
del gajim.nicks[gajim.ZEROCONF_ACC_NAME]
del gajim.block_signed_in_notifications[gajim.ZEROCONF_ACC_NAME]
del gajim.groups[gajim.ZEROCONF_ACC_NAME]
gajim.contacts.remove_account(gajim.ZEROCONF_ACC_NAME)
del gajim.gc_connected[gajim.ZEROCONF_ACC_NAME]
del gajim.automatic_rooms[gajim.ZEROCONF_ACC_NAME]
del gajim.to_be_removed[gajim.ZEROCONF_ACC_NAME]
del gajim.newly_added[gajim.ZEROCONF_ACC_NAME]
del gajim.sleeper_state[gajim.ZEROCONF_ACC_NAME]
del gajim.encrypted_chats[gajim.ZEROCONF_ACC_NAME]
del gajim.last_message_time[gajim.ZEROCONF_ACC_NAME]
del gajim.status_before_autoaway[gajim.ZEROCONF_ACC_NAME]
del gajim.transport_avatar[gajim.ZEROCONF_ACC_NAME]
del gajim.gajim_optional_features[gajim.ZEROCONF_ACC_NAME]
del gajim.caps_hash[gajim.ZEROCONF_ACC_NAME]
if len(gajim.connections) >= 2:
# Do not merge accounts if only one exists
gajim.interface.roster.regroup = gajim.config.get('mergeaccounts')
else:
gajim.interface.roster.regroup = False
gajim.interface.roster.setup_and_draw_roster()
gajim.interface.roster.set_actions_menu_needs_rebuild()
elif not gajim.config.get('enable_zeroconf') and widget.get_active():
self.xml.get_widget('zeroconf_notebook').set_sensitive(True)
# enable (will create new account if not present)
gajim.connections[gajim.ZEROCONF_ACC_NAME] = common.zeroconf.\
connection_zeroconf.ConnectionZeroconf(gajim.ZEROCONF_ACC_NAME)
if gajim.connections[gajim.ZEROCONF_ACC_NAME].gpg:
self.xml.get_widget('gpg_choose_button2').set_sensitive(True)
self.init_account_gpg()
# update variables
gajim.interface.instances[gajim.ZEROCONF_ACC_NAME] = {'infos': {},
'disco': {}, 'gc_config': {}, 'search': {}}
gajim.interface.minimized_controls[gajim.ZEROCONF_ACC_NAME] = {}
gajim.connections[gajim.ZEROCONF_ACC_NAME].connected = 0
gajim.groups[gajim.ZEROCONF_ACC_NAME] = {}
gajim.contacts.add_account(gajim.ZEROCONF_ACC_NAME)
gajim.gc_connected[gajim.ZEROCONF_ACC_NAME] = {}
gajim.automatic_rooms[gajim.ZEROCONF_ACC_NAME] = {}
gajim.newly_added[gajim.ZEROCONF_ACC_NAME] = []
gajim.to_be_removed[gajim.ZEROCONF_ACC_NAME] = []
gajim.nicks[gajim.ZEROCONF_ACC_NAME] = gajim.ZEROCONF_ACC_NAME
gajim.block_signed_in_notifications[gajim.ZEROCONF_ACC_NAME] = True
gajim.sleeper_state[gajim.ZEROCONF_ACC_NAME] = 'off'
gajim.encrypted_chats[gajim.ZEROCONF_ACC_NAME] = []
gajim.last_message_time[gajim.ZEROCONF_ACC_NAME] = {}
gajim.status_before_autoaway[gajim.ZEROCONF_ACC_NAME] = ''
gajim.transport_avatar[gajim.ZEROCONF_ACC_NAME] = {}
gajim.gajim_optional_features[gajim.ZEROCONF_ACC_NAME] = []
gajim.caps_hash[gajim.ZEROCONF_ACC_NAME] = ''
# refresh roster
if len(gajim.connections) >= 2:
# Do not merge accounts if only one exists
gajim.interface.roster.regroup = gajim.config.get('mergeaccounts')
else:
gajim.interface.roster.regroup = False
gajim.interface.roster.setup_and_draw_roster()
gajim.interface.roster.set_actions_menu_needs_rebuild()
gajim.interface.save_config()
self.on_checkbutton_toggled(widget, 'enable_zeroconf')
def on_custom_port_checkbutton2_toggled(self, widget):
self.xml.get_widget('custom_port_entry2').set_sensitive(
widget.get_active())
self.on_checkbutton_toggled(widget, 'use_custom_host',
account = self.current_account)
if not widget.get_active():
self.xml.get_widget('custom_port_entry2').set_text('5298')
def on_first_name_entry2_changed(self, widget):
if self.ignore_events:
return
name = widget.get_text().decode('utf-8')
if self.option_changed('zeroconf_first_name', name):
self.need_relogin = True
gajim.config.set_per('accounts', self.current_account,
'zeroconf_first_name', name)
def on_last_name_entry2_changed(self, widget):
if self.ignore_events:
return
name = widget.get_text().decode('utf-8')
if self.option_changed('zeroconf_last_name', name):
self.need_relogin = True
gajim.config.set_per('accounts', self.current_account,
'zeroconf_last_name', name)
def on_jabber_id_entry2_changed(self, widget):
if self.ignore_events:
return
id = widget.get_text().decode('utf-8')
if self.option_changed('zeroconf_jabber_id', id):
self.need_relogin = True
gajim.config.set_per('accounts', self.current_account,
'zeroconf_jabber_id', id)
def on_email_entry2_changed(self, widget):
if self.ignore_events:
return
email = widget.get_text().decode('utf-8')
if self.option_changed('zeroconf_email', email):
self.need_relogin = True
gajim.config.set_per('accounts', self.current_account,
'zeroconf_email', email)
class FakeDataForm(gtk.Table, object):
'''Class for forms that are in XML format <entry1>value1</entry1>
infos in a table {entry1: value1, }'''
def __init__(self, infos):
gtk.Table.__init__(self)
self.infos = infos
self.entries = {}
self._draw_table()
def _draw_table(self):
'''Draw the table'''
nbrow = 0
if 'instructions' in self.infos:
nbrow = 1
self.resize(rows = nbrow, columns = 2)
label = gtk.Label(self.infos['instructions'])
self.attach(label, 0, 2, 0, 1, 0, 0, 0, 0)
for name in self.infos.keys():
if name in ('key', 'instructions', 'x', 'registered'):
continue
if not name:
continue
nbrow = nbrow + 1
self.resize(rows = nbrow, columns = 2)
label = gtk.Label(name.capitalize() + ':')
self.attach(label, 0, 1, nbrow - 1, nbrow, 0, 0, 0, 0)
entry = gtk.Entry()
entry.set_activates_default(True)
if self.infos[name]:
entry.set_text(self.infos[name])
if name == 'password':
entry.set_visibility(False)
self.attach(entry, 1, 2, nbrow - 1, nbrow, 0, 0, 0, 0)
self.entries[name] = entry
if nbrow == 1:
entry.grab_focus()
def get_infos(self):
for name in self.entries.keys():
self.infos[name] = self.entries[name].get_text().decode('utf-8')
return self.infos
class ServiceRegistrationWindow:
'''Class for Service registration window:
Window that appears when we want to subscribe to a service
if is_form we use dataforms_widget else we use service_registarion_window'''
def __init__(self, service, infos, account, is_form):
self.service = service
self.account = account
self.is_form = is_form
self.xml = gtkgui_helpers.get_glade('service_registration_window.glade')
self.window = self.xml.get_widget('service_registration_window')
self.window.set_transient_for(gajim.interface.roster.window)
if self.is_form:
dataform = dataforms.ExtendForm(node = infos)
self.data_form_widget = dataforms_widget.DataFormWidget(dataform)
if self.data_form_widget.title:
self.window.set_title('%s - Gajim' % self.data_form_widget.title)
table = self.xml.get_widget('table')
table.attach(self.data_form_widget, 0, 2, 0, 1)
else:
if 'registered' in infos:
self.window.set_title(_('Edit %s') % service)
else:
self.window.set_title(_('Register to %s') % service)
self.data_form_widget = FakeDataForm(infos)
table = self.xml.get_widget('table')
table.attach(self.data_form_widget, 0, 2, 0, 1)
self.xml.signal_autoconnect(self)
self.window.show_all()
def on_cancel_button_clicked(self, widget):
self.window.destroy()
def on_ok_button_clicked(self, widget):
# send registration info to the core
if self.is_form:
form = self.data_form_widget.data_form
gajim.connections[self.account].register_agent(self.service,
form, True) # True is for is_form
else:
infos = self.data_form_widget.get_infos()
if 'instructions' in infos:
del infos['instructions']
if 'registered' in infos:
del infos['registered']
gajim.connections[self.account].register_agent(self.service, infos)
self.window.destroy()
class GroupchatConfigWindow:
'''GroupchatConfigWindow class'''
def __init__(self, account, room_jid, form = None):
self.account = account
self.room_jid = room_jid
self.form = form
self.remove_button = {}
self.affiliation_treeview = {}
self.start_users_dict = {} # list at the beginning
self.affiliation_labels = {'outcast': _('Ban List'),
'member': _('Member List'),
'owner': _('Owner List'),
'admin':_('Administrator List')}
self.xml = gtkgui_helpers.get_glade('data_form_window.glade', 'data_form_window')
self.window = self.xml.get_widget('data_form_window')
self.window.set_transient_for(gajim.interface.roster.window)
if self.form:
config_vbox = self.xml.get_widget('config_vbox')
dataform = dataforms.ExtendForm(node = self.form)
self.data_form_widget = dataforms_widget.DataFormWidget(dataform)
# hide scrollbar of this data_form_widget, we already have in this
# widget
sw = self.data_form_widget.xml.get_widget('single_form_scrolledwindow')
sw.set_policy(gtk.POLICY_NEVER, gtk.POLICY_NEVER)
self.data_form_widget.show()
config_vbox.pack_start(self.data_form_widget)
# Draw the edit affiliation list things
add_on_vbox = self.xml.get_widget('add_on_vbox')
for affiliation in self.affiliation_labels.keys():
self.start_users_dict[affiliation] = {}
hbox = gtk.HBox(spacing = 5)
add_on_vbox.pack_start(hbox, False)
label = gtk.Label(self.affiliation_labels[affiliation])
hbox.pack_start(label, False)
bb = gtk.HButtonBox()
bb.set_layout(gtk.BUTTONBOX_END)
bb.set_spacing(5)
hbox.pack_start(bb)
add_button = gtk.Button(stock = gtk.STOCK_ADD)
add_button.connect('clicked', self.on_add_button_clicked, affiliation)
bb.pack_start(add_button)
self.remove_button[affiliation] = gtk.Button(stock = gtk.STOCK_REMOVE)
self.remove_button[affiliation].set_sensitive(False)
self.remove_button[affiliation].connect('clicked',
self.on_remove_button_clicked, affiliation)
bb.pack_start(self.remove_button[affiliation])
liststore = gtk.ListStore(str, str, str, str) # Jid, reason, nick, role
self.affiliation_treeview[affiliation] = gtk.TreeView(liststore)
self.affiliation_treeview[affiliation].get_selection().set_mode(
gtk.SELECTION_MULTIPLE)
self.affiliation_treeview[affiliation].connect('cursor-changed',
self.on_affiliation_treeview_cursor_changed, affiliation)
renderer = gtk.CellRendererText()
col = gtk.TreeViewColumn(_('JID'), renderer)
col.add_attribute(renderer, 'text', 0)
self.affiliation_treeview[affiliation].append_column(col)
if affiliation == 'outcast':
renderer = gtk.CellRendererText()
renderer.set_property('editable', True)
renderer.connect('edited', self.on_cell_edited)
col = gtk.TreeViewColumn(_('Reason'), renderer)
col.add_attribute(renderer, 'text', 1)
self.affiliation_treeview[affiliation].append_column(col)
elif affiliation == 'member':
renderer = gtk.CellRendererText()
col = gtk.TreeViewColumn(_('Nick'), renderer)
col.add_attribute(renderer, 'text', 2)
self.affiliation_treeview[affiliation].append_column(col)
renderer = gtk.CellRendererText()
col = gtk.TreeViewColumn(_('Role'), renderer)
col.add_attribute(renderer, 'text', 3)
self.affiliation_treeview[affiliation].append_column(col)
sw = gtk.ScrolledWindow()
sw.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_NEVER)
sw.add(self.affiliation_treeview[affiliation])
add_on_vbox.pack_start(sw)
gajim.connections[self.account].get_affiliation_list(self.room_jid,
affiliation)
self.xml.signal_autoconnect(self)
self.window.show_all()
def on_cancel_button_clicked(self, widget):
self.window.destroy()
def on_cell_edited(self, cell, path, new_text):
model = self.affiliation_treeview['outcast'].get_model()
new_text = new_text.decode('utf-8')
iter = model.get_iter(path)
model[iter][1] = new_text
def on_add_button_clicked(self, widget, affiliation):
if affiliation == 'outcast':
title = _('Banning...')
#You can move '\n' before user@domain if that line is TOO BIG
prompt = _('<b>Whom do you want to ban?</b>\n\n')
elif affiliation == 'member':
title = _('Adding Member...')
prompt = _('<b>Whom do you want to make a member?</b>\n\n')
elif affiliation == 'owner':
title = _('Adding Owner...')
prompt = _('<b>Whom do you want to make an owner?</b>\n\n')
else:
title = _('Adding Administrator...')
prompt = _('<b>Whom do you want to make an administrator?</b>\n\n')
prompt += _('Can be one of the following:\n'
'1. user@domain/resource (only that resource matches).\n'
'2. user@domain (any resource matches).\n'
'3. domain/resource (only that resource matches).\n'
'4. domain (the domain itself matches, as does any user@domain,\n'
'domain/resource, or address containing a subdomain.')
def on_ok(jid):
if not jid:
return
model = self.affiliation_treeview[affiliation].get_model()
model.append((jid,'', '', ''))
instance = dialogs.InputDialog(title, prompt, ok_handler=on_ok)
def on_remove_button_clicked(self, widget, affiliation):
selection = self.affiliation_treeview[affiliation].get_selection()
model, paths = selection.get_selected_rows()
row_refs = []
for path in paths:
row_refs.append(gtk.TreeRowReference(model, path))
for row_ref in row_refs:
path = row_ref.get_path()
iter = model.get_iter(path)
jid = model[iter][0]
model.remove(iter)
self.remove_button[affiliation].set_sensitive(False)
def on_affiliation_treeview_cursor_changed(self, widget, affiliation):
self.remove_button[affiliation].set_sensitive(True)
def affiliation_list_received(self, users_dict):
'''Fill the affiliation treeview'''
for jid in users_dict:
affiliation = users_dict[jid]['affiliation']
if affiliation not in self.affiliation_labels.keys():
# Unknown affiliation or 'none' affiliation, do not show it
continue
self.start_users_dict[affiliation][jid] = users_dict[jid]
tv = self.affiliation_treeview[affiliation]
model = tv.get_model()
reason = users_dict[jid].get('reason', '')
nick = users_dict[jid].get('nick', '')
role = users_dict[jid].get('role', '')
model.append((jid, reason, nick, role))
def on_data_form_window_destroy(self, widget):
del gajim.interface.instances[self.account]['gc_config'][self.room_jid]
def on_ok_button_clicked(self, widget):
if self.form:
form = self.data_form_widget.data_form
gajim.connections[self.account].send_gc_config(self.room_jid, form)
for affiliation in self.affiliation_labels.keys():
users_dict = {}
actual_jid_list = []
model = self.affiliation_treeview[affiliation].get_model()
iter = model.get_iter_first()
# add new jid
while iter:
jid = model[iter][0].decode('utf-8')
actual_jid_list.append(jid)
if jid not in self.start_users_dict[affiliation] or \
(affiliation == 'outcast' and 'reason' in self.start_users_dict[affiliation]\
[jid] and self.start_users_dict[affiliation][jid]\
['reason'] != model[iter][1].decode('utf-8')):
users_dict[jid] = {'affiliation': affiliation}
if affiliation == 'outcast':
users_dict[jid]['reason'] = model[iter][1].decode('utf-8')
iter = model.iter_next(iter)
# remove removed one
for jid in self.start_users_dict[affiliation]:
if jid not in actual_jid_list:
users_dict[jid] = {'affiliation': 'none'}
if users_dict:
gajim.connections[self.account].send_gc_affiliation_list(
self.room_jid, users_dict)
self.window.destroy()
#---------- RemoveAccountWindow class -------------#
class RemoveAccountWindow:
'''ask for removing from gajim only or from gajim and server too
and do removing of the account given'''
def on_remove_account_window_destroy(self, widget):
if self.account in gajim.interface.instances:
del gajim.interface.instances[self.account]['remove_account']
def on_cancel_button_clicked(self, widget):
self.window.destroy()
def __init__(self, account):
self.account = account
xml = gtkgui_helpers.get_glade('remove_account_window.glade')
self.window = xml.get_widget('remove_account_window')
self.window.set_transient_for(gajim.interface.roster.window)
self.remove_and_unregister_radiobutton = xml.get_widget(
'remove_and_unregister_radiobutton')
self.window.set_title(_('Removing %s account') % self.account)
xml.signal_autoconnect(self)
self.window.show_all()
def on_remove_button_clicked(self, widget):
def remove():
if gajim.connections[self.account].connected and \
not self.remove_and_unregister_radiobutton.get_active():
# change status to offline only if we will not remove this JID from
# server
gajim.connections[self.account].change_status('offline', 'offline')
if self.remove_and_unregister_radiobutton.get_active():
if not gajim.connections[self.account].password:
def on_ok(passphrase, checked):
if passphrase == -1:
# We don't remove account cause we canceled pw window
return
gajim.connections[self.account].password = passphrase
gajim.connections[self.account].unregister_account(
self._on_remove_success)
w = dialogs.PassphraseDialog(
_('Password Required'),
_('Enter your password for account %s') % self.account,
_('Save password'), ok_handler=on_ok)
return
gajim.connections[self.account].unregister_account(
self._on_remove_success)
else:
self._on_remove_success(True)
if gajim.connections[self.account].connected:
dialog = dialogs.ConfirmationDialog(
_('Account "%s" is connected to the server') % self.account,
_('If you remove it, the connection will be lost.'),
on_response_ok=remove)
else:
remove()
def _on_remove_success(self, res):
# action of unregistration has failed, we don't remove the account
# Error message is send by connect_and_auth()
if not res:
return
# Close all opened windows
gajim.interface.roster.close_all(self.account, force = True)
gajim.connections[self.account].disconnect(on_purpose = True)
del gajim.connections[self.account]
gajim.config.del_per('accounts', self.account)
gajim.interface.save_config()
del gajim.interface.instances[self.account]
del gajim.interface.minimized_controls[self.account]
del gajim.nicks[self.account]
del gajim.block_signed_in_notifications[self.account]
del gajim.groups[self.account]
gajim.contacts.remove_account(self.account)
del gajim.gc_connected[self.account]
del gajim.automatic_rooms[self.account]
del gajim.to_be_removed[self.account]
del gajim.newly_added[self.account]
del gajim.sleeper_state[self.account]
del gajim.encrypted_chats[self.account]
del gajim.last_message_time[self.account]
del gajim.status_before_autoaway[self.account]
del gajim.transport_avatar[self.account]
del gajim.gajim_optional_features[self.account]
del gajim.caps_hash[self.account]
if len(gajim.connections) >= 2: # Do not merge accounts if only one exists
gajim.interface.roster.regroup = gajim.config.get('mergeaccounts')
else:
gajim.interface.roster.regroup = False
gajim.interface.roster.setup_and_draw_roster()
gajim.interface.roster.set_actions_menu_needs_rebuild()
if 'accounts' in gajim.interface.instances:
gajim.interface.instances['accounts'].init_accounts()
self.window.destroy()
#---------- ManageBookmarksWindow class -------------#
class ManageBookmarksWindow:
def __init__(self):
self.xml = gtkgui_helpers.get_glade('manage_bookmarks_window.glade')
self.window = self.xml.get_widget('manage_bookmarks_window')
self.window.set_transient_for(gajim.interface.roster.window)
# Account-JID, RoomName, Room-JID, Autojoin, Minimize, Passowrd, Nick,
# Show_Status
self.treestore = gtk.TreeStore(str, str, str, bool, bool, str, str, str)
self.treestore.set_sort_column_id(1, gtk.SORT_ASCENDING)
# Store bookmarks in treeview.
for account in gajim.connections:
if gajim.connections[account].connected <= 1:
continue
if gajim.connections[account].is_zeroconf:
continue
if not gajim.connections[account].private_storage_supported:
continue
iter = self.treestore.append(None, [None, account, None, None,
None, None, None, None])
for bookmark in gajim.connections[account].bookmarks:
if bookmark['name'] == '':
# No name was given for this bookmark.
# Use the first part of JID instead...
name = bookmark['jid'].split("@")[0]
bookmark['name'] = name
# make '1', '0', 'true', 'false' (or other) to True/False
autojoin = helpers.from_xs_boolean_to_python_boolean(
bookmark['autojoin'])
minimize = helpers.from_xs_boolean_to_python_boolean(
bookmark['minimize'])
print_status = bookmark.get('print_status', '')
if print_status not in ('', 'all', 'in_and_out', 'none'):
print_status = ''
self.treestore.append( iter, [
account,
bookmark['name'],
bookmark['jid'],
autojoin,
minimize,
bookmark['password'],
bookmark['nick'],
print_status ])
self.print_status_combobox = self.xml.get_widget('print_status_combobox')
model = gtk.ListStore(str, str)
self.option_list = {'': _('Default'), 'all': Q_('?print_status:All'),
'in_and_out': _('Enter and leave only'),
'none': Q_('?print_status:None')}
opts = sorted(self.option_list.keys())
for opt in opts:
model.append([self.option_list[opt], opt])
self.print_status_combobox.set_model(model)
self.print_status_combobox.set_active(1)
self.view = self.xml.get_widget('bookmarks_treeview')
self.view.set_model(self.treestore)
self.view.expand_all()
renderer = gtk.CellRendererText()
column = gtk.TreeViewColumn('Bookmarks', renderer, text=1)
self.view.append_column(column)
self.selection = self.view.get_selection()
self.selection.connect('changed', self.bookmark_selected)
#Prepare input fields
self.title_entry = self.xml.get_widget('title_entry')
self.title_entry.connect('changed', self.on_title_entry_changed)
self.nick_entry = self.xml.get_widget('nick_entry')
self.nick_entry.connect('changed', self.on_nick_entry_changed)
self.server_entry = self.xml.get_widget('server_entry')
self.server_entry.connect('changed', self.on_server_entry_changed)
self.room_entry = self.xml.get_widget('room_entry')
self.room_entry.connect('changed', self.on_room_entry_changed)
self.pass_entry = self.xml.get_widget('pass_entry')
self.pass_entry.connect('changed', self.on_pass_entry_changed)
self.autojoin_checkbutton = self.xml.get_widget('autojoin_checkbutton')
self.minimize_checkbutton = self.xml.get_widget('minimize_checkbutton')
self.xml.signal_autoconnect(self)
self.window.show_all()
def on_bookmarks_treeview_button_press_event(self, widget, event):
(model, iter) = self.selection.get_selected()
if not iter:
# Removed a bookmark before
return
if model.iter_parent(iter):
# The currently selected node is a bookmark
return not self.check_valid_bookmark()
def on_manage_bookmarks_window_destroy(self, widget, event):
del gajim.interface.instances['manage_bookmarks']
def on_add_bookmark_button_clicked(self, widget):
'''Add a new bookmark.'''
# Get the account that is currently used
# (the parent of the currently selected item)
(model, iter) = self.selection.get_selected()
if not iter: # Nothing selected, do nothing
return
parent = model.iter_parent(iter)
if parent:
# We got a bookmark selected, so we add_to the parent
add_to = parent
else:
# No parent, so we got an account -> add to this.
add_to = iter
account = model[add_to][1].decode('utf-8')
nick = gajim.nicks[account]
iter_ = self.treestore.append(add_to, [account, _('New Group Chat'), '',
False, False, '', nick, 'in_and_out'])
self.view.expand_row(model.get_path(add_to), True)
self.view.set_cursor(model.get_path(iter_))
def on_remove_bookmark_button_clicked(self, widget):
'''
Remove selected bookmark.
'''
(model, iter) = self.selection.get_selected()
if not iter: # Nothing selected
return
if not model.iter_parent(iter):
# Don't remove account iters
return
model.remove(iter)
self.clear_fields()
def check_valid_bookmark(self):
'''
Check if all neccessary fields are entered correctly.
'''
(model, iter) = self.selection.get_selected()
if not model.iter_parent(iter):
#Account data can't be changed
return
if self.server_entry.get_text().decode('utf-8') == '' or \
self.room_entry.get_text().decode('utf-8') == '':
dialogs.ErrorDialog(_('This bookmark has invalid data'),
_('Please be sure to fill out server and room fields or remove this'
' bookmark.'))
return False
return True
def on_ok_button_clicked(self, widget):
'''
Parse the treestore data into our new bookmarks array,
then send the new bookmarks to the server.
'''
(model, iter) = self.selection.get_selected()
if iter and model.iter_parent(iter):
#bookmark selected, check it
if not self.check_valid_bookmark():
return
for account in self.treestore:
account_unicode = account[1].decode('utf-8')
gajim.connections[account_unicode].bookmarks = []
for bm in account.iterchildren():
#Convert True/False/None to '1' or '0'
autojoin = unicode(int(bm[3]))
minimize = unicode(int(bm[4]))
#create the bookmark-dict
bmdict = { 'name': bm[1], 'jid': bm[2], 'autojoin': autojoin,
'minimize': minimize, 'password': bm[5], 'nick': bm[6],
'print_status': bm[7]}
gajim.connections[account_unicode].bookmarks.append(bmdict)
gajim.connections[account_unicode].store_bookmarks()
gajim.interface.roster.set_actions_menu_needs_rebuild()
self.window.destroy()
def on_cancel_button_clicked(self, widget):
self.window.destroy()
def bookmark_selected(self, selection):
'''
Fill in the bookmark's data into the fields.
'''
(model, iter) = selection.get_selected()
if not iter:
# After removing the last bookmark for one account
# this will be None, so we will just:
return
widgets = [ self.title_entry, self.nick_entry, self.room_entry,
self.server_entry, self.pass_entry, self.autojoin_checkbutton,
self.minimize_checkbutton, self.print_status_combobox]
if model.iter_parent(iter):
# make the fields sensitive
for field in widgets:
field.set_sensitive(True)
else:
# Top-level has no data (it's the account fields)
# clear fields & make them insensitive
self.clear_fields()
for field in widgets:
field.set_sensitive(False)
return
# Fill in the data for childs
self.title_entry.set_text(model[iter][1])
room_jid = model[iter][2].decode('utf-8')
try:
(room, server) = room_jid.split('@')
except ValueError:
# We just added this one
room = ''
server = ''
self.room_entry.set_text(room)
self.server_entry.set_text(server)
self.autojoin_checkbutton.set_active(model[iter][3])
self.minimize_checkbutton.set_active(model[iter][4])
# sensitive only if auto join is checked
self.minimize_checkbutton.set_sensitive(model[iter][3])
if model[iter][5] is not None:
password = model[iter][5].decode('utf-8')
else:
password = None
if password:
self.pass_entry.set_text(password)
else:
self.pass_entry.set_text('')
nick = model[iter][6]
if nick:
nick = nick.decode('utf-8')
self.nick_entry.set_text(nick)
else:
self.nick_entry.set_text('')
print_status = model[iter][7]
opts = sorted(self.option_list.keys())
self.print_status_combobox.set_active(opts.index(print_status))
def on_title_entry_changed(self, widget):
(model, iter) = self.selection.get_selected()
if iter: # After removing a bookmark, we got nothing selected
if model.iter_parent(iter):
# Don't clear the title field for account nodes
model[iter][1] = self.title_entry.get_text()
def on_nick_entry_changed(self, widget):
(model, iter) = self.selection.get_selected()
if iter:
model[iter][6] = self.nick_entry.get_text()
def on_server_entry_changed(self, widget):
(model, iter) = self.selection.get_selected()
if iter:
room_jid = self.room_entry.get_text().decode('utf-8').strip() + '@' + \
self.server_entry.get_text().decode('utf-8').strip()
model[iter][2] = room_jid.replace(' ', '')
def on_room_entry_changed(self, widget):
(model, iter) = self.selection.get_selected()
if iter:
room_jid = self.room_entry.get_text().decode('utf-8') + '@' + \
self.server_entry.get_text().decode('utf-8')
model[iter][2] = room_jid
def on_pass_entry_changed(self, widget):
(model, iter) = self.selection.get_selected()
if iter:
model[iter][5] = self.pass_entry.get_text()
def on_autojoin_checkbutton_toggled(self, widget):
(model, iter) = self.selection.get_selected()
if iter:
model[iter][3] = self.autojoin_checkbutton.get_active()
self.minimize_checkbutton.set_sensitive(model[iter][3])
def on_minimize_checkbutton_toggled(self, widget):
(model, iter) = self.selection.get_selected()
if iter:
model[iter][4] = self.minimize_checkbutton.get_active()
def on_print_status_combobox_changed(self, widget):
active = widget.get_active()
model = widget.get_model()
print_status = model[active][1]
(model2, iter) = self.selection.get_selected()
if iter:
model2[iter][7] = print_status
def clear_fields(self):
widgets = [ self.title_entry, self.nick_entry, self.room_entry,
self.server_entry, self.pass_entry ]
for field in widgets:
field.set_text('')
self.autojoin_checkbutton.set_active(False)
self.minimize_checkbutton.set_active(False)
self.print_status_combobox.set_active(1)
class AccountCreationWizardWindow:
def __init__(self):
self.xml = gtkgui_helpers.get_glade(
'account_creation_wizard_window.glade')
self.window = self.xml.get_widget('account_creation_wizard_window')
completion = gtk.EntryCompletion()
# Connect events from comboboxentry.child
server_comboboxentry = self.xml.get_widget('server_comboboxentry')
entry = server_comboboxentry.child
entry.connect('key_press_event',
self.on_server_comboboxentry_key_press_event, server_comboboxentry)
entry.set_completion(completion)
# Do the same for the other server comboboxentry
server_comboboxentry1 = self.xml.get_widget('server_comboboxentry1')
entry = server_comboboxentry1.child
entry.connect('key_press_event',
self.on_server_comboboxentry_key_press_event, server_comboboxentry1)
entry.set_completion(completion)
self.update_proxy_list()
# parse servers.xml
servers_xml = os.path.join(gajim.DATA_DIR, 'other', 'servers.xml')
servers = gtkgui_helpers.parse_server_xml(servers_xml)
servers_model = gtk.ListStore(str, int)
for server in servers:
if not server[2]['hidden']:
servers_model.append((str(server[0]), int(server[1])))
completion.set_model(servers_model)
completion.set_text_column(0)
# Put servers into comboboxentries
server_comboboxentry.set_model(servers_model)
server_comboboxentry.set_text_column(0)
server_comboboxentry1.set_model(servers_model)
server_comboboxentry1.set_text_column(0)
# Generic widgets
self.notebook = self.xml.get_widget('notebook')
self.cancel_button = self.xml.get_widget('cancel_button')
self.back_button = self.xml.get_widget('back_button')
self.forward_button = self.xml.get_widget('forward_button')
self.finish_button = self.xml.get_widget('finish_button')
self.advanced_button = self.xml.get_widget('advanced_button')
self.finish_label = self.xml.get_widget('finish_label')
self.go_online_checkbutton = self.xml.get_widget(
'go_online_checkbutton')
self.show_vcard_checkbutton = self.xml.get_widget(
'show_vcard_checkbutton')
self.progressbar = self.xml.get_widget('progressbar')
# some vars
self.update_progressbar_timeout_id = None
self.notebook.set_current_page(0)
self.xml.signal_autoconnect(self)
self.window.show_all()
def on_wizard_window_destroy(self, widget):
page = self.notebook.get_current_page()
if page in (4, 5) and self.account in gajim.connections:
# connection instance is saved in gajim.connections and we canceled the
# addition of the account
del gajim.connections[self.account]
del gajim.interface.instances['account_creation_wizard']
def on_register_server_features_button_clicked(self, widget):
helpers.launch_browser_mailer('url',
'http://www.jabber.org/network/oldnetwork.shtml')
def on_save_password_checkbutton_toggled(self, widget):
self.xml.get_widget('password_entry').grab_focus()
def on_cancel_button_clicked(self, widget):
self.window.destroy()
def on_back_button_clicked(self, widget):
cur_page = self.notebook.get_current_page()
if cur_page in (1, 2):
self.notebook.set_current_page(0)
self.back_button.set_sensitive(False)
elif cur_page == 3:
self.xml.get_widget('form_vbox').remove(self.data_form_widget)
self.notebook.set_current_page(2) # show server page
elif cur_page == 4:
if self.account in gajim.connections:
del gajim.connections[self.account]
self.notebook.set_current_page(2)
self.xml.get_widget('form_vbox').remove(self.data_form_widget)
elif cur_page == 6: # finish page
self.forward_button.show()
if self.modify:
self.notebook.set_current_page(1) # Go to parameters page
else:
self.notebook.set_current_page(2) # Go to server page
def on_forward_button_clicked(self, widget):
cur_page = self.notebook.get_current_page()
if cur_page == 0:
widget = self.xml.get_widget('use_existing_account_radiobutton')
if widget.get_active():
self.modify = True
self.notebook.set_current_page(1)
else:
self.modify = False
self.notebook.set_current_page(2)
self.back_button.set_sensitive(True)
return
elif cur_page == 1:
# We are adding an existing account
username = self.xml.get_widget('username_entry').get_text().decode(
'utf-8').strip()
if not username:
pritext = _('Invalid username')
sectext = _(
'You must provide a username to configure this account.')
dialogs.ErrorDialog(pritext, sectext)
return
server = self.xml.get_widget('server_comboboxentry').child.get_text().\
decode('utf-8').strip()
savepass = self.xml.get_widget('save_password_checkbutton').\
get_active()
password = self.xml.get_widget('password_entry').get_text().decode(
'utf-8')
jid = username + '@' + server
# check if jid is conform to RFC and stringprep it
try:
jid = helpers.parse_jid(jid)
except helpers.InvalidFormat, s:
pritext = _('Invalid Jabber ID')
dialogs.ErrorDialog(pritext, str(s))
return
already_in_jids = []
for account in gajim.connections:
j = gajim.config.get_per('accounts', account, 'name')
j += '@' + gajim.config.get_per('accounts', account, 'hostname')
already_in_jids.append(j)
if jid in already_in_jids:
pritext = _('Duplicate Jabber ID')
sectext = _('This account is already configured in Gajim.')
dialogs.ErrorDialog(pritext, sectext)
return
self.account = server
i = 1
while self.account in gajim.connections:
self.account = server + str(i)
i += 1
username, server = gajim.get_name_and_server_from_jid(jid)
self.save_account(username, server, savepass, password)
self.cancel_button.hide()
self.back_button.hide()
self.forward_button.hide()
if self.modify:
finish_text = '<big><b>%s</b></big>\n\n%s' % (
_('Account has been added successfully'),
_('You can set advanced account options by pressing the '
'Advanced button, or later by choosing the Accounts menuitem '
'under the Edit menu from the main window.'))
self.finish_label.set_markup(finish_text)
self.finish_button.show()
self.finish_button.set_property('has-default', True)
self.advanced_button.show()
self.go_online_checkbutton.show()
img = self.xml.get_widget('finish_image')
img.set_from_stock(gtk.STOCK_APPLY, gtk.ICON_SIZE_DIALOG)
self.notebook.set_current_page(6) # show finish page
self.show_vcard_checkbutton.set_active(False)
elif cur_page == 2:
# We are creating a new account
server = self.xml.get_widget('server_comboboxentry1').child.get_text()\
.decode('utf-8')
if not server:
dialogs.ErrorDialog(_('Invalid server'),
_('Please provide a server on which you want to register.'))
return
self.account = server
i = 1
while self.account in gajim.connections:
self.account = server + str(i)
i += 1
config = self.get_config('', server, '', '')
# Get advanced options
proxies_combobox = self.xml.get_widget('proxies_combobox')
active = proxies_combobox.get_active()
proxy = proxies_combobox.get_model()[active][0].decode('utf-8')
if proxy == _('None'):
proxy = ''
config['proxy'] = proxy
config['use_custom_host'] = self.xml.get_widget(
'custom_host_port_checkbutton').get_active()
custom_port = self.xml.get_widget('custom_port_entry').get_text()
try:
custom_port = int(custom_port)
except Exception:
dialogs.ErrorDialog(_('Invalid entry'),
_('Custom port must be a port number.'))
return
config['custom_port'] = custom_port
config['custom_host'] = self.xml.get_widget(
'custom_host_entry').get_text().decode('utf-8')
self.notebook.set_current_page(5) # show creating page
self.back_button.hide()
self.forward_button.hide()
self.update_progressbar_timeout_id = gobject.timeout_add(100,
self.update_progressbar)
# Get form from serveur
con = connection.Connection(self.account)
gajim.connections[self.account] = con
con.new_account(self.account, config)
elif cur_page == 3:
checked = self.xml.get_widget('ssl_checkbutton').get_active()
if checked:
hostname = gajim.connections[self.account].new_account_info[
'hostname']
# Check if cert is already in file
certs = ''
if os.path.isfile(gajim.MY_CACERTS):
f = open(gajim.MY_CACERTS)
certs = f.read()
f.close()
if self.ssl_cert in certs:
dialogs.ErrorDialog(_('Certificate Already in File'),
_('This certificate is already in file %s, so it\'s not added again.') % gajim.MY_CACERTS)
else:
f = open(gajim.MY_CACERTS, 'a')
f.write(hostname + '\n')
f.write(self.ssl_cert + '\n\n')
f.close()
gajim.connections[self.account].new_account_info[
'ssl_fingerprint_sha1'] = self.ssl_fingerprint
self.notebook.set_current_page(4) # show fom page
elif cur_page == 4:
if self.is_form:
form = self.data_form_widget.data_form
else:
form = self.data_form_widget.get_infos()
gajim.connections[self.account].send_new_account_infos(form,
self.is_form)
self.xml.get_widget('form_vbox').remove(self.data_form_widget)
self.xml.get_widget('progressbar_label').set_markup('<b>Account is being created</b>\n\nPlease wait...')
self.notebook.set_current_page(5) # show creating page
self.back_button.hide()
self.forward_button.hide()
self.update_progressbar_timeout_id = gobject.timeout_add(100,
self.update_progressbar)
def update_proxy_list(self):
proxies_combobox = self.xml.get_widget('proxies_combobox')
model = gtk.ListStore(str)
proxies_combobox.set_model(model)
l = gajim.config.get_per('proxies')
l.insert(0, _('None'))
for i in xrange(len(l)):
model.append([l[i]])
proxies_combobox.set_active(0)
def on_manage_proxies_button_clicked(self, widget):
if 'manage_proxies' in gajim.interface.instances:
gajim.interface.instances['manage_proxies'].window.present()
else:
gajim.interface.instances['manage_proxies'] = \
ManageProxiesWindow()
def on_custom_host_port_checkbutton_toggled(self, widget):
self.xml.get_widget('custom_host_hbox').set_sensitive(widget.get_active())
def update_progressbar(self):
self.progressbar.pulse()
return True # loop forever
def new_acc_connected(self, form, is_form, ssl_msg, ssl_err, ssl_cert,
ssl_fingerprint):
'''connection to server succeded, present the form to the user.'''
if self.update_progressbar_timeout_id is not None:
gobject.source_remove(self.update_progressbar_timeout_id)
self.back_button.show()
self.forward_button.show()
self.is_form = is_form
if is_form:
dataform = dataforms.ExtendForm(node = form)
self.data_form_widget = dataforms_widget.DataFormWidget(dataform)
else:
self.data_form_widget = FakeDataForm(form)
self.data_form_widget.show_all()
self.xml.get_widget('form_vbox').pack_start(self.data_form_widget)
self.ssl_fingerprint = ssl_fingerprint
self.ssl_cert = ssl_cert
if ssl_msg:
# An SSL warning occured, show it
hostname = gajim.connections[self.account].new_account_info['hostname']
self.xml.get_widget('ssl_label').set_markup(_('<b>Security Warning</b>'
'\n\nThe authenticity of the %(hostname)s SSL certificate could be '
'invalid.\nSSL Error: %(error)s\n'
'Do you still want to connect to this server?') % {
'hostname': hostname, 'error': ssl_msg})
if ssl_err in (18, 27):
text = _('Add this certificate to the list of trusted certificates.\nSHA1 fingerprint of the certificate:\n%s') % ssl_fingerprint
self.xml.get_widget('ssl_checkbutton').set_label(text)
else:
self.xml.get_widget('ssl_checkbutton').set_no_show_all(True)
self.xml.get_widget('ssl_checkbutton').hide()
self.notebook.set_current_page(3) # show SSL page
else:
self.notebook.set_current_page(4) # show form page
def new_acc_not_connected(self, reason):
'''Account creation failed: connection to server failed'''
if self.account not in gajim.connections:
return
if self.update_progressbar_timeout_id is not None:
gobject.source_remove(self.update_progressbar_timeout_id)
del gajim.connections[self.account]
self.back_button.show()
self.cancel_button.show()
self.go_online_checkbutton.hide()
self.show_vcard_checkbutton.hide()
img = self.xml.get_widget('finish_image')
img.set_from_stock(gtk.STOCK_DIALOG_ERROR, gtk.ICON_SIZE_DIALOG)
finish_text = '<big><b>%s</b></big>\n\n%s' % (
_('An error occurred during account creation') , reason)
self.finish_label.set_markup(finish_text)
self.notebook.set_current_page(6) # show finish page
def acc_is_ok(self, config):
'''Account creation succeeded'''
self.create_vars(config)
self.cancel_button.hide()
self.back_button.hide()
self.forward_button.hide()
self.finish_button.show()
self.finish_button.set_property('has-default', True)
self.advanced_button.show()
self.go_online_checkbutton.show()
self.show_vcard_checkbutton.show()
img = self.xml.get_widget('finish_image')
path_to_file = os.path.join(gajim.DATA_DIR, 'pixmaps', 'gajim.png')
img.set_from_file(path_to_file)
finish_text = '<big><b>%s</b></big>\n\n%s' % (
_('Your new account has been created successfully'),
_('You can set advanced account options by pressing the Advanced '
'button, or later by choosing the Accounts menuitem under the Edit '
'menu from the main window.'))
self.finish_label.set_markup(finish_text)
self.notebook.set_current_page(6) # show finish page
if self.update_progressbar_timeout_id is not None:
gobject.source_remove(self.update_progressbar_timeout_id)
def acc_is_not_ok(self, reason):
'''Account creation failed'''
self.back_button.show()
self.cancel_button.show()
self.go_online_checkbutton.hide()
self.show_vcard_checkbutton.hide()
del gajim.connections[self.account]
img = self.xml.get_widget('finish_image')
img.set_from_stock(gtk.STOCK_DIALOG_ERROR, gtk.ICON_SIZE_DIALOG)
finish_text = '<big><b>%s</b></big>\n\n%s' % (_('An error occurred during '
'account creation') , reason)
self.finish_label.set_markup(finish_text)
self.notebook.set_current_page(6) # show finish page
if self.update_progressbar_timeout_id is not None:
gobject.source_remove(self.update_progressbar_timeout_id)
def on_advanced_button_clicked(self, widget):
if 'accounts' in gajim.interface.instances:
gajim.interface.instances['accounts'].window.present()
else:
gajim.interface.instances['accounts'] = AccountsWindow()
gajim.interface.instances['accounts'].select_account(
self.account)
self.window.destroy()
def on_finish_button_clicked(self, widget):
go_online = self.xml.get_widget('go_online_checkbutton').get_active()
show_vcard = self.xml.get_widget('show_vcard_checkbutton').get_active()
self.window.destroy()
if show_vcard:
gajim.interface.show_vcard_when_connect.append(self.account)
if go_online:
gajim.interface.roster.send_status(self.account, 'online', '')
def on_username_entry_changed(self, widget):
self.update_jid(widget)
def on_server_comboboxentry_changed(self, widget):
self.update_jid(widget)
def on_username_entry_key_press_event(self, widget, event):
# Check for pressed @ and jump to combobox if found
if event.keyval == gtk.keysyms.at:
combobox = self.xml.get_widget('server_comboboxentry')
combobox.grab_focus()
combobox.child.set_position(-1)
return True
def on_server_comboboxentry_key_press_event(self, widget, event, combobox):
# If backspace is pressed in empty field, return to the nick entry field
backspace = event.keyval == gtk.keysyms.BackSpace
empty = len(combobox.get_active_text()) == 0
if backspace and empty and self.modify:
username_entry = self.xml.get_widget('username_entry')
username_entry.grab_focus()
username_entry.set_position(-1)
return True
def update_jid(self,widget):
username_entry = self.xml.get_widget('username_entry')
name = username_entry.get_text().decode('utf-8')
combobox = self.xml.get_widget('server_comboboxentry')
server = combobox.get_active_text()
jid_label = self.xml.get_widget('jid_label')
if len(name) == 0 or len(server) == 0:
jid_label.set_label('')
else:
string = '<b>%s@%s</b>' % (name, server)
jid_label.set_label(string)
def get_config(self, login, server, savepass, password):
config = {}
config['name'] = login
config['hostname'] = server
config['savepass'] = savepass
config['password'] = password
config['resource'] = 'Gajim'
config['priority'] = 5
config['autoconnect'] = True
config['no_log_for'] = ''
config['sync_with_global_status'] = True
config['proxy'] = ''
config['usessl'] = False
config['use_custom_host'] = False
config['custom_port'] = 0
config['custom_host'] = ''
config['keyname'] = ''
config['keyid'] = ''
return config
def save_account(self, login, server, savepass, password):
if self.account in gajim.connections:
dialogs.ErrorDialog(_('Account name is in use'),
_('You already have an account using this name.'))
return
con = connection.Connection(self.account)
con.password = password
config = self.get_config(login, server, savepass, password)
if not self.modify:
con.new_account(self.account, config)
return
gajim.connections[self.account] = con
self.create_vars(config)
def create_vars(self, config):
gajim.config.add_per('accounts', self.account)
if not config['savepass']:
config['password'] = ''
for opt in config:
gajim.config.set_per('accounts', self.account, opt, config[opt])
# update variables
gajim.interface.instances[self.account] = {'infos': {}, 'disco': {},
'gc_config': {}, 'search': {}}
gajim.interface.minimized_controls[self.account] = {}
gajim.connections[self.account].connected = 0
gajim.connections[self.account].keepalives = gajim.config.get_per(
'accounts', self.account, 'keep_alive_every_foo_secs')
gajim.groups[self.account] = {}
gajim.contacts.add_account(self.account)
gajim.gc_connected[self.account] = {}
gajim.automatic_rooms[self.account] = {}
gajim.newly_added[self.account] = []
gajim.to_be_removed[self.account] = []
gajim.nicks[self.account] = config['name']
gajim.block_signed_in_notifications[self.account] = True
gajim.sleeper_state[self.account] = 'off'
gajim.encrypted_chats[self.account] = []
gajim.last_message_time[self.account] = {}
gajim.status_before_autoaway[self.account] = ''
gajim.transport_avatar[self.account] = {}
gajim.gajim_optional_features[self.account] = []
gajim.caps_hash[self.account] = ''
# refresh accounts window
if 'accounts' in gajim.interface.instances:
gajim.interface.instances['accounts'].init_accounts()
# refresh roster
if len(gajim.connections) >= 2: # Do not merge accounts if only one exists
gajim.interface.roster.regroup = gajim.config.get('mergeaccounts')
else:
gajim.interface.roster.regroup = False
gajim.interface.roster.setup_and_draw_roster()
gajim.interface.roster.set_actions_menu_needs_rebuild()
gajim.interface.save_config()
class ManagePEPServicesWindow:
def __init__(self, account):
self.xml = gtkgui_helpers.get_glade('manage_pep_services_window.glade')
self.window = self.xml.get_widget('manage_pep_services_window')
self.window.set_transient_for(gajim.interface.roster.window)
self.xml.get_widget('configure_button').set_sensitive(False)
self.xml.get_widget('delete_button').set_sensitive(False)
self.xml.signal_autoconnect(self)
self.account = account
self.init_services()
self.xml.get_widget('services_treeview').get_selection().connect(
'changed', self.on_services_selection_changed)
self.window.show_all()
def on_manage_pep_services_window_destroy(self, widget):
'''close window'''
del gajim.interface.instances[self.account]['pep_services']
def on_close_button_clicked(self, widget):
self.window.destroy()
def on_services_selection_changed(self, sel):
self.xml.get_widget('configure_button').set_sensitive(True)
self.xml.get_widget('delete_button').set_sensitive(True)
def init_services(self):
self.treeview = self.xml.get_widget('services_treeview')
# service, access_model, group
self.treestore = gtk.ListStore(str)
self.treeview.set_model(self.treestore)
col = gtk.TreeViewColumn('Service')
self.treeview.append_column(col)
cellrenderer_text = gtk.CellRendererText()
col.pack_start(cellrenderer_text)
col.add_attribute(cellrenderer_text, 'text', 0)
our_jid = gajim.get_jid_from_account(self.account)
gajim.connections[self.account].discoverItems(our_jid)
def items_received(self, items):
our_jid = gajim.get_jid_from_account(self.account)
for item in items:
if 'jid' in item and item['jid'] == our_jid and 'node' in item:
self.treestore.append([item['node']])
def node_removed(self, node):
model = self.treeview.get_model()
iter = model.get_iter_root()
while iter:
if model[iter][0] == node:
model.remove(iter)
break
iter = model.get_iter_next(iter)
def on_delete_button_clicked(self, widget):
selection = self.treeview.get_selection()
if not selection:
return
model, iter = selection.get_selected()
node = model[iter][0]
our_jid = gajim.get_jid_from_account(self.account)
gajim.connections[self.account].send_pb_delete(our_jid, node)
def on_configure_button_clicked(self, widget):
selection = self.treeview.get_selection()
if not selection:
return
model, iter = selection.get_selected()
node = model[iter][0]
our_jid = gajim.get_jid_from_account(self.account)
gajim.connections[self.account].request_pb_configuration(our_jid, node)
def config(self, node, form):
def on_ok(form, node):
form.type = 'submit'
our_jid = gajim.get_jid_from_account(self.account)
gajim.connections[self.account].send_pb_configure(our_jid, node, form)
window = dialogs.DataFormWindow(form, (on_ok, node))
title = "Configure %s" % node
window.set_title(title)
window.show_all()
# vim: se ts=3:
|