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
|
/*
* This file is part of TelepathyQt4
*
* Copyright (C) 2008 Collabora Ltd. <http://www.collabora.co.uk/>
* Copyright (C) 2008 Nokia Corporation
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <TelepathyQt4/Account>
#include "TelepathyQt4/_gen/account.moc.hpp"
#include "TelepathyQt4/_gen/cli-account.moc.hpp"
#include "TelepathyQt4/_gen/cli-account-body.hpp"
#include "TelepathyQt4/debug-internal.h"
#include "TelepathyQt4/connection-internal.h"
#include <TelepathyQt4/AccountManager>
#include <TelepathyQt4/Channel>
#include <TelepathyQt4/ConnectionCapabilities>
#include <TelepathyQt4/ConnectionManager>
#include <TelepathyQt4/PendingChannelRequest>
#include <TelepathyQt4/PendingFailure>
#include <TelepathyQt4/PendingReady>
#include <TelepathyQt4/PendingStringList>
#include <TelepathyQt4/PendingVoid>
#include <TelepathyQt4/Profile>
#include <TelepathyQt4/ReferencedHandles>
#include <TelepathyQt4/Constants>
#include <TelepathyQt4/Debug>
#include <QQueue>
#include <QRegExp>
#include <QTimer>
#include <string.h>
namespace Tp
{
struct TELEPATHY_QT4_NO_EXPORT Account::Private
{
Private(Account *parent, const ConnectionFactoryConstPtr &connFactory,
const ChannelFactoryConstPtr &chanFactory,
const ContactFactoryConstPtr &contactFactory);
~Private();
void init();
static void introspectMain(Private *self);
static void introspectAvatar(Private *self);
static void introspectProtocolInfo(Private *self);
static void introspectCapabilities(Private *self);
void updateProperties(const QVariantMap &props);
void retrieveAvatar();
bool processConnQueue();
bool checkCapabilitiesChanged(bool profileChanged);
void addConferenceRequestCommonParameters(
const char *channelType,
HandleType targetHandleType,
const QList<ChannelPtr> &channels,
QVariantMap &request);
void addConferenceRequestParameters(
const char *channelType,
HandleType targetHandleType,
const QList<ChannelPtr> &channels,
const QStringList &initialInviteeContactsIdentifiers,
QVariantMap &request);
void addConferenceRequestParameters(
const char *channelType,
HandleType targetHandleType,
const QList<ChannelPtr> &channels,
const QList<ContactPtr> &initialInviteeContacts,
QVariantMap &request);
QString connectionObjectPath() const;
// Public object
Account *parent;
// Factories
ConnectionFactoryConstPtr connFactory;
ChannelFactoryConstPtr chanFactory;
ContactFactoryConstPtr contactFactory;
// Instance of generated interface class
Client::AccountInterface *baseInterface;
// Mandatory properties interface proxy
Client::DBus::PropertiesInterface *properties;
ReadinessHelper *readinessHelper;
// Introspection
QVariantMap parameters;
bool valid;
bool enabled;
bool connectsAutomatically;
bool hasBeenOnline;
bool changingPresence;
QString cmName;
QString protocolName;
QString serviceName;
ProfilePtr profile;
QString displayName;
QString nickname;
QString iconName;
QQueue<QString> connObjPathQueue;
ConnectionPtr connection;
bool mayFinishCore, coreFinished;
QString normalizedName;
Avatar avatar;
ConnectionManagerPtr cm;
ConnectionStatus connectionStatus;
ConnectionStatusReason connectionStatusReason;
QString connectionError;
Connection::ErrorDetails connectionErrorDetails;
Presence automaticPresence;
Presence currentPresence;
Presence requestedPresence;
bool usingConnectionCaps;
ConnectionCapabilities customCaps;
};
Account::Private::Private(Account *parent, const ConnectionFactoryConstPtr &connFactory,
const ChannelFactoryConstPtr &chanFactory, const ContactFactoryConstPtr &contactFactory)
: parent(parent),
connFactory(connFactory),
chanFactory(chanFactory),
contactFactory(contactFactory),
baseInterface(new Client::AccountInterface(parent)),
properties(parent->interface<Client::DBus::PropertiesInterface>()),
readinessHelper(parent->readinessHelper()),
valid(false),
enabled(false),
connectsAutomatically(false),
hasBeenOnline(false),
changingPresence(false),
mayFinishCore(false),
coreFinished(false),
connectionStatus(ConnectionStatusDisconnected),
connectionStatusReason(ConnectionStatusReasonNoneSpecified),
usingConnectionCaps(false)
{
// FIXME: QRegExp probably isn't the most efficient possible way to parse
// this :-)
QRegExp rx(QLatin1String("^" TELEPATHY_ACCOUNT_OBJECT_PATH_BASE
"/([_A-Za-z][_A-Za-z0-9]*)" // cap(1) is the CM
"/([_A-Za-z][_A-Za-z0-9]*)" // cap(2) is the protocol
"/([_A-Za-z][_A-Za-z0-9]*)" // account-specific part
));
if (rx.exactMatch(parent->objectPath())) {
cmName = rx.cap(1);
protocolName = rx.cap(2);
} else {
warning() << "Account object path is not spec-compliant, "
"trying again with a different account-specific part check";
rx = QRegExp(QLatin1String("^" TELEPATHY_ACCOUNT_OBJECT_PATH_BASE
"/([_A-Za-z][_A-Za-z0-9]*)" // cap(1) is the CM
"/([_A-Za-z][_A-Za-z0-9]*)" // cap(2) is the protocol
"/([_A-Za-z0-9]*)" // account-specific part
));
if (rx.exactMatch(parent->objectPath())) {
cmName = rx.cap(1);
protocolName = rx.cap(2);
} else {
warning() << "Not a valid Account object path:" <<
parent->objectPath();
}
}
ReadinessHelper::Introspectables introspectables;
// As Account does not have predefined statuses let's simulate one (0)
ReadinessHelper::Introspectable introspectableCore(
QSet<uint>() << 0, // makesSenseForStatuses
Features(), // dependsOnFeatures
QStringList(), // dependsOnInterfaces
(ReadinessHelper::IntrospectFunc) &Private::introspectMain,
this);
introspectables[FeatureCore] = introspectableCore;
ReadinessHelper::Introspectable introspectableAvatar(
QSet<uint>() << 0, // makesSenseForStatuses
Features() << FeatureCore, // dependsOnFeatures (core)
QStringList() << QLatin1String(TELEPATHY_INTERFACE_ACCOUNT_INTERFACE_AVATAR), // dependsOnInterfaces
(ReadinessHelper::IntrospectFunc) &Private::introspectAvatar,
this);
introspectables[FeatureAvatar] = introspectableAvatar;
ReadinessHelper::Introspectable introspectableProtocolInfo(
QSet<uint>() << 0, // makesSenseForStatuses
Features() << FeatureCore, // dependsOnFeatures (core)
QStringList(), // dependsOnInterfaces
(ReadinessHelper::IntrospectFunc) &Private::introspectProtocolInfo,
this);
introspectables[FeatureProtocolInfo] = introspectableProtocolInfo;
ReadinessHelper::Introspectable introspectableCapabilities(
QSet<uint>() << 0, // makesSenseForStatuses
Features() << FeatureCore << FeatureProtocolInfo << FeatureProfile, // dependsOnFeatures
QStringList(), // dependsOnInterfaces
(ReadinessHelper::IntrospectFunc) &Private::introspectCapabilities,
this);
introspectables[FeatureCapabilities] = introspectableCapabilities;
readinessHelper->addIntrospectables(introspectables);
if (connFactory->dbusConnection().name() != parent->dbusConnection().name()) {
warning() << " The D-Bus connection in the conn factory is not the proxy connection for"
<< parent->objectPath();
}
if (chanFactory->dbusConnection().name() != parent->dbusConnection().name()) {
warning() << " The D-Bus connection in the channel factory is not the proxy connection for"
<< parent->objectPath();
}
init();
}
Account::Private::~Private()
{
}
bool Account::Private::checkCapabilitiesChanged(bool profileChanged)
{
/* when the capabilities changed:
*
* - We were using the connection caps and now we don't have connection or
* the connection we have is not connected (changed to CM caps)
* - We were using the CM caps and now we have a connected connection
* (changed to new connection caps)
*/
bool changed = false;
if (usingConnectionCaps &&
(parent->connection().isNull() ||
connection->status() != ConnectionStatusConnected)) {
usingConnectionCaps = false;
changed = true;
} else if (!usingConnectionCaps &&
!parent->connection().isNull() &&
connection->status() == ConnectionStatusConnected) {
usingConnectionCaps = true;
changed = true;
} else if (!usingConnectionCaps && profileChanged) {
changed = true;
}
if (changed && parent->isReady(FeatureCapabilities)) {
emit parent->capabilitiesChanged(parent->capabilities());
}
return changed;
}
void Account::Private::addConferenceRequestCommonParameters(
const char *channelType,
HandleType targetHandleType,
const QList<ChannelPtr> &channels,
QVariantMap &request)
{
request.insert(QLatin1String(TELEPATHY_INTERFACE_CHANNEL ".ChannelType"),
QLatin1String(channelType));
if (targetHandleType != HandleTypeNone) {
request.insert(QLatin1String(TELEPATHY_INTERFACE_CHANNEL ".TargetHandleType"),
(uint) targetHandleType);
}
ObjectPathList objectPaths;
foreach (const ChannelPtr &channel, channels) {
objectPaths << QDBusObjectPath(channel->objectPath());
}
request.insert(TP_QT4_IFACE_CHANNEL_INTERFACE_CONFERENCE + QLatin1String(".InitialChannels"),
qVariantFromValue(objectPaths));
}
void Account::Private::addConferenceRequestParameters(
const char *channelType,
HandleType targetHandleType,
const QList<ChannelPtr> &channels,
const QStringList &initialInviteeContactsIdentifiers,
QVariantMap &request)
{
addConferenceRequestCommonParameters(channelType, targetHandleType,
channels, request);
if (!initialInviteeContactsIdentifiers.isEmpty()) {
request.insert(TP_QT4_IFACE_CHANNEL_INTERFACE_CONFERENCE + QLatin1String(".InitialInviteeIDs"),
initialInviteeContactsIdentifiers);
}
}
void Account::Private::addConferenceRequestParameters(
const char *channelType,
HandleType targetHandleType,
const QList<ChannelPtr> &channels,
const QList<ContactPtr> &initialInviteeContacts,
QVariantMap &request)
{
addConferenceRequestCommonParameters(channelType, targetHandleType,
channels, request);
if (!initialInviteeContacts.isEmpty()) {
UIntList handles;
foreach (const ContactPtr &contact, initialInviteeContacts) {
if (!contact) {
continue;
}
handles << contact->handle()[0];
}
if (!handles.isEmpty()) {
request.insert(TP_QT4_IFACE_CHANNEL_INTERFACE_CONFERENCE +
QLatin1String(".InitialInviteeHandles"),
qVariantFromValue(handles));
}
}
}
QString Account::Private::connectionObjectPath() const
{
return !connection.isNull() ? connection->objectPath() : QString();
}
/**
* \class Account
* \ingroup clientaccount
* \headerfile TelepathyQt4/account.h <TelepathyQt4/Account>
*
* \brief The Account class provides an object representing a Telepathy account.
*
* Account adds the following features compared to using
* Client::AccountManagerInterface directly:
* <ul>
* <li>Status tracking</li>
* <li>Getting the list of supported interfaces automatically</li>
* </ul>
*
* The remote object accessor functions on this object (isValidAccount(),
* isEnabled(), and so on) don't make any D-Bus calls; instead, they return/use
* values cached from a previous introspection run. The introspection process
* populates their values in the most efficient way possible based on what the
* service implements. Their return value is mostly undefined until the
* introspection process is completed, i.e. isReady() returns true. See the
* individual accessor descriptions for more details.
*
* Signals are emitted to indicate that properties have changed, for example
* displayNameChanged(), iconNameChanged(), etc.
*
* Convenience methods to create channels using the channel dispatcher such as
* ensureTextChat(), createFileTransfer() are provided.
*
* To avoid unnecessary D-Bus traffic, some methods only return valid
* information after a specific feature has been enabled by calling
* becomeReady() with the desired set of features as an argument, and waiting
* for the resulting PendingOperation to finish. For instance, to retrieve the
* account protocol information, it is necessary to call becomeReady() with
* Account::FeatureProtocolInfo included in the argument.
* The required features are documented by each method.
*
* If the account is deleted from the AccountManager, this object
* will not be deleted automatically; however, it will emit invalidated()
* with error code #TELEPATHY_QT4_ERROR_OBJECT_REMOVED and will cease to
* be useful.
*
* \section account_usage_sec Usage
*
* \subsection account_create_sec Creating an account object
*
* The easiest way to create account objects is through AccountManager. One can
* just use the AccountManager convenience methods such as
* AccountManager::validAccounts() to get a list of account objects representing
* valid accounts.
*
* If you already know the object path, you can just call create().
* For example:
*
* \code AccountPtr acc = Account::create(busName, objectPath); \endcode
*
* An AccountPtr object is returned, which will automatically keep
* track of object lifetime.
*
* You can also provide a D-Bus connection as a QDBusConnection:
*
* \code
*
* AccountPtr acc = Account::create(QDBusConnection::sessionBus(),
* busName, objectPath);
*
* \endcode
*
* \subsection account_ready_sec Making account ready to use
*
* An Account object needs to become ready before usage, meaning that the
* introspection process finished and the object accessors can be used.
*
* To make the object ready, use becomeReady() and wait for the
* PendingOperation::finished() signal to be emitted.
*
* \code
*
* class MyClass : public QObject
* {
* QOBJECT
*
* public:
* MyClass(QObject *parent = 0);
* ~MyClass() { }
*
* private Q_SLOTS:
* void onAccountReady(Tp::PendingOperation*);
*
* private:
* AccountPtr acc;
* };
*
* MyClass::MyClass(const QString &busName, const QString &objectPath,
* QObject *parent)
* : QObject(parent)
* acc(Account::create(busName, objectPath))
* {
* connect(acc->becomeReady(),
* SIGNAL(finished(Tp::PendingOperation*)),
* SLOT(onAccountReady(Tp::PendingOperation*)));
* }
*
* void MyClass::onAccountReady(Tp::PendingOperation *op)
* {
* if (op->isError()) {
* qWarning() << "Account cannot become ready:" <<
* op->errorName() << "-" << op->errorMessage();
* return;
* }
*
* // Account is now ready
* qDebug() << "Display name:" << acc->displayName();
* }
*
* \endcode
*
* See \ref async_model, \ref shared_ptr
*/
/**
* Feature representing the core that needs to become ready to make the Account
* object usable.
*
* Note that this feature must be enabled in order to use most Account methods.
* See specific methods documentation for more details.
*
* When calling isReady(), becomeReady(), this feature is implicitly added
* to the requested features.
*/
const Feature Account::FeatureCore = Feature(QLatin1String(Account::staticMetaObject.className()), 0, true);
/**
* Feature used in order to access account avatar info.
*
* See avatar specific methods' documentation for more details.
*/
const Feature Account::FeatureAvatar = Feature(QLatin1String(Account::staticMetaObject.className()), 1);
/**
* Feature used in order to access account protocol info.
*
* See protocol info specific methods' documentation for more details.
*/
const Feature Account::FeatureProtocolInfo = Feature(QLatin1String(Account::staticMetaObject.className()), 2);
/**
* Feature used in order to access account capabilities.
*
* This feature will enable FeatureProtocolInfo and FeatureProfile.
*
* See capabilities specific methods' documentation for more details.
*/
const Feature Account::FeatureCapabilities = Feature(QLatin1String(Account::staticMetaObject.className()), 3);
/**
* Feature used in order to access account profile info.
*
* See profile specific methods' documentation for more details.
*/
const Feature Account::FeatureProfile = FeatureProtocolInfo;
// FeatureProfile is the same as FeatureProtocolInfo for now, as it only needs
// the protocol info, cm name and protocol name to build a fake profile. Make it
// a full-featured feature if needed later.
/**
* Create a new Account object using QDBusConnection::sessionBus() and the given factories.
*
* A warning is printed if the factories are not for QDBusConnection::sessionBus().
*
* \param busName The account well-known bus name (sometimes called a "service
* name"). This is usually the same as the account manager
* bus name #TELEPATHY_ACCOUNT_MANAGER_BUS_NAME.
* \param objectPath The account object path.
* \param connectionFactory The connection factory to use.
* \param channelFactory The channel factory to use.
* \param contactFactory The contact factory to use.
* \return An AccountPtr object pointing to the newly created Account object.
*/
AccountPtr Account::create(const QString &busName, const QString &objectPath,
const ConnectionFactoryConstPtr &connectionFactory,
const ChannelFactoryConstPtr &channelFactory,
const ContactFactoryConstPtr &contactFactory)
{
return AccountPtr(new Account(QDBusConnection::sessionBus(), busName, objectPath,
connectionFactory, channelFactory, contactFactory, Account::FeatureCore));
}
/**
* Create a new Account object using the given \a bus and the given factories.
*
* A warning is printed if the factories are not for \a bus.
*
* \param bus QDBusConnection to use.
* \param busName The account well-known bus name (sometimes called a "service
* name"). This is usually the same as the account manager
* bus name #TELEPATHY_ACCOUNT_MANAGER_BUS_NAME.
* \param objectPath The account object path.
* \param connectionFactory The connection factory to use.
* \param channelFactory The channel factory to use.
* \param contactFactory The contact factory to use.
* \return An AccountPtr object pointing to the newly created Account object.
*/
AccountPtr Account::create(const QDBusConnection &bus,
const QString &busName, const QString &objectPath,
const ConnectionFactoryConstPtr &connectionFactory,
const ChannelFactoryConstPtr &channelFactory,
const ContactFactoryConstPtr &contactFactory)
{
return AccountPtr(new Account(bus, busName, objectPath, connectionFactory, channelFactory,
contactFactory, Account::FeatureCore));
}
/**
* Construct a new Account object using the given \a bus and the given factories.
*
* A warning is printed if the factories are not for \a bus.
*
* \param bus QDBusConnection to use.
* \param busName The account well-known bus name (sometimes called a "service
* name"). This is usually the same as the account manager
* bus name #TELEPATHY_ACCOUNT_MANAGER_BUS_NAME.
* \param objectPath The account object path.
* \param connectionFactory The connection factory to use.
* \param channelFactory The channel factory to use.
* \param contactFactory The contact factory to use.
* \param coreFeature The core feature of the Account subclass. The corresponding introspectable
* should depend on Account::FeatureCore.
*/
Account::Account(const QDBusConnection &bus,
const QString &busName, const QString &objectPath,
const ConnectionFactoryConstPtr &connectionFactory,
const ChannelFactoryConstPtr &channelFactory,
const ContactFactoryConstPtr &contactFactory,
const Feature &coreFeature)
: StatelessDBusProxy(bus, busName, objectPath, coreFeature),
OptionalInterfaceFactory<Account>(this),
mPriv(new Private(this, connectionFactory, channelFactory, contactFactory))
{
}
/**
* Class destructor.
*/
Account::~Account()
{
delete mPriv;
}
/**
* Get the connection factory used by this account.
*
* Only read access is provided. This allows constructing object instances and examining the object
* construction settings, but not changing settings. Allowing changes would lead to tricky
* situations where objects constructed at different times by the account would have unpredictably
* different construction settings (eg. subclass).
*
* \return Read-only pointer to the factory.
*/
ConnectionFactoryConstPtr Account::connectionFactory() const
{
return mPriv->connFactory;
}
/**
* Get the channel factory used by this account.
*
* Only read access is provided. This allows constructing object instances and examining the object
* construction settings, but not changing settings. Allowing changes would lead to tricky
* situations where objects constructed at different times by the account would have unpredictably
* different construction settings (eg. subclass).
*
* \return Read-only pointer to the factory.
*/
ChannelFactoryConstPtr Account::channelFactory() const
{
return mPriv->chanFactory;
}
/**
* Get the contact factory used by this account.
*
* Only read access is provided. This allows constructing object instances and examining the object
* construction settings, but not changing settings. Allowing changes would lead to tricky
* situations where objects constructed at different times by the account would have unpredictably
* different construction settings (eg. subclass).
*
* \return Read-only pointer to the factory.
*/
ContactFactoryConstPtr Account::contactFactory() const
{
return mPriv->contactFactory;
}
/**
* Return whether this is a valid account.
*
* If true, this account is considered by the account manager to be complete
* and usable. If false, user action is required to make it usable, and it will
* never attempt to connect (for instance, this might be caused by the absence
* of a required parameter).
*
* This method requires Account::FeatureCore to be enabled.
*
* \return \c true if the account is valid, \c false otherwise.
* \sa validityChanged()
*/
bool Account::isValidAccount() const
{
return mPriv->valid;
}
/**
* Return whether this account is enabled.
*
* Gives the users the possibility to prevent an account from
* being used. This flag does not change the validity of the account.
*
* This method requires Account::FeatureCore to be enabled.
*
* \return \c true if the account is enabled, \c false otherwise.
* \sa stateChanged()
*/
bool Account::isEnabled() const
{
return mPriv->enabled;
}
/**
* Set whether this account should be enabled or disabled.
*
* \param value Whether this account should be enabled or disabled.
* \return A PendingOperation which will emit PendingOperation::finished
* when the call has finished.
* \sa stateChanged()
*/
PendingOperation *Account::setEnabled(bool value)
{
return new PendingVoid(
mPriv->properties->Set(
QLatin1String(TELEPATHY_INTERFACE_ACCOUNT),
QLatin1String("Enabled"),
QDBusVariant(value)),
AccountPtr(this));
}
/**
* Return the connection manager name of this account.
*
* This method requires Account::FeatureCore to be enabled.
*
* \return The connection manager name of this account.
*/
QString Account::cmName() const
{
return mPriv->cmName;
}
/**
* Return the protocol name of this account.
*
* This method requires Account::FeatureCore to be enabled.
*
* \return The protocol name of this account.
*/
QString Account::protocolName() const
{
return mPriv->protocolName;
}
/**
* Return the service name of this account.
*
* Note that this method will fallback to protocolName() if service name
* is not known.
*
* This method requires Account::FeatureCore to be enabled.
*
* \return The service name of this account.
* \sa serviceNameChanged(), protocolName()
*/
QString Account::serviceName() const
{
if (mPriv->serviceName.isEmpty()) {
return mPriv->protocolName;
}
return mPriv->serviceName;
}
/**
* Set the service name of this account.
*
* \param value The service name of this account.
* \return A PendingOperation which will emit PendingOperation::finished
* when the call has finished.
* \sa serviceNameChanged()
*/
PendingOperation *Account::setServiceName(const QString &value)
{
return new PendingVoid(
mPriv->properties->Set(
QLatin1String(TELEPATHY_INTERFACE_ACCOUNT),
QLatin1String("Service"),
QDBusVariant(value)),
AccountPtr(this));
}
/**
* Return the profile used for this account.
*
* Note that if a profile for serviceName() is not available, a fake profile
* (Profile::isFake() will return \c true) will be returned in case protocolInfo() is valid.
*
* The fake profile will contain the following info:
* - Profile::type() will return "IM"
* - Profile::provider() will return an empty string
* - Profile::serviceName() will return cmName()-serviceName()
* - Profile::name() and Profile::protocolName() will return protocolName()
* - Profile::iconName() will return "im-protocolName()"
* - Profile::cmName() will return cmName()
* - Profile::parameters() will return a list matching CM default parameters for protocol with name
* protocolName()
* - Profile::presences() will return an empty list and
* Profile::allowOtherPresences() will return \c true, meaning that CM
* presences should be used
* - Profile::unsupportedChannelClassSpecs() will return an empty list
*
* This method requires Account::FeatureProfile to be enabled.
*
* \return The profile for this account.
* \sa profileChanged()
*/
ProfilePtr Account::profile() const
{
if (!isReady(FeatureProfile)) {
return ProfilePtr();
}
if (!mPriv->profile) {
mPriv->profile = Profile::createForServiceName(serviceName());
if (!mPriv->profile->isValid()) {
if (protocolInfo().isValid()) {
mPriv->profile = ProfilePtr(new Profile(
QString(QLatin1String("%1-%2")).arg(mPriv->cmName).arg(serviceName()),
mPriv->cmName,
mPriv->protocolName,
protocolInfo()));
} else {
warning() << "Cannot create profile as neither a .profile is installed for service" <<
serviceName() << "nor protocol info can be retrieved";
}
}
}
return mPriv->profile;
}
/**
* Return the display name of this account.
*
* This method requires Account::FeatureCore to be enabled.
*
* \return The display name of this account.
* \sa displayNameChanged()
*/
QString Account::displayName() const
{
return mPriv->displayName;
}
/**
* Set the display name of this account.
*
* \param value The display name of this account.
* \return A PendingOperation which will emit PendingOperation::finished
* when the call has finished.
* \sa displayNameChanged()
*/
PendingOperation *Account::setDisplayName(const QString &value)
{
return new PendingVoid(
mPriv->properties->Set(
QLatin1String(TELEPATHY_INTERFACE_ACCOUNT),
QLatin1String("DisplayName"),
QDBusVariant(value)),
AccountPtr(this));
}
/**
* Return the icon name of this account.
*
* This method requires Account::FeatureCore to be enabled.
*
* If the account has no icon, and Account::FeatureProfile is enabled, the icon from the result of
* profile() will be used.
*
* If neither the account nor the profile has an icon, and Account::FeatureProtocolInfo is
* enabled, the icon from protocolInfo() will be used if set.
*
* As a last resort, "im-" + protocolName() will be returned.
*
* This matches the fallbacks recommended by the Telepathy specification.
*
* \return The icon name of this account.
* \sa iconNameChanged()
*/
QString Account::iconName() const
{
if (mPriv->iconName.isEmpty()) {
if (isReady(FeatureProfile) && !profile().isNull()) {
QString iconName = profile()->iconName();
if (!iconName.isEmpty()) {
return iconName;
}
}
if (isReady(FeatureProtocolInfo) && protocolInfo().isValid()) {
return protocolInfo().iconName();
}
return QString(QLatin1String("im-%1")).arg(protocolName());
}
return mPriv->iconName;
}
/**
* Set the icon name of this account.
*
* \param value The icon name of this account.
* \return A PendingOperation which will emit PendingOperation::finished
* when the call has finished.
* \sa iconNameChanged()
*/
PendingOperation *Account::setIconName(const QString &value)
{
return new PendingVoid(
mPriv->properties->Set(
QLatin1String(TELEPATHY_INTERFACE_ACCOUNT),
QLatin1String("Icon"),
QDBusVariant(value)),
AccountPtr(this));
}
/**
* Return the nickname of this account.
*
* This method requires Account::FeatureCore to be enabled.
*
* \return The nickname of this account.
* \sa nicknameChanged()
*/
QString Account::nickname() const
{
return mPriv->nickname;
}
/**
* Set the nickname of this account.
*
* \param value The nickname of this account.
* \return A PendingOperation which will emit PendingOperation::finished
* when the call has finished.
* \sa nicknameChanged()
*/
PendingOperation *Account::setNickname(const QString &value)
{
return new PendingVoid(
mPriv->properties->Set(
QLatin1String(TELEPATHY_INTERFACE_ACCOUNT),
QLatin1String("Nickname"),
QDBusVariant(value)),
AccountPtr(this));
}
/**
* Return the avatar of this account.
*
* This method requires Account::FeatureAvatar to be enabled.
*
* \return The avatar of this account.
* \sa avatarChanged()
*/
const Avatar &Account::avatar() const
{
if (!isReady(Features() << FeatureAvatar)) {
warning() << "Trying to retrieve avatar from account, but "
"avatar is not supported or was not requested. "
"Use becomeReady(FeatureAvatar)";
}
return mPriv->avatar;
}
/**
* Set avatar of this account.
*
* \param avatar The avatar of this account.
* \return A PendingOperation which will emit PendingOperation::finished
* when the call has finished.
* \sa avatarChanged()
*/
PendingOperation *Account::setAvatar(const Avatar &avatar)
{
if (!interfaces().contains(QLatin1String(TELEPATHY_INTERFACE_ACCOUNT_INTERFACE_AVATAR))) {
return new PendingFailure(
QLatin1String(TELEPATHY_ERROR_NOT_IMPLEMENTED),
QLatin1String("Account does not support Avatar"),
AccountPtr(this));
}
return new PendingVoid(
mPriv->properties->Set(
QLatin1String(TELEPATHY_INTERFACE_ACCOUNT_INTERFACE_AVATAR),
QLatin1String("Avatar"),
QDBusVariant(QVariant::fromValue(avatar))),
AccountPtr(this));
}
/**
* Return the parameters of this account.
*
* This method requires Account::FeatureCore to be enabled.
*
* \return The parameters of this account.
* \sa parametersChanged()
*/
QVariantMap Account::parameters() const
{
return mPriv->parameters;
}
/**
* Update this account parameters.
*
* On success, the pending operation returned by this method will produce a
* list of strings, which are the names of parameters whose changes will not
* take effect until the account is disconnected and reconnected (for instance
* by calling reconnect()).
*
* \param set Parameters to set.
* \param unset Parameters to unset.
* \return A PendingStringList which will emit PendingStringList::finished
* when the call has finished
* \sa parametersChanged(), reconnect()
*/
PendingStringList *Account::updateParameters(const QVariantMap &set,
const QStringList &unset)
{
return new PendingStringList(
baseInterface()->UpdateParameters(set, unset),
AccountPtr(this));
}
/**
* Return the protocol info of this account protocol.
*
* This method requires Account::FeatureProtocolInfo to be enabled.
*
* \return The protocol info of this account protocol.
*/
ProtocolInfo Account::protocolInfo() const
{
if (!isReady(Features() << FeatureProtocolInfo)) {
warning() << "Trying to retrieve protocol info from account, but "
"protocol info is not supported or was not requested. "
"Use becomeReady(FeatureProtocolInfo)";
return ProtocolInfo();
}
return mPriv->cm->protocol(mPriv->protocolName);
}
/**
* Return the capabilities for this account.
*
* This method requires Account::FeatureCapabilities to be enabled.
*
* Note that this method will return the connection() capabilities if the
* account is online and ready. If the account is disconnected, it will fallback
* to return the subtraction of the protocolInfo() capabilities and the profile unsupported
* capabilities.
*
* \return The capabilities for this account.
*/
ConnectionCapabilities Account::capabilities() const
{
if (!isReady(FeatureCapabilities)) {
warning() << "Trying to retrieve capabilities from account, but "
"FeatureCapabilities was not requested. "
"Use becomeReady(FeatureCapabilities)";
return ConnectionCapabilities();
}
// if the connection is online and ready use its caps
if (mPriv->connection &&
mPriv->connection->status() == ConnectionStatusConnected) {
return mPriv->connection->capabilities();
}
// if we are here it means FeatureProtocolInfo and FeatureProfile are ready, as
// FeatureCapabilities depend on them, so let's use the subtraction of protocol info caps rccs
// and profile unsupported rccs.
//
// However, if we failed to introspect the CM (eg. this is a test), then let's not try to use
// the protocolInfo because it'll be NULL! Profile may also be NULL in case a .profile for
// serviceName() is not present and protocolInfo is NULL.
ProtocolInfo pi = protocolInfo();
if (!pi.isValid()) {
return ConnectionCapabilities();
}
ProfilePtr pr = profile();
if (!pr) {
return pi.capabilities();
}
RequestableChannelClassSpecList piClassSpecs = pi.capabilities().allClassSpecs();
RequestableChannelClassSpecList prUnsupportedClassSpecs = pr->unsupportedChannelClassSpecs();
RequestableChannelClassSpecList classSpecs;
bool unsupported;
foreach (const RequestableChannelClassSpec &piClassSpec, piClassSpecs) {
unsupported = false;
foreach (const RequestableChannelClassSpec &prUnsuportedClassSpec, prUnsupportedClassSpecs) {
// Here we check the following:
// - If the unsupported spec has no allowed property it means it does not support any
// class whose fixed properties match.
// E.g: Doesn't support any media calls, be it audio or video.
// - If the unsupported spec has allowed properties it means it does not support a
// specific class whose fixed properties and allowed properties should match.
// E.g: Doesn't support video calls but does support audio calls.
if (prUnsuportedClassSpec.allowedProperties().isEmpty()) {
if (piClassSpec.fixedProperties() == prUnsuportedClassSpec.fixedProperties()) {
unsupported = true;
break;
}
} else {
if (piClassSpec == prUnsuportedClassSpec) {
unsupported = true;
break;
}
}
}
if (!unsupported) {
classSpecs.append(piClassSpec);
} else {
}
}
mPriv->customCaps = ConnectionCapabilities(classSpecs);
return mPriv->customCaps;
}
/**
* Return whether this account should be put online automatically whenever
* possible.
*
* This method requires Account::FeatureCore to be enabled.
*
* \return \c true if it should try to connect automatically, \c false
* otherwise.
* \sa connectsAutomaticallyPropertyChanged()
*/
bool Account::connectsAutomatically() const
{
return mPriv->connectsAutomatically;
}
/**
* Set whether this account should be put online automatically whenever
* possible.
*
* \param value Value indicating if this account should be put online whenever
* possible.
* \return A PendingOperation which will emit PendingOperation::finished
* when the call has finished.
* \sa connectsAutomaticallyPropertyChanged()
*/
PendingOperation *Account::setConnectsAutomatically(bool value)
{
return new PendingVoid(
mPriv->properties->Set(
QLatin1String(TELEPATHY_INTERFACE_ACCOUNT),
QLatin1String("ConnectAutomatically"),
QDBusVariant(value)),
AccountPtr(this));
}
/**
* Return whether this account has ever been put online successfully.
*
* This property cannot change from true to false, only from false to true.
* When the account successfully goes online for the first time, or when it
* is detected that this has already happened, the firstOnline() signal is
* emitted.
*
* This method requires Account::FeatureCore to be enabled.
*
* \return Whether the account has ever been online.
*/
bool Account::hasBeenOnline() const
{
return mPriv->hasBeenOnline;
}
/**
* Return the status of this account connection.
*
* This method requires Account::FeatureCore to be enabled.
*
* \return The status of this account connection.
* \sa connectionStatusChanged()
*/
ConnectionStatus Account::connectionStatus() const
{
return mPriv->connectionStatus;
}
/**
* Return the status reason of this account connection.
*
* This method requires Account::FeatureCore to be enabled.
*
* \return The status reason of this account connection.
* \sa connectionStatusChanged()
*/
ConnectionStatusReason Account::connectionStatusReason() const
{
return mPriv->connectionStatusReason;
}
/**
* Return the D-Bus error name for the last disconnection or connection failure,
* (in particular, #TELEPATHY_ERROR_CANCELLED if it was disconnected by user
* request), or an empty string if the account is connected.
*
* This method requires Account::FeatureCore to be enabled.
*
* \return The D-Bus error name for the last disconnection or connection failure.
* \sa connectionErrorDetails(), connectionStatus(), connectionStatusReason(),
* connectionStatusChanged()
*/
QString Account::connectionError() const
{
return mPriv->connectionError;
}
/**
* Return a map containing extensible error details related to
* connectionError().
*
* The keys for this map are defined by
* <a href="http://telepathy.freedesktop.org/spec/">the Telepathy D-Bus
* Interface Specification</a>. They will typically include
* <literal>debug-message</literal>, which is a debugging message in the C
* locale.
*
* This method requires Account::FeatureCore to be enabled.
*
* \return A map containing extensible error details related to
* connectionError().
* \sa connectionError(), connectionStatus(), connectionStatusReason(), connectionStatusChanged(),
* Connection::ErrorDetails.
*/
Connection::ErrorDetails Account::connectionErrorDetails() const
{
return mPriv->connectionErrorDetails;
}
/**
* Return the ConnectionPtr object of this account.
*
* Note that the returned ConnectionPtr object will not be cached by the Account
* instance; applications should do it themselves.
*
* Remember to call Connection::becomeReady on the new connection to
* make sure it is ready before using it.
*
* This method requires Account::FeatureCore to be enabled.
*
* \return A ConnectionPtr object pointing to the Connection object of this
* account, or a null ConnectionPtr if this account does not currently
* have a connection or if an error occurred.
* \sa connectionChanged()
*/
ConnectionPtr Account::connection() const
{
return mPriv->connection;
}
/**
* Return whether this account's connection is changing presence.
*
* This method requires Account::FeatureCore to be enabled.
*
* \return Whether this account's connection is changing presence.
* \sa changingPresence(), currentPresenceChanged(), setRequestedPresence()
*/
bool Account::isChangingPresence() const
{
return mPriv->changingPresence;
}
/**
* Return the presence status that this account will have set on it by the
* account manager if it brings it online automatically.
*
* This method requires Account::FeatureCore to be enabled.
*
* \return The presence that will be set by the account manager if this
* account is brought online automatically by it.
* \sa automaticPresenceChanged()
*/
Presence Account::automaticPresence() const
{
return mPriv->automaticPresence;
}
/**
* Set the presence status that this account should have if it is brought
* online automatically by the account manager.
*
* \param presence The presence to set when this account is brought
* online automatically by the account manager.
* \return A PendingOperation which will emit PendingOperation::finished
* when the call has finished.
* \sa automaticPresenceChanged(), setRequestedPresence()
*/
PendingOperation *Account::setAutomaticPresence(const Presence &presence)
{
return new PendingVoid(
mPriv->properties->Set(
QLatin1String(TELEPATHY_INTERFACE_ACCOUNT),
QLatin1String("AutomaticPresence"),
QDBusVariant(QVariant::fromValue(presence.barePresence()))),
AccountPtr(this));
}
/**
* Return the actual presence of this account.
*
* This method requires Account::FeatureCore to be enabled.
*
* \return The actual presence of this account.
* \sa currentPresenceChanged(), setRequestedPresence(), requestedPresence(), automaticPresence()
*/
Presence Account::currentPresence() const
{
return mPriv->currentPresence;
}
/**
* Return the requested presence of this account.
*
* This method requires Account::FeatureCore to be enabled.
*
* \return The requested presence of this account.
* \sa requestedPresenceChanged(), setRequestedPresence(), currentPresence(), automaticPresence()
*/
Presence Account::requestedPresence() const
{
return mPriv->requestedPresence;
}
/**
* Set the requested presence.
*
* When requested presence is changed, the account manager should attempt to
* manipulate the connection to make currentPresence() match requestedPresence()
* as closely as possible.
*
* \param presence The requested presence.
* \return A PendingOperation which will emit PendingOperation::finished
* when the call has finished.
* \sa requestedPresenceChanged(), currentPresence(), automaticPresence(), setAutomaticPresence()
*/
PendingOperation *Account::setRequestedPresence(const Presence &presence)
{
return new PendingVoid(
mPriv->properties->Set(
QLatin1String(TELEPATHY_INTERFACE_ACCOUNT),
QLatin1String("RequestedPresence"),
QDBusVariant(QVariant::fromValue(presence.barePresence()))),
AccountPtr(this));
}
/**
* Return whether this account is online.
*
* \return \c true if this account is online, otherwise \c false.
*/
bool Account::isOnline() const
{
return mPriv->currentPresence.type() != ConnectionPresenceTypeOffline;
}
/**
* Return the unique identifier of this account.
*
* This identifier should be unique per AccountManager implementation,
* i.e. at least per QDBusConnection.
*
* \return The unique identifier of this account.
*/
QString Account::uniqueIdentifier() const
{
QString path = objectPath();
return path.right(path.length() -
strlen("/org/freedesktop/Telepathy/Account/"));
}
/**
* Return the normalized user ID of the local user of this account.
*
* It is unspecified whether this user ID is globally unique.
*
* As currently implemented, IRC user IDs are only unique within the same
* IRCnet. On some saner protocols, the user ID includes a DNS name which
* provides global uniqueness.
*
* If this value is not known yet (which will always be the case for accounts
* that have never been online), it will be an empty string.
*
* It is possible that this value will change if the connection manager's
* normalization algorithm changes.
*
* This method requires Account::FeatureCore to be enabled.
*
* \return Account normalized user ID of the local user.
* \sa normalizedNameChanged()
*/
QString Account::normalizedName() const
{
return mPriv->normalizedName;
}
/**
* If this account is currently connected, disconnect and reconnect it. If it
* is currently trying to connect, cancel the attempt to connect and start
* another. If it is currently disconnected, do nothing.
*
* \return A PendingOperation which will emit PendingOperation::finished
* when the call has finished.
*/
PendingOperation *Account::reconnect()
{
return new PendingVoid(baseInterface()->Reconnect(), AccountPtr(this));
}
/**
* Delete this account.
*
* \return A PendingOperation which will emit PendingOperation::finished
* when the call has finished.
*/
PendingOperation *Account::remove()
{
return new PendingVoid(baseInterface()->Remove(), AccountPtr(this));
}
/**
* Start a request to ensure that a text channel with the given
* contact \a contactIdentifier exists, creating it if necessary.
*
* See ensureChannel() for more details.
*
* \param contactIdentifier The identifier of the contact to chat with.
* \param userActionTime The time at which user action occurred, or QDateTime()
* if this channel request is for some reason not
* involving user action.
* \param preferredHandler Either the well-known bus name (starting with
* org.freedesktop.Telepathy.Client.) of the preferred
* handler for this channel, or an empty string to
* indicate that any handler would be acceptable.
* \return A PendingChannelRequest which will emit PendingChannelRequest::finished
* when the call has finished.
* \sa ensureChannel(), createChannel()
*/
PendingChannelRequest *Account::ensureTextChat(
const QString &contactIdentifier,
const QDateTime &userActionTime,
const QString &preferredHandler)
{
QVariantMap request;
request.insert(QLatin1String(TELEPATHY_INTERFACE_CHANNEL ".ChannelType"),
QLatin1String(TELEPATHY_INTERFACE_CHANNEL_TYPE_TEXT));
request.insert(QLatin1String(TELEPATHY_INTERFACE_CHANNEL ".TargetHandleType"),
(uint) Tp::HandleTypeContact);
request.insert(QLatin1String(TELEPATHY_INTERFACE_CHANNEL ".TargetID"),
contactIdentifier);
return new PendingChannelRequest(AccountPtr(this), request, userActionTime,
preferredHandler, false);
}
/**
* Start a request to ensure that a text channel with the given
* contact \a contact exists, creating it if necessary.
*
* See ensureChannel() for more details.
*
* \param contact The contact to chat with.
* \param userActionTime The time at which user action occurred, or QDateTime()
* if this channel request is for some reason not
* involving user action.
* \param preferredHandler Either the well-known bus name (starting with
* org.freedesktop.Telepathy.Client.) of the preferred
* handler for this channel, or an empty string to
* indicate that any handler would be acceptable.
* \return A PendingChannelRequest which will emit PendingChannelRequest::finished
* when the call has finished.
* \sa ensureChannel(), createChannel()
*/
PendingChannelRequest *Account::ensureTextChat(
const ContactPtr &contact,
const QDateTime &userActionTime,
const QString &preferredHandler)
{
QVariantMap request;
request.insert(QLatin1String(TELEPATHY_INTERFACE_CHANNEL ".ChannelType"),
QLatin1String(TELEPATHY_INTERFACE_CHANNEL_TYPE_TEXT));
request.insert(QLatin1String(TELEPATHY_INTERFACE_CHANNEL ".TargetHandleType"),
(uint) Tp::HandleTypeContact);
request.insert(QLatin1String(TELEPATHY_INTERFACE_CHANNEL ".TargetHandle"),
contact ? contact->handle().at(0) : (uint) 0);
return new PendingChannelRequest(AccountPtr(this), request, userActionTime,
preferredHandler, false);
}
/**
* Start a request to ensure that a text chat room with the given
* room name \a roomName exists, creating it if necessary.
*
* See ensureChannel() for more details.
*
* \param roomName The name of the chat room.
* \param userActionTime The time at which user action occurred, or QDateTime()
* if this channel request is for some reason not
* involving user action.
* \param preferredHandler Either the well-known bus name (starting with
* org.freedesktop.Telepathy.Client.) of the preferred
* handler for this channel, or an empty string to
* indicate that any handler would be acceptable.
* \return A PendingChannelRequest which will emit PendingChannelRequest::finished
* when the call has finished.
* \sa ensureChannel(), createChannel()
*/
PendingChannelRequest *Account::ensureTextChatroom(
const QString &roomName,
const QDateTime &userActionTime,
const QString &preferredHandler)
{
QVariantMap request;
request.insert(QLatin1String(TELEPATHY_INTERFACE_CHANNEL ".ChannelType"),
QLatin1String(TELEPATHY_INTERFACE_CHANNEL_TYPE_TEXT));
request.insert(QLatin1String(TELEPATHY_INTERFACE_CHANNEL ".TargetHandleType"),
(uint) Tp::HandleTypeRoom);
request.insert(QLatin1String(TELEPATHY_INTERFACE_CHANNEL ".TargetID"),
roomName);
return new PendingChannelRequest(AccountPtr(this), request, userActionTime,
preferredHandler, false);
}
/**
* Start a request to ensure that a media channel with the given
* contact \a contactIdentifier exists, creating it if necessary.
*
* See ensureChannel() for more details.
*
* \param contactIdentifier The identifier of the contact to call.
* \param userActionTime The time at which user action occurred, or QDateTime()
* if this channel request is for some reason not
* involving user action.
* \param preferredHandler Either the well-known bus name (starting with
* org.freedesktop.Telepathy.Client.) of the preferred
* handler for this channel, or an empty string to
* indicate that any handler would be acceptable.
* \return A PendingChannelRequest which will emit PendingChannelRequest::finished
* when the call has finished.
* \sa ensureChannel(), createChannel()
*/
PendingChannelRequest *Account::ensureStreamedMediaCall(
const QString &contactIdentifier,
const QDateTime &userActionTime,
const QString &preferredHandler)
{
QVariantMap request;
request.insert(QLatin1String(TELEPATHY_INTERFACE_CHANNEL ".ChannelType"),
QLatin1String(TELEPATHY_INTERFACE_CHANNEL_TYPE_STREAMED_MEDIA));
request.insert(QLatin1String(TELEPATHY_INTERFACE_CHANNEL ".TargetHandleType"),
(uint) Tp::HandleTypeContact);
request.insert(QLatin1String(TELEPATHY_INTERFACE_CHANNEL ".TargetID"),
contactIdentifier);
return new PendingChannelRequest(AccountPtr(this), request, userActionTime,
preferredHandler, false);
}
/**
* Start a request to ensure that a media channel with the given
* contact \a contact exists, creating it if necessary.
*
* See ensureChannel() for more details.
*
* \param contact The contact to call.
* \param userActionTime The time at which user action occurred, or QDateTime()
* if this channel request is for some reason not
* involving user action.
* \param preferredHandler Either the well-known bus name (starting with
* org.freedesktop.Telepathy.Client.) of the preferred
* handler for this channel, or an empty string to
* indicate that any handler would be acceptable.
* \return A PendingChannelRequest which will emit PendingChannelRequest::finished
* when the call has finished.
* \sa ensureChannel(), createChannel()
*/
PendingChannelRequest *Account::ensureStreamedMediaCall(
const ContactPtr &contact,
const QDateTime &userActionTime,
const QString &preferredHandler)
{
QVariantMap request;
request.insert(QLatin1String(TELEPATHY_INTERFACE_CHANNEL ".ChannelType"),
QLatin1String(TELEPATHY_INTERFACE_CHANNEL_TYPE_STREAMED_MEDIA));
request.insert(QLatin1String(TELEPATHY_INTERFACE_CHANNEL ".TargetHandleType"),
(uint) Tp::HandleTypeContact);
request.insert(QLatin1String(TELEPATHY_INTERFACE_CHANNEL ".TargetHandle"),
contact ? contact->handle().at(0) : (uint) 0);
return new PendingChannelRequest(AccountPtr(this), request, userActionTime,
preferredHandler, false);
}
/**
* Start a request to ensure that an audio call with the given
* contact \a contactIdentifier exists, creating it if necessary.
*
* See ensureChannel() for more details.
*
* This will only work on relatively modern connection managers,
* like telepathy-gabble 0.9.0 or later.
*
* \param contactIdentifier The identifier of the contact to call.
* \param userActionTime The time at which user action occurred, or QDateTime()
* if this channel request is for some reason not
* involving user action.
* \param preferredHandler Either the well-known bus name (starting with
* org.freedesktop.Telepathy.Client.) of the preferred
* handler for this channel, or an empty string to
* indicate that any handler would be acceptable.
* \return A PendingChannelRequest which will emit PendingChannelRequest::finished
* when the call has finished.
* \sa ensureChannel(), createChannel()
*/
PendingChannelRequest *Account::ensureStreamedMediaAudioCall(
const QString &contactIdentifier,
QDateTime userActionTime,
const QString &preferredHandler)
{
QVariantMap request;
request.insert(QLatin1String(TELEPATHY_INTERFACE_CHANNEL ".ChannelType"),
QLatin1String(TELEPATHY_INTERFACE_CHANNEL_TYPE_STREAMED_MEDIA));
request.insert(QLatin1String(TELEPATHY_INTERFACE_CHANNEL ".TargetHandleType"),
(uint) Tp::HandleTypeContact);
request.insert(QLatin1String(TELEPATHY_INTERFACE_CHANNEL ".InitialAudio"),
true);
request.insert(QLatin1String(TELEPATHY_INTERFACE_CHANNEL ".TargetID"),
contactIdentifier);
return new PendingChannelRequest(AccountPtr(this), request, userActionTime,
preferredHandler, false);
}
/**
* Start a request to ensure that an audio call with the given
* contact \a contact exists, creating it if necessary.
*
* See ensureChannel() for more details.
*
* This will only work on relatively modern connection managers,
* like telepathy-gabble 0.9.0 or later.
*
* \param contact The contact to call.
* \param userActionTime The time at which user action occurred, or QDateTime()
* if this channel request is for some reason not
* involving user action.
* \param preferredHandler Either the well-known bus name (starting with
* org.freedesktop.Telepathy.Client.) of the preferred
* handler for this channel, or an empty string to
* indicate that any handler would be acceptable.
* \return A PendingChannelRequest which will emit PendingChannelRequest::finished
* when the call has finished.
* \sa ensureChannel(), createChannel()
*/
PendingChannelRequest *Account::ensureStreamedMediaAudioCall(
const ContactPtr &contact,
QDateTime userActionTime,
const QString &preferredHandler)
{
QVariantMap request;
request.insert(QLatin1String(TELEPATHY_INTERFACE_CHANNEL ".ChannelType"),
QLatin1String(TELEPATHY_INTERFACE_CHANNEL_TYPE_STREAMED_MEDIA));
request.insert(QLatin1String(TELEPATHY_INTERFACE_CHANNEL ".TargetHandleType"),
(uint) Tp::HandleTypeContact);
request.insert(QLatin1String(TELEPATHY_INTERFACE_CHANNEL ".InitialAudio"),
true);
request.insert(QLatin1String(TELEPATHY_INTERFACE_CHANNEL ".TargetHandle"),
contact ? contact->handle().at(0) : (uint) 0);
return new PendingChannelRequest(AccountPtr(this), request, userActionTime,
preferredHandler, false);
}
/**
* Start a request to ensure that a video call with the given
* contact \a contactIdentifier exists, creating it if necessary.
*
* See ensureChannel() for more details.
*
* This will only work on relatively modern connection managers,
* like telepathy-gabble 0.9.0 or later.
*
* \param contactIdentifier The identifier of the contact to call.
* \param withAudio true if both audio and video are required, false for a
* video-only call.
* \param userActionTime The time at which user action occurred, or QDateTime()
* if this channel request is for some reason not
* involving user action.
* \param preferredHandler Either the well-known bus name (starting with
* org.freedesktop.Telepathy.Client.) of the preferred
* handler for this channel, or an empty string to
* indicate that any handler would be acceptable.
* \return A PendingChannelRequest which will emit PendingChannelRequest::finished
* when the call has finished.
* \sa ensureChannel(), createChannel()
*/
PendingChannelRequest *Account::ensureStreamedMediaVideoCall(
const QString &contactIdentifier,
bool withAudio,
QDateTime userActionTime,
const QString &preferredHandler)
{
QVariantMap request;
request.insert(QLatin1String(TELEPATHY_INTERFACE_CHANNEL ".ChannelType"),
QLatin1String(TELEPATHY_INTERFACE_CHANNEL_TYPE_STREAMED_MEDIA));
request.insert(QLatin1String(TELEPATHY_INTERFACE_CHANNEL ".TargetHandleType"),
(uint) Tp::HandleTypeContact);
request.insert(QLatin1String(TELEPATHY_INTERFACE_CHANNEL ".InitialVideo"),
true);
request.insert(QLatin1String(TELEPATHY_INTERFACE_CHANNEL ".TargetID"),
contactIdentifier);
if (withAudio) {
request.insert(QLatin1String(TELEPATHY_INTERFACE_CHANNEL ".InitialAudio"),
true);
}
return new PendingChannelRequest(AccountPtr(this), request, userActionTime,
preferredHandler, false);
}
/**
* Start a request to ensure that a video call with the given
* contact \a contact exists, creating it if necessary.
*
* See ensureChannel() for more details.
*
* This will only work on relatively modern connection managers,
* like telepathy-gabble 0.9.0 or later.
*
* \param contact The contact to call.
* \param withAudio true if both audio and video are required, false for a
* video-only call.
* \param userActionTime The time at which user action occurred, or QDateTime()
* if this channel request is for some reason not
* involving user action.
* \param preferredHandler Either the well-known bus name (starting with
* org.freedesktop.Telepathy.Client.) of the preferred
* handler for this channel, or an empty string to
* indicate that any handler would be acceptable.
* \return A PendingChannelRequest which will emit PendingChannelRequest::finished
* when the call has finished.
* \sa ensureChannel(), createChannel()
*/
PendingChannelRequest *Account::ensureStreamedMediaVideoCall(
const ContactPtr &contact,
bool withAudio,
QDateTime userActionTime,
const QString &preferredHandler)
{
QVariantMap request;
request.insert(QLatin1String(TELEPATHY_INTERFACE_CHANNEL ".ChannelType"),
QLatin1String(TELEPATHY_INTERFACE_CHANNEL_TYPE_STREAMED_MEDIA));
request.insert(QLatin1String(TELEPATHY_INTERFACE_CHANNEL ".TargetHandleType"),
(uint) Tp::HandleTypeContact);
request.insert(QLatin1String(TELEPATHY_INTERFACE_CHANNEL ".InitialVideo"),
true);
request.insert(QLatin1String(TELEPATHY_INTERFACE_CHANNEL ".TargetHandle"),
contact ? contact->handle().at(0) : (uint) 0);
if (withAudio) {
request.insert(QLatin1String(TELEPATHY_INTERFACE_CHANNEL ".InitialAudio"),
true);
}
return new PendingChannelRequest(AccountPtr(this), request, userActionTime,
preferredHandler, false);
}
/**
* Start a request to create a file transfer channel with the given
* contact \a contact.
*
* \param contactIdentifier The identifier of the contact to send a file.
* \param fileName The suggested filename for the receiver.
* \param properties The desired properties.
* \param userActionTime The time at which user action occurred, or QDateTime()
* if this channel request is for some reason not
* involving user action.
* \param preferredHandler Either the well-known bus name (starting with
* org.freedesktop.Telepathy.Client.) of the preferred
* handler for this channel, or an empty string to
* indicate that any handler would be acceptable.
* \return A PendingChannelRequest which will emit PendingChannelRequest::finished
* when the call has finished.
* \sa ensureChannel(), createChannel()
*/
PendingChannelRequest *Account::createFileTransfer(
const QString &contactIdentifier,
const FileTransferChannelCreationProperties &properties,
const QDateTime &userActionTime,
const QString &preferredHandler)
{
QVariantMap request;
request.insert(QLatin1String(TELEPATHY_INTERFACE_CHANNEL ".ChannelType"),
QLatin1String(TELEPATHY_INTERFACE_CHANNEL_TYPE_FILE_TRANSFER));
request.insert(QLatin1String(TELEPATHY_INTERFACE_CHANNEL ".TargetHandleType"),
(uint) Tp::HandleTypeContact);
request.insert(QLatin1String(TELEPATHY_INTERFACE_CHANNEL ".TargetID"),
contactIdentifier);
QFileInfo fileInfo(properties.suggestedFileName());
request.insert(QLatin1String(TELEPATHY_INTERFACE_CHANNEL_TYPE_FILE_TRANSFER ".Filename"),
fileInfo.fileName());
request.insert(QLatin1String(TELEPATHY_INTERFACE_CHANNEL_TYPE_FILE_TRANSFER ".ContentType"),
properties.contentType());
request.insert(QLatin1String(TELEPATHY_INTERFACE_CHANNEL_TYPE_FILE_TRANSFER ".Size"),
properties.size());
if (properties.hasContentHash()) {
request.insert(QLatin1String(TELEPATHY_INTERFACE_CHANNEL_TYPE_FILE_TRANSFER ".ContentHashType"),
(uint) properties.contentHashType());
request.insert(QLatin1String(TELEPATHY_INTERFACE_CHANNEL_TYPE_FILE_TRANSFER ".ContentHash"),
properties.contentHash());
}
if (properties.hasDescription()) {
request.insert(QLatin1String(TELEPATHY_INTERFACE_CHANNEL_TYPE_FILE_TRANSFER ".Description"),
properties.description());
}
if (properties.hasLastModificationTime()) {
request.insert(QLatin1String(TELEPATHY_INTERFACE_CHANNEL_TYPE_FILE_TRANSFER ".Date"),
(qulonglong) properties.lastModificationTime().toTime_t());
}
return new PendingChannelRequest(AccountPtr(this), request, userActionTime,
preferredHandler, true);
}
/**
* Start a request to create a file transfer channel with the given
* contact \a contact.
*
* \param contact The contact to send a file.
* \param properties The desired properties.
* \param userActionTime The time at which user action occurred, or QDateTime()
* if this channel request is for some reason not
* involving user action.
* \param preferredHandler Either the well-known bus name (starting with
* org.freedesktop.Telepathy.Client.) of the preferred
* handler for this channel, or an empty string to
* indicate that any handler would be acceptable.
* \return A PendingChannelRequest which will emit PendingChannelRequest::finished
* when the call has finished.
* \sa ensureChannel(), createChannel()
*/
PendingChannelRequest *Account::createFileTransfer(
const ContactPtr &contact,
const FileTransferChannelCreationProperties &properties,
const QDateTime &userActionTime,
const QString &preferredHandler)
{
QVariantMap request;
request.insert(QLatin1String(TELEPATHY_INTERFACE_CHANNEL ".ChannelType"),
QLatin1String(TELEPATHY_INTERFACE_CHANNEL_TYPE_FILE_TRANSFER));
request.insert(QLatin1String(TELEPATHY_INTERFACE_CHANNEL ".TargetHandleType"),
(uint) Tp::HandleTypeContact);
request.insert(QLatin1String(TELEPATHY_INTERFACE_CHANNEL ".TargetHandle"),
contact ? contact->handle().at(0) : (uint) 0);
QFileInfo fileInfo(properties.suggestedFileName());
request.insert(QLatin1String(TELEPATHY_INTERFACE_CHANNEL_TYPE_FILE_TRANSFER ".Filename"),
fileInfo.fileName());
request.insert(QLatin1String(TELEPATHY_INTERFACE_CHANNEL_TYPE_FILE_TRANSFER ".ContentType"),
properties.contentType());
request.insert(QLatin1String(TELEPATHY_INTERFACE_CHANNEL_TYPE_FILE_TRANSFER ".Size"),
properties.size());
if (properties.hasContentHash()) {
request.insert(QLatin1String(TELEPATHY_INTERFACE_CHANNEL_TYPE_FILE_TRANSFER ".ContentHashType"),
(uint) properties.contentHashType());
request.insert(QLatin1String(TELEPATHY_INTERFACE_CHANNEL_TYPE_FILE_TRANSFER ".ContentHash"),
properties.contentHash());
}
if (properties.hasDescription()) {
request.insert(QLatin1String(TELEPATHY_INTERFACE_CHANNEL_TYPE_FILE_TRANSFER ".Description"),
properties.description());
}
if (properties.hasLastModificationTime()) {
request.insert(QLatin1String(TELEPATHY_INTERFACE_CHANNEL_TYPE_FILE_TRANSFER ".Date"),
(qulonglong) properties.lastModificationTime().toTime_t());
}
return new PendingChannelRequest(AccountPtr(this), request, userActionTime,
preferredHandler, true);
}
/**
* Start a request to create a conference media call with the given
* channels \a channels.
*
* \param channels The conference channels.
* \param initialInviteeContactsIdentifiers A list of additional contacts
* identifiers to be invited to this
* conference when it is created.
* \param userActionTime The time at which user action occurred, or QDateTime()
* if this channel request is for some reason not
* involving user action.
* \param preferredHandler Either the well-known bus name (starting with
* org.freedesktop.Telepathy.Client.) of the preferred
* handler for this channel, or an empty string to
* indicate that any handler would be acceptable.
* \return A PendingChannelRequest which will emit PendingChannelRequest::finished
* when the call has finished.
* \sa ensureChannel(), createChannel()
*/
PendingChannelRequest *Account::createConferenceStreamedMediaCall(
const QList<ChannelPtr> &channels,
const QStringList &initialInviteeContactsIdentifiers,
const QDateTime &userActionTime,
const QString &preferredHandler)
{
QVariantMap request;
mPriv->addConferenceRequestParameters(
TELEPATHY_INTERFACE_CHANNEL_TYPE_STREAMED_MEDIA,
HandleTypeNone,
channels, initialInviteeContactsIdentifiers, request);
return new PendingChannelRequest(AccountPtr(this), request, userActionTime,
preferredHandler, true);
}
/**
* Start a request to create a conference media call with the given
* channels \a channels.
*
* \param channels The conference channels.
* \param initialInviteeContactsIdentifiers A list of additional contacts
* to be invited to this
* conference when it is created.
* \param userActionTime The time at which user action occurred, or QDateTime()
* if this channel request is for some reason not
* involving user action.
* \param preferredHandler Either the well-known bus name (starting with
* org.freedesktop.Telepathy.Client.) of the preferred
* handler for this channel, or an empty string to
* indicate that any handler would be acceptable.
* \return A PendingChannelRequest which will emit PendingChannelRequest::finished
* when the call has finished.
* \sa ensureChannel(), createChannel()
*/
PendingChannelRequest *Account::createConferenceStreamedMediaCall(
const QList<ChannelPtr> &channels,
const QList<ContactPtr> &initialInviteeContacts,
const QDateTime &userActionTime,
const QString &preferredHandler)
{
QVariantMap request;
// TODO may we use Channel.Type.StreamedMedia here or Channel.Type.Call
// should be used?
mPriv->addConferenceRequestParameters(
TELEPATHY_INTERFACE_CHANNEL_TYPE_STREAMED_MEDIA,
HandleTypeNone,
channels, initialInviteeContacts, request);
return new PendingChannelRequest(AccountPtr(this), request, userActionTime,
preferredHandler, true);
}
/**
* Start a request to create a conference text chat with the given
* channels \a channels.
*
* \param channels The conference channels.
* \param initialInviteeContactsIdentifiers A list of additional contacts
* identifiers to be invited to this
* conference when it is created.
* \param userActionTime The time at which user action occurred, or QDateTime()
* if this channel request is for some reason not
* involving user action.
* \param preferredHandler Either the well-known bus name (starting with
* org.freedesktop.Telepathy.Client.) of the preferred
* handler for this channel, or an empty string to
* indicate that any handler would be acceptable.
* \return A PendingChannelRequest which will emit PendingChannelRequest::finished
* when the call has finished.
* \sa ensureChannel(), createChannel()
*/
PendingChannelRequest *Account::createConferenceTextChat(
const QList<ChannelPtr> &channels,
const QStringList &initialInviteeContactsIdentifiers,
const QDateTime &userActionTime,
const QString &preferredHandler)
{
QVariantMap request;
mPriv->addConferenceRequestParameters(
TELEPATHY_INTERFACE_CHANNEL_TYPE_TEXT,
HandleTypeNone,
channels, initialInviteeContactsIdentifiers, request);
return new PendingChannelRequest(AccountPtr(this), request, userActionTime,
preferredHandler, true);
}
/**
* Start a request to create a conference text chat with the given
* channels \a channels.
*
* \param channels The conference channels.
* \param initialInviteeContactsIdentifiers A list of additional contacts
* to be invited to this
* conference when it is created.
* \param userActionTime The time at which user action occurred, or QDateTime()
* if this channel request is for some reason not
* involving user action.
* \param preferredHandler Either the well-known bus name (starting with
* org.freedesktop.Telepathy.Client.) of the preferred
* handler for this channel, or an empty string to
* indicate that any handler would be acceptable.
* \return A PendingChannelRequest which will emit PendingChannelRequest::finished
* when the call has finished.
* \sa ensureChannel(), createChannel()
*/
PendingChannelRequest *Account::createConferenceTextChat(
const QList<ChannelPtr> &channels,
const QList<ContactPtr> &initialInviteeContacts,
const QDateTime &userActionTime,
const QString &preferredHandler)
{
QVariantMap request;
mPriv->addConferenceRequestParameters(
TELEPATHY_INTERFACE_CHANNEL_TYPE_TEXT,
HandleTypeNone,
channels, initialInviteeContacts, request);
return new PendingChannelRequest(AccountPtr(this), request, userActionTime,
preferredHandler, true);
}
/**
* Start a request to create a conference text chat room with the given
* channels \a channels and room name \a roomName.
*
* \param roomName The room name.
* \param channels The conference channels.
* \param initialInviteeContactsIdentifiers A list of additional contacts
* identifiers to be invited to this
* conference when it is created.
* \param userActionTime The time at which user action occurred, or QDateTime()
* if this channel request is for some reason not
* involving user action.
* \param preferredHandler Either the well-known bus name (starting with
* org.freedesktop.Telepathy.Client.) of the preferred
* handler for this channel, or an empty string to
* indicate that any handler would be acceptable.
* \return A PendingChannelRequest which will emit PendingChannelRequest::finished
* when the call has finished.
* \sa ensureChannel(), createChannel()
*/
PendingChannelRequest *Account::createConferenceTextChatRoom(
const QString &roomName,
const QList<ChannelPtr> &channels,
const QStringList &initialInviteeContactsIdentifiers,
const QDateTime &userActionTime,
const QString &preferredHandler)
{
QVariantMap request;
request.insert(QLatin1String(TELEPATHY_INTERFACE_CHANNEL ".TargetID"),
roomName);
mPriv->addConferenceRequestParameters(
TELEPATHY_INTERFACE_CHANNEL_TYPE_TEXT,
HandleTypeRoom,
channels, initialInviteeContactsIdentifiers, request);
return new PendingChannelRequest(AccountPtr(this), request, userActionTime,
preferredHandler, true);
}
/**
* Start a request to create a conference text chat room with the given
* channels \a channels and room name \a roomName.
*
* \param roomName The room name.
* \param channels The conference channels.
* \param initialInviteeContactsIdentifiers A list of additional contacts
* to be invited to this
* conference when it is created.
* \param userActionTime The time at which user action occurred, or QDateTime()
* if this channel request is for some reason not
* involving user action.
* \param preferredHandler Either the well-known bus name (starting with
* org.freedesktop.Telepathy.Client.) of the preferred
* handler for this channel, or an empty string to
* indicate that any handler would be acceptable.
* \return A PendingChannelRequest which will emit PendingChannelRequest::finished
* when the call has finished.
* \sa ensureChannel(), createChannel()
*/
PendingChannelRequest *Account::createConferenceTextChatRoom(
const QString &roomName,
const QList<ChannelPtr> &channels,
const QList<ContactPtr> &initialInviteeContacts,
const QDateTime &userActionTime,
const QString &preferredHandler)
{
QVariantMap request;
request.insert(QLatin1String(TELEPATHY_INTERFACE_CHANNEL ".TargetID"),
roomName);
mPriv->addConferenceRequestParameters(
TELEPATHY_INTERFACE_CHANNEL_TYPE_TEXT,
HandleTypeRoom,
channels, initialInviteeContacts, request);
return new PendingChannelRequest(AccountPtr(this), request, userActionTime,
preferredHandler, true);
}
/**
* Start a request to create a contact search channel with the given
* server \a server and limit \a limit.
*
* \param server For protocols which support searching for contacts on multiple servers with
* different DNS names (like XMPP), the DNS name of the server to be searched,
* e.g. "characters.shakespeare.lit". Otherwise, an empty string.
* \param limit The desired maximum number of results that should be returned by a doing a search.
* If the protocol does not support specifying a limit for the number of results
* returned at a time, this will be ignored.
* \param userActionTime The time at which user action occurred, or QDateTime()
* if this channel request is for some reason not
* involving user action.
* \param preferredHandler Either the well-known bus name (starting with
* org.freedesktop.Telepathy.Client.) of the preferred
* handler for this channel, or an empty string to
* indicate that any handler would be acceptable.
* \return A PendingChannelRequest which will emit PendingChannelRequest::finished
* when the call has finished.
* \sa createChannel()
*/
PendingChannelRequest *Account::createContactSearch(
const QString &server,
uint limit,
const QDateTime &userActionTime,
const QString &preferredHandler)
{
QVariantMap request;
request.insert(QLatin1String(TELEPATHY_INTERFACE_CHANNEL ".ChannelType"),
QLatin1String(TELEPATHY_INTERFACE_CHANNEL_TYPE_CONTACT_SEARCH));
request.insert(QLatin1String(TELEPATHY_INTERFACE_CHANNEL_TYPE_CONTACT_SEARCH ".Server"),
server);
request.insert(QLatin1String(TELEPATHY_INTERFACE_CHANNEL_TYPE_CONTACT_SEARCH ".Limit"), limit);
return new PendingChannelRequest(AccountPtr(this), request, userActionTime,
preferredHandler, true);
}
/**
* Start a request to create a channel.
* This initially just creates a PendingChannelRequest object,
* which can be used to track the success or failure of the request,
* or to cancel it.
*
* Helper methods for text chat, text chat room, media call and conference are
* provided and should be used if appropriate.
*
* \param request A dictionary containing desirable properties.
* \param userActionTime The time at which user action occurred, or QDateTime()
* if this channel request is for some reason not
* involving user action.
* \param preferredHandler Either the well-known bus name (starting with
* org.freedesktop.Telepathy.Client.) of the preferred
* handler for this channel, or an empty string to
* indicate that any handler would be acceptable.
* \sa createChannel()
*/
PendingChannelRequest *Account::createChannel(
const QVariantMap &request,
const QDateTime &userActionTime,
const QString &preferredHandler)
{
return new PendingChannelRequest(AccountPtr(this), request, userActionTime,
preferredHandler, true);
}
/**
* Start a request to ensure that a channel exists, creating it if necessary.
* This initially just creates a PendingChannelRequest object,
* which can be used to track the success or failure of the request,
* or to cancel it.
*
* Helper methods for text chat, text chat room, media call and conference are
* provided and should be used if appropriate.
*
* \param request A dictionary containing desirable properties.
* \param userActionTime The time at which user action occurred, or QDateTime()
* if this channel request is for some reason not
* involving user action.
* \param preferredHandler Either the well-known bus name (starting with
* org.freedesktop.Telepathy.Client.) of the preferred
* handler for this channel, or an empty string to
* indicate that any handler would be acceptable.
* \sa createChannel()
*/
PendingChannelRequest *Account::ensureChannel(
const QVariantMap &request,
const QDateTime &userActionTime,
const QString &preferredHandler)
{
return new PendingChannelRequest(AccountPtr(this), request, userActionTime,
preferredHandler, false);
}
/**
* \fn void Account::serviceNameChanged(const QString &serviceName);
*
* This signal is emitted when the value of serviceName() of this account
* changes.
*
* \param serviceName The new service name of this account.
* \sa serviceName(), setServiceName()
*/
/**
* \fn void Account::profileChanged(const Tp::ProfilePtr &profile);
*
* This signal is emitted when the value of profile() of this account
* changes.
*
* \param profile The new profile of this account.
* \sa profile()
*/
/**
* \fn void Account::displayNameChanged(const QString &displayName);
*
* This signal is emitted when the value of displayName() of this account
* changes.
*
* \param displayName The new display name of this account.
* \sa displayName(), setDisplayName()
*/
/**
* \fn void Account::iconNameChanged(const QString &iconName);
*
* This signal is emitted when the value of iconName() of this account changes.
*
* \param iconName The new icon name of this account.
* \sa iconName(), setIconName()
*/
/**
* \fn void Account::nicknameChanged(const QString &nickname);
*
* This signal is emitted when the value of nickname() of this account changes.
*
* \param nickname The new nickname of this account.
* \sa nickname(), setNickname()
*/
/**
* \fn void Account::normalizedNameChanged(const QString &normalizedName);
*
* This signal is emitted when the value of normalizedName() of this account
* changes.
*
* \param normalizedName The new normalized name of this account.
* \sa normalizedName()
*/
/**
* \fn void Account::validityChanged(bool validity);
*
* This signal is emitted when the value of isValidAccount() of this account
* changes.
*
* \param validity The new validity of this account.
* \sa isValidAccount()
*/
/**
* \fn void Account::stateChanged(bool state);
*
* This signal is emitted when the value of isEnabled() of this account
* changes.
*
* \param state The new state of this account.
* \sa isEnabled()
*/
/**
* \fn void Account::connectsAutomaticallyPropertyChanged(bool connectsAutomatically);
*
* This signal is emitted when the value of connectsAutomatically() of this
* account changes.
*
* \param connectsAutomatically The new value of connects automatically property
* of this account.
* \sa isEnabled()
*/
/**
* \fn void Account::firstOnline();
*
* This signal is emitted when this account is first put online.
*
* \sa hasBeenOnline()
*/
/**
* \fn void Account::parametersChanged(const QVariantMap ¶meters);
*
* This signal is emitted when the value of parameters() of this
* account changes.
*
* \param parameters The new parameters of this account.
* \sa parameters()
*/
/**
* \fn void Account::changingPresence(bool value);
*
* This signal is emitted when the value of isChangingPresence() of this
* account changes.
*
* \param value Whether this account's connection is changing presence.
* \sa isChangingPresence()
*/
/**
* \fn void Account::automaticPresenceChanged(const Tp::Presence &automaticPresence) const;
*
* This signal is emitted when the value of automaticPresence() of this
* account changes.
*
* \param automaticPresence The new value of automatic presence property of this
* account.
* \sa automaticPresence()
*/
/**
* \fn void Account::currentPresenceChanged(const Tp::Presence ¤tPresence) const;
*
* This signal is emitted when the value of currentPresence() of this
* account changes.
*
* \param currentPresence The new value of current presence property of this
* account.
* \sa currentPresence()
*/
/**
* \fn void Account::requestedPresenceChanged(const Tp::Presence &requestedPresence) const;
*
* This signal is emitted when the value of requestedPresence() of this
* account changes.
*
* \param requestedPresence The new value of requested presence property of this
* account.
* \sa requestedPresence()
*/
/**
* \fn void Account::onlinenessChanged(bool online) const;
*
* This signal is emitted when the value of isOnline() of this
* account changes.
*
* \param online Whether this account is online.
* \sa currentPresence()
*/
/**
* \fn void Account::avatarChanged(const Tp::Avatar &avatar);
*
* This signal is emitted when the value of avatar() of this
* account changes.
*
* \param avatar The new avatar of this account.
* \sa avatar()
*/
/**
* \fn void Account::connectionStatusChanged(Tp::ConnectionStatus status);
*
* This signal is emitted when the connection status of this account changes.
*
* \param status The new status of this account connection.
* \param statusReason The new status reason of this account connection.
* \param errorName The D-Bus error name for the last disconnection or
* connection failure,
* \param errorDetails The error details related to errorName.
* \sa connectionStatus(), connectionStatusReason(), connectionError(), connectionErrorDetails(),
* Connection::ErrorDetails
*/
/**
* \fn void Account::connectionChanged(const Tp::ConnectionPtr &connection);
*
* This signal is emitted when the value of connection() of this
* account changes.
*
* \param connection A ConnectionPtr pointing to the new Connection object or a null ConnectionPtr
* if there is no connection.
* \sa connection()
*/
/**
* Return the Client::AccountInterface interface proxy object for this account.
* This method is protected since the convenience methods provided by this
* class should generally be used instead of calling D-Bus methods
* directly.
*
* \return A pointer to the existing Client::AccountInterface object for this
* Account object.
*/
Client::AccountInterface *Account::baseInterface() const
{
return mPriv->baseInterface;
}
/**** Private ****/
void Account::Private::init()
{
if (!parent->isValid()) {
return;
}
parent->connect(baseInterface,
SIGNAL(Removed()),
SLOT(onRemoved()));
parent->connect(baseInterface,
SIGNAL(AccountPropertyChanged(QVariantMap)),
SLOT(onPropertyChanged(QVariantMap)));
}
void Account::Private::introspectMain(Account::Private *self)
{
debug() << "Calling Properties::GetAll(Account)";
QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(
self->properties->GetAll(
QLatin1String(TELEPATHY_INTERFACE_ACCOUNT)), self->parent);
self->parent->connect(watcher,
SIGNAL(finished(QDBusPendingCallWatcher*)),
SLOT(gotMainProperties(QDBusPendingCallWatcher*)));
}
void Account::Private::introspectAvatar(Account::Private *self)
{
debug() << "Calling GetAvatar(Account)";
// we already checked if avatar interface exists, so bypass avatar interface
// checking
Client::AccountInterfaceAvatarInterface *iface =
self->parent->interface<Client::AccountInterfaceAvatarInterface>();
// If we are here it means the user cares about avatar, so
// connect to avatar changed signal, so we update the avatar
// when it changes.
self->parent->connect(iface,
SIGNAL(AvatarChanged()),
SLOT(onAvatarChanged()));
self->retrieveAvatar();
}
void Account::Private::introspectProtocolInfo(Account::Private *self)
{
Q_ASSERT(!self->cm);
self->cm = ConnectionManager::create(
self->parent->dbusConnection(), self->cmName,
self->connFactory, self->chanFactory, self->contactFactory);
self->parent->connect(self->cm->becomeReady(),
SIGNAL(finished(Tp::PendingOperation*)),
SLOT(onConnectionManagerReady(Tp::PendingOperation*)));
}
void Account::Private::introspectCapabilities(Account::Private *self)
{
if (!self->connection) {
// there is no connection, just make capabilities ready
self->readinessHelper->setIntrospectCompleted(FeatureCapabilities, true);
return;
}
self->parent->connect(self->connection->becomeReady(),
SIGNAL(finished(Tp::PendingOperation*)),
SLOT(onConnectionReady(Tp::PendingOperation*)));
}
void Account::Private::updateProperties(const QVariantMap &props)
{
debug() << "Account::updateProperties: changed:";
if (props.contains(QLatin1String("Interfaces"))) {
parent->setInterfaces(qdbus_cast<QStringList>(props[QLatin1String("Interfaces")]));
debug() << " Interfaces:" << parent->interfaces();
}
QString oldIconName = parent->iconName();
bool serviceNameChanged = false;
bool profileChanged = false;
if (props.contains(QLatin1String("Service")) &&
serviceName != qdbus_cast<QString>(props[QLatin1String("Service")])) {
serviceNameChanged = true;
serviceName = qdbus_cast<QString>(props[QLatin1String("Service")]);
debug() << " Service Name:" << parent->serviceName();
/* use parent->serviceName() here as if the service name is empty we are going to use the
* protocol name */
emit parent->serviceNameChanged(parent->serviceName());
parent->notify("serviceName");
/* if we had a profile and the service changed, it means the profile also changed */
if (parent->isReady(Account::FeatureProfile)) {
/* service name changed, let's recreate profile */
profileChanged = true;
profile.reset();
emit parent->profileChanged(parent->profile());
parent->notify("profile");
}
}
if (props.contains(QLatin1String("DisplayName")) &&
displayName != qdbus_cast<QString>(props[QLatin1String("DisplayName")])) {
displayName = qdbus_cast<QString>(props[QLatin1String("DisplayName")]);
debug() << " Display Name:" << displayName;
emit parent->displayNameChanged(displayName);
parent->notify("displayName");
}
if ((props.contains(QLatin1String("Icon")) &&
oldIconName != qdbus_cast<QString>(props[QLatin1String("Icon")])) ||
serviceNameChanged) {
if (props.contains(QLatin1String("Icon"))) {
iconName = qdbus_cast<QString>(props[QLatin1String("Icon")]);
}
QString newIconName = parent->iconName();
if (oldIconName != newIconName) {
debug() << " Icon:" << newIconName;
emit parent->iconNameChanged(newIconName);
parent->notify("iconName");
}
}
if (props.contains(QLatin1String("Nickname")) &&
nickname != qdbus_cast<QString>(props[QLatin1String("Nickname")])) {
nickname = qdbus_cast<QString>(props[QLatin1String("Nickname")]);
debug() << " Nickname:" << nickname;
emit parent->nicknameChanged(nickname);
parent->notify("nickname");
}
if (props.contains(QLatin1String("NormalizedName")) &&
normalizedName != qdbus_cast<QString>(props[QLatin1String("NormalizedName")])) {
normalizedName = qdbus_cast<QString>(props[QLatin1String("NormalizedName")]);
debug() << " Normalized Name:" << normalizedName;
emit parent->normalizedNameChanged(normalizedName);
parent->notify("normalizedName");
}
if (props.contains(QLatin1String("Valid")) &&
valid != qdbus_cast<bool>(props[QLatin1String("Valid")])) {
valid = qdbus_cast<bool>(props[QLatin1String("Valid")]);
debug() << " Valid:" << (valid ? "true" : "false");
emit parent->validityChanged(valid);
parent->notify("valid");
}
if (props.contains(QLatin1String("Enabled")) &&
enabled != qdbus_cast<bool>(props[QLatin1String("Enabled")])) {
enabled = qdbus_cast<bool>(props[QLatin1String("Enabled")]);
debug() << " Enabled:" << (enabled ? "true" : "false");
emit parent->stateChanged(enabled);
parent->notify("enabled");
}
if (props.contains(QLatin1String("ConnectAutomatically")) &&
connectsAutomatically !=
qdbus_cast<bool>(props[QLatin1String("ConnectAutomatically")])) {
connectsAutomatically =
qdbus_cast<bool>(props[QLatin1String("ConnectAutomatically")]);
debug() << " Connects Automatically:" << (connectsAutomatically ? "true" : "false");
emit parent->connectsAutomaticallyPropertyChanged(connectsAutomatically);
parent->notify("connectsAutomatically");
}
if (props.contains(QLatin1String("HasBeenOnline")) &&
!hasBeenOnline &&
qdbus_cast<bool>(props[QLatin1String("HasBeenOnline")])) {
hasBeenOnline = true;
debug() << " HasBeenOnline changed to true";
// don't emit firstOnline unless we're already ready, that would be
// misleading - we'd emit it just before any already-used account
// became ready
if (parent->isReady()) {
emit parent->firstOnline();
}
parent->notify("hasBeenOnline");
}
if (props.contains(QLatin1String("Parameters")) &&
parameters != qdbus_cast<QVariantMap>(props[QLatin1String("Parameters")])) {
parameters = qdbus_cast<QVariantMap>(props[QLatin1String("Parameters")]);
debug() << " Parameters:" << parameters;
emit parent->parametersChanged(parameters);
parent->notify("parameters");
}
if (props.contains(QLatin1String("AutomaticPresence")) &&
automaticPresence.barePresence() != qdbus_cast<SimplePresence>(
props[QLatin1String("AutomaticPresence")])) {
automaticPresence = Presence(qdbus_cast<SimplePresence>(
props[QLatin1String("AutomaticPresence")]));
debug() << " Automatic Presence:" << automaticPresence.type() <<
"-" << automaticPresence.status();
emit parent->automaticPresenceChanged(automaticPresence);
parent->notify("automaticPresence");
}
if (props.contains(QLatin1String("CurrentPresence")) &&
currentPresence.barePresence() != qdbus_cast<SimplePresence>(
props[QLatin1String("CurrentPresence")])) {
currentPresence = Presence(qdbus_cast<SimplePresence>(
props[QLatin1String("CurrentPresence")]));
debug() << " Current Presence:" << currentPresence.type() <<
"-" << currentPresence.status();
emit parent->currentPresenceChanged(currentPresence);
parent->notify("currentPresence");
emit parent->onlinenessChanged(parent->isOnline());
parent->notify("online");
}
if (props.contains(QLatin1String("RequestedPresence")) &&
requestedPresence.barePresence() != qdbus_cast<SimplePresence>(
props[QLatin1String("RequestedPresence")])) {
requestedPresence = Presence(qdbus_cast<SimplePresence>(
props[QLatin1String("RequestedPresence")]));
debug() << " Requested Presence:" << requestedPresence.type() <<
"-" << requestedPresence.status();
emit parent->requestedPresenceChanged(requestedPresence);
parent->notify("requestedPresence");
}
if (props.contains(QLatin1String("ChangingPresence")) &&
changingPresence != qdbus_cast<bool>(
props[QLatin1String("ChangingPresence")])) {
changingPresence = qdbus_cast<bool>(
props[QLatin1String("ChangingPresence")]);
debug() << " Changing Presence:" << changingPresence;
emit parent->changingPresence(changingPresence);
parent->notify("changingPresence");
}
if (props.contains(QLatin1String("Connection"))) {
QString path = qdbus_cast<QDBusObjectPath>(props[QLatin1String("Connection")]).path();
if (path.isEmpty()) {
debug() << " The map contains \"Connection\" but it's empty as a QDBusObjectPath!";
debug() << " Trying QString (known bug in some MC/dbus-glib versions)";
path = qdbus_cast<QString>(props[QLatin1String("Connection")]);
}
debug() << " Connection Object Path:" << path;
if (path == QLatin1String("/")) {
path = QString();
}
connObjPathQueue.enqueue(path);
if (connObjPathQueue.size() == 1) {
processConnQueue();
}
// onConnectionBuilt for a previous path will make sure the path we enqueued is processed if
// the queue wasn't empty (so is now size() > 1)
}
bool connectionStatusChanged = false;
if (props.contains(QLatin1String("ConnectionStatus")) ||
props.contains(QLatin1String("ConnectionStatusReason")) ||
props.contains(QLatin1String("ConnectionError")) ||
props.contains(QLatin1String("ConnectionErrorDetails"))) {
ConnectionStatus oldConnectionStatus = connectionStatus;
if (props.contains(QLatin1String("ConnectionStatus")) &&
connectionStatus != ConnectionStatus(
qdbus_cast<uint>(props[QLatin1String("ConnectionStatus")]))) {
connectionStatus = ConnectionStatus(
qdbus_cast<uint>(props[QLatin1String("ConnectionStatus")]));
debug() << " Connection Status:" << connectionStatus;
connectionStatusChanged = true;
}
if (props.contains(QLatin1String("ConnectionStatusReason")) &&
connectionStatusReason != ConnectionStatusReason(
qdbus_cast<uint>(props[QLatin1String("ConnectionStatusReason")]))) {
connectionStatusReason = ConnectionStatusReason(
qdbus_cast<uint>(props[QLatin1String("ConnectionStatusReason")]));
debug() << " Connection StatusReason:" << connectionStatusReason;
connectionStatusChanged = true;
}
if (connectionStatusChanged) {
parent->notify("connectionStatus");
parent->notify("connectionStatusReason");
}
if (props.contains(QLatin1String("ConnectionError")) &&
connectionError != qdbus_cast<QString>(
props[QLatin1String("ConnectionError")])) {
connectionError = qdbus_cast<QString>(
props[QLatin1String("ConnectionError")]);
debug() << " Connection Error:" << connectionError;
connectionStatusChanged = true;
}
if (props.contains(QLatin1String("ConnectionErrorDetails")) &&
connectionErrorDetails.allDetails() != qdbus_cast<QVariantMap>(
props[QLatin1String("ConnectionErrorDetails")])) {
connectionErrorDetails = Connection::ErrorDetails(qdbus_cast<QVariantMap>(
props[QLatin1String("ConnectionErrorDetails")]));
debug() << " Connection Error Details:" << connectionErrorDetails.allDetails();
connectionStatusChanged = true;
}
if (connectionStatusChanged) {
/* Something other than status changed, let's not emit connectionStatusChanged
* and keep the error/errorDetails, for the next interaction.
* It may happen if ConnectionError changes and in another property
* change the status changes to Disconnected, so we use the error
* previously signalled. If the status changes to something other
* than Disconnected later, the error is cleared. */
if (oldConnectionStatus != connectionStatus) {
/* We don't signal error for status other than Disconnected */
if (connectionStatus != ConnectionStatusDisconnected) {
connectionError = QString();
connectionErrorDetails = Connection::ErrorDetails();
} else if (connectionError.isEmpty()) {
connectionError = ConnectionHelper::statusReasonToErrorName(
connectionStatusReason, oldConnectionStatus);
}
checkCapabilitiesChanged(profileChanged);
emit parent->connectionStatusChanged(connectionStatus);
parent->notify("connectionError");
parent->notify("connectionErrorDetails");
} else {
connectionStatusChanged = false;
}
}
}
if (!connectionStatusChanged && profileChanged) {
checkCapabilitiesChanged(profileChanged);
}
}
void Account::Private::retrieveAvatar()
{
QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(
parent->mPriv->properties->Get(
QLatin1String(TELEPATHY_INTERFACE_ACCOUNT_INTERFACE_AVATAR),
QLatin1String("Avatar")), parent);
parent->connect(watcher,
SIGNAL(finished(QDBusPendingCallWatcher*)),
SLOT(gotAvatar(QDBusPendingCallWatcher*)));
}
bool Account::Private::processConnQueue()
{
while (!connObjPathQueue.isEmpty()) {
QString path = connObjPathQueue.head();
if (path.isEmpty()) {
if (!connection.isNull()) {
debug() << "Dropping connection for account" << parent->objectPath();
connection.reset();
emit parent->connectionChanged(connection);
parent->notify("connection");
parent->notify("connectionObjectPath");
}
connObjPathQueue.dequeue();
} else {
debug() << "Building connection" << path << "for account" << parent->objectPath();
QString busName = path.mid(1).replace(QLatin1String("/"), QLatin1String("."));
parent->connect(connFactory->proxy(busName, path, chanFactory, contactFactory),
SIGNAL(finished(Tp::PendingOperation*)),
SLOT(onConnectionBuilt(Tp::PendingOperation*)));
// No dequeue here, but only in onConnectionBuilt, so we will queue future changes
return false; // Only move on to the next paths when that build finishes
}
}
return true;
}
void Account::gotMainProperties(QDBusPendingCallWatcher *watcher)
{
QDBusPendingReply<QVariantMap> reply = *watcher;
if (!reply.isError()) {
debug() << "Got reply to Properties.GetAll(Account) for" << objectPath();
mPriv->updateProperties(reply.value());
mPriv->readinessHelper->setInterfaces(interfaces());
mPriv->mayFinishCore = true;
if (mPriv->connObjPathQueue.isEmpty()) {
debug() << "Account basic functionality is ready";
mPriv->coreFinished = true;
mPriv->readinessHelper->setIntrospectCompleted(FeatureCore, true);
} else {
debug() << "Deferring finishing Account::FeatureCore until the connection is built";
}
} else {
mPriv->readinessHelper->setIntrospectCompleted(FeatureCore, false, reply.error());
warning().nospace() <<
"GetAll(Account) failed: " <<
reply.error().name() << ": " << reply.error().message();
}
watcher->deleteLater();
}
void Account::gotAvatar(QDBusPendingCallWatcher *watcher)
{
QDBusPendingReply<QVariant> reply = *watcher;
if (!reply.isError()) {
debug() << "Got reply to GetAvatar(Account)";
mPriv->avatar = qdbus_cast<Avatar>(reply);
// It could be in either of actual or missing from the first time in corner cases like the
// object going away, so let's be prepared for both (only checking for actualFeatures here
// actually used to trigger a rare bug)
//
// Anyway, the idea is to not do setIntrospectCompleted twice
if (!mPriv->readinessHelper->actualFeatures().contains(FeatureAvatar) &&
!mPriv->readinessHelper->missingFeatures().contains(FeatureAvatar)) {
mPriv->readinessHelper->setIntrospectCompleted(FeatureAvatar, true);
}
emit avatarChanged(mPriv->avatar);
notify("avatar");
} else {
// check if the feature is already there, and for some reason retrieveAvatar
// failed when called the second time
if (!mPriv->readinessHelper->actualFeatures().contains(FeatureAvatar) &&
!mPriv->readinessHelper->missingFeatures().contains(FeatureAvatar)) {
mPriv->readinessHelper->setIntrospectCompleted(FeatureAvatar, false, reply.error());
}
warning().nospace() <<
"GetAvatar(Account) failed: " <<
reply.error().name() << ": " << reply.error().message();
}
watcher->deleteLater();
}
void Account::onAvatarChanged()
{
debug() << "Avatar changed, retrieving it";
mPriv->retrieveAvatar();
}
void Account::onConnectionManagerReady(PendingOperation *operation)
{
bool error = operation->isError();
if (!error) {
error = !mPriv->cm->hasProtocol(mPriv->protocolName);
}
if (!error) {
mPriv->readinessHelper->setIntrospectCompleted(FeatureProtocolInfo, true);
}
else {
warning() << "Failed to find the protocol in the CM protocols for account" << objectPath();
mPriv->readinessHelper->setIntrospectCompleted(FeatureProtocolInfo, false,
operation->errorName(), operation->errorMessage());
}
}
void Account::onConnectionReady(PendingOperation *op)
{
mPriv->checkCapabilitiesChanged(false);
/* let's not fail if connection can't become ready, the caps will still
* work, but return the CM caps instead. Also no need to call
* setIntrospectCompleted if the feature was already set to complete once,
* since this method will be called whenever the account connection
* changes */
if (!isReady(FeatureCapabilities)) {
mPriv->readinessHelper->setIntrospectCompleted(FeatureCapabilities, true);
}
}
void Account::onPropertyChanged(const QVariantMap &delta)
{
mPriv->updateProperties(delta);
}
void Account::onRemoved()
{
mPriv->valid = false;
mPriv->enabled = false;
invalidate(QLatin1String(TELEPATHY_QT4_ERROR_OBJECT_REMOVED),
QLatin1String("Account removed from AccountManager"));
emit removed();
}
void Account::onConnectionBuilt(PendingOperation *op)
{
PendingReady *readyOp = qobject_cast<PendingReady *>(op);
Q_ASSERT(readyOp != NULL);
if (op->isError()) {
warning() << "Building connection" << mPriv->connObjPathQueue.head() << "failed with" <<
op->errorName() << "-" << op->errorMessage();
if (!mPriv->connection.isNull()) {
mPriv->connection.reset();
emit connectionChanged(mPriv->connection);
notify("connection");
notify("connectionObjectPath");
}
} else {
ConnectionPtr prevConn = mPriv->connection;
QString prevConnPath = mPriv->connectionObjectPath();
mPriv->connection = ConnectionPtr::qObjectCast(readyOp->proxy());
Q_ASSERT(mPriv->connection);
debug() << "Connection" << mPriv->connectionObjectPath() << "built for" << objectPath();
if (prevConn != mPriv->connection) {
notify("connection");
emit connectionChanged(mPriv->connection);
}
if (prevConnPath != mPriv->connectionObjectPath()) {
notify("connectionObjectPath");
}
}
mPriv->connObjPathQueue.dequeue();
if (mPriv->processConnQueue() && !mPriv->coreFinished && mPriv->mayFinishCore) {
debug() << "Account" << objectPath() << "basic functionality is ready (connections built)";
mPriv->coreFinished = true;
mPriv->readinessHelper->setIntrospectCompleted(FeatureCore, true);
}
}
} // Tp
|