summaryrefslogtreecommitdiffstats
path: root/doc/kdearch/index.docbook
blob: 65963503dfd4adaa887bad6e61391e88db9462d9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
<?xml version="1.0" ?>
<!DOCTYPE book PUBLIC "-//KDE//DTD DocBook XML V4.2-Based Variant V1.1//EN" "dtd/kdex.dtd" [
  <!ENTITY % addindex "INCLUDE">
  <!ENTITY % English "INCLUDE" > <!-- change language only here -->
]>

<book lang="&language;">

<bookinfo>
<title>KDE Architecture Overview</title>

<date></date>
<releaseinfo></releaseinfo>

<authorgroup>
<author>
<firstname>Bernd</firstname>
<surname>Gehrmann</surname>
<affiliation><address><email>bernd@tdevelop.org</email></address></affiliation>
</author>
</authorgroup>

<copyright>
<year>2001</year>
<year>2002</year>
<holder>Bernd Gehrmann</holder>
</copyright>

<legalnotice>&FDLNotice;</legalnotice>

<abstract>
<para>This documentation gives an overview of the KDE Development Platform</para>
</abstract>

<keywordset>
<keyword>KDE</keyword>
<keyword>architecture</keyword>
<keyword>development</keyword>
<keyword>programming</keyword>
</keywordset>

</bookinfo>

<chapter id="structure">
<title>Library structure</title>

<simplesect id="structure-byname">
<title>Libraries by name</title>

<variablelist>

<varlistentry>
<term><ulink url="kdeapi:tdecore/index.html">tdecore</ulink></term>
<listitem><para>
The tdecore library is the basic application framework for every KDE based
program. It provides access to the configuration system, command line
handling, icon loading and manipulation, some special kinds inter-process
communication, file handling and various other utilities.
</para></listitem>
</varlistentry>

<varlistentry>
<term><ulink url="kdeapi:tdeui/index.html">tdeui</ulink></term>
<listitem><para>
The <literal>tdeui</literal> library provides many widgets and standard
dialogs which Qt doesn't have or which have more features than their Qt
counterparts. It also includes several widgets which are subclassed
from Qt ones and are better integrated with the KDE desktop by
respecting user preferences.
</para></listitem>
</varlistentry>

<varlistentry>
<term><ulink url="kdeapi:kio/index.html">kio</ulink></term>
<listitem><para>
The <literal>kio</literal> library contains facilities for asynchronous,
network transparent I/O and access to mimetype handling. It also provides the
KDE file dialog and its helper classes.
</para></listitem>
</varlistentry>

<varlistentry>
<term><ulink url="kdeapi:kjs/index.html">kjs</ulink></term>
<listitem><para>
The <literal>kjs</literal> library provides an implementation of JavaScript.
</para></listitem>
</varlistentry>

<varlistentry>
<term><ulink url="kdeapi:khtml/index.html">khtml</ulink></term>
<listitem><para>
The <literal>khtml</literal> library contains the KHTML part, a HTML browsing
widget, DOM API and parser, including interfaces to Java and JavaScript.
</para></listitem>
</varlistentry>

</variablelist>

</simplesect>


<simplesect id="structure-grouped">
<title>Grouped classes</title>

<para>
Core application skeleton - classes needed by almost every application.
</para>

<itemizedlist>

<listitem><formalpara>
<title><ulink url="kdeapi:tdecore/TDEApplication">TDEApplication</ulink></title>
<para>
Initializes and controls a KDE application.
</para>
</formalpara></listitem>

<listitem><formalpara>
<title><ulink url="kdeapi:tdecore/KUniqueApplication">KUniqueApplication</ulink></title>
<para>
Makes sure only one instance of an application can run simultaneously.
</para>
</formalpara></listitem>

<listitem><formalpara><title><ulink url="kdeapi:tdecore/KAboutData">KAboutData</ulink></title>
<para>
Holds information for the about box.
</para>
</formalpara></listitem>

<listitem><formalpara><title><ulink url="kdeapi:tdecore/KCmdLineArgs">KCmdLineArgs</ulink></title>
<para>
Command line argument processing.
</para>
</formalpara></listitem>

</itemizedlist>

<para>
Configuration settings - access to KDE's hierarchical configuration
database, global settings and application resources.
</para>

<itemizedlist>

<listitem><formalpara><title><ulink url="kdeapi:tdecore/KConfig">KConfig</ulink></title>
<para>
Provides access to KDE's configuration database.
</para>
</formalpara></listitem>

<listitem><formalpara><title><ulink url="kdeapi:tdecore/KSimpleConfig">KSimpleConfig</ulink></title>
<para>
Access to simple, non-hierarchical configuration files.
</para>
</formalpara></listitem>

<listitem><formalpara><title><ulink url="kdeapi:tdecore/KDesktopFile">KDesktopFile</ulink></title>
<para>
Access to <literal>.desktop</literal> files.
</para>
</formalpara></listitem>

<listitem><formalpara><title><ulink url="kdeapi:tdecore/KGlobalSettings">KGlobalSettings</ulink></title>
<para>
Convenient access to not application-specific settings.
</para>
</formalpara></listitem>

</itemizedlist>

<para>
File and URL handling - decoding of URLs, temporary files etc.
</para>

<itemizedlist>

<listitem><formalpara><title><ulink url="kdeapi:tdecore/KURL">KURL</ulink></title>
<para>
Represents and parses URLs.
</para>
</formalpara></listitem>

<listitem><formalpara><title><ulink url="kdeapi:tdecore/KTempFile">KTempFile</ulink></title>
<para>
Creates unique files for temporary data.
</para>
</formalpara></listitem>

<listitem><formalpara><title><ulink url="kdeapi:tdecore/KSaveFile">KSaveFile</ulink></title>
<para>
Allows to save files atomically.
</para>
</formalpara></listitem>

</itemizedlist>

<para>
Interprocess communication - DCOP helper classes and subprocess invocation.
</para>

<itemizedlist>

<listitem><formalpara><title><ulink url="kdeapi:tdecore/KProcess">KProcess</ulink></title>
<para>
Invokes and controls child processes.
</para>
</formalpara></listitem>

<listitem><formalpara><title><ulink url="kdeapi:tdecore/KShellProcess">KShellProcess</ulink></title>
<para>
Invokes child processes via a shell.
</para>
</formalpara></listitem>

<listitem><formalpara><title><ulink url="kdeapi:tdesu/PtyProcess">PtyProcess</ulink></title>
<para>
Communication with a child processes through a pseudo terminal.
</para>
</formalpara></listitem>

<listitem><formalpara><title><ulink url="kdeapi:tdecore/KIPC">KIPC</ulink></title>
<para>
Simple IPC mechanism using X11 ClientMessages.
</para>
</formalpara></listitem>

<listitem><formalpara><title><ulink url="kdeapi:dcop/DCOPClient">DCOPClient</ulink></title>
<para>
DCOP messaging.
</para>
</formalpara></listitem>

<listitem><formalpara><title><ulink url="kdeapi:tdecore/KDCOPPropertyProxy">KDCOPPropertyProxy</ulink></title>
<para>
A proxy class publishing Qt properties through DCOP.
</para>
</formalpara></listitem>

<listitem><formalpara><title><ulink url="kdeapi:tdeui/KDCOPActionProxy">KDCOPActionProxy</ulink></title>
<para>
A proxy class publishing a DCOP interface for actions.
</para>
</formalpara></listitem>

</itemizedlist>

<para>
Utility classes - memory management, regular expressions, string manipulation,
random numbers
</para>

<itemizedlist>

<listitem><formalpara><title><ulink url="kdeapi:tdecore/KRegExp">KRegExp</ulink></title>
<para>
POSIX regular expression matching.
</para>
</formalpara></listitem>

<listitem><formalpara><title><ulink url="kdeapi:tdecore/KStringHandler">KStringHandler</ulink></title>
<para>
An extravagant interface for string manipulation.
</para>
</formalpara></listitem>

<listitem><formalpara><title><ulink url="kdeapi:tdecore/KZoneAllocator">KZoneAllocator</ulink></title>
<para>
Efficient memory allocator for large groups of small objects.
</para>
</formalpara></listitem>

<listitem><formalpara><title><ulink url="kdeapi:tdecore/KRandomSequence">KRandomSequence</ulink></title>
<para>
Pseudo random number generator.
</para>
</formalpara></listitem>

</itemizedlist>

<para>
Keyboard accelerators - classes helping to establish consistent key bindings
throughout the desktop.
</para>

<itemizedlist>

<listitem><formalpara><title><ulink url="kdeapi:tdecore/KAccel">KAccel</ulink></title>
<para>
Collection of keyboard shortcuts.
</para>
</formalpara></listitem>

<listitem><formalpara><title><ulink url="kdeapi:tdecore/KStdAccel">KStdAccel</ulink></title>
<para>
Easy access to the common keyboard shortcut keys.
</para>
</formalpara></listitem>

<listitem><formalpara><title><ulink url="kdeapi:tdecore/KGlobalAccel"></ulink></title>
<para>
Collection of system-wide keyboard shortcuts.
</para>
</formalpara></listitem>

</itemizedlist>

<para>
Image processing - icon loading and manipulating.
</para>

<itemizedlist>

<listitem><formalpara><title><ulink url="kdeapi:tdecore/KIconLoader">KIconLoader</ulink></title>
<para>
Loads icons in a theme-conforming way.
</para>
</formalpara></listitem>

<listitem><formalpara><title><ulink url="kdeapi:tdecore/KIconTheme">KIconTheme</ulink></title>
<para>
Helper classes for KIconLoader.
</para>
</formalpara></listitem>

<listitem><formalpara><title><ulink url="kdeapi:tdecore/KPixmap">KPixmap</ulink></title>
<para>
A pixmap class with extended dithering capabilities.
</para>
</formalpara></listitem>

<listitem><formalpara><title><ulink url="kdeapi:tdeui/KPixmapEffect">KPixmapEffect</ulink></title>
<para>
Pixmap effects like gradients and patterns.
</para>
</formalpara></listitem>

<listitem><formalpara><title><ulink url="kdeapi:tdeui/KPixmapIO">KPixmapIO</ulink></title>
<para>
Fast <classname>QImage</classname> to <classname>QPixmap</classname> conversion.
</para>
</formalpara></listitem>

</itemizedlist>

<para>
Drag and Drop - drag objects for colors and URLs.
</para>

<itemizedlist>

<listitem><formalpara><title><ulink url="kdeapi:tdecore/KURLDrag">KURLDrag</ulink></title>
<para>
A drag object for URLs.
</para>
</formalpara></listitem>

<listitem><formalpara><title><ulink url="kdeapi:tdeui/KColorDrag">KColorDrag</ulink></title>
<para>
A drag object for colors.
</para>
</formalpara></listitem>

<listitem><formalpara><title><ulink url="kdeapi:tdecore/KMultipleDrag">KMultipleDrag</ulink></title>
<para>
Allows to construct drag objects from several others.
</para>
</formalpara></listitem>

</itemizedlist>

<para>
Auto-Completion
</para>

<itemizedlist>

<listitem><formalpara><title><ulink url="kdeapi:tdecore/KCompletion">KCompletion</ulink></title>
<para>
Generic auto-completion of strings.
</para>
</formalpara></listitem>

<listitem><formalpara><title><ulink url="kdeapi:kio/KURLCompletion">KURLCompletion</ulink></title>
<para>
Auto-completion of URLs.
</para>
</formalpara></listitem>

<listitem><formalpara><title><ulink url="kdeapi:kio/KShellCompletion">KShellCompletion</ulink></title>
<para>
Auto-completion of executables.
</para>
</formalpara></listitem>

</itemizedlist>

<para>
Widgets - widget classes for list views, rules, color selection etc.
</para>

<itemizedlist>

<listitem><formalpara><title><ulink url="kdeapi:tdeui/KListView">KListView</ulink></title>
<para>
A variant of <classname>QListView</classname> that honors KDE's system-wide settings.
</para>
</formalpara></listitem>

<listitem><formalpara><title><ulink url="kdeapi:tdeui/KListView">KListBox</ulink></title>
<para>
A variant of <classname>QListBox</classname> that honors KDE's system-wide settings.
</para>
</formalpara></listitem>

<listitem><formalpara><title><ulink url="kdeapi:tdeui/KListView">KIconView</ulink></title>
<para>
A variant of <classname>QIconView</classname> that honors KDE's system-wide settings.
</para>
</formalpara></listitem>

<listitem><formalpara><title><ulink url="kdeapi:tdeui/KListView">KLineEdit</ulink></title>
<para>
A variant of <classname>QLineEdit</classname> with completion support.
</para>
</formalpara></listitem>

<listitem><formalpara><title><ulink url="kdeapi:tdeui/KComboBox">KComboBox</ulink></title>
<para>
A variant of <classname>QComboBox</classname> with completion support.
</para>
</formalpara></listitem>

<listitem><formalpara><title><ulink url="kdeapi:tdeui/KFontCombo">KFontCombo</ulink></title>
<para>
A combo box for selecting fonts.
</para>
</formalpara></listitem>

<listitem><formalpara><title><ulink url="kdeapi:tdeui/KColorCombo">KColorCombo</ulink></title>
<para>
A combo box for selecting colors.
</para>
</formalpara></listitem>

<listitem><formalpara><title><ulink url="kdeapi:tdeui/KColorButton">KColorButton</ulink></title>
<para>
A button for selecting colors.
</para>
</formalpara></listitem>

