1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
3855
3856
3857
3858
3859
3860
3861
3862
3863
3864
3865
3866
3867
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881
3882
3883
3884
3885
3886
3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
3903
3904
3905
3906
3907
3908
3909
3910
3911
3912
3913
3914
3915
3916
3917
3918
3919
3920
3921
3922
3923
3924
3925
3926
3927
3928
3929
3930
3931
3932
3933
3934
3935
3936
3937
3938
3939
3940
3941
3942
3943
3944
3945
3946
3947
3948
3949
3950
3951
3952
3953
3954
3955
3956
3957
3958
3959
3960
3961
3962
3963
3964
3965
3966
3967
3968
3969
3970
3971
3972
3973
3974
3975
3976
3977
3978
3979
3980
3981
3982
3983
3984
3985
3986
3987
3988
3989
3990
3991
3992
3993
3994
3995
3996
3997
3998
3999
4000
4001
4002
4003
4004
4005
4006
4007
4008
4009
4010
4011
4012
4013
4014
4015
4016
4017
4018
4019
4020
4021
4022
4023
4024
4025
4026
4027
4028
4029
4030
4031
4032
4033
4034
4035
4036
4037
4038
4039
4040
4041
4042
4043
4044
4045
4046
4047
4048
4049
4050
4051
4052
4053
4054
4055
4056
4057
4058
4059
4060
4061
4062
4063
4064
4065
4066
4067
4068
4069
4070
4071
4072
4073
4074
4075
4076
4077
4078
4079
4080
4081
4082
4083
4084
4085
4086
4087
4088
4089
4090
4091
4092
4093
4094
4095
4096
4097
4098
4099
4100
4101
4102
4103
4104
4105
4106
4107
4108
4109
4110
4111
4112
4113
4114
4115
4116
4117
4118
4119
4120
4121
4122
4123
4124
4125
4126
4127
4128
4129
4130
4131
4132
4133
4134
4135
4136
4137
4138
4139
4140
4141
4142
4143
4144
4145
4146
4147
4148
4149
4150
4151
4152
4153
4154
4155
4156
4157
4158
4159
4160
4161
4162
4163
4164
4165
4166
4167
4168
4169
4170
4171
4172
4173
4174
4175
4176
4177
4178
4179
4180
4181
4182
4183
4184
4185
4186
4187
4188
4189
4190
4191
4192
4193
4194
4195
4196
4197
4198
4199
4200
4201
4202
4203
4204
4205
4206
4207
4208
4209
4210
4211
4212
4213
4214
4215
4216
4217
4218
4219
4220
4221
4222
4223
4224
4225
4226
4227
4228
4229
4230
4231
4232
4233
4234
4235
4236
4237
4238
4239
4240
4241
4242
4243
4244
4245
4246
4247
4248
4249
4250
4251
4252
4253
4254
4255
4256
4257
4258
4259
4260
4261
4262
4263
4264
4265
4266
4267
4268
4269
4270
4271
4272
4273
4274
4275
4276
4277
4278
4279
4280
4281
4282
4283
4284
4285
4286
4287
4288
4289
4290
4291
4292
4293
4294
4295
4296
4297
4298
4299
4300
4301
4302
4303
4304
4305
4306
4307
4308
4309
4310
4311
4312
4313
4314
4315
4316
4317
4318
4319
4320
4321
4322
4323
4324
4325
4326
4327
4328
4329
4330
4331
4332
4333
4334
4335
4336
4337
4338
4339
4340
4341
4342
4343
4344
4345
4346
4347
4348
4349
4350
4351
4352
4353
4354
4355
4356
4357
4358
4359
4360
4361
4362
4363
4364
4365
4366
4367
4368
4369
4370
4371
4372
4373
4374
4375
4376
4377
4378
4379
4380
4381
4382
4383
4384
4385
4386
4387
4388
4389
4390
4391
4392
4393
4394
4395
4396
4397
4398
4399
4400
4401
4402
4403
4404
4405
4406
4407
4408
4409
4410
4411
4412
4413
4414
4415
4416
4417
4418
4419
4420
4421
4422
4423
4424
4425
4426
4427
4428
4429
4430
4431
4432
4433
4434
4435
4436
4437
4438
4439
4440
4441
4442
4443
4444
4445
4446
4447
4448
4449
4450
4451
4452
4453
4454
4455
4456
4457
4458
4459
4460
4461
4462
4463
4464
4465
4466
4467
4468
4469
4470
4471
4472
4473
4474
4475
4476
4477
4478
4479
4480
4481
4482
4483
4484
4485
4486
4487
4488
4489
4490
4491
4492
4493
4494
4495
4496
4497
4498
4499
4500
4501
4502
4503
4504
4505
4506
4507
4508
4509
4510
4511
4512
4513
4514
4515
4516
4517
4518
4519
4520
4521
4522
4523
4524
4525
4526
4527
4528
4529
4530
4531
4532
4533
4534
4535
4536
4537
4538
4539
4540
4541
4542
4543
4544
4545
4546
4547
4548
4549
4550
4551
4552
4553
4554
4555
4556
4557
4558
4559
4560
4561
4562
4563
4564
4565
4566
4567
4568
4569
4570
4571
4572
4573
4574
4575
4576
4577
4578
4579
4580
4581
4582
4583
4584
4585
4586
4587
4588
4589
4590
4591
4592
4593
4594
4595
4596
4597
4598
4599
4600
4601
4602
4603
4604
4605
4606
4607
4608
4609
4610
4611
4612
4613
4614
4615
4616
4617
4618
4619
4620
4621
4622
4623
4624
4625
4626
4627
4628
4629
4630
4631
4632
4633
4634
4635
4636
4637
4638
4639
4640
4641
4642
4643
4644
4645
4646
4647
4648
4649
4650
4651
4652
4653
4654
4655
4656
4657
4658
4659
4660
4661
4662
4663
4664
4665
4666
4667
4668
4669
4670
4671
4672
4673
4674
4675
4676
4677
4678
4679
4680
4681
4682
4683
4684
4685
4686
4687
4688
4689
4690
4691
4692
4693
4694
4695
4696
4697
4698
4699
4700
4701
4702
4703
4704
4705
4706
4707
4708
4709
4710
4711
4712
4713
4714
4715
4716
4717
4718
4719
|
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
/* fm-properties-window.c - window that lets user modify file properties
Copyright (C) 2000 Eazel, Inc.
The Gnome Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public License as
published by the Free Software Foundation; either version 2 of the
License, or (at your option) any later version.
The Gnome Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with the Gnome Library; see the file COPYING.LIB. If not,
write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.
Authors: Darin Adler <darin@bentspoon.com>
*/
#include <config.h>
#include "fm-properties-window.h"
#include "fm-error-reporting.h"
#include <eel/eel-accessibility.h>
#include <eel/eel-ellipsizing-label.h>
#include <eel/eel-gdk-pixbuf-extensions.h>
#include <eel/eel-glib-extensions.h>
#include <eel/eel-gnome-extensions.h>
#include <eel/eel-gtk-extensions.h>
#include <eel/eel-labeled-image.h>
#include <eel/eel-mime-application-chooser.h>
#include <eel/eel-stock-dialogs.h>
#include <eel/eel-string.h>
#include <eel/eel-vfs-extensions.h>
#include <eel/eel-wrap-table.h>
#include <gtk/gtkalignment.h>
#include <gtk/gtkcheckbutton.h>
#include <gtk/gtkdnd.h>
#include <gtk/gtkeditable.h>
#include <gtk/gtkentry.h>
#include <gtk/gtkfilesel.h>
#include <gtk/gtkhbox.h>
#include <gtk/gtkhbbox.h>
#include <gtk/gtkhseparator.h>
#include <gtk/gtkimage.h>
#include <gtk/gtklabel.h>
#include <gtk/gtkmain.h>
#include <gtk/gtknotebook.h>
#include <gtk/gtkcombobox.h>
#include <gtk/gtkscrolledwindow.h>
#include <gtk/gtksignal.h>
#include <gtk/gtkstock.h>
#include <gtk/gtktable.h>
#include <gtk/gtkvbox.h>
#include <gtk/gtktreemodel.h>
#include <gtk/gtkliststore.h>
#include <glib/gi18n.h>
#include <libgnome/gnome-macros.h>
#include <libgnomeui/gnome-dialog.h>
#include <libgnomeui/gnome-help.h>
#include <libgnomeui/gnome-thumbnail.h>
#include <libgnomeui/gnome-uidefs.h>
#include <libgnomevfs/gnome-vfs.h>
#include <libnautilus-extension/nautilus-property-page-provider.h>
#include <libnautilus-private/nautilus-customization-data.h>
#include <libnautilus-private/nautilus-entry.h>
#include <libnautilus-private/nautilus-file-attributes.h>
#include <libnautilus-private/nautilus-file-operations.h>
#include <libnautilus-private/nautilus-desktop-icon-file.h>
#include <libnautilus-private/nautilus-global-preferences.h>
#include <libnautilus-private/nautilus-icon-factory.h>
#include <libnautilus-private/nautilus-emblem-utils.h>
#include <libnautilus-private/nautilus-link.h>
#include <libnautilus-private/nautilus-metadata.h>
#include <libnautilus-private/nautilus-module.h>
#include <libnautilus-private/nautilus-undo-signal-handlers.h>
#include <libnautilus-private/nautilus-mime-actions.h>
#include <libnautilus-private/nautilus-undo.h>
#include <string.h>
#define PREVIEW_IMAGE_WIDTH 96
#define ROW_PAD 6
static GHashTable *windows;
static GHashTable *pending_lists;
struct FMPropertiesWindowDetails {
GList *original_files;
GList *target_files;
GtkNotebook *notebook;
GtkTable *basic_table;
GtkTable *permissions_table;
gboolean advanced_permissions;
GtkWidget *icon_button;
GtkWidget *icon_image;
GtkWidget *icon_chooser;
GtkWidget *name_label;
GtkWidget *name_field;
char *pending_name;
GtkLabel *directory_contents_title_field;
GtkLabel *directory_contents_value_field;
guint update_directory_contents_timeout_id;
guint update_files_timeout_id;
GList *emblem_buttons;
GHashTable *initial_emblems;
GList *permission_buttons;
GList *permission_combos;
GHashTable *initial_permissions;
gboolean has_recursive_apply;
GList *value_fields;
GList *mime_list;
gboolean deep_count_finished;
guint total_count;
GnomeVFSFileSize total_size;
guint long_operation_underway;
GList *changed_files;
};
enum {
PERMISSIONS_CHECKBOXES_OWNER_ROW,
PERMISSIONS_CHECKBOXES_GROUP_ROW,
PERMISSIONS_CHECKBOXES_OTHERS_ROW,
PERMISSIONS_CHECKBOXES_ROW_COUNT
};
enum {
PERMISSIONS_CHECKBOXES_READ_COLUMN,
PERMISSIONS_CHECKBOXES_WRITE_COLUMN,
PERMISSIONS_CHECKBOXES_EXECUTE_COLUMN,
PERMISSIONS_CHECKBOXES_COLUMN_COUNT
};
enum {
TITLE_COLUMN,
VALUE_COLUMN,
COLUMN_COUNT
};
typedef struct {
GList *original_files;
GList *target_files;
GtkWidget *parent_widget;
char *pending_key;
GHashTable *pending_files;
} StartupData;
/* drag and drop definitions */
enum {
TARGET_URI_LIST,
TARGET_GNOME_URI_LIST,
TARGET_RESET_BACKGROUND
};
static const GtkTargetEntry target_table[] = {
{ "text/uri-list", 0, TARGET_URI_LIST },
{ "x-special/gnome-icon-list", 0, TARGET_GNOME_URI_LIST },
{ "x-special/gnome-reset-background", 0, TARGET_RESET_BACKGROUND }
};
#define DIRECTORY_CONTENTS_UPDATE_INTERVAL 200 /* milliseconds */
#define FILES_UPDATE_INTERVAL 200 /* milliseconds */
#define STANDARD_EMBLEM_HEIGHT 52
#define EMBLEM_LABEL_SPACING 2
static void directory_contents_value_field_update (FMPropertiesWindow *window);
static void file_changed_callback (NautilusFile *file,
gpointer user_data);
static void permission_button_update (FMPropertiesWindow *window,
GtkToggleButton *button);
static void permission_combo_update (FMPropertiesWindow *window,
GtkComboBox *combo);
static void value_field_update (FMPropertiesWindow *window,
GtkLabel *field);
static void properties_window_update (FMPropertiesWindow *window,
GList *files);
static void is_directory_ready_callback (NautilusFile *file,
gpointer data);
static void cancel_group_change_callback (gpointer callback_data);
static void cancel_owner_change_callback (gpointer callback_data);
static void parent_widget_destroyed_callback (GtkWidget *widget,
gpointer callback_data);
static void select_image_button_callback (GtkWidget *widget,
FMPropertiesWindow *properties_window);
static void set_icon (const char *icon_path,
FMPropertiesWindow *properties_window);
static void remove_pending (StartupData *data,
gboolean cancel_call_when_ready,
gboolean cancel_timed_wait,
gboolean cancel_destroy_handler);
static void append_extension_pages (FMPropertiesWindow *window);
static gboolean name_field_focus_out (NautilusEntry *name_field,
GdkEventFocus *event,
gpointer callback_data);
static void name_field_activate (NautilusEntry *name_field,
gpointer callback_data);
static GtkLabel *attach_ellipsizing_value_label (GtkTable *table,
int row,
int column,
const char *initial_text);
GNOME_CLASS_BOILERPLATE (FMPropertiesWindow, fm_properties_window,
GtkWindow, GTK_TYPE_WINDOW);
static gboolean
is_multi_file_window (FMPropertiesWindow *window)
{
GList *l;
int count;
count = 0;
for (l = window->details->original_files; l != NULL; l = l->next) {
if (!nautilus_file_is_gone (NAUTILUS_FILE (l->data))) {
count++;
if (count > 1) {
return TRUE;
}
}
}
return FALSE;
}
static int
get_not_gone_original_file_count (FMPropertiesWindow *window)
{
GList *l;
int count;
count = 0;
for (l = window->details->original_files; l != NULL; l = l->next) {
if (!nautilus_file_is_gone (NAUTILUS_FILE (l->data))) {
count++;
}
}
return count;
}
static NautilusFile *
get_original_file (FMPropertiesWindow *window)
{
g_return_val_if_fail (!is_multi_file_window (window), NULL);
if (window->details->original_files == NULL) {
return NULL;
}
return NAUTILUS_FILE (window->details->original_files->data);
}
static NautilusFile *
get_target_file_for_original_file (NautilusFile *file)
{
NautilusFile *target_file;
char *uri_to_display;
GnomeVFSVolume *volume;
GnomeVFSDrive *drive;
NautilusDesktopLink *link;
target_file = NULL;
if (nautilus_file_has_volume (file)) {
volume = nautilus_file_get_volume (file);
if (volume != NULL) {
uri_to_display = gnome_vfs_volume_get_activation_uri (volume);
target_file = nautilus_file_get (uri_to_display);
g_free (uri_to_display);
}
} else if (nautilus_file_has_drive (file)) {
drive = nautilus_file_get_drive (file);
if (drive != NULL) {
uri_to_display = gnome_vfs_drive_get_activation_uri (drive);
target_file = nautilus_file_get (uri_to_display);
g_free (uri_to_display);
}
} else if (NAUTILUS_IS_DESKTOP_ICON_FILE (file)) {
link = nautilus_desktop_icon_file_get_link (NAUTILUS_DESKTOP_ICON_FILE (file));
if (link != NULL) {
/* map to linked URI for these types of links */
uri_to_display = nautilus_desktop_link_get_activation_uri (link);
if (uri_to_display) {
target_file = nautilus_file_get (uri_to_display);
g_free (uri_to_display);
}
g_object_unref (link);
}
}
if (target_file != NULL) {
return target_file;
}
/* Ref passed-in file here since we've decided to use it. */
nautilus_file_ref (file);
return file;
}
static NautilusFile *
get_target_file (FMPropertiesWindow *window)
{
return NAUTILUS_FILE (window->details->target_files->data);
}
static void
add_prompt (GtkVBox *vbox, const char *prompt_text, gboolean pack_at_start)
{
GtkWidget *prompt;
prompt = gtk_label_new (prompt_text);
gtk_label_set_justify (GTK_LABEL (prompt), GTK_JUSTIFY_LEFT);
gtk_label_set_line_wrap (GTK_LABEL (prompt), TRUE);
gtk_widget_show (prompt);
if (pack_at_start) {
gtk_box_pack_start (GTK_BOX (vbox), prompt, FALSE, FALSE, 0);
} else {
gtk_box_pack_end (GTK_BOX (vbox), prompt, FALSE, FALSE, 0);
}
}
static void
add_prompt_and_separator (GtkVBox *vbox, const char *prompt_text)
{
GtkWidget *separator_line;
add_prompt (vbox, prompt_text, FALSE);
separator_line = gtk_hseparator_new ();
gtk_widget_show (separator_line);
gtk_box_pack_end (GTK_BOX (vbox), separator_line, TRUE, TRUE, 2*ROW_PAD);
}
static GdkPixbuf *
get_pixbuf_for_properties_window (FMPropertiesWindow *window)
{
GdkPixbuf *pixbuf;
char *icon;
GList *l;
icon = NULL;
for (l = window->details->original_files; l != NULL; l = l->next) {
NautilusFile *file;
file = NAUTILUS_FILE (l->data);
if (!icon) {
icon = nautilus_icon_factory_get_icon_for_file (file, FALSE);
} else {
char *new_icon;
new_icon = nautilus_icon_factory_get_icon_for_file (file, FALSE);
if (!new_icon || strcmp (new_icon, icon)) {
g_free (icon);
g_free (new_icon);
icon = NULL;
break;
}
g_free (new_icon);
}
}
if (!icon) {
icon = g_strdup ("gnome-fs-regular");
}
pixbuf = nautilus_icon_factory_get_pixbuf_for_icon (icon, NULL,
NAUTILUS_ICON_SIZE_STANDARD,
NULL, NULL,
FALSE, TRUE, NULL);
g_free (icon);
return pixbuf;
}
static void
update_properties_window_icon (GtkImage *image)
{
GdkPixbuf *pixbuf;
FMPropertiesWindow *window;
window = g_object_get_data (G_OBJECT (image), "properties_window");
pixbuf = get_pixbuf_for_properties_window (window);
gtk_image_set_from_pixbuf (image, pixbuf);
gtk_window_set_icon (GTK_WINDOW (window), pixbuf);
g_object_unref (pixbuf);
}
/* utility to test if a uri refers to a local image */
static gboolean
uri_is_local_image (const char *uri)
{
GdkPixbuf *pixbuf;
char *image_path;
image_path = gnome_vfs_get_local_path_from_uri (uri);
if (image_path == NULL) {
return FALSE;
}
pixbuf = gdk_pixbuf_new_from_file (image_path, NULL);
g_free (image_path);
if (pixbuf == NULL) {
return FALSE;
}
g_object_unref (pixbuf);
return TRUE;
}
static void
reset_icon (FMPropertiesWindow *properties_window)
{
GList *l;
for (l = properties_window->details->original_files; l != NULL; l = l->next) {
NautilusFile *file;
file = NAUTILUS_FILE (l->data);
nautilus_file_set_metadata (file,
NAUTILUS_METADATA_KEY_ICON_SCALE,
NULL, NULL);
nautilus_file_set_metadata (file,
NAUTILUS_METADATA_KEY_CUSTOM_ICON,
NULL, NULL);
}
}
static void
fm_properties_window_drag_data_received (GtkWidget *widget, GdkDragContext *context,
int x, int y,
GtkSelectionData *selection_data,
guint info, guint time)
{
char **uris;
gboolean exactly_one;
GtkImage *image;
GtkWindow *window;
image = GTK_IMAGE (widget);
window = GTK_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (image)));
if (info == TARGET_RESET_BACKGROUND) {
reset_icon (FM_PROPERTIES_WINDOW (window));
return;
}
uris = g_strsplit (selection_data->data, "\r\n", 0);
exactly_one = uris[0] != NULL && (uris[1] == NULL || uris[1][0] == '\0');
if (!exactly_one) {
eel_show_error_dialog
(_("You can't assign more than one custom icon at a time!"),
_("Please drag just one image to set a custom icon."),
window);
} else {
if (uri_is_local_image (uris[0])) {
set_icon (uris[0], FM_PROPERTIES_WINDOW (window));
} else {
if (eel_is_remote_uri (uris[0])) {
eel_show_error_dialog
(_("The file that you dropped is not local."),
_("You can only use local images as custom icons."),
window);
} else {
eel_show_error_dialog
(_("The file that you dropped is not an image."),
_("You can only use local images as custom icons."),
window);
}
}
}
g_strfreev (uris);
}
static GtkWidget *
create_image_widget (FMPropertiesWindow *window,
gboolean is_customizable)
{
GtkWidget *button;
GtkWidget *image;
GdkPixbuf *pixbuf;
pixbuf = get_pixbuf_for_properties_window (window);
image = gtk_image_new ();
gtk_widget_show (image);
button = NULL;
if (is_customizable) {
button = gtk_button_new ();
gtk_container_add (GTK_CONTAINER (button), image);
/* prepare the image to receive dropped objects to assign custom images */
gtk_drag_dest_set (GTK_WIDGET (image),
GTK_DEST_DEFAULT_MOTION | GTK_DEST_DEFAULT_HIGHLIGHT | GTK_DEST_DEFAULT_DROP,
target_table, G_N_ELEMENTS (target_table),
GDK_ACTION_COPY | GDK_ACTION_MOVE);
g_signal_connect (image, "drag_data_received",
G_CALLBACK (fm_properties_window_drag_data_received), NULL);
g_signal_connect (button, "clicked",
G_CALLBACK (select_image_button_callback), window);
}
gtk_image_set_from_pixbuf (GTK_IMAGE (image), pixbuf);
g_object_unref (pixbuf);
g_object_set_data (G_OBJECT (image), "properties_window", window);
/* React to icon theme changes. */
g_signal_connect_object (nautilus_icon_factory_get (),
"icons_changed",
G_CALLBACK (update_properties_window_icon),
image, G_CONNECT_SWAPPED);
window->details->icon_image = image;
window->details->icon_button = button;
return button != NULL ? button : image;
}
static void
set_name_field (FMPropertiesWindow *window, const gchar *original_name,
const gchar *name)
{
gboolean new_widget;
gboolean use_label;
/* There are four cases here:
* 1) Changing the text of a label
* 2) Changing the text of an entry
* 3) Creating label (potentially replacing entry)
* 4) Creating entry (potentially replacing label)
*/
use_label = is_multi_file_window (window) || !nautilus_file_can_rename (get_original_file (window));
new_widget = !window->details->name_field || (use_label ? NAUTILUS_IS_ENTRY (window->details->name_field) : GTK_IS_LABEL (window->details->name_field));
if (new_widget) {
if (window->details->name_field) {
gtk_widget_destroy (window->details->name_field);
}
if (use_label) {
window->details->name_field = GTK_WIDGET (attach_ellipsizing_value_label (window->details->basic_table, 0, VALUE_COLUMN, name));
} else {
window->details->name_field = nautilus_entry_new ();
gtk_entry_set_text (GTK_ENTRY (window->details->name_field), name);
gtk_widget_show (window->details->name_field);
gtk_table_attach (window->details->basic_table,
window->details->name_field,
VALUE_COLUMN,
VALUE_COLUMN + 1,
0, 1,
GTK_FILL, 0,
0, 0);
gtk_label_set_mnemonic_widget (GTK_LABEL (window->details->name_label), window->details->name_field);
/* FIXME bugzilla.gnome.org 42151:
* With this (and one place elsewhere in this file, not sure which is the
* trouble-causer) code in place, bug 2151 happens (crash on quit). Since
* we've removed Undo from Nautilus for now, I'm just ifdeffing out this
* code rather than trying to fix 2151 now. Note that it might be possible
* to fix 2151 without making Undo actually work, it's just not worth the
* trouble.
*/
#ifdef UNDO_ENABLED
/* Set up name field for undo */
nautilus_undo_set_up_nautilus_entry_for_undo ( NAUTILUS_ENTRY (window->details->name_field));
nautilus_undo_editable_set_undo_key (GTK_EDITABLE (window->details->name_field), TRUE);
#endif
g_signal_connect_object (window->details->name_field, "focus_out_event",
G_CALLBACK (name_field_focus_out), window, 0);
g_signal_connect_object (window->details->name_field, "activate",
G_CALLBACK (name_field_activate), window, 0);
}
gtk_widget_show (window->details->name_field);
}
/* Only replace text if the file's name has changed. */
else if (original_name == NULL || strcmp (original_name, name) != 0) {
if (use_label) {
gtk_label_set_text (GTK_LABEL (window->details->name_field), name);
} else {
/* Only reset the text if it's different from what is
* currently showing. This causes minimal ripples (e.g.
* selection change).
*/
gchar *displayed_name = gtk_editable_get_chars (GTK_EDITABLE (window->details->name_field), 0, -1);
if (strcmp (displayed_name, name) != 0) {
gtk_entry_set_text (GTK_ENTRY (window->details->name_field), name);
}
g_free (displayed_name);
}
}
}
static void
update_name_field (FMPropertiesWindow *window)
{
NautilusFile *file;
if (is_multi_file_window (window)) {
/* Multifile property dialog, show all names */
GString *str;
char *name;
gboolean first;
GList *l;
str = g_string_new ("");
first = TRUE;
for (l = window->details->target_files; l != NULL; l = l->next) {
file = NAUTILUS_FILE (l->data);
if (!nautilus_file_is_gone (file)) {
if (!first) {
g_string_append (str, ", ");
}
first = FALSE;
name = nautilus_file_get_display_name (file);
g_string_append (str, name);
g_free (name);
}
}
set_name_field (window, NULL, str->str);
g_string_free (str, TRUE);
} else {
const char *original_name = NULL;
char *current_name;
file = get_original_file (window);
if (file == NULL || nautilus_file_is_gone (file)) {
current_name = g_strdup ("");
} else {
current_name = nautilus_file_get_display_name (file);
}
/* If the file name has changed since the original name was stored,
* update the text in the text field, possibly (deliberately) clobbering
* an edit in progress. If the name hasn't changed (but some other
* aspect of the file might have), then don't clobber changes.
*/
if (window->details->name_field) {
original_name = (const char *) g_object_get_data (G_OBJECT (window->details->name_field), "original_name");
}
set_name_field (window, original_name, current_name);
if (original_name == NULL ||
eel_strcmp (original_name, current_name) != 0) {
g_object_set_data_full (G_OBJECT (window->details->name_field),
"original_name",
current_name,
g_free);
} else {
g_free (current_name);
}
}
}
static void
name_field_restore_original_name (NautilusEntry *name_field)
{
const char *original_name;
char *displayed_name;
original_name = (const char *) g_object_get_data (G_OBJECT (name_field),
"original_name");
if (!original_name) {
return;
}
displayed_name = gtk_editable_get_chars (GTK_EDITABLE (name_field), 0, -1);
if (strcmp (original_name, displayed_name) != 0) {
gtk_entry_set_text (GTK_ENTRY (name_field), original_name);
}
nautilus_entry_select_all (name_field);
g_free (displayed_name);
}
static void
rename_callback (NautilusFile *file, GnomeVFSResult result, gpointer callback_data)
{
FMPropertiesWindow *window;
char *new_name;
window = FM_PROPERTIES_WINDOW (callback_data);
/* Complain to user if rename failed. */
if (result != GNOME_VFS_OK) {
new_name = window->details->pending_name;
fm_report_error_renaming_file (file,
window->details->pending_name,
result,
GTK_WINDOW (window));
if (window->details->name_field != NULL) {
name_field_restore_original_name (NAUTILUS_ENTRY (window->details->name_field));
}
}
g_object_unref (window);
}
static void
set_pending_name (FMPropertiesWindow *window, const char *name)
{
g_free (window->details->pending_name);
window->details->pending_name = g_strdup (name);
}
static void
name_field_done_editing (NautilusEntry *name_field, FMPropertiesWindow *window)
{
NautilusFile *file;
char *new_name;
const char *original_name;
g_return_if_fail (NAUTILUS_IS_ENTRY (name_field));
/* Don't apply if the dialog has more than one file */
if (is_multi_file_window (window)) {
return;
}
file = get_original_file (window);
/* This gets called when the window is closed, which might be
* caused by the file having been deleted.
*/
if (file == NULL || nautilus_file_is_gone (file)) {
return;
}
new_name = gtk_editable_get_chars (GTK_EDITABLE (name_field), 0, -1);
/* Special case: silently revert text if new text is empty. */
if (strlen (new_name) == 0) {
name_field_restore_original_name (NAUTILUS_ENTRY (name_field));
} else {
original_name = (const char *) g_object_get_data (G_OBJECT (window->details->name_field),
"original_name");
/* Don't rename if not changed since we read the display name.
This is needed so that we don't save the display name to the
file when nothing is changed */
if (strcmp (new_name, original_name) != 0) {
set_pending_name (window, new_name);
g_object_ref (window);
nautilus_file_rename (file, new_name,
rename_callback, window);
}
}
g_free (new_name);
}
static gboolean
name_field_focus_out (NautilusEntry *name_field,
GdkEventFocus *event,
gpointer callback_data)
{
g_assert (FM_IS_PROPERTIES_WINDOW (callback_data));
if (GTK_WIDGET_SENSITIVE (name_field)) {
name_field_done_editing (name_field, FM_PROPERTIES_WINDOW (callback_data));
}
return FALSE;
}
static void
name_field_activate (NautilusEntry *name_field, gpointer callback_data)
{
g_assert (NAUTILUS_IS_ENTRY (name_field));
g_assert (FM_IS_PROPERTIES_WINDOW (callback_data));
/* Accept changes. */
name_field_done_editing (name_field, FM_PROPERTIES_WINDOW (callback_data));
nautilus_entry_select_all_at_idle (name_field);
}
static gboolean
file_has_keyword (NautilusFile *file, const char *keyword)
{
GList *keywords, *word;
keywords = nautilus_file_get_keywords (file);
word = g_list_find_custom (keywords, keyword, (GCompareFunc) strcmp);
eel_g_list_free_deep (keywords);
return (word != NULL);
}
static void
get_initial_emblem_state (FMPropertiesWindow *window,
const char *name,
GList **on,
GList **off)
{
GList *l;
*on = NULL;
*off = NULL;
for (l = window->details->original_files; l != NULL; l = l->next) {
GList *initial_emblems;
initial_emblems = g_hash_table_lookup (window->details->initial_emblems,
l->data);
if (g_list_find_custom (initial_emblems, name, (GCompareFunc) strcmp)) {
*on = g_list_prepend (*on, l->data);
} else {
*off = g_list_prepend (*off, l->data);
}
}
}
static void
emblem_button_toggled (GtkToggleButton *button,
FMPropertiesWindow *window)
{
GList *l;
GList *keywords;
GList *word;
char *name;
GList *files_on;
GList *files_off;
name = g_object_get_data (G_OBJECT (button), "nautilus_emblem_name");
files_on = NULL;
files_off = NULL;
if (gtk_toggle_button_get_active (button)
&& !gtk_toggle_button_get_inconsistent (button)) {
/* Go to the initial state unless the initial state was
consistent */
get_initial_emblem_state (window, name,
&files_on, &files_off);
if (!(files_on && files_off)) {
g_list_free (files_on);
g_list_free (files_off);
files_on = g_list_copy (window->details->original_files);
files_off = NULL;
}
} else if (gtk_toggle_button_get_inconsistent (button)
&& !gtk_toggle_button_get_active (button)) {
files_on = g_list_copy (window->details->original_files);
files_off = NULL;
} else {
files_off = g_list_copy (window->details->original_files);
files_on = NULL;
}
g_signal_handlers_block_by_func (G_OBJECT (button),
G_CALLBACK (emblem_button_toggled),
window);
gtk_toggle_button_set_active (button, files_on != NULL);
gtk_toggle_button_set_inconsistent (button, files_on && files_off);
g_signal_handlers_unblock_by_func (G_OBJECT (button),
G_CALLBACK (emblem_button_toggled),
window);
for (l = files_on; l != NULL; l = l->next) {
NautilusFile *file;
file = NAUTILUS_FILE (l->data);
keywords = nautilus_file_get_keywords (file);
word = g_list_find_custom (keywords, name, (GCompareFunc)strcmp);
if (!word) {
keywords = g_list_prepend (keywords, g_strdup (name));
}
nautilus_file_set_keywords (file, keywords);
eel_g_list_free_deep (keywords);
}
for (l = files_off; l != NULL; l = l->next) {
NautilusFile *file;
file = NAUTILUS_FILE (l->data);
keywords = nautilus_file_get_keywords (file);
word = g_list_find_custom (keywords, name, (GCompareFunc)strcmp);
if (word) {
keywords = g_list_remove_link (keywords, word);
eel_g_list_free_deep (word);
}
nautilus_file_set_keywords (file, keywords);
eel_g_list_free_deep (keywords);
}
g_list_free (files_on);
g_list_free (files_off);
}
static void
emblem_button_update (FMPropertiesWindow *window,
GtkToggleButton *button)
{
GList *l;
char *name;
gboolean all_set;
gboolean all_unset;
name = g_object_get_data (G_OBJECT (button), "nautilus_emblem_name");
all_set = TRUE;
all_unset = TRUE;
for (l = window->details->original_files; l != NULL; l = l->next) {
gboolean has_keyword;
NautilusFile *file;
file = NAUTILUS_FILE (l->data);
has_keyword = file_has_keyword (file, name);
if (has_keyword) {
all_unset = FALSE;
} else {
all_set = FALSE;
}
}
g_signal_handlers_block_by_func (G_OBJECT (button),
G_CALLBACK (emblem_button_toggled),
window);
gtk_toggle_button_set_active (button, !all_unset);
gtk_toggle_button_set_inconsistent (button, !all_unset && !all_set);
g_signal_handlers_unblock_by_func (G_OBJECT (button),
G_CALLBACK (emblem_button_toggled),
window);
}
static void
update_properties_window_title (FMPropertiesWindow *window)
{
char *name, *title;
NautilusFile *file;
g_return_if_fail (GTK_IS_WINDOW (window));
title = g_strdup_printf (_("Properties"));
if (!is_multi_file_window (window)) {
file = get_original_file (window);
if (file != NULL) {
g_free (title);
name = nautilus_file_get_display_name (file);
title = g_strdup_printf (_("%s Properties"), name);
g_free (name);
}
}
gtk_window_set_title (GTK_WINDOW (window), title);
g_free (title);
}
static void
clear_extension_pages (FMPropertiesWindow *window)
{
int i;
int num_pages;
GtkWidget *page;
num_pages = gtk_notebook_get_n_pages
(GTK_NOTEBOOK (window->details->notebook));
for (i = 0; i < num_pages; i++) {
page = gtk_notebook_get_nth_page
(GTK_NOTEBOOK (window->details->notebook), i);
if (g_object_get_data (G_OBJECT (page), "is-extension-page")) {
gtk_notebook_remove_page
(GTK_NOTEBOOK (window->details->notebook), i);
num_pages--;
i--;
}
}
}
static void
refresh_extension_pages (FMPropertiesWindow *window)
{
clear_extension_pages (window);
append_extension_pages (window);
}
static void
remove_from_dialog (FMPropertiesWindow *window,
NautilusFile *file)
{
int index;
GList *original_link;
GList *target_link;
NautilusFile *original_file;
NautilusFile *target_file;
index = g_list_index (window->details->target_files, file);
if (index == -1) {
index = g_list_index (window->details->original_files, file);
g_return_if_fail (index != -1);
}
original_link = g_list_nth (window->details->original_files, index);
target_link = g_list_nth (window->details->target_files, index);
g_return_if_fail (original_link && target_link);
original_file = NAUTILUS_FILE (original_link->data);
target_file = NAUTILUS_FILE (target_link->data);
window->details->original_files = g_list_remove_link (window->details->original_files, original_link);
g_list_free (original_link);
window->details->target_files = g_list_remove_link (window->details->target_files, target_link);
g_list_free (target_link);
g_hash_table_remove (window->details->initial_emblems, original_file);
g_hash_table_remove (window->details->initial_permissions, target_file);
g_signal_handlers_disconnect_by_func (original_file,
G_CALLBACK (file_changed_callback),
window);
g_signal_handlers_disconnect_by_func (target_file,
G_CALLBACK (file_changed_callback),
window);
nautilus_file_monitor_remove (original_file, &window->details->original_files);
nautilus_file_monitor_remove (target_file, &window->details->target_files);
nautilus_file_unref (original_file);
nautilus_file_unref (target_file);
}
static gboolean
mime_list_equal (GList *a, GList *b)
{
while (a && b) {
if (strcmp (a->data, b->data)) {
return FALSE;
}
a = a->next;
b = b->next;
}
return (a == b);
}
static GList *
get_mime_list (FMPropertiesWindow *window)
{
GList *ret;
GList *l;
ret = NULL;
for (l = window->details->target_files; l != NULL; l = l->next) {
ret = g_list_append (ret, nautilus_file_get_mime_type (NAUTILUS_FILE (l->data)));
}
ret = g_list_reverse (ret);
return ret;
}
static void
properties_window_update (FMPropertiesWindow *window,
GList *files)
{
GList *l;
GList *mime_list;
GList *tmp;
NautilusFile *changed_file;
gboolean dirty_original = FALSE;
gboolean dirty_target = FALSE;
if (files == NULL) {
dirty_original = TRUE;
dirty_target = TRUE;
}
for (tmp = files; tmp != NULL; tmp = tmp->next) {
changed_file = NAUTILUS_FILE (tmp->data);
if (changed_file && nautilus_file_is_gone (changed_file)) {
/* Remove the file from the property dialog */
remove_from_dialog (window, changed_file);
changed_file = NULL;
if (window->details->original_files == NULL) {
return;
}
}
if (changed_file == NULL ||
g_list_find (window->details->original_files, changed_file)) {
dirty_original = TRUE;
}
if (changed_file == NULL ||
g_list_find (window->details->target_files, changed_file)) {
dirty_target = TRUE;
}
}
if (dirty_original) {
update_properties_window_title (window);
update_properties_window_icon (GTK_IMAGE (window->details->icon_image));
update_name_field (window);
for (l = window->details->emblem_buttons; l != NULL; l = l->next) {
emblem_button_update (window, GTK_TOGGLE_BUTTON (l->data));
}
/* If any of the value fields start to depend on the original
* value, value_field_updates should be added here */
}
if (dirty_target) {
for (l = window->details->permission_buttons; l != NULL; l = l->next) {
permission_button_update (window, GTK_TOGGLE_BUTTON (l->data));
}
for (l = window->details->permission_combos; l != NULL; l = l->next) {
permission_combo_update (window, GTK_COMBO_BOX (l->data));
}
for (l = window->details->value_fields; l != NULL; l = l->next) {
value_field_update (window, GTK_LABEL (l->data));
}
}
mime_list = get_mime_list (window);
if (!window->details->mime_list) {
window->details->mime_list = mime_list;
} else {
if (!mime_list_equal (window->details->mime_list, mime_list)) {
refresh_extension_pages (window);
}
eel_g_list_free_deep (window->details->mime_list);
window->details->mime_list = mime_list;
}
}
static gboolean
update_files_callback (gpointer data)
{
FMPropertiesWindow *window;
window = FM_PROPERTIES_WINDOW (data);
window->details->update_files_timeout_id = 0;
properties_window_update (window, window->details->changed_files);
if (window->details->original_files == NULL) {
/* Close the window if no files are left */
gtk_widget_destroy (GTK_WIDGET (window));
} else {
nautilus_file_list_free (window->details->changed_files);
window->details->changed_files = NULL;
}
return FALSE;
}
static void
schedule_files_update (FMPropertiesWindow *window)
{
g_assert (FM_IS_PROPERTIES_WINDOW (window));
if (window->details->update_files_timeout_id == 0) {
window->details->update_files_timeout_id
= g_timeout_add (FILES_UPDATE_INTERVAL,
update_files_callback,
window);
}
}
static gboolean
file_list_attributes_identical (GList *file_list, const char *attribute_name)
{
gboolean identical;
char *first_attr;
GList *l;
first_attr = NULL;
identical = TRUE;
for (l = file_list; l != NULL; l = l->next) {
NautilusFile *file;
file = NAUTILUS_FILE (l->data);
if (nautilus_file_is_gone (file)) {
continue;
}
if (first_attr == NULL) {
first_attr = nautilus_file_get_string_attribute_with_default (file, attribute_name);
} else {
char *attr;
attr = nautilus_file_get_string_attribute_with_default (file, attribute_name);
if (strcmp (attr, first_attr)) {
identical = FALSE;
g_free (attr);
break;
}
g_free (attr);
}
}
g_free (first_attr);
return identical;
}
static char *
file_list_get_string_attribute (GList *file_list,
const char *attribute_name,
const char *inconsistent_value)
{
if (file_list_attributes_identical (file_list, attribute_name)) {
GList *l;
for (l = file_list; l != NULL; l = l->next) {
NautilusFile *file;
file = NAUTILUS_FILE (l->data);
if (!nautilus_file_is_gone (file)) {
return nautilus_file_get_string_attribute_with_default
(file,
attribute_name);
}
}
return g_strdup (_("unknown"));
} else {
return g_strdup (inconsistent_value);
}
}
static gboolean
file_list_all_local (GList *file_list)
{
GList *l;
for (l = file_list; l != NULL; l = l->next) {
if (!nautilus_file_is_local (NAUTILUS_FILE (l->data))) {
return FALSE;
}
}
return TRUE;
}
static gboolean
file_list_all_directories (GList *file_list)
{
GList *l;
for (l = file_list; l != NULL; l = l->next) {
if (!nautilus_file_is_directory (NAUTILUS_FILE (l->data))) {
return FALSE;
}
}
return TRUE;
}
static void
value_field_update_internal (GtkLabel *label,
GList *file_list,
gboolean ellipsize_text)
{
const char *attribute_name;
char *attribute_value;
char *inconsistent_string;
g_assert (GTK_IS_LABEL (label));
g_assert (!ellipsize_text || EEL_IS_ELLIPSIZING_LABEL (label));
attribute_name = g_object_get_data (G_OBJECT (label), "file_attribute");
inconsistent_string = g_object_get_data (G_OBJECT (label), "inconsistent_string");
attribute_value = file_list_get_string_attribute (file_list,
attribute_name,
inconsistent_string);
if (ellipsize_text) {
eel_ellipsizing_label_set_text (EEL_ELLIPSIZING_LABEL (label),
attribute_value);
} else {
gtk_label_set_text (label, attribute_value);
}
g_free (attribute_value);
}
static void
value_field_update (FMPropertiesWindow *window, GtkLabel *label)
{
gboolean ellipsize_text;
gboolean use_original;
ellipsize_text = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (label), "ellipsize_text"));
use_original = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (label), "show_original"));
value_field_update_internal (label,
(use_original ?
window->details->original_files :
window->details->target_files),
ellipsize_text);
}
static GtkLabel *
attach_label (GtkTable *table,
int row,
int column,
const char *initial_text,
gboolean right_aligned,
gboolean bold,
gboolean ellipsize_text,
gboolean selectable,
gboolean mnemonic)
{
GtkWidget *label_field;
if (ellipsize_text) {
label_field = eel_ellipsizing_label_new (initial_text);
} else if (mnemonic) {
label_field = gtk_label_new_with_mnemonic (initial_text);
} else {
label_field = gtk_label_new (initial_text);
}
if (selectable) {
gtk_label_set_selectable (GTK_LABEL (label_field), TRUE);
}
if (bold) {
eel_gtk_label_make_bold (GTK_LABEL (label_field));
}
gtk_misc_set_alignment (GTK_MISC (label_field), right_aligned ? 1 : 0, 0.5);
gtk_widget_show (label_field);
gtk_table_attach (table, label_field,
column, column + 1,
row, row + 1,
ellipsize_text
? GTK_FILL | GTK_EXPAND
: GTK_FILL,
0,
0, 0);
return GTK_LABEL (label_field);
}
static GtkLabel *
attach_value_label (GtkTable *table,
int row,
int column,
const char *initial_text)
{
return attach_label (table, row, column, initial_text, FALSE, FALSE, FALSE, TRUE, FALSE);
}
static GtkLabel *
attach_ellipsizing_value_label (GtkTable *table,
int row,
int column,
const char *initial_text)
{
return attach_label (table, row, column, initial_text, FALSE, FALSE, TRUE, TRUE, FALSE);
}
static void
attach_value_field_internal (FMPropertiesWindow *window,
GtkTable *table,
int row,
int column,
const char *file_attribute_name,
const char *inconsistent_string,
gboolean show_original,
gboolean ellipsize_text)
{
GtkLabel *value_field;
if (ellipsize_text) {
value_field = attach_ellipsizing_value_label (table, row, column, "");
} else {
value_field = attach_value_label (table, row, column, "");
}
/* Stash a copy of the file attribute name in this field for the callback's sake. */
g_object_set_data_full (G_OBJECT (value_field), "file_attribute",
g_strdup (file_attribute_name), g_free);
g_object_set_data_full (G_OBJECT (value_field), "inconsistent_string",
g_strdup (inconsistent_string), g_free);
g_object_set_data (G_OBJECT (value_field), "show_original", GINT_TO_POINTER (show_original));
g_object_set_data (G_OBJECT (value_field), "ellipsize_text", GINT_TO_POINTER (ellipsize_text));
window->details->value_fields = g_list_prepend (window->details->value_fields,
value_field);
}
static void
attach_value_field (FMPropertiesWindow *window,
GtkTable *table,
int row,
int column,
const char *file_attribute_name,
const char *inconsistent_string,
gboolean show_original)
{
attach_value_field_internal (window,
table, row, column,
file_attribute_name,
inconsistent_string,
show_original,
FALSE);
}
static void
attach_ellipsizing_value_field (FMPropertiesWindow *window,
GtkTable *table,
int row,
int column,
const char *file_attribute_name,
const char *inconsistent_string,
gboolean show_original)
{
attach_value_field_internal (window,
table, row, column,
file_attribute_name,
inconsistent_string,
show_original,
TRUE);
}
static void
group_change_callback (NautilusFile *file, GnomeVFSResult result, gpointer callback_data)
{
g_assert (callback_data == NULL);
/* Report the error if it's an error. */
eel_timed_wait_stop (cancel_group_change_callback, file);
fm_report_error_setting_group (file, result, NULL);
nautilus_file_unref (file);
}
static void
cancel_group_change_callback (gpointer callback_data)
{
NautilusFile *file;
file = NAUTILUS_FILE (callback_data);
nautilus_file_cancel (file, group_change_callback, NULL);
nautilus_file_unref (file);
}
static void
changed_group_callback (GtkComboBox *combo_box, NautilusFile *file)
{
char *group;
char *cur_group;
group = gtk_combo_box_get_active_text (combo_box);
cur_group = nautilus_file_get_group_name (file);
if (strcmp (group, cur_group) != 0) {
/* Try to change file group. If this fails, complain to user. */
nautilus_file_ref (file);
eel_timed_wait_start
(cancel_group_change_callback,
file,
_("Cancel Group Change?"),
NULL); /* FIXME bugzilla.gnome.org 42397: Parent this? */
nautilus_file_set_group
(file, group,
group_change_callback, NULL);
}
g_free (group);
g_free (cur_group);
}
static void
synch_groups_combo_box (GtkComboBox *combo_box, NautilusFile *file)
{
GList *groups;
GList *node;
GtkTreeModel *model;
GtkListStore *store;
const char *group_name;
char *current_group_name;
int group_index;
int current_group_index;
g_assert (GTK_IS_COMBO_BOX (combo_box));
g_assert (NAUTILUS_IS_FILE (file));
if (nautilus_file_is_gone (file)) {
return;
}
/* Clear the contents of ComboBox in a wacky way because there
* is no function to clear all items and also no function to obtain
* the number of items in a combobox.
*/
model = gtk_combo_box_get_model (combo_box);
g_return_if_fail (GTK_IS_LIST_STORE (model));
store = GTK_LIST_STORE (model);
gtk_list_store_clear (store);
current_group_name = nautilus_file_get_group_name (file);
current_group_index = -1;
groups = nautilus_file_get_settable_group_names (file);
for (node = groups, group_index = 0; node != NULL; node = node->next, ++group_index) {
group_name = (const char *)node->data;
if (strcmp (group_name, current_group_name) == 0) {
current_group_index = group_index;
}
gtk_combo_box_append_text (combo_box, group_name);
}
/* If current group wasn't in list, we prepend it (with a separator).
* This can happen if the current group is an id with no matching
* group in the groups file.
*/
if (current_group_index < 0 && current_group_name != NULL) {
if (groups != NULL) {
/* add separator */
gtk_combo_box_prepend_text (combo_box, "-");
}
gtk_combo_box_prepend_text (combo_box, current_group_name);
current_group_index = 0;
}
gtk_combo_box_set_active (combo_box, current_group_index);
g_free (current_group_name);
eel_g_list_free_deep (groups);
}
static gboolean
combo_box_row_separator_func (GtkTreeModel *model,
GtkTreeIter *iter,
gpointer data)
{
gchar *text;
gboolean ret;
gtk_tree_model_get (model, iter, 0, &text, -1);
if (text == NULL) {
return FALSE;
}
if (strcmp (text, "-") == 0) {
ret = TRUE;
} else {
ret = FALSE;
}
g_free (text);
return ret;
}
static GtkComboBox *
attach_combo_box (GtkTable *table,
int row)
{
GtkWidget *combo_box;
GtkWidget *aligner;
combo_box = gtk_combo_box_new_text ();
gtk_widget_show (combo_box);
gtk_combo_box_set_row_separator_func (GTK_COMBO_BOX (combo_box),
combo_box_row_separator_func,
NULL,
NULL);
/* Put combo box in alignment to make it left-justified
* but minimally sized.
*/
aligner = gtk_alignment_new (0, 0.5, 0, 0);
gtk_widget_show (aligner);
gtk_container_add (GTK_CONTAINER (aligner), combo_box);
gtk_table_attach (table, aligner,
VALUE_COLUMN, VALUE_COLUMN + 1,
row, row + 1,
GTK_FILL, 0,
0, 0);
return GTK_COMBO_BOX (combo_box);
}
static GtkComboBox*
attach_group_combo_box (GtkTable *table,
int row,
NautilusFile *file)
{
GtkComboBox *combo_box;
combo_box = attach_combo_box (table, row);
synch_groups_combo_box (combo_box, file);
/* Connect to signal to update menu when file changes. */
g_signal_connect_object (file, "changed",
G_CALLBACK (synch_groups_combo_box),
combo_box, G_CONNECT_SWAPPED);
g_signal_connect_data (combo_box, "changed",
G_CALLBACK (changed_group_callback),
nautilus_file_ref (file),
(GClosureNotify)nautilus_file_unref, 0);
return combo_box;
}
static void
owner_change_callback (NautilusFile *file, GnomeVFSResult result, gpointer callback_data)
{
g_assert (callback_data == NULL);
/* Report the error if it's an error. */
eel_timed_wait_stop (cancel_owner_change_callback, file);
fm_report_error_setting_owner (file, result, NULL);
nautilus_file_unref (file);
}
static void
cancel_owner_change_callback (gpointer callback_data)
{
NautilusFile *file;
file = NAUTILUS_FILE (callback_data);
nautilus_file_cancel (file, owner_change_callback, NULL);
nautilus_file_unref (file);
}
static void
changed_owner_callback (GtkComboBox *combo_box, NautilusFile* file)
{
char *owner_text;
char **name_array;
char *new_owner;
char *cur_owner;
g_assert (GTK_IS_COMBO_BOX (combo_box));
g_assert (NAUTILUS_IS_FILE (file));
owner_text = gtk_combo_box_get_active_text (combo_box);
name_array = g_strsplit (owner_text, " - ", 2);
new_owner = name_array[0];
g_free (owner_text);
cur_owner = nautilus_file_get_owner_name (file);
if (strcmp (new_owner, cur_owner) != 0) {
/* Try to change file owner. If this fails, complain to user. */
nautilus_file_ref (file);
eel_timed_wait_start
(cancel_owner_change_callback,
file,
_("Cancel Owner Change?"),
NULL); /* FIXME bugzilla.gnome.org 42397: Parent this? */
nautilus_file_set_owner
(file, name_array[0],
owner_change_callback, NULL);
}
g_strfreev (name_array);
g_free (cur_owner);
}
static void
synch_user_menu (GtkComboBox *combo_box, NautilusFile *file)
{
GList *users;
GList *node;
GtkTreeModel *model;
GtkListStore *store;
const char *user_name;
char *owner_name;
int user_index;
int owner_index;
char **name_array;
char *combo_text;
g_assert (GTK_IS_COMBO_BOX (combo_box));
g_assert (NAUTILUS_IS_FILE (file));
if (nautilus_file_is_gone (file)) {
return;
}
/* Clear the contents of ComboBox in a wacky way because there
* is no function to clear all items and also no function to obtain
* the number of items in a combobox.
*/
model = gtk_combo_box_get_model (combo_box);
g_return_if_fail (GTK_IS_LIST_STORE (model));
store = GTK_LIST_STORE (model);
gtk_list_store_clear (store);
owner_name = nautilus_file_get_string_attribute (file, "owner");
owner_index = -1;
users = nautilus_get_user_names ();
for (node = users, user_index = 0; node != NULL; node = node->next, ++user_index) {
user_name = (const char *)node->data;
name_array = g_strsplit (user_name, "\n", 2);
if (name_array[1] != NULL) {
combo_text = g_strdup_printf ("%s - %s", name_array[0], name_array[1]);
} else {
combo_text = g_strdup (name_array[0]);
}
if (strcmp (combo_text, owner_name) == 0) {
owner_index = user_index;
}
gtk_combo_box_append_text (combo_box, combo_text);
g_strfreev (name_array);
g_free (combo_text);
}
/* If owner wasn't in list, we prepend it (with a separator).
* This can happen if the owner is an id with no matching
* identifier in the passwords file.
*/
if (owner_index < 0 && owner_name != NULL) {
/* add separator */
gtk_combo_box_prepend_text (combo_box, "-");
gtk_combo_box_prepend_text (combo_box, owner_name);
owner_index = 0;
}
gtk_combo_box_set_active (combo_box, owner_index);
g_free (owner_name);
eel_g_list_free_deep (users);
}
static GtkComboBox*
attach_owner_combo_box (GtkTable *table,
int row,
NautilusFile *file)
{
GtkComboBox *combo_box;
combo_box = attach_combo_box (table, row);
synch_user_menu (combo_box, file);
/* Connect to signal to update menu when file changes. */
g_signal_connect_object (file, "changed",
G_CALLBACK (synch_user_menu),
combo_box, G_CONNECT_SWAPPED);
g_signal_connect_data (combo_box, "changed",
G_CALLBACK (changed_owner_callback),
nautilus_file_ref (file),
(GClosureNotify)nautilus_file_unref, 0);
return combo_box;
}
static guint
append_row (GtkTable *table)
{
guint new_row_count;
new_row_count = table->nrows + 1;
gtk_table_resize (table, new_row_count, table->ncols);
gtk_table_set_row_spacing (table, new_row_count - 1, ROW_PAD);
return new_row_count - 1;
}
static void
directory_contents_value_field_update (FMPropertiesWindow *window)
{
NautilusRequestStatus file_status, status;
char *text, *temp;
guint directory_count;
guint file_count;
guint total_count;
guint unreadable_directory_count;
GnomeVFSFileSize total_size;
gboolean used_two_lines;
NautilusFile *file;
GList *l;
guint file_unreadable;
GnomeVFSFileSize file_size;
g_assert (FM_IS_PROPERTIES_WINDOW (window));
status = NAUTILUS_REQUEST_DONE;
file_status = NAUTILUS_REQUEST_NOT_STARTED;
total_count = window->details->total_count;
total_size = window->details->total_size;
unreadable_directory_count = FALSE;
for (l = window->details->target_files; l; l = l->next) {
file = NAUTILUS_FILE (l->data);
if (nautilus_file_is_directory (file)) {
file_status = nautilus_file_get_deep_counts (file,
&directory_count,
&file_count,
&file_unreadable,
&file_size,
TRUE);
total_count += (file_count + directory_count);
total_size += file_size;
if (file_unreadable) {
unreadable_directory_count = TRUE;
}
if (file_status != NAUTILUS_REQUEST_DONE) {
status = file_status;
}
} else {
++total_count;
total_size += nautilus_file_get_size (file);
}
}
/* If we've already displayed the total once, don't do another visible
* count-up if the deep_count happens to get invalidated.
* But still display the new total, since it might have changed.
*/
if (window->details->deep_count_finished &&
status != NAUTILUS_REQUEST_DONE) {
return;
}
text = NULL;
used_two_lines = FALSE;
if (total_count == 0) {
switch (status) {
case NAUTILUS_REQUEST_DONE:
if (unreadable_directory_count == 0) {
text = g_strdup (_("nothing"));
} else {
text = g_strdup (_("unreadable"));
}
break;
default:
text = g_strdup ("...");
}
} else {
char *size_str;
size_str = gnome_vfs_format_file_size_for_display (total_size);
text = g_strdup_printf (ngettext("%d item, with size %s",
"%d items, totalling %s",
total_count),
total_count, size_str);
g_free (size_str);
if (unreadable_directory_count != 0) {
temp = text;
text = g_strconcat (temp, "\n",
_("(some contents unreadable)"),
NULL);
g_free (temp);
used_two_lines = TRUE;
}
}
gtk_label_set_text (window->details->directory_contents_value_field,
text);
g_free (text);
/* Also set the title field here, with a trailing carriage return &
* space if the value field has two lines. This is a hack to get the
* "Contents:" title to line up with the first line of the
* 2-line value. Maybe there's a better way to do this, but I
* couldn't think of one.
*/
text = g_strdup (_("Contents:"));
if (used_two_lines) {
temp = text;
text = g_strconcat (temp, "\n ", NULL);
g_free (temp);
}
gtk_label_set_text (window->details->directory_contents_title_field,
text);
g_free (text);
if (status == NAUTILUS_REQUEST_DONE) {
window->details->deep_count_finished = TRUE;
}
}
static gboolean
update_directory_contents_callback (gpointer data)
{
FMPropertiesWindow *window;
window = FM_PROPERTIES_WINDOW (data);
window->details->update_directory_contents_timeout_id = 0;
directory_contents_value_field_update (window);
return FALSE;
}
static void
schedule_directory_contents_update (FMPropertiesWindow *window)
{
g_assert (FM_IS_PROPERTIES_WINDOW (window));
if (window->details->update_directory_contents_timeout_id == 0) {
window->details->update_directory_contents_timeout_id
= g_timeout_add (DIRECTORY_CONTENTS_UPDATE_INTERVAL,
update_directory_contents_callback,
window);
}
}
static GtkLabel *
attach_directory_contents_value_field (FMPropertiesWindow *window,
GtkTable *table,
int row)
{
GtkLabel *value_field;
GList *l;
NautilusFile *file;
value_field = attach_value_label (table, row, VALUE_COLUMN, "");
g_assert (window->details->directory_contents_value_field == NULL);
window->details->directory_contents_value_field = value_field;
gtk_label_set_line_wrap (value_field, TRUE);
/* Fill in the initial value. */
directory_contents_value_field_update (window);
for (l = window->details->target_files; l; l = l->next) {
file = NAUTILUS_FILE (l->data);
nautilus_file_recompute_deep_counts (file);
g_signal_connect_object (file,
"updated_deep_count_in_progress",
G_CALLBACK (schedule_directory_contents_update),
window, G_CONNECT_SWAPPED);
}
return value_field;
}
static GtkLabel *
attach_title_field (GtkTable *table,
int row,
const char *title)
{
return attach_label (table, row, TITLE_COLUMN, title, TRUE, TRUE, FALSE, FALSE, TRUE);
}
static guint
append_title_field (GtkTable *table, const char *title, GtkLabel **label)
{
guint last_row;
GtkLabel *title_label;
last_row = append_row (table);
title_label = attach_title_field (table, last_row, title);
if (label) {
*label = title_label;
}
return last_row;
}
static guint
append_title_value_pair (FMPropertiesWindow *window,
GtkTable *table,
const char *title,
const char *file_attribute_name,
const char *inconsistent_state,
gboolean show_original)
{
guint last_row;
last_row = append_title_field (table, title, NULL);
attach_value_field (window, table, last_row, VALUE_COLUMN,
file_attribute_name,
inconsistent_state,
show_original);
return last_row;
}
static guint
append_title_and_ellipsizing_value (FMPropertiesWindow *window,
GtkTable *table,
const char *title,
const char *file_attribute_name,
const char *inconsistent_state,
gboolean show_original)
{
guint last_row;
last_row = append_title_field (table, title, NULL);
attach_ellipsizing_value_field (window, table, last_row, VALUE_COLUMN,
file_attribute_name,
inconsistent_state,
show_original);
return last_row;
}
static guint
append_directory_contents_fields (FMPropertiesWindow *window,
GtkTable *table)
{
GtkLabel *title_field, *value_field;
guint last_row;
last_row = append_row (table);
title_field = attach_title_field (table, last_row, "");
window->details->directory_contents_title_field = title_field;
gtk_label_set_line_wrap (title_field, TRUE);
value_field = attach_directory_contents_value_field
(window, table, last_row);
return last_row;
}
static GtkWidget *
create_page_with_vbox (GtkNotebook *notebook,
const char *title)
{
GtkWidget *vbox;
g_assert (GTK_IS_NOTEBOOK (notebook));
g_assert (title != NULL);
vbox = gtk_vbox_new (FALSE, 0);
gtk_widget_show (vbox);
gtk_container_set_border_width (GTK_CONTAINER (vbox), 12);
gtk_notebook_append_page (notebook, vbox, gtk_label_new (title));
return vbox;
}
static void
apply_standard_table_padding (GtkTable *table)
{
gtk_table_set_row_spacings (table, ROW_PAD);
gtk_table_set_col_spacings (table, 12);
}
static GtkWidget *
create_attribute_value_table (GtkVBox *vbox, int row_count)
{
GtkWidget *table;
table = gtk_table_new (row_count, COLUMN_COUNT, FALSE);
apply_standard_table_padding (GTK_TABLE (table));
gtk_widget_show (table);
gtk_box_pack_start (GTK_BOX (vbox), table, FALSE, FALSE, 0);
return table;
}
static void
create_page_with_table_in_vbox (GtkNotebook *notebook,
const char *title,
int row_count,
GtkTable **return_table,
GtkWidget **return_vbox)
{
GtkWidget *table;
GtkWidget *vbox;
vbox = create_page_with_vbox (notebook, title);
table = create_attribute_value_table (GTK_VBOX (vbox), row_count);
if (return_table != NULL) {
*return_table = GTK_TABLE (table);
}
if (return_vbox != NULL) {
*return_vbox = vbox;
}
}
static gboolean
is_merged_trash_directory (NautilusFile *file)
{
char *file_uri;
gboolean result;
file_uri = nautilus_file_get_uri (file);
result = gnome_vfs_uris_match (file_uri, EEL_TRASH_URI);
g_free (file_uri);
return result;
}
static gboolean
should_show_custom_icon_buttons (FMPropertiesWindow *window)
{
/* FIXME bugzilla.gnome.org 45642:
* Custom icons aren't displayed on the the desktop Trash icon, so
* we shouldn't pretend that they work by showing them here.
* When bug 5642 is fixed we can remove this case.
*/
if (!is_multi_file_window (window)
&& is_merged_trash_directory (get_target_file (window))) {
return FALSE;
}
return TRUE;
}
static gboolean
should_show_file_type (FMPropertiesWindow *window)
{
/* The trash on the desktop is one-of-a-kind */
if (!is_multi_file_window (window)
&& is_merged_trash_directory (get_target_file (window))) {
return FALSE;
}
return TRUE;
}
static gboolean
should_show_accessed_date (FMPropertiesWindow *window)
{
/* Accessed date for directory seems useless. If we some
* day decide that it is useful, we should separately
* consider whether it's useful for "trash:".
*/
if (file_list_all_directories (window->details->target_files)) {
return FALSE;
}
return TRUE;
}
static gboolean
should_show_mime_type (FMPropertiesWindow *window)
{
if (file_list_all_directories (window->details->target_files)) {
return FALSE;
}
return TRUE;
}
static gboolean
should_show_link_target (FMPropertiesWindow *window)
{
if (!is_multi_file_window (window)
&& nautilus_file_is_symbolic_link (get_target_file (window))) {
return TRUE;
}
return FALSE;
}
static gboolean
should_show_free_space (FMPropertiesWindow *window)
{
if (file_list_all_local (window->details->target_files)
&& file_list_all_directories (window->details->target_files)) {
return TRUE;
}
return FALSE;
}
static void
create_basic_page (FMPropertiesWindow *window)
{
GtkTable *table;
GtkWidget *container;
GtkWidget *icon_aligner;
GtkWidget *icon_pixmap_widget;
GtkWidget *hbox, *name_label;
create_page_with_table_in_vbox (window->details->notebook,
_("Basic"),
1,
&table,
&container);
window->details->basic_table = table;
/* Icon pixmap */
hbox = gtk_hbox_new (FALSE, 4);
gtk_widget_show (hbox);
gtk_table_attach (table,
hbox,
TITLE_COLUMN,
TITLE_COLUMN + 1,
0, 1,
0, 0,
0, 0);
icon_pixmap_widget = create_image_widget (
window, should_show_custom_icon_buttons (window));
gtk_widget_show (icon_pixmap_widget);
icon_aligner = gtk_alignment_new (1, 0.5, 0, 0);
gtk_widget_show (icon_aligner);
gtk_container_add (GTK_CONTAINER (icon_aligner), icon_pixmap_widget);
gtk_box_pack_start (GTK_BOX (hbox), icon_aligner, TRUE, TRUE, 0);
window->details->icon_chooser = NULL;
/* Name label */
name_label = gtk_label_new_with_mnemonic (ngettext ("_Name:", "_Names:",
get_not_gone_original_file_count (window)));
eel_gtk_label_make_bold (GTK_LABEL (name_label));
gtk_widget_show (name_label);
gtk_box_pack_end (GTK_BOX (hbox), name_label, FALSE, FALSE, 0);
window->details->name_label = name_label;
/* Name field */
window->details->name_field = NULL;
update_name_field (window);
/* Start with name field selected, if it's an entry. */
if (NAUTILUS_IS_ENTRY (window->details->name_field)) {
nautilus_entry_select_all (NAUTILUS_ENTRY (window->details->name_field));
gtk_widget_grab_focus (GTK_WIDGET (window->details->name_field));
}
if (should_show_file_type (window)) {
append_title_value_pair (window,
table, _("Type:"),
"type",
_("--"),
FALSE);
}
if (is_multi_file_window (window) ||
nautilus_file_is_directory (get_target_file (window))) {
append_directory_contents_fields (window, table);
} else {
append_title_value_pair (window, table, _("Size:"),
"size_detail",
_("--"),
FALSE);
}
append_title_and_ellipsizing_value (window, table, _("Location:"),
"where",
_("--"),
TRUE);
if (should_show_free_space (window)) {
append_title_and_ellipsizing_value (window, table,
_("Volume:"),
"volume",
_("--"),
FALSE);
append_title_value_pair (window, table, _("Free space:"),
"free_space",
_("--"),
FALSE);
}
if (should_show_link_target (window)) {
append_title_and_ellipsizing_value (window, table,
_("Link target:"),
"link_target",
_("--"),
FALSE);
}
if (should_show_mime_type (window)) {
append_title_value_pair (window, table, _("MIME type:"),
"mime_type",
_("--"),
FALSE);
}
/* Blank title ensures standard row height */
append_title_field (table, "", NULL);
append_title_value_pair (window, table, _("Modified:"),
"date_modified",
_("--"),
FALSE);
if (should_show_accessed_date (window)) {
append_title_value_pair (window, table, _("Accessed:"),
"date_accessed",
_("--"),
FALSE);
}
}
static GHashTable *
get_initial_emblems (GList *files)
{
GHashTable *ret;
GList *l;
ret = g_hash_table_new_full (g_direct_hash,
g_direct_equal,
NULL,
(GDestroyNotify)eel_g_list_free_deep);
for (l = files; l != NULL; l = l->next) {
NautilusFile *file;
GList *keywords;
file = NAUTILUS_FILE (l->data);
keywords = nautilus_file_get_keywords (file);
g_hash_table_insert (ret, file, keywords);
}
return ret;
}
static gboolean
files_has_directory (FMPropertiesWindow *window)
{
GList *l;
for (l = window->details->target_files; l != NULL; l = l->next) {
NautilusFile *file;
file = NAUTILUS_FILE (l->data);
if (nautilus_file_is_directory (file)) {
return TRUE;
}
}
return FALSE;
}
static gboolean
files_has_changable_permissions_directory (FMPropertiesWindow *window)
{
GList *l;
for (l = window->details->target_files; l != NULL; l = l->next) {
NautilusFile *file;
file = NAUTILUS_FILE (l->data);
if (nautilus_file_is_directory (file) &&
nautilus_file_can_get_permissions (file) &&
nautilus_file_can_set_permissions (file)) {
return TRUE;
}
}
return FALSE;
}
static gboolean
files_has_file (FMPropertiesWindow *window)
{
GList *l;
for (l = window->details->target_files; l != NULL; l = l->next) {
NautilusFile *file;
file = NAUTILUS_FILE (l->data);
if (!nautilus_file_is_directory (file)) {
return TRUE;
}
}
return FALSE;
}
static void
create_emblems_page (FMPropertiesWindow *window)
{
GtkWidget *emblems_table, *button, *scroller;
char *emblem_name;
GdkPixbuf *pixbuf;
char *label;
GList *icons, *l;
/* The emblems wrapped table */
scroller = eel_scrolled_wrap_table_new (TRUE, &emblems_table);
gtk_container_set_border_width (GTK_CONTAINER (emblems_table), 12);
gtk_widget_show (scroller);
gtk_notebook_append_page (window->details->notebook,
scroller, gtk_label_new (_("Emblems")));
icons = nautilus_emblem_list_availible ();
window->details->initial_emblems = get_initial_emblems (window->details->original_files);
l = icons;
while (l != NULL) {
emblem_name = l->data;
l = l->next;
if (!nautilus_emblem_should_show_in_list (emblem_name)) {
continue;
}
pixbuf = nautilus_icon_factory_get_pixbuf_from_name (emblem_name, NULL,
NAUTILUS_ICON_SIZE_SMALL, TRUE,
&label);
if (pixbuf == NULL) {
continue;
}
if (label == NULL) {
label = nautilus_emblem_get_keyword_from_icon_name (emblem_name);
}
button = eel_labeled_image_check_button_new (label, pixbuf);
eel_labeled_image_set_fixed_image_height (EEL_LABELED_IMAGE (GTK_BIN (button)->child), STANDARD_EMBLEM_HEIGHT);
eel_labeled_image_set_spacing (EEL_LABELED_IMAGE (GTK_BIN (button)->child), EMBLEM_LABEL_SPACING);
g_free (label);
g_object_unref (pixbuf);
/* Attach parameters and signal handler. */
g_object_set_data_full (G_OBJECT (button), "nautilus_emblem_name",
nautilus_emblem_get_keyword_from_icon_name (emblem_name), g_free);
window->details->emblem_buttons =
g_list_append (window->details->emblem_buttons,
button);
g_signal_connect_object (button, "toggled",
G_CALLBACK (emblem_button_toggled),
G_OBJECT (window),
0);
gtk_container_add (GTK_CONTAINER (emblems_table), button);
}
eel_g_list_free_deep (icons);
gtk_widget_show_all (emblems_table);
}
static void
start_long_operation (FMPropertiesWindow *window)
{
if (window->details->long_operation_underway == 0) {
/* start long operation */
GdkCursor * cursor;
cursor = gdk_cursor_new (GDK_WATCH);
gdk_window_set_cursor (GTK_WIDGET (window)->window, cursor);
gdk_cursor_unref (cursor);
}
window->details->long_operation_underway ++;
}
static void
end_long_operation (FMPropertiesWindow *window)
{
if (GTK_WIDGET (window)->window != NULL &&
window->details->long_operation_underway == 1) {
/* finished !! */
gdk_window_set_cursor (GTK_WIDGET (window)->window, NULL);
}
window->details->long_operation_underway--;
}
static void
permission_change_callback (NautilusFile *file, GnomeVFSResult result, gpointer callback_data)
{
FMPropertiesWindow *window;
g_assert (callback_data != NULL);
window = FM_PROPERTIES_WINDOW (callback_data);
end_long_operation (window);
/* Report the error if it's an error. */
fm_report_error_setting_permissions (file, result, NULL);
g_object_unref (window);
}
static void
update_permissions (FMPropertiesWindow *window,
GnomeVFSFilePermissions vfs_new_perm,
GnomeVFSFilePermissions vfs_mask,
gboolean is_folder,
gboolean apply_to_both_folder_and_dir,
gboolean use_original)
{
GList *l;
for (l = window->details->target_files; l != NULL; l = l->next) {
NautilusFile *file;
GnomeVFSFilePermissions permissions;
file = NAUTILUS_FILE (l->data);
if (!nautilus_file_can_get_permissions (file)) {
continue;
}
if (!apply_to_both_folder_and_dir &&
((nautilus_file_is_directory (file) && !is_folder) ||
(!nautilus_file_is_directory (file) && is_folder))) {
continue;
}
permissions = nautilus_file_get_permissions (file);
if (use_original) {
gpointer ptr;
if (g_hash_table_lookup_extended (window->details->initial_permissions,
file, NULL, &ptr)) {
permissions = (permissions & ~vfs_mask) | (GPOINTER_TO_INT (ptr) & vfs_mask);
}
} else {
permissions = (permissions & ~vfs_mask) | vfs_new_perm;
}
start_long_operation (window);
g_object_ref (window);
nautilus_file_set_permissions
(file, permissions,
permission_change_callback,
window);
}
}
static gboolean
initial_permission_state_consistent (FMPropertiesWindow *window,
GnomeVFSFilePermissions mask,
gboolean is_folder,
gboolean both_folder_and_dir)
{
GList *l;
gboolean first;
GnomeVFSFilePermissions first_permissions;
first = TRUE;
first_permissions = 0;
for (l = window->details->target_files; l != NULL; l = l->next) {
NautilusFile *file;
GnomeVFSFilePermissions permissions;
file = l->data;
if (!both_folder_and_dir &&
((nautilus_file_is_directory (file) && !is_folder) ||
(!nautilus_file_is_directory (file) && is_folder))) {
continue;
}
permissions = GPOINTER_TO_INT (g_hash_table_lookup (window->details->initial_permissions,
file));
if (first) {
if ((permissions & mask) != mask &&
(permissions & mask) != 0) {
/* Not fully on or off -> inconsistent */
return FALSE;
}
first_permissions = permissions;
first = FALSE;
} else if ((permissions & mask) != first_permissions) {
/* Not same permissions as first -> inconsistent */
return FALSE;
}
}
return TRUE;
}
static void
permission_button_toggled (GtkToggleButton *button,
FMPropertiesWindow *window)
{
gboolean is_folder, is_special;
GnomeVFSFilePermissions permission_mask;
gboolean inconsistent;
gboolean on;
permission_mask = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (button),
"permission"));
is_folder = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (button),
"is-folder"));
is_special = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (button),
"is-special"));
if (gtk_toggle_button_get_active (button)
&& !gtk_toggle_button_get_inconsistent (button)) {
/* Go to the initial state unless the initial state was
consistent, or we support recursive apply */
inconsistent = TRUE;
on = TRUE;
if (!window->details->has_recursive_apply &&
initial_permission_state_consistent (window, permission_mask, is_folder, is_special)) {
inconsistent = FALSE;
on = TRUE;
}
} else if (gtk_toggle_button_get_inconsistent (button)
&& !gtk_toggle_button_get_active (button)) {
inconsistent = FALSE;
on = TRUE;
} else {
inconsistent = FALSE;
on = FALSE;
}
g_signal_handlers_block_by_func (G_OBJECT (button),
G_CALLBACK (permission_button_toggled),
window);
gtk_toggle_button_set_active (button, on);
gtk_toggle_button_set_inconsistent (button, inconsistent);
g_signal_handlers_unblock_by_func (G_OBJECT (button),
G_CALLBACK (permission_button_toggled),
window);
update_permissions (window,
on?permission_mask:0,
permission_mask,
is_folder,
is_special,
inconsistent);
}
static void
permission_button_update (FMPropertiesWindow *window,
GtkToggleButton *button)
{
GList *l;
gboolean all_set;
gboolean all_unset;
gboolean all_cannot_set;
gboolean is_folder, is_special;
gboolean no_match;
gboolean sensitive;
GnomeVFSFilePermissions button_permission;
if (gtk_toggle_button_get_inconsistent (button) &&
window->details->has_recursive_apply) {
/* Never change from an inconsistent state if we have dirs, even
* if the current state is now consistent, because its a useful
* state for recursive apply.
*/
return;
}
button_permission = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (button),
"permission"));
is_folder = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (button),
"is-folder"));
is_special = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (button),
"is-special"));
all_set = TRUE;
all_unset = TRUE;
all_cannot_set = TRUE;
no_match = TRUE;
for (l = window->details->target_files; l != NULL; l = l->next) {
NautilusFile *file;
GnomeVFSFilePermissions file_permissions;
file = NAUTILUS_FILE (l->data);
if (!nautilus_file_can_get_permissions (file)) {
continue;
}
if (!is_special &&
((nautilus_file_is_directory (file) && !is_folder) ||
(!nautilus_file_is_directory (file) && is_folder))) {
continue;
}
no_match = FALSE;
file_permissions = nautilus_file_get_permissions (file);
if ((file_permissions & button_permission) == button_permission) {
all_unset = FALSE;
} else if ((file_permissions & button_permission) == 0) {
all_set = FALSE;
} else {
all_unset = FALSE;
all_set = FALSE;
}
if (nautilus_file_can_set_permissions (file)) {
all_cannot_set = FALSE;
}
}
sensitive = !all_cannot_set;
if (!is_folder) {
/* Don't insitive files when we have recursive apply */
sensitive |= window->details->has_recursive_apply;
}
g_signal_handlers_block_by_func (G_OBJECT (button),
G_CALLBACK (permission_button_toggled),
window);
gtk_toggle_button_set_active (button, !all_unset);
/* if actually inconsistent, or default value for file buttons
if no files are selected. (useful for recursive apply) */
gtk_toggle_button_set_inconsistent (button,
(!all_unset && !all_set) ||
(!is_folder && no_match));
gtk_widget_set_sensitive (GTK_WIDGET (button), sensitive);
g_signal_handlers_unblock_by_func (G_OBJECT (button),
G_CALLBACK (permission_button_toggled),
window);
}
static void
set_up_permissions_checkbox (FMPropertiesWindow *window,
GtkWidget *check_button,
GnomeVFSFilePermissions permission,
gboolean is_folder)
{
/* Load up the check_button with data we'll need when updating its state. */
g_object_set_data (G_OBJECT (check_button), "permission",
GINT_TO_POINTER (permission));
g_object_set_data (G_OBJECT (check_button), "properties_window",
window);
g_object_set_data (G_OBJECT (check_button), "is-folder",
GINT_TO_POINTER (is_folder));
window->details->permission_buttons =
g_list_prepend (window->details->permission_buttons,
check_button);
g_signal_connect_object (check_button, "toggled",
G_CALLBACK (permission_button_toggled),
window,
0);
}
static void
add_permissions_checkbox_with_label (FMPropertiesWindow *window,
GtkTable *table,
int row, int column,
const char *label,
GnomeVFSFilePermissions permission_to_check,
GtkLabel *label_for,
gboolean is_folder)
{
GtkWidget *check_button;
gboolean a11y_enabled;
check_button = gtk_check_button_new_with_mnemonic (label);
gtk_widget_show (check_button);
gtk_table_attach (table, check_button,
column, column + 1,
row, row + 1,
GTK_FILL, 0,
0, 0);
set_up_permissions_checkbox (window,
check_button,
permission_to_check,
is_folder);
a11y_enabled = GTK_IS_ACCESSIBLE (gtk_widget_get_accessible (check_button));
if (a11y_enabled && label_for != NULL) {
eel_accessibility_set_up_label_widget_relation (GTK_WIDGET (label_for),
check_button);
}
}
static void
add_permissions_checkbox (FMPropertiesWindow *window,
GtkTable *table,
int row, int column,
GnomeVFSFilePermissions permission_to_check,
GtkLabel *label_for,
gboolean is_folder)
{
gchar *label;
if (column == PERMISSIONS_CHECKBOXES_READ_COLUMN) {
label = _("_Read");
} else if (column == PERMISSIONS_CHECKBOXES_WRITE_COLUMN) {
label = _("_Write");
} else {
label = _("E_xecute");
}
add_permissions_checkbox_with_label (window, table,
row, column,
label,
permission_to_check,
label_for,
is_folder);
}
typedef enum {
PERMISSION_READ = (1<<0),
PERMISSION_WRITE = (1<<1),
PERMISSION_EXEC = (1<<2)
} PermissionValue;
typedef enum {
PERMISSION_USER,
PERMISSION_GROUP,
PERMISSION_OTHER
} PermissionType;
static GnomeVFSFilePermissions vfs_perms[3][3] = {
{GNOME_VFS_PERM_USER_READ, GNOME_VFS_PERM_USER_WRITE, GNOME_VFS_PERM_USER_EXEC},
{GNOME_VFS_PERM_GROUP_READ, GNOME_VFS_PERM_GROUP_WRITE, GNOME_VFS_PERM_GROUP_EXEC},
{GNOME_VFS_PERM_OTHER_READ, GNOME_VFS_PERM_OTHER_WRITE, GNOME_VFS_PERM_OTHER_EXEC},
};
static GnomeVFSFilePermissions
permission_to_vfs (PermissionType type, PermissionValue perm)
{
GnomeVFSFilePermissions vfs_perm;
g_assert (type >= 0 && type < 3);
vfs_perm = 0;
if (perm & PERMISSION_READ) {
vfs_perm |= vfs_perms[type][0];
}
if (perm & PERMISSION_WRITE) {
vfs_perm |= vfs_perms[type][1];
}
if (perm & PERMISSION_EXEC) {
vfs_perm |= vfs_perms[type][2];
}
return vfs_perm;
}
static PermissionValue
permission_from_vfs (PermissionType type, GnomeVFSFilePermissions vfs_perm)
{
PermissionValue perm;
g_assert (type >= 0 && type < 3);
perm = 0;
if (vfs_perm & vfs_perms[type][0]) {
perm |= PERMISSION_READ;
}
if (vfs_perm & vfs_perms[type][1]) {
perm |= PERMISSION_WRITE;
}
if (vfs_perm & vfs_perms[type][2]) {
perm |= PERMISSION_EXEC;
}
return perm;
}
static void
permission_combo_changed (GtkWidget *combo, FMPropertiesWindow *window)
{
GtkTreeIter iter;
GtkTreeModel *model;
gboolean is_folder, use_original;
PermissionType type;
int new_perm, mask;
GnomeVFSFilePermissions vfs_new_perm, vfs_mask;
is_folder = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (combo), "is-folder"));
type = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (combo), "permission-type"));
if (is_folder) {
mask = PERMISSION_READ|PERMISSION_WRITE|PERMISSION_EXEC;
} else {
mask = PERMISSION_READ|PERMISSION_WRITE;
}
vfs_mask = permission_to_vfs (type, mask);
model = gtk_combo_box_get_model (GTK_COMBO_BOX (combo));
if (!gtk_combo_box_get_active_iter (GTK_COMBO_BOX (combo), &iter)) {
return;
}
gtk_tree_model_get (model, &iter, 1, &new_perm, 2, &use_original, -1);
vfs_new_perm = permission_to_vfs (type, new_perm);
update_permissions (window, vfs_new_perm, vfs_mask,
is_folder, FALSE, use_original);
}
static void
permission_combo_add_multiple_choice (GtkComboBox *combo, GtkTreeIter *iter)
{
GtkTreeModel *model;
GtkListStore *store;
gboolean found;
model = gtk_combo_box_get_model (combo);
store = GTK_LIST_STORE (model);
found = FALSE;
gtk_tree_model_get_iter_first (model, iter);
do {
gboolean multi;
gtk_tree_model_get (model, iter, 2, &multi, -1);
if (multi) {
found = TRUE;
break;
}
} while (gtk_tree_model_iter_next (model, iter));
if (!found) {
gtk_list_store_append (store, iter);
gtk_list_store_set (store, iter, 0, "---", 1, 0, 2, TRUE, -1);
}
}
static void
permission_combo_update (FMPropertiesWindow *window,
GtkComboBox *combo)
{
PermissionType type;
PermissionValue perm, all_dir_perm, all_file_perm, all_perm;
gboolean is_folder, no_files, no_dirs, all_file_same, all_dir_same, all_same;
gboolean all_dir_cannot_set, all_file_cannot_set, sensitive;
GtkTreeIter iter;
int mask;
GtkTreeModel *model;
GtkListStore *store;
GList *l;
gboolean is_multi;
model = gtk_combo_box_get_model (combo);
is_folder = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (combo), "is-folder"));
type = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (combo), "permission-type"));
is_multi = FALSE;
if (gtk_combo_box_get_active_iter (GTK_COMBO_BOX (combo), &iter)) {
gtk_tree_model_get (model, &iter, 2, &is_multi, -1);
}
if (is_multi && window->details->has_recursive_apply) {
/* Never change from an inconsistent state if we have dirs, even
* if the current state is now consistent, because its a useful
* state for recursive apply.
*/
return;
}
no_files = TRUE;
no_dirs = TRUE;
all_dir_same = TRUE;
all_file_same = TRUE;
all_dir_perm = 0;
all_file_perm = 0;
all_dir_cannot_set = TRUE;
all_file_cannot_set = TRUE;
for (l = window->details->target_files; l != NULL; l = l->next) {
NautilusFile *file;
GnomeVFSFilePermissions file_permissions;
file = NAUTILUS_FILE (l->data);
if (!nautilus_file_can_get_permissions (file)) {
continue;
}
if (nautilus_file_is_directory (file)) {
mask = PERMISSION_READ|PERMISSION_WRITE|PERMISSION_EXEC;
} else {
mask = PERMISSION_READ|PERMISSION_WRITE;
}
file_permissions = nautilus_file_get_permissions (file);
perm = permission_from_vfs (type, file_permissions) & mask;
if (nautilus_file_is_directory (file)) {
if (no_dirs) {
all_dir_perm = perm;
no_dirs = FALSE;
} else if (perm != all_dir_perm) {
all_dir_same = FALSE;
}
if (nautilus_file_can_set_permissions (file)) {
all_dir_cannot_set = FALSE;
}
} else {
if (no_files) {
all_file_perm = perm;
no_files = FALSE;
} else if (perm != all_file_perm) {
all_file_same = FALSE;
}
if (nautilus_file_can_set_permissions (file)) {
all_file_cannot_set = FALSE;
}
}
}
if (is_folder) {
all_same = all_dir_same;
all_perm = all_dir_perm;
} else {
all_same = all_file_same && !no_files;
all_perm = all_file_perm;
}
store = GTK_LIST_STORE (model);
if (all_same) {
gboolean found;
found = FALSE;
gtk_tree_model_get_iter_first (model, &iter);
do {
int current_perm;
gtk_tree_model_get (model, &iter, 1, ¤t_perm, -1);
if (current_perm == all_perm) {
found = TRUE;
break;
}
} while (gtk_tree_model_iter_next (model, &iter));
if (!found) {
GString *str;
str = g_string_new ("");
if (!(all_perm & PERMISSION_READ)) {
g_string_append (str, _("no "));
}
if (is_folder) {
g_string_append (str, _("list"));
} else {
g_string_append (str, _("read"));
}
g_string_append (str, ", ");
if (!(all_perm & PERMISSION_WRITE)) {
g_string_append (str, _("no "));
}
if (is_folder) {
g_string_append (str, _("create/delete"));
} else {
g_string_append (str, _("write"));
}
if (is_folder) {
g_string_append (str, ", ");
if (!(all_perm & PERMISSION_EXEC)) {
g_string_append (str, _("no "));
}
g_string_append (str, _("access"));
}
gtk_list_store_append (store, &iter);
gtk_list_store_set (store, &iter,
0, str->str,
1, all_perm, -1);
g_string_free (str, TRUE);
}
} else {
permission_combo_add_multiple_choice (combo, &iter);
}
g_signal_handlers_block_by_func (G_OBJECT (combo),
G_CALLBACK (permission_combo_changed),
window);
gtk_combo_box_set_active_iter (combo, &iter);
/* Also enable if no files found (for recursive
file changes when only selecting folders) */
if (is_folder) {
sensitive = !all_dir_cannot_set;
} else {
sensitive = !all_file_cannot_set ||
window->details->has_recursive_apply;
}
gtk_widget_set_sensitive (GTK_WIDGET (combo), sensitive);
g_signal_handlers_unblock_by_func (G_OBJECT (combo),
G_CALLBACK (permission_combo_changed),
window);
}
static void
add_permissions_combo_box (FMPropertiesWindow *window, GtkTable *table,
PermissionType type, gboolean is_folder,
gboolean short_label)
{
GtkWidget *combo;
GtkListStore *store;
GtkCellRenderer *cell;
GtkTreeIter iter;
int row;
if (short_label) {
row = append_title_field (table, _("Access:"), NULL);
} else if (is_folder) {
row = append_title_field (table, _("Folder Access:"), NULL);
} else {
row = append_title_field (table, _("File Access:"), NULL);
}
store = gtk_list_store_new (3, G_TYPE_STRING, G_TYPE_INT, G_TYPE_BOOLEAN);
combo = gtk_combo_box_new_with_model (GTK_TREE_MODEL (store));
g_object_set_data (G_OBJECT (combo), "is-folder", GINT_TO_POINTER (is_folder));
g_object_set_data (G_OBJECT (combo), "permission-type", GINT_TO_POINTER (type));
if (is_folder) {
if (type != PERMISSION_USER) {
gtk_list_store_append (store, &iter);
gtk_list_store_set (store, &iter, 0, _("None"), 1, 0, -1);
}
gtk_list_store_append (store, &iter);
gtk_list_store_set (store, &iter, 0, _("List files only"), 1, PERMISSION_READ, -1);
gtk_list_store_append (store, &iter);
gtk_list_store_set (store, &iter, 0, _("Access files"), 1, PERMISSION_READ|PERMISSION_EXEC, -1);
gtk_list_store_append (store, &iter);
gtk_list_store_set (store, &iter, 0, _("Create and delete files"), 1, PERMISSION_READ|PERMISSION_EXEC|PERMISSION_WRITE, -1);
} else {
if (type != PERMISSION_USER) {
gtk_list_store_append (store, &iter);
gtk_list_store_set (store, &iter, 0, _("None"), 1, 0, -1);
}
gtk_list_store_append (store, &iter);
gtk_list_store_set (store, &iter, 0, _("Read-only"), 1, PERMISSION_READ, -1);
gtk_list_store_append (store, &iter);
gtk_list_store_set (store, &iter, 0, _("Read and write"), 1, PERMISSION_READ|PERMISSION_WRITE, -1);
}
if (window->details->has_recursive_apply) {
permission_combo_add_multiple_choice (GTK_COMBO_BOX (combo), &iter);
}
g_object_unref (store);
window->details->permission_combos =
g_list_prepend (window->details->permission_combos,
combo);
g_signal_connect (combo, "changed", G_CALLBACK (permission_combo_changed), window);
cell = gtk_cell_renderer_text_new ();
gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (combo), cell, TRUE);
gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (combo), cell,
"text", 0,
NULL);
gtk_widget_show (combo);
gtk_table_attach (table, combo,
VALUE_COLUMN, VALUE_COLUMN + 1,
row, row + 1,
GTK_FILL, 0,
0, 0);
}
static GtkWidget *
append_special_execution_checkbox (FMPropertiesWindow *window,
GtkTable *table,
const char *label_text,
GnomeVFSFilePermissions permission_to_check)
{
GtkWidget *check_button;
guint last_row;
last_row = append_row (table);
check_button = gtk_check_button_new_with_mnemonic (label_text);
gtk_widget_show (check_button);
gtk_table_attach (table, check_button,
VALUE_COLUMN, VALUE_COLUMN + 1,
last_row, last_row + 1,
GTK_FILL, 0,
0, 0);
set_up_permissions_checkbox (window,
check_button,
permission_to_check,
FALSE);
g_object_set_data (G_OBJECT (check_button), "is-special",
GINT_TO_POINTER (TRUE));
return check_button;
}
static void
append_special_execution_flags (FMPropertiesWindow *window, GtkTable *table)
{
append_special_execution_checkbox
(window, table, _("Set _user ID"), GNOME_VFS_PERM_SUID);
attach_title_field (table, table->nrows - 1, _("Special flags:"));
append_special_execution_checkbox (window, table, _("Set gro_up ID"), GNOME_VFS_PERM_SGID);
append_special_execution_checkbox (window, table, _("_Sticky"), GNOME_VFS_PERM_STICKY);
gtk_table_set_row_spacing (table, table->nrows - 1, 18);
}
static gboolean
all_can_get_permissions (GList *file_list)
{
GList *l;
for (l = file_list; l != NULL; l = l->next) {
NautilusFile *file;
file = NAUTILUS_FILE (l->data);
if (!nautilus_file_can_get_permissions (file)) {
return FALSE;
}
}
return TRUE;
}
static gboolean
all_can_set_permissions (GList *file_list)
{
GList *l;
for (l = file_list; l != NULL; l = l->next) {
NautilusFile *file;
file = NAUTILUS_FILE (l->data);
if (!nautilus_file_can_set_permissions (file)) {
return FALSE;
}
}
return TRUE;
}
static GHashTable *
get_initial_permissions (GList *file_list)
{
GHashTable *ret;
GList *l;
ret = g_hash_table_new (g_direct_hash,
g_direct_equal);
for (l = file_list; l != NULL; l = l->next) {
GnomeVFSFilePermissions permissions;
NautilusFile *file;
file = NAUTILUS_FILE (l->data);
permissions = nautilus_file_get_permissions (file);
g_hash_table_insert (ret, file,
GINT_TO_POINTER (permissions));
}
return ret;
}
static void
create_simple_permissions (FMPropertiesWindow *window, GtkTable *page_table)
{
gboolean has_file, has_directory;
GtkLabel *group_label;
GtkLabel *owner_label;
GtkComboBox *group_combo_box;
GtkComboBox *owner_combo_box;
guint last_row;
last_row = 0;
has_file = files_has_file (window);
has_directory = files_has_directory (window);
if (!is_multi_file_window (window) && nautilus_file_can_set_owner (get_target_file (window))) {
owner_label = attach_title_field (page_table, last_row, _("_Owner:"));
/* Combo box in this case. */
owner_combo_box = attach_owner_combo_box (page_table, last_row, get_target_file (window));
gtk_label_set_mnemonic_widget (owner_label,
GTK_WIDGET (owner_combo_box));
} else {
attach_title_field (page_table, last_row, _("Owner:"));
/* Static text in this case. */
attach_value_field (window,
page_table, last_row, VALUE_COLUMN,
"owner",
_("--"),
FALSE);
}
if (has_directory) {
add_permissions_combo_box (window, page_table,
PERMISSION_USER, TRUE, FALSE);
}
if (has_file || window->details->has_recursive_apply) {
add_permissions_combo_box (window, page_table,
PERMISSION_USER, FALSE, !has_directory);
}
gtk_table_set_row_spacing (page_table, page_table->nrows - 1, 18);
if (!is_multi_file_window (window) && nautilus_file_can_set_group (get_target_file (window))) {
last_row = append_title_field (page_table,
_("_Group:"),
&group_label);
/* Combo box in this case. */
group_combo_box = attach_group_combo_box (page_table, last_row,
get_target_file (window));
gtk_label_set_mnemonic_widget (group_label,
GTK_WIDGET (group_combo_box));
} else {
last_row = append_title_field (page_table,
_("Group:"),
NULL);
/* Static text in this case. */
attach_value_field (window, page_table, last_row,
VALUE_COLUMN,
"group",
_("--"),
FALSE);
}
if (has_directory) {
add_permissions_combo_box (window, page_table,
PERMISSION_GROUP, TRUE,
FALSE);
}
if (has_file || window->details->has_recursive_apply) {
add_permissions_combo_box (window, page_table,
PERMISSION_GROUP, FALSE,
!has_directory);
}
gtk_table_set_row_spacing (page_table, page_table->nrows - 1, 18);
append_title_field (page_table,
_("Others"),
&group_label);
if (has_directory) {
add_permissions_combo_box (window, page_table,
PERMISSION_OTHER, TRUE,
FALSE);
}
if (has_file || window->details->has_recursive_apply) {
add_permissions_combo_box (window, page_table,
PERMISSION_OTHER, FALSE,
!has_directory);
}
gtk_table_set_row_spacing (page_table, page_table->nrows - 1, 18);
last_row = append_title_field (page_table,
_("Execute:"),
NULL);
add_permissions_checkbox_with_label (window, page_table,
last_row, 1,
_("Allow _executing file as program"),
GNOME_VFS_PERM_USER_EXEC|GNOME_VFS_PERM_GROUP_EXEC|GNOME_VFS_PERM_OTHER_EXEC,
NULL, FALSE);
}
static void
create_permission_checkboxes (FMPropertiesWindow *window,
GtkTable *page_table,
gboolean is_folder)
{
guint checkbox_titles_row;
GtkLabel *owner_perm_label;
GtkLabel *group_perm_label;
GtkLabel *other_perm_label;
GtkTable *check_button_table;
checkbox_titles_row = append_title_field (page_table, _("Owner:"), &owner_perm_label);
append_title_field (page_table, _("Group:"), &group_perm_label);
append_title_field (page_table, _("Others:"), &other_perm_label);
check_button_table = GTK_TABLE (gtk_table_new
(PERMISSIONS_CHECKBOXES_ROW_COUNT,
PERMISSIONS_CHECKBOXES_COLUMN_COUNT,
FALSE));
apply_standard_table_padding (check_button_table);
gtk_widget_show (GTK_WIDGET (check_button_table));
gtk_table_attach (page_table, GTK_WIDGET (check_button_table),
VALUE_COLUMN, VALUE_COLUMN + 1,
checkbox_titles_row, checkbox_titles_row + PERMISSIONS_CHECKBOXES_ROW_COUNT,
0, 0,
0, 0);
add_permissions_checkbox (window,
check_button_table,
PERMISSIONS_CHECKBOXES_OWNER_ROW,
PERMISSIONS_CHECKBOXES_READ_COLUMN,
GNOME_VFS_PERM_USER_READ,
owner_perm_label,
is_folder);
add_permissions_checkbox (window,
check_button_table,
PERMISSIONS_CHECKBOXES_OWNER_ROW,
PERMISSIONS_CHECKBOXES_WRITE_COLUMN,
GNOME_VFS_PERM_USER_WRITE,
owner_perm_label,
is_folder);
add_permissions_checkbox (window,
check_button_table,
PERMISSIONS_CHECKBOXES_OWNER_ROW,
PERMISSIONS_CHECKBOXES_EXECUTE_COLUMN,
GNOME_VFS_PERM_USER_EXEC,
owner_perm_label,
is_folder);
add_permissions_checkbox (window,
check_button_table,
PERMISSIONS_CHECKBOXES_GROUP_ROW,
PERMISSIONS_CHECKBOXES_READ_COLUMN,
GNOME_VFS_PERM_GROUP_READ,
group_perm_label,
is_folder);
add_permissions_checkbox (window,
check_button_table,
PERMISSIONS_CHECKBOXES_GROUP_ROW,
PERMISSIONS_CHECKBOXES_WRITE_COLUMN,
GNOME_VFS_PERM_GROUP_WRITE,
group_perm_label,
is_folder);
add_permissions_checkbox (window,
check_button_table,
PERMISSIONS_CHECKBOXES_GROUP_ROW,
PERMISSIONS_CHECKBOXES_EXECUTE_COLUMN,
GNOME_VFS_PERM_GROUP_EXEC,
group_perm_label,
is_folder);
add_permissions_checkbox (window,
check_button_table,
PERMISSIONS_CHECKBOXES_OTHERS_ROW,
PERMISSIONS_CHECKBOXES_READ_COLUMN,
GNOME_VFS_PERM_OTHER_READ,
other_perm_label,
is_folder);
add_permissions_checkbox (window,
check_button_table,
PERMISSIONS_CHECKBOXES_OTHERS_ROW,
PERMISSIONS_CHECKBOXES_WRITE_COLUMN,
GNOME_VFS_PERM_OTHER_WRITE,
other_perm_label,
is_folder);
add_permissions_checkbox (window,
check_button_table,
PERMISSIONS_CHECKBOXES_OTHERS_ROW,
PERMISSIONS_CHECKBOXES_EXECUTE_COLUMN,
GNOME_VFS_PERM_OTHER_EXEC,
other_perm_label,
is_folder);
}
static void
create_advanced_permissions (FMPropertiesWindow *window, GtkTable *page_table)
{
guint last_row;
GtkLabel *group_label;
GtkLabel *owner_label;
GtkComboBox *group_combo_box;
GtkComboBox *owner_combo_box;
gboolean has_directory, has_file;
last_row = 0;
if (!is_multi_file_window (window) && nautilus_file_can_set_owner (get_target_file (window))) {
owner_label = attach_title_field (page_table, last_row, _("_Owner:"));
/* Combo box in this case. */
owner_combo_box = attach_owner_combo_box (page_table, last_row, get_target_file (window));
gtk_label_set_mnemonic_widget (owner_label,
GTK_WIDGET (owner_combo_box));
} else {
attach_title_field (page_table, last_row, _("Owner:"));
/* Static text in this case. */
attach_value_field (window,
page_table, last_row, VALUE_COLUMN,
"owner",
_("--"),
FALSE);
}
if (!is_multi_file_window (window) && nautilus_file_can_set_group (get_target_file (window))) {
last_row = append_title_field (page_table,
_("_Group:"),
&group_label);
/* Combo box in this case. */
group_combo_box = attach_group_combo_box (page_table, last_row,
get_target_file (window));
gtk_label_set_mnemonic_widget (group_label,
GTK_WIDGET (group_combo_box));
} else {
last_row = append_title_field (page_table,
_("Group:"),
NULL);
/* Static text in this case. */
attach_value_field (window, page_table, last_row,
VALUE_COLUMN,
"group",
_("--"),
FALSE);
}
gtk_table_set_row_spacing (page_table, page_table->nrows - 1, 18);
has_directory = files_has_directory (window);
has_file = files_has_file (window);
if (has_directory) {
if (has_file || window->details->has_recursive_apply) {
append_title_field (page_table,
_("Folder Permissions:"),
NULL);
}
create_permission_checkboxes (window, page_table, TRUE);
gtk_table_set_row_spacing (page_table, page_table->nrows - 1, 18);
}
if (has_file || window->details->has_recursive_apply) {
if (has_directory) {
append_title_field (page_table,
_("File Permissions:"),
NULL);
}
create_permission_checkboxes (window, page_table, FALSE);
gtk_table_set_row_spacing (page_table, page_table->nrows - 1, 18);
}
append_special_execution_flags (window, page_table);
append_title_value_pair
(window, page_table, _("Text view:"),
"permissions", _("--"),
FALSE);
}
static void
set_recursive_permissions_done (gpointer callback_data)
{
FMPropertiesWindow *window;
window = FM_PROPERTIES_WINDOW (callback_data);
end_long_operation (window);
g_object_unref (window);
}
static void
apply_recursive_clicked (GtkWidget *recursive_button,
FMPropertiesWindow *window)
{
GnomeVFSFilePermissions file_permission, file_permission_mask;
GnomeVFSFilePermissions dir_permission, dir_permission_mask;
GnomeVFSFilePermissions vfs_mask, vfs_new_perm, p;
GtkWidget *button, *combo;
gboolean active, is_folder, is_special, use_original;
GList *l;
GtkTreeModel *model;
GtkTreeIter iter;
PermissionType type;
int new_perm, mask;
file_permission = 0;
file_permission_mask = 0;
dir_permission = 0;
dir_permission_mask = 0;
/* Advanced mode and execute checkbox: */
for (l = window->details->permission_buttons; l != NULL; l = l->next) {
button = l->data;
if (gtk_toggle_button_get_inconsistent (GTK_TOGGLE_BUTTON (button))) {
continue;
}
active = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button));
p = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (button),
"permission"));
is_folder = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (button),
"is-folder"));
is_special = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (button),
"is-special"));
if (is_folder || is_special) {
dir_permission_mask |= p;
if (active) {
dir_permission |= p;
}
}
if (!is_folder || is_special) {
file_permission_mask |= p;
if (active) {
file_permission |= p;
}
}
}
/* Simple mode, minus exec checkbox */
for (l = window->details->permission_combos; l != NULL; l = l->next) {
combo = l->data;
if (!gtk_combo_box_get_active_iter (GTK_COMBO_BOX (combo), &iter)) {
continue;
}
type = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (combo), "permission-type"));
is_folder = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (combo),
"is-folder"));
model = gtk_combo_box_get_model (GTK_COMBO_BOX (combo));
gtk_tree_model_get (model, &iter, 1, &new_perm, 2, &use_original, -1);
if (use_original) {
continue;
}
vfs_new_perm = permission_to_vfs (type, new_perm);
if (is_folder) {
mask = PERMISSION_READ|PERMISSION_WRITE|PERMISSION_EXEC;
} else {
mask = PERMISSION_READ|PERMISSION_WRITE;
}
vfs_mask = permission_to_vfs (type, mask);
if (is_folder) {
dir_permission_mask |= vfs_mask;
dir_permission |= vfs_new_perm;
} else {
file_permission_mask |= vfs_mask;
file_permission |= vfs_new_perm;
}
}
for (l = window->details->target_files; l != NULL; l = l->next) {
NautilusFile *file;
char *uri;
file = NAUTILUS_FILE (l->data);
if (nautilus_file_is_directory (file) &&
nautilus_file_can_set_permissions (file)) {
uri = nautilus_file_get_uri (file);
start_long_operation (window);
g_object_ref (window);
nautilus_file_set_permissions_recursive (uri,
file_permission,
file_permission_mask,
dir_permission,
dir_permission_mask,
set_recursive_permissions_done,
window);
g_free (uri);
}
}
}
static void
create_permissions_page (FMPropertiesWindow *window)
{
GtkWidget *vbox, *button, *hbox;
GtkTable *page_table;
char *file_name, *prompt_text;
GList *file_list;
guint last_row;
vbox = create_page_with_vbox (window->details->notebook,
_("Permissions"));
file_list = window->details->original_files;
window->details->initial_permissions = NULL;
if (all_can_get_permissions (file_list) && all_can_get_permissions (window->details->target_files)) {
window->details->initial_permissions = get_initial_permissions (window->details->target_files);
window->details->has_recursive_apply = files_has_changable_permissions_directory (window);
if (!all_can_set_permissions (file_list)) {
add_prompt_and_separator (
GTK_VBOX (vbox),
_("You are not the owner, so you can't change these permissions."));
}
page_table = GTK_TABLE (gtk_table_new (1, COLUMN_COUNT, FALSE));
window->details->permissions_table = page_table;
apply_standard_table_padding (page_table);
gtk_widget_show (GTK_WIDGET (page_table));
gtk_box_pack_start (GTK_BOX (vbox),
GTK_WIDGET (page_table),
TRUE, TRUE, 0);
if (eel_preferences_get_boolean (NAUTILUS_PREFERENCES_SHOW_ADVANCED_PERMISSIONS)) {
window->details->advanced_permissions = TRUE;
create_advanced_permissions (window, page_table);
} else {
window->details->advanced_permissions = FALSE;
create_simple_permissions (window, page_table);
}
gtk_table_set_row_spacing (page_table, page_table->nrows - 1, 18);
append_title_value_pair
(window, page_table, _("Last changed:"),
"date_permissions", _("--"),
FALSE);
if (window->details->has_recursive_apply) {
last_row = append_row (page_table);
hbox = gtk_hbox_new (FALSE, 0);
gtk_widget_show (hbox);
gtk_table_attach (page_table, hbox,
0, 2,
last_row, last_row+1,
GTK_FILL, 0,
0, 0);
button = gtk_button_new_with_mnemonic (_("Apply permissions to enclosed files"));
gtk_widget_show (button);
gtk_box_pack_start (GTK_BOX (hbox), button, FALSE, FALSE, 0);
g_signal_connect (button, "clicked",
G_CALLBACK (apply_recursive_clicked),
window);
}
} else {
if (!is_multi_file_window (window)) {
file_name = nautilus_file_get_display_name (get_target_file (window));
prompt_text = g_strdup_printf (_("The permissions of \"%s\" could not be determined."), file_name);
g_free (file_name);
} else {
prompt_text = g_strdup (_("The permissions of the selected file could not be determined."));
}
add_prompt (GTK_VBOX (vbox), prompt_text, TRUE);
g_free (prompt_text);
}
}
static void
append_extension_pages (FMPropertiesWindow *window)
{
GList *providers;
GList *p;
providers = nautilus_module_get_extensions_for_type (NAUTILUS_TYPE_PROPERTY_PAGE_PROVIDER);
for (p = providers; p != NULL; p = p->next) {
NautilusPropertyPageProvider *provider;
GList *pages;
GList *l;
provider = NAUTILUS_PROPERTY_PAGE_PROVIDER (p->data);
pages = nautilus_property_page_provider_get_pages
(provider, window->details->original_files);
for (l = pages; l != NULL; l = l->next) {
NautilusPropertyPage *page;
GtkWidget *page_widget;
GtkWidget *label;
page = NAUTILUS_PROPERTY_PAGE (l->data);
g_object_get (G_OBJECT (page),
"page", &page_widget, "label", &label,
NULL);
gtk_notebook_append_page (window->details->notebook,
page_widget, label);
g_object_set_data (G_OBJECT (page_widget),
"is-extension-page",
page);
gtk_widget_unref (page_widget);
gtk_widget_unref (label);
g_object_unref (page);
}
g_list_free (pages);
}
nautilus_module_extension_list_free (providers);
}
static gboolean
should_show_emblems (FMPropertiesWindow *window)
{
/* FIXME bugzilla.gnome.org 45643:
* Emblems aren't displayed on the the desktop Trash icon, so
* we shouldn't pretend that they work by showing them here.
* When bug 5643 is fixed we can remove this case.
*/
if (!is_multi_file_window (window)
&& is_merged_trash_directory (get_target_file (window))) {
return FALSE;
}
return TRUE;
}
static gboolean
should_show_permissions (FMPropertiesWindow *window)
{
/* Don't show permissions for the Trash since it's not
* really a file system object.
*/
if (!is_multi_file_window (window)
&& is_merged_trash_directory (get_target_file (window))) {
return FALSE;
}
return TRUE;
}
static char *
get_pending_key (GList *file_list)
{
GList *l;
GList *uris;
GString *key;
char *ret;
uris = NULL;
for (l = file_list; l != NULL; l = l->next) {
uris = g_list_prepend (uris, nautilus_file_get_uri (NAUTILUS_FILE (l->data)));
}
uris = g_list_sort (uris, (GCompareFunc)strcmp);
key = g_string_new ("");
for (l = uris; l != NULL; l = l->next) {
g_string_append (key, l->data);
g_string_append (key, ";");
}
eel_g_list_free_deep (uris);
ret = key->str;
g_string_free (key, FALSE);
return ret;
}
static StartupData *
startup_data_new (GList *original_files,
GList *target_files,
const char *pending_key,
GtkWidget *parent_widget)
{
StartupData *data;
GList *l;
data = g_new0 (StartupData, 1);
data->original_files = nautilus_file_list_copy (original_files);
data->target_files = nautilus_file_list_copy (target_files);
data->parent_widget = parent_widget;
data->pending_key = g_strdup (pending_key);
data->pending_files = g_hash_table_new (g_direct_hash,
g_direct_equal);
for (l = data->target_files; l != NULL; l = l->next) {
g_hash_table_insert (data->pending_files, l->data, l->data);
}
return data;
}
static void
startup_data_free (StartupData *data)
{
nautilus_file_list_free (data->original_files);
nautilus_file_list_free (data->target_files);
g_hash_table_destroy (data->pending_files);
g_free (data->pending_key);
g_free (data);
}
static void
help_button_callback (GtkWidget *widget, GtkWidget *property_window)
{
GError *error = NULL;
gnome_help_display_desktop_on_screen (NULL, "user-guide", "user-guide.xml", "gosnautilus-51",
gtk_window_get_screen (GTK_WINDOW (property_window)),
&error);
if (error) {
eel_show_error_dialog (_("There was an error displaying help."), error->message,
GTK_WINDOW (property_window));
g_error_free (error);
}
}
static void
file_changed_callback (NautilusFile *file, gpointer user_data)
{
FMPropertiesWindow *window = FM_PROPERTIES_WINDOW (user_data);
if (!g_list_find (window->details->changed_files, file)) {
nautilus_file_ref (file);
window->details->changed_files = g_list_prepend (window->details->changed_files, file);
schedule_files_update (window);
}
}
static gboolean
should_show_open_with (FMPropertiesWindow *window)
{
NautilusFile *file;
if (is_multi_file_window (window)) {
return FALSE;
}
/* Don't show open with tab for desktop special icons (trash, etc)
* or desktop files. We don't get the open-with menu for these anyway.
*/
file = get_original_file (window);
if (file == NULL ||
NAUTILUS_IS_DESKTOP_ICON_FILE (file) ||
nautilus_file_is_nautilus_link (file)) {
return FALSE;
}
return TRUE;
}
static void
create_open_with_page (FMPropertiesWindow *window)
{
GtkWidget *vbox;
char *uri;
char *mime_type;
uri = nautilus_file_get_uri (get_target_file (window));
if (uri == NULL) {
return;
}
mime_type = nautilus_file_get_mime_type (get_target_file (window));
vbox = eel_mime_application_chooser_new (uri, mime_type);
gtk_widget_show (vbox);
g_free (uri);
g_free (mime_type);
gtk_notebook_append_page (window->details->notebook,
vbox, gtk_label_new (_("Open With")));
}
static FMPropertiesWindow *
create_properties_window (StartupData *startup_data)
{
FMPropertiesWindow *window;
GtkWidget *vbox;
GtkWidget *hbox;
GtkWidget *button;
GList *l;
window = FM_PROPERTIES_WINDOW (gtk_widget_new (fm_properties_window_get_type (), NULL));
window->details->original_files = nautilus_file_list_copy (startup_data->original_files);
window->details->target_files = nautilus_file_list_copy (startup_data->target_files);
gtk_window_set_wmclass (GTK_WINDOW (window), "file_properties", "Nautilus");
gtk_window_set_screen (GTK_WINDOW (window),
gtk_widget_get_screen (startup_data->parent_widget));
gtk_window_set_type_hint (GTK_WINDOW (window), GDK_WINDOW_TYPE_HINT_DIALOG);
/* Set initial window title */
update_properties_window_title (window);
/* Start monitoring the file attributes we display. Note that some
* of the attributes are for the original file, and some for the
* target files.
*/
for (l = window->details->original_files; l != NULL; l = l->next) {
NautilusFile *file;
NautilusFileAttributes attributes;
file = NAUTILUS_FILE (l->data);
attributes = nautilus_icon_factory_get_required_file_attributes ();
attributes |= NAUTILUS_FILE_ATTRIBUTE_DISPLAY_NAME
| NAUTILUS_FILE_ATTRIBUTE_SLOW_MIME_TYPE;
nautilus_file_monitor_add (NAUTILUS_FILE (l->data),
&window->details->original_files,
attributes);
}
for (l = window->details->target_files; l != NULL; l = l->next) {
NautilusFile *file;
NautilusFileAttributes attributes;
file = NAUTILUS_FILE (l->data);
attributes = 0;
if (nautilus_file_is_directory (file)) {
attributes |= NAUTILUS_FILE_ATTRIBUTE_DEEP_COUNTS;
}
attributes |= NAUTILUS_FILE_ATTRIBUTE_METADATA;
nautilus_file_monitor_add (file, &window->details->target_files, attributes);
}
for (l = window->details->target_files; l != NULL; l = l->next) {
g_signal_connect_object (NAUTILUS_FILE (l->data),
"changed",
G_CALLBACK (file_changed_callback),
G_OBJECT (window),
0);
}
for (l = window->details->original_files; l != NULL; l = l->next) {
g_signal_connect_object (NAUTILUS_FILE (l->data),
"changed",
G_CALLBACK (file_changed_callback),
G_OBJECT (window),
0);
}
/* Create box for notebook and button box. */
vbox = gtk_vbox_new (FALSE, 0);
gtk_container_set_border_width (GTK_CONTAINER (vbox), 5);
gtk_widget_show (vbox);
gtk_container_add (GTK_CONTAINER (window),
GTK_WIDGET (vbox));
/* Create the notebook tabs. */
window->details->notebook = GTK_NOTEBOOK (gtk_notebook_new ());
gtk_widget_show (GTK_WIDGET (window->details->notebook));
gtk_box_pack_start (GTK_BOX (vbox), GTK_WIDGET (window->details->notebook),
TRUE, TRUE, 0);
/* Create the pages. */
create_basic_page (window);
if (should_show_emblems (window)) {
create_emblems_page (window);
}
if (should_show_permissions (window)) {
create_permissions_page (window);
}
if (should_show_open_with (window)) {
create_open_with_page (window);
}
/* append pages from available views */
append_extension_pages (window);
/* Create box for help and close buttons. */
hbox = gtk_hbutton_box_new ();
gtk_widget_show (hbox);
gtk_box_pack_start (GTK_BOX (vbox), GTK_WIDGET (hbox), FALSE, TRUE, 5);
gtk_button_box_set_layout (GTK_BUTTON_BOX (hbox), GTK_BUTTONBOX_EDGE);
button = gtk_button_new_from_stock (GTK_STOCK_HELP);
gtk_widget_show (button);
gtk_box_pack_start (GTK_BOX (hbox), GTK_WIDGET (button),
FALSE, TRUE, 0);
g_signal_connect_object (button, "clicked",
G_CALLBACK (help_button_callback),
window, 0);
button = gtk_button_new_from_stock (GTK_STOCK_CLOSE);
gtk_widget_show (button);
gtk_box_pack_end (GTK_BOX (hbox), GTK_WIDGET (button),
FALSE, TRUE, 0);
g_signal_connect_swapped (button, "clicked",
G_CALLBACK (gtk_widget_destroy),
window);
/* Update from initial state */
properties_window_update (window, NULL);
return window;
}
static GList *
get_target_file_list (GList *original_files)
{
GList *ret;
GList *l;
ret = NULL;
for (l = original_files; l != NULL; l = l->next) {
NautilusFile *target;
target = get_target_file_for_original_file (NAUTILUS_FILE (l->data));
ret = g_list_prepend (ret, target);
}
ret = g_list_reverse (ret);
return ret;
}
static void
add_window (FMPropertiesWindow *window)
{
if (!is_multi_file_window (window)) {
g_hash_table_insert (windows,
get_original_file (window),
window);
g_object_set_data (G_OBJECT (window), "window_key",
get_original_file (window));
}
}
static void
remove_window (FMPropertiesWindow *window)
{
gpointer key;
key = g_object_get_data (G_OBJECT (window), "window_key");
if (key) {
g_hash_table_remove (windows, key);
}
}
static GtkWindow *
get_existing_window (GList *file_list)
{
if (!file_list->next) {
return g_hash_table_lookup (windows, file_list->data);
}
return NULL;
}
static void
cancel_create_properties_window_callback (gpointer callback_data)
{
remove_pending ((StartupData *)callback_data, TRUE, FALSE, TRUE);
}
static void
parent_widget_destroyed_callback (GtkWidget *widget, gpointer callback_data)
{
g_assert (widget == ((StartupData *)callback_data)->parent_widget);
remove_pending ((StartupData *)callback_data, TRUE, TRUE, FALSE);
}
static void
cancel_call_when_ready_callback (gpointer key,
gpointer value,
gpointer user_data)
{
nautilus_file_cancel_call_when_ready
(NAUTILUS_FILE (key),
is_directory_ready_callback,
user_data);
}
static void
remove_pending (StartupData *startup_data,
gboolean cancel_call_when_ready,
gboolean cancel_timed_wait,
gboolean cancel_destroy_handler)
{
if (cancel_call_when_ready) {
g_hash_table_foreach (startup_data->pending_files,
cancel_call_when_ready_callback,
startup_data);
}
if (cancel_timed_wait) {
eel_timed_wait_stop
(cancel_create_properties_window_callback, startup_data);
}
if (cancel_destroy_handler) {
g_signal_handlers_disconnect_by_func (startup_data->parent_widget,
G_CALLBACK (parent_widget_destroyed_callback),
startup_data);
}
g_hash_table_remove (pending_lists, startup_data->pending_key);
startup_data_free (startup_data);
}
static void
is_directory_ready_callback (NautilusFile *file,
gpointer data)
{
StartupData *startup_data;
startup_data = data;
g_hash_table_remove (startup_data->pending_files, file);
if (g_hash_table_size (startup_data->pending_files) == 0) {
FMPropertiesWindow *new_window;
new_window = create_properties_window (startup_data);
add_window (new_window);
remove_pending (startup_data, FALSE, TRUE, TRUE);
/* FIXME bugzilla.gnome.org 42151:
* See comment elsewhere in this file about bug 2151.
*/
#ifdef UNDO_ENABLED
nautilus_undo_share_undo_manager (GTK_OBJECT (new_window),
GTK_OBJECT (callback_data));
#endif
gtk_window_present (GTK_WINDOW (new_window));
}
}
void
fm_properties_window_present (GList *original_files,
GtkWidget *parent_widget)
{
GList *l, *next;
GtkWidget *parent_window;
StartupData *startup_data;
GList *target_files;
GtkWindow *existing_window;
char *pending_key;
g_return_if_fail (original_files != NULL);
g_return_if_fail (GTK_IS_WIDGET (parent_widget));
/* Create the hash tables first time through. */
if (windows == NULL) {
windows = eel_g_hash_table_new_free_at_exit
(NULL, NULL, "property windows");
}
if (pending_lists == NULL) {
pending_lists = eel_g_hash_table_new_free_at_exit
(g_str_hash, g_str_equal, "pending property window files");
}
/* Look to see if there's already a window for this file. */
existing_window = get_existing_window (original_files);
if (existing_window != NULL) {
gtk_window_set_screen (existing_window,
gtk_widget_get_screen (parent_widget));
gtk_window_present (existing_window);
return;
}
pending_key = get_pending_key (original_files);
/* Look to see if we're already waiting for a window for this file. */
if (g_hash_table_lookup (pending_lists, pending_key) != NULL) {
return;
}
target_files = get_target_file_list (original_files);
startup_data = startup_data_new (original_files,
target_files,
pending_key,
parent_widget);
nautilus_file_list_free (target_files);
g_free(pending_key);
/* Wait until we can tell whether it's a directory before showing, since
* some one-time layout decisions depend on that info.
*/
g_hash_table_insert (pending_lists, startup_data->pending_key, startup_data->pending_key);
g_signal_connect (parent_widget, "destroy",
G_CALLBACK (parent_widget_destroyed_callback), startup_data);
parent_window = gtk_widget_get_ancestor (parent_widget, GTK_TYPE_WINDOW);
eel_timed_wait_start
(cancel_create_properties_window_callback,
startup_data,
_("Creating Properties window."),
parent_window == NULL ? NULL : GTK_WINDOW (parent_window));
for (l = startup_data->target_files; l != NULL; l = next) {
next = l->next;
nautilus_file_call_when_ready
(NAUTILUS_FILE (l->data),
NAUTILUS_FILE_ATTRIBUTE_IS_DIRECTORY,
is_directory_ready_callback,
startup_data);
}
}
static void
real_destroy (GtkObject *object)
{
FMPropertiesWindow *window;
GList *l;
window = FM_PROPERTIES_WINDOW (object);
remove_window (window);
for (l = window->details->original_files; l != NULL; l = l->next) {
nautilus_file_monitor_remove (NAUTILUS_FILE (l->data), &window->details->original_files);
}
nautilus_file_list_free (window->details->original_files);
window->details->original_files = NULL;
for (l = window->details->target_files; l != NULL; l = l->next) {
nautilus_file_monitor_remove (NAUTILUS_FILE (l->data), &window->details->target_files);
}
nautilus_file_list_free (window->details->target_files);
window->details->target_files = NULL;
nautilus_file_list_free (window->details->changed_files);
window->details->changed_files = NULL;
window->details->name_field = NULL;
g_list_free (window->details->emblem_buttons);
window->details->emblem_buttons = NULL;
if (window->details->initial_emblems) {
g_hash_table_destroy (window->details->initial_emblems);
window->details->initial_emblems = NULL;
}
g_list_free (window->details->permission_buttons);
window->details->permission_buttons = NULL;
if (window->details->initial_permissions) {
g_hash_table_destroy (window->details->initial_permissions);
window->details->initial_permissions = NULL;
}
g_list_free (window->details->value_fields);
window->details->value_fields = NULL;
if (window->details->update_directory_contents_timeout_id != 0) {
g_source_remove (window->details->update_directory_contents_timeout_id);
window->details->update_directory_contents_timeout_id = 0;
}
if (window->details->update_files_timeout_id != 0) {
g_source_remove (window->details->update_files_timeout_id);
window->details->update_files_timeout_id = 0;
}
GTK_OBJECT_CLASS (parent_class)->destroy (object);
}
static void
real_finalize (GObject *object)
{
FMPropertiesWindow *window;
window = FM_PROPERTIES_WINDOW (object);
eel_g_list_free_deep (window->details->mime_list);
g_free (window->details->pending_name);
g_free (window->details);
G_OBJECT_CLASS (parent_class)->finalize (object);
}
/* converts
* file://foo/foobar/foofoo/bar
* to
* foofoo/bar
* if
* file://foo/foobar
* is the parent
*
* It does not resolve any symlinks.
* */
static char *
make_relative_uri_from_full (const char *uri,
const char *base_uri)
{
g_assert (uri != NULL);
g_assert (base_uri != NULL);
if (g_str_has_prefix (uri, base_uri)) {
uri += strlen (base_uri);
if (*uri != '/') {
return NULL;
}
while (*uri == '/') {
uri++;
}
if (*uri != '\0') {
return g_strdup (uri);
}
}
return NULL;
}
/* icon selection callback to set the image of the file object to the selected file */
static void
set_icon (const char* icon_uri, FMPropertiesWindow *properties_window)
{
NautilusFile *file;
GnomeDesktopItem *ditem;
char *file_uri;
char *icon_path;
char *real_icon_uri;
g_assert (icon_uri != NULL);
g_assert (FM_IS_PROPERTIES_WINDOW (properties_window));
icon_path = gnome_vfs_get_local_path_from_uri (icon_uri);
/* we don't allow remote URIs */
if (icon_path != NULL) {
GList *l;
for (l = properties_window->details->original_files; l != NULL; l = l->next) {
file = NAUTILUS_FILE (l->data);
file_uri = nautilus_file_get_uri (file);
if (nautilus_file_is_mime_type (file, "application/x-desktop")) {
ditem = gnome_desktop_item_new_from_uri (file_uri,
0,
NULL);
if (ditem != NULL) {
gnome_desktop_item_set_string (ditem,
GNOME_DESKTOP_ITEM_ICON,
icon_path);
gnome_desktop_item_save (ditem, NULL, TRUE, NULL);
gnome_desktop_item_unref (ditem);
nautilus_file_invalidate_attributes (file,
NAUTILUS_FILE_ATTRIBUTE_CUSTOM_ICON);
}
} else {
real_icon_uri = make_relative_uri_from_full (icon_uri, file_uri);
if (real_icon_uri == NULL) {
real_icon_uri = g_strdup (icon_uri);
}
nautilus_file_set_metadata (file, NAUTILUS_METADATA_KEY_CUSTOM_ICON, NULL, real_icon_uri);
nautilus_file_set_metadata (file, NAUTILUS_METADATA_KEY_ICON_SCALE, NULL, NULL);
g_free (real_icon_uri);
}
g_free (file_uri);
}
g_free (icon_path);
}
}
static void
update_preview_callback (GtkFileChooser *icon_chooser,
FMPropertiesWindow *window)
{
GtkWidget *preview_widget;
GdkPixbuf *pixbuf, *scaled_pixbuf;
char *filename;
double scale;
pixbuf = NULL;
filename = gtk_file_chooser_get_filename (icon_chooser);
if (filename != NULL) {
pixbuf = gdk_pixbuf_new_from_file (filename, NULL);
}
if (pixbuf != NULL) {
preview_widget = gtk_file_chooser_get_preview_widget (icon_chooser);
gtk_file_chooser_set_preview_widget_active (icon_chooser, TRUE);
if (gdk_pixbuf_get_width (pixbuf) > PREVIEW_IMAGE_WIDTH) {
scale = (double)gdk_pixbuf_get_height (pixbuf) /
gdk_pixbuf_get_width (pixbuf);
scaled_pixbuf = gnome_thumbnail_scale_down_pixbuf
(pixbuf,
PREVIEW_IMAGE_WIDTH,
scale * PREVIEW_IMAGE_WIDTH);
g_object_unref (pixbuf);
pixbuf = scaled_pixbuf;
}
gtk_image_set_from_pixbuf (GTK_IMAGE (preview_widget), pixbuf);
} else {
gtk_file_chooser_set_preview_widget_active (icon_chooser, FALSE);
}
g_free (filename);
if (pixbuf != NULL) {
g_object_unref (pixbuf);
}
}
static void
select_image_button_callback (GtkWidget *widget,
FMPropertiesWindow *window)
{
GtkWidget *dialog, *preview;
GtkFileFilter *filter;
GList *l;
NautilusFile *file;
char *image_path;
char *uri;
gboolean revert_is_sensitive;
g_assert (FM_IS_PROPERTIES_WINDOW (window));
dialog = window->details->icon_chooser;
if (dialog == NULL) {
dialog = gtk_file_chooser_dialog_new (_("Select Custom Icon"), GTK_WINDOW (window),
GTK_FILE_CHOOSER_ACTION_OPEN,
GTK_STOCK_REVERT_TO_SAVED, GTK_RESPONSE_NO,
GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
GTK_STOCK_OPEN, GTK_RESPONSE_OK,
NULL);
gtk_file_chooser_add_shortcut_folder (GTK_FILE_CHOOSER (dialog), "/usr/share/pixmaps", NULL);
gtk_window_set_destroy_with_parent (GTK_WINDOW (dialog), TRUE);
filter = gtk_file_filter_new ();
gtk_file_filter_add_pixbuf_formats (filter);
gtk_file_chooser_set_filter (GTK_FILE_CHOOSER (dialog), filter);
preview = gtk_image_new ();
gtk_widget_set_size_request (preview, PREVIEW_IMAGE_WIDTH, -1);
gtk_file_chooser_set_preview_widget (GTK_FILE_CHOOSER (dialog), preview);
gtk_file_chooser_set_use_preview_label (GTK_FILE_CHOOSER (dialog), FALSE);
gtk_file_chooser_set_preview_widget_active (GTK_FILE_CHOOSER (dialog), FALSE);
g_signal_connect (dialog, "update-preview",
G_CALLBACK (update_preview_callback), window);
window->details->icon_chooser = dialog;
g_object_add_weak_pointer (G_OBJECT (dialog),
(gpointer *) &window->details->icon_chooser);
}
/* it's likely that the user wants to pick an icon that is inside a local directory */
if (g_list_length (window->details->original_files) == 1) {
file = NAUTILUS_FILE (window->details->original_files->data);
if (nautilus_file_is_directory (file)) {
uri = nautilus_file_get_uri (file);
image_path = gnome_vfs_get_local_path_from_uri (uri);
if (image_path != NULL) {
gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (dialog), image_path);
g_free (image_path);
}
g_free (uri);
}
}
revert_is_sensitive = FALSE;
for (l = window->details->original_files; l != NULL; l = l->next) {
file = NAUTILUS_FILE (l->data);
image_path = nautilus_file_get_metadata (file, NAUTILUS_METADATA_KEY_CUSTOM_ICON, NULL);
revert_is_sensitive = (image_path != NULL);
g_free (image_path);
if (revert_is_sensitive) {
break;
}
}
gtk_dialog_set_response_sensitive (GTK_DIALOG (dialog), GTK_RESPONSE_NO, revert_is_sensitive);
switch (gtk_dialog_run (GTK_DIALOG (dialog))) {
case GTK_RESPONSE_NO:
reset_icon (window);
break;
case GTK_RESPONSE_OK:
uri = gtk_file_chooser_get_uri (GTK_FILE_CHOOSER (dialog));
set_icon (uri, window);
g_free (uri);
break;
default:
break;
}
gtk_widget_hide (dialog);
}
static void
fm_properties_window_class_init (FMPropertiesWindowClass *class)
{
G_OBJECT_CLASS (class)->finalize = real_finalize;
GTK_OBJECT_CLASS (class)->destroy = real_destroy;
}
static void
fm_properties_window_instance_init (FMPropertiesWindow *window)
{
window->details = g_new0 (FMPropertiesWindowDetails, 1);
eel_gtk_window_set_up_close_accelerator (GTK_WINDOW (window));
}
|