<listitem><formalpara><title><ulink url="kdeapi:tdeui/KURLCombo">KURLCombo</ulink></title>
<para>
A combo box for selecting file names and URLs.
</para>
</formalpara></listitem>

<listitem><formalpara><title><ulink url="kdeapi:kfile/KURLRequester">KURLRequester</ulink></title>
<para>
A line edit for selecting file names and URLs.
</para>
</formalpara></listitem>

<listitem><formalpara><title><ulink url="kdeapi:tdeui/KRuler">KRuler</ulink></title>
<para>
A ruler widget.
</para>
</formalpara></listitem>

<listitem><formalpara><title><ulink
url="kdeapi:tdeui/KAnimWidget">KAnimWidget</ulink></title>
<para>
animations.
</para>
</formalpara></listitem>

<listitem><formalpara><title><ulink url="kdeapi:tdeui/KNumInput">KNumInput</ulink></title>
<para>
A widget for inputting numbers.
</para>
</formalpara></listitem>

<listitem><formalpara><title><ulink url="kdeapi:tdeui/KPasswordEdit">KPasswordEdit</ulink></title>
<para>
A widget for inputting passwords.
</para>
</formalpara></listitem>

</itemizedlist>

<para>
Dialogs - full-featured dialogs for file, color and font selection.
</para>

<itemizedlist>

<listitem><formalpara><title><ulink url="kdeapi:kfile/KFileDialog">KFileDialog</ulink></title>
<para>
A file selection dialog.
</para>
</formalpara></listitem>

<listitem><formalpara><title><ulink url="kdeapi:tdeui/KColorDialog">KColorDialog</ulink></title>
<para>
A color selection dialog.
</para>
</formalpara></listitem>

<listitem><formalpara><title><ulink url="kdeapi:tdeui/KFontDialog">KFontDialog</ulink></title>
<para>
A font selection dialog.
</para>
</formalpara></listitem>

<listitem><formalpara><title><ulink url="kdeapi:kfile/KIconDialog">KIconDialog</ulink></title>
<para>
An icon selection dialog.
</para>
</formalpara></listitem>

<listitem><formalpara><title><ulink url="kdeapi:tdeui/KKeyDialog">KKeyDialog</ulink></title>
<para>
A dialog for editing keyboard bindings.
</para>
</formalpara></listitem>

<listitem><formalpara><title><ulink url="kdeapi:tdeui/KEditToolBar">KEditToolBar</ulink></title>
<para>
A dialog for editing toolbars.
</para>
</formalpara></listitem>

<listitem><formalpara><title><ulink url="kdeapi:tdeui/KTipDialog">KTipDialog</ulink></title>
<para>
A Tip-of-the-day dialog.
</para>
</formalpara></listitem>

<listitem><formalpara><title><ulink url="kdeapi:tdeui/KAboutDialog">KAboutDialog</ulink></title>
<para>
An about dialog.
</para>
</formalpara></listitem>

<listitem><formalpara><title><ulink url="kdeapi:tdeui/KLineEditDlg">KLineEditDlg</ulink></title>
<para>
A simple dialog for entering text.
</para>
</formalpara></listitem>

<listitem><formalpara><title><ulink url="kdeapi:kfile/KURLRequesterDlg">KURLRequesterDlg</ulink></title>
<para>
A simple dialog for entering URLs.
</para>
</formalpara></listitem>

<listitem><formalpara><title><ulink url="kdeapi:tdeui/KMessageBox">KMessageBox</ulink></title>
<para>
A dialog for signaling errors and warnings.
</para>
</formalpara></listitem>

<listitem><formalpara><title><ulink url="kdeapi:tdeui/KPasswordDialog">KPasswordDialog</ulink></title>
<para>
A dialog for inputting passwords.
</para>
</formalpara></listitem>

</itemizedlist>

<para>
Actions and XML GUI
</para>

<itemizedlist>

<listitem><formalpara><title><ulink url="kdeapi:tdeui/KAction">KAction</ulink></title>
<para>
Abstraction for an action that can be plugged into menu bars and tool bars.
</para>
</formalpara></listitem>

<listitem><formalpara><title><ulink url="kdeapi:tdeui/KActionCollection">KActionCollection</ulink></title>
<para>
A set of actions.
</para>
</formalpara></listitem>

<listitem><formalpara><title><ulink url="kdeapi:tdeui/KXMLGUIClient">KXMLGUIClient</ulink></title>
<para>
A GUI fragment consisting of an action collection and a DOM tree representing their location in the GUI.
</para>
</formalpara></listitem>

<listitem><formalpara><title><ulink url="kdeapi:kparts/KPartManager">KPartManager</ulink></title>
<para>
Manages the activation of XMLGUI clients.
</para>
</formalpara></listitem>

</itemizedlist>

<para>
Plugins and Components
</para>

<itemizedlist>

<listitem><formalpara><title><ulink url="kdeapi:tdecore/KLibrary">KLibrary</ulink></title>
<para>
Represents a dynamically loaded library.
</para>
</formalpara></listitem>

<listitem><formalpara><title><ulink url="kdeapi:tdecore/KLibrary">KLibLoader</ulink></title>
<para>
Shared library loading.
</para>
</formalpara></listitem>

<listitem><formalpara><title><ulink url="kdeapi:tdecore/KLibFactory">KLibFactory</ulink></title>
<para>
Object factory in plugins.
</para>
</formalpara></listitem>

<listitem><formalpara><title><ulink url="kdeapi:kio/KServiceType">KServiceType</ulink></title>
<para>
Represents a service type.
</para>
</formalpara></listitem>

<listitem><formalpara><title><ulink url="kdeapi:kio/KService">KService</ulink></title>
<para>
Represents a service.
</para>
</formalpara></listitem>

<listitem><formalpara><title><ulink url="kdeapi:kio/KMimeType">KMimeType</ulink></title>
<para>
Represents a MIME type.
</para>
</formalpara></listitem>

<listitem><formalpara><title><ulink url="kdeapi:kio/KServiceTypeProfile">KServiceTypeProfile</ulink></title>
<para>
User preferences for MIME type mappings.
</para>
</formalpara></listitem>

<listitem><formalpara><title><ulink url="kdeapi:kio/KServiceTypeProfile">KTrader</ulink></title>
<para>
Querying for services.
</para>
</formalpara></listitem>

</itemizedlist>

</simplesect>

</chapter>



<chapter id="graphics">
<title>Graphics</title>

<sect1 id="graphics-qpainter">
<title>Low-level graphics with QPainter</title>

<simplesect id="qpainter-rendering">
<title>Rendering with QPainter</title>

<para>
Qt's low level imaging model is based on the capabilities provided by X11 and
other windowing systems for which Qt ports exist. But it also extends these by
implementing additional features such as arbitrary affine transformations for
text and pixmaps.
</para>

<para>
The central graphics class for 2D painting with Qt is 
<ulink url="kdeapi:qt/QPainter">QPainter</ulink>. It can
draw on a
<ulink url="kdeapi:qt/QPaintDevice">QPaintDevice</ulink>.
There are three possible paint devices implemented: One is 
<ulink url="kdeapi:qt/QWidget">QWidget</ulink>
which represents a widget on the screen. The second is 
<ulink url="kdeapi:qt/QPrinter">QPrinter</ulink> which
represents a printer and produces Postscript output. The third it
the class
<ulink url="kdeapi:qt/QPicture">QPicture</ulink> which
records paint commands and can save them on disk and play them back
later. A possible storage format for paint commands is the W3C standard
SVG.
</para>

<para>
So, it is possible to reuse the rendering code you use for displaying a
widget for printing, with the same features supported. Of course, in
practice, the code is used in a slightly different context. Drawing
on a widget is almost exclusively done in the paintEvent() method
of a widget class.
</para>

<programlisting>
void FooWidget::paintEvent()
{
    QPainter p(this);
    // Setup painter
    // Use painter
}
</programlisting>

<para>
When drawing on a printer, you have to make sure to use QPrinter::newPage()
to finish with a page and begin a new one - something that naturally is not
relevant for painting widgets. Also, when printing, you may want to use the
<ulink url="kdeapi:qt/QPaintDeviceMetrics">device metrics</ulink>
in order to compute coordinates.
</para>

</simplesect>


<simplesect id="qpainter-transformations">
<title>Transformations</title>

<para>
By default, when using QPainter, it draws in the natural coordinate
system of the device used. This means, if you draw a line along the horizontal
axis with a length of 10 units, it will be painted as a horizontal line
on the screen with a length of 10 pixels. However, QPainter can apply arbitrary
affine transformations before actually rendering shapes and curves. An
affine transformation maps the x and y coordinates linearly into x' and
y' according to
</para>

<mediaobject>
<imageobject><imagedata fileref="affine-general.png"/></imageobject>
</mediaobject>

<para>
The 3x3 matrix in this equation can be set with QPainter::setWorldMatrix() and
is of type <ulink url="kdeapi:qt/QWMatrix">QWMatrix</ulink>.
Normally, this is the identity matrix, i.e. m11 and m22 are one, and the
other parameters are zero. There are basically three different groups of
transformations:
</para>

<itemizedlist>

<listitem><formalpara>
<title>Translations</title>
<para>
These move all points of an object by a fixed amount in
some direction. A translation matrix can be obtained by calling
method m.translate(dx, dy) for a QWMatrix. This corresponds to the
matrix
</para>
</formalpara>

<mediaobject>
<imageobject><imagedata fileref="affine-translate.png"/></imageobject>
</mediaobject>

</listitem>

<listitem><formalpara>
<title>Scaling</title>
<para>
These stretch or shrink the coordinates of an object, making
it bigger or smaller without distorting it. A scaling transformation
can be applied to a QWMatrix by calling m.scale(sx, sy). This corresponds
to the matrix
</para>
</formalpara>

<mediaobject>
<imageobject><imagedata fileref="affine-scale.png"/></imageobject>
</mediaobject>

<para>
By setting one of the parameters to a negative value, one can
achieve a mirroring of the coordinate system.
</para>

</listitem>

<listitem><formalpara>
<title>Shearing</title>
<para>
A distortion of the coordinate system with two
parameters. A shearing transformation can be applied by calling
m.shear(sh, sv), corresponding to the matrix
</para>
</formalpara>

<mediaobject>
    <imageobject><imagedata fileref="affine-shear.png"/></imageobject>
</mediaobject>

</listitem>

<listitem><formalpara>
<title>Rotating</title>
<para>
This rotates an object. A rotation transformation can be 
applied by calling m.rotate(alpha). Note that the angle has to be given
in degrees, not as mathematical angle! The corresponding matrix is
</para>
</formalpara>

<mediaobject>
<imageobject><imagedata fileref="affine-rotate.png"/></imageobject>
</mediaobject>

<para>
Note that a rotation is equivalent with a combination of
scaling and shearing.
</para>

</listitem>

</itemizedlist>

<para>
Here are some pictures that show the effect of the elementary
transformation to our masquot:
</para>

<informaltable frame="none">
<tgroup cols="3">
<tbody>
<row>
<entry><mediaobject>
    <imageobject><imagedata fileref="konqi-normal.png"/></imageobject>
</mediaobject></entry>
<entry><mediaobject>
    <imageobject><imagedata fileref="konqi-rotated.png"/></imageobject>
</mediaobject></entry>
<entry><mediaobject>
    <imageobject><imagedata fileref="konqi-sheared.png"/></imageobject>
</mediaobject></entry>
<entry><mediaobject>
   <imageobject><imagedata fileref="konqi-mirrored.png"/></imageobject>
</mediaobject></entry>
</row>
<row>
<entry>a) Normal</entry>
<entry>b) Rotated by 30 degrees</entry>
<entry>c) Sheared by 0.4</entry>
<entry>d) Mirrored</entry>
</row>
</tbody>
</tgroup>
</informaltable>

<para>
Transformations can be combined by multiplying elementary matrices. Note that 
matrix operations are not commutative in general, and therefore the combined 
effect of of a concatenation depends on the order in which the matrices are
multiplied.
</para>

</simplesect>


<simplesect id="qpainter-strokeattributes">
<title>Setting stroking attributes</title>

<para>
The rendering of lines, curves and outlines of polygons can be modified by 
setting a special pen with QPainter::setPen(). The argument of this function is a 
<ulink url="kdeapi:qt/QPen">QPen</ulink> object. The properties
stored in it are a style, a color, a join style and a cap style.
</para>

<para>
The pen style is member of the enum
<ulink url="kdeapi:qt/Qt#PenStyle-enum">Qt::PenStyle</ulink>. 
and can take one of the following values:
</para>

<mediaobject>
    <imageobject><imagedata fileref="penstyles.png"/></imageobject>
</mediaobject>

<para>
The join style is a member of the enum
<ulink url="kdeapi:qt/Qt#PenJoinStyle-enum">Qt::PenJoinStyle</ulink>. 
It specifies how the junction between multiple lines which are attached to each 
other is drawn. It takes one of the following values:
</para>

<informaltable frame="none">
<tgroup cols="3">
<tbody>
<row>
<entry><mediaobject>
    <imageobject><imagedata fileref="joinmiter.png"/></imageobject>
</mediaobject></entry>
<entry><mediaobject>
    <imageobject><imagedata fileref="joinbevel.png"/></imageobject>
</mediaobject></entry>
<entry><mediaobject>
    <imageobject><imagedata fileref="joinround.png"/></imageobject>
</mediaobject></entry>
</row>
<row>
<entry>a) MiterJoin</entry>
<entry>c) BevelJoin</entry>
<entry>b) RoundJoin</entry>
</row>
</tbody>
</tgroup>
</informaltable>

<para>
The cap style is a member of the enum 
<ulink url="kdeapi:qt/Qt#PenCapStyle-enum">Qt::PenCapStyle</ulink>and specifies how the end points of lines are drawn. It takes one of the values 
from the following table:
</para>

<informaltable frame="none">
<tgroup cols="3">
<tbody>
<row>
<entry><mediaobject>
    <imageobject><imagedata fileref="capflat.png"/></imageobject>
</mediaobject></entry>
<entry><mediaobject>
    <imageobject><imagedata fileref="capsquare.png"/></imageobject>
</mediaobject></entry>
<entry><mediaobject>
    <imageobject><imagedata fileref="capround.png"/></imageobject>
</mediaobject></entry>
</row>
<row>
<entry>a) FlatCap</entry>
<entry>b) SquareCap</entry>
<entry>c) RoundCap</entry>
</row>
</tbody>
</tgroup>
</informaltable>

</simplesect>


<simplesect id="qpainter-fillattributes">
<title>Setting fill attributes</title>

<para>
The fill style of polygons, circles or rectangles can be modified by setting
a special brush with QPainter::setBrush(). This function takes a
<ulink url="kdeapi:qt/QBrush">QBrush</ulink> object as argument. 
Brushes can be constructed in four different ways:
</para>

<itemizedlist>
<listitem>
<para>QBrush::QBrush() - This creates a brush that does not fill shapes.</para>
</listitem>
<listitem>
<para>QBrush::QBrush(BrushStyle) - This creates a black brush with one of the default
patterns shown below.</para>
</listitem>
<listitem>
<para>QBrush::QBrush(const QColor &amp;, BrushStyle) - This creates a colored brush
with one of the patterns shown below.</para>
</listitem>
<listitem>
<para>QBrush::QBrush(const QColor &amp;, const QPixmap) - This creates a colored
brush with the custom pattern you give as second parameter.</para>
</listitem>
</itemizedlist>

<para>
A default brush style is from the enum
<ulink url="kdeapi:qt/Qt#BrushStyle-enum">Qt::BrushStyle</ulink>.
Here is a picture of all predefined patterns:
</para>

<mediaobject>
    <imageobject><imagedata fileref="brushstyles.png"/></imageobject>
</mediaobject>

<para>
A further way to customize the brush behavior is to use the function
QPainter::setBrushOrigin().
</para>

</simplesect>


<simplesect id="qpainter-color">
<title>Color</title>

<para>
Colors play a role both when stroking curves and when filling shapes. In Qt, 
colors are represented by the class 
<ulink url="kdeapi:qt/QColor">QColor</ulink>. Qt does not support 
advanced graphics features like ICC color profiles and color correction. Colors 
are usually constructed by specifying their red, green and blue components, as 
the RGB model is the way pixels are composed of on a monitor. 
</para>

<para>
It is also possible to use hue, saturation and value. This HSV representation is 
what you use in the Gtk color dialog, e.g. in GIMP. There, the hue corresponds
to the angle on the color wheel, while the saturation corresponds to the 
distance from the center of the circle. The value can be chosen with a separate
slider.
</para>

</simplesect>


<simplesect id="qpainter-paintsettings">
<title>Other settings</title>

<para>
Normally, when you paint on a paint device, the pixels you draw replace those
that were there previously. This means, if you paint a certain region with
a red color and paint the same region with a blue color afterwards, only
the blue color will be visible. Qt's imaging model does not support 
transparency, i.e. a way to blend the painted foreground with the background.
However, there is a simple way to combine background and foreground with
boolean operators. The method QPainter::setRasterOp() sets the used operator,
which comes from the enum 
<ulink url="kdeapi:qt/Qt#RasterOp-enum">RasterOp</ulink>.
</para>

<para>
The default is CopyROP which ignores the background. Another popular choice is
XorROP. If you paint a black line with this operator on a colored image, then 
the covered area will be inverted. This effect is for example used to create
the rubberband selections in image manipulation programs known as 
"marching ants".
</para>

</simplesect>


<simplesect id="qpainter-primitives">
<title>Drawing graphics primitives</title>

<para>
In the following we list the elementary graphics elements supported by 
QPainter. Most of them exist in several overloaded versions which take a 
different number of arguments. For example, methods that deal with rectangles
usually either take a 
<ulink url="kdeapi:qt/QRect">QRect</ulink> as argument or a set
of four integers.
</para>

<itemizedlist>
<listitem>
<para>Drawing a single point - drawPoint().</para>
</listitem>
<listitem>
<para>Drawing lines - drawLine(), drawLineSegments() and drawPolyLine().</para>
</listitem>
<listitem>
<para>Drawing and filling rectangles - drawRect(), drawRoundRect(),
fillRect() and eraseRect().</para>
</listitem>
<listitem>
<para>Drawing and filling circles, ellipses and parts or them -
drawEllipse(), drawArc(), drawPie and drawChord().</para>
</listitem>
<listitem>
<para>Drawing and filling general polygons - drawPolygon().</para>
</listitem>
<listitem>
<para>Drawing bezier curves - drawQuadBezier() [drawCubicBezier in Qt 3.0].</para>
</listitem>
</itemizedlist>

</simplesect>


<simplesect id="qpainter-pixmaps">
<title>Drawing pixmaps and images</title>

<para>
Qt provides two very different classes to represent images. 
</para>

<para>
<ulink url="kdeapi:qt/QPixmap">QPixmap</ulink> directly corresponds
to the pixmap objects in X11. Pixmaps are server-side objects and may - on a
modern graphics card - even be stored directly in the card's memory. This makes
it <emphasis>very</emphasis> efficient to transfer pixmaps to the screen. Pixmaps also act as
an off-screen equivalent of widgets - the QPixmap class is a subclass of 
QPaintDevice, so you can draw on it with a QPainter. Elementary drawing 
operations are usually accelerated by modern graphics. Therefore, a common usage
pattern is to use pixmaps for double buffering. This means, instead of painting
directly on a widget, you paint on a temporary pixmap object and use the
<ulink url="kdeapi:qt/QPaintDevice#bitBlt-1">bitBlt</ulink>
function to transfer the pixmap to the widget. For complex repaints, this helps
to avoid flicker.
</para>

<para>
In contrast, <ulink url="kdeapi:qt/QImage">QImage</ulink> objects 
live on the client side. Their emphasis in on providing direct access to the
pixels of the image. This makes them of use for image manipulation, and things
like loading and saving to disk (QPixmap's load() method takes QImage as 
intermediate step). On the other hand, painting an image on a widget is a
relatively expensive operation, as it implies a transfer to the X server,
which can take some time, especially for large images and for remote servers.
Depending on the color depth, the conversion from QImage to QPixmap may also 
require dithering.
</para>

</simplesect>


<simplesect id="qpainter-drawingtext">
<title>Drawing text</title>

<para>
Text can be drawn with one of the overloaded variants of the method 
QPainter::drawText(). These draw a QString either at a given point or in a given
rectangle, using the font set by QPainter::setFont(). There is also a parameter
which takes an ORed combination of some flags from the enums
<ulink url="kdeapi:qt/Qt#AlignmentFlags-enum">Qt::AlignmentFlags</ulink>
and
<ulink url="kdeapi:qt/Qt#TextFlags-enum">Qt::TextFlags</ulink>
</para>

<para>
Beginning with version 3.0, Qt takes care of the complete text layout even for
languages written from right to left.
</para>

<para>
A more advanced way to display marked up text is the 
<ulink url="kdeapi:qt/QSimpleRichText">QSimpleRichText</ulink> 
class. Objects of this class can be constructed with a piece of text using
a subset of the HTML tags, which is quite rich and provides even tables.
The text style can be customized by using a 
<ulink url="kdeapi/qt/QStyleSheet">QStyleSheet</ulink> (the
documentation of the tags can also be found here). Once the rich text object has
been constructed, it can be rendered on a widget or another paint device with
the QSimpleRichText::draw() method.
</para>

</simplesect>

</sect1>


<sect1 id="graphics-qcanvas">
<title>Structured graphics with QCanvas</title>

<para>
QPainter offers a powerful imaging model for painting on widgets and pixmaps.
However, it can also be cumbersome to use. Each time your widget receives
a paint event, it has to analyze the QPaintEvent::region() or 
QPaintEvent::rect() which has to be redrawn. Then it has to setup a
QPainter and paint all objects which overlap with that region. For example,
image a vector graphics program which allows to drag objects like polygons,
circles and groups of them around. Each time those objects move a bit, the
widget's mouse event handler triggers a paint event for the whole area covered 
by the objects in their old position and in their new position. Figuring
out the necessary redraws and doing them in an efficient way can be difficult,
and it may also conflict with the object-oriented structure of the program's
source code.
</para>

<para>
As an alternative, Qt contains the class 
<ulink url="kdeapi:qt/QCanvas">QCanvas</ulink> in which
you put graphical objects like polygons, text, pixmaps. You may also provide
additional items by subclassing 
<ulink url="kdeapi:qt/QCanvasItem">QCanvasItem</ulink> or
one of its more specialized subclasses. A canvas can be shown on the screen by
one or more widgets of the class
<ulink url="kdeapi:qt/QCanvas">QCanvasView</ulink> which
you have to subclass in order to handle user interactions. Qt takes care of
all repaints of objects in the view, whether they are caused by the widget
being exposed, new objects being created or modified or other things. By using
double buffering, this can be done in an efficient and flicker-free way.
</para>

<para>
Canvas items can overlap each other. In this case, the visible one depends on
the z order which can be assigned by QCanvasItem::setZ(). Items can also be
made visible or invisible. You can also provide a background to be drawn 
"behind" all items and a foreground. For associating mouse events with objects,
in the canvas, there is the method QCanvas::collisions() which returns a list
of items overlapping with a given point. Here we show a screenshot of a canvas
view in action:
</para>

<mediaobject>
<imageobject><imagedata fileref="canvas.png"/></imageobject>
</mediaobject>

<para>
Here, the mesh is drawn in the background. Furthermore, there is a
QCanvasText item and a violet QCanvasPolygon. The butterfly is a
QCanvasPixmap. It has transparent areas, so you can see the underlying
items through it.
</para>

<para>
A tutorial on using QCanvas for writing sprite-based games can be
found <ulink url="http://zez.org/article/articleview/2/1/">here</ulink>.
</para>

</sect1>


<sect1 id="graphics-qglwidget">
<title>3D graphics with OpenGL</title>

<simplesect id="qglwidget-lowlevel">
<title>Low-level interface</title>

<para>
The de facto standard for rendering 3D graphics today is 
<ulink url="http://www.opengl.org">OpenGL</ulink>. Implementations of this
specification come with Microsoft Windows, Mac OS X and XFree86 and often
support the hardware acceleration features offered by modern graphics cards.
OpenGL itself only deals with rendering on a specified area of the framebuffer
through a <emphasis>GL context</emphasis> and does not have any interactions
with the toolkit of the environment
</para>

<para>
Qt offers the widget <ulink url="kdeapi:qt/QGLWidget">QGLWidget</ulink>
which encapsulates a window with an associated GL context. Basically, you use it
by subclassing it and reimplementing some methods.
</para>

<itemizedlist>

<listitem><para>
Instead of reimplementing paintEvent() and using QPainter to draw the widget's
contents, you override paintGL() and use GL commands to render a scene. QLWidget
will take care of making its GL context the current one before paintGL() is
called, and it will flush afterwards.
</para></listitem>

<listitem><para>
The virtual method initializeGL() is called once before the first time resizeGL()
or paintGL() are called. This can be used to construct display lists for objects,
and make any initializations.
</para></listitem>

<listitem><para>
Instead of reimplementing resizeEvent(), you override resizeGL(). This can
be used to set the viewport appropriately.
</para></listitem>

<listitem><para>
Instead of calling update() when the state of the scene has changed - for example
when you animate it with a timer -, you should call updateGL(). This will trigger
a repaint.
</para></listitem>

</itemizedlist>

<para>
In general, QGLWidget behaves just like any other widget, i.e. for example
you can process mouse events as usual, resize the widget and combine it with
others in a layout.
</para>

<mediaobject>
<imageobject><imagedata fileref="opengl.png"/></imageobject>
</mediaobject>

<para>
Qt contains some examples of QGLWidget usage in its <literal>demo</literal>
example. A collection of tutorials can be found 
<ulink url="http://www.libsdl.org/opengl/intro.html">here</ulink>,
and more information and a reference of OpenGL is available on the
<ulink url="http://www.opengl.org">OpenGL homepage</ulink>.
</para>

</simplesect>


<simplesect id="qglwidget-highlevel">
<title>High-level interfaces</title>

<para>
OpenGL is a relatively low-level interface for drawing 3D graphics. In the same
way QCanvas gives the programmer a higher-level interface which details with
objects and their properties, there are also high-level interfaces for 3D graphics.
One of the most popular is Open Inventor. Originally a technology developed by SGI,
there is today also the open source implementation 
<ulink url="http://www.coin3d.org">Coin</ulink>, complemented by a toolkit binding to Qt
called SoQt. 
</para>

<para>
The basic concept of Open Inventor is that of a <emphasis>scene</emphasis>.
A scene can be loaded from disk and saved in a special format closely related
to <ulink url="http://www.vrml.org">VRML</ulink>. A scene consists of a
collection of objects called <emphasis>nodes</emphasis>. Inventor already 
provides a rich collection of reusable nodes, such as cubes, cylinders and
meshes, furthermore light sources, materials, cameras etc. Nodes are 
represented by C++ classes and can be combined and subclassed.
</para>

<para>
An introduction to Inventor can be found 
<ulink url="http://www.motifzone.com/tmd/articles/OpenInventor/OpenInventor.html">here</ulink>
(in general, you can substitute all mentions of SoXt by SoQt in this article).
</para>

</simplesect>

</sect1>

</chapter>



<chapter id="userinterface">
<title>User interface</title>

<sect1 id="userinterface-actionpattern">
<title>The action pattern</title>

<para></para>

</sect1>


<sect1 id="userinterface-xmlgui">
<title>Defining menus and toolbars in XML</title>

<simplesect id="xmlgui-intro">
<title>Introduction</title>

<para>
While the <link linkend="userinterface-actionpattern">action pattern</link>
allows to encapsulate  actions triggered by the user in an object which can be
"plugged" somewhere in the menu bars or toolbars, it does not by itself solve
the problem of  constructing the menus themselves. In particular, you have to
build all popup menus in C++ code and explicitly insert the actions in a
certain order, under consideration of the style guide for standard actions.
This makes it pretty difficult to allow the user to customize the menus or
change shortcuts to fit his needs, without changing the source code.
</para>

<para>
This problem is solved by a set of classes called <literal>XMLGUI</literal>.
Basically, this separates actions (coded in C++) from their appearance in menu
bars and tool bars (coded in XML). Without modifying any source code, menus
can be simply customized by adjusting an XML file. Furthermore, it helps
to make sure that standard actions (such as
<menuchoice><guimenu>File</guimenu><guimenuitem>Open</guimenuitem></menuchoice>
or <menuchoice><guimenu>Help</guimenu><guimenuitem>About</guimenuitem></menuchoice>)
appear in the locations suggested by the style guide. XMLGUI is especially
important for modular programs, where the items appearing in the menu bar may
come from many different plugins or parts.
</para>

<para>
KDE's class for toplevel windows, 
<ulink url="kdeapi:tdeui/KMainWindow.html">KMainWindow</ulink>,
inherits 
<ulink url="kdeapi:tdeui/KXMLGUIClient.html">KXMLGUIClient</ulink>
and therefore supports XMLGUI out of the box. All actions created within it must
have the client's <literal>actionCollection()</literal> as parent. A call to
<literal>createGUI()</literal> will then build the whole set of menu and tool
bars defined the applications XML file  (conventionally with the suffix
<literal>ui.rc</literal>). 
</para>

</simplesect>


<simplesect id="xmlgui-kviewexample">
<title>An example: Menu in KView</title>

<para>
In the following, we take KDE's image view <application>KView</application> as
example. It has a <literal>ui.rc</literal> file named
<filename>kviewui.rc</filename> which is installed with the 
<filename>Makefile.am</filename> snippet
</para>

<programlisting>
rcdir = $(kde_datadir)/kview
rc_DATA = kviewui.rc
</programlisting>

<para>
Here is an excerpt from the <filename>kviewui.rc</filename> file. For
simplicity, we show only the definition of the <guimenu>View</guimenu> menu.
</para>

<programlisting>
&lt;!DOCTYPE kpartgui&gt;
&lt;kpartgui name="kview"&gt;
  &lt;MenuBar&gt;
    &lt;Menu name="view" &gt;
      &lt;Action name="zoom50" /&gt;
      &lt;Action name="zoom100" /&gt;
      &lt;Action name="zoom200" /&gt;
      &lt;Action name="zoomMaxpect" /&gt;
      &lt;Separator/&gt;
      &lt;Action name="fullscreen" /&gt;
    &lt;/Menu&gt;
  &lt;/MenuBar&gt;
&lt;/kpartgui&gt;
</programlisting>

<para>
The corresponding part of the setup in C++ is:
</para>

<programlisting>
  KStdAction::zoomIn    ( this, SLOT(slotZoomIn()), actionCollection() );
  KStdAction::zoomOut   ( this, SLOT(slotZoomOut()), actionCollection() );
  KStdAction::zoom      ( this, SLOT(slotZoom()), actionCollection() );
  new KAction           ( i18n("&amp;Half size"), ALT+Key_0, 
                          this, SLOT(slotHalfSize()), 
                          actionCollection(), "zoom50" );
  new KAction           ( i18n("&amp;Normal size"), ALT+Key_1,
                          this, SLOT(slotDoubleSize()), 
                          actionCollection(), "zoom100" );
  new KAction           ( i18n("&amp;Double size"), ALT+Key_2, 
                          this, SLOT(slotDoubleSize()), 
                          actionCollection(), "zoom200" );
  new KAction           ( i18n("&amp;Fill Screen"), ALT+Key_3, 
                          this, SLOT(slotFillScreen()), 
                          actionCollection(), "zoomMaxpect" );
  new KAction           ( i18n("Fullscreen &amp;Mode"), CTRL+SHIFT+Key_F, 
                          this, SLOT(slotFullScreen()), 
                          actionCollection(), "fullscreen" );
</programlisting>

<para>
The <guimenu>View</guimenu> menu resulting from this GUI definition looks like
in this screenshot:
</para>

<mediaobject>
<imageobject><imagedata fileref="kview-menu.png"/></imageobject>
</mediaobject>

<para>
The XML file begins with a document type declaration. The DTD for kpartgui can
be found in the tdelibs sources in <filename>tdeui/kpartgui.dtd</filename>. The
outermost element of the file contains the instance name of the application as
attribute. It can also contain a version number in the form "version=2". This
is useful when you release new versions of an application with a changed menu
structure, e.g. with more features. If you bump up the version number of the
<literal>ui.rc</literal> file, KDE makes sure that any customized version of
the file is discarded and the new  file is used instead.
</para>

<para>
The next line, <literal>&lt;MenuBar&gt;</literal>, contains a declaration of a
menu bar. You can also insert any number of <literal>&lt;ToolBar&gt;</literal>
declarations in order to create some tool bars. The menu contains a submenu
with the name "view". This name is already predefined, and thus you see a
translated version of the word "View" in the screenshot. If you declare your
own submenus, you have to add the title explicitly. For example,
<application>KView</application> has a submenu with the title "Image" which is
declared as follows:
</para>

<programlisting>
&lt;Menu name="image" &gt;
   &lt;text&gt;&amp;amp;Image&lt;/text&gt;
   ...
&lt;/Menu&gt;
</programlisting>

<para>
In KDE's automake framework, such titles are automatically extracted and put
into the application's <ulink url="tde-i18n-howto.html"><literal>.po</literal></ulink>
file , so it is considered by translators. Note that you have to write the
accelerator marker "&amp;" in the form XML compliant form "&amp;amp;".
</para>

<para>
Let us come back to the example. <application>KView</application>'s
<guimenu>View</guimenu> menu contains a couple of custom actions:
<literal>zoom50</literal>, <literal>zoom100</literal>,
<literal>zoom200</literal>, <literal>zoomMaxpect</literal> and
<literal>fullscreen</literal>, declared with a
<literal>&lt;Action&gt;</literal> element. The separator in the
screenshots corresponds to the <literal>&lt;Separator&gt;</literal> element. 
</para>

<para>
You will note that some menu items do not not have a corresponding element in 
the XML file. These are <emphasis>standard actions</emphasis>. Standard
actions are created by the class 
<ulink url="kdeapi:tdeui/KStdAction.html">KStdAction</ulink>.
When you create such actions in your application (such as in the C++ example
above), they will automatically be inserted in a prescribed position, and
possibly with an icon and a shortcut key. You can look up these locations in
the file <filename>tdeui/ui_standards.rc</filename> in the tdelibs sources.
</para>

</simplesect>


<simplesect id="xmlgui-konqexample">
<title>An example: Toolbars in Konqueror</title>

<para>
For the discussion of toolbars, we switch to
<application>Konqueror</application>'s GUI definition. This excerpt defines
the location bar, which contains the input field for URLs.
</para>

<programlisting>
&lt;ToolBar name="locationToolBar" fullWidth="true" newline="true" &gt;
  &lt;text&gt;Location Toolbar&lt;/text&gt;
  &lt;Action name="clear_location" /&gt;
  &lt;Action name="location_label" /&gt;
  &lt;Action name="toolbar_url_combo" /&gt;
  &lt;Action name="go_url" /&gt;
&lt;/ToolBar&gt;
</programlisting>

<para>
The first thing we notice is that there are a lot more attributes than for
menu bars. These include:
</para>

<itemizedlist>

<listitem><para>
<literal>fullWidth</literal>: Tells XMLGUI that the toolbar has the same width as the
    toplevel window. Af this is "false", the toolbar only takes as much space as
    necessary, and further toolbars are put in the same row.
</para></listitem>

<listitem><para>
<literal>newline</literal>: This is related to the option above. If newline is "true",
the toolbar starts a new row. Otherwise it may be put in the row together
with the previous toolbar.
</para></listitem>

<listitem><para>
<literal>noEdit</literal>: Normally toolbars can be customized by the user,
e.g. in <menuchoice><guimenu>Settings</guimenu><guimenuitem>Configure
Toolbars</guimenuitem></menuchoice> in
<application>Konqueror</application>. Setting this option to "true" marks this
toolbar as not editable. This is important for toolbars which are filled with
items at runtime, e.g. <application>Konqueror</application>'s bookmark toolbar.
</para></listitem>

<listitem><para>
<literal>iconText</literal>: Tells XMLGUI to show the text of the action next to the
icon. Normally, the text is only shown as a tooltip when the mouse cursor
remains over the icon for a while. Possible values for this attribute are
"icononly" (shows only the icon), "textonly" (shows only the text),
"icontextright" (shows the text on the right side of the icon) and 
"icontextbottom" (shows the text beneath the icon).
</para></listitem>


<listitem><para>
<literal>hidden</literal>: If this is "true", the toolbar is not visible initially
and must be activated by some menu item.
</para></listitem>


<listitem><para>
<literal>position</literal>: The default for this attribute is "top", meaning that the
toolbar is positioned under the menu bar. For programs with many tools,
such as graphics programs, it may be interesting to replace this with
"left", "right" or "bottom".
</para></listitem>

</itemizedlist>

</simplesect>


<simplesect id="xmlgui-dynamical">
<title>Dynamical menus</title>

<para>
Obviously, an XML can only contain a static description of a user interface.
Often, there are menus which change at runtime. For example,
<application>Konqueror</application>'s <guimenu>Location</guimenu> menu
contains a set of items <guimenuitem>Open with Foo</guimenuitem> with the
applications able to load a file with a given MIME type. Each time the
document shown changes, the list of menu items is updated. XMLGUI is prepared
to handle such cases with the notion of <emphasis>action lists</emphasis>.
An action list is declared as one item in the XML file, but consists of
several actions which are plugged into the menu at runtime. The above example
is implemented with the following declaration in
<application>Konqueror</application>'s XML file:
</para>

<programlisting>
&lt;Menu name="file"&gt;
  &lt;text&gt;&amp;amp;Location&lt;/text&gt;
  ...
  &lt;ActionList name="openwith"&gt;
  ...
&lt;/Menu&gt;
</programlisting>

<para>
The function <function>KXMLGUIClient::plugActionList()</function> is then used
to add actions to be displayed, whereas the function
<function>KXMLGuiClient::unplugActionList()</function> removes all
plugged actions. The routine responsible for updating looks as follows:
</para>

<programlisting>
void MainWindow::updateOpenWithActions()
{
    unplugActionList("openwith");
    openWithActions.clear();
    for ( /* iterate over the relevant services */ ) {
        KAction *action = new KAction( ...);
        openWithActions.append(action);
    }
    plugActionList("openwith", openWithActions);
}
</programlisting>

<para>
Note that in contrast to the static actions, the ones created here are 
<emphasis>not</emphasis> constructed with the action collection as parent, and
you are responsible for deleting them for yourself. The simplest way to achievethis
is by using <literal>openWithActions.setAutoDelete(true)</literal> in the above
example.
</para>

</simplesect>


<simplesect id="xmlgui-contextmenus">
<title>Context menus</title>

<para>
The examples above only contained cases where a main window's menubar and 
toolbars were created. In the cases, the processes of constructing these
containers is completely hidden from you behind the
<function>createGUI()</function> call (except if you have custom containers).
However, there are cases, where you want to construct other containers and
populate them with GUI definitions from the XML file. One such example are
context menus. In order to get a pointer to a context menu, you have to
ask the client's factory for it:
</para>

<programlisting>
void MainWindow::popupRequested()
{
    QWidget *w = factory()->container("context_popup", this);
    QPopupMenu *popup = static_cast&lt;QPopupMenu *&gt;(w);
    popup->exec(QCursor::pos());
}
</programlisting>

<para>
The method <function>KXMLGUIFactory::container()</function> used above looks
whether it finds a container in the XML file with the given name. Thus, a
possible definition could look as follows:
</para>

<programlisting>
...
&lt;Menu name="context_popup"&gt;
  &lt;Action name="file_add"/&gt;
  &lt;Action name="file_remove"/&gt;
&lt;/Menu&gt;
...
</programlisting>

</simplesect>

</sect1>


<sect1 id="help">
<title>Providing online help</title>

<para>
Making a program easy and intuitive to use involves a wide range of
facilities which are usually called online help. Online help has several,
partially conflicting goals: on the one, it should give the user answers
to the question "How can I do a certain task?", on the other hand it
should help the user exploring the application and finding features he
doesn't yet know about. It is important to recognize that this can only
be achieved by offering several levels of help:
</para>

<itemizedlist>

<listitem><para>
Tooltips are tiny labels that pop up over user interface elements when
the mouse remains there longer. They are especially important for tool-
bars, where icons are not always sufficient to explain the purpose of
a button. 
</para></listitem>

<listitem><para>
"What's this?" help is usually a longer and richer explanation of a widget
or a menu item. It is also more clunky to use: In dialogs, it can be invoked
in two ways: either by pressing
<keycombo><keycap>Shift</keycap><keycap>F1</keycap></keycombo> or by clicking
on the question mark in the title bar (where the support of the latter depends
on the window manager). The mouse pointer then turns into an arrow with a
question mark, and the help window appears when a user interfact element has
been clicked. "What's this?" help for menu items is usually activated by a
button in the toolbar which contains an arrow and a question mark. 
</para></listitem>

<listitem><para>
The problem with this approach is that the user can't see whether a widget
provides help or not. When the user activates the question mark button and
doesn't get any  help window when clicking on a user interface element, he
will get frustrated very quickly.
</para>

<para>
The advantage of "What's this?" help windows as provided by Qt and KDE is that
they can contain <ulink url="kdeapi:qt/QStyleSheet">rich text</ulink>, 
i.e. the may contain different fonts, bold and italic text and even images and tables.
</para>

<para>
An example of "What's this?" help:
</para>

<mediaobject>
<imageobject><imagedata fileref="whatsthis.png"/></imageobject>
</mediaobject>

</listitem>

<listitem><para>
Finally, every program should have a manual. A manual is normally viewed in
<application>KHelpCenter</application> by activating the
<guimenu>Help</guimenu> menu. That means, a complete additional application
pops up and diverts the user from his work. Consequently, consulting the
manual should only be necessary if other facilities like tooltips and what's
this help are not sufficient. Of course, a manual has the advantage that it
does not explain single, isolated aspects of the user interface. Instead, it
can explain aspects of the application in a greater context. Manuals for KDE
are written using the <ulink url="http://i18n.kde.org">DocBook</ulink> markup
language.
</para></listitem>

</itemizedlist>

<para>
From the programmer's point of view, Qt provides an easy to use API for online
help. To assign a tooltip to widget, use the 
<ulink url="kdeapi:qt/QToolTip">QToolTip</ulink> class.
</para>

<programlisting>
QToolTip::add(w, i18n("This widget does something."))
</programlisting>

<para>
If the menu bars and tool bars are created using the <ulink url="actionpattern.html">
action pattern</ulink>, the string used as tooltip is derived from the first argument
of the <ulink url="kdeapi:tdeui/KAction.html">KAction</ulink> constructor:
</para>

<programlisting>
action = new KAction(i18n("&amp;Delete"), "editdelete", 
                     SHIFT+Key_Delete, actionCollection(), "del")
</programlisting>

<para>
Here it is also possible to assign a text which is shown in the status bar when the 
respective menu item is highlighted:
</para>

<programlisting>
action->setStatusText(i18n("Deletes the marked file"))
</programlisting>

<para>
The API for "What's this?' help is very similar. In dialogs, use the following
code:
</para>

<programlisting>
QWhatsThis::add(w, i18n("&lt;qt&gt;This demonstrates &lt;b&gt;Qt&lt;/b&gt;'s"
                        " rich text engine.&lt;ul&gt;"
                        "&lt;li&gt;Foo&lt;/li&gt;"
                        "&lt;li&gt;Bar&lt;/li&gt;"
                        "&lt;/ul&gt;&lt;/qt&gt;"))
</programlisting>

<para>
For menu items, use
</para>

<programlisting>
action->setWhatsThis(i18n("Deletes the marked file"))
</programlisting>

<para>
The invocation of <application>KHelpCenter</application> is encapsulated in the
<ulink url="kdeapi:tdecore/TDEApplication">TDEApplication</ulink>
class. In order to show the manual of your application, just use 
</para>

<programlisting>
kapp->invokeHelp()
</programlisting>

<para>
This displays the first page with the table of contents. When you want to
display only a certain section of the manual, you can give an additional
argument to <function>invokeHelp()</function> determining the anchor which
the browser jumps to.
</para>

</sect1>

</chapter>



<chapter id="components">
<title>Components and services</title>

<sect1 id="components-services">
<title>KDE services</title>

<simplesect id="services-whatarekdeservices">
<title>What are KDE services?</title>

<para>
The notion of a <emphasis>service</emphasis> is a central concept in KDE's
modular architecture. There is no strict technical implementation connected
with this term - services can be plugins in the form of shared libraries,
or they can be programs controlled via <ulink url="dcop.html">DCOP</ulink>.
By claiming to be of a certain <emphasis>service type</emphasis>, a service
promises to implement certain APIs or features. In C++ terms, one can think
of a service type as an abstract class, and a service as an implementation
of that interface.
</para>

<para>
The advantage of this separation is clear: An application utilizing a service
type does not have to know about possible implementations of it. It just uses
the APIs associated with the service type. In this way, the used service can be
changed without affecting the application. Also, the user can configure which
services he prefers for certain features.
</para>

<para>
Some examples:
</para>

<itemizedlist>

<listitem><para>
The HTML rendering engine used in <application>Konqueror</application> is an
embedable component that implements the service types
<literal>KParts/ReadOnlyPart</literal> and <literal>Browser/View</literal>.
</para></listitem>
<listitem><para>
In <application>TDevelop</application> HEAD, most functionality is packaged in
plugins with the service type <literal>TDevelop/Part</literal>. At startup,
all services with this type are loaded, such that you can extend the IDE in a
very flexible way.
</para></listitem>
<listitem><para>
In the icon view, <application>Konqueror</application> displays - if enabled -
thumbnail pictures of images, HTML pages, PDF and text files. This ability can
be extended. If you want it to display preview pictures of your own data files
with some MIME type, you can implement a service with service type
<classname>ThumbCreator</classname>.
</para></listitem>

</itemizedlist>

<para>
Obviously, a service is not only characterized by the service types it
implements, but also by some <emphasis>properties</emphasis>. For example, a
ThumbCreator does not only claim to implement the C++ class with the type
<classname>ThumbCreator</classname>, it also has a list of MIME types it is
responsible for. Similarly, TDevelop parts have the programming language they
support as a property. When an application requests a service type, it can
also list constraints on the properties of the service. In the above example,
when TDevelop loads the plugins for a Java project, it asks only for the
plugins which have Java as the programming language property. For this 
purpose, KDE contains a full-blown CORBA-like <emphasis>trader</emphasis> with
a complex query language.
</para>

</simplesect>


<simplesect id="services-definingservicetypes">
<title>Defining service types</title>

<para>
New service types are added by installing a description of them into the
directory <filename>TDEDIR/share/servicetypes</filename>. In an automake
framework, this can be done with this <filename>Makefile.am</filename>
snippet:
</para>

<programlisting>
kde_servicetypesdir_DATA = tdeveloppart.desktop
EXTRA_DIST = $(kde_servicetypesdir_DATA)
</programlisting>

<para>
The definition <filename>tdeveloppart.desktop</filename> of a
<application>TDevelop</application> part looks as follows:
</para>

<programlisting>
[Desktop Entry]
Type=ServiceType
X-TDE-ServiceType=TDevelop/Part
Name=TDevelop Part

[PropertyDef::X-TDevelop-Scope]
Type=QString

[PropertyDef::X-TDevelop-ProgrammingLanguages]
Type=QStringList

[PropertyDef::X-TDevelop-Args]
Type=QString
</programlisting>

<para>
In addition to the usual entries, this example demonstrates how you declare
that a service has some properties. Each property definition corresponds
to a group <literal>[PropertyDef::name]</literal> in the configuration file. In
this group, the <literal>Type</literal> entry declares the type of the property.
Possible types are everything that can be stored in a 
<ulink url="kdeapi:qt/QVariant">QVariant</ulink>.
</para>

</simplesect>


<simplesect id="services-defininglibraryservices">
<title>Defining shared library services</title>

<para>
Service definitions are stored in the directory
<filename>TDEDIR/share/services</filename>:
</para>

<programlisting>
kde_servicesdir_DATA = kdevdoxygen.desktop
EXTRA_DIST = $(kde_servicesdir_DATA)
</programlisting>

<para>
The content of the following example file
<filename>kdevdoxygen.desktop</filename> defines the
<literal>KDevDoxygen</literal> plugin with the service type
<literal>TDevelop/Part</literal>:
</para>

<programlisting>
[Desktop Entry]
Type=Service
Comment=Doxygen
Name=KDevDoxygen
ServiceTypes=TDevelop/Part
X-TDE-Library=libkdevdoxygen
X-TDevelop-ProgrammingLanguages=C,C++,Java
X-TDevelop-Scope=Project
</programlisting>

<para>
In addition to the usual declarations, an important entry is 
<literal>X-TDE-Library</literal>. This contains the name of the libtool
library (without the <literal>.la</literal> extension). It also fixes
(with the prefix <literal>init_</literal> prepended) the name of the exported
symbol in the library which returns an object factory. For the above example,
the library must contain the following function:
</para>

<programlisting>
extern "C" {
    void *init_libkdevdoxygen()
    {
        return new DoxygenFactory;
    }
};
</programlisting>

<para>
The type of the factory class <classname>DoxygenFactory</classname> depends on
the specific service type the service implements. In our example of a TDevelop
plugin, the factory must be a <classname>KDevFactory</classname> (which
inherits <classname>KLibFactory</classname>). More common examples are
<ulink url="kdeapi:kparts/KParts::Factory">KParts::Factory</ulink>
which is supposed to produce 
<ulink url="kdeapi:kparts/KParts::ReadOnlyPart">KParts::ReadOnlyPart</ulink>
objects or in most cases the generic
<ulink url="kdeapi:tdecore/KLibFactory">KLibFactory</ulink>.
</para>

</simplesect>


<simplesect id="services-usinglibraryservices">
<title>Using shared library services</title>

<para>
In order to use a shared library service in an application, you need to obtain a
<ulink url="kdeapi:kio/KService.html">KService</ulink> object
representing it. This is discussed in the 
<ulink url="mime.html">section about MIME types</ulink> (and in a section about the
trader to be written :-)
</para>

<para>
With the <classname>KService</classname> object at hand, you can very simply
load the library and get a pointer to its factory object:
</para>

<programlisting>
KService *service = ...
QString libName = QFile::encodeName(service->library());
KLibFactory *factory = KLibLoader::self()->factory(libName);
if (!factory) {
    QString name = service->name();
    QString errorMessage = KLibLoader::self()->lastErrorMessage();
    KMessageBox::error(0, i18n("There was an error loading service %1.\n"
                               "The diagnostics from libtool is:\n%2")
                          .arg(name).arg(errorMessage);
}
</programlisting>

<para>
From this point, the further proceeding depends again on the service type. For
generic plugins, you create objects with the method
<ulink url="kdeapi:tdecore/KLibFactory.html#ref3">KLibFactory::create()</ulink>.
For KParts, you must cast the factory pointer to the more specific KParts::Factory and use
its create() method:
</para>

<programlisting>
if (factory->inherits("KParts::Factory")) {
    KParts::Factory *partFactory = static_cast&lt;KParts::Factory*&gt;(factory);
    QObject *obj = partFactory->createPart(parentWidget, widgetName, 
                                           parent, name, "KParts::ReadOnlyPart");
    ...
} else {
    cout &lt;&lt; "Service does not implement the right factory" &lt;&lt; endl;
}
</programlisting>

</simplesect>


<simplesect id="services-definingdcopservices">
<title>Defining DCOP services</title>

<para>
A DCOP service is usually implemented as a program that is started up when it is
needed. It then goes into a loop and listens for DCOP connections. The program 
may be an interactive one, but it may also run completely or for a part of its
lifetime as a daemon in the background without the user noticing it. An example 
for such a daemon is <literal>kio_uiserver</literal>, which implements user interaction 
such as progress dialog for the KIO library. The advantage of such a centralized 
daemon in this context is that e.g. the download progress for several different 
files can be shown in one window, even if those downloads were initiated from 
different applications.
</para>

<para>
A DCOP service is defined differently from a shared library service. Of course,
it doesn't specify a library, but instead an executable. Also, DCOP services 
do not specify a ServiceType line, because usually they are started by their
name. As additional properties, it contains two lines: 
</para>

<para>
<literal>X-DCOP-ServiceType</literal> specifies the way the service is
started. The value <literal>Unique</literal> says that the service must not be
started more than once. This means, if you try to start this service (e.g. via 
<ulink url="kdeapi:tdecore/TDEApplication.html#startServiceByName">
TDEApplication::startServiceByName()</ulink>, KDE looks whether it is already 
registered with DCOP and uses the running service. If it is not registered yet, 
KDE will start it up and wait until is registered. Thus, you can immediately 
send DCOP calls to the service. In such a case, the service should be implemented
as a 
<ulink url="kdeapi:tdecore/KUniqueApplication.html">KUniqueApplication</ulink>.
</para>

<para>
The value <literal>Multi</literal> for <literal>X-DCOP-ServiceType</literal> says that multiple
instances of the service can coexist, so every attempt to start the service
will create another process. As a last possibility the value <literal>None</literal>
can be used. In this case, a start of the service will not wait until it
is registered with DCOP.
</para>

<para>
<literal>X-TDE-StartupNotify</literal> should normally be set to false. Otherwise, when
the program is started, the task bar will show a startup notification, or, depending
on the user's settings, the cursor will be changed.
</para>

<para>
Here is the definition of <literal>kio_uiserver</literal>:
</para>

<programlisting>
[Desktop Entry]
Type=Service
Name=kio_uiserver
Exec=kio_uiserver
X-DCOP-ServiceType=Unique
X-TDE-StartupNotify=false
</programlisting>

</simplesect>


<simplesect id="services-usingdcopservices">
<title>Using DCOP services</title>

<para>
A DCOP service is started with one of several methods in the TDEApplication
class:
</para>

<programlisting>
DCOPClient *client = kapp->dcopClient();
client->attach();
if (!client->isApplicationRegistered("kio_uiserver")) {
    QString error;
    if (TDEApplication::startServiceByName("kio_uiserver", QStringList(), &amp;error))
        cout &lt;&lt; "Starting kioserver failed with message " &lt;&lt; error &lt;&lt; endl;
}
...
QByteArray data, replyData;
QCString replyType;
QDataStream arg(data, IO_WriteOnly);
arg &lt;&lt; true;
if (!client->call("kio_uiserver", "UIServer", "setListMode(bool)", 
                  data, replyType, replyData))
    cout &lt;&lt; "Call to kio_uiserver failed" &lt;&lt; endl;
...
</programlisting>

<para>
Note that the example of a DCOP call given here uses explicit marshalling
of arguments. Often you will want to use a stub generated by dcopidl2cpp
instead, because it is much simpler and less error prone.
</para>

<para>
In the example given here, the service was started "by name", i.e. the
first argument to <function>TDEApplication::startServiceByName()</function> is
the name is appearing in the <literal>Name</literal> line of the desktop
file. An alternative is to use
<function>TDEApplication::startServiceByDesktopName()</function>, which takes
the file name of its desktop file as argument, i.e. in this case
<literal>"kio_uiserver.desktop"</literal>.
</para>

<para>
All these calls take a list of URLs as a second argument, which is given
to the service on the command line. The third argument is a pointer to a
<classname>QString</classname>. If starting the service fails, this argument
is set to a translated error message.
</para>

</simplesect>

</sect1>


<sect1 id="components-mime">
<title>MIME types</title>

<simplesect id="mime-whataremimetypes">
<title>What are MIME types?</title>

<para>
MIME types are used to describe the content type of files or data
chunks. Originally they were introduced in order to allow sending around image
or sound files etc. by e-mail (MIME stands for "Multipurpose Internet Mail
Extensions"). Later this system was also used by web browsers to determine how
to present data sent by a web server to the user. For example, an HTML page
has a MIME type "text/html", a postscript file "application/postscript".  In
KDE, this concept is used at a variety of places:
</para>

<itemizedlist>

<listitem><para>
In <application>Konqueror</application>'s icon view, files are represented by
icons. Each MIME type has a certain associated icon shown here.
</para></listitem>

<listitem><para>
When you click onto a file icon or a file name in
<application>Konqueror</application>, either the file is shown in an embedded
view, or an application associated with the file type is opened.  
</para></listitem>

<listitem><para>
When you drag and drop some data from one application to another (or
within the same application), the drop target may choose to accept only
certain data types. Furthermore, it will handle image data different
from textual data.
</para></listitem>

<listitem><para>
Clipboard data has a MIME type. Traditionally, X programs only handle 
pixmaps or texts, but with Qt, there are no restrictions on the data type.
</para></listitem>

</itemizedlist>

<para>
From the above examples, it is clear that MIME handling is a complex issue.
First, it is necessary to establish a mapping from file names to MIME types.
KDE goes one step further in allowing even file contents to be mapped to
MIME types, for cases in which the file name is not available. Second, it
is necessary to map MIME types to applications or libraries which can view
or edit a file with a certain type, or create a thumbnail picture for it.
</para>

<para>
There is a variety of APIs to figure out the MIME type of data or files. In 
general, there is a certain speed/reliability trade-off you have to make. You 
can find out the type of a file by examining only its file name (i.e. in most 
cases the file name extension). For example, a file
<filename>foo.jpg</filename> is normally "image/jpeg". In cases where the
extension is stripped off this is not safe, and you actually  have to look at
the contents of the file. This is of course slower, in  particular for files
that have to be downloaded via HTTP first. The content-based method is based
on the file <filename>TDEDIR/share/mimelnk/magic</filename> and therefore
difficult to extend. But in general, MIME type information can easily be made
available to the system by installing a <literal>.desktop</literal> file, and
it is efficiently and conveniently available through the KDE libraries.
</para>

</simplesect>


<simplesect id="mime-definingmimetypes">
<title>Defining MIME types</title>

<para>
Let us define a type <literal>"application/x-foo"</literal> for our new
<application>foobar</application> program. To this end, you have to write a
file <filename>foo.desktop</filename> and install it into
<filename>TDEDIR/share/mimelnk/application</filename>. (This is the usual
location, which may differ between distributions). This can be done by adding
this to the <filename>Makefile.am</filename>:
</para>

<programlisting>
mimedir = $(kde_mimedir)/application
mime_DATA = foo.desktop
EXTRA_DIST = $(mime_DATA)
</programlisting>

<para>
The file <filename>foo.desktop</filename> should look as follows:
</para>

<programlisting>
[Desktop Entry]
Type=MimeType
MimeType=application/x-foo
Icon=fooicon
Patterns=*.foo;
DefaultApp=foobar
Comment=Foo Data File
Comment[de]=Foo Datei
</programlisting>

<para>
The <literal>"Comment"</literal> entry is supposed to be translated. Since the
<filename>.desktop</filename> file  specifies an icon, you should also install
an icon <filename>fooicon.png</filename>, which represents the file e.g. in
<application>Konqueror</application>.
</para>

<para>
In the KDE libraries, such a type definition is mapped to an instance of the 
class <ulink url="kdeapi:kio/KMimeType.html">KMimeType</ulink>.
Use this like in the following example:
</para>

<programlisting>
KMimeType::Ptr type = KMimeType::mimeType("application/x-foo");
cout &lt;&lt; "Type:    " &lt;&lt; type->name() &lt; endl;
cout &lt;&lt; "Icon:    " &lt;&lt; type->icon() &lt; endl;
cout &lt;&lt; "Comment: " &lt;&lt; type->icon() &lt; endl;
QStringList patterns = type->patterns();
QStringList::ConstIterator it;
for (it = patterns.begin(); it != patterns.end(); ++it)
  cout &lt;&lt; "Pattern: " &lt;&lt; (*it) &lt;&lt; endl;
</programlisting>

</simplesect>


<simplesect id="mime-determiningmimetypes">
<title>Determining the MIME type of data</title>

<para>
The fast method for determining the type of a file is
<function>KMimeType::findByURL()</function>. This looks for the URL string and
in most cases determines the type from the extension. For certain protocols
(e.g. http, man, info), this mechanism is not used. For example, CGI scripts
on web servers written in Perl often have the extension
<literal>.pl</literal>, which would indicate a
<literal>"text/x-perl"</literal> type. However, we file delivered by the
server is the output of this script, which is normally HTML. For such a case,
<function>KMimeType::findByURL()</function> returns the MIME type
<literal>"application/octet-stream"</literal> (available through
<function>KMimeType::defaultMimeType()</function>), which indicates a failure
to find out the type.
</para>

<programlisting>
KMimeType::Ptr type = KMimeType::findByURL("/home/bernd/foobar.jpg");
if (type->name() == KMimeType::defaultMimeType())
    cout &lt;&lt; "Could not find out type" &lt;&lt; endl;
else
    cout &lt;&lt; "Type: " &lt;&lt; type->name() &lt;&lt; endl;
</programlisting>

<para>
(this method has some more arguments, but these are undocumented, so simply
forget about them.)
</para>

<para>
You may want to find out a MIME from the contents of file instead of
the file name. This is more reliable, but also slower, as it requires
reading a part of the file. This is done with the 
<ulink url="kdeapi:kio/KMimeMagic.html">KMimeMagic</ulink> 
class, which has different error handling:
</para>

<programlisting>
KMimeMagicResult *result = KMimeMagic::self()->findFileType("/home/bernd/foobar.jpg");
if (!result || !result->isValid())
    cout &lt;&lt; "Could not find out type" &lt;&lt; endl;
else
    cout &lt;&lt; "Type: " &lt;&lt; result->mimeType() &lt;&lt; endl;
</programlisting>

<para>
As a variant of this function, you can also determine the type of a memory
chunk. This is e.g. used in <application>Kate</application> in order to find
out the highlighting mode:
</para>

<programlisting>
QByteArray array;
...
KMimeMagicResult *result = KMimeMagic::self()->findBufferType(array);
if (!result || !result->isValid())
    cout &lt;&lt; "Could not find out type" &lt;&lt; endl;
else
    cout &lt;&lt; "Type: " &lt;&lt; result->mimeType() &lt;&lt; endl;
</programlisting>

<para>
Of course, even KMimeMagic is only able to determine a file type from the
contents of a local file. For remote files, there is a further possibility:
</para>

<programlisting>
KURL url("http://developer.kde.org/favicon.ico");
QString type = KIO::NetAccess::mimetype(url);
if (type == KMimeType::defaultMimeType())
    cout &lt;&lt; "Could not find out type" &lt;&lt; endl;
else
    cout &lt;&lt; "Type: " &lt;&lt; type &lt;&lt; endl;
</programlisting>

<para>
This starts a KIO job to download a part of the file and check this.
Note that this function is perhaps quite slow and blocks the program. Normally
you will only want to use this if <function>KMimeType::findByURL()</function>
has returned <literal>"application/octet-stream"</literal>.
</para>

<para>
On the other hand, if you do not want to block your application, you can also 
explicitly start the KIO job and connect to some of its signals:
</para>

<programlisting>
void FooClass::findType()
{
    KURL url("http://developer.kde.org/favicon.ico");
    KIO::MimetypeJob *job = KIO::mimetype(url);
    connect( job, SIGNAL(result(KIO::Job*)),
             this, SLOT(mimeResult(KIO::Job*)) );
}

void FooClass::mimeResult(KIO::Job *job)
{
    if (job->error())
        job->showErrorDialog();
    else
        cout &lt;&lt; "MIME type: " &lt;&lt; ((KIO::MimetypeJob *)job)->mimetype() &lt;&lt; endl;
}
</programlisting>

</simplesect>


<simplesect id="mime-mappingmimetypes">
<title>Mapping a MIME type to an application or service</title>

<para>
When an application is installed, it installs a <literal>.desktop</literal>
file which contains a list of MIME types this application can load. Similarly,
components like KParts make this information available by their service
<literal>.desktop</literal> files. So in general, there are several programs
and components which can process a given MIME type. You can obtain such a list
from the class <classname>KServiceTypeProfile</classname>:
</para>

<programlisting>
KService::OfferList offers = KServiceTypeProfile::offers("text/html", "Application");
KService::OfferList::ConstIterator it;
for (it = offers.begin(); it != offers.end(); ++it) {
    KService::Ptr service = (*it);
    cout &lt;&lt; "Name: " &lt;&lt; service->name() &lt;&lt; endl;
}
</programlisting>

<para>
The return value of this function is a list of service offers. A
<classname>KServiceOffer</classname> object packages a KService::Ptr together
with a preference number. The list returned by
<function>KServiceTypeProfile::offers()</function> is ordered by the user's
preference. The user can change this by calling <command>"keditfiletype
text/html"</command> or choosing <guimenuitem>Edit File Type</guimenuitem> on
<application>Konqueror</application>'s context menu on a HTML file.
</para>

<para>
In the above example, an offer list of the applications supporting
<literal>text/html</literal> was requested. This will - among others - contain
HTML editors like <application>Quanta Plus</application>. You can also replace
the second argument <literal>"Application"</literal> by
<literal>"KParts::ReadOnlyPart"</literal>. In that case, you get a list of
embedable components for presenting HTML content, for example KHTML. 
</para>

<para>
In most cases, you are not interested in the list of all service offers
for a combination of MIME type and service type. There is a convenience
function which gives you only the service offer with the highest preference:
</para>

<programlisting>
KService::Ptr offer = KServiceTypeProfile::preferredService("text/html", "Application");
if (offer)
    cout &lt;&lt; "Name: " &lt;&lt; service->name() &lt;&lt; endl;
else
    cout &lt;&lt; "No appropriate service found" &lt;&lt; endl;
</programlisting>

<para>
For even more complex queries, there is a full-blown CORBA-like
<ulink url="kdeapi:kio/KTrader.html">trader</ulink>.
</para>

<para>
In order to run an application service with some URLs, use 
<ulink url="kdeapi:kio/KRun.html">KRun</ulink>:
</para>

<programlisting>
KURL::List urlList;
urlList &lt;&lt; "http://www.ietf.org/rfc/rfc1341.txt?number=1341";
urlList &lt;&lt; "http://www.ietf.org/rfc/rfc2046.txt?number=2046";
KRun::run(offer.service(), urlList);
</programlisting>

</simplesect>


<simplesect id="mime-misc">
<title>Miscellaneous</title>

<para>
In this section, we want to list some APIs which are loosely related
to the previous discussion.
</para>

<para>
Getting an icon for a URL. This looks for the type of the URL
and returns the associated icon.
</para>

<programlisting>
KURL url("ftp://ftp.kde.org/pub/incoming/wibble.c");
QString icon = KMimeType::iconForURL(url);
</programlisting>

<para>
Running a URL. This looks for the type of the URL and starts the
user's preferred program associated with this type.
</para>

<programlisting>
KURL url("http://dot.kde.org");
new KRun(url);
</programlisting>

</simplesect>

</sect1>


<sect1 id="nettransparency">
<title>Network transparency</title>

<simplesect id="nettransparency-intro">
<title>Introduction</title>

<para>
In the age of the world wide web, it is of essential importance that desktop
applications can access resources over the internet: they should be able to
download files from a web server, write files to an ftp server or read mails
from a web server. Often, the ability to access files regardless of their
location is called <emphasis>network transparency</emphasis>.
</para>

<para>
In the past, different approaches to this goals were implemented. The old NFS
file system is an attempt to implement network transparency on the level of
the POSIX API. While this approach works quite well in local, closely coupled
networks, it does not scale for resources to which access is unreliable and
possibly slow. Here, <emphasis>asynchronicity</emphasis> is important. While
you are waiting for your web browser to download a page, the user interface
should not block. Also, the page rendering should not begin when the page is
completely available, but should updated regularly as data comes in.
</para>

<para>
In the KDE libraries, network transparency is implemented in the KIO API. The
central concept of this architecture is an IO <emphasis>job</emphasis>. A job
may copy, or delete files or similar things. Once a job is started, it works
in the background and does not block the application. Any communication from
the job back to the application - like delivering data or progress information
- is done integrated with the Qt event loop.
</para>

<para>
Background operation is achieved by starting <emphasis>ioslaves</emphasis> to
perform certain tasks. ioslaves are started as separate processes and are
communicated with through UNIX domain sockets. In this way, no multi-threading
is necessary and unstable slaves can not crash the application that uses them.
</para>

<para>
File locations are expressed by the widely used URLs. But in KDE, URLs do not
only expand the range of addressable files beyond the local file system. It
also goes in the opposite direction - e.g. you can browse into tar archives.
This is achieved by nesting URLs. For example, a file in a tar archive on 
a http server could have the URL
</para>

<programlisting>
http://www-com.physik.hu-berlin.de/~bernd/article.tgz#tar:/paper.tex
</programlisting>

</simplesect>


<simplesect id="nettransparency-usingkio">
<title>Using KIO</title>

<para>
In most cases, jobs are created by calling functions in the KIO namespace.
These functions take one or two URLs as arguments, and possible other
necessary parameters. When the job is finished, it emits the signal
<literal>result(KIO::Job*)</literal>. After this signal has been emitted, the job
deletes itself. Thus, a typical use case will look like this:
</para>

<programlisting>
void FooClass::makeDirectory()
{
    SimpleJob *job = KIO::mkdir(KURL("file:/home/bernd/kiodir"));
    connect( job, SIGNAL(result(KIO::Job*)), 
             this, SLOT(mkdirResult(KIO::Job*)) );
}

void FooClass::mkdirResult(KIO::Job *job)
{
    if (job->error())
        job->showErrorDialog();
    else
        cout &lt;&lt; "mkdir went fine" &lt;&lt; endl;
}
</programlisting>

<para>
Depending on the type of the job, you may connect also to other
signals.
</para>

<para>
Here is an overview over the possible functions:
</para>

<variablelist>

<varlistentry><term>KIO::mkdir(const KURL &amp;url, int permission)</term>
<listitem><para>
Creates a directory, optionally with certain permissions.
</para></listitem>
</varlistentry>

<varlistentry><term>KIO::rmdir(const KURL &amp;url)</term>
<listitem><para>
Removes a directory.
</para></listitem>
</varlistentry>

<varlistentry><term>KIO::chmod(const KURL &amp;url, int permissions)</term>
<listitem><para>
Changes the permissions of a file.
</para></listitem>
</varlistentry>

<varlistentry><term>KIO::rename(const KURL &amp;src, const KURL &amp;dest, 
                                bool overwrite)</term>
<listitem><para>
Renames a file.
</para></listitem>
</varlistentry>

<varlistentry><term>KIO::symlink(const QString &amp;target, const KURL &amp;dest, 
                                 bool overwrite, bool showProgressInfo)</term>
<listitem><para>
Creates a symbolic link.
</para></listitem>
</varlistentry>

<varlistentry><term>KIO::stat(const KURL &amp;url, bool showProgressInfo)</term>
<listitem><para>
Finds out certain information about the file, such as size, modification 
time and permissions. The information can be obtained from 
KIO::StatJob::statResult() after the job has finished.
</para></listitem>
</varlistentry>

<varlistentry><term>KIO::get(const KURL &amp;url, bool reload, bool showProgressInfo)</term>
<listitem><para>
Transfers data from a URL.
</para></listitem>
</varlistentry>

<varlistentry><term>KIO::put(const KURL &amp;url, int permissions, bool overwrite, 
                             bool resume, bool showProgressInfo)</term>
<listitem><para>
Transfers data to a URL.
</para></listitem>
</varlistentry>

<varlistentry><term>KIO::http_post(const KURL &amp;url, const QByteArray &amp;data, 
                                    bool showProgressInfo)</term>
<listitem><para>Posts data. Special for HTTP.
</para></listitem>
</varlistentry>

<varlistentry><term>KIO::mimetype(const KURL &amp;url, bool showProgressInfo)</term>
<listitem><para>
Tries to find the MIME type of the URL. The type can be obtained from 
KIO::MimetypeJob::mimetype() after the job has finished.
</para></listitem>
</varlistentry>

<varlistentry><term>KIO::file_copy(const KURL &amp;src, const KURL &amp;dest, int permissions,
                                   bool overwrite, bool resume, bool showProgressInfo)</term>
<listitem><para>
Copies a single file.
</para></listitem>
</varlistentry>

<varlistentry><term>KIO::file_move(const KURL &amp;src, const KURL &amp;dest, int permissions,
                                   bool overwrite, bool resume, bool showProgressInfo)</term>
<listitem><para>
Renames or moves a single file.
</para></listitem>
</varlistentry>

<varlistentry><term>KIO::file_delete(const KURL &amp;url, bool showProgressInfo)</term>
<listitem><para>
Deletes a single file.
</para></listitem>
</varlistentry>

<varlistentry><term>KIO::listDir(const KURL &amp;url, bool showProgressInfo)</term>
<listitem><para>
Lists the contents of a directory. Each time some new entries are known, the
signal KIO::ListJob::entries() is emitted.
</para></listitem>
</varlistentry>

<varlistentry><term>KIO::listRecursive(const KURL &amp;url, bool showProgressInfo)</term>
<listitem><para>
Similar to the listDir() function, but this one is recursive.
</para></listitem>
</varlistentry>

<varlistentry><term>KIO::copy(const KURL &amp;src, const KURL &amp;dest, bool showProgressInfo)</term>
<listitem><para>
Copies a file or directory. Directories are copied recursively.
</para></listitem>
</varlistentry>

<varlistentry><term>KIO::move(const KURL &amp;src, const KURL &amp;dest, bool showProgressInfo)</term>
<listitem><para>
Moves or renames a file or directory.
</para></listitem>
</varlistentry>

<varlistentry><term>KIO::del(const KURL &amp;src, bool shred, bool showProgressInfo)</term>
<listitem><para>
Deletes a file or directory.
</para></listitem>
</varlistentry>

</variablelist>

</simplesect>


<simplesect id="nettransparency-direntries">
<title>Directory entries</title>

<para>
Both the KIO::stat() and KIO::listDir() jobs return their results as a type
UDSEntry, UDSEntryList resp. The latter is defined as QValueList&lt;UDSEntry&gt;.
The acronym UDS stands for "Universal directory service". The principle behind 
it is that the a directory entry only carries the information which an ioslave
can provide, not more. For example, the http slave does not provide any 
information about access permissions or file owners.
Instead, a UDSEntry is a list of UDSAtoms. Each atom provides a specific piece
of information. It consists of a type stored in m_uds and either an integer
value in m_long or a string value in m_str, depending on the type.
</para>

<para>
The following types are currently defined:
</para>

<itemizedlist>

<listitem><para>
UDS_SIZE (integer) - Size of the file.
</para></listitem>

<listitem><para>
UDS_USER (string) - User owning the file.
</para></listitem>

<listitem><para>
UDS_GROUP (string) - Group owning the file.
</para></listitem>

<listitem><para>
UDS_NAME (string) - File name.
</para></listitem>

<listitem><para>
UDS_ACCESS (integer) - Permission rights of the file, as e.g. stored
by the libc function stat() in the st_mode field.
</para></listitem>

<listitem><para>
UDS_FILE_TYPE (integer) - The file type, as e.g. stored by stat() in the 
st_mode field. Therefore you can use the usual libc macros like S_ISDIR to 
test this value. Note that the data provided by ioslaves corresponds to 
stat(), not lstat(), i.e. in case of symbolic links, the file type here is 
the type of the file pointed to by the link, not the link itself.
</para></listitem>

<listitem><para>
UDS_LINK_DEST (string) - In case of a symbolic link, the name of the file 
pointed to.
</para></listitem>

<listitem><para>
UDS_MODIFICATION_TIME (integer) - The time (as in the type time_t)  when the
file was last modified, as e.g. stored by stat() in the st_mtime field.
</para></listitem>

<listitem><para>
UDS_ACCESS_TIME (integer) - The time when the file was last accessed, as 
e.g. stored by stat() in the st_atime field.
</para></listitem>

<listitem><para>
UDS_CREATION_TIME (integer) - The time when the file was created, as e.g. 
stored by stat() in the st_ctime field. 
</para></listitem>

<listitem><para>
UDS_URL (string) - Provides a URL of a file, if it is not simply the
the concatenation of directory URL and file name.
</para></listitem>

<listitem><para>
UDS_MIME_TYPE (string) - MIME type of the file
</para></listitem>

<listitem><para>
UDS_GUESSED_MIME_TYPE (string) - MIME type of the file as guessed by the 
slave. The difference to the previous type is that the one provided here
should not be taken as reliable (because determining it in a reliable way
would be too expensive). For example, the KRun class explicitly checks the
MIME type if it does not have reliable information.
</para></listitem>

</itemizedlist>

<para>
Although the way of storing information about files in a
<classname>UDSEntry</classname> is flexible and practical from the ioslave
point of view, it is a mess to use for the application programmer. For
example, in order to find out the MIME type of the file, you have to iterate
over all atoms and test whether <literal>m_uds</literal> is
<literal>UDS_MIME_TYPE</literal>. Fortunately, there is an API which is a lot
easier to use: the class <classname>KFileItem</classname>.
</para>

</simplesect>


<simplesect id="nettransparency-syncuse">
<title>Synchronous usage</title>

<para>
Often, the asynchronous API of KIO is too complex to use and therefore 
implementing full asynchronicity is not a priority. For example, in a program 
that can only handle one document file at a time, there is little that can be
done while the program is downloading a file anyway. For these simple cases, 
there is a mucher simpler API in the form of a set of static functions in
KIO::NetAccess. For example, in order to copy a file, use
</para>

<programlisting>
KURL source, target;
source = ...;
target = ...
KIO::NetAccess::copy(source, target);
</programlisting>

<para>
The function will return after the complete copying process has finished. Still,
this method provides a progress dialog, and it makes sure that the application
processes repaint events.
</para>

<para>
A particularly interesting combination of functions is
<function>download()</function> in combination with
<function>removeTempFile()</function>. The former downloads a file from given
URL and stores it in a temporary file with a unique name. The name is stored
in the second argument. <emphasis>If</emphasis> the URL is local, the file is
not downloaded, and instead the second argument is set to the local file
name. The function <function>removeTempFile()</function> deletes the file
given by its argument if the file is the result of a former download. If that
is not the case, it does nothing. Thus, a very easy to use way of loading
files regardless of their location is the following code snippet:
</para>

<programlisting>
KURL url;
url = ...;
QString tempFile;
if (KIO::NetAccess::download(url, tempFile) {
    // load the file with the name tempFile
    KIO::NetAccess::removeTempFile(tempFile);
}
</programlisting>

</simplesect>


<simplesect id="nettransparency-metadata">
<title>Meta data</title>

<para>
As can be seen above, the interface to IO jobs is quite abstract and does not
consider any exchange of information between application and IO slave that
is protocol specific. This is not always appropriate. For example, you may give
certain parameters to the HTTP slave to control its caching behavior or
send a bunch of cookies with the request. For this need, the concept of meta
data has been introduced. When a job is created, you can configure it by adding
meta data to it. Each item of meta data consists of a key/value pair. For
example, in order to prevent the HTTP slave from loading a web page from its
cache, you can use:
</para>
 
<programlisting>
void FooClass::reloadPage()
{
    KURL url("http://www.kdevelop.org/index.html");
    KIO::TransferJob *job = KIO::get(url, true, false);
    job->addMetaData("cache", "reload");
    ...
}
</programlisting>

<para>
The same technique is used in the other direction, i.e. for communication from
the slave to the application. The method
<function>Job::queryMetaData()</function> asks for the value of the certain
key delivered by the slave. For the HTTP slave, one such example is the key
<literal>"modified"</literal>, which contains a (stringified representation of)
the date when the web page was last modified. An example how you can use this
is the following:
</para>
 
<programlisting>
void FooClass::printModifiedDate()
{
    KURL url("http://developer.kde.org/documentation/kde2arch/index.html");
    KIO::TransferJob *job = KIO::get(url, true, false);
    connect( job, SIGNAL(result(KIO::Job*)),
             this, SLOT(transferResult(KIO::Job*)) );
}

void FooClass::transferResult(KIO::Job *job)
{
    QString mimetype;
    if (job->error())
        job->showErrorDialog();
    else {
        KIO::TransferJob *transferJob = (KIO::TransferJob*) job;
        QString modified = transferJob->queryMetaData("modified");
        cout &lt;&lt; "Last modified: " &lt;&lt; modified &lt;&lt; endl;
}
</programlisting>

</simplesect>


<simplesect id="nettransparency-scheduling">
<title>Scheduling</title>

<para>
When using the KIO API, you usually do not have to cope with the details of
starting IO slaves and communicating with them. The normal use case is to
start a job and with some parameters and handle the signals the jobs emits.
</para>

<para>
Behind the curtains, the scenario is a lot more complicated. When you create a
job, it is put in a queue. When the application goes back to the event loop,
KIO allocates slave processes for the jobs in the queue.  For the first jobs
started, this is trivial: an IO slave for the appropriate protocol is started.
However, after the job (like a download from an http server) has finished, it
is not immediately killed. Instead, it is put in a pool of idle slaves and
killed after a certain time of inactivity (current 3 minutes). If a new request
for the same protocol and host arrives, the slave is reused. The obvious 
advantage is that for a series of jobs for the same host, the cost for creating
new processes and possibly going through an authentication handshake is saved.
</para>

<para>
Of course, reusing is only possible when the existing slave has already finished
its previous job. when a new request arrives while an existing slave process is 
still running, a new process must be started and used. In the API usage in the
examples above, there are no limitation for creating new slave processes: if you
start a consecutive series of downloads for 20 different files, then KIO will 
start 20 slave processes. This scheme of assigning slaves to jobs is called 
<emphasis>direct</emphasis>. It  not always the most appropriate scheme, as it
may need much memory and put a high load on both the client and server machines.
</para>

<para>
So there is a different way. You can <emphasis>schedule</emphasis> jobs. If
you do this, only a limited number (currently 3) of slave processes for a
protocol will be created. If you create more jobs than that, they are put in a
queue and are processed when a slave process becomes idle. This is done as
follows:
</para>

<programlisting>
KURL url("http://developer.kde.org/documentation/kde2arch/index.html");
KIO::TransferJob *job = KIO::get(url, true, false);
KIO::Scheduler::scheduleJob(job);
</programlisting>

<para>
A third possibility is <emphasis>connection oriented</emphasis>. For example,
for the IMAP slave, it does not make any sense to start multiple processes for
the same server. Only one IMAP connection at a time should be enforced. In
this case, the application must explicitly deal with the notion of a slave. It
has to deallocate a slave for a certain connection and then assign all jobs
which should go through the same connection to the same slave. This can again
be easily achieved by using the KIO::Scheduler:
</para>

<programlisting>
KURL baseUrl("imap://bernd@albert.physik.hu-berlin.de");
KIO::Slave *slave = KIO::Scheduler::getConnectedSlave(baseUrl);

KIO::TransferJob *job1 = KIO::get(KURL(baseUrl, "/INBOX;UID=79374"));
KIO::Scheduler::assignJobToSlave(slave, job1);

KIO::TransferJob *job2 = KIO::get(KURL(baseUrl, "/INBOX;UID=86793"));
KIO::Scheduler::assignJobToSlave(slave, job2);

...

KIO::Scheduler::disconnectSlave(slave);
</programlisting>

<para>
You may only disconnect the slave after all jobs assigned to it are guaranteed
to be finished.
</para>

</simplesect>


<simplesect id="nettransparency-definingslaves">
<title>Defining an ioslave</title>

<para>
In the following we discuss how you can add a new ioslave to the system.
In analogy to services, new ioslaves are advertised to the system by
installing a little configuration file. The following Makefile.am
snippet installs the ftp protocol:
</para>

<programlisting>
protocoldir = $(kde_servicesdir)
protocol_DATA = ftp.protocol
EXTRA_DIST = $(mime_DATA)
</programlisting>

<para>
The contents of the file ftp.protocol is as follows:
</para>

<programlisting>
[Protocol]
exec=kio_ftp
protocol=ftp
input=none
output=filesystem
listing=Name,Type,Size,Date,Access,Owner,Group,Link,
reading=true
writing=true
makedir=true
deleting=true
Icon=ftp
</programlisting>

<para>
The <literal>"protocol"</literal> entry defines for which protocol this slave
is responsible. <literal>"exec"</literal> is (in contrast what you would
expect naively) the name of the library that implements the slave. When the
slave is supposed to start, the <command>"tdeinit"</command> executable is
started which in turn loads this library into its address space. So in
practice, you can think of the running slave as a separate process although it
is implemented as library. The advantage of this mechanism is that it saves a
lot of memory and  reduces the time needed by the runtime linker.
</para>

<para>
The "input" and "output" lines are not used currently.
</para>

<para>
The remaining lines in the <literal>.protocol</literal> file define which
abilities the slave has. In general, the features a slave must implement are
much simpler than the features the KIO API provides for the application. The
reason for this is that complex jobs are scheduled to a couple of subjobs. For
example, in order to list a directory recursively, one job will be started for
the toplevel directory. Then for each subdirectory reported back, new subjobs
are started. A scheduler in KIO makes sure that not too many jobs are active
at the same time. Similarly, in order to copy a file within a protocol that
does not support copying directly (like the <literal>ftp:</literal> protocol),
KIO can read the source file and then write the data to the destination
file. For this to work, the <literal>.protocol</literal> must advertise the
actions its slave supports.
</para>

<para>
Since slaves are loaded as shared libraries, but constitute standalone programs,
their code framework looks a bit different from normal shared library plugins.
The function which is called to start the slave is called
<function>kdemain()</function>. This function does some initializations and
then goes into an event loop and waits for requests by the application using
it. This looks as follows:
</para>

<programlisting>
extern "C" { int kdemain(int argc, char **argv); }

int kdemain(int argc, char **argv)
{
    KLocale::setMainCatalogue("tdelibs");
    KInstance instance("kio_ftp");
    (void) KGlobal::locale();

    if (argc != 4) {
        fprintf(stderr, "Usage: kio_ftp protocol "
                        "domain-socket1 domain-socket2\n");
        exit(-1);
    }

    FtpSlave slave(argv[2], argv[3]);
    slave.dispatchLoop();
    return 0;
}
</programlisting>

</simplesect>


<simplesect id="nettransparency-implementingslaves">
<title>Implementing an ioslave</title>

<para>
Slaves are implemented as subclasses of <classname>KIO::SlaveBase</classname>
(FtpSlave in the above example). Thus, the actions listed in the
<literal>.protocol</literal> correspond to certain virtual functions in
<classname>KIO::SlaveBase</classname> the slave implementation must
reimplement. Here is a list of possible actions and the corresponding virtual
functions:
</para>

<variablelist>

<varlistentry><term>reading - Reads data from a URL</term>
<listitem><para>void get(const KURL &amp;url)</para></listitem></varlistentry>

<varlistentry><term>writing - Writes data to a URL and create the file if it does not exist yet.</term>
<listitem><para>void put(const KURL &amp;url, int permissions, bool overwrite, bool resume)</para></listitem></varlistentry>

<varlistentry><term>moving - Renames a file.</term>
<listitem><para>void rename(const KURL &amp;src, const KURL &amp;dest, bool overwrite)</para></listitem></varlistentry>

<varlistentry><term>deleting - Deletes a file or directory.</term>
<listitem><para>void del(const KURL &amp;url, bool isFile)</para></listitem></varlistentry>

<varlistentry><term>listing - Lists the contents of a directory.</term>
<listitem><para>void listDir(const KURL &amp;url)</para></listitem></varlistentry>

<varlistentry><term>makedir - Creates a directory.</term>
<listitem><para>void mkdir(const KURL &amp;url, int permissions)</para></listitem></varlistentry>

</variablelist>

<para>
Additionally, there are reimplementable functions not listed in the <literal>.protocol</literal>
file. For these operations, KIO automatically determines whether they are supported
or not (i.e. the default implementation returns an error).
</para>

<variablelist>

<varlistentry><term>Delivers information about a file, similar to the C function stat().</term>
<listitem><para>void stat(const KURL &amp;url)</para></listitem></varlistentry>

<varlistentry><term>Changes the access permissions of a file.</term>
<listitem><para>void chmod(const KURL &amp;url, int permissions)</para></listitem></varlistentry>

<varlistentry><term>Determines the MIME type of a file.</term>
<listitem><para>void mimetype(const KURL &amp;url)</para></listitem></varlistentry>

<varlistentry><term>Copies a file.</term>
<listitem><para>copy(const KURL &amp;url, const KURL &amp;dest, int permissions, bool overwrite)</para></listitem></varlistentry>

<varlistentry><term>Creates a symbolic link.</term>
<listitem><para>void symlink(const QString &amp;target, const KURL &amp;dest, bool overwrite)</para></listitem></varlistentry>

</variablelist>

<para>
All these implementation should end with one of two calls: If the operation
was successful, they should call <literal>finished()</literal>. If an error has occurred,
<literal>error()</literal> should be called with an error code as first argument and a
string in the second. Possible error codes are listed as enum
<type>KIO::Error</type>. The second argument is usually the URL in
question. It is used e.g. in <function>KIO::Job::showErrorDialog()</function>
in order to parameterize the human-readable error message.
</para>

<para>
For slaves that correspond to network protocols, it might be interesting to 
reimplement the method <function>SlaveBase::setHost()</function>. This is
called to tell the slave process about the host and port, and the user name
and password to log in. In general, meta data set by the application can be
queried by <function>SlaveBase::metaData()</function>. You can check for the
existence of meta data of a certain key with
<function>SlaveBase::hasMetaData()</function>.
</para>

</simplesect>


<simplesect id="nettransparency-communication">
<title>Communicating back to the application</title>

<para>
Various actions implemented in a slave need some way to communicate data back
to the application using the slave process:
</para>

<itemizedlist>

<listitem><para>
<function>get()</function> sends blocks of data. This is done with
<function>data()</function>, which takes a <classname>QByteArray</classname>
as argument. Of course, you do not need to send all data at once. If you send
a large file, call <function>data()</function> with smaller data blocks, so
the application can process them. Call <function>finished()</function> when
the transfer is finished.
</para></listitem>
    
<listitem><para>
<function>listDir()</function> reports information about the entries of a
directory. For this purpose, call <function>listEntries()</function> with a
<classname>KIO::UDSEntryList</classname> as argument. Analogously to
<function>data()</function>, you can call this several times. When you are
finished, call <function>listEntry()</function> with the second argument set
to true. You may also call <function>totalSize()</function> to report the
total number of directory entries, if known.
</para></listitem>

<listitem><para>
<function>stat()</function> reports information about a file like size, MIME
type, etc. Such information is packaged in a
<classname>KIO::UDSEntry</classname>, which will be discussed below. Use
<function>statEntry()</function> to send such an item to the application.
</para></listitem>

<listitem><para>
<function>mimetype()</function> calls <function>mimeType()</function> with a
string argument.
</para></listitem>

<listitem><para>
<function>get()</function> and <function>copy()</function> may want to provide
progress information. This is done with the methods
<function>totalSize()</function>, <function>processedSize()</function>,
<function>speed()</function>. The total size and processed size are reported
as bytes, the speed as bytes per second.
</para></listitem>

<listitem><para>
You can send arbitrary key/value pairs of meta data with
<function>setMetaData()</function>.
</para></listitem>

</itemizedlist>

</simplesect>


<simplesect id="nettransparency-interacting">
<title>Interacting with the user</title>

<para>
Sometimes a slave has to interact with the user. Examples include informational
messages, authentication dialogs and confirmation dialogs when a file is about
to be overwritten.
</para>

<itemizedlist>

<listitem><para>
<function>infoMessage()</function> - This is for informational feedback, such
as the message "Retrieving data from &lt;host&gt;" from the http slave, which
is often displayed in the status bar of the program. On the application side,
this method corresponds to the signal
<function>KIO::Job::infoMessage()</function>.
</para></listitem>

<listitem><para>
<function>warning()</function> - Displays a warning in a message box with
<function>KMessageBox::information()</function>. If a message box is still
open from a former call of warning() from the same slave process, nothing
happens.
</para></listitem>

<listitem><para>
<function>messageBox()</function> - This is richer than the previous
method. It allows to open a message box with text and caption and some
buttons. See the enum <type>SlaveBase::MessageBoxType</type> for reference.
</para></listitem>

<listitem><para>
<function>openPassDlg()</function> - Opens a dialog for the input of user name
and password.
</para></listitem>

</itemizedlist>

</simplesect>

</sect1>

</chapter>



<appendix id="misc">
<title>Licensing</title>

&underFDL;
&underGPL;

</appendix>

</book>